forked from zephir-lang/zephir
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding array_keys optimizer, allow using isset with parentheses, othe…
…r fixes
- Loading branch information
1 parent
b5b4aed
commit 15b4412
Showing
8 changed files
with
256 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
/* | ||
+--------------------------------------------------------------------------+ | ||
| Zephir Language | | ||
+--------------------------------------------------------------------------+ | ||
| Copyright (c) 2013-2014 Zephir Team and contributors | | ||
+--------------------------------------------------------------------------+ | ||
| This source file is subject the MIT license, that is bundled with | | ||
| this package in the file LICENSE, and is available through the | | ||
| world-wide-web at the following url: | | ||
| http://zephir-lang.com/license.html | | ||
| | | ||
| If you did not receive a copy of the MIT license and are unable | | ||
| to obtain it through the world-wide-web, please send a note to | | ||
| [email protected] so we can mail you a copy immediately. | | ||
+--------------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* ArrayKeysOptimizer | ||
* | ||
* Optimizes calls to 'array_keys' using internal function | ||
*/ | ||
class ArrayKeysOptimizer | ||
extends OptimizerAbstract | ||
{ | ||
/** | ||
* @param array $expression | ||
* @param Call $call | ||
* @param CompilationContext $context | ||
* @return bool|CompiledExpression|mixed | ||
* @throws CompilerException | ||
*/ | ||
public function optimize(array $expression, Call $call, CompilationContext $context) | ||
{ | ||
if (!isset($expression['parameters'])) { | ||
return false; | ||
} | ||
|
||
if (count($expression['parameters']) != 1) { | ||
return false; | ||
} | ||
|
||
/** | ||
* Process the expected symbol to be returned | ||
*/ | ||
$call->processExpectedReturn($context); | ||
|
||
$symbolVariable = $call->getSymbolVariable(); | ||
if ($symbolVariable->getType() != 'variable') { | ||
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression); | ||
} | ||
|
||
if ($call->mustInitSymbolVariable()) { | ||
$symbolVariable->initVariant($context); | ||
} | ||
|
||
$context->headersManager->add('kernel/extended/array'); | ||
|
||
$symbolVariable->setDynamicTypes('array'); | ||
|
||
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression); | ||
$context->codePrinter->output('zephir_array_keys(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ' TSRMLS_CC);'); | ||
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
|
||
/* | ||
+------------------------------------------------------------------------+ | ||
| Zephir Language | | ||
+------------------------------------------------------------------------+ | ||
| Copyright (c) 2011-2014 Zephir Team (http://www.zephir-lang.com) | | ||
+------------------------------------------------------------------------+ | ||
| This source file is subject to the New BSD License that is bundled | | ||
| with this package in the file docs/LICENSE.txt. | | ||
| | | ||
| If you did not receive a copy of the license and are unable to | | ||
| obtain it through the world-wide-web, please send an email | | ||
| to [email protected] so we can send you a copy immediately. | | ||
+------------------------------------------------------------------------+ | ||
| Authors: Andres Gutierrez <[email protected]> | | ||
| Eduar Carvajal <[email protected]> | | ||
+------------------------------------------------------------------------+ | ||
*/ | ||
|
||
/* | ||
+----------------------------------------------------------------------+ | ||
| PHP Version 5 | | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) 1997-2014 The PHP Group | | ||
+----------------------------------------------------------------------+ | ||
| This source file is subject to version 3.01 of the PHP license, | | ||
| that is bundled with this package in the file LICENSE, and is | | ||
| available through the world-wide-web at the following url: | | ||
| http://www.php.net/license/3_01.txt | | ||
| If you did not receive a copy of the PHP license and are unable to | | ||
| obtain it through the world-wide-web, please send a note to | | ||
| [email protected] so we can mail you a copy immediately. | | ||
+----------------------------------------------------------------------+ | ||
| Authors: Andi Gutmans <[email protected]> | | ||
| Zeev Suraski <[email protected]> | | ||
| Rasmus Lerdorf <[email protected]> | | ||
| Andrei Zmievski <[email protected]> | | ||
| Stig Venaas <[email protected]> | | ||
| Jason Greene <[email protected]> | | ||
+----------------------------------------------------------------------+ | ||
*/ | ||
|
||
#ifdef HAVE_CONFIG_H | ||
#include "config.h" | ||
#endif | ||
|
||
#include "php.h" | ||
#include "php_ext.h" | ||
|
||
#include "Zend/zend_API.h" | ||
#include "Zend/zend_exceptions.h" | ||
#include "Zend/zend_execute.h" | ||
|
||
#include "kernel/main.h" | ||
|
||
#include "kernel/extended/array.h" | ||
|
||
void zephir_array_keys(zval *input TSRMLS_DC) { | ||
|
||
zval *search_value = NULL, /* Value to search for */ | ||
**entry, /* An entry in the input array */ | ||
res, /* Result of comparison */ | ||
*new_val; /* New value */ | ||
int add_key; /* Flag to indicate whether a key should be added */ | ||
zend_bool strict = 0; /* do strict comparison */ | ||
HashPosition pos; | ||
int (*is_equal_func)(zval *, zval *, zval * TSRMLS_DC) = is_equal_function; | ||
|
||
//if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|zb", &input, &search_value, &strict) == FAILURE) { | ||
// return; | ||
//} | ||
|
||
if (strict) { | ||
is_equal_func = is_identical_function; | ||
} | ||
|
||
/* Initialize return array */ | ||
if (search_value != NULL) { | ||
array_init(return_value); | ||
} else { | ||
array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(input))); | ||
} | ||
add_key = 1; | ||
|
||
/* Go through input array and add keys to the return array */ | ||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(input), &pos); | ||
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(input), (void **)&entry, &pos) == SUCCESS) { | ||
if (search_value != NULL) { | ||
is_equal_func(&res, search_value, *entry TSRMLS_CC); | ||
add_key = zval_is_true(&res); | ||
} | ||
} | ||
|
||
if (add_key) { | ||
MAKE_STD_ZVAL(new_val); | ||
zend_hash_get_current_key_zval_ex(Z_ARRVAL_P(input), new_val, &pos); | ||
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &new_val, sizeof(zval *), NULL); | ||
} | ||
|
||
zend_hash_move_forward_ex(Z_ARRVAL_P(input), &pos); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
/* | ||
+------------------------------------------------------------------------+ | ||
| Zephir Language | | ||
+------------------------------------------------------------------------+ | ||
| Copyright (c) 2011-2014 Zephir Team (http://www.zephir-lang.com) | | ||
+------------------------------------------------------------------------+ | ||
| This source file is subject to the New BSD License that is bundled | | ||
| with this package in the file docs/LICENSE.txt. | | ||
| | | ||
| If you did not receive a copy of the license and are unable to | | ||
| obtain it through the world-wide-web, please send an email | | ||
| to [email protected] so we can send you a copy immediately. | | ||
+------------------------------------------------------------------------+ | ||
| Authors: Andres Gutierrez <[email protected]> | | ||
| Eduar Carvajal <[email protected]> | | ||
+------------------------------------------------------------------------+ | ||
*/ | ||
|
||
/* | ||
+----------------------------------------------------------------------+ | ||
| PHP Version 5 | | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) 1997-2014 The PHP Group | | ||
+----------------------------------------------------------------------+ | ||
| This source file is subject to version 3.01 of the PHP license, | | ||
| that is bundled with this package in the file LICENSE, and is | | ||
| available through the world-wide-web at the following url: | | ||
| http://www.php.net/license/3_01.txt | | ||
| If you did not receive a copy of the PHP license and are unable to | | ||
| obtain it through the world-wide-web, please send a note to | | ||
| [email protected] so we can mail you a copy immediately. | | ||
+----------------------------------------------------------------------+ | ||
| Authors: Andi Gutmans <[email protected]> | | ||
| Zeev Suraski <[email protected]> | | ||
| Rasmus Lerdorf <[email protected]> | | ||
| Andrei Zmievski <[email protected]> | | ||
| Stig Venaas <[email protected]> | | ||
| Jason Greene <[email protected]> | | ||
+----------------------------------------------------------------------+ | ||
*/ | ||
|
||
void zephir_array_keys(zval *input TSRMLS_DC); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters