Skip to content

Commit df8f210

Browse files
committed
rename State->Context. no return value
1 parent 0994bf9 commit df8f210

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

Python/ast_opt.c

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ typedef struct {
1212
bool in_finally;
1313
bool in_funcdef;
1414
bool in_loop;
15-
} ControlFlowInFinallyState;
15+
} ControlFlowInFinallyContext;
1616

1717
typedef struct {
1818
PyObject *filename;
@@ -23,7 +23,7 @@ typedef struct {
2323
int recursion_depth; /* current recursion depth */
2424
int recursion_limit; /* recursion limit */
2525

26-
ControlFlowInFinallyState cf_finally;
26+
ControlFlowInFinallyContext cf_finally;
2727
} _PyASTOptimizeState;
2828

2929
#define ENTER_RECURSIVE(ST) \
@@ -41,21 +41,20 @@ typedef struct {
4141
} while(0)
4242

4343

44-
static ControlFlowInFinallyState
44+
static ControlFlowInFinallyContext
4545
overwrite_state(_PyASTOptimizeState *state, bool finally, bool funcdef, bool loop)
4646
{
47-
ControlFlowInFinallyState saved = state->cf_finally;
47+
ControlFlowInFinallyContext saved = state->cf_finally;
4848
state->cf_finally.in_finally = finally;
4949
state->cf_finally.in_funcdef = funcdef;
5050
state->cf_finally.in_loop = loop;
5151
return saved;
5252
}
5353

54-
static int
55-
restore_state(_PyASTOptimizeState *state, ControlFlowInFinallyState *saved)
54+
static void
55+
restore_state(_PyASTOptimizeState *state, ControlFlowInFinallyContext *saved)
5656
{
5757
state->cf_finally = *saved;
58-
return 1;
5958
}
6059

6160
static int
@@ -94,17 +93,14 @@ before_loop_exit(_PyASTOptimizeState *state, stmt_ty node_, const char *kw)
9493
return 1;
9594
}
9695

97-
#define RESTORE_STATE_CHECKED(S, CFS) \
98-
if (!restore_state((S), (CFS))) { \
99-
return 0; \
100-
}
96+
#define RESTORE_STATE(S, CFS) restore_state((S), (CFS))
10197

10298
#define BEFORE_FINALLY(S) overwrite_state((S), true, false, false)
103-
#define AFTER_FINALLY(S, CFS) RESTORE_STATE_CHECKED((S), (CFS))
99+
#define AFTER_FINALLY(S, CFS) RESTORE_STATE((S), (CFS))
104100
#define BEFORE_FUNC_BODY(S) overwrite_state((S), false, true, false)
105-
#define AFTER_FUNC_BODY(S, CFS) RESTORE_STATE_CHECKED((S), (CFS))
101+
#define AFTER_FUNC_BODY(S, CFS) RESTORE_STATE((S), (CFS))
106102
#define BEFORE_LOOP_BODY(S) overwrite_state((S), false, false, true)
107-
#define AFTER_LOOP_BODY(S, CFS) RESTORE_STATE_CHECKED((S), (CFS))
103+
#define AFTER_LOOP_BODY(S, CFS) RESTORE_STATE((S), (CFS))
108104

109105
#define BEFORE_RETURN(S, N) \
110106
if (!before_return((S), (N))) { \
@@ -927,9 +923,9 @@ astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTOptimizeState *state)
927923
case FunctionDef_kind: {
928924
CALL_SEQ(astfold_type_param, type_param, node_->v.FunctionDef.type_params);
929925
CALL(astfold_arguments, arguments_ty, node_->v.FunctionDef.args);
930-
ControlFlowInFinallyState saved_state = BEFORE_FUNC_BODY(state);
926+
ControlFlowInFinallyContext saved_context = BEFORE_FUNC_BODY(state);
931927
CALL(astfold_body, asdl_seq, node_->v.FunctionDef.body);
932-
AFTER_FUNC_BODY(state, &saved_state);
928+
AFTER_FUNC_BODY(state, &saved_context);
933929
CALL_SEQ(astfold_expr, expr, node_->v.FunctionDef.decorator_list);
934930
if (!(state->ff_features & CO_FUTURE_ANNOTATIONS)) {
935931
CALL_OPT(astfold_expr, expr_ty, node_->v.FunctionDef.returns);
@@ -939,9 +935,9 @@ astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTOptimizeState *state)
939935
case AsyncFunctionDef_kind: {
940936
CALL_SEQ(astfold_type_param, type_param, node_->v.AsyncFunctionDef.type_params);
941937
CALL(astfold_arguments, arguments_ty, node_->v.AsyncFunctionDef.args);
942-
ControlFlowInFinallyState saved_state = BEFORE_FUNC_BODY(state);
938+
ControlFlowInFinallyContext saved_context = BEFORE_FUNC_BODY(state);
943939
CALL(astfold_body, asdl_seq, node_->v.AsyncFunctionDef.body);
944-
AFTER_FUNC_BODY(state, &saved_state);
940+
AFTER_FUNC_BODY(state, &saved_context);
945941
CALL_SEQ(astfold_expr, expr, node_->v.AsyncFunctionDef.decorator_list);
946942
if (!(state->ff_features & CO_FUTURE_ANNOTATIONS)) {
947943
CALL_OPT(astfold_expr, expr_ty, node_->v.AsyncFunctionDef.returns);
@@ -985,26 +981,26 @@ astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTOptimizeState *state)
985981
case For_kind: {
986982
CALL(astfold_expr, expr_ty, node_->v.For.target);
987983
CALL(astfold_expr, expr_ty, node_->v.For.iter);
988-
ControlFlowInFinallyState saved_state = BEFORE_LOOP_BODY(state);
984+
ControlFlowInFinallyContext saved_context = BEFORE_LOOP_BODY(state);
989985
CALL_SEQ(astfold_stmt, stmt, node_->v.For.body);
990-
AFTER_LOOP_BODY(state, &saved_state);
986+
AFTER_LOOP_BODY(state, &saved_context);
991987
CALL_SEQ(astfold_stmt, stmt, node_->v.For.orelse);
992988
break;
993989
}
994990
case AsyncFor_kind: {
995991
CALL(astfold_expr, expr_ty, node_->v.AsyncFor.target);
996992
CALL(astfold_expr, expr_ty, node_->v.AsyncFor.iter);
997-
ControlFlowInFinallyState saved_state = BEFORE_LOOP_BODY(state);
993+
ControlFlowInFinallyContext saved_context = BEFORE_LOOP_BODY(state);
998994
CALL_SEQ(astfold_stmt, stmt, node_->v.AsyncFor.body);
999-
AFTER_LOOP_BODY(state, &saved_state);
995+
AFTER_LOOP_BODY(state, &saved_context);
1000996
CALL_SEQ(astfold_stmt, stmt, node_->v.AsyncFor.orelse);
1001997
break;
1002998
}
1003999
case While_kind: {
10041000
CALL(astfold_expr, expr_ty, node_->v.While.test);
1005-
ControlFlowInFinallyState saved_state = BEFORE_LOOP_BODY(state);
1001+
ControlFlowInFinallyContext saved_context = BEFORE_LOOP_BODY(state);
10061002
CALL_SEQ(astfold_stmt, stmt, node_->v.While.body);
1007-
AFTER_LOOP_BODY(state, &saved_state);
1003+
AFTER_LOOP_BODY(state, &saved_context);
10081004
CALL_SEQ(astfold_stmt, stmt, node_->v.While.orelse);
10091005
break;
10101006
}
@@ -1029,18 +1025,18 @@ astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTOptimizeState *state)
10291025
CALL_SEQ(astfold_stmt, stmt, node_->v.Try.body);
10301026
CALL_SEQ(astfold_excepthandler, excepthandler, node_->v.Try.handlers);
10311027
CALL_SEQ(astfold_stmt, stmt, node_->v.Try.orelse);
1032-
ControlFlowInFinallyState saved_state = BEFORE_FINALLY(state);
1028+
ControlFlowInFinallyContext saved_context = BEFORE_FINALLY(state);
10331029
CALL_SEQ(astfold_stmt, stmt, node_->v.Try.finalbody);
1034-
AFTER_FINALLY(state, &saved_state);
1030+
AFTER_FINALLY(state, &saved_context);
10351031
break;
10361032
}
10371033
case TryStar_kind: {
10381034
CALL_SEQ(astfold_stmt, stmt, node_->v.TryStar.body);
10391035
CALL_SEQ(astfold_excepthandler, excepthandler, node_->v.TryStar.handlers);
10401036
CALL_SEQ(astfold_stmt, stmt, node_->v.TryStar.orelse);
1041-
ControlFlowInFinallyState saved_state = BEFORE_FINALLY(state);
1037+
ControlFlowInFinallyContext saved_context = BEFORE_FINALLY(state);
10421038
CALL_SEQ(astfold_stmt, stmt, node_->v.TryStar.finalbody);
1043-
AFTER_FINALLY(state, &saved_state);
1039+
AFTER_FINALLY(state, &saved_context);
10441040
break;
10451041
}
10461042
case Assert_kind:

0 commit comments

Comments
 (0)