penerapan metode direct linear transformation dalam penentuan distorsi kamera non metrik
Code transformation by direct transformation of ASTs
Transcript of Code transformation by direct transformation of ASTs
![Page 1: Code transformation by direct transformation of ASTs](https://reader036.fdocuments.net/reader036/viewer/2022062320/55d34fe7bb61eb2c628b45c3/html5/thumbnails/1.jpg)
1
Code Transformation by Direct Transformation of ASTsM. Rizun, J.-C. Bach, S. Ducasse
![Page 2: Code transformation by direct transformation of ASTs](https://reader036.fdocuments.net/reader036/viewer/2022062320/55d34fe7bb61eb2c628b45c3/html5/thumbnails/2.jpg)
2 Example of simple code transformation
foo
| result a b |
a := 2.
b := 3.
result := a >= b
ifTrue: [ a ]
ifFalse: [ b ]
foo
| result a b |
a := 2.
b := 3.
result := a max: b
Source code Resulting code
transformation
![Page 3: Code transformation by direct transformation of ASTs](https://reader036.fdocuments.net/reader036/viewer/2022062320/55d34fe7bb61eb2c628b45c3/html5/thumbnails/3.jpg)
3Manual code transformation process
(in big system)
Replace all found occurrences by target code.
Search for all occurrences of the code to replace in the source code.
Definition of the desired target code. (RHS)
Definition of the code to change. (LHS)
![Page 4: Code transformation by direct transformation of ASTs](https://reader036.fdocuments.net/reader036/viewer/2022062320/55d34fe7bb61eb2c628b45c3/html5/thumbnails/4.jpg)
4 Find & Replace
“…code…”
x >= y
ifTrue: [ x ]
ifFalse: [ y ]
“…code…”
“…code…”
x max: y
“…code…”
Right-Hand Side partLeft-Hand Side part
![Page 5: Code transformation by direct transformation of ASTs](https://reader036.fdocuments.net/reader036/viewer/2022062320/55d34fe7bb61eb2c628b45c3/html5/thumbnails/5.jpg)
5 Problems
Time-consuming and annoying task.
Complex and error-prone process.
Rules are not reusable.
![Page 6: Code transformation by direct transformation of ASTs](https://reader036.fdocuments.net/reader036/viewer/2022062320/55d34fe7bb61eb2c628b45c3/html5/thumbnails/6.jpg)
6 Tools to automate process
Tool Create transformation rules.
Apply rules on desired environment scope.
Save rules for later reuse.
![Page 7: Code transformation by direct transformation of ASTs](https://reader036.fdocuments.net/reader036/viewer/2022062320/55d34fe7bb61eb2c628b45c3/html5/thumbnails/7.jpg)
7 Rewrite Engine
Engine for code transformation
Unintuitive syntax & no GUI to apply
rules
Pros
Cons
![Page 8: Code transformation by direct transformation of ASTs](https://reader036.fdocuments.net/reader036/viewer/2022062320/55d34fe7bb61eb2c628b45c3/html5/thumbnails/8.jpg)
8 “Scary” transformation rule
Left-Hand Side part
| `@temporaries |
`.InitializationStatement.
`@condition1
ifTrue: [
| `@otherTemporaries |
`@.Statements.
`@condition2
ifTrue: [ ``@value := ``@calculate ]
ifFalse: [ ``@value := `#wrongLiteral ] ]
Right-Hand Side part
| `@temporaries `@otherTemporaries |
`.InitializationStatement.
`@condition1
ifFalse: [ ^self ].
`@.Statements.
``@value := `@condition2
ifTrue: [ ``@calculate ]
ifFalse: [ `#wrongLiteral ]
![Page 9: Code transformation by direct transformation of ASTs](https://reader036.fdocuments.net/reader036/viewer/2022062320/55d34fe7bb61eb2c628b45c3/html5/thumbnails/9.jpg)
9 Inattention causes impactful mistakes!
`.InitializationStateme
nt
`InitializationStateme
nt
![Page 10: Code transformation by direct transformation of ASTs](https://reader036.fdocuments.net/reader036/viewer/2022062320/55d34fe7bb61eb2c628b45c3/html5/thumbnails/10.jpg)
10
How to apply rules?
![Page 11: Code transformation by direct transformation of ASTs](https://reader036.fdocuments.net/reader036/viewer/2022062320/55d34fe7bb61eb2c628b45c3/html5/thumbnails/11.jpg)
11
OR
| rule result aCollection anEnvironment |
aCollection := self environment.
anEnvironment := RBClassEnvironment
classes: aCollection.
rule := (Smalltalk globals at: self rules selectedItem) new.
result := RBSmalllintChecker
runRule: rule
onEnvironment: anEnvironment.
(ChangesBrowser changes: result builder changes) open
![Page 12: Code transformation by direct transformation of ASTs](https://reader036.fdocuments.net/reader036/viewer/2022062320/55d34fe7bb61eb2c628b45c3/html5/thumbnails/12.jpg)
12 Rewrite Tool
Intuitive GUI
Real time result
Apply rules to any scope you want
Save rules for later reuse
![Page 13: Code transformation by direct transformation of ASTs](https://reader036.fdocuments.net/reader036/viewer/2022062320/55d34fe7bb61eb2c628b45c3/html5/thumbnails/13.jpg)
13
A B
C D
A. Input codeB. Resulting codeC. LHS part of ruleD. RHS part of rule
![Page 14: Code transformation by direct transformation of ASTs](https://reader036.fdocuments.net/reader036/viewer/2022062320/55d34fe7bb61eb2c628b45c3/html5/thumbnails/14.jpg)
![Page 15: Code transformation by direct transformation of ASTs](https://reader036.fdocuments.net/reader036/viewer/2022062320/55d34fe7bb61eb2c628b45c3/html5/thumbnails/15.jpg)
15
Live Demo
![Page 16: Code transformation by direct transformation of ASTs](https://reader036.fdocuments.net/reader036/viewer/2022062320/55d34fe7bb61eb2c628b45c3/html5/thumbnails/16.jpg)
16 Download & Info
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