ARudik / phc

Automatically exported from code.google.com/p/phc
0 stars 0 forks source link

Revisit decision to move statements in the global scope into a __MAIN__ function during the AST-to-HIR phase #75

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Initially, our AST::PHP_script was a list of classes, interfaces and
methods. Our main method went into class %%MAIN%%, method %%RUN%%. We
changed this because it doesnt actually correspond to a script, it changes
the order, and that may change the semantics.

I can't think of why it changes the semantics now, since top-level
definitions are somewhat magic.

Ordering isnt a concern for this. The change first appears in the HIR
(though its done in the AST-to-HIR phase), and ordering for unparsing
doesn't matter there. However, we use list of Top_level_defs instead of 3
lists of classes, methods and interface, so that defs are in the same
order, relative to each other. The only difference is moving non-defs to
the top.

Edsko worries that include statements may break this. I think this
shouldn't be the case, since top-level defintions are magic, so if they
move to the back, it will stay the same. If they were to move to the front,
then it might fail, since we would be trying to create the class before the
file is included. However, I'm not certain in either case.

This change is being made so that some passes are easier, notably
Dead_code_elimination and Copy_propagation. The nested functions are
messing with them a little bit.

Original issue reported on code.google.com by paul.biggar on 4 Apr 2008 at 2:37

GoogleCodeExporter commented 9 years ago
It turns out that ordering was a problem for this, and that top-level-statements
weren't as magic as I thought. So this change was undone almost immediately.

Original comment by paul.biggar on 6 Jun 2008 at 4:53