Search in sources :

Example 11 with ConstStatement

use of com.rockwellcollins.atc.agree.agree.ConstStatement in project AGREE by loonwerks.

the class AgreeTypeSystem method typeDefFromClassifier.

public static TypeDef typeDefFromClassifier(Classifier c) {
    if (c instanceof DataType || (c instanceof DataImplementation && ((DataImplementation) c).getAllSubcomponents().isEmpty() && ((DataImplementation) c).getType() != null)) {
        // Includes special case for data implementations implementing extensions of primitive types
        Classifier classifierType = c instanceof DataImplementation ? ((DataImplementation) c).getType() : c;
        List<PropertyAssociation> pas = classifierType.getAllPropertyAssociations();
        for (Classifier classType : classifierType.getSelfPlusAllExtended()) {
            if (classType != null && hasIntegerDataRepresentation(classType)) {
                for (PropertyAssociation choice : pas) {
                    Property p = choice.getProperty();
                    PropertyExpression v = choice.getOwnedValues().get(0).getOwnedValue();
                    String key = p.getQualifiedName();
                    if (key.equals("Data_Model::Integer_Range")) {
                        if (v instanceof RangeValue) {
                            try {
                                RangeValue rangeValue = (RangeValue) v;
                                long min = intFromPropExp(rangeValue.getMinimum()).get();
                                long max = intFromPropExp(rangeValue.getMaximum()).get();
                                return new RangeIntTypeDef(min, max);
                            } catch (Exception e) {
                                return Prim.ErrorTypeDef;
                            }
                        }
                    }
                }
                return Prim.IntTypeDef;
            } else if (classType != null && hasFloatDataRepresentation(classType)) {
                for (PropertyAssociation choice : pas) {
                    Property p = choice.getProperty();
                    PropertyExpression v = choice.getOwnedValues().get(0).getOwnedValue();
                    String key = p.getQualifiedName();
                    if (key.equals("Data_Model::Real_Range")) {
                        if (v instanceof RangeValue) {
                            try {
                                RangeValue rangeValue = (RangeValue) v;
                                double min = realFromPropExp(rangeValue.getMinimum()).get();
                                double max = realFromPropExp(rangeValue.getMaximum()).get();
                                return new RangeRealTypeDef(min, max);
                            } catch (Exception e) {
                                return Prim.ErrorTypeDef;
                            }
                        }
                    }
                }
                return Prim.RealTypeDef;
            } else if (classType != null && hasBooleanDataRepresentation(classType)) {
                return Prim.BoolTypeDef;
            }
        }
        boolean prop_isArray = false;
        int prop_arraySize = 0;
        TypeDef prop_arrayBaseType = null;
        boolean prop_isEnum = false;
        List<String> prop_enumValues = null;
        for (PropertyAssociation choice : pas) {
            Property p = choice.getProperty();
            PropertyExpression v = choice.getOwnedValues().get(0).getOwnedValue();
            String key = p.getQualifiedName();
            key = key == null ? p.getName() : key;
            if (key == null) {
                return Prim.ErrorTypeDef;
            }
            if (key.equalsIgnoreCase("Data_Model::Data_Representation")) {
                if (v instanceof NamedValue) {
                    AbstractNamedValue anv = ((NamedValue) v).getNamedValue();
                    if (anv instanceof EnumerationLiteral) {
                        EnumerationLiteral el = (EnumerationLiteral) anv;
                        prop_isArray = el.getName().equals("Array");
                        prop_isEnum = el.getName().equals("Enum");
                    }
                }
            } else if (key.equalsIgnoreCase("Data_Model::Enumerators")) {
                if (v instanceof ListValue) {
                    EList<PropertyExpression> peList = ((ListValue) v).getOwnedListElements();
                    String prefix = c.getQualifiedName() + "_";
                    prop_enumValues = new ArrayList<>();
                    for (PropertyExpression pe : peList) {
                        if (pe instanceof StringLiteral) {
                            String enumString = prefix + ((StringLiteral) pe).getValue();
                            prop_enumValues.add(enumString);
                        }
                    }
                }
            } else if (key.equalsIgnoreCase("Data_Model::Base_Type")) {
                if (v instanceof ListValue) {
                    ListValue l = (ListValue) v;
                    PropertyExpression pe = l.getOwnedListElements().get(0);
                    if (pe instanceof ClassifierValue) {
                        prop_arrayBaseType = typeDefFromClassifier(((ClassifierValue) pe).getClassifier());
                    }
                }
            } else if (key.equalsIgnoreCase("Data_Model::Dimension")) {
                if (v instanceof ListValue) {
                    ListValue l = (ListValue) v;
                    PropertyExpression pe = l.getOwnedListElements().get(0);
                    prop_arraySize = Math.toIntExact(intFromPropExp(pe).orElse((long) -1).longValue());
                }
            }
        }
        if (prop_isArray && prop_arraySize > 0 && prop_arrayBaseType != null) {
            return new ArrayTypeDef(prop_arrayBaseType, prop_arraySize, Optional.of(c));
        } else if (prop_isEnum && prop_enumValues != null) {
            String name = c.getQualifiedName();
            return new EnumTypeDef(name, prop_enumValues, c);
        }
    } else if (c instanceof ComponentClassifier) {
        Map<String, TypeDef> fields = new HashMap<>();
        Classifier currClsfr = c;
        while (currClsfr != null) {
            ComponentType ct = null;
            if (currClsfr instanceof ComponentImplementation) {
                EList<Subcomponent> subcomps = ((ComponentImplementation) currClsfr).getAllSubcomponents();
                for (Subcomponent sub : subcomps) {
                    String fieldName = sub.getName();
                    if (sub.getClassifier() != null) {
                        boolean prop_isArray = false;
                        int prop_arraySize = 0;
                        boolean prop_isEnum = false;
                        List<String> prop_enumValues = null;
                        for (PropertyAssociation pa : sub.getOwnedPropertyAssociations()) {
                            Property p = pa.getProperty();
                            String key = p.getQualifiedName();
                            key = key == null ? p.getName() : key;
                            PropertyExpression v = null;
                            if (!pa.getOwnedValues().isEmpty()) {
                                v = pa.getOwnedValues().get(0).getOwnedValue();
                            } else {
                                continue;
                            }
                            if (key.equals("Data_Model::Data_Representation")) {
                                if (v instanceof NamedValue) {
                                    AbstractNamedValue anv = ((NamedValue) v).getNamedValue();
                                    if (anv instanceof EnumerationLiteral) {
                                        EnumerationLiteral el = (EnumerationLiteral) anv;
                                        prop_isArray = el.getName().equals("Array");
                                        prop_isEnum = el.getName().equals("Enum");
                                    }
                                }
                            } else if (key.equals("Data_Model::Dimension")) {
                                if (v instanceof ListValue) {
                                    ListValue l = (ListValue) v;
                                    PropertyExpression pe = l.getOwnedListElements().get(0);
                                    prop_arraySize = Math.toIntExact(intFromPropExp(pe).orElse((long) -1).longValue());
                                }
                            } else if (key.equals("Data_Model::Enumerators")) {
                                if (v instanceof ListValue) {
                                    EList<PropertyExpression> peList = ((ListValue) v).getOwnedListElements();
                                    String prefix = c.getQualifiedName() + "_";
                                    prop_enumValues = new ArrayList<>();
                                    for (PropertyExpression pe : peList) {
                                        if (pe instanceof StringLiteral) {
                                            String enumString = prefix + ((StringLiteral) pe).getValue();
                                            prop_enumValues.add(enumString);
                                        }
                                    }
                                }
                            }
                        }
                        if (prop_isArray && prop_arraySize > 0) {
                            TypeDef typeDef = new ArrayTypeDef(typeDefFromClassifier(sub.getClassifier()), prop_arraySize, Optional.empty());
                            fields.putIfAbsent(fieldName, typeDef);
                        } else if (prop_isEnum && prop_enumValues != null) {
                            String name = c.getQualifiedName();
                            TypeDef typeDef = new EnumTypeDef(name, prop_enumValues, c);
                            fields.putIfAbsent(fieldName, typeDef);
                        } else if (sub.getArrayDimensions().size() == 0) {
                            TypeDef typeDef = typeDefFromClassifier(sub.getClassifier());
                            fields.putIfAbsent(fieldName, typeDef);
                        } else if (sub.getArrayDimensions().size() == 1) {
                            ArrayDimension ad = sub.getArrayDimensions().get(0);
                            int size = Math.toIntExact(getArraySize(ad));
                            TypeDef stem = typeDefFromClassifier(sub.getClassifier());
                            TypeDef typeDef = new ArrayTypeDef(stem, size, Optional.empty());
                            fields.putIfAbsent(fieldName, typeDef);
                        }
                    }
                }
                ct = ((ComponentImplementation) currClsfr).getType();
            } else if (c instanceof ComponentType) {
                ct = (ComponentType) currClsfr;
            }
            if (ct != null) {
                EList<Feature> features = ct.getAllFeatures();
                for (Feature feature : features) {
                    String fieldName = feature.getName();
                    if (feature.getClassifier() != null) {
                        if (feature.getArrayDimensions().size() == 0) {
                            TypeDef typeDef = typeDefFromClassifier(feature.getClassifier());
                            fields.putIfAbsent(fieldName, typeDef);
                        } else if (feature.getArrayDimensions().size() == 1) {
                            ArrayDimension ad = feature.getArrayDimensions().get(0);
                            int size = Math.toIntExact(getArraySize(ad));
                            TypeDef stem = typeDefFromClassifier(feature.getClassifier());
                            TypeDef typeDef = new ArrayTypeDef(stem, size, Optional.empty());
                            fields.putIfAbsent(fieldName, typeDef);
                        }
                    }
                }
                for (AnnexSubclause annex : AnnexUtil.getAllAnnexSubclauses(currClsfr, AgreePackage.eINSTANCE.getAgreeContractSubclause())) {
                    AgreeContract contract = (AgreeContract) ((AgreeContractSubclause) annex).getContract();
                    for (SpecStatement spec : contract.getSpecs()) {
                        List<Arg> args = new ArrayList<>();
                        if (spec instanceof EqStatement) {
                            args = ((EqStatement) spec).getLhs();
                        } else if (spec instanceof InputStatement) {
                            args = ((InputStatement) spec).getLhs();
                        }
                        for (Arg arg : args) {
                            String fieldName = arg.getName();
                            TypeDef typeDef = typeDefFromNE(arg);
                            fields.putIfAbsent(fieldName, typeDef);
                        }
                        if (spec instanceof ConstStatement) {
                            String fieldName = ((ConstStatement) spec).getName();
                            TypeDef typeDef = AgreeTypeSystem.typeDefFromType(((ConstStatement) spec).getType());
                            fields.putIfAbsent(fieldName, typeDef);
                        }
                    }
                }
            }
            currClsfr = currClsfr.getExtended();
        }
        String name = c.getQualifiedName();
        return new RecordTypeDef(name, fields, c);
    }
    return Prim.ErrorTypeDef;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentClassifier(org.osate.aadl2.ComponentClassifier) ClassifierValue(org.osate.aadl2.ClassifierValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) ArrayList(java.util.ArrayList) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) NamedValue(org.osate.aadl2.NamedValue) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) AadlString(org.osate.aadl2.AadlString) Feature(org.osate.aadl2.Feature) RangeValue(org.osate.aadl2.RangeValue) Subcomponent(org.osate.aadl2.Subcomponent) DataType(org.osate.aadl2.DataType) PropertyExpression(org.osate.aadl2.PropertyExpression) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList) InputStatement(com.rockwellcollins.atc.agree.agree.InputStatement) ArraySizeProperty(org.osate.aadl2.ArraySizeProperty) Property(org.osate.aadl2.Property) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral) AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) ComponentType(org.osate.aadl2.ComponentType) ListValue(org.osate.aadl2.ListValue) DataImplementation(org.osate.aadl2.DataImplementation) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) AgreeContractSubclause(com.rockwellcollins.atc.agree.agree.AgreeContractSubclause) ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) EList(org.eclipse.emf.common.util.EList) StringLiteral(org.osate.aadl2.StringLiteral) Arg(com.rockwellcollins.atc.agree.agree.Arg) EqStatement(com.rockwellcollins.atc.agree.agree.EqStatement) Map(java.util.Map) HashMap(java.util.HashMap) ArrayDimension(org.osate.aadl2.ArrayDimension) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Example 12 with ConstStatement

use of com.rockwellcollins.atc.agree.agree.ConstStatement in project AGREE by loonwerks.

the class AGREESimulationState method findConstantById.

/**
 * Retrieved an element using an absolute path.
 * @param packageName is the AADL package name. Case insensitive. For example a::b
 * @return
 */
@Override
public Object findConstantById(String id) {
    id = id.toLowerCase();
    final int index = id.lastIndexOf("::");
    if (index < 0) {
        return null;
    }
    final String pkgName = id.substring(0, index);
    final String constantName = id.substring(index + 2, id.length());
    final Map<String, ConstStatement> constMap = packageToConstantsMap.get(pkgName);
    return constMap == null ? null : constMap.get(constantName);
}
Also used : ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) InputConstraint(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.InputConstraint)

Example 13 with ConstStatement

use of com.rockwellcollins.atc.agree.agree.ConstStatement in project AGREE by loonwerks.

the class AgreeValidator method checkNodeStmt.

@Check(CheckType.FAST)
public void checkNodeStmt(NodeStmt nodeStmt) {
    List<NamedElmExpr> dotIds = EcoreUtil2.getAllContentsOfType(nodeStmt, NamedElmExpr.class);
    for (NamedElmExpr dotId : dotIds) {
        NamedElement id = dotId.getElm();
        // restrict the elements that are single names or the last projection.
        boolean restrictedElm = true;
        if (dotId.eContainer() instanceof SelectionExpr) {
            NamedElement ne = ((SelectionExpr) dotId.eContainer()).getField();
            restrictedElm = ne == id && !(dotId.eContainer().eContainer() instanceof SelectionExpr);
        }
        if (restrictedElm && !(id instanceof Arg) && !(id instanceof ConstStatement) && !(id instanceof NodeDef) && !(id instanceof FnDef) && !(id instanceof UninterpretedFnDef) && !(id instanceof DataSubcomponent) && !(id instanceof DoubleDotRef) && !(id instanceof DataImplementation) && !(id instanceof RecordDef) && !(id instanceof NamedID)) {
            error(dotId, "Only arguments, constants, and node calls allowed within a node");
        }
    }
}
Also used : NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) DataImplementation(org.osate.aadl2.DataImplementation) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) NamedID(com.rockwellcollins.atc.agree.agree.NamedID) FnDef(com.rockwellcollins.atc.agree.agree.FnDef) LibraryFnDef(com.rockwellcollins.atc.agree.agree.LibraryFnDef) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) DataSubcomponent(org.osate.aadl2.DataSubcomponent) Arg(com.rockwellcollins.atc.agree.agree.Arg) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) NamedElement(org.osate.aadl2.NamedElement) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) Check(org.eclipse.xtext.validation.Check)

Example 14 with ConstStatement

use of com.rockwellcollins.atc.agree.agree.ConstStatement in project AGREE by loonwerks.

the class AgreeValidator method isTimingConst.

/**
 * Is a given expression a usable timing constant
 *
 * Determine whether the given expression is a constant that may be a
 * statically evaluated such that can be used to set the timing model
 *
 * @param expr
 * @return true if acceptable timing constant, false otherwise
 */
protected boolean isTimingConst(Expr expr) {
    if (expr instanceof SelectionExpr) {
        SelectionExpr id = (SelectionExpr) expr;
        NamedElement finalId = id.getField();
        return (finalId instanceof ConstStatement);
    } else if (expr instanceof EnumLitExpr) {
        return true;
    }
    return false;
}
Also used : ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) NamedElement(org.osate.aadl2.NamedElement)

Aggregations

ConstStatement (com.rockwellcollins.atc.agree.agree.ConstStatement)14 AgreeContract (com.rockwellcollins.atc.agree.agree.AgreeContract)6 SpecStatement (com.rockwellcollins.atc.agree.agree.SpecStatement)6 NamedElement (org.osate.aadl2.NamedElement)6 SelectionExpr (com.rockwellcollins.atc.agree.agree.SelectionExpr)5 AnnexLibrary (org.osate.aadl2.AnnexLibrary)5 IntLitExpr (com.rockwellcollins.atc.agree.agree.IntLitExpr)4 NodeDef (com.rockwellcollins.atc.agree.agree.NodeDef)4 RealLitExpr (com.rockwellcollins.atc.agree.agree.RealLitExpr)4 ArrayList (java.util.ArrayList)4 AgreeContractLibrary (com.rockwellcollins.atc.agree.agree.AgreeContractLibrary)3 Arg (com.rockwellcollins.atc.agree.agree.Arg)3 BinaryExpr (com.rockwellcollins.atc.agree.agree.BinaryExpr)3 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)3 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)3 EnumStatement (com.rockwellcollins.atc.agree.agree.EnumStatement)3 NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)3 UnaryExpr (com.rockwellcollins.atc.agree.agree.UnaryExpr)3 HashMap (java.util.HashMap)3 EList (org.eclipse.emf.common.util.EList)3