From fa0220a8de391b4c42b7afe60b93f77797cd85d6 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 11 Jul 2012 20:44:24 -0700 Subject: [PATCH 01/31] Bug 299911. Partial implementation of ICPPEvaluation.instantiate methods. --- .../core/dom/parser/cpp/ICPPEvaluation.java | 10 ++++ .../dom/parser/cpp/semantics/EvalBinary.java | 18 ++++++- .../cpp/semantics/EvalBinaryTypeId.java | 14 +++++ .../dom/parser/cpp/semantics/EvalBinding.java | 53 +++++++++++++++++-- .../dom/parser/cpp/semantics/EvalComma.java | 18 +++++++ .../parser/cpp/semantics/EvalCompound.java | 12 +++++ .../parser/cpp/semantics/EvalConditional.java | 29 +++++++--- .../dom/parser/cpp/semantics/EvalFixed.java | 13 +++++ .../cpp/semantics/EvalFunctionCall.java | 18 +++++++ .../parser/cpp/semantics/EvalFunctionSet.java | 10 ++++ .../core/dom/parser/cpp/semantics/EvalID.java | 34 +++++++++++- .../parser/cpp/semantics/EvalInitList.java | 18 +++++++ .../cpp/semantics/EvalMemberAccess.java | 39 +++++++++++++- .../dom/parser/cpp/semantics/EvalTypeId.java | 19 +++++++ .../dom/parser/cpp/semantics/EvalUnary.java | 35 ++++++++++-- .../parser/cpp/semantics/EvalUnaryTypeID.java | 34 +++++++++++- 16 files changed, 354 insertions(+), 20 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java index 62e90c102f4..28a371e02be 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java @@ -14,6 +14,8 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; /** @@ -59,4 +61,12 @@ public interface ICPPEvaluation extends ISerializableEvaluation { * signatures are guaranteed to produce the same results. */ char[] getSignature(); + + /** + * Instantiates the evaluation with the provided template parameter map and pack offset. + * The context is used to replace templates with their specialization, where appropriate. + * @return a fully or partially instantiated evaluation, or the original evaluation + */ + ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point); } 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 0f119910e85..287193e6200 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 @@ -7,12 +7,16 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.*; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.glvalueType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueTypeWithResolvedTypedefs; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.typeFromFunctionCall; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; @@ -25,10 +29,12 @@ import org.eclipse.cdt.core.dom.ast.ISemanticProblem; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; @@ -273,4 +279,14 @@ public class EvalBinary extends CPPEvaluation { ICPPEvaluation arg2= (ICPPEvaluation) buffer.unmarshalEvaluation(); return new EvalBinary(op, arg1, arg2); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPEvaluation arg1 = fArg1.instantiate(tpMap, packOffset, within, maxdepth, point); + ICPPEvaluation arg2 = fArg2.instantiate(tpMap, packOffset, within, maxdepth, point); + if (arg1 == fArg1 && arg2 == fArg2) + return this; + return new EvalBinary(fOperator, arg1, arg2); + } } 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 ae2d6bd9878..200528f18f3 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 @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -18,11 +19,14 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.ISemanticProblem; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.core.runtime.CoreException; /** @@ -110,4 +114,14 @@ public class EvalBinaryTypeId extends CPPEvaluation { IType arg2= buffer.unmarshalType(); return new EvalBinaryTypeId(Operator.values()[op], arg1, arg2); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + IType type1 = CPPTemplates.instantiateType(fType1, tpMap, packOffset, within, point); + IType type2 = CPPTemplates.instantiateType(fType2, tpMap, packOffset, within, point); + if (type1 == fType1 && type2 == fType2) + return this; + return new EvalBinaryTypeId(fOperator, type1, type2); + } } 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 2f75c840940..3bad7828af5 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 @@ -7,12 +7,15 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.glvalueType; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueType; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -22,11 +25,15 @@ import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.IVariable; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; import org.eclipse.cdt.internal.core.dom.parser.Value; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.core.runtime.CoreException; @@ -40,7 +47,6 @@ public class EvalBinding extends CPPEvaluation { private boolean fIsTypeDependent; private boolean fCheckedIsTypeDependent; - public EvalBinding(IBinding binding, IType type) { fBinding= binding; fType= type; @@ -75,11 +81,11 @@ public class EvalBinding extends CPPEvaluation { } private boolean computeIsTypeDependent() { - if (fBinding instanceof ICPPUnknownBinding) - return true; - IType t= null; - if (fBinding instanceof IEnumerator) { + // mstodo: Please review this change. + if (fFixedType) { + t = fType; + } else if (fBinding instanceof IEnumerator) { t= ((IEnumerator) fBinding).getType(); } else if (fBinding instanceof ICPPTemplateNonTypeParameter) { t= ((ICPPTemplateNonTypeParameter) fBinding).getType(); @@ -184,4 +190,41 @@ public class EvalBinding extends CPPEvaluation { IType type= buffer.unmarshalType(); return new EvalBinding(binding, type); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + IBinding binding = fBinding; + if (fBinding instanceof IEnumerator) { + IEnumerator enumerator = (IEnumerator) binding; + IType originalType = enumerator.getType(); + IType type = CPPTemplates.instantiateType(originalType, tpMap, packOffset, within, point); + IValue originalValue = enumerator.getValue(); + IValue value = CPPTemplates.instantiateValue(originalValue, tpMap, packOffset, within, maxdepth, point); + // TODO(sprigogin): Not sure is the following condition is correct. + if (type != originalType || value != originalValue) + return new EvalFixed(type, ValueCategory.PRVALUE, value); + } else if (fBinding instanceof ICPPTemplateNonTypeParameter) { + ICPPTemplateArgument argument = tpMap.getArgument((ICPPTemplateNonTypeParameter) fBinding); + if (argument != null) { + IValue value = argument.getNonTypeValue(); + return new EvalFixed(null, ValueCategory.PRVALUE, value); + } + // TODO(sprigogin): Do we need something similar for pack expansion? + } else if (fBinding instanceof IVariable) { + // TODO(sprigogin): Not sure what to do in this case. + } else if (fBinding instanceof IFunction) { + // TODO(sprigogin): Not sure what to do in this case. + } else if (fBinding instanceof ICPPUnknownBinding) { + try { + binding = CPPTemplates.resolveUnknown((ICPPUnknownBinding) fBinding, tpMap, + packOffset, within, point); + } catch (DOMException e) { + CCorePlugin.log(e); // TODO(sprigogin): Is this exception safe to ignore? + } + } + if (binding == fBinding) + return this; + return new EvalBinding(binding, getFixedType()); + } } 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 31e0f1f80fc..970f22afe81 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 @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -18,7 +19,9 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.ISemanticProblem; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.Value; @@ -160,4 +163,19 @@ public class EvalComma extends CPPEvaluation { } return new EvalComma(args); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPEvaluation[] args = new ICPPEvaluation[fArguments.length]; + boolean changed = false; + for (int i = 0; i < fArguments.length; i++) { + args[i] = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point); + if (args[i] != fArguments[i]) + changed = true; + } + if (!changed) + return this; + return new EvalComma(args); + } } 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 8cae8cb319a..f926d275632 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 @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -16,6 +17,8 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.Value; @@ -81,4 +84,13 @@ public class EvalCompound extends CPPEvaluation { ICPPEvaluation arg= (ICPPEvaluation) buffer.unmarshalEvaluation(); return new EvalCompound(arg); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPEvaluation delegate = fDelegate.instantiate(tpMap, packOffset, within, maxdepth, point); + if (delegate == fDelegate) + return this; + return new EvalCompound(delegate); + } } \ No newline at end of file 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 d4caae8ea52..1ce00dddc1c 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 @@ -7,13 +7,17 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.XVALUE; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueType; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.*; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getNestedType; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; @@ -23,8 +27,10 @@ import org.eclipse.cdt.core.dom.ast.ISemanticProblem; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; @@ -49,13 +55,12 @@ public class EvalConditional extends CPPEvaluation { private IType fType; private ICPPFunction fOverload; - - public EvalConditional(ICPPEvaluation arg1, ICPPEvaluation arg2, ICPPEvaluation arg3, + public EvalConditional(ICPPEvaluation condition, ICPPEvaluation positive, ICPPEvaluation negative, boolean positiveThrows, boolean negativeThrows) { // Gnu-extension: Empty positive expression is replaced by condition. - fCondition= arg1; - fPositive= arg2; - fNegative= arg3; + fCondition= condition; + fPositive= positive; + fNegative= negative; fPositiveThrows= positiveThrows; fNegativeThrows= negativeThrows; } @@ -307,4 +312,16 @@ public class EvalConditional extends CPPEvaluation { ICPPEvaluation neg= (ICPPEvaluation) buffer.unmarshalEvaluation(); return new EvalConditional(cond, pos, neg, pth, nth); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPEvaluation condition = fCondition.instantiate(tpMap, packOffset, within, maxdepth, point); + ICPPEvaluation positive = fPositive == null ? + null : fPositive.instantiate(tpMap, packOffset, within, maxdepth, point); + ICPPEvaluation negative = fNegative.instantiate(tpMap, packOffset, within, maxdepth, point); + if (condition == fCondition && positive == fPositive && negative == fNegative) + return this; + return new EvalConditional(condition, positive, negative, fPositiveThrows, fNegativeThrows); + } } 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 c6985aed4c7..a985473ba7a 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 @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -18,6 +19,8 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; @@ -145,4 +148,14 @@ public class EvalFixed extends CPPEvaluation { value= readValue ? buffer.unmarshalValue() : Value.UNKNOWN; return new EvalFixed(type, cat, value); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + IType type = CPPTemplates.instantiateType(fType, tpMap, packOffset, within, point); + IValue value = CPPTemplates.instantiateValue(fValue, tpMap, packOffset, within, maxdepth, point); + if (type == fType && value == fValue) + return this; + return new EvalFixed(type, fValueCategory, value); + } } \ No newline at end of file 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 38c741f9e38..b8d8e7808e9 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 @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -24,8 +25,10 @@ import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.ISemanticProblem; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; @@ -169,4 +172,19 @@ public class EvalFunctionCall extends CPPEvaluation { } return new EvalComma(args); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPEvaluation[] args = new ICPPEvaluation[fArguments.length]; + boolean changed = false; + for (int i = 0; i < fArguments.length; i++) { + args[i] = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point); + if (args[i] != fArguments[i]) + changed = true; + } + if (!changed) + return this; + return new EvalFunctionCall(args); + } } 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 c2a98168cc7..f23105a53a8 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 @@ -16,11 +16,14 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.Value; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.core.runtime.CoreException; @@ -123,4 +126,11 @@ public class EvalFunctionSet extends CPPEvaluation { } return new EvalFunctionSet(new CPPFunctionSet(bindings, args, null), addressOf); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + // TODO(sprigogin): Not sure how to instantiate what to instantiate a CPPFunctionSet. + return this; + } } 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 366e8f6e7a2..52ffb477e70 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 @@ -13,6 +13,8 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTIdExpression; @@ -30,12 +32,15 @@ import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.Value; @@ -51,7 +56,8 @@ public class EvalID extends CPPEvaluation { private final boolean fQualified; private final ICPPTemplateArgument[] fTemplateArgs; - public EvalID(ICPPEvaluation fieldOwner, IBinding nameOwner, char[] simpleID, boolean addressOf, boolean qualified, ICPPTemplateArgument[] templateArgs) { + public EvalID(ICPPEvaluation fieldOwner, IBinding nameOwner, char[] simpleID, boolean addressOf, + boolean qualified, ICPPTemplateArgument[] templateArgs) { fFieldOwner= fieldOwner; fName= simpleID; fNameOwner= nameOwner; @@ -242,4 +248,30 @@ public class EvalID extends CPPEvaluation { } return false; } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPEvaluation fieldOwner = fFieldOwner.instantiate(tpMap, packOffset, within, maxdepth, point); + IBinding nameOwner = fNameOwner; + if (fNameOwner instanceof ICPPTemplateParameter) { + ICPPTemplateArgument argument = tpMap.getArgument((ICPPTemplateParameter) fNameOwner); + if (argument != null) { + IType type = argument.getTypeValue(); + if (type instanceof IBinding) + nameOwner = (IBinding) type; + } + } else if (fNameOwner instanceof ICPPUnknownBinding) { + try { + nameOwner = CPPTemplates.resolveUnknown((ICPPUnknownBinding) fNameOwner, tpMap, + packOffset, within, point); + } catch (DOMException e) { + CCorePlugin.log(e); // TODO(sprigogin): Is this exception safe to ignore? + } + } + if (fieldOwner == fFieldOwner && nameOwner == fNameOwner) + return this; + // TODO(sprigogin): Not sure how to construct the new evaluation. + return this; + } } 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 d54b0fb9bca..96e97581088 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 @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -16,6 +17,8 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.Value; @@ -96,4 +99,19 @@ public class EvalInitList extends CPPEvaluation { } return new EvalComma(args); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPEvaluation[] clauses = new ICPPEvaluation[fClauses.length]; + boolean changed = false; + for (int i = 0; i < fClauses.length; i++) { + clauses[i] = fClauses[i].instantiate(tpMap, packOffset, within, maxdepth, point); + if (clauses[i] != fClauses[i]) + changed = true; + } + if (!changed) + return this; + return new EvalInitList(clauses); + } } \ No newline at end of file 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 84c8d69ea80..480fe9a6934 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 @@ -7,17 +7,26 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.XVALUE; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.*; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.*; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.glvalueType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueTypeWithResolvedTypedefs; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.typeFromFunctionCall; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.ALLCVQ; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getUltimateTypeUptoPointers; import java.util.Collection; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -29,10 +38,12 @@ import org.eclipse.cdt.core.dom.ast.ISemanticProblem; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.IVariable; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; @@ -301,4 +312,28 @@ public class EvalMemberAccess extends CPPEvaluation { IBinding member= buffer.unmarshalBinding(); return new EvalMemberAccess(ownerType, ownerValueCat, member, isDeref); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + IType type = CPPTemplates.instantiateType(fOwnerType, tpMap, packOffset, within, point); + IBinding member = fMember; + if (fMember instanceof ICPPUnknownBinding) { + try { + member = CPPTemplates.resolveUnknown((ICPPUnknownBinding) fMember, tpMap, + packOffset, within, point); + } catch (DOMException e) { + CCorePlugin.log(e); // TODO(sprigogin): Is this exception safe to ignore? + } + } else if (fMember instanceof IEnumerator) { + // TODO(sprigogin): Not sure what to do in this case. + } else if (fMember instanceof IVariable) { + // TODO(sprigogin): Not sure what to do in this case. + } else if (fMember instanceof IFunction) { + // TODO(sprigogin): Not sure what to do in this case. + } + if (type == fOwnerType && member == fMember) + return this; + return new EvalMemberAccess(type, fOwnerValueCategory, member, fIsPointerDeref); + } } 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 e2e41b728b1..e78725f1552 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 @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -17,6 +18,8 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.Value; @@ -125,4 +128,20 @@ public class EvalTypeId extends CPPEvaluation { } return new EvalTypeId(type, args); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPEvaluation[] args = new ICPPEvaluation[fArguments.length]; + boolean argsChanged = false; + for (int i = 0; i < fArguments.length; i++) { + args[i] = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point); + if (args[i] != fArguments[i]) + argsChanged = true; + } + IType type = CPPTemplates.instantiateType(fInputType, tpMap, packOffset, within, point); + if (!argsChanged && type == fInputType) + return this; + return new EvalTypeId(type, args); + } } 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 ca5bef22dfc..ac40c69ebb4 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 @@ -7,13 +7,31 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; -import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.*; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.*; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_alignOf; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_amper; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_minus; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_not; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_plus; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_postFixDecr; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_postFixIncr; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_prefixDecr; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_prefixIncr; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_sizeof; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_sizeofParameterPack; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_star; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_throw; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_tilde; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_typeid; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.glvalueType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueTypeWithResolvedTypedefs; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.valueCategoryFromFunctionCall; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; @@ -25,7 +43,9 @@ import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.ISemanticProblem; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; @@ -90,7 +110,7 @@ public class EvalUnary extends CPPEvaluation { @Override public boolean isValueDependent() { - switch(fOperator) { + switch (fOperator) { case op_alignOf: case op_sizeof: case op_sizeofParameterPack: @@ -217,4 +237,13 @@ public class EvalUnary extends CPPEvaluation { ICPPEvaluation arg= (ICPPEvaluation) buffer.unmarshalEvaluation(); return new EvalUnary(op, arg); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPEvaluation argument = fArgument.instantiate(tpMap, packOffset, within, maxdepth, point); + if (argument == fArgument) + return this; + return new EvalUnary(fOperator, argument); + } } 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 9caf7ec00f4..03170775389 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 @@ -7,22 +7,43 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; -import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.*; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_alignof; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_nothrow_constructor; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_nothrow_copy; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_trivial_assign; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_trivial_constructor; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_trivial_copy; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_trivial_destructor; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_virtual_destructor; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_abstract; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_class; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_empty; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_enum; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_pod; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_polymorphic; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_union; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_sizeof; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_typeid; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_typeof; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.core.runtime.CoreException; public class EvalUnaryTypeID extends CPPEvaluation { @@ -139,7 +160,7 @@ public class EvalUnaryTypeID extends CPPEvaluation { public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { buffer.putByte(ITypeMarshalBuffer.EVAL_UNARY_TYPE_ID); buffer.putByte((byte) fOperator); - buffer.marshalType(fType); + buffer.marshalType(fOrigType); } public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { @@ -147,4 +168,13 @@ public class EvalUnaryTypeID extends CPPEvaluation { IType arg= buffer.unmarshalType(); return new EvalUnaryTypeID(op, arg); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + IType type = CPPTemplates.instantiateType(fOrigType, tpMap, packOffset, within, point); + if (type == fOrigType) + return this; + return new EvalUnaryTypeID(fOperator, type); + } } From 25b6c95ea806f2099777e1d739d2e08a2883abb8 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Fri, 13 Jul 2012 22:02:40 -0700 Subject: [PATCH 02/31] Cosmetics. --- .../eclipse/cdt/core/dom/ast/IASTTypeId.java | 9 +++----- .../core/dom/ast/IASTTypeIdExpression.java | 7 +++--- .../cdt/core/dom/ast/IASTWhileStatement.java | 3 +-- .../dom/ast/ICPPASTCompletionContext.java | 3 +-- .../cdt/core/dom/ast/ICompositeType.java | 9 ++++---- .../cdt/core/dom/ast/cpp/ICPPConstructor.java | 3 +-- .../ast/cpp/ICPPDeferredTemplateInstance.java | 4 ++-- .../cdt/core/dom/ast/cpp/ICPPEnumeration.java | 3 +-- .../cdt/core/dom/ast/cpp/ICPPField.java | 5 ++--- .../cdt/core/dom/ast/cpp/ICPPFunction.java | 16 +++++++------- .../core/dom/ast/cpp/ICPPFunctionScope.java | 1 - .../dom/ast/cpp/ICPPFunctionTemplate.java | 15 ++++++------- .../AbstractCPPClassSpecializationScope.java | 11 +++++----- .../parser/cpp/CPPASTAmbiguityResolver.java | 2 +- ...CPPASTAmbiguousBinaryVsCastExpression.java | 2 +- ...AmbiguousCastVsFunctionCallExpression.java | 6 ++--- .../parser/cpp/CPPASTAmbiguousCondition.java | 2 +- .../parser/cpp/CPPASTAmbiguousExpression.java | 14 +++++------- .../CPPASTAmbiguousParameterDeclaration.java | 12 +++++----- .../parser/cpp/CPPASTAmbiguousStatement.java | 3 ++- .../cpp/CPPASTAmbiguousTemplateArgument.java | 22 ++++++++----------- .../core/dom/parser/cpp/CPPArrayType.java | 12 +++++----- .../parser/cpp/semantics/CPPSemantics.java | 16 +++++++++++--- .../GenerateGettersAndSettersWizard.java | 2 +- 24 files changed, 88 insertions(+), 94 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeId.java index 13fc8a000c9..5e0f5546596 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeId.java @@ -15,10 +15,7 @@ package org.eclipse.cdt.core.dom.ast; * @noimplement This interface is not intended to be implemented by clients. */ public interface IASTTypeId extends IASTNode { - /** - * Constant. - */ - public static final IASTTypeId[] EMPTY_TYPEID_ARRAY = new IASTTypeId[0]; + public static final IASTTypeId[] EMPTY_TYPEID_ARRAY = {}; /** * DECL_SPECIFIER represents the relationship between an IASTTypeId @@ -35,7 +32,7 @@ public interface IASTTypeId extends IASTNode { "IASTTypeId.ABSTRACT_DECLARATOR - IASTDeclarator for IASTTypeId"); //$NON-NLS-1$ /** - * Get the decl specifier. + * Returns the decl specifier. * @return IASTDeclSpecifier */ public IASTDeclSpecifier getDeclSpecifier(); @@ -54,7 +51,7 @@ public interface IASTTypeId extends IASTNode { public IASTDeclarator getAbstractDeclarator(); /** - * Set the abstract declarator. + * Sets the abstract declarator. * @param abstractDeclarator IASTDeclarator */ public void setAbstractDeclarator(IASTDeclarator abstractDeclarator); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeIdExpression.java index f62f4313551..af81f5d4580 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeIdExpression.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * John Camelon (IBM Rational Software) - Initial API and implementation - * Markus Schorn (Wind River Systems) + * John Camelon (IBM Rational Software) - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; @@ -16,9 +16,8 @@ package org.eclipse.cdt.core.dom.ast; * @noimplement This interface is not intended to be implemented by clients. */ public interface IASTTypeIdExpression extends IASTExpression { - /** - * op_sizeof sizeof( typeId ) expression + * op_sizeof sizeof (typeId) expression */ public static final int op_sizeof = 0; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTWhileStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTWhileStatement.java index 77dbe1ed089..180b2eb8a78 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTWhileStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTWhileStatement.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Doug Schaefer (IBM) - Initial API and implementation + * Doug Schaefer (IBM) - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; @@ -17,7 +17,6 @@ package org.eclipse.cdt.core.dom.ast; * @noimplement This interface is not intended to be implemented by clients. */ public interface IASTWhileStatement extends IASTStatement { - /** * CONDITIONEXPRESSION represents the relationship between an IASTWhileStatement and * it's nested IASTExpression. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ICPPASTCompletionContext.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ICPPASTCompletionContext.java index 2bc8aed0b39..e502a24930b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ICPPASTCompletionContext.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ICPPASTCompletionContext.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Tomasz Wesolowski - initial API and implementation + * Tomasz Wesolowski - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; @@ -19,7 +19,6 @@ package org.eclipse.cdt.core.dom.ast; * @since 5.3 */ public interface ICPPASTCompletionContext extends IASTCompletionContext { - /** * Returns bindings that start with the given name or prefix, only considering those that are valid for * this context, including those in the requested set of namespaces. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ICompositeType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ICompositeType.java index 439bf8f9613..6775e42c92a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ICompositeType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ICompositeType.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * IBM - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; @@ -21,15 +21,16 @@ public interface ICompositeType extends IBinding, IType { public static final int k_union = IASTCompositeTypeSpecifier.k_union; /** - * Returns the type of the composite, {@link #k_struct}, {@link #k_union}, or - * {@link org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#k_class}. + * Returns the type of the composite, {@link #k_struct}, {@link #k_union}, + * or {@link org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#k_class}. */ public int getKey(); /** * Returns whether the type is anonymous or not. A type for which objects or * pointers are declared is not considered an anonymous type. - *
 struct Outer {
+	 * 
+	 * struct Outer {
 	 *    struct {int a;}; // anonymous
 	 *    struct {int b;} c; // not anonymous
 	 * }
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPConstructor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPConstructor.java
index 7ccdc403f85..0220f5c7deb 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPConstructor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPConstructor.java
@@ -10,11 +10,10 @@
  *******************************************************************************/
 package org.eclipse.cdt.core.dom.ast.cpp;
 
-
 /**
  * @noextend This interface is not intended to be extended by clients.
  * @noimplement This interface is not intended to be implemented by clients.
  */
 public interface ICPPConstructor extends ICPPMethod {
-	public static final ICPPConstructor [] EMPTY_CONSTRUCTOR_ARRAY = new ICPPConstructor[0];
+	public static final ICPPConstructor[] EMPTY_CONSTRUCTOR_ARRAY = {};
 }
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPDeferredTemplateInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPDeferredTemplateInstance.java
index 14f643f2d28..bbf8ab55f7d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPDeferredTemplateInstance.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPDeferredTemplateInstance.java
@@ -6,8 +6,8 @@
  * http://www.eclipse.org/legal/epl-v10.html
  *
  * Contributors:
- *    Bryan Wilkinson (QNX) - Initial API and implementation
- *    Markus Schorn (Wind River Systems)
+ *     Bryan Wilkinson (QNX) - Initial API and implementation
+ *     Markus Schorn (Wind River Systems)
  *******************************************************************************/
 package org.eclipse.cdt.core.dom.ast.cpp;
 
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPEnumeration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPEnumeration.java
index 7cd598500e0..22225a116aa 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPEnumeration.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPEnumeration.java
@@ -6,7 +6,7 @@
  * 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.core.dom.ast.cpp;
 
@@ -21,7 +21,6 @@ import org.eclipse.cdt.core.dom.ast.IType;
  * @noimplement This interface is not intended to be implemented by clients.
  */
 public interface ICPPEnumeration extends IEnumeration, ICPPBinding {
-    
     /**
      * Returns whether this enumeration is scoped.
      * An enumeration can only be scoped in C++.
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPField.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPField.java
index b0b0e7dbb31..196f0a5817f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPField.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPField.java
@@ -6,7 +6,7 @@
  * http://www.eclipse.org/legal/epl-v10.html
  *
  * Contributors:
- *    Doug Schaefer (IBM) - Initial API and implementation
+ *     Doug Schaefer (IBM) - Initial API and implementation
  *******************************************************************************/
 package org.eclipse.cdt.core.dom.ast.cpp;
 
@@ -17,6 +17,5 @@ import org.eclipse.cdt.core.dom.ast.IField;
  * @noimplement This interface is not intended to be implemented by clients.
  */
 public interface ICPPField extends IField, ICPPMember, ICPPVariable {
-    public static final ICPPField [] EMPTY_CPPFIELD_ARRAY = new ICPPField[0];
-
+    public static final ICPPField[] EMPTY_CPPFIELD_ARRAY = {};
 }
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java
index b1af1daf8a0..17248714040 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java
@@ -1,13 +1,13 @@
 /*******************************************************************************
- *  Copyright (c) 2005, 2010 IBM Corporation and others.
- *  All rights reserved. This program and the accompanying materials
- *  are made available under the terms of the Eclipse Public License v1.0
- *  which accompanies this distribution, and is available at
- *  http://www.eclipse.org/legal/epl-v10.html
+ * Copyright (c) 2005, 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
  * 
- *  Contributors:
- *      Andrew Niefer (IBM Corporation) - initial API and implementation
- *      Markus Schorn (Wind River Systems)
+ * Contributors:
+ *     Andrew Niefer (IBM Corporation) - initial API and implementation
+ *     Markus Schorn (Wind River Systems)
  *******************************************************************************/
 package org.eclipse.cdt.core.dom.ast.cpp;
 
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunctionScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunctionScope.java
index b6be37f5c51..e78ad625b74 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunctionScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunctionScope.java
@@ -18,7 +18,6 @@ import org.eclipse.cdt.core.dom.ast.IScope;
  * @noimplement This interface is not intended to be implemented by clients.
  */
 public interface ICPPFunctionScope extends ICPPScope {
-
 	/**
 	 * Get the scope representing the function body. returns null if there is no
 	 * function definition
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunctionTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunctionTemplate.java
index cdd9808211f..ea247dbb0d1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunctionTemplate.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunctionTemplate.java
@@ -1,12 +1,12 @@
 /*******************************************************************************
- *  Copyright (c) 2005, 2009 IBM Corporation and others.
- *  All rights reserved. This program and the accompanying materials
- *  are made available under the terms of the Eclipse Public License v1.0
- *  which accompanies this distribution, and is available at
- *  http://www.eclipse.org/legal/epl-v10.html
+ * Copyright (c) 2005, 2009 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
  * 
- *  Contributors:
- *    Andrew Niefer (IBM) - Initial API and implementation
+ * Contributors:
+ *     Andrew Niefer (IBM) - Initial API and implementation
  *******************************************************************************/
 package org.eclipse.cdt.core.dom.ast.cpp;
 
@@ -17,5 +17,4 @@ package org.eclipse.cdt.core.dom.ast.cpp;
  * @noextend This interface is not intended to be extended by clients.
  */
 public interface ICPPFunctionTemplate extends ICPPFunction, ICPPTemplateDefinition {
-
 }
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java
index 62ff6bc9ca8..560c545e08e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java
@@ -6,10 +6,10 @@
  * http://www.eclipse.org/legal/epl-v10.html
  *
  * Contributors:
- *    IBM - Initial API and implementation
- *    Markus Schorn (Wind River Systems)
- *    Bryan Wilkinson (QNX)
- *    Andrew Ferguson (Symbian)
+ *     IBM - Initial API and implementation
+ *     Markus Schorn (Wind River Systems)
+ *     Bryan Wilkinson (QNX)
+ *     Andrew Ferguson (Symbian)
  *******************************************************************************/
 package org.eclipse.cdt.internal.core.dom.parser.cpp;
 
@@ -91,7 +91,8 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat
     	return CPPSemantics.resolveAmbiguities(name, specs);
 	}
 
-	@Deprecated	@Override
+	@Deprecated
+	@Override
 	final public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup,
 			IIndexFileSet fileSet) {
 		return getBindings(new ScopeLookupData(name, resolve, prefixLookup));
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java
index 3a7043e32cd..198478bcb44 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java
@@ -6,7 +6,7 @@
  * 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;
 
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousBinaryVsCastExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousBinaryVsCastExpression.java
index 33e3534b2b3..a7967717781 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousBinaryVsCastExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousBinaryVsCastExpression.java
@@ -6,7 +6,7 @@
  * 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;
 
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCastVsFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCastVsFunctionCallExpression.java
index 4c08dbe087d..c9254d33de8 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCastVsFunctionCallExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCastVsFunctionCallExpression.java
@@ -6,7 +6,7 @@
  * 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;
 
@@ -15,8 +15,8 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
 import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpression;
 import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousCastVsFunctionCallExpression;
 
-public class CPPASTAmbiguousCastVsFunctionCallExpression extends
-		ASTAmbiguousCastVsFunctionCallExpression implements ICPPASTExpression {
+public class CPPASTAmbiguousCastVsFunctionCallExpression
+		extends	ASTAmbiguousCastVsFunctionCallExpression implements ICPPASTExpression {
 
     public CPPASTAmbiguousCastVsFunctionCallExpression(IASTCastExpression castExpr, IASTFunctionCallExpression funcCall) {
     	super(castExpr, funcCall);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCondition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCondition.java
index f47bcda4a3a..5839aa7d636 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCondition.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCondition.java
@@ -6,7 +6,7 @@
  * 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;
 
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java
index c45715f43aa..1612a28c1f9 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java
@@ -18,17 +18,15 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil;
 import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode;
 import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression;
 
-public class CPPASTAmbiguousExpression extends ASTAmbiguousNode implements
-        IASTAmbiguousExpression, ICPPASTExpression {
-
-    private IASTExpression [] exp = new IASTExpression[2];
-    private int expPos=-1;
+public class CPPASTAmbiguousExpression extends ASTAmbiguousNode
+		implements IASTAmbiguousExpression, ICPPASTExpression {
+    private IASTExpression[] exp = new IASTExpression[2];
+    private int expPos= -1;
     
     public CPPASTAmbiguousExpression(IASTExpression... expressions) {
 		for(IASTExpression e : expressions)
 			addExpression(e);
 	}
-
     
     @Override
 	public IASTExpression copy() {
@@ -44,7 +42,7 @@ public class CPPASTAmbiguousExpression extends ASTAmbiguousNode implements
 	public void addExpression(IASTExpression e) {
         assertNotFrozen();
     	if (e != null) {
-    		exp = ArrayUtil.appendAt( IASTExpression.class, exp, ++expPos, e );
+    		exp = ArrayUtil.appendAt(IASTExpression.class, exp, ++expPos, e);
     		e.setParent(this);
 			e.setPropertyInParent(SUBEXPRESSION);
     	}
@@ -52,7 +50,7 @@ public class CPPASTAmbiguousExpression extends ASTAmbiguousNode implements
 
     @Override
 	public IASTExpression[] getExpressions() {
-        exp = ArrayUtil.trimAt( IASTExpression.class, exp, expPos );
+        exp = ArrayUtil.trimAt(IASTExpression.class, exp, expPos);
     	return exp;
     }
 
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousParameterDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousParameterDeclaration.java
index 81b864a9bfc..5984d0efe9d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousParameterDeclaration.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousParameterDeclaration.java
@@ -6,7 +6,7 @@
  * 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;
 
@@ -34,9 +34,8 @@ import org.eclipse.core.runtime.Assert;
  * 
* template void function(T ...); // is T a parameter pack? */ -public class CPPASTAmbiguousParameterDeclaration extends ASTAmbiguousNode implements - IASTAmbiguousParameterDeclaration, ICPPASTParameterDeclaration { - +public class CPPASTAmbiguousParameterDeclaration extends ASTAmbiguousNode + implements IASTAmbiguousParameterDeclaration, ICPPASTParameterDeclaration { private ICPPASTParameterDeclaration fParameterDecl; public CPPASTAmbiguousParameterDeclaration(ICPPASTParameterDeclaration decl) { @@ -47,7 +46,6 @@ public class CPPASTAmbiguousParameterDeclaration extends ASTAmbiguousNode implem public void addParameterDeclaration(IASTParameterDeclaration d) { assert false; } - @Override protected final IASTNode doResolveAmbiguity(ASTVisitor resolver) { @@ -73,7 +71,7 @@ public class CPPASTAmbiguousParameterDeclaration extends ASTAmbiguousNode implem final ASTNode asNode = (ASTNode) dtor; if (ptrOps.length > 0) { final ASTNode first = (ASTNode)ptrOps[0]; - final ASTNode last = (ASTNode)ptrOps[ptrOps.length-1]; + final ASTNode last = (ASTNode)ptrOps[ptrOps.length - 1]; asNode.setOffsetAndLength(first.getOffset(), last.getOffset() + last.getLength()); } else { asNode.setOffsetAndLength(0, 0); @@ -82,7 +80,7 @@ public class CPPASTAmbiguousParameterDeclaration extends ASTAmbiguousNode implem @Override public IASTParameterDeclaration[] getParameterDeclarations() { - return new IASTParameterDeclaration[] {fParameterDecl}; + return new IASTParameterDeclaration[] { fParameterDecl }; } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java index 53b624a78f9..6d898528ee8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java @@ -32,8 +32,9 @@ public class CPPASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAm private IASTDeclaration fDeclaration; public CPPASTAmbiguousStatement(IASTStatement... statements) { - for (IASTStatement s : statements) + for (IASTStatement s : statements) { addStatement(s); + } } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java index f6deabd115f..bd2101e22f1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java @@ -6,9 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Ferguson (Symbian) - Initial Implementation - * Markus Schorn (Wind River Systems) - * IBM Corporation + * Andrew Ferguson (Symbian) - Initial Implementation + * Markus Schorn (Wind River Systems) + * IBM Corporation *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -33,11 +33,11 @@ import org.eclipse.core.runtime.Assert; * Ambiguity node for deciding between type-id and id-expression in a template argument. */ public class CPPASTAmbiguousTemplateArgument extends ASTAmbiguousNode implements ICPPASTAmbiguousTemplateArgument { - private List fNodes; /** - * @param nodes nodes of type {@link IASTTypeId}, {@link IASTIdExpression} or {@link ICPPASTPackExpansionExpression}. + * @param nodes nodes of type {@link IASTTypeId}, {@link IASTIdExpression} + * or {@link ICPPASTPackExpansionExpression}. */ public CPPASTAmbiguousTemplateArgument(IASTNode... nodes) { fNodes= new ArrayList(2); @@ -56,7 +56,6 @@ public class CPPASTAmbiguousTemplateArgument extends ASTAmbiguousNode implements } } } - @Override protected void beforeAlternative(IASTNode node) { @@ -77,13 +76,11 @@ public class CPPASTAmbiguousTemplateArgument extends ASTAmbiguousNode implements } } - @Override protected void afterResolution(ASTVisitor resolver, IASTNode best) { beforeAlternative(best); } - @Override public IASTNode copy() { return copy(CopyStyle.withoutLocations); @@ -91,15 +88,14 @@ public class CPPASTAmbiguousTemplateArgument extends ASTAmbiguousNode implements @Override public IASTNode copy(CopyStyle style) { - int sizeOfNodes = fNodes.size(); IASTNode[] copyNodes = new IASTNode[sizeOfNodes]; int arrayIndex = 0; - for(IASTNode node : fNodes) { - if(node!=null){ + for (IASTNode node : fNodes) { + if (node != null){ copyNodes[arrayIndex] = node.copy(style); - }else{ - copyNodes[arrayIndex]=null; + } else { + copyNodes[arrayIndex]= null; } arrayIndex++; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java index f38210cc2fb..a832a347973 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java @@ -1,11 +1,11 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2004, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: * Andrew Niefer (IBM Corporation) - initial API and implementation * Markus Schorn (Wind River Systems) *******************************************************************************/ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index 358e30115fd..ed466a91df0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -16,7 +16,17 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.*; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.ALLCVQ; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.ARRAY; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.MPTR; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.PTR; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.calculateInheritanceDepth; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getNestedType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getUltimateTypeUptoPointers; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.isConversionOperator; import java.util.ArrayList; import java.util.Arrays; @@ -3261,7 +3271,7 @@ public class CPPSemantics { if (tu != null && funcData.foundItems instanceof Object[]) { final IIndexFileSet fileSet = tu.getIndexFileSet(); if (fileSet != null) { - int j=0; + int j= 0; final Object[] items= (Object[]) funcData.foundItems; for (int i = 0; i < items.length; i++) { Object item = items[i]; @@ -3292,7 +3302,7 @@ public class CPPSemantics { items[j++]= func; } } - if (j>0) { + if (j > 0) { while (j < items.length) items[j++]= null; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersWizard.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersWizard.java index 8e48c62e61a..d89e479d21b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersWizard.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersWizard.java @@ -17,7 +17,7 @@ import org.eclipse.ltk.ui.refactoring.UserInputWizardPage; /** * @author Thomas Corbat */ -public class GenerateGettersAndSettersWizard extends RefactoringWizard { +public class GenerateGettersAndSettersWizard extends RefactoringWizard { public GenerateGettersAndSettersWizard( GenerateGettersAndSettersRefactoring refactoring) { super(refactoring, DIALOG_BASED_USER_INTERFACE | PREVIEW_EXPAND_FIRST_NODE); From 31c42c19eebc46f30f966b9686901f6690681df5 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sat, 14 Jul 2012 20:58:14 -0700 Subject: [PATCH 03/31] Bug 299911. Implementations of ICPPEvaluation.instantiate methods. --- .../dom/parser/cpp/semantics/EvalBinding.java | 8 +--- .../parser/cpp/semantics/EvalFunctionSet.java | 42 ++++++++++++++++++- .../core/dom/parser/cpp/semantics/EvalID.java | 41 ++++++++++++++++-- .../cpp/semantics/EvalMemberAccess.java | 28 ++++--------- 4 files changed, 87 insertions(+), 32 deletions(-) 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 3bad7828af5..f7d9e02e0ea 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 @@ -201,7 +201,7 @@ public class EvalBinding extends CPPEvaluation { IType type = CPPTemplates.instantiateType(originalType, tpMap, packOffset, within, point); IValue originalValue = enumerator.getValue(); IValue value = CPPTemplates.instantiateValue(originalValue, tpMap, packOffset, within, maxdepth, point); - // TODO(sprigogin): Not sure is the following condition is correct. + // TODO(sprigogin): Not sure if following condition is correct. if (type != originalType || value != originalValue) return new EvalFixed(type, ValueCategory.PRVALUE, value); } else if (fBinding instanceof ICPPTemplateNonTypeParameter) { @@ -211,16 +211,12 @@ public class EvalBinding extends CPPEvaluation { return new EvalFixed(null, ValueCategory.PRVALUE, value); } // TODO(sprigogin): Do we need something similar for pack expansion? - } else if (fBinding instanceof IVariable) { - // TODO(sprigogin): Not sure what to do in this case. - } else if (fBinding instanceof IFunction) { - // TODO(sprigogin): Not sure what to do in this case. } else if (fBinding instanceof ICPPUnknownBinding) { try { binding = CPPTemplates.resolveUnknown((ICPPUnknownBinding) fBinding, tpMap, packOffset, within, point); } catch (DOMException e) { - CCorePlugin.log(e); // TODO(sprigogin): Is this exception safe to ignore? + CCorePlugin.log(e); } } if (binding == fBinding) 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 f23105a53a8..70f8e72d589 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 @@ -7,13 +7,19 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; +import java.util.Arrays; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; @@ -130,7 +136,39 @@ public class EvalFunctionSet extends CPPEvaluation { @Override public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, int maxdepth, IASTNode point) { - // TODO(sprigogin): Not sure how to instantiate what to instantiate a CPPFunctionSet. - return this; + ICPPTemplateArgument[] originalArguments = fFunctionSet.getTemplateArguments(); + ICPPTemplateArgument[] arguments = originalArguments; + try { + arguments = CPPTemplates.instantiateArguments(originalArguments, tpMap, packOffset, within, point); + } catch (DOMException e) { + CCorePlugin.log(e); + } + + IBinding originalOwner = fFunctionSet.getOwner(); + IBinding owner = originalOwner; + if (originalOwner instanceof ICPPUnknownBinding) { + try { + owner = CPPTemplates.resolveUnknown((ICPPUnknownBinding) owner, tpMap, + packOffset, within, point); + } catch (DOMException e) { + CCorePlugin.log(e); // TODO(sprigogin): Is this exception safe to ignore? + } + } else if (owner instanceof IType) { + IType type = CPPTemplates.instantiateType((IType) owner, tpMap, packOffset, within, point); + if (type instanceof IBinding) + owner = (IBinding) type; + } + ICPPFunction[] originalFunctions = fFunctionSet.getBindings(); + ICPPFunction[] functions = originalFunctions; + if (owner instanceof ICPPClassSpecialization && owner != originalOwner) { + functions = new ICPPFunction[originalFunctions.length]; + for (int i = 0; i < originalFunctions.length; i++) { + functions[i] = (ICPPFunction) CPPTemplates.createSpecialization((ICPPClassSpecialization) owner, + originalFunctions[i], point); + } + } + if (Arrays.equals(arguments, originalArguments) && functions == originalFunctions) + return this; + return new EvalFunctionSet(new CPPFunctionSet(functions, arguments, null), fAddressOf); } } 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 52ffb477e70..eeae6cc797c 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 @@ -7,12 +7,15 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; +import java.util.Arrays; + import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression; @@ -22,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IProblemBinding; @@ -252,6 +256,13 @@ public class EvalID extends CPPEvaluation { @Override public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPTemplateArgument[] arguments = fTemplateArgs; + try { + arguments = CPPTemplates.instantiateArguments(fTemplateArgs, tpMap, packOffset, within, point); + } catch (DOMException e) { + CCorePlugin.log(e); + } + ICPPEvaluation fieldOwner = fFieldOwner.instantiate(tpMap, packOffset, within, maxdepth, point); IBinding nameOwner = fNameOwner; if (fNameOwner instanceof ICPPTemplateParameter) { @@ -266,12 +277,34 @@ public class EvalID extends CPPEvaluation { nameOwner = CPPTemplates.resolveUnknown((ICPPUnknownBinding) fNameOwner, tpMap, packOffset, within, point); } catch (DOMException e) { - CCorePlugin.log(e); // TODO(sprigogin): Is this exception safe to ignore? + CCorePlugin.log(e); } } - if (fieldOwner == fFieldOwner && nameOwner == fNameOwner) + if (Arrays.equals(arguments, fTemplateArgs) && fieldOwner == fFieldOwner && nameOwner == fNameOwner) return this; - // TODO(sprigogin): Not sure how to construct the new evaluation. - return this; + + if (nameOwner == null) + nameOwner = (IBinding) fFieldOwner.getTypeOrFunctionSet(point); + + if (nameOwner instanceof ICompositeType) { + ICompositeType ownerType = (ICompositeType) nameOwner; + // TODO(sprigogin): Is this the right way to do lookup, or should findBindings be used instead? + LookupData data = new LookupData(fName, fTemplateArgs, point); + try { + CPPSemantics.lookup(data, ownerType.getScope()); + } catch (DOMException e) { + } + IBinding[] bindings = data.getFoundBindings(); + IBinding binding = bindings.length == 1 ? bindings[0] : null; + if (binding instanceof IEnumerator) { + return new EvalBinding(binding, null); + } else if (binding instanceof ICPPMember) { + return new EvalMemberAccess(ownerType, ValueCategory.PRVALUE, binding, false); + } else if (binding instanceof CPPFunctionSet) { + return new EvalFunctionSet((CPPFunctionSet) binding, fAddressOf); + } + } + + return new EvalID(fieldOwner, nameOwner, fName, fAddressOf, fQualified, arguments); } } 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 480fe9a6934..fc60209bfed 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 @@ -25,8 +25,6 @@ import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUti import java.util.Collection; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -316,24 +314,14 @@ public class EvalMemberAccess extends CPPEvaluation { @Override public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, int maxdepth, IASTNode point) { - IType type = CPPTemplates.instantiateType(fOwnerType, tpMap, packOffset, within, point); - IBinding member = fMember; - if (fMember instanceof ICPPUnknownBinding) { - try { - member = CPPTemplates.resolveUnknown((ICPPUnknownBinding) fMember, tpMap, - packOffset, within, point); - } catch (DOMException e) { - CCorePlugin.log(e); // TODO(sprigogin): Is this exception safe to ignore? - } - } else if (fMember instanceof IEnumerator) { - // TODO(sprigogin): Not sure what to do in this case. - } else if (fMember instanceof IVariable) { - // TODO(sprigogin): Not sure what to do in this case. - } else if (fMember instanceof IFunction) { - // TODO(sprigogin): Not sure what to do in this case. - } - if (type == fOwnerType && member == fMember) + IType ownerType = CPPTemplates.instantiateType(fOwnerType, tpMap, packOffset, within, point); + if (ownerType == fOwnerType) return this; - return new EvalMemberAccess(type, fOwnerValueCategory, member, fIsPointerDeref); + + IBinding member = fMember; + if (ownerType instanceof ICPPClassSpecialization) { + member = CPPTemplates.createSpecialization((ICPPClassSpecialization) ownerType, fMember, point); + } + return new EvalMemberAccess(ownerType, fOwnerValueCategory, member, fIsPointerDeref); } } From 1f13ce68894967279f0ad092df3dc1c68f29246a Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sun, 15 Jul 2012 14:53:02 -0700 Subject: [PATCH 04/31] Cosmetics. --- .../parser/cpp/semantics/CPPTemplates.java | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) 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 bfd903dc69e..8fbb1cb8149 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 @@ -224,7 +224,7 @@ public class CPPTemplates { } if (isPack) { - int packOffset= numParams-1; + int packOffset= numParams - 1; int packSize= numArgs - packOffset; ICPPTemplateArgument[] pack= new ICPPTemplateArgument[packSize]; System.arraycopy(arguments, packOffset, pack, 0, packSize); @@ -401,7 +401,7 @@ public class CPPTemplates { for (int i = 0; i < arguments.length; i++) { ICPPTemplateArgument arg = arguments[i]; if (arg.isPackExpansion()) { - if (i != arguments.length-1) { + if (i != arguments.length - 1) { return arguments; } havePackExpansion= true; @@ -420,10 +420,10 @@ public class CPPTemplates { // More arguments allowed if we have a parameter pack. if (tparCount < argCount) { - if (tpars[tparCount-1].isParameterPack()) + if (tpars[tparCount - 1].isParameterPack()) return arguments; - if (havePackExpansion && tparCount+1 == argCount) + if (havePackExpansion && tparCount + 1 == argCount) return arguments; return null; } @@ -433,7 +433,7 @@ public class CPPTemplates { return arguments; // Fewer arguments are allowed with default arguments - if (tpars[tparCount-1].isParameterPack()) + if (tpars[tparCount - 1].isParameterPack()) tparCount--; if (tparCount == argCount) @@ -1024,7 +1024,7 @@ public class CPPTemplates { } else if (packSize == PACK_SIZE_DEFER) { newType= origType; } else { - IType[] newResult= new IType[result.length+packSize-1]; + IType[] newResult= new IType[result.length + packSize - 1]; System.arraycopy(result, 0, newResult, 0, j); result= newResult; for (int k= 0; k < packSize; k++) { @@ -1167,7 +1167,7 @@ public class CPPTemplates { return type; } // The parameter types need to be adjusted. - for (int i=0; i 0 || usesTemplateParameter((ICPPASTTemplateId) n, tparnames)) { @@ -1438,17 +1438,17 @@ public class CPPTemplates { b= b.getOwner(); } if (depIDCount > 0) { - nestingLevel+= depIDCount; + nestingLevel += depIDCount; } else if (consumesTDecl < tdeclCount && !lastIsTemplate) { nestingLevel++; lastIsTemplate= true; } } else { - nestingLevel+= depIDCount; + nestingLevel += depIDCount; node= outerMostTDecl.getParent(); while (node != null) { if (node instanceof ICPPASTInternalTemplateDeclaration) { - nestingLevel+= ((ICPPASTInternalTemplateDeclaration) node).getNestingLevel() + 1; + nestingLevel += ((ICPPASTInternalTemplateDeclaration) node).getNestingLevel() + 1; break; } node= node.getParent(); @@ -1461,7 +1461,7 @@ public class CPPTemplates { node= outerMostTDecl.getParent(); while (node != null) { if (node instanceof ICPPASTInternalTemplateDeclaration) { - nestingLevel+= ((ICPPASTInternalTemplateDeclaration) node).getNestingLevel() + 1; + nestingLevel += ((ICPPASTInternalTemplateDeclaration) node).getNestingLevel() + 1; break; } node= node.getParent(); @@ -1470,7 +1470,7 @@ public class CPPTemplates { } node= innerMostTDecl; - while(node instanceof ICPPASTInternalTemplateDeclaration) { + while (node instanceof ICPPASTInternalTemplateDeclaration) { if (--nestingLevel < 0) nestingLevel= 0; tdecl= (ICPPASTInternalTemplateDeclaration) node; @@ -1500,7 +1500,7 @@ public class CPPTemplates { private static CharArraySet collectTemplateParameterNames(ICPPASTTemplateDeclaration tdecl) { CharArraySet set= new CharArraySet(4); - while(true) { + while (true) { ICPPASTTemplateParameter[] pars = tdecl.getTemplateParameters(); for (ICPPASTTemplateParameter par : pars) { IASTName name= CPPTemplates.getTemplateParameterName(par); @@ -1520,7 +1520,7 @@ public class CPPTemplates { private static boolean usesTemplateParameter(final ICPPASTTemplateId id, final CharArraySet names) { final boolean[] result= {false}; ASTVisitor v= new ASTVisitor(false) { - { shouldVisitNames= true; shouldVisitAmbiguousNodes=true;} + { shouldVisitNames= true; shouldVisitAmbiguousNodes= true; } @Override public int visit(IASTName name) { if (name instanceof ICPPASTTemplateId) @@ -1612,7 +1612,7 @@ public class CPPTemplates { } private static ICPPASTInternalTemplateDeclaration getDirectlyEnclosingTemplateDeclaration( - ICPPASTInternalTemplateDeclaration tdecl ) { + ICPPASTInternalTemplateDeclaration tdecl) { final IASTNode parent= tdecl.getParent(); if (parent instanceof ICPPASTInternalTemplateDeclaration) return (ICPPASTInternalTemplateDeclaration) parent; @@ -1680,7 +1680,7 @@ public class CPPTemplates { if (args.length != specArgs.length) { return false; } - for (int i=0; i < args.length; i++) { + for (int i= 0; i < args.length; i++) { if (!specArgs[i].isSameValue(args[i])) return false; } @@ -1792,7 +1792,7 @@ public class CPPTemplates { static ICPPFunction[] instantiateConversionTemplates(ICPPFunction[] functions, IType conversionType, IASTNode point) { boolean checkedForDependentType= false; ICPPFunction[] result= functions; - int i=0; + int i= 0; boolean done= false; for (ICPPFunction f : functions) { ICPPFunction inst = f; @@ -1993,7 +1993,7 @@ public class CPPTemplates { } private static IType[] concat(final IType t, IType[] types) { - IType[] result= new IType[types.length+1]; + IType[] result= new IType[types.length + 1]; result[0]= t; System.arraycopy(types, 0, result, 1, types.length); return result; @@ -2216,8 +2216,8 @@ public class CPPTemplates { private static boolean matchTemplateTemplateParameters(ICPPTemplateParameter[] pParams, ICPPTemplateParameter[] aParams) throws DOMException { - int pi=0; - int ai=0; + int pi= 0; + int ai= 0; while (pi < pParams.length && ai < aParams.length) { final ICPPTemplateParameter pp = pParams[pi]; final ICPPTemplateParameter ap = aParams[ai]; @@ -2250,8 +2250,9 @@ public class CPPTemplates { } if (!matchTemplateTemplateParameters(((ICPPTemplateTemplateParameter) pp).getTemplateParameters(), - ((ICPPTemplateTemplateParameter) ap).getTemplateParameters()) ) + ((ICPPTemplateTemplateParameter) ap).getTemplateParameters())) { return false; + } } } if (!pp.isParameterPack()) From bb949f85d12bd90950bafd575a122d46c62c0499 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 24 Jul 2012 20:34:45 -0700 Subject: [PATCH 05/31] Bug 299911. Work in progress. 20 tests are currently failing. --- .../org/eclipse/cdt/core/dom/ast/IValue.java | 41 +- .../cdt/core/parser/util/CharArrayUtils.java | 13 +- .../cdt/internal/core/dom/parser/Value.java | 842 +++++------------- .../core/dom/parser/cpp/ICPPEvaluation.java | 7 + .../parser/cpp/semantics/CPPEvaluation.java | 17 +- .../parser/cpp/semantics/CPPTemplates.java | 199 ++--- .../dom/parser/cpp/semantics/EvalBinary.java | 32 +- .../cpp/semantics/EvalBinaryTypeId.java | 19 +- .../dom/parser/cpp/semantics/EvalBinding.java | 48 +- .../dom/parser/cpp/semantics/EvalComma.java | 22 +- .../parser/cpp/semantics/EvalCompound.java | 8 +- .../parser/cpp/semantics/EvalConditional.java | 22 +- .../dom/parser/cpp/semantics/EvalFixed.java | 5 + .../cpp/semantics/EvalFunctionCall.java | 16 +- .../parser/cpp/semantics/EvalFunctionSet.java | 10 + .../core/dom/parser/cpp/semantics/EvalID.java | 46 +- .../parser/cpp/semantics/EvalInitList.java | 15 +- .../cpp/semantics/EvalMemberAccess.java | 16 +- .../dom/parser/cpp/semantics/EvalTypeId.java | 25 +- .../dom/parser/cpp/semantics/EvalUnary.java | 17 +- .../parser/cpp/semantics/EvalUnaryTypeID.java | 60 +- .../composite/cpp/CPPCompositesFactory.java | 15 +- 22 files changed, 678 insertions(+), 817 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IValue.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IValue.java index 2f8a2f46b99..c1e8b2b8223 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IValue.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IValue.java @@ -7,9 +7,12 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; + /** * Models a value of a variable, enumerator or expression. * @@ -19,27 +22,33 @@ package org.eclipse.cdt.core.dom.ast; */ public interface IValue { /** - * Returns the value as a number, or null if this is not possible. + * Returns the value as a number, or {@code null} if it is not possible. */ Long numericalValue(); - + /** - * Returns an internal representation of the expression that builds up - * the value. It is suitable for instantiating dependent values but may not be - * used for the purpose of displaying values. + * Returns the evaluation object if this value is dependent, or {@code null} otherwise. + * If {@link #numericalValue()} returns {@code null}, {@link #getEvaluation()} returns + * not {@code null} and vice versa. + * @noreference This method is not intended to be referenced by clients. */ - char[] getInternalExpression(); - + ICPPEvaluation getEvaluation(); + /** - * A value may be dependent on template parameters, in which case a list - * of unknown bindings is maintained for later instantiation. - */ - IBinding[] getUnknownBindings(); - - /** - * Returns a signature containing both the internal representation and - * the unknown bindings. The representation is sufficient to distinguish values - * for the purpose of instantiation, it may not be used to display the value. + * Returns a signature uniquely identifying the value. Two values with identical + * signatures are guaranteed to be equal. */ char[] getSignature(); + + /** + * @deprecated Returns an empty character array. + */ + @Deprecated + char[] getInternalExpression(); + + /** + * @deprecated Returns an empty array. + */ + @Deprecated + IBinding[] getUnknownBindings(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayUtils.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayUtils.java index b3d27ee7b3d..330878bb36c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayUtils.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayUtils.java @@ -329,7 +329,7 @@ public class CharArrayUtils { } /** - * Find an array of chars in an array of arrays of chars. + * Finds an array of chars in an array of arrays of chars. * @return offset where the array was found or -1 */ public static int indexOf(final char[] searchFor, final char[][] searchIn) { @@ -340,4 +340,15 @@ public class CharArrayUtils { } return -1; } + + /** + * Converts a {@link StringBuilder} to a character array. + * @since 5.5 + */ + public static char[] extractChars(StringBuilder buf) { + final int len = buf.length(); + char[] result= new char[len]; + buf.getChars(0, len, result, 0); + return result; + } } 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 41c7f5bb0b2..701b9e71d74 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Wind River Systems, Inc. and others. + * Copyright (c) 2008, 2012 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,12 +11,6 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTCastExpression; @@ -24,7 +18,6 @@ import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; -import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -32,13 +25,14 @@ import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.IVariable; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerClause; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalBinding; import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator; import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator.EvalException; import org.eclipse.cdt.internal.core.pdom.db.TypeMarshalBuffer; @@ -50,112 +44,64 @@ import org.eclipse.core.runtime.CoreException; */ 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 = {}; + public static final Value UNKNOWN= new Value("".toCharArray(), null); //$NON-NLS-1$ + public static final Value NOT_INITIALIZED= new Value("<__>".toCharArray(), null); //$NON-NLS-1$ - private static final String SCOPE_OP = "::"; //$NON-NLS-1$ private static final char UNIQUE_CHAR = '_'; - private static final char TEMPLATE_PARAM_CHAR = '#'; - private static final char TEMPLATE_PARAM_PACK_CHAR = '`'; - private static final char REFERENCE_CHAR = '&'; - 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[] {'6'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY)}; + new Value(new char[] {'0'}, null), + new Value(new char[] {'1'}, null), + new Value(new char[] {'2'}, null), + new Value(new char[] {'3'}, null), + new Value(new char[] {'4'}, null), + new Value(new char[] {'5'}, null), + new Value(new char[] {'6'}, null)}; - private static class Reevaluation { - public final char[] fExpression; - private final int fPackOffset; - public int pos= 0; - public final Map fUnknownSigs; - public final List fUnknowns; - public final IBinding[] fResolvedUnknown; - public final ICPPTemplateParameterMap fMap; - - public Reevaluation(char[] expr, int packOffset, Map unknownSigs, - List unknowns, IBinding[] resolvedUnknowns, ICPPTemplateParameterMap map) { - fExpression= expr; - fPackOffset= packOffset; - fUnknownSigs= unknownSigs; - fUnknowns= unknowns; - fResolvedUnknown= resolvedUnknowns; - fMap= map; - } - - public void nextSeparator() throws UnknownValueException { - final char[] expression = fExpression; - final int len = expression.length; - int idx = pos; - while (idx < len) { - if (expression[idx++] == SEPARATOR) - break; - } - pos= idx; - } - } - private static class UnknownValueException extends Exception {} private static UnknownValueException UNKNOWN_EX= new UnknownValueException(); private static int sUnique= 0; - private final char[] fExpression; - private final ICPPUnknownBinding[] fUnknownBindings; + // The following invariant always holds: (fFixedValue == null) != (fEvaluation == null) + private final char[] fFixedValue; + private final ICPPEvaluation fEvaluation; private char[] fSignature; - private Value(char[] rep, ICPPUnknownBinding[] unknown) { - assert rep != null; - fExpression= rep; - fUnknownBindings= unknown; + private Value(char[] fixedValue, ICPPEvaluation evaluation) { + assert (fixedValue == null) != (evaluation == null); + fFixedValue = fixedValue; + fEvaluation = evaluation; } @Override - public char[] getInternalExpression() { - return fExpression; + public Long numericalValue() { + return fFixedValue == null ? null : parseLong(fFixedValue); } @Override - public IBinding[] getUnknownBindings() { - return fUnknownBindings; + public ICPPEvaluation getEvaluation() { + return fEvaluation; } @Override public char[] getSignature() { if (fSignature == null) { - if (fUnknownBindings.length == 0) { - fSignature= fExpression; - } else { - StringBuilder buf= new StringBuilder(); - buf.append(fExpression); - buf.append('['); - for (int i = 0; i < fUnknownBindings.length; i++) { - if (i > 0) - buf.append(','); - buf.append(getSignatureForUnknown(fUnknownBindings[i])); - } - buf.append(']'); - final int end= buf.length(); - fSignature= new char[end]; - buf.getChars(0, end, fSignature, 0); - } + fSignature = fFixedValue != null ? fFixedValue : fEvaluation.getSignature(); } return fSignature; } + @Deprecated @Override - public Long numericalValue() { - return parseLong(fExpression); + public char[] getInternalExpression() { + return CharArrayUtils.EMPTY_CHAR_ARRAY; + } + + @Deprecated + @Override + public IBinding[] getUnknownBindings() { + return IBinding.EMPTY_BINDING_ARRAY; } public void marshall(ITypeMarshalBuffer buf) throws CoreException { @@ -174,11 +120,7 @@ public class Value implements IValue { } } else { buf.putByte((ITypeMarshalBuffer.VALUE)); - buf.putCharArray(fExpression); - buf.putShort((short) fUnknownBindings.length); - for (ICPPUnknownBinding b : fUnknownBindings) { - buf.marshalBinding(b); - } + fEvaluation.marshal(buf, true); } } } @@ -198,48 +140,26 @@ public class Value implements IValue { return Value.create(val); } - char[] expr = buf.getCharArray(); - final int len= buf.getShort(); - ICPPUnknownBinding[] unknowns= new ICPPUnknownBinding[len]; - for (int i = 0; i < unknowns.length; i++) { - final ICPPUnknownBinding unknown = (ICPPUnknownBinding) buf.unmarshalBinding(); - if (unknown == null) { - return Value.UNKNOWN; - } - unknowns[i]= unknown; - } - return new Value(expr, unknowns); + ISerializableEvaluation eval= buf.unmarshalEvaluation(); + if (eval instanceof ICPPEvaluation) + return new Value(null, (ICPPEvaluation) eval); + return Value.UNKNOWN; } @Override public int hashCode() { - return CharArrayUtils.hash(fExpression); + return CharArrayUtils.hash(getSignature()); } @Override public boolean equals(Object obj) { - if (!(obj instanceof IValue)) { + if (!(obj instanceof Value)) { return false; } - 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) { - if (!getSignatureForUnknown((ICPPUnknownBinding) rhsUnknown).equals(getSignatureForUnknown(fUnknownBindings[i]))) { - return false; - } - } else { - return false; - } - } - return true; + final Value rhs = (Value) obj; + if (fFixedValue != null) + return CharArrayUtils.equals(fFixedValue, rhs.fFixedValue); + return CharArrayUtils.equals(getSignature(), rhs.getSignature()); } @Override @@ -253,41 +173,59 @@ public class Value implements IValue { public static IValue create(long value) { if (value >=0 && value < TYPICAL.length) return TYPICAL[(int) value]; - return new Value(toCharArray(value), ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY); + return new Value(toCharArray(value), null); + } + + /** + * Creates a value object representing the given boolean value. + */ + public static IValue create(boolean value) { + return create(value ? 1 : 0); } /** * Creates a value representing the given template parameter. */ public static IValue create(ICPPTemplateNonTypeParameter tntp) { - final String expr = createTemplateParamExpression(tntp.getParameterID(), tntp.isParameterPack()); - return new Value(expr.toCharArray(), ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY); - } - - private static String createTemplateParamExpression(int id, boolean isPack) { - StringBuilder buf= new StringBuilder(); - buf.append(isPack ? TEMPLATE_PARAM_PACK_CHAR : TEMPLATE_PARAM_CHAR); - buf.append(Integer.toHexString(id)); - return buf.toString(); + EvalBinding eval = new EvalBinding(tntp, null); + return new Value(null, eval); } /** - * 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. + * Create a value wrapping the given evaluation. + */ + public static IValue create(ICPPEvaluation eval) { + return new Value(null, eval); + } + + public static IValue evaluateBinaryExpression(final int op, final long v1, final long v2) { + try { + return create(combineBinary(op, v1, v2)); + } catch (UnknownValueException e) { + } + return UNKNOWN; + } + + public static IValue evaluateUnaryExpression(final int unaryOp, final long value) { + try { + return create(combineUnary(unaryOp, value)); + } catch (UnknownValueException e) { + } + return UNKNOWN; + } + + /** + * Tests whether the value is a template parameter (or parameter pack). + * + * @return the parameter id of the parameter, or -1 if it is not a template + * parameter. */ public static int isTemplateParameter(IValue tval) { - final char[] rep= tval.getInternalExpression(); - if (rep.length > 0) { - final char c = rep[0]; - if (c == TEMPLATE_PARAM_CHAR || c == TEMPLATE_PARAM_PACK_CHAR) { - for (int i = 1; i < rep.length; i++) { - if (rep[i] == SEPARATOR) - return -1; - } - try { - return parseHex(rep, 1); - } catch (UnknownValueException e) { - } + ICPPEvaluation eval = tval.getEvaluation(); + if (eval instanceof EvalBinding) { + IBinding binding = ((EvalBinding) eval).getBinding(); + if (binding instanceof ICPPTemplateParameter) { + ((ICPPTemplateParameter) binding).getParameterID(); } } return -1; @@ -296,63 +234,23 @@ public class Value implements IValue { /** * Tests whether the value directly references some template parameter. */ + // TODO(sprigogin): The semantics of "directly" is unclear. public static boolean referencesTemplateParameter(IValue tval) { - final char[] rep= tval.getInternalExpression(); - for (char element : rep) { - if (element == TEMPLATE_PARAM_CHAR || element == TEMPLATE_PARAM_PACK_CHAR) - return true; - } - return false; + // TODO(sprigogin): Implementation of this method is probably incomplete since it interprets "directly" in a very direct way. The old code is kept below for reference. + return isTemplateParameter(tval) >= 0; +// final char[] rep= tval.getInternalExpression(); +// for (char element : rep) { +// if (element == TEMPLATE_PARAM_CHAR || element == TEMPLATE_PARAM_PACK_CHAR) +// return true; +// } +// return false; } /** * Tests whether the value depends on a template parameter. */ public static boolean isDependentValue(IValue nonTypeValue) { - final char[] rep= nonTypeValue.getInternalExpression(); - for (final char c : rep) { - if (c == REFERENCE_CHAR || c == TEMPLATE_PARAM_CHAR || c == TEMPLATE_PARAM_PACK_CHAR) - return true; - } - return false; - } - - /** - * Collects all references to parameter packs. - */ - public static int[] getParameterPackReferences(IValue value) { - final char[] rep= value.getInternalExpression(); - int result= -1; - List array= null; - for (int i=0; i(2); - array.add(result); - } - array.add(ref); - } - } catch (UnknownValueException e) { - } - } - } - if (array != null) { - int[] ra= new int[array.size()]; - for (int i = 0; i < ra.length; i++) { - ra[i]= array.get(i); - } - return ra; - } - if (result != -1) - return new int[] {result}; - - return NO_INT; + return nonTypeValue.getEvaluation() != null; } /** @@ -360,19 +258,14 @@ public class Value implements IValue { */ public static IValue create(IASTExpression expr, int maxRecursionDepth) { try { - Map unknownSigs= new HashMap(); - List unknown= new ArrayList(); - Object obj= evaluate(expr, unknownSigs, unknown, maxRecursionDepth); - if (obj instanceof Number) - return create(((Number) obj).longValue()); + Object obj= evaluate(expr, maxRecursionDepth); + if (obj instanceof Long) + return create(((Long) obj).longValue()); - ICPPUnknownBinding[] ua; - if (unknown.isEmpty()) { - ua= ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY; - } else { - ua= unknown.toArray(new ICPPUnknownBinding[unknown.size()]); + if (expr instanceof ICPPASTInitializerClause) { + ICPPEvaluation evaluation = ((ICPPASTInitializerClause) expr).getEvaluation(); + return new Value(null, evaluation); } - return new Value(((String)obj).toCharArray(), ua); } catch (UnknownValueException e) { } return UNKNOWN; @@ -381,15 +274,8 @@ public class Value implements IValue { /** * 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) - return create(l.longValue()); - - return new Value(rep, unknown); + public static IValue fromInternalRepresentation(ICPPEvaluation evaluation) { + return new Value(null, evaluation); } /** @@ -399,67 +285,59 @@ 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(CharArrayUtils.extractChars(buf), null); } /** * Computes the canonical representation of the value of the expression. - * Returns a {@code Number} for numerical values or a {@code String}, otherwise. + * Returns a {@code Long} for numerical values or {@code null}, otherwise. * @throws UnknownValueException */ - private static Object evaluate(IASTExpression e, Map unknownSigs, - List unknowns, int maxdepth) throws UnknownValueException { - if (maxdepth < 0 || e == null) + private static Long evaluate(IASTExpression exp, int maxdepth) throws UnknownValueException { + if (maxdepth < 0 || exp == null) throw UNKNOWN_EX; - if (e instanceof IASTArraySubscriptExpression) { + if (exp instanceof IASTArraySubscriptExpression) { throw UNKNOWN_EX; } - if (e instanceof IASTBinaryExpression) { - return evaluateBinaryExpression((IASTBinaryExpression) e, unknownSigs, unknowns, maxdepth); + if (exp instanceof IASTBinaryExpression) { + return evaluateBinaryExpression((IASTBinaryExpression) exp, maxdepth); } - if (e instanceof IASTCastExpression) { // must be ahead of unary - return evaluate(((IASTCastExpression) e).getOperand(), unknownSigs, unknowns, maxdepth); + if (exp instanceof IASTCastExpression) { // must be ahead of unary + return evaluate(((IASTCastExpression) exp).getOperand(), maxdepth); } - if (e instanceof IASTUnaryExpression) { - return evaluateUnaryExpression((IASTUnaryExpression) e, unknownSigs, unknowns, maxdepth); + if (exp instanceof IASTUnaryExpression) { + return evaluateUnaryExpression((IASTUnaryExpression) exp, maxdepth); } - if (e instanceof IASTConditionalExpression) { - IASTConditionalExpression cexpr= (IASTConditionalExpression) e; - Object o= evaluate(cexpr.getLogicalConditionExpression(), unknownSigs, unknowns, maxdepth); - if (o instanceof Number) { - Number v= (Number) o; - if (v.longValue() == 0) { - return evaluate(cexpr.getNegativeResultExpression(), unknownSigs, unknowns, maxdepth); - } - final IASTExpression pe = cexpr.getPositiveResultExpression(); - if (pe == null) // gnu-extension allows to omit the positive expression. - return o; - return evaluate(pe, unknownSigs, unknowns, maxdepth); + if (exp instanceof IASTConditionalExpression) { + IASTConditionalExpression cexpr= (IASTConditionalExpression) exp; + Long v= evaluate(cexpr.getLogicalConditionExpression(), maxdepth); + if (v == null) + return null; + if (v.longValue() == 0) { + return evaluate(cexpr.getNegativeResultExpression(), maxdepth); } - final IASTExpression pe = cexpr.getPositiveResultExpression(); - Object po= pe == null ? o : evaluate(pe, unknownSigs, unknowns, maxdepth); - Object neg= evaluate(cexpr.getNegativeResultExpression(), unknownSigs, unknowns, maxdepth); - return "" + CONDITIONAL_CHAR + SEPARATOR + o.toString() + SEPARATOR + po.toString() + //$NON-NLS-1$ - SEPARATOR + neg.toString(); + if (pe == null) // gnu-extension allows to omit the positive expression. + return v; + return evaluate(pe, maxdepth); } - if (e instanceof IASTIdExpression) { - IBinding b= ((IASTIdExpression) e).getName().resolvePreBinding(); - return evaluateBinding(b, unknownSigs, unknowns, maxdepth); + if (exp instanceof IASTIdExpression) { + IBinding b= ((IASTIdExpression) exp).getName().resolvePreBinding(); + return evaluateBinding(b, maxdepth); } - if (e instanceof IASTLiteralExpression) { - IASTLiteralExpression litEx= (IASTLiteralExpression) e; + if (exp instanceof IASTLiteralExpression) { + IASTLiteralExpression litEx= (IASTLiteralExpression) exp; switch (litEx.getKind()) { case IASTLiteralExpression.lk_false: case IASTLiteralExpression.lk_nullptr: - return 0; + return Long.valueOf(0); case IASTLiteralExpression.lk_true: - return 1; + return Long.valueOf(1); case IASTLiteralExpression.lk_integer_constant: try { return ExpressionEvaluator.getNumber(litEx.getValue()); - } catch (EvalException e1) { + } catch (EvalException e) { throw UNKNOWN_EX; } case IASTLiteralExpression.lk_char_constant: @@ -468,13 +346,13 @@ public class Value implements IValue { if (image.length > 1 && image[0] == 'L') return ExpressionEvaluator.getChar(image, 2); return ExpressionEvaluator.getChar(image, 1); - } catch (EvalException e1) { + } catch (EvalException e) { throw UNKNOWN_EX; } } } - if (e instanceof IASTTypeIdExpression) { - IASTTypeIdExpression typeIdEx = (IASTTypeIdExpression) e; + if (exp instanceof IASTTypeIdExpression) { + IASTTypeIdExpression typeIdEx = (IASTTypeIdExpression) exp; switch (typeIdEx.getOperator()) { case IASTTypeIdExpression.op_sizeof: final IType type; @@ -493,18 +371,16 @@ public class Value implements IValue { /** * Extract a value off a binding. */ - private static Object evaluateBinding(IBinding b, Map unknownSigs, - List unknowns, int maxdepth) throws UnknownValueException { + private static Long evaluateBinding(IBinding b, int maxdepth) throws UnknownValueException { if (b instanceof IType) { throw UNKNOWN_EX; } if (b instanceof ICPPTemplateNonTypeParameter) { - final ICPPTemplateNonTypeParameter tp = (ICPPTemplateNonTypeParameter) b; - return createTemplateParamExpression(tp.getParameterID(), tp.isParameterPack()); + return null; } if (b instanceof ICPPUnknownBinding) { - return createReference((ICPPUnknownBinding) b, unknownSigs, unknowns); + return null; } IValue value= null; @@ -515,78 +391,22 @@ public class Value implements IValue { } else if (b instanceof IEnumerator) { value= ((IEnumerator) b).getValue(); } - if (value != null) - return evaluateValue(value, unknownSigs, unknowns); + if (value != null && value != Value.UNKNOWN) { + return value.numericalValue(); + } throw UNKNOWN_EX; } - private static Object createReference(ICPPUnknownBinding unknown, - Map unknownSigs, List unknowns) { - String sig= getSignatureForUnknown(unknown); - Integer idx= unknownSigs.get(sig); - if (idx == null) { - idx= unknownSigs.size(); - unknownSigs.put(sig, idx); - unknowns.add(unknown); - } - return "" + REFERENCE_CHAR + idx.toString(); //$NON-NLS-1$ - } - - private static Object evaluateValue(IValue cv, Map unknownSigs, - List unknowns) throws UnknownValueException { - 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++) { - final char c= expr[i]; - switch (c) { - case REFERENCE_CHAR: { - int idx= parseNonNegative(expr, i + 1); - if (idx >= oldUnknowns.length) - throw UNKNOWN_EX; - final IBinding old = oldUnknowns[idx]; - if (!(old instanceof ICPPUnknownBinding)) - throw UNKNOWN_EX; - - buf.append(createReference((ICPPUnknownBinding) old, unknownSigs, unknowns)); - skipToSeparator= true; - break; - } - case SEPARATOR: - skipToSeparator= false; - buf.append(c); - break; - default: - if (!skipToSeparator) - buf.append(c); - break; - } - } - return buf.toString(); - } - - private static Object evaluateUnaryExpression(IASTUnaryExpression ue, - Map unknownSigs, List unknowns, int maxdepth) + private static Long evaluateUnaryExpression(IASTUnaryExpression exp, int maxdepth) throws UnknownValueException { - final int unaryOp= ue.getOperator(); + final int unaryOp= exp.getOperator(); if (unaryOp == IASTUnaryExpression.op_sizeof) { - final IASTExpression operand = ue.getOperand(); + final IASTExpression operand = exp.getOperand(); if (operand != null) { IType type = operand.getExpressionType(); - ASTTranslationUnit ast = (ASTTranslationUnit) ue.getTranslationUnit(); + ASTTranslationUnit ast = (ASTTranslationUnit) exp.getTranslationUnit(); SizeofCalculator calculator = ast.getSizeofCalculator(); SizeAndAlignment info = calculator.sizeAndAlignment(type); if (info != null) @@ -600,338 +420,109 @@ public class Value implements IValue { throw UNKNOWN_EX; } - final Object value= evaluate(ue.getOperand(), unknownSigs, unknowns, maxdepth); + final Long value= evaluate(exp.getOperand(), maxdepth); + if (value == null) + return null; return combineUnary(unaryOp, value); } - private static Object combineUnary(final int unaryOp, final Object value) throws UnknownValueException { + private static long combineUnary(final int unaryOp, final long value) throws UnknownValueException { switch (unaryOp) { case IASTUnaryExpression.op_bracketedPrimary: case IASTUnaryExpression.op_plus: return value; } - if (value instanceof Number) { - long v= ((Number) value).longValue(); - switch (unaryOp) { - case IASTUnaryExpression.op_prefixIncr: - case IASTUnaryExpression.op_postFixIncr: - return ++v; - case IASTUnaryExpression.op_prefixDecr: - case IASTUnaryExpression.op_postFixDecr: - return --v; - case IASTUnaryExpression.op_minus: - return -v; - case IASTUnaryExpression.op_tilde: - return ~v; - case IASTUnaryExpression.op_not: - return v == 0 ? 1 : 0; - } - throw UNKNOWN_EX; - } - switch (unaryOp) { case IASTUnaryExpression.op_prefixIncr: case IASTUnaryExpression.op_postFixIncr: + return value + 1; case IASTUnaryExpression.op_prefixDecr: case IASTUnaryExpression.op_postFixDecr: + return value - 1; case IASTUnaryExpression.op_minus: + return -value; case IASTUnaryExpression.op_tilde: + return ~value; case IASTUnaryExpression.op_not: - return "" + UNARY_OP_CHAR + unaryOp + SEPARATOR + value.toString(); //$NON-NLS-1$ + return value == 0 ? 1 : 0; } throw UNKNOWN_EX; } - private static Object evaluateBinaryExpression(IASTBinaryExpression be, - Map unknownSigs, List unknowns, int maxdepth) + private static Long evaluateBinaryExpression(IASTBinaryExpression exp, int maxdepth) throws UnknownValueException { - final Object o1= evaluate(be.getOperand1(), unknownSigs, unknowns, maxdepth); - final Object o2= evaluate(be.getOperand2(), unknownSigs, unknowns, maxdepth); + final int op= exp.getOperator(); + switch (op) { + case IASTBinaryExpression.op_equals: + if (exp.getOperand1().equals(exp.getOperand2())) + return Long.valueOf(1); + break; + case IASTBinaryExpression.op_notequals: + if (exp.getOperand1().equals(exp.getOperand2())) + return Long.valueOf(0); + break; + } + + final Long o1= evaluate(exp.getOperand1(), maxdepth); + if (o1 == null) + return null; + final Long o2= evaluate(exp.getOperand2(), maxdepth); + if (o2 == null) + return null; - final int op= be.getOperator(); return combineBinary(op, o1, o2); } - private static Object combineBinary(final int op, final Object o1, final Object o2) + private static long combineBinary(final int op, final long v1, final long v2) throws UnknownValueException { - if (o1 instanceof Number && o2 instanceof Number) { - long v1= ((Number) o1).longValue(); - long v2= ((Number) o2).longValue(); - switch (op) { - case IASTBinaryExpression.op_multiply: - return v1 * v2; - case IASTBinaryExpression.op_divide: - if (v2 == 0) - throw UNKNOWN_EX; - return v1 / v2; - case IASTBinaryExpression.op_modulo: - if (v2 == 0) - throw UNKNOWN_EX; - return v1 % v2; - case IASTBinaryExpression.op_plus: - return v1 + v2; - case IASTBinaryExpression.op_minus: - return v1 - v2; - case IASTBinaryExpression.op_shiftLeft: - return v1 << v2; - case IASTBinaryExpression.op_shiftRight: - return v1 >> v2; - case IASTBinaryExpression.op_lessThan: - return v1 < v2 ? 1 : 0; - case IASTBinaryExpression.op_greaterThan: - return v1 > v2 ? 1 : 0; - case IASTBinaryExpression.op_lessEqual: - return v1 <= v2 ? 1 : 0; - case IASTBinaryExpression.op_greaterEqual: - return v1 >= v2 ? 1 : 0; - case IASTBinaryExpression.op_binaryAnd: - return v1 & v2; - case IASTBinaryExpression.op_binaryXor: - return v1 ^ v2; - case IASTBinaryExpression.op_binaryOr: - return v1 | v2; - case IASTBinaryExpression.op_logicalAnd: - return v1 != 0 && v2 != 0 ? 1 : 0; - case IASTBinaryExpression.op_logicalOr: - return v1 != 0 || v2 != 0 ? 1 : 0; - case IASTBinaryExpression.op_equals: - return v1 == v2 ? 1 : 0; - case IASTBinaryExpression.op_notequals: - return v1 != v2 ? 1 : 0; - case IASTBinaryExpression.op_max: - return Math.max(v1, v2); - case IASTBinaryExpression.op_min: - return Math.min(v1, v2); - } - throw UNKNOWN_EX; - } switch (op) { case IASTBinaryExpression.op_multiply: + return v1 * v2; case IASTBinaryExpression.op_divide: + if (v2 == 0) + throw UNKNOWN_EX; + return v1 / v2; case IASTBinaryExpression.op_modulo: + if (v2 == 0) + throw UNKNOWN_EX; + return v1 % v2; case IASTBinaryExpression.op_plus: + return v1 + v2; case IASTBinaryExpression.op_minus: + return v1 - v2; case IASTBinaryExpression.op_shiftLeft: + return v1 << v2; case IASTBinaryExpression.op_shiftRight: + return v1 >> v2; case IASTBinaryExpression.op_lessThan: + return v1 < v2 ? 1 : 0; case IASTBinaryExpression.op_greaterThan: + return v1 > v2 ? 1 : 0; case IASTBinaryExpression.op_lessEqual: + return v1 <= v2 ? 1 : 0; case IASTBinaryExpression.op_greaterEqual: + return v1 >= v2 ? 1 : 0; case IASTBinaryExpression.op_binaryAnd: + return v1 & v2; case IASTBinaryExpression.op_binaryXor: + return v1 ^ v2; case IASTBinaryExpression.op_binaryOr: + return v1 | v2; case IASTBinaryExpression.op_logicalAnd: + return v1 != 0 && v2 != 0 ? 1 : 0; case IASTBinaryExpression.op_logicalOr: - case IASTBinaryExpression.op_max: - case IASTBinaryExpression.op_min: - break; + return v1 != 0 || v2 != 0 ? 1 : 0; case IASTBinaryExpression.op_equals: - if (o1.equals(o2)) - return 1; - break; + return v1 == v2 ? 1 : 0; case IASTBinaryExpression.op_notequals: - if (o1.equals(o2)) - return 0; - break; - default: - throw UNKNOWN_EX; + return v1 != v2 ? 1 : 0; + case IASTBinaryExpression.op_max: + return Math.max(v1, v2); + case IASTBinaryExpression.op_min: + return Math.min(v1, v2); } - - 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 { - Map unknownSigs= new HashMap(); - List unknown= new ArrayList(); - Reevaluation reeval= new Reevaluation(val.getInternalExpression(), packOffset, - unknownSigs, unknown, - resolvedUnknowns, map); - 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; - } else { - ua= unknown.toArray(new ICPPUnknownBinding[unknown.size()]); - } - return new Value(((String)obj).toCharArray(), ua); - } catch (UnknownValueException e) { - } - return UNKNOWN; - } - - private static Object reevaluate(Reevaluation reeval, int maxdepth) - throws UnknownValueException { - if (maxdepth < 0) - throw UNKNOWN_EX; - - final int idx= reeval.pos; - final char[] buf= reeval.fExpression; - final int length = buf.length; - if (idx >= length) - throw UNKNOWN_EX; - - final char c= buf[idx]; - switch (c) { - case BINARY_OP_CHAR: - int op= parseNonNegative(buf, idx + 1); - reeval.nextSeparator(); - Object o1= reevaluate(reeval, maxdepth); - Object o2= reevaluate(reeval, maxdepth); - return combineBinary(op, o1, o2); - case UNARY_OP_CHAR: - op= parseNonNegative(buf, idx + 1); - reeval.nextSeparator(); - o1= reevaluate(reeval, maxdepth); - return combineUnary(op, o1); - case CONDITIONAL_CHAR: - reeval.nextSeparator(); - Object cond= reevaluate(reeval, maxdepth); - Object po= reevaluate(reeval, maxdepth); - Object neg= reevaluate(reeval, maxdepth); - if (cond instanceof Number) { - Number v= (Number) cond; - if (v.longValue() == 0) { - return neg; - } - return po; - } - return "" + CONDITIONAL_CHAR + SEPARATOR + cond.toString() + SEPARATOR + //$NON-NLS-1$ - po.toString() + SEPARATOR + neg.toString(); - case REFERENCE_CHAR: - int num= parseNonNegative(buf, idx + 1); - final IBinding[] resolvedUnknowns= reeval.fResolvedUnknown; - if (num >= resolvedUnknowns.length) - throw UNKNOWN_EX; - reeval.nextSeparator(); - return evaluateBinding(resolvedUnknowns[num], reeval.fUnknownSigs, reeval.fUnknowns, maxdepth); - - case TEMPLATE_PARAM_CHAR: - num= parseHex(buf, idx + 1); - reeval.nextSeparator(); - ICPPTemplateArgument arg = reeval.fMap.getArgument(num); - if (arg != null) { - IValue val= arg.getNonTypeValue(); - if (val == null) - throw UNKNOWN_EX; - return evaluateValue(val, reeval.fUnknownSigs, reeval.fUnknowns); - } - return createTemplateParamExpression(num, false); - - case TEMPLATE_PARAM_PACK_CHAR: - num= parseHex(buf, idx + 1); - reeval.nextSeparator(); - arg= null; - if (reeval.fPackOffset >= 0) { - ICPPTemplateArgument[] args= reeval.fMap.getPackExpansion(num); - if (args != null && reeval.fPackOffset < args.length) { - arg= args[reeval.fPackOffset]; - } - } - if (arg != null) { - IValue val= arg.getNonTypeValue(); - if (val == null) - throw UNKNOWN_EX; - return evaluateValue(val, reeval.fUnknownSigs, reeval.fUnknowns); - } - return createTemplateParamExpression(num, true); - - default: - reeval.nextSeparator(); - return parseLong(buf, idx); - } - } - - /** - * Parses a non negative int. - */ - private static int parseNonNegative(char[] value, int offset) throws UnknownValueException { - final long maxvalue= Integer.MAX_VALUE/10; - final int len= value.length; - int result = 0; - boolean ok= false; - 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; - } - if (!ok) - throw UNKNOWN_EX; - return result; - } - - /** - * Parses a a hex value. - */ - private static int parseHex(char[] value, int offset) throws UnknownValueException { - int result = 0; - boolean ok= false; - final int len= value.length; - for (; offset < len; offset++) { - int digit= (value[offset] - '0'); - if (digit < 0 || digit > 9) { - digit += '0' - 'a' + 10; - if (digit < 10 || digit > 15) { - digit += 'a' - 'A'; - if (digit < 10 || digit > 15) { - break; - } - } - } - if ((result & 0xf0000000) != 0) - throw UNKNOWN_EX; - - result= (result << 4) + digit; - ok= true; - } - if (!ok) - throw UNKNOWN_EX; - - return result; - } - - /** - * Parses a long. - */ - private static long parseLong(char[] value, int offset) throws UnknownValueException { - final long maxvalue= Long.MAX_VALUE / 10; - 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++) { - 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; + throw UNKNOWN_EX; } /** @@ -963,37 +554,12 @@ public class Value implements IValue { return negative ? -result : result; } - /** - * Computes a signature for an unknown binding. - */ - private static String getSignatureForUnknown(ICPPUnknownBinding binding) { - IBinding owner= binding.getOwner(); - if (owner instanceof IType) { - StringBuilder buf= new StringBuilder(); - ASTTypeUtil.appendType((IType) owner, true, buf); - return buf.append(SCOPE_OP).append(binding.getName()).toString(); - } - return binding.getName(); - } - /** * Converts long to a char array */ private static char[] toCharArray(long value) { StringBuilder buf= new StringBuilder(); buf.append(value); - return extractChars(buf); - } - - private static char[] extractChars(StringBuilder buf) { - final int len = buf.length(); - char[] result= new char[len]; - buf.getChars(0, len, result, 0); - return result; - } - - public static IValue create(ICPPEvaluation eval, IASTNode point) { - // Compute value of evaluation - return Value.UNKNOWN; + return CharArrayUtils.extractChars(buf); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java index 28a371e02be..48d743d2697 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java @@ -69,4 +69,11 @@ public interface ICPPEvaluation extends ISerializableEvaluation { */ ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, int maxdepth, IASTNode point); + + /** + * Determines size of the template parameter pack. + * + * @noreference This method is not intended to be referenced by clients. + */ + int determinePackSize(ICPPTemplateParameterMap tpMap); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java index 69460068b57..9bd224ccac0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java @@ -15,6 +15,8 @@ import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; @@ -45,6 +47,10 @@ public abstract class CPPEvaluation implements ICPPEvaluation { return fBuffer.toString(); } + public char[] getSignature() { + return CharArrayUtils.extractChars(fBuffer); + } + @Override public void marshalBinding(IBinding binding) throws CoreException { if (binding instanceof ISerializableType) { @@ -53,12 +59,11 @@ public abstract class CPPEvaluation implements ICPPEvaluation { putByte(NULL_TYPE); } else { appendSeparator(); - IBinding owner= binding.getOwner(); - if (owner instanceof IType) { - ASTTypeUtil.appendType((IType) owner, true, fBuffer); - fBuffer.append("::"); //$NON-NLS-1$ + if (binding instanceof ICPPBinding) { + fBuffer.append(ASTTypeUtil.getQualifiedName((ICPPBinding) binding)); + } else { + fBuffer.append(binding.getNameCharArray()); } - fBuffer.append(binding.getName()); } } @@ -223,6 +228,6 @@ public abstract class CPPEvaluation implements ICPPEvaluation { CCorePlugin.log(e); return new char[] { '?' }; } - return buf.toString().toCharArray(); + return buf.getSignature(); } } \ No newline at end of file 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 acec6713497..b4f594d148a 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 @@ -51,7 +51,6 @@ import org.eclipse.cdt.core.dom.ast.ISemanticProblem; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.IValue; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAmbiguousTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; @@ -138,6 +137,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUsingDeclarationSpecialization; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPASTInternalTemplateDeclaration; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalClassTemplate; @@ -153,9 +153,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.UDCMod * type instantiation. */ public class CPPTemplates { - private static final int PACK_SIZE_DEFER = -1; - private static final int PACK_SIZE_FAIL = -2; - private static final int PACK_SIZE_NOT_FOUND = Integer.MAX_VALUE; + static final int PACK_SIZE_DEFER = -1; + static final int PACK_SIZE_FAIL = -2; + static final int PACK_SIZE_NOT_FOUND = Integer.MAX_VALUE; private static final ICPPFunction[] NO_FUNCTIONS = {}; static enum TypeSelection { PARAMETERS, RETURN_TYPE, PARAMETERS_AND_RETURN_TYPE } @@ -225,7 +225,7 @@ public class CPPTemplates { } if (isPack) { - int packOffset= numParams - 1; + int packOffset= numParams-1; int packSize= numArgs - packOffset; ICPPTemplateArgument[] pack= new ICPPTemplateArgument[packSize]; System.arraycopy(arguments, packOffset, pack, 0, packSize); @@ -402,7 +402,7 @@ public class CPPTemplates { for (int i = 0; i < arguments.length; i++) { ICPPTemplateArgument arg = arguments[i]; if (arg.isPackExpansion()) { - if (i != arguments.length - 1) { + if (i != arguments.length-1) { return arguments; } havePackExpansion= true; @@ -421,10 +421,10 @@ public class CPPTemplates { // More arguments allowed if we have a parameter pack. if (tparCount < argCount) { - if (tpars[tparCount - 1].isParameterPack()) + if (tpars[tparCount-1].isParameterPack()) return arguments; - if (havePackExpansion && tparCount + 1 == argCount) + if (havePackExpansion && tparCount+1 == argCount) return arguments; return null; } @@ -434,7 +434,7 @@ public class CPPTemplates { return arguments; // Fewer arguments are allowed with default arguments - if (tpars[tparCount - 1].isParameterPack()) + if (tpars[tparCount-1].isParameterPack()) tparCount--; if (tparCount == argCount) @@ -862,43 +862,20 @@ public class CPPTemplates { ICPPClassSpecialization within, int maxdepth, IASTNode point) { if (value == null) return null; - IBinding[] unknowns= value.getUnknownBindings(); - IBinding[] resolvedUnknowns= null; - if (unknowns.length != 0) { - for (int i = 0; i < unknowns.length; i++) { - IBinding unknown= unknowns[i]; - IBinding resolved= unknown; - if (unknown instanceof ICPPUnknownBinding) { - try { - resolved= resolveUnknown((ICPPUnknownBinding) unknown, tpMap, packOffset, within, point); - } catch (DOMException e) { - return Value.UNKNOWN; - } - } - if (resolvedUnknowns != null) { - resolvedUnknowns[i]= resolved; - } else if (resolved != unknown) { - resolvedUnknowns= new IBinding[unknowns.length]; - System.arraycopy(unknowns, 0, resolvedUnknowns, 0, i); - resolvedUnknowns[i]= resolved; - } - } - } - - if (resolvedUnknowns != null) - return Value.reevaluate(value, packOffset, resolvedUnknowns, tpMap, maxdepth); - - if (Value.referencesTemplateParameter(value)) - return Value.reevaluate(value, packOffset, unknowns, tpMap, maxdepth); - - return value; + ICPPEvaluation evaluation = value.getEvaluation(); + if (evaluation == null) + return value; + ICPPEvaluation instantiated = evaluation.instantiate(tpMap, packOffset, within, maxdepth, point); + if (instantiated == evaluation) + return value; + return instantiated.getValue(point); } public static boolean containsParameterPack(IType type) { return determinePackSize(type, CPPTemplateParameterMap.EMPTY) == PACK_SIZE_DEFER; } - private static int determinePackSize(IType type, ICPPTemplateParameterMap tpMap) { + static int determinePackSize(IType type, ICPPTemplateParameterMap tpMap) { if (type instanceof ICPPFunctionType) { final ICPPFunctionType ft = (ICPPFunctionType) type; final IType rt = ft.getReturnType(); @@ -907,7 +884,7 @@ public class CPPTemplates { return r; IType[] ps = ft.getParameterTypes(); for (IType pt : ps) { - r= combine(r, determinePackSize(pt, tpMap)); + r= combinePackSize(r, determinePackSize(pt, tpMap)); if (r < 0) return r; } @@ -915,37 +892,17 @@ public class CPPTemplates { } if (type instanceof ICPPTemplateParameter) { - final ICPPTemplateParameter tpar = (ICPPTemplateParameter) type; - if (tpar.isParameterPack()) { - ICPPTemplateArgument[] args= tpMap.getPackExpansion(tpar); - if (args != null) - return args.length; - return PACK_SIZE_DEFER; - } - return PACK_SIZE_NOT_FOUND; + return determinePackSize((ICPPTemplateParameter) type, tpMap); } - int r= PACK_SIZE_NOT_FOUND; if (type instanceof ICPPUnknownBinding) { - if (type instanceof ICPPDeferredClassInstance) { - ICPPDeferredClassInstance dcl= (ICPPDeferredClassInstance) type; - ICPPTemplateArgument[] args = dcl.getTemplateArguments(); - for (ICPPTemplateArgument arg : args) { - r= combine(r, determinePackSize(arg, tpMap)); - if (r < 0) - return r; - } - } - IBinding binding= ((ICPPUnknownBinding) type).getOwner(); - if (binding instanceof IType) - r= combine(r, determinePackSize((IType) binding, tpMap)); - - return r; + return determinePackSize((ICPPUnknownBinding) type, tpMap); } if (type instanceof ICPPParameterPackType) return PACK_SIZE_NOT_FOUND; + int r= PACK_SIZE_NOT_FOUND; if (type instanceof IArrayType) { IArrayType at= (IArrayType) type; IValue asize= at.getSize(); @@ -956,12 +913,54 @@ public class CPPTemplates { if (type instanceof ITypeContainer) { final ITypeContainer typeContainer = (ITypeContainer) type; - r= combine(r, determinePackSize(typeContainer.getType(), tpMap)); + r= combinePackSize(r, determinePackSize(typeContainer.getType(), tpMap)); } return r; } - private static int combine(int ps1, int ps2) { + static int determinePackSize(ICPPTemplateParameter tpar, ICPPTemplateParameterMap tpMap) { + if (tpar.isParameterPack()) { + ICPPTemplateArgument[] args= tpMap.getPackExpansion(tpar); + if (args != null) + return args.length; + return PACK_SIZE_DEFER; + } + return PACK_SIZE_NOT_FOUND; + } + + static int determinePackSize(ICPPUnknownBinding binding, ICPPTemplateParameterMap tpMap) { + int r= PACK_SIZE_NOT_FOUND; + if (binding instanceof ICPPDeferredClassInstance) { + ICPPDeferredClassInstance dcl= (ICPPDeferredClassInstance) binding; + ICPPTemplateArgument[] args = dcl.getTemplateArguments(); + for (ICPPTemplateArgument arg : args) { + r= combinePackSize(r, determinePackSize(arg, tpMap)); + if (r < 0) + return r; + } + } + IBinding ownerBinding= binding.getOwner(); + if (ownerBinding instanceof IType) + r= combinePackSize(r, determinePackSize((IType) ownerBinding, tpMap)); + + return r; + } + + static int determinePackSize(IValue value, ICPPTemplateParameterMap tpMap) { + ICPPEvaluation eval = value.getEvaluation(); + if (eval == null) + return PACK_SIZE_NOT_FOUND; + + return ((CPPEvaluation) eval).determinePackSize(tpMap); + } + + static int determinePackSize(ICPPTemplateArgument arg, ICPPTemplateParameterMap tpMap) { + if (arg.isTypeValue()) + return determinePackSize(arg.getTypeValue(), tpMap); + return determinePackSize(arg.getNonTypeValue(), tpMap); + } + + static int combinePackSize(int ps1, int ps2) { if (ps1 < 0 || ps2 == PACK_SIZE_NOT_FOUND) return ps1; if (ps2 < 0 || ps1 == PACK_SIZE_NOT_FOUND) @@ -971,35 +970,6 @@ public class CPPTemplates { return ps1; } - private static int determinePackSize(IValue value, ICPPTemplateParameterMap tpMap) { - int r= PACK_SIZE_NOT_FOUND; - IBinding[] unknown= value.getUnknownBindings(); - for (IBinding binding : unknown) { - if (binding instanceof IType) { - r= combine(r, determinePackSize((IType) binding, tpMap)); - if (r < 0) - return r; - } - } - int[] tpars= Value.getParameterPackReferences(value); - for (int parID : tpars) { - ICPPTemplateArgument[] args= tpMap.getPackExpansion(parID); - if (args != null) { - r= combine(r, args.length); - if (r < 0) - return r; - } - return PACK_SIZE_DEFER; - } - return r; - } - - private static int determinePackSize(ICPPTemplateArgument arg, ICPPTemplateParameterMap tpMap) { - if (arg.isTypeValue()) - return determinePackSize(arg.getTypeValue(), tpMap); - return determinePackSize(arg.getNonTypeValue(), tpMap); - } - /** * Instantiates types contained in an array. * @param types an array of types @@ -1025,7 +995,7 @@ public class CPPTemplates { } else if (packSize == PACK_SIZE_DEFER) { newType= origType; } else { - IType[] newResult= new IType[result.length + packSize - 1]; + IType[] newResult= new IType[result.length+packSize-1]; System.arraycopy(result, 0, newResult, 0, j); result= newResult; for (int k= 0; k < packSize; k++) { @@ -1168,7 +1138,7 @@ public class CPPTemplates { return type; } // The parameter types need to be adjusted. - for (int i= 0; i < params.length; i++) { + for (int i=0; i 0 || usesTemplateParameter((ICPPASTTemplateId) n, tparnames)) { @@ -1439,17 +1409,17 @@ public class CPPTemplates { b= b.getOwner(); } if (depIDCount > 0) { - nestingLevel += depIDCount; + nestingLevel+= depIDCount; } else if (consumesTDecl < tdeclCount && !lastIsTemplate) { nestingLevel++; lastIsTemplate= true; } } else { - nestingLevel += depIDCount; + nestingLevel+= depIDCount; node= outerMostTDecl.getParent(); while (node != null) { if (node instanceof ICPPASTInternalTemplateDeclaration) { - nestingLevel += ((ICPPASTInternalTemplateDeclaration) node).getNestingLevel() + 1; + nestingLevel+= ((ICPPASTInternalTemplateDeclaration) node).getNestingLevel() + 1; break; } node= node.getParent(); @@ -1462,7 +1432,7 @@ public class CPPTemplates { node= outerMostTDecl.getParent(); while (node != null) { if (node instanceof ICPPASTInternalTemplateDeclaration) { - nestingLevel += ((ICPPASTInternalTemplateDeclaration) node).getNestingLevel() + 1; + nestingLevel+= ((ICPPASTInternalTemplateDeclaration) node).getNestingLevel() + 1; break; } node= node.getParent(); @@ -1471,7 +1441,7 @@ public class CPPTemplates { } node= innerMostTDecl; - while (node instanceof ICPPASTInternalTemplateDeclaration) { + while(node instanceof ICPPASTInternalTemplateDeclaration) { if (--nestingLevel < 0) nestingLevel= 0; tdecl= (ICPPASTInternalTemplateDeclaration) node; @@ -1501,7 +1471,7 @@ public class CPPTemplates { private static CharArraySet collectTemplateParameterNames(ICPPASTTemplateDeclaration tdecl) { CharArraySet set= new CharArraySet(4); - while (true) { + while(true) { ICPPASTTemplateParameter[] pars = tdecl.getTemplateParameters(); for (ICPPASTTemplateParameter par : pars) { IASTName name= CPPTemplates.getTemplateParameterName(par); @@ -1521,7 +1491,7 @@ public class CPPTemplates { private static boolean usesTemplateParameter(final ICPPASTTemplateId id, final CharArraySet names) { final boolean[] result= {false}; ASTVisitor v= new ASTVisitor(false) { - { shouldVisitNames= true; shouldVisitAmbiguousNodes= true; } + { shouldVisitNames= true; shouldVisitAmbiguousNodes=true;} @Override public int visit(IASTName name) { if (name instanceof ICPPASTTemplateId) @@ -1613,7 +1583,7 @@ public class CPPTemplates { } private static ICPPASTInternalTemplateDeclaration getDirectlyEnclosingTemplateDeclaration( - ICPPASTInternalTemplateDeclaration tdecl) { + ICPPASTInternalTemplateDeclaration tdecl ) { final IASTNode parent= tdecl.getParent(); if (parent instanceof ICPPASTInternalTemplateDeclaration) return (ICPPASTInternalTemplateDeclaration) parent; @@ -1681,7 +1651,7 @@ public class CPPTemplates { if (args.length != specArgs.length) { return false; } - for (int i= 0; i < args.length; i++) { + for (int i=0; i < args.length; i++) { if (!specArgs[i].isSameValue(args[i])) return false; } @@ -1707,10 +1677,6 @@ public class CPPTemplates { IType type= expr.getExpressionType(); IValue value= Value.create((IASTExpression) arg, Value.MAX_RECURSION_DEPTH); result[i]= new CPPTemplateArgument(value, type); - } else if (arg instanceof ICPPASTAmbiguousTemplateArgument) { - throw new IllegalArgumentException(id.getRawSignature() - + " contains an ambiguous template argument at position " + i + " in " //$NON-NLS-1$ //$NON-NLS-2$ - + id.getContainingFilename()); } else { throw new IllegalArgumentException("Unexpected type: " + arg.getClass().getName()); //$NON-NLS-1$ } @@ -1797,7 +1763,7 @@ public class CPPTemplates { static ICPPFunction[] instantiateConversionTemplates(ICPPFunction[] functions, IType conversionType, IASTNode point) { boolean checkedForDependentType= false; ICPPFunction[] result= functions; - int i= 0; + int i=0; boolean done= false; for (ICPPFunction f : functions) { ICPPFunction inst = f; @@ -1998,7 +1964,7 @@ public class CPPTemplates { } private static IType[] concat(final IType t, IType[] types) { - IType[] result= new IType[types.length + 1]; + IType[] result= new IType[types.length+1]; result[0]= t; System.arraycopy(types, 0, result, 1, types.length); return result; @@ -2221,8 +2187,8 @@ public class CPPTemplates { private static boolean matchTemplateTemplateParameters(ICPPTemplateParameter[] pParams, ICPPTemplateParameter[] aParams) throws DOMException { - int pi= 0; - int ai= 0; + int pi=0; + int ai=0; while (pi < pParams.length && ai < aParams.length) { final ICPPTemplateParameter pp = pParams[pi]; final ICPPTemplateParameter ap = aParams[ai]; @@ -2255,9 +2221,8 @@ public class CPPTemplates { } if (!matchTemplateTemplateParameters(((ICPPTemplateTemplateParameter) pp).getTemplateParameters(), - ((ICPPTemplateTemplateParameter) ap).getTemplateParameters())) { + ((ICPPTemplateTemplateParameter) ap).getTemplateParameters()) ) return false; - } } } if (!pp.isParameterPack()) 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 287193e6200..696a8db4a1d 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 @@ -108,7 +108,32 @@ public class EvalBinary extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + if (fOverload != null) { + // TODO(sprigogin): Simulate execution of a function call. + return Value.create(this); + } + + IValue v1 = fArg1.getValue(point); + IValue v2 = fArg2.getValue(point); + switch (fOperator) { + case IASTBinaryExpression.op_equals: + if (v1.equals(v2)) + return Value.create(1); + break; + case IASTBinaryExpression.op_notequals: + if (v1.equals(v2)) + return Value.create(0); + break; + } + + Long num1 = v1.numericalValue(); + if (num1 != null) { + Long num2 = v2.numericalValue(); + if (num2 != null) { + return Value.evaluateBinaryExpression(fOperator, num1, num2); + } + } + return Value.create(this); } @Override @@ -289,4 +314,9 @@ public class EvalBinary extends CPPEvaluation { return this; return new EvalBinary(fOperator, arg1, arg2); } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + return CPPTemplates.combinePackSize(fArg1.determinePackSize(tpMap), fArg2.determinePackSize(tpMap)); + } } 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 200528f18f3..d89d8ddd6e9 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 @@ -20,12 +20,14 @@ import org.eclipse.cdt.core.dom.ast.ISemanticProblem; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.core.runtime.CoreException; @@ -78,7 +80,16 @@ public class EvalBinaryTypeId extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + if (isValueDependent()) + return Value.create(this); + + switch (fOperator) { + case __is_base_of: + if (!(fType1 instanceof ICPPClassType) || !(fType1 instanceof ICPPClassType)) + return Value.UNKNOWN; + return Value.create(ClassTypeHelper.isSubclass((ICPPClassType) fType2, (ICPPClassType) fType1)); + } + return Value.create(this); } @Override @@ -124,4 +135,10 @@ public class EvalBinaryTypeId extends CPPEvaluation { return this; return new EvalBinaryTypeId(fOperator, type1, type2); } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + return CPPTemplates.combinePackSize(CPPTemplates.determinePackSize(fType1, tpMap), + CPPTemplates.determinePackSize(fType2, tpMap)); + } } 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 f7d9e02e0ea..1427b733c63 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 @@ -26,9 +26,13 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; +import org.eclipse.cdt.internal.core.dom.parser.IInternalVariable; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; @@ -164,7 +168,21 @@ public class EvalBinding extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + if (isValueDependent()) + return Value.create(this); + + IValue value= null; + if (fBinding instanceof IInternalVariable) { + value= ((IInternalVariable) fBinding).getInitialValue(Value.MAX_RECURSION_DEPTH); + } else if (fBinding instanceof IVariable) { + value= ((IVariable) fBinding).getInitialValue(); + } else if (fBinding instanceof IEnumerator) { + value= ((IEnumerator) fBinding).getValue(); + } + if (value == null) + value = Value.UNKNOWN; + + return value; } @Override @@ -223,4 +241,32 @@ public class EvalBinding extends CPPEvaluation { return this; return new EvalBinding(binding, getFixedType()); } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + if (fBinding instanceof IEnumerator) { + return CPPTemplates.determinePackSize(((IEnumerator) fBinding).getValue(), tpMap); + } + if (fBinding instanceof ICPPTemplateNonTypeParameter) { + return CPPTemplates.determinePackSize((ICPPTemplateNonTypeParameter) fBinding, tpMap); + } + if (fBinding instanceof ICPPUnknownBinding) { + return CPPTemplates.determinePackSize((ICPPUnknownBinding) fBinding, tpMap); + } + + IBinding binding = fBinding; + if (fBinding instanceof ICPPSpecialization) { + binding = ((ICPPSpecialization) fBinding).getSpecializedBinding(); + } + + int r = CPPTemplates.PACK_SIZE_NOT_FOUND; + if (binding instanceof ICPPTemplateDefinition) { + ICPPTemplateParameter[] parameters = ((ICPPTemplateDefinition) binding).getTemplateParameters(); + for (ICPPTemplateParameter param : parameters) { + r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize(param, tpMap)); + } + } + + return r; + } } 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 970f22afe81..2cf29f4343b 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 @@ -68,6 +68,7 @@ public class EvalComma extends CPPEvaluation { @Override public boolean isValueDependent() { + // TODO(sprigogin): Should the value depend only on the last argument? for (ICPPEvaluation arg : fArguments) { if (arg.isValueDependent()) return true; @@ -126,12 +127,18 @@ public class EvalComma extends CPPEvaluation { return typeFromFunctionCall(last); } } - return fArguments[fArguments.length-1].getTypeOrFunctionSet(point); + return fArguments[fArguments.length - 1].getTypeOrFunctionSet(point); } @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + ICPPFunction[] overloads = getOverloads(point); + if (overloads.length > 0) { + // TODO(sprigogin): Simulate execution of a function call. + return Value.create(this); + } + + return fArguments[fArguments.length - 1].getValue(point); } @Override @@ -143,7 +150,7 @@ public class EvalComma extends CPPEvaluation { return valueCategoryFromFunctionCall(last); } } - return fArguments[fArguments.length-1].getValueCategory(point); + return fArguments[fArguments.length - 1].getValueCategory(point); } @Override @@ -178,4 +185,13 @@ public class EvalComma extends CPPEvaluation { return this; return new EvalComma(args); } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + int r = CPPTemplates.PACK_SIZE_NOT_FOUND; + for (ICPPEvaluation arg : fArguments) { + r = CPPTemplates.combinePackSize(r, arg.determinePackSize(tpMap)); + } + return r; + } } 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 f926d275632..1175d6b8e72 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 @@ -21,7 +21,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; -import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.core.runtime.CoreException; @@ -66,7 +65,7 @@ public class EvalCompound extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + return fDelegate.getValue(point); } @Override @@ -93,4 +92,9 @@ public class EvalCompound extends CPPEvaluation { return this; return new EvalCompound(delegate); } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + return fDelegate.determinePackSize(tpMap); + } } \ No newline at end of file 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 1ce00dddc1c..772928eac3b 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 @@ -108,7 +108,18 @@ public class EvalConditional extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + IValue condValue = fCondition.getValue(point); + if (condValue == Value.UNKNOWN) + return Value.UNKNOWN; + Long cond = condValue.numericalValue(); + if (cond != null) { + if (cond.longValue() != 0) { + return fPositive == null ? condValue : fPositive.getValue(point); + } else { + return fNegative.getValue(point); + } + } + return Value.create(this); } @Override @@ -324,4 +335,13 @@ public class EvalConditional extends CPPEvaluation { return this; return new EvalConditional(condition, positive, negative, fPositiveThrows, fNegativeThrows); } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + int r = fCondition.determinePackSize(tpMap); + r = CPPTemplates.combinePackSize(r, fNegative.determinePackSize(tpMap)); + if (fPositive != null) + r = CPPTemplates.combinePackSize(r, fPositive.determinePackSize(tpMap)); + return r; + } } 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 a985473ba7a..f3892911125 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 @@ -158,4 +158,9 @@ public class EvalFixed extends CPPEvaluation { return this; return new EvalFixed(type, fValueCategory, value); } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + return CPPTemplates.determinePackSize(fValue, tpMap); + } } \ No newline at end of file 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 b8d8e7808e9..eba7284d57d 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 @@ -135,7 +135,10 @@ public class EvalFunctionCall extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + if (isValueDependent()) + return Value.create(this); + // TODO(sprigogin): Simulate execution of a function call. + return Value.UNKNOWN; } @Override @@ -170,7 +173,7 @@ public class EvalFunctionCall extends CPPEvaluation { for (int i = 0; i < args.length; i++) { args[i]= (ICPPEvaluation) buffer.unmarshalEvaluation(); } - return new EvalComma(args); + return new EvalFunctionCall(args); } @Override @@ -187,4 +190,13 @@ public class EvalFunctionCall extends CPPEvaluation { return this; return new EvalFunctionCall(args); } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + int r = CPPTemplates.PACK_SIZE_NOT_FOUND; + for (ICPPEvaluation arg : fArguments) { + r = CPPTemplates.combinePackSize(r, arg.determinePackSize(tpMap)); + } + return r; + } } 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 70f8e72d589..fbf64b923a8 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 @@ -171,4 +171,14 @@ public class EvalFunctionSet extends CPPEvaluation { return this; return new EvalFunctionSet(new CPPFunctionSet(functions, arguments, null), fAddressOf); } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + int r = CPPTemplates.PACK_SIZE_NOT_FOUND; + ICPPTemplateArgument[] templateArguments = fFunctionSet.getTemplateArguments(); + for (ICPPTemplateArgument arg : templateArguments) { + r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize(arg, tpMap)); + } + return r; + } } 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 eeae6cc797c..7f4d466af0a 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 @@ -70,6 +70,9 @@ public class EvalID extends CPPEvaluation { fTemplateArgs= templateArgs; } + /** + * Returns the field owner expression, or {@code null}. + */ public ICPPEvaluation getFieldOwner() { return fFieldOwner; } @@ -90,6 +93,9 @@ public class EvalID extends CPPEvaluation { return fQualified; } + /** + * Returns the template arguments, or {@code null} if there are no template arguments. + */ public ICPPTemplateArgument[] getTemplateArgs() { return fTemplateArgs; } @@ -121,7 +127,7 @@ public class EvalID extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + return Value.create(this); } @Override @@ -256,14 +262,19 @@ public class EvalID extends CPPEvaluation { @Override public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, int maxdepth, IASTNode point) { - ICPPTemplateArgument[] arguments = fTemplateArgs; - try { - arguments = CPPTemplates.instantiateArguments(fTemplateArgs, tpMap, packOffset, within, point); - } catch (DOMException e) { - CCorePlugin.log(e); + ICPPTemplateArgument[] templateArgs = fTemplateArgs; + if (templateArgs != null) { + try { + templateArgs = CPPTemplates.instantiateArguments(templateArgs, tpMap, packOffset, within, point); + } catch (DOMException e) { + CCorePlugin.log(e); + } } - ICPPEvaluation fieldOwner = fFieldOwner.instantiate(tpMap, packOffset, within, maxdepth, point); + ICPPEvaluation fieldOwner = fFieldOwner; + if (fieldOwner != null) { + fieldOwner = fieldOwner.instantiate(tpMap, packOffset, within, maxdepth, point); + } IBinding nameOwner = fNameOwner; if (fNameOwner instanceof ICPPTemplateParameter) { ICPPTemplateArgument argument = tpMap.getArgument((ICPPTemplateParameter) fNameOwner); @@ -280,16 +291,16 @@ public class EvalID extends CPPEvaluation { CCorePlugin.log(e); } } - if (Arrays.equals(arguments, fTemplateArgs) && fieldOwner == fFieldOwner && nameOwner == fNameOwner) + if (Arrays.equals(templateArgs, fTemplateArgs) && fieldOwner == fFieldOwner && nameOwner == fNameOwner) return this; - if (nameOwner == null) - nameOwner = (IBinding) fFieldOwner.getTypeOrFunctionSet(point); + if (nameOwner == null && fieldOwner != null) + nameOwner = (IBinding) fieldOwner.getTypeOrFunctionSet(point); - if (nameOwner instanceof ICompositeType) { + if (nameOwner instanceof ICompositeType && point != null) { ICompositeType ownerType = (ICompositeType) nameOwner; // TODO(sprigogin): Is this the right way to do lookup, or should findBindings be used instead? - LookupData data = new LookupData(fName, fTemplateArgs, point); + LookupData data = new LookupData(fName, templateArgs, point); try { CPPSemantics.lookup(data, ownerType.getScope()); } catch (DOMException e) { @@ -305,6 +316,15 @@ public class EvalID extends CPPEvaluation { } } - return new EvalID(fieldOwner, nameOwner, fName, fAddressOf, fQualified, arguments); + return new EvalID(fieldOwner, nameOwner, fName, fAddressOf, fQualified, templateArgs); + } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + int r = fFieldOwner.determinePackSize(tpMap); + for (ICPPTemplateArgument arg : fTemplateArgs) { + r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize(arg, tpMap)); + } + return r; } } 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 96e97581088..02469d272ef 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 @@ -74,7 +74,9 @@ public class EvalInitList extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + if (isValueDependent()) + return Value.create(this); + return Value.UNKNOWN; // TODO(sprigogin): Is this correct? } @Override @@ -97,7 +99,7 @@ public class EvalInitList extends CPPEvaluation { for (int i = 0; i < args.length; i++) { args[i]= (ICPPEvaluation) buffer.unmarshalEvaluation(); } - return new EvalComma(args); + return new EvalInitList(args); } @Override @@ -114,4 +116,13 @@ public class EvalInitList extends CPPEvaluation { return this; return new EvalInitList(clauses); } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + int r = CPPTemplates.PACK_SIZE_NOT_FOUND; + for (ICPPEvaluation arg : fClauses) { + r = CPPTemplates.combinePackSize(r, arg.determinePackSize(tpMap)); + } + return r; + } } \ No newline at end of file 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 fc60209bfed..ff097057121 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 @@ -254,7 +254,16 @@ public class EvalMemberAccess extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + if (fMember instanceof IEnumerator) { + return ((IEnumerator) fMember).getValue(); + } + if (fMember instanceof IVariable) { + return ((IVariable) fMember).getInitialValue(); + } + if (fMember instanceof IFunction) { + return Value.UNKNOWN; + } + return Value.create(this); } @Override @@ -324,4 +333,9 @@ public class EvalMemberAccess extends CPPEvaluation { } return new EvalMemberAccess(ownerType, fOwnerValueCategory, member, fIsPointerDeref); } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + return CPPTemplates.determinePackSize(fOwnerType, tpMap); + } } 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 e78725f1552..50719af6fd0 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 @@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; @@ -73,7 +74,20 @@ public class EvalTypeId extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + if (isValueDependent()) + return Value.create(this); + if (fArguments == null) + return Value.UNKNOWN; + + if (isTypeDependent()) + return Value.create(this); + if (fOutputType instanceof ICPPClassType) { + // TODO(sprigogin): Simulate execution of a ctor call. + return Value.UNKNOWN; + } + if (fArguments.length == 1) + return fArguments[0].getValue(point); + return Value.UNKNOWN; } @Override @@ -144,4 +158,13 @@ public class EvalTypeId extends CPPEvaluation { return this; return new EvalTypeId(type, args); } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + int r = CPPTemplates.determinePackSize(fInputType, tpMap); + for (ICPPEvaluation arg : fArguments) { + r = CPPTemplates.combinePackSize(r, arg.determinePackSize(tpMap)); + } + return r; + } } 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 ac40c69ebb4..1f44ac738e5 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 @@ -205,7 +205,17 @@ public class EvalUnary extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + if (fOverload != null) { + // TODO(sprigogin): Simulate execution of a function call. + return Value.create(this); + } + + IValue val = fArgument.getValue(point); + Long num = val.numericalValue(); + if (num != null) { + return Value.evaluateUnaryExpression(fOperator, num); + } + return Value.create(this); } @Override @@ -246,4 +256,9 @@ public class EvalUnary extends CPPEvaluation { return this; return new EvalUnary(fOperator, argument); } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + return fArgument.determinePackSize(tpMap); + } } 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 03170775389..6fe24993a15 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 @@ -34,6 +34,8 @@ import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_typeof; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.ICompositeType; +import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; @@ -41,6 +43,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; +import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator; +import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; @@ -148,7 +152,56 @@ public class EvalUnaryTypeID extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + if (isValueDependent()) + return Value.create(this); + + switch (fOperator) { + case op_sizeof: { + if (point == null) + return Value.UNKNOWN; + SizeAndAlignment info = new SizeofCalculator(point.getTranslationUnit()).sizeAndAlignment(fOrigType); + return info == null ? Value.UNKNOWN : Value.create(info.size); + } + case op_alignof: { + if (point == null) + return Value.UNKNOWN; + SizeAndAlignment info = new SizeofCalculator(point.getTranslationUnit()).sizeAndAlignment(fOrigType); + return info == null ? Value.UNKNOWN : Value.create(info.alignment); + } + case op_typeid: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_has_nothrow_copy: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_has_nothrow_constructor: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_has_trivial_assign: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_has_trivial_constructor: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_has_trivial_copy: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_has_trivial_destructor: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_has_virtual_destructor: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_is_abstract: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_is_class: + return Value.create(fOrigType instanceof ICompositeType && ((ICompositeType) fOrigType).getKey() != ICompositeType.k_union); + case op_is_empty: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_is_enum: + return Value.create(fOrigType instanceof IEnumeration); + case op_is_pod: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_is_polymorphic: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_is_union: + return Value.create(fOrigType instanceof ICompositeType && ((ICompositeType) fOrigType).getKey() == ICompositeType.k_union); + case op_typeof: + return Value.UNKNOWN; // TODO(sprigogin): Implement + } + return Value.create(this); } @Override @@ -177,4 +230,9 @@ public class EvalUnaryTypeID extends CPPEvaluation { return this; return new EvalUnaryTypeID(fOperator, type); } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + return CPPTemplates.determinePackSize(fOrigType, tpMap); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java index 482571a9c84..45f376da9bc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java @@ -425,16 +425,13 @@ public class CPPCompositesFactory extends AbstractCompositeFactory { public IValue getCompositeValue(IValue v) { if (v == null) return null; - - IBinding[] b= v.getUnknownBindings(); - if (b.length == 0) + + ICPPEvaluation eval = v.getEvaluation(); + if (eval == null) return v; - - ICPPUnknownBinding[] b2= new ICPPUnknownBinding[b.length]; - for (int i = 0; i < b2.length; i++) { - b2[i]= (ICPPUnknownBinding) getCompositeBinding((IIndexFragmentBinding) b[i]); - } - return Value.fromInternalRepresentation(v.getInternalExpression(), b2); + + eval = getCompositeEvaluation(eval); + return Value.fromInternalRepresentation(eval); } private ICPPNamespace[] getNamespaces(IBinding rbinding) throws CoreException { From 88eadc8573bb6386991583e03567ad932de7c49f Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 25 Jul 2012 20:50:04 -0700 Subject: [PATCH 06/31] Bug 299911. Work in progress. 5 tests are still failing. --- .../cdt/core/parser/util/IntArray.java | 151 ++++++++++++++++++ .../cdt/internal/core/dom/parser/Value.java | 19 +-- .../dom/parser/cpp/CPPASTFieldReference.java | 10 +- .../core/dom/parser/cpp/ICPPEvaluation.java | 6 + .../dom/parser/cpp/semantics/EvalBinary.java | 7 +- .../cpp/semantics/EvalBinaryTypeId.java | 5 + .../dom/parser/cpp/semantics/EvalBinding.java | 5 + .../dom/parser/cpp/semantics/EvalComma.java | 10 +- .../parser/cpp/semantics/EvalCompound.java | 8 +- .../parser/cpp/semantics/EvalConditional.java | 7 + .../dom/parser/cpp/semantics/EvalFixed.java | 5 + .../cpp/semantics/EvalFunctionCall.java | 9 ++ .../parser/cpp/semantics/EvalFunctionSet.java | 5 + .../core/dom/parser/cpp/semantics/EvalID.java | 9 +- .../parser/cpp/semantics/EvalInitList.java | 9 ++ .../cpp/semantics/EvalMemberAccess.java | 5 + .../dom/parser/cpp/semantics/EvalTypeId.java | 9 ++ .../dom/parser/cpp/semantics/EvalUnary.java | 7 +- .../parser/cpp/semantics/EvalUnaryTypeID.java | 5 + 19 files changed, 266 insertions(+), 25 deletions(-) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/IntArray.java diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/IntArray.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/IntArray.java new file mode 100644 index 00000000000..ba5a8b312c2 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/IntArray.java @@ -0,0 +1,151 @@ +/******************************************************************************* + * Copyright (c) 2012 Google, Inc and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.parser.util; + +import java.util.Arrays; + +/** + * Automatically growing integer array. + * + * @since 5.5 + */ +public class IntArray { + private static final int INITIAL_CAPACITY = 10; + private static final int[] EMPTY_ARRAY = {}; + + private int[] buffer = EMPTY_ARRAY; + private int size; + + public IntArray() { + } + + public IntArray(int initialCapacity) { + this.buffer = new int[initialCapacity]; + } + + public int size() { + return size; + } + + public boolean isEmpty() { + return size == 0; + } + + public void add(int value) { + grow(size + 1); + buffer[size++] = value; + } + + public void add(int index, int value) { + checkBounds(index); + grow(size + 1); + System.arraycopy(buffer, index, buffer, index + 1, size - index); + buffer[index] = value; + size++; + } + + public void addAll(IntArray other) { + grow(size + other.size()); + System.arraycopy(other.buffer, 0, buffer, size, other.size); + size += other.size; + return; + } + + public void addAll(int[] array) { + grow(size + array.length); + System.arraycopy(array, 0, buffer, size, array.length); + size += array.length; + return; + } + + public int remove(int index) { + checkBounds(index); + int old = buffer[index]; + int n = size - index - 1; + if (n > 0) { + System.arraycopy(buffer, index + 1, buffer, index, n); + } + return old; + } + + public void remove(int from, int to) { + checkBounds(from); + checkBounds(to); + System.arraycopy(buffer, to, buffer, from, size - to); + } + + public void clear() { + size = 0; + } + + public int get(int index) { + checkRange(index); + return buffer[index]; + } + + public int set(int index, int value) { + checkBounds(index); + int old = buffer[index]; + buffer[index] = value; + return old; + } + + public int[] toArray() { + return size == 0 ? EMPTY_ARRAY : Arrays.copyOf(buffer, size); + } + + public void trimToSize() { + if (size == 0) { + buffer = EMPTY_ARRAY; + } else if (size < buffer.length) { + buffer = Arrays.copyOf(buffer, size); + } + } + + public void ensureCapacity(int minCapacity) { + if (minCapacity > 0) { + grow(minCapacity); + } + } + + private void grow(int minCapacity) { + if (minCapacity < 0) // Overflow + throw new OutOfMemoryError(); + + int capacity = buffer.length; + if (minCapacity > capacity) { + int newCapacity = capacity == 0 ? INITIAL_CAPACITY : capacity + (capacity >> 1); + // newCapacity may be negative due to overflow. + if (newCapacity < minCapacity) + newCapacity = minCapacity; + // newCapacity is guaranteed to be non negative. + try { + buffer = Arrays.copyOf(buffer, newCapacity); + } catch (OutOfMemoryError e) { + // Try again it case we were too aggressive in reserving capacity. + buffer = Arrays.copyOf(buffer, minCapacity); + } + } + } + + private void checkBounds(int index) { + if (index < 0) { + throw new IndexOutOfBoundsException("Negative index: " + index); //$NON-NLS-1$ + } + checkRange(index); + } + + private void checkRange(int index) { + if (index >= size) { + throw new IndexOutOfBoundsException("Index: " + index + ", size: " + size); //$NON-NLS-1$//$NON-NLS-2$ + } + } +} 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 701b9e71d74..8f1b1295048 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 @@ -215,7 +215,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 a parameter pack). * * @return the parameter id of the parameter, or -1 if it is not a template * parameter. @@ -225,25 +225,20 @@ public class Value implements IValue { if (eval instanceof EvalBinding) { IBinding binding = ((EvalBinding) eval).getBinding(); if (binding instanceof ICPPTemplateParameter) { - ((ICPPTemplateParameter) binding).getParameterID(); + return ((ICPPTemplateParameter) binding).getParameterID(); } } return -1; } /** - * Tests whether the value directly references some template parameter. + * Tests whether the value references some template parameter. */ - // TODO(sprigogin): The semantics of "directly" is unclear. public static boolean referencesTemplateParameter(IValue tval) { - // TODO(sprigogin): Implementation of this method is probably incomplete since it interprets "directly" in a very direct way. The old code is kept below for reference. - return isTemplateParameter(tval) >= 0; -// final char[] rep= tval.getInternalExpression(); -// for (char element : rep) { -// if (element == TEMPLATE_PARAM_CHAR || element == TEMPLATE_PARAM_PACK_CHAR) -// return true; -// } -// return false; + ICPPEvaluation eval = tval.getEvaluation(); + if (eval == null) + return false; + return eval.referencesTemplateParameter(); } /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java index 8a2dff09a33..c2fb4dcb4b2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java @@ -53,7 +53,7 @@ public class CPPASTFieldReference extends ASTNode private boolean isDeref; private IASTImplicitName[] implicitNames; private ICPPEvaluation fEvaluation; - + public CPPASTFieldReference() { } @@ -74,11 +74,7 @@ public class CPPASTFieldReference extends ASTNode copy.setFieldOwner(owner == null ? null : owner.copy(style)); copy.isTemplate = isTemplate; copy.isDeref = isDeref; - copy.setOffsetAndLength(this); - if (style == CopyStyle.withLocations) { - copy.setCopyLocation(this); - } - return copy; + return copy(copy, style); } @Override @@ -282,7 +278,7 @@ public class CPPASTFieldReference extends ASTNode if (n instanceof ICPPASTTemplateId) { args= CPPTemplates.createTemplateArgumentArray((ICPPASTTemplateId) n); } - return new EvalID(ownerEval, qualifier, name.getSimpleID(), false, qualifier != null, args); + return new EvalID(ownerEval, qualifier, name.getSimpleID(), false, true, args); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java index 48d743d2697..aed832e59a4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java @@ -76,4 +76,10 @@ public interface ICPPEvaluation extends ISerializableEvaluation { * @noreference This method is not intended to be referenced by clients. */ int determinePackSize(ICPPTemplateParameterMap tpMap); + + /** + * Checks if the evaluation references a template parameter either directly or though nested + * evaluations. + */ + boolean referencesTemplateParameter(); } 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 696a8db4a1d..911c8cc1062 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 @@ -108,7 +108,7 @@ public class EvalBinary extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - if (fOverload != null) { + if (getOverload(point) != null) { // TODO(sprigogin): Simulate execution of a function call. return Value.create(this); } @@ -319,4 +319,9 @@ public class EvalBinary extends CPPEvaluation { public int determinePackSize(ICPPTemplateParameterMap tpMap) { return CPPTemplates.combinePackSize(fArg1.determinePackSize(tpMap), fArg2.determinePackSize(tpMap)); } + + @Override + public boolean referencesTemplateParameter() { + return fArg1.referencesTemplateParameter() || fArg2.referencesTemplateParameter(); + } } 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 d89d8ddd6e9..707e19f45e3 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 @@ -141,4 +141,9 @@ public class EvalBinaryTypeId extends CPPEvaluation { return CPPTemplates.combinePackSize(CPPTemplates.determinePackSize(fType1, tpMap), CPPTemplates.determinePackSize(fType2, tpMap)); } + + @Override + public boolean referencesTemplateParameter() { + return false; + } } 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 1427b733c63..ee5b09c13c0 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 @@ -269,4 +269,9 @@ public class EvalBinding extends CPPEvaluation { return r; } + + @Override + public boolean referencesTemplateParameter() { + return fBinding instanceof ICPPTemplateParameter; + } } 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 2cf29f4343b..752cb08797c 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 @@ -68,7 +68,6 @@ public class EvalComma extends CPPEvaluation { @Override public boolean isValueDependent() { - // TODO(sprigogin): Should the value depend only on the last argument? for (ICPPEvaluation arg : fArguments) { if (arg.isValueDependent()) return true; @@ -194,4 +193,13 @@ public class EvalComma extends CPPEvaluation { } return r; } + + @Override + public boolean referencesTemplateParameter() { + for (ICPPEvaluation arg : fArguments) { + if (arg.referencesTemplateParameter()) + return true; + } + return false; + } } 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 1175d6b8e72..dcc6c627d06 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 @@ -25,7 +25,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.core.runtime.CoreException; /** - * Performs evaluation of an expression. + * Performs evaluation of a compound statement expression. Most but not all methods + * delegate to the evaluation of the last expression in the compound one. */ public class EvalCompound extends CPPEvaluation { private final ICPPEvaluation fDelegate; @@ -97,4 +98,9 @@ public class EvalCompound extends CPPEvaluation { public int determinePackSize(ICPPTemplateParameterMap tpMap) { return fDelegate.determinePackSize(tpMap); } + + @Override + public boolean referencesTemplateParameter() { + return fDelegate.referencesTemplateParameter(); + } } \ No newline at end of file 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 772928eac3b..d918929a3c2 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 @@ -344,4 +344,11 @@ public class EvalConditional extends CPPEvaluation { r = CPPTemplates.combinePackSize(r, fPositive.determinePackSize(tpMap)); return r; } + + @Override + public boolean referencesTemplateParameter() { + return fCondition.referencesTemplateParameter() || + (fPositive != null && fPositive.referencesTemplateParameter()) || + fNegative.referencesTemplateParameter(); + } } 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 f3892911125..9ae762f8c2d 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 @@ -163,4 +163,9 @@ public class EvalFixed extends CPPEvaluation { public int determinePackSize(ICPPTemplateParameterMap tpMap) { return CPPTemplates.determinePackSize(fValue, tpMap); } + + @Override + public boolean referencesTemplateParameter() { + return false; + } } \ No newline at end of file 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 eba7284d57d..f574db24ece 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 @@ -199,4 +199,13 @@ public class EvalFunctionCall extends CPPEvaluation { } return r; } + + @Override + public boolean referencesTemplateParameter() { + for (ICPPEvaluation arg : fArguments) { + if (arg.referencesTemplateParameter()) + return true; + } + return false; + } } 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 fbf64b923a8..d645aa6032b 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 @@ -181,4 +181,9 @@ public class EvalFunctionSet extends CPPEvaluation { } return r; } + + @Override + public boolean referencesTemplateParameter() { + return false; + } } 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 7f4d466af0a..ec83268aa3a 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 @@ -299,10 +299,10 @@ public class EvalID extends CPPEvaluation { if (nameOwner instanceof ICompositeType && point != null) { ICompositeType ownerType = (ICompositeType) nameOwner; - // TODO(sprigogin): Is this the right way to do lookup, or should findBindings be used instead? LookupData data = new LookupData(fName, templateArgs, point); + data.qualified = fQualified; try { - CPPSemantics.lookup(data, ownerType.getScope()); + CPPSemantics.lookup(data, ownerType.getCompositeScope()); } catch (DOMException e) { } IBinding[] bindings = data.getFoundBindings(); @@ -327,4 +327,9 @@ public class EvalID extends CPPEvaluation { } return r; } + + @Override + public boolean referencesTemplateParameter() { + return fFieldOwner.referencesTemplateParameter(); + } } 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 02469d272ef..e1d4b237e29 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 @@ -125,4 +125,13 @@ public class EvalInitList extends CPPEvaluation { } return r; } + + @Override + public boolean referencesTemplateParameter() { + for (ICPPEvaluation clause : fClauses) { + if (clause.referencesTemplateParameter()) + return true; + } + return false; + } } \ No newline at end of file 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 ff097057121..7e164f70ecd 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 @@ -338,4 +338,9 @@ public class EvalMemberAccess extends CPPEvaluation { public int determinePackSize(ICPPTemplateParameterMap tpMap) { return CPPTemplates.determinePackSize(fOwnerType, tpMap); } + + @Override + public boolean referencesTemplateParameter() { + return false; + } } 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 50719af6fd0..6e8ef088d12 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 @@ -167,4 +167,13 @@ public class EvalTypeId extends CPPEvaluation { } return r; } + + @Override + public boolean referencesTemplateParameter() { + for (ICPPEvaluation arg : fArguments) { + if (arg.referencesTemplateParameter()) + return true; + } + return false; + } } 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 1f44ac738e5..ab728bf6462 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 @@ -205,7 +205,7 @@ public class EvalUnary extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - if (fOverload != null) { + if (getOverload(point) != null) { // TODO(sprigogin): Simulate execution of a function call. return Value.create(this); } @@ -261,4 +261,9 @@ public class EvalUnary extends CPPEvaluation { public int determinePackSize(ICPPTemplateParameterMap tpMap) { return fArgument.determinePackSize(tpMap); } + + @Override + public boolean referencesTemplateParameter() { + return fArgument.referencesTemplateParameter(); + } } 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 6fe24993a15..993b032ded9 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 @@ -235,4 +235,9 @@ public class EvalUnaryTypeID extends CPPEvaluation { public int determinePackSize(ICPPTemplateParameterMap tpMap) { return CPPTemplates.determinePackSize(fOrigType, tpMap); } + + @Override + public boolean referencesTemplateParameter() { + return false; + } } From 8520d6cfdfc9675640cf27b870ebb6b419f2c173 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Thu, 26 Jul 2012 17:06:30 -0700 Subject: [PATCH 07/31] Bug 299911. Fixed remaining failing tests. --- .../parser/tests/ast2/AST2CPPSpecTest.java | 2 +- .../parser/tests/ast2/AST2TemplateTests.java | 2 +- .../core/dom/parser/cpp/CPPScope.java | 2 +- .../parser/cpp/semantics/CPPEvaluation.java | 62 +++++-------------- .../core/dom/parser/cpp/semantics/EvalID.java | 54 +++++++++------- 5 files changed, 52 insertions(+), 70 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java index c64e96b3069..ebce79f3774 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java @@ -5747,7 +5747,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest { // g(0); // The N member of C is not a non-type // h(0); // The TT member of D is not a template // } - public void _test14_8_2s8d() throws Exception { + public void test14_8_2s8d() throws Exception { final String content= getAboveComment(); BindingAssertionHelper bh= new BindingAssertionHelper(content, true); bh.assertProblem("f", 0); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 6a650ca9ad2..7eca6882562 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -4404,7 +4404,7 @@ public class AST2TemplateTests extends AST2BaseTest { assertEquals("void (#0 (* ...)())", ASTTypeUtil.getType(f.getType(), true)); assertTrue(f.getParameters()[0].isParameterPack()); f= bh.assertNonProblem("f4", 2); - assertEquals("void (int (& ...)[`0])", ASTTypeUtil.getType(f.getType(), true)); + assertEquals("void (int (& ...)[3 *0 0])", ASTTypeUtil.getType(f.getType(), true)); assertTrue(f.getParameters()[0].isParameterPack()); f= bh.assertNonProblem("f5", 2); assertEquals("void (#0 ...)", ASTTypeUtil.getType(f.getType(), true)); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java index a3246049bbb..8cb4e502d3b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java @@ -184,7 +184,7 @@ abstract public class CPPScope implements ICPPASTInternalScope { @Override public IBinding[] getBindings(ScopeLookupData lookup) { IBinding[] result = getBindingsInAST(lookup); - final IASTTranslationUnit tu = lookup.getLookupPoint().getTranslationUnit(); + final IASTTranslationUnit tu = lookup.getTranslationUnit(); if (tu != null) { IIndex index = tu.getIndex(); if (index != null) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java index 9bd224ccac0..0e91a249095 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java @@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; @@ -29,11 +30,8 @@ public abstract class CPPEvaluation implements ICPPEvaluation { private static class SignatureBuilder implements ITypeMarshalBuffer { private static final byte NULL_TYPE= 0; private static final byte UNSTORABLE_TYPE= (byte) -1; - private static final char[] HEX_DIGITS = - { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; private final StringBuilder fBuffer; - private boolean hexMode; /** * Constructor for input buffer. @@ -60,7 +58,13 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } else { appendSeparator(); if (binding instanceof ICPPBinding) { - fBuffer.append(ASTTypeUtil.getQualifiedName((ICPPBinding) binding)); + if (binding instanceof ICPPTemplateParameter) { + ICPPTemplateParameter param = (ICPPTemplateParameter) binding; + fBuffer.append(param.isParameterPack() ? '*' : '#'); + fBuffer.append(param.getParameterID()); + } else { + fBuffer.append(ASTTypeUtil.getQualifiedName((ICPPBinding) binding)); + } } else { fBuffer.append(binding.getNameCharArray()); } @@ -100,49 +104,27 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } @Override - public void putByte(byte b) { - appendHexDigit(b >> 4); - appendHexDigit(b); + public void putByte(byte value) { + appendSeparator(); + fBuffer.append(value); } @Override public void putShort(short value) { - appendHexDigit(value >> 12); - appendHexDigit(value >> 8); - appendHexDigit(value >> 4); - appendHexDigit(value); + appendSeparator(); + fBuffer.append(value); } @Override public void putInt(int value) { - appendHexDigit(value >> 28); - appendHexDigit(value >> 24); - appendHexDigit(value >> 20); - appendHexDigit(value >> 16); - appendHexDigit(value >> 12); - appendHexDigit(value >> 8); - appendHexDigit(value >> 4); - appendHexDigit(value); + appendSeparator(); + fBuffer.append(value); } @Override public void putLong(long value) { - appendHexDigit((int) (value >> 60)); - appendHexDigit((int) (value >> 56)); - appendHexDigit((int) (value >> 52)); - appendHexDigit((int) (value >> 48)); - appendHexDigit((int) (value >> 44)); - appendHexDigit((int) (value >> 40)); - appendHexDigit((int) (value >> 36)); - appendHexDigit((int) (value >> 32)); - appendHexDigit((int) (value >> 28)); - appendHexDigit((int) (value >> 24)); - appendHexDigit((int) (value >> 20)); - appendHexDigit((int) (value >> 16)); - appendHexDigit((int) (value >> 12)); - appendHexDigit((int) (value >> 8)); - appendHexDigit((int) (value >> 4)); - appendHexDigit((int) value); + appendSeparator(); + fBuffer.append(value); } @Override @@ -153,19 +135,9 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } } - private void appendHexDigit(int val) { - if (hexMode) { - appendSeparator(); - fBuffer.append("0x"); //$NON-NLS-1$ - hexMode = true; - } - fBuffer.append(HEX_DIGITS[val & 0xF]); - } - private void appendSeparator() { if (fBuffer.length() != 0) fBuffer.append(' '); - hexMode = false; } @Override 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 ec83268aa3a..f19bea25407 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 @@ -25,7 +25,6 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IProblemBinding; @@ -37,6 +36,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; @@ -127,6 +127,15 @@ public class EvalID extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { + IBinding nameOwner = fNameOwner; + if (nameOwner == null && fFieldOwner != null) + nameOwner = (IBinding) fFieldOwner.getTypeOrFunctionSet(point); + + if (nameOwner instanceof ICPPClassType) { + ICPPEvaluation eval = resolveName((ICPPClassType) nameOwner, fTemplateArgs, point); + if (eval != null) + return eval.getValue(point); + } return Value.create(this); } @@ -294,31 +303,32 @@ public class EvalID extends CPPEvaluation { if (Arrays.equals(templateArgs, fTemplateArgs) && fieldOwner == fFieldOwner && nameOwner == fNameOwner) return this; - if (nameOwner == null && fieldOwner != null) - nameOwner = (IBinding) fieldOwner.getTypeOrFunctionSet(point); - - if (nameOwner instanceof ICompositeType && point != null) { - ICompositeType ownerType = (ICompositeType) nameOwner; - LookupData data = new LookupData(fName, templateArgs, point); - data.qualified = fQualified; - try { - CPPSemantics.lookup(data, ownerType.getCompositeScope()); - } catch (DOMException e) { - } - IBinding[] bindings = data.getFoundBindings(); - IBinding binding = bindings.length == 1 ? bindings[0] : null; - if (binding instanceof IEnumerator) { - return new EvalBinding(binding, null); - } else if (binding instanceof ICPPMember) { - return new EvalMemberAccess(ownerType, ValueCategory.PRVALUE, binding, false); - } else if (binding instanceof CPPFunctionSet) { - return new EvalFunctionSet((CPPFunctionSet) binding, fAddressOf); - } - } + // We don't do name lookup here since it is going to happen anyway when the getValue method + // is called. return new EvalID(fieldOwner, nameOwner, fName, fAddressOf, fQualified, templateArgs); } + private ICPPEvaluation resolveName(ICPPClassType nameOwner, ICPPTemplateArgument[] templateArgs, + IASTNode point) { + LookupData data = new LookupData(fName, templateArgs, point); + data.qualified = fQualified; + try { + CPPSemantics.lookup(data, nameOwner.getCompositeScope()); + } catch (DOMException e) { + } + IBinding[] bindings = data.getFoundBindings(); + IBinding binding = bindings.length == 1 ? bindings[0] : null; + if (binding instanceof IEnumerator) { + return new EvalBinding(binding, null); + } else if (binding instanceof ICPPMember) { + return new EvalMemberAccess(nameOwner, ValueCategory.PRVALUE, binding, false); + } else if (binding instanceof CPPFunctionSet) { + return new EvalFunctionSet((CPPFunctionSet) binding, fAddressOf); + } + return null; + } + @Override public int determinePackSize(ICPPTemplateParameterMap tpMap) { int r = fFieldOwner.determinePackSize(tpMap); From 927f0e708284122118d1f7d39ab4a80f32f8012a Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sat, 28 Jul 2012 16:44:25 -0700 Subject: [PATCH 08/31] Cosmetics. --- .../dom/ast/cpp/ICPPASTInitializerList.java | 3 +- .../core/dom/parser/c/CArrayType.java | 6 +-- .../cpp/CPPTemplateNonTypeParameter.java | 15 ++++-- .../composite/cpp/TemplateInstanceUtil.java | 36 +++++++-------- .../pdom/dom/cpp/PDOMCPPArgumentList.java | 33 +++++++------ .../cpp/PDOMCPPTemplateNonTypeParameter.java | 27 ++++++----- .../dom/cpp/PDOMCPPTemplateParameterMap.java | 46 +++++++++---------- 7 files changed, 84 insertions(+), 82 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTInitializerList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTInitializerList.java index 21edb4e56be..a91a814f66d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTInitializerList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTInitializerList.java @@ -6,7 +6,7 @@ * 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.core.dom.ast.cpp; @@ -20,7 +20,6 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializerList; * @noimplement This interface is not intended to be implemented by clients. */ public interface ICPPASTInitializerList extends IASTInitializerList, ICPPASTInitializerClause, ICPPASTPackExpandable { - @Override ICPPASTInitializerList copy(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java index a90f9f3395a..d9869e70ddc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Devin Steffler (IBM Corporation) - initial API and implementation + * Devin Steffler (IBM Corporation) - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -157,7 +157,6 @@ public class CArrayType implements ICArrayType, ITypeContainer, ISerializableTyp return ASTTypeUtil.getType(this); } - @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { int firstByte= ITypeMarshalBuffer.ARRAY_TYPE; @@ -174,14 +173,13 @@ public class CArrayType implements ICArrayType, ITypeContainer, ISerializableTyp firstByte |= ITypeMarshalBuffer.FLAG1; } - val= getSize(); if (val != null) { firstByte |= ITypeMarshalBuffer.FLAG2; Long num= val.numericalValue(); if (num != null) { long l= num; - if (l>=0 && l <= Short.MAX_VALUE) { + if (l >= 0 && l <= Short.MAX_VALUE) { nval= (short) l; firstByte |= ITypeMarshalBuffer.FLAG3; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java index 29f4703398b..d6396a23de8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java @@ -32,10 +32,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; /** * Binding for a non-type template parameter. */ -public class CPPTemplateNonTypeParameter extends CPPTemplateParameter implements - ICPPTemplateNonTypeParameter { - - private IType type = null; +public class CPPTemplateNonTypeParameter extends CPPTemplateParameter + implements ICPPTemplateNonTypeParameter { + private IType type; public CPPTemplateNonTypeParameter(IASTName name) { super(name); @@ -80,7 +79,7 @@ public class CPPTemplateNonTypeParameter extends CPPTemplateParameter implements d= (IASTExpression) dc; } else if (dc instanceof ICPPASTInitializerList) { ICPPASTInitializerList list= (ICPPASTInitializerList) dc; - switch(list.getSize()) { + switch (list.getSize()) { case 0: return new CPPTemplateArgument(Value.create(0), getType()); case 1: @@ -123,26 +122,32 @@ public class CPPTemplateNonTypeParameter extends CPPTemplateParameter implements public boolean isStatic() { return false; } + @Override public boolean isExtern() { return false; } + @Override public boolean isAuto() { return false; } + @Override public boolean isRegister() { return false; } + @Override public IValue getInitialValue() { return null; } + @Override public boolean isExternC() { return false; } + @Override public boolean isMutable() { return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/TemplateInstanceUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/TemplateInstanceUtil.java index a95fb3f576e..316af361b69 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/TemplateInstanceUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/TemplateInstanceUtil.java @@ -6,9 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Ferguson (Symbian) - Initial implementation - * Bryan Wilkinson (QNX) - * Markus Schorn (Wind River Systems) + * Andrew Ferguson (Symbian) - Initial implementation + * Bryan Wilkinson (QNX) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; @@ -26,15 +26,16 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; /** - * For implementation re-use in the absence of multiple inheritance + * For implementation re-use in the absence of multiple inheritance. */ public class TemplateInstanceUtil { + public static ICPPTemplateParameterMap getTemplateParameterMap(ICompositesFactory cf, ICPPTemplateInstance rbinding) { ICPPTemplateParameterMap preresult= rbinding.getTemplateParameterMap(); Integer[] keys= preresult.getAllParameterPositions(); @@ -50,8 +51,8 @@ public class TemplateInstanceUtil { result.put(key, convert(cf, pack)); } } - } catch(DOMException de) { - CCorePlugin.log(de); + } catch (DOMException e) { + CCorePlugin.log(e); } return result; } @@ -105,7 +106,7 @@ public class TemplateInstanceUtil { final IType typeValue = arg.getTypeValue(); IType t= cf.getCompositeType(typeValue); if (t != typeValue) { - return new CPPTemplateArgument(t); + return new CPPTemplateTypeArgument(t); } return arg; } @@ -113,8 +114,8 @@ public class TemplateInstanceUtil { @Deprecated public static ObjectMap getArgumentMap(ICompositesFactory cf, IIndexBinding rbinding) { ICPPSpecialization specn= (ICPPSpecialization) rbinding; - IBinding specd= ((CPPCompositesFactory)cf).findOneBinding(specn.getSpecializedBinding()); - if(specd == null) + IBinding specd= ((CPPCompositesFactory) cf).findOneBinding(specn.getSpecializedBinding()); + if (specd == null) specd= specn.getSpecializedBinding(); ObjectMap preresult= specn.getArgumentMap(); @@ -122,14 +123,13 @@ public class TemplateInstanceUtil { Object[] keys= preresult.keyArray(); Object[] keysToAdapt= keys; - if(specd instanceof ICPPTemplateDefinition) { - keysToAdapt= ((ICPPTemplateDefinition)specd).getTemplateParameters(); + if (specd instanceof ICPPTemplateDefinition) { + keysToAdapt= ((ICPPTemplateDefinition) specd).getTemplateParameters(); } - for(int i = 0; i < keys.length && i < keysToAdapt.length; i++) { + for (int i= 0; i < keys.length && i < keysToAdapt.length; i++) { IType type= (IType) preresult.get(keys[i]); result.put( - cf.getCompositeBinding((IIndexFragmentBinding)keysToAdapt[i]), - cf.getCompositeType(type)); + cf.getCompositeBinding((IIndexFragmentBinding) keysToAdapt[i]), cf.getCompositeType(type)); } return result; @@ -144,15 +144,15 @@ public class TemplateInstanceUtil { public static IType[] getArguments(ICompositesFactory cf, ICPPClassTemplatePartialSpecialization rbinding) { try { return getArguments(cf, rbinding.getArguments()); - } catch(DOMException de) { - CCorePlugin.log(de); + } catch (DOMException e) { + CCorePlugin.log(e); return IType.EMPTY_TYPE_ARRAY; } } @Deprecated private static IType[] getArguments(ICompositesFactory cf, IType[] result) { - for(int i=0; i= 0 && len <= (Database.MAX_MALLOC_SIZE-2)/NODE_SIZE); - long p= record+2; - for (int i=0; i= 0 && len <= (Database.MAX_MALLOC_SIZE - 2) / NODE_SIZE); + long p= record + 2; + for (int i= 0; i < len; i++) { linkage.storeType(p, null); - linkage.storeValue(p+VALUE_OFFSET, null); + linkage.storeValue(p + VALUE_OFFSET, null); p+= NODE_SIZE; } db.free(record); @@ -81,25 +80,25 @@ public class PDOMCPPArgumentList { final Database db= linkage.getDB(); final short len= db.getShort(rec); - Assert.isTrue(len >= 0 && len <= (Database.MAX_MALLOC_SIZE-2)/NODE_SIZE); + Assert.isTrue(len >= 0 && len <= (Database.MAX_MALLOC_SIZE - 2) / NODE_SIZE); if (len == 0) { return ICPPTemplateArgument.EMPTY_ARGUMENTS; } - rec+=2; + rec += 2; ICPPTemplateArgument[] result= new ICPPTemplateArgument[len]; - for (int i=0; i> 16); + return (short) (getParameterID() >> 16); } @Override @@ -184,18 +182,22 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem public IValue getInitialValue() { return null; } + @Override public boolean isAuto() { return false; } + @Override public boolean isExtern() { return false; } + @Override public boolean isRegister() { return false; } + @Override public boolean isStatic() { return false; @@ -204,6 +206,7 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem public boolean isExternC() { return false; } + @Override public boolean isMutable() { return false; @@ -213,6 +216,7 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem public Object clone() { throw new UnsupportedOperationException(); } + /** * @deprecated */ @@ -221,5 +225,4 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem public IASTExpression getDefault() { return null; } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateParameterMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateParameterMap.java index 32bd0ad3e13..7bf5bd2a6fe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateParameterMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateParameterMap.java @@ -6,7 +6,7 @@ * 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.pdom.dom.cpp; @@ -16,7 +16,6 @@ import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap; import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; @@ -42,32 +41,32 @@ public class PDOMCPPTemplateParameterMap { int keyLen= 0; int dataSize= 2; for (Integer key : keys) { - int delta= 2+4+NODE_SIZE; + int delta= 2 + 4 + NODE_SIZE; ICPPTemplateArgument[] packExpansion= map.getPackExpansion(key); if (packExpansion != null) { - delta+= (packExpansion.length-1) * NODE_SIZE; + delta += (packExpansion.length - 1) * NODE_SIZE; } - if (dataSize+delta > Database.MAX_MALLOC_SIZE) + if (dataSize + delta > Database.MAX_MALLOC_SIZE) break; dataSize += delta; keyLen++; } final long block= db.malloc(dataSize); long p= block; - db.putShort(p, (short)keyLen); p+=2; + db.putShort(p, (short) keyLen); p += 2; for (final Integer paramId : keys) { if (--keyLen < 0) break; - db.putInt(p, paramId); p+=4; + db.putInt(p, paramId); p += 4; final ICPPTemplateArgument arg = map.getArgument(paramId); if (arg != null) { - db.putShort(p, (short) -1); p+=2; - storeArgument(db, linkage, p, arg); p+= NODE_SIZE; + db.putShort(p, (short) -1); p += 2; + storeArgument(db, linkage, p, arg); p += NODE_SIZE; } else { final ICPPTemplateArgument[] args = map.getPackExpansion(paramId); - db.putShort(p, (short) args.length); p+=2; + db.putShort(p, (short) args.length); p += 2; for (ICPPTemplateArgument a : args) { - storeArgument(db, linkage, p, a); p+= NODE_SIZE; + storeArgument(db, linkage, p, a); p += NODE_SIZE; } } } @@ -93,16 +92,16 @@ public class PDOMCPPTemplateParameterMap { final Database db= linkage.getDB(); long p= record; - final short len= db.getShort(p); p+= 2; + final short len= db.getShort(p); p += 2; - for (int i=0; i Date: Sat, 28 Jul 2012 18:37:31 -0700 Subject: [PATCH 09/31] Bug 299911. Split CPPTemplateArgument class into CPPTemplateTypeArgument and CPPTemplateNonTypeArgument. --- .../tests/IndexCPPBindingResolutionBugs.java | 4 +- .../tests/IndexCPPTemplateResolutionTest.java | 6 +- .../core/dom/parser/ITypeMarshalBuffer.java | 3 + .../cpp/CPPTemplateNonTypeArgument.java | 101 ++++++++++++++++++ .../cpp/CPPTemplateNonTypeParameter.java | 6 +- .../cpp/CPPTemplateTemplateParameter.java | 2 +- ...ment.java => CPPTemplateTypeArgument.java} | 37 ++----- .../parser/cpp/CPPTemplateTypeParameter.java | 2 +- .../parser/cpp/semantics/CPPEvaluation.java | 17 +++ .../parser/cpp/semantics/CPPTemplates.java | 39 +++---- .../dom/parser/cpp/semantics/CPPVisitor.java | 6 +- .../core/dom/parser/cpp/semantics/EvalID.java | 11 +- .../parser/cpp/semantics/SemanticUtil.java | 4 +- .../semantics/TemplateArgumentDeduction.java | 9 +- .../composite/cpp/CPPCompositesFactory.java | 2 +- .../composite/cpp/TemplateInstanceUtil.java | 32 +++--- .../core/pdom/db/TypeMarshalBuffer.java | 30 +++++- .../pdom/dom/cpp/PDOMCPPArgumentList.java | 6 +- .../core/pdom/dom/cpp/PDOMCPPLinkage.java | 11 +- .../cpp/PDOMCPPTemplateNonTypeParameter.java | 3 +- .../dom/cpp/PDOMCPPTemplateParameterMap.java | 6 +- .../cpp/PDOMCPPTemplateTemplateParameter.java | 4 +- .../dom/cpp/PDOMCPPTemplateTypeParameter.java | 4 +- 23 files changed, 244 insertions(+), 101 deletions(-) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeArgument.java rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/{CPPTemplateArgument.java => CPPTemplateTypeArgument.java} (67%) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java index bcb559c0bf8..f5b63b5bc7a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java @@ -55,7 +55,7 @@ import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexMacro; import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache; import org.eclipse.core.runtime.CoreException; @@ -226,7 +226,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertInstance(b1, ICPPInstanceCache.class); ICPPInstanceCache ct= (ICPPInstanceCache) b1; - ICPPSpecialization inst= ct.getInstance(new ICPPTemplateArgument[]{new CPPTemplateArgument((IType)b0)}); + ICPPSpecialization inst= ct.getInstance(new ICPPTemplateArgument[]{new CPPTemplateTypeArgument((IType)b0)}); assertInstance(inst, ICPPClassType.class); ICPPClassType c2t= (ICPPClassType) inst; ICPPBase[] bases= c2t.getBases(); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java index d49b31b5520..303976fb74f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java @@ -56,7 +56,7 @@ import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; @@ -1556,8 +1556,8 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa IBinding inst2= CPPTemplates.instantiate(tmplDef, inst.getTemplateArguments(), name); assertSame(inst, inst2); - IBinding charInst1= CPPTemplates.instantiate(tmplDef, new ICPPTemplateArgument[] {new CPPTemplateArgument(new CPPBasicType(Kind.eChar, 0))}, name); - IBinding charInst2= CPPTemplates.instantiate(tmplDef, new ICPPTemplateArgument[] {new CPPTemplateArgument(new CPPBasicType(Kind.eChar, 0))}, name); + IBinding charInst1= CPPTemplates.instantiate(tmplDef, new ICPPTemplateArgument[] {new CPPTemplateTypeArgument(new CPPBasicType(Kind.eChar, 0))}, name); + IBinding charInst2= CPPTemplates.instantiate(tmplDef, new ICPPTemplateArgument[] {new CPPTemplateTypeArgument(new CPPBasicType(Kind.eChar, 0))}, name); assertSame(charInst1, charInst2); } 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 4b0ebf003e7..6d859a6d450 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 @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.dom.parser; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.core.runtime.CoreException; /** @@ -61,6 +62,7 @@ public interface ITypeMarshalBuffer { IValue unmarshalValue() throws CoreException; IBinding unmarshalBinding() throws CoreException; ISerializableEvaluation unmarshalEvaluation() throws CoreException; + ICPPTemplateArgument unmarshalTemplateArgument() throws CoreException; int getByte() throws CoreException; int getShort() throws CoreException; int getInt() throws CoreException; @@ -71,6 +73,7 @@ public interface ITypeMarshalBuffer { void marshalValue(IValue value) throws CoreException; void marshalBinding(IBinding binding) throws CoreException; void marshalEvaluation(ISerializableEvaluation eval, boolean includeValue) throws CoreException; + void marshalTemplateArgument(ICPPTemplateArgument arg) throws CoreException; void putByte(byte data); void putShort(short data); void putInt(int data); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeArgument.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeArgument.java new file mode 100644 index 00000000000..3c095d5db00 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeArgument.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2008, 2012 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.cpp; + +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; + +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalTypeId; +import org.eclipse.core.runtime.Assert; + +/** + * Implementation of non-type template argument, used by AST and index. + */ +public class CPPTemplateNonTypeArgument implements ICPPTemplateArgument { + private final ICPPEvaluation fEvaluation; + + public CPPTemplateNonTypeArgument(ICPPEvaluation evaluation) { + Assert.isNotNull(evaluation); + fEvaluation= evaluation; + } + + public CPPTemplateNonTypeArgument(IValue value, IType type) { + fEvaluation = new EvalFixed(type, PRVALUE, value); + } + + @Override + public boolean isTypeValue() { + return false; + } + + @Override + public boolean isNonTypeValue() { + return true; + } + + @Override + public IType getTypeValue() { + return null; + } + + @Override + public IValue getNonTypeValue() { + return fEvaluation.getValue(null); + } + + @Override + public IType getTypeOfNonTypeValue() { + return fEvaluation.getTypeOrFunctionSet(null); + } + + @Override + public boolean isPackExpansion() { + return fEvaluation.getTypeOrFunctionSet(null) instanceof ICPPParameterPackType; + } + + @Override + public ICPPTemplateArgument getExpansionPattern() { + IType type = fEvaluation.getTypeOrFunctionSet(null); + if (type instanceof ICPPParameterPackType) { + IType t= ((ICPPParameterPackType) type).getType(); + if (t != null) { + ICPPEvaluation evaluation; + if (fEvaluation instanceof EvalFixed) { + EvalFixed fixed = (EvalFixed) fEvaluation; + evaluation = new EvalFixed(t, fixed.getValueCategory(), fixed.getValue()); + } else { + evaluation = new EvalTypeId(t, fEvaluation); + } + return new CPPTemplateNonTypeArgument(evaluation); + } + } + return null; + } + + @Override + public boolean isSameValue(ICPPTemplateArgument arg) { + return getNonTypeValue().equals(arg.getNonTypeValue()); + } + + @Override + public String toString() { + return getNonTypeValue().toString(); + } + + public ICPPEvaluation getEvaluation() { + return fEvaluation; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java index d6396a23de8..a0280dd5359 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2010 IBM Corporation and others. + * Copyright (c) 2005, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -81,7 +81,7 @@ public class CPPTemplateNonTypeParameter extends CPPTemplateParameter ICPPASTInitializerList list= (ICPPASTInitializerList) dc; switch (list.getSize()) { case 0: - return new CPPTemplateArgument(Value.create(0), getType()); + return new CPPTemplateNonTypeArgument(Value.create(0), getType()); case 1: dc= list.getClauses()[0]; if (dc instanceof IASTExpression) { @@ -95,7 +95,7 @@ public class CPPTemplateNonTypeParameter extends CPPTemplateParameter IValue val= Value.create(d, Value.MAX_RECURSION_DEPTH); IType t= getType(); - return new CPPTemplateArgument(val, t); + return new CPPTemplateNonTypeArgument(val, t); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java index 67f62f5fe8b..bc070eda26f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java @@ -131,7 +131,7 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement if (d == null) return null; - return new CPPTemplateArgument(d); + return new CPPTemplateTypeArgument(d); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateArgument.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeArgument.java similarity index 67% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateArgument.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeArgument.java index a7a33a6a73e..7ec0f62f798 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateArgument.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeArgument.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 Wind River Systems, Inc. and others. + * Copyright (c) 2008, 2012 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -17,47 +18,39 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.core.runtime.Assert; /** - * Implementation of template arguments, used by ast and index. + * Implementation of type template arguments, used by AST and index. */ -public class CPPTemplateArgument implements ICPPTemplateArgument { +public class CPPTemplateTypeArgument implements ICPPTemplateArgument { private final IType fType; - private final IValue fValue; - public CPPTemplateArgument(IValue value, IType type) { - Assert.isNotNull(value); - fType= type; - fValue= value; - } - - public CPPTemplateArgument(IType type) { + public CPPTemplateTypeArgument(IType type) { Assert.isNotNull(type); fType= type; - fValue= null; } @Override public boolean isTypeValue() { - return fValue == null; + return true; } @Override public boolean isNonTypeValue() { - return fValue != null; + return false; } @Override public IType getTypeValue() { - return isTypeValue() ? fType : null; + return fType; } @Override public IValue getNonTypeValue() { - return fValue; + return null; } @Override public IType getTypeOfNonTypeValue() { - return isNonTypeValue() ? fType : null; + return null; } @Override @@ -70,10 +63,7 @@ public class CPPTemplateArgument implements ICPPTemplateArgument { if (fType instanceof ICPPParameterPackType) { IType t= ((ICPPParameterPackType) fType).getType(); if (t != null) { - if (fValue != null) { - return new CPPTemplateArgument(fValue, t); - } - return new CPPTemplateArgument(t); + return new CPPTemplateTypeArgument(t); } } return null; @@ -81,16 +71,11 @@ public class CPPTemplateArgument implements ICPPTemplateArgument { @Override public boolean isSameValue(ICPPTemplateArgument arg) { - if (fValue != null) { - return fValue.equals(arg.getNonTypeValue()); - } return fType.isSameType(arg.getTypeValue()); } @Override public String toString() { - if (fValue != null) - return fValue.toString(); return fType.toString(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeParameter.java index ec47f888fbd..9b2bf75ab72 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeParameter.java @@ -78,7 +78,7 @@ public class CPPTemplateTypeParameter extends CPPTemplateParameter implements if (t == null) return null; - return new CPPTemplateArgument(t); + return new CPPTemplateTypeArgument(t); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java index 0e91a249095..57623407455 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java @@ -16,12 +16,14 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.Value; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.core.runtime.CoreException; @@ -103,6 +105,16 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } } + @Override + public void marshalTemplateArgument(ICPPTemplateArgument arg) throws CoreException { + if (arg instanceof CPPTemplateNonTypeArgument) { + putByte(VALUE); + ((CPPTemplateNonTypeArgument) arg).getEvaluation().marshal(this, true); + } else { + marshalType(arg.getTypeValue()); + } + } + @Override public void putByte(byte value) { appendSeparator(); @@ -160,6 +172,11 @@ public abstract class CPPEvaluation implements ICPPEvaluation { throw new UnsupportedOperationException(); } + @Override + public ICPPTemplateArgument unmarshalTemplateArgument() throws CoreException { + throw new UnsupportedOperationException(); + } + @Override public int getByte() throws CoreException { throw new UnsupportedOperationException(); 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 b4f594d148a..b7382678968 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 @@ -123,11 +123,12 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethodTemplateSpecializat import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPParameterPackType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerToMemberType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateDefinition; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeParameter; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTemplateParameter; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeParameter; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTypedefSpecialization; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownBinding; @@ -492,11 +493,11 @@ public class CPPTemplates { if (tp.isParameterPack()) { t= new CPPParameterPackType(t); } - args[i] = new CPPTemplateArgument(t); + args[i] = new CPPTemplateTypeArgument(t); } else if (tp instanceof ICPPTemplateNonTypeParameter) { // Non-type template parameter pack already has type 'ICPPParameterPackType' final ICPPTemplateNonTypeParameter nttp = (ICPPTemplateNonTypeParameter) tp; - args[i] = new CPPTemplateArgument(Value.create(nttp), nttp.getType()); + args[i] = new CPPTemplateNonTypeArgument(Value.create(nttp), nttp.getType()); } else { assert false; } @@ -1083,14 +1084,14 @@ public class CPPTemplates { final IType instType= instantiateType(origType, tpMap, packOffset, within, point); if (origType == instType && origValue == instValue) return arg; - return new CPPTemplateArgument(instValue, instType); + return new CPPTemplateNonTypeArgument(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); + return new CPPTemplateTypeArgument(inst); } private static CPPTemplateParameterMap instantiateArgumentMap(ICPPTemplateParameterMap orig, ICPPTemplateParameterMap tpMap, @@ -1138,7 +1139,7 @@ public class CPPTemplates { return type; } // The parameter types need to be adjusted. - for (int i=0; i= 0) { ICPPTemplateArgument old= fDeducedArgs.getArgument(parID, fPackOffset); if (old == null) { - if (!deduce(parID, new CPPTemplateArgument(as, new CPPBasicType(ICPPBasicType.Kind.eInt, 0)))) { + if (!deduce(parID, new CPPTemplateNonTypeArgument(as, new CPPBasicType(ICPPBasicType.Kind.eInt, 0)))) { return false; } } else if (!as.equals(old.getNonTypeValue())) { @@ -764,7 +765,7 @@ public class TemplateArgumentDeduction { } if (a == null) return false; - return deduce(((ICPPTemplateParameter)p).getParameterID(), new CPPTemplateArgument(a)); + return deduce(((ICPPTemplateParameter)p).getParameterID(), new CPPTemplateTypeArgument(a)); } else if (p instanceof ICPPTemplateInstance) { if (!(a instanceof ICPPTemplateInstance)) return false; @@ -792,7 +793,7 @@ public class TemplateArgumentDeduction { if (current != null) { if (current.isNonTypeValue() || !current.getTypeValue().isSameType(aTemplate)) return false; - } else if (!deduce(tparId, new CPPTemplateArgument(aTemplate))) { + } else if (!deduce(tparId, new CPPTemplateTypeArgument(aTemplate))) { return false; } } else if (!aTemplate.isSameType(pTemplate)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java index 45f376da9bc..1108417de68 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java @@ -233,7 +233,7 @@ public class CPPCompositesFactory extends AbstractCompositeFactory { throw new CompositingNotImplementedError(); } - private ICPPEvaluation getCompositeEvaluation(ICPPEvaluation eval) { + public ICPPEvaluation getCompositeEvaluation(ICPPEvaluation eval) { if (eval == null) return null; if (eval instanceof EvalBinary) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/TemplateInstanceUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/TemplateInstanceUtil.java index 316af361b69..06cc8f1fc69 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/TemplateInstanceUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/TemplateInstanceUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 Symbian Software Systems and others. + * Copyright (c) 2007, 2012 Symbian Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * Andrew Ferguson (Symbian) - Initial implementation * Bryan Wilkinson (QNX) * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; @@ -16,7 +17,6 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; @@ -26,8 +26,10 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.parser.util.ObjectMap; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; @@ -91,22 +93,18 @@ public class TemplateInstanceUtil { } static ICPPTemplateArgument convert(ICompositesFactory cf, ICPPTemplateArgument arg) throws DOMException { - if (arg == null) - return null; - if (arg.isNonTypeValue()) { - final IType t= arg.getTypeOfNonTypeValue(); - final IType t2= cf.getCompositeType(t); - final IValue v= arg.getNonTypeValue(); - final IValue v2= cf.getCompositeValue(v); - if (t != t2 || v != v2) { - return new CPPTemplateArgument(v2, t2); + if (arg instanceof CPPTemplateTypeArgument) { + final IType typeValue = arg.getTypeValue(); + IType t= cf.getCompositeType(typeValue); + if (t != typeValue) { + return new CPPTemplateTypeArgument(t); + } + } else if (arg instanceof CPPTemplateNonTypeArgument) { + ICPPEvaluation eval = ((CPPTemplateNonTypeArgument) arg).getEvaluation(); + ICPPEvaluation eval2 = ((CPPCompositesFactory) cf).getCompositeEvaluation(eval); + if (eval2 != eval) { + return new CPPTemplateNonTypeArgument(eval2); } - return arg; - } - final IType typeValue = arg.getTypeValue(); - IType t= cf.getCompositeType(typeValue); - if (t != typeValue) { - return new CPPTemplateTypeArgument(t); } return arg; } 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 7c3f483a70e..b3e7656fca4 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Wind River Systems, Inc. and others. + * Copyright (c) 2009, 2012 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.db; @@ -16,11 +17,15 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ISemanticProblem; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; import org.eclipse.cdt.internal.core.dom.parser.Value; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; import org.eclipse.core.runtime.CoreException; @@ -93,7 +98,7 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer { byte firstByte= fBuffer[fPos]; if (firstByte == BINDING_TYPE) { - fPos+= 2; + fPos += 2; long rec= getRecordPointer(); return (IBinding) fLinkage.getNode(rec); } else if (firstByte == NULL_TYPE || firstByte == UNSTORABLE_TYPE) { @@ -182,6 +187,27 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer { return Value.unmarshal(this); } + @Override + public void marshalTemplateArgument(ICPPTemplateArgument arg) throws CoreException { + if (arg instanceof CPPTemplateNonTypeArgument) { + putByte(VALUE); + ((CPPTemplateNonTypeArgument) arg).getEvaluation().marshal(this, true); + } else { + marshalType(arg.getTypeValue()); + } + } + + @Override + public ICPPTemplateArgument unmarshalTemplateArgument() throws CoreException { + int firstByte= getByte(); + if (firstByte == VALUE) { + return new CPPTemplateNonTypeArgument((ICPPEvaluation) unmarshalEvaluation()); + } else { + fPos--; + return new CPPTemplateTypeArgument(unmarshalType()); + } + } + private void request(int i) { if (fBuffer == null) { if (i <= Database.TYPE_SIZE) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPArgumentList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPArgumentList.java index 387d3265e27..0fc6df2b276 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPArgumentList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPArgumentList.java @@ -15,6 +15,8 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; @@ -94,9 +96,9 @@ public class PDOMCPPArgumentList { } IValue val= linkage.loadValue(rec + VALUE_OFFSET); if (val != null) { - result[i]= new CPPTemplateArgument(val, type); + result[i]= new CPPTemplateNonTypeArgument(val, type); } else { - result[i]= new CPPTemplateArgument(type); + result[i]= new CPPTemplateTypeArgument(type); } rec += NODE_SIZE; } 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 decd3d170cb..946b8a9caac 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,6 +13,11 @@ *******************************************************************************/ 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; @@ -114,11 +119,6 @@ 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. */ @@ -1109,5 +1109,4 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { } throw new CoreException(CCorePlugin.createStatus("Cannot unmarshal an evaluation, first byte=" + firstByte)); //$NON-NLS-1$ } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateNonTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateNonTypeParameter.java index bc909772cda..5b5988ebfad 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateNonTypeParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateNonTypeParameter.java @@ -24,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.internal.core.Util; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner; @@ -72,7 +73,7 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding IValue val= getLinkage().loadValue(record + DEFAULTVAL); if (val == null) return null; - return new CPPTemplateArgument(val, getType()); + return new CPPTemplateNonTypeArgument(val, getType()); } catch (CoreException e) { CCorePlugin.log(e); return null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateParameterMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateParameterMap.java index 7bf5bd2a6fe..74b2e6ef453 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateParameterMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateParameterMap.java @@ -16,7 +16,9 @@ import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; @@ -148,9 +150,9 @@ public class PDOMCPPTemplateParameterMap { IValue val= linkage.loadValue(rec + VALUE_OFFSET); ICPPTemplateArgument arg; if (val != null) { - arg= new CPPTemplateArgument(val, type); + arg= new CPPTemplateNonTypeArgument(val, type); } else { - arg= new CPPTemplateArgument(type); + arg= new CPPTemplateTypeArgument(type); } return arg; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTemplateParameter.java index 1d876f39dfc..29a85f62671 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTemplateParameter.java @@ -32,7 +32,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType; @@ -169,7 +169,7 @@ public class PDOMCPPTemplateTemplateParameter extends PDOMCPPBinding if (d == null) return null; - return new CPPTemplateArgument(d); + return new CPPTemplateTypeArgument(d); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTypeParameter.java index fe65201466d..2ebf0ac7c52 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTypeParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTypeParameter.java @@ -24,7 +24,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; @@ -155,7 +155,7 @@ class PDOMCPPTemplateTypeParameter extends PDOMCPPBinding implements IPDOMMember if (d == null) return null; - return new CPPTemplateArgument(d); + return new CPPTemplateTypeArgument(d); } @Override From 5ba0df7c575ef2b76bf87efcea760a8217b4db5d Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 31 Jul 2012 18:38:58 -0700 Subject: [PATCH 10/31] Cosmetics. --- .../core/parser/tests/ast2/AST2CPPTests.java | 8 +- .../parser/tests/ast2/AST2TemplateTests.java | 182 +++++++++--------- .../dom/ast/cpp/ICPPClassSpecialization.java | 3 +- .../core/dom/ast/cpp/ICPPClassTemplate.java | 5 +- .../cdt/core/dom/ast/cpp/ICPPClassType.java | 4 +- .../parser/cpp/CPPFieldSpecialization.java | 12 +- .../parser/cpp/CPPUnknownClassInstance.java | 4 +- .../core/dom/parser/cpp/CPPVariable.java | 11 +- .../parser/cpp/ICPPDeferredClassInstance.java | 5 +- .../dom/parser/cpp/ICPPUnknownClassType.java | 3 +- .../core/dom/parser/cpp/ICPPUnknownType.java | 3 +- .../dom/cpp/PDOMCPPClassSpecialization.java | 19 +- 12 files changed, 126 insertions(+), 133 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 9f663484c0d..f5ff218fd0d 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -9288,7 +9288,7 @@ public class AST2CPPTests extends AST2BaseTest { // auto f2 (); // missing late return type. public void testBug332114a() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); IBinding b= bh.assertNonProblem("f2", 0); // Must not throw a NPE IndexCPPSignatureUtil.getSignature(b); @@ -9713,7 +9713,7 @@ public class AST2CPPTests extends AST2BaseTest { // g( nullptr ); // error // } public void testNullptr_327298b() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); bh.assertProblem("checkNullPtr(1)", 12); bh.assertProblem("checklvalue(nullptr)", 11); bh.assertProblem("g( nullptr )", 1); @@ -9727,7 +9727,7 @@ public class AST2CPPTests extends AST2BaseTest { // } public void testNullptr_327298c() throws Exception { parseAndCheckBindings(); - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); IFunction f= bh.assertNonProblem("f( nullptr )", 1); assertEquals("void (char *)", ASTTypeUtil.getType(f.getType())); f= bh.assertNonProblem("f( 0 )", 1); @@ -9736,7 +9736,7 @@ public class AST2CPPTests extends AST2BaseTest { // void foo(struct S s); public void testParameterForwardDeclaration_379511() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPClassType struct= bh.assertNonProblem("S", 1, ICPPClassType.class); IName[] declarations= bh.getTranslationUnit().getDeclarations(struct); assertEquals(1, declarations.length); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 7eca6882562..77ae63e3a0a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -14,6 +14,7 @@ *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; +import static org.eclipse.cdt.core.parser.ParserLanguage.CPP; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getNestedType; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getUltimateType; @@ -81,7 +82,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; -import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase; @@ -107,11 +107,11 @@ public class AST2TemplateTests extends AST2BaseTest { } private IASTTranslationUnit parseAndCheckBindings(final String code) throws Exception { - return parseAndCheckBindings(code, ParserLanguage.CPP); + return parseAndCheckBindings(code, CPP); } public void testBasicClassTemplate() throws Exception { - IASTTranslationUnit tu = parse("template class A{ T t; };", ParserLanguage.CPP); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("template class A{ T t; };", CPP); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -143,7 +143,7 @@ public class AST2TemplateTests extends AST2BaseTest { // a.t1; a.t2; // } public void testBasicTemplateInstance_1() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -194,7 +194,7 @@ public class AST2TemplateTests extends AST2BaseTest { // a.f((int*)0); // } public void testBasicTemplateInstance_2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -226,7 +226,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f(0); // } public void testBasicTemplateFunction() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -255,7 +255,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template < class U > pair(const pair &); // }; public void testStackOverflow() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -276,7 +276,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template < class T > class A< T* > {}; // template < class T > class A< T** > {}; public void testBasicClassPartialSpecialization() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -302,7 +302,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template < class T > typename A::TYPE foo(T); // template < class T > typename A::TYPE foo(T); public void testStackOverflow_2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -337,7 +337,7 @@ public class AST2TemplateTests extends AST2BaseTest { // }; // template < class T > void A::f() { } public void testTemplateMemberDef() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -352,7 +352,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f(1); // } public void testTemplateFunctionImplicitInstantiation() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -371,7 +371,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f(p); //calls f(const T *) , 3 is more specialized than 1 or 2 // } public void test_14_5_5_2s5_OrderingFunctionTemplates_1() throws Exception{ - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -395,7 +395,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f(x); //ambiguous 1 or 2 // } public void test_14_5_5_2s5_OrderingFunctionTemplates_2() throws Exception{ - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -411,7 +411,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template < class T, template < class X > class U, T *pT > class A { // }; public void testTemplateParameters() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -438,7 +438,7 @@ public class AST2TemplateTests extends AST2BaseTest { // b->a; // } public void testDeferredInstances() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -478,7 +478,7 @@ public class AST2TemplateTests extends AST2BaseTest { // A a4; //uses #5, T is int, T2 is char, I is1 // A a5; //ambiguous, matches #3 & #5. public void test_14_5_4_1s2_MatchingTemplateSpecializations() throws Exception{ - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -521,7 +521,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template <> void f(int); //ok // template <> void f(int*); //ok public void test14_7_3_FunctionExplicitSpecialization() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -538,7 +538,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template void f(T*); // void g(int* p) { f(p); } public void test_14_5_5_1_FunctionTemplates_1() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -552,7 +552,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template void f(T); // void g(int* p) { f(p); } public void test_14_5_5_1_FunctionTemplates_2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -568,7 +568,7 @@ public class AST2TemplateTests extends AST2BaseTest { // int i = f(5); // Y is int // } public void test_14_8_1s2_FunctionTemplates() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -584,7 +584,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f("Annemarie"); // } public void test14_8_3s6_FunctionTemplates() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -604,7 +604,7 @@ public class AST2TemplateTests extends AST2BaseTest { // g(ip); //calls #4 // } public void test14_5_5_2s6_FunctionTemplates() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -631,7 +631,7 @@ public class AST2TemplateTests extends AST2BaseTest { // X* p2; // }; public void test14_6_1s1_LocalNames() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -652,7 +652,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f(&b); //call f(char**) // } public void test14_8s2_() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -683,7 +683,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template<> inline void f<>(int) { } //OK: inline // template<> int g<>(int) { } // OK: not inline public void test14_7_3s14() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -712,7 +712,7 @@ public class AST2TemplateTests extends AST2BaseTest { // x.a.a.a.a; // } public void test14_7_1s14_InfiniteInstantiation() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -744,7 +744,7 @@ public class AST2TemplateTests extends AST2BaseTest { // Y* q; // meaning Y // }; public void test14_6_1s2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -768,7 +768,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f(g); // } public void testBug45129() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -791,7 +791,7 @@ public class AST2TemplateTests extends AST2BaseTest { // a.u; // } public void testBug76951_2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -821,7 +821,7 @@ public class AST2TemplateTests extends AST2BaseTest { // }; // void f(A p) { } public void testInstances() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -837,7 +837,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template void f(T); // template void f(T) {} public void testTemplateParameterDeclarations() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -859,7 +859,7 @@ public class AST2TemplateTests extends AST2BaseTest { // a->pA; // }; public void testDeferredInstantiation() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -905,7 +905,7 @@ public class AST2TemplateTests extends AST2BaseTest { // ac.f<>(1); //template // } public void test14_5_2s2_MemberSpecializations() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -949,7 +949,7 @@ public class AST2TemplateTests extends AST2BaseTest { // A ac; // A ai; public void testClassSpecializations() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -981,7 +981,7 @@ public class AST2TemplateTests extends AST2BaseTest { // // explicitly specialized class template specialization // void A::f(int) { } public void test14_7_3s5_SpecializationMemberDefinition() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1018,7 +1018,7 @@ public class AST2TemplateTests extends AST2BaseTest { // b.f(c); // } public void testNestedSpecializations() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1060,7 +1060,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } // A a; public void test14_5_4s7_UsingClassTemplate() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1090,7 +1090,7 @@ public class AST2TemplateTests extends AST2BaseTest { // c.y.x; c.z.x; // } public void testTemplateTemplateParameter() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1137,7 +1137,7 @@ public class AST2TemplateTests extends AST2BaseTest { // a.t; // } public void testNestedTypeSpecializations() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1171,7 +1171,7 @@ public class AST2TemplateTests extends AST2BaseTest { // a.b.t; // } public void testNestedClassTypeSpecializations() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1210,7 +1210,7 @@ public class AST2TemplateTests extends AST2BaseTest { // A< C > a; a.s; // }; public void testTemplateParameterQualifiedType_1() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1262,7 +1262,7 @@ public class AST2TemplateTests extends AST2BaseTest { // U u; // } public void testTemplateScopes() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1286,7 +1286,7 @@ public class AST2TemplateTests extends AST2BaseTest { // }; // template void A::f<>(U){} public void testTemplateScopes_2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1443,7 +1443,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template<> template<> void A::g(int,char); // template<> void A::h(int) { } public void test14_7_3s16() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1505,7 +1505,7 @@ public class AST2TemplateTests extends AST2BaseTest { // C b; // C is the template parameter, not N::C // } public void test14_6_1s6() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1538,7 +1538,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template void sort(Array &); // template void sort<>(Array &); public void testBug90689_ExplicitInstantiation() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1564,7 +1564,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template void sort(Array& v) { } // template void sort(Array&); // argument is deduced here public void test14_7_2s2_ExplicitInstantiation() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1587,7 +1587,7 @@ public class AST2TemplateTests extends AST2BaseTest { // void f() { this; } // }; public void testBug74204() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1606,7 +1606,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f(t); // } public void testDeferredFunctionTemplates() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1625,7 +1625,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } // }; public void testRelaxationForTemplateInheritance() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1651,7 +1651,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } // } public void testBug91707() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1681,7 +1681,7 @@ public class AST2TemplateTests extends AST2BaseTest { // (*t).i; // } public void testBug98961() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1704,7 +1704,7 @@ public class AST2TemplateTests extends AST2BaseTest { // void begin(); // }; public void testBug98784() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1719,7 +1719,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f(A(1)); // } public void testBug99254() throws Exception{ - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1749,7 +1749,7 @@ public class AST2TemplateTests extends AST2BaseTest { // b->add(core::A(10, 2)); // } public void testBug99254_2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1776,7 +1776,7 @@ public class AST2TemplateTests extends AST2BaseTest { // b->add(A(10)); // } public void testBug99254_3() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1796,7 +1796,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testBug98666() throws Exception { CPPASTNameBase.sAllowNameComputation= true; - IASTTranslationUnit tu = parse("A::template B b;", ParserLanguage.CPP); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("A::template B b;", CPP); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1815,7 +1815,7 @@ public class AST2TemplateTests extends AST2BaseTest { // struct A::C::B{}; // A::C::B ab; public void testBug90678() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1847,7 +1847,7 @@ public class AST2TemplateTests extends AST2BaseTest { // int l = f<>(1); // uses #1 public void testBug95208() throws Exception { String content= getAboveComment(); - IASTTranslationUnit tu = parse(content, ParserLanguage.CPP); + IASTTranslationUnit tu = parse(content, CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1862,7 +1862,7 @@ public class AST2TemplateTests extends AST2BaseTest { assertSame(f1, col.getName(10).resolveBinding()); - tu = parse(content,ParserLanguage.CPP); + tu = parse(content,CPP); col = new CPPNameCollector(); tu.accept(col); @@ -1876,7 +1876,7 @@ public class AST2TemplateTests extends AST2BaseTest { // A broken; // }; public void testBug103578() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1896,7 +1896,7 @@ public class AST2TemplateTests extends AST2BaseTest { // a.base; // } public void testBug103715() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1921,7 +1921,7 @@ public class AST2TemplateTests extends AST2BaseTest { // void complex::f(float){ // } public void testBug74276() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1947,7 +1947,7 @@ public class AST2TemplateTests extends AST2BaseTest { // myType t; // } public void testBug105852() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1968,7 +1968,7 @@ public class AST2TemplateTests extends AST2BaseTest { // k.c; // } public void testBug105769() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1983,7 +1983,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template <> C(wchar_t * c) : blah(c) {} // }; public void testBug162230() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2018,7 +2018,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template< class T > class C {}; // typedef struct C CInt; public void testBug169628() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2362,7 +2362,7 @@ public class AST2TemplateTests extends AST2BaseTest { // // foo -> CPPMethodInstance // } public void testCPPConstructorTemplateSpecialization() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2384,7 +2384,7 @@ public class AST2TemplateTests extends AST2BaseTest { // return (lhs < rhs ? rhs : lhs); // } public void testNestedFuncTemplatedDeclarator_bug190241() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2434,7 +2434,7 @@ public class AST2TemplateTests extends AST2BaseTest { // void f(B::tb r) {} public void testTemplateTypedef_214447() throws Exception { CPPASTNameBase.sAllowNameComputation= true; - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2468,7 +2468,7 @@ public class AST2TemplateTests extends AST2BaseTest { // void f(Vec::reference r) {} public void testRebindPattern_214447_1() throws Exception { CPPASTNameBase.sAllowNameComputation= true; - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2508,7 +2508,7 @@ public class AST2TemplateTests extends AST2BaseTest { // void f(Vec::reference r) {} public void testRebindPattern_214447_2() throws Exception { CPPASTNameBase.sAllowNameComputation= true; - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2547,7 +2547,7 @@ public class AST2TemplateTests extends AST2BaseTest { // void f(map::value_type r) {} public void testRebindPattern_236197() throws Exception { CPPASTNameBase.sAllowNameComputation= true; - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); for (IASTName name : col.nameList) { @@ -2579,7 +2579,7 @@ public class AST2TemplateTests extends AST2BaseTest { // void main(Iter::iter_reference r); public void testSpecializationSelection_229218() throws Exception { CPPASTNameBase.sAllowNameComputation= true; - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); for (IASTName name : col.nameList) { @@ -2608,7 +2608,7 @@ public class AST2TemplateTests extends AST2BaseTest { // B::b::a x; public void testDefaultTemplateParameter() throws Exception { CPPASTNameBase.sAllowNameComputation= true; - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2754,7 +2754,7 @@ public class AST2TemplateTests extends AST2BaseTest { // const int i= 1; // A a1; public void testNonTypeArgumentIsIDExpression_229942_a() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2773,7 +2773,7 @@ public class AST2TemplateTests extends AST2BaseTest { // const int i= 1; // }; public void testNonTypeArgumentIsIDExpression_229942_b() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2787,7 +2787,7 @@ public class AST2TemplateTests extends AST2BaseTest { // const int i= 1; // A a1; public void testExpressionArgumentIsExpression_229942_c() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2802,7 +2802,7 @@ public class AST2TemplateTests extends AST2BaseTest { // const int i= 1; // A a1; public void testTypeIdOperatorArgumentIsUnaryExpression_229942_d() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2815,7 +2815,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template< class T1, class T2, int q1, int q2> // class A< C, C > {}; public void testTemplateIdAsTemplateArgumentIsTypeId_229942_e() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2848,7 +2848,7 @@ public class AST2TemplateTests extends AST2BaseTest { BindingAssertionHelper ba=new BindingAssertionHelper(getAboveComment(), true); ba.assertNonProblem("T> at) {", 1); - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2868,7 +2868,7 @@ public class AST2TemplateTests extends AST2BaseTest { // inline const void foo(void (*f)(A), T* t) { // disallowed, but we're testing the AST // } public void testTypeIdAsTemplateArgumentIsTypeId_229942_g() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2884,7 +2884,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template<> class Alias { // }; public void testNonAmbiguityCase_229942_h() throws Exception { - IASTTranslationUnit tu= parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu= parse(getAboveComment(), CPP); CPPNameCollector col= new CPPNameCollector(); tu.accept(col); @@ -3254,7 +3254,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testBug238180_ArrayOutOfBounds() throws Exception { // the code above used to trigger an ArrayOutOfBoundsException - parse(getAboveComment(), ParserLanguage.CPP); + parse(getAboveComment(), CPP); } // namespace detail { @@ -3293,7 +3293,7 @@ public class AST2TemplateTests extends AST2BaseTest { // test(new X(g)); // } public void testBug239586_ClassCast() throws Exception { - parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); + parseAndCheckBindings(getAboveComment(), CPP); } // template class CT { @@ -3399,7 +3399,7 @@ public class AST2TemplateTests extends AST2BaseTest { @Override public void run() { try { - parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); + parseAndCheckBindings(getAboveComment(), CPP); } catch (Throwable e) { th[0]= e; } @@ -3419,7 +3419,7 @@ public class AST2TemplateTests extends AST2BaseTest { // }; // template void A::foo(T t) {} public void testBug177418() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true ); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true ); CPPNameCollector col = new CPPNameCollector(); tu.accept( col ); @@ -3456,7 +3456,7 @@ public class AST2TemplateTests extends AST2BaseTest { // return new CT; // } public void testNewOfThisTemplate() throws Exception { - parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); + parseAndCheckBindings(getAboveComment(), CPP); } // template void f(T); @@ -4164,7 +4164,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testMethodSpecialization_322988() throws Exception { final String code= getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, CPP); } @@ -4323,7 +4323,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testClosingAngleBrackets2_261268() throws Exception { final String code= getAboveComment(); - IASTTranslationUnit tu = parse(code, ParserLanguage.CPP, true, false); + IASTTranslationUnit tu = parse(code, CPP, true, false); IASTFunctionDefinition fdef= getDeclaration(tu, 2); IASTProblemStatement p1= getStatement(fdef, 1); } @@ -4950,7 +4950,7 @@ public class AST2TemplateTests extends AST2BaseTest { code.append('\n').append("int_<0> >::type,"); } code.append("int_<0> >::type tdef;"); - IASTTranslationUnit tu= parse(code.toString(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu= parse(code.toString(), CPP, true, true); tu = validateCopy(tu); assertEquals(1, tu.getDeclarations().length); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java index 0a9d97a11b7..b71a4e4aa15 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java @@ -6,7 +6,7 @@ * 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.core.dom.ast.cpp; @@ -21,7 +21,6 @@ import org.eclipse.cdt.core.dom.ast.IBinding; * @noimplement This interface is not intended to be implemented by clients. */ public interface ICPPClassSpecialization extends ICPPSpecialization, ICPPClassType { - @Override ICPPClassType getSpecializedBinding(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassTemplate.java index 27e0e81beb0..107ce9e6183 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassTemplate.java @@ -6,12 +6,11 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Niefer (IBM) - Initial API and implementation - * Markus Schorn (Wind River Systems) + * Andrew Niefer (IBM) - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; - /** * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassType.java index 16bfa987063..633387a65c3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassType.java @@ -25,10 +25,8 @@ public interface ICPPClassType extends ICompositeType, ICPPBinding { public static final int k_class = ICPPASTCompositeTypeSpecifier.k_class; /** - * Returns a list of base class relationships. The list is empty if there + * Returns an array of base class relationships. The returned array is empty if there * are none. - * - * @return List of ICPPBase */ public ICPPBase[] getBases(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java index 929451e7eff..39b4c496cd9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Niefer (IBM) - Initial API and implementation - * Markus Schorn (Wind River Systems) + * Andrew Niefer (IBM) - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -23,8 +23,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; * Binding for a specialization of a field. */ public class CPPFieldSpecialization extends CPPSpecialization implements ICPPField { - private IType type = null; - private IValue value= null; + private final IType type; + private final IValue value; public CPPFieldSpecialization(IBinding orig, ICPPClassType owner, ICPPTemplateParameterMap tpmap, IType type, IValue value) { @@ -36,7 +36,7 @@ public class CPPFieldSpecialization extends CPPSpecialization implements ICPPFie private ICPPField getField() { return (ICPPField) getSpecializedBinding(); } - + @Override public int getVisibility() { return getField().getVisibility(); @@ -46,7 +46,7 @@ public class CPPFieldSpecialization extends CPPSpecialization implements ICPPFie public ICPPClassType getClassOwner() { return getField().getClassOwner(); } - + @Override public IType getType() { return type; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java index d83258844ef..93a9386f9ce 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Sergey Prigogin (Google) - initial API and implementation - * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java index bfa9f6b0498..a32d30b02d9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java @@ -47,9 +47,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; import org.eclipse.core.runtime.PlatformObject; public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInternalBinding, IInternalVariable { - private IASTName fDefinition = null; - private IASTName fDeclarations[] = null; - private IType fType = null; + private IASTName fDefinition; + private IASTName fDeclarations[]; + private IType fType; private boolean fAllResolved; public CPPVariable(IASTName name) { @@ -59,10 +59,11 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt name = ns[ns.length - 1]; } - if (isDef) + if (isDef) { fDefinition = name; - else + } else { fDeclarations = new IASTName[] { name }; + } // built-in variables supply a null if (name != null) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPDeferredClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPDeferredClassInstance.java index 8bd724ab129..c6017e6a0f4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPDeferredClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPDeferredClassInstance.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation - * Markus Schorn (Wind River Systems) + * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -19,7 +19,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; * Interface for deferred class template instances. */ public interface ICPPDeferredClassInstance extends ICPPUnknownClassType, ICPPTemplateInstance { - /** * Returns the class template for the deferred instantiation. */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownClassType.java index 910da0448ec..aaecce2d77a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownClassType.java @@ -6,7 +6,7 @@ * 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; @@ -20,5 +20,4 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; * @since 5.0 */ public interface ICPPUnknownClassType extends ICPPUnknownBinding, ICPPUnknownType, ICPPClassType { - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownType.java index 341a26c7496..981782b0263 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownType.java @@ -6,7 +6,7 @@ * 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; @@ -16,5 +16,4 @@ import org.eclipse.cdt.core.dom.ast.IType; * Marks types that depend on a template parameter and are thus unknown. */ public interface ICPPUnknownType extends IType { - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java index 8a801a9b415..d153b3fac5b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java @@ -54,9 +54,8 @@ import org.eclipse.core.runtime.CoreException; */ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements ICPPClassSpecialization, IPDOMMemberOwner, IPDOMCPPClassType { - - private static final int FIRSTBASE = PDOMCPPSpecialization.RECORD_SIZE + 0; - private static final int MEMBERLIST = PDOMCPPSpecialization.RECORD_SIZE + 4; + private static final int FIRST_BASE = PDOMCPPSpecialization.RECORD_SIZE + 0; + private static final int MEMBER_LIST = PDOMCPPSpecialization.RECORD_SIZE + 4; /** * The size in bytes of a PDOMCPPClassSpecialization record in the database. @@ -167,13 +166,13 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements } public PDOMCPPBase getFirstBase() throws CoreException { - long rec = getDB().getRecPtr(record + FIRSTBASE); + long rec = getDB().getRecPtr(record + FIRST_BASE); return rec != 0 ? new PDOMCPPBase(getLinkage(), rec) : null; } private void setFirstBase(PDOMCPPBase base) throws CoreException { long rec = base != null ? base.getRecord() : 0; - getDB().putRecPtr(record + FIRSTBASE, rec); + getDB().putRecPtr(record + FIRST_BASE, rec); } public void addBase(PDOMCPPBase base) throws CoreException { @@ -206,7 +205,6 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements } } - // implementation of class type @Override public ICPPBase[] getBases() { IScope scope= getCompositeScope(); @@ -214,7 +212,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements return ((ICPPClassSpecializationScope) scope).getBases(); } - // this is an explicit specialization + // This is an explicit specialization Long key= record + PDOMCPPLinkage.CACHE_BASES; ICPPBase[] bases= (ICPPBase[]) getPDOM().getCachedResult(key); if (bases != null) @@ -222,8 +220,9 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements try { List list = new ArrayList(); - for (PDOMCPPBase base = getFirstBase(); base != null; base = base.getNextBase()) + for (PDOMCPPBase base = getFirstBase(); base != null; base = base.getNextBase()) { list.add(base); + } Collections.reverse(list); bases = list.toArray(new ICPPBase[list.size()]); getPDOM().putCachedResult(key, bases); @@ -362,13 +361,13 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public void addChild(PDOMNode member) throws CoreException { - PDOMNodeLinkedList list = new PDOMNodeLinkedList(getLinkage(), record + MEMBERLIST); + PDOMNodeLinkedList list = new PDOMNodeLinkedList(getLinkage(), record + MEMBER_LIST); list.addMember(member); } @Override public void acceptUncached(IPDOMVisitor visitor) throws CoreException { - PDOMNodeLinkedList list = new PDOMNodeLinkedList(getLinkage(), record + MEMBERLIST); + PDOMNodeLinkedList list = new PDOMNodeLinkedList(getLinkage(), record + MEMBER_LIST); list.accept(visitor); } From 85d3fcdd0df9e89a48713be86781507a5488634a Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 31 Jul 2012 18:43:37 -0700 Subject: [PATCH 11/31] Bug 299911. Few fixes and a test that is currently failing due to a NPE. --- .../parser/tests/ast2/AST2TemplateTests.java | 44 +++++++++++++++++++ .../cdt/internal/core/dom/parser/Value.java | 8 +++- .../core/dom/parser/cpp/semantics/EvalID.java | 29 ++++++++---- 3 files changed, 70 insertions(+), 11 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 77ae63e3a0a..c7e8539f991 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -5591,6 +5591,50 @@ public class AST2TemplateTests extends AST2BaseTest { parseAndCheckBindings(); } + // class A; + // class B; + // + // template + // struct bool_constant { + // static const bool value = bool_value; + // }; + // + // template + // struct ImplicitlyConvertible { + // static From MakeFrom(); + // + // static char Helper(To); + // static char (&Helper(...))[2]; + // + // static const bool value = sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1; + // }; + // + // template + // struct IsAorB + // : public bool_constant< + // ImplicitlyConvertible::value || + // ImplicitlyConvertible::value> { + // }; + // + // namespace ns { + // + // template + // class C { + // }; + // + // template + // void f(V a); + // + // } // namespace ns + // + // void test() { + // ns::C::value> a; + // f(a); + // }; + public void _testDependentExpressions() throws Exception { + parseAndCheckBindings(); + } + // template void* foo(int); // template void f(T t) { // if (T* i = foo<0>(0)) 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 8f1b1295048..44e298d51fb 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 @@ -32,6 +32,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalBinding; import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator; import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator.EvalException; @@ -350,9 +351,10 @@ public class Value implements IValue { IASTTypeIdExpression typeIdEx = (IASTTypeIdExpression) exp; switch (typeIdEx.getOperator()) { case IASTTypeIdExpression.op_sizeof: - final IType type; ASTTranslationUnit ast = (ASTTranslationUnit) typeIdEx.getTranslationUnit(); - type = ast.createType(typeIdEx.getTypeId()); + final IType type = ast.createType(typeIdEx.getTypeId()); + if (type instanceof ICPPUnknownType) + return null; SizeofCalculator calculator = ast.getSizeofCalculator(); SizeAndAlignment info = calculator.sizeAndAlignment(type); if (info == null) @@ -401,6 +403,8 @@ public class Value implements IValue { final IASTExpression operand = exp.getOperand(); if (operand != null) { IType type = operand.getExpressionType(); + if (type instanceof ICPPUnknownType) + return null; ASTTranslationUnit ast = (ASTTranslationUnit) exp.getTranslationUnit(); SizeofCalculator calculator = ast.getSizeofCalculator(); SizeAndAlignment info = calculator.sizeAndAlignment(type); 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 296ac5c9d46..3e5971d1a9c 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 @@ -36,6 +36,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration; @@ -291,21 +292,20 @@ public class EvalID extends CPPEvaluation { if (fieldOwner != null) { fieldOwner = fieldOwner.instantiate(tpMap, packOffset, within, maxdepth, point); } + IBinding nameOwner = fNameOwner; - if (fNameOwner instanceof ICPPTemplateParameter) { - ICPPTemplateArgument argument = tpMap.getArgument((ICPPTemplateParameter) fNameOwner); + if (nameOwner instanceof ICPPTemplateParameter) { + ICPPTemplateArgument argument = tpMap.getArgument((ICPPTemplateParameter) nameOwner); if (argument != null) { IType type = argument.getTypeValue(); if (type instanceof IBinding) nameOwner = (IBinding) type; } - } else if (fNameOwner instanceof ICPPUnknownBinding) { - try { - nameOwner = CPPTemplates.resolveUnknown((ICPPUnknownBinding) fNameOwner, tpMap, - packOffset, within, point); - } catch (DOMException e) { - CCorePlugin.log(e); - } + } else if (nameOwner instanceof ICPPUnknownBinding) { + nameOwner = resolveUnknown(nameOwner, tpMap, packOffset, within, point); + } else if (nameOwner instanceof ICPPClassTemplate) { + nameOwner = resolveUnknown(CPPTemplates.createDeferredInstance((ICPPClassTemplate) nameOwner), + tpMap, packOffset, within, point); } if (Arrays.equals(templateArgs, fTemplateArgs) && fieldOwner == fFieldOwner && nameOwner == fNameOwner) return this; @@ -316,6 +316,17 @@ public class EvalID extends CPPEvaluation { return new EvalID(fieldOwner, nameOwner, fName, fAddressOf, fQualified, templateArgs); } + IBinding resolveUnknown(IBinding binding, ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, IASTNode point) { + try { + binding = CPPTemplates.resolveUnknown((ICPPUnknownBinding) binding, tpMap, + packOffset, within, point); + } catch (DOMException e) { + CCorePlugin.log(e); + } + return binding; + } + private ICPPEvaluation resolveName(ICPPClassType nameOwner, ICPPTemplateArgument[] templateArgs, IASTNode point) { LookupData data = new LookupData(fName, templateArgs, point); From cb169419a6f5ce96da0e597ea399ef10145663ac Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 31 Jul 2012 20:01:29 -0700 Subject: [PATCH 12/31] Cosmetics. --- .../composite/cpp/CompositeCPPClassSpecialization.java | 7 +++---- .../index/composite/cpp/CompositeCPPClassType.java | 10 +++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java index aaf32627865..dc3851e7285 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Ferguson (Symbian) - Initial implementation - * Markus Schorn (Wind River Systems) + * Andrew Ferguson (Symbian) - Initial implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; @@ -37,8 +37,7 @@ import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; public class CompositeCPPClassSpecialization extends CompositeCPPClassType implements ICPPClassSpecialization { - - private ObjectMap specializationMap= null; + private ObjectMap specializationMap; private final ThreadLocal> fInProgress= new ThreadLocal>(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassType.java index f6a197b91f7..11e2cb9b8b5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassType.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Ferguson (Symbian) - Initial implementation - * Markus Schorn (Wind River Systems) + * Andrew Ferguson (Symbian) - Initial implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; @@ -65,7 +65,7 @@ class CompositeCPPClassType extends CompositeCPPBinding implements ICPPClassType if (baseClass != null) { return baseClass; } else { - return cf.getCompositeBinding((IIndexFragmentBinding)base.getBaseClass()); + return cf.getCompositeBinding((IIndexFragmentBinding) base.getBaseClass()); } } @@ -122,7 +122,7 @@ class CompositeCPPClassType extends CompositeCPPBinding implements ICPPClassType public ICPPField[] getDeclaredFields() { ICPPField[] result = ((ICPPClassType) rbinding).getDeclaredFields(); for (int i= 0; i < result.length; i++) { - result[i] = (ICPPField) cf.getCompositeBinding((IIndexFragmentBinding)result[i]); + result[i] = (ICPPField) cf.getCompositeBinding((IIndexFragmentBinding) result[i]); } return result; } @@ -131,7 +131,7 @@ class CompositeCPPClassType extends CompositeCPPBinding implements ICPPClassType public ICPPMethod[] getDeclaredMethods() { ICPPMethod[] result = ((ICPPClassType) rbinding).getDeclaredMethods(); for (int i= 0; i < result.length; i++) { - result[i]= (ICPPMethod) cf.getCompositeBinding((IIndexFragmentBinding)result[i]); + result[i]= (ICPPMethod) cf.getCompositeBinding((IIndexFragmentBinding) result[i]); } return result; } From 1a3652ec9b732db6ee63606713d9acedc9213346 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 31 Jul 2012 20:32:36 -0700 Subject: [PATCH 13/31] Bug 299911. Added ICPPClassSpecialization.getBases(IASTNode point) method to avoid loss of instantiation context. --- .../cdt/core/dom/ast/cpp/ICPPClassSpecialization.java | 7 +++++++ .../parser/cpp/AbstractCPPClassSpecializationScope.java | 3 +-- .../core/dom/parser/cpp/CPPClassSpecialization.java | 7 ++++++- .../dom/parser/cpp/ICPPClassSpecializationScope.java | 3 ++- .../core/dom/parser/cpp/semantics/BaseClassLookup.java | 7 ++++++- .../composite/cpp/CompositeCPPClassSpecialization.java | 7 ++++++- .../cpp/CompositeCPPClassSpecializationScope.java | 5 +++-- .../core/pdom/dom/cpp/PDOMCPPClassSpecialization.java | 9 +++++++-- 8 files changed, 38 insertions(+), 10 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java index b71a4e4aa15..8f77959f00b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java @@ -36,4 +36,11 @@ public interface ICPPClassSpecialization extends ICPPSpecialization, ICPPClassTy * @since 5.5 */ IBinding specializeMember(IBinding binding, IASTNode point); + + /** + * Similar to {@link ICPPClassType#getBases()} but a accepts a starting point for template + * instantiation. + * @since 5.5 + */ + public ICPPBase[] getBases(IASTNode point); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java index 560c545e08e..82af915cf26 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java @@ -124,14 +124,13 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat } @Override - public ICPPBase[] getBases() { + public ICPPBase[] getBases(IASTNode point) { if (fBases == null) { ICPPBase[] result = null; ICPPBase[] bases = specialClass.getSpecializedBinding().getBases(); if (bases.length == 0) { fBases= bases; } else { - IASTNode point= null; // Instantiation of dependent expression may not work. final ICPPTemplateParameterMap tpmap = specialClass.getTemplateParameterMap(); for (ICPPBase base : bases) { IBinding origClass = base.getBaseClass(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java index c1e5df4ee23..1f3c24d52f5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java @@ -122,11 +122,16 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPBase[] getBases() { + return getBases(null); + } + + @Override + public ICPPBase[] getBases(IASTNode point) { ICPPClassSpecializationScope scope= getSpecializationScope(); if (scope == null) return ClassTypeHelper.getBases(this); - return scope.getBases(); + return scope.getBases(point); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPClassSpecializationScope.java index 4dd8464e8fd..eb4bbffc704 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPClassSpecializationScope.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; @@ -39,7 +40,7 @@ public interface ICPPClassSpecializationScope extends ICPPClassScope { /** * Computes the bases via the original class. */ - ICPPBase[] getBases(); + ICPPBase[] getBases(IASTNode point); /** * Computes the methods via the original class. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java index 8579ae27553..def3ed540db 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java @@ -24,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; import org.eclipse.cdt.core.parser.util.ArrayUtil; @@ -182,7 +183,11 @@ class BaseClassLookup { ICPPClassType baseClass= result.getClassType(); if (baseClass != null) { ICPPBase[] grandBases= null; - grandBases= baseClass.getBases(); + if (baseClass instanceof ICPPClassSpecialization) { + grandBases = ((ICPPClassSpecialization) baseClass).getBases(data.getLookupPoint()); + } else { + grandBases= baseClass.getBases(); + } if (grandBases != null && grandBases.length > 0) { HashSet grandBaseBindings= null; BitSet selectedBases= null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java index dc3851e7285..618de5509f2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java @@ -129,9 +129,14 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple @Override public final ICPPBase[] getBases() { + return getBases(null); + } + + @Override + public final ICPPBase[] getBases(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getBases(); + return ((ICPPClassSpecializationScope) scope).getBases(point); } return super.getBases(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java index 4776ac8bdf6..671ba7884b8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.index.composite.cpp; import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; @@ -108,9 +109,9 @@ public class CompositeCPPClassSpecializationScope extends CompositeScope impleme } @Override - public ICPPBase[] getBases() { + public ICPPBase[] getBases(IASTNode point) { createDelegate(); - return fDelegate.getBases(); + return fDelegate.getBases(point); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java index d153b3fac5b..b3fea4a1fca 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java @@ -207,10 +207,15 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPBase[] getBases() { + return getBases(null); + } + + @Override + public ICPPBase[] getBases(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getBases(); - } + return ((ICPPClassSpecializationScope) scope).getBases(point); + } // This is an explicit specialization Long key= record + PDOMCPPLinkage.CACHE_BASES; From c1847dbc1581088298f96bf10f72b6042eaa368b Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 1 Aug 2012 19:01:51 -0700 Subject: [PATCH 14/31] Bug 299911. Fixed AST2TemplateTests.testDependentExpressions test. --- .../parser/tests/ast2/AST2TemplateTests.java | 2 +- .../core/dom/parser/SizeofCalculator.java | 5 +- .../parser/cpp/semantics/CPPEvaluation.java | 25 +++++ .../dom/parser/cpp/semantics/EvalBinary.java | 93 +++++++++++++------ .../dom/parser/cpp/semantics/EvalBinding.java | 20 ++-- .../cpp/semantics/EvalFunctionCall.java | 30 +++++- .../parser/cpp/semantics/EvalFunctionSet.java | 26 +++--- .../core/dom/parser/cpp/semantics/EvalID.java | 32 +++---- .../dom/parser/cpp/semantics/EvalUnary.java | 33 ++++++- .../parser/cpp/semantics/EvalUnaryTypeID.java | 14 +-- 10 files changed, 193 insertions(+), 87 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index c7e8539f991..10d8d03ec8d 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -5631,7 +5631,7 @@ public class AST2TemplateTests extends AST2BaseTest { // ns::C::value> a; // f(a); // }; - public void _testDependentExpressions() throws Exception { + public void testDependentExpressions() throws Exception { parseAndCheckBindings(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java index 52863030731..aa3ed3d9321 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java @@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IField; +import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; @@ -109,7 +110,9 @@ public class SizeofCalculator { */ public SizeAndAlignment sizeAndAlignment(IType type) { type = SemanticUtil.getNestedType(type, SemanticUtil.CVTYPE | SemanticUtil.TDEF); - + if (type instanceof IFunctionType) { + return sizeAndAlignment(((IFunctionType) type).getReturnType()); + } if (type instanceof IBasicType) { return sizeAndAlignment((IBasicType) type); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java index 57623407455..3faa3341be6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java @@ -12,12 +12,16 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; @@ -25,6 +29,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.core.runtime.CoreException; public abstract class CPPEvaluation implements ICPPEvaluation { @@ -219,4 +224,24 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } return buf.getSignature(); } + + protected static IBinding resolveUnknown(ICPPUnknownBinding unknown, ICPPTemplateParameterMap tpMap, + int packOffset, ICPPClassSpecialization within, IASTNode point) { + try { + return CPPTemplates.resolveUnknown(unknown, tpMap, packOffset, within, point); + } catch (DOMException e) { + CCorePlugin.log(e); + } + return unknown; + } + + protected static ICPPTemplateArgument[] instantiateArguments(ICPPTemplateArgument[] args, + ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, IASTNode point) { + try { + return CPPTemplates.instantiateArguments(args, tpMap, packOffset, within, point); + } catch (DOMException e) { + CCorePlugin.log(e); + } + return args; + } } \ No newline at end of file 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 911c8cc1062..625fe770542 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 @@ -11,6 +11,30 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_assign; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_binaryAnd; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_binaryAndAssign; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_binaryOrAssign; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_binaryXorAssign; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_divideAssign; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_equals; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_greaterEqual; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_greaterThan; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_lessEqual; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_lessThan; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_logicalAnd; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_logicalOr; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_minus; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_minusAssign; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_moduloAssign; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_multiplyAssign; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_notequals; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_plus; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_plusAssign; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_pmarrow; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_pmdot; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_shiftLeftAssign; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_shiftRightAssign; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.glvalueType; @@ -21,14 +45,12 @@ import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUti import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; -import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.ISemanticProblem; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; @@ -114,13 +136,18 @@ public class EvalBinary extends CPPEvaluation { } IValue v1 = fArg1.getValue(point); + if (v1 == Value.UNKNOWN) + return Value.UNKNOWN; IValue v2 = fArg2.getValue(point); + if (v2 == Value.UNKNOWN) + return Value.UNKNOWN; + switch (fOperator) { - case IASTBinaryExpression.op_equals: + case op_equals: if (v1.equals(v2)) return Value.create(1); break; - case IASTBinaryExpression.op_notequals: + case op_notequals: if (v1.equals(v2)) return Value.create(0); break; @@ -128,6 +155,12 @@ public class EvalBinary extends CPPEvaluation { Long num1 = v1.numericalValue(); if (num1 != null) { + if (num1 == 0) { + if (fOperator == op_binaryAnd || fOperator == op_logicalAnd) + return v1; + } else if (fOperator == op_logicalOr) { + return v1; + } Long num2 = v2.numericalValue(); if (num2 != null) { return Value.evaluateBinaryExpression(fOperator, num1, num2); @@ -160,25 +193,25 @@ public class EvalBinary extends CPPEvaluation { switch (fOperator) { case op_arrayAccess: - case IASTBinaryExpression.op_assign: - case IASTBinaryExpression.op_binaryAndAssign: - case IASTBinaryExpression.op_binaryOrAssign: - case IASTBinaryExpression.op_binaryXorAssign: - case IASTBinaryExpression.op_divideAssign: - case IASTBinaryExpression.op_minusAssign: - case IASTBinaryExpression.op_moduloAssign: - case IASTBinaryExpression.op_multiplyAssign: - case IASTBinaryExpression.op_plusAssign: - case IASTBinaryExpression.op_shiftLeftAssign: - case IASTBinaryExpression.op_shiftRightAssign: + case op_assign: + case op_binaryAndAssign: + case op_binaryOrAssign: + case op_binaryXorAssign: + case op_divideAssign: + case op_minusAssign: + case op_moduloAssign: + case op_multiplyAssign: + case op_plusAssign: + case op_shiftLeftAssign: + case op_shiftRightAssign: return LVALUE; - case IASTBinaryExpression.op_pmdot: + case op_pmdot: if (!(getTypeOrFunctionSet(point) instanceof ICPPFunctionType)) return fArg1.getValueCategory(point); break; - case IASTBinaryExpression.op_pmarrow: + case op_pmarrow: if (!(getTypeOrFunctionSet(point) instanceof ICPPFunctionType)) return LVALUE; break; @@ -246,17 +279,17 @@ public class EvalBinary extends CPPEvaluation { } return ProblemType.UNKNOWN_FOR_EXPRESSION; - case IASTBinaryExpression.op_lessEqual: - case IASTBinaryExpression.op_lessThan: - case IASTBinaryExpression.op_greaterEqual: - case IASTBinaryExpression.op_greaterThan: - case IASTBinaryExpression.op_logicalAnd: - case IASTBinaryExpression.op_logicalOr: - case IASTBinaryExpression.op_equals: - case IASTBinaryExpression.op_notequals: + case op_lessEqual: + case op_lessThan: + case op_greaterEqual: + case op_greaterThan: + case op_logicalAnd: + case op_logicalOr: + case op_equals: + case op_notequals: return CPPBasicType.BOOLEAN; - case IASTBinaryExpression.op_plus: + case op_plus: if (type1 instanceof IPointerType) { return ExpressionTypes.restoreTypedefs(type1, originalType1); } @@ -265,7 +298,7 @@ public class EvalBinary extends CPPEvaluation { } break; - case IASTBinaryExpression.op_minus: + case op_minus: if (type1 instanceof IPointerType) { if (type2 instanceof IPointerType) { return CPPVisitor.getPointerDiffType(point); @@ -274,13 +307,13 @@ public class EvalBinary extends CPPEvaluation { } break; - case ICPPASTBinaryExpression.op_pmarrow: - case ICPPASTBinaryExpression.op_pmdot: + case op_pmarrow: + case op_pmdot: if (type2 instanceof ICPPPointerToMemberType) { IType t= ((ICPPPointerToMemberType) type2).getType(); if (t instanceof ICPPFunctionType) return t; - if (fOperator == ICPPASTBinaryExpression.op_pmdot && fArg1.getValueCategory(point) == PRVALUE) { + if (fOperator == op_pmdot && fArg1.getValueCategory(point) == PRVALUE) { return prvalueType(t); } return glvalueType(t); 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 ee5b09c13c0..74788246143 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 @@ -14,8 +14,6 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.glvalueType; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueType; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -26,6 +24,8 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; @@ -86,7 +86,6 @@ public class EvalBinding extends CPPEvaluation { private boolean computeIsTypeDependent() { IType t= null; - // mstodo: Please review this change. if (fFixedType) { t = fType; } else if (fBinding instanceof IEnumerator) { @@ -230,11 +229,16 @@ public class EvalBinding extends CPPEvaluation { } // TODO(sprigogin): Do we need something similar for pack expansion? } else if (fBinding instanceof ICPPUnknownBinding) { - try { - binding = CPPTemplates.resolveUnknown((ICPPUnknownBinding) fBinding, tpMap, - packOffset, within, point); - } catch (DOMException e) { - CCorePlugin.log(e); + binding = resolveUnknown((ICPPUnknownBinding) fBinding, tpMap, packOffset, within, point); + } else if (fBinding instanceof ICPPMethod) { + IBinding owner = fBinding.getOwner(); + if (owner instanceof ICPPClassTemplate) { + owner = resolveUnknown(CPPTemplates.createDeferredInstance((ICPPClassTemplate) owner), + tpMap, packOffset, within, point); + } + if (owner instanceof ICPPClassSpecialization) { + binding = CPPTemplates.createSpecialization((ICPPClassSpecialization) owner, + fBinding, point); } } if (binding == fBinding) 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 f574db24ece..d7737ffc9e4 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 @@ -18,8 +18,13 @@ import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUti import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; +import java.util.Arrays; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.ISemanticProblem; @@ -48,6 +53,10 @@ public class EvalFunctionCall extends CPPEvaluation { fArguments= args; } + /** + * Returns arguments of the function call. The first argument is the function name, the rest + * are arguments passed to the function. + */ public ICPPEvaluation[] getArguments() { return fArguments; } @@ -135,10 +144,8 @@ public class EvalFunctionCall extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - if (isValueDependent()) - return Value.create(this); - // TODO(sprigogin): Simulate execution of a function call. - return Value.UNKNOWN; + // TODO(sprigogin): Simulate execution of a function call if the value is not dependent. + return Value.create(this); } @Override @@ -188,6 +195,21 @@ public class EvalFunctionCall extends CPPEvaluation { } if (!changed) return this; + + if (args[0] instanceof EvalFunctionSet) { + CPPFunctionSet functionSet = ((EvalFunctionSet) args[0]).getFunctionSet(); + ICPPFunction[] functions = functionSet.getBindings(); + LookupData data = new LookupData(functions[0].getNameCharArray(), + functionSet.getTemplateArguments(), point); + data.setFunctionArguments(false, Arrays.copyOfRange(args, 1, args.length)); + try { + IBinding binding = CPPSemantics.resolveFunction(data, functions, true); + if (binding instanceof ICPPFunction) + return new EvalBinding(binding, null); + } catch (DOMException e) { + CCorePlugin.log(e); + } + } return new EvalFunctionCall(args); } 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 d645aa6032b..47fc4b8a99e 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 @@ -15,8 +15,6 @@ import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; import java.util.Arrays; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -115,7 +113,10 @@ public class EvalFunctionSet extends CPPEvaluation { buffer.marshalBinding(binding); } if (args != null) { - // mstodo marshall arguments + buffer.putShort((short) args.length); + for (ICPPTemplateArgument arg : args) { + buffer.marshalTemplateArgument(arg); + } } } @@ -128,7 +129,11 @@ public class EvalFunctionSet extends CPPEvaluation { } ICPPTemplateArgument[] args= null; if ((firstByte & ITypeMarshalBuffer.FLAG2) != 0) { - // mstodo marshall arguments + int len= buffer.getShort(); + args = new ICPPTemplateArgument[len]; + for (int i = 0; i < args.length; i++) { + args[i]= buffer.unmarshalTemplateArgument(); + } } return new EvalFunctionSet(new CPPFunctionSet(bindings, args, null), addressOf); } @@ -138,21 +143,12 @@ public class EvalFunctionSet extends CPPEvaluation { ICPPClassSpecialization within, int maxdepth, IASTNode point) { ICPPTemplateArgument[] originalArguments = fFunctionSet.getTemplateArguments(); ICPPTemplateArgument[] arguments = originalArguments; - try { - arguments = CPPTemplates.instantiateArguments(originalArguments, tpMap, packOffset, within, point); - } catch (DOMException e) { - CCorePlugin.log(e); - } + arguments = instantiateArguments(originalArguments, tpMap, packOffset, within, point); IBinding originalOwner = fFunctionSet.getOwner(); IBinding owner = originalOwner; if (originalOwner instanceof ICPPUnknownBinding) { - try { - owner = CPPTemplates.resolveUnknown((ICPPUnknownBinding) owner, tpMap, - packOffset, within, point); - } catch (DOMException e) { - CCorePlugin.log(e); // TODO(sprigogin): Is this exception safe to ignore? - } + owner = resolveUnknown((ICPPUnknownBinding) owner, tpMap, packOffset, within, point); } else if (owner instanceof IType) { IType type = CPPTemplates.instantiateType((IType) owner, tpMap, packOffset, within, point); if (type instanceof IBinding) 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 3e5971d1a9c..206047da2f3 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 @@ -16,7 +16,6 @@ import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; import java.util.Arrays; -import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; @@ -40,6 +39,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; @@ -132,6 +132,7 @@ public class EvalID extends CPPEvaluation { if (nameOwner == null && fFieldOwner != null) nameOwner = (IBinding) fFieldOwner.getTypeOrFunctionSet(point); + // TODO(sprigogin): Verify that name resolution is required here. if (nameOwner instanceof ICPPClassType) { ICPPEvaluation eval = resolveName((ICPPClassType) nameOwner, fTemplateArgs, point); if (eval != null) @@ -281,11 +282,7 @@ public class EvalID extends CPPEvaluation { ICPPClassSpecialization within, int maxdepth, IASTNode point) { ICPPTemplateArgument[] templateArgs = fTemplateArgs; if (templateArgs != null) { - try { - templateArgs = CPPTemplates.instantiateArguments(templateArgs, tpMap, packOffset, within, point); - } catch (DOMException e) { - CCorePlugin.log(e); - } + templateArgs = instantiateArguments(templateArgs, tpMap, packOffset, within, point); } ICPPEvaluation fieldOwner = fFieldOwner; @@ -302,7 +299,7 @@ public class EvalID extends CPPEvaluation { nameOwner = (IBinding) type; } } else if (nameOwner instanceof ICPPUnknownBinding) { - nameOwner = resolveUnknown(nameOwner, tpMap, packOffset, within, point); + nameOwner = resolveUnknown((ICPPUnknownBinding) nameOwner, tpMap, packOffset, within, point); } else if (nameOwner instanceof ICPPClassTemplate) { nameOwner = resolveUnknown(CPPTemplates.createDeferredInstance((ICPPClassTemplate) nameOwner), tpMap, packOffset, within, point); @@ -310,23 +307,13 @@ public class EvalID extends CPPEvaluation { if (Arrays.equals(templateArgs, fTemplateArgs) && fieldOwner == fFieldOwner && nameOwner == fNameOwner) return this; - // We don't do name lookup here since it is going to happen anyway when the getValue method - // is called. + ICPPEvaluation eval = resolveName((ICPPClassType) nameOwner, fTemplateArgs, point); + if (eval != null) + return eval; return new EvalID(fieldOwner, nameOwner, fName, fAddressOf, fQualified, templateArgs); } - IBinding resolveUnknown(IBinding binding, ICPPTemplateParameterMap tpMap, int packOffset, - ICPPClassSpecialization within, IASTNode point) { - try { - binding = CPPTemplates.resolveUnknown((ICPPUnknownBinding) binding, tpMap, - packOffset, within, point); - } catch (DOMException e) { - CCorePlugin.log(e); - } - return binding; - } - private ICPPEvaluation resolveName(ICPPClassType nameOwner, ICPPTemplateArgument[] templateArgs, IASTNode point) { LookupData data = new LookupData(fName, templateArgs, point); @@ -336,6 +323,11 @@ public class EvalID extends CPPEvaluation { } catch (DOMException e) { } IBinding[] bindings = data.getFoundBindings(); + if (bindings.length > 1 && bindings[0] instanceof ICPPFunction) { + ICPPFunction[] functions = new ICPPFunction[bindings.length]; + System.arraycopy(bindings, 0, functions, 0, bindings.length); + return new EvalFunctionSet(new CPPFunctionSet(functions, fTemplateArgs, null), fAddressOf); + } IBinding binding = bindings.length == 1 ? bindings[0] : null; if (binding instanceof IEnumerator) { return new EvalBinding(binding, 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 ab728bf6462..17017f2770a 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 @@ -38,7 +38,6 @@ import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUti import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.ISemanticProblem; import org.eclipse.cdt.core.dom.ast.IType; @@ -49,6 +48,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; +import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator; +import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPArithmeticConversion; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; @@ -144,7 +145,7 @@ public class EvalUnary extends CPPEvaluation { return null; ICPPEvaluation[] args; - if (fOperator == IASTUnaryExpression.op_postFixDecr || fOperator == IASTUnaryExpression.op_postFixIncr) { + if (fOperator == op_postFixDecr || fOperator == op_postFixIncr) { args = new ICPPEvaluation[] { fArgument, ZERO_EVAL }; } else { args = new ICPPEvaluation[] { fArgument }; @@ -205,11 +206,31 @@ public class EvalUnary extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { + if (isValueDependent()) + return Value.create(this); + if (getOverload(point) != null) { // TODO(sprigogin): Simulate execution of a function call. return Value.create(this); } + switch (fOperator) { + case op_sizeof: { + SizeAndAlignment info = getSizeAndAlignment(point); + return info == null ? Value.UNKNOWN : Value.create(info.size); + } + case op_alignOf: { + SizeAndAlignment info = getSizeAndAlignment(point); + return info == null ? Value.UNKNOWN : Value.create(info.alignment); + } + case op_sizeofParameterPack: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_typeid: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_throw: + return Value.UNKNOWN; // TODO(sprigogin): Implement + } + IValue val = fArgument.getValue(point); Long num = val.numericalValue(); if (num != null) { @@ -218,6 +239,14 @@ public class EvalUnary extends CPPEvaluation { return Value.create(this); } + private SizeAndAlignment getSizeAndAlignment(IASTNode point) { + if (point == null) + return null; + + IType type = fArgument.getTypeOrFunctionSet(point); + return new SizeofCalculator(point.getTranslationUnit()).sizeAndAlignment(type); + } + @Override public ValueCategory getValueCategory(IASTNode point) { ICPPFunction overload = getOverload(point); 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 993b032ded9..e7e97cc5c12 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 @@ -157,15 +157,11 @@ public class EvalUnaryTypeID extends CPPEvaluation { switch (fOperator) { case op_sizeof: { - if (point == null) - return Value.UNKNOWN; - SizeAndAlignment info = new SizeofCalculator(point.getTranslationUnit()).sizeAndAlignment(fOrigType); + SizeAndAlignment info = getSizeAndAlignment(point); return info == null ? Value.UNKNOWN : Value.create(info.size); } case op_alignof: { - if (point == null) - return Value.UNKNOWN; - SizeAndAlignment info = new SizeofCalculator(point.getTranslationUnit()).sizeAndAlignment(fOrigType); + SizeAndAlignment info = getSizeAndAlignment(point); return info == null ? Value.UNKNOWN : Value.create(info.alignment); } case op_typeid: @@ -204,6 +200,12 @@ public class EvalUnaryTypeID extends CPPEvaluation { return Value.create(this); } + private SizeAndAlignment getSizeAndAlignment(IASTNode point) { + if (point == null) + return null; + return new SizeofCalculator(point.getTranslationUnit()).sizeAndAlignment(fOrigType); + } + @Override public ValueCategory getValueCategory(IASTNode point) { return fOperator == op_typeid ? LVALUE : PRVALUE; From f63c39ef9603c644402126f3739c7caaa0f4e1b9 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 1 Aug 2012 19:15:48 -0700 Subject: [PATCH 15/31] Bug 299911. Removed redundant name lookup. --- .../core/dom/parser/cpp/semantics/EvalID.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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 206047da2f3..da50a23c01e 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 @@ -128,16 +128,16 @@ public class EvalID extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - IBinding nameOwner = fNameOwner; - if (nameOwner == null && fFieldOwner != null) - nameOwner = (IBinding) fFieldOwner.getTypeOrFunctionSet(point); - - // TODO(sprigogin): Verify that name resolution is required here. - if (nameOwner instanceof ICPPClassType) { - ICPPEvaluation eval = resolveName((ICPPClassType) nameOwner, fTemplateArgs, point); - if (eval != null) - return eval.getValue(point); - } + // Name lookup is not needed here because it was already done in "instantiate" method. +// IBinding nameOwner = fNameOwner; +// if (nameOwner == null && fFieldOwner != null) +// nameOwner = (IBinding) fFieldOwner.getTypeOrFunctionSet(point); +// +// if (nameOwner instanceof ICPPClassType) { +// ICPPEvaluation eval = resolveName((ICPPClassType) nameOwner, fTemplateArgs, point); +// if (eval != null) +// return eval.getValue(point); +// } return Value.create(this); } From 07407b55e8b9837baf5f34ceebf929eb3c89c3f3 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 1 Aug 2012 19:58:48 -0700 Subject: [PATCH 16/31] Bug 299911. Minor fix. --- .../cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 625fe770542..7eb375ebeb2 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 @@ -12,7 +12,6 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_assign; -import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_binaryAnd; import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_binaryAndAssign; import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_binaryOrAssign; import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_binaryXorAssign; @@ -156,7 +155,7 @@ public class EvalBinary extends CPPEvaluation { Long num1 = v1.numericalValue(); if (num1 != null) { if (num1 == 0) { - if (fOperator == op_binaryAnd || fOperator == op_logicalAnd) + if (fOperator == op_logicalAnd) return v1; } else if (fOperator == op_logicalOr) { return v1; From 202f1d095e34e5f93761c1aa47fa0568ad9b075b Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Fri, 3 Aug 2012 15:22:22 -0700 Subject: [PATCH 17/31] Cosmetics. --- .../cdt/core/dom/ast/cpp/ICPPClassScope.java | 9 +++------ .../cdt/core/dom/ast/cpp/ICPPClassType.java | 5 ++--- .../parser/cpp/CPPClassSpecializationScope.java | 8 ++++---- .../core/dom/parser/cpp/ICPPUnknownBinding.java | 2 +- .../dom/parser/cpp/ICPPUnknownClassInstance.java | 4 ++-- .../parser/cpp/semantics/BuiltinOperators.java | 11 +++++------ .../dom/parser/cpp/semantics/CVQualifier.java | 16 +++++++++------- 7 files changed, 26 insertions(+), 29 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassScope.java index 6938527c524..ef7b553a89c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassScope.java @@ -6,12 +6,11 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Niefer (IBM Corporation) - initial API and implementation - * Markus Schorn (Wind River Systems) + * Andrew Niefer (IBM Corporation) - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; - /** * Interface for class scopes. * @@ -20,8 +19,7 @@ package org.eclipse.cdt.core.dom.ast.cpp; */ public interface ICPPClassScope extends ICPPScope { /** - * Get the binding for the class this scope is associated with - * + * Returns the binding for the class this scope is associated with. */ ICPPClassType getClassType(); @@ -30,7 +28,6 @@ public interface ICPPClassScope extends ICPPScope { * scope. These methods may or may not have been explicitly declared in the * code. The methods that will be implicitly declared are: the default * constructor, copy constructor, copy assignment operator, and destructor - * */ public ICPPMethod[] getImplicitMethods(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassType.java index 633387a65c3..1fc4b2daffa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassType.java @@ -86,18 +86,17 @@ public interface ICPPClassType extends ICompositeType, ICPPBinding { * Returns an array of ICPPConstructor objects representing the constructors * for this class. This list includes both declared and implicit * constructors. - * */ public ICPPConstructor[] getConstructors(); /** - * return an array of bindings for those classes/functions declared as + * Returns an array of bindings for those classes/functions declared as * friends of this class. */ public IBinding[] getFriends(); /** - * return an array of nested classes/structures + * Returns an array of nested classes/structures */ public ICPPClassType[] getNestedClasses(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java index b03b19a2dd8..e3f11c51f09 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java @@ -6,10 +6,10 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Niefer (IBM) - Initial API and implementation - * Markus Schorn (Wind River Systems) - * Bryan Wilkinson (QNX) - * Andrew Ferguson (Symbian) + * Andrew Niefer (IBM) - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Bryan Wilkinson (QNX) + * Andrew Ferguson (Symbian) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownBinding.java index af26b8dd21e..4d41e4df2f0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownBinding.java @@ -6,7 +6,7 @@ * 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; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownClassInstance.java index 2ec1d50f377..daef1004737 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownClassInstance.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Sergey Prigogin (Google) - initial API and implementation - * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BuiltinOperators.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BuiltinOperators.java index 228047b9233..5cc74b55ef7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BuiltinOperators.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BuiltinOperators.java @@ -10,7 +10,10 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.*; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.ALLCVQ; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; import java.util.ArrayList; import java.util.HashSet; @@ -80,7 +83,7 @@ class BuiltinOperators { Object[] globCandidates) { fFileScope= point.getTranslationUnit().getScope(); fOperator= operator; - fUnary= args.length<2; + fUnary= args.length < 2; fGlobalCandidates= globCandidates; if (args.length > 0) { IType type= args[0].getTypeOrFunctionSet(point); @@ -95,7 +98,6 @@ class BuiltinOperators { } } - private ICPPFunction[] create() { switch (fOperator) { case ARROW: @@ -231,8 +233,6 @@ class BuiltinOperators { return fResult.toArray(new ICPPFunction[fResult.size()]); } - - // 13.6-3, 13.6-4, 13.6-5 private void opIncOrDec() { IType[] types= getClassConversionTypes(FIRST); @@ -424,7 +424,6 @@ class BuiltinOperators { return p1; } - // 13.6-13, 13.6.14 private void pointerArithmetic(boolean useRef, boolean isDiff) { IType[] types= getClassConversionTypes(FIRST); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CVQualifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CVQualifier.java index cd3f8035b3b..76b0fbaa3fd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CVQualifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CVQualifier.java @@ -6,11 +6,10 @@ * 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; - /** * Represents the possible cv-qualification of a type. */ @@ -23,16 +22,19 @@ public enum CVQualifier { private static final int R = 4; final private int fQualifiers; + private CVQualifier(int qualifiers) { fQualifiers= qualifiers; } - + public boolean isConst() { return (fQualifiers & C) != 0; } + public boolean isVolatile() { return (fQualifiers & V) != 0; } + public boolean isRestrict() { return (fQualifiers & R) != 0; } @@ -54,7 +56,7 @@ public enum CVQualifier { } private CVQualifier fromQualifier(final int q) { - switch(q) { + switch (q) { case C|V|R: return CONST_VOLATILE_RESTRICT; case V|R: return VOLATILE_RESTRICT; case C|R: return CONST_RESTRICT; @@ -65,7 +67,7 @@ public enum CVQualifier { case 0: default: return NONE; } } - + /** * [3.9.3-4] Implements cv-qualification (partial) comparison. There is a (partial) * ordering on cv-qualifiers, so that a type can be said to be more @@ -83,12 +85,12 @@ public enum CVQualifier { * */ public int partialComparison(CVQualifier cv2) { - // same qualifications + // Same qualifications. if (this == cv2) return 0; if (!isAtLeastAsQualifiedAs(cv2)) return -1; - return fQualifiers-cv2.fQualifiers; + return fQualifiers - cv2.fQualifiers; } } From c74cc8a309084c1aaee128b750eeefd834b3f550 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Fri, 3 Aug 2012 15:35:06 -0700 Subject: [PATCH 18/31] Bug 299911. Improved propagation of name lookup context. --- .../parser/tests/ast2/SemanticsTests.java | 2 +- .../dom/ast/cpp/ICPPClassSpecialization.java | 40 +++++++- .../AbstractCPPClassSpecializationScope.java | 34 ++++--- .../CPPASTConstructorChainInitializer.java | 3 +- .../dom/parser/cpp/CPPASTQualifiedName.java | 6 +- .../parser/cpp/CPPClassSpecialization.java | 37 ++++++-- .../cpp/ICPPClassSpecializationScope.java | 26 ++++-- .../parser/cpp/semantics/BaseClassLookup.java | 8 +- .../cpp/semantics/BuiltinOperators.java | 8 +- .../parser/cpp/semantics/CPPEvaluation.java | 7 ++ .../parser/cpp/semantics/CPPSemantics.java | 45 ++++----- .../parser/cpp/semantics/CPPTemplates.java | 2 +- .../dom/parser/cpp/semantics/CPPVisitor.java | 12 ++- .../dom/parser/cpp/semantics/Conversions.java | 91 ++++++++++--------- .../core/dom/parser/cpp/semantics/Cost.java | 12 +-- .../parser/cpp/semantics/EvalConditional.java | 4 +- .../core/dom/parser/cpp/semantics/EvalID.java | 3 + .../dom/parser/cpp/semantics/EvalUnary.java | 13 +-- .../parser/cpp/semantics/EvalUnaryTypeID.java | 11 +-- .../parser/cpp/semantics/FunctionCost.java | 16 ++-- .../parser/cpp/semantics/SemanticUtil.java | 69 +++++++++++--- .../cpp/CompositeCPPClassSpecialization.java | 39 ++++++-- .../CompositeCPPClassSpecializationScope.java | 30 ++++-- .../dom/cpp/PDOMCPPClassSpecialization.java | 40 ++++++-- 24 files changed, 369 insertions(+), 189 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticsTests.java index 760aedb62bc..e4d259c68bc 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticsTests.java @@ -90,7 +90,7 @@ public class SemanticsTests extends AST2BaseTest { // Test getDeclaredConversionOperators() BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); ICPPClassType c= ba.assertNonProblem("X {", 1, ICPPClassType.class); - ICPPMethod[] cops= SemanticUtil.getDeclaredConversionOperators(c); + ICPPMethod[] cops= SemanticUtil.getDeclaredConversionOperators(c, null); assertEquals(2, cops.length); Set actual= new HashSet(); actual.add(cops[0].getName()); actual.add(cops[1].getName()); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java index 8f77959f00b..229697cb7d8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 Wind River Systems, Inc. and others. + * Copyright (c) 2008, 2012 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; @@ -42,5 +43,40 @@ public interface ICPPClassSpecialization extends ICPPSpecialization, ICPPClassTy * instantiation. * @since 5.5 */ - public ICPPBase[] getBases(IASTNode point); + ICPPBase[] getBases(IASTNode point); + + /** + * Similar to {@link ICPPClassType#getConstructors()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + ICPPConstructor[] getConstructors(IASTNode point); + + /** + * Similar to {@link ICPPClassType#getDeclaredFields()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + ICPPField[] getDeclaredFields(IASTNode point); + + /** + * Similar to {@link ICPPClassType#getDeclaredMethods()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + ICPPMethod[] getDeclaredMethods(IASTNode point); + + /** + * Similar to {@link ICPPClassType#getFriends()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + IBinding[] getFriends(IASTNode point); + + /** + * Similar to {@link ICPPClassType#getNestedClasses()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + ICPPClassType[] getNestedClasses(IASTNode point); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java index 82af915cf26..0c02d4274c4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2011 IBM Corporation and others. + * Copyright (c) 2005, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,6 +10,7 @@ * Markus Schorn (Wind River Systems) * Bryan Wilkinson (QNX) * Andrew Ferguson (Symbian) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -181,15 +182,18 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat } @Override - public ICPPField[] getDeclaredFields() { - IASTNode point= null; // Instantiation of dependent expression may not work. + public ICPPField[] getDeclaredFields(IASTNode point) { ICPPField[] fields= specialClass.getSpecializedBinding().getDeclaredFields(); return specializeMembers(fields, point); } - + @Override public ICPPMethod[] getImplicitMethods() { - IASTNode point= null; // Instantiation of dependent expression may not work. + return getImplicitMethods(null); // Instantiation of dependent expression may not work. + } + + @Override + public ICPPMethod[] getImplicitMethods(IASTNode point) { ICPPClassScope origClassScope= (ICPPClassScope) specialClass.getSpecializedBinding().getCompositeScope(); if (origClassScope == null) { return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; @@ -207,29 +211,29 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat @Override public ICPPConstructor[] getConstructors() { - // mstodo need to pass the point of instantiation - IASTNode point= null; // Instantiation of dependent expression may not work. - ICPPConstructor[] ctors= specialClass.getSpecializedBinding().getConstructors(); - return specializeMembers(ctors, point); + return getConstructors(null); // Instantiation of dependent expression may not work. } @Override - public ICPPMethod[] getDeclaredMethods() { - IASTNode point= null; // Instantiation of dependent expression may not work. + public ICPPConstructor[] getConstructors(IASTNode point) { + ICPPConstructor[] ctors= specialClass.getSpecializedBinding().getConstructors(); + return specializeMembers(ctors, point); + } + + @Override + public ICPPMethod[] getDeclaredMethods(IASTNode point) { ICPPMethod[] bindings = specialClass.getSpecializedBinding().getDeclaredMethods(); return specializeMembers(bindings, point); } @Override - public ICPPClassType[] getNestedClasses() { - IASTNode point= null; // Instantiation of dependent expression may not work. + public ICPPClassType[] getNestedClasses(IASTNode point) { ICPPClassType[] bindings = specialClass.getSpecializedBinding().getNestedClasses(); return specializeMembers(bindings, point); } @Override - public IBinding[] getFriends() { - IASTNode point= null; // Instantiation of dependent expression may not work. + public IBinding[] getFriends(IASTNode point) { IBinding[] friends = specialClass.getSpecializedBinding().getFriends(); return specializeMembers(friends, point); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java index a07965123db..bc482f514c9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java @@ -35,6 +35,7 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArraySet; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; /** * For example in the constructor definition
@@ -174,7 +175,7 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements IBinding method= fdef.getDeclarator().getName().resolveBinding(); if (method instanceof ICPPMethod) { ICPPClassType cls= ((ICPPMethod) method).getClassOwner(); - for (ICPPBase base : cls.getBases()) { + for (ICPPBase base : SemanticUtil.getBases(cls, fdef)) { result.put(base.getBaseClassSpecifierName().getSimpleID()); } return result; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java index 68a6a9938aa..5c7e349989a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java @@ -271,14 +271,14 @@ public class CPPASTQualifiedName extends CPPASTNameBase IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces); if (namesPos > 0) { - IBinding binding = names[namesPos-1].resolveBinding(); + IBinding binding = names[namesPos - 1].resolveBinding(); if (binding instanceof ICPPClassType) { ICPPClassType classType = (ICPPClassType) binding; final boolean isDeclaration = getParent().getParent() instanceof IASTSimpleDeclaration; List filtered = filterClassScopeBindings(classType, bindings, isDeclaration); if (isDeclaration && nameMatches(classType.getNameCharArray(), n.getLookupKey(), isPrefix)) { - ICPPConstructor[] constructors = classType.getConstructors(); + ICPPConstructor[] constructors = SemanticUtil.getConstructors(classType, n); for (int i = 0; i < constructors.length; i++) { if (!constructors[i].isImplicit()) { filtered.add(constructors[i]); @@ -303,7 +303,7 @@ public class CPPASTQualifiedName extends CPPASTNameBase while(scope != null) { if (scope instanceof ICPPClassScope) { ICPPClassType classType = ((ICPPClassScope) scope).getClassType(); - if (SemanticUtil.calculateInheritanceDepth(classType, baseClass) >= 0) { + if (SemanticUtil.calculateInheritanceDepth(classType, baseClass, this) >= 0) { return true; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java index 1f3c24d52f5..1d6cea256da 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java @@ -136,47 +136,72 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPField[] getDeclaredFields() { + return getDeclaredFields(null); // Instantiation of dependent expression may not work. + } + + @Override + public ICPPField[] getDeclaredFields(IASTNode point) { ICPPClassSpecializationScope scope= getSpecializationScope(); if (scope == null) return ClassTypeHelper.getDeclaredFields(this); - return scope.getDeclaredFields(); + return scope.getDeclaredFields(point); } @Override public ICPPMethod[] getDeclaredMethods() { + return getDeclaredMethods(null); // Instantiation of dependent expression may not work. + } + + @Override + public ICPPMethod[] getDeclaredMethods(IASTNode point) { ICPPClassSpecializationScope scope= getSpecializationScope(); if (scope == null) return ClassTypeHelper.getDeclaredMethods(this); - return scope.getDeclaredMethods(); + return scope.getDeclaredMethods(point); } @Override public ICPPConstructor[] getConstructors() { + return getConstructors(null); + } + + @Override + public ICPPConstructor[] getConstructors(IASTNode point) { ICPPClassSpecializationScope scope= getSpecializationScope(); if (scope == null) return ClassTypeHelper.getConstructors(this); - return scope.getConstructors(); + return scope.getConstructors(point); } @Override public IBinding[] getFriends() { + return getFriends(null); // Instantiation of dependent expression may not work. + } + + @Override + public IBinding[] getFriends(IASTNode point) { ICPPClassSpecializationScope scope= getSpecializationScope(); if (scope == null) return ClassTypeHelper.getFriends(this); - return scope.getFriends(); + return scope.getFriends(point); } @Override public ICPPClassType[] getNestedClasses() { + return getNestedClasses(null); // Instantiation of dependent expression may not work. + } + + @Override + public ICPPClassType[] getNestedClasses(IASTNode point) { ICPPClassSpecializationScope scope= getSpecializationScope(); if (scope == null) return ClassTypeHelper.getNestedClasses(this); - return scope.getNestedClasses(); + return scope.getNestedClasses(point); } @Override @@ -231,7 +256,7 @@ public class CPPClassSpecialization extends CPPSpecialization if (getDefinition() != null) return null; - //implicit specialization: must specialize bindings in scope + // Implicit specialization: must specialize bindings in scope. if (specScope == null) { specScope = new CPPClassSpecializationScope(this); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPClassSpecializationScope.java index eb4bbffc704..55da58c8586 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPClassSpecializationScope.java @@ -1,12 +1,13 @@ /******************************************************************************* - * Copyright (c) 2008, 2010 Wind River Systems, Inc. and others. + * Copyright (c) 2008, 2012 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -16,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; @@ -42,23 +44,35 @@ public interface ICPPClassSpecializationScope extends ICPPClassScope { */ ICPPBase[] getBases(IASTNode point); + /** + * Similar to {@link ICPPClassScope#getConstructors()} but a accepts a starting point + * for template instantiation. + */ + ICPPConstructor[] getConstructors(IASTNode point); + + /** + * Similar to {@link ICPPClassScope#getImplicitMethods()} but a accepts a starting point + * for template instantiation. + */ + ICPPMethod[] getImplicitMethods(IASTNode point); + /** * Computes the methods via the original class. */ - ICPPMethod[] getDeclaredMethods(); + ICPPMethod[] getDeclaredMethods(IASTNode point); /** * Computes the fields via the original class. */ - ICPPField[] getDeclaredFields(); + ICPPField[] getDeclaredFields(IASTNode point); /** * Computes the friends via the original class. */ - IBinding[] getFriends(); + IBinding[] getFriends(IASTNode point); /** * Computes the nested classes via the original class. */ - ICPPClassType[] getNestedClasses(); + ICPPClassType[] getNestedClasses(IASTNode point); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java index def3ed540db..d8de2c8590d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java @@ -24,7 +24,6 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; import org.eclipse.cdt.core.parser.util.ArrayUtil; @@ -182,12 +181,7 @@ class BaseClassLookup { // base-classes ICPPClassType baseClass= result.getClassType(); if (baseClass != null) { - ICPPBase[] grandBases= null; - if (baseClass instanceof ICPPClassSpecialization) { - grandBases = ((ICPPClassSpecialization) baseClass).getBases(data.getLookupPoint()); - } else { - grandBases= baseClass.getBases(); - } + ICPPBase[] grandBases= SemanticUtil.getBases(baseClass, data.getLookupPoint()); if (grandBases != null && grandBases.length > 0) { HashSet grandBaseBindings= null; BitSet selectedBases= null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BuiltinOperators.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BuiltinOperators.java index 5cc74b55ef7..4032094ee4b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BuiltinOperators.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BuiltinOperators.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 Wind River Systems, Inc. and others. + * Copyright (c) 2010, 2012 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -70,6 +70,7 @@ class BuiltinOperators { private final OverloadableOperator fOperator; private final boolean fUnary; + private final IASTNode fPoint; private IType fType1; private IType fType2; private IType[][] fClassConversionTypes= { null, null }; @@ -83,6 +84,7 @@ class BuiltinOperators { Object[] globCandidates) { fFileScope= point.getTranslationUnit().getScope(); fOperator= operator; + fPoint = point; fUnary= args.length < 2; fGlobalCandidates= globCandidates; if (args.length > 0) { @@ -355,7 +357,7 @@ class BuiltinOperators { IType t2= SemanticUtil.getNestedType(memPtr.getMemberOfClass(), TDEF); if (t2 instanceof ICPPClassType) { ICPPClassType c2= (ICPPClassType) t2; - if (SemanticUtil.calculateInheritanceDepth(c1, c2) >= 0) { + if (SemanticUtil.calculateInheritanceDepth(c1, c2, fPoint) >= 0) { IType cvt= SemanticUtil.getNestedType(memPtr.getType(), TDEF); IType rt= new CPPReferenceType( SemanticUtil.addQualifiers(cvt, cv1.isConst(), cv1.isVolatile(), cv1.isRestrict()), false); @@ -664,7 +666,7 @@ class BuiltinOperators { if (type instanceof ICPPClassType) { fIsClass[idx]= true; try { - ICPPMethod[] ops = SemanticUtil.getConversionOperators((ICPPClassType) type); + ICPPMethod[] ops = SemanticUtil.getConversionOperators((ICPPClassType) type, fPoint); result= new IType[ops.length]; int j= -1; for (ICPPMethod op : ops) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java index 3faa3341be6..45edc144710 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java @@ -23,9 +23,11 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.core.parser.util.CharArrayUtils; +import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; @@ -244,4 +246,9 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } return args; } + + protected static SizeAndAlignment getSizeAndAlignment(IType type, IASTNode point) { + ASTTranslationUnit ast = (ASTTranslationUnit) point.getTranslationUnit(); + return ast.getSizeofCalculator().sizeAndAlignment(type); + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index ed466a91df0..f2d1602f903 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -244,7 +244,7 @@ public class CPPSemantics { public static int traceIndent= 0; // special return value for costForFunctionCall - private static final FunctionCost CONTAINS_DEPENDENT_TYPES = new FunctionCost(null, 0); + private static final FunctionCost CONTAINS_DEPENDENT_TYPES = new FunctionCost(null, 0, null); static protected IBinding resolveBinding(IASTName name) { if (traceBindingResolution) { @@ -257,11 +257,11 @@ public class CPPSemantics { ((CPPASTNameBase) name).incResolutionDepth(); } - // 1: get some context info off of the name to figure out what kind of lookup we want + // 1: Get some context info off of the name to figure out what kind of lookup we want LookupData data = createLookupData(name); try { - // 2: lookup + // 2: Lookup lookup(data, null); // Perform argument dependent lookup @@ -274,14 +274,14 @@ public class CPPSemantics { if (data.problem != null) return data.problem; - // 3: resolve ambiguities + // 3: Resolve ambiguities IBinding binding; try { binding = resolveAmbiguities(data); } catch (DOMException e) { binding = e.getProblem(); } - // 4: post processing + // 4: Post processing binding = postResolution(binding, data); if (traceBindingResolution) { traceIndent--; @@ -306,6 +306,8 @@ public class CPPSemantics { if (lookupName == null) return binding; + IASTNode lookupPoint = data.getLookupPoint(); + if (binding == null && data.checkClassContainingFriend()) { // 3.4.1-10 if we don't find a name used in a friend declaration in the member declaration's class // we should look in the class granting friendship @@ -403,7 +405,7 @@ public class CPPSemantics { if (data.getTranslationUnit() != null) { ICPPASTTemplateId id = (ICPPASTTemplateId) lookupName; ICPPTemplateArgument[] args = CPPTemplates.createTemplateArgumentArray(id); - IBinding inst= CPPTemplates.instantiate((ICPPClassTemplate) cls, args, data.getLookupPoint()); + IBinding inst= CPPTemplates.instantiate((ICPPClassTemplate) cls, args, lookupPoint); if (inst instanceof ICPPClassType) { cls= (ICPPClassType) inst; } @@ -412,7 +414,7 @@ public class CPPSemantics { if (cls instanceof ICPPUnknownBinding) { binding= new CPPUnknownConstructor(cls); } else { - binding= CPPSemantics.resolveFunction(data, cls.getConstructors(), true); + binding= CPPSemantics.resolveFunction(data, SemanticUtil.getConstructors(cls, lookupPoint), true); } } catch (DOMException e) { return e.getProblem(); @@ -712,7 +714,7 @@ public class CPPSemantics { } if (t instanceof ICPPClassType && !(t instanceof ICPPClassTemplate)) { ICPPClassType ct= (ICPPClassType) t; - ICPPBase[] bases = ct.getBases(); + ICPPBase[] bases = SemanticUtil.getBases(ct, tu); for (ICPPBase base : bases) { IBinding b = base.getBaseClass(); if (b instanceof IType) @@ -2413,7 +2415,7 @@ public class CPPSemantics { potentialCosts.add(fnCost); continue; } - int cmp= fnCost.compareTo(tu, bestFnCost, lookupPoint); + int cmp= fnCost.compareTo(tu, bestFnCost); if (cmp < 0) { bestFnCost= fnCost; ambiguousFunctions= null; @@ -2425,7 +2427,7 @@ public class CPPSemantics { if (potentialCosts != null) { for (FunctionCost fnCost : potentialCosts) { if (!fnCost.mustBeWorse(bestFnCost) && fnCost.performUDC(lookupPoint)) { - int cmp= fnCost.compareTo(tu, bestFnCost, lookupPoint); + int cmp= fnCost.compareTo(tu, bestFnCost); if (cmp < 0) { bestFnCost= fnCost; ambiguousFunctions= null; @@ -2630,9 +2632,9 @@ public class CPPSemantics { final int sourceLen= argTypes.length - skipArg; final FunctionCost result; if (implicitParameterType == null) { - result= new FunctionCost(fn, sourceLen); + result= new FunctionCost(fn, sourceLen, data.getLookupPoint()); } else { - result= new FunctionCost(fn, sourceLen + 1); + result= new FunctionCost(fn, sourceLen + 1, data.getLookupPoint()); ValueCategory sourceIsLValue= LVALUE; if (impliedObjectType == null) { @@ -2656,7 +2658,7 @@ public class CPPSemantics { if (CPPTemplates.isDependentType(implicitParameterType) || CPPTemplates.isDependentType(impliedObjectType)) { IType s= getNestedType(impliedObjectType, TDEF|REF|CVTYPE); IType t= getNestedType(implicitParameterType, TDEF|REF|CVTYPE); - if (SemanticUtil.calculateInheritanceDepth(s, t) >= 0) + if (SemanticUtil.calculateInheritanceDepth(s, t, data.getLookupPoint()) >= 0) return null; return CONTAINS_DEPENDENT_TYPES; @@ -2671,7 +2673,7 @@ public class CPPSemantics { final UDCMode udc = allowUDC ? UDCMode.DEFER : UDCMode.FORBIDDEN; for (int j = 0; j < sourceLen; j++) { - final IType argType= SemanticUtil.getNestedType(argTypes[j+skipArg], TDEF | REF); + final IType argType= SemanticUtil.getNestedType(argTypes[j + skipArg], TDEF | REF); if (argType == null) return null; @@ -2815,7 +2817,7 @@ public class CPPSemantics { LookupData data= new LookupData(name); data.setFunctionArguments(false, init.getArguments()); try { - IBinding ctor = CPPSemantics.resolveFunction(data, ((ICPPClassType) targetType).getConstructors(), true); + IBinding ctor = CPPSemantics.resolveFunction(data, SemanticUtil.getConstructors((ICPPClassType) targetType, name), true); if (ctor instanceof ICPPConstructor) { int i= 0; for (IASTNode arg : init.getArguments()) { @@ -3086,7 +3088,7 @@ public class CPPSemantics { ValueCategory isLValue= evaluation.getValueCategory(name); if (sourceType != null) { Cost c; - if (calculateInheritanceDepth(sourceType, classType) >= 0) { + if (calculateInheritanceDepth(sourceType, classType, name) >= 0) { c = Conversions.copyInitializationOfClass(isLValue, sourceType, classType, false, name); } else { c = Conversions.checkImplicitConversionSequence(type, sourceType, isLValue, UDCMode.ALLOWED, Context.ORDINARY, name); @@ -3122,13 +3124,13 @@ public class CPPSemantics { LookupData data = new LookupData(astName); data.setFunctionArguments(false, arguments); data.qualified = true; - data.foundItems = classType.getConstructors(); + data.foundItems = SemanticUtil.getConstructors(classType, name); binding = resolveAmbiguities(data); if (binding instanceof ICPPConstructor) return (ICPPConstructor) binding; } else if (initializer == null) { // Default initialization - ICPPConstructor[] ctors = classType.getConstructors(); + ICPPConstructor[] ctors = SemanticUtil.getConstructors(classType, name); for (ICPPConstructor ctor : ctors) { if (ctor.getRequiredArgumentCount() == 0) return ctor; @@ -3342,7 +3344,7 @@ public class CPPSemantics { if (callToObjectOfClassType != null) { try { // 13.3.1.1.2 call to object of class type - ICPPMethod[] ops = SemanticUtil.getConversionOperators(callToObjectOfClassType); + ICPPMethod[] ops = SemanticUtil.getConversionOperators(callToObjectOfClassType, point); for (ICPPMethod op : ops) { if (op.isExplicit()) continue; @@ -3652,9 +3654,10 @@ public class CPPSemantics { return false; } - protected static IBinding resolveUnknownName(IScope scope, ICPPUnknownBinding unknown) { + protected static IBinding resolveUnknownName(IScope scope, ICPPUnknownBinding unknown, IASTNode point) { final IASTName unknownName = unknown.getUnknownName(); - LookupData data = new LookupData(unknownName); + LookupData data = unknownName.getTranslationUnit() != null ? + new LookupData(unknownName) : new LookupData(unknownName.getSimpleID(), null, point); data.setIgnorePointOfDeclaration(true); data.typesOnly= unknown instanceof IType; 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 b7382678968..338e683b912 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 @@ -2405,7 +2405,7 @@ public class CPPTemplates { } else if (t instanceof ICPPClassType) { IScope s = ((ICPPClassType) t).getCompositeScope(); if (s != null) { - result= CPPSemantics.resolveUnknownName(s, unknown); + result= CPPSemantics.resolveUnknownName(s, unknown, point); if (unknown instanceof ICPPUnknownClassInstance && result instanceof ICPPTemplateDefinition) { ICPPTemplateArgument[] newArgs = CPPTemplates.instantiateArguments( ((ICPPUnknownClassInstance) unknown).getArguments(), tpMap, packOffset, within, point); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index 4f5aa61113e..b3b5d1c82ad 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -13,7 +13,11 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.*; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.ALLCVQ; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getNestedType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getUltimateTypeUptoPointers; import java.util.ArrayList; import java.util.Arrays; @@ -157,6 +161,7 @@ import org.eclipse.cdt.core.parser.util.AttributeUtil; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; +import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator; @@ -191,8 +196,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerToMemberType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPReferenceType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScope; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTypedef; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownTypeScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable; @@ -2236,7 +2241,8 @@ public class CPPVisitor extends ASTQueries { } private static IType getStdType(final IASTNode node, char[] name) { - IBinding[] std= node.getTranslationUnit().getScope().find(STD); + ASTTranslationUnit ast = (ASTTranslationUnit) node.getTranslationUnit(); + IBinding[] std= ast.getScope().find(STD); for (IBinding binding : std) { if (binding instanceof ICPPNamespace) { final ICPPNamespaceScope scope = ((ICPPNamespace) binding).getNamespaceScope(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java index 1a63d462fee..a32ce424546 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java @@ -1,16 +1,16 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 IBM Corporation and others. + * Copyright (c) 2004, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) - * Bryan Wilkinson (QNX) - * Andrew Ferguson (Symbian) - * Sergey Prigogin (Google) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Bryan Wilkinson (QNX) + * Andrew Ferguson (Symbian) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -75,8 +75,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Cost.ReferenceBind * Routines for calculating the cost of conversions. */ public class Conversions { - public enum UDCMode {ALLOWED, FORBIDDEN, DEFER} - public enum Context {ORDINARY, IMPLICIT_OBJECT, FIRST_PARAM_OF_DIRECT_COPY_CTOR, REQUIRE_DIRECT_BINDING} + public enum UDCMode { ALLOWED, FORBIDDEN, DEFER } + public enum Context { ORDINARY, IMPLICIT_OBJECT, FIRST_PARAM_OF_DIRECT_COPY_CTOR, REQUIRE_DIRECT_BINDING } private static final char[] INITIALIZER_LIST_NAME = "initializer_list".toCharArray(); //$NON-NLS-1$ private static final char[] STD_NAME = "std".toCharArray(); //$NON-NLS-1$ @@ -135,7 +135,7 @@ public class Conversions { // [for overload resolution bit-fields are treated the same, error if selected as best match] if (valueCat == LVALUE) { // ... and "cv1 T1" is reference-compatible with "cv2 T2" - Cost cost= isReferenceCompatible(cv1T1, cv2T2, isImpliedObject); + Cost cost= isReferenceCompatible(cv1T1, cv2T2, isImpliedObject, point); if (cost != null) { cost.setReferenceBinding(refBindingType); return cost; @@ -145,7 +145,7 @@ public class Conversions { // implicitly converted to an lvalue of type 'cv3 T3', where 'cv1 T1' is reference-compatible with // 'cv3 T3' (this conversion is selected by enumerating the applicable conversion functions (13.3.1.6) // and choosing the best one through overload resolution (13.3)), - if (T2 instanceof ICPPClassType && udc != UDCMode.FORBIDDEN && isReferenceRelated(T1, T2) < 0) { + if (T2 instanceof ICPPClassType && udc != UDCMode.FORBIDDEN && isReferenceRelated(T1, T2, point) < 0) { Cost cost= initializationByConversionForDirectReference(cv1T1, cv2T2, (ICPPClassType) T2, true, ctx, point); if (cost != null) { cost.setReferenceBinding(refBindingType); @@ -195,7 +195,7 @@ public class Conversions { // ... the initializer expression is an rvalue and 'cv1 T1' is reference-compatible with 'cv2 T2' // ..., then the reference is bound to the initializer expression rvalue in the first case if (valueCat.isRValue()) { - Cost cost= isReferenceCompatible(cv1T1, cv2T2, isImpliedObject); + Cost cost= isReferenceCompatible(cv1T1, cv2T2, isImpliedObject, point); if (cost != null) { // [13.3.3.1.4-1] direct binding has either identity or conversion rank. if (cost.getInheritanceDistance() > 0) { @@ -212,7 +212,7 @@ public class Conversions { // resolution (13.3)), then the reference is bound to the initializer expression rvalue in the // first case and to the object that is the result of the conversion in the second case (or, // in either case, to the appropriate base class sub-object of the object). - if (udc != UDCMode.FORBIDDEN && isReferenceRelated(T1, T2) < 0) { + if (udc != UDCMode.FORBIDDEN && isReferenceRelated(T1, T2, point) < 0) { Cost cost= initializationByConversionForDirectReference(cv1T1, cv2T2, (ICPPClassType) T2, false, ctx, point); if (cost != null) { cost.setReferenceBinding(refBindingType); @@ -225,7 +225,7 @@ public class Conversions { // reference-compatible with 'cv2 T2' the reference is bound to the object represented by the // rvalue (see 3.10). if (T2 instanceof IArrayType && valueCat.isRValue()) { - Cost cost= isReferenceCompatible(cv1T1, cv2T2, isImpliedObject); + Cost cost= isReferenceCompatible(cv1T1, cv2T2, isImpliedObject, point); if (cost != null) { cost.setReferenceBinding(refBindingType); return cost; @@ -239,7 +239,7 @@ public class Conversions { // 13.3.3.1.7 no temporary object when converting the implicit object parameter if (!isImpliedObject && ctx != Context.REQUIRE_DIRECT_BINDING) { - if (isReferenceRelated(T1, T2) < 0 || compareQualifications(cv1T1, cv2T2) >= 0) { + if (isReferenceRelated(T1, T2, point) < 0 || compareQualifications(cv1T1, cv2T2) >= 0) { Cost cost= nonReferenceConversion(valueCat, cv2T2, T1, udc, point); if (cost.converts()) { cost.setReferenceBinding(refBindingType); @@ -260,7 +260,7 @@ public class Conversions { */ private static Cost initializationByConversionForDirectReference(final IType cv1T1, final IType cv2T2, final ICPPClassType T2, boolean needLValue, Context ctx, IASTNode point) throws DOMException { - ICPPMethod[] fcns= SemanticUtil.getConversionOperators(T2); + ICPPMethod[] fcns= SemanticUtil.getConversionOperators(T2, point); Cost operatorCost= null; FunctionCost bestUdcCost= null; boolean ambiguousConversionOperator= false; @@ -276,14 +276,14 @@ public class Conversions { final boolean isLValueRef= t instanceof ICPPReferenceType && !((ICPPReferenceType) t).isRValueReference(); if (isLValueRef == needLValue) { // require an lvalue or rvalue IType implicitParameterType= CPPSemantics.getImplicitParameterType(op); - Cost udcCost= isReferenceCompatible(getNestedType(implicitParameterType, TDEF | REF), cv2T2, true); // expression type to implicit object type + Cost udcCost= isReferenceCompatible(getNestedType(implicitParameterType, TDEF | REF), cv2T2, true, point); // expression type to implicit object type if (udcCost != null) { // Make sure top-level cv-qualifiers are compared udcCost.setReferenceBinding(ReferenceBinding.LVALUE_REF); - FunctionCost udcFuncCost= new FunctionCost(op, udcCost); - int cmp= udcFuncCost.compareTo(null, bestUdcCost, point); + FunctionCost udcFuncCost= new FunctionCost(op, udcCost, point); + int cmp= udcFuncCost.compareTo(null, bestUdcCost); if (cmp <= 0) { - Cost cost= isReferenceCompatible(cv1T1, getNestedType(t, TDEF | REF), false); // converted to target + Cost cost= isReferenceCompatible(cv1T1, getNestedType(t, TDEF | REF), false, point); // converted to target if (cost != null) { bestUdcCost= udcFuncCost; ambiguousConversionOperator= cmp == 0; @@ -315,7 +315,7 @@ public class Conversions { if (uqTarget instanceof ICPPClassType) { if (uqSource instanceof ICPPClassType) { // 13.3.3.1-6 Conceptual derived to base conversion - int depth= calculateInheritanceDepth(uqSource, uqTarget); + int depth= calculateInheritanceDepth(uqSource, uqTarget, point); if (depth >= 0) { if (depth == 0) { return new Cost(source, target, Rank.IDENTITY); @@ -338,7 +338,7 @@ public class Conversions { return initializationByConversion(valueCat, source, (ICPPClassType) uqSource, target, udc == UDCMode.DEFER, point); } - return checkStandardConversionSequence(uqSource, target); + return checkStandardConversionSequence(uqSource, target, point); } /** @@ -439,7 +439,7 @@ public class Conversions { * Note this is not a symmetric relation. * @return inheritance distance, or -1, if cv1t1 is not reference-related to cv2t2 */ - private static final int isReferenceRelated(IType cv1Target, IType cv2Source) { + private static final int isReferenceRelated(IType cv1Target, IType cv2Source, IASTNode point) { IType t= SemanticUtil.getNestedType(cv1Target, TDEF | REF); IType s= SemanticUtil.getNestedType(cv2Source, TDEF | REF); @@ -474,7 +474,7 @@ public class Conversions { s= SemanticUtil.getNestedType(((IQualifierType) s).getType(), TDEF | REF); if (t instanceof ICPPClassType && s instanceof ICPPClassType) { - return SemanticUtil.calculateInheritanceDepth(s, t); + return SemanticUtil.calculateInheritanceDepth(s, t, point); } } if (t == s || (t != null && s != null && t.isSameType(s))) { @@ -490,8 +490,8 @@ public class Conversions { * @return The cost for converting or null if cv1t1 is not * reference-compatible with cv2t2 */ - private static final Cost isReferenceCompatible(IType cv1Target, IType cv2Source, boolean isImpliedObject) { - int inheritanceDist= isReferenceRelated(cv1Target, cv2Source); + private static final Cost isReferenceCompatible(IType cv1Target, IType cv2Source, boolean isImpliedObject, IASTNode point) { + int inheritanceDist= isReferenceRelated(cv1Target, cv2Source, point); if (inheritanceDist < 0) return null; final int cmp= compareQualifications(cv1Target, cv2Source); @@ -515,7 +515,7 @@ public class Conversions { * [4] Standard Conversions * Computes the cost of using the standard conversion sequence from source to target. */ - private static final Cost checkStandardConversionSequence(IType source, IType target) { + private static final Cost checkStandardConversionSequence(IType source, IType target, IASTNode point) { final Cost cost= new Cost(source, target, Rank.IDENTITY); if (lvalue_to_rvalue(cost)) return cost; @@ -523,7 +523,7 @@ public class Conversions { if (promotion(cost)) return cost; - if (conversion(cost)) + if (conversion(cost, point)) return cost; if (qualificationConversion(cost)) @@ -546,7 +546,7 @@ public class Conversions { ICPPConstructor usedCtor= null; Cost bestCost= null; boolean hasInitListConstructor= false; - final ICPPConstructor[] constructors = t.getConstructors(); + final ICPPConstructor[] constructors = SemanticUtil.getConstructors(t, point); ICPPConstructor[] ctors= constructors; for (ICPPConstructor ctor : ctors) { final int minArgCount = ctor.getRequiredArgumentCount(); @@ -630,7 +630,8 @@ public class Conversions { /** * 13.3.1.4 Copy-initialization of class by user-defined conversion [over.match.copy] */ - static final Cost copyInitializationOfClass(ValueCategory valueCat, IType source, ICPPClassType t, boolean deferUDC, IASTNode point) throws DOMException { + static final Cost copyInitializationOfClass(ValueCategory valueCat, IType source, ICPPClassType t, + boolean deferUDC, IASTNode point) throws DOMException { if (deferUDC) { Cost c= new Cost(source, t, Rank.USER_DEFINED_CONVERSION); c.setDeferredUDC(DeferredUDC.COPY_INIT_OF_CLASS); @@ -639,7 +640,7 @@ public class Conversions { FunctionCost cost1= null; Cost cost2= null; - ICPPFunction[] ctors= t.getConstructors(); + ICPPFunction[] ctors= SemanticUtil.getConstructors(t, point); ctors = CPPTemplates.instantiateForFunctionCall(ctors, null, Collections.singletonList(source), Collections.singletonList(valueCat), false, point); @@ -657,7 +658,7 @@ public class Conversions { FunctionCost c1; if (ptypes.length == 0) { if (ctor.takesVarArgs()) { - c1= new FunctionCost(ctor, new Cost(source, null, Rank.ELLIPSIS_CONVERSION)); + c1= new FunctionCost(ctor, new Cost(source, null, Rank.ELLIPSIS_CONVERSION), point); } else { continue; } @@ -669,9 +670,9 @@ public class Conversions { if (ctor.getRequiredArgumentCount() > 1) continue; - c1= new FunctionCost(ctor, checkImplicitConversionSequence(ptype, source, valueCat, UDCMode.FORBIDDEN, Context.ORDINARY, point)); + c1= new FunctionCost(ctor, checkImplicitConversionSequence(ptype, source, valueCat, UDCMode.FORBIDDEN, Context.ORDINARY, point), point); } - int cmp= c1.compareTo(null, cost1, point); + int cmp= c1.compareTo(null, cost1); if (cmp <= 0) { cost1= c1; cost2= new Cost(t, t, Rank.IDENTITY); @@ -685,7 +686,7 @@ public class Conversions { final IType uqSource= getNestedType(source, TDEF | REF | CVTYPE); if (uqSource instanceof ICPPClassType) { - ICPPFunction[] ops = SemanticUtil.getConversionOperators((ICPPClassType) uqSource); + ICPPFunction[] ops = SemanticUtil.getConversionOperators((ICPPClassType) uqSource, point); ops= CPPTemplates.instantiateConversionTemplates(ops, t, point); for (final ICPPFunction f : ops) { if (f instanceof ICPPMethod && !(f instanceof IProblemBinding)) { @@ -694,15 +695,15 @@ public class Conversions { continue; final IType returnType = op.getType().getReturnType(); final IType uqReturnType= getNestedType(returnType, REF | TDEF | CVTYPE); - final int dist = SemanticUtil.calculateInheritanceDepth(uqReturnType, t); + final int dist = SemanticUtil.calculateInheritanceDepth(uqReturnType, t, point); if (dist >= 0) { IType implicitType= CPPSemantics.getImplicitParameterType(op); - final Cost udcCost = isReferenceCompatible(getNestedType(implicitType, TDEF | REF), source, true); + final Cost udcCost = isReferenceCompatible(getNestedType(implicitType, TDEF | REF), source, true, point); if (udcCost != null) { // Make sure top-level cv-qualifiers are compared udcCost.setReferenceBinding(ReferenceBinding.LVALUE_REF); - FunctionCost c1= new FunctionCost(op, udcCost); - int cmp= c1.compareTo(null, cost1, point); + FunctionCost c1= new FunctionCost(op, udcCost, point); + int cmp= c1.compareTo(null, cost1); if (cmp <= 0) { cost1= c1; cost2= new Cost(t, t, Rank.IDENTITY); @@ -735,7 +736,7 @@ public class Conversions { c.setDeferredUDC(DeferredUDC.INIT_BY_CONVERSION); return c; } - ICPPFunction[] ops = SemanticUtil.getConversionOperators(uqSource); + ICPPFunction[] ops = SemanticUtil.getConversionOperators(uqSource, point); ops= CPPTemplates.instantiateConversionTemplates(ops, target, point); FunctionCost cost1= null; Cost cost2= null; @@ -753,12 +754,12 @@ public class Conversions { if (isExplicitConversion && c2.getRank() != Rank.IDENTITY) continue; IType implicitType= CPPSemantics.getImplicitParameterType(op); - final Cost udcCost = isReferenceCompatible(getNestedType(implicitType, TDEF | REF), source, true); + final Cost udcCost = isReferenceCompatible(getNestedType(implicitType, TDEF | REF), source, true, point); if (udcCost != null) { // Make sure top-level cv-qualifiers are compared udcCost.setReferenceBinding(ReferenceBinding.LVALUE_REF); - FunctionCost c1= new FunctionCost(op, udcCost); - int cmp= c1.compareTo(null, cost1, point); + FunctionCost c1= new FunctionCost(op, udcCost, point); + int cmp= c1.compareTo(null, cost1); if (cmp <= 0) { cost1= c1; cost2= c2; @@ -1014,7 +1015,7 @@ public class Conversions { * [4.10] Pointer conversions * [4.11] Pointer to member conversions */ - private static final boolean conversion(Cost cost){ + private static final boolean conversion(Cost cost, IASTNode point) { final IType s = cost.source; final IType t = cost.target; @@ -1085,7 +1086,7 @@ public class Conversions { // to an rvalue of type "pointer to cv B", where B is a base class of D. IType srcPtrTgt= getNestedType(srcPtr.getType(), TDEF | CVTYPE | REF); if (tgtPtrTgt instanceof ICPPClassType && srcPtrTgt instanceof ICPPClassType) { - int depth= SemanticUtil.calculateInheritanceDepth(srcPtrTgt, tgtPtrTgt); + int depth= SemanticUtil.calculateInheritanceDepth(srcPtrTgt, tgtPtrTgt, point); if (depth == -1) { cost.setRank(Rank.NO_MATCH); return true; @@ -1108,7 +1109,7 @@ public class Conversions { IType tt = tpm.getType(); if (st != null && tt != null && st.isSameType(tt)) { int depth = SemanticUtil.calculateInheritanceDepth(tpm.getMemberOfClass(), - spm.getMemberOfClass()); + spm.getMemberOfClass(), point); if (depth == -1) { cost.setRank(Rank.NO_MATCH); return true; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Cost.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Cost.java index e054cc9ddbd..70a67d20b7a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Cost.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Cost.java @@ -6,10 +6,10 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) - * Bryan Wilkinson (QNX) - * Andrew Ferguson (Symbian) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Bryan Wilkinson (QNX) + * Andrew Ferguson (Symbian) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -114,7 +114,6 @@ public class Cost { public void setRank(Rank rank) { fRank= rank; } - public ReferenceBinding getReferenceBinding() { return fReferenceBinding; @@ -123,7 +122,6 @@ public class Cost { public void setReferenceBinding(ReferenceBinding binding) { fReferenceBinding= binding; } - public boolean isAmbiguousUDC() { return fAmbiguousUDC; @@ -303,7 +301,7 @@ public class Cost { public void setSelectedFunction(ICPPFunction function) { fSelectedFunction= function; } - + public ICPPFunction getSelectedFunction() { return fSelectedFunction; } 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 d918929a3c2..7d564ad1ecb 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 @@ -268,7 +268,7 @@ public class EvalConditional extends CPPEvaluation { } // Both are class types and one derives from the other if (uqt1 instanceof ICPPClassType && uqt2 instanceof ICPPClassType) { - int dist= SemanticUtil.calculateInheritanceDepth(uqt1, uqt2); + int dist= SemanticUtil.calculateInheritanceDepth(uqt1, uqt2, point); if (dist >= 0) { CVQualifier cv1 = SemanticUtil.getCVQualifier(t1); CVQualifier cv2 = SemanticUtil.getCVQualifier(t2); @@ -279,7 +279,7 @@ public class EvalConditional extends CPPEvaluation { } return Cost.NO_CONVERSION; } - if (SemanticUtil.calculateInheritanceDepth(uqt2, uqt1) >= 0) + if (SemanticUtil.calculateInheritanceDepth(uqt2, uqt1, point) >= 0) return Cost.NO_CONVERSION; } // Unrelated class types or just one class: 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 da50a23c01e..f618cd64020 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 @@ -304,6 +304,9 @@ public class EvalID extends CPPEvaluation { nameOwner = resolveUnknown(CPPTemplates.createDeferredInstance((ICPPClassTemplate) nameOwner), tpMap, packOffset, within, point); } + if (fieldOwner instanceof IProblemBinding || nameOwner instanceof IProblemBinding) + return this; + if (Arrays.equals(templateArgs, fTemplateArgs) && fieldOwner == fFieldOwner && nameOwner == fNameOwner) return this; 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 17017f2770a..cde19a8c8d8 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 @@ -48,7 +48,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; -import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator; import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPArithmeticConversion; @@ -216,11 +215,11 @@ public class EvalUnary extends CPPEvaluation { switch (fOperator) { case op_sizeof: { - SizeAndAlignment info = getSizeAndAlignment(point); + SizeAndAlignment info = getSizeAndAlignment(fArgument.getTypeOrFunctionSet(point), point); return info == null ? Value.UNKNOWN : Value.create(info.size); } case op_alignOf: { - SizeAndAlignment info = getSizeAndAlignment(point); + SizeAndAlignment info = getSizeAndAlignment(fArgument.getTypeOrFunctionSet(point), point); return info == null ? Value.UNKNOWN : Value.create(info.alignment); } case op_sizeofParameterPack: @@ -239,14 +238,6 @@ public class EvalUnary extends CPPEvaluation { return Value.create(this); } - private SizeAndAlignment getSizeAndAlignment(IASTNode point) { - if (point == null) - return null; - - IType type = fArgument.getTypeOrFunctionSet(point); - return new SizeofCalculator(point.getTranslationUnit()).sizeAndAlignment(type); - } - @Override public ValueCategory getValueCategory(IASTNode point) { ICPPFunction overload = getOverload(point); 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 e7e97cc5c12..43f8cbdd3db 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 @@ -43,7 +43,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; -import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator; import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; @@ -157,11 +156,11 @@ public class EvalUnaryTypeID extends CPPEvaluation { switch (fOperator) { case op_sizeof: { - SizeAndAlignment info = getSizeAndAlignment(point); + SizeAndAlignment info = getSizeAndAlignment(fOrigType, point); return info == null ? Value.UNKNOWN : Value.create(info.size); } case op_alignof: { - SizeAndAlignment info = getSizeAndAlignment(point); + SizeAndAlignment info = getSizeAndAlignment(fOrigType, point); return info == null ? Value.UNKNOWN : Value.create(info.alignment); } case op_typeid: @@ -200,12 +199,6 @@ public class EvalUnaryTypeID extends CPPEvaluation { return Value.create(this); } - private SizeAndAlignment getSizeAndAlignment(IASTNode point) { - if (point == null) - return null; - return new SizeofCalculator(point.getTranslationUnit()).sizeAndAlignment(fOrigType); - } - @Override public ValueCategory getValueCategory(IASTNode point) { return fOperator == op_typeid ? LVALUE : PRVALUE; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FunctionCost.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FunctionCost.java index ef6dd69e55a..81ba5a75dd5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FunctionCost.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FunctionCost.java @@ -40,18 +40,21 @@ class FunctionCost { private final ICPPFunction fFunction; private final Cost[] fCosts; private final ValueCategory[] fValueCategories; + private final IASTNode fPoint; private boolean fIsDirectCopyCtor; - public FunctionCost(ICPPFunction fn, int paramCount) { + public FunctionCost(ICPPFunction fn, int paramCount, IASTNode point) { fFunction= fn; fCosts= new Cost[paramCount]; fValueCategories= new ValueCategory[paramCount]; + fPoint = point; } - public FunctionCost(ICPPFunction fn, Cost cost) { + public FunctionCost(ICPPFunction fn, Cost cost, IASTNode point) { fFunction= fn; fCosts= new Cost[] {cost}; fValueCategories= null; // no udc will be performed + fPoint = point; } public int getLength() { @@ -127,9 +130,8 @@ class FunctionCost { /** * Compares this function call cost to another one. - * @param point */ - public int compareTo(IASTTranslationUnit tu, FunctionCost other, IASTNode point) throws DOMException { + public int compareTo(IASTTranslationUnit tu, FunctionCost other) throws DOMException { if (other == null) return -1; @@ -169,7 +171,7 @@ class FunctionCost { haveBetter = true; } else if (isTemplate && otherIsTemplate) { TypeSelection ts= SemanticUtil.isConversionOperator(f1) ? RETURN_TYPE : PARAMETERS; - int order = CPPTemplates.orderFunctionTemplates(otherAsTemplate, asTemplate, ts, point); + int order = CPPTemplates.orderFunctionTemplates(otherAsTemplate, asTemplate, ts, fPoint); if (order < 0) { haveBetter= true; } else if (order > 0) { @@ -215,10 +217,10 @@ class FunctionCost { if (!parameterTypesMatch(ft1, ft2)) return 0; - int diff= SemanticUtil.calculateInheritanceDepth(o2, o1); + int diff= SemanticUtil.calculateInheritanceDepth(o2, o1, fPoint); if (diff >= 0) return diff; - return -SemanticUtil.calculateInheritanceDepth(o1, o2); + return -SemanticUtil.calculateInheritanceDepth(o1, o2, fPoint); } private boolean parameterTypesMatch(final ICPPFunctionType ft1, final ICPPFunctionType ft2) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java index 817bb8b37c3..9779ceb971c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 IBM Corporation and others. + * Copyright (c) 2004, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -40,7 +40,10 @@ import org.eclipse.cdt.core.dom.ast.IQualifierType; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; @@ -100,12 +103,12 @@ public class SemanticUtil { * @param clazz * @return an array of conversion operators. */ - public static final ICPPMethod[] getDeclaredConversionOperators(ICPPClassType clazz) throws DOMException { + public static final ICPPMethod[] getDeclaredConversionOperators(ICPPClassType clazz, IASTNode point) throws DOMException { ICPPMethod[] methods= ICPPMethod.EMPTY_CPPMETHOD_ARRAY; if (clazz instanceof ICPPDeferredClassInstance) { clazz= (ICPPClassType) ((ICPPDeferredClassInstance) clazz).getTemplateDefinition(); } - ICPPMethod[] decs= clazz.getDeclaredMethods(); + ICPPMethod[] decs= getDeclaredMethods(clazz, point); if (decs != null) { for (ICPPMethod method : decs) { if (isConversionOperator(method)) { @@ -123,11 +126,11 @@ public class SemanticUtil { * @param clazz * @return an array of conversion operators. */ - public static ICPPMethod[] getConversionOperators(ICPPClassType clazz) throws DOMException { + public static ICPPMethod[] getConversionOperators(ICPPClassType clazz, IASTNode point) throws DOMException { ICPPMethod[] methods= ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - ObjectSet ancestry= inheritanceClosure(clazz); + ObjectSet ancestry= inheritanceClosure(clazz, point); for (int i = 0; i < ancestry.size(); i++) { - methods= ArrayUtil.addAll(methods, getDeclaredConversionOperators(ancestry.keyAt(i))); + methods= ArrayUtil.addAll(methods, getDeclaredConversionOperators(ancestry.keyAt(i), point)); } return methods; } @@ -137,7 +140,7 @@ public class SemanticUtil { * @return the root and all its ancestor classes * @throws DOMException */ - public static ObjectSet inheritanceClosure(ICPPClassType root) throws DOMException { + public static ObjectSet inheritanceClosure(ICPPClassType root, IASTNode point) throws DOMException { ObjectSet done= new ObjectSet(2); ObjectSet current= new ObjectSet(2); current.put(root); @@ -148,8 +151,8 @@ public class SemanticUtil { for (int i = 0; i < current.size(); i++) { ICPPClassType clazz= current.keyAt(i); done.put(clazz); - - for (ICPPBase base : clazz.getBases()) { + + for (ICPPBase base : getBases(clazz, point)) { IBinding binding= base.getBaseClass(); if (binding instanceof ICPPClassType && !(binding instanceof IProblemBinding)) { ICPPClassType ct= (ICPPClassType) binding; @@ -165,7 +168,43 @@ public class SemanticUtil { return done; } - + + public static ICPPBase[] getBases(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getBases(point); + return classType.getBases(); + } + + public static ICPPConstructor[] getConstructors(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getConstructors(point); + return classType.getConstructors(); + } + + public static ICPPField[] getDeclaredFields(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getDeclaredFields(point); + return classType.getDeclaredFields(); + } + + public static ICPPMethod[] getDeclaredMethods(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getDeclaredMethods(point); + return classType.getDeclaredMethods(); + } + + public static IBinding[] getFriends(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getFriends(point); + return classType.getFriends(); + } + + public static ICPPClassType[] getNestedClasses(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getNestedClasses(point); + return classType.getNestedClasses(); + } + /** * @param method * @return true if the specified method is a conversion operator @@ -622,11 +661,11 @@ public class SemanticUtil { * @return the number of edges in the inheritance graph, or -1 if the specified classes have * no inheritance relation */ - public static final int calculateInheritanceDepth(IType type, IType baseClass) { - return calculateInheritanceDepth(CPPSemantics.MAX_INHERITANCE_DEPTH, new HashSet(), type, baseClass); + public static final int calculateInheritanceDepth(IType type, IType baseClass, IASTNode point) { + return calculateInheritanceDepth(CPPSemantics.MAX_INHERITANCE_DEPTH, new HashSet(), type, baseClass, point); } - private static final int calculateInheritanceDepth(int maxdepth, Set hashSet, IType type, IType baseClass) { + private static final int calculateInheritanceDepth(int maxdepth, Set hashSet, IType type, IType baseClass, IASTNode point) { if (type == baseClass || type.isSameType(baseClass)) { return 0; } @@ -637,7 +676,7 @@ public class SemanticUtil { clazz= (ICPPClassType) ((ICPPDeferredClassInstance) clazz).getSpecializedBinding(); } - for (ICPPBase cppBase : clazz.getBases()) { + for (ICPPBase cppBase : getBases(clazz, point)) { IBinding base= cppBase.getBaseClass(); if (base instanceof IType && hashSet.add(base)) { IType tbase= (IType) base; @@ -648,7 +687,7 @@ public class SemanticUtil { } if (tbase instanceof ICPPClassType) { - int n= calculateInheritanceDepth(maxdepth - 1, hashSet, tbase, baseClass); + int n= calculateInheritanceDepth(maxdepth - 1, hashSet, tbase, baseClass, point); if (n > 0) return n + 1; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java index 618de5509f2..c33fa703f25 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Symbian Software Systems and others. + * Copyright (c) 2007, 2012 Symbian Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * Andrew Ferguson (Symbian) - Initial implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; @@ -40,7 +41,6 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple private ObjectMap specializationMap; private final ThreadLocal> fInProgress= new ThreadLocal>(); - public CompositeCPPClassSpecialization(ICompositesFactory cf, ICPPClassType rbinding) { super(cf, rbinding); } @@ -143,45 +143,70 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple @Override public final ICPPConstructor[] getConstructors() { + return getConstructors(null); + } + + @Override + public final ICPPConstructor[] getConstructors(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getConstructors(); + return ((ICPPClassSpecializationScope) scope).getConstructors(point); } return super.getConstructors(); } @Override public final ICPPMethod[] getDeclaredMethods() { + return getDeclaredMethods(null); + } + + @Override + public final ICPPMethod[] getDeclaredMethods(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getDeclaredMethods(); + return ((ICPPClassSpecializationScope) scope).getDeclaredMethods(point); } return super.getDeclaredMethods(); } @Override public final ICPPField[] getDeclaredFields() { + return getDeclaredFields(null); + } + + @Override + public final ICPPField[] getDeclaredFields(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getDeclaredFields(); + return ((ICPPClassSpecializationScope) scope).getDeclaredFields(point); } return super.getDeclaredFields(); } @Override public final IBinding[] getFriends() { + return getFriends(null); + } + + @Override + public final IBinding[] getFriends(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getFriends(); + return ((ICPPClassSpecializationScope) scope).getFriends(point); } return super.getFriends(); } @Override public final ICPPClassType[] getNestedClasses() { + return getNestedClasses(null); + } + + @Override + public final ICPPClassType[] getNestedClasses(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getNestedClasses(); + return ((ICPPClassSpecializationScope) scope).getNestedClasses(point); } return super.getNestedClasses(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java index 671ba7884b8..e184fb5baec 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java @@ -66,6 +66,11 @@ public class CompositeCPPClassSpecializationScope extends CompositeScope impleme } } + @Override + public ICPPMethod[] getImplicitMethods(IASTNode point) { + return getImplicitMethods(null); + } + @Override public ICPPMethod[] getImplicitMethods() { createDelegate(); @@ -98,14 +103,19 @@ public class CompositeCPPClassSpecializationScope extends CompositeScope impleme @Override public ICPPConstructor[] getConstructors() { - createDelegate(); - return fDelegate.getConstructors(); + return getConstructors(null); } @Override - public ICPPMethod[] getDeclaredMethods() { + public ICPPConstructor[] getConstructors(IASTNode point) { createDelegate(); - return fDelegate.getDeclaredMethods(); + return fDelegate.getConstructors(point); + } + + @Override + public ICPPMethod[] getDeclaredMethods(IASTNode point) { + createDelegate(); + return fDelegate.getDeclaredMethods(point); } @Override @@ -115,20 +125,20 @@ public class CompositeCPPClassSpecializationScope extends CompositeScope impleme } @Override - public ICPPField[] getDeclaredFields() { + public ICPPField[] getDeclaredFields(IASTNode point) { createDelegate(); - return fDelegate.getDeclaredFields(); + return fDelegate.getDeclaredFields(point); } @Override - public IBinding[] getFriends() { + public IBinding[] getFriends(IASTNode point) { createDelegate(); - return fDelegate.getFriends(); + return fDelegate.getFriends(point); } @Override - public ICPPClassType[] getNestedClasses() { + public ICPPClassType[] getNestedClasses(IASTNode point) { createDelegate(); - return fDelegate.getNestedClasses(); + return fDelegate.getNestedClasses(point); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java index b3fea4a1fca..2af5f563b82 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 QNX Software Systems and others. + * Copyright (c) 2007, 2012 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * QNX - Initial API and implementation * Andrew Ferguson (Symbian) * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -64,7 +65,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements protected static final int RECORD_SIZE = PDOMCPPSpecialization.RECORD_SIZE + 8; private volatile ICPPClassScope fScope; - private ObjectMap specializationMap= null; // Obtained from the synchronized PDOM cache + private ObjectMap specializationMap; // Obtained from the synchronized PDOM cache private final ThreadLocal> fInProgress= new ThreadLocal>(); public PDOMCPPClassSpecialization(PDOMLinkage linkage, PDOMNode parent, ICPPClassType classType, @@ -240,9 +241,14 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPConstructor[] getConstructors() { + return getConstructors(null); + } + + @Override + public ICPPConstructor[] getConstructors(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getConstructors(); + return ((ICPPClassSpecializationScope) scope).getConstructors(point); } try { PDOMClassUtil.ConstructorCollector visitor= new PDOMClassUtil.ConstructorCollector(); @@ -256,9 +262,14 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPMethod[] getDeclaredMethods() { + return getDeclaredMethods(null); + } + + @Override + public ICPPMethod[] getDeclaredMethods(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getDeclaredMethods(); + return ((ICPPClassSpecializationScope) scope).getDeclaredMethods(point); } try { PDOMClassUtil.MethodCollector methods = new PDOMClassUtil.MethodCollector(false); @@ -272,9 +283,14 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPField[] getDeclaredFields() { + return getDeclaredFields(null); + } + + @Override + public ICPPField[] getDeclaredFields(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getDeclaredFields(); + return ((ICPPClassSpecializationScope) scope).getDeclaredFields(point); } try { PDOMClassUtil.FieldCollector visitor = new PDOMClassUtil.FieldCollector(); @@ -288,9 +304,14 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPClassType[] getNestedClasses() { + return getNestedClasses(null); + } + + @Override + public ICPPClassType[] getNestedClasses(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getNestedClasses(); + return ((ICPPClassSpecializationScope) scope).getNestedClasses(point); } try { PDOMClassUtil.NestedClassCollector visitor = new PDOMClassUtil.NestedClassCollector(); @@ -304,7 +325,12 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public IBinding[] getFriends() { - // not yet supported. + return getFriends(null); + } + + @Override + public IBinding[] getFriends(IASTNode point) { + // Not yet supported. return IBinding.EMPTY_BINDING_ARRAY; } From 0e1f8ce5adf14017ab3882dcd029acd678db4e12 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sat, 4 Aug 2012 18:13:00 -0700 Subject: [PATCH 19/31] Cosmetics. --- .../core/dom/parser/cpp/CPPBasicType.java | 2 +- .../parser/cpp/semantics/CPPTemplates.java | 31 ++++++------ .../cdt/internal/core/index/IIndexType.java | 4 +- .../dom/cpp/PDOMCPPClassSpecialization.java | 48 +++++++++---------- .../pdom/dom/cpp/PDOMCPPUnknownBinding.java | 3 +- .../dom/cpp/PDOMCPPUnknownClassInstance.java | 8 ++-- .../pdom/dom/cpp/PDOMCPPUnknownClassType.java | 17 ++++--- .../pdom/dom/cpp/PDOMCPPUnknownScope.java | 4 +- 8 files changed, 56 insertions(+), 61 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java index 592255ac337..bc4a3a3e8ca 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java @@ -211,7 +211,7 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType { int modifiers= 0; int kind; if (dense) { - kind= (firstByte & (ITypeMarshalBuffer.FLAG4-1))/ITypeMarshalBuffer.FLAG1; + kind= (firstByte & (ITypeMarshalBuffer.FLAG4 - 1)) / ITypeMarshalBuffer.FLAG1; } else { kind= buffer.getByte(); modifiers= buffer.getByte(); 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 338e683b912..0f2f9a6ad9f 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 @@ -796,12 +796,13 @@ public class CPPTemplates { IType[] exceptionSpecs= instantiateTypes(func.getExceptionSpecification(), tpMap, -1, within, point); if (decl instanceof ICPPFunctionTemplate) { - if (decl instanceof ICPPConstructor) + if (decl instanceof ICPPConstructor) { spec = new CPPConstructorTemplateSpecialization((ICPPConstructor) decl, owner, tpMap, type, exceptionSpecs); - else if (decl instanceof ICPPMethod) + } else if (decl instanceof ICPPMethod) { spec = new CPPMethodTemplateSpecialization((ICPPMethod) decl, owner, tpMap, type, exceptionSpecs); - else + } else { spec = new CPPFunctionTemplateSpecialization((ICPPFunctionTemplate) decl, owner, tpMap, type, exceptionSpecs); + } } else if (decl instanceof ICPPConstructor) { spec = new CPPConstructorSpecialization((ICPPConstructor) decl, owner, tpMap, type, exceptionSpecs); } else if (decl instanceof ICPPMethod) { @@ -1265,11 +1266,11 @@ public class CPPTemplates { } /** - * Checks whether a given name corresponds to a template declaration and returns the ast node for it. - * This works for the name of a template-definition and also for a name needed to qualify a member - * definition: + * Checks whether a given name corresponds to a template declaration and returns the AST node + * for it. This works for the name of a template-definition and also for a name needed to + * qualify a member definition: *
-	 * template <typename T> void MyTemplate<T>::member() {}
+	 * template <typename T> void MyTemplate<T>::member() {}
 	 * 
* @param name a name for which the corresponding template declaration is searched for. * @return the template declaration or null if name does not @@ -1614,10 +1615,11 @@ public class CPPTemplates { name = dtor.getName(); } else if (simple.getDeclarators().length == 0) { IASTDeclSpecifier spec = simple.getDeclSpecifier(); - if (spec instanceof ICPPASTCompositeTypeSpecifier) + if (spec instanceof ICPPASTCompositeTypeSpecifier) { name = ((ICPPASTCompositeTypeSpecifier) spec).getName(); - else if (spec instanceof ICPPASTElaboratedTypeSpecifier) + } else if (spec instanceof ICPPASTElaboratedTypeSpecifier) { name = ((ICPPASTElaboratedTypeSpecifier) spec).getName(); + } } } else if (nestedDecl instanceof IASTFunctionDefinition) { IASTDeclarator declarator = ((IASTFunctionDefinition) nestedDecl).getDeclarator(); @@ -1633,11 +1635,10 @@ public class CPPTemplates { if (currDecl == templateDecl) { return ns[j]; } - if (currDecl instanceof ICPPASTTemplateDeclaration) { - currDecl = ((ICPPASTTemplateDeclaration) currDecl).getDeclaration(); - } else { + if (!(currDecl instanceof ICPPASTTemplateDeclaration)) { return null; } + currDecl = ((ICPPASTTemplateDeclaration) currDecl).getDeclaration(); } } } else { @@ -2361,7 +2362,7 @@ public class CPPTemplates { public static boolean containsDependentArg(ObjectMap tpMap) { for (Object arg : tpMap.valueArray()) { - if (isDependentType((IType)arg)) + if (isDependentType((IType) arg)) return true; } return false; @@ -2395,9 +2396,9 @@ public class CPPTemplates { } } else if (!t.equals(owner)) { if (unknown instanceof ICPPUnknownClassType) { - result= new CPPUnknownClass((ICPPUnknownBinding)t, unknown.getNameCharArray()); + result= new CPPUnknownClass((ICPPUnknownBinding) t, unknown.getNameCharArray()); } else if (unknown instanceof IFunction) { - result= new CPPUnknownClass((ICPPUnknownBinding)t, unknown.getNameCharArray()); + result= new CPPUnknownClass((ICPPUnknownBinding) t, unknown.getNameCharArray()); } else { result= new CPPUnknownBinding((ICPPUnknownBinding) t, unknown.getNameCharArray()); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexType.java index c037e381213..348ccf74905 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexType.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.index; import org.eclipse.cdt.core.dom.ast.IType; @@ -18,5 +17,4 @@ import org.eclipse.cdt.core.dom.ast.IType; * @since 4.0 */ public interface IIndexType extends IType { - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java index 2af5f563b82..92b9cc2a8a6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java @@ -57,13 +57,13 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements ICPPClassSpecialization, IPDOMMemberOwner, IPDOMCPPClassType { private static final int FIRST_BASE = PDOMCPPSpecialization.RECORD_SIZE + 0; private static final int MEMBER_LIST = PDOMCPPSpecialization.RECORD_SIZE + 4; - + /** * The size in bytes of a PDOMCPPClassSpecialization record in the database. */ @SuppressWarnings("hiding") protected static final int RECORD_SIZE = PDOMCPPSpecialization.RECORD_SIZE + 8; - + private volatile ICPPClassScope fScope; private ObjectMap specializationMap; // Obtained from the synchronized PDOM cache private final ThreadLocal> fInProgress= new ThreadLocal>(); @@ -76,7 +76,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements public PDOMCPPClassSpecialization(PDOMLinkage linkage, long bindingRecord) { super(linkage, bindingRecord); } - + @Override protected int getRecordSize() { return RECORD_SIZE; @@ -91,14 +91,14 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements public ICPPClassType getSpecializedBinding() { return (ICPPClassType) super.getSpecializedBinding(); } - + @Override public IBinding specializeMember(IBinding original) { return specializeMember(original, null); } @Override - public IBinding specializeMember(IBinding original, IASTNode point) { + public IBinding specializeMember(IBinding original, IASTNode point) { if (specializationMap == null) { final Long key= record+PDOMCPPLinkage.CACHE_INSTANCE_SCOPE; Object cached= getPDOM().getCachedResult(key); @@ -124,14 +124,14 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements Set set; synchronized (specializationMap) { IBinding result= (IBinding) specializationMap.get(original); - if (result != null) + if (result != null) return result; set= fInProgress.get(); if (set == null) { set= new HashSet(); fInProgress.set(set); - } - if (!set.add(original)) + } + if (!set.add(original)) return new RecursionResolvingBinding(null, null); } IBinding newSpec= CPPTemplates.createSpecialization(this, original, point); @@ -154,7 +154,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements if (hasOwnScope()) { fScope= new PDOMCPPClassScope(this); return fScope; - } + } } catch (CoreException e) { } fScope= new PDOMCPPClassSpecializationScope(this); @@ -175,14 +175,14 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements long rec = base != null ? base.getRecord() : 0; getDB().putRecPtr(record + FIRST_BASE, rec); } - + public void addBase(PDOMCPPBase base) throws CoreException { getPDOM().removeCachedResult(record+PDOMCPPLinkage.CACHE_BASES); PDOMCPPBase firstBase = getFirstBase(); base.setNextBase(firstBase); setFirstBase(base); } - + public void removeBase(PDOMName pdomName) throws CoreException { getPDOM().removeCachedResult(record+PDOMCPPLinkage.CACHE_BASES); PDOMCPPBase base= getFirstBase(); @@ -205,7 +205,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements base.delete(); } } - + @Override public ICPPBase[] getBases() { return getBases(null); @@ -217,11 +217,11 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements if (scope instanceof ICPPClassSpecializationScope) { return ((ICPPClassSpecializationScope) scope).getBases(point); } - + // This is an explicit specialization Long key= record + PDOMCPPLinkage.CACHE_BASES; ICPPBase[] bases= (ICPPBase[]) getPDOM().getCachedResult(key); - if (bases != null) + if (bases != null) return bases; try { @@ -238,7 +238,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements } return ICPPBase.EMPTY_BASE_ARRAY; } - + @Override public ICPPConstructor[] getConstructors() { return getConstructors(null); @@ -291,7 +291,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { return ((ICPPClassSpecializationScope) scope).getDeclaredFields(point); - } + } try { PDOMClassUtil.FieldCollector visitor = new PDOMClassUtil.FieldCollector(); PDOMCPPClassScope.acceptViaCache(this, visitor, false); @@ -301,18 +301,18 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements return ICPPField.EMPTY_CPPFIELD_ARRAY; } } - + @Override public ICPPClassType[] getNestedClasses() { return getNestedClasses(null); } - + @Override public ICPPClassType[] getNestedClasses(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { return ((ICPPClassSpecializationScope) scope).getNestedClasses(point); - } + } try { PDOMClassUtil.NestedClassCollector visitor = new PDOMClassUtil.NestedClassCollector(); PDOMCPPClassScope.acceptViaCache(this, visitor, false); @@ -335,7 +335,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements } @Override - public ICPPMethod[] getMethods() { + public ICPPMethod[] getMethods() { return ClassTypeHelper.getMethods(this); } @@ -343,12 +343,12 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements public ICPPMethod[] getAllDeclaredMethods() { return ClassTypeHelper.getAllDeclaredMethods(this); } - + @Override public IField[] getFields() { return ClassTypeHelper.getFields(this); } - + @Override public IField findField(String name) { return ClassTypeHelper.findField(this, name); @@ -380,7 +380,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements return CPPClassSpecialization.isSameClassSpecialization(this, (ICPPClassSpecialization) type); } - + @Override public Object clone() { try { @@ -406,7 +406,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements public void accept(IPDOMVisitor visitor) throws CoreException { PDOMCPPClassScope.acceptViaCache(this, visitor, false); } - + @Override public boolean isAnonymous() { return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownBinding.java index ccde7a87f8a..c3fd0884c7a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownBinding.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn (Wind River Systems) - initial API and implementation + * Markus Schorn (Wind River Systems) - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -24,7 +24,6 @@ import org.eclipse.core.runtime.CoreException; * serves as a base for unknown types. */ class PDOMCPPUnknownBinding extends PDOMCPPBinding implements ICPPUnknownBinding { - @SuppressWarnings("hiding") protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownClassInstance.java index 272deb85c00..ffa71595578 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownClassInstance.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Sergey Prigogin (Google) - initial API and implementation - * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -31,7 +31,6 @@ import org.eclipse.core.runtime.CoreException; * @author Sergey Prigogin */ class PDOMCPPUnknownClassInstance extends PDOMCPPUnknownClassType implements ICPPUnknownClassInstance, IPDOMOverloader { - private static final int ARGUMENTS = PDOMCPPUnknownClassType.RECORD_SIZE + 0; private static final int SIGNATURE_HASH = ARGUMENTS + 4; @@ -54,7 +53,6 @@ class PDOMCPPUnknownClassInstance extends PDOMCPPUnknownClassType implements ICP db.putInt(record + SIGNATURE_HASH, sigHash != null ? sigHash.intValue() : 0); } catch (DOMException e) { } - } public PDOMCPPUnknownClassInstance(PDOMLinkage linkage, long bindingRecord) { @@ -80,7 +78,7 @@ class PDOMCPPUnknownClassInstance extends PDOMCPPUnknownClassType implements ICP public ICPPTemplateArgument[] getArguments() { if (arguments == null) { try { - final long rec= getPDOM().getDB().getRecPtr(record+ARGUMENTS); + final long rec= getPDOM().getDB().getRecPtr(record + ARGUMENTS); arguments= PDOMCPPArgumentList.getArguments(this, rec); } catch (CoreException e) { CCorePlugin.log(e); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownClassType.java index 32f96933696..b6e68938324 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownClassType.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Sergey Prigogin (Google) - initial API and implementation - * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -45,9 +45,8 @@ import org.eclipse.core.runtime.CoreException; /** * @author Sergey Prigogin */ -class PDOMCPPUnknownClassType extends PDOMCPPUnknownBinding implements ICPPClassScope, ICPPUnknownClassType, - IPDOMMemberOwner, IIndexType, IIndexScope { - +class PDOMCPPUnknownClassType extends PDOMCPPUnknownBinding + implements ICPPClassScope, ICPPUnknownClassType, IPDOMMemberOwner, IIndexType, IIndexScope { private static final int KEY = PDOMCPPBinding.RECORD_SIZE + 0; // byte private static final int MEMBERLIST = PDOMCPPBinding.RECORD_SIZE + 4; @SuppressWarnings("hiding") @@ -59,7 +58,7 @@ class PDOMCPPUnknownClassType extends PDOMCPPUnknownBinding implements ICPPClass super(linkage, parent, classType); setKind(classType); - // linked list is initialized by storage being zero'd by malloc + // Linked list is initialized by storage being zero'd by malloc } public PDOMCPPUnknownClassType(PDOMLinkage linkage, long bindingRecord) { @@ -245,7 +244,7 @@ class PDOMCPPUnknownClassType extends PDOMCPPUnknownBinding implements ICPPClass } /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType) + * @see IType#isSameType(IType) */ @Override public boolean isSameType(IType type) { @@ -263,8 +262,8 @@ class PDOMCPPUnknownClassType extends PDOMCPPUnknownBinding implements ICPPClass } if (type instanceof ICPPUnknownClassType - && type instanceof ICPPUnknownClassInstance == false - && type instanceof ICPPDeferredClassInstance == false) { + && !(type instanceof ICPPUnknownClassInstance) + && !(type instanceof ICPPDeferredClassInstance)) { ICPPUnknownClassType rhs= (ICPPUnknownClassType) type; if (CharArrayUtils.equals(getNameCharArray(), rhs.getNameCharArray())) { final IBinding lhsContainer = getOwner(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownScope.java index 84c07283f7e..77ed17ec565 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownScope.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - * Sergey Prigogin (Google) + * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; From 6fd6e1836d24f9d8068db815b006fcdecb56b745 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sat, 4 Aug 2012 18:19:46 -0700 Subject: [PATCH 20/31] Bug 299911. Added AST2TemplateTests.testSFINAE. --- .../parser/tests/ast2/AST2TemplateTests.java | 48 +++++++++++++++++++ .../dom/parser/cpp/semantics/EvalBinding.java | 10 ++-- .../dom/parser/cpp/semantics/EvalComma.java | 16 ++++--- .../cpp/semantics/EvalFunctionCall.java | 16 ++++--- .../core/dom/parser/cpp/semantics/EvalID.java | 2 +- .../parser/cpp/semantics/EvalInitList.java | 16 ++++--- .../dom/parser/cpp/semantics/EvalTypeId.java | 21 +++++--- 7 files changed, 98 insertions(+), 31 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 10d8d03ec8d..0b6c3b0f988 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -5876,4 +5876,52 @@ public class AST2TemplateTests extends AST2BaseTest { public void testConstInTypeParameter_377223() throws Exception { parseAndCheckBindings(); } + + // template + // struct integral_constant { + // static constexpr T value = v; + // typedef T value_type; + // typedef integral_constant type; + // }; + // + // typedef integral_constant true_type; + // + // typedef integral_constant false_type; + // + // template + // class helper { + // typedef char one; + // typedef struct { char arr[2]; } two; + // template struct Wrap_type {}; + // template static one test(Wrap_type*); + // template static two test(...); + // public: static const bool value = sizeof(test(0)) == 1; + // }; + // + // template + // struct has_category : integral_constant::value> {}; + // + // template::value> + // struct traits {}; + // + // template + // struct traits { + // typedef typename Iterator::value_type value_type; + // }; + // + // struct tag {}; + // + // struct C { + // typedef int value_type; + // typedef tag category; + // }; + // + // template::value_type> + // class A { + // }; + // + // typedef A type; + public void testSFINAE() throws Exception { + parseAndCheckBindings(); + } } 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 74788246143..acd6fc952c9 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 @@ -94,10 +94,10 @@ public class EvalBinding extends CPPEvaluation { t= ((ICPPTemplateNonTypeParameter) fBinding).getType(); } else if (fBinding instanceof IVariable) { t = ((IVariable) fBinding).getType(); - } else if (fBinding instanceof IFunction) { - t= ((IFunction) fBinding).getType(); } else if (fBinding instanceof ICPPUnknownBinding) { return true; + } else if (fBinding instanceof IFunction) { + t= ((IFunction) fBinding).getType(); } else { return false; } @@ -123,12 +123,12 @@ public class EvalBinding extends CPPEvaluation { if (fBinding instanceof IVariable) { return Value.isDependentValue(((IVariable) fBinding).getInitialValue()); } - if (fBinding instanceof IFunction) { - return false; - } if (fBinding instanceof ICPPUnknownBinding) { return true; } + if (fBinding instanceof IFunction) { + return false; + } return false; } 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 752cb08797c..fe5266bae77 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 @@ -173,14 +173,18 @@ public class EvalComma extends CPPEvaluation { @Override public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, int maxdepth, IASTNode point) { - ICPPEvaluation[] args = new ICPPEvaluation[fArguments.length]; - boolean changed = false; + ICPPEvaluation[] args = null; for (int i = 0; i < fArguments.length; i++) { - args[i] = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point); - if (args[i] != fArguments[i]) - changed = true; + ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point); + if (arg != fArguments[i]) { + if (args == null) { + args = new ICPPEvaluation[fArguments.length]; + System.arraycopy(fArguments, 0, args, 0, fArguments.length); + } + args[i] = arg; + } } - if (!changed) + if (args == null) return this; return new EvalComma(args); } 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 d7737ffc9e4..6cb3db90499 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 @@ -186,14 +186,18 @@ public class EvalFunctionCall extends CPPEvaluation { @Override public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, int maxdepth, IASTNode point) { - ICPPEvaluation[] args = new ICPPEvaluation[fArguments.length]; - boolean changed = false; + ICPPEvaluation[] args = null; for (int i = 0; i < fArguments.length; i++) { - args[i] = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point); - if (args[i] != fArguments[i]) - changed = true; + ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point); + if (arg != fArguments[i]) { + if (args == null) { + args = new ICPPEvaluation[fArguments.length]; + System.arraycopy(fArguments, 0, args, 0, fArguments.length); + } + args[i] = arg; + } } - if (!changed) + if (args == null) return this; if (args[0] instanceof EvalFunctionSet) { 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 f618cd64020..34d3d063c46 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 @@ -128,7 +128,7 @@ public class EvalID extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - // Name lookup is not needed here because it was already done in "instantiate" method. + // Name lookup is not needed here because it was already done in the "instantiate" method. // IBinding nameOwner = fNameOwner; // if (nameOwner == null && fFieldOwner != null) // nameOwner = (IBinding) fFieldOwner.getTypeOrFunctionSet(point); 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 e1d4b237e29..db7d1c46bba 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 @@ -105,14 +105,18 @@ public class EvalInitList extends CPPEvaluation { @Override public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, int maxdepth, IASTNode point) { - ICPPEvaluation[] clauses = new ICPPEvaluation[fClauses.length]; - boolean changed = false; + ICPPEvaluation[] clauses = null; for (int i = 0; i < fClauses.length; i++) { - clauses[i] = fClauses[i].instantiate(tpMap, packOffset, within, maxdepth, point); - if (clauses[i] != fClauses[i]) - changed = true; + ICPPEvaluation clause = fClauses[i].instantiate(tpMap, packOffset, within, maxdepth, point); + if (clause != fClauses[i]) { + if (clauses == null) { + clauses = new ICPPEvaluation[fClauses.length]; + System.arraycopy(fClauses, 0, clauses, 0, fClauses.length); + } + clauses[i] = clause; + } } - if (!changed) + if (clauses == null) return this; return new EvalInitList(clauses); } 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 6e8ef088d12..c0c25271eba 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 @@ -146,16 +146,23 @@ public class EvalTypeId extends CPPEvaluation { @Override public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, int maxdepth, IASTNode point) { - ICPPEvaluation[] args = new ICPPEvaluation[fArguments.length]; - boolean argsChanged = false; + ICPPEvaluation[] args = null; for (int i = 0; i < fArguments.length; i++) { - args[i] = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point); - if (args[i] != fArguments[i]) - argsChanged = true; + ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point); + if (arg != fArguments[i]) { + if (args == null) { + args = new ICPPEvaluation[fArguments.length]; + System.arraycopy(fArguments, 0, args, 0, fArguments.length); + } + args[i] = arg; + } } IType type = CPPTemplates.instantiateType(fInputType, tpMap, packOffset, within, point); - if (!argsChanged && type == fInputType) - return this; + if (args == null) { + if (type == fInputType) + return this; + args = fArguments; + } return new EvalTypeId(type, args); } From 6cc4775e1764e1c91c516bbac15ab3c3e9baada6 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sun, 5 Aug 2012 16:15:30 -0700 Subject: [PATCH 21/31] Cosmetics. --- .../parser/tests/ast2/AST2TemplateTests.java | 180 +++++++++--------- .../dom/parser/cpp/CPPUnknownFunction.java | 2 - 2 files changed, 90 insertions(+), 92 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 0b6c3b0f988..1195974b73f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -1320,7 +1320,7 @@ public class AST2TemplateTests extends AST2BaseTest { // A ab; // A ac; public void testEnclosingScopes_a() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPSpecialization b0= ba.assertNonProblem("A", 4, ICPPSpecialization.class, ICPPClassType.class); ICPPTemplateInstance b1= ba.assertNonProblem("A", 4, ICPPTemplateInstance.class, ICPPClassType.class); @@ -1363,7 +1363,7 @@ public class AST2TemplateTests extends AST2BaseTest { // A::B adb; // } public void testEnclosingScopes_b() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPClassType b0= ba.assertNonProblem("B acb", 1, ICPPClassType.class); ICPPClassType b1= ba.assertNonProblem("B adb", 1, ICPPClassType.class, ICPPSpecialization.class); @@ -1392,7 +1392,7 @@ public class AST2TemplateTests extends AST2BaseTest { // // X::Y::Z xayz; public void testEnclosingScopes_c() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPClassType b0= ba.assertNonProblem("Y::Z x", 1, ICPPClassType.class); ICPPClassType b1= ba.assertNonProblem("Z xayz", 1, ICPPClassType.class); @@ -1417,7 +1417,7 @@ public class AST2TemplateTests extends AST2BaseTest { // // X::N n; public void testEnclosingScopes_d() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPClassType b0= ba.assertNonProblem("N n", 1, ICPPClassType.class); ICPPClassType b1= ba.assertNonProblem("N {", 1, ICPPClassType.class); @@ -2042,7 +2042,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } // }; public void testBug201204() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction fn= bh.assertNonProblem("makeClosure(this", 11, ICPPFunction.class); } @@ -2068,7 +2068,7 @@ public class AST2TemplateTests extends AST2BaseTest { // func(d, &C::m2); // } public void testBug233889() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction fn1= bh.assertNonProblem("func(c", 4, ICPPFunction.class); ICPPFunction fn2= bh.assertNonProblem("func(d", 4, ICPPFunction.class); assertNotSame(fn1, fn2); @@ -2091,7 +2091,7 @@ public class AST2TemplateTests extends AST2BaseTest { // GetPair(x, 1); // } public void testBug229917_1() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction fn = bh.assertNonProblem("GetPair(x", 7, ICPPFunction.class); } @@ -2108,7 +2108,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template // typename _C::value_type GetPair(_C& collection, typename _C::value_type::first_type key); public void testBug229917_2() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); IBinding b0 = bh.assertNonProblem("value_type GetPair", 10, IBinding.class); } @@ -2127,7 +2127,7 @@ public class AST2TemplateTests extends AST2BaseTest { // str.m(); // } public void testBug232086() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction b0 = bh.assertNonProblem("m();", 1, ICPPFunction.class); } @@ -2150,7 +2150,7 @@ public class AST2TemplateTests extends AST2BaseTest { // bar(ca); // } public void testBug214646() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); IBinding b0= bh.assertNonProblem("foo(a)", 3); IBinding b1= bh.assertNonProblem("bar(ca)", 3); @@ -2182,7 +2182,7 @@ public class AST2TemplateTests extends AST2BaseTest { // func(a2); // } public void testFunctionTemplate_245049_1() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction b0= bh.assertNonProblem("func(a1)", 4, ICPPFunction.class); assertInstance(b0, ICPPTemplateInstance.class); ICPPFunction b1= bh.assertNonProblem("func(a2)", 4, ICPPFunction.class); @@ -2205,7 +2205,7 @@ public class AST2TemplateTests extends AST2BaseTest { // func(a2); // } public void testFunctionTemplate_245049_2() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction b0= bh.assertNonProblem("func(a1)", 4, ICPPFunction.class); assertInstance(b0, ICPPTemplateInstance.class); ICPPFunction b1= bh.assertNonProblem("func(a2)", 4, ICPPFunction.class); @@ -2228,7 +2228,7 @@ public class AST2TemplateTests extends AST2BaseTest { // using ns::make_pair; // pair p = make_pair(1, 2); public void testFunctionTemplateWithUsing() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); bh.assertNonProblem("make_pair(1", 9, ICPPFunction.class); } @@ -2246,7 +2246,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f(a(x)); // } public void testFunctionTemplate_264963() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); bh.assertNonProblem("f(a(x));", 1, ICPPFunction.class); } @@ -2261,7 +2261,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f(&A::m); // } public void testFunctionTemplate_266532() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); bh.assertNonProblem("f(&A::m);", 1, ICPPFunction.class); } @@ -2336,7 +2336,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f1(x, &f2); // } public void testFunctionTemplateWithFunctionPointer_281783() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); bh.assertNonProblem("f1(x, &f2);", 2, ICPPFunction.class); } @@ -2658,7 +2658,7 @@ public class AST2TemplateTests extends AST2BaseTest { // foo(d); // } public void testUserDefinedConversions_224364() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction fn= bh.assertNonProblem("foo(d)", 3, ICPPFunction.class); } @@ -2678,7 +2678,7 @@ public class AST2TemplateTests extends AST2BaseTest { // foo(d); // } public void testUserDefinedConversions_224364_2() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction fn= bh.assertNonProblem("foo(d)", 3, ICPPFunction.class); } @@ -2701,7 +2701,7 @@ public class AST2TemplateTests extends AST2BaseTest { // // Z z= foo(*new E()); public void testUserDefinedConversions_224364_3() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction fn= bh.assertNonProblem("foo(*new", 3, ICPPFunction.class); } @@ -2725,7 +2725,7 @@ public class AST2TemplateTests extends AST2BaseTest { // foo(cx); // } public void testUserDefinedConversions_226231() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction fn= bh.assertNonProblem("foo(cx", 3, ICPPFunction.class); } @@ -2744,7 +2744,7 @@ public class AST2TemplateTests extends AST2BaseTest { // return foo(c); // } public void testUserDefinedConversions_239023() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ba.assertNonProblem("foo(c);", 3); } @@ -2845,7 +2845,7 @@ public class AST2TemplateTests extends AST2BaseTest { // return at; // } public void testTypeIdAsTemplateArgumentIsTypeId_229942_f() throws Exception { - BindingAssertionHelper ba=new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba=new BindingAssertionHelper(getAboveComment(), CPP); ba.assertNonProblem("T> at) {", 1); IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); @@ -2910,7 +2910,7 @@ public class AST2TemplateTests extends AST2BaseTest { // C c1; // C<> c2; // ok - default args public void testMissingTemplateArgumentLists() throws Exception { - BindingAssertionHelper ba=new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba=new BindingAssertionHelper(getAboveComment(), CPP); ba.assertProblem("B b1", 1); ba.assertNonProblem("B<> b2", 1, ICPPTemplateDefinition.class, ICPPClassType.class); ba.assertProblem("B<> b2", 3); @@ -2927,7 +2927,7 @@ public class AST2TemplateTests extends AST2BaseTest { // member1 = 0; // } public void testDefinitionOfClassTemplateWithNonTypeParameter() throws Exception { - BindingAssertionHelper ba=new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba=new BindingAssertionHelper(getAboveComment(), CPP); ICPPMethod f1= ba.assertNonProblem("fun1(void);", 4, ICPPMethod.class); ICPPField m1= ba.assertNonProblem("member1;", 7, ICPPField.class); ICPPMethod f2= ba.assertNonProblem("fun1(void) {", 4, ICPPMethod.class); @@ -2953,7 +2953,7 @@ public class AST2TemplateTests extends AST2BaseTest { // A::B<> b; // } public void testNestedTemplateDefinitionParameter() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPTemplateTypeParameter T3a= ba.assertNonProblem("T3 f", 2, ICPPTemplateTypeParameter.class); ICPPTemplateTypeParameter T3b= ba.assertNonProblem("T3)", 2, ICPPTemplateTypeParameter.class); ICPPClassType b= ba.assertNonProblem("B<>", 3, ICPPClassType.class, ICPPTemplateInstance.class); @@ -2969,7 +2969,7 @@ public class AST2TemplateTests extends AST2BaseTest { // A::Y y; // A::Z z; public void testNonTypeArgumentDisambiguation_233460() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPClassType b2= ba.assertNonProblem("A", 7, ICPPClassType.class, ICPPTemplateInstance.class); ICPPClassType b3= ba.assertNonProblem("A", 7, ICPPClassType.class, ICPPTemplateInstance.class); ICPPClassType b4= ba.assertNonProblem("A", 7, ICPPClassType.class, ICPPTemplateInstance.class); @@ -2998,7 +2998,7 @@ public class AST2TemplateTests extends AST2BaseTest { // A::X x; //3 should be an error // A::Y y; //4 should be an error public void testNonTypeBooleanArgumentDisambiguation() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPClassType X= ba.assertNonProblem("X x; //1", 1, ICPPClassType.class); ICPPClassType Y= ba.assertNonProblem("Y y; //2", 1, ICPPClassType.class); @@ -3029,7 +3029,7 @@ public class AST2TemplateTests extends AST2BaseTest { // baz(); // } public void testBug207871() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPVariable _256= ba.assertNonProblem("_256=0x100", 4, ICPPVariable.class); IQualifierType qt1= assertInstance(_256.getType(), IQualifierType.class); @@ -3070,7 +3070,7 @@ public class AST2TemplateTests extends AST2BaseTest { // C go(); // }; public void testDeferredNonTypeArgument() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPDeferredClassInstance ci= ba.assertNonProblem("C", 4, ICPPDeferredClassInstance.class); ICPPTemplateArgument[] args= ci.getTemplateArguments(); assertEquals(1, args.length); @@ -3082,7 +3082,7 @@ public class AST2TemplateTests extends AST2BaseTest { // // A aint; // should be an error public void testTypeArgumentToNonTypeParameter() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ba.assertProblem("A", 6); } @@ -3102,7 +3102,7 @@ public class AST2TemplateTests extends AST2BaseTest { // inline This::This() : That(I) { // } public void testParameterReferenceInChainInitializer_a() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); // These intermediate assertions will not hold until deferred non-type arguments are // correctly modelled @@ -3135,7 +3135,7 @@ public class AST2TemplateTests extends AST2BaseTest { // inline This::This() : That() { // } public void testParameterReferenceInChainInitializer_b() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPClassType tid= ba.assertNonProblem("This::T", 7, ICPPClassType.class); assertFalse(tid instanceof ICPPSpecialization); @@ -3157,7 +3157,7 @@ public class AST2TemplateTests extends AST2BaseTest { // // C ca5L; public void testIntegralConversionInPartialSpecializationMatching_237914() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPTemplateInstance ctps= ba.assertNonProblem("C", 7, ICPPTemplateInstance.class, ICPPClassType.class); assertInstance(ctps.getTemplateDefinition(), ICPPClassTemplatePartialSpecialization.class); } @@ -3177,7 +3177,7 @@ public class AST2TemplateTests extends AST2BaseTest { // ca5L.test= 0; // } public void testIntegralConversionInSpecializationMatching_237914() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPSpecialization ctps= ba.assertNonProblem("C", 7, ICPPSpecialization.class, ICPPClassType.class); ba.assertNonProblem("test=", 4, ICPPField.class); } @@ -3193,7 +3193,7 @@ public class AST2TemplateTests extends AST2BaseTest { // B(const B& other) : A(other) {} // }; public void testChainInitializerLookupThroughDeferredClassBase() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ba.assertNonProblem("A(other", 1); } @@ -3212,7 +3212,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } // }; public void testMemberLookupThroughDeferredClassBase() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ba.assertNonProblem("foo(s", 3); } @@ -3228,7 +3228,7 @@ public class AST2TemplateTests extends AST2BaseTest { // return foo(); // } public void testMemberReferenceFromTemplatedMethodDefinition_238232() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ba.assertNonProblem("foo();", 3); } @@ -3273,7 +3273,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } // detail public void testBug238180_ClassCast() throws Exception { // the code above used to trigger a ClassCastException - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPClassType p= ba.assertNonProblem("str", 0, ICPPClassType.class); ICPPConstructor con= p.getConstructors()[1]; ICPPReferenceType reftype= (ICPPReferenceType) con.getType().getParameterTypes()[0]; @@ -3301,7 +3301,7 @@ public class AST2TemplateTests extends AST2BaseTest { // }; // template int CT::x = sizeof(T); public void testUsingTemplParamInInitializerOfStaticField() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPTemplateTypeParameter t= ba.assertNonProblem("T)", 1, ICPPTemplateTypeParameter.class); } @@ -3348,7 +3348,7 @@ public class AST2TemplateTests extends AST2BaseTest { // func(cb); // } public void testTemplateMetaProgramming_245027() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPMethod method= ba.assertNonProblem("method();", 6, ICPPMethod.class); ICPPVariable a= ba.assertNonProblem("a =", 1, ICPPVariable.class); ICPPVariable b= ba.assertNonProblem("b =", 1, ICPPVariable.class); @@ -3374,7 +3374,7 @@ public class AST2TemplateTests extends AST2BaseTest { // ns1::A<(sizeof(probe(x)) == 1)>::m(x); // } public void testNonTypeTemplateParameter_252108() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ba.assertNonProblem("x))", 1, ICPPVariable.class); } @@ -3466,7 +3466,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testFunctionSpecializationAsFriend() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPFunctionTemplate f= bh.assertNonProblem("f(T)", 1); IFunction fref1= bh.assertNonProblem("f<>", 1); assertSame(fref1, f); @@ -3493,7 +3493,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testMethodImplWithNonDeferredType() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPMethod m1= bh.assertNonProblem("m1();", 2); ICPPMethod m2= bh.assertNonProblem("m1() ", 2); assertSame(m1, m2); @@ -3518,7 +3518,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testClassTemplateMemberFunctionTemplate_Bug104262() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPClassTemplate A1= bh.assertNonProblem("A1", 2); ICPPMethod method= bh.assertNonProblem("A1::f1", 13); @@ -3541,7 +3541,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testQualifiedMethodTemplate() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPMethod mt1= bh.assertNonProblem("m(V);", 1); ICPPMethod mt2= bh.assertNonProblem("m(V) ", 1); @@ -3570,7 +3570,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testFieldReference_Bug257186() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); IBinding a1= bh.assertNonProblem("a;", 1); IBinding a2= bh.assertNonProblem("a=", 1); @@ -3592,7 +3592,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testUnknownReferences_Bug257194() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("func();", 4, ICPPUnknownBinding.class); bh.assertNonProblem("var;", 3, ICPPUnknownBinding.class); @@ -3616,7 +3616,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testTypeOfUnknownReferences_Bug257194a() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("b.c", 1, ICPPUnknownBinding.class); bh.assertNonProblem("c;", 1, ICPPUnknownBinding.class); @@ -3641,7 +3641,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testTypeOfUnknownReferences_Bug257194b() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("b->c", 1, ICPPUnknownBinding.class); bh.assertNonProblem("c;", 1, ICPPUnknownBinding.class); @@ -3666,7 +3666,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testTypeVsExpressionInArgsOfDependentTemplateID_257194() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPUnknownBinding b= bh.assertNonProblem("a>", 1); assertFalse(b instanceof IType); @@ -3702,7 +3702,7 @@ public class AST2TemplateTests extends AST2BaseTest { // func(p); // } public void testTypedefReference_259871() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); bh.assertNonProblem("func(p)", 4, ICPPFunction.class); } @@ -3724,7 +3724,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } // }; public void testNestedTemplates_259872_1() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); bh.assertNonProblem("A", 9, ICPPConstructor.class); } @@ -3749,7 +3749,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } // }; public void testNestedTemplates_259872_2() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); bh.assertNonProblem("A", 9, ICPPConstructor.class); } @@ -3768,7 +3768,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testCtorWithTemplateID_259600() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPConstructor ctor= bh.assertNonProblem("DumbPtr/**/", 7); ICPPMethod dtor= bh.assertNonProblem("~DumbPtr/**/", 8); } @@ -3783,7 +3783,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testCtorTemplateWithTemplateID_259600() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPConstructor ctor= bh.assertNonProblem("XT/**/", 2); ctor= bh.assertNonProblem("XT/**/", 5); } @@ -3807,7 +3807,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testResolutionOfUnknownBindings_262163() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); IVariable x= bh.assertNonProblem("x;", 1); ITypedef Nested= bh.assertNonProblem("Nested;", 6); IType t= x.getType(); @@ -3839,7 +3839,7 @@ public class AST2TemplateTests extends AST2BaseTest { // s.substr(0); // } public void testResolutionOfUnknownBindings_262328() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); bh.assertNonProblem("substr(0)", 6, ICPPMethod.class); } @@ -3881,7 +3881,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testConflictInTemplateArgumentDeduction() throws Exception { String code= getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPMethod m= bh.assertNonProblem("append(3", 6); assertFalse(m instanceof ICPPTemplateInstance); } @@ -3900,7 +3900,7 @@ public class AST2TemplateTests extends AST2BaseTest { // p.m(); // } public void testConversionSequence_263159() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPMethod m= bh.assertNonProblem("m();", 1, ICPPMethod.class); } @@ -3921,7 +3921,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testForwardDeclarations_264109() throws Exception { final String code = getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("A make_A(C* p) {", 4, ICPPTemplateInstance.class); parseAndCheckBindings(code); } @@ -3989,7 +3989,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testAmbiguousDeclaratorInFunctionTemplate_265342() throws Exception { final String code = getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("getline2(i)", 8, ICPPTemplateInstance.class); parseAndCheckBindings(code); } @@ -4008,7 +4008,7 @@ public class AST2TemplateTests extends AST2BaseTest { // }; public void testOwnerOfFriendTemplate_265671() throws Exception { final String code = getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); IFunction f= bh.assertNonProblem("f1(", 2, IFunction.class); IBinding owner= f.getOwner(); assertNull(owner); @@ -4034,7 +4034,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template void g(T t) {} public void testDependentNameReferencingLaterDeclaration_265926a() throws Exception { final String code = getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); IFunction gref= bh.assertNonProblem("g(t)", 1); assertInstance(gref, ICPPUnknownBinding.class); IFunction gdecl= bh.assertNonProblem("g(T t)", 1); @@ -4198,7 +4198,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testInlineFriendFunction_287409() throws Exception { final String code = getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPFunction func= bh.assertNonProblem("f(x)", 1, ICPPFunction.class); assertFalse(func instanceof ICPPUnknownBinding); } @@ -4231,7 +4231,7 @@ public class AST2TemplateTests extends AST2BaseTest { // }; public void testResolutionOfNonDependentNames_293052() throws Exception { final String code = getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPFunction func= bh.assertNonProblem("m();", 1, ICPPFunction.class); assertFalse(func instanceof ICPPUnknownBinding); bh.assertProblem("n();", 1); @@ -4256,7 +4256,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testArgumentDeduction_293409() throws Exception { final String code = getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("f1(d);", 2, ICPPFunction.class); bh.assertNonProblem("f2(&d);", 2, ICPPFunction.class); bh.assertNonProblem("f2(&cd);", 2, ICPPFunction.class); @@ -4364,7 +4364,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testRValueReferences_1_294730() throws Exception { final String code= getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPClassType type= bh.assertNonProblem("X", 7); ICPPMethod[] ms= type.getMethods(); @@ -4393,7 +4393,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testFunctionParameterPacks_280909() throws Exception { final String code= getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPFunctionTemplate f= bh.assertNonProblem("f1", 2); assertEquals("void (int (*)(#0 ...))", ASTTypeUtil.getType(f.getType(), true)); assertFalse(f.getParameters()[0].isParameterPack()); @@ -4422,7 +4422,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testTemplateParameterPacks_280909() throws Exception { final String code= getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPClassTemplate ct= bh.assertNonProblem("C1", 2); ICPPTemplateParameter tp= ct.getTemplateParameters()[0]; assertTrue(tp.isParameterPack()); @@ -4451,7 +4451,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testParameterPackExpansions_280909() throws Exception { final String code= getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPField field= bh.assertNonProblem("a= 1", 1); field= bh.assertNonProblem("b= 1", 1); @@ -4467,7 +4467,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testTemplateParameterPacksAmbiguity_280909() throws Exception { final String code= getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPFunctionTemplate ft= bh.assertNonProblem("f1", 2); ICPPTemplateParameter tp= ft.getTemplateParameters()[0]; assertTrue(tp.isParameterPack()); @@ -4532,7 +4532,7 @@ public class AST2TemplateTests extends AST2BaseTest { // Tuple* u; // syntax error public void testVariadicTemplateExamples_280909e() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("String<>", 6); bh.assertProblem("String*", 6); bh.assertNonProblem("Tuple<>", 5); @@ -4552,7 +4552,7 @@ public class AST2TemplateTests extends AST2BaseTest { // Y yc; // okay public void testVariadicTemplateExamples_280909f() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("X", 4); bh.assertProblem("X", 4); bh.assertProblem("X", 4); @@ -4575,7 +4575,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template void B::f4() {} // error public void testVariadicTemplateExamples_280909g() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("f1() {}", 2); bh.assertProblem("f2() {}", 2); bh.assertNonProblem("f3() {}", 2); @@ -4596,7 +4596,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } // int (*)(bool), Z is deduced to an empty sequence public void testVariadicTemplateExamples_280909h() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("f(5.6)", 6); bh.assertProblem("f(5.6)", 1); bh.assertNonProblem("f(f)", 7); @@ -4617,7 +4617,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testVariadicTemplateExamples_280909i() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("f", 0); bh.assertNonProblem("f", 0); bh.assertNonProblem("f", 0); @@ -4673,7 +4673,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testVariadicTemplateExamples_280909p() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("Tuple<>", 0); bh.assertNonProblem("Tuple", 0); bh.assertNonProblem("Tuple", 0); @@ -4722,7 +4722,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testVariadicTemplateExamples_280909s() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ITypedef td= bh.assertNonProblem("T1;", 2); IType type = getNestedType(td, TDEF); assertEquals("Tuple,Pair>", ASTTypeUtil.getType(type, false)); @@ -4761,7 +4761,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testDefaultTemplateArgsForFunctionTemplates_294730() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPTemplateInstance f= bh.assertNonProblem("f(1, 'c');", 1); assertEquals("", ASTTypeUtil.getArgumentListString(f.getTemplateArguments(), true)); @@ -4799,7 +4799,7 @@ public class AST2TemplateTests extends AST2BaseTest { // eval> eE; // error: E does not match TT in partial specialization public void testExtendingVariadicTemplateTemplateParameters_302282() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPClassTemplate ct= bh.assertNonProblem("eval;", -1); ICPPClassTemplatePartialSpecialization pspec= bh.assertNonProblem("eval>", 0); @@ -4833,7 +4833,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testExplicitSpecializations_296427() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPTemplateInstance inst; inst= bh.assertNonProblem("X", 0); @@ -4873,7 +4873,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testBug306213a() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("func", 0); parseAndCheckBindings(code); } @@ -4890,7 +4890,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testBug306213b() throws Exception { CPPASTNameBase.sAllowRecursionBindings= true; final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertProblem("func", 0); } @@ -4917,7 +4917,7 @@ public class AST2TemplateTests extends AST2BaseTest { CPPASTNameBase.sAllowNameComputation= true; final String code= getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); final IASTTranslationUnit tu = bh.getTranslationUnit(); IBinding b= bh.assertNonProblem("CT {", 2); @@ -4986,7 +4986,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testInlineNamespaces_305980() throws Exception { final String code= getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPFunctionTemplate ft= bh.assertNonProblem("f(T&)", 1); ICPPNamespace M= (ICPPNamespace) ft.getOwner(); @@ -5115,7 +5115,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testInstantiationOfFunctionTemplateWithOverloadedFunctionSetArgument_Bug326492() throws Exception { String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPFunctionTemplate f1= bh.assertNonProblem("f(T (*)(int), char)", 1); ICPPFunctionTemplate f2= bh.assertNonProblem("f(int (*)(T), int)", 1); IFunction g1= bh.assertNonProblem("g(char)", 1); @@ -5183,7 +5183,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testNestedTypedefSpecialization_Bug329795() throws Exception { String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPField f1= bh.assertNonProblem("foo;", 3); IBinding f2= bh.assertNonProblem("foo =", 3); assertSame(f1, f2); @@ -5493,7 +5493,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testArgumentDeductionFromReturnTypeOfExplicitSpecialization_355304() throws Exception { parseAndCheckBindings(); - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunctionTemplate template= bh.assertNonProblem("f();", 1); ICPPTemplateInstance inst= bh.assertNonProblem("f() {", 1); assertSame(template, inst.getTemplateDefinition()); @@ -5759,7 +5759,7 @@ public class AST2TemplateTests extends AST2BaseTest { // }; public void testTemplateShortNameInQualifiedName_367607() throws Exception { parseAndCheckBindings(); - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPDeferredClassInstance shortHand= bh.assertNonProblem("derived:", -1); assertTrue(shortHand.getClassTemplate() instanceof ICPPClassTemplatePartialSpecialization); } @@ -5806,7 +5806,7 @@ public class AST2TemplateTests extends AST2BaseTest { // e.x; // ERROR HERE: "Field 'x' could not be resolved" // } public void testAutoTypeWithTypedef_368311() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); IVariable v= bh.assertNonProblem("cur = r.begin()", 3); assertEquals("A::iterator_t", ASTTypeUtil.getType(v.getType(), true)); parseAndCheckBindings(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownFunction.java index 9221489b2c3..16f5d86af25 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownFunction.java @@ -26,7 +26,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemType; * it depends on a template parameter. A compiler would resolve it during instantiation. */ public class CPPUnknownFunction extends CPPUnknownBinding implements ICPPFunction { - private static final ICPPFunctionType FUNCTION_TYPE= new CPPFunctionType(ProblemType.UNKNOWN_FOR_EXPRESSION, IType.EMPTY_TYPE_ARRAY); public static ICPPFunction createForSample(IFunction sample) throws DOMException { @@ -36,7 +35,6 @@ public class CPPUnknownFunction extends CPPUnknownBinding implements ICPPFunctio return new CPPUnknownFunction(sample.getOwner(), sample.getNameCharArray()); } - public CPPUnknownFunction(IBinding owner, char[] name) { super(owner, name); } From e69af609a2e9701e0b7c49643ab07ee1eca063e0 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sun, 5 Aug 2012 16:25:29 -0700 Subject: [PATCH 22/31] Bug 374993. Added a failing test - AST2TemplateTests._testDependentExpressionsDecltype. --- .../parser/tests/ast2/AST2TemplateTests.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 1195974b73f..c1bcafa8798 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -5635,6 +5635,42 @@ public class AST2TemplateTests extends AST2BaseTest { parseAndCheckBindings(); } + // template + // struct A { + // typedef T type; + // }; + // + // template + // struct B {}; + // + // template > + // struct C { + // struct D { + // template + // static typename V::pointer test(typename V::pointer*); + // template + // static T* test(...); + // + // typedef typename A::type E; + // typedef decltype(test(0)) type; + // }; + // + // typedef typename D::type pointer; + // }; + // + // void f(int*); + // void f(int); + // + // void test(C::pointer a) { + // f(a); + // } + public void _testDependentExpressionsDecltype() throws Exception { + parseAndCheckBindings(); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); + ICPPFunction func= bh.assertNonProblem("f(a)", 1, ICPPFunction.class); + assertFalse(func instanceof ICPPUnknownBinding); + } + // template void* foo(int); // template void f(T t) { // if (T* i = foo<0>(0)) From d909a4f50a3e740d7f941662d19d37fcf0f88032 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Mon, 6 Aug 2012 13:57:36 -0700 Subject: [PATCH 23/31] Cosmetics. --- .../parser/cpp/CPPASTFunctionCallExpression.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java index 6ae3b430d93..0c74af3421a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java @@ -13,7 +13,10 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.*; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getNestedType; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.DOMException; @@ -163,7 +166,7 @@ public class CPPASTFunctionCallExpression extends ASTNode } } else { n1.computeOperatorOffsets(functionName, true); - n2.computeOperatorOffsets(fArguments[fArguments.length-1], true); + n2.computeOperatorOffsets(fArguments[fArguments.length - 1], true); } implicitNames = new IASTImplicitName[] { n1, n2 }; @@ -219,8 +222,6 @@ public class CPPASTFunctionCallExpression extends ASTNode } } - - @Override @Deprecated public IASTExpression getParameterExpression() { @@ -296,10 +297,10 @@ public class CPPASTFunctionCallExpression extends ASTNode if (conversion != null) return conversion; - ICPPEvaluation[] args= new ICPPEvaluation[fArguments.length+1]; + ICPPEvaluation[] args= new ICPPEvaluation[fArguments.length + 1]; args[0]= functionName.getEvaluation(); for (int i = 1; i < args.length; i++) { - args[i]= ((ICPPASTExpression) fArguments[i-1]).getEvaluation(); + args[i]= ((ICPPASTExpression) fArguments[i - 1]).getEvaluation(); } return new EvalFunctionCall(args); } @@ -318,7 +319,6 @@ public class CPPASTFunctionCallExpression extends ASTNode } return null; } - @Override public IType getExpressionType() { From bd6fb125eb76650b167d9b5f617f86920c5a538b Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Mon, 6 Aug 2012 21:09:46 -0700 Subject: [PATCH 24/31] Bug 374993. Simplified a test. --- .../parser/tests/ast2/AST2TemplateTests.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index c1bcafa8798..0cba0b7e158 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -5631,7 +5631,7 @@ public class AST2TemplateTests extends AST2BaseTest { // ns::C::value> a; // f(a); // }; - public void testDependentExpressions() throws Exception { + public void testDependentExpressions_a() throws Exception { parseAndCheckBindings(); } @@ -5640,31 +5640,28 @@ public class AST2TemplateTests extends AST2BaseTest { // typedef T type; // }; // - // template - // struct B {}; - // - // template > - // struct C { - // struct D { + // template + // struct B { + // struct C { // template // static typename V::pointer test(typename V::pointer*); // template // static T* test(...); // - // typedef typename A::type E; - // typedef decltype(test(0)) type; + // typedef typename A::type D; + // typedef decltype(test(0)) type; // }; // - // typedef typename D::type pointer; + // typedef typename C::type pointer; // }; // // void f(int*); // void f(int); // - // void test(C::pointer a) { + // void test(B::pointer a) { // f(a); // } - public void _testDependentExpressionsDecltype() throws Exception { + public void _testDependentExpressions_b() throws Exception { parseAndCheckBindings(); BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction func= bh.assertNonProblem("f(a)", 1, ICPPFunction.class); From f1ae22d5d8ea7fceca9f3942b1b6ebf93c6d70b0 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Mon, 6 Aug 2012 21:14:00 -0700 Subject: [PATCH 25/31] Bug 374993. Fixed AST2TemplateTests.testDependentExpressions_b. --- .../parser/tests/ast2/AST2TemplateTests.java | 2 +- .../parser/cpp/semantics/CPPEvaluation.java | 3 +++ .../parser/cpp/semantics/CPPTemplates.java | 7 ++++++ .../dom/parser/cpp/semantics/EvalBinding.java | 2 +- .../cpp/semantics/EvalFunctionCall.java | 6 +++-- .../core/dom/parser/cpp/semantics/EvalID.java | 22 ++++++++----------- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 0cba0b7e158..afa8c76d131 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -5661,7 +5661,7 @@ public class AST2TemplateTests extends AST2BaseTest { // void test(B::pointer a) { // f(a); // } - public void _testDependentExpressions_b() throws Exception { + public void testDependentExpressions_b() throws Exception { parseAndCheckBindings(); BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction func= bh.assertNonProblem("f(a)", 1, ICPPFunction.class); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java index 45edc144710..beafb1b0979 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java @@ -215,6 +215,9 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } } + CPPEvaluation() { + } + @Override public char[] getSignature() { SignatureBuilder buf = new SignatureBuilder(); 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 0f2f9a6ad9f..d1036eab0ea 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 @@ -1259,6 +1259,13 @@ public class CPPTemplates { return typeContainer; } + if (type instanceof TypeOfDependentExpression) { + ICPPEvaluation eval = ((TypeOfDependentExpression) type).getEvaluation(); + ICPPEvaluation instantiated = eval.instantiate(tpMap, packOffset, within, Value.MAX_RECURSION_DEPTH, point); + if (instantiated != eval) + return instantiated.getTypeOrFunctionSet(point); + } + return type; } catch (DOMException e) { return e.getProblem(); 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 acd6fc952c9..fbb50500da8 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 @@ -160,7 +160,7 @@ public class EvalBinding extends CPPEvaluation { final IFunctionType type = ((IFunction) fBinding).getType(); if (CPPTemplates.isDependentType(type)) return new TypeOfDependentExpression(this); - return SemanticUtil.mapToAST(type, point); + return SemanticUtil.mapToAST(type, point); } return ProblemType.UNKNOWN_FOR_EXPRESSION; } 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 6cb3db90499..db34d140b8d 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 @@ -40,6 +40,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemType; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.LookupMode; import org.eclipse.core.runtime.CoreException; @@ -201,6 +202,7 @@ public class EvalFunctionCall extends CPPEvaluation { return this; if (args[0] instanceof EvalFunctionSet) { + // Resolve the function using the parameters of the function call. CPPFunctionSet functionSet = ((EvalFunctionSet) args[0]).getFunctionSet(); ICPPFunction[] functions = functionSet.getBindings(); LookupData data = new LookupData(functions[0].getNameCharArray(), @@ -208,8 +210,8 @@ public class EvalFunctionCall extends CPPEvaluation { data.setFunctionArguments(false, Arrays.copyOfRange(args, 1, args.length)); try { IBinding binding = CPPSemantics.resolveFunction(data, functions, true); - if (binding instanceof ICPPFunction) - return new EvalBinding(binding, null); + if (binding instanceof ICPPFunction && !(binding instanceof ICPPUnknownBinding)) + args[0] = new EvalBinding(binding, null); } catch (DOMException e) { CCorePlugin.log(e); } 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 34d3d063c46..f5547474e44 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 @@ -44,7 +44,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; @@ -291,26 +290,23 @@ public class EvalID extends CPPEvaluation { } IBinding nameOwner = fNameOwner; - if (nameOwner instanceof ICPPTemplateParameter) { - ICPPTemplateArgument argument = tpMap.getArgument((ICPPTemplateParameter) nameOwner); - if (argument != null) { - IType type = argument.getTypeValue(); - if (type instanceof IBinding) - nameOwner = (IBinding) type; - } - } else if (nameOwner instanceof ICPPUnknownBinding) { - nameOwner = resolveUnknown((ICPPUnknownBinding) nameOwner, tpMap, packOffset, within, point); - } else if (nameOwner instanceof ICPPClassTemplate) { + if (nameOwner instanceof ICPPClassTemplate) { + // TODO(sprigogin): Figure out why testDependentExpressions_a fails without special-casing ICPPClassTemplate nameOwner = resolveUnknown(CPPTemplates.createDeferredInstance((ICPPClassTemplate) nameOwner), tpMap, packOffset, within, point); + } else if (nameOwner instanceof IType) { + IType type = CPPTemplates.instantiateType((IType) nameOwner, tpMap, packOffset, within, point); + if (type instanceof IBinding) + nameOwner = (IBinding) type; } + if (fieldOwner instanceof IProblemBinding || nameOwner instanceof IProblemBinding) return this; if (Arrays.equals(templateArgs, fTemplateArgs) && fieldOwner == fFieldOwner && nameOwner == fNameOwner) return this; - ICPPEvaluation eval = resolveName((ICPPClassType) nameOwner, fTemplateArgs, point); + ICPPEvaluation eval = resolveName((ICPPClassType) nameOwner, templateArgs, point); if (eval != null) return eval; @@ -329,7 +325,7 @@ public class EvalID extends CPPEvaluation { if (bindings.length > 1 && bindings[0] instanceof ICPPFunction) { ICPPFunction[] functions = new ICPPFunction[bindings.length]; System.arraycopy(bindings, 0, functions, 0, bindings.length); - return new EvalFunctionSet(new CPPFunctionSet(functions, fTemplateArgs, null), fAddressOf); + return new EvalFunctionSet(new CPPFunctionSet(functions, templateArgs, null), fAddressOf); } IBinding binding = bindings.length == 1 ? bindings[0] : null; if (binding instanceof IEnumerator) { From 690fac29b1c637794dbcc57240e96f58f2503dc2 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Mon, 6 Aug 2012 21:15:11 -0700 Subject: [PATCH 26/31] Cosmetics. --- .../core/pdom/dom/cpp/PDOMCPPTemplateTemplateParameter.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTemplateParameter.java index 29a85f62671..db0a22f3fba 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTemplateParameter.java @@ -6,7 +6,7 @@ * 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.pdom.dom.cpp; @@ -50,7 +50,6 @@ import org.eclipse.core.runtime.CoreException; public class PDOMCPPTemplateTemplateParameter extends PDOMCPPBinding implements ICPPTemplateTemplateParameter, ICPPUnknownBinding, ICPPUnknownType, IIndexType, IPDOMCPPTemplateParameter, IPDOMCPPTemplateParameterOwner { - private static final int PACK_BIT = 1 << 31; private static final int DEFAULT_TYPE = PDOMCPPBinding.RECORD_SIZE; From d6e91170b264361283107029e0437943e9a7b3a7 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 7 Aug 2012 11:48:02 -0700 Subject: [PATCH 27/31] Bug 299911. Code streamlining. --- .../parser/tests/ast2/AST2TemplateTests.java | 14 +++++------ .../dom/parser/cpp/semantics/EvalComma.java | 6 ++--- .../cpp/semantics/EvalFunctionCall.java | 25 ++++--------------- .../parser/cpp/semantics/EvalFunctionSet.java | 25 +++++++++++++++++++ .../core/dom/parser/cpp/semantics/EvalID.java | 5 +--- .../parser/cpp/semantics/EvalInitList.java | 6 ++--- .../dom/parser/cpp/semantics/EvalTypeId.java | 11 +++----- 7 files changed, 47 insertions(+), 45 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index afa8c76d131..9ae7649f3ad 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -88,6 +88,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; public class AST2TemplateTests extends AST2BaseTest { @@ -5655,17 +5656,14 @@ public class AST2TemplateTests extends AST2BaseTest { // typedef typename C::type pointer; // }; // - // void f(int*); - // void f(int); - // - // void test(B::pointer a) { - // f(a); - // } + // B::pointer a; public void testDependentExpressions_b() throws Exception { parseAndCheckBindings(); BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); - ICPPFunction func= bh.assertNonProblem("f(a)", 1, ICPPFunction.class); - assertFalse(func instanceof ICPPUnknownBinding); + ICPPVariable var= bh.assertNonProblem("a;", 1, ICPPVariable.class); + IType type = var.getType(); + type = SemanticUtil.getNestedType(type, TDEF); + assertEquals("int *", type.toString()); } // template void* foo(int); 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 fe5266bae77..9328c13ddcf 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 @@ -173,18 +173,18 @@ public class EvalComma extends CPPEvaluation { @Override public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, int maxdepth, IASTNode point) { - ICPPEvaluation[] args = null; + ICPPEvaluation[] args = fArguments; for (int i = 0; i < fArguments.length; i++) { ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point); if (arg != fArguments[i]) { - if (args == null) { + if (args == fArguments) { args = new ICPPEvaluation[fArguments.length]; System.arraycopy(fArguments, 0, args, 0, fArguments.length); } args[i] = arg; } } - if (args == null) + if (args == fArguments) return this; return new EvalComma(args); } 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 db34d140b8d..6bf4ddc8f91 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 @@ -20,11 +20,8 @@ import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUti import java.util.Arrays; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.ISemanticProblem; @@ -40,7 +37,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemType; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.LookupMode; import org.eclipse.core.runtime.CoreException; @@ -187,34 +183,23 @@ public class EvalFunctionCall extends CPPEvaluation { @Override public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, int maxdepth, IASTNode point) { - ICPPEvaluation[] args = null; + ICPPEvaluation[] args = fArguments; for (int i = 0; i < fArguments.length; i++) { ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point); if (arg != fArguments[i]) { - if (args == null) { + if (args == fArguments) { args = new ICPPEvaluation[fArguments.length]; System.arraycopy(fArguments, 0, args, 0, fArguments.length); } args[i] = arg; } } - if (args == null) + if (args == fArguments) return this; - if (args[0] instanceof EvalFunctionSet) { + if (args[0] instanceof EvalFunctionSet && getOverload(point) == null) { // Resolve the function using the parameters of the function call. - CPPFunctionSet functionSet = ((EvalFunctionSet) args[0]).getFunctionSet(); - ICPPFunction[] functions = functionSet.getBindings(); - LookupData data = new LookupData(functions[0].getNameCharArray(), - functionSet.getTemplateArguments(), point); - data.setFunctionArguments(false, Arrays.copyOfRange(args, 1, args.length)); - try { - IBinding binding = CPPSemantics.resolveFunction(data, functions, true); - if (binding instanceof ICPPFunction && !(binding instanceof ICPPUnknownBinding)) - args[0] = new EvalBinding(binding, null); - } catch (DOMException e) { - CCorePlugin.log(e); - } + args[0] = ((EvalFunctionSet) args[0]).resolveFunction(Arrays.copyOfRange(args, 1, args.length), point); } return new EvalFunctionCall(args); } 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 47fc4b8a99e..881db03f857 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 @@ -15,6 +15,8 @@ import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; import java.util.Arrays; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -168,6 +170,29 @@ public class EvalFunctionSet extends CPPEvaluation { return new EvalFunctionSet(new CPPFunctionSet(functions, arguments, null), fAddressOf); } + /** + * Attempts to resolve the function using the parameters of a function call. + * + * @param args the arguments of a function call + * @param point the name lookup context + * @return the resolved or the original evaluation depending on whether function resolution + * succeeded or not + */ + public ICPPEvaluation resolveFunction(ICPPEvaluation[] args, IASTNode point) { + ICPPFunction[] functions = fFunctionSet.getBindings(); + LookupData data = new LookupData(functions[0].getNameCharArray(), + fFunctionSet.getTemplateArguments(), point); + data.setFunctionArguments(false, args); + try { + IBinding binding = CPPSemantics.resolveFunction(data, functions, true); + if (binding instanceof ICPPFunction && !(binding instanceof ICPPUnknownBinding)) + return new EvalBinding(binding, null); + } catch (DOMException e) { + CCorePlugin.log(e); + } + return this; + } + @Override public int determinePackSize(ICPPTemplateParameterMap tpMap) { int r = CPPTemplates.PACK_SIZE_NOT_FOUND; 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 f5547474e44..ae55002ba98 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 @@ -14,8 +14,6 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; -import java.util.Arrays; - import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; @@ -291,7 +289,6 @@ public class EvalID extends CPPEvaluation { IBinding nameOwner = fNameOwner; if (nameOwner instanceof ICPPClassTemplate) { - // TODO(sprigogin): Figure out why testDependentExpressions_a fails without special-casing ICPPClassTemplate nameOwner = resolveUnknown(CPPTemplates.createDeferredInstance((ICPPClassTemplate) nameOwner), tpMap, packOffset, within, point); } else if (nameOwner instanceof IType) { @@ -303,7 +300,7 @@ public class EvalID extends CPPEvaluation { if (fieldOwner instanceof IProblemBinding || nameOwner instanceof IProblemBinding) return this; - if (Arrays.equals(templateArgs, fTemplateArgs) && fieldOwner == fFieldOwner && nameOwner == fNameOwner) + if (templateArgs == fTemplateArgs && fieldOwner == fFieldOwner && nameOwner == fNameOwner) return this; ICPPEvaluation eval = resolveName((ICPPClassType) nameOwner, templateArgs, point); 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 db7d1c46bba..02eb709506e 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 @@ -105,18 +105,18 @@ public class EvalInitList extends CPPEvaluation { @Override public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, int maxdepth, IASTNode point) { - ICPPEvaluation[] clauses = null; + ICPPEvaluation[] clauses = fClauses; for (int i = 0; i < fClauses.length; i++) { ICPPEvaluation clause = fClauses[i].instantiate(tpMap, packOffset, within, maxdepth, point); if (clause != fClauses[i]) { - if (clauses == null) { + if (clauses == fClauses) { clauses = new ICPPEvaluation[fClauses.length]; System.arraycopy(fClauses, 0, clauses, 0, fClauses.length); } clauses[i] = clause; } } - if (clauses == null) + if (clauses == fClauses) return this; return new EvalInitList(clauses); } 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 c0c25271eba..f17201b2139 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 @@ -146,11 +146,11 @@ public class EvalTypeId extends CPPEvaluation { @Override public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, int maxdepth, IASTNode point) { - ICPPEvaluation[] args = null; + ICPPEvaluation[] args = fArguments; for (int i = 0; i < fArguments.length; i++) { ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point); if (arg != fArguments[i]) { - if (args == null) { + if (args == fArguments) { args = new ICPPEvaluation[fArguments.length]; System.arraycopy(fArguments, 0, args, 0, fArguments.length); } @@ -158,11 +158,8 @@ public class EvalTypeId extends CPPEvaluation { } } IType type = CPPTemplates.instantiateType(fInputType, tpMap, packOffset, within, point); - if (args == null) { - if (type == fInputType) - return this; - args = fArguments; - } + if (args == fArguments && type == fInputType) + return this; return new EvalTypeId(type, args); } From e1ef59e384c0f1c7bed4ab1cd969187c26de6b9c Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 7 Aug 2012 12:17:20 -0700 Subject: [PATCH 28/31] Cosmetics. --- .../eclipse/cdt/internal/core/dom/Linkage.java | 2 +- .../dom/parser/cpp/CPPClassSpecialization.java | 4 ++-- ...atePartialSpecializationSpecialization.java | 9 ++++----- .../composite/cpp/CompositeCPPClassScope.java | 18 +++++++++--------- .../cpp/CompositeCPPClassSpecialization.java | 12 ++++++------ ...atePartialSpecializationSpecialization.java | 2 +- .../dom/cpp/PDOMCPPClassSpecialization.java | 12 ++++++------ 7 files changed, 29 insertions(+), 30 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/Linkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/Linkage.java index 485e092db80..4414f2d530a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/Linkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/Linkage.java @@ -33,7 +33,7 @@ public class Linkage implements ILinkage { } public static String getLinkageName(int linkageID) throws CoreException { - switch(linkageID) { + switch (linkageID) { case NO_LINKAGE_ID: return NO_LINKAGE_NAME; case C_LINKAGE_ID: return C_LINKAGE_NAME; case CPP_LINKAGE_ID: return CPP_LINKAGE_NAME; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java index 1d6cea256da..e8a8497f532 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java @@ -122,7 +122,7 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPBase[] getBases() { - return getBases(null); + return getBases(null); // Instantiation of dependent expression may not work. } @Override @@ -164,7 +164,7 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPConstructor[] getConstructors() { - return getConstructors(null); + return getConstructors(null); // Instantiation of dependent expression may not work. } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecializationSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecializationSpecialization.java index 443fc1218c8..8fbdd440b41 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecializationSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecializationSpecialization.java @@ -6,7 +6,7 @@ * 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; @@ -30,8 +30,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; */ public class CPPClassTemplatePartialSpecializationSpecialization extends CPPClassSpecialization implements ICPPClassTemplatePartialSpecializationSpecialization, ICPPInternalClassTemplate { - - private ObjectMap instances = null; + private ObjectMap instances; private ICPPDeferredClassInstance fDeferredInstance; private final ICPPClassTemplate fClassTemplate; private final ICPPTemplateArgument[] fArguments; @@ -70,7 +69,7 @@ public class CPPClassTemplatePartialSpecializationSpecialization extends CPPClas public synchronized ICPPTemplateInstance[] getAllInstances() { if (instances != null) { ICPPTemplateInstance[] result= new ICPPTemplateInstance[instances.size()]; - for (int i=0; i < instances.size(); i++) { + for (int i= 0; i < instances.size(); i++) { result[i]= (ICPPTemplateInstance) instances.getAt(i); } return result; @@ -142,7 +141,7 @@ public class CPPClassTemplatePartialSpecializationSpecialization extends CPPClas @Override public ICPPTemplateArgument getDefaultArgFromIndex(int paramPos) throws DOMException { - // no default arguments for partial specializations + // No default arguments for partial specializations return null; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassScope.java index ab9e34545f0..9de1673b314 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassScope.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Ferguson (Symbian) - Initial implementation - * Markus Schorn (Wind River Systems) + * Andrew Ferguson (Symbian) - Initial implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; @@ -43,8 +43,8 @@ class CompositeCPPClassScope extends CompositeScope implements ICPPClassScope { public ICPPMethod[] getImplicitMethods() { ICPPClassScope rscope = (ICPPClassScope) ((ICPPClassType)rbinding).getCompositeScope(); ICPPMethod[] result = rscope.getImplicitMethods(); - for(int i=0; i Date: Tue, 7 Aug 2012 12:24:52 -0700 Subject: [PATCH 29/31] Bug 299911. A minor bug fix. --- .../cpp/CompositeCPPClassSpecializationScope.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java index e184fb5baec..3a1ef81a859 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java @@ -8,6 +8,7 @@ * Contributors: * Andrew Ferguson (Symbian) - Initial implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; @@ -67,14 +68,14 @@ public class CompositeCPPClassSpecializationScope extends CompositeScope impleme } @Override - public ICPPMethod[] getImplicitMethods(IASTNode point) { - return getImplicitMethods(null); + public ICPPMethod[] getImplicitMethods() { + return getImplicitMethods(null); // Instantiation of dependent expression may not work. } @Override - public ICPPMethod[] getImplicitMethods() { + public ICPPMethod[] getImplicitMethods(IASTNode point) { createDelegate(); - return fDelegate.getImplicitMethods(); + return fDelegate.getImplicitMethods(point); } @Override @@ -103,7 +104,7 @@ public class CompositeCPPClassSpecializationScope extends CompositeScope impleme @Override public ICPPConstructor[] getConstructors() { - return getConstructors(null); + return getConstructors(null); // Instantiation of dependent expression may not work. } @Override From 4079362341a52bbf78fd5ead4738fd616f321acf Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 8 Aug 2012 15:08:33 -0700 Subject: [PATCH 30/31] Cosmetics. --- .../cdt/core/dom/ast/cpp/ICPPClassScope.java | 20 +- .../eclipse/cdt/core/parser/IScannerInfo.java | 18 +- .../cdt/core/parser/ISignificantMacros.java | 3 +- .../dom/parser/cpp/CPPASTTranslationUnit.java | 8 +- .../dom/parser/cpp/GNUCPPSourceParser.java | 686 +++++++++--------- .../src/org/eclipse/cdt/core/CCorePlugin.java | 133 ++-- .../ui/editor/OverrideIndicatorManager.java | 23 +- 7 files changed, 424 insertions(+), 467 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassScope.java index ef7b553a89c..fbe1ea328e0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassScope.java @@ -1,13 +1,13 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2004, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * Andrew Niefer (IBM Corporation) - initial API and implementation - * Markus Schorn (Wind River Systems) + * Contributors: + * Andrew Niefer (IBM Corporation) - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; @@ -25,8 +25,8 @@ public interface ICPPClassScope extends ICPPScope { /** * Returns an array of methods that were implicitly added to this class - * scope. These methods may or may not have been explicitly declared in the - * code. The methods that will be implicitly declared are: the default + * scope. These methods may or may not have been explicitly declared in + * the code. The methods that will be implicitly declared are: the default * constructor, copy constructor, copy assignment operator, and destructor */ public ICPPMethod[] getImplicitMethods(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScannerInfo.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScannerInfo.java index 294c2d4fdfe..339b6bb1b47 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScannerInfo.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScannerInfo.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.parser; @@ -19,11 +19,10 @@ import java.util.Map; */ public interface IScannerInfo { /** - * Returns a Map containing all the defined preprocessor - * symbols and their values. + * Returns a {@link Map} containing all the defined preprocessor symbols and their values. * Symbols defined without values have an empty string for a value. For - * example,-Dsymbol=value would have a map entry (symbol,value). A symbol - * defined as -Dsymbol= would have a map entry of (symbol,""). + * example, -Dsymbol=value would have a map entry (symbol, value). A symbol + * defined as -Dsymbol= would have a map entry of (symbol, ""). */ public Map getDefinedSymbols(); @@ -36,9 +35,10 @@ public interface IScannerInfo { *
E.g.: /System/Library/Frameworks/__framework__.framework/Headers/__header__, * /System/Library/Frameworks/__framework__.framework/PrivateHeaders/__header__ * would handle the framework search for '/System/Library/Frameworks' - *
The variables are handled only, if a search path element makes use of both of the variables. - * The __framework__ variable will receive the first segment of the include, the __header__ variable - * the rest. Such a search path element is not used for directives with a single segment (e.g. 'header.h') + *
The variables are handled only, if a search path element makes use of both of + * the variables. The __framework__ variable will receive the first segment of the include, + * the __header__ variable the rest. Such a search path element is not used for directives + * with a single segment (e.g. 'header.h') */ public String[] getIncludePaths(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISignificantMacros.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISignificantMacros.java index e4182f46133..f231a2f82fe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISignificantMacros.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISignificantMacros.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.core.parser; import org.eclipse.cdt.core.parser.util.CharArrayUtils; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java index 801741e72df..1759cb2165e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -40,8 +40,8 @@ import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent; * C++-specific implementation of a translation-unit. */ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPASTTranslationUnit, IASTAmbiguityParent { - private CPPNamespaceScope fScope = null; - private ICPPNamespace fBinding = null; + private CPPNamespaceScope fScope; + private ICPPNamespace fBinding; private final CPPScopeMapper fScopeMapper= new CPPScopeMapper(this); public CPPASTTranslationUnit() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index e4634d81fb0..b43368d784f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -165,12 +165,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private final IIndex index; protected ICPPASTTranslationUnit translationUnit; - private int functionBodyCount= 0; + private int functionBodyCount; private char[] currentClassName; private final ICPPNodeFactory nodeFactory; private TemplateIdStrategy fTemplateParameterListStrategy; - + public GNUCPPSourceParser(IScanner scanner, ParserMode mode, IParserLogService log, ICPPParserExtensionConfiguration config) { this(scanner, mode, log, config, null); @@ -181,10 +181,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IIndex index) { super(scanner, log, mode, CPPNodeFactory.getDefault(), config.supportStatementsInExpressions(), - config.supportTypeofUnaryExpressions(), - config.supportAlignOfUnaryExpression(), + config.supportTypeofUnaryExpressions(), + config.supportAlignOfUnaryExpression(), config.supportKnRC(), - config.supportAttributeSpecifiers(), + config.supportAttributeSpecifiers(), config.supportDeclspecSpecifiers(), config.getBuiltinBindingsProvider()); allowCPPRestrict = config.allowRestrictPointerOperators(); @@ -210,7 +210,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { throw backtrack; } - + private IASTName qualifiedName() throws BacktrackException, EndOfFileException { return ambiguousQualifiedName(CastExprCtx.eNotInBExpr); } @@ -218,7 +218,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private IASTName ambiguousQualifiedName(CastExprCtx ctx) throws BacktrackException, EndOfFileException { TemplateIdStrategy strat= new TemplateIdStrategy(); IToken m= mark(); - for(;;) { + while (true) { try { return qualifiedName(ctx, strat); } catch (BacktrackException e) { @@ -237,7 +237,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private IASTName qualifiedName(CastExprCtx ctx, ITemplateIdStrategy strat) throws BacktrackException, EndOfFileException { if (strat == null) return ambiguousQualifiedName(ctx); - + ICPPASTQualifiedName qname= null; IASTName name= null; final int offset= LA(1).getOffset(); @@ -250,9 +250,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { boolean mustBeLast= false; boolean haveName= false; - loop: for(;;) { + loop: while (true) { boolean keywordTemplate= false; - if (qname != null && LT(1) == IToken.t_template) { + if (qname != null && LT(1) == IToken.t_template) { consume(); keywordTemplate= true; } @@ -270,7 +270,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IToken nt= consume(); name = buildName(destructorOffset, nt); break; - + case IToken.t_operator: name= operatorId(); break; @@ -287,7 +287,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } haveName= true; - + // Check for template-id if (LTcatchEOF(1) == IToken.tLT) { final boolean inBinaryExpression = ctx != CastExprCtx.eNotInBExpr; @@ -303,7 +303,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (templateID) { if (haveArgs == -1) throwBacktrack(LA(1)); - + name= addTemplateArguments(name, strat); } } @@ -362,7 +362,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IToken end= LA(1); switch (end.getType()) { case IToken.tGT_in_SHIFTR: - case IToken.tGT: + case IToken.tGT: consume(); break; case IToken.tEOC: @@ -389,7 +389,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } /** - * Makes a fast check whether there could be template arguments. + * Makes a fast check whether there could be template arguments. * -1: no, 0: ambiguous, 1: yes */ private static final int NO_TEMPLATE_ID= -1; @@ -409,53 +409,53 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.tEOC: case IToken.tCOMPLETION: return AMBIGUOUS_TEMPLATE_ID; - + case IToken.tLT: if (nk == 0) { angleDepth++; } break; case IToken.tGT_in_SHIFTR: - case IToken.tGT: + case IToken.tGT: if (nk == 0) { --angleDepth; if (!inBinaryExpression) return angleDepth == 0 ? TEMPLATE_ID : AMBIGUOUS_TEMPLATE_ID; - + int end= endsTemplateIDInBinaryExpression(); if (end == NO_TEMPLATE_ID) { if (angleDepth == 0) return NO_TEMPLATE_ID; } else { return AMBIGUOUS_TEMPLATE_ID; - } + } } break; - case IToken.tLBRACKET: + case IToken.tLBRACKET: if (nk == 0) { nk= IToken.tLBRACKET; depth= 0; } else if (nk == IToken.tLBRACKET) { depth++; - } + } break; - case IToken.tRBRACKET: + case IToken.tRBRACKET: if (nk == IToken.tLBRACKET) { if (--depth < 0) { nk= 0; } } break; - case IToken.tLPAREN: + case IToken.tLPAREN: if (nk == 0) { nk= IToken.tLPAREN; depth= 0; } else if (nk == IToken.tLPAREN) { depth++; - } + } break; - case IToken.tRPAREN: + case IToken.tRPAREN: if (nk == IToken.tLPAREN) { if (--depth < 0) { nk= 0; @@ -476,9 +476,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { backup(mark); } } - + /** - * If '>' is followed by an expression, then it denotes the binary operator, + * If '>' is followed by an expression, then it denotes the binary operator, * else it is the end of a template-id, or special-cast. */ private int endsTemplateIDInBinaryExpression() { @@ -493,10 +493,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return AMBIGUOUS_TEMPLATE_ID; // Start of unary expression - case IToken.tMINUS: - case IToken.tPLUS: - case IToken.tAMPER: - case IToken.tSTAR: + case IToken.tMINUS: + case IToken.tPLUS: + case IToken.tAMPER: + case IToken.tSTAR: case IToken.tNOT: case IToken.tBITCOMPLEMENT: case IToken.tINCR: @@ -506,7 +506,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.t_sizeof: case IGCCToken.t___alignof__: return NO_TEMPLATE_ID; - + // Start of a postfix expression case IToken.t_typename: case IToken.t_char: @@ -527,7 +527,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.t_const_cast: case IToken.t_typeid: return NO_TEMPLATE_ID; - + // Start of a primary expression case IToken.tINTEGER: case IToken.tFLOATINGPT: @@ -546,7 +546,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.t_operator: case IToken.tCOMPLETION: return NO_TEMPLATE_ID; - + // Tokens that end an expression case IToken.tSEMI: case IToken.tCOMMA: @@ -565,8 +565,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.tGT_in_SHIFTR: case IToken.tEQUAL: return TEMPLATE_ID; - - default: + + default: return AMBIGUOUS_TEMPLATE_ID; } } @@ -587,7 +587,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } else { needComma= true; } - + IASTNode node= templateArgument(strat); if (list == null) { list= new ArrayList(); @@ -616,7 +616,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { || lt1 == IToken.tEOC || lt1 == IToken.tELLIPSIS)) { // This is potentially a type-id, now check ambiguity with id-expression IASTDeclSpecifier declspec= typeId.getDeclSpecifier(); - if (declspec instanceof IASTNamedTypeSpecifier) { + if (declspec instanceof IASTNamedTypeSpecifier) { final IASTNamedTypeSpecifier namedDeclspec = (IASTNamedTypeSpecifier) declspec; IASTName name= namedDeclspec.getName(); if (name.contains(typeId)) { @@ -652,7 +652,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } return typeId; } - + // Not a type-id, parse as expression backup(argStart); IASTExpression expr= expression(ExprKind.eAssignment, BinaryExprCtx.eInTemplateID, null, strat); @@ -682,12 +682,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { switch (lt1) { case IToken.tLPAREN: op = OverloadableOperator.PAREN; // operator () - consume(); + consume(); endOffset = consume(IToken.tRPAREN).getEndOffset(); break; case IToken.tLBRACKET: op = OverloadableOperator.BRACKET; // operator [] - consume(); + consume(); endOffset = consume(IToken.tRBRACKET).getEndOffset(); break; case IToken.t_new: @@ -714,8 +714,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { endOffset= consume().getEndOffset(); } break; - } - + } + if (op != null) { IASTName name= nodeFactory.newOperatorName(op.toCharArray()); setRange(name, firstToken.getOffset(), endOffset); @@ -750,17 +750,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private IASTExpression expression(final ExprKind kind, final BinaryExprCtx ctx, IASTInitializerClause expr, ITemplateIdStrategy strat) throws EndOfFileException, BacktrackException { final boolean allowComma= kind==ExprKind.eExpression; boolean allowAssignment= kind !=ExprKind.eConstant; - + if (allowAssignment && LT(1) == IToken.t_throw) { return throwExpression(); - } + } final int startOffset= expr != null ? ((ASTNode) expr).getOffset() : LA(1).getOffset(); int lt1; int conditionCount= 0; BinaryOperator lastOperator= null; NameOrTemplateIDVariants variants= null; - + if (expr == null) { Object e = castExpressionForBinaryExpression(strat); if (e instanceof IASTExpression) { @@ -780,7 +780,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { boolean allowThrow= false; // Brace initializers are allowed on the right hand side of an expression boolean allowBraceInitializer= false; - + BacktrackException tryRecovery= null; final int operatorOffset= LA().getOffset(); lt1= LT(1); @@ -789,7 +789,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { conditionCount++; // ? : // Precedence: 25 is lower than precedence of logical or; 0 is lower than precedence of expression - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 25, 0); + lastOperator= new BinaryOperator(lastOperator, expr, lt1, 25, 0); allowAssignment= true; // assignment expressions will be subsumed by the conditional expression allowThrow= true; break; @@ -799,13 +799,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { doneExpression= true; } else { // ? : - // Precedence: 0 is lower than precedence of expression; 15 is lower than precedence of assignment; - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 0, 15); + // Precedence: 0 is lower than precedence of expression; 15 is lower than precedence of assignment; + lastOperator= new BinaryOperator(lastOperator, expr, lt1, 0, 15); allowAssignment= true; // assignment expressions will be subsumed by the conditional expression allowThrow= true; } break; - + case IToken.tCOMMA: allowThrow= true; if (!allowComma && conditionCount == 0) { @@ -831,13 +831,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { doneExpression= true; } else { // Assignments group right to left - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 21, 20); + lastOperator= new BinaryOperator(lastOperator, expr, lt1, 21, 20); allowBraceInitializer= true; } break; case IToken.tOR: - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 30, 31); + lastOperator= new BinaryOperator(lastOperator, expr, lt1, 30, 31); break; case IToken.tAND: lastOperator= new BinaryOperator(lastOperator, expr, lt1, 40, 41); @@ -878,8 +878,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { backtrack.initialize(token.getOffset(), token.getLength()); tryRecovery= backtrack; break; - } - + } + lt1= IToken.tSHIFTR; // convert back consume(); // consume the extra token //$FALL-THROUGH$ @@ -904,19 +904,19 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { doneExpression= true; break; } - + if (!doneExpression && tryRecovery == null) { consume(); // consumes the operator - + // Link variants that are closed by the new operator if (variants != null) { variants.closeVariants(operatorOffset, lastOperator); } - + // Determine next sub-expression if (lt1 == IToken.tQUESTION && LT(1) == IToken.tCOLON) { // Missing sub-expression after '?' (gnu-extension) - expr= null; + expr= null; } else if (allowThrow && LT(1) == IToken.t_throw) { // Throw expression expr= throwExpression(); @@ -939,20 +939,20 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } else { final Variant ae = (Variant) e; expr= ae.getExpression(); - if (variants == null) + if (variants == null) variants= new NameOrTemplateIDVariants(); - + variants.addBranchPoint(ae.getNext(), lastOperator, allowAssignment, conditionCount); } } catch (BacktrackException e) { - if (variants == null) + if (variants == null) throw e; tryRecovery= e; backup(m); } } } - + if (tryRecovery != null || doneExpression) { if (variants != null) { if (lt1 == IToken.tEOC) { @@ -961,7 +961,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // Try fall-back to an open variant Variant fallback= variants.findFallback(operatorOffset); if (fallback == null) { - if (tryRecovery != null) + if (tryRecovery != null) throw tryRecovery; variants.discardOpenVariants(operatorOffset); } else { @@ -982,7 +982,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } } } - } + } } while (!doneExpression); // Check for incomplete conditional expression @@ -994,7 +994,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { setRange(result, startOffset, calculateEndOffset(expr)); return result; } - + return buildExpression(lastOperator, expr); } @@ -1003,15 +1003,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (s != null) { return castExpression(CastExprCtx.eDirectlyInBExpr, s); } - + TemplateIdStrategy strat= new TemplateIdStrategy(); Variant variants= null; IASTExpression singleExpression= null; IASTName[] firstNames= null; - + final IToken mark= mark(); IToken lastToken= null; - for(;;) { + while (true) { try { IASTExpression e = castExpression(CastExprCtx.eDirectlyInBExpr, strat); if (variants == null) { @@ -1027,15 +1027,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { lastToken= LA(); if (variants != null) { variants = new Variant(variants, e, strat.getTemplateNames(), lastToken.getOffset()); - } + } if (!strat.setNextAlternative()) { break; } } catch (BacktrackException e) { if (!strat.setNextAlternative()) { - if (lastToken == null) + if (lastToken == null) throw e; - + backup(lastToken); break; } @@ -1045,7 +1045,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return variants != null ? variants : singleExpression; } - @Override protected IASTExpression buildBinaryExpression(int operator, IASTExpression expr1, IASTInitializerClause expr2, int lastOffset) { IASTBinaryExpression result = nodeFactory.newBinaryExpression(operator, expr1, expr2); @@ -1063,8 +1062,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { backup(throwToken); consume(); } - int o = throwExpression != null ? calculateEndOffset(throwExpression) - : throwToken.getEndOffset(); + int o = throwExpression != null ? + calculateEndOffset(throwExpression) : throwToken.getEndOffset(); return buildUnaryExpression(ICPPASTUnaryExpression.op_throw, throwExpression, throwToken.getOffset(), o); // fix for 95225 } @@ -1095,7 +1094,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return deleteExpression; } - /** * Parse a new-expression. There is room for ambiguities. With P for placement, T for typeid, * and I for initializer the potential patterns (with the new omitted) are: @@ -1126,11 +1124,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { try { plcmt= expressionList(); endOffset= consumeOrEOC(IToken.tRPAREN).getEndOffset(); - + final int lt1= LT(1); if (lt1 == IToken.tEOC) { return newExpression(isGlobal, plcmt, typeid, isNewTypeId, init, offset, endOffset); - } + } if (lt1 == IToken.tLPAREN) { // (P)(T) ... isNewTypeId= false; @@ -1153,8 +1151,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { int lt1= LT(1); if (lt1 == IToken.tEOC) return newExpression(isGlobal, plcmt, typeid, isNewTypeId, init, offset, endOffset); - - if (lt1 == IToken.tLPAREN || lt1 == IToken.tLBRACE) { + + if (lt1 == IToken.tLPAREN || lt1 == IToken.tLBRACE) { init= bracedOrCtorStyleInitializer(); endOffset= calculateEndOffset(init); return newExpression(isGlobal, plcmt, typeid, isNewTypeId, init, offset, endOffset); @@ -1169,13 +1167,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { try { typeid2= typeId(DeclarationOptions.TYPEID); endOffset2= consumeOrEOC(IToken.tRPAREN).getEndOffset(); - + final int lt1= LT(1); - if (lt1 == IToken.tEOC) + if (lt1 == IToken.tEOC) return newExpression(isGlobal, null, typeid2, false, init2, offset, endOffset2); - + if (lt1 == IToken.tLPAREN || lt1 == IToken.tLBRACE) { - if (plcmt != null && + if (plcmt != null && ASTQueries.findTypeRelevantDeclarator(typeid2.getAbstractDeclarator()) instanceof IASTArrayDeclarator) { throwBacktrack(LA(1)); } @@ -1189,9 +1187,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { throw e; endOffset2= -1; } - - if (plcmt == null || endOffset2 > endOffset) + if (plcmt == null || endOffset2 > endOffset) return newExpression(isGlobal, null, typeid2, false, init2, offset, endOffset2); if (endOffset != endOffset2) { @@ -1208,9 +1205,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { ((ASTNode) ambiguity).setOffsetAndLength((ASTNode) ex1); return ambiguity; } - + // T ... - final IASTTypeId typeid = typeId(DeclarationOptions.TYPEID_NEW); + final IASTTypeId typeid = typeId(DeclarationOptions.TYPEID_NEW); int endOffset = calculateEndOffset(typeid); IASTInitializer init= null; final int lt1= LT(1); @@ -1222,10 +1219,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return newExpression(isGlobal, null, typeid, true, init, offset, endOffset); } - private IASTExpression newExpression(boolean isGlobal, List plcmt, IASTTypeId typeid, boolean isNewTypeId, IASTInitializer init, int offset, int endOffset) { - + IASTInitializerClause[] plcmtArray= null; if (plcmt != null && !plcmt.isEmpty()) { plcmtArray= plcmt.toArray(new IASTInitializerClause[plcmt.size()]); @@ -1237,7 +1233,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return result; } - @Override protected IASTExpression unaryExpression(CastExprCtx ctx, ITemplateIdStrategy strat) throws EndOfFileException, BacktrackException { switch (LT(1)) { @@ -1280,7 +1275,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { setRange(idexpr, id); IASTUnaryExpression expr= nodeFactory.newUnaryExpression(IASTUnaryExpression.op_sizeofParameterPack, idexpr); final int lt1= LT(1); - if (lt1 == IToken.tEOC) { + if (lt1 == IToken.tEOC) { setRange(expr, offset, calculateEndOffset(id)); } else { final int endOffset = consume(IToken.tRPAREN).getEndOffset(); // ) @@ -1288,12 +1283,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } return expr; } - return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(), + return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(), IASTTypeIdExpression.op_sizeof, IASTUnaryExpression.op_sizeof, ctx, strat); case IGCCToken.t___alignof__: - return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(), + return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(), IASTTypeIdExpression.op_alignof, IASTUnaryExpression.op_alignOf, ctx, strat); - + case IGCCToken.tTT_has_nothrow_assign: case IGCCToken.tTT_has_nothrow_constructor: case IGCCToken.tTT_has_nothrow_copy: @@ -1311,7 +1306,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IGCCToken.tTT_is_polymorphic: case IGCCToken.tTT_is_union: return parseTypeTrait(); - + default: return postfixExpression(ctx, strat); } @@ -1320,7 +1315,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private IASTExpression parseTypeTrait() throws EndOfFileException, BacktrackException { IToken first= consume(); final boolean isBinary= isBinaryTrait(first); - + consume(IToken.tLPAREN); IASTTypeId typeId= typeId(DeclarationOptions.TYPEID); IASTTypeId secondTypeId= null; @@ -1341,7 +1336,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } private boolean isBinaryTrait(IToken first) { - switch(first.getType()) { + switch (first.getType()) { case IGCCToken.tTT_is_base_of: return true; } @@ -1349,17 +1344,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } private Operator getBinaryTypeTraitOperator(IToken first) { - switch(first.getType()) { + switch (first.getType()) { case IGCCToken.tTT_is_base_of: return IASTBinaryTypeIdExpression.Operator.__is_base_of; } - + assert false; return null; } private int getUnaryTypeTraitOperator(IToken first) { - switch(first.getType()) { + switch (first.getType()) { case IGCCToken.tTT_has_nothrow_assign: return IASTTypeIdExpression.op_has_nothrow_assign; case IGCCToken.tTT_has_nothrow_constructor: @@ -1400,7 +1395,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * [gnu-extension, compound literals in c++] * ( type-name ) { initializer-list } * ( type-name ) { initializer-list , } - * + * * primary-expression * postfix-expression [ expression ] * postfix-expression [ braced-init-list ] @@ -1439,7 +1434,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.t_const_cast: firstExpression = specialCastExpression(ICPPASTCastExpression.op_const_cast); break; - + case IToken.t_typeid: // 'typeid' ( expression ) // 'typeid' ( type-id ) @@ -1447,7 +1442,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { firstExpression = parseTypeidInParenthesisOrUnaryExpression(true, so, ICPPASTTypeIdExpression.op_typeid, ICPPASTUnaryExpression.op_typeid, ctx, strat); break; - + case IToken.tLPAREN: // Gnu-extension: compound literals in c++ // ( type-name ) { initializer-list } @@ -1462,12 +1457,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IASTInitializer i = bracedInitList(false); firstExpression= nodeFactory.newTypeIdInitializerExpression(t, i); setRange(firstExpression, offset, calculateEndOffset(i)); - break; + break; } } } catch (BacktrackException bt) { } - backup(m); + backup(m); firstExpression= primaryExpression(ctx, strat); break; @@ -1493,7 +1488,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IGCCToken.t_typeof: firstExpression = simpleTypeConstructorExpression(simpleTypeSpecifier()); break; - + default: firstExpression = primaryExpression(ctx, strat); if (firstExpression instanceof IASTIdExpression && LT(1) == IToken.tLBRACE) { @@ -1528,7 +1523,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) == IToken.tRPAREN) { initArray= IASTExpression.EMPTY_EXPRESSION_ARRAY; } else { - final List exprList = expressionList(); + final List exprList = expressionList(); initArray = exprList.toArray(new IASTInitializerClause[exprList.size()]); } endOffset = consumeOrEOC(IToken.tRPAREN).getEndOffset(); @@ -1547,7 +1542,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { firstExpression = buildUnaryExpression(IASTUnaryExpression.op_postFixDecr, firstExpression, ((ASTNode) firstExpression).getOffset(), endOffset); break; - + case IToken.tDOT: // member access IToken dot = consume(); @@ -1557,9 +1552,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } IASTName name = qualifiedName(ctx, strat); - + if (name == null) - throwBacktrack(((ASTNode) firstExpression).getOffset(), + throwBacktrack(((ASTNode) firstExpression).getOffset(), ((ASTNode) firstExpression).getLength() + dot.getLength()); ICPPASTFieldReference fieldReference = nodeFactory.newFieldReference(name, firstExpression); @@ -1580,11 +1575,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } name = qualifiedName(ctx, strat); - + if (name == null) - throwBacktrack(((ASTNode) firstExpression).getOffset(), + throwBacktrack(((ASTNode) firstExpression).getOffset(), ((ASTNode) firstExpression).getLength() + arrow.getLength()); - + fieldReference = nodeFactory.newFieldReference(name, firstExpression); fieldReference.setIsPointerDereference(true); fieldReference.setIsTemplate(isTemplate); @@ -1603,7 +1598,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { protected IASTAmbiguousExpression createAmbiguousExpression() { return new CPPASTAmbiguousExpression(); } - + @Override protected IASTAmbiguousExpression createAmbiguousBinaryVsCastExpression(IASTBinaryExpression binary, IASTCastExpression castExpr) { return new CPPASTAmbiguousBinaryVsCastExpression(binary, castExpr); @@ -1617,7 +1612,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { protected ICPPASTAmbiguousTemplateArgument createAmbiguousTemplateArgument() { return new CPPASTAmbiguousTemplateArgument(); } - private IASTExpression simpleTypeConstructorExpression(ICPPASTDeclSpecifier declSpec) throws EndOfFileException, BacktrackException { IASTInitializer initializer = bracedOrCtorStyleInitializer(); @@ -1634,11 +1628,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // TO DO: we need more literals... case IToken.tINTEGER: t = consume(); - literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_integer_constant, t.getImage()); + literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_integer_constant, t.getImage()); return setRange(literalExpression, t.getOffset(), t.getEndOffset()); case IToken.tFLOATINGPT: t = consume(); - literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_float_constant, t.getImage()); + literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_float_constant, t.getImage()); return setRange(literalExpression, t.getOffset(), t.getEndOffset()); case IToken.tSTRING: case IToken.tLSTRING: @@ -1650,24 +1644,24 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.tUTF16CHAR: case IToken.tUTF32CHAR: t = consume(); - literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_char_constant, t.getImage()); + literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_char_constant, t.getImage()); return setRange(literalExpression, t.getOffset(), t.getEndOffset()); case IToken.t_false: t = consume(); - literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_false, t.getImage()); + literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_false, t.getImage()); return setRange(literalExpression, t.getOffset(), t.getEndOffset()); case IToken.t_true: t = consume(); - literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_true, t.getImage()); + literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_true, t.getImage()); return setRange(literalExpression, t.getOffset(), t.getEndOffset()); case IToken.t_nullptr: t= consume(); - literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_nullptr, t.getImage()); + literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_nullptr, t.getImage()); return setRange(literalExpression, t.getOffset(), t.getEndOffset()); - + case IToken.t_this: t = consume(); - literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_this, t.getImage()); + literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_this, t.getImage()); return setRange(literalExpression, t.getOffset(), t.getEndOffset()); case IToken.tLPAREN: if (supportStatementsInExpressions && LT(2) == IToken.tLBRACE) { @@ -1696,7 +1690,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } case IToken.tLBRACKET: return lambdaExpression(); - + default: IToken la = LA(1); int startingOffset = la.getOffset(); @@ -1725,11 +1719,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { final int offset= LA().getOffset(); ICPPASTLambdaExpression lambdaExpr= nodeFactory.newLambdaExpression(); - + // Lambda introducer consume(IToken.tLBRACKET); boolean needComma= false; - switch(LT(1)) { + switch (LT(1)) { case IToken.tASSIGN: lambdaExpr.setCaptureDefault(CaptureDefault.BY_COPY); consume(); @@ -1744,31 +1738,31 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } break; } - loop: for(;;) { + loop: while (true) { switch (LT(1)) { - case IToken.tEOC: + case IToken.tEOC: return setRange(lambdaExpr, offset, LA().getEndOffset()); - case IToken.tRBRACKET: + case IToken.tRBRACKET: consume(); break loop; } - + if (needComma) { consume(IToken.tCOMMA); } - + ICPPASTCapture cap= capture(); lambdaExpr.addCapture(cap); needComma= true; } - + if (LT(1) == IToken.tLPAREN) { ICPPASTFunctionDeclarator dtor = functionDeclarator(true); lambdaExpr.setDeclarator(dtor); if (LT(1) == IToken.tEOC) return setRange(lambdaExpr, offset, calculateEndOffset(dtor)); } - + IASTCompoundStatement body = functionBody(); lambdaExpr.setBody(body); return setRange(lambdaExpr, offset, calculateEndOffset(body)); @@ -1777,7 +1771,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private ICPPASTCapture capture() throws EndOfFileException, BacktrackException { final int offset= LA().getOffset(); final ICPPASTCapture result = nodeFactory.newCapture(); - + switch (LT(1)) { case IToken.t_this: return setRange(result, offset, consume().getEndOffset()); @@ -1786,15 +1780,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { result.setIsByReference(true); break; } - + final IASTName identifier= identifier(); result.setIdentifier(identifier); - + if (LT(1) == IToken.tELLIPSIS) { result.setIsPackExpansion(true); return setRange(result, offset, consume().getEndOffset()); - } - + } + return setRange(result, offset, calculateEndOffset(identifier)); } @@ -1826,7 +1820,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { break; default: operator = IASTCastExpression.op_cast; - break; + break; } return buildCastExpression(operator, typeID, operand, offset, endOffset); } @@ -1836,7 +1830,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * using-declaration: using typename? ::? nested-name-specifier * unqualified-id ; using :: unqualified-id ; using-directive: using * namespace ::? nested-name-specifier? namespace-name ; - * + * * @throws BacktrackException * request for a backtrack */ @@ -1859,7 +1853,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } attributes = __attribute__(); - + switch (LT(1)) { case IToken.tSEMI: case IToken.tEOC: @@ -1907,13 +1901,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return result; } - /** * static_assert-declaration: static_assert ( constant-expression , string-literal ) ; */ private ICPPASTStaticAssertDeclaration staticAssertDeclaration() throws EndOfFileException, BacktrackException { - int offset= consume(IToken.t_static_assert).getOffset(); + int offset= consume(IToken.t_static_assert).getOffset(); consume(IToken.tLPAREN); IASTExpression e= constantExpression(); int endOffset= calculateEndOffset(e); @@ -1924,7 +1917,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { consume(IToken.tRPAREN); endOffset= consume(IToken.tSEMI).getEndOffset(); } - ICPPASTStaticAssertDeclaration assertion = nodeFactory.newStaticAssertion(e, lit); + ICPPASTStaticAssertDeclaration assertion = nodeFactory.newStaticAssertion(e, lit); return setRange(assertion, offset, endOffset); } @@ -1932,14 +1925,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * Implements Linkage specification in the ANSI C++ grammar. * linkageSpecification : extern "string literal" declaration | extern * "string literal" { declaration-seq } - * + * * @throws BacktrackException * request for a backtrack */ protected ICPPASTLinkageSpecification linkageSpecification() throws EndOfFileException, BacktrackException { int offset= consume().getOffset(); // t_extern String spec = consume().getImage(); // tString - ICPPASTLinkageSpecification linkage = nodeFactory.newLinkageSpecification(spec); + ICPPASTLinkageSpecification linkage = nodeFactory.newLinkageSpecification(spec); if (LT(1) == IToken.tLBRACE) { declarationListInBraces(linkage, offset, DeclarationOptions.GLOBAL); @@ -1953,15 +1946,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return linkage; } - /** * Represents the amalgamation of template declarations, template * instantiations and specializations in the ANSI C++ grammar. * template-declaration: export? template < template-parameter-list > * declaration explicit-instantiation: template declaration * explicit-specialization: template <>declaration - * @param option - * + * @param option + * * @throws BacktrackException * request for a backtrack */ @@ -1987,9 +1979,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { explicitInstMod= ICPPASTExplicitTemplateInstantiation.INLINE; break; } - + consume(IToken.t_template); - + if (LT(1) != IToken.tLT) { // explicit-instantiation IASTDeclaration d = declaration(option); @@ -1998,12 +1990,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { setRange(ti, offset, calculateEndOffset(d)); return ti; } - + // Modifiers for explicit instantiations if (explicitInstMod != 0) { throwBacktrack(LA(1)); } - consume(IToken.tLT); + consume(IToken.tLT); if (LT(1) == IToken.tGT) { // explicit-specialization consume(); @@ -2037,7 +2029,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * template-argument-list: template-argument template-argument-list , * template-argument template-argument: assignment-expression type-id * id-expression - * + * * @throws BacktrackException * request for a backtrack */ @@ -2046,7 +2038,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { try { List result = new ArrayList(DEFAULT_PARM_LIST_SIZE); IToken m= mark(); - for(;;) { + while (true) { try { return templateParameterList(result); } catch (BacktrackException e) { @@ -2111,7 +2103,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { defaultValue = typeId(DeclarationOptions.TYPEID); // type-id endOffset = calculateEndOffset(defaultValue); } - + // Check if followed by comma switch (LT(1)) { case IToken.tGT: @@ -2149,7 +2141,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) == IToken.tASSIGN) { // optional = type-id if (parameterPack) throw backtrack; - + consume(); defaultValue = primaryExpression(CastExprCtx.eNotInBExpr, null); endOffset = calculateEndOffset(defaultValue); @@ -2157,7 +2149,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } else { identifierName = nodeFactory.newName(); } - + ICPPASTTemplatedTypeTemplateParameter tpar = nodeFactory.newTemplatedTypeTemplateParameter(identifierName, defaultValue); tpar.setIsParameterPack(parameterPack); setRange(tpar, start.getOffset(), endOffset); @@ -2167,13 +2159,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { tpar.addTemplateParameter(p); } return tpar; - } - + } + // Try non-type template parameter return parameterDeclaration(); } - /** * The most abstract construct within a translationUnit : a declaration. * declaration : {"asm"} asmDefinition | {"namespace"} namespaceDefinition | @@ -2183,7 +2174,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * functionDefinition into simpleDeclaration - namespaceAliasDefinition into * namespaceDefinition - usingDirective into usingDeclaration - * explicitInstantiation and explicitSpecialization into templateDeclaration - * + * * @throws BacktrackException * request a backtrack */ @@ -2221,10 +2212,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IASTSimpleDeclaration decl= nodeFactory.newSimpleDeclaration(declspec); ((ASTNode) declspec).setOffsetAndLength(t.getOffset(), 0); ((ASTNode) decl).setOffsetAndLength(t.getOffset(), t.getLength()); - return decl; + return decl; case IToken.t_public: case IToken.t_protected: - case IToken.t_private: + case IToken.t_private: if (option == DeclarationOptions.CPP_MEMBER) { t= consume(); int key= t.getType(); @@ -2235,7 +2226,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } break; } - + try { return simpleDeclaration(option); } catch (BacktrackException e) { @@ -2252,12 +2243,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } } } - + /** * Serves as the namespace declaration portion of the ANSI C++ grammar. * namespace-definition: namespace identifier { namespace-body } | namespace { * namespace-body } namespace-body: declaration-seq? - * + * * @throws BacktrackException * request a backtrack */ @@ -2265,13 +2256,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { final int offset= LA().getOffset(); int endOffset; boolean isInline= false; - + if (LT(1) == IToken.t_inline) { consume(); isInline= true; } consume(IToken.t_namespace); - + // optional name IASTName name = null; if (LT(1) == IToken.tIDENTIFIER) { @@ -2289,8 +2280,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { ns.setIsInline(isInline); declarationListInBraces(ns, offset, DeclarationOptions.GLOBAL); return ns; - } - + } + if (LT(1) == IToken.tASSIGN) { endOffset= consume().getEndOffset(); if (name.toString() == null) { @@ -2304,7 +2295,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { ICPPASTNamespaceAlias alias = nodeFactory.newNamespaceAlias(name, qualifiedName); ((ASTNode) alias).setOffsetAndLength(offset, endOffset - offset); return alias; - } + } throwBacktrack(LA(1)); return null; } @@ -2323,7 +2314,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { protected IASTDeclaration simpleDeclaration(DeclarationOptions declOption) throws BacktrackException, EndOfFileException { if (LT(1) == IToken.tLBRACE) throwBacktrack(LA(1)); - + final int firstOffset= LA(1).getOffset(); int endOffset= firstOffset; boolean insertSemi= false; @@ -2354,7 +2345,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } throw e; } - + IASTDeclarator[] declarators= IASTDeclarator.EMPTY_DECLARATOR_ARRAY; if (dtor != null) { declarators= new IASTDeclarator[]{dtor}; @@ -2394,7 +2385,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.tASSIGN: // defaulted or deleted function definition if (declarators.length != 1 || !declOption.fAllowFunctionDefinition) throwBacktrack(LA(1)); - + dtor= declarators[0]; if (altDeclSpec != null && altDtor != null && dtor != null && !(ASTQueries.findTypeRelevantDeclarator(dtor) instanceof IASTFunctionDeclarator)) { @@ -2402,8 +2393,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { dtor= altDtor; } return functionDefinition(firstOffset, declSpec, dtor); - - default: + + default: insertSemi= true; if (declOption == DeclarationOptions.LOCAL) { endOffset= figureEndOffset(declSpec, declarators); @@ -2425,9 +2416,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } throwBacktrack(LA(1)); } - + // no function body - + final boolean isAmbiguous= altDeclSpec != null && altDtor != null && declarators.length == 1; IASTSimpleDeclaration simpleDeclaration; if (isAmbiguous) { @@ -2435,13 +2426,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // prefer the empty declspec, it shall be used if both variants show no problems simpleDeclaration= nodeFactory.newSimpleDeclaration(altDeclSpec); simpleDeclaration.addDeclarator(altDtor); - } else { + } else { simpleDeclaration= nodeFactory.newSimpleDeclaration(declSpec); for (IASTDeclarator declarator : declarators) { - simpleDeclaration.addDeclarator(declarator); + simpleDeclaration.addDeclarator(declarator); } } - + setRange(simpleDeclaration, firstOffset, endOffset); if (isAmbiguous) { simpleDeclaration = new CPPASTAmbiguousSimpleDeclaration(simpleDeclaration, declSpec, dtor); @@ -2457,23 +2448,22 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private IASTDeclaration functionDefinition(final int firstOffset, IASTDeclSpecifier declSpec, IASTDeclarator outerDtor) throws EndOfFileException, BacktrackException { - + final IASTDeclarator dtor= ASTQueries.findTypeRelevantDeclarator(outerDtor); if (!(dtor instanceof ICPPASTFunctionDeclarator)) throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset); - ICPPASTFunctionDefinition fdef; if (LT(1) == IToken.t_try) { consume(); - fdef= nodeFactory.newFunctionTryBlock(declSpec, (ICPPASTFunctionDeclarator) dtor, null); + fdef= nodeFactory.newFunctionTryBlock(declSpec, (ICPPASTFunctionDeclarator) dtor, null); } else { - fdef= nodeFactory.newFunctionDefinition(declSpec, (ICPPASTFunctionDeclarator) dtor, null); + fdef= nodeFactory.newFunctionDefinition(declSpec, (ICPPASTFunctionDeclarator) dtor, null); } if (LT(1) == IToken.tASSIGN) { consume(); IToken kind= consume(); - switch(kind.getType()) { + switch (kind.getType()) { case IToken.t_default: fdef.setIsDefaulted(true); break; @@ -2503,7 +2493,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } throw bt; } - + if (fdef instanceof ICPPASTFunctionWithTryBlock) { ICPPASTFunctionWithTryBlock tryblock= (ICPPASTFunctionWithTryBlock) fdef; List handlers = new ArrayList(DEFAULT_CATCH_HANDLER_LIST_SIZE); @@ -2525,7 +2515,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * : mem-initializer-list * mem-initializer-list: * mem-initializer ...? - * mem-initializer ...?, mem-initializer-list + * mem-initializer ...?, mem-initializer-list * mem-initializer: * mem-initializer-id ( expression-list? ) * mem-initializer-id braced-init-list @@ -2535,7 +2525,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { */ protected void ctorInitializer(ICPPASTFunctionDefinition fdef) throws EndOfFileException, BacktrackException { consume(IToken.tCOLON); - loop: for(;;) { + loop: while (true) { final int offset= LA(1).getOffset(); final IASTName name = qualifiedName(); final IASTInitializer init; @@ -2551,7 +2541,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) == IToken.tELLIPSIS) { ctorInitializer.setIsPackExpansion(true); endOffset= consume().getEndOffset(); - } + } fdef.addMemberInitializer(setRange(ctorInitializer, offset, endOffset)); if (LT(1) == IToken.tCOMMA) { @@ -2564,17 +2554,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { /** * This routine parses a parameter declaration - * + * * @throws BacktrackException * request a backtrack */ protected ICPPASTParameterDeclaration parameterDeclaration() throws BacktrackException, EndOfFileException { final int startOffset= LA(1).getOffset(); - + if (LT(1) == IToken.tLBRACKET && supportParameterInfoBlock) { skipBrackets(IToken.tLBRACKET, IToken.tRBRACKET, 0); } - + IASTDeclSpecifier declSpec= null; IASTDeclarator declarator; try { @@ -2592,24 +2582,22 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return parm; } - - private final static int INLINE= 0x1, CONST= 0x2, CONSTEXPR= 0x4, RESTRICT= 0x8, VOLATILE= 0x10, + private final static int INLINE= 0x1, CONST= 0x2, CONSTEXPR= 0x4, RESTRICT= 0x8, VOLATILE= 0x10, SHORT= 0x20, UNSIGNED= 0x40, SIGNED= 0x80, COMPLEX= 0x100, IMAGINARY= 0x200, VIRTUAL= 0x400, EXPLICIT= 0x800, FRIEND= 0x1000, THREAD_LOCAL= 0x2000; - private static final int FORBID_IN_EMPTY_DECLSPEC = + private static final int FORBID_IN_EMPTY_DECLSPEC = CONST | RESTRICT | VOLATILE | SHORT | UNSIGNED | SIGNED | COMPLEX | IMAGINARY | FRIEND | THREAD_LOCAL; - /** * This function parses a declaration specifier sequence, as according to - * the ANSI C++ specification. - * declSpecifier : - * "register" | "static" | "extern" | "mutable" | + * the ANSI C++ specification. + * declSpecifier : + * "register" | "static" | "extern" | "mutable" | * "inline" | "virtual" | "explicit" | - * "typedef" | "friend" | "constexpr" | + * "typedef" | "friend" | "constexpr" | * "const" | "volatile" | * "short" | "long" | "signed" | "unsigned" | "int" | - * "char" | "wchar_t" | "bool" | "float" | "double" | "void" | + * "char" | "wchar_t" | "bool" | "float" | "double" | "void" | * "auto" | * ("typename")? name | * { "class" | "struct" | "union" } classSpecifier | @@ -2619,7 +2607,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { protected Decl declSpecifierSeq(final DeclarationOptions option) throws BacktrackException, EndOfFileException { return declSpecifierSeq(option, false); } - + private ICPPASTDeclSpecifier simpleTypeSpecifier() throws BacktrackException, EndOfFileException { Decl d= declSpecifierSeq(null, true); return (ICPPASTDeclSpecifier) d.fDeclSpec1; @@ -2885,7 +2873,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { result= (ICPPASTDeclSpecifier) bt.getNodeBeforeProblem(); problem= bt.getProblem(); break declSpecifiers; - } + } throw bt; } endOffset= calculateEndOffset(result); @@ -2909,7 +2897,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { simpleType= IASTSimpleDeclSpecifier.t_typeof; consume(IGCCToken.t_typeof); - typeofExpression= parseTypeidInParenthesisOrUnaryExpression(false, LA(1).getOffset(), + typeofExpression= parseTypeidInParenthesisOrUnaryExpression(false, LA(1).getOffset(), IASTTypeIdExpression.op_typeof, -1, CastExprCtx.eNotInBExpr, null); encounteredTypename= true; @@ -2940,7 +2928,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (encounteredRawType && encounteredTypename) throwBacktrack(LA(1)); - + if (single) break declSpecifiers; } @@ -2975,7 +2963,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { throw e; } } - + Decl target= new Decl(); target.fDeclSpec1= result; target.fDeclSpec2= altResult; @@ -2995,7 +2983,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private ICPPASTSimpleDeclSpecifier buildSimpleDeclSpec(int storageClass, int simpleType, int options, int isLong, IASTExpression typeofExpression, int offset, int endOffset) { ICPPASTSimpleDeclSpecifier declSpec= nodeFactory.newSimpleDeclSpecifier(); - + configureDeclSpec(declSpec, storageClass, options); declSpec.setType(simpleType); @@ -3039,7 +3027,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { isScoped= true; consume(); } - // if __attribute__ or __declspec occurs after struct/union/class and before the identifier + // if __attribute__ or __declspec occurs after struct/union/class and before the identifier __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); if (isScoped || LT(1) == IToken.tIDENTIFIER) { @@ -3065,28 +3053,28 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return elaboratedTypeSpecifier(); } mark= null; - + if (isOpaque && !isScoped && baseType == null) throwBacktrack(LA(1)); - + if (name == null) { if (isOpaque) throwBacktrack(LA(1)); name= nodeFactory.newName(); } - + final ICPPASTEnumerationSpecifier result= nodeFactory.newEnumerationSpecifier(isScoped, name, baseType); result.setIsOpaque(isOpaque); if (lt1 == IToken.tLBRACE) { endOffset= enumBody(result); - } + } assert endOffset != 0; return setRange(result, offset, endOffset); } /** * Parse an elaborated type specifier. - * + * * @throws BacktrackException * request a backtrack */ @@ -3111,18 +3099,18 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { default: throwBacktrack(LA(1)); } - + final int offset= consume().getOffset(); - // if __attribute__ or __declspec occurs after struct/union/class and before the identifier + // if __attribute__ or __declspec occurs after struct/union/class and before the identifier __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); IASTName name = qualifiedName(); return setRange(nodeFactory.newElaboratedTypeSpecifier(eck, name), offset, calculateEndOffset(name)); } - + @Override - protected IASTDeclarator initDeclarator(IASTDeclSpecifier declspec, DeclarationOptions option) + protected IASTDeclarator initDeclarator(IASTDeclSpecifier declspec, DeclarationOptions option) throws EndOfFileException, BacktrackException, FoundAggregateInitializer { final IToken mark= mark(); IASTDeclarator dtor1= null; @@ -3132,23 +3120,23 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { try { dtor1= initDeclarator(DtorStrategy.PREFER_FUNCTION, declspec, option); verifyDtor(declspec, dtor1, option); - + int lt1= LTcatchEOF(1); switch (lt1) { case 0: return dtor1; - case IToken.tLBRACE: - if (option.fCanBeFollowedByBrace + case IToken.tLBRACE: + if (option.fCanBeFollowedByBrace || ASTQueries.findTypeRelevantDeclarator(dtor1) instanceof IASTFunctionDeclarator) return dtor1; dtor1= null; throwBacktrack(LA(1)); break; - + case IToken.tCOLON: - // a colon can be used after a type-id in a conditional expression + // a colon can be used after a type-id in a conditional expression if (option != DeclarationOptions.CPP_MEMBER && option != DeclarationOptions.GLOBAL) break; //$FALL-THROUGH$ @@ -3163,15 +3151,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { throwBacktrack(LA(1)); } } - + if (!(dtor1 instanceof IASTFunctionDeclarator)) return dtor1; - + end1= LA(1); } catch (BacktrackException e) { bt= e; - } - + } + if (!option.fAllowCtorStyleInitializer || !canHaveConstructorInitializer(declspec, dtor1)) { if (bt != null) throw bt; @@ -3181,7 +3169,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { backup(mark); try { dtor2= initDeclarator(DtorStrategy.PREFER_NESTED, declspec, option); - if (dtor1 == null) { + if (dtor1 == null) { return dtor2; } } catch (BacktrackException e) { @@ -3190,14 +3178,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return dtor1; } throw e; - } - + } + // we have an ambiguity if (end1 != null && LA(1).getEndOffset() != end1.getEndOffset()) { backup(end1); return dtor1; } - + if (functionBodyCount != 0) { // prefer the variable prototype: IASTDeclarator h= dtor1; dtor1= dtor2; dtor2= h; @@ -3225,7 +3213,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // accept conversion operator if (name instanceof ICPPASTConversionName) return; - if (opt == DeclarationOptions.CPP_MEMBER) { // Accept constructor and destructor within class body @@ -3240,15 +3227,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return; } } - + ASTNode node= (ASTNode) dtor; throwBacktrack(node.getOffset(), node.getLength()); } } - + private boolean canHaveConstructorInitializer(IASTDeclSpecifier declspec, IASTDeclarator dtor) { if (declspec instanceof ICPPASTDeclSpecifier) { - ICPPASTDeclSpecifier cppspec= (ICPPASTDeclSpecifier) declspec; + ICPPASTDeclSpecifier cppspec= (ICPPASTDeclSpecifier) declspec; if (cppspec.isFriend()) { return false; } @@ -3266,8 +3253,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { dtor.getPointerOperators().length == 0 && dtor.getNestedDeclarator() == null) { return false; } - } - + } + if (dtor != null) { IASTName name = ASTQueries.findInnermostDeclarator(dtor).getName().getLastName(); if (name instanceof ICPPASTTemplateId) { @@ -3276,18 +3263,18 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (name instanceof ICPPASTOperatorName || name instanceof ICPPASTConversionName) return false; } - + return true; } /** * Parses the initDeclarator construct of the ANSI C++ spec. initDeclarator : * declarator ("=" initializerClause | "(" expressionList ")")? - * + * * @return declarator that this parsing produced. * @throws BacktrackException * request a backtrack - * @throws FoundAggregateInitializer + * @throws FoundAggregateInitializer */ private IASTDeclarator initDeclarator(DtorStrategy strategy, IASTDeclSpecifier declspec, DeclarationOptions option) throws EndOfFileException, BacktrackException, FoundAggregateInitializer { @@ -3303,13 +3290,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IToken t = consume(); char[] image = t.getCharImage(); if (image.length != 1 || image[0] != '0') { - throwBacktrack(t); + throwBacktrack(t); } ((ICPPASTFunctionDeclarator) typeRelevantDtor).setPureVirtual(true); adjustEndOffset(dtor, t.getEndOffset()); // we can only adjust the offset of the outermost dtor. } } else { - if (LTcatchEOF(1) == IToken.tASSIGN && LTcatchEOF(2) == IToken.tLBRACE) + if (LTcatchEOF(1) == IToken.tASSIGN && LTcatchEOF(2) == IToken.tLBRACE) throw new FoundAggregateInitializer(declspec, dtor); IASTInitializer initializer= optionalInitializer(dtor, option); @@ -3335,12 +3322,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } return dtor; } - + /** * initializer: * brace-or-equal-initializer * ( expression-list ) - * + * * brace-or-equal-initializer: * = initializer-clause * braced-init-list @@ -3348,14 +3335,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { @Override protected IASTInitializer optionalInitializer(IASTDeclarator dtor, DeclarationOptions option) throws EndOfFileException, BacktrackException { final int lt1= LTcatchEOF(1); - + // = initializer-clause if (lt1 == IToken.tASSIGN) { // Check for deleted or defaulted function syntax. final int lt2= LTcatchEOF(2); if (lt2 == IToken.t_delete || lt2 == IToken.t_default) return null; - + int offset= consume().getOffset(); final boolean allowSkipping = LT(1) == IToken.tLBRACE && specifiesArray(dtor); IASTInitializerClause initClause = initClause(allowSkipping); @@ -3367,14 +3354,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (option.fAllowBracedInitializer && lt1 == IToken.tLBRACE) { return bracedInitList(false); } - + // ( expression-list ) if (option.fAllowCtorStyleInitializer && lt1 == IToken.tLPAREN) { return ctorStyleInitializer(false); - } + } return null; } - + private boolean specifiesArray(IASTDeclarator dtor) { dtor = ASTQueries.findTypeRelevantDeclarator(dtor); return dtor instanceof IASTArrayDeclarator; @@ -3395,12 +3382,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { throws EndOfFileException, BacktrackException { IASTInitializerClause[] initArray; int offset = consume(IToken.tLPAREN).getOffset(); - + // ( ) if (optionalExpressionList && LT(1) == IToken.tRPAREN) { initArray= IASTExpression.EMPTY_EXPRESSION_ARRAY; } else { - final List exprList = expressionList(); + final List exprList = expressionList(); initArray = exprList.toArray(new IASTInitializerClause[exprList.size()]); } int endOffset = consumeOrEOC(IToken.tRPAREN).getEndOffset(); @@ -3441,17 +3428,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { */ private ICPPASTInitializerList bracedInitList(boolean allowSkipping) throws EndOfFileException, BacktrackException { int offset = consume(IToken.tLBRACE).getOffset(); - + // { } if (LT(1) == IToken.tRBRACE) { return setRange(nodeFactory.newInitializerList(), offset, consume().getEndOffset()); } - + // { initializer-list ,opt } List initList= initializerList(allowSkipping); if (LT(1) == IToken.tCOMMA) consume(); - + int endOffset= consumeOrEOC(IToken.tRBRACE).getEndOffset(); ICPPASTInitializerList result = nodeFactory.newInitializerList(); for (IASTInitializerClause init : initList) { @@ -3459,7 +3446,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } return setRange(result, offset, endOffset); } - + /** * initializerList: * initializer-clause ...opt @@ -3467,10 +3454,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { */ private List initializerList(boolean allowSkipping) throws EndOfFileException, BacktrackException { - List result= null; // List of initializer clauses - loop: for(;;) { + loop: while (true) { // Clause may be null, add to initializer anyways, such that the size can be computed. IASTInitializerClause clause = initClause(allowSkipping); if (LT(1) == IToken.tELLIPSIS) { @@ -3499,10 +3485,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } consume(IToken.tCOMMA); } - + if (result == null) return Collections.emptyList(); - + return result; } @@ -3514,7 +3500,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { final int offset = LA().getOffset(); IASTDeclSpecifier declSpecifier = null; IASTDeclarator declarator = null; - + try { Decl decl= declSpecifierSequence_initDeclarator(option, false); declSpecifier= decl.fDeclSpec1; @@ -3522,22 +3508,22 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } catch (FoundAggregateInitializer lie) { // type-ids have no initializers throwBacktrack(lie.fDeclarator); - } - ICPPASTTypeId result = nodeFactory.newTypeId(declSpecifier, declarator); + } + ICPPASTTypeId result = nodeFactory.newTypeId(declSpecifier, declarator); setRange(result, offset, figureEndOffset(declSpecifier, declarator)); return result; } /** * Parse a declarator, as according to the ANSI C++ specification. - * declarator : (ptrOperator)* directDeclarator - * directDeclarator : - * declaratorId | - * directDeclarator "(" parameterDeclarationClause ")" (cvQualifier)* (exceptionSpecification)* | - * directDeclarator "[" (constantExpression)? "]" | - * "(" declarator")" | - * directDeclarator "(" parameterDeclarationClause ")" (oldKRParameterDeclaration)* - * + * declarator : (ptrOperator)* directDeclarator + * directDeclarator : + * declaratorId | + * directDeclarator "(" parameterDeclarationClause ")" (cvQualifier)* (exceptionSpecification)* | + * directDeclarator "[" (constantExpression)? "]" | + * "(" declarator")" | + * directDeclarator "(" parameterDeclarationClause ")" (oldKRParameterDeclaration)* + * * declaratorId : name * @return declarator that this parsing produced. * @throws BacktrackException @@ -3552,7 +3538,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (pointerOps != null) { endOffset = calculateEndOffset(pointerOps.get(pointerOps.size() - 1)); } - + // Accept __attribute__ or __declspec between pointer operators and declarator. __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); @@ -3571,21 +3557,21 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.tCOMPLETION: if (option.fRequireAbstract) throwBacktrack(LA(1)); - + final IASTName declaratorName= !option.fRequireSimpleName ? qualifiedName() : identifier(); endOffset= calculateEndOffset(declaratorName); return declarator(pointerOps, hasEllipsis, declaratorName, null, startingOffset, endOffset, strategy, option); - } - + } + if (lt1 == IToken.tLPAREN) { IASTDeclarator cand1= null; IToken cand1End= null; - // try an abstract function declarator + // try an abstract function declarator if (option.fAllowAbstract && option.fAllowFunctions) { final IToken mark= mark(); try { cand1= declarator(pointerOps, hasEllipsis, nodeFactory.newName(), null, startingOffset, endOffset, strategy, option); - if (option.fRequireAbstract || !option.fAllowNested || hasEllipsis) + if (option.fRequireAbstract || !option.fAllowNested || hasEllipsis) return cand1; cand1End= LA(1); @@ -3593,7 +3579,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } backup(mark); } - + // type-ids for new or operator-id: if (!option.fAllowNested || hasEllipsis) { if (option.fAllowAbstract) { @@ -3601,7 +3587,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } throwBacktrack(LA(1)); } - + // try a nested declarator try { consume(); @@ -3620,7 +3606,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return result; } // use the longer variant - if (cand1End.getOffset() < cand2End.getOffset()) + if (cand1End.getOffset() < cand2End.getOffset()) return cand2; } catch (BacktrackException e) { @@ -3643,7 +3629,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { /** * Parse a Pointer Operator. ptrOperator : "*" (cvQualifier)* | "&" | ::? * nestedNameSpecifier "*" (cvQualifier)* - * + * * @throws BacktrackException * request a backtrack */ @@ -3652,7 +3638,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { for (;;) { // __attribute__ in-between pointers __attribute_decl_seq(supportAttributeSpecifiers, false); - + final int lt1 = LT(1); if (lt1 == IToken.tAMPER || lt1 == IToken.tAND) { IToken endToken= consume(); @@ -3669,7 +3655,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } return Collections.singletonList(refOp); } - + IToken mark = mark(); final int startOffset = mark.getOffset(); boolean isConst = false, isVolatile = false, isRestrict = false; @@ -3704,7 +3690,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { backup(mark); return result; } - + int endOffset= consume().getEndOffset(); loop: for (;;) { switch (LTcatchEOF(1)) { @@ -3717,7 +3703,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { isVolatile = true; break; case IToken.t_restrict: - if (!allowCPPRestrict) + if (!allowCPPRestrict) throwBacktrack(LA(1)); endOffset= consume().getEndOffset(); isRestrict = true; @@ -3746,7 +3732,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private IASTDeclarator declarator(List pointerOps, boolean hasEllipsis, IASTName declaratorName, IASTDeclarator nestedDeclarator, int startingOffset, int endOffset, - DtorStrategy strategy, DeclarationOptions option) + DtorStrategy strategy, DeclarationOptions option) throws EndOfFileException, BacktrackException { ICPPASTDeclarator result= null; List attributes = null; @@ -3759,20 +3745,20 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { setDeclaratorID(result, hasEllipsis, declaratorName, nestedDeclarator); } break loop; - + case IToken.tLBRACKET: result= arrayDeclarator(option); setDeclaratorID(result, hasEllipsis, declaratorName, nestedDeclarator); break loop; - + case IToken.tCOLON: if (!option.fAllowBitField || nestedDeclarator != null) break loop; // no backtrack because typeid can be followed by colon - + result= bitFieldDeclarator(); setDeclaratorID(result, hasEllipsis, declaratorName, nestedDeclarator); break loop; - + case IGCCToken.t__attribute__: // if __attribute__ is after a declarator if (!supportAttributeSpecifiers) throwBacktrack(LA(1)); @@ -3824,7 +3810,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } private void setDeclaratorID(ICPPASTDeclarator declarator, boolean hasEllipsis, IASTName declaratorName, IASTDeclarator nestedDeclarator) { - if (nestedDeclarator != null) { + if (nestedDeclarator != null) { declarator.setNestedDeclarator(nestedDeclarator); declarator.setName(nodeFactory.newName()); } else { @@ -3832,7 +3818,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } declarator.setDeclaresParameterPack(hasEllipsis); } - + /** * Parse a function declarator starting with the left parenthesis. */ @@ -3840,7 +3826,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IToken last = consume(IToken.tLPAREN); final int startOffset= last.getOffset(); int endOffset= last.getEndOffset(); - + final ICPPASTFunctionDeclarator fc = nodeFactory.newFunctionDeclarator(null); ICPPASTParameterDeclaration pd= null; paramLoop: while(true) { @@ -3863,7 +3849,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { default: if (pd != null) throwBacktrack(startOffset, endOffset - startOffset); - + pd = parameterDeclaration(); fc.addParameterDeclaration(pd); endOffset = calculateEndOffset(pd); @@ -3911,7 +3897,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) == IToken.t_throw) { fc.setEmptyExceptionSpecification(); consume(); // throw - consume(IToken.tLPAREN); + consume(IToken.tLPAREN); thloop: while (true) { switch (LT(1)) { @@ -3949,13 +3935,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { attributes = CollectionUtils.merge(attributes, __attribute_decl_seq(supportAttributeSpecifiers, false)); } - + if (LT(1) == IToken.tARROW) { consume(); IASTTypeId typeId= typeId(DeclarationOptions.TYPEID_TRAILING_RETURN_TYPE); fc.setTrailingReturnType(typeId); endOffset= calculateEndOffset(typeId); - } + } if (attributes != null) { for (IASTAttribute attribute : attributes) { @@ -3975,27 +3961,26 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { consumeArrayModifiers(option, arrayMods); if (arrayMods.isEmpty()) throwBacktrack(LA(1)); - + final int endOffset = calculateEndOffset(arrayMods.get(arrayMods.size() - 1)); final ICPPASTArrayDeclarator d = nodeFactory.newArrayDeclarator(null); for (IASTArrayModifier m : arrayMods) { d.addArrayModifier(m); } - + ((ASTNode) d).setOffsetAndLength(start, endOffset-start); return d; } - - + /** * Parses for a bit field declarator starting with the colon */ private ICPPASTFieldDeclarator bitFieldDeclarator() throws EndOfFileException, BacktrackException { int start= consume(IToken.tCOLON).getOffset(); - + final IASTExpression bitField = constantExpression(); final int endOffset = calculateEndOffset(bitField); - + ICPPASTFieldDeclarator d = nodeFactory.newFieldDeclarator(null, bitField); ((ASTNode) d).setOffsetAndLength(start, endOffset-start); return d; @@ -4004,7 +3989,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { /** * Parse a class/struct/union definition. classSpecifier : classKey name * (baseClause)? "{" (memberSpecification)* "}" - * + * * @throws BacktrackException * request a backtrack */ @@ -4032,9 +4017,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return null; // line is never reached, hint for the parser } - // if __attribute__ or __declspec occurs after struct/union/class and before the identifier + // if __attribute__ or __declspec occurs after struct/union/class and before the identifier __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); - + // class name IASTName name = null; if (LT(1) == IToken.tIDENTIFIER) { @@ -4042,10 +4027,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } else { name = nodeFactory.newName(); } - + // if __attribute__ or __declspec occurs after struct/union/class identifier and before the { or ; __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); - + ICPPASTCompositeTypeSpecifier astClassSpecifier = nodeFactory.newCompositeTypeSpecifier(classKind, name); // base clause @@ -4087,45 +4072,45 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } /** - * Parse a base clause for a class specification. - * base-clause: - * : base-specifier-list - * base-specifier-list: - * base-specifier - * base-specifier-list, base-specifier + * Parse a base clause for a class specification. + * base-clause: + * : base-specifier-list + * base-specifier-list: + * base-specifier + * base-specifier-list, base-specifier */ private void baseClause(ICPPASTCompositeTypeSpecifier astClassSpec) throws EndOfFileException, BacktrackException { consume(IToken.tCOLON); for (;;) { ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier baseSpec = baseSpecifier(); astClassSpec.addBaseSpecifier(baseSpec); - + if (LT(1) == IToken.tELLIPSIS) { baseSpec.setIsPackExpansion(true); adjustEndOffset(baseSpec, consume().getEndOffset()); } - + if (LT(1) != IToken.tCOMMA) { return; } - + consume(); } } /** - * base-specifier: - * ::? nested-name-specifier? class-name - * virtual access-specifier? ::? nested-name-specifier? class-name - * access-specifier virtual? ::? nested-name-specifier? class-name - * + * base-specifier: + * ::? nested-name-specifier? class-name + * virtual access-specifier? ::? nested-name-specifier? class-name + * access-specifier virtual? ::? nested-name-specifier? class-name + * * access-specifier: private | protected | public - * @return + * @return */ private ICPPASTBaseSpecifier baseSpecifier() throws EndOfFileException, BacktrackException { int startOffset= LA(1).getOffset(); boolean isVirtual = false; - int visibility = 0; + int visibility = 0; IASTName name = null; loop: for (;;) { switch (LT(1)) { @@ -4158,10 +4143,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { protected void catchHandlerSequence(List collection) throws EndOfFileException, BacktrackException { if (LT(1) == IToken.tEOC) return; - - if (LT(1) != IToken.t_catch) + + if (LT(1) != IToken.t_catch) throwBacktrack(LA(1)); // error, need at least one - + int lt1 = LT(1); while (lt1 == IToken.t_catch) { int startOffset = consume().getOffset(); @@ -4195,7 +4180,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { handler.setCatchBody(compoundStatement); } } - + collection.add(handler); lt1 = LTcatchEOF(1); } @@ -4216,14 +4201,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } final int endOffset = figureEndOffset(declSpec, declarator); - final IASTSimpleDeclaration decl= nodeFactory.newSimpleDeclaration(declSpec); - if (declarator != null) + final IASTSimpleDeclaration decl= nodeFactory.newSimpleDeclaration(declSpec); + if (declarator != null) decl.addDeclarator(declarator); ((ASTNode) decl).setOffsetAndLength(startOffset, endOffset - startOffset); return decl; } - protected IASTStatement catchBlockCompoundStatement() throws BacktrackException, EndOfFileException { if (mode == ParserMode.QUICK_PARSE || mode == ParserMode.STRUCTURAL_PARSE || !isActiveCode()) { int offset = LA(1).getOffset(); @@ -4248,11 +4232,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { translationUnit = nodeFactory.newTranslationUnit(scanner); translationUnit.setIndex(index); - // add built-in names to the scope - // add built-in names to the scope + // Add built-in names to the scope. if (builtinBindingsProvider != null) { IScope tuScope = translationUnit.getScope(); - + IBinding[] bindings = builtinBindingsProvider.getBuiltinBindings(tuScope); for (IBinding binding : bindings) { ASTInternal.addBinding(tuScope, binding); @@ -4260,7 +4243,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } } - private void consumeArrayModifiers(DeclarationOptions option, List collection) throws EndOfFileException, BacktrackException { boolean allowExpression= option == DeclarationOptions.TYPEID_NEW; @@ -4288,7 +4270,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return; } - @Override protected IASTTranslationUnit getTranslationUnit() { return translationUnit; @@ -4362,7 +4343,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { translationUnit = null; } - @Override protected IASTStatement parseWhileStatement() throws EndOfFileException, BacktrackException { int startOffset = consume().getOffset(); @@ -4386,7 +4366,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { while_statement = nodeFactory.newWhileStatement((IASTExpression)while_condition, while_body); else while_statement = nodeFactory.newWhileStatement((IASTDeclaration)while_condition, while_body); - + ((ASTNode) while_statement).setOffsetAndLength(startOffset, (while_body != null ? calculateEndOffset(while_body) : LA(1).getEndOffset()) - startOffset); return while_statement; @@ -4397,7 +4377,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IASTExpression e= null; IASTSimpleDeclaration decl= null; IToken end= null; - + IToken mark = mark(); try { decl= simpleSingleDeclaration(DeclarationOptions.CONDITION); @@ -4406,7 +4386,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (la != expectToken && la != IToken.tEOC) { end= null; decl= null; - } + } } catch (BacktrackException b) { } @@ -4421,7 +4401,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } if (end == null) return e; - final int endOffset = end.getOffset(); final int endOffset2 = end2.getOffset(); @@ -4430,8 +4409,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { setRange(ambig, e); return ambig; } - - if (endOffset < endOffset2) + + if (endOffset < endOffset2) return e; } catch (BacktrackException bt) { if (end == null) { @@ -4446,7 +4425,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return decl; } - @Override protected ASTVisitor createAmbiguityNodeVisitor() { return new CPPASTAmbiguityResolver(); @@ -4465,7 +4443,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { int so = consume(IToken.t_if).getOffset(); consume(IToken.tLPAREN); // condition - IASTNode condition= cppStyleCondition(IToken.tRPAREN); + IASTNode condition= cppStyleCondition(IToken.tRPAREN); if (LT(1) == IToken.tEOC) { // Completing in the condition ICPPASTIfStatement new_if = nodeFactory.newIfStatement(); @@ -4481,11 +4459,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } consume(IToken.tRPAREN); - IASTStatement thenClause = statement(); ICPPASTIfStatement new_if_statement = nodeFactory.newIfStatement(); ((ASTNode) new_if_statement).setOffset(so); - if (condition != null && (condition instanceof IASTExpression || condition instanceof IASTDeclaration)) + if (condition != null && (condition instanceof IASTExpression || condition instanceof IASTDeclaration)) // shouldn't be possible but failure in condition() makes it so { if (condition instanceof IASTExpression) @@ -4545,7 +4522,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return result; } - @Override protected IASTCompoundStatement functionBody() throws EndOfFileException, BacktrackException { ++functionBodyCount; @@ -4580,7 +4556,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } else if (switch_condition instanceof IASTDeclaration) { switch_statement.setControllerDeclaration((IASTDeclaration) switch_condition); } - + if (switch_body != null) { switch_statement.setBody(switch_body); } @@ -4613,7 +4589,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } return setRange(forStmt, offset, endOffset); } - + // Look for "for-range-declaration : for-range-initializer" // for-range-declaration: // attribute-specifier? type-specifier-seq declarator @@ -4633,7 +4609,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { default: init= expression(); } - + ICPPASTRangeBasedForStatement result = nodeFactory.newRangeBasedForStatement(); result.setDeclaration(decl); result.setInitializerClause(init); @@ -4644,7 +4620,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { final IASTStatement initStmt = forInitStatement(); IASTNode condition= null; IASTExpression iterExpr= null; - + int lt1 = LT(1); if (lt1 != IToken.tSEMI && lt1 != IToken.tEOC) { condition = cppStyleCondition(IToken.tSEMI); @@ -4655,13 +4631,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (lt1 != IToken.tRPAREN && lt1 != IToken.tEOC) { iterExpr = expression(); } - + ICPPASTForStatement result = nodeFactory.newForStatement(); result.setInitializerStatement(initStmt); if (condition instanceof IASTExpression) { result.setConditionExpression((IASTExpression) condition); } else if (condition instanceof IASTDeclaration) { - result.setConditionDeclaration((IASTDeclaration) condition); + result.setConditionDeclaration((IASTDeclaration) condition); } result.setIterationExpression(iterExpr); return result; diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java index 8ce68747762..42387484aef 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java @@ -95,7 +95,6 @@ import com.ibm.icu.text.MessageFormat; * @noinstantiate This class is not intended to be instantiated by clients. */ public class CCorePlugin extends Plugin { - public static final int STATUS_CDTPROJECT_EXISTS = 1; public static final int STATUS_CDTPROJECT_MISMATCH = 2; public static final int CDT_PROJECT_NATURE_ID_MISMATCH = 3; @@ -299,7 +298,6 @@ public class CCorePlugin extends Plugin { return fgCPlugin; } - /** * @see Plugin#shutdown */ @@ -510,7 +508,6 @@ public class CCorePlugin extends Plugin { getDefault().savePluginPreferences(); } - /** * Create CDT console adapter for build console defined as an extension. * See {@code org.eclipse.cdt.core.CBuildConsole} extension point. @@ -833,61 +830,61 @@ public class CCorePlugin extends Plugin { final IProject projectHandle, final String bsId, IProgressMonitor monitor) - throws CoreException, OperationCanceledException { + throws CoreException, OperationCanceledException { - getWorkspace().run(new IWorkspaceRunnable() { - @Override - public void run(IProgressMonitor monitor) throws CoreException { - try { - if (monitor == null) { - monitor = new NullProgressMonitor(); - } - monitor.beginTask("Creating C Project...", 3); //$NON-NLS-1$ - if (!projectHandle.exists()) { - projectHandle.create(description, new SubProgressMonitor(monitor, 1)); - } - - if (monitor.isCanceled()) { - throw new OperationCanceledException(); - } - - // Open first. - projectHandle.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 1)); - -// mapCProjectOwner(projectHandle, projectID, false); - - // Add C Nature ... does not add duplicates - CProjectNature.addCNature(projectHandle, new SubProgressMonitor(monitor, 1)); - - if(bsId != null){ - ICProjectDescription projDes = createProjectDescription(projectHandle, true); - ICConfigurationDescription cfgs[] = projDes.getConfigurations(); - ICConfigurationDescription cfg = null; - for (ICConfigurationDescription cfg2 : cfgs) { - if(bsId.equals(cfg2.getBuildSystemId())){ - cfg = cfg2; - break; - } - } - - if(cfg == null){ - ICConfigurationDescription prefCfg = getPreferenceConfiguration(bsId); - if(prefCfg != null){ - cfg = projDes.createConfiguration(CDataUtil.genId(prefCfg.getId()), prefCfg.getName(), prefCfg); - } - } - - if(cfg != null){ - setProjectDescription(projectHandle, projDes); - } - } - } finally { - monitor.done(); + getWorkspace().run(new IWorkspaceRunnable() { + @Override + public void run(IProgressMonitor monitor) throws CoreException { + try { + if (monitor == null) { + monitor = new NullProgressMonitor(); } + monitor.beginTask("Creating C Project...", 3); //$NON-NLS-1$ + if (!projectHandle.exists()) { + projectHandle.create(description, new SubProgressMonitor(monitor, 1)); + } + + if (monitor.isCanceled()) { + throw new OperationCanceledException(); + } + + // Open first. + projectHandle.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 1)); + + // mapCProjectOwner(projectHandle, projectID, false); + + // Add C Nature ... does not add duplicates + CProjectNature.addCNature(projectHandle, new SubProgressMonitor(monitor, 1)); + + if (bsId != null){ + ICProjectDescription projDes = createProjectDescription(projectHandle, true); + ICConfigurationDescription cfgs[] = projDes.getConfigurations(); + ICConfigurationDescription cfg = null; + for (ICConfigurationDescription cfg2 : cfgs) { + if (bsId.equals(cfg2.getBuildSystemId())){ + cfg = cfg2; + break; + } + } + + if (cfg == null){ + ICConfigurationDescription prefCfg = getPreferenceConfiguration(bsId); + if (prefCfg != null){ + cfg = projDes.createConfiguration(CDataUtil.genId(prefCfg.getId()), prefCfg.getName(), prefCfg); + } + } + + if (cfg != null){ + setProjectDescription(projectHandle, projDes); + } + } + } finally { + monitor.done(); } - }, getWorkspace().getRoot(), 0, monitor); - return projectHandle; - } + } + }, getWorkspace().getRoot(), 0, monitor); + return projectHandle; + } /** * Method convertProjectFromCtoCC converts @@ -899,7 +896,6 @@ public class CCorePlugin extends Plugin { * @param monitor * @throws CoreException */ - public void convertProjectFromCtoCC(IProject projectHandle, IProgressMonitor monitor) throws CoreException { if ((projectHandle != null) && projectHandle.hasNature(CProjectNature.C_NATURE_ID) @@ -974,7 +970,7 @@ public class CCorePlugin extends Plugin { for (IConfigurationElement configElement : configElements) { if (configElement.getName().equals("processList")) { //$NON-NLS-1$ String platform = configElement.getAttribute("platform"); //$NON-NLS-1$ - if (platform == null ) { // first contributor found with not platform will be default. + if (platform == null) { // first contributor found with not platform will be default. if (defaultContributor == null) { defaultContributor = configElement; } @@ -985,12 +981,11 @@ public class CCorePlugin extends Plugin { } } } - if ( defaultContributor != null) { + if (defaultContributor != null) { return (IProcessList) defaultContributor.createExecutableExtension("class"); //$NON-NLS-1$ } } return null; - } /** @@ -1024,7 +1019,7 @@ public class CCorePlugin extends Plugin { try { // Look up in session property for previously created provider QualifiedName scannerInfoProviderName = new QualifiedName(PLUGIN_ID, SCANNER_INFO_PROVIDER2_NAME); - provider = (IScannerInfoProvider)project.getSessionProperty(scannerInfoProviderName); + provider = (IScannerInfoProvider) project.getSessionProperty(scannerInfoProviderName); if (provider != null) return provider; @@ -1117,8 +1112,6 @@ public class CCorePlugin extends Plugin { CContentTypes.setUseProjectSpecificContentTypes(project, val); } - - private static final String MODEL = CCorePlugin.PLUGIN_ID + "/debug/model" ; //$NON-NLS-1$ private static final String PARSER = CCorePlugin.PLUGIN_ID + "/debug/parser" ; //$NON-NLS-1$ private static final String PARSER_EXCEPTIONS = CCorePlugin.PLUGIN_ID + "/debug/parser/exceptions" ; //$NON-NLS-1$ @@ -1130,27 +1123,25 @@ public class CCorePlugin extends Plugin { * Configure the plug-in with respect to option settings defined in ".options" file */ public void configurePluginDebugOptions() { - - if(CCorePlugin.getDefault().isDebugging()) { + if (CCorePlugin.getDefault().isDebugging()) { String option = Platform.getDebugOption(PARSER); - if(option != null) Util.VERBOSE_PARSER = option.equalsIgnoreCase("true") ; //$NON-NLS-1$ + if (option != null) Util.VERBOSE_PARSER = option.equalsIgnoreCase("true") ; //$NON-NLS-1$ option = Platform.getDebugOption(PARSER_EXCEPTIONS); - if( option != null ) Util.PARSER_EXCEPTIONS = option.equalsIgnoreCase("true"); //$NON-NLS-1$ + if (option != null) Util.PARSER_EXCEPTIONS = option.equalsIgnoreCase("true"); //$NON-NLS-1$ option = Platform.getDebugOption(SCANNER); - if( option != null ) Util.VERBOSE_SCANNER = option.equalsIgnoreCase("true"); //$NON-NLS-1$ + if (option != null) Util.VERBOSE_SCANNER = option.equalsIgnoreCase("true"); //$NON-NLS-1$ option = Platform.getDebugOption(MODEL); - if(option != null) Util.VERBOSE_MODEL = option.equalsIgnoreCase("true") ; //$NON-NLS-1$ + if (option != null) Util.VERBOSE_MODEL = option.equalsIgnoreCase("true") ; //$NON-NLS-1$ option = Platform.getDebugOption(DELTA); - if(option != null) Util.VERBOSE_DELTA= option.equalsIgnoreCase("true") ; //$NON-NLS-1$ - + if (option != null) Util.VERBOSE_DELTA= option.equalsIgnoreCase("true") ; //$NON-NLS-1$ } } - // Preference to turn on/off the use of structural parse mode to build the CModel + // Preference to turn on/off the use of structural parse mode to build the CModel. public void setStructuralParseMode(boolean useNewParser) { getPluginPreferences().setValue(PREF_USE_STRUCTURAL_PARSE_MODE, useNewParser); savePluginPreferences(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OverrideIndicatorManager.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OverrideIndicatorManager.java index b183769b80a..6aed8cca197 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OverrideIndicatorManager.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OverrideIndicatorManager.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Tomasz Wesolowski - initial API and implementation + * Tomasz Wesolowski - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.ui.editor; @@ -52,13 +52,10 @@ import org.eclipse.cdt.internal.ui.text.ICReconcilingListener; import org.eclipse.cdt.internal.ui.viewsupport.IndexUI; public class OverrideIndicatorManager implements ICReconcilingListener { - static final String ANNOTATION_TYPE = "org.eclipse.cdt.ui.overrideIndicator"; //$NON-NLS-1$ - private static final String MESSAGE_SEPARATOR = ";\n"; //$NON-NLS-1$ public static class OverrideInfo { - public int nodeOffset; public int resultType; public String message; @@ -79,7 +76,6 @@ public class OverrideIndicatorManager implements ICReconcilingListener { public static final int RESULT_SHADOWS = 2; public class OverrideIndicator extends Annotation { - public static final String ANNOTATION_TYPE_ID = "org.eclipse.cdt.ui.overrideIndicator"; //$NON-NLS-1$ private int type; private ICElementHandle declaration; @@ -108,9 +104,7 @@ public class OverrideIndicatorManager implements ICReconcilingListener { CDTUITools.openInEditor(declaration, true, true); } catch (CoreException e) { } - } - } private IAnnotationModel fAnnotationModel; @@ -123,7 +117,6 @@ public class OverrideIndicatorManager implements ICReconcilingListener { } private void handleResult(OverrideInfo info, IIndex index) { - Position position = new Position(info.nodeOffset, info.nodeLength); OverrideIndicator indicator = new OverrideIndicator(info.resultType, info.message, info.binding, index); @@ -166,7 +159,7 @@ public class OverrideIndicatorManager implements ICReconcilingListener { } if (binding instanceof ICPPMethod) { method = (ICPPMethod) binding; - OverrideInfo overrideInfo = testForOverride(method, declaration.getFileLocation()); + OverrideInfo overrideInfo = checkForOverride(method, declaration); if (overrideInfo != null) { handleResult(overrideInfo, index); } @@ -209,7 +202,7 @@ public class OverrideIndicatorManager implements ICReconcilingListener { return PROCESS_SKIP; } ICPPMethod method = (ICPPMethod) definitionBinding; - OverrideInfo overrideInfo = testForOverride(method, definition.getFileLocation()); + OverrideInfo overrideInfo = checkForOverride(method, definition); if (overrideInfo != null) { handleResult(overrideInfo, index); } @@ -223,8 +216,8 @@ public class OverrideIndicatorManager implements ICReconcilingListener { ast.accept(new MethodDefinitionFinder()); } - public static OverrideInfo testForOverride(ICPPMethod testedOverride, IASTFileLocation location) throws DOMException { - + private static OverrideInfo checkForOverride(ICPPMethod testedOverride, IASTNode node) throws DOMException { + IASTFileLocation location = node.getFileLocation(); testedOverride.getClassOwner().getBases(); boolean onlyPureVirtual = true; @@ -301,7 +294,6 @@ public class OverrideIndicatorManager implements ICReconcilingListener { return info; } return null; - } /** @@ -314,8 +306,8 @@ public class OverrideIndicatorManager implements ICReconcilingListener { * @throws DOMException */ private static void handleBaseClass(ICPPClassType aClass, ICPPMethod testedOverride, - Set foundMethods, Set shadowedMethods, Set alreadyTestedBases) throws DOMException { - + Set foundMethods, Set shadowedMethods, + Set alreadyTestedBases) throws DOMException { if (alreadyTestedBases.contains(aClass)) { return; } else { @@ -427,5 +419,4 @@ public class OverrideIndicatorManager implements ICReconcilingListener { } return annotationModel; } - } From f4d616cdc0eb7b48ca53029365cd4952f108f241 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 8 Aug 2012 17:38:17 -0700 Subject: [PATCH 31/31] Bug 299911. Added logging of methods that loose template instantiation context. --- .../AbstractClassInstantiationChecker.java | 4 +- .../checkers/NonVirtualDestructor.java | 19 +- .../core/parser/tests/ast2/AST2CPPTests.java | 22 +-- .../parser/tests/ast2/AST2TemplateTests.java | 11 +- .../tests/IndexCPPBindingResolutionBugs.java | 100 +++++----- .../tests/IndexCPPTemplateResolutionTest.java | 27 +-- .../pdom/tests/CPPClassTemplateTests.java | 9 +- .../dom/ast/cpp/ICPPClassSpecialization.java | 22 +++ .../dom/ast/cpp/ICPPMethodSpecialization.java | 30 +++ .../core/dom/parser/SizeofCalculator.java | 30 +++ .../AbstractCPPClassSpecializationScope.java | 22 ++- .../CPPASTConstructorChainInitializer.java | 2 +- .../cpp/CPPASTFunctionCallExpression.java | 3 +- .../dom/parser/cpp/CPPASTQualifiedName.java | 2 +- .../parser/cpp/CPPClassSpecialization.java | 43 ++++- .../core/dom/parser/cpp/CPPClassTemplate.java | 6 +- .../cpp/CPPClassTemplateSpecialization.java | 2 +- .../core/dom/parser/cpp/CPPClassType.java | 6 +- .../dom/parser/cpp/CPPImplicitMethod.java | 2 +- .../parser/cpp/CPPMethodSpecialization.java | 30 +-- .../core/dom/parser/cpp/ClassTypeHelper.java | 180 +++++++++++------- .../parser/cpp/semantics/AccessContext.java | 2 +- .../parser/cpp/semantics/BaseClassLookup.java | 3 +- .../parser/cpp/semantics/CPPEvaluation.java | 7 +- .../parser/cpp/semantics/CPPSemantics.java | 13 +- .../dom/parser/cpp/semantics/CPPVisitor.java | 2 + .../dom/parser/cpp/semantics/Conversions.java | 6 +- .../parser/cpp/semantics/SemanticUtil.java | 46 +---- .../semantics/TemplateArgumentDeduction.java | 29 ++- .../cpp/CompositeCPPClassSpecialization.java | 76 ++++++-- .../CompositeCPPClassSpecializationScope.java | 7 +- .../composite/cpp/CompositeCPPClassType.java | 68 +++---- .../dom/cpp/PDOMCPPClassSpecialization.java | 42 +++- .../PDOMCPPClassTemplateSpecialization.java | 2 +- .../core/pdom/dom/cpp/PDOMCPPClassType.java | 6 +- .../core/pdom/dom/cpp/PDOMCPPLinkage.java | 14 +- .../core/pdom/dom/cpp/PDOMCPPMethod.java | 2 +- .../dom/cpp/PDOMCPPMethodSpecialization.java | 15 +- .../internal/ui/callhierarchy/CHQueries.java | 2 +- .../ui/editor/OverrideIndicatorManager.java | 11 +- .../rename/CRenameMethodProcessor.java | 3 +- .../cdt/internal/ui/search/CSearchQuery.java | 3 +- .../internal/ui/search/LinkedNamesFinder.java | 2 +- .../DOMCompletionProposalComputer.java | 7 +- .../cdt/internal/ui/viewsupport/IndexUI.java | 2 +- 45 files changed, 577 insertions(+), 365 deletions(-) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethodSpecialization.java diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AbstractClassInstantiationChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AbstractClassInstantiationChecker.java index 0461da5b940..4e68e5b7360 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AbstractClassInstantiationChecker.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AbstractClassInstantiationChecker.java @@ -188,7 +188,7 @@ public class AbstractClassInstantiationChecker extends AbstractIndexAstChecker { * Checks whether specified type (class or typedef to the class) is an abstract class. * If it is, reports violations on each pure virtual method */ - private void reportProblemsIfAbstract(IType typeToCheck, IASTNode problemNode ) { + private void reportProblemsIfAbstract(IType typeToCheck, IASTNode problemNode) { IType unwindedType = CxxAstUtils.unwindTypedef(typeToCheck); if (!(unwindedType instanceof ICPPClassType) || unwindedType instanceof IProblemBinding) { return; @@ -196,7 +196,7 @@ public class AbstractClassInstantiationChecker extends AbstractIndexAstChecker { ICPPClassType classType = (ICPPClassType) unwindedType; ICPPMethod[] pureVirtualMethods = pureVirtualMethodsCache.get(classType); if (pureVirtualMethods == null) { - pureVirtualMethods = ClassTypeHelper.getPureVirtualMethods(classType); + pureVirtualMethods = ClassTypeHelper.getPureVirtualMethods(classType, problemNode); pureVirtualMethodsCache.put(classType, pureVirtualMethods); } diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java index db7235a7307..bb780c1912f 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java @@ -27,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; /** @@ -46,8 +47,8 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker { ast.accept(new OnEachClass()); } - private static ICPPMethod getDestructor(ICPPClassType classType) { - for (ICPPMethod method : classType.getDeclaredMethods()) { + private static ICPPMethod getDestructor(ICPPClassType classType, IASTNode point) { + for (ICPPMethod method : ClassTypeHelper.getDeclaredMethods(classType, point)) { if (method.isDestructor()) { return method; } @@ -55,18 +56,18 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker { return null; } - private static boolean hasVirtualDestructor(ICPPClassType classType) { + private static boolean hasVirtualDestructor(ICPPClassType classType, IASTNode point) { checkedClassTypes.add(classType); - ICPPMethod destructor = getDestructor(classType); + ICPPMethod destructor = getDestructor(classType, point); if (destructor != null && destructor.isVirtual()) { return true; } - ICPPBase[] bases = classType.getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases(classType, point); for (ICPPBase base : bases) { IBinding baseClass = base.getBaseClass(); if (baseClass instanceof ICPPClassType) { ICPPClassType cppClassType = (ICPPClassType) baseClass; - if (!checkedClassTypes.contains(cppClassType) && hasVirtualDestructor(cppClassType)) { + if (!checkedClassTypes.contains(cppClassType) && hasVirtualDestructor(cppClassType, point)) { return true; } } @@ -89,13 +90,13 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker { return PROCESS_SKIP; } ICPPClassType classType = (ICPPClassType) binding; - boolean hasVirtualDestructor = hasVirtualDestructor(classType); + boolean hasVirtualDestructor = hasVirtualDestructor(classType, className); checkedClassTypes.clear(); if (hasVirtualDestructor) { return PROCESS_SKIP; } ICPPMethod virtualMethod = null; - for (ICPPMethod method : classType.getAllDeclaredMethods()) { + for (ICPPMethod method : ClassTypeHelper.getAllDeclaredMethods(classType, className)) { if (!method.isDestructor() && method.isVirtual()) { virtualMethod = method; } @@ -103,7 +104,7 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker { if (virtualMethod == null) { return PROCESS_SKIP; } - ICPPMethod destructor = getDestructor(classType); + ICPPMethod destructor = getDestructor(classType, className); if (destructor != null && destructor.getVisibility() != ICPPASTVisibilityLabel.v_public && classType.getFriends().length == 0) { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index f5ff218fd0d..0c40d13cc63 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -6252,20 +6252,20 @@ public class AST2CPPTests extends AST2BaseTest { assertFalse(ClassTypeHelper.isOverrider(m5, m2)); assertTrue(ClassTypeHelper.isOverrider(m4, m2)); - ICPPMethod[] ors= ClassTypeHelper.findOverridden(m0); + ICPPMethod[] ors= ClassTypeHelper.findOverridden(m0, null); assertEquals(0, ors.length); - ors= ClassTypeHelper.findOverridden(m1); + ors= ClassTypeHelper.findOverridden(m1, null); assertEquals(0, ors.length); - ors= ClassTypeHelper.findOverridden(m2); + ors= ClassTypeHelper.findOverridden(m2, null); assertEquals(1, ors.length); assertSame(ors[0], m1); - ors= ClassTypeHelper.findOverridden(m3); + ors= ClassTypeHelper.findOverridden(m3, null); assertEquals(0, ors.length); - ors= ClassTypeHelper.findOverridden(m4); + ors= ClassTypeHelper.findOverridden(m4, null); assertEquals(2, ors.length); assertSame(ors[0], m2); assertSame(ors[1], m1); - ors= ClassTypeHelper.findOverridden(m5); + ors= ClassTypeHelper.findOverridden(m5, null); assertEquals(1, ors.length); assertSame(ors[0], m1); } @@ -8732,14 +8732,14 @@ public class AST2CPPTests extends AST2BaseTest { assertFalse(ClassTypeHelper.isOverrider(m3, m0)); assertFalse(ClassTypeHelper.isOverrider(m3, m1)); - ICPPMethod[] ors= ClassTypeHelper.findOverridden(m0); + ICPPMethod[] ors= ClassTypeHelper.findOverridden(m0, null); assertEquals(0, ors.length); - ors= ClassTypeHelper.findOverridden(m1); + ors= ClassTypeHelper.findOverridden(m1, null); assertEquals(0, ors.length); - ors= ClassTypeHelper.findOverridden(m2); + ors= ClassTypeHelper.findOverridden(m2, null); assertEquals(1, ors.length); assertSame(ors[0], m0); - ors= ClassTypeHelper.findOverridden(m3); + ors= ClassTypeHelper.findOverridden(m3, null); assertEquals(0, ors.length); } @@ -9546,7 +9546,7 @@ public class AST2CPPTests extends AST2BaseTest { public void testRecursiveClassInheritance_Bug357256() throws Exception { BindingAssertionHelper bh= getAssertionHelper(); ICPPClassType c= bh.assertNonProblem("A", 1); - assertEquals(0, ClassTypeHelper.getPureVirtualMethods(c).length); + assertEquals(0, ClassTypeHelper.getPureVirtualMethods(c, null).length); } // template struct CT1 {}; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 9ae7649f3ad..7a3d4cc0270 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -85,6 +85,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; @@ -1907,7 +1908,7 @@ public class AST2TemplateTests extends AST2BaseTest { ICPPClassType B = (ICPPClassType) col.getName(3).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(6).resolveBinding(); - ICPPBase[] bases = A.getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases(A, tu); assertEquals(bases.length, 1); assertSame(bases[0].getBaseClass(), B); } @@ -4368,19 +4369,19 @@ public class AST2TemplateTests extends AST2BaseTest { BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPClassType type= bh.assertNonProblem("X", 7); - ICPPMethod[] ms= type.getMethods(); + ICPPMethod[] ms= ClassTypeHelper.getMethods(type, null); int i= ms[0].getName().equals("f") ? 0 : 1; ICPPMethod m= ms[i]; assertEquals("int &", ASTTypeUtil.getType(m.getType().getParameterTypes()[0])); - m= ms[1-i]; + m= ms[1 - i]; assertEquals("int &", ASTTypeUtil.getType(m.getType().getParameterTypes()[0])); type= bh.assertNonProblem("X", 14); - ms= type.getMethods(); + ms= ClassTypeHelper.getMethods(type, null); i= ms[0].getName().equals("f") ? 0 : 1; m= ms[i]; assertEquals("const int &", ASTTypeUtil.getType(m.getType().getParameterTypes()[0])); - m= ms[1-i]; + m= ms[1 - i]; assertEquals("const int &&", ASTTypeUtil.getType(m.getType().getParameterTypes()[0])); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java index f5b63b5bc7a..05fc01240ba 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java @@ -56,7 +56,9 @@ import org.eclipse.cdt.core.index.IIndexMacro; import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; import org.eclipse.core.runtime.CoreException; /** @@ -229,7 +231,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas ICPPSpecialization inst= ct.getInstance(new ICPPTemplateArgument[]{new CPPTemplateTypeArgument((IType)b0)}); assertInstance(inst, ICPPClassType.class); ICPPClassType c2t= (ICPPClassType) inst; - ICPPBase[] bases= c2t.getBases(); + ICPPBase[] bases= ClassTypeHelper.getBases(c2t, null); assertEquals(1, bases.length); assertInstance(bases[0].getBaseClass(), ICPPClassType.class); } @@ -998,74 +1000,74 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // class template instance ct= getBindingFromASTName("CT", 7); assertInstance(ct, ICPPTemplateInstance.class); - assertBindings(new String[] {"B"}, ct.getBases()); - assertBindings(new String[] {"n", "m", "B", "CT"}, ct.getAllDeclaredMethods()); - assertBindings(new String[] {"CT", "CT"}, ct.getConstructors()); - assertBindings(new String[] {"g"}, ct.getDeclaredFields()); - assertBindings(new String[] {"n", "CT"}, ct.getDeclaredMethods()); - assertBindings(new String[] {"f", "g"}, ct.getFields()); - assertBindings(new String[] {"m", "n", "CT", "CT", "~CT", "B", "B", "~B", "operator =", "operator ="}, ct.getMethods()); - assertBindings(new String[] {"O"}, ct.getNestedClasses()); + assertBindings(new String[] {"B"}, ClassTypeHelper.getBases(ct, null)); + assertBindings(new String[] {"n", "m", "B", "CT"}, ClassTypeHelper.getAllDeclaredMethods(ct, null)); + assertBindings(new String[] {"CT", "CT"}, ClassTypeHelper.getConstructors(ct, null)); + assertBindings(new String[] {"g"}, ClassTypeHelper.getDeclaredFields(ct, null)); + assertBindings(new String[] {"n", "CT"}, ClassTypeHelper.getDeclaredMethods(ct, null)); + assertBindings(new String[] {"f", "g"}, ClassTypeHelper.getFields(ct, null)); + assertBindings(new String[] {"m", "n", "CT", "CT", "~CT", "B", "B", "~B", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null)); + assertBindings(new String[] {"O"}, ClassTypeHelper.getNestedClasses(ct, null)); // explicit class template instance ct= getBindingFromASTName("CT", 8); assertInstance(ct, ICPPTemplateInstance.class); - assertBindings(new String[] {"A"}, ct.getBases()); - assertBindings(new String[] {"o", "l", "A", "CT", "CT"}, ct.getAllDeclaredMethods()); - assertBindings(new String[] {"CT", "CT", "CT"}, ct.getConstructors()); - assertBindings(new String[] {"h"}, ct.getDeclaredFields()); - assertBindings(new String[] {"o", "CT", "CT"}, ct.getDeclaredMethods()); - assertBindings(new String[] {"e", "h"}, ct.getFields()); - assertBindings(new String[] {"l", "o", "CT", "CT", "CT", "~CT", "A", "A", "~A", "operator =", "operator ="}, ct.getMethods()); - assertBindings(new String[] {"P"}, ct.getNestedClasses()); + assertBindings(new String[] {"A"}, ClassTypeHelper.getBases(ct, null)); + assertBindings(new String[] {"o", "l", "A", "CT", "CT"}, ClassTypeHelper.getAllDeclaredMethods(ct, null)); + assertBindings(new String[] {"CT", "CT", "CT"}, ClassTypeHelper.getConstructors(ct, null)); + assertBindings(new String[] {"h"}, ClassTypeHelper.getDeclaredFields(ct, null)); + assertBindings(new String[] {"o", "CT", "CT"}, ClassTypeHelper.getDeclaredMethods(ct, null)); + assertBindings(new String[] {"e", "h"}, ClassTypeHelper.getFields(ct, null)); + assertBindings(new String[] {"l", "o", "CT", "CT", "CT", "~CT", "A", "A", "~A", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null)); + assertBindings(new String[] {"P"}, ClassTypeHelper.getNestedClasses(ct, null)); // class specialization ct= getBindingFromASTName("C spec", 1); assertInstance(ct, ICPPClassSpecialization.class); - assertBindings(new String[] {"B"}, ct.getBases()); - assertBindings(new String[] {"n", "m", "B", "C"}, ct.getAllDeclaredMethods()); - assertBindings(new String[] {"C", "C"}, ct.getConstructors()); - assertBindings(new String[] {"g"}, ct.getDeclaredFields()); - assertBindings(new String[] {"n", "C"}, ct.getDeclaredMethods()); - assertBindings(new String[] {"f", "g"}, ct.getFields()); - assertBindings(new String[] {"m", "n", "C", "C", "~C", "B", "B", "~B", "operator =", "operator ="}, ct.getMethods()); - assertBindings(new String[] {"O"}, ct.getNestedClasses()); + assertBindings(new String[] {"B"}, ClassTypeHelper.getBases(ct, null)); + assertBindings(new String[] {"n", "m", "B", "C"}, ClassTypeHelper.getAllDeclaredMethods(ct, null)); + assertBindings(new String[] {"C", "C"}, ClassTypeHelper.getConstructors(ct, null)); + assertBindings(new String[] {"g"}, ClassTypeHelper.getDeclaredFields(ct, null)); + assertBindings(new String[] {"n", "C"}, ClassTypeHelper.getDeclaredMethods(ct, null)); + assertBindings(new String[] {"f", "g"}, ClassTypeHelper.getFields(ct, null)); + assertBindings(new String[] {"m", "n", "C", "C", "~C", "B", "B", "~B", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null)); + assertBindings(new String[] {"O"}, ClassTypeHelper.getNestedClasses(ct, null)); // class template specialization ct= getBindingFromASTName("CT spect", 2); assertInstance(ct, ICPPClassTemplate.class, ICPPClassSpecialization.class); - assertBindings(new String[] {"B"}, ct.getBases()); - assertBindings(new String[] {"n", "m", "B", "CT"}, ct.getAllDeclaredMethods()); - assertBindings(new String[] {"CT", "CT"}, ct.getConstructors()); - assertBindings(new String[] {"g"}, ct.getDeclaredFields()); - assertBindings(new String[] {"n", "CT"}, ct.getDeclaredMethods()); - assertBindings(new String[] {"f", "g"}, ct.getFields()); - assertBindings(new String[] {"m", "n", "CT", "CT", "~CT", "B", "B", "~B", "operator =", "operator ="}, ct.getMethods()); - assertBindings(new String[] {"O"}, ct.getNestedClasses()); + assertBindings(new String[] {"B"}, ClassTypeHelper.getBases(ct, null)); + assertBindings(new String[] {"n", "m", "B", "CT"}, ClassTypeHelper.getAllDeclaredMethods(ct, null)); + assertBindings(new String[] {"CT", "CT"}, ClassTypeHelper.getConstructors(ct, null)); + assertBindings(new String[] {"g"}, ClassTypeHelper.getDeclaredFields(ct, null)); + assertBindings(new String[] {"n", "CT"}, ClassTypeHelper.getDeclaredMethods(ct, null)); + assertBindings(new String[] {"f", "g"}, ClassTypeHelper.getFields(ct, null)); + assertBindings(new String[] {"m", "n", "CT", "CT", "~CT", "B", "B", "~B", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null)); + assertBindings(new String[] {"O"}, ClassTypeHelper.getNestedClasses(ct, null)); // explicit class specialization ct= getBindingFromASTName("C espec", 1); assertInstance(ct, ICPPClassSpecialization.class); - assertBindings(new String[] {"A"}, ct.getBases()); - assertBindings(new String[] {"o", "l", "A", "C", "C"}, ct.getAllDeclaredMethods()); - assertBindings(new String[] {"C", "C", "C"}, ct.getConstructors()); - assertBindings(new String[] {"h"}, ct.getDeclaredFields()); - assertBindings(new String[] {"o", "C", "C"}, ct.getDeclaredMethods()); - assertBindings(new String[] {"e", "h"}, ct.getFields()); - assertBindings(new String[] {"l", "o", "C", "C", "C", "~C", "A", "A", "~A", "operator =", "operator ="}, ct.getMethods()); - assertBindings(new String[] {"P"}, ct.getNestedClasses()); + assertBindings(new String[] {"A"}, ClassTypeHelper.getBases(ct, null)); + assertBindings(new String[] {"o", "l", "A", "C", "C"}, ClassTypeHelper.getAllDeclaredMethods(ct, null)); + assertBindings(new String[] {"C", "C", "C"}, ClassTypeHelper.getConstructors(ct, null)); + assertBindings(new String[] {"h"}, ClassTypeHelper.getDeclaredFields(ct, null)); + assertBindings(new String[] {"o", "C", "C"}, ClassTypeHelper.getDeclaredMethods(ct, null)); + assertBindings(new String[] {"e", "h"}, ClassTypeHelper.getFields(ct, null)); + assertBindings(new String[] {"l", "o", "C", "C", "C", "~C", "A", "A", "~A", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null)); + assertBindings(new String[] {"P"}, ClassTypeHelper.getNestedClasses(ct, null)); // explicit class template specialization ct= getBindingFromASTName("CT espect", 7); assertInstance(ct, ICPPTemplateInstance.class); - assertBindings(new String[] {"A"}, ct.getBases()); - assertBindings(new String[] {"o", "l", "A", "CT", "CT"}, ct.getAllDeclaredMethods()); - assertBindings(new String[] {"CT", "CT", "CT"}, ct.getConstructors()); - assertBindings(new String[] {"h"}, ct.getDeclaredFields()); - assertBindings(new String[] {"o", "CT", "CT"}, ct.getDeclaredMethods()); - assertBindings(new String[] {"e", "h"}, ct.getFields()); - assertBindings(new String[] {"l", "o", "CT", "CT", "CT", "~CT", "A", "A", "~A", "operator =", "operator ="}, ct.getMethods()); - assertBindings(new String[] {"P"}, ct.getNestedClasses()); + assertBindings(new String[] {"A"}, ClassTypeHelper.getBases(ct, null)); + assertBindings(new String[] {"o", "l", "A", "CT", "CT"}, ClassTypeHelper.getAllDeclaredMethods(ct, null)); + assertBindings(new String[] {"CT", "CT", "CT"}, ClassTypeHelper.getConstructors(ct, null)); + assertBindings(new String[] {"h"}, ClassTypeHelper.getDeclaredFields(ct, null)); + assertBindings(new String[] {"o", "CT", "CT"}, ClassTypeHelper.getDeclaredMethods(ct, null)); + assertBindings(new String[] {"e", "h"}, ClassTypeHelper.getFields(ct, null)); + assertBindings(new String[] {"l", "o", "CT", "CT", "CT", "~CT", "A", "A", "~A", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null)); + assertBindings(new String[] {"P"}, ClassTypeHelper.getNestedClasses(ct, null)); } // void func(const int* x) {} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java index 303976fb74f..da5652cb9c5 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java @@ -10,6 +10,7 @@ * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.index.tests; + import java.util.ArrayList; import java.util.List; @@ -57,13 +58,13 @@ import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.core.runtime.CoreException; - /** * Tests for exercising resolution of template bindings against IIndex */ @@ -629,23 +630,23 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertInstance(b2, ICPPClassType.class); assertInstance(b2, ICPPTemplateInstance.class); ICPPClassType ct2= (ICPPClassType) b2; - ICPPBase[] bss2= ct2.getBases(); + ICPPBase[] bss2= ClassTypeHelper.getBases(ct2, null); assertEquals(1, bss2.length); assertInstance(bss2[0].getBaseClass(), ICPPClassType.class); ICPPClassType ct2b= (ICPPClassType) bss2[0].getBaseClass(); assertInstance(ct2b, ICPPTemplateInstance.class); - + IBinding b0= getBindingFromASTName("B", 6); assertInstance(b0, ICPPClassType.class); ICPPClassType ct= (ICPPClassType) b0; - ICPPBase[] bss= ct.getBases(); + ICPPBase[] bss= ClassTypeHelper.getBases(ct, null); assertEquals(1, bss.length); assertInstance(bss[0].getBaseClass(), ICPPClassType.class); - + IBinding b1= getBindingFromASTName("B", 7); assertInstance(b1, ICPPClassType.class); ICPPClassType ct1= (ICPPClassType) b1; - ICPPBase[] bss1= ct1.getBases(); + ICPPBase[] bss1= ClassTypeHelper.getBases(ct1, null); assertEquals(1, bss1.length); assertInstance(bss1[0].getBaseClass(), ICPPClassType.class); } @@ -672,13 +673,13 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa IBinding b0= getBindingFromASTName("A ab", 4); assertInstance(b0, ICPPClassType.class); assertInstance(b0, ICPPSpecialization.class); - + ICPPClassType ct= (ICPPClassType) b0; - ICPPMethod[] dms= ct.getDeclaredMethods(); + ICPPMethod[] dms= ClassTypeHelper.getDeclaredMethods(ct, null); assertEquals(2, dms.length); // if the specialization was used, we have 2 fields. - ICPPField[] fs= ct.getDeclaredFields(); + ICPPField[] fs= ClassTypeHelper.getDeclaredFields(ct, null); assertEquals(2, fs.length); ICPPMethod foo= dms[0].getName().equals("foo") ? dms[0] : dms[1]; @@ -1574,7 +1575,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertInstance(m, ICPPSpecialization.class); ICPPClassType ct= m.getClassOwner(); assertInstance(ct, ICPPTemplateInstance.class); - ICPPMethod[] ms= ct.getDeclaredMethods(); + ICPPMethod[] ms= ClassTypeHelper.getDeclaredMethods(ct, null); assertEquals(1, ms.length); assertEquals(m, ms[0]); } @@ -1849,16 +1850,16 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa methods= ct.getMethods(); assertEquals(14, methods.length); - ICPPBase[] bases = ct.getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases(ct, null); assertEquals(1, bases.length); IField field = ct.findField("bfield"); assertNotNull(field); - IField[] fields = ct.getFields(); + IField[] fields = ClassTypeHelper.getFields(ct, null); assertEquals(2, fields.length); - IBinding[] friends = ct.getFriends(); + IBinding[] friends = ClassTypeHelper.getFriends(ct, null); assertEquals(0, friends.length); // not yet supported } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPClassTemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPClassTemplateTests.java index 808169ddf87..e06d3cb350b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPClassTemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPClassTemplateTests.java @@ -18,6 +18,7 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IType; @@ -34,6 +35,7 @@ import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.internal.core.CCoreInternals; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; @@ -237,9 +239,10 @@ public class CPPClassTemplateTests extends PDOMTestBase { ICPPVariable var= (ICPPVariable) bs[0]; assertInstance(var.getType(), ICPPClassType.class); ICPPClassType ct= (ICPPClassType) var.getType(); - assertEquals(1, ct.getFields().length); - assertInstance(ct.getFields()[0].getType(), IPointerType.class); - IPointerType pt= (IPointerType) ct.getFields()[0].getType(); + IField[] fields = ClassTypeHelper.getFields(ct, null); + assertEquals(1, fields.length); + assertInstance(fields[0].getType(), IPointerType.class); + IPointerType pt= (IPointerType) fields[0].getType(); assertInstance(pt.getType(), IFunctionType.class); IFunctionType ft= (IFunctionType) pt.getType(); assertInstance(ft.getReturnType(), ICPPClassType.class); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java index 229697cb7d8..5bef68a2aec 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.core.dom.ast.cpp; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IField; /** * Specializations of all sorts of class types. @@ -59,6 +60,20 @@ public interface ICPPClassSpecialization extends ICPPSpecialization, ICPPClassTy */ ICPPField[] getDeclaredFields(IASTNode point); + /** + * Similar to {@link ICPPClassType#getMethods()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + ICPPMethod[] getMethods(IASTNode point); + + /** + * Similar to {@link ICPPClassType#getAllDeclaredMethods()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + ICPPMethod[] getAllDeclaredMethods(IASTNode point); + /** * Similar to {@link ICPPClassType#getDeclaredMethods()} but a accepts a starting point * for template instantiation. @@ -73,6 +88,13 @@ public interface ICPPClassSpecialization extends ICPPSpecialization, ICPPClassTy */ IBinding[] getFriends(IASTNode point); + /** + * Similar to {@link ICPPClassType#getFriends()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + IField[] getFields(IASTNode point); + /** * Similar to {@link ICPPClassType#getNestedClasses()} but a accepts a starting point * for template instantiation. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethodSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethodSpecialization.java new file mode 100644 index 00000000000..1f2a1ed41cc --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethodSpecialization.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2012 Google, Inc and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.dom.ast.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IType; + +/** + * Specialization of a method. + * @since 5.5 + * + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface ICPPMethodSpecialization extends ICPPSpecialization, ICPPMethod { + /** + * Similar to {@link ICPPFunction#getExceptionSpecification()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + IType[] getExceptionSpecification(IASTNode point); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java index aa3ed3d9321..625ec0c2446 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java @@ -49,6 +49,8 @@ public class SizeofCalculator { } } + private static final SizeofCalculator defaultInstance = new SizeofCalculator(); + private static final SizeAndAlignment SIZE_1 = new SizeAndAlignment(1, 1); public final SizeAndAlignment size_2; @@ -68,6 +70,15 @@ public class SizeofCalculator { public final SizeAndAlignment sizeof_long_double; public final SizeAndAlignment sizeof_complex_long_double; + /** + * Returns the default instance of sizeof calculator. The default instance is not aware + * of the parser configuration and can only calculate sizes that are the same across all + * C/C++ implementations. + */ + public static SizeofCalculator getDefault() { + return defaultInstance; + } + public SizeofCalculator(IASTTranslationUnit ast) { int maxAlignment = 32; Map sizeofMacros = new HashMap(); @@ -103,6 +114,25 @@ public class SizeofCalculator { sizeof_complex_long_double = getSizeOfPair(sizeof_long_double); } + private SizeofCalculator() { + size_2 = new SizeAndAlignment(2, 2); + size_4 = new SizeAndAlignment(4, 4); + size_8 = new SizeAndAlignment(8, 8); + sizeof_pointer = null; + sizeof_int = null; + sizeof_long = null; + sizeof_long_long = null; + sizeof_short = null; + sizeof_bool = null; + sizeof_wchar_t = null; + sizeof_float = null; + sizeof_complex_float = null; + sizeof_double = null; + sizeof_complex_double = null; + sizeof_long_double = null; + sizeof_complex_long_double = null; + } + /** * Calculates size and alignment for the given type. * @param type the type to get size and alignment for. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java index 0c02d4274c4..5b21be4b3a1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java @@ -14,6 +14,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.EScopeKind; @@ -128,7 +129,7 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat public ICPPBase[] getBases(IASTNode point) { if (fBases == null) { ICPPBase[] result = null; - ICPPBase[] bases = specialClass.getSpecializedBinding().getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases(specialClass.getSpecializedBinding(), point); if (bases.length == 0) { fBases= bases; } else { @@ -136,7 +137,8 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat for (ICPPBase base : bases) { IBinding origClass = base.getBaseClass(); if (origClass instanceof ICPPTemplateParameter && ((ICPPTemplateParameter) origClass).isParameterPack()) { - IType[] specClasses= CPPTemplates.instantiateTypes(new IType[]{new CPPParameterPackType((IType) origClass)}, tpmap, -1, specialClass, point); + IType[] specClasses= CPPTemplates.instantiateTypes(new IType[] { new CPPParameterPackType((IType) origClass) }, + tpmap, -1, specialClass, point); if (specClasses.length == 1 && specClasses[0] instanceof ICPPParameterPackType) { result= ArrayUtil.append(ICPPBase.class, result, base); } else { @@ -183,13 +185,14 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat @Override public ICPPField[] getDeclaredFields(IASTNode point) { - ICPPField[] fields= specialClass.getSpecializedBinding().getDeclaredFields(); + ICPPField[] fields= ClassTypeHelper.getDeclaredFields(specialClass.getSpecializedBinding(), point); return specializeMembers(fields, point); } @Override public ICPPMethod[] getImplicitMethods() { - return getImplicitMethods(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getImplicitMethods(null); } @Override @@ -211,30 +214,31 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat @Override public ICPPConstructor[] getConstructors() { - return getConstructors(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getConstructors(null); } @Override public ICPPConstructor[] getConstructors(IASTNode point) { - ICPPConstructor[] ctors= specialClass.getSpecializedBinding().getConstructors(); + ICPPConstructor[] ctors= ClassTypeHelper.getConstructors(specialClass.getSpecializedBinding(), point); return specializeMembers(ctors, point); } @Override public ICPPMethod[] getDeclaredMethods(IASTNode point) { - ICPPMethod[] bindings = specialClass.getSpecializedBinding().getDeclaredMethods(); + ICPPMethod[] bindings = ClassTypeHelper.getDeclaredMethods(specialClass.getSpecializedBinding(), point); return specializeMembers(bindings, point); } @Override public ICPPClassType[] getNestedClasses(IASTNode point) { - ICPPClassType[] bindings = specialClass.getSpecializedBinding().getNestedClasses(); + ICPPClassType[] bindings = ClassTypeHelper.getNestedClasses(specialClass.getSpecializedBinding(), point); return specializeMembers(bindings, point); } @Override public IBinding[] getFriends(IASTNode point) { - IBinding[] friends = specialClass.getSpecializedBinding().getFriends(); + IBinding[] friends = ClassTypeHelper.getFriends(specialClass.getSpecializedBinding(), point); return specializeMembers(friends, point); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java index bc482f514c9..60e3b2a1a4c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java @@ -175,7 +175,7 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements IBinding method= fdef.getDeclarator().getName().resolveBinding(); if (method instanceof ICPPMethod) { ICPPClassType cls= ((ICPPMethod) method).getClassOwner(); - for (ICPPBase base : SemanticUtil.getBases(cls, fdef)) { + for (ICPPBase base : ClassTypeHelper.getBases(cls, fdef)) { result.put(base.getBaseClassSpecifierName().getSimpleID()); } return result; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java index 0c74af3421a..25fb6187c7e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java @@ -43,6 +43,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFunctionCall; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalTypeId; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.LookupData; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; public class CPPASTFunctionCallExpression extends ASTNode implements ICPPASTFunctionCallExpression, IASTAmbiguityParent { @@ -270,7 +271,7 @@ public class CPPASTFunctionCallExpression extends ASTNode ICPPClassType cls= (ICPPClassType) t; LookupData data= CPPSemantics.createLookupData(((IASTIdExpression) functionName).getName()); try { - IBinding b= CPPSemantics.resolveFunction(data, cls.getConstructors(), true); + IBinding b= CPPSemantics.resolveFunction(data, ClassTypeHelper.getConstructors(cls, data.getLookupPoint()), true); if (b instanceof ICPPFunction) return (ICPPFunction) b; } catch (DOMException e) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java index 5c7e349989a..b59a06e4189 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java @@ -278,7 +278,7 @@ public class CPPASTQualifiedName extends CPPASTNameBase List filtered = filterClassScopeBindings(classType, bindings, isDeclaration); if (isDeclaration && nameMatches(classType.getNameCharArray(), n.getLookupKey(), isPrefix)) { - ICPPConstructor[] constructors = SemanticUtil.getConstructors(classType, n); + ICPPConstructor[] constructors = ClassTypeHelper.getConstructors(classType, n); for (int i = 0; i < constructors.length; i++) { if (!constructors[i].isImplicit()) { filtered.add(constructors[i]); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java index e8a8497f532..92205e34e45 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java @@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import java.util.HashSet; import java.util.Set; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; @@ -122,7 +123,8 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPBase[] getBases() { - return getBases(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getBases(null); } @Override @@ -136,7 +138,8 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPField[] getDeclaredFields() { - return getDeclaredFields(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getDeclaredFields(null); } @Override @@ -150,7 +153,8 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPMethod[] getDeclaredMethods() { - return getDeclaredMethods(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getDeclaredMethods(null); } @Override @@ -164,7 +168,8 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPConstructor[] getConstructors() { - return getConstructors(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getConstructors(null); } @Override @@ -178,7 +183,8 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public IBinding[] getFriends() { - return getFriends(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getFriends(null); } @Override @@ -192,7 +198,8 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPClassType[] getNestedClasses() { - return getNestedClasses(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getNestedClasses(null); } @Override @@ -206,7 +213,13 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public IField[] getFields() { - return ClassTypeHelper.getFields(this); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getFields(null); + } + + @Override + public IField[] getFields(IASTNode point) { + return ClassTypeHelper.getFields(this, point); } @Override @@ -216,12 +229,24 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPMethod[] getMethods() { - return ClassTypeHelper.getMethods(this); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getMethods(null); + } + + @Override + public ICPPMethod[] getMethods(IASTNode point) { + return ClassTypeHelper.getMethods(this, point); } @Override public ICPPMethod[] getAllDeclaredMethods() { - return ClassTypeHelper.getAllDeclaredMethods(this); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getAllDeclaredMethods(null); + } + + @Override + public ICPPMethod[] getAllDeclaredMethods(IASTNode point) { + return ClassTypeHelper.getAllDeclaredMethods(this, point); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java index a7aa9075a67..b5093453da0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java @@ -159,7 +159,7 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements ICPPClass @Override public IField[] getFields() { - return ClassTypeHelper.getFields(this); + return ClassTypeHelper.getFields(this, null); } @Override @@ -169,12 +169,12 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements ICPPClass @Override public ICPPMethod[] getMethods() { - return ClassTypeHelper.getMethods(this); + return ClassTypeHelper.getMethods(this, null); } @Override public ICPPMethod[] getAllDeclaredMethods() { - return ClassTypeHelper.getAllDeclaredMethods(this); + return ClassTypeHelper.getAllDeclaredMethods(this, null); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java index 32e50325a8d..4bdd0ab55ab 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java @@ -43,7 +43,7 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization @Override public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() { if (fPartialSpecs == null) { - IASTNode point= null; // Instantiation of dependent expression may not work. + IASTNode point= null; // Instantiation of dependent expressions may not work. ICPPClassTemplate origTemplate= (ICPPClassTemplate) getSpecializedBinding(); ICPPClassTemplatePartialSpecialization[] orig = origTemplate.getPartialSpecializations(); ICPPClassTemplatePartialSpecialization[] spec = new ICPPClassTemplatePartialSpecialization[orig.length]; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java index 08dfc43baae..b6a32c6a886 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java @@ -309,7 +309,7 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp @Override public IField[] getFields() { - return ClassTypeHelper.getFields(this); + return ClassTypeHelper.getFields(this, null); } @Override @@ -319,12 +319,12 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp @Override public ICPPMethod[] getMethods() { - return ClassTypeHelper.getMethods(this); + return ClassTypeHelper.getMethods(this, null); } @Override public ICPPMethod[] getAllDeclaredMethods() { - return ClassTypeHelper.getAllDeclaredMethods(this); + return ClassTypeHelper.getAllDeclaredMethods(this, null); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java index 229f129609a..bf44bc27797 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java @@ -194,6 +194,6 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod @Override public IType[] getExceptionSpecification() { - return ClassTypeHelper.getInheritedExceptionSpecification(this); + return ClassTypeHelper.getInheritedExceptionSpecification(this, null); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java index a8baca56672..988ae58bccd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2010 IBM Corporation and others. + * Copyright (c) 2005, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * Andrew Niefer (IBM) - Initial API and implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -20,20 +21,27 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethodSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; /** * The specialization of a method in the context of a class-specialization. */ -public class CPPMethodSpecialization extends CPPFunctionSpecialization implements ICPPMethod { +public class CPPMethodSpecialization extends CPPFunctionSpecialization implements ICPPMethodSpecialization { - public CPPMethodSpecialization(ICPPMethod orig, ICPPClassType owner, ICPPTemplateParameterMap argMap, ICPPFunctionType type, IType[] exceptionSpec ) { - super(orig, owner, argMap, type, exceptionSpec ); + public CPPMethodSpecialization(ICPPMethod orig, ICPPClassType owner, ICPPTemplateParameterMap argMap, + ICPPFunctionType type, IType[] exceptionSpec) { + super(orig, owner, argMap, type, exceptionSpec); + } + + @Override + public ICPPMethod getSpecializedBinding() { + return (ICPPMethod) super.getSpecializedBinding(); } @Override public boolean isVirtual() { - ICPPMethod f = (ICPPMethod) getSpecializedBinding(); + ICPPMethod f = getSpecializedBinding(); if (f != null) return f.isVirtual(); IASTNode definition = getDefinition(); @@ -58,7 +66,7 @@ public class CPPMethodSpecialization extends CPPFunctionSpecialization implement @Override public int getVisibility() { - ICPPMethod f = (ICPPMethod) getSpecializedBinding(); + ICPPMethod f = getSpecializedBinding(); if (f != null) return f.getVisibility(); return 0; @@ -80,17 +88,17 @@ public class CPPMethodSpecialization extends CPPFunctionSpecialization implement @Override public boolean isExplicit() { - return ((ICPPMethod) getSpecializedBinding()).isExplicit(); + return getSpecializedBinding().isExplicit(); } @Override public boolean isImplicit() { - return ((ICPPMethod) getSpecializedBinding()).isImplicit(); + return getSpecializedBinding().isImplicit(); } @Override public boolean isPureVirtual() { - ICPPMethod f = (ICPPMethod) getSpecializedBinding(); + ICPPMethod f = getSpecializedBinding(); if (f != null) return f.isPureVirtual(); @@ -98,9 +106,9 @@ public class CPPMethodSpecialization extends CPPFunctionSpecialization implement } @Override - public IType[] getExceptionSpecification() { + public IType[] getExceptionSpecification(IASTNode point) { if (isImplicit()) { - return ClassTypeHelper.getInheritedExceptionSpecification(this); + return ClassTypeHelper.getInheritedExceptionSpecification(this, point); } return super.getExceptionSpecification(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java index d2b13592b99..2debf208a5c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java @@ -54,6 +54,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; @@ -101,14 +102,14 @@ public class ClassTypeHelper { IASTDeclaration[] members = host.getCompositeTypeSpecifier().getMembers(); for (IASTDeclaration decl : members) { while (decl instanceof ICPPASTTemplateDeclaration) - decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration(); + decl = ((ICPPASTTemplateDeclaration) decl).getDeclaration(); if (decl instanceof IASTSimpleDeclaration) { - ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)decl).getDeclSpecifier(); + ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration) decl).getDeclSpecifier(); if (declSpec.isFriend()) { - IASTDeclarator[] dtors = ((IASTSimpleDeclaration)decl).getDeclarators(); + IASTDeclarator[] dtors = ((IASTSimpleDeclaration) decl).getDeclarators(); if (declSpec instanceof ICPPASTElaboratedTypeSpecifier && dtors.length == 0) { - resultSet.put(((ICPPASTElaboratedTypeSpecifier)declSpec).getName().resolveBinding()); + resultSet.put(((ICPPASTElaboratedTypeSpecifier) declSpec).getName().resolveBinding()); } else { for (IASTDeclarator dtor : dtors) { if (dtor == null) break; @@ -118,9 +119,9 @@ public class ClassTypeHelper { } } } else if (decl instanceof IASTFunctionDefinition) { - ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition)decl).getDeclSpecifier(); + ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition) decl).getDeclSpecifier(); if (declSpec.isFriend()) { - IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator(); + IASTDeclarator dtor = ((IASTFunctionDefinition) decl).getDeclarator(); dtor= ASTQueries.findInnermostDeclarator(dtor); resultSet.put(dtor.getName().resolveBinding()); } @@ -144,7 +145,7 @@ public class ClassTypeHelper { if (type.isSameType(classType)) { return true; } - for (IBinding friend : classType.getFriends()) { + for (IBinding friend : getFriends(classType, null)) { if (friend instanceof ICPPClassType && type.isSameType((IType) friend)) { return true; } @@ -152,7 +153,7 @@ public class ClassTypeHelper { } else if (binding instanceof ICPPFunction) { type = ((ICPPFunction) binding).getType(); char[] name = binding.getNameCharArray(); - for (IBinding friend : classType.getFriends()) { + for (IBinding friend : getFriends(classType, null)) { if (friend instanceof ICPPFunction && CharArrayUtils.equals(name, friend.getNameCharArray()) && SemanticUtil.isSameOwner(binding.getOwner(), friend.getOwner()) && @@ -217,17 +218,17 @@ public class ClassTypeHelper { IASTDeclaration[] decls = host.getCompositeTypeSpecifier().getMembers(); for (IASTDeclaration decl : decls) { if (decl instanceof IASTSimpleDeclaration) { - IASTDeclarator[] dtors = ((IASTSimpleDeclaration)decl).getDeclarators(); + IASTDeclarator[] dtors = ((IASTSimpleDeclaration) decl).getDeclarators(); for (IASTDeclarator dtor : dtors) { binding = ASTQueries.findInnermostDeclarator(dtor).getName().resolveBinding(); if (binding instanceof ICPPField) result = ArrayUtil.append(ICPPField.class, result, (ICPPField) binding); } } else if (decl instanceof ICPPASTUsingDeclaration) { - IASTName n = ((ICPPASTUsingDeclaration)decl).getName(); + IASTName n = ((ICPPASTUsingDeclaration) decl).getName(); binding = n.resolveBinding(); if (binding instanceof ICPPUsingDeclaration) { - IBinding[] bs = ((ICPPUsingDeclaration)binding).getDelegates(); + IBinding[] bs = ((ICPPUsingDeclaration) binding).getDelegates(); for (IBinding element : bs) { if (element instanceof ICPPField) result = ArrayUtil.append(ICPPField.class, result, (ICPPField) element); @@ -240,27 +241,63 @@ public class ClassTypeHelper { return ArrayUtil.trim(ICPPField.class, result); } + public static ICPPBase[] getBases(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getBases(point); + return classType.getBases(); + } + + public static ICPPConstructor[] getConstructors(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getConstructors(point); + return classType.getConstructors(); + } + + public static ICPPField[] getDeclaredFields(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getDeclaredFields(point); + return classType.getDeclaredFields(); + } + + public static ICPPMethod[] getDeclaredMethods(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getDeclaredMethods(point); + return classType.getDeclaredMethods(); + } + + public static IBinding[] getFriends(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getFriends(point); + return classType.getFriends(); + } + + public static ICPPClassType[] getNestedClasses(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getNestedClasses(point); + return classType.getNestedClasses(); + } + /** * Returns all direct and indirect base classes. * @param classType a class * @return An array of visible base classes in arbitrary order. */ - public static ICPPClassType[] getAllBases(ICPPClassType classType) { + public static ICPPClassType[] getAllBases(ICPPClassType classType, IASTNode point) { HashSet result= new HashSet(); result.add(classType); - getAllBases(classType, result); + getAllBases(classType, result, point); result.remove(classType); return result.toArray(new ICPPClassType[result.size()]); } - private static void getAllBases(ICPPClassType classType, HashSet result) { - ICPPBase[] bases= classType.getBases(); + private static void getAllBases(ICPPClassType classType, HashSet result, IASTNode point) { + ICPPBase[] bases= ClassTypeHelper.getBases(classType, point); for (ICPPBase base : bases) { IBinding b= base.getBaseClass(); if (b instanceof ICPPClassType) { final ICPPClassType baseClass = (ICPPClassType) b; if (result.add(baseClass)) { - getAllBases(baseClass, result); + getAllBases(baseClass, result, point); } } } @@ -287,25 +324,22 @@ public class ClassTypeHelper { return false; } - public static ICPPMethod[] getAllDeclaredMethods(ICPPClassType ct) { - ICPPMethod[] methods= ct.getDeclaredMethods(); - ICPPClassType[] bases= getAllBases(ct); + public static ICPPMethod[] getAllDeclaredMethods(ICPPClassType ct, IASTNode point) { + ICPPMethod[] methods= getDeclaredMethods(ct, point); + ICPPClassType[] bases= getAllBases(ct, point); for (ICPPClassType base : bases) { - methods = ArrayUtil.addAll(ICPPMethod.class, methods, base.getDeclaredMethods()); + methods = ArrayUtil.addAll(ICPPMethod.class, methods, getDeclaredMethods(base, point)); } return ArrayUtil.trim(ICPPMethod.class, methods); } - public static ICPPMethod[] getMethods(ICPPClassType ct) { - ObjectSet set = getOwnMethods(ct); + public static ICPPMethod[] getMethods(ICPPClassType ct, IASTNode point) { + ObjectSet set = getOwnMethods(ct, point); - ICPPClassType[] bases= getAllBases(ct); + ICPPClassType[] bases= getAllBases(ct, point); for (ICPPClassType base : bases) { - set.addAll(base.getDeclaredMethods()); - final IScope compositeScope = base.getCompositeScope(); - if (compositeScope instanceof ICPPClassScope) { - set.addAll(((ICPPClassScope) compositeScope).getImplicitMethods()); - } + set.addAll(getDeclaredMethods(base, point)); + set.addAll(getImplicitMethods(base, point)); } return set.keyArray(ICPPMethod.class); } @@ -314,16 +348,23 @@ public class ClassTypeHelper { * Returns methods either declared by the given class or generated by the compiler. Does not * include methods declared in base classes. */ - private static ObjectSet getOwnMethods(ICPPClassType classType) { + private static ObjectSet getOwnMethods(ICPPClassType classType, IASTNode point) { ObjectSet set= new ObjectSet(4); - set.addAll(classType.getDeclaredMethods()); - IScope scope = classType.getCompositeScope(); - if (scope instanceof ICPPClassScope) { - set.addAll(((ICPPClassScope) scope).getImplicitMethods()); - } + set.addAll(ClassTypeHelper.getDeclaredMethods(classType, point)); + set.addAll(getImplicitMethods(classType, point)); return set; } + public static ICPPMethod[] getImplicitMethods(ICPPClassType classType, IASTNode point) { + IScope scope = classType.getCompositeScope(); + if (scope instanceof ICPPClassSpecializationScope) { + return ((ICPPClassSpecializationScope) scope).getImplicitMethods(point); + } else if (scope instanceof ICPPClassScope) { + return ((ICPPClassScope) scope).getImplicitMethods(); + } + return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; + } + public static ICPPMethod[] getDeclaredMethods(ICPPInternalClassTypeMixinHost host) { if (host.getDefinition() == null) { host.checkForDefinition(); @@ -341,9 +382,9 @@ public class ClassTypeHelper { IASTDeclaration[] decls = host.getCompositeTypeSpecifier().getMembers(); for (IASTDeclaration decl : decls) { while (decl instanceof ICPPASTTemplateDeclaration) - decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration(); + decl = ((ICPPASTTemplateDeclaration) decl).getDeclaration(); if (decl instanceof IASTSimpleDeclaration) { - final IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration)decl; + final IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration) decl; if (!((ICPPASTDeclSpecifier) sdecl.getDeclSpecifier()).isFriend()) { IASTDeclarator[] dtors = sdecl.getDeclarators(); for (IASTDeclarator dtor : dtors) { @@ -353,7 +394,7 @@ public class ClassTypeHelper { } } } else if (decl instanceof IASTFunctionDefinition) { - final IASTFunctionDefinition fdef = (IASTFunctionDefinition)decl; + final IASTFunctionDefinition fdef = (IASTFunctionDefinition) decl; if (!((ICPPASTDeclSpecifier) fdef.getDeclSpecifier()).isFriend()) { IASTDeclarator dtor = fdef.getDeclarator(); dtor = ASTQueries.findInnermostDeclarator(dtor); @@ -363,10 +404,10 @@ public class ClassTypeHelper { } } } else if (decl instanceof ICPPASTUsingDeclaration) { - IASTName n = ((ICPPASTUsingDeclaration)decl).getName(); + IASTName n = ((ICPPASTUsingDeclaration) decl).getName(); binding = n.resolveBinding(); if (binding instanceof ICPPUsingDeclaration) { - IBinding[] bs = ((ICPPUsingDeclaration)binding).getDelegates(); + IBinding[] bs = ((ICPPUsingDeclaration) binding).getDelegates(); for (IBinding element : bs) { if (element instanceof ICPPMethod) result = ArrayUtil.append(ICPPMethod.class, result, (ICPPMethod) element); @@ -407,15 +448,15 @@ public class ClassTypeHelper { IASTDeclaration[] decls = host.getCompositeTypeSpecifier().getMembers(); for (IASTDeclaration decl : decls) { while (decl instanceof ICPPASTTemplateDeclaration) - decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration(); + decl = ((ICPPASTTemplateDeclaration) decl).getDeclaration(); if (decl instanceof IASTSimpleDeclaration) { IBinding binding = null; IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration) decl).getDeclSpecifier(); if (declSpec instanceof ICPPASTCompositeTypeSpecifier) { - binding = ((ICPPASTCompositeTypeSpecifier)declSpec).getName().resolveBinding(); + binding = ((ICPPASTCompositeTypeSpecifier) declSpec).getName().resolveBinding(); } else if (declSpec instanceof ICPPASTElaboratedTypeSpecifier && - ((IASTSimpleDeclaration)decl).getDeclarators().length == 0) { - binding = ((ICPPASTElaboratedTypeSpecifier)declSpec).getName().resolveBinding(); + ((IASTSimpleDeclaration) decl).getDeclarators().length == 0) { + binding = ((ICPPASTElaboratedTypeSpecifier) declSpec).getName().resolveBinding(); } if (binding instanceof ICPPClassType) result = ArrayUtil.append(ICPPClassType.class, result, (ICPPClassType) binding); @@ -424,11 +465,11 @@ public class ClassTypeHelper { return ArrayUtil.trim(ICPPClassType.class, result); } - public static IField[] getFields(ICPPClassType ct) { - IField[] fields = ct.getDeclaredFields(); - ICPPClassType[] bases = getAllBases(ct); + public static IField[] getFields(ICPPClassType ct, IASTNode point) { + IField[] fields = getDeclaredFields(ct, point); + ICPPClassType[] bases = getAllBases(ct, point); for (ICPPClassType base : bases) { - fields = ArrayUtil.addAll(IField.class, fields, base.getDeclaredFields()); + fields = ArrayUtil.addAll(IField.class, fields, getDeclaredFields(base, point)); } return ArrayUtil.trim(IField.class, fields); } @@ -464,7 +505,8 @@ public class ClassTypeHelper { final ICPPClassType mcl= m.getClassOwner(); if (mcl != null) { final ICPPFunctionType mft= m.getType(); - ICPPMethod[] allMethods= mcl.getMethods(); + IASTNode point = null; // Instantiation of dependent expressions may not work + ICPPMethod[] allMethods= ClassTypeHelper.getMethods(mcl, point); for (ICPPMethod method : allMethods) { if (CharArrayUtils.equals(mname, method.getNameCharArray()) && functionTypesAllowOverride(mft, method.getType())) { if (method.isVirtual()) { @@ -520,7 +562,7 @@ public class ClassTypeHelper { if (sourceClass == null || targetClass == null) return false; - ICPPClassType[] bases= getAllBases(sourceClass); + ICPPClassType[] bases= getAllBases(sourceClass, null); for (ICPPClassType base : bases) { if (base.isSameType(targetClass)) return true; @@ -532,7 +574,7 @@ public class ClassTypeHelper { /** * Returns all methods that are overridden by the given {@code method}. */ - public static ICPPMethod[] findOverridden(ICPPMethod method) { + public static ICPPMethod[] findOverridden(ICPPMethod method, IASTNode point) { if (method instanceof ICPPConstructor) return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; @@ -546,7 +588,7 @@ public class ClassTypeHelper { final ICPPFunctionType mft= method.getType(); virtualInClass.put(mcl, method.isVirtual()); - ICPPBase[] bases= mcl.getBases(); + ICPPBase[] bases= getBases(mcl, point); for (ICPPBase base : bases) { IBinding b= base.getBaseClass(); if (b instanceof ICPPClassType) { @@ -681,10 +723,10 @@ public class ClassTypeHelper { /** * For implicit methods the exception specification is inherited, search it */ - public static IType[] getInheritedExceptionSpecification(ICPPMethod implicitMethod) { + public static IType[] getInheritedExceptionSpecification(ICPPMethod implicitMethod, IASTNode point) { // See 15.4.13 ICPPClassType owner= implicitMethod.getClassOwner(); - if (owner == null || owner.getBases().length == 0) + if (owner == null || ClassTypeHelper.getBases(owner, point).length == 0) return null; // we use a list as types aren't comparable, and can have duplicates (15.4.6) @@ -693,7 +735,7 @@ public class ClassTypeHelper { return null; List inheritedTypeids = new ArrayList(); - ICPPClassType[] bases= getAllBases(owner); + ICPPClassType[] bases= getAllBases(owner, point); for (ICPPClassType base : bases) { if (!(base instanceof ICPPDeferredClassInstance)) { ICPPMethod baseMethod= getMethodInClass(base, kind); @@ -792,10 +834,10 @@ public class ClassTypeHelper { * no private or protected non-static data members (Clause 11), * no base classes (Clause 10), and no virtual functions (10.3). */ - public static boolean isAggregateClass(ICPPClassType classTarget) { - if (classTarget.getBases().length > 0) + public static boolean isAggregateClass(ICPPClassType classTarget, IASTNode point) { + if (ClassTypeHelper.getBases(classTarget, point).length > 0) return false; - ICPPMethod[] methods = classTarget.getDeclaredMethods(); + ICPPMethod[] methods = ClassTypeHelper.getDeclaredMethods(classTarget, point); for (ICPPMethod m : methods) { if (m instanceof ICPPConstructor) return false; @@ -803,7 +845,7 @@ public class ClassTypeHelper { return false; } } - ICPPField[] fields = classTarget.getDeclaredFields(); + ICPPField[] fields = ClassTypeHelper.getDeclaredFields(classTarget, point); for (ICPPField field : fields) { if (!(field.getVisibility() == ICPPMember.v_public || field.isStatic())) { return false; @@ -837,7 +879,7 @@ public class ClassTypeHelper { if (base.isVirtual()) return false; } - for (ICPPClassType baseClass : getAllBases(classTarget)) { + for (ICPPClassType baseClass : getAllBases(classTarget, null)) { if (!classTarget.isSameType(baseClass) && !hasTrivialCopyCtor(baseClass)) return false; } @@ -889,7 +931,7 @@ public class ClassTypeHelper { if (!ctor.isImplicit() && ctor.getParameters().length == 0) return false; } - for (ICPPClassType baseClass : getAllBases(classTarget)) { + for (ICPPClassType baseClass : getAllBases(classTarget, null)) { if (!classTarget.isSameType(baseClass) && !hasTrivialDefaultConstructor(baseClass)) return false; } @@ -925,7 +967,7 @@ public class ClassTypeHelper { if (method.isDestructor()) return false; } - for (ICPPClassType baseClass : getAllBases(classTarget)) { + for (ICPPClassType baseClass : getAllBases(classTarget, null)) { if (!classTarget.isSameType(baseClass) && !hasTrivialDestructor(baseClass)) return false; } @@ -952,7 +994,7 @@ public class ClassTypeHelper { public static boolean isPolymorphic(ICPPClassType classTarget) { if (hasDeclaredVirtualMethod(classTarget)) return true; - for (ICPPClassType baseClass : getAllBases(classTarget)) { + for (ICPPClassType baseClass : getAllBases(classTarget, null)) { if (hasDeclaredVirtualMethod(baseClass)) return true; } @@ -976,9 +1018,9 @@ public class ClassTypeHelper { * but doesn't take into account base classes and methods dependent on unspecified * template parameters. */ - public static ICPPMethod[] getPureVirtualMethods(ICPPClassType classType) { + public static ICPPMethod[] getPureVirtualMethods(ICPPClassType classType, IASTNode point) { Map> result= collectPureVirtualMethods(classType, - new HashMap>>()); + new HashMap>>(), point); int resultArraySize = 0; for (List methods : result.values()) { @@ -995,7 +1037,7 @@ public class ClassTypeHelper { } private static Map> collectPureVirtualMethods(ICPPClassType classType, - Map>> cache) { + Map>> cache, IASTNode point) { Map> result = cache.get(classType); if (result != null) return result; @@ -1005,10 +1047,10 @@ public class ClassTypeHelper { // Look at the pure virtual methods of the base classes Set handledBaseClasses= new HashSet(); - for (ICPPBase base : classType.getBases()) { + for (ICPPBase base : ClassTypeHelper.getBases(classType, point)) { final IBinding baseClass = base.getBaseClass(); if (baseClass instanceof ICPPClassType && handledBaseClasses.add(baseClass)) { - Map> pureVirtuals = collectPureVirtualMethods((ICPPClassType) baseClass, cache); + Map> pureVirtuals = collectPureVirtualMethods((ICPPClassType) baseClass, cache, point); // Merge derived pure virtual methods for (String key : pureVirtuals.keySet()) { List list = result.get(key); @@ -1021,8 +1063,8 @@ public class ClassTypeHelper { } } - // Remove overridden pure-virtual methods and add in new pure virutals. - final ObjectSet methods = getOwnMethods(classType); + // Remove overridden pure-virtual methods and add in new pure virtuals. + final ObjectSet methods = getOwnMethods(classType, point); for (ICPPMethod method : methods) { String key= getMethodNameForOverrideKey(method); List list = result.get(key); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AccessContext.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AccessContext.java index 78e1a4b670d..42a6213a7b2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AccessContext.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AccessContext.java @@ -152,7 +152,7 @@ public class AccessContext { return isAccessible(bindingVisibility, accessLevel); } - ICPPBase[] bases = derivedClass.getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases(derivedClass, name); if (bases != null) { for (ICPPBase base : bases) { IBinding baseBinding = base.getBaseClass(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java index d8de2c8590d..aee259f5dca 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java @@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; @@ -181,7 +182,7 @@ class BaseClassLookup { // base-classes ICPPClassType baseClass= result.getClassType(); if (baseClass != null) { - ICPPBase[] grandBases= SemanticUtil.getBases(baseClass, data.getLookupPoint()); + ICPPBase[] grandBases= ClassTypeHelper.getBases(baseClass, data.getLookupPoint()); if (grandBases != null && grandBases.length > 0) { HashSet grandBaseBindings= null; BitSet selectedBases= null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java index beafb1b0979..53b6ff28028 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java @@ -27,6 +27,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator; import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument; @@ -251,7 +252,9 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } protected static SizeAndAlignment getSizeAndAlignment(IType type, IASTNode point) { - ASTTranslationUnit ast = (ASTTranslationUnit) point.getTranslationUnit(); - return ast.getSizeofCalculator().sizeAndAlignment(type); + SizeofCalculator calc = point == null ? + SizeofCalculator.getDefault() : + ((ASTTranslationUnit) point.getTranslationUnit()).getSizeofCalculator(); + return calc.sizeAndAlignment(type); } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index f2d1602f903..454b1230c15 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -203,6 +203,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUsingDeclaration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUsingDirective; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPASTInternalScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; @@ -414,7 +415,7 @@ public class CPPSemantics { if (cls instanceof ICPPUnknownBinding) { binding= new CPPUnknownConstructor(cls); } else { - binding= CPPSemantics.resolveFunction(data, SemanticUtil.getConstructors(cls, lookupPoint), true); + binding= CPPSemantics.resolveFunction(data, ClassTypeHelper.getConstructors(cls, lookupPoint), true); } } catch (DOMException e) { return e.getProblem(); @@ -714,7 +715,7 @@ public class CPPSemantics { } if (t instanceof ICPPClassType && !(t instanceof ICPPClassTemplate)) { ICPPClassType ct= (ICPPClassType) t; - ICPPBase[] bases = SemanticUtil.getBases(ct, tu); + ICPPBase[] bases = ClassTypeHelper.getBases(ct, tu); for (ICPPBase base : bases) { IBinding b = base.getBaseClass(); if (b instanceof IType) @@ -725,7 +726,7 @@ public class CPPSemantics { // (excluding template template parameters); // * ... owners of which any template template arguments are members; if (ct instanceof ICPPTemplateInstance) { - for (IBinding friend : ct.getFriends()) { + for (IBinding friend : ClassTypeHelper.getFriends(ct, tu)) { if (friend instanceof ICPPFunction) { friendFns.add((ICPPFunction) friend); } @@ -2817,7 +2818,7 @@ public class CPPSemantics { LookupData data= new LookupData(name); data.setFunctionArguments(false, init.getArguments()); try { - IBinding ctor = CPPSemantics.resolveFunction(data, SemanticUtil.getConstructors((ICPPClassType) targetType, name), true); + IBinding ctor = CPPSemantics.resolveFunction(data, ClassTypeHelper.getConstructors((ICPPClassType) targetType, name), true); if (ctor instanceof ICPPConstructor) { int i= 0; for (IASTNode arg : init.getArguments()) { @@ -3124,13 +3125,13 @@ public class CPPSemantics { LookupData data = new LookupData(astName); data.setFunctionArguments(false, arguments); data.qualified = true; - data.foundItems = SemanticUtil.getConstructors(classType, name); + data.foundItems = ClassTypeHelper.getConstructors(classType, name); binding = resolveAmbiguities(data); if (binding instanceof ICPPConstructor) return (ICPPConstructor) binding; } else if (initializer == null) { // Default initialization - ICPPConstructor[] ctors = SemanticUtil.getConstructors(classType, name); + ICPPConstructor[] ctors = ClassTypeHelper.getConstructors(classType, name); for (ICPPConstructor ctor : ctors) { if (ctor.getRequiredArgumentCount() == 0) return ctor; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index b3b5d1c82ad..4ea01916b56 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -2241,6 +2241,8 @@ public class CPPVisitor extends ASTQueries { } private static IType getStdType(final IASTNode node, char[] name) { + if (node == null) + return null; ASTTranslationUnit ast = (ASTTranslationUnit) node.getTranslationUnit(); IBinding[] std= ast.getScope().find(STD); for (IBinding binding : std) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java index a32ce424546..31d1d843881 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java @@ -371,7 +371,7 @@ public class Conversions { return Cost.NO_CONVERSION; ICPPClassType classTarget= (ICPPClassType) noCVTarget; - if (ClassTypeHelper.isAggregateClass(classTarget)) { + if (ClassTypeHelper.isAggregateClass(classTarget, point)) { Cost cost= new Cost(arg.getTypeOrFunctionSet(point), target, Rank.IDENTITY); cost.setUserDefinedConversion(null); return cost; @@ -546,7 +546,7 @@ public class Conversions { ICPPConstructor usedCtor= null; Cost bestCost= null; boolean hasInitListConstructor= false; - final ICPPConstructor[] constructors = SemanticUtil.getConstructors(t, point); + final ICPPConstructor[] constructors = ClassTypeHelper.getConstructors(t, point); ICPPConstructor[] ctors= constructors; for (ICPPConstructor ctor : ctors) { final int minArgCount = ctor.getRequiredArgumentCount(); @@ -640,7 +640,7 @@ public class Conversions { FunctionCost cost1= null; Cost cost2= null; - ICPPFunction[] ctors= SemanticUtil.getConstructors(t, point); + ICPPFunction[] ctors= ClassTypeHelper.getConstructors(t, point); ctors = CPPTemplates.instantiateForFunctionCall(ctors, null, Collections.singletonList(source), Collections.singletonList(valueCat), false, point); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java index 9779ceb971c..3d9dadf4b01 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java @@ -40,10 +40,7 @@ import org.eclipse.cdt.core.dom.ast.IQualifierType; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; @@ -66,6 +63,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerToMemberType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator; @@ -108,7 +106,7 @@ public class SemanticUtil { if (clazz instanceof ICPPDeferredClassInstance) { clazz= (ICPPClassType) ((ICPPDeferredClassInstance) clazz).getTemplateDefinition(); } - ICPPMethod[] decs= getDeclaredMethods(clazz, point); + ICPPMethod[] decs= ClassTypeHelper.getDeclaredMethods(clazz, point); if (decs != null) { for (ICPPMethod method : decs) { if (isConversionOperator(method)) { @@ -152,7 +150,7 @@ public class SemanticUtil { ICPPClassType clazz= current.keyAt(i); done.put(clazz); - for (ICPPBase base : getBases(clazz, point)) { + for (ICPPBase base : ClassTypeHelper.getBases(clazz, point)) { IBinding binding= base.getBaseClass(); if (binding instanceof ICPPClassType && !(binding instanceof IProblemBinding)) { ICPPClassType ct= (ICPPClassType) binding; @@ -169,42 +167,6 @@ public class SemanticUtil { return done; } - public static ICPPBase[] getBases(ICPPClassType classType, IASTNode point) { - if (classType instanceof ICPPClassSpecialization) - return ((ICPPClassSpecialization) classType).getBases(point); - return classType.getBases(); - } - - public static ICPPConstructor[] getConstructors(ICPPClassType classType, IASTNode point) { - if (classType instanceof ICPPClassSpecialization) - return ((ICPPClassSpecialization) classType).getConstructors(point); - return classType.getConstructors(); - } - - public static ICPPField[] getDeclaredFields(ICPPClassType classType, IASTNode point) { - if (classType instanceof ICPPClassSpecialization) - return ((ICPPClassSpecialization) classType).getDeclaredFields(point); - return classType.getDeclaredFields(); - } - - public static ICPPMethod[] getDeclaredMethods(ICPPClassType classType, IASTNode point) { - if (classType instanceof ICPPClassSpecialization) - return ((ICPPClassSpecialization) classType).getDeclaredMethods(point); - return classType.getDeclaredMethods(); - } - - public static IBinding[] getFriends(ICPPClassType classType, IASTNode point) { - if (classType instanceof ICPPClassSpecialization) - return ((ICPPClassSpecialization) classType).getFriends(point); - return classType.getFriends(); - } - - public static ICPPClassType[] getNestedClasses(ICPPClassType classType, IASTNode point) { - if (classType instanceof ICPPClassSpecialization) - return ((ICPPClassSpecialization) classType).getNestedClasses(point); - return classType.getNestedClasses(); - } - /** * @param method * @return true if the specified method is a conversion operator @@ -676,7 +638,7 @@ public class SemanticUtil { clazz= (ICPPClassType) ((ICPPDeferredClassInstance) clazz).getSpecializedBinding(); } - for (ICPPBase cppBase : getBases(clazz, point)) { + for (ICPPBase cppBase : ClassTypeHelper.getBases(clazz, point)) { IBinding base= cppBase.getBaseClass(); if (base instanceof IType && hashSet.add(base)) { IType tbase= (IType) base; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java index ed22833493b..14d895b84ae 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Wind River Systems, Inc. and others. + * Copyright (c) 2009, 2012 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -63,6 +64,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPReferenceType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; @@ -71,9 +73,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; */ public class TemplateArgumentDeduction { /** - * Deduce arguments for a template function from the template id + the template function parameters. + * Deduce arguments for a template function from the template id and the template function + * parameters. * 14.8.2.1 - * @param point */ static ICPPTemplateArgument[] deduceForFunctionCall(ICPPFunctionTemplate template, ICPPTemplateArgument[] tmplArgs, List fnArgs, List argIsLValue, @@ -236,7 +238,7 @@ public class TemplateArgumentDeduction { ICPPTemplateInstance pInst = (ICPPTemplateInstance) pcheck; ICPPClassTemplate pTemplate= getPrimaryTemplate(pInst); if (pTemplate != null) { - ICPPClassType aInst= findBaseInstance((ICPPClassType) argcheck, pTemplate); + ICPPClassType aInst= findBaseInstance((ICPPClassType) argcheck, pTemplate, point); if (aInst != null && aInst != argcheck) { par= pcheck; arg= aInst; @@ -291,7 +293,6 @@ public class TemplateArgumentDeduction { /** * Deduce arguments for a user defined conversion template * 14.8.2.3 - * @param point */ static ICPPTemplateArgument[] deduceForConversion(ICPPFunctionTemplate template, IType conversionType, CPPTemplateParameterMap map, IASTNode point) throws DOMException { @@ -326,7 +327,6 @@ public class TemplateArgumentDeduction { /** * Deduce arguments for a function declaration * 14.8.2.6 - * @param point */ static ICPPTemplateArgument[] deduceForDeclaration(ICPPFunctionTemplate template, ICPPTemplateArgument[] args, ICPPFunctionType ftype, CPPTemplateParameterMap map, IASTNode point) throws DOMException { @@ -361,7 +361,6 @@ public class TemplateArgumentDeduction { /** * Deduces the mapping for the template parameters from the function parameters, * returns false if there is no mapping. - * @param point */ static int deduceForPartialOrdering(ICPPTemplateParameter[] tmplPars, IType[] fnPars, IType[] fnArgs, IASTNode point) { try { @@ -424,7 +423,6 @@ public class TemplateArgumentDeduction { /** * Adds the explicit arguments to the map. - * @param point */ private static boolean addExplicitArguments(final ICPPTemplateParameter[] tmplParams, ICPPTemplateArgument[] tmplArgs, CPPTemplateParameterMap map, IASTNode point) { @@ -482,13 +480,14 @@ public class TemplateArgumentDeduction { } /** - * 14.8.2.1.3 If P is a class and has the form template-id, then A can be a derived class of the deduced A. + * 14.8.2.1.3 If P is a class and has the form template-id, then A can be a derived class of + * the deduced A. */ - private static ICPPClassType findBaseInstance(ICPPClassType a, ICPPClassTemplate pTemplate) throws DOMException { - return findBaseInstance(a, pTemplate, CPPSemantics.MAX_INHERITANCE_DEPTH, new HashSet()); + private static ICPPClassType findBaseInstance(ICPPClassType a, ICPPClassTemplate pTemplate, IASTNode point) throws DOMException { + return findBaseInstance(a, pTemplate, CPPSemantics.MAX_INHERITANCE_DEPTH, new HashSet(), point); } - private static ICPPClassType findBaseInstance(ICPPClassType a, ICPPClassTemplate pTemplate, int maxdepth, HashSet handled) throws DOMException { + private static ICPPClassType findBaseInstance(ICPPClassType a, ICPPClassTemplate pTemplate, int maxdepth, HashSet handled, IASTNode point) throws DOMException { if (a instanceof ICPPTemplateInstance) { final ICPPTemplateInstance inst = (ICPPTemplateInstance) a; ICPPClassTemplate tmpl= getPrimaryTemplate(inst); @@ -496,10 +495,10 @@ public class TemplateArgumentDeduction { return a; } if (maxdepth-- > 0) { - for (ICPPBase cppBase : a.getBases()) { + for (ICPPBase cppBase : ClassTypeHelper.getBases(a, point)) { IBinding base= cppBase.getBaseClass(); if (base instanceof ICPPClassType && handled.add(base)) { - final ICPPClassType inst= findBaseInstance((ICPPClassType) base, pTemplate, maxdepth, handled); + final ICPPClassType inst= findBaseInstance((ICPPClassType) base, pTemplate, maxdepth, handled, point); if (inst != null) return inst; } @@ -547,7 +546,6 @@ public class TemplateArgumentDeduction { /** * Deduces the template parameter mapping from pairs of template arguments. - * @param point */ public static boolean fromTemplateArguments(final ICPPTemplateParameter[] pars, final ICPPTemplateArgument[] p, final ICPPTemplateArgument[] a, CPPTemplateParameterMap map, @@ -640,7 +638,6 @@ public class TemplateArgumentDeduction { /** * Deduces the template parameter mapping from one pair of template arguments. - * @param point */ private boolean fromTemplateArgument(ICPPTemplateArgument p, ICPPTemplateArgument a, IASTNode point) throws DOMException { if (p.isNonTypeValue() != a.isNonTypeValue()) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java index 5aba0d03b0f..4d82579e7bc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java @@ -15,8 +15,10 @@ package org.eclipse.cdt.internal.core.index.composite.cpp; import java.util.HashSet; import java.util.Set; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; @@ -30,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassSpecialization.RecursionResolvingBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.index.IIndexFragment; @@ -79,11 +82,11 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple specializationMap= (ObjectMap) cached; } else { final ObjectMap newMap= new ObjectMap(2); - // in any fragment explicit specializations may be defined. + // In any fragment explicit specializations may be defined. IIndexFragmentBinding[] frags= cf.findEquivalentBindings(rbinding); for (IIndexFragmentBinding fb : frags) { if (fb instanceof ICPPClassType) { - final ICPPClassType[] nested = ((ICPPClassType)fb).getNestedClasses(); + final ICPPClassType[] nested = ClassTypeHelper.getNestedClasses((ICPPClassType) fb, point); if (nested.length > 0) { for (ICPPClassType ct : nested) { if (ct instanceof ICPPClassSpecialization && @@ -129,7 +132,8 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple @Override public final ICPPBase[] getBases() { - return getBases(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getBases(null); } @Override @@ -138,12 +142,14 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple if (scope instanceof ICPPClassSpecializationScope) { return ((ICPPClassSpecializationScope) scope).getBases(point); } - return super.getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases((ICPPClassType) rbinding, point); + return wrapBases(bases); } @Override public final ICPPConstructor[] getConstructors() { - return getConstructors(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getConstructors(null); } @Override @@ -152,12 +158,25 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple if (scope instanceof ICPPClassSpecializationScope) { return ((ICPPClassSpecializationScope) scope).getConstructors(point); } - return super.getConstructors(); + ICPPConstructor[] result = ClassTypeHelper.getConstructors((ICPPClassType) rbinding, point); + return wrapBindings(result); + } + + @Override + public ICPPMethod[] getMethods() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getMethods(null); + } + + @Override + public ICPPMethod[] getMethods(IASTNode point) { + return ClassTypeHelper.getMethods(this, point); } @Override public final ICPPMethod[] getDeclaredMethods() { - return getDeclaredMethods(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getDeclaredMethods(null); } @Override @@ -166,12 +185,25 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple if (scope instanceof ICPPClassSpecializationScope) { return ((ICPPClassSpecializationScope) scope).getDeclaredMethods(point); } - return super.getDeclaredMethods(); + ICPPMethod[] result = ClassTypeHelper.getDeclaredMethods((ICPPClassType) rbinding, point); + return wrapBindings(result); + } + + @Override + public final ICPPMethod[] getAllDeclaredMethods() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getAllDeclaredMethods(null); + } + + @Override + public final ICPPMethod[] getAllDeclaredMethods(IASTNode point) { + return ClassTypeHelper.getAllDeclaredMethods(this, point); } @Override public final ICPPField[] getDeclaredFields() { - return getDeclaredFields(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getDeclaredFields(null); } @Override @@ -180,12 +212,25 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple if (scope instanceof ICPPClassSpecializationScope) { return ((ICPPClassSpecializationScope) scope).getDeclaredFields(point); } - return super.getDeclaredFields(); + ICPPField[] result = ClassTypeHelper.getDeclaredFields((ICPPClassType) rbinding, point); + return wrapBindings(result); + } + + @Override + public IField[] getFields() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getFields(null); + } + + @Override + public final IField[] getFields(IASTNode point) { + return ClassTypeHelper.getFields(this, point); } @Override public final IBinding[] getFriends() { - return getFriends(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getFriends(null); } @Override @@ -194,12 +239,14 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple if (scope instanceof ICPPClassSpecializationScope) { return ((ICPPClassSpecializationScope) scope).getFriends(point); } - return super.getFriends(); + IBinding[] result = ClassTypeHelper.getFriends((ICPPClassType) rbinding, point); + return wrapBindings(result); } @Override public final ICPPClassType[] getNestedClasses() { - return getNestedClasses(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getNestedClasses(null); } @Override @@ -208,7 +255,8 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple if (scope instanceof ICPPClassSpecializationScope) { return ((ICPPClassSpecializationScope) scope).getNestedClasses(point); } - return super.getNestedClasses(); + ICPPClassType[] result = ClassTypeHelper.getNestedClasses((ICPPClassType) rbinding, point); + return wrapBindings(result); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java index 3a1ef81a859..b00a7b572dd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; @@ -69,7 +70,8 @@ public class CompositeCPPClassSpecializationScope extends CompositeScope impleme @Override public ICPPMethod[] getImplicitMethods() { - return getImplicitMethods(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getImplicitMethods(null); } @Override @@ -104,7 +106,8 @@ public class CompositeCPPClassSpecializationScope extends CompositeScope impleme @Override public ICPPConstructor[] getConstructors() { - return getConstructors(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getConstructors(null); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassType.java index 11e2cb9b8b5..9866bac677a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Symbian Software Systems and others. + * Copyright (c) 2007, 2012 Symbian Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,9 +8,12 @@ * Contributors: * Andrew Ferguson (Symbian) - Initial implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; +import java.util.Arrays; + import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IField; @@ -42,8 +45,8 @@ class CompositeCPPClassType extends CompositeCPPBinding implements ICPPClassType } @Override - public final ICPPMethod[] getAllDeclaredMethods() { - return ClassTypeHelper.getAllDeclaredMethods(this); + public ICPPMethod[] getAllDeclaredMethods() { + return ClassTypeHelper.getAllDeclaredMethods(this, null); } private class CPPBaseDelegate implements ICPPBase { @@ -101,68 +104,48 @@ class CompositeCPPClassType extends CompositeCPPBinding implements ICPPClassType @Override public ICPPBase[] getBases() { - final ICPPBase[] preresult = ((ICPPClassType) rbinding).getBases(); - ICPPBase[] result = new ICPPBase[preresult.length]; - for (int i= 0; i < preresult.length; i++) { - result[i] = new CPPBaseDelegate(preresult[i]); - } - return result; + ICPPBase[] bases = ((ICPPClassType) rbinding).getBases(); + return wrapBases(bases); } @Override public ICPPConstructor[] getConstructors() { ICPPConstructor[] result = ((ICPPClassType) rbinding).getConstructors(); - for (int i= 0; i < result.length; i++) { - result[i] = (ICPPConstructor) cf.getCompositeBinding((IIndexFragmentBinding) result[i]); - } - return result; + return wrapBindings(result); } @Override public ICPPField[] getDeclaredFields() { ICPPField[] result = ((ICPPClassType) rbinding).getDeclaredFields(); - for (int i= 0; i < result.length; i++) { - result[i] = (ICPPField) cf.getCompositeBinding((IIndexFragmentBinding) result[i]); - } - return result; + return wrapBindings(result); } @Override public ICPPMethod[] getDeclaredMethods() { ICPPMethod[] result = ((ICPPClassType) rbinding).getDeclaredMethods(); - for (int i= 0; i < result.length; i++) { - result[i]= (ICPPMethod) cf.getCompositeBinding((IIndexFragmentBinding) result[i]); - } - return result; + return wrapBindings(result); } @Override - public final IField[] getFields() { - return ClassTypeHelper.getFields(this); + public IField[] getFields() { + return ClassTypeHelper.getFields(this, null); } @Override public IBinding[] getFriends() { IBinding[] preResult = ((ICPPClassType) rbinding).getFriends(); - IBinding[] result = new IBinding[preResult.length]; - for (int i= 0; i < preResult.length; i++) { - result[i] = cf.getCompositeBinding((IIndexFragmentBinding) preResult[i]); - } - return result; + return wrapBindings(preResult); } @Override - public final ICPPMethod[] getMethods() { - return ClassTypeHelper.getMethods(this); + public ICPPMethod[] getMethods() { + return ClassTypeHelper.getMethods(this, null); } @Override public ICPPClassType[] getNestedClasses() { ICPPClassType[] result = ((ICPPClassType) rbinding).getNestedClasses(); - for (int i= 0; i < result.length; i++) { - result[i] = (ICPPClassType) cf.getCompositeBinding((IIndexFragmentBinding) result[i]); - } - return result; + return wrapBindings(result); } @Override @@ -184,4 +167,21 @@ class CompositeCPPClassType extends CompositeCPPBinding implements ICPPClassType public boolean isAnonymous() { return ((ICPPClassType) rbinding).isAnonymous(); } + + protected ICPPBase[] wrapBases(final ICPPBase[] bases) { + ICPPBase[] result = new ICPPBase[bases.length]; + for (int i= 0; i < bases.length; i++) { + result[i] = new CPPBaseDelegate(bases[i]); + } + return result; + } + + @SuppressWarnings("unchecked") + protected T[] wrapBindings(T[] bindings) { + T[] result = Arrays.copyOf(bindings, bindings.length); + for (int i= 0; i < bindings.length; i++) { + result[i] = (T) cf.getCompositeBinding((IIndexFragmentBinding) bindings[i]); + } + return result; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java index a90da22c5ef..b9e4969e680 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java @@ -208,7 +208,8 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPBase[] getBases() { - return getBases(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getBases(null); } @Override @@ -241,7 +242,8 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPConstructor[] getConstructors() { - return getConstructors(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getConstructors(null); } @Override @@ -262,7 +264,8 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPMethod[] getDeclaredMethods() { - return getDeclaredMethods(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getDeclaredMethods(null); } @Override @@ -283,7 +286,8 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPField[] getDeclaredFields() { - return getDeclaredFields(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getDeclaredFields(null); } @Override @@ -304,7 +308,8 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPClassType[] getNestedClasses() { - return getNestedClasses(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getNestedClasses(null); } @Override @@ -325,7 +330,8 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public IBinding[] getFriends() { - return getFriends(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getFriends(null); } @Override @@ -336,17 +342,35 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPMethod[] getMethods() { - return ClassTypeHelper.getMethods(this); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getMethods(null); + } + + @Override + public ICPPMethod[] getMethods(IASTNode point) { + return ClassTypeHelper.getMethods(this, point); } @Override public ICPPMethod[] getAllDeclaredMethods() { - return ClassTypeHelper.getAllDeclaredMethods(this); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getAllDeclaredMethods(null); + } + + @Override + public ICPPMethod[] getAllDeclaredMethods(IASTNode point) { + return ClassTypeHelper.getAllDeclaredMethods(this, point); } @Override public IField[] getFields() { - return ClassTypeHelper.getFields(this); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getFields(null); + } + + @Override + public IField[] getFields(IASTNode point) { + return ClassTypeHelper.getFields(this, point); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplateSpecialization.java index ccbdb499f7b..f370b1e8fc3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplateSpecialization.java @@ -158,7 +158,7 @@ class PDOMCPPClassTemplateSpecialization extends PDOMCPPClassSpecialization @Override public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() { - IASTNode point= null; // Instantiation of dependent expression may not work. + IASTNode point= null; // Instantiation of dependent expressions may not work. ICPPClassTemplate origTemplate= (ICPPClassTemplate) getSpecializedBinding(); ICPPClassTemplatePartialSpecialization[] orig = origTemplate.getPartialSpecializations(); ICPPClassTemplatePartialSpecialization[] spec = new ICPPClassTemplatePartialSpecialization[orig.length]; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java index f79a0c1f2f1..1ebf474b9ba 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java @@ -351,17 +351,17 @@ class PDOMCPPClassType extends PDOMCPPBinding implements IPDOMCPPClassType, IPDO @Override public ICPPMethod[] getMethods() { - return ClassTypeHelper.getMethods(this); + return ClassTypeHelper.getMethods(this, null); } @Override public ICPPMethod[] getAllDeclaredMethods() { - return ClassTypeHelper.getAllDeclaredMethods(this); + return ClassTypeHelper.getAllDeclaredMethods(this, null); } @Override public IField[] getFields() { - return ClassTypeHelper.getFields(this); + return ClassTypeHelper.getFields(this, null); } @Override 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 946b8a9caac..1e15385117e 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 @@ -14,7 +14,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; @@ -68,6 +67,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.index.IIndexBinding; +import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; @@ -82,6 +82,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerToMemberType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPReferenceType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance; @@ -252,7 +253,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { PDOMBinding pdomBinding = addBinding(binding, name); if (pdomBinding instanceof PDOMCPPClassType || pdomBinding instanceof PDOMCPPClassSpecialization) { if (binding instanceof ICPPClassType && name.isDefinition()) { - addImplicitMethods(pdomBinding, (ICPPClassType) binding); + addImplicitMethods(pdomBinding, (ICPPClassType) binding, name); } } @@ -299,7 +300,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { if (pdomBinding != null) { getPDOM().putCachedResult(inputBinding, pdomBinding); if (inputBinding instanceof CPPClosureType) { - addImplicitMethods(pdomBinding, (ICPPClassType) binding); + addImplicitMethods(pdomBinding, (ICPPClassType) binding, fromName); } } } catch (DOMException e) { @@ -490,17 +491,14 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { return result; } - private void addImplicitMethods(PDOMBinding type, ICPPClassType binding) throws CoreException { + private void addImplicitMethods(PDOMBinding type, ICPPClassType binding, IASTNode point) throws CoreException { try { final long fileLocalRec= type.getLocalToFileRec(); IScope scope = binding.getCompositeScope(); if (scope instanceof ICPPClassScope) { List old= new ArrayList(); if (type instanceof ICPPClassType) { - IScope oldScope = ((ICPPClassType)type).getCompositeScope(); - if (oldScope instanceof ICPPClassScope) { - old.addAll(Arrays.asList(((ICPPClassScope) oldScope).getImplicitMethods())); - } + ArrayUtil.addAll(old, ClassTypeHelper.getImplicitMethods((ICPPClassType) type, point)); } ICPPMethod[] implicit= ((ICPPClassScope) scope).getImplicitMethods(); for (ICPPMethod method : implicit) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java index df9d4578aa9..7360c7a1ff5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java @@ -253,7 +253,7 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod { @Override public IType[] getExceptionSpecification() { if (isImplicit()) { - return ClassTypeHelper.getInheritedExceptionSpecification(this); + return ClassTypeHelper.getInheritedExceptionSpecification(this, null); } return super.getExceptionSpecification(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java index 03dfa708e9d..1de4f84d7e5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java @@ -6,16 +6,18 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Bryan Wilkinson (QNX) - Initial API and implementation - * Markus Schorn (Wind River Systems) + * Bryan Wilkinson (QNX) - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethodSpecialization; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; @@ -30,8 +32,7 @@ import org.eclipse.core.runtime.CoreException; * Specialization of a method */ class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization - implements ICPPMethod { - + implements ICPPMethodSpecialization { /** * Offset of remaining annotation information (relative to the beginning of * the record). @@ -67,7 +68,7 @@ class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization public PDOMCPPMethodSpecialization(PDOMLinkage linkage, long bindingRecord) { super(linkage, bindingRecord); } - + @Override protected int getRecordSize() { return RECORD_SIZE; @@ -135,9 +136,9 @@ class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization } @Override - public IType[] getExceptionSpecification() { + public IType[] getExceptionSpecification(IASTNode point) { if (isImplicit()) { - return ClassTypeHelper.getInheritedExceptionSpecification(this); + return ClassTypeHelper.getInheritedExceptionSpecification(this, point); } return super.getExceptionSpecification(); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java index ecf68a72717..039319a9de5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java @@ -82,7 +82,7 @@ public class CHQueries { if (calleeBinding != null) { findCalledBy1(index, calleeBinding, true, project, result); if (calleeBinding instanceof ICPPMethod) { - IBinding[] overriddenBindings= ClassTypeHelper.findOverridden((ICPPMethod) calleeBinding); + IBinding[] overriddenBindings= ClassTypeHelper.findOverridden((ICPPMethod) calleeBinding, null); for (IBinding overriddenBinding : overriddenBindings) { findCalledBy1(index, overriddenBinding, false, project, result); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OverrideIndicatorManager.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OverrideIndicatorManager.java index 6aed8cca197..117fc21ec08 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OverrideIndicatorManager.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OverrideIndicatorManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Tomasz Wesolowski and others + * Copyright (c) 2010, 2012 Tomasz Wesolowski and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Tomasz Wesolowski - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.ui.editor; @@ -218,7 +219,6 @@ public class OverrideIndicatorManager implements ICReconcilingListener { private static OverrideInfo checkForOverride(ICPPMethod testedOverride, IASTNode node) throws DOMException { IASTFileLocation location = node.getFileLocation(); - testedOverride.getClassOwner().getBases(); boolean onlyPureVirtual = true; StringBuilder sb = new StringBuilder(); @@ -227,7 +227,7 @@ public class OverrideIndicatorManager implements ICReconcilingListener { Set alreadyTestedBases = new HashSet(); - ICPPBase[] bases = testedOverride.getClassOwner().getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases(testedOverride.getClassOwner(), node); // Don't override 'self' in cyclic inheritance alreadyTestedBases.add(testedOverride.getClassOwner()); @@ -244,7 +244,6 @@ public class OverrideIndicatorManager implements ICReconcilingListener { handleBaseClass(testedClass, testedOverride, overridenMethods, shadowedMethods, alreadyTestedBases); for (ICPPMethod overriddenMethod : overridenMethods) { - if (sb.length() > 0) { sb.append(MESSAGE_SEPARATOR); } @@ -289,8 +288,8 @@ public class OverrideIndicatorManager implements ICReconcilingListener { } if (sb.length() > 0) { - OverrideInfo info = new OverrideInfo(location.getNodeOffset(), location.getNodeLength(), markerType, - sb.toString(), bindingToOpen); + OverrideInfo info = new OverrideInfo(location.getNodeOffset(), location.getNodeLength(), + markerType, sb.toString(), bindingToOpen); return info; } return null; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameMethodProcessor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameMethodProcessor.java index fa58c0f1e39..2548a03142f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameMethodProcessor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameMethodProcessor.java @@ -31,7 +31,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; - /** * Rename processor for methods. */ @@ -108,7 +107,7 @@ public class CRenameMethodProcessor extends CRenameGlobalProcessor { if (binding instanceof ICPPMethod) { ICPPMethod m= (ICPPMethod) binding; try { - IBinding[] bs= ClassTypeHelper.findOverridden(m); + IBinding[] bs= ClassTypeHelper.findOverridden(m, argument.getTranslationUnit()); bindings.addAll(Arrays.asList(bs)); bs= ClassTypeHelper.findOverriders(getIndex(), m); bindings.addAll(Arrays.asList(bs)); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchQuery.java index c534bd7ea9d..62296c39645 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchQuery.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchQuery.java @@ -357,7 +357,8 @@ public abstract class CSearchQuery implements ISearchQuery { if (binding instanceof ICPPMethod) { ICPPMethod m= (ICPPMethod) binding; - ICPPMethod[] msInBases = ClassTypeHelper.findOverridden(m); + IASTNode point = null; // Instantiation of dependent expressions may not work. + ICPPMethod[] msInBases = ClassTypeHelper.findOverridden(m, point); if (msInBases.length > 0) { if (polymorphicNames == null) { polymorphicNames= new ArrayList(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LinkedNamesFinder.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LinkedNamesFinder.java index 0bbfe23e972..3de9c43fae1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LinkedNamesFinder.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LinkedNamesFinder.java @@ -99,7 +99,7 @@ public class LinkedNamesFinder { } } else if (target instanceof ICPPMethod) { ICPPMethod method= (ICPPMethod) target; - for (ICPPMethod m : ClassTypeHelper.findOverridden(method)) { + for (ICPPMethod m : ClassTypeHelper.findOverridden(method, root)) { findBinding(m); } try { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java index e225d62efcf..1fdb266723d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java @@ -36,6 +36,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IEnumeration; @@ -78,6 +79,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBuiltinVariable; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitMethod; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitTypedef; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.AccessContext; import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory; @@ -309,7 +311,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer if (binding instanceof ICPPClassType) { handleClass((ICPPClassType) binding, astContext, cContext, baseRelevance, proposals); } else if (binding instanceof IFunction) { - handleFunction((IFunction)binding, cContext, baseRelevance, proposals); + handleFunction((IFunction) binding, cContext, baseRelevance, proposals); } else if (binding instanceof IVariable) { handleVariable((IVariable) binding, cContext, baseRelevance, proposals); } else if (!cContext.isContextInformationStyle()) { @@ -466,7 +468,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer t= unwindTypedefs(t); if (t instanceof ICPPClassType) { ICPPClassType classType= (ICPPClassType) t; - ICPPConstructor[] constructors = classType.getConstructors(); + IASTTranslationUnit ast = context.getCompletionNode().getTranslationUnit(); + ICPPConstructor[] constructors = ClassTypeHelper.getConstructors(classType, ast); for (ICPPConstructor constructor : constructors) { handleFunction(constructor, context, baseRelevance, proposals); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java index 528fd655cde..8f8bd310991 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java @@ -511,7 +511,7 @@ public class IndexUI { // Check for specializations of the owner IBinding owner = binding.getOwner(); if (owner != null) { - IASTNode point= null; // Instantiation of dependent expression may not work. + IASTNode point= null; // Instantiation of dependent expressions may not work. for (IBinding specOwner : findSpecializations(index, owner)) { if (specOwner instanceof ICPPClassSpecialization) { // Add the specialized member