bpo-41746: Add type information to asdl_seq objects (GH-22223)

* Add new capability to the PEG parser to type variable assignments. For instance:
```
       | a[asdl_stmt_seq*]=';'.small_stmt+ [';'] NEWLINE { a }
```

* Add new sequence types from the asdl definition (automatically generated)
* Make `asdl_seq` type a generic aliasing pointer type.
* Create a new `asdl_generic_seq` for the generic case using `void*`.
* The old `asdl_seq_GET`/`ast_seq_SET` macros now are typed.
* New `asdl_seq_GET_UNTYPED`/`ast_seq_SET_UNTYPED` macros for dealing with generic sequences.
* Changes all possible `asdl_seq` types to use specific versions everywhere.
This commit is contained in:
Pablo Galindo 2020-09-16 19:42:00 +01:00 committed by GitHub
parent 5c1b46d897
commit a5634c4067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 1338 additions and 1086 deletions

View File

@ -43,7 +43,7 @@ class PEGLexer(RegexLexer):
(r"'\W+?'", Text),
(r'"\W+?"', Text),
],
"variables": [(_name + _text_ws + "(=)", bygroups(None, None, None),),],
"variables": [(_name + _text_ws + r"(\[.*\])?" + _text_ws + "(=)", bygroups(None, None, None, None, None),),],
"invalids": [
(r"^(\s+\|\s+invalid_\w+\s*\n)", bygroups(None)),
(r"^(\s+\|\s+incorrect_\w+\s*\n)", bygroups(None)),

View File

@ -34,27 +34,27 @@ func_type[mod_ty]: '(' a=[type_expressions] ')' '->' b=expression NEWLINE* ENDMA
fstring[expr_ty]: star_expressions
# type_expressions allow */** but ignore them
type_expressions[asdl_seq*]:
type_expressions[asdl_expr_seq*]:
| a=','.expression+ ',' '*' b=expression ',' '**' c=expression {
_PyPegen_seq_append_to_end(p, CHECK(_PyPegen_seq_append_to_end(p, a, b)), c) }
| a=','.expression+ ',' '*' b=expression { _PyPegen_seq_append_to_end(p, a, b) }
| a=','.expression+ ',' '**' b=expression { _PyPegen_seq_append_to_end(p, a, b) }
(asdl_expr_seq*)_PyPegen_seq_append_to_end(p, CHECK(_PyPegen_seq_append_to_end(p, a, b)), c) }
| a=','.expression+ ',' '*' b=expression { (asdl_expr_seq*)_PyPegen_seq_append_to_end(p, a, b) }
| a=','.expression+ ',' '**' b=expression { (asdl_expr_seq*)_PyPegen_seq_append_to_end(p, a, b) }
| '*' a=expression ',' '**' b=expression {
_PyPegen_seq_append_to_end(p, CHECK(_PyPegen_singleton_seq(p, a)), b) }
| '*' a=expression { _PyPegen_singleton_seq(p, a) }
| '**' a=expression { _PyPegen_singleton_seq(p, a) }
| ','.expression+
(asdl_expr_seq*)_PyPegen_seq_append_to_end(p, CHECK(_PyPegen_singleton_seq(p, a)), b) }
| '*' a=expression { (asdl_expr_seq*)_PyPegen_singleton_seq(p, a) }
| '**' a=expression { (asdl_expr_seq*)_PyPegen_singleton_seq(p, a) }
| a[asdl_expr_seq*]=','.expression+ {a}
statements[asdl_seq*]: a=statement+ { _PyPegen_seq_flatten(p, a) }
statement[asdl_seq*]: a=compound_stmt { _PyPegen_singleton_seq(p, a) } | simple_stmt
statement_newline[asdl_seq*]:
| a=compound_stmt NEWLINE { _PyPegen_singleton_seq(p, a) }
statements[asdl_stmt_seq*]: a=statement+ { (asdl_stmt_seq*)_PyPegen_seq_flatten(p, a) }
statement[asdl_stmt_seq*]: a=compound_stmt { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a) } | a[asdl_stmt_seq*]=simple_stmt { a }
statement_newline[asdl_stmt_seq*]:
| a=compound_stmt NEWLINE { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a) }
| simple_stmt
| NEWLINE { _PyPegen_singleton_seq(p, CHECK(_Py_Pass(EXTRA))) }
| NEWLINE { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, CHECK(_Py_Pass(EXTRA))) }
| ENDMARKER { _PyPegen_interactive_exit(p) }
simple_stmt[asdl_seq*]:
| a=small_stmt !';' NEWLINE { _PyPegen_singleton_seq(p, a) } # Not needed, there for speedup
| a=';'.small_stmt+ [';'] NEWLINE { a }
simple_stmt[asdl_stmt_seq*]:
| a=small_stmt !';' NEWLINE { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a) } # Not needed, there for speedup
| a[asdl_stmt_seq*]=';'.small_stmt+ [';'] NEWLINE { a }
# NOTE: assignment MUST precede expression, else parsing a simple assignment
# will throw a SyntaxError.
small_stmt[stmt_ty] (memo):
@ -91,7 +91,7 @@ assignment[stmt_ty]:
| a=('(' b=single_target ')' { b }
| single_subscript_attribute_target) ':' b=expression c=['=' d=annotated_rhs { d }] {
CHECK_VERSION(6, "Variable annotations syntax is", _Py_AnnAssign(a, b, c, 0, EXTRA)) }
| a=(z=star_targets '=' { z })+ b=(yield_expr | star_expressions) !'=' tc=[TYPE_COMMENT] {
| a[asdl_expr_seq*]=(z=star_targets '=' { z })+ b=(yield_expr | star_expressions) !'=' tc=[TYPE_COMMENT] {
_Py_Assign(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) }
| a=single_target b=augassign ~ c=(yield_expr | star_expressions) {
_Py_AugAssign(a, b->kind, c, EXTRA) }
@ -112,9 +112,9 @@ augassign[AugOperator*]:
| '**=' { _PyPegen_augoperator(p, Pow) }
| '//=' { _PyPegen_augoperator(p, FloorDiv) }
global_stmt[stmt_ty]: 'global' a=','.NAME+ {
global_stmt[stmt_ty]: 'global' a[asdl_expr_seq*]=','.NAME+ {
_Py_Global(CHECK(_PyPegen_map_names_to_ids(p, a)), EXTRA) }
nonlocal_stmt[stmt_ty]: 'nonlocal' a=','.NAME+ {
nonlocal_stmt[stmt_ty]: 'nonlocal' a[asdl_expr_seq*]=','.NAME+ {
_Py_Nonlocal(CHECK(_PyPegen_map_names_to_ids(p, a)), EXTRA) }
yield_stmt[stmt_ty]: y=yield_expr { _Py_Expr(y, EXTRA) }
@ -133,19 +133,19 @@ import_from[stmt_ty]:
_Py_ImportFrom(b->v.Name.id, c, _PyPegen_seq_count_dots(a), EXTRA) }
| 'from' a=('.' | '...')+ 'import' b=import_from_targets {
_Py_ImportFrom(NULL, b, _PyPegen_seq_count_dots(a), EXTRA) }
import_from_targets[asdl_seq*]:
import_from_targets[asdl_alias_seq*]:
| '(' a=import_from_as_names [','] ')' { a }
| import_from_as_names !','
| '*' { _PyPegen_singleton_seq(p, CHECK(_PyPegen_alias_for_star(p))) }
| '*' { (asdl_alias_seq*)_PyPegen_singleton_seq(p, CHECK(_PyPegen_alias_for_star(p))) }
| invalid_import_from_targets
import_from_as_names[asdl_seq*]:
| a=','.import_from_as_name+ { a }
import_from_as_names[asdl_alias_seq*]:
| a[asdl_alias_seq*]=','.import_from_as_name+ { a }
import_from_as_name[alias_ty]:
| a=NAME b=['as' z=NAME { z }] { _Py_alias(a->v.Name.id,
(b) ? ((expr_ty) b)->v.Name.id : NULL,
p->arena) }
dotted_as_names[asdl_seq*]:
| a=','.dotted_as_name+ { a }
dotted_as_names[asdl_alias_seq*]:
| a[asdl_alias_seq*]=','.dotted_as_name+ { a }
dotted_as_name[alias_ty]:
| a=dotted_name b=['as' z=NAME { z }] { _Py_alias(a->v.Name.id,
(b) ? ((expr_ty) b)->v.Name.id : NULL,
@ -155,12 +155,12 @@ dotted_name[expr_ty]:
| NAME
if_stmt[stmt_ty]:
| 'if' a=named_expression ':' b=block c=elif_stmt { _Py_If(a, b, CHECK(_PyPegen_singleton_seq(p, c)), EXTRA) }
| 'if' a=named_expression ':' b=block c=elif_stmt { _Py_If(a, b, CHECK((asdl_stmt_seq*)_PyPegen_singleton_seq(p, c)), EXTRA) }
| 'if' a=named_expression ':' b=block c=[else_block] { _Py_If(a, b, c, EXTRA) }
elif_stmt[stmt_ty]:
| 'elif' a=named_expression ':' b=block c=elif_stmt { _Py_If(a, b, CHECK(_PyPegen_singleton_seq(p, c)), EXTRA) }
| 'elif' a=named_expression ':' b=block c=[else_block] { _Py_If(a, b, c, EXTRA) }
else_block[asdl_seq*]: 'else' ':' b=block { b }
else_block[asdl_stmt_seq*]: 'else' ':' b=block { b }
while_stmt[stmt_ty]:
| 'while' a=named_expression ':' b=block c=[else_block] { _Py_While(a, b, c, EXTRA) }
@ -173,13 +173,13 @@ for_stmt[stmt_ty]:
| invalid_for_target
with_stmt[stmt_ty]:
| 'with' '(' a=','.with_item+ ','? ')' ':' b=block {
| 'with' '(' a[asdl_withitem_seq*]=','.with_item+ ','? ')' ':' b=block {
_Py_With(a, b, NULL, EXTRA) }
| 'with' a=','.with_item+ ':' tc=[TYPE_COMMENT] b=block {
| 'with' a[asdl_withitem_seq*]=','.with_item+ ':' tc=[TYPE_COMMENT] b=block {
_Py_With(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) }
| ASYNC 'with' '(' a=','.with_item+ ','? ')' ':' b=block {
| ASYNC 'with' '(' a[asdl_withitem_seq*]=','.with_item+ ','? ')' ':' b=block {
CHECK_VERSION(5, "Async with statements are", _Py_AsyncWith(a, b, NULL, EXTRA)) }
| ASYNC 'with' a=','.with_item+ ':' tc=[TYPE_COMMENT] b=block {
| ASYNC 'with' a[asdl_withitem_seq*]=','.with_item+ ':' tc=[TYPE_COMMENT] b=block {
CHECK_VERSION(5, "Async with statements are", _Py_AsyncWith(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA)) }
with_item[withitem_ty]:
| e=expression 'as' t=target &(',' | ')' | ':') { _Py_withitem(e, t, p->arena) }
@ -188,12 +188,12 @@ with_item[withitem_ty]:
try_stmt[stmt_ty]:
| 'try' ':' b=block f=finally_block { _Py_Try(b, NULL, NULL, f, EXTRA) }
| 'try' ':' b=block ex=except_block+ el=[else_block] f=[finally_block] { _Py_Try(b, ex, el, f, EXTRA) }
| 'try' ':' b=block ex[asdl_excepthandler_seq*]=except_block+ el=[else_block] f=[finally_block] { _Py_Try(b, ex, el, f, EXTRA) }
except_block[excepthandler_ty]:
| 'except' e=expression t=['as' z=NAME { z }] ':' b=block {
_Py_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
| 'except' ':' b=block { _Py_ExceptHandler(NULL, NULL, b, EXTRA) }
finally_block[asdl_seq*]: 'finally' ':' a=block { a }
finally_block[asdl_stmt_seq*]: 'finally' ':' a=block { a }
return_stmt[stmt_ty]:
| 'return' a=[star_expressions] { _Py_Return(a, EXTRA) }
@ -229,11 +229,11 @@ params[arguments_ty]:
| parameters
parameters[arguments_ty]:
| a=slash_no_default b=param_no_default* c=param_with_default* d=[star_etc] {
| a=slash_no_default b[asdl_arg_seq*]=param_no_default* c=param_with_default* d=[star_etc] {
_PyPegen_make_arguments(p, a, NULL, b, c, d) }
| a=slash_with_default b=param_with_default* c=[star_etc] {
_PyPegen_make_arguments(p, NULL, a, NULL, b, c) }
| a=param_no_default+ b=param_with_default* c=[star_etc] {
| a[asdl_arg_seq*]=param_no_default+ b=param_with_default* c=[star_etc] {
_PyPegen_make_arguments(p, NULL, NULL, a, b, c) }
| a=param_with_default+ b=[star_etc] { _PyPegen_make_arguments(p, NULL, NULL, NULL, a, b)}
| a=star_etc { _PyPegen_make_arguments(p, NULL, NULL, NULL, NULL, a) }
@ -241,12 +241,12 @@ parameters[arguments_ty]:
# Some duplication here because we can't write (',' | &')'),
# which is because we don't support empty alternatives (yet).
#
slash_no_default[asdl_seq*]:
| a=param_no_default+ '/' ',' { a }
| a=param_no_default+ '/' &')' { a }
slash_no_default[asdl_arg_seq*]:
| a[asdl_arg_seq*]=param_no_default+ '/' ',' { a }
| a[asdl_arg_seq*]=param_no_default+ '/' &')' { a }
slash_with_default[SlashWithDefault*]:
| a=param_no_default* b=param_with_default+ '/' ',' { _PyPegen_slash_with_default(p, a, b) }
| a=param_no_default* b=param_with_default+ '/' &')' { _PyPegen_slash_with_default(p, a, b) }
| a=param_no_default* b=param_with_default+ '/' ',' { _PyPegen_slash_with_default(p, (asdl_arg_seq *)a, b) }
| a=param_no_default* b=param_with_default+ '/' &')' { _PyPegen_slash_with_default(p, (asdl_arg_seq *)a, b) }
star_etc[StarEtc*]:
| '*' a=param_no_default b=param_maybe_default* c=[kwds] {
@ -284,7 +284,7 @@ param[arg_ty]: a=NAME b=annotation? { _Py_arg(a->v.Name.id, b, NULL, EXTRA) }
annotation[expr_ty]: ':' a=expression { a }
default[expr_ty]: '=' a=expression { a }
decorators[asdl_seq*]: a=('@' f=named_expression NEWLINE { f })+ { a }
decorators[asdl_expr_seq*]: a[asdl_expr_seq*]=('@' f=named_expression NEWLINE { f })+ { a }
class_def[stmt_ty]:
| a=decorators b=class_def_raw { _PyPegen_class_def_decorators(p, a, b) }
@ -296,12 +296,12 @@ class_def_raw[stmt_ty]:
(b) ? ((expr_ty) b)->v.Call.keywords : NULL,
c, NULL, EXTRA) }
block[asdl_seq*] (memo):
block[asdl_stmt_seq*] (memo):
| NEWLINE INDENT a=statements DEDENT { a }
| simple_stmt
| invalid_block
expressions_list[asdl_seq*]: a=','.star_expression+ [','] { a }
expressions_list[asdl_expr_seq*]: a[asdl_expr_seq*]=','.star_expression+ [','] { a }
star_expressions[expr_ty]:
| a=star_expression b=(',' c=star_expression { c })+ [','] {
_Py_Tuple(CHECK(_PyPegen_seq_insert_in_front(p, a, b)), Load, EXTRA) }
@ -311,7 +311,7 @@ star_expression[expr_ty] (memo):
| '*' a=bitwise_or { _Py_Starred(a, Load, EXTRA) }
| expression
star_named_expressions[asdl_seq*]: a=','.star_named_expression+ [','] { a }
star_named_expressions[asdl_expr_seq*]: a[asdl_expr_seq*]=','.star_named_expression+ [','] { a }
star_named_expression[expr_ty]:
| '*' a=bitwise_or { _Py_Starred(a, Load, EXTRA) }
| named_expression
@ -344,21 +344,21 @@ lambda_params[arguments_ty]:
# a colon, not a close parenthesis. (For more, see parameters above.)
#
lambda_parameters[arguments_ty]:
| a=lambda_slash_no_default b=lambda_param_no_default* c=lambda_param_with_default* d=[lambda_star_etc] {
| a=lambda_slash_no_default b[asdl_arg_seq*]=lambda_param_no_default* c=lambda_param_with_default* d=[lambda_star_etc] {
_PyPegen_make_arguments(p, a, NULL, b, c, d) }
| a=lambda_slash_with_default b=lambda_param_with_default* c=[lambda_star_etc] {
_PyPegen_make_arguments(p, NULL, a, NULL, b, c) }
| a=lambda_param_no_default+ b=lambda_param_with_default* c=[lambda_star_etc] {
| a[asdl_arg_seq*]=lambda_param_no_default+ b=lambda_param_with_default* c=[lambda_star_etc] {
_PyPegen_make_arguments(p, NULL, NULL, a, b, c) }
| a=lambda_param_with_default+ b=[lambda_star_etc] { _PyPegen_make_arguments(p, NULL, NULL, NULL, a, b)}
| a=lambda_star_etc { _PyPegen_make_arguments(p, NULL, NULL, NULL, NULL, a) }
lambda_slash_no_default[asdl_seq*]:
| a=lambda_param_no_default+ '/' ',' { a }
| a=lambda_param_no_default+ '/' &':' { a }
lambda_slash_no_default[asdl_arg_seq*]:
| a[asdl_arg_seq*]=lambda_param_no_default+ '/' ',' { a }
| a[asdl_arg_seq*]=lambda_param_no_default+ '/' &':' { a }
lambda_slash_with_default[SlashWithDefault*]:
| a=lambda_param_no_default* b=lambda_param_with_default+ '/' ',' { _PyPegen_slash_with_default(p, a, b) }
| a=lambda_param_no_default* b=lambda_param_with_default+ '/' &':' { _PyPegen_slash_with_default(p, a, b) }
| a=lambda_param_no_default* b=lambda_param_with_default+ '/' ',' { _PyPegen_slash_with_default(p, (asdl_arg_seq *)a, b) }
| a=lambda_param_no_default* b=lambda_param_with_default+ '/' &':' { _PyPegen_slash_with_default(p, (asdl_arg_seq *)a, b) }
lambda_star_etc[StarEtc*]:
| '*' a=lambda_param_no_default b=lambda_param_maybe_default* c=[lambda_kwds] {
@ -472,7 +472,7 @@ primary[expr_ty]:
slices[expr_ty]:
| a=slice !',' { a }
| a=','.slice+ [','] { _Py_Tuple(a, Load, EXTRA) }
| a[asdl_expr_seq*]=','.slice+ [','] { _Py_Tuple(a, Load, EXTRA) }
slice[expr_ty]:
| a=[expression] ':' b=[expression] c=[':' d=[expression] { d }] { _Py_Slice(a, b, c, EXTRA) }
| a=expression { a }
@ -518,12 +518,12 @@ double_starred_kvpair[KeyValuePair*]:
| '**' a=bitwise_or { _PyPegen_key_value_pair(p, NULL, a) }
| kvpair
kvpair[KeyValuePair*]: a=expression ':' b=expression { _PyPegen_key_value_pair(p, a, b) }
for_if_clauses[asdl_seq*]:
| for_if_clause+
for_if_clauses[asdl_comprehension_seq*]:
| a[asdl_comprehension_seq*]=for_if_clause+ { a }
for_if_clause[comprehension_ty]:
| ASYNC 'for' a=star_targets 'in' ~ b=disjunction c=('if' z=disjunction { z })* {
| ASYNC 'for' a=star_targets 'in' ~ b=disjunction c[asdl_expr_seq*]=('if' z=disjunction { z })* {
CHECK_VERSION(6, "Async comprehensions are", _Py_comprehension(a, b, c, 1, p->arena)) }
| 'for' a=star_targets 'in' ~ b=disjunction c=('if' z=disjunction { z })* {
| 'for' a=star_targets 'in' ~ b=disjunction c[asdl_expr_seq*]=('if' z=disjunction { z })* {
_Py_comprehension(a, b, c, 0, p->arena) }
| invalid_for_target
@ -535,7 +535,7 @@ arguments[expr_ty] (memo):
| a=args [','] &')' { a }
| incorrect_arguments
args[expr_ty]:
| a=','.(starred_expression | named_expression !'=')+ b=[',' k=kwargs {k}] { _PyPegen_collect_call_seqs(p, a, b, EXTRA) }
| a[asdl_expr_seq*]=','.(starred_expression | named_expression !'=')+ b=[',' k=kwargs {k}] { _PyPegen_collect_call_seqs(p, a, b, EXTRA) }
| a=kwargs { _Py_Call(_PyPegen_dummy_name(p),
CHECK_NULL_ALLOWED(_PyPegen_seq_extract_starred_exprs(p, a)),
CHECK_NULL_ALLOWED(_PyPegen_seq_delete_starred_exprs(p, a)),
@ -562,7 +562,7 @@ star_targets[expr_ty]:
| a=star_target !',' { a }
| a=star_target b=(',' c=star_target { c })* [','] {
_Py_Tuple(CHECK(_PyPegen_seq_insert_in_front(p, a, b)), Store, EXTRA) }
star_targets_seq[asdl_seq*]: a=','.star_target+ [','] { a }
star_targets_seq[asdl_expr_seq*]: a[asdl_expr_seq*]=','.star_target+ [','] { a }
star_target[expr_ty] (memo):
| '*' a=(!'*' star_target) {
_Py_Starred(CHECK(_PyPegen_set_expr_context(p, a, Store)), Store, EXTRA) }
@ -583,7 +583,7 @@ single_subscript_attribute_target[expr_ty]:
| a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Store, EXTRA) }
| a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) }
del_targets[asdl_seq*]: a=','.del_target+ [','] { a }
del_targets[asdl_expr_seq*]: a[asdl_expr_seq*]=','.del_target+ [','] { a }
del_target[expr_ty] (memo):
| a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Del, EXTRA) }
| a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Del, EXTRA) }
@ -594,7 +594,7 @@ del_t_atom[expr_ty]:
| '(' a=[del_targets] ')' { _Py_Tuple(a, Del, EXTRA) }
| '[' a=[del_targets] ']' { _Py_List(a, Del, EXTRA) }
targets[asdl_seq*]: a=','.target+ [','] { a }
targets[asdl_expr_seq*]: a[asdl_expr_seq*]=','.target+ [','] { a }
target[expr_ty] (memo):
| a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Store, EXTRA) }
| a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) }

358
Include/Python-ast.h generated
View File

@ -47,18 +47,99 @@ typedef struct _withitem *withitem_ty;
typedef struct _type_ignore *type_ignore_ty;
typedef struct {
_ASDL_SEQ_HEAD
mod_ty typed_elements[1];
} asdl_mod_seq;
asdl_mod_seq *_Py_asdl_mod_seq_new(Py_ssize_t size, PyArena *arena);
typedef struct {
_ASDL_SEQ_HEAD
stmt_ty typed_elements[1];
} asdl_stmt_seq;
asdl_stmt_seq *_Py_asdl_stmt_seq_new(Py_ssize_t size, PyArena *arena);
typedef struct {
_ASDL_SEQ_HEAD
expr_ty typed_elements[1];
} asdl_expr_seq;
asdl_expr_seq *_Py_asdl_expr_seq_new(Py_ssize_t size, PyArena *arena);
typedef struct {
_ASDL_SEQ_HEAD
comprehension_ty typed_elements[1];
} asdl_comprehension_seq;
asdl_comprehension_seq *_Py_asdl_comprehension_seq_new(Py_ssize_t size, PyArena
*arena);
typedef struct {
_ASDL_SEQ_HEAD
excepthandler_ty typed_elements[1];
} asdl_excepthandler_seq;
asdl_excepthandler_seq *_Py_asdl_excepthandler_seq_new(Py_ssize_t size, PyArena
*arena);
typedef struct {
_ASDL_SEQ_HEAD
arguments_ty typed_elements[1];
} asdl_arguments_seq;
asdl_arguments_seq *_Py_asdl_arguments_seq_new(Py_ssize_t size, PyArena *arena);
typedef struct {
_ASDL_SEQ_HEAD
arg_ty typed_elements[1];
} asdl_arg_seq;
asdl_arg_seq *_Py_asdl_arg_seq_new(Py_ssize_t size, PyArena *arena);
typedef struct {
_ASDL_SEQ_HEAD
keyword_ty typed_elements[1];
} asdl_keyword_seq;
asdl_keyword_seq *_Py_asdl_keyword_seq_new(Py_ssize_t size, PyArena *arena);
typedef struct {
_ASDL_SEQ_HEAD
alias_ty typed_elements[1];
} asdl_alias_seq;
asdl_alias_seq *_Py_asdl_alias_seq_new(Py_ssize_t size, PyArena *arena);
typedef struct {
_ASDL_SEQ_HEAD
withitem_ty typed_elements[1];
} asdl_withitem_seq;
asdl_withitem_seq *_Py_asdl_withitem_seq_new(Py_ssize_t size, PyArena *arena);
typedef struct {
_ASDL_SEQ_HEAD
type_ignore_ty typed_elements[1];
} asdl_type_ignore_seq;
asdl_type_ignore_seq *_Py_asdl_type_ignore_seq_new(Py_ssize_t size, PyArena
*arena);
enum _mod_kind {Module_kind=1, Interactive_kind=2, Expression_kind=3,
FunctionType_kind=4};
struct _mod {
enum _mod_kind kind;
union {
struct {
asdl_seq *body;
asdl_seq *type_ignores;
asdl_stmt_seq *body;
asdl_type_ignore_seq *type_ignores;
} Module;
struct {
asdl_seq *body;
asdl_stmt_seq *body;
} Interactive;
struct {
@ -66,7 +147,7 @@ struct _mod {
} Expression;
struct {
asdl_seq *argtypes;
asdl_expr_seq *argtypes;
expr_ty returns;
} FunctionType;
@ -87,8 +168,8 @@ struct _stmt {
struct {
identifier name;
arguments_ty args;
asdl_seq *body;
asdl_seq *decorator_list;
asdl_stmt_seq *body;
asdl_expr_seq *decorator_list;
expr_ty returns;
string type_comment;
} FunctionDef;
@ -96,18 +177,18 @@ struct _stmt {
struct {
identifier name;
arguments_ty args;
asdl_seq *body;
asdl_seq *decorator_list;
asdl_stmt_seq *body;
asdl_expr_seq *decorator_list;
expr_ty returns;
string type_comment;
} AsyncFunctionDef;
struct {
identifier name;
asdl_seq *bases;
asdl_seq *keywords;
asdl_seq *body;
asdl_seq *decorator_list;
asdl_expr_seq *bases;
asdl_keyword_seq *keywords;
asdl_stmt_seq *body;
asdl_expr_seq *decorator_list;
} ClassDef;
struct {
@ -115,11 +196,11 @@ struct _stmt {
} Return;
struct {
asdl_seq *targets;
asdl_expr_seq *targets;
} Delete;
struct {
asdl_seq *targets;
asdl_expr_seq *targets;
expr_ty value;
string type_comment;
} Assign;
@ -140,40 +221,40 @@ struct _stmt {
struct {
expr_ty target;
expr_ty iter;
asdl_seq *body;
asdl_seq *orelse;
asdl_stmt_seq *body;
asdl_stmt_seq *orelse;
string type_comment;
} For;
struct {
expr_ty target;
expr_ty iter;
asdl_seq *body;
asdl_seq *orelse;
asdl_stmt_seq *body;
asdl_stmt_seq *orelse;
string type_comment;
} AsyncFor;
struct {
expr_ty test;
asdl_seq *body;
asdl_seq *orelse;
asdl_stmt_seq *body;
asdl_stmt_seq *orelse;
} While;
struct {
expr_ty test;
asdl_seq *body;
asdl_seq *orelse;
asdl_stmt_seq *body;
asdl_stmt_seq *orelse;
} If;
struct {
asdl_seq *items;
asdl_seq *body;
asdl_withitem_seq *items;
asdl_stmt_seq *body;
string type_comment;
} With;
struct {
asdl_seq *items;
asdl_seq *body;
asdl_withitem_seq *items;
asdl_stmt_seq *body;
string type_comment;
} AsyncWith;
@ -183,10 +264,10 @@ struct _stmt {
} Raise;
struct {
asdl_seq *body;
asdl_seq *handlers;
asdl_seq *orelse;
asdl_seq *finalbody;
asdl_stmt_seq *body;
asdl_excepthandler_seq *handlers;
asdl_stmt_seq *orelse;
asdl_stmt_seq *finalbody;
} Try;
struct {
@ -195,21 +276,21 @@ struct _stmt {
} Assert;
struct {
asdl_seq *names;
asdl_alias_seq *names;
} Import;
struct {
identifier module;
asdl_seq *names;
asdl_alias_seq *names;
int level;
} ImportFrom;
struct {
asdl_seq *names;
asdl_identifier_seq *names;
} Global;
struct {
asdl_seq *names;
asdl_identifier_seq *names;
} Nonlocal;
struct {
@ -236,7 +317,7 @@ struct _expr {
union {
struct {
boolop_ty op;
asdl_seq *values;
asdl_expr_seq *values;
} BoolOp;
struct {
@ -267,33 +348,33 @@ struct _expr {
} IfExp;
struct {
asdl_seq *keys;
asdl_seq *values;
asdl_expr_seq *keys;
asdl_expr_seq *values;
} Dict;
struct {
asdl_seq *elts;
asdl_expr_seq *elts;
} Set;
struct {
expr_ty elt;
asdl_seq *generators;
asdl_comprehension_seq *generators;
} ListComp;
struct {
expr_ty elt;
asdl_seq *generators;
asdl_comprehension_seq *generators;
} SetComp;
struct {
expr_ty key;
expr_ty value;
asdl_seq *generators;
asdl_comprehension_seq *generators;
} DictComp;
struct {
expr_ty elt;
asdl_seq *generators;
asdl_comprehension_seq *generators;
} GeneratorExp;
struct {
@ -311,13 +392,13 @@ struct _expr {
struct {
expr_ty left;
asdl_int_seq *ops;
asdl_seq *comparators;
asdl_expr_seq *comparators;
} Compare;
struct {
expr_ty func;
asdl_seq *args;
asdl_seq *keywords;
asdl_expr_seq *args;
asdl_keyword_seq *keywords;
} Call;
struct {
@ -327,7 +408,7 @@ struct _expr {
} FormattedValue;
struct {
asdl_seq *values;
asdl_expr_seq *values;
} JoinedStr;
struct {
@ -358,12 +439,12 @@ struct _expr {
} Name;
struct {
asdl_seq *elts;
asdl_expr_seq *elts;
expr_context_ty ctx;
} List;
struct {
asdl_seq *elts;
asdl_expr_seq *elts;
expr_context_ty ctx;
} Tuple;
@ -383,7 +464,7 @@ struct _expr {
struct _comprehension {
expr_ty target;
expr_ty iter;
asdl_seq *ifs;
asdl_expr_seq *ifs;
int is_async;
};
@ -394,7 +475,7 @@ struct _excepthandler {
struct {
expr_ty type;
identifier name;
asdl_seq *body;
asdl_stmt_seq *body;
} ExceptHandler;
} v;
@ -405,13 +486,13 @@ struct _excepthandler {
};
struct _arguments {
asdl_seq *posonlyargs;
asdl_seq *args;
asdl_arg_seq *posonlyargs;
asdl_arg_seq *args;
arg_ty vararg;
asdl_seq *kwonlyargs;
asdl_seq *kw_defaults;
asdl_arg_seq *kwonlyargs;
asdl_expr_seq *kw_defaults;
arg_ty kwarg;
asdl_seq *defaults;
asdl_expr_seq *defaults;
};
struct _arg {
@ -458,39 +539,41 @@ struct _type_ignore {
// Note: these macros affect function definitions, not only call sites.
#define Module(a0, a1, a2) _Py_Module(a0, a1, a2)
mod_ty _Py_Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena);
mod_ty _Py_Module(asdl_stmt_seq * body, asdl_type_ignore_seq * type_ignores,
PyArena *arena);
#define Interactive(a0, a1) _Py_Interactive(a0, a1)
mod_ty _Py_Interactive(asdl_seq * body, PyArena *arena);
mod_ty _Py_Interactive(asdl_stmt_seq * body, PyArena *arena);
#define Expression(a0, a1) _Py_Expression(a0, a1)
mod_ty _Py_Expression(expr_ty body, PyArena *arena);
#define FunctionType(a0, a1, a2) _Py_FunctionType(a0, a1, a2)
mod_ty _Py_FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena);
mod_ty _Py_FunctionType(asdl_expr_seq * argtypes, expr_ty returns, PyArena
*arena);
#define FunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) _Py_FunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
stmt_ty _Py_FunctionDef(identifier name, arguments_ty args, asdl_seq * body,
asdl_seq * decorator_list, expr_ty returns, string
type_comment, int lineno, int col_offset, int
stmt_ty _Py_FunctionDef(identifier name, arguments_ty args, asdl_stmt_seq *
body, asdl_expr_seq * decorator_list, expr_ty returns,
string type_comment, int lineno, int col_offset, int
end_lineno, int end_col_offset, PyArena *arena);
#define AsyncFunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) _Py_AsyncFunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
stmt_ty _Py_AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq *
body, asdl_seq * decorator_list, expr_ty returns,
string type_comment, int lineno, int col_offset,
int end_lineno, int end_col_offset, PyArena
*arena);
#define ClassDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) _Py_ClassDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9)
stmt_ty _Py_ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords,
asdl_seq * body, asdl_seq * decorator_list, int lineno,
int col_offset, int end_lineno, int end_col_offset,
stmt_ty _Py_AsyncFunctionDef(identifier name, arguments_ty args, asdl_stmt_seq
* body, asdl_expr_seq * decorator_list, expr_ty
returns, string type_comment, int lineno, int
col_offset, int end_lineno, int end_col_offset,
PyArena *arena);
#define ClassDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) _Py_ClassDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9)
stmt_ty _Py_ClassDef(identifier name, asdl_expr_seq * bases, asdl_keyword_seq *
keywords, asdl_stmt_seq * body, asdl_expr_seq *
decorator_list, int lineno, int col_offset, int
end_lineno, int end_col_offset, PyArena *arena);
#define Return(a0, a1, a2, a3, a4, a5) _Py_Return(a0, a1, a2, a3, a4, a5)
stmt_ty _Py_Return(expr_ty value, int lineno, int col_offset, int end_lineno,
int end_col_offset, PyArena *arena);
#define Delete(a0, a1, a2, a3, a4, a5) _Py_Delete(a0, a1, a2, a3, a4, a5)
stmt_ty _Py_Delete(asdl_seq * targets, int lineno, int col_offset, int
stmt_ty _Py_Delete(asdl_expr_seq * targets, int lineno, int col_offset, int
end_lineno, int end_col_offset, PyArena *arena);
#define Assign(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Assign(a0, a1, a2, a3, a4, a5, a6, a7)
stmt_ty _Py_Assign(asdl_seq * targets, expr_ty value, string type_comment, int
lineno, int col_offset, int end_lineno, int end_col_offset,
PyArena *arena);
stmt_ty _Py_Assign(asdl_expr_seq * targets, expr_ty value, string type_comment,
int lineno, int col_offset, int end_lineno, int
end_col_offset, PyArena *arena);
#define AugAssign(a0, a1, a2, a3, a4, a5, a6, a7) _Py_AugAssign(a0, a1, a2, a3, a4, a5, a6, a7)
stmt_ty _Py_AugAssign(expr_ty target, operator_ty op, expr_ty value, int
lineno, int col_offset, int end_lineno, int
@ -500,52 +583,54 @@ stmt_ty _Py_AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int
simple, int lineno, int col_offset, int end_lineno, int
end_col_offset, PyArena *arena);
#define For(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) _Py_For(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9)
stmt_ty _Py_For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq *
orelse, string type_comment, int lineno, int col_offset, int
end_lineno, int end_col_offset, PyArena *arena);
stmt_ty _Py_For(expr_ty target, expr_ty iter, asdl_stmt_seq * body,
asdl_stmt_seq * orelse, string type_comment, int lineno, int
col_offset, int end_lineno, int end_col_offset, PyArena *arena);
#define AsyncFor(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) _Py_AsyncFor(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9)
stmt_ty _Py_AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq *
orelse, string type_comment, int lineno, int col_offset,
int end_lineno, int end_col_offset, PyArena *arena);
#define While(a0, a1, a2, a3, a4, a5, a6, a7) _Py_While(a0, a1, a2, a3, a4, a5, a6, a7)
stmt_ty _Py_While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno,
int col_offset, int end_lineno, int end_col_offset, PyArena
*arena);
#define If(a0, a1, a2, a3, a4, a5, a6, a7) _Py_If(a0, a1, a2, a3, a4, a5, a6, a7)
stmt_ty _Py_If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno,
int col_offset, int end_lineno, int end_col_offset, PyArena
*arena);
#define With(a0, a1, a2, a3, a4, a5, a6, a7) _Py_With(a0, a1, a2, a3, a4, a5, a6, a7)
stmt_ty _Py_With(asdl_seq * items, asdl_seq * body, string type_comment, int
lineno, int col_offset, int end_lineno, int end_col_offset,
stmt_ty _Py_AsyncFor(expr_ty target, expr_ty iter, asdl_stmt_seq * body,
asdl_stmt_seq * orelse, string type_comment, int lineno,
int col_offset, int end_lineno, int end_col_offset,
PyArena *arena);
#define AsyncWith(a0, a1, a2, a3, a4, a5, a6, a7) _Py_AsyncWith(a0, a1, a2, a3, a4, a5, a6, a7)
stmt_ty _Py_AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment,
#define While(a0, a1, a2, a3, a4, a5, a6, a7) _Py_While(a0, a1, a2, a3, a4, a5, a6, a7)
stmt_ty _Py_While(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse,
int lineno, int col_offset, int end_lineno, int
end_col_offset, PyArena *arena);
#define If(a0, a1, a2, a3, a4, a5, a6, a7) _Py_If(a0, a1, a2, a3, a4, a5, a6, a7)
stmt_ty _Py_If(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
lineno, int col_offset, int end_lineno, int end_col_offset,
PyArena *arena);
#define With(a0, a1, a2, a3, a4, a5, a6, a7) _Py_With(a0, a1, a2, a3, a4, a5, a6, a7)
stmt_ty _Py_With(asdl_withitem_seq * items, asdl_stmt_seq * body, string
type_comment, int lineno, int col_offset, int end_lineno, int
end_col_offset, PyArena *arena);
#define AsyncWith(a0, a1, a2, a3, a4, a5, a6, a7) _Py_AsyncWith(a0, a1, a2, a3, a4, a5, a6, a7)
stmt_ty _Py_AsyncWith(asdl_withitem_seq * items, asdl_stmt_seq * body, string
type_comment, int lineno, int col_offset, int end_lineno,
int end_col_offset, PyArena *arena);
#define Raise(a0, a1, a2, a3, a4, a5, a6) _Py_Raise(a0, a1, a2, a3, a4, a5, a6)
stmt_ty _Py_Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int
end_lineno, int end_col_offset, PyArena *arena);
#define Try(a0, a1, a2, a3, a4, a5, a6, a7, a8) _Py_Try(a0, a1, a2, a3, a4, a5, a6, a7, a8)
stmt_ty _Py_Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse,
asdl_seq * finalbody, int lineno, int col_offset, int
end_lineno, int end_col_offset, PyArena *arena);
stmt_ty _Py_Try(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers,
asdl_stmt_seq * orelse, asdl_stmt_seq * finalbody, int lineno,
int col_offset, int end_lineno, int end_col_offset, PyArena
*arena);
#define Assert(a0, a1, a2, a3, a4, a5, a6) _Py_Assert(a0, a1, a2, a3, a4, a5, a6)
stmt_ty _Py_Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int
end_lineno, int end_col_offset, PyArena *arena);
#define Import(a0, a1, a2, a3, a4, a5) _Py_Import(a0, a1, a2, a3, a4, a5)
stmt_ty _Py_Import(asdl_seq * names, int lineno, int col_offset, int
stmt_ty _Py_Import(asdl_alias_seq * names, int lineno, int col_offset, int
end_lineno, int end_col_offset, PyArena *arena);
#define ImportFrom(a0, a1, a2, a3, a4, a5, a6, a7) _Py_ImportFrom(a0, a1, a2, a3, a4, a5, a6, a7)
stmt_ty _Py_ImportFrom(identifier module, asdl_seq * names, int level, int
lineno, int col_offset, int end_lineno, int
stmt_ty _Py_ImportFrom(identifier module, asdl_alias_seq * names, int level,
int lineno, int col_offset, int end_lineno, int
end_col_offset, PyArena *arena);
#define Global(a0, a1, a2, a3, a4, a5) _Py_Global(a0, a1, a2, a3, a4, a5)
stmt_ty _Py_Global(asdl_seq * names, int lineno, int col_offset, int
stmt_ty _Py_Global(asdl_identifier_seq * names, int lineno, int col_offset, int
end_lineno, int end_col_offset, PyArena *arena);
#define Nonlocal(a0, a1, a2, a3, a4, a5) _Py_Nonlocal(a0, a1, a2, a3, a4, a5)
stmt_ty _Py_Nonlocal(asdl_seq * names, int lineno, int col_offset, int
end_lineno, int end_col_offset, PyArena *arena);
stmt_ty _Py_Nonlocal(asdl_identifier_seq * names, int lineno, int col_offset,
int end_lineno, int end_col_offset, PyArena *arena);
#define Expr(a0, a1, a2, a3, a4, a5) _Py_Expr(a0, a1, a2, a3, a4, a5)
stmt_ty _Py_Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
end_col_offset, PyArena *arena);
@ -559,8 +644,9 @@ stmt_ty _Py_Break(int lineno, int col_offset, int end_lineno, int
stmt_ty _Py_Continue(int lineno, int col_offset, int end_lineno, int
end_col_offset, PyArena *arena);
#define BoolOp(a0, a1, a2, a3, a4, a5, a6) _Py_BoolOp(a0, a1, a2, a3, a4, a5, a6)
expr_ty _Py_BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset,
int end_lineno, int end_col_offset, PyArena *arena);
expr_ty _Py_BoolOp(boolop_ty op, asdl_expr_seq * values, int lineno, int
col_offset, int end_lineno, int end_col_offset, PyArena
*arena);
#define NamedExpr(a0, a1, a2, a3, a4, a5, a6) _Py_NamedExpr(a0, a1, a2, a3, a4, a5, a6)
expr_ty _Py_NamedExpr(expr_ty target, expr_ty value, int lineno, int
col_offset, int end_lineno, int end_col_offset, PyArena
@ -580,28 +666,28 @@ expr_ty _Py_IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int
col_offset, int end_lineno, int end_col_offset, PyArena
*arena);
#define Dict(a0, a1, a2, a3, a4, a5, a6) _Py_Dict(a0, a1, a2, a3, a4, a5, a6)
expr_ty _Py_Dict(asdl_seq * keys, asdl_seq * values, int lineno, int
expr_ty _Py_Dict(asdl_expr_seq * keys, asdl_expr_seq * values, int lineno, int
col_offset, int end_lineno, int end_col_offset, PyArena
*arena);
#define Set(a0, a1, a2, a3, a4, a5) _Py_Set(a0, a1, a2, a3, a4, a5)
expr_ty _Py_Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno,
int end_col_offset, PyArena *arena);
expr_ty _Py_Set(asdl_expr_seq * elts, int lineno, int col_offset, int
end_lineno, int end_col_offset, PyArena *arena);
#define ListComp(a0, a1, a2, a3, a4, a5, a6) _Py_ListComp(a0, a1, a2, a3, a4, a5, a6)
expr_ty _Py_ListComp(expr_ty elt, asdl_seq * generators, int lineno, int
col_offset, int end_lineno, int end_col_offset, PyArena
*arena);
#define SetComp(a0, a1, a2, a3, a4, a5, a6) _Py_SetComp(a0, a1, a2, a3, a4, a5, a6)
expr_ty _Py_SetComp(expr_ty elt, asdl_seq * generators, int lineno, int
col_offset, int end_lineno, int end_col_offset, PyArena
*arena);
#define DictComp(a0, a1, a2, a3, a4, a5, a6, a7) _Py_DictComp(a0, a1, a2, a3, a4, a5, a6, a7)
expr_ty _Py_DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int
expr_ty _Py_ListComp(expr_ty elt, asdl_comprehension_seq * generators, int
lineno, int col_offset, int end_lineno, int
end_col_offset, PyArena *arena);
#define GeneratorExp(a0, a1, a2, a3, a4, a5, a6) _Py_GeneratorExp(a0, a1, a2, a3, a4, a5, a6)
expr_ty _Py_GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int
col_offset, int end_lineno, int end_col_offset,
#define SetComp(a0, a1, a2, a3, a4, a5, a6) _Py_SetComp(a0, a1, a2, a3, a4, a5, a6)
expr_ty _Py_SetComp(expr_ty elt, asdl_comprehension_seq * generators, int
lineno, int col_offset, int end_lineno, int end_col_offset,
PyArena *arena);
#define DictComp(a0, a1, a2, a3, a4, a5, a6, a7) _Py_DictComp(a0, a1, a2, a3, a4, a5, a6, a7)
expr_ty _Py_DictComp(expr_ty key, expr_ty value, asdl_comprehension_seq *
generators, int lineno, int col_offset, int end_lineno,
int end_col_offset, PyArena *arena);
#define GeneratorExp(a0, a1, a2, a3, a4, a5, a6) _Py_GeneratorExp(a0, a1, a2, a3, a4, a5, a6)
expr_ty _Py_GeneratorExp(expr_ty elt, asdl_comprehension_seq * generators, int
lineno, int col_offset, int end_lineno, int
end_col_offset, PyArena *arena);
#define Await(a0, a1, a2, a3, a4, a5) _Py_Await(a0, a1, a2, a3, a4, a5)
expr_ty _Py_Await(expr_ty value, int lineno, int col_offset, int end_lineno,
int end_col_offset, PyArena *arena);
@ -612,19 +698,19 @@ expr_ty _Py_Yield(expr_ty value, int lineno, int col_offset, int end_lineno,
expr_ty _Py_YieldFrom(expr_ty value, int lineno, int col_offset, int
end_lineno, int end_col_offset, PyArena *arena);
#define Compare(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Compare(a0, a1, a2, a3, a4, a5, a6, a7)
expr_ty _Py_Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators,
int lineno, int col_offset, int end_lineno, int
end_col_offset, PyArena *arena);
expr_ty _Py_Compare(expr_ty left, asdl_int_seq * ops, asdl_expr_seq *
comparators, int lineno, int col_offset, int end_lineno,
int end_col_offset, PyArena *arena);
#define Call(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Call(a0, a1, a2, a3, a4, a5, a6, a7)
expr_ty _Py_Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int
lineno, int col_offset, int end_lineno, int end_col_offset,
PyArena *arena);
expr_ty _Py_Call(expr_ty func, asdl_expr_seq * args, asdl_keyword_seq *
keywords, int lineno, int col_offset, int end_lineno, int
end_col_offset, PyArena *arena);
#define FormattedValue(a0, a1, a2, a3, a4, a5, a6, a7) _Py_FormattedValue(a0, a1, a2, a3, a4, a5, a6, a7)
expr_ty _Py_FormattedValue(expr_ty value, int conversion, expr_ty format_spec,
int lineno, int col_offset, int end_lineno, int
end_col_offset, PyArena *arena);
#define JoinedStr(a0, a1, a2, a3, a4, a5) _Py_JoinedStr(a0, a1, a2, a3, a4, a5)
expr_ty _Py_JoinedStr(asdl_seq * values, int lineno, int col_offset, int
expr_ty _Py_JoinedStr(asdl_expr_seq * values, int lineno, int col_offset, int
end_lineno, int end_col_offset, PyArena *arena);
#define Constant(a0, a1, a2, a3, a4, a5, a6) _Py_Constant(a0, a1, a2, a3, a4, a5, a6)
expr_ty _Py_Constant(constant value, string kind, int lineno, int col_offset,
@ -646,11 +732,11 @@ expr_ty _Py_Name(identifier id, expr_context_ty ctx, int lineno, int
col_offset, int end_lineno, int end_col_offset, PyArena
*arena);
#define List(a0, a1, a2, a3, a4, a5, a6) _Py_List(a0, a1, a2, a3, a4, a5, a6)
expr_ty _Py_List(asdl_seq * elts, expr_context_ty ctx, int lineno, int
expr_ty _Py_List(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
col_offset, int end_lineno, int end_col_offset, PyArena
*arena);
#define Tuple(a0, a1, a2, a3, a4, a5, a6) _Py_Tuple(a0, a1, a2, a3, a4, a5, a6)
expr_ty _Py_Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int
expr_ty _Py_Tuple(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
col_offset, int end_lineno, int end_col_offset, PyArena
*arena);
#define Slice(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Slice(a0, a1, a2, a3, a4, a5, a6, a7)
@ -658,18 +744,18 @@ expr_ty _Py_Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int
col_offset, int end_lineno, int end_col_offset, PyArena
*arena);
#define comprehension(a0, a1, a2, a3, a4) _Py_comprehension(a0, a1, a2, a3, a4)
comprehension_ty _Py_comprehension(expr_ty target, expr_ty iter, asdl_seq *
ifs, int is_async, PyArena *arena);
comprehension_ty _Py_comprehension(expr_ty target, expr_ty iter, asdl_expr_seq
* ifs, int is_async, PyArena *arena);
#define ExceptHandler(a0, a1, a2, a3, a4, a5, a6, a7) _Py_ExceptHandler(a0, a1, a2, a3, a4, a5, a6, a7)
excepthandler_ty _Py_ExceptHandler(expr_ty type, identifier name, asdl_seq *
body, int lineno, int col_offset, int
excepthandler_ty _Py_ExceptHandler(expr_ty type, identifier name, asdl_stmt_seq
* body, int lineno, int col_offset, int
end_lineno, int end_col_offset, PyArena
*arena);
#define arguments(a0, a1, a2, a3, a4, a5, a6, a7) _Py_arguments(a0, a1, a2, a3, a4, a5, a6, a7)
arguments_ty _Py_arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty
vararg, asdl_seq * kwonlyargs, asdl_seq *
kw_defaults, arg_ty kwarg, asdl_seq * defaults,
PyArena *arena);
arguments_ty _Py_arguments(asdl_arg_seq * posonlyargs, asdl_arg_seq * args,
arg_ty vararg, asdl_arg_seq * kwonlyargs,
asdl_expr_seq * kw_defaults, arg_ty kwarg,
asdl_expr_seq * defaults, PyArena *arena);
#define arg(a0, a1, a2, a3, a4, a5, a6, a7) _Py_arg(a0, a1, a2, a3, a4, a5, a6, a7)
arg_ty _Py_arg(identifier arg, expr_ty annotation, string type_comment, int
lineno, int col_offset, int end_lineno, int end_col_offset,

View File

@ -13,25 +13,80 @@ typedef PyObject * constant;
interned Python strings.
*/
/* XXX A sequence should be typed so that its use can be typechecked. */
#define _ASDL_SEQ_HEAD \
Py_ssize_t size; \
void **elements;
typedef struct {
Py_ssize_t size;
void *elements[1];
_ASDL_SEQ_HEAD
} asdl_seq;
typedef struct {
Py_ssize_t size;
int elements[1];
_ASDL_SEQ_HEAD
void *typed_elements[1];
} asdl_generic_seq;
typedef struct {
_ASDL_SEQ_HEAD
PyObject *typed_elements[1];
} asdl_identifier_seq;
typedef struct {
_ASDL_SEQ_HEAD
int typed_elements[1];
} asdl_int_seq;
asdl_seq *_Py_asdl_seq_new(Py_ssize_t size, PyArena *arena);
asdl_generic_seq *_Py_asdl_generic_seq_new(Py_ssize_t size, PyArena *arena);
asdl_identifier_seq *_Py_asdl_identifier_seq_new(Py_ssize_t size, PyArena *arena);
asdl_int_seq *_Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena);
#define asdl_seq_GET(S, I) (S)->elements[(I)]
#define GENERATE_ASDL_SEQ_CONSTRUCTOR(NAME, TYPE) \
asdl_ ## NAME ## _seq *_Py_asdl_ ## NAME ## _seq_new(Py_ssize_t size, PyArena *arena) \
{ \
asdl_ ## NAME ## _seq *seq = NULL; \
size_t n; \
/* check size is sane */ \
if (size < 0 || \
(size && (((size_t)size - 1) > (SIZE_MAX / sizeof(void *))))) { \
PyErr_NoMemory(); \
return NULL; \
} \
n = (size ? (sizeof(TYPE *) * (size - 1)) : 0); \
/* check if size can be added safely */ \
if (n > SIZE_MAX - sizeof(asdl_ ## NAME ## _seq)) { \
PyErr_NoMemory(); \
return NULL; \
} \
n += sizeof(asdl_ ## NAME ## _seq); \
seq = (asdl_ ## NAME ## _seq *)PyArena_Malloc(arena, n); \
if (!seq) { \
PyErr_NoMemory(); \
return NULL; \
} \
memset(seq, 0, n); \
seq->size = size; \
seq->elements = (void**)seq->typed_elements; \
return seq; \
}
#define asdl_seq_GET_UNTYPED(S, I) (S)->elements[(I)]
#define asdl_seq_GET(S, I) (S)->typed_elements[(I)]
#define asdl_seq_LEN(S) ((S) == NULL ? 0 : (S)->size)
#ifdef Py_DEBUG
#define asdl_seq_SET(S, I, V) \
do { \
Py_ssize_t _asdl_i = (I); \
assert((S) != NULL); \
assert(0 <= _asdl_i && _asdl_i < (S)->size); \
(S)->typed_elements[_asdl_i] = (V); \
} while (0)
#else
#define asdl_seq_SET(S, I, V) (S)->typed_elements[I] = (V)
#endif
#ifdef Py_DEBUG
#define asdl_seq_SET_UNTYPED(S, I, V) \
do { \
Py_ssize_t _asdl_i = (I); \
assert((S) != NULL); \
@ -39,7 +94,7 @@ asdl_int_seq *_Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena);
(S)->elements[_asdl_i] = (V); \
} while (0)
#else
#define asdl_seq_SET(S, I, V) (S)->elements[I] = (V)
#define asdl_seq_SET_UNTYPED(S, I, V) (S)->elements[I] = (V)
#endif
#endif /* !Py_ASDL_H */

View File

@ -15,7 +15,7 @@ PyAPI_FUNC(PyObject *) _PyAST_ExprAsUnicode(expr_ty);
/* Return the borrowed reference to the first literal string in the
sequence of statements or NULL if it doesn't start from a literal string.
Doesn't set exception. */
PyAPI_FUNC(PyObject *) _PyAST_GetDocString(asdl_seq *);
PyAPI_FUNC(PyObject *) _PyAST_GetDocString(asdl_stmt_seq *);
#ifdef __cplusplus
}

View File

@ -163,6 +163,32 @@ class TypeDefVisitor(EmitVisitor):
self.emit(s, depth)
self.emit("", depth)
class SequenceDefVisitor(EmitVisitor):
def visitModule(self, mod):
for dfn in mod.dfns:
self.visit(dfn)
def visitType(self, type, depth=0):
self.visit(type.value, type.name, depth)
def visitSum(self, sum, name, depth):
if is_simple(sum):
return
self.emit_sequence_constructor(name, depth)
def emit_sequence_constructor(self, name,depth):
ctype = get_c_type(name)
self.emit("""\
typedef struct {
_ASDL_SEQ_HEAD
%(ctype)s typed_elements[1];
} asdl_%(name)s_seq;""" % locals(), reflow=False, depth=depth)
self.emit("", depth)
self.emit("asdl_%(name)s_seq *_Py_asdl_%(name)s_seq_new(Py_ssize_t size, PyArena *arena);" % locals(), depth)
self.emit("", depth)
def visitProduct(self, product, name, depth):
self.emit_sequence_constructor(name, depth)
class StructVisitor(EmitVisitor):
"""Visitor to generate typedefs for AST."""
@ -219,7 +245,8 @@ class StructVisitor(EmitVisitor):
if field.type == 'cmpop':
self.emit("asdl_int_seq *%(name)s;" % locals(), depth)
else:
self.emit("asdl_seq *%(name)s;" % locals(), depth)
_type = field.type
self.emit("asdl_%(_type)s_seq *%(name)s;" % locals(), depth)
else:
self.emit("%(ctype)s %(name)s;" % locals(), depth)
@ -274,7 +301,7 @@ class PrototypeVisitor(EmitVisitor):
if f.type == 'cmpop':
ctype = "asdl_int_seq *"
else:
ctype = "asdl_seq *"
ctype = f"asdl_{f.type}_seq *"
else:
ctype = get_c_type(f.type)
args.append((ctype, name, f.opt or f.seq))
@ -507,7 +534,8 @@ class Obj2ModVisitor(PickleVisitor):
if self.isSimpleType(field):
self.emit("asdl_int_seq* %s;" % field.name, depth)
else:
self.emit("asdl_seq* %s;" % field.name, depth)
_type = field.type
self.emit(f"asdl_{field.type}_seq* {field.name};", depth)
else:
ctype = get_c_type(field.type)
self.emit("%s %s;" % (ctype, field.name), depth)
@ -562,7 +590,7 @@ class Obj2ModVisitor(PickleVisitor):
if self.isSimpleType(field):
self.emit("%s = _Py_asdl_int_seq_new(len, arena);" % field.name, depth+1)
else:
self.emit("%s = _Py_asdl_seq_new(len, arena);" % field.name, depth+1)
self.emit("%s = _Py_asdl_%s_seq_new(len, arena);" % (field.name, field.type), depth+1)
self.emit("if (%s == NULL) goto failed;" % field.name, depth+1)
self.emit("for (i = 0; i < len; i++) {", depth+1)
self.emit("%s val;" % ctype, depth+2)
@ -600,6 +628,24 @@ class MarshalPrototypeVisitor(PickleVisitor):
visitProduct = visitSum = prototype
class SequenceConstructorVisitor(EmitVisitor):
def visitModule(self, mod):
for dfn in mod.dfns:
self.visit(dfn)
def visitType(self, type):
self.visit(type.value, type.name)
def visitProduct(self, prod, name):
self.emit_sequence_constructor(name, get_c_type(name))
def visitSum(self, sum, name):
if not is_simple(sum):
self.emit_sequence_constructor(name, get_c_type(name))
def emit_sequence_constructor(self, name, type):
self.emit(f"GENERATE_ASDL_SEQ_CONSTRUCTOR({name}, {type})", depth=0)
class PyTypesDeclareVisitor(PickleVisitor):
def visitProduct(self, prod, name):
@ -647,6 +693,7 @@ class PyTypesDeclareVisitor(PickleVisitor):
self.emit('"%s",' % t.name, 1)
self.emit("};",0)
class PyTypesVisitor(PickleVisitor):
def visitModule(self, mod):
@ -874,7 +921,7 @@ static PyObject* ast2obj_list(astmodulestate *state, asdl_seq *seq, PyObject* (*
if (!result)
return NULL;
for (i = 0; i < n; i++) {
value = func(state, asdl_seq_GET(seq, i));
value = func(state, asdl_seq_GET_UNTYPED(seq, i));
if (!value) {
Py_DECREF(result);
return NULL;
@ -1264,7 +1311,7 @@ class ObjVisitor(PickleVisitor):
depth+2, reflow=False)
self.emit("}", depth)
else:
self.emit("value = ast2obj_list(state, %s, ast2obj_%s);" % (value, field.type), depth)
self.emit("value = ast2obj_list(state, (asdl_seq*)%s, ast2obj_%s);" % (value, field.type), depth)
else:
ctype = get_c_type(field.type)
self.emit("value = ast2obj_%s(state, %s);" % (field.type, value), depth, reflow=False)
@ -1431,6 +1478,7 @@ def write_header(f, mod):
f.write('#undef Yield /* undefine macro conflicting with <winbase.h> */\n')
f.write('\n')
c = ChainOfVisitors(TypeDefVisitor(f),
SequenceDefVisitor(f),
StructVisitor(f))
c.visit(mod)
f.write("// Note: these macros affect function definitions, not only call sites.\n")
@ -1457,6 +1505,7 @@ def write_source(f, mod):
generate_module_def(f, mod)
v = ChainOfVisitors(
SequenceConstructorVisitor(f),
PyTypesDeclareVisitor(f),
PyTypesVisitor(f),
Obj2ModPrototypeVisitor(f),

File diff suppressed because it is too large Load Diff

View File

@ -1243,7 +1243,7 @@ error:
return result;
}
void *
asdl_stmt_seq*
_PyPegen_interactive_exit(Parser *p)
{
if (p->errcode) {
@ -1257,11 +1257,11 @@ asdl_seq *
_PyPegen_singleton_seq(Parser *p, void *a)
{
assert(a != NULL);
asdl_seq *seq = _Py_asdl_seq_new(1, p->arena);
asdl_seq *seq = (asdl_seq*)_Py_asdl_generic_seq_new(1, p->arena);
if (!seq) {
return NULL;
}
asdl_seq_SET(seq, 0, a);
asdl_seq_SET_UNTYPED(seq, 0, a);
return seq;
}
@ -1274,14 +1274,14 @@ _PyPegen_seq_insert_in_front(Parser *p, void *a, asdl_seq *seq)
return _PyPegen_singleton_seq(p, a);
}
asdl_seq *new_seq = _Py_asdl_seq_new(asdl_seq_LEN(seq) + 1, p->arena);
asdl_seq *new_seq = (asdl_seq*)_Py_asdl_generic_seq_new(asdl_seq_LEN(seq) + 1, p->arena);
if (!new_seq) {
return NULL;
}
asdl_seq_SET(new_seq, 0, a);
asdl_seq_SET_UNTYPED(new_seq, 0, a);
for (Py_ssize_t i = 1, l = asdl_seq_LEN(new_seq); i < l; i++) {
asdl_seq_SET(new_seq, i, asdl_seq_GET(seq, i - 1));
asdl_seq_SET_UNTYPED(new_seq, i, asdl_seq_GET_UNTYPED(seq, i - 1));
}
return new_seq;
}
@ -1295,15 +1295,15 @@ _PyPegen_seq_append_to_end(Parser *p, asdl_seq *seq, void *a)
return _PyPegen_singleton_seq(p, a);
}
asdl_seq *new_seq = _Py_asdl_seq_new(asdl_seq_LEN(seq) + 1, p->arena);
asdl_seq *new_seq = (asdl_seq*)_Py_asdl_generic_seq_new(asdl_seq_LEN(seq) + 1, p->arena);
if (!new_seq) {
return NULL;
}
for (Py_ssize_t i = 0, l = asdl_seq_LEN(new_seq); i + 1 < l; i++) {
asdl_seq_SET(new_seq, i, asdl_seq_GET(seq, i));
asdl_seq_SET_UNTYPED(new_seq, i, asdl_seq_GET_UNTYPED(seq, i));
}
asdl_seq_SET(new_seq, asdl_seq_LEN(new_seq) - 1, a);
asdl_seq_SET_UNTYPED(new_seq, asdl_seq_LEN(new_seq) - 1, a);
return new_seq;
}
@ -1312,7 +1312,7 @@ _get_flattened_seq_size(asdl_seq *seqs)
{
Py_ssize_t size = 0;
for (Py_ssize_t i = 0, l = asdl_seq_LEN(seqs); i < l; i++) {
asdl_seq *inner_seq = asdl_seq_GET(seqs, i);
asdl_seq *inner_seq = asdl_seq_GET_UNTYPED(seqs, i);
size += asdl_seq_LEN(inner_seq);
}
return size;
@ -1325,16 +1325,16 @@ _PyPegen_seq_flatten(Parser *p, asdl_seq *seqs)
Py_ssize_t flattened_seq_size = _get_flattened_seq_size(seqs);
assert(flattened_seq_size > 0);
asdl_seq *flattened_seq = _Py_asdl_seq_new(flattened_seq_size, p->arena);
asdl_seq *flattened_seq = (asdl_seq*)_Py_asdl_generic_seq_new(flattened_seq_size, p->arena);
if (!flattened_seq) {
return NULL;
}
int flattened_seq_idx = 0;
for (Py_ssize_t i = 0, l = asdl_seq_LEN(seqs); i < l; i++) {
asdl_seq *inner_seq = asdl_seq_GET(seqs, i);
asdl_seq *inner_seq = asdl_seq_GET_UNTYPED(seqs, i);
for (Py_ssize_t j = 0, li = asdl_seq_LEN(inner_seq); j < li; j++) {
asdl_seq_SET(flattened_seq, flattened_seq_idx++, asdl_seq_GET(inner_seq, j));
asdl_seq_SET_UNTYPED(flattened_seq, flattened_seq_idx++, asdl_seq_GET_UNTYPED(inner_seq, j));
}
}
assert(flattened_seq_idx == flattened_seq_size);
@ -1403,7 +1403,7 @@ _PyPegen_seq_count_dots(asdl_seq *seq)
{
int number_of_dots = 0;
for (Py_ssize_t i = 0, l = asdl_seq_LEN(seq); i < l; i++) {
Token *current_expr = asdl_seq_GET(seq, i);
Token *current_expr = asdl_seq_GET_UNTYPED(seq, i);
switch (current_expr->type) {
case ELLIPSIS:
number_of_dots += 3;
@ -1435,13 +1435,13 @@ _PyPegen_alias_for_star(Parser *p)
}
/* Creates a new asdl_seq* with the identifiers of all the names in seq */
asdl_seq *
_PyPegen_map_names_to_ids(Parser *p, asdl_seq *seq)
asdl_identifier_seq *
_PyPegen_map_names_to_ids(Parser *p, asdl_expr_seq *seq)
{
Py_ssize_t len = asdl_seq_LEN(seq);
assert(len > 0);
asdl_seq *new_seq = _Py_asdl_seq_new(len, p->arena);
asdl_identifier_seq *new_seq = _Py_asdl_identifier_seq_new(len, p->arena);
if (!new_seq) {
return NULL;
}
@ -1477,39 +1477,39 @@ _PyPegen_get_cmpops(Parser *p, asdl_seq *seq)
return NULL;
}
for (Py_ssize_t i = 0; i < len; i++) {
CmpopExprPair *pair = asdl_seq_GET(seq, i);
CmpopExprPair *pair = asdl_seq_GET_UNTYPED(seq, i);
asdl_seq_SET(new_seq, i, pair->cmpop);
}
return new_seq;
}
asdl_seq *
asdl_expr_seq *
_PyPegen_get_exprs(Parser *p, asdl_seq *seq)
{
Py_ssize_t len = asdl_seq_LEN(seq);
assert(len > 0);
asdl_seq *new_seq = _Py_asdl_seq_new(len, p->arena);
asdl_expr_seq *new_seq = _Py_asdl_expr_seq_new(len, p->arena);
if (!new_seq) {
return NULL;
}
for (Py_ssize_t i = 0; i < len; i++) {
CmpopExprPair *pair = asdl_seq_GET(seq, i);
CmpopExprPair *pair = asdl_seq_GET_UNTYPED(seq, i);
asdl_seq_SET(new_seq, i, pair->expr);
}
return new_seq;
}
/* Creates an asdl_seq* where all the elements have been changed to have ctx as context */
static asdl_seq *
_set_seq_context(Parser *p, asdl_seq *seq, expr_context_ty ctx)
static asdl_expr_seq *
_set_seq_context(Parser *p, asdl_expr_seq *seq, expr_context_ty ctx)
{
Py_ssize_t len = asdl_seq_LEN(seq);
if (len == 0) {
return NULL;
}
asdl_seq *new_seq = _Py_asdl_seq_new(len, p->arena);
asdl_expr_seq *new_seq = _Py_asdl_expr_seq_new(len, p->arena);
if (!new_seq) {
return NULL;
}
@ -1529,13 +1529,19 @@ _set_name_context(Parser *p, expr_ty e, expr_context_ty ctx)
static expr_ty
_set_tuple_context(Parser *p, expr_ty e, expr_context_ty ctx)
{
return _Py_Tuple(_set_seq_context(p, e->v.Tuple.elts, ctx), ctx, EXTRA_EXPR(e, e));
return _Py_Tuple(
_set_seq_context(p, e->v.Tuple.elts, ctx),
ctx,
EXTRA_EXPR(e, e));
}
static expr_ty
_set_list_context(Parser *p, expr_ty e, expr_context_ty ctx)
{
return _Py_List(_set_seq_context(p, e->v.List.elts, ctx), ctx, EXTRA_EXPR(e, e));
return _Py_List(
_set_seq_context(p, e->v.List.elts, ctx),
ctx,
EXTRA_EXPR(e, e));
}
static expr_ty
@ -1602,32 +1608,32 @@ _PyPegen_key_value_pair(Parser *p, expr_ty key, expr_ty value)
}
/* Extracts all keys from an asdl_seq* of KeyValuePair*'s */
asdl_seq *
asdl_expr_seq *
_PyPegen_get_keys(Parser *p, asdl_seq *seq)
{
Py_ssize_t len = asdl_seq_LEN(seq);
asdl_seq *new_seq = _Py_asdl_seq_new(len, p->arena);
asdl_expr_seq *new_seq = _Py_asdl_expr_seq_new(len, p->arena);
if (!new_seq) {
return NULL;
}
for (Py_ssize_t i = 0; i < len; i++) {
KeyValuePair *pair = asdl_seq_GET(seq, i);
KeyValuePair *pair = asdl_seq_GET_UNTYPED(seq, i);
asdl_seq_SET(new_seq, i, pair->key);
}
return new_seq;
}
/* Extracts all values from an asdl_seq* of KeyValuePair*'s */
asdl_seq *
asdl_expr_seq *
_PyPegen_get_values(Parser *p, asdl_seq *seq)
{
Py_ssize_t len = asdl_seq_LEN(seq);
asdl_seq *new_seq = _Py_asdl_seq_new(len, p->arena);
asdl_expr_seq *new_seq = _Py_asdl_expr_seq_new(len, p->arena);
if (!new_seq) {
return NULL;
}
for (Py_ssize_t i = 0; i < len; i++) {
KeyValuePair *pair = asdl_seq_GET(seq, i);
KeyValuePair *pair = asdl_seq_GET_UNTYPED(seq, i);
asdl_seq_SET(new_seq, i, pair->value);
}
return new_seq;
@ -1648,7 +1654,7 @@ _PyPegen_name_default_pair(Parser *p, arg_ty arg, expr_ty value, Token *tc)
/* Constructs a SlashWithDefault */
SlashWithDefault *
_PyPegen_slash_with_default(Parser *p, asdl_seq *plain_names, asdl_seq *names_with_defaults)
_PyPegen_slash_with_default(Parser *p, asdl_arg_seq *plain_names, asdl_seq *names_with_defaults)
{
SlashWithDefault *a = PyArena_Malloc(p->arena, sizeof(SlashWithDefault));
if (!a) {
@ -1678,47 +1684,47 @@ _PyPegen_join_sequences(Parser *p, asdl_seq *a, asdl_seq *b)
{
Py_ssize_t first_len = asdl_seq_LEN(a);
Py_ssize_t second_len = asdl_seq_LEN(b);
asdl_seq *new_seq = _Py_asdl_seq_new(first_len + second_len, p->arena);
asdl_seq *new_seq = (asdl_seq*)_Py_asdl_generic_seq_new(first_len + second_len, p->arena);
if (!new_seq) {
return NULL;
}
int k = 0;
for (Py_ssize_t i = 0; i < first_len; i++) {
asdl_seq_SET(new_seq, k++, asdl_seq_GET(a, i));
asdl_seq_SET_UNTYPED(new_seq, k++, asdl_seq_GET_UNTYPED(a, i));
}
for (Py_ssize_t i = 0; i < second_len; i++) {
asdl_seq_SET(new_seq, k++, asdl_seq_GET(b, i));
asdl_seq_SET_UNTYPED(new_seq, k++, asdl_seq_GET_UNTYPED(b, i));
}
return new_seq;
}
static asdl_seq *
static asdl_arg_seq*
_get_names(Parser *p, asdl_seq *names_with_defaults)
{
Py_ssize_t len = asdl_seq_LEN(names_with_defaults);
asdl_seq *seq = _Py_asdl_seq_new(len, p->arena);
asdl_arg_seq *seq = _Py_asdl_arg_seq_new(len, p->arena);
if (!seq) {
return NULL;
}
for (Py_ssize_t i = 0; i < len; i++) {
NameDefaultPair *pair = asdl_seq_GET(names_with_defaults, i);
NameDefaultPair *pair = asdl_seq_GET_UNTYPED(names_with_defaults, i);
asdl_seq_SET(seq, i, pair->arg);
}
return seq;
}
static asdl_seq *
static asdl_expr_seq *
_get_defaults(Parser *p, asdl_seq *names_with_defaults)
{
Py_ssize_t len = asdl_seq_LEN(names_with_defaults);
asdl_seq *seq = _Py_asdl_seq_new(len, p->arena);
asdl_expr_seq *seq = _Py_asdl_expr_seq_new(len, p->arena);
if (!seq) {
return NULL;
}
for (Py_ssize_t i = 0; i < len; i++) {
NameDefaultPair *pair = asdl_seq_GET(names_with_defaults, i);
NameDefaultPair *pair = asdl_seq_GET_UNTYPED(names_with_defaults, i);
asdl_seq_SET(seq, i, pair->value);
}
return seq;
@ -1726,39 +1732,45 @@ _get_defaults(Parser *p, asdl_seq *names_with_defaults)
/* Constructs an arguments_ty object out of all the parsed constructs in the parameters rule */
arguments_ty
_PyPegen_make_arguments(Parser *p, asdl_seq *slash_without_default,
SlashWithDefault *slash_with_default, asdl_seq *plain_names,
_PyPegen_make_arguments(Parser *p, asdl_arg_seq *slash_without_default,
SlashWithDefault *slash_with_default, asdl_arg_seq *plain_names,
asdl_seq *names_with_default, StarEtc *star_etc)
{
asdl_seq *posonlyargs;
asdl_arg_seq *posonlyargs;
if (slash_without_default != NULL) {
posonlyargs = slash_without_default;
}
else if (slash_with_default != NULL) {
asdl_seq *slash_with_default_names =
asdl_arg_seq *slash_with_default_names =
_get_names(p, slash_with_default->names_with_defaults);
if (!slash_with_default_names) {
return NULL;
}
posonlyargs = _PyPegen_join_sequences(p, slash_with_default->plain_names, slash_with_default_names);
posonlyargs = (asdl_arg_seq*)_PyPegen_join_sequences(
p,
(asdl_seq*)slash_with_default->plain_names,
(asdl_seq*)slash_with_default_names);
if (!posonlyargs) {
return NULL;
}
}
else {
posonlyargs = _Py_asdl_seq_new(0, p->arena);
posonlyargs = _Py_asdl_arg_seq_new(0, p->arena);
if (!posonlyargs) {
return NULL;
}
}
asdl_seq *posargs;
asdl_arg_seq *posargs;
if (plain_names != NULL && names_with_default != NULL) {
asdl_seq *names_with_default_names = _get_names(p, names_with_default);
asdl_arg_seq *names_with_default_names = _get_names(p, names_with_default);
if (!names_with_default_names) {
return NULL;
}
posargs = _PyPegen_join_sequences(p, plain_names, names_with_default_names);
posargs = (asdl_arg_seq*)_PyPegen_join_sequences(
p,
(asdl_seq*)plain_names,
(asdl_seq*)names_with_default_names);
if (!posargs) {
return NULL;
}
@ -1773,24 +1785,27 @@ _PyPegen_make_arguments(Parser *p, asdl_seq *slash_without_default,
posargs = plain_names;
}
else {
posargs = _Py_asdl_seq_new(0, p->arena);
posargs = _Py_asdl_arg_seq_new(0, p->arena);
if (!posargs) {
return NULL;
}
}
asdl_seq *posdefaults;
asdl_expr_seq *posdefaults;
if (slash_with_default != NULL && names_with_default != NULL) {
asdl_seq *slash_with_default_values =
asdl_expr_seq *slash_with_default_values =
_get_defaults(p, slash_with_default->names_with_defaults);
if (!slash_with_default_values) {
return NULL;
}
asdl_seq *names_with_default_values = _get_defaults(p, names_with_default);
asdl_expr_seq *names_with_default_values = _get_defaults(p, names_with_default);
if (!names_with_default_values) {
return NULL;
}
posdefaults = _PyPegen_join_sequences(p, slash_with_default_values, names_with_default_values);
posdefaults = (asdl_expr_seq*)_PyPegen_join_sequences(
p,
(asdl_seq*)slash_with_default_values,
(asdl_seq*)names_with_default_values);
if (!posdefaults) {
return NULL;
}
@ -1808,7 +1823,7 @@ _PyPegen_make_arguments(Parser *p, asdl_seq *slash_without_default,
}
}
else {
posdefaults = _Py_asdl_seq_new(0, p->arena);
posdefaults = _Py_asdl_expr_seq_new(0, p->arena);
if (!posdefaults) {
return NULL;
}
@ -1819,7 +1834,7 @@ _PyPegen_make_arguments(Parser *p, asdl_seq *slash_without_default,
vararg = star_etc->vararg;
}
asdl_seq *kwonlyargs;
asdl_arg_seq *kwonlyargs;
if (star_etc != NULL && star_etc->kwonlyargs != NULL) {
kwonlyargs = _get_names(p, star_etc->kwonlyargs);
if (!kwonlyargs) {
@ -1827,13 +1842,13 @@ _PyPegen_make_arguments(Parser *p, asdl_seq *slash_without_default,
}
}
else {
kwonlyargs = _Py_asdl_seq_new(0, p->arena);
kwonlyargs = _Py_asdl_arg_seq_new(0, p->arena);
if (!kwonlyargs) {
return NULL;
}
}
asdl_seq *kwdefaults;
asdl_expr_seq *kwdefaults;
if (star_etc != NULL && star_etc->kwonlyargs != NULL) {
kwdefaults = _get_defaults(p, star_etc->kwonlyargs);
if (!kwdefaults) {
@ -1841,7 +1856,7 @@ _PyPegen_make_arguments(Parser *p, asdl_seq *slash_without_default,
}
}
else {
kwdefaults = _Py_asdl_seq_new(0, p->arena);
kwdefaults = _Py_asdl_expr_seq_new(0, p->arena);
if (!kwdefaults) {
return NULL;
}
@ -1861,23 +1876,23 @@ _PyPegen_make_arguments(Parser *p, asdl_seq *slash_without_default,
arguments_ty
_PyPegen_empty_arguments(Parser *p)
{
asdl_seq *posonlyargs = _Py_asdl_seq_new(0, p->arena);
asdl_arg_seq *posonlyargs = _Py_asdl_arg_seq_new(0, p->arena);
if (!posonlyargs) {
return NULL;
}
asdl_seq *posargs = _Py_asdl_seq_new(0, p->arena);
asdl_arg_seq *posargs = _Py_asdl_arg_seq_new(0, p->arena);
if (!posargs) {
return NULL;
}
asdl_seq *posdefaults = _Py_asdl_seq_new(0, p->arena);
asdl_expr_seq *posdefaults = _Py_asdl_expr_seq_new(0, p->arena);
if (!posdefaults) {
return NULL;
}
asdl_seq *kwonlyargs = _Py_asdl_seq_new(0, p->arena);
asdl_arg_seq *kwonlyargs = _Py_asdl_arg_seq_new(0, p->arena);
if (!kwonlyargs) {
return NULL;
}
asdl_seq *kwdefaults = _Py_asdl_seq_new(0, p->arena);
asdl_expr_seq *kwdefaults = _Py_asdl_expr_seq_new(0, p->arena);
if (!kwdefaults) {
return NULL;
}
@ -1900,7 +1915,7 @@ _PyPegen_augoperator(Parser *p, operator_ty kind)
/* Construct a FunctionDef equivalent to function_def, but with decorators */
stmt_ty
_PyPegen_function_def_decorators(Parser *p, asdl_seq *decorators, stmt_ty function_def)
_PyPegen_function_def_decorators(Parser *p, asdl_expr_seq *decorators, stmt_ty function_def)
{
assert(function_def != NULL);
if (function_def->kind == AsyncFunctionDef_kind) {
@ -1922,7 +1937,7 @@ _PyPegen_function_def_decorators(Parser *p, asdl_seq *decorators, stmt_ty functi
/* Construct a ClassDef equivalent to class_def, but with decorators */
stmt_ty
_PyPegen_class_def_decorators(Parser *p, asdl_seq *decorators, stmt_ty class_def)
_PyPegen_class_def_decorators(Parser *p, asdl_expr_seq *decorators, stmt_ty class_def)
{
assert(class_def != NULL);
return _Py_ClassDef(class_def->v.ClassDef.name, class_def->v.ClassDef.bases,
@ -1950,7 +1965,7 @@ _seq_number_of_starred_exprs(asdl_seq *seq)
{
int n = 0;
for (Py_ssize_t i = 0, l = asdl_seq_LEN(seq); i < l; i++) {
KeywordOrStarred *k = asdl_seq_GET(seq, i);
KeywordOrStarred *k = asdl_seq_GET_UNTYPED(seq, i);
if (!k->is_keyword) {
n++;
}
@ -1959,21 +1974,21 @@ _seq_number_of_starred_exprs(asdl_seq *seq)
}
/* Extract the starred expressions of an asdl_seq* of KeywordOrStarred*s */
asdl_seq *
asdl_expr_seq *
_PyPegen_seq_extract_starred_exprs(Parser *p, asdl_seq *kwargs)
{
int new_len = _seq_number_of_starred_exprs(kwargs);
if (new_len == 0) {
return NULL;
}
asdl_seq *new_seq = _Py_asdl_seq_new(new_len, p->arena);
asdl_expr_seq *new_seq = _Py_asdl_expr_seq_new(new_len, p->arena);
if (!new_seq) {
return NULL;
}
int idx = 0;
for (Py_ssize_t i = 0, len = asdl_seq_LEN(kwargs); i < len; i++) {
KeywordOrStarred *k = asdl_seq_GET(kwargs, i);
KeywordOrStarred *k = asdl_seq_GET_UNTYPED(kwargs, i);
if (!k->is_keyword) {
asdl_seq_SET(new_seq, idx++, k->element);
}
@ -1982,7 +1997,7 @@ _PyPegen_seq_extract_starred_exprs(Parser *p, asdl_seq *kwargs)
}
/* Return a new asdl_seq* with only the keywords in kwargs */
asdl_seq *
asdl_keyword_seq*
_PyPegen_seq_delete_starred_exprs(Parser *p, asdl_seq *kwargs)
{
Py_ssize_t len = asdl_seq_LEN(kwargs);
@ -1990,14 +2005,14 @@ _PyPegen_seq_delete_starred_exprs(Parser *p, asdl_seq *kwargs)
if (new_len == 0) {
return NULL;
}
asdl_seq *new_seq = _Py_asdl_seq_new(new_len, p->arena);
asdl_keyword_seq *new_seq = _Py_asdl_keyword_seq_new(new_len, p->arena);
if (!new_seq) {
return NULL;
}
int idx = 0;
for (Py_ssize_t i = 0; i < len; i++) {
KeywordOrStarred *k = asdl_seq_GET(kwargs, i);
KeywordOrStarred *k = asdl_seq_GET_UNTYPED(kwargs, i);
if (k->is_keyword) {
asdl_seq_SET(new_seq, idx++, k->element);
}
@ -2011,8 +2026,8 @@ _PyPegen_concatenate_strings(Parser *p, asdl_seq *strings)
Py_ssize_t len = asdl_seq_LEN(strings);
assert(len > 0);
Token *first = asdl_seq_GET(strings, 0);
Token *last = asdl_seq_GET(strings, len - 1);
Token *first = asdl_seq_GET_UNTYPED(strings, 0);
Token *last = asdl_seq_GET_UNTYPED(strings, len - 1);
int bytesmode = 0;
PyObject *bytes_str = NULL;
@ -2021,7 +2036,7 @@ _PyPegen_concatenate_strings(Parser *p, asdl_seq *strings)
_PyPegen_FstringParser_Init(&state);
for (Py_ssize_t i = 0; i < len; i++) {
Token *t = asdl_seq_GET(strings, i);
Token *t = asdl_seq_GET_UNTYPED(strings, i);
int this_bytesmode;
int this_rawmode;
@ -2095,12 +2110,12 @@ error:
}
mod_ty
_PyPegen_make_module(Parser *p, asdl_seq *a) {
asdl_seq *type_ignores = NULL;
_PyPegen_make_module(Parser *p, asdl_stmt_seq *a) {
asdl_type_ignore_seq *type_ignores = NULL;
Py_ssize_t num = p->type_ignore_comments.num_items;
if (num > 0) {
// Turn the raw (comment, lineno) pairs into TypeIgnore objects in the arena
type_ignores = _Py_asdl_seq_new(num, p->arena);
type_ignores = _Py_asdl_type_ignore_seq_new(num, p->arena);
if (type_ignores == NULL) {
return NULL;
}
@ -2219,7 +2234,7 @@ _PyPegen_nonparen_genexp_in_call(Parser *p, expr_ty args)
}
expr_ty _PyPegen_collect_call_seqs(Parser *p, asdl_seq *a, asdl_seq *b,
expr_ty _PyPegen_collect_call_seqs(Parser *p, asdl_expr_seq *a, asdl_seq *b,
int lineno, int col_offset, int end_lineno,
int end_col_offset, PyArena *arena) {
Py_ssize_t args_len = asdl_seq_LEN(a);
@ -2231,14 +2246,14 @@ expr_ty _PyPegen_collect_call_seqs(Parser *p, asdl_seq *a, asdl_seq *b,
}
asdl_seq *starreds = _PyPegen_seq_extract_starred_exprs(p, b);
asdl_seq *keywords = _PyPegen_seq_delete_starred_exprs(p, b);
asdl_expr_seq *starreds = _PyPegen_seq_extract_starred_exprs(p, b);
asdl_keyword_seq *keywords = _PyPegen_seq_delete_starred_exprs(p, b);
if (starreds) {
total_len += asdl_seq_LEN(starreds);
}
asdl_seq *args = _Py_asdl_seq_new(total_len, arena);
asdl_expr_seq *args = _Py_asdl_expr_seq_new(total_len, arena);
Py_ssize_t i = 0;
for (i = 0; i < args_len; i++) {
@ -2250,6 +2265,4 @@ expr_ty _PyPegen_collect_call_seqs(Parser *p, asdl_seq *a, asdl_seq *b,
return _Py_Call(_PyPegen_dummy_name(p), args, keywords, lineno,
col_offset, end_lineno, end_col_offset, arena);
}

View File

@ -91,7 +91,7 @@ typedef struct {
} NameDefaultPair;
typedef struct {
asdl_seq *plain_names;
asdl_arg_seq *plain_names;
asdl_seq *names_with_defaults; // asdl_seq* of NameDefaultsPair's
} SlashWithDefault;
@ -229,7 +229,7 @@ mod_ty _PyPegen_run_parser_from_file_pointer(FILE *, int, PyObject *, const char
void *_PyPegen_run_parser(Parser *);
mod_ty _PyPegen_run_parser_from_file(const char *, int, PyObject *, PyCompilerFlags *, PyArena *);
mod_ty _PyPegen_run_parser_from_string(const char *, int, PyObject *, PyCompilerFlags *, PyArena *);
void *_PyPegen_interactive_exit(Parser *);
asdl_stmt_seq *_PyPegen_interactive_exit(Parser *);
asdl_seq *_PyPegen_singleton_seq(Parser *, void *);
asdl_seq *_PyPegen_seq_insert_in_front(Parser *, void *, asdl_seq *);
asdl_seq *_PyPegen_seq_append_to_end(Parser *, asdl_seq *, void *);
@ -237,33 +237,33 @@ asdl_seq *_PyPegen_seq_flatten(Parser *, asdl_seq *);
expr_ty _PyPegen_join_names_with_dot(Parser *, expr_ty, expr_ty);
int _PyPegen_seq_count_dots(asdl_seq *);
alias_ty _PyPegen_alias_for_star(Parser *);
asdl_seq *_PyPegen_map_names_to_ids(Parser *, asdl_seq *);
asdl_identifier_seq *_PyPegen_map_names_to_ids(Parser *, asdl_expr_seq *);
CmpopExprPair *_PyPegen_cmpop_expr_pair(Parser *, cmpop_ty, expr_ty);
asdl_int_seq *_PyPegen_get_cmpops(Parser *p, asdl_seq *);
asdl_seq *_PyPegen_get_exprs(Parser *, asdl_seq *);
asdl_expr_seq *_PyPegen_get_exprs(Parser *, asdl_seq *);
expr_ty _PyPegen_set_expr_context(Parser *, expr_ty, expr_context_ty);
KeyValuePair *_PyPegen_key_value_pair(Parser *, expr_ty, expr_ty);
asdl_seq *_PyPegen_get_keys(Parser *, asdl_seq *);
asdl_seq *_PyPegen_get_values(Parser *, asdl_seq *);
asdl_expr_seq *_PyPegen_get_keys(Parser *, asdl_seq *);
asdl_expr_seq *_PyPegen_get_values(Parser *, asdl_seq *);
NameDefaultPair *_PyPegen_name_default_pair(Parser *, arg_ty, expr_ty, Token *);
SlashWithDefault *_PyPegen_slash_with_default(Parser *, asdl_seq *, asdl_seq *);
SlashWithDefault *_PyPegen_slash_with_default(Parser *, asdl_arg_seq *, asdl_seq *);
StarEtc *_PyPegen_star_etc(Parser *, arg_ty, asdl_seq *, arg_ty);
arguments_ty _PyPegen_make_arguments(Parser *, asdl_seq *, SlashWithDefault *,
asdl_seq *, asdl_seq *, StarEtc *);
arguments_ty _PyPegen_make_arguments(Parser *, asdl_arg_seq *, SlashWithDefault *,
asdl_arg_seq *, asdl_seq *, StarEtc *);
arguments_ty _PyPegen_empty_arguments(Parser *);
AugOperator *_PyPegen_augoperator(Parser*, operator_ty type);
stmt_ty _PyPegen_function_def_decorators(Parser *, asdl_seq *, stmt_ty);
stmt_ty _PyPegen_class_def_decorators(Parser *, asdl_seq *, stmt_ty);
stmt_ty _PyPegen_function_def_decorators(Parser *, asdl_expr_seq *, stmt_ty);
stmt_ty _PyPegen_class_def_decorators(Parser *, asdl_expr_seq *, stmt_ty);
KeywordOrStarred *_PyPegen_keyword_or_starred(Parser *, void *, int);
asdl_seq *_PyPegen_seq_extract_starred_exprs(Parser *, asdl_seq *);
asdl_seq *_PyPegen_seq_delete_starred_exprs(Parser *, asdl_seq *);
expr_ty _PyPegen_collect_call_seqs(Parser *, asdl_seq *, asdl_seq *,
asdl_expr_seq *_PyPegen_seq_extract_starred_exprs(Parser *, asdl_seq *);
asdl_keyword_seq *_PyPegen_seq_delete_starred_exprs(Parser *, asdl_seq *);
expr_ty _PyPegen_collect_call_seqs(Parser *, asdl_expr_seq *, asdl_seq *,
int lineno, int col_offset, int end_lineno,
int end_col_offset, PyArena *arena);
expr_ty _PyPegen_concatenate_strings(Parser *p, asdl_seq *);
asdl_seq *_PyPegen_join_sequences(Parser *, asdl_seq *, asdl_seq *);
int _PyPegen_check_barry_as_flufl(Parser *);
mod_ty _PyPegen_make_module(Parser *, asdl_seq *);
mod_ty _PyPegen_make_module(Parser *, asdl_stmt_seq *);
// Error reporting helpers
typedef enum {

View File

@ -970,15 +970,15 @@ ExprList_Dealloc(ExprList *l)
l->size = -1;
}
static asdl_seq *
static asdl_expr_seq *
ExprList_Finish(ExprList *l, PyArena *arena)
{
asdl_seq *seq;
asdl_expr_seq *seq;
ExprList_check_invariants(l);
/* Allocate the asdl_seq and copy the expressions in to it. */
seq = _Py_asdl_seq_new(l->size, arena);
seq = _Py_asdl_expr_seq_new(l->size, arena);
if (seq) {
Py_ssize_t i;
for (i = 0; i < l->size; i++) {
@ -1167,7 +1167,7 @@ expr_ty
_PyPegen_FstringParser_Finish(Parser *p, FstringParser *state, Token* first_token,
Token *last_token)
{
asdl_seq *seq;
asdl_expr_seq *seq;
FstringParser_check_invariants(state);

507
Python/Python-ast.c generated

File diff suppressed because it is too large Load Diff

View File

@ -1,64 +1,6 @@
#include "Python.h"
#include "asdl.h"
asdl_seq *
_Py_asdl_seq_new(Py_ssize_t size, PyArena *arena)
{
asdl_seq *seq = NULL;
size_t n;
/* check size is sane */
if (size < 0 ||
(size && (((size_t)size - 1) > (SIZE_MAX / sizeof(void *))))) {
PyErr_NoMemory();
return NULL;
}
n = (size ? (sizeof(void *) * (size - 1)) : 0);
/* check if size can be added safely */
if (n > SIZE_MAX - sizeof(asdl_seq)) {
PyErr_NoMemory();
return NULL;
}
n += sizeof(asdl_seq);
seq = (asdl_seq *)PyArena_Malloc(arena, n);
if (!seq) {
PyErr_NoMemory();
return NULL;
}
memset(seq, 0, n);
seq->size = size;
return seq;
}
asdl_int_seq *
_Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena)
{
asdl_int_seq *seq = NULL;
size_t n;
/* check size is sane */
if (size < 0 ||
(size && (((size_t)size - 1) > (SIZE_MAX / sizeof(void *))))) {
PyErr_NoMemory();
return NULL;
}
n = (size ? (sizeof(void *) * (size - 1)) : 0);
/* check if size can be added safely */
if (n > SIZE_MAX - sizeof(asdl_seq)) {
PyErr_NoMemory();
return NULL;
}
n += sizeof(asdl_seq);
seq = (asdl_int_seq *)PyArena_Malloc(arena, n);
if (!seq) {
PyErr_NoMemory();
return NULL;
}
memset(seq, 0, n);
seq->size = size;
return seq;
}
GENERATE_ASDL_SEQ_CONSTRUCTOR(generic, void*);
GENERATE_ASDL_SEQ_CONSTRUCTOR(identifier, PyObject*);
GENERATE_ASDL_SEQ_CONSTRUCTOR(int, int);

View File

@ -14,9 +14,9 @@
#define MAXLEVEL 200 /* Max parentheses level */
static int validate_stmts(asdl_seq *);
static int validate_exprs(asdl_seq *, expr_context_ty, int);
static int validate_nonempty_seq(asdl_seq *, const char *, const char *);
static int validate_stmts(asdl_stmt_seq *);
static int validate_exprs(asdl_expr_seq*, expr_context_ty, int);
static int _validate_nonempty_seq(asdl_seq *, const char *, const char *);
static int validate_stmt(stmt_ty);
static int validate_expr(expr_ty, expr_context_ty);
@ -40,7 +40,7 @@ validate_name(PyObject *name)
}
static int
validate_comprehension(asdl_seq *gens)
validate_comprehension(asdl_comprehension_seq *gens)
{
Py_ssize_t i;
if (!asdl_seq_LEN(gens)) {
@ -58,7 +58,7 @@ validate_comprehension(asdl_seq *gens)
}
static int
validate_keywords(asdl_seq *keywords)
validate_keywords(asdl_keyword_seq *keywords)
{
Py_ssize_t i;
for (i = 0; i < asdl_seq_LEN(keywords); i++)
@ -68,7 +68,7 @@ validate_keywords(asdl_seq *keywords)
}
static int
validate_args(asdl_seq *args)
validate_args(asdl_arg_seq *args)
{
Py_ssize_t i;
for (i = 0; i < asdl_seq_LEN(args); i++) {
@ -324,23 +324,24 @@ validate_expr(expr_ty exp, expr_context_ty ctx)
}
static int
validate_nonempty_seq(asdl_seq *seq, const char *what, const char *owner)
_validate_nonempty_seq(asdl_seq *seq, const char *what, const char *owner)
{
if (asdl_seq_LEN(seq))
return 1;
PyErr_Format(PyExc_ValueError, "empty %s on %s", what, owner);
return 0;
}
#define validate_nonempty_seq(seq, what, owner) _validate_nonempty_seq((asdl_seq*)seq, what, owner)
static int
validate_assignlist(asdl_seq *targets, expr_context_ty ctx)
validate_assignlist(asdl_expr_seq *targets, expr_context_ty ctx)
{
return validate_nonempty_seq(targets, "targets", ctx == Del ? "Delete" : "Assign") &&
validate_exprs(targets, ctx, 0);
}
static int
validate_body(asdl_seq *body, const char *owner)
validate_body(asdl_stmt_seq *body, const char *owner)
{
return validate_nonempty_seq(body, "body", owner) && validate_stmts(body);
}
@ -488,7 +489,7 @@ validate_stmt(stmt_ty stmt)
}
static int
validate_stmts(asdl_seq *seq)
validate_stmts(asdl_stmt_seq *seq)
{
Py_ssize_t i;
for (i = 0; i < asdl_seq_LEN(seq); i++) {
@ -507,7 +508,7 @@ validate_stmts(asdl_seq *seq)
}
static int
validate_exprs(asdl_seq *exprs, expr_context_ty ctx, int null_ok)
validate_exprs(asdl_expr_seq *exprs, expr_context_ty ctx, int null_ok)
{
Py_ssize_t i;
for (i = 0; i < asdl_seq_LEN(exprs); i++) {
@ -550,7 +551,7 @@ PyAST_Validate(mod_ty mod)
}
PyObject *
_PyAST_GetDocString(asdl_seq *body)
_PyAST_GetDocString(asdl_stmt_seq *body)
{
if (!asdl_seq_LEN(body)) {
return NULL;

View File

@ -271,7 +271,7 @@ fold_binop(expr_ty node, PyArena *arena, _PyASTOptimizeState *state)
}
static PyObject*
make_const_tuple(asdl_seq *elts)
make_const_tuple(asdl_expr_seq *elts)
{
for (int i = 0; i < asdl_seq_LEN(elts); i++) {
expr_ty e = (expr_ty)asdl_seq_GET(elts, i);
@ -337,7 +337,7 @@ fold_iter(expr_ty arg, PyArena *arena, _PyASTOptimizeState *state)
PyObject *newval;
if (arg->kind == List_kind) {
/* First change a list into tuple. */
asdl_seq *elts = arg->v.List.elts;
asdl_expr_seq *elts = arg->v.List.elts;
Py_ssize_t n = asdl_seq_LEN(elts);
for (Py_ssize_t i = 0; i < n; i++) {
expr_ty e = (expr_ty)asdl_seq_GET(elts, i);
@ -368,7 +368,7 @@ static int
fold_compare(expr_ty node, PyArena *arena, _PyASTOptimizeState *state)
{
asdl_int_seq *ops;
asdl_seq *args;
asdl_expr_seq *args;
Py_ssize_t i;
ops = node->v.Compare.ops;
@ -405,9 +405,9 @@ static int astfold_excepthandler(excepthandler_ty node_, PyArena *ctx_, _PyASTOp
#define CALL_SEQ(FUNC, TYPE, ARG) { \
int i; \
asdl_seq *seq = (ARG); /* avoid variable capture */ \
asdl_ ## TYPE ## _seq *seq = (ARG); /* avoid variable capture */ \
for (i = 0; i < asdl_seq_LEN(seq); i++) { \
TYPE elt = (TYPE)asdl_seq_GET(seq, i); \
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
if (elt != NULL && !FUNC(elt, ctx_, state)) \
return 0; \
} \
@ -424,13 +424,13 @@ static int astfold_excepthandler(excepthandler_ty node_, PyArena *ctx_, _PyASTOp
}
static int
astfold_body(asdl_seq *stmts, PyArena *ctx_, _PyASTOptimizeState *state)
astfold_body(asdl_stmt_seq *stmts, PyArena *ctx_, _PyASTOptimizeState *state)
{
int docstring = _PyAST_GetDocString(stmts) != NULL;
CALL_SEQ(astfold_stmt, stmt_ty, stmts);
CALL_SEQ(astfold_stmt, stmt, stmts);
if (!docstring && _PyAST_GetDocString(stmts) != NULL) {
stmt_ty st = (stmt_ty)asdl_seq_GET(stmts, 0);
asdl_seq *values = _Py_asdl_seq_new(1, ctx_);
asdl_expr_seq *values = _Py_asdl_expr_seq_new(1, ctx_);
if (!values) {
return 0;
}
@ -453,7 +453,7 @@ astfold_mod(mod_ty node_, PyArena *ctx_, _PyASTOptimizeState *state)
CALL(astfold_body, asdl_seq, node_->v.Module.body);
break;
case Interactive_kind:
CALL_SEQ(astfold_stmt, stmt_ty, node_->v.Interactive.body);
CALL_SEQ(astfold_stmt, stmt, node_->v.Interactive.body);
break;
case Expression_kind:
CALL(astfold_expr, expr_ty, node_->v.Expression.body);
@ -469,7 +469,7 @@ astfold_expr(expr_ty node_, PyArena *ctx_, _PyASTOptimizeState *state)
{
switch (node_->kind) {
case BoolOp_kind:
CALL_SEQ(astfold_expr, expr_ty, node_->v.BoolOp.values);
CALL_SEQ(astfold_expr, expr, node_->v.BoolOp.values);
break;
case BinOp_kind:
CALL(astfold_expr, expr_ty, node_->v.BinOp.left);
@ -490,28 +490,28 @@ astfold_expr(expr_ty node_, PyArena *ctx_, _PyASTOptimizeState *state)
CALL(astfold_expr, expr_ty, node_->v.IfExp.orelse);
break;
case Dict_kind:
CALL_SEQ(astfold_expr, expr_ty, node_->v.Dict.keys);
CALL_SEQ(astfold_expr, expr_ty, node_->v.Dict.values);
CALL_SEQ(astfold_expr, expr, node_->v.Dict.keys);
CALL_SEQ(astfold_expr, expr, node_->v.Dict.values);
break;
case Set_kind:
CALL_SEQ(astfold_expr, expr_ty, node_->v.Set.elts);
CALL_SEQ(astfold_expr, expr, node_->v.Set.elts);
break;
case ListComp_kind:
CALL(astfold_expr, expr_ty, node_->v.ListComp.elt);
CALL_SEQ(astfold_comprehension, comprehension_ty, node_->v.ListComp.generators);
CALL_SEQ(astfold_comprehension, comprehension, node_->v.ListComp.generators);
break;
case SetComp_kind:
CALL(astfold_expr, expr_ty, node_->v.SetComp.elt);
CALL_SEQ(astfold_comprehension, comprehension_ty, node_->v.SetComp.generators);
CALL_SEQ(astfold_comprehension, comprehension, node_->v.SetComp.generators);
break;
case DictComp_kind:
CALL(astfold_expr, expr_ty, node_->v.DictComp.key);
CALL(astfold_expr, expr_ty, node_->v.DictComp.value);
CALL_SEQ(astfold_comprehension, comprehension_ty, node_->v.DictComp.generators);
CALL_SEQ(astfold_comprehension, comprehension, node_->v.DictComp.generators);
break;
case GeneratorExp_kind:
CALL(astfold_expr, expr_ty, node_->v.GeneratorExp.elt);
CALL_SEQ(astfold_comprehension, comprehension_ty, node_->v.GeneratorExp.generators);
CALL_SEQ(astfold_comprehension, comprehension, node_->v.GeneratorExp.generators);
break;
case Await_kind:
CALL(astfold_expr, expr_ty, node_->v.Await.value);
@ -524,20 +524,20 @@ astfold_expr(expr_ty node_, PyArena *ctx_, _PyASTOptimizeState *state)
break;
case Compare_kind:
CALL(astfold_expr, expr_ty, node_->v.Compare.left);
CALL_SEQ(astfold_expr, expr_ty, node_->v.Compare.comparators);
CALL_SEQ(astfold_expr, expr, node_->v.Compare.comparators);
CALL(fold_compare, expr_ty, node_);
break;
case Call_kind:
CALL(astfold_expr, expr_ty, node_->v.Call.func);
CALL_SEQ(astfold_expr, expr_ty, node_->v.Call.args);
CALL_SEQ(astfold_keyword, keyword_ty, node_->v.Call.keywords);
CALL_SEQ(astfold_expr, expr, node_->v.Call.args);
CALL_SEQ(astfold_keyword, keyword, node_->v.Call.keywords);
break;
case FormattedValue_kind:
CALL(astfold_expr, expr_ty, node_->v.FormattedValue.value);
CALL_OPT(astfold_expr, expr_ty, node_->v.FormattedValue.format_spec);
break;
case JoinedStr_kind:
CALL_SEQ(astfold_expr, expr_ty, node_->v.JoinedStr.values);
CALL_SEQ(astfold_expr, expr, node_->v.JoinedStr.values);
break;
case Attribute_kind:
CALL(astfold_expr, expr_ty, node_->v.Attribute.value);
@ -556,10 +556,10 @@ astfold_expr(expr_ty node_, PyArena *ctx_, _PyASTOptimizeState *state)
CALL_OPT(astfold_expr, expr_ty, node_->v.Slice.step);
break;
case List_kind:
CALL_SEQ(astfold_expr, expr_ty, node_->v.List.elts);
CALL_SEQ(astfold_expr, expr, node_->v.List.elts);
break;
case Tuple_kind:
CALL_SEQ(astfold_expr, expr_ty, node_->v.Tuple.elts);
CALL_SEQ(astfold_expr, expr, node_->v.Tuple.elts);
CALL(fold_tuple, expr_ty, node_);
break;
case Name_kind:
@ -586,7 +586,7 @@ astfold_comprehension(comprehension_ty node_, PyArena *ctx_, _PyASTOptimizeState
{
CALL(astfold_expr, expr_ty, node_->target);
CALL(astfold_expr, expr_ty, node_->iter);
CALL_SEQ(astfold_expr, expr_ty, node_->ifs);
CALL_SEQ(astfold_expr, expr, node_->ifs);
CALL(fold_iter, expr_ty, node_->iter);
return 1;
@ -595,13 +595,13 @@ astfold_comprehension(comprehension_ty node_, PyArena *ctx_, _PyASTOptimizeState
static int
astfold_arguments(arguments_ty node_, PyArena *ctx_, _PyASTOptimizeState *state)
{
CALL_SEQ(astfold_arg, arg_ty, node_->posonlyargs);
CALL_SEQ(astfold_arg, arg_ty, node_->args);
CALL_SEQ(astfold_arg, arg, node_->posonlyargs);
CALL_SEQ(astfold_arg, arg, node_->args);
CALL_OPT(astfold_arg, arg_ty, node_->vararg);
CALL_SEQ(astfold_arg, arg_ty, node_->kwonlyargs);
CALL_SEQ(astfold_expr, expr_ty, node_->kw_defaults);
CALL_SEQ(astfold_arg, arg, node_->kwonlyargs);
CALL_SEQ(astfold_expr, expr, node_->kw_defaults);
CALL_OPT(astfold_arg, arg_ty, node_->kwarg);
CALL_SEQ(astfold_expr, expr_ty, node_->defaults);
CALL_SEQ(astfold_expr, expr, node_->defaults);
return 1;
}
@ -621,7 +621,7 @@ astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTOptimizeState *state)
case FunctionDef_kind:
CALL(astfold_arguments, arguments_ty, node_->v.FunctionDef.args);
CALL(astfold_body, asdl_seq, node_->v.FunctionDef.body);
CALL_SEQ(astfold_expr, expr_ty, node_->v.FunctionDef.decorator_list);
CALL_SEQ(astfold_expr, expr, node_->v.FunctionDef.decorator_list);
if (!(state->ff_features & CO_FUTURE_ANNOTATIONS)) {
CALL_OPT(astfold_expr, expr_ty, node_->v.FunctionDef.returns);
}
@ -629,25 +629,25 @@ astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTOptimizeState *state)
case AsyncFunctionDef_kind:
CALL(astfold_arguments, arguments_ty, node_->v.AsyncFunctionDef.args);
CALL(astfold_body, asdl_seq, node_->v.AsyncFunctionDef.body);
CALL_SEQ(astfold_expr, expr_ty, node_->v.AsyncFunctionDef.decorator_list);
CALL_SEQ(astfold_expr, expr, node_->v.AsyncFunctionDef.decorator_list);
if (!(state->ff_features & CO_FUTURE_ANNOTATIONS)) {
CALL_OPT(astfold_expr, expr_ty, node_->v.AsyncFunctionDef.returns);
}
break;
case ClassDef_kind:
CALL_SEQ(astfold_expr, expr_ty, node_->v.ClassDef.bases);
CALL_SEQ(astfold_keyword, keyword_ty, node_->v.ClassDef.keywords);
CALL_SEQ(astfold_expr, expr, node_->v.ClassDef.bases);
CALL_SEQ(astfold_keyword, keyword, node_->v.ClassDef.keywords);
CALL(astfold_body, asdl_seq, node_->v.ClassDef.body);
CALL_SEQ(astfold_expr, expr_ty, node_->v.ClassDef.decorator_list);
CALL_SEQ(astfold_expr, expr, node_->v.ClassDef.decorator_list);
break;
case Return_kind:
CALL_OPT(astfold_expr, expr_ty, node_->v.Return.value);
break;
case Delete_kind:
CALL_SEQ(astfold_expr, expr_ty, node_->v.Delete.targets);
CALL_SEQ(astfold_expr, expr, node_->v.Delete.targets);
break;
case Assign_kind:
CALL_SEQ(astfold_expr, expr_ty, node_->v.Assign.targets);
CALL_SEQ(astfold_expr, expr, node_->v.Assign.targets);
CALL(astfold_expr, expr_ty, node_->v.Assign.value);
break;
case AugAssign_kind:
@ -664,44 +664,44 @@ astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTOptimizeState *state)
case For_kind:
CALL(astfold_expr, expr_ty, node_->v.For.target);
CALL(astfold_expr, expr_ty, node_->v.For.iter);
CALL_SEQ(astfold_stmt, stmt_ty, node_->v.For.body);
CALL_SEQ(astfold_stmt, stmt_ty, node_->v.For.orelse);
CALL_SEQ(astfold_stmt, stmt, node_->v.For.body);
CALL_SEQ(astfold_stmt, stmt, node_->v.For.orelse);
CALL(fold_iter, expr_ty, node_->v.For.iter);
break;
case AsyncFor_kind:
CALL(astfold_expr, expr_ty, node_->v.AsyncFor.target);
CALL(astfold_expr, expr_ty, node_->v.AsyncFor.iter);
CALL_SEQ(astfold_stmt, stmt_ty, node_->v.AsyncFor.body);
CALL_SEQ(astfold_stmt, stmt_ty, node_->v.AsyncFor.orelse);
CALL_SEQ(astfold_stmt, stmt, node_->v.AsyncFor.body);
CALL_SEQ(astfold_stmt, stmt, node_->v.AsyncFor.orelse);
break;
case While_kind:
CALL(astfold_expr, expr_ty, node_->v.While.test);
CALL_SEQ(astfold_stmt, stmt_ty, node_->v.While.body);
CALL_SEQ(astfold_stmt, stmt_ty, node_->v.While.orelse);
CALL_SEQ(astfold_stmt, stmt, node_->v.While.body);
CALL_SEQ(astfold_stmt, stmt, node_->v.While.orelse);
break;
case If_kind:
CALL(astfold_expr, expr_ty, node_->v.If.test);
CALL_SEQ(astfold_stmt, stmt_ty, node_->v.If.body);
CALL_SEQ(astfold_stmt, stmt_ty, node_->v.If.orelse);
CALL_SEQ(astfold_stmt, stmt, node_->v.If.body);
CALL_SEQ(astfold_stmt, stmt, node_->v.If.orelse);
break;
case With_kind:
CALL_SEQ(astfold_withitem, withitem_ty, node_->v.With.items);
CALL_SEQ(astfold_stmt, stmt_ty, node_->v.With.body);
CALL_SEQ(astfold_withitem, withitem, node_->v.With.items);
CALL_SEQ(astfold_stmt, stmt, node_->v.With.body);
break;
case AsyncWith_kind:
CALL_SEQ(astfold_withitem, withitem_ty, node_->v.AsyncWith.items);
CALL_SEQ(astfold_stmt, stmt_ty, node_->v.AsyncWith.body);
CALL_SEQ(astfold_withitem, withitem, node_->v.AsyncWith.items);
CALL_SEQ(astfold_stmt, stmt, node_->v.AsyncWith.body);
break;
case Raise_kind:
CALL_OPT(astfold_expr, expr_ty, node_->v.Raise.exc);
CALL_OPT(astfold_expr, expr_ty, node_->v.Raise.cause);
break;
case Try_kind:
CALL_SEQ(astfold_stmt, stmt_ty, node_->v.Try.body);
CALL_SEQ(astfold_excepthandler, excepthandler_ty, node_->v.Try.handlers);
CALL_SEQ(astfold_stmt, stmt_ty, node_->v.Try.orelse);
CALL_SEQ(astfold_stmt, stmt_ty, node_->v.Try.finalbody);
CALL_SEQ(astfold_stmt, stmt, node_->v.Try.body);
CALL_SEQ(astfold_excepthandler, excepthandler, node_->v.Try.handlers);
CALL_SEQ(astfold_stmt, stmt, node_->v.Try.orelse);
CALL_SEQ(astfold_stmt, stmt, node_->v.Try.finalbody);
break;
case Assert_kind:
CALL(astfold_expr, expr_ty, node_->v.Assert.test);
@ -722,7 +722,7 @@ astfold_excepthandler(excepthandler_ty node_, PyArena *ctx_, _PyASTOptimizeState
switch (node_->kind) {
case ExceptHandler_kind:
CALL_OPT(astfold_expr, expr_ty, node_->v.ExceptHandler.type);
CALL_SEQ(astfold_stmt, stmt_ty, node_->v.ExceptHandler.body);
CALL_SEQ(astfold_stmt, stmt, node_->v.ExceptHandler.body);
break;
default:
break;

View File

@ -117,7 +117,7 @@ static int
append_ast_boolop(_PyUnicodeWriter *writer, expr_ty e, int level)
{
Py_ssize_t i, value_count;
asdl_seq *values;
asdl_expr_seq *values;
const char *op = (e->v.BoolOp.op == And) ? " and " : " or ";
int pr = (e->v.BoolOp.op == And) ? PR_AND : PR_OR;
@ -398,7 +398,7 @@ append_ast_comprehension(_PyUnicodeWriter *writer, comprehension_ty gen)
}
static int
append_ast_comprehensions(_PyUnicodeWriter *writer, asdl_seq *comprehensions)
append_ast_comprehensions(_PyUnicodeWriter *writer, asdl_comprehension_seq *comprehensions)
{
Py_ssize_t i, gen_count;
gen_count = asdl_seq_LEN(comprehensions);
@ -453,7 +453,7 @@ append_ast_compare(_PyUnicodeWriter *writer, expr_ty e, int level)
{
const char *op;
Py_ssize_t i, comparator_count;
asdl_seq *comparators;
asdl_expr_seq *comparators;
asdl_int_seq *ops;
APPEND_STR_IF(level > PR_CMP, "(");
@ -612,7 +612,7 @@ append_fstring_element(_PyUnicodeWriter *writer, expr_ty e, bool is_format_spec)
/* Build body separately to enable wrapping the entire stream of Strs,
Constants and FormattedValues in one opening and one closing quote. */
static PyObject *
build_fstring_body(asdl_seq *values, bool is_format_spec)
build_fstring_body(asdl_expr_seq *values, bool is_format_spec)
{
Py_ssize_t i, value_count;
_PyUnicodeWriter body_writer;

View File

@ -222,27 +222,27 @@ static int compiler_subscript(struct compiler *, expr_ty);
static int compiler_slice(struct compiler *, expr_ty);
static int inplace_binop(operator_ty);
static int are_all_items_const(asdl_seq *, Py_ssize_t, Py_ssize_t);
static int are_all_items_const(asdl_expr_seq *, Py_ssize_t, Py_ssize_t);
static int expr_constant(expr_ty);
static int compiler_with(struct compiler *, stmt_ty, int);
static int compiler_async_with(struct compiler *, stmt_ty, int);
static int compiler_async_for(struct compiler *, stmt_ty);
static int compiler_call_helper(struct compiler *c, int n,
asdl_seq *args,
asdl_seq *keywords);
asdl_expr_seq *args,
asdl_keyword_seq *keywords);
static int compiler_try_except(struct compiler *, stmt_ty);
static int compiler_set_qualname(struct compiler *);
static int compiler_sync_comprehension_generator(
struct compiler *c,
asdl_seq *generators, int gen_index,
asdl_comprehension_seq *generators, int gen_index,
int depth,
expr_ty elt, expr_ty val, int type);
static int compiler_async_comprehension_generator(
struct compiler *c,
asdl_seq *generators, int gen_index,
asdl_comprehension_seq *generators, int gen_index,
int depth,
expr_ty elt, expr_ty val, int type);
@ -1525,7 +1525,7 @@ compiler_addop_j(struct compiler *c, int opcode, basicblock *b)
#define VISIT_SEQ(C, TYPE, SEQ) { \
int _i; \
asdl_seq *seq = (SEQ); /* avoid variable capture */ \
asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
for (_i = 0; _i < asdl_seq_LEN(seq); _i++) { \
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, _i); \
if (!compiler_visit_ ## TYPE((C), elt)) \
@ -1535,7 +1535,7 @@ compiler_addop_j(struct compiler *c, int opcode, basicblock *b)
#define VISIT_SEQ_IN_SCOPE(C, TYPE, SEQ) { \
int _i; \
asdl_seq *seq = (SEQ); /* avoid variable capture */ \
asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
for (_i = 0; _i < asdl_seq_LEN(seq); _i++) { \
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, _i); \
if (!compiler_visit_ ## TYPE((C), elt)) { \
@ -1559,7 +1559,7 @@ compiler_addop_j(struct compiler *c, int opcode, basicblock *b)
/* Search if variable annotations are present statically in a block. */
static int
find_ann(asdl_seq *stmts)
find_ann(asdl_stmt_seq *stmts)
{
int i, j, res = 0;
stmt_ty st;
@ -1778,7 +1778,7 @@ compiler_unwind_fblock_stack(struct compiler *c, int preserve_tos, struct fblock
and for annotations. */
static int
compiler_body(struct compiler *c, asdl_seq *stmts)
compiler_body(struct compiler *c, asdl_stmt_seq *stmts)
{
int i = 0;
stmt_ty st;
@ -1841,8 +1841,7 @@ compiler_mod(struct compiler *c, mod_ty mod)
ADDOP(c, SETUP_ANNOTATIONS);
}
c->c_interactive = 1;
VISIT_SEQ_IN_SCOPE(c, stmt,
mod->v.Interactive.body);
VISIT_SEQ_IN_SCOPE(c, stmt, mod->v.Interactive.body);
break;
case Expression_kind:
VISIT_IN_SCOPE(c, expr, mod->v.Expression.body);
@ -1945,7 +1944,7 @@ compiler_make_closure(struct compiler *c, PyCodeObject *co, Py_ssize_t flags, Py
}
static int
compiler_decorators(struct compiler *c, asdl_seq* decos)
compiler_decorators(struct compiler *c, asdl_expr_seq* decos)
{
int i;
@ -1959,8 +1958,8 @@ compiler_decorators(struct compiler *c, asdl_seq* decos)
}
static int
compiler_visit_kwonlydefaults(struct compiler *c, asdl_seq *kwonlyargs,
asdl_seq *kw_defaults)
compiler_visit_kwonlydefaults(struct compiler *c, asdl_arg_seq *kwonlyargs,
asdl_expr_seq *kw_defaults)
{
/* Push a dict of keyword-only default values.
@ -2047,7 +2046,7 @@ compiler_visit_argannotation(struct compiler *c, identifier id,
}
static int
compiler_visit_argannotations(struct compiler *c, asdl_seq* args,
compiler_visit_argannotations(struct compiler *c, asdl_arg_seq* args,
PyObject *names)
{
int i;
@ -2173,7 +2172,7 @@ compiler_check_debug_one_arg(struct compiler *c, arg_ty arg)
}
static int
compiler_check_debug_args_seq(struct compiler *c, asdl_seq *args)
compiler_check_debug_args_seq(struct compiler *c, asdl_arg_seq *args)
{
if (args != NULL) {
for (Py_ssize_t i = 0, n = asdl_seq_LEN(args); i < n; i++) {
@ -2208,8 +2207,8 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async)
arguments_ty args;
expr_ty returns;
identifier name;
asdl_seq* decos;
asdl_seq *body;
asdl_expr_seq* decos;
asdl_stmt_seq *body;
Py_ssize_t i, funcflags;
int annotations;
int scope_type;
@ -2306,7 +2305,7 @@ compiler_class(struct compiler *c, stmt_ty s)
PyCodeObject *co;
PyObject *str;
int i, firstlineno;
asdl_seq* decos = s->v.ClassDef.decorator_list;
asdl_expr_seq *decos = s->v.ClassDef.decorator_list;
if (!compiler_decorators(c, decos))
return 0;
@ -2418,9 +2417,7 @@ compiler_class(struct compiler *c, stmt_ty s)
ADDOP_LOAD_CONST(c, s->v.ClassDef.name);
/* 5. generate the rest of the code for the call */
if (!compiler_call_helper(c, 2,
s->v.ClassDef.bases,
s->v.ClassDef.keywords))
if (!compiler_call_helper(c, 2, s->v.ClassDef.bases, s->v.ClassDef.keywords))
return 0;
/* 6. apply decorators */
@ -2528,7 +2525,7 @@ compiler_jump_if(struct compiler *c, expr_ty e, basicblock *next, int cond)
/* fallback to general implementation */
break;
case BoolOp_kind: {
asdl_seq *s = e->v.BoolOp.values;
asdl_expr_seq *s = e->v.BoolOp.values;
Py_ssize_t i, n = asdl_seq_LEN(s) - 1;
assert(n >= 0);
int cond2 = e->v.BoolOp.op == Or;
@ -3645,7 +3642,7 @@ compiler_boolop(struct compiler *c, expr_ty e)
basicblock *end;
int jumpi;
Py_ssize_t i, n;
asdl_seq *s;
asdl_expr_seq *s;
assert(e->kind == BoolOp_kind);
if (e->v.BoolOp.op == And)
@ -3673,7 +3670,7 @@ compiler_boolop(struct compiler *c, expr_ty e)
}
static int
starunpack_helper(struct compiler *c, asdl_seq *elts, int pushed,
starunpack_helper(struct compiler *c, asdl_expr_seq *elts, int pushed,
int build, int add, int extend, int tuple)
{
Py_ssize_t n = asdl_seq_LEN(elts);
@ -3750,7 +3747,7 @@ starunpack_helper(struct compiler *c, asdl_seq *elts, int pushed,
}
static int
assignment_helper(struct compiler *c, asdl_seq *elts)
assignment_helper(struct compiler *c, asdl_expr_seq *elts)
{
Py_ssize_t n = asdl_seq_LEN(elts);
Py_ssize_t i;
@ -3784,7 +3781,7 @@ assignment_helper(struct compiler *c, asdl_seq *elts)
static int
compiler_list(struct compiler *c, expr_ty e)
{
asdl_seq *elts = e->v.List.elts;
asdl_expr_seq *elts = e->v.List.elts;
if (e->v.List.ctx == Store) {
return assignment_helper(c, elts);
}
@ -3800,7 +3797,7 @@ compiler_list(struct compiler *c, expr_ty e)
static int
compiler_tuple(struct compiler *c, expr_ty e)
{
asdl_seq *elts = e->v.Tuple.elts;
asdl_expr_seq *elts = e->v.Tuple.elts;
if (e->v.Tuple.ctx == Store) {
return assignment_helper(c, elts);
}
@ -3821,7 +3818,7 @@ compiler_set(struct compiler *c, expr_ty e)
}
static int
are_all_items_const(asdl_seq *seq, Py_ssize_t begin, Py_ssize_t end)
are_all_items_const(asdl_expr_seq *seq, Py_ssize_t begin, Py_ssize_t end)
{
Py_ssize_t i;
for (i = begin; i < end; i++) {
@ -4084,7 +4081,7 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e)
{
Py_ssize_t argsl, i;
expr_ty meth = e->v.Call.func;
asdl_seq *args = e->v.Call.args;
asdl_expr_seq *args = e->v.Call.args;
/* Check that the call node is an attribute access, and that
the call doesn't have keyword parameters. */
@ -4110,7 +4107,7 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e)
}
static int
validate_keywords(struct compiler *c, asdl_seq *keywords)
validate_keywords(struct compiler *c, asdl_keyword_seq *keywords)
{
Py_ssize_t nkeywords = asdl_seq_LEN(keywords);
for (Py_ssize_t i = 0; i < nkeywords; i++) {
@ -4210,7 +4207,7 @@ compiler_formatted_value(struct compiler *c, expr_ty e)
}
static int
compiler_subkwargs(struct compiler *c, asdl_seq *keywords, Py_ssize_t begin, Py_ssize_t end)
compiler_subkwargs(struct compiler *c, asdl_keyword_seq *keywords, Py_ssize_t begin, Py_ssize_t end)
{
Py_ssize_t i, n = end - begin;
keyword_ty kw;
@ -4249,8 +4246,8 @@ compiler_subkwargs(struct compiler *c, asdl_seq *keywords, Py_ssize_t begin, Py_
static int
compiler_call_helper(struct compiler *c,
int n, /* Args already pushed */
asdl_seq *args,
asdl_seq *keywords)
asdl_expr_seq *args,
asdl_keyword_seq *keywords)
{
Py_ssize_t i, nseen, nelts, nkwelts;
@ -4375,7 +4372,7 @@ ex_call:
static int
compiler_comprehension_generator(struct compiler *c,
asdl_seq *generators, int gen_index,
asdl_comprehension_seq *generators, int gen_index,
int depth,
expr_ty elt, expr_ty val, int type)
{
@ -4392,7 +4389,7 @@ compiler_comprehension_generator(struct compiler *c,
static int
compiler_sync_comprehension_generator(struct compiler *c,
asdl_seq *generators, int gen_index,
asdl_comprehension_seq *generators, int gen_index,
int depth,
expr_ty elt, expr_ty val, int type)
{
@ -4424,7 +4421,7 @@ compiler_sync_comprehension_generator(struct compiler *c,
/* Fast path for the temporary variable assignment idiom:
for y in [f(x)]
*/
asdl_seq *elts;
asdl_expr_seq *elts;
switch (gen->iter->kind) {
case List_kind:
elts = gen->iter->v.List.elts;
@ -4511,7 +4508,7 @@ compiler_sync_comprehension_generator(struct compiler *c,
static int
compiler_async_comprehension_generator(struct compiler *c,
asdl_seq *generators, int gen_index,
asdl_comprehension_seq *generators, int gen_index,
int depth,
expr_ty elt, expr_ty val, int type)
{
@ -4602,7 +4599,7 @@ compiler_async_comprehension_generator(struct compiler *c,
static int
compiler_comprehension(struct compiler *c, expr_ty e, int type,
identifier name, asdl_seq *generators, expr_ty elt,
identifier name, asdl_comprehension_seq *generators, expr_ty elt,
expr_ty val)
{
PyCodeObject *co = NULL;
@ -5226,7 +5223,7 @@ check_ann_subscr(struct compiler *c, expr_ty e)
return 1;
case Tuple_kind: {
/* extended slice */
asdl_seq *elts = e->v.Tuple.elts;
asdl_expr_seq *elts = e->v.Tuple.elts;
Py_ssize_t i, n = asdl_seq_LEN(elts);
for (i = 0; i < n; i++) {
if (!check_ann_subscr(c, asdl_seq_GET(elts, i))) {

View File

@ -13,11 +13,10 @@ static int
future_check_features(PyFutureFeatures *ff, stmt_ty s, PyObject *filename)
{
int i;
asdl_seq *names;
assert(s->kind == ImportFrom_kind);
names = s->v.ImportFrom.names;
asdl_alias_seq *names = s->v.ImportFrom.names;
for (i = 0; i < asdl_seq_LEN(names); i++) {
alias_ty name = (alias_ty)asdl_seq_GET(names, i);
const char *feature = PyUnicode_AsUTF8(name->name);

View File

@ -202,8 +202,8 @@ static int symtable_visit_excepthandler(struct symtable *st, excepthandler_ty);
static int symtable_visit_alias(struct symtable *st, alias_ty);
static int symtable_visit_comprehension(struct symtable *st, comprehension_ty);
static int symtable_visit_keyword(struct symtable *st, keyword_ty);
static int symtable_visit_params(struct symtable *st, asdl_seq *args);
static int symtable_visit_argannotations(struct symtable *st, asdl_seq *args);
static int symtable_visit_params(struct symtable *st, asdl_arg_seq *args);
static int symtable_visit_argannotations(struct symtable *st, asdl_arg_seq *args);
static int symtable_implicit_arg(struct symtable *st, int pos);
static int symtable_visit_annotations(struct symtable *st, arguments_ty, expr_ty);
static int symtable_visit_withitem(struct symtable *st, withitem_ty item);
@ -261,7 +261,7 @@ struct symtable *
PySymtable_BuildObject(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
{
struct symtable *st = symtable_new();
asdl_seq *seq;
asdl_stmt_seq *seq;
int i;
PyThreadState *tstate;
int recursion_limit = Py_GetRecursionLimit();
@ -1116,7 +1116,7 @@ symtable_add_def(struct symtable *st, PyObject *name, int flag) {
#define VISIT_SEQ(ST, TYPE, SEQ) { \
int i; \
asdl_seq *seq = (SEQ); /* avoid variable capture */ \
asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
for (i = 0; i < asdl_seq_LEN(seq); i++) { \
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
if (!symtable_visit_ ## TYPE((ST), elt)) \
@ -1126,7 +1126,7 @@ symtable_add_def(struct symtable *st, PyObject *name, int flag) {
#define VISIT_SEQ_TAIL(ST, TYPE, SEQ, START) { \
int i; \
asdl_seq *seq = (SEQ); /* avoid variable capture */ \
asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
for (i = (START); i < asdl_seq_LEN(seq); i++) { \
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
if (!symtable_visit_ ## TYPE((ST), elt)) \
@ -1136,7 +1136,7 @@ symtable_add_def(struct symtable *st, PyObject *name, int flag) {
#define VISIT_SEQ_WITH_NULL(ST, TYPE, SEQ) { \
int i = 0; \
asdl_seq *seq = (SEQ); /* avoid variable capture */ \
asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
for (i = 0; i < asdl_seq_LEN(seq); i++) { \
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
if (!elt) continue; /* can be NULL */ \
@ -1318,7 +1318,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
break;
case Global_kind: {
int i;
asdl_seq *seq = s->v.Global.names;
asdl_identifier_seq *seq = s->v.Global.names;
for (i = 0; i < asdl_seq_LEN(seq); i++) {
identifier name = (identifier)asdl_seq_GET(seq, i);
long cur = symtable_lookup(st, name);
@ -1351,7 +1351,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
}
case Nonlocal_kind: {
int i;
asdl_seq *seq = s->v.Nonlocal.names;
asdl_identifier_seq *seq = s->v.Nonlocal.names;
for (i = 0; i < asdl_seq_LEN(seq); i++) {
identifier name = (identifier)asdl_seq_GET(seq, i);
long cur = symtable_lookup(st, name);
@ -1683,7 +1683,7 @@ symtable_implicit_arg(struct symtable *st, int pos)
}
static int
symtable_visit_params(struct symtable *st, asdl_seq *args)
symtable_visit_params(struct symtable *st, asdl_arg_seq *args)
{
int i;
@ -1700,7 +1700,7 @@ symtable_visit_params(struct symtable *st, asdl_seq *args)
}
static int
symtable_visit_argannotations(struct symtable *st, asdl_seq *args)
symtable_visit_argannotations(struct symtable *st, asdl_arg_seq *args)
{
int i;
@ -1850,7 +1850,7 @@ symtable_visit_keyword(struct symtable *st, keyword_ty k)
static int
symtable_handle_comprehension(struct symtable *st, expr_ty e,
identifier scope_name, asdl_seq *generators,
identifier scope_name, asdl_comprehension_seq *generators,
expr_ty elt, expr_ty value)
{
int is_generator = (e->kind == GeneratorExp_kind);

View File

@ -74,6 +74,7 @@ class FunctionCall:
function: str
arguments: List[Any] = field(default_factory=list)
assigned_variable: Optional[str] = None
assigned_variable_type: Optional[str] = None
return_type: Optional[str] = None
nodetype: Optional[NodeTypes] = None
force_true: bool = False
@ -87,6 +88,9 @@ class FunctionCall:
if self.force_true:
parts.append(", 1")
if self.assigned_variable:
if self.assigned_variable_type:
parts = ["(", self.assigned_variable, " = ", '(', self.assigned_variable_type, ')', *parts, ")"]
else:
parts = ["(", self.assigned_variable, " = ", *parts, ")"]
if self.comment:
parts.append(f" // {self.comment}")
@ -210,6 +214,8 @@ class CCallMakerVisitor(GrammarVisitor):
call = self.generate_call(node.item)
if node.name:
call.assigned_variable = node.name
if node.type:
call.assigned_variable_type = node.type
return call
def lookahead_call_helper(self, node: Lookahead, positive: int) -> FunctionCall:
@ -568,9 +574,9 @@ class CParserGenerator(ParserGenerator, GrammarVisitor):
self.print("PyMem_Free(_children);")
self.add_return("NULL")
self.print("}")
self.print("asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena);")
self.print("asdl_seq *_seq = (asdl_seq*)_Py_asdl_generic_seq_new(_n, p->arena);")
self.out_of_memory_return(f"!_seq", cleanup_code="PyMem_Free(_children);")
self.print("for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]);")
self.print("for (int i = 0; i < _n; i++) asdl_seq_SET_UNTYPED(_seq, i, _children[i]);")
self.print("PyMem_Free(_children);")
if node.name:
self.print(f"_PyPegen_insert_memo(p, _start_mark, {node.name}_type, _seq);")
@ -782,4 +788,5 @@ class CParserGenerator(ParserGenerator, GrammarVisitor):
name = node.name if node.name else call.assigned_variable
if name is not None:
name = self.dedupe(name)
return name, call.return_type
return_type = call.return_type if node.type is None else node.type
return name, return_type

View File

@ -259,9 +259,10 @@ class Alt:
class NamedItem:
def __init__(self, name: Optional[str], item: Item):
def __init__(self, name: Optional[str], item: Item, type: Optional[str] = None):
self.name = name
self.item = item
self.type = type
self.nullable = False
def __str__(self) -> str:

View File

@ -402,9 +402,49 @@ class GeneratedParser(Parser):
@memoize
def named_item(self) -> Optional[NamedItem]:
# named_item: NAME '=' ~ item | item | lookahead
# named_item: NAME '[' NAME '*' ']' '=' ~ item | NAME '[' NAME ']' '=' ~ item | NAME '=' ~ item | item | lookahead
mark = self.mark()
cut = False
if (
(name := self.name())
and
(literal := self.expect('['))
and
(type := self.name())
and
(literal_1 := self.expect('*'))
and
(literal_2 := self.expect(']'))
and
(literal_3 := self.expect('='))
and
(cut := True)
and
(item := self.item())
):
return NamedItem ( name . string , item , f"{type.string}*" )
self.reset(mark)
if cut: return None
cut = False
if (
(name := self.name())
and
(literal := self.expect('['))
and
(type := self.name())
and
(literal_1 := self.expect(']'))
and
(literal_2 := self.expect('='))
and
(cut := True)
and
(item := self.item())
):
return NamedItem ( name . string , item , type . string )
self.reset(mark)
if cut: return None
cut = False
if (
(name := self.name())
and

View File

@ -83,6 +83,8 @@ items[NamedItemList]:
| named_item { [named_item] }
named_item[NamedItem]:
| NAME '[' type=NAME '*' ']' '=' ~ item {NamedItem(name.string, item, f"{type.string}*")}
| NAME '[' type=NAME ']' '=' ~ item {NamedItem(name.string, item, type.string)}
| NAME '=' ~ item {NamedItem(name.string, item)}
| item {NamedItem(None, item)}
| it=lookahead {NamedItem(None, it)}