diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/BTreeTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/BTreeTests.java index 39539150044..c489e58a2f7 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/BTreeTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/BTreeTests.java @@ -52,8 +52,8 @@ public class BTreeTests extends BaseTestCase { dbFile = File.createTempFile("pdomtest", "db"); db = new Database(dbFile.getAbsolutePath()); rootRecord = Database.DATA_AREA; - btree = new BTree(db, rootRecord, degree); comparator = new BTMockRecordComparator(); + btree = new BTree(db, rootRecord, degree, comparator); } // tearDown is not used for the same reason as above @@ -131,7 +131,7 @@ public class BTreeTests extends BaseTestCase { history.add(btValue); if(debugMode) System.out.println("Add: "+value+" @ "+btValue.record); - btree.insert(btValue.getRecord(), comparator); + btree.insert(btValue.getRecord()); } } else { if(!history.isEmpty()) { @@ -141,7 +141,7 @@ public class BTreeTests extends BaseTestCase { expected.remove(new Integer(btValue.intValue())); if(debugMode) System.out.println("Remove: "+btValue.intValue()+" @ "+btValue.record); - btree.delete(btValue.getRecord(), comparator); + btree.delete(btValue.getRecord()); } } if(i % 1000 == 0) { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java index 70ec29d44cd..e1c0ec6fb6c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java @@ -142,10 +142,7 @@ public class CPPFunctionTests extends PDOMTestBase { assertReturnType(pdom, "floatCPPFunction", IBasicType.t_float); } - public void _testOverloadedFunction() throws Exception { - // Right now, only one binding is showing up for overloaded functions. - // There really should be one for each declaration. - + public void testOverloadedFunction() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "overloadedFunction"); assertEquals(2, bindings.length); boolean[] seen = new boolean[2]; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DBTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DBTest.java index 20e315670f5..6e709c2ca26 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DBTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DBTest.java @@ -140,20 +140,21 @@ public class DBTest extends TestCase { "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) { String name = names[i]; int record = db.malloc(8); db.putInt(record + 0, i); IString string = db.newString(name); db.putInt(record + 4, string.getRecord()); - btree.insert(record, 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.insert(record); } for (int i = 0; i < names.length; ++i) { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DefDeclTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DefDeclTests.java index 2a01c0eb8b0..18ab5978067 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DefDeclTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DefDeclTests.java @@ -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.IBinding; 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.IndexFilter; import org.eclipse.cdt.core.model.ICProject; @@ -272,16 +273,21 @@ public class DefDeclTests extends PDOMTestBase { assertDefDeclRef("type", "_t03", 1, 1, 1); } - 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 + public void _testStructAndTypedef_t04_unexpected() throws Exception { String num = "_t04"; String elName = "type" + num; - ICompositeType element = (ICompositeType) findSingleBinding(elName); - // checkReference(element, "ref" + num, 1); - checkReference(element, "refS" + num, 1); - checkDefinition(element, "defS" + num, 1); - // checkDeclaration(element, "def" + num, 1); + + IBinding[] bindings = pdom.findBindings(Pattern.compile(elName), false, new IndexFilter(), new NullProgressMonitor()); + assertEquals(2,bindings.length); + + 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 { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinCommonHeaderTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinCommonHeaderTests.java new file mode 100644 index 00000000000..3f0c5b23cd4 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinCommonHeaderTests.java @@ -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); + } +} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinSingleTUTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinSingleTUTests.java new file mode 100644 index 00000000000..06c2161a4a9 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinSingleTUTests.java @@ -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 + * 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; +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/bid/ILocalBindingIdentityComparator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/bid/ILocalBindingIdentityComparator.java new file mode 100644 index 00000000000..0e319264c85 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/bid/ILocalBindingIdentityComparator.java @@ -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<b, 0 if a==b and 1 if a>b + * @throws CoreException + */ + public int compare(IBinding a, IBinding b) throws CoreException; + /** + * + * @param a + * @param b + * @return -1 if a<b, 0 if a==b and 1 if a>b + * @throws CoreException + */ + public int compare(ILocalBindingIdentity a, IBinding b) throws CoreException; + /** + * + * @param a + * @param b + * @return -1 if a<b, 0 if a==b and 1 if a>b + * @throws CoreException + */ + public int compare(IBinding a, ILocalBindingIdentity b) throws CoreException; + /** + * + * @param a + * @param b + * @return -1 if a<b, 0 if a==b and 1 if a>b + * @throws CoreException + */ + public int compare(ILocalBindingIdentity a, ILocalBindingIdentity b) throws CoreException; +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java index a6125f51649..747f5c3bd42 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java @@ -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.PDOMName; 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.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -64,7 +63,7 @@ import org.eclipse.core.runtime.Status; public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { private Database db; - + public static final int VERSION = 13; // 0 - the beginning of it all // 1 - first change to kick off upgrades @@ -83,7 +82,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { public static final int LINKAGES = Database.DATA_AREA; public static final int FILE_INDEX = Database.DATA_AREA + 4; - + // Local caches private BTree fileIndex; private Map fLinkageIDCache = new HashMap(); @@ -93,12 +92,12 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { // Load up the database fPath= dbPath; db = new Database(dbPath.toOSString()); - + if (db.getVersion() == VERSION) { readLinkages(); } } - + public boolean versionMismatch() { if (db.getVersion() != VERSION) { db.setVersion(VERSION); @@ -106,32 +105,32 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { } else return false; } - + public void accept(IPDOMVisitor visitor) throws CoreException { for (Iterator iter = fLinkageIDCache.values().iterator(); iter.hasNext();) { PDOMLinkage linkage = (PDOMLinkage) iter.next(); linkage.accept(visitor); } } - + public static interface IListener { public void handleChange(PDOM pdom); } - + private List listeners; - + public void addListener(IListener listener) { if (listeners == null) listeners = new LinkedList(); listeners.add(listener); } - + public void removeListener(IListener listener) { if (listeners == null) return; listeners.remove(listener); } - + private void fireChange() { if (listeners == null) return; @@ -146,7 +145,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { public BTree getFileIndex() throws CoreException { if (fileIndex == null) - fileIndex = new BTree(getDB(), FILE_INDEX); + fileIndex = new BTree(getDB(), FILE_INDEX, new PDOMFile.Comparator(getDB())); return fileIndex; } @@ -156,29 +155,29 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { int record = finder.getRecord(); return record != 0 ? new PDOMFile(this, record) : null; } - + public IIndexFragmentFile getFile(IPath path) throws CoreException { return getFile(path.toOSString()); } - + protected IIndexFragmentFile addFile(String filename) throws CoreException { PDOMFile file = getFile(filename); if (file == null) { file = new PDOMFile(this, filename); - getFileIndex().insert(file.getRecord(), new Comparator(db)); + getFileIndex().insert(file.getRecord()); } return file; } - + protected void clear() throws CoreException { Database db = getDB(); // Clear out the database db.clear(); - + // Zero out the File Index and Linkages db.putInt(FILE_INDEX, 0); fileIndex = null; - + db.putInt(LINKAGES, 0); fLinkageIDCache.clear(); } @@ -201,8 +200,8 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { if (binding instanceof PDOMBinding) { List names = new ArrayList(); for (PDOMName name = ((PDOMBinding)binding).getFirstDefinition(); - name != null; - name = name.getNextInBinding()) + name != null; + name = name.getNextInBinding()) names.add(name); return (IName[]) names.toArray(new IIndexName[names.size()]); } @@ -216,14 +215,14 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { if (binding instanceof PDOMBinding) { List names = new ArrayList(); for (PDOMName name = ((PDOMBinding)binding).getFirstReference(); - name != null; - name = name.getNextInBinding()) + name != null; + name = name.getNextInBinding()) names.add(name); return (IName[]) names.toArray(new IIndexName[names.size()]); } return IIndexFragmentName.EMPTY_NAME_ARRAY; } - + public IIndexProxyBinding findBinding(IASTName name) throws CoreException { PDOMLinkage linkage= adaptLinkage(name.getLinkage()); if (linkage != null) { @@ -235,13 +234,13 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { private static class BindingFinder implements IPDOMVisitor { private final Pattern[] pattern; private final IProgressMonitor monitor; - + private final ArrayList currentPath= new ArrayList(); private final ArrayList matchStack= new ArrayList(); private List bindings = new ArrayList(); private boolean isFullyQualified; private BitSet matchesUpToLevel; - + public BindingFinder(Pattern[] pattern, boolean isFullyQualified, IProgressMonitor monitor) { this.pattern = pattern; this.monitor = monitor; @@ -250,11 +249,11 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { matchesUpToLevel.set(0); matchStack.add(matchesUpToLevel); } - + public boolean visit(IPDOMNode node) throws CoreException { if (monitor.isCanceled()) throw new CoreException(Status.OK_STATUS); - + if (node instanceof PDOMBinding) { PDOMBinding binding = (PDOMBinding)node; String name = binding.getName(); @@ -264,7 +263,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { if (matchesUpToLevel.get(lastIdx) && pattern[lastIdx].matcher(name).matches()) { bindings.add(binding); } - + // check if we have a partial match if (binding.mayHaveChildren()) { boolean visitNextLevel= false; @@ -298,12 +297,12 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { matchesUpToLevel= (BitSet) matchStack.remove(matchStack.size()-1); } } - + public IIndexFragmentBinding[] getBindings() { return (IIndexFragmentBinding[])bindings.toArray(new IIndexFragmentBinding[bindings.size()]); } } - + /** * @deprecated */ @@ -317,7 +316,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { public IBinding[] findBindings(Pattern[] pattern, IProgressMonitor monitor) throws CoreException { return findBindings(pattern, true, new IndexFilter(), monitor); } - + public IIndexBinding[] findBindings(Pattern pattern, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException { return findBindings(new Pattern[] { pattern }, isFullyQualified, filter, monitor); } @@ -373,7 +372,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { public PDOMLinkage getLinkage(int record) throws CoreException { if (record == 0) return null; - + // First check the cache. We do a linear search since there will be very few linkages // in a given database. Iterator i = fLinkageIDCache.values().iterator(); @@ -382,26 +381,26 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { if (linkage.getRecord() == record) return linkage; } - + String id = PDOMLinkage.getId(this, record).getString(); return createLinkage(id); } - + private int getFirstLinkageRecord() throws CoreException { return db.getInt(LINKAGES); } - + public PDOMLinkage[] getLinkages() { Collection values = fLinkageIDCache.values(); return (PDOMLinkage[]) values.toArray(new PDOMLinkage[values.size()]); } - + public void insertLinkage(PDOMLinkage linkage) throws CoreException { linkage.setNext(db.getInt(LINKAGES)); db.putInt(LINKAGES, linkage.getRecord()); fLinkageIDCache.put(linkage.getID(), linkage); } - + public PDOMBinding getBinding(int record) throws CoreException { if (record == 0) return null; @@ -417,7 +416,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { private int lockCount; private int waitingReaders; private long lastWriteAccess= 0; - + public void acquireReadLock() throws InterruptedException { synchronized (mutex) { ++waitingReaders; @@ -427,7 +426,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { ++lockCount; } } - + public void releaseReadLock() { synchronized (mutex) { assert lockCount > 0: "No lock to release"; //$NON-NLS-1$ @@ -436,11 +435,11 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { mutex.notifyAll(); } } - + public void acquireWriteLock() throws InterruptedException { acquireWriteLock(0); } - + public void acquireWriteLock(int giveupReadLocks) throws InterruptedException { synchronized (mutex) { if (giveupReadLocks > 0) { @@ -453,18 +452,18 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { lockCount= 0; } } - + // Let the readers go first while (lockCount != 0 || waitingReaders > 0) mutex.wait(); --lockCount; } } - + public void releaseWriteLock() { releaseWriteLock(0); } - + public void releaseWriteLock(int establishReadLocks) { assert lockCount == -1; lastWriteAccess= System.currentTimeMillis(); @@ -475,8 +474,8 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { } fireChange(); } - - + + public long getLastWriteAccess() { return lastWriteAccess; } @@ -492,7 +491,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { return pdomBinding; } } - + PDOMLinkage linkage= adaptLinkage(binding.getLinkage()); if (linkage != null) { return linkage.adaptBinding(binding); @@ -525,7 +524,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { public IIndexFragmentName[] findNames(IIndexProxyBinding binding, int options) throws CoreException { PDOMBinding pdomBinding = (PDOMBinding) adaptBinding(binding); - + if (pdomBinding != null) { PDOMName name; List names = new ArrayList(); @@ -565,7 +564,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { if (file.getIndexFragment() == this && file instanceof PDOMFile) { return (PDOMFile) file; } - + return getFile(file.getLocation()); } @@ -580,7 +579,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { } return new PDOMInclude[0]; } - + public IIndexFragmentFile resolveInclude(IIndexFragmentInclude include) throws CoreException { if (include.getFragment() == this && include instanceof PDOMInclude) { PDOMInclude pdomInclude= (PDOMInclude) include; @@ -592,5 +591,4 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { public IPath getPath() { return fPath; } - } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/BTree.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/BTree.java index 6ef5bb36516..545d65dff87 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/BTree.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/BTree.java @@ -7,7 +7,7 @@ * * Contributors: * 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; @@ -39,8 +39,10 @@ public class BTree { protected final int OFFSET_CHILDREN; protected final int MEDIAN_RECORD; - public BTree(Database db, int rootPointer) { - this(db, rootPointer, 8); + protected final IBTreeComparator cmp; + + public BTree(Database db, int rootPointer, IBTreeComparator cmp) { + this(db, rootPointer, 8, cmp); } /** @@ -49,13 +51,14 @@ public class BTree { * @param db the database containing the btree * @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) throw new IllegalArgumentException(Messages.getString("BTree.IllegalDegree")); //$NON-NLS-1$ this.db = db; this.rootPointer = rootPointer; - + this.cmp = cmp; + this.DEGREE = degree; this.MIN_RECORDS = DEGREE - 1; this.MAX_RECORDS = 2*DEGREE - 1; @@ -92,7 +95,7 @@ public class BTree { * @param offset of the record * @return */ - public int insert(int record, IBTreeComparator comparator) throws CoreException { + public int insert(int record) throws CoreException { int root = getRoot(); // is this our first time in @@ -101,10 +104,10 @@ public class BTree { 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); // 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); // set the node to the correct one to follow - if (comparator.compare(record, median) > 0) { + if (cmp.compare(record, median) > 0) { node = newnode; chunk = newchunk; } @@ -164,7 +167,7 @@ public class BTree { // past the end break; } else { - int compare = comparator.compare(record1, record); + int compare = cmp.compare(record1, record); if (compare == 0) // found it, no insert, just return the record return record; @@ -177,7 +180,7 @@ public class BTree { int child = getChild(chunk, node, i); if (child != 0) { // visit the children - return insert(chunk, node, i, child, record, comparator); + return insert(chunk, node, i, child, record); } else { // were at the leaf, add us in. // first copy everything after over one @@ -218,9 +221,9 @@ public class BTree { * @param cmp the comparator for locating the record * @throws CoreException */ - public void delete(int record, IBTreeComparator cmp) throws CoreException { + public void delete(int record) throws CoreException { try { - deleteImp(record, getRoot(), DELMODE_NORMAL, cmp); + deleteImp(record, getRoot(), DELMODE_NORMAL); } catch(BTreeKeyNotFoundException e) { // 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 * @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 { BTNode node = new BTNode(nodeRecord); @@ -316,7 +319,7 @@ public class BTree { BTNode succ = node.getChild(keyIndexInNode+1); if(succ!=null && succ.keyCount > MIN_RECORDS) { /* 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); return key; } @@ -324,7 +327,7 @@ public class BTree { BTNode pred = node.getChild(keyIndexInNode); if(pred!=null && pred.keyCount > MIN_RECORDS) { /* 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); return key; } @@ -332,7 +335,7 @@ public class BTree { /* Case 2c: Merge successor and predecessor */ // assert(pred!=null && succ!=null); mergeNodes(succ, node, keyIndexInNode, pred); - return deleteImp(key, pred.node, mode, cmp); + return deleteImp(key, pred.node, mode); } else { /* Case 3: non-leaf node which does not itself contain the key */ @@ -358,7 +361,7 @@ public class BTree { } if(child.keyCount > MIN_RECORDS) { - return deleteImp(key, child.node, mode, cmp); + return deleteImp(key, child.node, mode); } else { BTNode sibR = node.getChild(subtreeIndex+1); if(sibR!=null && sibR.keyCount > MIN_RECORDS) { @@ -368,7 +371,7 @@ public class BTree { append(child, rightKey, getChild(sibR.chunk, sibR.node, 0)); nodeContentDelete(sibR, 0, 1); 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); @@ -380,19 +383,19 @@ public class BTree { putRecord(sibL.chunk, sibL.node, sibL.keyCount-1, 0); putChild(sibL.chunk, sibL.node, sibL.keyCount, 0); 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 */ if(sibL!=null) { // merge child into leftSibling 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 mergeNodes(sibR, node, subtreeIndex, child); - return deleteImp(key, child.node, mode, cmp); + return deleteImp(key, child.node, mode); } throw new BTreeKeyNotFoundException( diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java index 730ef2c7bac..bdd4ee162d0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.db; +import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; @@ -53,6 +54,7 @@ import org.eclipse.core.runtime.Status; */ public class Database { + private final File location; private final RandomAccessFile file; Chunk[] toc; @@ -73,6 +75,7 @@ public class Database { public Database(String filename) throws CoreException { try { + location = new File(filename); file = new RandomAccessFile(filename, "rw"); //$NON-NLS-1$ // Allocate chunk table, make sure we have at least one @@ -331,4 +334,11 @@ public class Database { public void close() throws IOException { file.close(); } + + /** + * This method is public for testing purposes only. + */ + public File getLocation() { + return location; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/FindBindingByLinkageConstant.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/FindBindingByLinkageConstant.java new file mode 100644 index 00000000000..15fb219995e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/FindBindingByLinkageConstant.java @@ -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; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/FindBindingsInBTree.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/FindBindingsInBTree.java index f2b6ae1e280..e3267e09ec7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/FindBindingsInBTree.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/FindBindingsInBTree.java @@ -15,9 +15,18 @@ import java.util.List; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.internal.core.pdom.PDOM; +import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor; 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 final int[] desiredType; @@ -51,7 +60,8 @@ public final class FindBindingsInBTree extends PDOMNamedNode.NodeFinder { * @param desiredType */ public FindBindingsInBTree(PDOM pdom, char[] name, int[] desiredType) { - super(pdom, name); + this.pdom = pdom; + this.name = name; this.desiredType = desiredType; } @@ -83,5 +93,4 @@ public final class FindBindingsInBTree extends PDOMNamedNode.NodeFinder { public IBinding[] getBinding() { return (IBinding[])bindings.toArray(new IBinding[bindings.size()]); } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/FindEquivalentBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/FindEquivalentBinding.java new file mode 100644 index 00000000000..4b499f45e3b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/FindEquivalentBinding.java @@ -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; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/IPDOMMemberOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/IPDOMMemberOwner.java index 8af9c8c143b..d509c518516 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/IPDOMMemberOwner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/IPDOMMemberOwner.java @@ -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; import org.eclipse.cdt.core.dom.IPDOMVisitor; 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 void addMember(PDOMNode member) throws CoreException; public void accept(IPDOMVisitor visitor) throws CoreException; + public void addChild(PDOMNode member) throws CoreException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java index aca99ecd6ed..88186c57d99 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java @@ -8,6 +8,7 @@ * Contributors: * QNX - Initial API and implementation * Markus Schorn (Wind River Systems) + * Andrew Ferguson (Symbian) *******************************************************************************/ 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()); } + protected PDOMBinding(PDOM pdom, PDOMNode parent, char[] name) throws CoreException { + super(pdom, parent, name); + } + public PDOMBinding(PDOM pdom, int record) { super(pdom, record); } @@ -149,12 +154,12 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen } return new char[0]; } - + public IScope getScope() throws DOMException { // TODO implement this return null; } - + public IIndexBinding getParentBinding() throws CoreException { PDOMNode parent= getParentNode(); if (parent instanceof IIndexBinding) { @@ -167,6 +172,22 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen 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() { return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java index 21a9bfc2b95..79952537b7b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java @@ -99,6 +99,13 @@ public class PDOMFile implements IIndexFragmentFile { 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() { return record; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java index c2694510ebd..851d300a01d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java @@ -9,6 +9,7 @@ * QNX - Initial API and implementation * Markus Schorn (Wind River Systems) * IBM Corporation + * Andrew Ferguson (Symbian) *******************************************************************************/ 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.IIndexLinkage; 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.pdom.PDOM; 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.IBTreeComparator; import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor; import org.eclipse.cdt.internal.core.pdom.db.IString; 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 * 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 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 { - 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 { @@ -122,8 +126,8 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage return this; } - protected void addChild(PDOMNamedNode child) throws CoreException { - getIndex().insert(child.getRecord(), child.getIndexComparator()); + public final void addChild(PDOMNode child) throws CoreException { + getIndex().insert(child.getRecord()); } public PDOMNode getNode(int record) throws CoreException { @@ -137,68 +141,97 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage } public PDOMNode addType(PDOMNode parent, IType type) throws CoreException { + PDOMNode node; + if (type instanceof IPointerType) - return new PDOMPointerType(pdom, parent, (IPointerType)type); + node = new PDOMPointerType(pdom, parent, (IPointerType)type); else if (type instanceof IQualifierType) - return new PDOMQualifierType(pdom, parent, (IQualifierType)type); + node = new PDOMQualifierType(pdom, parent, (IQualifierType)type); 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 adaptBinding(IBinding binding) 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 { try { - IScope scope = binding.getScope(); - if (scope == null) - return null; - - if (scope instanceof IIndexBinding) { - IIndexBinding parent= ((IIndexBinding) scope).getParentBinding(); - if (parent == null) { - return this; - } - return adaptBinding(parent); - } - - // the scope is from the ast - - // mstodo revisit unnamed namespaces - IScope testScope= scope; - while (testScope instanceof ICPPNamespaceScope) { - IName name= testScope.getScopeName(); - if (name != null && name.toCharArray().length == 0) { - testScope= scope.getParent(); - if (testScope != null) { - scope= testScope; - } - } - else { - testScope= null; - } - } - - IASTNode scopeNode = ASTInternal.getPhysicalNodeOfScope(scope); - if (scopeNode instanceof IASTCompoundStatement) - return null; - else if (scopeNode instanceof IASTTranslationUnit) + IScope scope = binding.getScope(); + if (scope == null) { + return binding instanceof PDOMBinding ? this : null; + } + + if (scope instanceof IIndexBinding) { + IIndexBinding parent= ((IIndexBinding) scope).getParentBinding(); + if (parent == null) { return this; - else { - IName scopeName = scope.getScopeName(); - if (scopeName instanceof IASTName) { - IBinding scopeBinding = ((IASTName) scopeName).resolveBinding(); - PDOMBinding scopePDOMBinding = adaptBinding(scopeBinding); - if (scopePDOMBinding != null) - return scopePDOMBinding; + } + return adaptBinding(parent); + } + + // the scope is from the ast + + // mstodo revisit unnamed namespaces + IScope testScope= scope; + while (testScope instanceof ICPPNamespaceScope) { + IName name= testScope.getScopeName(); + if (name != null && name.toCharArray().length == 0) { + testScope= scope.getParent(); + if (testScope != null) { + scope= testScope; } } + else { + testScope= null; + } + } + + IASTNode scopeNode = ASTInternal.getPhysicalNodeOfScope(scope); + if (scopeNode instanceof IASTCompoundStatement) + return null; + else if (scopeNode instanceof IASTTranslationUnit) + return this; + else { + IName scopeName = scope.getScopeName(); + if (scopeName instanceof IASTName) { + IBinding scopeBinding = ((IASTName) scopeName).resolveBinding(); + PDOMBinding scopePDOMBinding = adaptBinding(scopeBinding); + if (scopePDOMBinding != null) + return scopePDOMBinding; + } + } } catch (DOMException e) { throw new CoreException(Util.createStatus(e)); } return null; } + + public abstract IBindingIdentityFactory getBindingIdentityFactory(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNamedNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNamedNode.java index 0a9ae4d6e65..7e377ef9a2c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNamedNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNamedNode.java @@ -8,6 +8,7 @@ * Contributors: * QNX - Initial API and implementation * IBM Corporation + * Andrew Ferguson (Symbian) *******************************************************************************/ 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.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.IString; import org.eclipse.core.runtime.CoreException; @@ -45,9 +45,6 @@ public abstract class PDOMNamedNode extends PDOMNode { Database db = pdom.getDB(); db.putInt(record + NAME, name != null ? db.newString(name).getRecord() : 0); - - if (parent != null) - parent.addChild(this); } protected int getRecordSize() { @@ -75,7 +72,7 @@ public abstract class PDOMNamedNode extends PDOMNode { int string1 = db.getInt(record1 + NAME); int string2 = db.getInt(record2 + NAME); return db.getString(string1).compare(db.getString(string2)); - }; + } }; } @@ -105,18 +102,4 @@ public abstract class PDOMNamedNode extends PDOMNode { 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); - } - } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNode.java index 3607aa2401d..1f15ed04d1c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNode.java @@ -8,6 +8,7 @@ * Contributors: * QNX - Initial API and implementation * Markus Schorn (Wind River Systems) + * Andrew Ferguson (Symbian) *******************************************************************************/ 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. * 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 PARENT = 4; @@ -52,8 +53,6 @@ public abstract class PDOMNode implements IPDOMNode{ // parent db.putInt(record + PARENT, parent != null ? parent.getRecord() : 0); - if (parent instanceof IPDOMMemberOwner) - ((IPDOMMemberOwner)parent).addMember(this); } protected abstract int getRecordSize(); @@ -111,8 +110,8 @@ public abstract class PDOMNode implements IPDOMNode{ return pdom.getLinkage(linkagerec); } - protected void addChild(PDOMNamedNode child) throws CoreException { + public void addChild(PDOMNode child) throws CoreException { // nothing here } - + } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/CBindingIdentity.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/CBindingIdentity.java new file mode 100644 index 00000000000..7c3cd49375b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/CBindingIdentity.java @@ -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$ + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCBasicType.java new file mode 100644 index 00000000000..30257e1cb2f --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCBasicType.java @@ -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; + } + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunction.java index ec8ca158035..23f9ccba94a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunction.java @@ -8,21 +8,28 @@ * Contributors: * QNX - Initial API and implementation * IBM Corporation + * 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.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.IFunctionType; import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError; import org.eclipse.core.runtime.CoreException; /** @@ -30,30 +37,69 @@ import org.eclipse.core.runtime.CoreException; * */ 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 * 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 { super(pdom, parent, name); 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())); - } catch (DOMException e) { + } catch(DOMException 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) { super(pdom, record); } - + protected int getRecordSize() { return RECORD_SIZE; } @@ -61,17 +107,27 @@ class PDOMCFunction extends PDOMBinding implements IFunction { public int getNodeType() { return PDOMCLinkage.CFUNCTION; } - - public IParameter[] getParameters() throws DOMException { - throw new PDOMNotImplementedError(); - } - - public IScope getFunctionScope() throws DOMException { - throw new PDOMNotImplementedError(); - } 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 { @@ -82,6 +138,38 @@ class PDOMCFunction extends PDOMBinding implements IFunction { 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 { // ISO/IEC 9899:TC1 6.9.1.4 return false; @@ -99,5 +187,9 @@ class PDOMCFunction extends PDOMBinding implements IFunction { public boolean takesVarArgs() throws DOMException { 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;} } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java index 8329fd5e9b1..1d94c633879 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java @@ -9,12 +9,11 @@ * QNX - Initial API and implementation * Markus Schorn (Wind River Systems) * IBM Corporation + * Andrew Ferguson (Symbian) *******************************************************************************/ 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.IASTFunctionCallExpression; 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.IVariable; 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.model.ILanguage; 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.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.PDOMBinding; 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.PDOMName; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Status; @@ -58,6 +61,10 @@ class PDOMCLinkage extends PDOMLinkage { public PDOMCLinkage(PDOM pdom) throws CoreException { super(pdom, C_LINKAGE_ID, C_LINKAGE_ID.toCharArray()); } + + public int getNodeType() { + return LINKAGE; + } public String getID() { return C_LINKAGE_ID; @@ -70,19 +77,23 @@ class PDOMCLinkage extends PDOMLinkage { public static final int CENUMERATION = PDOMLinkage.LAST_NODE_TYPE + 5; public static final int CENUMERATOR = PDOMLinkage.LAST_NODE_TYPE + 6; 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() { return new GCCLanguage(); } + + public PDOMBinding addName(IASTName name, PDOMFile file) throws CoreException { if (name == null) return null; - + char[] namechars = name.toCharArray(); if (namechars == null || name.toCharArray().length == 0) return null; - + IBinding binding = name.resolveBinding(); if (binding == null || binding instanceof IProblemBinding) // can't tell what it is @@ -91,13 +102,13 @@ class PDOMCLinkage extends PDOMLinkage { if (binding instanceof IParameter) // skip parameters return null; - + PDOMBinding pdomBinding = adaptBinding(binding); if (pdomBinding == null) { PDOMNode parent = getAdaptedParent(binding); if (parent == null) return null; - + if (binding instanceof IParameter) return null; // skip parameters else if (binding instanceof IField) { // must be before IVariable @@ -116,76 +127,23 @@ class PDOMCLinkage extends PDOMLinkage { IEnumeration enumeration = (IEnumeration)((IEnumerator)binding).getType(); PDOMBinding pdomEnumeration = adaptBinding(enumeration); if (pdomEnumeration instanceof PDOMCEnumeration) - pdomBinding = new PDOMCEnumerator(pdom, parent, name, - (PDOMCEnumeration)pdomEnumeration); + pdomBinding = new PDOMCEnumerator(pdom, parent, name, + (PDOMCEnumeration)pdomEnumeration); } catch (DOMException e) { throw new CoreException(Util.createStatus(e)); } } else if (binding instanceof ITypedef) pdomBinding = new PDOMCTypedef(pdom, parent, name, (ITypedef)binding); + + parent.addChild(pdomBinding); } - + if (pdomBinding != null) new PDOMName(pdom, name, file, 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) { if (binding instanceof IField) // This needs to be before variable @@ -205,7 +163,7 @@ class PDOMCLinkage extends PDOMLinkage { else return 0; } - + public PDOMBinding adaptBinding(IBinding binding) throws CoreException { if (binding instanceof PDOMBinding) { // there is no guarantee, that the binding is from the same PDOM object. @@ -215,31 +173,33 @@ class PDOMCLinkage extends PDOMLinkage { } // so if the binding is from another pdom it has to be adapted. } + + FindEquivalentBinding visitor = new FindEquivalentBinding(this, binding); PDOMNode parent = getAdaptedParent(binding); + if (parent == this) { - FindBinding visitor = new FindBinding(pdom, binding.getNameCharArray(), getBindingType(binding)); getIndex().accept(visitor); - return visitor.pdomBinding; + return visitor.getResult(); } else if (parent instanceof IPDOMMemberOwner) { - FindBinding2 visitor = new FindBinding2(binding.getNameCharArray(), getBindingType(binding)); IPDOMMemberOwner owner = (IPDOMMemberOwner)parent; try { owner.accept(visitor); } catch (CoreException e) { if (e.getStatus().equals(Status.OK_STATUS)) - return visitor.getBinding(); + return visitor.getResult(); else throw e; } } + return null; } public PDOMNode getNode(int record) throws CoreException { if (record == 0) return null; - + switch (PDOMNode.getNodeType(pdom, record)) { case CVARIABLE: return new PDOMCVariable(pdom, record); @@ -255,36 +215,54 @@ class PDOMCLinkage extends PDOMLinkage { return new PDOMCEnumerator(pdom, record); case CTYPEDEF: return new PDOMCTypedef(pdom, record); + case CPARAMETER: + return new PDOMCParameter(pdom, record); + case CBASICTYPE: + return new PDOMCBasicType(pdom, record); } return super.getNode(record); } public PDOMBinding resolveBinding(IASTName name) throws CoreException { + int constant; IASTNode parent = name.getParent(); - if (parent instanceof IASTIdExpression) { - // reference + if (parent instanceof IASTIdExpression) { // reference IASTNode eParent = parent.getParent(); if (eParent instanceof IASTFunctionCallExpression) { - FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CFUNCTION); - getIndex().accept(visitor); - return visitor.pdomBinding; + constant = CFUNCTION; } else { - FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CVARIABLE); - getIndex().accept(visitor); - return visitor.pdomBinding; + constant = CVARIABLE; } } else if (parent instanceof ICASTElaboratedTypeSpecifier) { - FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CSTRUCTURE); - getIndex().accept(visitor); - return visitor.pdomBinding; + constant = CSTRUCTURE; + } else { + 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 { - // TODO Auto-generated method stub - return null; + if (type instanceof ICBasicType) { + 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; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java new file mode 100644 index 00000000000..0f650307b85 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java @@ -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]; + } + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java index 1d02a9e8544..07b0f33ea10 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java @@ -8,6 +8,7 @@ * Contributors: * QNX - Initial API and implementation * Markus Schorn (Wind River Systems) + * Andrew Ferguson (Symbian) *******************************************************************************/ 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.dom.IPDOMMemberOwner; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError; import org.eclipse.core.runtime.CoreException; @@ -149,6 +149,10 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, IPDOM return RECORD_SIZE; } + public void addChild(PDOMNode member) throws CoreException { + addMember(member); + } + public boolean mayHaveChildren() { return true; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/CPPBindingIdentity.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/CPPBindingIdentity.java new file mode 100644 index 00000000000..7bedfe3e095 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/CPPBindingIdentity.java @@ -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; i0) { + 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(); + } + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java index d2a37fcc829..a2c2a17a0b9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java @@ -23,6 +23,7 @@ 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.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IScope; @@ -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.PDOMName; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError; import org.eclipse.core.runtime.CoreException; /** * @author Doug Schaefer * */ +/* + * aftodo - contract get Methods/Fields not honoured? + */ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, ICPPClassScope, IPDOMMemberOwner { @@ -74,14 +77,14 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, // 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 { PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl()); list.addMember(member); } - - public PDOMCPPClassType(PDOM pdom, int bindingRecord) { - super(pdom, bindingRecord); - } protected int getRecordSize() { return RECORD_SIZE; @@ -114,14 +117,6 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, // TODO - should we check for real? return false; } - - public Object clone() { - throw new PDOMNotImplementedError(); - } - - public IField findField(String name) throws DOMException { - throw new PDOMNotImplementedError(); - } public ICPPBase[] getBases() throws DOMException { try { @@ -143,15 +138,6 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, 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 final 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 List nestedClasses = new ArrayList(); @@ -299,31 +283,11 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, 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 { // TODO - this might be a better way of adding names to scopes // 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 { try { PDOMName name = getFirstDefinition(); @@ -336,8 +300,44 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, } } - public void removeBinding(IBinding binding) throws DOMException { - throw new PDOMNotImplementedError(); + public void addChild(PDOMNode member) throws CoreException {addMember(member);} + + 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() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java index 4368b9b9805..b8e64b7e750 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java @@ -8,15 +8,17 @@ * Contributors: * QNX - Initial API and implementation * Markus Schorn (Wind River Systems) + * Andrew Ferguson (Symbian) *******************************************************************************/ 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.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; 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.IASTNamedTypeSpecifier; 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.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; 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.model.ILanguage; 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.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.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.PDOMBinding; 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.PDOMName; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Status; @@ -62,24 +70,26 @@ import org.eclipse.core.runtime.Status; * */ class PDOMCPPLinkage extends PDOMLinkage { - public PDOMCPPLinkage(PDOM pdom, int record) { super(pdom, record); } - public PDOMCPPLinkage(PDOM pdom) - throws CoreException { + public PDOMCPPLinkage(PDOM pdom) throws CoreException { super(pdom, CPP_LINKAGE_ID, CPP_LINKAGE_ID.toCharArray()); } public String getID() { return CPP_LINKAGE_ID; } - + protected int getRecordSize() { return RECORD_SIZE; } - + + public int getNodeType() { + return LINKAGE; + } + // Binding types public static final int CPPVARIABLE = PDOMLinkage.LAST_NODE_TYPE + 1; public static final int CPPFUNCTION = PDOMLinkage.LAST_NODE_TYPE + 2; @@ -97,25 +107,28 @@ class PDOMCPPLinkage extends PDOMLinkage { public ILanguage getLanguage() { return new GPPLanguage(); } - + + public PDOMBinding addName(IASTName name, PDOMFile file) throws CoreException { if (name == null || name instanceof ICPPASTQualifiedName) return null; - + // Check for null name char[] namechars = name.toCharArray(); if (namechars == null || namechars.length == 0) return null; - + + IBinding binding = name.resolveBinding(); + if (binding == null || binding instanceof IProblemBinding) // Can't tell what it is return null; - + if (binding instanceof IParameter) // Skip parameters (TODO and others I'm sure) return null; - + PDOMBinding pdomBinding = adaptBinding(binding); try { if (pdomBinding == null) { @@ -133,6 +146,30 @@ class PDOMCPPLinkage extends PDOMLinkage { //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) { + 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 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); } } else if (binding instanceof ICPPFunction) { pdomBinding = new PDOMCPPFunction(pdom, parent, name); @@ -153,17 +190,18 @@ class PDOMCPPLinkage extends PDOMLinkage { } 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)); } - + // final processing if (pdomBinding != null) { // Add in the name new PDOMName(pdom, name, file, pdomBinding); - + // Check if is a base specifier if (pdomBinding instanceof ICPPClassType && name.getParent() instanceof ICPPASTBaseSpecifier) { ICPPASTBaseSpecifier baseNode = (ICPPASTBaseSpecifier)name.getParent(); @@ -177,69 +215,8 @@ class PDOMCPPLinkage extends PDOMLinkage { } } } - - 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; } + return pdomBinding; } protected int getBindingType(IBinding binding) { @@ -271,11 +248,14 @@ class PDOMCPPLinkage extends PDOMLinkage { else return 0; } - + + /** + * Find the equivalent binding, or binding placeholder within this PDOM + */ public PDOMBinding adaptBinding(IBinding binding) throws CoreException { if (binding == null || binding instanceof IProblemBinding) return null; - + if (binding instanceof PDOMBinding) { // there is no guarantee, that the binding is from the same PDOM object. PDOMBinding pdomBinding = (PDOMBinding) binding; @@ -284,48 +264,54 @@ class PDOMCPPLinkage extends PDOMLinkage { } // so if the binding is from another pdom it has to be adapted. } - + + FindEquivalentBinding visitor = new FindEquivalentBinding(this, binding); PDOMNode parent = getAdaptedParent(binding); + if (parent == this) { - FindBinding visitor = new FindBinding(pdom, binding.getNameCharArray(), getBindingType(binding)); getIndex().accept(visitor); - return visitor.pdomBinding; + return visitor.getResult(); } else if (parent instanceof IPDOMMemberOwner) { - FindBinding2 visitor = new FindBinding2(binding.getNameCharArray(), getBindingType(binding)); IPDOMMemberOwner owner = (IPDOMMemberOwner)parent; try { owner.accept(visitor); } catch (CoreException e) { if (e.getStatus().equals(Status.OK_STATUS)) - return visitor.getBinding(); + return visitor.getResult(); else throw e; } } else if (parent instanceof PDOMCPPNamespace) { - FindBinding visitor = new FindBinding(pdom, binding.getNameCharArray(), getBindingType(binding)); ((PDOMCPPNamespace)parent).getIndex().accept(visitor); - return visitor.pdomBinding; + return visitor.getResult(); } + return null; } - + 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 - IBinding origBinding = name.getBinding(); + IBinding origBinding = name.getBinding(); if (origBinding != null) return adaptBinding(origBinding); + + if (name instanceof ICPPASTQualifiedName) { IASTName[] names = ((ICPPASTQualifiedName)name).getNames(); if (names.length == 1) return resolveBinding(names[0]); IASTName lastName = names[names.length - 1]; PDOMBinding nsBinding = adaptBinding(names[names.length - 2].resolveBinding()); - try { - if (nsBinding instanceof IScope) { - return (PDOMBinding) ((IScope)nsBinding).getBinding(lastName, true); - } - } catch (DOMException e) { - throw new CoreException(Util.createStatus(e)); + if (nsBinding instanceof IScope) { + return (PDOMBinding) ((IScope)nsBinding).getBinding(lastName, true); } } IASTNode parent = name.getParent(); @@ -340,38 +326,122 @@ class PDOMCPPLinkage extends PDOMLinkage { parent = parent.getParent(); } } - + if (parent instanceof IASTIdExpression) { // reference IASTNode eParent = parent.getParent(); if (eParent instanceof IASTFunctionCallExpression) { - FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CPPFUNCTION); - getIndex().accept(visitor); - return visitor.pdomBinding; + return resolveFunctionCall((IASTIdExpression)parent, name, (IASTFunctionCallExpression) eParent); } else { - FindBinding visitor = new FindBinding(pdom, name.toCharArray(), - (name.getParent() instanceof ICPPASTQualifiedName - && ((ICPPASTQualifiedName)name.getParent()).getLastName() != name) - ? CPPNAMESPACE : CPPVARIABLE); - getIndex().accept(visitor); - return visitor.pdomBinding; + int constant = (name.getParent() instanceof ICPPASTQualifiedName + && ((ICPPASTQualifiedName)name.getParent()).getLastName() != name) + ? CPPNAMESPACE : CPPVARIABLE; + FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant(this, name.toCharArray(), constant); + getIndex().accept(finder); + return finder.getResult(); } } else if (parent instanceof IASTNamedTypeSpecifier) { - FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CPPCLASSTYPE); - getIndex().accept(visitor); - return visitor.pdomBinding; + FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CPPCLASSTYPE); + getIndex().accept(finder); + PDOMBinding result = finder.getResult(); + return result; + } else if (parent instanceof ICPPASTNamespaceAlias) { - FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CPPNAMESPACE); - getIndex().accept(visitor); - return visitor.pdomBinding; + FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CPPNAMESPACE); + getIndex().accept(finder); + 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 0 ? bindings[0] : null; + IType[] types = ((PDOMCPPLinkage)getLinkage()).getTypes( + ((IASTFunctionCallExpression)eParent).getParameterExpression() + ); + 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 { FindBindingsInBTree visitor = new FindBindingsInBTree(pdom, name.toCharArray(), (name.getParent() instanceof ICPPASTQualifiedName @@ -175,13 +166,17 @@ class PDOMCPPNamespace extends PDOMCPPBinding ? PDOMCPPLinkage.CPPNAMESPACE : PDOMCPPLinkage.CPPVARIABLE); getIndex().accept(visitor); IBinding[] bindings = visitor.getBinding(); - return bindings.length > 0 ? bindings[0] : null; + return bindings.length > 0 + ? bindings[0] + : null; } } else if (parent instanceof IASTNamedTypeSpecifier) { FindBindingsInBTree visitor = new FindBindingsInBTree(pdom, name.toCharArray(), PDOMCPPLinkage.CPPCLASSTYPE); getIndex().accept(visitor); IBinding[] bindings = visitor.getBinding(); - return bindings.length > 0 ? bindings[0] : null; + return bindings.length > 0 + ? bindings[0] + : null; } return null; } catch (CoreException e) { @@ -195,14 +190,21 @@ class PDOMCPPNamespace extends PDOMCPPBinding return null; } - public IName getScopeName() throws DOMException { - throw new PDOMNotImplementedError(); + public boolean isFullyCached() throws DOMException { + return true; } - public void removeBinding(IBinding binding) throws DOMException { - throw new PDOMNotImplementedError(); - } public boolean mayHaveChildren() { 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();} } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java index af8e5bd3c53..109cb8fc4f5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java @@ -53,4 +53,7 @@ public class PDOMFastIndexer implements IPDOMIndexer { CCoreInternals.getPDOMManager().enqueue(new PDOMFastReindex(this)); } + public String getID() { + return ID; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullHandleDelta.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullHandleDelta.java index 80c1a10ec30..cef1fb37bee 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullHandleDelta.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullHandleDelta.java @@ -53,6 +53,7 @@ class PDOMFullHandleDelta extends PDOMFullIndexerJob { } public void run(IProgressMonitor monitor) { + setupIndexAndReaderFactory(); try { long start = System.currentTimeMillis(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexer.java index c3b9a9ac5e2..c0b985866a2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexer.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.pdom.indexer.full; 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.ICProject; import org.eclipse.cdt.internal.core.CCoreInternals; @@ -25,7 +26,8 @@ import org.eclipse.core.runtime.CoreException; * */ public class PDOMFullIndexer implements IPDOMIndexer { - + public static final String ID = IPDOMManager.ID_FULL_INDEXER; + private ICProject project; public ICProject getProject() { @@ -44,4 +46,7 @@ public class PDOMFullIndexer implements IPDOMIndexer { CCoreInternals.getPDOMManager().enqueue(new PDOMFullReindex(this)); } + public String getID() { + return ID; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerJob.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerJob.java index 0ab128bdaff..a6e5d43337d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerJob.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerJob.java @@ -48,6 +48,9 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe return indexer; } + protected void setupIndexAndReaderFactory() { + // mstodo delay setting up index to here. + } protected void doChangeTU(ITranslationUnit tu) throws CoreException, InterruptedException { IPath path = tu.getLocation(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullReindex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullReindex.java index 91f2ca7d205..f174128ace6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullReindex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullReindex.java @@ -41,9 +41,8 @@ class PDOMFullReindex extends PDOMFullIndexerJob { public void run(final IProgressMonitor monitor) { try { - long start = System.currentTimeMillis(); - - // First clear out the PDOM + long start = System.currentTimeMillis(); + setupIndexAndReaderFactory(); clearIndex(index); fFilesToIndex--; @@ -73,7 +72,7 @@ class PDOMFullReindex extends PDOMFullIndexerJob { String showTimings = Platform.getDebugOption(CCorePlugin.PLUGIN_ID + "/debug/pdomtimings"); //$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$ } catch (CoreException e) { if (e.getStatus() != Status.CANCEL_STATUS) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/nulli/PDOMNullIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/nulli/PDOMNullIndexer.java index bcdf66482e9..dac81ae5251 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/nulli/PDOMNullIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/nulli/PDOMNullIndexer.java @@ -73,8 +73,12 @@ public class PDOMNullIndexer implements IPDOMIndexer { return 1; } } + public void reindex() throws CoreException { CCoreInternals.getPDOMManager().enqueue(new PDOMNullReindex()); } + public String getID() { + return ID; + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/IndexLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/IndexLabelProvider.java index f13863da51e..f2a38832ee7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/IndexLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/IndexLabelProvider.java @@ -9,24 +9,11 @@ * QNX - Initial API and implementation * Markus Schorn (Wind River Systems) * IBM Corporation + * Andrew Ferguson (Symbian) *******************************************************************************/ 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.jface.resource.ImageDescriptor; 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.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. * @@ -45,7 +53,21 @@ public class IndexLabelProvider extends LabelProvider { return "null :("; //$NON-NLS-1$ } else if (element instanceof PDOMNode) { 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) { return e.getMessage(); } @@ -81,6 +103,12 @@ public class IndexLabelProvider extends LabelProvider { desc = CElementImageProvider.getStructImageDescriptor(); else if (element instanceof ICPPNamespace) 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) desc = CPluginImages.DESC_OBJS_SEARCHHIERPROJECT; else if (element instanceof ICContainer)