From b091d2dad84af062d0425abc6fbaea09115f4933 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 27 Feb 2026 15:21:10 +0800 Subject: [PATCH] Revert "code format" This reverts commit b6d64407f31df188ef293fba765f0cbdbe95c857. --- src/Core/Translator.php | 8 +- src/Php/CompilerBase.php | 50 +++--- src/Php/Exception/PlaceHolder.php | 9 +- src/Php/Generator/ClosureGenerator.php | 19 ++- src/Php/Generator/PlaceHolderGenerator.php | 9 +- src/Php/Generator/Utils.php | 6 - src/Php/Preprocessor.php | 3 - src/Php/Reflection.php | 26 +-- src/Php/Translator.php | 5 +- src/Python/Translator.php | 149 ++++++++-------- src/config/compiler_options.php | 9 +- src/functions.php | 13 +- src/template/extension.cc.php | 187 ++++++++++----------- 13 files changed, 230 insertions(+), 263 deletions(-) diff --git a/src/Core/Translator.php b/src/Core/Translator.php index 55f4d1cf..0ff39ae1 100644 --- a/src/Core/Translator.php +++ b/src/Core/Translator.php @@ -1,18 +1,12 @@ 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,7 +452,6 @@ 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); } @@ -623,7 +622,7 @@ class CompilerBase extends \PhpAot\Core\Translator } } else { if ($this->function) { - $prefix .= $this->function . '_'; + $prefix .= $this->function . '_'; } } return $prefix . $name; @@ -725,13 +724,14 @@ class CompilerBase extends \PhpAot\Core\Translator return 'php_get_method(' . $funcId . ', ' . $this->getLiteralString($method) . ', ' . $classId . ', ' . $this->getLiteralString($class) . ')'; } - protected function parseTypeDecl(?NodeAbstract $type): string + protected function parseTypeDecl(NodeAbstract|null $type): string { // 联合类型暂时不支持,使用 var 类型代替 - if ($type instanceof UnionType or $type instanceof NullableType) { + if ($type instanceof Node\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,7 +1057,6 @@ class CompilerBase extends \PhpAot\Core\Translator break; case 'Stmt_Class': $this->fatalError($v, 'Cannot declare class in function'); - // no break default: abort($v); } @@ -1352,8 +1351,9 @@ 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,8 +2070,9 @@ 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); @@ -3011,9 +3012,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() . '}'; @@ -3115,6 +3116,8 @@ class CompilerBase extends \PhpAot\Core\Translator /** * 左值只能为变量、数组、对象属性、对象静态属性 + * @param NodeAbstract $expr + * @return void */ protected function checkLeftValue(NodeAbstract $expr): void { @@ -3170,7 +3173,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); } @@ -3350,9 +3353,8 @@ class CompilerBase extends \PhpAot\Core\Translator if ($this->isTypedObject($var)) { $class = $this->getObjectType($var); goto _do_call; - } - if ($this->getVarType($var) == self::TYPE_OBJECT) { - $fn = 'php::concat({' . $var . '.getClassName(), "::", ' . $this->identifierToStr($expr->name) . '})'; + } elseif ($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) . '})'; } @@ -3379,8 +3381,9 @@ 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); @@ -3438,8 +3441,7 @@ class CompilerBase extends \PhpAot\Core\Translator $propertyDef = $classDef->getProperty($property); if ($propertyDef->isPublic()) { return self::PREFIX . $this->getPropertyOffset($property, $classDef->name, $classDef->namespace); - } - if ($propertyDef->isProtected()) { + } elseif ($propertyDef->isProtected()) { if ($scope) { return self::PREFIX . $this->getPropertyOffset($property, $classDef->name, $classDef->namespace); } @@ -3859,13 +3861,13 @@ class CompilerBase extends \PhpAot\Core\Translator { if ($this->functionDef->returnType === self::TYPE_VOID) { return ''; - } - if ($this->functionDef->returnType === self::TYPE_INT + } elseif ($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 d4aa2450..4b1b9327 100644 --- a/src/Php/Exception/PlaceHolder.php +++ b/src/Php/Exception/PlaceHolder.php @@ -1,13 +1,8 @@ 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 af609a13..422a0959 100644 --- a/src/Php/Generator/PlaceHolderGenerator.php +++ b/src/Php/Generator/PlaceHolderGenerator.php @@ -1,13 +1,10 @@ foundStrayCode($v); - // no break default: $this->fatalError($v, 'Unsupported statement: ' . $type); } @@ -149,7 +148,6 @@ class Preprocessor extends CompilerBase break; case 'Stmt_Expression': $this->foundStrayCode($v2); - // no break default: abort($v2); } @@ -185,7 +183,6 @@ 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 ee8a29ec..9bf6e3f2 100644 --- a/src/Php/Reflection.php +++ b/src/Php/Reflection.php @@ -8,17 +8,23 @@ 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; @@ -27,12 +33,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; @@ -51,14 +57,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) { @@ -72,7 +78,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) { @@ -81,7 +87,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 b74d3f77..1acedf43 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -334,8 +334,9 @@ class Translator extends Preprocessor public function getArgInfoStubFilename(string $stubFile): string { - $rs = str_replace(['.stub.php', '.php'], '', $stubFile); - return str_replace('-', '_', $rs); + $rs = str_replace([".stub.php", '.php'], "", $stubFile); + $rs = str_replace('-', '_', $rs); + return $rs; } public function getArgInfoHeaderFile(string $stubFilenameWithoutExtension, bool $relative = false): string diff --git a/src/Python/Translator.php b/src/Python/Translator.php index 65562b41..db1af2c9 100644 --- a/src/Python/Translator.php +++ b/src/Python/Translator.php @@ -1,19 +1,13 @@ id; if (isset($this->keywordsMap[$id])) { return 'PyCore::' . $id; - } - if (isset($this->definedFunctions[$id])) { + } elseif (isset($this->definedFunctions[$id])) { return $id; - } - if (isset($this->builtinTypes[$id])) { + } elseif (isset($this->builtinTypes[$id])) { return '$builtins->' . $id; + } else { + return '$' . $id; } - return '$' . $id; - + // no break case 'Attribute': return $this->parseAttribute($fn->value) . '->' . $fn->attr; default: @@ -136,45 +129,41 @@ class Translator extends \PhpAot\Core\Translator } if (empty($args_list)) { - return "{$fn}()"; + return "$fn()"; + } else { + return "$fn(" . implode(', ', $args_list) . ")"; } - 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}\""; - } - if ($v === []) { + return "\"$v\""; + } elseif ($v === []) { return '[]'; - } - if (is_numeric($v)) { + } elseif (is_numeric($v)) { if ($python) { if (is_infinite($v)) { return "float('inf')"; - } - if (is_nan($v)) { + } elseif (is_nan($v)) { return "float('nan')"; } } return strval($v); - } - if (is_bool($v)) { + } elseif (is_bool($v)) { return $python ? ($v ? 'True' : 'False') : ($v ? 'true' : 'false'); - } - if (is_null($v)) { + } elseif (is_null($v)) { return $python ? 'None' : 'null'; - } - if (is_array($v)) { + } elseif (is_array($v)) { return var_export($v, true); + } else { + return $python ? 'None' : 'null'; } - return $python ? 'None' : 'null'; } public function parseConstant($value): string @@ -260,17 +249,16 @@ class Translator extends \PhpAot\Core\Translator { if ($slice->_type == 'Constant') { return $this->parseConstant($slice); - } - if ($slice->_type === 'Tuple') { + } elseif ($slice->_type === 'Tuple') { return $this->parseTuple($slice); - } - if ($slice->_type === 'Slice') { + } elseif ($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 @@ -280,7 +268,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); @@ -292,7 +280,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; } @@ -360,9 +348,10 @@ 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) . ';'; } - return $this->parseValue($node->value) . ';'; - + // no break default: return $this->parseValue($node->value) . ';'; } @@ -479,14 +468,15 @@ 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'; - } - if ($op == 'Del') { + return $value. '[' . $this->parseSlice($node->slice) . '] = $__value'; + } elseif ($op == 'Del') { return 'unset(' . $value . '[' . $this->parseSlice($node->slice) . '])'; + } else { + return $value . '[' . $this->parseSlice($node->slice) . ']'; } - return $value . '[' . $this->parseSlice($node->slice) . ']'; + } else { + abort($node); } - abort($node); } public function parseFor($node) @@ -512,36 +502,13 @@ 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) { @@ -561,9 +528,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': @@ -643,6 +610,29 @@ 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 = []; @@ -696,8 +686,9 @@ 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) @@ -708,8 +699,9 @@ 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) @@ -746,7 +738,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; @@ -790,6 +782,7 @@ class Translator extends \PhpAot\Core\Translator return 'new PyDict(' . $code . '])'; } + private function parseBoolOp($value) { switch ($value->op->_type) { @@ -955,11 +948,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) . ')'; - } - if (str_contains($format, '%')) { + } elseif (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 19a9106d..2518d1fa 100644 --- a/src/config/compiler_options.php +++ b/src/config/compiler_options.php @@ -1,11 +1,4 @@ [ 'prefix' => 'O', @@ -63,4 +56,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 518db764..7d2f371d 100644 --- a/src/functions.php +++ b/src/functions.php @@ -1,17 +1,11 @@ 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; } @@ -118,86 +117,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