use of verdict.vdm.vdm_lustre.NodeParameter in project VERDICT by ge-high-assurance.
the class Agree2Vdm method addNodeDefToTypeDeclarations.
private void addNodeDefToTypeDeclarations(NodeDef nodeDef, HashSet<String> dataTypeDecl, HashSet<String> nodeDecl, Model model) {
Node vdmNode = new Node();
// String agreeNodeName = nodeDef.getName();
String agreeNodeName = nodeDef.getQualifiedName();
vdmNode.setName(agreeNodeName);
// SETTING NODE INPUT PARAMETERS
// get agree node's args and set them as input parameter
EList<Arg> nodeInpArgs = nodeDef.getArgs();
for (Arg arg : nodeInpArgs) {
NodeParameter nodeParameter = new NodeParameter();
nodeParameter.setName(arg.getName());
// get types of each arg and define those types if needed -- will be done in getVdmTypeFromAgreeType()
nodeParameter.setDataType(getVdmTypeFromAgreeType(arg.getType(), dataTypeDecl, model));
vdmNode.getInputParameter().add(nodeParameter);
}
// SETTING NODE OUTPUT PARAMETERS
EList<Arg> nodeReturnArgs = nodeDef.getRets();
// get agree node's rets and set them as output parameter
for (Arg arg : nodeReturnArgs) {
NodeParameter nodeParameter = new NodeParameter();
nodeParameter.setName(arg.getName());
// get types of each arg and define those types if needed -- will be done in getVdmTypeFromAgreeType()
nodeParameter.setDataType(getVdmTypeFromAgreeType(arg.getType(), dataTypeDecl, model));
vdmNode.getOutputParameter().add(nodeParameter);
}
// SETTING NODE BODY
NodeBody vdmNodeBody = new NodeBody();
// get agree node's body
NodeBodyExpr agreeNodeBody = nodeDef.getNodeBody();
EList<NodeStmt> agreeNodeStmts = agreeNodeBody.getStmts();
for (NodeStmt agreeNodeStmt : agreeNodeStmts) {
if (agreeNodeStmt instanceof NodeEqImpl) {
NodeEq agreeNodeEq = (NodeEq) agreeNodeStmt;
// get all LHS identifiers in the statement and add it to the vdm node equation LHS
NodeEquation vdmNodeEquation = new NodeEquation();
EList<Arg> agreeLHSArgs = agreeNodeEq.getLhs();
// this type is just a list of strings
NodeEquationLHS vdmNodeEquationLHS = new NodeEquationLHS();
for (Arg agreeLHSArg : agreeLHSArgs) {
vdmNodeEquationLHS.getIdentifier().add(agreeLHSArg.getName());
}
vdmNodeEquation.setLhs(vdmNodeEquationLHS);
// get the RHS i.e.expr of the agree NodeEq and set it as the vdm node equation's RHS
vdmNodeEquation.setRhs(getVdmExpressionFromAgreeExpression(agreeNodeEq.getExpr(), dataTypeDecl, nodeDecl, model));
vdmNodeBody.getEquation().add(vdmNodeEquation);
} else {
System.out.println("Node contains non-eq type statements");
}
}
vdmNode.setBody(vdmNodeBody);
vdmNode.setIsFunction(false);
vdmNode.setIsImported(false);
if (!nodeDecl.contains(agreeNodeName)) {
nodeDecl.add(agreeNodeName);
LustreProgram lustreProgram = model.getDataflowCode();
lustreProgram.getNodeDeclaration().add(vdmNode);
model.setDataflowCode(lustreProgram);
}
}
Aggregations