[phc-internals] [phc commit] r1177 - in trunk: src/process_ast
test/subjects/parsing test/subjects/reduced
codesite-noreply at google.com
codesite-noreply at google.com
Tue Apr 15 12:48:16 IST 2008
Author: paul.biggar
Date: Tue Apr 15 04:46:32 2008
New Revision: 1177
Added:
trunk/test/subjects/reduced/0039.php
Modified:
trunk/src/process_ast/AST_unparser.cpp
trunk/src/process_ast/Token_conversion.cpp
trunk/test/subjects/parsing/unary_plus.php
Log:
We used to remove double unary operations just after parsring, during
token conversion. However, this breaks if later parts of the compiler
add a double unary, since the unparser is unable to handle it. This
makes the unparser add a space in this event, and removes the
transformation from Token_conversion. This will be included in
constant_folding instead, which is nearly ready.
Modified: trunk/src/process_ast/AST_unparser.cpp
==============================================================================
--- trunk/src/process_ast/AST_unparser.cpp (original)
+++ trunk/src/process_ast/AST_unparser.cpp Tue Apr 15 04:46:32 2008
@@ -655,6 +655,20 @@
void AST_unparser::children_unary_op(Unary_op* in)
{
visit_op(in->op);
+
+ // Special case for '-': avoid --1 (-+ or +- is OK)
+ Literal* lit;
+ Wildcard<Expr> outer, inner;
+
+ if (in->match (new Unary_op (&outer, "-")))
+ {
+ if (outer.value->match (new Unary_op (&inner, "-"))
+ || ((lit = dynamic_cast<Literal*> (outer.value))
+ && (*lit->get_value_as_string ())[0] == '-'))
+ echo (" ");
+ }
+
+
visit_expr(in->expr);
}
Modified: trunk/src/process_ast/Token_conversion.cpp
==============================================================================
--- trunk/src/process_ast/Token_conversion.cpp (original)
+++ trunk/src/process_ast/Token_conversion.cpp Tue Apr 15 04:46:32 2008
@@ -40,10 +40,10 @@
return PHP::convert_token (in);
}
-// Convert unary_op(-,int(5)) to int(-5), and similarly for reals
+// Convert unary_op(-,int(5)) to int(-5), and similarly for reals.
Note that
+// multiple '-' unary ops are allowed.
Expr* Token_conversion::pre_unary_op(Unary_op* in)
{
- Wildcard<Expr>* expr = new Wildcard<Expr>;
Wildcard<INT>* i = new Wildcard<INT>;
Wildcard<REAL>* r = new Wildcard<REAL>;
@@ -51,22 +51,13 @@
// attributes from *in to *result
Expr* result;
- if(in->match(new Unary_op(new Unary_op(expr, "-"), "-")))
- {
- // Double negation; remove both
- result = pre_expr(expr->value);
- }
-
- // TODO add a pass to check for the lack of unary -s
-
- else if(in->match(new Unary_op(i, "-")))
+ if(in->match(new Unary_op(i, "-")))
{
String* source_rep = new String("-");
*source_rep += *i->value->get_source_rep ();
i->value->set_source_rep (source_rep);
result = PHP::convert_token (i->value);
}
-
else if(in->match(new Unary_op(r, "-")))
{
String* source_rep = new String("-");
@@ -74,7 +65,6 @@
r->value->set_source_rep (source_rep);
result = PHP::convert_token (r->value);
}
-
else
{
// No changes
Modified: trunk/test/subjects/parsing/unary_plus.php
==============================================================================
--- trunk/test/subjects/parsing/unary_plus.php (original)
+++ trunk/test/subjects/parsing/unary_plus.php Tue Apr 15 04:46:32 2008
@@ -1,6 +1,35 @@
<?php
$x = +1;
+ var_dump ($x);
$x = +1.0;
+ var_dump ($x);
$x = + +1;
+ var_dump ($x);
$x = + -1;
+ var_dump ($x);
+
+ $x = -1;
+ var_dump ($x);
+ $x = - -1;
+ var_dump ($x);
+ $x = - - -1;
+ var_dump ($x);
+ $x = - - - -1;
+ var_dump ($x);
+ $x = - - - - -1;
+ var_dump ($x);
+
+ $x = -1;
+ var_dump ($x);
+ $x = +-1;
+ var_dump ($x);
+ $x = -+-1;
+ var_dump ($x);
+ $x = +-+-1;
+ var_dump ($x);
+ $x = -+-+-1;
+ var_dump ($x);
+
+
+
?>
Added: trunk/test/subjects/reduced/0039.php
==============================================================================
--- (empty file)
+++ trunk/test/subjects/reduced/0039.php Tue Apr 15 04:46:32 2008
@@ -0,0 +1,4 @@
+<?php
+
+ var_dump (- - - - - - - - -4);
+?>
More information about the phc-internals
mailing list