diff options
Diffstat (limited to 'Parser')
-rwxr-xr-x | Parser/asdl_c.py | 71 | ||||
-rw-r--r-- | Parser/pegen.c | 1 | ||||
-rw-r--r-- | Parser/pegen.h | 4 | ||||
-rw-r--r-- | Parser/string_parser.h | 2 |
4 files changed, 46 insertions, 32 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index aefea12..73cb774 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -1445,13 +1445,12 @@ get_ast_state(void) } """) - # f-string for {mod.name} - f.write(f""" -// Include {mod.name}-ast.h after pycore_interp.h to avoid conflicts -// with the Yield macro redefined by <winbase.h> -#include "{mod.name}-ast.h" -#include "structmember.h" -""") + print(textwrap.dedent(""" + // Include pycore_ast.h after pycore_interp.h to avoid conflicts + // with the Yield macro redefined by <winbase.h> + #include "pycore_ast.h" + #include "structmember.h" + """).rstrip(), file=f) generate_ast_fini(module_state, f) @@ -1465,33 +1464,49 @@ get_ast_state(void) f.write('};\n\n') def write_header(mod, f): - f.write('#ifndef Py_PYTHON_AST_H\n') - f.write('#define Py_PYTHON_AST_H\n') - f.write('#ifdef __cplusplus\n') - f.write('extern "C" {\n') - f.write('#endif\n') - f.write('\n') - f.write('#ifndef Py_LIMITED_API\n') - f.write('#include "asdl.h"\n') - f.write('\n') - f.write('#undef Yield /* undefine macro conflicting with <winbase.h> */\n') - f.write('\n') + f.write(textwrap.dedent(""" + #ifndef Py_INTERNAL_AST_H + #define Py_INTERNAL_AST_H + #ifdef __cplusplus + extern "C" { + #endif + + #ifndef Py_BUILD_CORE + # error "this header requires Py_BUILD_CORE define" + #endif + + #include "pycore_asdl.h" + + #undef Yield /* undefine macro conflicting with <winbase.h> */ + + """).lstrip()) c = ChainOfVisitors(TypeDefVisitor(f), SequenceDefVisitor(f), StructVisitor(f)) c.visit(mod) f.write("// Note: these macros affect function definitions, not only call sites.\n") PrototypeVisitor(f).visit(mod) - f.write("\n") - f.write("PyObject* PyAST_mod2obj(mod_ty t);\n") - f.write("mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n") - f.write("int PyAST_Check(PyObject* obj);\n") - f.write("#endif /* !Py_LIMITED_API */\n") - f.write('\n') - f.write('#ifdef __cplusplus\n') - f.write('}\n') - f.write('#endif\n') - f.write('#endif /* !Py_PYTHON_AST_H */\n') + f.write(textwrap.dedent(""" + + PyObject* PyAST_mod2obj(mod_ty t); + mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode); + int PyAST_Check(PyObject* obj); + + extern int _PyAST_Validate(mod_ty); + + /* _PyAST_ExprAsUnicode is defined in ast_unparse.c */ + extern 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. */ + extern PyObject* _PyAST_GetDocString(asdl_stmt_seq *); + + #ifdef __cplusplus + } + #endif + #endif /* !Py_INTERNAL_AST_H */ + """)) def write_internal_h_header(mod, f): diff --git a/Parser/pegen.c b/Parser/pegen.c index d2b7ec4..f5c7994 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -5,7 +5,6 @@ #include "pegen.h" #include "string_parser.h" -#include "ast.h" PyObject * _PyPegen_new_type_comment(Parser *p, char *s) diff --git a/Parser/pegen.h b/Parser/pegen.h index 8720e60..66de75c 100644 --- a/Parser/pegen.h +++ b/Parser/pegen.h @@ -4,7 +4,7 @@ #define PY_SSIZE_T_CLEAN #include <Python.h> #include <token.h> -#include <Python-ast.h> +#include <pycore_ast.h> #if 0 #define PyPARSE_YIELD_IS_KEYWORD 0x0001 @@ -101,7 +101,7 @@ typedef struct { arg_ty kwarg; } StarEtc; -typedef struct { operator_ty kind; } AugOperator; +typedef struct { operator_ty kind; } AugOperator; typedef struct { void *element; int is_keyword; diff --git a/Parser/string_parser.h b/Parser/string_parser.h index cd85bd5..4a22f3d 100644 --- a/Parser/string_parser.h +++ b/Parser/string_parser.h @@ -2,7 +2,7 @@ #define STRINGS_H #include <Python.h> -#include <Python-ast.h> +#include <pycore_ast.h> #include "pegen.h" #define EXPRLIST_N_CACHED 64 |