1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 10:46:02 +02:00

165213: undo misadventure with abstraction

This commit is contained in:
Andrew Ferguson 2006-11-23 18:31:38 +00:00
parent 3329794554
commit 773b11c204
24 changed files with 446 additions and 904 deletions

View file

@ -0,0 +1,71 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian 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:
* Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.index.tests;
import java.util.regex.Pattern;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CTestPlugin;
import org.eclipse.cdt.core.testplugin.TestScannerProvider;
import org.eclipse.cdt.internal.core.CCoreInternals;
import org.eclipse.cdt.utils.spawner.EnvironmentReader;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.osgi.framework.Bundle;
/**
* aftodo - it would be nice to have this as a real performance test
*
* n.b. this is intentionally not added to any test suite at the moment
*/
public class TrilogyPerformanceTest extends IndexTestBase {
ICProject cproject;
public TrilogyPerformanceTest() {
super("TrilogyPerformance");
}
protected void setUp() throws Exception {
Bundle b = CTestPlugin.getDefault().getBundle();
if (cproject == null) {
cproject= createProject(true, "resources/indexTests/trilogy");
}
}
protected void tearDown() throws Exception {
cproject.getProject().delete(true, new NullProgressMonitor());
}
// you must have the Windows SDK installed and the INETSDK env var setup
public void testIndexTrilogyPerformanceTimes() throws CoreException {
if(Platform.getOS().equals(Platform.OS_WIN32)) {
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
TestScannerProvider.sIncludes = new String[]{EnvironmentReader.getEnvVar("INETSDK")+"\\Include"};
try {
CCoreInternals.getPDOMManager().setIndexAllFiles(cproject, true);
long start = System.currentTimeMillis();
CCorePlugin.getPDOMManager().reindex(cproject);
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
System.out.println("Took: "+(System.currentTimeMillis() - start));
IIndex index= CCorePlugin.getIndexManager().getIndex(cproject);
IBinding[] binding = index.findBindings(Pattern.compile("IXMLElementCollection"), false, IndexFilter.ALL, new NullProgressMonitor());
assertEquals(1, binding.length);
} finally {
TestScannerProvider.sIncludes = null;
}
}
}
}

View file

@ -0,0 +1,5 @@
#include <stdio.h>
#include <windows.h>
#include <iostream>
int main() { return 0; }

View file

@ -28,7 +28,6 @@ Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.internal.core;x-friends:="org.eclipse.cdt.ui", org.eclipse.cdt.internal.core;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.browser.util;x-internal:=true, org.eclipse.cdt.internal.core.browser.util;x-internal:=true,
org.eclipse.cdt.internal.core.dom;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring", org.eclipse.cdt.internal.core.dom;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring",
org.eclipse.cdt.internal.core.dom.bid,
org.eclipse.cdt.internal.core.dom.parser;x-friends:="org.eclipse.cdt.refactoring", org.eclipse.cdt.internal.core.dom.parser;x-friends:="org.eclipse.cdt.refactoring",
org.eclipse.cdt.internal.core.dom.parser.c;x-friends:="org.eclipse.cdt.refactoring", org.eclipse.cdt.internal.core.dom.parser.c;x-friends:="org.eclipse.cdt.refactoring",
org.eclipse.cdt.internal.core.dom.parser.cpp;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring", org.eclipse.cdt.internal.core.dom.parser.cpp;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring",

View file

@ -1,54 +0,0 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.bid;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.core.runtime.CoreException;
/**
*
*/
public abstract class AbstractCLocalBindingIdentity implements ICLocalBindingIdentity {
protected static final String SEP = " | "; //$NON-NLS-1$
protected PDOMLinkage linkage;
protected IBinding binding;
protected String extendedType; // cached
protected AbstractCLocalBindingIdentity(IBinding binding, PDOMLinkage linkage) {
if(binding==null || linkage==null)
throw new IllegalArgumentException();
this.binding = binding;
this.linkage = linkage;
}
public String getName() {
return binding.getName();
}
public abstract int getTypeConstant() throws CoreException;
public abstract String getExtendedType() throws CoreException;
public String toString() {
try {
return getName()+SEP+getTypeConstant()+SEP+getExtendedType();
} catch(CoreException ce) {
throw new RuntimeException(ce);
}
}
public char[] getNameCharArray() throws CoreException {
return binding.getNameCharArray();
}
}

View file

@ -1,77 +0,0 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.bid;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.core.runtime.CoreException;
/**
* An implementation of ILocalBindingIdentityComparator for CLocalBinding objects
*/
public class CLocalBindingIdentityComparator implements ILocalBindingIdentityComparator {
protected IBindingIdentityFactory factory;
public CLocalBindingIdentityComparator(IBindingIdentityFactory factory) {
this.factory = factory;
}
public int compare(IBinding a, IBinding b) throws CoreException {
ICLocalBindingIdentity aID = (ICLocalBindingIdentity) factory.getLocalBindingIdentity(a);
ICLocalBindingIdentity bID = (ICLocalBindingIdentity) factory.getLocalBindingIdentity(b);
return compare(aID, bID);
}
public int compare(ILocalBindingIdentity aID, IBinding b) throws CoreException {
ICLocalBindingIdentity bID = (ICLocalBindingIdentity) factory.getLocalBindingIdentity(b);
return compare((ICLocalBindingIdentity) aID, bID);
}
public int compare(IBinding a, ILocalBindingIdentity bID) throws CoreException {
ICLocalBindingIdentity aID = (ICLocalBindingIdentity) factory.getLocalBindingIdentity(a);
return compare(aID, bID);
}
public int compare(ILocalBindingIdentity aID, ILocalBindingIdentity bID) throws CoreException {
return compare((ICLocalBindingIdentity) aID, (ICLocalBindingIdentity) bID);
}
public int compare(ICLocalBindingIdentity aID, ICLocalBindingIdentity bID) throws CoreException {
int cmp = CharArrayUtils.compare(aID.getNameCharArray(), bID.getNameCharArray());
if(cmp!=0) return cmp;
int tyConA = aID.getTypeConstant();
int tyConB = bID.getTypeConstant();
if(tyConA != tyConB) {
return tyConA < tyConB ? -1 : 1;
}
cmp = aID.getExtendedType().compareTo(bID.getExtendedType());
return cmp;
}
public int compareNameAndConstOnly(IBinding a, char[] bName, int bConst) throws CoreException {
ICLocalBindingIdentity aID = (ICLocalBindingIdentity) factory.getLocalBindingIdentity(a);
int cmp = CharArrayUtils.compare(aID.getNameCharArray(), bName);
if(cmp!=0) {
return cmp;
}
int tyCon = aID.getTypeConstant();
if(tyCon != bConst) {
return tyCon < bConst ? -1 : 1;
}
return 0;
}
}

View file

@ -1,35 +0,0 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.bid;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.core.runtime.CoreException;
/**
* A factory for instances of binding identitys
*/
public interface IBindingIdentityFactory {
/**
* Return an IBindingIdentity instance for the named binding. No assumption
* is made about whether the IBinding parameter is from the PDOM or DOM
* @param binding the binding to create a IBindingIdentity for
* @return a binding identity instance
* @throws CoreException
*/
public ILocalBindingIdentity getLocalBindingIdentity(IBinding binding) throws CoreException;
/*
* aftodo - we might want to introduce a true binding identity (i.e. identifies globally
* not within a scope). I've no client code for this though.
*
* public IBindingIdentity getBindingIdentity(IBinding binding) throws CoreException
*/
}

View file

@ -1,37 +0,0 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.bid;
import org.eclipse.core.runtime.CoreException;
/**
* An IBindingIdentity instance uniquely defines a binding within a scope. Instances
* are provided by an IBindingIdentityFactory and used by datastructures within the
* PDOM to order binding records.
*/
public interface ICLocalBindingIdentity extends ILocalBindingIdentity {
/**
* Returns the constant associated with the coarse-grained type of the
* associated IBinding
* @return the constant associated with the coarse-grained type of the
* associated IBinding
* @throws CoreException
*/
public int getTypeConstant() throws CoreException;
/**
* Returns a String of unspecified format which uniquely identifies this
* binding within its scope
* @return
* @throws CoreException
*/
public String getExtendedType() throws CoreException;
}

View file

@ -1,28 +0,0 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.bid;
import org.eclipse.core.runtime.CoreException;
/**
* An ILocalBindingIdentity instance uniquely defines a binding within a scope.
* <p>
* All LocalBindingIdentity instances are required to order by name as the most significant
* component, and then by any other information. This is for indexing purposes.
*/
public interface ILocalBindingIdentity {
/**
* Get the name of the binding this identity represents
* @return the name of the binding this identity represents
* @throws CoreException
*/
public char[] getNameCharArray() throws CoreException;
}

View file

@ -1,52 +0,0 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.bid;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.core.runtime.CoreException;
/**
* A comparator for ILocalBindingIdentity objects
*/
public interface ILocalBindingIdentityComparator {
/**
*
* @param a
* @param b
* @return -1 if a&lt;b, 0 if a==b and 1 if a&gt;b
* @throws CoreException
*/
public int compare(IBinding a, IBinding b) throws CoreException;
/**
*
* @param a
* @param b
* @return -1 if a&lt;b, 0 if a==b and 1 if a&gt;b
* @throws CoreException
*/
public int compare(ILocalBindingIdentity a, IBinding b) throws CoreException;
/**
*
* @param a
* @param b
* @return -1 if a&lt;b, 0 if a==b and 1 if a&gt;b
* @throws CoreException
*/
public int compare(IBinding a, ILocalBindingIdentity b) throws CoreException;
/**
*
* @param a
* @param b
* @return -1 if a&lt;b, 0 if a==b and 1 if a&gt;b
* @throws CoreException
*/
public int compare(ILocalBindingIdentity a, ILocalBindingIdentity b) throws CoreException;
}

View file

@ -0,0 +1,87 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian 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:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
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.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;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
/**
* Look up bindings in BTree objects and IPDOMNode objects
*/
public class FindBinding {
public static class DefaultBindingBTreeComparator implements IBTreeComparator {
protected PDOM pdom;
public DefaultBindingBTreeComparator(PDOM pdom) {
this.pdom = pdom;
}
public int compare(int record1, int record2) throws CoreException {
IString nm1 = PDOMNamedNode.getDBName(pdom, record1);
IString nm2 = PDOMNamedNode.getDBName(pdom, record2);
return nm1.compare(nm2);
}
}
public static PDOMBinding findBinding(BTree btree, final PDOM pdom, final char[]name, final int[] constants) throws CoreException {
final PDOMBinding[] result = new PDOMBinding[1];
btree.accept(new IBTreeVisitor() {
public int compare(int record) throws CoreException {
IString nm1 = PDOMNamedNode.getDBName(pdom, record);
return nm1.compare(name);
}
public boolean visit(int record) throws CoreException {
result[0] = pdom.getBinding(record);
return false;
}
});
return result[0];
}
public static PDOMBinding findBinding(IPDOMNode node, final PDOM pdom, final char[]name, final int[] constants) {
final PDOMBinding[] result = new PDOMBinding[1];
try {
node.accept(new IPDOMVisitor() {
public boolean visit(IPDOMNode node) throws CoreException {
if(node instanceof PDOMNamedNode) {
PDOMNamedNode nnode = (PDOMNamedNode) node;
if(nnode.hasName(name)) {
int constant = nnode.getNodeType();
for(int i=0; i<constants.length; i++) {
if(constant==constants[i]) {
result[0] = (PDOMBinding) node;
throw new CoreException(Status.OK_STATUS);
}
}
}
}
return false; /* do not visit children of node */
}
public void leave(IPDOMNode node) throws CoreException {}
});
} catch(CoreException ce) {
if(ce.getStatus().getCode()==IStatus.OK) {
return result[0];
} else {
CCorePlugin.log(ce);
}
}
return null;
}
}

View file

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

View file

@ -1,74 +0,0 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.internal.core.dom.bid.CLocalBindingIdentityComparator;
import org.eclipse.cdt.internal.core.dom.bid.ILocalBindingIdentity;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Status;
public class FindEquivalentBinding implements IBTreeVisitor, IPDOMVisitor {
PDOMBinding result;
PDOMLinkage linkage;
ILocalBindingIdentity targetBID;
CLocalBindingIdentityComparator cmp;
public FindEquivalentBinding(PDOMLinkage linkage, ILocalBindingIdentity target) throws CoreException {
this.linkage = linkage;
this.targetBID = target;
this.cmp = new CLocalBindingIdentityComparator(linkage);
}
public FindEquivalentBinding(PDOMLinkage linkage, IBinding target) throws CoreException {
this.linkage = linkage;
this.targetBID = linkage.getLocalBindingIdentity(target);
this.cmp = new CLocalBindingIdentityComparator(linkage);
}
public boolean visit(int record) throws CoreException {
if(record!=0) {
PDOMNode node = linkage.getNode(record);
if(cmp.compare(targetBID, (IBinding) node)==0) {
result = (PDOMBinding) node;
return false;
}
}
return true;
}
public int compare(int record) throws CoreException {
PDOMNode node = linkage.getNode(record);
return cmp.compare((IBinding) node, targetBID);
}
public boolean visit(IPDOMNode node) throws CoreException {
if(node!=null && (node instanceof IBinding)) {
if(cmp.compare(targetBID, (IBinding) node)==0) {
result = (PDOMBinding) node;
// aftodo - there is probably no performance reason not
// to just return false here
throw new CoreException(Status.OK_STATUS);
}
}
return true;
}
public void leave(IPDOMNode node) throws CoreException {/*NO-OP*/}
public PDOMBinding getResult() {
return result;
}
}

View file

@ -191,12 +191,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
abstract protected int getRecordSize(); // superclass's implementation is no longer valid abstract protected int getRecordSize(); // superclass's implementation is no longer valid
public String toString() { public String toString() {
try { return getName() + " " + getNodeType(); //$NON-NLS-1$
return getLinkageImpl().getLocalBindingIdentity(this).toString();
} catch(CoreException ce) {
CCorePlugin.log(ce);
return super.toString();
}
} }
/** /**

View file

@ -31,8 +31,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexLinkage; import org.eclipse.cdt.core.index.IIndexLinkage;
import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.bid.CLocalBindingIdentityComparator;
import org.eclipse.cdt.internal.core.dom.bid.IBindingIdentityFactory;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.BTree; import org.eclipse.cdt.internal.core.pdom.db.BTree;
@ -48,7 +46,7 @@ import org.eclipse.core.runtime.CoreException;
* This class represents a collection of symbols that can be linked together at * This class represents a collection of symbols that can be linked together at
* link time. These are generally global symbols specific to a given language. * link time. These are generally global symbols specific to a given language.
*/ */
public abstract class PDOMLinkage extends PDOMNamedNode implements IBindingIdentityFactory, IIndexLinkage { public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage {
// record offsets // record offsets
private static final int ID_OFFSET = PDOMNamedNode.RECORD_SIZE + 0; private static final int ID_OFFSET = PDOMNamedNode.RECORD_SIZE + 0;
@ -157,16 +155,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IBindingIdent
return node; return node;
} }
public final IBTreeComparator getIndexComparator() { public abstract 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 addBinding(IASTName name) throws CoreException; public abstract PDOMBinding addBinding(IASTName name) throws CoreException;
@ -227,5 +216,5 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IBindingIdent
return null; return null;
} }
public abstract IBindingIdentityFactory getBindingIdentityFactory(); public abstract int getBindingType(IBinding binding);
} }

View file

@ -54,6 +54,12 @@ public abstract class PDOMNamedNode extends PDOMNode {
return db.getString(namerec); return db.getString(namerec);
} }
public static IString getDBName(PDOM pdom, int record) throws CoreException {
Database db = pdom.getDB();
int namerec = db.getInt(record + NAME);
return db.getString(namerec);
}
public char[] getNameCharArray() throws CoreException { public char[] getNameCharArray() throws CoreException {
return getDBName().getChars(); return getDBName().getChars();
} }
@ -87,5 +93,4 @@ public abstract class PDOMNamedNode extends PDOMNode {
int mask = 1 << offset; int mask = 1 << offset;
return (bitVector & mask) == mask; return (bitVector & mask) == mask;
} }
} }

View file

@ -1,47 +0,0 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.c;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.bid.AbstractCLocalBindingIdentity;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.core.runtime.CoreException;
public class CBindingIdentity extends AbstractCLocalBindingIdentity {
public CBindingIdentity(IBinding binding, PDOMLinkage linkage) {
super(binding, linkage);
}
public int getTypeConstant() throws CoreException {
if(binding instanceof PDOMBinding) {
return ((PDOMBinding) binding).getNodeType();
} else {
return ((PDOMCLinkage)linkage).getBindingType(binding);
}
}
public String getExtendedType() throws CoreException {
if(binding instanceof IFunction) {
IFunction f = (IFunction) binding;
try {
String mangled = ASTTypeUtil.getParameterTypeString(f.getType());
return mangled;
} catch(DOMException e) {
throw new CoreException(Util.createStatus(e));
}
}
return ""; //$NON-NLS-1$
}
}

View file

@ -36,17 +36,14 @@ import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage; import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.bid.IBindingIdentityFactory;
import org.eclipse.cdt.internal.core.dom.bid.ILocalBindingIdentity;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.FindBindingByLinkageConstant; import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
import org.eclipse.cdt.internal.core.pdom.dom.FindEquivalentBinding; import org.eclipse.cdt.internal.core.pdom.dom.FindBinding;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Status;
/** /**
* @author Doug Schaefer * @author Doug Schaefer
@ -148,7 +145,7 @@ class PDOMCLinkage extends PDOMLinkage {
return pdomBinding; return pdomBinding;
} }
protected int getBindingType(IBinding binding) { public int getBindingType(IBinding binding) {
if (binding instanceof IField) if (binding instanceof IField)
// This needs to be before variable // This needs to be before variable
return CFIELD; return CFIELD;
@ -178,23 +175,12 @@ class PDOMCLinkage extends PDOMLinkage {
// so if the binding is from another pdom it has to be adapted. // so if the binding is from another pdom it has to be adapted.
} }
FindEquivalentBinding visitor = new FindEquivalentBinding(this, binding);
PDOMNode parent = getAdaptedParent(binding); PDOMNode parent = getAdaptedParent(binding);
if (parent == this) { if (parent == this) {
getIndex().accept(visitor); return FindBinding.findBinding(getIndex(), getPDOM(), binding.getNameCharArray(), new int[] {getBindingType(binding)});
return visitor.getResult();
} else if (parent instanceof IPDOMMemberOwner) { } else if (parent instanceof IPDOMMemberOwner) {
IPDOMMemberOwner owner = (IPDOMMemberOwner)parent; return FindBinding.findBinding(parent, getPDOM(), binding.getNameCharArray(), new int[] {getBindingType(binding)});
try {
owner.accept(visitor);
} catch (CoreException e) {
if (e.getStatus().equals(Status.OK_STATUS))
return visitor.getResult();
else
throw e;
}
} }
return null; return null;
@ -241,47 +227,25 @@ class PDOMCLinkage extends PDOMLinkage {
} else if (parent instanceof ICASTElaboratedTypeSpecifier) { } else if (parent instanceof ICASTElaboratedTypeSpecifier) {
constant = CSTRUCTURE; constant = CSTRUCTURE;
} else if (parent instanceof IASTNamedTypeSpecifier){ } else if (parent instanceof IASTNamedTypeSpecifier){
FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CSTRUCTURE); return FindBinding.findBinding(getIndex(), getPDOM(), name.toCharArray(), new int [] {CSTRUCTURE, CENUMERATION, CTYPEDEF});
getIndex().accept(finder);
PDOMBinding result = finder.getResult();
if(result==null) {
finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CENUMERATION);
getIndex().accept(finder);
result = finder.getResult();
}
if(result==null) {
finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CTYPEDEF);
getIndex().accept(finder);
result = finder.getResult();
}
return result;
} else { } else {
return null; return null;
} }
FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant(this, name.toCharArray(), constant); return FindBinding.findBinding(getIndex(), getPDOM(), name.toCharArray(), new int[] {constant});
getIndex().accept(finder);
return finder.getResult();
} }
public PDOMNode addType(PDOMNode parent, IType type) throws CoreException { public PDOMNode addType(PDOMNode parent, IType type) throws CoreException {
if (type instanceof ICBasicType) { if (type instanceof ICBasicType) {
return new PDOMCBasicType(pdom, parent, (ICBasicType)type); return new PDOMCBasicType(pdom, parent, (ICBasicType)type);
} else if (type instanceof ICompositeType) { } else if (type instanceof ICompositeType) {
FindEquivalentBinding feb = new FindEquivalentBinding(this,(ICompositeType)type); ICompositeType ctype = (ICompositeType) type;
getIndex().accept(feb); return FindBinding.findBinding(getIndex(), getPDOM(), ctype.getNameCharArray(), new int[] {getBindingType(ctype)});
if(feb.getResult()!=null) {
return feb.getResult();
}
} }
return super.addType(parent, type); return super.addType(parent, type);
} }
public ILocalBindingIdentity getLocalBindingIdentity(IBinding b) throws CoreException { public IBTreeComparator getIndexComparator() {
return new CBindingIdentity(b, this); return new FindBinding.DefaultBindingBTreeComparator(getPDOM());
}
public IBindingIdentityFactory getBindingIdentityFactory() {
return this;
} }
} }

View file

@ -1,112 +0,0 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.bid.AbstractCLocalBindingIdentity;
import org.eclipse.cdt.internal.core.dom.bid.ICLocalBindingIdentity;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.core.runtime.CoreException;
public class CPPBindingIdentity extends AbstractCLocalBindingIdentity {
public CPPBindingIdentity(IBinding binding, PDOMLinkage linkage) {
super(binding, linkage);
}
public int getTypeConstant() throws CoreException {
if(binding instanceof PDOMBinding) {
return ((PDOMBinding) binding).getNodeType();
} else {
return ((PDOMCPPLinkage)linkage).getBindingType(binding);
}
}
public String getExtendedType() throws CoreException {
try {
if(binding instanceof ICPPFunction) {
return renderFunctionType(((ICPPFunction)binding).getType());
} else if(binding instanceof ICPPMethod) {
return renderFunctionType(((ICPPMethod)binding).getType());
} else {
return ""; //$NON-NLS-1$
}
} catch(DOMException e) {
throw new CoreException(Util.createStatus(e));
}
}
protected static String renderTypes(IType[] types) throws DOMException {
if(types.length==1) {
if(types[0] instanceof IBasicType) {
if(((IBasicType)types[0]).getType()==IBasicType.t_void) {
types = new IType[0];
}
}
}
StringBuffer result = new StringBuffer();
result.append('(');
for(int i=0; i<types.length; i++) {
if (i>0) {
result.append(',');
}
result.append(ASTTypeUtil.getType(types[i]));
}
result.append(')');
return result.toString();
}
private String renderFunctionType(IFunctionType type) throws DOMException {
IType[] params = type.getParameterTypes();
return renderTypes(params);
}
public static class Holder implements ICLocalBindingIdentity {
String name;
int type;
String mangledExtendedType;
public Holder(String name, int type, IType[] types) throws DOMException {
this.name = name;
this.type = type;
mangledExtendedType = renderTypes(types);
}
public int getTypeConstant() throws CoreException {
return type;
}
public String getName() throws CoreException {
return name;
}
public String getExtendedType() throws CoreException {
return mangledExtendedType;
}
public String toString() {
return name+" "+type+" "+mangledExtendedType; //$NON-NLS-1$ //$NON-NLS-2$
}
public char[] getNameCharArray() throws CoreException {
return name.toCharArray();
}
}
}

View file

@ -0,0 +1,154 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian 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:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
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.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IType;
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.IBTreeVisitor;
import org.eclipse.cdt.internal.core.pdom.db.IString;
import org.eclipse.cdt.internal.core.pdom.dom.FindBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
/**
* Look up bindings in BTree objects and IPDOMNode objects. This additionally
* takes into account function/method parameters for overloading.
*/
public class CPPFindBinding extends FindBinding {
public static PDOMBinding findBinding(BTree btree, final PDOM pdom, final char[]name, final int c2, final IType[] types) throws CoreException {
final PDOMBinding[] result = new PDOMBinding[1];
try {
final int ty2 = PDOMCPPFunction.getSignatureMemento(types);
btree.accept(new IBTreeVisitor() {
public int compare(int record) throws CoreException {
IString nm1 = PDOMNamedNode.getDBName(pdom, record);
int cmp = nm1.compare(name);
if(cmp==0) {
int c1 = PDOMNode.getNodeType(pdom, record);
cmp = c1 < c2 ? -1 : (c1 > c2 ? 1 : 0);
if(cmp==0) {
PDOMBinding binding = pdom.getBinding(record);
if(binding instanceof PDOMCPPFunction) {
int ty1 = ((PDOMCPPFunction)binding).getSignatureMemento();
cmp = ty1 < ty2 ? -1 : (ty1 > ty2 ? 1 : 0);
}
}
}
return cmp;
}
public boolean visit(int record) throws CoreException {
result[0] = pdom.getBinding(record);
return false;
}
});
} catch(DOMException de) {
CCorePlugin.log(de);
}
return result[0];
}
public static PDOMBinding findBinding(PDOMNode node, final PDOM pdom, final char[]name, final int constant, final IType[] types) {
final PDOMBinding[] result = new PDOMBinding[1];
try {
final int ty2 = PDOMCPPFunction.getSignatureMemento(types);
node.accept(new IPDOMVisitor() {
public boolean visit(IPDOMNode binding) throws CoreException {
if(binding instanceof PDOMNamedNode) {
PDOMNamedNode nnode = (PDOMNamedNode) binding;
if(nnode.hasName(name)) {
if(nnode.getNodeType() == constant) {
if(binding instanceof PDOMCPPFunction) {
int ty1 = ((PDOMCPPFunction)binding).getSignatureMemento();
if(ty1==ty2) {
result[0] = (PDOMBinding) binding;
throw new CoreException(Status.OK_STATUS);
}
}
}
}
}
return false;
}
public void leave(IPDOMNode node) throws CoreException {}
});
} catch(CoreException ce) {
if(ce.getStatus().getCode()==IStatus.OK) {
return result[0];
} else {
CCorePlugin.log(ce);
}
} catch(DOMException de) {
CCorePlugin.log(de);
}
return null;
}
public static PDOMBinding findBinding(BTree btree, PDOMLinkage linkage, IBinding binding) throws CoreException {
if(binding instanceof IFunction) {
try {
IFunctionType type = ((IFunction) binding).getType();
return findBinding(btree, linkage.getPDOM(), binding.getNameCharArray(), linkage.getBindingType(binding), type.getParameterTypes());
} catch(DOMException de) {
CCorePlugin.log(de);
return null;
}
}
return findBinding(btree, linkage.getPDOM(), binding.getNameCharArray(), new int [] {linkage.getBindingType(binding)});
}
public static PDOMBinding findBinding(PDOMNode node, PDOMLinkage linkage, IBinding binding) {
if(binding instanceof IFunction) {
try {
IFunctionType type = ((IFunction) binding).getType();
return findBinding(node, linkage.getPDOM(), binding.getNameCharArray(), linkage.getBindingType(binding), type.getParameterTypes());
} catch(DOMException de) {
CCorePlugin.log(de);
return null;
}
}
return findBinding(node, linkage.getPDOM(), binding.getNameCharArray(), new int[] {linkage.getBindingType(binding)});
}
public static class CPPBindingBTreeComparator extends FindBinding.DefaultBindingBTreeComparator {
public CPPBindingBTreeComparator(PDOM pdom) {
super(pdom);
}
public int compare(int record1, int record2) throws CoreException {
int cmp = super.compare(record1, record2);
if(cmp==0) {
PDOMBinding binding1 = pdom.getBinding(record1);
PDOMBinding binding2 = pdom.getBinding(record2);
if(binding1 instanceof PDOMCPPFunction && binding2 instanceof PDOMCPPFunction) {
int ty1 = ((PDOMCPPFunction)binding1).getSignatureMemento();
int ty2 = ((PDOMCPPFunction)binding2).getSignatureMemento();
cmp = ty1 < ty2 ? -1 : (ty1 > ty2 ? 1 : 0);
}
}
return cmp;
}
}
}

View file

@ -42,19 +42,16 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.bid.ILocalBindingIdentity;
import org.eclipse.cdt.internal.core.index.IIndexProxyBinding; import org.eclipse.cdt.internal.core.index.IIndexProxyBinding;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList; import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList;
import org.eclipse.cdt.internal.core.pdom.dom.FindBindingByLinkageConstant; import org.eclipse.cdt.internal.core.pdom.dom.FindBinding;
import org.eclipse.cdt.internal.core.pdom.dom.FindEquivalentBinding;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Status;
/** /**
* @author Doug Schaefer * @author Doug Schaefer
@ -388,21 +385,7 @@ ICPPClassScope, IPDOMMemberOwner {
try { try {
IType[] types = PDOMCPPLinkage.getTypes(fce.getParameterExpression()); IType[] types = PDOMCPPLinkage.getTypes(fce.getParameterExpression());
if(types!=null) { if(types!=null) {
ILocalBindingIdentity bid = new CPPBindingIdentity.Holder( return CPPFindBinding.findBinding(this, getPDOM(), name.toCharArray(), PDOMCPPLinkage.CPPFUNCTION, types);
new String(name.toCharArray()),
PDOMCPPLinkage.CPPFUNCTION,
types);
FindEquivalentBinding feb = new FindEquivalentBinding(getLinkageImpl(), bid);
try {
accept(feb);
} catch(CoreException e) {
if (e.getStatus().equals(Status.OK_STATUS)) {
return feb.getResult();
} else {
CCorePlugin.log(e);
}
}
return feb.getResult();
} }
} catch(DOMException de) { } catch(DOMException de) {
CCorePlugin.log(de); CCorePlugin.log(de);
@ -419,17 +402,7 @@ ICPPClassScope, IPDOMMemberOwner {
} }
private IBinding searchCurrentScope(char[] name, int constant) throws CoreException { private IBinding searchCurrentScope(char[] name, int constant) throws CoreException {
FindBindingByLinkageConstant visitor = new FindBindingByLinkageConstant(getLinkageImpl(), name, constant); return FindBinding.findBinding(this, getPDOM(), name, new int [] {constant});
try {
accept(visitor);
} catch(CoreException e) {
if (e.getStatus().equals(Status.OK_STATUS)) {
return visitor.getResult();
} else {
CCorePlugin.log(e);
}
}
return null;
} }
// Not implemented // Not implemented

View file

@ -13,7 +13,9 @@
package org.eclipse.cdt.internal.core.pdom.dom.cpp; package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException; 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.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IParameter;
@ -48,16 +50,21 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, ICPPFuncti
*/ */
private static final int FIRST_PARAM = PDOMBinding.RECORD_SIZE + 4; private static final int FIRST_PARAM = PDOMBinding.RECORD_SIZE + 4;
/**
* Offset of hash of parameter information to allow fast comparison
*/
private static final int SIGNATURE_MEMENTO = PDOMBinding.RECORD_SIZE + 8;
/** /**
* Offset of annotation information (relative to the beginning of the * Offset of annotation information (relative to the beginning of the
* record). * record).
*/ */
private static final int ANNOTATION = PDOMBinding.RECORD_SIZE + 8; // byte protected static final int ANNOTATION = PDOMBinding.RECORD_SIZE + 12; // byte
/** /**
* The size in bytes of a PDOMCPPFunction record in the database. * The size in bytes of a PDOMCPPFunction record in the database.
*/ */
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 9; protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 13;
public PDOMCPPFunction(PDOM pdom, PDOMNode parent, ICPPFunction function) throws CoreException { public PDOMCPPFunction(PDOM pdom, PDOMNode parent, ICPPFunction function) throws CoreException {
super(pdom, parent, function.getNameCharArray()); super(pdom, parent, function.getNameCharArray());
@ -72,6 +79,8 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, ICPPFuncti
setFirstParameter(new PDOMCPPParameter(pdom, this, params[i])); setFirstParameter(new PDOMCPPParameter(pdom, this, params[i]));
} }
db.putByte(record + ANNOTATION, PDOMCPPAnnotation.encodeAnnotation(binding)); db.putByte(record + ANNOTATION, PDOMCPPAnnotation.encodeAnnotation(binding));
IFunctionType ftype = function.getType();
db.putInt(record + SIGNATURE_MEMENTO, getSignatureMemento(ftype.getParameterTypes()));
} catch (DOMException e) { } catch (DOMException e) {
throw new CoreException(Util.createStatus(e)); throw new CoreException(Util.createStatus(e));
} }
@ -81,6 +90,14 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, ICPPFuncti
super(pdom, bindingRecord); super(pdom, bindingRecord);
} }
public int getSignatureMemento() throws CoreException {
return pdom.getDB().getInt(record + SIGNATURE_MEMENTO);
}
public static int getSignatureMemento(PDOM pdom, int record) throws CoreException {
return pdom.getDB().getInt(record + SIGNATURE_MEMENTO);
}
protected int getRecordSize() { protected int getRecordSize() {
return RECORD_SIZE; return RECORD_SIZE;
} }
@ -201,4 +218,29 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, ICPPFuncti
throw new PDOMNotImplementedError(); throw new PDOMNotImplementedError();
} }
public static int getSignatureMemento(IType[] types) throws DOMException {
if(types.length==1) {
if(types[0] instanceof IBasicType) {
if(((IBasicType)types[0]).getType()==IBasicType.t_void) {
types = new IType[0];
}
}
}
StringBuffer result = new StringBuffer();
result.append('(');
for(int i=0; i<types.length; i++) {
if (i>0) {
result.append(',');
}
result.append(ASTTypeUtil.getType(types[i]));
}
result.append(')');
return result.toString().hashCode();
}
public static int getSignatureMemento(IFunctionType type) throws DOMException {
IType[] params = type.getParameterTypes();
return getSignatureMemento(params);
}
} }

View file

@ -56,29 +56,26 @@ import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.bid.IBindingIdentityFactory;
import org.eclipse.cdt.internal.core.dom.bid.ILocalBindingIdentity;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBlockScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBlockScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitMethod; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitMethod;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.FindBindingByLinkageConstant; import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
import org.eclipse.cdt.internal.core.pdom.dom.FindEquivalentBinding; import org.eclipse.cdt.internal.core.pdom.dom.FindBinding;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Status;
/** /**
* @author Doug Schaefer * @author Doug Schaefer
* *
*/ */
class PDOMCPPLinkage extends PDOMLinkage { public class PDOMCPPLinkage extends PDOMLinkage {
public PDOMCPPLinkage(PDOM pdom, int record) { public PDOMCPPLinkage(PDOM pdom, int record) {
super(pdom, record); super(pdom, record);
} }
@ -211,7 +208,7 @@ class PDOMCPPLinkage extends PDOMLinkage {
return pdomBinding; return pdomBinding;
} }
protected int getBindingType(IBinding binding) { public int getBindingType(IBinding binding) {
if (binding instanceof ICPPTemplateDefinition) if (binding instanceof ICPPTemplateDefinition)
// this must be before class type // this must be before class type
return 0; return 0;
@ -257,25 +254,14 @@ class PDOMCPPLinkage extends PDOMLinkage {
// so if the binding is from another pdom it has to be adapted. // so if the binding is from another pdom it has to be adapted.
} }
FindEquivalentBinding visitor = new FindEquivalentBinding(this, binding);
PDOMNode parent = getAdaptedParent(binding); PDOMNode parent = getAdaptedParent(binding);
if (parent == this) { if (parent == this) {
getIndex().accept(visitor); return CPPFindBinding.findBinding(getIndex(), this, binding);
return visitor.getResult();
} else if (parent instanceof IPDOMMemberOwner) { } else if (parent instanceof IPDOMMemberOwner) {
IPDOMMemberOwner owner = (IPDOMMemberOwner)parent; return CPPFindBinding.findBinding(parent, this, binding);
try {
owner.accept(visitor);
} catch (CoreException e) {
if (e.getStatus().equals(Status.OK_STATUS))
return visitor.getResult();
else
throw e;
}
} else if (parent instanceof PDOMCPPNamespace) { } else if (parent instanceof PDOMCPPNamespace) {
((PDOMCPPNamespace)parent).getIndex().accept(visitor); return CPPFindBinding.findBinding(((PDOMCPPNamespace)parent).getIndex(), this, binding);
return visitor.getResult();
} }
return null; return null;
@ -344,13 +330,12 @@ class PDOMCPPLinkage extends PDOMLinkage {
IASTExpression left = ((IASTBinaryExpression) epParent).getOperand1(); IASTExpression left = ((IASTBinaryExpression) epParent).getOperand1();
IType type = CPPSemantics.getUltimateType(left.getExpressionType(), false); IType type = CPPSemantics.getUltimateType(left.getExpressionType(), false);
if (type instanceof IFunctionType) { if (type instanceof IFunctionType) {
ILocalBindingIdentity lbi = new CPPBindingIdentity.Holder( return CPPFindBinding.findBinding(getIndex(),
new String(name.toCharArray()), getPDOM(),
name.toCharArray(),
CPPFUNCTION, CPPFUNCTION,
((IFunctionType) type).getParameterTypes()); ((IFunctionType) type).getParameterTypes()
FindEquivalentBinding feb = new FindEquivalentBinding(this, lbi); );
getIndex().accept(feb);
return feb.getResult();
} }
} }
} }
@ -387,17 +372,7 @@ class PDOMCPPLinkage extends PDOMLinkage {
IType type = ((ICPPVariable)fieldOwnerBinding).getType(); IType type = ((ICPPVariable)fieldOwnerBinding).getType();
if(type instanceof ICompositeType) { if(type instanceof ICompositeType) {
PDOMBinding pdomFOB = adaptBinding( (ICompositeType) type); PDOMBinding pdomFOB = adaptBinding( (ICompositeType) type);
FindBindingByLinkageConstant visitor = new FindBindingByLinkageConstant(this, name.toCharArray(), PDOMCPPLinkage.CPPFIELD); return FindBinding.findBinding(pdomFOB, getPDOM(), name.toCharArray(), new int [] {PDOMCPPLinkage.CPPFIELD});
try {
pdomFOB.accept(visitor);
} catch (CoreException e) {
if (e.getStatus().equals(Status.OK_STATUS)) {
return visitor.getResult();
}
else {
throw e;
}
}
} }
} }
} }
@ -417,12 +392,10 @@ class PDOMCPPLinkage extends PDOMLinkage {
} }
private PDOMBinding searchCurrentScope(char[] name, int constant) throws CoreException { private PDOMBinding searchCurrentScope(char[] name, int constant) throws CoreException {
FindBindingByLinkageConstant visitor = new FindBindingByLinkageConstant(getLinkageImpl(), name, constant); return FindBinding.findBinding(getIndex(), getPDOM(), name, new int [] {constant});
getIndex().accept(visitor);
return visitor.getResult();
} }
/** /**
* Read type information from the AST or null if the types could not be determined * Read type information from the AST or null if the types could not be determined
* @param paramExp the parameter expression to get types for (null indicates void function/method) * @param paramExp the parameter expression to get types for (null indicates void function/method)
@ -477,26 +450,19 @@ class PDOMCPPLinkage extends PDOMLinkage {
IType[] types = getTypes(paramExp); IType[] types = getTypes(paramExp);
if (types != null) { if (types != null) {
IBinding parentBinding = id.getName().getBinding(); IBinding parentBinding = id.getName().getBinding();
ILocalBindingIdentity bid = null;
if (parentBinding instanceof ICPPVariable) { if (parentBinding instanceof ICPPVariable) {
ICPPVariable v = (ICPPVariable) parentBinding; ICPPVariable v = (ICPPVariable) parentBinding;
IType type = v.getType(); IType type = v.getType();
if (type instanceof PDOMBinding) { if (type instanceof PDOMBinding) {
bid = new CPPBindingIdentity.Holder(new String(name return CPPFindBinding.findBinding(
.toCharArray()), CPPMETHOD, types); ((PDOMBinding) type),
FindEquivalentBinding feb = new FindEquivalentBinding(this, getPDOM(),
bid); name.toCharArray(),
try { CPPMETHOD,
((PDOMBinding) type).accept(feb); types
} catch (CoreException e) { );
if (e.getStatus().equals(Status.OK_STATUS)) {
return feb.getResult();
} else {
throw e;
}
}
} }
} else { } else {
IASTNode expPNode = callExp.getParent(); IASTNode expPNode = callExp.getParent();
@ -508,31 +474,23 @@ class PDOMCPPLinkage extends PDOMLinkage {
IASTExpression left = bExp.getOperand1(); IASTExpression left = bExp.getOperand1();
IType t = CPPSemantics.getUltimateType(left.getExpressionType(), false); IType t = CPPSemantics.getUltimateType(left.getExpressionType(), false);
if (t instanceof PDOMCPPClassType) { if (t instanceof PDOMCPPClassType) {
bid = new CPPBindingIdentity.Holder( return CPPFindBinding.findBinding(
new String(name.toCharArray()), ((PDOMCPPClassType) t),
getPDOM(),
name.toCharArray(),
CPPMETHOD, CPPMETHOD,
types); types
FindEquivalentBinding feb = new FindEquivalentBinding(this, bid); );
try {
((PDOMCPPClassType) t).accept(feb);
} catch (CoreException e) {
if (e.getStatus().equals(Status.OK_STATUS)) {
return feb.getResult();
} else {
throw e;
}
}
return null;
} }
} }
} else { // filescope } else { // filescope
bid = new CPPBindingIdentity.Holder( return CPPFindBinding.findBinding(
new String(name.toCharArray()), getIndex(),
getPDOM(),
name.toCharArray(),
CPPFUNCTION, CPPFUNCTION,
types); types
FindEquivalentBinding feb = new FindEquivalentBinding(this,bid); );
getIndex().accept(feb);
return feb.getResult();
} }
} }
} }
@ -549,19 +507,9 @@ class PDOMCPPLinkage extends PDOMLinkage {
if(index!=-1) { if(index!=-1) {
if (index == 0) { if (index == 0) {
// we are at the root // we are at the root
FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant( return FindBinding.findBinding(getIndex(), getPDOM(), name.toCharArray(), new int[]{
this, name.toCharArray(), CPPNAMESPACE); CPPNAMESPACE, CPPCLASSTYPE, CPPNAMESPACEALIAS
});
getIndex().accept(finder);
if (finder.getResult() == null) {
finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CPPCLASSTYPE);
getIndex().accept(finder);
}
if (finder.getResult() == null) {
finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CPPNAMESPACEALIAS);
getIndex().accept(finder);
}
return finder.getResult();
} else { } else {
try { try {
PDOMBinding binding = adaptBinding(names[index-1].getBinding()); PDOMBinding binding = adaptBinding(names[index-1].getBinding());
@ -638,11 +586,7 @@ class PDOMCPPLinkage extends PDOMLinkage {
} }
} }
public ILocalBindingIdentity getLocalBindingIdentity(IBinding b) throws CoreException { public IBTreeComparator getIndexComparator() {
return new CPPBindingIdentity(b, this); return new CPPFindBinding.CPPBindingBTreeComparator(pdom);
}
public IBindingIdentityFactory getBindingIdentityFactory() {
return this;
} }
} }

View file

@ -16,7 +16,6 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IFunctionType; 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.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
@ -25,7 +24,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation; import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation;
@ -33,38 +31,20 @@ import org.eclipse.core.runtime.CoreException;
/** /**
* @author Doug Schaefer * @author Doug Schaefer
* *
*/ */
class PDOMCPPMethod extends PDOMCPPBinding implements ICPPMethod, ICPPFunctionType { class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod, ICPPFunctionType {
/** /**
* Offset of total number of method parameters (relative to the * Offset of remaining annotation information (relative to the beginning of
* beginning of the record). * the record).
*/ */
private static final int NUM_PARAMS = PDOMBinding.RECORD_SIZE + 0; private static final int ANNOTATION1 = PDOMCPPFunction.RECORD_SIZE; // byte
/**
* Offset of pointer to the first parameter of this method (relative to
* the beginning of the record).
*/
private static final int FIRST_PARAM = PDOMBinding.RECORD_SIZE + 4;
/**
* Offset of first byte of annotation information (relative to the
* beginning of the record).
*/
private static final int ANNOTATION0 = PDOMBinding.RECORD_SIZE + 8; // byte
/**
* Offset of remaining annotation information (relative to the
* beginning of the record).
*/
private static final int ANNOTATION1 = PDOMBinding.RECORD_SIZE + 9; // byte
/** /**
* The size in bytes of a PDOMCPPMethod record in the database. * The size in bytes of a PDOMCPPMethod record in the database.
*/ */
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 10; protected static final int RECORD_SIZE = PDOMCPPFunction.RECORD_SIZE + 1;
/** /**
* The bit offset of CV qualifier flags within ANNOTATION1. * The bit offset of CV qualifier flags within ANNOTATION1.
@ -72,23 +52,16 @@ class PDOMCPPMethod extends PDOMCPPBinding implements ICPPMethod, ICPPFunctionTy
private static final int CV_OFFSET = 2; private static final int CV_OFFSET = 2;
public PDOMCPPMethod(PDOM pdom, PDOMNode parent, ICPPMethod method) throws CoreException { public PDOMCPPMethod(PDOM pdom, PDOMNode parent, ICPPMethod method) throws CoreException {
super(pdom, parent, method.getNameCharArray()); super(pdom, parent, method);
Database db = pdom.getDB(); Database db = pdom.getDB();
try { try {
IParameter[] params = method.getParameters();
db.putInt(record + NUM_PARAMS, params.length);
for (int i=0; i<params.length; ++i) {
setFirstParameter(new PDOMCPPParameter(pdom, this, params[i]));
}
ICPPFunctionType type = (ICPPFunctionType) method.getType(); ICPPFunctionType type = (ICPPFunctionType) method.getType();
byte annotation = 0; byte annotation = 0;
annotation |= PDOMCAnnotation.encodeCVQualifiers(type) << CV_OFFSET; annotation |= PDOMCAnnotation.encodeCVQualifiers(type) << CV_OFFSET;
annotation |= PDOMCPPAnnotation.encodeExtraAnnotation(method); annotation |= PDOMCPPAnnotation.encodeExtraAnnotation(method);
db.putByte(record + ANNOTATION0, PDOMCPPAnnotation.encodeAnnotation(method)); db.putByte(record + ANNOTATION1, annotation);
db.putByte(record + ANNOTATION1, annotation);
} catch (DOMException e) { } catch (DOMException e) {
throw new CoreException(Util.createStatus(e)); throw new CoreException(Util.createStatus(e));
} }
@ -105,19 +78,7 @@ class PDOMCPPMethod extends PDOMCPPBinding implements ICPPMethod, ICPPFunctionTy
public int getNodeType() { public int getNodeType() {
return PDOMCPPLinkage.CPPMETHOD; return PDOMCPPLinkage.CPPMETHOD;
} }
public PDOMCPPParameter getFirstParameter() throws CoreException {
int rec = pdom.getDB().getInt(record + FIRST_PARAM);
return rec != 0 ? new PDOMCPPParameter(pdom, rec) : null;
}
public void setFirstParameter(PDOMCPPParameter param) throws CoreException {
if (param != null)
param.setNextParameter(getFirstParameter());
int rec = param != null ? param.getRecord() : 0;
pdom.getDB().putInt(record + FIRST_PARAM, rec);
}
public boolean isVirtual() throws DOMException { public boolean isVirtual() throws DOMException {
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.VIRTUAL_OFFSET); return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.VIRTUAL_OFFSET);
} }
@ -130,26 +91,6 @@ class PDOMCPPMethod extends PDOMCPPBinding implements ICPPMethod, ICPPFunctionTy
throw new PDOMNotImplementedError(); throw new PDOMNotImplementedError();
} }
public boolean isInline() throws DOMException {
return getBit(getByte(record + ANNOTATION0), PDOMCAnnotation.INLINE_OFFSET);
}
public IParameter[] getParameters() throws DOMException {
try {
int n = pdom.getDB().getInt(record + NUM_PARAMS);
IParameter[] params = new IParameter[n];
PDOMCPPParameter param = getFirstParameter();
while (param != null) {
params[--n] = param;
param = param.getNextParameter();
}
return params;
} catch (CoreException e) {
CCorePlugin.log(e);
return new IParameter[0];
}
}
public IScope getFunctionScope() throws DOMException { public IScope getFunctionScope() throws DOMException {
throw new PDOMNotImplementedError(); throw new PDOMNotImplementedError();
} }
@ -158,36 +99,28 @@ class PDOMCPPMethod extends PDOMCPPBinding implements ICPPMethod, ICPPFunctionTy
return this; return this;
} }
public boolean isStatic() throws DOMException {
return getBit(getByte(record + ANNOTATION0), PDOMCAnnotation.STATIC_OFFSET);
}
public boolean isExtern() throws DOMException { public boolean isExtern() throws DOMException {
// ISO/IEC 14882:2003 9.2.6 // ISO/IEC 14882:2003 9.2.6
return false; return false;
} }
public boolean isAuto() throws DOMException { public boolean isAuto() throws DOMException {
// ISO/IEC 14882:2003 9.2.6 // ISO/IEC 14882:2003 9.2.6
return false; return false;
} }
public boolean isRegister() throws DOMException { public boolean isRegister() throws DOMException {
// ISO/IEC 14882:2003 9.2.6 // ISO/IEC 14882:2003 9.2.6
return false; return false;
}
public boolean takesVarArgs() throws DOMException {
return getBit(getByte(record + ANNOTATION0), PDOMCAnnotation.VARARGS_OFFSET);
} }
public int getVisibility() throws DOMException { public int getVisibility() throws DOMException {
return PDOMCPPAnnotation.getVisibility(getByte(record + ANNOTATION0)); return PDOMCPPAnnotation.getVisibility(getByte(record + ANNOTATION));
} }
public ICPPClassType getClassOwner() throws DOMException { public ICPPClassType getClassOwner() throws DOMException {
try { try {
return (ICPPClassType)getParentNode(); return (ICPPClassType) getParentNode();
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
return null; return null;
@ -198,25 +131,9 @@ class PDOMCPPMethod extends PDOMCPPBinding implements ICPPMethod, ICPPFunctionTy
throw new PDOMNotImplementedError(); throw new PDOMNotImplementedError();
} }
public IType[] getParameterTypes() throws DOMException {
try {
int n = pdom.getDB().getInt(record + NUM_PARAMS);
IType[] types = new IType[n];
PDOMCPPParameter param = getFirstParameter();
while (param != null) {
types[--n] = param.getType();
param = param.getNextParameter();
}
return types;
} catch (CoreException e) {
CCorePlugin.log(e);
return new IType[0];
}
}
public IType getReturnType() throws DOMException { public IType getReturnType() throws DOMException {
return null; return null;
// TODO throw new PDOMNotImplementedError(); // TODO throw new PDOMNotImplementedError();
} }
public boolean isConst() { public boolean isConst() {
@ -231,7 +148,7 @@ class PDOMCPPMethod extends PDOMCPPBinding implements ICPPMethod, ICPPFunctionTy
if (type == this) if (type == this)
return true; return true;
if (type instanceof PDOMCPPMethod) if (type instanceof PDOMCPPMethod)
return getRecord() == ((PDOMCPPMethod)type).getRecordSize(); return getRecord() == ((PDOMCPPMethod) type).getRecordSize();
// TODO further analysis to compare with DOM objects // TODO further analysis to compare with DOM objects
return false; return false;
} }

View file

@ -27,13 +27,11 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.bid.ILocalBindingIdentity;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.BTree; import org.eclipse.cdt.internal.core.pdom.db.BTree;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor; import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
import org.eclipse.cdt.internal.core.pdom.dom.FindBindingByLinkageConstant; import org.eclipse.cdt.internal.core.pdom.dom.FindBinding;
import org.eclipse.cdt.internal.core.pdom.dom.FindBindingsInBTree; import org.eclipse.cdt.internal.core.pdom.dom.FindBindingsInBTree;
import org.eclipse.cdt.internal.core.pdom.dom.FindEquivalentBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
@ -176,10 +174,10 @@ implements ICPPNamespace, ICPPNamespaceScope {
&& ((ICPPASTQualifiedName)name.getParent()).getLastName() != name) && ((ICPPASTQualifiedName)name.getParent()).getLastName() != name)
? PDOMCPPLinkage.CPPNAMESPACE : PDOMCPPLinkage.CPPVARIABLE; ? PDOMCPPLinkage.CPPNAMESPACE : PDOMCPPLinkage.CPPVARIABLE;
IBinding result = searchCurrentScope(name.toCharArray(), desiredType); IBinding result = searchCurrentScope(name.toCharArray(), new int[] {desiredType});
if(result!=null) if(result!=null)
return result; return result;
return searchCurrentScope(name.toCharArray(), PDOMCPPLinkage.CPPTYPEDEF); return searchCurrentScope(name.toCharArray(), new int[] {PDOMCPPLinkage.CPPTYPEDEF});
} }
} else if (parent instanceof IASTNamedTypeSpecifier) { } else if (parent instanceof IASTNamedTypeSpecifier) {
return searchCurrentScope(name.toCharArray(), new int[] { return searchCurrentScope(name.toCharArray(), new int[] {
@ -200,13 +198,7 @@ implements ICPPNamespace, ICPPNamespaceScope {
try { try {
IType[] types = PDOMCPPLinkage.getTypes(fce.getParameterExpression()); IType[] types = PDOMCPPLinkage.getTypes(fce.getParameterExpression());
if(types!=null) { if(types!=null) {
ILocalBindingIdentity bid = new CPPBindingIdentity.Holder( return CPPFindBinding.findBinding(getIndex(), getPDOM(), name.toCharArray(), PDOMCPPLinkage.CPPFUNCTION, types);
new String(name.toCharArray()),
PDOMCPPLinkage.CPPFUNCTION,
types);
FindEquivalentBinding feb = new FindEquivalentBinding(getLinkageImpl(), bid);
getIndex().accept(feb);
return feb.getResult();
} }
} catch(DOMException de) { } catch(DOMException de) {
CCorePlugin.log(de); CCorePlugin.log(de);
@ -215,16 +207,7 @@ implements ICPPNamespace, ICPPNamespaceScope {
} }
private PDOMBinding searchCurrentScope(char[] name, int[] constants) throws CoreException { private PDOMBinding searchCurrentScope(char[] name, int[] constants) throws CoreException {
PDOMBinding result = null; return FindBinding.findBinding(getIndex(), getPDOM(), name, constants);
for(int i=0; result==null && i<constants.length; i++)
result = searchCurrentScope(name, constants[i]);
return result;
}
private PDOMBinding searchCurrentScope(char[] name, int constant) throws CoreException {
FindBindingByLinkageConstant visitor = new FindBindingByLinkageConstant(getLinkageImpl(), name, constant);
getIndex().accept(visitor);
return visitor.getResult();
} }
public boolean isFullyCached() throws DOMException { public boolean isFullyCached() throws DOMException {