Commit 5d4b1506 authored by Johannes Mey's avatar Johannes Mey
Browse files

Merge branch 'mquat2' into 'master'

Mquat2

Closes #11, #6, and #5

See merge request johannes.mey/relast!1
parents 6cbd6486 3872f912
Pipeline #3456 passed with stage
in 59 seconds
.DS_Store *.jar
.idea/
.gradle/
build
src/gen-res/
src/gen/
out/
*.class *.class
.vimrc src/test/jastadd/*/*.ast
.*.swp src/test/jastadd/*/*.jadd
/*.relast src/test/jastadd/*/*ResolverStubs.jrag
!src/test/jastadd/*/MyRefResolver.jadd
/.settings
/bin/
/ant-bin/
/relast-compiler.jar
/src/generated/
/.gradle
/.idea/
*.iml
stages:
- build
test:
image: openjdk:8
stage: build
script:
- ./gradlew --no-daemon build
...@@ -2,13 +2,14 @@ ...@@ -2,13 +2,14 @@
Run preprocessor on train benchmark (output written to standard output): Run preprocessor on train benchmark (output written to standard output):
$ ant jar $ ./gradlew jar
$ cat examples/TrainBenchmark.relast $ cat examples/TrainBenchmark.relast
$ java -jar relast-compiler.jar examples/TrainBenchmark.relast $ java -jar relast-compiler.jar examples/TrainBenchmark.relast
$ java -jar build/libs/relast.jar examples/TrainBenchmark.relast
Run preprocessor and write output to files: Run preprocessor and write output to files:
$ java -jar relast-compiler.jar examples/TrainBenchmark.relast --file $ java -jar build/libs/relast.jar examples/TrainBenchmark.relast --file
$ cat examples/TrainBenchmarkGen.ast $ cat examples/TrainBenchmarkGen.ast
$ cat examples/TrainBenchmarkGen.jadd $ cat examples/TrainBenchmarkGen.jadd
......
import org.jastadd.relast.plugin.RelastTest
apply plugin: 'java'
apply plugin: 'jastadd'
apply plugin: 'application'
apply plugin: "idea"
apply plugin: "org.jastadd.relast.plugin"
sourceCompatibility = 1.8
mainClassName = 'org.jastadd.relast.compiler.Compiler'
repositories {
jcenter()
}
buildscript {
repositories.jcenter()
dependencies {
classpath 'org.jastadd:jastaddgradle:1.13.3'
}
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.0'
testCompile 'org.assertj:assertj-core:3.12.1'
compile 'com.fasterxml.jackson.core:jackson-core:2.9.8'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.8'
runtime 'org.jastadd:jastadd:2.3.2'
compile group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.10.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0'
}
sourceSets {
main {
java.srcDir "src/gen/java"
java.srcDir "buildSrc/gen/java"
}
test {
java.srcDir "src/test/java-gen"
}
}
jar {
manifest {
attributes "Main-Class": 'org.jastadd.relast.compiler.Compiler'
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
jastadd {
configureModuleBuild()
modules {
//noinspection GroovyAssignabilityCheck
module("RelAst") {
java {
basedir "."
include "src/main/**/*.java"
include "src/gen/**/*.java"
}
jastadd {
basedir "src/main/jastadd/"
include "**/*.ast"
include "**/*.jadd"
include "**/*.jrag"
}
scanner {
include "src/main/jastadd/RelAst.flex"
}
parser {
include "src/main/jastadd/Preamble.parser"
include "src/main/jastadd/RelAst.parser"
}
}
}
cleanGen.doFirst {
delete "src/gen/java/org"
delete "src/gen-res/BuildInfo.properties"
}
preprocessParser.doFirst {
args += ["--no-beaver-symbol"]
}
module = "RelAst"
astPackage = 'org.jastadd.relast.ast'
parser.name = 'RelAstParser'
genDir = 'src/gen/java'
buildInfoDir = 'src/gen-res'
scanner.genDir = "src/gen/java/org/jastadd/relast/scanner"
parser.genDir = "src/gen/java/org/jastadd/relast/parser"
jastaddOptions = ["--lineColumnNumbers", "--safeLazy", "--visitCheck=true", "--rewrite=cnta", "--cache=all"]
}
task preprocessRelationTest(type: JavaExec, group: 'verification') {
doFirst {
delete 'src/test/jastadd/relations/Relations.ast', 'src/test/jastadd/relations/Relations.jadd'
}
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
//noinspection GroovyAssignabilityCheck
args 'src/test/jastadd/relations/Relations.relast', '--useJastAddNames', '--file', '--grammarName=src/test/jastadd/relations/Relations'
}
task doublePreprocessRelationTest(type: JavaExec, group: 'verification') {
doFirst {
delete 'src/test/jastadd/relations/Relations2.ast', 'src/test/jastadd/relations/Relations2.jadd'
}
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
//noinspection GroovyAssignabilityCheck
args 'src/test/jastadd/relations/Relations.ast', '--useJastAddNames', '--file', '--grammarName=src/test/jastadd/relations/Relations2'
}
task compileRelationTest(type: JavaExec, group: 'verification') {
doFirst {
delete 'src/test/java-gen/relations'
}
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.JastAdd'
//noinspection GroovyAssignabilityCheck
args '--o=src/test/java-gen/', '--package=relations.ast',
'src/test/jastadd/relations/Relations.ast',
'src/test/jastadd/relations/Relations.jadd',
'src/test/jastadd/Utils.jadd'
}
test.dependsOn compileRelationTest
compileRelationTest.dependsOn doublePreprocessRelationTest
doublePreprocessRelationTest.dependsOn preprocessRelationTest
task compileDefaultNamesTest(type: RelastTest) {
relastFiles 'src/test/jastadd/relations/Relations.relast'
grammarName = 'src/test/jastadd/relations/Relations3'
packageName = 'defaultnames.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd'
}
task compileDefaultNamesResolverTest(type: RelastTest) {
relastFiles 'src/test/jastadd/resolver/Resolver.relast'
grammarName = 'src/test/jastadd/resolver/Resolver2'
resolverHelper = true
packageName = 'defaultnames.resolver.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd',
'src/test/jastadd/resolver/ResolverUtils.jadd',
'src/test/jastadd/resolver/MyRefResolver.jadd'
}
task compileLowerBoundsTest(type: RelastTest) {
relastFiles 'src/test/jastadd/lowerbounds/LowerBounds.relast'
grammarName = 'src/test/jastadd/lowerbounds/LowerBounds'
useJastAddNames = true
packageName = 'lowerbounds.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd'
}
task compileMultipleTest(type: RelastTest) {
relastFiles 'src/test/jastadd/multiple/Part1.relast',
'src/test/jastadd/multiple/Part2.relast',
'src/test/jastadd/multiple/Part3.relast'
grammarName = 'src/test/jastadd/multiple/Multiple'
useJastAddNames = true
packageName = 'multiple.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd'
}
task compileResolverTest(type: RelastTest) {
relastFiles 'src/test/jastadd/resolver/Resolver.relast'
grammarName = 'src/test/jastadd/resolver/Resolver'
useJastAddNames = true
resolverHelper = true
packageName = 'resolver.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd',
'src/test/jastadd/resolver/ResolverUtils.jadd',
'src/test/jastadd/resolver/MyRefResolver.jadd'
}
task compileResolver2Test(type: RelastTest) {
relastFiles 'src/test/jastadd/resolver2/Resolver.relast'
grammarName = 'src/test/jastadd/resolver2/Resolver'
useJastAddNames = true
resolverHelper = true
packageName = 'resolver2.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd',
'src/test/jastadd/resolver2/ResolverUtils.jadd',
'src/test/jastadd/resolver2/MyRefResolver.jadd'
}
task compileListNamesTest(type: RelastTest) {
relastFiles 'src/test/jastadd/listnames/ListNames.relast'
grammarName = 'src/test/jastadd/listnames/ListNames'
useJastAddNames = true
jastAddList = 'ListyMcListface'
packageName = 'listnames.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd'
}
task compileSerializerTest(type: RelastTest) {
relastFiles 'src/test/jastadd/serializer/Serializer.relast'
grammarName = 'src/test/jastadd/serializer/Serializer'
useJastAddNames = true
serializer = 'jackson'
packageName = 'serializer.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd'
}
task compileSerializerDefaultNamesTest(type: RelastTest) {
relastFiles 'src/test/jastadd/serializer-names/Serializer.relast'
grammarName = 'src/test/jastadd/serializer-names/Serializer'
serializer = 'jackson'
packageName = 'defaultnames.serializer.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd'
}
test {
outputs.upToDateWhen { false }
useJUnitPlatform()
}
<project name="RelAstCompiler" default="build" basedir=".">
<property name="srcdir" value="${basedir}/src" />
<property name="gendir" value="${srcdir}/generated" />
<property name="bindir" value="${basedir}/ant-bin" />
<property name="docdir" value="${basedir}/doc" />
<property name="tools" value="${basedir}/tools"/>
<property name="test-reports.dir" location="report-tests"/>
<property name="jarfile" value="relast-compiler.jar" />
<property name="junitjar" value="${tools}/junit-4.11-SNAPSHOT.jar" />
<!-- "package" is the directory where generated files will be stored -->
<property name="package" value="org.jastadd.relast.ast"/>
<loadresource property="package.path">
<propertyresource name="package"/>
<filterchain>
<tokenfilter>
<filetokenizer/>
<replacestring from="." to="/"/>
</tokenfilter>
</filterchain>
</loadresource>
<!-- Define Ant tasks -->
<taskdef name="jastadd" classname="org.jastadd.JastAddTask" classpath="${tools}/jastadd2.jar"/>
<taskdef name="jflex" classname="jflex.anttask.JFlexTask" classpath="${tools}/JFlex.jar"/>
<taskdef name="beaver" classname="beaver.comp.run.AntTask" classpath="${tools}/beaver.jar"/>
<!-- compile sources -->
<target name="build" depends="gen">
<mkdir dir="${bindir}" />
<javac
debug="true"
nowarn="true"
srcdir="${basedir}"
destdir="${bindir}"
includes="src/**/*.java"
classpath=".:${tools}/beaver-rt.jar:${junitjar}"
fork="true"
includeAntRuntime="false"
memoryMaximumSize="128M"
target="8"
source="8"
/>
</target>
<!-- generate compiler source files -->
<target name="gen" depends="scanner,parser">
<!-- create AST node types and weave aspect modules -->
<echo message = "Running JastAdd"/>
<jastadd package="${package}" rewrite="cnta" safeLazy="true" beaver="true" visitcheck="false"
lazyMaps="true" outdir="${gendir}" cache="all" lineColumnNumbers="true">
<fileset dir=".">
<include name="spec/jastadd/*.ast"/>
<include name="spec/jastadd/*.jadd"/>
<include name="spec/jastadd/*.jrag"/>
</fileset>
</jastadd>
</target>
<target name="scanner">
<jflex file="spec/scanner/RelAst.flex" outdir="${gendir}/${package.path}" InputStreamCtor="false" nobak="yes"/>
</target>
<target name="parser" depends="scanner">
<concat destfile="${gendir}/${package.path}/RelAstParser.all" binary="true" force="false">
<!-- we use filelist because the order is important -->
<filelist dir="spec/parser/">
<file name="Preamble.parser"/>
<file name="RelAstBase.parser"/>
</filelist>
</concat>
<!-- generate the parser phase 1, translating .parser to .beaver -->
<java classpath="${tools}/JastAddParser.jar:${tools}/beaver-rt.jar" classname="Main" fork="true">
<arg value="--no-beaver-symbol" />
<arg value="${gendir}/${package.path}/RelAstParser.all" />
<arg value="${gendir}/${package.path}/RelAstParser.beaver" />
</java>
<!-- generate the parser phase 2, translating .beaver to .java -->
<beaver file="${gendir}/${package.path}/RelAstParser.beaver" terminalNames="yes" compress="no" useSwitch="yes"/>
</target>
<!-- remove generated source files and .class files -->
<target name="clean">
<delete dir="${gendir}" />
<mkdir dir="${gendir}" />
<delete dir="${bindir}" />
<delete file="${jarfile}" />
<delete>
<fileset dir="." includes="**/*.class" excludes="bin/" />
</delete>
</target>
<target name="test" depends="build">
<mkdir dir="${test-reports.dir}"/>
<junit>
<classpath>
<pathelement path="${bindir}:${junitjar}:${tools}/beaver-rt.jar" />
</classpath>
<formatter type="brief" usefile="false" />
<batchtest todir="${test-reports.dir}">
<fileset dir="src/java">
<include name="org/jastadd/relast/tests/*.java" />
<include name="org/jastadd/relast/tests/codegen/*.java" />
</fileset>
</batchtest>
<formatter type="xml" />
</junit>
</target>
<target name="jar" depends="build">
<jar destfile="${jarfile}">
<fileset dir="${bindir}" includes="**/*.class" excludes="org/jastadd/relast/tests/*" />
<fileset dir="${srcdir}/java" includes="**/*.java" excludes="org/jastadd/relast/tests/*" />
<fileset dir="${gendir}" includes="**/*.java" />
<zipfileset includes="**/*.class" src="${tools}/beaver-rt.jar"/>
<manifest>
<attribute name="Main-Class" value="org.jastadd.relast.compiler.Compiler" />
</manifest>
</jar>
</target>
<target name="doc" depends="build" description="generate documentation">
<mkdir dir="${docdir}"/>
<javadoc
classpath="${gendir}:${tools}/beaver.jar"
destdir="${docdir}"
docletpath="${tools}/RagDoll.jar"
doclet="ragdoll.RagDollDoclet"
sourcepath="${gendir}">
<arg value="-linksource"/>
<arg value="-ragroot"/>
<arg value="."/>
</javadoc>
</target>
<!-- Run DrAST. Clone and build DrAST if it's not there -->
<target name="drast" depends="drast-init" >
<java jar="drast/DrAST-1.2.0.jar" fork="true" spawn="true" />
</target>
<target name="drast-init" depends="drast-check" unless="drast.exists" >
<exec executable="git">
<arg value="clone"/>
<arg value="git@bitbucket.org:jastadd/drast.git"/>
</exec>
<exec dir="drast" executable="./gradlew" />
</target>
<target name="drast-check">
<condition property="drast.exists">
<available file="drast" type="dir" />
</condition>
</target>
<target name="drast-update">
<delete dir="drast" />
<antcall target="drast-init" />
</target>
</project>
package org.jastadd.relast.plugin;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.tasks.TaskCollection;
import java.util.Set;
/**
* Plugin for RelAst-Test.
*
* @author rschoene - Initial contribution
*/
public class RelastPlugin implements Plugin<Project> {
private Task testTask;
@Override
public void apply(Project project) {
Set<Task> tasks = project.getTasksByName("test", false);
// there should be only one task "test"
testTask = tasks.iterator().next();
TaskCollection<RelastTest> relastTests = project.getTasks().withType(RelastTest.class);
relastTests.forEach(this::setupRelastTest);
relastTests.whenTaskAdded(this::setupRelastTest);
}
private void setupRelastTest(RelastTest relastTest) {
testTask.dependsOn(relastTest);
relastTest.setGroup("verification");
}
}
package org.jastadd.relast.plugin;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.file.FileCollection;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskAction;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* RelAst Test Task
*
* @author rschoene - Initial contribution
*/
@SuppressWarnings({"unused", "WeakerAccess"})
public class RelastTest extends DefaultTask {
// general options
private boolean verbose = false;
// pre-process options
private List<String> relastFiles = new ArrayList<>();
private boolean useJastAddNames;
private boolean resolverHelper;
private boolean writeToFile = true;
private String grammarName;
private String listClass;
private String jastAddList;
private String serializer;
// compile options
private boolean runJastAdd = true;
private String outputDir = "src/test/java-gen/";
private String packageName;
private List<String> moreInputFiles = new ArrayList<>();
public boolean isVerbose() {
return verbose;
}
public void setVerbose(boolean verbose) {
this.verbose = verbose;
}
// pre-process options
public List<String> getRelastFiles() {
return relastFiles;
}
public void relastFiles(String relastFile) {
this.relastFiles.add(relastFile);
}
public void relastFiles(String[] relastFilesArray) {
this.relastFiles = Arrays.asList(relastFilesArray);
}
public boolean isUseJastAddNames() {
return useJastAddNames;
}
public void setUseJastAddNames(boolean useJastAddNames) {
this.useJastAddNames = useJastAddNames;
}
public boolean isResolverHelper() {
return resolverHelper;
}
public void setResolverHelper(boolean resolverHelper) {
this.resolverHelper = resolverHelper;
}
public boolean isWriteToFile() {
return writeToFile;
}
public void setWriteToFile(boolean writeToFile) {
this.writeToFile = writeToFile;
}
public String getGrammarName() {
return grammarName;
}
public void setGrammarName(String grammarName) {
this.grammarName = grammarName;
}
public String getListClass() {
return listClass;
}
public void setListClass(String listClass) {
this.listClass = listClass;
}
public String getJastAddList() {
return jastAddList;
}
public void setJastAddList(String jastAddList) {
this.jastAddList = jastAddList;
}
public String getSerializer() {
return serializer;
}
public void setSerializer(String serializer) {
this.serializer = serializer;
}
// compile options
public boolean isRunJastAdd() {
return runJastAdd;
}
public void setRunJastAdd(boolean runJastAdd) {
this.runJastAdd = runJastAdd;
}
public String getOutputDir() {
return outputDir;
}