SlideShare uma empresa Scribd logo
1 de 17
Code Transformation by
Direct Transformation of ASTs
M. Rizun, J.-C. Bach, S. Ducasse
1
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
2
transformation
Manual 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)
3
Find & Replace
“…code…”
x >= y
ifTrue: [ x ]
ifFalse: [ y ]
“…code…”
“…code…”
x max: y
“…code…”
4
Right-Hand Side partLeft-Hand Side part
Problems
Time-consuming and annoying task.
Complex and error-prone process.
Rules are not reusable.
5
Tools to automate process
Tool Create transformation rules.
Apply rules on desired environment scope.
Save rules for later reuse.
6
Rewrite Engine
Engine for code
transformation
Unintuitive
syntax & no GUI
to apply rules
Pros
Cons
7
“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 ]
8
Inattention causes impactful mistakes!
`.InitializationStatement `InitializationStatement
9
10
How to apply rules?
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
11
Rewrite Tool
 Intuitive GUI
 Real time result
 Apply rules to any scope you want
 Save rules for later reuse
12
A. Input code
B. Resulting code
C. LHS part of rule
D. RHS part of rule
13
15
Live Demo
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
Mark Rizun e-mail: mrizun@gmail.com blog: http://myfuncoding.blogspot.com/
17

Mais conteúdo relacionado

Mais procurados

Code Optimization
Code OptimizationCode Optimization
Code OptimizationESUG
 
Exercise6 ch2
Exercise6 ch2Exercise6 ch2
Exercise6 ch2IIUM
 
7.3 daqy 2
7.3 daqy 27.3 daqy 2
7.3 daqy 2leblance
 
Debugging Python with Pdb!
Debugging Python with Pdb!Debugging Python with Pdb!
Debugging Python with Pdb!Noelle Daley
 
Hash Function(Grostl) and Contex Hull Research paper
Hash Function(Grostl) and Contex Hull Research paperHash Function(Grostl) and Contex Hull Research paper
Hash Function(Grostl) and Contex Hull Research paperSAIFUR RAHMAN
 
Write a C function that returns the length of a string. Function name: strinq...
Write a C function that returns the length of a string. Function name: strinq...Write a C function that returns the length of a string. Function name: strinq...
Write a C function that returns the length of a string. Function name: strinq...hwbloom42
 
Optimization in the world of 64-bit errors
Optimization  in the world of 64-bit errorsOptimization  in the world of 64-bit errors
Optimization in the world of 64-bit errorsPVS-Studio
 
Recurrence relationships
Recurrence relationshipsRecurrence relationships
Recurrence relationshipsDevansh16
 
C programming - String
C programming - StringC programming - String
C programming - StringAchyut Devkota
 
Process of algorithm evaluation
Process of algorithm evaluationProcess of algorithm evaluation
Process of algorithm evaluationAshish Ranjan
 
Hw5 2017-spring
Hw5 2017-springHw5 2017-spring
Hw5 2017-spring奕安 陳
 

Mais procurados (17)

Code optimization
Code optimization Code optimization
Code optimization
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Exercise6 ch2
Exercise6 ch2Exercise6 ch2
Exercise6 ch2
 
C programming Tutorial Session 1
C programming Tutorial Session 1C programming Tutorial Session 1
C programming Tutorial Session 1
 
7.3 daqy 2
7.3 daqy 27.3 daqy 2
7.3 daqy 2
 
Debugging Python with Pdb!
Debugging Python with Pdb!Debugging Python with Pdb!
Debugging Python with Pdb!
 
C programming Tutorial Session 4
C programming Tutorial Session 4C programming Tutorial Session 4
C programming Tutorial Session 4
 
Hash Function(Grostl) and Contex Hull Research paper
Hash Function(Grostl) and Contex Hull Research paperHash Function(Grostl) and Contex Hull Research paper
Hash Function(Grostl) and Contex Hull Research paper
 
Write a C function that returns the length of a string. Function name: strinq...
Write a C function that returns the length of a string. Function name: strinq...Write a C function that returns the length of a string. Function name: strinq...
Write a C function that returns the length of a string. Function name: strinq...
 
String functions in C
String functions in CString functions in C
String functions in C
 
NACA Regula Falsi Method
 NACA Regula Falsi Method NACA Regula Falsi Method
NACA Regula Falsi Method
 
Optimization in the world of 64-bit errors
Optimization  in the world of 64-bit errorsOptimization  in the world of 64-bit errors
Optimization in the world of 64-bit errors
 
Recurrence relationships
Recurrence relationshipsRecurrence relationships
Recurrence relationships
 
C programming - String
C programming - StringC programming - String
C programming - String
 
vhdl exp-5
vhdl exp-5vhdl exp-5
vhdl exp-5
 
Process of algorithm evaluation
Process of algorithm evaluationProcess of algorithm evaluation
Process of algorithm evaluation
 
Hw5 2017-spring
Hw5 2017-springHw5 2017-spring
Hw5 2017-spring
 

Destaque

Presentación Web 2.0
Presentación Web 2.0Presentación Web 2.0
Presentación Web 2.0cesarandruben
 
Gary Lim DBS Real Estate - Testimonial
Gary Lim DBS Real Estate - TestimonialGary Lim DBS Real Estate - Testimonial
Gary Lim DBS Real Estate - TestimonialMarvin Tan
 
Lab. modestina
Lab. modestinaLab. modestina
Lab. modestinaluarafaria
 
zzz McALEER REFERENCE
zzz McALEER REFERENCEzzz McALEER REFERENCE
zzz McALEER REFERENCEVince Fallon
 
Antonio e nuno
Antonio e nunoAntonio e nuno
Antonio e nunoTurma 6a
 
Casa Gastronômica Expresso 500 / Selo BH Sustentável - Cyleno Guimarães
Casa Gastronômica Expresso 500 / Selo BH Sustentável - Cyleno Guimarães Casa Gastronômica Expresso 500 / Selo BH Sustentável - Cyleno Guimarães
Casa Gastronômica Expresso 500 / Selo BH Sustentável - Cyleno Guimarães forumsustentar
 
Políticas Ambientais e Sustentabilidade – Experiências de Fortaleza/CE - Ana...
Políticas Ambientais e Sustentabilidade  – Experiências de Fortaleza/CE - Ana...Políticas Ambientais e Sustentabilidade  – Experiências de Fortaleza/CE - Ana...
Políticas Ambientais e Sustentabilidade – Experiências de Fortaleza/CE - Ana...forumsustentar
 
CENTRO EDUCATIVO SANTA TERESA - YOPAL-
CENTRO EDUCATIVO SANTA TERESA - YOPAL-CENTRO EDUCATIVO SANTA TERESA - YOPAL-
CENTRO EDUCATIVO SANTA TERESA - YOPAL-ATALAMIA
 
Becas en Administración en Red
Becas en Administración en RedBecas en Administración en Red
Becas en Administración en RedAlexander Perdomo
 
HistoriadeespaýA[1][1]. LaespaýAdenuestrosdýAs
HistoriadeespaýA[1][1]. LaespaýAdenuestrosdýAsHistoriadeespaýA[1][1]. LaespaýAdenuestrosdýAs
HistoriadeespaýA[1][1]. LaespaýAdenuestrosdýAsshewaka
 
Inclusion.Superior
Inclusion.SuperiorInclusion.Superior
Inclusion.Superiorf.equitas
 
Oliver con Pamela en los camerinos
Oliver con Pamela en los camerinosOliver con Pamela en los camerinos
Oliver con Pamela en los camerinosJandritaGH
 
Los tiempos de jesús
Los tiempos de jesúsLos tiempos de jesús
Los tiempos de jesúspacoguirola
 

Destaque (20)

Presentación Web 2.0
Presentación Web 2.0Presentación Web 2.0
Presentación Web 2.0
 
Ltter Head
Ltter HeadLtter Head
Ltter Head
 
Releituras miró 3º e
Releituras miró 3º eReleituras miró 3º e
Releituras miró 3º e
 
Gary Lim DBS Real Estate - Testimonial
Gary Lim DBS Real Estate - TestimonialGary Lim DBS Real Estate - Testimonial
Gary Lim DBS Real Estate - Testimonial
 
HagerDirectMail2
HagerDirectMail2HagerDirectMail2
HagerDirectMail2
 
Lab. modestina
Lab. modestinaLab. modestina
Lab. modestina
 
zzz McALEER REFERENCE
zzz McALEER REFERENCEzzz McALEER REFERENCE
zzz McALEER REFERENCE
 
Antonio e nuno
Antonio e nunoAntonio e nuno
Antonio e nuno
 
Apresentação SEO
Apresentação SEOApresentação SEO
Apresentação SEO
 
Casa Gastronômica Expresso 500 / Selo BH Sustentável - Cyleno Guimarães
Casa Gastronômica Expresso 500 / Selo BH Sustentável - Cyleno Guimarães Casa Gastronômica Expresso 500 / Selo BH Sustentável - Cyleno Guimarães
Casa Gastronômica Expresso 500 / Selo BH Sustentável - Cyleno Guimarães
 
Políticas Ambientais e Sustentabilidade – Experiências de Fortaleza/CE - Ana...
Políticas Ambientais e Sustentabilidade  – Experiências de Fortaleza/CE - Ana...Políticas Ambientais e Sustentabilidade  – Experiências de Fortaleza/CE - Ana...
Políticas Ambientais e Sustentabilidade – Experiências de Fortaleza/CE - Ana...
 
CENTRO EDUCATIVO SANTA TERESA - YOPAL-
CENTRO EDUCATIVO SANTA TERESA - YOPAL-CENTRO EDUCATIVO SANTA TERESA - YOPAL-
CENTRO EDUCATIVO SANTA TERESA - YOPAL-
 
caminho_critico_f
caminho_critico_fcaminho_critico_f
caminho_critico_f
 
Becas en Administración en Red
Becas en Administración en RedBecas en Administración en Red
Becas en Administración en Red
 
HistoriadeespaýA[1][1]. LaespaýAdenuestrosdýAs
HistoriadeespaýA[1][1]. LaespaýAdenuestrosdýAsHistoriadeespaýA[1][1]. LaespaýAdenuestrosdýAs
HistoriadeespaýA[1][1]. LaespaýAdenuestrosdýAs
 
Inclusion.Superior
Inclusion.SuperiorInclusion.Superior
Inclusion.Superior
 
Oliver con Pamela en los camerinos
Oliver con Pamela en los camerinosOliver con Pamela en los camerinos
Oliver con Pamela en los camerinos
 
Manual Handling
Manual HandlingManual Handling
Manual Handling
 
Los tiempos de jesús
Los tiempos de jesúsLos tiempos de jesús
Los tiempos de jesús
 
Mara
MaraMara
Mara
 

Semelhante a Code transformation by direct transformation of ASTs

refactoring code by clean code rules
refactoring code by clean code rulesrefactoring code by clean code rules
refactoring code by clean code rulessaber tabatabaee
 
DAC CCAT GUESS PAPER Jun-Jul 2013
DAC CCAT GUESS PAPER Jun-Jul 2013 DAC CCAT GUESS PAPER Jun-Jul 2013
DAC CCAT GUESS PAPER Jun-Jul 2013 prabhatjon
 
Phases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingPhases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingMukesh Tekwani
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptxPython Homework Help
 
Detecting soft errors by a purely software approach
Detecting soft errors by a purely software approachDetecting soft errors by a purely software approach
Detecting soft errors by a purely software approachMd. Hasibur Rashid
 
Detecting soft errors by a purely software approach
Detecting soft errors by a purely software approachDetecting soft errors by a purely software approach
Detecting soft errors by a purely software approachMd. Hasibur Rashid
 
Libra : A Compatible Method for Defending Against Arbitrary Memory Overwrite
Libra : A Compatible Method for Defending Against Arbitrary Memory OverwriteLibra : A Compatible Method for Defending Against Arbitrary Memory Overwrite
Libra : A Compatible Method for Defending Against Arbitrary Memory OverwriteJeremy Haung
 
GSP 215 Effective Communication - tutorialrank.com
GSP 215  Effective Communication - tutorialrank.comGSP 215  Effective Communication - tutorialrank.com
GSP 215 Effective Communication - tutorialrank.comBartholomew35
 
Software testing strategies
Software testing strategiesSoftware testing strategies
Software testing strategiesKrishna Sujeer
 
Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design LogsAk
 

Semelhante a Code transformation by direct transformation of ASTs (20)

Compilation
CompilationCompilation
Compilation
 
Compilation
CompilationCompilation
Compilation
 
Cs419 lec12 semantic analyzer
Cs419 lec12  semantic analyzerCs419 lec12  semantic analyzer
Cs419 lec12 semantic analyzer
 
refactoring code by clean code rules
refactoring code by clean code rulesrefactoring code by clean code rules
refactoring code by clean code rules
 
DAC CCAT GUESS PAPER Jun-Jul 2013
DAC CCAT GUESS PAPER Jun-Jul 2013 DAC CCAT GUESS PAPER Jun-Jul 2013
DAC CCAT GUESS PAPER Jun-Jul 2013
 
Javascript.ppt
Javascript.pptJavascript.ppt
Javascript.ppt
 
Phases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingPhases of the Compiler - Systems Programming
Phases of the Compiler - Systems Programming
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
 
Detecting soft errors by a purely software approach
Detecting soft errors by a purely software approachDetecting soft errors by a purely software approach
Detecting soft errors by a purely software approach
 
Detecting soft errors by a purely software approach
Detecting soft errors by a purely software approachDetecting soft errors by a purely software approach
Detecting soft errors by a purely software approach
 
Libra : A Compatible Method for Defending Against Arbitrary Memory Overwrite
Libra : A Compatible Method for Defending Against Arbitrary Memory OverwriteLibra : A Compatible Method for Defending Against Arbitrary Memory Overwrite
Libra : A Compatible Method for Defending Against Arbitrary Memory Overwrite
 
GSP 215 Effective Communication - tutorialrank.com
GSP 215  Effective Communication - tutorialrank.comGSP 215  Effective Communication - tutorialrank.com
GSP 215 Effective Communication - tutorialrank.com
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Software testing strategies
Software testing strategiesSoftware testing strategies
Software testing strategies
 
Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design
 
embedded C.pptx
embedded C.pptxembedded C.pptx
embedded C.pptx
 

Último

Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Sérgio Sacani
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Lokesh Kothari
 
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsBiogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsSérgio Sacani
 
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 60009654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000Sapana Sha
 
Green chemistry and Sustainable development.pptx
Green chemistry  and Sustainable development.pptxGreen chemistry  and Sustainable development.pptx
Green chemistry and Sustainable development.pptxRajatChauhan518211
 
Presentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxPresentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxgindu3009
 
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceuticsPulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceuticssakshisoni2385
 
Animal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxAnimal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxUmerFayaz5
 
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...Lokesh Kothari
 
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...ssifa0344
 
GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)Areesha Ahmad
 
Seismic Method Estimate velocity from seismic data.pptx
Seismic Method Estimate velocity from seismic  data.pptxSeismic Method Estimate velocity from seismic  data.pptx
Seismic Method Estimate velocity from seismic data.pptxAlMamun560346
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTSérgio Sacani
 
Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfSumit Kumar yadav
 
Forensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfForensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfrohankumarsinghrore1
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...RohitNehra6
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...Sérgio Sacani
 
COST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptxCOST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptxFarihaAbdulRasheed
 
Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)PraveenaKalaiselvan1
 
Botany krishna series 2nd semester Only Mcq type questions
Botany krishna series 2nd semester Only Mcq type questionsBotany krishna series 2nd semester Only Mcq type questions
Botany krishna series 2nd semester Only Mcq type questionsSumit Kumar yadav
 

Último (20)

Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
 
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsBiogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
 
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 60009654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
 
Green chemistry and Sustainable development.pptx
Green chemistry  and Sustainable development.pptxGreen chemistry  and Sustainable development.pptx
Green chemistry and Sustainable development.pptx
 
Presentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxPresentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptx
 
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceuticsPulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
 
Animal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxAnimal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptx
 
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
 
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
 
GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)
 
Seismic Method Estimate velocity from seismic data.pptx
Seismic Method Estimate velocity from seismic  data.pptxSeismic Method Estimate velocity from seismic  data.pptx
Seismic Method Estimate velocity from seismic data.pptx
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOST
 
Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdf
 
Forensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfForensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdf
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
 
COST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptxCOST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptx
 
Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)
 
Botany krishna series 2nd semester Only Mcq type questions
Botany krishna series 2nd semester Only Mcq type questionsBotany krishna series 2nd semester Only Mcq type questions
Botany krishna series 2nd semester Only Mcq type questions
 

Code transformation by direct transformation of ASTs

  • 1. Code Transformation by Direct Transformation of ASTs M. Rizun, J.-C. Bach, S. Ducasse 1
  • 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 2 transformation
  • 3. Manual 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) 3
  • 4. Find & Replace “…code…” x >= y ifTrue: [ x ] ifFalse: [ y ] “…code…” “…code…” x max: y “…code…” 4 Right-Hand Side partLeft-Hand Side part
  • 5. Problems Time-consuming and annoying task. Complex and error-prone process. Rules are not reusable. 5
  • 6. Tools to automate process Tool Create transformation rules. Apply rules on desired environment scope. Save rules for later reuse. 6
  • 7. Rewrite Engine Engine for code transformation Unintuitive syntax & no GUI to apply rules Pros Cons 7
  • 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 ] 8
  • 9. Inattention causes impactful mistakes! `.InitializationStatement `InitializationStatement 9
  • 10. 10 How to apply rules?
  • 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 11
  • 12. Rewrite Tool  Intuitive GUI  Real time result  Apply rules to any scope you want  Save rules for later reuse 12
  • 13. A. Input code B. Resulting code C. LHS part of rule D. RHS part of rule 13
  • 14.
  • 16. 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
  • 17. Mark Rizun e-mail: mrizun@gmail.com blog: http://myfuncoding.blogspot.com/ 17

Notas do Editor

  1. Usually we transform code because we want to: 1 Improve readability and quality of code 2 Make the integration of new features to the code easier 3 To change the API The transformation is a change of structure of code. We call it LHS and RHS part of transformation rule.
  2. Considering our example, we get the following transformation rule where x and y are some abstract objects. In case of single method, it is easy to perform transformation. However when it is required to carry out the transformation on big system (with large code base) we have to do the following process.
  3. Obviously, to avoid such problems, it is mandatory to use tools to automate code transformation process, especially in big systems.
  4. Rewrite Engine – an engine that allows defining abstract expressions to match and transform code. However, the language, that is used to define LHS and RHS parts of rule, has unintuitive syntax. Moreover, there is no GUI to apply rules to desired environment scope.
  5. Syntax ` or `@ or ``@ or `# or `@. Etc.
  6. Inattention can cause impactful mistakes like missed symbol, or misspelt name. For example, if one misses a dot symbol in `.InitializationStatement, it will match not a statement, but a single variable. Thus, the whole rule will be completely different than one planned, and it will match different code than was desired.
  7. In Pharo, we have no GUI that would allow user to apply rewrite rule. Clearly, you can apply code transformation programmatically, but not everyone knows how to write that code. The code for applying rules would look similar to what is on slide.
  8. Rewrite Tool. It provides intuitive GUI for implementing rewrite rules, and, what is important, the tool does not require knowledge of Rewrite Engine syntax. Also while creating rule, user is able to see the result of applying current rule on the source code in real time. The Rewrite Tool saves user created rules for later reuse and allows users to apply rules on specific environment scope (packages/classes).
  9. To create transformation rules RT provides contextual menu. For example when user selects an instance of RBBlockNode (the block []), he has an option to create an abstraction that matches any block.