Viewing file: Remove_concat_null.cpp (1.1 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
/* * phc -- the open source PHP compiler * See doc/license/README.license for licensing information * * Remove concatenations to empty strings (which are generated by the parser) */
#include "Remove_concat_null.h"
using namespace AST;
Expr* Remove_concat_null::post_bin_op(Bin_op* in) { STRING* empty = new STRING(new String("")); Wildcard<Expr>* wildcard = new Wildcard<Expr>;
// Unparsing may break when we start removing concats without clearing // the in_string flags. Hence, we clear all such flags here and this // pass should only be run after the AST (as part of the translation // to the HIR) in->op->attrs->erase("phc.unparser.in_string_syntax.simple"); in->op->attrs->erase("phc.unparser.in_string_syntax.delimited"); in->op->attrs->erase("phc.unparser.in_string_syntax.complex");
// Replace with right operand if left operand is the empty string if(in->match(new Bin_op(empty, wildcard, "."))) { return wildcard->value; }
// Replace with left operand if right operand is the empty string if(in->match(new Bin_op(wildcard, empty, "."))) return wildcard->value; return in; }
|