CSG 7111 Structure and Interpretation of an Aspect Language for Datatype Karl Lieberherr.

Slides:



Advertisements
Similar presentations
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) SSA Guo, Yao.
Advertisements

Introducing Formal Methods, Module 1, Version 1.1, Oct., Formal Specification and Analytical Verification L 5.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
February R. McFadyen1 Polymorphism Indirection Pure Fabrication Protected Variations (Law of Demeter) More GRASP Patterns.
Oct R McFadyen1 Recall UML Class Diagram BusRoute BusStopList BusStop BusList BusPersonList Person passengers buses busStops waiting 0..*
INTERPRETER Main Topics What is an Interpreter. Why should we learn about them.
3/7/2003Bioinformatics1 How To Address Rapidly Changing Data Representations in an Evolving Scientific Domain Using Aspect-oriented Programming Techniques.
March R. McFadyen1 Principle of Least Knowledge – page 265 Principle: talk only to your immediate friends Also called Law of Demeter (LoD)
Midterm Fall 2000 solutions. Question 1 From sentence to class dictionary abstraction In this case like from object graph to class graph abstraction because.
1 Introduction to Software Engineering Lecture 42 – Communication Skills.
Cse321, Programming Languages and Compilers 1 6/19/2015 Lecture #18, March 14, 2007 Syntax directed translations, Meanings of programs, Rules for writing.
Oct 21, R. McFadyen1 Pure Fabrication P Problem: You have a responsibility to assign to a class, but assigning it to a class in the conceptual.
Validating Streaming XML Documents Luc Segoufin & Victor Vianu Presented by Harel Paz.
CSE 373, Copyright S. Tanimoto, 2002 Up-trees - 1 Up-Trees Review of the UNION-FIND ADT Straight implementation with Up-Trees Path compression Worst-case.
UML class diagrams and XML schemas Karl Lieberherr UBS AG Northeastern University.
3/7/2003Bioinformatics1 How To Address Rapidly Changing Data Representations in an Evolving Scientific Domain Using Aspect-oriented Programming Techniques.
Cost-based Optimization of Graph Queries Silke Trißl Humboldt-Universität zu Berlin Knowledge Management in Bioinformatics IDAR 2007.
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
程建群 博士(Dr. Jason Cheng) 年03月
Catalysis/Testing Catalysis Objects, components, and Frameworks with UML.
Integrating Independent Components with On-Demand Remodularization based on OOPSLA 2002 paper by Mira Mezini Klaus Ostermann Prepared by Karl Lieberherr.
Pattern Language for AP1 Pattern Language for Adaptive Programming (AP) Karl Lieberherr Northeastern University.
Expression evaluation E : S | C. S = int. C = Op E E. Op : A | M. A = “+”. M = “*”.
3/7/2003 ABB rapid change 1 How To Address Rapidly Changing Data Representations in an Evolving Scientific Domain Using Aspect-oriented Programming Techniques.
Slides for Gregor Kiczales Two versions –short version: Crosscutting capabilities for Java and AspectJ through DJ (4 viewgraphs only) –long version: Controlling.
CS 363 Comparative Programming Languages Semantics.
RRXS Redundancy reducing XML storage in relations O. MERT ERKUŞ A. ONUR DOĞUÇ
Not only mark-up languages! There are other many other grammar formalisms and tools than XML. Some of them standardized (ASN). Even XML does not always.
John J. Sung TA Consulting. Motivation for TraversalJ KL Enterprises identified AOP Enter into the AOP market early Add value by adding traversals to.
Midterm CSG 110 Karl Lieberherr. Managing Software Development Managers of software development must first be software developers.
Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.
Catalysis/Testing Catalysis Objects, components, and Frameworks with UML.
Pattern Language for AP1 Pattern Language for Adaptive Programming (AP) Karl Lieberherr Northeastern University.
3.2 Semantics. 2 Semantics Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Demeter Aspects We study techniques for the emerging area of Aspect-Oriented Software Development and focus on the following areas:  Aspectual Collaborations.
Translating Traversals to AspectJ. Outline Motivation Demeter Process for Traversals AspectJ Translation Process.
ModTransf A Simple Model to Model Transformation Engine Cédric Dumoulin.
DJ: traversal-visitor-style programming in Java Josh Marshall/ Doug Orleans Want to add more on traversal through collections and Aspectual Components.
Problem with Java and how it causes a problem for DJ.
AOP/cross-cutting What is an aspect?. An aspect is a modular unit that cross-cuts other modular units. What means cross-cutting? Apply AOP to AOP. Tease.
Interpreters and Higher-Order Functions CSE 413 Autumn 2008 Credit: CSE341 notes by Dan Grossman.
Pattern Language for AP1 Pattern Language for Adaptive Programming (AP) Karl Lieberherr Northeastern University.
R-customizers Goal: define relation between graph and its customizers, study domains of adaptive programs, merging of interface class graphs.
AO Mechanisms in Demeter1 Discussion with Gregor Kiczales at UBC Ontology of AOP Ontology is the study of what there is, an inventory of what exists. An.
Jesse proposal1 Jesse’s proposal Karl Lieberherr.
Pattern Language for AP1 Pattern Language for Adaptive Programming (AP) Karl Lieberherr Northeastern University.
Features of AOP languages AOP languages have the following main elements: –a join point model (JPM) wrt base PL –a specification language for expressing.
Advanced Computer Systems
Viewgraphs for Semantics
Crosscutting Capabilities for Java and AspectJ through DJ
Pattern Language for Adaptive Programming (AP)
A Simple Syntax-Directed Translator
Structure and Interpretation of an Aspect Language for Datatype
Adaptive Object-Oriented Software Development
Software Design and Development
ADAPTIVE PROGRAMMING Sezen ERDEM December 2005.
Review lecture AOO/Demeter.
The Metacircular Evaluator
Midterm Review CSU 670 Spring 2004.
AP/DJ AP: a generic technology
Lecture 21: Crosscutting Aspect-Oriented Programming Background
Better Separation of Crosscutting Concerns with Aspectual Components
AOSD and the Law of Demeter: Shyness in Programming
Ideas for testing Transformations of cds 4/27/2019 AOO/Demeter.
Objects, components, and Frameworks with UML
Karl Lieberherr Doug Orleans
Inductively Defined Data Concrete and Abstract syntax
Presentation transcript:

CSG 7111 Structure and Interpretation of an Aspect Language for Datatype Karl Lieberherr

CSG Lectures The motivation and theory behind “Aspect Language for Datatype”. –datatypes and class graphs –Semantics (// A B) (navig-object graphs.*) –Visitors and type checking Interpreter implementation

CSG 7113 Motivation Build on foundations that Matthias presented. Connections to templates: stressing the importance of structural recursion. Not only an interpreter but also a compiler (works, because traversals are sufficiently simple). Very useful application of foundations that is in itself a foundation. Demonstration that simple languages can be full of surprises.

CSG 7114 Homework Simple aspect-oriented language. Leads to a radically different way of programming: programming without knowing details of data structures. Write programs for a family of related data structures. Northeastern SAIC project ca

CSG 7115 Homework evolution Initial motivation: make EOPL datatype style programming easier by adding a traverse function. Visitors written in full Scheme: AdaptiveScheme = Scheme + EOPL datatype + traversal strategies + visitors. You get a simplified form (thanks Matthias).

CSG 7116 Interpretation Interpret a traversal on an object tree. (join (//A B) (//B C)): starting at an A-node, traverse entire object tree, return C-nodes that are contained in B-nodes that are in turn contained in A-nodes. Not interesting enough. Can meta information about object trees make it more interesting?

CSG 7117 Interpretation with meta information Use a graph to express meta information. Many applications: –data type / data trees –class graph / object trees –schema / documents (XML) –programs / execution trees

CSG 7118 Class graphs (simplified UML class diagrams) nodes and edges nodes: concrete and abstract edges: has-a (triples) and is-a (pairs) concrete nodes: no incoming is-a supports inheritance flat: a class graph is flat if no abstract node has an outgoing has-a edge

CSG 7119 Example B2 A R B X S D 0..1 C T A//T//D a1:A r1:R s1:S c1:C d1:D class graph strategy t1:T r2:R c2:C d2:D s2:S object graph

CSG Plan (M s cg og) = ? –(M1(M2 s cg) og) = ? –og satisfies cg! Not only traverse! (Mv s cg og V) –(Mv1 (M1 (M2 s cg) og) V) –visitor V: before / after applications to node / edge. Local storage. Visitor functions are activated by traversal.

CSG Sample visitor (visitor PersonCountVisitor 0 // initial value PersonCountVisitor // return before (host Person) (+ PersonCountVisitor 1) )

CSG Example (Mv s cg og PersonCountVisitor) cg : class graph for bus routes og: object graph for bus routes s = (join (// BusRoute BusStop) (// BusStop Person)) count all persons waiting at any bus stop on a bus route

CSG Class Graph BusRoute BusStopList BusStop BusList BusPersonList Person passengers buses busStops waiting 0..* count all persons waiting at any bus stop on a bus route

CSG Object Graph Route1:BusRoute :BusStopList busStops CentralSquare:BusStop :PersonList waiting Daniel:PersonViera:Person BusList buses Bus15:Bus :PersonList passengers Christine:Person Bryan:Person s = (join (// BusRoute BusStop) (// BusStop Person)) (Mv s cg og PersonCountVisitor) = ?? c=0 c++

CSG Robustness BusRoute BusStopList BusStop BusList BusPersonList Person passengers busses busStops waiting 0..* s = BusRoute // BusStop // Person VillageList Village villages 0..* count all persons waiting at any bus stop on a bus route c=0 c++

CSG Aspects Aspects as program enhancers Here we enhance traversal programs with before and after advice defined in aspects called visitors General AOP enhances any kind of program This is a special case with good software engineering properties

CSG Develop a sequence of semantics (M s cg og) = ? –og satisfies cg! s, cg, og: are graphs. Graphs are relations. Use terminology of relations. Restrict to s = (// A B).

CSG Object level semantics (M s cg og), where s = (// A B). The key is to find a set FIRST(A,B) of edges such that e in FIRST(A, B) iff it is possible for an object of class A to reach an object of type B by a path beginning with an edge e. (M s cg og) is the FIRST(A,B) sets.

CSG Homework class graphs A CG is: (DD+) A DD is: (datatype TypeName Alternative+) An Alternative is: (AlternativeName (FieldName TypeName)+) HW class graph to class graph transformation: TypeName -- abstract class AlternativeName – concrete class (AlternativeName, FieldName, TypeName) – has-a (AlternativeName, TypeName) – is-a

CSG Homework class graphs CD = PL(DD). DD = "(datatype" TypeName L(Alternative) ")". Alternative = "(" AlternativeName L(TypedField) ")". TypedField = "(" FieldName TypeName ")". FieldName = Ident. TypeName = Ident. AlternativeName = Ident. L(S) ~ {S}. PL(S) ~ "(" {S} ")".

CSG Class graph example (datatype Container (a_Container (contents ItemList) (capacity Number) (total_weight Number))) (datatype Item (Cont (c Container)) (Simple (name String) (weight Weight))) (datatype Weight (a_Weight (v Number))) (datatype ItemList (Empty) (NonEmpty (first Item) (rest ItemList)))) HW class graph to class graph transformation: TypeName -- abstract class AlternativeName – concrete class (AlternativeName, FieldName, TypeName) – has-a (AlternativeName, TypeName) – is-a traversal strategy: (// a_Container a_Weight)

CSG As traditional class graph Container aContainer ItemListNumber contents capacity total_weight Empty NonEmpty Item Cont Simple c String Weight nameweight v first rest

CSG Another class graph example (datatype P (CP (q Q))) (datatype Q (CQ (p P))) Because we only allow trees for object graphs, we should disallow such class graphs? P and Q are useless.

CSG F CBA D G E H F CBA G E H Class graphs object-equivalent inheritance

CSG object-equivalent inheritance Class graphs F CBA G E H F CBA G E H

CSG inheritance Class graphs F CBA G E H H F A1 aH E G aE B1C1 aG Preview: (// aH aE) (// aH aG) (// aH Hid_A)

CSG inheritance Evolution F CBA G E H H F Hid_A aH E G aE Hid_BHid_C aG B aB not evolution-friendly

CSG inheritance Class graphs F CBA G E H H F A1 aH E G aE B1C1 aG Preview: (// aH aE) (// aH aG) (// aH Hid_A) CB A aA aBaC now evolution-friendly

CSG inheritance Class graphs F CBA G E H H F A1 aH E G aE B1C1 aG Preview: (// aH aE) (// aH aG) (// aH Hid_A) CB A aA aBaC

CSG inheritance Class graphs F CBA G E H H F A1 aH E G aE B1C1 aG Preview: (// aH aE) (// aH aG) (// aH Hid_A) CB A aA aBaC E1

CSG inheritance Class graphs F CBA G E H (datatype H (aH (f F) (b B) )) (datatype G (aG)) (datatype A (aA (e E) (g G))) (datatype B (aB (e E) (g G))) (datatype C (aC (g G))) (datatype E (aE)) (datatype F (A1 (a A)) (B1 (b B)) (C1 (c C)) (E1 (e E)) ) H = F B. G =. A = E G. B = E G. C = G. E =. F : A | B | C | E.

CSG Separate Viewgraphs Difference between homework class graphs and class graphs. No inheritance in homework class graphs. Flat class graphs can easily be modeled by home work class graph. A class graph is flat if abstract classes have no outgoing has-a edges. Quadratic growth in size.

CSG Apply class graph knowledge to homework class graphs Only consider flat class graph (flattening is an object preserving transformation). In flat class graph the rules are simpler. HW class graph to class graph transformation: TypeName -- abstract class AlternativeName – concrete class (AlternativeName, FieldName, TypeName) – has-a (AlternativeName, enclosing TypeName) – is-a

CSG Meaning of strategies and visitors (// A B) (only this in hw) –A:AlternativeName B:AlternativeName –starts at A-object and ends at B-object (// A B) –A:TypeName B:TypeName –starts at an AlternativeName-object of A –ends at an AlternativeName-object of B

CSG From Semantics to Interpreter From object-level semantics to class-level semantics (M1(M2 s cg) og) –M2: FIRST sets at class level SWITCH to navig-object-graphs

CSG From Interpreter to Compiler Connect to Structural Recursion Consider the strategy (// A *) (everything reachable from A) (M1(M2 s cg) og): we want M1 to be apply M2 must return a function that we apply to og Primitives: functions with one argument: the data traversed, no other arguments.

CSG Code generation: should produce something useful (define-datatype BusRoute BusRoute? (a-BusRoute (name symbol?) (buses (list-of Bus?)) (towns (list-of Town?))))

CSG Style 1: display (define (trav br) (cases BusRoute br (a-BusRoute (name buses towns) (list name (trav-buses buses) (trav-towns towns))))) (define (trav-buses lob) (map trav-bus lob))

CSG Style 2: copy (define (cp br) (cases BusRoute br (a-BusRoute (name buses towns) (apply a-BusRoute (list name (cp-buses buses) (cp-towns towns)))))) (define (cp-buses lob) (map cp-bus lob))

CSG Summary phase 1 Language: strategies: A // B, class graphs, object graphs Semantics: FIRST: there exists object Interpreter: FIRST: there exists path in class graph Compiler: generated code is equivalent to a subgraph of class graph

CSG Visitors

CSG Visitors Several kinds: –Think of strategy as making a list out of an og. Fold on that list. (cg og s) -> list of target objects of s. (gather cg og s). (// CContainer CWeight) (+ (+ … (+ w2 (+ w1 0)) … ) –Think of visitor as having a suit case of variables in which they store data from their trip. Available as argument. –functions for nodes and edges. –multiple visitors.

CSG Type checking of hw programs check: Program =(Strategy x Visitor). (Program x ClassGraph) -> Bool Fundamental question: Given a program, with respect to which class graphs is it type correct. –Type checking: Given a class graph, is the program type correct? –Typability: Does there exist a class graph such that the program is type correct?

CSG Reference Class-graph Inference for Adaptive Programs, Jdens Palsberg, TAPOS 3 (2), 75-85, 1997.

CSG fix 27 semantics: go everywhere and collect ogs. then apply visitors general strats: exponentially many paths