1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 299911. Added logging of methods that loose template instantiation

context.
This commit is contained in:
Sergey Prigogin 2012-08-08 17:38:17 -07:00
parent dd039973ae
commit f122365484
45 changed files with 577 additions and 365 deletions

View file

@ -188,7 +188,7 @@ public class AbstractClassInstantiationChecker extends AbstractIndexAstChecker {
* Checks whether specified type (class or typedef to the class) is an abstract class. * Checks whether specified type (class or typedef to the class) is an abstract class.
* If it is, reports violations on each pure virtual method * 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); IType unwindedType = CxxAstUtils.unwindTypedef(typeToCheck);
if (!(unwindedType instanceof ICPPClassType) || unwindedType instanceof IProblemBinding) { if (!(unwindedType instanceof ICPPClassType) || unwindedType instanceof IProblemBinding) {
return; return;
@ -196,7 +196,7 @@ public class AbstractClassInstantiationChecker extends AbstractIndexAstChecker {
ICPPClassType classType = (ICPPClassType) unwindedType; ICPPClassType classType = (ICPPClassType) unwindedType;
ICPPMethod[] pureVirtualMethods = pureVirtualMethodsCache.get(classType); ICPPMethod[] pureVirtualMethods = pureVirtualMethodsCache.get(classType);
if (pureVirtualMethods == null) { if (pureVirtualMethods == null) {
pureVirtualMethods = ClassTypeHelper.getPureVirtualMethods(classType); pureVirtualMethods = ClassTypeHelper.getPureVirtualMethods(classType, problemNode);
pureVirtualMethodsCache.put(classType, pureVirtualMethods); pureVirtualMethodsCache.put(classType, pureVirtualMethods);
} }

View file

@ -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.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; 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; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
/** /**
@ -46,8 +47,8 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
ast.accept(new OnEachClass()); ast.accept(new OnEachClass());
} }
private static ICPPMethod getDestructor(ICPPClassType classType) { private static ICPPMethod getDestructor(ICPPClassType classType, IASTNode point) {
for (ICPPMethod method : classType.getDeclaredMethods()) { for (ICPPMethod method : ClassTypeHelper.getDeclaredMethods(classType, point)) {
if (method.isDestructor()) { if (method.isDestructor()) {
return method; return method;
} }
@ -55,18 +56,18 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
return null; return null;
} }
private static boolean hasVirtualDestructor(ICPPClassType classType) { private static boolean hasVirtualDestructor(ICPPClassType classType, IASTNode point) {
checkedClassTypes.add(classType); checkedClassTypes.add(classType);
ICPPMethod destructor = getDestructor(classType); ICPPMethod destructor = getDestructor(classType, point);
if (destructor != null && destructor.isVirtual()) { if (destructor != null && destructor.isVirtual()) {
return true; return true;
} }
ICPPBase[] bases = classType.getBases(); ICPPBase[] bases = ClassTypeHelper.getBases(classType, point);
for (ICPPBase base : bases) { for (ICPPBase base : bases) {
IBinding baseClass = base.getBaseClass(); IBinding baseClass = base.getBaseClass();
if (baseClass instanceof ICPPClassType) { if (baseClass instanceof ICPPClassType) {
ICPPClassType cppClassType = (ICPPClassType) baseClass; ICPPClassType cppClassType = (ICPPClassType) baseClass;
if (!checkedClassTypes.contains(cppClassType) && hasVirtualDestructor(cppClassType)) { if (!checkedClassTypes.contains(cppClassType) && hasVirtualDestructor(cppClassType, point)) {
return true; return true;
} }
} }
@ -89,13 +90,13 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
return PROCESS_SKIP; return PROCESS_SKIP;
} }
ICPPClassType classType = (ICPPClassType) binding; ICPPClassType classType = (ICPPClassType) binding;
boolean hasVirtualDestructor = hasVirtualDestructor(classType); boolean hasVirtualDestructor = hasVirtualDestructor(classType, className);
checkedClassTypes.clear(); checkedClassTypes.clear();
if (hasVirtualDestructor) { if (hasVirtualDestructor) {
return PROCESS_SKIP; return PROCESS_SKIP;
} }
ICPPMethod virtualMethod = null; ICPPMethod virtualMethod = null;
for (ICPPMethod method : classType.getAllDeclaredMethods()) { for (ICPPMethod method : ClassTypeHelper.getAllDeclaredMethods(classType, className)) {
if (!method.isDestructor() && method.isVirtual()) { if (!method.isDestructor() && method.isVirtual()) {
virtualMethod = method; virtualMethod = method;
} }
@ -103,7 +104,7 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
if (virtualMethod == null) { if (virtualMethod == null) {
return PROCESS_SKIP; return PROCESS_SKIP;
} }
ICPPMethod destructor = getDestructor(classType); ICPPMethod destructor = getDestructor(classType, className);
if (destructor != null && if (destructor != null &&
destructor.getVisibility() != ICPPASTVisibilityLabel.v_public && destructor.getVisibility() != ICPPASTVisibilityLabel.v_public &&
classType.getFriends().length == 0) { classType.getFriends().length == 0) {

View file

@ -6252,20 +6252,20 @@ public class AST2CPPTests extends AST2BaseTest {
assertFalse(ClassTypeHelper.isOverrider(m5, m2)); assertFalse(ClassTypeHelper.isOverrider(m5, m2));
assertTrue(ClassTypeHelper.isOverrider(m4, m2)); assertTrue(ClassTypeHelper.isOverrider(m4, m2));
ICPPMethod[] ors= ClassTypeHelper.findOverridden(m0); ICPPMethod[] ors= ClassTypeHelper.findOverridden(m0, null);
assertEquals(0, ors.length); assertEquals(0, ors.length);
ors= ClassTypeHelper.findOverridden(m1); ors= ClassTypeHelper.findOverridden(m1, null);
assertEquals(0, ors.length); assertEquals(0, ors.length);
ors= ClassTypeHelper.findOverridden(m2); ors= ClassTypeHelper.findOverridden(m2, null);
assertEquals(1, ors.length); assertEquals(1, ors.length);
assertSame(ors[0], m1); assertSame(ors[0], m1);
ors= ClassTypeHelper.findOverridden(m3); ors= ClassTypeHelper.findOverridden(m3, null);
assertEquals(0, ors.length); assertEquals(0, ors.length);
ors= ClassTypeHelper.findOverridden(m4); ors= ClassTypeHelper.findOverridden(m4, null);
assertEquals(2, ors.length); assertEquals(2, ors.length);
assertSame(ors[0], m2); assertSame(ors[0], m2);
assertSame(ors[1], m1); assertSame(ors[1], m1);
ors= ClassTypeHelper.findOverridden(m5); ors= ClassTypeHelper.findOverridden(m5, null);
assertEquals(1, ors.length); assertEquals(1, ors.length);
assertSame(ors[0], m1); assertSame(ors[0], m1);
} }
@ -8732,14 +8732,14 @@ public class AST2CPPTests extends AST2BaseTest {
assertFalse(ClassTypeHelper.isOverrider(m3, m0)); assertFalse(ClassTypeHelper.isOverrider(m3, m0));
assertFalse(ClassTypeHelper.isOverrider(m3, m1)); assertFalse(ClassTypeHelper.isOverrider(m3, m1));
ICPPMethod[] ors= ClassTypeHelper.findOverridden(m0); ICPPMethod[] ors= ClassTypeHelper.findOverridden(m0, null);
assertEquals(0, ors.length); assertEquals(0, ors.length);
ors= ClassTypeHelper.findOverridden(m1); ors= ClassTypeHelper.findOverridden(m1, null);
assertEquals(0, ors.length); assertEquals(0, ors.length);
ors= ClassTypeHelper.findOverridden(m2); ors= ClassTypeHelper.findOverridden(m2, null);
assertEquals(1, ors.length); assertEquals(1, ors.length);
assertSame(ors[0], m0); assertSame(ors[0], m0);
ors= ClassTypeHelper.findOverridden(m3); ors= ClassTypeHelper.findOverridden(m3, null);
assertEquals(0, ors.length); assertEquals(0, ors.length);
} }
@ -9546,7 +9546,7 @@ public class AST2CPPTests extends AST2BaseTest {
public void testRecursiveClassInheritance_Bug357256() throws Exception { public void testRecursiveClassInheritance_Bug357256() throws Exception {
BindingAssertionHelper bh= getAssertionHelper(); BindingAssertionHelper bh= getAssertionHelper();
ICPPClassType c= bh.assertNonProblem("A", 1); ICPPClassType c= bh.assertNonProblem("A", 1);
assertEquals(0, ClassTypeHelper.getPureVirtualMethods(c).length); assertEquals(0, ClassTypeHelper.getPureVirtualMethods(c, null).length);
} }
// template <typename T> struct CT1 {}; // template <typename T> struct CT1 {};

View file

@ -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.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.Value; 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.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.ICPPDeferredClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
@ -1907,7 +1908,7 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPClassType B = (ICPPClassType) col.getName(3).resolveBinding(); ICPPClassType B = (ICPPClassType) col.getName(3).resolveBinding();
ICPPClassType A = (ICPPClassType) col.getName(6).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(6).resolveBinding();
ICPPBase[] bases = A.getBases(); ICPPBase[] bases = ClassTypeHelper.getBases(A, tu);
assertEquals(bases.length, 1); assertEquals(bases.length, 1);
assertSame(bases[0].getBaseClass(), B); assertSame(bases[0].getBaseClass(), B);
} }
@ -4368,19 +4369,19 @@ public class AST2TemplateTests extends AST2BaseTest {
BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP);
ICPPClassType type= bh.assertNonProblem("X<int&>", 7); ICPPClassType type= bh.assertNonProblem("X<int&>", 7);
ICPPMethod[] ms= type.getMethods(); ICPPMethod[] ms= ClassTypeHelper.getMethods(type, null);
int i= ms[0].getName().equals("f") ? 0 : 1; int i= ms[0].getName().equals("f") ? 0 : 1;
ICPPMethod m= ms[i]; ICPPMethod m= ms[i];
assertEquals("int &", ASTTypeUtil.getType(m.getType().getParameterTypes()[0])); assertEquals("int &", ASTTypeUtil.getType(m.getType().getParameterTypes()[0]));
m= ms[1-i]; m= ms[1 - i];
assertEquals("int &", ASTTypeUtil.getType(m.getType().getParameterTypes()[0])); assertEquals("int &", ASTTypeUtil.getType(m.getType().getParameterTypes()[0]));
type= bh.assertNonProblem("X<const int&&>", 14); type= bh.assertNonProblem("X<const int&&>", 14);
ms= type.getMethods(); ms= ClassTypeHelper.getMethods(type, null);
i= ms[0].getName().equals("f") ? 0 : 1; i= ms[0].getName().equals("f") ? 0 : 1;
m= ms[i]; m= ms[i];
assertEquals("const int &", ASTTypeUtil.getType(m.getType().getParameterTypes()[0])); 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])); assertEquals("const int &&", ASTTypeUtil.getType(m.getType().getParameterTypes()[0]));
} }

View file

@ -56,7 +56,9 @@ import org.eclipse.cdt.core.index.IIndexMacro;
import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.parser.util.ObjectMap; 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.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.ICPPInstanceCache;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
import org.eclipse.core.runtime.CoreException; 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)}); ICPPSpecialization inst= ct.getInstance(new ICPPTemplateArgument[]{new CPPTemplateTypeArgument((IType)b0)});
assertInstance(inst, ICPPClassType.class); assertInstance(inst, ICPPClassType.class);
ICPPClassType c2t= (ICPPClassType) inst; ICPPClassType c2t= (ICPPClassType) inst;
ICPPBase[] bases= c2t.getBases(); ICPPBase[] bases= ClassTypeHelper.getBases(c2t, null);
assertEquals(1, bases.length); assertEquals(1, bases.length);
assertInstance(bases[0].getBaseClass(), ICPPClassType.class); assertInstance(bases[0].getBaseClass(), ICPPClassType.class);
} }
@ -998,74 +1000,74 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas
// class template instance // class template instance
ct= getBindingFromASTName("CT<int>", 7); ct= getBindingFromASTName("CT<int>", 7);
assertInstance(ct, ICPPTemplateInstance.class); assertInstance(ct, ICPPTemplateInstance.class);
assertBindings(new String[] {"B"}, ct.getBases()); assertBindings(new String[] {"B"}, ClassTypeHelper.getBases(ct, null));
assertBindings(new String[] {"n", "m", "B", "CT"}, ct.getAllDeclaredMethods()); assertBindings(new String[] {"n", "m", "B", "CT"}, ClassTypeHelper.getAllDeclaredMethods(ct, null));
assertBindings(new String[] {"CT", "CT"}, ct.getConstructors()); assertBindings(new String[] {"CT", "CT"}, ClassTypeHelper.getConstructors(ct, null));
assertBindings(new String[] {"g"}, ct.getDeclaredFields()); assertBindings(new String[] {"g"}, ClassTypeHelper.getDeclaredFields(ct, null));
assertBindings(new String[] {"n", "CT"}, ct.getDeclaredMethods()); assertBindings(new String[] {"n", "CT"}, ClassTypeHelper.getDeclaredMethods(ct, null));
assertBindings(new String[] {"f", "g"}, ct.getFields()); assertBindings(new String[] {"f", "g"}, ClassTypeHelper.getFields(ct, null));
assertBindings(new String[] {"m", "n", "CT", "CT", "~CT", "B", "B", "~B", "operator =", "operator ="}, ct.getMethods()); assertBindings(new String[] {"m", "n", "CT", "CT", "~CT", "B", "B", "~B", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null));
assertBindings(new String[] {"O"}, ct.getNestedClasses()); assertBindings(new String[] {"O"}, ClassTypeHelper.getNestedClasses(ct, null));
// explicit class template instance // explicit class template instance
ct= getBindingFromASTName("CT<char>", 8); ct= getBindingFromASTName("CT<char>", 8);
assertInstance(ct, ICPPTemplateInstance.class); assertInstance(ct, ICPPTemplateInstance.class);
assertBindings(new String[] {"A"}, ct.getBases()); assertBindings(new String[] {"A"}, ClassTypeHelper.getBases(ct, null));
assertBindings(new String[] {"o", "l", "A", "CT", "CT"}, ct.getAllDeclaredMethods()); assertBindings(new String[] {"o", "l", "A", "CT", "CT"}, ClassTypeHelper.getAllDeclaredMethods(ct, null));
assertBindings(new String[] {"CT", "CT", "CT"}, ct.getConstructors()); assertBindings(new String[] {"CT", "CT", "CT"}, ClassTypeHelper.getConstructors(ct, null));
assertBindings(new String[] {"h"}, ct.getDeclaredFields()); assertBindings(new String[] {"h"}, ClassTypeHelper.getDeclaredFields(ct, null));
assertBindings(new String[] {"o", "CT", "CT"}, ct.getDeclaredMethods()); assertBindings(new String[] {"o", "CT", "CT"}, ClassTypeHelper.getDeclaredMethods(ct, null));
assertBindings(new String[] {"e", "h"}, ct.getFields()); assertBindings(new String[] {"e", "h"}, ClassTypeHelper.getFields(ct, null));
assertBindings(new String[] {"l", "o", "CT", "CT", "CT", "~CT", "A", "A", "~A", "operator =", "operator ="}, ct.getMethods()); assertBindings(new String[] {"l", "o", "CT", "CT", "CT", "~CT", "A", "A", "~A", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null));
assertBindings(new String[] {"P"}, ct.getNestedClasses()); assertBindings(new String[] {"P"}, ClassTypeHelper.getNestedClasses(ct, null));
// class specialization // class specialization
ct= getBindingFromASTName("C spec", 1); ct= getBindingFromASTName("C spec", 1);
assertInstance(ct, ICPPClassSpecialization.class); assertInstance(ct, ICPPClassSpecialization.class);
assertBindings(new String[] {"B"}, ct.getBases()); assertBindings(new String[] {"B"}, ClassTypeHelper.getBases(ct, null));
assertBindings(new String[] {"n", "m", "B", "C"}, ct.getAllDeclaredMethods()); assertBindings(new String[] {"n", "m", "B", "C"}, ClassTypeHelper.getAllDeclaredMethods(ct, null));
assertBindings(new String[] {"C", "C"}, ct.getConstructors()); assertBindings(new String[] {"C", "C"}, ClassTypeHelper.getConstructors(ct, null));
assertBindings(new String[] {"g"}, ct.getDeclaredFields()); assertBindings(new String[] {"g"}, ClassTypeHelper.getDeclaredFields(ct, null));
assertBindings(new String[] {"n", "C"}, ct.getDeclaredMethods()); assertBindings(new String[] {"n", "C"}, ClassTypeHelper.getDeclaredMethods(ct, null));
assertBindings(new String[] {"f", "g"}, ct.getFields()); assertBindings(new String[] {"f", "g"}, ClassTypeHelper.getFields(ct, null));
assertBindings(new String[] {"m", "n", "C", "C", "~C", "B", "B", "~B", "operator =", "operator ="}, ct.getMethods()); assertBindings(new String[] {"m", "n", "C", "C", "~C", "B", "B", "~B", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null));
assertBindings(new String[] {"O"}, ct.getNestedClasses()); assertBindings(new String[] {"O"}, ClassTypeHelper.getNestedClasses(ct, null));
// class template specialization // class template specialization
ct= getBindingFromASTName("CT<int> spect", 2); ct= getBindingFromASTName("CT<int> spect", 2);
assertInstance(ct, ICPPClassTemplate.class, ICPPClassSpecialization.class); assertInstance(ct, ICPPClassTemplate.class, ICPPClassSpecialization.class);
assertBindings(new String[] {"B"}, ct.getBases()); assertBindings(new String[] {"B"}, ClassTypeHelper.getBases(ct, null));
assertBindings(new String[] {"n", "m", "B", "CT"}, ct.getAllDeclaredMethods()); assertBindings(new String[] {"n", "m", "B", "CT"}, ClassTypeHelper.getAllDeclaredMethods(ct, null));
assertBindings(new String[] {"CT", "CT"}, ct.getConstructors()); assertBindings(new String[] {"CT", "CT"}, ClassTypeHelper.getConstructors(ct, null));
assertBindings(new String[] {"g"}, ct.getDeclaredFields()); assertBindings(new String[] {"g"}, ClassTypeHelper.getDeclaredFields(ct, null));
assertBindings(new String[] {"n", "CT"}, ct.getDeclaredMethods()); assertBindings(new String[] {"n", "CT"}, ClassTypeHelper.getDeclaredMethods(ct, null));
assertBindings(new String[] {"f", "g"}, ct.getFields()); assertBindings(new String[] {"f", "g"}, ClassTypeHelper.getFields(ct, null));
assertBindings(new String[] {"m", "n", "CT", "CT", "~CT", "B", "B", "~B", "operator =", "operator ="}, ct.getMethods()); assertBindings(new String[] {"m", "n", "CT", "CT", "~CT", "B", "B", "~B", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null));
assertBindings(new String[] {"O"}, ct.getNestedClasses()); assertBindings(new String[] {"O"}, ClassTypeHelper.getNestedClasses(ct, null));
// explicit class specialization // explicit class specialization
ct= getBindingFromASTName("C espec", 1); ct= getBindingFromASTName("C espec", 1);
assertInstance(ct, ICPPClassSpecialization.class); assertInstance(ct, ICPPClassSpecialization.class);
assertBindings(new String[] {"A"}, ct.getBases()); assertBindings(new String[] {"A"}, ClassTypeHelper.getBases(ct, null));
assertBindings(new String[] {"o", "l", "A", "C", "C"}, ct.getAllDeclaredMethods()); assertBindings(new String[] {"o", "l", "A", "C", "C"}, ClassTypeHelper.getAllDeclaredMethods(ct, null));
assertBindings(new String[] {"C", "C", "C"}, ct.getConstructors()); assertBindings(new String[] {"C", "C", "C"}, ClassTypeHelper.getConstructors(ct, null));
assertBindings(new String[] {"h"}, ct.getDeclaredFields()); assertBindings(new String[] {"h"}, ClassTypeHelper.getDeclaredFields(ct, null));
assertBindings(new String[] {"o", "C", "C"}, ct.getDeclaredMethods()); assertBindings(new String[] {"o", "C", "C"}, ClassTypeHelper.getDeclaredMethods(ct, null));
assertBindings(new String[] {"e", "h"}, ct.getFields()); assertBindings(new String[] {"e", "h"}, ClassTypeHelper.getFields(ct, null));
assertBindings(new String[] {"l", "o", "C", "C", "C", "~C", "A", "A", "~A", "operator =", "operator ="}, ct.getMethods()); assertBindings(new String[] {"l", "o", "C", "C", "C", "~C", "A", "A", "~A", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null));
assertBindings(new String[] {"P"}, ct.getNestedClasses()); assertBindings(new String[] {"P"}, ClassTypeHelper.getNestedClasses(ct, null));
// explicit class template specialization // explicit class template specialization
ct= getBindingFromASTName("CT<int> espect", 7); ct= getBindingFromASTName("CT<int> espect", 7);
assertInstance(ct, ICPPTemplateInstance.class); assertInstance(ct, ICPPTemplateInstance.class);
assertBindings(new String[] {"A"}, ct.getBases()); assertBindings(new String[] {"A"}, ClassTypeHelper.getBases(ct, null));
assertBindings(new String[] {"o", "l", "A", "CT", "CT"}, ct.getAllDeclaredMethods()); assertBindings(new String[] {"o", "l", "A", "CT", "CT"}, ClassTypeHelper.getAllDeclaredMethods(ct, null));
assertBindings(new String[] {"CT", "CT", "CT"}, ct.getConstructors()); assertBindings(new String[] {"CT", "CT", "CT"}, ClassTypeHelper.getConstructors(ct, null));
assertBindings(new String[] {"h"}, ct.getDeclaredFields()); assertBindings(new String[] {"h"}, ClassTypeHelper.getDeclaredFields(ct, null));
assertBindings(new String[] {"o", "CT", "CT"}, ct.getDeclaredMethods()); assertBindings(new String[] {"o", "CT", "CT"}, ClassTypeHelper.getDeclaredMethods(ct, null));
assertBindings(new String[] {"e", "h"}, ct.getFields()); assertBindings(new String[] {"e", "h"}, ClassTypeHelper.getFields(ct, null));
assertBindings(new String[] {"l", "o", "CT", "CT", "CT", "~CT", "A", "A", "~A", "operator =", "operator ="}, ct.getMethods()); assertBindings(new String[] {"l", "o", "CT", "CT", "CT", "~CT", "A", "A", "~A", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null));
assertBindings(new String[] {"P"}, ct.getNestedClasses()); assertBindings(new String[] {"P"}, ClassTypeHelper.getNestedClasses(ct, null));
} }
// void func(const int* x) {} // void func(const int* x) {}

View file

@ -10,6 +10,7 @@
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.index.tests; package org.eclipse.cdt.internal.index.tests;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; 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.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.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; 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.dom.parser.cpp.semantics.SemanticUtil;
import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/** /**
* Tests for exercising resolution of template bindings against IIndex * Tests for exercising resolution of template bindings against IIndex
*/ */
@ -629,7 +630,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
assertInstance(b2, ICPPClassType.class); assertInstance(b2, ICPPClassType.class);
assertInstance(b2, ICPPTemplateInstance.class); assertInstance(b2, ICPPTemplateInstance.class);
ICPPClassType ct2= (ICPPClassType) b2; ICPPClassType ct2= (ICPPClassType) b2;
ICPPBase[] bss2= ct2.getBases(); ICPPBase[] bss2= ClassTypeHelper.getBases(ct2, null);
assertEquals(1, bss2.length); assertEquals(1, bss2.length);
assertInstance(bss2[0].getBaseClass(), ICPPClassType.class); assertInstance(bss2[0].getBaseClass(), ICPPClassType.class);
ICPPClassType ct2b= (ICPPClassType) bss2[0].getBaseClass(); ICPPClassType ct2b= (ICPPClassType) bss2[0].getBaseClass();
@ -638,14 +639,14 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
IBinding b0= getBindingFromASTName("B<int>", 6); IBinding b0= getBindingFromASTName("B<int>", 6);
assertInstance(b0, ICPPClassType.class); assertInstance(b0, ICPPClassType.class);
ICPPClassType ct= (ICPPClassType) b0; ICPPClassType ct= (ICPPClassType) b0;
ICPPBase[] bss= ct.getBases(); ICPPBase[] bss= ClassTypeHelper.getBases(ct, null);
assertEquals(1, bss.length); assertEquals(1, bss.length);
assertInstance(bss[0].getBaseClass(), ICPPClassType.class); assertInstance(bss[0].getBaseClass(), ICPPClassType.class);
IBinding b1= getBindingFromASTName("B<long>", 7); IBinding b1= getBindingFromASTName("B<long>", 7);
assertInstance(b1, ICPPClassType.class); assertInstance(b1, ICPPClassType.class);
ICPPClassType ct1= (ICPPClassType) b1; ICPPClassType ct1= (ICPPClassType) b1;
ICPPBase[] bss1= ct1.getBases(); ICPPBase[] bss1= ClassTypeHelper.getBases(ct1, null);
assertEquals(1, bss1.length); assertEquals(1, bss1.length);
assertInstance(bss1[0].getBaseClass(), ICPPClassType.class); assertInstance(bss1[0].getBaseClass(), ICPPClassType.class);
} }
@ -674,11 +675,11 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
assertInstance(b0, ICPPSpecialization.class); assertInstance(b0, ICPPSpecialization.class);
ICPPClassType ct= (ICPPClassType) b0; ICPPClassType ct= (ICPPClassType) b0;
ICPPMethod[] dms= ct.getDeclaredMethods(); ICPPMethod[] dms= ClassTypeHelper.getDeclaredMethods(ct, null);
assertEquals(2, dms.length); assertEquals(2, dms.length);
// if the specialization was used, we have 2 fields. // if the specialization was used, we have 2 fields.
ICPPField[] fs= ct.getDeclaredFields(); ICPPField[] fs= ClassTypeHelper.getDeclaredFields(ct, null);
assertEquals(2, fs.length); assertEquals(2, fs.length);
ICPPMethod foo= dms[0].getName().equals("foo") ? dms[0] : dms[1]; ICPPMethod foo= dms[0].getName().equals("foo") ? dms[0] : dms[1];
@ -1574,7 +1575,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
assertInstance(m, ICPPSpecialization.class); assertInstance(m, ICPPSpecialization.class);
ICPPClassType ct= m.getClassOwner(); ICPPClassType ct= m.getClassOwner();
assertInstance(ct, ICPPTemplateInstance.class); assertInstance(ct, ICPPTemplateInstance.class);
ICPPMethod[] ms= ct.getDeclaredMethods(); ICPPMethod[] ms= ClassTypeHelper.getDeclaredMethods(ct, null);
assertEquals(1, ms.length); assertEquals(1, ms.length);
assertEquals(m, ms[0]); assertEquals(m, ms[0]);
} }
@ -1849,16 +1850,16 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
methods= ct.getMethods(); methods= ct.getMethods();
assertEquals(14, methods.length); assertEquals(14, methods.length);
ICPPBase[] bases = ct.getBases(); ICPPBase[] bases = ClassTypeHelper.getBases(ct, null);
assertEquals(1, bases.length); assertEquals(1, bases.length);
IField field = ct.findField("bfield"); IField field = ct.findField("bfield");
assertNotNull(field); assertNotNull(field);
IField[] fields = ct.getFields(); IField[] fields = ClassTypeHelper.getFields(ct, null);
assertEquals(2, fields.length); assertEquals(2, fields.length);
IBinding[] friends = ct.getFriends(); IBinding[] friends = ClassTypeHelper.getFriends(ct, null);
assertEquals(0, friends.length); // not yet supported assertEquals(0, friends.length); // not yet supported
} }

View file

@ -18,6 +18,7 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding; 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.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IType; 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.CTestPlugin;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.cdt.internal.core.CCoreInternals; 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.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
@ -237,9 +239,10 @@ public class CPPClassTemplateTests extends PDOMTestBase {
ICPPVariable var= (ICPPVariable) bs[0]; ICPPVariable var= (ICPPVariable) bs[0];
assertInstance(var.getType(), ICPPClassType.class); assertInstance(var.getType(), ICPPClassType.class);
ICPPClassType ct= (ICPPClassType) var.getType(); ICPPClassType ct= (ICPPClassType) var.getType();
assertEquals(1, ct.getFields().length); IField[] fields = ClassTypeHelper.getFields(ct, null);
assertInstance(ct.getFields()[0].getType(), IPointerType.class); assertEquals(1, fields.length);
IPointerType pt= (IPointerType) ct.getFields()[0].getType(); assertInstance(fields[0].getType(), IPointerType.class);
IPointerType pt= (IPointerType) fields[0].getType();
assertInstance(pt.getType(), IFunctionType.class); assertInstance(pt.getType(), IFunctionType.class);
IFunctionType ft= (IFunctionType) pt.getType(); IFunctionType ft= (IFunctionType) pt.getType();
assertInstance(ft.getReturnType(), ICPPClassType.class); assertInstance(ft.getReturnType(), ICPPClassType.class);

View file

@ -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.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IField;
/** /**
* Specializations of all sorts of class types. * Specializations of all sorts of class types.
@ -59,6 +60,20 @@ public interface ICPPClassSpecialization extends ICPPSpecialization, ICPPClassTy
*/ */
ICPPField[] getDeclaredFields(IASTNode point); 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 * Similar to {@link ICPPClassType#getDeclaredMethods()} but a accepts a starting point
* for template instantiation. * for template instantiation.
@ -73,6 +88,13 @@ public interface ICPPClassSpecialization extends ICPPSpecialization, ICPPClassTy
*/ */
IBinding[] getFriends(IASTNode point); 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 * Similar to {@link ICPPClassType#getNestedClasses()} but a accepts a starting point
* for template instantiation. * for template instantiation.

View file

@ -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);
}

View file

@ -49,6 +49,8 @@ public class SizeofCalculator {
} }
} }
private static final SizeofCalculator defaultInstance = new SizeofCalculator();
private static final SizeAndAlignment SIZE_1 = new SizeAndAlignment(1, 1); private static final SizeAndAlignment SIZE_1 = new SizeAndAlignment(1, 1);
public final SizeAndAlignment size_2; public final SizeAndAlignment size_2;
@ -68,6 +70,15 @@ public class SizeofCalculator {
public final SizeAndAlignment sizeof_long_double; public final SizeAndAlignment sizeof_long_double;
public final SizeAndAlignment sizeof_complex_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) { public SizeofCalculator(IASTTranslationUnit ast) {
int maxAlignment = 32; int maxAlignment = 32;
Map<String, String> sizeofMacros = new HashMap<String, String>(); Map<String, String> sizeofMacros = new HashMap<String, String>();
@ -103,6 +114,25 @@ public class SizeofCalculator {
sizeof_complex_long_double = getSizeOfPair(sizeof_long_double); 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. * Calculates size and alignment for the given type.
* @param type the type to get size and alignment for. * @param type the type to get size and alignment for.

View file

@ -14,6 +14,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; 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.IName;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.EScopeKind;
@ -128,7 +129,7 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat
public ICPPBase[] getBases(IASTNode point) { public ICPPBase[] getBases(IASTNode point) {
if (fBases == null) { if (fBases == null) {
ICPPBase[] result = null; ICPPBase[] result = null;
ICPPBase[] bases = specialClass.getSpecializedBinding().getBases(); ICPPBase[] bases = ClassTypeHelper.getBases(specialClass.getSpecializedBinding(), point);
if (bases.length == 0) { if (bases.length == 0) {
fBases= bases; fBases= bases;
} else { } else {
@ -136,7 +137,8 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat
for (ICPPBase base : bases) { for (ICPPBase base : bases) {
IBinding origClass = base.getBaseClass(); IBinding origClass = base.getBaseClass();
if (origClass instanceof ICPPTemplateParameter && ((ICPPTemplateParameter) origClass).isParameterPack()) { 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) { if (specClasses.length == 1 && specClasses[0] instanceof ICPPParameterPackType) {
result= ArrayUtil.append(ICPPBase.class, result, base); result= ArrayUtil.append(ICPPBase.class, result, base);
} else { } else {
@ -183,13 +185,14 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat
@Override @Override
public ICPPField[] getDeclaredFields(IASTNode point) { public ICPPField[] getDeclaredFields(IASTNode point) {
ICPPField[] fields= specialClass.getSpecializedBinding().getDeclaredFields(); ICPPField[] fields= ClassTypeHelper.getDeclaredFields(specialClass.getSpecializedBinding(), point);
return specializeMembers(fields, point); return specializeMembers(fields, point);
} }
@Override @Override
public ICPPMethod[] getImplicitMethods() { 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 @Override
@ -211,30 +214,31 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat
@Override @Override
public ICPPConstructor[] getConstructors() { 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 @Override
public ICPPConstructor[] getConstructors(IASTNode point) { public ICPPConstructor[] getConstructors(IASTNode point) {
ICPPConstructor[] ctors= specialClass.getSpecializedBinding().getConstructors(); ICPPConstructor[] ctors= ClassTypeHelper.getConstructors(specialClass.getSpecializedBinding(), point);
return specializeMembers(ctors, point); return specializeMembers(ctors, point);
} }
@Override @Override
public ICPPMethod[] getDeclaredMethods(IASTNode point) { public ICPPMethod[] getDeclaredMethods(IASTNode point) {
ICPPMethod[] bindings = specialClass.getSpecializedBinding().getDeclaredMethods(); ICPPMethod[] bindings = ClassTypeHelper.getDeclaredMethods(specialClass.getSpecializedBinding(), point);
return specializeMembers(bindings, point); return specializeMembers(bindings, point);
} }
@Override @Override
public ICPPClassType[] getNestedClasses(IASTNode point) { public ICPPClassType[] getNestedClasses(IASTNode point) {
ICPPClassType[] bindings = specialClass.getSpecializedBinding().getNestedClasses(); ICPPClassType[] bindings = ClassTypeHelper.getNestedClasses(specialClass.getSpecializedBinding(), point);
return specializeMembers(bindings, point); return specializeMembers(bindings, point);
} }
@Override @Override
public IBinding[] getFriends(IASTNode point) { public IBinding[] getFriends(IASTNode point) {
IBinding[] friends = specialClass.getSpecializedBinding().getFriends(); IBinding[] friends = ClassTypeHelper.getFriends(specialClass.getSpecializedBinding(), point);
return specializeMembers(friends, point); return specializeMembers(friends, point);
} }

View file

@ -175,7 +175,7 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements
IBinding method= fdef.getDeclarator().getName().resolveBinding(); IBinding method= fdef.getDeclarator().getName().resolveBinding();
if (method instanceof ICPPMethod) { if (method instanceof ICPPMethod) {
ICPPClassType cls= ((ICPPMethod) method).getClassOwner(); ICPPClassType cls= ((ICPPMethod) method).getClassOwner();
for (ICPPBase base : SemanticUtil.getBases(cls, fdef)) { for (ICPPBase base : ClassTypeHelper.getBases(cls, fdef)) {
result.put(base.getBaseClassSpecifierName().getSimpleID()); result.put(base.getBaseClassSpecifierName().getSimpleID());
} }
return result; return result;

View file

@ -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.EvalFunctionCall;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalTypeId; 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.LookupData;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
public class CPPASTFunctionCallExpression extends ASTNode public class CPPASTFunctionCallExpression extends ASTNode
implements ICPPASTFunctionCallExpression, IASTAmbiguityParent { implements ICPPASTFunctionCallExpression, IASTAmbiguityParent {
@ -270,7 +271,7 @@ public class CPPASTFunctionCallExpression extends ASTNode
ICPPClassType cls= (ICPPClassType) t; ICPPClassType cls= (ICPPClassType) t;
LookupData data= CPPSemantics.createLookupData(((IASTIdExpression) functionName).getName()); LookupData data= CPPSemantics.createLookupData(((IASTIdExpression) functionName).getName());
try { try {
IBinding b= CPPSemantics.resolveFunction(data, cls.getConstructors(), true); IBinding b= CPPSemantics.resolveFunction(data, ClassTypeHelper.getConstructors(cls, data.getLookupPoint()), true);
if (b instanceof ICPPFunction) if (b instanceof ICPPFunction)
return (ICPPFunction) b; return (ICPPFunction) b;
} catch (DOMException e) { } catch (DOMException e) {

View file

@ -278,7 +278,7 @@ public class CPPASTQualifiedName extends CPPASTNameBase
List<IBinding> filtered = filterClassScopeBindings(classType, bindings, isDeclaration); List<IBinding> filtered = filterClassScopeBindings(classType, bindings, isDeclaration);
if (isDeclaration && nameMatches(classType.getNameCharArray(), if (isDeclaration && nameMatches(classType.getNameCharArray(),
n.getLookupKey(), isPrefix)) { n.getLookupKey(), isPrefix)) {
ICPPConstructor[] constructors = SemanticUtil.getConstructors(classType, n); ICPPConstructor[] constructors = ClassTypeHelper.getConstructors(classType, n);
for (int i = 0; i < constructors.length; i++) { for (int i = 0; i < constructors.length; i++) {
if (!constructors[i].isImplicit()) { if (!constructors[i].isImplicit()) {
filtered.add(constructors[i]); filtered.add(constructors[i]);

View file

@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; 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.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
@ -122,7 +123,8 @@ public class CPPClassSpecialization extends CPPSpecialization
@Override @Override
public ICPPBase[] getBases() { 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 @Override
@ -136,7 +138,8 @@ public class CPPClassSpecialization extends CPPSpecialization
@Override @Override
public ICPPField[] getDeclaredFields() { 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 @Override
@ -150,7 +153,8 @@ public class CPPClassSpecialization extends CPPSpecialization
@Override @Override
public ICPPMethod[] getDeclaredMethods() { 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 @Override
@ -164,7 +168,8 @@ public class CPPClassSpecialization extends CPPSpecialization
@Override @Override
public ICPPConstructor[] getConstructors() { 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 @Override
@ -178,7 +183,8 @@ public class CPPClassSpecialization extends CPPSpecialization
@Override @Override
public IBinding[] getFriends() { 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 @Override
@ -192,7 +198,8 @@ public class CPPClassSpecialization extends CPPSpecialization
@Override @Override
public ICPPClassType[] getNestedClasses() { 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 @Override
@ -206,7 +213,13 @@ public class CPPClassSpecialization extends CPPSpecialization
@Override @Override
public IField[] getFields() { 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 @Override
@ -216,12 +229,24 @@ public class CPPClassSpecialization extends CPPSpecialization
@Override @Override
public ICPPMethod[] getMethods() { 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 @Override
public ICPPMethod[] getAllDeclaredMethods() { 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) /* (non-Javadoc)

View file

@ -159,7 +159,7 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements ICPPClass
@Override @Override
public IField[] getFields() { public IField[] getFields() {
return ClassTypeHelper.getFields(this); return ClassTypeHelper.getFields(this, null);
} }
@Override @Override
@ -169,12 +169,12 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements ICPPClass
@Override @Override
public ICPPMethod[] getMethods() { public ICPPMethod[] getMethods() {
return ClassTypeHelper.getMethods(this); return ClassTypeHelper.getMethods(this, null);
} }
@Override @Override
public ICPPMethod[] getAllDeclaredMethods() { public ICPPMethod[] getAllDeclaredMethods() {
return ClassTypeHelper.getAllDeclaredMethods(this); return ClassTypeHelper.getAllDeclaredMethods(this, null);
} }
@Override @Override

View file

@ -43,7 +43,7 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization
@Override @Override
public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() { public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() {
if (fPartialSpecs == null) { 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(); ICPPClassTemplate origTemplate= (ICPPClassTemplate) getSpecializedBinding();
ICPPClassTemplatePartialSpecialization[] orig = origTemplate.getPartialSpecializations(); ICPPClassTemplatePartialSpecialization[] orig = origTemplate.getPartialSpecializations();
ICPPClassTemplatePartialSpecialization[] spec = new ICPPClassTemplatePartialSpecialization[orig.length]; ICPPClassTemplatePartialSpecialization[] spec = new ICPPClassTemplatePartialSpecialization[orig.length];

View file

@ -309,7 +309,7 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
@Override @Override
public IField[] getFields() { public IField[] getFields() {
return ClassTypeHelper.getFields(this); return ClassTypeHelper.getFields(this, null);
} }
@Override @Override
@ -319,12 +319,12 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
@Override @Override
public ICPPMethod[] getMethods() { public ICPPMethod[] getMethods() {
return ClassTypeHelper.getMethods(this); return ClassTypeHelper.getMethods(this, null);
} }
@Override @Override
public ICPPMethod[] getAllDeclaredMethods() { public ICPPMethod[] getAllDeclaredMethods() {
return ClassTypeHelper.getAllDeclaredMethods(this); return ClassTypeHelper.getAllDeclaredMethods(this, null);
} }
@Override @Override

View file

@ -194,6 +194,6 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod
@Override @Override
public IType[] getExceptionSpecification() { public IType[] getExceptionSpecification() {
return ClassTypeHelper.getInheritedExceptionSpecification(this); return ClassTypeHelper.getInheritedExceptionSpecification(this, null);
} }
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -8,6 +8,7 @@
* Contributors: * Contributors:
* Andrew Niefer (IBM) - Initial API and implementation * Andrew Niefer (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; 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.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; 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.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethodSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
/** /**
* The specialization of a method in the context of a class-specialization. * 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 ) { public CPPMethodSpecialization(ICPPMethod orig, ICPPClassType owner, ICPPTemplateParameterMap argMap,
super(orig, owner, argMap, type, exceptionSpec ); ICPPFunctionType type, IType[] exceptionSpec) {
super(orig, owner, argMap, type, exceptionSpec);
}
@Override
public ICPPMethod getSpecializedBinding() {
return (ICPPMethod) super.getSpecializedBinding();
} }
@Override @Override
public boolean isVirtual() { public boolean isVirtual() {
ICPPMethod f = (ICPPMethod) getSpecializedBinding(); ICPPMethod f = getSpecializedBinding();
if (f != null) if (f != null)
return f.isVirtual(); return f.isVirtual();
IASTNode definition = getDefinition(); IASTNode definition = getDefinition();
@ -58,7 +66,7 @@ public class CPPMethodSpecialization extends CPPFunctionSpecialization implement
@Override @Override
public int getVisibility() { public int getVisibility() {
ICPPMethod f = (ICPPMethod) getSpecializedBinding(); ICPPMethod f = getSpecializedBinding();
if (f != null) if (f != null)
return f.getVisibility(); return f.getVisibility();
return 0; return 0;
@ -80,17 +88,17 @@ public class CPPMethodSpecialization extends CPPFunctionSpecialization implement
@Override @Override
public boolean isExplicit() { public boolean isExplicit() {
return ((ICPPMethod) getSpecializedBinding()).isExplicit(); return getSpecializedBinding().isExplicit();
} }
@Override @Override
public boolean isImplicit() { public boolean isImplicit() {
return ((ICPPMethod) getSpecializedBinding()).isImplicit(); return getSpecializedBinding().isImplicit();
} }
@Override @Override
public boolean isPureVirtual() { public boolean isPureVirtual() {
ICPPMethod f = (ICPPMethod) getSpecializedBinding(); ICPPMethod f = getSpecializedBinding();
if (f != null) if (f != null)
return f.isPureVirtual(); return f.isPureVirtual();
@ -98,9 +106,9 @@ public class CPPMethodSpecialization extends CPPFunctionSpecialization implement
} }
@Override @Override
public IType[] getExceptionSpecification() { public IType[] getExceptionSpecification(IASTNode point) {
if (isImplicit()) { if (isImplicit()) {
return ClassTypeHelper.getInheritedExceptionSpecification(this); return ClassTypeHelper.getInheritedExceptionSpecification(this, point);
} }
return super.getExceptionSpecification(); return super.getExceptionSpecification();
} }

View file

@ -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.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; 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.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.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; 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.ICPPField;
@ -101,14 +102,14 @@ public class ClassTypeHelper {
IASTDeclaration[] members = host.getCompositeTypeSpecifier().getMembers(); IASTDeclaration[] members = host.getCompositeTypeSpecifier().getMembers();
for (IASTDeclaration decl : members) { for (IASTDeclaration decl : members) {
while (decl instanceof ICPPASTTemplateDeclaration) while (decl instanceof ICPPASTTemplateDeclaration)
decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration(); decl = ((ICPPASTTemplateDeclaration) decl).getDeclaration();
if (decl instanceof IASTSimpleDeclaration) { if (decl instanceof IASTSimpleDeclaration) {
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)decl).getDeclSpecifier(); ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration) decl).getDeclSpecifier();
if (declSpec.isFriend()) { if (declSpec.isFriend()) {
IASTDeclarator[] dtors = ((IASTSimpleDeclaration)decl).getDeclarators(); IASTDeclarator[] dtors = ((IASTSimpleDeclaration) decl).getDeclarators();
if (declSpec instanceof ICPPASTElaboratedTypeSpecifier && dtors.length == 0) { if (declSpec instanceof ICPPASTElaboratedTypeSpecifier && dtors.length == 0) {
resultSet.put(((ICPPASTElaboratedTypeSpecifier)declSpec).getName().resolveBinding()); resultSet.put(((ICPPASTElaboratedTypeSpecifier) declSpec).getName().resolveBinding());
} else { } else {
for (IASTDeclarator dtor : dtors) { for (IASTDeclarator dtor : dtors) {
if (dtor == null) break; if (dtor == null) break;
@ -118,9 +119,9 @@ public class ClassTypeHelper {
} }
} }
} else if (decl instanceof IASTFunctionDefinition) { } else if (decl instanceof IASTFunctionDefinition) {
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition)decl).getDeclSpecifier(); ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition) decl).getDeclSpecifier();
if (declSpec.isFriend()) { if (declSpec.isFriend()) {
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator(); IASTDeclarator dtor = ((IASTFunctionDefinition) decl).getDeclarator();
dtor= ASTQueries.findInnermostDeclarator(dtor); dtor= ASTQueries.findInnermostDeclarator(dtor);
resultSet.put(dtor.getName().resolveBinding()); resultSet.put(dtor.getName().resolveBinding());
} }
@ -144,7 +145,7 @@ public class ClassTypeHelper {
if (type.isSameType(classType)) { if (type.isSameType(classType)) {
return true; return true;
} }
for (IBinding friend : classType.getFriends()) { for (IBinding friend : getFriends(classType, null)) {
if (friend instanceof ICPPClassType && type.isSameType((IType) friend)) { if (friend instanceof ICPPClassType && type.isSameType((IType) friend)) {
return true; return true;
} }
@ -152,7 +153,7 @@ public class ClassTypeHelper {
} else if (binding instanceof ICPPFunction) { } else if (binding instanceof ICPPFunction) {
type = ((ICPPFunction) binding).getType(); type = ((ICPPFunction) binding).getType();
char[] name = binding.getNameCharArray(); char[] name = binding.getNameCharArray();
for (IBinding friend : classType.getFriends()) { for (IBinding friend : getFriends(classType, null)) {
if (friend instanceof ICPPFunction && if (friend instanceof ICPPFunction &&
CharArrayUtils.equals(name, friend.getNameCharArray()) && CharArrayUtils.equals(name, friend.getNameCharArray()) &&
SemanticUtil.isSameOwner(binding.getOwner(), friend.getOwner()) && SemanticUtil.isSameOwner(binding.getOwner(), friend.getOwner()) &&
@ -217,17 +218,17 @@ public class ClassTypeHelper {
IASTDeclaration[] decls = host.getCompositeTypeSpecifier().getMembers(); IASTDeclaration[] decls = host.getCompositeTypeSpecifier().getMembers();
for (IASTDeclaration decl : decls) { for (IASTDeclaration decl : decls) {
if (decl instanceof IASTSimpleDeclaration) { if (decl instanceof IASTSimpleDeclaration) {
IASTDeclarator[] dtors = ((IASTSimpleDeclaration)decl).getDeclarators(); IASTDeclarator[] dtors = ((IASTSimpleDeclaration) decl).getDeclarators();
for (IASTDeclarator dtor : dtors) { for (IASTDeclarator dtor : dtors) {
binding = ASTQueries.findInnermostDeclarator(dtor).getName().resolveBinding(); binding = ASTQueries.findInnermostDeclarator(dtor).getName().resolveBinding();
if (binding instanceof ICPPField) if (binding instanceof ICPPField)
result = ArrayUtil.append(ICPPField.class, result, (ICPPField) binding); result = ArrayUtil.append(ICPPField.class, result, (ICPPField) binding);
} }
} else if (decl instanceof ICPPASTUsingDeclaration) { } else if (decl instanceof ICPPASTUsingDeclaration) {
IASTName n = ((ICPPASTUsingDeclaration)decl).getName(); IASTName n = ((ICPPASTUsingDeclaration) decl).getName();
binding = n.resolveBinding(); binding = n.resolveBinding();
if (binding instanceof ICPPUsingDeclaration) { if (binding instanceof ICPPUsingDeclaration) {
IBinding[] bs = ((ICPPUsingDeclaration)binding).getDelegates(); IBinding[] bs = ((ICPPUsingDeclaration) binding).getDelegates();
for (IBinding element : bs) { for (IBinding element : bs) {
if (element instanceof ICPPField) if (element instanceof ICPPField)
result = ArrayUtil.append(ICPPField.class, result, (ICPPField) element); result = ArrayUtil.append(ICPPField.class, result, (ICPPField) element);
@ -240,27 +241,63 @@ public class ClassTypeHelper {
return ArrayUtil.trim(ICPPField.class, result); 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. * Returns all direct and indirect base classes.
* @param classType a class * @param classType a class
* @return An array of visible base classes in arbitrary order. * @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<ICPPClassType> result= new HashSet<ICPPClassType>(); HashSet<ICPPClassType> result= new HashSet<ICPPClassType>();
result.add(classType); result.add(classType);
getAllBases(classType, result); getAllBases(classType, result, point);
result.remove(classType); result.remove(classType);
return result.toArray(new ICPPClassType[result.size()]); return result.toArray(new ICPPClassType[result.size()]);
} }
private static void getAllBases(ICPPClassType classType, HashSet<ICPPClassType> result) { private static void getAllBases(ICPPClassType classType, HashSet<ICPPClassType> result, IASTNode point) {
ICPPBase[] bases= classType.getBases(); ICPPBase[] bases= ClassTypeHelper.getBases(classType, point);
for (ICPPBase base : bases) { for (ICPPBase base : bases) {
IBinding b= base.getBaseClass(); IBinding b= base.getBaseClass();
if (b instanceof ICPPClassType) { if (b instanceof ICPPClassType) {
final ICPPClassType baseClass = (ICPPClassType) b; final ICPPClassType baseClass = (ICPPClassType) b;
if (result.add(baseClass)) { if (result.add(baseClass)) {
getAllBases(baseClass, result); getAllBases(baseClass, result, point);
} }
} }
} }
@ -287,25 +324,22 @@ public class ClassTypeHelper {
return false; return false;
} }
public static ICPPMethod[] getAllDeclaredMethods(ICPPClassType ct) { public static ICPPMethod[] getAllDeclaredMethods(ICPPClassType ct, IASTNode point) {
ICPPMethod[] methods= ct.getDeclaredMethods(); ICPPMethod[] methods= getDeclaredMethods(ct, point);
ICPPClassType[] bases= getAllBases(ct); ICPPClassType[] bases= getAllBases(ct, point);
for (ICPPClassType base : bases) { 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); return ArrayUtil.trim(ICPPMethod.class, methods);
} }
public static ICPPMethod[] getMethods(ICPPClassType ct) { public static ICPPMethod[] getMethods(ICPPClassType ct, IASTNode point) {
ObjectSet<ICPPMethod> set = getOwnMethods(ct); ObjectSet<ICPPMethod> set = getOwnMethods(ct, point);
ICPPClassType[] bases= getAllBases(ct); ICPPClassType[] bases= getAllBases(ct, point);
for (ICPPClassType base : bases) { for (ICPPClassType base : bases) {
set.addAll(base.getDeclaredMethods()); set.addAll(getDeclaredMethods(base, point));
final IScope compositeScope = base.getCompositeScope(); set.addAll(getImplicitMethods(base, point));
if (compositeScope instanceof ICPPClassScope) {
set.addAll(((ICPPClassScope) compositeScope).getImplicitMethods());
}
} }
return set.keyArray(ICPPMethod.class); 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 * Returns methods either declared by the given class or generated by the compiler. Does not
* include methods declared in base classes. * include methods declared in base classes.
*/ */
private static ObjectSet<ICPPMethod> getOwnMethods(ICPPClassType classType) { private static ObjectSet<ICPPMethod> getOwnMethods(ICPPClassType classType, IASTNode point) {
ObjectSet<ICPPMethod> set= new ObjectSet<ICPPMethod>(4); ObjectSet<ICPPMethod> set= new ObjectSet<ICPPMethod>(4);
set.addAll(classType.getDeclaredMethods()); set.addAll(ClassTypeHelper.getDeclaredMethods(classType, point));
IScope scope = classType.getCompositeScope(); set.addAll(getImplicitMethods(classType, point));
if (scope instanceof ICPPClassScope) {
set.addAll(((ICPPClassScope) scope).getImplicitMethods());
}
return set; 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) { public static ICPPMethod[] getDeclaredMethods(ICPPInternalClassTypeMixinHost host) {
if (host.getDefinition() == null) { if (host.getDefinition() == null) {
host.checkForDefinition(); host.checkForDefinition();
@ -341,9 +382,9 @@ public class ClassTypeHelper {
IASTDeclaration[] decls = host.getCompositeTypeSpecifier().getMembers(); IASTDeclaration[] decls = host.getCompositeTypeSpecifier().getMembers();
for (IASTDeclaration decl : decls) { for (IASTDeclaration decl : decls) {
while (decl instanceof ICPPASTTemplateDeclaration) while (decl instanceof ICPPASTTemplateDeclaration)
decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration(); decl = ((ICPPASTTemplateDeclaration) decl).getDeclaration();
if (decl instanceof IASTSimpleDeclaration) { if (decl instanceof IASTSimpleDeclaration) {
final IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration)decl; final IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration) decl;
if (!((ICPPASTDeclSpecifier) sdecl.getDeclSpecifier()).isFriend()) { if (!((ICPPASTDeclSpecifier) sdecl.getDeclSpecifier()).isFriend()) {
IASTDeclarator[] dtors = sdecl.getDeclarators(); IASTDeclarator[] dtors = sdecl.getDeclarators();
for (IASTDeclarator dtor : dtors) { for (IASTDeclarator dtor : dtors) {
@ -353,7 +394,7 @@ public class ClassTypeHelper {
} }
} }
} else if (decl instanceof IASTFunctionDefinition) { } else if (decl instanceof IASTFunctionDefinition) {
final IASTFunctionDefinition fdef = (IASTFunctionDefinition)decl; final IASTFunctionDefinition fdef = (IASTFunctionDefinition) decl;
if (!((ICPPASTDeclSpecifier) fdef.getDeclSpecifier()).isFriend()) { if (!((ICPPASTDeclSpecifier) fdef.getDeclSpecifier()).isFriend()) {
IASTDeclarator dtor = fdef.getDeclarator(); IASTDeclarator dtor = fdef.getDeclarator();
dtor = ASTQueries.findInnermostDeclarator(dtor); dtor = ASTQueries.findInnermostDeclarator(dtor);
@ -363,10 +404,10 @@ public class ClassTypeHelper {
} }
} }
} else if (decl instanceof ICPPASTUsingDeclaration) { } else if (decl instanceof ICPPASTUsingDeclaration) {
IASTName n = ((ICPPASTUsingDeclaration)decl).getName(); IASTName n = ((ICPPASTUsingDeclaration) decl).getName();
binding = n.resolveBinding(); binding = n.resolveBinding();
if (binding instanceof ICPPUsingDeclaration) { if (binding instanceof ICPPUsingDeclaration) {
IBinding[] bs = ((ICPPUsingDeclaration)binding).getDelegates(); IBinding[] bs = ((ICPPUsingDeclaration) binding).getDelegates();
for (IBinding element : bs) { for (IBinding element : bs) {
if (element instanceof ICPPMethod) if (element instanceof ICPPMethod)
result = ArrayUtil.append(ICPPMethod.class, result, (ICPPMethod) element); result = ArrayUtil.append(ICPPMethod.class, result, (ICPPMethod) element);
@ -407,15 +448,15 @@ public class ClassTypeHelper {
IASTDeclaration[] decls = host.getCompositeTypeSpecifier().getMembers(); IASTDeclaration[] decls = host.getCompositeTypeSpecifier().getMembers();
for (IASTDeclaration decl : decls) { for (IASTDeclaration decl : decls) {
while (decl instanceof ICPPASTTemplateDeclaration) while (decl instanceof ICPPASTTemplateDeclaration)
decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration(); decl = ((ICPPASTTemplateDeclaration) decl).getDeclaration();
if (decl instanceof IASTSimpleDeclaration) { if (decl instanceof IASTSimpleDeclaration) {
IBinding binding = null; IBinding binding = null;
IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration) decl).getDeclSpecifier(); IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration) decl).getDeclSpecifier();
if (declSpec instanceof ICPPASTCompositeTypeSpecifier) { if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
binding = ((ICPPASTCompositeTypeSpecifier)declSpec).getName().resolveBinding(); binding = ((ICPPASTCompositeTypeSpecifier) declSpec).getName().resolveBinding();
} else if (declSpec instanceof ICPPASTElaboratedTypeSpecifier && } else if (declSpec instanceof ICPPASTElaboratedTypeSpecifier &&
((IASTSimpleDeclaration)decl).getDeclarators().length == 0) { ((IASTSimpleDeclaration) decl).getDeclarators().length == 0) {
binding = ((ICPPASTElaboratedTypeSpecifier)declSpec).getName().resolveBinding(); binding = ((ICPPASTElaboratedTypeSpecifier) declSpec).getName().resolveBinding();
} }
if (binding instanceof ICPPClassType) if (binding instanceof ICPPClassType)
result = ArrayUtil.append(ICPPClassType.class, result, (ICPPClassType) binding); result = ArrayUtil.append(ICPPClassType.class, result, (ICPPClassType) binding);
@ -424,11 +465,11 @@ public class ClassTypeHelper {
return ArrayUtil.trim(ICPPClassType.class, result); return ArrayUtil.trim(ICPPClassType.class, result);
} }
public static IField[] getFields(ICPPClassType ct) { public static IField[] getFields(ICPPClassType ct, IASTNode point) {
IField[] fields = ct.getDeclaredFields(); IField[] fields = getDeclaredFields(ct, point);
ICPPClassType[] bases = getAllBases(ct); ICPPClassType[] bases = getAllBases(ct, point);
for (ICPPClassType base : bases) { 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); return ArrayUtil.trim(IField.class, fields);
} }
@ -464,7 +505,8 @@ public class ClassTypeHelper {
final ICPPClassType mcl= m.getClassOwner(); final ICPPClassType mcl= m.getClassOwner();
if (mcl != null) { if (mcl != null) {
final ICPPFunctionType mft= m.getType(); 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) { for (ICPPMethod method : allMethods) {
if (CharArrayUtils.equals(mname, method.getNameCharArray()) && functionTypesAllowOverride(mft, method.getType())) { if (CharArrayUtils.equals(mname, method.getNameCharArray()) && functionTypesAllowOverride(mft, method.getType())) {
if (method.isVirtual()) { if (method.isVirtual()) {
@ -520,7 +562,7 @@ public class ClassTypeHelper {
if (sourceClass == null || targetClass == null) if (sourceClass == null || targetClass == null)
return false; return false;
ICPPClassType[] bases= getAllBases(sourceClass); ICPPClassType[] bases= getAllBases(sourceClass, null);
for (ICPPClassType base : bases) { for (ICPPClassType base : bases) {
if (base.isSameType(targetClass)) if (base.isSameType(targetClass))
return true; return true;
@ -532,7 +574,7 @@ public class ClassTypeHelper {
/** /**
* Returns all methods that are overridden by the given {@code method}. * 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) if (method instanceof ICPPConstructor)
return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; return ICPPMethod.EMPTY_CPPMETHOD_ARRAY;
@ -546,7 +588,7 @@ public class ClassTypeHelper {
final ICPPFunctionType mft= method.getType(); final ICPPFunctionType mft= method.getType();
virtualInClass.put(mcl, method.isVirtual()); virtualInClass.put(mcl, method.isVirtual());
ICPPBase[] bases= mcl.getBases(); ICPPBase[] bases= getBases(mcl, point);
for (ICPPBase base : bases) { for (ICPPBase base : bases) {
IBinding b= base.getBaseClass(); IBinding b= base.getBaseClass();
if (b instanceof ICPPClassType) { if (b instanceof ICPPClassType) {
@ -681,10 +723,10 @@ public class ClassTypeHelper {
/** /**
* For implicit methods the exception specification is inherited, search it * 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 // See 15.4.13
ICPPClassType owner= implicitMethod.getClassOwner(); ICPPClassType owner= implicitMethod.getClassOwner();
if (owner == null || owner.getBases().length == 0) if (owner == null || ClassTypeHelper.getBases(owner, point).length == 0)
return null; return null;
// we use a list as types aren't comparable, and can have duplicates (15.4.6) // 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; return null;
List<IType> inheritedTypeids = new ArrayList<IType>(); List<IType> inheritedTypeids = new ArrayList<IType>();
ICPPClassType[] bases= getAllBases(owner); ICPPClassType[] bases= getAllBases(owner, point);
for (ICPPClassType base : bases) { for (ICPPClassType base : bases) {
if (!(base instanceof ICPPDeferredClassInstance)) { if (!(base instanceof ICPPDeferredClassInstance)) {
ICPPMethod baseMethod= getMethodInClass(base, kind); ICPPMethod baseMethod= getMethodInClass(base, kind);
@ -792,10 +834,10 @@ public class ClassTypeHelper {
* no private or protected non-static data members (Clause 11), * no private or protected non-static data members (Clause 11),
* no base classes (Clause 10), and no virtual functions (10.3). * no base classes (Clause 10), and no virtual functions (10.3).
*/ */
public static boolean isAggregateClass(ICPPClassType classTarget) { public static boolean isAggregateClass(ICPPClassType classTarget, IASTNode point) {
if (classTarget.getBases().length > 0) if (ClassTypeHelper.getBases(classTarget, point).length > 0)
return false; return false;
ICPPMethod[] methods = classTarget.getDeclaredMethods(); ICPPMethod[] methods = ClassTypeHelper.getDeclaredMethods(classTarget, point);
for (ICPPMethod m : methods) { for (ICPPMethod m : methods) {
if (m instanceof ICPPConstructor) if (m instanceof ICPPConstructor)
return false; return false;
@ -803,7 +845,7 @@ public class ClassTypeHelper {
return false; return false;
} }
} }
ICPPField[] fields = classTarget.getDeclaredFields(); ICPPField[] fields = ClassTypeHelper.getDeclaredFields(classTarget, point);
for (ICPPField field : fields) { for (ICPPField field : fields) {
if (!(field.getVisibility() == ICPPMember.v_public || field.isStatic())) { if (!(field.getVisibility() == ICPPMember.v_public || field.isStatic())) {
return false; return false;
@ -837,7 +879,7 @@ public class ClassTypeHelper {
if (base.isVirtual()) if (base.isVirtual())
return false; return false;
} }
for (ICPPClassType baseClass : getAllBases(classTarget)) { for (ICPPClassType baseClass : getAllBases(classTarget, null)) {
if (!classTarget.isSameType(baseClass) && !hasTrivialCopyCtor(baseClass)) if (!classTarget.isSameType(baseClass) && !hasTrivialCopyCtor(baseClass))
return false; return false;
} }
@ -889,7 +931,7 @@ public class ClassTypeHelper {
if (!ctor.isImplicit() && ctor.getParameters().length == 0) if (!ctor.isImplicit() && ctor.getParameters().length == 0)
return false; return false;
} }
for (ICPPClassType baseClass : getAllBases(classTarget)) { for (ICPPClassType baseClass : getAllBases(classTarget, null)) {
if (!classTarget.isSameType(baseClass) && !hasTrivialDefaultConstructor(baseClass)) if (!classTarget.isSameType(baseClass) && !hasTrivialDefaultConstructor(baseClass))
return false; return false;
} }
@ -925,7 +967,7 @@ public class ClassTypeHelper {
if (method.isDestructor()) if (method.isDestructor())
return false; return false;
} }
for (ICPPClassType baseClass : getAllBases(classTarget)) { for (ICPPClassType baseClass : getAllBases(classTarget, null)) {
if (!classTarget.isSameType(baseClass) && !hasTrivialDestructor(baseClass)) if (!classTarget.isSameType(baseClass) && !hasTrivialDestructor(baseClass))
return false; return false;
} }
@ -952,7 +994,7 @@ public class ClassTypeHelper {
public static boolean isPolymorphic(ICPPClassType classTarget) { public static boolean isPolymorphic(ICPPClassType classTarget) {
if (hasDeclaredVirtualMethod(classTarget)) if (hasDeclaredVirtualMethod(classTarget))
return true; return true;
for (ICPPClassType baseClass : getAllBases(classTarget)) { for (ICPPClassType baseClass : getAllBases(classTarget, null)) {
if (hasDeclaredVirtualMethod(baseClass)) if (hasDeclaredVirtualMethod(baseClass))
return true; return true;
} }
@ -976,9 +1018,9 @@ public class ClassTypeHelper {
* but doesn't take into account base classes and methods dependent on unspecified * but doesn't take into account base classes and methods dependent on unspecified
* template parameters. * template parameters.
*/ */
public static ICPPMethod[] getPureVirtualMethods(ICPPClassType classType) { public static ICPPMethod[] getPureVirtualMethods(ICPPClassType classType, IASTNode point) {
Map<String, List<ICPPMethod>> result= collectPureVirtualMethods(classType, Map<String, List<ICPPMethod>> result= collectPureVirtualMethods(classType,
new HashMap<ICPPClassType, Map<String, List<ICPPMethod>>>()); new HashMap<ICPPClassType, Map<String, List<ICPPMethod>>>(), point);
int resultArraySize = 0; int resultArraySize = 0;
for (List<ICPPMethod> methods : result.values()) { for (List<ICPPMethod> methods : result.values()) {
@ -995,7 +1037,7 @@ public class ClassTypeHelper {
} }
private static Map<String, List<ICPPMethod>> collectPureVirtualMethods(ICPPClassType classType, private static Map<String, List<ICPPMethod>> collectPureVirtualMethods(ICPPClassType classType,
Map<ICPPClassType, Map<String, List<ICPPMethod>>> cache) { Map<ICPPClassType, Map<String, List<ICPPMethod>>> cache, IASTNode point) {
Map<String, List<ICPPMethod>> result = cache.get(classType); Map<String, List<ICPPMethod>> result = cache.get(classType);
if (result != null) if (result != null)
return result; return result;
@ -1005,10 +1047,10 @@ public class ClassTypeHelper {
// Look at the pure virtual methods of the base classes // Look at the pure virtual methods of the base classes
Set<IBinding> handledBaseClasses= new HashSet<IBinding>(); Set<IBinding> handledBaseClasses= new HashSet<IBinding>();
for (ICPPBase base : classType.getBases()) { for (ICPPBase base : ClassTypeHelper.getBases(classType, point)) {
final IBinding baseClass = base.getBaseClass(); final IBinding baseClass = base.getBaseClass();
if (baseClass instanceof ICPPClassType && handledBaseClasses.add(baseClass)) { if (baseClass instanceof ICPPClassType && handledBaseClasses.add(baseClass)) {
Map<String, List<ICPPMethod>> pureVirtuals = collectPureVirtualMethods((ICPPClassType) baseClass, cache); Map<String, List<ICPPMethod>> pureVirtuals = collectPureVirtualMethods((ICPPClassType) baseClass, cache, point);
// Merge derived pure virtual methods // Merge derived pure virtual methods
for (String key : pureVirtuals.keySet()) { for (String key : pureVirtuals.keySet()) {
List<ICPPMethod> list = result.get(key); List<ICPPMethod> list = result.get(key);
@ -1021,8 +1063,8 @@ public class ClassTypeHelper {
} }
} }
// Remove overridden pure-virtual methods and add in new pure virutals. // Remove overridden pure-virtual methods and add in new pure virtuals.
final ObjectSet<ICPPMethod> methods = getOwnMethods(classType); final ObjectSet<ICPPMethod> methods = getOwnMethods(classType, point);
for (ICPPMethod method : methods) { for (ICPPMethod method : methods) {
String key= getMethodNameForOverrideKey(method); String key= getMethodNameForOverrideKey(method);
List<ICPPMethod> list = result.get(key); List<ICPPMethod> list = result.get(key);

View file

@ -152,7 +152,7 @@ public class AccessContext {
return isAccessible(bindingVisibility, accessLevel); return isAccessible(bindingVisibility, accessLevel);
} }
ICPPBase[] bases = derivedClass.getBases(); ICPPBase[] bases = ClassTypeHelper.getBases(derivedClass, name);
if (bases != null) { if (bases != null) {
for (ICPPBase base : bases) { for (ICPPBase base : bases) {
IBinding baseBinding = base.getBaseClass(); IBinding baseBinding = base.getBaseClass();

View file

@ -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.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; 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.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.ICPPDeferredClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
@ -181,7 +182,7 @@ class BaseClassLookup {
// base-classes // base-classes
ICPPClassType baseClass= result.getClassType(); ICPPClassType baseClass= result.getClassType();
if (baseClass != null) { if (baseClass != null) {
ICPPBase[] grandBases= SemanticUtil.getBases(baseClass, data.getLookupPoint()); ICPPBase[] grandBases= ClassTypeHelper.getBases(baseClass, data.getLookupPoint());
if (grandBases != null && grandBases.length > 0) { if (grandBases != null && grandBases.length > 0) {
HashSet<IBinding> grandBaseBindings= null; HashSet<IBinding> grandBaseBindings= null;
BitSet selectedBases= null; BitSet selectedBases= null;

View file

@ -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.ISerializableEvaluation;
import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; 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.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.SizeofCalculator.SizeAndAlignment;
import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument;
@ -251,7 +252,9 @@ public abstract class CPPEvaluation implements ICPPEvaluation {
} }
protected static SizeAndAlignment getSizeAndAlignment(IType type, IASTNode point) { protected static SizeAndAlignment getSizeAndAlignment(IType type, IASTNode point) {
ASTTranslationUnit ast = (ASTTranslationUnit) point.getTranslationUnit(); SizeofCalculator calc = point == null ?
return ast.getSizeofCalculator().sizeAndAlignment(type); SizeofCalculator.getDefault() :
((ASTTranslationUnit) point.getTranslationUnit()).getSizeofCalculator();
return calc.sizeAndAlignment(type);
} }
} }

View file

@ -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.CPPUsingDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUsingDirective; 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.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.ICPPASTInternalScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
@ -414,7 +415,7 @@ public class CPPSemantics {
if (cls instanceof ICPPUnknownBinding) { if (cls instanceof ICPPUnknownBinding) {
binding= new CPPUnknownConstructor(cls); binding= new CPPUnknownConstructor(cls);
} else { } else {
binding= CPPSemantics.resolveFunction(data, SemanticUtil.getConstructors(cls, lookupPoint), true); binding= CPPSemantics.resolveFunction(data, ClassTypeHelper.getConstructors(cls, lookupPoint), true);
} }
} catch (DOMException e) { } catch (DOMException e) {
return e.getProblem(); return e.getProblem();
@ -714,7 +715,7 @@ public class CPPSemantics {
} }
if (t instanceof ICPPClassType && !(t instanceof ICPPClassTemplate)) { if (t instanceof ICPPClassType && !(t instanceof ICPPClassTemplate)) {
ICPPClassType ct= (ICPPClassType) t; ICPPClassType ct= (ICPPClassType) t;
ICPPBase[] bases = SemanticUtil.getBases(ct, tu); ICPPBase[] bases = ClassTypeHelper.getBases(ct, tu);
for (ICPPBase base : bases) { for (ICPPBase base : bases) {
IBinding b = base.getBaseClass(); IBinding b = base.getBaseClass();
if (b instanceof IType) if (b instanceof IType)
@ -725,7 +726,7 @@ public class CPPSemantics {
// (excluding template template parameters); // (excluding template template parameters);
// * ... owners of which any template template arguments are members; // * ... owners of which any template template arguments are members;
if (ct instanceof ICPPTemplateInstance) { if (ct instanceof ICPPTemplateInstance) {
for (IBinding friend : ct.getFriends()) { for (IBinding friend : ClassTypeHelper.getFriends(ct, tu)) {
if (friend instanceof ICPPFunction) { if (friend instanceof ICPPFunction) {
friendFns.add((ICPPFunction) friend); friendFns.add((ICPPFunction) friend);
} }
@ -2817,7 +2818,7 @@ public class CPPSemantics {
LookupData data= new LookupData(name); LookupData data= new LookupData(name);
data.setFunctionArguments(false, init.getArguments()); data.setFunctionArguments(false, init.getArguments());
try { 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) { if (ctor instanceof ICPPConstructor) {
int i= 0; int i= 0;
for (IASTNode arg : init.getArguments()) { for (IASTNode arg : init.getArguments()) {
@ -3124,13 +3125,13 @@ public class CPPSemantics {
LookupData data = new LookupData(astName); LookupData data = new LookupData(astName);
data.setFunctionArguments(false, arguments); data.setFunctionArguments(false, arguments);
data.qualified = true; data.qualified = true;
data.foundItems = SemanticUtil.getConstructors(classType, name); data.foundItems = ClassTypeHelper.getConstructors(classType, name);
binding = resolveAmbiguities(data); binding = resolveAmbiguities(data);
if (binding instanceof ICPPConstructor) if (binding instanceof ICPPConstructor)
return (ICPPConstructor) binding; return (ICPPConstructor) binding;
} else if (initializer == null) { } else if (initializer == null) {
// Default initialization // Default initialization
ICPPConstructor[] ctors = SemanticUtil.getConstructors(classType, name); ICPPConstructor[] ctors = ClassTypeHelper.getConstructors(classType, name);
for (ICPPConstructor ctor : ctors) { for (ICPPConstructor ctor : ctors) {
if (ctor.getRequiredArgumentCount() == 0) if (ctor.getRequiredArgumentCount() == 0)
return ctor; return ctor;

View file

@ -2241,6 +2241,8 @@ public class CPPVisitor extends ASTQueries {
} }
private static IType getStdType(final IASTNode node, char[] name) { private static IType getStdType(final IASTNode node, char[] name) {
if (node == null)
return null;
ASTTranslationUnit ast = (ASTTranslationUnit) node.getTranslationUnit(); ASTTranslationUnit ast = (ASTTranslationUnit) node.getTranslationUnit();
IBinding[] std= ast.getScope().find(STD); IBinding[] std= ast.getScope().find(STD);
for (IBinding binding : std) { for (IBinding binding : std) {

View file

@ -371,7 +371,7 @@ public class Conversions {
return Cost.NO_CONVERSION; return Cost.NO_CONVERSION;
ICPPClassType classTarget= (ICPPClassType) noCVTarget; ICPPClassType classTarget= (ICPPClassType) noCVTarget;
if (ClassTypeHelper.isAggregateClass(classTarget)) { if (ClassTypeHelper.isAggregateClass(classTarget, point)) {
Cost cost= new Cost(arg.getTypeOrFunctionSet(point), target, Rank.IDENTITY); Cost cost= new Cost(arg.getTypeOrFunctionSet(point), target, Rank.IDENTITY);
cost.setUserDefinedConversion(null); cost.setUserDefinedConversion(null);
return cost; return cost;
@ -546,7 +546,7 @@ public class Conversions {
ICPPConstructor usedCtor= null; ICPPConstructor usedCtor= null;
Cost bestCost= null; Cost bestCost= null;
boolean hasInitListConstructor= false; boolean hasInitListConstructor= false;
final ICPPConstructor[] constructors = SemanticUtil.getConstructors(t, point); final ICPPConstructor[] constructors = ClassTypeHelper.getConstructors(t, point);
ICPPConstructor[] ctors= constructors; ICPPConstructor[] ctors= constructors;
for (ICPPConstructor ctor : ctors) { for (ICPPConstructor ctor : ctors) {
final int minArgCount = ctor.getRequiredArgumentCount(); final int minArgCount = ctor.getRequiredArgumentCount();
@ -640,7 +640,7 @@ public class Conversions {
FunctionCost cost1= null; FunctionCost cost1= null;
Cost cost2= null; Cost cost2= null;
ICPPFunction[] ctors= SemanticUtil.getConstructors(t, point); ICPPFunction[] ctors= ClassTypeHelper.getConstructors(t, point);
ctors = CPPTemplates.instantiateForFunctionCall(ctors, null, ctors = CPPTemplates.instantiateForFunctionCall(ctors, null,
Collections.singletonList(source), Collections.singletonList(valueCat), false, point); Collections.singletonList(source), Collections.singletonList(valueCat), false, point);

View file

@ -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.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; 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.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.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.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; 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.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.CPPPointerType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType; 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.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.ICPPDeferredClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator; import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator;
@ -108,7 +106,7 @@ public class SemanticUtil {
if (clazz instanceof ICPPDeferredClassInstance) { if (clazz instanceof ICPPDeferredClassInstance) {
clazz= (ICPPClassType) ((ICPPDeferredClassInstance) clazz).getTemplateDefinition(); clazz= (ICPPClassType) ((ICPPDeferredClassInstance) clazz).getTemplateDefinition();
} }
ICPPMethod[] decs= getDeclaredMethods(clazz, point); ICPPMethod[] decs= ClassTypeHelper.getDeclaredMethods(clazz, point);
if (decs != null) { if (decs != null) {
for (ICPPMethod method : decs) { for (ICPPMethod method : decs) {
if (isConversionOperator(method)) { if (isConversionOperator(method)) {
@ -152,7 +150,7 @@ public class SemanticUtil {
ICPPClassType clazz= current.keyAt(i); ICPPClassType clazz= current.keyAt(i);
done.put(clazz); done.put(clazz);
for (ICPPBase base : getBases(clazz, point)) { for (ICPPBase base : ClassTypeHelper.getBases(clazz, point)) {
IBinding binding= base.getBaseClass(); IBinding binding= base.getBaseClass();
if (binding instanceof ICPPClassType && !(binding instanceof IProblemBinding)) { if (binding instanceof ICPPClassType && !(binding instanceof IProblemBinding)) {
ICPPClassType ct= (ICPPClassType) binding; ICPPClassType ct= (ICPPClassType) binding;
@ -169,42 +167,6 @@ public class SemanticUtil {
return done; 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 * @param method
* @return true if the specified method is a conversion operator * @return true if the specified method is a conversion operator
@ -676,7 +638,7 @@ public class SemanticUtil {
clazz= (ICPPClassType) ((ICPPDeferredClassInstance) clazz).getSpecializedBinding(); clazz= (ICPPClassType) ((ICPPDeferredClassInstance) clazz).getSpecializedBinding();
} }
for (ICPPBase cppBase : getBases(clazz, point)) { for (ICPPBase cppBase : ClassTypeHelper.getBases(clazz, point)) {
IBinding base= cppBase.getBaseClass(); IBinding base= cppBase.getBaseClass();
if (base instanceof IType && hashSet.add(base)) { if (base instanceof IType && hashSet.add(base)) {
IType tbase= (IType) base; IType tbase= (IType) base;

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; 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.CPPTemplateNonTypeArgument;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap; 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.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.ICPPEvaluation;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; 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 { 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 * 14.8.2.1
* @param point
*/ */
static ICPPTemplateArgument[] deduceForFunctionCall(ICPPFunctionTemplate template, static ICPPTemplateArgument[] deduceForFunctionCall(ICPPFunctionTemplate template,
ICPPTemplateArgument[] tmplArgs, List<IType> fnArgs, List<ValueCategory> argIsLValue, ICPPTemplateArgument[] tmplArgs, List<IType> fnArgs, List<ValueCategory> argIsLValue,
@ -236,7 +238,7 @@ public class TemplateArgumentDeduction {
ICPPTemplateInstance pInst = (ICPPTemplateInstance) pcheck; ICPPTemplateInstance pInst = (ICPPTemplateInstance) pcheck;
ICPPClassTemplate pTemplate= getPrimaryTemplate(pInst); ICPPClassTemplate pTemplate= getPrimaryTemplate(pInst);
if (pTemplate != null) { if (pTemplate != null) {
ICPPClassType aInst= findBaseInstance((ICPPClassType) argcheck, pTemplate); ICPPClassType aInst= findBaseInstance((ICPPClassType) argcheck, pTemplate, point);
if (aInst != null && aInst != argcheck) { if (aInst != null && aInst != argcheck) {
par= pcheck; par= pcheck;
arg= aInst; arg= aInst;
@ -291,7 +293,6 @@ public class TemplateArgumentDeduction {
/** /**
* Deduce arguments for a user defined conversion template * Deduce arguments for a user defined conversion template
* 14.8.2.3 * 14.8.2.3
* @param point
*/ */
static ICPPTemplateArgument[] deduceForConversion(ICPPFunctionTemplate template, static ICPPTemplateArgument[] deduceForConversion(ICPPFunctionTemplate template,
IType conversionType, CPPTemplateParameterMap map, IASTNode point) throws DOMException { IType conversionType, CPPTemplateParameterMap map, IASTNode point) throws DOMException {
@ -326,7 +327,6 @@ public class TemplateArgumentDeduction {
/** /**
* Deduce arguments for a function declaration * Deduce arguments for a function declaration
* 14.8.2.6 * 14.8.2.6
* @param point
*/ */
static ICPPTemplateArgument[] deduceForDeclaration(ICPPFunctionTemplate template, static ICPPTemplateArgument[] deduceForDeclaration(ICPPFunctionTemplate template,
ICPPTemplateArgument[] args, ICPPFunctionType ftype, CPPTemplateParameterMap map, IASTNode point) throws DOMException { 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, * Deduces the mapping for the template parameters from the function parameters,
* returns <code>false</code> if there is no mapping. * returns <code>false</code> if there is no mapping.
* @param point
*/ */
static int deduceForPartialOrdering(ICPPTemplateParameter[] tmplPars, IType[] fnPars, IType[] fnArgs, IASTNode point) { static int deduceForPartialOrdering(ICPPTemplateParameter[] tmplPars, IType[] fnPars, IType[] fnArgs, IASTNode point) {
try { try {
@ -424,7 +423,6 @@ public class TemplateArgumentDeduction {
/** /**
* Adds the explicit arguments to the map. * Adds the explicit arguments to the map.
* @param point
*/ */
private static boolean addExplicitArguments(final ICPPTemplateParameter[] tmplParams, private static boolean addExplicitArguments(final ICPPTemplateParameter[] tmplParams,
ICPPTemplateArgument[] tmplArgs, CPPTemplateParameterMap map, IASTNode point) { 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 { private static ICPPClassType findBaseInstance(ICPPClassType a, ICPPClassTemplate pTemplate, IASTNode point) throws DOMException {
return findBaseInstance(a, pTemplate, CPPSemantics.MAX_INHERITANCE_DEPTH, new HashSet<Object>()); return findBaseInstance(a, pTemplate, CPPSemantics.MAX_INHERITANCE_DEPTH, new HashSet<Object>(), point);
} }
private static ICPPClassType findBaseInstance(ICPPClassType a, ICPPClassTemplate pTemplate, int maxdepth, HashSet<Object> handled) throws DOMException { private static ICPPClassType findBaseInstance(ICPPClassType a, ICPPClassTemplate pTemplate, int maxdepth, HashSet<Object> handled, IASTNode point) throws DOMException {
if (a instanceof ICPPTemplateInstance) { if (a instanceof ICPPTemplateInstance) {
final ICPPTemplateInstance inst = (ICPPTemplateInstance) a; final ICPPTemplateInstance inst = (ICPPTemplateInstance) a;
ICPPClassTemplate tmpl= getPrimaryTemplate(inst); ICPPClassTemplate tmpl= getPrimaryTemplate(inst);
@ -496,10 +495,10 @@ public class TemplateArgumentDeduction {
return a; return a;
} }
if (maxdepth-- > 0) { if (maxdepth-- > 0) {
for (ICPPBase cppBase : a.getBases()) { for (ICPPBase cppBase : ClassTypeHelper.getBases(a, point)) {
IBinding base= cppBase.getBaseClass(); IBinding base= cppBase.getBaseClass();
if (base instanceof ICPPClassType && handled.add(base)) { 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) if (inst != null)
return inst; return inst;
} }
@ -547,7 +546,6 @@ public class TemplateArgumentDeduction {
/** /**
* Deduces the template parameter mapping from pairs of template arguments. * Deduces the template parameter mapping from pairs of template arguments.
* @param point
*/ */
public static boolean fromTemplateArguments(final ICPPTemplateParameter[] pars, public static boolean fromTemplateArguments(final ICPPTemplateParameter[] pars,
final ICPPTemplateArgument[] p, final ICPPTemplateArgument[] a, CPPTemplateParameterMap map, 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. * Deduces the template parameter mapping from one pair of template arguments.
* @param point
*/ */
private boolean fromTemplateArgument(ICPPTemplateArgument p, ICPPTemplateArgument a, IASTNode point) throws DOMException { private boolean fromTemplateArgument(ICPPTemplateArgument p, ICPPTemplateArgument a, IASTNode point) throws DOMException {
if (p.isNonTypeValue() != a.isNonTypeValue()) if (p.isNonTypeValue() != a.isNonTypeValue())

View file

@ -15,8 +15,10 @@ package org.eclipse.cdt.internal.core.index.composite.cpp;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; 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.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; 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.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.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.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassSpecialization.RecursionResolvingBinding; 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.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.ICPPClassSpecializationScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.IIndexFragment;
@ -79,11 +82,11 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple
specializationMap= (ObjectMap) cached; specializationMap= (ObjectMap) cached;
} else { } else {
final ObjectMap newMap= new ObjectMap(2); 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); IIndexFragmentBinding[] frags= cf.findEquivalentBindings(rbinding);
for (IIndexFragmentBinding fb : frags) { for (IIndexFragmentBinding fb : frags) {
if (fb instanceof ICPPClassType) { if (fb instanceof ICPPClassType) {
final ICPPClassType[] nested = ((ICPPClassType)fb).getNestedClasses(); final ICPPClassType[] nested = ClassTypeHelper.getNestedClasses((ICPPClassType) fb, point);
if (nested.length > 0) { if (nested.length > 0) {
for (ICPPClassType ct : nested) { for (ICPPClassType ct : nested) {
if (ct instanceof ICPPClassSpecialization && if (ct instanceof ICPPClassSpecialization &&
@ -129,7 +132,8 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple
@Override @Override
public final ICPPBase[] getBases() { 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 @Override
@ -138,12 +142,14 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple
if (scope instanceof ICPPClassSpecializationScope) { if (scope instanceof ICPPClassSpecializationScope) {
return ((ICPPClassSpecializationScope) scope).getBases(point); return ((ICPPClassSpecializationScope) scope).getBases(point);
} }
return super.getBases(); ICPPBase[] bases = ClassTypeHelper.getBases((ICPPClassType) rbinding, point);
return wrapBases(bases);
} }
@Override @Override
public final ICPPConstructor[] getConstructors() { 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 @Override
@ -152,12 +158,25 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple
if (scope instanceof ICPPClassSpecializationScope) { if (scope instanceof ICPPClassSpecializationScope) {
return ((ICPPClassSpecializationScope) scope).getConstructors(point); 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 @Override
public final ICPPMethod[] getDeclaredMethods() { 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 @Override
@ -166,12 +185,25 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple
if (scope instanceof ICPPClassSpecializationScope) { if (scope instanceof ICPPClassSpecializationScope) {
return ((ICPPClassSpecializationScope) scope).getDeclaredMethods(point); 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 @Override
public final ICPPField[] getDeclaredFields() { 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 @Override
@ -180,12 +212,25 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple
if (scope instanceof ICPPClassSpecializationScope) { if (scope instanceof ICPPClassSpecializationScope) {
return ((ICPPClassSpecializationScope) scope).getDeclaredFields(point); 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 @Override
public final IBinding[] getFriends() { 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 @Override
@ -194,12 +239,14 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple
if (scope instanceof ICPPClassSpecializationScope) { if (scope instanceof ICPPClassSpecializationScope) {
return ((ICPPClassSpecializationScope) scope).getFriends(point); return ((ICPPClassSpecializationScope) scope).getFriends(point);
} }
return super.getFriends(); IBinding[] result = ClassTypeHelper.getFriends((ICPPClassType) rbinding, point);
return wrapBindings(result);
} }
@Override @Override
public final ICPPClassType[] getNestedClasses() { 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 @Override
@ -208,7 +255,8 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple
if (scope instanceof ICPPClassSpecializationScope) { if (scope instanceof ICPPClassSpecializationScope) {
return ((ICPPClassSpecializationScope) scope).getNestedClasses(point); return ((ICPPClassSpecializationScope) scope).getNestedClasses(point);
} }
return super.getNestedClasses(); ICPPClassType[] result = ClassTypeHelper.getNestedClasses((ICPPClassType) rbinding, point);
return wrapBindings(result);
} }
@Override @Override

View file

@ -12,6 +12,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp; 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.EScopeKind;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -69,7 +70,8 @@ public class CompositeCPPClassSpecializationScope extends CompositeScope impleme
@Override @Override
public ICPPMethod[] getImplicitMethods() { 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 @Override
@ -104,7 +106,8 @@ public class CompositeCPPClassSpecializationScope extends CompositeScope impleme
@Override @Override
public ICPPConstructor[] getConstructors() { 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 @Override

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -8,9 +8,12 @@
* Contributors: * Contributors:
* Andrew Ferguson (Symbian) - Initial implementation * Andrew Ferguson (Symbian) - Initial implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp; 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.IName;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IField;
@ -42,8 +45,8 @@ class CompositeCPPClassType extends CompositeCPPBinding implements ICPPClassType
} }
@Override @Override
public final ICPPMethod[] getAllDeclaredMethods() { public ICPPMethod[] getAllDeclaredMethods() {
return ClassTypeHelper.getAllDeclaredMethods(this); return ClassTypeHelper.getAllDeclaredMethods(this, null);
} }
private class CPPBaseDelegate implements ICPPBase { private class CPPBaseDelegate implements ICPPBase {
@ -101,68 +104,48 @@ class CompositeCPPClassType extends CompositeCPPBinding implements ICPPClassType
@Override @Override
public ICPPBase[] getBases() { public ICPPBase[] getBases() {
final ICPPBase[] preresult = ((ICPPClassType) rbinding).getBases(); ICPPBase[] bases = ((ICPPClassType) rbinding).getBases();
ICPPBase[] result = new ICPPBase[preresult.length]; return wrapBases(bases);
for (int i= 0; i < preresult.length; i++) {
result[i] = new CPPBaseDelegate(preresult[i]);
}
return result;
} }
@Override @Override
public ICPPConstructor[] getConstructors() { public ICPPConstructor[] getConstructors() {
ICPPConstructor[] result = ((ICPPClassType) rbinding).getConstructors(); ICPPConstructor[] result = ((ICPPClassType) rbinding).getConstructors();
for (int i= 0; i < result.length; i++) { return wrapBindings(result);
result[i] = (ICPPConstructor) cf.getCompositeBinding((IIndexFragmentBinding) result[i]);
}
return result;
} }
@Override @Override
public ICPPField[] getDeclaredFields() { public ICPPField[] getDeclaredFields() {
ICPPField[] result = ((ICPPClassType) rbinding).getDeclaredFields(); ICPPField[] result = ((ICPPClassType) rbinding).getDeclaredFields();
for (int i= 0; i < result.length; i++) { return wrapBindings(result);
result[i] = (ICPPField) cf.getCompositeBinding((IIndexFragmentBinding) result[i]);
}
return result;
} }
@Override @Override
public ICPPMethod[] getDeclaredMethods() { public ICPPMethod[] getDeclaredMethods() {
ICPPMethod[] result = ((ICPPClassType) rbinding).getDeclaredMethods(); ICPPMethod[] result = ((ICPPClassType) rbinding).getDeclaredMethods();
for (int i= 0; i < result.length; i++) { return wrapBindings(result);
result[i]= (ICPPMethod) cf.getCompositeBinding((IIndexFragmentBinding) result[i]);
}
return result;
} }
@Override @Override
public final IField[] getFields() { public IField[] getFields() {
return ClassTypeHelper.getFields(this); return ClassTypeHelper.getFields(this, null);
} }
@Override @Override
public IBinding[] getFriends() { public IBinding[] getFriends() {
IBinding[] preResult = ((ICPPClassType) rbinding).getFriends(); IBinding[] preResult = ((ICPPClassType) rbinding).getFriends();
IBinding[] result = new IBinding[preResult.length]; return wrapBindings(preResult);
for (int i= 0; i < preResult.length; i++) {
result[i] = cf.getCompositeBinding((IIndexFragmentBinding) preResult[i]);
}
return result;
} }
@Override @Override
public final ICPPMethod[] getMethods() { public ICPPMethod[] getMethods() {
return ClassTypeHelper.getMethods(this); return ClassTypeHelper.getMethods(this, null);
} }
@Override @Override
public ICPPClassType[] getNestedClasses() { public ICPPClassType[] getNestedClasses() {
ICPPClassType[] result = ((ICPPClassType) rbinding).getNestedClasses(); ICPPClassType[] result = ((ICPPClassType) rbinding).getNestedClasses();
for (int i= 0; i < result.length; i++) { return wrapBindings(result);
result[i] = (ICPPClassType) cf.getCompositeBinding((IIndexFragmentBinding) result[i]);
}
return result;
} }
@Override @Override
@ -184,4 +167,21 @@ class CompositeCPPClassType extends CompositeCPPBinding implements ICPPClassType
public boolean isAnonymous() { public boolean isAnonymous() {
return ((ICPPClassType) rbinding).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 extends IBinding> 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;
}
} }

View file

@ -208,7 +208,8 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements
@Override @Override
public ICPPBase[] getBases() { 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 @Override
@ -241,7 +242,8 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements
@Override @Override
public ICPPConstructor[] getConstructors() { 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 @Override
@ -262,7 +264,8 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements
@Override @Override
public ICPPMethod[] getDeclaredMethods() { 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 @Override
@ -283,7 +286,8 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements
@Override @Override
public ICPPField[] getDeclaredFields() { 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 @Override
@ -304,7 +308,8 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements
@Override @Override
public ICPPClassType[] getNestedClasses() { 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 @Override
@ -325,7 +330,8 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements
@Override @Override
public IBinding[] getFriends() { 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 @Override
@ -336,17 +342,35 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements
@Override @Override
public ICPPMethod[] getMethods() { 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 @Override
public ICPPMethod[] getAllDeclaredMethods() { 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 @Override
public IField[] getFields() { 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 @Override

View file

@ -158,7 +158,7 @@ class PDOMCPPClassTemplateSpecialization extends PDOMCPPClassSpecialization
@Override @Override
public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() { 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(); ICPPClassTemplate origTemplate= (ICPPClassTemplate) getSpecializedBinding();
ICPPClassTemplatePartialSpecialization[] orig = origTemplate.getPartialSpecializations(); ICPPClassTemplatePartialSpecialization[] orig = origTemplate.getPartialSpecializations();
ICPPClassTemplatePartialSpecialization[] spec = new ICPPClassTemplatePartialSpecialization[orig.length]; ICPPClassTemplatePartialSpecialization[] spec = new ICPPClassTemplatePartialSpecialization[orig.length];

View file

@ -351,17 +351,17 @@ class PDOMCPPClassType extends PDOMCPPBinding implements IPDOMCPPClassType, IPDO
@Override @Override
public ICPPMethod[] getMethods() { public ICPPMethod[] getMethods() {
return ClassTypeHelper.getMethods(this); return ClassTypeHelper.getMethods(this, null);
} }
@Override @Override
public ICPPMethod[] getAllDeclaredMethods() { public ICPPMethod[] getAllDeclaredMethods() {
return ClassTypeHelper.getAllDeclaredMethods(this); return ClassTypeHelper.getAllDeclaredMethods(this, null);
} }
@Override @Override
public IField[] getFields() { public IField[] getFields() {
return ClassTypeHelper.getFields(this); return ClassTypeHelper.getFields(this, null);
} }
@Override @Override

View file

@ -14,7 +14,6 @@
package org.eclipse.cdt.internal.core.pdom.dom.cpp; package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; 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.ICPPUsingDirective;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.index.IIndexBinding; 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.Util;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; 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.CPPPointerType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType; 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.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.ICPPDeferredClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance; 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); PDOMBinding pdomBinding = addBinding(binding, name);
if (pdomBinding instanceof PDOMCPPClassType || pdomBinding instanceof PDOMCPPClassSpecialization) { if (pdomBinding instanceof PDOMCPPClassType || pdomBinding instanceof PDOMCPPClassSpecialization) {
if (binding instanceof ICPPClassType && name.isDefinition()) { 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) { if (pdomBinding != null) {
getPDOM().putCachedResult(inputBinding, pdomBinding); getPDOM().putCachedResult(inputBinding, pdomBinding);
if (inputBinding instanceof CPPClosureType) { if (inputBinding instanceof CPPClosureType) {
addImplicitMethods(pdomBinding, (ICPPClassType) binding); addImplicitMethods(pdomBinding, (ICPPClassType) binding, fromName);
} }
} }
} catch (DOMException e) { } catch (DOMException e) {
@ -490,17 +491,14 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return result; return result;
} }
private void addImplicitMethods(PDOMBinding type, ICPPClassType binding) throws CoreException { private void addImplicitMethods(PDOMBinding type, ICPPClassType binding, IASTNode point) throws CoreException {
try { try {
final long fileLocalRec= type.getLocalToFileRec(); final long fileLocalRec= type.getLocalToFileRec();
IScope scope = binding.getCompositeScope(); IScope scope = binding.getCompositeScope();
if (scope instanceof ICPPClassScope) { if (scope instanceof ICPPClassScope) {
List<ICPPMethod> old= new ArrayList<ICPPMethod>(); List<ICPPMethod> old= new ArrayList<ICPPMethod>();
if (type instanceof ICPPClassType) { if (type instanceof ICPPClassType) {
IScope oldScope = ((ICPPClassType)type).getCompositeScope(); ArrayUtil.addAll(old, ClassTypeHelper.getImplicitMethods((ICPPClassType) type, point));
if (oldScope instanceof ICPPClassScope) {
old.addAll(Arrays.asList(((ICPPClassScope) oldScope).getImplicitMethods()));
}
} }
ICPPMethod[] implicit= ((ICPPClassScope) scope).getImplicitMethods(); ICPPMethod[] implicit= ((ICPPClassScope) scope).getImplicitMethods();
for (ICPPMethod method : implicit) { for (ICPPMethod method : implicit) {

View file

@ -253,7 +253,7 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod {
@Override @Override
public IType[] getExceptionSpecification() { public IType[] getExceptionSpecification() {
if (isImplicit()) { if (isImplicit()) {
return ClassTypeHelper.getInheritedExceptionSpecification(this); return ClassTypeHelper.getInheritedExceptionSpecification(this, null);
} }
return super.getExceptionSpecification(); return super.getExceptionSpecification();
} }

View file

@ -12,10 +12,12 @@
package org.eclipse.cdt.internal.core.pdom.dom.cpp; package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException; 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.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; 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.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; 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.Util;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
@ -30,8 +32,7 @@ import org.eclipse.core.runtime.CoreException;
* Specialization of a method * Specialization of a method
*/ */
class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization
implements ICPPMethod { implements ICPPMethodSpecialization {
/** /**
* Offset of remaining annotation information (relative to the beginning of * Offset of remaining annotation information (relative to the beginning of
* the record). * the record).
@ -135,9 +136,9 @@ class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization
} }
@Override @Override
public IType[] getExceptionSpecification() { public IType[] getExceptionSpecification(IASTNode point) {
if (isImplicit()) { if (isImplicit()) {
return ClassTypeHelper.getInheritedExceptionSpecification(this); return ClassTypeHelper.getInheritedExceptionSpecification(this, point);
} }
return super.getExceptionSpecification(); return super.getExceptionSpecification();
} }

View file

@ -82,7 +82,7 @@ public class CHQueries {
if (calleeBinding != null) { if (calleeBinding != null) {
findCalledBy1(index, calleeBinding, true, project, result); findCalledBy1(index, calleeBinding, true, project, result);
if (calleeBinding instanceof ICPPMethod) { if (calleeBinding instanceof ICPPMethod) {
IBinding[] overriddenBindings= ClassTypeHelper.findOverridden((ICPPMethod) calleeBinding); IBinding[] overriddenBindings= ClassTypeHelper.findOverridden((ICPPMethod) calleeBinding, null);
for (IBinding overriddenBinding : overriddenBindings) { for (IBinding overriddenBinding : overriddenBindings) {
findCalledBy1(index, overriddenBinding, false, project, result); findCalledBy1(index, overriddenBinding, false, project, result);
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* Tomasz Wesolowski - initial API and implementation * Tomasz Wesolowski - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.editor; 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 { private static OverrideInfo checkForOverride(ICPPMethod testedOverride, IASTNode node) throws DOMException {
IASTFileLocation location = node.getFileLocation(); IASTFileLocation location = node.getFileLocation();
testedOverride.getClassOwner().getBases();
boolean onlyPureVirtual = true; boolean onlyPureVirtual = true;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -227,7 +227,7 @@ public class OverrideIndicatorManager implements ICReconcilingListener {
Set<ICPPClassType> alreadyTestedBases = new HashSet<ICPPClassType>(); Set<ICPPClassType> alreadyTestedBases = new HashSet<ICPPClassType>();
ICPPBase[] bases = testedOverride.getClassOwner().getBases(); ICPPBase[] bases = ClassTypeHelper.getBases(testedOverride.getClassOwner(), node);
// Don't override 'self' in cyclic inheritance // Don't override 'self' in cyclic inheritance
alreadyTestedBases.add(testedOverride.getClassOwner()); alreadyTestedBases.add(testedOverride.getClassOwner());
@ -244,7 +244,6 @@ public class OverrideIndicatorManager implements ICReconcilingListener {
handleBaseClass(testedClass, testedOverride, overridenMethods, shadowedMethods, alreadyTestedBases); handleBaseClass(testedClass, testedOverride, overridenMethods, shadowedMethods, alreadyTestedBases);
for (ICPPMethod overriddenMethod : overridenMethods) { for (ICPPMethod overriddenMethod : overridenMethods) {
if (sb.length() > 0) { if (sb.length() > 0) {
sb.append(MESSAGE_SEPARATOR); sb.append(MESSAGE_SEPARATOR);
} }
@ -289,8 +288,8 @@ public class OverrideIndicatorManager implements ICReconcilingListener {
} }
if (sb.length() > 0) { if (sb.length() > 0) {
OverrideInfo info = new OverrideInfo(location.getNodeOffset(), location.getNodeLength(), markerType, OverrideInfo info = new OverrideInfo(location.getNodeOffset(), location.getNodeLength(),
sb.toString(), bindingToOpen); markerType, sb.toString(), bindingToOpen);
return info; return info;
} }
return null; return null;

View file

@ -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.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
/** /**
* Rename processor for methods. * Rename processor for methods.
*/ */
@ -108,7 +107,7 @@ public class CRenameMethodProcessor extends CRenameGlobalProcessor {
if (binding instanceof ICPPMethod) { if (binding instanceof ICPPMethod) {
ICPPMethod m= (ICPPMethod) binding; ICPPMethod m= (ICPPMethod) binding;
try { try {
IBinding[] bs= ClassTypeHelper.findOverridden(m); IBinding[] bs= ClassTypeHelper.findOverridden(m, argument.getTranslationUnit());
bindings.addAll(Arrays.asList(bs)); bindings.addAll(Arrays.asList(bs));
bs= ClassTypeHelper.findOverriders(getIndex(), m); bs= ClassTypeHelper.findOverriders(getIndex(), m);
bindings.addAll(Arrays.asList(bs)); bindings.addAll(Arrays.asList(bs));

View file

@ -357,7 +357,8 @@ public abstract class CSearchQuery implements ISearchQuery {
if (binding instanceof ICPPMethod) { if (binding instanceof ICPPMethod) {
ICPPMethod m= (ICPPMethod) binding; 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 (msInBases.length > 0) {
if (polymorphicNames == null) { if (polymorphicNames == null) {
polymorphicNames= new ArrayList<IIndexName>(); polymorphicNames= new ArrayList<IIndexName>();

View file

@ -99,7 +99,7 @@ public class LinkedNamesFinder {
} }
} else if (target instanceof ICPPMethod) { } else if (target instanceof ICPPMethod) {
ICPPMethod method= (ICPPMethod) target; ICPPMethod method= (ICPPMethod) target;
for (ICPPMethod m : ClassTypeHelper.findOverridden(method)) { for (ICPPMethod m : ClassTypeHelper.findOverridden(method, root)) {
findBinding(m); findBinding(m);
} }
try { try {

View file

@ -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.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; 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.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration; 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.CPPImplicitFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitMethod; 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.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.dom.parser.cpp.semantics.AccessContext;
import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory; import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory;
@ -309,7 +311,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
if (binding instanceof ICPPClassType) { if (binding instanceof ICPPClassType) {
handleClass((ICPPClassType) binding, astContext, cContext, baseRelevance, proposals); handleClass((ICPPClassType) binding, astContext, cContext, baseRelevance, proposals);
} else if (binding instanceof IFunction) { } else if (binding instanceof IFunction) {
handleFunction((IFunction)binding, cContext, baseRelevance, proposals); handleFunction((IFunction) binding, cContext, baseRelevance, proposals);
} else if (binding instanceof IVariable) { } else if (binding instanceof IVariable) {
handleVariable((IVariable) binding, cContext, baseRelevance, proposals); handleVariable((IVariable) binding, cContext, baseRelevance, proposals);
} else if (!cContext.isContextInformationStyle()) { } else if (!cContext.isContextInformationStyle()) {
@ -466,7 +468,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
t= unwindTypedefs(t); t= unwindTypedefs(t);
if (t instanceof ICPPClassType) { if (t instanceof ICPPClassType) {
ICPPClassType classType= (ICPPClassType) t; ICPPClassType classType= (ICPPClassType) t;
ICPPConstructor[] constructors = classType.getConstructors(); IASTTranslationUnit ast = context.getCompletionNode().getTranslationUnit();
ICPPConstructor[] constructors = ClassTypeHelper.getConstructors(classType, ast);
for (ICPPConstructor constructor : constructors) { for (ICPPConstructor constructor : constructors) {
handleFunction(constructor, context, baseRelevance, proposals); handleFunction(constructor, context, baseRelevance, proposals);
} }

View file

@ -511,7 +511,7 @@ public class IndexUI {
// Check for specializations of the owner // Check for specializations of the owner
IBinding owner = binding.getOwner(); IBinding owner = binding.getOwner();
if (owner != null) { 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)) { for (IBinding specOwner : findSpecializations(index, owner)) {
if (specOwner instanceof ICPPClassSpecialization) { if (specOwner instanceof ICPPClassSpecialization) {
// Add the specialized member // Add the specialized member