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:
parent
94db642b5f
commit
fd77ff4e64
7 changed files with 31 additions and 29 deletions
|
@ -93,17 +93,18 @@ public class CPPDeferredClassInstance extends CPPUnknownClass implements ICPPDef
|
||||||
@Override
|
@Override
|
||||||
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
|
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
|
||||||
IType[] arguments = getArguments();
|
IType[] arguments = getArguments();
|
||||||
IType[] newArgs = new IType[arguments.length];
|
IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope);
|
||||||
int size = arguments.length;
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
newArgs[i] = CPPTemplates.instantiateType(arguments[i], argMap, instantiationScope);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
boolean changed= arguments != newArgs;
|
||||||
ICPPClassTemplate classTemplate = getClassTemplate();
|
ICPPClassTemplate classTemplate = getClassTemplate();
|
||||||
if (argMap.containsKey(classTemplate)) {
|
if (argMap.containsKey(classTemplate)) {
|
||||||
classTemplate = (ICPPClassTemplate) argMap.get(classTemplate);
|
classTemplate = (ICPPClassTemplate) argMap.get(classTemplate);
|
||||||
|
changed= true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!changed) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
return ((ICPPInternalTemplateInstantiator) classTemplate).instantiate(newArgs);
|
return ((ICPPInternalTemplateInstantiator) classTemplate).instantiate(newArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,9 @@ public class CPPUnknownClassInstance extends CPPUnknownClass implements ICPPUnkn
|
||||||
@Override
|
@Override
|
||||||
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
|
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
|
||||||
IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope);
|
IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope);
|
||||||
|
if (parentBinding == unknownContainerBinding && newArgs == arguments) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
return new CPPUnknownClassInstance(parentBinding, name, newArgs);
|
return new CPPUnknownClassInstance(parentBinding, name, newArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -692,11 +692,12 @@ public class CPPTemplates {
|
||||||
IType ret = null;
|
IType ret = null;
|
||||||
IType[] params = null;
|
IType[] params = null;
|
||||||
try {
|
try {
|
||||||
ret = instantiateType(((IFunctionType) type).getReturnType(), argMap, instantiationScope);
|
final IType r = ((IFunctionType) type).getReturnType();
|
||||||
|
ret = instantiateType(r, argMap, instantiationScope);
|
||||||
IType[] ps = ((IFunctionType) type).getParameterTypes();
|
IType[] ps = ((IFunctionType) type).getParameterTypes();
|
||||||
params = new IType[ps.length];
|
params = instantiateTypes(ps, argMap, (ICPPScope) instantiationScope);
|
||||||
for (int i = 0; i < params.length; i++) {
|
if (ret == r && params == ps) {
|
||||||
params[i]= instantiateType(ps[i], argMap, instantiationScope);
|
return type;
|
||||||
}
|
}
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
}
|
}
|
||||||
|
@ -809,14 +810,14 @@ public class CPPTemplates {
|
||||||
IType[] result = types;
|
IType[] result = types;
|
||||||
for (int i = 0; i < types.length; i++) {
|
for (int i = 0; i < types.length; i++) {
|
||||||
IType type = CPPTemplates.instantiateType(types[i], argMap, instantiationScope);
|
IType type = CPPTemplates.instantiateType(types[i], argMap, instantiationScope);
|
||||||
if (type != types[i]) {
|
if (result != types) {
|
||||||
if (result == types) {
|
result[i]= type;
|
||||||
result = new IType[types.length];
|
} else if (type != types[i]) {
|
||||||
if (i > 0) {
|
result = new IType[types.length];
|
||||||
System.arraycopy(types, 0, result, 0, i);
|
if (i > 0) {
|
||||||
}
|
System.arraycopy(types, 0, result, 0, i);
|
||||||
}
|
}
|
||||||
result[i] = type;
|
result[i]= type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -68,11 +68,9 @@ public class CompositeCPPDeferredClassInstance extends CompositeCPPClassType imp
|
||||||
|
|
||||||
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
|
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
|
||||||
IType[] arguments = getArguments();
|
IType[] arguments = getArguments();
|
||||||
|
IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope);
|
||||||
IType [] newArgs = new IType[ arguments.length ];
|
if (arguments == newArgs) {
|
||||||
int size = arguments.length;
|
return this;
|
||||||
for( int i = 0; i < size; i++ ){
|
|
||||||
newArgs[i] = CPPTemplates.instantiateType( arguments[i], argMap, instantiationScope);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((ICPPInternalTemplateInstantiator)getTemplateDefinition()).instantiate( newArgs );
|
return ((ICPPInternalTemplateInstantiator)getTemplateDefinition()).instantiate( newArgs );
|
||||||
|
|
|
@ -156,6 +156,9 @@ class PDOMCPPDeferredClassInstance extends PDOMCPPInstance implements ICPPDeferr
|
||||||
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
|
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
|
||||||
IType[] arguments = getArguments();
|
IType[] arguments = getArguments();
|
||||||
IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope);
|
IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope);
|
||||||
|
if (arguments == newArgs) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
return ((ICPPInternalTemplateInstantiator) getTemplateDefinition()).instantiate(newArgs);
|
return ((ICPPInternalTemplateInstantiator) getTemplateDefinition()).instantiate(newArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
@ -108,7 +107,7 @@ class PDOMCPPUnknownClassInstance extends PDOMCPPUnknownClassType implements ICP
|
||||||
IType[] arguments = getArguments();
|
IType[] arguments = getArguments();
|
||||||
IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope);
|
IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope);
|
||||||
if (parentBinding instanceof PDOMNode && isChildOf((PDOMNode) parentBinding) &&
|
if (parentBinding instanceof PDOMNode && isChildOf((PDOMNode) parentBinding) &&
|
||||||
Arrays.equals(newArgs, arguments)) {
|
newArgs == arguments) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
IASTName name = new CPPASTName(getNameCharArray());
|
IASTName name = new CPPASTName(getNameCharArray());
|
||||||
|
|
|
@ -247,11 +247,8 @@ class PDOMCPPUnknownClassType extends PDOMCPPBinding implements ICPPClassScope,
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
|
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
|
||||||
try {
|
if (parentBinding instanceof PDOMNode && isChildOf((PDOMNode) parentBinding)) {
|
||||||
if (parentBinding == getParentBinding()) {
|
return this;
|
||||||
return this;
|
|
||||||
}
|
|
||||||
} catch (CoreException e) {
|
|
||||||
}
|
}
|
||||||
return new CPPUnknownClass(parentBinding, getUnknownName());
|
return new CPPUnknownClass(parentBinding, getUnknownName());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue