1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Bug 144095 - Added hooks to look up things in PDOMCPPNamespace when they aren't found during the regular scope lookup.

This commit is contained in:
Doug Schaefer 2006-05-31 17:56:43 +00:00
parent d0636fd983
commit bc520fcaff
5 changed files with 66 additions and 14 deletions

View file

@ -13,11 +13,13 @@
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
@ -25,6 +27,7 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.ObjectSet; import org.eclipse.cdt.core.parser.util.ObjectSet;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.pdom.PDOM;
/** /**
* @author aniefer * @author aniefer
@ -80,10 +83,10 @@ abstract public class CPPScope implements ICPPScope{
public IBinding getBinding(IASTName name, boolean forceResolve) throws DOMException { public IBinding getBinding(IASTName name, boolean forceResolve) throws DOMException {
char [] c = name.toCharArray(); char [] c = name.toCharArray();
//can't look up bindings that don't have a name //can't look up bindings that don't have a name
if( c.length == 0 || bindings == null ) if( c.length == 0 )
return null; return null;
Object obj = bindings.get( c ); Object obj = bindings != null ? bindings.get( c ) : null;
if( obj != null ){ if( obj != null ){
if( obj instanceof ObjectSet ) { if( obj instanceof ObjectSet ) {
ObjectSet os = (ObjectSet) obj; ObjectSet os = (ObjectSet) obj;
@ -121,6 +124,18 @@ abstract public class CPPScope implements ICPPScope{
return binding; return binding;
} }
return (IBinding) obj; return (IBinding) obj;
} else {
IPDOM pdom = name.getTranslationUnit().getIndex();
if (pdom != null) {
// Try looking this up in the PDOM
if (physicalNode instanceof ICPPASTNamespaceDefinition) {
ICPPASTNamespaceDefinition nsdef = (ICPPASTNamespaceDefinition)physicalNode;
IASTName nsname = nsdef.getName();
IBinding nsbinding = ((PDOM)pdom).resolveBinding(nsname);
if (nsbinding instanceof ICPPScope)
return ((ICPPScope)nsbinding).getBinding(name, forceResolve);
}
}
} }
return null; return null;
} }

View file

@ -126,6 +126,7 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil.ArrayWrapper;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
/** /**
* @author aniefer * @author aniefer
@ -746,7 +747,7 @@ public class CPPSemantics {
addDefinition( binding, data.astName ); addDefinition( binding, data.astName );
} }
} }
if( binding == null ){ if( binding == null || binding instanceof IProblemBinding ){
// Let's try the pdom // Let's try the pdom
IPDOM pdom = name.getTranslationUnit().getIndex(); IPDOM pdom = name.getTranslationUnit().getIndex();
if (pdom != null) { if (pdom != null) {
@ -1025,7 +1026,9 @@ public class CPPSemantics {
} else { } else {
if (!data.prefixLookup && data.astName != null ) { if (!data.prefixLookup && data.astName != null ) {
IBinding b = scope.getBinding( data.astName, false ); IBinding b = scope.getBinding( data.astName, false );
if (b instanceof CPPImplicitFunction || b instanceof CPPImplicitTypedef) if (b instanceof CPPImplicitFunction || b instanceof CPPImplicitTypedef
|| b instanceof PDOMBinding)
// TODO the PDOMBinding thing is a kludge
mergeResults( data, b, true ); mergeResults( data, b, true );
} }
mergeResults( data, lookupInScope( data, scope, blockItem ), true ); mergeResults( data, lookupInScope( data, scope, blockItem ), true );

View file

@ -232,6 +232,9 @@ public class PDOMCPPLinkage extends PDOMLinkage {
} }
public IBinding resolveBinding(IASTName name) throws CoreException { public IBinding resolveBinding(IASTName name) throws CoreException {
IBinding origBinding = name.getBinding();
if (origBinding != null)
return adaptBinding(origBinding);
if (name instanceof ICPPASTQualifiedName) { if (name instanceof ICPPASTQualifiedName) {
IASTName[] names = ((ICPPASTQualifiedName)name).getNames(); IASTName[] names = ((ICPPASTQualifiedName)name).getNames();
if (names.length == 1) if (names.length == 1)

View file

@ -132,8 +132,11 @@ public class PDOMCPPNamespace extends PDOMBinding
private static final class FindBinding extends PDOMNamedNode.NodeFinder { private static final class FindBinding extends PDOMNamedNode.NodeFinder {
PDOMBinding pdomBinding; PDOMBinding pdomBinding;
final int desiredType; final int[] desiredType;
public FindBinding(PDOM pdom, char[] name, int desiredType) { public FindBinding(PDOM pdom, char[] name, int desiredType) {
this(pdom, name, new int[] { desiredType });
}
public FindBinding(PDOM pdom, char[] name, int[] desiredType) {
super(pdom, name); super(pdom, name);
this.desiredType = desiredType; this.desiredType = desiredType;
} }
@ -144,13 +147,16 @@ public class PDOMCPPNamespace extends PDOMBinding
if (!tBinding.hasName(name)) if (!tBinding.hasName(name))
// no more bindings with our desired name // no more bindings with our desired name
return false; return false;
if (tBinding.getNodeType() != desiredType) int nodeType = tBinding.getNodeType();
// wrong type, try again for (int i = 0; i < desiredType.length; ++i)
return true; if (nodeType == desiredType[i]) {
// got it
pdomBinding = tBinding;
return false;
}
// got it // wrong type, try again
pdomBinding = tBinding; return true;
return false;
} }
} }
@ -161,8 +167,32 @@ public class PDOMCPPNamespace extends PDOMBinding
return lastName != null ? lastName.resolveBinding() : null; return lastName != null ? lastName.resolveBinding() : null;
} }
IASTNode parent = name.getParent(); IASTNode parent = name.getParent();
if (parent instanceof ICPPASTQualifiedName) if (parent instanceof ICPPASTQualifiedName) {
parent = parent.getParent(); IASTName[] names = ((ICPPASTQualifiedName)parent).getNames();
if (name == names[names.length - 1]) {
parent = parent.getParent();
} else {
IASTName nsname = null;
for (int i = 0; i < names.length - 2; ++i) {
if (name != names[i])
nsname = names[i];
}
// make sure we're the namespace they're talking about
if (nsname != null && !equals(pdom.resolveBinding(nsname)))
return null;
// Look up the name
FindBinding visitor = new FindBinding(pdom, name.toCharArray(),
new int[] {
PDOMCPPLinkage.CPPCLASSTYPE,
PDOMCPPLinkage.CPPNAMESPACE,
PDOMCPPLinkage.CPPFUNCTION,
PDOMCPPLinkage.CPPVARIABLE
});
getIndex().accept(visitor);
return visitor.pdomBinding;
}
}
if (parent instanceof IASTIdExpression) { if (parent instanceof IASTIdExpression) {
// reference // reference
IASTNode eParent = parent.getParent(); IASTNode eParent = parent.getParent();

View file

@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
@ -69,7 +70,7 @@ public class OpenDeclarationsAction extends SelectionParseAction {
IASTName searchName = selectedNames[0]; IASTName searchName = selectedNames[0];
IBinding binding = searchName.resolveBinding(); IBinding binding = searchName.resolveBinding();
if (binding != null) { if (binding != null && !(binding instanceof IProblemBinding)) {
final IASTName[] declNames = ast.getDeclarations(binding); final IASTName[] declNames = ast.getDeclarations(binding);
if (declNames.length > 0) { if (declNames.length > 0) {
Display.getDefault().asyncExec(new Runnable() { Display.getDefault().asyncExec(new Runnable() {