views:

72

answers:

1

I'm working on some code generation tools, and a lot of complexity comes from doing scope analysis. I frequently find myself wanting to know things like

  1. What are the free variables of a function or block?
  2. Where is this symbol declared?
  3. What does this declaration mask?
  4. Does this usage of a symbol potentially occur before initialization?
  5. Does this variable potentially escape?

and I think it's time to rethink my scoping kludge.

I can do all this analysis but am trying to figure out a way to structure APIs so that it's easy to use, and ideally, possible to do enough of this work lazily.

What tools like this are people familiar with, and what did they do right and wrong in their APIs?

+2  A: 
Norman Ramsey
Thanks for the thoughtful response.Alpha renaming is not an issue in this system.This is for a system that includes lint-tools for a dynamic language so good heuristic are often workable.
Mike Samuel
You're right about escape analysis of course, but a heuristic that tells whether a function defined inside another function might escape can help a lint tool ignore things like immediately used javascript closures closing over too much, or accessing a loop counter that's used in multiple loops.
Mike Samuel
Thanks for the pointers. I will see what I can glean from those links.
Mike Samuel