Commit graph

313 commits

Author SHA1 Message Date
Daniel Scherzer
54863f4930
gen_stub: Update PHP-Parser to 5.6.0 (#19271)
Includes support for declaring functions named `clone`, so update the stub file
where `clone` is declared to remove the `_clone` workaround.
2025-07-29 07:47:58 -07:00
Daniel Scherzer
ff810d5e36
Arginfo: reuse zend_string objects for initializing attribute values (#19241)
Avoid initializing the same string content multiple times and make use of the
fact that the strings created to initialize attribute values are not freed by
simply making use of an existing zend_string with the same content if one is
available.
2025-07-27 17:27:22 -07:00
Daniel Scherzer
747ecce51f gen_stub: simplify ClassInfo::getRegistration() 2025-07-25 11:17:34 -07:00
Daniel Scherzer
74f7ecbe04 gen_stub: add ConstInfo::getPredefinedConstantElement()
Simplifies the implementation of `::getPredefinedConstantTerm()` and
`::getPredefinedConstantEntry()`, which only differ in the name of the tag
used.
2025-07-25 11:17:34 -07:00
Daniel Scherzer
5ae87ffef4 gen_stub: avoid unneeded regex match 2025-07-25 11:17:34 -07:00
Daniel Scherzer
ecc403a8fa gen_stub: inline computeStubHash() 2025-07-25 11:17:34 -07:00
Daniel Scherzer
2ed5472f06 gen_stub: make some FuncInfo methods private
* `FuncInfo::isFinalMethod()`
* `FuncInfo::getModifierNames()`
* `FuncInfo::equalsApartFromNameAndRefcount()`
2025-07-25 11:17:34 -07:00
Daniel Scherzer
0b01640b58 gen_stub: replace FunctionOrMethodName::isMethod() with instanceof 2025-07-25 11:17:34 -07:00
Daniel Scherzer
49f1685cde gen_stub: simplify FuncInfo::getFramelessDeclaration() 2025-07-25 11:17:34 -07:00
Daniel Scherzer
988da4c951 gen_stub: simplify FuncInfo::getFunctionEntry() 2025-07-25 11:17:34 -07:00
Daniel Scherzer
9dfee95dae gen_stub: add SimpleType::toTypeInfo()
Simplifies the implementation of `::toTypeCode()` and `::toTypeMask()` by
combining the `switch` blocks.
2025-07-25 11:17:34 -07:00
Daniel Scherzer
e5d4d656ab gen_stub: replace AbstractConstName::isClassConst() with instanceof 2025-07-25 11:17:34 -07:00
Daniel Scherzer
8bd8223bad gen_stub: remove unused AbstractConstName::equals() 2025-07-25 11:17:34 -07:00
Daniel Scherzer
15547a2eb1 gen_stub: simplify generateFunctionEntries() 2025-07-25 11:17:34 -07:00
Daniel Scherzer
30c8480a39 gen_stub: move getFileDocComments() into FileInfo
Reduce the number of global functions by moving it to static method
`FileInfo::getFileDocComments()`. Since it is only used by
`FileInfo::parseStubFile()`, also make it private.
2025-07-25 11:17:34 -07:00
Daniel Scherzer
24d94197fd gen_stub: move generateClassEntryCode() into FileInfo
Reduce the number of global functions by moving it to instance method
`FileInfo::generateClassEntryCode()`.
2025-07-25 11:17:34 -07:00
Daniel Scherzer
0d221c5b70 gen_stub: create VersionFlags class
This new class holds the logic for applying different flags based on the PHP
version, and replaces `VariableLike::addFlagForVersionsAbove()` (use
`VersionFlags::addForVersionsAbove()`) and `generateVersionDependentFlagCode()`
(use `VersionFlags::generateVersionDependentFlagCode()`).
2025-07-25 11:17:34 -07:00
Daniel Scherzer
1218e39b07 gen_stub: add maximum option to generateVersionDependentFlagCode()
In preparation for moving this logic to a dedicated class, add support for a
maximum version of PHP in the generation of version-dependent flags. This
replaces the manual logic in `FuncInfo::getFunctionEntry()` to split up the
flags that are used when PHP 8.4 is not supported.
2025-07-25 11:17:34 -07:00
DanielEScherzer
1eadf553f1
Arginfo: avoid using temporary zvals for initializing attribute values (#19141)
Instead of
* adding a zval on the stack
* initializing it
* copying the value to the attribute

Just initialize the value directly in the zend_attribute_arg
2025-07-21 13:33:51 -07:00
Daniel Scherzer
142e378618 Arginfo: add and use known strings for attribute values 2025-07-14 17:31:22 -07:00
Daniel Scherzer
0c920ecb07 gen_stub: use StringBuilder for attribute strings 2025-07-14 17:31:22 -07:00
Daniel Scherzer
ecdff3b563 gen_stub: add StringBuilder class for managing known strings
Split out from the PropertyInfo class so that known strings can also be used
for attributes in a follow-up commit.
2025-07-14 17:31:22 -07:00
DanielEScherzer
9225cb45ac
Make zend_register_*_constant() functions return pointers, use them (#19029)
Have each of the specialized methods for registering a constant return a
pointer to the registered constant the same way that the generic
`zend_register_constant()` function does, and use those in the generated
arginfo files to avoid needing to search for a constant that was just
registered in order to add attributes to it.
2025-07-07 12:23:52 -07:00
Saki Takamachi
8b61c49987
Allowed the use of formats like @param array<> (#18924) 2025-06-25 18:36:20 +09:00
Tim Düsterhus
ca49a7bec2
RFC: Turn clone() into a function (#18919)
RFC: https://wiki.php.net/rfc/clone_with_v2

Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>
2025-06-24 20:14:40 +02:00
DanielEScherzer
ddd33fd7e4
Generated arginfo headers: combine preprocessor conditional blocks (2) (#18667)
When global constants' or class constants' availability is based on some
preprocessor condition, the generated arginfo header files wrap the
declarations in the preprocessor `#if` conditional blocks, one per declaration,
even if they are in the same conditional block based on comments in the stub
file. Instead of having multiple conditional blocks one after the other with
the same condition, combine them into a single conditional block.
2025-06-22 14:35:28 -07:00
Tim Düsterhus
5f9a0b568b
gen_stub: Fix undefined variable warning (#18821)
> PHP Warning:  Undefined variable $code in build/gen_stub.php on line 5322

Introduced in php/php-src#18735.
2025-06-10 15:28:34 +02:00
Máté Kocsis
3399235bec
Add Uri\WhatWg classes to ext/uri (#18672)
Relates to #14461 and https://wiki.php.net/rfc/url_parsing_api

Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
Co-authored-by: Tim Düsterhus <tim@tideways-gmbh.com>
2025-06-10 10:18:22 +02:00
DanielEScherzer
8f3cdf6236
gen_stub: Add support for attributes on constants in stubs (#18735)
Update to PHP-Parser 5.5.0 and add support for attributes on constants in
stubs. For now, I have only migrated over E_STRICT, once the support is in
place I'll do a larger migration of the existing deprecated constants.

In the process, fix the logic in `copy_zend_constant()` for copying attributes
when a constant is copied; just increase the reference count for the attributes
table rather than trying to duplicate the contents.
2025-06-05 14:46:46 -07:00
Tim Düsterhus
73c4e9f0b2
Merge branch 'PHP-8.4'
* PHP-8.4:
  gen_stub: Fix `ce_flags` generation for compatibility mode (#18507)
2025-05-09 13:33:58 +02:00
Tim Düsterhus
84f82d0a1c
gen_stub: Fix ce_flags generation for compatibility mode (#18507)
* gen_stub: Fix `ce_flags` generation for compatibility mode

Fixes php/php-src#18506

* gen_stub: Improve output for ce_flags compatibility
2025-05-09 13:33:09 +02:00
Daniel Scherzer
2b0cb760d4 gen_stub: move parseStubFile() into FileInfo
Reduce the number of global functions by moving it to static method
`FileInfo::parseStubFile()`. Additionally, make `FileInfo::handleStatements()`
private now that the only caller is part of the class.
2025-05-08 13:06:51 -07:00
Daniel Scherzer
05dbf0707a gen_stub: further reduce the number of public properties
The following properties are made private:
* `ArgInfo::$phpDocType`
* `ClassInfo::$flags`, `::$attributes`, `::$extends`, `::$implements`
* `FileInfo::$isUndocumentable`

The following are made protected:
* `VariableLike::$flags`
2025-05-08 13:06:51 -07:00
Daniel Scherzer
c89d7a7426 gen_stub: add and use FileInfo::getLegacyVersion()
Separate out the creation of a legacy version of a FileInfo object, which has
information for old versions of PHP discarded, from its subsequent use in
`processStubFile()`.

In the process, make `FileInfo::$legacyArginfoGeneration` private, and inline
the single use of `FileInfo::getAllClassInfos()`, removing that method.
2025-05-08 13:06:51 -07:00
Daniel Scherzer
bb555926c4 gen_stub: deduplicate and simplify DocCommentTag processing
For a lot of the structures, the parsing of doc comment tags is based on if a
specific tag is present, or the value that it has if it is. Add a new helper
method, `DocCommentTag::makeTagMap()`, that turns an array of tag instances
into a map from tag name to value (the last value, if there are multiple uses
of the same tag name). Then, for the simple cases where just a tag's presence
is all that is checked, or just the (last) value is used, check the map instead
of using a loop through all of the tags present.
2025-05-08 13:06:51 -07:00
Daniel Scherzer
d42bac2866 gen_stub: move parseDocComments() into DocCommentTag
Reduce the number of global functions by moving it to static method
`DocCommentTag::parseDocComments()`.
2025-05-08 13:06:51 -07:00
Daniel Scherzer
ce3990c1d3 gen_stub: move handlePreprocessorConditions() into FileInfo()
Reduce the number of global functions by moving it to static method
`FileInfo::handlePreprocessorConditions()`. Since it is only used by
`FileInfo::handleStatements()`, also make it private.
2025-05-08 13:06:51 -07:00
Daniel Scherzer
1c9b6b84df gen_stub: move handleStatements() into FileInfo
Reduce the number of global functions by moving it to instance method
`FileInfo::handleStatements()`.
2025-05-08 13:06:51 -07:00
Daniel Scherzer
ec3ecdc2c8 gen_stub: documentation updates
* Use `@param` instead of `@var` for parameters
* Fix type of `$attributeGroups` in `AttributeInfo::createFromGroups()`
* Remove extra documentation of `$allConstInfo` for
`ClassInfo::getClassSynopsisDocument()`, it is already documented under the
correct name `$allConstInfos`
* Remove unneeded `@throws`
2025-05-08 13:06:51 -07:00
Daniel Scherzer
722eba20ae gen_stub: drop unused parameters
The following parameters were either unused before this commit or became unused
as part of updating callers to stop passing unused parameters to other
functions updated in this commit:
* `FuncInfo::getMethodSynopsisDocument()` - `$funcMap`, `$aliasMap`
* `FuncInfo::getMethodSynopsisElement()` - `$funcMap`, `$aliasMap`
* `ConstInfo::getGlobalConstDeclaration()` - `$allConstInfos`
* `generateMethodSynopses()` - `$aliasMap`
* `replaceMethodSynopses()` - `$aliasMap`
2025-05-08 13:06:51 -07:00
Daniel Scherzer
4861391501 gen_stub: inline some single-use variables 2025-05-08 13:06:51 -07:00
Daniel Scherzer
39a6d6086e gen_stub: move funcInfoToCode() into FuncInfo
Reduce the number of global functions by moving it to instance method
`FuncInfo::toArgInfoCode()`.

In the process, make `FuncInfo::$numRequiredArgs` private.
2025-05-08 13:06:51 -07:00
Daniel Scherzer
b5361d75e0 gen_stub: add ReturnInfo::beginArgInfo()
The vast majority of the decisions about the use of `ZEND_BEGIN_ARG_INFO_EX` or
one of its variations are based on the return information of the function - is
the type builtin, is the return information tentative, does it include an
object mask, etc. Accordingly, move the logic into the `ReturnInfo` class.

The logic is actually moved into two methods, `ReturnInfo::beginArgInfo()`,
which needs to handle the case of tentative returns being used when PHP < 8.1
is supported, and `::beginArgInfoCompatible()`, which can assume that PHP 8.1+
is supported and thus make use of early returns and guard clauses. Further
improvements to the logic will be made in a subsequent commit.

In the process, make `ReturnInfo::$byRef` private.
2025-05-08 13:06:51 -07:00
Daniel Scherzer
24b7c7a365 gen_stub: add ArgInfo::toZendInfo()
Move the logic out of `funcInfoToCode()` and update it. In the process, make
`ArgInfo::getDefaultValueAsArginfoString()` private.
2025-05-08 13:06:51 -07:00
Daniel Scherzer
0d79039027 gen_stub: simplify ArgInfo::getDefaultValueAsMethodSynopsisString()
There is no need to add special handling for the default value of `null`, since
it is not loosely-equals to any of the strings 'UNKNOWN', 'false', 'true', or
'null' it will just be returned directly anyway.
2025-05-08 13:06:51 -07:00
Daniel Scherzer
45d313bbd7 gen_stub: simplify generateVersionDependentFlagCode()
* Return a string rather than an array, all callers just immediately used
`implode()` to join the elements in the array with nothing between them
* In the callers, inline some single-use variables with the template for the
version-dependent code
* Remove the callback to `array_filter` specifying that only items that are not
`empty()` be removed - this is the default behavior
2025-05-08 13:06:51 -07:00
Daniel Scherzer
bfa2b92ca6 gen_stub: add ExposedDocComment::getInitCode()
Deduplicates the setting up of the `zend_string_init_interned()` call, removes
the need for `ExposedDocComment::getLength()` and so that method is removed.
2025-05-08 13:06:51 -07:00
Daniel Scherzer
4527bafad0 gen_stub: break up closing tag in DOMCdataSection
Otherwise GitHub's syntax highlighting treats it as the end of the code and
stops highlighting
2025-05-08 13:06:51 -07:00
DanielEScherzer
940ee1a641
gen_stub: ZEND_ACC_NODISCARD is for PHP 8.5+ (#18465) 2025-05-04 15:08:37 -07:00
Máté Kocsis
93a3256da8 Fix GH-18108 gen_stub: Using $this when not in object context 2025-04-15 20:56:11 +02:00