3. Scope
● Complex Textual Modeling Languages
○ CS is textual (particularly, defined by a grammar)
○ AS is model-based (particularly, defined by a meta-model)
○ Complex Language = AS definition can not be directly inferred from CS definition
● Examples
○ Languages specified by OMG, such as OCL and QVT languages.
○ OCL specification defines the CS via a grammar (Clause 9.3)
○ OCL specification defines the AS via a meta-model (Clause 8)
○ OCL specification describes how to obtain AS from CS (Clause 9.4)
3
5. Problem
● Related works (e.g. Xtext) allow to map CS grammars to AS meta-models, but...
● let … in x.y -- an OCL expression
○ ‘y’ is a navigation (i.e. a PropertyCallExp in the AS)
○ ‘x’ ? → It depends on the context
y:
Property
CallExp
x:
VariableExp
ownedSource
x:
Property
CallExp
self:
VariableExp
y:
Property
CallExp
ownedSource ownedSource
‘x’ is a
variable name
‘x’ is a
property name
(i.e self.x.y)
5
6. Problem II
CallExpCS:
PrimaryExpCS ( ('.' | '->') NameExpCS)*
NameExpCS:
SimpleNameCS (RoundedBracketClauseCS)?
SimpleNameCS:
ID;
RoundedBracketClauseCS:
'(' (ExpCS (',' ExpCS)* )? ')'
OCLExpression
Operation
CallExp
Variable
Exp
Property
CallExp
Problem: Syntactically, it can not be determined if a simple name corresponds
to a PropertyCallExp or VariableExp
6
7. Problem III
● Support to non-simple (i.e. 1-1) CS2AS mappings
○ e.g. a NameExpCS may map to a VariableExp and PropertyCallExp (output pattern)
● Support to cross-references computation
○ e.g. an OCLExpression is a TypedElement: it requires a type cross-reference to be computed
● Name resolution
○ Special case of cross-reference computation
○ e.g. a VariableExp requires to refer to a Variable.
● CS Disambiguation
○ e.g. a NameExpCS may map to either an OperationCallExp, or a PropertyCallExp, or a
VariableExp
7
10. Solution II
● (External) DSTL to bridge CS and AS (meta-models).
● Why is domain-specific
○ Just one input domain and one output domain (no in-place tx)
○ Specific constructs for name resolution
○ Specific guards semantics for disambiguation rules
● Features:
○ Declarative (M2M) language
○ Resuses Essential OCL as expressions language
○ Currently, four sections
■ helpers
■ mappings
■ disambiguation rules
■ name resolution
10
11. DSTL: Helpers
● To define contextual operations
helpers {
NameExpCS::parentAsCallExpCS() : CallExpCS =
let container = self.oclContainer()
in if container.oclIsKindOf(CallExpCS)
then container.oclAsType(CallExpCS)
else null
endif
NameExpCS::isNameExpOfACallExpCS() : Boolean =
let parentCallExpCS = parentAsCallExpCS()
in parentCallExpCS <> null and parentCallExpCS.nameExp = self }
body
result
context
11
12. DSTL: Mappings
● To define mappings between CS and AS (meta-)classes
mappings {
map PropertyCallExp from NameExpCS
when isPropCallExpWithImplicitSource {
ownedSource := let referredVar = trace.lookup(Variable, 'self')
in VariableExp {
referredVariable = referredVar,
type = referredVar.type }
referredProperty := trace.lookupExported(Property,
trace.ownedSource.type, expName),
type := trace.referredProperty?.type}
}
Mapping guard
AS property
initialization
To access AS domain
from the CS one Lookup
expressions
Target AS
term
Source
CS term
12
13. DSTL: Mappings II
● Multi-way mappings (same NameExpCS mapped to different outcomes)
mappings {
map PropertyCallExp from NameExpCS
when isPropCallExpWithImplicitSource { … }
map PropertyCallExp from NameExpCS
when isPropCallExpWithExplicitSource { … }
map OperationCallExp from NameExpCS
when isOpCallExpWithExplicitSource { … }
map OperationCallExp from NameExpCS
when isOpCallExpWithExplicitSource { … }
map VariableExp from NameExpCS
when isVariableExp { … } }
Same source (CS)
Different
targets (AS)
13
14. DSTL: Disambiguation Rules
● To define disambiguation rules
disambiguation {
NameExpCS {
isOpCallExpWithImplicitSource := roundedBrackets <> null
and not isNameExpOfACallExpCS()
isOpCallExpWithExplicitSource := roundedBrackets <> null
and isNameExpOfACallExpCS()
isPropCallExpWithExplicitSource := roundedBrackets = null
and isNameExpOfACallExpCS()
isVariableExp := …
isPropCallExpWithImplicitSource := …
} }
CS element to
disambiguate
Disambiguation rule name
Boolean-valued
expression
Important: Order matters
14
15. Name Resolution
● Activity to solve AS cross-references, which involve a name-based lookup
○ From an AS element another named AS element needs to be found in the model.
○ Declaratively, it’s matter of how named elements are contributed to lookup scopes.
○ Scopes are key data structures that keep all visible named element within that scope.
● Scopes:
○ Current Scope
○ Exported Scope
○ Nested Scopes
15
16. Name Resolution II
● Current Scope
class C1 {
prop p1 : String;
op getP1(): String = p1;
}
:
Expression
InOCL
:
Property
CallExp
class C2 {
op getP1() : String = p1;
}
:
Expression
InOCL
:
Property
CallExp
C1:
Class
p1:
Property
getP1:
Operation
referredProperty
C2:
Class
getP1:
Operation
referredProperty
16
17. Name Resolution III
● Exported Scope
class C1 {
prop p1 : String;
op getP1(): String
= p1;
}
class C2 {
prop c1 : C1;
op getP1() : String
= c1.p1;
}
:
Expression
InOCL
:
Property
CallExp
:
Expression
InOCL
:
Property
CallExp
C1:
Class
p1:
Property
getP1:
Operation
referredProperty
getP1:
Operation
referredProperty
:
Property
CallExp
referredProperty
C2:
Class
c1:
Property
17
18. Name Resolution IV
● Nested Scope (name oclusssion)
-- valid expression which
-- evaluates to false
let v = ‘foo’
in let v = ‘bar’
in v = ‘foo’
‘foo’:
String
LiteralExp
:
LetExp
:
LetExp
v:
Variable
v:
Variable
‘bar’:
String
LiteralExp
‘foo’:
String
LiteralExp
‘=’:
Operation
CallExp
:
Variable
Exp
‘v’ ->
Variable (‘foo’)
‘v’ ->
Variable (‘bar’)parent
nested
18
19. DSTL: Name Resolution
● To define name resolution
targets {
NamedElement using name; -- ’name’: property used to identify ’targets’
Property; -- ’using’ is optional: extends a fully defined ’target’ element }
inputs {
SimpleNameCS using name; -- ’name’: property used to match ’targets’ }
providers {
Class {
in current-scope provides
occluding ownedProperties;
in exported-scope provides
ownedProperties; } } 19
20. DSTL: Name Resolution II
● Slightly more complex name resolution
providers {
Class {
in current-scope provides
occluding ownedProperties
occluding getAllSuperClasses().ownedProperties;
in exported-scope provides
ownedProperties
occluding getAllSuperClasses().ownedProperties;
}
}
20
21. DSTL: Name Resolution III
● Expressions to perform name-based lookups
trace.lookup(Variable, 'self')
Kind of target to look up
trace.lookupExported(Property,trace.ownedSource.type, expName)
The lookup input (a String)Lookup in current scope
Lookup in a exported scope
Kind of target to look up
Actual element providing the
exported scope
The lookup input (a SimpleNameCS)
21
23. Comparative Study: Gra2Mol
● Gra2Mol
○ DSTL can be used for the same purpose: bridging CS and AS syntax
○ Map arbitrary grammars to arbitrary AS meta-models
Source Target Nature Query
Language
Gra2Mol Grammar
Terms
AS MM
Terms
Declarative Structure-Shy
(Xpath Like)
CS2AS
DSTL
CS MM
Terms
AS MM
Terms
Declarative Statically Typed
(Essent. OCL)
23
24. Qualitative Study
● Gra2Mol pros:
○ Query Language is more concise (few and effort-saving navigation operators)
○ Provides a language extensibility mechanism
● CS2AS DSTL pros:
○ OCL has more expressive power (beyond simple model navigation)
○ AS model can be navigated (Gra2Mol QL only operates at CS level)
○ No coupling with a parsing technology
○ Declarative name resolution section saves encoding lookup algorithms
■ to resolve name-based cross-references
○ Ordering-based disambiguation rules description
■ to overcome their admitted limitation of having to define exclusive rule guards.
24