Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 00e24832cfc12dad1a9b110834db4c3fd936c883 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
source cs : 'generated/MiniOCLCS.ecore#/'
target as : '/resource/org.eclipse.qvtd.doc.miniocl/model/MiniOCL.ecore#/'

helpers {
  as::Class {
    commonSupertype(another : Class) : Class :=
      let allSupertypes = self->asOrderedSet()->closure(superClasses),
          allOtherSupertypes = another->asOrderedSet()->closure(superClasses)
      in allSupertypes->intersection(allOtherSupertypes)->any(true);
    conformsTo(another : Class) : Boolean :=
        self = another or 
        superClasses->exists(conformsTo(another));
  }
  
  cs::NavigationExpCS {
  	parentAsCallExpCS() : CallExpCS :=
      let container = self.oclContainer()
      in if container.oclIsKindOf(CallExpCS)
         then container.oclAsType(CallExpCS)
         else null
         endif;
  }
  cs::NameExpCS {
    isNavExpOfACallExpCS() : Boolean :=
      let parentCallExpCS = parentAsCallExpCS()
      in parentCallExpCS <> null and parentCallExpCS.navExp = self;
  }  
  cs::PropertyCS {
  	computeLowerBound() : Integer :=
  	  if multiplicity = null then 0
  	  else if multiplicity.opt then 0
  	       else if multiplicity.mult then 0
  	       else if multiplicity.mandatory <> 0 then multiplicity.mandatory
  	       else multiplicity.lowerInt
  	       endif endif endif 
  	  endif;
  	computeUpperBound() : Integer :=
  	  if multiplicity = null then 1
  		else if multiplicity.opt then 1
  		     else if multiplicity.mult then -1
  		     else if multiplicity.mandatory <> 0 then multiplicity.mandatory
  		     else if multiplicity.upperMult then -1
  		     else multiplicity.upperInt
  		     endif endif endif endif
  		endif;
  }
}

disambiguation {
  CollectionLiteralPartCS   {
    withoutLastExpression := last = null;
    withLastExpression := last <> null;
  }
  
  NameExpCS { -- Note: order of the disambiguation rules matters
    isOpCallExpWithExplicitSource := 
      roundedBrackets <> null and isNavExpOfACallExpCS();
    isOpCallExpWithImplicitSource :=
      roundedBrackets <> null and not isNavExpOfACallExpCS();
    isPropCallExpWithExplicitSource := 
      roundedBrackets = null and isNavExpOfACallExpCS();
    isVariableExp := 
      roundedBrackets = null and not isNavExpOfACallExpCS()
      and lookup(Variable, expName.pathElements->first()) <> null;
    isPropCallExpWithImplicitSource :=
      roundedBrackets = null and not isNavExpOfACallExpCS()
      and lookup(Property, expName) <> null;
   }
   
  LetExpCS {
    singleVarDecl := letVars->size() = 1;
    multipleVarDecls := letVars->size() > 1;
  }
}
mappings {
  create Root from RootCS {
     ownedImports := imports.trace;
     ownedPackages := packages.trace;
     ownedConstraints := constraints.invariants.trace;
  }
  create Import from ImportCS {
  	alias := if alias = null then null else alias endif;
  	uri := uri;
  }
  create Constraint from InvariantCS {
     ownedSpecification := as::ExpressionInOCL {
               language = 'OCL',
               ownedBody = exp.trace,
               ownedSelfVar =  as::Variable { name = 'self', 
                                             type = trace.constrainedElement }
               };
     constrainedElement := lookup(Class, self.ConstraintsDefCS.typeRef);
  }
  create Package from PackageCS {
    name := name;
    ownedPackages := packages.trace;
    ownedClasses  := classes.trace;
  }
  create Class from ClassCS {
    name := name;
    ownedProperties := properties.trace;    
    ownedOperations := operations.trace;
    superClasses := if _extends ->notEmpty() 
                    then _extends->collect(x | lookup(Class,x))
                    else OrderedSet{}
                    endif;
  }
  create Operation from OperationCS {
    name := name;
    type := lookup(Class, resultRef);
    ownedParameters := params.trace;    
    ownedBodyExpression := as::ExpressionInOCL {
          language = 'OCL',
          ownedBody = body.trace,
          ownedSelfVar = as::Variable {name = 'self' , type = trace.owningClass }
    };
  }
  
  create Variable from ParameterCS {
    name := name;
    type := lookup(Class,typeRef);	
  }
  
  create Property from PropertyCS {
    name := name;  	
    lowerBound := computeLowerBound();
    upperBound := computeUpperBound();
    type := lookup(Class, typeRef);
  }
  -- Expressions
  refer CallExp from CallExpCS :=
    self.navExp.trace;
    
  create OperationCallExp from EqualityExpCS {
     ownedSource := left.trace;
     ownedArguments := right.trace;
     referredOperation := lookupExported(Operation, trace.ownedSource.type,
                                         opName, trace.ownedArguments);
     type := lookup(Class, 'Boolean');
  }
  create VariableExp from NameExpCS
  when fall_back {
      referredVariable := null;
      type := lookup(Class, 'OclVoid');
  } 
  create VariableExp from NameExpCS
  when isVariableExp {
    referredVariable := lookup(Variable, expName.pathElements->first());
    type := trace.referredVariable.type;
  }  
  create PropertyCallExp from NameExpCS
  when isPropCallExpWithExplicitSource {
    ownedSource := parentAsCallExpCS()._source.trace;
    referredProperty := lookupExported(Property,trace.ownedSource.type,expName);
    type := trace.referredProperty?.type;
  }  
  create PropertyCallExp from NameExpCS
  when isPropCallExpWithImplicitSource {
    ownedSource := let referredVar = lookup(Variable, 'self')
                   in as::VariableExp {
                        referredVariable = referredVar, 
                        type = referredVar.type
                   };
    referredProperty := lookupExported(Property,trace.ownedSource.type,expName);
    type := trace.referredProperty?.type;
  }
  create OperationCallExp from NameExpCS
  when isOpCallExpWithExplicitSource {
    ownedSource := parentAsCallExpCS()._source.trace;
    ownedArguments := roundedBrackets.args.trace;
    referredOperation := lookupExported(Operation,trace.ownedSource.type,
                                       expName, trace.ownedArguments);
    type := trace.referredOperation?.type;
  }  
  create OperationCallExp from NameExpCS
  when isOpCallExpWithImplicitSource {
    ownedSource := let referredVar = lookup(Variable, 'self')
                   in as::VariableExp {
                        referredVariable = referredVar,
                        type = referredVar.type
                   };
    ownedArguments := roundedBrackets.args.trace;
    referredOperation:= lookupExported(Operation,trace.ownedSource.type,
                                       expName, trace.ownedArguments);
    type := trace.referredOperation?.type;
  }
  
  create LetExp from LetExpCS 
  when singleVarDecl {
    ownedVariable := letVars->at(1).trace;
    ownedIn  := inExp.trace;
    type := inExp.trace.type;
  }
  create LetExp from LetExpCS
  when multipleVarDecls  {
    ownedVariable := letVars->first().trace;
    ownedIn  := letVars->excluding(letVars->first())->reverse()
                       ->iterate(x : LetVarCS; acc : as::OCLExpression = inExp.trace |
                                     as::LetExp {
                                       ownedVariable = x.trace,
                                       ownedIn = acc,
                                       type = acc.type
                                     });
    type := inExp.trace.type;
  }
  create Variable from LetVarCS  {
  	name := name;
  	ownedInitExp := initExp.trace;
    type := if typeRef <> null then lookup(Class,typeRef) else trace.ownedInitExp.type endif;
  }
  
  create IterateExp from IterateExpCS {
    ownedIterator := itVar.trace;
    ownedResult := accVar.trace;
    ownedBody := exp.trace;
    ownedSource := parentAsCallExpCS()._source.trace;
    type := trace.ownedResult.type;
  }
  
  create IteratorExp from CollectExpCS {
    iterator := 'collect';
    ownedIterator := if itVar = null
                     then as::Variable { name='self', type=lookup(Class,'OclAny') }
                     else itVar.trace
                     endif;
    ownedBody := exp.trace;
    ownedSource := parentAsCallExpCS()._source.trace;
    type := lookup(Class,'Collection');
  }
  create Variable from IteratorVarCS  {
  	name := itName;  	
    type := if itType <> null then lookup(Class,itType) else lookup(Class,'OclAny') endif;
  }
  create Variable from AccVarCS  {
  	name := accName;
  	ownedInitExp := accInitExp.trace;
    type := if accType <> null then lookup(Class,accType) else trace.ownedInitExp.type endif;
  }
  create CollectionLiteralExp from CollectionLiteralExpCS {
    kind := kind;
    ownedParts := parts.trace;
    type := lookup(Class,'Collection');
  }
  create CollectionItem from CollectionLiteralPartCS  
  when withoutLastExpression {
    ownedItem := first.trace;
    type := trace.ownedItem.type;
  }
  create CollectionRange from CollectionLiteralPartCS 
  when withLastExpression {
     ownedFirst := first.trace;
     ownedLast := last.trace;
     type := trace.ownedFirst.type;
  }
}

name_resolution {
	targets {
		NamedElement using name scaped_with '_';
		Package qualifies Package using ownedPackages,
					   Class using ownedClasses;
		Class qualifies Operation using ownedOperations,
					   Property using ownedProperties;
		Operation filtered_by arguments : OrderedSet(OCLExpression)
					when ownedParameters->size() = arguments->size() and
						arguments->forAll(x | 
							let argIdx = arguments->indexOf(x)
							in x.type.conformsTo(ownedParameters->at(argIdx).type));
		Property;
		Variable;
	}
	inputs {
		PathElementCS using elementName;
		qualifier PathNameCS using pathElements;
	}
	providers {
		Root {
			in current_scope provides adding
				Package using ownedPackages, exported ownedImports;
		}
		
		Import {
			in exported_scope provides
				Package using loaded Package from uri;
		}
		Package {	
			in current_scope provides occluding 
				Package using ownedPackages
				Class using ownedClasses;
		}
		
		Class {
			vars allSuperClasses = self->closure(superClasses);
			
			in current_scope provides occluding
				Operation using ownedOperations occluding allSuperClasses.ownedOperations
				Property using ownedProperties occluding allSuperClasses.ownedProperties;
				
			in exported_scope provides
				Operation using ownedOperations occluding allSuperClasses.ownedOperations
				Property using ownedProperties occluding allSuperClasses.ownedOperations;
		}
		
		Operation {	
			in current_scope provides occluding
				Variable using ownedParameters;
		}
		
		ExpressionInOCL {
			in current_scope provides occluding
				Variable using ownedSelfVar;
		}
		
		LetExp {
			in current_scope 
			 for all excepting ownedVariable
			    provides occluding Variable using  ownedVariable;
		}
	}
}

Back to the top