Fakultät Informatik - Institut Software- und Multimediatechnik - Softwaretechnologie – Prof. Aßmann – Model-Driven Softwrae Development in Technical Spaces 30. Model Synchronisation, Code Generation and Round-Trip Engineering for the Consistency of Macromodels Code Generation as Apps for RAG 1) Single-source principle and macromodel Prof. Dr. U. Aßmann principle Technische Universität Dresden 2) Code generation techniques Institut für Software- und ● Template-based Code generation Multimediatechnik 3) Re-parsing http://st.inf.tu-dresden.de/ teaching/most Version 20-1.1, 02.01.21 OO Q10: The House of a Technical Space 2 Model-Driven Software Development in Technical Spaces (MOST) TechnicalTechnical Space Space Model synchronisation ToolTool Engineering Engineering Composition, Extension Composition, Extension Mega-Mega- and and Macromodels Macromodels Technical Tracing, Regeneration, Synchronization Code Generation Technical Tracing, Regeneration, Synchronization Meta- Space Meta- Space modeling Bridges modeling Bridges ModelModel Management Management Composition, Mapping, Transformation Composition, Mapping, Transformation Model Analysis n n Model Analysis a Querying, Attribution, Analysis, Interpretation m Querying, Attribution, Analysis, Interpretation ß A . U . f o r P © Metapyramid (Metahierarchy) Metapyramid (Metahierarchy) Literature 3 Model-Driven Software Development in Technical Spaces (MOST) ► http://www.codegeneration.net/ ► www.programtransformation.org ► http://www.codegeneration.net/tiki-read_article.php?articleId=65 ► Paul Bassett. Frame-based software engineering. IEEE Software, 4(4):9-16, 1987. ■ http://doi.ieeecomputersociety.org/10.1109/MS.1987.231057 ► Chris Holmes, Andy Evans. A review of frame technology. University of York, Dept. of Computer Science, 2003 ftp://www-users.cs.york.ac.uk/reports/2003/YCS/369/YCS-2003-369.pdf ► Daniel Weise and Roger Crew. Programmable syntax macros. In Proceedings of the ACM SIGPLAN '93 Conference on Programming Language Design and Implementation, pages 156-165, Albuquerque, New Mexico, June 23-25, 1993. ► Optional ■ Völter, Stahl: Model-Driven Software Development, AWL 2005. n n a ■ Falk Hartmann. Safe Template Processing of XML Documents. PhD thesis, m ß A . Technische Universität Dresden, Fakultät Informatik, July 2011. U . f o r . P http://nbn-resolving.de/urn:nbn:de:bsz:14-qucosa-75342 © 4 Model-Driven Software Development in Technical Spaces (MOST) n n a m ß A . U . f o r P © Fakultät Informatik - Institut Software- und Multimediatechnik - Softwaretechnologie – Prof. Aßmann – Model-Driven Softwrae Development in Technical Spaces 30.1 Model2Code Transformation (Code Generation) Transforming models into code (Programmüberführung) MDSD-Code-Generators 6 Model-Driven Software Development in Technical Spaces (MOST) Source artefacts Specification of the Target program Source artefacts target language Target program (RTG, String grammar, RAG) Graph-based Models UML-Diagrams File with Textual specifications Generator Target Code (Code, Scripts, Templates) Specification of the transformation n n a m Templates in the ß A . target language U . f o r P © MDSD-Code-Generators as Attributors of Syntax Trees 7 Model-Driven Software Development in Technical Spaces (MOST) SourceSource artefacts artefacts TargetTarget tree tree attribute attribute RAG Specification of the Link Tree-based Models target language UML-Diagrams Syntax Tree Textual Higher-order Tree with target specifications Syntax RAG with code in higher-order (Code, Scripts) Tree synthesized attribute code attribute Syntax Tree RAG Specification Templates in the n of the transformation n a target language m ß A . (as template syntax U . f o trees, or partially parsed r P © from snippets in the template language) Different Kinds of Code Generators 8 Model-Driven Software Development in Technical Spaces (MOST) ► A code selector is a transformation system (term, link trees, graphs) covering the input models with rules (code coverage) transforming the model elements once ► A code scheduler orders instructions in an optimized manner Code scheduling runs after code selection ► Metaprogramming code generators: A template expander generates code by filling code templates withinset snippets An invasive fragment composer (invasive software composition) composes templates in a typed and wellformed way (→ CBSE) n n a m ß A . U . f o r P © MDSD-Code-Generators as Template Expanders 9 Model-Driven Software Development in Technical Spaces (MOST) ► A template engine hides the tree construction, attribution with code attributes, and pretty-printing under a simple interface. It provides functions ■ templparse(): String in TemplateLanguage → Tree ■ pparse(): String in BaseLanguage → Tree ► Template engines are apps of higher-order RAGs Binding rules of templates Target code SourceSource artefacts artefacts Target code Graph-based Models Syntax Tree with UML-Diagrams Attribution Tree expanded code Target Textual specifications Syntax code (OCL, Scripts) Tree Template engine Syntax (template expander) Tree n Templates in the n a m target language ß A . (as template syntax U . f o trees, or partially parsed Parser of template language r P © from snippets in the template language) Fakultät Informatik - Institut Software- und Multimediatechnik - Softwaretechnologie - Model-Driven Software Development in Technical Spaces (MOST) 30.1.2 Code Generation in RAGs ► With higher-order (tree-generation) attributes and special functions ■ partial parsing ■ template expansion Model-Driven Software Development in Technical Spaces (MOST) © Prof. U. Aßmann Code Generation with RAGs 11 Model-Driven Software Development in Technical Spaces (MOST) ► Attribution functions may generate code syntax trees ► Suppose a partial parse function pparse(): String->LinkTree eqeq Constant.Code()Constant.Code() {{ ifif (AsBoolean())(AsBoolean()) ifif (AsValue()(AsValue() ==== 1)1) returnreturn pparse(“pparse(“(boolean)1(boolean)1”);”); elseelse ifif (AsValue()(AsValue() ==== 0)0) returnreturn pparse(“pparse(“(boolean)0(boolean)0”);”); else return EmptyTree; else return EmptyTree; else { else { if (AsValue() == 1) if (AsValue() == 1) return pparse(„new Integer(1)“); return pparse(„new Integer(1)“); else if (AsValue() == 0) else if (AsValue() == 0) n return pparse(„new Integer(0)“); n a return pparse(„new Integer(0)“); m ß else A else . U . return pparse(„new Integer(“+AsValue()+„)“); f o return pparse(„new Integer(“+AsValue()+„)“); r P } © } }} Template-Based Code Generation with RAGs 12 Model-Driven Software Development in Technical Spaces (MOST) ► Attribution functions may expand code templates to code trees ► Done with the template processing function templparse(): String, List(ID)->LinkTree that expands variable names into attribution functions, e.g., TypeParameterName → TypeParameterName() ► templparse() is called a template processor, String is of a template language eq GenericClassInstantiation.Code() { eq GenericClassInstantiation.Code() { return templparse( return templparse( “public class GenClass$TypeParameterName$ extends Object { “public class GenClass$TypeParameterName$ extends Object { private int myId; private int myId; public GenClass$TypeParameterName$() { // constructor public GenClass$TypeParameterName$() { // constructor } } public int getId() { return myId; } public int getId() { return myId; } }“ }“ , List(pparse(„Person“)) , List(pparse(„Person“)) n ); n a ); m } ß A } . U . f o r P © Template-Based Code Generation with RAGs 13 Model-Driven Software Development in Technical Spaces (MOST) ► The template processing function can be made generic in terms of grammars: templparseGeneric(): CSGrammar, RTG, String,List(ID)->LinkTree that expands variable names into attribution functions, e.g., TypeParameterName → TypeParameterName() ► templparse() is called a template processor, String is of a template language eq GenericClassInstantiation.Code() { eq GenericClassInstantiation.Code() { CSGrammar CSAceleo; CSGrammar CSAceleo; RTGrammar RTGAceleo; RTGrammar RTGAceleo; return templparseGeneric(CSAceleo, RTGAceleo, return templparseGeneric(CSAceleo, RTGAceleo, “public class GenClass$TypeParameterName$ extends Object { “public class GenClass$TypeParameterName$ extends Object { private int myId; private int myId; public GenClass$TypeParameterName$() { // constructor public GenClass$TypeParameterName$() { // constructor } } public int getId() { return myId; } public int getId() { return myId; } }“ n n }“ a , List(pparse(„Person“)) m ß , List(pparse(„Person“)) A . ); U ); . f o } r P } © Fakultät Informatik - Institut Software- und Multimediatechnik - Softwaretechnologie 30.1.3 Single-Source Principle and Macromodels Model-Driven Software Development in Technical Spaces (MOST) © Prof. U. Aßmann Single-Source-Principle, Major-Source, Code Addition, and Round-Trip Engineering 15 Model-Driven Software Development in Technical Spaces (MOST) Document Major Source generation Documen- Source Models tation Program/Code- Code- TreeWare Generation) Parsing ModelWare Optimized and <<dependent>> Generated extended Code Target code n n a m ß Manual addition (code addition, A . Hand-written U . code „patching“), code composition f o r Source code P © Major Source GrammarWare Macromodel Principle and Round-Trip Engineering Multiple Consistent 16 Model-Driven Software Development in Technical Spaces (MOST) Sources Source Model Document B generation Documen- Source Model A tation Source Model C Program/Code- Code- TreeWare Generation) Parsing ModelWare Optimized and Generated
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages38 Page
-
File Size-