Search in sources :

Example 6 with DataTypeImpl

use of org.osate.aadl2.impl.DataTypeImpl in project AMASE by loonwerks.

the class SafetyValidator method checkInput.

/**
 * Checks fault def name is valid,
 * expressions passed into node match parameter types,
 * and correct number of arguments passed in.
 *
 * @param inputs
 */
@Check(CheckType.FAST)
public void checkInput(InputStatement inputs) {
    EObject container = inputs.eContainer();
    NamedElement defNameSub;
    List<Expr> exprList = inputs.getNom_conn();
    List<String> inputList = inputs.getFault_in();
    ArrayList<String> argNames = new ArrayList<String>();
    if (container instanceof FaultStatement) {
        FaultStatement faultStatement = (FaultStatement) container;
        DoubleDotRef defName = faultStatement.getFaultDefName();
        defNameSub = defName.getElm();
        // Make sure we have a NodeDefExpr
        if (defNameSub instanceof NodeDef) {
            List<Arg> nodeArgs = ((NodeDef) defNameSub).getArgs();
            for (Arg arg : nodeArgs) {
                argNames.add(arg.getFullName());
                if (arg.getType() instanceof DoubleDotRefImpl) {
                    if ((((DoubleDotRefImpl) arg.getType()).getElm() instanceof PropertyImpl) || (((DoubleDotRefImpl) arg.getType()).getElm() instanceof DataTypeImpl)) {
                        error(inputs, "Fault node parameters are not recognized: a possible issue is that the keyword 'float' is used instead of 'real.'");
                    }
                }
            }
            // If the sizes are accurate, make sure names match
            if (nodeArgs.size() - 1 == (inputList.size())) {
                // Go through input list and make sure each name is in the arg list
                for (String inputName : inputList) {
                    if (!argNames.contains(inputName)) {
                        error(inputs, "Input names must match fault node definition names. " + "The input name " + inputName + " is not an input in the node definition. " + "All possible input names are: " + argNames.toString());
                    }
                }
            } else {
                argNames.remove("trigger");
                error(inputs, "With this fault definition, you must have " + (argNames.size() - 1) + " inputs." + " These are called: " + argNames.toString());
            }
            if (inputListHasRepeats(inputList)) {
                error(inputs, "There is a repeated name in the input list: " + inputList.toString());
            }
            if (!checkInputTypes(exprList, nodeArgs)) {
                error(inputs, "Types of inputs do not match types of node parameters");
            }
        } else {
            // Not a node def expr
            error(defName, "Fault definition: " + defNameSub.getFullName() + " must be a valid agree node definition name.");
        }
    } else {
        error(inputs, "Fault inputs must be defined within a fault statement.");
    }
}
Also used : NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) ArrayList(java.util.ArrayList) FaultStatement(edu.umn.cs.crisys.safety.safety.FaultStatement) HWFaultStatement(edu.umn.cs.crisys.safety.safety.HWFaultStatement) PropertyImpl(org.osate.aadl2.impl.PropertyImpl) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) UnaryExpr(com.rockwellcollins.atc.agree.agree.UnaryExpr) Expr(com.rockwellcollins.atc.agree.agree.Expr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) DataTypeImpl(org.osate.aadl2.impl.DataTypeImpl) EObject(org.eclipse.emf.ecore.EObject) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) Arg(com.rockwellcollins.atc.agree.agree.Arg) DoubleDotRefImpl(com.rockwellcollins.atc.agree.agree.impl.DoubleDotRefImpl) NamedElement(org.osate.aadl2.NamedElement) Check(org.eclipse.xtext.validation.Check)

Example 7 with DataTypeImpl

use of org.osate.aadl2.impl.DataTypeImpl in project osate-plugin by sireum.

the class Visitor method processDataType.

public org.sireum.hamr.ir.Component processDataType(DataClassifier f) {
    final String name = f.getQualifiedName();
    if (datamap.containsKey(name)) {
        return datamap.get(name);
    }
    if (f.getExtended() != null) {
        Classifier c = f.getExtended();
        String parentName = c.getQualifiedName();
    // TODO: add extended classifier name to AIR nodes
    // System.out.println(parentName + " >> " + name);
    }
    /*
		 * need to use 'getAll...' in order to pickup properties inherited from parent
		 * since DataClassifier is coming from the declarative model (i.e. isn't flattened)
		 * javadoc for method:
		 * A list of the property associations. Property associations from
		 * an ancestor component classifier will appear before those of any
		 * descendents.
		 */
    List<PropertyAssociation> allProperties = VisitorUtil.toIList(f.getAllPropertyAssociations());
    List<org.sireum.hamr.ir.Component> subComponents = VisitorUtil.iList();
    if (f instanceof DataTypeImpl) {
    // do nothing as component types can't have subcomponents
    } else if (f instanceof DataImplementation) {
        final DataImplementation di = (DataImplementation) f;
        // the properties from the data component's type are not inherited by
        // the data component's implementation in the declarative model.
        // Add the data component type's properties before the data component
        // implemention's properties
        allProperties = VisitorUtil.addAll(di.getType().getAllPropertyAssociations(), allProperties);
        for (Subcomponent subcom : di.getAllSubcomponents()) {
            if (!(subcom instanceof DataSubcomponent)) {
                throw new RuntimeException("Unexpected data subcomponent: " + subcom.getFullName() + " of type " + subcom.getClass().getSimpleName() + " from " + f.getFullName());
            }
            DataSubcomponent dsc = (DataSubcomponent) subcom;
            final org.sireum.hamr.ir.Name subName = factory.name(VisitorUtil.toIList(dsc.getName()), VisitorUtil.buildPosInfo(dsc));
            final List<org.sireum.hamr.ir.Property> fProperties = dsc.getOwnedPropertyAssociations().stream().map(op -> buildProperty(op, VisitorUtil.iList())).collect(Collectors.toList());
            DataClassifier sct = null;
            if (dsc.getDataSubcomponentType() instanceof DataClassifier) {
                sct = (DataClassifier) dsc.getDataSubcomponentType();
            } else {
                if (dsc.getDataSubcomponentType() != null) {
                    String mesg = "Expecting a DataClassifier for " + dsc.qualifiedName() + " but found something of type " + dsc.getDataSubcomponentType().getClass().getSimpleName() + (dsc.getDataSubcomponentType().hasName() ? " whose name is " + dsc.getDataSubcomponentType().getQualifiedName() : "") + ". This can happen when your model has multiple copies of the same resource.";
                    throw new RuntimeException(mesg);
                }
            }
            if (sct != null) {
                final org.sireum.hamr.ir.Component c = processDataType(sct);
                final List<org.sireum.hamr.ir.Property> cProps = VisitorUtil.addAll(VisitorUtil.isz2IList(c.properties()), fProperties);
                final AadlASTJavaFactory.ComponentCategory category = AadlASTJavaFactory.ComponentCategory.valueOf(c.category().name());
                final org.sireum.hamr.ir.Classifier classifier = c.classifier().nonEmpty() ? c.classifier().get() : null;
                final org.sireum.hamr.ir.Component sub = factory.component(subName, category, classifier, VisitorUtil.isz2IList(c.features()), VisitorUtil.isz2IList(c.subComponents()), VisitorUtil.isz2IList(c.connections()), VisitorUtil.isz2IList(c.connectionInstances()), cProps, VisitorUtil.isz2IList(c.flows()), VisitorUtil.isz2IList(c.modes()), VisitorUtil.isz2IList(c.annexes()), VisitorUtil.getUriFragment(sct));
                subComponents = VisitorUtil.add(subComponents, sub);
            } else {
                // type not specified for subcomponent/field
                final org.sireum.hamr.ir.Component sub = // name
                factory.component(// name
                subName, // category
                AadlASTJavaFactory.ComponentCategory.Data, // classifier
                null, // features
                VisitorUtil.iList(), // subComponents
                VisitorUtil.iList(), // connections
                VisitorUtil.iList(), // connectionInstances
                VisitorUtil.iList(), // properties
                fProperties, // flows
                VisitorUtil.iList(), // modes
                VisitorUtil.iList(), // annexes
                VisitorUtil.iList(), "");
                subComponents = VisitorUtil.add(subComponents, sub);
            }
        }
    } else {
        throw new RuntimeException("Unexpected data type: " + f);
    }
    // NOTE there may be multiple properties associations with the same name if, e.g, a
    // data component extends Base_Type::Integer_32 but also adds the property
    // Data_Size => 16 bits. So would need to 'findLast' when processing these
    // ... so instead remove duplicates? Unless there is a reason why we'd want to
    // know the parent values of properties the child shadows
    List<PropertyAssociation> uniqueProperties = VisitorUtil.removeShadowedProperties(allProperties);
    List<org.sireum.hamr.ir.Property> properties = uniqueProperties.stream().map(op -> buildProperty(op, VisitorUtil.iList())).collect(Collectors.toList());
    List<Annex> annexes = new ArrayList<>();
    for (AnnexVisitor av : annexVisitors) {
        annexes.addAll(av.visit(f, new ArrayList<>()));
    }
    // this is a hack as we're sticking something from the declarative
    // model into a node meant for things from the instance model. Todo
    // would be to add a declarative model AIR AST and ...
    final org.sireum.hamr.ir.Component c = // 
    factory.component(// identifier
    factory.name(VisitorUtil.iList(), null), // category
    AadlASTJavaFactory.ComponentCategory.Data, // features
    factory.classifier(name), // features
    VisitorUtil.iList(), // connections
    subComponents, // connections
    VisitorUtil.iList(), // connectionInstances
    VisitorUtil.iList(), // properties
    properties, // flows
    VisitorUtil.iList(), // modes
    VisitorUtil.iList(), // annexes
    annexes, "");
    datamap.put(name, c);
    return c;
}
Also used : Arrays(java.util.Arrays) DataImplementation(org.osate.aadl2.DataImplementation) ListValue(org.osate.aadl2.ListValue) Element(org.osate.aadl2.Element) NamedValue(org.osate.aadl2.NamedValue) RangeValue(org.osate.aadl2.RangeValue) PropertyUtils(org.osate.xtext.aadl2.properties.util.PropertyUtils) PropertyExpression(org.osate.aadl2.PropertyExpression) AnnexLib(org.sireum.hamr.ir.AnnexLib) Classifier(org.osate.aadl2.Classifier) RecordValue(org.osate.aadl2.RecordValue) FeatureConnection(org.osate.aadl2.FeatureConnection) AccessImpl(org.osate.aadl2.impl.AccessImpl) Map(java.util.Map) ParameterConnection(org.osate.aadl2.ParameterConnection) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) Bundle(org.osgi.framework.Bundle) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral) Annex(org.sireum.hamr.ir.Annex) AccessConnection(org.osate.aadl2.AccessConnection) ConnectionEnd(org.osate.aadl2.ConnectionEnd) DirectedFeatureImpl(org.osate.aadl2.impl.DirectedFeatureImpl) FeatureCategory(org.osate.aadl2.instance.FeatureCategory) InstancePackage(org.osate.aadl2.instance.InstancePackage) FeatureGroupConnection(org.osate.aadl2.FeatureGroupConnection) BusAccessImpl(org.osate.aadl2.impl.BusAccessImpl) Set(java.util.Set) EObject(org.eclipse.emf.ecore.EObject) Connection(org.osate.aadl2.Connection) AadlASTJavaFactory(org.sireum.hamr.ir.AadlASTJavaFactory) Collectors(java.util.stream.Collectors) UnitLiteral(org.osate.aadl2.UnitLiteral) List(java.util.List) Property(org.osate.aadl2.Property) AccessType(org.osate.aadl2.AccessType) ReferenceValue(org.osate.aadl2.ReferenceValue) BusSubcomponentImpl(org.osate.aadl2.impl.BusSubcomponentImpl) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) StringLiteral(org.osate.aadl2.StringLiteral) Option(org.sireum.Option) Feature(org.osate.aadl2.Feature) HashMap(java.util.HashMap) Constructor(java.lang.reflect.Constructor) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) DataSubcomponent(org.osate.aadl2.DataSubcomponent) PropertyAssociation(org.osate.aadl2.PropertyAssociation) PreferenceValues(org.sireum.aadl.osate.PreferenceValues) DirectionType(org.osate.aadl2.DirectionType) Subcomponent(org.osate.aadl2.Subcomponent) Position(org.sireum.message.Position) FeatureGroup(org.osate.aadl2.FeatureGroup) NumberValue(org.osate.aadl2.NumberValue) FeatureGroupImpl(org.osate.aadl2.impl.FeatureGroupImpl) ClassifierValue(org.osate.aadl2.ClassifierValue) AadlUtil(org.osate.aadl2.modelsupport.util.AadlUtil) InstanceReferenceValue(org.osate.aadl2.instance.InstanceReferenceValue) Some(org.sireum.Some) PropertyConstant(org.osate.aadl2.PropertyConstant) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ModeTransitionInstance(org.osate.aadl2.instance.ModeTransitionInstance) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) FeatureGroupType(org.osate.aadl2.FeatureGroupType) PortConnection(org.osate.aadl2.PortConnection) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) DataTypeImpl(org.osate.aadl2.impl.DataTypeImpl) DataClassifier(org.osate.aadl2.DataClassifier) BooleanLiteral(org.osate.aadl2.BooleanLiteral) Platform(org.eclipse.core.runtime.Platform) NamedElement(org.osate.aadl2.NamedElement) FlowSpecificationInstance(org.osate.aadl2.instance.FlowSpecificationInstance) ConnectedElement(org.osate.aadl2.ConnectedElement) PropertyAssociation(org.osate.aadl2.PropertyAssociation) ArrayList(java.util.ArrayList) Classifier(org.osate.aadl2.Classifier) DataClassifier(org.osate.aadl2.DataClassifier) DataClassifier(org.osate.aadl2.DataClassifier) DataSubcomponent(org.osate.aadl2.DataSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) List(java.util.List) ArrayList(java.util.ArrayList) Property(org.osate.aadl2.Property) DataImplementation(org.osate.aadl2.DataImplementation) Annex(org.sireum.hamr.ir.Annex) DataTypeImpl(org.osate.aadl2.impl.DataTypeImpl) DataSubcomponent(org.osate.aadl2.DataSubcomponent)

Example 8 with DataTypeImpl

use of org.osate.aadl2.impl.DataTypeImpl in project VERDICT by ge-high-assurance.

the class Aadl2Vdm method createVdmPort.

/**
 * @author Vidhya Tekken Valapil
 * Creates a new Vdm Port object and returns
 * Populates "name", "mode" and "type"
 * @param dataport
 * @return vdm port
 */
private Port createVdmPort(DataPort dataPort, Model model, HashSet<String> dataTypeDecl) {
    String modeString = "in";
    if (dataPort.isIn()) {
        modeString = "in";
    } else if (dataPort.isOut()) {
        modeString = "out";
    }
    // fetching data type information
    DataSubcomponentType dSubCompType = dataPort.getDataFeatureClassifier();
    verdict.vdm.vdm_data.DataType dtype = new verdict.vdm.vdm_data.DataType();
    if (dSubCompType instanceof DataTypeImpl) {
        org.osate.aadl2.DataType aadlDType = (org.osate.aadl2.DataType) dSubCompType;
        dtype = resolveAADLDataType(aadlDType, model, dataTypeDecl);
    } else if (dSubCompType instanceof DataImplementationImpl) {
        org.osate.aadl2.DataImplementation aadlDImpl = (org.osate.aadl2.DataImplementation) dSubCompType;
        dtype = resolveAADLDataImplementationType(aadlDImpl, model, dataTypeDecl);
    } else {
        System.out.println("Unresolved/unexpected Named Element.");
    }
    verdict.vdm.vdm_model.Port newPort = new verdict.vdm.vdm_model.Port();
    newPort.setProbe(false);
    if (dataPort.getOwnedPropertyAssociations().size() != 0) {
        EList<PropertyAssociation> propertyAssocs = dataPort.getOwnedPropertyAssociations();
        for (PropertyAssociation propertyAssoc : propertyAssocs) {
            if (propertyAssoc.getProperty().getName().equalsIgnoreCase("probe")) {
                EList<ModalPropertyValue> propVals = propertyAssoc.getOwnedValues();
                if (propVals.size() == 0 || propVals.size() > 1) {
                    throw new RuntimeException("Unexpected number for values for probe property of port.");
                }
                if (propVals.get(0).getOwnedValue() instanceof BooleanLiteral) {
                    BooleanLiteral probeVal = (BooleanLiteral) propVals.get(0).getOwnedValue();
                    newPort.setProbe(probeVal.getValue());
                } else {
                    throw new RuntimeException("Unexpected type of value for probe property of port.");
                }
            }
        }
    }
    newPort.setId(dataPort.getQualifiedName());
    newPort.setName(dataPort.getName());
    newPort.setMode(convertToVdmPortMode(modeString));
    newPort.setType(dtype);
    return newPort;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) DataImplementationImpl(org.osate.aadl2.impl.DataImplementationImpl) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BooleanLiteral(org.osate.aadl2.BooleanLiteral) SLPort(com.ge.research.osate.verdict.dsl.verdict.SLPort) LPort(com.ge.research.osate.verdict.dsl.verdict.LPort) EventPort(org.osate.aadl2.EventPort) DataPort(org.osate.aadl2.DataPort) Port(verdict.vdm.vdm_model.Port) EventDataPort(org.osate.aadl2.EventDataPort) DataImplementation(org.osate.aadl2.DataImplementation) Port(verdict.vdm.vdm_model.Port) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) DataTypeImpl(org.osate.aadl2.impl.DataTypeImpl) DataType(org.osate.aadl2.DataType) DataType(org.osate.aadl2.DataType)

Example 9 with DataTypeImpl

use of org.osate.aadl2.impl.DataTypeImpl in project VERDICT by ge-high-assurance.

the class Aadl2Vdm method defineDataImplementationType.

/**
 * @author Vidhya Tekken Valapil
 * populate information related to data implementation types in the vdm
 */
private void defineDataImplementationType(DataImplementation dataImplementation, Model model, HashSet<String> dataTypeDecl) {
    // DEFINE DATA TYPE IN DECLARATIONS IF NOT ALREADY DEFINED
    String dataImplementationName = dataImplementation.getName();
    if (!dataTypeDecl.contains(dataImplementationName)) {
        dataTypeDecl.add(dataImplementationName);
        // vdm data type declaration
        TypeDeclaration dataTypeVdm = new TypeDeclaration();
        dataTypeVdm.setName(dataImplementationName);
        verdict.vdm.vdm_data.DataType dtype = new verdict.vdm.vdm_data.DataType();
        // GET DETAILS OF THE DATA IMPLEMENTATION AND CREATE CORRESPONDING VDM DATATYPE
        EList<DataSubcomponent> subcomponents = dataImplementation.getOwnedDataSubcomponents();
        if (!(subcomponents.isEmpty())) {
            // if the dataType definition has subcomponents
            RecordType recType = new RecordType();
            for (DataSubcomponent dataSubComp : subcomponents) {
                RecordField recField = new RecordField();
                recField.setName(dataSubComp.getName());
                DataSubcomponentType dataSubCompType = dataSubComp.getDataSubcomponentType();
                if (dataSubCompType instanceof org.osate.aadl2.DataType) {
                    org.osate.aadl2.DataType aadlDataType = (org.osate.aadl2.DataType) dataSubCompType;
                    Agree2Vdm agree2vdm = new Agree2Vdm();
                    verdict.vdm.vdm_data.DataType recFieldDtype = agree2vdm.getVdmTypeFromAADLType(aadlDataType);
                    recField.setType(recFieldDtype);
                    resolveAADLDataType(aadlDataType, model, dataTypeDecl);
                    recType.getRecordField().add(recField);
                } else if (dataSubCompType instanceof DataImplementation) {
                    DataImplementation dataSubCompDataImplementation = (DataImplementation) dataSubCompType;
                    verdict.vdm.vdm_data.DataType recFieldDtype = new verdict.vdm.vdm_data.DataType();
                    recFieldDtype.setUserDefinedType(dataSubCompDataImplementation.getName());
                    recField.setType(recFieldDtype);
                    defineDataImplementationType(dataSubCompDataImplementation, model, dataTypeDecl);
                    recType.getRecordField().add(recField);
                } else {
                    System.out.println("Unexpected Data Subcomponent that is not a DataTypeImpl or DataImplementatioImpl.");
                }
            }
            if (recType.getRecordField().size() != 0) {
                dtype.setRecordType(recType);
                dataTypeVdm.setDefinition(dtype);
            }
        } else {
            // if the dataType is base type boolean or integer or char or string
            System.out.println("Data implementation type has no subcomponents");
        }
        // add the typeDeclaration to the model
        model.getTypeDeclaration().add(dataTypeVdm);
    }
}
Also used : RecordField(verdict.vdm.vdm_data.RecordField) DataImplementation(org.osate.aadl2.DataImplementation) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) RecordType(verdict.vdm.vdm_data.RecordType) DataSubcomponent(org.osate.aadl2.DataSubcomponent) DataType(org.osate.aadl2.DataType) TypeDeclaration(verdict.vdm.vdm_data.TypeDeclaration) DataType(org.osate.aadl2.DataType)

Aggregations

DataImplementation (org.osate.aadl2.DataImplementation)7 DataTypeImpl (org.osate.aadl2.impl.DataTypeImpl)7 DataSubcomponentType (org.osate.aadl2.DataSubcomponentType)5 DataPort (org.osate.aadl2.DataPort)4 DataSubcomponent (org.osate.aadl2.DataSubcomponent)4 DataType (org.osate.aadl2.DataType)4 EventDataPort (org.osate.aadl2.EventDataPort)4 EventPort (org.osate.aadl2.EventPort)4 LPort (com.ge.research.osate.verdict.dsl.verdict.LPort)3 SLPort (com.ge.research.osate.verdict.dsl.verdict.SLPort)3 DataImplementationImpl (org.osate.aadl2.impl.DataImplementationImpl)3 Arg (com.rockwellcollins.atc.agree.agree.Arg)2 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)2 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)2 Expr (com.rockwellcollins.atc.agree.agree.Expr)2 IntLitExpr (com.rockwellcollins.atc.agree.agree.IntLitExpr)2 NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)2 NodeDef (com.rockwellcollins.atc.agree.agree.NodeDef)2 RealLitExpr (com.rockwellcollins.atc.agree.agree.RealLitExpr)2 UnaryExpr (com.rockwellcollins.atc.agree.agree.UnaryExpr)2