code transformation by direct transformation of asts
play

Code Transformation by Direct Transformation of ASTs 1 M. Rizun, - PowerPoint PPT Presentation

Code Transformation by Direct Transformation of ASTs 1 M. Rizun, J.-C. Bach, S. Ducasse Example of simple code transformation 2 Source code Resulting code foo foo | result a b | | result a b | a := 2. a := 2. b := 3. b := 3.


  1. Code Transformation by Direct Transformation of ASTs 1 M. Rizun, J.-C. Bach, S. Ducasse

  2. Example of simple code transformation 2 Source code Resulting code foo foo | result a b | | result a b | a := 2. a := 2. b := 3. b := 3. transformation result := a >= b result := a max: b ifTrue: [ a ] ifFalse: [ b ]

  3. Manual code transformation process 3 (in big system) Definition of the code to change. (LHS) Definition of the desired target code. (RHS) Search for all occurrences of the code to replace in the source code. Replace all found occurrences by target code.

  4. Find & Replace 4 Left-Hand Side part Right-Hand Side part “…code…” “…code…” x >= y x max: y ifTrue: [ x ] ifFalse: [ y ] “…code…” “…code…”

  5. Problems 5 Time-consuming and annoying task. Complex and error-prone process. Rules are not reusable.

  6. Tools to automate process 6 Tool Create transformation rules. Apply rules on desired environment scope. Save rules for later reuse.

  7. Rewrite Engine 7 Engine for code Pros transformation Unintuitive Cons syntax & no GUI to apply rules

  8. “Scary” transformation rule 8 Left-Hand Side part Right-Hand Side part | `@temporaries | | `@temporaries `@otherTemporaries | `.InitializationStatement. `.InitializationStatement. `@condition1 `@condition1 ifTrue: [ ifFalse: [ ^self ]. | `@otherTemporaries | `@.Statements. `@.Statements. ``@value := `@condition2 `@condition2 ifTrue: [ ``@calculate ] ifTrue: [ ``@value := ``@calculate ] ifFalse: [ `#wrongLiteral ] ifFalse: [ ``@value := `#wrongLiteral ] ]

  9. Inattention causes impactful mistakes! 9 `.InitializationStatement `InitializationStatement

  10. 10 How to apply rules?

  11. 11 | rule result aCollection anEnvironment | aCollection := self environment. anEnvironment := RBClassEnvironment classes: aCollection. rule := (Smalltalk globals at: self rules selectedItem) new. OR result := RBSmalllintChecker runRule: rule onEnvironment: anEnvironment. (ChangesBrowser changes: result builder changes) open

  12. Rewrite Tool 12 ´ Intuitive GUI ´ Real time result ´ Apply rules to any scope you want ´ Save rules for later reuse

  13. 13 A. Input code B. Resulting code C. LHS part of rule D. RHS part of rule

  14. 15 Live Demo

  15. Download & Info 16 ´ http://smalltalkhub.com/#!/~MarkRizun/RewriteTool ´ Configuration Browser (Pharo4) ´ http://myfuncoding.com ´ Pharo For The Enterprise (RewriteTool chapter) https://github.com/SquareBracketAssociates/PharoForTheEnterprise-english/tree/master/RewriteTool

  16. 17 Mark Rizun e-mail: mrizun@gmail.com blog: http://myfuncoding.blogspot.com/

Recommend


More recommend