[phc-internals] [phc commit] r1148 - in trunk: plugins/tools src
src/codegen src/generated src/generated_src src/pass_manager ...
codesite-noreply at google.com
codesite-noreply at google.com
Sun Apr 6 14:45:42 IST 2008
Author: paul.biggar
Date: Sun Apr 6 06:44:03 2008
New Revision: 1148
Modified:
trunk/plugins/tools/reduce_statements.cpp
trunk/src/codegen/Compile_C.cpp
trunk/src/codegen/Compile_C.h
trunk/src/codegen/Copy_propagation.cpp
trunk/src/codegen/Generate_C.cpp
trunk/src/codegen/Generate_C.h
trunk/src/codegen/Lift_functions_and_classes.h
trunk/src/generated/AST.cpp
trunk/src/generated/AST.h
trunk/src/generated/HIR.cpp
trunk/src/generated/HIR.h
trunk/src/generated/MIR.cpp
trunk/src/generated/MIR.h
trunk/src/generated_src/ast.tea
trunk/src/generated_src/hir.tea
trunk/src/generated_src/mir.tea
trunk/src/pass_manager/Fake_pass.h
trunk/src/pass_manager/Pass.h
trunk/src/pass_manager/Pass_manager.cpp
trunk/src/pass_manager/Pass_manager.h
trunk/src/pass_manager/Plugin_pass.cpp
trunk/src/pass_manager/Plugin_pass.h
trunk/src/pass_manager/Transform_pass.h
trunk/src/pass_manager/Visitor_pass.h
trunk/src/phc.cpp
trunk/src/process_ast/Invalid_check.cpp
trunk/src/process_ast/Invalid_check.h
trunk/src/process_ast/Pretty_print.h
trunk/src/process_ast/Process_includes.h
trunk/src/process_ir/General.cpp
trunk/src/process_ir/IR.cpp
trunk/src/process_ir/IR.h
trunk/src/process_mir/Obfuscate.h
Log:
Instead of using IR as our base class, switch to using IR::Node as the
base class, and IR::PHP_script as the top-level class. This requires a
newly committed version of maketea (revision 78).
All of the changes are entirely mechanical.
Modified: trunk/plugins/tools/reduce_statements.cpp
==============================================================================
--- trunk/plugins/tools/reduce_statements.cpp (original)
+++ trunk/plugins/tools/reduce_statements.cpp Sun Apr 6 06:44:03 2008
@@ -182,7 +182,7 @@
// pm->add_mir_pass (pass);
}
-void run (IR* in, String* option)
+void run (IR::PHP_script* in, String* option)
{
// Read START and LENGTH from the option string (\d+:\d+)
int colon_index = -1;
Modified: trunk/src/codegen/Compile_C.cpp
==============================================================================
--- trunk/src/codegen/Compile_C.cpp (original)
+++ trunk/src/codegen/Compile_C.cpp Sun Apr 6 06:44:03 2008
@@ -34,7 +34,7 @@
return pm->args_info->compile_flag;
}
-void Compile_C::run (IR* in, Pass_manager* pm)
+void Compile_C::run (IR::PHP_script* in, Pass_manager* pm)
{
// Find PHP installation path
const char* php_path;
Modified: trunk/src/codegen/Compile_C.h
==============================================================================
--- trunk/src/codegen/Compile_C.h (original)
+++ trunk/src/codegen/Compile_C.h Sun Apr 6 06:44:03 2008
@@ -13,6 +13,6 @@
stringstream& os;
Compile_C (stringstream& os);
- void run (IR* in, Pass_manager* pm);
+ void run (IR::PHP_script* in, Pass_manager* pm);
bool pass_is_enabled (Pass_manager* pm);
};
Modified: trunk/src/codegen/Copy_propagation.cpp
==============================================================================
--- trunk/src/codegen/Copy_propagation.cpp (original)
+++ trunk/src/codegen/Copy_propagation.cpp Sun Apr 6 06:44:03 2008
@@ -47,7 +47,6 @@
* - $L1 must be assigned exactly once.
* - $L1 must be used exactly once - in the assignment to $L2.
* - $L2 is assigned exactly once, by $R1
- * - We only work in methods, not in the global statement list
*/
#include "Copy_propagation.h"
@@ -93,12 +92,12 @@
replaceable [slhs] = assignment;
}
- // be conservative
+ // consider for immediate removal
if (replaceable.find (srhs) != replaceable.end ()
&& rhs->attrs->get_integer ("phc.use_defs.use_count")->value () == 1
&& rhs->attrs->get_integer ("phc.use_defs.def_count")->value () == 1)
{
- cdebug << "r s is replacable" << endl;
+ cdebug << "rhs is replacable" << endl;
replaceable [srhs]->variable = new Variable (
NULL,
new VARIABLE_NAME (s(slhs)),
Modified: trunk/src/codegen/Generate_C.cpp
==============================================================================
--- trunk/src/codegen/Generate_C.cpp (original)
+++ trunk/src/codegen/Generate_C.cpp Sun Apr 6 06:44:03 2008
@@ -56,7 +56,7 @@
return pm->args_info->generate_c_flag or pm->args_info->compile_flag;
}
-void Generate_C::run (IR* in, Pass_manager* pm)
+void Generate_C::run (IR::PHP_script* in, Pass_manager* pm)
{
args_info = pm->args_info;
if (not PHP::is_available ())
@@ -1387,8 +1387,8 @@
<< "int result = zend_fcall_info_init (&function_name, &fci, &fcic TSRMLS_CC);\n"
<< "if (result == FAILURE) // check for missing function\n"
<< "{\n"
- << "phc_setup_error (1, "
- << rhs->get_filename () << ", "
+ << "phc_setup_error (1, \""
+ << *rhs->get_filename () << "\", "
<< rhs->get_line_number () << ", "
<< "NULL TSRMLS_CC);\n"
// die
@@ -1537,8 +1537,8 @@
}
code
- << "phc_setup_error (1, "
- << rhs->get_filename () << ", "
+ << "phc_setup_error (1, \""
+ << *rhs->get_filename () << "\", "
<< rhs->get_line_number () << ", "
<< " NULL TSRMLS_CC);\n"
Modified: trunk/src/codegen/Generate_C.h
==============================================================================
--- trunk/src/codegen/Generate_C.h (original)
+++ trunk/src/codegen/Generate_C.h Sun Apr 6 06:44:03 2008
@@ -5,7 +5,7 @@
* Generate C code
*
* Currently, the C code is generated directly from the AST; once we
have an
- * IR, the C code will be generated from the IR instead.
+ * LIR, the C code will be generated from the LIR instead.
*/
#ifndef GENERATE_C
@@ -20,7 +20,7 @@
ostream& os;
- void run (IR*, Pass_manager*);
+ void run (IR::PHP_script*, Pass_manager*);
Generate_C(ostream&);
public:
Modified: trunk/src/codegen/Lift_functions_and_classes.h
==============================================================================
--- trunk/src/codegen/Lift_functions_and_classes.h (original)
+++ trunk/src/codegen/Lift_functions_and_classes.h Sun Apr 6 06:44:03 2008
@@ -22,7 +22,7 @@
}
// TODO this should be done on HIR, I think
- void run (IR* in, Pass_manager* pm)
+ void run (IR::PHP_script* in, Pass_manager* pm)
{
if (pm->args_info->generate_c_flag
or pm->args_info->compile_flag)
Modified: trunk/src/generated/AST.cpp
==============================================================================
--- trunk/src/generated/AST.cpp (original)
+++ trunk/src/generated/AST.cpp Sun Apr 6 06:44:03 2008
@@ -3,34 +3,8 @@
#include "AST_visitor.h"
namespace AST{
-// Return the line number of the node (or 0 if unknown)
-int Node::get_line_number()
-{
- {
- Integer* i = dynamic_cast<Integer*>(attrs->get("phc.line_number"));
- if(i != NULL)
- return i->value();
- else
- return 0;
- }
-}
-
-// Return the filename of the node (or NULL if unknown)
-String* Node::get_filename()
-{
- {
- return dynamic_cast<String*>(attrs->get("phc.filename"));
- }
-}
-
Node::Node()
{
- {
- // Constructor gets called because all classes inherit from
- // Node virtually; also, because maketea knows Node is
- // abstract, it won't add a constructor itself
- attrs = new AttrMap();
- }
}
void Node::clone_mixin_from(Node* in)
Modified: trunk/src/generated/AST.h
==============================================================================
--- trunk/src/generated/AST.h (original)
+++ trunk/src/generated/AST.h Sun Apr 6 06:44:03 2008
@@ -112,9 +112,11 @@
class Visitor;
// Node ::= PHP_script | Class_mod | Signature | Method_mod |
Formal_parameter | Type | Attr_mod | Name_with_default | Directive |
List_element | Variable_name | Target | Array_elem | Method_name |
Actual_parameter | Class_name | Commented_node | Source_rep | HT_ITERATOR<long>;
-class Node : virtual public Object
+class Node : virtual public IR::Node
{
public:
+ Node();
+public:
virtual void visit(Visitor* visitor) = 0;
virtual void transform_children(Transform* transform) = 0;
public:
@@ -128,19 +130,13 @@
public:
virtual void assert_valid() = 0;
public:
- AttrMap* attrs;
- // Return the line number of the node (or 0 if unknown)
- int get_line_number();
- // Return the filename of the node (or NULL if unknown)
- String* get_filename();
- Node();
void clone_mixin_from(Node* in);
void assert_mixin_valid();
bool is_mixin_equal(Node* in);
};
// PHP_script ::= Statement* ;
-class PHP_script : virtual public Node, virtual public IR
+class PHP_script : virtual public Node, virtual public IR::PHP_script
{
public:
PHP_script(List<Statement*>* statements);
Modified: trunk/src/generated/HIR.cpp
==============================================================================
--- trunk/src/generated/HIR.cpp (original)
+++ trunk/src/generated/HIR.cpp Sun Apr 6 06:44:03 2008
@@ -3,41 +3,8 @@
#include "HIR_visitor.h"
namespace HIR{
-// Return the line number of the node (or 0 if unknown)
-int Node::get_line_number()
-{
- {
- Integer* i = dynamic_cast<Integer*>(attrs->get("phc.line_number"));
- if(i != NULL)
- return i->value();
- else
- return 0;
- }
-}
-
-// Return the filename of the node. If unknown, use "<unknown>",
-// which is what the interpreter uses.
-// TODO In the future, make sure we always have filenames and
-// line numbers.
-String* Node::get_filename()
-{
- {
- String* result = dynamic_cast<String*>(attrs->get("phc.filename"));
- if (result == NULL)
- result = new String ("<unknown>");
-
- return result;
- }
-}
-
Node::Node()
{
- {
- // Constructor gets called because all classes inherit from
- // Node virtually; also, because maketea knows Node is
- // abstract, it won't add a constructor itself
- attrs = new AttrMap();
- }
}
void Node::clone_mixin_from(Node* in)
Modified: trunk/src/generated/HIR.h
==============================================================================
--- trunk/src/generated/HIR.h (original)
+++ trunk/src/generated/HIR.h Sun Apr 6 06:44:03 2008
@@ -98,9 +98,11 @@
class Visitor;
// Node ::= PHP_script | Statement | Class_mod | Member | Signature |
Method_mod | Formal_parameter | Type | Attr_mod | Name_with_default |
Catch | Conditional_expr | Variable_name | Target | Array_elem |
Method_name | Actual_parameter | Class_name | Identifier | HT_ITERATOR<long>;
-class Node : virtual public Object
+class Node : virtual public IR::Node
{
public:
+ Node();
+public:
virtual void visit(Visitor* visitor) = 0;
virtual void transform_children(Transform* transform) = 0;
public:
@@ -114,22 +116,13 @@
public:
virtual void assert_valid() = 0;
public:
- AttrMap* attrs;
- // Return the line number of the node (or 0 if unknown)
- int get_line_number();
- // Return the filename of the node. If unknown, use "<unknown>",
- // which is what the interpreter uses.
- // TODO In the future, make sure we always have filenames and
- // line numbers.
- String* get_filename();
- Node();
void clone_mixin_from(Node* in);
void assert_mixin_valid();
bool is_mixin_equal(Node* in);
};
// PHP_script ::= Statement* ;
-class PHP_script : virtual public Node, virtual public IR
+class PHP_script : virtual public Node, virtual public IR::PHP_script
{
public:
PHP_script(List<Statement*>* statements);
Modified: trunk/src/generated/MIR.cpp
==============================================================================
--- trunk/src/generated/MIR.cpp (original)
+++ trunk/src/generated/MIR.cpp Sun Apr 6 06:44:03 2008
@@ -3,34 +3,8 @@
#include "MIR_visitor.h"
namespace MIR{
-// Return the line number of the node (or 0 if unknown)
-int Node::get_line_number()
-{
- {
- Integer* i = dynamic_cast<Integer*>(attrs->get("phc.line_number"));
- if(i != NULL)
- return i->value();
- else
- return 0;
- }
-}
-
-// Return the filename of the node (or NULL if unknown)
-String* Node::get_filename()
-{
- {
- return dynamic_cast<String*>(attrs->get("phc.filename"));
- }
-}
-
Node::Node()
{
- {
- // Constructor gets called because all classes inherit from
- // Node virtually; also, because maketea knows Node is
- // abstract, it won't add a constructor itself
- attrs = new AttrMap();
- }
}
void Node::clone_mixin_from(Node* in)
@@ -79,15 +53,6 @@
}
return true;
- }
-}
-
-// Return the comments associated with the node
-List<String*>* Node::get_comments()
-{
- {
- List<String*>* comments = dynamic_cast<List<String*>*>(attrs->get("phc.comments"));
- return comments;
}
}
Modified: trunk/src/generated/MIR.h
==============================================================================
--- trunk/src/generated/MIR.h (original)
+++ trunk/src/generated/MIR.h Sun Apr 6 06:44:03 2008
@@ -90,9 +90,11 @@
class Visitor;
// Node ::= PHP_script | Statement | Class_mod | Member | Signature |
Method_mod | Formal_parameter | Type | Attr_mod | Name_with_default |
Catch | Variable_name | Target | Array_elem | Method_name |
Actual_parameter | Class_name | Identifier | HT_ITERATOR<long>;
-class Node : virtual public Object
+class Node : virtual public IR::Node
{
public:
+ Node();
+public:
virtual void visit(Visitor* visitor) = 0;
virtual void transform_children(Transform* transform) = 0;
public:
@@ -106,21 +108,13 @@
public:
virtual void assert_valid() = 0;
public:
- AttrMap* attrs;
- // Return the line number of the node (or 0 if unknown)
- int get_line_number();
- // Return the filename of the node (or NULL if unknown)
- String* get_filename();
- Node();
void clone_mixin_from(Node* in);
void assert_mixin_valid();
bool is_mixin_equal(Node* in);
- // Return the comments associated with the node
- List<String*>* get_comments();
};
// PHP_script ::= Statement* ;
-class PHP_script : virtual public Node, virtual public IR
+class PHP_script : virtual public Node, virtual public IR::PHP_script
{
public:
PHP_script(List<Statement*>* statements);
Modified: trunk/src/generated_src/ast.tea
==============================================================================
--- trunk/src/generated_src/ast.tea (original)
+++ trunk/src/generated_src/ast.tea Sun Apr 6 06:44:03 2008
@@ -14,7 +14,8 @@
output_dir "src/generated";
prefix "AST";
external class "Object";
-external class "IR";
+external class "IR::Node";
+external class "IR::PHP_script";
use list "List";
use string "String";
use namespace "AST";
@@ -197,35 +198,9 @@
#include "lib/AttrMap.h"
#include "process_ir/IR.h"
-class Node : Object
+class Node : IR::Node
{
public:
- AttrMap* attrs;
-
- // Return the line number of the node (or 0 if unknown)
- int get_line_number()
- {
- Integer* i = dynamic_cast<Integer*>(attrs->get("phc.line_number"));
- if(i != NULL)
- return i->value();
- else
- return 0;
- }
-
- // Return the filename of the node (or NULL if unknown)
- String* get_filename()
- {
- return dynamic_cast<String*>(attrs->get("phc.filename"));
- }
-
- Node()
- {
- // Constructor gets called because all classes inherit from
- // Node virtually; also, because maketea knows Node is
- // abstract, it won't add a constructor itself
- attrs = new AttrMap();
- }
-
void clone_mixin_from(Node* in)
{
attrs->clone_all_from (in->attrs);
@@ -268,8 +243,11 @@
return true;
}
+
};
+class PHP_script : IR::PHP_script {};
+
class Commented_node
{
public:
@@ -289,10 +267,6 @@
return comments;
}
-};
-
-class PHP_script : IR
-{
};
class Signature
Modified: trunk/src/generated_src/hir.tea
==============================================================================
--- trunk/src/generated_src/hir.tea (original)
+++ trunk/src/generated_src/hir.tea Sun Apr 6 06:44:03 2008
@@ -19,7 +19,8 @@
output_dir "src/generated";
prefix "HIR";
external class "Object";
-external class "IR";
+external class "IR::Node";
+external class "IR::PHP_script";
use list "List";
use string "String";
use namespace "HIR";
@@ -201,42 +202,9 @@
#include "lib/AttrMap.h"
#include "process_ir/IR.h"
-class Node : Object
+class Node : IR::Node
{
public:
- AttrMap* attrs;
-
- // Return the line number of the node (or 0 if unknown)
- int get_line_number()
- {
- Integer* i = dynamic_cast<Integer*>(attrs->get("phc.line_number"));
- if(i != NULL)
- return i->value();
- else
- return 0;
- }
-
- // Return the filename of the node. If unknown, use "<unknown>",
- // which is what the interpreter uses.
- // TODO In the future, make sure we always have filenames and
- // line numbers.
- String* get_filename()
- {
- String* result = dynamic_cast<String*>(attrs->get("phc.filename"));
- if (result == NULL)
- result = new String ("<unknown>");
-
- return result;
- }
-
- Node()
- {
- // Constructor gets called because all classes inherit from
- // Node virtually; also, because maketea knows Node is
- // abstract, it won't add a constructor itself
- attrs = new AttrMap();
- }
-
void clone_mixin_from(Node* in)
{
attrs->clone_all_from (in->attrs);
@@ -279,11 +247,10 @@
return true;
}
-};
-class PHP_script : IR
-{
};
+
+class PHP_script : IR::PHP_script {};
class Signature
{
Modified: trunk/src/generated_src/mir.tea
==============================================================================
--- trunk/src/generated_src/mir.tea (original)
+++ trunk/src/generated_src/mir.tea Sun Apr 6 06:44:03 2008
@@ -17,7 +17,8 @@
output_dir "src/generated";
prefix "MIR";
external class "Object";
-external class "IR";
+external class "IR::Node";
+external class "IR::PHP_script";
use list "List";
use string "String";
use namespace "MIR";
@@ -183,35 +184,9 @@
#include "lib/AttrMap.h"
#include "process_ir/IR.h"
-class Node : Object
+class Node : IR::Node
{
public:
- AttrMap* attrs;
-
- // Return the line number of the node (or 0 if unknown)
- int get_line_number()
- {
- Integer* i = dynamic_cast<Integer*>(attrs->get("phc.line_number"));
- if(i != NULL)
- return i->value();
- else
- return 0;
- }
-
- // Return the filename of the node (or NULL if unknown)
- String* get_filename()
- {
- return dynamic_cast<String*>(attrs->get("phc.filename"));
- }
-
- Node()
- {
- // Constructor gets called because all classes inherit from
- // Node virtually; also, because maketea knows Node is
- // abstract, it won't add a constructor itself
- attrs = new AttrMap();
- }
-
void clone_mixin_from(Node* in)
{
attrs->clone_all_from (in->attrs);
@@ -255,17 +230,9 @@
return true;
}
- // Return the comments associated with the node
- List<String*>* get_comments()
- {
- List<String*>* comments = dynamic_cast<List<String*>*>(attrs->get("phc.comments"));
- return comments;
- }
};
-class PHP_script : IR
-{
-};
+class PHP_script : IR::PHP_script {};
class Signature
{
Modified: trunk/src/pass_manager/Fake_pass.h
==============================================================================
--- trunk/src/pass_manager/Fake_pass.h (original)
+++ trunk/src/pass_manager/Fake_pass.h Sun Apr 6 06:44:03 2008
@@ -23,7 +23,7 @@
this->description = description;
}
- void run (IR*, Pass_manager*) {}
+ void run (IR::PHP_script*, Pass_manager*) {}
};
Modified: trunk/src/pass_manager/Pass.h
==============================================================================
--- trunk/src/pass_manager/Pass.h (original)
+++ trunk/src/pass_manager/Pass.h Sun Apr 6 06:44:03 2008
@@ -22,7 +22,7 @@
public:
- virtual void run (IR* in, Pass_manager* pm) = 0;
+ virtual void run (IR::PHP_script* in, Pass_manager* pm) = 0;
virtual void post_process () { }
private:
@@ -36,7 +36,7 @@
// Passes should use this to control their activation
virtual bool pass_is_enabled (Pass_manager* pm) { return true; }
- void run_pass (IR* in, Pass_manager* pm)
+ void run_pass (IR::PHP_script* in, Pass_manager* pm)
{
if (is_enabled (pm))
run (in, pm);
Modified: trunk/src/pass_manager/Pass_manager.cpp
==============================================================================
--- trunk/src/pass_manager/Pass_manager.cpp (original)
+++ trunk/src/pass_manager/Pass_manager.cpp Sun Apr 6 06:44:03 2008
@@ -302,7 +302,7 @@
}
}
-void Pass_manager::dump (IR* in, Pass* pass)
+void Pass_manager::dump (IR::PHP_script* in, Pass* pass)
{
String* name = pass->name;
for (unsigned int i = 0; i < args_info->dump_given; i++)
@@ -357,7 +357,7 @@
}
}
-void Pass_manager::run (IR* in, bool dump)
+void Pass_manager::run (IR::PHP_script* in, bool dump)
{
// AST
for_lci (ast_queue, Pass, p)
@@ -387,7 +387,7 @@
// The pass manager is used to parse and transform small snippets of
// compiler-generated code aswell as the whole file. Set DUMP to false for
// small snippets, and to true for the main program.
-void Pass_manager::run_pass (Pass* pass, IR* in, bool dump)
+void Pass_manager::run_pass (Pass* pass, IR::PHP_script* in, bool dump)
{
assert (pass->name);
@@ -406,13 +406,13 @@
}
/* Run all passes between FROM and TO, inclusive. */
-IR* Pass_manager::run_from (String* from, IR* in, bool dump)
+IR::PHP_script* Pass_manager::run_from (String* from, IR::PHP_script*
in, bool dump)
{
return run_from_until (from, NULL, in, dump);
}
/* Run all passes until TO, inclusive. */
-IR* Pass_manager::run_until (String* to, IR* in, bool dump)
+IR::PHP_script* Pass_manager::run_until (String* to, IR::PHP_script*
in, bool dump)
{
return run_from_until (NULL, to, in, dump);
}
@@ -420,7 +420,7 @@
/* Run all passes between FROM and TO, inclusive. */
-IR* Pass_manager::run_from_until (String* from, String* to, IR* in,
bool dump)
+IR::PHP_script* Pass_manager::run_from_until (String* from, String*
to, IR::PHP_script* in, bool dump)
{
bool exec = false;
for_lci (queues, List<Pass*>, q)
Modified: trunk/src/pass_manager/Pass_manager.h
==============================================================================
--- trunk/src/pass_manager/Pass_manager.h (original)
+++ trunk/src/pass_manager/Pass_manager.h Sun Apr 6 06:44:03 2008
@@ -15,7 +15,7 @@
#include "ltdl.h"
class Pass;
-class IR;
+class IR::PHP_script;
class Pass_manager
{
@@ -70,17 +70,17 @@
Pass* get_pass_named (String* name);
// Run (returns passed IR, or new IR if lowered
- IR* run_from (String* from, IR* in, bool dump = false);
- IR* run_from_until (String* from, String* to, IR* in, bool dump = false);
- IR* run_until (String* to, IR* in, bool dump = false);
+ IR::PHP_script* run_from (String* from, IR::PHP_script* in, bool dump
= false);
+ IR::PHP_script* run_from_until (String* from, String* to,
IR::PHP_script* in, bool dump = false);
+ IR::PHP_script* run_until (String* to, IR::PHP_script* in, bool dump
= false);
- void run (IR* in, bool dump = false);
- void run_pass (Pass* pass, IR* in, bool dump = false);
+ void run (IR::PHP_script* in, bool dump = false);
+ void run_pass (Pass* pass, IR::PHP_script* in, bool dump = false);
void post_process ();
void list_passes ();
- void dump (IR* in, Pass* pass);
+ void dump (IR::PHP_script* in, Pass* pass);
void maybe_enable_debug (Pass* pass);
protected:
Modified: trunk/src/pass_manager/Plugin_pass.cpp
==============================================================================
--- trunk/src/pass_manager/Plugin_pass.cpp (original)
+++ trunk/src/pass_manager/Plugin_pass.cpp Sun Apr 6 06:44:03 2008
@@ -19,7 +19,7 @@
this->option = option;
}
-void Plugin_pass::run (IR* in, Pass_manager* pm)
+void Plugin_pass::run (IR::PHP_script* in, Pass_manager* pm)
{
/* The ltdl interface uses C, so overloading on type doesnt work. We must
* use different names instead. */
Modified: trunk/src/pass_manager/Plugin_pass.h
==============================================================================
--- trunk/src/pass_manager/Plugin_pass.h (original)
+++ trunk/src/pass_manager/Plugin_pass.h Sun Apr 6 06:44:03 2008
@@ -17,7 +17,7 @@
public:
Plugin_pass (String* name, lt_dlhandle handle, Pass_manager* pm,
String* option);
- void run (IR* in, Pass_manager* pm);
+ void run (IR::PHP_script* in, Pass_manager* pm);
void post_process ();
};
Modified: trunk/src/pass_manager/Transform_pass.h
==============================================================================
--- trunk/src/pass_manager/Transform_pass.h (original)
+++ trunk/src/pass_manager/Transform_pass.h Sun Apr 6 06:44:03 2008
@@ -46,7 +46,7 @@
mir_transform = NULL;
}
- void run (IR* in, Pass_manager* pm)
+ void run (IR::PHP_script* in, Pass_manager* pm)
{
if (ast_transform)
in->transform_children (ast_transform);
Modified: trunk/src/pass_manager/Visitor_pass.h
==============================================================================
--- trunk/src/pass_manager/Visitor_pass.h (original)
+++ trunk/src/pass_manager/Visitor_pass.h Sun Apr 6 06:44:03 2008
@@ -49,7 +49,7 @@
- void run (IR* in, Pass_manager* pm)
+ void run (IR::PHP_script* in, Pass_manager* pm)
{
if (ast_visitor)
in->visit (ast_visitor);
Modified: trunk/src/phc.cpp
==============================================================================
--- trunk/src/phc.cpp (original)
+++ trunk/src/phc.cpp Sun Apr 6 06:44:03 2008
@@ -84,7 +84,7 @@
* Startup
*/
- IR* ir = NULL;
+ IR::PHP_script* ir = NULL;
// Start the embedded interpreter
PHP::startup_php ();
Modified: trunk/src/process_ast/Invalid_check.cpp
==============================================================================
--- trunk/src/process_ast/Invalid_check.cpp (original)
+++ trunk/src/process_ast/Invalid_check.cpp Sun Apr 6 06:44:03 2008
@@ -12,7 +12,7 @@
using namespace AST;
-void check (IR* in, bool use_ice)
+void check (IR::PHP_script* in, bool use_ice)
{
in->assert_valid();
@@ -47,7 +47,7 @@
-void Invalid_check::run (IR* in, Pass_manager* pm)
+void Invalid_check::run (IR::PHP_script* in, Pass_manager* pm)
{
in->visit(this);
// Indicate that after this pass, ICEs should be used.
Modified: trunk/src/process_ast/Invalid_check.h
==============================================================================
--- trunk/src/process_ast/Invalid_check.h (original)
+++ trunk/src/process_ast/Invalid_check.h Sun Apr 6 06:44:03 2008
@@ -18,7 +18,7 @@
// Returns true if IN is not allowed be on the RHS of a reference assignment.
bool is_ref_literal (AST::Expr* in);
bool is_ref_literal (HIR::Expr* in); // todo avoid duplication
-void check (IR* in, bool use_ice);
+void check (IR::PHP_script* in, bool use_ice);
class Invalid_check : public AST::Visitor, public Pass
{
@@ -30,7 +30,7 @@
// decide the error based on whether USE_ICE is set
void error (const char* message, AST::Node* node);
- void run (IR*, Pass_manager*);
+ void run (IR::PHP_script*, Pass_manager*);
void pre_statement (AST::Statement* in);
void pre_assignment (AST::Assignment* in);
Modified: trunk/src/process_ast/Pretty_print.h
==============================================================================
--- trunk/src/process_ast/Pretty_print.h (original)
+++ trunk/src/process_ast/Pretty_print.h Sun Apr 6 06:44:03 2008
@@ -24,7 +24,7 @@
this->description = new String ("Print the formatted program source");
}
- void run (IR* in, Pass_manager* pm)
+ void run (IR::PHP_script* in, Pass_manager* pm)
{
in->visit(new AST_unparser());
set_enabled (false);
Modified: trunk/src/process_ast/Process_includes.h
==============================================================================
--- trunk/src/process_ast/Process_includes.h (original)
+++ trunk/src/process_ast/Process_includes.h Sun Apr 6 06:44:03 2008
@@ -26,7 +26,7 @@
String* pass_name;
Pass_manager* pm;
- void run (IR* in, Pass_manager* pm)
+ void run (IR::PHP_script* in, Pass_manager* pm)
{
in->transform_children(this);
}
Modified: trunk/src/process_ir/General.cpp
==============================================================================
--- trunk/src/process_ir/General.cpp (original)
+++ trunk/src/process_ir/General.cpp Sun Apr 6 06:44:03 2008
@@ -19,7 +19,7 @@
assert (pm->has_pass_named (name));
- IR* new_script = pm->run_from_until (s("hir"), name, script);
+ IR::PHP_script* new_script = pm->run_from_until (s("hir"), name, script);
// TODO the typing is here is quite poor
return dynamic_cast<HIR::PHP_script*>(new_script)->statements;
@@ -36,7 +36,7 @@
assert (pm->has_pass_named (name));
- IR* new_script = pm->run_from_until (s("ast"), name, script);
+ IR::PHP_script* new_script = pm->run_from_until (s("ast"), name, script);
// TODO the typing is here is quite poor
return dynamic_cast<AST::PHP_script*>(new_script)->statements;
Modified: trunk/src/process_ir/IR.cpp
==============================================================================
--- trunk/src/process_ir/IR.cpp (original)
+++ trunk/src/process_ir/IR.cpp Sun Apr 6 06:44:03 2008
@@ -11,8 +11,9 @@
#include "hir_to_mir/HIR_to_MIR.h"
#include "ast_to_hir/AST_to_HIR.h"
+using namespace IR;
-void IR::assert_valid()
+void PHP_script::assert_valid()
{
if(is_AST())
as_AST()->assert_valid();
@@ -25,22 +26,22 @@
// VISIT
-void IR::visit(AST::Visitor* ast_visitor)
+void PHP_script::visit(AST::Visitor* ast_visitor)
{
as_AST()->visit(ast_visitor);
}
-void IR::visit(HIR::Visitor* hir_visitor)
+void PHP_script::visit(HIR::Visitor* hir_visitor)
{
as_HIR()->visit(hir_visitor);
}
-void IR::visit(MIR::Visitor* mir_visitor)
+void PHP_script::visit(MIR::Visitor* mir_visitor)
{
as_MIR()->visit(mir_visitor);
}
-void IR::visit(AST::Visitor* ast_visitor, HIR::Visitor* hir_visitor,
MIR::Visitor* mir_visitor)
+void PHP_script::visit(AST::Visitor* ast_visitor, HIR::Visitor*
hir_visitor, MIR::Visitor* mir_visitor)
{
if(is_AST())
visit(ast_visitor);
@@ -53,22 +54,22 @@
// TRANSFORM
-void IR::transform_children(AST::Transform* ast_transform)
+void PHP_script::transform_children(AST::Transform* ast_transform)
{
as_AST()->transform_children(ast_transform);
}
-void IR::transform_children(HIR::Transform* hir_transform)
+void PHP_script::transform_children(HIR::Transform* hir_transform)
{
as_HIR()->transform_children(hir_transform);
}
-void IR::transform_children(MIR::Transform* mir_transform)
+void PHP_script::transform_children(MIR::Transform* mir_transform)
{
as_MIR()->transform_children(mir_transform);
}
-void IR::transform_children(AST::Transform* ast_transform,
HIR::Transform* hir_transform, MIR::Transform* mir_transform)
+void PHP_script::transform_children(AST::Transform* ast_transform,
HIR::Transform* hir_transform, MIR::Transform* mir_transform)
{
if(is_AST())
transform_children(ast_transform);
@@ -80,30 +81,30 @@
-bool IR::is_AST()
+bool PHP_script::is_AST()
{
return dynamic_cast<AST::PHP_script*>(this) != NULL;
}
-bool IR::is_HIR()
+bool PHP_script::is_HIR()
{
return dynamic_cast<HIR::PHP_script*>(this) != NULL;
}
-bool IR::is_MIR()
+bool PHP_script::is_MIR()
{
return dynamic_cast<MIR::PHP_script*>(this) != NULL;
}
-AST::PHP_script* IR::as_AST()
+AST::PHP_script* PHP_script::as_AST()
{
AST::PHP_script* ast = dynamic_cast<AST::PHP_script*>(this);
assert(ast != NULL);
return ast;
}
-HIR::PHP_script* IR::as_HIR()
+HIR::PHP_script* PHP_script::as_HIR()
{
HIR::PHP_script* hir = dynamic_cast<HIR::PHP_script*>(this);
assert(hir != NULL);
@@ -111,7 +112,7 @@
}
-MIR::PHP_script* IR::as_MIR()
+MIR::PHP_script* PHP_script::as_MIR()
{
MIR::PHP_script* mir = dynamic_cast<MIR::PHP_script*>(this);
assert(mir != NULL);
@@ -119,7 +120,7 @@
}
-IR* IR::fold_lower ()
+PHP_script* PHP_script::fold_lower ()
{
if (is_AST ())
return (new AST_to_HIR ())->fold_php_script (as_AST ());
Modified: trunk/src/process_ir/IR.h
==============================================================================
--- trunk/src/process_ir/IR.h (original)
+++ trunk/src/process_ir/IR.h Sun Apr 6 06:44:03 2008
@@ -8,6 +8,12 @@
#ifndef PHC_IR_H
#define PHC_IR_H
+#include "lib/Object.h"
+#include "lib/AttrMap.h"
+#include "lib/Integer.h"
+#include "lib/String.h"
+#include <string>
+
namespace AST
{
class PHP_script;
@@ -29,7 +35,50 @@
class Transform;
}
-class IR
+namespace IR
+{
+
+class Node : public Object
+{
+public:
+ AttrMap* attrs;
+
+ // Return the line number of the node (or 0 if unknown)
+ int get_line_number()
+ {
+ Integer* i = dynamic_cast<Integer*>(attrs->get("phc.line_number"));
+ if(i != NULL)
+ return i->value();
+ else
+ return 0;
+ }
+
+ // Return the filename of the node. If unknown, use "<unknown>",
+ // which is what the interpreter uses.
+ // TODO In the future, make sure we always have filenames and
+ // line numbers.
+ String* get_filename()
+ {
+ String* result = dynamic_cast<String*>(attrs->get("phc.filename"));
+ if (result == NULL)
+ result = new String ("<unknown>");
+
+ return result;
+ }
+
+ Node()
+ {
+ // Constructor gets called because all classes inherit from
+ // Node virtually; also, because maketea knows Node is
+ // abstract, it won't add a constructor itself
+ attrs = new AttrMap();
+ }
+
+ virtual ~Node() {}
+};
+
+
+class PHP_script
{
// Operations that are defined over all IRs
public:
@@ -61,11 +110,13 @@
virtual AST::PHP_script* as_AST();
virtual HIR::PHP_script* as_HIR();
virtual MIR::PHP_script* as_MIR();
- virtual IR* fold_lower ();
+ virtual PHP_script* fold_lower ();
// Make sure IR is virtual
public:
- virtual ~IR() {}
+ virtual ~PHP_script() {}
};
+
+}
#endif // PHC_IR_H
Modified: trunk/src/process_mir/Obfuscate.h
==============================================================================
--- trunk/src/process_mir/Obfuscate.h (original)
+++ trunk/src/process_mir/Obfuscate.h Sun Apr 6 06:44:03 2008
@@ -21,7 +21,7 @@
description = new String ("Print program with obfuscated control-flow");
}
- void run (IR* in, Pass_manager* pm)
+ void run (IR::PHP_script* in, Pass_manager* pm)
{
AST::PHP_script* ast = in->as_AST()->clone ();
ast->transform_children (new Foreach_uppering);
More information about the phc-internals
mailing list