From 77e792334f6d74072ab0e60e8a21f878927f743d Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sun, 8 Jul 2012 20:03:24 -0700 Subject: [PATCH] Cosmetics. --- .../core/dom/parser/ITypeMarshalBuffer.java | 12 +- .../cdt/internal/core/dom/parser/Value.java | 162 ++++----- .../parser/cpp/semantics/CPPTemplates.java | 331 +++++++++--------- .../dom/parser/cpp/semantics/EvalBinary.java | 34 +- .../cpp/semantics/EvalBinaryTypeId.java | 11 +- .../dom/parser/cpp/semantics/EvalBinding.java | 43 ++- .../dom/parser/cpp/semantics/EvalComma.java | 29 +- .../parser/cpp/semantics/EvalCompound.java | 7 +- .../parser/cpp/semantics/EvalConditional.java | 43 ++- .../dom/parser/cpp/semantics/EvalFixed.java | 37 +- .../cpp/semantics/EvalFunctionCall.java | 29 +- .../parser/cpp/semantics/EvalFunctionSet.java | 11 +- .../core/dom/parser/cpp/semantics/EvalID.java | 41 ++- .../parser/cpp/semantics/EvalInitList.java | 9 +- .../cpp/semantics/EvalMemberAccess.java | 67 ++-- .../dom/parser/cpp/semantics/EvalTypeId.java | 15 +- .../dom/parser/cpp/semantics/EvalUnary.java | 33 +- .../parser/cpp/semantics/EvalUnaryTypeID.java | 19 +- .../core/pdom/db/TypeMarshalBuffer.java | 85 ++--- .../core/pdom/dom/cpp/PDOMCPPLinkage.java | 100 +++--- 20 files changed, 552 insertions(+), 566 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeMarshalBuffer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeMarshalBuffer.java index b4ead75e4c5..f3dbae212dc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeMarshalBuffer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeMarshalBuffer.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ + * Markus Schorn - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -30,7 +30,7 @@ public interface ITypeMarshalBuffer { final static byte PROBLEM_TYPE= 9; final static byte VALUE= 10; final static byte DEPENDENT_EXPRESSION_TYPE= 11; - + final static byte EVAL_BINARY= 1, EVAL_BINARY_TYPE_ID = 2, @@ -47,16 +47,16 @@ public interface ITypeMarshalBuffer { EVAL_TYPE_ID= 13, EVAL_UNARY= 14, EVAL_UNARY_TYPE_ID = 15; - + static final byte KIND_MASK= 15; - + final static int FLAG1 = 0x10; final static int FLAG2 = 0x20; final static int FLAG3 = 0x40; final static int FLAG4 = 0x80; CoreException unmarshallingError(); - + IType unmarshalType() throws CoreException; IValue unmarshalValue() throws CoreException; IBinding unmarshalBinding() throws CoreException; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java index 76c8d107687..808165c5c65 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java @@ -8,7 +8,7 @@ * Contributors: * Markus Schorn - initial API and implementation * Sergey Prigogin (Google) - *******************************************************************************/ + *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; import java.util.ArrayList; @@ -45,15 +45,15 @@ import org.eclipse.cdt.internal.core.pdom.db.TypeMarshalBuffer; import org.eclipse.core.runtime.CoreException; /** - * Represents values of variables, enumerators or expressions. The primary purpose of the representation - * is to support instantiation of templates with non-type template parameters. + * Represents values of variables, enumerators or expressions. The primary purpose of + * the representation is to support instantiation of templates with non-type template parameters. */ public class Value implements IValue { public static final int MAX_RECURSION_DEPTH = 25; public final static IValue UNKNOWN= new Value("".toCharArray(), ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY); //$NON-NLS-1$ public final static IValue NOT_INITIALIZED= new Value("<__>".toCharArray(), ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY); //$NON-NLS-1$ private static final int[] NO_INT = {}; - + private static final String SCOPE_OP = "::"; //$NON-NLS-1$ private static final char UNIQUE_CHAR = '_'; private static final char TEMPLATE_PARAM_CHAR = '#'; @@ -62,16 +62,16 @@ public class Value implements IValue { private static final char UNARY_OP_CHAR = '$'; private static final char BINARY_OP_CHAR = '@'; private static final char CONDITIONAL_CHAR= '?'; - + private static final char SEPARATOR = ','; private final static IValue[] TYPICAL= { - new Value(new char[] {'0'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY), - new Value(new char[] {'1'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY), - new Value(new char[] {'2'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY), - new Value(new char[] {'3'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY), - new Value(new char[] {'4'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY), - new Value(new char[] {'5'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY), + new Value(new char[] {'0'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY), + new Value(new char[] {'1'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY), + new Value(new char[] {'2'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY), + new Value(new char[] {'3'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY), + new Value(new char[] {'4'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY), + new Value(new char[] {'5'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY), new Value(new char[] {'6'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY)}; @@ -113,13 +113,13 @@ public class Value implements IValue { private final char[] fExpression; private final ICPPUnknownBinding[] fUnknownBindings; private char[] fSignature; - + private Value(char[] rep, ICPPUnknownBinding[] unknown) { assert rep != null; fExpression= rep; fUnknownBindings= unknown; } - + @Override public char[] getInternalExpression() { return fExpression; @@ -129,7 +129,7 @@ public class Value implements IValue { public IBinding[] getUnknownBindings() { return fUnknownBindings; } - + @Override public char[] getSignature() { if (fSignature == null) { @@ -152,12 +152,12 @@ public class Value implements IValue { } return fSignature; } - + @Override public Long numericalValue() { return parseLong(fExpression); } - + public void marshall(TypeMarshalBuffer buf) throws CoreException { if (UNKNOWN == this) { buf.putByte((byte) (ITypeMarshalBuffer.VALUE | ITypeMarshalBuffer.FLAG1)); @@ -182,12 +182,12 @@ public class Value implements IValue { } } } - + public static IValue unmarshal(TypeMarshalBuffer buf) throws CoreException { int firstByte= buf.getByte(); if (firstByte == TypeMarshalBuffer.NULL_TYPE) return null; - if ((firstByte & ITypeMarshalBuffer.FLAG1) != 0) + if ((firstByte & ITypeMarshalBuffer.FLAG1) != 0) return Value.UNKNOWN; if ((firstByte & ITypeMarshalBuffer.FLAG2) != 0) { int val= buf.getInt(); @@ -197,7 +197,7 @@ public class Value implements IValue { long val= buf.getLong(); return Value.create(val); } - + char[] expr = buf.getCharArray(); final int len= buf.getShort(); ICPPUnknownBinding[] unknowns= new ICPPUnknownBinding[len]; @@ -215,7 +215,7 @@ public class Value implements IValue { public int hashCode() { return CharArrayUtils.hash(fExpression); } - + @Override public boolean equals(Object obj) { if (!(obj instanceof IValue)) { @@ -224,11 +224,11 @@ public class Value implements IValue { final IValue rhs = (IValue) obj; if (!CharArrayUtils.equals(fExpression, rhs.getInternalExpression())) return false; - + IBinding[] rhsUnknowns= rhs.getUnknownBindings(); if (fUnknownBindings.length != rhsUnknowns.length) return false; - + for (int i = 0; i < rhsUnknowns.length; i++) { final IBinding rhsUnknown = rhsUnknowns[i]; if (rhsUnknown instanceof ICPPUnknownBinding) { @@ -241,7 +241,7 @@ public class Value implements IValue { } return true; } - + @Override public String toString() { return new String(getSignature()); @@ -255,7 +255,7 @@ public class Value implements IValue { return TYPICAL[(int) value]; return new Value(toCharArray(value), ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY); } - + /** * Creates a value representing the given template parameter. */ @@ -272,7 +272,7 @@ public class Value implements IValue { } /** - * Tests whether the value is a template parameter (or parameter pack), + * Tests whether the value is a template parameter (or parameter pack), * returns the parameter id of the parameter, or -1 if it is not a template parameter. */ public static int isTemplateParameter(IValue tval) { @@ -292,7 +292,7 @@ public class Value implements IValue { } return -1; } - + /** * Tests whether the value directly references some template parameter. */ @@ -351,7 +351,7 @@ public class Value implements IValue { } if (result != -1) return new int[] {result}; - + return NO_INT; } @@ -365,7 +365,7 @@ public class Value implements IValue { Object obj= evaluate(expr, unknownSigs, unknown, maxRecursionDepth); if (obj instanceof Number) return create(((Number) obj).longValue()); - + ICPPUnknownBinding[] ua; if (unknown.isEmpty()) { ua= ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY; @@ -377,18 +377,18 @@ public class Value implements IValue { } return UNKNOWN; } - + /** * Creates a value off its canonical representation. */ public static IValue fromInternalRepresentation(char[] rep, ICPPUnknownBinding[] unknown) { if (CharArrayUtils.equals(rep, UNKNOWN.getInternalExpression())) return UNKNOWN; - + Long l= parseLong(rep); - if (l != null) + if (l != null) return create(l.longValue()); - + return new Value(rep, unknown); } @@ -399,11 +399,11 @@ public class Value implements IValue { StringBuilder buf= new StringBuilder(10); buf.append(UNIQUE_CHAR); buf.append(++sUnique); - return new Value(extractChars(buf), ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY); + return new Value(extractChars(buf), ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY); } /** - * Computes the canonical representation of the value of the expression. + * Computes the canonical representation of the value of the expression. * Returns a {@code Number} for numerical values or a {@code String}, otherwise. * @throws UnknownValueException */ @@ -411,7 +411,7 @@ public class Value implements IValue { List unknowns, int maxdepth) throws UnknownValueException { if (maxdepth < 0 || e == null) throw UNKNOWN_EX; - + if (e instanceof IASTArraySubscriptExpression) { throw UNKNOWN_EX; } @@ -465,7 +465,7 @@ public class Value implements IValue { case IASTLiteralExpression.lk_char_constant: try { final char[] image= litEx.getValue(); - if (image.length > 1 && image[0] == 'L') + if (image.length > 1 && image[0] == 'L') return ExpressionEvaluator.getChar(image, 2); return ExpressionEvaluator.getChar(image, 1); } catch (EvalException e1) { @@ -489,7 +489,7 @@ public class Value implements IValue { } throw UNKNOWN_EX; } - + /** * Extract a value off a binding. */ @@ -502,11 +502,11 @@ public class Value implements IValue { final ICPPTemplateNonTypeParameter tp = (ICPPTemplateNonTypeParameter) b; return createTemplateParamExpression(tp.getParameterID(), tp.isParameterPack()); } - + if (b instanceof ICPPUnknownBinding) { return createReference((ICPPUnknownBinding) b, unknownSigs, unknowns); } - + IValue value= null; if (b instanceof IInternalVariable) { value= ((IInternalVariable) b).getInitialValue(maxdepth - 1); @@ -514,10 +514,10 @@ public class Value implements IValue { value= ((IVariable) b).getInitialValue(); } else if (b instanceof IEnumerator) { value= ((IEnumerator) b).getValue(); - } + } if (value != null) return evaluateValue(value, unknownSigs, unknowns); - + throw UNKNOWN_EX; } @@ -532,21 +532,21 @@ public class Value implements IValue { } return "" + REFERENCE_CHAR + idx.toString(); //$NON-NLS-1$ } - + private static Object evaluateValue(IValue cv, Map unknownSigs, List unknowns) throws UnknownValueException { - if (cv == Value.UNKNOWN) + if (cv == Value.UNKNOWN) throw UNKNOWN_EX; - + Long lv= cv.numericalValue(); if (lv != null) return lv; - + final IBinding[] oldUnknowns = cv.getUnknownBindings(); final char[] expr= cv.getInternalExpression(); if (oldUnknowns.length == 0) return new String(expr); - + StringBuilder buf= new StringBuilder(expr.length); boolean skipToSeparator= false; for (int i = 0; i < expr.length; i++) { @@ -557,7 +557,7 @@ public class Value implements IValue { if (idx >= oldUnknowns.length) throw UNKNOWN_EX; final IBinding old = oldUnknowns[idx]; - if (!(old instanceof ICPPUnknownBinding)) + if (!(old instanceof ICPPUnknownBinding)) throw UNKNOWN_EX; buf.append(createReference((ICPPUnknownBinding) old, unknownSigs, unknowns)); @@ -576,7 +576,7 @@ public class Value implements IValue { } return buf.toString(); } - + private static Object evaluateUnaryExpression(IASTUnaryExpression ue, Map unknownSigs, List unknowns, int maxdepth) throws UnknownValueException { @@ -599,11 +599,11 @@ public class Value implements IValue { unaryOp == IASTUnaryExpression.op_sizeofParameterPack) { throw UNKNOWN_EX; } - + final Object value= evaluate(ue.getOperand(), unknownSigs, unknowns, maxdepth); - return combineUnary(unaryOp, value); + return combineUnary(unaryOp, value); } - + private static Object combineUnary(final int unaryOp, final Object value) throws UnknownValueException { switch (unaryOp) { case IASTUnaryExpression.op_bracketedPrimary: @@ -628,8 +628,8 @@ public class Value implements IValue { return v == 0 ? 1 : 0; } throw UNKNOWN_EX; - } - + } + switch (unaryOp) { case IASTUnaryExpression.op_prefixIncr: case IASTUnaryExpression.op_postFixIncr: @@ -643,7 +643,7 @@ public class Value implements IValue { throw UNKNOWN_EX; } - private static Object evaluateBinaryExpression(IASTBinaryExpression be, + private static Object evaluateBinaryExpression(IASTBinaryExpression be, Map unknownSigs, List unknowns, int maxdepth) throws UnknownValueException { final Object o1= evaluate(be.getOperand1(), unknownSigs, unknowns, maxdepth); @@ -652,7 +652,7 @@ public class Value implements IValue { final int op= be.getOperator(); return combineBinary(op, o1, o2); } - + private static Object combineBinary(final int op, final Object o1, final Object o2) throws UnknownValueException { if (o1 instanceof Number && o2 instanceof Number) { @@ -737,10 +737,10 @@ public class Value implements IValue { default: throw UNKNOWN_EX; } - + return "" + BINARY_OP_CHAR + op + SEPARATOR + o1.toString() + SEPARATOR + o2.toString(); //$NON-NLS-1$ } - + public static IValue reevaluate(IValue val, int packOffset, IBinding[] resolvedUnknowns, ICPPTemplateParameterMap map, int maxdepth) { try { @@ -752,10 +752,10 @@ public class Value implements IValue { Object obj= reevaluate(reeval, maxdepth); if (reeval.pos != reeval.fExpression.length) return UNKNOWN; - + if (obj instanceof Number) return create(((Number) obj).longValue()); - + ICPPUnknownBinding[] ua; if (unknown.isEmpty()) { ua= ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY; @@ -768,7 +768,7 @@ public class Value implements IValue { return UNKNOWN; } - private static Object reevaluate(Reevaluation reeval, int maxdepth) + private static Object reevaluate(Reevaluation reeval, int maxdepth) throws UnknownValueException { if (maxdepth < 0) throw UNKNOWN_EX; @@ -778,16 +778,16 @@ public class Value implements IValue { final int length = buf.length; if (idx >= length) throw UNKNOWN_EX; - + final char c= buf[idx]; switch (c) { - case BINARY_OP_CHAR: + case BINARY_OP_CHAR: int op= parseNonNegative(buf, idx + 1); reeval.nextSeperator(); Object o1= reevaluate(reeval, maxdepth); Object o2= reevaluate(reeval, maxdepth); return combineBinary(op, o1, o2); - case UNARY_OP_CHAR: + case UNARY_OP_CHAR: op= parseNonNegative(buf, idx + 1); reeval.nextSeperator(); o1= reevaluate(reeval, maxdepth); @@ -806,7 +806,7 @@ public class Value implements IValue { } return "" + CONDITIONAL_CHAR + SEPARATOR + cond.toString() + SEPARATOR + //$NON-NLS-1$ po.toString() + SEPARATOR + neg.toString(); - case REFERENCE_CHAR: + case REFERENCE_CHAR: int num= parseNonNegative(buf, idx + 1); final IBinding[] resolvedUnknowns= reeval.fResolvedUnknown; if (num >= resolvedUnknowns.length) @@ -825,7 +825,7 @@ public class Value implements IValue { return evaluateValue(val, reeval.fUnknownSigs, reeval.fUnknowns); } return createTemplateParamExpression(num, false); - + case TEMPLATE_PARAM_PACK_CHAR: num= parseHex(buf, idx + 1); reeval.nextSeperator(); @@ -843,7 +843,7 @@ public class Value implements IValue { return evaluateValue(val, reeval.fUnknownSigs, reeval.fUnknowns); } return createTemplateParamExpression(num, true); - + default: reeval.nextSeperator(); return parseLong(buf, idx); @@ -858,13 +858,13 @@ public class Value implements IValue { final int len= value.length; int result = 0; boolean ok= false; - for(; offset < len; offset++) { + for (; offset < len; offset++) { final int digit= (value[offset] - '0'); if (digit < 0 || digit > 9) break; if (result > maxvalue) return -1; - + result= result * 10 + digit; ok= true; } @@ -880,7 +880,7 @@ public class Value implements IValue { int result = 0; boolean ok= false; final int len= value.length; - for(; offset < len; offset++) { + for (; offset < len; offset++) { int digit= (value[offset] - '0'); if (digit < 0 || digit > 9) { digit += '0' - 'a' + 10; @@ -893,13 +893,13 @@ public class Value implements IValue { } if ((result & 0xf0000000) != 0) throw UNKNOWN_EX; - + result= (result << 4) + digit; ok= true; } if (!ok) throw UNKNOWN_EX; - + return result; } @@ -911,26 +911,26 @@ public class Value implements IValue { final int len= value.length; boolean negative= false; long result = 0; - + boolean ok= false; if (offset < len && value[offset] == '-') { negative = true; offset++; } - for(; offset < len; offset++) { + for (; offset < len; offset++) { final int digit= (value[offset] - '0'); if (digit < 0 || digit > 9) break; - + if (result > maxvalue) throw UNKNOWN_EX; - + result= result * 10 + digit; ok= true; } if (!ok) throw UNKNOWN_EX; - + return negative ? -result : result; } @@ -943,18 +943,18 @@ public class Value implements IValue { boolean negative= false; long result = 0; int i= 0; - + if (len > 0 && value[0] == '-') { negative = true; i++; } if (i == len) return null; - - for(; i < len; i++) { + + for (; i < len; i++) { if (result > maxvalue) return null; - + final int digit= (value[i] - '0'); if (digit < 0 || digit > 9) return null; @@ -993,7 +993,7 @@ public class Value implements IValue { } public static IValue create(ICPPEvaluation eval, IASTNode point) { - // compute value of evaluation + // Compute value of evaluation return Value.UNKNOWN; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java index 3b6521e49fd..b42087adb35 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java @@ -162,13 +162,13 @@ public class CPPTemplates { * Instantiates a class template with the given arguments. May return null. */ public static IBinding instantiate(ICPPClassTemplate template, ICPPTemplateArgument[] args, IASTNode point) { - return instantiate(template, args, false, false, point); + return instantiate(template, args, false, false, point); } - + /** * Instantiates a class template with the given arguments. May return null. */ - private static IBinding instantiate(ICPPClassTemplate template, ICPPTemplateArgument[] args, + private static IBinding instantiate(ICPPClassTemplate template, ICPPTemplateArgument[] args, boolean isDefinition, boolean isExplicitSpecialization, IASTNode point) { try { // Add default arguments, if necessary. @@ -180,7 +180,7 @@ public class CPPTemplates { if (template instanceof ICPPTemplateTemplateParameter || hasDependentArgument(arguments)) { return deferredInstance(template, arguments); } - + if (template instanceof ICPPClassTemplatePartialSpecialization) { return instantiatePartialSpecialization((ICPPClassTemplatePartialSpecialization) template, arguments, isDefinition, null, point); } @@ -191,7 +191,7 @@ public class CPPTemplates { final int length= Math.max(numArgs, numParams); CPPTemplateParameterMap map= new CPPTemplateParameterMap(numParams); - + boolean isPack= false; ICPPTemplateParameter param= null; for (int i = 0; i < length; i++) { @@ -220,9 +220,9 @@ public class CPPTemplates { } else { // Parameter pack with empty arguments. assert isPack; - } + } } - + if (isPack) { int packOffset= numParams-1; int packSize= numArgs - packOffset; @@ -240,8 +240,8 @@ public class CPPTemplates { if (result != null) return result; } - - return instantiatePrimaryTemplate(template, arguments, map, isDefinition, point); + + return instantiatePrimaryTemplate(template, arguments, map, isDefinition, point); } catch (DOMException e) { return e.getProblem(); } @@ -295,7 +295,7 @@ public class CPPTemplates { scope= CPPVisitor.getContainingScope(internalScope.getPhysicalNode()); if (scope == internalScope) return null; - } else { + } else { scope= scope.getParent(); } } @@ -310,7 +310,7 @@ public class CPPTemplates { if (instance != null) { return instance; } - + IBinding owner= template.getOwner(); instance = CPPTemplates.createInstance(owner, template, map, arguments, point); addInstance(template, arguments, instance); @@ -319,7 +319,7 @@ public class CPPTemplates { /** * Instantiates a partial class template specialization. - * @param point + * @param point */ private static IBinding instantiatePartialSpecialization( ICPPClassTemplatePartialSpecialization partialSpec, ICPPTemplateArgument[] args, boolean isDef, @@ -340,13 +340,13 @@ public class CPPTemplates { return instance; } - /** + /** * Instantiates the selected template, without looking for specializations. May return null. - * @param map + * @param map */ - private static IBinding instantiatePrimaryTemplate(ICPPClassTemplate template, ICPPTemplateArgument[] arguments, + private static IBinding instantiatePrimaryTemplate(ICPPClassTemplate template, ICPPTemplateArgument[] arguments, CPPTemplateParameterMap map, boolean isDef, IASTNode point) throws DOMException { - + assert !(template instanceof ICPPClassTemplatePartialSpecialization); ICPPTemplateInstance instance= getInstance(template, arguments, isDef); if (instance != null) { @@ -396,7 +396,7 @@ public class CPPTemplates { ICPPTemplateArgument[] arguments, IASTNode point) throws DOMException { if (template instanceof ICPPClassTemplatePartialSpecialization) return arguments; - + boolean havePackExpansion= false; for (int i = 0; i < arguments.length; i++) { ICPPTemplateArgument arg = arguments[i]; @@ -407,38 +407,38 @@ public class CPPTemplates { havePackExpansion= true; } } - + ICPPTemplateParameter[] tpars = template.getTemplateParameters(); int tparCount = tpars.length; final int argCount = arguments.length; - + if (tparCount == argCount) return arguments; - + if (tparCount == 0) return null; - + // More arguments allowed if we have a parameter pack. if (tparCount < argCount) { if (tpars[tparCount-1].isParameterPack()) return arguments; - + if (havePackExpansion && tparCount+1 == argCount) return arguments; return null; - } - + } + // Fewer arguments are allowed with a pack expansion if (havePackExpansion) return arguments; - + // Fewer arguments are allowed with default arguments if (tpars[tparCount-1].isParameterPack()) tparCount--; - - if (tparCount == argCount) + + if (tparCount == argCount) return arguments; - + ICPPTemplateArgument[] completeArgs= new ICPPTemplateArgument[tparCount]; CPPTemplateParameterMap map= new CPPTemplateParameterMap(tparCount); for (int i = 0; i < tparCount; i++) { @@ -463,7 +463,7 @@ public class CPPTemplates { arg= SemanticUtil.getSimplifiedArgument(arg); if (!isValidArgument(arg)) { return null; - } + } } map.put(tpar, arg); completeArgs[i]= arg; @@ -503,7 +503,7 @@ public class CPPTemplates { return args; } - /** + /** * Extracts the IASTName of a template parameter. */ public static IASTName getTemplateParameterName(ICPPASTTemplateParameter param) { @@ -585,7 +585,7 @@ public class CPPTemplates { public static IBinding createBinding(ICPPASTTemplateParameter tp) { if (tp instanceof ICPPASTSimpleTypeTemplateParameter) { return new CPPTemplateTypeParameter(((ICPPASTSimpleTypeTemplateParameter) tp).getName(), tp.isParameterPack()); - } + } if (tp instanceof ICPPASTTemplatedTypeTemplateParameter) { return new CPPTemplateTemplateParameter(((ICPPASTTemplatedTypeTemplateParameter) tp).getName(), tp.isParameterPack()); } @@ -593,7 +593,7 @@ public class CPPTemplates { final IASTDeclarator dtor = ((ICPPASTParameterDeclaration) tp).getDeclarator(); return new CPPTemplateNonTypeParameter(ASTQueries.findInnermostDeclarator(dtor).getName()); } - + public static IBinding createBinding(ICPPASTTemplateId id) { if (!isClassTemplate(id)) { //functions are instantiated as part of the resolution process @@ -611,7 +611,7 @@ public class CPPTemplates { return result; } } - + IASTNode parentOfName = id.getParent(); boolean isLastName= true; if (parentOfName instanceof ICPPASTQualifiedName) { @@ -629,7 +629,7 @@ public class CPPTemplates { isDeclaration= true; } else if (parentOfName instanceof ICPPASTCompositeTypeSpecifier) { isDefinition= true; - } + } if (isDeclaration || isDefinition) { IASTNode parentOfDeclaration = declaration.getParent(); if (parentOfDeclaration instanceof ICPPASTExplicitTemplateInstantiation) { @@ -649,7 +649,7 @@ public class CPPTemplates { if (template instanceof ICPPConstructor) { template= template.getOwner(); } - + if (template instanceof ICPPUnknownClassType) { IBinding owner= template.getOwner(); if (owner instanceof ICPPUnknownBinding) { @@ -659,7 +659,7 @@ public class CPPTemplates { } } - if (!(template instanceof ICPPClassTemplate) || template instanceof ICPPClassTemplatePartialSpecialization) + if (!(template instanceof ICPPClassTemplate) || template instanceof ICPPClassTemplatePartialSpecialization) return new ProblemBinding(id, IProblemBinding.SEMANTIC_INVALID_TYPE, templateName.toCharArray()); final ICPPClassTemplate classTemplate = (ICPPClassTemplate) template; @@ -668,12 +668,12 @@ public class CPPTemplates { ICPPASTTemplateDeclaration tdecl= getTemplateDeclaration(id); if (tdecl != null) { if (argsAreTrivial(classTemplate.getTemplateParameters(), args)) { - result= classTemplate; + result= classTemplate; } else { args= addDefaultArguments(classTemplate, args, id); if (args == null) { return new ProblemBinding(id, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS, templateName.toCharArray()); - } + } ICPPClassTemplatePartialSpecialization partialSpec= findPartialSpecialization(classTemplate, args); if (isDeclaration || isDefinition) { if (partialSpec == null) { @@ -681,7 +681,7 @@ public class CPPTemplates { if (template instanceof ICPPInternalClassTemplate) ((ICPPInternalClassTemplate) template).addPartialSpecialization(partialSpec); return partialSpec; - } + } } if (partialSpec == null) return new ProblemBinding(id, IProblemBinding.SEMANTIC_INVALID_TYPE, templateName.toCharArray()); @@ -716,10 +716,10 @@ public class CPPTemplates { if (parentOfName instanceof ICPPASTElaboratedTypeSpecifier || parentOfName instanceof ICPPASTCompositeTypeSpecifier || - parentOfName instanceof ICPPASTNamedTypeSpecifier || + parentOfName instanceof ICPPASTNamedTypeSpecifier || parentOfName instanceof ICPPASTBaseSpecifier) return true; - + if (parentOfName instanceof IASTDeclarator) { IASTDeclarator rel= ASTQueries.findTypeRelevantDeclarator((IASTDeclarator) parentOfName); return !(rel instanceof IASTFunctionDeclarator); @@ -728,7 +728,7 @@ public class CPPTemplates { } - public static ICPPTemplateInstance createInstance(IBinding owner, ICPPTemplateDefinition template, + public static ICPPTemplateInstance createInstance(IBinding owner, ICPPTemplateDefinition template, CPPTemplateParameterMap tpMap, ICPPTemplateArgument[] args, IASTNode point) { if (owner instanceof ICPPSpecialization) { ICPPTemplateParameterMap map= ((ICPPSpecialization) owner).getTemplateParameterMap(); @@ -736,7 +736,7 @@ public class CPPTemplates { tpMap.putAll(map); } } - + ICPPTemplateInstance instance = null; if (template instanceof ICPPClassType) { instance = new CPPClassInstance((ICPPClassType) template, owner, tpMap, args); @@ -838,7 +838,7 @@ public class CPPTemplates { } return spec; } - + private static ICPPClassSpecialization getSpecializationContext(IBinding owner) { if (!(owner instanceof ICPPClassSpecialization)) return null; @@ -847,17 +847,18 @@ public class CPPTemplates { for(;;) { IBinding o1 = within.getOwner(); IBinding o2 = orig.getOwner(); - if (!(o1 instanceof ICPPClassSpecialization && o2 instanceof ICPPClassType)) + if (!(o1 instanceof ICPPClassSpecialization && o2 instanceof ICPPClassType)) return within; ICPPClassSpecialization nextWithin = (ICPPClassSpecialization) o1; orig= (ICPPClassType) o2; - if (orig.isSameType(nextWithin)) + if (orig.isSameType(nextWithin)) return within; within= nextWithin; } } -public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, int maxdepth, IASTNode point) { + public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { if (value == null) return null; IBinding[] unknowns= value.getUnknownBindings(); @@ -882,11 +883,11 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM } } } - + if (resolvedUnknowns != null) return Value.reevaluate(value, packOffset, resolvedUnknowns, tpMap, maxdepth); - - if (Value.referencesTemplateParameter(value)) + + if (Value.referencesTemplateParameter(value)) return Value.reevaluate(value, packOffset, unknowns, tpMap, maxdepth); return value; @@ -901,7 +902,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM final ICPPFunctionType ft = (ICPPFunctionType) type; final IType rt = ft.getReturnType(); int r = determinePackSize(rt, tpMap); - if (r < 0) + if (r < 0) return r; IType[] ps = ft.getParameterTypes(); for (IType pt : ps) { @@ -910,7 +911,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM return r; } return r; - } + } if (type instanceof ICPPTemplateParameter) { final ICPPTemplateParameter tpar = (ICPPTemplateParameter) type; @@ -921,7 +922,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM return PACK_SIZE_DEFER; } return PACK_SIZE_NOT_FOUND; - } + } int r= PACK_SIZE_NOT_FOUND; if (type instanceof ICPPUnknownBinding) { @@ -943,7 +944,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM if (type instanceof ICPPParameterPackType) return PACK_SIZE_NOT_FOUND; - + if (type instanceof IArrayType) { IArrayType at= (IArrayType) type; IValue asize= at.getSize(); @@ -955,7 +956,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM if (type instanceof ITypeContainer) { final ITypeContainer typeContainer = (ITypeContainer) type; r= combine(r, determinePackSize(typeContainer.getType(), tpMap)); - } + } return r; } @@ -1002,13 +1003,13 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM * Instantiates types contained in an array. * @param types an array of types * @param tpMap template argument map - * @param point + * @param point * @return an array containing instantiated types. */ public static IType[] instantiateTypes(IType[] types, ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, IASTNode point) { if (types == null) return null; - + // Don't create a new array until it's really needed. IType[] result = types; int j= 0; @@ -1050,7 +1051,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM /** * Instantiates arguments contained in an array. - * @param point + * @param point */ public static ICPPTemplateArgument[] instantiateArguments(ICPPTemplateArgument[] args, ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, IASTNode point) @@ -1098,7 +1099,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM /** * Instantiates an argument - * @param point + * @param point */ static ICPPTemplateArgument instantiateArgument(ICPPTemplateArgument arg, ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, IASTNode point) { @@ -1113,14 +1114,14 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM return arg; return new CPPTemplateArgument(instValue, instType); } - + final IType orig= arg.getTypeValue(); final IType inst= instantiateType(orig, tpMap, packOffset, within, point); if (orig == inst) return arg; return new CPPTemplateArgument(inst); } - + private static CPPTemplateParameterMap instantiateArgumentMap(ICPPTemplateParameterMap orig, ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, IASTNode point) { final Integer[] positions = orig.getAllParameterPositions(); @@ -1146,7 +1147,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM /** * Instantiates the given type with the provided map and packoffset. * The context is used to replace templates with their specialization, where appropriate. - * @param point + * @param point */ public static IType instantiateType(IType type, ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, IASTNode point) { @@ -1173,7 +1174,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM } } return new CPPFunctionType(ret, params, ft.isConst(), ft.isVolatile(), ft.takesVarArgs()); - } + } if (type instanceof ICPPTemplateParameter) { final ICPPTemplateParameter tpar = (ICPPTemplateParameter) type; @@ -1198,7 +1199,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM return t; } return type; - } + } if (type instanceof ICPPUnknownBinding) { IBinding binding= resolveUnknown((ICPPUnknownBinding) type, tpMap, packOffset, within, point); @@ -1212,7 +1213,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM IType unwound= getNestedType(type, TDEF); if (unwound instanceof ICPPClassType && unwound.isSameType(within.getSpecializedBinding())) { // Convert (partial) class-templates (specializations) to the more specialized version. - if (within instanceof ICPPClassTemplate || !(unwound instanceof ICPPClassTemplate)) + if (within instanceof ICPPClassTemplate || !(unwound instanceof ICPPClassTemplate)) return within; } IBinding typeAsBinding= (IBinding) type; @@ -1221,18 +1222,18 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM final IType ownerAsType = getNestedType((IType) owner, TDEF); Object newOwner= owner; if (ownerAsType instanceof ICPPClassType && ownerAsType.isSameType(within.getSpecializedBinding())) { - // Convert (partial) class-templates (specializations) that are used as owner of + // Convert (partial) class-templates (specializations) that are used as owner of // another binding, to the more specialized version. newOwner= within; } else { newOwner= instantiateType(ownerAsType, tpMap, packOffset, within, point); } - + if (newOwner != owner && newOwner instanceof ICPPClassSpecialization) { return (IType) ((ICPPClassSpecialization) newOwner).specializeMember(typeAsBinding, point); } } - + if (unwound instanceof ICPPTemplateInstance && !(unwound instanceof ICPPDeferredClassInstance)) { // Argument of a class specialization can be a nested class subject to specialization. final ICPPTemplateInstance classInstance = (ICPPTemplateInstance) unwound; @@ -1245,8 +1246,8 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM return new CPPClassInstance((ICPPClassType) origClass, classInstance.getOwner(), tparMap, args); } } - } - } + } + } if (type instanceof ITypeContainer) { final ITypeContainer typeContainer = (ITypeContainer) type; @@ -1259,7 +1260,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM if (newMemberOfClass instanceof IQualifierType) { newMemberOfClass = ((IQualifierType) newMemberOfClass).getType(); } - if (!(newMemberOfClass instanceof ICPPClassType || newMemberOfClass instanceof UniqueType + if (!(newMemberOfClass instanceof ICPPClassType || newMemberOfClass instanceof UniqueType || newMemberOfClass instanceof ICPPUnknownBinding)) { return new ProblemType(ISemanticProblem.BINDING_INVALID_TYPE); } @@ -1268,7 +1269,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM ptm.isConst(), ptm.isVolatile(), ptm.isRestrict()); } return typeContainer; - } + } if (typeContainer instanceof IArrayType) { IArrayType at= (IArrayType) typeContainer; IValue asize= at.getSize(); @@ -1281,9 +1282,9 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM } if (newNestedType != nestedType) { return SemanticUtil.replaceNestedType(typeContainer, newNestedType); - } + } return typeContainer; - } + } return type; } catch (DOMException e) { @@ -1303,14 +1304,14 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM * correspond to a template declaration. */ public static ICPPASTTemplateDeclaration getTemplateDeclaration(IASTName name) { - if (name == null) + if (name == null) return null; // first look for a related sequence of template declarations ICPPASTInternalTemplateDeclaration tdecl= getInnerTemplateDeclaration(name); if (tdecl == null) return null; - + name= name.getLastName(); IASTNode parent= name.getParent(); if (!(parent instanceof ICPPASTQualifiedName)) { @@ -1319,23 +1320,23 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM } // one name: use innermost template declaration return tdecl; - } - + } + // last name can be associated even if it is not a template-id final ICPPASTQualifiedName qname= (ICPPASTQualifiedName) parent; final IASTName lastName = qname.getLastName(); final boolean lastIsTemplate= tdecl.isAssociatedWithLastName(); - if (name == lastName) { + if (name == lastName) { if (lastIsTemplate) { return tdecl; } return null; - } - + } + // not the last name, search for the matching template declaration - if (!(name instanceof ICPPASTTemplateId)) + if (!(name instanceof ICPPASTTemplateId)) return null; - + if (lastIsTemplate) { // skip one tdecl= getDirectlyEnclosingTemplateDeclaration(tdecl); @@ -1353,7 +1354,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM // not enough template declarations return null; } - + public static void associateTemplateDeclarations(ICPPASTInternalTemplateDeclaration tdecl) { // Find innermost template declaration IASTDeclaration decl= tdecl.getDeclaration(); @@ -1362,7 +1363,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM decl= tdecl.getDeclaration(); } final ICPPASTInternalTemplateDeclaration innerMostTDecl= tdecl; - + // Find name declared within the template declaration final IASTName declName= getNameForDeclarationInTemplateDeclaration(decl); @@ -1399,14 +1400,14 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM if (n instanceof ICPPASTTemplateId) { if (depIDCount > 0 || usesTemplateParameter((ICPPASTTemplateId) n, tparnames)) { depIDCount++; - } - } - if (depIDCount == 0) { + } + } + if (depIDCount == 0) { owner= n; } } - - if (qname.getLastName() instanceof ICPPASTTemplateId + + if (qname.getLastName() instanceof ICPPASTTemplateId || paramTDeclCount > depIDCount // not enough template ids || ns.length < 2 // ::name ) { @@ -1415,7 +1416,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM } else { lastIsTemplate= false; } - + nestingLevel= 0; if (owner != null) { int consumesTDecl= 0; @@ -1467,7 +1468,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM } } } - + node= innerMostTDecl; while(node instanceof ICPPASTInternalTemplateDeclaration) { if (--nestingLevel < 0) @@ -1530,7 +1531,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM return PROCESS_SKIP; return PROCESS_CONTINUE; } - + if (names.containsKey(name.getLookupKey())) { IASTNode parent= name.getParent(); if (parent instanceof ICPPASTQualifiedName) { @@ -1575,14 +1576,14 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM } else if (declspec instanceof IASTElaboratedTypeSpecifier) { name= ((IASTElaboratedTypeSpecifier) declspec).getName(); } - } + } } else if (decl instanceof IASTFunctionDefinition) { IASTFunctionDefinition fdef= (IASTFunctionDefinition) decl; name= ASTQueries.findInnermostDeclarator(fdef.getDeclarator()).getName(); } return name; } - + private static ICPPASTInternalTemplateDeclaration getInnerTemplateDeclaration(final IASTName name) { IASTNode parent = name.getParent(); @@ -1600,22 +1601,22 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM parent = parent.getParent(); } } - if (!(parent instanceof IASTDeclaration)) + if (!(parent instanceof IASTDeclaration)) return null; - + parent = parent.getParent(); - if (parent instanceof ICPPASTInternalTemplateDeclaration) + if (parent instanceof ICPPASTInternalTemplateDeclaration) return (ICPPASTInternalTemplateDeclaration) parent; return null; } - + private static ICPPASTInternalTemplateDeclaration getDirectlyEnclosingTemplateDeclaration( ICPPASTInternalTemplateDeclaration tdecl ) { final IASTNode parent= tdecl.getParent(); - if (parent instanceof ICPPASTInternalTemplateDeclaration) + if (parent instanceof ICPPASTInternalTemplateDeclaration) return (ICPPASTInternalTemplateDeclaration) parent; - + return null; } @@ -1680,12 +1681,12 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM return false; } for (int i=0; i < args.length; i++) { - if (!specArgs[i].isSameValue(args[i])) + if (!specArgs[i].isSameValue(args[i])) return false; } return true; } - + /** * @param id the template id containing the template arguments * @return an array of template arguments, currently modeled as IType objects. @@ -1712,13 +1713,13 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM } return result; } - + static ICPPFunction[] instantiateForFunctionCall(ICPPFunction[] fns, ICPPTemplateArgument[] tmplArgs, List fnArgs, List argCats, boolean withImpliedObjectArg, IASTNode point) { // Extract template arguments. boolean requireTemplate= tmplArgs != null; boolean haveTemplate= false; - + for (final ICPPFunction func : fns) { if (func instanceof ICPPConstructor || (func instanceof ICPPMethod && ((ICPPMethod) func).isDestructor())) requireTemplate= false; @@ -1726,11 +1727,11 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM if (func instanceof ICPPFunctionTemplate) { ICPPFunctionTemplate template= (ICPPFunctionTemplate) func; try { - if (containsDependentType(fnArgs)) + if (containsDependentType(fnArgs)) return new ICPPFunction[] {CPPUnknownFunction.createForSample(template)}; if (requireTemplate) { - if (hasDependentArgument(tmplArgs)) + if (hasDependentArgument(tmplArgs)) return new ICPPFunction[] {CPPUnknownFunction.createForSample(template)}; } } catch (DOMException e) { @@ -1741,9 +1742,9 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM } } - if (!haveTemplate && !requireTemplate) + if (!haveTemplate && !requireTemplate) return fns; - + final List result= new ArrayList(fns.length); for (ICPPFunction fn : fns) { if (fn != null) { @@ -1767,7 +1768,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM fnArgs= fnArgs.subList(1, fnArgs.size()); argCats= argCats.subList(1, argCats.size()); } - + CPPTemplateParameterMap map= new CPPTemplateParameterMap(fnArgs.size()); try { ICPPTemplateArgument[] args= TemplateArgumentDeduction.deduceForFunctionCall(template, tmplArgs, fnArgs, argCats, map, point); @@ -1775,9 +1776,9 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM IBinding instance= instantiateFunctionTemplate(template, args, map, point); if (instance instanceof ICPPFunction) { final ICPPFunction f = (ICPPFunction) instance; - if (isValidType(f.getType())) + if (isValidType(f.getType())) return f; - } + } } } catch (DOMException e) { } @@ -1786,7 +1787,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM /** * 14.8.2.3 Deducing conversion function template arguments - * @param point + * @param point */ static ICPPFunction[] instantiateConversionTemplates(ICPPFunction[] functions, IType conversionType, IASTNode point) { boolean checkedForDependentType= false; @@ -1798,7 +1799,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM if (f instanceof ICPPFunctionTemplate) { ICPPFunctionTemplate template= (ICPPFunctionTemplate) f; inst= null; - + // Extract template arguments and parameter types. if (!checkedForDependentType) { try { @@ -1818,12 +1819,12 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM IBinding instance= instantiateFunctionTemplate(template, args, map, point); if (instance instanceof ICPPFunction) { inst= (ICPPFunction) instance; - } + } } } catch (DOMException e) { // try next candidate } - } + } if (result != functions || f != inst) { if (result == functions) { result= new ICPPFunction[functions.length]; @@ -1836,11 +1837,11 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM } return result; } - + /** * 14.8.2.6 Deducing template arguments from a function declaration - * @param point - * @return + * @param point + * @return */ static ICPPFunction instantiateForFunctionDeclaration(ICPPFunctionTemplate template, ICPPTemplateArgument[] args, ICPPFunctionType functionType, IASTNode point) { @@ -1851,7 +1852,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM IBinding instance= instantiateFunctionTemplate(template, args, map, point); if (instance instanceof ICPPFunction) { return (ICPPFunction) instance; - } + } } } catch (DOMException e) { // try next candidate @@ -1863,14 +1864,14 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM /** * 14.8.2.2 Deducing template arguments taking the address of a function template [temp.deduct.funcaddr] */ - static ICPPFunction instantiateForAddressOfFunction(ICPPFunctionTemplate template, IFunctionType target, + static ICPPFunction instantiateForAddressOfFunction(ICPPFunctionTemplate template, IFunctionType target, ICPPTemplateArgument[] args, IASTNode point) { try { if (target != null && isDependentType(target)) { return CPPUnknownFunction.createForSample(template); } - - if (template instanceof ICPPConstructor || args == null) + + if (template instanceof ICPPConstructor || args == null) args= ICPPTemplateArgument.EMPTY_ARGUMENTS; CPPTemplateParameterMap map= new CPPTemplateParameterMap(4); @@ -1879,7 +1880,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM IBinding instance= instantiateFunctionTemplate(template, args, map, point); if (instance instanceof ICPPFunction) { return (ICPPFunction) instance; - } + } } } catch (DOMException e) { } @@ -1895,10 +1896,10 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM return -1; if (f2 == null) return 1; - + int s1 = compareSpecialization(f1, f2, mode, point); int s2 = compareSpecialization(f2, f1, mode, point); - + if (s1 == s2) return 0; if (s1 < 0 || s2 > 0) @@ -1910,7 +1911,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM private static ICPPFunction transferFunctionTemplate(ICPPFunctionTemplate f, IASTNode point) throws DOMException { final ICPPTemplateParameter[] tpars = f.getTemplateParameters(); final int argLen = tpars.length; - + // Create arguments and map ICPPTemplateArgument[] args = new ICPPTemplateArgument[argLen]; CPPTemplateParameterMap map = new CPPTemplateParameterMap(argLen); @@ -1920,7 +1921,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM args[i]= arg; if (tpar.isParameterPack()) { map.put(tpar, new ICPPTemplateArgument[] {arg}); - } else { + } else { map.put(tpar, arg); } } @@ -1928,12 +1929,12 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM IBinding result = instantiateFunctionTemplate(f, args, map, point); if (result instanceof ICPPFunction) return (ICPPFunction) result; - + return null; } private static CPPTemplateArgument uniqueArg(final ICPPTemplateParameter tpar) throws DOMException { - final CPPTemplateArgument arg; + final CPPTemplateArgument arg; if (tpar instanceof ICPPTemplateNonTypeParameter) { arg = new CPPTemplateArgument(Value.unique(), ((ICPPTemplateNonTypeParameter) tpar).getType()); } else { @@ -2047,7 +2048,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM if (bestMatch == null) return null; - + return instantiatePartialSpecialization(bestMatch, args, isDef, bestMap, point); } @@ -2056,7 +2057,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM * is more specialized, = 0 otherwise. * @param spec1 * @param spec2 - * @param point + * @param point * @return * @throws DOMException */ @@ -2095,7 +2096,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM final ICPPTemplateArgument[] targs2 = f2.getTemplateArguments(); if (targs1.length != targs2.length) return false; - + // Transfer arguments of specialization 1 final int tpars1Len = tpars1.length; ICPPTemplateArgument[] args = new ICPPTemplateArgument[tpars1Len]; @@ -2107,12 +2108,12 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM transferMap.put(param, arg); } final ICPPTemplateArgument[] transferredArgs1 = instantiateArguments(targs1, transferMap, -1, null, point); - + // Deduce arguments for specialization 2 final CPPTemplateParameterMap deductionMap= new CPPTemplateParameterMap(2); if (!TemplateArgumentDeduction.fromTemplateArguments(tpars2, targs2, transferredArgs1, deductionMap, point)) return false; - + // Compare for (int i = 0; i < targs2.length; i++) { ICPPTemplateArgument transferredArg2= instantiateArgument(targs2[i], deductionMap, -1, null, point); @@ -2145,12 +2146,12 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM } } } - + static boolean isValidArgument(ICPPTemplateArgument arg) { return arg != null && isValidType(arg.isTypeValue() ? arg.getTypeValue() : arg.getTypeOfNonTypeValue()); } - static ICPPTemplateArgument matchTemplateParameterAndArgument(ICPPTemplateParameter param, + static ICPPTemplateArgument matchTemplateParameterAndArgument(ICPPTemplateParameter param, ICPPTemplateArgument arg, CPPTemplateParameterMap map, IASTNode point) { if (arg == null || !isValidType(arg.getTypeValue())) { return null; @@ -2160,8 +2161,8 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM if (t != null && ! (t instanceof ICPPTemplateDefinition)) return arg; return null; - } - + } + if (param instanceof ICPPTemplateTemplateParameter) { IType t= arg.getTypeValue(); while (!(t instanceof ICPPTemplateDefinition)) { @@ -2186,8 +2187,8 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM } return arg; - } - + } + if (param instanceof ICPPTemplateNonTypeParameter) { if (!arg.isNonTypeValue()) return null; @@ -2204,7 +2205,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM return new CPPTemplateArgument(arg.getNonTypeValue(), pType); } return null; - + } catch (DOMException e) { return null; } @@ -2212,7 +2213,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM assert false; return null; } - + private static boolean matchTemplateTemplateParameters(ICPPTemplateParameter[] pParams, ICPPTemplateParameter[] aParams) throws DOMException { int pi=0; @@ -2220,17 +2221,17 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM while (pi < pParams.length && ai < aParams.length) { final ICPPTemplateParameter pp = pParams[pi]; final ICPPTemplateParameter ap = aParams[ai]; - + // A parameter pack does not match a regular template parameter. if (ap.isParameterPack() && !pp.isParameterPack()) return false; - - + + boolean pb= pp instanceof ICPPTemplateTypeParameter; boolean ab= ap instanceof ICPPTemplateTypeParameter; if (pb != ab) return false; - + if (pb) { // Both are template type parameters } else { @@ -2247,7 +2248,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM assert false; return false; } - + if (!matchTemplateTemplateParameters(((ICPPTemplateTemplateParameter) pp).getTemplateParameters(), ((ICPPTemplateTemplateParameter) ap).getTemplateParameters()) ) return false; @@ -2262,7 +2263,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM return true; return false; } - + return ai == aParams.length; } @@ -2305,7 +2306,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM if (argType == null) return false; } - if (!argType.isSameType((IType) par)) + if (!argType.isSameType((IType) par)) return false; } else { if (arg.isTypeValue()) @@ -2325,11 +2326,11 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM } return false; } - + public static boolean isDependentArgument(ICPPTemplateArgument arg) { - if (arg.isTypeValue()) + if (arg.isTypeValue()) return isDependentType(arg.getTypeValue()); - + return Value.isDependentValue(arg.getNonTypeValue()); } @@ -2348,12 +2349,12 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM } return false; } - + public static boolean isDependentType(IType t) { while (true) { if (t instanceof ICPPUnknownType) return true; - + if (t instanceof ICPPFunctionType) { final ICPPFunctionType ft = (ICPPFunctionType) t; if (containsDependentType(ft.getParameterTypes())) @@ -2385,7 +2386,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM } } } - + public static boolean containsDependentArg(ObjectMap tpMap) { for (Object arg : tpMap.valueArray()) { if (isDependentType((IType)arg)) @@ -2406,7 +2407,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM final IBinding owner= unknown.getOwner(); if (!(owner instanceof ICPPTemplateTypeParameter || owner instanceof ICPPUnknownClassType)) return unknown; - + IBinding result = unknown; IType t = CPPTemplates.instantiateType((IType) owner, tpMap, packOffset, within, point); if (t != null) { @@ -2428,7 +2429,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM } else { result= new CPPUnknownBinding((ICPPUnknownBinding) t, unknown.getNameCharArray()); } - } + } } else if (t instanceof ICPPClassType) { IScope s = ((ICPPClassType) t).getCompositeScope(); if (s != null) { @@ -2445,7 +2446,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM return new ProblemBinding(unknown.getUnknownName(), IProblemBinding.SEMANTIC_BAD_SCOPE); } } - + return result; } @@ -2486,7 +2487,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM public static boolean haveSameArguments(ICPPTemplateInstance i1, ICPPTemplateInstance i2) { final ICPPTemplateArgument[] m1= i1.getTemplateArguments(); final ICPPTemplateArgument[] m2= i2.getTemplateArguments(); - + if (m1 == null || m2 == null || m1.length != m2.length) return false; @@ -2523,7 +2524,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM } return types; } - + /** * @deprecated for backwards compatibility, only. */ @@ -2533,7 +2534,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM Integer[] keys= tpmap.getAllParameterPositions(); if (keys.length == 0) return ObjectMap.EMPTY_MAP; - + List defs= new ArrayList(); IBinding owner= b; while (owner != null) { @@ -2547,7 +2548,7 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM Collections.reverse(defs); ObjectMap result= new ObjectMap(keys.length); - for (int key: keys) { + for (int key : keys) { int nestingLevel= key >> 16; int numParam= key & 0xffff; @@ -2568,9 +2569,9 @@ public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpM public static IBinding findDeclarationForSpecialization(IBinding binding) { while (binding instanceof ICPPSpecialization) { - if (ASTInternal.hasDeclaration(binding)) + if (ASTInternal.hasDeclaration(binding)) return binding; - + IBinding original= ((ICPPSpecialization) binding).getSpecializedBinding(); if (original == null) return binding; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java index 5f90c8de82e..c762f12a9a7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ - + * Markus Schorn - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; @@ -50,7 +49,7 @@ public class EvalBinary implements ICPPEvaluation { private final ICPPEvaluation fArg1; private final ICPPEvaluation fArg2; - + private ICPPFunction fOverload= CPPFunction.UNINITIALIZED_FUNCTION; private IType fType; @@ -81,7 +80,7 @@ public class EvalBinary implements ICPPEvaluation { public boolean isFunctionSet() { return false; } - + @Override public IType getTypeOrFunctionSet(IASTNode point) { if (fType == null) { @@ -121,11 +120,11 @@ public class EvalBinary implements ICPPEvaluation { @Override public ValueCategory getValueCategory(IASTNode point) { - if (isTypeDependent()) + if (isTypeDependent()) return ValueCategory.PRVALUE; - + ICPPFunction overload = getOverload(point); - if (overload != null) + if (overload != null) return ExpressionTypes.valueCategoryFromFunctionCall(overload); switch (fOperator) { @@ -144,12 +143,12 @@ public class EvalBinary implements ICPPEvaluation { return LVALUE; case IASTBinaryExpression.op_pmdot: - if (!(getTypeOrFunctionSet(point) instanceof ICPPFunctionType)) + if (!(getTypeOrFunctionSet(point) instanceof ICPPFunctionType)) return fArg1.getValueCategory(point); break; case IASTBinaryExpression.op_pmarrow: - if (!(getTypeOrFunctionSet(point) instanceof ICPPFunctionType)) + if (!(getTypeOrFunctionSet(point) instanceof ICPPFunctionType)) return LVALUE; break; } @@ -186,15 +185,15 @@ public class EvalBinary implements ICPPEvaluation { public IType computeType(IASTNode point) { // Check for overloaded operator. ICPPFunction o= getOverload(point); - if (o != null) + if (o != null) return typeFromFunctionCall(o); - + final IType originalType1 = fArg1.getTypeOrFunctionSet(point); final IType type1 = prvalueTypeWithResolvedTypedefs(originalType1); if (type1 instanceof ISemanticProblem) { return type1; } - + final IType originalType2 = fArg2.getTypeOrFunctionSet(point); final IType type2 = prvalueTypeWithResolvedTypedefs(originalType2); if (type2 instanceof ISemanticProblem) { @@ -206,7 +205,6 @@ public class EvalBinary implements ICPPEvaluation { return ExpressionTypes.restoreTypedefs(type, originalType1, originalType2); } - switch (fOperator) { case op_arrayAccess: if (type1 instanceof IPointerType) { @@ -216,7 +214,7 @@ public class EvalBinary implements ICPPEvaluation { return glvalueType(((IPointerType) type2).getType()); } return ProblemType.UNKNOWN_FOR_EXPRESSION; - + case IASTBinaryExpression.op_lessEqual: case IASTBinaryExpression.op_lessThan: case IASTBinaryExpression.op_greaterEqual: @@ -230,10 +228,10 @@ public class EvalBinary implements ICPPEvaluation { case IASTBinaryExpression.op_plus: if (type1 instanceof IPointerType) { return ExpressionTypes.restoreTypedefs(type1, originalType1); - } + } if (type2 instanceof IPointerType) { return ExpressionTypes.restoreTypedefs(type2, originalType2); - } + } break; case IASTBinaryExpression.op_minus: @@ -268,7 +266,7 @@ public class EvalBinary implements ICPPEvaluation { buffer.marshalEvaluation(fArg1, includeValue); buffer.marshalEvaluation(fArg2, includeValue); } - + public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { int op= buffer.getByte(); ICPPEvaluation arg1= (ICPPEvaluation) buffer.unmarshalEvaluation(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java index f710e0b834e..7ef770b186a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ - + * Markus Schorn - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; @@ -33,10 +32,10 @@ import org.eclipse.core.runtime.CoreException; public class EvalBinaryTypeId implements ICPPEvaluation { private final Operator fOperator; private final IType fType1, fType2; - + private boolean fCheckedValueDependent; private boolean fIsValueDependent; - + public EvalBinaryTypeId(Operator kind, IType type1, IType type2) { fOperator= kind; fType1= type1; @@ -105,7 +104,7 @@ public class EvalBinaryTypeId implements ICPPEvaluation { buffer.marshalType(fType1); buffer.marshalType(fType2); } - + public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { int op= buffer.getByte(); IType arg1= buffer.unmarshalType(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java index b353d5f4040..8567ea3b666 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ - + * Markus Schorn - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.glvalueType; @@ -35,7 +34,7 @@ import org.eclipse.core.runtime.CoreException; public class EvalBinding implements ICPPEvaluation { private final IBinding fBinding; private final boolean fFixedType; - + private IType fType; private boolean fCheckedIsValueDependent; private boolean fIsValueDependent; @@ -56,7 +55,7 @@ public class EvalBinding implements ICPPEvaluation { public IType getFixedType() { return fFixedType ? fType : null; } - + @Override public boolean isInitializerList() { return false; @@ -75,9 +74,9 @@ public class EvalBinding implements ICPPEvaluation { } return fIsTypeDependent; } - + private boolean computeIsTypeDependent() { - if (fBinding instanceof ICPPUnknownBinding) + if (fBinding instanceof ICPPUnknownBinding) return true; IType t= null; @@ -105,26 +104,26 @@ public class EvalBinding implements ICPPEvaluation { } return fIsValueDependent; } - + private boolean computeIsValueDependent() { if (fBinding instanceof IEnumerator) { return Value.isDependentValue(((IEnumerator) fBinding).getValue()); - } + } if (fBinding instanceof ICPPTemplateNonTypeParameter) { return true; } if (fBinding instanceof IVariable) { return Value.isDependentValue(((IVariable) fBinding).getInitialValue()); - } + } if (fBinding instanceof IFunction) { return false; - } + } if (fBinding instanceof ICPPUnknownBinding) { return true; - } + } return false; } - + @Override public IType getTypeOrFunctionSet(IASTNode point) { if (fType == null) { @@ -132,42 +131,42 @@ public class EvalBinding implements ICPPEvaluation { } return fType; } - + private IType computeType(IASTNode point) { if (fBinding instanceof IEnumerator) { return ((IEnumerator) fBinding).getType(); - } + } if (fBinding instanceof ICPPTemplateNonTypeParameter) { IType type= ((ICPPTemplateNonTypeParameter) fBinding).getType(); if (CPPTemplates.isDependentType(type)) return new TypeOfDependentExpression(this); return prvalueType(type); - } + } if (fBinding instanceof IVariable) { final IType type = ((IVariable) fBinding).getType(); if (CPPTemplates.isDependentType(type)) return new TypeOfDependentExpression(this); return SemanticUtil.mapToAST(glvalueType(type), point); - } + } if (fBinding instanceof IFunction) { final IFunctionType type = ((IFunction) fBinding).getType(); if (CPPTemplates.isDependentType(type)) return new TypeOfDependentExpression(this); return SemanticUtil.mapToAST(type, point); - } + } return ProblemType.UNKNOWN_FOR_EXPRESSION; } - + @Override public IValue getValue(IASTNode point) { return Value.create(this, point); } - + @Override public ValueCategory getValueCategory(IASTNode point) { if (fBinding instanceof ICPPTemplateNonTypeParameter) return ValueCategory.PRVALUE; - + if (fBinding instanceof IVariable || fBinding instanceof IFunction) { return ValueCategory.LVALUE; } @@ -180,7 +179,7 @@ public class EvalBinding implements ICPPEvaluation { buffer.marshalBinding(fBinding); buffer.marshalType(fFixedType ? fType : null); } - + public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { IBinding binding= buffer.unmarshalBinding(); IType type= buffer.unmarshalType(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java index 5925b119095..13a284e8c59 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ - + * Markus Schorn - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.typeFromFunctionCall; @@ -31,9 +30,9 @@ public class EvalComma implements ICPPEvaluation { private final ICPPEvaluation[] fArguments; private ICPPFunction[] fOverloads; - + private IType fType; - + public EvalComma(ICPPEvaluation[] evals) { fArguments= evals; } @@ -54,9 +53,9 @@ public class EvalComma implements ICPPEvaluation { @Override public boolean isTypeDependent() { - if (fType != null) + if (fType != null) return fType instanceof TypeOfDependentExpression; - + for (ICPPEvaluation arg : fArguments) { if (arg.isTypeDependent()) return true; @@ -83,12 +82,12 @@ public class EvalComma implements ICPPEvaluation { private ICPPFunction[] computeOverloads(IASTNode point) { if (fArguments.length < 2) return NO_FUNCTIONS; - + if (isTypeDependent()) return NO_FUNCTIONS; - + ICPPFunction[] overloads = new ICPPFunction[fArguments.length - 1]; - ICPPEvaluation e1= fArguments[0]; + ICPPEvaluation e1= fArguments[0]; for (int i = 1; i < fArguments.length; i++) { ICPPEvaluation e2 = fArguments[i]; ICPPFunction overload = CPPSemantics.findOverloadedOperatorComma(point, e1, e2); @@ -99,7 +98,7 @@ public class EvalComma implements ICPPEvaluation { e1= new EvalFixed(typeFromFunctionCall(overload), valueCategoryFromFunctionCall(overload), Value.UNKNOWN); if (e1.getTypeOrFunctionSet(point) instanceof ISemanticProblem) { e1= e2; - } + } } } return overloads; @@ -112,11 +111,11 @@ public class EvalComma implements ICPPEvaluation { } return fType; } - + private IType computeType(IASTNode point) { if (isTypeDependent()) { return new TypeOfDependentExpression(this); - } + } ICPPFunction[] overloads = getOverloads(point); if (overloads.length > 0) { ICPPFunction last = overloads[overloads.length - 1]; @@ -126,7 +125,7 @@ public class EvalComma implements ICPPEvaluation { } return fArguments[fArguments.length-1].getTypeOrFunctionSet(point); } - + @Override public IValue getValue(IASTNode point) { return Value.create(this, point); @@ -152,7 +151,7 @@ public class EvalComma implements ICPPEvaluation { buffer.marshalEvaluation(arg, includeValue); } } - + public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { int len= buffer.getShort(); ICPPEvaluation[] args = new ICPPEvaluation[len]; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompound.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompound.java index c602e10c936..f4621924a41 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompound.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompound.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ - + * Markus Schorn - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; @@ -77,7 +76,7 @@ public class EvalCompound implements ICPPEvaluation { buffer.putByte(ITypeMarshalBuffer.EVAL_COMPOUND); buffer.marshalEvaluation(fDelegate, includeValue); } - + public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { ICPPEvaluation arg= (ICPPEvaluation) buffer.unmarshalEvaluation(); return new EvalCompound(arg); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConditional.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConditional.java index 023e432448f..67bc4c3c1ee 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConditional.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConditional.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ - + * Markus Schorn - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; @@ -45,12 +44,12 @@ import org.eclipse.core.runtime.CoreException; public class EvalConditional implements ICPPEvaluation { private final ICPPEvaluation fCondition, fPositive, fNegative; private final boolean fPositiveThrows, fNegativeThrows; - + private ValueCategory fValueCategory; private IType fType; private ICPPFunction fOverload; - + public EvalConditional(ICPPEvaluation arg1, ICPPEvaluation arg2, ICPPEvaluation arg3, boolean positiveThrows, boolean negativeThrows) { // Gnu-extension: Empty positive expression is replaced by condition. @@ -85,7 +84,7 @@ public class EvalConditional implements ICPPEvaluation { public boolean isInitializerList() { return false; } - + @Override public boolean isFunctionSet() { return false; @@ -95,7 +94,7 @@ public class EvalConditional implements ICPPEvaluation { evaluate(point); return fOverload; } - + @Override public IType getTypeOrFunctionSet(IASTNode point) { evaluate(point); @@ -106,36 +105,36 @@ public class EvalConditional implements ICPPEvaluation { public IValue getValue(IASTNode point) { return Value.create(this, point); } - + @Override public ValueCategory getValueCategory(IASTNode point) { evaluate(point); return fValueCategory; } - + @Override public boolean isTypeDependent() { final ICPPEvaluation positive = fPositive == null ? fCondition : fPositive; return positive.isTypeDependent() || fNegative.isTypeDependent(); } - + @Override public boolean isValueDependent() { return fCondition.isValueDependent() || (fPositive != null && fPositive.isValueDependent()) || fNegative.isValueDependent(); } - + private void evaluate(IASTNode point) { if (fValueCategory != null) return; - + fValueCategory= PRVALUE; - + final ICPPEvaluation positive = fPositive == null ? fCondition : fPositive; - + IType t2 = positive.getTypeOrFunctionSet(point); IType t3 = fNegative.getTypeOrFunctionSet(point); - + final IType uqt2= getNestedType(t2, TDEF | REF | CVTYPE); final IType uqt3= getNestedType(t3, TDEF | REF | CVTYPE); if (uqt2 instanceof ISemanticProblem || uqt2 instanceof ICPPUnknownType) { @@ -146,7 +145,7 @@ public class EvalConditional implements ICPPEvaluation { fType= uqt3; return; } - + final boolean void2= isVoidType(uqt2); final boolean void3= isVoidType(uqt3); @@ -163,7 +162,7 @@ public class EvalConditional implements ICPPEvaluation { } return; } - + final ValueCategory vcat2= positive.getValueCategory(point); final ValueCategory vcat3= fNegative.getValueCategory(point); @@ -177,8 +176,8 @@ public class EvalConditional implements ICPPEvaluation { fValueCategory= PRVALUE; } return; - } - + } + final boolean isClassType2 = uqt2 instanceof ICPPClassType; final boolean isClassType3 = uqt3 instanceof ICPPClassType; @@ -211,7 +210,7 @@ public class EvalConditional implements ICPPEvaluation { } return; } - + // 5.16-5: At least one class type but no conversion if (isClassType2 || isClassType3) { fOverload = CPPSemantics.findOverloadedConditionalOperator(point, positive, fNegative); @@ -293,13 +292,13 @@ public class EvalConditional implements ICPPEvaluation { firstByte |= ITypeMarshalBuffer.FLAG1; if (fNegativeThrows) firstByte |= ITypeMarshalBuffer.FLAG2; - + buffer.putByte((byte) firstByte); buffer.marshalEvaluation(fCondition, includeValue); buffer.marshalEvaluation(fPositive, includeValue); buffer.marshalEvaluation(fNegative, includeValue); } - + public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { boolean pth= (firstByte & ITypeMarshalBuffer.FLAG1) != 0; boolean nth= (firstByte & ITypeMarshalBuffer.FLAG2) != 0; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFixed.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFixed.java index 28d1ba27c61..fbd99448f59 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFixed.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFixed.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ - + * Markus Schorn - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; @@ -30,9 +29,9 @@ import org.eclipse.core.runtime.CoreException; * Performs evaluation of an expression. */ public class EvalFixed implements ICPPEvaluation { - public static final ICPPEvaluation INCOMPLETE = new EvalFixed( - ProblemType.UNKNOWN_FOR_EXPRESSION, PRVALUE, Value.UNKNOWN); - + public static final ICPPEvaluation INCOMPLETE = + new EvalFixed(ProblemType.UNKNOWN_FOR_EXPRESSION, PRVALUE, Value.UNKNOWN); + private final IType fType; private final IValue fValue; private final ValueCategory fValueCategory; @@ -108,7 +107,7 @@ public class EvalFixed implements ICPPEvaluation { int firstByte = ITypeMarshalBuffer.EVAL_FIXED; if (includeValue) firstByte |= ITypeMarshalBuffer.FLAG1; - switch(fValueCategory) { + switch (fValueCategory) { case LVALUE: firstByte |= ITypeMarshalBuffer.FLAG2; break; @@ -118,30 +117,30 @@ public class EvalFixed implements ICPPEvaluation { default: break; } - + buffer.putByte((byte) firstByte); buffer.marshalType(fType); if (includeValue) { buffer.marshalValue(fValue); } } - + public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { final boolean readValue= (firstByte & ITypeMarshalBuffer.FLAG1) != 0; IValue value; ValueCategory cat; switch (firstByte & (ITypeMarshalBuffer.FLAG2 | ITypeMarshalBuffer.FLAG3)) { - case ITypeMarshalBuffer.FLAG2: - cat= LVALUE; - break; - case ITypeMarshalBuffer.FLAG3: - cat= PRVALUE; - break; - default: - cat= XVALUE; - break; + case ITypeMarshalBuffer.FLAG2: + cat= LVALUE; + break; + case ITypeMarshalBuffer.FLAG3: + cat= PRVALUE; + break; + default: + cat= XVALUE; + break; } - + IType type= buffer.unmarshalType(); value= readValue ? buffer.unmarshalValue() : Value.UNKNOWN; return new EvalFixed(type, cat, value); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java index dde693d47b3..2c2db81fb2e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ - + * Markus Schorn - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.typeFromReturnType; @@ -41,7 +40,7 @@ public class EvalFunctionCall implements ICPPEvaluation { private final ICPPEvaluation[] fArguments; private ICPPFunction fOverload= CPPFunction.UNINITIALIZED_FUNCTION; private IType fType; - + public EvalFunctionCall(ICPPEvaluation[] args) { fArguments= args; } @@ -88,36 +87,36 @@ public class EvalFunctionCall implements ICPPEvaluation { private ICPPFunction computeOverload(IASTNode point) { if (isTypeDependent()) return null; - + IType t= SemanticUtil.getNestedType(fArguments[0].getTypeOrFunctionSet(point), TDEF|REF|CVTYPE); if (t instanceof ICPPClassType) { return CPPSemantics.findOverloadedOperator(point, fArguments, t, OverloadableOperator.PAREN, LookupMode.NO_GLOBALS); } return null; } - + @Override public IType getTypeOrFunctionSet(IASTNode point) { - if (fType == null) + if (fType == null) fType= computeType(point); return fType; } - + private IType computeType(IASTNode point) { - if (isTypeDependent()) + if (isTypeDependent()) return new TypeOfDependentExpression(this); - + ICPPFunction overload = getOverload(point); - if (overload != null) + if (overload != null) return ExpressionTypes.typeFromFunctionCall(overload); - + final ICPPEvaluation arg0 = fArguments[0]; IType t= SemanticUtil.getNestedType(arg0.getTypeOrFunctionSet(point), TDEF|REF|CVTYPE); if (t instanceof ICPPClassType) { return new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION); } - + if (t instanceof IPointerType) { t= SemanticUtil.getNestedType(((IPointerType) t).getType(), TDEF | REF | CVTYPE); } @@ -142,7 +141,7 @@ public class EvalFunctionCall implements ICPPEvaluation { if (overload != null) return valueCategoryFromFunctionCall(overload); - + IType t= fArguments[0].getTypeOrFunctionSet(point); if (t instanceof IPointerType) { t= SemanticUtil.getNestedType(((IPointerType) t).getType(), TDEF | REF | CVTYPE); @@ -161,7 +160,7 @@ public class EvalFunctionCall implements ICPPEvaluation { buffer.marshalEvaluation(arg, includeValue); } } - + public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { int len= buffer.getShort(); ICPPEvaluation[] args = new ICPPEvaluation[len]; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java index 4be4f8ac06c..ce16b11a6b4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ - + * Markus Schorn - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; @@ -32,7 +31,7 @@ import org.eclipse.core.runtime.CoreException; public class EvalFunctionSet implements ICPPEvaluation { private final CPPFunctionSet fFunctionSet; private final boolean fAddressOf; - + public EvalFunctionSet(CPPFunctionSet set, boolean addressOf) { fFunctionSet= set; fAddressOf= addressOf; @@ -101,7 +100,7 @@ public class EvalFunctionSet implements ICPPEvaluation { firstByte |= ITypeMarshalBuffer.FLAG1; if (args != null) firstByte |= ITypeMarshalBuffer.FLAG2; - + buffer.putByte((byte) firstByte); buffer.putShort((short) bindings.length); for (ICPPFunction binding : bindings) { @@ -111,7 +110,7 @@ public class EvalFunctionSet implements ICPPEvaluation { // mstodo marshall arguments } } - + public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { final boolean addressOf= (firstByte & ITypeMarshalBuffer.FLAG1) != 0; int bindingCount= buffer.getShort(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java index 3bf54753c7b..962def2afec 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ - + * Markus Schorn - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; @@ -60,7 +59,7 @@ public class EvalID implements ICPPEvaluation { fQualified= qualified; fTemplateArgs= templateArgs; } - + public ICPPEvaluation getFieldOwner() { return fFieldOwner; } @@ -68,7 +67,7 @@ public class EvalID implements ICPPEvaluation { public IBinding getNameOwner() { return fNameOwner; } - + public char[] getName() { return fName; } @@ -80,11 +79,11 @@ public class EvalID implements ICPPEvaluation { public boolean isQualified() { return fQualified; } - + public ICPPTemplateArgument[] getTemplateArgs() { return fTemplateArgs; } - + @Override public boolean isInitializerList() { return false; @@ -99,22 +98,22 @@ public class EvalID implements ICPPEvaluation { public boolean isTypeDependent() { return true; } - + @Override public boolean isValueDependent() { return true; } - + @Override public IType getTypeOrFunctionSet(IASTNode point) { return new TypeOfDependentExpression(this); } - + @Override public IValue getValue(IASTNode point) { return Value.create(this, point); } - + @Override public ValueCategory getValueCategory(IASTNode point) { return PRVALUE; @@ -129,7 +128,7 @@ public class EvalID implements ICPPEvaluation { firstByte |= ITypeMarshalBuffer.FLAG2; if (fTemplateArgs != null) firstByte |= ITypeMarshalBuffer.FLAG3; - + buffer.putByte((byte) firstByte); buffer.marshalEvaluation(fFieldOwner, false); buffer.putCharArray(fName); @@ -138,7 +137,7 @@ public class EvalID implements ICPPEvaluation { // mstodo marshall arguments } } - + public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { final boolean addressOf= (firstByte & ITypeMarshalBuffer.FLAG1) != 0; final boolean qualified= (firstByte & ITypeMarshalBuffer.FLAG2) != 0; @@ -155,7 +154,7 @@ public class EvalID implements ICPPEvaluation { public static ICPPEvaluation create(IASTIdExpression expr) { final IASTName name = expr.getName(); IBinding binding = name.resolvePreBinding(); - if (binding instanceof IProblemBinding || binding instanceof IType || binding instanceof ICPPConstructor) + if (binding instanceof IProblemBinding || binding instanceof IType || binding instanceof ICPPConstructor) return EvalFixed.INCOMPLETE; if (binding instanceof CPPFunctionSet) { return new EvalFunctionSet((CPPFunctionSet) binding, isAddressOf(expr)); @@ -164,7 +163,7 @@ public class EvalID implements ICPPEvaluation { IBinding owner = binding.getOwner(); if (owner instanceof IProblemBinding) return EvalFixed.INCOMPLETE; - + ICPPEvaluation fieldOwner= null; IType fieldOwnerType= withinNonStaticMethod(expr); if (fieldOwnerType != null) { @@ -175,20 +174,20 @@ public class EvalID implements ICPPEvaluation { if (lastName instanceof ICPPASTTemplateId) { templateArgs= CPPTemplates.createTemplateArgumentArray((ICPPASTTemplateId) lastName); } - return new EvalID(fieldOwner, owner, name.getSimpleID(), isAddressOf(expr), + return new EvalID(fieldOwner, owner, name.getSimpleID(), isAddressOf(expr), name instanceof ICPPASTQualifiedName, templateArgs); } /** - * 9.3.1-3 Transformation to class member access within a non-static member function. + * 9.3.1-3 Transformation to class member access within a non-static member function. */ - if (binding instanceof ICPPMember && !(binding instanceof IType) + if (binding instanceof ICPPMember && !(binding instanceof IType) && !(binding instanceof ICPPConstructor) &&!((ICPPMember) binding).isStatic()) { IType fieldOwnerType= withinNonStaticMethod(expr); if (fieldOwnerType != null) { return new EvalMemberAccess(fieldOwnerType, LVALUE, binding, true); } } - + if (binding instanceof IEnumerator) { IType type= ((IEnumerator) binding).getType(); if (type instanceof ICPPEnumeration) { @@ -206,7 +205,7 @@ public class EvalID implements ICPPEvaluation { } } return new EvalBinding(binding, null); - } + } if (binding instanceof ICPPTemplateNonTypeParameter || binding instanceof IVariable || binding instanceof IFunction) { return new EvalBinding(binding, null); @@ -239,7 +238,7 @@ public class EvalID implements ICPPEvaluation { e= unary.getOperand(); } else { return op == IASTUnaryExpression.op_amper; - } + } } return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalInitList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalInitList.java index 408f9cfac5f..3b5e432cf2b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalInitList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalInitList.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ - + * Markus Schorn - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; @@ -32,7 +31,7 @@ public class EvalInitList implements ICPPEvaluation { public EvalInitList(ICPPEvaluation[] clauses) { fClauses= clauses; } - + public ICPPEvaluation[] getClauses() { return fClauses; } @@ -88,7 +87,7 @@ public class EvalInitList implements ICPPEvaluation { buffer.marshalEvaluation(arg, includeValue); } } - + public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { int len= buffer.getShort(); ICPPEvaluation[] args = new ICPPEvaluation[len]; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java index 8123662d07d..e6eb6eb4437 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ - + * Markus Schorn - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; @@ -70,7 +69,7 @@ public class EvalMemberAccess implements ICPPEvaluation { public IType getOwnerType() { return fOwnerType; } - + public ValueCategory getOwnerValueCategory() { return fOwnerValueCategory; } @@ -101,7 +100,7 @@ public class EvalMemberAccess implements ICPPEvaluation { } return fIsTypeDependent; } - + private boolean computeIsTypeDependent() { IType t; if (fMember instanceof ICPPUnknownBinding) { @@ -126,71 +125,71 @@ public class EvalMemberAccess implements ICPPEvaluation { } return fIsValueDependent; } - + private boolean computeIsValueDependent() { if (fMember instanceof ICPPUnknownBinding) { return true; - } + } if (fMember instanceof IEnumerator) { return Value.isDependentValue(((IEnumerator) fMember).getValue()); - } + } if (fMember instanceof IVariable) { return Value.isDependentValue(((IVariable) fMember).getInitialValue()); - } + } if (fMember instanceof IFunction) { return false; - } + } return false; } - + public static IType getFieldOwnerType(IType fieldOwnerExpressionType, boolean isDeref, IASTNode point, Collection functionBindings, boolean returnUnnamed) { IType type= fieldOwnerExpressionType; if (!isDeref) return type; - - // Bug 205964: as long as the type is a class type, recurse. + + // Bug 205964: as long as the type is a class type, recurse. // Be defensive and allow a max of 20 levels. for (int j = 0; j < 20; j++) { IType classType= getUltimateTypeUptoPointers(type); - if (!(classType instanceof ICPPClassType)) + if (!(classType instanceof ICPPClassType)) break; - + IScope scope = ((ICPPClassType) classType).getCompositeScope(); if (scope == null || scope instanceof ICPPInternalUnknownScope) break; - + /* * 13.5.6-1: An expression x->m is interpreted as (x.operator->())->m for a * class object x of type T - * + * * Construct an AST fragment for x.operator-> which the lookup routines can * examine for type information. */ - + ICPPEvaluation[] args= {new EvalFixed(type, LVALUE, Value.UNKNOWN)}; ICPPFunction op= CPPSemantics.findOverloadedOperator(point, args, classType, OverloadableOperator.ARROW, LookupMode.NO_GLOBALS); - if (op == null) + if (op == null) break; if (functionBindings != null) functionBindings.add(op); - + type= typeFromFunctionCall(op); type= SemanticUtil.mapToAST(type, point); } - + IType prValue= prvalueTypeWithResolvedTypedefs(type); if (prValue instanceof IPointerType) { return glvalueType(((IPointerType) prValue).getType()); } - + if (CPPTemplates.isDependentType(type)) return returnUnnamed ? CPPUnknownClass.createUnnamedInstance() : null; return new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION); } - + @Override public IType getTypeOrFunctionSet(IASTNode point) { if (fType == null) { @@ -198,14 +197,14 @@ public class EvalMemberAccess implements ICPPEvaluation { } return fType; } - + private IType computeType(IASTNode point) { if (fMember instanceof ICPPUnknownBinding) { return new TypeOfDependentExpression(this); } if (fMember instanceof IEnumerator) { return ((IEnumerator) fMember).getType(); - } + } if (fMember instanceof IVariable) { IType e2 = ((IVariable) fMember).getType(); e2= SemanticUtil.getNestedType(e2, TDEF); @@ -220,15 +219,15 @@ public class EvalMemberAccess implements ICPPEvaluation { } else { e2= glvalueType(e2); } - } + } return SemanticUtil.mapToAST(e2, point); - } + } if (fMember instanceof IFunction) { return SemanticUtil.mapToAST(((IFunction) fMember).getType(), point); } return ProblemType.UNKNOWN_FOR_EXPRESSION; } - + private IType addQualifiersForAccess(ICPPField field, IType fieldType, IType ownerType) { CVQualifier cvq1 = SemanticUtil.getCVQualifier(ownerType); CVQualifier cvq2 = SemanticUtil.getCVQualifier(fieldType); @@ -248,7 +247,7 @@ public class EvalMemberAccess implements ICPPEvaluation { public IValue getValue(IASTNode point) { return Value.create(this, point); } - + @Override public ValueCategory getValueCategory(IASTNode point) { if (fMember instanceof IVariable) { @@ -256,7 +255,7 @@ public class EvalMemberAccess implements ICPPEvaluation { e2= SemanticUtil.getNestedType(e2, TDEF); if (e2 instanceof ICPPReferenceType) { return LVALUE; - } + } if (fMember instanceof ICPPField && !((ICPPField) fMember).isStatic()) { if (fIsPointerDeref) return LVALUE; @@ -264,7 +263,7 @@ public class EvalMemberAccess implements ICPPEvaluation { return fOwnerValueCategory; } return LVALUE; - } + } if (fMember instanceof IFunction) { return LVALUE; } @@ -281,12 +280,12 @@ public class EvalMemberAccess implements ICPPEvaluation { } else if (fOwnerValueCategory == XVALUE) { firstByte |= ITypeMarshalBuffer.FLAG3; } - + buffer.putByte((byte) firstByte); buffer.marshalType(fOwnerType); buffer.marshalBinding(fMember); } - + public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { boolean isDeref= (firstByte & ITypeMarshalBuffer.FLAG1) != 0; ValueCategory ownerValueCat; @@ -297,7 +296,7 @@ public class EvalMemberAccess implements ICPPEvaluation { } else { ownerValueCat= PRVALUE; } - + IType ownerType= buffer.unmarshalType(); IBinding member= buffer.unmarshalBinding(); return new EvalMemberAccess(ownerType, ownerValueCat, member, isDeref); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java index d788d3204a3..7ffadea8273 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ - + * Markus Schorn - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.typeFromReturnType; @@ -31,7 +30,7 @@ public class EvalTypeId implements ICPPEvaluation { private final IType fInputType; private final ICPPEvaluation[] fArguments; private IType fOutputType; - + public EvalTypeId(IType type, ICPPEvaluation... argument) { fInputType= type; fArguments= argument; @@ -44,7 +43,7 @@ public class EvalTypeId implements ICPPEvaluation { public ICPPEvaluation[] getArguments() { return fArguments; } - + @Override public boolean isInitializerList() { return false; @@ -62,7 +61,7 @@ public class EvalTypeId implements ICPPEvaluation { } return fOutputType; } - + private IType computeType() { if (CPPTemplates.isDependentType(fInputType)) return new TypeOfDependentExpression(this); @@ -103,7 +102,7 @@ public class EvalTypeId implements ICPPEvaluation { int firstByte = ITypeMarshalBuffer.EVAL_TYPE_ID; if (includeValue) firstByte |= ITypeMarshalBuffer.FLAG1; - + buffer.putByte((byte) firstByte); buffer.marshalType(fInputType); if (includeValue) { @@ -113,7 +112,7 @@ public class EvalTypeId implements ICPPEvaluation { } } } - + public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { IType type= buffer.unmarshalType(); ICPPEvaluation[] args= null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java index 3faecff3a4c..2058d62e861 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ - + * Markus Schorn - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; @@ -42,12 +41,12 @@ import org.eclipse.core.runtime.CoreException; public class EvalUnary implements ICPPEvaluation { private static final ICPPEvaluation ZERO_EVAL = new EvalFixed(CPPSemantics.INT_TYPE, PRVALUE, Value.create(0)); - + private final int fOperator; private final ICPPEvaluation fArgument; private ICPPFunction fOverload= CPPFunction.UNINITIALIZED_FUNCTION; private IType fType; - + public EvalUnary(int operator, ICPPEvaluation operand) { fOperator= operator; fArgument= operand; @@ -60,7 +59,7 @@ public class EvalUnary implements ICPPEvaluation { public ICPPEvaluation getArgument() { return fArgument; } - + @Override public boolean isInitializerList() { return false; @@ -73,7 +72,7 @@ public class EvalUnary implements ICPPEvaluation { @Override public boolean isTypeDependent() { - if (fType != null) + if (fType != null) return fType instanceof TypeOfDependentExpression; switch(fOperator) { @@ -115,10 +114,10 @@ public class EvalUnary implements ICPPEvaluation { OverloadableOperator op = OverloadableOperator.fromUnaryExpression(fOperator); if (op == null) return null; - + if (fArgument.isTypeDependent()) return null; - + IType type = fArgument.getTypeOrFunctionSet(point); type = SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE); if (!CPPSemantics.isUserDefined(type)) @@ -132,20 +131,20 @@ public class EvalUnary implements ICPPEvaluation { } return CPPSemantics.findOverloadedOperator(point, args, type, op, LookupMode.LIMITED_GLOBALS); } - + @Override public IType getTypeOrFunctionSet(IASTNode point) { - if (fType == null) + if (fType == null) fType= computeType(point); return fType; } - + private IType computeType(IASTNode point) { - if (isTypeDependent()) + if (isTypeDependent()) return new TypeOfDependentExpression(this); - + ICPPFunction overload = getOverload(point); - if (overload != null) + if (overload != null) return ExpressionTypes.typeFromFunctionCall(overload); switch (fOperator) { @@ -163,7 +162,7 @@ public class EvalUnary implements ICPPEvaluation { type = prvalueTypeWithResolvedTypedefs(type); if (type instanceof IPointerType) { return glvalueType(((IPointerType) type).getType()); - } + } if (type instanceof ISemanticProblem) { return type; } @@ -212,7 +211,7 @@ public class EvalUnary implements ICPPEvaluation { buffer.putByte((byte) fOperator); buffer.marshalEvaluation(fArgument, includeValue); } - + public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { int op= buffer.getByte(); ICPPEvaluation arg= (ICPPEvaluation) buffer.unmarshalEvaluation(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java index 7c2ad77d1ad..c40d89f1011 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ - + * Markus Schorn - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; @@ -31,7 +30,7 @@ public class EvalUnaryTypeID implements ICPPEvaluation { private final int fOperator; private final IType fOrigType; private IType fType; - + public EvalUnaryTypeID(int operator, IType type) { fOperator= operator; fOrigType= type; @@ -44,7 +43,7 @@ public class EvalUnaryTypeID implements ICPPEvaluation { public IType getArgument() { return fOrigType; } - + @Override public boolean isInitializerList() { return false; @@ -82,7 +81,7 @@ public class EvalUnaryTypeID implements ICPPEvaluation { case op_is_polymorphic: case op_is_union: return CPPTemplates.isDependentType(fOrigType); - + case op_typeid: case op_typeof: return false; @@ -92,11 +91,11 @@ public class EvalUnaryTypeID implements ICPPEvaluation { @Override public IType getTypeOrFunctionSet(IASTNode point) { - if (fType == null) + if (fType == null) fType= computeType(point); return fType; } - + private IType computeType(IASTNode point) { switch (fOperator) { case op_sizeof: @@ -120,7 +119,7 @@ public class EvalUnaryTypeID implements ICPPEvaluation { case op_is_union: return CPPBasicType.BOOLEAN; case op_typeof: - if (isTypeDependent()) + if (isTypeDependent()) return new TypeOfDependentExpression(this); return fOrigType; } @@ -143,7 +142,7 @@ public class EvalUnaryTypeID implements ICPPEvaluation { buffer.putByte((byte) fOperator); buffer.marshalType(fType); } - + public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { int op= buffer.getByte(); IType arg= buffer.unmarshalType(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java index bd5e6a46b61..5c3b1646143 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java @@ -7,7 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation - *******************************************************************************/ + *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.db; import org.eclipse.cdt.core.CCorePlugin; @@ -29,13 +29,13 @@ import org.eclipse.core.runtime.CoreException; * For marshalling types to byte arrays. */ public class TypeMarshalBuffer implements ITypeMarshalBuffer { - public final static byte[] EMPTY= { 0, 0, 0, 0, 0, 0 }; - public final static byte NULL_TYPE= 0; - public final static byte INDIRECT_TYPE= (byte) -1; - public final static byte BINDING_TYPE= (byte) -2; - public final static byte UNSTORABLE_TYPE= (byte) -3; - - public final static IType UNSTORABLE_TYPE_PROBLEM = new ProblemType(ISemanticProblem.TYPE_NOT_PERSISTED); + public static final byte[] EMPTY= { 0, 0, 0, 0, 0, 0 }; + public static final byte NULL_TYPE= 0; + public static final byte INDIRECT_TYPE= (byte) -1; + public static final byte BINDING_TYPE= (byte) -2; + public static final byte UNSTORABLE_TYPE= (byte) -3; + + public static final IType UNSTORABLE_TYPE_PROBLEM = new ProblemType(ISemanticProblem.TYPE_NOT_PERSISTED); static { assert EMPTY.length == Database.TYPE_SIZE; @@ -83,14 +83,14 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer { putByte((byte) 0); putRecordPointer(pb.getRecord()); } - } + } } @Override public IBinding unmarshalBinding() throws CoreException { if (fPos >= fBuffer.length) throw unmarshallingError(); - + byte firstByte= fBuffer[fPos]; if (firstByte == BINDING_TYPE) { fPos+= 2; @@ -99,12 +99,12 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer { } else if (firstByte == NULL_TYPE || firstByte == UNSTORABLE_TYPE) { fPos++; return null; - } - + } + IType type= fLinkage.unmarshalType(this); if (type == null || type instanceof IBinding) return (IBinding) type; - + throw unmarshallingError(); } @@ -126,10 +126,10 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer { public IType unmarshalType() throws CoreException { if (fPos >= fBuffer.length) throw unmarshallingError(); - + byte firstByte= fBuffer[fPos]; if (firstByte == BINDING_TYPE) { - fPos+= 2; + fPos += 2; long rec= getRecordPointer(); return (IType) fLinkage.getNode(rec); } else if (firstByte == NULL_TYPE) { @@ -139,7 +139,7 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer { fPos++; return UNSTORABLE_TYPE_PROBLEM; } - + return fLinkage.unmarshalType(this); } @@ -150,18 +150,18 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer { } else { eval.marshal(this, includeValues); } - } - + } + @Override public ISerializableEvaluation unmarshalEvaluation() throws CoreException { if (fPos >= fBuffer.length) throw unmarshallingError(); - + byte firstByte= fBuffer[fPos]; if (firstByte == NULL_TYPE) { fPos++; return null; - } + } return fLinkage.unmarshalEvaluation(this); } @@ -171,14 +171,14 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer { ((Value) value).marshall(this); } else { putByte(NULL_TYPE); - } + } } @Override public IValue unmarshalValue() throws CoreException { if (fPos >= fBuffer.length) throw unmarshallingError(); - + return Value.unmarshal(this); } @@ -209,7 +209,7 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer { @Override public int getByte() throws CoreException { - if (fPos+1 > fBuffer.length) + if (fPos + 1 > fBuffer.length) throw unmarshallingError(); return 0xff & fBuffer[fPos++]; } @@ -218,6 +218,7 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer { public CoreException unmarshallingError() { return new CoreException(CCorePlugin.createStatus("Unmarshalling error")); //$NON-NLS-1$ } + public CoreException marshallingError() { return new CoreException(CCorePlugin.createStatus("Marshalling error")); //$NON-NLS-1$ } @@ -225,31 +226,31 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer { @Override public void putShort(short value) { request(2); - fBuffer[fPos++]= (byte)(value >> 8); - fBuffer[fPos++]= (byte)(value); + fBuffer[fPos++]= (byte) (value >> 8); + fBuffer[fPos++]= (byte) (value); } @Override public int getShort() throws CoreException { - if (fPos+2 > fBuffer.length) + if (fPos + 2 > fBuffer.length) throw unmarshallingError(); final int byte1 = 0xff & fBuffer[fPos++]; final int byte2 = 0xff & fBuffer[fPos++]; return (((byte1 << 8) | (byte2 & 0xff))); } - + public void putInt(int value) { request(4); fPos += 4; int p= fPos; - fBuffer[--p]= (byte)(value); value >>= 8; - fBuffer[--p]= (byte)(value); value >>= 8; - fBuffer[--p]= (byte)(value); value >>= 8; - fBuffer[--p]= (byte)(value); + fBuffer[--p]= (byte) (value); value >>= 8; + fBuffer[--p]= (byte) (value); value >>= 8; + fBuffer[--p]= (byte) (value); value >>= 8; + fBuffer[--p]= (byte) (value); } public int getInt() throws CoreException { - if (fPos+4 > fBuffer.length) + if (fPos + 4 > fBuffer.length) throw unmarshallingError(); int result= 0; result |= fBuffer[fPos++] & 0xff; result <<= 8; @@ -264,19 +265,19 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer { request(8); fPos += 8; int p= fPos; - fBuffer[--p]= (byte)(value); value >>= 8; - fBuffer[--p]= (byte)(value); value >>= 8; - fBuffer[--p]= (byte)(value); value >>= 8; - fBuffer[--p]= (byte)(value); value >>= 8; - fBuffer[--p]= (byte)(value); value >>= 8; - fBuffer[--p]= (byte)(value); value >>= 8; - fBuffer[--p]= (byte)(value); value >>= 8; - fBuffer[--p]= (byte)(value); + fBuffer[--p]= (byte) (value); value >>= 8; + fBuffer[--p]= (byte) (value); value >>= 8; + fBuffer[--p]= (byte) (value); value >>= 8; + fBuffer[--p]= (byte) (value); value >>= 8; + fBuffer[--p]= (byte) (value); value >>= 8; + fBuffer[--p]= (byte) (value); value >>= 8; + fBuffer[--p]= (byte) (value); value >>= 8; + fBuffer[--p]= (byte) (value); } @Override public long getLong() throws CoreException { - if (fPos+8 > fBuffer.length) + if (fPos + 8 > fBuffer.length) throw unmarshallingError(); long result= 0; result |= fBuffer[fPos++] & 0xff; result <<= 8; @@ -293,7 +294,7 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer { private void putRecordPointer(long record) { request(Database.PTR_SIZE); Chunk.putRecPtr(record, fBuffer, fPos); - fPos+= Database.PTR_SIZE; + fPos += Database.PTR_SIZE; } private long getRecordPointer() throws CoreException { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java index d2e86cd34c4..decd3d170cb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java @@ -13,11 +13,6 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; @@ -119,6 +114,11 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.core.runtime.CoreException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + /** * Container for c++-entities. */ @@ -127,15 +127,15 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { public final static int CACHE_BASES= 1; public final static int CACHE_INSTANCES= 2; public final static int CACHE_INSTANCE_SCOPE= 3; - + private final static int FIRST_NAMESPACE_CHILD_OFFSET= PDOMLinkage.RECORD_SIZE; - + @SuppressWarnings("hiding") private final static int RECORD_SIZE= FIRST_NAMESPACE_CHILD_OFFSET + Database.PTR_SIZE; // Only used when writing to database, which is single-threaded - private final LinkedList postProcesses = new LinkedList(); - + private final LinkedList postProcesses = new LinkedList(); + public PDOMCPPLinkage(PDOM pdom, long record) { super(pdom, record); } @@ -168,13 +168,13 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { class ConfigureTemplateParameters implements Runnable { private final IPDOMCPPTemplateParameter[] fPersisted; private final ICPPTemplateParameter[] fOriginal; - + public ConfigureTemplateParameters(ICPPTemplateParameter[] original, IPDOMCPPTemplateParameter[] params) { fOriginal= original; fPersisted= params; postProcesses.add(this); } - + @Override public void run() { for (int i = 0; i < fOriginal.length; i++) { @@ -184,18 +184,18 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { } } } - + class ConfigurePartialSpecialization implements Runnable { IPDOMPartialSpecialization partial; ICPPClassTemplatePartialSpecialization binding; - + public ConfigurePartialSpecialization(IPDOMPartialSpecialization partial, ICPPClassTemplatePartialSpecialization binding) { this.partial = partial; this.binding = binding; postProcesses.add(this); } - + @Override public void run() { try { @@ -209,7 +209,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { } } } - + class ConfigureFunctionTemplate implements Runnable { private final PDOMCPPFunctionTemplate fTemplate; private final IPDOMCPPTemplateParameter[] fTemplateParameters; @@ -217,7 +217,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { private final ICPPFunctionType fOriginalFunctionType; private final ICPPParameter[] fOriginalParameters; private final IType[] fOriginalExceptionSpec; - + public ConfigureFunctionTemplate(ICPPFunctionTemplate original, PDOMCPPFunctionTemplate template) throws DOMException { fTemplate = template; fTemplateParameters= template.getTemplateParameters(); @@ -227,7 +227,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { fOriginalExceptionSpec= template.extractExceptionSpec(original); postProcesses.add(this); } - + @Override public void run() { for (int i = 0; i < fOriginalTemplateParameters.length; i++) { @@ -238,7 +238,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { fTemplate.initData(fOriginalFunctionType, fOriginalParameters, fOriginalExceptionSpec); } } - + /** * Adds or returns existing binding for the given name. */ @@ -255,7 +255,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { addImplicitMethods(pdomBinding, (ICPPClassType) binding); } } - + handlePostProcesses(); return pdomBinding; } @@ -277,18 +277,18 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { if (cannotAdapt(inputBinding)) { return null; } - + PDOMBinding pdomBinding= attemptFastAdaptBinding(inputBinding); if (pdomBinding == null) { // assign names to anonymous types. IBinding binding= PDOMASTAdapter.getAdapterForAnonymousASTBinding(inputBinding); - if (binding == null) + if (binding == null) return null; final PDOMNode parent= adaptOrAddParent(true, binding); if (parent == null) return null; - + long fileLocalRec[]= {0}; pdomBinding = adaptBinding(parent, binding, fileLocalRec); if (pdomBinding != null) { @@ -349,9 +349,9 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { PDOMNode parent2= null; // template parameters are created directly by their owners. - if (binding instanceof ICPPTemplateParameter) + if (binding instanceof ICPPTemplateParameter) return null; - + if (binding instanceof ICPPSpecialization) { IBinding specialized = ((ICPPSpecialization) binding).getSpecializedBinding(); PDOMBinding pdomSpecialized= addBinding(specialized, null); @@ -427,7 +427,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { insertIntoNestedBindingsIndex(pdomBinding); } } - + return pdomBinding; } @@ -438,8 +438,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { ((PDOMCPPNamespace) node).addToList(record + FIRST_NAMESPACE_CHILD_OFFSET); } } - - private PDOMBinding createSpecialization(PDOMNode parent, PDOMBinding orig, IBinding special) + + private PDOMBinding createSpecialization(PDOMNode parent, PDOMBinding orig, IBinding special) throws CoreException, DOMException { PDOMBinding result= null; if (special instanceof ICPPDeferredClassInstance) { @@ -465,7 +465,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { result= new PDOMCPPFieldSpecialization(this, parent, (ICPPField) special, orig); } else if (special instanceof ICPPFunctionTemplate) { if (special instanceof ICPPConstructor) { - result= new PDOMCPPConstructorTemplateSpecialization( this, parent, (ICPPConstructor) special, orig); + result= new PDOMCPPConstructorTemplateSpecialization( this, parent, (ICPPConstructor) special, orig); } else if (special instanceof ICPPMethod) { result= new PDOMCPPMethodTemplateSpecialization( this, parent, (ICPPMethod) special, orig); } else if (special instanceof ICPPFunction) { @@ -486,10 +486,10 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { } else if (special instanceof ICPPUsingDeclaration) { result= new PDOMCPPUsingDeclarationSpecialization(this, parent, (ICPPUsingDeclaration) special, orig); } - + return result; } - + private void addImplicitMethods(PDOMBinding type, ICPPClassType binding) throws CoreException { try { final long fileLocalRec= type.getLocalToFileRec(); @@ -537,7 +537,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { } else if (binding instanceof ICPPFunction) { return CPP_FUNCTION_INSTANCE; } else if (binding instanceof ICPPClassType) { - return CPP_CLASS_INSTANCE; + return CPP_CLASS_INSTANCE; } } else if (binding instanceof ICPPClassTemplatePartialSpecialization) { if (binding instanceof ICPPClassTemplatePartialSpecializationSpecialization) @@ -619,7 +619,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { } else if (binding instanceof ITypedef) { return CPPTYPEDEF; } - + return 0; } @@ -682,7 +682,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { if (fileLocalRecHolder == null) return glob; final long loc= getLocalToFileRec(parent, binding, glob); - if (loc == 0) + if (loc == 0) return glob; fileLocalRecHolder[0]= loc; return CPPFindBinding.findBinding(getIndex(), this, binding, loc); @@ -693,7 +693,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { if (fileLocalRecHolder == null) return glob; final long loc= getLocalToFileRec(parent, binding, glob); - if (loc == 0) + if (loc == 0) return glob; fileLocalRecHolder[0]= loc; return CPPFindBinding.findBinding(btree, this, binding, loc); @@ -705,7 +705,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { if (parent instanceof IPDOMMemberOwner) { PDOMBinding glob= CPPFindBinding.findBinding(parent, this, binding, 0); final long loc= getLocalToFileRec(parent, binding, glob); - if (loc == 0) + if (loc == 0) return glob; fileLocalRecHolder[0]= loc; return CPPFindBinding.findBinding(parent, this, binding, loc); @@ -714,7 +714,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { } /** - * Adapts the parent of the given binding to an object contained in this linkage. May return + * Adapts the parent of the given binding to an object contained in this linkage. May return * null if the binding cannot be adapted or the binding does not exist and addParent * is set to false. * @param binding the binding to adapt @@ -747,7 +747,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { owner= owner.getOwner(); } } - + if (owner == null) return this; @@ -766,7 +766,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { postProcesses.removeFirst().run(); } } - + @Override public PDOMNode getNode(long record, int nodeType) throws CoreException { switch (nodeType) { @@ -863,7 +863,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { @Override public void onCreateName(PDOMFile file, IASTName name, PDOMName pdomName) throws CoreException { super.onCreateName(file, name, pdomName); - + IASTNode parentNode= name.getParent(); if (parentNode instanceof ICPPASTQualifiedName) { if (name != ((ICPPASTQualifiedName) parentNode).getLastName()) @@ -897,7 +897,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { IScope container= CPPVisitor.getContainingScope(name); boolean doit= false; PDOMCPPNamespace containerNS= null; - + IASTNode node= ASTInternal.getPhysicalNodeOfScope(container); if (node instanceof IASTTranslationUnit) { doit= true; @@ -931,7 +931,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { } } } - } else if (parentNode instanceof ICPPASTFunctionDeclarator) { + } else if (parentNode instanceof ICPPASTFunctionDeclarator) { if (parentNode.getParent() instanceof IASTSimpleDeclaration) { IASTSimpleDeclaration grandparentNode = (IASTSimpleDeclaration) parentNode.getParent(); if (grandparentNode.getDeclSpecifier() instanceof ICPPASTDeclSpecifier) { @@ -974,7 +974,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { @Override public void onDeleteName(PDOMName pdomName) throws CoreException { super.onDeleteName(pdomName); - + if (pdomName.isBaseSpecifier()) { PDOMName derivedClassName= (PDOMName) pdomName.getEnclosingDefinition(); if (derivedClassName != null) { @@ -1031,22 +1031,22 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { if (file != null) { return file; } - } + } if (binding instanceof ICPPMember) { return null; } return super.getLocalToFile(binding, glob); } - - @Override + + @Override public PDOMBinding addTypeBinding(IBinding type) throws CoreException { return addBinding(type, null); } - + @Override public IType unmarshalType(ITypeMarshalBuffer buffer) throws CoreException { int firstByte= buffer.getByte(); - switch((firstByte & ITypeMarshalBuffer.KIND_MASK)) { + switch ((firstByte & ITypeMarshalBuffer.KIND_MASK)) { case ITypeMarshalBuffer.ARRAY_TYPE: return CPPArrayType.unmarshal(firstByte, buffer); case ITypeMarshalBuffer.BASIC_TYPE: @@ -1068,14 +1068,14 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { case ITypeMarshalBuffer.DEPENDENT_EXPRESSION_TYPE: return TypeOfDependentExpression.unmarshal(firstByte, buffer); } - + throw new CoreException(CCorePlugin.createStatus("Cannot unmarshal a type, first byte=" + firstByte)); //$NON-NLS-1$ } - + @Override public ISerializableEvaluation unmarshalEvaluation(ITypeMarshalBuffer buffer) throws CoreException { int firstByte= buffer.getByte(); - switch((firstByte & ITypeMarshalBuffer.KIND_MASK)) { + switch ((firstByte & ITypeMarshalBuffer.KIND_MASK)) { case ITypeMarshalBuffer.EVAL_BINARY: return EvalBinary.unmarshal(firstByte, buffer); case ITypeMarshalBuffer.EVAL_BINARY_TYPE_ID: