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

Fix for 164619, interaction between cpp name resolution and index.

This commit is contained in:
Markus Schorn 2006-12-06 10:41:32 +00:00
parent ea0d728a40
commit c44d3fa59d
76 changed files with 1523 additions and 867 deletions

View file

@ -80,7 +80,7 @@ public class IndexListenerTest extends BaseTestCase {
if (state[0]+state[1] < 2) { if (state[0]+state[1] < 2) {
mutex.wait(8000); mutex.wait(8000);
if (state[0]+state[1] < 2) { if (state[0]+state[1] < 2) {
mutex.wait(2000); mutex.wait(5000);
} }
} }
assertEquals(1, state[0]); assertEquals(1, state[0]);
@ -114,7 +114,7 @@ public class IndexListenerTest extends BaseTestCase {
IFile file= TestSourceReader.createFile(fProject1.getProject(), "test.cpp", "int a;"); IFile file= TestSourceReader.createFile(fProject1.getProject(), "test.cpp", "int a;");
synchronized (mutex) { synchronized (mutex) {
mutex.wait(2000); mutex.wait(8000);
} }
assertEquals(1, projects.size()); assertEquals(1, projects.size());
assertTrue(projects.contains(fProject1)); assertTrue(projects.contains(fProject1));

View file

@ -123,28 +123,23 @@ public class CPPFunctionTests extends PDOMTestBase {
assertDefinitionCount(pdom, "forwardDeclaration", 1); assertDefinitionCount(pdom, "forwardDeclaration", 1);
} }
public void _testVoidFunction() throws Exception { public void testVoidFunction() throws Exception {
// Type information not yet stored in PDOM.
assertReturnType(pdom, "voidCPPFunction", IBasicType.t_void); assertReturnType(pdom, "voidCPPFunction", IBasicType.t_void);
} }
public void _testIntFunction() throws Exception { public void testIntFunction() throws Exception {
// Type information not yet stored in PDOM.
assertReturnType(pdom, "intCPPFunction", IBasicType.t_int); assertReturnType(pdom, "intCPPFunction", IBasicType.t_int);
} }
public void _testDoubleFunction() throws Exception { public void testDoubleFunction() throws Exception {
// Type information not yet stored in PDOM.
assertReturnType(pdom, "doubleCPPFunction", IBasicType.t_double); assertReturnType(pdom, "doubleCPPFunction", IBasicType.t_double);
} }
public void _testCharFunction() throws Exception { public void testCharFunction() throws Exception {
// Type information not yet stored in PDOM.
assertReturnType(pdom, "charCPPFunction", IBasicType.t_char); assertReturnType(pdom, "charCPPFunction", IBasicType.t_char);
} }
public void _testFloatFunction() throws Exception { public void testFloatFunction() throws Exception {
// Type information not yet stored in PDOM.
assertReturnType(pdom, "floatCPPFunction", IBasicType.t_float); assertReturnType(pdom, "floatCPPFunction", IBasicType.t_float);
} }

View file

@ -81,7 +81,8 @@ public abstract class IndexBindingResolutionTestBase extends PDOMTestBase {
protected IBinding getBindingFromASTName(String section, int len) { protected IBinding getBindingFromASTName(String section, int len) {
IASTName[] names= ast.getLanguage().getSelectedNames(ast, testData[1].indexOf(section), len); IASTName[] names= ast.getLanguage().getSelectedNames(ast, testData[1].indexOf(section), len);
assertEquals("<>1 name found for \""+section+"\"", 1, names.length); 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())); assertFalse("Binding is a ProblemBinding for name "+names[0].getRawSignature(), IProblemBinding.class.isAssignableFrom(names[0].resolveBinding().getClass()));
return names[0].resolveBinding(); return names[0].resolveBinding();
} }

View file

@ -55,7 +55,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas
// long * CS::* autsch; // long * CS::* autsch;
// C * CS::* method(CS **); // C * CS::* method(CS **);
// }; // };
// // referencing file // // referencing file
// #include "header.h" // #include "header.h"
// void references() { // void references() {
@ -73,6 +73,32 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas
IBinding b3 = getBindingFromASTName("cs)->*cp->a", 2); IBinding b3 = getBindingFromASTName("cs)->*cp->a", 2);
IBinding b4 = getBindingFromASTName("autsch = lp", 6); IBinding b4 = getBindingFromASTName("autsch = lp", 6);
IBinding b5 = getBindingFromASTName("ouch;", 4); 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 b6 = getBindingFromASTName("method(cp->cspp);/*1*/", 6);
IBinding b7 = getBindingFromASTName("method(cp->cspp);/*2*/", 6); IBinding b7 = getBindingFromASTName("method(cp->cspp);/*2*/", 6);
} }
@ -367,10 +393,10 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas
// void m1() { e1 = ER1; } // void m1() { e1 = ER1; }
// static void m2() { e2 = ER2; } // static void m2() { e2 = ER2; }
// }; // };
public void _testEnumeratorInClassScope() { public void testEnumeratorInClassScope() {
IBinding b0 = getBindingFromASTName("E e1", 1); IBinding b0 = getBindingFromASTName("E e1", 1);
IBinding b1 = getBindingFromASTName("ER1; }", 1); IBinding b1 = getBindingFromASTName("ER1; }", 3);
IBinding b2 = getBindingFromASTName("ER2; }", 1); IBinding b2 = getBindingFromASTName("ER2; }", 3);
} }
// // header content // // header content
@ -426,7 +452,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas
// #include "header.h" // #include "header.h"
// void ref() { foo(); } // void ref() { foo(); }
public void _testFunctionDefaultArguments() { public void testFunctionDefaultArguments() {
IBinding b0 = getBindingFromASTName("foo();", 3); 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) // d.foo(4); // also calls long version (int version is hidden)
// // aftodo - does this test make sense? // // aftodo - does this test make sense?
// } // }
public void _testMethodHidingInInheritance() { public void testMethodHidingInInheritance() {
IBinding b0 = getBindingFromASTName("d; /*d*/", 1); IBinding b0 = getBindingFromASTName("d; /*d*/", 1);
IBinding b1 = getBindingFromASTName("foo(55L);", 3); IBinding b1 = getBindingFromASTName("foo(55L);", 3);
IBinding b2 = getBindingFromASTName("foo(4);", 3); IBinding b2 = getBindingFromASTName("foo(4);", 3);
@ -493,7 +519,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas
////reference content ////reference content
//void references() { //void references() {
// a[0]->i/*0*/++; (*a[0]).i/*1*/++; // IASTArraySubscriptExpression // 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 // ((S*)sp)->i/*3*/++; ((S)s).i/*4*/++; //aftodo-valid? // IASTCastExpression
// (true ? sp : sp)->i/*5*/++; (true ? s : s).i/*6*/++; // IASTConditionalExpression // (true ? sp : sp)->i/*5*/++; (true ? s : s).i/*6*/++; // IASTConditionalExpression
// (sp,sp)->i/*7*/++; (s,s).i/*8*/++; // IASTExpressionList // (sp,sp)->i/*7*/++; (s,s).i/*8*/++; // IASTExpressionList
@ -507,7 +533,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas
// /* not applicable */ // ICPPASTDeleteExpression // /* not applicable */ // ICPPASTDeleteExpression
// (new S())->i/*18*/++; // ICPPASTNewExpression // (new S())->i/*18*/++; // ICPPASTNewExpression
//} //}
public void _testFieldReference() { public void testFieldReference() {
IBinding b0 = getBindingFromASTName("i/*0*/", 1); IBinding b0 = getBindingFromASTName("i/*0*/", 1);
IBinding b1 = getBindingFromASTName("i/*1*/", 1); IBinding b1 = getBindingFromASTName("i/*1*/", 1);
// IBinding b2 = getBindingFromASTName(ast, "i/*2*/", 1); // IBinding b2 = getBindingFromASTName(ast, "i/*2*/", 1);
@ -559,6 +585,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas
// // foo/*p*/(MADE_UP_SYMBOL); // ICPPASTTypenameExprssion // // foo/*p*/(MADE_UP_SYMBOL); // ICPPASTTypenameExprssion
// } // }
public void _testExpressionKindForFunctionCalls() { public void _testExpressionKindForFunctionCalls() {
// depends on bug 164470 because resolution takes place during parse.
IBinding b0 = getBindingFromASTName("foo/*a*/", 3); IBinding b0 = getBindingFromASTName("foo/*a*/", 3);
IBinding b0a = getBindingFromASTName("cp[1]", 2); IBinding b0a = getBindingFromASTName("cp[1]", 2);
// assertCompositeTypeParam(0, ICPPClassType.k_class, b0, "C"); // assertCompositeTypeParam(0, ICPPClassType.k_class, b0, "C");

View file

@ -125,7 +125,7 @@ public class PDOMSearchTest extends PDOMTestBase {
/** result #1 * */ /** result #1 * */
ICPPClassType class1 = (ICPPClassType) class1s[0]; ICPPClassType class1 = (ICPPClassType) class1s[0];
assertEquals("Class1", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(class1))); assertEquals("Class1", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(class1)));
IBinding[] methods = class1.getMethods(); IBinding[] methods = class1.getDeclaredMethods();
assertEquals(0, methods.length); assertEquals(0, methods.length);
/** result #2 * */ /** result #2 * */
@ -135,7 +135,7 @@ public class PDOMSearchTest extends PDOMTestBase {
/* Members in this class */ /* Members in this class */
// methods // methods
methods = class2.getMethods(); methods = class2.getDeclaredMethods();
assertEquals(2, methods.length); assertEquals(2, methods.length);
assertEquals("Class1", methods[0].getName()); assertEquals("Class1", methods[0].getName());
assertEquals("~Class1", methods[1].getName()); assertEquals("~Class1", methods[1].getName());
@ -159,7 +159,7 @@ public class PDOMSearchTest extends PDOMTestBase {
/** result #4 * */ /** result #4 * */
ICPPClassType class4 = (ICPPClassType) class1s[3]; ICPPClassType class4 = (ICPPClassType) class1s[3];
assertEquals("namespace1::namespace2::Class1", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(class4))); assertEquals("namespace1::namespace2::Class1", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(class4)));
methods = class4.getMethods(); methods = class4.getDeclaredMethods();
assertEquals(0, methods.length); assertEquals(0, methods.length);
/* Search for "Class2" */ /* Search for "Class2" */
@ -173,7 +173,7 @@ public class PDOMSearchTest extends PDOMTestBase {
/** result #1 * */ /** result #1 * */
ICPPClassType cls1 = (ICPPClassType) class2s[0]; ICPPClassType cls1 = (ICPPClassType) class2s[0];
assertEquals("Class2", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(cls1))); assertEquals("Class2", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(cls1)));
methods = cls1.getMethods(); methods = cls1.getDeclaredMethods();
assertEquals(3, methods.length); assertEquals(3, methods.length);
assertEquals("Class2", methods[0].getName()); assertEquals("Class2", methods[0].getName());
assertEquals("~Class2", methods[1].getName()); assertEquals("~Class2", methods[1].getName());
@ -223,7 +223,7 @@ public class PDOMSearchTest extends PDOMTestBase {
public void testMethods() throws Exception { 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); assertEquals(1, methods.length);
assertTrue(methods[0] instanceof ICPPMethod); assertTrue(methods[0] instanceof ICPPMethod);
assertEquals("Class2::~Class2", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(methods[0]))); assertEquals("Class2::~Class2", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(methods[0])));

View file

@ -76,7 +76,7 @@ public class TypesTests extends PDOMTestBase {
IBinding [] As = pdom.findBindings(Pattern.compile("A"), false, new IndexFilter(), new NullProgressMonitor()); IBinding [] As = pdom.findBindings(Pattern.compile("A"), false, new IndexFilter(), new NullProgressMonitor());
assertEquals(1, As.length); assertEquals(1, As.length);
ICPPClassType A = (ICPPClassType)As[0]; ICPPClassType A = (ICPPClassType)As[0];
ICPPMethod[] Amethods = A.getMethods(); ICPPMethod[] Amethods = A.getDeclaredMethods();
assertEquals(1, Amethods.length); assertEquals(1, Amethods.length);
ICPPMethod f = Amethods[0]; ICPPMethod f = Amethods[0];
assertEquals("f", f.getName()); assertEquals("f", f.getName());

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * 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 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;
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Dec 10, 2004 * Created on Dec 10, 2004
@ -19,8 +20,20 @@ import org.eclipse.cdt.core.dom.ast.IBasicType;
* @author aniefer * @author aniefer
*/ */
public interface ICPPBasicType extends IBasicType { 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 // Extra types
public static final int t_bool = ICPPASTSimpleDeclSpecifier.t_bool; public static final int t_bool = ICPPASTSimpleDeclSpecifier.t_bool;
public static final int t_wchar_t = ICPPASTSimpleDeclSpecifier.t_wchar_t; public static final int t_wchar_t = ICPPASTSimpleDeclSpecifier.t_wchar_t;
/**
* @return a combination of qualifiers.
* @since 4.0
*/
public int getQualifierBits();
} }

View file

@ -31,4 +31,10 @@ public interface ICPPMethod extends ICPPFunction, ICPPMember {
* returns true if its name starts with '~' * returns true if its name starts with '~'
*/ */
public boolean isDestructor() throws DOMException; public boolean isDestructor() throws DOMException;
/**
* Returns whether this is an implicit method (constructor, assignment operator, etc.)
* @since 4.0
*/
public boolean isImplicit();
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,13 +7,13 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Apr 20, 2005 * Created on Apr 20, 2005
*/ */
package org.eclipse.cdt.core.dom.ast.cpp; package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IParameter; 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 { public interface ICPPParameter extends IParameter, ICPPVariable {
/** /**
* the default value of this parameter or null if there is none. * if there is a default value or not.
* @return
*/ */
public IASTInitializer getDefaultValue(); public boolean hasDefaultValue();
} }

View file

@ -14,6 +14,7 @@ package org.eclipse.cdt.core.index;
import java.util.regex.Pattern; 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.IName;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.core.runtime.CoreException; 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; 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 * 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. * or definitions, or a combination of those.

View file

@ -12,7 +12,6 @@
package org.eclipse.cdt.core.index; package org.eclipse.cdt.core.index;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.core.runtime.CoreException;
/** /**
* Represents the semantics of a name in the index. * Represents the semantics of a name in the index.
@ -30,10 +29,10 @@ import org.eclipse.core.runtime.CoreException;
* @since 4.0 * @since 4.0
*/ */
public interface IIndexBinding extends IBinding { public interface IIndexBinding extends IBinding {
IIndexBinding[] EMPTY_INDEX_BINDING_ARRAY = new IIndexBinding[0];
/** /**
* Returns the enclosing binding. May return <code>null</code>. To give an example, for a member function * Returns the qualified name of this binding as array of strings.
* the parent binding would be the class defining the member.
* @throws CoreException
*/ */
IIndexBinding getParentBinding() throws CoreException; String[] getQualifiedName();
} }

View file

@ -28,16 +28,6 @@ import org.eclipse.cdt.core.dom.ILinkage;
public class IndexFilter { public class IndexFilter {
public static final IndexFilter ALL = new 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 * Get an IndexFilter that filters out bindings from linkages other than that
* specified * 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;
}
} }

View file

@ -52,7 +52,19 @@ public class CharArrayUtils {
return true; 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 * Implements a lexicographical comparator for char arrays. Comparison is done
* on a per char basis, not a code-point basis. * on a per char basis, not a code-point basis.

View file

@ -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.ILinkage;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTBuiltinSymbolProvider; 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.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; 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.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.ArrayUtil; 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 = new CPPBasicType(IBasicType.t_float, 0);
cpp_float_complex = new GPPBasicType(IBasicType.t_float, GPPBasicType.IS_COMPLEX, null); cpp_float_complex = new GPPBasicType(IBasicType.t_float, GPPBasicType.IS_COMPLEX, null);
cpp_int = new CPPBasicType(IBasicType.t_int, 0); cpp_int = new CPPBasicType(IBasicType.t_int, 0);
cpp_long_int = new CPPBasicType(IBasicType.t_int, CPPBasicType.IS_LONG); cpp_long_int = new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_LONG);
cpp_long_double = new CPPBasicType(IBasicType.t_double, CPPBasicType.IS_LONG); cpp_long_double = new CPPBasicType(IBasicType.t_double, ICPPBasicType.IS_LONG);
cpp_long_double_complex = new GPPBasicType(IBasicType.t_double, CPPBasicType.IS_LONG | GPPBasicType.IS_COMPLEX, null); 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_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_int = new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_UNSIGNED);
cpp_unsigned_long = new CPPBasicType(IBasicType.t_int, CPPBasicType.IS_UNSIGNED | CPPBasicType.IS_LONG); cpp_unsigned_long = new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_UNSIGNED | ICPPBasicType.IS_LONG);
cpp_unsigned_long_long = new GPPBasicType(IBasicType.t_int, CPPBasicType.IS_UNSIGNED | GPPBasicType.IS_LONGLONG, null); 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_size_t = cpp_unsigned_long; // assumed unsigned long int
cpp_va_list = new CPPFunctionType( cpp_char_p, new IType[0]); // assumed: char * va_list(); 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 null;
} }
/** public boolean hasDefaultValue() {
* return false return false;
*/
public IASTInitializer getDefaultValue() {
return null;
} }
/** /**

View file

@ -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_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_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_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$ errorMessages[SEMANTIC_MEMBER_DECLARATION_NOT_FOUND - 1]= ParserMessages.getString("ASTProblemFactory.error.semantic.dom.memberDeclNotFound"); //$NON-NLS-1$
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; 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.ITypedef;
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICBasicType; import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
import org.eclipse.cdt.internal.core.index.IIndexType;
/** /**
* @author dsteffle * @author dsteffle
@ -116,7 +118,7 @@ public class CBasicType implements ICBasicType {
public boolean isSameType(IType obj) { public boolean isSameType(IType obj) {
if( obj == this ) if( obj == this )
return true; return true;
if( obj instanceof ITypedef ) if( obj instanceof ITypedef || obj instanceof IIndexType)
return obj.isSameType( this ); return obj.isSameType( this );
if (!(obj instanceof CBasicType)) return false; if (!(obj instanceof CBasicType)) return false;

View file

@ -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.ICASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier;
import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
/** /**
@ -154,7 +155,7 @@ public class CEnumeration extends PlatformObject implements IEnumeration {
public boolean isSameType( IType type ) { public boolean isSameType( IType type ) {
if( type == this ) if( type == this )
return true; return true;
if( type instanceof ITypedef ) if( type instanceof ITypedef || type instanceof IIndexType)
return type.isSameType( this ); return type.isSameType( this );
return false; return false;

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; 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.ICASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.c.ICPointerType; import org.eclipse.cdt.core.dom.ast.c.ICPointerType;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.index.IIndexType;
/** /**
* @author dsteffle * @author dsteffle
@ -80,7 +82,7 @@ public class CQualifiedPointerType implements ICPointerType, ITypeContainer {
public boolean isSameType( IType type ) { public boolean isSameType( IType type ) {
if( type == this ) if( type == this )
return true; return true;
if( type instanceof ITypedef ) if( type instanceof ITypedef || type instanceof IIndexType)
return type.isSameType( this ); return type.isSameType( this );
if( type instanceof CQualifiedPointerType ){ if( type instanceof CQualifiedPointerType ){

View file

@ -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.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
/** /**
@ -257,7 +258,7 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte
public boolean isSameType( IType type ) { public boolean isSameType( IType type ) {
if( type == this ) if( type == this )
return true; return true;
if( type instanceof ITypedef ) if( type instanceof ITypedef || type instanceof IIndexType)
return type.isSameType( this ); return type.isSameType( this );
return false; return false;
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; 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.IASTNameOwner;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
/** /**
* @author jcamelon * @author jcamelon
*/ */
public class CPPASTName extends CPPASTNode implements IASTName { 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 char[] EMPTY_CHAR_ARRAY = {};
private static final String EMPTY_STRING = ""; //$NON-NLS-1$ private static final String EMPTY_STRING = ""; //$NON-NLS-1$
private static final int MAX_RESOLUTION_DEPTH = 3;
private IBinding binding = null; private IBinding binding = null;
private int fResolutionDepth= 0;
/** /**
* @param name * @param name
@ -48,9 +63,14 @@ public class CPPASTName extends CPPASTNode implements IASTName {
* @see org.eclipse.cdt.core.dom.ast.IASTName#resolveBinding() * @see org.eclipse.cdt.core.dom.ast.IASTName#resolveBinding()
*/ */
public IBinding resolveBinding() { public IBinding resolveBinding() {
if (binding == null) if (binding == null) {
binding = CPPVisitor.createBinding(this); if (++fResolutionDepth > MAX_RESOLUTION_DEPTH) {
binding= new RecursionResolvingBinding(this);
}
else {
binding = CPPVisitor.createBinding(this);
}
}
return binding; return binding;
} }
@ -60,6 +80,7 @@ public class CPPASTName extends CPPASTNode implements IASTName {
public void setBinding(IBinding binding) { public void setBinding(IBinding binding) {
this.binding = binding; this.binding = binding;
fResolutionDepth= 0;
} }
public IBinding getBinding() { public IBinding getBinding() {

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Dec 10, 2004 * 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.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.internal.core.index.IIndexType;
/** /**
* @author aniefer * @author aniefer
*/ */
public class CPPBasicType implements ICPPBasicType { 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 qualifierBits = 0;
protected int type; protected int type;
@ -53,7 +50,7 @@ public class CPPBasicType implements ICPPBasicType {
if( object == this ) if( object == this )
return true; return true;
if( object instanceof ITypedef ) if( object instanceof ITypedef || object instanceof IIndexType)
return object.isSameType( this ); return object.isSameType( this );
if( !(object instanceof CPPBasicType) ) if( !(object instanceof CPPBasicType) )
@ -127,4 +124,8 @@ public class CPPBasicType implements ICPPBasicType {
public void setValue( IASTExpression val ){ public void setValue( IASTExpression val ){
value = val; value = val;
} }
public int getQualifierBits() {
return qualifierBits;
}
} }

View file

@ -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.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
/** /**
@ -778,8 +779,8 @@ public class CPPClassType extends PlatformObject implements ICPPClassType, ICPPI
public boolean isSameType( IType type ) { public boolean isSameType( IType type ) {
if( type == this ) if( type == this )
return true; return true;
if( type instanceof ITypedef ) if( type instanceof ITypedef || type instanceof IIndexType)
return ((ITypedef)type).isSameType( this ); return type.isSameType( this );
return false; return false;
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * 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.ICPPBlockScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
/** /**
@ -186,8 +188,8 @@ public class CPPEnumeration extends PlatformObject implements IEnumeration, ICPP
public boolean isSameType( IType type ) { public boolean isSameType( IType type ) {
if( type == this ) if( type == this )
return true; return true;
if( type instanceof ITypedef ) if( type instanceof ITypedef || type instanceof IIndexType)
return ((ITypedef)type).isSameType( this ); return type.isSameType( this );
return false; return false;
} }

View file

@ -177,7 +177,9 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
IScope scope = getScope(); IScope scope = getScope();
try { try {
IASTNode node = ASTInternal.getPhysicalNodeOfScope(scope); IASTNode node = ASTInternal.getPhysicalNodeOfScope(scope);
tu = node.getTranslationUnit(); if (node != null) {
tu = node.getTranslationUnit();
}
} catch ( DOMException e ) { } catch ( DOMException e ) {
} }
} }

View file

@ -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.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; 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.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
@ -87,6 +88,9 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod
IType [] params = ftype.getParameterTypes(); IType [] params = ftype.getParameterTypes();
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(getScope()); ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(getScope());
if (compSpec == null) {
return null;
}
IASTDeclaration [] members = compSpec.getMembers(); IASTDeclaration [] members = compSpec.getMembers();
for( int i = 0; i < members.length; i++ ){ for( int i = 0; i < members.length; i++ ){
IASTDeclarator dtor = null; IASTDeclarator dtor = null;
@ -113,21 +117,28 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod
{ {
IFunctionType t = (IFunctionType) CPPVisitor.createType( dtor ); IFunctionType t = (IFunctionType) CPPVisitor.createType( dtor );
IType [] ps = t.getParameterTypes(); IType [] ps = t.getParameterTypes();
boolean ok= false;
if( ps.length == params.length ){ if( ps.length == params.length ){
int idx = 0; int idx = 0;
for( ; idx < ps.length && ps[idx] != null; idx++ ){ for( ; idx < ps.length && ps[idx] != null; idx++ ){
if( !ps[idx].isSameType(params[idx]) ) if( !ps[idx].isSameType(params[idx]) )
break; break;
} }
if( idx == ps.length ){ ok= idx == ps.length;
name.setBinding( this ); }
if( member instanceof IASTSimpleDeclaration ) else if (ps.length == 0) {
addDeclaration( dtor ); if (params.length == 1) {
else if( member instanceof IASTFunctionDefinition ) IType t1= params[0];
addDefinition( dtor ); ok = (t1 instanceof IBasicType) && ((IBasicType) t1).getType() == IBasicType.t_void;
return members[i];
} }
}
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; dtor = ( di > -1 && ++ di < ds.length ) ? ds[di] : null;
@ -146,4 +157,12 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod
return n[0] == '~'; return n[0] == '~';
return false; return false;
} }
public boolean isImplicit() {
try {
return getPrimaryDeclaration() == null;
} catch (DOMException e) {
}
return true;
}
} }

View file

@ -64,6 +64,9 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
return false; return false;
} }
public boolean isImplicit() {
return ((ICPPMethod)getBinding()).isImplicit();
}
} }
public static class CPPMethodProblem extends CPPFunctionProblem implements ICPPMethod { public static class CPPMethodProblem extends CPPFunctionProblem implements ICPPMethod {
@ -98,6 +101,10 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
return false; return false;
} }
public boolean isImplicit() {
return false;
}
} }
public CPPMethod( ICPPASTFunctionDeclarator declarator ){ public CPPMethod( ICPPASTFunctionDeclarator declarator ){
@ -121,25 +128,27 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
ICPPClassScope scope = (ICPPClassScope) getScope(); ICPPClassScope scope = (ICPPClassScope) getScope();
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(scope); ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(scope);
IASTDeclaration [] members = compSpec.getMembers(); if (compSpec != null) {
for( int i = 0; i < members.length; i++ ){ IASTDeclaration [] members = compSpec.getMembers();
if( members[i] instanceof IASTSimpleDeclaration ){ for( int i = 0; i < members.length; i++ ){
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)members[i]).getDeclarators(); if( members[i] instanceof IASTSimpleDeclaration ){
for( int j = 0; j < dtors.length; j++ ){ IASTDeclarator [] dtors = ((IASTSimpleDeclaration)members[i]).getDeclarators();
IASTName name = dtors[j].getName(); 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 ) && if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
name.resolveBinding() == this ) name.resolveBinding() == this )
{ {
return members[i]; 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; return null;
@ -278,4 +287,8 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
return false; return false;
} }
public boolean isImplicit() {
return false;
}
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Mar 29, 2005 * Created on Mar 29, 2005
@ -65,4 +66,8 @@ public class CPPMethodInstance extends CPPFunctionInstance implements ICPPMethod
return false; return false;
} }
public boolean isImplicit() {
return false;
}
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,7 +7,7 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* / * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Apr 29, 2005 * Created on Apr 29, 2005
@ -82,4 +82,8 @@ public class CPPMethodSpecialization extends CPPFunctionSpecialization
return false; return false;
} }
public boolean isImplicit() {
return false;
}
} }

View file

@ -151,4 +151,8 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
return false; return false;
} }
public boolean isImplicit() {
return false;
}
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,7 +7,7 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* / * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Apr 29, 2005 * Created on Apr 29, 2005
@ -65,4 +65,8 @@ public class CPPMethodTemplateSpecialization extends
return false; return false;
} }
public boolean isImplicit() {
return false;
}
} }

View file

@ -60,8 +60,8 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI
public boolean isMutable() { public boolean isMutable() {
return false; return false;
} }
public IASTInitializer getDefaultValue() { public boolean hasDefaultValue() {
return ((ICPPParameter)getBinding()).getDefaultValue(); return ((ICPPParameter)getBinding()).hasDefaultValue();
} }
} }
@ -276,6 +276,10 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI
return null; return null;
} }
public boolean hasDefaultValue() {
return getDefaultValue() != null;
}
public ILinkage getLinkage() { public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE; return Linkage.CPP_LINKAGE;
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Mar 29, 2005 * Created on Mar 29, 2005
@ -14,7 +15,6 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException; 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.IASTName;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
@ -87,8 +87,8 @@ public class CPPParameterSpecialization extends CPPSpecialization implements ICP
return false; return false;
} }
public IASTInitializer getDefaultValue() { public boolean hasDefaultValue() {
return getParameter().getDefaultValue(); return getParameter().hasDefaultValue();
} }
public ICPPDelegate createDelegate(IASTName name) { public ICPPDelegate createDelegate(IASTName name) {

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Feb 11, 2005 * 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.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember; 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.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
import org.eclipse.cdt.internal.core.index.IIndexType;
/** /**
* @author aniefer * @author aniefer
@ -39,6 +42,11 @@ public class CPPPointerToMemberType extends CPPPointerType implements
} }
public boolean isSameType( IType o ){ 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 ) ) if( !super.isSameType( o ) )
return false; return false;

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Dec 10, 2004 * 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.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.index.IIndexType;
/** /**
* @author aniefer * @author aniefer
@ -62,8 +64,8 @@ public class CPPPointerType implements IPointerType, ITypeContainer {
public boolean isSameType( IType o ){ public boolean isSameType( IType o ){
if( o == this ) if( o == this )
return true; return true;
if( o instanceof ITypedef ) if( o instanceof ITypedef || o instanceof IIndexType)
return ((ITypedef)o).isSameType( this ); return o.isSameType( this );
if( !( o instanceof CPPPointerType ) ) if( !( o instanceof CPPPointerType ) )
return false; return false;

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * 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.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.index.IIndexType;
/** /**
* @author aniefer * @author aniefer
@ -34,7 +36,7 @@ public class CPPQualifierType implements IQualifierType, ITypeContainer {
} }
public boolean isSameType( IType o ){ public boolean isSameType( IType o ){
if( o instanceof ITypedef ) if( o instanceof ITypedef || o instanceof IIndexType)
return o.isSameType( this ); return o.isSameType( this );
if( !( o instanceof CPPQualifierType ) ) if( !( o instanceof CPPQualifierType ) )
return false; return false;

View file

@ -14,10 +14,10 @@
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; 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.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.ObjectSet; 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.IASTInternalScope;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.core.runtime.CoreException;
/** /**
* @author aniefer * @author aniefer
@ -84,6 +84,30 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
} }
public IBinding getBinding(IASTName name, boolean forceResolve) throws DOMException { 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(); char [] c = name.toCharArray();
//can't look up bindings that don't have a name //can't look up bindings that don't have a name
if( c.length == 0 ) if( c.length == 0 )
@ -127,27 +151,10 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
return binding; return binding;
} }
return (IBinding) obj; return (IBinding) obj;
} else { }
IIndex index = name.getTranslationUnit().getIndex(); return null;
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;
} }
private boolean isfull = false; private boolean isfull = false;
public void setFullyCached( boolean full ){ public void setFullyCached( boolean full ){
isfull = full; isfull = full;

View file

@ -14,7 +14,6 @@
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; 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.ICPPTemplateTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; 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.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; 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.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; 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 * @author aniefer
@ -750,24 +747,12 @@ public class CPPSemantics {
addDefinition( binding, data.astName ); addDefinition( binding, data.astName );
} }
} }
if( binding == null || binding instanceof IProblemBinding ){ // If we're still null...
// Let's try the pdom if (binding == null) {
IIndex index = name.getTranslationUnit().getIndex(); if( name instanceof ICPPASTQualifiedName && data.forDefinition() )
if (index != null) { binding = new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND, data.name() );
try { else
binding = index.findBinding(name); binding = new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, data.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() );
}
} }
return binding; return binding;
} }
@ -1033,14 +1018,21 @@ public class CPPSemantics {
mergeResults( data, binding, true ); mergeResults( data, binding, true );
} }
} else { } else {
IBinding b= null;
if (!data.prefixLookup && data.astName != null ) { if (!data.prefixLookup && data.astName != null ) {
IBinding b = scope.getBinding( data.astName, false ); b= scope.getBinding( data.astName, false );
if (b instanceof CPPImplicitFunction || b instanceof CPPImplicitTypedef if (b instanceof CPPImplicitFunction || b instanceof CPPImplicitTypedef)
|| b instanceof PDOMBinding)
// TODO the PDOMBinding thing is a kludge
mergeResults( data, b, true ); 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 ){ if( (!data.hasResults() || data.prefixLookup) && scope instanceof ICPPNamespaceScope ){
@ -1101,7 +1093,11 @@ public class CPPSemantics {
node = blockItem; node = blockItem;
ICPPScope parentScope = (ICPPScope) scope.getParent(); 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(); IASTNode parent = node.getParent();
while( parent != null && !(parent instanceof ICPPASTTemplateDeclaration) ){ while( parent != null && !(parent instanceof ICPPASTTemplateDeclaration) ){
node = parent; 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 ); bindings = ArrayUtil.trim( Object.class, bindings );
if( bindings == null || bindings.length == 0 ) if( bindings == null || bindings.length == 0 )
return null; return null;
@ -1908,6 +1904,7 @@ public class CPPSemantics {
IBinding obj = null; IBinding obj = null;
IBinding temp = null; IBinding temp = null;
ObjectSet fns = ObjectSet.EMPTY_SET; ObjectSet fns = ObjectSet.EMPTY_SET;
boolean fnsFromAST= false;
ObjectSet templateFns = ObjectSet.EMPTY_SET; ObjectSet templateFns = ObjectSet.EMPTY_SET;
Object [] items = (Object[]) data.foundItems; Object [] items = (Object[]) data.foundItems;
@ -1938,6 +1935,28 @@ public class CPPSemantics {
mergeResults( data, bindings, false ); mergeResults( data, bindings, false );
items = (Object[]) data.foundItems; items = (Object[]) data.foundItems;
continue; 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 ){ } else if( temp instanceof IType ){
if( type == null ){ if( type == null ){
type = temp; type = temp;
@ -1954,25 +1973,25 @@ public class CPPSemantics {
} else if( type != temp && !((IType)type).isSameType( (IType) temp )) { } else if( type != temp && !((IType)type).isSameType( (IType) temp )) {
return new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name() ); 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 { } else {
if( obj == null ) if( obj == null)
obj = temp; obj = temp;
else if( (temp instanceof ICPPDelegate && ((ICPPDelegate)temp).getBinding() == obj) || else if ( obj == temp ||
(obj instanceof ICPPDelegate && ((ICPPDelegate)obj).getBinding() == temp) ) (temp instanceof ICPPDelegate && ((ICPPDelegate)temp).getBinding() == obj) ||
{ (obj instanceof ICPPDelegate && ((ICPPDelegate)obj).getBinding() == temp)) {
//ok, delegates are synonyms //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; int size = functions.length;
for( int i = 0; i < size && functions[i] != null; i++ ){ for( int i = 0; i < size && functions[i] != null; i++ ){
function = (IFunction) functions[i]; function = (IFunction) functions[i];
if (function instanceof IProblemBinding) {
functions[i]= null;
continue;
}
num = function.getParameters().length; num = function.getParameters().length;
//if there are m arguments in the list, all candidate functions having m parameters //if there are m arguments in the list, all candidate functions having m parameters
@ -2087,7 +2110,7 @@ public class CPPSemantics {
else { else {
IParameter [] params = function.getParameters(); IParameter [] params = function.getParameters();
for( int j = num - 1; j >= numParameters; j-- ){ for( int j = num - 1; j >= numParameters; j-- ){
if( ((ICPPParameter)params[j]).getDefaultValue() == null ){ if( !((ICPPParameter)params[j]).hasDefaultValue()){
functions[i] = null; functions[i] = null;
break; break;
} }

View file

@ -392,7 +392,7 @@ public class CPPVisitor {
try { try {
if( name.toCharArray().length > 0 && scope != null ) //can't lookup anonymous things if( name.toCharArray().length > 0 && scope != null ) //can't lookup anonymous things
binding = scope.getBinding( name, false ); binding = scope.getBinding( name, false );
if( binding == null || !(binding instanceof ICPPClassType) ){ if( !(binding instanceof ICPPInternalBinding) || !(binding instanceof ICPPClassType)){
if( template ) if( template )
binding = new CPPClassTemplate( name ); binding = new CPPClassTemplate( name );
else else
@ -400,14 +400,11 @@ public class CPPVisitor {
if( scope != null ) if( scope != null )
ASTInternal.addName( scope, compType.getName() ); ASTInternal.addName( scope, compType.getName() );
} else { } else {
if( binding instanceof ICPPInternalBinding ){ ICPPInternalBinding internal = (ICPPInternalBinding) binding;
ICPPInternalBinding internal = (ICPPInternalBinding) binding; if( internal.getDefinition() == null )
if( internal.getDefinition() == null ) internal.addDefinition( compType );
internal.addDefinition( compType ); else
else binding = new ProblemBinding( name, IProblemBinding.SEMANTIC_INVALID_REDEFINITION, name.toCharArray() );
binding = new ProblemBinding( name, IProblemBinding.SEMANTIC_INVALID_REDEFINITION, name.toCharArray() );
}
} }
} catch ( DOMException e ) { } catch ( DOMException e ) {
binding = e.getProblem(); binding = e.getProblem();
@ -421,7 +418,7 @@ public class CPPVisitor {
IBinding binding; IBinding binding;
try { try {
binding = scope.getBinding( namespaceDef.getName(), false ); binding = scope.getBinding( namespaceDef.getName(), false );
if( binding == null || binding instanceof IProblemBinding ){ if( !(binding instanceof ICPPInternalBinding) || binding instanceof IProblemBinding ){
binding = new CPPNamespace( namespaceDef ); binding = new CPPNamespace( namespaceDef );
ASTInternal.addName( scope, namespaceDef.getName() ); ASTInternal.addName( scope, namespaceDef.getName() );
} }
@ -532,21 +529,23 @@ public class CPPVisitor {
return CPPTemplates.createBinding( param ); return CPPTemplates.createBinding( param );
} }
} else if( simpleDecl != null && simpleDecl.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef ){ } else if( simpleDecl != null && simpleDecl.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef ){
if( binding != null && binding instanceof ITypedef ){ if( binding instanceof ICPPInternalBinding && binding instanceof ITypedef ){
try { try {
IType t1 = ((ITypedef)binding).getType(); IType t1 = ((ITypedef)binding).getType();
IType t2 = createType( declarator ); IType t2 = createType( declarator );
if( t1 != null && t2 != null && t1.isSameType( t2 ) ){ if( t1 != null && t2 != null && t1.isSameType( t2 ) ){
((ICPPInternalBinding)binding).addDeclaration( name ); ICPPInternalBinding internal = (ICPPInternalBinding) binding;
internal.addDeclaration(name);
return binding; return binding;
} }
} catch ( DOMException e1 ) { } catch ( DOMException e1 ) {
return e1.getProblem();
} }
return new ProblemBinding( name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION, name.toCharArray() ); return new ProblemBinding( name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION, name.toCharArray() );
} }
binding = new CPPTypedef( name ); binding = new CPPTypedef( name );
} else if( declarator instanceof ICPPASTFunctionDeclarator ){ } else if( declarator instanceof ICPPASTFunctionDeclarator ){
if( binding != null && binding instanceof IFunction ){ if( binding instanceof ICPPInternalBinding && binding instanceof IFunction ){
IFunction function = (IFunction) binding; IFunction function = (IFunction) binding;
if( CPPSemantics.isSameFunction( function, declarator ) ){ if( CPPSemantics.isSameFunction( function, declarator ) ){
ICPPInternalBinding internal = (ICPPInternalBinding) function; ICPPInternalBinding internal = (ICPPInternalBinding) function;
@ -554,7 +553,7 @@ public class CPPVisitor {
internal.addDeclaration( name ); internal.addDeclaration( name );
else { else {
if( internal.getDefinition() == null ) if( internal.getDefinition() == null )
((ICPPInternalBinding)function).addDefinition( name ); internal.addDefinition( name );
else { else {
IASTNode def = internal.getDefinition(); IASTNode def = internal.getDefinition();
if( def instanceof IASTDeclarator ) if( def instanceof IASTDeclarator )
@ -1588,10 +1587,10 @@ public class CPPVisitor {
name = ((IASTEnumerationSpecifier)declSpec).getName(); name = ((IASTEnumerationSpecifier)declSpec).getName();
} else if( declSpec instanceof ICPPASTSimpleDeclSpecifier ){ } else if( declSpec instanceof ICPPASTSimpleDeclSpecifier ){
ICPPASTSimpleDeclSpecifier spec = (ICPPASTSimpleDeclSpecifier) declSpec; ICPPASTSimpleDeclSpecifier spec = (ICPPASTSimpleDeclSpecifier) declSpec;
int bits = ( spec.isLong() ? CPPBasicType.IS_LONG : 0 ) | int bits = ( spec.isLong() ? ICPPBasicType.IS_LONG : 0 ) |
( spec.isShort() ? CPPBasicType.IS_SHORT : 0 ) | ( spec.isShort() ? ICPPBasicType.IS_SHORT : 0 ) |
( spec.isSigned() ? CPPBasicType.IS_SIGNED: 0 ) | ( spec.isSigned() ? ICPPBasicType.IS_SIGNED: 0 ) |
( spec.isUnsigned() ? CPPBasicType.IS_UNSIGNED : 0 ); ( spec.isUnsigned() ? ICPPBasicType.IS_UNSIGNED : 0 );
if( spec instanceof IGPPASTSimpleDeclSpecifier ){ if( spec instanceof IGPPASTSimpleDeclSpecifier ){
IGPPASTSimpleDeclSpecifier gspec = (IGPPASTSimpleDeclSpecifier) spec; IGPPASTSimpleDeclSpecifier gspec = (IGPPASTSimpleDeclSpecifier) spec;
if( gspec.getTypeofExpression() != null ){ if( gspec.getTypeofExpression() != null ){
@ -1606,9 +1605,7 @@ public class CPPVisitor {
} }
if( name != null ){ if( name != null ){
IBinding binding = name.resolveBinding(); IBinding binding = name.resolveBinding();
if( binding instanceof IType ) if( binding instanceof ICPPConstructor ){
type = (IType) binding;
else if( binding instanceof ICPPConstructor ){
try { try {
ICPPClassScope scope = (ICPPClassScope) binding.getScope(); ICPPClassScope scope = (ICPPClassScope) binding.getScope();
type = scope.getClassType(); type = scope.getClassType();
@ -1616,6 +1613,8 @@ public class CPPVisitor {
} catch (DOMException e) { } catch (DOMException e) {
type = e.getProblem(); type = e.getProblem();
} }
} else if( binding instanceof IType ) {
type = (IType) binding;
} else if( binding instanceof ICPPTemplateNonTypeParameter ){ } else if( binding instanceof ICPPTemplateNonTypeParameter ){
//TODO workaround... is there anything better? //TODO workaround... is there anything better?
try { try {
@ -1831,7 +1830,7 @@ public class CPPVisitor {
} }
} catch (DOMException e) { } 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() ); IType type = getExpressionType(((IASTUnaryExpression)expression).getOperand() );
@ -1886,7 +1885,7 @@ public class CPPVisitor {
} }
} catch (DOMException e) { } 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() ); return createType( typeidExp.getTypeId() );
} else if( expression instanceof IASTArraySubscriptExpression ){ } else if( expression instanceof IASTArraySubscriptExpression ){

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
@ -15,8 +16,10 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointerToMember; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointerToMember;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPPointerToMemberType; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPPointerToMemberType;
import org.eclipse.cdt.internal.core.index.IIndexType;
/** /**
* @author aniefer * @author aniefer
@ -55,8 +58,14 @@ public class GPPPointerToMemberType extends CPPPointerToMemberType implements
} }
public boolean isSameType( IType o ){ 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( !super.isSameType( o ) ) return false;
if( o instanceof IGPPPointerToMemberType ){ if( o instanceof IGPPPointerToMemberType ){
return (isRestrict == ((IGPPPointerToMemberType) o).isRestrict()); return (isRestrict == ((IGPPPointerToMemberType) o).isRestrict());
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
@ -15,8 +16,10 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPPointerType; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPPointerType;
import org.eclipse.cdt.internal.core.index.IIndexType;
/** /**
* @author aniefer * @author aniefer
@ -67,6 +70,13 @@ public class GPPPointerType extends CPPPointerType implements IGPPPointerType {
} }
public boolean isSameType( IType o ){ 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( !super.isSameType( o ) ) return false;
if( o instanceof IGPPPointerType ){ if( o instanceof IGPPPointerType ){

View file

@ -20,6 +20,8 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; 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.IName;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
@ -324,4 +326,46 @@ public class CIndex implements IIndex {
} }
return result; 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;
}
} }

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.index;
import java.util.regex.Pattern; 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.IName;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
@ -96,4 +97,12 @@ final public class EmptyCIndex implements IIndex {
public IIndexBinding adaptBinding(IBinding binding) throws CoreException { public IIndexBinding adaptBinding(IBinding binding) throws CoreException {
return null; 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;
}
} }

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.index;
import java.util.regex.Pattern; 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.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
@ -133,5 +134,13 @@ public interface IIndexFragment {
*/ */
long getLastWriteAccess(); 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;
} }

View file

@ -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 {
}

View file

@ -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 # All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0 # are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at # which accompanies this distribution, and is available at
@ -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.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.invalidRedefinition=Invalid redefinition of the name {0}
ASTProblemFactory.error.semantic.dom.invalidRedeclaration=Invalid redeclaration 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.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} ASTProblemFactory.error.semantic.dom.memberDeclNotFound=A declaration could not be found for this member definition: {0}

View file

@ -30,8 +30,8 @@ import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding; 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.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexName; import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.index.IndexFilter; 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.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; 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.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.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
@ -66,7 +68,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
private Database db; private Database db;
public static final int VERSION = 18; public static final int VERSION = 20;
// 0 - the beginning of it all // 0 - the beginning of it all
// 1 - first change to kick off upgrades // 1 - first change to kick off upgrades
// 2 - added file inclusions // 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. // 17 - use single linked list for names in file, adds a link to enclosing defintion name.
// 18 - distinction between c-unions and c-structs. // 18 - distinction between c-unions and c-structs.
// 19 - alter representation of paths in the pdom (162172) // 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 LINKAGES = Database.DATA_AREA;
public static final int FILE_INDEX = Database.DATA_AREA + 4; 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 Map fLinkageIDCache = new HashMap();
private File fPath; private File fPath;
private IIndexLocationConverter locationConverter; private IIndexLocationConverter locationConverter;
public PDOM(File dbPath, IIndexLocationConverter locationConverter) throws CoreException { public PDOM(File dbPath, IIndexLocationConverter locationConverter) throws CoreException {
// Load up the database // Load up the database
fPath= dbPath; fPath= dbPath;
@ -249,11 +252,13 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
private List bindings = new ArrayList(); private List bindings = new ArrayList();
private boolean isFullyQualified; private boolean isFullyQualified;
private BitSet matchesUpToLevel; 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.pattern = pattern;
this.monitor = monitor; this.monitor = monitor;
this.isFullyQualified= isFullyQualified; this.isFullyQualified= isFullyQualified;
this.acceptImplicitMethods= acceptImplicitMethods;
matchesUpToLevel= new BitSet(); matchesUpToLevel= new BitSet();
matchesUpToLevel.set(0); matchesUpToLevel.set(0);
matchStack.add(matchesUpToLevel); matchStack.add(matchesUpToLevel);
@ -270,7 +275,10 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
// check if we have a complete match. // check if we have a complete match.
final int lastIdx = pattern.length-1; final int lastIdx = pattern.length-1;
if (matchesUpToLevel.get(lastIdx) && pattern[lastIdx].matcher(name).matches()) { 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 // 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 { 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();) { for (Iterator iter = fLinkageIDCache.values().iterator(); iter.hasNext();) {
PDOMLinkage linkage = (PDOMLinkage) iter.next(); PDOMLinkage linkage = (PDOMLinkage) iter.next();
if (filter.acceptLinkage(linkage)) { if (filter.acceptLinkage(linkage)) {
@ -580,4 +588,20 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
public File getPath() { public File getPath() {
return fPath; 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;
}
} }

View file

@ -25,8 +25,8 @@ import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.IPDOMIndexer; import org.eclipse.cdt.core.dom.IPDOMIndexer;
import org.eclipse.cdt.core.dom.IPDOMIndexerTask; import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
import org.eclipse.cdt.core.dom.IPDOMManager; 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.IIndex;
import org.eclipse.cdt.core.index.IIndexChangeListener;
import org.eclipse.cdt.core.index.IIndexerStateListener; import org.eclipse.cdt.core.index.IIndexerStateListener;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElementDelta; 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.CoreException;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.IStatus; 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. * Stores mapping from pdom to project, used to serialize\ creation of new pdoms.
*/ */
private Map fProjectToPDOM= new HashMap(); private Map fProjectToPDOM= new HashMap();
private Map fLocationToCProject= new HashMap(); private Map fFileToProject= new HashMap();
private ListenerList fChangeListeners= new ListenerList(); private ListenerList fChangeListeners= new ListenerList();
private ListenerList fStateListeners= new ListenerList(); private ListenerList fStateListeners= new ListenerList();
@ -155,19 +154,19 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
} }
String dbName= rproject.getPersistentProperty(dbNameProperty); String dbName= rproject.getPersistentProperty(dbNameProperty);
IPath dbPath= null; File dbFile= null;
if (dbName != null) { if (dbName != null) {
dbPath= CCorePlugin.getDefault().getStateLocation().append(dbName); dbFile= CCorePlugin.getDefault().getStateLocation().append(dbName).toFile();
ICProject currentCOwner= (ICProject) fLocationToCProject.get(dbPath); ICProject currentCOwner= (ICProject) fFileToProject.get(dbFile);
if (currentCOwner != null) { if (currentCOwner != null) {
IProject currentOwner= currentCOwner.getProject(); IProject currentOwner= currentCOwner.getProject();
if (currentOwner.exists()) { if (currentOwner.exists()) {
dbName= null; dbName= null;
dbPath= null; dbFile= null;
} }
else { else {
pdom= (WritablePDOM) fProjectToPDOM.remove(currentOwner); 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) { if (dbName == null) {
dbName= getDefaultName(project); dbName= getDefaultName(project);
rproject.setPersistentProperty(dbNameProperty, dbName); 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); pdom.addListener(this);
} }
fLocationToCProject.put(dbPath, project); fFileToProject.put(dbFile, project);
fProjectToPDOM.put(rproject, pdom); fProjectToPDOM.put(rproject, pdom);
return pdom; return pdom;
} }
@ -626,7 +625,7 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
ICProject project; ICProject project;
synchronized (fProjectToPDOM) { synchronized (fProjectToPDOM) {
project = (ICProject) fLocationToCProject.get(pdom.getPath()); project = (ICProject) fFileToProject.get(pdom.getPath());
} }
if (project != null) { if (project != null) {

View file

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

View file

@ -12,6 +12,9 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom; 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.CCorePlugin;
import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
@ -214,4 +217,21 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
return null; 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;
}
}
} }

View file

@ -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.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; 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.IBinding;
import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IQualifierType; import org.eclipse.cdt.core.dom.ast.IQualifierType;
@ -58,7 +59,8 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
// node types // node types
protected static final int LINKAGE = 0; // special one for myself protected static final int LINKAGE = 0; // special one for myself
static final int POINTER_TYPE = 1; 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; 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)) { switch (PDOMNode.getNodeType(pdom, record)) {
case POINTER_TYPE: case POINTER_TYPE:
return new PDOMPointerType(pdom, record); return new PDOMPointerType(pdom, record);
case ARRAY_TYPE:
return new PDOMArrayType(pdom, record);
case QUALIFIER_TYPE: case QUALIFIER_TYPE:
return new PDOMQualifierType(pdom, record); return new PDOMQualifierType(pdom, record);
} }
@ -143,6 +147,8 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
if (type instanceof IPointerType) if (type instanceof IPointerType)
node = new PDOMPointerType(pdom, parent, (IPointerType)type); node = new PDOMPointerType(pdom, parent, (IPointerType)type);
else if (type instanceof IArrayType)
node= new PDOMArrayType(pdom, parent, (IArrayType) type);
else if (type instanceof IQualifierType) else if (type instanceof IQualifierType)
node = new PDOMQualifierType(pdom, parent, (IQualifierType)type); node = new PDOMQualifierType(pdom, parent, (IQualifierType)type);
else else
@ -180,11 +186,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
} }
if (scope instanceof IIndexBinding) { if (scope instanceof IIndexBinding) {
IIndexBinding parent= ((IIndexBinding) scope).getParentBinding(); return adaptBinding((IBinding) scope);
if (parent == null) {
return this;
}
return adaptBinding(parent);
} }
// the scope is from the ast // 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 abstract int getBindingType(IBinding binding);
public IBinding[] findInGlobalScope(char[] name) throws CoreException {
FindBindingsInBTree visitor= new FindBindingsInBTree(this, name);
getIndex().accept(visitor);
return visitor.getBinding();
}
} }

View file

@ -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.DOMException;
import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; 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.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -27,12 +29,12 @@ import org.eclipse.core.runtime.CoreException;
* @author Doug Schaefer * @author Doug Schaefer
*/ */
public class PDOMPointerType extends PDOMNode implements IPointerType, public class PDOMPointerType extends PDOMNode implements IPointerType,
ITypeContainer { ITypeContainer, IIndexType {
private static final int FLAGS = PDOMNode.RECORD_SIZE + 0; // byte private static final int FLAGS = PDOMNode.RECORD_SIZE + 0; // byte
private static final int TYPE = PDOMNode.RECORD_SIZE + 1; 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 CONST = 0x1;
private static final int VOLATILE = 0x2; private static final int VOLATILE = 0x2;
@ -81,7 +83,7 @@ public class PDOMPointerType extends PDOMNode implements IPointerType,
return pdom.getDB().getByte(record + FLAGS); return pdom.getDB().getByte(record + FLAGS);
} }
public IType getType() throws DOMException { public IType getType() {
try { try {
PDOMNode node = getLinkageImpl().getNode(pdom.getDB().getInt(record + TYPE)); PDOMNode node = getLinkageImpl().getNode(pdom.getDB().getInt(record + TYPE));
return node instanceof IType ? (IType)node : null; 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 { try {
return (getFlags() & CONST) != 0; return (getFlags() & CONST) != 0;
} catch (CoreException e) { } catch (CoreException e) {
@ -100,7 +102,7 @@ public class PDOMPointerType extends PDOMNode implements IPointerType,
} }
} }
public boolean isVolatile() throws DOMException { public boolean isVolatile() {
try { try {
return (getFlags() & VOLATILE) != 0; return (getFlags() & VOLATILE) != 0;
} catch (CoreException e) { } catch (CoreException e) {
@ -110,7 +112,23 @@ public class PDOMPointerType extends PDOMNode implements IPointerType,
} }
public boolean isSameType(IType type) { 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) { public void setType(IType type) {

View file

@ -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.DOMException;
import org.eclipse.cdt.core.dom.ast.IQualifierType; import org.eclipse.cdt.core.dom.ast.IQualifierType;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; 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.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -28,7 +30,7 @@ import org.eclipse.core.runtime.CoreException;
* *
*/ */
public class PDOMQualifierType extends PDOMNode implements IQualifierType, public class PDOMQualifierType extends PDOMNode implements IQualifierType,
ITypeContainer { ITypeContainer, IIndexType {
private static final int FLAGS = PDOMNode.RECORD_SIZE; private static final int FLAGS = PDOMNode.RECORD_SIZE;
private static final int TYPE = PDOMNode.RECORD_SIZE + 1; 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) { 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) { public void setType(IType type) {

View file

@ -8,6 +8,7 @@
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.c; 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.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.c.ICBasicType; import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
import org.eclipse.cdt.internal.core.Util; 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.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database; 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.PDOMNode;
@ -27,7 +30,7 @@ import org.eclipse.core.runtime.CoreException;
* @author Doug Schaefer * @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 TYPE_ID = PDOMNode.RECORD_SIZE + 0; // short
public static final int FLAGS = PDOMNode.RECORD_SIZE + 2; // short public static final int FLAGS = PDOMNode.RECORD_SIZE + 2; // short
@ -77,7 +80,7 @@ class PDOMCBasicType extends PDOMNode implements ICBasicType {
return PDOMCLinkage.CBASICTYPE; return PDOMCLinkage.CBASICTYPE;
} }
public int getType() throws DOMException { public int getType() {
try { try {
return pdom.getDB().getChar(record + TYPE_ID); return pdom.getDB().getChar(record + TYPE_ID);
} catch (CoreException e) { } catch (CoreException e) {
@ -101,9 +104,31 @@ class PDOMCBasicType extends PDOMNode implements ICBasicType {
public boolean isComplex() { return flagSet(IS_COMPLEX); } public boolean isComplex() { return flagSet(IS_COMPLEX); }
public boolean isSameType(IType type) { public boolean isSameType(IType rhs) {
// TODO something fancier if( rhs instanceof ITypedef )
return equals(type); 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() { public Object clone() {

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.c; 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.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.pdom.PDOM; 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.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
@ -26,7 +29,7 @@ import org.eclipse.core.runtime.CoreException;
/** /**
* @author Doug Schaefer * @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; 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) { 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() { public Object clone() {

View file

@ -248,4 +248,8 @@ class PDOMCLinkage extends PDOMLinkage {
public IBTreeComparator getIndexComparator() { public IBTreeComparator getIndexComparator() {
return new FindBinding.DefaultBindingBTreeComparator(getPDOM()); return new FindBinding.DefaultBindingBTreeComparator(getPDOM());
} }
public IBinding findInGlobalScope(String filePath, IASTName name) throws CoreException {
return null;
}
} }

View file

@ -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.IField;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope; import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
import org.eclipse.cdt.internal.core.Util; 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.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList; import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner;
@ -41,7 +43,7 @@ import org.eclipse.core.runtime.Status;
* @author Doug Schaefer * @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 MEMBERLIST = PDOMBinding.RECORD_SIZE;
private static final int KEY = MEMBERLIST + 4; // byte private static final int KEY = MEMBERLIST + 4; // byte
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 8; 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) { public boolean isSameType(IType type) {
if (equals(type)) if (type instanceof PDOMNode) {
return true; PDOMNode node= (PDOMNode) type;
else if (node.getPDOM() == getPDOM()) {
// TODO - see if it matches return node.getRecord() == getRecord();
return false; }
}
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() { protected int getRecordSize() {

View file

@ -18,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; 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.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
@ -26,7 +27,7 @@ import org.eclipse.core.runtime.CoreException;
/** /**
* @author Doug Schaefer * @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; 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) { public boolean isSameType(IType type) {
try { try {
if (type instanceof PDOMBinding)
return record == ((PDOMBinding)type).getRecord();
IType myrtype = getType(); IType myrtype = getType();
if (myrtype == null) if (myrtype == null)
return false; return false;
if (type instanceof ITypedef) { if (type instanceof ITypedef) {
IType rtype = ((ITypedef)type).getType(); type= ((ITypedef)type).getType();
return rtype != null ? myrtype.isSameType(rtype) : false;
} }
return myrtype.isSameType(type);
} catch (DOMException e) { } catch (DOMException e) {
CCorePlugin.log(e);
} }
return false; return false;
} }

View file

@ -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.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding; 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.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
@ -31,6 +32,9 @@ public class PDOMCPPAnnotation {
// byte of annotations. // byte of annotations.
public static final int VIRTUAL_OFFSET = 0; public static final int VIRTUAL_OFFSET = 0;
public static final int DESTRUCTOR_OFFSET = 1; 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 * Encodes storage class specifiers and other annotation, including
@ -69,6 +73,13 @@ public class PDOMCPPAnnotation {
ICPPMethod method = (ICPPMethod) binding; ICPPMethod method = (ICPPMethod) binding;
modifiers |= (method.isVirtual() ? 1 : 0) << VIRTUAL_OFFSET; modifiers |= (method.isVirtual() ? 1 : 0) << VIRTUAL_OFFSET;
modifiers |= (method.isDestructor() ? 1 : 0) << DESTRUCTOR_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; return modifiers;
} }

View file

@ -14,9 +14,12 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTExpression; 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.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.internal.core.Util; 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.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database; 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.PDOMNode;
@ -26,18 +29,13 @@ import org.eclipse.core.runtime.CoreException;
* @author Doug Schaefer * @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 TYPE_ID = PDOMNode.RECORD_SIZE + 0; // short
public static final int FLAGS = PDOMNode.RECORD_SIZE + 2; // 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 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) { public PDOMCPPBasicType(PDOM pdom, int record) {
super(pdom, record); super(pdom, record);
} }
@ -74,7 +72,7 @@ class PDOMCPPBasicType extends PDOMNode implements ICPPBasicType {
return PDOMCPPLinkage.CPPBASICTYPE; return PDOMCPPLinkage.CPPBASICTYPE;
} }
public int getType() throws DOMException { public int getType() {
try { try {
return pdom.getDB().getChar(record + TYPE_ID); return pdom.getDB().getChar(record + TYPE_ID);
} catch (CoreException e) { } catch (CoreException e) {
@ -129,9 +127,28 @@ class PDOMCPPBasicType extends PDOMNode implements ICPPBasicType {
} }
} }
public boolean isSameType(IType type) { public boolean isSameType(IType rhs) {
// TODO something fancier if( rhs instanceof ITypedef )
return equals(type); 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() { public Object clone() {
@ -141,5 +158,13 @@ class PDOMCPPBasicType extends PDOMNode implements ICPPBasicType {
return null; return null;
} }
} }
public int getQualifierBits() {
try {
return getFlags();
} catch (CoreException e) {
CCorePlugin.log(e);
return 0;
}
}
} }

View file

@ -7,13 +7,11 @@
* *
* Contributors: * Contributors:
* Symbian - Initial API and implementation * Symbian - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp; package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; 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 { public PDOMCPPBinding(PDOM pdom, PDOMNode parent, char[] name) throws CoreException {
super(pdom, parent, name); super(pdom, parent, name);
} }
// TODO: performance? protected boolean hasQualifiedName(char[][] qname, int idx) {
final public String[] getQualifiedName() throws DOMException {
List result = new ArrayList();
try { try {
PDOMNode node = this; if (getDBName().equals(qname[idx])) {
while (node != null) { PDOMNode parent= getParentNode();
if (node instanceof PDOMBinding) { if (--idx < 0) {
result.add(0, ((PDOMBinding)node).getName()); 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 e) {
} catch(CoreException ce) { CCorePlugin.log(e);
CCorePlugin.log(ce);
return null;
} }
return false;
} }
// TODO: performance? // TODO: performance?

View file

@ -23,34 +23,28 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMNode; import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException; 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.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.IBinding;
import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; 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.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; 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.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.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList; 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.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.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.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/** /**
@ -61,7 +55,7 @@ import org.eclipse.core.runtime.CoreException;
* aftodo - contract get Methods/Fields not honoured? * aftodo - contract get Methods/Fields not honoured?
*/ */
class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
ICPPClassScope, IPDOMMemberOwner { ICPPClassScope, IPDOMMemberOwner, IIndexType {
private static final int FIRSTBASE = PDOMCPPBinding.RECORD_SIZE + 0; private static final int FIRSTBASE = PDOMCPPBinding.RECORD_SIZE + 0;
private static final int KEY = PDOMCPPBinding.RECORD_SIZE + 4; // byte 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; protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE + 12;
public PDOMCPPClassType(PDOM pdom, PDOMNode parent, ICPPClassType classType) public PDOMCPPClassType(PDOM pdom, PDOMNode parent, ICPPClassType classType)
throws CoreException { throws CoreException {
super(pdom, parent, classType.getName().toCharArray()); super(pdom, parent, classType.getName().toCharArray());
try { try {
@ -115,23 +109,29 @@ ICPPClassScope, IPDOMMemberOwner {
} }
public boolean isSameType(IType type) { public boolean isSameType(IType type) {
if (type instanceof PDOMBinding) { if (type instanceof PDOMNode) {
return record == ((PDOMBinding)type).getRecord(); PDOMNode node= (PDOMNode) type;
} else if (type instanceof ICPPClassType) { if (node.getPDOM() == getPDOM()) {
try { return node.getRecord() == getRecord();
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;
} }
} 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 { public ICPPBase[] getBases() throws DOMException {
@ -154,17 +154,24 @@ ICPPClassScope, IPDOMMemberOwner {
list.accept(visitor); list.accept(visitor);
} }
private static class GetMethods implements IPDOMVisitor { private static class MethodCollector implements IPDOMVisitor {
private final List methods; private final List methods;
public GetMethods(List methods) { private final boolean acceptImplicit;
this.methods = methods; private final boolean acceptAll;
public MethodCollector(List methods, boolean acceptImplicit) {
this(methods, acceptImplicit, true);
} }
public GetMethods() { public MethodCollector(List methods, boolean acceptImplicit, boolean acceptExplicit) {
this.methods = new ArrayList(); this.methods = methods == null ? new ArrayList() : methods;
this.acceptImplicit= acceptImplicit;
this.acceptAll= acceptImplicit && acceptExplicit;
} }
public boolean visit(IPDOMNode node) throws CoreException { public boolean visit(IPDOMNode node) throws CoreException {
if (node instanceof ICPPMethod) if (node instanceof ICPPMethod) {
methods.add(node); if (acceptAll || ((ICPPMethod) node).isImplicit() == acceptImplicit) {
methods.add(node);
}
}
return false; // don't visit the method return false; // don't visit the method
} }
public void leave(IPDOMNode node) throws CoreException { public void leave(IPDOMNode node) throws CoreException {
@ -176,7 +183,27 @@ ICPPClassScope, IPDOMMemberOwner {
public ICPPMethod[] getDeclaredMethods() throws DOMException { public ICPPMethod[] getDeclaredMethods() throws DOMException {
try { 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); accept(methods);
return methods.getMethods(); return methods.getMethods();
} catch (CoreException e) { } catch (CoreException e) {
@ -190,7 +217,7 @@ ICPPClassScope, IPDOMMemberOwner {
visited.add(this); visited.add(this);
// Get my members // Get my members
GetMethods myMethods = new GetMethods(methods); MethodCollector myMethods = new MethodCollector(methods, false, true);
accept(myMethods); accept(myMethods);
// Visit my base classes // Visit my base classes
@ -216,13 +243,8 @@ ICPPClassScope, IPDOMMemberOwner {
return new ICPPMethod[0]; return new ICPPMethod[0];
} }
} }
public ICPPMethod[] getMethods() throws DOMException { private static class FieldCollector implements IPDOMVisitor {
// TODO Should really include implicit methods too
return getDeclaredMethods();
}
private static class GetFields implements IPDOMVisitor {
private List fields = new ArrayList(); private List fields = new ArrayList();
public boolean visit(IPDOMNode node) throws CoreException { public boolean visit(IPDOMNode node) throws CoreException {
if (node instanceof IField) if (node instanceof IField)
@ -238,7 +260,7 @@ ICPPClassScope, IPDOMMemberOwner {
public IField[] getFields() throws DOMException { public IField[] getFields() throws DOMException {
try { try {
GetFields visitor = new GetFields(); FieldCollector visitor = new FieldCollector();
accept(visitor); accept(visitor);
return visitor.getFields(); return visitor.getFields();
} catch (CoreException e) { } catch (CoreException e) {
@ -247,9 +269,7 @@ ICPPClassScope, IPDOMMemberOwner {
} }
} }
private static class NestedClassCollector implements IPDOMVisitor {
private static class GetNestedClasses implements IPDOMVisitor {
private List nestedClasses = new ArrayList(); private List nestedClasses = new ArrayList();
public boolean visit(IPDOMNode node) throws CoreException { public boolean visit(IPDOMNode node) throws CoreException {
if (node instanceof ICPPClassType) if (node instanceof ICPPClassType)
@ -265,7 +285,7 @@ ICPPClassScope, IPDOMMemberOwner {
public ICPPClassType[] getNestedClasses() throws DOMException { public ICPPClassType[] getNestedClasses() throws DOMException {
try { try {
GetNestedClasses visitor = new GetNestedClasses(); NestedClassCollector visitor = new NestedClassCollector();
accept(visitor); accept(visitor);
return visitor.getNestedClasses(); return visitor.getNestedClasses();
} catch (CoreException e) { } catch (CoreException e) {
@ -303,114 +323,75 @@ ICPPClassScope, IPDOMMemberOwner {
addMember(member); addMember(member);
} }
public ICPPConstructor[] getConstructors() throws DOMException { private static class ConstructorCollector implements IPDOMVisitor {
// TODO private List fConstructors = new ArrayList();
return new ICPPConstructor[0]; 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 ICPPConstructor[] getConstructors() throws DOMException {
ConstructorCollector visitor= new ConstructorCollector();
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
IASTNode parent = name.getParent();
try { try {
if (name instanceof ICPPASTQualifiedName) { accept(visitor);
IASTName lastName = ((ICPPASTQualifiedName)name).getLastName(); } catch (CoreException e) {
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) {
CCorePlugin.log(e); CCorePlugin.log(e);
} }
return visitor.getConstructors();
return null;
} }
private PDOMBinding searchCurrentScopeForFunction(IASTFunctionCallExpression fce, IASTName name) throws CoreException {
try { public boolean isFullyCached() {
IType[] types = PDOMCPPLinkage.getTypes(fce.getParameterExpression()); return true;
if(types!=null) { }
return CPPFindBinding.findBinding(this, getPDOM(), name.toCharArray(), PDOMCPPLinkage.CPPFUNCTION, types);
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) { return false;
CCorePlugin.log(de); }
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; return null;
} }
private IBinding searchCurrentScope(char[] name, int[] constants) throws CoreException {
IBinding result = null;
for(int i=0; result==null && i<constants.length; i++)
result = searchCurrentScope(name, constants[i]);
return result;
}
private IBinding searchCurrentScope(char[] name, int constant) throws CoreException {
return FindBinding.findBinding(this, getPDOM(), name, new int [] {constant});
}
// Not implemented // Not implemented
public Object clone() {fail();return null;} public Object clone() {fail();return null;}
public IField findField(String name) throws DOMException {fail();return null;} public IField findField(String name) throws DOMException {fail();return null;}
public IBinding[] getFriends() throws DOMException {fail();return null;} public IBinding[] getFriends() throws DOMException {fail();return null;}
public ICPPMethod[] getImplicitMethods() {fail(); return null;}
public IBinding[] find(String name) throws DOMException {fail();return null;} public IBinding[] find(String name) throws DOMException {fail();return null;}
public ICPPField[] getDeclaredFields() throws DOMException {fail();return null;} public ICPPField[] getDeclaredFields() throws DOMException {fail();return null;}

View file

@ -0,0 +1,37 @@
/*******************************************************************************
* 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.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
public class PDOMCPPConstructor extends PDOMCPPMethod implements ICPPConstructor {
public PDOMCPPConstructor(PDOM pdom, PDOMNode parent, ICPPConstructor method) throws CoreException {
super(pdom, parent, method);
}
public PDOMCPPConstructor(PDOM pdom, int record) {
super(pdom, record);
}
public boolean isExplicit() throws DOMException {
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.EXPLICIT_CONSTRUCTOR_OFFSET);
}
public int getNodeType() {
return PDOMCPPLinkage.CPP_CONSTRUCTOR;
}
}

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp; package org.eclipse.cdt.internal.core.pdom.dom.cpp;
@ -17,8 +18,9 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.internal.core.index.IIndexProxyBinding; import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.pdom.PDOM; 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.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
@ -28,7 +30,7 @@ import org.eclipse.core.runtime.CoreException;
/** /**
* @author Doug Schaefer * @author Doug Schaefer
*/ */
class PDOMCPPEnumeration extends PDOMCPPBinding implements IEnumeration, ICPPBinding { class PDOMCPPEnumeration extends PDOMCPPBinding implements IEnumeration, IIndexType, ICPPBinding {
private static final int FIRST_ENUMERATOR = PDOMBinding.RECORD_SIZE + 0; private static final int FIRST_ENUMERATOR = PDOMBinding.RECORD_SIZE + 0;
@ -89,23 +91,34 @@ class PDOMCPPEnumeration extends PDOMCPPBinding implements IEnumeration, ICPPBin
} }
public boolean isSameType(IType type) { public boolean isSameType(IType type) {
if (type instanceof PDOMBinding) if (type instanceof PDOMNode) {
return record == ((PDOMBinding)type).getRecord(); PDOMNode node= (PDOMNode) type;
else if (type instanceof IEnumeration) { if (node.getPDOM() == getPDOM()) {
try { return node.getRecord() == getRecord();
IIndexProxyBinding pdomType = pdom.adaptBinding((IEnumeration)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;
} }
} else }
return false;
if (type instanceof ITypedef) {
return type.isSameType(this);
}
try {
if (type instanceof IEnumeration) {
if (type instanceof ICPPBinding) {
ICPPBinding etype= (ICPPBinding) type;
char[][] qname = etype.getQualifiedNameCharArray();
return hasQualifiedName(qname, qname.length-1);
}
else if (type instanceof PDOMCPPEnumeration) {
PDOMCPPEnumeration etype= (PDOMCPPEnumeration) type;
char[][] qname= etype.getQualifiedNameCharArray();
return hasQualifiedName(qname, qname.length-1);
}
}
} catch (DOMException e) {
CCorePlugin.log(e);
}
return false;
} }
public Object clone() { public Object clone() {

View file

@ -8,6 +8,7 @@
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* IBM Corporation * IBM Corporation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp; package org.eclipse.cdt.internal.core.pdom.dom.cpp;
@ -21,9 +22,11 @@ import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.internal.core.Util; 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.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
@ -36,7 +39,7 @@ import org.eclipse.core.runtime.CoreException;
* @author Doug Schaefer * @author Doug Schaefer
* *
*/ */
class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, ICPPFunctionType { class PDOMCPPFunction extends PDOMCPPBinding implements IIndexType, ICPPFunction, ICPPFunctionType {
/** /**
* Offset of total number of function parameters (relative to the * Offset of total number of function parameters (relative to the
@ -49,22 +52,28 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, ICPPFuncti
* the beginning of the record). * the beginning of the record).
*/ */
private static final int FIRST_PARAM = PDOMBinding.RECORD_SIZE + 4; private static final int FIRST_PARAM = PDOMBinding.RECORD_SIZE + 4;
/** /**
* Offset of hash of parameter information to allow fast comparison * Offset of hash of parameter information to allow fast comparison
*/ */
private static final int SIGNATURE_MEMENTO = PDOMBinding.RECORD_SIZE + 8; private static final int SIGNATURE_MEMENTO = PDOMBinding.RECORD_SIZE + 8;
/**
* Offset for return type of this function (relative to
* the beginning of the record).
*/
private static final int RETURN_TYPE = PDOMBinding.RECORD_SIZE + 12;
/** /**
* Offset of annotation information (relative to the beginning of the * Offset of annotation information (relative to the beginning of the
* record). * record).
*/ */
protected static final int ANNOTATION = PDOMBinding.RECORD_SIZE + 12; // byte protected static final int ANNOTATION = PDOMBinding.RECORD_SIZE + 16; // byte
/** /**
* The size in bytes of a PDOMCPPFunction record in the database. * The size in bytes of a PDOMCPPFunction record in the database.
*/ */
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 13; protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 17;
public PDOMCPPFunction(PDOM pdom, PDOMNode parent, ICPPFunction function) throws CoreException { public PDOMCPPFunction(PDOM pdom, PDOMNode parent, ICPPFunction function) throws CoreException {
super(pdom, parent, function.getNameCharArray()); super(pdom, parent, function.getNameCharArray());
@ -72,6 +81,14 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, ICPPFuncti
Database db = pdom.getDB(); Database db = pdom.getDB();
IBinding binding = function; IBinding binding = function;
try { try {
IType rt= function.getType().getReturnType();
if (rt != null) {
PDOMNode typeNode = getLinkageImpl().addType(this, rt);
if (typeNode != null) {
db.putInt(record + RETURN_TYPE, typeNode.getRecord());
}
}
IParameter[] params = function.getParameters(); IParameter[] params = function.getParameters();
db.putInt(record + NUM_PARAMS, params.length); db.putInt(record + NUM_PARAMS, params.length);
@ -189,8 +206,15 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, ICPPFuncti
} }
public IType getReturnType() throws DOMException { public IType getReturnType() throws DOMException {
try {
PDOMNode node = getLinkageImpl().getNode(pdom.getDB().getInt(record + RETURN_TYPE));
if (node instanceof IType) {
return (IType) node;
}
} catch (CoreException e) {
CCorePlugin.log(e);
}
return null; return null;
// TODO throw new PDOMNotImplementedError();
} }
public boolean isConst() { public boolean isConst() {
@ -205,13 +229,48 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, ICPPFuncti
return false; return false;
} }
public boolean isSameType(IType type) { public boolean isSameType(IType type) {
if (type instanceof PDOMCPPFunction) { if (type instanceof ITypedef) {
return record == ((PDOMCPPFunction)type).getRecord(); return type.isSameType(this);
} else {
// TODO check the other type for matching name, params
return false;
} }
try {
if (type instanceof ICPPFunctionType) {
ICPPFunctionType ft = (ICPPFunctionType) type;
IType rt1= getReturnType();
IType rt2= ft.getReturnType();
if (rt1 != rt2) {
if (rt1 == null || !rt1.isSameType(rt2)) {
return false;
}
}
IType[] params1= getParameterTypes();
IType[] params2= ft.getParameterTypes();
if( params1.length == 1 && params2.length == 0 ){
if( !(params1[0] instanceof IBasicType) || ((IBasicType)params1[0]).getType() != IBasicType.t_void )
return false;
} else if( params2.length == 1 && params1.length == 0 ){
if( !(params2[0] instanceof IBasicType) || ((IBasicType)params2[0]).getType() != IBasicType.t_void )
return false;
} else if( params1.length != params2.length ){
return false;
} else {
for( int i = 0; i < params1.length; i++ ){
if (params1[i] == null || ! params1[i].isSameType( params2[i] ) )
return false;
}
}
if( isConst() != ft.isConst() || isVolatile() != ft.isVolatile() )
return false;
return true;
}
return false;
} catch (DOMException e) {
}
return false;
} }
public Object clone() { public Object clone() {
@ -223,10 +282,9 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, ICPPFuncti
if(types[0] instanceof IBasicType) { if(types[0] instanceof IBasicType) {
if(((IBasicType)types[0]).getType()==IBasicType.t_void) { if(((IBasicType)types[0]).getType()==IBasicType.t_void) {
types = new IType[0]; types = new IType[0];
} }
} }
} }
StringBuffer result = new StringBuffer(); StringBuffer result = new StringBuffer();
result.append('('); result.append('(');
for(int i=0; i<types.length; i++) { for(int i=0; i<types.length; i++) {

View file

@ -18,18 +18,13 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTName; 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.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
@ -37,38 +32,34 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
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.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.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage; import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBlockScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBlockScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitMethod;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator; import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
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.IPDOMMemberOwner;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; 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.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/** /**
@ -109,6 +100,9 @@ public class PDOMCPPLinkage extends PDOMLinkage {
public static final int CPPENUMERATION = PDOMLinkage.LAST_NODE_TYPE + 10; public static final int CPPENUMERATION = PDOMLinkage.LAST_NODE_TYPE + 10;
public static final int CPPENUMERATOR = PDOMLinkage.LAST_NODE_TYPE + 11; public static final int CPPENUMERATOR = PDOMLinkage.LAST_NODE_TYPE + 11;
public static final int CPPTYPEDEF = PDOMLinkage.LAST_NODE_TYPE + 12; public static final int CPPTYPEDEF = PDOMLinkage.LAST_NODE_TYPE + 12;
public static final int CPP_POINTER_TO_MEMBER_TYPE= PDOMLinkage.LAST_NODE_TYPE + 13;
public static final int CPP_CONSTRUCTOR= PDOMLinkage.LAST_NODE_TYPE + 14;
public static final int CPP_REFERENCE_TYPE= PDOMLinkage.LAST_NODE_TYPE + 15;
public ILanguage getLanguage() { public ILanguage getLanguage() {
return new GPPLanguage(); return new GPPLanguage();
@ -140,74 +134,96 @@ public class PDOMCPPLinkage extends PDOMLinkage {
PDOMNode parent = getAdaptedParent(binding); PDOMNode parent = getAdaptedParent(binding);
if (parent == null) if (parent == null)
return null; return null;
pdomBinding = addBinding(parent, binding);
if (binding instanceof ICPPField && parent instanceof PDOMCPPClassType)
pdomBinding = new PDOMCPPField(pdom, (PDOMCPPClassType)parent, (ICPPField) binding);
else if (binding instanceof ICPPVariable && !(binding.getScope() instanceof CPPBlockScope)) {
if (!(binding.getScope() instanceof CPPBlockScope)) {
ICPPVariable var= (ICPPVariable) binding;
if (!var.isStatic()) { // bug 161216
pdomBinding = new PDOMCPPVariable(pdom, parent, var);
}
}
} else if (parent instanceof PDOMCPPClassType && binding instanceof ICPPMethod) {
pdomBinding = new PDOMCPPMethod(pdom, parent, (ICPPMethod)binding);
} else if (binding instanceof CPPImplicitMethod && parent instanceof PDOMCPPClassType) {
if(!name.isReference()) {
//because we got the implicit method off of an IASTName that is not a reference,
//it is no longer completly implicit and it should be treated as a normal method.
pdomBinding = new PDOMCPPMethod(pdom, parent, (ICPPMethod)binding);
}
} else if (binding instanceof ICPPFunction) {
ICPPFunction func= (ICPPFunction) binding;
if (!func.isStatic()) { // bug 161216
pdomBinding = new PDOMCPPFunction(pdom, parent, func);
}
} else if (binding instanceof ICPPClassType) {
pdomBinding = new PDOMCPPClassType(pdom, parent, (ICPPClassType) binding);
} else if (binding instanceof ICPPNamespaceAlias) {
pdomBinding = new PDOMCPPNamespaceAlias(pdom, parent, (ICPPNamespaceAlias) binding);
} else if (binding instanceof ICPPNamespace) {
pdomBinding = new PDOMCPPNamespace(pdom, parent, (ICPPNamespace) binding);
} else if (binding instanceof IEnumeration) {
pdomBinding = new PDOMCPPEnumeration(pdom, parent, (IEnumeration) binding);
} else if (binding instanceof IEnumerator) {
IEnumeration enumeration = (IEnumeration)((IEnumerator)binding).getType();
PDOMBinding pdomEnumeration = adaptBinding(enumeration);
if (pdomEnumeration instanceof PDOMCPPEnumeration)
pdomBinding = new PDOMCPPEnumerator(pdom, parent, (IEnumerator) binding,
(PDOMCPPEnumeration)pdomEnumeration);
} else if (binding instanceof ITypedef) {
pdomBinding = new PDOMCPPTypedef(pdom, parent, name, (ITypedef)binding);
}
if(pdomBinding!=null) {
parent.addChild(pdomBinding);
}
} }
} catch(DOMException e) { } catch(DOMException e) {
throw new CoreException(Util.createStatus(e)); throw new CoreException(Util.createStatus(e));
} }
// final processing if (pdomBinding instanceof PDOMCPPClassType) {
if (pdomBinding != null) { PDOMCPPClassType pdomClassType= (PDOMCPPClassType) pdomBinding;
// Check if is a base specifier IASTNode baseNode= name.getParent();
if (pdomBinding instanceof ICPPClassType && name.getParent() instanceof ICPPASTBaseSpecifier) { if (baseNode instanceof ICPPASTBaseSpecifier)
ICPPASTBaseSpecifier baseNode = (ICPPASTBaseSpecifier)name.getParent(); addBaseClasses(pdomClassType, (ICPPASTBaseSpecifier) baseNode);
ICPPASTCompositeTypeSpecifier ownerNode = (ICPPASTCompositeTypeSpecifier)baseNode.getParent();
IBinding ownerBinding = adaptBinding(ownerNode.getName().resolveBinding()); if (binding instanceof ICPPClassType && name.isDefinition()) {
if (ownerBinding != null && ownerBinding instanceof PDOMCPPClassType) { addImplicitMethods(pdomClassType, (ICPPClassType) binding);
PDOMCPPClassType ownerClass = (PDOMCPPClassType)ownerBinding;
PDOMCPPBase pdomBase = new PDOMCPPBase(pdom, (PDOMCPPClassType)pdomBinding,
baseNode.isVirtual(), baseNode.getVisibility());
ownerClass.addBase(pdomBase);
}
} }
} }
return pdomBinding; return pdomBinding;
} }
private void addBaseClasses(PDOMCPPClassType pdomBinding, ICPPASTBaseSpecifier baseNode) throws CoreException {
ICPPASTCompositeTypeSpecifier ownerNode = (ICPPASTCompositeTypeSpecifier)baseNode.getParent();
IBinding ownerBinding = adaptBinding(ownerNode.getName().resolveBinding());
if (ownerBinding != null && ownerBinding instanceof PDOMCPPClassType) {
PDOMCPPClassType ownerClass = (PDOMCPPClassType)ownerBinding;
PDOMCPPBase pdomBase = new PDOMCPPBase(pdom, pdomBinding,
baseNode.isVirtual(), baseNode.getVisibility());
ownerClass.addBase(pdomBase);
}
}
private PDOMBinding addBinding(PDOMNode parent, IBinding binding) throws CoreException, DOMException {
PDOMBinding pdomBinding= null;
if (binding instanceof ICPPField && parent instanceof PDOMCPPClassType)
pdomBinding = new PDOMCPPField(pdom, (PDOMCPPClassType)parent, (ICPPField) binding);
else if (binding instanceof ICPPVariable && !(binding.getScope() instanceof CPPBlockScope)) {
if (!(binding.getScope() instanceof CPPBlockScope)) {
ICPPVariable var= (ICPPVariable) binding;
if (!var.isStatic()) { // bug 161216
pdomBinding = new PDOMCPPVariable(pdom, parent, var);
}
}
} else if (binding instanceof ICPPConstructor && parent instanceof PDOMCPPClassType) {
pdomBinding = new PDOMCPPConstructor(pdom, parent, (ICPPConstructor)binding);
} else if (binding instanceof ICPPMethod && parent instanceof PDOMCPPClassType) {
pdomBinding = new PDOMCPPMethod(pdom, parent, (ICPPMethod)binding);
} else if (binding instanceof ICPPFunction) {
ICPPFunction func= (ICPPFunction) binding;
if (!func.isStatic()) { // bug 161216
pdomBinding = new PDOMCPPFunction(pdom, parent, func);
}
} else if (binding instanceof ICPPClassType) {
pdomBinding= new PDOMCPPClassType(pdom, parent, (ICPPClassType) binding);
} else if (binding instanceof ICPPNamespaceAlias) {
pdomBinding = new PDOMCPPNamespaceAlias(pdom, parent, (ICPPNamespaceAlias) binding);
} else if (binding instanceof ICPPNamespace) {
pdomBinding = new PDOMCPPNamespace(pdom, parent, (ICPPNamespace) binding);
} else if (binding instanceof IEnumeration) {
pdomBinding = new PDOMCPPEnumeration(pdom, parent, (IEnumeration) binding);
} else if (binding instanceof IEnumerator) {
IEnumeration enumeration = (IEnumeration)((IEnumerator)binding).getType();
PDOMBinding pdomEnumeration = adaptBinding(enumeration);
if (pdomEnumeration instanceof PDOMCPPEnumeration)
pdomBinding = new PDOMCPPEnumerator(pdom, parent, (IEnumerator) binding,
(PDOMCPPEnumeration)pdomEnumeration);
} else if (binding instanceof ITypedef) {
pdomBinding = new PDOMCPPTypedef(pdom, parent, (ITypedef)binding);
}
if(pdomBinding!=null) {
parent.addChild(pdomBinding);
}
return pdomBinding;
}
private void addImplicitMethods(PDOMCPPClassType type, ICPPClassType binding) throws CoreException {
try {
IScope scope = binding.getCompositeScope();
if (scope instanceof ICPPClassScope) {
ICPPMethod[] implicit= ((ICPPClassScope) scope).getImplicitMethods();
for (int i = 0; i < implicit.length; i++) {
ICPPMethod method = implicit[i];
addBinding(type, method);
}
}
} catch (DOMException e) {
CCorePlugin.log(e);
}
}
public int getBindingType(IBinding binding) { public int getBindingType(IBinding binding) {
if (binding instanceof ICPPTemplateDefinition) if (binding instanceof ICPPTemplateDefinition)
// this must be before class type // this must be before class type
@ -217,6 +233,9 @@ public class PDOMCPPLinkage extends PDOMLinkage {
return CPPFIELD; return CPPFIELD;
else if (binding instanceof ICPPVariable) else if (binding instanceof ICPPVariable)
return CPPVARIABLE; return CPPVARIABLE;
else if (binding instanceof ICPPConstructor)
// before methods
return CPP_CONSTRUCTOR;
else if (binding instanceof ICPPMethod) else if (binding instanceof ICPPMethod)
// this must be before functions // this must be before functions
return CPPMETHOD; return CPPMETHOD;
@ -268,134 +287,13 @@ public class PDOMCPPLinkage extends PDOMLinkage {
} }
public PDOMBinding resolveBinding(IASTName name) throws CoreException { public PDOMBinding resolveBinding(IASTName name) throws CoreException {
try { IBinding binding= name.resolveBinding();
return _resolveBinding(name); if (binding != null) {
} catch(DOMException e) { return adaptBinding(binding);
throw new CoreException(Util.createStatus(e));
} }
}
private PDOMBinding _resolveBinding(IASTName name) throws CoreException, DOMException {
IBinding origBinding = name.getBinding();
if (origBinding != null)
return adaptBinding(origBinding);
if (name instanceof ICPPASTQualifiedName) {
IASTName[] names = ((ICPPASTQualifiedName)name).getNames();
if (names.length == 1)
return resolveBinding(names[0]);
IASTName lastName = names[names.length - 1];
PDOMBinding nsBinding = adaptBinding(names[names.length - 2].resolveBinding());
// aftodo - namespace aliases?
if (nsBinding instanceof IScope) {
return (PDOMBinding) ((IScope)nsBinding).getBinding(lastName, true);
}
}
IASTNode parent = name.getParent();
if (parent instanceof ICPPASTQualifiedName) {
ICPPASTQualifiedName qualName = (ICPPASTQualifiedName)parent;
IASTName lastName = qualName.getLastName();
if (name != lastName) {
return resolveInQualifiedName(name);
} else {
// Drop down to the rest of the resolution procedure
// with the parent of the qualified name
parent = parent.getParent();
}
}
if (parent instanceof IASTIdExpression) {
// reference
IASTNode eParent = parent.getParent();
if (eParent instanceof IASTFunctionCallExpression) {
if (parent.getPropertyInParent().equals(IASTFunctionCallExpression.FUNCTION_NAME)) {
return resolveFunctionCall(
(IASTFunctionCallExpression) eParent,
(IASTIdExpression) parent, name);
} else if (parent.getPropertyInParent().equals(IASTFunctionCallExpression.PARAMETERS)) {
int desiredType = (name.getParent() instanceof ICPPASTQualifiedName
&& ((ICPPASTQualifiedName) name.getParent()).getLastName() != name)
? CPPNAMESPACE : CPPVARIABLE;
return searchCurrentScope(name.toCharArray(), desiredType);
}
} else {
// if the address of me is taken, and assigned to something,
// find out the type of the thing I'm assigned to
if (eParent instanceof IASTUnaryExpression) {
IASTUnaryExpression unaryExp = (IASTUnaryExpression) eParent;
if (unaryExp.getOperator() == IASTUnaryExpression.op_amper) {
IASTNode epParent = eParent.getParent();
if (epParent instanceof IASTBinaryExpression) {
if (((IASTBinaryExpression) epParent).getOperator() == IASTBinaryExpression.op_assign) {
IASTExpression left = ((IASTBinaryExpression) epParent).getOperand1();
IType type = CPPSemantics.getUltimateType(left.getExpressionType(), false);
if (type instanceof IFunctionType) {
return CPPFindBinding.findBinding(getIndex(),
getPDOM(),
name.toCharArray(),
CPPFUNCTION,
((IFunctionType) type).getParameterTypes()
);
}
}
}
}
}
return searchCurrentScope(name.toCharArray(), new int[]{
CPPVARIABLE,
CPPENUMERATOR
});
}
} else if (parent instanceof IASTNamedTypeSpecifier) {
return searchCurrentScope(name.toCharArray(), new int[] {
CPPCLASSTYPE,
CPPENUMERATION,
CPPTYPEDEF
});
} else if (parent instanceof ICPPASTNamespaceAlias) {
return searchCurrentScope(name.toCharArray(), CPPNAMESPACE);
} else if(parent instanceof ICPPASTFieldReference) {
ICPPASTFieldReference ref = (ICPPASTFieldReference) parent;
IASTExpression exp = ref.getFieldOwner();
if(exp instanceof IASTIdExpression) {
IASTIdExpression fieldOwner = (IASTIdExpression) exp;
IASTNode eParent = parent.getParent();
if (eParent instanceof IASTFunctionCallExpression &&
parent.getPropertyInParent().equals(IASTFunctionCallExpression.FUNCTION_NAME)) {
if(name.getPropertyInParent().equals(IASTFieldReference.FIELD_NAME)) {
return resolveFunctionCall((IASTFunctionCallExpression) eParent, fieldOwner, name);
}
} else {
IBinding fieldOwnerBinding = fieldOwner.getName().getBinding();
if(fieldOwnerBinding instanceof ICPPVariable) {
IType type = ((ICPPVariable)fieldOwnerBinding).getType();
if(type instanceof ICompositeType) {
PDOMBinding pdomFOB = adaptBinding( (ICompositeType) type);
return FindBinding.findBinding(pdomFOB, getPDOM(), name.toCharArray(), new int [] {PDOMCPPLinkage.CPPFIELD});
}
}
}
}
} else if(parent instanceof ICPPASTBaseSpecifier) {
return searchCurrentScope(name.toCharArray(), PDOMCPPLinkage.CPPCLASSTYPE);
}
return null; return null;
} }
private PDOMBinding searchCurrentScope(char[] name, int[] constants) throws CoreException {
PDOMBinding result = null;
for(int i=0; result==null && i<constants.length; i++)
result = searchCurrentScope(name, constants[i]);
return result;
}
private PDOMBinding searchCurrentScope(char[] name, int constant) throws CoreException {
return FindBinding.findBinding(getIndex(), getPDOM(), name, new int [] {constant});
}
/** /**
* Read type information from the AST or null if the types could not be determined * Read type information from the AST or null if the types could not be determined
* @param paramExp the parameter expression to get types for (null indicates void function/method) * @param paramExp the parameter expression to get types for (null indicates void function/method)
@ -498,43 +396,6 @@ public class PDOMCPPLinkage extends PDOMLinkage {
return null; return null;
} }
private PDOMBinding resolveInQualifiedName(IASTName name) throws CoreException {
ICPPASTQualifiedName qualName = (ICPPASTQualifiedName)name.getParent();
// Must be a namespace or a class
IASTName[] names = qualName.getNames();
int index = ArrayUtil.indexOf(names, name);
if(index!=-1) {
if (index == 0) {
// we are at the root
return FindBinding.findBinding(getIndex(), getPDOM(), name.toCharArray(), new int[]{
CPPNAMESPACE, CPPCLASSTYPE, CPPNAMESPACEALIAS
});
} else {
try {
PDOMBinding binding = adaptBinding(names[index-1].getBinding());
if(binding instanceof PDOMCPPClassType) {
// TODO - a test case for this..
return (PDOMBinding) ((PDOMCPPClassType)binding).getBinding(name, true);
} else if(binding instanceof PDOMCPPNamespaceAlias) {
PDOMCPPNamespace pns = (PDOMCPPNamespace) ((PDOMCPPNamespaceAlias) binding).getBinding();
return (PDOMBinding) ((ICPPNamespaceScope) pns).getBinding(name, true);
} else if(binding instanceof PDOMCPPNamespace) {
return (PDOMBinding) ((ICPPNamespaceScope)binding).getBinding(name, true);
} else {
throw new PDOMNotImplementedError(); // aftodo - again I think we can't get here
}
} catch(DOMException de) {
throw new CoreException(CCorePlugin.createStatus(de.getMessage())); // aftodo
}
}
} else {
// aftodo - I don't believe this can happen..
// didn't find our name here, weird...
return null;
}
}
public PDOMNode addType(PDOMNode parent, IType type) throws CoreException { public PDOMNode addType(PDOMNode parent, IType type) throws CoreException {
if (type instanceof ICPPBasicType) { if (type instanceof ICPPBasicType) {
return new PDOMCPPBasicType(pdom, parent, (ICPPBasicType)type); return new PDOMCPPBasicType(pdom, parent, (ICPPBasicType)type);
@ -550,7 +411,10 @@ public class PDOMCPPLinkage extends PDOMLinkage {
if (binding != null) { if (binding != null) {
return binding; return binding;
} }
} else if (type instanceof ICPPPointerToMemberType) {
return new PDOMCPPPointerToMemberType(pdom, parent, (ICPPPointerToMemberType)type);
} }
return super.addType(parent, type); return super.addType(parent, type);
} }
@ -567,6 +431,8 @@ public class PDOMCPPLinkage extends PDOMLinkage {
return new PDOMCPPClassType(pdom, record); return new PDOMCPPClassType(pdom, record);
case CPPFIELD: case CPPFIELD:
return new PDOMCPPField(pdom, record); return new PDOMCPPField(pdom, record);
case CPP_CONSTRUCTOR:
return new PDOMCPPConstructor(pdom, record);
case CPPMETHOD: case CPPMETHOD:
return new PDOMCPPMethod(pdom, record); return new PDOMCPPMethod(pdom, record);
case CPPNAMESPACE: case CPPNAMESPACE:
@ -581,6 +447,11 @@ public class PDOMCPPLinkage extends PDOMLinkage {
return new PDOMCPPEnumerator(pdom, record); return new PDOMCPPEnumerator(pdom, record);
case CPPTYPEDEF: case CPPTYPEDEF:
return new PDOMCPPTypedef(pdom, record); return new PDOMCPPTypedef(pdom, record);
case CPP_POINTER_TO_MEMBER_TYPE:
return new PDOMCPPPointerToMemberType(pdom, record);
case CPP_REFERENCE_TYPE:
return new PDOMCPPReferenceType(pdom, record);
default: default:
return super.getNode(record); return super.getNode(record);
} }

View file

@ -9,6 +9,7 @@
* QNX - Initial API and implementation * QNX - Initial API and implementation
* IBM Corporation * IBM Corporation
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp; package org.eclipse.cdt.internal.core.pdom.dom.cpp;
@ -22,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.internal.core.Util; 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.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database; 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.PDOMNode;
@ -33,13 +35,13 @@ import org.eclipse.core.runtime.CoreException;
* @author Doug Schaefer * @author Doug Schaefer
* *
*/ */
class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod, ICPPFunctionType { public class PDOMCPPMethod extends PDOMCPPFunction implements IIndexType, ICPPMethod, ICPPFunctionType {
/** /**
* Offset of remaining annotation information (relative to the beginning of * Offset of remaining annotation information (relative to the beginning of
* the record). * the record).
*/ */
private static final int ANNOTATION1 = PDOMCPPFunction.RECORD_SIZE; // byte protected static final int ANNOTATION1 = PDOMCPPFunction.RECORD_SIZE; // byte
/** /**
* The size in bytes of a PDOMCPPMethod record in the database. * The size in bytes of a PDOMCPPMethod record in the database.
@ -49,7 +51,7 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod, ICPPFunctionT
/** /**
* The bit offset of CV qualifier flags within ANNOTATION1. * The bit offset of CV qualifier flags within ANNOTATION1.
*/ */
private static final int CV_OFFSET = 2; private static final int CV_OFFSET = PDOMCPPAnnotation.MAX_EXTRA_OFFSET + 1;
public PDOMCPPMethod(PDOM pdom, PDOMNode parent, ICPPMethod method) throws CoreException { public PDOMCPPMethod(PDOM pdom, PDOMNode parent, ICPPMethod method) throws CoreException {
super(pdom, parent, method); super(pdom, parent, method);
@ -91,6 +93,10 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod, ICPPFunctionT
throw new PDOMNotImplementedError(); throw new PDOMNotImplementedError();
} }
public boolean isImplicit() {
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.IMPLICIT_METHOD_OFFSET);
}
public IScope getFunctionScope() throws DOMException { public IScope getFunctionScope() throws DOMException {
throw new PDOMNotImplementedError(); throw new PDOMNotImplementedError();
} }
@ -144,12 +150,7 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod, ICPPFunctionT
return getBit(getByte(record + ANNOTATION1), PDOMCAnnotation.VOLATILE_OFFSET + CV_OFFSET); return getBit(getByte(record + ANNOTATION1), PDOMCAnnotation.VOLATILE_OFFSET + CV_OFFSET);
} }
public boolean isSameType(IType type) { public boolean isSameType(IType type) {
if (type == this) return super.isSameType(type);
return true;
if (type instanceof PDOMCPPMethod)
return getRecord() == ((PDOMCPPMethod) type).getRecordSize();
// TODO further analysis to compare with DOM objects
return false;
} }
} }

View file

@ -16,33 +16,26 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
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.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.BTree; import org.eclipse.cdt.internal.core.pdom.db.BTree;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor; import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
import org.eclipse.cdt.internal.core.pdom.dom.FindBinding;
import org.eclipse.cdt.internal.core.pdom.dom.FindBindingsInBTree; import org.eclipse.cdt.internal.core.pdom.dom.FindBindingsInBTree;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/** /**
* @author Doug Schaefer * @author Doug Schaefer
* *
*/ */
class PDOMCPPNamespace extends PDOMCPPBinding public class PDOMCPPNamespace extends PDOMCPPBinding implements ICPPNamespace, ICPPNamespaceScope {
implements ICPPNamespace, ICPPNamespaceScope {
private static final int INDEX_OFFSET = PDOMBinding.RECORD_SIZE + 0; private static final int INDEX_OFFSET = PDOMBinding.RECORD_SIZE + 0;
@ -99,117 +92,30 @@ implements ICPPNamespace, ICPPNamespaceScope {
return new IASTNode[0]; return new IASTNode[0];
} }
// mstodo this method currently does not get called, we could try to remove it. public IBinding[] find(String name) {
// an alternative an appropriate method in CPPSemantics. This implementation is not
// correct for sure.
public IBinding[] find(String name) throws DOMException {
try { try {
FindBindingsInBTree visitor = new FindBindingsInBTree(getLinkageImpl(), name.toCharArray()); FindBindingsInBTree visitor = new FindBindingsInBTree(getLinkageImpl(), name.toCharArray());
getIndex().accept(visitor); getIndex().accept(visitor);
return visitor.getBinding(); return visitor.getBinding();
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
return new IBinding[0];
} }
return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY;
} }
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException { public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
IASTNode parent = name.getParent();
try { try {
if (name instanceof ICPPASTQualifiedName) { FindBindingsInBTree visitor= new FindBindingsInBTree(getLinkageImpl(), name.toCharArray());
IASTName lastName = ((ICPPASTQualifiedName)name).getLastName(); getIndex().accept(visitor);
return lastName != null ? lastName.resolveBinding() : null;
}
if (parent instanceof ICPPASTQualifiedName) { IBinding[] bindings= visitor.getBinding();
IASTName[] names = ((ICPPASTQualifiedName)parent).getNames(); return CPPSemantics.resolveAmbiguities(name, bindings);
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 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
});
}
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
} }
return null; 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 { public boolean isFullyCached() throws DOMException {
return true; return true;
} }

View file

@ -15,11 +15,11 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException; 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.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.db.Database;
@ -33,7 +33,7 @@ import org.eclipse.core.runtime.CoreException;
* *
* @author Doug Schaefer * @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 * 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). * (relative to the beginning of the record).
*/ */
private static final int TYPE = PDOMNamedNode.RECORD_SIZE + 4; 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. * 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) { public PDOMCPPParameter(PDOM pdom, int record) {
super(pdom, record); super(pdom, record);
@ -63,6 +72,8 @@ class PDOMCPPParameter extends PDOMNamedNode implements IParameter {
Database db = pdom.getDB(); Database db = pdom.getDB();
db.putInt(record + NEXT_PARAM, 0); db.putInt(record + NEXT_PARAM, 0);
byte flags= encodeFlags(param);
db.putByte(record + FLAGS, flags);
try { try {
IType type = param.getType(); 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() { protected int getRecordSize() {
return RECORD_SIZE; return RECORD_SIZE;
} }
@ -95,11 +115,6 @@ class PDOMCPPParameter extends PDOMNamedNode implements IParameter {
return rec != 0 ? new PDOMCPPParameter(pdom, rec) : null; return rec != 0 ? new PDOMCPPParameter(pdom, rec) : null;
} }
public IASTInitializer getDefaultValue() {
return null;
// TODO throw new PDOMNotImplementedError();
}
public String[] getQualifiedName() throws DOMException { public String[] getQualifiedName() throws DOMException {
throw new PDOMNotImplementedError(); throw new PDOMNotImplementedError();
} }
@ -165,4 +180,18 @@ class PDOMCPPParameter extends PDOMNamedNode implements IParameter {
return new char[0]; 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;
}
} }

View file

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

View file

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

View file

@ -13,11 +13,11 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException; 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.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; 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.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
@ -26,15 +26,15 @@ import org.eclipse.core.runtime.CoreException;
/** /**
* @author Doug Schaefer * @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; private static final int TYPE = PDOMBinding.RECORD_SIZE + 0;
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 4; 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 { throws CoreException {
super(pdom, parent, name.toCharArray()); super(pdom, parent, typedef.getNameCharArray());
try { try {
IType type = typedef.getType(); IType type = typedef.getType();
PDOMNode typeNode = parent.getLinkageImpl().addType(this, type); PDOMNode typeNode = parent.getLinkageImpl().addType(this, type);
@ -57,7 +57,7 @@ class PDOMCPPTypedef extends PDOMCPPBinding implements ITypedef, ITypeContainer
return PDOMCPPLinkage.CPPTYPEDEF; return PDOMCPPLinkage.CPPTYPEDEF;
} }
public IType getType() throws DOMException { public IType getType() {
try { try {
PDOMNode node = getLinkageImpl().getNode(pdom.getDB().getInt(record + TYPE)); PDOMNode node = getLinkageImpl().getNode(pdom.getDB().getInt(record + TYPE));
return node instanceof IType ? (IType)node : null; return node instanceof IType ? (IType)node : null;
@ -67,28 +67,19 @@ class PDOMCPPTypedef extends PDOMCPPBinding implements ITypedef, ITypeContainer
} }
} }
public boolean isSameType(IType o) { public boolean isSameType(IType type) {
if( o == this ) try {
return true; IType myrtype = getType();
if( o instanceof ITypedef ) if (myrtype == null)
try { return false;
IType t = getType();
if( t != null ) if (type instanceof ITypedef) {
return t.isSameType( ((ITypedef)o).getType()); type= ((ITypedef)type).getType();
return false; }
} catch ( DOMException e ) { return myrtype.isSameType(type);
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 Object clone() { fail(); return null; } public Object clone() { fail(); return null; }

View file

@ -374,7 +374,7 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
IIndexFileLocation path = orderedPaths[i]; IIndexFileLocation path = orderedPaths[i];
if (path != null) { if (path != null) {
if (fTrace) { 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); IIndexFile file= addToIndex(index, path, symbolMap);
if (postAddToIndex(path, file)) { if (postAddToIndex(path, file)) {

View file

@ -440,7 +440,7 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest {
checkTreeNode(tree, 0, 2, "ns::func()"); checkTreeNode(tree, 0, 2, "ns::func()");
} }
public void _testNamespacePart2_156519() throws Exception { public void testNamespacePart2_156519() throws Exception {
String content = readTaggedComment("testNamespace"); String content = readTaggedComment("testNamespace");
IFile file= createFile(getProject(), "testNamespace.cpp", content); IFile file= createFile(getProject(), "testNamespace.cpp", content);
waitForIndexer(fIndex, file, MAX_TIME_INDEXER); waitForIndexer(fIndex, file, MAX_TIME_INDEXER);

View file

@ -30,11 +30,9 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.tests.BaseUITestCase; import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.internal.core.CCoreInternals;
public class ResolveBindingTests extends BaseUITestCase { 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 ICProject fCProject;
private IIndex fIndex; private IIndex fIndex;
@ -48,8 +46,7 @@ public class ResolveBindingTests extends BaseUITestCase {
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
fCProject= CProjectHelper.createCProject("ResolveBindingTests", "bin", IPDOMManager.ID_NO_INDEXER); fCProject= CProjectHelper.createCCProject("ResolveBindingTests", "bin", IPDOMManager.ID_FAST_INDEXER);
CCoreInternals.getPDOMManager().reindex(fCProject);
fIndex= CCorePlugin.getIndexManager().getIndex(fCProject); fIndex= CCorePlugin.getIndexManager().getIndex(fCProject);
} }
@ -151,7 +148,7 @@ public class ResolveBindingTests extends BaseUITestCase {
// m.method(); // r2 // m.method(); // r2
// n->method(); // r3 // n->method(); // r3
// } // }
public void _testMethodBinding_158735() throws Exception { public void testMethodBinding_158735() throws Exception {
String content = readTaggedComment("testMethods.h"); String content = readTaggedComment("testMethods.h");
IFile hfile= createFile(fCProject.getProject(), "testMethods.h", content); IFile hfile= createFile(fCProject.getProject(), "testMethods.h", content);
content = readTaggedComment("testMethods.cpp"); content = readTaggedComment("testMethods.cpp");

View file

@ -441,11 +441,13 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
*/ */
private static String getBindingQualifiedName(IIndexBinding binding) throws CoreException private static String getBindingQualifiedName(IIndexBinding binding) throws CoreException
{ {
StringBuffer buf = new StringBuffer(binding.getName()); StringBuffer buf = new StringBuffer();
binding= binding.getParentBinding(); String[] qname= binding.getQualifiedName();
while (binding != null) { for (int i = 0; i < qname.length; i++) {
buf.insert(0, binding.getName() + "::"); //$NON-NLS-1$ if (i>0) {
binding= binding.getParentBinding(); buf.append("::"); //$NON-NLS-1$
}
buf.append(qname[i]);
} }
return buf.toString(); return buf.toString();
} }