#REFACTORING by exept
authorClaus Gittinger <cg@exept.de>
Sun, 13 Oct 2019 23:31:57 +0200
changeset 4582 120e83524d09
parent 4581 8936eaed9e9b
child 4583 18c9ee9d89f4
#REFACTORING by exept class: ParseNode added: #whoDefines:
ParseNode.st
--- a/ParseNode.st	Thu Oct 10 11:35:17 2019 +0200
+++ b/ParseNode.st	Sun Oct 13 23:31:57 2019 +0200
@@ -675,6 +675,25 @@
     ^ 9999
 !
 
+whoDefines:aName
+    "return the node (blockNode) in which this variable is defined.
+     (nil if instvar, classvar or global)"
+
+    |p|
+
+    "/ TODO
+"/    block notNil ifTrue:[
+"/        self halt
+"/    ].
+    p := parent.
+    [p notNil and:[p isFunctionNode not and:[p isBlockNode not]]] whileTrue:[ p := p parent].
+    p notNil ifTrue:[
+        ((p arguments ? #()) contains:[:var | var name = aName]) ifTrue:[^ p].
+        ((p localVariables ? #()) contains:[:var | var name = aName]) ifTrue:[^ p].
+    ].
+    ^ nil
+!
+
 withConstantValueDo:aBlock
     "return true, if this evaluates to a constant value
      and evaluate aBlock with it"