compile.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef Py_COMPILE_H
  2. #define Py_COMPILE_H
  3. #ifndef Py_LIMITED_API
  4. #include "code.h"
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. /* Public interface */
  9. struct _node; /* Declare the existence of this type */
  10. PyAPI_FUNC(PyCodeObject *) PyNode_Compile(struct _node *, const char *);
  11. /* XXX (ncoghlan): Unprefixed type name in a public API! */
  12. #define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \
  13. CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | \
  14. CO_FUTURE_UNICODE_LITERALS | CO_FUTURE_BARRY_AS_BDFL | \
  15. CO_FUTURE_GENERATOR_STOP | CO_FUTURE_ANNOTATIONS)
  16. #define PyCF_MASK_OBSOLETE (CO_NESTED)
  17. #define PyCF_SOURCE_IS_UTF8 0x0100
  18. #define PyCF_DONT_IMPLY_DEDENT 0x0200
  19. #define PyCF_ONLY_AST 0x0400
  20. #define PyCF_IGNORE_COOKIE 0x0800
  21. #define PyCF_TYPE_COMMENTS 0x1000
  22. #define PyCF_ALLOW_TOP_LEVEL_AWAIT 0x2000
  23. #ifndef Py_LIMITED_API
  24. typedef struct {
  25. int cf_flags; /* bitmask of CO_xxx flags relevant to future */
  26. int cf_feature_version; /* minor Python version (PyCF_ONLY_AST) */
  27. } PyCompilerFlags;
  28. #define _PyCompilerFlags_INIT \
  29. (PyCompilerFlags){.cf_flags = 0, .cf_feature_version = PY_MINOR_VERSION}
  30. #endif
  31. /* Future feature support */
  32. typedef struct {
  33. int ff_features; /* flags set by future statements */
  34. int ff_lineno; /* line number of last future statement */
  35. } PyFutureFeatures;
  36. #define FUTURE_NESTED_SCOPES "nested_scopes"
  37. #define FUTURE_GENERATORS "generators"
  38. #define FUTURE_DIVISION "division"
  39. #define FUTURE_ABSOLUTE_IMPORT "absolute_import"
  40. #define FUTURE_WITH_STATEMENT "with_statement"
  41. #define FUTURE_PRINT_FUNCTION "print_function"
  42. #define FUTURE_UNICODE_LITERALS "unicode_literals"
  43. #define FUTURE_BARRY_AS_BDFL "barry_as_FLUFL"
  44. #define FUTURE_GENERATOR_STOP "generator_stop"
  45. #define FUTURE_ANNOTATIONS "annotations"
  46. struct _mod; /* Declare the existence of this type */
  47. #define PyAST_Compile(mod, s, f, ar) PyAST_CompileEx(mod, s, f, -1, ar)
  48. PyAPI_FUNC(PyCodeObject *) PyAST_CompileEx(
  49. struct _mod *mod,
  50. const char *filename, /* decoded from the filesystem encoding */
  51. PyCompilerFlags *flags,
  52. int optimize,
  53. PyArena *arena);
  54. PyAPI_FUNC(PyCodeObject *) PyAST_CompileObject(
  55. struct _mod *mod,
  56. PyObject *filename,
  57. PyCompilerFlags *flags,
  58. int optimize,
  59. PyArena *arena);
  60. PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST(
  61. struct _mod * mod,
  62. const char *filename /* decoded from the filesystem encoding */
  63. );
  64. PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromASTObject(
  65. struct _mod * mod,
  66. PyObject *filename
  67. );
  68. /* _Py_Mangle is defined in compile.c */
  69. PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);
  70. #define PY_INVALID_STACK_EFFECT INT_MAX
  71. PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg);
  72. PyAPI_FUNC(int) PyCompile_OpcodeStackEffectWithJump(int opcode, int oparg, int jump);
  73. PyAPI_FUNC(int) _PyAST_Optimize(struct _mod *, PyArena *arena, int optimize);
  74. #ifdef __cplusplus
  75. }
  76. #endif
  77. #endif /* !Py_LIMITED_API */
  78. /* These definitions must match corresponding definitions in graminit.h. */
  79. #define Py_single_input 256
  80. #define Py_file_input 257
  81. #define Py_eval_input 258
  82. #define Py_func_type_input 345
  83. #endif /* !Py_COMPILE_H */