Commit 001af931 authored by Johannes Mey's avatar Johannes Mey
Browse files

remove some indirections and attribute usage when only serialization is used

parent 30c8be06
Pipeline #3165 passed with stage
in 1 minute and 13 seconds
...@@ -871,8 +871,8 @@ aspect NameResolutionHelper { ...@@ -871,8 +871,8 @@ aspect NameResolutionHelper {
} }
public void TypeDecl.generateContextIndependentNameResolution(StringBuilder sb) { public void TypeDecl.generateContextIndependentNameResolution(StringBuilder sb) {
sb.append(ind(1) + "// context-independent name resolution\n"); sb.append(ind(1) + "// context-independent name resolution\n");
sb.append(ind(1) + "uncache ASTNode.globallyResolve" + getID() + "ByToken(String id);\n");
sb.append(ind(1) + "syn " + getID() + " ASTNode.globallyResolve" + getID() + "ByToken(String id) {\n"); sb.append(ind(1) + "syn " + getID() + " ASTNode.globallyResolve" + getID() + "ByToken(String id) {\n");
if (serializer) { if (serializer) {
sb.append(ind(2) + "return (" + getID() + ") globallyResolveASTNodeByUID(id);\n"); sb.append(ind(2) + "return (" + getID() + ") globallyResolveASTNodeByUID(id);\n");
...@@ -908,24 +908,36 @@ aspect NameResolutionHelper { ...@@ -908,24 +908,36 @@ aspect NameResolutionHelper {
generateDirectedContextDependentNameResolution(sb); generateDirectedContextDependentNameResolution(sb);
} }
public void ManyRelationComponent.generateContextDependentNameResolution(StringBuilder sb) { public void ManyRelationComponent.generateContextDependentNameResolution(StringBuilder sb) {
sb.append(ind(1) + "// context-dependent name resolution\n"); System.out.println("serializer: " + serializer);
sb.append(ind(1) + "syn " + ofTypeDecl() + " " + toTypeDecl() + ".resolve" + nameCapitalized() + "ByToken(String id, int position) {\n"); System.out.println("ResolverHelper: " + resolverHelper);
sb.append(ind(2) + "// default to context-independent name resolution\n");
sb.append(ind(2) + "return globallyResolve" + ofTypeDecl() + "ByToken(id);\n"); if (serializer && !resolverHelper) {
sb.append(ind(1) + "}\n"); sb.append(ind(1) + ofTypeDecl() + " " + toTypeDecl() + ".resolve" + nameCapitalized() + "ByToken(String id, int position) {\n");
sb.append(ind(2) + "return (" + ofTypeDecl() + ") globallyResolveASTNodeByUID(id);\n");
sb.append(ind(1) + "}\n");
} else {
sb.append(ind(1) + "// context-dependent name resolution\n");
sb.append(ind(1) + "uncache " + toTypeDecl() + ".resolve" + nameCapitalized() + "ByToken(String id, int position);\n");
sb.append(ind(1) + "syn " + ofTypeDecl() + " " + toTypeDecl() + ".resolve" + nameCapitalized() + "ByToken(String id, int position) {\n");
sb.append(ind(2) + "// default to context-independent name resolution\n");
sb.append(ind(2) + "return globallyResolve" + ofTypeDecl() + "ByToken(id);\n");
sb.append(ind(1) + "}\n");
}
} }
public void RelationComponent.generateDirectedContextDependentNameResolution(StringBuilder sb) { public void RelationComponent.generateDirectedContextDependentNameResolution(StringBuilder sb) {
// // context-dependent name resolution if (serializer && !resolverHelper) {
// NamedElement A.resolveRel1(String id) { sb.append(ind(1) + ofTypeDecl() + " " + toTypeDecl() + ".resolve" + nameCapitalized() + "ByToken(String id) {\n");
// // default to context-independent name resolution sb.append(ind(2) + "return (" + ofTypeDecl() + ") globallyResolveASTNodeByUID(id);\n");
// return resolveNamedElement(id); sb.append(ind(1) + "}\n");
// } } else {
sb.append(ind(1) + "// context-dependent name resolution\n"); sb.append(ind(1) + "// context-dependent name resolution\n");
sb.append(ind(1) + "syn " + ofTypeDecl() + " " + toTypeDecl() + ".resolve" + nameCapitalized() + "ByToken(String id) {\n"); sb.append(ind(1) + "uncache " + toTypeDecl() + ".resolve" + nameCapitalized() + "ByToken(String id);\n");
sb.append(ind(2) + "// default to context-independent name resolution\n"); sb.append(ind(1) + "syn " + ofTypeDecl() + " " + toTypeDecl() + ".resolve" + nameCapitalized() + "ByToken(String id) {\n");
sb.append(ind(2) + "return globallyResolve" + ofTypeDecl() + "ByToken(id);\n"); sb.append(ind(2) + "// default to context-independent name resolution\n");
sb.append(ind(1) + "}\n"); sb.append(ind(2) + "return globallyResolve" + ofTypeDecl() + "ByToken(id);\n");
sb.append(ind(1) + "}\n");
}
} }
public void Program.resolveAll(StringBuilder sb) { public void Program.resolveAll(StringBuilder sb) {
...@@ -1345,13 +1357,15 @@ aspect Serializer { ...@@ -1345,13 +1357,15 @@ aspect Serializer {
sb.append(ind(2) + "return null;\n"); sb.append(ind(2) + "return null;\n");
sb.append(ind(1) + "}\n"); sb.append(ind(1) + "}\n");
sb.append(ind(1) + "syn ASTNode ASTNode.globallyResolveASTNodeByUID(String uid) {\n"); if (serializer) {
sb.append(ind(2) + "if (getParent() == null) {\n"); sb.append(ind(1) + "ASTNode ASTNode.globallyResolveASTNodeByUID(String uid) {\n");
sb.append(ind(3) + "return __uidMap().get(uid);\n"); sb.append(ind(2) + "if (getParent() == null) {\n");
sb.append(ind(2) + "} else {\n"); sb.append(ind(3) + "return __uidMap().get(uid);\n");
sb.append(ind(3) + "return getParent().globallyResolveASTNodeByUID(uid);\n"); sb.append(ind(2) + "} else {\n");
sb.append(ind(2) + "}\n"); sb.append(ind(3) + "return getParent().globallyResolveASTNodeByUID(uid);\n");
sb.append(ind(1) + "}\n"); sb.append(ind(2) + "}\n");
sb.append(ind(1) + "}\n");
}
sb.append(ind(1) + "syn java.util.Map<String, ASTNode> ASTNode.__uidMap() {\n"); sb.append(ind(1) + "syn java.util.Map<String, ASTNode> ASTNode.__uidMap() {\n");
sb.append(ind(2) + "return(__uidMap(new java.util.HashMap()));\n"); sb.append(ind(2) + "return(__uidMap(new java.util.HashMap()));\n");
......
...@@ -89,8 +89,11 @@ public class Compiler { ...@@ -89,8 +89,11 @@ public class Compiler {
} }
} }
if (optionResolverHelper.isSet() || optionSerializer.isSet()) { if (optionResolverHelper.isSet()) {
ASTNode.resolverHelper = true; ASTNode.resolverHelper = true;
}
if (optionResolverHelper.isSet() || optionSerializer.isSet()) {
writeToFile(grammarName + "ResolverStubs.jrag", p.generateResolverStubs()); writeToFile(grammarName + "ResolverStubs.jrag", p.generateResolverStubs());
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment