Class Diagrams with Constraints Philippe Nguyen McGill University COMP-762 Winter 2005.

Slides:



Advertisements
Similar presentations
Optional Static Typing Guido van Rossum (with Paul Prescod, Greg Stein, and the types-SIG)
Advertisements

Language Specification using Metamodelling Joachim Fischer Humboldt University Berlin LAB Workshop Geneva
Type Checking, Inference, & Elaboration CS153: Compilers Greg Morrisett.
Semantics Static semantics Dynamic semantics attribute grammars
Python Mini-Course University of Oklahoma Department of Psychology Lesson 28 Classes and Methods 6/17/09 Python Mini-Course: Lesson 28 1.
Budapest University of Technology and EconomicsDagstuhl 2004 Department of Measurement and Information Systems 1 Towards Automated Formal Verification.
Page 1 Automatic Evaluation of Modelling Rules and Design Guidelines, July 2006 Automatic Evaluation of Modelling Rules and Design Guidelines Tibor Farkas,
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der.
9/27/2006Prof. Hilfinger, Lecture 141 Syntax-Directed Translation Lecture 14 (adapted from slides by R. Bodik)
30 March 2005, IPA lentedagen, BredaGraph-Based State Spaces1 Graph Transformation for Model Transformation Arend Rensink University of Twente.
Institute For Software Integrated Systems Vanderbilt University Applications of Model Integrated Computing to The Synchronous Language Signal Ethan Jackson.
Cse321, Programming Languages and Compilers 1 6/19/2015 Lecture #18, March 14, 2007 Syntax directed translations, Meanings of programs, Rules for writing.
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
1 Control Flow Analysis Mooly Sagiv Tel Aviv University Textbook Chapter 3
What is UML? A modeling language standardized by the OMG (Object Management Group), and widely used in OO analysis and design A modeling language is a.
Chapter 2 A Simple Compiler
CPSC Compiler Tutorial 3 Parser. Parsing The syntax of most programming languages can be specified by a Context-free Grammar (CGF) Parsing: Given.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
8/19/2015© Hal Perkins & UW CSEC-1 CSE P 501 – Compilers Parsing & Context-Free Grammars Hal Perkins Winter 2008.
CIS Computer Programming Logic
Supporting Automatic Model Inconsistency Fixing Yingfei Xiong University of Tokyo, Japan Zhenjiang HuNational Institute of Informatics, Japan Haiyan ZhaoPeking.
Introduction to Python
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
AToM 3 : A Tool for Multi- Formalism and Meta-Modelling Juan de Lara (1,2) Hans Vangheluwe (2) (1) ETS Informática Universidad Autónoma de Madrid Madrid,
Invitation to Computer Science, Java Version, Second Edition.
1 MDWE'2008, Toulouse, France, September 30, 2008 A Comparative Analysis of Transformation Engines for User Interface Development Juan Manuel González.
{ Graphite Grigory Arashkovich, Anuj Khanna, Anirban Gangopadhyay, Michael D’Egidio, Laura Willson.
Building Tools by Model Transformations in Eclipse Oskars Vilitis, Audris Kalnins, Edgars Celms, Elina Kalnina, Agris Sostaks, Janis Barzdins Institute.
Validated Model Transformation Tihamér Levendovszky Budapest University of Technology and Economics Department of Automation and Applied Informatics Applied.
SaveUML System design. System overview Possible...
CS 363 Comparative Programming Languages Semantics.
Looping and Counting Lecture 3 Hartmut Kaiser
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
Chapter 2. Design of a Simple Compiler J. H. Wang Sep. 21, 2015.
Documentation Dr. Andrew Wallace PhD BEng(hons) EurIng
Automata Based Method for Domain Specific Languages Definition Ulyana Tikhonova PhD student at St. Petersburg State Politechnical University, supervised.
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam I Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Chapter 3 Part II Describing Syntax and Semantics.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
The Visitor Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Programmeren 1 6 september 2010 HOORCOLLEGE 2: INTERACTIE EN CONDITIES PROGRAMMEREN 1 6 SEPTEMBER 2009 Software Systems - Programming - Week.
CS412/413 Introduction to Compilers Radu Rugina Lecture 13 : Static Semantics 18 Feb 02.
C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
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.
14 October 2002GGF6 / CGS-WG1 Working with CIM Ellen Stokes
Model-Driven Synthesis of Embedded Robotic Navigation Systems Rachael Dennison Bina Shah
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
® IBM Software Group A Metamodeling Approach to Pattern Specification Maged Elaasar 1,2, Dr. Lionel Briand 1, Dr. Yvan Labiche 1 1 Carleton University,
GME-MOF: The MOF-Based GME Metamodeling Environment Matt Emerson 10/24/2004 Advisor: Dr. Janos Sztipanovits OOPSLA 2004 Domain-Specific Modeling Workshop.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
Programming Languages Meeting 3 September 9/10, 2014.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
XML Schema – XSLT Week 8 Web site:
On Combining Multi-formalism Knowledge to Select Models for Model Transformation Testing Sagar Sen (1 st year PhD student), Benoit Baudry, Jean-Marie Mottu.
Defects of UML Yang Yichuan. For the Presentation Something you know Instead of lots of new stuff. Cases Instead of Concepts. Methodology instead of the.
Sections 4.1 & 4.2 Recursive Definitions,
Propositional Calculus: Boolean Functions and Expressions
Parsing & Context-Free Grammars
Business Process Measures
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Object-Oriented Knowledge Representation
CSC1018F: Intermediate Python
Python Tutorial for C Programmer Boontee Kruatrachue Kritawan Siriboon
COMPILER CONSTRUCTION
Software Architecture & Design
Presentation transcript:

Class Diagrams with Constraints Philippe Nguyen McGill University COMP-762 Winter 2005

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Topics Outline Motivation Solution  Metamodel  Code Generation  Type Checker  Constraint Checker Validation  Order System Example Future Work Conclusion

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Motivation MOF/UML:  Use OCL and natural language to constrain the metamodel Are OCL and natural language constraints included in the metamodel itself? True bootstrapping would assume so…

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Motivation: Current Situation in MOF 2.0 The constraint specification is a ValueSpecification  A ValueSpecification identifies values in a model  Can be an Expression (e.g. a + b = 3)  Can be an OpaqueExpression (e.g. an OCL statement) Where does it go from there?

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Motivation: Goals Define a metamodel for Class Diagrams in which constraints are also metamodeled Be able to check a model instance against a model defined in this “new” formalism Start using pyGK

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Solution: General Approach (1) ClassDiagramWithConstraints Class Diagram Constraint Language references ClassDiagramWithConstraints Modeling Environment AToM 3 Model + Constraints (ASG) produces Re-metamodel Class Diagrams  Including a constraint language Abstract (and concrete) syntax  Inspired by MOF and OCL

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Solution: General Approach (2) ASG2pyGK Model + Constraints (pyGK) model_pyGK.py def model_MDL(): def constraint1(context): def constraint2(context): … model_chkr.py def model_MDL_chkr(): checks type checks constraints generate Model + Constraints (ASG)

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Solution: ClassDiagramsWithConstraints (1) Class Diagram Part

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Solution: ClassDiagramsWithConstraints (2) Constraint Part

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Solution: Overview of pyGK (1) The Python Graph Kernel Developed by Marc Provost An easy to use API for graph representation

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Solution: Overview of pyGK (2) _id: unique identifier _label: “type” PrimitiveTypes:  Int, Float, Bool, String, List  SymbolTable / AttrNode Straightforward functions to:  Construct a graph: add(), connect()  Traverse a graph: BFS, DFS Ref: moncs.cs.mcgill.ca/MSDL/presentations/ MarcProvost.pyGK/presentation.pdf

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Solution: Converting ASG model to pyGK E.g. A +att1: Int B +att2: String C +att3: Float N Class Diagram in pyGK format model = Graph(ID=“model”, label=“ClassDiagram”) A = AttrNode(ID=“A”, label=“Class”) A[“att1”] = Int() B = AttrNode(ID=“B”, label=“Class”) B[“att2”] = String() C = AttrNode(ID=“C”, label=“Class”) C[“att3”] = Float() hasB = AttrNode(ID=“hasB”, label=“Association”) hasB[“srcMultMin”] = Int(value=1) hasB[“trgMultMin”] = Int(value=0) hasB[“trgMultMin”] = String(value=“N”) CInheritsB = AttrNode(ID=“CInheritsB”, label=“Inherit”) // Add and connect nodes in model hasB Class Diagram in ASG format Iterate through the ASGNodes and generate…

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Solution: Converting ASG constraint to pyGK E.g Invariant1 GREATER_EQ PersonAge Zero 0 > 1 > 2 Iterate through the ASGNodes and generate… Constraint expression in ASG format Constraint expression in pyGK fomrat constraints = model(ID=“constraints”, label=“Constraints”) Invariant1 = AttrNode(ID=“Invariant1”, label=“Invariant”) comp1 = AttrNode(ID = "comp1", label = "ComparisonOp") PersonAge = AttrNode(ID="PersonAge", label="AttributeCall") PersonAge["calledAttributeType"] = Int() PersonAge["calledAttributeName"] = String(value="Age") PersonAge["owningClassifier"] = String(value="Person") comp1["operator"] = String(value = "GREATER_EQ") comp1[“argument1”] = PersonAge comp1[“argument2”] = Int(value=0) Invariant1[“bodyExp”] = comp1 Invariant1[“context”] = String(value=“Person”) // Add and connect nodes in constraints Person +Age: Int >

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Solution: Saving to file (1) Define an API for constructing Python code:  A sort of an AST interface for Python  E.g. an Assignment Statement is AssignmentStmt ::= LHS “ = ” RHS LHS ::= LiteralStmt RHS ::= LiteralStmt | OperationStmt Using this API, we can generate code constructs like If statements and function calls Also supports indentation for writing out Python code

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Solution: Saving to file (2) lit1 = LiteralStmt("a") lit2 = LiteralStmt("in") lit3 = LiteralStmt("c") listLit = LiteralStmt("[0, 1, 2, 3]") trueLit = LiteralStmt("True") zeroLit = LiteralStmt("0") imp1 = ImportStmt(LiteralStmt("pack"), LiteralStmt("mod")) def1 = DefStmt(LiteralStmt("foo"), [lit2]) blk1 = BlockStmt([imp1]) blk1.appendReturnCarriage() blk1.appendStmt(def1) ass1 = AssignmentStmt(lit1, lit2) plus1 = NaryOpStmt(LiteralStmt("+"), [lit1, lit2]) ass2 = AssignmentStmt(LHS=lit3, RHS=plus1) eq1 = BinaryOpStmt(LiteralStmt("=="), [lit3, trueLit]) call1 = FunctionCallStmt(context=None, fnName=LiteralStmt("len"), arguments=[listLit]) less1 = BinaryOpStmt(LiteralStmt("<"), [call1, zeroLit]) if1 = IfStmt(eq1, BlockStmt([ReturnStmt(trueLit)]), BlockStmt([ReturnStmt(less1)])) blk2 = BlockStmt([ass1, ass2, if1]) print blk1.toString(0) print blk2.toString(1) Output: from pack import mod def foo(in): a = in c = (a + in) if (c == True): return True else: return (len([0, 1, 2, 3]) < 0)

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Solution: Saving to file (3) Saving the model:  Define a function: def _MDL():  Spit out the pyGK statements that can rebuild the model Saving the constraints:  For each constraint, define a function: def (context):  Turn the pyGK format into Python code using the syntax API

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Solution: Type Checking Checks that a model instance conforms to a model It entails checking  That every instance element corresponds to a meta-element  That every instance element owns only properties that its meta- element can own  That every association in the model is respected

07/04/2005Philippe Nguyen McGill University COMP-762 Winter …every instance element corresponds to a meta-element For every (pyGK) Node in the instance,  Check that the model contains a Node whose id corresponds to the instance Node’s label E.g. In model: In instance: AttrNode(id=“A”, label=“Class”) AttrNode(id=“myA”, label=“A”) A +att1: Int myA : A +att1 = 0

07/04/2005Philippe Nguyen McGill University COMP-762 Winter … every instance element owns only properties that its meta-element can own For each key in an AttrNode of the instance,  Check that the corresponding meta-element, or a super type of the meta-element, has the same key  Check that the values for the corresponding keys have the same type E.g. In model: In instance: A = AttrNode(id=“A”, label=“Class”) myA = AttrNode(id=“myA”, label=“A”) A[“att1”] = Int() myA[“att1”] = Int(value=0) A +att1: Int myA : A +att1 = 0

07/04/2005Philippe Nguyen McGill University COMP-762 Winter …every association in the model is respected (1) Check that their instances attach the correct types, as permitted by the model  For every association, Get the hierarchy of the source and built a list of IDs Do the same for the target Check that every instance connects a source whose label is in the source ID list a target whose label is in the target ID list Complexity: Inheritance

07/04/2005Philippe Nguyen McGill University COMP-762 Winter …every association in the model is respected (2) Check that their instances respect the multiplicities  Build a tuple table of all the instance links  Check: srcMultMin <= # source instances <= srcMultMax trgMultMin <= # target instances <= trgMultMax

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Solution: Constraint Checking In type checking, the checker can be written offline  Applicable to any model For constraint checking, the checker is specific to the model  So, we need to generate something that will check each contraint against every instance of the constraint’s context Call the generated Python function  Don’t forget sub types!

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Validation So does all this work??? Let us see the solution in action Order System Example

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Validation: What do we have now? A constraint language that is included within the Class Diagram metamodel “Static” checking of model instances  A client application of the checker would input a model instance that is considered to be “stable” at that point A concrete application for pyGK

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Validation: Limitations & Future Work What about operations? N-ary associations Visually surcharged models  But the abstract syntax tree will look something like that… Expressiveness of the constraint language  Add more constructs like for loop or select operation Tests on bigger models  Performance issues?

07/04/2005Philippe Nguyen McGill University COMP-762 Winter More Future Work Check multiplicities as constraints  So Type Checker would be a pure structural check Generation of modeling environment  Generate a modeling environment from ClassDiagramWithConstraints but without the constraint language Bootstrapping  Re-metamodel ClassDiagramWithConstraints in itself Defining the constraints in the constraint language itself

07/04/2005Philippe Nguyen McGill University COMP-762 Winter Acknowledgements Special thanks to:  Dr. Hans Vangheluwe  Dr. Juan de Lara for ClassDiagram formalism in AToM 3  Marc Provost for help on pyGK and metamodeling

07/04/2005Philippe Nguyen McGill University COMP-762 Winter References 1.Object Management Group, UML 2.0 Infrastructure Final Adopted Specifcation, Available Online, URL: September Object Management Group, MOF 2.0 Core Final Adopted Specification, Available Online, URL: October 2003http:// 3.Object Management Group, MOF-XMI Final Adopted Specification, Available Online, URL: November 2003http:// 4.Object Management Group, UML 2.0 OCL Specification, Available Online, URL: Octoer 2003http:// 5.C. Kiesner, G. Taentzer, J. Winklemann, Visual OCL: A Visual Notation of Object Constraint Language, Available Online, URL: