Skip to content
Snippets Groups Projects
Commit cb0a2b7a authored by René Schöne's avatar René Schöne
Browse files

WIP dumpAst 0.3.1

- changed package names to de.tudresden.inf.st.*
- begin with tests
- fixed some bugs while testing
parent 575c70bc
No related branches found
No related tags found
No related merge requests found
Pipeline #7861 failed
Showing
with 603 additions and 584 deletions
File moved
...@@ -4,7 +4,7 @@ apply plugin: 'idea' ...@@ -4,7 +4,7 @@ apply plugin: 'idea'
sourceCompatibility = 1.8 sourceCompatibility = 1.8
mainClassName = 'org.jastadd.dumpAst2uml.compiler.Compiler' mainClassName = 'de.tudresden.inf.st.jastadd.dumpAst.compiler.Compiler'
repositories { repositories {
jcenter() jcenter()
...@@ -82,9 +82,9 @@ task relast(type: JavaExec) { ...@@ -82,9 +82,9 @@ task relast(type: JavaExec) {
doFirst { doFirst {
delete "src/gen/jastadd/*.ast" delete "src/gen/jastadd/*.ast"
delete "src/gen/jastadd/DumpAst2.jadd" delete "src/gen/jastadd/DumpAst.jadd"
delete "src/gen/jastadd/DumpAstlRefResolver.jadd" delete "src/gen/jastadd/DumpAstRefResolver.jadd"
delete "src/gen/jastadd/DumpAstlResolverStubs.jrag" delete "src/gen/jastadd/DumpAstResolverStubs.jrag"
mkdir "src/gen/jastadd/" mkdir "src/gen/jastadd/"
} }
...@@ -97,12 +97,12 @@ task relast(type: JavaExec) { ...@@ -97,12 +97,12 @@ task relast(type: JavaExec) {
"--useJastAddNames", "--useJastAddNames",
"--file", "--file",
"--resolverHelper", "--resolverHelper",
"--grammarName=./src/gen/jastadd/DumpAst2" "--grammarName=./src/gen/jastadd/DumpAst"
] ]
inputs.files(file("../libs/relast.jar"), inputs.files(file("../libs/relast.jar"),
dumpAstGrammar) dumpAstGrammar)
outputs.files(file("./src/gen/jastadd/DumpAst2.ast"), outputs.files(file("./src/gen/jastadd/DumpAst.ast"),
file("./src/gen/jastadd/DumpAst.jadd"), file("./src/gen/jastadd/DumpAst.jadd"),
file("./src/gen/jastadd/DumpAstRefResolver.jadd"), file("./src/gen/jastadd/DumpAstRefResolver.jadd"),
file('./src/gen/jastadd/DumpAstResolverStubs.jrag')) file('./src/gen/jastadd/DumpAstResolverStubs.jrag'))
...@@ -112,28 +112,28 @@ jastadd { ...@@ -112,28 +112,28 @@ jastadd {
configureModuleBuild() configureModuleBuild()
modules { modules {
//noinspection GroovyAssignabilityCheck //noinspection GroovyAssignabilityCheck
module("DumpAst2Uml") { module("DumpAst") {
java { java {
basedir ".." basedir ".."
include "dumpAst2uml/src/main/**/*.java" include "dumpAst/src/main/**/*.java"
include "dumpAst2uml/src/gen/**/*.java" include "dumpAst/src/gen/**/*.java"
} }
jastadd { jastadd {
basedir ".." basedir ".."
include "dumpAst2uml/src/main/jastadd/**/*.ast" include "dumpAst/src/main/jastadd/**/*.ast"
include "dumpAst2uml/src/main/jastadd/**/*.jadd" include "dumpAst/src/main/jastadd/**/*.jadd"
include "dumpAst2uml/src/main/jastadd/**/*.jrag" include "dumpAst/src/main/jastadd/**/*.jrag"
include "dumpAst2uml/src/gen/jastadd/**/*.ast" include "dumpAst/src/gen/jastadd/**/*.ast"
include "dumpAst2uml/src/gen/jastadd/**/*.jadd" include "dumpAst/src/gen/jastadd/**/*.jadd"
include "dumpAst2uml/src/gen/jastadd/**/*.jrag" include "dumpAst/src/gen/jastadd/**/*.jrag"
} }
} }
} }
cleanGen.doFirst { cleanGen.doFirst {
delete "src/gen/java/org" delete "src/gen/java/de"
delete "src/gen-res/BuildInfo.properties" delete "src/gen-res/BuildInfo.properties"
} }
...@@ -143,8 +143,8 @@ jastadd { ...@@ -143,8 +143,8 @@ jastadd {
} }
module = "DumpAst2Uml" module = "DumpAst"
astPackage = 'org.jastadd.dumpAst2uml.ast' astPackage = 'de.tudresden.inf.st.jastadd.dumpAst.ast'
genDir = 'src/gen/java' genDir = 'src/gen/java'
buildInfoDir = 'src/gen-res' buildInfoDir = 'src/gen-res'
jastaddOptions = ["--lineColumnNumbers", "--List=JastAddList", "--safeLazy", "--visitCheck=true", "--rewrite=cnta", "--cache=all"] jastaddOptions = ["--lineColumnNumbers", "--List=JastAddList", "--safeLazy", "--visitCheck=true", "--rewrite=cnta", "--cache=all"]
......
...@@ -10,8 +10,6 @@ abstract DumpChildNode ::= <Name> ; ...@@ -10,8 +10,6 @@ abstract DumpChildNode ::= <Name> ;
DumpNormalChildNode : DumpChildNode ; DumpNormalChildNode : DumpChildNode ;
rel DumpNormalChildNode.DumpNode -> DumpNode ; rel DumpNormalChildNode.DumpNode -> DumpNode ;
DumpListChildNode : DumpChildNode ::= InnerDumpNode* ; DumpListChildNode : DumpChildNode ::= InnerDumpNode* ;
//DumpOptChildNode : DumpChildNode ;
//rel DumpOptChildNode.DumpNode? -> DumpNode ;
abstract DumpToken ::= <Name> ; abstract DumpToken ::= <Name> ;
DumpReferenceToken : DumpToken ; DumpReferenceToken : DumpToken ;
...@@ -22,5 +20,3 @@ abstract DumpRelation ::= <Name> <Bidirectional:boolean> ; ...@@ -22,5 +20,3 @@ abstract DumpRelation ::= <Name> <Bidirectional:boolean> ;
DumpNormalRelation : DumpRelation ; DumpNormalRelation : DumpRelation ;
rel DumpNormalRelation.DumpNode -> DumpNode ; rel DumpNormalRelation.DumpNode -> DumpNode ;
DumpListRelation : DumpRelation ::= InnerDumpNode* ; DumpListRelation : DumpRelation ::= InnerDumpNode* ;
//DumpOptRelation : DumpRelation ;
//rel DumpOptRelation.DumpNode? -> DumpNode ;
aspect Generation { aspect GenerationFrontend {
public class Dumper { public class Dumper {
public static DumpBuilder read(Object obj) { public static DumpBuilder read(Object obj) {
return new DumpBuilder(obj); return new DumpBuilder(obj);
...@@ -127,6 +127,9 @@ aspect Generation { ...@@ -127,6 +127,9 @@ aspect Generation {
return this; return this;
} }
} }
}
aspect GenerationBackend {
// --- transform --- (need to be a method, because it alters the AST while traversing the object structure) // --- transform --- (need to be a method, because it alters the AST while traversing the object structure)
// maybe return type is unncessary // maybe return type is unncessary
protected DumpNode DumpAst.transform(TransformationTransferInformation tti, Object obj) protected DumpNode DumpAst.transform(TransformationTransferInformation tti, Object obj)
...@@ -179,8 +182,10 @@ aspect Generation { ...@@ -179,8 +182,10 @@ aspect Generation {
listChild.addInnerDumpNode(new InnerDumpNode(targetNode)); listChild.addInnerDumpNode(new InnerDumpNode(targetNode));
} }
} }
if (listChild.getNumInnerDumpNode() > 0) {
node.addDumpChildNode(listChild); node.addDumpChildNode(listChild);
} }
}
// -- singleRelation -- // -- singleRelation --
for (java.lang.reflect.Method method : car.singleRelationMethods) { for (java.lang.reflect.Method method : car.singleRelationMethods) {
Object target = method.invoke(obj); Object target = method.invoke(obj);
...@@ -203,8 +208,10 @@ aspect Generation { ...@@ -203,8 +208,10 @@ aspect Generation {
listRelation.addInnerDumpNode(new InnerDumpNode(targetNode)); listRelation.addInnerDumpNode(new InnerDumpNode(targetNode));
} }
} }
if (listRelation.getNumInnerDumpNode() > 0) {
node.addDumpRelation(listRelation); node.addDumpRelation(listRelation);
} }
}
// -- token -- // -- token --
for (java.lang.reflect.Method method : car.tokenMethods) { for (java.lang.reflect.Method method : car.tokenMethods) {
Object target = method.invoke(obj); Object target = method.invoke(obj);
...@@ -241,13 +248,26 @@ aspect Generation { ...@@ -241,13 +248,26 @@ aspect Generation {
String simpleName = annotation.annotationType().getSimpleName(); String simpleName = annotation.annotationType().getSimpleName();
switch (simpleName) { switch (simpleName) {
case "Child": case "Child":
case "OptChild":
String singleChildName = invokeName(annotation); String singleChildName = invokeName(annotation);
if (!matches(buildConfig().childIgnorePattern(), singleChildName)) { if (!matches(buildConfig().childIgnorePattern(), singleChildName)) {
result.singleChildMethods.add(method); result.singleChildMethods.add(method);
result.names.put(method, singleChildName); result.names.put(method, singleChildName);
} }
break; break;
case "OptChild":
String optChildName = invokeName(annotation);
if (!matches(buildConfig().childIgnorePattern(), optChildName)) {
try {
// the annotated method is "get???Opt", but we want "get???"
java.lang.reflect.Method realGetter = clazz.getMethod("get" + optChildName);
result.singleChildMethods.add(realGetter);
result.names.put(realGetter, optChildName);
} catch (NoSuchMethodException e) {
System.err.println("Could not find getter for Opt-child " + optChildName + " in " + clazz.getName());
throw new RuntimeException(e);
}
}
break;
case "ListChild": case "ListChild":
String listChildName = invokeName(annotation); String listChildName = invokeName(annotation);
if (!matches(buildConfig().childIgnorePattern(), listChildName)) { if (!matches(buildConfig().childIgnorePattern(), listChildName)) {
...@@ -259,7 +279,7 @@ aspect Generation { ...@@ -259,7 +279,7 @@ aspect Generation {
// heuristic for relations // heuristic for relations
String tokenName = invokeName(annotation); String tokenName = invokeName(annotation);
if (tokenName.startsWith("_impl_")) { if (tokenName.startsWith("_impl_")) {
String relationName = tokenName.substring(6); String relationName = titleCase(tokenName.substring(6));
try { try {
java.lang.reflect.Method relationMethod = clazz.getMethod("get" + relationName); java.lang.reflect.Method relationMethod = clazz.getMethod("get" + relationName);
// normal get + token-name -> singleRelation // normal get + token-name -> singleRelation
...@@ -289,6 +309,10 @@ aspect Generation { ...@@ -289,6 +309,10 @@ aspect Generation {
result.names.put(method, tokenName); result.names.put(method, tokenName);
} }
break; break;
case "Attribute":
// TODO. check for isNTA=true. then check for whether target is instance of iterable. if so, add to listChildren, otherwise to singelChild
// TODO. if isNTA=false, then handle attribute
break
} }
} }
} }
...@@ -296,6 +320,13 @@ aspect Generation { ...@@ -296,6 +320,13 @@ aspect Generation {
return result; return result;
} }
private String DumpNode.titleCase(String s) {
if (s.isEmpty()) {
return s;
}
return Character.toUpperCase(s.charAt(0)) + s.substring(1);
}
syn java.util.regex.Pattern BuildConfig.typeIgnorePattern() = java.util.regex.Pattern.compile(getTypeIgnore()); syn java.util.regex.Pattern BuildConfig.typeIgnorePattern() = java.util.regex.Pattern.compile(getTypeIgnore());
syn java.util.regex.Pattern BuildConfig.childIgnorePattern() = java.util.regex.Pattern.compile(getChildIgnore()); syn java.util.regex.Pattern BuildConfig.childIgnorePattern() = java.util.regex.Pattern.compile(getChildIgnore());
syn java.util.regex.Pattern BuildConfig.tokenIgnorePattern() = java.util.regex.Pattern.compile(getTokenIgnore()); syn java.util.regex.Pattern BuildConfig.tokenIgnorePattern() = java.util.regex.Pattern.compile(getTokenIgnore());
......
...@@ -9,9 +9,15 @@ aspect Navigation { ...@@ -9,9 +9,15 @@ aspect Navigation {
syn boolean DumpToken.isDumpValueToken() = false; syn boolean DumpToken.isDumpValueToken() = false;
eq DumpValueToken.isDumpValueToken() = true; eq DumpValueToken.isDumpValueToken() = true;
// --- asDumpValueToken ---
syn DumpValueToken DumpToken.asDumpValueToken() = null;
eq DumpValueToken.asDumpValueToken() = this;
// --- buildConfig ---
inh BuildConfig DumpNode.buildConfig(); inh BuildConfig DumpNode.buildConfig();
eq DumpAst.getChild().buildConfig() = getBuildConfig(); eq DumpAst.getChild().buildConfig() = getBuildConfig();
// --- printConfig ---
inh PrintConfig BuildConfig.printConfig(); inh PrintConfig BuildConfig.printConfig();
eq DumpAst.getChild().printConfig() = getPrintConfig(); eq DumpAst.getChild().printConfig() = getPrintConfig();
} }
package org.jastadd.dumpAst2uml.compiler; package de.tudresden.inf.st.jastadd.dumpAst;
import beaver.Parser; import beaver.Parser;
import org.jastadd.dumpAst2uml.ast.*; import de.tudresden.inf.st.jastadd.dumpAst.ast.*;
import org.jastadd.grammar2uml.ast.*; import de.tudresden.inf.st.jastadd.grammar2uml.ast.*;
import org.jastadd.grammar2uml.parser.Grammar2UmlParser; import de.tudresden.inf.st.jastadd.grammar2uml.parser.Grammar2UmlParser;
import org.jastadd.grammar2uml.scanner.Grammar2UmlScanner; import de.tudresden.inf.st.jastadd.grammar2uml.scanner.Grammar2UmlScanner;
import java.io.*; import java.io.BufferedReader;
import java.io.IOException;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
...@@ -14,12 +15,10 @@ import java.lang.reflect.Method; ...@@ -14,12 +15,10 @@ import java.lang.reflect.Method;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern;
import static org.jastadd.dumpAst2uml.compiler.SimpleMain.Kind.*; import static de.tudresden.inf.st.jastadd.dumpAst.SimpleMain.Kind.*;
/** /**
* Testing Relast2Uml without parser. * Testing Relast2Uml without parser.
......
#Fri Sep 11 23:37:05 CEST 2020
version=0.3.1
#Sat Sep 05 23:54:45 CEST 2020
version=0.3
...@@ -4,7 +4,7 @@ apply plugin: 'idea' ...@@ -4,7 +4,7 @@ apply plugin: 'idea'
sourceCompatibility = 1.8 sourceCompatibility = 1.8
mainClassName = 'org.jastadd.grammar2uml.compiler.Compiler' mainClassName = 'de.tudresden.inf.st.jastadd.grammar2uml.compiler.Compiler'
repositories { repositories {
jcenter() jcenter()
...@@ -162,7 +162,7 @@ jastadd { ...@@ -162,7 +162,7 @@ jastadd {
} }
cleanGen.doFirst { cleanGen.doFirst {
delete "src/gen/java/org" delete "src/gen/java/de"
delete "src/gen-res/BuildInfo.properties" delete "src/gen-res/BuildInfo.properties"
} }
...@@ -174,7 +174,7 @@ jastadd { ...@@ -174,7 +174,7 @@ jastadd {
module = "Grammar2Uml" module = "Grammar2Uml"
astPackage = 'org.jastadd.grammar2uml.ast' astPackage = 'de.tudresden.inf.st.jastadd.grammar2uml.ast'
parser.name = 'Grammar2UmlParser' parser.name = 'Grammar2UmlParser'
...@@ -182,8 +182,8 @@ jastadd { ...@@ -182,8 +182,8 @@ jastadd {
buildInfoDir = 'src/gen-res' buildInfoDir = 'src/gen-res'
scanner.genDir = "src/gen/java/org/jastadd/grammar2uml/scanner" scanner.genDir = "src/gen/java/de/tudresden/inf/st/jastadd/grammar2uml/scanner"
parser.genDir = "src/gen/java/org/jastadd/grammar2uml/parser" parser.genDir = "src/gen/java/de/tudresden/inf/st/jastadd/grammar2uml/parser"
jastaddOptions = ["--lineColumnNumbers", "--List=JastAddList", "--safeLazy", "--visitCheck=true", "--rewrite=cnta", "--cache=all"] jastaddOptions = ["--lineColumnNumbers", "--List=JastAddList", "--safeLazy", "--visitCheck=true", "--rewrite=cnta", "--cache=all"]
} }
......
...@@ -186,7 +186,30 @@ aspect AspectGeneration { ...@@ -186,7 +186,30 @@ aspect AspectGeneration {
com.github.mustachejava.DefaultMustacheFactory mf = new com.github.mustachejava.DefaultMustacheFactory(); com.github.mustachejava.DefaultMustacheFactory mf = new com.github.mustachejava.DefaultMustacheFactory();
// mf.setObjectHandler(roh); // mf.setObjectHandler(roh);
com.github.mustachejava.Mustache m = mf.compile("grammar2uml.mustache"); com.github.mustachejava.Mustache m = mf.compile("grammar2uml.mustache");
m.execute(new java.io.PrintWriter(new org.jastadd.grammar2uml.compiler.AppendableWriter(sb)), this); m.execute(new java.io.PrintWriter(new AppendableWriter(sb)), this);
return sb.toString(); return sb.toString();
} }
public class AppendableWriter extends java.io.Writer {
private final StringBuilder sb;
public AppendableWriter(StringBuilder sb) {
this.sb = sb;
}
@Override
public void write(char[] chars, int off, int len) {
sb.append(chars, off, len);
}
@Override
public void write(String str) {
sb.append(str);
}
@Override
public void flush() {}
@Override
public void close() {}
}
} }
%header {: %header {:
package org.jastadd.grammar2uml.parser; package de.tudresden.inf.st.jastadd.grammar2uml.parser;
import org.jastadd.grammar2uml.ast.*; import de.tudresden.inf.st.jastadd.grammar2uml.ast.*;
:}; :};
%goal goal; %goal goal;
......
package org.jastadd.grammar2uml.scanner; package de.tudresden.inf.st.jastadd.grammar2uml.scanner;
import org.jastadd.grammar2uml.parser.Grammar2UmlParser.Terminals; import de.tudresden.inf.st.jastadd.grammar2uml.parser.Grammar2UmlParser.Terminals;
%% %%
%public %public
......
package org.jastadd.grammar2uml.compiler; package de.tudresden.inf.st.jastadd.grammar2uml.compiler;
import beaver.Parser; import beaver.Parser;
import org.jastadd.option.BooleanOption; import org.jastadd.option.BooleanOption;
import org.jastadd.option.ValueOption; import org.jastadd.option.ValueOption;
import org.jastadd.relast.compiler.AbstractCompiler; import org.jastadd.relast.compiler.AbstractCompiler;
import org.jastadd.relast.compiler.CompilerException; import org.jastadd.relast.compiler.CompilerException;
import org.jastadd.grammar2uml.ast.ErrorMessage; import de.tudresden.inf.st.jastadd.grammar2uml.ast.ErrorMessage;
import org.jastadd.grammar2uml.ast.GrammarFile; import de.tudresden.inf.st.jastadd.grammar2uml.ast.GrammarFile;
import org.jastadd.grammar2uml.ast.Program; import de.tudresden.inf.st.jastadd.grammar2uml.ast.Program;
import org.jastadd.grammar2uml.ast.Grammar2Uml; import de.tudresden.inf.st.jastadd.grammar2uml.ast.Grammar2Uml;
import org.jastadd.grammar2uml.parser.Grammar2UmlParser; import de.tudresden.inf.st.jastadd.grammar2uml.parser.Grammar2UmlParser;
import org.jastadd.grammar2uml.scanner.Grammar2UmlScanner; import de.tudresden.inf.st.jastadd.grammar2uml.scanner.Grammar2UmlScanner;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
......
package org.jastadd.grammar2uml.compiler; package de.tudresden.inf.st.jastadd.grammar2uml.compiler;
import beaver.Parser; import beaver.Parser;
import org.jastadd.grammar2uml.ast.*; import de.tudresden.inf.st.jastadd.grammar2uml.ast.*;
import org.jastadd.grammar2uml.parser.Grammar2UmlParser; import de.tudresden.inf.st.jastadd.grammar2uml.parser.Grammar2UmlParser;
import org.jastadd.grammar2uml.scanner.Grammar2UmlScanner; import de.tudresden.inf.st.jastadd.grammar2uml.scanner.Grammar2UmlScanner;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
......
package org.jastadd.grammar2uml.compiler; package de.tudresden.inf.st.jastadd.grammar2uml.compiler;
import java.util.*; import java.util.*;
import java.util.function.Predicate; import java.util.function.Predicate;
......
package org.jastadd.grammar2uml.compiler;
import java.io.IOException;
import java.io.Writer;
/**
* Writer appending to a StringBuilder.
*
* @author rschoene - Initial contribution
*/
public class AppendableWriter extends Writer {
private final StringBuilder sb;
public AppendableWriter(StringBuilder sb) {
this.sb = sb;
}
@Override
public void write(char[] chars, int off, int len) throws IOException {
sb.append(chars, off, len);
}
@Override
public void write(String str) throws IOException {
sb.append(str);
}
@Override
public void flush() {
}
@Override
public void close() {
}
}
package org.jastadd.grammar2uml.test; package de.tudresden.inf.st.jastadd.grammar2uml.test;
import org.jastadd.relast.compiler.CompilerException; import org.jastadd.relast.compiler.CompilerException;
import org.jastadd.grammar2uml.compiler.Compiler; import de.tudresden.inf.st.jastadd.grammar2uml.compiler.Compiler;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.io.File; import java.io.File;
......
...@@ -2,4 +2,5 @@ rootProject.name = 'relast2uml' ...@@ -2,4 +2,5 @@ rootProject.name = 'relast2uml'
include 'relast.preprocessor' include 'relast.preprocessor'
include 'grammar2uml' include 'grammar2uml'
include 'dumpAst2uml' include 'dumpAst'
include 'testDumper'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment