Ander Zubizarreta	9/1/2009DSLto  C++Sysdefcodegenerationusing MDWorkbench
ProblemDefinitionWehave a source XML filedescribing a system, accordingto a XML SchemametamodelSystem has manyelements of thetypeControllableThegoalistogeneratea cppimplementationforeachControllabletypeelement
ProblemdefinitionXSD
ProblemDefinitionSourceXML fileThe XML file describes a systemThesystem has manycontrollablesEachcontrollable has inputs, outputs, params, faults…Target.h and .cppfileforeachControllableThe generation of the .H file is straightforwardThe generation of the .CPP file comprises several RuleSetsLocals:For each input/output/param/fault/timer define a local of that typedoInit\\ initialize each local variable\\ by getting its value (using mappings in wtsl)WHY IS USED?We’ll use MDWorkbench forthatpurpose
MDWorkbenchMDWorkbench is a model-driven engineering development environment to build:Source code and text generatorsWord documentationModel transformersEclipse-based IDEJava code may be used in MDWorkbench projectsDeveloped by Sodius SAS
MDWorkbench
SolutionMetamodelC++ codeModelRulesTemplates
StepsImportthemetamodelto MDWorkbenchBrowsethemodelusing MDWorkbenchCreatetherulesets and templatesforcodegenerationRunthegenerator
1. Importing a metamodelMDWorkbench nativelyallowstoworkwithEcore, Relationalor UML modelsNew metamodels can beimported, allowingtoworkwithdifferentkind of modelsImporting a metamodelconsists in creatingan Eclipse pluginwhichwillbeusedby MDWorkbenchOurmetamodelisdefinedusing XML Schema
1. Importing a metamodel1342Select the specific file
1. Importing a metamodelCreatingPluginWenowhavetoexportthecreatedproject as a pluginWhenwerestart MDWorkbench the new metamodelwillbeavailable
2. BrowsingthemodelOnce themetamodel has beenimportedwe can open themodel in MDWorkbench and browseit
3. WritingthegeneratorsRulesets, texttemplates and scripts can beusedtogeneratecodeRulesets are written in MQLTemplatesarwritten in TGLScripts can bewritten in MQL, TGL or JavaFirst sketch of thesolution:Twocodetemplates: onefor .h files and otherfor .cpp filesA ruleset: toapplythetemplatestoeachcontrollable in themodelScripts: we’llcalltosomescrpitsfromthetemplatestogettheelements of thecontrollable
3. WritingthegeneratorsRuleset:cppGenerator.mqrTemplates:hGen.tgtcppGen.tgtScripts:doGetInitializations()doGetLocalsDefinitions()
3. WritingthegeneratorshGen.tgtRefer to “20081202_MDWorkbench_Tool.ppt” for a detailed overview of Templates
3. WritingthegeneratorscppGen.Tgt (callto script)Refer to “20081202_MDWorkbench_Tool.ppt” for a detailed overview of Templates
3. WritingthegeneratorsScriptsRefer to “20081202_MDWorkbench_Tool.ppt” for a detailed overview of Scripts
3. WritingthegeneratorsRulesetcppGeneration.mqr: appliesthetexttemplatestoeachcontrollableRefer to “20081202_MDWorkbench_Tool.ppt”for a detailed overview of  Rulesets
4. RunningthegeneratorRunconfigurationSelecttheruleset as themainelementwewanttorun and the input model
4. RunningthegeneratorOutputConsole output:Report:
4. RunningthegeneratorOutputPart of a generated .cppfile:

20090109 Dsl2cpp Md Workbench