Code Generation. Ákos Horváth Gábor Bergmann Dániel Varró Model Driven Systems Development Lecture 8. Budapesti Műszaki és Gazdaságtudományi Egyetem

Hasonló dokumentumok
Széchenyi István Egyetem

Using the CW-Net in a user defined IP network

Adatbázis-kezelés ODBC driverrel

discosnp demo - Peterlongo Pierre 1 DISCOSNP++: Live demo

Cloud computing. Cloud computing. Dr. Bakonyi Péter.

Correlation & Linear Regression in SPSS

Szoftver-technológia II. Tervezési minták. Irodalom. Szoftver-technológia II.

Cloud computing Dr. Bakonyi Péter.

Excel vagy Given-When-Then? Vagy mindkettő?

EEA, Eionet and Country visits. Bernt Röndell - SES

C#, OOP. Osztályok tervezése C#-ban

Mapping Sequencing Reads to a Reference Genome

KOGGM614 JÁRMŰIPARI KUTATÁS ÉS FEJLESZTÉS FOLYAMATA

Kezdőlap > Termékek > Szabályozó rendszerek > EASYLAB és TCU-LON-II szabályozó rendszer LABCONTROL > Érzékelő rendszerek > Típus DS-TRD-01

Mobil webszerverek. Márton Gábor Nokia Research Center. W3C Mobilweb Műhelykonferencia, Budapest október 18.

CLUSTALW Multiple Sequence Alignment

Az Open Data jogi háttere. Dr. Telek Eszter

Supporting Information

Proxer 7 Manager szoftver felhasználói leírás

LabVIEW Academy. 6. óra state machine

Simulation and transformation of domain-specific languages. Master s Thesis

(NGB_TA024_1) MÉRÉSI JEGYZŐKÖNYV

Modell alapú rendszertervezés

4. Gyakorlat: Csoportházirend beállítások

Fejlesztési projektek menedzselése IBM Rational CLM termékekkel. Ker-Soft Kft. Kaszás Orsolya - üzleti tanácsadó

ios alkalmazásfejlesztés Koltai Róbert

C# versus Java. Óbudai Egyetem, Java Standard Edition Mérnök Informatikus szak, BSc Labor 3. Bedők Dávid v0.4

Csatlakozás a BME eduroam hálózatához Setting up the BUTE eduroam network

Miskolci Egyetem Gazdaságtudományi Kar Üzleti Információgazdálkodási és Módszertani Intézet. Correlation & Linear. Petra Petrovics.

On The Number Of Slim Semimodular Lattices

Declarative Specification of Domain Specific Visual Languages. Master s Thesis. Dr. Dániel Varró assistant professor

Léptetőmotorok. Előnyök: Hátrányok:

WCF, Entity Framework, ASP.NET, WPF 1. WCF service-t (adatbázissal Entity Framework) 2. ASP.NET kliens 3. WPF kliens

Genome 373: Hidden Markov Models I. Doug Fowler

USER MANUAL Guest user

16F628A megszakítás kezelése

Új hálózati megoldások Gbit xdsl technológiával

Performance Modeling of Intelligent Car Parking Systems

Földtani térképek kartografálásának segítése térinformatikai módszerekkel

RESEARCHING THE CONNECTION BETWEEN URBAN OPEN SPACES

AZ APACHE MAVEN ÉLETE ÉS HALÁLA.! Cservenák Tamás

Professional competence, autonomy and their effects

Modellalkotás UML-ben

KN-CP50. MANUAL (p. 2) Digital compass. ANLEITUNG (s. 4) Digitaler Kompass. GEBRUIKSAANWIJZING (p. 10) Digitaal kompas

Statistical Inference

Statistical Dependence

BKI13ATEX0030/1 EK-Típus Vizsgálati Tanúsítvány/ EC-Type Examination Certificate 1. kiegészítés / Amendment 1 MSZ EN :2014

Summer of LabVIEW The Sunny Side of System Design

Több app. Egy kódbázis

FOSS4G-CEE Prágra, 2012 május. Márta Gergely Sándor Csaba

Csima Judit április 9.

Választási modellek 3

Cluster Analysis. Potyó László

István Micsinai Csaba Molnár: Analysing Parliamentary Data in Hungarian

ANGOL NYELV KÖZÉPSZINT SZÓBELI VIZSGA I. VIZSGÁZTATÓI PÉLDÁNY

ELEKTRONIKAI ALAPISMERETEK ANGOL NYELVEN

DOAS változások, összefoglaló

SZET GYAK1: Követelmények ellenőrzése

Web Services. (webszolgáltatások): egy osztott alkalmazásfejlesztési plattform

Phenotype. Genotype. It is like any other experiment! What is a bioinformatics experiment? Remember the Goal. Infectious Disease Paradigm

Correlation & Linear Regression in SPSS

THS710A, THS720A, THS730A & THS720P TekScope Reference

Energetika az építész kezében

Java Development Alapképzés

Felnőttképzés Európában

ANGOL NYELV KÖZÉPSZINT SZÓBELI VIZSGA I. VIZSGÁZTATÓI PÉLDÁNY

Szoftver min ség és menedzsment

Road construction works

Miért is transzformáljunk modelleket? Varró Dániel

Önkiszolgáló BI infrastruktúra az adatvezérelt teljesítménymenedzsmentben

JAVA webes alkalmazások

1. Gyakorlat: Telepítés: Windows Server 2008 R2 Enterprise, Core, Windows 7

3. Nemzetközi talajinformációs rendszerek

Mérnök informatikus (BSc) alapszak levelező tagozat (BIL) / BSc in Engineering Information Technology (Part Time)

First experiences with Gd fuel assemblies in. Tamás Parkó, Botond Beliczai AER Symposium

2. Local communities involved in landscape architecture in Óbuda

}w!"#$%&'()+,-./012345<ya

Abigail Norfleet James, Ph.D.

Bevezetés a kvantum-informatikába és kommunikációba 2015/2016 tavasz

Teszt topológia E1/1 E1/0 SW1 E1/0 E1/0 SW3 SW2. Kuris Ferenc - [HUN] Cisco Blog -

Road traffic-control equipment

Effect of the different parameters to the surface roughness in freeform surface milling

Domain- specifikus modellezés az Eclipse Modeling Framework használatával

Lopocsi Istvánné MINTA DOLGOZATOK FELTÉTELES MONDATOK. (1 st, 2 nd, 3 rd CONDITIONAL) + ANSWER KEY PRESENT PERFECT + ANSWER KEY

Characteristics and categorization of transportation organizations

Web-fejlesztés NGM_IN002_1

C++ fejlesztés az ECLIPSE környezetben

Rotary District 1911 DISTRICT TÁMOGATÁS IGÉNYLŐ LAP District Grants Application Form

Az Ipoly árvízi előrejelző rendszer

A V Á R B Ű V Ö L E T É B E N

Sebastián Sáez Senior Trade Economist INTERNATIONAL TRADE DEPARTMENT WORLD BANK

AZ ISO/IEC-9126 SZOFTVER MINŐSÉGI SZABVÁNY ÁTTEKINTÉSE

A Microsoft Visual Studio 2005 fejlesztőkörnyezet

Furniture. Info. Buyer. Version changes Contract award. Description. Version 3. Publish date 5/13/2014 4:21 AM

Oracle Big Data koncepció. Stadler Gellért Vezető tanácsadó Oracle ConsulKng HTE 2015 Konferencia

Minta ANGOL NYELV KÖZÉPSZINT SZÓBELI VIZSGA II. Minta VIZSGÁZTATÓI PÉLDÁNY

Számítógéppel irányított rendszerek elmélete. Gyakorlat - Mintavételezés, DT-LTI rendszermodellek

SQL/PSM kurzorok rész

Biztonság java web alkalmazásokban

3. MINTAFELADATSOR KÖZÉPSZINT. Az írásbeli vizsga időtartama: 30 perc. III. Hallott szöveg értése

Átírás:

Code Generation Ákos Horváth Gábor Bergmann Dániel Varró Model Driven Systems Development Lecture 8

Agenda Code Generation in general Approaches Advanced Text Generation Issues Example template languages o JET, Velocity, Xpand and XTend

Code Generation (text synthesis)

Why? Let s shorten Development time! Use our models/requirements/plans to derive o Documentation o Source code o Configuration descriptors o Communication messages o Object Serialization o Need to support designing text synthesis

Text synthesis The realization of a high-level model on an implementation platform A choice between certain attributes compromise between: o Compatibility o Performance o Maintainability o Reusability

Similarity with compilers Mapping between abstraction levels o e.g., From C to assembly Usage of design patterns o e.g., function calls in C Many similarities, NOT a strict separation o pl. C++ templates, automatically generated ctor+dtor Prediction: o yesterday s design pattern today s code generation feature tomorrow s language element Domain-specific instead of universal languages

Example: Source Code generation in MDD DSM model High-level language Assembly code generation compile

Approaches

Dedicated Approaches o Specific, ad-hoc o Using a dedicated code generator Template based

Specific, ad-hoc Designed for the specific problem domain: o Best performance o Quick and dirty o Long development, hard maintainability o Zero reusability o Dedicated problem domains Minimal changes during support cycle (safety critical embedded system, defense) Certifiability o Example: ARINC653 Multistatic configuration generator (python script)

Dedicated code generator Parameters Model Dedicated Code generator Textual artifact Based on a framework: o Faster development time o Slower performance, better reusability o Embedded systems, moderate changes during project lifecycle

Dedicated code generator Parameters Model Dedicated Code generator Textual artifact Examples: o IBM Rational Software Architect o VASP (DO-178B Level A) Display graphics in avionics o Mathworks o Matlab Simulink o Esterel Scade suite

Template Based Parameters Model Template Compiler/generator Template Executable Template Code Textual Artifact

Template Based Name= John Doe Balance= 1000$ Parameters Model Template Compiler/generator Template Executable Template Code Textual Artifact Dear [Name], Dear John Doe, I would like to inform you that your current balance is [Balance] I would like to inform you that your current balance is 1000$

Template Based Parameters Model Template Compiler/generator Template Executable Template Code Textual Artifact Fastest development time Slowest performance, highest reusability Fast changing environments (e.g., web based technologies) Complex changes during project lifecycle o Models and templates can be changed independently

Template Based Parameters Model Template Compiler/generator Template Executable Template Code Textual Artifact Examples: o JET (for EMF models) o Velocity (/JSP) o OpenArchitectureWare/ XPand (MDD approach) o AutoFilter (Kalman filters) o Smarty (php)

Advanced Code/Text Generation Issues

Direct source code generation Direct source code generation o Simple structure o Low complexity o Fast development o Linear output generation (single pass) o Problematic formatting o Problematic M2C synchronization Output:

Output: AST generation AST generation o Represents the program structure (PSM) o Can be very complex o Slower development o Non-linear generation process o Support for M2C synchronization o Incremental output generation o pretty formatting o E.g., Eclipse JDT

Direct source code generation vs. AST Direct source code generation o Simple structure o Low complexity o Fast development o Linear output generation (single pass) o Problematic formatting o Problematic M2C synchronization AST generation o Represents the program structure (PSM) o Can be very complex o Slower development o Non-linear generation process o Support for M2C synchronization o Incremental output generation o pretty formatting o E.g., Eclipse JDT

Generator model Model Input Models Generator Model AST models Output models generate Generated Documents Multiple source models generator model Stores all additional information References to both Input Models and Outputs (prettyprintable) Helps code generation by o Multiple output streams o Traceability between models cross references o Support for Non-linear Multi Pass traversals and model build o Support for complex model hierarchies (multiple AST-s, packages etc.)

Model to code synchronization What if the output text is changed? M2C synchronization Works only with AST based approaches Requires o Traceability between model and text o Model compare o Change localization Incremental model building for better performance Example o Eclipse JDT: java source and its AST o EMF: model generator

Manual and generated parts Don t overwrite manual extensions upon re-generation Where to put non-changing parts o Model Allows better reusability Increases complexity o Template o AST Works well for simple cases Manual markings in AST the rest is generated o Directly to code Java no support Use generalization C# partial classes

Code formatting Where to include? o Model Does not follow typical MVC design paradigm o Templates Simple formatting element o AST Can store all relevant information Makes it very complex Best solution: Code formatting as separate step o a new step in the generation workflow o Can be handled with 3rd party code formatters Eclipse JDT formatter XML DOM serializer

Keywords and special characters Restricted keywords in the target language o Java: abstract, class o XML: <, > o etc. Needs to validate the model before generation o Can be very complex separate step before code generation o Example Escaping Java simple support: isjavaidentifierstart() (in Character) EMF validation o On the model (in separate generator model?) o Only at code generation time

Java Emitter Templates (JET) Velocity, Xpand, Xtend

Java Emitter Templates Model JET Templates + Parameters Template Compiler/generator JET classes execute Generated Document Java Emitting Templates (JET) o JSP-like template language using Java as its control sequence o Compiled to Java o Open output format (Text) o Parameters as Java objects o Part of EMF o Eclipse uses JET as its own template language

JET example <%@ jet package="hello" imports="java.util.*" class="xmldemotemplate" %> <% List elementlist = (List) argument; %> <?xml version="1.0" encoding="utf-8"?> <demo> <% for (Iterator i = elementlist.iterator(); i.hasnext(); ) { %> <element><%=i.next().tostring()%></element> <% } %> </demo>

JET example <%@ jet package="hello" imports="java.util.*" class="xmldemotemplate" %> <% List elementlist = (List) argument; %> <?xml version="1.0" encoding="utf-8"?> <demo> Jet Header <% for (Iterator i = elementlist.iterator(); representing the Template i.hasnext(); ) { %> <element><%=i.next().tostring()%></element> <% } %> </demo> Name of the Class Package of representing class Packages to import

<%@ jet package="hello" imports="java.util.*" class="xmldemotemplate" %> <% List elementlist = (List) argument; %> <?xml version="1.0" encoding="utf-8"?> Input parameter <demo> Start of code section <% for (Iterator i = elementlist.iterator(); i.hasnext(); ) { %> <element><%=i.next().tostring()%></element> <% } %> </demo> JET example End of code section

<%@ jet package="hello" imports="java.util.*" class="xmldemotemplate" %> <% List elementlist = (List) argument; %> <?xml version="1.0" encoding="utf-8"?> <demo> <% for (Iterator i = elementlist.iterator(); i.hasnext(); ) { %> <element><%=i.next().tostring()%></element> <% } %> </demo> JET example Start of target document

JET example <%@ jet package="hello" imports="java.util.*" class="xmldemotemplate" %> <% List elementlist = (List) argument; %> Loop with the input parameter <?xml version="1.0" encoding="utf-8"?> <demo> <% for (Iterator i = elementlist.iterator(); i.hasnext(); ) { %> <element><%=i.next().tostring()%></element> <% } %> Loop body </demo> Returns value of the argument

Apache Velocity Model Velocity Templates Velocity Template Engine Executable Template Code execute Generated Document Apache Velocity o JSP like template language with limited control sequence o Interpreted o Open output format (Text) o Parameters as a Map

Velocity example <?xml version="1.0" encoding="utf-8"?> <demo> #set( $tempstring = " Element") #foreach( $element in $elementlist) <element> ${element.tostring()} <element> #end </demo>

Velocity example <?xml version="1.0" encoding="utf-8"?> <demo> #set( $tempstring = "Element") #foreach( $element in $elementlist) <element> ${element.tostring()} <element> #end </demo> Setting values Start of target document New variable New value of tempstring

Velocity example <?xml version="1.0" encoding="utf-8"?> <demo> Input parameter #set( $tempstring = "Element") #foreach( $element in $elementlist) <element> ${element.tostring()} <element> #end </demo> For loop New running variable Arbitrary Java method call

Xtend EMF model Validation Transformation (Xtend) Generator (Xpand) execute Generated Document M2C workflow (former OAW) Eclipse M2C (former OAW) o Complete M2C workflow Validation Transformation (Xtend language) Code generation (Xpand language) Mainly for EMF model based transformation Flexible workflow definition

Xtend EMF model Validation Transformation (Xtend) Generator (Xpand) execute Generated Document M2C workflow (former OAW) Interpreted Statically-typed template language Polymorphic template invocation Support for AOP programming Error handling Support for whitespace generation/definition

Xpand «IMPORT XMLmetamodel» «DEFINE main FOR Model» «FILE this.name + ".myxml"» <?xml version="1.0" encoding="utf-8"?> <demo> «EXPAND listelement FOREACH elements» </demo> «ENDFILE» «ENDDEFINE» «DEFINE listelement FOR Element» <element> «this.tostring()»</element> «ENDDEFINE»

Xpand «IMPORT XMLmetamodel» «DEFINE main FOR Model» «FILE this.name + ".myxml"» <?xml version="1.0" encoding="utf-8"?> <demo> «EXPAND listelement FOREACH elements» </demo> «ENDFILE» «ENDDEFINE» Import EMF metamodel «DEFINE listelement FOR Element» <element> «this.tostring()»</element> «ENDDEFINE» Define template for specific type

Xpand «IMPORT XMLmetamodel» «DEFINE main FOR Model» «FILE this.name + ".myxml"» <?xml version="1.0" encoding="utf-8"?> <demo> «EXPAND listelement FOREACH elements» </demo> «ENDFILE» Start of target document «ENDDEFINE» Output file definition «DEFINE listelement FOR Element» <element> «this.tostring()»</element> «ENDDEFINE»

Xpand «IMPORT XMLmetamodel» «DEFINE main FOR Model» «FILE this.name + ".myxml"» <?xml version="1.0" encoding="utf-8"?> <demo> «EXPAND listelement FOREACH elements» </demo> «ENDFILE» «ENDDEFINE» EReference holding the elements Invoke other template with type definition «DEFINE listelement FOR Element» <element> «this.tostring()»</element> «ENDDEFINE»

Foundation of Xtext2 Xtend overview o Original purpose: compile Xtext2 DSLs to Java A JVM-based language o Imperative, statically typed, compiles to Java o Incorporates functional programming constructs Advanced features o Type inference o Properties o Everything is an expression o Operator overloading o Power switch o Lambda expressions o Templates

Xtend example import com.google.inject.inject class DomainmodelGenerator implements IGenerator { @Inject extension IQualifiedNameProvider nameprovider Java Import? override void dogenerate(resource resource, IFileSystemAccess fsa) { for(e: resource.allcontentsiterable.filter(typeof(entity))) { fsa.generatefile( e.fullyqualifiedname.tostring.replace(".", "/") + ".java", e.compile) } } def compile(entity e) ''' «IF e.econtainer!= null» package «e.econtainer.fullyqualifiedname»; «ENDIF» public class «e.name» «IF e.supertype!= null» extends «e.supertype.fullyqualifiedname» «ENDIF»{ «FOR f:e.features» «f.compile» «ENDFOR» } Built-in function Syntactic sugar for first parameter =generated text is the default

Summary

Code generation - Summary Started from source code generation UML -> Java, C++,. Used in many other text based artifacts document generation (web) report generation (XML, XLS, CSV, print) Configuration (wsdl) Strong tool support Xpand Xtend (CodeDOM) There are some use cases outside of the MDE field