use of org.osate.aadl2.properties.EvaluationContext in project osate2 by osate.
the class NamedValueImpl method evaluate.
/*
* (non-Javadoc)
*
* @see org.osate.aadl2.impl.PropertyExpressionImpl#evaluate(org.osate.aadl2.properties.EvaluationContext)
*/
public EvaluatedProperty evaluate(EvaluationContext ctx, int depth) {
AbstractNamedValue nv = getNamedValue();
if (depth > 50) {
throw new InvalidModelException(ctx.getInstanceObject(), "Property " + ((Property) nv).getQualifiedName() + " has cyclic value");
}
PropertyEvaluationResult pev = nv.evaluate(ctx, depth + 1);
List<EvaluatedProperty> evaluated = pev.getEvaluated();
if (evaluated.isEmpty()) {
/*
* Issue 2387: If this NamedValue is a reference to a property value, and the
* property value doesn't exist, we need to check for the property's default
* value. (This cannot be done in PropertyImpl.evaluate(), because it is used to
* broadly. See the comment in PropertyImpl.evaluate().)
*/
if (nv instanceof Property) {
final PropertyExpression defaultValueExpression = ((Property) nv).getDefaultValue();
if (defaultValueExpression != null) {
evaluated = Collections.singletonList(defaultValueExpression.evaluate(ctx, depth));
}
}
// Test it again...
if (evaluated.isEmpty()) {
throw new InvalidModelException(ctx.getInstanceObject(), "Property " + ((Property) nv).getQualifiedName() + " is undefined");
}
}
return evaluated.get(0);
}
use of org.osate.aadl2.properties.EvaluationContext in project osate2 by osate.
the class ResoluteInterface method executeResoluteFunctionOnce.
/**
* invokes Resolute claim function on targetComponent or targetElement if not null.
* instanceroot is used to initialize the Resolute evaluation context.
* targetComponent is the evaluation context
* targetElement is the model element within the component instance or null.
* parameterObjects is a list of additional parameters of types RealLiteral, IntegerLiteral, StringLiteral, BooleanLiteral
* parameterObjects can be null or an empty list.
* The return value is an Issue object with subissues for the list of issues returned in the Resolute ClaimResult.
* If the proof fails then the top Issue is set to FAIL, if successful it is set to SUCCESS
*/
public EObject executeResoluteFunctionOnce(EObject fundef, final ComponentInstance targetComponent, final InstanceObject targetElement, List<PropertyExpression> parameterObjects) {
FunctionDefinition fd = (FunctionDefinition) fundef;
initializeResoluteContext(targetComponent.getSystemInstance());
EvaluationContext context = new EvaluationContext(targetComponent, sets, featToConnsMap);
// check for claim function
FnCallExpr fcncall = createWrapperFunctionCall(fd, targetElement, parameterObjects);
if (fcncall != null) {
// if (fcncall.getFn().getBody() instanceof ClaimBody) {
// using com.rockwellcollins.atc.resolute.analysis.results.ClaimResult
ResoluteProver prover = new ResoluteProver(context) {
@Override
protected ResoluteEvaluator createResoluteEvaluator() {
return new ResoluteEvaluator(context, varStack.peek()) {
@Override
public ResoluteValue caseThisExpr(ThisExpr object) {
// We prepare a thisexpr with either the component instance as context object or a single reference to a model element
// See createWrapperFunctionCall
NamedElement curr = context.getThisInstance();
if (object.getSub() != null) {
curr = object.getSub().getBase();
}
return new NamedElementValue(curr);
}
};
}
};
try {
ResoluteResult res = prover.doSwitch(fcncall);
return doResoluteResults(res);
} catch (ResoluteFailException e) {
return ResultUtil.createFailureResult(e.getMessage(), targetElement);
}
// } else {
// // computational function
// ResoluteEvaluator engine = new ResoluteEvaluator(context, null) {
// @Override
// public ResoluteValue caseThisExpr(ThisExpr object) {
// // We prepare a thisexpr with either the component instance as context object or a single reference to a model element
// // See createWrapperFunctionCall
// NamedElement curr = context.getThisInstance();
// if (object.getSub() != null) {
// curr = object.getSub().getBase();
// }
// return new NamedElementValue(curr);
// }
// };
// Object res = engine.doSwitch(fcncall);
// return null;
// }
} else {
return ResultUtil.createErrorDiagnostic("Could not find Resolute Function " + fd.getName(), fd);
}
}
use of org.osate.aadl2.properties.EvaluationContext in project osate2 by osate.
the class RangeValueImpl method evaluate.
public final EvaluatedProperty evaluate(EvaluationContext ctx, int depth) throws InvalidModelException {
/*
* The min, max, and delta attributes can refer to PropertyReferences to
* signed property constants that we need to resolve. So we first
* evaluate the min, max, and delta values, and then create a new
* RangeValue out of the evaluated contents.
*/
try {
NumberValue maxNumberValue;
NumberValue minNumberValue;
EvaluatedProperty maxVal = maximum.evaluate(ctx, depth);
EvaluatedProperty minVal = minimum.evaluate(ctx, depth);
EvaluatedProperty deltaVal = null;
maxNumberValue = null;
minNumberValue = null;
/*
* First, retrieve the maximum value.
*/
if (maxVal.size() != 1 || maxVal.first().isModal()) {
throw new InvalidModelException(ctx.getInstanceObject(), "Range maximum is modal");
}
if (maxVal.first().getValue() instanceof NumberValue) {
maxNumberValue = (NumberValue) maxVal.first().getValue();
} else {
throw new InvalidModelException(ctx.getInstanceObject(), "Range maximum is not numeric");
}
/*
* So now, retrieve the minimum value.
*/
if (minVal.size() != 1 || minVal.first().isModal()) {
throw new InvalidModelException(ctx.getInstanceObject(), "Range minimum is modal");
}
if (minVal.first().getValue() instanceof NumberValue) {
minNumberValue = (NumberValue) minVal.first().getValue();
} else {
throw new InvalidModelException(ctx.getInstanceObject(), "Range minimum is not numeric");
}
if (delta != null) {
deltaVal = delta.evaluate(ctx, depth);
if (deltaVal.size() != 1 || deltaVal.first().isModal()) {
throw new InvalidModelException(ctx.getInstanceObject(), "Range delta is modal");
}
if (!(deltaVal.first().getValue() instanceof NumberValue)) {
throw new InvalidModelException(ctx.getInstanceObject(), "Range delta is not numeric");
}
}
RangeValue newVal = Aadl2Factory.eINSTANCE.createRangeValue();
newVal.setMaximum(maxNumberValue);
newVal.setMinimum(minNumberValue);
if (deltaVal != null) {
newVal.setDelta(deltaVal.first().getValue());
}
return new EvaluatedProperty(newVal);
} catch (NullPointerException e) {
throw new InvalidModelException(ctx.getInstanceObject(), "Incomplete range value");
} catch (ClassCastException e) {
throw new InvalidModelException(ctx.getInstanceObject(), "Incomplete range value");
}
}
use of org.osate.aadl2.properties.EvaluationContext in project osate2 by osate.
the class PropertyImpl method getPropertyValue.
private PropertyAcc getPropertyValue(EvaluationContext ctx) throws IllegalStateException, InvalidModelException, PropertyDoesNotApplyToHolderException, IllegalArgumentException {
// Error if the property is not acceptable
final PropertyAcc pas = new PropertyAcc(this);
getPropertyValueInternal(ctx, pas);
return pas;
}
use of org.osate.aadl2.properties.EvaluationContext in project osate2 by osate.
the class PropertyImpl method getPropertyValueInternal.
public final void getPropertyValueInternal(EvaluationContext ctx, final PropertyAcc paa) throws InvalidModelException {
InstanceObject io = ctx.getInstanceObject();
/*
* Only relevant for connection instances
*/
if (ctx.getSCProp() != null) {
if (paa.add(ctx.getSCProp())) {
return;
}
}
/*
* First see if the property is defined locally in the instance. Such
* local property associations arise from component property
* associations in the declarative spec, from explicit programmatic
* setting of the property, or as cached results from earlier property
* lookups.
*/
if (paa.addLocal(io)) {
return;
}
getPropertyValueFromDeclarativeModel(ctx, paa);
/*
* If the property is "inherit", get it from the enclosing component
* instance. Don't short-circuit this step because the property caching
* during instantiation doesn't catch contained property values that may
* be attached to an ancestor instance and that might be inherited by
* this instance.
*/
if (isInherit()) {
io = (InstanceObject) io.eContainer();
if (io != null) {
getPropertyValueInternal(new EvaluationContext(io, ctx.getClassifierCache()), paa);
}
}
}
Aggregations