1 / 33

Introducing Static Semantic Analysis to Templates Using JastAdd

Introducing Static Semantic Analysis to Templates Using JastAdd. Jos Peeters. Goal. Ambition Improve the quality of code generators based on templates. Primary Research Question Can static semantic checking be used in template-based code generators using off-the-shelf tooling?.

ophrah
Download Presentation

Introducing Static Semantic Analysis to Templates Using JastAdd

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introducing Static Semantic Analysis to Templates Using JastAdd Jos Peeters

  2. Goal Ambition • Improve the quality of code generators based on templates. Primary Research Question • Can static semantic checking be used in template-based code generators using off-the-shelf tooling? / name of department

  3. Research Questions • Can JastAdd be coupled to Repleo? • Is the resulting coupling scalable? • How can static semantic checking be performed on templates? • How to deal with syntactic ambiguities? • How to implement this using JastAdd? / name of department

  4. Research Questions • Tools • Repleo • JastAdd • Connection • Methodology • Placeholders • Static Semantic Checking • Syntactic Ambiguities • Implementing the Methodology • Conclusion / name of department

  5. Tools • Repleo • Syntax-safe template engine • JastAdd • Java-based compiler compiler system • Object-oriented abstract syntax • Advanced attribute grammar features / name of department

  6. Repleo • Templates • Architectural Pattern • Code with empty spaces and generative commands • Features • Guarantees syntax-safe output code • Provides meta-language for templates / name of department

  7. Repleo / name of department

  8. JastAdd • Features • Abstract Syntax • Parser Independent • Extended support Attribute Grammars • Aspect Oriented / name of department

  9. JastAdd / name of department

  10. Abstract syntax abstract BlockStmt; abstract Stmt: BlockStmt; AssignStmt : Stmt ::= Variable:Access Value:Exp; WhileStmt : Stmt ::= Condition:Exp Body:Stmt; abstract Exp; abstract Access:Exp; IntLiteral : Exp ::= <Value:String>; abstract Operator : Exp; abstract BinOperator : Operator ::= lhs:Exp rhs:Exp; PlusOp : BinOperator; / name of department

  11. Attributes Properties as attributes • Synthesized • Inherited • Equations Also: • Rewrites • Circular attributes • Non-terminal attributes / name of department

  12. Weaving Aspects aspect TypeAnalysis { synlazy TypeDecl Exp.type(); eq BinOperator.type() { if (getlhs().type().isSubtypeOf(getrhs().type()) || getrhs().type().isSubtypeOf(getlhs().type()) ) { if (getlhs().type().isUnknown() ) return getrhs().type(); return getlhs().type(); } return unknownDecl().type(); } eq IntLiteral.type() = intType(); } / name of department

  13. Connection • Boolean Evaluator • Simple boolean expressions • Java 1.4 • Using JastAddJ / name of department

  14. Connection / name of department

  15. Connection JastAddJ Issues • No strict separation between checker and parser • Instantiation parts of checker • Rewriting during parse phase • Grammar differences between SDF and AST For placeholder a 1-to-1 transformation is required / name of department

  16. Research Questions • Tools • Repleo • JastAdd • Connection • Methodology • Placeholders • Static Semantic Checking • Syntactic Ambiguities • Implementing the Methodology • Conclusion / name of department

  17. Placeholders(1) What are placeholders? • Representation of empty space in code • Substitution or generative command • Properties defined by place of occurrence "<:" TreeQuery ":>" -> PlaceHolderSubstitution[[X]] / name of department

  18. Placeholders(2) Substitution int <: x :>; Conditional <: if x == "true" then :> boolean b; <: else :> int i; <: fi :> / name of department

  19. Placeholders (3) Iterative int i = 0; <: foreach $x in X do :> i = i + <: $x :>; <: od :> Match-Replace int i = 0; i = <: match X :> <: [$e,$t] = :> <: $e :> + <: $t :> <: [] = :> 0 <: end :>; / name of department

  20. Static Semantic Checking • Target language • Type checking • Context related checks (f.i. duplicate declarations) • Placeholders language • Uniqueness meta-variables (i.e. $e) • Combination of both • Checking influence of placeholders on target language • “Bad Smells” / name of department

  21. Bad Smells Not permitted • errors that are related to properties of placeholders <: foreach $x in X do :> int i; <: od :> Permitted • restrictions given only by the input data <: foreach $x in X do :> int <: $x :>; <: od :> / name of department

  22. Syntactic Ambiguities • Occur when multiple production can be applied • Parsing problem • SGLR • Bad Smell publicclass A { <: a :> <: b :>(){} } / name of department

  23. Disambiguation • Via Context • Use static semantic checker • Compare previous use of placeholders publicclass A { <: a :> i = 0; <: a :> <: b :>(){} } / name of department

  24. Disambiguation • Using prioritization • Select the option containing the placeholder { int i; i = <: a :>; } / name of department

  25. Research Questions • Tools • Repleo • JastAdd • Connection • Methodology • Placeholders • Static Semantic Checking • Syntactic Ambiguities • Implementing the Methodology • Conclusion / name of department

  26. Implementing the Methodology PicoJava • Subset of Java • Originally an example of JastAdd Present • PicoJava language definition in JastAdd • Attributes to support checking • Static semantic checker • SDF definition Placeholders / name of department

  27. Pipeline / name of department

  28. Implementation Implemented as part of this project • SDF definition PicoJava • Traversal SGLR  JastAdd With JastAdd • Language definition placeholders • Extend attributes for the placeholders • Static semantic checker • Placeholders • Bad Smells • Ambiguity nodes • Disambiguation filter NB. JastAdd is Aspect-Oriented / name of department

  29. template( { <: if x == $e then :> boolean i; i = <: match y :> <: [$e, $t] = :> <: $e :> + <: $t :> <: [] = :> 0 <: end :>; <: fi :> i = 0; } ) 1 2 3 4 5 6 7 8 9 10 11 12 Example - Template / name of department

  30. Example – Output(1) --> Resolving ambiguities 6:21 Ambiguity found: Exp Ambiguity resolved using prioritization 6:32 Ambiguity found: Exp Ambiguity resolved using prioritization Done / name of department

  31. Example – Output(2) --> Language Errors 10:2 : Can not assign to a variable of type boolean a value of type int --> Placeholder Errors 6:6 : duplicate declaration of meta-variables [$e] --> Placeholder Bad Smells 7:6 : inferred type of placeholder does not match the type of its declaration 10:2 : Variable i might not be declared, dependent on [x] --> List of PlaceHolders $e PhExp $unknown $unknown $t PhExp $unknown $unknown y PhMRExp $unknown int x PhIfBlockStmt $unknown $unknown / name of department

  32. Conclusions Presented in this Thesis • Static Semantic Checks on Template • Use of off-the-shelf tools • Repleo • JastAdd Methodology • Multi-language approach • Ease-of-use of templates • Syntax-safe • Static Semantic Analysis / name of department

  33. Questions / name of department

More Related