Search in sources :

Example 31 with RealLiteral

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

the class InterpreterUtil method multiply.

public static NumberValue multiply(NumberValue v1, NumberValue v2) {
    UnitLiteral unit = (v1.getUnit() != null) ? v1.getUnit() : v2.getUnit();
    if (v1 instanceof IntegerLiteral && v2 instanceof IntegerLiteral) {
        long s1 = ((IntegerLiteral) v1).getValue();
        long s2 = ((IntegerLiteral) v2).getValue();
        IntegerLiteral result = Aadl2Factory.eINSTANCE.createIntegerLiteral();
        result.setValue(s1 * s2);
        result.setUnit(unit);
        return result;
    } else {
        double s1 = (v1 instanceof IntegerLiteral) ? ((IntegerLiteral) v1).getValue() : ((RealLiteral) v1).getValue();
        double s2 = (v2 instanceof IntegerLiteral) ? ((IntegerLiteral) v2).getValue() : ((RealLiteral) v2).getValue();
        RealLiteral result = Aadl2Factory.eINSTANCE.createRealLiteral();
        result.setValue(s1 * s2);
        result.setUnit(unit);
        return result;
    }
}
Also used : RealLiteral(org.osate.aadl2.RealLiteral) UnitLiteral(org.osate.aadl2.UnitLiteral) IntegerLiteral(org.osate.aadl2.IntegerLiteral)

Example 32 with RealLiteral

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

the class InterpreterUtil method round.

public static IntegerLiteral round(NumberValue nv) {
    if (nv instanceof RealLiteral) {
        long iv = Math.round(((RealLiteral) nv).getValue());
        IntegerLiteral result = Aadl2Factory.eINSTANCE.createIntegerLiteral();
        result.setValue(iv);
        result.setUnit(nv.getUnit());
        return result;
    } else {
        return (IntegerLiteral) nv;
    }
}
Also used : RealLiteral(org.osate.aadl2.RealLiteral) IntegerLiteral(org.osate.aadl2.IntegerLiteral)

Example 33 with RealLiteral

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

the class AadlBaParserVisitor method clonePropertyExpression.

private PropertyExpression clonePropertyExpression(PropertyExpression sourcePropertyExpression) {
    PropertyExpression targetPropertyExpression = null;
    if (sourcePropertyExpression instanceof ListValue) {
        ListValue sourceLV = (ListValue) sourcePropertyExpression;
        ListValue targetLV = _coreFact.createListValue();
        for (PropertyExpression propInList : sourceLV.getOwnedListElements()) {
            targetLV.getOwnedListElements().add(clonePropertyExpression(propInList));
        }
        targetPropertyExpression = targetLV;
    } else if (sourcePropertyExpression instanceof StringLiteral) {
        StringLiteral sourceSL = (StringLiteral) sourcePropertyExpression;
        StringLiteral targetSL = _coreFact.createStringLiteral();
        targetSL.setValue(sourceSL.getValue());
        targetPropertyExpression = targetSL;
    } else if (sourcePropertyExpression instanceof IntegerLiteral) {
        IntegerLiteral sourceIL = (IntegerLiteral) sourcePropertyExpression;
        IntegerLiteral targetIL = _coreFact.createIntegerLiteral();
        targetIL.setValue(sourceIL.getValue());
        targetIL.setUnit(sourceIL.getUnit());
        targetPropertyExpression = targetIL;
    } else if (sourcePropertyExpression instanceof RealLiteral) {
        RealLiteral sourceRL = (RealLiteral) sourcePropertyExpression;
        RealLiteral targetRL = _coreFact.createRealLiteral();
        targetRL.setValue(sourceRL.getValue());
        targetRL.setUnit(sourceRL.getUnit());
        targetPropertyExpression = targetRL;
    } else if (sourcePropertyExpression instanceof RecordValue) {
        RecordValue sourceRV = (RecordValue) sourcePropertyExpression;
        RecordValue targetRV = _coreFact.createRecordValue();
        targetRV.getOwnedFieldValues().addAll(sourceRV.getOwnedFieldValues());
        targetPropertyExpression = targetRV;
    } else if (sourcePropertyExpression instanceof BooleanLiteral) {
        BooleanLiteral sourceBL = (BooleanLiteral) sourcePropertyExpression;
        BooleanLiteral targetBL = _coreFact.createBooleanLiteral();
        targetBL.setValue(sourceBL.getValue());
        targetPropertyExpression = targetBL;
    } else if (sourcePropertyExpression instanceof RangeValue) {
        RangeValue sourceRV = (RangeValue) sourcePropertyExpression;
        RangeValue targetRV = _coreFact.createRangeValue();
        targetRV.setMinimum(clonePropertyExpression(sourceRV.getMinimum()));
        targetRV.setMaximum(clonePropertyExpression(sourceRV.getMaximum()));
        targetPropertyExpression = targetRV;
    } else if (sourcePropertyExpression instanceof DeclarativeReferenceValue) {
        DeclarativeReferenceValue sourceDRV = (DeclarativeReferenceValue) sourcePropertyExpression;
        ReferenceValue targetRV = _coreFact.createReferenceValue();
        targetRV.setPath(sourceDRV.getRef());
        targetPropertyExpression = targetRV;
    } else if (sourcePropertyExpression instanceof DeclarativeClassifierValue) {
        DeclarativeClassifierValue sourceDCV = (DeclarativeClassifierValue) sourcePropertyExpression;
        ClassifierValue targetCV = _coreFact.createClassifierValue();
        targetCV.setClassifier(sourceDCV.getClassifier());
        targetPropertyExpression = targetCV;
    }
    return targetPropertyExpression;
}
Also used : RealLiteral(org.osate.aadl2.RealLiteral) BehaviorRealLiteral(org.osate.ba.aadlba.BehaviorRealLiteral) ClassifierValue(org.osate.aadl2.ClassifierValue) DeclarativeClassifierValue(org.osate.ba.declarative.DeclarativeClassifierValue) BehaviorStringLiteral(org.osate.ba.aadlba.BehaviorStringLiteral) StringLiteral(org.osate.aadl2.StringLiteral) DeclarativeReferenceValue(org.osate.ba.declarative.DeclarativeReferenceValue) BehaviorBooleanLiteral(org.osate.ba.aadlba.BehaviorBooleanLiteral) BooleanLiteral(org.osate.aadl2.BooleanLiteral) DeclarativeReferenceValue(org.osate.ba.declarative.DeclarativeReferenceValue) ReferenceValue(org.osate.aadl2.ReferenceValue) DeclarativeClassifierValue(org.osate.ba.declarative.DeclarativeClassifierValue) ListValue(org.osate.aadl2.ListValue) RecordValue(org.osate.aadl2.RecordValue) PropertyExpression(org.osate.aadl2.PropertyExpression) DeclarativePropertyExpression(org.osate.ba.declarative.DeclarativePropertyExpression) IntegerLiteral(org.osate.aadl2.IntegerLiteral) BehaviorIntegerLiteral(org.osate.ba.aadlba.BehaviorIntegerLiteral) RangeValue(org.osate.aadl2.RangeValue)

Example 34 with RealLiteral

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

the class AadlBaNameResolver method propertyExpressionResolver.

/**
 * Resolves the property expressions used in behavior annex.
 * @param p
 *
 * @return {@code true} if all names are resolved. {@code false} otherwise.
 */
private boolean propertyExpressionResolver(BehaviorVariable bv, Property p, PropertyExpression pe) {
    QualifiedNamedElement qne = (QualifiedNamedElement) p;
    String propertyName = "";
    boolean hasNamespace = qne.getBaNamespace() != null;
    if (hasNamespace) {
        propertyName = qne.getBaNamespace().getId() + "::";
    }
    propertyName += qne.getBaName().getId();
    boolean result = true;
    if (pe instanceof DeclarativeListValue) {
        ListValue dlv = (DeclarativeListValue) pe;
        for (PropertyExpression peInList : dlv.getOwnedListElements()) {
            result &= propertyExpressionResolver(bv, p, peInList);
        }
    } else if (pe instanceof IntegerLiteral) {
        IntegerLiteral il = (IntegerLiteral) pe;
        if (il.getUnit() != null && il.getUnit() instanceof QualifiedNamedElement) {
            result &= unitResolver(il, bv, p);
        }
    } else if (pe instanceof RealLiteral) {
        RealLiteral rl = (RealLiteral) pe;
        if (rl.getUnit() != null && rl.getUnit() instanceof QualifiedNamedElement) {
            result &= unitResolver(rl, bv, p);
        }
    } else if (pe instanceof RecordValue) {
        RecordValue rv = (RecordValue) pe;
        for (BasicPropertyAssociation bpa : rv.getOwnedFieldValues()) {
            if (bpa instanceof DeclarativeBasicPropertyAssociation) {
                DeclarativeBasicPropertyAssociation dbpa = (DeclarativeBasicPropertyAssociation) bpa;
                String basicPropertyName = dbpa.getBasicPropertyName();
                BasicProperty basicProp = getBasicPropertyResolver(bv, p, basicPropertyName);
                if (basicProp == null) {
                    _errManager.error(bv, "Property field \'" + basicPropertyName + "\' of property " + propertyName + " is not found");
                    result = false;
                }
                dbpa.setProperty(basicProp);
            }
        }
    } else if (pe instanceof RangeValue) {
        RangeValue rv = (RangeValue) pe;
        result &= propertyExpressionResolver(bv, p, rv.getMaximum());
        result &= propertyExpressionResolver(bv, p, rv.getMinimum());
    } else if (pe instanceof ReferenceValue) {
        ReferenceValue rv = (ReferenceValue) pe;
        Reference r = (Reference) (rv.getPath());
        ContainmentPathElement firstCne = Aadl2Factory.eINSTANCE.createContainmentPathElement();
        ContainmentPathElement prevCne = null;
        boolean first = true;
        Classifier context = _baParentContainer;
        for (Identifier subPath : r.getIds()) {
            ContainmentPathElement currentCne;
            if (!first) {
                currentCne = Aadl2Factory.eINSTANCE.createContainmentPathElement();
            } else {
                currentCne = firstCne;
            }
            first = false;
            NamedElement ne = Aadl2Visitors.findSubcomponentInComponent(context, subPath.getId());
            if (ne == null) {
                ne = Aadl2Visitors.findFeatureInComponent(context, subPath.getId());
            }
            if (ne == null) {
                _errManager.error(bv, "Element \'" + subPath.getId() + "\' is not found in " + context.getName() + "(property " + propertyName + ")");
                result = false;
            } else {
                currentCne.setNamedElement(ne);
                if (prevCne != null) {
                    prevCne.setPath(currentCne);
                }
                if (ne instanceof Subcomponent) {
                    Subcomponent sub = (Subcomponent) ne;
                    context = sub.getClassifier();
                } else if (ne instanceof Feature) {
                    Feature f = (Feature) ne;
                    context = f.getClassifier();
                }
            }
            prevCne = currentCne;
        }
        rv.setPath(firstCne);
    } else if (pe instanceof ClassifierValue) {
        ClassifierValue cv = (ClassifierValue) pe;
        QualifiedNamedElement classifierQne = (QualifiedNamedElement) cv.getClassifier();
        String qneClassPackageName = "";
        boolean qneClassHasNamespace = classifierQne.getBaNamespace() != null;
        if (qneClassHasNamespace) {
            qneClassPackageName = classifierQne.getBaNamespace().getId();
        }
        boolean resolved = false;
        for (PackageSection context : _contextsTab) {
            NamedElement ne = Aadl2Visitors.findElementInPackage(classifierQne.getBaName().getId(), qneClassPackageName, context);
            if (ne != null && ne instanceof Classifier) {
                cv.setClassifier((Classifier) ne);
                resolved = true;
                break;
            }
        }
        if (!resolved) {
            String cvQualifiedName = "";
            if (!qneClassPackageName.isEmpty()) {
                cvQualifiedName += qneClassPackageName + "::";
            }
            cvQualifiedName += classifierQne.getBaName().getId();
            _errManager.error(bv, "Classifier \'" + cvQualifiedName + "\' associated to property " + propertyName + " is not found");
            result = false;
        }
    }
    return result;
}
Also used : ClassifierValue(org.osate.aadl2.ClassifierValue) ReferenceValue(org.osate.aadl2.ReferenceValue) DeclarativePropertyReference(org.osate.ba.declarative.DeclarativePropertyReference) Reference(org.osate.ba.declarative.Reference) PackageSection(org.osate.aadl2.PackageSection) ListValue(org.osate.aadl2.ListValue) DeclarativeListValue(org.osate.ba.declarative.DeclarativeListValue) DeclarativeListValue(org.osate.ba.declarative.DeclarativeListValue) RecordValue(org.osate.aadl2.RecordValue) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) Feature(org.osate.aadl2.Feature) ClassifierFeature(org.osate.aadl2.ClassifierFeature) RangeValue(org.osate.aadl2.RangeValue) RealLiteral(org.osate.aadl2.RealLiteral) BasicProperty(org.osate.aadl2.BasicProperty) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) Identifier(org.osate.ba.declarative.Identifier) ArrayableIdentifier(org.osate.ba.declarative.ArrayableIdentifier) Subcomponent(org.osate.aadl2.Subcomponent) PropertyExpression(org.osate.aadl2.PropertyExpression) DeclarativeBasicPropertyAssociation(org.osate.ba.declarative.DeclarativeBasicPropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) DeclarativeBasicPropertyAssociation(org.osate.ba.declarative.DeclarativeBasicPropertyAssociation) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) NamedElement(org.osate.aadl2.NamedElement) IntegerLiteral(org.osate.aadl2.IntegerLiteral) BehaviorIntegerLiteral(org.osate.ba.aadlba.BehaviorIntegerLiteral)

Example 35 with RealLiteral

use of org.osate.aadl2.RealLiteral 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)

Aggregations

RealLiteral (org.osate.aadl2.RealLiteral)43 IntegerLiteral (org.osate.aadl2.IntegerLiteral)31 BooleanLiteral (org.osate.aadl2.BooleanLiteral)17 StringLiteral (org.osate.aadl2.StringLiteral)17 RangeValue (org.osate.aadl2.RangeValue)13 RecordValue (org.osate.aadl2.RecordValue)12 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)11 NamedValue (org.osate.aadl2.NamedValue)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 ClassifierValue (org.osate.aadl2.ClassifierValue)10 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)10 ListValue (org.osate.aadl2.ListValue)10 PropertyExpression (org.osate.aadl2.PropertyExpression)10 ReferenceValue (org.osate.aadl2.ReferenceValue)10 PropertyAssociation (org.osate.aadl2.PropertyAssociation)8 UnitLiteral (org.osate.aadl2.UnitLiteral)8 AadlBoolean (org.osate.aadl2.AadlBoolean)7