SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

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奕安 陳
 

Tendances (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
 

En vedette

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
 

En vedette (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
 

Similaire à 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
 

Similaire à 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
 

Dernier

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
 
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts ServiceJustdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Servicemonikaservice1
 
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPirithiRaju
 
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.Nitya salvi
 
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Alandi Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Bacterial Identification and Classifications
Bacterial Identification and ClassificationsBacterial Identification and Classifications
Bacterial Identification and ClassificationsAreesha Ahmad
 
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
 
GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)Areesha Ahmad
 
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
 
9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Servicenishacall1
 
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
 
Chemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdfChemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdfSumit Kumar yadav
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksSérgio Sacani
 
Nanoparticles synthesis and characterization​ ​
Nanoparticles synthesis and characterization​  ​Nanoparticles synthesis and characterization​  ​
Nanoparticles synthesis and characterization​ ​kaibalyasahoo82800
 
Connaught Place, Delhi Call girls :8448380779 Model Escorts | 100% verified
Connaught Place, Delhi Call girls :8448380779 Model Escorts | 100% verifiedConnaught Place, Delhi Call girls :8448380779 Model Escorts | 100% verified
Connaught Place, Delhi Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
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
 
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
 
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
 
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryFAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryAlex Henderson
 

Dernier (20)

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
 
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts ServiceJustdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
 
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
 
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
 
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Alandi Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance Booking
 
Bacterial Identification and Classifications
Bacterial Identification and ClassificationsBacterial Identification and Classifications
Bacterial Identification and Classifications
 
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
 
GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)
 
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
 
9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service
 
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
 
Chemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdfChemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdf
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disks
 
Nanoparticles synthesis and characterization​ ​
Nanoparticles synthesis and characterization​  ​Nanoparticles synthesis and characterization​  ​
Nanoparticles synthesis and characterization​ ​
 
Connaught Place, Delhi Call girls :8448380779 Model Escorts | 100% verified
Connaught Place, Delhi Call girls :8448380779 Model Escorts | 100% verifiedConnaught Place, Delhi Call girls :8448380779 Model Escorts | 100% verified
Connaught Place, Delhi Call girls :8448380779 Model Escorts | 100% verified
 
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
 
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...
 
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...
 
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryFAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
 

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

Notes de l'éditeur

  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.