[phc-internals] [phc commit] r1151 - in trunk/src: ast_to_hir
generated generated_src hir_to_mir process_hir
codesite-noreply at google.com
codesite-noreply at google.com
Mon Apr 7 13:04:46 IST 2008
Author: paul.biggar
Date: Mon Apr 7 05:04:05 2008
New Revision: 1151
Modified:
trunk/src/ast_to_hir/AST_to_HIR.h
trunk/src/generated/HIR.cpp
trunk/src/generated/HIR.h
trunk/src/generated/HIR_factory.cpp
trunk/src/generated/HIR_fold.h
trunk/src/generated/HIR_transform.cpp
trunk/src/generated/HIR_visitor.cpp
trunk/src/generated_src/hir.tea
trunk/src/hir_to_mir/Lower_control_flow.cpp
trunk/src/process_hir/HIR_to_AST.h
Log:
Change the HIR defintion of foreach, to take a VARIABLE_NAME instead of
an Expr.
Modified: trunk/src/ast_to_hir/AST_to_HIR.h
==============================================================================
--- trunk/src/ast_to_hir/AST_to_HIR.h (original)
+++ trunk/src/ast_to_hir/AST_to_HIR.h Mon Apr 7 05:04:05 2008
@@ -365,7 +365,7 @@
HIR::Foreach* fold_impl_foreach (AST::Foreach* orig, HIR::Expr* expr,
HIR::Variable* key, bool is_ref, HIR::Variable* val,
List<HIR::Statement*>* statements)
{
HIR::Foreach* result;
- result = new HIR::Foreach(expr, key, is_ref, val, statements);
+ result = new HIR::Foreach(expr_to_var_name (expr), key, is_ref, val, statements);
copy_attrs (result, orig);
return result;
}
Modified: trunk/src/generated/HIR.cpp
==============================================================================
--- trunk/src/generated/HIR.cpp (original)
+++ trunk/src/generated/HIR.cpp Mon Apr 7 05:04:05 2008
@@ -2699,9 +2699,9 @@
Node::assert_mixin_valid();
}
-Foreach::Foreach(Expr* expr, Variable* key, bool is_ref, Variable*
val, List<Statement*>* statements)
+Foreach::Foreach(VARIABLE_NAME* variable_name, Variable* key, bool
is_ref, Variable* val, List<Statement*>* statements)
{
- this->expr = expr;
+ this->variable_name = variable_name;
this->key = key;
this->is_ref = is_ref;
this->val = val;
@@ -2710,7 +2710,7 @@
Foreach::Foreach()
{
- this->expr = 0;
+ this->variable_name = 0;
this->key = 0;
this->is_ref = 0;
this->val = 0;
@@ -2742,12 +2742,12 @@
Foreach* that = dynamic_cast<Foreach*>(in);
if(that == NULL) return false;
- if(this->expr == NULL)
+ if(this->variable_name == NULL)
{
- if(that->expr != NULL && !that->expr->match(this->expr))
+ if(that->variable_name != NULL && !that->variable_name->match(this->variable_name))
return false;
}
- else if(!this->expr->match(that->expr))
+ else if(!this->variable_name->match(that->variable_name))
return false;
if(this->key == NULL)
@@ -2795,12 +2795,12 @@
Foreach* that = dynamic_cast<Foreach*>(in);
if(that == NULL) return false;
- if(this->expr == NULL || that->expr == NULL)
+ if(this->variable_name == NULL || that->variable_name == NULL)
{
- if(this->expr != NULL || that->expr != NULL)
+ if(this->variable_name != NULL || that->variable_name != NULL)
return false;
}
- else if(!this->expr->equals(that->expr))
+ else if(!this->variable_name->equals(that->variable_name))
return false;
if(this->key == NULL || that->key == NULL)
@@ -2853,7 +2853,7 @@
Foreach* Foreach::clone()
{
- Expr* expr = this->expr ? this->expr->clone() : NULL;
+ VARIABLE_NAME* variable_name = this->variable_name ?
this->variable_name->clone() : NULL;
Variable* key = this->key ? this->key->clone() : NULL;
bool is_ref = this->is_ref;
Variable* val = this->val ? this->val->clone() : NULL;
@@ -2865,15 +2865,15 @@
for(i = this->statements->begin(); i != this->statements->end(); i++)
statements->push_back(*i ? (*i)->clone() : NULL);
}
- Foreach* clone = new Foreach(expr, key, is_ref, val, statements);
+ Foreach* clone = new Foreach(variable_name, key, is_ref, val, statements);
clone->Node::clone_mixin_from(this);
return clone;
}
void Foreach::assert_valid()
{
- assert(expr != NULL);
- expr->assert_valid();
+ assert(variable_name != NULL);
+ variable_name->assert_valid();
if(key != NULL) key->assert_valid();
assert(val != NULL);
val->assert_valid();
Modified: trunk/src/generated/HIR.h
==============================================================================
--- trunk/src/generated/HIR.h (original)
+++ trunk/src/generated/HIR.h Mon Apr 7 05:04:05 2008
@@ -801,15 +801,15 @@
virtual void assert_valid();
};
-// Foreach ::= Expr key:Variable? is_ref:"&" val:Variable Statement* ;
+// Foreach ::= VARIABLE_NAME key:Variable? is_ref:"&" val:Variable Statement* ;
class Foreach : virtual public Statement
{
public:
- Foreach(Expr* expr, Variable* key, bool is_ref, Variable* val,
List<Statement*>* statements);
+ Foreach(VARIABLE_NAME* variable_name, Variable* key, bool is_ref,
Variable* val, List<Statement*>* statements);
protected:
Foreach();
public:
- Expr* expr;
+ VARIABLE_NAME* variable_name;
Variable* key;
bool is_ref;
Variable* val;
Modified: trunk/src/generated/HIR_factory.cpp
==============================================================================
--- trunk/src/generated/HIR_factory.cpp (original)
+++ trunk/src/generated/HIR_factory.cpp Mon Apr 7 05:04:05 2008
@@ -128,13 +128,13 @@
}
if(!strcmp(type_id, "Foreach"))
{
- Expr* expr = dynamic_cast<Expr*>(*i++);
+ VARIABLE_NAME* variable_name = dynamic_cast<VARIABLE_NAME*>(*i++);
Variable* key = dynamic_cast<Variable*>(*i++);
bool is_ref = dynamic_cast<Boolean*>(*i++)->value();
Variable* val = dynamic_cast<Variable*>(*i++);
List<Statement*>* statements = dynamic_cast<List<Statement*>*>(*i++);
assert(i == args->end());
- return new Foreach(expr, key, is_ref, val, statements);
+ return new Foreach(variable_name, key, is_ref, val, statements);
}
if(!strcmp(type_id, "Break"))
{
Modified: trunk/src/generated/HIR_fold.h
==============================================================================
--- trunk/src/generated/HIR_fold.h (original)
+++ trunk/src/generated/HIR_fold.h Mon Apr 7 05:04:05 2008
@@ -305,8 +305,8 @@
virtual _Foreach fold_foreach(Foreach* in)
{
- _Expr expr = 0;
- if(in->expr != NULL) expr = fold_expr(in->expr);
+ _VARIABLE_NAME variable_name = 0;
+ if(in->variable_name != NULL) variable_name = fold_variable_name(in->variable_name);
_Variable key = 0;
if(in->key != NULL) key = fold_variable(in->key);
bool is_ref = in->is_ref;
@@ -321,7 +321,7 @@
if(*i != NULL) statements->push_back(fold_statement(*i));
else statements->push_back(0);
}
- return fold_impl_foreach(in, expr, key, is_ref, val, statements);
+ return fold_impl_foreach(in, variable_name, key, is_ref, val, statements);
}
virtual _Break fold_break(Break* in)
@@ -700,7 +700,7 @@
virtual _Name_with_default
fold_impl_name_with_default(Name_with_default* orig, _VARIABLE_NAME
variable_name, _Expr expr) { assert(0); };
virtual _If fold_impl_if(If* orig, _VARIABLE_NAME variable_name,
List<_Statement>* iftrue, List<_Statement>* iffalse) { assert(0); };
virtual _Loop fold_impl_loop(Loop* orig, List<_Statement>*
statements) { assert(0); };
- virtual _Foreach fold_impl_foreach(Foreach* orig, _Expr expr,
_Variable key, bool is_ref, _Variable val, List<_Statement>*
statements) { assert(0); };
+ virtual _Foreach fold_impl_foreach(Foreach* orig, _VARIABLE_NAME
variable_name, _Variable key, bool is_ref, _Variable val,
List<_Statement>* statements) { assert(0); };
virtual _Break fold_impl_break(Break* orig, _Expr expr) { assert(0); };
virtual _Continue fold_impl_continue(Continue* orig, _Expr expr) {
assert(0); };
virtual _Return fold_impl_return(Return* orig, _Expr expr) {
assert(0); };
Modified: trunk/src/generated/HIR_transform.cpp
==============================================================================
--- trunk/src/generated/HIR_transform.cpp (original)
+++ trunk/src/generated/HIR_transform.cpp Mon Apr 7 05:04:05 2008
@@ -731,7 +731,7 @@
void Transform::children_foreach(Foreach* in)
{
- in->expr = transform_expr(in->expr);
+ in->variable_name = transform_variable_name(in->variable_name);
in->key = transform_variable(in->key);
in->val = transform_variable(in->val);
in->statements = transform_statement_list(in->statements);
Modified: trunk/src/generated/HIR_visitor.cpp
==============================================================================
--- trunk/src/generated/HIR_visitor.cpp (original)
+++ trunk/src/generated/HIR_visitor.cpp Mon Apr 7 05:04:05 2008
@@ -698,7 +698,7 @@
void Visitor::children_foreach(Foreach* in)
{
- visit_expr(in->expr);
+ visit_variable_name(in->variable_name);
visit_variable(in->key);
visit_marker("is_ref", in->is_ref);
visit_variable(in->val);
Modified: trunk/src/generated_src/hir.tea
==============================================================================
--- trunk/src/generated_src/hir.tea (original)
+++ trunk/src/generated_src/hir.tea Mon Apr 7 05:04:05 2008
@@ -72,7 +72,7 @@
If ::= VARIABLE_NAME iftrue:Statement* iffalse:Statement* ;
Loop ::= Statement* ;
-Foreach ::= Expr key:Variable? is_ref:"&"? val:Variable Statement* ;
+Foreach ::= VARIABLE_NAME key:Variable? is_ref:"&"? val:Variable Statement* ;
Break ::= Expr? ;
Continue ::= Expr? ;
Modified: trunk/src/hir_to_mir/Lower_control_flow.cpp
==============================================================================
--- trunk/src/hir_to_mir/Lower_control_flow.cpp (original)
+++ trunk/src/hir_to_mir/Lower_control_flow.cpp Mon Apr 7 05:04:05 2008
@@ -141,12 +141,11 @@
}
/* Convert
- * foreach (expr() as $key => $value)
+ * foreach ($arr as $key => $value)
* {
* ...;
* }
* into
- * $array = expr ();
* foreach_reset ($arr, iter);
* loop()
* {
@@ -164,20 +163,7 @@
void Lower_control_flow::lower_foreach (Foreach* in, List<Statement*>* out)
{
- // $array = expr (); (only is array is not var)
- Variable* array = dynamic_cast<Variable*> (in->expr);
- if (array == NULL || array->is_simple_variable ())
- {
- array = fresh_var ("LCF_ARRAY_");
- out->push_back (
- new Eval_expr (
- new Assignment (
- array ,
- false,
- in->expr)));
- }
- VARIABLE_NAME* array_name = dynamic_cast<VARIABLE_NAME*> (array->variable_name);
-
+ VARIABLE_NAME* array_name = in->variable_name;
// foreach_reset ($arr, iter);
HT_ITERATOR* iter = fresh_iter ();
Modified: trunk/src/process_hir/HIR_to_AST.h
==============================================================================
--- trunk/src/process_hir/HIR_to_AST.h (original)
+++ trunk/src/process_hir/HIR_to_AST.h Mon Apr 7 05:04:05 2008
@@ -319,10 +319,10 @@
return result;
}
- AST::Foreach* fold_impl_foreach (HIR::Foreach* orig, AST::Expr* expr,
AST::Variable* key, bool is_ref, AST::Variable* val,
List<AST::Statement*>* statements)
+ AST::Foreach* fold_impl_foreach (HIR::Foreach* orig,
AST::VARIABLE_NAME* expr, AST::Variable* key, bool is_ref,
AST::Variable* val, List<AST::Statement*>* statements)
{
AST::Foreach* result;
- result = new AST::Foreach(expr, key, is_ref, val, statements);
+ result = new AST::Foreach(wrap_var_name (expr), key, is_ref, val, statements);
result->attrs = orig->attrs;
return result;
}
More information about the phc-internals
mailing list