diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/BindingClassifierTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/BindingClassifierTest.java index 3dfc22a7adf..9d5d48a1c48 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/BindingClassifierTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/BindingClassifierTest.java @@ -128,6 +128,22 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase { // td1 a = *f(); public void testTypedef_2() throws Exception { assertDefined("f", "td1"); + assertDeclared(); + } + + // template struct allocator {}; + // template> class basic_string {}; + // typedef basic_string string; + // template + // basic_string f(const T* a, const basic_string& b); + + // void test() { + // string a; + // f("*", a); + // } + public void testTypedef_3() throws Exception { + assertDefined("f", "string"); // "basic_string" and "allocator" should not be defined. + assertDeclared(); } // class A { int x; }; @@ -137,6 +153,7 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase { // int a = f()->x; public void testClassMember() throws Exception { assertDefined("f", "A"); + assertDeclared(); } // class A { void m(); }; @@ -146,6 +163,7 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase { // } public void testMethodCall() throws Exception { assertDefined("A"); + assertDeclared(); } // struct A {}; @@ -167,17 +185,42 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase { // } public void testVariableReference() throws Exception { assertDefined("a"); // Forward declaration of variables is not allowed by default. + assertDeclared(); } // struct A { // void operator()(int p); // }; - // const A a; + // const A& a; // void test() { // a(1); // } public void testCallOperator() throws Exception { - assertDefined("A", "a"); // Forward declaration of variables is not allowed by default. + assertDefined("A", "a"); + assertDeclared(); + } + + // struct A {}; + // template struct B {}; + // template> struct C {}; + + // struct D : public C {}; + public void testTemplate_1() throws Exception { + assertDefined("C"); + assertDeclared("A"); + } + + // struct A {}; + // template struct B {}; + // template> struct C {}; + // struct D : public C {}; + + // void test() { + // D d; + // } + public void testTemplate_2() throws Exception { + assertDefined("D"); + assertDeclared(); } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/IncludeOrganizerTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/IncludeOrganizerTest.java index 34e450a1ede..f73ea2f8c15 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/IncludeOrganizerTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/IncludeOrganizerTest.java @@ -165,7 +165,8 @@ public class IncludeOrganizerTest extends IncludesTestBase { //#pragma once // //#include "B.h" - //#include "C.h" + // + //class C; // //namespace ns { //// Comment line 1 diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/BindingClassifier.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/BindingClassifier.java index fd1854e7d88..ccf5112b159 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/BindingClassifier.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/BindingClassifier.java @@ -84,13 +84,12 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.index.IIndexMacro; import org.eclipse.cdt.core.index.IndexFilter; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; + /** * For a whole translation unit or a part of it determines a set of externally defined bindings that * must be defined and a set of bindings that must be declared. @@ -395,12 +394,17 @@ public class BindingClassifier { if (!fProcessedDefinedBindings.add(binding)) return; - if (fAst.getDefinitionsInAST(binding).length != 0) { - return; // Defined locally + if (binding instanceof ITypedef) { + IType type = ((ITypedef) binding).getType(); + type = SemanticUtil.getNestedType(type, ALLCVQ); + if (type instanceof IBinding) { + // Record the fact that we also have a definition of the typedef's target type. + fProcessedDefinedBindings.add((IBinding) type); + } } - if (binding instanceof ICPPTemplateInstance) { - defineTemplateArguments((ICPPTemplateInstance) binding); + if (fAst.getDefinitionsInAST(binding).length != 0) { + return; // Defined locally } List requiredBindings = getRequiredBindings(binding); @@ -410,43 +414,6 @@ public class BindingClassifier { } } - /** - * Defines non-pointer template arguments. - */ - protected void defineTemplateArguments(ICPPTemplateInstance instance) { - ICPPTemplateDefinition templateDefinition = instance.getTemplateDefinition(); - ICPPTemplateParameter[] templateParameters = templateDefinition.getTemplateParameters(); - ICPPTemplateArgument[] templateArguments = instance.getTemplateArguments(); - for (int i = 0; i < templateArguments.length; i++) { - ICPPTemplateArgument argument = templateArguments[i]; - ICPPTemplateParameter parameter = templateParameters[i]; - ICPPTemplateArgument parameterDefault = parameter.getDefaultValue(); - if (parameterDefault != null) { - // Skip the template arguments if it is the same as parameter default. - if (argument.isSameValue(parameterDefault)) - continue; - if (argument.isTypeValue() && parameterDefault.isTypeValue()) { - IType argType = argument.getTypeValue(); - IType defType = parameterDefault.getTypeValue(); - if (argType instanceof ICPPTemplateInstance && defType instanceof ICPPTemplateInstance) { - IType argTemplate = (IType) ((ICPPTemplateInstance) argType).getTemplateDefinition(); - IType defTemplate = (IType) ((ICPPTemplateInstance) defType).getTemplateDefinition(); - if (argTemplate.isSameType(defTemplate)) { - defineTemplateArguments((ICPPTemplateInstance) argType); - continue; - } - } - } - } - IType type = argument.getTypeValue(); - if (!(type instanceof IPointerType) && !(type instanceof ICPPReferenceType)) { - IBinding binding = getTypeBinding(type); - if (binding != null) - defineBinding(binding); - } - } - } - private void declareFunction(IFunction function, IASTFunctionCallExpression functionCallExpression) { // Handle return or expression type of the function or constructor call. IType returnType = function.getType().getReturnType();