Commit 0f40a1a4 authored by Johannes Mey's avatar Johannes Mey
Browse files

create tests for issue #6

parent 9e256ef7
*.jar
*.jarsrc/test/java/org/jastadd/relast/tests/Resolver2.java
.idea/
.gradle/
build
......@@ -15,5 +15,8 @@ src/test/jastadd/multiple/Multiple.jadd
src/test/jastadd/resolver/Resolver.ast
src/test/jastadd/resolver/Resolver.jadd
src/test/jastadd/resolver/ResolverRefResolver.jadd
src/test/jastadd/resolver2/Resolver.ast
src/test/jastadd/resolver2/Resolver.jadd
src/test/jastadd/resolver2/ResolverRefResolver.jadd
src/test/jastadd/listnames/ListNames.ast
src/test/jastadd/listnames/ListNames.jadd
\ No newline at end of file
......@@ -201,6 +201,29 @@ task compileResolverTest(type: JavaExec, group: 'verification') {
args '--o=src/test/java-gen/', '--package=resolver.ast', 'src/test/jastadd/resolver/Resolver.ast', 'src/test/jastadd/resolver/Resolver.jadd', 'src/test/jastadd/resolver/ResolverUtils.jadd', 'src/test/jastadd/resolver/ResolverRefResolver.jadd', 'src/test/jastadd/resolver/MyRefResolver.jadd', 'src/test/jastadd/Utils.jadd'
}
task preprocessResolver2Test(type: JavaExec, group: 'verification') {
doFirst {
delete 'src/test/jastadd/resolver2/Resolver.ast', 'src/test/jastadd/resolver2/Resolver.jadd', 'src/test/jastadd/resolver2/ResolverRefResolver.jadd'
}
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
args 'src/test/jastadd/resolver2/Resolver.relast', '--file', '--grammarName=src/test/jastadd/resolver2/Resolver', '--resolverHelper'
}
task compileResolver2Test(type: JavaExec, group: 'verification') {
doFirst {
delete 'src/test/java-gen/resolver2'
}
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.JastAdd'
args '--o=src/test/java-gen/', '--package=resolver2.ast', 'src/test/jastadd/resolver2/Resolver.ast', 'src/test/jastadd/resolver2/Resolver.jadd', 'src/test/jastadd/resolver2/ResolverUtils.jadd', 'src/test/jastadd/resolver2/ResolverRefResolver.jadd', 'src/test/jastadd/resolver2/MyRefResolver.jadd', 'src/test/jastadd/Utils.jadd'
}
task preprocessListNamesTest(type: JavaExec, group: 'verification') {
doFirst {
......@@ -243,5 +266,8 @@ compileMultipleTest.dependsOn preprocessMultipleTest
test.dependsOn compileResolverTest
compileResolverTest.dependsOn preprocessResolverTest
test.dependsOn compileResolver2Test
compileResolver2Test.dependsOn preprocessResolver2Test
test.dependsOn compileListNamesTest
compileListNamesTest.dependsOn preprocessListNamesTest
\ No newline at end of file
aspect MyRewrites {
// context-independent name resolution
refine RefResolverStubs eq ASTNode.globallyResolveNamedElementByToken(String id) {
System.out.println("resolving " + id + " to " + root().findNamedElement(id));
return root().findNamedElement(id);
}
// context-independent name resolution
refine RefResolverStubs eq ASTNode.globallyResolveAByToken(String id) {
System.out.println("resolving " + id + " to " + root().findNamedElement(id));
return root().findA(id);
}
// context-independent name resolution
refine RefResolverStubs eq ASTNode.globallyResolveBByToken(String id) {
System.out.println("resolving " + id + " to " + root().findNamedElement(id));
return root().findB(id);
}
}
Root ::= A* B*;
abstract NamedElement ::= <Name:String>;
A:NamedElement;
B:NamedElement;
rel A.Rel1 -> NamedElement;
rel A.Rel2 -> NamedElement;
rel A.Di1 -> B;
rel A.Di2? -> B;
rel A.Di3* -> B;
rel A.Bi1l <-> B.Bi1;
rel A.Bi2l <-> B.Bi2?;
rel A.Bi3l <-> B.Bi3*;
rel A.Bi4l? <-> B.Bi4;
rel A.Bi5l? <-> B.Bi5?;
rel A.Bi6l? <-> B.Bi6*;
rel A.Bi7l* <-> B.Bi7;
rel A.Bi8l* <-> B.Bi8?;
rel A.Bi9l* <-> B.Bi9*;
aspect Utils {
inh Root ASTNode.root();
eq Root.getA(int i).root() = this;
eq Root.getB(int i).root() = this;
syn NamedElement Root.findNamedElement(String name) {
for (A a : getAList()) {
if (a.getName().equals(name)) {
return a;
}
}
for (B b : getBList()) {
if (b.getName().equals(name)) {
return b;
}
}
return null;
}
syn A Root.findA(String name) {
for (A a : getAList()) {
if (a.getName().equals(name)) {
return a;
}
}
return null;
}
syn B Root.findB(String name) {
for (B b : getBList()) {
if (b.getName().equals(name)) {
return b;
}
}
return null;
}
}
\ No newline at end of file
This diff is collapsed.
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