[Pyrex] Unused variables
Phillip J. Eby
pje at telecommunity.com
Fri Dec 2 00:14:15 CET 2005
At 11:44 AM 12/2/2005 +1300, Greg Ewing wrote:
>Jim Fulton wrote:
>
> > Pyrex is generating
> > code with unused labels and variables and with static declarations for
> > things that aren't defined. I wasn't sure if this was normal
>
>Yes, it's normal, and yes it's not ideal, but fixing
>it is non-trivial.
Well, this might not be *trivial*, but what if you were to...
1. When writing a label, store the output file's seek position and the
length of the label in a dictionary keyed by label.
2. When referencing a label, remove its entry from the dictionary (if it
hasn't already been removed)
3. At the end of processing, seek back to any entries still in the
dictionary and overwrite them with spaces.
This can be trivially generalized to other declarations, and can use the
same dictionary if basically you just store the text of the lines to be
overwritten. So for labels you'd use "label_foo:" as the key, and for
other things you'd use variable declarations or whatever. So the cleanup
loop could know how many spaces to write based on the key length, and the
values could just be the seek offsets.
Depending on your perspective, this is a brilliant solution, an evil hack,
or both. :)
More information about the Pyrex
mailing list