Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2008-02-06 12:41:45 +0000
committerMarkus Schorn2008-02-06 12:41:45 +0000
commit1c88bb0adfb068a4ce69afeafb8635ac550ae1fc (patch)
tree8989b746821f7929922efefe94390d1922ed52e1
parent8a3ee521008b3fcc33c607b1ed6ce8cb467a65b3 (diff)
downloadorg.eclipse.cdt-1c88bb0adfb068a4ce69afeafb8635ac550ae1fc.tar.gz
org.eclipse.cdt-1c88bb0adfb068a4ce69afeafb8635ac550ae1fc.tar.xz
org.eclipse.cdt-1c88bb0adfb068a4ce69afeafb8635ac550ae1fc.zip
Moves c++-specific stuff from PDOMLinkage to PDOMCPPLinkage.
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java119
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java75
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java102
3 files changed, 175 insertions, 121 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java
index c03fc8823cd..019f2d59302 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java
@@ -14,14 +14,11 @@
package org.eclipse.cdt.internal.core.pdom.dom;
import org.eclipse.cdt.core.dom.ILinkage;
-import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException;
-import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
-import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
@@ -31,25 +28,12 @@ import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IQualifierType;
-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.core.dom.ast.IVariable;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
-import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexLinkage;
-import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.index.IIndexBindingConstants;
-import org.eclipse.cdt.internal.core.index.IIndexScope;
-import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
import org.eclipse.cdt.internal.core.pdom.db.BTree;
@@ -235,109 +219,6 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
}
return null;
}
-
- /**
- *
- * @param binding
- * @return <ul><li> null - skip this binding (don't add to pdom)
- * <li>this - for filescope
- * <li>a PDOMBinding instance - parent adapted binding
- * </ul>
- * @throws CoreException
- */
- protected PDOMNode getAdaptedParent(IBinding binding, boolean addParent) throws CoreException {
- try {
- IBinding scopeBinding = null;
- if (binding instanceof ICPPTemplateInstance) {
- scopeBinding = ((ICPPTemplateInstance)binding).getTemplateDefinition();
- } else {
- IScope scope = binding.getScope();
- if (scope == null) {
- if (binding instanceof ICPPDeferredTemplateInstance) {
- ICPPDeferredTemplateInstance deferred = (ICPPDeferredTemplateInstance) binding;
- ICPPTemplateDefinition template = deferred.getTemplateDefinition();
- scope = template.getScope();
- }
-
- IIndexBinding ib = (binding instanceof IIndexBinding) ? (IIndexBinding) binding : null;
-
- if (ib == null && binding instanceof ICPPSpecialization) {
- IBinding spec = ((ICPPSpecialization)binding).getSpecializedBinding();
- if (spec instanceof IIndexBinding) {
- ib = (IIndexBinding) spec;
- }
- }
-
- if (ib != null) {
- // don't adapt file local bindings from other fragments to this one.
- if (ib.isFileLocal()) {
- return null;
- }
- // in an index the null scope represents global scope.
- return this;
- }
-
- return null;
- }
-
- if (scope instanceof IIndexScope) {
- if (scope instanceof CompositeScope) { // we special case for performance
- return adaptBinding(((CompositeScope)scope).getRawScopeBinding());
- } else {
- return adaptBinding(((IIndexScope) scope).getScopeBinding());
- }
- }
-
- // the scope is from the ast
- if (scope instanceof ICPPTemplateScope && !(binding instanceof ICPPTemplateParameter || binding instanceof ICPPTemplateInstance)) {
- scope = scope.getParent();
- if (scope == null) {
- return null;
- }
- }
-
- while (scope instanceof ICPPNamespaceScope) {
- IName name= scope.getScopeName();
- if (name != null && name.toCharArray().length == 0) {
- // skip unnamed namespaces
- scope= scope.getParent();
- } else {
- break;
- }
- }
-
- IASTNode scopeNode = ASTInternal.getPhysicalNodeOfScope(scope);
- if (scopeNode instanceof IASTCompoundStatement) {
- return null;
- } else if (scopeNode instanceof IASTTranslationUnit) {
- return this;
- } else {
- if (scope instanceof ICPPClassScope) {
- scopeBinding = ((ICPPClassScope)scope).getClassType();
- } else {
- IName scopeName = scope.getScopeName();
- if (scopeName instanceof IASTName) {
- scopeBinding = ((IASTName) scopeName).resolveBinding();
- }
- }
- }
- }
- if (scopeBinding != null && scopeBinding != binding) {
- PDOMBinding scopePDOMBinding = null;
- if (addParent) {
- scopePDOMBinding = addBinding(scopeBinding, null);
- } else {
- scopePDOMBinding = adaptBinding(scopeBinding);
- }
- if (scopePDOMBinding != null)
- return scopePDOMBinding;
- }
- } catch (DOMException e) {
- throw new CoreException(Util.createStatus(e));
- }
- return null;
- }
-
final protected int getLocalToFileRec(PDOMNode parent, IBinding binding) throws CoreException {
int rec= 0;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java
index 68727593946..13533b7e0b3 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java
@@ -14,8 +14,12 @@
package org.eclipse.cdt.internal.core.pdom.dom.c;
+import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
@@ -25,12 +29,17 @@ import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
+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.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
+import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.internal.core.Util;
+import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
+import org.eclipse.cdt.internal.core.index.IIndexScope;
+import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
import org.eclipse.cdt.internal.core.pdom.dom.FindBinding;
@@ -74,7 +83,7 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
}
}
else {
- PDOMNode parent = getAdaptedParent(binding, false);
+ PDOMNode parent = getAdaptedParent(binding);
if (parent == null)
return null;
@@ -172,8 +181,70 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
return 0;
}
+ /**
+ * Adapts the parent of the given binding to an object contained in this linkage. May return
+ * <code>null</code> if the binding cannot be adapted or the binding does not exist and addParent
+ * is set to <code>false</code>.
+ * @param binding the binding to adapt
+ * @return <ul>
+ * <li> null - skip this binding (don't add to pdom)
+ * <li> this - for global scope
+ * <li> a PDOMBinding instance - parent adapted binding
+ * </ul>
+ * @throws CoreException
+ */
+ final private PDOMNode getAdaptedParent(IBinding binding) throws CoreException {
+ try {
+ IScope scope = binding.getScope();
+ if (binding instanceof IIndexBinding) {
+ IIndexBinding ib= (IIndexBinding) binding;
+ if (ib.isFileLocal()) {
+ return null;
+ }
+ // in an index the null scope represents global scope.
+ if (scope == null) {
+ return this;
+ }
+ }
+
+ if (scope == null) {
+ return null;
+ }
+
+ if (scope instanceof IIndexScope) {
+ if (scope instanceof CompositeScope) { // we special case for performance
+ return adaptBinding(((CompositeScope)scope).getRawScopeBinding());
+ } else {
+ return adaptBinding(((IIndexScope) scope).getScopeBinding());
+ }
+ }
+
+ // the scope is from the ast
+ IASTNode scopeNode = ASTInternal.getPhysicalNodeOfScope(scope);
+ IBinding scopeBinding = null;
+ if (scopeNode instanceof IASTCompoundStatement) {
+ return null;
+ } else if (scopeNode instanceof IASTTranslationUnit) {
+ return this;
+ } else {
+ IName scopeName = scope.getScopeName();
+ if (scopeName instanceof IASTName) {
+ scopeBinding = ((IASTName) scopeName).resolveBinding();
+ }
+ }
+ if (scopeBinding != null && scopeBinding != binding) {
+ PDOMBinding scopePDOMBinding= adaptBinding(scopeBinding);
+ if (scopePDOMBinding != null)
+ return scopePDOMBinding;
+ }
+ } catch (DOMException e) {
+ throw new CoreException(Util.createStatus(e));
+ }
+ return null;
+ }
+
public final PDOMBinding doAdaptBinding(final IBinding binding) throws CoreException {
- PDOMNode parent = getAdaptedParent(binding, false);
+ PDOMNode parent = getAdaptedParent(binding);
if (parent == this) {
int localToFileRec= getLocalToFileRec(null, binding);
return FindBinding.findBinding(getIndex(), getPDOM(), binding.getNameCharArray(), new int[] {getBindingType(binding)}, localToFileRec);
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 62b62ad5487..d8e8403d6d4 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
@@ -21,8 +21,10 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
@@ -55,6 +57,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
@@ -66,6 +69,8 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
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.index.IIndexCPPBindingConstants;
+import org.eclipse.cdt.internal.core.index.IIndexScope;
+import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
@@ -591,6 +596,103 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return null;
}
+ /**
+ * Adapts the parent of the given binding to an object contained in this linkage. May return
+ * <code>null</code> if the binding cannot be adapted or the binding does not exist and addParent
+ * is set to <code>false</code>.
+ * @param binding the binding to adapt
+ * @return <ul>
+ * <li> null - skip this binding (don't add to pdom)
+ * <li> this - for global scope
+ * <li> a PDOMBinding instance - parent adapted binding
+ * </ul>
+ * @throws CoreException
+ */
+ private final PDOMNode getAdaptedParent(IBinding binding, boolean addParent) throws CoreException {
+ try {
+ IBinding scopeBinding = null;
+ if (binding instanceof ICPPTemplateInstance) {
+ scopeBinding = ((ICPPTemplateInstance)binding).getTemplateDefinition();
+ } else {
+ IScope scope = binding.getScope();
+ if (binding instanceof IIndexBinding) {
+ IIndexBinding ib= (IIndexBinding) binding;
+ // don't adapt file local bindings from other fragments to this one.
+ if (ib.isFileLocal()) {
+ return null;
+ }
+ // in an index the null scope represents global scope.
+ if (scope == null) {
+ return this;
+ }
+ }
+ if (scope == null) {
+ if (binding instanceof ICPPSpecialization) {
+ if (((ICPPSpecialization) binding).getSpecializedBinding() instanceof IIndexBinding) {
+ return this;
+ }
+ }
+ return null;
+ }
+
+ if (scope instanceof IIndexScope) {
+ if (scope instanceof CompositeScope) { // we special case for performance
+ return adaptBinding(((CompositeScope)scope).getRawScopeBinding());
+ } else {
+ return adaptBinding(((IIndexScope) scope).getScopeBinding());
+ }
+ }
+
+ // the scope is from the ast
+ if (scope instanceof ICPPTemplateScope && !(binding instanceof ICPPTemplateParameter || binding instanceof ICPPTemplateInstance)) {
+ scope = scope.getParent();
+ if (scope == null) {
+ return null;
+ }
+ }
+
+ while (scope instanceof ICPPNamespaceScope) {
+ IName name= scope.getScopeName();
+ if (name != null && name.toCharArray().length == 0) {
+ // skip unnamed namespaces
+ scope= scope.getParent();
+ } else {
+ break;
+ }
+ }
+
+ IASTNode scopeNode = ASTInternal.getPhysicalNodeOfScope(scope);
+ if (scopeNode instanceof IASTCompoundStatement) {
+ return null;
+ } else if (scopeNode instanceof IASTTranslationUnit) {
+ return this;
+ } else {
+ if (scope instanceof ICPPClassScope) {
+ scopeBinding = ((ICPPClassScope)scope).getClassType();
+ } else {
+ IName scopeName = scope.getScopeName();
+ if (scopeName instanceof IASTName) {
+ scopeBinding = ((IASTName) scopeName).resolveBinding();
+ }
+ }
+ }
+ }
+ if (scopeBinding != null && scopeBinding != binding) {
+ PDOMBinding scopePDOMBinding = null;
+ if (addParent) {
+ scopePDOMBinding = addBinding(scopeBinding, null);
+ } else {
+ scopePDOMBinding = adaptBinding(scopeBinding);
+ }
+ if (scopePDOMBinding != null)
+ return scopePDOMBinding;
+ }
+ } catch (DOMException e) {
+ throw new CoreException(Util.createStatus(e));
+ }
+ return null;
+ }
+
@Override
public PDOMNode addType(PDOMNode parent, IType type) throws CoreException {
if (type instanceof IProblemBinding) {

Back to the top