diff --git a/src/Core/Translator.php b/src/Core/Translator.php index 0ff39ae1..55f4d1cf 100644 --- a/src/Core/Translator.php +++ b/src/Core/Translator.php @@ -1,12 +1,18 @@ rootPath = $rootPath; $this->parser = (new ParserFactory())->createForNewestSupportedVersion(); - $this->printer = new PrettyPrinter\Standard; + $this->printer = new PrettyPrinter\Standard(); $this->setBuildDir($rootPath . '/build'); $climate = new CLImate(); $this->climate = $climate; @@ -452,6 +452,7 @@ class CompilerBase extends \PhpAot\Core\Translator case 'Expr_Yield': case 'Expr_YieldFrom': $this->fatalError($expr, 'The `' . $type . '` is not supported'); + // no break default: abort($expr); } @@ -622,7 +623,7 @@ class CompilerBase extends \PhpAot\Core\Translator } } else { if ($this->function) { - $prefix .= $this->function . '_'; + $prefix .= $this->function . '_'; } } return $prefix . $name; @@ -724,14 +725,13 @@ class CompilerBase extends \PhpAot\Core\Translator return 'php_get_method(' . $funcId . ', ' . $this->getLiteralString($method) . ', ' . $classId . ', ' . $this->getLiteralString($class) . ')'; } - protected function parseTypeDecl(NodeAbstract|null $type): string + protected function parseTypeDecl(?NodeAbstract $type): string { // 联合类型暂时不支持,使用 var 类型代替 - if ($type instanceof Node\UnionType or $type instanceof NullableType) { + if ($type instanceof UnionType or $type instanceof NullableType) { return self::TYPE_VAR; - } else { - return $type ? $this->getTypeFromZendType($this->parseIdentifier($type)) : self::TYPE_VOID; } + return $type ? $this->getTypeFromZendType($this->parseIdentifier($type)) : self::TYPE_VOID; } protected function parseFunctionDecl(Node\Stmt\Function_|Node\Stmt\ClassMethod $v): FunctionDef @@ -1057,6 +1057,7 @@ class CompilerBase extends \PhpAot\Core\Translator break; case 'Stmt_Class': $this->fatalError($v, 'Cannot declare class in function'); + // no break default: abort($v); } @@ -1351,9 +1352,8 @@ class CompilerBase extends \PhpAot\Core\Translator if ($v->expr === null) { if ($this->functionDef->returnType === self::TYPE_VOID and !$this->inClosure) { return 'return;'; - } else { - return 'return ' . self::VALUE_NULL . ';'; } + return 'return ' . self::VALUE_NULL . ';'; } // 实际函数的返回值 $type = $this->detectExprType($v->expr); @@ -1391,7 +1391,7 @@ class CompilerBase extends \PhpAot\Core\Translator $this->localVars[$name] = $type; } - protected function addStaticVar(string $name, string $type): void + protected function addStaticVar(string $name, string $type): void { $this->staticVars[$name] = $type; $this->addGlobalVar($this->getStaticVarName($name), $type); @@ -1984,7 +1984,7 @@ class CompilerBase extends \PhpAot\Core\Translator protected function foundStrayCode(Node $node): never { - $this->fatalError($node, "All execution code must be within a function, found stray code"); + $this->fatalError($node, 'All execution code must be within a function, found stray code'); } protected function parseFuncCall(Node\Expr\FuncCall $expr, bool $silent = false): string @@ -2044,7 +2044,7 @@ class CompilerBase extends \PhpAot\Core\Translator throw new PlaceHolder(); } if ($arg->name) { - foreach($functionDef->argInfoList as $k => $argInfo) { + foreach ($functionDef->argInfoList as $k => $argInfo) { if ($argInfo->name === $arg->name->name) { $args[$k] = $arg; $hasNamedArg = true; @@ -2070,9 +2070,8 @@ class CompilerBase extends \PhpAot\Core\Translator } $argList[] = '{' . implode(', ', $list_vargs) . '}'; break; - } else { - $argList[] = $this->getTypeConvertedArg($arg, $argInfo); } + $argList[] = $this->getTypeConvertedArg($arg, $argInfo); } return implode(', ', $argList); @@ -3012,9 +3011,9 @@ class CompilerBase extends \PhpAot\Core\Translator if ($var->default) { $initState = self::STATIC_VAR . $varName . '_initialized'; $initCode = $this->getIndent() . 'static bool ' . $initState . ' = false;'; - $initCode .= $this->getIndent() . "if (!$initState) { \n"; + $initCode .= $this->getIndent() . "if (!{$initState}) { \n"; $this->indentLevel++; - $initCode .= $this->getIndent() . "$initState = true;\n"; + $initCode .= $this->getIndent() . "{$initState} = true;\n"; $initCode .= $this->getIndent() . $this->getStaticVarName($varName) . ' = ' . $this->parseIdentifier($var->default) . ';'; $this->indentLevel--; $initCode .= $this->getIndent() . '}'; @@ -3116,8 +3115,6 @@ class CompilerBase extends \PhpAot\Core\Translator /** * 左值只能为变量、数组、对象属性、对象静态属性 - * @param NodeAbstract $expr - * @return void */ protected function checkLeftValue(NodeAbstract $expr): void { @@ -3173,7 +3170,7 @@ class CompilerBase extends \PhpAot\Core\Translator return array_key_exists($name, $this->globalVars); } - protected function hasStaticVar(string $name): bool + protected function hasStaticVar(string $name): bool { return array_key_exists($name, $this->staticVars); } @@ -3353,8 +3350,9 @@ class CompilerBase extends \PhpAot\Core\Translator if ($this->isTypedObject($var)) { $class = $this->getObjectType($var); goto _do_call; - } elseif ($this->getVarType($var) == self::TYPE_OBJECT) { - $fn = 'php::concat({' . $var . '.getClassName()' . ', "::", ' . $this->identifierToStr($expr->name) . '})'; + } + if ($this->getVarType($var) == self::TYPE_OBJECT) { + $fn = 'php::concat({' . $var . '.getClassName(), "::", ' . $this->identifierToStr($expr->name) . '})'; } else { $fn = 'php::concat({' . $this->identifierToStr($expr->class) . ', "::", ' . $this->identifierToStr($expr->name) . '})'; } @@ -3381,9 +3379,8 @@ class CompilerBase extends \PhpAot\Core\Translator } if ($args) { return self::PREFIX . $nativeFunc . '(php::null_object, ' . $args . ')'; - } else { - return self::PREFIX . $nativeFunc . '(php::null_object)'; } + return self::PREFIX . $nativeFunc . '(php::null_object)'; } } $ce = $this->getClassEntryPtr($class); @@ -3441,7 +3438,8 @@ class CompilerBase extends \PhpAot\Core\Translator $propertyDef = $classDef->getProperty($property); if ($propertyDef->isPublic()) { return self::PREFIX . $this->getPropertyOffset($property, $classDef->name, $classDef->namespace); - } elseif ($propertyDef->isProtected()) { + } + if ($propertyDef->isProtected()) { if ($scope) { return self::PREFIX . $this->getPropertyOffset($property, $classDef->name, $classDef->namespace); } @@ -3861,13 +3859,13 @@ class CompilerBase extends \PhpAot\Core\Translator { if ($this->functionDef->returnType === self::TYPE_VOID) { return ''; - } elseif ($this->functionDef->returnType === self::TYPE_INT + } + if ($this->functionDef->returnType === self::TYPE_INT or $this->functionDef->returnType === self::TYPE_FLOAT or $this->functionDef->returnType === self::TYPE_BOOL) { return $this->getIndent() . 'return 0;'; - } else { - return $this->getIndent() . 'return ' . self::VALUE_NULL . ';'; } + return $this->getIndent() . 'return ' . self::VALUE_NULL . ';'; } protected function genEmbeddedCode(NodeAbstract $stmt): string diff --git a/src/Php/Exception/PlaceHolder.php b/src/Php/Exception/PlaceHolder.php index 4b1b9327..d4aa2450 100644 --- a/src/Php/Exception/PlaceHolder.php +++ b/src/Php/Exception/PlaceHolder.php @@ -1,8 +1,13 @@ errorUndefinedVariable($useItem->var); } if ($useItem->byRef) { - $useVars [] = $this->convertToRef($useItem->var); + $useVars[] = $this->convertToRef($useItem->var); } else { - $useVars [] = $var; + $useVars[] = $var; } } } if ($this->methodDef) { return 'php::newClosure(' . $tmpVar . ', { ' . implode(', ', $useVars) . ' }, this_)'; - } else { - return 'php::newClosure(' . $tmpVar . ', { ' . implode(', ', $useVars) . ' })'; } + return 'php::newClosure(' . $tmpVar . ', { ' . implode(', ', $useVars) . ' })'; } } diff --git a/src/Php/Generator/PlaceHolderGenerator.php b/src/Php/Generator/PlaceHolderGenerator.php index 422a0959..af609a13 100644 --- a/src/Php/Generator/PlaceHolderGenerator.php +++ b/src/Php/Generator/PlaceHolderGenerator.php @@ -1,10 +1,13 @@ foundStrayCode($v); + // no break default: $this->fatalError($v, 'Unsupported statement: ' . $type); } @@ -148,6 +149,7 @@ class Preprocessor extends CompilerBase break; case 'Stmt_Expression': $this->foundStrayCode($v2); + // no break default: abort($v2); } @@ -183,6 +185,7 @@ class Preprocessor extends CompilerBase break; case 'Stmt_Expression': $this->foundStrayCode($v); + // no break default: abort($v); } diff --git a/src/Php/Reflection.php b/src/Php/Reflection.php index 9bf6e3f2..ee8a29ec 100644 --- a/src/Php/Reflection.php +++ b/src/Php/Reflection.php @@ -8,23 +8,17 @@ namespace PhpAot\Php; -use ReflectionClass; -use ReflectionException; -use ReflectionFunction; -use ReflectionParameter; -use ReflectionUnionType; - class Reflection { private static array $functions = []; private static array $classes = []; - public static function getFunction(string $fn): ?ReflectionFunction + public static function getFunction(string $fn): ?\ReflectionFunction { if (!isset(self::$functions[$fn])) { try { - $ref = new ReflectionFunction($fn); - } catch (ReflectionException $e) { + $ref = new \ReflectionFunction($fn); + } catch (\ReflectionException $e) { return null; } self::$functions[$fn] = $ref; @@ -33,12 +27,12 @@ class Reflection return self::$functions[$fn]; } - public static function getClass(string $className): ?ReflectionClass + public static function getClass(string $className): ?\ReflectionClass { if (!isset(self::$classes[$className])) { try { - $ref = new ReflectionClass($className); - } catch (ReflectionException $e) { + $ref = new \ReflectionClass($className); + } catch (\ReflectionException $e) { return null; } self::$classes[$className] = $ref; @@ -57,14 +51,14 @@ class Reflection if (!$returnType) { return null; } - if ($returnType instanceof ReflectionUnionType) { + if ($returnType instanceof \ReflectionUnionType) { return null; } return $returnType->getName(); } - public static function getFunctionParameter(string $fn, int $index): ?ReflectionParameter + public static function getFunctionParameter(string $fn, int $index): ?\ReflectionParameter { $func = self::getFunction($fn); if (!$func) { @@ -78,7 +72,7 @@ class Reflection return $args[$index]; } - public static function getClassMethodParameter(string $className, string $fn, int $index): ?ReflectionParameter + public static function getClassMethodParameter(string $className, string $fn, int $index): ?\ReflectionParameter { $classRef = self::getClass($className); if (!$classRef) { @@ -87,7 +81,7 @@ class Reflection try { $method = $classRef->getMethod($fn); - } catch (ReflectionException $e) { + } catch (\ReflectionException $e) { return null; } diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 1acedf43..b74d3f77 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -334,9 +334,8 @@ class Translator extends Preprocessor public function getArgInfoStubFilename(string $stubFile): string { - $rs = str_replace([".stub.php", '.php'], "", $stubFile); - $rs = str_replace('-', '_', $rs); - return $rs; + $rs = str_replace(['.stub.php', '.php'], '', $stubFile); + return str_replace('-', '_', $rs); } public function getArgInfoHeaderFile(string $stubFilenameWithoutExtension, bool $relative = false): string diff --git a/src/Python/Translator.php b/src/Python/Translator.php index db1af2c9..65562b41 100644 --- a/src/Python/Translator.php +++ b/src/Python/Translator.php @@ -1,13 +1,19 @@ id; if (isset($this->keywordsMap[$id])) { return 'PyCore::' . $id; - } elseif (isset($this->definedFunctions[$id])) { + } + if (isset($this->definedFunctions[$id])) { return $id; - } elseif (isset($this->builtinTypes[$id])) { + } + if (isset($this->builtinTypes[$id])) { return '$builtins->' . $id; - } else { - return '$' . $id; } - // no break + return '$' . $id; + case 'Attribute': return $this->parseAttribute($fn->value) . '->' . $fn->attr; default: @@ -129,41 +136,45 @@ class Translator extends \PhpAot\Core\Translator } if (empty($args_list)) { - return "$fn()"; - } else { - return "$fn(" . implode(', ', $args_list) . ")"; + return "{$fn}()"; } + return "{$fn}(" . implode(', ', $args_list) . ')'; } public static function valueToRepr($v, $python = false) { if (is_string($v)) { $v = str_replace( - ["\\", "\n", "\r", "\t", "\v", "\x00", "\""], - ["\\\\", "\\n", "\\r", "\\t", "\\v", "\\x00", "\\\""], + ['\\', "\n", "\r", "\t", "\v", "\x00", '"'], + ['\\\\', '\\n', '\\r', '\\t', '\\v', '\\x00', '\\"'], $v ); - return "\"$v\""; - } elseif ($v === []) { + return "\"{$v}\""; + } + if ($v === []) { return '[]'; - } elseif (is_numeric($v)) { + } + if (is_numeric($v)) { if ($python) { if (is_infinite($v)) { return "float('inf')"; - } elseif (is_nan($v)) { + } + if (is_nan($v)) { return "float('nan')"; } } return strval($v); - } elseif (is_bool($v)) { + } + if (is_bool($v)) { return $python ? ($v ? 'True' : 'False') : ($v ? 'true' : 'false'); - } elseif (is_null($v)) { + } + if (is_null($v)) { return $python ? 'None' : 'null'; - } elseif (is_array($v)) { + } + if (is_array($v)) { return var_export($v, true); - } else { - return $python ? 'None' : 'null'; } + return $python ? 'None' : 'null'; } public function parseConstant($value): string @@ -249,16 +260,17 @@ class Translator extends \PhpAot\Core\Translator { if ($slice->_type == 'Constant') { return $this->parseConstant($slice); - } elseif ($slice->_type === 'Tuple') { + } + if ($slice->_type === 'Tuple') { return $this->parseTuple($slice); - } elseif ($slice->_type === 'Slice') { + } + if ($slice->_type === 'Slice') { $_args[] = $slice->lower ? $this->parseTarget($slice->lower) : 'null'; $_args[] = $slice->upper ? $this->parseTarget($slice->upper) : 'null'; $_args[] = $slice->step ? $this->parseTarget($slice->step) : 'null'; return 'PyCore::slice(' . implode(', ', $_args) . ')'; - } else { - abort($slice); } + abort($slice); } public function parseImportFrom($node): string @@ -268,7 +280,7 @@ class Translator extends \PhpAot\Core\Translator foreach ($node->names as $name) { $type = $name->name; $as = empty($name->asname) ? $type : $name->asname; - $imports[] = "\$$as = PyCore::import('$module')->$type"; + $imports[] = "\${$as} = PyCore::import('{$module}')->{$type}"; } return implode(';' . PHP_EOL, $imports); @@ -280,7 +292,7 @@ class Translator extends \PhpAot\Core\Translator foreach ($node->names as $name) { $module = $name->name; $as = empty($name->asname) ? $module : $name->asname; - $out .= $this->getIndent() . "\$$as = PyCore::import('$module');\n"; + $out .= $this->getIndent() . "\${$as} = PyCore::import('{$module}');\n"; } return $out; } @@ -348,10 +360,9 @@ class Translator extends \PhpAot\Core\Translator case 'Expr': if (is_string($node->value->value)) { return '/** ' . $node->value->value . ' */' . PHP_EOL; - } else { - return $this->parseValue($node->value) . ';'; } - // no break + return $this->parseValue($node->value) . ';'; + default: return $this->parseValue($node->value) . ';'; } @@ -468,15 +479,14 @@ class Translator extends \PhpAot\Core\Translator $op = $node->ctx->_type; $value = $this->parseValue($node->value); if ($node->ctx->_type == 'Store') { - return $value. '[' . $this->parseSlice($node->slice) . '] = $__value'; - } elseif ($op == 'Del') { + return $value . '[' . $this->parseSlice($node->slice) . '] = $__value'; + } + if ($op == 'Del') { return 'unset(' . $value . '[' . $this->parseSlice($node->slice) . '])'; - } else { - return $value . '[' . $this->parseSlice($node->slice) . ']'; } - } else { - abort($node); + return $value . '[' . $this->parseSlice($node->slice) . ']'; } + abort($node); } public function parseFor($node) @@ -502,13 +512,36 @@ class Translator extends \PhpAot\Core\Translator $fn = PHP_EOL . $this->getIndent() . 'function ' . $name . '(' . $args . ') {' . PHP_EOL; $this->indentLevel++; $fn .= $this->parseBody($node->body) . PHP_EOL; - ; + $this->indentLevel--; $fn .= $this->getIndent() . '}' . PHP_EOL . PHP_EOL; return $fn; } + public function parseBody($tree): string + { + $lines = []; + foreach ($tree as $node) { + $this->parseLine($node, $lines); + } + foreach ($lines as &$line) { + $line = $this->getIndent() . $line; + } + return implode(PHP_EOL, $lines); + } + + public function convert($tree): void + { + $this->prepare($tree); + $output = 'parseBody($tree->body); + echo $output; + echo PHP_EOL; + } + private function addLine($line, array &$lines) { if ($this->mode == 'cli' && STEP) { @@ -528,9 +561,9 @@ class Translator extends \PhpAot\Core\Translator $value = $this->parseValue($node->value); if ($node->targets[0]->_type == 'Subscript') { $this->addLine('$__value = ' . $value . ';', $lines); - $line = "$target;"; + $line = "{$target};"; } else { - $line = "$target = $value;"; + $line = "{$target} = {$value};"; } break; case 'AugAssign': @@ -610,29 +643,6 @@ class Translator extends \PhpAot\Core\Translator $this->addLine($line, $lines); } - public function parseBody($tree): string - { - $lines = []; - foreach ($tree as $node) { - $this->parseLine($node, $lines); - } - foreach ($lines as &$line) { - $line = $this->getIndent() . $line; - } - return implode(PHP_EOL, $lines); - } - - public function convert($tree): void - { - $this->prepare($tree); - $output = 'parseBody($tree->body); - echo $output; - echo PHP_EOL; - } - private function parseGenerators($generators, $recipient, &$captures) { $captures = []; @@ -686,9 +696,8 @@ class Translator extends \PhpAot\Core\Translator $op_str = $this->parseOp($op); if ($op_str) { return $left . ' ' . $op_str . '= ' . $right . ';'; - } else { - return $left . ' = $operator->' . strtolower($op) . '(' . $left . ' , ' . $right . ');'; } + return $left . ' = $operator->' . strtolower($op) . '(' . $left . ' , ' . $right . ');'; } private function parseBinOp($value) @@ -699,9 +708,8 @@ class Translator extends \PhpAot\Core\Translator $op_str = $this->parseOp($op); if ($op_str) { return $left . ' ' . $op_str . ' ' . $right; - } else { - return '$operator->' . strtolower($op) . '(' . $left . ' , ' . $right . ')'; } + return '$operator->' . strtolower($op) . '(' . $left . ' , ' . $right . ')'; } private function parseJoinedStr($value) @@ -738,7 +746,7 @@ class Translator extends \PhpAot\Core\Translator $call = $this->parseCall($call); $target = empty($target) ? '$__' : $this->parseTarget($target); $code .= $target . '__object = ' . $call . ';' . PHP_EOL; - ; + $code .= $target . ' = ' . $target . '__object->__enter__();' . PHP_EOL; $this->indentLevel++; $finally_code .= $this->getIndent() . $target . '__object->__exit__(null, null, null);' . PHP_EOL; @@ -782,7 +790,6 @@ class Translator extends \PhpAot\Core\Translator return 'new PyDict(' . $code . '])'; } - private function parseBoolOp($value) { switch ($value->op->_type) { @@ -948,11 +955,11 @@ class Translator extends \PhpAot\Core\Translator $format = $value->format_spec->values[0]->value; if ($format[0] == '.' and $format[-1] == 'f') { return 'round(' . $expr . ', ' . substr($format, 1, strlen($format) - 2) . ')'; - } elseif (str_contains($format, '%')) { + } + if (str_contains($format, '%')) { return $expr . '->strftime("' . $format . '")'; - } else { - throw new \RuntimeException("Unsupported format: $format"); } + throw new \RuntimeException("Unsupported format: {$format}"); } else { return $expr; } diff --git a/src/config/compiler_options.php b/src/config/compiler_options.php index 2518d1fa..19a9106d 100644 --- a/src/config/compiler_options.php +++ b/src/config/compiler_options.php @@ -1,4 +1,11 @@ [ 'prefix' => 'O', @@ -56,4 +63,4 @@ return [ 'description' => 'Enable debug info', 'required' => false, ], -]; \ No newline at end of file +]; diff --git a/src/functions.php b/src/functions.php index 7d2f371d..518db764 100644 --- a/src/functions.php +++ b/src/functions.php @@ -1,11 +1,17 @@ genIncludeHeaderFiles(); ?> // global vars globalVars as $name => $type): -?> - ; - +foreach ($this->globalVars as $name => $type) { + ?> + ; + // class register functions classCeList as $ce): -?> -zend_class_entry * ; - +foreach ($this->classCeList as $ce) { + ?> +zend_class_entry * ; + // class entry -zend_class_entry *classMap) . ']' ?>; +zend_class_entry *classMap) . ']'; ?>; // func -zend_function *funcMap) . ']' ?>; +zend_function *funcMap) . ']'; ?>; zend_class_entry *php_get_class(int class_id, const php::String &class_name) { - if (UNEXPECTED([class_id] == nullptr)) { - [class_id] = php::getClassEntrySafe(class_name); + if (UNEXPECTED([class_id] == nullptr)) { + [class_id] = php::getClassEntrySafe(class_name); } - return [class_id]; + return [class_id]; } zend_function *php_get_func(int func_id, const php::String &func_name) { - if (UNEXPECTED([func_id] == nullptr)) { - [func_id] = php::getFunction(func_name); + if (UNEXPECTED([func_id] == nullptr)) { + [func_id] = php::getFunction(func_name); } - return [func_id]; + return [func_id]; } zend_function *php_get_method(int func_id, const php::Str &method_name, int class_id, const php::Str &class_name) { - if (UNEXPECTED([func_id] == nullptr)) { + if (UNEXPECTED([func_id] == nullptr)) { auto ce = php_get_class(class_id, class_name); - [func_id] = php::getMethod(ce, method_name); + [func_id] = php::getMethod(ce, method_name); } - return [func_id]; + return [func_id]; } // literal strings -php::Str [] = { +php::Str [] = { literalStrings as $str => $index): -?> - php::String{ZEND_STRL("escapeString($str)?>"), true}, - +foreach ($this->literalStrings as $str => $index) { + ?> + php::String{ZEND_STRL("escapeString($str); ?>"), true}, + }; // constants nativeConstants as $name => $const): -?> -type?> ; - +foreach ($this->nativeConstants as $name => $const) { + ?> +type; ?> ; + // property offset classes as $classDef): - foreach ($classDef->properties as $propertyDef): -?> -uint32_t getPropertyOffset($propertyDef->name, $classDef->name, $classDef->namespace)?>; +foreach ($this->classes as $classDef) { + foreach ($classDef->properties as $propertyDef) { + ?> +uint32_t getPropertyOffset($propertyDef->name, $classDef->name, $classDef->namespace); ?>; // clang-format off static const zend_function_entry ext_functions[] = { functions as $functionDef): +foreach ($this->functions as $functionDef) { if ($this->buildMode === 'ext' and $functionDef->name === 'main') { continue; } $zif_name = $this->escapeZendFnName($functionDef->getNamespacedName()); -?> -namespace): ?> - ZEND_NAMED_FE("escapeString($functionDef->getNamespacedName())?>", ZEND_FN(), arginfo_) - - ZEND_FE(, arginfo_) - - + ?> +namespace) { ?> + ZEND_NAMED_FE("escapeString($functionDef->getNamespacedName()); ?>", ZEND_FN(), arginfo_) + + ZEND_FE(, arginfo_) + + ZEND_FE_END }; // clang-format on -PHP_MINIT_FUNCTION(getModuleName()?>) { +PHP_MINIT_FUNCTION(getModuleName(); ?>) { // class/interface class entries classCeList as $ce): +foreach ($this->classCeList as $ce) { $info = $this->classCeInfo[$ce] ?? $this->getInternalCeInfo($ce); -?> - = (); - + ?> + = (); + // register symbols registerSymbols as $registerSymbolFn): -?> - (module_number); - +foreach ($this->registerSymbols as $registerSymbolFn) { + ?> + (module_number); + return SUCCESS; } @@ -117,86 +118,86 @@ foreach ($this->registerSymbols as $registerSymbolFn): void php_app_init() { // register constants nativeConstants as $name => $const): -?> - = value ?>; - php::define("escapeString($const->name)?>", ); - +foreach ($this->nativeConstants as $name => $const) { + ?> + = value; ?>; + php::define("escapeString($const->name); ?>", ); + // global vars globalVars as $name => $type): -?> - php::initGlobal("", ); - +foreach ($this->globalVars as $name => $type) { + ?> + php::initGlobal("", ); + // property offset classes as $classDef): - foreach ($classDef->properties as $propertyDef): +foreach ($this->classes as $classDef) { + foreach ($classDef->properties as $propertyDef) { ?> - getPropertyOffset($propertyDef->name, $classDef->name, $classDef->namespace)?> = php::getPropertyOffset("getNamespacedName(false)?>", "name?>"); + getPropertyOffset($propertyDef->name, $classDef->name, $classDef->namespace); ?> = php::getPropertyOffset("getNamespacedName(false); ?>", "name; ?>"); } void php_app_clean() { globalVars as $name => $type) : -?> - .unset(); - php::unsetGlobal(""); - +foreach ($this->globalVars as $name => $type) { + ?> + .unset(); + php::unsetGlobal(""); + nativeConstants as $name => $const): +foreach ($this->nativeConstants as $name => $const) { if ($const->type !== Translator::TYPE_VAR) { continue; } -?> - .unset(); - + ?> + .unset(); + } -PHP_RINIT_FUNCTION(getModuleName()?>) { +PHP_RINIT_FUNCTION(getModuleName(); ?>) { php::request_init(); php_app_init(); -buildMode === 'bin'): ?> -functions['main']->argInfoList) == 2): ?> +buildMode === 'bin') { ?> +functions['main']->argInfoList) == 2) { ?> php::eval("global $argc, $argv; main($argc, $argv);"); - + php::eval("main();"); - - + + return SUCCESS; } -PHP_RSHUTDOWN_FUNCTION(getModuleName()?>) { +PHP_RSHUTDOWN_FUNCTION(getModuleName(); ?>) { php_app_clean(); php::request_shutdown(); return SUCCESS; } -zend_module_entry getModuleName()?>_module_entry = { +zend_module_entry getModuleName(); ?>_module_entry = { STANDARD_MODULE_HEADER, - "getModuleName()?>", + "getModuleName(); ?>", ext_functions, - PHP_MINIT(getModuleName()?>), + PHP_MINIT(getModuleName(); ?>), nullptr, - PHP_RINIT(getModuleName()?>), - PHP_RSHUTDOWN(getModuleName()?>), + PHP_RINIT(getModuleName(); ?>), + PHP_RSHUTDOWN(getModuleName(); ?>), nullptr, nullptr, STANDARD_MODULE_PROPERTIES, }; -buildMode === 'ext'): ?> -ZEND_GET_MODULE(getModuleName()?>); - -zend_module_entry *get_module() { - return &getModuleName() ?>_module_entry; +buildMode === 'ext') { ?> +ZEND_GET_MODULE(getModuleName(); ?>); + +zend_module_entry *get_module() { + return &getModuleName(); ?>_module_entry; } - \ No newline at end of file + \ No newline at end of file