xref: /php-ast/tests/metadata.phpt (revision 1fc2c3a1)
1--TEST--
2AST metadata
3--FILE--
4<?php
5
6$metadata = ast\get_metadata();
7foreach ($metadata as $data) {
8    $flags = [];
9    foreach ($data->flags as $flag) {
10        $flags[] = substr($flag, strrpos($flag, '\\') + 1);
11    }
12    $metadataHasFlags = count($flags) > 0;
13    $kindUsesFlags = ast\kind_uses_flags($data->kind);
14    if ($metadataHasFlags != $kindUsesFlags) {
15        echo "kind_uses_flags for $data->name is unexpectedly " . var_export($kindUsesFlags, true) . "\n";
16    }
17
18    echo "$data->name: ";
19    if ($data->flagsCombinable) {
20        echo "(combinable) ";
21    }
22    echo "[", implode(", ", $flags), "]\n";
23}
24
25// NOTE: AST_PARAM has overlapping flag values for MODIFIER_PUBLIC and PARAM_REF in php 7.4.
26// To work around this, MODIFIER_* were omitted from get_metadata in 7.4 and older.
27?>
28--EXPECT--
29AST_ARG_LIST: []
30AST_LIST: []
31AST_ARRAY: [ARRAY_SYNTAX_LIST, ARRAY_SYNTAX_LONG, ARRAY_SYNTAX_SHORT]
32AST_ENCAPS_LIST: []
33AST_EXPR_LIST: []
34AST_STMT_LIST: []
35AST_IF: []
36AST_SWITCH_LIST: []
37AST_CATCH_LIST: []
38AST_PARAM_LIST: []
39AST_CLOSURE_USES: []
40AST_PROP_DECL: (combinable) [MODIFIER_PUBLIC, MODIFIER_PROTECTED, MODIFIER_PRIVATE, MODIFIER_STATIC, MODIFIER_ABSTRACT, MODIFIER_FINAL, MODIFIER_READONLY]
41AST_CONST_DECL: []
42AST_CLASS_CONST_DECL: (combinable) [MODIFIER_PUBLIC, MODIFIER_PROTECTED, MODIFIER_PRIVATE, MODIFIER_STATIC, MODIFIER_ABSTRACT, MODIFIER_FINAL, MODIFIER_READONLY]
43AST_NAME_LIST: []
44AST_TRAIT_ADAPTATIONS: []
45AST_USE: [USE_NORMAL, USE_FUNCTION, USE_CONST]
46AST_TYPE_UNION: []
47AST_TYPE_INTERSECTION: []
48AST_ATTRIBUTE_LIST: []
49AST_ATTRIBUTE_GROUP: []
50AST_MATCH_ARM_LIST: []
51AST_NAME: [NAME_FQ, NAME_NOT_FQ, NAME_RELATIVE]
52AST_CLOSURE_VAR: [CLOSURE_USE_REF]
53AST_NULLABLE_TYPE: []
54AST_FUNC_DECL: (combinable) [MODIFIER_PUBLIC, MODIFIER_PROTECTED, MODIFIER_PRIVATE, MODIFIER_STATIC, MODIFIER_ABSTRACT, MODIFIER_FINAL, MODIFIER_READONLY, FUNC_RETURNS_REF, FUNC_GENERATOR]
55AST_CLOSURE: (combinable) [MODIFIER_PUBLIC, MODIFIER_PROTECTED, MODIFIER_PRIVATE, MODIFIER_STATIC, MODIFIER_ABSTRACT, MODIFIER_FINAL, MODIFIER_READONLY, FUNC_RETURNS_REF, FUNC_GENERATOR]
56AST_METHOD: (combinable) [MODIFIER_PUBLIC, MODIFIER_PROTECTED, MODIFIER_PRIVATE, MODIFIER_STATIC, MODIFIER_ABSTRACT, MODIFIER_FINAL, MODIFIER_READONLY, FUNC_RETURNS_REF, FUNC_GENERATOR]
57AST_ARROW_FUNC: (combinable) [MODIFIER_PUBLIC, MODIFIER_PROTECTED, MODIFIER_PRIVATE, MODIFIER_STATIC, MODIFIER_ABSTRACT, MODIFIER_FINAL, MODIFIER_READONLY, FUNC_RETURNS_REF, FUNC_GENERATOR]
58AST_CLASS: (combinable) [CLASS_ABSTRACT, CLASS_FINAL, CLASS_TRAIT, CLASS_INTERFACE, CLASS_ANONYMOUS, CLASS_ENUM, CLASS_READONLY]
59AST_PROPERTY_HOOK: (combinable) [MODIFIER_PUBLIC, MODIFIER_PROTECTED, MODIFIER_PRIVATE, MODIFIER_STATIC, MODIFIER_ABSTRACT, MODIFIER_FINAL, MODIFIER_READONLY, FUNC_RETURNS_REF, FUNC_GENERATOR]
60AST_MAGIC_CONST: [MAGIC_LINE, MAGIC_FILE, MAGIC_DIR, MAGIC_NAMESPACE, MAGIC_FUNCTION, MAGIC_METHOD, MAGIC_CLASS, MAGIC_TRAIT]
61AST_TYPE: [TYPE_NULL, TYPE_FALSE, TYPE_TRUE, TYPE_BOOL, TYPE_LONG, TYPE_DOUBLE, TYPE_STRING, TYPE_ARRAY, TYPE_OBJECT, TYPE_CALLABLE, TYPE_VOID, TYPE_ITERABLE, TYPE_STATIC, TYPE_MIXED, TYPE_NEVER]
62AST_CALLABLE_CONVERT: []
63AST_VAR: (combinable) [ENCAPS_VAR_DOLLAR_CURLY_VAR_VAR, ENCAPS_VAR_DOLLAR_CURLY]
64AST_CONST: []
65AST_UNPACK: []
66AST_CAST: [TYPE_NULL, TYPE_FALSE, TYPE_TRUE, TYPE_BOOL, TYPE_LONG, TYPE_DOUBLE, TYPE_STRING, TYPE_ARRAY, TYPE_OBJECT, TYPE_CALLABLE, TYPE_VOID, TYPE_ITERABLE, TYPE_STATIC, TYPE_MIXED, TYPE_NEVER]
67AST_EMPTY: []
68AST_ISSET: []
69AST_SHELL_EXEC: []
70AST_CLONE: []
71AST_EXIT: []
72AST_PRINT: []
73AST_INCLUDE_OR_EVAL: [EXEC_EVAL, EXEC_INCLUDE, EXEC_INCLUDE_ONCE, EXEC_REQUIRE, EXEC_REQUIRE_ONCE]
74AST_UNARY_OP: [UNARY_BOOL_NOT, UNARY_BITWISE_NOT, UNARY_MINUS, UNARY_PLUS, UNARY_SILENCE]
75AST_PRE_INC: []
76AST_PRE_DEC: []
77AST_POST_INC: []
78AST_POST_DEC: []
79AST_YIELD_FROM: []
80AST_GLOBAL: []
81AST_UNSET: []
82AST_RETURN: []
83AST_LABEL: []
84AST_REF: []
85AST_HALT_COMPILER: []
86AST_ECHO: []
87AST_THROW: []
88AST_GOTO: []
89AST_BREAK: []
90AST_CONTINUE: []
91AST_CLASS_NAME: []
92AST_PROPERTY_HOOK_SHORT_BODY: []
93AST_CLASS_CONST_GROUP: (combinable) [MODIFIER_PUBLIC, MODIFIER_PROTECTED, MODIFIER_PRIVATE, MODIFIER_STATIC, MODIFIER_ABSTRACT, MODIFIER_FINAL, MODIFIER_READONLY]
94AST_DIM: (combinable) [DIM_ALTERNATIVE_SYNTAX, ENCAPS_VAR_DOLLAR_CURLY]
95AST_PROP: []
96AST_NULLSAFE_PROP: []
97AST_STATIC_PROP: []
98AST_CALL: []
99AST_CLASS_CONST: []
100AST_ASSIGN: []
101AST_ASSIGN_REF: []
102AST_ASSIGN_OP: [BINARY_BITWISE_OR, BINARY_BITWISE_AND, BINARY_BITWISE_XOR, BINARY_CONCAT, BINARY_ADD, BINARY_SUB, BINARY_MUL, BINARY_DIV, BINARY_MOD, BINARY_POW, BINARY_SHIFT_LEFT, BINARY_SHIFT_RIGHT, BINARY_COALESCE]
103AST_BINARY_OP: [BINARY_BITWISE_OR, BINARY_BITWISE_AND, BINARY_BITWISE_XOR, BINARY_CONCAT, BINARY_ADD, BINARY_SUB, BINARY_MUL, BINARY_DIV, BINARY_MOD, BINARY_POW, BINARY_SHIFT_LEFT, BINARY_SHIFT_RIGHT, BINARY_COALESCE, BINARY_BOOL_AND, BINARY_BOOL_OR, BINARY_BOOL_XOR, BINARY_IS_IDENTICAL, BINARY_IS_NOT_IDENTICAL, BINARY_IS_EQUAL, BINARY_IS_NOT_EQUAL, BINARY_IS_SMALLER, BINARY_IS_SMALLER_OR_EQUAL, BINARY_IS_GREATER, BINARY_IS_GREATER_OR_EQUAL, BINARY_SPACESHIP]
104AST_ARRAY_ELEM: [ARRAY_ELEM_REF]
105AST_NEW: []
106AST_INSTANCEOF: []
107AST_YIELD: []
108AST_STATIC: []
109AST_WHILE: []
110AST_DO_WHILE: []
111AST_IF_ELEM: []
112AST_SWITCH: []
113AST_SWITCH_CASE: []
114AST_DECLARE: []
115AST_PROP_ELEM: []
116AST_PROP_GROUP: (combinable) [MODIFIER_PUBLIC, MODIFIER_PROTECTED, MODIFIER_PRIVATE, MODIFIER_STATIC, MODIFIER_ABSTRACT, MODIFIER_FINAL, MODIFIER_READONLY]
117AST_CONST_ELEM: []
118AST_USE_TRAIT: []
119AST_TRAIT_PRECEDENCE: []
120AST_METHOD_REFERENCE: []
121AST_NAMESPACE: []
122AST_USE_ELEM: [USE_NORMAL, USE_FUNCTION, USE_CONST]
123AST_TRAIT_ALIAS: (combinable) [MODIFIER_PUBLIC, MODIFIER_PROTECTED, MODIFIER_PRIVATE, MODIFIER_STATIC, MODIFIER_ABSTRACT, MODIFIER_FINAL, MODIFIER_READONLY]
124AST_GROUP_USE: [USE_NORMAL, USE_FUNCTION, USE_CONST]
125AST_ATTRIBUTE: []
126AST_MATCH: []
127AST_MATCH_ARM: []
128AST_NAMED_ARG: []
129AST_METHOD_CALL: []
130AST_NULLSAFE_METHOD_CALL: []
131AST_STATIC_CALL: []
132AST_CONDITIONAL: (combinable) [PARENTHESIZED_CONDITIONAL]
133AST_TRY: []
134AST_CATCH: []
135AST_FOR: []
136AST_FOREACH: []
137AST_ENUM_CASE: []
138AST_PARAM: (combinable) [PARAM_REF, PARAM_VARIADIC, PARAM_MODIFIER_PUBLIC, PARAM_MODIFIER_PROTECTED, PARAM_MODIFIER_PRIVATE]
139