Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2006-05-31 17:56:43 +0000
committerDoug Schaefer2006-05-31 17:56:43 +0000
commitbc520fcaffb0a059c0a6c36e354090af027cbbe0 (patch)
treecc8e236f0f0509158c0818fd3ea870ab60f1829f
parentd0636fd9836410fb003dfbc2617eaa611cdcac5a (diff)
downloadorg.eclipse.cdt-bc520fcaffb0a059c0a6c36e354090af027cbbe0.tar.gz
org.eclipse.cdt-bc520fcaffb0a059c0a6c36e354090af027cbbe0.tar.xz
org.eclipse.cdt-bc520fcaffb0a059c0a6c36e354090af027cbbe0.zip
Bug 144095 - Added hooks to look up things in PDOMCPPNamespace when they aren't found during the regular scope lookup.
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java19
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java7
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java3
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java48
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java3
5 files changed, 66 insertions, 14 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java
index 49455b26a7..c381648c88 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java
@@ -13,11 +13,13 @@
*/
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.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
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.ICPPScope;
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.ObjectSet;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
+import org.eclipse.cdt.internal.core.pdom.PDOM;
/**
* @author aniefer
@@ -80,10 +83,10 @@ abstract public class CPPScope implements ICPPScope{
public IBinding getBinding(IASTName name, boolean forceResolve) throws DOMException {
char [] c = name.toCharArray();
//can't look up bindings that don't have a name
- if( c.length == 0 || bindings == null )
+ if( c.length == 0 )
return null;
- Object obj = bindings.get( c );
+ Object obj = bindings != null ? bindings.get( c ) : null;
if( obj != null ){
if( obj instanceof ObjectSet ) {
ObjectSet os = (ObjectSet) obj;
@@ -121,6 +124,18 @@ abstract public class CPPScope implements ICPPScope{
return binding;
}
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;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java
index 61fbe3d572..0453ff6785 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java
@@ -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.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
+import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
/**
* @author aniefer
@@ -746,7 +747,7 @@ public class CPPSemantics {
addDefinition( binding, data.astName );
}
}
- if( binding == null ){
+ if( binding == null || binding instanceof IProblemBinding ){
// Let's try the pdom
IPDOM pdom = name.getTranslationUnit().getIndex();
if (pdom != null) {
@@ -1025,7 +1026,9 @@ public class CPPSemantics {
} else {
if (!data.prefixLookup && data.astName != null ) {
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, lookupInScope( data, scope, blockItem ), true );
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
index c574f92b94..6828088d2a 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
@@ -232,6 +232,9 @@ public class PDOMCPPLinkage extends PDOMLinkage {
}
public IBinding resolveBinding(IASTName name) throws CoreException {
+ IBinding origBinding = name.getBinding();
+ if (origBinding != null)
+ return adaptBinding(origBinding);
if (name instanceof ICPPASTQualifiedName) {
IASTName[] names = ((ICPPASTQualifiedName)name).getNames();
if (names.length == 1)
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java
index c3415a4b4f..db89d08572 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java
@@ -132,8 +132,11 @@ public class PDOMCPPNamespace extends PDOMBinding
private static final class FindBinding extends PDOMNamedNode.NodeFinder {
PDOMBinding pdomBinding;
- final int desiredType;
+ final int[] desiredType;
public FindBinding(PDOM pdom, char[] name, int desiredType) {
+ this(pdom, name, new int[] { desiredType });
+ }
+ public FindBinding(PDOM pdom, char[] name, int[] desiredType) {
super(pdom, name);
this.desiredType = desiredType;
}
@@ -144,13 +147,16 @@ public class PDOMCPPNamespace extends PDOMBinding
if (!tBinding.hasName(name))
// no more bindings with our desired name
return false;
- if (tBinding.getNodeType() != desiredType)
- // wrong type, try again
- return true;
+ int nodeType = tBinding.getNodeType();
+ for (int i = 0; i < desiredType.length; ++i)
+ if (nodeType == desiredType[i]) {
+ // got it
+ pdomBinding = tBinding;
+ return false;
+ }
- // got it
- pdomBinding = tBinding;
- return false;
+ // wrong type, try again
+ return true;
}
}
@@ -161,8 +167,32 @@ public class PDOMCPPNamespace extends PDOMBinding
return lastName != null ? lastName.resolveBinding() : null;
}
IASTNode parent = name.getParent();
- if (parent instanceof ICPPASTQualifiedName)
- parent = parent.getParent();
+ if (parent instanceof ICPPASTQualifiedName) {
+ 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) {
// reference
IASTNode eParent = parent.getParent();
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java
index 4c39b9dac9..bb4bcf1f9d 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java
@@ -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.IASTTranslationUnit;
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.IWorkingCopy;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
@@ -69,7 +70,7 @@ public class OpenDeclarationsAction extends SelectionParseAction {
IASTName searchName = selectedNames[0];
IBinding binding = searchName.resolveBinding();
- if (binding != null) {
+ if (binding != null && !(binding instanceof IProblemBinding)) {
final IASTName[] declNames = ast.getDeclarations(binding);
if (declNames.length > 0) {
Display.getDefault().asyncExec(new Runnable() {

Back to the top