This homework continues the Xtext exercise from homework #10. This time, you have to generate Java code from EngineeringC code. Add this example model to your EngineeringC project:
EngineeringCDiagram diag {
ECBlockDecl test {
ECStore x {
value : "0"
}
ECStore y {
value : "7"
}
ECComputeBlock comp1 {
expression : "x = 6 * y"
}
}
ECBlockDecl callTest {
ECStore z {
value : "0"
}
ECBlockAppl callTest {
instanceof : test
}
ECComputeBlock comp2 {
expression : "z = x + 42"
}
}
}
(Remember to first modify your grammar before creating a code generation template!)
The generated Java code should calculate the correct result for all ECComputeBlocks. To ensure this, create a JUnit test in the same package as the generated class. Call the generated methods from the test and ensure that the expected values are computed. To make cross-block variable access possible, you have to modify the Xpand template so that these variables are accessible from the generated methods.
Xtext Workflow from the lecture:
<workflow>
<property file="workflow.properties"/>
<component class="org.eclipse.xtext.MweReader" uri="${modelFile}">
<register class="de.unikassel.se.compilerbau.ECStandaloneSetup"/>
</component>
<component id="generator" class="org.eclipse.xpand2.Generator">
<metaModel id="mm" class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
<metaModelPackage value="de.unikassel.se.compilerbau.eC.ECPackage"/>
</metaModel>
<expand value="GenerateEC::Root FOR model"/>
<outlet path="${srcGenPath}/">
<postprocessor class="org.eclipse.xpand2.output.JavaBeautifier"/>
</outlet>
</component>
</workflow>
Helpful links: