mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
Cosmetics.
Change-Id: I83607322be2e3309e12604c5b5c2473aa3823f8f
This commit is contained in:
parent
17a5ba8361
commit
b59d930ed4
1 changed files with 48 additions and 50 deletions
|
@ -13,7 +13,6 @@ import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUti
|
||||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF;
|
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTNodeFactoryFactory;
|
import org.eclipse.cdt.core.dom.ast.ASTNodeFactoryFactory;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
|
@ -49,19 +48,19 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPExecution;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.InstantiationContext;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.InstantiationContext;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
public class EvalConstructor extends CPPDependentEvaluation {
|
public final class EvalConstructor extends CPPDependentEvaluation {
|
||||||
private final IType type;
|
private final IType fType;
|
||||||
private final ICPPConstructor constructor;
|
private final ICPPConstructor fConstructor;
|
||||||
private final ICPPEvaluation[] arguments;
|
private final ICPPEvaluation[] fArguments;
|
||||||
private boolean checkedIsTypeDependent;
|
private boolean fCheckedIsTypeDependent;
|
||||||
private boolean isTypeDependent;
|
private boolean fIsTypeDependent;
|
||||||
static private final IASTName tempName = ASTNodeFactoryFactory.getDefaultCPPNodeFactory().newName();
|
private static final IASTName TEMP_NAME = ASTNodeFactoryFactory.getDefaultCPPNodeFactory().newName();
|
||||||
|
|
||||||
public EvalConstructor(IType type, ICPPConstructor constructor, ICPPEvaluation[] arguments, IBinding templateDefinition) {
|
public EvalConstructor(IType type, ICPPConstructor constructor, ICPPEvaluation[] arguments, IBinding templateDefinition) {
|
||||||
super(templateDefinition);
|
super(templateDefinition);
|
||||||
this.type = type;
|
fType = type;
|
||||||
this.constructor = constructor;
|
fConstructor = constructor;
|
||||||
this.arguments = arguments != null ? arguments : new ICPPEvaluation[0];
|
fArguments = arguments != null ? arguments : ICPPEvaluation.EMPTY_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EvalConstructor(IType type, ICPPConstructor constructor, ICPPEvaluation[] arguments, IASTNode pointOfDefinition) {
|
public EvalConstructor(IType type, ICPPConstructor constructor, ICPPEvaluation[] arguments, IASTNode pointOfDefinition) {
|
||||||
|
@ -80,18 +79,18 @@ public class EvalConstructor extends CPPDependentEvaluation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTypeDependent() {
|
public boolean isTypeDependent() {
|
||||||
if (!checkedIsTypeDependent) {
|
if (!fCheckedIsTypeDependent) {
|
||||||
checkedIsTypeDependent = true;
|
fCheckedIsTypeDependent = true;
|
||||||
isTypeDependent = CPPTemplates.isDependentType(type) || containsDependentType(arguments);
|
fIsTypeDependent = CPPTemplates.isDependentType(fType) || containsDependentType(fArguments);
|
||||||
}
|
}
|
||||||
return isTypeDependent;
|
return fIsTypeDependent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValueDependent() {
|
public boolean isValueDependent() {
|
||||||
if (CPPTemplates.isDependentType(type))
|
if (CPPTemplates.isDependentType(fType))
|
||||||
return true;
|
return true;
|
||||||
for (ICPPEvaluation arg : arguments) {
|
for (ICPPEvaluation arg : fArguments) {
|
||||||
if (arg.isValueDependent())
|
if (arg.isValueDependent())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -105,7 +104,7 @@ public class EvalConstructor extends CPPDependentEvaluation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IType getType(IASTNode point) {
|
public IType getType(IASTNode point) {
|
||||||
return type;
|
return fType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -123,34 +122,33 @@ public class EvalConstructor extends CPPDependentEvaluation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ICPPEvaluation computeForFunctionCall(ActivationRecord callSiteRecord, ConstexprEvaluationContext context) {
|
public ICPPEvaluation computeForFunctionCall(ActivationRecord callSiteRecord, ConstexprEvaluationContext context) {
|
||||||
final ICPPClassType classType = (ICPPClassType)SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE);
|
final ICPPClassType classType = (ICPPClassType)SemanticUtil.getNestedType(fType, TDEF | REF | CVTYPE);
|
||||||
final CompositeValue compositeValue = CompositeValue.create(classType);
|
final CompositeValue compositeValue = CompositeValue.create(classType);
|
||||||
ICPPEvaluation[] argList = evaluateArguments(arguments, callSiteRecord, context);
|
ICPPEvaluation[] argList = evaluateArguments(fArguments, callSiteRecord, context);
|
||||||
EvalFixed constructedObject = new EvalFixed(type, ValueCategory.PRVALUE, compositeValue);
|
EvalFixed constructedObject = new EvalFixed(fType, ValueCategory.PRVALUE, compositeValue);
|
||||||
CPPVariable binding = new CPPVariable(tempName);
|
CPPVariable binding = new CPPVariable(TEMP_NAME);
|
||||||
|
|
||||||
ActivationRecord localRecord = EvalFunctionCall.createActivationRecord(
|
ActivationRecord localRecord = EvalFunctionCall.createActivationRecord(
|
||||||
this.constructor.getParameters(), argList, constructedObject, context.getPoint());
|
fConstructor.getParameters(), argList, constructedObject, context.getPoint());
|
||||||
localRecord.update(binding, constructedObject);
|
localRecord.update(binding, constructedObject);
|
||||||
|
|
||||||
ICPPExecution exec = constructor.getConstructorChainExecution(context.getPoint());
|
ICPPExecution exec = fConstructor.getConstructorChainExecution(context.getPoint());
|
||||||
if (exec instanceof ExecConstructorChain) {
|
if (exec instanceof ExecConstructorChain) {
|
||||||
ExecConstructorChain memberInitList = (ExecConstructorChain) exec;
|
ExecConstructorChain memberInitList = (ExecConstructorChain) exec;
|
||||||
Map<IBinding, ICPPEvaluation> ccInitializers = memberInitList.getConstructorChainInitializers();
|
Map<IBinding, ICPPEvaluation> ccInitializers = memberInitList.getConstructorChainInitializers();
|
||||||
for (Entry<IBinding, ICPPEvaluation> ccInitializer : ccInitializers.entrySet()) {
|
for (Map.Entry<IBinding, ICPPEvaluation> ccInitializer : ccInitializers.entrySet()) {
|
||||||
if (ccInitializer.getKey() instanceof ICPPConstructor) {
|
if (ccInitializer.getKey() instanceof ICPPConstructor) {
|
||||||
ICPPClassType baseClassType = (ICPPClassType) ccInitializer.getKey().getOwner();
|
ICPPClassType baseClassType = (ICPPClassType) ccInitializer.getKey().getOwner();
|
||||||
final ICPPEvaluation memberEval = ccInitializer.getValue();
|
final ICPPEvaluation memberEval = ccInitializer.getValue();
|
||||||
ICPPEvaluation memberValue = memberEval.computeForFunctionCall(localRecord, context.recordStep());
|
ICPPEvaluation memberValue = memberEval.computeForFunctionCall(localRecord, context.recordStep());
|
||||||
ICPPEvaluation[] baseClassValues = memberValue.getValue(context.getPoint()).getAllSubValues();
|
ICPPEvaluation[] baseClassValues = memberValue.getValue(context.getPoint()).getAllSubValues();
|
||||||
|
|
||||||
ICPPField[] baseFields = (ICPPField[])ClassTypeHelper.getFields(baseClassType, context.getPoint());
|
ICPPField[] baseFields = (ICPPField[]) ClassTypeHelper.getFields(baseClassType, context.getPoint());
|
||||||
for (ICPPField baseField : baseFields) {
|
for (ICPPField baseField : baseFields) {
|
||||||
// TODO: This has the same problem with multiple inheritance as
|
// TODO: This has the same problem with multiple inheritance as
|
||||||
// CompositeValue.create(ICPPClassType).
|
// CompositeValue.create(ICPPClassType).
|
||||||
int fieldPos = CPPASTFieldReference.getFieldPosition(baseField);
|
int fieldPos = CPPASTFieldReference.getFieldPosition(baseField);
|
||||||
constructedObject.getValue(context.getPoint()).setSubValue(fieldPos,
|
constructedObject.getValue(context.getPoint()).setSubValue(fieldPos, baseClassValues[fieldPos]);
|
||||||
baseClassValues[fieldPos]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,7 +157,7 @@ public class EvalConstructor extends CPPDependentEvaluation {
|
||||||
|
|
||||||
ICPPField[] fields = ClassTypeHelper.getDeclaredFields(classType, context.getPoint());
|
ICPPField[] fields = ClassTypeHelper.getDeclaredFields(classType, context.getPoint());
|
||||||
for (ICPPField field : fields) {
|
for (ICPPField field : fields) {
|
||||||
final Entry<IBinding, ICPPEvaluation> ccInitializer = getInitializerFromMemberInitializerList(field, exec);
|
final Map.Entry<IBinding, ICPPEvaluation> ccInitializer = getInitializerFromMemberInitializerList(field, exec);
|
||||||
|
|
||||||
ICPPEvaluation value = null;
|
ICPPEvaluation value = null;
|
||||||
if (ccInitializer != null) {
|
if (ccInitializer != null) {
|
||||||
|
@ -178,17 +176,16 @@ public class EvalConstructor extends CPPDependentEvaluation {
|
||||||
// Are these necessary?
|
// Are these necessary?
|
||||||
new EvalFunctionCall(argList, constructedObject, context.getPoint()).computeForFunctionCall(
|
new EvalFunctionCall(argList, constructedObject, context.getPoint()).computeForFunctionCall(
|
||||||
localRecord, context.recordStep());
|
localRecord, context.recordStep());
|
||||||
ICPPEvaluation resultingObject = localRecord.getVariable(binding);
|
return localRecord.getVariable(binding);
|
||||||
return resultingObject;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Entry<IBinding, ICPPEvaluation> getInitializerFromMemberInitializerList(ICPPField field, ICPPExecution exec) {
|
private Map.Entry<IBinding, ICPPEvaluation> getInitializerFromMemberInitializerList(ICPPField field, ICPPExecution exec) {
|
||||||
if (!(exec instanceof ExecConstructorChain)) {
|
if (!(exec instanceof ExecConstructorChain)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ExecConstructorChain memberInitList = (ExecConstructorChain) exec;
|
final ExecConstructorChain memberInitList = (ExecConstructorChain) exec;
|
||||||
for (Entry<IBinding, ICPPEvaluation> ccInitializer : memberInitList.getConstructorChainInitializers().entrySet()) {
|
for (Map.Entry<IBinding, ICPPEvaluation> ccInitializer : memberInitList.getConstructorChainInitializers().entrySet()) {
|
||||||
final IBinding member = ccInitializer.getKey();
|
final IBinding member = ccInitializer.getKey();
|
||||||
if (member instanceof ICPPField && member.getName().equals(field.getName())) {
|
if (member instanceof ICPPField && member.getName().equals(field.getName())) {
|
||||||
return ccInitializer;
|
return ccInitializer;
|
||||||
|
@ -197,7 +194,7 @@ public class EvalConstructor extends CPPDependentEvaluation {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ExecDeclarator getDeclaratorExecutionFromMemberInitializerList(Entry<IBinding, ICPPEvaluation> ccInitializer) {
|
private ExecDeclarator getDeclaratorExecutionFromMemberInitializerList(Map.Entry<IBinding, ICPPEvaluation> ccInitializer) {
|
||||||
final ICPPBinding member = (ICPPBinding) ccInitializer.getKey();
|
final ICPPBinding member = (ICPPBinding) ccInitializer.getKey();
|
||||||
final ICPPEvaluation memberEval = ccInitializer.getValue();
|
final ICPPEvaluation memberEval = ccInitializer.getValue();
|
||||||
return new ExecDeclarator(member, memberEval);
|
return new ExecDeclarator(member, memberEval);
|
||||||
|
@ -226,7 +223,7 @@ public class EvalConstructor extends CPPDependentEvaluation {
|
||||||
|
|
||||||
public static ICPPEvaluation[] extractArguments(IASTInitializer initializer) {
|
public static ICPPEvaluation[] extractArguments(IASTInitializer initializer) {
|
||||||
if (initializer == null) {
|
if (initializer == null) {
|
||||||
return new ICPPEvaluation[0];
|
return ICPPEvaluation.EMPTY_ARRAY;
|
||||||
} else if (initializer instanceof ICPPASTConstructorInitializer) {
|
} else if (initializer instanceof ICPPASTConstructorInitializer) {
|
||||||
ICPPASTConstructorInitializer ctorInitializer = (ICPPASTConstructorInitializer) initializer;
|
ICPPASTConstructorInitializer ctorInitializer = (ICPPASTConstructorInitializer) initializer;
|
||||||
return evaluateArguments(ctorInitializer.getArguments());
|
return evaluateArguments(ctorInitializer.getArguments());
|
||||||
|
@ -238,7 +235,8 @@ public class EvalConstructor extends CPPDependentEvaluation {
|
||||||
IASTInitializerClause initClause = equalsInitalizer.getInitializerClause();
|
IASTInitializerClause initClause = equalsInitalizer.getInitializerClause();
|
||||||
return evaluateArguments(initClause);
|
return evaluateArguments(initClause);
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("this type of initializer is not supported"); //$NON-NLS-1$
|
throw new IllegalArgumentException(initializer.getClass().getSimpleName()
|
||||||
|
+ " type of initializer is not supported"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,7 +251,7 @@ public class EvalConstructor extends CPPDependentEvaluation {
|
||||||
|
|
||||||
private ICPPEvaluation[] evaluateArguments(ICPPEvaluation[] arguments, ActivationRecord record, ConstexprEvaluationContext context) {
|
private ICPPEvaluation[] evaluateArguments(ICPPEvaluation[] arguments, ActivationRecord record, ConstexprEvaluationContext context) {
|
||||||
ICPPEvaluation[] argList = new ICPPEvaluation[arguments.length + 1];
|
ICPPEvaluation[] argList = new ICPPEvaluation[arguments.length + 1];
|
||||||
EvalBinding constructorBinding = new EvalBinding(constructor, constructor.getType(), getTemplateDefinition());
|
EvalBinding constructorBinding = new EvalBinding(fConstructor, fConstructor.getType(), getTemplateDefinition());
|
||||||
argList[0] = constructorBinding;
|
argList[0] = constructorBinding;
|
||||||
for (int i = 0; i < arguments.length; i++) {
|
for (int i = 0; i < arguments.length; i++) {
|
||||||
ICPPEvaluation evaluatedClause = arguments[i].computeForFunctionCall(record, context.recordStep());
|
ICPPEvaluation evaluatedClause = arguments[i].computeForFunctionCall(record, context.recordStep());
|
||||||
|
@ -265,8 +263,8 @@ public class EvalConstructor extends CPPDependentEvaluation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int determinePackSize(ICPPTemplateParameterMap tpMap) {
|
public int determinePackSize(ICPPTemplateParameterMap tpMap) {
|
||||||
int r = CPPTemplates.determinePackSize(type, tpMap);
|
int r = CPPTemplates.determinePackSize(fType, tpMap);
|
||||||
for (ICPPEvaluation arg : arguments) {
|
for (ICPPEvaluation arg : fArguments) {
|
||||||
r = CPPTemplates.combinePackSize(r, arg.determinePackSize(tpMap));
|
r = CPPTemplates.combinePackSize(r, arg.determinePackSize(tpMap));
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
|
@ -274,7 +272,7 @@ public class EvalConstructor extends CPPDependentEvaluation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean referencesTemplateParameter() {
|
public boolean referencesTemplateParameter() {
|
||||||
for (ICPPEvaluation arg : arguments) {
|
for (ICPPEvaluation arg : fArguments) {
|
||||||
if (arg.referencesTemplateParameter())
|
if (arg.referencesTemplateParameter())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -284,10 +282,10 @@ public class EvalConstructor extends CPPDependentEvaluation {
|
||||||
@Override
|
@Override
|
||||||
public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException {
|
public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException {
|
||||||
buffer.putShort(ITypeMarshalBuffer.EVAL_CONSTRUCTOR);
|
buffer.putShort(ITypeMarshalBuffer.EVAL_CONSTRUCTOR);
|
||||||
buffer.marshalType(type);
|
buffer.marshalType(fType);
|
||||||
buffer.marshalBinding(constructor);
|
buffer.marshalBinding(fConstructor);
|
||||||
buffer.putInt(arguments.length);
|
buffer.putInt(fArguments.length);
|
||||||
for (ICPPEvaluation arg : arguments) {
|
for (ICPPEvaluation arg : fArguments) {
|
||||||
buffer.marshalEvaluation(arg, includeValue);
|
buffer.marshalEvaluation(arg, includeValue);
|
||||||
}
|
}
|
||||||
marshalTemplateDefinition(buffer);
|
marshalTemplateDefinition(buffer);
|
||||||
|
@ -307,16 +305,16 @@ public class EvalConstructor extends CPPDependentEvaluation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ICPPEvaluation instantiate(InstantiationContext context, int maxDepth) {
|
public ICPPEvaluation instantiate(InstantiationContext context, int maxDepth) {
|
||||||
IType newType = CPPTemplates.instantiateType(type, context);
|
IType newType = CPPTemplates.instantiateType(fType, context);
|
||||||
|
|
||||||
ICPPEvaluation[] newArguments = new ICPPEvaluation[arguments.length];
|
ICPPEvaluation[] newArguments = new ICPPEvaluation[fArguments.length];
|
||||||
for (int i = 0; i < arguments.length; i++) {
|
for (int i = 0; i < fArguments.length; i++) {
|
||||||
newArguments[i] = arguments[i].instantiate(context, maxDepth);
|
newArguments[i] = fArguments[i].instantiate(context, maxDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
ICPPConstructor newConstructor;
|
ICPPConstructor newConstructor;
|
||||||
try {
|
try {
|
||||||
newConstructor = (ICPPConstructor)CPPTemplates.instantiateBinding(constructor, context, maxDepth);
|
newConstructor = (ICPPConstructor)CPPTemplates.instantiateBinding(fConstructor, context, maxDepth);
|
||||||
if (newConstructor instanceof CPPDeferredFunction) {
|
if (newConstructor instanceof CPPDeferredFunction) {
|
||||||
ICPPFunction[] candidates = ((CPPDeferredFunction) newConstructor).getCandidates();
|
ICPPFunction[] candidates = ((CPPDeferredFunction) newConstructor).getCandidates();
|
||||||
if (candidates != null) {
|
if (candidates != null) {
|
||||||
|
@ -331,7 +329,7 @@ public class EvalConstructor extends CPPDependentEvaluation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
newConstructor = constructor;
|
newConstructor = fConstructor;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new EvalConstructor(newType, newConstructor, newArguments, getTemplateDefinition());
|
return new EvalConstructor(newType, newConstructor, newArguments, getTemplateDefinition());
|
||||||
|
|
Loading…
Add table
Reference in a new issue