bpo-42000: Cleanup the AST related C-code (GH-22641)

- Use the proper asdl sequence when creating empty arguments
- Remove reduntant casts (thanks to new typed asdl_sequences)
- Remove MarshalPrototypeVisitor and some utilities from asdl generator
- Fix the header of `Python/ast.c` (kept from pgen times)

Automerge-Triggered-By: @pablogsal
This commit is contained in:
Batuhan Taskaya 2020-10-10 20:14:59 +03:00 committed by GitHub
parent 637a09b0d6
commit 02a1603f91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 53 deletions

View file

@ -1,18 +1,12 @@
/*
* This file includes functions to transform a concrete syntax tree (CST) to
* an abstract syntax tree (AST). The main function is PyAST_FromNode().
*
* This file exposes PyAST_Validate interface to check the integrity
* of the given abstract syntax tree (potentially constructed manually).
*/
#include "Python.h"
#include "Python-ast.h"
#include "ast.h"
#include "token.h"
#include "pythonrun.h"
#include <assert.h>
#include <stdbool.h>
#define MAXLEVEL 200 /* Max parentheses level */
static int validate_stmts(asdl_stmt_seq *);
static int validate_exprs(asdl_expr_seq*, expr_context_ty, int);
@ -62,7 +56,7 @@ validate_keywords(asdl_keyword_seq *keywords)
{
Py_ssize_t i;
for (i = 0; i < asdl_seq_LEN(keywords); i++)
if (!validate_expr(((keyword_ty)asdl_seq_GET(keywords, i))->value, Load))
if (!validate_expr((asdl_seq_GET(keywords, i))->value, Load))
return 0;
return 1;
}
@ -556,7 +550,7 @@ _PyAST_GetDocString(asdl_stmt_seq *body)
if (!asdl_seq_LEN(body)) {
return NULL;
}
stmt_ty st = (stmt_ty)asdl_seq_GET(body, 0);
stmt_ty st = asdl_seq_GET(body, 0);
if (st->kind != Expr_kind) {
return NULL;
}