29
An OCL-based bridge from concrete to abstract syntax Adolfo Sánchez-Barbudo Herrera, Edward D. Willink and Richard F. Paige

An OCL-based bridge from CS to AS

Embed Size (px)

Citation preview

Page 1: An OCL-based bridge from CS to AS

An OCL-based bridge from concrete to abstract

syntaxAdolfo Sánchez-Barbudo Herrera, Edward D. Willink

and Richard F. Paige

Page 2: An OCL-based bridge from CS to AS

Agenda● Motivation & Problem● Challenges & Proposed Solutions

○ CS2AS Mappings○ Name Resolution○ CS Disambiguation

● On going and future work

2

Page 3: An OCL-based bridge from CS to AS

Motivation: Example● Sequence {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}● Sequence {1, 1+1, 3..9+1}

3

Page 4: An OCL-based bridge from CS to AS

Motivation: CS to ASCollectionLiteralPartCS:

OclExpressionCS | CollectionRangeCS

CollectionRangeCS:OclExpressionCS ’..’ OclExpressionCS

CS2AS

4

Page 5: An OCL-based bridge from CS to AS

Motivation: CS to AS

5

OMG

AS Meta-model

CS Grammar

CSMetamodel

CS2AS Bridge

Page 6: An OCL-based bridge from CS to AS

Motivation: CS to AS in OCL● Attribute grammars

○ Synthesized attributes○ Inherited attributes

● OCL Expressions

6

Page 7: An OCL-based bridge from CS to AS

Motivation: CS to AS in OCL

CollectionRangeCS.ast

Another way of AS mapping description?

.oclAsType(CollectionItem).item

7

Page 8: An OCL-based bridge from CS to AS

Problem: CS to AS in OCL● It’s not really formal● Typos and inconsistencies● It is not checked/validated

○ No tool can understand the semi-formal descriptions● Implementors can’t benefit from automation

We need models to formalize CS2AS 8

Page 9: An OCL-based bridge from CS to AS

Solution: OCL-based DSL● OCL-based internal DSL

○ Complete OCL documents● CS2AS bridge:

○ CS2AS mappings○ Name resolution○ CS Disambiguation

● Existing OCL tools can be used● Implementors can exploit CS2AS bridges

9

Page 10: An OCL-based bridge from CS to AS

Solution: CS2AS mappingscontext CollectionLiteralPartCSdef : ast() : ocl::CollectionLiteralPart =ocl::CollectionItem { item = first.ast(), type = first.ast().type }

10

Page 11: An OCL-based bridge from CS to AS

Solution: CS2AS mappingscontext CollectionRangeCSdef : ast() : ocl::CollectionRange =ocl::CollectionRange { first = first.ast(), last = last.ast(), type = first.ast().type.commonType(last.ast().type) }

11

Page 12: An OCL-based bridge from CS to AS

Challenge: Name Resolutionlet var : String = 'something' in var

Name resolutionbased cross-reference

12

Page 13: An OCL-based bridge from CS to AS

Name Resolution: Roles

Environment(named elements)

Producer

Consumer

Named Elements

Name Named Elements

nestedEnvironment

● Nested Environments (lookup scopes)● Namespaces & qualified names● Name visibility rules 13

Page 14: An OCL-based bridge from CS to AS

Name Resolution:EnvironmentEr = env::Environment{} -- Empty Environment

NE C

NP P

R

Ep= ErEnp = Er

Ene = Ep Ec= Ep including NER Root node

NP Non-producer node

P Producer node

NE Named-element node

C Consumer node 14

Page 15: An OCL-based bridge from CS to AS

Solution: Environment defcontext OclAnydef : env : env::Environment =if oclContainer() <> nullthen oclContainer().childEnv(self)else env::Environment{} -- empty environmentendif

def : childEnv(child : OclAny) : env::Environment =env

NP NP

NP NP

R

15

Page 16: An OCL-based bridge from CS to AS

Solution: Producerscontext LetExpdef : childEnv(child : OclAny) : env::Environment =if child = variablethen -- the owned let variable envelse -- the owned in expression env.nestedEnv().addElement(variable)endif

16

Page 17: An OCL-based bridge from CS to AS

Solution: Consumers context OclAnydef : lookupVariable(varName : String) : Variable =env.namedElements->selectOfKind(Variable)

->select(v | v.name = varName)->first()context VariableExpCSdef : ast () : ocl::VariableExp =let referredVar = ast().lookupVariable(varName)in ocl::VariableExp {

name = varName,referredVariable = referredVar ,type = if referredVar = null then null else referredVar.type endif }

17

Page 18: An OCL-based bridge from CS to AS

Challenge: CS Disambiguationlet … in x.y● y is a PropertyCallExp● x ?

○ VariableExp-if x is a let variable, or operation param○ PropertyCallExp i.e. self.x.y

18

Page 19: An OCL-based bridge from CS to AS

Challenge: CS Disambiguation

“Some of the production rules are syntactically ambiguous. For such productions disambiguating rules have been defined. Using these rules, each production and thus the complete grammar becomes non-ambiguous."

19

Page 20: An OCL-based bridge from CS to AS

Solution: CS DisambiguationNameExpCS:

simpleName isMarkedPre?

● Disambiguation rules:○ should NameExpCS produce a VariableExp○ should NameExpCS produce a PropertyCallExp○ should NameExpCS produce …

● In a CS2AS activity○ Syntactic information from CS meta-model○ Semantic information from AS meta-model 20

Unified NameExpCS

Page 21: An OCL-based bridge from CS to AS

Solution: CS Disambiguationcontext NameExpCSdef : ast() : ocl::OclExpression =if isAVariableExp()then let variable = ast().lookupVariable(name) in ocl::VariableExp { name = name, referredVariable = variable, type = if variable = null then null else variable.type endif }else … endif

21

Page 22: An OCL-based bridge from CS to AS

Solution: CS Disambiguationcontext NameExpCS-- Disambiguation rule from NameExpCS to VariableExpdef : isAVariableExp() : Boolean =let variable = ast().lookupVariable(name)in variable <> null

-- Disambiguation rule from NameExpCS to PropertyCallExpdef : isAPropertyCallExp() : Boolean =let property = ast().lookupProperty(name)in property <> null

22

Page 23: An OCL-based bridge from CS to AS

Ongoing & Future work● Executable CS2AS transformation generation

23

CS ASOCL-based

CS2AS

ASModel

OCL OCL

CS’ AS’

CS Model

M2M tx’

OCL-basedCS2AS’

M2M tx

CS Model’

AS Model’

QVT QVT

Page 24: An OCL-based bridge from CS to AS

High QualityIDE

Ongoing & Future work● Xtext integration

Xtext Grammar CS

OCL-based CS2AS AS

AS-basedOutline

Name Reso-basedContentAssistant 24

Page 25: An OCL-based bridge from CS to AS

Ongoing & Future work● External CS2AS DSL

25

Now OCL-basedInternal DSL

FutureOCL-embeddedExternal DSL

Page 27: An OCL-based bridge from CS to AS

Yet another M2M tx language

27

● Yes, it’s another M2M tx language, but …● It’s a Domain Specific Transformation

Language○ e.g (Name resolution)...

● One input model, one output model○ We don’t need support to more

● Suitable for OMG specifications○ OCL is more widespread than QVT

Page 28: An OCL-based bridge from CS to AS

Just for textual CS

28

● Not researched, but …● As long the CS is represented by an Ecore

metamodel, it sounds feasible:○ Eg: A square is mapped to a concept ‘X’ in the AS

○ Disambiguation rules to disambiguate a CS element (e.g. a blue-coloured square is ‘X’ and a red one is ‘Y’)

Page 29: An OCL-based bridge from CS to AS

● We can’t have a well-designed AS with a concise grammar (unless the language is simple)

● If the language is not simple:○ Either we don’t care about a well designed AS○ or, we don’t care about how big is the grammar*○ or, we have substantial differences between CS & AS.

Why do we need a CS mm ?

29

Language Capabilities

CS Grammar Conciseness

Good AS design