diff options
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecDeclarator.java')
-rw-r--r-- | core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecDeclarator.java | 102 |
1 files changed, 51 insertions, 51 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecDeclarator.java index 15dbb0669b6..269d22dde0c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecDeclarator.java @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2016 Institute for Software, HSR Hochschule fuer Technik +* Copyright (c) 2016 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -43,102 +43,102 @@ public class ExecDeclarator implements ICPPExecution { @Override public ICPPExecution executeForFunctionCall(ActivationRecord record, ConstexprEvaluationContext context) { - if(!(declaredBinding instanceof ICPPVariable)) { + if (!(declaredBinding instanceof ICPPVariable)) { return this; } - - ICPPVariable declaredVariable = (ICPPVariable)declaredBinding; + + ICPPVariable declaredVariable = (ICPPVariable) declaredBinding; IType type = declaredVariable.getType(); ICPPEvaluation initialValue = createInitialValue(type, record, context); - if(initialValue == null || initialValue == EvalFixed.INCOMPLETE) { + if (initialValue == null || initialValue == EvalFixed.INCOMPLETE) { return ExecIncomplete.INSTANCE; } - + record.update(declaredBinding, initialValue); return this; } - + public ICPPBinding getDeclaredBinding() { return declaredBinding; } - + private ICPPEvaluation createInitialValue(IType type, ActivationRecord record, ConstexprEvaluationContext context) { - if(initializerEval == null) { + if (initializerEval == null) { return createDefaultInitializedCompositeValue(type); } - + ICPPEvaluation computedInitializerEval = initializerEval.computeForFunctionCall(record, context.recordStep()); //if a compositevalue with only one member is initialized with an initializer list - //it evaluates to a EvalFixed with a Value instead of a CompositeValue because the initializer list - //doesn't know that it is initializing a composite. + //it evaluates to a EvalFixed with a Value instead of a CompositeValue because the initializer list + //doesn't know that it is initializing a composite. IType nestedType = SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE); - if(isClassType(nestedType) && computedInitializerEval instanceof EvalFixed) { + if (isClassType(nestedType) && computedInitializerEval instanceof EvalFixed) { EvalFixed evalFixed = (EvalFixed) computedInitializerEval; IValue val = evalFixed.getValue(); - if(!(val instanceof CompositeValue)) { + if (!(val instanceof CompositeValue)) { CompositeValue compVal = new CompositeValue(initializerEval, new ICPPEvaluation[]{evalFixed}); computedInitializerEval = new EvalFixed(type, computedInitializerEval.getValueCategory(context.getPoint()), compVal); } } - + if (isReferenceType(type)) { return createReferenceValue(record, context, computedInitializerEval); } else if (isPointerType(nestedType) && !isCStringType(nestedType)) { return createPointerValue(record, context, computedInitializerEval); - } else if(isArrayType(nestedType) && !isCStringType(nestedType)) { - IValue value = CompositeValue.create((EvalInitList)computedInitializerEval,(IArrayType) (type)); + } else if (isArrayType(nestedType) && !isCStringType(nestedType)) { + IValue value = CompositeValue.create((EvalInitList) computedInitializerEval,(IArrayType) (type)); return new EvalFixed(type, computedInitializerEval.getValueCategory(context.getPoint()), value); - } else if (isValueInitialization(computedInitializerEval)){ + } else if (isValueInitialization(computedInitializerEval)) { ICPPEvaluation defaultValue = new EvalTypeId(type, context.getPoint(), false, new ICPPEvaluation[]{}); return new EvalFixed(type, defaultValue.getValueCategory(context.getPoint()), defaultValue.getValue(context.getPoint())); } else { return new EvalFixed(type, computedInitializerEval.getValueCategory(context.getPoint()), computedInitializerEval.getValue(context.getPoint())); } } - + private static ICPPEvaluation createDefaultInitializedCompositeValue(IType type) { - if(!isClassType(type)) { + if (!isClassType(type)) { return EvalFixed.INCOMPLETE; } - ICPPClassType classType = (ICPPClassType)type; + ICPPClassType classType = (ICPPClassType) type; // TODO(nathanridge): CompositeValue.create() only consider default member initializers, not // constructors. Should we be considering constructors here as well? IValue compositeValue = CompositeValue.create(classType); EvalFixed initialValue = new EvalFixed(type, ValueCategory.PRVALUE, compositeValue); return initialValue; } - + private ICPPEvaluation createReferenceValue(ActivationRecord record, ConstexprEvaluationContext context, ICPPEvaluation computedInitializerEval) { ICPPEvaluation initValue = initializerEval; - if(!(initValue instanceof EvalBinding)) { + if (!(initValue instanceof EvalBinding)) { initValue = initializerEval.getValue(context.getPoint()).getSubValue(0); } - - if(initValue instanceof EvalBinding) { + + if (initValue instanceof EvalBinding) { return createReferenceFromBinding(record, context, (EvalBinding) initValue); - } else if(initValue instanceof EvalBinary && computedInitializerEval instanceof EvalCompositeAccess) { + } else if (initValue instanceof EvalBinary && computedInitializerEval instanceof EvalCompositeAccess) { return createReferenceFromCompositeAccess(record, context, (EvalCompositeAccess) computedInitializerEval); } else { return EvalFixed.INCOMPLETE; } } - + private ICPPEvaluation createPointerValue(ActivationRecord record, ConstexprEvaluationContext context, ICPPEvaluation computedInitializerEval) { ICPPEvaluation initValue = initializerEval.getValue(context.getPoint()).getSubValue(0); if (isPointerToArray(initValue, context)) { EvalCompositeAccess arrayPointer = new EvalCompositeAccess(computedInitializerEval, 0); return createPointerFromCompositeAccess(record, context, arrayPointer); } else if (computedInitializerEval instanceof EvalPointer) { - EvalPointer pointer = (EvalPointer)computedInitializerEval; + EvalPointer pointer = (EvalPointer) computedInitializerEval; return pointer.copy(); } return EvalFixed.INCOMPLETE; } private static boolean isValueInitialization(ICPPEvaluation eval) { - if(eval instanceof EvalInitList) { - EvalInitList evalInitList = (EvalInitList)eval; + if (eval instanceof EvalInitList) { + EvalInitList evalInitList = (EvalInitList) eval; return evalInitList.getClauses().length == 0; } return false; @@ -151,11 +151,11 @@ public class ExecDeclarator implements ICPPExecution { private static ICPPEvaluation createReferenceFromBinding(ActivationRecord record, ConstexprEvaluationContext context, EvalBinding evalBinding) { return new EvalReference(record, evalBinding.getBinding(), context.getPoint()); } - + private static ICPPEvaluation createReferenceFromCompositeAccess(ActivationRecord record, ConstexprEvaluationContext context, EvalCompositeAccess evalCompAccess) { return new EvalReference(record, evalCompAccess, context.getPoint()); } - + private static ICPPEvaluation createPointerFromCompositeAccess(ActivationRecord record, ConstexprEvaluationContext context, EvalCompositeAccess evalCompAccess) { return new EvalPointer(record, evalCompAccess, context.getPoint()); } @@ -163,57 +163,57 @@ public class ExecDeclarator implements ICPPExecution { private static boolean isReferenceType(IType type) { return type instanceof ICPPReferenceType; } - + private static boolean isPointerType(IType type) { return type instanceof IPointerType; } - + private static boolean isArrayType(IType type) { return type instanceof IArrayType; } - + private static boolean isCStringType(IType type) { IType nestedType = null; - if(type instanceof IArrayType) { - nestedType = ((IArrayType)type).getType(); - } else if(type instanceof IPointerType) { - nestedType = ((IPointerType)type).getType(); + if (type instanceof IArrayType) { + nestedType = ((IArrayType) type).getType(); + } else if (type instanceof IPointerType) { + nestedType = ((IPointerType) type).getType(); } - - if(nestedType != null) { + + if (nestedType != null) { return nestedType.isSameType(new CPPQualifierType(CPPBasicType.CHAR, true, false)); } return false; } - + private static boolean isClassType(IType type) { return type instanceof ICPPClassType; } - + @Override public ICPPExecution instantiate(InstantiationContext context, int maxDepth) { ICPPBinding newDeclaredBinding; - if(declaredBinding instanceof ICPPVariable) { - ICPPVariable declaredVariable = (ICPPVariable)declaredBinding; - newDeclaredBinding = CPPTemplates.createVariableSpecialization(context, declaredVariable); + if (declaredBinding instanceof ICPPVariable) { + ICPPVariable declaredVariable = (ICPPVariable) declaredBinding; + newDeclaredBinding = CPPTemplates.createVariableSpecialization(context, declaredVariable); } else { newDeclaredBinding = (ICPPBinding)CPPTemplates.createSpecialization(context.getContextSpecialization(), declaredBinding, context.getPoint()); } - + ICPPEvaluation newInitializerEval = initializerEval != null ? initializerEval.instantiate(context, maxDepth) : null; return new ExecDeclarator(newDeclaredBinding, newInitializerEval); } - + @Override public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { buffer.putShort(ITypeMarshalBuffer.EXEC_DECLARATOR); buffer.marshalBinding(declaredBinding); buffer.marshalEvaluation(initializerEval, includeValue); } - + public static ISerializableExecution unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - ICPPBinding declaredBinding = (ICPPBinding)buffer.unmarshalBinding(); - ICPPEvaluation initializerEval = (ICPPEvaluation)buffer.unmarshalEvaluation(); + ICPPBinding declaredBinding = (ICPPBinding) buffer.unmarshalBinding(); + ICPPEvaluation initializerEval = (ICPPEvaluation) buffer.unmarshalEvaluation(); return new ExecDeclarator(declaredBinding, initializerEval); } } |