Search in sources :

Example 1 with SimulationVariable

use of edu.uah.rsesc.aadlsimulator.agree.SimulationVariable in project AGREE by loonwerks.

the class AgreeProgramToSimulationProgram method populateMetadata.

private static void populateMetadata(final SimulationProgramBuilder builder, final AgreeProgram agreeProgram, final Program lustreProgram, final AgreeRenaming agreeRenaming, final Map<String, EObject> refMap) {
    // Exclude inputs that are used internally by AGREE.
    for (final VarDecl vd : lustreProgram.getMainNode().inputs) {
        if (vd instanceof AgreeVar) {
            final AgreeVar agreeVar = (AgreeVar) vd;
            if (agreeVar.compInst != null) {
                final FeatureInstance featureInstance = agreeVar.featInst;
                // Use the name as provided by the instance object path unless it is not available
                final String variableName;
                if (featureInstance != null) {
                    variableName = featureInstance.getFullName();
                } else {
                    final String[] idSegs = vd.id.split("__");
                    variableName = idSegs[idSegs.length - 1];
                }
                builder.addSimulationVariable(new SimulationVariable(agreeVar.compInst, variableName, vd.id, vd.type, featureInstance, agreeVar.reference));
            }
        }
    }
    // Add mappings from component instances to agree nodes
    builder.addMapping(agreeProgram.topNode.compInst, agreeProgram.topNode);
    for (final AgreeNode n : agreeProgram.agreeNodes) {
        builder.addMapping(n.compInst, n);
    }
}
Also used : AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) VarDecl(jkind.lustre.VarDecl) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) SimulationVariable(edu.uah.rsesc.aadlsimulator.agree.SimulationVariable)

Example 2 with SimulationVariable

use of edu.uah.rsesc.aadlsimulator.agree.SimulationVariable in project AGREE by loonwerks.

the class AGREESimulationStateElementFactory method createVariableStateElements.

private static List<AGREESimulationStateElement> createVariableStateElements(final AGREESimulationStateElement parent, final SimulationProgramType programType, final ComponentInstance componentInstance, final TimingModel parentTimingModel, final Map<ComponentInstance, Collection<SimulationVariable>> componentInstanceToVariablesMap, final Map<String, jkind.lustre.Type> typeIdToTypeMap, final Map<ComponentInstance, AgreeNode> componentInstanceToAgreeNodeMap, boolean includeSubcomponents) {
    assert componentInstance != null;
    assert componentInstanceToVariablesMap != null;
    assert typeIdToTypeMap != null;
    final List<AGREESimulationStateElement> elements = new ArrayList<AGREESimulationStateElement>();
    // Get the timing model for the component instance
    final AgreeNode agreeNode = componentInstanceToAgreeNodeMap.get(componentInstance);
    final TimingModel timingModel = agreeNode == null ? null : agreeNode.timing;
    // Create elements for subcomponents
    if (includeSubcomponents) {
        for (final ComponentInstance child : componentInstance.getComponentInstances()) {
            final AGREESimulationStateElement newElement = new AGREESimulationStateElement(parent, child.getFullName(), edu.uah.rsesc.aadlsimulator.VariableType.NONE, null, child, child.getSubcomponent(), false);
            newElement.setChildren(createVariableStateElements(newElement, programType, child, timingModel, componentInstanceToVariablesMap, typeIdToTypeMap, componentInstanceToAgreeNodeMap, programType.isMonolithic()));
            elements.add(newElement);
        }
    }
    // Create elements for simulation variables
    final Collection<SimulationVariable> variables = componentInstanceToVariablesMap.get(componentInstance);
    if (variables != null) {
        final boolean showClockVariables = parentTimingModel == TimingModel.ASYNC;
        for (SimulationVariable var : variables) {
            final boolean isClock = var.getLustreId().endsWith(AgreeASTBuilder.clockIDSuffix);
            boolean hidden = (var.getLustreId().contains("___") || var.getLustreId().startsWith("_")) && (!isClock || !showClockVariables);
            addChildElementsForVariable(elements, parent, var.getName(), var.getType(), new IdExpr(var.getLustreId()), typeIdToTypeMap, var.getFeatureInstance(), var.getDeclarativeReference(), hidden);
        }
    }
    return elements;
}
Also used : AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) IdExpr(jkind.lustre.IdExpr) TimingModel(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode.TimingModel) ArrayList(java.util.ArrayList) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) SimulationVariable(edu.uah.rsesc.aadlsimulator.agree.SimulationVariable)

Example 3 with SimulationVariable

use of edu.uah.rsesc.aadlsimulator.agree.SimulationVariable in project AGREE by loonwerks.

the class AGREESimulationStateElementFactory method createStateElements.

/**
 * Creates and returns the root state elements for a specified simulation program.
 * @param program
 * @return
 */
public static List<AGREESimulationStateElement> createStateElements(final SimulationProgram program) {
    Objects.requireNonNull(program, "program must not be null");
    // Build a component instance to simulation variable collection map
    final Map<ComponentInstance, Collection<SimulationVariable>> componentInstanceToVariablesMap = new HashMap<ComponentInstance, Collection<SimulationVariable>>();
    for (final SimulationVariable var : program.getVariables()) {
        if (!componentInstanceToVariablesMap.containsKey(var.getComponentInstance())) {
            componentInstanceToVariablesMap.put(var.getComponentInstance(), new ArrayList<SimulationVariable>());
        }
        componentInstanceToVariablesMap.get(var.getComponentInstance()).add(var);
    }
    // Build a type id to type map
    final Map<String, jkind.lustre.Type> typeIdToTypeMap = new HashMap<String, jkind.lustre.Type>();
    for (final TypeDef typeDef : program.getLustreProgram().types) {
        typeIdToTypeMap.put(typeDef.id, typeDef.type);
    }
    return Collections.unmodifiableList(createVariableStateElements(null, program.getType(), program.getComponentInstance(), null, componentInstanceToVariablesMap, typeIdToTypeMap, program.getComponentInstanceToAgreeNodeMap(), true));
}
Also used : SimulationProgramType(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramType) RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) ArrayType(jkind.lustre.ArrayType) TypeDef(jkind.lustre.TypeDef) HashMap(java.util.HashMap) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) Collection(java.util.Collection) SimulationVariable(edu.uah.rsesc.aadlsimulator.agree.SimulationVariable)

Aggregations

SimulationVariable (edu.uah.rsesc.aadlsimulator.agree.SimulationVariable)3 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)2 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)2 TimingModel (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode.TimingModel)1 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)1 SimulationProgramType (edu.uah.rsesc.aadlsimulator.agree.SimulationProgramType)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 ArrayType (jkind.lustre.ArrayType)1 IdExpr (jkind.lustre.IdExpr)1 NamedType (jkind.lustre.NamedType)1 RecordType (jkind.lustre.RecordType)1 Type (jkind.lustre.Type)1 TypeDef (jkind.lustre.TypeDef)1 VarDecl (jkind.lustre.VarDecl)1 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)1