Skip to content

Commit

Permalink
pythongh-117411: move PyFutureFeatures to pycore_symtable.h
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel committed Mar 31, 2024
1 parent 18e1264 commit 16c162a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
5 changes: 0 additions & 5 deletions Include/cpython/compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ typedef struct {

/* Future feature support */

typedef struct {
int ff_features; /* flags set by future statements */
_PyCompilerSrcLocation ff_location; /* location of last future statement */
} PyFutureFeatures;

#define FUTURE_NESTED_SCOPES "nested_scopes"
#define FUTURE_GENERATORS "generators"
#define FUTURE_DIVISION "division"
Expand Down
11 changes: 8 additions & 3 deletions Include/internal/pycore_symtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ typedef enum _comprehension_type {
SetComprehension = 3,
GeneratorExpression = 4 } _Py_comprehension_ty;

typedef struct {
int ff_features; /* flags set by future statements */
_PyCompilerSrcLocation ff_location; /* location of last future statement */
} _PyFutureFeatures;

struct _symtable_entry;

struct symtable {
Expand All @@ -44,7 +49,7 @@ struct symtable {
consistency with the corresponding
compiler structure */
PyObject *st_private; /* name of current class or NULL */
PyFutureFeatures *st_future; /* module's future features that affect
_PyFutureFeatures *st_future; /* module's future features that affect
the symbol table */
int recursion_depth; /* current recursion depth */
int recursion_limit; /* recursion limit */
Expand Down Expand Up @@ -100,7 +105,7 @@ extern int _PyST_IsFunctionLike(PySTEntryObject *);
extern struct symtable* _PySymtable_Build(
struct _mod *mod,
PyObject *filename,
PyFutureFeatures *future);
_PyFutureFeatures *future);
extern PySTEntryObject* _PySymtable_Lookup(struct symtable *, void *);

extern void _PySymtable_Free(struct symtable *);
Expand Down Expand Up @@ -150,7 +155,7 @@ extern struct symtable* _Py_SymtableStringObjectFlags(
int _PyFuture_FromAST(
struct _mod * mod,
PyObject *filename,
PyFutureFeatures* futures);
_PyFutureFeatures* futures);

#ifdef __cplusplus
}
Expand Down
4 changes: 2 additions & 2 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 4 additions & 3 deletions Python/future.c
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -98,7 +99,7 @@ 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};
Expand Down

0 comments on commit 16c162a

Please sign in to comment.