diff --git a/libs/ecore2relast-0.1.jar b/libs/ecore2relast-0.1.jar new file mode 100644 index 0000000000000000000000000000000000000000..fc7098d7a8c5169277c6cf5c199b01424e1a8862 Binary files /dev/null and b/libs/ecore2relast-0.1.jar differ diff --git a/statemachine/build.gradle b/statemachine/build.gradle index cf7835e9d8ae4b2cbd0e890da1dc21ab06862986..3e1e392fd76220d282b152944898b343c37f24a2 100644 --- a/statemachine/build.gradle +++ b/statemachine/build.gradle @@ -77,37 +77,51 @@ task jarDrAst(type: Jar) { with jar } -task runDrAST(type: JavaExec, dependsOn:jar) { +task runDrAST(type: JavaExec, dependsOn: jar) { group = "application" description = 'run the DrAST visual debugger tool' classpath = sourceSets.main.runtimeClasspath main = 'de.tudresden.inf.st.statemachine.DrAstRunner' } -def relastFiles = fileTree('src/main/jastadd/') { - include '**/*.relast' }.toList().toArray() +def relastFiles = fileTree('src/main/jastadd/') { include '**/*.relast' } + + fileTree('src/gen/jastadd/') { include '**/*.relast' } String[] relastArguments = [ "../libs/relast.jar", - "--grammarName=./src/gen/jastadd/StatemachineGen", + "--grammarName=./src/gen/jastadd/StateMachine", "--useJastAddNames", "--listClass=ArrayList", "--jastAddList=JastAddList", "--resolverHelper", "--file" ] -task preprocess(type: JavaExec) { +def ecoreFile = "./src/main/resources/StateMachine.ecore" +def relastFile = "./src/gen/jastadd/StateMachine.relast" + +task ecoreToRelast(type: JavaExec) { group = 'Build' main = "-jar" + doFirst { delete "src/gen/jastadd" mkdir "src/gen/jastadd" } + args "../libs/ecore2relast-0.1.jar", ecoreFile, relastFile + + inputs.files file(ecoreFile) + outputs.files file(relastFile) +} + +task preprocess(type: JavaExec) { + group = 'Build' + main = "-jar" + args relastArguments + relastFiles inputs.files relastFiles - outputs.files file("./src/main/jastadd/StatemachineGen.ast"), file("./src/main/jastadd/StatemachineGen.jadd") + outputs.files file("./src/gen/jastadd/StateMachine.ast"), file("./src/gen/jastadd/StateMachine.jadd") } jastadd { @@ -181,9 +195,8 @@ task copyRagdoc(type: Copy, dependsOn: cleanRagdoc) { eachFile { println it.file } } +preprocess.dependsOn ecoreToRelast generateAst.dependsOn preprocess -//generateAst.inputs.files file("./src/main/jastadd/StatemachineGen.ast"), file("./src/main/jastadd/StatemachineGen.jadd") -//compileJava.dependsOn jastadd -// + //// always run jastadd //jastadd.outputs.upToDateWhen {false} diff --git a/statemachine/src/main/jastadd/StateMachine.relast b/statemachine/src/main/jastadd/StateMachine.relast deleted file mode 100644 index 525070d79b683a99811f5c398f4df20ffc2815a7..0000000000000000000000000000000000000000 --- a/statemachine/src/main/jastadd/StateMachine.relast +++ /dev/null @@ -1,9 +0,0 @@ -StateMachine ::= Element*; -abstract Element ::= <Label:String>; -State : Element; -Transition : Element; - -rel Transition.From <-> State.Outgoing*; -rel Transition.To <-> State.Incoming*; -rel StateMachine.Initial -> State; -rel StateMachine.Final* -> State; diff --git a/statemachine/src/main/java/de/tudresden/inf/st/statemachine/Main.java b/statemachine/src/main/java/de/tudresden/inf/st/statemachine/Main.java index ea757e857e6616c29c30471d347bd3e0bae6f81b..ab27666ea8434cb8b6fca20ca1acfe163eae1e46 100644 --- a/statemachine/src/main/java/de/tudresden/inf/st/statemachine/Main.java +++ b/statemachine/src/main/java/de/tudresden/inf/st/statemachine/Main.java @@ -1,71 +1,69 @@ package de.tudresden.inf.st.statemachine; import beaver.Parser; -import de.tudresden.inf.st.statemachine.jastadd.model.DotGraph; import de.tudresden.inf.st.statemachine.jastadd.model.State; import de.tudresden.inf.st.statemachine.jastadd.model.StateMachine; import de.tudresden.inf.st.statemachine.jastadd.model.Transition; import java.io.IOException; import java.nio.file.Paths; -import java.util.Set; public class Main { - @SuppressWarnings("WeakerAccess") - public static Object DrAST_root_node; + @SuppressWarnings("WeakerAccess") + public static Object DrAST_root_node; - public static void main(String[] args) { - if (args.length == 0) { - // manual construction of a simple statemachine - // (S) -- 1 --> (B) -- 3 --> (E) - // ^ | - // \ / - // `---- 2 ----* - StateMachine stateMachine = new StateMachine(); - State start = new State(); - start.setLabel("S"); - State stateB = new State(); - stateB.setLabel("B"); - State end = new State(); - end.setLabel("E"); - Transition t1 = new Transition(); - t1.setLabel("1"); - Transition t2 = new Transition(); - t2.setLabel("2"); - Transition t3 = new Transition(); - t3.setLabel("3"); - t1.setFrom(start); - t1.setTo(stateB); - t2.setFrom(stateB); - t2.setTo(start); - t3.setFrom(stateB); - t3.setTo(end); - stateMachine.addElement(start); - stateMachine.addElement(stateB); - stateMachine.addElement(end); - stateMachine.addElement(t1); - stateMachine.addElement(t2); - stateMachine.addElement(t3); - stateMachine.setInitial(start); - stateMachine.addFinal(end); + public static void main(String[] args) { + if (args.length == 0) { + // manual construction of a simple statemachine + // (S) -- 1 --> (B) -- 3 --> (E) + // ^ | + // \ / + // `---- 2 ----* + StateMachine stateMachine = new StateMachine(); + State start = new State(); + start.setLabel("S"); + State stateB = new State(); + stateB.setLabel("B"); + State end = new State(); + end.setLabel("E"); + Transition t1 = new Transition(); + t1.setLabel("1"); + Transition t2 = new Transition(); + t2.setLabel("2"); + Transition t3 = new Transition(); + t3.setLabel("3"); + t1.setFrom(start); + t1.setTo(stateB); + t2.setFrom(stateB); + t2.setTo(start); + t3.setFrom(stateB); + t3.setTo(end); + stateMachine.addElement(start); + stateMachine.addElement(stateB); + stateMachine.addElement(end); + stateMachine.addElement(t1); + stateMachine.addElement(t2); + stateMachine.addElement(t3); + stateMachine.setInitial(start); + stateMachine.addFinal(end); - System.out.println(stateMachine.prettyPrint()); - stateMachine.printSomeAnalysis(); - DrAST_root_node = stateMachine; - } else { - // load the file given as first argument - try { - StateMachine stateMachine = ParserUtils.load(Paths.get(args[0])); - stateMachine.treeResolveAll(); + System.out.println(stateMachine.prettyPrint()); + stateMachine.printSomeAnalysis(); + DrAST_root_node = stateMachine; + } else { + // load the file given as first argument + try { + StateMachine stateMachine = ParserUtils.load(Paths.get(args[0])); + stateMachine.treeResolveAll(); stateMachine.printSomeAnalysis(); - System.out.println("> toDotGraph():"); - System.out.println(stateMachine.toDot()); - DrAST_root_node = stateMachine; - } catch (IOException | Parser.Exception e) { - e.printStackTrace(); - } - } - } + System.out.println("> toDotGraph():"); + System.out.println(stateMachine.toDot()); + DrAST_root_node = stateMachine; + } catch (IOException | Parser.Exception e) { + e.printStackTrace(); + } + } + } } diff --git a/statemachine/src/main/resources/StateMachine.ecore b/statemachine/src/main/resources/StateMachine.ecore new file mode 100644 index 0000000000000000000000000000000000000000..d2f3afeefd28471f3c5d9e855e36b76822ca67c7 --- /dev/null +++ b/statemachine/src/main/resources/StateMachine.ecore @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="statemachine" nsURI="http://www.example.org/statemachine" nsPrefix="statemachine"> + <eClassifiers xsi:type="ecore:EClass" name="StateMachine"> + <eStructuralFeatures xsi:type="ecore:EReference" name="element" upperBound="-1" + eType="#//Element" containment="true"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="initial" lowerBound="1" + eType="#//State"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="final" upperBound="-1" + eType="#//State"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="Element" abstract="true"> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="label" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="State" eSuperTypes="#//Element"> + <eStructuralFeatures xsi:type="ecore:EReference" name="outgoing" upperBound="-1" + eType="#//Transition" eOpposite="#//Transition/from"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="incoming" upperBound="-1" + eType="#//Transition" eOpposite="#//Transition/to"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="Transition" eSuperTypes="#//Element"> + <eStructuralFeatures xsi:type="ecore:EReference" name="from" lowerBound="1" eType="#//State" + eOpposite="#//State/outgoing"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="to" lowerBound="1" eType="#//State" + eOpposite="#//State/incoming"/> + </eClassifiers> +</ecore:EPackage>