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

resolver helper now works for all sorts of relations

parent 995282e4
No related branches found
No related tags found
1 merge request!1Mquat2
Pipeline #2959 passed
......@@ -4,6 +4,7 @@
build
src/gen-res/
src/gen/
out/
*.class
src/test/jastadd/relations/Relations.ast
src/test/jastadd/relations/Relations.jadd
......
......@@ -217,7 +217,7 @@ aspect BackendDirectedAPI {
sb.append(".get" + nameCapitalized() + "() {\n");
if (resolverHelper) {
sb.append(ind(2) + "if (get" + getImplAttributeName() + "() != null && get" + getImplAttributeName() + "().unresolved()) {\n");
sb.append(ind(3) + "set" + getImplAttributeName() + "(resolve" + nameCapitalized() + "(get" + getImplAttributeName() + "().asUnresolved" + ofTypeDecl() + "().get__token()));\n");
sb.append(ind(3) + "set" + nameCapitalized() + "(resolve" + nameCapitalized() + "(get" + getImplAttributeName() + "().asUnresolved" + ofTypeDecl() + "().get__token()));\n");
sb.append(ind(2) + "}\n");
}
sb.append(ind(2) + "return get" + getImplAttributeName() + "();\n");
......@@ -250,6 +250,20 @@ aspect BackendDirectedAPI {
sb.append(".get" + nameCapitalized() + "List() {\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> l = get"
+ getImplAttributeName() + "();\n");
// resolve the entire list
if (resolverHelper) {
sb.append(ind(2) + "int removedElements = 0;\n");
sb.append(ind(2) + "if (l != null) {\n");
sb.append(ind(3) + "for (int i = 0; i < l.size() - removedElements; i++) {\n");
sb.append(ind(4) + "if (get" + getImplAttributeName() + "().get(i) != null && get" + getImplAttributeName() + "().get(i).unresolved()) {\n");
sb.append(ind(5) + ofTypeDecl() + " element = l.remove(i);\n");
sb.append(ind(5) + "add" + nameCapitalized() + "(resolve" + nameCapitalized() + "(element.asUnresolved" + ofTypeDecl() + "().get__token(), i));\n");
sb.append(ind(5) + "i--; // go back an index, because we removed an element\n");
sb.append(ind(5) + "removedElements++; // no need to iterate over the removed elements again\n");
sb.append(ind(4) + "}\n");
sb.append(ind(3) + "}\n");
sb.append(ind(2) + "}\n");
}
sb.append(ind(2) + "return l != null ? Collections.unmodifiableList(l) : Collections.emptyList();\n");
sb.append(ind(1) + "}\n");
}
......@@ -306,20 +320,42 @@ aspect BackendBidirectionalAPI {
if (!isOpt) {
sb.append(ind(2) + "assertNotNull(o);\n");
}
sb.append(ind(2) + "if (get" + getImplAttributeName() + "() != null) {\n");
// unset the old opposite
// if (resolverHelper) {
// sb.append(ind(2) + "if (!o.unresolved() && get" + getImplAttributeName() + "() != null) {\n");
// } else {
sb.append(ind(2) + "if (get" + getImplAttributeName() + "() != null) {\n");
// }
sb.append(ind(3) + "get" + getImplAttributeName() + "().set" + otherSide().getImplAttributeName() + "(null);\n");
sb.append(ind(2) + "}\n");
sb.append(ind(2) + "if (o != null && o.get" + otherSide().getImplAttributeName() + "() != null) {\n");
if (resolverHelper) {
sb.append(ind(2) + "if (!o.unresolved() && o != null && o.get" + otherSide().getImplAttributeName() + "() != null) {\n");
} else {
sb.append(ind(2) + "if (o != null && o.get" + otherSide().getImplAttributeName() + "() != null) {\n");
}
sb.append(ind(3) + "o.get" + otherSide().getImplAttributeName() + "().set" + getImplAttributeName() + "(null);\n");
sb.append(ind(2) + "}\n");
sb.append(ind(2) + "set" + getImplAttributeName() + "(o);\n");
if (isOpt) {
sb.append(ind(2) + "if (o != null) {\n");
sb.append(ind(3) + "o.set" + otherSide().getImplAttributeName() + "(this);\n");
if (resolverHelper) {
sb.append(ind(2) + "if (!o.unresolved()) {\n");
if (isOpt) {
sb.append(ind(3) + "if (o != null) {\n");
sb.append(ind(4) + "o.set" + otherSide().getImplAttributeName() + "(this);\n");
sb.append(ind(3) + "}\n");
} else {
sb.append(ind(3) + "o.set" + otherSide().getImplAttributeName() + "(this);\n");
}
sb.append(ind(2) + "}\n");
} else {
sb.append(ind(2) + "o.set" + otherSide().getImplAttributeName() + "(this);\n");
if (isOpt) {
sb.append(ind(2) + "if (o != null) {\n");
sb.append(ind(3) + "o.set" + otherSide().getImplAttributeName() + "(this);\n");
sb.append(ind(2) + "}\n");
} else {
sb.append(ind(2) + "o.set" + otherSide().getImplAttributeName() + "(this);\n");
}
}
sb.append(ind(1) + "}\n");
if (isOpt) {
......@@ -610,7 +646,8 @@ aspect NameResolutionHelper {
relation().getLeft().generateContextDependentNameResolution(sb);
}
public void Bidirectional.generateContextDependentNameResolution(StringBuilder sb) {
// TODO
relation().getLeft().generateContextDependentNameResolution(sb);
relation().getRight().generateContextDependentNameResolution(sb);
}
public abstract void RelationComponent.generateContextDependentNameResolution(StringBuilder sb);
......@@ -618,10 +655,16 @@ aspect NameResolutionHelper {
generateDirectedContextDependentNameResolution(sb);
}
public void OptionalRelationComponent.generateContextDependentNameResolution(StringBuilder sb) {
// TODO
// optional relations are resolved in the same way as mandatory relations
// TODO maybe, there should be a check if the id to be solved is empty or null
generateDirectedContextDependentNameResolution(sb);
}
public void ManyRelationComponent.generateContextDependentNameResolution(StringBuilder sb) {
// TODO
sb.append(ind(1) + "// context-dependent name resolution\n");
sb.append(ind(1) + "syn " + ofTypeDecl() + " " + toTypeDecl() + ".resolve" + nameCapitalized() + "(String id, int position) {\n");
sb.append(ind(2) + "// default to context-independent name resolution\n");
sb.append(ind(2) + "return resolve" + ofTypeDecl() + "(id);\n");
sb.append(ind(1) + "}\n");
}
public void RelationComponent.generateDirectedContextDependentNameResolution(StringBuilder sb) {
......
......@@ -6,5 +6,17 @@ aspect MyRewrites {
return root().findNamedElement(id);
}
// context-independent name resolution
refine RefResolverStubs eq ASTNode.resolveA(String id) {
System.out.println("resolving " + id + " to " + root().findNamedElement(id));
return root().findA(id);
}
// context-independent name resolution
refine RefResolverStubs eq ASTNode.resolveB(String id) {
System.out.println("resolving " + id + " to " + root().findNamedElement(id));
return root().findB(id);
}
}
......@@ -5,3 +5,19 @@ B:NamedElement;
rel A.Rel1 -> NamedElement;
rel A.Rel2 -> NamedElement;
rel A.Di1 -> B;
rel A.Di2? -> B;
rel A.Di3* -> B;
rel A.Bi1 <-> B.Bi1;
rel A.Bi2 <-> B.Bi2?;
rel A.Bi3 <-> B.Bi3*;
rel A.Bi4? <-> B.Bi4;
rel A.Bi5? <-> B.Bi5?;
rel A.Bi6? <-> B.Bi6*;
rel A.Bi7* <-> B.Bi7;
rel A.Bi8* <-> B.Bi8?;
rel A.Bi9* <-> B.Bi9*;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment