Skip to content
Snippets Groups Projects
Commit 38f37081 authored by Johannes Mey's avatar Johannes Mey
Browse files

add option to rename list class. this made it much easier to use the generator...

add option to rename list class. this made it much easier to use the generator in the train benchmark.
parent e455e10b
No related branches found
No related tags found
No related merge requests found
aspect BackendAbstractGrammar { aspect BackendAbstractGrammar {
public static String ASTNode.listClass = "ArrayList";
public String Program.generateAbstractGrammar() { public String Program.generateAbstractGrammar() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
generateAbstractGrammar(sb); generateAbstractGrammar(sb);
...@@ -56,7 +59,7 @@ aspect BackendAbstractGrammar { ...@@ -56,7 +59,7 @@ aspect BackendAbstractGrammar {
return "<" + getImplAttributeName() + ":" + ofTypeDecl() + ">"; return "<" + getImplAttributeName() + ":" + ofTypeDecl() + ">";
} }
public String ManyRelationComponent.generateAbstractGrammar() { public String ManyRelationComponent.generateAbstractGrammar() {
return "<" + getImplAttributeName() + ":ArrayList<" + ofTypeDecl() + ">>"; return "<" + getImplAttributeName() + ":" + ASTNode.listClass + "<" + ofTypeDecl() + ">>";
} }
public String RelationComponent.getImplAttributeName() { public String RelationComponent.getImplAttributeName() {
...@@ -184,9 +187,9 @@ aspect BackendDirectedAPI { ...@@ -184,9 +187,9 @@ aspect BackendDirectedAPI {
sb.append(ind(1) + "public void " + toTypeDecl() + ".addTo"); sb.append(ind(1) + "public void " + toTypeDecl() + ".addTo");
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n"); sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n"); sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + "ArrayList<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
sb.append(ind(2) + "if (list == null) {\n"); sb.append(ind(2) + "if (list == null) {\n");
sb.append(ind(3) + "list = new ArrayList<>();\n"); sb.append(ind(3) + "list = new " + ASTNode.listClass + "<>();\n");
sb.append(ind(2) + "}\n"); sb.append(ind(2) + "}\n");
sb.append(ind(2) + "list.add(o);\n"); sb.append(ind(2) + "list.add(o);\n");
sb.append(ind(2) + "set" + getImplAttributeName() + "(list);\n"); sb.append(ind(2) + "set" + getImplAttributeName() + "(list);\n");
...@@ -196,7 +199,7 @@ aspect BackendDirectedAPI { ...@@ -196,7 +199,7 @@ aspect BackendDirectedAPI {
sb.append(ind(1) + "public void " + toTypeDecl() + ".removeFrom"); sb.append(ind(1) + "public void " + toTypeDecl() + ".removeFrom");
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n"); sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n"); sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + "ArrayList<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
sb.append(ind(2) + "if (list != null && list.remove(o)) {\n"); sb.append(ind(2) + "if (list != null && list.remove(o)) {\n");
sb.append(ind(3) + "set" + getImplAttributeName() + "(list);\n"); sb.append(ind(3) + "set" + getImplAttributeName() + "(list);\n");
sb.append(ind(2) + "}\n"); sb.append(ind(2) + "}\n");
...@@ -227,7 +230,7 @@ aspect BackendDirectedAPI { ...@@ -227,7 +230,7 @@ aspect BackendDirectedAPI {
public void RelationComponent.generateGetMany(StringBuilder sb) { public void RelationComponent.generateGetMany(StringBuilder sb) {
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl()); sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append("." + name() + "() {\n"); sb.append("." + name() + "() {\n");
sb.append(ind(2) + "ArrayList<" + ofTypeDecl() + "> l = get" sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> l = get"
+ getImplAttributeName() + "();\n"); + getImplAttributeName() + "();\n");
sb.append(ind(2) + "return l != null ? Collections.unmodifiableList(l) : Collections.emptyList();\n"); sb.append(ind(2) + "return l != null ? Collections.unmodifiableList(l) : Collections.emptyList();\n");
sb.append(ind(1) + "}\n"); sb.append(ind(1) + "}\n");
...@@ -314,14 +317,14 @@ aspect BackendBidirectionalAPI { ...@@ -314,14 +317,14 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "public void " + toTypeDecl() + ".addTo"); sb.append(ind(1) + "public void " + toTypeDecl() + ".addTo");
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n"); sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n"); sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + "ArrayList<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
sb.append(ind(2) + "if (list == null) {\n"); sb.append(ind(2) + "if (list == null) {\n");
sb.append(ind(3) + "list = new ArrayList<>();\n"); sb.append(ind(3) + "list = new " + ASTNode.listClass + "<>();\n");
sb.append(ind(2) + "}\n"); sb.append(ind(2) + "}\n");
sb.append(ind(2) + "ArrayList<" + otherSide().ofTypeDecl() + "> list2 = o.get" sb.append(ind(2) + ASTNode.listClass + "<" + otherSide().ofTypeDecl() + "> list2 = o.get"
+ otherSide().getImplAttributeName() + "();\n"); + otherSide().getImplAttributeName() + "();\n");
sb.append(ind(2) + "if (list2 == null) {\n"); sb.append(ind(2) + "if (list2 == null) {\n");
sb.append(ind(3) + "list2 = new ArrayList<>();\n"); sb.append(ind(3) + "list2 = new "+ ASTNode.listClass + "<>();\n");
sb.append(ind(2) + "}\n"); sb.append(ind(2) + "}\n");
sb.append(ind(2) + "list.add(o);\n"); sb.append(ind(2) + "list.add(o);\n");
sb.append(ind(2) + "list2.add(this);\n"); sb.append(ind(2) + "list2.add(this);\n");
...@@ -333,9 +336,9 @@ aspect BackendBidirectionalAPI { ...@@ -333,9 +336,9 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "public void " + toTypeDecl() + ".removeFrom"); sb.append(ind(1) + "public void " + toTypeDecl() + ".removeFrom");
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n"); sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n"); sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + "ArrayList<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
sb.append(ind(2) + "if (list != null && list.remove(o)) {\n"); sb.append(ind(2) + "if (list != null && list.remove(o)) {\n");
sb.append(ind(3) + "ArrayList<" + otherSide().ofTypeDecl() + "> list2 = o.get" sb.append(ind(3) + ASTNode.listClass + "<" + otherSide().ofTypeDecl() + "> list2 = o.get"
+ otherSide().getImplAttributeName() + "();\n"); + otherSide().getImplAttributeName() + "();\n");
sb.append(ind(3) + "if (list2 != null) list2.remove(this);\n"); sb.append(ind(3) + "if (list2 != null) list2.remove(this);\n");
sb.append(ind(3) + "set" + getImplAttributeName() + "(list);\n"); sb.append(ind(3) + "set" + getImplAttributeName() + "(list);\n");
...@@ -354,15 +357,15 @@ aspect BackendBidirectionalAPI { ...@@ -354,15 +357,15 @@ aspect BackendBidirectionalAPI {
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n"); sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n"); sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + "if (o != null && o.get" + otherSide().getImplAttributeName() + "() != null) {\n"); sb.append(ind(2) + "if (o != null && o.get" + otherSide().getImplAttributeName() + "() != null) {\n");
sb.append(ind(3) + "ArrayList<" + ofTypeDecl() + "> list2 = o.get" sb.append(ind(3) + ASTNode.listClass + "<" + ofTypeDecl() + "> list2 = o.get"
+ otherSide().getImplAttributeName() + "().get" + getImplAttributeName() + "();\n"); + otherSide().getImplAttributeName() + "().get" + getImplAttributeName() + "();\n");
sb.append(ind(3) + "if (list2.remove(o))\n"); sb.append(ind(3) + "if (list2.remove(o))\n");
sb.append(ind(4) + "o.get" + otherSide().getImplAttributeName() sb.append(ind(4) + "o.get" + otherSide().getImplAttributeName()
+ "().set" + getImplAttributeName() + "(list2);\n"); + "().set" + getImplAttributeName() + "(list2);\n");
sb.append(ind(2) + "}\n"); sb.append(ind(2) + "}\n");
sb.append(ind(2) + "ArrayList<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
sb.append(ind(2) + "if (list == null) {\n"); sb.append(ind(2) + "if (list == null) {\n");
sb.append(ind(3) + "list = new ArrayList<>();\n"); sb.append(ind(3) + "list = new " + ASTNode.listClass + "<>();\n");
sb.append(ind(2) + "}\n"); sb.append(ind(2) + "}\n");
sb.append(ind(2) + "list.add(o);\n"); sb.append(ind(2) + "list.add(o);\n");
sb.append(ind(2) + "set" + getImplAttributeName() + "(list);\n"); sb.append(ind(2) + "set" + getImplAttributeName() + "(list);\n");
...@@ -373,7 +376,7 @@ aspect BackendBidirectionalAPI { ...@@ -373,7 +376,7 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "public void " + toTypeDecl() + ".removeFrom"); sb.append(ind(1) + "public void " + toTypeDecl() + ".removeFrom");
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n"); sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n"); sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + "ArrayList<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n"); sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
sb.append(ind(2) + "if (list != null && list.remove(o)) {\n"); sb.append(ind(2) + "if (list != null && list.remove(o)) {\n");
sb.append(ind(3) + "set" + getImplAttributeName() + "(list);\n"); sb.append(ind(3) + "set" + getImplAttributeName() + "(list);\n");
sb.append(ind(3) + "if (o.get" + otherSide().getImplAttributeName() + "() == this) {\n"); sb.append(ind(3) + "if (o.get" + otherSide().getImplAttributeName() + "() == this) {\n");
...@@ -394,7 +397,7 @@ aspect BackendBidirectionalAPI { ...@@ -394,7 +397,7 @@ aspect BackendBidirectionalAPI {
sb.append(ind(2) + "assertNotNull(o);\n"); sb.append(ind(2) + "assertNotNull(o);\n");
} }
sb.append(ind(2) + "if (get" + getImplAttributeName() + "() != null) {\n"); sb.append(ind(2) + "if (get" + getImplAttributeName() + "() != null) {\n");
sb.append(ind(3) + "ArrayList<" + toTypeDecl() + "> list2 = get" + getImplAttributeName() sb.append(ind(3) + ASTNode.listClass + "<" + toTypeDecl() + "> list2 = get" + getImplAttributeName()
+ "()." + "get" + otherSide().getImplAttributeName() + "();\n"); + "()." + "get" + otherSide().getImplAttributeName() + "();\n");
sb.append(ind(3) + "list2.remove(this);\n"); sb.append(ind(3) + "list2.remove(this);\n");
sb.append(ind(3) + "get" + getImplAttributeName() + "()." + "set" sb.append(ind(3) + "get" + getImplAttributeName() + "()." + "set"
...@@ -406,10 +409,10 @@ aspect BackendBidirectionalAPI { ...@@ -406,10 +409,10 @@ aspect BackendBidirectionalAPI {
if (isOpt) { if (isOpt) {
sb.append(ind(2) + "if (o != null) {\n"); sb.append(ind(2) + "if (o != null) {\n");
} }
sb.append(ind(ind) + "ArrayList<" + toTypeDecl() + "> list = o.get" sb.append(ind(ind) + ASTNode.listClass + "<" + toTypeDecl() + "> list = o.get"
+ otherSide().getImplAttributeName() + "();\n"); + otherSide().getImplAttributeName() + "();\n");
sb.append(ind(ind) + "if (list == null) {\n"); sb.append(ind(ind) + "if (list == null) {\n");
sb.append(ind(ind+1) + "list = new ArrayList<>();\n"); sb.append(ind(ind+1) + "list = new " + ASTNode.listClass + "<>();\n");
sb.append(ind(ind) + "}\n"); sb.append(ind(ind) + "}\n");
sb.append(ind(ind) + "list.add(this);\n"); sb.append(ind(ind) + "list.add(this);\n");
sb.append(ind(ind) + "o.set" + otherSide().getImplAttributeName() + "(list);\n"); sb.append(ind(ind) + "o.set" + otherSide().getImplAttributeName() + "(list);\n");
......
...@@ -21,6 +21,7 @@ public class Compiler { ...@@ -21,6 +21,7 @@ public class Compiler {
protected ArrayList<Option<?>> options; protected ArrayList<Option<?>> options;
protected FlagOption optionWriteToFile; protected FlagOption optionWriteToFile;
protected FlagOption optionPrintAST; protected FlagOption optionPrintAST;
protected StringOption optionListClass;
protected CommandLine commandLine; protected CommandLine commandLine;
public Compiler(String args[]) throws CommandLineException { public Compiler(String args[]) throws CommandLineException {
...@@ -47,6 +48,12 @@ public class Compiler { ...@@ -47,6 +48,12 @@ public class Compiler {
} }
System.exit(1); System.exit(1);
} else { } else {
if (optionListClass.isSet()) {
System.out.println("ListClass is set to " + optionListClass.getValue());
p.listClass = optionListClass.getValue();
}
if (optionWriteToFile.isSet()) { if (optionWriteToFile.isSet()) {
File file = new File(filename); File file = new File(filename);
String absPath = file.getAbsolutePath(); String absPath = file.getAbsolutePath();
...@@ -76,6 +83,7 @@ public class Compiler { ...@@ -76,6 +83,7 @@ public class Compiler {
protected void addOptions() { protected void addOptions() {
optionWriteToFile = addOption(new FlagOption("file", "write output to files <filename>Gen.ast and <filename>Gen.jadd")); optionWriteToFile = addOption(new FlagOption("file", "write output to files <filename>Gen.ast and <filename>Gen.jadd"));
optionPrintAST = addOption(new FlagOption("ast", "print AST")); optionPrintAST = addOption(new FlagOption("ast", "print AST"));
optionListClass = addOption(new StringOption("listClass", "determine the class name of the nonterminal reference list"));
} }
protected <OptionType extends Option<?>> OptionType addOption(OptionType option) { protected <OptionType extends Option<?>> OptionType addOption(OptionType option) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment