forked from pbiggar/phc
/
Lift_functions_and_classes.cpp
41 lines (33 loc) · 1.01 KB
/
Lift_functions_and_classes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* phc -- the open source PHP compiler
* See doc/license/README.license for licensing information
*
* Lift functions and classes to the global scope, and introduce "__MAIN__"
*
*/
#include "Lift_functions_and_classes.h"
#include "process_ir/General.h"
using namespace MIR;
void Lift_functions_and_classes::children_php_script(PHP_script* in)
{
Statement_list* main = new Statement_list;
Statement_list* top_level_statements = new Statement_list;
// move all non-declaration statements into main
foreach (Statement* s, *in->statements)
{
if ((s->attrs->is_true("phc.lower_control_flow.top_level_declaration")))
top_level_statements->push_back(s);
else
main->push_back(s);
}
top_level_statements->push_back(new Method(
new Signature(
new Method_mod(),
false,
false,
new METHOD_NAME(new String("__MAIN__")),
new Formal_parameter_list),
main));
top_level_statements->back()->attrs->set_true("phc.lower_control_flow.top_level_declaration");
in->statements = top_level_statements;
}