Skip to main content
summaryrefslogtreecommitdiffstats
blob: 52e396ed6c1de493cf16b287b32149ec6b19266a (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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
/*******************************************************************************
 * Copyright (c) 2014 The University of York and Willink Transformations.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Horacio Hoyos - initial implementation
 ******************************************************************************/
import "../helpers/QVTHelpers.eol";
import "../helpers/QVTsHelpers.eol";
//import "Scheduler.eol";
 
/****t* /org.eclipse.qvtd.build.etl/scheduling/QVTpToSchedule
 * NAME
 *  QVTpToSchedule -- Craetes the base schedule from a partitioned (QVTp)
  * transformation
 * FUNCTION
 *  Extract the basic Schedule information from the QVTp trnasformation. The QVTp
 *  trasnformation must conform to QVTi. The basic schedule craetes the Class and
 *  Parameter information but does not reduce the DistinctData information (i.e.
 *  does not perform derivation analysis.
 * SEE ALSO
 *  /org.eclipse.qvtd.build.etl/scheduling/DerivationAnalysis
 *    
 */

/****u* QVTpToSchedule/TransformationToSchedule
 * NAME
 *  TransformationToSchedule - Transform the trnsformation
 * FUNCTION
 *  Just creates the place holder for datums and actions
 * FROM
 *  QVTp!Transformation
 * TO
 *  QVTs!Schedule
 */
rule TransformationToSchedule
    transform t : QVTp!Transformation
    to s : QVTs!Schedule {
        
    }

/****u* QVTpToSchedule/MappingToMappingAction
 * NAME
 *  MappingToMappingAction - A mapping genereates a mapping action and its datums
 * FUNCTION
 *  Visit the mapping input/ouput variables to create the appropriate results and
 *  arguments.
 * FROM
 *  QVTp!Mapping
 * TO
 *  QVTs!MappingAction
 */
 
rule MappingToMappingAction
    transform m : QVTp!Mapping
    to ma : QVTs!MappingAction {
        
        //m.name.println("mapping ");
        ma.schedule ::= m.transformation;
        ma.mapping = m;
        ma.parameters.addAll(m.getInputVariables().equivalent());
        ma.requisites.addAll(m.getInputVariables().collect(v | v.type.equivalent()));
        ma.results.addAll(m.getOutputVariables().equivalent());
        ma.productions.addAll(m.getOutputVariables().collect(v | v.type.equivalent()));
    }


/****u* QVTpToSchedule/VariableToDataParameter
 * NAME
 *  VariableToDataParameter - Variables and RealizedVariables are transformed
 *  into DataParameter.
 * FROM
 *  QVTp!Variable
 * TO
 *  QVTs!DataParameter
 * ANNOTATIONS
 *  lazy        Lazy variables from iterators and not automatically transformed
 *  greedy      Greedy so we also transform RealizedVariables
 */
@lazy
@greedy
rule VariableToDataParameter
    transform v : QVTp!Variable
    to dp : QVTs!DataParameter {
        
        //v.name.println("VariableToDataParameter ");
        dp.variable = v;
        dp.datum ::= v.type;            
    }

/****u* QVTpToSchedule/ClassToClassDatum
 * NAME
 *  ClassToClassDatum - Transform the types of variables into
 *  ClassDatums. All types must be classes. It also transforms the 
 *  Class super types. 
 * FROM
 *  QVTp!Class
 * TO
 *  QVTs!ClassDatum
 * ANNOTATIONS
 *  lazy        Lazy variables from iterators and not automatically transformed
 *  greedy      Greedy so we also transform super types of the class
 */
@lazy
@greedy
rule ClassToClassDatum
    transform t : QVTp!Class
    to d : QVTs!ClassDatum {
                         
        guard : t.producesDatums()
        
        var domain;
        if (t.existsCorePatternVariable()) {
        	// FIXME What if we have different variables belonging to different domains ?
        	domain = t.getCorePatternVariables().first().oppositePattern().area;
        } else {
        	domain = null; 
        }
        //t.name.println("TypeToClassDatum ");
        d.type = t;
        d.super.addAll(t.superClasses.equivalent());
 		d.domain = domain;
 		d.schedule ::= QVTp!Transformation.all.first();
    }


@greedy 
rule PropertyCallExpToPropertyDatum
    transform pCallExp : QVTp!PropertyCallExp
    to pDatum : QVTs!PropertyDatum {
       
        // guard: PropertyCallExp belonging to a mapping and
        //        the referred property doesn't have any property datum
		guard { 
			var propContext = pCallExp.getContextType();
			var refProperty = pCallExp.referredProperty;
			return pCallExp.isContainedInAnArea() and 
					refProperty.propertyDatumNotCreated(propContext);
		}
		var propContext = pCallExp.getContextType();
		var refProperty = pCallExp.referredProperty;
		// refProperty.print("Analyzing property call Exp: ");
		pDatum.updatePropertyDatum(propContext,refProperty);
	}

-- greedy to also consider MiddlePropertyCallExp
@greedy
rule OppositePropertyCallExpToPropertyDatum
    transform oPropCallExp : QVTp!OppositePropertyCallExp
    to pDatum : QVTs!PropertyDatum {

        // guard: OppPropertyCallExp belonging to a mapping and
        //        the referred property doesn't have any property datum
		guard { 
			var propContext = oPropCallExp.getContextType();
			var refProperty = oPropCallExp.referredProperty.opposite;
       		return pCallExp.isContainedInAnArea() and 
       				refProperty.propertyDatumNotCreated(propContext);
		}
		var propContext = oPropCallExp.getContextType();
		var refProperty = oPropCallExp.referredProperty.opposite;
		pDatum.updatePropertyDatum(propContext,refProperty);
	}


-- greedy to also consider MiddlePropertyAssignment
// FIXME opposites (nonNavigable) will need different treat. See Bug 454555
@greedy    
rule PropertyAssignmentToPropertyDatum 
    transform pAssign : QVTp!PropertyAssignment
    to pDatum : QVTs!PropertyDatum {

		// guard: the referred property doesn't have any property datum        
		guard { 
			var propContext = pAssign.getContextType();
			var refProperty = pAssign.targetProperty;
       		return refProperty.propertyDatumNotCreated(propContext);
		}
		var propContext = pAssign.getContextType();
		var refProperty = pAssign.targetProperty;
     	pDatum.updatePropertyDatum(propContext, refProperty);
	}

-- 
-- Since operations might have other PropertyCallExp and OperationCallExp of interest, they have
-- to be individually analyzed. We will start the analysis from OperationCallExps which are used
-- from expression which belong to the mapping (or any of their CorePatterns)
-- 
-- Note that the original context type on which the operation is called, needs to be carried on
-- through the anlysis, so the proper PropertyDatums are accordingly created
-- 
rule OperationCallExpToPropertyDatums
	transform opCall : QVTp!OperationCallExp
	to pDatums : OrderedSet(QVTs!PropertyDatum) {

	// We are only interested in operation call expressions made from expressions
	// belonging to the mappings (or any of their CorePatterns)
	guard : opCall.isContainedInAnArea()
	
	var context = opCall.getContextType();
	// context.print("Analyzing operation call Exp: ");
	// opCall.println("::");
	pDatums.addAll(opCall.analyseOCLExpression(context, Map{}, Map{}));
}

operation QVTp!OperationCallExp analyseOCLExpression(context : QVTp!Type, type2VisitedOperations : Map, type2VariableBindings : Map) : OrderedSet(QVTp!PropertyDatum) {
		
	var visitedOps = type2VisitedOperations.get(context);
	if (visitedOps = null) {
		visitedOps = Set{};
		type2VisitedOperations.put(context, visitedOps);
	}
	
	var variable2BoundContext = type2VariableBindings.get(context);
	if (variable2BoundContext = null) {
		variable2BoundContext = Map{};
		type2VariableBindings.put(context, variable2BoundContext);
	}
	
	var result = OrderedSet{};
	var op = self.referredOperation;
	
	if (not visitedOps.contains(op)) {
		//context.name.print("Op analised: ");
		//op.name.println("::");
		visitedOps.add(op);
		if (op.isOclContainerOp()) {
			for (newContext in self.getComputedContexts(variable2BoundContext)) {
				result.addAll(newContext.analyseOclContainerCall());
			} 
		} else {
			var expInOCL = op.getBodyExpression();
			if (expInOCL.isKindOf(QVTp!ExpressionInOCL)) {
				var oclExp = expInOCL.getOwnedBody();
				if (oclExp <> null) {
					variable2BoundContext.put(expInOCL.ownedContext, context);
					for (eObject in oclExp.getAllContentsIncludingSelf()) {
						if (eObject.isKindOf(QVTp!LetExp)) {
							eObject.updateVariableBindings(variable2BoundContext);
						} else if (eObject.isKindOf(QVTp!PropertyCallExp)) { // FIXME OppositeCallExp ?
							for (newContext in eObject.getComputedContexts(variable2BoundContext)) {
								result.add(eObject.analyseOCLExpression(newContext));
							}
						} else if (eObject.isKindOf(QVTp!OperationCallExp)) {
							for (newContext in eObject.getComputedContexts(variable2BoundContext)) {
								result.addAll(eObject.analyseOCLExpression(newContext, type2VisitedOperations, type2VariableBindings));
							}
						}
					}
				}
			}
		}
	}
	return result;
}

operation QVTp!PropertyCallExp analyseOCLExpression(context : QVTp!Type) : QVTs!PropertyDatum {

	var refProperty = self.referredProperty;
	// refProperty.println("\tSUB property : ");
	return refProperty.getOrCreatePropertyDatum(context);
}

operation QVTp!Type analyseOclContainerCall() : OrderedSet(QVTp!PropertyDatum) {
	
	var result =  OrderedSet{};	
	for (parentClass in self.getContainingTypes()) {
		for (prop in parentClass.ownedProperties.select(x | x.isComposite)) {
			if (self.getAllSuperAndSubClassesIncludingSelf().includes(prop.getElementType())) {
				// self.print("\tOCL Container property  for ");
				// prop.println(" : ");	
				// FIXME I'm getting non-deterministic QVTs 2 Graphml transformations
				// when there are references to non-navigable (inexistent) properties
				// in .oclas. Example3: Kiama
				// For the time being, let's create the dependency on the forward
				// containment property
				--var opposite = prop.opposite;
				--result.add(opposite.getOrCreatePropertyDatum(self));
				result.add(prop.getOrCreatePropertyDatum(parentClass));
			}
		}
	}
	return result;
}



operation QVTp!LetExp updateVariableBindings(variable2BoundContext : Map ) {

	var variable = self.ownedVariable;
	variable2BoundContext.put(variable, variable.ownedInit.computeContexts(variable2BoundContext));
}

-- 
-- PropertyDatums can be created either via an ETL rule or 'new' statment. Whereas PropertyDatums can 
-- be differently created, this common subroutine will accordignly update the properties of those PropertyDatums.
-- 
operation QVTs!PropertyDatum updatePropertyDatum(context: QVTp!Type, prop : QVTp!Property) {

	var classDatum ::= context;
	--context.name.print("Updating property for ");
	--prop.name.println("::");
	self.domain = classDatum.domain;
	self.property = prop;
    self.classDatum = classDatum;
    if (context <> prop.owningClass) { // Propagate to supertypes as long as the context is not the property owner
	    for (superClass in context.superClasses) {
	    	if (superClass.producesDatums()) {
		    	var superPropDatum = prop.getOrCreatePropertyDatum(superClass);
		    	self.super.add(superPropDatum);
	    	}
	    }
    }
}

operation QVTp!Property propertyDatumNotCreated(context : QVTp!Type) : Boolean {
    return self.getPropertyDatum(context).isUndefined();
}

operation QVTp!Property getOrCreatePropertyDatum(context : QVTp!Type) : QVTs!PropertyDatum {

	if (self.propertyDatumNotCreated(context)) {
		var pDatum = new QVTs!PropertyDatum;
		pDatum.updatePropertyDatum(context,self);
		return pDatum;
	} else {
		return self.getPropertyDatum(context);
	}
}

operation QVTs!PropertyDatum getOrCreateOppositePropDatum() : QVTs!PropertyDatum {
	if (self.opposite.isDefined()) { // The opposite was already created
		return self;
	} else {
		var oppProp = self.property.opposite;
		if (oppProp.isDefined()) {
			var oppPropContext = oppProp.owningClass;
			if (oppPropContext.producesDatums()) {
				var oppositePropDatum = oppProp.getOrCreatePropertyDatum(oppPropContext);
				self.opposite = oppositePropDatum;
				return oppositePropDatum;
			}
		}
		return null;	
	}
}

operation QVTp!Property getPropertyDatum(context : QVTp!Type) {
	var classDatum = context.equivalent();
    if (classDatum.isUndefined()) {
    	return null;
    } else {
    	return classDatum.propertyDatums.selectOne(x | x.property = self);
    }
}

operation QVTp!OperationCallExp getPropertyDatums() : OrderedSet(QVTs!PropertyDatum) {
	return self.equivalent();
}

operation QVTp!PropertyCallExp getPropertyDatum() : QVTs!PropertyDatum {
	return self.referredProperty.getPropertyDatum(self.ownedSource.type);
} 

operation QVTp!OppositePropertyCallExp getPropertyDatum() : QVTs!PropertyDatum {
	return self.referredProperty.opposite.getPropertyDatum(self.ownedSource.type);
}

operation QVTp!PropertyAssignment getPropertyDatum() : QVTs!PropertyDatum {
	return self.targetProperty.getPropertyDatum(self.slotExpression.type);
}

@cached
operation QVTp!Type producesDatums() : Boolean {
	return self.existsCorePatternVariable() or self.hasUsedProperties();
}

@cached
operation QVTp!Type existsCorePatternVariable() : Boolean {
	return self.getCorePatternVariables().notEmpty();
}

@cached
operation QVTp!Type getCorePatternVariables() : OrderedSet(QVTp!Variable) {
	return QVTp!Variable.all().asOrderedSet().select(v | v.eContainer().isKindOf(QVTp!CorePattern) 
		and self.getAllSuperClasses().select(x | x.existsCorePatternVariable()).including(v.type).includes(self));
}

@cached
operation QVTp!Type getAllSuperClasses() : OrderedSet {
    if (self.isClass().isDefined())
	   return self.asSequence().closure(x | x.superClasses).asOrderedSet();
	return new OrderedSet();
}

@cached 
operation QVTp!Type getAllSuperClassesIncludingSelf() : OrderedSet {
	return self.getAllSuperClasses().including(self);
}

@cached
operation QVTp!Type getAllSubClasses() : OrderedSet {
	return QVTp!Class.all().select(x | x.getAllSuperClasses().includes(self)).asOrderedSet();
}

@cached
operation QVTp!Type getAllSubClassesIncludingSelf() : OrderedSet {
	return self.getAllSubClasses().including(self);
}

@cached 
operation QVTp!Type getAllSuperAndSubClassesIncludingSelf() : OrderedSet {
	return self.getAllSuperClassesIncludingSelf().includingAll(self.getAllSubClasses());
}

@cached
operation QVTp!Type hasUsedProperties() : Boolean {
	return self.getUsedProperties().notEmpty();
}

@cached 
operation QVTp!Type getUsedProperties() : OrderedSet(QVTp!Property) {
	var allSuperTypes = self.getAllSuperClasses();
	
	var allUsedForwardProps = getAllUsedForwardProps();
	var allUsedOppositeProps = getAllUsedOppositeProps();
	// FIXME Since oclContainerOpCalls are dependending on the forward containment reference
	// of the possible object parent types. This allUsedContainerProps is not needed, for the time being
	// See comment in analyseOclContainerCall();
	
	//var allUsedContainerProps = getAllUsedContainerProps();
	
	return
		allUsedForwardProps.select(x | allSuperTypes.including(self).includes(x.owningClass)).includingAll(
		allUsedOppositeProps.select(x | self = x.type));//.includingAll(
		//allUsedContainerProps.select(x | allSuperTypes.including(self).includes(x.owningClass)));
}

@cached
operation getAllUsedForwardProps() : OrderedSet(QVTp!Property) {
	// TODO Using all() ->  might bring properties from PropCallExp unused operation. Improve analysis
	var allForwardPropCalls = QVTp!PropertyCallExp.all();
	var allForwardPropAssigns = QVTp!PropertyAssignment.all();
	var allUsedForwardProps = allForwardPropCalls.collect(x | x.referredProperty).asOrderedSet();
	allUsedForwardProps.addAll(allForwardPropAssigns.collect(x | x.targetProperty));
	return allUsedForwardProps;
}

@cached
operation getAllUsedOppositeProps() : OrderedSet(QVTp!Property) {
	// TODO Using all() ->  might bring properties from OppositeCallExp unused operation. Improve analysis
	var allOppositePropCalls = QVTp!OppositePropertyCallExp.all();
	return allOppositePropCalls.collect(x | x.referredProperty).asOrderedSet();
}

@cached
operation getAllUsedContainerProps() : OrderedSet(QVTp!Property) {
	// TODO Using all() ->  might bring properties from OppositeCallExp unused operation. Improve analysis
	var allUsedContainerOpCalls = QVTp!OperationCallExp.all().select(x | x.referredOperation.isOclContainerOp());
	var allUsedContainerOpCallCtxs = allUsedContainerOpCalls.collect(x | x.ownedSource.type).asOrderedSet();
	var allUsedContainerOpCallCtxsWithSubs = allUsedContainerOpCallCtxs.collect(x | x.getAllSubClassesIncludingSelf()).flatten();
	var allContainmentProperties = QVTp!Property.all().select(x | x.isComposite);

	var allUsedContainmentProperties = allContainmentProperties.select(x | allUsedContainerOpCallCtxsWithSubs.includes(x.getElementType()));

	return allUsedContainmentProperties.collect(x | x.opposite).excluding(null).asOrderedSet();
}

@cached
operation QVTp!OCLExpression getSourceVariable() : QVTp!Variable {
    -- return self.asSequence().closure(x | if x.isKindOf(QVTp!CallExp) x.ownedSource else Collection{}).one(x | x.isKindOf(QVTp!VariableExp).variable;
    var exp = self;
	while (true) {
		if (exp.isKindOf(QVTp!VariableExp)) {
			return exp.referredVariable;
		}
		if (not exp.isKindOf(QVTp!CallExp)) {
			return null;
		}
		exp = exp.ownedSource;
	}
}

@cached
operation QVTp!PropertyAssignment getSourceVariable() : QVTp!Variable { 
	return self.slotExpression.getSourceVariable(); 
}

@cached 
operation QVTp!Mapping getAllContents() : Sequence {
	return self.asSequence().closure(x | x.eContents());
}

@cached
operation QVTp!Mapping getPropertyAssignments() : Sequence { 
	return self.getAllContents().select(x | x.isKindOf(QVTp!PropertyAssignment));
}

@cached
operation QVTp!Mapping getPropertyAccesses() : Sequence { 
	return self.getAllContents().select(x | x.isKindOf(QVTp!PropertyCallExp) or x.isKindOf(QVTp!OppositePropertyCallExp));
}

@cached
operation QVTp!Mapping getOperationCallExps() : Sequence { 
	return self.getAllContents().select(x | x.isKindOf(QVTp!OperationCallExp));
}

@cached
operation QVTp!CallExp getContextType() : QVTp!Type {
	// TODO Calling operations in the context is trycky, analyze this!
	return self.ownedSource.type;
}

@cached
operation QVTp!PropertyAssignment getContextType() : QVTp!Type {
	return self.slotExpression.type;
}

@cached
operation QVTp!TypedElement getElementType() : QVTp!Type {
	var type = self.type;
	if (type.isKindOf(QVTp!CollectionType)) {
		return type.elementType;
	} else {
		return type;
	}
}

-- This is needed when analysing Property/Operation call exps so that they exploit the statically computed context 
-- carried on through the analysis.
@cached
operation QVTp!CallExp getComputedContexts(variable2BoundContext : Map) : OrderedSet(QVTp!Type) {
	var source = self.ownedSource;
	return source.computeContexts(variable2BoundContext);
}

@cached
operation QVTp!VariableExp computeContexts(variable2BoundContext : Map) : OrderedSet(QVTp!Type) {
	var result;
	var context = variable2BoundContext.get(self.referredVariable);
	if (context.isDefined()) {
		result = context;
	} else {
		result = self.type;
	}
	return result.asOrderedSet();
}

@cached
operation QVTp!CallExp computeContexts(variable2BoundContext : Map) : OrderedSet(QVTp!Type) {
	var result = OrderedSet{};
	if (self.isKindOf(QVTp!OperationCallExp) and self.referredOperation.isOclContainerOp()) {
		for(oclContainerOpContext in self.ownedSource.computeContexts(variable2BoundContext)) {
			result.addAll(oclContainerOpContext.getContainingTypes());
		}
	} else {
		result.add(self.type);
	}
	return result;
}

@cached
operation QVTp!Operation isOclContainerOp() : Boolean {
	// FIXME make this check more robust
	return self.name = 'oclContainer' and self.ownedParameters.isEmpty();
}
@cached 
operation QVTp!OCLExpression isContainedInAnArea() : Boolean {

	var container = self.eContainer();
	while (container <> null) {
		if (container.isKindOf(QVTp!Area)) {
			return true;
		}
		container = container.eContainer();
	}
	return false;
}

@cached 
operation QVTp!OCLExpression getAllContents() : Sequence {
	return self.asSequence().closure(x | x.eContents());
}

@cached
operation QVTp!OCLExpression getAllContentsIncludingSelf() : Sequence {
	var initSeq = self.asSequence(); 
	return initSeq.includingAll(initSeq.closure(x | x.eContents()));
}

@cached
operation QVTp!Type getContainingTypes() : OrderedSet(QVTp!PropertyType) {

	var result =  OrderedSet{};
	var node = self.getNode();
	if (node == null) {
		return result;
	} else {
		// We also consider subtypes, due to a more conservative approach:
		// If we want to compute possible containers of A, since the actual element could
		// be a subtype B/C, possible containers of B/C will also be required 
		var nodeAndSubtypes = node.asOrderedSet.closure(x | x.subTypes).including(node);
		var allParents = nodeAndSubtypes.collect(x | x.parent).flatten();
		for (parentNode in allParents) {
			result.add(parentNode.getClass());
		}
		return result;
	}
}

// FIXME oclContainer might be used on inputs. Discuss with Ed if we want to add those dependencies or not.
// Probably not.
@cached
operation rTree!Node getClass() : QVTp!Class {
	return QVTp!Class.all.selectOne(x | x.getETarget() = self.element);
}

// FIXME oclContainer might be used on inputs. Discuss with Ed if we want to add those dependencies or not.
// Probably not.
@cached
operation QVTp!Class getNode() : rTree!Node {
	return rTree!Node.all.selectOne(x | x.element = self.getETarget());
}

post{
	// Traces can't be used because only one pDatum access/assignment is associated with the pDatum via traces
	// Therefore, update the requisites/productions at the end
	for (ma in  QVTs!MappingAction.all) {
		var m = ma.mapping;
		var consumedPDatums = m.getPropertyAccesses().collect(x | x.getPropertyDatum()).asOrderedSet();
		consumedPDatums.addAll(m.getOperationCallExps().collect(x | x.getPropertyDatums()).flatten());
		var producedPDatums = m.getPropertyAssignments().collect(x | x.getPropertyDatum()).asOrderedSet();
		for (pDatum in producedPDatums.clone()) { // We want all the opposite produced by them
			var oppositePDatum = pDatum.getOrCreateOppositePropDatum();
			if (oppositePDatum.isDefined()) {
				producedPDatums.add(oppositePDatum);
			}
		}
		ma.productions.addAll(producedPDatums);
		ma.requisites.addAll(consumedPDatums);
	} 
	
	"QVTpToSchedule Done".println();
}

Back to the top