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

@ -62,6 +62,8 @@ public abstract class IndexBindingResolutionTestBase extends PDOMTestBase {
IFile file = TestSourceReader.createFile(cproject.getProject(), header, testData[0].toString());
CCoreInternals.getPDOMManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER);
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());
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 n1 { n2::Int i11; }
// namespace n1 { namespace n2 { Int i12; }}
public void _testQualifiedNamesForTypedef() throws DOMException {
public void testQualifiedNamesForTypedef() throws DOMException {
IBinding b0 = getBindingFromASTName("Int i0;", 3);
assertQNEquals("n1::n2::Int", b0);
IBinding b1= getBindingFromASTName("Int i1;", 3);
@ -675,4 +675,6 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas
IBinding b23 = getBindingFromASTName("f;/*23*/", 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.IScope;
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.pdom.PDOM;
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);
try {
IType type = param.getType();
while(type instanceof ITypedef)
type = ((ITypedef)type).getType();
if (type != null) {
PDOMNode typeNode = getLinkageImpl().addType(this, type);
db.putInt(record + TYPE, typeNode != null ? typeNode.getRecord() : 0);

View file

@ -8,6 +8,7 @@
* Contributors:
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
@ -22,7 +23,6 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.IPDOMNode;
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.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
@ -328,18 +328,13 @@ ICPPClassScope, IPDOMMemberOwner {
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
IASTNode parent = name.getParent();
ASTNodeProperty prop = name.getPropertyInParent();
PDOMLinkage linkage;
try {
linkage = getLinkageImpl();
if (name instanceof ICPPASTQualifiedName) {
IASTName lastName = ((ICPPASTQualifiedName)name).getLastName();
return lastName != null ? lastName.resolveBinding() : null;
}
if(parent instanceof ICPPASTQualifiedName) {
if (parent instanceof ICPPASTQualifiedName) {
IASTName[] names = ((ICPPASTQualifiedName)parent).getNames();
int index = ArrayUtil.indexOf(names, name);
@ -362,149 +357,93 @@ ICPPClassScope, IPDOMMemberOwner {
}
}
FindBindingByLinkageConstant visitor = new FindBindingByLinkageConstant(linkage, name.toCharArray(), PDOMCPPLinkage.CPPCLASSTYPE);
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.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
// aftodo - do we even need specify the type - we should
// expect only one name here anyway?
return searchCurrentScope(name.toCharArray(), new int[] {
PDOMCPPLinkage.CPPCLASSTYPE,
PDOMCPPLinkage.CPPMETHOD,
PDOMCPPLinkage.CPPFIELD,
PDOMCPPLinkage.CPPENUMERATION,
PDOMCPPLinkage.CPPENUMERATOR
});
}
}
IASTNode eParent = parent.getParent();
if(parent instanceof IASTIdExpression) {
FindBindingByLinkageConstant 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);
}
}
if (parent instanceof IASTIdExpression) {
return searchCurrentScope(name.toCharArray(), PDOMCPPLinkage.CPPENUMERATOR);
} else if(eParent instanceof IASTFunctionCallExpression) {
if(parent.getPropertyInParent().equals(IASTFunctionCallExpression.FUNCTION_NAME)) {
IType[] types = ((PDOMCPPLinkage)linkage).getTypes(
((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();
}
return searchCurrentScopeForFunction((IASTFunctionCallExpression)eParent, name);
} else if(parent.getPropertyInParent().equals(IASTFunctionCallExpression.PARAMETERS)) {
if(parent instanceof IASTFieldReference) {
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(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);
return searchCurrentScope(name.toCharArray(), PDOMCPPLinkage.CPPFIELD);
}
}
} else if(name.getPropertyInParent().equals(IASTFieldReference.FIELD_NAME)) {
return searchCurrentScope(name.toCharArray(), PDOMCPPLinkage.CPPFIELD);
} else if (parent instanceof IASTNamedTypeSpecifier) {
FindBindingByLinkageConstant visitor = new FindBindingByLinkageConstant(linkage, name.toCharArray(), PDOMCPPLinkage.CPPCLASSTYPE);
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);
}
}
return searchCurrentScope(name.toCharArray(), new int[] {
PDOMCPPLinkage.CPPCLASSTYPE,
PDOMCPPLinkage.CPPENUMERATION,
PDOMCPPLinkage.CPPTYPEDEF
});
}
} catch(CoreException 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);
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
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.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.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
@ -335,13 +336,10 @@ class PDOMCPPLinkage extends PDOMLinkage {
(IASTFunctionCallExpression) eParent,
(IASTIdExpression) parent, name);
} else if (parent.getPropertyInParent().equals(IASTFunctionCallExpression.PARAMETERS)) {
int constant = (name.getParent() instanceof ICPPASTQualifiedName
int desiredType = (name.getParent() instanceof ICPPASTQualifiedName
&& ((ICPPASTQualifiedName) name.getParent()).getLastName() != name)
? CPPNAMESPACE : CPPVARIABLE;
FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant(
this, name.toCharArray(), constant);
getIndex().accept(finder);
return finder.getResult();
return searchCurrentScope(name.toCharArray(), desiredType);
}
} else {
// 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);
getIndex().accept(finder);
if (finder.getResult() == null) {
finder = new FindBindingByLinkageConstant(this, name
.toCharArray(), CPPENUMERATOR);
getIndex().accept(finder);
}
return finder.getResult();
return searchCurrentScope(name.toCharArray(), new int[]{
CPPVARIABLE,
CPPENUMERATOR
});
}
} else if (parent instanceof IASTNamedTypeSpecifier) {
FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CPPCLASSTYPE);
getIndex().accept(finder);
PDOMBinding result = finder.getResult();
if(result==null) {
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;
return searchCurrentScope(name.toCharArray(), new int[] {
CPPCLASSTYPE,
CPPENUMERATION,
CPPTYPEDEF
});
} else if (parent instanceof ICPPASTNamespaceAlias) {
FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CPPNAMESPACE);
getIndex().accept(finder);
return finder.getResult();
return searchCurrentScope(name.toCharArray(), CPPNAMESPACE);
} else if(parent instanceof ICPPASTFieldReference) {
ICPPASTFieldReference ref = (ICPPASTFieldReference) parent;
IASTExpression exp = ref.getFieldOwner();
if(exp instanceof IASTIdExpression) {
IASTIdExpression fieldOwner = (IASTIdExpression) exp;
IASTNode eParent = parent.getParent();
if (eParent instanceof IASTFunctionCallExpression) {
if (eParent instanceof IASTFunctionCallExpression &&
parent.getPropertyInParent().equals(IASTFunctionCallExpression.FUNCTION_NAME)) {
if(name.getPropertyInParent().equals(IASTFieldReference.FIELD_NAME)) {
return resolveFunctionCall((IASTFunctionCallExpression) eParent, fieldOwner, name);
}
@ -429,22 +412,34 @@ class PDOMCPPLinkage extends PDOMLinkage {
}
}
} else if(parent instanceof ICPPASTBaseSpecifier) {
FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CPPCLASSTYPE);
getIndex().accept(finder);
return finder.getResult();
return searchCurrentScope(name.toCharArray(), PDOMCPPLinkage.CPPCLASSTYPE);
}
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
* @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)
*/
public IType[] getTypes(IASTExpression paramExp) throws DOMException {
public static IType[] getTypes(IASTExpression paramExp) throws DOMException {
IType[] types = null;
if(paramExp==null) { // void function/method
types = new IType[0];
} else if(paramExp instanceof ICPPASTNewExpression) {
@ -453,25 +448,23 @@ class PDOMCPPLinkage extends PDOMLinkage {
ICPPASTNewExpression exp3 = (ICPPASTNewExpression) paramExp;
IType type = exp3.getExpressionType();
types = new IType[] {new CPPPointerType(type)};
} else {
if(paramExp instanceof IASTExpressionList) {
IASTExpressionList list = (IASTExpressionList) paramExp;
IASTExpression[] paramExps = list.getExpressions();
types = new IType[paramExps.length];
for(int i=0; i<paramExps.length; i++) {
types[i] = paramExps[i].getExpressionType();
}
} else {
types = new IType[] {paramExp.getExpressionType()};
} else if(paramExp instanceof IASTExpressionList) {
IASTExpressionList list = (IASTExpressionList) paramExp;
IASTExpression[] paramExps = list.getExpressions();
types = new IType[paramExps.length];
for(int i=0; i<paramExps.length; i++) {
types[i] = paramExps[i].getExpressionType();
}
} else {
types = new IType[] {paramExp.getExpressionType()};
}
if(types!=null) { // aftodo - unit test coverage of this is low
for(int i=0; i<types.length; i++) {
// aftodo - assumed this always terminates
while(types[i] instanceof ITypedef) {
types[i] = ((ITypedef)types[i]).getType();
}
}
if(types[i] instanceof ProblemBinding)
return null;
}

View file

@ -46,10 +46,10 @@ import org.eclipse.core.runtime.CoreException;
*
*/
class PDOMCPPNamespace extends PDOMCPPBinding
implements ICPPNamespace, ICPPNamespaceScope {
implements ICPPNamespace, ICPPNamespaceScope {
private static final int INDEX_OFFSET = PDOMBinding.RECORD_SIZE + 0;
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 4;
public PDOMCPPNamespace(PDOM pdom, PDOMNode parent, ICPPNamespace namespace) throws CoreException {
@ -63,11 +63,11 @@ class PDOMCPPNamespace extends PDOMCPPBinding
protected int getRecordSize() {
return RECORD_SIZE;
}
public int getNodeType() {
return PDOMCPPLinkage.CPPNAMESPACE;
}
public BTree getIndex() throws CoreException {
return new BTree(pdom.getDB(), record + INDEX_OFFSET, getLinkageImpl().getIndexComparator());
}
@ -89,7 +89,7 @@ class PDOMCPPNamespace extends PDOMCPPBinding
}
});
}
public void addChild(PDOMNode child) throws CoreException {
getIndex().insert(child.getRecord());
}
@ -118,16 +118,18 @@ class PDOMCPPNamespace extends PDOMCPPBinding
}
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
IASTNode parent = name.getParent();
try {
if (name instanceof ICPPASTQualifiedName) {
IASTName lastName = ((ICPPASTQualifiedName)name).getLastName();
return lastName != null ? lastName.resolveBinding() : null;
}
IASTNode parent = name.getParent();
if (parent instanceof ICPPASTQualifiedName) {
IASTName[] names = ((ICPPASTQualifiedName)parent).getNames();
int index = ArrayUtil.indexOf(names, name);
if (index == names.length - 1) { // tip of qn
parent = parent.getParent();
} else {
@ -151,71 +153,83 @@ class PDOMCPPNamespace extends PDOMCPPBinding
}
}
}
// Look up the name
FindBindingsInBTree visitor = new FindBindingsInBTree(getLinkageImpl(), name.toCharArray(),
new int[] {
PDOMCPPLinkage.CPPCLASSTYPE,
PDOMCPPLinkage.CPPNAMESPACE,
PDOMCPPLinkage.CPPFUNCTION,
PDOMCPPLinkage.CPPVARIABLE
});
getIndex().accept(visitor);
IBinding[] bindings = visitor.getBinding();
return bindings.length > 0 ? bindings[0] : null;
// aftodo - do we even need specify the type - we should
// expect only one name here anyway?
return searchCurrentScope(name.toCharArray(), new int[] {
PDOMCPPLinkage.CPPCLASSTYPE,
PDOMCPPLinkage.CPPNAMESPACE,
PDOMCPPLinkage.CPPFUNCTION,
PDOMCPPLinkage.CPPVARIABLE,
PDOMCPPLinkage.CPPENUMERATION,
PDOMCPPLinkage.CPPENUMERATOR
});
}
}
IASTNode eParent = parent.getParent();
if (parent instanceof IASTIdExpression) {
// reference
IASTNode eParent = parent.getParent();
if (eParent instanceof IASTFunctionCallExpression) {
if(parent.getPropertyInParent().equals(IASTFunctionCallExpression.FUNCTION_NAME)) {
IType[] types = ((PDOMCPPLinkage)getLinkage()).getTypes(
((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();
}
return searchCurrentScopeForFunction((IASTFunctionCallExpression)eParent, name);
}
} else {
int desiredType = ((name.getParent() instanceof ICPPASTQualifiedName)
&& ((ICPPASTQualifiedName)name.getParent()).getLastName() != name)
? 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);
getIndex().accept(visitor2);
if(visitor2.getResult()!=null) {
return visitor2.getResult();
}
return null;
IBinding result = searchCurrentScope(name.toCharArray(), desiredType);
if(result!=null)
return result;
return searchCurrentScope(name.toCharArray(), PDOMCPPLinkage.CPPTYPEDEF);
}
} else if (parent instanceof IASTNamedTypeSpecifier) {
FindBindingsInBTree visitor = new FindBindingsInBTree(getLinkageImpl(), name.toCharArray(), PDOMCPPLinkage.CPPCLASSTYPE);
getIndex().accept(visitor);
IBinding[] bindings = visitor.getBinding();
return bindings.length > 0
? bindings[0]
: null;
return searchCurrentScope(name.toCharArray(), new int[] {
PDOMCPPLinkage.CPPCLASSTYPE,
PDOMCPPLinkage.CPPENUMERATION,
PDOMCPPLinkage.CPPTYPEDEF
});
}
return null;
} catch (CoreException 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 {
// TODO
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.IScope;
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.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database;
@ -65,6 +66,8 @@ class PDOMCPPParameter extends PDOMNamedNode implements IParameter {
try {
IType type = param.getType();
while(type instanceof ITypedef)
type = ((ITypedef)type).getType();
if (type != null) {
PDOMNode typeNode = getLinkageImpl().addType(this, type);
db.putInt(record + TYPE, typeNode != null ? typeNode.getRecord() : 0);

View file

@ -26,7 +26,7 @@ import org.eclipse.core.runtime.CoreException;
/**
* @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;