Skip to content

Commit 36ec337

Browse files
committed
Zend/zend_ast: Add const qualifier
1 parent d8e014d commit 36ec337

File tree

3 files changed

+54
-54
lines changed

3 files changed

+54
-54
lines changed

Zend/zend_ast.c

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static inline void *zend_ast_alloc(size_t size) {
3333
return zend_arena_alloc(&CG(ast_arena), size);
3434
}
3535

36-
static inline void *zend_ast_realloc(void *old, size_t old_size, size_t new_size) {
36+
static inline void *zend_ast_realloc(const void *old, size_t old_size, size_t new_size) {
3737
void *new = zend_ast_alloc(new_size);
3838
memcpy(new, old, old_size);
3939
return new;
@@ -43,7 +43,7 @@ static inline size_t zend_ast_list_size(uint32_t children) {
4343
return sizeof(zend_ast_list) - sizeof(zend_ast *) + sizeof(zend_ast *) * children;
4444
}
4545

46-
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_znode(znode *node) {
46+
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_znode(const znode *node) {
4747
zend_ast_znode *ast;
4848

4949
ast = zend_ast_alloc(sizeof(zend_ast_znode));
@@ -66,7 +66,7 @@ ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_fcc(void) {
6666
return (zend_ast *) ast;
6767
}
6868

69-
static zend_always_inline zend_ast * zend_ast_create_zval_int(zval *zv, uint32_t attr, uint32_t lineno) {
69+
static zend_always_inline zend_ast * zend_ast_create_zval_int(const zval *zv, uint32_t attr, uint32_t lineno) {
7070
zend_ast_zval *ast;
7171

7272
ast = zend_ast_alloc(sizeof(zend_ast_zval));
@@ -77,15 +77,15 @@ static zend_always_inline zend_ast * zend_ast_create_zval_int(zval *zv, uint32_t
7777
return (zend_ast *) ast;
7878
}
7979

80-
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_zval_with_lineno(zval *zv, uint32_t lineno) {
80+
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_zval_with_lineno(const zval *zv, uint32_t lineno) {
8181
return zend_ast_create_zval_int(zv, 0, lineno);
8282
}
8383

84-
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_zval_ex(zval *zv, zend_ast_attr attr) {
84+
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_zval_ex(const zval *zv, zend_ast_attr attr) {
8585
return zend_ast_create_zval_int(zv, attr, CG(zend_lineno));
8686
}
8787

88-
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_zval(zval *zv) {
88+
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_zval(const zval *zv) {
8989
return zend_ast_create_zval_int(zv, 0, CG(zend_lineno));
9090
}
9191

@@ -508,7 +508,7 @@ ZEND_API zend_ast * ZEND_FASTCALL zend_ast_list_add(zend_ast *ast, zend_ast *op)
508508
return (zend_ast *) list;
509509
}
510510

511-
static zend_result zend_ast_add_array_element(zval *result, zval *offset, zval *expr)
511+
static zend_result zend_ast_add_array_element(const zval *result, zval *offset, zval *expr)
512512
{
513513
if (Z_TYPE_P(offset) == IS_UNDEF) {
514514
if (!zend_hash_next_index_insert(Z_ARRVAL_P(result), expr)) {
@@ -528,9 +528,9 @@ static zend_result zend_ast_add_array_element(zval *result, zval *offset, zval *
528528
return SUCCESS;
529529
}
530530

531-
static zend_result zend_ast_add_unpacked_element(zval *result, zval *expr) {
531+
static zend_result zend_ast_add_unpacked_element(const zval *result, const zval *expr) {
532532
if (EXPECTED(Z_TYPE_P(expr) == IS_ARRAY)) {
533-
HashTable *ht = Z_ARRVAL_P(expr);
533+
const HashTable *ht = Z_ARRVAL_P(expr);
534534
zval *val;
535535
zend_string *key;
536536

@@ -1243,7 +1243,7 @@ static size_t ZEND_FASTCALL zend_ast_tree_size(zend_ast *ast)
12431243
size = sizeof(zend_ast_fcc);
12441244
} else if (zend_ast_is_list(ast)) {
12451245
uint32_t i;
1246-
zend_ast_list *list = zend_ast_get_list(ast);
1246+
const zend_ast_list *list = zend_ast_get_list(ast);
12471247

12481248
size = zend_ast_list_size(list->children);
12491249
for (i = 0; i < list->children; i++) {
@@ -1284,7 +1284,7 @@ static void* ZEND_FASTCALL zend_ast_tree_copy(zend_ast *ast, void *buf)
12841284
Z_LINENO(new->val) = zend_ast_get_lineno(ast);
12851285
buf = (void*)((char*)buf + sizeof(zend_ast_zval));
12861286
} else if (zend_ast_is_list(ast)) {
1287-
zend_ast_list *list = zend_ast_get_list(ast);
1287+
const zend_ast_list *list = zend_ast_get_list(ast);
12881288
zend_ast_list *new = (zend_ast_list*)buf;
12891289
uint32_t i;
12901290
new->kind = list->kind;
@@ -1301,7 +1301,7 @@ static void* ZEND_FASTCALL zend_ast_tree_copy(zend_ast *ast, void *buf)
13011301
}
13021302
}
13031303
} else if (ast->kind == ZEND_AST_OP_ARRAY) {
1304-
zend_ast_op_array *old = zend_ast_get_op_array(ast);
1304+
const zend_ast_op_array *old = zend_ast_get_op_array(ast);
13051305
zend_ast_op_array *new = (zend_ast_op_array*)buf;
13061306
new->kind = old->kind;
13071307
new->attr = old->attr;
@@ -1310,7 +1310,7 @@ static void* ZEND_FASTCALL zend_ast_tree_copy(zend_ast *ast, void *buf)
13101310
function_add_ref((zend_function *)new->op_array);
13111311
buf = (void*)((char*)buf + sizeof(zend_ast_op_array));
13121312
} else if (ast->kind == ZEND_AST_CALLABLE_CONVERT) {
1313-
zend_ast_fcc *old = (zend_ast_fcc*)ast;
1313+
const zend_ast_fcc *old = (zend_ast_fcc*)ast;
13141314
zend_ast_fcc *new = (zend_ast_fcc*)buf;
13151315
new->kind = old->kind;
13161316
new->attr = old->attr;
@@ -1371,7 +1371,7 @@ ZEND_API void ZEND_FASTCALL zend_ast_destroy(zend_ast *ast)
13711371
} else if (EXPECTED(ast->kind == ZEND_AST_ZVAL)) {
13721372
zval_ptr_dtor_nogc(zend_ast_get_zval(ast));
13731373
} else if (EXPECTED(zend_ast_is_list(ast))) {
1374-
zend_ast_list *list = zend_ast_get_list(ast);
1374+
const zend_ast_list *list = zend_ast_get_list(ast);
13751375
if (list->children) {
13761376
uint32_t i;
13771377

@@ -1386,7 +1386,7 @@ ZEND_API void ZEND_FASTCALL zend_ast_destroy(zend_ast *ast)
13861386
} else if (EXPECTED(ast->kind == ZEND_AST_OP_ARRAY)) {
13871387
destroy_op_array(zend_ast_get_op_array(ast)->op_array);
13881388
} else if (EXPECTED(zend_ast_is_decl(ast))) {
1389-
zend_ast_decl *decl = (zend_ast_decl *) ast;
1389+
const zend_ast_decl *decl = (const zend_ast_decl *) ast;
13901390

13911391
if (decl->name) {
13921392
zend_string_release_ex(decl->name, 0);
@@ -1465,7 +1465,7 @@ ZEND_API void zend_ast_apply(zend_ast *ast, zend_ast_apply_func fn, void *contex
14651465

14661466
static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int priority, int indent);
14671467

1468-
static ZEND_COLD void zend_ast_export_str(smart_str *str, zend_string *s)
1468+
static ZEND_COLD void zend_ast_export_str(smart_str *str, const zend_string *s)
14691469
{
14701470
size_t i;
14711471

@@ -1480,7 +1480,7 @@ static ZEND_COLD void zend_ast_export_str(smart_str *str, zend_string *s)
14801480
}
14811481
}
14821482

1483-
static ZEND_COLD void zend_ast_export_qstr(smart_str *str, char quote, zend_string *s)
1483+
static ZEND_COLD void zend_ast_export_qstr(smart_str *str, char quote, const zend_string *s)
14841484
{
14851485
size_t i;
14861486

@@ -1536,7 +1536,7 @@ static ZEND_COLD void zend_ast_export_indent(smart_str *str, int indent)
15361536
static ZEND_COLD void zend_ast_export_name(smart_str *str, zend_ast *ast, int priority, int indent)
15371537
{
15381538
if (ast->kind == ZEND_AST_ZVAL) {
1539-
zval *zv = zend_ast_get_zval(ast);
1539+
const zval *zv = zend_ast_get_zval(ast);
15401540

15411541
if (Z_TYPE_P(zv) == IS_STRING) {
15421542
smart_str_append(str, Z_STR_P(zv));
@@ -1549,7 +1549,7 @@ static ZEND_COLD void zend_ast_export_name(smart_str *str, zend_ast *ast, int pr
15491549
static ZEND_COLD void zend_ast_export_ns_name(smart_str *str, zend_ast *ast, int priority, int indent)
15501550
{
15511551
if (ast->kind == ZEND_AST_ZVAL) {
1552-
zval *zv = zend_ast_get_zval(ast);
1552+
const zval *zv = zend_ast_get_zval(ast);
15531553

15541554
if (Z_TYPE_P(zv) == IS_STRING) {
15551555
if (ast->attr == ZEND_NAME_FQ) {
@@ -1628,7 +1628,7 @@ static ZEND_COLD void zend_ast_export_var(smart_str *str, zend_ast *ast, int pri
16281628

16291629
/* Use zend_ast_export_list() unless fewer than `list->children` children should
16301630
* be exported. */
1631-
static ZEND_COLD void zend_ast_export_list_ex(smart_str *str, zend_ast_list *list, bool separator, int priority, int indent, int children)
1631+
static ZEND_COLD void zend_ast_export_list_ex(smart_str *str, const zend_ast_list *list, bool separator, int priority, int indent, int children)
16321632
{
16331633
ZEND_ASSERT(children <= list->children);
16341634
uint32_t i = 0;
@@ -1642,20 +1642,20 @@ static ZEND_COLD void zend_ast_export_list_ex(smart_str *str, zend_ast_list *lis
16421642
}
16431643
}
16441644

1645-
static ZEND_COLD void zend_ast_export_list(smart_str *str, zend_ast_list *list, bool separator, int priority, int indent)
1645+
static ZEND_COLD void zend_ast_export_list(smart_str *str, const zend_ast_list *list, bool separator, int priority, int indent)
16461646
{
16471647
zend_ast_export_list_ex(str, list, separator, priority, indent, list->children);
16481648
}
16491649

1650-
static ZEND_COLD void zend_ast_export_encaps_list(smart_str *str, char quote, zend_ast_list *list, int indent)
1650+
static ZEND_COLD void zend_ast_export_encaps_list(smart_str *str, char quote, const zend_ast_list *list, int indent)
16511651
{
16521652
uint32_t i = 0;
16531653
zend_ast *ast;
16541654

16551655
while (i < list->children) {
16561656
ast = list->child[i];
16571657
if (ast->kind == ZEND_AST_ZVAL) {
1658-
zval *zv = zend_ast_get_zval(ast);
1658+
const zval *zv = zend_ast_get_zval(ast);
16591659

16601660
ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING);
16611661
zend_ast_export_qstr(str, quote, Z_STR_P(zv));
@@ -1676,7 +1676,7 @@ static ZEND_COLD void zend_ast_export_encaps_list(smart_str *str, char quote, ze
16761676
}
16771677
}
16781678

1679-
static ZEND_COLD void zend_ast_export_name_list_ex(smart_str *str, zend_ast_list *list, int indent, const char *separator)
1679+
static ZEND_COLD void zend_ast_export_name_list_ex(smart_str *str, const zend_ast_list *list, int indent, const char *separator)
16801680
{
16811681
uint32_t i = 0;
16821682

@@ -1692,7 +1692,7 @@ static ZEND_COLD void zend_ast_export_name_list_ex(smart_str *str, zend_ast_list
16921692
#define zend_ast_export_name_list(s, l, i) zend_ast_export_name_list_ex(s, l, i, ", ")
16931693
#define zend_ast_export_catch_name_list(s, l, i) zend_ast_export_name_list_ex(s, l, i, "|")
16941694

1695-
static ZEND_COLD void zend_ast_export_var_list(smart_str *str, zend_ast_list *list, int indent)
1695+
static ZEND_COLD void zend_ast_export_var_list(smart_str *str, const zend_ast_list *list, int indent)
16961696
{
16971697
uint32_t i = 0;
16981698

@@ -1717,7 +1717,7 @@ static ZEND_COLD void zend_ast_export_stmt(smart_str *str, zend_ast *ast, int in
17171717

17181718
if (ast->kind == ZEND_AST_STMT_LIST ||
17191719
ast->kind == ZEND_AST_TRAIT_ADAPTATIONS) {
1720-
zend_ast_list *list = (zend_ast_list*)ast;
1720+
const zend_ast_list *list = (const zend_ast_list*)ast;
17211721
uint32_t i = 0;
17221722

17231723
while (i < list->children) {
@@ -1744,8 +1744,8 @@ static ZEND_COLD void zend_ast_export_stmt(smart_str *str, zend_ast *ast, int in
17441744
case ZEND_AST_DECLARE:
17451745
break;
17461746
case ZEND_AST_PROP_GROUP: {
1747-
zend_ast *first_prop = zend_ast_get_list(ast->child[1])->child[0];
1748-
zend_ast *hook_list = first_prop->child[3];
1747+
const zend_ast *first_prop = zend_ast_get_list(ast->child[1])->child[0];
1748+
const zend_ast *hook_list = first_prop->child[3];
17491749
if (hook_list == NULL) {
17501750
smart_str_appendc(str, ';');
17511751
}
@@ -1759,7 +1759,7 @@ static ZEND_COLD void zend_ast_export_stmt(smart_str *str, zend_ast *ast, int in
17591759
}
17601760
}
17611761

1762-
static ZEND_COLD void zend_ast_export_if_stmt(smart_str *str, zend_ast_list *list, int indent)
1762+
static ZEND_COLD void zend_ast_export_if_stmt(smart_str *str, const zend_ast_list *list, int indent)
17631763
{
17641764
uint32_t i;
17651765
zend_ast *ast;
@@ -1783,7 +1783,7 @@ static ZEND_COLD void zend_ast_export_if_stmt(smart_str *str, zend_ast_list *lis
17831783
zend_ast_export_indent(str, indent);
17841784
smart_str_appends(str, "} else ");
17851785
if (ast->child[1] && ast->child[1]->kind == ZEND_AST_IF) {
1786-
list = (zend_ast_list*)ast->child[1];
1786+
list = (const zend_ast_list*)ast->child[1];
17871787
goto tail_call;
17881788
} else {
17891789
smart_str_appends(str, "{\n");
@@ -1796,7 +1796,7 @@ static ZEND_COLD void zend_ast_export_if_stmt(smart_str *str, zend_ast_list *lis
17961796
smart_str_appendc(str, '}');
17971797
}
17981798

1799-
static ZEND_COLD void zend_ast_export_zval(smart_str *str, zval *zv, int priority, int indent)
1799+
static ZEND_COLD void zend_ast_export_zval(smart_str *str, const zval *zv, int priority, int indent)
18001800
{
18011801
ZVAL_DEREF(zv);
18021802
switch (Z_TYPE_P(zv)) {
@@ -1853,7 +1853,7 @@ static ZEND_COLD void zend_ast_export_zval(smart_str *str, zval *zv, int priorit
18531853
}
18541854
}
18551855

1856-
static ZEND_COLD void zend_ast_export_class_no_header(smart_str *str, zend_ast_decl *decl, int indent) {
1856+
static ZEND_COLD void zend_ast_export_class_no_header(smart_str *str, const zend_ast_decl *decl, int indent) {
18571857
if (decl->child[0]) {
18581858
smart_str_appends(str, " extends ");
18591859
zend_ast_export_ns_name(str, decl->child[0], 0, indent);
@@ -1869,9 +1869,9 @@ static ZEND_COLD void zend_ast_export_class_no_header(smart_str *str, zend_ast_d
18691869
}
18701870

18711871
static ZEND_COLD void zend_ast_export_attribute_group(smart_str *str, zend_ast *ast, int indent) {
1872-
zend_ast_list *list = zend_ast_get_list(ast);
1872+
const zend_ast_list *list = zend_ast_get_list(ast);
18731873
for (uint32_t i = 0; i < list->children; i++) {
1874-
zend_ast *attr = list->child[i];
1874+
const zend_ast *attr = list->child[i];
18751875

18761876
if (i) {
18771877
smart_str_appends(str, ", ");
@@ -1887,7 +1887,7 @@ static ZEND_COLD void zend_ast_export_attribute_group(smart_str *str, zend_ast *
18871887
}
18881888

18891889
static ZEND_COLD void zend_ast_export_attributes(smart_str *str, zend_ast *ast, int indent, bool newlines) {
1890-
zend_ast_list *list = zend_ast_get_list(ast);
1890+
const zend_ast_list *list = zend_ast_get_list(ast);
18911891
uint32_t i;
18921892

18931893
for (i = 0; i < list->children; i++) {
@@ -1926,7 +1926,7 @@ static ZEND_COLD void zend_ast_export_visibility(smart_str *str, uint32_t flags,
19261926

19271927
static ZEND_COLD void zend_ast_export_type(smart_str *str, zend_ast *ast, int indent) {
19281928
if (ast->kind == ZEND_AST_TYPE_UNION) {
1929-
zend_ast_list *list = zend_ast_get_list(ast);
1929+
const zend_ast_list *list = zend_ast_get_list(ast);
19301930
for (uint32_t i = 0; i < list->children; i++) {
19311931
if (i != 0) {
19321932
smart_str_appendc(str, '|');
@@ -1936,7 +1936,7 @@ static ZEND_COLD void zend_ast_export_type(smart_str *str, zend_ast *ast, int in
19361936
return;
19371937
}
19381938
if (ast->kind == ZEND_AST_TYPE_INTERSECTION) {
1939-
zend_ast_list *list = zend_ast_get_list(ast);
1939+
const zend_ast_list *list = zend_ast_get_list(ast);
19401940
for (uint32_t i = 0; i < list->children; i++) {
19411941
if (i != 0) {
19421942
smart_str_appendc(str, '&');
@@ -1951,15 +1951,15 @@ static ZEND_COLD void zend_ast_export_type(smart_str *str, zend_ast *ast, int in
19511951
zend_ast_export_ns_name(str, ast, 0, indent);
19521952
}
19531953

1954-
static ZEND_COLD void zend_ast_export_hook_list(smart_str *str, zend_ast_list *hook_list, int indent)
1954+
static ZEND_COLD void zend_ast_export_hook_list(smart_str *str, const zend_ast_list *hook_list, int indent)
19551955
{
19561956
smart_str_appends(str, " {");
19571957
smart_str_appendc(str, '\n');
19581958
indent++;
19591959
zend_ast_export_indent(str, indent);
19601960

19611961
for (uint32_t i = 0; i < hook_list->children; i++) {
1962-
zend_ast_decl *hook = (zend_ast_decl *)hook_list->child[i];
1962+
const zend_ast_decl *hook = (const zend_ast_decl *)hook_list->child[i];
19631963
zend_ast_export_visibility(str, hook->flags, ZEND_MODIFIER_TARGET_PROPERTY);
19641964
if (hook->flags & ZEND_ACC_FINAL) {
19651965
smart_str_appends(str, "final ");
@@ -2033,7 +2033,7 @@ static ZEND_COLD void zend_ast_export_hook_list(smart_str *str, zend_ast_list *h
20332033

20342034
static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int priority, int indent)
20352035
{
2036-
zend_ast_decl *decl;
2036+
const zend_ast_decl *decl;
20372037
int p, pl, pr;
20382038
const char *op;
20392039

@@ -2069,7 +2069,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
20692069
case ZEND_AST_CLOSURE:
20702070
case ZEND_AST_ARROW_FUNC:
20712071
case ZEND_AST_METHOD:
2072-
decl = (zend_ast_decl *) ast;
2072+
decl = (const zend_ast_decl *) ast;
20732073
if (decl->child[4]) {
20742074
bool newlines = !(ast->kind == ZEND_AST_CLOSURE || ast->kind == ZEND_AST_ARROW_FUNC);
20752075
zend_ast_export_attributes(str, decl->child[4], indent, newlines);
@@ -2128,7 +2128,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
21282128
}
21292129
break;
21302130
case ZEND_AST_CLASS:
2131-
decl = (zend_ast_decl *) ast;
2131+
decl = (const zend_ast_decl *) ast;
21322132
if (decl->child[3]) {
21332133
zend_ast_export_attributes(str, decl->child[3], indent, 1);
21342134
}
@@ -2523,7 +2523,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
25232523
case ZEND_AST_NEW:
25242524
smart_str_appends(str, "new ");
25252525
if (ast->child[0]->kind == ZEND_AST_CLASS) {
2526-
zend_ast_decl *decl = (zend_ast_decl *) ast->child[0];
2526+
const zend_ast_decl *decl = (const zend_ast_decl *) ast->child[0];
25272527
if (decl->child[3]) {
25282528
zend_ast_export_attributes(str, decl->child[3], indent, 0);
25292529
}

0 commit comments

Comments
 (0)