diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexListenerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexListenerTest.java index b7358ff8208..17a09d0c47a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexListenerTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexListenerTest.java @@ -80,7 +80,7 @@ public class IndexListenerTest extends BaseTestCase { if (state[0]+state[1] < 2) { mutex.wait(8000); if (state[0]+state[1] < 2) { - mutex.wait(2000); + mutex.wait(5000); } } assertEquals(1, state[0]); @@ -114,7 +114,7 @@ public class IndexListenerTest extends BaseTestCase { IFile file= TestSourceReader.createFile(fProject1.getProject(), "test.cpp", "int a;"); synchronized (mutex) { - mutex.wait(2000); + mutex.wait(8000); } assertEquals(1, projects.size()); assertTrue(projects.contains(fProject1)); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java index 956fb226e7b..784200f7820 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java @@ -123,28 +123,23 @@ public class CPPFunctionTests extends PDOMTestBase { assertDefinitionCount(pdom, "forwardDeclaration", 1); } - public void _testVoidFunction() throws Exception { - // Type information not yet stored in PDOM. + public void testVoidFunction() throws Exception { assertReturnType(pdom, "voidCPPFunction", IBasicType.t_void); } - public void _testIntFunction() throws Exception { - // Type information not yet stored in PDOM. + public void testIntFunction() throws Exception { assertReturnType(pdom, "intCPPFunction", IBasicType.t_int); } - public void _testDoubleFunction() throws Exception { - // Type information not yet stored in PDOM. + public void testDoubleFunction() throws Exception { assertReturnType(pdom, "doubleCPPFunction", IBasicType.t_double); } - public void _testCharFunction() throws Exception { - // Type information not yet stored in PDOM. + public void testCharFunction() throws Exception { assertReturnType(pdom, "charCPPFunction", IBasicType.t_char); } - public void _testFloatFunction() throws Exception { - // Type information not yet stored in PDOM. + public void testFloatFunction() throws Exception { assertReturnType(pdom, "floatCPPFunction", IBasicType.t_float); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionTestBase.java index a6c53b520c7..35488bfc839 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionTestBase.java @@ -81,7 +81,8 @@ public abstract class IndexBindingResolutionTestBase extends PDOMTestBase { protected IBinding getBindingFromASTName(String section, int len) { IASTName[] names= ast.getLanguage().getSelectedNames(ast, testData[1].indexOf(section), len); assertEquals("<>1 name found for \""+section+"\"", 1, names.length); - assertNotNull("No binding for "+names[0].getRawSignature(), names[0].resolveBinding()); + IBinding binding = names[0].resolveBinding(); + assertNotNull("No binding for "+names[0].getRawSignature(), binding); assertFalse("Binding is a ProblemBinding for name "+names[0].getRawSignature(), IProblemBinding.class.isAssignableFrom(names[0].resolveBinding().getClass())); return names[0].resolveBinding(); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexCPPBindingResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexCPPBindingResolutionTest.java index 273f0289518..735f76397e3 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexCPPBindingResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexCPPBindingResolutionTest.java @@ -55,7 +55,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas // long * CS::* autsch; // C * CS::* method(CS **); // }; - + // // referencing file // #include "header.h" // void references() { @@ -73,6 +73,32 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas IBinding b3 = getBindingFromASTName("cs)->*cp->a", 2); IBinding b4 = getBindingFromASTName("autsch = lp", 6); IBinding b5 = getBindingFromASTName("ouch;", 4); + } + + // // header file + + // class C { + // public: + // int field; + // struct CS { long* l; C *method(CS **); }; + // CS cs; + // CS **cspp; + // long * CS::* ouch; + // long * CS::* autsch; + // C * CS::* method(CS **); + // }; + // // referencing file + // #include "header.h" + // void references() { + // C *cp = new C(); + // long l = 5, *lp; + // lp = &l; + // cp->cs.*cp->ouch = lp = cp->cs.*cp->autsch; + // &(cp->cs)->*cp->autsch = lp = &(cp->cs)->*cp->ouch; + // cp->cs.*method(cp->cspp);/*1*/ &(cp->cs)->*method(cp->cspp);/*2*/ + // } + public void _testPointerToMemberFields_2() throws IOException { + // fails with AST parser, only (the header is empty) IBinding b6 = getBindingFromASTName("method(cp->cspp);/*1*/", 6); IBinding b7 = getBindingFromASTName("method(cp->cspp);/*2*/", 6); } @@ -367,10 +393,10 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas // void m1() { e1 = ER1; } // static void m2() { e2 = ER2; } // }; - public void _testEnumeratorInClassScope() { + public void testEnumeratorInClassScope() { IBinding b0 = getBindingFromASTName("E e1", 1); - IBinding b1 = getBindingFromASTName("ER1; }", 1); - IBinding b2 = getBindingFromASTName("ER2; }", 1); + IBinding b1 = getBindingFromASTName("ER1; }", 3); + IBinding b2 = getBindingFromASTName("ER2; }", 3); } // // header content @@ -426,7 +452,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas // #include "header.h" // void ref() { foo(); } - public void _testFunctionDefaultArguments() { + public void testFunctionDefaultArguments() { IBinding b0 = getBindingFromASTName("foo();", 3); } @@ -442,7 +468,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas // d.foo(4); // also calls long version (int version is hidden) // // aftodo - does this test make sense? // } - public void _testMethodHidingInInheritance() { + public void testMethodHidingInInheritance() { IBinding b0 = getBindingFromASTName("d; /*d*/", 1); IBinding b1 = getBindingFromASTName("foo(55L);", 3); IBinding b2 = getBindingFromASTName("foo(4);", 3); @@ -493,7 +519,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas ////reference content //void references() { // a[0]->i/*0*/++; (*a[0]).i/*1*/++; // IASTArraySubscriptExpression - // /* not applicable */ ?? // IASTBinaryExpression + // /* not applicable ?? */ // IASTBinaryExpression // ((S*)sp)->i/*3*/++; ((S)s).i/*4*/++; //aftodo-valid? // IASTCastExpression // (true ? sp : sp)->i/*5*/++; (true ? s : s).i/*6*/++; // IASTConditionalExpression // (sp,sp)->i/*7*/++; (s,s).i/*8*/++; // IASTExpressionList @@ -507,7 +533,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas // /* not applicable */ // ICPPASTDeleteExpression // (new S())->i/*18*/++; // ICPPASTNewExpression //} - public void _testFieldReference() { + public void testFieldReference() { IBinding b0 = getBindingFromASTName("i/*0*/", 1); IBinding b1 = getBindingFromASTName("i/*1*/", 1); // IBinding b2 = getBindingFromASTName(ast, "i/*2*/", 1); @@ -559,6 +585,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas // // foo/*p*/(MADE_UP_SYMBOL); // ICPPASTTypenameExprssion // } public void _testExpressionKindForFunctionCalls() { + // depends on bug 164470 because resolution takes place during parse. IBinding b0 = getBindingFromASTName("foo/*a*/", 3); IBinding b0a = getBindingFromASTName("cp[1]", 2); // assertCompositeTypeParam(0, ICPPClassType.k_class, b0, "C"); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java index 9685c5de726..243e02e1fdd 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java @@ -125,7 +125,7 @@ public class PDOMSearchTest extends PDOMTestBase { /** result #1 * */ ICPPClassType class1 = (ICPPClassType) class1s[0]; assertEquals("Class1", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(class1))); - IBinding[] methods = class1.getMethods(); + IBinding[] methods = class1.getDeclaredMethods(); assertEquals(0, methods.length); /** result #2 * */ @@ -135,7 +135,7 @@ public class PDOMSearchTest extends PDOMTestBase { /* Members in this class */ // methods - methods = class2.getMethods(); + methods = class2.getDeclaredMethods(); assertEquals(2, methods.length); assertEquals("Class1", methods[0].getName()); assertEquals("~Class1", methods[1].getName()); @@ -159,7 +159,7 @@ public class PDOMSearchTest extends PDOMTestBase { /** result #4 * */ ICPPClassType class4 = (ICPPClassType) class1s[3]; assertEquals("namespace1::namespace2::Class1", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(class4))); - methods = class4.getMethods(); + methods = class4.getDeclaredMethods(); assertEquals(0, methods.length); /* Search for "Class2" */ @@ -173,7 +173,7 @@ public class PDOMSearchTest extends PDOMTestBase { /** result #1 * */ ICPPClassType cls1 = (ICPPClassType) class2s[0]; assertEquals("Class2", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(cls1))); - methods = cls1.getMethods(); + methods = cls1.getDeclaredMethods(); assertEquals(3, methods.length); assertEquals("Class2", methods[0].getName()); assertEquals("~Class2", methods[1].getName()); @@ -223,7 +223,7 @@ public class PDOMSearchTest extends PDOMTestBase { public void testMethods() throws Exception { - IBinding[] methods = pdom.findBindings(Pattern.compile("~Class2"), false, INDEX_FILTER,NULL_MONITOR); + IBinding[] methods = pdom.findBindings(Pattern.compile("~Class2"), false, INDEX_FILTER, NULL_MONITOR); assertEquals(1, methods.length); assertTrue(methods[0] instanceof ICPPMethod); assertEquals("Class2::~Class2", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(methods[0]))); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/TypesTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/TypesTests.java index cbe848fc2fc..e3ce3f63682 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/TypesTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/TypesTests.java @@ -76,7 +76,7 @@ public class TypesTests extends PDOMTestBase { IBinding [] As = pdom.findBindings(Pattern.compile("A"), false, new IndexFilter(), new NullProgressMonitor()); assertEquals(1, As.length); ICPPClassType A = (ICPPClassType)As[0]; - ICPPMethod[] Amethods = A.getMethods(); + ICPPMethod[] Amethods = A.getDeclaredMethods(); assertEquals(1, Amethods.length); ICPPMethod f = Amethods[0]; assertEquals("f", f.getName()); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IProblemBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IProblemBinding.java index 62bb8e7c361..2c6a774b92b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IProblemBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IProblemBinding.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* @@ -128,5 +129,8 @@ public interface IProblemBinding extends IBinding, IScope, IType { public static final int SEMANTIC_MEMBER_DECLARATION_NOT_FOUND = 0x00D; - public static final int LAST_PROBLEM = SEMANTIC_MEMBER_DECLARATION_NOT_FOUND; + public static final int SEMANTIC_RECURSION_IN_LOOKUP = 0x00E; + + public static final int LAST_PROBLEM = SEMANTIC_RECURSION_IN_LOOKUP; + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPBasicType.java index 76c52c6f230..d99d2769f3b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPBasicType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* * Created on Dec 10, 2004 @@ -19,8 +20,20 @@ import org.eclipse.cdt.core.dom.ast.IBasicType; * @author aniefer */ public interface ICPPBasicType extends IBasicType { + public static final int IS_LONG = 1; + public static final int IS_SHORT = 1 << 1; + public static final int IS_SIGNED = 1 << 2; + public static final int IS_UNSIGNED = 1 << 3; + public static final int LAST = IS_UNSIGNED; + // Extra types public static final int t_bool = ICPPASTSimpleDeclSpecifier.t_bool; public static final int t_wchar_t = ICPPASTSimpleDeclSpecifier.t_wchar_t; + + /** + * @return a combination of qualifiers. + * @since 4.0 + */ + public int getQualifierBits(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethod.java index a10dc6a8eb3..898d9bdbd61 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethod.java @@ -31,4 +31,10 @@ public interface ICPPMethod extends ICPPFunction, ICPPMember { * returns true if its name starts with '~' */ public boolean isDestructor() throws DOMException; + + /** + * Returns whether this is an implicit method (constructor, assignment operator, etc.) + * @since 4.0 + */ + public boolean isImplicit(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPParameter.java index 60ded666509..2b65eb1e301 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPParameter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,13 +7,13 @@ * * Contributors: * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* * Created on Apr 20, 2005 */ package org.eclipse.cdt.core.dom.ast.cpp; -import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IParameter; /** @@ -23,8 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IParameter; public interface ICPPParameter extends IParameter, ICPPVariable { /** - * the default value of this parameter or null if there is none. - * @return + * if there is a default value or not. */ - public IASTInitializer getDefaultValue(); + public boolean hasDefaultValue(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndex.java index d076ff586ab..ff2336f41ff 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndex.java @@ -14,6 +14,7 @@ package org.eclipse.cdt.core.index; import java.util.regex.Pattern; +import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.core.runtime.CoreException; @@ -222,6 +223,24 @@ public interface IIndex { */ public IIndexBinding[] findBindings(Pattern[] patterns, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException; + /** + * Searches the global scope for all bindings of a given name and linkage. + * In case a binding exists in multiple projects, no duplicate bindings are returned. + * @param linkage the linkage to be searched + * @param name a simple (unqualified) name. + * @return an array of bindings + */ + public IBinding[] findInGlobalScope(ILinkage linkage, char[] name); + + /** + * Searches the given namespace for all bindings of a given name. + * In case a binding exists in multiple projects, no duplicate bindings are returned. + * @param nsbinding the namespace to be searched. + * @param name a simple (unqualified) name. + * @return an array of bindings + */ + public IBinding[] findInNamespace(IBinding nsbinding, char[] name); + /** * Searches for all names that resolve to the given binding. You can limit the result to references, declarations * or definitions, or a combination of those. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexBinding.java index dabbbef505a..a8c23d0e42c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexBinding.java @@ -12,7 +12,6 @@ package org.eclipse.cdt.core.index; import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.core.runtime.CoreException; /** * Represents the semantics of a name in the index. @@ -30,10 +29,10 @@ import org.eclipse.core.runtime.CoreException; * @since 4.0 */ public interface IIndexBinding extends IBinding { + IIndexBinding[] EMPTY_INDEX_BINDING_ARRAY = new IIndexBinding[0]; + /** - * Returns the enclosing binding. May return null. To give an example, for a member function - * the parent binding would be the class defining the member. - * @throws CoreException + * Returns the qualified name of this binding as array of strings. */ - IIndexBinding getParentBinding() throws CoreException; + String[] getQualifiedName(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexFilter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexFilter.java index 5289831df02..20dddfdb8ef 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexFilter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexFilter.java @@ -28,16 +28,6 @@ import org.eclipse.cdt.core.dom.ILinkage; public class IndexFilter { public static final IndexFilter ALL = new IndexFilter(); - /** - * Returns whether or not to include objects of the given linkage in the query. - * @see IIndex#findBindings(java.util.regex.Pattern, boolean, IndexFilter, org.eclipse.core.runtime.IProgressMonitor) - * @param linkage a linkage to be tested - * @return whether to include objects of the given linkage in the query. - */ - public boolean acceptLinkage(ILinkage linkage) { - return true; - } - /** * Get an IndexFilter that filters out bindings from linkages other than that * specified @@ -51,4 +41,24 @@ public class IndexFilter { } }; } + + /** + * Returns whether or not to include objects of the given linkage in the query. + * @see IIndex#findBindings(java.util.regex.Pattern, boolean, IndexFilter, org.eclipse.core.runtime.IProgressMonitor) + * @param linkage a linkage to be tested + * @return whether to include objects of the given linkage in the query. + */ + public boolean acceptLinkage(ILinkage linkage) { + return true; + } + + /** + * Returns whether or not to include implicit methods in the query. + * @see IIndex#findBindings(java.util.regex.Pattern, boolean, IndexFilter, org.eclipse.core.runtime.IProgressMonitor) + * @return whether or not to include implicit methods in the query. + * @since 4.0 + */ + public boolean acceptImplicitMethods() { + return false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayUtils.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayUtils.java index e69387320ce..4723647b57e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayUtils.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayUtils.java @@ -52,7 +52,19 @@ public class CharArrayUtils { return true; } - + + public static final boolean equals(char[][] strarr1, char[][] strarr2) { + if (strarr1.length != strarr2.length) { + return false; + } + for (int i = 0; i < strarr2.length; i++) { + if (!equals(strarr1[i], strarr2[i])) { + return false; + } + } + return true; + } + /** * Implements a lexicographical comparator for char arrays. Comparison is done * on a per char basis, not a code-point basis. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java index 04cced1fc2e..fd7f132cab4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java @@ -14,13 +14,13 @@ package org.eclipse.cdt.internal.core.dom.parser; import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.IASTBuiltinSymbolProvider; -import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.util.ArrayUtil; @@ -265,15 +265,15 @@ public class GCCBuiltinSymbolProvider implements IASTBuiltinSymbolProvider { cpp_float = new CPPBasicType(IBasicType.t_float, 0); cpp_float_complex = new GPPBasicType(IBasicType.t_float, GPPBasicType.IS_COMPLEX, null); cpp_int = new CPPBasicType(IBasicType.t_int, 0); - cpp_long_int = new CPPBasicType(IBasicType.t_int, CPPBasicType.IS_LONG); - cpp_long_double = new CPPBasicType(IBasicType.t_double, CPPBasicType.IS_LONG); - cpp_long_double_complex = new GPPBasicType(IBasicType.t_double, CPPBasicType.IS_LONG | GPPBasicType.IS_COMPLEX, null); + cpp_long_int = new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_LONG); + cpp_long_double = new CPPBasicType(IBasicType.t_double, ICPPBasicType.IS_LONG); + cpp_long_double_complex = new GPPBasicType(IBasicType.t_double, ICPPBasicType.IS_LONG | GPPBasicType.IS_COMPLEX, null); cpp_long_long_int = new CPPBasicType(IBasicType.t_int, GPPBasicType.IS_LONGLONG); - cpp_signed_long_int = new CPPBasicType(IBasicType.t_int, CPPBasicType.IS_LONG | CPPBasicType.IS_SIGNED); + cpp_signed_long_int = new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_LONG | ICPPBasicType.IS_SIGNED); - cpp_unsigned_int = new CPPBasicType(IBasicType.t_int, CPPBasicType.IS_UNSIGNED); - cpp_unsigned_long = new CPPBasicType(IBasicType.t_int, CPPBasicType.IS_UNSIGNED | CPPBasicType.IS_LONG); - cpp_unsigned_long_long = new GPPBasicType(IBasicType.t_int, CPPBasicType.IS_UNSIGNED | GPPBasicType.IS_LONGLONG, null); + cpp_unsigned_int = new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_UNSIGNED); + cpp_unsigned_long = new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_UNSIGNED | ICPPBasicType.IS_LONG); + cpp_unsigned_long_long = new GPPBasicType(IBasicType.t_int, ICPPBasicType.IS_UNSIGNED | GPPBasicType.IS_LONGLONG, null); cpp_size_t = cpp_unsigned_long; // assumed unsigned long int cpp_va_list = new CPPFunctionType( cpp_char_p, new IType[0]); // assumed: char * va_list(); @@ -2416,11 +2416,8 @@ public class GCCBuiltinSymbolProvider implements IASTBuiltinSymbolProvider { return null; } - /** - * return false - */ - public IASTInitializer getDefaultValue() { - return null; + public boolean hasDefaultValue() { + return false; } /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java index 25b689d047f..ff020287f5e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java @@ -67,6 +67,7 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I errorMessages[SEMANTIC_INVALID_REDEFINITION - 1] = ParserMessages.getString("ASTProblemFactory.error.semantic.dom.invalidRedefinition"); //$NON-NLS-1$ errorMessages[SEMANTIC_INVALID_REDECLARATION - 1] = ParserMessages.getString("ASTProblemFactory.error.semantic.dom.invalidRedeclaration"); //$NON-NLS-1$ errorMessages[SEMANTIC_BAD_SCOPE - 1] = ParserMessages.getString("ASTProblemFactory.error.semantic.dom.badScope"); //$NON-NLS-1$ + errorMessages[SEMANTIC_RECURSION_IN_LOOKUP - 1] = ParserMessages.getString("ASTProblemFactory.error.semantic.dom.recursionInResolution"); //$NON-NLS-1$ errorMessages[SEMANTIC_MEMBER_DECLARATION_NOT_FOUND - 1]= ParserMessages.getString("ASTProblemFactory.error.semantic.dom.memberDeclNotFound"); //$NON-NLS-1$ } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java index 301cab170d3..8f058dca803 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -16,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICBasicType; +import org.eclipse.cdt.internal.core.index.IIndexType; /** * @author dsteffle @@ -116,7 +118,7 @@ public class CBasicType implements ICBasicType { public boolean isSameType(IType obj) { if( obj == this ) return true; - if( obj instanceof ITypedef ) + if( obj instanceof ITypedef || obj instanceof IIndexType) return obj.isSameType( this ); if (!(obj instanceof CBasicType)) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java index e78d089590f..bff0f339ae6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java @@ -31,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier; import org.eclipse.cdt.internal.core.dom.Linkage; +import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.core.runtime.PlatformObject; /** @@ -154,7 +155,7 @@ public class CEnumeration extends PlatformObject implements IEnumeration { public boolean isSameType( IType type ) { if( type == this ) return true; - if( type instanceof ITypedef ) + if( type instanceof ITypedef || type instanceof IIndexType) return type.isSameType( this ); return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CQualifiedPointerType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CQualifiedPointerType.java index 43610f682ac..97e44c3e1dd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CQualifiedPointerType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CQualifiedPointerType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -16,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier; import org.eclipse.cdt.core.dom.ast.c.ICPointerType; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; +import org.eclipse.cdt.internal.core.index.IIndexType; /** * @author dsteffle @@ -80,7 +82,7 @@ public class CQualifiedPointerType implements ICPointerType, ITypeContainer { public boolean isSameType( IType type ) { if( type == this ) return true; - if( type instanceof ITypedef ) + if( type instanceof ITypedef || type instanceof IIndexType) return type.isSameType( this ); if( type instanceof CQualifiedPointerType ){ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java index 2bc69c23d72..69ee7806bb6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java @@ -36,6 +36,7 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; +import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.core.runtime.PlatformObject; /** @@ -257,7 +258,7 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte public boolean isSameType( IType type ) { if( type == this ) return true; - if( type instanceof ITypedef ) + if( type instanceof ITypedef || type instanceof IIndexType) return type.isSameType( this ); return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java index b2400faa9da..73cbf7de8e1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -15,18 +16,32 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNameOwner; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IProblemBinding; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; +import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; /** * @author jcamelon */ public class CPPASTName extends CPPASTNode implements IASTName { + private final static class RecursionResolvingBinding extends ProblemBinding { + public RecursionResolvingBinding() { + super(null, IProblemBinding.SEMANTIC_RECURSION_IN_LOOKUP, CharArrayUtils.EMPTY); + } + public RecursionResolvingBinding(IASTName node) { + super(node, IProblemBinding.SEMANTIC_RECURSION_IN_LOOKUP, node.toCharArray()); + } + } - private char[] name; + private char[] name; private static final char[] EMPTY_CHAR_ARRAY = {}; private static final String EMPTY_STRING = ""; //$NON-NLS-1$ + private static final int MAX_RESOLUTION_DEPTH = 3; + private IBinding binding = null; + private int fResolutionDepth= 0; /** * @param name @@ -48,9 +63,14 @@ public class CPPASTName extends CPPASTNode implements IASTName { * @see org.eclipse.cdt.core.dom.ast.IASTName#resolveBinding() */ public IBinding resolveBinding() { - if (binding == null) - binding = CPPVisitor.createBinding(this); - + if (binding == null) { + if (++fResolutionDepth > MAX_RESOLUTION_DEPTH) { + binding= new RecursionResolvingBinding(this); + } + else { + binding = CPPVisitor.createBinding(this); + } + } return binding; } @@ -60,6 +80,7 @@ public class CPPASTName extends CPPASTNode implements IASTName { public void setBinding(IBinding binding) { this.binding = binding; + fResolutionDepth= 0; } public IBinding getBinding() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java index fe6dd673df6..52f7e234416 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* * Created on Dec 10, 2004 @@ -18,16 +19,12 @@ import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; +import org.eclipse.cdt.internal.core.index.IIndexType; /** * @author aniefer */ public class CPPBasicType implements ICPPBasicType { - public static final int IS_LONG = 1; - public static final int IS_SHORT = 1 << 1; - public static final int IS_SIGNED = 1 << 2; - public static final int IS_UNSIGNED = 1 << 3; - protected static final int LAST = IS_UNSIGNED; protected int qualifierBits = 0; protected int type; @@ -53,7 +50,7 @@ public class CPPBasicType implements ICPPBasicType { if( object == this ) return true; - if( object instanceof ITypedef ) + if( object instanceof ITypedef || object instanceof IIndexType) return object.isSameType( this ); if( !(object instanceof CPPBasicType) ) @@ -127,4 +124,8 @@ public class CPPBasicType implements ICPPBasicType { public void setValue( IASTExpression val ){ value = val; } + + public int getQualifierBits() { + return qualifierBits; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java index 7835bc686ec..88039eb325f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java @@ -58,6 +58,7 @@ import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; +import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.core.runtime.PlatformObject; /** @@ -778,8 +779,8 @@ public class CPPClassType extends PlatformObject implements ICPPClassType, ICPPI public boolean isSameType( IType type ) { if( type == this ) return true; - if( type instanceof ITypedef ) - return ((ITypedef)type).isSameType( this ); + if( type instanceof ITypedef || type instanceof IIndexType) + return type.isSameType( this ); return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java index 1d6bd3256b5..0828255897c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* @@ -27,6 +28,7 @@ import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.internal.core.dom.Linkage; +import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.core.runtime.PlatformObject; /** @@ -186,8 +188,8 @@ public class CPPEnumeration extends PlatformObject implements IEnumeration, ICPP public boolean isSameType( IType type ) { if( type == this ) return true; - if( type instanceof ITypedef ) - return ((ITypedef)type).isSameType( this ); + if( type instanceof ITypedef || type instanceof IIndexType) + return type.isSameType( this ); return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java index 3e8f1bb410c..b3a9e2653c2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java @@ -177,7 +177,9 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt IScope scope = getScope(); try { IASTNode node = ASTInternal.getPhysicalNodeOfScope(scope); - tu = node.getTranslationUnit(); + if (node != null) { + tu = node.getTranslationUnit(); + } } catch ( DOMException e ) { } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java index 711ea946898..99205a17daa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java @@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IType; @@ -87,6 +88,9 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod IType [] params = ftype.getParameterTypes(); ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(getScope()); + if (compSpec == null) { + return null; + } IASTDeclaration [] members = compSpec.getMembers(); for( int i = 0; i < members.length; i++ ){ IASTDeclarator dtor = null; @@ -113,21 +117,28 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod { IFunctionType t = (IFunctionType) CPPVisitor.createType( dtor ); IType [] ps = t.getParameterTypes(); + boolean ok= false; if( ps.length == params.length ){ int idx = 0; for( ; idx < ps.length && ps[idx] != null; idx++ ){ if( !ps[idx].isSameType(params[idx]) ) break; } - if( idx == ps.length ){ - name.setBinding( this ); - if( member instanceof IASTSimpleDeclaration ) - addDeclaration( dtor ); - else if( member instanceof IASTFunctionDefinition ) - addDefinition( dtor ); - return members[i]; + ok= idx == ps.length; + } + else if (ps.length == 0) { + if (params.length == 1) { + IType t1= params[0]; + ok = (t1 instanceof IBasicType) && ((IBasicType) t1).getType() == IBasicType.t_void; } - + } + if (ok) { + name.setBinding( this ); + if( member instanceof IASTSimpleDeclaration ) + addDeclaration( dtor ); + else if( member instanceof IASTFunctionDefinition ) + addDefinition( dtor ); + return members[i]; } } dtor = ( di > -1 && ++ di < ds.length ) ? ds[di] : null; @@ -146,4 +157,12 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod return n[0] == '~'; return false; } + + public boolean isImplicit() { + try { + return getPrimaryDeclaration() == null; + } catch (DOMException e) { + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java index fe66a070476..ae6e79686e1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java @@ -64,6 +64,9 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { return false; } + public boolean isImplicit() { + return ((ICPPMethod)getBinding()).isImplicit(); + } } public static class CPPMethodProblem extends CPPFunctionProblem implements ICPPMethod { @@ -98,6 +101,10 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { return false; } + + public boolean isImplicit() { + return false; + } } public CPPMethod( ICPPASTFunctionDeclarator declarator ){ @@ -121,25 +128,27 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { ICPPClassScope scope = (ICPPClassScope) getScope(); ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(scope); - IASTDeclaration [] members = compSpec.getMembers(); - for( int i = 0; i < members.length; i++ ){ - if( members[i] instanceof IASTSimpleDeclaration ){ - IASTDeclarator [] dtors = ((IASTSimpleDeclaration)members[i]).getDeclarators(); - for( int j = 0; j < dtors.length; j++ ){ - IASTName name = dtors[j].getName(); + if (compSpec != null) { + IASTDeclaration [] members = compSpec.getMembers(); + for( int i = 0; i < members.length; i++ ){ + if( members[i] instanceof IASTSimpleDeclaration ){ + IASTDeclarator [] dtors = ((IASTSimpleDeclaration)members[i]).getDeclarators(); + for( int j = 0; j < dtors.length; j++ ){ + IASTName name = dtors[j].getName(); + if( CharArrayUtils.equals( name.toCharArray(), myName ) && + name.resolveBinding() == this ) + { + return members[i]; + } + } + } else if( members[i] instanceof IASTFunctionDefinition ){ + IASTName name = ((IASTFunctionDefinition) members[i]).getDeclarator().getName(); if( CharArrayUtils.equals( name.toCharArray(), myName ) && - name.resolveBinding() == this ) + name.resolveBinding() == this ) { return members[i]; } } - } else if( members[i] instanceof IASTFunctionDefinition ){ - IASTName name = ((IASTFunctionDefinition) members[i]).getDeclarator().getName(); - if( CharArrayUtils.equals( name.toCharArray(), myName ) && - name.resolveBinding() == this ) - { - return members[i]; - } } } return null; @@ -278,4 +287,8 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { return false; } + + public boolean isImplicit() { + return false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodInstance.java index bf6993f6086..eaa47bbcc5e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodInstance.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* * Created on Mar 29, 2005 @@ -65,4 +66,8 @@ public class CPPMethodInstance extends CPPFunctionInstance implements ICPPMethod return false; } + public boolean isImplicit() { + return false; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java index ad4d0b587dc..70828e567e4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,7 +7,7 @@ * * Contributors: * IBM - Initial API and implementation - * / + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* * Created on Apr 29, 2005 @@ -82,4 +82,8 @@ public class CPPMethodSpecialization extends CPPFunctionSpecialization return false; } + public boolean isImplicit() { + return false; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java index acaca8a1de2..136cae47023 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java @@ -151,4 +151,8 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements return false; } + public boolean isImplicit() { + return false; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplateSpecialization.java index b50b2a30842..df6a24745af 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplateSpecialization.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,7 +7,7 @@ * * Contributors: * IBM - Initial API and implementation - * / + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* * Created on Apr 29, 2005 @@ -65,4 +65,8 @@ public class CPPMethodTemplateSpecialization extends return false; } + public boolean isImplicit() { + return false; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java index 278dffdbf6b..44071a199e6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java @@ -60,8 +60,8 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI public boolean isMutable() { return false; } - public IASTInitializer getDefaultValue() { - return ((ICPPParameter)getBinding()).getDefaultValue(); + public boolean hasDefaultValue() { + return ((ICPPParameter)getBinding()).hasDefaultValue(); } } @@ -276,6 +276,10 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI return null; } + public boolean hasDefaultValue() { + return getDefaultValue() != null; + } + public ILinkage getLinkage() { return Linkage.CPP_LINKAGE; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java index b72349d636f..305dafe27e5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* * Created on Mar 29, 2005 @@ -14,7 +15,6 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; @@ -87,8 +87,8 @@ public class CPPParameterSpecialization extends CPPSpecialization implements ICP return false; } - public IASTInitializer getDefaultValue() { - return getParameter().getDefaultValue(); + public boolean hasDefaultValue() { + return getParameter().hasDefaultValue(); } public ICPPDelegate createDelegate(IASTName name) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java index 6dfa03cc397..2e4296b7b87 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* * Created on Feb 11, 2005 @@ -17,10 +18,12 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; +import org.eclipse.cdt.internal.core.index.IIndexType; /** * @author aniefer @@ -39,6 +42,11 @@ public class CPPPointerToMemberType extends CPPPointerType implements } public boolean isSameType( IType o ){ + if( o == this ) + return true; + if( o instanceof ITypedef || o instanceof IIndexType) + return o.isSameType( this ); + if( !super.isSameType( o ) ) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java index 11120db202f..8d651c96d07 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* * Created on Dec 10, 2004 @@ -18,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; +import org.eclipse.cdt.internal.core.index.IIndexType; /** * @author aniefer @@ -62,8 +64,8 @@ public class CPPPointerType implements IPointerType, ITypeContainer { public boolean isSameType( IType o ){ if( o == this ) return true; - if( o instanceof ITypedef ) - return ((ITypedef)o).isSameType( this ); + if( o instanceof ITypedef || o instanceof IIndexType) + return o.isSameType( this ); if( !( o instanceof CPPPointerType ) ) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPQualifierType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPQualifierType.java index c62d2e707c5..011b7cb8cc2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPQualifierType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPQualifierType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* @@ -18,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IQualifierType; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; +import org.eclipse.cdt.internal.core.index.IIndexType; /** * @author aniefer @@ -34,7 +36,7 @@ public class CPPQualifierType implements IQualifierType, ITypeContainer { } public boolean isSameType( IType o ){ - if( o instanceof ITypedef ) + if( o instanceof ITypedef || o instanceof IIndexType) return o.isSameType( this ); if( !( o instanceof CPPQualifierType ) ) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java index 46baf7aaaa6..6fe5470de34 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java @@ -14,10 +14,10 @@ */ package org.eclipse.cdt.internal.core.dom.parser.cpp; -import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; @@ -28,9 +28,9 @@ import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.ObjectSet; +import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; -import org.eclipse.core.runtime.CoreException; /** * @author aniefer @@ -84,6 +84,30 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope { } public IBinding getBinding(IASTName name, boolean forceResolve) throws DOMException { + IBinding binding= getBindingInAST(name, forceResolve); + if (binding == null) { + IIndex index = name.getTranslationUnit().getIndex(); + if (index != null) { + // Try looking this up in the PDOM + if (physicalNode instanceof IASTTranslationUnit) { + IBinding[] bindings= index.findInGlobalScope(Linkage.CPP_LINKAGE, name.toCharArray()); + binding= CPPSemantics.resolveAmbiguities(name, bindings); + } + else if (physicalNode instanceof ICPPASTNamespaceDefinition) { + ICPPASTNamespaceDefinition nsdef = (ICPPASTNamespaceDefinition)physicalNode; + IASTName nsname = nsdef.getName(); + IBinding nsbinding= nsname.resolveBinding(); + if (nsbinding != null) { + IBinding[] bindings= index.findInNamespace(nsbinding, name.toCharArray()); + binding= CPPSemantics.resolveAmbiguities(name, bindings); + } + } + } + } + return binding; + } + + public IBinding getBindingInAST(IASTName name, boolean forceResolve) throws DOMException { char [] c = name.toCharArray(); //can't look up bindings that don't have a name if( c.length == 0 ) @@ -127,27 +151,10 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope { return binding; } return (IBinding) obj; - } else { - IIndex index = name.getTranslationUnit().getIndex(); - if (index != null) { - // Try looking this up in the PDOM - if (physicalNode instanceof ICPPASTNamespaceDefinition) { - ICPPASTNamespaceDefinition nsdef = (ICPPASTNamespaceDefinition)physicalNode; - IASTName nsname = nsdef.getName(); - IBinding nsbinding= null; - try { - nsbinding = index.findBinding(nsname); - } catch (CoreException e) { - CCorePlugin.log(e); - } - if (nsbinding instanceof ICPPScope) - return ((ICPPScope)nsbinding).getBinding(name, forceResolve); - } - } - } - return null; + } + return null; } - + private boolean isfull = false; public void setFullyCached( boolean full ){ isfull = full; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java index e7fb2877574..72bb9beb8f3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java @@ -14,7 +14,6 @@ */ package org.eclipse.cdt.internal.core.dom.parser.cpp; -import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; @@ -117,7 +116,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; -import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayUtils; @@ -128,8 +127,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; -import org.eclipse.core.runtime.CoreException; /** * @author aniefer @@ -750,24 +747,12 @@ public class CPPSemantics { addDefinition( binding, data.astName ); } } - if( binding == null || binding instanceof IProblemBinding ){ - // Let's try the pdom - IIndex index = name.getTranslationUnit().getIndex(); - if (index != null) { - try { - binding = index.findBinding(name); - } catch (CoreException e) { - CCorePlugin.log(e); - } - } - - // If we're still null... - if (binding == null) { - if( name instanceof ICPPASTQualifiedName && data.forDefinition() ) - binding = new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND, data.name() ); - else - binding = new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, data.name() ); - } + // If we're still null... + if (binding == null) { + if( name instanceof ICPPASTQualifiedName && data.forDefinition() ) + binding = new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND, data.name() ); + else + binding = new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, data.name() ); } return binding; } @@ -1033,14 +1018,21 @@ public class CPPSemantics { mergeResults( data, binding, true ); } } else { + IBinding b= null; if (!data.prefixLookup && data.astName != null ) { - IBinding b = scope.getBinding( data.astName, false ); - if (b instanceof CPPImplicitFunction || b instanceof CPPImplicitTypedef - || b instanceof PDOMBinding) - // TODO the PDOMBinding thing is a kludge + b= scope.getBinding( data.astName, false ); + if (b instanceof CPPImplicitFunction || b instanceof CPPImplicitTypedef) mergeResults( data, b, true ); } - mergeResults( data, lookupInScope( data, scope, blockItem ), true ); + IASTName[] inScope = lookupInScope( data, scope, blockItem ); + if (inScope != null) { + mergeResults( data, inScope, true ); + } + else if (b instanceof IIndexBinding) { + // since the ast did not come up with a binding, use what + // we have found in the index. + mergeResults(data, b, true); + } } if( (!data.hasResults() || data.prefixLookup) && scope instanceof ICPPNamespaceScope ){ @@ -1101,7 +1093,11 @@ public class CPPSemantics { node = blockItem; ICPPScope parentScope = (ICPPScope) scope.getParent(); - if( parentScope instanceof ICPPTemplateScope ){ + // the index cannot return the translation unit as parent scope + if (parentScope == null && scope instanceof IIndexBinding) { + parentScope= (ICPPScope) node.getTranslationUnit().getScope(); + } + else if( parentScope instanceof ICPPTemplateScope ){ IASTNode parent = node.getParent(); while( parent != null && !(parent instanceof ICPPASTTemplateDeclaration) ){ node = parent; @@ -1804,7 +1800,7 @@ public class CPPSemantics { } } - static protected IBinding resolveAmbiguities( IASTName name, Object[] bindings ){ + public static IBinding resolveAmbiguities( IASTName name, Object[] bindings ){ bindings = ArrayUtil.trim( Object.class, bindings ); if( bindings == null || bindings.length == 0 ) return null; @@ -1908,6 +1904,7 @@ public class CPPSemantics { IBinding obj = null; IBinding temp = null; ObjectSet fns = ObjectSet.EMPTY_SET; + boolean fnsFromAST= false; ObjectSet templateFns = ObjectSet.EMPTY_SET; Object [] items = (Object[]) data.foundItems; @@ -1938,6 +1935,28 @@ public class CPPSemantics { mergeResults( data, bindings, false ); items = (Object[]) data.foundItems; continue; + } else if( temp instanceof IFunction ){ + if( temp instanceof ICPPTemplateDefinition ){ + if( templateFns == ObjectSet.EMPTY_SET ) + templateFns = new ObjectSet(2); + templateFns.put( temp ); + } else { + if( fns == ObjectSet.EMPTY_SET ) + fns = new ObjectSet(2); + if (temp instanceof IIndexBinding) { + // accept bindings from index only, in case we have none in the AST + if (!fnsFromAST) { + fns.put(temp); + } + } + else { + if (!fnsFromAST) { + fns.clear(); + fnsFromAST= true; + } + fns.put( temp ); + } + } } else if( temp instanceof IType ){ if( type == null ){ type = temp; @@ -1954,25 +1973,25 @@ public class CPPSemantics { } else if( type != temp && !((IType)type).isSameType( (IType) temp )) { return new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name() ); } - } else if( temp instanceof IFunction ){ - if( temp instanceof ICPPTemplateDefinition ){ - if( templateFns == ObjectSet.EMPTY_SET ) - templateFns = new ObjectSet(2); - templateFns.put( temp ); - } else { - if( fns == ObjectSet.EMPTY_SET ) - fns = new ObjectSet(2); - fns.put( temp ); - } } else { - if( obj == null ) + if( obj == null) obj = temp; - else if( (temp instanceof ICPPDelegate && ((ICPPDelegate)temp).getBinding() == obj) || - (obj instanceof ICPPDelegate && ((ICPPDelegate)obj).getBinding() == temp) ) - { + else if ( obj == temp || + (temp instanceof ICPPDelegate && ((ICPPDelegate)temp).getBinding() == obj) || + (obj instanceof ICPPDelegate && ((ICPPDelegate)obj).getBinding() == temp)) { //ok, delegates are synonyms - } else if( obj != temp ){ - return new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name() ); + } + else { + // ignore index stuff in case we have bindings from the ast + boolean ibobj= obj instanceof IIndexBinding; + boolean ibtemp= temp instanceof IIndexBinding; + // blame it on the index + if (ibobj != ibtemp) { + if (ibobj) + obj= temp; + } + else + return new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name() ); } } } @@ -2050,6 +2069,10 @@ public class CPPSemantics { int size = functions.length; for( int i = 0; i < size && functions[i] != null; i++ ){ function = (IFunction) functions[i]; + if (function instanceof IProblemBinding) { + functions[i]= null; + continue; + } num = function.getParameters().length; //if there are m arguments in the list, all candidate functions having m parameters @@ -2087,7 +2110,7 @@ public class CPPSemantics { else { IParameter [] params = function.getParameters(); for( int j = num - 1; j >= numParameters; j-- ){ - if( ((ICPPParameter)params[j]).getDefaultValue() == null ){ + if( !((ICPPParameter)params[j]).hasDefaultValue()){ functions[i] = null; break; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java index 00ad276eeb0..eb1eb1872de 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java @@ -392,7 +392,7 @@ public class CPPVisitor { try { if( name.toCharArray().length > 0 && scope != null ) //can't lookup anonymous things binding = scope.getBinding( name, false ); - if( binding == null || !(binding instanceof ICPPClassType) ){ + if( !(binding instanceof ICPPInternalBinding) || !(binding instanceof ICPPClassType)){ if( template ) binding = new CPPClassTemplate( name ); else @@ -400,14 +400,11 @@ public class CPPVisitor { if( scope != null ) ASTInternal.addName( scope, compType.getName() ); } else { - if( binding instanceof ICPPInternalBinding ){ - ICPPInternalBinding internal = (ICPPInternalBinding) binding; - if( internal.getDefinition() == null ) - internal.addDefinition( compType ); - else - binding = new ProblemBinding( name, IProblemBinding.SEMANTIC_INVALID_REDEFINITION, name.toCharArray() ); - } - + ICPPInternalBinding internal = (ICPPInternalBinding) binding; + if( internal.getDefinition() == null ) + internal.addDefinition( compType ); + else + binding = new ProblemBinding( name, IProblemBinding.SEMANTIC_INVALID_REDEFINITION, name.toCharArray() ); } } catch ( DOMException e ) { binding = e.getProblem(); @@ -421,7 +418,7 @@ public class CPPVisitor { IBinding binding; try { binding = scope.getBinding( namespaceDef.getName(), false ); - if( binding == null || binding instanceof IProblemBinding ){ + if( !(binding instanceof ICPPInternalBinding) || binding instanceof IProblemBinding ){ binding = new CPPNamespace( namespaceDef ); ASTInternal.addName( scope, namespaceDef.getName() ); } @@ -532,21 +529,23 @@ public class CPPVisitor { return CPPTemplates.createBinding( param ); } } else if( simpleDecl != null && simpleDecl.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef ){ - if( binding != null && binding instanceof ITypedef ){ + if( binding instanceof ICPPInternalBinding && binding instanceof ITypedef ){ try { IType t1 = ((ITypedef)binding).getType(); IType t2 = createType( declarator ); if( t1 != null && t2 != null && t1.isSameType( t2 ) ){ - ((ICPPInternalBinding)binding).addDeclaration( name ); + ICPPInternalBinding internal = (ICPPInternalBinding) binding; + internal.addDeclaration(name); return binding; } } catch ( DOMException e1 ) { + return e1.getProblem(); } return new ProblemBinding( name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION, name.toCharArray() ); } binding = new CPPTypedef( name ); } else if( declarator instanceof ICPPASTFunctionDeclarator ){ - if( binding != null && binding instanceof IFunction ){ + if( binding instanceof ICPPInternalBinding && binding instanceof IFunction ){ IFunction function = (IFunction) binding; if( CPPSemantics.isSameFunction( function, declarator ) ){ ICPPInternalBinding internal = (ICPPInternalBinding) function; @@ -554,7 +553,7 @@ public class CPPVisitor { internal.addDeclaration( name ); else { if( internal.getDefinition() == null ) - ((ICPPInternalBinding)function).addDefinition( name ); + internal.addDefinition( name ); else { IASTNode def = internal.getDefinition(); if( def instanceof IASTDeclarator ) @@ -1588,10 +1587,10 @@ public class CPPVisitor { name = ((IASTEnumerationSpecifier)declSpec).getName(); } else if( declSpec instanceof ICPPASTSimpleDeclSpecifier ){ ICPPASTSimpleDeclSpecifier spec = (ICPPASTSimpleDeclSpecifier) declSpec; - int bits = ( spec.isLong() ? CPPBasicType.IS_LONG : 0 ) | - ( spec.isShort() ? CPPBasicType.IS_SHORT : 0 ) | - ( spec.isSigned() ? CPPBasicType.IS_SIGNED: 0 ) | - ( spec.isUnsigned() ? CPPBasicType.IS_UNSIGNED : 0 ); + int bits = ( spec.isLong() ? ICPPBasicType.IS_LONG : 0 ) | + ( spec.isShort() ? ICPPBasicType.IS_SHORT : 0 ) | + ( spec.isSigned() ? ICPPBasicType.IS_SIGNED: 0 ) | + ( spec.isUnsigned() ? ICPPBasicType.IS_UNSIGNED : 0 ); if( spec instanceof IGPPASTSimpleDeclSpecifier ){ IGPPASTSimpleDeclSpecifier gspec = (IGPPASTSimpleDeclSpecifier) spec; if( gspec.getTypeofExpression() != null ){ @@ -1606,9 +1605,7 @@ public class CPPVisitor { } if( name != null ){ IBinding binding = name.resolveBinding(); - if( binding instanceof IType ) - type = (IType) binding; - else if( binding instanceof ICPPConstructor ){ + if( binding instanceof ICPPConstructor ){ try { ICPPClassScope scope = (ICPPClassScope) binding.getScope(); type = scope.getClassType(); @@ -1616,6 +1613,8 @@ public class CPPVisitor { } catch (DOMException e) { type = e.getProblem(); } + } else if( binding instanceof IType ) { + type = (IType) binding; } else if( binding instanceof ICPPTemplateNonTypeParameter ){ //TODO workaround... is there anything better? try { @@ -1831,7 +1830,7 @@ public class CPPVisitor { } } catch (DOMException e) { } - return new CPPBasicType( IBasicType.t_int, CPPBasicType.IS_LONG | CPPBasicType.IS_UNSIGNED ); + return new CPPBasicType( IBasicType.t_int, ICPPBasicType.IS_LONG | ICPPBasicType.IS_UNSIGNED ); } IType type = getExpressionType(((IASTUnaryExpression)expression).getOperand() ); @@ -1886,7 +1885,7 @@ public class CPPVisitor { } } catch (DOMException e) { } - return new CPPBasicType( IBasicType.t_int, CPPBasicType.IS_LONG | CPPBasicType.IS_UNSIGNED ); + return new CPPBasicType( IBasicType.t_int, ICPPBasicType.IS_LONG | ICPPBasicType.IS_UNSIGNED ); } return createType( typeidExp.getTypeId() ); } else if( expression instanceof IASTArraySubscriptExpression ){ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerToMemberType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerToMemberType.java index 08449aa3efd..6827cb4d431 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerToMemberType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerToMemberType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* @@ -15,8 +16,10 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointerToMember; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPPointerToMemberType; +import org.eclipse.cdt.internal.core.index.IIndexType; /** * @author aniefer @@ -55,8 +58,14 @@ public class GPPPointerToMemberType extends CPPPointerToMemberType implements } public boolean isSameType( IType o ){ + if (o==this) { + return true; + } + if (o instanceof ITypedef || o instanceof IIndexType) { + return o.isSameType(this); + } + if( !super.isSameType( o ) ) return false; - if( o instanceof IGPPPointerToMemberType ){ return (isRestrict == ((IGPPPointerToMemberType) o).isRestrict()); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerType.java index c8880d8a2cd..3d6254f5fd3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* @@ -15,8 +16,10 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPPointerType; +import org.eclipse.cdt.internal.core.index.IIndexType; /** * @author aniefer @@ -67,6 +70,13 @@ public class GPPPointerType extends CPPPointerType implements IGPPPointerType { } public boolean isSameType( IType o ){ + if (o==this) { + return true; + } + if (o instanceof ITypedef || o instanceof IIndexType) { + return o.isSameType(this); + } + if( !super.isSameType( o ) ) return false; if( o instanceof IGPPPointerType ){ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java index aec355416c4..91cea0979f1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java @@ -20,6 +20,8 @@ import java.util.LinkedList; import java.util.List; import java.util.regex.Pattern; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -324,4 +326,46 @@ public class CIndex implements IIndex { } return result; } + + public IBinding[] findInGlobalScope(ILinkage linkage, char[] name) { + ArrayList result= new ArrayList(); + for (int i = 0; i < fFragments.length; i++) { + try { + IBinding[] part = fFragments[i].findInGlobalScope(linkage, name); + for (int j = 0; j < part.length; j++) { + IBinding binding = part[j]; + if (binding instanceof IIndexBinding) { + result.add(binding); + } + } + } catch (CoreException e) { + CCorePlugin.log(e); + } + } + if (!result.isEmpty()) { + return (IIndexBinding[]) result.toArray(new IIndexBinding[result.size()]); + } + return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY; + } + + public IBinding[] findInNamespace(IBinding nsbinding, char[] name) { + ArrayList result= new ArrayList(); + for (int i = 0; i < fFragments.length; i++) { + try { + IBinding[] part = fFragments[i].findInNamespace(nsbinding, name); + for (int j = 0; j < part.length; j++) { + IBinding binding = part[j]; + if (binding instanceof IIndexBinding) { + result.add(binding); + } + } + if (!result.isEmpty()) { + return (IIndexBinding[]) result.toArray(new IIndexBinding[result.size()]); + } + } catch (CoreException e) { + CCorePlugin.log(e); + } + } + return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java index e82917cb39c..2c388905361 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.index; import java.util.regex.Pattern; +import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.index.IIndex; @@ -96,4 +97,12 @@ final public class EmptyCIndex implements IIndex { public IIndexBinding adaptBinding(IBinding binding) throws CoreException { return null; } + + public IBinding[] findInGlobalScope(ILinkage linkage, char[] name) { + return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY; + } + + public IBinding[] findInNamespace(IBinding nsbinding, char[] name) { + return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY; + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java index 6a7b73ca772..8bdd97f3d2a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.index; import java.util.regex.Pattern; +import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.index.IIndex; @@ -133,5 +134,13 @@ public interface IIndexFragment { */ long getLastWriteAccess(); + /** + * Returns all bindings with the given name in the given linkage + */ + IBinding[] findInGlobalScope(ILinkage linkage, char[] name) throws CoreException; + /** + * Returns all bindings with the given name in the given namespace + */ + IBinding[] findInNamespace(IBinding nsbinding, char[] name) throws CoreException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexType.java new file mode 100644 index 00000000000..c037e381213 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexType.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2006 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.core.index; + +import org.eclipse.cdt.core.dom.ast.IType; + +/** + * Interface for types stored in the index + * @since 4.0 + */ +public interface IIndexType extends IType { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserMessages.properties b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserMessages.properties index 15702290be3..71c3fafc60e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserMessages.properties +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2005 IBM Corporation and others. +# Copyright (c) 2005, 2006 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -82,5 +82,6 @@ ASTProblemFactory.error.semantic.dom.knrParameterDeclarationNotFound=A declarati ASTProblemFactory.error.semantic.dom.labelStatementNotFound=A label statement was not found for the name {0} ASTProblemFactory.error.semantic.dom.invalidRedefinition=Invalid redefinition of the name {0} ASTProblemFactory.error.semantic.dom.invalidRedeclaration=Invalid redeclaration of the name {0} +ASTProblemFactory.error.semantic.dom.recursionInResolution=Recursion while looking up ''{0}'' ASTProblemFactory.error.semantic.dom.badScope=A scope could not be created to represent the name {0} ASTProblemFactory.error.semantic.dom.memberDeclNotFound=A declaration could not be found for this member definition: {0} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java index 5fed95137e2..4b3e9c1cddd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java @@ -30,8 +30,8 @@ import org.eclipse.cdt.core.dom.IPDOMNode; import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IIndexName; import org.eclipse.cdt.core.index.IndexFilter; @@ -52,6 +52,8 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMInclude; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; +import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPMethod; +import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPNamespace; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.PlatformObject; @@ -66,7 +68,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { private Database db; - public static final int VERSION = 18; + public static final int VERSION = 20; // 0 - the beginning of it all // 1 - first change to kick off upgrades // 2 - added file inclusions @@ -87,6 +89,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { // 17 - use single linked list for names in file, adds a link to enclosing defintion name. // 18 - distinction between c-unions and c-structs. // 19 - alter representation of paths in the pdom (162172) + // 20 - add pointer to member types, array types, return types for functions public static final int LINKAGES = Database.DATA_AREA; public static final int FILE_INDEX = Database.DATA_AREA + 4; @@ -96,7 +99,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { private Map fLinkageIDCache = new HashMap(); private File fPath; private IIndexLocationConverter locationConverter; - + public PDOM(File dbPath, IIndexLocationConverter locationConverter) throws CoreException { // Load up the database fPath= dbPath; @@ -249,11 +252,13 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { private List bindings = new ArrayList(); private boolean isFullyQualified; private BitSet matchesUpToLevel; + private boolean acceptImplicitMethods; - public BindingFinder(Pattern[] pattern, boolean isFullyQualified, IProgressMonitor monitor) { + public BindingFinder(Pattern[] pattern, boolean isFullyQualified, boolean acceptImplicitMethods, IProgressMonitor monitor) { this.pattern = pattern; this.monitor = monitor; this.isFullyQualified= isFullyQualified; + this.acceptImplicitMethods= acceptImplicitMethods; matchesUpToLevel= new BitSet(); matchesUpToLevel.set(0); matchStack.add(matchesUpToLevel); @@ -270,7 +275,10 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { // check if we have a complete match. final int lastIdx = pattern.length-1; if (matchesUpToLevel.get(lastIdx) && pattern[lastIdx].matcher(name).matches()) { - bindings.add(binding); + if (acceptImplicitMethods || !(binding instanceof PDOMCPPMethod) || + !((PDOMCPPMethod)binding).isImplicit()) { + bindings.add(binding); + } } // check if we have a partial match @@ -331,7 +339,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { } public IIndexFragmentBinding[] findBindings(Pattern[] pattern, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException { - BindingFinder finder = new BindingFinder(pattern, isFullyQualified, monitor); + BindingFinder finder = new BindingFinder(pattern, isFullyQualified, filter.acceptImplicitMethods(), monitor); for (Iterator iter = fLinkageIDCache.values().iterator(); iter.hasNext();) { PDOMLinkage linkage = (PDOMLinkage) iter.next(); if (filter.acceptLinkage(linkage)) { @@ -580,4 +588,20 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { public File getPath() { return fPath; } + + public IBinding[] findInGlobalScope(ILinkage linkage, char[] name) throws CoreException { + PDOMLinkage pdomLinkage= adaptLinkage(linkage); + if (pdomLinkage != null) { + return pdomLinkage.findInGlobalScope(name); + } + return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY; + } + + public IBinding[] findInNamespace(IBinding nsbinding, char[] name) throws CoreException { + IIndexProxyBinding ns= adaptBinding(nsbinding); + if (ns instanceof PDOMCPPNamespace) { + return ((PDOMCPPNamespace) ns).find(new String(name)); + } + return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY; + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java index abb5967bed9..6f003b54657 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java @@ -25,8 +25,8 @@ import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.dom.IPDOMIndexer; import org.eclipse.cdt.core.dom.IPDOMIndexerTask; import org.eclipse.cdt.core.dom.IPDOMManager; -import org.eclipse.cdt.core.index.IIndexChangeListener; import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.index.IIndexChangeListener; import org.eclipse.cdt.core.index.IIndexerStateListener; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElementDelta; @@ -47,7 +47,6 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.IStatus; @@ -104,7 +103,7 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen * Stores mapping from pdom to project, used to serialize\ creation of new pdoms. */ private Map fProjectToPDOM= new HashMap(); - private Map fLocationToCProject= new HashMap(); + private Map fFileToProject= new HashMap(); private ListenerList fChangeListeners= new ListenerList(); private ListenerList fStateListeners= new ListenerList(); @@ -155,19 +154,19 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen } String dbName= rproject.getPersistentProperty(dbNameProperty); - IPath dbPath= null; + File dbFile= null; if (dbName != null) { - dbPath= CCorePlugin.getDefault().getStateLocation().append(dbName); - ICProject currentCOwner= (ICProject) fLocationToCProject.get(dbPath); + dbFile= CCorePlugin.getDefault().getStateLocation().append(dbName).toFile(); + ICProject currentCOwner= (ICProject) fFileToProject.get(dbFile); if (currentCOwner != null) { IProject currentOwner= currentCOwner.getProject(); if (currentOwner.exists()) { dbName= null; - dbPath= null; + dbFile= null; } else { pdom= (WritablePDOM) fProjectToPDOM.remove(currentOwner); - fLocationToCProject.remove(dbPath); + fFileToProject.remove(dbFile); } } } @@ -176,14 +175,14 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen if (dbName == null) { dbName= getDefaultName(project); rproject.setPersistentProperty(dbNameProperty, dbName); - dbPath= CCorePlugin.getDefault().getStateLocation().append(dbName); + dbFile= CCorePlugin.getDefault().getStateLocation().append(dbName).toFile(); } - pdom = new WritablePDOM(new File(dbPath.toOSString()), new PDOMProjectIndexLocationConverter(rproject)); + pdom = new WritablePDOM(dbFile, new PDOMProjectIndexLocationConverter(rproject)); pdom.addListener(this); } - fLocationToCProject.put(dbPath, project); + fFileToProject.put(dbFile, project); fProjectToPDOM.put(rproject, pdom); return pdom; } @@ -626,7 +625,7 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen ICProject project; synchronized (fProjectToPDOM) { - project = (ICProject) fLocationToCProject.get(pdom.getPath()); + project = (ICProject) fFileToProject.get(pdom.getPath()); } if (project != null) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMArrayType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMArrayType.java new file mode 100644 index 00000000000..beded9e9519 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMArrayType.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2006 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.core.pdom.dom; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IArrayType; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; +import org.eclipse.cdt.internal.core.index.IIndexType; +import org.eclipse.cdt.internal.core.pdom.PDOM; +import org.eclipse.cdt.internal.core.pdom.db.Database; +import org.eclipse.core.runtime.CoreException; + +public class PDOMArrayType extends PDOMNode implements IIndexType, IArrayType, ITypeContainer { + + private static final int TYPE = PDOMNode.RECORD_SIZE; + private static final int RECORD_SIZE= TYPE+4; + + public PDOMArrayType(PDOM pdom, int record) { + super(pdom, record); + } + + public PDOMArrayType(PDOM pdom, PDOMNode parent, IArrayType type) throws CoreException { + super(pdom, parent); + Database db = pdom.getDB(); + + try { + PDOMNode targetTypeNode = getLinkageImpl().addType(this, type.getType()); + if (targetTypeNode != null) { + int typeRec = targetTypeNode.getRecord(); + db.putInt(record + TYPE, typeRec); + } + } catch (DOMException e) { + CCorePlugin.log(e); + } + } + + protected int getRecordSize() { + return RECORD_SIZE; + } + + public int getNodeType() { + return PDOMLinkage.ARRAY_TYPE; + } + + public IASTExpression getArraySizeExpression() throws DOMException { + return null; + } + + public IType getType() throws DOMException { + try { + PDOMNode node = getLinkageImpl().getNode(pdom.getDB().getInt(record + TYPE)); + return node instanceof IType ? (IType)node : null; + } catch (CoreException e) { + CCorePlugin.log(e); + return null; + } + } + + public boolean isSameType(IType type) { + if( type instanceof ITypedef ) + return ((ITypedef)type).isSameType( this ); + + if( !( type instanceof IArrayType )) + return false; + + try { + IType type1= this.getType(); + if( type1 == null ) + return false; + + IArrayType rhs = (IArrayType) type; + return type1.isSameType( rhs.getType() ); + } catch (DOMException e) { + } + return false; + } + + public void setType(IType type) { + throw new PDOMNotImplementedError(); + } + + public Object clone() { + throw new PDOMNotImplementedError(); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java index 760449493bd..fbbda752cd2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java @@ -12,6 +12,9 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.DOMException; @@ -214,4 +217,21 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen return null; } } + + final public String[] getQualifiedName() { + List result = new ArrayList(); + try { + PDOMNode node = this; + while (node != null) { + if (node instanceof PDOMBinding) { + result.add(0, ((PDOMBinding)node).getName()); + } + node = node.getParentNode(); + } + return (String[]) result.toArray(new String[result.size()]); + } catch(CoreException ce) { + CCorePlugin.log(ce); + return null; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java index 21f97513870..63d411b6514 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java @@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IArrayType; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IQualifierType; @@ -58,7 +59,8 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage // node types protected static final int LINKAGE = 0; // special one for myself static final int POINTER_TYPE = 1; - static final int QUALIFIER_TYPE = 2; + static final int ARRAY_TYPE = 2; + static final int QUALIFIER_TYPE = 3; protected static final int LAST_NODE_TYPE = QUALIFIER_TYPE; @@ -132,6 +134,8 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage switch (PDOMNode.getNodeType(pdom, record)) { case POINTER_TYPE: return new PDOMPointerType(pdom, record); + case ARRAY_TYPE: + return new PDOMArrayType(pdom, record); case QUALIFIER_TYPE: return new PDOMQualifierType(pdom, record); } @@ -143,6 +147,8 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage if (type instanceof IPointerType) node = new PDOMPointerType(pdom, parent, (IPointerType)type); + else if (type instanceof IArrayType) + node= new PDOMArrayType(pdom, parent, (IArrayType) type); else if (type instanceof IQualifierType) node = new PDOMQualifierType(pdom, parent, (IQualifierType)type); else @@ -180,11 +186,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage } if (scope instanceof IIndexBinding) { - IIndexBinding parent= ((IIndexBinding) scope).getParentBinding(); - if (parent == null) { - return this; - } - return adaptBinding(parent); + return adaptBinding((IBinding) scope); } // the scope is from the ast @@ -217,4 +219,11 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage } public abstract int getBindingType(IBinding binding); + + public IBinding[] findInGlobalScope(char[] name) throws CoreException { + FindBindingsInBTree visitor= new FindBindingsInBTree(this, name); + getIndex().accept(visitor); + + return visitor.getBinding(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMPointerType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMPointerType.java index 8f2ec982163..cae16cd8f8b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMPointerType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMPointerType.java @@ -17,8 +17,10 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; +import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.core.runtime.CoreException; @@ -27,12 +29,12 @@ import org.eclipse.core.runtime.CoreException; * @author Doug Schaefer */ public class PDOMPointerType extends PDOMNode implements IPointerType, - ITypeContainer { + ITypeContainer, IIndexType { private static final int FLAGS = PDOMNode.RECORD_SIZE + 0; // byte private static final int TYPE = PDOMNode.RECORD_SIZE + 1; - private static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 5; + protected static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 5; private static final int CONST = 0x1; private static final int VOLATILE = 0x2; @@ -81,7 +83,7 @@ public class PDOMPointerType extends PDOMNode implements IPointerType, return pdom.getDB().getByte(record + FLAGS); } - public IType getType() throws DOMException { + public IType getType() { try { PDOMNode node = getLinkageImpl().getNode(pdom.getDB().getInt(record + TYPE)); return node instanceof IType ? (IType)node : null; @@ -91,7 +93,7 @@ public class PDOMPointerType extends PDOMNode implements IPointerType, } } - public boolean isConst() throws DOMException { + public boolean isConst() { try { return (getFlags() & CONST) != 0; } catch (CoreException e) { @@ -100,7 +102,7 @@ public class PDOMPointerType extends PDOMNode implements IPointerType, } } - public boolean isVolatile() throws DOMException { + public boolean isVolatile() { try { return (getFlags() & VOLATILE) != 0; } catch (CoreException e) { @@ -110,7 +112,23 @@ public class PDOMPointerType extends PDOMNode implements IPointerType, } public boolean isSameType(IType type) { - return equals(type); + if( type instanceof ITypedef ) + return ((ITypedef)type).isSameType( this ); + + if( !( type instanceof IPointerType )) + return false; + + IPointerType rhs = (IPointerType) type; + try { + if (isConst() == rhs.isConst() && isVolatile() == rhs.isVolatile()) { + IType type1= getType(); + if (type1 != null) { + return type1.isSameType(rhs.getType()); + } + } + } catch (DOMException e) { + } + return false; } public void setType(IType type) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMQualifierType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMQualifierType.java index 8fb94fff4cd..7117f43bc62 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMQualifierType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMQualifierType.java @@ -17,8 +17,10 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IQualifierType; import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; +import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.core.runtime.CoreException; @@ -28,7 +30,7 @@ import org.eclipse.core.runtime.CoreException; * */ public class PDOMQualifierType extends PDOMNode implements IQualifierType, - ITypeContainer { + ITypeContainer, IIndexType { private static final int FLAGS = PDOMNode.RECORD_SIZE; private static final int TYPE = PDOMNode.RECORD_SIZE + 1; @@ -111,7 +113,18 @@ public class PDOMQualifierType extends PDOMNode implements IQualifierType, } public boolean isSameType(IType type) { - return equals(type); + if( type instanceof ITypedef ) + return type.isSameType( this ); + if( !( type instanceof IQualifierType ) ) + return false; + + IQualifierType pt = (IQualifierType) type; + try { + if( isConst() == pt.isConst() && isVolatile() == pt.isVolatile() ) + return type.isSameType( pt.getType() ); + } catch (DOMException e) { + } + return false; } public void setType(IType type) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCBasicType.java index 30257e1cb2f..858d125a711 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCBasicType.java @@ -8,6 +8,7 @@ * Contributors: * QNX - Initial API and implementation * Andrew Ferguson (Symbian) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.c; @@ -16,8 +17,10 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.c.ICBasicType; import org.eclipse.cdt.internal.core.Util; +import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; @@ -27,7 +30,7 @@ import org.eclipse.core.runtime.CoreException; * @author Doug Schaefer * */ -class PDOMCBasicType extends PDOMNode implements ICBasicType { +class PDOMCBasicType extends PDOMNode implements ICBasicType, IIndexType { public static final int TYPE_ID = PDOMNode.RECORD_SIZE + 0; // short public static final int FLAGS = PDOMNode.RECORD_SIZE + 2; // short @@ -77,7 +80,7 @@ class PDOMCBasicType extends PDOMNode implements ICBasicType { return PDOMCLinkage.CBASICTYPE; } - public int getType() throws DOMException { + public int getType() { try { return pdom.getDB().getChar(record + TYPE_ID); } catch (CoreException e) { @@ -101,9 +104,31 @@ class PDOMCBasicType extends PDOMNode implements ICBasicType { public boolean isComplex() { return flagSet(IS_COMPLEX); } - public boolean isSameType(IType type) { - // TODO something fancier - return equals(type); + public boolean isSameType(IType rhs) { + if( rhs instanceof ITypedef ) + return rhs.isSameType( this ); + + if( !(rhs instanceof ICBasicType)) + return false; + + ICBasicType rhs1= (ICBasicType) rhs; + int type; + try { + type = this.getType(); + if (type == -1 || type != rhs1.getType()) + return false; + + return (rhs1.getType() == this.getType() + && rhs1.isLong() == this.isLong() + && rhs1.isShort() == this.isShort() + && rhs1.isSigned() == this.isSigned() + && rhs1.isUnsigned() == this.isUnsigned() + && rhs1.isLongLong() == this.isLongLong() + && rhs1.isComplex() == this.isComplex() + && rhs1.isImaginary() == this.isImaginary()); + } catch (DOMException e) { + return false; + } } public Object clone() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCEnumeration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCEnumeration.java index 585f064cd56..61f59ca484b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCEnumeration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCEnumeration.java @@ -7,6 +7,7 @@ * * Contributors: * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.c; @@ -17,6 +18,8 @@ import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; @@ -26,7 +29,7 @@ import org.eclipse.core.runtime.CoreException; /** * @author Doug Schaefer */ -class PDOMCEnumeration extends PDOMBinding implements IEnumeration { +class PDOMCEnumeration extends PDOMBinding implements IEnumeration, IIndexType { private static final int FIRST_ENUMERATOR = PDOMBinding.RECORD_SIZE + 0; @@ -87,7 +90,26 @@ class PDOMCEnumeration extends PDOMBinding implements IEnumeration { } public boolean isSameType(IType type) { - throw new PDOMNotImplementedError(); + if (type instanceof PDOMNode) { + PDOMNode node= (PDOMNode) type; + if (node.getPDOM() == getPDOM()) { + return node.getRecord() == getRecord(); + } + } + + if (type instanceof ITypedef) { + return type.isSameType(this); + } + + if (type instanceof IEnumeration) { + IEnumeration etype= (IEnumeration) type; + try { + return getDBName().equals(etype.getNameCharArray()); + } catch (CoreException e) { + CCorePlugin.log(e); + } + } + return false; } public Object clone() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java index f381cabe097..927f91fbf72 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java @@ -248,4 +248,8 @@ class PDOMCLinkage extends PDOMLinkage { public IBTreeComparator getIndexComparator() { return new FindBinding.DefaultBindingBTreeComparator(getPDOM()); } + + public IBinding findInGlobalScope(String filePath, IASTName name) throws CoreException { + return null; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java index ec7cd59701a..6c008da4ccd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java @@ -26,8 +26,10 @@ import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope; import org.eclipse.cdt.internal.core.Util; +import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner; @@ -41,7 +43,7 @@ import org.eclipse.core.runtime.Status; * @author Doug Schaefer * */ -public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCompositeTypeScope, IPDOMMemberOwner { +public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCompositeTypeScope, IPDOMMemberOwner, IIndexType { private static final int MEMBERLIST = PDOMBinding.RECORD_SIZE; private static final int KEY = MEMBERLIST + 4; // byte protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 8; @@ -152,11 +154,26 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCom } public boolean isSameType(IType type) { - if (equals(type)) - return true; - else - // TODO - see if it matches - return false; + if (type instanceof PDOMNode) { + PDOMNode node= (PDOMNode) type; + if (node.getPDOM() == getPDOM()) { + return node.getRecord() == getRecord(); + } + } + + if (type instanceof ITypedef) { + return type.isSameType(this); + } + + if (type instanceof ICompositeType) { + ICompositeType etype= (ICompositeType) type; + try { + return getDBName().equals(etype.getNameCharArray()); + } catch (CoreException e) { + CCorePlugin.log(e); + } + } + return false; } protected int getRecordSize() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCTypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCTypedef.java index c3e0f02353f..edea134058e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCTypedef.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCTypedef.java @@ -18,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; +import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; @@ -26,7 +27,7 @@ import org.eclipse.core.runtime.CoreException; /** * @author Doug Schaefer */ -class PDOMCTypedef extends PDOMBinding implements ITypedef, ITypeContainer { +class PDOMCTypedef extends PDOMBinding implements ITypedef, ITypeContainer, IIndexType { private static final int TYPE = PDOMBinding.RECORD_SIZE + 0; @@ -70,19 +71,15 @@ class PDOMCTypedef extends PDOMBinding implements ITypedef, ITypeContainer { public boolean isSameType(IType type) { try { - if (type instanceof PDOMBinding) - return record == ((PDOMBinding)type).getRecord(); - IType myrtype = getType(); if (myrtype == null) return false; if (type instanceof ITypedef) { - IType rtype = ((ITypedef)type).getType(); - return rtype != null ? myrtype.isSameType(rtype) : false; + type= ((ITypedef)type).getType(); } + return myrtype.isSameType(type); } catch (DOMException e) { - CCorePlugin.log(e); } return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPAnnotation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPAnnotation.java index 129a46cef79..a807b41f6ae 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPAnnotation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPAnnotation.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IBinding; +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.ICPPMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; @@ -31,6 +32,9 @@ public class PDOMCPPAnnotation { // byte of annotations. public static final int VIRTUAL_OFFSET = 0; public static final int DESTRUCTOR_OFFSET = 1; + public static final int IMPLICIT_METHOD_OFFSET = 2; + public static final int EXPLICIT_CONSTRUCTOR_OFFSET = 3; + public static final int MAX_EXTRA_OFFSET= EXPLICIT_CONSTRUCTOR_OFFSET; /** * Encodes storage class specifiers and other annotation, including @@ -69,6 +73,13 @@ public class PDOMCPPAnnotation { ICPPMethod method = (ICPPMethod) binding; modifiers |= (method.isVirtual() ? 1 : 0) << VIRTUAL_OFFSET; modifiers |= (method.isDestructor() ? 1 : 0) << DESTRUCTOR_OFFSET; + modifiers |= (method.isImplicit() ? 1 : 0) << IMPLICIT_METHOD_OFFSET; + } + if (binding instanceof ICPPConstructor) { + ICPPConstructor constructor= (ICPPConstructor) binding; + if (constructor.isExplicit()) { + modifiers |= (1 << EXPLICIT_CONSTRUCTOR_OFFSET); + } } return modifiers; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBasicType.java index f2c812ceead..f932c7685ff 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBasicType.java @@ -14,9 +14,12 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.internal.core.Util; +import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; @@ -26,18 +29,13 @@ import org.eclipse.core.runtime.CoreException; * @author Doug Schaefer * */ -class PDOMCPPBasicType extends PDOMNode implements ICPPBasicType { +class PDOMCPPBasicType extends PDOMNode implements ICPPBasicType, IIndexType { public static final int TYPE_ID = PDOMNode.RECORD_SIZE + 0; // short public static final int FLAGS = PDOMNode.RECORD_SIZE + 2; // short public static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 4; - - public static final int IS_LONG = 0x1; - public static final int IS_SHORT = 0x2; - public static final int IS_UNSIGNED = 0x4; - public static final int IS_SIGNED = 0x8; - + public PDOMCPPBasicType(PDOM pdom, int record) { super(pdom, record); } @@ -74,7 +72,7 @@ class PDOMCPPBasicType extends PDOMNode implements ICPPBasicType { return PDOMCPPLinkage.CPPBASICTYPE; } - public int getType() throws DOMException { + public int getType() { try { return pdom.getDB().getChar(record + TYPE_ID); } catch (CoreException e) { @@ -129,9 +127,28 @@ class PDOMCPPBasicType extends PDOMNode implements ICPPBasicType { } } - public boolean isSameType(IType type) { - // TODO something fancier - return equals(type); + public boolean isSameType(IType rhs) { + if( rhs instanceof ITypedef ) + return rhs.isSameType( this ); + + if( !(rhs instanceof ICPPBasicType)) + return false; + + ICPPBasicType rhs1= (ICPPBasicType) rhs; + int type; + try { + type = this.getType(); + if (type == -1 || type != rhs1.getType()) + return false; + + if( type == IBasicType.t_int ){ + //signed int and int are equivalent + return (this.getQualifierBits() & ~ICPPBasicType.IS_SIGNED ) == (rhs1.getQualifierBits() & ~ICPPBasicType.IS_SIGNED ); + } + return (this.getQualifierBits() == rhs1.getQualifierBits() ); + } catch (DOMException e) { + return false; + } } public Object clone() { @@ -141,5 +158,13 @@ class PDOMCPPBasicType extends PDOMNode implements ICPPBasicType { return null; } } - + + public int getQualifierBits() { + try { + return getFlags(); + } catch (CoreException e) { + CCorePlugin.log(e); + return 0; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBinding.java index 91e9bcaebfb..8eba88b356a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBinding.java @@ -7,13 +7,11 @@ * * Contributors: * Symbian - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; -import java.util.ArrayList; -import java.util.List; - import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; @@ -33,23 +31,22 @@ abstract public class PDOMCPPBinding extends PDOMBinding implements ICPPBinding public PDOMCPPBinding(PDOM pdom, PDOMNode parent, char[] name) throws CoreException { super(pdom, parent, name); } - - // TODO: performance? - final public String[] getQualifiedName() throws DOMException { - List result = new ArrayList(); + + protected boolean hasQualifiedName(char[][] qname, int idx) { try { - PDOMNode node = this; - while (node != null) { - if (node instanceof PDOMBinding) { - result.add(0, ((PDOMBinding)node).getName()); + if (getDBName().equals(qname[idx])) { + PDOMNode parent= getParentNode(); + if (--idx < 0) { + return parent == null; + } + if (parent instanceof PDOMCPPBinding) { + return ((PDOMCPPBinding) parent).hasQualifiedName(qname, idx); } - node = node.getParentNode(); } - return (String[]) result.toArray(new String[result.size()]); - } catch(CoreException ce) { - CCorePlugin.log(ce); - return null; + } catch (CoreException e) { + CCorePlugin.log(e); } + return false; } // TODO: performance? diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java index 0e4ca876346..f420bb4a26b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java @@ -23,34 +23,28 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOMNode; import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IASTFieldReference; -import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; -import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTName; -import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; -import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; +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.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; -import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.Util; -import org.eclipse.cdt.internal.core.index.IIndexProxyBinding; +import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics; +import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList; -import org.eclipse.cdt.internal.core.pdom.dom.FindBinding; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError; import org.eclipse.core.runtime.CoreException; /** @@ -61,7 +55,7 @@ import org.eclipse.core.runtime.CoreException; * aftodo - contract get Methods/Fields not honoured? */ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, -ICPPClassScope, IPDOMMemberOwner { +ICPPClassScope, IPDOMMemberOwner, IIndexType { private static final int FIRSTBASE = PDOMCPPBinding.RECORD_SIZE + 0; private static final int KEY = PDOMCPPBinding.RECORD_SIZE + 4; // byte @@ -70,7 +64,7 @@ ICPPClassScope, IPDOMMemberOwner { protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE + 12; public PDOMCPPClassType(PDOM pdom, PDOMNode parent, ICPPClassType classType) - throws CoreException { + throws CoreException { super(pdom, parent, classType.getName().toCharArray()); try { @@ -115,23 +109,29 @@ ICPPClassScope, IPDOMMemberOwner { } public boolean isSameType(IType type) { - if (type instanceof PDOMBinding) { - return record == ((PDOMBinding)type).getRecord(); - } else if (type instanceof ICPPClassType) { - try { - IIndexProxyBinding pdomType = pdom.adaptBinding((ICPPClassType)type); - if (pdomType == null) - return false; - else if (pdomType instanceof PDOMBinding) - return record == ((PDOMBinding)pdomType).getRecord(); - else - throw new PDOMNotImplementedError(); - } catch (CoreException e) { - CCorePlugin.log(e); - return false; + if (type instanceof PDOMNode) { + PDOMNode node= (PDOMNode) type; + if (node.getPDOM() == getPDOM()) { + return node.getRecord() == getRecord(); } - } else - return false; + } + + if (type instanceof ITypedef) { + return type.isSameType(this); + } + + if (type instanceof ICPPClassType && !(type instanceof ProblemBinding)) { + ICPPClassType ctype= (ICPPClassType) type; + try { + if (ctype.getKey() == getKey()) { + char[][] qname= ctype.getQualifiedNameCharArray(); + return hasQualifiedName(qname, qname.length-1); + } + } catch (DOMException e) { + CCorePlugin.log(e); + } + } + return false; } public ICPPBase[] getBases() throws DOMException { @@ -154,17 +154,24 @@ ICPPClassScope, IPDOMMemberOwner { list.accept(visitor); } - private static class GetMethods implements IPDOMVisitor { + private static class MethodCollector implements IPDOMVisitor { private final List methods; - public GetMethods(List methods) { - this.methods = methods; + private final boolean acceptImplicit; + private final boolean acceptAll; + public MethodCollector(List methods, boolean acceptImplicit) { + this(methods, acceptImplicit, true); } - public GetMethods() { - this.methods = new ArrayList(); + public MethodCollector(List methods, boolean acceptImplicit, boolean acceptExplicit) { + this.methods = methods == null ? new ArrayList() : methods; + this.acceptImplicit= acceptImplicit; + this.acceptAll= acceptImplicit && acceptExplicit; } public boolean visit(IPDOMNode node) throws CoreException { - if (node instanceof ICPPMethod) - methods.add(node); + if (node instanceof ICPPMethod) { + if (acceptAll || ((ICPPMethod) node).isImplicit() == acceptImplicit) { + methods.add(node); + } + } return false; // don't visit the method } public void leave(IPDOMNode node) throws CoreException { @@ -176,7 +183,27 @@ ICPPClassScope, IPDOMMemberOwner { public ICPPMethod[] getDeclaredMethods() throws DOMException { try { - GetMethods methods = new GetMethods(); + MethodCollector methods = new MethodCollector(null, false); + accept(methods); + return methods.getMethods(); + } catch (CoreException e) { + return new ICPPMethod[0]; + } + } + + public ICPPMethod[] getMethods() throws DOMException { + try { + MethodCollector methods = new MethodCollector(null, true); + accept(methods); + return methods.getMethods(); + } catch (CoreException e) { + return new ICPPMethod[0]; + } + } + + public ICPPMethod[] getImplicitMethods() { + try { + MethodCollector methods = new MethodCollector(null, true, false); accept(methods); return methods.getMethods(); } catch (CoreException e) { @@ -190,7 +217,7 @@ ICPPClassScope, IPDOMMemberOwner { visited.add(this); // Get my members - GetMethods myMethods = new GetMethods(methods); + MethodCollector myMethods = new MethodCollector(methods, false, true); accept(myMethods); // Visit my base classes @@ -216,13 +243,8 @@ ICPPClassScope, IPDOMMemberOwner { return new ICPPMethod[0]; } } - - public ICPPMethod[] getMethods() throws DOMException { - // TODO Should really include implicit methods too - return getDeclaredMethods(); - } - - private static class GetFields implements IPDOMVisitor { + + private static class FieldCollector implements IPDOMVisitor { private List fields = new ArrayList(); public boolean visit(IPDOMNode node) throws CoreException { if (node instanceof IField) @@ -238,7 +260,7 @@ ICPPClassScope, IPDOMMemberOwner { public IField[] getFields() throws DOMException { try { - GetFields visitor = new GetFields(); + FieldCollector visitor = new FieldCollector(); accept(visitor); return visitor.getFields(); } catch (CoreException e) { @@ -247,9 +269,7 @@ ICPPClassScope, IPDOMMemberOwner { } } - - - private static class GetNestedClasses implements IPDOMVisitor { + private static class NestedClassCollector implements IPDOMVisitor { private List nestedClasses = new ArrayList(); public boolean visit(IPDOMNode node) throws CoreException { if (node instanceof ICPPClassType) @@ -265,7 +285,7 @@ ICPPClassScope, IPDOMMemberOwner { public ICPPClassType[] getNestedClasses() throws DOMException { try { - GetNestedClasses visitor = new GetNestedClasses(); + NestedClassCollector visitor = new NestedClassCollector(); accept(visitor); return visitor.getNestedClasses(); } catch (CoreException e) { @@ -303,114 +323,75 @@ ICPPClassScope, IPDOMMemberOwner { addMember(member); } - public ICPPConstructor[] getConstructors() throws DOMException { - // TODO - return new ICPPConstructor[0]; + private static class ConstructorCollector implements IPDOMVisitor { + private List fConstructors = new ArrayList(); + public boolean visit(IPDOMNode node) throws CoreException { + if (node instanceof ICPPConstructor) + fConstructors.add(node); + return false; + } + public void leave(IPDOMNode node) throws CoreException { + } + public ICPPConstructor[] getConstructors() { + return (ICPPConstructor[])fConstructors.toArray(new ICPPConstructor[fConstructors.size()]); + } } - public boolean isFullyCached() throws DOMException {return true;} - - public IBinding getBinding(IASTName name, boolean resolve) throws DOMException { - IASTNode parent = name.getParent(); - + public ICPPConstructor[] getConstructors() throws DOMException { + ConstructorCollector visitor= new ConstructorCollector(); try { - if (name instanceof ICPPASTQualifiedName) { - IASTName lastName = ((ICPPASTQualifiedName)name).getLastName(); - return lastName != null ? lastName.resolveBinding() : null; - } - - if (parent instanceof ICPPASTQualifiedName) { - IASTName[] names = ((ICPPASTQualifiedName)parent).getNames(); - int index = ArrayUtil.indexOf(names, name); - - if (index == names.length - 1) { // tip of qn - parent = parent.getParent(); - } else { - { // bail out if this is not the outerscope of the name being resolved - if(index==-1) { - throw new PDOMNotImplementedError(); - } else { - if(index>0) { - // make sure we're the class they're talking about - PDOMBinding binding = (PDOMBinding) pdom.findBinding(names[index-1]); - if(!equals(binding)) { - return null; - } - } else { - // ok - just search us and return null if there is nothing in here - } - } - } - - // aftodo - do we even need specify the type - we should - // expect only one name here anyway? - return searchCurrentScope(name.toCharArray(), new int[] { - PDOMCPPLinkage.CPPCLASSTYPE, - PDOMCPPLinkage.CPPMETHOD, - PDOMCPPLinkage.CPPFIELD, - PDOMCPPLinkage.CPPENUMERATION, - PDOMCPPLinkage.CPPENUMERATOR - }); - } - } - - IASTNode eParent = parent.getParent(); - if (parent instanceof IASTIdExpression) { - return searchCurrentScope(name.toCharArray(), PDOMCPPLinkage.CPPENUMERATOR); - } else if(eParent instanceof IASTFunctionCallExpression) { - if(parent.getPropertyInParent().equals(IASTFunctionCallExpression.FUNCTION_NAME)) { - return searchCurrentScopeForFunction((IASTFunctionCallExpression)eParent, name); - } else if(parent.getPropertyInParent().equals(IASTFunctionCallExpression.PARAMETERS)) { - if(parent instanceof IASTFieldReference) { - return searchCurrentScope(name.toCharArray(), PDOMCPPLinkage.CPPFIELD); - } - } - } else if(name.getPropertyInParent().equals(IASTFieldReference.FIELD_NAME)) { - return searchCurrentScope(name.toCharArray(), PDOMCPPLinkage.CPPFIELD); - } else if (parent instanceof IASTNamedTypeSpecifier) { - return searchCurrentScope(name.toCharArray(), new int[] { - PDOMCPPLinkage.CPPCLASSTYPE, - PDOMCPPLinkage.CPPENUMERATION, - PDOMCPPLinkage.CPPTYPEDEF - }); - } - } catch(CoreException e) { + accept(visitor); + } catch (CoreException e) { CCorePlugin.log(e); } - - return null; + return visitor.getConstructors(); } - private PDOMBinding searchCurrentScopeForFunction(IASTFunctionCallExpression fce, IASTName name) throws CoreException { - try { - IType[] types = PDOMCPPLinkage.getTypes(fce.getParameterExpression()); - if(types!=null) { - return CPPFindBinding.findBinding(this, getPDOM(), name.toCharArray(), PDOMCPPLinkage.CPPFUNCTION, types); + + public boolean isFullyCached() { + return true; + } + + private static class BindingCollector implements IPDOMVisitor { + private List fBindings = new ArrayList(); + private char[] fName; + + public BindingCollector(char[] name) { + fName= name; + } + + public boolean visit(IPDOMNode node) throws CoreException { + if (node instanceof PDOMNamedNode && node instanceof IBinding) { + PDOMNamedNode nn= (PDOMNamedNode) node; + if (nn.getDBName().equals(fName)) { + fBindings.add(node); + } } - } catch(DOMException de) { - CCorePlugin.log(de); + return false; + } + public void leave(IPDOMNode node) throws CoreException { + } + public IBinding[] getBindings() { + return (IBinding[])fBindings.toArray(new IBinding[fBindings.size()]); + } + } + + public IBinding getBinding(IASTName name, boolean resolve) throws DOMException { + try { + BindingCollector visitor= new BindingCollector(name.toCharArray()); + accept(visitor); + return CPPSemantics.resolveAmbiguities(name, visitor.getBindings()); + } catch (CoreException e) { + CCorePlugin.log(e); } return null; } - - private IBinding searchCurrentScope(char[] name, int[] constants) throws CoreException { - IBinding result = null; - for(int i=0; result==null && i0) { - // make sure we're the namespace they're talking about - PDOMBinding binding = (PDOMBinding) pdom.findBinding(names[index-1]); // index == 0 ? - if(binding instanceof PDOMCPPNamespaceAlias) { - // aftodo - this needs a review - do we want to assign to binding - // or just check against this? - binding = (PDOMBinding) ((PDOMCPPNamespaceAlias) binding).getBinding(); - } - if(!equals(binding)) { - return null; - } - } else { - // ok - just search us and return null if there is nothing in here - } - } - } - - // aftodo - do we even need specify the type - we should - // expect only one name here anyway? - return searchCurrentScope(name.toCharArray(), new int[] { - PDOMCPPLinkage.CPPCLASSTYPE, - PDOMCPPLinkage.CPPNAMESPACE, - PDOMCPPLinkage.CPPFUNCTION, - PDOMCPPLinkage.CPPVARIABLE, - PDOMCPPLinkage.CPPENUMERATION, - PDOMCPPLinkage.CPPENUMERATOR - }); - } - } - - IASTNode eParent = parent.getParent(); - if (parent instanceof IASTIdExpression) { - if (eParent instanceof IASTFunctionCallExpression) { - if(parent.getPropertyInParent().equals(IASTFunctionCallExpression.FUNCTION_NAME)) { - return searchCurrentScopeForFunction((IASTFunctionCallExpression)eParent, name); - } - } else { - int desiredType = ((name.getParent() instanceof ICPPASTQualifiedName) - && ((ICPPASTQualifiedName)name.getParent()).getLastName() != name) - ? PDOMCPPLinkage.CPPNAMESPACE : PDOMCPPLinkage.CPPVARIABLE; - - IBinding result = searchCurrentScope(name.toCharArray(), new int[] {desiredType}); - if(result!=null) - return result; - return searchCurrentScope(name.toCharArray(), new int[] {PDOMCPPLinkage.CPPTYPEDEF}); - } - } else if (parent instanceof IASTNamedTypeSpecifier) { - return searchCurrentScope(name.toCharArray(), new int[] { - PDOMCPPLinkage.CPPCLASSTYPE, - PDOMCPPLinkage.CPPENUMERATION, - PDOMCPPLinkage.CPPTYPEDEF - }); - } + IBinding[] bindings= visitor.getBinding(); + return CPPSemantics.resolveAmbiguities(name, bindings); } catch (CoreException e) { CCorePlugin.log(e); } - return null; } - - private PDOMBinding searchCurrentScopeForFunction(IASTFunctionCallExpression fce, IASTName name) throws CoreException { - try { - IType[] types = PDOMCPPLinkage.getTypes(fce.getParameterExpression()); - if(types!=null) { - return CPPFindBinding.findBinding(getIndex(), getPDOM(), name.toCharArray(), PDOMCPPLinkage.CPPFUNCTION, types); - } - } catch(DOMException de) { - CCorePlugin.log(de); - } - return null; - } - - private PDOMBinding searchCurrentScope(char[] name, int[] constants) throws CoreException { - return FindBinding.findBinding(getIndex(), getPDOM(), name, constants); - } - public boolean isFullyCached() throws DOMException { return true; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java index b722713df25..5922bd7d684 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java @@ -15,11 +15,11 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.Database; @@ -33,7 +33,7 @@ import org.eclipse.core.runtime.CoreException; * * @author Doug Schaefer */ -class PDOMCPPParameter extends PDOMNamedNode implements IParameter { +class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter { /** * Offset of pointer to the next parameter (relative to the @@ -46,11 +46,20 @@ class PDOMCPPParameter extends PDOMNamedNode implements IParameter { * (relative to the beginning of the record). */ private static final int TYPE = PDOMNamedNode.RECORD_SIZE + 4; + + /** + * Offset of flags + * (relative to the beginning of the record). + */ + private static final int FLAGS = PDOMNamedNode.RECORD_SIZE + 8; + /** * The size in bytes of a PDOMCPPParameter record in the database. */ - protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 8; + protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 9; + + private static final byte FLAG_DEFAULT_VALUE = 0x1; public PDOMCPPParameter(PDOM pdom, int record) { super(pdom, record); @@ -63,6 +72,8 @@ class PDOMCPPParameter extends PDOMNamedNode implements IParameter { Database db = pdom.getDB(); db.putInt(record + NEXT_PARAM, 0); + byte flags= encodeFlags(param); + db.putByte(record + FLAGS, flags); try { IType type = param.getType(); @@ -77,6 +88,15 @@ class PDOMCPPParameter extends PDOMNamedNode implements IParameter { } } + private byte encodeFlags(IParameter param) { + byte flags= 0; + if (param instanceof ICPPParameter && + ((ICPPParameter) param).hasDefaultValue()) { + flags |= FLAG_DEFAULT_VALUE; + } + return flags; + } + protected int getRecordSize() { return RECORD_SIZE; } @@ -95,11 +115,6 @@ class PDOMCPPParameter extends PDOMNamedNode implements IParameter { return rec != 0 ? new PDOMCPPParameter(pdom, rec) : null; } - public IASTInitializer getDefaultValue() { - return null; -// TODO throw new PDOMNotImplementedError(); - } - public String[] getQualifiedName() throws DOMException { throw new PDOMNotImplementedError(); } @@ -165,4 +180,18 @@ class PDOMCPPParameter extends PDOMNamedNode implements IParameter { return new char[0]; } } + + public boolean hasDefaultValue() { + return hasFlag(FLAG_DEFAULT_VALUE, false); + } + + private boolean hasFlag(byte flag, boolean defValue) { + try { + byte myflags= pdom.getDB().getByte(record + FLAGS); + return (myflags & flag) == flag; + } catch (CoreException e) { + CCorePlugin.log(e); + } + return defValue; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPPointerToMemberType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPPointerToMemberType.java new file mode 100644 index 00000000000..c6b7d2407ca --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPPointerToMemberType.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2006 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.core.pdom.dom.cpp; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; +import org.eclipse.cdt.internal.core.index.IIndexType; +import org.eclipse.cdt.internal.core.pdom.PDOM; +import org.eclipse.cdt.internal.core.pdom.db.Database; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMPointerType; +import org.eclipse.core.runtime.CoreException; + +public class PDOMCPPPointerToMemberType extends PDOMPointerType +implements ICPPPointerToMemberType, IIndexType { + + private static final int TYPE = PDOMPointerType.RECORD_SIZE; + private static final int RECORD_SIZE= TYPE+4; + + public PDOMCPPPointerToMemberType(PDOM pdom, int record) { + super(pdom, record); + } + + public PDOMCPPPointerToMemberType(PDOM pdom, PDOMNode parent, ICPPPointerToMemberType type) throws CoreException { + super(pdom, parent, type); + Database db = pdom.getDB(); + + // type + ICPPClassType ct = type.getMemberOfClass(); + int typeRec = 0; + if (ct != null) { + PDOMNode targetTypeNode = getLinkageImpl().addType(this, ct); + if (targetTypeNode != null) + typeRec = targetTypeNode.getRecord(); + } + db.putInt(record + TYPE, typeRec); + } + + protected int getRecordSize() { + return RECORD_SIZE; + } + + public int getNodeType() { + return PDOMCPPLinkage.CPP_POINTER_TO_MEMBER_TYPE; + } + + public ICPPClassType getMemberOfClass() { + try { + int rec; + rec = pdom.getDB().getInt(record + TYPE); + if (rec != 0) { + return new PDOMCPPClassType(pdom, rec); + } + } catch (CoreException e) { + CCorePlugin.log(e); + } + return null; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPReferenceType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPReferenceType.java new file mode 100644 index 00000000000..a21c29ce40d --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPReferenceType.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2006 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.core.pdom.dom.cpp; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; +import org.eclipse.cdt.internal.core.Util; +import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; +import org.eclipse.cdt.internal.core.index.IIndexType; +import org.eclipse.cdt.internal.core.pdom.PDOM; +import org.eclipse.cdt.internal.core.pdom.db.Database; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError; +import org.eclipse.core.runtime.CoreException; + +public class PDOMCPPReferenceType extends PDOMNode implements ICPPReferenceType, + ITypeContainer, IIndexType { + + private static final int TYPE = PDOMNode.RECORD_SIZE + 0; + + protected static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 4; + + public PDOMCPPReferenceType(PDOM pdom, int record) { + super(pdom, record); + } + + public PDOMCPPReferenceType(PDOM pdom, PDOMNode parent, ICPPReferenceType type) throws CoreException { + super(pdom, parent); + + Database db = pdom.getDB(); + + try { + // type + IType targetType = type.getType(); + int typeRec = 0; + if (type != null) { + PDOMNode targetTypeNode = getLinkageImpl().addType(this, targetType); + if (targetTypeNode != null) + typeRec = targetTypeNode.getRecord(); + } + db.putInt(record + TYPE, typeRec); + } catch (DOMException e) { + throw new CoreException(Util.createStatus(e)); + } + } + + protected int getRecordSize() { + return RECORD_SIZE; + } + + public int getNodeType() { + return PDOMCPPLinkage.CPP_REFERENCE_TYPE; + } + + + public IType getType() { + try { + PDOMNode node = getLinkageImpl().getNode(pdom.getDB().getInt(record + TYPE)); + return node instanceof IType ? (IType)node : null; + } catch (CoreException e) { + CCorePlugin.log(e); + return null; + } + } + + public boolean isSameType(IType type) { + if( type instanceof ITypedef ) + return type.isSameType(this); + + if( !( type instanceof ICPPReferenceType )) + return false; + + ICPPReferenceType rhs = (ICPPReferenceType) type; + try { + IType type1= getType(); + if (type1 != null) { + return type1.isSameType(rhs.getType()); + } + } catch (DOMException e) { + } + return false; + } + + public void setType(IType type) { + throw new PDOMNotImplementedError(); + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + CCorePlugin.log(e); + return null; + } + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTypedef.java index 1b0dde406d2..cbfc3fb7588 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTypedef.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTypedef.java @@ -13,11 +13,11 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; +import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; @@ -26,15 +26,15 @@ import org.eclipse.core.runtime.CoreException; /** * @author Doug Schaefer */ -class PDOMCPPTypedef extends PDOMCPPBinding implements ITypedef, ITypeContainer { +class PDOMCPPTypedef extends PDOMCPPBinding implements ITypedef, ITypeContainer, IIndexType { private static final int TYPE = PDOMBinding.RECORD_SIZE + 0; protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 4; - public PDOMCPPTypedef(PDOM pdom, PDOMNode parent, IASTName name, ITypedef typedef) + public PDOMCPPTypedef(PDOM pdom, PDOMNode parent, ITypedef typedef) throws CoreException { - super(pdom, parent, name.toCharArray()); + super(pdom, parent, typedef.getNameCharArray()); try { IType type = typedef.getType(); PDOMNode typeNode = parent.getLinkageImpl().addType(this, type); @@ -57,7 +57,7 @@ class PDOMCPPTypedef extends PDOMCPPBinding implements ITypedef, ITypeContainer return PDOMCPPLinkage.CPPTYPEDEF; } - public IType getType() throws DOMException { + public IType getType() { try { PDOMNode node = getLinkageImpl().getNode(pdom.getDB().getInt(record + TYPE)); return node instanceof IType ? (IType)node : null; @@ -67,28 +67,19 @@ class PDOMCPPTypedef extends PDOMCPPBinding implements ITypedef, ITypeContainer } } - public boolean isSameType(IType o) { - if( o == this ) - return true; - if( o instanceof ITypedef ) - try { - IType t = getType(); - if( t != null ) - return t.isSameType( ((ITypedef)o).getType()); - return false; - } catch ( DOMException e ) { - return false; - } - - try { - IType t = getType(); - if( t != null ) - return t.isSameType( o ); - } catch(DOMException de) { - CCorePlugin.log(de); - } - - return false; + public boolean isSameType(IType type) { + try { + IType myrtype = getType(); + if (myrtype == null) + return false; + + if (type instanceof ITypedef) { + type= ((ITypedef)type).getType(); + } + return myrtype.isSameType(type); + } catch (DOMException e) { + } + return false; } public Object clone() { fail(); return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java index 5bed0ab6fe1..7edf906a022 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java @@ -374,7 +374,7 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask { IIndexFileLocation path = orderedPaths[i]; if (path != null) { if (fTrace) { - System.out.println("Indexer: adding " + path); //$NON-NLS-1$ + System.out.println("Indexer: adding " + path.getURI()); //$NON-NLS-1$ } IIndexFile file= addToIndex(index, path, symbolMap); if (postAddToIndex(path, file)) { diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCppCallHierarchyTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCppCallHierarchyTest.java index 7ac10bec7b9..5d0d09e867a 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCppCallHierarchyTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCppCallHierarchyTest.java @@ -440,7 +440,7 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest { checkTreeNode(tree, 0, 2, "ns::func()"); } - public void _testNamespacePart2_156519() throws Exception { + public void testNamespacePart2_156519() throws Exception { String content = readTaggedComment("testNamespace"); IFile file= createFile(getProject(), "testNamespace.cpp", content); waitForIndexer(fIndex, file, MAX_TIME_INDEXER); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/ResolveBindingTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/ResolveBindingTests.java index 51e79cd214e..cb3921eb2b4 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/ResolveBindingTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/ResolveBindingTests.java @@ -30,11 +30,9 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.ui.tests.BaseUITestCase; -import org.eclipse.cdt.internal.core.CCoreInternals; - public class ResolveBindingTests extends BaseUITestCase { - private static final int WAIT_FOR_INDEXER = 5000; + private static final int WAIT_FOR_INDEXER = 8000; private ICProject fCProject; private IIndex fIndex; @@ -48,8 +46,7 @@ public class ResolveBindingTests extends BaseUITestCase { protected void setUp() throws Exception { super.setUp(); - fCProject= CProjectHelper.createCProject("ResolveBindingTests", "bin", IPDOMManager.ID_NO_INDEXER); - CCoreInternals.getPDOMManager().reindex(fCProject); + fCProject= CProjectHelper.createCCProject("ResolveBindingTests", "bin", IPDOMManager.ID_FAST_INDEXER); fIndex= CCorePlugin.getIndexManager().getIndex(fCProject); } @@ -151,7 +148,7 @@ public class ResolveBindingTests extends BaseUITestCase { // m.method(); // r2 // n->method(); // r3 // } - public void _testMethodBinding_158735() throws Exception { + public void testMethodBinding_158735() throws Exception { String content = readTaggedComment("testMethods.h"); IFile hfile= createFile(fCProject.getProject(), "testMethods.h", content); content = readTaggedComment("testMethods.cpp"); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java index 909c9342fbd..e87c6cbf7e0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java @@ -441,11 +441,13 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate { */ private static String getBindingQualifiedName(IIndexBinding binding) throws CoreException { - StringBuffer buf = new StringBuffer(binding.getName()); - binding= binding.getParentBinding(); - while (binding != null) { - buf.insert(0, binding.getName() + "::"); //$NON-NLS-1$ - binding= binding.getParentBinding(); + StringBuffer buf = new StringBuffer(); + String[] qname= binding.getQualifiedName(); + for (int i = 0; i < qname.length; i++) { + if (i>0) { + buf.append("::"); //$NON-NLS-1$ + } + buf.append(qname[i]); } return buf.toString(); }