Your SlideShare is downloading. ×
Using Stratego/XT for generation of software connectors.
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Using Stratego/XT for generation of software connectors.

1,035
views

Published on

The talk presents a master thesis describing generation of software connectors code in accordance with a high-level connector description and a domain specific language.

The talk presents a master thesis describing generation of software connectors code in accordance with a high-level connector description and a domain specific language.

Published in: Business, Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,035
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Using Stratego/XT for Generation of Software Connectors Michal Malohlava Supervisor: RNDr. Tomáš Bureš, Ph. D. DISTRIBUTED SYSTEMS RESEARCH GROUP http://dsrg.mff.cuni.cz/ CHARLES UNIVERSITY IN PRAGUE Faculty of Mathematics and Physics
  • 2. Outline Connector generation ● Existing connector generator overview ● Stratego/XT overview ● Proposed solution ● Conclusion ● 2
  • 3. Connectors? Generation? Why? Why should be component interested in communication? ● It should just implement business logic – => Connectors ● Displace communication matters from components – Design time view – Model component interaction (communication style, NFP) ● Run-time view – Implements interaction with help of some middleware ● Additional services (e.g. Logging) ● Preparation of connectors ● During deployment time – complete info about application and its distribution ● 3 Automatic generation (component interface, depl. docks, ● requirements, code template)
  • 4. General goal Define and implement simple method of ● defining connectors implementations Template based system – Source code generation – Integrate new solution with existing solution – Non-invasively (preserve original functionality) ● 4
  • 5. Connector architecture Connector ● Connector units – Connector elements ● 5
  • 6. Existing connector generator Architecture resolver ● Find architecture of connector in according to described – requirements (HLCS) Source code generation ● Driven by generation script – Generates Java code – Per conn. element ● Simple templates ● Compile java code – Package binaries – 6
  • 7. Existing connector generator Simple code templates which are processed by Java class ● Class just substitutes parts enclosed in % by Java code – Sufficient for primitive connector elements, but composite ● element looks like this: package %PACKAGE%; imports org...runtime.*; public class %CLASS% implements ElementLocalServer , ElementLocalClient , ElementRemoteServer , ElementRemoteClient { protected Element[] subElements ; protected UnitReferenceBundle[] boundedToRRef; public %CLASS%( ) { } %INIT METHODS% // this part processed by special Java class } 7
  • 8. Existing connector generator Simple code templates which are processed by Java class ● Class just substitutes parts enclosed in % by Java code – Sufficient for primitive connector elements, but composite ● element looks like this: package %PACKAGE%; imports org...runtime.*; public class %CLASS% implements This variable is unfolded into into 200LOC by ElementLocalServer , Java class with ElementLocalClient , 1200LOC! ElementRemoteServer , ElementRemoteClient { protected Element[] subElements ; protected UnitReferenceBundle[] boundedToRRef; public %CLASS%( ) { } %INIT METHODS% // this part processed by special Java class } 8
  • 9. Stratego/XT Developed at Delft University of Technology, ● Netherlands (Eelco Visser, Martin Bravenboer) Tool set ● Grammar tools – SDF – Syntax Definition Formalism ● Pretty printers ● Grammar definitions (Java, C/C++, XML, ...) ● Program transformation language Stratego – Based on AST rewriting via strategies ● 9
  • 10. Stratego/XT - architecture How does it work? ● 10
  • 11. Stratego/XT - SDF Modular, one grammar defines: ● Lexical tokens – Context-free rules – Generation of parser (scannerless generalized LR parser) ● Generates “a forest of Abstract Syntax Trees (AST)” – ambiguous parts are explicitly marked ● AST represented by ATerm – 11
  • 12. Stratego/XT – SDF example module Expr−literals module Expr−expressions imports Expr−literals exports exports sorts Int lexical syntax sorts Exp context−free syntax ”0” −> Int [1−9][0−9]* −> Int I n t −> Exp { cons ( ” I n t ” )} lexical restrictions Exp ”+” Exp −> Exp { cons ( ”Add” ) , assoc} Int −/− [0−9] Exp ”−” Exp −> Exp { cons ( ”Sub” ) , left } Exp ” *” Exp −> Exp { cons ( ”Mul ” ) , assoc} Exp ” / ” Exp −> Exp { cons ( ” Div ” ) , assoc} Exp ” ˆ ” Exp −> Exp { cons ( ”Pow” ) , right } ” ( ” Exp ” ) ” −> Exp { bracket } SDF grammar for simple language describing numerical expressions ● 12
  • 13. Stratego/XT – Stratego language Based on strategies manipulating with AST ● Input/Output: AST represented by ATerms – Rewriting strategies and rules ● Strategy – Describes how is AST traversed and rewrited ● Rule – simple rewrite strategy ( Rule: A -> B <=> ?A; !B) ● Many predefined strategies and rules for AST traversing (id, fail, ● bottomup, topdown, try,...), system access strategies (e.g. ls, chmod, open_file,...) Dynamic rules – Allows creating rewrite rules on the fly in according to context ● Program in Stratego language is translated into C and compiled 13 ●
  • 14. Stratego/XT – Stratego example module EExpr imports liblib Expr−eval strategies io−EExpr = io−wrap ( expr−eval ) imports Expr strategies expr-eval = innermost(EvalAdd <+ EvalMul <+ EvalSub <+ EvalDiv <+ EvalPow) rules EvalAdd: Add(Int(i), Int(j)) -> Int(<addS>(i,j)) EvalSub: Sub(Int(i), Int(j)) -> Int(<subtS>(i,j)) EvalMul: Mul(Int(i), Int(j)) -> Int(<mulS>(i,j)) EvalDiv: Div(Int(i), Int(j)) -> Int(<divS>(i,j)) EvalPow: Pow(Int(i), Int(j)) -> Int(<powS>(i,j)) strategies powS = (string-to-int, string-to-int); pow; int-to-string 14 pow = ?(A,B); <copy>(B, A); foldr(!1, mul) // à la Haskell
  • 15. Goals revisited Rebuild source code generator ● Design more sophisticated templates based on DSL – Implement source code generator – Test eligibility of Stratego/XT for this purposes – Incorporate the developed connector element code – generator into the existing solution 15
  • 16. Solution – DSL Designed new Domain Specific Language ● Mixture of meta-language ElLang and target language (Java) – MetaBorg method developed by Stratego/XT group ● Allows embedding language into another language – Connecting selected nonterminals of both languages – ● Defined via SDF Meta-language ElLang ● Meta-variables – ${a}, ${a[index]} ● Meta-queries – ${a.b.c} ● Meta-statements – $set, $if, $include, $foreach, $rforeach 16 ●
  • 17. Solution – DSL Designed new Domain Specific Language ● – Recursive foreach – designed ElLang of Java grammar constraints Mixture of meta-language because and target language (Java) MetaBorg method developed by Stratego/XT group ● $rforeach(PORT in ${ports.port(type=PROVIDED)} )$ if (quot;${PORT.name}quot;.equals(portName)) {into another language – Allows embedding language ObjectConnecting selected neterminals of both languages – result = ((ElementLocalServer) subElements[${el[PORT....]}]); Defined via SDF ● if (isTopLevel) { Meta-language ElLang ● dcm.reregisterConnectorUnitReference(parentUnit, portName, result); } – Meta-variables return result; } else $recpoint$ ● ${a}, ${a[index]} $final$ throw new ElementLinkException(quot;Invalid port 'quot;+portName+quot;'.quot;); – Meta-queries $end$ ${a.b.c} ● Meta-statements – $set, $if, $include, $foreach, $rforeach 17 ●
  • 18. Solution - DSL Special meta-statements ● Simple templates inheritance (extends) – Extension points ($extPoint$) – Allow define points in template which can be extended in a ● child template Method templates – Important for implementing component interfaces ● ! component iface is not known when template is designing ! – Language should provides information about iface ● methods ${method.name}, ${method.variables}, ... – 18
  • 19. Solution - DSL Special meta-statements element console_log extends quot;primitive_default.ellangquot; { ● implements interface ${ports.port(name=in).signature} { Simplemethod template inheritance (extends) templates { – ${method.declareReturnValue} ExtensionSystem.out.println(quot;method > ${method.name} < calledquot;); points ($extPoint$) – Allow define points in template which can be extended in a $if (method.returnVar) $ ● child template${method.returnVar} = this.target.${method.name}(${method.variables}); – Method templates $else$ this.target.${method.name}(${method.variables}); ● Important for implementing component interfaces $end$ ! component iface is not known when needed //generates return statemene if it is templates is designing ! – Language should provides information about iface ${method.returnStm} ● } methods } } ${method.name}, ${method.variables}, ... – 19
  • 20. Solution – template structure ElLang-J = mixture of ElLang and Java ● package ${package}; import org . . . runtime .* ; element console_log extends “primitive_default.ellang” { public ${classname} { / / constructor } implements interface ElementLocalClient { public void bindElPort(String portName , Object target ) { /* ... */ } } implements interface ${ ports.port (name=line).signature} { method template { } } 20
  • 21. Solution – generator architecture Java part ● Prepares low-level connector configuration – Description of connector element internals ● Stratego part ● Generates source code – From template written in ElLang-J ● From L-LCC passed from Java part of generator ● 21
  • 22. Solution - Java part Implementing action interface ● JimplGeneratorInterface rewrites Low-Level – Connector configuration into XML and passed it to Stratego part Just defines new action for – script controlling generation Bridge between Java and ● Stratego: JNI – Shell (execute connector – 22 generator)
  • 23. Solution – Java v. Stratego part low-level connector ● configuration Describes ports ● Name – Type (provided, required, – remote) Resolved port signature – List of subelements ● Name – Implementing class – Bindings between ● subelements Selects template for ● implementation 23
  • 24. Solution – Stratego part Pipe line of several small ● transformation components Input XML preprocessor – Template parser – Template evaluation – Target code gen. – Query component – All of them transform and ● produce AST (in ATerms) 24
  • 25. Solution – Query module Provides access to input XML (contains L-LCC) ● Simple queries à la XPath – Traversing XML ● ${ports.port.name} – ● conditions ● ${ports.port(name=call).signature} – ● Returns signature of port called “call” Count operator ● – ${elements.element#count} ● Returns number of sub-elements 25
  • 26. Solution – evaluation module Pipe-line of evaluation modules ● Processing extends – Processing imports – Template adjustment – Normalization of statements with different notations ● e.g. If -> If-Else ( in ATerms: If(cond,body) -> If(cond, body, [])) – Queries evaluation – Meta-statements evaluation – 26
  • 27. Evaluation (pro-and-con) Advantages ● Simple template which has at least the same power as the – previous solution Shown by implementing all connectors elements into new ● templates Extensible template language (e.g. ElLang-C#) – New generator can be used just by modifying script – controlling connector generation Disadvantages ● Stratego/XT is C-based, rest of generator is in Java – ? Java implementation of Stratego ? ● Annoying long-time compilation of longer Stratego programs – Should be fixed in new release of Stratego ● 27
  • 28. Future work Byte code manipulation ● To avoid need of javac (~SDK) during deployment – process Templates are precompiled into binary form – Presented and implemented in master thesis – “Optimizing performance of software connectors code generator”, Pavel Petřek Simplifying connectors ● Merging generated Java classes – Implements ElLang-C# ● 28 Improve method templates ●
  • 29. Results T. Bureš, M. Malohlava, P. Hnětynka “Using ● DSL for Automatic Generation of Software Connector” Accepted at 7th IEEE International Conference on – Composition Based Software Systems (ICCBSS), Madrid, February 2008 29