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);
}
}
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;
}
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));
}
Aggregations