jenkins-bot has submitted this change and it was merged.
Change subject: merge functions T_PRINT and T_ISSET ... in Compiler.php
......................................................................
merge functions T_PRINT and T_ISSET ... in Compiler.php
* removed unused $operatorsPrecedence in Runtime.php
Time: 424 ms, Memory: 25.00Mb
OK (451 tests, 457 assertions)
Change-Id: Ibcd38e86c2f3e23360a025d232d7d05e7a70dcd2
---
M includes/Compiler.php
M includes/Runtime.php
2 files changed, 16 insertions(+), 71 deletions(-)
Approvals:
Pastakhov: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/Compiler.php b/includes/Compiler.php
index 596bfea..af3678d 100644
--- a/includes/Compiler.php
+++ b/includes/Compiler.php
@@ -44,6 +44,7 @@
/**
* Operator Precedence
+ * @see http://www.php.net/manual/en/language.operators.precedence.php
* @var array
*/
protected static $operatorsPrecedence = array(
@@ -700,10 +701,12 @@
$k =
array_keys($tmp);
$lk =
array_pop( $k ); // Get key of last right operator
$lastValue = &$tmp[$lk]; // Set $lastValue as link to last right operator
+
$stack[] = &$needParams[0]; // add operator T_PRINT to stack
$stack
= array_merge($stack, $tmp); // Push right operators to stack
unset($tmp);
}else{
$lastValue = &$needParams[0]; // restore T_PRINT as value
+
$stack[] = &$lastValue; // add operator T_PRINT to stack
}
array_shift($needParams);
if(
$parentFlags & FOXWAY_NEED_RESTORE_OPERATOR ) { // Restore $operator if
necessary
@@ -1037,43 +1040,14 @@
}while( ',' == self::getNextToken(
$tokens, $index, $countTokens, $tokenLine, array(',', ';') ) );
$bytecode[][] = $tmp;
break;
- case T_PRINT: // print
- if( $needOperator || $parentFlags &
FOXWAY_ALLOW_ONLY_VARIABLES ) { throw new ExceptionFoxway($id,
FOXWAY_PHP_SYNTAX_ERROR_UNEXPECTED, $tokenLine); }
- $parentheses[] = $parentFlags;
- $parentFlags = FOXWAY_EXPECT_SEMICOLON
| FOXWAY_THIS_IS_FUNCTION;
-
- array_unshift( $needParams,
array(FOXWAY_STACK_COMMAND=>T_PRINT, FOXWAY_STACK_RESULT=>1,
FOXWAY_STACK_TOKEN_LINE=>$tokenLine) );
- $stack[] = &$needParams[0];
-
- if( isset($operator) ) { // Operator
exists. Examples: echo 1+print
- $memOperators[] = &$operator;
// push $operator temporarily without PARAM_2
- unset($operator);
- $parentFlags |=
FOXWAY_NEED_RESTORE_OPERATOR;
- }
- if( $rightOperators ) { // right
operator was used, example: echo -print
- $memOperators[] =
$rightOperators; // push $rightOperators for restore later
- $rightOperators = array();
- $parentFlags |=
FOXWAY_NEED_RESTORE_RIGHT_OPERATORS;
- unset($lastValue);
- }
-
- ksort($math);
- $memory[] = array($stack, $math); //
push stack for restore late. Example: echo $a + array
- $stack = array();
- $math = array();
- break;
+ case T_PRINT:
case T_ISSET:
case T_UNSET:
case T_EMPTY:
if( $needOperator || $parentFlags &
FOXWAY_ALLOW_ONLY_VARIABLES ) { throw new ExceptionFoxway($id,
FOXWAY_PHP_SYNTAX_ERROR_UNEXPECTED, $tokenLine); }
$parentheses[] = $parentFlags;
- if( $id == T_EMPTY ) {
- $parentFlags =
FOXWAY_EXPECT_PARENTHES_CLOSE|FOXWAY_EXPECT_LIST_PARAMS|FOXWAY_THIS_IS_FUNCTION;
- }else{
- $parentFlags =
FOXWAY_EXPECT_PARENTHES_CLOSE|FOXWAY_EXPECT_LIST_PARAMS|FOXWAY_THIS_IS_FUNCTION|FOXWAY_ALLOW_ONLY_VARIABLES;
- }
-
+ $parentFlags = FOXWAY_THIS_IS_FUNCTION;
array_unshift( $needParams, array(
FOXWAY_STACK_COMMAND=>$id, FOXWAY_STACK_RESULT=>null,
FOXWAY_STACK_PARAM=>array(), FOXWAY_STACK_TOKEN_LINE=>$tokenLine ) );
if( isset($operator) ) { // Operator
exists. Example: $foo = isset
@@ -1087,13 +1061,23 @@
$parentFlags |=
FOXWAY_NEED_RESTORE_RIGHT_OPERATORS;
unset($lastValue);
}
- $parentLevel++;
ksort($math);
$memory[] = array($stack, $math); //
push stack for restore late. Example: echo $a + array
$stack = array();
$math = array();
+ if( $id == T_PRINT ) {
+ $parentFlags |=
FOXWAY_EXPECT_SEMICOLON;
+
$needParams[0][FOXWAY_STACK_RESULT] = 1;
+ break; /**** EXIT ****/
+ }elseif( $id == T_EMPTY ) {
+ $parentFlags |=
FOXWAY_EXPECT_PARENTHES_CLOSE|FOXWAY_EXPECT_LIST_PARAMS;
+ }else{ // T_UNSET, T_ISSET
+ $parentFlags |=
FOXWAY_EXPECT_PARENTHES_CLOSE|FOXWAY_EXPECT_LIST_PARAMS|FOXWAY_ALLOW_ONLY_VARIABLES;
+ }
+ $parentLevel++;
+
self::getNextToken( $tokens, $index,
$countTokens, $tokenLine, array('(') );
break;
case T_LIST:
diff --git a/includes/Runtime.php b/includes/Runtime.php
index b3fdc86..6d12dd4 100644
--- a/includes/Runtime.php
+++ b/includes/Runtime.php
@@ -35,45 +35,6 @@
protected static $staticVariables = array();
protected static $globalVariables = array();
- // @see http://www.php.net/manual/ru/language.operators.precedence.php
- protected static $operatorsPrecedence = array(
- //array('['),
- // ++ -- (int)
(float) (string) (array) (bool)
(unset)
- array(T_INC, T_DEC, '~', T_INT_CAST, T_DOUBLE_CAST,
T_STRING_CAST, T_ARRAY_CAST, T_BOOL_CAST, T_UNSET_CAST),
- array('!'),
- array('*', '/', '%'),
- array('+', '-', '.'),
- // << >>
- array(T_SL, T_SR),
- // <=
>=
- array('<', '>', T_IS_SMALLER_OR_EQUAL, T_IS_GREATER_OR_EQUAL),
- // == !=
=== !==
- array(T_IS_EQUAL, T_IS_NOT_EQUAL, T_IS_IDENTICAL,
T_IS_NOT_IDENTICAL),
- array('&'),
- array('^'),
- array('|'),
- array(T_BOOLEAN_AND), // &&
- array(T_BOOLEAN_OR), // ||
- array('?', ':'),
- // += -=
*= /= .=
%= &=
|= ^= <<= >>=
=>
- array('=', T_PLUS_EQUAL, T_MINUS_EQUAL, T_MUL_EQUAL,
T_DIV_EQUAL, T_CONCAT_EQUAL, T_MOD_EQUAL, T_AND_EQUAL, T_OR_EQUAL, T_XOR_EQUAL,
T_SL_EQUAL, T_SR_EQUAL, T_DOUBLE_ARROW),
- array(T_LOGICAL_AND), // and
- array(T_LOGICAL_XOR), // xor
- array(T_LOGICAL_OR), // or
- array(','),
- );
- private static $precedencesCount;
- private static $precedencesMatrix=array();
-
- public function __construct() {
- if( self::$precedencesCount === null ) {
- foreach (self::$operatorsPrecedence as $key => &$value)
{
- self::$precedencesMatrix +=
array_fill_keys($value, $key);
- }
- self::$precedencesCount = $key;
- }
- }
-
/*public function startTime($scope) {
self::$startTime[$scope] = microtime(true);
if( isset(self::$time[$scope]) ) {
--
To view, visit https://gerrit.wikimedia.org/r/93940
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibcd38e86c2f3e23360a025d232d7d05e7a70dcd2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Foxway
Gerrit-Branch: develop
Gerrit-Owner: Pastakhov <[email protected]>
Gerrit-Reviewer: Pastakhov <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits