Search in sources :

Example 6 with EqStatement

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

the class AgreeASTBuilder method getEquationVars.

private List<AgreeVar> getEquationVars(EList<SpecStatement> specs, ComponentInstance compInst) {
    List<AgreeVar> agreeVars = new ArrayList<>();
    for (SpecStatement spec : specs) {
        if (spec instanceof EqStatement) {
            EList<Arg> args = ((EqStatement) spec).getLhs();
            List<VarDecl> vars = agreeVarsFromArgs(args, compInst);
            for (VarDecl var : vars) {
                agreeVars.add((AgreeVar) var);
            }
        } else if (spec instanceof PropertyStatement) {
            agreeVars.add(new AgreeVar(((PropertyStatement) spec).getName(), NamedType.BOOL, spec, compInst, null));
        }
    }
    return agreeVars;
}
Also used : VarDecl(jkind.lustre.VarDecl) Arg(com.rockwellcollins.atc.agree.agree.Arg) ArrayList(java.util.ArrayList) PropertyStatement(com.rockwellcollins.atc.agree.agree.PropertyStatement) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) EqStatement(com.rockwellcollins.atc.agree.agree.EqStatement)

Example 7 with EqStatement

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

the class AgreeASTBuilder method getEquationStatements.

private GatheredVariablesAndConstraints getEquationStatements(EList<SpecStatement> specs, Map<String, jkind.lustre.Expr> rewriteMap) {
    GatheredVariablesAndConstraints result = new GatheredVariablesAndConstraints();
    for (SpecStatement spec : specs) {
        if (spec instanceof EqStatement) {
            EqStatement eq = (EqStatement) spec;
            EList<Arg> lhs = eq.getLhs();
            if (eq.getExpr() != null) {
                Expr expr = doSwitch(eq.getExpr()).accept(new SubstitutionVisitor(rewriteMap));
                if (lhs.size() != 1) {
                    List<Expr> ids = new ArrayList<>();
                    for (Arg arg : lhs) {
                        ids.add(new IdExpr(arg.getName()));
                    }
                    TupleExpr tuple = new TupleExpr(ids);
                    expr = new BinaryExpr(tuple, BinaryOp.EQUAL, expr);
                } else {
                    expr = new BinaryExpr(new IdExpr(lhs.get(0).getName()), BinaryOp.EQUAL, expr);
                }
                result.assertions.add(new AgreeStatement("", expr, spec));
            }
            result.obligations.addAll(getConstraintsFromArgs(lhs, eq));
        }
    }
    return result;
}
Also used : IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) TupleExpr(jkind.lustre.TupleExpr) SubstitutionVisitor(jkind.translation.SubstitutionVisitor) EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) FlatmapExpr(com.rockwellcollins.atc.agree.agree.FlatmapExpr) TimeFallExpr(com.rockwellcollins.atc.agree.agree.TimeFallExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) ArrayExpr(jkind.lustre.ArrayExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) IdExpr(jkind.lustre.IdExpr) TimeExpr(com.rockwellcollins.atc.agree.agree.TimeExpr) FoldRightExpr(com.rockwellcollins.atc.agree.agree.FoldRightExpr) TagExpr(com.rockwellcollins.atc.agree.agree.TagExpr) EventExpr(com.rockwellcollins.atc.agree.agree.EventExpr) LatchedExpr(com.rockwellcollins.atc.agree.agree.LatchedExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) FunctionCallExpr(jkind.lustre.FunctionCallExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) IntExpr(jkind.lustre.IntExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) ExistsExpr(com.rockwellcollins.atc.agree.agree.ExistsExpr) FoldLeftExpr(com.rockwellcollins.atc.agree.agree.FoldLeftExpr) RecordUpdateExpr(com.rockwellcollins.atc.agree.agree.RecordUpdateExpr) ForallExpr(com.rockwellcollins.atc.agree.agree.ForallExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) ArrayUpdateExpr(com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) CallExpr(com.rockwellcollins.atc.agree.agree.CallExpr) ArrayLiteralExpr(com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr) Arg(com.rockwellcollins.atc.agree.agree.Arg) EqStatement(com.rockwellcollins.atc.agree.agree.EqStatement)

Example 8 with EqStatement

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

the class RenamingVisitor method getReferenceStr.

private String getReferenceStr(AgreeVar var) {
    String prefix = getCategory(rootInstance, var);
    if (prefix == null) {
        return null;
    }
    if (var.id.endsWith(AgreeASTBuilder.clockIDSuffix)) {
        return null;
    }
    String seperator = (prefix == "" ? "" : ".");
    EObject reference = var.reference;
    String suffix = "";
    if (var.id.endsWith(AgreeASTBuilder.eventSuffix + AgreeInlineLatchedConnections.LATCHED_SUFFIX)) {
        suffix = "._EVENT_._LATCHED_";
    } else if (var.id.endsWith(AgreeASTBuilder.eventSuffix)) {
        suffix = "._EVENT_";
    } else if (var.id.endsWith(AgreeInlineLatchedConnections.LATCHED_SUFFIX)) {
        suffix = "._LATCHED_";
    }
    if (reference instanceof GuaranteeStatement) {
        String id = ((GuaranteeStatement) reference).getName();
        if (id == null || id.isEmpty()) {
            id = "";
        } else {
            id = "[" + id + "] ";
        }
        return id + ((GuaranteeStatement) reference).getStr();
    } else if (reference instanceof AssumeStatement) {
        String id = ((AssumeStatement) reference).getName();
        if (id == null || id.isEmpty()) {
            id = "";
        } else {
            id = "[" + id + "] ";
        }
        return prefix + " assume: " + id + ((AssumeStatement) reference).getStr();
    } else if (reference instanceof LemmaStatement) {
        String id = ((LemmaStatement) reference).getName();
        if (id == null || id.isEmpty()) {
            id = "";
        } else {
            id = "[" + id + "] ";
        }
        return prefix + " lemma: " + id + ((LemmaStatement) reference).getStr();
    } else if (reference instanceof ReachableStatement) {
        renaming.addInvertedProperty(var.id);
        String id = ((ReachableStatement) reference).getName();
        if (id == null || id.isEmpty()) {
            id = "";
        } else {
            id = "[" + id + "] ";
        }
        return prefix + " reachable: " + id + ((ReachableStatement) reference).getStr();
    } else if (reference instanceof AssertStatement) {
        throw new AgreeException("We really didn't expect to see an assert statement here");
    } else if (reference instanceof Arg) {
        return prefix + seperator + ((Arg) reference).getName() + suffix;
    } else if (reference instanceof EqStatement) {
        return prefix + "eq " + String.join(", ", ((EqStatement) reference).getLhs().stream().map(lhs -> argToString(lhs)).collect(Collectors.toList()));
    } else if (reference instanceof InputStatement) {
        return prefix + "agree_input " + String.join(", ", ((InputStatement) reference).getLhs().stream().map(lhs -> argToString(lhs)).collect(Collectors.toList()));
    } else if (reference instanceof DataPort) {
        return prefix + seperator + ((DataPort) reference).getName() + suffix;
    } else if (reference instanceof EventPort) {
        return prefix + seperator + ((EventPort) reference).getName() + suffix;
    } else if (reference instanceof EventDataPort) {
        return prefix + seperator + ((EventDataPort) reference).getName() + suffix;
    } else if (reference instanceof FeatureGroup) {
        String featName = ((FeatureGroup) reference).getName();
        String varName = var.toString();
        featName = varName.substring(varName.indexOf(featName)).replace("__", ".");
        return prefix + seperator + featName;
    } else if (reference instanceof PropertyStatement) {
        return prefix + seperator + ((PropertyStatement) reference).getName();
    } else if (reference instanceof Property) {
        return "AADL property " + ((Property) reference).getName();
    } else if (reference instanceof GetPropertyExpr) {
        return "Get_Property(" + ((GetPropertyExpr) reference).getContainingClassifier().getName() + ", " + ((Property) ((GetPropertyExpr) reference).getProp()).getName() + ")";
    } else if (reference instanceof ComponentType || reference instanceof ComponentImplementation || reference instanceof SystemImplementation) {
        if (var.id.equals(LustreAstBuilder.assumeHistSufix)) {
            return "Subcomponent Assumptions";
        }
        return "Result";
    } else if (reference instanceof AgreeStatement) {
        return prefix + reference.toString();
    }
    throw new AgreeException("Unhandled reference type: '" + reference.getClass().getName() + "'");
}
Also used : ComponentInstance(org.osate.aadl2.instance.ComponentInstance) AstIterVisitor(jkind.lustre.visitors.AstIterVisitor) Arg(com.rockwellcollins.atc.agree.agree.Arg) Program(jkind.lustre.Program) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) ComponentImplementation(org.osate.aadl2.ComponentImplementation) AgreeLayout(com.rockwellcollins.atc.agree.analysis.AgreeLayout) SystemImplementation(org.osate.aadl2.SystemImplementation) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) Function(jkind.lustre.Function) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) ComponentType(org.osate.aadl2.ComponentType) SigType(com.rockwellcollins.atc.agree.analysis.AgreeLayout.SigType) InputStatement(com.rockwellcollins.atc.agree.agree.InputStatement) PropertyStatement(com.rockwellcollins.atc.agree.agree.PropertyStatement) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) FeatureGroup(org.osate.aadl2.FeatureGroup) AssertStatement(com.rockwellcollins.atc.agree.agree.AssertStatement) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) EqStatement(com.rockwellcollins.atc.agree.agree.EqStatement) AgreeInlineLatchedConnections(com.rockwellcollins.atc.agree.analysis.ast.visitors.AgreeInlineLatchedConnections) PrimType(com.rockwellcollins.atc.agree.agree.PrimType) ReachableStatement(com.rockwellcollins.atc.agree.agree.ReachableStatement) EObject(org.eclipse.emf.ecore.EObject) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) Collectors(java.util.stream.Collectors) EventPort(org.osate.aadl2.EventPort) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) LustreAstBuilder(com.rockwellcollins.atc.agree.analysis.translation.LustreAstBuilder) Node(jkind.lustre.Node) DataPort(org.osate.aadl2.DataPort) Property(org.osate.aadl2.Property) AgreeRenaming(com.rockwellcollins.atc.agree.analysis.AgreeRenaming) VarDecl(jkind.lustre.VarDecl) EventDataPort(org.osate.aadl2.EventDataPort) GuaranteeStatement(com.rockwellcollins.atc.agree.agree.GuaranteeStatement) AgreeASTBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeASTBuilder) ComponentImplementation(org.osate.aadl2.ComponentImplementation) GuaranteeStatement(com.rockwellcollins.atc.agree.agree.GuaranteeStatement) FeatureGroup(org.osate.aadl2.FeatureGroup) ComponentType(org.osate.aadl2.ComponentType) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) EventPort(org.osate.aadl2.EventPort) SystemImplementation(org.osate.aadl2.SystemImplementation) EObject(org.eclipse.emf.ecore.EObject) Arg(com.rockwellcollins.atc.agree.agree.Arg) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) AssertStatement(com.rockwellcollins.atc.agree.agree.AssertStatement) PropertyStatement(com.rockwellcollins.atc.agree.agree.PropertyStatement) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) EqStatement(com.rockwellcollins.atc.agree.agree.EqStatement) InputStatement(com.rockwellcollins.atc.agree.agree.InputStatement) EventDataPort(org.osate.aadl2.EventDataPort) Property(org.osate.aadl2.Property) ReachableStatement(com.rockwellcollins.atc.agree.agree.ReachableStatement)

Example 9 with EqStatement

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

the class EquationStatementHandler method validateName.

@Override
public Optional<String> validateName(final RenameContext ctx) {
    final EqStatement bo = ctx.getBusinessObject(EqStatement.class).get();
    final String[] names = getNames(ctx);
    for (int i = 0; i < names.length; i++) {
        final String name = names[i];
        if (i < bo.getLhs().size()) {
            final Optional<String> error = AgreeNamingUtil.validateName(bo.getLhs().get(0), name);
            if (error.isPresent()) {
                return error;
            }
        } else {
            if (!AgreeNamingUtil.isValidIdentifier(name)) {
                return Optional.of("'" + name + "' is not a valid identifier.");
            }
        }
    }
    return Optional.empty();
}
Also used : EqStatement(com.rockwellcollins.atc.agree.agree.EqStatement)

Example 10 with EqStatement

use of com.rockwellcollins.atc.agree.agree.EqStatement 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)

Aggregations

EqStatement (com.rockwellcollins.atc.agree.agree.EqStatement)11 SpecStatement (com.rockwellcollins.atc.agree.agree.SpecStatement)7 Arg (com.rockwellcollins.atc.agree.agree.Arg)6 InputStatement (com.rockwellcollins.atc.agree.agree.InputStatement)6 ArrayList (java.util.ArrayList)5 PrimType (com.rockwellcollins.atc.agree.agree.PrimType)4 ComponentType (org.osate.aadl2.ComponentType)4 AgreeContract (com.rockwellcollins.atc.agree.agree.AgreeContract)3 AgreeContractSubclause (com.rockwellcollins.atc.agree.agree.AgreeContractSubclause)3 AssumeStatement (com.rockwellcollins.atc.agree.agree.AssumeStatement)3 ConstStatement (com.rockwellcollins.atc.agree.agree.ConstStatement)3 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)3 EnumStatement (com.rockwellcollins.atc.agree.agree.EnumStatement)3 GetPropertyExpr (com.rockwellcollins.atc.agree.agree.GetPropertyExpr)3 GuaranteeStatement (com.rockwellcollins.atc.agree.agree.GuaranteeStatement)3 PropertyStatement (com.rockwellcollins.atc.agree.agree.PropertyStatement)3 ComponentImplementation (org.osate.aadl2.ComponentImplementation)3 NamedElement (org.osate.aadl2.NamedElement)3 Property (org.osate.aadl2.Property)3 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)2