Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMarkus Schorn2008-04-23 16:51:58 +0000
committerMarkus Schorn2008-04-23 16:51:58 +0000
commitb46e95b387a52afb03a7df29714afe789d2af924 (patch)
tree9dd5c6eff638751c78c523d2b497309668e5fc3e /core
parenteb2d63351aa327ec7aac09797ab9d2526002524e (diff)
downloadorg.eclipse.cdt-b46e95b387a52afb03a7df29714afe789d2af924.tar.gz
org.eclipse.cdt-b46e95b387a52afb03a7df29714afe789d2af924.tar.xz
org.eclipse.cdt-b46e95b387a52afb03a7df29714afe789d2af924.zip
Adapting template related bindings to their counterparts in the index, bug 214017.
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java93
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java13
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java14
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexInternalTemplateParameter.java21
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexCPPSignatureUtil.java81
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPTemplateTypeParameter.java15
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java59
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java140
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplatePartialSpecialization.java11
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java344
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTypeParameter.java37
11 files changed, 469 insertions, 359 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
index a47ffaa64cd..9447e16b21a 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
@@ -59,50 +59,6 @@ import org.eclipse.core.runtime.CoreException;
public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBase {
public static class SingleProject extends IndexCPPTemplateResolutionTest {
public SingleProject() {setStrategy(new SinglePDOMTestStrategy(true));}
-
- // template<typename _TpAllocatorForward>
- // class Allocator;
- //
- // template<>
- // class Allocator<void> {
- // public:
- // template<typename _TpRebind>
- // struct rebind {
- // typedef Allocator<_TpRebind> other;
- // };
- // };
- //
- // template<typename _TpAllocator>
- // class Allocator {
- // public:
- // typedef _TpAllocator& alloc_reference;
- // template<typename _TpRebind>
- // struct rebind {
- // typedef Allocator<_TpRebind> other;
- // };
- // };
- //
- // template<typename _TpBase, typename _AllocBase>
- // class VecBase {
- // public:
- // typedef typename _AllocBase::template rebind<_TpBase>::other _Tp_alloc_type;
- // };
- //
- // template<typename _Tp, typename _Alloc = Allocator<_Tp> >
- // class Vec : protected VecBase<_Tp, _Alloc> {
- // public:
- // typedef typename VecBase<_Tp, _Alloc>::_Tp_alloc_type::alloc_reference reference;
- // };
-
- // void f(Vec<int>::reference r) {}
- public void _testRebindPattern_214017_3() throws Exception {
- IBinding b0= getBindingFromASTName("r)", 1);
- assertInstance(b0, ICPPVariable.class);
- IType type = ((ICPPVariable) b0).getType();
- type = SemanticUtil.getUltimateType(type, false);
- assertInstance(type, IBasicType.class);
- assertEquals("int", ASTTypeUtil.getType(type));
- }
}
public static class ProjectWithDepProj extends IndexCPPTemplateResolutionTest {
@@ -176,6 +132,50 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
assertEquals("int", ASTTypeUtil.getType(type));
}
+ // template<typename _TpAllocatorForward>
+ // class Allocator;
+ //
+ // template<>
+ // class Allocator<void> {
+ // public:
+ // template<typename _TpRebind>
+ // struct rebind {
+ // typedef Allocator<_TpRebind> other;
+ // };
+ // };
+ //
+ // template<typename _TpAllocator>
+ // class Allocator {
+ // public:
+ // typedef _TpAllocator& alloc_reference;
+ // template<typename _TpRebind>
+ // struct rebind {
+ // typedef Allocator<_TpRebind> other;
+ // };
+ // };
+ //
+ // template<typename _TpBase, typename _AllocBase>
+ // class VecBase {
+ // public:
+ // typedef typename _AllocBase::template rebind<_TpBase>::other _Tp_alloc_type;
+ // };
+ //
+ // template<typename _Tp, typename _Alloc = Allocator<_Tp> >
+ // class Vec : protected VecBase<_Tp, _Alloc> {
+ // public:
+ // typedef typename VecBase<_Tp, _Alloc>::_Tp_alloc_type::alloc_reference reference;
+ // };
+
+ // void f(Vec<int>::reference r) {}
+ public void testRebindPattern_214017_3() throws Exception {
+ IBinding b0= getBindingFromASTName("r)", 1);
+ assertInstance(b0, ICPPVariable.class);
+ IType type = ((ICPPVariable) b0).getType();
+ type = SemanticUtil.getUltimateType(type, false);
+ assertInstance(type, IBasicType.class);
+ assertEquals("int", ASTTypeUtil.getType(type));
+ }
+
// class Str1 {
// public:
// Str1(const char* s) {
@@ -489,9 +489,8 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
getBindingFromASTName("Z z;", 1)
};
- for(int i=0; i<bs.length; i++) {
- IBinding b= bs[i];
- assertInstance(b, ICPPClassType.class);
+ for (IBinding b : bs) {
+ assertInstance(b, ICPPClassType.class);
ICPPClassType C= (ICPPClassType) b;
assertEquals(1, C.getBases().length);
ICPPClassType xb= (ICPPClassType) C.getBases()[0].getBaseClass();
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java
index f8bdbc9611c..2f99b6c8b15 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 IBM Corporation.
+ * Copyright (c) 2007, 2008 IBM Corporation.
* 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
@@ -44,6 +44,11 @@ import org.eclipse.core.runtime.NullProgressMonitor;
*
*/
public class PDOMSearchTest extends PDOMTestBase {
+ final Comparator<IBinding> BINDING_COMPARATOR = new Comparator<IBinding>() {
+ public int compare(IBinding o1, IBinding o2) {
+ return o1.getName().compareTo(o2.getName());
+ }};
+
protected ICProject project;
protected PDOM pdom;
protected IProgressMonitor NULL_MONITOR = new NullProgressMonitor();
@@ -152,6 +157,7 @@ public class PDOMSearchTest extends PDOMTestBase {
// fields
IBinding[] fields = class2.getFields();
assertEquals(2, fields.length);
+ Arrays.sort(fields, BINDING_COMPARATOR);
assertEquals("class1x", fields[0].getName());
assertEquals("class1y", fields[1].getName());
@@ -179,10 +185,7 @@ public class PDOMSearchTest extends PDOMTestBase {
assertEquals("Class2", getBindingQualifiedName(pdom.getLinkageImpls()[0].adaptBinding(cls1)));
methods = cls1.getDeclaredMethods();
assertEquals(3, methods.length);
- Arrays.sort(methods, new Comparator<IBinding>() {
- public int compare(IBinding o1, IBinding o2) {
- return o1.getName().compareTo(o2.getName());
- }});
+ Arrays.sort(methods, BINDING_COMPARATOR);
assertEquals("Class2", methods[0].getName());
assertEquals("~Class2", methods[2].getName());
assertEquals("foo", methods[1].getName());
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java
index b15a9ec6306..d27a22e3379 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java
@@ -1,16 +1,13 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 IBM Corporation and others.
+ * Copyright (c) 2005, 2008 IBM Corporation 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:
- * IBM - Initial API and implementation
+ * IBM - Initial API and implementation
*******************************************************************************/
-/*
- * Created on Apr 5, 2005
- */
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
@@ -112,7 +109,12 @@ public class CPPClassTemplatePartialSpecialization extends CPPClassTemplate impl
*/
public ObjectMap getArgumentMap() {
IType[] arg= getArguments();
- ICPPTemplateParameter[] params = getTemplateParameters();
+ ICPPTemplateParameter[] params;
+ try {
+ params = getPrimaryClassTemplate().getTemplateParameters();
+ } catch (DOMException e) {
+ return ObjectMap.EMPTY_MAP;
+ }
ObjectMap map = new ObjectMap(params.length);
for (int i = 0; i < params.length; i++) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexInternalTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexInternalTemplateParameter.java
deleted file mode 100644
index 5df3a88df6c..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexInternalTemplateParameter.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 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:
- * Andrew Ferguson (Symbian) - Initial implementation
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.index;
-
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * This interface is possibly interim. It allows determining the owner of a parameter.
- */
-public interface IIndexInternalTemplateParameter {
- ICPPBinding getParameterOwner() throws CoreException;
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexCPPSignatureUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexCPPSignatureUtil.java
index a2c8740c175..292130b8310 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexCPPSignatureUtil.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexCPPSignatureUtil.java
@@ -6,11 +6,16 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
- * Andrew Ferguson (Symbian)
+ * QNX - Initial API and implementation
+ * Andrew Ferguson (Symbian)
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
@@ -20,15 +25,15 @@ import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
+import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
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.parser.util.ObjectMap;
-import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.core.runtime.CoreException;
/**
@@ -90,39 +95,73 @@ public class IndexCPPSignatureUtil {
* @throws DOMException
*/
private static String getTemplateArgString(IType[] types, boolean qualifyTemplateParameters) throws CoreException, DOMException {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append('<');
for (int i = 0; i < types.length; i++) {
if (i>0) {
buffer.append(',');
}
- if (qualifyTemplateParameters && types[i] instanceof ICPPTemplateParameter) {
- ICPPBinding parent = null;
- if (types[i] instanceof IIndexInternalTemplateParameter) {
- parent = ((IIndexInternalTemplateParameter)types[i]).getParameterOwner();
- } else {
- IName parentName = ((ICPPTemplateParameter)types[i]).getScope().getScopeName();
- if (parentName instanceof IASTName) {
- parent = (ICPPBinding)((IASTName)parentName).resolveBinding();
+ final IType type = types[i];
+ if (qualifyTemplateParameters && type instanceof ICPPTemplateParameter) {
+ List<IBinding> parents = new ArrayList<IBinding>();
+ IScope parentScope= ((ICPPTemplateParameter) type).getScope();
+ while (parentScope != null) {
+ if (parentScope instanceof IIndexScope) {
+ parents.add(((IIndexScope)parentScope).getScopeBinding());
+ }
+ else {
+ final IName scopeName = parentScope.getScopeName();
+ if (scopeName instanceof IASTName) {
+ parents.add(((IASTName) scopeName).resolveBinding());
+ }
+ }
+ parentScope= parentScope.getParent();
+ while (parentScope instanceof ICPPTemplateScope) {
+ parentScope= parentScope.getParent();
}
}
//identical template parameters from different templates must have unique signatures
- if (parent != null) {
- buffer.append(CPPVisitor.renderQualifiedName(parent.getQualifiedName()));
- String sig = getSignature(parent);
- if (sig != null)
- buffer.append(sig);
- buffer.append("::"); //$NON-NLS-1$
+ Collections.reverse(parents);
+ for (IBinding binding : parents) {
+ if (binding != null) {
+ buffer.append(binding.getNameCharArray());
+ if (binding instanceof ICPPTemplateDefinition) {
+ if (binding instanceof ICPPSpecialization) {
+ ICPPSpecialization spec= (ICPPSpecialization) binding;
+ appendTemplateParams(spec.getArgumentMap().keyArray(), buffer);
+ appendTemplateParams(spec.getArgumentMap().valueArray(), buffer);
+ }
+ else {
+ ICPPTemplateDefinition def= (ICPPTemplateDefinition) binding;
+ appendTemplateParams(def.getTemplateParameters(), buffer);
+ }
+ }
+ buffer.append("::"); //$NON-NLS-1$
+ }
}
- buffer.append(((ICPPTemplateParameter)types[i]).getName());
+ buffer.append(((ICPPTemplateParameter)type).getName());
} else {
- buffer.append(ASTTypeUtil.getType(types[i]));
+ buffer.append(ASTTypeUtil.getType(type));
}
}
buffer.append('>');
return buffer.toString();
}
+ private static void appendTemplateParams(Object[] values, StringBuilder buffer) {
+ boolean needcomma= false;
+ buffer.append('<');
+ for (final Object val : values) {
+ if (val instanceof IType) {
+ if (needcomma)
+ buffer.append(',');
+ needcomma= true;
+ buffer.append(ASTTypeUtil.getType((IType) val));
+ }
+ }
+ buffer.append('>');
+ }
+
/**
* Constructs a string in the format:
* (paramName1,paramName2,...)
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPTemplateTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPTemplateTypeParameter.java
index 1393b34df7f..4caef5155de 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPTemplateTypeParameter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPTemplateTypeParameter.java
@@ -1,26 +1,22 @@
/*******************************************************************************
- * Copyright (c) 2007 Symbian Software Systems and others.
+ * Copyright (c) 2007, 2008 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:
- * Andrew Ferguson (Symbian) - Initial implementation
+ * Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IType;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
-import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
-import org.eclipse.cdt.internal.core.index.IIndexInternalTemplateParameter;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
-import org.eclipse.core.runtime.CoreException;
-public class CompositeCPPTemplateTypeParameter extends CompositeCPPBinding implements ICPPTemplateTypeParameter, IIndexType, IIndexInternalTemplateParameter {
+public class CompositeCPPTemplateTypeParameter extends CompositeCPPBinding implements ICPPTemplateTypeParameter, IIndexType {
public CompositeCPPTemplateTypeParameter(ICompositesFactory cf, ICPPTemplateTypeParameter binding) {
super(cf, binding);
@@ -34,11 +30,6 @@ public class CompositeCPPTemplateTypeParameter extends CompositeCPPBinding imple
public boolean isSameType(IType type) {
return ((IType)rbinding).isSameType(type);
}
-
- public ICPPBinding getParameterOwner() throws CoreException {
- IIndexFragmentBinding preresult= (IIndexFragmentBinding) ((IIndexInternalTemplateParameter)rbinding).getParameterOwner();
- return (ICPPBinding) cf.getCompositeBinding(preresult);
- }
@Override
public Object clone() {
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 1f838b21437..3671482c7eb 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
@@ -25,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.IFunction;
+import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IQualifierType;
@@ -178,48 +179,32 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
return new FindBinding.NestedBindingsBTreeComparator(this);
}
- public abstract PDOMBinding addBinding(IASTName name) throws CoreException;
-
- public abstract PDOMBinding addBinding(IBinding binding, IASTName fromName) throws CoreException;
-
- public final PDOMBinding adaptBinding(final IBinding inputBinding) throws CoreException {
- if (inputBinding == null || inputBinding instanceof IProblemBinding) {
- return null;
+ protected boolean cannotAdapt(final IBinding inputBinding) throws CoreException {
+ if (inputBinding == null || inputBinding instanceof IProblemBinding || inputBinding instanceof IParameter) {
+ return true;
}
-
- IBinding binding= inputBinding;
+ if (inputBinding instanceof PDOMBinding) {
+ PDOMBinding pdomBinding = (PDOMBinding) inputBinding;
+ if (pdomBinding.getPDOM() != getPDOM() && pdomBinding.isFileLocal()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected final PDOMBinding attemptFastAdaptBinding(final IBinding binding) throws CoreException {
if (binding instanceof PDOMBinding) {
// there is no guarantee, that the binding is from the same PDOM object.
PDOMBinding pdomBinding = (PDOMBinding) binding;
if (pdomBinding.getPDOM() == getPDOM()) {
return pdomBinding;
}
- // if the binding is from another pdom it has to be adapted. However don't adapt file-local bindings
- if (pdomBinding.isFileLocal()) {
- return null;
- }
}
-
- PDOMBinding result= (PDOMBinding) pdom.getCachedResult(inputBinding);
- if (result != null) {
- return result;
- }
-
- // assign names to anonymous types.
- binding= PDOMASTAdapter.getAdapterForAnonymousASTBinding(binding);
- if (binding == null) {
- return null;
- }
-
- result= doAdaptBinding(binding);
- if (result != null) {
- pdom.putCachedResult(inputBinding, result);
- }
- return result;
+ return (PDOMBinding) pdom.getCachedResult(binding);
}
+ public abstract PDOMBinding adaptBinding(IBinding binding) throws CoreException;
+ public abstract PDOMBinding addBinding(IASTName name) throws CoreException;
- protected abstract PDOMBinding doAdaptBinding(IBinding binding) throws CoreException;
-
final protected int getLocalToFileRec(PDOMNode parent, IBinding binding) throws CoreException {
int rec= 0;
if (parent instanceof PDOMBinding) {
@@ -391,4 +376,14 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
pdom.putCachedResult(key, null);
getMacroIndex().delete(container.getRecord());
}
+
+ /**
+ * For debugging purposes, only.
+ */
+ @Override
+ public String toString() {
+ return getLinkageName();
+ }
+
+
}
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 428bfd49faf..2a80c488554 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
@@ -27,7 +27,6 @@ import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IField;
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;
@@ -78,59 +77,78 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
return C_LINKAGE_ID;
}
- @Override
- public PDOMBinding addBinding(IBinding binding, IASTName fromName) throws CoreException {
- PDOMBinding pdomBinding = adaptBinding(binding);
- if (pdomBinding != null) {
- if (shouldUpdate(pdomBinding, fromName)) {
- pdomBinding.update(this, fromName.getBinding());
- }
+ private PDOMBinding addBinding(final IBinding inputBinding, IASTName fromName) throws CoreException {
+ if (cannotAdapt(inputBinding)) {
+ return null;
}
- else {
+
+ PDOMBinding pdomBinding= attemptFastAdaptBinding(inputBinding);
+
+ if (pdomBinding == null) {
// assign names to anonymous types.
- binding= PDOMASTAdapter.getAdapterForAnonymousASTBinding(binding);
- if (binding == null || binding instanceof IParameter)
- return null; // skip parameters
+ IBinding binding= PDOMASTAdapter.getAdapterForAnonymousASTBinding(inputBinding);
+ if (binding == null)
+ return null;
PDOMNode parent = getAdaptedParent(binding);
if (parent == null)
return null;
-
- if (binding instanceof IField) { // must be before IVariable
- if (parent instanceof IPDOMMemberOwner)
- pdomBinding = new PDOMCField(pdom, (IPDOMMemberOwner)parent, (IField) binding);
- } else if (binding instanceof IVariable) {
- IVariable var= (IVariable) binding;
- pdomBinding = new PDOMCVariable(pdom, parent, var);
- } else if (binding instanceof IFunction) {
- IFunction func= (IFunction) binding;
- pdomBinding = new PDOMCFunction(pdom, parent, func);
- } else if (binding instanceof ICompositeType) {
- pdomBinding = new PDOMCStructure(pdom, parent, (ICompositeType) binding);
- } else if (binding instanceof IEnumeration) {
- pdomBinding = new PDOMCEnumeration(pdom, parent, (IEnumeration) binding);
- } else if (binding instanceof IEnumerator) {
- try {
- IEnumeration enumeration = (IEnumeration)((IEnumerator)binding).getType();
- PDOMBinding pdomEnumeration = adaptBinding(enumeration);
- if (pdomEnumeration instanceof PDOMCEnumeration)
- pdomBinding = new PDOMCEnumerator(pdom, parent, (IEnumerator) binding, (PDOMCEnumeration)pdomEnumeration);
- } catch (DOMException e) {
- throw new CoreException(Util.createStatus(e));
+
+ pdomBinding = adaptBinding(parent, binding);
+ if (pdomBinding == null) {
+ pdomBinding = createBinding(parent, binding);
+ if (pdomBinding != null) {
+ pdom.putCachedResult(inputBinding, pdomBinding);
}
- } else if (binding instanceof ITypedef) {
- pdomBinding = new PDOMCTypedef(pdom, parent, (ITypedef)binding);
+ return pdomBinding;
}
- if (pdomBinding != null) {
- pdomBinding.setLocalToFileRec(getLocalToFileRec(parent, binding));
- parent.addChild(pdomBinding);
- afterAddBinding(pdomBinding);
- }
+ pdom.putCachedResult(inputBinding, pdomBinding);
+ }
+
+ if (shouldUpdate(pdomBinding, fromName)) {
+ pdomBinding.update(this, fromName.getBinding());
}
return pdomBinding;
}
+ private PDOMBinding createBinding(PDOMNode parent, IBinding binding) throws CoreException {
+ PDOMBinding pdomBinding= null;
+
+ if (binding instanceof IField) { // must be before IVariable
+ if (parent instanceof IPDOMMemberOwner)
+ pdomBinding = new PDOMCField(pdom, (IPDOMMemberOwner)parent, (IField) binding);
+ } else if (binding instanceof IVariable) {
+ IVariable var= (IVariable) binding;
+ pdomBinding = new PDOMCVariable(pdom, parent, var);
+ } else if (binding instanceof IFunction) {
+ IFunction func= (IFunction) binding;
+ pdomBinding = new PDOMCFunction(pdom, parent, func);
+ } else if (binding instanceof ICompositeType) {
+ pdomBinding = new PDOMCStructure(pdom, parent, (ICompositeType) binding);
+ } else if (binding instanceof IEnumeration) {
+ pdomBinding = new PDOMCEnumeration(pdom, parent, (IEnumeration) binding);
+ } else if (binding instanceof IEnumerator) {
+ try {
+ IEnumeration enumeration = (IEnumeration)((IEnumerator)binding).getType();
+ PDOMBinding pdomEnumeration = adaptBinding(enumeration);
+ if (pdomEnumeration instanceof PDOMCEnumeration)
+ pdomBinding = new PDOMCEnumerator(pdom, parent, (IEnumerator) binding, (PDOMCEnumeration)pdomEnumeration);
+ } catch (DOMException e) {
+ throw new CoreException(Util.createStatus(e));
+ }
+ } else if (binding instanceof ITypedef) {
+ pdomBinding = new PDOMCTypedef(pdom, parent, (ITypedef)binding);
+ }
+
+ if (pdomBinding != null) {
+ pdomBinding.setLocalToFileRec(getLocalToFileRec(parent, binding));
+ parent.addChild(pdomBinding);
+ afterAddBinding(pdomBinding);
+ }
+ return pdomBinding;
+ }
+
private boolean shouldUpdate(PDOMBinding pdomBinding, IASTName fromName) throws CoreException {
if (fromName != null) {
if (fromName.isDefinition()) {
@@ -154,14 +172,6 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
return null;
IBinding binding = name.resolveBinding();
- if (binding == null || binding instanceof IProblemBinding)
- // can't tell what it is
- return null;
-
- if (binding instanceof IParameter)
- // skip parameters
- return null;
-
return addBinding(binding, name);
}
@@ -264,8 +274,36 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
}
@Override
- public final PDOMBinding doAdaptBinding(final IBinding binding) throws CoreException {
- PDOMNode parent = getAdaptedParent(binding);
+ public final PDOMBinding adaptBinding(final IBinding inputBinding) throws CoreException {
+ return adaptBinding(null, inputBinding);
+ }
+
+ private final PDOMBinding adaptBinding(final PDOMNode parent, IBinding inputBinding) throws CoreException {
+ if (cannotAdapt(inputBinding)) {
+ return null;
+ }
+ PDOMBinding result= attemptFastAdaptBinding(inputBinding);
+ if (result != null) {
+ return result;
+ }
+
+ // assign names to anonymous types.
+ IBinding binding= PDOMASTAdapter.getAdapterForAnonymousASTBinding(inputBinding);
+ if (binding == null) {
+ return null;
+ }
+
+ result= doAdaptBinding(parent, binding);
+ if (result != null) {
+ pdom.putCachedResult(inputBinding, result);
+ }
+ return result;
+ }
+
+ private final PDOMBinding doAdaptBinding(PDOMNode parent, final IBinding binding) throws CoreException {
+ if (parent == null) {
+ 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/PDOMCPPClassTemplatePartialSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplatePartialSpecialization.java
index aae966d5c5a..285fe00d0d7 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplatePartialSpecialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplatePartialSpecialization.java
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 QNX Software Systems and others.
+ * Copyright (c) 2007, 2008 QNX 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:
- * QNX - Initial API and implementation
+ * QNX - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
@@ -222,7 +222,12 @@ class PDOMCPPClassTemplatePartialSpecialization extends
public ObjectMap getArgumentMap() {
try {
PDOMNodeLinkedList argList = new PDOMNodeLinkedList(pdom, record + ARGUMENTS, getLinkageImpl());
- ICPPTemplateParameter[] params = getTemplateParameters();
+ ICPPTemplateParameter[] params;
+ try {
+ params = getPrimaryClassTemplate().getTemplateParameters();
+ } catch (DOMException e) {
+ return ObjectMap.EMPTY_MAP;
+ }
NodeCollector argVisitor = new NodeCollector();
argList.accept(argVisitor);
IPDOMNode[] argNodes = argVisitor.getNodes();
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 480a87591f9..ee47495ddf8 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
@@ -11,7 +11,6 @@
* Andrew Ferguson (Symbian)
* Sergey Prigogin (Google)
*******************************************************************************/
-
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import java.util.ArrayList;
@@ -29,7 +28,6 @@ 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;
-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;
@@ -201,6 +199,9 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
List<Runnable> postProcesses = new ArrayList<Runnable>();
+ /**
+ * Adds or returns existing binding for the given name.
+ */
@Override
public PDOMBinding addBinding(IASTName name) throws CoreException {
if (name == null || name instanceof ICPPASTQualifiedName)
@@ -213,15 +214,6 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
IBinding binding = name.resolveBinding();
- if (binding == null || binding instanceof IProblemBinding) {
- // Can't tell what it is
- return null;
- }
-
- if (binding instanceof IParameter)
- // Skip parameters (TODO and others I'm sure)
- return null;
-
PDOMBinding pdomBinding = addBinding(binding, name);
if (pdomBinding instanceof PDOMCPPClassType || pdomBinding instanceof PDOMCPPClassSpecialization) {
if (binding instanceof ICPPClassType && name.isDefinition()) {
@@ -229,46 +221,59 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
}
}
- handlePostProcesses();
-
+ handlePostProcesses();
return pdomBinding;
}
- @Override
- public PDOMBinding addBinding(IBinding binding, IASTName fromName) throws CoreException {
- // assign names to anonymous types.
- binding= PDOMASTAdapter.getAdapterForAnonymousASTBinding(binding);
- if (binding == null)
+ /**
+ * Adds or returns existing binding for the given one. If <code>fromName</code> is not <code>null</code>
+ * then an existing binding is updated with the properties of the name.
+ */
+ private PDOMBinding addBinding(final IBinding inputBinding, IASTName fromName) throws CoreException {
+ if (cannotAdapt(inputBinding)) {
return null;
+ }
- final PDOMNode parent= adaptOrAddParent(true, binding);
- if (parent == null)
- return null;
+ PDOMBinding pdomBinding= attemptFastAdaptBinding(inputBinding);
+ if (pdomBinding == null) {
+ // assign names to anonymous types.
+ IBinding binding= PDOMASTAdapter.getAdapterForAnonymousASTBinding(inputBinding);
+ if (binding == null)
+ return null;
+
+ final PDOMNode parent= adaptOrAddParent(true, binding);
+ if (parent == null)
+ return null;
- PDOMBinding pdomBinding = adaptBinding(binding);
- if (pdomBinding != null) {
- if (shouldUpdate(pdomBinding, fromName)) {
- pdomBinding.update(this, fromName.getBinding());
+ pdomBinding = adaptBinding(parent, binding);
+ if (pdomBinding != null) {
+ pdom.putCachedResult(inputBinding, pdomBinding);
}
- } else {
- try {
- if (binding instanceof ICPPSpecialization) {
- IBinding specialized= ((ICPPSpecialization)binding).getSpecializedBinding();
- addBinding(specialized, null);
- }
-
- pdomBinding = addBinding(parent, binding);
- if ((pdomBinding instanceof PDOMCPPClassInstance || pdomBinding instanceof PDOMCPPDeferredClassInstance) && binding instanceof ICPPClassType) {
- // Add instantiated constructors to the index (bug 201174).
- addConstructors(pdomBinding, (ICPPClassType) binding);
- if(SemanticUtil.ENABLE_224364) {
- addConversionOperators(pdomBinding, (ICPPClassType) binding);
+ else {
+ try {
+ pdomBinding = createBinding(parent, binding);
+ if (pdomBinding != null) {
+ pdom.putCachedResult(inputBinding, pdomBinding);
}
+
+ if (binding instanceof ICPPClassType && (pdomBinding instanceof PDOMCPPClassInstance
+ || pdomBinding instanceof PDOMCPPDeferredClassInstance)) {
+ // Add instantiated constructors to the index (bug 201174).
+ addConstructors(pdomBinding, (ICPPClassType) binding);
+ if(SemanticUtil.ENABLE_224364) {
+ addConversionOperators(pdomBinding, (ICPPClassType) binding);
+ }
+ }
+ } catch (DOMException e) {
+ throw new CoreException(Util.createStatus(e));
}
- } catch (DOMException e) {
- throw new CoreException(Util.createStatus(e));
+ return pdomBinding;
}
}
+
+ if (shouldUpdate(pdomBinding, fromName)) {
+ pdomBinding.update(this, fromName.getBinding());
+ }
return pdomBinding;
}
@@ -307,74 +312,16 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return false;
}
- private PDOMBinding addBinding(PDOMNode parent, IBinding binding) throws CoreException, DOMException {
+ private PDOMBinding createBinding(PDOMNode parent, IBinding binding) throws CoreException, DOMException {
PDOMBinding pdomBinding= null;
if (binding instanceof ICPPSpecialization) {
IBinding specialized = ((ICPPSpecialization)binding).getSpecializedBinding();
- PDOMBinding pdomSpecialized= adaptBinding(specialized);
+ PDOMBinding pdomSpecialized= addBinding(specialized, null);
if (pdomSpecialized == null)
return null;
- if (binding instanceof ICPPDeferredTemplateInstance) {
- if (binding instanceof ICPPFunction && pdomSpecialized instanceof ICPPFunctionTemplate) {
- pdomBinding = new PDOMCPPDeferredFunctionInstance(pdom,
- parent, (ICPPFunction) binding, pdomSpecialized);
- } else if (binding instanceof ICPPClassType && pdomSpecialized instanceof ICPPClassTemplate) {
- pdomBinding = new PDOMCPPDeferredClassInstance(pdom,
- parent, (ICPPClassType) binding, pdomSpecialized);
- }
- } else if (binding instanceof ICPPTemplateInstance) {
- if (binding instanceof ICPPConstructor && pdomSpecialized instanceof ICPPConstructor) {
- pdomBinding = new PDOMCPPConstructorInstance(pdom, parent,
- (ICPPConstructor) binding, pdomSpecialized);
- } else if (binding instanceof ICPPMethod && pdomSpecialized instanceof ICPPMethod) {
- pdomBinding = new PDOMCPPMethodInstance(pdom, parent,
- (ICPPMethod) binding, pdomSpecialized);
- } else if (binding instanceof ICPPFunction && pdomSpecialized instanceof ICPPFunction) {
- pdomBinding = new PDOMCPPFunctionInstance(pdom, parent,
- (ICPPFunction) binding, pdomSpecialized);
- } else if (binding instanceof ICPPClassType && pdomSpecialized instanceof ICPPClassType) {
- pdomBinding = new PDOMCPPClassInstance(pdom, parent,
- (ICPPClassType) binding, pdomSpecialized);
- }
- } else if (binding instanceof ICPPClassTemplatePartialSpecialization &&
- pdomSpecialized instanceof PDOMCPPClassTemplate) {
- pdomBinding = new PDOMCPPClassTemplatePartialSpecialization(
- pdom, parent, (ICPPClassTemplatePartialSpecialization) binding,
- (PDOMCPPClassTemplate) pdomSpecialized);
- } else if (binding instanceof ICPPField) {
- pdomBinding = new PDOMCPPFieldSpecialization(pdom, parent,
- (ICPPField) binding, pdomSpecialized);
- } else if (binding instanceof ICPPFunctionTemplate) {
- if (binding instanceof ICPPConstructor) {
- pdomBinding = new PDOMCPPConstructorTemplateSpecialization(
- pdom, parent, (ICPPConstructor) binding, pdomSpecialized);
- } else if (binding instanceof ICPPMethod) {
- pdomBinding = new PDOMCPPMethodTemplateSpecialization(
- pdom, parent, (ICPPMethod) binding, pdomSpecialized);
- } else if (binding instanceof ICPPFunction) {
- pdomBinding = new PDOMCPPFunctionTemplateSpecialization(
- pdom, parent, (ICPPFunctionTemplate) binding, pdomSpecialized);
- }
- } else if (binding instanceof ICPPConstructor) {
- pdomBinding = new PDOMCPPConstructorSpecialization(pdom, parent,
- (ICPPConstructor) binding, pdomSpecialized);
- } else if (binding instanceof ICPPMethod) {
- pdomBinding = new PDOMCPPMethodSpecialization(pdom, parent,
- (ICPPMethod) binding, pdomSpecialized);
- } else if (binding instanceof ICPPFunction) {
- pdomBinding = new PDOMCPPFunctionSpecialization(pdom, parent,
- (ICPPFunction) binding, pdomSpecialized);
- } else if (binding instanceof ICPPClassTemplate) {
- pdomBinding = new PDOMCPPClassTemplateSpecialization(pdom, parent,
- (ICPPClassTemplate) binding, pdomSpecialized);
- } else if (binding instanceof ICPPClassType) {
- pdomBinding = new PDOMCPPClassSpecialization(pdom, parent,
- (ICPPClassType) binding, pdomSpecialized);
- } else if (binding instanceof ITypedef) {
- pdomBinding = new PDOMCPPTypedefSpecialization(pdom, parent,
- (ITypedef) binding, pdomSpecialized);
- }
+
+ pdomBinding = createSpecializationBinding(parent, pdomSpecialized, binding);
} else if (binding instanceof ICPPTemplateParameter) {
if (binding instanceof ICPPTemplateTypeParameter) {
pdomBinding = new PDOMCPPTemplateTypeParameter(pdom, parent, (ICPPTemplateTypeParameter)binding);
@@ -453,6 +400,90 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return pdomBinding;
}
+
+ private PDOMBinding createSpecializationBinding(PDOMNode parent, PDOMBinding pdomSpecialized,
+ IBinding binding) throws CoreException {
+ if (binding instanceof ICPPDeferredTemplateInstance) {
+ if (binding instanceof ICPPFunction && pdomSpecialized instanceof ICPPFunctionTemplate) {
+ return new PDOMCPPDeferredFunctionInstance(pdom,
+ parent, (ICPPFunction) binding, pdomSpecialized);
+ }
+ if (binding instanceof ICPPClassType && pdomSpecialized instanceof ICPPClassTemplate) {
+ return new PDOMCPPDeferredClassInstance(pdom,
+ parent, (ICPPClassType) binding, pdomSpecialized);
+ }
+ return null;
+ }
+ if (binding instanceof ICPPTemplateInstance) {
+ if (binding instanceof ICPPConstructor && pdomSpecialized instanceof ICPPConstructor) {
+ return new PDOMCPPConstructorInstance(pdom, parent,
+ (ICPPConstructor) binding, pdomSpecialized);
+ }
+ if (binding instanceof ICPPMethod && pdomSpecialized instanceof ICPPMethod) {
+ return new PDOMCPPMethodInstance(pdom, parent,
+ (ICPPMethod) binding, pdomSpecialized);
+ }
+ if (binding instanceof ICPPFunction && pdomSpecialized instanceof ICPPFunction) {
+ return new PDOMCPPFunctionInstance(pdom, parent,
+ (ICPPFunction) binding, pdomSpecialized);
+ }
+ if (binding instanceof ICPPClassType && pdomSpecialized instanceof ICPPClassType) {
+ return new PDOMCPPClassInstance(pdom, parent,
+ (ICPPClassType) binding, pdomSpecialized);
+ }
+ return null;
+ }
+ if (binding instanceof ICPPClassTemplatePartialSpecialization &&
+ pdomSpecialized instanceof PDOMCPPClassTemplate) {
+ return new PDOMCPPClassTemplatePartialSpecialization(
+ pdom, parent, (ICPPClassTemplatePartialSpecialization) binding,
+ (PDOMCPPClassTemplate) pdomSpecialized);
+ }
+ if (binding instanceof ICPPField) {
+ return new PDOMCPPFieldSpecialization(pdom, parent,
+ (ICPPField) binding, pdomSpecialized);
+ }
+ if (binding instanceof ICPPFunctionTemplate) {
+ if (binding instanceof ICPPConstructor) {
+ return new PDOMCPPConstructorTemplateSpecialization(
+ pdom, parent, (ICPPConstructor) binding, pdomSpecialized);
+ }
+ if (binding instanceof ICPPMethod) {
+ return new PDOMCPPMethodTemplateSpecialization(
+ pdom, parent, (ICPPMethod) binding, pdomSpecialized);
+ }
+ if (binding instanceof ICPPFunction) {
+ return new PDOMCPPFunctionTemplateSpecialization(
+ pdom, parent, (ICPPFunctionTemplate) binding, pdomSpecialized);
+ }
+ return null;
+ }
+ if (binding instanceof ICPPConstructor) {
+ return new PDOMCPPConstructorSpecialization(pdom, parent,
+ (ICPPConstructor) binding, pdomSpecialized);
+ }
+ if (binding instanceof ICPPMethod) {
+ return new PDOMCPPMethodSpecialization(pdom, parent,
+ (ICPPMethod) binding, pdomSpecialized);
+ }
+ if (binding instanceof ICPPFunction) {
+ return new PDOMCPPFunctionSpecialization(pdom, parent,
+ (ICPPFunction) binding, pdomSpecialized);
+ }
+ if (binding instanceof ICPPClassTemplate) {
+ return new PDOMCPPClassTemplateSpecialization(pdom, parent,
+ (ICPPClassTemplate) binding, pdomSpecialized);
+ }
+ if (binding instanceof ICPPClassType) {
+ return new PDOMCPPClassSpecialization(pdom, parent,
+ (ICPPClassType) binding, pdomSpecialized);
+ }
+ if (binding instanceof ITypedef) {
+ return new PDOMCPPTypedefSpecialization(pdom, parent,
+ (ITypedef) binding, pdomSpecialized);
+ }
+ return null;
+ }
private void pushPostProcesses(PDOMBinding pdomBinding, IBinding binding) throws CoreException, DOMException {
if (pdomBinding instanceof PDOMCPPClassTemplatePartialSpecialization &&
@@ -480,7 +511,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
for (ICPPMethod method : implicit) {
PDOMBinding pdomBinding= adaptBinding(method);
if (pdomBinding == null) {
- addBinding(type, method);
+ createBinding(type, method);
} else if (!pdomBinding.hasDefinition()) {
pdomBinding.update(this, method);
}
@@ -596,12 +627,41 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return 0;
}
+ @Override
+ public final PDOMBinding adaptBinding(final IBinding inputBinding) throws CoreException {
+ return adaptBinding(null, inputBinding);
+ }
+
+ private final PDOMBinding adaptBinding(final PDOMNode parent, IBinding inputBinding) throws CoreException {
+ if (cannotAdapt(inputBinding)) {
+ return null;
+ }
+
+ PDOMBinding result= attemptFastAdaptBinding(inputBinding);
+ if (result != null) {
+ return result;
+ }
+
+ // assign names to anonymous types.
+ IBinding binding= PDOMASTAdapter.getAdapterForAnonymousASTBinding(inputBinding);
+ if (binding == null) {
+ return null;
+ }
+
+ result= doAdaptBinding(parent, binding);
+ if (result != null) {
+ pdom.putCachedResult(inputBinding, result);
+ }
+ return result;
+ }
+
/**
- * Find the equivalent binding, or binding placeholder within this PDOM
+ * Find the equivalent binding, or binding place holder within this PDOM
*/
- @Override
- public PDOMBinding doAdaptBinding(IBinding binding) throws CoreException {
- PDOMNode parent = adaptOrAddParent(false, binding);
+ private final PDOMBinding doAdaptBinding(PDOMNode parent, IBinding binding) throws CoreException {
+ if (parent == null) {
+ parent= adaptOrAddParent(false, binding);
+ }
if (parent == this) {
int localToFileRec= getLocalToFileRec(null, binding);
return CPPFindBinding.findBinding(getIndex(), this, binding, localToFileRec);
@@ -611,14 +671,6 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return CPPFindBinding.findBinding(((PDOMCPPNamespace)parent).getIndex(), this, binding,
localToFileRec);
}
- // TODO(sprigogin): Hack. There should be a better way to adapt unknown bindings.
- if (parent instanceof ICPPInternalUnknown) {
- if (binding instanceof ICPPInternalUnknownClassInstance) {
- return new PDOMCPPUnknownClassInstance(getPDOM(), parent, (ICPPInternalUnknownClassInstance) binding);
- } else if (binding instanceof ICPPInternalUnknownClassType) {
- return new PDOMCPPUnknownClassType(getPDOM(), parent, (ICPPInternalUnknownClassType) binding);
- }
- }
if (parent instanceof IPDOMMemberOwner) {
int localToFileRec= getLocalToFileRec(parent, binding);
return CPPFindBinding.findBinding(parent, this, binding, localToFileRec);
@@ -641,9 +693,11 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
private final PDOMNode adaptOrAddParent(boolean add, IBinding binding) throws CoreException {
try {
IBinding scopeBinding = null;
+ // all instances are stored with their template definition
if (binding instanceof ICPPTemplateInstance) {
- scopeBinding = ((ICPPTemplateInstance)binding).getTemplateDefinition();
- } else {
+ scopeBinding= ((ICPPTemplateInstance) binding).getTemplateDefinition();
+ }
+ else {
IScope scope = binding.getScope();
if (binding instanceof IIndexBinding) {
IIndexBinding ib= (IIndexBinding) binding;
@@ -651,72 +705,58 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
if (ib.isFileLocal()) {
return null;
}
+ // in an index the null scope represents global scope.
if (scope == null) {
- if (binding instanceof ICPPInternalUnknownClassType) {
- if (binding instanceof PDOMBinding) {
- return adaptOrAddBinding(add, ((PDOMBinding) binding).getParentBinding());
- }
- // what if we have a composite binding??
- return null;
- }
-
- // in an index the null scope represents global scope.
return this;
}
}
if (scope == null) {
- if (binding instanceof ICPPSpecialization) {
- if (((ICPPSpecialization) binding).getSpecializedBinding() instanceof IIndexBinding) {
- return this;
- }
- }
return null;
}
-
- if (scope instanceof ICPPTemplateScope &&
- !(binding instanceof ICPPTemplateParameter || binding instanceof ICPPTemplateInstance)) {
+
+ if (scope instanceof ICPPTemplateScope && !(binding instanceof ICPPTemplateParameter)) {
scope = scope.getParent();
if (scope == null) {
return this;
}
}
-
+
if (scope instanceof IIndexScope) {
if (scope instanceof CompositeScope) { // we special case for performance
return adaptOrAddBinding(add, ((CompositeScope) scope).getRawScopeBinding());
}
return adaptOrAddBinding(add, ((IIndexScope) scope).getScopeBinding());
}
-
+
// the scope is from the ast
while (scope instanceof ICPPNamespaceScope) {
- IName name= scope.getScopeName();
- if (name != null && name.toCharArray().length == 0) {
- // skip unnamed namespaces
- scope= scope.getParent();
- } else {
+ final IName name= scope.getScopeName();
+ if (name == null || name.toCharArray().length > 0) {
break;
}
+ // skip unnamed namespaces
+ scope= scope.getParent();
}
-
+
IASTNode scopeNode = ASTInternal.getPhysicalNodeOfScope(scope);
if (scopeNode instanceof IASTCompoundStatement) {
return null;
- } else if (scopeNode instanceof IASTTranslationUnit) {
+ }
+ if (scopeNode instanceof IASTTranslationUnit) {
return this;
+ }
+ if (scope instanceof ICPPClassScope) {
+ scopeBinding = ((ICPPClassScope)scope).getClassType();
+ } else if (scope instanceof ICPPInternalUnknownScope) {
+ scopeBinding = ((ICPPInternalUnknownScope) scope).getScopeBinding();
} else {
- if (scope instanceof ICPPClassScope) {
- scopeBinding = ((ICPPClassScope)scope).getClassType();
- } else if (scope instanceof ICPPInternalUnknownScope) {
- scopeBinding = ((ICPPInternalUnknownScope) scope).getScopeBinding();
- } else {
- IName scopeName = scope.getScopeName();
- if (scopeName instanceof IASTName) {
- scopeBinding = ((IASTName) scopeName).resolveBinding();
- }
+ IName scopeName = scope.getScopeName();
+ if (scopeName instanceof IASTName) {
+ scopeBinding = ((IASTName) scopeName).resolveBinding();
}
}
}
+ assert scopeBinding != binding;
if (scopeBinding != null && scopeBinding != binding) {
return adaptOrAddBinding(add, scopeBinding);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTypeParameter.java
index 3d59165b826..78291596a98 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTypeParameter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTypeParameter.java
@@ -1,18 +1,19 @@
/*******************************************************************************
- * Copyright (c) 2007 QNX Software Systems and others.
+ * Copyright (c) 2007, 2008 QNX 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:
- * QNX - Initial API and implementation
- * Markus Schorn (Wind River Systems)
- * Sergey Prigogin (Google)
+ * QNX - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
@@ -26,25 +27,27 @@ import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknown;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
-import org.eclipse.cdt.internal.core.index.IIndexInternalTemplateParameter;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.pdom.PDOM;
+import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList;
+import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
/**
* @author Bryan Wilkinson
*/
-class PDOMCPPTemplateTypeParameter extends PDOMCPPBinding implements
- ICPPTemplateTypeParameter, ICPPInternalUnknown, IIndexType, IIndexInternalTemplateParameter {
+class PDOMCPPTemplateTypeParameter extends PDOMCPPBinding implements IPDOMMemberOwner,
+ ICPPTemplateTypeParameter, ICPPInternalUnknown, IIndexType {
private static final int DEFAULT_TYPE = PDOMCPPBinding.RECORD_SIZE + 0;
-
+ private static final int MEMBERLIST = PDOMCPPBinding.RECORD_SIZE + 4;
+
/**
* The size in bytes of a PDOMCPPTemplateTypeParameter record in the database.
*/
@SuppressWarnings("hiding")
- protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE + 4;
+ protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE + 8;
public PDOMCPPTemplateTypeParameter(PDOM pdom, PDOMNode parent,
ICPPTemplateTypeParameter param) throws CoreException {
@@ -77,6 +80,22 @@ class PDOMCPPTemplateTypeParameter extends PDOMCPPBinding implements
return IIndexCPPBindingConstants.CPP_TEMPLATE_TYPE_PARAMETER;
}
+ @Override
+ public void addChild(PDOMNode member) throws CoreException {
+ addMember(member);
+ }
+
+ public void addMember(PDOMNode member) throws CoreException {
+ PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl());
+ list.addMember(member);
+ }
+
+ @Override
+ public void accept(IPDOMVisitor visitor) throws CoreException {
+ PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl());
+ list.accept(visitor);
+ }
+
public boolean isSameType(IType type) {
if (type instanceof ITypedef) {
return type.isSameType(this);

Back to the top