-
-
Notifications
You must be signed in to change notification settings - Fork 470
/
Copy pathExitOptimizer.php
59 lines (51 loc) · 1.73 KB
/
ExitOptimizer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* This file is part of the Zephir.
*
* (c) Phalcon Team <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Zephir\Optimizers\FunctionCall;
use Zephir\Call;
use Zephir\CompilationContext;
use Zephir\CompiledExpression;
use Zephir\Exception\CompilerException;
use Zephir\Optimizers\OptimizerAbstract;
use function count;
/**
* Optimizes calls to 'exit' using internal function
*/
class ExitOptimizer 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']) && count($expression['parameters']) > 1) {
return false;
}
$context->headersManager->add('kernel/exit');
if (isset($expression['parameters'])) {
// TODO: protect resolvedParams[0] from restore
}
if (!isset($expression['parameters'])) {
// $context->codePrinter->output('ZEPHIR_MM_RESTORE();');
$context->codePrinter->output('zephir_exit_empty();');
} else {
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
// $context->codePrinter->output('ZEPHIR_MM_RESTORE();');
$context->codePrinter->output('zephir_exit(' . $resolvedParams[0] . ');');
}
return new CompiledExpression('void ', '', $expression);
}
}