1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Cosmetics

Change-Id: Ib5d970ad0b34db58cbf7d87bdb67b457539985e4
This commit is contained in:
Sergey Prigogin 2017-01-28 08:54:22 -08:00
parent 7b05dbf791
commit e891f9e555

View file

@ -57,14 +57,16 @@ public final class EvalConstructor extends CPPDependentEvaluation {
private boolean fIsConstantExpression; private boolean fIsConstantExpression;
private static final IASTName TEMP_NAME = 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);
fType = type; fType = type;
fConstructor = constructor; fConstructor = constructor;
fArguments = arguments != null ? arguments : ICPPEvaluation.EMPTY_ARRAY; 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) {
this(type, constructor, arguments, findEnclosingTemplate(pointOfDefinition)); this(type, constructor, arguments, findEnclosingTemplate(pointOfDefinition));
} }
@ -132,7 +134,8 @@ public final class EvalConstructor extends CPPDependentEvaluation {
} }
@Override @Override
public ICPPEvaluation computeForFunctionCall(ActivationRecord callSiteRecord, ConstexprEvaluationContext context) { public ICPPEvaluation computeForFunctionCall(ActivationRecord callSiteRecord,
ConstexprEvaluationContext context) {
final IType unwrappedType = SemanticUtil.getNestedType(fType, TDEF | REF | CVTYPE); final IType unwrappedType = SemanticUtil.getNestedType(fType, TDEF | REF | CVTYPE);
if (!(unwrappedType instanceof ICPPClassType)) { if (!(unwrappedType instanceof ICPPClassType)) {
return this; return this;
@ -143,11 +146,12 @@ public final class EvalConstructor extends CPPDependentEvaluation {
EvalFixed constructedObject = new EvalFixed(fType, ValueCategory.PRVALUE, compositeValue); EvalFixed constructedObject = new EvalFixed(fType, ValueCategory.PRVALUE, compositeValue);
CPPVariable binding = new CPPVariable(TEMP_NAME); CPPVariable binding = new CPPVariable(TEMP_NAME);
IASTNode point = context.getPoint();
ActivationRecord localRecord = EvalFunctionCall.createActivationRecord( ActivationRecord localRecord = EvalFunctionCall.createActivationRecord(
fConstructor.getParameters(), argList, constructedObject, context.getPoint()); fConstructor.getParameters(), argList, constructedObject, point);
localRecord.update(binding, constructedObject); localRecord.update(binding, constructedObject);
ICPPExecution exec = fConstructor.getConstructorChainExecution(context.getPoint()); ICPPExecution exec = fConstructor.getConstructorChainExecution(point);
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();
@ -155,28 +159,30 @@ public final class EvalConstructor extends CPPDependentEvaluation {
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 =
ICPPEvaluation[] baseClassValues = memberValue.getValue(context.getPoint()).getAllSubValues(); memberEval.computeForFunctionCall(localRecord, context.recordStep());
ICPPEvaluation[] baseClassValues = memberValue.getValue(point).getAllSubValues();
ICPPField[] baseFields = ClassTypeHelper.getFields(baseClassType, context.getPoint()); ICPPField[] baseFields = ClassTypeHelper.getFields(baseClassType, point);
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, baseClassValues[fieldPos]); constructedObject.getValue(point).setSubValue(fieldPos, baseClassValues[fieldPos]);
} }
} }
} }
} }
ICPPField[] fields = ClassTypeHelper.getDeclaredFields(classType, context.getPoint()); ICPPField[] fields = ClassTypeHelper.getDeclaredFields(classType, point);
for (ICPPField field : fields) { for (ICPPField field : fields) {
final Map.Entry<IBinding, ICPPEvaluation> ccInitializer = getInitializerFromMemberInitializerList(field, exec); final Map.Entry<IBinding, ICPPEvaluation> initializer =
getInitializerFromMemberInitializerList(field, exec);
ICPPEvaluation value = null; ICPPEvaluation value = null;
if (ccInitializer != null) { if (initializer != null) {
ExecDeclarator declaratorExec = getDeclaratorExecutionFromMemberInitializerList(ccInitializer); ExecDeclarator declaratorExec = getDeclaratorExecutionFromMemberInitializerList(initializer);
value = getFieldValue(declaratorExec, classType, localRecord, context); value = getFieldValue(declaratorExec, classType, localRecord, context);
} else { } else {
value = EvalUtil.getVariableValue(field, localRecord); value = EvalUtil.getVariableValue(field, localRecord);
@ -189,33 +195,36 @@ public final class EvalConstructor extends CPPDependentEvaluation {
// - evaluate the arguments again // - evaluate the arguments again
// - create another ActivationRecord (inside evaluateFunctionBody()) // - create another ActivationRecord (inside evaluateFunctionBody())
// Are these necessary? // Are these necessary?
new EvalFunctionCall(argList, constructedObject, context.getPoint()).computeForFunctionCall( new EvalFunctionCall(argList, constructedObject, point).computeForFunctionCall(
localRecord, context.recordStep()); localRecord, context.recordStep());
return localRecord.getVariable(binding); return localRecord.getVariable(binding);
} }
private Map.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 initList = (ExecConstructorChain) exec;
for (Map.Entry<IBinding, ICPPEvaluation> ccInitializer : memberInitList.getConstructorChainInitializers().entrySet()) { for (Map.Entry<IBinding, ICPPEvaluation> init : initList.getConstructorChainInitializers().entrySet()) {
final IBinding member = ccInitializer.getKey(); final IBinding member = init.getKey();
if (member instanceof ICPPField && member.getName().equals(field.getName())) { if (member instanceof ICPPField && member.getName().equals(field.getName())) {
return ccInitializer; return init;
} }
} }
return null; return null;
} }
private ExecDeclarator getDeclaratorExecutionFromMemberInitializerList(Map.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);
} }
private ICPPEvaluation getFieldValue(ExecDeclarator declaratorExec, ICPPClassType classType, ActivationRecord record, ConstexprEvaluationContext context) { private ICPPEvaluation getFieldValue(ExecDeclarator declaratorExec, ICPPClassType classType,
ActivationRecord record, ConstexprEvaluationContext context) {
if (declaratorExec == null) { if (declaratorExec == null) {
return null; return null;
} }
@ -269,9 +278,11 @@ public final class EvalConstructor extends CPPDependentEvaluation {
return args; return args;
} }
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(fConstructor, fConstructor.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());
@ -338,9 +349,10 @@ public final class EvalConstructor extends CPPDependentEvaluation {
if (newConstructor instanceof CPPDeferredFunction) { if (newConstructor instanceof CPPDeferredFunction) {
ICPPFunction[] candidates = ((CPPDeferredFunction) newConstructor).getCandidates(); ICPPFunction[] candidates = ((CPPDeferredFunction) newConstructor).getCandidates();
if (candidates != null) { if (candidates != null) {
CPPFunctionSet functionSet = new CPPFunctionSet(candidates, new ICPPTemplateArgument[]{}, null); CPPFunctionSet functionSet =
EvalFunctionSet evalFunctionSet = new EvalFunctionSet(functionSet, false, false, newType, new CPPFunctionSet(candidates, new ICPPTemplateArgument[]{}, null);
context.getPoint()); EvalFunctionSet evalFunctionSet =
new EvalFunctionSet(functionSet, false, false, newType, context.getPoint());
ICPPEvaluation resolved = evalFunctionSet.resolveFunction(newArguments, context.getPoint()); ICPPEvaluation resolved = evalFunctionSet.resolveFunction(newArguments, context.getPoint());
if (resolved instanceof EvalBinding) { if (resolved instanceof EvalBinding) {
EvalBinding evalBinding = (EvalBinding) resolved; EvalBinding evalBinding = (EvalBinding) resolved;