Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2008-04-06 21:49:46 +0000
committerSergey Prigogin2008-04-06 21:49:46 +0000
commit1a2abe7d43195375e2f300213605cbd5b3dc0c96 (patch)
tree07e0efc82e00b69beda4834d5425123c3ce3f4d8 /core/org.eclipse.cdt.core
parente87ef6e31dfc284e6b24fbbbdf9dea9a32f98a2d (diff)
downloadorg.eclipse.cdt-1a2abe7d43195375e2f300213605cbd5b3dc0c96.tar.gz
org.eclipse.cdt-1a2abe7d43195375e2f300213605cbd5b3dc0c96.tar.xz
org.eclipse.cdt-1a2abe7d43195375e2f300213605cbd5b3dc0c96.zip
More cleanup of template resolution code. Do not use clone.
Diffstat (limited to 'core/org.eclipse.cdt.core')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownBinding.java12
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClass.java12
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java27
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalUnknownClassType.java11
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java24
5 files changed, 69 insertions, 17 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownBinding.java
index ceba6e6b97..da70f04b97 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownBinding.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownBinding.java
@@ -31,7 +31,8 @@ import org.eclipse.core.runtime.PlatformObject;
/**
* @author aniefer
*/
-public class CPPUnknownBinding extends PlatformObject implements ICPPInternalUnknown, Cloneable {
+public abstract class CPPUnknownBinding extends PlatformObject
+ implements ICPPInternalUnknown, Cloneable {
private ICPPScope unknownScope;
protected ICPPInternalUnknown scopeBinding;
protected IASTName name;
@@ -145,15 +146,16 @@ public class CPPUnknownBinding extends PlatformObject implements ICPPInternalUnk
if (s != null && ASTInternal.isFullyCached(s))
result = s.getBinding(name, true);
} else if (t instanceof ICPPInternalUnknown) {
- CPPUnknownBinding res = clone();
- res.scopeBinding = (ICPPInternalUnknown) t;
- res.unknownScope = null;
- result = res;
+ result = resolvePartially((ICPPInternalUnknown) t, argMap);
}
}
return result;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownClassType#resolvePartially(org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknown, org.eclipse.cdt.core.parser.util.ObjectMap)
+ */
+ protected abstract IBinding resolvePartially(ICPPInternalUnknown parentBinding, ObjectMap argMap);
public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClass.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClass.java
index ced7737bc7..7e8c5a341e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClass.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClass.java
@@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
+import org.eclipse.cdt.core.parser.util.ObjectMap;
/**
* Represents a C++ class, declaration of which is not yet available.
@@ -124,4 +125,15 @@ public class CPPUnknownClass extends CPPUnknownBinding implements ICPPInternalUn
public ICPPClassType[] getNestedClasses() {
return ICPPClassType.EMPTY_CLASS_ARRAY;
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownClassType#resolvePartially(org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknown, org.eclipse.cdt.core.parser.util.ObjectMap)
+ */
+ @Override
+ public IBinding resolvePartially(ICPPInternalUnknown parentBinding, ObjectMap argMap) {
+ if (parentBinding == this.scopeBinding) {
+ return this;
+ }
+ return new CPPUnknownClass(parentBinding, name);
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java
index cd8b749d00..ab650e28aa 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java
@@ -101,25 +101,28 @@ public class CPPUnknownClassInstance extends CPPUnknownClass implements ICPPInte
return arguments;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknown#resolveUnknown(org.eclipse.cdt.core.parser.util.ObjectMap)
+ */
@Override
public IBinding resolveUnknown(ObjectMap argMap) throws DOMException {
IBinding result = super.resolveUnknown(argMap);
-
- IType[] newArgs = new IType[arguments.length];
- for (int i = 0; i < newArgs.length; i++) {
- newArgs[i] = CPPTemplates.instantiateType(arguments[i], argMap);
- }
- if (result instanceof ICPPSpecialization) {
- ICPPSpecialization specialization = (ICPPSpecialization) result;
- result = CPPTemplates.instantiateTemplate((ICPPTemplateDefinition) specialization, newArgs, null);
- } else {
- ICPPInternalUnknown newScopeBinding = result instanceof CPPUnknownBinding ?
- ((CPPUnknownBinding) result).scopeBinding : scopeBinding;
- result = new CPPUnknownClassInstance(newScopeBinding, name, newArgs);
+ if (result instanceof ICPPSpecialization && result instanceof ICPPTemplateDefinition) {
+ IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap);
+ result = CPPTemplates.instantiateTemplate((ICPPTemplateDefinition) result, newArgs, null);
}
return result;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownClassType#resolvePartially(org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknown, org.eclipse.cdt.core.parser.util.ObjectMap)
+ */
+ @Override
+ public IBinding resolvePartially(ICPPInternalUnknown parentBinding, ObjectMap argMap) {
+ IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap);
+ return new CPPUnknownClassInstance(parentBinding, name, newArgs);
+ }
+
@Override
public String toString() {
return getName() + " <" + ASTTypeUtil.getTypeListString(arguments) + ">"; //$NON-NLS-1$ //$NON-NLS-2$
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalUnknownClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalUnknownClassType.java
index 8f723ec4e2..cf3e36d14f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalUnknownClassType.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalUnknownClassType.java
@@ -10,11 +10,22 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
+import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
+import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknown;
/*
* @author Sergey Prigogin
*/
public interface ICPPInternalUnknownClassType extends ICPPClassType, ICPPInternalUnknown {
+ /**
+ * Resolves unknown type to another unknown type that is a step closer to the final
+ * name resolution.
+ * @param parentBinding a new parent binding, usually a result of partial resolution
+ * of the original parent binding.
+ * @param argMap template argument map.
+ * @return a partially resolved, but still unknown, binding.
+ */
+ public IBinding resolvePartially(ICPPInternalUnknown parentBinding, ObjectMap argMap);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java
index 190506b737..cff07c909f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java
@@ -753,6 +753,30 @@ public class CPPTemplates {
return newType;
}
+ /**
+ * Instantiates types contained in an array.
+ * @param types an array of types
+ * @param argMap template argument map
+ * @return an array containing instantiated types.
+ */
+ public static IType[] instantiateTypes(IType[] types, ObjectMap argMap) {
+ // Don't create a new array until it's really needed.
+ IType[] result = types;
+ for (int i = 0; i < types.length; i++) {
+ IType type = CPPTemplates.instantiateType(types[i], argMap);
+ if (type != types[i]) {
+ if (result == types) {
+ result = new IType[types.length];
+ if (i > 0) {
+ System.arraycopy(types, 0, result, 0, i);
+ }
+ }
+ result[i] = type;
+ }
+ }
+ return result;
+ }
+
public static ICPPASTTemplateDeclaration getTemplateDeclaration(IASTName name) {
if (name == null) return null;

Back to the top