From f122365484945698d312a4b14e8b0b4b562f77d4 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 8 Aug 2012 17:38:17 -0700 Subject: [PATCH] Bug 299911. Added logging of methods that loose template instantiation context. --- .../AbstractClassInstantiationChecker.java | 4 +- .../checkers/NonVirtualDestructor.java | 19 +- .../core/parser/tests/ast2/AST2CPPTests.java | 22 +-- .../parser/tests/ast2/AST2TemplateTests.java | 11 +- .../tests/IndexCPPBindingResolutionBugs.java | 100 +++++----- .../tests/IndexCPPTemplateResolutionTest.java | 27 +-- .../pdom/tests/CPPClassTemplateTests.java | 9 +- .../dom/ast/cpp/ICPPClassSpecialization.java | 22 +++ .../dom/ast/cpp/ICPPMethodSpecialization.java | 30 +++ .../core/dom/parser/SizeofCalculator.java | 30 +++ .../AbstractCPPClassSpecializationScope.java | 22 ++- .../CPPASTConstructorChainInitializer.java | 2 +- .../cpp/CPPASTFunctionCallExpression.java | 3 +- .../dom/parser/cpp/CPPASTQualifiedName.java | 2 +- .../parser/cpp/CPPClassSpecialization.java | 43 ++++- .../core/dom/parser/cpp/CPPClassTemplate.java | 6 +- .../cpp/CPPClassTemplateSpecialization.java | 2 +- .../core/dom/parser/cpp/CPPClassType.java | 6 +- .../dom/parser/cpp/CPPImplicitMethod.java | 2 +- .../parser/cpp/CPPMethodSpecialization.java | 30 +-- .../core/dom/parser/cpp/ClassTypeHelper.java | 180 +++++++++++------- .../parser/cpp/semantics/AccessContext.java | 2 +- .../parser/cpp/semantics/BaseClassLookup.java | 3 +- .../parser/cpp/semantics/CPPEvaluation.java | 7 +- .../parser/cpp/semantics/CPPSemantics.java | 13 +- .../dom/parser/cpp/semantics/CPPVisitor.java | 2 + .../dom/parser/cpp/semantics/Conversions.java | 6 +- .../parser/cpp/semantics/SemanticUtil.java | 46 +---- .../semantics/TemplateArgumentDeduction.java | 29 ++- .../cpp/CompositeCPPClassSpecialization.java | 76 ++++++-- .../CompositeCPPClassSpecializationScope.java | 7 +- .../composite/cpp/CompositeCPPClassType.java | 68 +++---- .../dom/cpp/PDOMCPPClassSpecialization.java | 42 +++- .../PDOMCPPClassTemplateSpecialization.java | 2 +- .../core/pdom/dom/cpp/PDOMCPPClassType.java | 6 +- .../core/pdom/dom/cpp/PDOMCPPLinkage.java | 14 +- .../core/pdom/dom/cpp/PDOMCPPMethod.java | 2 +- .../dom/cpp/PDOMCPPMethodSpecialization.java | 15 +- .../internal/ui/callhierarchy/CHQueries.java | 2 +- .../ui/editor/OverrideIndicatorManager.java | 11 +- .../rename/CRenameMethodProcessor.java | 3 +- .../cdt/internal/ui/search/CSearchQuery.java | 3 +- .../internal/ui/search/LinkedNamesFinder.java | 2 +- .../DOMCompletionProposalComputer.java | 7 +- .../cdt/internal/ui/viewsupport/IndexUI.java | 2 +- 45 files changed, 577 insertions(+), 365 deletions(-) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethodSpecialization.java diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AbstractClassInstantiationChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AbstractClassInstantiationChecker.java index 0461da5b940..4e68e5b7360 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AbstractClassInstantiationChecker.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AbstractClassInstantiationChecker.java @@ -188,7 +188,7 @@ public class AbstractClassInstantiationChecker extends AbstractIndexAstChecker { * Checks whether specified type (class or typedef to the class) is an abstract class. * If it is, reports violations on each pure virtual method */ - private void reportProblemsIfAbstract(IType typeToCheck, IASTNode problemNode ) { + private void reportProblemsIfAbstract(IType typeToCheck, IASTNode problemNode) { IType unwindedType = CxxAstUtils.unwindTypedef(typeToCheck); if (!(unwindedType instanceof ICPPClassType) || unwindedType instanceof IProblemBinding) { return; @@ -196,7 +196,7 @@ public class AbstractClassInstantiationChecker extends AbstractIndexAstChecker { ICPPClassType classType = (ICPPClassType) unwindedType; ICPPMethod[] pureVirtualMethods = pureVirtualMethodsCache.get(classType); if (pureVirtualMethods == null) { - pureVirtualMethods = ClassTypeHelper.getPureVirtualMethods(classType); + pureVirtualMethods = ClassTypeHelper.getPureVirtualMethods(classType, problemNode); pureVirtualMethodsCache.put(classType, pureVirtualMethods); } diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java index db7235a7307..bb780c1912f 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java @@ -27,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; /** @@ -46,8 +47,8 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker { ast.accept(new OnEachClass()); } - private static ICPPMethod getDestructor(ICPPClassType classType) { - for (ICPPMethod method : classType.getDeclaredMethods()) { + private static ICPPMethod getDestructor(ICPPClassType classType, IASTNode point) { + for (ICPPMethod method : ClassTypeHelper.getDeclaredMethods(classType, point)) { if (method.isDestructor()) { return method; } @@ -55,18 +56,18 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker { return null; } - private static boolean hasVirtualDestructor(ICPPClassType classType) { + private static boolean hasVirtualDestructor(ICPPClassType classType, IASTNode point) { checkedClassTypes.add(classType); - ICPPMethod destructor = getDestructor(classType); + ICPPMethod destructor = getDestructor(classType, point); if (destructor != null && destructor.isVirtual()) { return true; } - ICPPBase[] bases = classType.getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases(classType, point); for (ICPPBase base : bases) { IBinding baseClass = base.getBaseClass(); if (baseClass instanceof ICPPClassType) { ICPPClassType cppClassType = (ICPPClassType) baseClass; - if (!checkedClassTypes.contains(cppClassType) && hasVirtualDestructor(cppClassType)) { + if (!checkedClassTypes.contains(cppClassType) && hasVirtualDestructor(cppClassType, point)) { return true; } } @@ -89,13 +90,13 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker { return PROCESS_SKIP; } ICPPClassType classType = (ICPPClassType) binding; - boolean hasVirtualDestructor = hasVirtualDestructor(classType); + boolean hasVirtualDestructor = hasVirtualDestructor(classType, className); checkedClassTypes.clear(); if (hasVirtualDestructor) { return PROCESS_SKIP; } ICPPMethod virtualMethod = null; - for (ICPPMethod method : classType.getAllDeclaredMethods()) { + for (ICPPMethod method : ClassTypeHelper.getAllDeclaredMethods(classType, className)) { if (!method.isDestructor() && method.isVirtual()) { virtualMethod = method; } @@ -103,7 +104,7 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker { if (virtualMethod == null) { return PROCESS_SKIP; } - ICPPMethod destructor = getDestructor(classType); + ICPPMethod destructor = getDestructor(classType, className); if (destructor != null && destructor.getVisibility() != ICPPASTVisibilityLabel.v_public && classType.getFriends().length == 0) { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index f5ff218fd0d..0c40d13cc63 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -6252,20 +6252,20 @@ public class AST2CPPTests extends AST2BaseTest { assertFalse(ClassTypeHelper.isOverrider(m5, m2)); assertTrue(ClassTypeHelper.isOverrider(m4, m2)); - ICPPMethod[] ors= ClassTypeHelper.findOverridden(m0); + ICPPMethod[] ors= ClassTypeHelper.findOverridden(m0, null); assertEquals(0, ors.length); - ors= ClassTypeHelper.findOverridden(m1); + ors= ClassTypeHelper.findOverridden(m1, null); assertEquals(0, ors.length); - ors= ClassTypeHelper.findOverridden(m2); + ors= ClassTypeHelper.findOverridden(m2, null); assertEquals(1, ors.length); assertSame(ors[0], m1); - ors= ClassTypeHelper.findOverridden(m3); + ors= ClassTypeHelper.findOverridden(m3, null); assertEquals(0, ors.length); - ors= ClassTypeHelper.findOverridden(m4); + ors= ClassTypeHelper.findOverridden(m4, null); assertEquals(2, ors.length); assertSame(ors[0], m2); assertSame(ors[1], m1); - ors= ClassTypeHelper.findOverridden(m5); + ors= ClassTypeHelper.findOverridden(m5, null); assertEquals(1, ors.length); assertSame(ors[0], m1); } @@ -8732,14 +8732,14 @@ public class AST2CPPTests extends AST2BaseTest { assertFalse(ClassTypeHelper.isOverrider(m3, m0)); assertFalse(ClassTypeHelper.isOverrider(m3, m1)); - ICPPMethod[] ors= ClassTypeHelper.findOverridden(m0); + ICPPMethod[] ors= ClassTypeHelper.findOverridden(m0, null); assertEquals(0, ors.length); - ors= ClassTypeHelper.findOverridden(m1); + ors= ClassTypeHelper.findOverridden(m1, null); assertEquals(0, ors.length); - ors= ClassTypeHelper.findOverridden(m2); + ors= ClassTypeHelper.findOverridden(m2, null); assertEquals(1, ors.length); assertSame(ors[0], m0); - ors= ClassTypeHelper.findOverridden(m3); + ors= ClassTypeHelper.findOverridden(m3, null); assertEquals(0, ors.length); } @@ -9546,7 +9546,7 @@ public class AST2CPPTests extends AST2BaseTest { public void testRecursiveClassInheritance_Bug357256() throws Exception { BindingAssertionHelper bh= getAssertionHelper(); ICPPClassType c= bh.assertNonProblem("A", 1); - assertEquals(0, ClassTypeHelper.getPureVirtualMethods(c).length); + assertEquals(0, ClassTypeHelper.getPureVirtualMethods(c, null).length); } // template struct CT1 {}; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 9ae7649f3ad..7a3d4cc0270 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -85,6 +85,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; @@ -1907,7 +1908,7 @@ public class AST2TemplateTests extends AST2BaseTest { ICPPClassType B = (ICPPClassType) col.getName(3).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(6).resolveBinding(); - ICPPBase[] bases = A.getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases(A, tu); assertEquals(bases.length, 1); assertSame(bases[0].getBaseClass(), B); } @@ -4368,19 +4369,19 @@ public class AST2TemplateTests extends AST2BaseTest { BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPClassType type= bh.assertNonProblem("X", 7); - ICPPMethod[] ms= type.getMethods(); + ICPPMethod[] ms= ClassTypeHelper.getMethods(type, null); int i= ms[0].getName().equals("f") ? 0 : 1; ICPPMethod m= ms[i]; assertEquals("int &", ASTTypeUtil.getType(m.getType().getParameterTypes()[0])); - m= ms[1-i]; + m= ms[1 - i]; assertEquals("int &", ASTTypeUtil.getType(m.getType().getParameterTypes()[0])); type= bh.assertNonProblem("X", 14); - ms= type.getMethods(); + ms= ClassTypeHelper.getMethods(type, null); i= ms[0].getName().equals("f") ? 0 : 1; m= ms[i]; assertEquals("const int &", ASTTypeUtil.getType(m.getType().getParameterTypes()[0])); - m= ms[1-i]; + m= ms[1 - i]; assertEquals("const int &&", ASTTypeUtil.getType(m.getType().getParameterTypes()[0])); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java index f5b63b5bc7a..05fc01240ba 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java @@ -56,7 +56,9 @@ import org.eclipse.cdt.core.index.IIndexMacro; import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; import org.eclipse.core.runtime.CoreException; /** @@ -229,7 +231,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas ICPPSpecialization inst= ct.getInstance(new ICPPTemplateArgument[]{new CPPTemplateTypeArgument((IType)b0)}); assertInstance(inst, ICPPClassType.class); ICPPClassType c2t= (ICPPClassType) inst; - ICPPBase[] bases= c2t.getBases(); + ICPPBase[] bases= ClassTypeHelper.getBases(c2t, null); assertEquals(1, bases.length); assertInstance(bases[0].getBaseClass(), ICPPClassType.class); } @@ -998,74 +1000,74 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // class template instance ct= getBindingFromASTName("CT", 7); assertInstance(ct, ICPPTemplateInstance.class); - assertBindings(new String[] {"B"}, ct.getBases()); - assertBindings(new String[] {"n", "m", "B", "CT"}, ct.getAllDeclaredMethods()); - assertBindings(new String[] {"CT", "CT"}, ct.getConstructors()); - assertBindings(new String[] {"g"}, ct.getDeclaredFields()); - assertBindings(new String[] {"n", "CT"}, ct.getDeclaredMethods()); - assertBindings(new String[] {"f", "g"}, ct.getFields()); - assertBindings(new String[] {"m", "n", "CT", "CT", "~CT", "B", "B", "~B", "operator =", "operator ="}, ct.getMethods()); - assertBindings(new String[] {"O"}, ct.getNestedClasses()); + assertBindings(new String[] {"B"}, ClassTypeHelper.getBases(ct, null)); + assertBindings(new String[] {"n", "m", "B", "CT"}, ClassTypeHelper.getAllDeclaredMethods(ct, null)); + assertBindings(new String[] {"CT", "CT"}, ClassTypeHelper.getConstructors(ct, null)); + assertBindings(new String[] {"g"}, ClassTypeHelper.getDeclaredFields(ct, null)); + assertBindings(new String[] {"n", "CT"}, ClassTypeHelper.getDeclaredMethods(ct, null)); + assertBindings(new String[] {"f", "g"}, ClassTypeHelper.getFields(ct, null)); + assertBindings(new String[] {"m", "n", "CT", "CT", "~CT", "B", "B", "~B", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null)); + assertBindings(new String[] {"O"}, ClassTypeHelper.getNestedClasses(ct, null)); // explicit class template instance ct= getBindingFromASTName("CT", 8); assertInstance(ct, ICPPTemplateInstance.class); - assertBindings(new String[] {"A"}, ct.getBases()); - assertBindings(new String[] {"o", "l", "A", "CT", "CT"}, ct.getAllDeclaredMethods()); - assertBindings(new String[] {"CT", "CT", "CT"}, ct.getConstructors()); - assertBindings(new String[] {"h"}, ct.getDeclaredFields()); - assertBindings(new String[] {"o", "CT", "CT"}, ct.getDeclaredMethods()); - assertBindings(new String[] {"e", "h"}, ct.getFields()); - assertBindings(new String[] {"l", "o", "CT", "CT", "CT", "~CT", "A", "A", "~A", "operator =", "operator ="}, ct.getMethods()); - assertBindings(new String[] {"P"}, ct.getNestedClasses()); + assertBindings(new String[] {"A"}, ClassTypeHelper.getBases(ct, null)); + assertBindings(new String[] {"o", "l", "A", "CT", "CT"}, ClassTypeHelper.getAllDeclaredMethods(ct, null)); + assertBindings(new String[] {"CT", "CT", "CT"}, ClassTypeHelper.getConstructors(ct, null)); + assertBindings(new String[] {"h"}, ClassTypeHelper.getDeclaredFields(ct, null)); + assertBindings(new String[] {"o", "CT", "CT"}, ClassTypeHelper.getDeclaredMethods(ct, null)); + assertBindings(new String[] {"e", "h"}, ClassTypeHelper.getFields(ct, null)); + assertBindings(new String[] {"l", "o", "CT", "CT", "CT", "~CT", "A", "A", "~A", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null)); + assertBindings(new String[] {"P"}, ClassTypeHelper.getNestedClasses(ct, null)); // class specialization ct= getBindingFromASTName("C spec", 1); assertInstance(ct, ICPPClassSpecialization.class); - assertBindings(new String[] {"B"}, ct.getBases()); - assertBindings(new String[] {"n", "m", "B", "C"}, ct.getAllDeclaredMethods()); - assertBindings(new String[] {"C", "C"}, ct.getConstructors()); - assertBindings(new String[] {"g"}, ct.getDeclaredFields()); - assertBindings(new String[] {"n", "C"}, ct.getDeclaredMethods()); - assertBindings(new String[] {"f", "g"}, ct.getFields()); - assertBindings(new String[] {"m", "n", "C", "C", "~C", "B", "B", "~B", "operator =", "operator ="}, ct.getMethods()); - assertBindings(new String[] {"O"}, ct.getNestedClasses()); + assertBindings(new String[] {"B"}, ClassTypeHelper.getBases(ct, null)); + assertBindings(new String[] {"n", "m", "B", "C"}, ClassTypeHelper.getAllDeclaredMethods(ct, null)); + assertBindings(new String[] {"C", "C"}, ClassTypeHelper.getConstructors(ct, null)); + assertBindings(new String[] {"g"}, ClassTypeHelper.getDeclaredFields(ct, null)); + assertBindings(new String[] {"n", "C"}, ClassTypeHelper.getDeclaredMethods(ct, null)); + assertBindings(new String[] {"f", "g"}, ClassTypeHelper.getFields(ct, null)); + assertBindings(new String[] {"m", "n", "C", "C", "~C", "B", "B", "~B", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null)); + assertBindings(new String[] {"O"}, ClassTypeHelper.getNestedClasses(ct, null)); // class template specialization ct= getBindingFromASTName("CT spect", 2); assertInstance(ct, ICPPClassTemplate.class, ICPPClassSpecialization.class); - assertBindings(new String[] {"B"}, ct.getBases()); - assertBindings(new String[] {"n", "m", "B", "CT"}, ct.getAllDeclaredMethods()); - assertBindings(new String[] {"CT", "CT"}, ct.getConstructors()); - assertBindings(new String[] {"g"}, ct.getDeclaredFields()); - assertBindings(new String[] {"n", "CT"}, ct.getDeclaredMethods()); - assertBindings(new String[] {"f", "g"}, ct.getFields()); - assertBindings(new String[] {"m", "n", "CT", "CT", "~CT", "B", "B", "~B", "operator =", "operator ="}, ct.getMethods()); - assertBindings(new String[] {"O"}, ct.getNestedClasses()); + assertBindings(new String[] {"B"}, ClassTypeHelper.getBases(ct, null)); + assertBindings(new String[] {"n", "m", "B", "CT"}, ClassTypeHelper.getAllDeclaredMethods(ct, null)); + assertBindings(new String[] {"CT", "CT"}, ClassTypeHelper.getConstructors(ct, null)); + assertBindings(new String[] {"g"}, ClassTypeHelper.getDeclaredFields(ct, null)); + assertBindings(new String[] {"n", "CT"}, ClassTypeHelper.getDeclaredMethods(ct, null)); + assertBindings(new String[] {"f", "g"}, ClassTypeHelper.getFields(ct, null)); + assertBindings(new String[] {"m", "n", "CT", "CT", "~CT", "B", "B", "~B", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null)); + assertBindings(new String[] {"O"}, ClassTypeHelper.getNestedClasses(ct, null)); // explicit class specialization ct= getBindingFromASTName("C espec", 1); assertInstance(ct, ICPPClassSpecialization.class); - assertBindings(new String[] {"A"}, ct.getBases()); - assertBindings(new String[] {"o", "l", "A", "C", "C"}, ct.getAllDeclaredMethods()); - assertBindings(new String[] {"C", "C", "C"}, ct.getConstructors()); - assertBindings(new String[] {"h"}, ct.getDeclaredFields()); - assertBindings(new String[] {"o", "C", "C"}, ct.getDeclaredMethods()); - assertBindings(new String[] {"e", "h"}, ct.getFields()); - assertBindings(new String[] {"l", "o", "C", "C", "C", "~C", "A", "A", "~A", "operator =", "operator ="}, ct.getMethods()); - assertBindings(new String[] {"P"}, ct.getNestedClasses()); + assertBindings(new String[] {"A"}, ClassTypeHelper.getBases(ct, null)); + assertBindings(new String[] {"o", "l", "A", "C", "C"}, ClassTypeHelper.getAllDeclaredMethods(ct, null)); + assertBindings(new String[] {"C", "C", "C"}, ClassTypeHelper.getConstructors(ct, null)); + assertBindings(new String[] {"h"}, ClassTypeHelper.getDeclaredFields(ct, null)); + assertBindings(new String[] {"o", "C", "C"}, ClassTypeHelper.getDeclaredMethods(ct, null)); + assertBindings(new String[] {"e", "h"}, ClassTypeHelper.getFields(ct, null)); + assertBindings(new String[] {"l", "o", "C", "C", "C", "~C", "A", "A", "~A", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null)); + assertBindings(new String[] {"P"}, ClassTypeHelper.getNestedClasses(ct, null)); // explicit class template specialization ct= getBindingFromASTName("CT espect", 7); assertInstance(ct, ICPPTemplateInstance.class); - assertBindings(new String[] {"A"}, ct.getBases()); - assertBindings(new String[] {"o", "l", "A", "CT", "CT"}, ct.getAllDeclaredMethods()); - assertBindings(new String[] {"CT", "CT", "CT"}, ct.getConstructors()); - assertBindings(new String[] {"h"}, ct.getDeclaredFields()); - assertBindings(new String[] {"o", "CT", "CT"}, ct.getDeclaredMethods()); - assertBindings(new String[] {"e", "h"}, ct.getFields()); - assertBindings(new String[] {"l", "o", "CT", "CT", "CT", "~CT", "A", "A", "~A", "operator =", "operator ="}, ct.getMethods()); - assertBindings(new String[] {"P"}, ct.getNestedClasses()); + assertBindings(new String[] {"A"}, ClassTypeHelper.getBases(ct, null)); + assertBindings(new String[] {"o", "l", "A", "CT", "CT"}, ClassTypeHelper.getAllDeclaredMethods(ct, null)); + assertBindings(new String[] {"CT", "CT", "CT"}, ClassTypeHelper.getConstructors(ct, null)); + assertBindings(new String[] {"h"}, ClassTypeHelper.getDeclaredFields(ct, null)); + assertBindings(new String[] {"o", "CT", "CT"}, ClassTypeHelper.getDeclaredMethods(ct, null)); + assertBindings(new String[] {"e", "h"}, ClassTypeHelper.getFields(ct, null)); + assertBindings(new String[] {"l", "o", "CT", "CT", "CT", "~CT", "A", "A", "~A", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null)); + assertBindings(new String[] {"P"}, ClassTypeHelper.getNestedClasses(ct, null)); } // void func(const int* x) {} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java index 303976fb74f..da5652cb9c5 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java @@ -10,6 +10,7 @@ * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.index.tests; + import java.util.ArrayList; import java.util.List; @@ -57,13 +58,13 @@ import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.core.runtime.CoreException; - /** * Tests for exercising resolution of template bindings against IIndex */ @@ -629,23 +630,23 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertInstance(b2, ICPPClassType.class); assertInstance(b2, ICPPTemplateInstance.class); ICPPClassType ct2= (ICPPClassType) b2; - ICPPBase[] bss2= ct2.getBases(); + ICPPBase[] bss2= ClassTypeHelper.getBases(ct2, null); assertEquals(1, bss2.length); assertInstance(bss2[0].getBaseClass(), ICPPClassType.class); ICPPClassType ct2b= (ICPPClassType) bss2[0].getBaseClass(); assertInstance(ct2b, ICPPTemplateInstance.class); - + IBinding b0= getBindingFromASTName("B", 6); assertInstance(b0, ICPPClassType.class); ICPPClassType ct= (ICPPClassType) b0; - ICPPBase[] bss= ct.getBases(); + ICPPBase[] bss= ClassTypeHelper.getBases(ct, null); assertEquals(1, bss.length); assertInstance(bss[0].getBaseClass(), ICPPClassType.class); - + IBinding b1= getBindingFromASTName("B", 7); assertInstance(b1, ICPPClassType.class); ICPPClassType ct1= (ICPPClassType) b1; - ICPPBase[] bss1= ct1.getBases(); + ICPPBase[] bss1= ClassTypeHelper.getBases(ct1, null); assertEquals(1, bss1.length); assertInstance(bss1[0].getBaseClass(), ICPPClassType.class); } @@ -672,13 +673,13 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa IBinding b0= getBindingFromASTName("A ab", 4); assertInstance(b0, ICPPClassType.class); assertInstance(b0, ICPPSpecialization.class); - + ICPPClassType ct= (ICPPClassType) b0; - ICPPMethod[] dms= ct.getDeclaredMethods(); + ICPPMethod[] dms= ClassTypeHelper.getDeclaredMethods(ct, null); assertEquals(2, dms.length); // if the specialization was used, we have 2 fields. - ICPPField[] fs= ct.getDeclaredFields(); + ICPPField[] fs= ClassTypeHelper.getDeclaredFields(ct, null); assertEquals(2, fs.length); ICPPMethod foo= dms[0].getName().equals("foo") ? dms[0] : dms[1]; @@ -1574,7 +1575,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertInstance(m, ICPPSpecialization.class); ICPPClassType ct= m.getClassOwner(); assertInstance(ct, ICPPTemplateInstance.class); - ICPPMethod[] ms= ct.getDeclaredMethods(); + ICPPMethod[] ms= ClassTypeHelper.getDeclaredMethods(ct, null); assertEquals(1, ms.length); assertEquals(m, ms[0]); } @@ -1849,16 +1850,16 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa methods= ct.getMethods(); assertEquals(14, methods.length); - ICPPBase[] bases = ct.getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases(ct, null); assertEquals(1, bases.length); IField field = ct.findField("bfield"); assertNotNull(field); - IField[] fields = ct.getFields(); + IField[] fields = ClassTypeHelper.getFields(ct, null); assertEquals(2, fields.length); - IBinding[] friends = ct.getFriends(); + IBinding[] friends = ClassTypeHelper.getFriends(ct, null); assertEquals(0, friends.length); // not yet supported } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPClassTemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPClassTemplateTests.java index 808169ddf87..e06d3cb350b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPClassTemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPClassTemplateTests.java @@ -18,6 +18,7 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IType; @@ -34,6 +35,7 @@ import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.internal.core.CCoreInternals; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; @@ -237,9 +239,10 @@ public class CPPClassTemplateTests extends PDOMTestBase { ICPPVariable var= (ICPPVariable) bs[0]; assertInstance(var.getType(), ICPPClassType.class); ICPPClassType ct= (ICPPClassType) var.getType(); - assertEquals(1, ct.getFields().length); - assertInstance(ct.getFields()[0].getType(), IPointerType.class); - IPointerType pt= (IPointerType) ct.getFields()[0].getType(); + IField[] fields = ClassTypeHelper.getFields(ct, null); + assertEquals(1, fields.length); + assertInstance(fields[0].getType(), IPointerType.class); + IPointerType pt= (IPointerType) fields[0].getType(); assertInstance(pt.getType(), IFunctionType.class); IFunctionType ft= (IFunctionType) pt.getType(); assertInstance(ft.getReturnType(), ICPPClassType.class); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java index 229697cb7d8..5bef68a2aec 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.core.dom.ast.cpp; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IField; /** * Specializations of all sorts of class types. @@ -59,6 +60,20 @@ public interface ICPPClassSpecialization extends ICPPSpecialization, ICPPClassTy */ ICPPField[] getDeclaredFields(IASTNode point); + /** + * Similar to {@link ICPPClassType#getMethods()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + ICPPMethod[] getMethods(IASTNode point); + + /** + * Similar to {@link ICPPClassType#getAllDeclaredMethods()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + ICPPMethod[] getAllDeclaredMethods(IASTNode point); + /** * Similar to {@link ICPPClassType#getDeclaredMethods()} but a accepts a starting point * for template instantiation. @@ -73,6 +88,13 @@ public interface ICPPClassSpecialization extends ICPPSpecialization, ICPPClassTy */ IBinding[] getFriends(IASTNode point); + /** + * Similar to {@link ICPPClassType#getFriends()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + IField[] getFields(IASTNode point); + /** * Similar to {@link ICPPClassType#getNestedClasses()} but a accepts a starting point * for template instantiation. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethodSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethodSpecialization.java new file mode 100644 index 00000000000..1f2a1ed41cc --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethodSpecialization.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2012 Google, Inc and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.dom.ast.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IType; + +/** + * Specialization of a method. + * @since 5.5 + * + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface ICPPMethodSpecialization extends ICPPSpecialization, ICPPMethod { + /** + * Similar to {@link ICPPFunction#getExceptionSpecification()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + IType[] getExceptionSpecification(IASTNode point); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java index aa3ed3d9321..625ec0c2446 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java @@ -49,6 +49,8 @@ public class SizeofCalculator { } } + private static final SizeofCalculator defaultInstance = new SizeofCalculator(); + private static final SizeAndAlignment SIZE_1 = new SizeAndAlignment(1, 1); public final SizeAndAlignment size_2; @@ -68,6 +70,15 @@ public class SizeofCalculator { public final SizeAndAlignment sizeof_long_double; public final SizeAndAlignment sizeof_complex_long_double; + /** + * Returns the default instance of sizeof calculator. The default instance is not aware + * of the parser configuration and can only calculate sizes that are the same across all + * C/C++ implementations. + */ + public static SizeofCalculator getDefault() { + return defaultInstance; + } + public SizeofCalculator(IASTTranslationUnit ast) { int maxAlignment = 32; Map sizeofMacros = new HashMap(); @@ -103,6 +114,25 @@ public class SizeofCalculator { sizeof_complex_long_double = getSizeOfPair(sizeof_long_double); } + private SizeofCalculator() { + size_2 = new SizeAndAlignment(2, 2); + size_4 = new SizeAndAlignment(4, 4); + size_8 = new SizeAndAlignment(8, 8); + sizeof_pointer = null; + sizeof_int = null; + sizeof_long = null; + sizeof_long_long = null; + sizeof_short = null; + sizeof_bool = null; + sizeof_wchar_t = null; + sizeof_float = null; + sizeof_complex_float = null; + sizeof_double = null; + sizeof_complex_double = null; + sizeof_long_double = null; + sizeof_complex_long_double = null; + } + /** * Calculates size and alignment for the given type. * @param type the type to get size and alignment for. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java index 0c02d4274c4..5b21be4b3a1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java @@ -14,6 +14,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.EScopeKind; @@ -128,7 +129,7 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat public ICPPBase[] getBases(IASTNode point) { if (fBases == null) { ICPPBase[] result = null; - ICPPBase[] bases = specialClass.getSpecializedBinding().getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases(specialClass.getSpecializedBinding(), point); if (bases.length == 0) { fBases= bases; } else { @@ -136,7 +137,8 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat for (ICPPBase base : bases) { IBinding origClass = base.getBaseClass(); if (origClass instanceof ICPPTemplateParameter && ((ICPPTemplateParameter) origClass).isParameterPack()) { - IType[] specClasses= CPPTemplates.instantiateTypes(new IType[]{new CPPParameterPackType((IType) origClass)}, tpmap, -1, specialClass, point); + IType[] specClasses= CPPTemplates.instantiateTypes(new IType[] { new CPPParameterPackType((IType) origClass) }, + tpmap, -1, specialClass, point); if (specClasses.length == 1 && specClasses[0] instanceof ICPPParameterPackType) { result= ArrayUtil.append(ICPPBase.class, result, base); } else { @@ -183,13 +185,14 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat @Override public ICPPField[] getDeclaredFields(IASTNode point) { - ICPPField[] fields= specialClass.getSpecializedBinding().getDeclaredFields(); + ICPPField[] fields= ClassTypeHelper.getDeclaredFields(specialClass.getSpecializedBinding(), point); return specializeMembers(fields, point); } @Override public ICPPMethod[] getImplicitMethods() { - return getImplicitMethods(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getImplicitMethods(null); } @Override @@ -211,30 +214,31 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat @Override public ICPPConstructor[] getConstructors() { - return getConstructors(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getConstructors(null); } @Override public ICPPConstructor[] getConstructors(IASTNode point) { - ICPPConstructor[] ctors= specialClass.getSpecializedBinding().getConstructors(); + ICPPConstructor[] ctors= ClassTypeHelper.getConstructors(specialClass.getSpecializedBinding(), point); return specializeMembers(ctors, point); } @Override public ICPPMethod[] getDeclaredMethods(IASTNode point) { - ICPPMethod[] bindings = specialClass.getSpecializedBinding().getDeclaredMethods(); + ICPPMethod[] bindings = ClassTypeHelper.getDeclaredMethods(specialClass.getSpecializedBinding(), point); return specializeMembers(bindings, point); } @Override public ICPPClassType[] getNestedClasses(IASTNode point) { - ICPPClassType[] bindings = specialClass.getSpecializedBinding().getNestedClasses(); + ICPPClassType[] bindings = ClassTypeHelper.getNestedClasses(specialClass.getSpecializedBinding(), point); return specializeMembers(bindings, point); } @Override public IBinding[] getFriends(IASTNode point) { - IBinding[] friends = specialClass.getSpecializedBinding().getFriends(); + IBinding[] friends = ClassTypeHelper.getFriends(specialClass.getSpecializedBinding(), point); return specializeMembers(friends, point); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java index bc482f514c9..60e3b2a1a4c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java @@ -175,7 +175,7 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements IBinding method= fdef.getDeclarator().getName().resolveBinding(); if (method instanceof ICPPMethod) { ICPPClassType cls= ((ICPPMethod) method).getClassOwner(); - for (ICPPBase base : SemanticUtil.getBases(cls, fdef)) { + for (ICPPBase base : ClassTypeHelper.getBases(cls, fdef)) { result.put(base.getBaseClassSpecifierName().getSimpleID()); } return result; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java index 0c74af3421a..25fb6187c7e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java @@ -43,6 +43,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFunctionCall; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalTypeId; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.LookupData; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; public class CPPASTFunctionCallExpression extends ASTNode implements ICPPASTFunctionCallExpression, IASTAmbiguityParent { @@ -270,7 +271,7 @@ public class CPPASTFunctionCallExpression extends ASTNode ICPPClassType cls= (ICPPClassType) t; LookupData data= CPPSemantics.createLookupData(((IASTIdExpression) functionName).getName()); try { - IBinding b= CPPSemantics.resolveFunction(data, cls.getConstructors(), true); + IBinding b= CPPSemantics.resolveFunction(data, ClassTypeHelper.getConstructors(cls, data.getLookupPoint()), true); if (b instanceof ICPPFunction) return (ICPPFunction) b; } catch (DOMException e) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java index 5c7e349989a..b59a06e4189 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java @@ -278,7 +278,7 @@ public class CPPASTQualifiedName extends CPPASTNameBase List filtered = filterClassScopeBindings(classType, bindings, isDeclaration); if (isDeclaration && nameMatches(classType.getNameCharArray(), n.getLookupKey(), isPrefix)) { - ICPPConstructor[] constructors = SemanticUtil.getConstructors(classType, n); + ICPPConstructor[] constructors = ClassTypeHelper.getConstructors(classType, n); for (int i = 0; i < constructors.length; i++) { if (!constructors[i].isImplicit()) { filtered.add(constructors[i]); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java index e8a8497f532..92205e34e45 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java @@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import java.util.HashSet; import java.util.Set; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; @@ -122,7 +123,8 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPBase[] getBases() { - return getBases(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getBases(null); } @Override @@ -136,7 +138,8 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPField[] getDeclaredFields() { - return getDeclaredFields(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getDeclaredFields(null); } @Override @@ -150,7 +153,8 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPMethod[] getDeclaredMethods() { - return getDeclaredMethods(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getDeclaredMethods(null); } @Override @@ -164,7 +168,8 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPConstructor[] getConstructors() { - return getConstructors(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getConstructors(null); } @Override @@ -178,7 +183,8 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public IBinding[] getFriends() { - return getFriends(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getFriends(null); } @Override @@ -192,7 +198,8 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPClassType[] getNestedClasses() { - return getNestedClasses(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getNestedClasses(null); } @Override @@ -206,7 +213,13 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public IField[] getFields() { - return ClassTypeHelper.getFields(this); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getFields(null); + } + + @Override + public IField[] getFields(IASTNode point) { + return ClassTypeHelper.getFields(this, point); } @Override @@ -216,12 +229,24 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPMethod[] getMethods() { - return ClassTypeHelper.getMethods(this); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getMethods(null); + } + + @Override + public ICPPMethod[] getMethods(IASTNode point) { + return ClassTypeHelper.getMethods(this, point); } @Override public ICPPMethod[] getAllDeclaredMethods() { - return ClassTypeHelper.getAllDeclaredMethods(this); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getAllDeclaredMethods(null); + } + + @Override + public ICPPMethod[] getAllDeclaredMethods(IASTNode point) { + return ClassTypeHelper.getAllDeclaredMethods(this, point); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java index a7aa9075a67..b5093453da0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java @@ -159,7 +159,7 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements ICPPClass @Override public IField[] getFields() { - return ClassTypeHelper.getFields(this); + return ClassTypeHelper.getFields(this, null); } @Override @@ -169,12 +169,12 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements ICPPClass @Override public ICPPMethod[] getMethods() { - return ClassTypeHelper.getMethods(this); + return ClassTypeHelper.getMethods(this, null); } @Override public ICPPMethod[] getAllDeclaredMethods() { - return ClassTypeHelper.getAllDeclaredMethods(this); + return ClassTypeHelper.getAllDeclaredMethods(this, null); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java index 32e50325a8d..4bdd0ab55ab 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java @@ -43,7 +43,7 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization @Override public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() { if (fPartialSpecs == null) { - IASTNode point= null; // Instantiation of dependent expression may not work. + IASTNode point= null; // Instantiation of dependent expressions may not work. ICPPClassTemplate origTemplate= (ICPPClassTemplate) getSpecializedBinding(); ICPPClassTemplatePartialSpecialization[] orig = origTemplate.getPartialSpecializations(); ICPPClassTemplatePartialSpecialization[] spec = new ICPPClassTemplatePartialSpecialization[orig.length]; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java index 08dfc43baae..b6a32c6a886 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java @@ -309,7 +309,7 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp @Override public IField[] getFields() { - return ClassTypeHelper.getFields(this); + return ClassTypeHelper.getFields(this, null); } @Override @@ -319,12 +319,12 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp @Override public ICPPMethod[] getMethods() { - return ClassTypeHelper.getMethods(this); + return ClassTypeHelper.getMethods(this, null); } @Override public ICPPMethod[] getAllDeclaredMethods() { - return ClassTypeHelper.getAllDeclaredMethods(this); + return ClassTypeHelper.getAllDeclaredMethods(this, null); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java index 229f129609a..bf44bc27797 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java @@ -194,6 +194,6 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod @Override public IType[] getExceptionSpecification() { - return ClassTypeHelper.getInheritedExceptionSpecification(this); + return ClassTypeHelper.getInheritedExceptionSpecification(this, null); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java index a8baca56672..988ae58bccd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2010 IBM Corporation and others. + * Copyright (c) 2005, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * Andrew Niefer (IBM) - Initial API and implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -20,20 +21,27 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethodSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; /** * The specialization of a method in the context of a class-specialization. */ -public class CPPMethodSpecialization extends CPPFunctionSpecialization implements ICPPMethod { +public class CPPMethodSpecialization extends CPPFunctionSpecialization implements ICPPMethodSpecialization { - public CPPMethodSpecialization(ICPPMethod orig, ICPPClassType owner, ICPPTemplateParameterMap argMap, ICPPFunctionType type, IType[] exceptionSpec ) { - super(orig, owner, argMap, type, exceptionSpec ); + public CPPMethodSpecialization(ICPPMethod orig, ICPPClassType owner, ICPPTemplateParameterMap argMap, + ICPPFunctionType type, IType[] exceptionSpec) { + super(orig, owner, argMap, type, exceptionSpec); + } + + @Override + public ICPPMethod getSpecializedBinding() { + return (ICPPMethod) super.getSpecializedBinding(); } @Override public boolean isVirtual() { - ICPPMethod f = (ICPPMethod) getSpecializedBinding(); + ICPPMethod f = getSpecializedBinding(); if (f != null) return f.isVirtual(); IASTNode definition = getDefinition(); @@ -58,7 +66,7 @@ public class CPPMethodSpecialization extends CPPFunctionSpecialization implement @Override public int getVisibility() { - ICPPMethod f = (ICPPMethod) getSpecializedBinding(); + ICPPMethod f = getSpecializedBinding(); if (f != null) return f.getVisibility(); return 0; @@ -80,17 +88,17 @@ public class CPPMethodSpecialization extends CPPFunctionSpecialization implement @Override public boolean isExplicit() { - return ((ICPPMethod) getSpecializedBinding()).isExplicit(); + return getSpecializedBinding().isExplicit(); } @Override public boolean isImplicit() { - return ((ICPPMethod) getSpecializedBinding()).isImplicit(); + return getSpecializedBinding().isImplicit(); } @Override public boolean isPureVirtual() { - ICPPMethod f = (ICPPMethod) getSpecializedBinding(); + ICPPMethod f = getSpecializedBinding(); if (f != null) return f.isPureVirtual(); @@ -98,9 +106,9 @@ public class CPPMethodSpecialization extends CPPFunctionSpecialization implement } @Override - public IType[] getExceptionSpecification() { + public IType[] getExceptionSpecification(IASTNode point) { if (isImplicit()) { - return ClassTypeHelper.getInheritedExceptionSpecification(this); + return ClassTypeHelper.getInheritedExceptionSpecification(this, point); } return super.getExceptionSpecification(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java index d2b13592b99..2debf208a5c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java @@ -54,6 +54,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; @@ -101,14 +102,14 @@ public class ClassTypeHelper { IASTDeclaration[] members = host.getCompositeTypeSpecifier().getMembers(); for (IASTDeclaration decl : members) { while (decl instanceof ICPPASTTemplateDeclaration) - decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration(); + decl = ((ICPPASTTemplateDeclaration) decl).getDeclaration(); if (decl instanceof IASTSimpleDeclaration) { - ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)decl).getDeclSpecifier(); + ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration) decl).getDeclSpecifier(); if (declSpec.isFriend()) { - IASTDeclarator[] dtors = ((IASTSimpleDeclaration)decl).getDeclarators(); + IASTDeclarator[] dtors = ((IASTSimpleDeclaration) decl).getDeclarators(); if (declSpec instanceof ICPPASTElaboratedTypeSpecifier && dtors.length == 0) { - resultSet.put(((ICPPASTElaboratedTypeSpecifier)declSpec).getName().resolveBinding()); + resultSet.put(((ICPPASTElaboratedTypeSpecifier) declSpec).getName().resolveBinding()); } else { for (IASTDeclarator dtor : dtors) { if (dtor == null) break; @@ -118,9 +119,9 @@ public class ClassTypeHelper { } } } else if (decl instanceof IASTFunctionDefinition) { - ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition)decl).getDeclSpecifier(); + ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition) decl).getDeclSpecifier(); if (declSpec.isFriend()) { - IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator(); + IASTDeclarator dtor = ((IASTFunctionDefinition) decl).getDeclarator(); dtor= ASTQueries.findInnermostDeclarator(dtor); resultSet.put(dtor.getName().resolveBinding()); } @@ -144,7 +145,7 @@ public class ClassTypeHelper { if (type.isSameType(classType)) { return true; } - for (IBinding friend : classType.getFriends()) { + for (IBinding friend : getFriends(classType, null)) { if (friend instanceof ICPPClassType && type.isSameType((IType) friend)) { return true; } @@ -152,7 +153,7 @@ public class ClassTypeHelper { } else if (binding instanceof ICPPFunction) { type = ((ICPPFunction) binding).getType(); char[] name = binding.getNameCharArray(); - for (IBinding friend : classType.getFriends()) { + for (IBinding friend : getFriends(classType, null)) { if (friend instanceof ICPPFunction && CharArrayUtils.equals(name, friend.getNameCharArray()) && SemanticUtil.isSameOwner(binding.getOwner(), friend.getOwner()) && @@ -217,17 +218,17 @@ public class ClassTypeHelper { IASTDeclaration[] decls = host.getCompositeTypeSpecifier().getMembers(); for (IASTDeclaration decl : decls) { if (decl instanceof IASTSimpleDeclaration) { - IASTDeclarator[] dtors = ((IASTSimpleDeclaration)decl).getDeclarators(); + IASTDeclarator[] dtors = ((IASTSimpleDeclaration) decl).getDeclarators(); for (IASTDeclarator dtor : dtors) { binding = ASTQueries.findInnermostDeclarator(dtor).getName().resolveBinding(); if (binding instanceof ICPPField) result = ArrayUtil.append(ICPPField.class, result, (ICPPField) binding); } } else if (decl instanceof ICPPASTUsingDeclaration) { - IASTName n = ((ICPPASTUsingDeclaration)decl).getName(); + IASTName n = ((ICPPASTUsingDeclaration) decl).getName(); binding = n.resolveBinding(); if (binding instanceof ICPPUsingDeclaration) { - IBinding[] bs = ((ICPPUsingDeclaration)binding).getDelegates(); + IBinding[] bs = ((ICPPUsingDeclaration) binding).getDelegates(); for (IBinding element : bs) { if (element instanceof ICPPField) result = ArrayUtil.append(ICPPField.class, result, (ICPPField) element); @@ -240,27 +241,63 @@ public class ClassTypeHelper { return ArrayUtil.trim(ICPPField.class, result); } + public static ICPPBase[] getBases(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getBases(point); + return classType.getBases(); + } + + public static ICPPConstructor[] getConstructors(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getConstructors(point); + return classType.getConstructors(); + } + + public static ICPPField[] getDeclaredFields(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getDeclaredFields(point); + return classType.getDeclaredFields(); + } + + public static ICPPMethod[] getDeclaredMethods(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getDeclaredMethods(point); + return classType.getDeclaredMethods(); + } + + public static IBinding[] getFriends(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getFriends(point); + return classType.getFriends(); + } + + public static ICPPClassType[] getNestedClasses(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getNestedClasses(point); + return classType.getNestedClasses(); + } + /** * Returns all direct and indirect base classes. * @param classType a class * @return An array of visible base classes in arbitrary order. */ - public static ICPPClassType[] getAllBases(ICPPClassType classType) { + public static ICPPClassType[] getAllBases(ICPPClassType classType, IASTNode point) { HashSet result= new HashSet(); result.add(classType); - getAllBases(classType, result); + getAllBases(classType, result, point); result.remove(classType); return result.toArray(new ICPPClassType[result.size()]); } - private static void getAllBases(ICPPClassType classType, HashSet result) { - ICPPBase[] bases= classType.getBases(); + private static void getAllBases(ICPPClassType classType, HashSet result, IASTNode point) { + ICPPBase[] bases= ClassTypeHelper.getBases(classType, point); for (ICPPBase base : bases) { IBinding b= base.getBaseClass(); if (b instanceof ICPPClassType) { final ICPPClassType baseClass = (ICPPClassType) b; if (result.add(baseClass)) { - getAllBases(baseClass, result); + getAllBases(baseClass, result, point); } } } @@ -287,25 +324,22 @@ public class ClassTypeHelper { return false; } - public static ICPPMethod[] getAllDeclaredMethods(ICPPClassType ct) { - ICPPMethod[] methods= ct.getDeclaredMethods(); - ICPPClassType[] bases= getAllBases(ct); + public static ICPPMethod[] getAllDeclaredMethods(ICPPClassType ct, IASTNode point) { + ICPPMethod[] methods= getDeclaredMethods(ct, point); + ICPPClassType[] bases= getAllBases(ct, point); for (ICPPClassType base : bases) { - methods = ArrayUtil.addAll(ICPPMethod.class, methods, base.getDeclaredMethods()); + methods = ArrayUtil.addAll(ICPPMethod.class, methods, getDeclaredMethods(base, point)); } return ArrayUtil.trim(ICPPMethod.class, methods); } - public static ICPPMethod[] getMethods(ICPPClassType ct) { - ObjectSet set = getOwnMethods(ct); + public static ICPPMethod[] getMethods(ICPPClassType ct, IASTNode point) { + ObjectSet set = getOwnMethods(ct, point); - ICPPClassType[] bases= getAllBases(ct); + ICPPClassType[] bases= getAllBases(ct, point); for (ICPPClassType base : bases) { - set.addAll(base.getDeclaredMethods()); - final IScope compositeScope = base.getCompositeScope(); - if (compositeScope instanceof ICPPClassScope) { - set.addAll(((ICPPClassScope) compositeScope).getImplicitMethods()); - } + set.addAll(getDeclaredMethods(base, point)); + set.addAll(getImplicitMethods(base, point)); } return set.keyArray(ICPPMethod.class); } @@ -314,16 +348,23 @@ public class ClassTypeHelper { * Returns methods either declared by the given class or generated by the compiler. Does not * include methods declared in base classes. */ - private static ObjectSet getOwnMethods(ICPPClassType classType) { + private static ObjectSet getOwnMethods(ICPPClassType classType, IASTNode point) { ObjectSet set= new ObjectSet(4); - set.addAll(classType.getDeclaredMethods()); - IScope scope = classType.getCompositeScope(); - if (scope instanceof ICPPClassScope) { - set.addAll(((ICPPClassScope) scope).getImplicitMethods()); - } + set.addAll(ClassTypeHelper.getDeclaredMethods(classType, point)); + set.addAll(getImplicitMethods(classType, point)); return set; } + public static ICPPMethod[] getImplicitMethods(ICPPClassType classType, IASTNode point) { + IScope scope = classType.getCompositeScope(); + if (scope instanceof ICPPClassSpecializationScope) { + return ((ICPPClassSpecializationScope) scope).getImplicitMethods(point); + } else if (scope instanceof ICPPClassScope) { + return ((ICPPClassScope) scope).getImplicitMethods(); + } + return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; + } + public static ICPPMethod[] getDeclaredMethods(ICPPInternalClassTypeMixinHost host) { if (host.getDefinition() == null) { host.checkForDefinition(); @@ -341,9 +382,9 @@ public class ClassTypeHelper { IASTDeclaration[] decls = host.getCompositeTypeSpecifier().getMembers(); for (IASTDeclaration decl : decls) { while (decl instanceof ICPPASTTemplateDeclaration) - decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration(); + decl = ((ICPPASTTemplateDeclaration) decl).getDeclaration(); if (decl instanceof IASTSimpleDeclaration) { - final IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration)decl; + final IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration) decl; if (!((ICPPASTDeclSpecifier) sdecl.getDeclSpecifier()).isFriend()) { IASTDeclarator[] dtors = sdecl.getDeclarators(); for (IASTDeclarator dtor : dtors) { @@ -353,7 +394,7 @@ public class ClassTypeHelper { } } } else if (decl instanceof IASTFunctionDefinition) { - final IASTFunctionDefinition fdef = (IASTFunctionDefinition)decl; + final IASTFunctionDefinition fdef = (IASTFunctionDefinition) decl; if (!((ICPPASTDeclSpecifier) fdef.getDeclSpecifier()).isFriend()) { IASTDeclarator dtor = fdef.getDeclarator(); dtor = ASTQueries.findInnermostDeclarator(dtor); @@ -363,10 +404,10 @@ public class ClassTypeHelper { } } } else if (decl instanceof ICPPASTUsingDeclaration) { - IASTName n = ((ICPPASTUsingDeclaration)decl).getName(); + IASTName n = ((ICPPASTUsingDeclaration) decl).getName(); binding = n.resolveBinding(); if (binding instanceof ICPPUsingDeclaration) { - IBinding[] bs = ((ICPPUsingDeclaration)binding).getDelegates(); + IBinding[] bs = ((ICPPUsingDeclaration) binding).getDelegates(); for (IBinding element : bs) { if (element instanceof ICPPMethod) result = ArrayUtil.append(ICPPMethod.class, result, (ICPPMethod) element); @@ -407,15 +448,15 @@ public class ClassTypeHelper { IASTDeclaration[] decls = host.getCompositeTypeSpecifier().getMembers(); for (IASTDeclaration decl : decls) { while (decl instanceof ICPPASTTemplateDeclaration) - decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration(); + decl = ((ICPPASTTemplateDeclaration) decl).getDeclaration(); if (decl instanceof IASTSimpleDeclaration) { IBinding binding = null; IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration) decl).getDeclSpecifier(); if (declSpec instanceof ICPPASTCompositeTypeSpecifier) { - binding = ((ICPPASTCompositeTypeSpecifier)declSpec).getName().resolveBinding(); + binding = ((ICPPASTCompositeTypeSpecifier) declSpec).getName().resolveBinding(); } else if (declSpec instanceof ICPPASTElaboratedTypeSpecifier && - ((IASTSimpleDeclaration)decl).getDeclarators().length == 0) { - binding = ((ICPPASTElaboratedTypeSpecifier)declSpec).getName().resolveBinding(); + ((IASTSimpleDeclaration) decl).getDeclarators().length == 0) { + binding = ((ICPPASTElaboratedTypeSpecifier) declSpec).getName().resolveBinding(); } if (binding instanceof ICPPClassType) result = ArrayUtil.append(ICPPClassType.class, result, (ICPPClassType) binding); @@ -424,11 +465,11 @@ public class ClassTypeHelper { return ArrayUtil.trim(ICPPClassType.class, result); } - public static IField[] getFields(ICPPClassType ct) { - IField[] fields = ct.getDeclaredFields(); - ICPPClassType[] bases = getAllBases(ct); + public static IField[] getFields(ICPPClassType ct, IASTNode point) { + IField[] fields = getDeclaredFields(ct, point); + ICPPClassType[] bases = getAllBases(ct, point); for (ICPPClassType base : bases) { - fields = ArrayUtil.addAll(IField.class, fields, base.getDeclaredFields()); + fields = ArrayUtil.addAll(IField.class, fields, getDeclaredFields(base, point)); } return ArrayUtil.trim(IField.class, fields); } @@ -464,7 +505,8 @@ public class ClassTypeHelper { final ICPPClassType mcl= m.getClassOwner(); if (mcl != null) { final ICPPFunctionType mft= m.getType(); - ICPPMethod[] allMethods= mcl.getMethods(); + IASTNode point = null; // Instantiation of dependent expressions may not work + ICPPMethod[] allMethods= ClassTypeHelper.getMethods(mcl, point); for (ICPPMethod method : allMethods) { if (CharArrayUtils.equals(mname, method.getNameCharArray()) && functionTypesAllowOverride(mft, method.getType())) { if (method.isVirtual()) { @@ -520,7 +562,7 @@ public class ClassTypeHelper { if (sourceClass == null || targetClass == null) return false; - ICPPClassType[] bases= getAllBases(sourceClass); + ICPPClassType[] bases= getAllBases(sourceClass, null); for (ICPPClassType base : bases) { if (base.isSameType(targetClass)) return true; @@ -532,7 +574,7 @@ public class ClassTypeHelper { /** * Returns all methods that are overridden by the given {@code method}. */ - public static ICPPMethod[] findOverridden(ICPPMethod method) { + public static ICPPMethod[] findOverridden(ICPPMethod method, IASTNode point) { if (method instanceof ICPPConstructor) return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; @@ -546,7 +588,7 @@ public class ClassTypeHelper { final ICPPFunctionType mft= method.getType(); virtualInClass.put(mcl, method.isVirtual()); - ICPPBase[] bases= mcl.getBases(); + ICPPBase[] bases= getBases(mcl, point); for (ICPPBase base : bases) { IBinding b= base.getBaseClass(); if (b instanceof ICPPClassType) { @@ -681,10 +723,10 @@ public class ClassTypeHelper { /** * For implicit methods the exception specification is inherited, search it */ - public static IType[] getInheritedExceptionSpecification(ICPPMethod implicitMethod) { + public static IType[] getInheritedExceptionSpecification(ICPPMethod implicitMethod, IASTNode point) { // See 15.4.13 ICPPClassType owner= implicitMethod.getClassOwner(); - if (owner == null || owner.getBases().length == 0) + if (owner == null || ClassTypeHelper.getBases(owner, point).length == 0) return null; // we use a list as types aren't comparable, and can have duplicates (15.4.6) @@ -693,7 +735,7 @@ public class ClassTypeHelper { return null; List inheritedTypeids = new ArrayList(); - ICPPClassType[] bases= getAllBases(owner); + ICPPClassType[] bases= getAllBases(owner, point); for (ICPPClassType base : bases) { if (!(base instanceof ICPPDeferredClassInstance)) { ICPPMethod baseMethod= getMethodInClass(base, kind); @@ -792,10 +834,10 @@ public class ClassTypeHelper { * no private or protected non-static data members (Clause 11), * no base classes (Clause 10), and no virtual functions (10.3). */ - public static boolean isAggregateClass(ICPPClassType classTarget) { - if (classTarget.getBases().length > 0) + public static boolean isAggregateClass(ICPPClassType classTarget, IASTNode point) { + if (ClassTypeHelper.getBases(classTarget, point).length > 0) return false; - ICPPMethod[] methods = classTarget.getDeclaredMethods(); + ICPPMethod[] methods = ClassTypeHelper.getDeclaredMethods(classTarget, point); for (ICPPMethod m : methods) { if (m instanceof ICPPConstructor) return false; @@ -803,7 +845,7 @@ public class ClassTypeHelper { return false; } } - ICPPField[] fields = classTarget.getDeclaredFields(); + ICPPField[] fields = ClassTypeHelper.getDeclaredFields(classTarget, point); for (ICPPField field : fields) { if (!(field.getVisibility() == ICPPMember.v_public || field.isStatic())) { return false; @@ -837,7 +879,7 @@ public class ClassTypeHelper { if (base.isVirtual()) return false; } - for (ICPPClassType baseClass : getAllBases(classTarget)) { + for (ICPPClassType baseClass : getAllBases(classTarget, null)) { if (!classTarget.isSameType(baseClass) && !hasTrivialCopyCtor(baseClass)) return false; } @@ -889,7 +931,7 @@ public class ClassTypeHelper { if (!ctor.isImplicit() && ctor.getParameters().length == 0) return false; } - for (ICPPClassType baseClass : getAllBases(classTarget)) { + for (ICPPClassType baseClass : getAllBases(classTarget, null)) { if (!classTarget.isSameType(baseClass) && !hasTrivialDefaultConstructor(baseClass)) return false; } @@ -925,7 +967,7 @@ public class ClassTypeHelper { if (method.isDestructor()) return false; } - for (ICPPClassType baseClass : getAllBases(classTarget)) { + for (ICPPClassType baseClass : getAllBases(classTarget, null)) { if (!classTarget.isSameType(baseClass) && !hasTrivialDestructor(baseClass)) return false; } @@ -952,7 +994,7 @@ public class ClassTypeHelper { public static boolean isPolymorphic(ICPPClassType classTarget) { if (hasDeclaredVirtualMethod(classTarget)) return true; - for (ICPPClassType baseClass : getAllBases(classTarget)) { + for (ICPPClassType baseClass : getAllBases(classTarget, null)) { if (hasDeclaredVirtualMethod(baseClass)) return true; } @@ -976,9 +1018,9 @@ public class ClassTypeHelper { * but doesn't take into account base classes and methods dependent on unspecified * template parameters. */ - public static ICPPMethod[] getPureVirtualMethods(ICPPClassType classType) { + public static ICPPMethod[] getPureVirtualMethods(ICPPClassType classType, IASTNode point) { Map> result= collectPureVirtualMethods(classType, - new HashMap>>()); + new HashMap>>(), point); int resultArraySize = 0; for (List methods : result.values()) { @@ -995,7 +1037,7 @@ public class ClassTypeHelper { } private static Map> collectPureVirtualMethods(ICPPClassType classType, - Map>> cache) { + Map>> cache, IASTNode point) { Map> result = cache.get(classType); if (result != null) return result; @@ -1005,10 +1047,10 @@ public class ClassTypeHelper { // Look at the pure virtual methods of the base classes Set handledBaseClasses= new HashSet(); - for (ICPPBase base : classType.getBases()) { + for (ICPPBase base : ClassTypeHelper.getBases(classType, point)) { final IBinding baseClass = base.getBaseClass(); if (baseClass instanceof ICPPClassType && handledBaseClasses.add(baseClass)) { - Map> pureVirtuals = collectPureVirtualMethods((ICPPClassType) baseClass, cache); + Map> pureVirtuals = collectPureVirtualMethods((ICPPClassType) baseClass, cache, point); // Merge derived pure virtual methods for (String key : pureVirtuals.keySet()) { List list = result.get(key); @@ -1021,8 +1063,8 @@ public class ClassTypeHelper { } } - // Remove overridden pure-virtual methods and add in new pure virutals. - final ObjectSet methods = getOwnMethods(classType); + // Remove overridden pure-virtual methods and add in new pure virtuals. + final ObjectSet methods = getOwnMethods(classType, point); for (ICPPMethod method : methods) { String key= getMethodNameForOverrideKey(method); List list = result.get(key); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AccessContext.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AccessContext.java index 78e1a4b670d..42a6213a7b2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AccessContext.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AccessContext.java @@ -152,7 +152,7 @@ public class AccessContext { return isAccessible(bindingVisibility, accessLevel); } - ICPPBase[] bases = derivedClass.getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases(derivedClass, name); if (bases != null) { for (ICPPBase base : bases) { IBinding baseBinding = base.getBaseClass(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java index d8de2c8590d..aee259f5dca 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java @@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; @@ -181,7 +182,7 @@ class BaseClassLookup { // base-classes ICPPClassType baseClass= result.getClassType(); if (baseClass != null) { - ICPPBase[] grandBases= SemanticUtil.getBases(baseClass, data.getLookupPoint()); + ICPPBase[] grandBases= ClassTypeHelper.getBases(baseClass, data.getLookupPoint()); if (grandBases != null && grandBases.length > 0) { HashSet grandBaseBindings= null; BitSet selectedBases= null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java index beafb1b0979..53b6ff28028 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java @@ -27,6 +27,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator; import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument; @@ -251,7 +252,9 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } protected static SizeAndAlignment getSizeAndAlignment(IType type, IASTNode point) { - ASTTranslationUnit ast = (ASTTranslationUnit) point.getTranslationUnit(); - return ast.getSizeofCalculator().sizeAndAlignment(type); + SizeofCalculator calc = point == null ? + SizeofCalculator.getDefault() : + ((ASTTranslationUnit) point.getTranslationUnit()).getSizeofCalculator(); + return calc.sizeAndAlignment(type); } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index f2d1602f903..454b1230c15 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -203,6 +203,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUsingDeclaration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUsingDirective; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPASTInternalScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; @@ -414,7 +415,7 @@ public class CPPSemantics { if (cls instanceof ICPPUnknownBinding) { binding= new CPPUnknownConstructor(cls); } else { - binding= CPPSemantics.resolveFunction(data, SemanticUtil.getConstructors(cls, lookupPoint), true); + binding= CPPSemantics.resolveFunction(data, ClassTypeHelper.getConstructors(cls, lookupPoint), true); } } catch (DOMException e) { return e.getProblem(); @@ -714,7 +715,7 @@ public class CPPSemantics { } if (t instanceof ICPPClassType && !(t instanceof ICPPClassTemplate)) { ICPPClassType ct= (ICPPClassType) t; - ICPPBase[] bases = SemanticUtil.getBases(ct, tu); + ICPPBase[] bases = ClassTypeHelper.getBases(ct, tu); for (ICPPBase base : bases) { IBinding b = base.getBaseClass(); if (b instanceof IType) @@ -725,7 +726,7 @@ public class CPPSemantics { // (excluding template template parameters); // * ... owners of which any template template arguments are members; if (ct instanceof ICPPTemplateInstance) { - for (IBinding friend : ct.getFriends()) { + for (IBinding friend : ClassTypeHelper.getFriends(ct, tu)) { if (friend instanceof ICPPFunction) { friendFns.add((ICPPFunction) friend); } @@ -2817,7 +2818,7 @@ public class CPPSemantics { LookupData data= new LookupData(name); data.setFunctionArguments(false, init.getArguments()); try { - IBinding ctor = CPPSemantics.resolveFunction(data, SemanticUtil.getConstructors((ICPPClassType) targetType, name), true); + IBinding ctor = CPPSemantics.resolveFunction(data, ClassTypeHelper.getConstructors((ICPPClassType) targetType, name), true); if (ctor instanceof ICPPConstructor) { int i= 0; for (IASTNode arg : init.getArguments()) { @@ -3124,13 +3125,13 @@ public class CPPSemantics { LookupData data = new LookupData(astName); data.setFunctionArguments(false, arguments); data.qualified = true; - data.foundItems = SemanticUtil.getConstructors(classType, name); + data.foundItems = ClassTypeHelper.getConstructors(classType, name); binding = resolveAmbiguities(data); if (binding instanceof ICPPConstructor) return (ICPPConstructor) binding; } else if (initializer == null) { // Default initialization - ICPPConstructor[] ctors = SemanticUtil.getConstructors(classType, name); + ICPPConstructor[] ctors = ClassTypeHelper.getConstructors(classType, name); for (ICPPConstructor ctor : ctors) { if (ctor.getRequiredArgumentCount() == 0) return ctor; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index b3b5d1c82ad..4ea01916b56 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -2241,6 +2241,8 @@ public class CPPVisitor extends ASTQueries { } private static IType getStdType(final IASTNode node, char[] name) { + if (node == null) + return null; ASTTranslationUnit ast = (ASTTranslationUnit) node.getTranslationUnit(); IBinding[] std= ast.getScope().find(STD); for (IBinding binding : std) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java index a32ce424546..31d1d843881 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java @@ -371,7 +371,7 @@ public class Conversions { return Cost.NO_CONVERSION; ICPPClassType classTarget= (ICPPClassType) noCVTarget; - if (ClassTypeHelper.isAggregateClass(classTarget)) { + if (ClassTypeHelper.isAggregateClass(classTarget, point)) { Cost cost= new Cost(arg.getTypeOrFunctionSet(point), target, Rank.IDENTITY); cost.setUserDefinedConversion(null); return cost; @@ -546,7 +546,7 @@ public class Conversions { ICPPConstructor usedCtor= null; Cost bestCost= null; boolean hasInitListConstructor= false; - final ICPPConstructor[] constructors = SemanticUtil.getConstructors(t, point); + final ICPPConstructor[] constructors = ClassTypeHelper.getConstructors(t, point); ICPPConstructor[] ctors= constructors; for (ICPPConstructor ctor : ctors) { final int minArgCount = ctor.getRequiredArgumentCount(); @@ -640,7 +640,7 @@ public class Conversions { FunctionCost cost1= null; Cost cost2= null; - ICPPFunction[] ctors= SemanticUtil.getConstructors(t, point); + ICPPFunction[] ctors= ClassTypeHelper.getConstructors(t, point); ctors = CPPTemplates.instantiateForFunctionCall(ctors, null, Collections.singletonList(source), Collections.singletonList(valueCat), false, point); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java index 9779ceb971c..3d9dadf4b01 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java @@ -40,10 +40,7 @@ import org.eclipse.cdt.core.dom.ast.IQualifierType; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; @@ -66,6 +63,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerToMemberType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator; @@ -108,7 +106,7 @@ public class SemanticUtil { if (clazz instanceof ICPPDeferredClassInstance) { clazz= (ICPPClassType) ((ICPPDeferredClassInstance) clazz).getTemplateDefinition(); } - ICPPMethod[] decs= getDeclaredMethods(clazz, point); + ICPPMethod[] decs= ClassTypeHelper.getDeclaredMethods(clazz, point); if (decs != null) { for (ICPPMethod method : decs) { if (isConversionOperator(method)) { @@ -152,7 +150,7 @@ public class SemanticUtil { ICPPClassType clazz= current.keyAt(i); done.put(clazz); - for (ICPPBase base : getBases(clazz, point)) { + for (ICPPBase base : ClassTypeHelper.getBases(clazz, point)) { IBinding binding= base.getBaseClass(); if (binding instanceof ICPPClassType && !(binding instanceof IProblemBinding)) { ICPPClassType ct= (ICPPClassType) binding; @@ -169,42 +167,6 @@ public class SemanticUtil { return done; } - public static ICPPBase[] getBases(ICPPClassType classType, IASTNode point) { - if (classType instanceof ICPPClassSpecialization) - return ((ICPPClassSpecialization) classType).getBases(point); - return classType.getBases(); - } - - public static ICPPConstructor[] getConstructors(ICPPClassType classType, IASTNode point) { - if (classType instanceof ICPPClassSpecialization) - return ((ICPPClassSpecialization) classType).getConstructors(point); - return classType.getConstructors(); - } - - public static ICPPField[] getDeclaredFields(ICPPClassType classType, IASTNode point) { - if (classType instanceof ICPPClassSpecialization) - return ((ICPPClassSpecialization) classType).getDeclaredFields(point); - return classType.getDeclaredFields(); - } - - public static ICPPMethod[] getDeclaredMethods(ICPPClassType classType, IASTNode point) { - if (classType instanceof ICPPClassSpecialization) - return ((ICPPClassSpecialization) classType).getDeclaredMethods(point); - return classType.getDeclaredMethods(); - } - - public static IBinding[] getFriends(ICPPClassType classType, IASTNode point) { - if (classType instanceof ICPPClassSpecialization) - return ((ICPPClassSpecialization) classType).getFriends(point); - return classType.getFriends(); - } - - public static ICPPClassType[] getNestedClasses(ICPPClassType classType, IASTNode point) { - if (classType instanceof ICPPClassSpecialization) - return ((ICPPClassSpecialization) classType).getNestedClasses(point); - return classType.getNestedClasses(); - } - /** * @param method * @return true if the specified method is a conversion operator @@ -676,7 +638,7 @@ public class SemanticUtil { clazz= (ICPPClassType) ((ICPPDeferredClassInstance) clazz).getSpecializedBinding(); } - for (ICPPBase cppBase : getBases(clazz, point)) { + for (ICPPBase cppBase : ClassTypeHelper.getBases(clazz, point)) { IBinding base= cppBase.getBaseClass(); if (base instanceof IType && hashSet.add(base)) { IType tbase= (IType) base; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java index ed22833493b..14d895b84ae 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Wind River Systems, Inc. and others. + * Copyright (c) 2009, 2012 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -63,6 +64,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPReferenceType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; @@ -71,9 +73,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; */ public class TemplateArgumentDeduction { /** - * Deduce arguments for a template function from the template id + the template function parameters. + * Deduce arguments for a template function from the template id and the template function + * parameters. * 14.8.2.1 - * @param point */ static ICPPTemplateArgument[] deduceForFunctionCall(ICPPFunctionTemplate template, ICPPTemplateArgument[] tmplArgs, List fnArgs, List argIsLValue, @@ -236,7 +238,7 @@ public class TemplateArgumentDeduction { ICPPTemplateInstance pInst = (ICPPTemplateInstance) pcheck; ICPPClassTemplate pTemplate= getPrimaryTemplate(pInst); if (pTemplate != null) { - ICPPClassType aInst= findBaseInstance((ICPPClassType) argcheck, pTemplate); + ICPPClassType aInst= findBaseInstance((ICPPClassType) argcheck, pTemplate, point); if (aInst != null && aInst != argcheck) { par= pcheck; arg= aInst; @@ -291,7 +293,6 @@ public class TemplateArgumentDeduction { /** * Deduce arguments for a user defined conversion template * 14.8.2.3 - * @param point */ static ICPPTemplateArgument[] deduceForConversion(ICPPFunctionTemplate template, IType conversionType, CPPTemplateParameterMap map, IASTNode point) throws DOMException { @@ -326,7 +327,6 @@ public class TemplateArgumentDeduction { /** * Deduce arguments for a function declaration * 14.8.2.6 - * @param point */ static ICPPTemplateArgument[] deduceForDeclaration(ICPPFunctionTemplate template, ICPPTemplateArgument[] args, ICPPFunctionType ftype, CPPTemplateParameterMap map, IASTNode point) throws DOMException { @@ -361,7 +361,6 @@ public class TemplateArgumentDeduction { /** * Deduces the mapping for the template parameters from the function parameters, * returns false if there is no mapping. - * @param point */ static int deduceForPartialOrdering(ICPPTemplateParameter[] tmplPars, IType[] fnPars, IType[] fnArgs, IASTNode point) { try { @@ -424,7 +423,6 @@ public class TemplateArgumentDeduction { /** * Adds the explicit arguments to the map. - * @param point */ private static boolean addExplicitArguments(final ICPPTemplateParameter[] tmplParams, ICPPTemplateArgument[] tmplArgs, CPPTemplateParameterMap map, IASTNode point) { @@ -482,13 +480,14 @@ public class TemplateArgumentDeduction { } /** - * 14.8.2.1.3 If P is a class and has the form template-id, then A can be a derived class of the deduced A. + * 14.8.2.1.3 If P is a class and has the form template-id, then A can be a derived class of + * the deduced A. */ - private static ICPPClassType findBaseInstance(ICPPClassType a, ICPPClassTemplate pTemplate) throws DOMException { - return findBaseInstance(a, pTemplate, CPPSemantics.MAX_INHERITANCE_DEPTH, new HashSet()); + private static ICPPClassType findBaseInstance(ICPPClassType a, ICPPClassTemplate pTemplate, IASTNode point) throws DOMException { + return findBaseInstance(a, pTemplate, CPPSemantics.MAX_INHERITANCE_DEPTH, new HashSet(), point); } - private static ICPPClassType findBaseInstance(ICPPClassType a, ICPPClassTemplate pTemplate, int maxdepth, HashSet handled) throws DOMException { + private static ICPPClassType findBaseInstance(ICPPClassType a, ICPPClassTemplate pTemplate, int maxdepth, HashSet handled, IASTNode point) throws DOMException { if (a instanceof ICPPTemplateInstance) { final ICPPTemplateInstance inst = (ICPPTemplateInstance) a; ICPPClassTemplate tmpl= getPrimaryTemplate(inst); @@ -496,10 +495,10 @@ public class TemplateArgumentDeduction { return a; } if (maxdepth-- > 0) { - for (ICPPBase cppBase : a.getBases()) { + for (ICPPBase cppBase : ClassTypeHelper.getBases(a, point)) { IBinding base= cppBase.getBaseClass(); if (base instanceof ICPPClassType && handled.add(base)) { - final ICPPClassType inst= findBaseInstance((ICPPClassType) base, pTemplate, maxdepth, handled); + final ICPPClassType inst= findBaseInstance((ICPPClassType) base, pTemplate, maxdepth, handled, point); if (inst != null) return inst; } @@ -547,7 +546,6 @@ public class TemplateArgumentDeduction { /** * Deduces the template parameter mapping from pairs of template arguments. - * @param point */ public static boolean fromTemplateArguments(final ICPPTemplateParameter[] pars, final ICPPTemplateArgument[] p, final ICPPTemplateArgument[] a, CPPTemplateParameterMap map, @@ -640,7 +638,6 @@ public class TemplateArgumentDeduction { /** * Deduces the template parameter mapping from one pair of template arguments. - * @param point */ private boolean fromTemplateArgument(ICPPTemplateArgument p, ICPPTemplateArgument a, IASTNode point) throws DOMException { if (p.isNonTypeValue() != a.isNonTypeValue()) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java index 5aba0d03b0f..4d82579e7bc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java @@ -15,8 +15,10 @@ package org.eclipse.cdt.internal.core.index.composite.cpp; import java.util.HashSet; import java.util.Set; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; @@ -30,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassSpecialization.RecursionResolvingBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.index.IIndexFragment; @@ -79,11 +82,11 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple specializationMap= (ObjectMap) cached; } else { final ObjectMap newMap= new ObjectMap(2); - // in any fragment explicit specializations may be defined. + // In any fragment explicit specializations may be defined. IIndexFragmentBinding[] frags= cf.findEquivalentBindings(rbinding); for (IIndexFragmentBinding fb : frags) { if (fb instanceof ICPPClassType) { - final ICPPClassType[] nested = ((ICPPClassType)fb).getNestedClasses(); + final ICPPClassType[] nested = ClassTypeHelper.getNestedClasses((ICPPClassType) fb, point); if (nested.length > 0) { for (ICPPClassType ct : nested) { if (ct instanceof ICPPClassSpecialization && @@ -129,7 +132,8 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple @Override public final ICPPBase[] getBases() { - return getBases(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getBases(null); } @Override @@ -138,12 +142,14 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple if (scope instanceof ICPPClassSpecializationScope) { return ((ICPPClassSpecializationScope) scope).getBases(point); } - return super.getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases((ICPPClassType) rbinding, point); + return wrapBases(bases); } @Override public final ICPPConstructor[] getConstructors() { - return getConstructors(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getConstructors(null); } @Override @@ -152,12 +158,25 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple if (scope instanceof ICPPClassSpecializationScope) { return ((ICPPClassSpecializationScope) scope).getConstructors(point); } - return super.getConstructors(); + ICPPConstructor[] result = ClassTypeHelper.getConstructors((ICPPClassType) rbinding, point); + return wrapBindings(result); + } + + @Override + public ICPPMethod[] getMethods() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getMethods(null); + } + + @Override + public ICPPMethod[] getMethods(IASTNode point) { + return ClassTypeHelper.getMethods(this, point); } @Override public final ICPPMethod[] getDeclaredMethods() { - return getDeclaredMethods(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getDeclaredMethods(null); } @Override @@ -166,12 +185,25 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple if (scope instanceof ICPPClassSpecializationScope) { return ((ICPPClassSpecializationScope) scope).getDeclaredMethods(point); } - return super.getDeclaredMethods(); + ICPPMethod[] result = ClassTypeHelper.getDeclaredMethods((ICPPClassType) rbinding, point); + return wrapBindings(result); + } + + @Override + public final ICPPMethod[] getAllDeclaredMethods() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getAllDeclaredMethods(null); + } + + @Override + public final ICPPMethod[] getAllDeclaredMethods(IASTNode point) { + return ClassTypeHelper.getAllDeclaredMethods(this, point); } @Override public final ICPPField[] getDeclaredFields() { - return getDeclaredFields(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getDeclaredFields(null); } @Override @@ -180,12 +212,25 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple if (scope instanceof ICPPClassSpecializationScope) { return ((ICPPClassSpecializationScope) scope).getDeclaredFields(point); } - return super.getDeclaredFields(); + ICPPField[] result = ClassTypeHelper.getDeclaredFields((ICPPClassType) rbinding, point); + return wrapBindings(result); + } + + @Override + public IField[] getFields() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getFields(null); + } + + @Override + public final IField[] getFields(IASTNode point) { + return ClassTypeHelper.getFields(this, point); } @Override public final IBinding[] getFriends() { - return getFriends(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getFriends(null); } @Override @@ -194,12 +239,14 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple if (scope instanceof ICPPClassSpecializationScope) { return ((ICPPClassSpecializationScope) scope).getFriends(point); } - return super.getFriends(); + IBinding[] result = ClassTypeHelper.getFriends((ICPPClassType) rbinding, point); + return wrapBindings(result); } @Override public final ICPPClassType[] getNestedClasses() { - return getNestedClasses(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getNestedClasses(null); } @Override @@ -208,7 +255,8 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple if (scope instanceof ICPPClassSpecializationScope) { return ((ICPPClassSpecializationScope) scope).getNestedClasses(point); } - return super.getNestedClasses(); + ICPPClassType[] result = ClassTypeHelper.getNestedClasses((ICPPClassType) rbinding, point); + return wrapBindings(result); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java index 3a1ef81a859..b00a7b572dd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; @@ -69,7 +70,8 @@ public class CompositeCPPClassSpecializationScope extends CompositeScope impleme @Override public ICPPMethod[] getImplicitMethods() { - return getImplicitMethods(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getImplicitMethods(null); } @Override @@ -104,7 +106,8 @@ public class CompositeCPPClassSpecializationScope extends CompositeScope impleme @Override public ICPPConstructor[] getConstructors() { - return getConstructors(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getConstructors(null); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassType.java index 11e2cb9b8b5..9866bac677a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Symbian Software Systems and others. + * Copyright (c) 2007, 2012 Symbian Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,9 +8,12 @@ * Contributors: * Andrew Ferguson (Symbian) - Initial implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; +import java.util.Arrays; + import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IField; @@ -42,8 +45,8 @@ class CompositeCPPClassType extends CompositeCPPBinding implements ICPPClassType } @Override - public final ICPPMethod[] getAllDeclaredMethods() { - return ClassTypeHelper.getAllDeclaredMethods(this); + public ICPPMethod[] getAllDeclaredMethods() { + return ClassTypeHelper.getAllDeclaredMethods(this, null); } private class CPPBaseDelegate implements ICPPBase { @@ -101,68 +104,48 @@ class CompositeCPPClassType extends CompositeCPPBinding implements ICPPClassType @Override public ICPPBase[] getBases() { - final ICPPBase[] preresult = ((ICPPClassType) rbinding).getBases(); - ICPPBase[] result = new ICPPBase[preresult.length]; - for (int i= 0; i < preresult.length; i++) { - result[i] = new CPPBaseDelegate(preresult[i]); - } - return result; + ICPPBase[] bases = ((ICPPClassType) rbinding).getBases(); + return wrapBases(bases); } @Override public ICPPConstructor[] getConstructors() { ICPPConstructor[] result = ((ICPPClassType) rbinding).getConstructors(); - for (int i= 0; i < result.length; i++) { - result[i] = (ICPPConstructor) cf.getCompositeBinding((IIndexFragmentBinding) result[i]); - } - return result; + return wrapBindings(result); } @Override public ICPPField[] getDeclaredFields() { ICPPField[] result = ((ICPPClassType) rbinding).getDeclaredFields(); - for (int i= 0; i < result.length; i++) { - result[i] = (ICPPField) cf.getCompositeBinding((IIndexFragmentBinding) result[i]); - } - return result; + return wrapBindings(result); } @Override public ICPPMethod[] getDeclaredMethods() { ICPPMethod[] result = ((ICPPClassType) rbinding).getDeclaredMethods(); - for (int i= 0; i < result.length; i++) { - result[i]= (ICPPMethod) cf.getCompositeBinding((IIndexFragmentBinding) result[i]); - } - return result; + return wrapBindings(result); } @Override - public final IField[] getFields() { - return ClassTypeHelper.getFields(this); + public IField[] getFields() { + return ClassTypeHelper.getFields(this, null); } @Override public IBinding[] getFriends() { IBinding[] preResult = ((ICPPClassType) rbinding).getFriends(); - IBinding[] result = new IBinding[preResult.length]; - for (int i= 0; i < preResult.length; i++) { - result[i] = cf.getCompositeBinding((IIndexFragmentBinding) preResult[i]); - } - return result; + return wrapBindings(preResult); } @Override - public final ICPPMethod[] getMethods() { - return ClassTypeHelper.getMethods(this); + public ICPPMethod[] getMethods() { + return ClassTypeHelper.getMethods(this, null); } @Override public ICPPClassType[] getNestedClasses() { ICPPClassType[] result = ((ICPPClassType) rbinding).getNestedClasses(); - for (int i= 0; i < result.length; i++) { - result[i] = (ICPPClassType) cf.getCompositeBinding((IIndexFragmentBinding) result[i]); - } - return result; + return wrapBindings(result); } @Override @@ -184,4 +167,21 @@ class CompositeCPPClassType extends CompositeCPPBinding implements ICPPClassType public boolean isAnonymous() { return ((ICPPClassType) rbinding).isAnonymous(); } + + protected ICPPBase[] wrapBases(final ICPPBase[] bases) { + ICPPBase[] result = new ICPPBase[bases.length]; + for (int i= 0; i < bases.length; i++) { + result[i] = new CPPBaseDelegate(bases[i]); + } + return result; + } + + @SuppressWarnings("unchecked") + protected T[] wrapBindings(T[] bindings) { + T[] result = Arrays.copyOf(bindings, bindings.length); + for (int i= 0; i < bindings.length; i++) { + result[i] = (T) cf.getCompositeBinding((IIndexFragmentBinding) bindings[i]); + } + return result; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java index a90da22c5ef..b9e4969e680 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java @@ -208,7 +208,8 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPBase[] getBases() { - return getBases(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getBases(null); } @Override @@ -241,7 +242,8 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPConstructor[] getConstructors() { - return getConstructors(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getConstructors(null); } @Override @@ -262,7 +264,8 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPMethod[] getDeclaredMethods() { - return getDeclaredMethods(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getDeclaredMethods(null); } @Override @@ -283,7 +286,8 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPField[] getDeclaredFields() { - return getDeclaredFields(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getDeclaredFields(null); } @Override @@ -304,7 +308,8 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPClassType[] getNestedClasses() { - return getNestedClasses(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getNestedClasses(null); } @Override @@ -325,7 +330,8 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public IBinding[] getFriends() { - return getFriends(null); // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getFriends(null); } @Override @@ -336,17 +342,35 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPMethod[] getMethods() { - return ClassTypeHelper.getMethods(this); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getMethods(null); + } + + @Override + public ICPPMethod[] getMethods(IASTNode point) { + return ClassTypeHelper.getMethods(this, point); } @Override public ICPPMethod[] getAllDeclaredMethods() { - return ClassTypeHelper.getAllDeclaredMethods(this); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getAllDeclaredMethods(null); + } + + @Override + public ICPPMethod[] getAllDeclaredMethods(IASTNode point) { + return ClassTypeHelper.getAllDeclaredMethods(this, point); } @Override public IField[] getFields() { - return ClassTypeHelper.getFields(this); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getFields(null); + } + + @Override + public IField[] getFields(IASTNode point) { + return ClassTypeHelper.getFields(this, point); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplateSpecialization.java index ccbdb499f7b..f370b1e8fc3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplateSpecialization.java @@ -158,7 +158,7 @@ class PDOMCPPClassTemplateSpecialization extends PDOMCPPClassSpecialization @Override public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() { - IASTNode point= null; // Instantiation of dependent expression may not work. + IASTNode point= null; // Instantiation of dependent expressions may not work. ICPPClassTemplate origTemplate= (ICPPClassTemplate) getSpecializedBinding(); ICPPClassTemplatePartialSpecialization[] orig = origTemplate.getPartialSpecializations(); ICPPClassTemplatePartialSpecialization[] spec = new ICPPClassTemplatePartialSpecialization[orig.length]; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java index f79a0c1f2f1..1ebf474b9ba 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java @@ -351,17 +351,17 @@ class PDOMCPPClassType extends PDOMCPPBinding implements IPDOMCPPClassType, IPDO @Override public ICPPMethod[] getMethods() { - return ClassTypeHelper.getMethods(this); + return ClassTypeHelper.getMethods(this, null); } @Override public ICPPMethod[] getAllDeclaredMethods() { - return ClassTypeHelper.getAllDeclaredMethods(this); + return ClassTypeHelper.getAllDeclaredMethods(this, null); } @Override public IField[] getFields() { - return ClassTypeHelper.getFields(this); + return ClassTypeHelper.getFields(this, null); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java index 946b8a9caac..1e15385117e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java @@ -14,7 +14,6 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp; import java.util.ArrayList; -import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -68,6 +67,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.index.IIndexBinding; +import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; @@ -82,6 +82,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerToMemberType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPReferenceType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance; @@ -252,7 +253,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { PDOMBinding pdomBinding = addBinding(binding, name); if (pdomBinding instanceof PDOMCPPClassType || pdomBinding instanceof PDOMCPPClassSpecialization) { if (binding instanceof ICPPClassType && name.isDefinition()) { - addImplicitMethods(pdomBinding, (ICPPClassType) binding); + addImplicitMethods(pdomBinding, (ICPPClassType) binding, name); } } @@ -299,7 +300,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { if (pdomBinding != null) { getPDOM().putCachedResult(inputBinding, pdomBinding); if (inputBinding instanceof CPPClosureType) { - addImplicitMethods(pdomBinding, (ICPPClassType) binding); + addImplicitMethods(pdomBinding, (ICPPClassType) binding, fromName); } } } catch (DOMException e) { @@ -490,17 +491,14 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { return result; } - private void addImplicitMethods(PDOMBinding type, ICPPClassType binding) throws CoreException { + private void addImplicitMethods(PDOMBinding type, ICPPClassType binding, IASTNode point) throws CoreException { try { final long fileLocalRec= type.getLocalToFileRec(); IScope scope = binding.getCompositeScope(); if (scope instanceof ICPPClassScope) { List old= new ArrayList(); if (type instanceof ICPPClassType) { - IScope oldScope = ((ICPPClassType)type).getCompositeScope(); - if (oldScope instanceof ICPPClassScope) { - old.addAll(Arrays.asList(((ICPPClassScope) oldScope).getImplicitMethods())); - } + ArrayUtil.addAll(old, ClassTypeHelper.getImplicitMethods((ICPPClassType) type, point)); } ICPPMethod[] implicit= ((ICPPClassScope) scope).getImplicitMethods(); for (ICPPMethod method : implicit) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java index df9d4578aa9..7360c7a1ff5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java @@ -253,7 +253,7 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod { @Override public IType[] getExceptionSpecification() { if (isImplicit()) { - return ClassTypeHelper.getInheritedExceptionSpecification(this); + return ClassTypeHelper.getInheritedExceptionSpecification(this, null); } return super.getExceptionSpecification(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java index 03dfa708e9d..1de4f84d7e5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java @@ -6,16 +6,18 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Bryan Wilkinson (QNX) - Initial API and implementation - * Markus Schorn (Wind River Systems) + * Bryan Wilkinson (QNX) - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethodSpecialization; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; @@ -30,8 +32,7 @@ import org.eclipse.core.runtime.CoreException; * Specialization of a method */ class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization - implements ICPPMethod { - + implements ICPPMethodSpecialization { /** * Offset of remaining annotation information (relative to the beginning of * the record). @@ -67,7 +68,7 @@ class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization public PDOMCPPMethodSpecialization(PDOMLinkage linkage, long bindingRecord) { super(linkage, bindingRecord); } - + @Override protected int getRecordSize() { return RECORD_SIZE; @@ -135,9 +136,9 @@ class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization } @Override - public IType[] getExceptionSpecification() { + public IType[] getExceptionSpecification(IASTNode point) { if (isImplicit()) { - return ClassTypeHelper.getInheritedExceptionSpecification(this); + return ClassTypeHelper.getInheritedExceptionSpecification(this, point); } return super.getExceptionSpecification(); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java index ecf68a72717..039319a9de5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java @@ -82,7 +82,7 @@ public class CHQueries { if (calleeBinding != null) { findCalledBy1(index, calleeBinding, true, project, result); if (calleeBinding instanceof ICPPMethod) { - IBinding[] overriddenBindings= ClassTypeHelper.findOverridden((ICPPMethod) calleeBinding); + IBinding[] overriddenBindings= ClassTypeHelper.findOverridden((ICPPMethod) calleeBinding, null); for (IBinding overriddenBinding : overriddenBindings) { findCalledBy1(index, overriddenBinding, false, project, result); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OverrideIndicatorManager.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OverrideIndicatorManager.java index 6aed8cca197..117fc21ec08 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OverrideIndicatorManager.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OverrideIndicatorManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Tomasz Wesolowski and others + * Copyright (c) 2010, 2012 Tomasz Wesolowski and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Tomasz Wesolowski - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.ui.editor; @@ -218,7 +219,6 @@ public class OverrideIndicatorManager implements ICReconcilingListener { private static OverrideInfo checkForOverride(ICPPMethod testedOverride, IASTNode node) throws DOMException { IASTFileLocation location = node.getFileLocation(); - testedOverride.getClassOwner().getBases(); boolean onlyPureVirtual = true; StringBuilder sb = new StringBuilder(); @@ -227,7 +227,7 @@ public class OverrideIndicatorManager implements ICReconcilingListener { Set alreadyTestedBases = new HashSet(); - ICPPBase[] bases = testedOverride.getClassOwner().getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases(testedOverride.getClassOwner(), node); // Don't override 'self' in cyclic inheritance alreadyTestedBases.add(testedOverride.getClassOwner()); @@ -244,7 +244,6 @@ public class OverrideIndicatorManager implements ICReconcilingListener { handleBaseClass(testedClass, testedOverride, overridenMethods, shadowedMethods, alreadyTestedBases); for (ICPPMethod overriddenMethod : overridenMethods) { - if (sb.length() > 0) { sb.append(MESSAGE_SEPARATOR); } @@ -289,8 +288,8 @@ public class OverrideIndicatorManager implements ICReconcilingListener { } if (sb.length() > 0) { - OverrideInfo info = new OverrideInfo(location.getNodeOffset(), location.getNodeLength(), markerType, - sb.toString(), bindingToOpen); + OverrideInfo info = new OverrideInfo(location.getNodeOffset(), location.getNodeLength(), + markerType, sb.toString(), bindingToOpen); return info; } return null; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameMethodProcessor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameMethodProcessor.java index fa58c0f1e39..2548a03142f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameMethodProcessor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameMethodProcessor.java @@ -31,7 +31,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; - /** * Rename processor for methods. */ @@ -108,7 +107,7 @@ public class CRenameMethodProcessor extends CRenameGlobalProcessor { if (binding instanceof ICPPMethod) { ICPPMethod m= (ICPPMethod) binding; try { - IBinding[] bs= ClassTypeHelper.findOverridden(m); + IBinding[] bs= ClassTypeHelper.findOverridden(m, argument.getTranslationUnit()); bindings.addAll(Arrays.asList(bs)); bs= ClassTypeHelper.findOverriders(getIndex(), m); bindings.addAll(Arrays.asList(bs)); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchQuery.java index c534bd7ea9d..62296c39645 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchQuery.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchQuery.java @@ -357,7 +357,8 @@ public abstract class CSearchQuery implements ISearchQuery { if (binding instanceof ICPPMethod) { ICPPMethod m= (ICPPMethod) binding; - ICPPMethod[] msInBases = ClassTypeHelper.findOverridden(m); + IASTNode point = null; // Instantiation of dependent expressions may not work. + ICPPMethod[] msInBases = ClassTypeHelper.findOverridden(m, point); if (msInBases.length > 0) { if (polymorphicNames == null) { polymorphicNames= new ArrayList(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LinkedNamesFinder.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LinkedNamesFinder.java index 0bbfe23e972..3de9c43fae1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LinkedNamesFinder.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LinkedNamesFinder.java @@ -99,7 +99,7 @@ public class LinkedNamesFinder { } } else if (target instanceof ICPPMethod) { ICPPMethod method= (ICPPMethod) target; - for (ICPPMethod m : ClassTypeHelper.findOverridden(method)) { + for (ICPPMethod m : ClassTypeHelper.findOverridden(method, root)) { findBinding(m); } try { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java index e225d62efcf..1fdb266723d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java @@ -36,6 +36,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IEnumeration; @@ -78,6 +79,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBuiltinVariable; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitMethod; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitTypedef; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.AccessContext; import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory; @@ -309,7 +311,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer if (binding instanceof ICPPClassType) { handleClass((ICPPClassType) binding, astContext, cContext, baseRelevance, proposals); } else if (binding instanceof IFunction) { - handleFunction((IFunction)binding, cContext, baseRelevance, proposals); + handleFunction((IFunction) binding, cContext, baseRelevance, proposals); } else if (binding instanceof IVariable) { handleVariable((IVariable) binding, cContext, baseRelevance, proposals); } else if (!cContext.isContextInformationStyle()) { @@ -466,7 +468,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer t= unwindTypedefs(t); if (t instanceof ICPPClassType) { ICPPClassType classType= (ICPPClassType) t; - ICPPConstructor[] constructors = classType.getConstructors(); + IASTTranslationUnit ast = context.getCompletionNode().getTranslationUnit(); + ICPPConstructor[] constructors = ClassTypeHelper.getConstructors(classType, ast); for (ICPPConstructor constructor : constructors) { handleFunction(constructor, context, baseRelevance, proposals); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java index 528fd655cde..8f8bd310991 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java @@ -511,7 +511,7 @@ public class IndexUI { // Check for specializations of the owner IBinding owner = binding.getOwner(); if (owner != null) { - IASTNode point= null; // Instantiation of dependent expression may not work. + IASTNode point= null; // Instantiation of dependent expressions may not work. for (IBinding specOwner : findSpecializations(index, owner)) { if (specOwner instanceof ICPPClassSpecialization) { // Add the specialized member