daviis / PyDucker

A static ducking tool for python 3 source code
2 stars 2 forks source link

Walkers need scope info #15

Closed daviis closed 9 years ago

daviis commented 10 years ago

There should be an internal var in a walker that holds the LevelBean stack that will be used for scoping.

JakeAlbee commented 9 years ago

Instead of using an internal var would it be smarter to abstract the scoping function from the walkers?

For example making a scoping class where we store all the scope information and when you need to check scope a walker(of any variety) can call it to check the scope of something?

Such as if you're checking to see if the variable test is in your scope you could do something like...

test = 1
     def main():
          x = scopeInfo()
          x.check(test) #Would return true or false for being in scop
         #post checking, add the current level to the scope
          x.addLevel(levelBean)
         #continue walking here

We'd have to make the scopeInfo object outside the initial walking attempt, probably the same place #12 is done, but then we would have an object that knows all the scoping info and would be easily accessible if we needed to check scoping somewhere else?

daviis commented 9 years ago

Currently we are sending copies of the scope bean into the walkers (class/fun)def and then when they complete, the extra vars should be gone.

daviis commented 9 years ago

I think it might be best to have the namespace be a member of the scope bean. It won't be used outside of it for look ups so it may be beneficial.

daviis commented 9 years ago

No need to house namespace in scope because it seems to flow well with out. Look at visit_binop in GenericWalker for an example of this