gh-117411: move PyFutureFeatures to pycore_symtable.h and make it private (#117412)

This commit is contained in:
Irit Katriel 2024-04-02 11:34:49 +01:00 committed by GitHub
parent 5fd1897ec5
commit 1d5479b236
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 49 additions and 42 deletions

View file

@ -5,6 +5,7 @@
#include "pycore_compile.h"
#include "pycore_opcode_utils.h" // IS_BACKWARDS_JUMP_OPCODE
#include "pycore_opcode_metadata.h" // is_pseudo_target, _PyOpcode_Caches
#include "pycore_symtable.h" // _Py_SourceLocation
#define DEFAULT_CODE_SIZE 128
@ -21,7 +22,7 @@
return ERROR; \
}
typedef _PyCompilerSrcLocation location;
typedef _Py_SourceLocation location;
typedef _PyCompile_Instruction instruction;
typedef _PyCompile_InstructionSequence instr_sequence;

View file

@ -70,11 +70,11 @@
((C)->c_flags.cf_flags & PyCF_ALLOW_TOP_LEVEL_AWAIT) \
&& ((C)->u->u_ste->ste_type == ModuleBlock))
typedef _PyCompilerSrcLocation location;
typedef _Py_SourceLocation location;
typedef struct _PyCfgBuilder cfg_builder;
#define LOCATION(LNO, END_LNO, COL, END_COL) \
((const _PyCompilerSrcLocation){(LNO), (END_LNO), (COL), (END_COL)})
((const _Py_SourceLocation){(LNO), (END_LNO), (COL), (END_COL)})
/* Return true if loc1 starts after loc2 ends. */
static inline bool
@ -408,7 +408,7 @@ handled by the symbol analysis pass.
struct compiler {
PyObject *c_filename;
struct symtable *c_st;
PyFutureFeatures c_future; /* module's __future__ */
_PyFutureFeatures c_future; /* module's __future__ */
PyCompilerFlags c_flags;
int c_optimize; /* optimization level */
@ -585,7 +585,7 @@ int
_PyCompile_AstOptimize(mod_ty mod, PyObject *filename, PyCompilerFlags *cf,
int optimize, PyArena *arena)
{
PyFutureFeatures future;
_PyFutureFeatures future;
if (!_PyFuture_FromAST(mod, filename, &future)) {
return -1;
}

View file

@ -22,13 +22,13 @@
#define DEFAULT_BLOCK_SIZE 16
typedef _PyCompilerSrcLocation location;
typedef _Py_SourceLocation location;
typedef _PyCfgJumpTargetLabel jump_target_label;
typedef struct _PyCfgInstruction {
int i_opcode;
int i_oparg;
_PyCompilerSrcLocation i_loc;
_Py_SourceLocation i_loc;
struct _PyCfgBasicblock *i_target; /* target block (if jump instruction) */
struct _PyCfgBasicblock *i_except; /* target block when exception is raised */
} cfg_instr;
@ -92,7 +92,7 @@ static const jump_target_label NO_LABEL = {-1};
#define IS_LABEL(L) (!SAME_LABEL((L), (NO_LABEL)))
#define LOCATION(LNO, END_LNO, COL, END_COL) \
((const _PyCompilerSrcLocation){(LNO), (END_LNO), (COL), (END_COL)})
((const _Py_SourceLocation){(LNO), (END_LNO), (COL), (END_COL)})
static inline int
is_block_push(cfg_instr *i)

View file

@ -1,11 +1,12 @@
#include "Python.h"
#include "pycore_ast.h" // _PyAST_GetDocString()
#include "pycore_symtable.h" // _PyFutureFeatures
#include "pycore_unicodeobject.h" // _PyUnicode_EqualToASCIIString()
#define UNDEFINED_FUTURE_FEATURE "future feature %.100s is not defined"
static int
future_check_features(PyFutureFeatures *ff, stmt_ty s, PyObject *filename)
future_check_features(_PyFutureFeatures *ff, stmt_ty s, PyObject *filename)
{
int i;
@ -53,7 +54,7 @@ future_check_features(PyFutureFeatures *ff, stmt_ty s, PyObject *filename)
}
static int
future_parse(PyFutureFeatures *ff, mod_ty mod, PyObject *filename)
future_parse(_PyFutureFeatures *ff, mod_ty mod, PyObject *filename)
{
if (!(mod->kind == Module_kind || mod->kind == Interactive_kind)) {
return 1;
@ -98,10 +99,10 @@ future_parse(PyFutureFeatures *ff, mod_ty mod, PyObject *filename)
int
_PyFuture_FromAST(mod_ty mod, PyObject *filename, PyFutureFeatures *ff)
_PyFuture_FromAST(mod_ty mod, PyObject *filename, _PyFutureFeatures *ff)
{
ff->ff_features = 0;
ff->ff_location = (_PyCompilerSrcLocation){-1, -1, -1, -1};
ff->ff_location = (_Py_SourceLocation){-1, -1, -1, -1};
if (!future_parse(ff, mod, filename)) {
return 0;

View file

@ -387,7 +387,7 @@ symtable_new(void)
}
struct symtable *
_PySymtable_Build(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
_PySymtable_Build(mod_ty mod, PyObject *filename, _PyFutureFeatures *future)
{
struct symtable *st = symtable_new();
asdl_stmt_seq *seq;
@ -2757,7 +2757,7 @@ _Py_SymtableStringObjectFlags(const char *str, PyObject *filename,
_PyArena_Free(arena);
return NULL;
}
PyFutureFeatures future;
_PyFutureFeatures future;
if (!_PyFuture_FromAST(mod, filename, &future)) {
_PyArena_Free(arena);
return NULL;

View file

@ -5,7 +5,6 @@
#include "pycore_ast.h" // asdl_seq_GET()
#include "pycore_call.h" // _PyObject_CallMethodFormat()
#include "pycore_compile.h" // _PyAST_Optimize()
#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
#include "pycore_frame.h" // _PyFrame_GetCode()
#include "pycore_interp.h" // PyInterpreterState.gc