Skip to content

Commit 19eabc6

Browse files
authored
zend_compile: Use return true / return false for functions returning bool (#21649)
Changes done with Coccinelle: @r1 exists@ identifier fn; typedef bool; symbol false; symbol true; @@ bool fn ( ... ) { ... return ( - 0 + false | - 1 + true ) ; }
1 parent f4d9ed1 commit 19eabc6

File tree

1 file changed

+55
-55
lines changed

1 file changed

+55
-55
lines changed

Zend/zend_compile.c

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ static bool zend_get_unqualified_name(const zend_string *name, const char **resu
188188
if (ns_separator != NULL) {
189189
*result = ns_separator + 1;
190190
*result_len = ZSTR_VAL(name) + ZSTR_LEN(name) - *result;
191-
return 1;
191+
return true;
192192
}
193193

194-
return 0;
194+
return false;
195195
}
196196
/* }}} */
197197

@@ -234,11 +234,11 @@ static bool zend_is_reserved_class_name(const zend_string *name) /* {{{ */
234234
if (uqname_len == reserved->len
235235
&& zend_binary_strcasecmp(uqname, uqname_len, reserved->name, reserved->len) == 0
236236
) {
237-
return 1;
237+
return true;
238238
}
239239
}
240240

241-
return 0;
241+
return false;
242242
}
243243
/* }}} */
244244

@@ -1665,13 +1665,13 @@ static bool array_is_const(const zend_array *array)
16651665

16661666
static bool can_ct_eval_const(const zend_constant *c) {
16671667
if (ZEND_CONSTANT_FLAGS(c) & CONST_DEPRECATED) {
1668-
return 0;
1668+
return false;
16691669
}
16701670
if ((ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT)
16711671
&& !(CG(compiler_options) & ZEND_COMPILE_NO_PERSISTENT_CONSTANT_SUBSTITUTION)
16721672
&& !((ZEND_CONSTANT_FLAGS(c) & CONST_NO_FILE_CACHE)
16731673
&& (CG(compiler_options) & ZEND_COMPILE_WITH_FILE_CACHE))) {
1674-
return 1;
1674+
return true;
16751675
}
16761676
if (Z_TYPE(c->value) < IS_ARRAY
16771677
&& !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION)) {
@@ -1681,7 +1681,7 @@ static bool can_ct_eval_const(const zend_constant *c) {
16811681
&& array_is_const(Z_ARR(c->value))) {
16821682
return 1;
16831683
}
1684-
return 0;
1684+
return false;
16851685
}
16861686

16871687
static bool zend_try_ct_eval_const(zval *zv, zend_string *name, bool is_fully_qualified) /* {{{ */
@@ -1698,27 +1698,27 @@ static bool zend_try_ct_eval_const(zval *zv, zend_string *name, bool is_fully_qu
16981698
zend_constant *c;
16991699
if ((c = zend_get_special_const(lookup_name, lookup_len))) {
17001700
ZVAL_COPY_VALUE(zv, &c->value);
1701-
return 1;
1701+
return true;
17021702
}
17031703
c = zend_hash_find_ptr(EG(zend_constants), name);
17041704
if (c && can_ct_eval_const(c)) {
17051705
ZVAL_COPY_OR_DUP(zv, &c->value);
1706-
return 1;
1706+
return true;
17071707
}
1708-
return 0;
1708+
return false;
17091709
}
17101710
/* }}} */
17111711

17121712
static inline bool zend_is_scope_known(void) /* {{{ */
17131713
{
17141714
if (!CG(active_op_array)) {
17151715
/* This can only happen when evaluating a default value string. */
1716-
return 0;
1716+
return false;
17171717
}
17181718

17191719
if (CG(active_op_array)->fn_flags & ZEND_ACC_CLOSURE) {
17201720
/* Closures can be rebound to a different scope */
1721-
return 0;
1721+
return false;
17221722
}
17231723

17241724
if (!CG(active_class_entry)) {
@@ -1735,10 +1735,10 @@ static inline bool zend_is_scope_known(void) /* {{{ */
17351735
static inline bool class_name_refers_to_active_ce(const zend_string *class_name, uint32_t fetch_type) /* {{{ */
17361736
{
17371737
if (!CG(active_class_entry)) {
1738-
return 0;
1738+
return false;
17391739
}
17401740
if (fetch_type == ZEND_FETCH_CLASS_SELF && zend_is_scope_known()) {
1741-
return 1;
1741+
return true;
17421742
}
17431743
return fetch_type == ZEND_FETCH_CLASS_DEFAULT
17441744
&& zend_string_equals_ci(class_name, CG(active_class_entry)->name);
@@ -1803,7 +1803,7 @@ static bool zend_try_compile_const_expr_resolve_class_name(zval *zv, zend_ast *c
18031803
const zval *class_name;
18041804

18051805
if (class_ast->kind != ZEND_AST_ZVAL) {
1806-
return 0;
1806+
return false;
18071807
}
18081808

18091809
class_name = zend_ast_get_zval(class_ast);
@@ -1819,21 +1819,21 @@ static bool zend_try_compile_const_expr_resolve_class_name(zval *zv, zend_ast *c
18191819
case ZEND_FETCH_CLASS_SELF:
18201820
if (CG(active_class_entry) && zend_is_scope_known()) {
18211821
ZVAL_STR_COPY(zv, CG(active_class_entry)->name);
1822-
return 1;
1822+
return true;
18231823
}
1824-
return 0;
1824+
return false;
18251825
case ZEND_FETCH_CLASS_PARENT:
18261826
if (CG(active_class_entry) && CG(active_class_entry)->parent_name
18271827
&& zend_is_scope_known()) {
18281828
ZVAL_STR_COPY(zv, CG(active_class_entry)->parent_name);
1829-
return 1;
1829+
return true;
18301830
}
1831-
return 0;
1831+
return false;
18321832
case ZEND_FETCH_CLASS_STATIC:
1833-
return 0;
1833+
return false;
18341834
case ZEND_FETCH_CLASS_DEFAULT:
18351835
ZVAL_STR(zv, zend_resolve_class_name_ast(class_ast));
1836-
return 1;
1836+
return true;
18371837
default: ZEND_UNREACHABLE();
18381838
}
18391839
}
@@ -1896,11 +1896,11 @@ static bool zend_try_ct_eval_class_const(zval *zv, zend_string *class_name, zend
18961896
}
18971897

18981898
if (CG(compiler_options) & ZEND_COMPILE_NO_PERSISTENT_CONSTANT_SUBSTITUTION) {
1899-
return 0;
1899+
return false;
19001900
}
19011901

19021902
if (!cc || !zend_verify_ct_const_access(cc, CG(active_class_entry))) {
1903-
return 0;
1903+
return false;
19041904
}
19051905

19061906
c = &cc->value;
@@ -1914,7 +1914,7 @@ static bool zend_try_ct_eval_class_const(zval *zv, zend_string *class_name, zend
19141914
return 1;
19151915
}
19161916

1917-
return 0;
1917+
return false;
19181918
}
19191919
/* }}} */
19201920

@@ -2513,9 +2513,9 @@ static bool zend_ast_kind_is_short_circuited(zend_ast_kind ast_kind)
25132513
case ZEND_AST_METHOD_CALL:
25142514
case ZEND_AST_NULLSAFE_METHOD_CALL:
25152515
case ZEND_AST_STATIC_CALL:
2516-
return 1;
2516+
return true;
25172517
default:
2518-
return 0;
2518+
return false;
25192519
}
25202520
}
25212521

@@ -2530,9 +2530,9 @@ static bool zend_ast_is_short_circuited(const zend_ast *ast)
25302530
return zend_ast_is_short_circuited(ast->child[0]);
25312531
case ZEND_AST_NULLSAFE_PROP:
25322532
case ZEND_AST_NULLSAFE_METHOD_CALL:
2533-
return 1;
2533+
return true;
25342534
default:
2535-
return 0;
2535+
return false;
25362536
}
25372537
}
25382538

@@ -2802,7 +2802,7 @@ static inline bool zend_can_write_to_variable(const zend_ast *ast) /* {{{ */
28022802
static inline bool zend_is_const_default_class_ref(zend_ast *name_ast) /* {{{ */
28032803
{
28042804
if (name_ast->kind != ZEND_AST_ZVAL) {
2805-
return 0;
2805+
return false;
28062806
}
28072807

28082808
return ZEND_FETCH_CLASS_DEFAULT == zend_get_class_fetch_type_ast(name_ast);
@@ -2994,7 +2994,7 @@ static bool is_this_fetch(const zend_ast *ast) /* {{{ */
29942994
return Z_TYPE_P(name) == IS_STRING && zend_string_equals(Z_STR_P(name), ZSTR_KNOWN(ZEND_STR_THIS));
29952995
}
29962996

2997-
return 0;
2997+
return false;
29982998
}
29992999
/* }}} */
30003000

@@ -3005,7 +3005,7 @@ static bool is_globals_fetch(const zend_ast *ast)
30053005
return Z_TYPE_P(name) == IS_STRING && zend_string_equals_literal(Z_STR_P(name), "GLOBALS");
30063006
}
30073007

3008-
return 0;
3008+
return false;
30093009
}
30103010

30113011
static bool is_global_var_fetch(const zend_ast *ast)
@@ -3461,15 +3461,15 @@ static void zend_ensure_writable_variable(const zend_ast *ast) /* {{{ */
34613461
static bool zend_is_assign_to_self(const zend_ast *var_ast, const zend_ast *expr_ast) /* {{{ */
34623462
{
34633463
if (expr_ast->kind != ZEND_AST_VAR || expr_ast->child[0]->kind != ZEND_AST_ZVAL) {
3464-
return 0;
3464+
return false;
34653465
}
34663466

34673467
while (zend_is_variable(var_ast) && var_ast->kind != ZEND_AST_VAR) {
34683468
var_ast = var_ast->child[0];
34693469
}
34703470

34713471
if (var_ast->kind != ZEND_AST_VAR || var_ast->child[0]->kind != ZEND_AST_ZVAL) {
3472-
return 0;
3472+
return false;
34733473
}
34743474

34753475
{
@@ -4132,10 +4132,10 @@ static inline bool zend_args_contain_unpack_or_named(const zend_ast_list *args)
41324132
for (i = 0; i < args->children; ++i) {
41334133
const zend_ast *arg = args->child[i];
41344134
if (arg->kind == ZEND_AST_UNPACK || arg->kind == ZEND_AST_NAMED_ARG) {
4135-
return 1;
4135+
return true;
41364136
}
41374137
}
4138-
return 0;
4138+
return false;
41394139
}
41404140
/* }}} */
41414141

@@ -5890,7 +5890,7 @@ static bool zend_handle_loops_and_finally_ex(zend_long depth, znode *return_valu
58905890
zend_loop_var *loop_var = zend_stack_top(&CG(loop_var_stack));
58915891

58925892
if (!loop_var) {
5893-
return 1;
5893+
return true;
58945894
}
58955895
base = zend_stack_base(&CG(loop_var_stack));
58965896
for (; loop_var >= base; loop_var--) {
@@ -5945,7 +5945,7 @@ static bool zend_has_finally_ex(zend_long depth) /* {{{ */
59455945
zend_loop_var *loop_var = zend_stack_top(&CG(loop_var_stack));
59465946

59475947
if (!loop_var) {
5948-
return 0;
5948+
return false;
59495949
}
59505950
base = zend_stack_base(&CG(loop_var_stack));
59515951
for (; loop_var >= base; loop_var--) {
@@ -5961,7 +5961,7 @@ static bool zend_has_finally_ex(zend_long depth) /* {{{ */
59615961
depth--;
59625962
}
59635963
}
5964-
return 0;
5964+
return false;
59655965
}
59665966
/* }}} */
59675967

@@ -6563,7 +6563,7 @@ static uint8_t determine_switch_jumptable_type(const zend_ast_list *cases) {
65636563

65646564
static bool should_use_jumptable(const zend_ast_list *cases, uint8_t jumptable_type) {
65656565
if (CG(compiler_options) & ZEND_COMPILE_NO_JUMPTABLES) {
6566-
return 0;
6566+
return false;
65676567
}
65686568

65696569
/* Thresholds are chosen based on when the average switch time for equidistributed
@@ -6746,17 +6746,17 @@ static bool can_match_use_jumptable(const zend_ast_list *arms) {
67466746

67476747
zend_eval_const_expr(cond_ast);
67486748
if ((*cond_ast)->kind != ZEND_AST_ZVAL) {
6749-
return 0;
6749+
return false;
67506750
}
67516751

67526752
const zval *cond_zv = zend_ast_get_zval(*cond_ast);
67536753
if (Z_TYPE_P(cond_zv) != IS_LONG && Z_TYPE_P(cond_zv) != IS_STRING) {
6754-
return 0;
6754+
return false;
67556755
}
67566756
}
67576757
}
67586758

6759-
return 1;
6759+
return true;
67606760
}
67616761

67626762
static bool zend_is_pipe_optimizable_callable_name(zend_ast *ast)
@@ -7204,7 +7204,7 @@ bool zend_handle_encoding_declaration(zend_ast *ast) /* {{{ */
72047204
if (zend_string_equals_literal_ci(name, "encoding")) {
72057205
if (value_ast->kind != ZEND_AST_ZVAL) {
72067206
zend_throw_exception(zend_ce_compile_error, "Encoding must be a literal", 0);
7207-
return 0;
7207+
return false;
72087208
}
72097209

72107210
if (CG(multibyte)) {
@@ -7238,7 +7238,7 @@ bool zend_handle_encoding_declaration(zend_ast *ast) /* {{{ */
72387238
}
72397239
}
72407240

7241-
return 1;
7241+
return true;
72427242
}
72437243
/* }}} */
72447244

@@ -7776,14 +7776,14 @@ static bool zend_is_valid_default_value(zend_type type, zval *value)
77767776
{
77777777
ZEND_ASSERT(ZEND_TYPE_IS_SET(type));
77787778
if (ZEND_TYPE_CONTAINS_CODE(type, Z_TYPE_P(value))) {
7779-
return 1;
7779+
return true;
77807780
}
77817781
if ((ZEND_TYPE_FULL_MASK(type) & MAY_BE_DOUBLE) && Z_TYPE_P(value) == IS_LONG) {
77827782
/* Integers are allowed as initializers for floating-point values. */
77837783
convert_to_double(value);
7784-
return 1;
7784+
return true;
77857785
}
7786-
return 0;
7786+
return false;
77877787
}
77887788

77897789
static void zend_compile_attributes(
@@ -10222,7 +10222,7 @@ static bool zend_try_ct_eval_magic_const(zval *zv, const zend_ast *ast) /* {{{ *
1022210222
default: ZEND_UNREACHABLE();
1022310223
}
1022410224

10225-
return 1;
10225+
return true;
1022610226
}
1022710227
/* }}} */
1022810228

@@ -10326,12 +10326,12 @@ ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, const zval *op1, co
1032610326
static inline bool zend_try_ct_eval_binary_op(zval *result, uint32_t opcode, zval *op1, zval *op2) /* {{{ */
1032710327
{
1032810328
if (zend_binary_op_produces_error(opcode, op1, op2)) {
10329-
return 0;
10329+
return false;
1033010330
}
1033110331

1033210332
const binary_op_type fn = get_binary_op(opcode);
1033310333
fn(result, op1, op2);
10334-
return 1;
10334+
return true;
1033510335
}
1033610336
/* }}} */
1033710337

@@ -10356,12 +10356,12 @@ ZEND_API bool zend_unary_op_produces_error(uint32_t opcode, const zval *op)
1035610356
static inline bool zend_try_ct_eval_unary_op(zval *result, uint32_t opcode, zval *op) /* {{{ */
1035710357
{
1035810358
if (zend_unary_op_produces_error(opcode, op)) {
10359-
return 0;
10359+
return false;
1036010360
}
1036110361

1036210362
const unary_op_type fn = get_unary_op(opcode);
1036310363
fn(result, op);
10364-
return 1;
10364+
return true;
1036510365
}
1036610366
/* }}} */
1036710367

@@ -10425,12 +10425,12 @@ static bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */
1042510425
}
1042610426

1042710427
if (!is_constant) {
10428-
return 0;
10428+
return false;
1042910429
}
1043010430

1043110431
if (!list->children) {
1043210432
ZVAL_EMPTY_ARRAY(result);
10433-
return 1;
10433+
return true;
1043410434
}
1043510435

1043610436
array_init_size(result, list->children);
@@ -10503,7 +10503,7 @@ static bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */
1050310503
}
1050410504
}
1050510505

10506-
return 1;
10506+
return true;
1050710507
}
1050810508
/* }}} */
1050910509

0 commit comments

Comments
 (0)