Search in sources :

Example 6 with EvaluationContext

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);
}
Also used : InvalidModelException(org.osate.aadl2.properties.InvalidModelException) PropertyEvaluationResult(org.osate.aadl2.properties.PropertyEvaluationResult) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) PropertyExpression(org.osate.aadl2.PropertyExpression) Property(org.osate.aadl2.Property) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty)

Example 7 with EvaluationContext

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);
    }
}
Also used : ResoluteEvaluator(com.rockwellcollins.atc.resolute.analysis.execution.ResoluteEvaluator) ResoluteResult(com.rockwellcollins.atc.resolute.analysis.results.ResoluteResult) NamedElementValue(com.rockwellcollins.atc.resolute.analysis.values.NamedElementValue) FunctionDefinition(com.rockwellcollins.atc.resolute.resolute.FunctionDefinition) ResoluteFailException(com.rockwellcollins.atc.resolute.analysis.execution.ResoluteFailException) EvaluationContext(com.rockwellcollins.atc.resolute.analysis.execution.EvaluationContext) FnCallExpr(com.rockwellcollins.atc.resolute.resolute.FnCallExpr) NamedElement(org.osate.aadl2.NamedElement) ResoluteProver(com.rockwellcollins.atc.resolute.analysis.execution.ResoluteProver) ThisExpr(com.rockwellcollins.atc.resolute.resolute.ThisExpr)

Example 8 with EvaluationContext

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");
    }
}
Also used : InvalidModelException(org.osate.aadl2.properties.InvalidModelException) NumberValue(org.osate.aadl2.NumberValue) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) RangeValue(org.osate.aadl2.RangeValue)

Example 9 with EvaluationContext

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;
}
Also used : PropertyAcc(org.osate.aadl2.properties.PropertyAcc)

Example 10 with EvaluationContext

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);
        }
    }
}
Also used : InstanceObject(org.osate.aadl2.instance.InstanceObject) EvaluationContext(org.osate.aadl2.properties.EvaluationContext)

Aggregations

EvaluatedProperty (org.osate.aadl2.properties.EvaluatedProperty)8 InvalidModelException (org.osate.aadl2.properties.InvalidModelException)7 PropertyExpression (org.osate.aadl2.PropertyExpression)5 InstanceObject (org.osate.aadl2.instance.InstanceObject)4 NamedElement (org.osate.aadl2.NamedElement)3 Property (org.osate.aadl2.Property)3 EvaluationContext (org.osate.aadl2.properties.EvaluationContext)3 PropertyEvaluationResult (org.osate.aadl2.properties.PropertyEvaluationResult)3 EvaluationContext (com.rockwellcollins.atc.resolute.analysis.execution.EvaluationContext)2 ResoluteEvaluator (com.rockwellcollins.atc.resolute.analysis.execution.ResoluteEvaluator)2 ResoluteProver (com.rockwellcollins.atc.resolute.analysis.execution.ResoluteProver)2 ResoluteResult (com.rockwellcollins.atc.resolute.analysis.results.ResoluteResult)2 NamedElementValue (com.rockwellcollins.atc.resolute.analysis.values.NamedElementValue)2 FnCallExpr (com.rockwellcollins.atc.resolute.resolute.FnCallExpr)2 FunctionDefinition (com.rockwellcollins.atc.resolute.resolute.FunctionDefinition)2 ThisExpr (com.rockwellcollins.atc.resolute.resolute.ThisExpr)2 AadlPackage (org.osate.aadl2.AadlPackage)2 Classifier (org.osate.aadl2.Classifier)2 ListValue (org.osate.aadl2.ListValue)2 NumberValue (org.osate.aadl2.NumberValue)2