summaryrefslogtreecommitdiffstats
path: root/Parser/asdl_c.py
diff options
context:
space:
mode:
Diffstat (limited to 'Parser/asdl_c.py')
-rwxr-xr-xParser/asdl_c.py71
1 files changed, 43 insertions, 28 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):