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/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/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 9f663484c0d..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); } @@ -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); @@ -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 {}; @@ -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 6a650ca9ad2..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 @@ -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,13 +82,14 @@ 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; +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; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; public class AST2TemplateTests extends AST2BaseTest { @@ -107,11 +109,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 +145,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 +196,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 +228,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 +257,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 +278,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 +304,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 +339,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 +354,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 +373,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 +397,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 +413,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 +440,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 +480,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 +523,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 +540,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 +554,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 +570,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 +586,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 +606,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 +633,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 +654,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 +685,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 +714,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 +746,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 +770,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 +793,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 +823,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 +839,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 +861,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 +907,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 +951,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 +983,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 +1020,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 +1062,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 +1092,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 +1139,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 +1173,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 +1212,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 +1264,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 +1288,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); @@ -1320,7 +1322,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 +1365,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 +1394,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 +1419,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); @@ -1443,7 +1445,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 +1507,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 +1540,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 +1566,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 +1589,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 +1608,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 +1627,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 +1653,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 +1683,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 +1706,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 +1721,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 +1751,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 +1778,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 +1798,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 +1817,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 +1849,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 +1864,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 +1878,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 +1898,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); @@ -1906,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); } @@ -1921,7 +1923,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 +1949,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 +1970,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 +1985,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 +2020,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); @@ -2042,7 +2044,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 +2070,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 +2093,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 +2110,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 +2129,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 +2152,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 +2184,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 +2207,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 +2230,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 +2248,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 +2263,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 +2338,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); } @@ -2362,7 +2364,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 +2386,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 +2436,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 +2470,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 +2510,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 +2549,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 +2581,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 +2610,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); @@ -2658,7 +2660,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 +2680,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 +2703,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 +2727,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 +2746,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); } @@ -2754,7 +2756,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 +2775,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 +2789,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 +2804,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 +2817,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); @@ -2845,10 +2847,10 @@ 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(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2868,7 +2870,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 +2886,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); @@ -2910,7 +2912,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 +2929,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 +2955,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 +2971,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 +3000,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 +3031,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 +3072,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 +3084,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 +3104,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 +3137,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 +3159,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 +3179,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 +3195,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 +3214,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 +3230,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); } @@ -3254,7 +3256,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 { @@ -3273,7 +3275,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]; @@ -3293,7 +3295,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 { @@ -3301,7 +3303,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 +3350,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 +3376,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); } @@ -3399,7 +3401,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 +3421,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 +3458,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); @@ -3466,7 +3468,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 +3495,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 +3520,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 +3543,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 +3572,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 +3594,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 +3618,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 +3643,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 +3668,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 +3704,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 +3726,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 +3751,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 +3770,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 +3785,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 +3809,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 +3841,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 +3883,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 +3902,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 +3923,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 +3991,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 +4010,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 +4036,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); @@ -4164,7 +4166,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testMethodSpecialization_322988() throws Exception { final String code= getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, CPP); } @@ -4198,7 +4200,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 +4233,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 +4258,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); @@ -4323,7 +4325,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); } @@ -4364,22 +4366,22 @@ 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(); + 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])); } @@ -4393,7 +4395,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()); @@ -4404,7 +4406,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)); @@ -4422,7 +4424,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 +4453,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 +4469,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 +4534,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 +4554,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 +4577,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 +4598,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 +4619,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 +4675,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 +4724,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 +4763,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 +4801,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 +4835,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 +4875,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 +4892,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 +4919,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); @@ -4950,7 +4952,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); } @@ -4986,7 +4988,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 +5117,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 +5185,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 +5495,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()); @@ -5591,6 +5593,80 @@ 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_a() throws Exception { + parseAndCheckBindings(); + } + + // template + // struct A { + // typedef T type; + // }; + // + // template + // struct B { + // struct C { + // template + // static typename V::pointer test(typename V::pointer*); + // template + // static T* test(...); + // + // typedef typename A::type D; + // typedef decltype(test(0)) type; + // }; + // + // typedef typename C::type pointer; + // }; + // + // B::pointer a; + public void testDependentExpressions_b() throws Exception { + parseAndCheckBindings(); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); + 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); // template void f(T t) { // if (T* i = foo<0>(0)) @@ -5715,7 +5791,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); } @@ -5762,7 +5838,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(); @@ -5832,4 +5908,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.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.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..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 @@ -55,8 +55,10 @@ 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.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; /** @@ -226,10 +228,10 @@ 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(); + 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 d49b31b5520..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; @@ -56,14 +57,14 @@ 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.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]; @@ -1556,8 +1557,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); } @@ -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/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/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/core/dom/ast/cpp/ICPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassScope.java index 6938527c524..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,17 +1,16 @@ /******************************************************************************* - * 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) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; - /** * Interface for class scopes. * @@ -20,17 +19,15 @@ 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(); /** * 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/dom/ast/cpp/ICPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java index 0a9d97a11b7..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 @@ -1,17 +1,19 @@ /******************************************************************************* - * 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 * 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.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. @@ -21,7 +23,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(); @@ -37,4 +38,67 @@ 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 + */ + 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#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. + * @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#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. + * @since 5.5 + */ + ICPPClassType[] getNestedClasses(IASTNode point); } 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..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 @@ -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(); @@ -88,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/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/core/parser/IScannerInfo.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScannerInfo.java index 2ae00659169..2ae97cfd6e1 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(); @@ -41,9 +40,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/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/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/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/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/SizeofCalculator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java index 52863030731..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 @@ -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; @@ -48,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; @@ -67,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(); @@ -102,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. @@ -109,7 +140,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/Value.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java index 41c7f5bb0b2..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 @@ -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,15 @@ 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.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; import org.eclipse.cdt.internal.core.pdom.db.TypeMarshalBuffer; @@ -50,112 +45,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 +121,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 +141,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,106 +174,79 @@ 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 a 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) { + return ((ICPPTemplateParameter) binding).getParameterID(); } } return -1; } /** - * Tests whether the value directly references some template parameter. + * Tests whether the value references some template parameter. */ 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; + ICPPEvaluation eval = tval.getEvaluation(); + if (eval == null) + return false; + return eval.referencesTemplateParameter(); } /** * 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 +254,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 +270,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 +281,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,18 +342,19 @@ 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; 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) @@ -493,18 +368,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 +388,24 @@ 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(); + if (type instanceof ICPPUnknownType) + return null; + ASTTranslationUnit ast = (ASTTranslationUnit) exp.getTranslationUnit(); SizeofCalculator calculator = ast.getSizeofCalculator(); SizeAndAlignment info = calculator.sizeAndAlignment(type); if (info != null) @@ -600,338 +419,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 +553,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/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/AbstractCPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java index 560c545e08e..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 @@ -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,9 +10,11 @@ * Markus Schorn (Wind River Systems) * Bryan Wilkinson (QNX) * Andrew Ferguson (Symbian) + * Sergey Prigogin (Google) *******************************************************************************/ 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; @@ -124,19 +126,19 @@ 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(); + ICPPBase[] bases = ClassTypeHelper.getBases(specialClass.getSpecializedBinding(), point); 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(); 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 { @@ -182,15 +184,19 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat } @Override - public ICPPField[] getDeclaredFields() { - IASTNode point= null; // Instantiation of dependent expression may not work. - ICPPField[] fields= specialClass.getSpecializedBinding().getDeclaredFields(); + public ICPPField[] getDeclaredFields(IASTNode point) { + ICPPField[] fields= ClassTypeHelper.getDeclaredFields(specialClass.getSpecializedBinding(), point); return specializeMembers(fields, point); } - + @Override public ICPPMethod[] getImplicitMethods() { - IASTNode point= 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 + public ICPPMethod[] getImplicitMethods(IASTNode point) { ICPPClassScope origClassScope= (ICPPClassScope) specialClass.getSpecializedBinding().getCompositeScope(); if (origClassScope == null) { return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; @@ -208,30 +214,31 @@ 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); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getConstructors(null); } @Override - public ICPPMethod[] getDeclaredMethods() { - IASTNode point= null; // Instantiation of dependent expression may not work. - ICPPMethod[] bindings = specialClass.getSpecializedBinding().getDeclaredMethods(); + public ICPPConstructor[] getConstructors(IASTNode point) { + ICPPConstructor[] ctors= ClassTypeHelper.getConstructors(specialClass.getSpecializedBinding(), point); + return specializeMembers(ctors, point); + } + + @Override + public ICPPMethod[] getDeclaredMethods(IASTNode point) { + ICPPMethod[] bindings = ClassTypeHelper.getDeclaredMethods(specialClass.getSpecializedBinding(), point); return specializeMembers(bindings, point); } @Override - public ICPPClassType[] getNestedClasses() { - IASTNode point= null; // Instantiation of dependent expression may not work. - ICPPClassType[] bindings = specialClass.getSpecializedBinding().getNestedClasses(); + public ICPPClassType[] getNestedClasses(IASTNode point) { + ICPPClassType[] bindings = ClassTypeHelper.getNestedClasses(specialClass.getSpecializedBinding(), point); return specializeMembers(bindings, point); } @Override - public IBinding[] getFriends() { - IASTNode point= null; // Instantiation of dependent expression may not work. - IBinding[] friends = specialClass.getSpecializedBinding().getFriends(); + public IBinding[] getFriends(IASTNode point) { + 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 a07965123db..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 @@ -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 : 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/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/CPPASTFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java index 6ae3b430d93..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 @@ -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; @@ -40,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 { @@ -163,7 +167,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 +223,6 @@ public class CPPASTFunctionCallExpression extends ASTNode } } - - @Override @Deprecated public IASTExpression getParameterExpression() { @@ -269,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) { @@ -296,10 +298,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 +320,6 @@ public class CPPASTFunctionCallExpression extends ASTNode } return null; } - @Override public IType getExpressionType() { 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..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 @@ -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 = ClassTypeHelper.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/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/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/CPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java index c1e5df4ee23..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,61 +123,103 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPBase[] getBases() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + 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 public ICPPField[] getDeclaredFields() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getDeclaredFields(null); + } + + @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() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getDeclaredMethods(null); + } + + @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() { + 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) { ICPPClassSpecializationScope scope= getSpecializationScope(); if (scope == null) return ClassTypeHelper.getConstructors(this); - return scope.getConstructors(); + return scope.getConstructors(point); } @Override public IBinding[] getFriends() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getFriends(null); + } + + @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() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getNestedClasses(null); + } + + @Override + public ICPPClassType[] getNestedClasses(IASTNode point) { ICPPClassSpecializationScope scope= getSpecializationScope(); if (scope == null) return ClassTypeHelper.getNestedClasses(this); - return scope.getNestedClasses(); + return scope.getNestedClasses(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 @@ -186,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) @@ -226,7 +281,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/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/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/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/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/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/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/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/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 29f4703398b..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 @@ -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,9 +79,9 @@ 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()); + return new CPPTemplateNonTypeArgument(Value.create(0), getType()); case 1: dc= list.getClauses()[0]; if (dc instanceof IASTExpression) { @@ -96,7 +95,7 @@ public class CPPTemplateNonTypeParameter extends CPPTemplateParameter implements IValue val= Value.create(d, Value.MAX_RECURSION_DEPTH); IType t= getType(); - return new CPPTemplateArgument(val, t); + return new CPPTemplateNonTypeArgument(val, t); } @Override @@ -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/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/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/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/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/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..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,20 +1,23 @@ /******************************************************************************* - * 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; +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; 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; @@ -39,25 +42,37 @@ public interface ICPPClassSpecializationScope extends ICPPClassScope { /** * Computes the bases via the original class. */ - ICPPBase[] getBases(); + 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/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/ICPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java index 62e90c102f4..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 @@ -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,25 @@ 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); + + /** + * Determines size of the template parameter pack. + * + * @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/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/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/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 8579ae27553..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,8 +182,7 @@ class BaseClassLookup { // base-classes ICPPClassType baseClass= result.getClassType(); if (baseClass != null) { - ICPPBase[] grandBases= null; - grandBases= baseClass.getBases(); + 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/BuiltinOperators.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BuiltinOperators.java index 228047b9233..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 @@ -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; @@ -67,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 }; @@ -80,7 +84,8 @@ class BuiltinOperators { Object[] globCandidates) { fFileScope= point.getTranslationUnit().getScope(); fOperator= operator; - fUnary= args.length<2; + fPoint = point; + fUnary= args.length < 2; fGlobalCandidates= globCandidates; if (args.length > 0) { IType type= args[0].getTypeOrFunctionSet(point); @@ -95,7 +100,6 @@ class BuiltinOperators { } } - private ICPPFunction[] create() { switch (fOperator) { case ARROW: @@ -231,8 +235,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); @@ -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); @@ -424,7 +426,6 @@ class BuiltinOperators { return p1; } - // 13.6-13, 13.6.14 private void pointerArithmetic(boolean useRef, boolean isDiff) { IType[] types= getClassConversionTypes(FIRST); @@ -665,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 69460068b57..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 @@ -12,14 +12,27 @@ 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.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; 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 { @@ -27,11 +40,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. @@ -45,6 +55,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 +67,17 @@ 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) { + 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()); } - fBuffer.append(binding.getName()); } } @@ -95,49 +114,37 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } @Override - public void putByte(byte b) { - appendHexDigit(b >> 4); - appendHexDigit(b); + 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(); + 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 @@ -148,19 +155,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 @@ -183,6 +180,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(); @@ -214,6 +216,9 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } } + CPPEvaluation() { + } + @Override public char[] getSignature() { SignatureBuilder buf = new SignatureBuilder(); @@ -223,6 +228,33 @@ public abstract class CPPEvaluation implements ICPPEvaluation { CCorePlugin.log(e); return new char[] { '?' }; } - return buf.toString().toCharArray(); + 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; + } + + protected static SizeAndAlignment getSizeAndAlignment(IType type, IASTNode point) { + 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 ed466a91df0..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; @@ -244,7 +245,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 +258,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 +275,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 +307,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 +406,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 +415,7 @@ public class CPPSemantics { if (cls instanceof ICPPUnknownBinding) { binding= new CPPUnknownConstructor(cls); } else { - binding= CPPSemantics.resolveFunction(data, cls.getConstructors(), true); + binding= CPPSemantics.resolveFunction(data, ClassTypeHelper.getConstructors(cls, lookupPoint), true); } } catch (DOMException e) { return e.getProblem(); @@ -712,7 +715,7 @@ public class CPPSemantics { } if (t instanceof ICPPClassType && !(t instanceof ICPPClassTemplate)) { ICPPClassType ct= (ICPPClassType) t; - ICPPBase[] bases = ct.getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases(ct, tu); for (ICPPBase base : bases) { IBinding b = base.getBaseClass(); if (b instanceof IType) @@ -723,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); } @@ -2413,7 +2416,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 +2428,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 +2633,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 +2659,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 +2674,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 +2818,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, ClassTypeHelper.getConstructors((ICPPClassType) targetType, name), true); if (ctor instanceof ICPPConstructor) { int i= 0; for (IASTNode arg : init.getArguments()) { @@ -3086,7 +3089,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 +3125,13 @@ public class CPPSemantics { LookupData data = new LookupData(astName); data.setFunctionArguments(false, arguments); data.qualified = true; - data.foundItems = classType.getConstructors(); + data.foundItems = ClassTypeHelper.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 = ClassTypeHelper.getConstructors(classType, name); for (ICPPConstructor ctor : ctors) { if (ctor.getRequiredArgumentCount() == 0) return ctor; @@ -3342,7 +3345,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 +3655,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 acec6713497..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 @@ -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; @@ -124,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; @@ -138,6 +138,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 +154,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 +226,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 +403,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 +422,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 +435,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) @@ -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; } @@ -795,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) { @@ -862,43 +864,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 +886,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 +894,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 +915,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 +972,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 +997,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++) { @@ -1113,14 +1085,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, @@ -1287,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(); @@ -1294,11 +1273,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 @@ -1396,7 +1375,7 @@ public class CPPTemplates { int depIDCount= 0; IASTName owner= null; final IASTName[] ns= qname.getNames(); - for (int i = 0; i < ns.length - 1; i++) { + for (int i = 0; i < ns.length-1; i++) { IASTName n= ns[i]; if (n instanceof ICPPASTTemplateId) { if (depIDCount > 0 || usesTemplateParameter((ICPPASTTemplateId) n, tparnames)) { @@ -1439,17 +1418,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 +1441,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 +1450,7 @@ public class CPPTemplates { } node= innerMostTDecl; - while (node instanceof ICPPASTInternalTemplateDeclaration) { + while(node instanceof ICPPASTInternalTemplateDeclaration) { if (--nestingLevel < 0) nestingLevel= 0; tdecl= (ICPPASTInternalTemplateDeclaration) node; @@ -1501,7 +1480,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 +1500,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 +1592,7 @@ public class CPPTemplates { } private static ICPPASTInternalTemplateDeclaration getDirectlyEnclosingTemplateDeclaration( - ICPPASTInternalTemplateDeclaration tdecl) { + ICPPASTInternalTemplateDeclaration tdecl ) { final IASTNode parent= tdecl.getParent(); if (parent instanceof ICPPASTInternalTemplateDeclaration) return (ICPPASTInternalTemplateDeclaration) parent; @@ -1643,10 +1622,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(); @@ -1662,11 +1642,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 { @@ -1701,16 +1680,12 @@ public class CPPTemplates { for (int i = 0; i < args.length; i++) { IASTNode arg= args[i]; if (arg instanceof IASTTypeId) { - result[i]= new CPPTemplateArgument(CPPVisitor.createType((IASTTypeId) arg)); + result[i]= new CPPTemplateTypeArgument(CPPVisitor.createType((IASTTypeId) arg)); } else if (arg instanceof IASTExpression) { IASTExpression expr= (IASTExpression) arg; 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()); + result[i]= new CPPTemplateNonTypeArgument(value, type); } else { throw new IllegalArgumentException("Unexpected type: " + arg.getClass().getName()); //$NON-NLS-1$ } @@ -1922,7 +1897,7 @@ public class CPPTemplates { CPPTemplateParameterMap map = new CPPTemplateParameterMap(argLen); for (int i = 0; i < argLen; i++) { final ICPPTemplateParameter tpar = tpars[i]; - final CPPTemplateArgument arg = uniqueArg(tpar); + final ICPPTemplateArgument arg = uniqueArg(tpar); args[i]= arg; if (tpar.isParameterPack()) { map.put(tpar, new ICPPTemplateArgument[] {arg}); @@ -1938,12 +1913,12 @@ public class CPPTemplates { return null; } - private static CPPTemplateArgument uniqueArg(final ICPPTemplateParameter tpar) throws DOMException { - final CPPTemplateArgument arg; + private static ICPPTemplateArgument uniqueArg(final ICPPTemplateParameter tpar) throws DOMException { + final ICPPTemplateArgument arg; if (tpar instanceof ICPPTemplateNonTypeParameter) { - arg = new CPPTemplateArgument(Value.unique(), ((ICPPTemplateNonTypeParameter) tpar).getType()); + arg = new CPPTemplateNonTypeArgument(Value.unique(), ((ICPPTemplateNonTypeParameter) tpar).getType()); } else { - arg = new CPPTemplateArgument(new UniqueType(tpar.isParameterPack())); + arg = new CPPTemplateTypeArgument(new UniqueType(tpar.isParameterPack())); } return arg; } @@ -1998,7 +1973,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; @@ -2108,7 +2083,7 @@ public class CPPTemplates { final CPPTemplateParameterMap transferMap= new CPPTemplateParameterMap(tpars1Len); for (int i = 0; i < tpars1Len; i++) { final ICPPTemplateParameter param = tpars1[i]; - final CPPTemplateArgument arg = uniqueArg(param); + final ICPPTemplateArgument arg = uniqueArg(param); args[i]= arg; transferMap.put(param, arg); } @@ -2207,7 +2182,7 @@ public class CPPTemplates { pType= instantiateType(pType, map, -1, null, point); } if (argType instanceof ICPPUnknownType || argType instanceof ISemanticProblem || isNonTypeArgumentConvertible(pType, argType, point)) { - return new CPPTemplateArgument(arg.getNonTypeValue(), pType); + return new CPPTemplateNonTypeArgument(arg.getNonTypeValue(), pType); } return null; @@ -2255,9 +2230,8 @@ public class CPPTemplates { } if (!matchTemplateTemplateParameters(((ICPPTemplateTemplateParameter) pp).getTemplateParameters(), - ((ICPPTemplateTemplateParameter) ap).getTemplateParameters())) { + ((ICPPTemplateTemplateParameter) ap).getTemplateParameters()) ) return false; - } } } if (!pp.isParameterPack()) @@ -2395,7 +2369,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; @@ -2429,9 +2403,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()); } @@ -2439,7 +2413,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 f6369015283..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 @@ -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.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.dom.parser.cpp.CPPTypedef; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownTypeScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable; @@ -2029,7 +2034,7 @@ public class CPPVisitor extends ASTQueries { return new ProblemType(ISemanticProblem.TYPE_CANNOT_DEDUCE_AUTO_TYPE); } type = (IType) CPPTemplates.instantiate(initializer_list_template, - new ICPPTemplateArgument[] { new CPPTemplateArgument(type) }, initClause); + new ICPPTemplateArgument[] { new CPPTemplateTypeArgument(type) }, initClause); if (type instanceof IProblemBinding) { return new ProblemType(ISemanticProblem.TYPE_CANNOT_DEDUCE_AUTO_TYPE); } @@ -2058,7 +2063,7 @@ public class CPPVisitor extends ASTQueries { type = t; if (initClause instanceof ICPPASTInitializerList) { type = (IType) CPPTemplates.instantiate(initializer_list_template, - new ICPPTemplateArgument[] { new CPPTemplateArgument(type) }, initClause); + new ICPPTemplateArgument[] { new CPPTemplateTypeArgument(type) }, initClause); } return decorateType(type, declSpec, declarator); } @@ -2236,7 +2241,10 @@ public class CPPVisitor extends ASTQueries { } private static IType getStdType(final IASTNode node, char[] name) { - IBinding[] std= node.getTranslationUnit().getScope().find(STD); + if (node == null) + return null; + 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/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; } } 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..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 @@ -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); } /** @@ -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; @@ -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 = ClassTypeHelper.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= ClassTypeHelper.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/EvalBinary.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java index 0f119910e85..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 @@ -7,28 +7,55 @@ * * 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.IASTBinaryExpression.op_assign; +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.*; +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; -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; 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; @@ -102,7 +129,43 @@ public class EvalBinary extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + if (getOverload(point) != null) { + // TODO(sprigogin): Simulate execution of a function call. + return Value.create(this); + } + + 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 op_equals: + if (v1.equals(v2)) + return Value.create(1); + break; + case op_notequals: + if (v1.equals(v2)) + return Value.create(0); + break; + } + + Long num1 = v1.numericalValue(); + if (num1 != null) { + if (num1 == 0) { + if (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); + } + } + return Value.create(this); } @Override @@ -129,25 +192,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; @@ -215,17 +278,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); } @@ -234,7 +297,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); @@ -243,13 +306,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); @@ -273,4 +336,24 @@ 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); + } + + @Override + 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 ae2d6bd9878..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 @@ -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,16 @@ 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.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; /** @@ -74,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 @@ -110,4 +125,25 @@ 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); + } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + 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 2f75c840940..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 @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -22,11 +23,21 @@ 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.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; 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; 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 +51,6 @@ public class EvalBinding extends CPPEvaluation { private boolean fIsTypeDependent; private boolean fCheckedIsTypeDependent; - public EvalBinding(IBinding binding, IType type) { fBinding= binding; fType= type; @@ -75,20 +85,19 @@ public class EvalBinding extends CPPEvaluation { } private boolean computeIsTypeDependent() { - if (fBinding instanceof ICPPUnknownBinding) - return true; - IType t= null; - if (fBinding instanceof IEnumerator) { + if (fFixedType) { + t = fType; + } else if (fBinding instanceof IEnumerator) { t= ((IEnumerator) fBinding).getType(); } else if (fBinding instanceof ICPPTemplateNonTypeParameter) { 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; } @@ -114,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; } @@ -151,14 +160,28 @@ 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; } @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 @@ -184,4 +207,75 @@ 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 if 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 ICPPUnknownBinding) { + 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) + 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; + } + + @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 31e0f1f80fc..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 @@ -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; @@ -123,12 +126,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 @@ -140,7 +149,7 @@ public class EvalComma extends CPPEvaluation { return valueCategoryFromFunctionCall(last); } } - return fArguments[fArguments.length-1].getValueCategory(point); + return fArguments[fArguments.length - 1].getValueCategory(point); } @Override @@ -160,4 +169,41 @@ 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 = 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 == fArguments) { + args = new ICPPEvaluation[fArguments.length]; + System.arraycopy(fArguments, 0, args, 0, fArguments.length); + } + args[i] = arg; + } + } + if (args == fArguments) + 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; + } + + @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 8cae8cb319a..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 @@ -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,14 +17,16 @@ 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; 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; @@ -63,7 +66,7 @@ public class EvalCompound extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + return fDelegate.getValue(point); } @Override @@ -81,4 +84,23 @@ 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); + } + + @Override + 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 d4caae8ea52..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 @@ -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; } @@ -103,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 @@ -252,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); @@ -263,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: @@ -307,4 +323,32 @@ 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); + } + + @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; + } + + @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 c6985aed4c7..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 @@ -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,24 @@ 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); + } + + @Override + 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 38c741f9e38..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 @@ -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 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.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IFunctionType; @@ -24,8 +27,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; @@ -45,6 +50,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; } @@ -132,7 +141,8 @@ public class EvalFunctionCall extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + // TODO(sprigogin): Simulate execution of a function call if the value is not dependent. + return Value.create(this); } @Override @@ -167,6 +177,48 @@ 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 + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + 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 == fArguments) { + args = new ICPPEvaluation[fArguments.length]; + System.arraycopy(fArguments, 0, args, 0, fArguments.length); + } + args[i] = arg; + } + } + if (args == fArguments) + return this; + + if (args[0] instanceof EvalFunctionSet && getOverload(point) == null) { + // Resolve the function using the parameters of the function call. + args[0] = ((EvalFunctionSet) args[0]).resolveFunction(Arrays.copyOfRange(args, 1, args.length), point); + } + 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; + } + + @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 c2a98168cc7..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 @@ -7,20 +7,29 @@ * * 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; 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; @@ -106,7 +115,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); + } } } @@ -119,8 +131,80 @@ 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); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPTemplateArgument[] originalArguments = fFunctionSet.getTemplateArguments(); + ICPPTemplateArgument[] arguments = originalArguments; + arguments = instantiateArguments(originalArguments, tpMap, packOffset, within, point); + + IBinding originalOwner = fFunctionSet.getOwner(); + IBinding owner = originalOwner; + if (originalOwner instanceof ICPPUnknownBinding) { + 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) + 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); + } + + /** + * 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; + ICPPTemplateArgument[] templateArguments = fFunctionSet.getTemplateArguments(); + for (ICPPTemplateArgument arg : templateArguments) { + r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize(arg, tpMap)); + } + 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 366e8f6e7a2..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 @@ -7,12 +7,14 @@ * * 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 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,17 @@ 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.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; 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.Value; @@ -51,7 +58,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; @@ -60,6 +68,9 @@ public class EvalID extends CPPEvaluation { fTemplateArgs= templateArgs; } + /** + * Returns the field owner expression, or {@code null}. + */ public ICPPEvaluation getFieldOwner() { return fFieldOwner; } @@ -80,6 +91,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; } @@ -111,7 +125,17 @@ public class EvalID extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + // 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); +// +// if (nameOwner instanceof ICPPClassType) { +// ICPPEvaluation eval = resolveName((ICPPClassType) nameOwner, fTemplateArgs, point); +// if (eval != null) +// return eval.getValue(point); +// } + return Value.create(this); } @Override @@ -134,7 +158,10 @@ public class EvalID extends CPPEvaluation { buffer.putCharArray(fName); buffer.marshalBinding(fNameOwner); if (fTemplateArgs != null) { - // mstodo marshall arguments + buffer.putShort((short) fTemplateArgs.length); + for (ICPPTemplateArgument arg : fTemplateArgs) { + buffer.marshalTemplateArgument(arg); + } } } @@ -146,7 +173,11 @@ public class EvalID extends CPPEvaluation { IBinding nameOwner= buffer.unmarshalBinding(); ICPPTemplateArgument[] args= null; if ((firstByte & ITypeMarshalBuffer.FLAG3) != 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 EvalID(fieldOwner, nameOwner, name, addressOf, qualified, args); } @@ -242,4 +273,79 @@ public class EvalID extends CPPEvaluation { } return false; } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPTemplateArgument[] templateArgs = fTemplateArgs; + if (templateArgs != null) { + templateArgs = instantiateArguments(templateArgs, tpMap, packOffset, within, point); + } + + ICPPEvaluation fieldOwner = fFieldOwner; + if (fieldOwner != null) { + fieldOwner = fieldOwner.instantiate(tpMap, packOffset, within, maxdepth, point); + } + + IBinding nameOwner = fNameOwner; + if (nameOwner instanceof 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 (templateArgs == fTemplateArgs && fieldOwner == fFieldOwner && nameOwner == fNameOwner) + return this; + + ICPPEvaluation eval = resolveName((ICPPClassType) nameOwner, templateArgs, point); + if (eval != null) + return eval; + + 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(); + 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, templateArgs, null), fAddressOf); + } + 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); + for (ICPPTemplateArgument arg : fTemplateArgs) { + r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize(arg, tpMap)); + } + 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 d54b0fb9bca..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 @@ -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; @@ -71,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 @@ -94,6 +99,43 @@ 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 + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + 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 == fClauses) { + clauses = new ICPPEvaluation[fClauses.length]; + System.arraycopy(fClauses, 0, clauses, 0, fClauses.length); + } + clauses[i] = clause; + } + } + if (clauses == fClauses) + 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; + } + + @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 84c8d69ea80..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 @@ -7,14 +7,21 @@ * * 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; @@ -29,10 +36,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; @@ -245,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 @@ -301,4 +319,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 ownerType = CPPTemplates.instantiateType(fOwnerType, tpMap, packOffset, within, point); + if (ownerType == fOwnerType) + return this; + + IBinding member = fMember; + if (ownerType instanceof ICPPClassSpecialization) { + member = CPPTemplates.createSpecialization((ICPPClassSpecialization) ownerType, fMember, point); + } + return new EvalMemberAccess(ownerType, fOwnerValueCategory, member, fIsPointerDeref); + } + + @Override + 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 e2e41b728b1..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 @@ -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,9 @@ 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.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.Value; @@ -70,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 @@ -125,4 +142,42 @@ 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 = 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 == fArguments) { + 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 (args == fArguments && type == fInputType) + 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; + } + + @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 ca5bef22dfc..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 @@ -7,28 +7,48 @@ * * 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; 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; 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; +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; @@ -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: @@ -124,7 +144,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 }; @@ -185,7 +205,37 @@ public class EvalUnary extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, 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(fArgument.getTypeOrFunctionSet(point), point); + return info == null ? Value.UNKNOWN : Value.create(info.size); + } + case op_alignOf: { + SizeAndAlignment info = getSizeAndAlignment(fArgument.getTypeOrFunctionSet(point), 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) { + return Value.evaluateUnaryExpression(fOperator, num); + } + return Value.create(this); } @Override @@ -217,4 +267,23 @@ 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); + } + + @Override + 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 9caf7ec00f4..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 @@ -7,22 +7,46 @@ * * 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.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; +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.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; import org.eclipse.core.runtime.CoreException; public class EvalUnaryTypeID extends CPPEvaluation { @@ -127,7 +151,52 @@ 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: { + SizeAndAlignment info = getSizeAndAlignment(fOrigType, point); + return info == null ? Value.UNKNOWN : Value.create(info.size); + } + case op_alignof: { + SizeAndAlignment info = getSizeAndAlignment(fOrigType, point); + 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 @@ -139,7 +208,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 +216,23 @@ 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); + } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + return CPPTemplates.determinePackSize(fOrigType, 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/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 cd03ac12cc5..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 @@ -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 @@ -62,7 +62,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionType; 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.CPPTemplateArgument; +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; @@ -100,12 +101,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= ClassTypeHelper.getDeclaredMethods(clazz, point); if (decs != null) { for (ICPPMethod method : decs) { if (isConversionOperator(method)) { @@ -123,11 +124,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 +138,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 +149,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 : ClassTypeHelper.getBases(clazz, point)) { IBinding binding= base.getBaseClass(); if (binding instanceof ICPPClassType && !(binding instanceof IProblemBinding)) { ICPPClassType ct= (ICPPClassType) binding; @@ -165,7 +166,7 @@ public class SemanticUtil { return done; } - + /** * @param method * @return true if the specified method is a conversion operator @@ -511,7 +512,7 @@ public class SemanticUtil { final IType type= arg.getTypeValue(); final IType newType= getSimplifiedType(type); if (newType != type) { - return new CPPTemplateArgument(newType); + return new CPPTemplateTypeArgument(newType); } } return arg; @@ -622,11 +623,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 +638,7 @@ public class SemanticUtil { clazz= (ICPPClassType) ((ICPPDeferredClassInstance) clazz).getSpecializedBinding(); } - for (ICPPBase cppBase : clazz.getBases()) { + for (ICPPBase cppBase : ClassTypeHelper.getBases(clazz, point)) { IBinding base= cppBase.getBaseClass(); if (base instanceof IType && hashSet.add(base)) { IType tbase= (IType) base; @@ -648,7 +649,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/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 cdc2cdfa66a..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; @@ -60,8 +61,10 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; 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.CPPTemplateArgument; +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; @@ -70,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, @@ -235,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; @@ -290,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 { @@ -325,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 { @@ -360,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 { @@ -423,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) { @@ -481,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); @@ -495,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; } @@ -546,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, @@ -639,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()) @@ -723,7 +721,7 @@ public class TemplateArgumentDeduction { if (parID >= 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 +762,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 +790,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/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/index/composite/cpp/CPPCompositesFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java index 482571a9c84..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) { @@ -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 { 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> fInProgress= new ThreadLocal>(); - public CompositeCPPClassSpecialization(ICompositesFactory cf, ICPPClassType rbinding) { super(cf, rbinding); } @@ -80,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 && @@ -130,56 +132,131 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple @Override public final ICPPBase[] getBases() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + 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(); + ICPPBase[] bases = ClassTypeHelper.getBases((ICPPClassType) rbinding, point); + return wrapBases(bases); } @Override public final ICPPConstructor[] getConstructors() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + 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(); + 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() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + 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(); + 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() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + 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(); + 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() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + 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(); + IBinding[] result = ClassTypeHelper.getFriends((ICPPClassType) rbinding, point); + return wrapBindings(result); } @Override public final ICPPClassType[] getNestedClasses() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + 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(); + 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 4776ac8bdf6..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 @@ -8,11 +8,14 @@ * Contributors: * Andrew Ferguson (Symbian) - Initial implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ 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; 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; @@ -67,8 +70,14 @@ public class CompositeCPPClassSpecializationScope extends CompositeScope impleme @Override public ICPPMethod[] getImplicitMethods() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getImplicitMethods(null); + } + + @Override + public ICPPMethod[] getImplicitMethods(IASTNode point) { createDelegate(); - return fDelegate.getImplicitMethods(); + return fDelegate.getImplicitMethods(point); } @Override @@ -97,37 +106,43 @@ public class CompositeCPPClassSpecializationScope extends CompositeScope impleme @Override public ICPPConstructor[] getConstructors() { - createDelegate(); - return fDelegate.getConstructors(); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getConstructors(null); } @Override - public ICPPMethod[] getDeclaredMethods() { + public ICPPConstructor[] getConstructors(IASTNode point) { createDelegate(); - return fDelegate.getDeclaredMethods(); + return fDelegate.getConstructors(point); } @Override - public ICPPBase[] getBases() { + public ICPPMethod[] getDeclaredMethods(IASTNode point) { createDelegate(); - return fDelegate.getBases(); + return fDelegate.getDeclaredMethods(point); } @Override - public ICPPField[] getDeclaredFields() { + public ICPPBase[] getBases(IASTNode point) { createDelegate(); - return fDelegate.getDeclaredFields(); + return fDelegate.getBases(point); } @Override - public IBinding[] getFriends() { + public ICPPField[] getDeclaredFields(IASTNode point) { createDelegate(); - return fDelegate.getFriends(); + return fDelegate.getDeclaredFields(point); } @Override - public ICPPClassType[] getNestedClasses() { + public IBinding[] getFriends(IASTNode point) { createDelegate(); - return fDelegate.getNestedClasses(); + return fDelegate.getFriends(point); + } + + @Override + public ICPPClassType[] getNestedClasses(IASTNode point) { + createDelegate(); + return fDelegate.getNestedClasses(point); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplatePartialSpecializationSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplatePartialSpecializationSpecialization.java index 1418d866aa9..9570ec658cd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplatePartialSpecializationSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplatePartialSpecializationSpecialization.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.index.composite.cpp; 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..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,16 +1,19 @@ /******************************************************************************* - * 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 * 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) + * 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 { @@ -65,7 +68,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()); } } @@ -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/index/composite/cpp/TemplateInstanceUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/TemplateInstanceUtil.java index a95fb3f576e..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,14 +1,15 @@ /******************************************************************************* - * 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 * 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) + * 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,15 +26,18 @@ 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.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; /** - * 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 +53,8 @@ public class TemplateInstanceUtil { result.put(key, convert(cf, pack)); } } - } catch(DOMException de) { - CCorePlugin.log(de); + } catch (DOMException e) { + CCorePlugin.log(e); } return result; } @@ -90,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 CPPTemplateArgument(t); } return arg; } @@ -113,8 +112,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 +121,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 +142,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 +82,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> fInProgress= new ThreadLocal>(); public PDOMCPPClassSpecialization(PDOMLinkage linkage, PDOMNode parent, ICPPClassType classType, @@ -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); @@ -167,22 +167,22 @@ 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 { 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,25 +205,31 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements base.delete(); } } - - // implementation of class type + @Override public ICPPBase[] getBases() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getBases(null); + } + + @Override + public ICPPBase[] getBases(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getBases(); - } - - // this is an explicit specialization + 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 { 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); @@ -233,12 +239,18 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements } return ICPPBase.EMPTY_BASE_ARRAY; } - + @Override public ICPPConstructor[] getConstructors() { + 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) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getConstructors(); + return ((ICPPClassSpecializationScope) scope).getConstructors(point); } try { PDOMClassUtil.ConstructorCollector visitor= new PDOMClassUtil.ConstructorCollector(); @@ -252,9 +264,15 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPMethod[] getDeclaredMethods() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + 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); @@ -268,10 +286,16 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPField[] getDeclaredFields() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + 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(); PDOMCPPClassScope.acceptViaCache(this, visitor, false); @@ -281,13 +305,19 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements return ICPPField.EMPTY_CPPFIELD_ARRAY; } } - + @Override public ICPPClassType[] getNestedClasses() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + 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(); PDOMCPPClassScope.acceptViaCache(this, visitor, false); @@ -300,25 +330,49 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public IBinding[] getFriends() { - // not yet supported. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getFriends(null); + } + + @Override + public IBinding[] getFriends(IASTNode point) { + // Not yet supported. return IBinding.EMPTY_BINDING_ARRAY; } @Override - public ICPPMethod[] getMethods() { - return ClassTypeHelper.getMethods(this); + 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 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 public IField findField(String name) { return ClassTypeHelper.findField(this, name); @@ -350,7 +404,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements return CPPClassSpecialization.isSameClassSpecialization(this, (ICPPClassSpecialization) type); } - + @Override public Object clone() { try { @@ -362,13 +416,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); } @@ -376,7 +430,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/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 decd3d170cb..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 @@ -13,6 +13,10 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; +import java.util.ArrayList; +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; @@ -63,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; @@ -77,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; @@ -114,11 +120,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. */ @@ -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) { @@ -1109,5 +1107,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/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.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 836b8a637bd..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 @@ -6,10 +6,10 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Bryan Wilkinson (QNX) - Initial API and implementation - * Markus Schorn (Wind River Systems) - * Sergey Prigogin (Google) - * Andrew Ferguson (Symbian) + * Bryan Wilkinson (QNX) - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) + * Andrew Ferguson (Symbian) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -24,7 +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.CPPTemplateArgument; +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; @@ -35,9 +35,8 @@ import org.eclipse.core.runtime.CoreException; /** * Binding for template non-type parameter in the index. */ -class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMemberOwner, - ICPPTemplateNonTypeParameter, IPDOMCPPTemplateParameter { - +class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding + implements IPDOMMemberOwner, ICPPTemplateNonTypeParameter, IPDOMCPPTemplateParameter { private static final int TYPE_OFFSET= PDOMCPPBinding.RECORD_SIZE; private static final int PARAMETERID= TYPE_OFFSET + Database.TYPE_SIZE; private static final int DEFAULTVAL= PARAMETERID + Database.VALUE_SIZE; @@ -74,7 +73,7 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem 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; @@ -100,8 +99,8 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem @Override public void forceDelete(PDOMLinkage linkage) throws CoreException { getDBName().delete(); - linkage.storeType(record+TYPE_OFFSET, null); - linkage.storeValue(record+DEFAULTVAL, null); + linkage.storeType(record + TYPE_OFFSET, null); + linkage.storeValue(record + DEFAULTVAL, null); } @Override @@ -112,7 +111,7 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem @Override public short getTemplateNestingLevel() { readParamID(); - return (short)(getParameterID() >> 16); + return (short) (getParameterID() >> 16); } @Override @@ -184,18 +183,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 +207,7 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem public boolean isExternC() { return false; } + @Override public boolean isMutable() { return false; @@ -213,6 +217,7 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem public Object clone() { throw new UnsupportedOperationException(); } + /** * @deprecated */ @@ -221,5 +226,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..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 @@ -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,8 +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.CPPTemplateArgument; +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; @@ -42,32 +43,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 +94,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 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()); @@ -251,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); } @@ -296,12 +288,11 @@ 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; - } /** @@ -314,8 +305,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 +418,4 @@ public class OverrideIndicatorManager implements ICReconcilingListener { } return annotationModel; } - } 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