|
1 "{ Package: 'jv:tea/compiler' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
|
4 |
|
5 Object subclass:#TScope |
|
6 instanceVariableNames:'node parent children variables' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'' |
|
9 category:'Languages-Tea-Compiler-Bindings' |
|
10 ! |
|
11 |
|
12 !TScope class methodsFor:'instance creation'! |
|
13 |
|
14 node: node |
|
15 ^ self node: node parent: nil. |
|
16 |
|
17 "Created: / 25-08-2015 / 22:28:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
18 ! |
|
19 |
|
20 node: node parent: parent |
|
21 ^ self new initializeWithNode: node parent: parent |
|
22 |
|
23 "Created: / 25-08-2015 / 22:24:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
24 ! ! |
|
25 |
|
26 !TScope methodsFor:'accessing'! |
|
27 |
|
28 children |
|
29 ^ children ? #() |
|
30 |
|
31 "Modified: / 25-08-2015 / 22:28:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
32 ! |
|
33 |
|
34 node |
|
35 ^ node |
|
36 ! |
|
37 |
|
38 parent |
|
39 ^ parent |
|
40 ! ! |
|
41 |
|
42 !TScope methodsFor:'initialization'! |
|
43 |
|
44 initializeWithNode: n parent: p |
|
45 node := n. |
|
46 parent := p. |
|
47 |
|
48 "Created: / 25-08-2015 / 22:25:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
49 ! ! |
|
50 |
|
51 !TScope methodsFor:'instance creation'! |
|
52 |
|
53 subScope: methodOrBlockNode |
|
54 children isNil ifTrue:[ |
|
55 children := OrderedCollection new: 5. |
|
56 ]. |
|
57 ^ children add: (self class node: methodOrBlockNode parent: self) |
|
58 |
|
59 "Created: / 25-08-2015 / 22:28:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
60 ! ! |
|
61 |
|
62 !TScope methodsFor:'lookup'! |
|
63 |
|
64 addVariable: aTVariableBinding |
|
65 variables isNil ifTrue:[ |
|
66 variables := OrderedCollection new. |
|
67 ]. |
|
68 variables add: aTVariableBinding |
|
69 |
|
70 "Created: / 25-08-2015 / 22:42:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
71 ! |
|
72 |
|
73 lookupVariable: name |
|
74 ^ variables |
|
75 detect:[:binding | binding name = name ] |
|
76 ifNone:[ parent notNil ifTrue:[ parent lookupVariable: name ] ifFalse:[ self error:'variable not found' ] ] |
|
77 |
|
78 "Created: / 25-08-2015 / 22:58:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
79 ! ! |
|
80 |