http://prog.vub.ac.be © Programming Technology Lab 1
Declarative Meta Programming
Dr. Kim Mens ([email protected])Programming Technology LabVrije Universiteit Brussel
© Programming Technology Lab 2May 2001
Overview of the presentation
Part 1: Declarative Meta Programming at the Programming Technology Lab
Part 2: Declarative Meta Programming for checking architectural conformance
http://prog.vub.ac.be © Programming Technology Lab 3
Part 1Declarative Meta Programming …
… at the Programming Technology Lab
© Programming Technology Lab 4May 2001
Overview of Part 1
Declarative Meta Programming Logic Meta Programming Applications of DMP SOUL TyRuBa QSOUL SOUL for Java Conclusion
DMP =Declarative Meta Programming
© Programming Technology Lab 5May 2001
Overview
Declarative Meta Programming Logic Meta Programming Applications of DMP SOUL TyRuBa QSOUL SOUL for Java Conclusion
© Programming Technology Lab 6May 2001
Declarative Meta Programming (DMP)
DMP = Declarative Meta ProgrammingCombines declarative meta language with
standard (object-oriented) base languagebase-level programs are expressed as terms,
facts and rules at the meta levelmeta-level programs can manipulate and
reason about base-level programs
© Programming Technology Lab 7May 2001
Declarative Reasoning
Declarative programming language readable, intuitive, intentional, concisee.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
© Programming Technology Lab 8May 2001
Overview
Declarative Meta Programming Logic Meta Programming Applications of DMP SOUL TyRuBa QSOUL SOUL for Java Conclusion
© Programming Technology Lab 9May 2001
Logic Meta Programming
LMP = Logic Meta Programming LMP is particular flavour of DMP Meta language is a PROLOG-like logic
programming language Logic programming is good at
meta programming language processing reasoning about knowledgeunification, backtracking, multi-way reasoning
© Programming Technology Lab 10May 2001
Logic Meta Programming
Reasoning about the structure of OO systems using the Smalltalk Open Unification Language (SOUL)
Roel Wuyts, Declarative Reasoning about the Structure of Object-Oriented Systems. In Proceedings of TOOLS USA 1998, pages 112-124. IEEE Computer Society Press, 1998
© Programming Technology Lab 11May 2001
Overview
Declarative Meta Programming Logic Meta Programming Applications of DMP SOUL TyRuBa QSOUL SOUL for Java Conclusion
© Programming Technology Lab 12May 2001
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 independentlyneed to keep information in these phases synchronised
To support advanced software engineering techniques DMP is unifying approach that combines the
research of many PROG researchers
© Programming Technology Lab 13May 2001
Applications of DMP
Co-evolution of design and implementation Extract design information from the implementation. Verify the implementation with the corresponding design. Generate the implementation from the design Synchronize implementation and design
Theo D'Hondt, Kris De Volder, Kim Mens & Roel Wuyts, Co-evolution of Object-Oriented Software Design and Implementation. In Proceedings of SACT 2000. Kluwer Academic Publishers, 2000
Roel Wuyts, A 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
© Programming Technology Lab 14May 2001
Applications of DMP
Architectural conformance checkingUse logic programs to declare software
architectures declaratively and check them against the implementation
Kim Mens, Automating Architectural Conformance Checking by means of Logic Meta Programming, PhD thesis, Dept. of Computer Science, VUB, Belgium. October 2000
© Programming Technology Lab 15May 2001
Applications of DMP
Code optimization & change propagationa functional language with logic extensions to
write declarative code transformations thatdetect propagation of changes to source codereplace design patterns by optimized
implementations Tom Tourwe, Optimizing Object-Oriented Languages Through
Architectural Transformations, Published in Proceedings of the 8th
International Conference on Compiler Construction.
© Programming Technology Lab 16May 2001
Applications of DMP
Code GenerationTyRuBa
very expressive type system (“Type Rule Base”)generate implementation from logic descriptionsprecompiler that uses logic programs to generate
(Java) code Kris de Volder, Type-Oriented Logic Meta Programming for Java,
PhD thesis, Dept. of Computer Science, VUB, Belgium. September 1998
© Programming Technology Lab 17May 2001
Applications of DMP
Aspect-Oriented Programming (AOP)Aspect-Oriented Logic Meta ProgrammingExpressing domain knowledge as a separate
aspect that can be factored out from the base program
Declarative combination of aspects Kris De Volder & Johan Brichau
© Programming Technology Lab 18May 2001
Applications of DMP
Guiding reuse Maja D’Hondt Wolfgang De Meuter
© Programming Technology Lab 19May 2001
Overview
Declarative Meta Programming Logic Meta Programming Applications of DMP SOUL TyRuBa QSOUL SOUL for Java Conclusion
© Programming Technology Lab 20May 2001
SOUL
SOUL = Smalltalk Open Unification LanguageProlog-like meta languageSmalltalk as base language
Strong symbiosis between logic language and SmalltalkLogic language works directly on current Smalltalk
imageSmalltalk entities can be used as constants in the
logic languageLogic clauses can execute parameterised Smalltalk
expressions
© Programming Technology Lab 21May 2001
SOUL: set-up
Reason about and manipulatesource code:
check, extract, search,generate, enforce, transform
Smalltalkimplementation
artefacts
Me
ta-le
vel Interface
Me
ta-le
vel Interface
SOUL SmalltalkImage
© Programming Technology Lab 23May 2001
SOUL: the language
SOUL languageProlog
Constants, variables, functors, listsPredicates, facts, rules, queries
Symbiosis with SmalltalkSmalltalk term, Smalltalk objectSmalltalk clauseGenerate-predicate
append(<?car | ?cdr>,?list, <?car | ?res>) if append(?cdr,?list,?res)
class(?class) if [SOULExplicitMLI current isClass: ?
class].
© Programming Technology Lab 25May 2001
SOUL: symbiosis with ST
“Smalltalk clause”Execute parameterized Smalltalk expressions
write(?text) if [Transcript show: (?text asString). true].
smallerThan(?x,?y) ifatom(?x),atom(?y),[?x < ?y].
© Programming Technology Lab 26May 2001
SOUL: symbiosis with ST
“Smalltalk term”Represent Smalltalk objects in SOUL
clauses.Smalltalk object is the result of the evaluation
of the parameterized Smalltalk expression.
plus(?x,?y,[ ?x + ?y ]).allClasses([Smalltalk allClasses])
aInteger objectaCollection object
if class([Array])
© Programming Technology Lab 27May 2001
SOUL: symbiosis with ST
“Generate” predicateDisassembles a Smalltalk collection into
subsequent results of the generate-clause
class(?class) ifgenerate(?class,[SOULExplicitMLI current allClasses])
aCollection object containingall classes.
aClass
© Programming Technology Lab 28May 2001
SOUL: reflection mechanism
Meta-language: SOULBase-language: SmalltalkSymbiosis
Smalltalk values can be used in SOUL‘up’ of ST-values: explicit wrapper for ST-objects
defining the unification on ST-objects.SOUL values can be used in Smalltalk
‘down’ of ‘upped ST-values’: ST-value.But: ‘down’ of SOUL-values: ongoing research…
“down” “up”
© Programming Technology Lab 29May 2001
SOUL: reflection mechanism
Smalltalk
SOUL [ SOULExplicitMLI current isClass: ?class ]
false
[false]
“up”“down”
[:env | (SOULExplicitMLI currentisClass: (env at: 1) soulDown) soulUp ]
© Programming Technology Lab 30May 2001
SOUL: a layered declarative reasoning Framework
ArchitecturalLayer
DesignPatterns
LayerCoding
ConventionsLayer
BaseLayer
Representational
LayerRepository-
accessLayer
isClassifiedAs
findMetaClassedFromClasses
findMethodsFromClasses
factoryMethod compositePattern
instanceCreationMethod
isSentTo hierarchy
traverseMethodParseTree
artefact artefactNestingID
protocolNamemethodNameclassImplementsMethodNamedclassImplementsMethod
metaClass methodInProtocol
inheritanceclassName
© Programming Technology Lab 31May 2001
SOUL: example
Composite Design Pattern:
if compositePattern([VisualPart],?comp,?sel)
look for all the possible composite classes,where the component is VisualPart:
© Programming Technology Lab 32May 2001
SOUL: example
compositeStructure(?comp,?composite) ifclass(?comp),hierarchy(?comp,?composite).
compositePattern(?comp,?composite,?msg) ifcompositeStructure(?comp,?composite),compositeAggregation(?comp,?composite,?msg).
compositeAggregation(?comp,?composite,?msg) ifcommonMethods(?comp,?composite,?M,?compositeM),methodSelector(?compositeM,?msg),oneToManyStatement(?compositeM,?instVar,?enumStatement),containsSend(?enumStatement,?msg).
© Programming Technology Lab 33May 2001
SOUL: the repository inspector
Construct andexecute queries
Inspect logicfacts and rules
Browse and edit(hierarchic) repository
structure
© Programming Technology Lab 34May 2001
SOUL:the query inspector
© Programming Technology Lab 35May 2001
Overview
Declarative Meta Programming Logic Meta Programming Applications of DMP SOUL TyRuBa QSOUL SOUL for Java Conclusion
© Programming Technology Lab 36May 2001
TyRuBa
Allows to write generic templates of software modules by means of DMPMore high-level description of the software
Code generator instantiates these templatesLogic inference process
Generic templates are represented using logic declarations (facts & rules)
© Programming Technology Lab 37May 2001
TyRuBa: set-up
Set OfLogic Propositions
Set OfLogic Propositions
Logic Program=
Init Files+
User Rules
Logic Program=
Init Files+
User Rules
Represents
TyRuBa core-language implementation
Code GeneratorCode Generator
Queries
Java Source Code
Outputs
© Programming Technology Lab 38May 2001
TyRuBa: code generation
Set of logic propositionsSet of logic propositions
Base Language ProgramBase Language Program
Represents
Logic ProgramLogic Program
Represents
Represents
Java Programs are represented by facts. To generate Java code, we can use logic programs to
describe the Java programs we want to generate!
© Programming Technology Lab 39May 2001
TyRuBa: the language
TyRuBa languageProlog
Constants, variables, functors, listsPredicates, facts, rules, queries
Code generation constructsQuasiQuotedCode termCore code generator
© Programming Technology Lab 40May 2001
TyRuBa: Code generation contstructs
Quasiquoted termAllows to write down parameterized chunks of source
code.
Code GeneratorAssembles chunks of code into working programA core code generator existsThis code generator can be fine-tuned
class(Array<?el>,{private ?El[] contents; … })
© Programming Technology Lab 41May 2001
TyRuBa: example
class(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<?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; }}).
Code generator
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 ; }}
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 ; }}
Generic Java array
Java array for strings
© Programming Technology Lab 42May 2001
TyRuBa example:visitor design pattern
Design Patterns [Gamma&al.] capture solutions to common problems which are encountered while designing software.
Design Patterns [Gamma&al.] capture solutions to common problems which are encountered while designing software.
The implementation of a design pattern typically• spans several classes• must be repeated for every instance of the pattern
The implementation of a design pattern typically• spans several classes• must be repeated for every instance of the pattern
Code Scattering!
Visitor intends to separate • the basic implementation of an object structure • from operations over this structure.
© Programming Technology Lab 43May 2001
TyRuBa example:visitor design pattern
abstract class Tree { boolean isNode() { return false; } boolean isLeaf() { return false; } abstract Object accept(Visitor v);}class Node extends Tree { boolean isNode() {return true;} ... Object accept(Visitor v) { return v.visitNode(this); }}class Leaf extends AbstractTree { boolean isLeaf() {return false;} ... Object accept(Visitor v) { return v.visitLeaf(this); }}abstract class TreeVisitor { abstract Object visitNode(Node node); abstract Object visitLeaf(Leaf leaf);}
abstract class Tree { boolean isNode() { return false; } boolean isLeaf() { return false; } abstract Object accept(Visitor v);}class Node extends Tree { boolean isNode() {return true;} ... Object accept(Visitor v) { return v.visitNode(this); }}class Leaf extends AbstractTree { boolean isLeaf() {return false;} ... Object accept(Visitor v) { return v.visitLeaf(this); }}abstract class TreeVisitor { abstract Object visitNode(Node node); abstract Object visitLeaf(Leaf leaf);}
Tree
Node
isNode...accept
Leaf
isLeaf...accept
isNodeisLeafaccept
TreeVisitor
visitNodevisitLeaf
PrintVisitor
visitNodevisitLeaf
© Programming Technology Lab 44May 2001
TyRuBa example:visitor design pattern
TreeVisitor
visitNodevisitLeaf
abstractmethod(?RootNode,accept,...) :- rootVisitedNode(?Visitor,?RootNode).
method(?Visited,accept,...,{...}) :- visitedNode(?Visitor,?Visited).
abstractmethod(?Visitor,visit<?Visited>,...) :- visitedNode(?Visitor,?Visited).
abstractmethod(?RootNode,accept,...) :- rootVisitedNode(?Visitor,?RootNode).
method(?Visited,accept,...,{...}) :- visitedNode(?Visitor,?Visited).
abstractmethod(?Visitor,visit<?Visited>,...) :- visitedNode(?Visitor,?Visited).
2) Visitor Code Generation
rootVisitedNode(TreeVisitor,Tree).
visitedNode(TreeVisitor,Node).visitedNode(TreeVisitor,Leaf).
rootVisitedNode(TreeVisitor,Tree).
visitedNode(TreeVisitor,Node).visitedNode(TreeVisitor,Leaf).
1) Knowledge about this particular visitor Tree
Node
isNode...accept
Leaf
isLeaf...accept
isNodeisLeafaccept
© Programming Technology Lab 45May 2001
Synchronization: code scattering
TODOclass Stack { public Object peek ( ) { while (true) { synchronized (this) { … } } try { return contents [ pos ]; } finally { synchronized ( this ) { … }}public void push ( Object e ) { while (true) { synchronized (this) { … } } try { contents[++pos]=e; } finally { synchronized ( this ) { … }}
class Stack { public Object peek ( ) { while (true) { synchronized (this) { … } } try { return contents [ pos ]; } finally { synchronized ( this ) { … }}public void push ( Object e ) { while (true) { synchronized (this) { … } } try { contents[++pos]=e; } finally { synchronized ( this ) { … }}
© Programming Technology Lab 46May 2001
Synchronization: AOP solution
Separate out ‘synchronization aspect’ from the basic functionality.Use a special purpose synchronization aspect language
Separate out ‘synchronization aspect’ from the basic functionality.Use a special purpose synchronization aspect language
class Stack {public Object peek ( ) { return contents[pos];} public void push (Object e) { contents[++pos]=e; } ...
class Stack {public Object peek ( ) { return contents[pos];} public void push (Object e) { contents[++pos]=e; } ...
Basic functionality
mutuallyExclusive(push,pop)mutuallyExclusive(push,peek)...
mutuallyExclusive(push,pop)mutuallyExclusive(push,peek)...
Aspect declarationsWeaver
class Stack {public Object peek ( ) { while (true) { synchronized (this) { … } } try { return contents [ pos ]; } finally { synchronized ( this ) { … }}public void push ( Object e ) { while (true) { synchronized (this) { … } } try { contents[++pos]=e; } finally { synchronized ( this ) { … }}
class Stack {public Object peek ( ) { while (true) { synchronized (this) { … } } try { return contents [ pos ]; } finally { synchronized ( this ) { … }}public void push ( Object e ) { while (true) { synchronized (this) { … } } try { contents[++pos]=e; } finally { synchronized ( this ) { … }}
© Programming Technology Lab 47May 2001
Using TyRuBa-LMP for AOP
Logic program representing aspect
declarations
Weaver
Logic Program
Facts representingbasic functionality code
+Java code
with synchronization
Basic Functionality CodeIn Java
Parser
© Programming Technology Lab 48May 2001
Overview
Declarative Meta Programming Logic Meta Programming Applications of DMP SOUL TyRuBa QSOUL SOUL for Java Conclusion
© Programming Technology Lab 49May 2001
QSOUL:combine TyRuBa & SOUL
QSOUL = “Quasiquoted SOUL”SOUL expanded with quasiquoted termsImplementation in Squeak
Idea: combination of reasoning about code and code-generation.
© Programming Technology Lab 50May 2001
QSOUL: ongoing research
Ongoing research @ PROG & SSELOriginal SOUL & TyRuBa functionality almost
finished. ‘down’ of SOUL values in Smalltalk?Reworking of quasiquoted termsBrowsers built on top of QSOUL to
Use ‘computed classifications’to browse code[ Koen De Hondt: Classification Browser]
Use ‘computed classifications’to generate code[ ECOOP 2000 Classification WS]
© Programming Technology Lab 51May 2001
QSOUL:the repository inspector
© Programming Technology Lab 52May 2001
Overview
Declarative Meta Programming Logic meta programming Applications of DMP SOUL TyRuBa QSOUL SOUL for Java Conclusion
© Programming Technology Lab 53May 2001
SOUL for Java
Can SOUL/DMP be applied to Java?Represent Java classes as logic factsFocus on class files
Java grammar is complicatedSource code is not always availableClass files have a more uniform
representationClass-file format is more stable over time
© Programming Technology Lab 54May 2001
SOUL for Java:class file representation
© Programming Technology Lab 55May 2001
Classes to Clauses: C2C
Written in JavaExtracts information from class filesRepresents this information as logic factsBased on existing class parser: BCEL
Byte Code Engineering Library (formerly JavaClass)
Tested on Drawlets
© Programming Technology Lab 56May 2001
SOUL for Java:representation in C2C
class(<className>). interface(<className>). accessFlag(<className>, <accessFlag>). superclass(<className>, <superClassName>). directInterface(<className>, <interface>). fieldAccessFlag(<className>, <fieldName>, <flag>). fieldDescriptor(<className>, <fieldName>, <returnType>).
© Programming Technology Lab 57May 2001
SOUL for Java:representation in C2C
methodAccessFlag(<className>,<methodName>, <argList>,<accessFlag>).
methodReturnType(…, <returnType>). methodBody(…, <invokesUsedModifiedsList>)
invokespecial(<invocation>) putfield(<fieldName>) putstatic(<fieldName>) getfield(<fieldName>) getstatic(<fieldName>)
© Programming Technology Lab 58May 2001
C2C: example (input file)
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);
} …}
© Programming Technology Lab 59May 2001
C2C example (output file)
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(…).
© Programming Technology Lab 60May 2001
Overview
Declarative Meta Programming Logic meta programming Applications of DMP SOUL TyRuBa QSOUL SOUL for Java Conclusion
© Programming Technology Lab 61May 2001
Conclusion (of Part 1)
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, QSOUL, ...
We use DMP as a technique to build state-of-the art software development tools
http://prog.vub.ac.be © Programming Technology Lab 62
Part 2Declarative Meta Programming …
… for checking architectural conformance
© Programming Technology Lab 63May 2001
Software architectures
describe the overall structure of a software system, abstracting away from its implementation details
provide a simple mental picture that allows software engineers to grasp the global structure
facilitate the understanding of software systems improve maintainability, adaptability, reusability,
… … if they are up to date
© Programming Technology Lab 64May 2001
Architectural drift
Architectural erosion and drift implementation tends to drift away from the original
architecturechanges are often made only at implementation level
Solutionarchitecture is more than documentationarchitectural constraints should explicitly constrain
the implementationneed to ensure conformance of the implementation to
these architectural constraints
© Programming Technology Lab 65May 2001
Conformance checking
How to keep architecture and implementation synchronised?
Architectural conformance checkingexplicit description of the software architecturebi-directional conformance mapping between
architecture and implementationautomated support for checking conformance of a
software implementation to its architecture(s)support for solving problems in case of conformance
breaches
© Programming Technology Lab 66May 2001
Declarative meta programming
use declarative meta programming to express and enforce architectural constraintsuse logic expressions at meta-level to:
explicitly describe the software architecturedeclare its mapping to the implementation
implement conformance checking algorithm as a logic program
© Programming Technology Lab 67May 2001
Case study: SOUL
SOUL “Smalltalk Open Unification Language” Prolog-like logic language that can reason about Smalltalk code
SOUL implementation entirely in Smalltalk contains about 100 classes fairly well designed (coding conventions, design patterns) class hierarchy resembles SOUL abstract syntax tree
3 architectural views ‘rule-based interpreter’ ‘user interaction’ ‘application architecture’
© Programming Technology Lab 68May 2001
SOUL implementation
Clause
CachedRule
BasicClause
RuleClauses Query
Fact
AbstractTerm
TermGeneratePredicate
TrueTerm
SmalltalkTerm
NamedTerm
Terms
Terms:
Clauses:
...
...
© Programming Technology Lab 69May 2001
UsesData1
UsesData2
Asks2
Asks1
Updates1
ClauseSelector
KnowledgeBase
RuleInterpreter
WorkingMemory
UsesData1
UsesData2
Asks2
Asks1
Updates1
ClauseSelector
KnowledgeBase
RuleInterpreter
WorkingMemory
Architecture:‘rule-based interpreter’
view(ruleBasedInterpreter).…concept(ruleBasedInterpreter,'Rule Interpreter').relation(ruleBasedInterpreter,'Updates_1').…port(ruleBasedInterpreter,'Rule Interpreter', 'interpret').role(ruleBasedInterpreter,’Asks_1','interrogator').…link(ruleBasedInterpreter,'Rule Interpreter','unify', 'Asks_1','interrogator').link(ruleBasedInterpreter, 'Clause Selector’, 'matching clauses’,'Asks_1','interrogated’).…
© Programming Technology Lab 70May 2001
Conformance mappingU
ses
Dat
a 1
Use
sD
ata 2
Ask
s 2
Ask
s 1
Upd
ates
1
Cla
use
Sel
ecto
r
Kno
wle
dge
Bas
e
Rul
eIn
terp
rete
r
Wor
king
Mem
ory
Architecture ImplementationConformancemapping
SOULClause
SOULCachedRule
SOULBasicClause
SOULQuerySOULClauses SOULRule
SOULFact
SOULAbstractTerm
SOULTermSOULGeneratePredicate SOULTrueTerm
SOULSmalltalkConstantTermSOULNamedTerm SOULTerms
SOULAndTerms SOULOrTermsSOULAdvancedSmalltalkTerm SOULCachedSmalltalkTerm
© Programming Technology Lab 71May 2001
Conformance mappingU
ses
Dat
a 1
Use
sD
ata 2
Ask
s 2
Ask
s 1
Upd
ates
1
Cla
use
Sel
ecto
r
Kno
wle
dge
Bas
e
Rul
eIn
terp
rete
r
Wor
king
Mem
ory
Architecture ImplementationSOULClause
SOULCachedRule
SOULBasicClause
SOULQuerySOULClauses SOULRule
SOULFact
SOULAbstractTerm
SOULTermSOULGeneratePredicate SOULTrueTerm
SOULSmalltalkConstantTermSOULNamedTerm SOULTerms
SOULAndTerms SOULOrTermsSOULAdvancedSmalltalkTerm SOULCachedSmalltalkTerm
qzfdxgf
qzfdxgf qzfdxgf
qzfdxgf
qzfdxgf qzfdxgf
qzfdxgf
qzfdxgf qzfdxgf
Conformancemapping
© Programming Technology Lab 72May 2001
“Cross-cutting” mappingsU
ses
Dat
a 1
Use
sD
ata 2
Ask
s 2
Ask
s 1
Upd
ates
1
Cla
use
Sel
ecto
r
Kno
wle
dge
Bas
e
Rul
eIn
terp
rete
r
Wor
king
Mem
ory
Architecture ImplementationSOULClause
SOULCachedRule
SOULBasicClause
SOULQuerySOULClauses SOULRule
SOULFact
SOULAbstractTerm
SOULTermSOULGeneratePredicate SOULTrueTerm
SOULSmalltalkConstantTermSOULNamedTerm SOULTerms
SOULAndTerms SOULOrTermsSOULAdvancedSmalltalkTerm SOULCachedSmalltalkTerm
qzfdxgf
qzfdxgf qzfdxgf
qzfdxgf
qzfdxgf qzfdxgf
qzfdxgf
qzfdxgf qzfdxgf
Conformancemapping
© Programming Technology Lab 73May 2001
Software classificationsU
ses
Dat
a 1
Use
sD
ata 2
Ask
s 2
Ask
s 1
Upd
ates
1
Cla
use
Sel
ecto
r
Kno
wle
dge
Bas
e
Rul
eIn
terp
rete
r
Wor
king
Mem
ory
Architecture ArchitecturalAbstraction
ImplementationSOULClause
SOULCachedRule
SOULBasicClause
SOULQuerySOULClauses SOULRule
SOULFact
SOULAbstractTerm
SOULTermSOULGeneratePredicate SOULTrueTerm
SOULSmalltalkConstantTermSOULNamedTerm SOULTerms
SOULAndTerms SOULOrTermsSOULAdvancedSmalltalkTerm SOULCachedSmalltalkTerm
qzfdxgf
qzfdxgf qzfdxgf
qzfdxgf
qzfdxgf qzfdxgf
qzfdxgf
qzfdxgf qzfdxgf
ArchitecturalInstantiation
queryInterpreter
© Programming Technology Lab 74May 2001
Virtual classifications (1)
classifiedAs(method('queryInterpreter’), Method) :- classifiedAs(class('soul'), Class), interpretingProtocolName(ProtocolName), protocolName(Protocol, ProtocolName), methodInProtocol(Class, Protocol, Method).
classifiedAs(method('queryInterpreter’), Method) :- classifiedAs(class('soul'), Class), interpretingProtocolName(ProtocolName), protocolName(Protocol, ProtocolName), methodInProtocol(Class, Protocol, Method).
Use
sD
ata 1
Use
sD
ata 2
Ask
s 2
Ask
s 1
Upd
ates
1
Cla
use
Sel
ecto
r
Kno
wle
dge
Bas
e
Rul
eIn
terp
rete
r
Wor
king
Mem
ory
Architecture ArchitecturalAbstraction
ImplementationSOULClause
SOULCachedRule
SOULBasicClause
SOULQuerySOULClauses SOULRule
SOULFact
SOULAbstractTerm
SOULTermSOULGeneratePredicate SOULTrueTerm
SOULSmalltalkConstantTermSOULNamedTerm SOULTerms
SOULAndTerms SOULOrTermsSOULAdvancedSmalltalkTerm SOULCachedSmalltalkTerm
qzfdxgf
qzfdxgf qzfdxgf
qzfdxgf
qzfdxgf qzfdxgf
qzfdxgf
qzfdxgf qzfdxgf
ArchitecturalInstantiation
© Programming Technology Lab 75May 2001
Virtual classifications (2)
classifiedAs(method('queryInterpreter'),Artef):-classifiedAs(zclass('soul'), Class),interpretingProtocolName(ProtocolName),protocolName(Protocol, ProtocolName),methodInProtocol(Class, Protocol, Artef).
interpretingProtocolName('interpreting').interpretingProtocolName('interpretation').…
Generated or checked artefactGenerated or checked artefactPredicate for checking classified artefacts Predicate for checking classified artefacts or generating a collection of artefactsor generating a collection of artefacts
RuleInterpreter
queryInterpreter
© Programming Technology Lab 76May 2001
Virtual classifications (3)
“intentional”describe how to “compute” their elements
described as logic predicates over implementationexpressive, readable and concise
can be used in multiple waysGenerating: which artifacts belong to classification?Checking: does artifact belong to this classification?
© Programming Technology Lab 77May 2001
Virtual dependencies (1)
asks_M_M(M1, M2) :- isAskedBy_M_M(M2, M1).isAskedBy_M_M(M2, M1) :- classImplementsMethodNamed(C1, M1N, M1), className(C1, C1N), methodName(M2, M2N), …
asks_M_M(M1, M2) :- isAskedBy_M_M(M2, M1).isAskedBy_M_M(M2, M1) :- classImplementsMethodNamed(C1, M1N, M1), className(C1, C1N), methodName(M2, M2N), …
Use
sD
ata 1
Use
sD
ata 2
Ask
s 2
Ask
s 1
Upd
ates
1
Cla
use
Sel
ecto
r
Kno
wle
dge
Bas
e
Rul
eIn
terp
rete
r
Wor
king
Mem
ory
Architecture ArchitecturalAbstraction
ImplementationSOULClause
SOULCachedRule
SOULBasicClause
SOULQuerySOULClauses SOULRule
SOULFact
SOULAbstractTerm
SOULTermSOULGeneratePredicate SOULTrueTerm
SOULSmalltalkConstantTermSOULNamedTerm SOULTerms
SOULAndTerms SOULOrTermsSOULAdvancedSmalltalkTerm SOULCachedSmalltalkTerm
qzfdxgf
qzfdxgf
qzfdxgf
qzfdxgf
ArchitecturalInstantiation
© Programming Technology Lab 78May 2001
Virtual dependencies (2)
asks_M_M(M1, M2) :- isAskedBy_M_M(M2, M1). isAskedBy_M_M(M2, M1) :- classImplementsMethodNamed(C1, M1Name, M1), className(C1, C1Name), methodName(M2, M2Name), isSentTo(C1Name, M1Name, Rcvr, M2Name, Args), mayHaveType_E_M_C(Rcvr, M1, RcvrClass), classImplementsMethod(RcvrClass, M2), isUsedBy_E_M(send(Rcvr, M2Name, Args), M1).
Asks1
asks_M_M(M1, M2) :- isAskedBy_M_M(M2, M1).
© Programming Technology Lab 79May 2001
Virtual dependencies (3)
declare high-level relationships among implementation artifacts “derived” from primitive implementation dependencies e.g., transitive closures, complex interactions, …
described as logic predicates over implementation Expressive, concise, readable, intentional
can be used in multiple ways Checking: does relationship hold between artifacts? Generating: find all artifacts that satisfy relationship Browsing/searching: find artifacts related to a given one.
© Programming Technology Lab 80May 2001
Conformance mapping: summary
ImplementationSOULClause
SOULCachedRule
SOULBasicClause
SOULQuerySOULClauses SOULRule
SOULFact
SOULAbstractTerm
SOULTermSOULGeneratePredicate SOULTrueTerm
SOULSmalltalkConstantTermSOULNamedTerm SOULTerms
SOULAndTerms SOULOrTermsSOULAdvancedSmalltalkTerm SOULCachedSmalltalkTerm
qzfdxgf
qzfdxgf qzfdxgf
qzfdxgf
qzfdxgf qzfdxgf
qzfdxgf
qzfdxgf qzfdxgf
qzfdxgf
Conformance mappingA
sks
2
Ask
s 1
Cla
use
Sel
ecto
r
Kn
owle
dge
Bas
e
Ru
leIn
terp
rete
r
Wor
kin
gM
emor
y
ArchitectureU
pd
ates
1
Use
sD
ata 1
Use
sD
ata 2
ArchitecturalInstantiation
Virtual classification
ImplementationAbstraction
Virtual dependency
Filter
Argument
Quantifier
© Programming Technology Lab 81May 2001
Conformance checkingU
ses
Dat
a 1
Use
sD
ata 2
Ask
s 2
Ask
s 1
Upd
ates
1
Cla
use
Sel
ecto
r
Kno
wle
dge
Bas
e
Rul
eIn
terp
rete
r
Wor
king
Mem
ory
Architecture ArchitecturalAbstraction
ImplementationSOULClause
SOULCachedRule
SOULBasicClause
SOULQuerySOULClauses SOULRule
SOULFact
SOULAbstractTerm
SOULTermSOULGeneratePredicate SOULTrueTerm
SOULSmalltalkConstantTermSOULNamedTerm SOULTerms
SOULAndTerms SOULOrTermsSOULAdvancedSmalltalkTerm SOULCachedSmalltalkTerm
qzfdxgf
qzfdxgf qzfdxgf
qzfdxgf
qzfdxgf qzfdxgf
qzfdxgf
qzfdxgf qzfdxgf
ArchitecturalInstantiation
queryInterpreter
ruleSelection
asks_M_M(M1, M2)
© Programming Technology Lab 82May 2001
Conformance checking algorithm
exists(filteredIsClassifiedAs(queryInterpreter, methodFilter,X1), exists(filteredIsClassifiedAs(ruleSelection, methodFilter,X2), asks_M_M(X1,X2)))
queryInterpreter ruleSelection
exists exists
asks_M_M
RuleInterpreter
ClauseSelector
rrAsks1
methodFilter methodFilter
1 2
© Programming Technology Lab 83May 2001
Conclusion: strengths
Conformance mapping isvery expressive
full expressive power of LMP intentional
virtual classifications and dependenciesconcise and intuitive
declarative nature of LMPwell-chosen implementation abstractions:
virtual classifications, filters and set qualifiers virtual dependencies
© Programming Technology Lab 84May 2001
Conclusion: weaknesses
Conformance mappinglacks efficiencyis defined manually
requires experiencecan be abusedmay contain bugs
Partial solutionpredefined library of mapping predicatesoptimizations, e.g. caching techniques