--- a/compiler/TScope.st Fri Sep 18 06:20:53 2015 +0100
+++ b/compiler/TScope.st Sun Sep 20 12:01:42 2015 +0100
@@ -37,29 +37,24 @@
parent
^ parent
+!
+
+variables
+ ^ variables ? #()
+
+ "Modified: / 19-09-2015 / 05:56:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
-!TScope methodsFor:'initialization'!
-
-initializeWithNode: n parent: p
- node := n.
- parent := p.
+!TScope methodsFor:'adding & removing'!
- "Created: / 25-08-2015 / 22:25:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!TScope methodsFor:'instance creation'!
-
-subScope: methodOrBlockNode
+addSubScope: aTScope
children isNil ifTrue:[
children := OrderedCollection new: 5.
].
- ^ children add: (self class node: methodOrBlockNode parent: self)
+ children add: aTScope
- "Created: / 25-08-2015 / 22:28:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!TScope methodsFor:'lookup'!
+ "Created: / 19-09-2015 / 06:05:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
addVariable: aTVariableBinding
variables isNil ifTrue:[
@@ -68,14 +63,36 @@
variables add: aTVariableBinding
"Created: / 25-08-2015 / 22:42:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
+! !
+
+!TScope methodsFor:'initialization'!
+
+initializeWithNode: n parent: p
+ node := n.
+ parent := p.
+ parent notNil ifTrue:[
+ parent addSubScope: self.
+ ].
+
+ "Created: / 25-08-2015 / 22:25:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 19-09-2015 / 06:06:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!TScope methodsFor:'lookup'!
lookupVariable: name
- ^ variables
- detect:[:binding | binding name = name ]
- ifNone:[ parent notNil ifTrue:[ parent lookupVariable: name ] ifFalse:[ self error:'variable not found' ] ]
+ "Return binding for variable with given name or nil if not found"
+ | variable |
+ variables notNil ifTrue:[
+ variable := variables detect:[:binding | binding name = name ] ifNone:[ nil ].
+ ].
+ (variable isNil and:[parent notNil]) ifTrue:[
+ variable := parent lookupVariable: name.
+ ].
+ ^ variable
"Created: / 25-08-2015 / 22:58:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 20-09-2015 / 06:11:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!TScope methodsFor:'testing'!