Skip to content

Commit

Permalink
This looks like a large commit, but conceptually it is quite simple: …
Browse files Browse the repository at this point in the history
…maketea no

longer generates prefixes, so that AST::AST_node is now called AST::Node. 

Also fixed a (separate) bug in the XML parser/unparser, which didn't deal with
CASTs properly. 

Did not run all tests to their completion, but BasicParseTest and XML_roundtrip
are working, and I suspect that removing prefixes cannot introduce any subtle
bugs (though I may be wrong :)
  • Loading branch information
edsko committed Dec 1, 2007
1 parent b13fed5 commit a848c99
Show file tree
Hide file tree
Showing 133 changed files with 14,652 additions and 14,428 deletions.
2 changes: 1 addition & 1 deletion doc/manual/code/count_statements.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <AST.h>

extern "C" void process_ast(AST_php_script* php_script)
extern "C" void process_ast(PHP_script* php_script)
{
printf("%d statement(s) found\n", php_script->statements->size());
}
6 changes: 3 additions & 3 deletions doc/manual/code/foobar.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include "AST_visitor.h"

class Rename_foo_to_bar : public AST_visitor
class Rename_foo_to_bar : public Visitor
{
void pre_method_name(Token_method_name* in)
void pre_method_name(METHOD_NAME* in)
{
if(*in->value == "foo")
in->value = new String("bar");
}
};

extern "C" void process_ast(AST_php_script* php_script)
extern "C" void process_ast(PHP_script* php_script)
{
Rename_foo_to_bar f2b;
php_script->visit(&f2b);
Expand Down
2 changes: 1 addition & 1 deletion doc/manual/code/minimal.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <AST.h>

extern "C" void process_ast(AST_php_script* php_script)
extern "C" void process_ast(PHP_script* php_script)
{
cout << "Hello world (I'm a phc plugin!)" << endl;
}
104 changes: 104 additions & 0 deletions misc/convert_AST_names.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# From phc revision 907 onwards, name prefixes have been removed on classes.
# For example, "AST::AST_node" is now called "AST::node" (namespaces were
# introduced earlier). This script can be used to update 'legacy' code.
#
# Use
#
# perl -n -i- convert_AST_names foo.cpp
#
# To convert 'foo.cpp' (a backup 'foo.cpp-' will be created)
s/AST_node(?!\.)/Node/g;
s/AST_php_script(?!\.)/PHP_script/g;
s/AST_class_mod(?!\.)/Class_mod/g;
s/AST_signature(?!\.)/Signature/g;
s/AST_method_mod(?!\.)/Method_mod/g;
s/AST_formal_parameter(?!\.)/Formal_parameter/g;
s/AST_type(?!\.)/Type/g;
s/AST_attr_mod(?!\.)/Attr_mod/g;
s/AST_name_with_default(?!\.)/Name_with_default/g;
s/AST_directive(?!\.)/Directive/g;
s/AST_list_element(?!\.)/List_element/g;
s/AST_variable_name(?!\.)/Variable_name/g;
s/AST_target(?!\.)/Target/g;
s/AST_array_elem(?!\.)/Array_elem/g;
s/AST_method_name(?!\.)/Method_name/g;
s/AST_actual_parameter(?!\.)/Actual_parameter/g;
s/AST_class_name(?!\.)/Class_name/g;
s/AST_commented_node(?!\.)/Commented_node/g;
s/AST_identifier(?!\.)/Identifier/g;
s/AST_statement(?!\.)/Statement/g;
s/AST_member(?!\.)/Member/g;
s/AST_switch_case(?!\.)/Switch_case/g;
s/AST_catch(?!\.)/Catch/g;
s/AST_expr(?!\.)/Expr/g;
s/AST_nested_list_elements(?!\.)/Nested_list_elements/g;
s/AST_reflection(?!\.)/Reflection/g;
s/Token_class_name(?!\.)/CLASS_NAME/g;
s/Token_interface_name(?!\.)/INTERFACE_NAME/g;
s/Token_method_name(?!\.)/METHOD_NAME/g;
s/Token_variable_name(?!\.)/VARIABLE_NAME/g;
s/Token_directive_name(?!\.)/DIRECTIVE_NAME/g;
s/Token_label_name(?!\.)/LABEL_NAME/g;
s/Token_ht_iterator(?!\.)/HT_ITERATOR/g;
s/Token_op(?!\.)/OP/g;
s/Token_cast(?!\.)/CAST/g;
s/Token_constant_name(?!\.)/CONSTANT_NAME/g;
s/AST_class_def(?!\.)/Class_def/g;
s/AST_interface_def(?!\.)/Interface_def/g;
s/AST_method(?!\.)/Method/g;
s/AST_attribute(?!\.)/Attribute/g;
s/AST_if(?!\.)/If/g;
s/AST_while(?!\.)/While/g;
s/AST_do(?!\.)/Do/g;
s/AST_for(?!\.)/For/g;
s/AST_foreach(?!\.)/Foreach/g;
s/AST_switch(?!\.)/Switch/g;
s/AST_break(?!\.)/Break/g;
s/AST_continue(?!\.)/Continue/g;
s/AST_return(?!\.)/Return/g;
s/AST_static_declaration(?!\.)/Static_declaration/g;
s/AST_global(?!\.)/Global/g;
s/AST_declare(?!\.)/Declare/g;
s/AST_try(?!\.)/Try/g;
s/AST_throw(?!\.)/Throw/g;
s/AST_eval_expr(?!\.)/Eval_expr/g;
s/AST_nop(?!\.)/Nop/g;
s/AST_branch(?!\.)/Branch/g;
s/AST_goto(?!\.)/Goto/g;
s/AST_label(?!\.)/Label/g;
s/AST_foreach_reset(?!\.)/Foreach_reset/g;
s/AST_foreach_next(?!\.)/Foreach_next/g;
s/AST_foreach_end(?!\.)/Foreach_end/g;
s/AST_foreach_has_key(?!\.)/Foreach_has_key/g;
s/AST_foreach_get_key(?!\.)/Foreach_get_key/g;
s/AST_foreach_get_data(?!\.)/Foreach_get_data/g;
s/AST_literal(?!\.)/Literal/g;
s/AST_assignment(?!\.)/Assignment/g;
s/AST_op_assignment(?!\.)/Op_assignment/g;
s/AST_list_assignment(?!\.)/List_assignment/g;
s/AST_cast(?!\.)/Cast/g;
s/AST_unary_op(?!\.)/Unary_op/g;
s/AST_bin_op(?!\.)/Bin_op/g;
s/AST_conditional_expr(?!\.)/Conditional_expr/g;
s/AST_ignore_errors(?!\.)/Ignore_errors/g;
s/AST_constant(?!\.)/Constant/g;
s/AST_instanceof(?!\.)/Instanceof/g;
s/AST_variable(?!\.)/Variable/g;
s/AST_pre_op(?!\.)/Pre_op/g;
s/AST_post_op(?!\.)/Post_op/g;
s/AST_array(?!\.)/Array/g;
s/AST_method_invocation(?!\.)/Method_invocation/g;
s/AST_new(?!\.)/New/g;
s/Token_int(?!\.)/INT/g;
s/Token_real(?!\.)/REAL/g;
s/Token_string(?!\.)/STRING/g;
s/Token_bool(?!\.)/BOOL/g;
s/Token_null(?!\.)/NIL/g;
s/AST_transform(?!\.)/Transform/g;
s/AST_visitor(?!\.)/Visitor/g;
s/AST_fold(?!\.)/Fold/g;
s/AST_factory(?!\.)/Node_factory/g;
s/pre_null/pre_nil/g;
s/post_null/post_nil/g;
s/children_null/children_nil/g;
print;
80 changes: 80 additions & 0 deletions misc/convert_HIR_names.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# From phc revision 907 onwards, name prefixes have been removed on classes.
# For example, "HIR::HIR_node" is now called "HIR::node" (namespaces were
# introduced earlier). This script can be used to update 'legacy' code.
#
# Use
#
# perl -n -i- convert_HIR_names foo.cpp
#
# To convert 'foo.cpp' (a backup 'foo.cpp-' will be created)
s/HIR_node(?!\.)/Node/g;
s/HIR_php_script(?!\.)/PHP_script/g;
s/HIR_statement(?!\.)/Statement/g;
s/HIR_class_mod(?!\.)/Class_mod/g;
s/HIR_member(?!\.)/Member/g;
s/HIR_signature(?!\.)/Signature/g;
s/HIR_method_mod(?!\.)/Method_mod/g;
s/HIR_formal_parameter(?!\.)/Formal_parameter/g;
s/HIR_type(?!\.)/Type/g;
s/HIR_attr_mod(?!\.)/Attr_mod/g;
s/HIR_name_with_default(?!\.)/Name_with_default/g;
s/HIR_catch(?!\.)/Catch/g;
s/HIR_variable_name(?!\.)/Variable_name/g;
s/HIR_target(?!\.)/Target/g;
s/HIR_array_elem(?!\.)/Array_elem/g;
s/HIR_method_name(?!\.)/Method_name/g;
s/HIR_actual_parameter(?!\.)/Actual_parameter/g;
s/HIR_class_name(?!\.)/Class_name/g;
s/HIR_identifier(?!\.)/Identifier/g;
s/HIR_class_def(?!\.)/Class_def/g;
s/HIR_interface_def(?!\.)/Interface_def/g;
s/HIR_method(?!\.)/Method/g;
s/HIR_attribute(?!\.)/Attribute/g;
s/HIR_return(?!\.)/Return/g;
s/HIR_static_declaration(?!\.)/Static_declaration/g;
s/HIR_global(?!\.)/Global/g;
s/HIR_try(?!\.)/Try/g;
s/HIR_throw(?!\.)/Throw/g;
s/HIR_eval_expr(?!\.)/Eval_expr/g;
s/HIR_branch(?!\.)/Branch/g;
s/HIR_goto(?!\.)/Goto/g;
s/HIR_label(?!\.)/Label/g;
s/HIR_foreach_reset(?!\.)/Foreach_reset/g;
s/HIR_foreach_next(?!\.)/Foreach_next/g;
s/HIR_foreach_end(?!\.)/Foreach_end/g;
s/HIR_expr(?!\.)/Expr/g;
s/HIR_reflection(?!\.)/Reflection/g;
s/Token_class_name(?!\.)/CLASS_NAME/g;
s/Token_interface_name(?!\.)/INTERFACE_NAME/g;
s/Token_method_name(?!\.)/METHOD_NAME/g;
s/Token_variable_name(?!\.)/VARIABLE_NAME/g;
s/Token_label_name(?!\.)/LABEL_NAME/g;
s/Token_ht_iterator(?!\.)/HT_ITERATOR/g;
s/Token_cast(?!\.)/CAST/g;
s/Token_op(?!\.)/OP/g;
s/Token_constant_name(?!\.)/CONSTANT_NAME/g;
s/HIR_foreach_has_key(?!\.)/Foreach_has_key/g;
s/HIR_foreach_get_key(?!\.)/Foreach_get_key/g;
s/HIR_foreach_get_data(?!\.)/Foreach_get_data/g;
s/HIR_literal(?!\.)/Literal/g;
s/HIR_assignment(?!\.)/Assignment/g;
s/HIR_cast(?!\.)/Cast/g;
s/HIR_unary_op(?!\.)/Unary_op/g;
s/HIR_bin_op(?!\.)/Bin_op/g;
s/HIR_constant(?!\.)/Constant/g;
s/HIR_instanceof(?!\.)/Instanceof/g;
s/HIR_variable(?!\.)/Variable/g;
s/HIR_pre_op(?!\.)/Pre_op/g;
s/HIR_array(?!\.)/Array/g;
s/HIR_method_invocation(?!\.)/Method_invocation/g;
s/HIR_new(?!\.)/New/g;
s/Token_int(?!\.)/INT/g;
s/Token_real(?!\.)/REAL/g;
s/Token_string(?!\.)/STRING/g;
s/Token_bool(?!\.)/BOOL/g;
s/Token_null(?!\.)/NIL/g;
s/HIR_transform(?!\.)/Transform/g;
s/HIR_visitor(?!\.)/Visitor/g;
s/HIR_fold(?!\.)/Fold/g;
s/HIR_factory(?!\.)/Node_factory/g;
print;
4 changes: 2 additions & 2 deletions plugins/tests/Collect_all_pointers.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
#include "AST_visitor.h"


class Collect_all_pointers : virtual public AST::AST_visitor
class Collect_all_pointers : virtual public AST::Visitor
{
public:
list<Object*> all_pointers;
set<Object*> unique_pointers;

public:
void pre_node(AST::AST_node* in)
void pre_node(AST::Node* in)
{
all_pointers.push_back(in);
unique_pointers.insert(in);
Expand Down
62 changes: 31 additions & 31 deletions plugins/tests/canonical_unparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

using namespace AST;

class Clear_user_syntax : public virtual AST_visitor
class Clear_user_syntax : public virtual Visitor
{
void pre_node (AST_node* in)
void pre_node (Node* in)
{
// Remove all the unparser attributes. is_singly_quoted must either be
// escaped or removed, however.
Expand All @@ -29,23 +29,23 @@ class Clear_user_syntax : public virtual AST_visitor
}
}

#define REMOVE_SOURCE_REP(TYPE) \
void pre##TYPE (Token_##TYPE* in) { in->source_rep = NULL; }
#define REMOVE_SOURCE_REP(TYPE_V, TYPE_C) \
void pre##TYPE_V (TYPE_C* in) { in->source_rep = NULL; }

/* Not all tokens have source_reps. Those that do should still be unparsable
* if they're set to NULL. */
REMOVE_SOURCE_REP (bool);
REMOVE_SOURCE_REP (cast);
REMOVE_SOURCE_REP (bool, BOOL);
REMOVE_SOURCE_REP (cast, CAST);
// REMOVE_SOURCE_REP (class_name); REMOVE_SOURCE_REP (constant_name);
// REMOVE_SOURCE_REP (directive_name);
REMOVE_SOURCE_REP (int);
REMOVE_SOURCE_REP (int, INT);
// REMOVE_SOURCE_REP (interface_name);
// REMOVE_SOURCE_REP (label_name);
// REMOVE_SOURCE_REP (method_name);
REMOVE_SOURCE_REP (null);
REMOVE_SOURCE_REP (nil, NIL);
// REMOVE_SOURCE_REP (op);
REMOVE_SOURCE_REP (real);
REMOVE_SOURCE_REP (string);
REMOVE_SOURCE_REP (real, REAL);
REMOVE_SOURCE_REP (string, STRING);
// REMOVE_SOURCE_REP (variable_name);

#undef REMOVE_SOURCE_REP
Expand All @@ -59,7 +59,7 @@ class Canonical_unparser : public virtual AST_unparser { bool bracket;

// clear all the users syntax so the PHP_unparser wont print it
// out
void pre_php_script (AST_php_script* in)
void pre_php_script (PHP_script* in)
{
Clear_user_syntax cus;
in->visit(&cus);
Expand All @@ -69,33 +69,33 @@ class Canonical_unparser : public virtual AST_unparser { bool bracket;


// bracket all allowed expressions
#define WRAP(TYPE) \
void pre_##TYPE (AST_##TYPE* in) { if (bracket) echo ("("); } \
void post_##TYPE (AST_##TYPE* in) { if (bracket) echo (")"); }
#define WRAP(TYPE_V, TYPE_C) \
void pre_##TYPE_V (TYPE_C* in) { if (bracket) echo ("("); } \
void post_##TYPE_V (TYPE_C* in) { if (bracket) echo (")"); }

// within some constructs, bracketing leads to a parse error
#define EXCEPT_IN(TYPE) \
void pre_##TYPE (AST_##TYPE* in) { bracket = false; } \
void post_##TYPE (AST_##TYPE* in) { bracket = true; }
#define EXCEPT_IN(TYPE_V, TYPE_C) \
void pre_##TYPE_V (TYPE_C* in) { bracket = false; } \
void post_##TYPE_V (TYPE_C* in) { bracket = true; }

WRAP (unary_op)
WRAP (unary_op, Unary_op)
// bin_op handled separately
WRAP (conditional_expr)
WRAP (constant)
WRAP (pre_op)
WRAP (post_op)
WRAP (array)
WRAP (literal)

EXCEPT_IN (attribute)
EXCEPT_IN (static_declaration)
EXCEPT_IN (formal_parameter)
EXCEPT_IN (directive)
WRAP (conditional_expr, Conditional_expr)
WRAP (constant, Constant)
WRAP (pre_op, Pre_op)
WRAP (post_op, Post_op)
WRAP (array, Array)
WRAP (literal, Literal)

EXCEPT_IN (attribute, Attribute)
EXCEPT_IN (static_declaration, Static_declaration)
EXCEPT_IN (formal_parameter, Formal_parameter)
EXCEPT_IN (directive, Directive)

#undef WRAP
#undef EXCEPT_IN

void children_bin_op(AST_bin_op* in)
void children_bin_op(Bin_op* in)
{
if (*in->op->value != ",") echo("(");
AST_unparser::children_bin_op (in);
Expand All @@ -108,7 +108,7 @@ extern "C" void load (Pass_manager* pm, Plugin_pass* pass)
pm->add_after_named_pass (pass, "ast");
}

extern "C" void run (AST_php_script* in, Pass_manager* pm)
extern "C" void run (PHP_script* in, Pass_manager* pm)
{
in->clone()->visit (new Canonical_unparser ());
}
4 changes: 2 additions & 2 deletions plugins/tests/cloning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extern "C" void load (Pass_manager* pm, Plugin_pass* pass)
pm->add_after_each_pass (pass);
}

extern "C" void run (AST_php_script* in, Pass_manager* pm)
extern "C" void run (PHP_script* in, Pass_manager* pm)
{
is_run = true;

Expand All @@ -28,7 +28,7 @@ extern "C" void run (AST_php_script* in, Pass_manager* pm)
in->visit(&orig_cap);

// make a duplicate
AST_php_script* dup_script = in->clone();
PHP_script* dup_script = in->clone();
Collect_all_pointers dup_cap;
dup_script->visit(&dup_cap);

Expand Down
Loading

0 comments on commit a848c99

Please sign in to comment.