use of com.rockwellcollins.atc.agree.analysis.ast.AgreeNode 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 com.rockwellcollins.atc.agree.analysis.ast.AgreeNode in project AGREE by loonwerks.
the class CreateLocalVariablesForPropertyExpressions method transform.
public static SimulationProgram transform(final SimulationProgram program) {
final Program lustreProgram = program.getLustreProgram();
final SimulationProgramBuilder builder = new SimulationProgramBuilder(program);
// Build mappings between Agree Statements, expressions, and Agree Nodes
final Map<Expr, AgreeStatement> exprToStatementMap = new HashMap<>();
final Map<AgreeStatement, AgreeNode> agreeStatementToAgreeNodeMap = new HashMap<>();
for (final AgreeNode agreeNode : program.getAllAgreeNodes()) {
for (final AgreeStatement statement : agreeNode.assertions) {
if (statement.reference instanceof AssertStatement) {
exprToStatementMap.put(statement.expr, statement);
agreeStatementToAgreeNodeMap.put(statement, agreeNode);
}
}
for (final AgreeStatement statement : agreeNode.assumptions) {
exprToStatementMap.put(statement.expr, statement);
agreeStatementToAgreeNodeMap.put(statement, agreeNode);
}
for (final AgreeStatement statement : agreeNode.guarantees) {
exprToStatementMap.put(statement.expr, statement);
agreeStatementToAgreeNodeMap.put(statement, agreeNode);
}
}
// Create local variables for assert statements, assumptions, and guarantees
final ProgramBuilder lustreBuilder = new ProgramBuilder(lustreProgram).clearNodes();
for (final Node lustreNode : lustreProgram.nodes) {
lustreBuilder.addNode(VariableCreator.transform(lustreNode, exprToStatementMap, agreeStatementToAgreeNodeMap));
}
builder.setLustreProgram(lustreBuilder.build());
return builder.build();
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeNode 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 com.rockwellcollins.atc.agree.analysis.ast.AgreeNode in project AGREE by loonwerks.
the class AgreeASTPrettyprinter method visit.
@Override
public Void visit(AgreeProgram program) {
if (program.containsRealTimePatterns) {
write("-- Program contains real-time patterns");
newline();
newline();
}
write("-- Program top-level node is: " + program.topNode.id);
newline();
newline();
if (!program.globalTypes.isEmpty()) {
for (Type type : program.globalTypes) {
String name = "dummy";
if (type instanceof RecordType) {
name = ((RecordType) type).id;
} else if (type instanceof EnumType) {
name = ((EnumType) type).id;
}
TypeDef typeDef = new TypeDef(Location.NULL, name, type);
typeDef.accept(this);
newline();
}
newline();
}
if (!program.globalLustreNodes.isEmpty()) {
Iterator<Node> iterator = program.globalLustreNodes.iterator();
while (iterator.hasNext()) {
iterator.next().accept(this);
newline();
if (iterator.hasNext()) {
newline();
}
}
newline();
}
if (!program.uninterpretedFunctions.isEmpty()) {
Iterator<Function> iterator = program.uninterpretedFunctions.iterator();
while (iterator.hasNext()) {
iterator.next().accept(this);
newline();
if (iterator.hasNext()) {
newline();
}
}
newline();
}
Iterator<AgreeNode> iterator = program.agreeNodes.iterator();
while (iterator.hasNext()) {
iterator.next().accept(this);
newline();
if (iterator.hasNext()) {
newline();
}
}
newline();
return null;
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeNode in project AGREE by loonwerks.
the class AgreeASTPrettyprinter method visit.
@Override
public Void visit(AgreeNode node) {
write("agree node ");
write(node.id);
write("(");
newline();
agreeVarDecls(node.inputs);
newline();
write(") returns (");
newline();
agreeVarDecls(node.outputs);
newline();
write(");");
newline();
if (!node.locals.isEmpty()) {
write("var");
newline();
agreeVarDecls(node.locals);
write(";");
newline();
}
if (node.id.equals(main)) {
write(" --%MAIN;");
newline();
}
write("let");
newline();
if (!node.connections.isEmpty()) {
for (AgreeConnection connection : node.connections) {
connection(connection);
}
newline();
}
write(" children {");
for (AgreeNode subNode : node.subNodes) {
write(subNode.id);
write(" ");
}
write(" }");
newline();
newline();
statementList("assertions", node.assertions);
statementList("assumptions", node.assumptions);
statementList("guarantees", node.guarantees);
statementList("lemmas", node.lemmas);
statementList("pattern props", node.patternProps);
for (AgreeEquation equation : node.localEquations) {
write(" ");
visit(equation);
newline();
newline();
}
if (node.clockConstraint != null) {
write(" clock constraint: ");
node.clockConstraint.accept(this);
newline();
}
if (node.initialConstraint != null) {
write(" initial constraint: ");
node.initialConstraint.accept(this);
newline();
}
if (node.clockVar != null) {
write(" clock variable: ");
visit(node.clockVar);
newline();
}
write(" timing model: " + node.timing);
newline();
write(" -- TBD: event models to go along with timing model");
newline();
newline();
write("tel;");
return null;
}
Aggregations