Institute for Programming and Reactive Systems TU Braunschweig, Germany 2nd International Workshop on Equation-Based Object-Oriented Languages and Tools at ECOOP 2008, July 8, Paphos, Cyprus A Static Aspect Language for Modelica Models Malte Lochau (lochau@ips.cs.tu-bs.de) Henning Günther (h.guenther@tu-bs.de) EOOLT 2008 July 8, 2008
Contents • Introduction • Modelica and Quality Requirements • Principles of Aspect Orientation • Static Aspect Language • Rule Syntax • Evaluation Semantics • Variables and Type System • Implementation Framework • Conclusion EOOLT 2008 July 8, 2008 1
Contents Introduction Static Aspect Language Implementation Conclusion • Introduction • Modelica and Quality Requirements • Principles of Aspect Orientation • Static Aspect Language • Rule Syntax • Evaluation Semantics • Variables and Type System • Implementation Framework • Conclusion EOOLT 2008 July 8, 2008 2
Modelica Description Standard Introduction Static Aspect Language Implementation Conclusion • Modelica • Multi-discipline mathematical modeling and simulation of complex physical systems • Object-oriented • Equation-based (declarative) • … • Modelica 3: „balanced models“ concept • Restrictions / design rules for increased model quality • E.g. balanced connector property: „… the number of flow variables in a connector must be identical to the number of non-causal non-flow variables …“ EOOLT 2008 July 8, 2008 3
Quality Requirements for Modelica Models Introduction Static Aspect Language Implementation Conclusion • Generalizing: Quality Requirements • Modeling restrictions, design rules, conventions, policies, … • Domain specific, non-functional, … „… flow variables shall be named with a _flow postfix …“ „… inheritance hierarchies deeper than 4 are to be avoided …“ � Exceed expressiveness of Modelica language capabilites partial model OnePort ������� ... � Requirements superpose end OnePort; or crosscut model model Resistor extends OnePort �������� ... components and end Resistor; hierarchies model ResistorTh extends Resistor ���������� ... end ResistorTh; EOOLT 2008 July 8, 2008 4
Maintaining Quality Requirements Introduction Static Aspect Language Implementation Conclusion � Objectives: • Formalism for concise specification and automated evaluation of quality requirements • Querying Modelica models, matching point(s) meeting certain criteria • Rule checking by negation: <forbidden property> => <error message> • Model manipulation / transformation • Modelica specific approach • … EOOLT 2008 July 8, 2008 5
Applying Aspect Orientation to Modelica Introduction Static Aspect Language Implementation Conclusion • Aspect Orientation [Kizcales et. al]: „Modularization and integration of crosscutting concerns in existing systems“ „… is Obliviousness and Quantification“ „… applied to procedural-like programming languages “ • Aspect Orientation for EOO languages? • dynamic vs. static aspects � Structural properties of Modelica models are largely stated at compile-time � Static Aspects for Modelica models: „ In a model M, wherever condition C arises, perform action A“ EOOLT 2008 July 8, 2008 6
Aspects Terminology Introduction Static Aspect Language Implementation Conclusion • Aspects: Encapsulation of crosscutting concerns <Pointcut> => <Advice>; pointcut expression flow(class) and not ‘*_flow‘ • Pointcut : Expression matching specific elements (joinpoints) matching joinpoints model Pin connector FluidPort of a model ... ... • Joinpoints : Model entities flow Current i; flow MassFlowRate m; considered in an aspect ... ... end Pin; end FluidPort; • Advice : Action(s) to be applied applying advice to joinpoints to joinpoints model Pin connector FluidPort � Weaving : „Injecting“ advices of ... ... flow Current i_flow; flow MassFlowRate m_flow; an aspect to the original model ... ... end Pin; end FluidPort ; EOOLT 2008 July 8, 2008 7
Contents Introduction Static Aspect Language Implementation Conclusion • Introduction • Modelica and Quality Requirements • Principles of Aspect Orientation • Static Aspect Language • Rule Syntax • Evaluation Semantics • Variables and Type System • Implementation Framework • Conclusion EOOLT 2008 July 8, 2008 8
Syntactic Structure of Static Aspects Introduction Static Aspect Language Implementation Conclusion <Pointcut> => <Advice>; • Pointcut language: • Expression terms matching joinpoints • Primitives: predicates, relations (Modelica-specific) • Operators for term compositions (crosscutting entities) • Advice language: • Actions applied to each joinpoint matching the pointcut • E.g. high-level programming language code EOOLT 2008 July 8, 2008 9
Syntax of the Pointcut Language Introduction Static Aspect Language Implementation Conclusion � Expressions applied to the set of all relevant joinpoints in a model � Step-wise refinements by unary predicates, binary relations, and operators p ::= u operators u ::= <id> unary | b(p) | ‘<pattern>‘ p and p | b ::= <id> binary p or p b + | | not p b + <n> | | exists b : p p product p | | forall b : p p product-d p | | p equals p | p: pointcut expression p subset p | u: unary pointcut expression p less p | b: binary pointcut relation <relop> n b n: natural number | relop: on of <,<=, =, !=, >, >= … id: identifier pattern: name pattern expression EOOLT 2008 July 8, 2008 10
Primitives of the Pointcut Language Introduction Static Aspect Language Implementation Conclusion • Predefined Modelica primitives matching subsets / pairs of Modelica entities • Unary primitives: High-level structural entities for model organization, i.e. Class types • class, model, connector, block, … • partialType, finalType, localType, … • Binary relations: Inspecting properties of model elements • Class type members • member(p), publicMember(p), replMember(p), … • flow(p), parameter(p), modifier(p), … • Class type inheritance • derivedType(p), baseType(p), subType(p), … • Class type behavior • equation(p), connectEquation(p), unknown(p), … • … EOOLT 2008 July 8, 2008 11
Pointcut Operators Introduction Static Aspect Language Implementation Conclusion • C rosscutting model entities: Correlation / combination of pointcut expressions • Operators working on joinpoint sets • Logical combination of joinpoint sets and, or, not, less, … • Naming pattern for accessing elements by their names ‘*_flow‘ • Cardinalities: Number of joinpoints matching pointcuts <relop> n b • Quantification: Conditions on a range of values forall, exists, … • Transitive closure of binary relations derivedType + EOOLT 2008 July 8, 2008 12
Examples: Pointcut Expression Introduction Static Aspect Language Implementation Conclusion • Are there partial types that are never derived? partialType and not baseType(class) • Are there package declarations with less than 5 members? package and ( < 5 componentMember ) • Are there blocks only having output members? forall primitiveMember : output(block) EOOLT 2008 July 8, 2008 13
Semantics of the Pointcut Language Introduction Static Aspect Language Implementation Conclusion P : J M → P (J M ) • Evaluation of pointcuts: • Pointcut expression P • Modelica model specification M • Set of all joinpoints J M present in M • Element-wise reasoning of joinpoint sets by considering the stated conditions of P • Evaluation preceeds from inwards to outwards • Stepwise refinement of the resulting joinpoint set via unary and binary pointcut evaluation EOOLT 2008 July 8, 2008 14
Evaluation Rules Introduction Static Aspect Language Implementation Conclusion P � p � = U � u � U : unary pointcut → P (J m ) operators unary P � b(p) �� = { j 1 | (j 1 , j 2 ) ∈ B � b � , j ∈ ∈ P � p �� } U �� id � = { j | j ∈ J M matching id } U � ’pattern’ � = { j | j ∈ J M matching ’pattern’} … P � p 1 and p 2 � = P � p 1 � � P � p 2 � P � p 1 or p 2 � = P � p 1 � ∪ P � p 2 �� binary B : binary relation → P (J M × J M ) P � not p 1 � = { j | j ∉ P � p 1 � } B �� id � = { (j 1 , j 2 ) | j 1 , j 2 ∈ J M related pair w.r.t. id} P � p 1 less p 2 � = P � p 1 � \ P � p 2 � … P � forall b : p � = { j 2 | ∀ (j 1 , j 2 ) ∈ B � b � : j 1 ∈ P � p � } P � exists b : p � = { j 2 | ∃ (j 1 , j 2 ) ∈ B � b � : j 1 ∈ P � p � } P � p 1 product p 2 � = { (j 1 , j 2 ) ∈ P � p 1 � × P � p 2 � } … P � b + � = { (j 1 , j 2 ) | ∃ (j 1 , j 2 ), …, (j k-1 , j k ) ∈ B � b � } EOOLT 2008 July 8, 2008 15
Recommend
More recommend