Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 874fee4c4500652608032e0f423fa35d1aa60a45 (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
import  _source : 'SourceMM1.ecore#/'
import  _target : 'TargetMM1.ecore#/'
import 'EnvExample1.ecore'

package ocl
---- Default Environment related functionality
context OclElement
--	
def : _exported_env(importer : OclElement) : lookup::LookupEnvironment[1] =
	lookup::LookupEnvironment { }
	
-- Domain specific default functionality
def : unqualified_env_A1() : lookup::LookupEnvironment[1] =
	_unqualified_env_A1(null)
def : unqualified_env_A2() : lookup::LookupEnvironment[1] =
	_unqualified_env_A2(null)
def : unqualified_env_B() : lookup::LookupEnvironment[1] =
	_unqualified_env_B(null)
def : unqualified_env_C() : lookup::LookupEnvironment[1] =
	_unqualified_env_C(null)

def : _unqualified_env_A1(child : OclElement) : lookup::LookupEnvironment[1] =
	parentEnv_A1()
def : _unqualified_env_A2(child : OclElement) : lookup::LookupEnvironment[1] =
	parentEnv_A2()
def : _unqualified_env_B(child : OclElement) : lookup::LookupEnvironment[1] =
	parentEnv_B()
def : _unqualified_env_C(child : OclElement) : lookup::LookupEnvironment[1] =
	parentEnv_C()

def : parentEnv_A1() : lookup::LookupEnvironment[1] =
	let parent = oclContainer() in if parent = null then lookup::LookupEnvironment { } else parent._unqualified_env_A1(self) endif
def : parentEnv_A2() : lookup::LookupEnvironment[1] =
	let parent = oclContainer() in if parent = null then lookup::LookupEnvironment { } else parent._unqualified_env_A2(self) endif
def : parentEnv_B() : lookup::LookupEnvironment[1] =
	let parent = oclContainer() in if parent = null then lookup::LookupEnvironment { } else parent._unqualified_env_B(self) endif
def : parentEnv_C() : lookup::LookupEnvironment[1] =
	let parent = oclContainer() in if parent = null then lookup::LookupEnvironment { } else parent._unqualified_env_C(self) endif
-- End of domain specific default functionality
endpackage 

package lookup
context LookupEnvironment
def : nestedEnv() : LookupEnvironment[1] = 
	LookupEnvironment {
		parentEnv = self
	}
endpackage

package _target

	
context TRoot
def : _unqualified_env_A1(child : ocl::OclElement) : lookup::LookupEnvironment =
	parentEnv_A1()
		.addElements(ownedA)
		
def : _unqualified_env_A2(child : ocl::OclElement) : lookup::LookupEnvironment =
	parentEnv_A2()
		.addElements(ownedA)
	
context A1
	
def : _lookupQualifiedB(bName : String) : B[?] =
	let foundB = _lookupB(_qualified_env(), bName)
	in  if foundB->isEmpty()
		then null
		else foundB->first()
		endif
def : lookupQualifiedB(aPathElementCS : _source::PathElementCS) : B[?] =
   _lookupQualifiedB(aPathElementCS.name)
   
	
def : _qualified_env() : lookup::LookupEnvironment =
	let env = lookup::LookupEnvironment{}
	in env
		.addElements(ownsB)
def : _unqualified_env_B(child : ocl::OclElement) : lookup::LookupEnvironment =
	if ownsB->includes(child)
	then parentEnv_B().nestedEnv()
		.addElements(ownsB->select(x | self.ownsB->indexOf(x) < self.ownsB->indexOf(child)))
		
	else parentEnv_B()
	endif
	
context A2
	
def : _lookupQualifiedC(cName : String) : C[?] =
	let foundC = _lookupC(_qualified_env(), cName)
	in  if foundC->isEmpty()
		then null
		else foundC->first()
		endif
def : lookupQualifiedC(aPathElementCS : _source::PathElementCS) : C[?] =
   _lookupQualifiedC(aPathElementCS.name)
   
	
def : _qualified_env() : lookup::LookupEnvironment =
	let env = lookup::LookupEnvironment{}
	in env
		.addElements(ownsC)
def : _unqualified_env_C(child : ocl::OclElement) : lookup::LookupEnvironment =
	if ownsC->includes(child)
	then parentEnv_C().nestedEnv()
		.addElements(ownsC->select(x | self.ownsC->indexOf(x) < self.ownsC->indexOf(child)))
		
	else parentEnv_C()
	endif

context Visitable
-- A1 lookup
def : _lookupA1(env : lookup::LookupEnvironment, aName : String) : OrderedSet(A1) =
let foundA1 = env.namedElements->selectByKind(A1)->select(name = aName)
in  if foundA1->isEmpty() and not (env.parentEnv = null)
	then _lookupA1(env.parentEnv, aName)
	else foundA1
	endif
	
-- Note: when calling this method, the source element of the argument passed to this method, will be the contextual 
-- object on which error reports will be handled
def : _lookupUnqualifiedA1(aName : String) : A1[?] =
let foundA1 = _lookupA1(unqualified_env_A1(), aName)
in  if foundA1->isEmpty()
	then null
	else foundA1->first() -- LookupVisitor will report ambiguous result
	endif
def : lookupA1(aPathElementCS : _source::PathElementCS) : A1[?] =
   _lookupUnqualifiedA1(aPathElementCS.name)
   


-- A2 lookup
def : _lookupA2(env : lookup::LookupEnvironment, aName : String) : OrderedSet(A2) =
let foundA2 = env.namedElements->selectByKind(A2)->select(name = aName)
in  if foundA2->isEmpty() and not (env.parentEnv = null)
	then _lookupA2(env.parentEnv, aName)
	else foundA2
	endif
	
-- Note: when calling this method, the source element of the argument passed to this method, will be the contextual 
-- object on which error reports will be handled
def : _lookupUnqualifiedA2(aName : String) : A2[?] =
let foundA2 = _lookupA2(unqualified_env_A2(), aName)
in  if foundA2->isEmpty()
	then null
	else foundA2->first() -- LookupVisitor will report ambiguous result
	endif
def : lookupA2(aPathElementCS : _source::PathElementCS) : A2[?] =
   _lookupUnqualifiedA2(aPathElementCS.name)
   


-- B lookup
def : _lookupB(env : lookup::LookupEnvironment, bName : String) : OrderedSet(B) =
let foundB = env.namedElements->selectByKind(B)->select(name = bName)
in  if foundB->isEmpty() and not (env.parentEnv = null)
	then _lookupB(env.parentEnv, bName)
	else foundB
	endif
	
-- Note: when calling this method, the source element of the argument passed to this method, will be the contextual 
-- object on which error reports will be handled
def : _lookupUnqualifiedB(bName : String) : B[?] =
let foundB = _lookupB(unqualified_env_B(), bName)
in  if foundB->isEmpty()
	then null
	else foundB->first() -- LookupVisitor will report ambiguous result
	endif
def : lookupB(aPathElementCS : _source::PathElementCS) : B[?] =
   _lookupUnqualifiedB(aPathElementCS.name)
   

-- QN B lookup
def : lookupB(aPathNameCS : _source::PathNameCS) : B[?] =
   lookupB(aPathNameCS .path)

def : lookupB(segments : OrderedSet(_source::PathElementCS)) : B[?] =
   if segments->size() = 1
   then lookupB(segments->first())
   else let qualifierSegments = segments->subOrderedSet(1,segments->size()-1),
            qualifier = lookupA1(qualifierSegments->first())
        in qualifier?.lookupQualifiedB(segments->last())
   endif

-- C lookup
def : _lookupC(env : lookup::LookupEnvironment, cName : String) : OrderedSet(C) =
let foundC = env.namedElements->selectByKind(C)->select(name = cName)
in  if foundC->isEmpty() and not (env.parentEnv = null)
	then _lookupC(env.parentEnv, cName)
	else foundC
	endif
	
-- Note: when calling this method, the source element of the argument passed to this method, will be the contextual 
-- object on which error reports will be handled
def : _lookupUnqualifiedC(cName : String) : C[?] =
let foundC = _lookupC(unqualified_env_C(), cName)
in  if foundC->isEmpty()
	then null
	else foundC->first() -- LookupVisitor will report ambiguous result
	endif
def : lookupC(aPathElementCS : _source::PathElementCS) : C[?] =
   _lookupUnqualifiedC(aPathElementCS.name)
   

-- QN C lookup
def : lookupC(aPathNameCS : _source::PathNameCS) : C[?] =
   lookupC(aPathNameCS .path)

def : lookupC(segments : OrderedSet(_source::PathElementCS)) : C[?] =
   if segments->size() = 1
   then lookupC(segments->first())
   else let qualifierSegments = segments->subOrderedSet(1,segments->size()-1),
            qualifier = lookupA2(qualifierSegments->first())
        in qualifier?.lookupQualifiedC(segments->last())
   endif



endpackage

Back to the top