Presentation is loading. Please wait.

Presentation is loading. Please wait.

2000 Advanced OOSA State of the Art on Software Architecture Declarative Meta Programming Session 3: Declarative Meta Programming.

Similar presentations


Presentation on theme: "2000 Advanced OOSA State of the Art on Software Architecture Declarative Meta Programming Session 3: Declarative Meta Programming."— Presentation transcript:

1 kimmens@vub.ac.be1December 2000 Advanced OOSA State of the Art on Software Architecture Declarative Meta Programming Session 3: Declarative Meta Programming Nantes, EMOOSE 2000–2001 Dr. Kim Mens, PROG, VUB

2 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 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

3 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 3 References n 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 n 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 n 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 RECAP

4 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 4 Session overview n Declarative Meta Programming n Logic meta programming n Applications of DMP n SOUL n TyRuBa n DMP for Java n Conclusion DMP = Declarative Meta Programming

5 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 5 Session overview n Declarative Meta Programming n Logic meta programming n Applications of DMP n SOUL n TyRuBa n DMP for Java n Conclusion

6 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 6 Declarative Meta Programming n DMP = Declarative Meta Programming n Combines a declarative meta language with a standard object-oriented base language n Explicit symbiosis between meta and base language u base-level programs are expressed as terms, facts and rules at the meta level u meta-level programs can manipulate and reason about the base-level programs

7 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 7 Declarative reasoning n Declarative programming language u readable, intuitive, intentional, concise u e.g. a logic programming language n Declarative reasoning u use a declarative programming language to reason about structural aspects of source code in some base language u check source against certain constructs, conventions, patterns u search source for certain constructs, conventions, patterns u extract certain constructs, conventions, patterns from source u enforce certain constructs, conventions, patterns in source u generate source from high-level declarative descriptions u transform source based on high-level declarative descriptions

8 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 8 Session overview n Declarative Meta Programming n Logic meta programming n Applications of DMP n SOUL n TyRuBa n DMP for Java n Conclusion

9 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 9 Logic meta programming (LMP) n LMP = Logic Meta Programming n LMP as particular flavour of DMP n Meta language is a PROLOG-like logic programming language n Logic programming is good at u meta programming u language processing u reasoning about knowledge u unification, backtracking, multi-way reasoning

10 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 10 LMP — Multi-way reasoning n Explain append example here

11 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 11 LMP languages for Smalltalk n SOUL u “Smalltalk Open Unification Language” u Prolog-like meta language u Smalltalk (or Squeak) as base language u 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 n Prolog + Prodata u Prolog as meta language u Store base-level source code in ODBC-compliant repository u Access repository from Prolog using some ODBC interface u Weaker symbiosis but more efficient reasoning engine

12 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 12 LMP languages for Java n TyRuBa u Java as base language u Prolog-like meta language u Generates Java source code from logic descriptions containing parameterised Java expressions n DMP for Java (C2C) u Java as base language u Prolog as meta language u Prolog facts representing the base-level program are generated from the Java class files for that program

13 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 13 Session overview n Declarative Meta Programming n Logic meta programming n Applications of DMP n SOUL n TyRuBa n DMP for Java n Conclusion

14 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 14 Applications of DMP n What is DMP used for at PROG? u Emerging technique to build state-of-the art software development tools u 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 u To build advanced software architecture tools n DMP is unifying approach that combines the research of many PROG researchers n Focus of this course: u DMP for building advanced software architecture tools

15 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 15 Some DMP experiments n Roel Wuyts: SOUL u Reasoning about the structure of OO systems using the Smalltalk Open Unification Language u Synchronizing implementation and design n Kim Mens: architectural conformance checking u use logic programs to declare software architectures declaratively and check them against the implementation n Tom Tourwé: code optimization & change propagation u 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

16 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 16 More DMP experiments n Kris De Volder: TyRuBa u very expressive type system u precompiler that uses logic programs to generate (Java) code n Aspect-Oriented Programming (AOP) u Kris De Volder: using TyRuBa for AOP u Maja D'Hondt: expressing domain knowledge as a separate aspect that can be factored out from the base program u Johan Brichau: declarative combination of aspects n Wolfgang De Meuter & Maja D’Hondt u Using DMP techniques for guiding reuse

17 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 17 Advanced software architecture tools n There is a need for advanced tools that support an architecture-driven software development process: n Navigating u “architecture-driven browsing” through the source-code n Conformance checking u of source code to architectural descriptions n Enforcing u architectural constraints over the source code n Generating u source-code (fragments) from architecture descriptions n...

18 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 18 Advanced software architecture tools n... n Extracting u architectural information from source code n Transforming & reverse-engineering u source code based on architectural information n Co-evolution u keep source code and architecture synchronised when one of the evolves u change propagation, impact analysis, conflict detection, … n Etc.

19 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 19 Session overview n Declarative Meta Programming n Logic meta programming n Applications of DMP n SOUL n TyRuBa n DMP for Java n Conclusion

20 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 20 SOUL n Set-up n Integration with Smalltalk n SOUL environment n Prolog variant n Declarative framework

21 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 21 SOUL set-up Experiments were conducted in two alternative set-ups: u SOUL u Prolog Reason about and manipulate source code: check, extract, search, generate, enforce, transform Smalltalk implementation artefacts Meta-level Interface SOULSmalltalk Image

22 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 22 SOUL n Set-up n Integration with Smalltalk n SOUL environment n Prolog variant n Declarative framework

23 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 23 SOUL is integrated with Smalltalk VisualWorks Smalltalk environment SOUL menu (opens SOUL applications)

24 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 24 SOUL is embedded in Smalltalk Actual SOUL code can be inspected Smalltalk class browser Logic repositories are stored as special “classes” “Methods” group set of related logic clauses

25 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 25 SOUL language Rule class(?class) if constant(?class), [ SOULExplicitMLI curent isClass: ?class ]. n Logic programming language, featuring symbiosis and reflection with Smalltalk n Specific language features: u Smalltalk term: “wrap” extended Smalltalk code u Generate predicate: transform collection of x Smalltalk elements into x logic solutions u Quoted term: represent strings with logic variables

26 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 26 n Up-down mechanism: n Reflection: u 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 curent isClass: (env at: 1) soulUp ]

27 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 27 SOUL n Set-up n Integration with Smalltalk n SOUL environment n Prolog variant n Declarative framework

28 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 28 The SOUL Repository Inspector Construct and execute queries Inspect logic facts and rules Browse and edit (hierarchic) repository structure

29 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 29 Browse and edit repository structure

30 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 30 Inspecting the logic repository all clauses with a given name SOUL implementation of the selected clause select name of the clause

31 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 31 The SOUL Query and Structural Find applications SOUL Query Application SOUL Structural Find Application

32 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 32 The SOUL Query Application query editor status field find all query results find only first query result

33 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 33 The Query Result Inspector

34 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 34 The SOUL Structural Find Application

35 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 35 SOUL n Set-up n Integration with Smalltalk n SOUL environment n Prolog variant n Declarative framework

36 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 36 Prolog variant Experiments were conducted in two alternative set-ups: u SOUL u Prolog Smalltalk implementation artefacts ODBC Interface PrologMS Access Database Reason about and manipulate source code: check, extract, search, generate, enforce, transform

37 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 37 SOUL n Set-up n Integration with Smalltalk n SOUL environment n Prolog variant n Declarative framework

38 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 38 A layered declarative framework Architectural Layer Design Patterns Layer Coding Conventions Layer Base Layer Representational Layer Repository- access Layer isClassifiedAs findMetaClassedFromClasses findMethodsFromClasses factoryMethodcompositePattern instanceCreationMethod isSentTohierarchy traverseMethodParseTree artefactartefactNestingID protocolNamemethodName classImplementsMethodNamed classImplementsMethod metaClassmethodInProtocol inheritanceclassName

39 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 39 Session overview n Declarative Meta Programming n Logic meta programming n Applications of DMP n SOUL n TyRuBa n DMP for Java n Conclusion

40 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 40 TyRuBa (Typed Rule Base) n Java Code Generation through DMP n Ph.D. Thesis of Kris De Volder, 1999 n Allows to write generic templates of software modules by means of DMP n Code generator instantiates these templates n Generic templates are represented by logic declarations (facts & rules)

41 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 41 TyRuBa Architecture

42 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 42 TyRuBa class( Array, { private ?El[] contents; /** Construction */ Array (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

43 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 43 TyRuBa n Code generator can do much more reasoning u E.g.: generate an implementation of a Container (e.g. Array) based on the element it should contain. u... n Code generator itself is implemented in TyRuBa u Adaptable and extensible

44 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 44 Session overview n Declarative Meta Programming n Logic meta programming n Applications of DMP n SOUL n TyRuBa n DMP for Java n Conclusion

45 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 45 DMP for Java n Can DMP be applied to Java? n Represent Java classes as logic facts n Focus on class files u Java grammar is complicated u Source code is not always available u Class files have a more uniform representation u Class-file format is more stable over time

46 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 46 Java class representation

47 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 47 Classes to clauses: C2C n Written in Java n Extracts information from class files n Represents this information as logic facts n Based on existing class parser: BCEL u Byte Code Engineering Library u (formerly JavaClass) n Tested on Drawlets

48 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 48 Used representation (1) n class( ). n interface( ). n accessFlag(, ). n superclass(, ). n directInterface(, ).

49 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 49 Used representation (2) n fieldAccessFlag(,, ). n fieldDescriptor(,, ).

50 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 50 Used representation (3) n methodAccessFlag(,,, ). n methodReturnType(…, ). n methodBody(…, ) u invokespecial( ) u putfield( ) u putstatic( ) u getfield( ) u getstatic( )

51 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 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); } … }

52 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 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(…).

53 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 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)’)]).

54 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 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)’).

55 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 55 Session overview n Declarative Meta Programming n Logic meta programming n Applications of DMP n SOUL n TyRuBa n DMP for Java n Conclusion

56 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 56 Conclusion n DMP = use a declarative meta language to reason about & manipulate programs written in a standard object-oriented base language n DMP is unifying approach that combines the research of many PROG researchers n Several DMP tools and environments already exist: u SOUL, TyRuBa, C2C,... n We use DMP as a technique to build state-of-the art software development tools n In particular, in this course we will focus on the use of DMP for building advanced software architecture tools

57 State of the Art on Software Architecture — Declarative Meta ProgrammingSession 3, page 57 Session overview n Declarative Meta Programming n Logic meta programming n Applications of DMP n SOUL n TyRuBa n DMP for Java n Conclusion Time for a break


Download ppt "2000 Advanced OOSA State of the Art on Software Architecture Declarative Meta Programming Session 3: Declarative Meta Programming."

Similar presentations


Ads by Google