From 46881c110d328ce8749c4f4e8e0a86d6f86d4bdd Mon Sep 17 00:00:00 2001 From: Andres Gutierrez Date: Fri, 24 Oct 2014 14:44:16 -0500 Subject: [PATCH] Fixing str_replace optimizer, improved parser to support any kind of keys expressions when creating arrays --- Library/Compiler.php | 2 +- .../FunctionCall/StrReplaceOptimizer.php | 2 +- ext/kernel/string.c | 2 +- ext/kernel/string.h | 2 +- parser/parser.lemon | 16 ++-------------- 5 files changed, 6 insertions(+), 18 deletions(-) diff --git a/Library/Compiler.php b/Library/Compiler.php index ae925f046d..372023f3ba 100755 --- a/Library/Compiler.php +++ b/Library/Compiler.php @@ -30,7 +30,7 @@ */ class Compiler { - const VERSION = '0.5.5a'; + const VERSION = '0.5.6a'; /** * @var CompilerFile[] diff --git a/Library/Optimizers/FunctionCall/StrReplaceOptimizer.php b/Library/Optimizers/FunctionCall/StrReplaceOptimizer.php index 6b273b06d2..c327602854 100644 --- a/Library/Optimizers/FunctionCall/StrReplaceOptimizer.php +++ b/Library/Optimizers/FunctionCall/StrReplaceOptimizer.php @@ -68,7 +68,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont $symbolVariable->setDynamicTypes('string'); $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression); - $context->codePrinter->output('zephir_fast_str_replace(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ', ' . $resolvedParams[2] . ');'); + $context->codePrinter->output('zephir_fast_str_replace(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ', ' . $resolvedParams[2] . ' TSRMLS_CC);'); return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression); } } diff --git a/ext/kernel/string.c b/ext/kernel/string.c index 9f8cbfca32..9d56e20577 100644 --- a/ext/kernel/string.c +++ b/ext/kernel/string.c @@ -506,7 +506,7 @@ void zephir_fast_stripos_str(zval *return_value, zval *haystack, char *needle, u /** * Immediate function resolution for str_replace function */ -void zephir_fast_str_replace(zval *return_value, zval *search, zval *replace, zval *subject) { +void zephir_fast_str_replace(zval *return_value, zval *search, zval *replace, zval *subject TSRMLS_DC) { zval replace_copy, search_copy; int copy_replace = 0, copy_search = 0; diff --git a/ext/kernel/string.h b/ext/kernel/string.h index 8806026dd4..c74274a5e5 100644 --- a/ext/kernel/string.h +++ b/ext/kernel/string.h @@ -43,7 +43,7 @@ void zephir_fast_explode_str(zval *result, const char *delimiter, int delimiter_ void zephir_fast_strpos(zval *return_value, const zval *haystack, const zval *needle, unsigned int offset); void zephir_fast_strpos_str(zval *return_value, const zval *haystack, char *needle, unsigned int needle_length); void zephir_fast_stripos_str(zval *return_value, zval *haystack, char *needle, unsigned int needle_length); -void zephir_fast_str_replace(zval *return_value, zval *search, zval *replace, zval *subject); +void zephir_fast_str_replace(zval *return_value, zval *search, zval *replace, zval *subject TSRMLS_DC); void zephir_fast_trim(zval *return_value, zval *str, zval *charlist, int where TSRMLS_DC); void zephir_fast_strip_tags(zval *return_value, zval *str); void zephir_fast_strtoupper(zval *return_value, zval *str); diff --git a/parser/parser.lemon b/parser/parser.lemon index 36c16a75c4..f006a1a36e 100644 --- a/parser/parser.lemon +++ b/parser/parser.lemon @@ -2988,20 +2988,8 @@ xx_array_item(R) ::= xx_array_value(V) . { R = xx_ret_array_item(NULL, V, status->scanner_state); } -xx_array_key(R) ::= CONSTANT(I) . { - R = xx_ret_literal(XX_T_CONSTANT, I, status->scanner_state); -} - -xx_array_key(R) ::= IDENTIFIER(I) . { - R = xx_ret_literal(XX_T_IDENTIFIER, I, status->scanner_state); -} - -xx_array_key(R) ::= STRING(S) . { - R = xx_ret_literal(XX_T_STRING, S, status->scanner_state); -} - -xx_array_key(R) ::= INTEGER(I) . { - R = xx_ret_literal(XX_T_INTEGER, I, status->scanner_state); +xx_array_key(R) ::= xx_common_expr(E) . { + R = E; } xx_array_value(R) ::= xx_common_expr(E) . {