Steven Smyth and Alexander Schulz-Rosengarten and Reinhard von Hanxleden. Towards Interactive Compilation Models. In Proceedings of the 8th International Symposium on Leveraging Applications of Formal Methods, Verification and Validation (ISoLA 2018), volume 11244 of LNCS, page 246–260, Limassol, Cyprus, November 2018. Springer. |
In this tutorial we will set up a plugin for KiCo compilation systems and create processor that will convert a text file into a text file with all upper case characters.
To use and develop with KiCo you need to setup or integrate the KiCo framework into your Eclipse IDE. There are two scenarios:
For this tutorial we will create a new eclipse plugin to carry our processors and systems.
de.cau.cs.kieler.tutorials.kico
. Click Next.KiCo Tutorial
. Uncheck all checkboxes in Options. Click Finish.de.cau.cs.kieler.kicool
(see screenshot).For implementing processors we recommend the language Xtend. In this tutorial we will use Xtend for all implementations. However, you can of cause use plain Java instead. Xtend will require a few more plugin dependencies and we have some tutorials on Xtend you may want to look into beforehand.
To create our new processor:
UpperCaseProcessor
extend de.cau.cs.kieler.kicool.compilation.Processor
de.cau.cs.kieler.kicool.compilation.CodeContainer
as input and output type.getId()
should return a unique id of the processor: de.cau.cs.kieler.tutorials.uppercasegetName()
should return a human readable name for our processor: Upper CasegetType()
returns the "job" of the processor. Here we have the processor that should transform the input and have the same meta-model (or type since CodeContainer is not EMF based) as input and output type we return ProcessorType.ENDOGENOUS_TRANSFORMATOR
.Now we can implement the actual transformation in process()
. Note that the method has no parameters because all information are accessed via getters from the environment of the processor. Thanks to Xtend, these getter can be accesses as they were fields in the class. Hence, to convert all character in the input file to upper case the following line is sufficient:
model.files.head.code.toUpperCase
model
get the input model from the environment. files
access the list of files in this CodeContainer
. Since we know that the input at this point is always a single file, we access the first file in the list with head
and convert the code
sting in this file to upper case.
Since we have a transformation on the same meta-model we create the output of our transformation by changing/remodeling our input directly (the input is actually a copy made by KiCo). Hence, in this case there is no more to do here. If we would write an EXOGENOUS_TRANSFORMATOR
we would need to create a new target model instance and set it as result explicitly with model = <myNewModel>
but this will be addressed in more detail in later tutorials.
package de.cau.cs.kieler.tutorials.kico import de.cau.cs.kieler.kicool.compilation.Processor import de.cau.cs.kieler.kicool.compilation.ProcessorType import de.cau.cs.kieler.kicool.compilation.CodeContainer /** * Converts all characters of an input file into upper case. * @author als */ class UpperCaseProcessor extends Processor<CodeContainer, CodeContainer> { override getId() { return "de.cau.cs.kieler.tutorials.uppercase" } override getName() { return "Upper Case" } override getType() { return ProcessorType.ENDOGENOUS_TRANSFORMATOR } override process() { model.files.head.code.toUpperCase } } |