| |
---|
| | |
---|
| | import java.util.ArrayList; |
---|
| | |
---|
| | import code.ast.Block; |
---|
| | import code.ast.CompilationUnit; |
---|
| | import code.ast.FieldDeclaration; |
---|
| | import code.ast.MethodDeclaration; |
---|
| | import code.ast.TypeDeclaration; |
---|
| | import code.ast.VariableDeclaration; |
---|
| |
---|
| | import models.dataFlowModel.StoreAttribute; |
---|
| | |
---|
| | public class CodeGenerator { |
---|
| | public static final Type typeVoid = new Type("Void", "void"); |
---|
| | |
---|
| | static public ArrayList<TypeDeclaration> doGenerate(ResourceDependencyGraph graph, DataFlowModel model) { |
---|
| | ArrayList<TypeDeclaration> codes = new ArrayList<>(); |
---|
| | public static String mainTypeName = "Main"; |
---|
| | |
---|
| | static public ArrayList<CompilationUnit> doGenerate(ResourceDependencyGraph graph, DataFlowModel model) { |
---|
| | ArrayList<CompilationUnit> codes = new ArrayList<>(); |
---|
| | ArrayList<ResourceNode> resources = StoreResourceCheck(graph); |
---|
| | |
---|
| | codes.add(new TypeDeclaration("Main")); |
---|
| | |
---|
| | TypeDeclaration mainType = new TypeDeclaration(mainTypeName); |
---|
| | codes.add(new CompilationUnit(mainType)); |
---|
| | for (ResourceNode rn : resources) { |
---|
| | boolean f = false; |
---|
| | String name = rn.getIdentifierTemplate().getResourceName().substring(0, 1).toUpperCase() |
---|
| | + rn.getIdentifierTemplate().getResourceName().substring(1); |
---|
| |
---|
| | consstr = consstr.substring(0, consstr.length() - 1); |
---|
| | consstr += ")"; |
---|
| | FieldDeclaration field = new FieldDeclaration(new Type(name, name), |
---|
| | rn.getIdentifierTemplate().getResourceName(), consstr); |
---|
| | codes.get(0).addField(field); |
---|
| | mainType.addField(field); |
---|
| | MethodDeclaration cons = new MethodDeclaration(name, true); |
---|
| | Block block = new Block(); |
---|
| | for (Edge e : rn.getOutEdges()) { |
---|
| | ResourceDependency re = (ResourceDependency) e; |
---|
| |
---|
| | type.addMethod(io); |
---|
| | io = new MethodDeclaration( |
---|
| | ((Term) cm.getStateTransition().getMessageExpression()).getSymbol().getImplName(), |
---|
| | false, typeVoid, params); |
---|
| | codes.get(0).addMethod(io); |
---|
| | mainType.addMethod(io); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| |
---|
| | rn.getIdentifierTemplate().getResourceName(), str)); |
---|
| | } |
---|
| | type.addMethod(new MethodDeclaration("get" + type.getTypeName(), |
---|
| | rn.getIdentifierTemplate().getResourceStateType())); |
---|
| | codes.add(type); |
---|
| | codes.add(new CompilationUnit(type)); |
---|
| | } |
---|
| | for (Node n : graph.getNodes()) { |
---|
| | ResourceNode rn = (ResourceNode) n; |
---|
| | MethodDeclaration get = new MethodDeclaration( |
---|
| |
---|
| | rn.getIdentifierTemplate().getResourceStateType()); |
---|
| | get.setBody(new Block()); |
---|
| | get.getBody().addStatement( |
---|
| | "return " + rn.getIdentifierTemplate().getResourceName() + "." + get.getName() + "();"); |
---|
| | codes.get(0).addMethod(get); |
---|
| | mainType.addMethod(get); |
---|
| | } |
---|
| | return codes; |
---|
| | } |
---|
| | |
---|
| |
---|
| | ArrayList<String> codes = new ArrayList<>(); |
---|
| | for (TypeDeclaration type : codeTree) { |
---|
| | codes.add("public class " + type.getTypeName() + "{"); |
---|
| | for (FieldDeclaration field : type.getFields()) { |
---|
| | if (type.getTypeName() != "Main") { |
---|
| | if (type.getTypeName() != mainTypeName) { |
---|
| | String cons = "\t" + "private " + field.getType().getImplementationTypeName() + " " |
---|
| | + field.getName(); |
---|
| | if (field.getType().equals(DataConstraintModel.typeList)) |
---|
| | cons += " = new ArrayList<>()"; |
---|
| |
---|
| | codes.add(cons); |
---|
| | } |
---|
| | } |
---|
| | codes.add(""); |
---|
| | if (type.getTypeName() != "Main") { |
---|
| | if (type.getTypeName() != mainTypeName) { |
---|
| | if (!type.getConstructors().isEmpty()) { |
---|
| | String cons = "\t" + "public " + type.getTypeName() + "("; |
---|
| | for (VariableDeclaration constructor : type.getConstructors()) { |
---|
| | cons += constructor.getType().getTypeName() + " " + constructor.getName() + ","; |
---|
| |
---|
| | |