xref: /php-ast/ast_stub.php (revision 1fc2c3a1)
1<?php
2/**
3 * PHPDoc stub file for ast extension
4 * @author Bill Schaller <bill@zeroedin.com>
5 * @author Nikita Popov <nikic@php.net>
6 */
7
8// AST KIND CONSTANTS
9namespace ast;
10const AST_ARG_LIST = 128;
11const AST_LIST = 255;
12const AST_ARRAY = 129;
13const AST_ENCAPS_LIST = 130;
14const AST_EXPR_LIST = 131;
15const AST_STMT_LIST = 132;
16const AST_IF = 133;
17const AST_SWITCH_LIST = 134;
18const AST_CATCH_LIST = 135;
19const AST_PARAM_LIST = 136;
20const AST_CLOSURE_USES = 137;
21const AST_PROP_DECL = 138;
22const AST_CONST_DECL = 139;
23const AST_CLASS_CONST_DECL = 140;
24const AST_NAME_LIST = 141;
25const AST_TRAIT_ADAPTATIONS = 142;
26const AST_USE = 143;
27const AST_TYPE_UNION = 144;
28const AST_TYPE_INTERSECTION = 145;
29const AST_ATTRIBUTE_LIST = 146;
30const AST_ATTRIBUTE_GROUP = 147;
31const AST_MATCH_ARM_LIST = 148;
32const AST_NAME = 2048;
33const AST_CLOSURE_VAR = 2049;
34const AST_NULLABLE_TYPE = 2050;
35const AST_FUNC_DECL = 67;
36const AST_CLOSURE = 68;
37const AST_METHOD = 69;
38const AST_ARROW_FUNC = 71;
39const AST_CLASS = 70;
40const AST_MAGIC_CONST = 0;
41const AST_TYPE = 1;
42const AST_CALLABLE_CONVERT = 3;
43const AST_VAR = 256;
44const AST_CONST = 257;
45const AST_UNPACK = 258;
46const AST_CAST = 261;
47const AST_EMPTY = 262;
48const AST_ISSET = 263;
49const AST_SHELL_EXEC = 265;
50const AST_CLONE = 266;
51const AST_EXIT = 267;
52const AST_PRINT = 268;
53const AST_INCLUDE_OR_EVAL = 269;
54const AST_UNARY_OP = 270;
55const AST_PRE_INC = 271;
56const AST_PRE_DEC = 272;
57const AST_POST_INC = 273;
58const AST_POST_DEC = 274;
59const AST_YIELD_FROM = 275;
60const AST_GLOBAL = 277;
61const AST_UNSET = 278;
62const AST_RETURN = 279;
63const AST_LABEL = 280;
64const AST_REF = 281;
65const AST_HALT_COMPILER = 282;
66const AST_ECHO = 283;
67const AST_THROW = 284;
68const AST_GOTO = 285;
69const AST_BREAK = 286;
70const AST_CONTINUE = 287;
71const AST_CLASS_NAME = 276;
72const AST_CLASS_CONST_GROUP = 777;
73const AST_DIM = 512;
74const AST_PROP = 513;
75const AST_NULLSAFE_PROP = 514;
76const AST_STATIC_PROP = 515;
77const AST_CALL = 516;
78const AST_CLASS_CONST = 517;
79const AST_ASSIGN = 518;
80const AST_ASSIGN_REF = 519;
81const AST_ASSIGN_OP = 520;
82const AST_BINARY_OP = 521;
83const AST_ARRAY_ELEM = 526;
84const AST_NEW = 527;
85const AST_INSTANCEOF = 528;
86const AST_YIELD = 529;
87const AST_STATIC = 532;
88const AST_WHILE = 533;
89const AST_DO_WHILE = 534;
90const AST_IF_ELEM = 535;
91const AST_SWITCH = 536;
92const AST_SWITCH_CASE = 537;
93const AST_DECLARE = 538;
94const AST_PROP_ELEM = 775;
95const AST_PROP_GROUP = 774;
96const AST_CONST_ELEM = 776;
97const AST_USE_TRAIT = 539;
98const AST_TRAIT_PRECEDENCE = 540;
99const AST_METHOD_REFERENCE = 541;
100const AST_NAMESPACE = 542;
101const AST_USE_ELEM = 543;
102const AST_TRAIT_ALIAS = 544;
103const AST_GROUP_USE = 545;
104const AST_ATTRIBUTE = 546;
105const AST_MATCH = 547;
106const AST_MATCH_ARM = 548;
107const AST_NAMED_ARG = 549;
108const AST_METHOD_CALL = 768;
109const AST_NULLSAFE_METHOD_CALL = 769;
110const AST_STATIC_CALL = 770;
111const AST_CONDITIONAL = 771;
112const AST_TRY = 772;
113const AST_CATCH = 773;
114const AST_FOR = 1024;
115const AST_FOREACH = 1025;
116const AST_ENUM_CASE = 1026;
117const AST_PARAM = 1280;
118// END AST KIND CONSTANTS
119
120// AST FLAG CONSTANTS
121namespace ast\flags;
122const NAME_FQ = 0;
123const NAME_NOT_FQ = 1;
124const NAME_RELATIVE = 2;
125const MODIFIER_PUBLIC = 1;
126const MODIFIER_PROTECTED = 2;
127const MODIFIER_PRIVATE = 4;
128const MODIFIER_STATIC = 16;
129const MODIFIER_ABSTRACT = 64;
130const MODIFIER_FINAL = 32;
131const MODIFIER_READONLY = 128;
132const PARAM_MODIFIER_PUBLIC = 1;
133const PARAM_MODIFIER_PROTECTED = 2;
134const PARAM_MODIFIER_PRIVATE = 4;
135const RETURNS_REF = 4096;
136const FUNC_RETURNS_REF = 4096;
137const FUNC_GENERATOR = 16777216;
138const ARRAY_ELEM_REF = 1;
139const CLOSURE_USE_REF = 1;
140const CLASS_ABSTRACT = 64;
141const CLASS_FINAL = 32;
142const CLASS_TRAIT = 2;
143const CLASS_INTERFACE = 1;
144const CLASS_ANONYMOUS = 4;
145const CLASS_ENUM = 268435456;
146const CLASS_READONLY = 65536;
147const PARAM_REF = 8;
148const PARAM_VARIADIC = 16;
149const TYPE_NULL = 1;
150const TYPE_FALSE = 2;
151const TYPE_TRUE = 3;
152const TYPE_BOOL = 18;
153const TYPE_LONG = 4;
154const TYPE_DOUBLE = 5;
155const TYPE_STRING = 6;
156const TYPE_ARRAY = 7;
157const TYPE_OBJECT = 8;
158const TYPE_CALLABLE = 12;
159const TYPE_VOID = 14;
160const TYPE_ITERABLE = 13;
161const TYPE_STATIC = 15;
162const TYPE_MIXED = 16;
163const TYPE_NEVER = 17;
164const UNARY_BOOL_NOT = 14;
165const UNARY_BITWISE_NOT = 13;
166const UNARY_SILENCE = 260;
167const UNARY_PLUS = 261;
168const UNARY_MINUS = 262;
169const BINARY_BOOL_AND = 259;
170const BINARY_BOOL_OR = 258;
171const BINARY_BOOL_XOR = 15;
172const BINARY_BITWISE_OR = 9;
173const BINARY_BITWISE_AND = 10;
174const BINARY_BITWISE_XOR = 11;
175const BINARY_CONCAT = 8;
176const BINARY_ADD = 1;
177const BINARY_SUB = 2;
178const BINARY_MUL = 3;
179const BINARY_DIV = 4;
180const BINARY_MOD = 5;
181const BINARY_POW = 12;
182const BINARY_SHIFT_LEFT = 6;
183const BINARY_SHIFT_RIGHT = 7;
184const BINARY_IS_IDENTICAL = 16;
185const BINARY_IS_NOT_IDENTICAL = 17;
186const BINARY_IS_EQUAL = 18;
187const BINARY_IS_NOT_EQUAL = 19;
188const BINARY_IS_SMALLER = 20;
189const BINARY_IS_SMALLER_OR_EQUAL = 21;
190const BINARY_IS_GREATER = 256;
191const BINARY_IS_GREATER_OR_EQUAL = 257;
192const BINARY_SPACESHIP = 170;
193const BINARY_COALESCE = 260;
194const EXEC_EVAL = 1;
195const EXEC_INCLUDE = 2;
196const EXEC_INCLUDE_ONCE = 4;
197const EXEC_REQUIRE = 8;
198const EXEC_REQUIRE_ONCE = 16;
199const USE_NORMAL = 1;
200const USE_FUNCTION = 2;
201const USE_CONST = 4;
202const MAGIC_LINE = 379;
203const MAGIC_FILE = 380;
204const MAGIC_DIR = 381;
205const MAGIC_NAMESPACE = 386;
206const MAGIC_FUNCTION = 385;
207const MAGIC_METHOD = 384;
208const MAGIC_CLASS = 382;
209const MAGIC_TRAIT = 383;
210const ARRAY_SYNTAX_LIST = 1;
211const ARRAY_SYNTAX_LONG = 2;
212const ARRAY_SYNTAX_SHORT = 3;
213const DIM_ALTERNATIVE_SYNTAX = 2;
214const PARENTHESIZED_CONDITIONAL = 1;
215const ENCAPS_VAR_DOLLAR_CURLY = 1;
216const ENCAPS_VAR_DOLLAR_CURLY_VAR_VAR = 2;
217// END AST FLAG CONSTANTS
218
219namespace ast;
220
221/**
222 * Parses code file and returns AST root node.
223 *
224 * @param string $filename Code file to parse
225 * @param int    $version  AST version
226 * @return Node Root node of AST
227 *
228 * @see https://github.com/nikic/php-ast for version information
229 */
230function parse_file(string $filename, int $version)
231{
232}
233
234/**
235 * Parses code string and returns AST root node.
236 *
237 * @param string $code     Code string to parse
238 * @param int    $version  AST version
239 * @param string $filename Optional filename for use in parse errors
240 * @return Node Root node of AST
241 *
242 * @see https://github.com/nikic/php-ast for version information
243 */
244function parse_code(string $code, int $version, string $filename = "string code")
245{
246}
247
248/**
249 * @param int $kind AST_* constant value defining the kind of an AST node
250 * @return string String representation of AST kind value
251 */
252function get_kind_name(int $kind): string
253{
254}
255
256/**
257 * @param int $kind AST_* constant value defining the kind of an AST node
258 * @return bool Returns true if AST kind uses flags
259 */
260function kind_uses_flags(int $kind): bool
261{
262}
263
264/**
265 * Provides metadata for the AST kinds.
266 *
267 * The returned array is a map from AST kind to a Metadata object.
268 *
269 * @return Metadata[] Metadata about AST kinds
270 */
271function get_metadata(): array
272{
273}
274
275/**
276 * Returns currently supported AST versions.
277 *
278 * @param bool $exclude_deprecated Whether to exclude deprecated versions
279 * @return int[] Array of supported AST versions
280 */
281function get_supported_versions($exclude_deprecated = false): array
282{
283}
284
285// In php 8.2+, this class has the attribute AllowDynamicProperties
286/**
287 * This class describes a single node in a PHP AST.
288 */
289#[AllowDynamicProperties]
290class Node
291{
292    /** @var int AST Node Kind. Values are one of ast\AST_* constants. */
293    public $kind;
294
295    /**
296     * @var int AST Flags.
297     * Certain node kinds have flags that can be set.
298     * These will be a bitfield of ast\flags\* constants.
299     */
300    public $flags;
301
302    /** @var int Line the node starts in */
303    public $lineno;
304
305    /** @var array Child nodes (may be empty) */
306    public $children;
307
308    /**
309     * A constructor which validates data types but not the values themselves.
310     * For backwards compatibility reasons, all values are optional and properties default to null
311     */
312    public function __construct(int $kind = null, int $flags = null, array $children = null, int $lineno = null) {
313        $this->kind = $kind;
314        $this->flags = $flags;
315        $this->children = $children;
316        $this->lineno = $lineno;
317    }
318}
319
320/**
321 * Metadata entry for a single AST kind, as returned by ast\get_metadata().
322 */
323class Metadata
324{
325    /** @var int AST node kind (one of the ast\AST_* constants). */
326    public $kind;
327
328    /** @var string Name of the node kind (e.g. "AST_NAME"). */
329    public $name;
330
331    /**
332     * @var string[] Array of supported flags. The flags are given as names of constants, such as
333     *               "ast\flags\TYPE_STRING".
334     */
335    public $flags;
336
337    /**
338     * @var bool Whether the flags are exclusive or combinable. Exclusive flags should be checked
339     *           using ===, while combinable flags should be checked using &. */
340    public $flagsCombinable;
341}
342