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:
UpperCase
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.processor 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 Alexander Schulz-Rosengarten <als@informatik.uni-kiel.de> */ class UpperCase 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 } } |
With KiCo 3.0 processors are no longer registered individually vie eclipse extension point. Instead a provider is created that is loaded via the service loader mechanism and that registers all the processors of a plugin in one batch.
First, create a new class TutorialProcessors
that implements the de.cau.cs.kieler.kicool.registration.IProcessorProvider
interface. Implement getProcessors() and return the UpperCase processor in a list.
Now the provider needs to be registered for KiCo to be able to find it. This is done according to the service loader specification:
META-INF
folder of your plugin project create a new folder named services
de.cau.cs.kieler.kicool.registration.IProcessorProvider
de.cau.cs.kieler.tutorials.kico.provider.TutorialProcessors
package de.cau.cs.kieler.tutorials.kico.provider import de.cau.cs.kieler.kicool.registration.IProcessorProvider import de.cau.cs.kieler.tutorials.kico.processor.UpperCase /** * Registers all tutorial processors. * @author Alexander Schulz-Rosengarten <als@informatik.uni-kiel.de> */ class TutorialProcessors implements IProcessorProvider { override getProcessors() { return #[ UpperCase ] } } |
A proccessor is only one unit in the compilation and KiCo uses Compilation Systems composed of proccessors (and systems) for compilation. Hence, to actually use our proccessor we need to include it in a system.
First, create a new folder for your systems in your plugin project, let's name it systems. Open the build.properties file in your project and tick the new folder in the Binary Build section. Otherwise your systems will nor be part of your jar when you deploy your plugin.
Now create a new file de.cau.cs.kieler.tutorials.uppercase.system in the systems folder and open it.
Compilation systems are written in their own DSL. If you want to have full editor support for system files, you can install the KIELER Semantics Framework feature into your development eclipse. For this tutorial just copy the code below into the file.
public system de.cau.cs.kieler.tutorials.uppercase label "Upper Case" de.cau.cs.kieler.tutorials.uppercase |
Same as processors