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

Tidy up pdom binding resolution code, fix typedefs accessed by qualified names

This commit is contained in:
Andrew Ferguson 2006-11-15 10:14:30 +00:00
parent d6eadac266
commit e714b84612
9 changed files with 227 additions and 236 deletions

View file

@ -63,6 +63,8 @@ public abstract class IndexBindingResolutionTestBase extends PDOMTestBase {
CCoreInternals.getPDOMManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER); CCoreInternals.getPDOMManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER);
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
/* ((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter()); */
IFile cppfile= TestSourceReader.createFile(cproject.getProject(), references, testData[1].toString()); IFile cppfile= TestSourceReader.createFile(cproject.getProject(), references, testData[1].toString());
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));

View file

@ -324,7 +324,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas
// namespace n3 { c3::s3::u3::Int i10; } // namespace n3 { c3::s3::u3::Int i10; }
// namespace n1 { n2::Int i11; } // namespace n1 { n2::Int i11; }
// namespace n1 { namespace n2 { Int i12; }} // namespace n1 { namespace n2 { Int i12; }}
public void _testQualifiedNamesForTypedef() throws DOMException { public void testQualifiedNamesForTypedef() throws DOMException {
IBinding b0 = getBindingFromASTName("Int i0;", 3); IBinding b0 = getBindingFromASTName("Int i0;", 3);
assertQNEquals("n1::n2::Int", b0); assertQNEquals("n1::n2::Int", b0);
IBinding b1= getBindingFromASTName("Int i1;", 3); IBinding b1= getBindingFromASTName("Int i1;", 3);
@ -675,4 +675,6 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas
IBinding b23 = getBindingFromASTName("f;/*23*/", 1); IBinding b23 = getBindingFromASTName("f;/*23*/", 1);
IBinding b24 = getBindingFromASTName("f;/*24*/", 1); IBinding b24 = getBindingFromASTName("f;/*24*/", 1);
} }
public void _testAddressOfOverloadedMethod() throws DOMException { fail("aftodo"); }
} }

View file

@ -0,0 +1,35 @@
/*******************************************************************************
* 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:
* Symbian - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.pdom.tests;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.core.runtime.CoreException;
/**
* Dump the contents of the PDOM index to stdout (for when you need
* a lo-fidelity debugging tool)
*/
public class PDOMPrettyPrinter implements IPDOMVisitor {
StringBuffer indent = new StringBuffer();
final String step = " "; //$NON-NLS-1$
public void leave(IPDOMNode node) throws CoreException {
if(indent.length()>=step.length())
indent.setLength(indent.length()-step.length());
}
public boolean visit(IPDOMNode node) throws CoreException {
indent.append(step);
System.out.println(indent+""+node);
return true;
}
}

View file

@ -18,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.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;
@ -52,6 +53,8 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter {
db.putInt(record + NEXT_PARAM, 0); db.putInt(record + NEXT_PARAM, 0);
try { try {
IType type = param.getType(); IType type = param.getType();
while(type instanceof ITypedef)
type = ((ITypedef)type).getType();
if (type != null) { if (type != null) {
PDOMNode typeNode = getLinkageImpl().addType(this, type); PDOMNode typeNode = getLinkageImpl().addType(this, type);
db.putInt(record + TYPE, typeNode != null ? typeNode.getRecord() : 0); db.putInt(record + TYPE, typeNode != null ? typeNode.getRecord() : 0);

View file

@ -8,6 +8,7 @@
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp; package org.eclipse.cdt.internal.core.pdom.dom.cpp;
@ -22,7 +23,6 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.IPDOMNode; import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference; import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
@ -328,18 +328,13 @@ ICPPClassScope, IPDOMMemberOwner {
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException { public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
IASTNode parent = name.getParent(); IASTNode parent = name.getParent();
ASTNodeProperty prop = name.getPropertyInParent();
PDOMLinkage linkage;
try { try {
linkage = getLinkageImpl();
if (name instanceof ICPPASTQualifiedName) { if (name instanceof ICPPASTQualifiedName) {
IASTName lastName = ((ICPPASTQualifiedName)name).getLastName(); IASTName lastName = ((ICPPASTQualifiedName)name).getLastName();
return lastName != null ? lastName.resolveBinding() : null; return lastName != null ? lastName.resolveBinding() : null;
} }
if(parent instanceof ICPPASTQualifiedName) { if (parent instanceof ICPPASTQualifiedName) {
IASTName[] names = ((ICPPASTQualifiedName)parent).getNames(); IASTName[] names = ((ICPPASTQualifiedName)parent).getNames();
int index = ArrayUtil.indexOf(names, name); int index = ArrayUtil.indexOf(names, name);
@ -362,149 +357,93 @@ ICPPClassScope, IPDOMMemberOwner {
} }
} }
FindBindingByLinkageConstant visitor = new FindBindingByLinkageConstant(linkage, name.toCharArray(), PDOMCPPLinkage.CPPCLASSTYPE); // aftodo - do we even need specify the type - we should
try { // expect only one name here anyway?
accept(visitor); return searchCurrentScope(name.toCharArray(), new int[] {
} catch(CoreException e) { PDOMCPPLinkage.CPPCLASSTYPE,
if (e.getStatus().equals(Status.OK_STATUS)) { PDOMCPPLinkage.CPPMETHOD,
return visitor.getResult(); PDOMCPPLinkage.CPPFIELD,
} else { PDOMCPPLinkage.CPPENUMERATION,
CCorePlugin.log(e); PDOMCPPLinkage.CPPENUMERATOR
} });
}
visitor = new FindBindingByLinkageConstant(linkage, name.toCharArray(), PDOMCPPLinkage.CPPMETHOD);
try {
accept(visitor);
} catch(CoreException e) {
if (e.getStatus().equals(Status.OK_STATUS)) {
return visitor.getResult();
} else {
CCorePlugin.log(e);
}
}
visitor = new FindBindingByLinkageConstant(linkage, name.toCharArray(), PDOMCPPLinkage.CPPFIELD);
try {
accept(visitor);
} catch(CoreException e) {
if (e.getStatus().equals(Status.OK_STATUS)) {
return visitor.getResult();
} else {
CCorePlugin.log(e);
}
}
visitor = new FindBindingByLinkageConstant(linkage, name.toCharArray(), PDOMCPPLinkage.CPPENUMERATION);
try {
accept(visitor);
} catch(CoreException e) {
if (e.getStatus().equals(Status.OK_STATUS)) {
return visitor.getResult();
} else {
CCorePlugin.log(e);
}
}
visitor = new FindBindingByLinkageConstant(linkage, name.toCharArray(), PDOMCPPLinkage.CPPENUMERATOR);
try {
accept(visitor);
} catch(CoreException e) {
if (e.getStatus().equals(Status.OK_STATUS)) {
return visitor.getResult();
} else {
CCorePlugin.log(e);
}
}
return null; // not found in this scope
} }
} }
IASTNode eParent = parent.getParent(); IASTNode eParent = parent.getParent();
if(parent instanceof IASTIdExpression) { if (parent instanceof IASTIdExpression) {
FindBindingByLinkageConstant visitor = new FindBindingByLinkageConstant(linkage, name.toCharArray(), PDOMCPPLinkage.CPPENUMERATOR); return searchCurrentScope(name.toCharArray(), PDOMCPPLinkage.CPPENUMERATOR);
try {
accept(visitor);
} catch(CoreException e) {
if (e.getStatus().equals(Status.OK_STATUS)) {
return visitor.getResult();
} else {
CCorePlugin.log(e);
}
}
} else if(eParent instanceof IASTFunctionCallExpression) { } else if(eParent instanceof IASTFunctionCallExpression) {
if(parent.getPropertyInParent().equals(IASTFunctionCallExpression.FUNCTION_NAME)) { if(parent.getPropertyInParent().equals(IASTFunctionCallExpression.FUNCTION_NAME)) {
IType[] types = ((PDOMCPPLinkage)linkage).getTypes( return searchCurrentScopeForFunction((IASTFunctionCallExpression)eParent, name);
((IASTFunctionCallExpression)eParent).getParameterExpression()
);
if(types!=null) {
ILocalBindingIdentity bid = new CPPBindingIdentity.Holder(
new String(name.toCharArray()),
PDOMCPPLinkage.CPPFUNCTION,
types);
FindEquivalentBinding feb = new FindEquivalentBinding(linkage, bid);
try {
accept(feb);
} catch(CoreException e) {
if (e.getStatus().equals(Status.OK_STATUS)) {
return feb.getResult();
} else {
CCorePlugin.log(e);
}
}
return feb.getResult();
}
} else if(parent.getPropertyInParent().equals(IASTFunctionCallExpression.PARAMETERS)) { } else if(parent.getPropertyInParent().equals(IASTFunctionCallExpression.PARAMETERS)) {
if(parent instanceof IASTFieldReference) { if(parent instanceof IASTFieldReference) {
FindBindingByLinkageConstant visitor = new FindBindingByLinkageConstant(linkage, name.toCharArray(), PDOMCPPLinkage.CPPFIELD); return searchCurrentScope(name.toCharArray(), PDOMCPPLinkage.CPPFIELD);
try {
accept(visitor);
} catch(CoreException e) {
if (e.getStatus().equals(Status.OK_STATUS)) {
return visitor.getResult();
} else {
CCorePlugin.log(e);
}
}
}
}
} else if(prop.equals(IASTFieldReference.FIELD_NAME)) {
FindBindingByLinkageConstant visitor = new FindBindingByLinkageConstant(linkage, name.toCharArray(), PDOMCPPLinkage.CPPFIELD);
try {
accept(visitor);
} catch(CoreException e) {
if (e.getStatus().equals(Status.OK_STATUS)) {
return visitor.getResult();
} else {
CCorePlugin.log(e);
} }
} }
} else if(name.getPropertyInParent().equals(IASTFieldReference.FIELD_NAME)) {
return searchCurrentScope(name.toCharArray(), PDOMCPPLinkage.CPPFIELD);
} else if (parent instanceof IASTNamedTypeSpecifier) { } else if (parent instanceof IASTNamedTypeSpecifier) {
FindBindingByLinkageConstant visitor = new FindBindingByLinkageConstant(linkage, name.toCharArray(), PDOMCPPLinkage.CPPCLASSTYPE); return searchCurrentScope(name.toCharArray(), new int[] {
try { PDOMCPPLinkage.CPPCLASSTYPE,
accept(visitor); PDOMCPPLinkage.CPPENUMERATION,
} catch(CoreException e) { PDOMCPPLinkage.CPPTYPEDEF
if (e.getStatus().equals(Status.OK_STATUS)) { });
return visitor.getResult();
} else {
CCorePlugin.log(e);
}
}
visitor = new FindBindingByLinkageConstant(linkage, name.toCharArray(), PDOMCPPLinkage.CPPENUMERATION);
try {
accept(visitor);
} catch(CoreException e) {
if (e.getStatus().equals(Status.OK_STATUS)) {
return visitor.getResult();
} else {
CCorePlugin.log(e);
}
}
} }
} catch(CoreException e) { } catch(CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
return null;
} }
return null; return null;
} }
private PDOMBinding searchCurrentScopeForFunction(IASTFunctionCallExpression fce, IASTName name) throws CoreException {
try {
IType[] types = PDOMCPPLinkage.getTypes(fce.getParameterExpression());
if(types!=null) {
ILocalBindingIdentity bid = new CPPBindingIdentity.Holder(
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) {
CCorePlugin.log(de);
}
return null;
}
private IBinding searchCurrentScope(char[] name, int[] constants) throws CoreException {
IBinding result = null;
for(int i=0; result==null && i<constants.length; i++)
result = searchCurrentScope(name, constants[i]);
return result;
}
private IBinding searchCurrentScope(char[] name, int constant) throws CoreException {
FindBindingByLinkageConstant visitor = new FindBindingByLinkageConstant(getLinkageImpl(), name, 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
public Object clone() {fail();return null;} public Object clone() {fail();return null;}

View file

@ -15,6 +15,7 @@ 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.IASTArraySubscriptExpression;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
@ -335,13 +336,10 @@ class PDOMCPPLinkage extends PDOMLinkage {
(IASTFunctionCallExpression) eParent, (IASTFunctionCallExpression) eParent,
(IASTIdExpression) parent, name); (IASTIdExpression) parent, name);
} else if (parent.getPropertyInParent().equals(IASTFunctionCallExpression.PARAMETERS)) { } else if (parent.getPropertyInParent().equals(IASTFunctionCallExpression.PARAMETERS)) {
int constant = (name.getParent() instanceof ICPPASTQualifiedName int desiredType = (name.getParent() instanceof ICPPASTQualifiedName
&& ((ICPPASTQualifiedName) name.getParent()).getLastName() != name) && ((ICPPASTQualifiedName) name.getParent()).getLastName() != name)
? CPPNAMESPACE : CPPVARIABLE; ? CPPNAMESPACE : CPPVARIABLE;
FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant( return searchCurrentScope(name.toCharArray(), desiredType);
this, name.toCharArray(), constant);
getIndex().accept(finder);
return finder.getResult();
} }
} else { } else {
// if the address of me is taken, and assigned to something, // if the address of me is taken, and assigned to something,
@ -368,42 +366,27 @@ class PDOMCPPLinkage extends PDOMLinkage {
} }
} }
FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CPPVARIABLE); return searchCurrentScope(name.toCharArray(), new int[]{
getIndex().accept(finder); CPPVARIABLE,
CPPENUMERATOR
if (finder.getResult() == null) { });
finder = new FindBindingByLinkageConstant(this, name
.toCharArray(), CPPENUMERATOR);
getIndex().accept(finder);
}
return finder.getResult();
} }
} else if (parent instanceof IASTNamedTypeSpecifier) { } else if (parent instanceof IASTNamedTypeSpecifier) {
FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CPPCLASSTYPE); return searchCurrentScope(name.toCharArray(), new int[] {
getIndex().accept(finder); CPPCLASSTYPE,
PDOMBinding result = finder.getResult(); CPPENUMERATION,
if(result==null) { CPPTYPEDEF
finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CPPENUMERATION); });
getIndex().accept(finder);
result = finder.getResult();
}
if(result==null) {
finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CPPTYPEDEF);
getIndex().accept(finder);
result = finder.getResult();
}
return result;
} else if (parent instanceof ICPPASTNamespaceAlias) { } else if (parent instanceof ICPPASTNamespaceAlias) {
FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CPPNAMESPACE); return searchCurrentScope(name.toCharArray(), CPPNAMESPACE);
getIndex().accept(finder);
return finder.getResult();
} else if(parent instanceof ICPPASTFieldReference) { } else if(parent instanceof ICPPASTFieldReference) {
ICPPASTFieldReference ref = (ICPPASTFieldReference) parent; ICPPASTFieldReference ref = (ICPPASTFieldReference) parent;
IASTExpression exp = ref.getFieldOwner(); IASTExpression exp = ref.getFieldOwner();
if(exp instanceof IASTIdExpression) { if(exp instanceof IASTIdExpression) {
IASTIdExpression fieldOwner = (IASTIdExpression) exp; IASTIdExpression fieldOwner = (IASTIdExpression) exp;
IASTNode eParent = parent.getParent(); IASTNode eParent = parent.getParent();
if (eParent instanceof IASTFunctionCallExpression) { if (eParent instanceof IASTFunctionCallExpression &&
parent.getPropertyInParent().equals(IASTFunctionCallExpression.FUNCTION_NAME)) {
if(name.getPropertyInParent().equals(IASTFieldReference.FIELD_NAME)) { if(name.getPropertyInParent().equals(IASTFieldReference.FIELD_NAME)) {
return resolveFunctionCall((IASTFunctionCallExpression) eParent, fieldOwner, name); return resolveFunctionCall((IASTFunctionCallExpression) eParent, fieldOwner, name);
} }
@ -429,20 +412,32 @@ class PDOMCPPLinkage extends PDOMLinkage {
} }
} }
} else if(parent instanceof ICPPASTBaseSpecifier) { } else if(parent instanceof ICPPASTBaseSpecifier) {
FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CPPCLASSTYPE); return searchCurrentScope(name.toCharArray(), PDOMCPPLinkage.CPPCLASSTYPE);
getIndex().accept(finder);
return finder.getResult();
} }
return null; return null;
} }
private PDOMBinding searchCurrentScope(char[] name, int[] constants) throws CoreException {
PDOMBinding result = null;
for(int i=0; result==null && i<constants.length; i++)
result = searchCurrentScope(name, constants[i]);
return result;
}
private PDOMBinding searchCurrentScope(char[] name, int constant) throws CoreException {
FindBindingByLinkageConstant visitor = new FindBindingByLinkageConstant(getLinkageImpl(), name, 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)
* @return an array of types or null if types could not be determined (because of missing semantic information in the AST) * @return an array of types or null if types could not be determined (because of missing semantic information in the AST)
*/ */
public IType[] getTypes(IASTExpression paramExp) throws DOMException { public static IType[] getTypes(IASTExpression paramExp) throws DOMException {
IType[] types = null; IType[] types = null;
if(paramExp==null) { // void function/method if(paramExp==null) { // void function/method
@ -453,17 +448,15 @@ class PDOMCPPLinkage extends PDOMLinkage {
ICPPASTNewExpression exp3 = (ICPPASTNewExpression) paramExp; ICPPASTNewExpression exp3 = (ICPPASTNewExpression) paramExp;
IType type = exp3.getExpressionType(); IType type = exp3.getExpressionType();
types = new IType[] {new CPPPointerType(type)}; types = new IType[] {new CPPPointerType(type)};
} else { } else if(paramExp instanceof IASTExpressionList) {
if(paramExp instanceof IASTExpressionList) { IASTExpressionList list = (IASTExpressionList) paramExp;
IASTExpressionList list = (IASTExpressionList) paramExp; IASTExpression[] paramExps = list.getExpressions();
IASTExpression[] paramExps = list.getExpressions(); types = new IType[paramExps.length];
types = new IType[paramExps.length]; for(int i=0; i<paramExps.length; i++) {
for(int i=0; i<paramExps.length; i++) { types[i] = paramExps[i].getExpressionType();
types[i] = paramExps[i].getExpressionType();
}
} else {
types = new IType[] {paramExp.getExpressionType()};
} }
} else {
types = new IType[] {paramExp.getExpressionType()};
} }
if(types!=null) { // aftodo - unit test coverage of this is low if(types!=null) { // aftodo - unit test coverage of this is low
@ -471,7 +464,7 @@ class PDOMCPPLinkage extends PDOMLinkage {
// aftodo - assumed this always terminates // aftodo - assumed this always terminates
while(types[i] instanceof ITypedef) { while(types[i] instanceof ITypedef) {
types[i] = ((ITypedef)types[i]).getType(); types[i] = ((ITypedef)types[i]).getType();
} }
if(types[i] instanceof ProblemBinding) if(types[i] instanceof ProblemBinding)
return null; return null;
} }

View file

@ -46,7 +46,7 @@ import org.eclipse.core.runtime.CoreException;
* *
*/ */
class PDOMCPPNamespace extends PDOMCPPBinding class PDOMCPPNamespace extends PDOMCPPBinding
implements ICPPNamespace, ICPPNamespaceScope { implements ICPPNamespace, ICPPNamespaceScope {
private static final int INDEX_OFFSET = PDOMBinding.RECORD_SIZE + 0; private static final int INDEX_OFFSET = PDOMBinding.RECORD_SIZE + 0;
@ -118,12 +118,14 @@ class PDOMCPPNamespace extends PDOMCPPBinding
} }
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException { public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
IASTNode parent = name.getParent();
try { try {
if (name instanceof ICPPASTQualifiedName) { if (name instanceof ICPPASTQualifiedName) {
IASTName lastName = ((ICPPASTQualifiedName)name).getLastName(); IASTName lastName = ((ICPPASTQualifiedName)name).getLastName();
return lastName != null ? lastName.resolveBinding() : null; return lastName != null ? lastName.resolveBinding() : null;
} }
IASTNode parent = name.getParent();
if (parent instanceof ICPPASTQualifiedName) { if (parent instanceof ICPPASTQualifiedName) {
IASTName[] names = ((ICPPASTQualifiedName)parent).getNames(); IASTName[] names = ((ICPPASTQualifiedName)parent).getNames();
int index = ArrayUtil.indexOf(names, name); int index = ArrayUtil.indexOf(names, name);
@ -152,70 +154,82 @@ class PDOMCPPNamespace extends PDOMCPPBinding
} }
} }
// Look up the name // aftodo - do we even need specify the type - we should
FindBindingsInBTree visitor = new FindBindingsInBTree(getLinkageImpl(), name.toCharArray(), // expect only one name here anyway?
new int[] { return searchCurrentScope(name.toCharArray(), new int[] {
PDOMCPPLinkage.CPPCLASSTYPE, PDOMCPPLinkage.CPPCLASSTYPE,
PDOMCPPLinkage.CPPNAMESPACE, PDOMCPPLinkage.CPPNAMESPACE,
PDOMCPPLinkage.CPPFUNCTION, PDOMCPPLinkage.CPPFUNCTION,
PDOMCPPLinkage.CPPVARIABLE PDOMCPPLinkage.CPPVARIABLE,
}); PDOMCPPLinkage.CPPENUMERATION,
getIndex().accept(visitor); PDOMCPPLinkage.CPPENUMERATOR
IBinding[] bindings = visitor.getBinding(); });
return bindings.length > 0 ? bindings[0] : null;
} }
} }
IASTNode eParent = parent.getParent();
if (parent instanceof IASTIdExpression) { if (parent instanceof IASTIdExpression) {
// reference
IASTNode eParent = parent.getParent();
if (eParent instanceof IASTFunctionCallExpression) { if (eParent instanceof IASTFunctionCallExpression) {
if(parent.getPropertyInParent().equals(IASTFunctionCallExpression.FUNCTION_NAME)) { if(parent.getPropertyInParent().equals(IASTFunctionCallExpression.FUNCTION_NAME)) {
IType[] types = ((PDOMCPPLinkage)getLinkage()).getTypes( return searchCurrentScopeForFunction((IASTFunctionCallExpression)eParent, name);
((IASTFunctionCallExpression)eParent).getParameterExpression()
);
if(types!=null) {
ILocalBindingIdentity bid = new CPPBindingIdentity.Holder(
new String(name.toCharArray()),
PDOMCPPLinkage.CPPFUNCTION,
types);
FindEquivalentBinding feb = new FindEquivalentBinding(getLinkageImpl(), bid);
getIndex().accept(feb);
return feb.getResult();
}
} }
} else { } else {
int desiredType = ((name.getParent() instanceof ICPPASTQualifiedName) int desiredType = ((name.getParent() instanceof ICPPASTQualifiedName)
&& ((ICPPASTQualifiedName)name.getParent()).getLastName() != name) && ((ICPPASTQualifiedName)name.getParent()).getLastName() != name)
? PDOMCPPLinkage.CPPNAMESPACE : PDOMCPPLinkage.CPPVARIABLE; ? PDOMCPPLinkage.CPPNAMESPACE : PDOMCPPLinkage.CPPVARIABLE;
FindBindingByLinkageConstant visitor2 = new FindBindingByLinkageConstant(getLinkageImpl(), name.toCharArray(), desiredType);
getIndex().accept(visitor2);
if(visitor2.getResult()!=null) {
return visitor2.getResult();
}
visitor2 = new FindBindingByLinkageConstant(getLinkageImpl(), name.toCharArray(), PDOMCPPLinkage.CPPTYPEDEF); IBinding result = searchCurrentScope(name.toCharArray(), desiredType);
getIndex().accept(visitor2); if(result!=null)
if(visitor2.getResult()!=null) { return result;
return visitor2.getResult(); return searchCurrentScope(name.toCharArray(), PDOMCPPLinkage.CPPTYPEDEF);
}
return null;
} }
} else if (parent instanceof IASTNamedTypeSpecifier) { } else if (parent instanceof IASTNamedTypeSpecifier) {
FindBindingsInBTree visitor = new FindBindingsInBTree(getLinkageImpl(), name.toCharArray(), PDOMCPPLinkage.CPPCLASSTYPE); return searchCurrentScope(name.toCharArray(), new int[] {
getIndex().accept(visitor); PDOMCPPLinkage.CPPCLASSTYPE,
IBinding[] bindings = visitor.getBinding(); PDOMCPPLinkage.CPPENUMERATION,
return bindings.length > 0 PDOMCPPLinkage.CPPTYPEDEF
? bindings[0] });
: null;
} }
return null;
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
return null;
} }
return null;
} }
private PDOMBinding searchCurrentScopeForFunction(IASTFunctionCallExpression fce, IASTName name) throws CoreException {
try {
IType[] types = PDOMCPPLinkage.getTypes(fce.getParameterExpression());
if(types!=null) {
ILocalBindingIdentity bid = new CPPBindingIdentity.Holder(
new String(name.toCharArray()),
PDOMCPPLinkage.CPPFUNCTION,
types);
FindEquivalentBinding feb = new FindEquivalentBinding(getLinkageImpl(), bid);
getIndex().accept(feb);
return feb.getResult();
}
} catch(DOMException de) {
CCorePlugin.log(de);
}
return null;
}
private PDOMBinding searchCurrentScope(char[] name, int[] constants) throws CoreException {
PDOMBinding result = null;
for(int i=0; result==null && i<constants.length; i++)
result = searchCurrentScope(name, constants[i]);
return result;
}
private PDOMBinding searchCurrentScope(char[] name, int constant) throws CoreException {
FindBindingByLinkageConstant visitor = new FindBindingByLinkageConstant(getLinkageImpl(), name, constant);
getIndex().accept(visitor);
return visitor.getResult();
}
public IScope getParent() throws DOMException { public IScope getParent() throws DOMException {
// TODO // TODO
return null; return null;

View file

@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.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;
@ -65,6 +66,8 @@ class PDOMCPPParameter extends PDOMNamedNode implements IParameter {
try { try {
IType type = param.getType(); IType type = param.getType();
while(type instanceof ITypedef)
type = ((ITypedef)type).getType();
if (type != null) { if (type != null) {
PDOMNode typeNode = getLinkageImpl().addType(this, type); PDOMNode typeNode = getLinkageImpl().addType(this, type);
db.putInt(record + TYPE, typeNode != null ? typeNode.getRecord() : 0); db.putInt(record + TYPE, typeNode != null ? typeNode.getRecord() : 0);

View file

@ -26,7 +26,7 @@ import org.eclipse.core.runtime.CoreException;
/** /**
* @author Doug Schaefer * @author Doug Schaefer
*/ */
class PDOMCPPTypedef extends PDOMBinding implements ITypedef, ITypeContainer { class PDOMCPPTypedef extends PDOMCPPBinding implements ITypedef, ITypeContainer {
private static final int TYPE = PDOMBinding.RECORD_SIZE + 0; private static final int TYPE = PDOMBinding.RECORD_SIZE + 0;