1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Correct CPPTemplates.instantiateTypes(..) and use it where possible.

This commit is contained in:
Markus Schorn 2008-05-14 09:26:08 +00:00
parent 94db642b5f
commit fd77ff4e64
7 changed files with 31 additions and 29 deletions

View file

@ -93,17 +93,18 @@ public class CPPDeferredClassInstance extends CPPUnknownClass implements ICPPDef
@Override
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
IType[] arguments = getArguments();
IType[] newArgs = new IType[arguments.length];
int size = arguments.length;
for (int i = 0; i < size; i++) {
newArgs[i] = CPPTemplates.instantiateType(arguments[i], argMap, instantiationScope);
}
IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope);
boolean changed= arguments != newArgs;
ICPPClassTemplate classTemplate = getClassTemplate();
if (argMap.containsKey(classTemplate)) {
classTemplate = (ICPPClassTemplate) argMap.get(classTemplate);
changed= true;
}
if (!changed) {
return this;
}
return ((ICPPInternalTemplateInstantiator) classTemplate).instantiate(newArgs);
}

View file

@ -38,6 +38,9 @@ public class CPPUnknownClassInstance extends CPPUnknownClass implements ICPPUnkn
@Override
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope);
if (parentBinding == unknownContainerBinding && newArgs == arguments) {
return this;
}
return new CPPUnknownClassInstance(parentBinding, name, newArgs);
}

View file

@ -692,11 +692,12 @@ public class CPPTemplates {
IType ret = null;
IType[] params = null;
try {
ret = instantiateType(((IFunctionType) type).getReturnType(), argMap, instantiationScope);
final IType r = ((IFunctionType) type).getReturnType();
ret = instantiateType(r, argMap, instantiationScope);
IType[] ps = ((IFunctionType) type).getParameterTypes();
params = new IType[ps.length];
for (int i = 0; i < params.length; i++) {
params[i]= instantiateType(ps[i], argMap, instantiationScope);
params = instantiateTypes(ps, argMap, (ICPPScope) instantiationScope);
if (ret == r && params == ps) {
return type;
}
} catch (DOMException e) {
}
@ -809,13 +810,13 @@ public class CPPTemplates {
IType[] result = types;
for (int i = 0; i < types.length; i++) {
IType type = CPPTemplates.instantiateType(types[i], argMap, instantiationScope);
if (type != types[i]) {
if (result == types) {
if (result != types) {
result[i]= type;
} else if (type != types[i]) {
result = new IType[types.length];
if (i > 0) {
System.arraycopy(types, 0, result, 0, i);
}
}
result[i]= type;
}
}

View file

@ -68,11 +68,9 @@ public class CompositeCPPDeferredClassInstance extends CompositeCPPClassType imp
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
IType[] arguments = getArguments();
IType [] newArgs = new IType[ arguments.length ];
int size = arguments.length;
for( int i = 0; i < size; i++ ){
newArgs[i] = CPPTemplates.instantiateType( arguments[i], argMap, instantiationScope);
IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope);
if (arguments == newArgs) {
return this;
}
return ((ICPPInternalTemplateInstantiator)getTemplateDefinition()).instantiate( newArgs );

View file

@ -156,6 +156,9 @@ class PDOMCPPDeferredClassInstance extends PDOMCPPInstance implements ICPPDeferr
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
IType[] arguments = getArguments();
IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope);
if (arguments == newArgs) {
return this;
}
return ((ICPPInternalTemplateInstantiator) getTemplateDefinition()).instantiate(newArgs);
}

View file

@ -12,7 +12,6 @@
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
@ -108,7 +107,7 @@ class PDOMCPPUnknownClassInstance extends PDOMCPPUnknownClassType implements ICP
IType[] arguments = getArguments();
IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope);
if (parentBinding instanceof PDOMNode && isChildOf((PDOMNode) parentBinding) &&
Arrays.equals(newArgs, arguments)) {
newArgs == arguments) {
return this;
}
IASTName name = new CPPASTName(getNameCharArray());

View file

@ -247,12 +247,9 @@ class PDOMCPPUnknownClassType extends PDOMCPPBinding implements ICPPClassScope,
}
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
try {
if (parentBinding == getParentBinding()) {
if (parentBinding instanceof PDOMNode && isChildOf((PDOMNode) parentBinding)) {
return this;
}
} catch (CoreException e) {
}
return new CPPUnknownClass(parentBinding, getUnknownName());
}