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

Fix for 156504 by Andrew Ferguson, Overloaded functions/methods in PDOM

This commit is contained in:
Markus Schorn 2006-10-20 09:59:38 +00:00
parent e57307c5b3
commit d54cf4d243
54 changed files with 2195 additions and 530 deletions

View file

@ -52,8 +52,8 @@ public class BTreeTests extends BaseTestCase {
dbFile = File.createTempFile("pdomtest", "db"); dbFile = File.createTempFile("pdomtest", "db");
db = new Database(dbFile.getAbsolutePath()); db = new Database(dbFile.getAbsolutePath());
rootRecord = Database.DATA_AREA; rootRecord = Database.DATA_AREA;
btree = new BTree(db, rootRecord, degree);
comparator = new BTMockRecordComparator(); comparator = new BTMockRecordComparator();
btree = new BTree(db, rootRecord, degree, comparator);
} }
// tearDown is not used for the same reason as above // tearDown is not used for the same reason as above
@ -131,7 +131,7 @@ public class BTreeTests extends BaseTestCase {
history.add(btValue); history.add(btValue);
if(debugMode) if(debugMode)
System.out.println("Add: "+value+" @ "+btValue.record); System.out.println("Add: "+value+" @ "+btValue.record);
btree.insert(btValue.getRecord(), comparator); btree.insert(btValue.getRecord());
} }
} else { } else {
if(!history.isEmpty()) { if(!history.isEmpty()) {
@ -141,7 +141,7 @@ public class BTreeTests extends BaseTestCase {
expected.remove(new Integer(btValue.intValue())); expected.remove(new Integer(btValue.intValue()));
if(debugMode) if(debugMode)
System.out.println("Remove: "+btValue.intValue()+" @ "+btValue.record); System.out.println("Remove: "+btValue.intValue()+" @ "+btValue.record);
btree.delete(btValue.getRecord(), comparator); btree.delete(btValue.getRecord());
} }
} }
if(i % 1000 == 0) { if(i % 1000 == 0) {

View file

@ -142,10 +142,7 @@ public class CPPFunctionTests extends PDOMTestBase {
assertReturnType(pdom, "floatCPPFunction", IBasicType.t_float); assertReturnType(pdom, "floatCPPFunction", IBasicType.t_float);
} }
public void _testOverloadedFunction() throws Exception { public void testOverloadedFunction() throws Exception {
// Right now, only one binding is showing up for overloaded functions.
// There really should be one for each declaration.
IBinding[] bindings = findQualifiedName(pdom, "overloadedFunction"); IBinding[] bindings = findQualifiedName(pdom, "overloadedFunction");
assertEquals(2, bindings.length); assertEquals(2, bindings.length);
boolean[] seen = new boolean[2]; boolean[] seen = new boolean[2];

View file

@ -140,20 +140,21 @@ public class DBTest extends TestCase {
"BETA" "BETA"
}; };
BTree btree = new BTree(db, Database.DATA_AREA); IBTreeComparator comparator = new IBTreeComparator() {
public int compare(int record1, int record2) throws CoreException {
IString string1 = db.getString(db.getInt(record1 + 4));
IString string2 = db.getString(db.getInt(record2 + 4));
return string1.compare(string2);
}
};
BTree btree = new BTree(db, Database.DATA_AREA, comparator);
for (int i = 0; i < names.length; ++i) { for (int i = 0; i < names.length; ++i) {
String name = names[i]; String name = names[i];
int record = db.malloc(8); int record = db.malloc(8);
db.putInt(record + 0, i); db.putInt(record + 0, i);
IString string = db.newString(name); IString string = db.newString(name);
db.putInt(record + 4, string.getRecord()); db.putInt(record + 4, string.getRecord());
btree.insert(record, new IBTreeComparator() { btree.insert(record);
public int compare(int record1, int record2) throws CoreException {
IString string1 = db.getString(db.getInt(record1 + 4));
IString string2 = db.getString(db.getInt(record2 + 4));
return string1.compare(string2);
}
});
} }
for (int i = 0; i < names.length; ++i) { for (int i = 0; i < names.length; ++i) {

View file

@ -23,6 +23,7 @@ import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
@ -272,16 +273,21 @@ public class DefDeclTests extends PDOMTestBase {
assertDefDeclRef("type", "_t03", 1, 1, 1); assertDefDeclRef("type", "_t03", 1, 1, 1);
} }
public void testStructAndTypedef_t04_unexpected() throws Exception { public void _testStructAndTypedef_t04_unexpected() throws Exception {
// suppose to find either 2 findings or 2 def/ref pairs
// because type_t04 defined as struct type_04 as typedef
String num = "_t04"; String num = "_t04";
String elName = "type" + num; String elName = "type" + num;
ICompositeType element = (ICompositeType) findSingleBinding(elName);
// checkReference(element, "ref" + num, 1); IBinding[] bindings = pdom.findBindings(Pattern.compile(elName), false, new IndexFilter(), new NullProgressMonitor());
checkReference(element, "refS" + num, 1); assertEquals(2,bindings.length);
checkDefinition(element, "defS" + num, 1);
// checkDeclaration(element, "def" + num, 1); IBinding typedef = bindings[0] instanceof ITypedef ? bindings[0] : bindings[1];
IBinding struct = bindings[0] instanceof ICompositeType ? bindings[0] : bindings[1];
checkReference(typedef, "ref" + num, 1);
checkDeclaration(typedef, "def" + num, 1);
checkReference(struct, "refS" + num, 1);
checkDefinition(struct, "defS" + num, 1);
} }
public void testTypedefAndAnonymousStruct_t05() throws Exception { public void testTypedefAndAnonymousStruct_t05() throws Exception {

View file

@ -0,0 +1,114 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software 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:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.pdom.tests;
import java.util.regex.Pattern;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
/**
* Test overloaded symbols are correctly resolved when in a common header. This
* is of interested with the Fast Indexer, as binding resolution occurs purely on
* AST information (as opposed to adapting a non-PDOM binding to a PDOM binding)
*/
public class OverloadsWithinCommonHeaderTests extends PDOMTestBase {
protected PDOM pdom;
protected void setUp() throws Exception {
if (pdom == null) {
ICProject project = createProject("overloadsWithinCommonHeader", true);
pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project);
}
pdom.acquireReadLock();
}
protected void tearDown() throws Exception {
pdom.releaseReadLock();
}
public void testOverloadedInCommonHeader_ClassScope() throws CoreException {
Pattern[] ManyOverloadedQuxPath = makePatternArray(new String[] {"ManyOverloaded","qux"});
IBinding[] ManyOverloadedQux = pdom.findBindings(ManyOverloadedQuxPath, new NullProgressMonitor());
assertEquals(5,ManyOverloadedQux.length);
// ManyOverloaded.qux()
assertFunctionRefCount(new Class[0], ManyOverloadedQux, 2);
// ManyOverloaded.qux(int)
assertFunctionRefCount(new Class[]{IBasicType.class}, ManyOverloadedQux, 4);
// ManyOverloaded.qux(int,char)
assertFunctionRefCount(new Class[]{IBasicType.class,IBasicType.class}, ManyOverloadedQux, 6);
// ManyOverloaded.qux(ManyOverloaded*)
assertFunctionRefCount(new Class[]{IPointerType.class}, ManyOverloadedQux, 8);
// ManyOverloaded.qux(ManyOverloaded)
assertFunctionRefCount(new Class[]{ICPPClassType.class}, ManyOverloadedQux, 10);
}
public void testOverloadedInCommonHeader_FileScope() throws CoreException {
Pattern[] QuuxPath = makePatternArray(new String[] {"quux"});
IBinding[] Quux = pdom.findBindings(QuuxPath, false, IndexFilter.getFilter(Linkage.CPP_LINKAGE), new NullProgressMonitor());
assertEquals(5,Quux.length);
// (file scope) quux()
assertFunctionRefCount(new Class[0], Quux, 4);
// (file scope) quux(int,char)
assertFunctionRefCount(new Class[] {IBasicType.class}, Quux, 6);
// (file scope) quux(int,char)
assertFunctionRefCount(new Class[] {IBasicType.class, IBasicType.class}, Quux, 8);
// (file scope) quux(ManyOverloaded*)
assertFunctionRefCount(new Class[] {IPointerType.class}, Quux, 10);
// (file scope) quux(ManyOverloaded)
assertFunctionRefCount(new Class[] {ICPPClassType.class}, Quux, 12);
}
public void testOverloadedInCommonHeader_NamespaceScope() throws CoreException {
Pattern[] GraultPath = makePatternArray(new String[] {"corge","grault"});
IBinding[] Grault = pdom.findBindings(GraultPath, true, IndexFilter.getFilter(Linkage.CPP_LINKAGE), new NullProgressMonitor());
assertEquals(5,Grault.length);
// corge::grault()
assertFunctionRefCount(new Class[0], Grault, 6);
// corge::grault(int,char)
assertFunctionRefCount(new Class[] {IBasicType.class}, Grault, 8);
// corge::grault(int,char)
assertFunctionRefCount(new Class[] {IBasicType.class, IBasicType.class}, Grault, 10);
// corge::grault(ManyOverloaded*)
assertFunctionRefCount(new Class[] {IPointerType.class}, Grault, 12);
// (corge::grault(ManyOverloaded)
assertFunctionRefCount(new Class[] {ICPPClassType.class}, Grault, 14);
}
public void assertFunctionRefCount(Class[] args, IBinding[] bindingPool, int refCount) throws CoreException {
assertFunctionRefCount(pdom, args, bindingPool, refCount);
}
}

View file

@ -0,0 +1,115 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software 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:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.pdom.tests;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
/**
* Test overloaded symbols are correctly resolved when within a single translation
* unit. This covers the case of adapting non-PDOM bindings to PDOM bindings by
* searching for the equivalent binding within the PDOM.
*/
public class OverloadsWithinSingleTUTests extends PDOMTestBase {
protected PDOM pdom;
protected void setUp() throws Exception {
if (pdom == null) {
ICProject project = createProject("overloadsWithinSingleTU");
pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project);
}
pdom.acquireReadLock();
}
protected void tearDown() throws Exception {
pdom.releaseReadLock();
}
public void testDistinctBindingsPresent() throws Exception {
IBinding[] fooBs = pdom.findBindings(Pattern.compile("foo"), new NullProgressMonitor());
assertEquals(3, fooBs.length);
IBinding[] barBs = pdom.findBindings(Pattern.compile("bar"), new NullProgressMonitor());
assertEquals(8, barBs.length);
IBinding[] FooBs = pdom.findBindings(Pattern.compile("Foo"), new NullProgressMonitor());
assertEquals(4, FooBs.length);
Pattern[] XBarAbsPath = makePatternArray(new String[] {"X","bar"});
IBinding[] XBarBs = pdom.findBindings(XBarAbsPath, new NullProgressMonitor());
assertEquals(4, XBarBs.length);
Pattern[] XFooPath = makePatternArray(new String[] {"X","Foo"});
IBinding[] XFooPathBs = pdom.findBindings(XFooPath, new NullProgressMonitor());
assertEquals(1, XFooPathBs.length);
}
public void testReferencesToGlobalBindings() throws Exception {
IBinding[] BarBs = pdom.findBindings(Pattern.compile("bar"), new NullProgressMonitor());
IBinding[] globalBs = getGlobalBindings(BarBs);
assertEquals(4, globalBs.length);
// bar()
assertFunctionRefCount(new Class[] {}, globalBs, 4);
// bar(int)
assertFunctionRefCount(new Class[] {IBasicType.class}, globalBs, 3);
// bar(int,int)
assertFunctionRefCount(new Class[] {IBasicType.class, IBasicType.class}, globalBs, 2);
// bar(Foo,int)
assertFunctionRefCount(new Class[] {ICPPClassType.class, IBasicType.class}, globalBs, 1);
}
// aftodo - this is probably not the best way to determine this
private static IBinding[] getGlobalBindings(IBinding[] bindings) throws CoreException {
List preresult = new ArrayList();
for(int i=0; i<bindings.length; i++) {
if(((PDOMBinding)bindings[i]).getParentNode()==null) {
preresult.add(bindings[i]);
}
}
return (IBinding[]) preresult.toArray(new IBinding[preresult.size()]);
}
public void testReferencesToNamespacedBindings() throws Exception {
Pattern[] XBarAbsPath = makePatternArray(new String[] {"X","bar"});
IBinding[] XBarBs = pdom.findBindings(XBarAbsPath, new NullProgressMonitor());
// X::bar()
assertFunctionRefCount(new Class[] {}, XBarBs, 2);
// X::bar(int)
assertFunctionRefCount(new Class[] {IBasicType.class}, XBarBs, 3);
// X::bar(int,int)
assertFunctionRefCount(new Class[] {IBasicType.class,IBasicType.class}, XBarBs, 4);
// X::bar(X::Foo,int)
assertFunctionRefCount(new Class[] {ICPPClassType.class,IBasicType.class}, XBarBs, 5);
}
public void assertFunctionRefCount(Class[] args, IBinding[] bindingPool, int refCount) throws CoreException {
assertFunctionRefCount(pdom, args, bindingPool, refCount);
}
}

View file

@ -14,7 +14,9 @@
package org.eclipse.cdt.internal.pdom.tests; package org.eclipse.cdt.internal.pdom.tests;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -23,6 +25,8 @@ import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.IPDOMManager;
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.IFunction;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
@ -30,6 +34,7 @@ import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.cdt.core.testplugin.CTestPlugin;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspace;
@ -57,6 +62,10 @@ public class PDOMTestBase extends BaseTestCase {
private String projectName= null; private String projectName= null;
protected ICProject createProject(String folderName) throws CoreException { protected ICProject createProject(String folderName) throws CoreException {
return createProject(folderName, false);
}
protected ICProject createProject(String folderName, final boolean cpp) throws CoreException {
// Create the project // Create the project
projectName = "ProjTest_" + System.currentTimeMillis(); projectName = "ProjTest_" + System.currentTimeMillis();
@ -66,7 +75,8 @@ public class PDOMTestBase extends BaseTestCase {
workspace.run(new IWorkspaceRunnable() { workspace.run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException { public void run(IProgressMonitor monitor) throws CoreException {
// Create the project // Create the project
ICProject cproject= CProjectHelper.createCProject(projectName, null); ICProject cproject= cpp ? CProjectHelper.createCCProject(projectName, null)
: CProjectHelper.createCProject(projectName, null);
// Set the indexer to the null indexer and invoke it later on. // Set the indexer to the null indexer and invoke it later on.
CCorePlugin.getPDOMManager().setIndexerId(cproject, IPDOMManager.ID_NO_INDEXER); CCorePlugin.getPDOMManager().setIndexerId(cproject, IPDOMManager.ID_NO_INDEXER);
@ -92,7 +102,7 @@ public class PDOMTestBase extends BaseTestCase {
// Index the project // Index the project
CCorePlugin.getPDOMManager().setIndexerId(cprojects[0], IPDOMManager.ID_FAST_INDEXER); CCorePlugin.getPDOMManager().setIndexerId(cprojects[0], IPDOMManager.ID_FAST_INDEXER);
// wait until the indexer is done // wait until the indexer is done
assertTrue(CCorePlugin.getIndexManager().joinIndexer(5000, new NullProgressMonitor())); assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
return cprojects[0]; return cprojects[0];
} }
@ -173,4 +183,47 @@ public class PDOMTestBase extends BaseTestCase {
ICPPMember member = (ICPPMember) bindings[0]; ICPPMember member = (ICPPMember) bindings[0];
assertEquals(visibility, member.getVisibility()); assertEquals(visibility, member.getVisibility());
} }
public static final void assertFunctionRefCount(PDOM pdom, Class[] args, IBinding[] bindingPool, int refCount) throws CoreException {
IBinding[] bindings = findIFunctions(args, bindingPool);
assertEquals(1, bindings.length);
IName[] refs = pdom.getReferences(bindings[0]);
assertEquals(refCount, refs.length);
}
// this is only approximate - composite types are not supported
public static IBinding[] findIFunctions(Class[] paramTypes, IBinding[] bindings) throws CoreException {
try {
List preresult = new ArrayList();
for(int i=0; i<bindings.length; i++) {
if(bindings[i] instanceof IFunction) {
IFunction function = (IFunction) bindings[i];
IType[] candidate = function.getType().getParameterTypes();
boolean areEqual = candidate.length == paramTypes.length;
for(int j=0; areEqual && j<paramTypes.length; j++) {
if(!paramTypes[j].isAssignableFrom(candidate[j].getClass())) {
areEqual = false;
}
}
if(areEqual) {
preresult.add(bindings[i]);
}
}
}
return (IBinding[]) preresult.toArray(new IBinding[preresult.size()]);
} catch(DOMException e) {
throw new CoreException(Util.createStatus(e));
}
}
public static Pattern[] makePatternArray(String[] args) {
List preresult = new ArrayList();
for(int i=0; i<args.length; i++) {
preresult.add(Pattern.compile(args[i]));
}
return (Pattern[]) preresult.toArray(new Pattern[preresult.size()]);
}
} }

View file

@ -22,11 +22,14 @@ public class PDOMTests extends TestSuite {
public static Test suite() { public static Test suite() {
TestSuite suite = new PDOMTests(); TestSuite suite = new PDOMTests();
suite.addTest(EnumerationTests.suite()); suite.addTestSuite(EnumerationTests.class);
suite.addTest(ClassTests.suite()); suite.addTestSuite(ClassTests.class);
suite.addTest(TypesTests.suite()); suite.addTestSuite(TypesTests.class);
suite.addTest(IncludesTests.suite()); suite.addTestSuite(IncludesTests.class);
suite.addTest(BTreeTests.suite()); suite.addTestSuite(OverloadsWithinSingleTUTests.class);
suite.addTestSuite(OverloadsWithinCommonHeaderTests.class);
suite.addTestSuite(BTreeTests.class);
suite.addTest(CPPFieldTests.suite()); suite.addTest(CPPFieldTests.suite());
suite.addTest(CPPFunctionTests.suite()); suite.addTest(CPPFunctionTests.suite());

View file

@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Symbian - Repeatedly index classTests test project to detect a particular race condition
*******************************************************************************/
package org.eclipse.cdt.internal.pdom.tests;
import java.util.regex.Pattern;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.core.runtime.NullProgressMonitor;
/**
* Test case for a race condition from Bugzilla#157992
*/
public class RaceCondition157992Test extends PDOMTestBase {
public void testRepeatedly() throws Exception {
int successes = 0, noTrials = 100;
for(int i=0; i<noTrials; i++) {
ICProject project = createProject("classTests");
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project);
pdom.acquireReadLock();
IBinding[] Bs = pdom.findBindings(Pattern.compile("B"), new NullProgressMonitor());
if(Bs.length==1)
successes++;
pdom.releaseReadLock();
}
String msg = "Same indexer on same project produces different results."
+ "Failure rate of "+(noTrials-successes)+" failures in "+noTrials+" tests";
assertTrue("Non-race-condition failure", successes!=0);
assertTrue(msg, successes == noTrials);
}
}

View file

@ -11,3 +11,10 @@ int intCFunction();
double doubleCFunction(); double doubleCFunction();
char charCFunction(); char charCFunction();
float floatCFunction(); float floatCFunction();
struct S {
struct D {
int a;
};
};

View file

@ -0,0 +1,23 @@
class ManyOverloaded {
public:
void qux() {}
void qux(int i) {}
void qux(int i, char c) {}
void qux(ManyOverloaded* ptr) {}
void qux(ManyOverloaded nptr) {}
};
void quux() {}
void quux(int i) {}
void quux(int i, char c) {}
void quux(ManyOverloaded* ptr) {}
void quux(ManyOverloaded nptr) {}
namespace corge {
void grault() {}
void grault(int i) {}
void grault(int i, char c) {}
void grault(ManyOverloaded* ptr) {}
void grault(ManyOverloaded nptr) {}
}

View file

@ -0,0 +1,27 @@
#include "class.h"
void referencesA() {
ManyOverloaded m;
m.qux();
m.qux(4); m.qux(4);
m.qux(6,'f'); m.qux(6,'f'); m.qux(6,'f');
m.qux(new ManyOverloaded()); m.qux(new ManyOverloaded());
m.qux(new ManyOverloaded()); m.qux(new ManyOverloaded());
m.qux(m); m.qux(m); m.qux(m); m.qux(m); m.qux(m);
quux(); quux();
quux(4); quux(4); quux(4);
quux(6,'f'); quux(6,'f'); quux(6,'f'); quux(6,'f');
quux(new ManyOverloaded()); quux(new ManyOverloaded());
quux(new ManyOverloaded()); quux(new ManyOverloaded()); quux(new ManyOverloaded());
quux(m); quux(m); quux(m); quux(m); quux(m); quux(m);
corge::grault(); corge::grault(); corge::grault();
corge::grault(4); corge::grault(4); corge::grault(4); corge::grault(4);
corge::grault(6,'f'); corge::grault(6,'f'); corge::grault(6,'f'); corge::grault(6,'f'); corge::grault(6,'f');
corge::grault(new ManyOverloaded()); corge::grault(new ManyOverloaded());
corge::grault(new ManyOverloaded()); corge::grault(new ManyOverloaded());
corge::grault(new ManyOverloaded()); corge::grault(new ManyOverloaded());
corge::grault(m); corge::grault(m); corge::grault(m); corge::grault(m); corge::grault(m);
corge::grault(m); corge::grault(m);
}

View file

@ -0,0 +1,27 @@
#include "class.h"
void referencesB() {
ManyOverloaded m;
m.qux();
m.qux(4); m.qux(4);
m.qux(6,'f'); m.qux(6,'f'); m.qux(6,'f');
m.qux(new ManyOverloaded()); m.qux(new ManyOverloaded());
m.qux(new ManyOverloaded()); m.qux(new ManyOverloaded());
m.qux(m); m.qux(m); m.qux(m); m.qux(m); m.qux(m);
quux(); quux();
quux(4); quux(4); quux(4);
quux(6,'f'); quux(6,'f'); quux(6,'f'); quux(6,'f');
quux(new ManyOverloaded()); quux(new ManyOverloaded());
quux(new ManyOverloaded()); quux(new ManyOverloaded()); quux(new ManyOverloaded());
quux(m); quux(m); quux(m); quux(m); quux(m); quux(m);
corge::grault(); corge::grault(); corge::grault();
corge::grault(4); corge::grault(4); corge::grault(4); corge::grault(4);
corge::grault(6,'f'); corge::grault(6,'f'); corge::grault(6,'f'); corge::grault(6,'f'); corge::grault(6,'f');
corge::grault(new ManyOverloaded()); corge::grault(new ManyOverloaded());
corge::grault(new ManyOverloaded()); corge::grault(new ManyOverloaded());
corge::grault(new ManyOverloaded()); corge::grault(new ManyOverloaded());
corge::grault(m); corge::grault(m); corge::grault(m); corge::grault(m); corge::grault(m);
corge::grault(m); corge::grault(m);
}

View file

@ -0,0 +1,52 @@
class Foo {
public:
Foo() {}
void foo() {}
void foo(int a) {}
void foo(Foo f) {}
};
void bar() {printf("bar()\n");}
void bar(int a) {printf("bar(int)\n");}
void bar(int a, int b) {printf("bar(int,int)\n");}
void bar(Foo f, int z) {
Foo a,b,c;
printf("bar(Foo,int)\n");
}
void baz() {}
namespace X {
class Foo {
public:
Foo(void) {}
void m() {}
};
void bar() {printf("X::bar()\n");}
void bar(int a) {printf("X::bar(int)\n");}
void bar(int a, int b) {printf("X::bar(int,int)\n");}
void bar(Foo f, int z) {
Foo a,b,c;
printf("X::bar(X::Foo,int)\n");
}
namespace Y {
void qux() {}
}
}
void references(Foo f, X::Foo h) {
X::bar(); X::bar();
X::bar(3); X::bar(3); X::bar(3);
X::bar(4,4); X::bar(4,4); X::bar(4,4); X::bar(4,4);
X::bar(h, 5); X::bar(h, 5); X::bar(h, 5); X::bar(h, 5); X::bar(h, 5);
bar(); bar(); bar(); bar();
bar(3); bar(3); bar(3);
bar(2,2); bar(2,2);
bar(f, 1);
Foo y = new Foo();
X::Foo z = new X::Foo();
}

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom; package org.eclipse.cdt.core.dom;
@ -29,4 +30,9 @@ public interface IPDOMIndexer {
public void reindex() throws CoreException; public void reindex() throws CoreException;
/**
* Return the unique ID of type of this indexer
* @return the unique ID of type of this indexer
*/
public String getID();
} }

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.index; package org.eclipse.cdt.core.index;

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.index; package org.eclipse.cdt.core.index;
@ -34,4 +35,18 @@ public class IndexFilter {
public boolean acceptLinkage(ILinkage linkage) { public boolean acceptLinkage(ILinkage linkage) {
return true; return true;
} }
/**
* Get an IndexFilter that filters out bindings from linkages other than that
* specified
* @param target the linkage whose bindings should be retained
* @return an IndexFilter instance
*/
public static IndexFilter getFilter(final ILinkage target) {
return new IndexFilter() {
public boolean acceptLinkage(ILinkage linkage) {
return linkage.getID() == target.getID();
}
};
}
} }

View file

@ -7,22 +7,20 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on May 28, 2004 * Created on May 28, 2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/ */
package org.eclipse.cdt.core.parser.util; package org.eclipse.cdt.core.parser.util;
/** /**
* A static utility class for char arrays
* @author dschaefe * @author dschaefe
* *
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/ */
public class CharArrayUtils { public class CharArrayUtils {
private CharArrayUtils() {}
public static final int hash(char[] str, int start, int length) { public static final int hash(char[] str, int start, int length) {
int h = 0; int h = 0;
@ -52,6 +50,32 @@ public class CharArrayUtils {
return true; return true;
} }
/**
* Implements a lexicographical comparator for char arrays. Comparison is done
* on a per char basis, not a code-point basis.
*
* @param str1 the first of the two char arrays to compare
* @param str2 the second of the two char arrays to compare
* @return 0 if str1==str2, -1 if str1 &lt; str2 and 1 if str1 &gt; str2
*/
/*
* aftodo - we should think about using the Character codepoint static methods
* if we move to Java 5
*/
public static final int compare(char[] str1, char[] str2) {
if (str1 == str2)
return 0;
if (str1.length != str2.length)
return str1.length < str2.length ? -1 : 1;
for (int i = 0; i < str1.length; ++i)
if (str1[i] != str2[i])
return str1[i] < str2[i] ? -1 : 1;
return 0;
}
public static final boolean equals(char[] str1, int start1, int length1, char[] str2) { public static final boolean equals(char[] str1, int start1, int length1, char[] str2) {
if (length1 != str2.length || str1.length < length1 ) if (length1 != str2.length || str1.length < length1 )
return false; return false;
@ -231,7 +255,6 @@ public class CharArrayUtils {
} }
final static public char[] trim(char[] chars) { final static public char[] trim(char[] chars) {
if (chars == null) if (chars == null)
return null; return null;
@ -248,7 +271,6 @@ public class CharArrayUtils {
return chars; return chars;
} }
final static public char[] lastSegment(char[] array, char[] separator) { final static public char[] lastSegment(char[] array, char[] separator) {
int pos = lastIndexOf(separator, array); int pos = lastIndexOf(separator, array);
if (pos < 0) if (pos < 0)
@ -268,6 +290,4 @@ public class CharArrayUtils {
buff[ i + j ] = charImage[j]; buff[ i + j ] = charImage[j];
} }
} }
} }

View file

@ -0,0 +1,54 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software 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:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.bid;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.core.runtime.CoreException;
/**
*
*/
public abstract class AbstractCLocalBindingIdentity implements ICLocalBindingIdentity {
protected static final String SEP = " | "; //$NON-NLS-1$
protected PDOMLinkage linkage;
protected IBinding binding;
protected String extendedType; // cached
protected AbstractCLocalBindingIdentity(IBinding binding, PDOMLinkage linkage) {
if(binding==null || linkage==null)
throw new IllegalArgumentException();
this.binding = binding;
this.linkage = linkage;
}
public String getName() {
return binding.getName();
}
public abstract int getTypeConstant() throws CoreException;
public abstract String getExtendedType() throws CoreException;
public String toString() {
try {
return getName()+SEP+getTypeConstant()+SEP+getExtendedType();
} catch(CoreException ce) {
throw new RuntimeException(ce);
}
}
public char[] getNameCharArray() throws CoreException {
return binding.getNameCharArray();
}
}

View file

@ -0,0 +1,77 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software 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:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.bid;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.core.runtime.CoreException;
/**
* An implementation of ILocalBindingIdentityComparator for CLocalBinding objects
*/
public class CLocalBindingIdentityComparator implements ILocalBindingIdentityComparator {
protected IBindingIdentityFactory factory;
public CLocalBindingIdentityComparator(IBindingIdentityFactory factory) {
this.factory = factory;
}
public int compare(IBinding a, IBinding b) throws CoreException {
ICLocalBindingIdentity aID = (ICLocalBindingIdentity) factory.getLocalBindingIdentity(a);
ICLocalBindingIdentity bID = (ICLocalBindingIdentity) factory.getLocalBindingIdentity(b);
return compare(aID, bID);
}
public int compare(ILocalBindingIdentity aID, IBinding b) throws CoreException {
ICLocalBindingIdentity bID = (ICLocalBindingIdentity) factory.getLocalBindingIdentity(b);
return compare((ICLocalBindingIdentity) aID, bID);
}
public int compare(IBinding a, ILocalBindingIdentity bID) throws CoreException {
ICLocalBindingIdentity aID = (ICLocalBindingIdentity) factory.getLocalBindingIdentity(a);
return compare(aID, bID);
}
public int compare(ILocalBindingIdentity aID, ILocalBindingIdentity bID) throws CoreException {
return compare((ICLocalBindingIdentity) aID, (ICLocalBindingIdentity) bID);
}
public int compare(ICLocalBindingIdentity aID, ICLocalBindingIdentity bID) throws CoreException {
int cmp = CharArrayUtils.compare(aID.getNameCharArray(), bID.getNameCharArray());
if(cmp!=0) return cmp;
int tyConA = aID.getTypeConstant();
int tyConB = bID.getTypeConstant();
if(tyConA != tyConB) {
return tyConA < tyConB ? -1 : 1;
}
cmp = aID.getExtendedType().compareTo(bID.getExtendedType());
return cmp;
}
public int compareNameAndConstOnly(IBinding a, char[] bName, int bConst) throws CoreException {
ICLocalBindingIdentity aID = (ICLocalBindingIdentity) factory.getLocalBindingIdentity(a);
int cmp = CharArrayUtils.compare(aID.getNameCharArray(), bName);
if(cmp!=0) {
return cmp;
}
int tyCon = aID.getTypeConstant();
if(tyCon != bConst) {
return tyCon < bConst ? -1 : 1;
}
return 0;
}
}

View file

@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software 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:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.bid;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.core.runtime.CoreException;
/**
* A factory for instances of binding identitys
*/
public interface IBindingIdentityFactory {
/**
* Return an IBindingIdentity instance for the named binding. No assumption
* is made about whether the IBinding parameter is from the PDOM or DOM
* @param binding the binding to create a IBindingIdentity for
* @return a binding identity instance
* @throws CoreException
*/
public ILocalBindingIdentity getLocalBindingIdentity(IBinding binding) throws CoreException;
/*
* aftodo - we might want to introduce a true binding identity (i.e. identifies globally
* not within a scope). I've no client code for this though.
*
* public IBindingIdentity getBindingIdentity(IBinding binding) throws CoreException
*/
}

View file

@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software 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:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.bid;
import org.eclipse.core.runtime.CoreException;
/**
* An IBindingIdentity instance uniquely defines a binding within a scope. Instances
* are provided by an IBindingIdentityFactory and used by datastructures within the
* PDOM to order binding records.
*/
public interface ICLocalBindingIdentity extends ILocalBindingIdentity {
/**
* Returns the constant associated with the coarse-grained type of the
* associated IBinding
* @return the constant associated with the coarse-grained type of the
* associated IBinding
* @throws CoreException
*/
public int getTypeConstant() throws CoreException;
/**
* Returns a String of unspecified format which uniquely identifies this
* binding within its scope
* @return
* @throws CoreException
*/
public String getExtendedType() throws CoreException;
}

View file

@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software 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:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.bid;
import org.eclipse.core.runtime.CoreException;
/**
* An ILocalBindingIdentity instance uniquely defines a binding within a scope.
* <p>
* All LocalBindingIdentity instances are required to order by name as the most significant
* component, and then by any other information. This is for indexing purposes.
*/
public interface ILocalBindingIdentity {
/**
* Get the name of the binding this identity represents
* @return the name of the binding this identity represents
* @throws CoreException
*/
public char[] getNameCharArray() throws CoreException;
}

View file

@ -0,0 +1,52 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software 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:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.bid;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.core.runtime.CoreException;
/**
* A comparator for ILocalBindingIdentity objects
*/
public interface ILocalBindingIdentityComparator {
/**
*
* @param a
* @param b
* @return -1 if a&lt;b, 0 if a==b and 1 if a&gt;b
* @throws CoreException
*/
public int compare(IBinding a, IBinding b) throws CoreException;
/**
*
* @param a
* @param b
* @return -1 if a&lt;b, 0 if a==b and 1 if a&gt;b
* @throws CoreException
*/
public int compare(ILocalBindingIdentity a, IBinding b) throws CoreException;
/**
*
* @param a
* @param b
* @return -1 if a&lt;b, 0 if a==b and 1 if a&gt;b
* @throws CoreException
*/
public int compare(IBinding a, ILocalBindingIdentity b) throws CoreException;
/**
*
* @param a
* @param b
* @return -1 if a&lt;b, 0 if a==b and 1 if a&gt;b
* @throws CoreException
*/
public int compare(ILocalBindingIdentity a, ILocalBindingIdentity b) throws CoreException;
}

View file

@ -48,7 +48,6 @@ 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.PDOMFile.Comparator;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile.Finder; import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile.Finder;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
@ -146,7 +145,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
public BTree getFileIndex() throws CoreException { public BTree getFileIndex() throws CoreException {
if (fileIndex == null) if (fileIndex == null)
fileIndex = new BTree(getDB(), FILE_INDEX); fileIndex = new BTree(getDB(), FILE_INDEX, new PDOMFile.Comparator(getDB()));
return fileIndex; return fileIndex;
} }
@ -165,7 +164,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
PDOMFile file = getFile(filename); PDOMFile file = getFile(filename);
if (file == null) { if (file == null) {
file = new PDOMFile(this, filename); file = new PDOMFile(this, filename);
getFileIndex().insert(file.getRecord(), new Comparator(db)); getFileIndex().insert(file.getRecord());
} }
return file; return file;
} }
@ -592,5 +591,4 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
public IPath getPath() { public IPath getPath() {
return fPath; return fPath;
} }
} }

View file

@ -7,7 +7,7 @@
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Symbian - Provide B-tree deletion routine * Andrew Ferguson (Symbian) - Provide B-tree deletion routine
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.db; package org.eclipse.cdt.internal.core.pdom.db;
@ -39,8 +39,10 @@ public class BTree {
protected final int OFFSET_CHILDREN; protected final int OFFSET_CHILDREN;
protected final int MEDIAN_RECORD; protected final int MEDIAN_RECORD;
public BTree(Database db, int rootPointer) { protected final IBTreeComparator cmp;
this(db, rootPointer, 8);
public BTree(Database db, int rootPointer, IBTreeComparator cmp) {
this(db, rootPointer, 8, cmp);
} }
/** /**
@ -49,12 +51,13 @@ public class BTree {
* @param db the database containing the btree * @param db the database containing the btree
* @param root offset into database of the pointer to the root node * @param root offset into database of the pointer to the root node
*/ */
public BTree(Database db, int rootPointer, int degree) { public BTree(Database db, int rootPointer, int degree, IBTreeComparator cmp) {
if(degree<2) if(degree<2)
throw new IllegalArgumentException(Messages.getString("BTree.IllegalDegree")); //$NON-NLS-1$ throw new IllegalArgumentException(Messages.getString("BTree.IllegalDegree")); //$NON-NLS-1$
this.db = db; this.db = db;
this.rootPointer = rootPointer; this.rootPointer = rootPointer;
this.cmp = cmp;
this.DEGREE = degree; this.DEGREE = degree;
this.MIN_RECORDS = DEGREE - 1; this.MIN_RECORDS = DEGREE - 1;
@ -92,7 +95,7 @@ public class BTree {
* @param offset of the record * @param offset of the record
* @return * @return
*/ */
public int insert(int record, IBTreeComparator comparator) throws CoreException { public int insert(int record) throws CoreException {
int root = getRoot(); int root = getRoot();
// is this our first time in // is this our first time in
@ -101,10 +104,10 @@ public class BTree {
return record; return record;
} }
return insert(null, 0, 0, root, record, comparator); return insert(null, 0, 0, root, record);
} }
private int insert(Chunk pChunk, int parent, int iParent, int node, int record, IBTreeComparator comparator) throws CoreException { private int insert(Chunk pChunk, int parent, int iParent, int node, int record) throws CoreException {
Chunk chunk = db.getChunk(node); Chunk chunk = db.getChunk(node);
// if this node is full (last record isn't null), split it // if this node is full (last record isn't null), split it
@ -149,7 +152,7 @@ public class BTree {
putRecord(chunk, node, MEDIAN_RECORD, 0); putRecord(chunk, node, MEDIAN_RECORD, 0);
// set the node to the correct one to follow // set the node to the correct one to follow
if (comparator.compare(record, median) > 0) { if (cmp.compare(record, median) > 0) {
node = newnode; node = newnode;
chunk = newchunk; chunk = newchunk;
} }
@ -164,7 +167,7 @@ public class BTree {
// past the end // past the end
break; break;
} else { } else {
int compare = comparator.compare(record1, record); int compare = cmp.compare(record1, record);
if (compare == 0) if (compare == 0)
// found it, no insert, just return the record // found it, no insert, just return the record
return record; return record;
@ -177,7 +180,7 @@ public class BTree {
int child = getChild(chunk, node, i); int child = getChild(chunk, node, i);
if (child != 0) { if (child != 0) {
// visit the children // visit the children
return insert(chunk, node, i, child, record, comparator); return insert(chunk, node, i, child, record);
} else { } else {
// were at the leaf, add us in. // were at the leaf, add us in.
// first copy everything after over one // first copy everything after over one
@ -218,9 +221,9 @@ public class BTree {
* @param cmp the comparator for locating the record * @param cmp the comparator for locating the record
* @throws CoreException * @throws CoreException
*/ */
public void delete(int record, IBTreeComparator cmp) throws CoreException { public void delete(int record) throws CoreException {
try { try {
deleteImp(record, getRoot(), DELMODE_NORMAL, cmp); deleteImp(record, getRoot(), DELMODE_NORMAL);
} catch(BTreeKeyNotFoundException e) { } catch(BTreeKeyNotFoundException e) {
// contract of this method is to NO-OP upon this event // contract of this method is to NO-OP upon this event
} }
@ -277,7 +280,7 @@ public class BTree {
* @return the address of the record removed from the B-tree * @return the address of the record removed from the B-tree
* @throws CoreException * @throws CoreException
*/ */
private int deleteImp(int key, int nodeRecord, int mode, IBTreeComparator cmp) private int deleteImp(int key, int nodeRecord, int mode)
throws CoreException, BTreeKeyNotFoundException { throws CoreException, BTreeKeyNotFoundException {
BTNode node = new BTNode(nodeRecord); BTNode node = new BTNode(nodeRecord);
@ -316,7 +319,7 @@ public class BTree {
BTNode succ = node.getChild(keyIndexInNode+1); BTNode succ = node.getChild(keyIndexInNode+1);
if(succ!=null && succ.keyCount > MIN_RECORDS) { if(succ!=null && succ.keyCount > MIN_RECORDS) {
/* Case 2a: Delete key by overwriting it with its successor (which occurs in a leaf node) */ /* Case 2a: Delete key by overwriting it with its successor (which occurs in a leaf node) */
int subst = deleteImp(-1, succ.node, DELMODE_DELETE_MINIMUM, cmp); int subst = deleteImp(-1, succ.node, DELMODE_DELETE_MINIMUM);
putRecord(node.chunk, node.node, keyIndexInNode, subst); putRecord(node.chunk, node.node, keyIndexInNode, subst);
return key; return key;
} }
@ -324,7 +327,7 @@ public class BTree {
BTNode pred = node.getChild(keyIndexInNode); BTNode pred = node.getChild(keyIndexInNode);
if(pred!=null && pred.keyCount > MIN_RECORDS) { if(pred!=null && pred.keyCount > MIN_RECORDS) {
/* Case 2b: Delete key by overwriting it with its predecessor (which occurs in a leaf node) */ /* Case 2b: Delete key by overwriting it with its predecessor (which occurs in a leaf node) */
int subst = deleteImp(-1, pred.node, DELMODE_DELETE_MAXIMUM, cmp); int subst = deleteImp(-1, pred.node, DELMODE_DELETE_MAXIMUM);
putRecord(node.chunk, node.node, keyIndexInNode, subst); putRecord(node.chunk, node.node, keyIndexInNode, subst);
return key; return key;
} }
@ -332,7 +335,7 @@ public class BTree {
/* Case 2c: Merge successor and predecessor */ /* Case 2c: Merge successor and predecessor */
// assert(pred!=null && succ!=null); // assert(pred!=null && succ!=null);
mergeNodes(succ, node, keyIndexInNode, pred); mergeNodes(succ, node, keyIndexInNode, pred);
return deleteImp(key, pred.node, mode, cmp); return deleteImp(key, pred.node, mode);
} else { } else {
/* Case 3: non-leaf node which does not itself contain the key */ /* Case 3: non-leaf node which does not itself contain the key */
@ -358,7 +361,7 @@ public class BTree {
} }
if(child.keyCount > MIN_RECORDS) { if(child.keyCount > MIN_RECORDS) {
return deleteImp(key, child.node, mode, cmp); return deleteImp(key, child.node, mode);
} else { } else {
BTNode sibR = node.getChild(subtreeIndex+1); BTNode sibR = node.getChild(subtreeIndex+1);
if(sibR!=null && sibR.keyCount > MIN_RECORDS) { if(sibR!=null && sibR.keyCount > MIN_RECORDS) {
@ -368,7 +371,7 @@ public class BTree {
append(child, rightKey, getChild(sibR.chunk, sibR.node, 0)); append(child, rightKey, getChild(sibR.chunk, sibR.node, 0));
nodeContentDelete(sibR, 0, 1); nodeContentDelete(sibR, 0, 1);
putRecord(node.chunk, node.node, subtreeIndex, leftmostRightSiblingKey); putRecord(node.chunk, node.node, subtreeIndex, leftmostRightSiblingKey);
return deleteImp(key, child.node, mode, cmp); return deleteImp(key, child.node, mode);
} }
BTNode sibL = node.getChild(subtreeIndex-1); BTNode sibL = node.getChild(subtreeIndex-1);
@ -380,19 +383,19 @@ public class BTree {
putRecord(sibL.chunk, sibL.node, sibL.keyCount-1, 0); putRecord(sibL.chunk, sibL.node, sibL.keyCount-1, 0);
putChild(sibL.chunk, sibL.node, sibL.keyCount, 0); putChild(sibL.chunk, sibL.node, sibL.keyCount, 0);
putRecord(node.chunk, node.node, subtreeIndex-1, rightmostLeftSiblingKey); putRecord(node.chunk, node.node, subtreeIndex-1, rightmostLeftSiblingKey);
return deleteImp(key, child.node, mode, cmp); return deleteImp(key, child.node, mode);
} }
/* Case 3b (i,ii): leftSibling, child, rightSibling all have minimum number of keys */ /* Case 3b (i,ii): leftSibling, child, rightSibling all have minimum number of keys */
if(sibL!=null) { // merge child into leftSibling if(sibL!=null) { // merge child into leftSibling
mergeNodes(child, node, subtreeIndex-1, sibL); mergeNodes(child, node, subtreeIndex-1, sibL);
return deleteImp(key, sibL.node, mode, cmp); return deleteImp(key, sibL.node, mode);
} }
if(sibR!=null) { // merge rightSibling into child if(sibR!=null) { // merge rightSibling into child
mergeNodes(sibR, node, subtreeIndex, child); mergeNodes(sibR, node, subtreeIndex, child);
return deleteImp(key, child.node, mode, cmp); return deleteImp(key, child.node, mode);
} }
throw new BTreeKeyNotFoundException( throw new BTreeKeyNotFoundException(

View file

@ -11,6 +11,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.db; package org.eclipse.cdt.internal.core.pdom.db;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
@ -53,6 +54,7 @@ import org.eclipse.core.runtime.Status;
*/ */
public class Database { public class Database {
private final File location;
private final RandomAccessFile file; private final RandomAccessFile file;
Chunk[] toc; Chunk[] toc;
@ -73,6 +75,7 @@ public class Database {
public Database(String filename) throws CoreException { public Database(String filename) throws CoreException {
try { try {
location = new File(filename);
file = new RandomAccessFile(filename, "rw"); //$NON-NLS-1$ file = new RandomAccessFile(filename, "rw"); //$NON-NLS-1$
// Allocate chunk table, make sure we have at least one // Allocate chunk table, make sure we have at least one
@ -331,4 +334,11 @@ public class Database {
public void close() throws IOException { public void close() throws IOException {
file.close(); file.close();
} }
/**
* This method is public for testing purposes only.
*/
public File getLocation() {
return location;
}
} }

View file

@ -0,0 +1,70 @@
/*******************************************************************************
* Copyright (c) 2005, 2006 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.bid.CLocalBindingIdentityComparator;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Status;
public class FindBindingByLinkageConstant implements IBTreeVisitor, IPDOMVisitor {
protected final char[] name;
protected final int constant;
protected final PDOMLinkage linkage;
protected final CLocalBindingIdentityComparator bic;
protected PDOMBinding result;
public FindBindingByLinkageConstant(PDOMLinkage linkage, char[] name, int constant) {
this.name = name;
this.constant = constant;
this.linkage = linkage;
this.bic = new CLocalBindingIdentityComparator(linkage);
}
public int compare(int record) throws CoreException {
PDOMNode node = linkage.getNode(record);
return CharArrayUtils.compare(
((PDOMBinding)node).getNameCharArray(),
name);
}
public boolean visit(int record) throws CoreException {
if(record!=0) {
PDOMNode node = linkage.getNode(record);
if(bic.compareNameAndConstOnly((PDOMBinding)node, name, constant)==0) {
result = (PDOMBinding) node;
return false;
}
}
return true;
}
public boolean visit(IPDOMNode node) throws CoreException {
if(node!=null) {
if(bic.compareNameAndConstOnly((PDOMBinding)node, name, constant)==0) {
result = (PDOMBinding) node;
throw new CoreException(Status.OK_STATUS); // TODO - why not just return false?
}
}
return true;
}
public void leave(IPDOMNode node) throws CoreException {/*NO-OP*/}
public PDOMBinding getResult() {
return result;
}
}

View file

@ -15,9 +15,18 @@ import java.util.List;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
public final class FindBindingsInBTree extends PDOMNamedNode.NodeFinder { public final class FindBindingsInBTree implements IBTreeVisitor {
protected final PDOM pdom;
protected final char[] name;
public int compare(int record) throws CoreException {
PDOMNamedNode node = ((PDOMNamedNode)pdom.getLinkage(record).getNode(record));
return node.getDBName().compare(name);
}
private List bindings = new ArrayList(); private List bindings = new ArrayList();
private final int[] desiredType; private final int[] desiredType;
@ -51,7 +60,8 @@ public final class FindBindingsInBTree extends PDOMNamedNode.NodeFinder {
* @param desiredType * @param desiredType
*/ */
public FindBindingsInBTree(PDOM pdom, char[] name, int[] desiredType) { public FindBindingsInBTree(PDOM pdom, char[] name, int[] desiredType) {
super(pdom, name); this.pdom = pdom;
this.name = name;
this.desiredType = desiredType; this.desiredType = desiredType;
} }
@ -83,5 +93,4 @@ public final class FindBindingsInBTree extends PDOMNamedNode.NodeFinder {
public IBinding[] getBinding() { public IBinding[] getBinding() {
return (IBinding[])bindings.toArray(new IBinding[bindings.size()]); return (IBinding[])bindings.toArray(new IBinding[bindings.size()]);
} }
} }

View file

@ -0,0 +1,74 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software 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:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.internal.core.dom.bid.CLocalBindingIdentityComparator;
import org.eclipse.cdt.internal.core.dom.bid.ILocalBindingIdentity;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Status;
public class FindEquivalentBinding implements IBTreeVisitor, IPDOMVisitor {
PDOMBinding result;
PDOMLinkage linkage;
ILocalBindingIdentity targetBID;
CLocalBindingIdentityComparator cmp;
public FindEquivalentBinding(PDOMLinkage linkage, ILocalBindingIdentity target) throws CoreException {
this.linkage = linkage;
this.targetBID = target;
this.cmp = new CLocalBindingIdentityComparator(linkage);
}
public FindEquivalentBinding(PDOMLinkage linkage, IBinding target) throws CoreException {
this.linkage = linkage;
this.targetBID = linkage.getLocalBindingIdentity(target);
this.cmp = new CLocalBindingIdentityComparator(linkage);
}
public boolean visit(int record) throws CoreException {
if(record!=0) {
PDOMNode node = linkage.getNode(record);
if(cmp.compare(targetBID, (IBinding) node)==0) {
result = (PDOMBinding) node;
return false;
}
}
return true;
}
public int compare(int record) throws CoreException {
PDOMNode node = linkage.getNode(record);
return cmp.compare((IBinding) node, targetBID);
}
public boolean visit(IPDOMNode node) throws CoreException {
if(node!=null && (node instanceof IBinding)) {
if(cmp.compare(targetBID, (IBinding) node)==0) {
result = (PDOMBinding) node;
// aftodo - there is probably no performance reason not
// to just return false here
throw new CoreException(Status.OK_STATUS);
}
}
return true;
}
public void leave(IPDOMNode node) throws CoreException {/*NO-OP*/}
public PDOMBinding getResult() {
return result;
}
}

View file

@ -1,12 +1,23 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software 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:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom; package org.eclipse.cdt.internal.core.pdom.dom;
import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/** /**
* Interface for PDOM entities that contain members * Interface for PDOM entities that contain members. Note this is not a generic
*/ */
public interface IPDOMMemberOwner { public interface IPDOMMemberOwner {
public void addMember(PDOMNode member) throws CoreException; public void addMember(PDOMNode member) throws CoreException;
public void accept(IPDOMVisitor visitor) throws CoreException; public void accept(IPDOMVisitor visitor) throws CoreException;
public void addChild(PDOMNode member) throws CoreException;
} }

View file

@ -8,6 +8,7 @@
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom; package org.eclipse.cdt.internal.core.pdom.dom;
@ -38,6 +39,10 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
super(pdom, parent, name.toCharArray()); super(pdom, parent, name.toCharArray());
} }
protected PDOMBinding(PDOM pdom, PDOMNode parent, char[] name) throws CoreException {
super(pdom, parent, name);
}
public PDOMBinding(PDOM pdom, int record) { public PDOMBinding(PDOM pdom, int record) {
super(pdom, record); super(pdom, record);
} }
@ -167,6 +172,22 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
return pdom; return pdom;
} }
abstract protected int getRecordSize(); // superclass's implementation is no longer valid
public String toString() {
try {
return getLinkageImpl().getLocalBindingIdentity(this).toString();
} catch(CoreException ce) {
CCorePlugin.log(ce);
return super.toString();
}
}
/**
* Convenience method to shorten subclass file length
*/
protected void fail() { throw new PDOMNotImplementedError(); }
public boolean mayHaveChildren() { public boolean mayHaveChildren() {
return false; return false;
} }

View file

@ -99,6 +99,13 @@ public class PDOMFile implements IIndexFragmentFile {
setFirstIncludedBy(null); setFirstIncludedBy(null);
} }
public void setFilename(String newName) throws CoreException {
Database db = pdom.getDB();
int oldRecord = db.getInt(record + FILE_NAME);
db.free(oldRecord);
db.putInt(record + FILE_NAME, db.newString(newName).getRecord());
}
public int getRecord() { public int getRecord() {
return record; return record;
} }

View file

@ -9,6 +9,7 @@
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* IBM Corporation * IBM Corporation
* Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom; package org.eclipse.cdt.internal.core.pdom.dom;
@ -30,10 +31,13 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexLinkage; import org.eclipse.cdt.core.index.IIndexLinkage;
import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.bid.CLocalBindingIdentityComparator;
import org.eclipse.cdt.internal.core.dom.bid.IBindingIdentityFactory;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
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.Database; import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
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.db.IString; import org.eclipse.cdt.internal.core.pdom.db.IString;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -44,7 +48,7 @@ import org.eclipse.core.runtime.CoreException;
* This class represents a collection of symbols that can be linked together at * This class represents a collection of symbols that can be linked together at
* link time. These are generally global symbols specific to a given language. * link time. These are generally global symbols specific to a given language.
*/ */
public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage { public abstract class PDOMLinkage extends PDOMNamedNode implements IBindingIdentityFactory, IIndexLinkage {
// record offsets // record offsets
private static final int ID_OFFSET = PDOMNamedNode.RECORD_SIZE + 0; private static final int ID_OFFSET = PDOMNamedNode.RECORD_SIZE + 0;
@ -97,7 +101,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
} }
public BTree getIndex() throws CoreException { public BTree getIndex() throws CoreException {
return new BTree(pdom.getDB(), record + INDEX_OFFSET); return new BTree(pdom.getDB(), record + INDEX_OFFSET, getIndexComparator());
} }
public void accept(final IPDOMVisitor visitor) throws CoreException { public void accept(final IPDOMVisitor visitor) throws CoreException {
@ -122,8 +126,8 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
return this; return this;
} }
protected void addChild(PDOMNamedNode child) throws CoreException { public final void addChild(PDOMNode child) throws CoreException {
getIndex().insert(child.getRecord(), child.getIndexComparator()); getIndex().insert(child.getRecord());
} }
public PDOMNode getNode(int record) throws CoreException { public PDOMNode getNode(int record) throws CoreException {
@ -137,12 +141,31 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
} }
public PDOMNode addType(PDOMNode parent, IType type) throws CoreException { public PDOMNode addType(PDOMNode parent, IType type) throws CoreException {
PDOMNode node;
if (type instanceof IPointerType) if (type instanceof IPointerType)
return new PDOMPointerType(pdom, parent, (IPointerType)type); node = new PDOMPointerType(pdom, parent, (IPointerType)type);
else if (type instanceof IQualifierType) else if (type instanceof IQualifierType)
return new PDOMQualifierType(pdom, parent, (IQualifierType)type); node = new PDOMQualifierType(pdom, parent, (IQualifierType)type);
else else
return null; node = null;
if(node!=null) {
parent.addChild(node);
}
return node;
}
public final IBTreeComparator getIndexComparator() {
return new IBTreeComparator() {
CLocalBindingIdentityComparator cmp = new CLocalBindingIdentityComparator(PDOMLinkage.this);
public final int compare(int record1, int record2) throws CoreException {
PDOMNode node1 = getNode(record1);
PDOMNode node2 = getNode(record2);
return cmp.compare((IBinding)node1,(IBinding)node2);
}
};
} }
public abstract PDOMBinding addName(IASTName name, PDOMFile file) throws CoreException; public abstract PDOMBinding addName(IASTName name, PDOMFile file) throws CoreException;
@ -151,11 +174,19 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
public abstract PDOMBinding resolveBinding(IASTName name) throws CoreException; public abstract PDOMBinding resolveBinding(IASTName name) throws CoreException;
/**
*
* @param binding
* @return null for filescope for non-pdom bindings, this for filescope for pdom bindings
* or the parent binding in any other case
* @throws CoreException
*/
public PDOMNode getAdaptedParent(IBinding binding) throws CoreException { public PDOMNode getAdaptedParent(IBinding binding) throws CoreException {
try { try {
IScope scope = binding.getScope(); IScope scope = binding.getScope();
if (scope == null) if (scope == null) {
return null; return binding instanceof PDOMBinding ? this : null;
}
if (scope instanceof IIndexBinding) { if (scope instanceof IIndexBinding) {
IIndexBinding parent= ((IIndexBinding) scope).getParentBinding(); IIndexBinding parent= ((IIndexBinding) scope).getParentBinding();
@ -201,4 +232,6 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
} }
return null; return null;
} }
public abstract IBindingIdentityFactory getBindingIdentityFactory();
} }

View file

@ -8,6 +8,7 @@
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* IBM Corporation * IBM Corporation
* Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom; package org.eclipse.cdt.internal.core.pdom.dom;
@ -16,7 +17,6 @@ import org.eclipse.cdt.core.CCorePlugin;
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.db.IBTreeComparator; import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
import org.eclipse.cdt.internal.core.pdom.db.IString; import org.eclipse.cdt.internal.core.pdom.db.IString;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -45,9 +45,6 @@ public abstract class PDOMNamedNode extends PDOMNode {
Database db = pdom.getDB(); Database db = pdom.getDB();
db.putInt(record + NAME, db.putInt(record + NAME,
name != null ? db.newString(name).getRecord() : 0); name != null ? db.newString(name).getRecord() : 0);
if (parent != null)
parent.addChild(this);
} }
protected int getRecordSize() { protected int getRecordSize() {
@ -75,7 +72,7 @@ public abstract class PDOMNamedNode extends PDOMNode {
int string1 = db.getInt(record1 + NAME); int string1 = db.getInt(record1 + NAME);
int string2 = db.getInt(record2 + NAME); int string2 = db.getInt(record2 + NAME);
return db.getString(string1).compare(db.getString(string2)); return db.getString(string1).compare(db.getString(string2));
}; }
}; };
} }
@ -105,18 +102,4 @@ public abstract class PDOMNamedNode extends PDOMNode {
return (bitVector & mask) == mask; return (bitVector & mask) == mask;
} }
public abstract static class NodeFinder implements IBTreeVisitor {
protected final PDOM pdom;
protected final char[] name;
protected NodeFinder(PDOM pdom, char [] name) {
this.pdom = pdom;
this.name = name;
}
public int compare(int record) throws CoreException {
Database db = pdom.getDB();
int namerec = db.getInt(record + NAME);
return db.getString(namerec).compare(name);
}
}
} }

View file

@ -8,6 +8,7 @@
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom; package org.eclipse.cdt.internal.core.pdom.dom;
@ -26,7 +27,7 @@ import org.eclipse.core.runtime.CoreException;
* PDOM nodes form a multi-root tree with linkages being the roots. * PDOM nodes form a multi-root tree with linkages being the roots.
* This class managed the parent pointer. * This class managed the parent pointer.
*/ */
public abstract class PDOMNode implements IPDOMNode{ public abstract class PDOMNode implements IPDOMNode {
private static final int TYPE = 0; private static final int TYPE = 0;
private static final int PARENT = 4; private static final int PARENT = 4;
@ -52,8 +53,6 @@ public abstract class PDOMNode implements IPDOMNode{
// parent // parent
db.putInt(record + PARENT, parent != null ? parent.getRecord() : 0); db.putInt(record + PARENT, parent != null ? parent.getRecord() : 0);
if (parent instanceof IPDOMMemberOwner)
((IPDOMMemberOwner)parent).addMember(this);
} }
protected abstract int getRecordSize(); protected abstract int getRecordSize();
@ -111,7 +110,7 @@ public abstract class PDOMNode implements IPDOMNode{
return pdom.getLinkage(linkagerec); return pdom.getLinkage(linkagerec);
} }
protected void addChild(PDOMNamedNode child) throws CoreException { public void addChild(PDOMNode child) throws CoreException {
// nothing here // nothing here
} }

View file

@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software 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:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.c;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.bid.AbstractCLocalBindingIdentity;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.core.runtime.CoreException;
public class CBindingIdentity extends AbstractCLocalBindingIdentity {
public CBindingIdentity(IBinding binding, PDOMLinkage linkage) {
super(binding, linkage);
}
public int getTypeConstant() throws CoreException {
if(binding instanceof PDOMBinding) {
return ((PDOMBinding) binding).getNodeType();
} else {
return ((PDOMCLinkage)linkage).getBindingType(binding);
}
}
public String getExtendedType() throws CoreException {
if(binding instanceof IFunction) {
IFunction f = (IFunction) binding;
try {
String mangled = ASTTypeUtil.getParameterTypeString(f.getType());
return mangled;
} catch(DOMException e) {
throw new CoreException(Util.createStatus(e));
}
}
return ""; //$NON-NLS-1$
}
}

View file

@ -0,0 +1,129 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.c;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
import org.eclipse.cdt.internal.core.Util;
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.core.runtime.CoreException;
/**
* @author Doug Schaefer
*
*/
class PDOMCBasicType extends PDOMNode implements ICBasicType {
public static final int TYPE_ID = PDOMNode.RECORD_SIZE + 0; // short
public static final int FLAGS = PDOMNode.RECORD_SIZE + 2; // short
public static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 4;
public static final int IS_LONG = 0x1;
public static final int IS_SHORT = 0x2;
public static final int IS_UNSIGNED = 0x4;
public static final int IS_SIGNED = 0x8;
public static final int IS_LONGLONG = 0x10;
public static final int IS_IMAGINARY = 0x20;
public static final int IS_COMPLEX = 0x40;
public PDOMCBasicType(PDOM pdom, int record) {
super(pdom, record);
}
public PDOMCBasicType(PDOM pdom, PDOMNode parent, ICBasicType type) throws CoreException {
super(pdom, parent);
try {
Database db = pdom.getDB();
db.putChar(record + TYPE_ID, (char)type.getType());
char flags = 0;
if (type.isLong()) flags |= IS_LONG;
if (type.isShort()) flags |= IS_SHORT;
if (type.isSigned()) flags |= IS_SIGNED;
if (type.isUnsigned()) flags |= IS_UNSIGNED;
if (type.isLongLong()) flags |= IS_LONGLONG;
if (type.isImaginary()) flags |= IS_IMAGINARY;
if (type.isComplex()) flags |= IS_COMPLEX;
db.putChar(record + FLAGS, flags);
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
}
protected int getRecordSize() {
return RECORD_SIZE;
}
public int getNodeType() {
return PDOMCLinkage.CBASICTYPE;
}
public int getType() throws DOMException {
try {
return pdom.getDB().getChar(record + TYPE_ID);
} catch (CoreException e) {
CCorePlugin.log(e);
return 0;
}
}
public IASTExpression getValue() throws DOMException {
// Returning null for now, not sure what needs to be here if anything
// Values only seem to be used at type resolution time.
return null;
}
public boolean isLong() throws DOMException { return flagSet(IS_LONG); }
public boolean isShort() throws DOMException { return flagSet(IS_SHORT); }
public boolean isSigned() throws DOMException { return flagSet(IS_SIGNED); }
public boolean isUnsigned() throws DOMException { return flagSet(IS_UNSIGNED); }
public boolean isLongLong() throws DOMException { return flagSet(IS_LONGLONG); }
public boolean isImaginary() { return flagSet(IS_IMAGINARY); }
public boolean isComplex() { return flagSet(IS_COMPLEX); }
public boolean isSameType(IType type) {
// TODO something fancier
return equals(type);
}
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
return null;
}
}
private char getFlags() throws CoreException {
return pdom.getDB().getChar(record + FLAGS);
}
private boolean flagSet(int flag) {
try {
return (getFlags() & flag) != 0;
} catch (CoreException e) {
CCorePlugin.log(e);
return false;
}
}
}

View file

@ -8,21 +8,28 @@
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* IBM Corporation * IBM Corporation
* Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.c; package org.eclipse.cdt.internal.core.pdom.dom.c;
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.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IFunction;
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.gnu.c.ICASTKnRFunctionDeclarator;
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.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;
/** /**
@ -30,26 +37,65 @@ import org.eclipse.core.runtime.CoreException;
* *
*/ */
class PDOMCFunction extends PDOMBinding implements IFunction { class PDOMCFunction extends PDOMBinding implements IFunction {
/**
* Offset of total number of function parameters (relative to the
* beginning of the record).
*/
public static final int NUM_PARAMS = PDOMBinding.RECORD_SIZE + 0;
/**
* Offset of total number of function parameters (relative to the
* beginning of the record).
*/
public static final int FIRST_PARAM = PDOMBinding.RECORD_SIZE + 4;
/** /**
* Offset of annotation information (relative to the beginning of the * Offset of annotation information (relative to the beginning of the
* record). * record).
*/ */
private static final int ANNOTATIONS = PDOMBinding.RECORD_SIZE + 0; // byte private static final int ANNOTATIONS = PDOMBinding.RECORD_SIZE + 8; // byte
/** /**
* The size in bytes of a PDOMCFunction record in the database. * The size in bytes of a PDOMCPPFunction record in the database.
*/ */
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 1; public static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 9;
public PDOMCFunction(PDOM pdom, PDOMNode parent, IASTName name) throws CoreException { public PDOMCFunction(PDOM pdom, PDOMNode parent, IASTName name) throws CoreException {
super(pdom, parent, name); super(pdom, parent, name);
try { try {
IASTNode parentNode = name.getParent();
if (parentNode instanceof IASTStandardFunctionDeclarator) {
IASTStandardFunctionDeclarator funcDecl = (IASTStandardFunctionDeclarator)parentNode;
IASTParameterDeclaration[] params = funcDecl.getParameters();
pdom.getDB().putInt(record + NUM_PARAMS, params.length);
for (int i = 0; i < params.length; ++i) {
IASTParameterDeclaration param = params[i];
IASTName paramName = param.getDeclarator().getName();
IBinding binding = paramName.resolveBinding();
IParameter paramBinding = (IParameter)binding;
setFirstParameter(new PDOMCParameter(pdom, this, paramName, paramBinding));
}
} else if(parentNode instanceof ICASTKnRFunctionDeclarator) {
fail(); // aftodo
}
pdom.getDB().putByte(record + ANNOTATIONS, PDOMCAnnotation.encodeAnnotation(name.resolveBinding())); pdom.getDB().putByte(record + ANNOTATIONS, PDOMCAnnotation.encodeAnnotation(name.resolveBinding()));
} catch (DOMException e) { } catch(DOMException e) {
throw new CoreException(Util.createStatus(e)); throw new CoreException(Util.createStatus(e));
} }
} }
public PDOMCParameter getFirstParameter() throws CoreException {
int rec = pdom.getDB().getInt(record + FIRST_PARAM);
return rec != 0 ? new PDOMCParameter(pdom, rec) : null;
}
public void setFirstParameter(PDOMCParameter param) throws CoreException {
if (param != null)
param.setNextParameter(getFirstParameter());
int rec = param != null ? param.getRecord() : 0;
pdom.getDB().putInt(record + FIRST_PARAM, rec);
}
public PDOMCFunction(PDOM pdom, int record) { public PDOMCFunction(PDOM pdom, int record) {
super(pdom, record); super(pdom, record);
} }
@ -62,16 +108,26 @@ class PDOMCFunction extends PDOMBinding implements IFunction {
return PDOMCLinkage.CFUNCTION; return PDOMCLinkage.CFUNCTION;
} }
public IParameter[] getParameters() throws DOMException {
throw new PDOMNotImplementedError();
}
public IScope getFunctionScope() throws DOMException {
throw new PDOMNotImplementedError();
}
public IFunctionType getType() throws DOMException { public IFunctionType getType() throws DOMException {
throw new PDOMNotImplementedError(); /*
* CVisitor binding resolution assumes any IBinding which is
* also an IType should be converted to a IProblemBinding in a
* route through the code that triggers errors here. This means
* we can't use the convenient idea of having PDOMCFunction implement
* both the IType and IBinding subinterfaces.
*/
return new IFunctionType() {
public Object clone() { fail(); return null; }
public IType[] getParameterTypes() throws DOMException {
return PDOMCFunction.this.getParameterTypes();
}
public IType getReturnType() throws DOMException {
return PDOMCFunction.this.getReturnType();
}
public boolean isSameType(IType type) {
return PDOMCFunction.this.isSameType(type);
}
};
} }
public boolean isStatic() throws DOMException { public boolean isStatic() throws DOMException {
@ -82,6 +138,38 @@ class PDOMCFunction extends PDOMBinding implements IFunction {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.EXTERN_OFFSET); return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.EXTERN_OFFSET);
} }
public IParameter[] getParameters() throws DOMException {
try {
int n = pdom.getDB().getInt(record + NUM_PARAMS);
IParameter[] params = new IParameter[n];
PDOMCParameter param = getFirstParameter();
while (param != null) {
params[--n] = param;
param = param.getNextParameter();
}
return params;
} catch (CoreException e) {
CCorePlugin.log(e);
return new IParameter[0];
}
}
public IType[] getParameterTypes() throws DOMException {
try {
int n = pdom.getDB().getInt(record + NUM_PARAMS);
IType[] types = new IType[n];
PDOMCParameter param = getFirstParameter();
while (param != null) {
types[--n] = param.getType();
param = param.getNextParameter();
}
return types;
} catch (CoreException e) {
CCorePlugin.log(e);
return new IType[0];
}
}
public boolean isAuto() throws DOMException { public boolean isAuto() throws DOMException {
// ISO/IEC 9899:TC1 6.9.1.4 // ISO/IEC 9899:TC1 6.9.1.4
return false; return false;
@ -100,4 +188,8 @@ class PDOMCFunction extends PDOMBinding implements IFunction {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.VARARGS_OFFSET); return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.VARARGS_OFFSET);
} }
public IScope getFunctionScope() throws DOMException {fail(); return null;}
public IType getReturnType() throws DOMException {fail();return null;}
public boolean isSameType(IType type) {fail(); return false;}
public Object clone() {fail(); return null;}
} }

View file

@ -9,12 +9,11 @@
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* IBM Corporation * IBM Corporation
* Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.c; package org.eclipse.cdt.internal.core.pdom.dom.c;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
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;
@ -32,16 +31,20 @@ 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.IVariable; import org.eclipse.cdt.core.dom.ast.IVariable;
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.ICBasicType;
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage; import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.bid.IBindingIdentityFactory;
import org.eclipse.cdt.internal.core.dom.bid.ILocalBindingIdentity;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.FindBindingByLinkageConstant;
import org.eclipse.cdt.internal.core.pdom.dom.FindEquivalentBinding;
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.PDOMFile; import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
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.PDOMNamedNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
@ -59,6 +62,10 @@ class PDOMCLinkage extends PDOMLinkage {
super(pdom, C_LINKAGE_ID, C_LINKAGE_ID.toCharArray()); super(pdom, C_LINKAGE_ID, C_LINKAGE_ID.toCharArray());
} }
public int getNodeType() {
return LINKAGE;
}
public String getID() { public String getID() {
return C_LINKAGE_ID; return C_LINKAGE_ID;
} }
@ -70,11 +77,15 @@ class PDOMCLinkage extends PDOMLinkage {
public static final int CENUMERATION = PDOMLinkage.LAST_NODE_TYPE + 5; public static final int CENUMERATION = PDOMLinkage.LAST_NODE_TYPE + 5;
public static final int CENUMERATOR = PDOMLinkage.LAST_NODE_TYPE + 6; public static final int CENUMERATOR = PDOMLinkage.LAST_NODE_TYPE + 6;
public static final int CTYPEDEF = PDOMLinkage.LAST_NODE_TYPE + 7; public static final int CTYPEDEF = PDOMLinkage.LAST_NODE_TYPE + 7;
public static final int CPARAMETER = PDOMLinkage.LAST_NODE_TYPE + 8;
public static final int CBASICTYPE = PDOMLinkage.LAST_NODE_TYPE + 9;
public ILanguage getLanguage() { public ILanguage getLanguage() {
return new GCCLanguage(); return new GCCLanguage();
} }
public PDOMBinding addName(IASTName name, PDOMFile file) throws CoreException { public PDOMBinding addName(IASTName name, PDOMFile file) throws CoreException {
if (name == null) if (name == null)
return null; return null;
@ -123,6 +134,8 @@ class PDOMCLinkage extends PDOMLinkage {
} }
} else if (binding instanceof ITypedef) } else if (binding instanceof ITypedef)
pdomBinding = new PDOMCTypedef(pdom, parent, name, (ITypedef)binding); pdomBinding = new PDOMCTypedef(pdom, parent, name, (ITypedef)binding);
parent.addChild(pdomBinding);
} }
if (pdomBinding != null) if (pdomBinding != null)
@ -131,61 +144,6 @@ class PDOMCLinkage extends PDOMLinkage {
return pdomBinding; return pdomBinding;
} }
private static final class FindBinding extends PDOMNamedNode.NodeFinder {
PDOMBinding pdomBinding;
final int desiredType;
public FindBinding(PDOM pdom, char[] name, int desiredType) {
super(pdom, name);
this.desiredType = desiredType;
}
public boolean visit(int record) throws CoreException {
if (record == 0)
return true;
PDOMBinding tBinding = pdom.getBinding(record);
if (!tBinding.hasName(name))
// no more bindings with our desired name
return false;
if (tBinding.getNodeType() != desiredType)
// wrong type, try again
return true;
// got it
pdomBinding = tBinding;
return false;
}
}
private static class FindBinding2 implements IPDOMVisitor {
private PDOMBinding binding;
private final char[] name;
private final int[] desiredType;
public FindBinding2(char[] name, int desiredType) {
this(name, new int[] { desiredType });
}
public FindBinding2(char[] name, int[] desiredType) {
this.name = name;
this.desiredType = desiredType;
}
public boolean visit(IPDOMNode node) throws CoreException {
if (node instanceof PDOMBinding) {
PDOMBinding tBinding = (PDOMBinding)node;
if (tBinding.hasName(name)) {
int nodeType = tBinding.getNodeType();
for (int i = 0; i < desiredType.length; ++i)
if (nodeType == desiredType[i]) {
// got it
binding = tBinding;
throw new CoreException(Status.OK_STATUS);
}
}
}
return false;
}
public void leave(IPDOMNode node) throws CoreException {
}
public PDOMBinding getBinding() { return binding; }
}
protected int getBindingType(IBinding binding) { protected int getBindingType(IBinding binding) {
if (binding instanceof IField) if (binding instanceof IField)
// This needs to be before variable // This needs to be before variable
@ -216,23 +174,25 @@ class PDOMCLinkage extends PDOMLinkage {
// so if the binding is from another pdom it has to be adapted. // so if the binding is from another pdom it has to be adapted.
} }
FindEquivalentBinding visitor = new FindEquivalentBinding(this, binding);
PDOMNode parent = getAdaptedParent(binding); PDOMNode parent = getAdaptedParent(binding);
if (parent == this) { if (parent == this) {
FindBinding visitor = new FindBinding(pdom, binding.getNameCharArray(), getBindingType(binding));
getIndex().accept(visitor); getIndex().accept(visitor);
return visitor.pdomBinding; return visitor.getResult();
} else if (parent instanceof IPDOMMemberOwner) { } else if (parent instanceof IPDOMMemberOwner) {
FindBinding2 visitor = new FindBinding2(binding.getNameCharArray(), getBindingType(binding));
IPDOMMemberOwner owner = (IPDOMMemberOwner)parent; IPDOMMemberOwner owner = (IPDOMMemberOwner)parent;
try { try {
owner.accept(visitor); owner.accept(visitor);
} catch (CoreException e) { } catch (CoreException e) {
if (e.getStatus().equals(Status.OK_STATUS)) if (e.getStatus().equals(Status.OK_STATUS))
return visitor.getBinding(); return visitor.getResult();
else else
throw e; throw e;
} }
} }
return null; return null;
} }
@ -255,36 +215,54 @@ class PDOMCLinkage extends PDOMLinkage {
return new PDOMCEnumerator(pdom, record); return new PDOMCEnumerator(pdom, record);
case CTYPEDEF: case CTYPEDEF:
return new PDOMCTypedef(pdom, record); return new PDOMCTypedef(pdom, record);
case CPARAMETER:
return new PDOMCParameter(pdom, record);
case CBASICTYPE:
return new PDOMCBasicType(pdom, record);
} }
return super.getNode(record); return super.getNode(record);
} }
public PDOMBinding resolveBinding(IASTName name) throws CoreException { public PDOMBinding resolveBinding(IASTName name) throws CoreException {
int constant;
IASTNode parent = name.getParent(); IASTNode parent = name.getParent();
if (parent instanceof IASTIdExpression) { if (parent instanceof IASTIdExpression) { // reference
// reference
IASTNode eParent = parent.getParent(); IASTNode eParent = parent.getParent();
if (eParent instanceof IASTFunctionCallExpression) { if (eParent instanceof IASTFunctionCallExpression) {
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CFUNCTION); constant = CFUNCTION;
getIndex().accept(visitor);
return visitor.pdomBinding;
} else { } else {
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CVARIABLE); constant = CVARIABLE;
getIndex().accept(visitor);
return visitor.pdomBinding;
} }
} else if (parent instanceof ICASTElaboratedTypeSpecifier) { } else if (parent instanceof ICASTElaboratedTypeSpecifier) {
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CSTRUCTURE); constant = CSTRUCTURE;
getIndex().accept(visitor); } else {
return visitor.pdomBinding;
}
return null; return null;
} }
FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant(this, name.toCharArray(), constant);
getIndex().accept(finder);
return finder.getResult();
}
public PDOMNode addType(PDOMNode parent, IType type) throws CoreException { public PDOMNode addType(PDOMNode parent, IType type) throws CoreException {
// TODO Auto-generated method stub if (type instanceof ICBasicType) {
return null; return new PDOMCBasicType(pdom, parent, (ICBasicType)type);
} else if (type instanceof ICompositeType) {
FindEquivalentBinding feb = new FindEquivalentBinding(this,(ICompositeType)type);
getIndex().accept(feb);
if(feb.getResult()!=null) {
return feb.getResult();
}
}
return super.addType(parent, type);
} }
public ILocalBindingIdentity getLocalBindingIdentity(IBinding b) throws CoreException {
return new CBindingIdentity(b, this);
}
public IBindingIdentityFactory getBindingIdentityFactory() {
return this;
}
} }

View file

@ -0,0 +1,135 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.c;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.internal.core.Util;
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.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException;
/**
* A parameter to a function or a method
*
* @author Doug Schaefer
*/
class PDOMCParameter extends PDOMNamedNode implements IParameter {
private static final int NEXT_PARAM = PDOMNamedNode.RECORD_SIZE + 0;
private static final int TYPE = PDOMNamedNode.RECORD_SIZE + 4;
public static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 8;
public PDOMCParameter(PDOM pdom, int record) {
super(pdom, record);
}
public PDOMCParameter(PDOM pdom, PDOMNode parent, IASTName name, IParameter param)
throws CoreException {
super(pdom, parent, name.toCharArray());
Database db = pdom.getDB();
db.putInt(record + NEXT_PARAM, 0);
try {
IType type = param.getType();
if (type != null) {
PDOMNode typeNode = getLinkageImpl().addType(this, type);
db.putInt(record + TYPE, typeNode != null ? typeNode.getRecord() : 0);
}
} catch(DOMException e) {
throw new CoreException(Util.createStatus(e));
}
}
protected int getRecordSize() {
return RECORD_SIZE;
}
public int getNodeType() {
return PDOMCLinkage.CPARAMETER;
}
public void setNextParameter(PDOMCParameter nextParam) throws CoreException {
int rec = nextParam != null ? nextParam.getRecord() : 0;
pdom.getDB().putInt(record + NEXT_PARAM, rec);
}
public PDOMCParameter getNextParameter() throws CoreException {
int rec = pdom.getDB().getInt(record + NEXT_PARAM);
return rec != 0 ? new PDOMCParameter(pdom, rec) : null;
}
public IASTInitializer getDefaultValue() {
return null;
// TODO throw new PDOMNotImplementedError();
}
public IType getType() throws DOMException {
try {
PDOMLinkage linkage = getLinkageImpl();
PDOMNode node = linkage.getNode(pdom.getDB().getInt(record + TYPE));
return node instanceof IType ? (IType)node : null;
} catch (CoreException e) {
CCorePlugin.log(e);
return null;
}
}
public boolean isAuto() throws DOMException {
throw new PDOMNotImplementedError();
}
public boolean isExtern() throws DOMException {
throw new PDOMNotImplementedError();
}
public boolean isRegister() throws DOMException {
throw new PDOMNotImplementedError();
}
public boolean isStatic() throws DOMException {
throw new PDOMNotImplementedError();
}
public String getName() {
return new String(getNameCharArray());
}
public IScope getScope() throws DOMException {
throw new PDOMNotImplementedError();
}
public Object getAdapter(Class adapter) {
throw new PDOMNotImplementedError();
}
public char[] getNameCharArray() {
try {
return super.getNameCharArray();
} catch (CoreException e) {
CCorePlugin.log(e);
return new char[0];
}
}
}

View file

@ -8,6 +8,7 @@
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.c; package org.eclipse.cdt.internal.core.pdom.dom.c;
@ -28,7 +29,6 @@ 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;
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.PDOMNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -149,6 +149,10 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, IPDOM
return RECORD_SIZE; return RECORD_SIZE;
} }
public void addChild(PDOMNode member) throws CoreException {
addMember(member);
}
public boolean mayHaveChildren() { public boolean mayHaveChildren() {
return true; return true;
} }

View file

@ -0,0 +1,112 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software 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:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.bid.AbstractCLocalBindingIdentity;
import org.eclipse.cdt.internal.core.dom.bid.ICLocalBindingIdentity;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.core.runtime.CoreException;
public class CPPBindingIdentity extends AbstractCLocalBindingIdentity {
public CPPBindingIdentity(IBinding binding, PDOMLinkage linkage) {
super(binding, linkage);
}
public int getTypeConstant() throws CoreException {
if(binding instanceof PDOMBinding) {
return ((PDOMBinding) binding).getNodeType();
} else {
return ((PDOMCPPLinkage)linkage).getBindingType(binding);
}
}
public String getExtendedType() throws CoreException {
try {
if(binding instanceof ICPPFunction) {
return renderFunctionType(((ICPPFunction)binding).getType());
} else if(binding instanceof ICPPMethod) {
return renderFunctionType(((ICPPMethod)binding).getType());
} else {
return ""; //$NON-NLS-1$
}
} catch(DOMException e) {
throw new CoreException(Util.createStatus(e));
}
}
protected static String renderTypes(IType[] types) throws DOMException {
if(types.length==1) {
if(types[0] instanceof IBasicType) {
if(((IBasicType)types[0]).getType()==IBasicType.t_void) {
types = new IType[0];
}
}
}
StringBuffer result = new StringBuffer();
result.append('(');
for(int i=0; i<types.length; i++) {
if (i>0) {
result.append(',');
}
result.append(ASTTypeUtil.getType(types[i]));
}
result.append(')');
return result.toString();
}
private String renderFunctionType(IFunctionType type) throws DOMException {
IType[] params = type.getParameterTypes();
return renderTypes(params);
}
public static class Holder implements ICLocalBindingIdentity {
String name;
int type;
String mangledExtendedType;
public Holder(String name, int type, IType[] types) throws DOMException {
this.name = name;
this.type = type;
mangledExtendedType = renderTypes(types);
}
public int getTypeConstant() throws CoreException {
return type;
}
public String getName() throws CoreException {
return name;
}
public String getExtendedType() throws CoreException {
return mangledExtendedType;
}
public String toString() {
return name+" "+type+" "+mangledExtendedType;
}
public char[] getNameCharArray() throws CoreException {
return name.toCharArray();
}
}
}

View file

@ -23,6 +23,7 @@ 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.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
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;
@ -42,13 +43,15 @@ 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.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.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/** /**
* @author Doug Schaefer * @author Doug Schaefer
* *
*/ */
/*
* aftodo - contract get Methods/Fields not honoured?
*/
class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
ICPPClassScope, IPDOMMemberOwner { ICPPClassScope, IPDOMMemberOwner {
@ -74,15 +77,15 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
// linked list is initialized by storage being zero'd by malloc // linked list is initialized by storage being zero'd by malloc
} }
public PDOMCPPClassType(PDOM pdom, int bindingRecord) {
super(pdom, bindingRecord);
}
public void addMember(PDOMNode member) throws CoreException { public void addMember(PDOMNode member) throws CoreException {
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl()); PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl());
list.addMember(member); list.addMember(member);
} }
public PDOMCPPClassType(PDOM pdom, int bindingRecord) {
super(pdom, bindingRecord);
}
protected int getRecordSize() { protected int getRecordSize() {
return RECORD_SIZE; return RECORD_SIZE;
} }
@ -115,14 +118,6 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
return false; return false;
} }
public Object clone() {
throw new PDOMNotImplementedError();
}
public IField findField(String name) throws DOMException {
throw new PDOMNotImplementedError();
}
public ICPPBase[] getBases() throws DOMException { public ICPPBase[] getBases() throws DOMException {
try { try {
List list = new ArrayList(); List list = new ArrayList();
@ -143,15 +138,6 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
list.accept(visitor); list.accept(visitor);
} }
public ICPPConstructor[] getConstructors() throws DOMException {
// TODO
return new ICPPConstructor[0];
}
public ICPPField[] getDeclaredFields() throws DOMException {
throw new PDOMNotImplementedError();
}
private static class GetMethods implements IPDOMVisitor { private static class GetMethods implements IPDOMVisitor {
private final List methods; private final List methods;
public GetMethods(List methods) { public GetMethods(List methods) {
@ -245,9 +231,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
} }
} }
public IBinding[] getFriends() throws DOMException {
throw new PDOMNotImplementedError();
}
private static class GetNestedClasses implements IPDOMVisitor { private static class GetNestedClasses implements IPDOMVisitor {
private List nestedClasses = new ArrayList(); private List nestedClasses = new ArrayList();
@ -299,31 +283,11 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
return this; return this;
} }
public ICPPMethod[] getImplicitMethods() {
throw new PDOMNotImplementedError();
}
public void addBinding(IBinding binding) throws DOMException {
throw new PDOMNotImplementedError();
}
public void addName(IASTName name) throws DOMException { public void addName(IASTName name) throws DOMException {
// TODO - this might be a better way of adding names to scopes // TODO - this might be a better way of adding names to scopes
// but for now do nothing. // but for now do nothing.
} }
public IBinding[] find(String name) throws DOMException {
throw new PDOMNotImplementedError();
}
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
return null;
}
public IScope getParent() throws DOMException {
return null;
}
public IName getScopeName() throws DOMException { public IName getScopeName() throws DOMException {
try { try {
PDOMName name = getFirstDefinition(); PDOMName name = getFirstDefinition();
@ -336,8 +300,44 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
} }
} }
public void removeBinding(IBinding binding) throws DOMException { public void addChild(PDOMNode member) throws CoreException {addMember(member);}
throw new PDOMNotImplementedError();
public ICPPConstructor[] getConstructors() throws DOMException {
// TODO
return new ICPPConstructor[0];
}
public boolean isFullyCached() throws DOMException {return true;}
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
return null;
}
public IScope getParent() throws DOMException {
return null;
}
// Not implemented
public Object clone() {fail();return null;}
public IField findField(String name) throws DOMException {fail();return null;}
public IBinding[] getFriends() throws DOMException {fail();return null;}
public ICPPMethod[] getImplicitMethods() {fail(); return null;}
public void addBinding(IBinding binding) throws DOMException {fail();}
public IBinding[] find(String name) throws DOMException {fail();return null;}
public void flushCache() throws DOMException {fail();}
public ICPPField[] getDeclaredFields() throws DOMException {fail();return null;}
public void removeBinding(IBinding binding) throws DOMException {fail();}
public void setFullyCached(boolean b) throws DOMException {fail();}
public IASTNode getPhysicalNode() throws DOMException {fail();return null;}
public IScope getScope() throws DOMException {
try {
return (IScope)getParentNode();
} catch(CoreException ce) {
CCorePlugin.log(ce);
return null;
}
} }
public boolean mayHaveChildren() { public boolean mayHaveChildren() {

View file

@ -8,15 +8,17 @@
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp; package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
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.IASTLiteralExpression;
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.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -29,7 +31,9 @@ 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.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.ICPPASTNamespaceAlias;
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.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
@ -44,15 +48,19 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBas
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.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.bid.IBindingIdentityFactory;
import org.eclipse.cdt.internal.core.dom.bid.ILocalBindingIdentity;
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.CPPImplicitMethod;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.FindBindingByLinkageConstant;
import org.eclipse.cdt.internal.core.pdom.dom.FindEquivalentBinding;
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.PDOMFile; import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
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.PDOMNamedNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
@ -62,13 +70,11 @@ import org.eclipse.core.runtime.Status;
* *
*/ */
class PDOMCPPLinkage extends PDOMLinkage { class PDOMCPPLinkage extends PDOMLinkage {
public PDOMCPPLinkage(PDOM pdom, int record) { public PDOMCPPLinkage(PDOM pdom, int record) {
super(pdom, record); super(pdom, record);
} }
public PDOMCPPLinkage(PDOM pdom) public PDOMCPPLinkage(PDOM pdom) throws CoreException {
throws CoreException {
super(pdom, CPP_LINKAGE_ID, CPP_LINKAGE_ID.toCharArray()); super(pdom, CPP_LINKAGE_ID, CPP_LINKAGE_ID.toCharArray());
} }
@ -80,6 +86,10 @@ class PDOMCPPLinkage extends PDOMLinkage {
return RECORD_SIZE; return RECORD_SIZE;
} }
public int getNodeType() {
return LINKAGE;
}
// Binding types // Binding types
public static final int CPPVARIABLE = PDOMLinkage.LAST_NODE_TYPE + 1; public static final int CPPVARIABLE = PDOMLinkage.LAST_NODE_TYPE + 1;
public static final int CPPFUNCTION = PDOMLinkage.LAST_NODE_TYPE + 2; public static final int CPPFUNCTION = PDOMLinkage.LAST_NODE_TYPE + 2;
@ -98,6 +108,7 @@ class PDOMCPPLinkage extends PDOMLinkage {
return new GPPLanguage(); return new GPPLanguage();
} }
public PDOMBinding addName(IASTName name, PDOMFile file) throws CoreException { public PDOMBinding addName(IASTName name, PDOMFile file) throws CoreException {
if (name == null || name instanceof ICPPASTQualifiedName) if (name == null || name instanceof ICPPASTQualifiedName)
return null; return null;
@ -107,7 +118,9 @@ class PDOMCPPLinkage extends PDOMLinkage {
if (namechars == null || namechars.length == 0) if (namechars == null || namechars.length == 0)
return null; return null;
IBinding binding = name.resolveBinding(); IBinding binding = name.resolveBinding();
if (binding == null || binding instanceof IProblemBinding) if (binding == null || binding instanceof IProblemBinding)
// Can't tell what it is // Can't tell what it is
return null; return null;
@ -128,6 +141,11 @@ class PDOMCPPLinkage extends PDOMLinkage {
pdomBinding = new PDOMCPPVariable(pdom, parent, name); pdomBinding = new PDOMCPPVariable(pdom, parent, name);
} else if (binding instanceof ICPPMethod && parent instanceof PDOMCPPClassType) { } else if (binding instanceof ICPPMethod && parent instanceof PDOMCPPClassType) {
pdomBinding = new PDOMCPPMethod(pdom, parent, name); pdomBinding = new PDOMCPPMethod(pdom, parent, name);
} 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, name);
} else if (binding instanceof CPPImplicitMethod && parent instanceof PDOMCPPClassType) { } else if (binding instanceof CPPImplicitMethod && parent instanceof PDOMCPPClassType) {
if(!name.isReference()) { if(!name.isReference()) {
//because we got the implicit method off of an IASTName that is not a reference, //because we got the implicit method off of an IASTName that is not a reference,
@ -153,9 +171,29 @@ class PDOMCPPLinkage extends PDOMLinkage {
} else if (binding instanceof ITypedef) { } else if (binding instanceof ITypedef) {
pdomBinding = new PDOMCPPTypedef(pdom, parent, name, (ITypedef)binding); pdomBinding = new PDOMCPPTypedef(pdom, parent, name, (ITypedef)binding);
} }
} else if (binding instanceof ICPPFunction) {
pdomBinding = new PDOMCPPFunction(pdom, parent, name);
} else if (binding instanceof ICPPClassType) {
pdomBinding = new PDOMCPPClassType(pdom, parent, name);
} else if (binding instanceof ICPPNamespaceAlias) {
pdomBinding = new PDOMCPPNamespaceAlias(pdom, parent, name);
} else if (binding instanceof ICPPNamespace) {
pdomBinding = new PDOMCPPNamespace(pdom, parent, name);
} else if (binding instanceof IEnumeration) {
pdomBinding = new PDOMCPPEnumeration(pdom, parent, name);
} else if (binding instanceof IEnumerator) {
IEnumeration enumeration = (IEnumeration)((IEnumerator)binding).getType();
PDOMBinding pdomEnumeration = adaptBinding(enumeration);
if (pdomEnumeration instanceof PDOMCPPEnumeration)
pdomBinding = new PDOMCPPEnumerator(pdom, parent, name,
(PDOMCPPEnumeration)pdomEnumeration);
} else if (binding instanceof ITypedef) {
pdomBinding = new PDOMCPPTypedef(pdom, parent, name, (ITypedef)binding);
}
parent.addChild(pdomBinding);
} }
} }
} catch (DOMException e) { } catch(DOMException e) {
throw new CoreException(Util.createStatus(e)); throw new CoreException(Util.createStatus(e));
} }
@ -181,67 +219,6 @@ class PDOMCPPLinkage extends PDOMLinkage {
return pdomBinding; return pdomBinding;
} }
private static final class FindBinding extends PDOMNamedNode.NodeFinder {
PDOMBinding pdomBinding;
final int[] desiredType;
public FindBinding(PDOM pdom, char[] name, int desiredType) {
this(pdom, name, new int[] { desiredType });
}
public FindBinding(PDOM pdom, char[] name, int[] desiredType) {
super(pdom, name);
this.desiredType = desiredType;
}
public boolean visit(int record) throws CoreException {
if (record == 0)
return true;
PDOMBinding tBinding = pdom.getBinding(record);
if (!tBinding.hasName(name))
// no more bindings with our desired name
return false;
int nodeType = tBinding.getNodeType();
for (int i = 0; i < desiredType.length; ++i)
if (nodeType == desiredType[i]) {
// got it
pdomBinding = tBinding;
return false;
}
// wrong type, try again
return true;
}
}
private static class FindBinding2 implements IPDOMVisitor {
private PDOMBinding binding;
private final char[] name;
private final int[] desiredType;
public FindBinding2(char[] name, int desiredType) {
this(name, new int[] { desiredType });
}
public FindBinding2(char[] name, int[] desiredType) {
this.name = name;
this.desiredType = desiredType;
}
public boolean visit(IPDOMNode node) throws CoreException {
if (node instanceof PDOMBinding) {
PDOMBinding tBinding = (PDOMBinding)node;
if (tBinding.hasName(name)) {
int nodeType = tBinding.getNodeType();
for (int i = 0; i < desiredType.length; ++i)
if (nodeType == desiredType[i]) {
// got it
binding = tBinding;
throw new CoreException(Status.OK_STATUS);
}
}
}
return false;
}
public void leave(IPDOMNode node) throws CoreException {
}
public PDOMBinding getBinding() { return binding; }
}
protected int getBindingType(IBinding binding) { protected int getBindingType(IBinding binding) {
if (binding instanceof ICPPTemplateDefinition) if (binding instanceof ICPPTemplateDefinition)
// this must be before class type // this must be before class type
@ -272,6 +249,9 @@ class PDOMCPPLinkage extends PDOMLinkage {
return 0; return 0;
} }
/**
* Find the equivalent binding, or binding placeholder within this PDOM
*/
public PDOMBinding adaptBinding(IBinding binding) throws CoreException { public PDOMBinding adaptBinding(IBinding binding) throws CoreException {
if (binding == null || binding instanceof IProblemBinding) if (binding == null || binding instanceof IProblemBinding)
return null; return null;
@ -285,48 +265,54 @@ class PDOMCPPLinkage extends PDOMLinkage {
// so if the binding is from another pdom it has to be adapted. // so if the binding is from another pdom it has to be adapted.
} }
FindEquivalentBinding visitor = new FindEquivalentBinding(this, binding);
PDOMNode parent = getAdaptedParent(binding); PDOMNode parent = getAdaptedParent(binding);
if (parent == this) { if (parent == this) {
FindBinding visitor = new FindBinding(pdom, binding.getNameCharArray(), getBindingType(binding));
getIndex().accept(visitor); getIndex().accept(visitor);
return visitor.pdomBinding; return visitor.getResult();
} else if (parent instanceof IPDOMMemberOwner) { } else if (parent instanceof IPDOMMemberOwner) {
FindBinding2 visitor = new FindBinding2(binding.getNameCharArray(), getBindingType(binding));
IPDOMMemberOwner owner = (IPDOMMemberOwner)parent; IPDOMMemberOwner owner = (IPDOMMemberOwner)parent;
try { try {
owner.accept(visitor); owner.accept(visitor);
} catch (CoreException e) { } catch (CoreException e) {
if (e.getStatus().equals(Status.OK_STATUS)) if (e.getStatus().equals(Status.OK_STATUS))
return visitor.getBinding(); return visitor.getResult();
else else
throw e; throw e;
} }
} else if (parent instanceof PDOMCPPNamespace) { } else if (parent instanceof PDOMCPPNamespace) {
FindBinding visitor = new FindBinding(pdom, binding.getNameCharArray(), getBindingType(binding));
((PDOMCPPNamespace)parent).getIndex().accept(visitor); ((PDOMCPPNamespace)parent).getIndex().accept(visitor);
return visitor.pdomBinding; return visitor.getResult();
} }
return null; return null;
} }
public PDOMBinding resolveBinding(IASTName name) throws CoreException { public PDOMBinding resolveBinding(IASTName name) throws CoreException {
try {
return _resolveBinding(name);
} catch(DOMException e) {
throw new CoreException(Util.createStatus(e));
}
}
private PDOMBinding _resolveBinding(IASTName name) throws CoreException, DOMException {
// mstodo revisit // mstodo revisit
IBinding origBinding = name.getBinding(); IBinding origBinding = name.getBinding();
if (origBinding != null) if (origBinding != null)
return adaptBinding(origBinding); return adaptBinding(origBinding);
if (name instanceof ICPPASTQualifiedName) { if (name instanceof ICPPASTQualifiedName) {
IASTName[] names = ((ICPPASTQualifiedName)name).getNames(); IASTName[] names = ((ICPPASTQualifiedName)name).getNames();
if (names.length == 1) if (names.length == 1)
return resolveBinding(names[0]); return resolveBinding(names[0]);
IASTName lastName = names[names.length - 1]; IASTName lastName = names[names.length - 1];
PDOMBinding nsBinding = adaptBinding(names[names.length - 2].resolveBinding()); PDOMBinding nsBinding = adaptBinding(names[names.length - 2].resolveBinding());
try {
if (nsBinding instanceof IScope) { if (nsBinding instanceof IScope) {
return (PDOMBinding) ((IScope)nsBinding).getBinding(lastName, true); return (PDOMBinding) ((IScope)nsBinding).getBinding(lastName, true);
} }
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
} }
IASTNode parent = name.getParent(); IASTNode parent = name.getParent();
if (parent instanceof ICPPASTQualifiedName) { if (parent instanceof ICPPASTQualifiedName) {
@ -345,25 +331,109 @@ class PDOMCPPLinkage extends PDOMLinkage {
// reference // reference
IASTNode eParent = parent.getParent(); IASTNode eParent = parent.getParent();
if (eParent instanceof IASTFunctionCallExpression) { if (eParent instanceof IASTFunctionCallExpression) {
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CPPFUNCTION); return resolveFunctionCall((IASTIdExpression)parent, name, (IASTFunctionCallExpression) eParent);
getIndex().accept(visitor);
return visitor.pdomBinding;
} else { } else {
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), int constant = (name.getParent() instanceof ICPPASTQualifiedName
(name.getParent() instanceof ICPPASTQualifiedName
&& ((ICPPASTQualifiedName)name.getParent()).getLastName() != name) && ((ICPPASTQualifiedName)name.getParent()).getLastName() != name)
? CPPNAMESPACE : CPPVARIABLE); ? CPPNAMESPACE : CPPVARIABLE;
getIndex().accept(visitor); FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant(this, name.toCharArray(), constant);
return visitor.pdomBinding; getIndex().accept(finder);
return finder.getResult();
} }
} else if (parent instanceof IASTNamedTypeSpecifier) { } else if (parent instanceof IASTNamedTypeSpecifier) {
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CPPCLASSTYPE); FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CPPCLASSTYPE);
getIndex().accept(visitor); getIndex().accept(finder);
return visitor.pdomBinding; PDOMBinding result = finder.getResult();
return result;
} else if (parent instanceof ICPPASTNamespaceAlias) { } else if (parent instanceof ICPPASTNamespaceAlias) {
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CPPNAMESPACE); FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CPPNAMESPACE);
getIndex().accept(visitor); getIndex().accept(finder);
return visitor.pdomBinding; return finder.getResult();
} else if(parent instanceof ICPPASTFieldReference) {
ICPPASTFieldReference ref = (ICPPASTFieldReference) parent;
IASTExpression exp = ref.getFieldOwner();
if(exp instanceof IASTIdExpression) {
IASTIdExpression id = (IASTIdExpression) exp;
IASTNode eParent = parent.getParent();
if (eParent instanceof IASTFunctionCallExpression) {
IASTFunctionCallExpression exp2 = (IASTFunctionCallExpression) eParent;
return resolveFunctionCall(id, name, exp2);
}
}
}
return null;
}
public IType[] getTypes(IASTExpression paramExp) {
IType[] types;
if(paramExp==null) {
types = new IType[0];
} else {
if(paramExp instanceof IASTExpressionList) {
IASTExpressionList list = (IASTExpressionList) paramExp;
IASTExpression[] paramExps = list.getExpressions();
types = new IType[paramExps.length];
for(int i=0; i<paramExps.length; i++) {
types[i] = paramExps[i].getExpressionType();
}
} else if(paramExp instanceof IASTLiteralExpression) {
IASTLiteralExpression litExp = (IASTLiteralExpression) paramExp;
types = new IType[] {litExp.getExpressionType()};
} else if(paramExp instanceof ICPPASTNewExpression) {
ICPPASTNewExpression exp3 = (ICPPASTNewExpression) paramExp;
IType type = exp3.getExpressionType();
types = new IType[] {new CPPPointerType(type)};
} else {
types = new IType[]{paramExp.getExpressionType()};
}
}
return types;
}
/*
* aftodo - I'm not confident I'm going through the correct AST routes here
*
* (It does work though)
*/
public PDOMBinding resolveFunctionCall(IASTIdExpression id, IASTName name, IASTFunctionCallExpression exp2)
throws CoreException, DOMException {
IASTExpression paramExp = exp2.getParameterExpression();
ILocalBindingIdentity bid = null;
IType[] types = getTypes(paramExp);
IBinding parentBinding = id.getName().getBinding();
if(parentBinding == null) {
bid = new CPPBindingIdentity.Holder(
new String(name.toCharArray()),
CPPFUNCTION,
types);
FindEquivalentBinding feb = new FindEquivalentBinding(this, bid);
getIndex().accept(feb);
return feb.getResult();
} else if(parentBinding instanceof ICPPVariable) {
ICPPVariable v = (ICPPVariable) parentBinding;
IType type = v.getType();
if(type instanceof PDOMBinding) {
bid = new CPPBindingIdentity.Holder(
new String(name.toCharArray()),
CPPMETHOD,
types);
FindEquivalentBinding feb = new FindEquivalentBinding(this, bid);
try {
((PDOMBinding)type).accept(feb);
} catch (CoreException e) {
if (e.getStatus().equals(Status.OK_STATUS)) {
return feb.getResult();
}
else {
throw e;
}
}
}
} }
return null; return null;
@ -387,10 +457,14 @@ class PDOMCPPLinkage extends PDOMLinkage {
if (nsName == null) { if (nsName == null) {
// we are at the root // we are at the root
FindBinding visitor = new FindBinding(pdom, name.toCharArray(),
new int[] { CPPNAMESPACE, CPPCLASSTYPE }); FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CPPNAMESPACE);
getIndex().accept(visitor); getIndex().accept(finder);
return visitor.pdomBinding; if(finder.getResult()==null) {
finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CPPCLASSTYPE);
getIndex().accept(finder);
}
return finder.getResult();
} else { } else {
// TODO we are in another namespace // TODO we are in another namespace
return null; return null;
@ -398,9 +472,15 @@ class PDOMCPPLinkage extends PDOMLinkage {
} }
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);
else } else if (type instanceof ICPPClassType) {
FindEquivalentBinding feb = new FindEquivalentBinding(this,(ICPPClassType)type);
getIndex().accept(feb);
if(feb.getResult()!=null) {
return feb.getResult();
}
}
return super.addType(parent, type); return super.addType(parent, type);
} }
@ -436,4 +516,11 @@ class PDOMCPPLinkage extends PDOMLinkage {
} }
} }
public ILocalBindingIdentity getLocalBindingIdentity(IBinding b) throws CoreException {
return new CPPBindingIdentity(b, this);
}
public IBindingIdentityFactory getBindingIdentityFactory() {
return this;
}
} }

View file

@ -8,6 +8,7 @@
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* IBM Corporation * IBM Corporation
* Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp; package org.eclipse.cdt.internal.core.pdom.dom.cpp;
@ -210,8 +211,19 @@ class PDOMCPPMethod extends PDOMCPPBinding implements ICPPMethod, ICPPFunctionTy
} }
public IType[] getParameterTypes() throws DOMException { public IType[] getParameterTypes() throws DOMException {
try {
int n = pdom.getDB().getInt(record + NUM_PARAMS);
IType[] types = new IType[n];
PDOMCPPParameter param = getFirstParameter();
while (param != null) {
types[--n] = param.getType();
param = param.getNextParameter();
}
return types;
} catch (CoreException e) {
CCorePlugin.log(e);
return new IType[0]; return new IType[0];
// TODO throw new PDOMNotImplementedError(); }
} }
public IType getReturnType() throws DOMException { public IType getReturnType() throws DOMException {
@ -236,4 +248,12 @@ class PDOMCPPMethod extends PDOMCPPBinding implements ICPPMethod, ICPPFunctionTy
return false; return false;
} }
public IScope getScope() throws DOMException {
try {
return (IScope)getParentNode();
} catch(CoreException ce) {
CCorePlugin.log(ce);
return null;
}
}
} }

View file

@ -8,6 +8,7 @@
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp; package org.eclipse.cdt.internal.core.pdom.dom.cpp;
@ -23,18 +24,18 @@ 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.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.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.internal.core.dom.bid.ILocalBindingIdentity;
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.FindBindingsInBTree; import org.eclipse.cdt.internal.core.pdom.dom.FindBindingsInBTree;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner; import org.eclipse.cdt.internal.core.pdom.dom.FindEquivalentBinding;
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.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;
/** /**
@ -52,7 +53,7 @@ class PDOMCPPNamespace extends PDOMCPPBinding
super(pdom, parent, name); super(pdom, parent, name);
} }
public PDOMCPPNamespace(PDOM pdom, int record) { public PDOMCPPNamespace(PDOM pdom, int record) throws CoreException {
super(pdom, record); super(pdom, record);
} }
@ -65,7 +66,7 @@ class PDOMCPPNamespace extends PDOMCPPBinding
} }
public BTree getIndex() throws CoreException { public BTree getIndex() throws CoreException {
return new BTree(pdom.getDB(), record + INDEX_OFFSET); return new BTree(pdom.getDB(), record + INDEX_OFFSET, getLinkageImpl().getIndexComparator());
} }
public void accept(final IPDOMVisitor visitor) throws CoreException { public void accept(final IPDOMVisitor visitor) throws CoreException {
@ -86,35 +87,19 @@ class PDOMCPPNamespace extends PDOMCPPBinding
}); });
} }
public void addChild(PDOMNamedNode child) throws CoreException { public void addChild(PDOMNode child) throws CoreException {
getIndex().insert(child.getRecord(), child.getIndexComparator()); getIndex().insert(child.getRecord());
}
public IBinding[] getMemberBindings() throws DOMException {
throw new PDOMNotImplementedError();
} }
public ICPPNamespaceScope getNamespaceScope() throws DOMException { public ICPPNamespaceScope getNamespaceScope() throws DOMException {
return this; return this;
} }
public void addUsingDirective(IASTNode directive) throws DOMException {
throw new PDOMNotImplementedError();
}
public IASTNode[] getUsingDirectives() throws DOMException { public IASTNode[] getUsingDirectives() throws DOMException {
// TODO // TODO
return new IASTNode[0]; return new IASTNode[0];
} }
public void addBinding(IBinding binding) throws DOMException {
throw new PDOMNotImplementedError();
}
public void addName(IASTName name) throws DOMException {
throw new PDOMNotImplementedError();
}
public IBinding[] find(String name) throws DOMException { public IBinding[] find(String name) throws DOMException {
try { try {
FindBindingsInBTree visitor = new FindBindingsInBTree(pdom, name.toCharArray()); FindBindingsInBTree visitor = new FindBindingsInBTree(pdom, name.toCharArray());
@ -164,10 +149,16 @@ class PDOMCPPNamespace extends PDOMCPPBinding
// reference // reference
IASTNode eParent = parent.getParent(); IASTNode eParent = parent.getParent();
if (eParent instanceof IASTFunctionCallExpression) { if (eParent instanceof IASTFunctionCallExpression) {
FindBindingsInBTree visitor = new FindBindingsInBTree(pdom, name.toCharArray(), PDOMCPPLinkage.CPPFUNCTION); IType[] types = ((PDOMCPPLinkage)getLinkage()).getTypes(
getIndex().accept(visitor); ((IASTFunctionCallExpression)eParent).getParameterExpression()
IBinding[] bindings = visitor.getBinding(); );
return bindings.length > 0 ? bindings[0] : null; ILocalBindingIdentity bid = new CPPBindingIdentity.Holder(
new String(name.toCharArray()),
PDOMCPPLinkage.CPPFUNCTION,
types);
FindEquivalentBinding feb = new FindEquivalentBinding(getLinkageImpl(), bid);
getIndex().accept(feb);
return feb.getResult();
} else { } else {
FindBindingsInBTree visitor = new FindBindingsInBTree(pdom, name.toCharArray(), FindBindingsInBTree visitor = new FindBindingsInBTree(pdom, name.toCharArray(),
(name.getParent() instanceof ICPPASTQualifiedName (name.getParent() instanceof ICPPASTQualifiedName
@ -175,13 +166,17 @@ class PDOMCPPNamespace extends PDOMCPPBinding
? PDOMCPPLinkage.CPPNAMESPACE : PDOMCPPLinkage.CPPVARIABLE); ? PDOMCPPLinkage.CPPNAMESPACE : PDOMCPPLinkage.CPPVARIABLE);
getIndex().accept(visitor); getIndex().accept(visitor);
IBinding[] bindings = visitor.getBinding(); IBinding[] bindings = visitor.getBinding();
return bindings.length > 0 ? bindings[0] : null; return bindings.length > 0
? bindings[0]
: null;
} }
} else if (parent instanceof IASTNamedTypeSpecifier) { } else if (parent instanceof IASTNamedTypeSpecifier) {
FindBindingsInBTree visitor = new FindBindingsInBTree(pdom, name.toCharArray(), PDOMCPPLinkage.CPPCLASSTYPE); FindBindingsInBTree visitor = new FindBindingsInBTree(pdom, name.toCharArray(), PDOMCPPLinkage.CPPCLASSTYPE);
getIndex().accept(visitor); getIndex().accept(visitor);
IBinding[] bindings = visitor.getBinding(); IBinding[] bindings = visitor.getBinding();
return bindings.length > 0 ? bindings[0] : null; return bindings.length > 0
? bindings[0]
: null;
} }
return null; return null;
} catch (CoreException e) { } catch (CoreException e) {
@ -195,14 +190,21 @@ class PDOMCPPNamespace extends PDOMCPPBinding
return null; return null;
} }
public IName getScopeName() throws DOMException { public boolean isFullyCached() throws DOMException {
throw new PDOMNotImplementedError(); return true;
} }
public void removeBinding(IBinding binding) throws DOMException {
throw new PDOMNotImplementedError();
}
public boolean mayHaveChildren() { public boolean mayHaveChildren() {
return true; return true;
} }
public IBinding[] getMemberBindings() throws DOMException {fail(); return null;}
public IASTNode getPhysicalNode() throws DOMException {fail(); return null;}
public IName getScopeName() throws DOMException {fail(); return null;}
public void removeBinding(IBinding binding) throws DOMException {fail();}
public void setFullyCached(boolean b) throws DOMException {fail();}
public void flushCache() throws DOMException {fail();}
public void addUsingDirective(IASTNode directive) throws DOMException {fail();}
public void addBinding(IBinding binding) throws DOMException {fail();}
public void addName(IASTName name) throws DOMException {fail();}
} }

View file

@ -53,4 +53,7 @@ public class PDOMFastIndexer implements IPDOMIndexer {
CCoreInternals.getPDOMManager().enqueue(new PDOMFastReindex(this)); CCoreInternals.getPDOMManager().enqueue(new PDOMFastReindex(this));
} }
public String getID() {
return ID;
}
} }

View file

@ -53,6 +53,7 @@ class PDOMFullHandleDelta extends PDOMFullIndexerJob {
} }
public void run(IProgressMonitor monitor) { public void run(IProgressMonitor monitor) {
setupIndexAndReaderFactory();
try { try {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();

View file

@ -12,6 +12,7 @@
package org.eclipse.cdt.internal.core.pdom.indexer.full; package org.eclipse.cdt.internal.core.pdom.indexer.full;
import org.eclipse.cdt.core.dom.IPDOMIndexer; import org.eclipse.cdt.core.dom.IPDOMIndexer;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.model.ICElementDelta; import org.eclipse.cdt.core.model.ICElementDelta;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.CCoreInternals;
@ -25,6 +26,7 @@ import org.eclipse.core.runtime.CoreException;
* *
*/ */
public class PDOMFullIndexer implements IPDOMIndexer { public class PDOMFullIndexer implements IPDOMIndexer {
public static final String ID = IPDOMManager.ID_FULL_INDEXER;
private ICProject project; private ICProject project;
@ -44,4 +46,7 @@ public class PDOMFullIndexer implements IPDOMIndexer {
CCoreInternals.getPDOMManager().enqueue(new PDOMFullReindex(this)); CCoreInternals.getPDOMManager().enqueue(new PDOMFullReindex(this));
} }
public String getID() {
return ID;
}
} }

View file

@ -48,6 +48,9 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
return indexer; return indexer;
} }
protected void setupIndexAndReaderFactory() {
// mstodo delay setting up index to here.
}
protected void doChangeTU(ITranslationUnit tu) throws CoreException, InterruptedException { protected void doChangeTU(ITranslationUnit tu) throws CoreException, InterruptedException {
IPath path = tu.getLocation(); IPath path = tu.getLocation();

View file

@ -42,8 +42,7 @@ class PDOMFullReindex extends PDOMFullIndexerJob {
public void run(final IProgressMonitor monitor) { public void run(final IProgressMonitor monitor) {
try { try {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
setupIndexAndReaderFactory();
// First clear out the PDOM
clearIndex(index); clearIndex(index);
fFilesToIndex--; fFilesToIndex--;
@ -73,7 +72,7 @@ class PDOMFullReindex extends PDOMFullIndexerJob {
String showTimings = Platform.getDebugOption(CCorePlugin.PLUGIN_ID String showTimings = Platform.getDebugOption(CCorePlugin.PLUGIN_ID
+ "/debug/pdomtimings"); //$NON-NLS-1$ + "/debug/pdomtimings"); //$NON-NLS-1$
if (showTimings != null && showTimings.equalsIgnoreCase("true")) //$NON-NLS-1$ if (showTimings != null && showTimings.equalsIgnoreCase("true")) //$NON-NLS-1$
System.out.println("PDOM Full Reindex Time: " + (System.currentTimeMillis() - start) //$NON-NLS-1$ System.out.println(indexer.getID()+" indexing time: " + (System.currentTimeMillis() - start) //$NON-NLS-1$
+ " " + indexer.getProject().getElementName()); //$NON-NLS-1$ + " " + indexer.getProject().getElementName()); //$NON-NLS-1$
} catch (CoreException e) { } catch (CoreException e) {
if (e.getStatus() != Status.CANCEL_STATUS) if (e.getStatus() != Status.CANCEL_STATUS)

View file

@ -73,8 +73,12 @@ public class PDOMNullIndexer implements IPDOMIndexer {
return 1; return 1;
} }
} }
public void reindex() throws CoreException { public void reindex() throws CoreException {
CCoreInternals.getPDOMManager().enqueue(new PDOMNullReindex()); CCoreInternals.getPDOMManager().enqueue(new PDOMNullReindex());
} }
public String getID() {
return ID;
}
} }

View file

@ -9,24 +9,11 @@
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* IBM Corporation * IBM Corporation
* Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui; package org.eclipse.cdt.internal.ui;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
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.ui.viewsupport.CElementImageProvider;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.LabelProvider;
@ -34,6 +21,27 @@ import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages; import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI; import org.eclipse.ui.PlatformUI;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin;
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.ui.viewsupport.CElementImageProvider;
/** /**
* Common label provider for index based viewers. * Common label provider for index based viewers.
* *
@ -45,7 +53,21 @@ public class IndexLabelProvider extends LabelProvider {
return "null :("; //$NON-NLS-1$ return "null :("; //$NON-NLS-1$
} else if (element instanceof PDOMNode) { } else if (element instanceof PDOMNode) {
try { try {
return ((PDOMNamedNode)element).getDBName().getString(); String result = ((PDOMNamedNode)element).getDBName().getString();
/*
* aftodo - Ideally here we'd call ASTTypeUtil.getType but
* we don't currently store return types
*/
if(element instanceof IFunction) {
try {
result += " "+ASTTypeUtil.getParameterTypeString(((IFunction) element).getType()); //$NON-NLS-1$
} catch(DOMException de) {
/* NO-OP: just use plain name as label */
}
}
return result;
} catch (CoreException e) { } catch (CoreException e) {
return e.getMessage(); return e.getMessage();
} }
@ -81,6 +103,12 @@ public class IndexLabelProvider extends LabelProvider {
desc = CElementImageProvider.getStructImageDescriptor(); desc = CElementImageProvider.getStructImageDescriptor();
else if (element instanceof ICPPNamespace) else if (element instanceof ICPPNamespace)
desc = CElementImageProvider.getNamespaceImageDescriptor(); desc = CElementImageProvider.getNamespaceImageDescriptor();
else if (element instanceof IEnumeration)
desc = CElementImageProvider.getEnumerationImageDescriptor();
else if (element instanceof IEnumerator)
CElementImageProvider.getEnumeratorImageDescriptor();
else if (element instanceof ITypedef)
desc = CElementImageProvider.getTypedefImageDescriptor();
else if (element instanceof ICProject) else if (element instanceof ICProject)
desc = CPluginImages.DESC_OBJS_SEARCHHIERPROJECT; desc = CPluginImages.DESC_OBJS_SEARCHHIERPROJECT;
else if (element instanceof ICContainer) else if (element instanceof ICContainer)