Search in sources :

Example 11 with EvaluationContext

use of org.osate.aadl2.properties.EvaluationContext in project osate2 by osate.

the class PropertyImpl method getPropertyValueFromDeclarativeModel.

protected void getPropertyValueFromDeclarativeModel(EvaluationContext ctx, PropertyAcc pas) throws InvalidModelException {
    InstanceObject io = ctx.getInstanceObject();
    List<? extends NamedElement> compDecls = io.getInstantiatedObjects();
    if (compDecls == null) {
    }
    // Here we assume compDecls is empty or has only one element
    if (!compDecls.isEmpty()) {
        NamedElement compDecl = compDecls.get(0);
        if (compDecl == null) {
            return;
        }
        InstantiatedClassifier ic = ctx.getClassifierCache().get(io);
        Classifier cl = (ic == null) ? null : ic.getClassifier();
        if (compDecl instanceof Subcomponent) {
            ((SubcomponentImpl) compDecl).getPropertyValue(this, pas, cl, false);
        } else if (compDecl instanceof FeatureGroup) {
            ((FeatureGroupImpl) compDecl).getPropertyValue(this, pas, cl, false);
        } else if (compDecl instanceof Feature) {
            ((FeatureImpl) compDecl).getPropertyValue(this, pas, cl, false);
        } else if (compDecl instanceof PortConnection) {
            ((PortConnectionImpl) compDecl).getPropertyValue(this, pas);
        } else {
            compDecl.getPropertyValueInternal(this, pas, true);
        }
    }
}
Also used : InstanceObject(org.osate.aadl2.instance.InstanceObject) FeatureGroup(org.osate.aadl2.FeatureGroup) InstantiatedClassifier(org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier) Subcomponent(org.osate.aadl2.Subcomponent) InstantiatedClassifier(org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier) Classifier(org.osate.aadl2.Classifier) NamedElement(org.osate.aadl2.NamedElement) Feature(org.osate.aadl2.Feature) PortConnection(org.osate.aadl2.PortConnection)

Example 12 with EvaluationContext

use of org.osate.aadl2.properties.EvaluationContext in project osate2 by osate.

the class RecordValueImpl method evaluate.

/*
	 * (non-Javadoc)
	 *
	 * @see org.osate.aadl2.impl.PropertyExpressionImpl#evaluate(org.osate.aadl2.properties.EvaluationContext, int)
	 */
public EvaluatedProperty evaluate(EvaluationContext ctx, int depth) {
    // evaluate each record field
    RecordValue newVal = Aadl2Factory.eINSTANCE.createRecordValue();
    for (BasicPropertyAssociation field : getOwnedFieldValues()) {
        EvaluatedProperty fieldVal = field.getOwnedValue().evaluate(ctx, depth + 1);
        String name = field.getProperty().getName();
        if (fieldVal.isEmpty()) {
            throw new InvalidModelException(this, "Field " + name + " has no value");
        }
        if (fieldVal.size() > 1) {
            throw new InvalidModelException(this, "Field " + name + " has multiple values");
        }
        if (fieldVal.first().isModal()) {
            throw new InvalidModelException(this, "Field " + name + ": value is modal");
        }
        BasicPropertyAssociation newField = newVal.createOwnedFieldValue();
        newField.setProperty(field.getProperty());
        PropertyExpression exp = fieldVal.first().getValue();
        newField.setOwnedValue(exp);
    }
    return new EvaluatedProperty(newVal);
}
Also used : InvalidModelException(org.osate.aadl2.properties.InvalidModelException) RecordValue(org.osate.aadl2.RecordValue) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) PropertyExpression(org.osate.aadl2.PropertyExpression) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation)

Example 13 with EvaluationContext

use of org.osate.aadl2.properties.EvaluationContext in project osate2 by osate.

the class CachePropertyAssociationsSwitch method cacheConnectionPropertyAssociations.

protected void cacheConnectionPropertyAssociations(final ConnectionInstance conni) {
    PropertyAssociation setPA;
    PropertyExpression defaultvalue;
    try {
        /*
			 * propertyFilter contains all properties used by the system, so, we try to
			 * use the one associated to the connection instance and their reference and
			 * see if the user declares a specific value.
			 */
        for (Property prop : propertyFilter) {
            setPA = null;
            defaultvalue = prop.getDefaultValue();
            for (final ConnectionReference connRef : conni.getConnectionReferences()) {
                /*
					 * In the following piece of code, we check that a property
					 * is consistent all along the connection reference.
					 * For example, we check that the timing property (immediate, delayed)
					 * is consistent for each connection.
					 */
                if (connRef.acceptsProperty(prop)) {
                    /*
						 * Just look up the property. The property doesn't yet have
						 * a local association, so lookup will get the value from
						 * the declarative model. Property lookup process now
						 * corrects reference values to instance reference values.
						 */
                    final PropertyAssociation propAssociation = scProps.retrieveSCProperty(conni, prop, connRef.getConnection());
                    final EvaluationContext ctx = new EvaluationContext(connRef, classifierCache, propAssociation);
                    PropertyEvaluationResult result = prop.evaluate(ctx, 0);
                    List<EvaluatedProperty> evaluated = result.getEvaluated();
                    if (!evaluated.isEmpty()) {
                        PropertyAssociationInstance newPA = InstanceFactory.eINSTANCE.createPropertyAssociationInstance();
                        newPA.setProperty(prop);
                        newPA.setPropertyAssociation(getDeclarativePA(result.getPa()));
                        fillPropertyValue(connRef, newPA, evaluated);
                        if (!newPA.getOwnedValues().isEmpty()) {
                            /*
								 * FIXME JD
								 *
								 * Try to look if the property references a component or not.
								 * This was done to fix the issue related to the Bound Bus analysis plugin
								 */
                            for (Iterator<Element> content = EcoreUtil.getAllProperContents(newPA, false); content.hasNext(); ) {
                                Element elem = content.next();
                                if (elem instanceof ModalPropertyValue) {
                                    ModalPropertyValue mpv = (ModalPropertyValue) elem;
                                    if (mpv.getOwnedValue() instanceof ListValue) {
                                        ListValue lv = (ListValue) mpv.getOwnedValue();
                                        for (Element e : lv.getOwnedListElements()) {
                                            if (e instanceof ReferenceValue) {
                                                PropertyExpression irv = ((ReferenceValue) e).instantiate(conni.getContainingComponentInstance());
                                                if (irv != null) {
                                                    EcoreUtil.replace(e, irv);
                                                }
                                            }
                                        }
                                    }
                                }
                                if (elem instanceof ReferenceValue) {
                                    PropertyExpression irv = ((ReferenceValue) elem).instantiate(conni.getContainingComponentInstance());
                                    if (irv != null) {
                                        EcoreUtil.replace(elem, irv);
                                    }
                                }
                            }
                            scProps.recordSCProperty(conni, prop, connRef.getConnection(), newPA);
                            if (setPA == null) {
                                setPA = newPA;
                                conni.getOwnedPropertyAssociations().add(newPA);
                            } else {
                                // check consistency
                                for (Mode m : conni.getSystemInstance().getSystemOperationModes()) {
                                    PropertyExpression newVal = newPA.valueInMode(m);
                                    PropertyExpression setVal = setPA.valueInMode(m);
                                    if (!newVal.sameAs(setVal)) {
                                        error(conni, "Value for property " + setPA.getProperty().getQualifiedName() + " not consistent along connection");
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            checkIfCancelled();
            if (cancelled()) {
                break;
            }
        }
    } catch (IllegalStateException e) {
        // circular dependency
        // xxx: this is a misleading place to put the marker
        error(conni, e.getMessage());
        System.out.println("IllegalStateException raised in cacheConnectionPropertyAssociations");
    } catch (InvalidModelException e) {
        error(conni, e.getMessage());
        System.out.println("InvalidModelException raised in cacheConnectionPropertyAssociations");
    }
}
Also used : PropertyEvaluationResult(org.osate.aadl2.properties.PropertyEvaluationResult) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) ReferenceValue(org.osate.aadl2.ReferenceValue) Element(org.osate.aadl2.Element) ListValue(org.osate.aadl2.ListValue) Mode(org.osate.aadl2.Mode) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) InvalidModelException(org.osate.aadl2.properties.InvalidModelException) PropertyAssociationInstance(org.osate.aadl2.instance.PropertyAssociationInstance) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) PropertyExpression(org.osate.aadl2.PropertyExpression) EvaluationContext(org.osate.aadl2.properties.EvaluationContext) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) Property(org.osate.aadl2.Property)

Example 14 with EvaluationContext

use of org.osate.aadl2.properties.EvaluationContext in project osate2 by osate.

the class OperationImpl method evaluate.

public EvaluatedProperty evaluate(EvaluationContext ctx, int depth) throws InvalidModelException {
    if (ownedPropertyExpressions.size() < 1) {
        throw new InvalidModelException(ctx.getInstanceObject(), "Property expression has no operands");
    }
    EvaluatedProperty left = ownedPropertyExpressions.get(0).evaluate(ctx, depth);
    EvaluatedProperty right = null;
    PropertyExpression arg1 = null;
    PropertyExpression arg2 = null;
    if (left.size() == 0) {
        throw new InvalidModelException(ctx.getInstanceObject(), "Argument has no value");
    }
    if (left.size() != 1 || left.first().isModal()) {
        throw new InvalidModelException(ctx.getInstanceObject(), "Argument to operation cannot be modal");
    }
    arg1 = left.first().getValue();
    if (arg1 == null) {
        throw new InvalidModelException(ctx.getInstanceObject(), "Argument missing");
    }
    // check for required arguments to operation
    switch(op) {
        case AND:
        case OR:
            if (ownedPropertyExpressions.size() < 2) {
                throw new InvalidModelException(ctx.getInstanceObject(), "Second operand missing for binary operation");
            }
            if (ownedPropertyExpressions.size() > 2) {
                throw new InvalidModelException(ctx.getInstanceObject(), "Too many operands in expression");
            }
            right = ownedPropertyExpressions.get(1).evaluate(ctx, depth);
            if (right.size() != 1 || right.first().isModal()) {
                throw new InvalidModelException(ctx.getInstanceObject(), "Argument to operation cannot be modal");
            }
            if (right.size() == 0) {
                throw new InvalidModelException(ctx.getInstanceObject(), "Argument has no value");
            }
            arg2 = right.first().getValue();
            if (arg2 == null) {
                throw new InvalidModelException(ctx.getInstanceObject(), "Argument missing");
            }
            break;
        default:
            if (ownedPropertyExpressions.size() > 1) {
                throw new InvalidModelException(ctx.getInstanceObject(), "Too many operands in expression");
            }
            break;
    }
    // check argument types
    switch(op) {
        case NOT:
            if (!(arg1 instanceof BooleanLiteral)) {
                throw new InvalidModelException(ctx.getInstanceObject(), "Argument to NOT does not evaluate to a boolean value");
            }
        // fall through!
        case AND:
        case OR:
            if (!(arg2 instanceof BooleanLiteral)) {
                throw new InvalidModelException(ctx.getInstanceObject(), "Second argument does not evaluate to a boolean value");
            }
            break;
        default:
            if (!(arg1 instanceof NumberValue)) {
                throw new InvalidModelException(ctx.getInstanceObject(), "Argument does not evaluate to a numeric value");
            }
            break;
    }
    // calculate result
    EvaluatedProperty result = null;
    switch(op) {
        case AND:
            BooleanLiteral abv = Aadl2Factory.eINSTANCE.createBooleanLiteral();
            abv.setValue(((BooleanLiteral) arg1).getValue() && ((BooleanLiteral) arg1).getValue());
            result = new EvaluatedProperty(abv);
            break;
        case OR:
            BooleanLiteral obv = Aadl2Factory.eINSTANCE.createBooleanLiteral();
            obv.setValue(((BooleanLiteral) arg1).getValue() || ((BooleanLiteral) arg1).getValue());
            result = new EvaluatedProperty(obv);
            break;
        case NOT:
            BooleanLiteral nbv = Aadl2Factory.eINSTANCE.createBooleanLiteral();
            nbv.setValue(!((BooleanLiteral) arg1).getValue());
            result = new EvaluatedProperty(nbv);
            break;
        case PLUS:
            result = left;
            break;
        case MINUS:
            result = new EvaluatedProperty(((NumberValue) arg1).cloneAndInvert());
            break;
        default:
            throw new AssertionError("Unexpected enum literal: " + getOp());
    }
    return result;
}
Also used : InvalidModelException(org.osate.aadl2.properties.InvalidModelException) NumberValue(org.osate.aadl2.NumberValue) BooleanLiteral(org.osate.aadl2.BooleanLiteral) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) PropertyExpression(org.osate.aadl2.PropertyExpression)

Example 15 with EvaluationContext

use of org.osate.aadl2.properties.EvaluationContext in project osate2 by osate.

the class ListValueImpl method evaluate.

/*
	 * (non-Javadoc)
	 *
	 * @see org.osate.aadl2.impl.PropertyExpressionImpl#evaluate(org.osate.aadl2.properties.EvaluationContext, int)
	 */
public EvaluatedProperty evaluate(EvaluationContext ctx, int depth) {
    // evaluate each list element
    ListValue newVal = Aadl2Factory.eINSTANCE.createListValue();
    int i = 0;
    for (PropertyExpression elem : getOwnedListElements()) {
        i += 1;
        EvaluatedProperty elemVal = elem.evaluate(ctx, depth + 1);
        if (elemVal.isEmpty()) {
            throw new InvalidModelException(this, "Element " + i + " has no value");
        }
        if (elemVal.size() > 1) {
            throw new InvalidModelException(this, "Element " + i + " has multiple values");
        }
        if (elemVal.first().isModal()) {
            throw new InvalidModelException(this, "Element " + i + ": value is modal");
        }
        PropertyExpression exp = elemVal.first().getValue();
        newVal.getOwnedListElements().add(exp);
    }
    return new EvaluatedProperty(newVal);
}
Also used : InvalidModelException(org.osate.aadl2.properties.InvalidModelException) ListValue(org.osate.aadl2.ListValue) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) PropertyExpression(org.osate.aadl2.PropertyExpression)

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