2000 Advanced OOSA State of the Art on Software Architecture Declarative Meta Programming Session 3:...
-
Upload
imogene-moody -
Category
Documents
-
view
231 -
download
0
description
Transcript of 2000 Advanced OOSA State of the Art on Software Architecture Declarative Meta Programming Session 3:...
1December 2000 [email protected]
Advanced OOSAState of the Art on Software Architecture
Declarative Meta Programming
Session 3:Declarative Meta Programming
Nantes, EMOOSE 2000–2001Dr. Kim Mens, PROG, VUB
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 2
Course overview
Introduction Software Architecture Declarative Meta Programming Software Classification Lightweight Architectural Tools Automated Architectural Conformance Checking An Architecture-driven Software Development Tool Assignments
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 3
References
Roel WuytsDeclarative Reasoning about the Structure of Object-Oriented Systems. In Proceedings of TOOLS USA 1998, pages 112-124. IEEE Computer Society Press, 1998
Theo D'Hondt, Kris De Volder, Kim Mens & Roel WuytsCo-evolution of Object-Oriented Software Design and Implementation. In Proceedings of SACT 2000. Kluwer Academic Publishers, 2000
Roel WuytsA Logic Meta-Programming Approach to Support the Co-Evolution of Object-Oriented Design and Implementation.PhD thesis, Dept. of Computer Science, VUB, Belgium. January 2001
RECAP
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 4
Session overview
Declarative Meta Programming Logic meta programming Applications of DMP SOUL TyRuBa DMP for Java Conclusion
DMP =Declarative Meta Programming
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 5
Session overview
Declarative Meta Programming Logic meta programming Applications of DMP SOUL TyRuBa DMP for Java Conclusion
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 6
Declarative Meta Programming
DMP = Declarative Meta Programming Combines a declarative meta language with a standard
object-oriented base language Explicit symbiosis between meta and base language
base-level programs are expressed as terms, facts and rules at the meta level
meta-level programs can manipulate and reason about the base-level programs
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 7
Declarative reasoning
Declarative programming language readable, intuitive, intentional, concise e.g. a logic programming language
Declarative reasoning use a declarative programming language to reason about
structural aspects of source code in some base language check source against certain constructs, conventions, patterns search source for certain constructs, conventions, patterns extract certain constructs, conventions, patterns from source enforce certain constructs, conventions, patterns in source generate source from high-level declarative descriptions transform source based on high-level declarative descriptions
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 8
Session overview
Declarative Meta Programming Logic meta programming Applications of DMP SOUL TyRuBa DMP for Java Conclusion
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 9
Logic meta programming (LMP)
LMP = Logic Meta Programming LMP as particular flavour of DMP Meta language is a PROLOG-like logic programming
language Logic programming is good at
meta programming language processing reasoning about knowledge unification, backtracking, multi-way reasoning
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 10
LMP — Multi-way reasoning
Explain append example here
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 11
LMP languages for Smalltalk
SOUL “Smalltalk Open Unification Language” Prolog-like meta language Smalltalk (or Squeak) as base language Strong symbiosis between logic language and Smalltalk
• Logic language works directly on current Smalltalk image• Smalltalk entities can be used as constants in the logic language• Logic clauses can execute parameterised Smalltalk expressions
Prolog + Prodata Prolog as meta language Store base-level source code in ODBC-compliant repository Access repository from Prolog using some ODBC interface Weaker symbiosis but more efficient reasoning engine
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 12
LMP languages for Java
TyRuBa Java as base language Prolog-like meta language Generates Java source code
• from logic descriptions containing parameterised Java expressions
DMP for Java (C2C) Java as base language Prolog as meta language Prolog facts representing the base-level program are
generated from the Java class files for that program
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 13
Session overview
Declarative Meta Programming Logic meta programming Applications of DMP SOUL TyRuBa DMP for Java Conclusion
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 14
Applications of DMP
What is DMP used for at PROG? Emerging technique to build state-of-the art software
development tools In particular, tools to support co-evolution in all facets and
phases of the software life-cycle• information in implementation and earlier life-cycle phases may
evolve independently• need to keep information in these phases synchronised
To build advanced software architecture tools DMP is unifying approach that combines the research of
many PROG researchers Focus of this course:
DMP for building advanced software architecture tools
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 15
Some DMP experiments
Roel Wuyts: SOUL Reasoning about the structure of OO systems using the
Smalltalk Open Unification Language Synchronizing implementation and design
Kim Mens: architectural conformance checking use logic programs to declare software architectures
declaratively and check them against the implementation Tom Tourwé: code optimization & change propagation
a functional language with logic extensions to write declarative code transformations that
• detect propagation of changes to source code• replace design patterns by optimized implementations
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 16
More DMP experiments
Kris De Volder: TyRuBa very expressive type system precompiler that uses logic programs to generate (Java) code
Aspect-Oriented Programming (AOP) Kris De Volder: using TyRuBa for AOP Maja D'Hondt: expressing domain knowledge as a separate
aspect that can be factored out from the base program Johan Brichau: declarative combination of aspects
Wolfgang De Meuter & Maja D’Hondt Using DMP techniques for guiding reuse
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 17
Advanced software architecture tools
There is a need for advanced tools that support an architecture-driven software development process:
Navigating “architecture-driven browsing” through the source-code
Conformance checking of source code to architectural descriptions
Enforcing architectural constraints over the source code
Generating source-code (fragments) from architecture descriptions
...
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 18
Advanced software architecture tools
... Extracting
architectural information from source code Transforming & reverse-engineering
source code based on architectural information Co-evolution
keep source code and architecture synchronised when one of the evolves
change propagation, impact analysis, conflict detection, … Etc.
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 19
Session overview
Declarative Meta Programming Logic meta programming Applications of DMP SOUL TyRuBa DMP for Java Conclusion
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 20
SOUL
Set-up Integration with Smalltalk SOUL environment Prolog variant Declarative framework
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 21
SOUL set-up
Experiments were conducted in two alternative set-ups: SOUL Prolog
Reason about and manipulatesource code:
check, extract, search,generate, enforce, transform
Smalltalkimplementation
artefacts
Meta-level Interface
SOUL SmalltalkImage
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 22
SOUL
Set-up Integration with Smalltalk SOUL environment Prolog variant Declarative framework
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 23
SOUL is integrated with SmalltalkVisualWorks
Smalltalkenvironment
SOUL menu(opens SOULapplications)
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 24
SOUL is embedded in Smalltalk
Actual SOULcode can be
inspected
Smalltalkclass browser
Logic repositoriesare stored as
special “classes”
“Methods” groupset of relatedlogic clauses
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 25
SOUL language
Rule class(?class) ifconstant(?class),[ SOULExplicitMLI curent isClass: ?class ].
Logic programming language, featuring symbiosis and reflection with Smalltalk
Specific language features: Smalltalk term: “wrap” extended Smalltalk code Generate predicate: transform collection of x Smalltalk
elements into x logic solutions Quoted term: represent strings with logic variables
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 26
Up-down mechanism:
Reflection: use the predefined variables ?repository or ?bindings in logic
terms expressing Smalltalk expressions to gain direct access to the current logic repository or set of bindings
Smalltalk
SOUL [ SOULExplicitMLI curent isClass: ?class ]
false
[false]
“up”“down”
Symbiosis with Smalltalk
[:env | SOULExplicitMLI curentisClass: (env at: 1) soulUp ]
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 27
SOUL
Set-up Integration with Smalltalk SOUL environment Prolog variant Declarative framework
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 28
The SOUL Repository Inspector
Construct andexecute queries
Inspect logicfacts and rules
Browse and edit(hierarchic) repository
structure
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 29
Browse and edit repository structure
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 30
Inspecting the logic repository
all clauses witha given name
SOUL implementationof the selected clause
select nameof the clause
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 31
The SOUL Query andStructural Find applications
SOULQuery
Application
SOULStructural
FindApplication
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 32
The SOUL Query Application
queryeditor
statusfield
find allquery results
find only firstquery result
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 33
The Query Result Inspector
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 34
The SOUL Structural Find Application
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 35
SOUL
Set-up Integration with Smalltalk SOUL environment Prolog variant Declarative framework
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 36
Prolog variant
Experiments were conducted in two alternative set-ups: SOUL Prolog
Smalltalkimplementation
artefacts
OD
BC
InterfaceProlog MS Access
DatabaseReason about and manipulatesource code:
check, extract, search,generate, enforce, transform
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 37
SOUL
Set-up Integration with Smalltalk SOUL environment Prolog variant Declarative framework
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 38
A layered declarative framework
ArchitecturalLayer
DesignPatterns
LayerCoding
ConventionsLayerBaseLayer
RepresentationalLayer
Repository-accessLayer
isClassifiedAsfindMetaClassedFromClasses
findMethodsFromClasses
factoryMethod compositePattern
instanceCreationMethod
isSentTo hierarchy
traverseMethodParseTree
artefact artefactNestingID
protocolNamemethodNameclassImplementsMethodNamedclassImplementsMethod
metaClass methodInProtocol
inheritanceclassName
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 39
Session overview
Declarative Meta Programming Logic meta programming Applications of DMP SOUL TyRuBa DMP for Java Conclusion
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 40
TyRuBa (Typed Rule Base)
Java Code Generation through DMP Ph.D. Thesis of Kris De Volder, 1999
Allows to write generic templates of software modules by means of DMP
Code generator instantiates these templates Generic templates are represented by logic
declarations (facts & rules)
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 41
TyRuBa Architecture
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 42
TyRuBaclass(Array<?El>,{ private ?El[] contents;
/** Construction */ Array<?El>(int sz) { contents = new ?El[sz]; }
/** Basic Array functionality */ ?El elementAt(int i) { return contents[i]; } void setElementAt(?El e,int i) { contents[i]=e; } int length() { return contents.length; }}).
class Array_LString_R { private String [ ] contents ; Array_LString_R ( int sz ) { contents = new String [ sz ] ; } String elementAt ( int i ) { return contents [ i ] ; } void setElementAt ( String e , int i ) { contents [ i ] = e ; } int length ( ) { return contents . length ; }}
Code generator
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 43
TyRuBa
Code generator can do much more reasoning E.g.: generate an implementation of a Container (e.g. Array)
based on the element it should contain. ...
Code generator itself is implemented in TyRuBa Adaptable and extensible
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 44
Session overview
Declarative Meta Programming Logic meta programming Applications of DMP SOUL TyRuBa DMP for Java Conclusion
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 45
DMP for Java
Can DMP be applied to Java? Represent Java classes as logic facts Focus on class files
Java grammar is complicated Source code is not always available Class files have a more uniform representation Class-file format is more stable over time
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 46
Java class representation
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 47
Classes to clauses: C2C
Written in Java Extracts information from class files Represents this information as logic facts Based on existing class parser: BCEL
Byte Code Engineering Library (formerly JavaClass)
Tested on Drawlets
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 48
Used representation (1)
class(<className>). interface(<className>).
accessFlag(<className>, <accessFlag>).
superclass(<className>, <superClassName>).
directInterface(<className>, <interface>).
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 49
Used representation (2)
fieldAccessFlag(<className>, <fieldName>, <flag>).
fieldDescriptor(<className>, <fieldName>, <returnType>).
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 50
Used representation (3)
methodAccessFlag(<className>, <methodName>, <argList>,<accessFlag>).
methodReturnType(…, <returnType>).
methodBody(…, <invokesUsedModifiedsList>) invokespecial(<invocation>) putfield(<fieldName>) putstatic(<fieldName>) getfield(<fieldName>) getstatic(<fieldName>)
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 51
C2C example: input class
public final class LineNumber implements Cloneable { private int start_pc; LineNumber(DataInputStream file) throws IOException { this(file.readUnsignedShort(), file.readUnsignedShort()); }
public final void dump(DataOutputStream file) throws IOException { file.writeShort(start_pc); file.writeShort(line_number);
} …}
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 52
c2c example: output (1)
class(‘LineNumber’).classAccessFlag(‘LineNumber’, public).classAccessFlag(‘LineNumber’, final).directInterface(‘LineNumber’, ‘java.lang.Cloneable’).superClass(‘LineNumber’, ‘java.lang.Object’).
fieldAccessFlags(‘LineNumber’, ‘start_pc’, private).fieldDescriptor(‘LineNumber’, ‘start_pc’, int).
methodReturnType(‘LineNumber’, ‘LineNumber’, [‘java.io.DataInputStream’], void).methodException(‘LineNumber’, ‘LineNumber’, [‘java.io.DataInputStream’],
‘java.io.IOException’).methodBody(…).
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 53
c2c example: output (2)
methodAccessFlag(‘LineNumber’, dump, [‘java.io.DataOutputStream’], public).methodAccessFlag(‘LineNumber’, dump, [‘java.io.DataOutputStream’], final).methodReturnType(‘LineNumber’, dump, [‘java.io.DataOutputStream’], void).methodException(‘LineNumber’, dump, [‘java.io.DataOutputStream’],
‘java.io.IOException’).
methodBody(‘LineNumber’, dump, [‘java.io.DataOutputStream’],[ getfield(‘start_pc’),
invokevirtual(‘java.io.DataOutputStream.writeShort(int)’),getfield(‘line_number’),invokevirtual(‘java.io.DataOutputStream.writeShort(int)’)]).
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 54
c2c example: output (3)
getfield(‘LineNumber’, dump, [‘java.io.DataOutputStream’], ‘start_pc’).
invokevirtual(‘LineNumber’, dump, [‘java.io.DataOutputStream’],‘java.io.DataOutputStream.writeShort(int)’).
getfield(‘LineNumber’, dump, [‘java.io.DataOutputStream’], ‘line_number’).
invokevirtual(‘LineNumber’, dump, [‘java.io.DataOutputStream’],‘java.io.DataOutputStream.writeShort(int)’).
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 55
Session overview
Declarative Meta Programming Logic meta programming Applications of DMP SOUL TyRuBa DMP for Java Conclusion
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 56
Conclusion
DMP = use a declarative meta language to reason about & manipulate programs written in a standard object-oriented base language
DMP is unifying approach that combines the research of many PROG researchers
Several DMP tools and environments already exist: SOUL, TyRuBa, C2C, ...
We use DMP as a technique to build state-of-the art software development tools
In particular, in this course we will focus on the use of DMP for building advanced software architecture tools
State of the Art on Software Architecture — Declarative Meta Programming Session 3, page 57
Session overview
Declarative Meta Programming Logic meta programming Applications of DMP SOUL TyRuBa DMP for Java Conclusion
Time for a break