@ -16,14 +16,6 @@ use PhpParser\Node\Stmt\Trait_;
use PhpParser\PrettyPrinter\Standard;
use PhpParser\PrettyPrinterAbstract;
error_reporting(E_ALL);
ini_set("precision", "-1");
require __DIR__ . '/bootstrap.php';
$translator = new PhpAot\Php\Translator(ROOT_PATH);
$translator->setIndent("\t");
$translator->setIndentLevel(1);
const PHP_70_VERSION_ID = 70000;
const PHP_80_VERSION_ID = 80000;
const PHP_81_VERSION_ID = 80100;
@ -94,6 +86,7 @@ function processStubFile(string $stubFile, Context $context, bool $includeOnly =
$oldStubHash = extractStubHash($arginfoFile);
if ($stubHash === $oldStubHash & & !$context->forceParse) {
/* Stub file did not change, do not regenerate. */
echo "Skipping $stubFile, stub hash unchanged\n";
return null;
}
}
@ -4238,11 +4231,16 @@ class FileInfo {
/**
* @return iterable< FuncInfo >
*/
public function getAllFuncInfos(): iterable {
yield from $this->funcInfos;
public function getAllFuncInfos(): iterable
{
global $genClass;
if ($genClass) {
foreach ($this->classInfos as $classInfo) {
yield from $classInfo->funcInfos;
}
} else {
yield from $this->funcInfos;
}
}
/** @return array< string , ConstInfo > */
@ -5171,6 +5169,8 @@ function generateArgInfoCode(
$generatedFuncInfos = [];
global $genClass;
$argInfoCode = generateCodeWithConditions(
$fileInfo->getAllFuncInfos(), "\n",
static function (FuncInfo $funcInfo) use (& $generatedFuncInfos, $fileInfo) {
@ -5221,14 +5221,16 @@ function generateArgInfoCode(
$code .= generateFunctionEntries(null, $fileInfo->funcInfos);
if ($genClass) {
foreach ($fileInfo->classInfos as $classInfo) {
$code .= generateFunctionEntries($classInfo->name, $classInfo->funcInfos, $classInfo->cond);
}
}
}
$php80MinimumCompatibility = $fileInfo->getMinimumPhpVersionIdCompatibility() === null || $fileInfo->getMinimumPhpVersionIdCompatibility() >= PHP_80_VERSION_ID;
if ($fileInfo->generateClassEntries) {
if ($genClass and $ fileInfo->generateClassEntries) {
$declaredStrings = [];
$attributeInitializationCode = generateFunctionAttributeInitialization($fileInfo->funcInfos, $allConstInfos, $fileInfo->getMinimumPhpVersionIdCompatibility(), null, $declaredStrings);
$attributeInitializationCode .= generateGlobalConstantAttributeInitialization($fileInfo->constInfos, $allConstInfos, $fileInfo->getMinimumPhpVersionIdCompatibility(), null, $declaredStrings);
@ -6097,61 +6099,82 @@ function initPhpParser() {
$isInitialized = true;
}
$optind = null;
$options = getopt(
function main()
{
global $argv, $argc, $genClass, $translator;
error_reporting(E_ALL);
ini_set("precision", "-1");
require __DIR__ . '/bootstrap.php';
$translator = new PhpAot\Php\Translator(ROOT_PATH);
$translator->setIndent("\t");
$translator->setIndentLevel(1);
$opt_index = 0;
$options = getopt(
"fh",
[
"force-regeneration", "parameter-stats", "help", "verify", "verify-manual", "replace-predefined-constants",
"generate-classsynopses", "replace-classsynopses", "generate-methodsynopses", "replace-methodsynopses",
"generate-optimizer-info",
"generate-optimizer-info", "gen-class-info", "gen-func -info",
],
$optind
);
$context = new Context;
$printParameterStats = isset($options["parameter-stats"]);
$verify = isset($options["verify"]);
$verifyManual = isset($options["verify-manual"]);
$replacePredefinedConstants = isset($options["replace-predefined-constants"]);
$generateClassSynopses = isset($options["generate-classsynopses"]);
$replaceClassSynopses = isset($options["replace-classsynopses"]);
$generateMethodSynopses = isset($options["generate-methodsynopses"]);
$replaceMethodSynopses = isset($options["replace-methodsynopses"]);
$generateOptimizerInfo = isset($options["generate-optimizer-info"]);
$context->forceRegeneration = isset($options["f"]) || isset($options["force-regeneration"]);
$context->forceParse = $context->forceRegeneration || $printParameterStats || $verify || $verifyManual || $replacePredefinedConstants || $generateClassSynopses || $generateOptimizerInfo || $replaceClassSynopses || $generateMethodSynopses || $replaceMethodSynopses;
if (isset($options["h"]) || isset($options["help"])) {
$opt_index
);
$context = new Context;
$printParameterStats = isset($options["parameter-stats"]);
$verify = isset($options["verify"]);
$verifyManual = isset($options["verify-manual"]);
$replacePredefinedConstants = isset($options["replace-predefined-constants"]);
$generateClassSynopses = isset($options["generate-classsynopses"]);
$replaceClassSynopses = isset($options["replace-classsynopses"]);
$generateMethodSynopses = isset($options["generate-methodsynopses"]);
$replaceMethodSynopses = isset($options["replace-methodsynopses"]);
$generateOptimizerInfo = isset($options["generate-optimizer-info"]);
if (isset($options["gen-class-info"])) {
$genClass = true;
} elseif (isset($options["gen-func-info"])) {
$genClass = false;
} else {
die("Please specify whether to generate class or function info\n");
}
$context->forceRegeneration = isset($options["f"]) || isset($options["force-regeneration"]);
$context->forceParse = $context->forceRegeneration || $printParameterStats || $verify || $verifyManual || $replacePredefinedConstants || $generateClassSynopses || $generateOptimizerInfo || $replaceClassSynopses || $generateMethodSynopses || $replaceMethodSynopses;
if (isset($options["h"]) || isset($options["help"])) {
die("\nUsage: gen_stub.php [ -f | --force-regeneration ] [ --replace-predefined-constants ] [ --generate-classsynopses ] [ --replace-classsynopses ] [ --generate-methodsynopses ] [ --replace-methodsynopses ] [ --parameter-stats ] [ --verify ] [ --verify-manual ] [ --generate-optimizer-info ] [ -h | --help ] [ name.stub.php | directory ] [ directory ]\n\n");
}
}
$locations = array_slice($argv, $optind);
$locationCount = count($locations);
if ($replacePredefinedConstants & & $locationCount < 2 ) {
$locations = array_slice($argv, $opt_ index );
$locationCount = count($locations);
if ($replacePredefinedConstants & & $locationCount < 2 ) {
die("At least one source stub path and a target manual directory has to be provided:\n./build/gen_stub.php --replace-predefined-constants ./ ../doc-en/\n");
}
if ($replaceClassSynopses & & $locationCount < 2 ) {
}
if ($replaceClassSynopses & & $locationCount < 2 ) {
die("At least one source stub path and a target manual directory has to be provided:\n./build/gen_stub.php --replace-classsynopses ./ ../doc-en/\n");
}
if ($generateMethodSynopses & & $locationCount < 2 ) {
}
if ($generateMethodSynopses & & $locationCount < 2 ) {
die("At least one source stub path and a target manual directory has to be provided:\n./build/gen_stub.php --generate-methodsynopses ./ ../doc-en/\n");
}
if ($replaceMethodSynopses & & $locationCount < 2 ) {
}
if ($replaceMethodSynopses & & $locationCount < 2 ) {
die("At least one source stub path and a target manual directory has to be provided:\n./build/gen_stub.php --replace-methodsynopses ./ ../doc-en/\n");
}
if ($verifyManual & & $locationCount < 2 ) {
}
if ($verifyManual & & $locationCount < 2 ) {
die("At least one source stub path and a target manual directory has to be provided:\n./build/gen_stub.php --verify-manual ./ ../doc-en/\n");
}
$manualTarget = null;
if ($replacePredefinedConstants || $replaceClassSynopses || $generateMethodSynopses || $replaceMethodSynopses || $verifyManual) {
}
$manualTarget = null;
if ($replacePredefinedConstants || $replaceClassSynopses || $generateMethodSynopses || $replaceMethodSynopses || $verifyManual) {
$manualTarget = array_pop($locations);
}
if ($locations === []) {
}
if ($locations === []) {
$locations = ['.'];
}
}
$fileInfos = [];
foreach (array_unique($locations) as $location) {
$fileInfos = [];
foreach (array_unique($locations) as $location) {
if (is_file($location)) {
// Generate single file.
$fileInfo = processStubFile($location, $context);
@ -6164,9 +6187,9 @@ foreach (array_unique($locations) as $location) {
echo "$location is neither a file nor a directory.\n";
exit(1);
}
}
}
if ($printParameterStats) {
if ($printParameterStats) {
$parameterStats = [];
foreach ($fileInfos as $fileInfo) {
@ -6182,25 +6205,25 @@ if ($printParameterStats) {
arsort($parameterStats);
echo json_encode($parameterStats, JSON_PRETTY_PRINT), "\n";
}
}
/** @var array< string , ClassInfo > $classMap */
$classMap = [];
/** @var array< string , FuncInfo > $funcMap */
$funcMap = [];
/** @var array< string , FuncInfo > $aliasMap */
$aliasMap = [];
/** @var array< string , ClassInfo > $classMap */
$classMap = [];
/** @var array< string , FuncInfo > $funcMap */
$funcMap = [];
/** @var array< string , FuncInfo > $aliasMap */
$aliasMap = [];
/** @var array< string , ConstInfo > $undocumentedConstMap */
$undocumentedConstMap = [];
/** @var array< string , ClassInfo > $undocumentedClassMap */
$undocumentedClassMap = [];
/** @var array< string , FuncInfo > $undocumentedFuncMap */
$undocumentedFuncMap = [];
/** @var array< int , string > $methodSynopsisWarnings */
$methodSynopsisWarnings = [];
foreach ($fileInfos as $fileInfo) {
/** @var array< string , ConstInfo > $undocumentedConstMap */
$undocumentedConstMap = [];
/** @var array< string , ClassInfo > $undocumentedClassMap */
$undocumentedClassMap = [];
/** @var array< string , FuncInfo > $undocumentedFuncMap */
$undocumentedFuncMap = [];
/** @var array< int , string > $methodSynopsisWarnings */
$methodSynopsisWarnings = [];
foreach ($fileInfos as $fileInfo) {
foreach ($fileInfo->getAllFuncInfos() as $funcInfo) {
$funcMap[$funcInfo->name->__toString()] = $funcInfo;
@ -6217,9 +6240,9 @@ foreach ($fileInfos as $fileInfo) {
$classMap[$classInfo->alias] = $classInfo;
}
}
}
}
if ($verify) {
if ($verify) {
$errors = [];
foreach ($funcMap as $aliasFunc) {
@ -6302,9 +6325,9 @@ if ($verify) {
echo "\n";
exit(1);
}
}
}
if ($replacePredefinedConstants || $verifyManual) {
if ($replacePredefinedConstants || $verifyManual) {
$predefinedConstants = replacePredefinedConstants($manualTarget, $context->allConstInfos, $undocumentedConstMap);
if ($replacePredefinedConstants) {
@ -6312,9 +6335,9 @@ if ($replacePredefinedConstants || $verifyManual) {
reportFilePutContents($filename, $content);
}
}
}
}
if ($generateClassSynopses) {
if ($generateClassSynopses) {
$classSynopsesDirectory = getcwd() . "/classsynopses";
$classSynopses = generateClassSynopses($classMap, $context->allConstInfos);
@ -6327,9 +6350,9 @@ if ($generateClassSynopses) {
reportFilePutContents("$classSynopsesDirectory/$filename", $content);
}
}
}
}
if ($replaceClassSynopses || $verifyManual) {
if ($replaceClassSynopses || $verifyManual) {
$classSynopses = replaceClassSynopses($manualTarget, $classMap, $context->allConstInfos, $undocumentedClassMap);
if ($replaceClassSynopses) {
@ -6337,9 +6360,9 @@ if ($replaceClassSynopses || $verifyManual) {
reportFilePutContents($filename, $content);
}
}
}
}
if ($generateMethodSynopses) {
if ($generateMethodSynopses) {
$methodSynopses = generateMethodSynopses($funcMap);
if (!file_exists($manualTarget)) {
mkdir($manualTarget);
@ -6356,9 +6379,9 @@ if ($generateMethodSynopses) {
reportFilePutContents($path, $content);
}
}
}
}
if ($replaceMethodSynopses || $verifyManual) {
if ($replaceMethodSynopses || $verifyManual) {
$methodSynopses = replaceMethodSynopses($manualTarget, $funcMap, $verifyManual, $methodSynopsisWarnings, $undocumentedFuncMap);
if ($replaceMethodSynopses) {
@ -6366,16 +6389,16 @@ if ($replaceMethodSynopses || $verifyManual) {
reportFilePutContents($filename, $content);
}
}
}
}
if ($generateOptimizerInfo) {
if ($generateOptimizerInfo) {
$filename = dirname(__FILE__, 2) . "/Zend/Optimizer/zend_func_infos.h";
$optimizerInfo = generateOptimizerInfo($funcMap);
reportFilePutContents($filename, $optimizerInfo);
}
}
if ($verifyManual) {
if ($verifyManual) {
foreach ($undocumentedConstMap as $constName => $info) {
if ($info->name instanceof ClassConstName || $info->isUndocumentable) {
continue;
@ -6399,4 +6422,7 @@ if ($verifyManual) {
echo "Warning: Missing method synopsis for $functionName()\n";
}
}
}
}
main();