Don't save whether a string is binary anymore. The binary flag isn't going to be used in the next couple of years, so it doesn't make sense to unnecessarily complicate things.

This commit is contained in:
nikic 2011-08-09 14:19:44 +02:00
parent 197b8e6967
commit ae46aeda7f
7 changed files with 22 additions and 33 deletions

View File

@ -113,8 +113,6 @@ This script will have an output similar to the following:
1: Scalar_String( 1: Scalar_String(
value: value:
isBinary: false
type: 1
) )
) )
) )
@ -130,8 +128,6 @@ This script will have an output similar to the following:
0: Expr_FuncCallArg( 0: Expr_FuncCallArg(
value: Scalar_String( value: Scalar_String(
value: Hallo World!!! value: Hallo World!!!
isBinary: false
type: 0
) )
byRef: false byRef: false
) )

View File

@ -622,9 +622,9 @@ common_scalar:
| T_FUNC_C { $$ = Scalar_FuncConst[]; } | T_FUNC_C { $$ = Scalar_FuncConst[]; }
| T_NS_C { $$ = Scalar_NSConst[]; } | T_NS_C { $$ = Scalar_NSConst[]; }
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC | T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC
{ $$ = Scalar_String[value: Scalar_String::parseEscapeSequences($2), isBinary: 'b' === $1[0]]; } { $$ = Scalar_String[value: Scalar_String::parseEscapeSequences($2)]; }
| T_START_HEREDOC T_END_HEREDOC | T_START_HEREDOC T_END_HEREDOC
{ $$ = Scalar_String[value: '', isBinary: 'b' === $1[0]]; } { $$ = Scalar_String[value: '']; }
; ;
static_scalar: /* compile-time evaluated scalars */ static_scalar: /* compile-time evaluated scalars */
@ -637,7 +637,7 @@ static_scalar: /* compile-time evaluated scalars */
; ;
scalar: scalar:
T_STRING_VARNAME { $$ = Scalar_String[value: $1, isBinary: false]; } T_STRING_VARNAME { $$ = Scalar_String[value: $1]; }
| class_constant { $$ = $1; } | class_constant { $$ = $1; }
| name { $$ = Expr_ConstFetch[name: $1]; } | name { $$ = Expr_ConstFetch[name: $1]; }
| common_scalar { $$ = $1; } | common_scalar { $$ = $1; }
@ -776,7 +776,7 @@ encaps_var:
; ;
encaps_var_offset: encaps_var_offset:
T_STRING { $$ = Scalar_String[value: $1, isBinary: false]; } T_STRING { $$ = Scalar_String[value: $1]; }
| T_NUM_STRING { $$ = Scalar_LNumber[value: parseLNumber($1)]; } | T_NUM_STRING { $$ = Scalar_LNumber[value: parseLNumber($1)]; }
| T_VARIABLE { $$ = Variable[name: parseVar($1)]; } | T_VARIABLE { $$ = Variable[name: parseVar($1)]; }
; ;

View File

@ -2,7 +2,6 @@
/** /**
* @property string $value String value * @property string $value String value
* @property bool $isBinary Whether the string is binary (b'')
*/ */
class PHPParser_Node_Scalar_String extends PHPParser_Node_Scalar class PHPParser_Node_Scalar_String extends PHPParser_Node_Scalar
{ {
@ -15,25 +14,23 @@ class PHPParser_Node_Scalar_String extends PHPParser_Node_Scalar
* @return PHPParser_Node_Scalar_String String Node * @return PHPParser_Node_Scalar_String String Node
*/ */
public static function create($s, $line) { public static function create($s, $line) {
$isBinary = false; $bLength = 0;
if ('b' === $s[0]) { if ('b' === $s[0]) {
$isBinary = true; $bLength = 1;
} }
if ('\'' === $s[$isBinary]) { if ('\'' === $s[$bLength]) {
$s = str_replace( $s = str_replace(
array('\\\\', '\\\''), array('\\\\', '\\\''),
array( '\\', '\''), array( '\\', '\''),
substr($s, $isBinary + 1, -1) substr($s, $bLength + 1, -1)
); );
} else { } else {
$s = self::parseEscapeSequences(substr($s, $isBinary + 1, -1)); $s = self::parseEscapeSequences(substr($s, $bLength + 1, -1));
} }
return new self( return new self(
array( array('value' => $s),
'value' => $s, 'isBinary' => $isBinary
),
$line $line
); );
} }

View File

@ -2114,11 +2114,11 @@ class PHPParser_Parser
} }
private function yyn275($line, $docComment) { private function yyn275($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => PHPParser_Node_Scalar_String::parseEscapeSequences($this->yyastk[$this->yysp-(3-2)]), 'isBinary' => 'b' === $this->yyastk[$this->yysp-(3-1)][0]), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_String(array('value' => PHPParser_Node_Scalar_String::parseEscapeSequences($this->yyastk[$this->yysp-(3-2)])), $line, $docComment);
} }
private function yyn276($line, $docComment) { private function yyn276($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => '', 'isBinary' => 'b' === $this->yyastk[$this->yysp-(2-1)][0]), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_String(array('value' => ''), $line, $docComment);
} }
private function yyn277($line, $docComment) { private function yyn277($line, $docComment) {
@ -2146,7 +2146,7 @@ class PHPParser_Parser
} }
private function yyn283($line, $docComment) { private function yyn283($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => $this->yyastk[$this->yysp-(1-1)], 'isBinary' => false), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_String(array('value' => $this->yyastk[$this->yysp-(1-1)]), $line, $docComment);
} }
private function yyn284($line, $docComment) { private function yyn284($line, $docComment) {
@ -2422,7 +2422,7 @@ class PHPParser_Parser
} }
private function yyn352($line, $docComment) { private function yyn352($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => $this->yyastk[$this->yysp-(1-1)], 'isBinary' => false), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_String(array('value' => $this->yyastk[$this->yysp-(1-1)]), $line, $docComment);
} }
private function yyn353($line, $docComment) { private function yyn353($line, $docComment) {

View File

@ -2513,11 +2513,11 @@ class PHPParser_ParserDebug
} }
private function yyn275($line, $docComment) { private function yyn275($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => PHPParser_Node_Scalar_String::parseEscapeSequences($this->yyastk[$this->yysp-(3-2)]), 'isBinary' => 'b' === $this->yyastk[$this->yysp-(3-1)][0]), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_String(array('value' => PHPParser_Node_Scalar_String::parseEscapeSequences($this->yyastk[$this->yysp-(3-2)])), $line, $docComment);
} }
private function yyn276($line, $docComment) { private function yyn276($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => '', 'isBinary' => 'b' === $this->yyastk[$this->yysp-(2-1)][0]), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_String(array('value' => ''), $line, $docComment);
} }
private function yyn277($line, $docComment) { private function yyn277($line, $docComment) {
@ -2545,7 +2545,7 @@ class PHPParser_ParserDebug
} }
private function yyn283($line, $docComment) { private function yyn283($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => $this->yyastk[$this->yysp-(1-1)], 'isBinary' => false), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_String(array('value' => $this->yyastk[$this->yysp-(1-1)]), $line, $docComment);
} }
private function yyn284($line, $docComment) { private function yyn284($line, $docComment) {
@ -2821,7 +2821,7 @@ class PHPParser_ParserDebug
} }
private function yyn352($line, $docComment) { private function yyn352($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => $this->yyastk[$this->yysp-(1-1)], 'isBinary' => false), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_String(array('value' => $this->yyastk[$this->yysp-(1-1)]), $line, $docComment);
} }
private function yyn353($line, $docComment) { private function yyn353($line, $docComment) {

View File

@ -52,8 +52,7 @@ class PHPParser_PrettyPrinter_Zend extends PHPParser_PrettyPrinterAbstract
// Scalars // Scalars
public function pScalar_String(PHPParser_Node_Scalar_String $node) { public function pScalar_String(PHPParser_Node_Scalar_String $node) {
return ($node->isBinary ? 'b' : '') return '\'' . $this->pSafe(addcslashes($node->value, '\'\\')) . '\'';
. '\'' . $this->pSafe(addcslashes($node->value, '\'\\')) . '\'';
} }
public function pScalar_Encapsed(PHPParser_Node_Scalar_Encapsed $node) { public function pScalar_Encapsed(PHPParser_Node_Scalar_Encapsed $node) {

View File

@ -12,15 +12,13 @@ class Unit_NodeTraverserTest extends PHPUnit_Framework_TestCase
new PHPParser_Node_Stmt_Echo(array( new PHPParser_Node_Stmt_Echo(array(
'exprs' => array( 'exprs' => array(
new PHPParser_Node_Scalar_String(array( new PHPParser_Node_Scalar_String(array(
'value' => 'Hallo World', 'value' => 'Hallo World'
'isBinary' => false
)) ))
) )
)), )),
new PHPParser_Node_Expr_Print(array( new PHPParser_Node_Expr_Print(array(
'expr' => new PHPParser_Node_Scalar_String(array( 'expr' => new PHPParser_Node_Scalar_String(array(
'value' => 'Hallo World, again!', 'value' => 'Hallo World, again!'
'isBinary' => false
)) ))
)), )),
) )
@ -80,8 +78,7 @@ class Unit_NodeTraverserTest extends PHPUnit_Framework_TestCase
new PHPParser_Node_Stmt_Echo(array( new PHPParser_Node_Stmt_Echo(array(
'exprs' => array( 'exprs' => array(
new PHPParser_Node_Scalar_String(array( new PHPParser_Node_Scalar_String(array(
'value' => 'Foo Bar', 'value' => 'Foo Bar'
'isBinary' => false
)) ))
) )
)), )),