Skip to content
Snippets Groups Projects
Commit 9825a6b2 authored by Jesper's avatar Jesper
Browse files

Removed global static indentation variable

fixes #123
parent 2b647e98
No related branches found
No related tags found
No related merge requests found
2013-04-04 Jesper Öqvist <jesper.oqvist@cs.lth.se>
* Removed global static variables to allow multiple concurrent JastAdd
instances in the same JVM
2013-04-03 Jesper Öqvist <jesper.oqvist@cs.lth.se>
* Improved error handling for missing equations of synthesized attributes
......
......@@ -107,6 +107,7 @@ aspect ASTCloneNode {
// the NTA children from the full copy, but for Opt and List NTAs
// we still need to create a placeholder Opt/List node
String skipNTAs = "";
String ind = grammar().ind;
if (!ntaAggregateIndices.isEmpty() || !ntaOptIndices.isEmpty() ||
!ntaListIndices.isEmpty()) {
......
......@@ -47,6 +47,7 @@ aspect CollectionAttributes {
for(int i = 0; i < getNumCollDecl(); i++) {
CollDecl attr = getCollDecl(i);
if(!attr.separateEvaluation() && (attr.isCircular() || !attr.onePhase())) {
String ind = grammar().ind;
out.println(ind + "/**");
out.println(ind + " * @apilevel internal");
out.println(ind + " */");
......@@ -85,6 +86,7 @@ aspect CollectionAttributes {
if(!separateEvaluation())
return super.cacheCycleCheck();
if (!grammar().cacheCycle) return "";
String ind = grammar().ind;
if(getNumParameter() == 0) {
return
"if (state().LAST_CYCLE) {\n" +
......@@ -192,10 +194,10 @@ aspect CollectionAttributes {
CollEq firstEq = equations.get(0);
out.println(ind + "protected void collect_contributors_" + decl.collectingSignature() + "() {"); // once per group
out.println(grammar().ind + "protected void collect_contributors_" + decl.collectingSignature() + "() {"); // once per group
if (isRootNode()) {
out.println(ind(2) + "if(collect_contributors_" + decl.collectingSignature() + ") return;");
out.println(grammar().ind(2) + "if(collect_contributors_" + decl.collectingSignature() + ") return;");
}
String bottomValue = Unparser.unparse(decl.getBottomValue());
......@@ -220,15 +222,15 @@ aspect CollectionAttributes {
}
}
if (isASTNode()) {
out.println(ind(2) + "for(int i = 0; i < getNumChild(); i++)");
out.println(ind(3) + "getChild(i).collect_contributors_" + decl.collectingSignature() + "();"); // once per group
out.println(grammar().ind(2) + "for(int i = 0; i < getNumChild(); i++)");
out.println(grammar().ind(3) + "getChild(i).collect_contributors_" + decl.collectingSignature() + "();"); // once per group
} else {
out.println(ind(2) + "super.collect_contributors_" + decl.collectingSignature() + "();");
out.println(grammar().ind(2) + "super.collect_contributors_" + decl.collectingSignature() + "();");
if (isRootNode()) {
out.println(ind(2) + "collect_contributors_" + decl.collectingSignature() + " = true;");
out.println(grammar().ind(2) + "collect_contributors_" + decl.collectingSignature() + " = true;");
}
}
out.println(ind + "}");
out.println(grammar().ind + "}");
}
}
......@@ -251,20 +253,20 @@ aspect CollectionAttributes {
CollDecl decl = entry.getKey();
ArrayList<CollEq> equations = entry.getValue();
out.println(ind + "protected void contributeTo_" + decl.getTarget() + "_" + decl.attributeSignature() + "(" + decl.getType() + " collection) {");
out.println(ind(2) + "super.contributeTo_" + decl.getTarget() + "_" + decl.attributeSignature() + "(collection);");
out.println(grammar().ind + "protected void contributeTo_" + decl.getTarget() + "_" + decl.attributeSignature() + "(" + decl.getType() + " collection) {");
out.println(grammar().ind(2) + "super.contributeTo_" + decl.getTarget() + "_" + decl.attributeSignature() + "(collection);");
for (CollEq attr: equations) {
for (int j = 0; j < attr.getNumContribution(); j++) {
Contribution c = attr.getContribution(j);
if (c.hasCondition() /* && attr.getNumContribution() > 1*/) {
out.println(ind(2) + "if(" + c.getCondition().trim() + ")");
out.println(ind(3) + "collection." + decl.getCombOp() + "(" + c.getValue().trim() + ");");
out.println(grammar().ind(2) + "if(" + c.getCondition().trim() + ")");
out.println(grammar().ind(3) + "collection." + decl.getCombOp() + "(" + c.getValue().trim() + ");");
} else {
out.println(ind(2) + "collection." + decl.getCombOp() + "(" + c.getValue().trim() + ");");
out.println(grammar().ind(2) + "collection." + decl.getCombOp() + "(" + c.getValue().trim() + ");");
}
}
}
out.println(ind + "}\n");
out.println(grammar().ind + "}\n");
}
}
......@@ -296,7 +298,7 @@ aspect CollectionAttributes {
valueAccess = "n.new_";
}
out.println(ind + "protected void " + decl.getTarget() + "_" + firstEq.attributeSignature() + "_nextIteration(" + decl.getTarget() + " n) {");
out.println(grammar().ind + "protected void " + decl.getTarget() + "_" + firstEq.attributeSignature() + "_nextIteration(" + decl.getTarget() + " n) {");
for (CollEq attr: equations) {
TemplateContext tt = attr.templateContext();
tt.bind("CombOp", decl.getCombOp());
......@@ -312,12 +314,12 @@ aspect CollectionAttributes {
}
}
if(isASTNode()) {
out.println(ind(2) + "for(int i = 0; i < getNumChild(); i++)");
out.println(ind(3) + "getChild(i)." + decl.getTarget() + "_" + firstEq.attributeSignature() + "_next_Iteration(n);"); // once per group
out.println(grammar().ind(2) + "for(int i = 0; i < getNumChild(); i++)");
out.println(grammar().ind(3) + "getChild(i)." + decl.getTarget() + "_" + firstEq.attributeSignature() + "_next_Iteration(n);"); // once per group
} else {
out.println(ind(3) + "r." + decl.getTarget() + "_" + firstEq.attributeSignature() + "_nextIteration(n);");
out.println(grammar().ind(3) + "r." + decl.getTarget() + "_" + firstEq.attributeSignature() + "_nextIteration(n);");
}
out.println(ind + "}");
out.println(grammar().ind + "}");
}
}
......
......@@ -145,7 +145,7 @@ aspect Flush {
res.append(attr.resetVisit());
res.append(attr.resetCache());
if(!attr.separateEvaluation() && !attr.onePhase())
res.append(ind(2) + attr.attributeSignature() + "_contributors = " + (grammar().lazyMaps ? "null" : grammar().createContributorSet) + ";\n");
res.append(grammar().ind(2) + attr.attributeSignature() + "_contributors = " + (grammar().lazyMaps ? "null" : grammar().createContributorSet) + ";\n");
}
res.append(collectionReset());
return res.toString();
......
......@@ -189,10 +189,10 @@ aspect JaddCodeGen {
if(c instanceof TokenComponent) {
TokenComponent t = (TokenComponent)c;
String tokenId = t.getTokenId().getID();
out.println(ind(2) + "set" + tokenId + "(p" + param + ");");
out.println(grammar().ind(2) + "set" + tokenId + "(p" + param + ");");
}
else {
out.println(ind(2) + "setChild(p" + param + ", " + childIndex + ");");
out.println(grammar().ind(2) + "setChild(p" + param + ", " + childIndex + ");");
childIndex++;
}
param += 1;
......@@ -206,9 +206,9 @@ aspect JaddCodeGen {
}
if(grammar().rewriteEnabled && isRootNode()) {
if(grammar().stagedRewrites)
out.println(ind(2) + "is$Final(java.lang.Integer.MAX_VALUE);");
out.println(grammar().ind(2) + "is$Final(java.lang.Integer.MAX_VALUE);");
else
out.println(ind(2) + "is$Final(true);");
out.println(grammar().ind(2) + "is$Final(true);");
}
out.print(tt.expand("State.incHookConstructionEnd"));
......@@ -223,7 +223,7 @@ aspect JaddCodeGen {
// we only build constructors if there are components
if(!getComponents().hasNext())
return;
out.print(ind + "public " + name() + "." + name() + "(");
out.print(grammar().ind + "public " + name() + "." + name() + "(");
int i = 0; // parameter index
for(Iterator iter = getComponents(); iter.hasNext(); ) {
Components c = (Components)iter.next();
......@@ -235,7 +235,7 @@ aspect JaddCodeGen {
}
out.println(") {");
emitBuildingConstructorBody(out);
out.println(ind + "}");
out.println(grammar().ind + "}");
}
public void ASTDecl.emitSymbolConstructor(PrintWriter out) {
......@@ -251,7 +251,7 @@ aspect JaddCodeGen {
}
if(!stringArg) return;
out.print(ind + "public " + name() + "." + name() + "(");
out.print(grammar().ind + "public " + name() + "." + name() + "(");
int i = 0; // parameter index
for(Iterator iter = getComponents(); iter.hasNext(); ) {
Components c = (Components)iter.next();
......@@ -266,7 +266,7 @@ aspect JaddCodeGen {
}
out.println(") {");
emitBuildingConstructorBody(out);
out.println(ind + "}");
out.println(grammar().ind + "}");
}
public void Grammar.genReset(PrintWriter out) {
......@@ -312,7 +312,7 @@ aspect JaddCodeGen {
buf.append("!(this instanceof " + root.name() + ")");
}
buf.append(")\n");
buf.append(ind + "throw new RuntimeException(\"Trying to evaluate state in a node which is not attached to the main tree\");");
buf.append(grammar().ind + "throw new RuntimeException(\"Trying to evaluate state in a node which is not attached to the main tree\");");
return buf.toString();
} else {
return "";
......@@ -476,6 +476,8 @@ aspect JaddCodeGen {
* @param out Aspect output stream
*/
public void ASTDecl.emitMayHaveRewrite(PrintWriter out) {
String ind = grammar().ind;
String ind2 = grammar().ind(2);
out.println(ind + "/**");
out.println(ind + " * @apilevel internal");
out.println(ind + " */");
......@@ -484,21 +486,21 @@ aspect JaddCodeGen {
// Avoiding list touch rewrite
if (!(grammar().incremental || grammar().fullFlush)) {
out.println(ind(2) + "return true;"); // old code
out.println(ind2 + "return true;"); // old code
} else {
out.println(ind(2) + "return false;");
out.println(ind2 + "return false;");
}
} else if(!hasRewrites())
out.println(ind(2) + "return false;");
out.println(ind2 + "return false;");
else if(!grammar().stagedRewrites || rewriteWithNoPhaseCondition())
out.println(ind(2) + "return true;");
out.println(ind2 + "return true;");
else {
for(Iterator iter = rewritePhaseConditions().iterator(); iter.hasNext(); ) {
String condition = (String)iter.next();
out.println(ind(2) + "if(" + condition + ") return true;");
out.println(ind2 + "if(" + condition + ") return true;");
}
out.println(ind(2) + "return false;");
out.println(ind2 + "return false;");
}
out.println(ind + "}");
}
......
......@@ -45,8 +45,33 @@ aspect AttributeKind {
aspect JragCodeGen {
public static String ASTNode.ind = " ";
public static java.util.List<String> ASTNode.indList = new ArrayList<String>(32);
/**
* One level of indentation.
*/
public String Grammar.ind = " ";
/**
* Indentation level cache.
*/
protected java.util.List<String> Grammar.indList = new ArrayList<String>(32);
/**
* Builds an indentation string equal to a certain level of
* indentation.
*
* @param level the required indentation level
* @return the indentation string
*/
public final String Grammar.ind(int level) {
while (indList.size() <= level) {
if (indList.size() == 0) {
indList.add("");
} else {
indList.add(indList.get(indList.size()-1) + ind);
}
}
return indList.get(level);
}
/**
* Generate the declaredat documentation tag. If no file name is available
......@@ -79,24 +104,6 @@ aspect JragCodeGen {
syn String RewriteList.declaredat() =
ASTNode.declaredat(getFileName(), getStartLine());
/**
* Builds an indentation string equal to a certain level of
* indentation.
*
* @param level the required indentation level
* @return the indentation string
*/
public static final String ASTNode.ind(int level) {
while (indList.size() <= level) {
if (indList.size() == 0) {
indList.add("");
} else {
indList.add(indList.get(indList.size()-1) + ind);
}
}
return indList.get(level);
}
// EMMA_2009-11-16: Modifying cache conditions, using cacheNone instead of noCaching
refine public boolean AttrDecl.getLazy() {
if (grammar().cacheAll)
......@@ -107,6 +114,7 @@ aspect JragCodeGen {
return declaredNTA() || refined(); //Ast.AttrDecl.getLazy();
// return (Ast.AttrDecl.getLazy() || grammar().cacheAll) && (!noCaching || declaredNTA());
}
refine public boolean SynDecl.getLazy() {
if (grammar().cacheAll)
return true;
......@@ -116,6 +124,7 @@ aspect JragCodeGen {
return declaredNTA() || refined(); //Ast.SynDecl.getLazy();
// return (Ast.SynDecl.getLazy() || grammar().cacheAll) && (!noCaching || declaredNTA());
}
refine public boolean InhDecl.getLazy() {
if (grammar().cacheAll)
return true;
......@@ -125,6 +134,7 @@ aspect JragCodeGen {
return declaredNTA() || refined(); //Ast.InhDecl.getLazy();
// return (Ast.InhDecl.getLazy() || grammar().cacheAll) && (!noCaching || declaredNTA());
}
refine public boolean CollDecl.getLazy() {
if (grammar().cacheAll)
return true;
......@@ -233,7 +243,7 @@ aspect JragCodeGen {
jrag.AST.SimpleNode node = obj.node;
out.print(obj.modifiers);
out.println(javadocComment(obj));
out.print(ind);
out.print(grammar().ind);
StringBuffer buf = new StringBuffer();
node.jjtAccept(new ClassBodyDeclUnparser(), buf);
out.print(buf.toString());
......@@ -268,7 +278,7 @@ aspect JragCodeGen {
if(!equ) {
out.println(attr.hostFileComment());
out.print(suppressWarnings());
out.println(ind + "public abstract " + attr.getType() + " " + attr.attributeName() + "(" + attr.parametersDecl() + ");");
out.println(grammar().ind + "public abstract " + attr.getType() + " " + attr.attributeName() + "(" + attr.parametersDecl() + ");");
}
}
}
......@@ -565,27 +575,27 @@ aspect JragCodeGen {
public String AttrDecl.callCompute() {
if(getLazy() && getNumParameter() == 0)
return ind(2) + attributeSignature() + "_value = " + attributeName() + "_compute(" + parameters() + ");\n";
return grammar().ind(2) + attributeSignature() + "_value = " + attributeName() + "_compute(" + parameters() + ");\n";
else
return ind(2) + getType() + " " + attributeSignature() + "_value = " + attributeName() + "_compute(" + parameters() + ");\n";
return grammar().ind(2) + getType() + " " + attributeSignature() + "_value = " + attributeName() + "_compute(" + parameters() + ");\n";
}
// TODO: INH
public String InhDecl.callCompute() {
if(getLazy() && getNumParameter() == 0) {
return inhDebugString() +
ind(2) + attributeSignature() + "_value = getParent().Define_" + getTypeInSignature() + "_" + attributeName() + "(" + interfaceParametersStart() + ");\n";
grammar().ind(2) + attributeSignature() + "_value = getParent().Define_" + getTypeInSignature() + "_" + attributeName() + "(" + interfaceParametersStart() + ");\n";
} else {
return inhDebugString() +
ind(2) + getType() + " " + attributeSignature() + "_value = getParent().Define_" + getTypeInSignature() + "_" + attributeName() + "(" + interfaceParametersStart() + ");\n";
grammar().ind(2) + getType() + " " + attributeSignature() + "_value = getParent().Define_" + getTypeInSignature() + "_" + attributeName() + "(" + interfaceParametersStart() + ");\n";
}
}
public String AttrDecl.cacheStoreRewrite() {
if(!grammar().rewriteEnabled || getFinal())
return ind + "if(true)";
return grammar().ind + "if(true)";
else
return ind + "if(isFinal && num == state().boundariesCrossed)";
return grammar().ind + "if(isFinal && num == state().boundariesCrossed)";
}
public String AttrDecl.cacheStore() {
......@@ -611,15 +621,15 @@ aspect JragCodeGen {
int index = indexNTAchild();
return getType() + " node = (" + getType() + ") this.getChild(" + attributeSignature() + "ChildPosition());\n" +
tt.expand("AttrDecl.incHookAttrCompEnd") +
ind(2) + "return node;\n";
grammar().ind(2) + "return node;\n";
}
if (isCircular()) {
return ind(2) + "return " + attributeSignature() + "_value;\n";
return grammar().ind(2) + "return " + attributeSignature() + "_value;\n";
}
return tt.expand("AttrDecl.incHookAttrCompEnd") +
ind(2) + "return " + attributeSignature() + "_value;\n";
grammar().ind(2) + "return " + attributeSignature() + "_value;\n";
}
syn boolean AttrEq.hasComputeBlock() = true;
......@@ -663,7 +673,7 @@ aspect JragCodeGen {
if(!grammar().debugMode) {
return "";
} else {
return ind(2) + "if(getParent() == null) throw new RuntimeException(\"Trying to evaluate attribute in subtree not attached to main tree\");\n";
return grammar().ind(2) + "if(getParent() == null) throw new RuntimeException(\"Trying to evaluate attribute in subtree not attached to main tree\");\n";
}
}
......@@ -738,6 +748,7 @@ aspect JragCodeGen {
getNumParameter() != 0;
public String AttrDecl.resetCycleCheck() {
String ind = grammar().ind;
if(getNumParameter() == 0)
return
"if (state.RESET_CYCLE) {\n" +
......@@ -756,7 +767,8 @@ aspect JragCodeGen {
public String AttrDecl.cacheCycleCheck() {
if (!grammar().cacheCycle) return "";
TemplateContext tt = templateContext();
if(getNumParameter() == 0)
String ind = grammar().ind;
if(getNumParameter() == 0) {
return
"if (state.LAST_CYCLE) {\n" +
attributeSignature() + "_computed = true;\n" +
......@@ -766,14 +778,14 @@ aspect JragCodeGen {
tt.expand("AttrDecl.incHookAttrCompEndCircular") +
ind + "return new_" + attributeSignature() + "_value;\n" +
"}\n";
else {
if (grammar().java5)
} else {
if (grammar().java5) {
return
"if (state.LAST_CYCLE) {\n" +
inhDebugString() +
ind + attributeSignature() + "_values.put(_parameters, new_" + attributeSignature() + "_value);\n" +
"}\n";
else
} else {
return
"if (state.LAST_CYCLE) {\n" +
inhDebugString() +
......@@ -781,10 +793,12 @@ aspect JragCodeGen {
"}\n";
}
}
}
public String AttrDecl.addComponentCheck() {
if(!grammar().componentCheck || !grammar().visitCheckEnabled) return "";
String arg = getNumParameter() == 0 ? "null" : "_parameters";
String ind = grammar().ind;
if(getNumParameter() == 0) {
if(grammar().rewriteEnabled)
return
......@@ -838,6 +852,7 @@ aspect JragCodeGen {
// and calls an overriden equation it can cause a circularity exception.
needsCacheDeclaration = true; // superClass() == null || !superClass().hasLazySynEqFor(attr);
}
String ind = grammar().ind;
if (!attr.isCircular()) {
if (needsCacheDeclaration) {
attr.emitVisitedDeclarations(out);
......@@ -977,7 +992,7 @@ aspect JragCodeGen {
comp instanceof OptionalComponentNTA
|| comp instanceof TokenComponentNTA
|| comp instanceof AggregateComponentsNTA )) {
result.append(ind + "set" + attrName + "(" + attributeSignature() + "_value);\n");
result.append(grammar().ind + "set" + attrName + "(" + attributeSignature() + "_value);\n");
}
if(attrName.equals(comp.name() + "Opt") && comp instanceof OptionalComponentNTA) {
result.append("set" + attrName + "(" + attributeSignature() + "_value);\n");
......@@ -1064,6 +1079,9 @@ aspect JragCodeGen {
public void ASTDecl.emitInhEquations(PrintStream out) {
String ind = grammar().ind;
String ind2 = grammar().ind(2);
String ind3 = grammar().ind(3);
for(Iterator idIter = inhAttrSet(); idIter.hasNext(); ) {
String attrId = (String)idIter.next();
Iterator iter = inhAttrEqs(attrId);
......@@ -1081,7 +1099,7 @@ aspect JragCodeGen {
boolean hasGetChildEq = false;
do {
out.print(ind(2));
out.print(ind2);
if (hasComponentEq) {
out.print("else ");
}
......@@ -1112,14 +1130,14 @@ aspect JragCodeGen {
String childIndex = equ.hasIndex() ? equ.getIndex().getName() : "childIndex";
if(equ.getRHS() instanceof ASTBlock) { // Block
out.println(ind + "{");
out.println(ind(2) + "int " + childIndex + " = caller.getIndexOfChild(child);");
out.println(ind(2) + Unparser.unparse(equ.getRHS()));
out.println(ind2 + "int " + childIndex + " = caller.getIndexOfChild(child);");
out.println(ind2 + Unparser.unparse(equ.getRHS()));
out.println(ind + "}");
}
else { // Expr
out.println(ind + "{");
out.println(ind(2) + "int " + childIndex + " = caller.getIndexOfChild(child);");
out.println(ind(2) + "return " + Unparser.unparse(equ.getRHS()) + ";");
out.println(ind2 + "int " + childIndex + " = caller.getIndexOfChild(child);");
out.println(ind2 + "return " + Unparser.unparse(equ.getRHS()) + ";");
out.println(ind + "}");
}
......@@ -1130,23 +1148,23 @@ aspect JragCodeGen {
}
else { // Expr
out.println(" {");
out.println(ind(3) + "return " + Unparser.unparse(equ.getRHS()) + ";");
out.println(ind(2) + "}");
out.println(ind3 + "return " + Unparser.unparse(equ.getRHS()) + ";");
out.println(ind2 + "}");
}
}
else if(equ.getSonName().equals("getChild")) {
String childIndex = equ.hasIndex() ? equ.getIndex().getName() : "childIndex";
if(equ.getRHS() instanceof ASTBlock) { // Block
out.println(" {");
out.println(ind(3) + "int " + childIndex + " = this.getIndexOfChild(caller);");
out.println(ind3 + "int " + childIndex + " = this.getIndexOfChild(caller);");
out.println(Unparser.unparse(equ.getRHS()));
out.println(ind(2) + "}");
out.println(ind2 + "}");
}
else { // Expr
out.println(" {");
out.println(ind(3) + "int " + childIndex + " = this.getIndexOfChild(caller);");
out.println(ind(3) + "return " + Unparser.unparse(equ.getRHS()) + ";");
out.println(ind(2) + "}");
out.println(ind3 + "int " + childIndex + " = this.getIndexOfChild(caller);");
out.println(ind3 + "return " + Unparser.unparse(equ.getRHS()) + ";");
out.println(ind2 + "}");
}
}
else {
......@@ -1154,15 +1172,15 @@ aspect JragCodeGen {
out.println("{");
if(attrDecl.getNumParameter() != 0) {
String childIndex = equ.hasIndex() ? equ.getIndex().getName() : "childIndex";
out.println(ind(3) + "int " + childIndex + " = caller.getIndexOfChild(child);");
out.println(ind3 + "int " + childIndex + " = caller.getIndexOfChild(child);");
}
if(equ.getRHS() instanceof ASTBlock) { // Block
out.println(Unparser.unparse(equ.getRHS()));
out.println(ind(2) + "}");
out.println(ind2 + "}");
}
else { // Expr
out.println(ind(3) + "return " + Unparser.unparse(equ.getRHS()) + ";");
out.println(ind(2) + "}");
out.println(ind3 + "return " + Unparser.unparse(equ.getRHS()) + ";");
out.println(ind2 + "}");
}
}
......@@ -1175,19 +1193,19 @@ aspect JragCodeGen {
} while(equ != null);
if (!hasGetChildEq) {
out.print(ind(2));
out.print(ind2);
if (hasComponentEq) {
out.print("else {");
}
if(superClass() != null && superClass().hasInhEq(decl.name())) {
out.println(ind(3) + "return super.Define_" + decl.getTypeInSignature() + "_" + decl.attributeName() + "(" + decl.interfaceParameters() + ");");
out.println(ind(2) + "}");
out.println(ind3 + "return super.Define_" + decl.getTypeInSignature() + "_" + decl.attributeName() + "(" + decl.interfaceParameters() + ");");
out.println(ind2 + "}");
}
else {
// TODO: INH
out.print(decl.inhDebugString());
out.println(ind(3) + "return getParent().Define_" + decl.getTypeInSignature() + "_" + decl.attributeName() + "(" + decl.interfaceParametersContinue() + ");");
out.println(ind(2) + "}");
out.println(ind3 + "return getParent().Define_" + decl.getTypeInSignature() + "_" + decl.attributeName() + "(" + decl.interfaceParametersContinue() + ");");
out.println(ind2 + "}");
}
}
out.println(ind + "}");
......
......@@ -114,12 +114,14 @@ aspect Rewrites {
}
public void Rewrite.genRewritesExtra(PrintStream out, int index) {
String ind = grammar().ind;
String ind2 = grammar().ind(2);
TemplateContext tt = templateContext();
tt.expand("Rewrite.javaDoc:internal", out);
if(getResult() instanceof jrag.AST.ASTBlock) {
out.println(ind + "private " + getReturnType() + " rewriteRule" + index + "() {");
if(grammar().rewriteLimit > 0)
out.println(ind(2) +
out.println(ind2 +
"debugRewrite(\"Rewriting \" + getClass().getName() + \" " +
"using rule in " + getFileNameEscaped() + " at line " +
getStartLine() + "\");");
......@@ -129,21 +131,23 @@ aspect Rewrites {
else {
out.println(ind + "private " + getReturnType() + " rewriteRule" + index + "() {");
if(grammar().rewriteLimit > 0)
out.println(ind(2) +
out.println(ind2 +
"debugRewrite(\"Rewriting \" + getClass().getName() + \" " +
"using rule in " + getFileNameEscaped() + " at line " +
getStartLine() + "\");");
out.println(ind(2) + "return " + Unparser.unparse(getResult()) + ";");
out.println(ind2 + "return " + Unparser.unparse(getResult()) + ";");
out.println(ind + "}");
}
}
public void RewriteList.genRewritesExtra(PrintStream out, int index) {
String ind = grammar().ind;
String ind2 = grammar().ind(2);
TemplateContext tt = templateContext();
tt.expand("Rewrite.javaDoc:internal", out);
if(getResult() instanceof jrag.AST.ASTBlock) {
out.println(ind + "private " + getReturnType() + " rewrite" + getParentName() + "_" + getChildName() + "() {");
if(grammar().rewriteLimit > 0)
out.println(ind(2) +
out.println(ind2 +
"debugRewrite(\"Rewriting \" + getClass().getName() + \" " +
"using rule in " + getFileNameEscaped() + " at line " +
getStartLine() + "\");");
......@@ -153,11 +157,11 @@ aspect Rewrites {
else {
out.println(ind + "private " + getReturnType() + " rewrite" + getParentName() + "_" + getChildName() + "() {");
if(grammar().rewriteLimit > 0)
out.println(ind(2) +
out.println(ind2 +
"debugRewrite(\"Rewriting \" + getClass().getName() + \" " +
"using rule in " + getFileNameEscaped() + " at line " +
getStartLine() + "\");");
out.println(ind(2) + "return " + Unparser.unparse(getResult()) + ";");
out.println(ind2 + "return " + Unparser.unparse(getResult()) + ";");
out.println(ind + "}");
}
}
......
......@@ -42,7 +42,7 @@ aspect TemplateUtil {
*/
eq Grammar.templateContext() {
TinyTemplate tt = new TinyTemplate();
tt.setIndentation(ASTNode.ind);
tt.setIndentation(ind);
tt.throwExceptions(true);
loadTemplates(tt, "ast/ASTNode");
loadTemplates(tt, "ast/List");
......
......@@ -40,7 +40,6 @@ import jrag.AST.ASTCompilationUnit;
import jrag.AST.JragParser;
import ast.AST.ASTDecl;
import ast.AST.ASTNode;
import ast.AST.Ast;
import ast.AST.Components;
import ast.AST.Grammar;
......
......@@ -36,7 +36,6 @@ import java.util.StringTokenizer;
import org.jastadd.tinytemplate.TemplateContext;
import ast.AST.ASTNode;
import ast.AST.Grammar;
/**
......@@ -252,16 +251,16 @@ public class JastAddConfiguration {
// TODO make ASTNode.ind not-static
if (indent.value().equals("2space")) {
// Use 2 spaces for indentation
ASTNode.ind = " ";
root.ind = " ";
} else if (indent.value().equals("4space")) {
// Use 4 spaces for indentation
ASTNode.ind = " ";
root.ind = " ";
} else if (indent.value().equals("8space")) {
// Use 8 spaces for indentation
ASTNode.ind = " ";
root.ind = " ";
} else if (indent.value().equals("tab")) {
// Use tabs for indentation
ASTNode.ind = "\t";
root.ind = "\t";
}
try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment