@@ -20,10 +20,16 @@ |
||
20 | 20 | 'case_separator', 'optional_comma' |
21 | 21 | )); |
22 | 22 | |
23 | +/** |
|
24 | + * @param string $regex |
|
25 | + */ |
|
23 | 26 | function regex($regex) { |
24 | 27 | return '~' . LIB . '(?:' . str_replace('~', '\~', $regex) . ')~'; |
25 | 28 | } |
26 | 29 | |
30 | +/** |
|
31 | + * @param string $regex |
|
32 | + */ |
|
27 | 33 | function magicSplit($regex, $string) { |
28 | 34 | $pieces = preg_split(regex('(?:(?&string)|(?&comment)|(?&code))(*SKIP)(*FAIL)|' . $regex), $string); |
29 | 35 |
@@ -175,6 +175,9 @@ discard block |
||
175 | 175 | ); |
176 | 176 | } |
177 | 177 | |
178 | +/** |
|
179 | + * @param integer $num |
|
180 | + */ |
|
178 | 181 | function assertArgs($num, $args, $name) { |
179 | 182 | if ($num != count($args)) { |
180 | 183 | die('Wrong argument count for ' . $name . '().'); |
@@ -203,10 +206,16 @@ discard block |
||
203 | 206 | /// Regex helper functions /// |
204 | 207 | ////////////////////////////// |
205 | 208 | |
209 | +/** |
|
210 | + * @param string $regex |
|
211 | + */ |
|
206 | 212 | function regex($regex) { |
207 | 213 | return '~' . LIB . '(?:' . str_replace('~', '\~', $regex) . ')~'; |
208 | 214 | } |
209 | 215 | |
216 | +/** |
|
217 | + * @param string $regex |
|
218 | + */ |
|
210 | 219 | function magicSplit($regex, $string) { |
211 | 220 | $pieces = preg_split(regex('(?:(?&string)|(?&comment)|(?&code))(*SKIP)(*FAIL)|' . $regex), $string); |
212 | 221 |
@@ -44,8 +44,6 @@ |
||
44 | 44 | /** |
45 | 45 | * Implements one or more interfaces. |
46 | 46 | * |
47 | - * @param Name|string $interface Name of interface to implement |
|
48 | - * @param Name|string $... More interfaces to implement |
|
49 | 47 | * |
50 | 48 | * @return $this The builder instance (for fluid interface) |
51 | 49 | */ |
@@ -25,8 +25,6 @@ |
||
25 | 25 | /** |
26 | 26 | * Extends one or more interfaces. |
27 | 27 | * |
28 | - * @param Name|string $interface Name of interface to extend |
|
29 | - * @param Name|string $... More interfaces to extend |
|
30 | 28 | * |
31 | 29 | * @return $this The builder instance (for fluid interface) |
32 | 30 | */ |
@@ -110,6 +110,9 @@ |
||
110 | 110 | ); |
111 | 111 | } |
112 | 112 | |
113 | + /** |
|
114 | + * @param Name $type |
|
115 | + */ |
|
113 | 116 | protected function addAlias(Stmt\UseUse $use, $type, Name $prefix = null) { |
114 | 117 | // Add prefix for group uses |
115 | 118 | $name = $prefix ? Name::concat($prefix, $use->name) : $use->name; |
@@ -51,6 +51,9 @@ |
||
51 | 51 | return $this->errors; |
52 | 52 | } |
53 | 53 | |
54 | + /** |
|
55 | + * @param string $code |
|
56 | + */ |
|
54 | 57 | private function tryParse(Parser $parser, $code) { |
55 | 58 | $stmts = null; |
56 | 59 | $error = null; |
@@ -534,6 +534,9 @@ discard block |
||
534 | 534 | . ($node->name->getLast() !== $node->alias ? ' as ' . $node->alias : ''); |
535 | 535 | } |
536 | 536 | |
537 | + /** |
|
538 | + * @param integer $type |
|
539 | + */ |
|
537 | 540 | private function pUseType($type) { |
538 | 541 | return $type === Stmt\Use_::TYPE_FUNCTION ? 'function ' |
539 | 542 | : ($type === Stmt\Use_::TYPE_CONSTANT ? 'const ' : ''); |
@@ -744,6 +747,9 @@ discard block |
||
744 | 747 | return is_string($node) ? $node : $this->p($node); |
745 | 748 | } |
746 | 749 | |
750 | + /** |
|
751 | + * @param string $afterClassToken |
|
752 | + */ |
|
747 | 753 | protected function pClassCommon(Stmt\Class_ $node, $afterClassToken) { |
748 | 754 | return $this->pModifiers($node->type) |
749 | 755 | . 'class' . $afterClassToken |
@@ -760,6 +766,9 @@ discard block |
||
760 | 766 | } |
761 | 767 | } |
762 | 768 | |
769 | + /** |
|
770 | + * @param integer $modifiers |
|
771 | + */ |
|
763 | 772 | protected function pModifiers($modifiers) { |
764 | 773 | return ($modifiers & Stmt\Class_::MODIFIER_PUBLIC ? 'public ' : '') |
765 | 774 | . ($modifiers & Stmt\Class_::MODIFIER_PROTECTED ? 'protected ' : '') |
@@ -769,6 +778,9 @@ discard block |
||
769 | 778 | . ($modifiers & Stmt\Class_::MODIFIER_FINAL ? 'final ' : ''); |
770 | 779 | } |
771 | 780 | |
781 | + /** |
|
782 | + * @param string $quote |
|
783 | + */ |
|
772 | 784 | protected function pEncapsList(array $encapsList, $quote) { |
773 | 785 | $return = ''; |
774 | 786 | foreach ($encapsList as $element) { |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | return ($node->static ? 'static ' : '') |
464 | 464 | . 'function ' . ($node->byRef ? '&' : '') |
465 | 465 | . '(' . $this->pCommaSeparated($node->params) . ')' |
466 | - . (!empty($node->uses) ? ' use(' . $this->pCommaSeparated($node->uses) . ')': '') |
|
466 | + . (!empty($node->uses) ? ' use(' . $this->pCommaSeparated($node->uses) . ')' : '') |
|
467 | 467 | . (null !== $node->returnType ? ' : ' . $this->pType($node->returnType) : '') |
468 | 468 | . ' {' . $this->pStmts($node->stmts) . "\n" . '}'; |
469 | 469 | } |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | return (null !== $node->trait ? $this->p($node->trait) . '::' : '') |
571 | 571 | . $node->method . ' as' |
572 | 572 | . (null !== $node->newModifier ? ' ' . rtrim($this->pModifiers($node->newModifier), ' ') : '') |
573 | - . (null !== $node->newName ? ' ' . $node->newName : '') |
|
573 | + . (null !== $node->newName ? ' ' . $node->newName : '') |
|
574 | 574 | . ';'; |
575 | 575 | } |
576 | 576 | |
@@ -761,12 +761,12 @@ discard block |
||
761 | 761 | } |
762 | 762 | |
763 | 763 | protected function pModifiers($modifiers) { |
764 | - return ($modifiers & Stmt\Class_::MODIFIER_PUBLIC ? 'public ' : '') |
|
764 | + return ($modifiers & Stmt\Class_::MODIFIER_PUBLIC ? 'public ' : '') |
|
765 | 765 | . ($modifiers & Stmt\Class_::MODIFIER_PROTECTED ? 'protected ' : '') |
766 | - . ($modifiers & Stmt\Class_::MODIFIER_PRIVATE ? 'private ' : '') |
|
767 | - . ($modifiers & Stmt\Class_::MODIFIER_STATIC ? 'static ' : '') |
|
768 | - . ($modifiers & Stmt\Class_::MODIFIER_ABSTRACT ? 'abstract ' : '') |
|
769 | - . ($modifiers & Stmt\Class_::MODIFIER_FINAL ? 'final ' : ''); |
|
766 | + . ($modifiers & Stmt\Class_::MODIFIER_PRIVATE ? 'private ' : '') |
|
767 | + . ($modifiers & Stmt\Class_::MODIFIER_STATIC ? 'static ' : '') |
|
768 | + . ($modifiers & Stmt\Class_::MODIFIER_ABSTRACT ? 'abstract ' : '') |
|
769 | + . ($modifiers & Stmt\Class_::MODIFIER_FINAL ? 'final ' : ''); |
|
770 | 770 | } |
771 | 771 | |
772 | 772 | protected function pEncapsList(array $encapsList, $quote) { |
@@ -797,7 +797,7 @@ discard block |
||
797 | 797 | || $node instanceof Expr\ClassConstFetch |
798 | 798 | ) { |
799 | 799 | return $this->p($node); |
800 | - } else { |
|
800 | + } else { |
|
801 | 801 | return '(' . $this->p($node) . ')'; |
802 | 802 | } |
803 | 803 | } |
@@ -812,7 +812,7 @@ discard block |
||
812 | 812 | || $node instanceof Expr\Array_ |
813 | 813 | ) { |
814 | 814 | return $this->p($node); |
815 | - } else { |
|
815 | + } else { |
|
816 | 816 | return '(' . $this->p($node) . ')'; |
817 | 817 | } |
818 | 818 | } |
@@ -187,6 +187,10 @@ discard block |
||
187 | 187 | return $this->{'p' . $node->getType()}($node); |
188 | 188 | } |
189 | 189 | |
190 | + /** |
|
191 | + * @param string $type |
|
192 | + * @param string $operatorString |
|
193 | + */ |
|
190 | 194 | protected function pInfixOp($type, Node $leftNode, $operatorString, Node $rightNode) { |
191 | 195 | list($precedence, $associativity) = $this->precedenceMap[$type]; |
192 | 196 | |
@@ -195,11 +199,19 @@ discard block |
||
195 | 199 | . $this->pPrec($rightNode, $precedence, $associativity, 1); |
196 | 200 | } |
197 | 201 | |
202 | + /** |
|
203 | + * @param string $type |
|
204 | + * @param string $operatorString |
|
205 | + */ |
|
198 | 206 | protected function pPrefixOp($type, $operatorString, Node $node) { |
199 | 207 | list($precedence, $associativity) = $this->precedenceMap[$type]; |
200 | 208 | return $operatorString . $this->pPrec($node, $precedence, $associativity, 1); |
201 | 209 | } |
202 | 210 | |
211 | + /** |
|
212 | + * @param string $type |
|
213 | + * @param string $operatorString |
|
214 | + */ |
|
203 | 215 | protected function pPostfixOp($type, Node $node, $operatorString) { |
204 | 216 | list($precedence, $associativity) = $this->precedenceMap[$type]; |
205 | 217 | return $this->pPrec($node, $precedence, $associativity, -1) . $operatorString; |
@@ -264,7 +276,7 @@ discard block |
||
264 | 276 | * |
265 | 277 | * @param string $string Not to be indented string |
266 | 278 | * |
267 | - * @return mixed String marked with $this->noIndentToken's. |
|
279 | + * @return string String marked with $this->noIndentToken's. |
|
268 | 280 | */ |
269 | 281 | protected function pNoIndent($string) { |
270 | 282 | return str_replace("\n", "\n" . $this->noIndentToken, $string); |
@@ -9,65 +9,65 @@ |
||
9 | 9 | { |
10 | 10 | protected $precedenceMap = array( |
11 | 11 | // [precedence, associativity] where for the latter -1 is %left, 0 is %nonassoc and 1 is %right |
12 | - 'Expr_BinaryOp_Pow' => array( 0, 1), |
|
13 | - 'Expr_BitwiseNot' => array( 10, 1), |
|
14 | - 'Expr_PreInc' => array( 10, 1), |
|
15 | - 'Expr_PreDec' => array( 10, 1), |
|
16 | - 'Expr_PostInc' => array( 10, -1), |
|
17 | - 'Expr_PostDec' => array( 10, -1), |
|
18 | - 'Expr_UnaryPlus' => array( 10, 1), |
|
19 | - 'Expr_UnaryMinus' => array( 10, 1), |
|
20 | - 'Expr_Cast_Int' => array( 10, 1), |
|
21 | - 'Expr_Cast_Double' => array( 10, 1), |
|
22 | - 'Expr_Cast_String' => array( 10, 1), |
|
23 | - 'Expr_Cast_Array' => array( 10, 1), |
|
24 | - 'Expr_Cast_Object' => array( 10, 1), |
|
25 | - 'Expr_Cast_Bool' => array( 10, 1), |
|
26 | - 'Expr_Cast_Unset' => array( 10, 1), |
|
27 | - 'Expr_ErrorSuppress' => array( 10, 1), |
|
28 | - 'Expr_Instanceof' => array( 20, 0), |
|
29 | - 'Expr_BooleanNot' => array( 30, 1), |
|
30 | - 'Expr_BinaryOp_Mul' => array( 40, -1), |
|
31 | - 'Expr_BinaryOp_Div' => array( 40, -1), |
|
32 | - 'Expr_BinaryOp_Mod' => array( 40, -1), |
|
33 | - 'Expr_BinaryOp_Plus' => array( 50, -1), |
|
34 | - 'Expr_BinaryOp_Minus' => array( 50, -1), |
|
35 | - 'Expr_BinaryOp_Concat' => array( 50, -1), |
|
36 | - 'Expr_BinaryOp_ShiftLeft' => array( 60, -1), |
|
37 | - 'Expr_BinaryOp_ShiftRight' => array( 60, -1), |
|
38 | - 'Expr_BinaryOp_Smaller' => array( 70, 0), |
|
39 | - 'Expr_BinaryOp_SmallerOrEqual' => array( 70, 0), |
|
40 | - 'Expr_BinaryOp_Greater' => array( 70, 0), |
|
41 | - 'Expr_BinaryOp_GreaterOrEqual' => array( 70, 0), |
|
42 | - 'Expr_BinaryOp_Equal' => array( 80, 0), |
|
43 | - 'Expr_BinaryOp_NotEqual' => array( 80, 0), |
|
44 | - 'Expr_BinaryOp_Identical' => array( 80, 0), |
|
45 | - 'Expr_BinaryOp_NotIdentical' => array( 80, 0), |
|
46 | - 'Expr_BinaryOp_Spaceship' => array( 80, 0), |
|
47 | - 'Expr_BinaryOp_BitwiseAnd' => array( 90, -1), |
|
12 | + 'Expr_BinaryOp_Pow' => array(0, 1), |
|
13 | + 'Expr_BitwiseNot' => array(10, 1), |
|
14 | + 'Expr_PreInc' => array(10, 1), |
|
15 | + 'Expr_PreDec' => array(10, 1), |
|
16 | + 'Expr_PostInc' => array(10, -1), |
|
17 | + 'Expr_PostDec' => array(10, -1), |
|
18 | + 'Expr_UnaryPlus' => array(10, 1), |
|
19 | + 'Expr_UnaryMinus' => array(10, 1), |
|
20 | + 'Expr_Cast_Int' => array(10, 1), |
|
21 | + 'Expr_Cast_Double' => array(10, 1), |
|
22 | + 'Expr_Cast_String' => array(10, 1), |
|
23 | + 'Expr_Cast_Array' => array(10, 1), |
|
24 | + 'Expr_Cast_Object' => array(10, 1), |
|
25 | + 'Expr_Cast_Bool' => array(10, 1), |
|
26 | + 'Expr_Cast_Unset' => array(10, 1), |
|
27 | + 'Expr_ErrorSuppress' => array(10, 1), |
|
28 | + 'Expr_Instanceof' => array(20, 0), |
|
29 | + 'Expr_BooleanNot' => array(30, 1), |
|
30 | + 'Expr_BinaryOp_Mul' => array(40, -1), |
|
31 | + 'Expr_BinaryOp_Div' => array(40, -1), |
|
32 | + 'Expr_BinaryOp_Mod' => array(40, -1), |
|
33 | + 'Expr_BinaryOp_Plus' => array(50, -1), |
|
34 | + 'Expr_BinaryOp_Minus' => array(50, -1), |
|
35 | + 'Expr_BinaryOp_Concat' => array(50, -1), |
|
36 | + 'Expr_BinaryOp_ShiftLeft' => array(60, -1), |
|
37 | + 'Expr_BinaryOp_ShiftRight' => array(60, -1), |
|
38 | + 'Expr_BinaryOp_Smaller' => array(70, 0), |
|
39 | + 'Expr_BinaryOp_SmallerOrEqual' => array(70, 0), |
|
40 | + 'Expr_BinaryOp_Greater' => array(70, 0), |
|
41 | + 'Expr_BinaryOp_GreaterOrEqual' => array(70, 0), |
|
42 | + 'Expr_BinaryOp_Equal' => array(80, 0), |
|
43 | + 'Expr_BinaryOp_NotEqual' => array(80, 0), |
|
44 | + 'Expr_BinaryOp_Identical' => array(80, 0), |
|
45 | + 'Expr_BinaryOp_NotIdentical' => array(80, 0), |
|
46 | + 'Expr_BinaryOp_Spaceship' => array(80, 0), |
|
47 | + 'Expr_BinaryOp_BitwiseAnd' => array(90, -1), |
|
48 | 48 | 'Expr_BinaryOp_BitwiseXor' => array(100, -1), |
49 | 49 | 'Expr_BinaryOp_BitwiseOr' => array(110, -1), |
50 | 50 | 'Expr_BinaryOp_BooleanAnd' => array(120, -1), |
51 | 51 | 'Expr_BinaryOp_BooleanOr' => array(130, -1), |
52 | - 'Expr_BinaryOp_Coalesce' => array(140, 1), |
|
52 | + 'Expr_BinaryOp_Coalesce' => array(140, 1), |
|
53 | 53 | 'Expr_Ternary' => array(150, -1), |
54 | 54 | // parser uses %left for assignments, but they really behave as %right |
55 | - 'Expr_Assign' => array(160, 1), |
|
56 | - 'Expr_AssignRef' => array(160, 1), |
|
57 | - 'Expr_AssignOp_Plus' => array(160, 1), |
|
58 | - 'Expr_AssignOp_Minus' => array(160, 1), |
|
59 | - 'Expr_AssignOp_Mul' => array(160, 1), |
|
60 | - 'Expr_AssignOp_Div' => array(160, 1), |
|
61 | - 'Expr_AssignOp_Concat' => array(160, 1), |
|
62 | - 'Expr_AssignOp_Mod' => array(160, 1), |
|
63 | - 'Expr_AssignOp_BitwiseAnd' => array(160, 1), |
|
64 | - 'Expr_AssignOp_BitwiseOr' => array(160, 1), |
|
65 | - 'Expr_AssignOp_BitwiseXor' => array(160, 1), |
|
66 | - 'Expr_AssignOp_ShiftLeft' => array(160, 1), |
|
67 | - 'Expr_AssignOp_ShiftRight' => array(160, 1), |
|
68 | - 'Expr_AssignOp_Pow' => array(160, 1), |
|
69 | - 'Expr_YieldFrom' => array(165, 1), |
|
70 | - 'Expr_Print' => array(168, 1), |
|
55 | + 'Expr_Assign' => array(160, 1), |
|
56 | + 'Expr_AssignRef' => array(160, 1), |
|
57 | + 'Expr_AssignOp_Plus' => array(160, 1), |
|
58 | + 'Expr_AssignOp_Minus' => array(160, 1), |
|
59 | + 'Expr_AssignOp_Mul' => array(160, 1), |
|
60 | + 'Expr_AssignOp_Div' => array(160, 1), |
|
61 | + 'Expr_AssignOp_Concat' => array(160, 1), |
|
62 | + 'Expr_AssignOp_Mod' => array(160, 1), |
|
63 | + 'Expr_AssignOp_BitwiseAnd' => array(160, 1), |
|
64 | + 'Expr_AssignOp_BitwiseOr' => array(160, 1), |
|
65 | + 'Expr_AssignOp_BitwiseXor' => array(160, 1), |
|
66 | + 'Expr_AssignOp_ShiftLeft' => array(160, 1), |
|
67 | + 'Expr_AssignOp_ShiftRight' => array(160, 1), |
|
68 | + 'Expr_AssignOp_Pow' => array(160, 1), |
|
69 | + 'Expr_YieldFrom' => array(165, 1), |
|
70 | + 'Expr_Print' => array(168, 1), |
|
71 | 71 | 'Expr_BinaryOp_LogicalAnd' => array(170, -1), |
72 | 72 | 'Expr_BinaryOp_LogicalXor' => array(180, -1), |
73 | 73 | 'Expr_BinaryOp_LogicalOr' => array(190, -1), |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | $this->code = $code; // keep the code around for __halt_compiler() handling |
64 | 64 | $this->pos = -1; |
65 | - $this->line = 1; |
|
65 | + $this->line = 1; |
|
66 | 66 | $this->filePos = 0; |
67 | 67 | } |
68 | 68 | |
@@ -264,10 +264,10 @@ discard block |
||
264 | 264 | if (T_DOUBLE_COLON === $i) { |
265 | 265 | // T_DOUBLE_COLON is equivalent to T_PAAMAYIM_NEKUDOTAYIM |
266 | 266 | $tokenMap[$i] = Tokens::T_PAAMAYIM_NEKUDOTAYIM; |
267 | - } elseif(T_OPEN_TAG_WITH_ECHO === $i) { |
|
267 | + } elseif (T_OPEN_TAG_WITH_ECHO === $i) { |
|
268 | 268 | // T_OPEN_TAG_WITH_ECHO with dropped T_OPEN_TAG results in T_ECHO |
269 | 269 | $tokenMap[$i] = Tokens::T_ECHO; |
270 | - } elseif(T_CLOSE_TAG === $i) { |
|
270 | + } elseif (T_CLOSE_TAG === $i) { |
|
271 | 271 | // T_CLOSE_TAG is equivalent to ';' |
272 | 272 | $tokenMap[$i] = ord(';'); |
273 | 273 | } elseif ('UNKNOWN' !== $name = token_name($i)) { |