Search in sources :

Example 36 with StringLiteral

use of org.osate.aadl2.StringLiteral in project osate2 by osate.

the class ResoluteInterface method addParams.

private void addParams(FnCallExpr call, List<PropertyExpression> params) {
    for (PropertyExpression p : params) {
        if (p instanceof RealLiteral) {
            RealExpr realval = ResoluteFactory.eINSTANCE.createRealExpr();
            realval.setVal((RealLiteral) p);
            call.getArgs().add(realval);
        } else if (p instanceof IntegerLiteral) {
            IntExpr intval = ResoluteFactory.eINSTANCE.createIntExpr();
            intval.setVal((IntegerLiteral) p);
            call.getArgs().add(intval);
        } else if (p instanceof StringLiteral) {
            StringExpr stringval = ResoluteFactory.eINSTANCE.createStringExpr();
            stringval.setVal((StringLiteral) p);
            call.getArgs().add(stringval);
        } else if (p instanceof BooleanLiteral) {
            BoolExpr boolval = ResoluteFactory.eINSTANCE.createBoolExpr();
            boolval.setVal((BooleanLiteral) p);
            call.getArgs().add(boolval);
        } else if (p instanceof InstanceReferenceValue) {
            Expr ref = createInstanceObjectReference(((InstanceReferenceValue) p).getReferencedInstanceObject());
            call.getArgs().add(ref);
        }
    }
}
Also used : RealLiteral(org.osate.aadl2.RealLiteral) StringExpr(com.rockwellcollins.atc.resolute.resolute.StringExpr) BoolExpr(com.rockwellcollins.atc.resolute.resolute.BoolExpr) StringLiteral(org.osate.aadl2.StringLiteral) BoolExpr(com.rockwellcollins.atc.resolute.resolute.BoolExpr) Expr(com.rockwellcollins.atc.resolute.resolute.Expr) IntExpr(com.rockwellcollins.atc.resolute.resolute.IntExpr) FnCallExpr(com.rockwellcollins.atc.resolute.resolute.FnCallExpr) RealExpr(com.rockwellcollins.atc.resolute.resolute.RealExpr) ThisExpr(com.rockwellcollins.atc.resolute.resolute.ThisExpr) StringExpr(com.rockwellcollins.atc.resolute.resolute.StringExpr) BooleanLiteral(org.osate.aadl2.BooleanLiteral) PropertyExpression(org.osate.aadl2.PropertyExpression) InstanceReferenceValue(org.osate.aadl2.instance.InstanceReferenceValue) IntExpr(com.rockwellcollins.atc.resolute.resolute.IntExpr) RealExpr(com.rockwellcollins.atc.resolute.resolute.RealExpr) IntegerLiteral(org.osate.aadl2.IntegerLiteral)

Example 37 with StringLiteral

use of org.osate.aadl2.StringLiteral 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 38 with StringLiteral

use of org.osate.aadl2.StringLiteral in project osate2 by osate.

the class PropertyUtils method getValue.

/**
 * Returns the first property expression or abstract named element (
 * EnumerationLiteral, Property, PropertyConstant, UnitLiteral) that matches
 * to the given String object within the given ProperyExpression object.
 * If the property expression doesn't exist, it returns {@code null}.
 *
 * @param pe the given ProperyExpression object
 * @param toBeMatched the given String object
 * @return the first matching property expression or abstract named element.
 * otherwise return {@code null}
 *
 * @throws UnsupportedOperationException for other property values than:
 *   _ StringLiteral
 *   _ ListValue (recursion supported)
 *   _ ClassifierValue
 *   _ InstanceReferenceValue
 *   _ ComputedValue
 *   _ RecordValue (based on field matching)
 *   _ NamedValue (returns abstract named element)
 */
public static Element getValue(PropertyExpression pe, String toBeMatched) {
    Element tmp = null;
    int id = pe.eClass().getClassifierID();
    switch(id) {
        case Aadl2Package.STRING_LITERAL:
            {
                StringLiteral sl = (StringLiteral) pe;
                if (sl.getValue().equalsIgnoreCase(toBeMatched)) {
                    return sl;
                }
                return null;
            }
        case Aadl2Package.LIST_VALUE:
            {
                ListValue lv = (ListValue) pe;
                EList<PropertyExpression> pel = lv.getOwnedListElements();
                for (PropertyExpression ownedPe : pel) {
                    tmp = getValue(ownedPe, toBeMatched);
                    if (tmp != null) {
                        return tmp;
                    }
                }
                return null;
            }
        case Aadl2Package.RECORD_VALUE:
            {
                RecordValue rv = (RecordValue) pe;
                for (BasicPropertyAssociation bpa : rv.getOwnedFieldValues()) {
                    if (bpa.getProperty().getName().equalsIgnoreCase(toBeMatched)) {
                        return bpa.getValue();
                    }
                }
                return null;
            }
        case Aadl2Package.CLASSIFIER_VALUE:
            {
                ClassifierValue cv = (ClassifierValue) pe;
                if (cv.getClassifier().getName().equalsIgnoreCase(toBeMatched)) {
                    return cv;
                } else {
                    return null;
                }
            }
        case Aadl2Package.REFERENCE_VALUE:
            {
                InstanceReferenceValue irv = (InstanceReferenceValue) pe;
                if (irv.getReferencedInstanceObject().getName().equalsIgnoreCase(toBeMatched)) {
                    return irv;
                } else {
                    return null;
                }
            }
        case Aadl2Package.COMPUTED_VALUE:
            {
                ComputedValue cv = (ComputedValue) pe;
                if (cv.getFunction().equalsIgnoreCase(toBeMatched)) {
                    return cv;
                } else {
                    return null;
                }
            }
        case Aadl2Package.NAMED_VALUE:
            {
                NamedValue nv = (NamedValue) pe;
                AbstractNamedValue anv = nv.getNamedValue();
                if (anv instanceof NamedElement) {
                    NamedElement ne = (NamedElement) anv;
                    String name = ((NamedElement) anv).getName();
                    // Consider as a final node.
                    if (name.equalsIgnoreCase(toBeMatched)) {
                        return ne;
                    } else if (// Or a structure.
                    ne instanceof Property) {
                        Property p = (Property) ne;
                        if (p.getDefaultValue() != null) {
                            tmp = getValue(p.getDefaultValue(), toBeMatched);
                            return tmp;
                        }
                    }
                } else {
                    String msg = anv.getClass().getSimpleName() + " is not supported";
                    System.err.println(msg);
                    throw new UnsupportedOperationException(msg);
                }
                return null;
            }
        default:
            {
                String msg = pe.getClass().getSimpleName() + " is not supported";
                System.err.println(msg);
                throw new UnsupportedOperationException(msg);
            }
    }
}
Also used : ComputedValue(org.osate.aadl2.ComputedValue) ClassifierValue(org.osate.aadl2.ClassifierValue) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) Element(org.osate.aadl2.Element) RefinableElement(org.osate.aadl2.RefinableElement) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) ListValue(org.osate.aadl2.ListValue) RecordValue(org.osate.aadl2.RecordValue) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) NamedValue(org.osate.aadl2.NamedValue) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) BasicEList(org.eclipse.emf.common.util.BasicEList) EList(org.eclipse.emf.common.util.EList) StringLiteral(org.osate.aadl2.StringLiteral) PropertyExpression(org.osate.aadl2.PropertyExpression) InstanceReferenceValue(org.osate.aadl2.instance.InstanceReferenceValue) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property)

Example 39 with StringLiteral

use of org.osate.aadl2.StringLiteral in project osate2 by osate.

the class ProgrammingProperties method getInitializeEntrypointSourceText.

public static Optional<String> getInitializeEntrypointSourceText(NamedElement lookupContext, Optional<Mode> mode) {
    Property property = getInitializeEntrypointSourceText_Property(lookupContext);
    try {
        PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
        PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
        return Optional.of(((StringLiteral) resolved).getValue());
    } catch (PropertyNotPresentException e) {
        return Optional.empty();
    }
}
Also used : PropertyNotPresentException(org.osate.aadl2.properties.PropertyNotPresentException) PropertyExpression(org.osate.aadl2.PropertyExpression) Property(org.osate.aadl2.Property)

Example 40 with StringLiteral

use of org.osate.aadl2.StringLiteral in project osate2 by osate.

the class ProgrammingProperties method getTypeSourceName.

public static Optional<String> getTypeSourceName(NamedElement lookupContext, Optional<Mode> mode) {
    Property property = getTypeSourceName_Property(lookupContext);
    try {
        PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
        PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
        return Optional.of(((StringLiteral) resolved).getValue());
    } catch (PropertyNotPresentException e) {
        return Optional.empty();
    }
}
Also used : PropertyNotPresentException(org.osate.aadl2.properties.PropertyNotPresentException) PropertyExpression(org.osate.aadl2.PropertyExpression) Property(org.osate.aadl2.Property)

Aggregations

StringLiteral (org.osate.aadl2.StringLiteral)42 PropertyExpression (org.osate.aadl2.PropertyExpression)37 Property (org.osate.aadl2.Property)32 ListValue (org.osate.aadl2.ListValue)24 PropertyNotPresentException (org.osate.aadl2.properties.PropertyNotPresentException)19 BooleanLiteral (org.osate.aadl2.BooleanLiteral)18 IntegerLiteral (org.osate.aadl2.IntegerLiteral)17 RealLiteral (org.osate.aadl2.RealLiteral)17 NamedValue (org.osate.aadl2.NamedValue)16 RecordValue (org.osate.aadl2.RecordValue)14 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)13 ClassifierValue (org.osate.aadl2.ClassifierValue)13 RangeValue (org.osate.aadl2.RangeValue)12 PropertyAssociation (org.osate.aadl2.PropertyAssociation)11 EPackage (org.eclipse.emf.ecore.EPackage)10 Action (org.eclipse.xtext.Action)10 Parameter (org.eclipse.xtext.Parameter)10 ParserRule (org.eclipse.xtext.ParserRule)10 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)10 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)10