19
SWAT - Software Analysis and Transformation Tips & Tricks for TUE students doing Architecture Reconstruction with Rascal Jurgen Vinju Davy Landman https://gist.github.com/jurgenvinju/8972255 http://update.rascal-mpl.org/unstable See peach assignment 0 for install instruction And assignment 2 and Tonella & Potrich

Tips & Tricks for TUE students doing Architecture ...aserebre/2IMP25/2015-2016/TipsAndTricksTUE.pdf · UML & Object Flow Source Code Rascal M3 AST Model loc abstract Flow Program

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Tips & Tricks for TUE students doing Architecture ...aserebre/2IMP25/2015-2016/TipsAndTricksTUE.pdf · UML & Object Flow Source Code Rascal M3 AST Model loc abstract Flow Program

SWAT - Software Analysis and Transformation

Tips & Tricks for TUE students

doing Architecture Reconstruction with Rascal

Jurgen Vinju Davy Landman

https://gist.github.com/jurgenvinju/8972255 http://update.rascal-mpl.org/unstable

See peach assignment 0 for install instruction And assignment 2 and Tonella & Potrich

Page 2: Tips & Tricks for TUE students doing Architecture ...aserebre/2IMP25/2015-2016/TipsAndTricksTUE.pdf · UML & Object Flow Source Code Rascal M3 AST Model loc abstract Flow Program

2

Research

Gereedschap

Industrie

Rascal

valorisatie (toepassing)

experiment (validatie)

kennisuitwisseling

meer gereedschap mogelijk maken

PL

SE

Page 3: Tips & Tricks for TUE students doing Architecture ...aserebre/2IMP25/2015-2016/TipsAndTricksTUE.pdf · UML & Object Flow Source Code Rascal M3 AST Model loc abstract Flow Program

3

• PhD supersnelle code genereren voor hele grote printers bij OCÉ

• Accurate modellen extraheren uit C en C++ code bij Philips Healthcare

Vacatures

Page 4: Tips & Tricks for TUE students doing Architecture ...aserebre/2IMP25/2015-2016/TipsAndTricksTUE.pdf · UML & Object Flow Source Code Rascal M3 AST Model loc abstract Flow Program

SWAT - SoftWare Analysis and Transformation

Code

Model

Picture

GenerationExtraction

FormalizationVisualization

Transformation

Conversion

Analysis

Execution

Rendering

(Brueghel, Tower of Babel)

Rascal is a DSL for

meta programming

Page 5: Tips & Tricks for TUE students doing Architecture ...aserebre/2IMP25/2015-2016/TipsAndTricksTUE.pdf · UML & Object Flow Source Code Rascal M3 AST Model loc abstract Flow Program

SWAT - SoftWare Analysis and Transformation

Extract Analyze SYnthesize

Source Code

Java project Eclipse JDT

Projects

Parser

Name resolver

Type

Rascal M3

AST

Model

loc

Your Rascal code

comprehensions visitors

functions patterns

relational operators string templates

Figure

Rascal Eclipse Lib

Editors

Image in Eclipse

View GraphViz

DOT

Page 6: Tips & Tricks for TUE students doing Architecture ...aserebre/2IMP25/2015-2016/TipsAndTricksTUE.pdf · UML & Object Flow Source Code Rascal M3 AST Model loc abstract Flow Program

SWAT - SoftWare Analysis and Transformation

UML & Object FlowSource Code

Rascal M3

AST

Model

loc

abstract

Flow ProgramYour code

not executable but flow is the same

as the original -

only handful of constructs

queries the flow program and the M3

model.

rel[loc,loc]Flow graph

builds basic UML diagram

& uses flow graph

to add/filter edges

Your code

UML Diagrams render

extract

filter &propagate generate

Page 7: Tips & Tricks for TUE students doing Architecture ...aserebre/2IMP25/2015-2016/TipsAndTricksTUE.pdf · UML & Object Flow Source Code Rascal M3 AST Model loc abstract Flow Program

SWAT - SoftWare Analysis and Transformation

Identifying code• Source code locations: loc type

• |project://MyProj/src/org/myproj/Fruit.java|

• Structured names: loc type

• |java+class://java/util/List|

• |java+class://java/util/List| + “this” == |java+class://java/util/List/this|

• Back to code

• hyperlinks (if you extracted a full M3 model)

• IO::readFile(loc) produces a str with the contents

Page 8: Tips & Tricks for TUE students doing Architecture ...aserebre/2IMP25/2015-2016/TipsAndTricksTUE.pdf · UML & Object Flow Source Code Rascal M3 AST Model loc abstract Flow Program

SWAT - SoftWare Analysis and Transformation

Getting facts• First have a compileable Eclipse project “eLib”

• import lang::java::jdt::m3::Core; import lang::java::jdt::m3::AST;

• m = createM3FromEclipseProject(|project://eLib|);

• import lang::java::flow::JavaToObjectFlow;

• import analysis::flow::ObjectFlow;

• p = createOFG(|project://eLib|);

• Now you have:

• an M3 model in m

• a flow program in p

• hyperlinks

Page 9: Tips & Tricks for TUE students doing Architecture ...aserebre/2IMP25/2015-2016/TipsAndTricksTUE.pdf · UML & Object Flow Source Code Rascal M3 AST Model loc abstract Flow Program

SWAT - SoftWare Analysis and Transformation

src

m3 flow program???

Page 10: Tips & Tricks for TUE students doing Architecture ...aserebre/2IMP25/2015-2016/TipsAndTricksTUE.pdf · UML & Object Flow Source Code Rascal M3 AST Model loc abstract Flow Program

SWAT - SoftWare Analysis and Transformation

src

m3 flow program???

Page 11: Tips & Tricks for TUE students doing Architecture ...aserebre/2IMP25/2015-2016/TipsAndTricksTUE.pdf · UML & Object Flow Source Code Rascal M3 AST Model loc abstract Flow Program

SWAT - SoftWare Analysis and Transformation

Initial flow graph

• a relation as a graph

• uses generators and matching to project out of program

• uses “+” on locs to build new implicit identifiers

• uses “index” from List to pair formal/actual parameters

Page 12: Tips & Tricks for TUE students doing Architecture ...aserebre/2IMP25/2015-2016/TipsAndTricksTUE.pdf · UML & Object Flow Source Code Rascal M3 AST Model loc abstract Flow Program

SWAT - SoftWare Analysis and Transformation

Flow propagation sketch

• use “solve” for fixed point

• projection “g[n]” is succ, revert and project “g<to,from>[n]” is pred

• comprehensions for next solution

Page 13: Tips & Tricks for TUE students doing Architecture ...aserebre/2IMP25/2015-2016/TipsAndTricksTUE.pdf · UML & Object Flow Source Code Rascal M3 AST Model loc abstract Flow Program

SWAT - SoftWare Analysis and Transformation

Faster flow propagation• Use more builtin primitives:

invert eagerly

compose instead of comprehension

Page 14: Tips & Tricks for TUE students doing Architecture ...aserebre/2IMP25/2015-2016/TipsAndTricksTUE.pdf · UML & Object Flow Source Code Rascal M3 AST Model loc abstract Flow Program

14

veilig overschatten: geen gemiste edges, maar wel teveel edges

gevonden

goed gevonden

vals alarm

goed genegeerd

gemiste bugs

échte oplossing

Page 15: Tips & Tricks for TUE students doing Architecture ...aserebre/2IMP25/2015-2016/TipsAndTricksTUE.pdf · UML & Object Flow Source Code Rascal M3 AST Model loc abstract Flow Program

15

efficiënt onderschatten: nooit te veel edges, maar je mist wel veel edges

gevonden

goed gevonden

vals alarm

goed genegeerd

gemiste bugs

échte oplossing

Page 16: Tips & Tricks for TUE students doing Architecture ...aserebre/2IMP25/2015-2016/TipsAndTricksTUE.pdf · UML & Object Flow Source Code Rascal M3 AST Model loc abstract Flow Program

16

gevonden

goed gevonden

vals alarm

goed genegeerd

gemiste bugs

Onder- en overschatten tegelijkertijd: lijkt haast onvermijdbaar… maar creëert verwarring

échte oplossing

Page 17: Tips & Tricks for TUE students doing Architecture ...aserebre/2IMP25/2015-2016/TipsAndTricksTUE.pdf · UML & Object Flow Source Code Rascal M3 AST Model loc abstract Flow Program

SWAT - SoftWare Analysis and Transformation

Debugging• IO::println, iprintln,

• util::ValueUI::text,tree,graph

• interactive debugger (just put a breakpoint)

• online manual?! http://tutor.rascal-mpl.org, also in Eclipse Tutor View

• online questions?! http://ask.rascal-mpl.org

• Issue tracker at github.org

Page 18: Tips & Tricks for TUE students doing Architecture ...aserebre/2IMP25/2015-2016/TipsAndTricksTUE.pdf · UML & Object Flow Source Code Rascal M3 AST Model loc abstract Flow Program

SWAT - SoftWare Analysis and Transformation

Caveats

• No type checker (coming soon)

• No incremental parsing (one error at a time)

• Slowness (compiler coming soon)

• But: consider doing this from scratch :-)

Page 19: Tips & Tricks for TUE students doing Architecture ...aserebre/2IMP25/2015-2016/TipsAndTricksTUE.pdf · UML & Object Flow Source Code Rascal M3 AST Model loc abstract Flow Program

SWAT - SoftWare Analysis and Transformation

Demo• Inheritance diagram from Eclipse Java project

• Get code into an Eclipse Java project

• Start a Rascal project

• Start a Rascal console

• Browse library code and tutorial

• Script the tool

• https://gist.github.com/jurgenvinju/8972255