MCPcopy Index your code
hub / github.com/python/cpython / write_header

Function write_header

Parser/asdl_c.py:2341–2390  ·  view source on GitHub ↗
(mod, metadata, f)

Source from the content-addressed store, hash-verified

2339 f.write('};\n\n')
2340
2341def write_header(mod, metadata, f):
2342 f.write(textwrap.dedent("""
2343 #ifndef Py_INTERNAL_AST_H
2344 #define Py_INTERNAL_AST_H
2345 #ifdef __cplusplus
2346 extern "C" {
2347 #endif
2348
2349 #ifndef Py_BUILD_CORE
2350 # error "this header requires Py_BUILD_CORE define"
2351 #endif
2352
2353 #include "pycore_asdl.h" // _ASDL_SEQ_HEAD
2354
2355 """).lstrip())
2356
2357 c = ChainOfVisitors(
2358 TypeDefVisitor(f),
2359 SequenceDefVisitor(f),
2360 StructVisitor(f),
2361 metadata=metadata
2362 )
2363 c.visit(mod)
2364
2365 f.write("// Note: these macros affect function definitions, not only call sites.\n")
2366 prototype_visitor = PrototypeVisitor(f, metadata=metadata)
2367 prototype_visitor.visit(mod)
2368
2369 f.write(textwrap.dedent("""
2370
2371 PyObject* PyAST_mod2obj(mod_ty t);
2372 int PyAst_CheckMode(PyObject *ast, int mode);
2373 mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);
2374 int PyAST_Check(PyObject* obj);
2375
2376 extern int _PyAST_Validate(mod_ty);
2377
2378 /* _PyAST_ExprAsUnicode is defined in ast_unparse.c */
2379 extern PyObject* _PyAST_ExprAsUnicode(expr_ty);
2380
2381 /* Return the borrowed reference to the first literal string in the
2382 sequence of statements or NULL if it doesn't start from a literal string.
2383 Doesn't set exception. */
2384 extern PyObject* _PyAST_GetDocString(asdl_stmt_seq *);
2385
2386 #ifdef __cplusplus
2387 }
2388 #endif
2389 #endif /* !Py_INTERNAL_AST_H */
2390 """))
2391
2392
2393def write_internal_h_header(mod, f):

Callers 1

mainFunction · 0.70

Calls 10

visitMethod · 0.95
ChainOfVisitorsClass · 0.85
TypeDefVisitorClass · 0.85
SequenceDefVisitorClass · 0.85
StructVisitorClass · 0.85
PrototypeVisitorClass · 0.85
writeMethod · 0.45
lstripMethod · 0.45
dedentMethod · 0.45
visitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…