]> granicus.if.org Git - python/commitdiff
Refactor future feature handling
authorJeremy Hylton <jeremy@alum.mit.edu>
Fri, 10 Aug 2001 21:41:33 +0000 (21:41 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Fri, 10 Aug 2001 21:41:33 +0000 (21:41 +0000)
Replace uses of PyCF_xxx with CO_xxx.

Replace individual feature slots in PyFutureFeatures with single
bitmask ff_features.

When flags must be transfered among the three parts of the interpreter
that care about them -- the pythonrun layer, the compiler, and the
future feature parser -- can simply or (|) the definitions.

Python/ceval.c
Python/compile.c
Python/future.c
Python/pythonrun.c

index 583d7e3dacc6d0186dc2f53674e5bcd63c7fea6a..bf85f1112375a22be5a057203524ffaa253000e7 100644 (file)
@@ -2937,11 +2937,11 @@ PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
                const int codeflags = current_frame->f_code->co_flags;
                if (codeflags & CO_NESTED) {
                        result = 1;
-                       cf->cf_flags |= PyCF_NESTED_SCOPES;
+                       cf->cf_flags |= CO_NESTED;
                }
                if (codeflags & CO_GENERATOR_ALLOWED) {
                        result = 1;
-                       cf->cf_flags |= PyCF_GENERATORS;
+                       cf->cf_flags |= CO_GENERATOR_ALLOWED;
                }
        }
        return result;
index d310e357f5902cab0e60a025667fb5826a250616..66cd00ab8393ffb8073f10520dc83fa34f866d6c 100644 (file)
@@ -3967,22 +3967,8 @@ jcompile(node *n, char *filename, struct compiling *base,
                        com_free(&sc);
                        return NULL;
                }
-               if (flags) {
-                       if (flags->cf_flags & PyCF_NESTED_SCOPES)
-                               sc.c_future->ff_nested_scopes = 1;
-                       else if (sc.c_future->ff_nested_scopes)
-                               flags->cf_flags |= PyCF_NESTED_SCOPES;
-
-                       if (flags->cf_flags & PyCF_GENERATORS)
-                               sc.c_future->ff_generators = 1;
-                       else if (sc.c_future->ff_generators)
-                               flags->cf_flags |= PyCF_GENERATORS;
-
-                       if (flags->cf_flags & PyCF_DIVISION)
-                               sc.c_future->ff_division = 1;
-                       else if (sc.c_future->ff_division)
-                               flags->cf_flags |= PyCF_DIVISION;
-               }
+               if (flags)
+                       sc.c_future->ff_features |= flags->cf_flags;
                if (symtable_build(&sc, n) < 0) {
                        com_free(&sc);
                        return NULL;
@@ -4150,8 +4136,6 @@ symtable_build(struct compiling *c, node *n)
        if ((c->c_symtable = symtable_init()) == NULL)
                return -1;
        c->c_symtable->st_future = c->c_future;
-       if (c->c_future->ff_nested_scopes)
-               c->c_symtable->st_nested_scopes = 1;
        c->c_symtable->st_filename = c->c_filename;
        symtable_enter_scope(c->c_symtable, TOP, TYPE(n), n->n_lineno);
        if (c->c_symtable->st_errors > 0)
@@ -4451,14 +4435,8 @@ static int
 symtable_update_flags(struct compiling *c, PySymtableEntryObject *ste,
                      struct symbol_info *si)
 {
-       if (c->c_future) {
-               if (c->c_future->ff_nested_scopes)
-                       c->c_flags |= CO_NESTED;
-               if (c->c_future->ff_generators)
-                       c->c_flags |= CO_GENERATOR_ALLOWED;
-               if (c->c_future->ff_division)
-                       c->c_flags |= CO_FUTURE_DIVISION;
-       }
+       if (c->c_future)
+               c->c_flags |= c->c_future->ff_features;
        if (ste->ste_generator)
                c->c_flags |= CO_GENERATOR;
        if (ste->ste_type != TYPE_MODULE)
@@ -4617,7 +4595,6 @@ symtable_init()
        if (st == NULL)
                return NULL;
        st->st_pass = 1;
-       st->st_nested_scopes = NESTED_SCOPES_DEFAULT;
        st->st_filename = NULL;
        if ((st->st_stack = PyList_New(0)) == NULL)
                goto fail;
index db62b5b251bcbd04676b8fe5e348560a5b3c0f31..6b1c0c55b892cba9ddd751ab260786f045caccdd 100644 (file)
@@ -30,11 +30,11 @@ future_check_features(PyFutureFeatures *ff, node *n, char *filename)
                REQ(ch, import_as_name);
                feature = STR(CHILD(ch, 0));
                if (strcmp(feature, FUTURE_NESTED_SCOPES) == 0) {
-                       ff->ff_nested_scopes = 1;
+                       continue;
                } else if (strcmp(feature, FUTURE_GENERATORS) == 0) {
-                       ff->ff_generators = 1;
+                       ff->ff_features |= CO_GENERATOR_ALLOWED;
                } else if (strcmp(feature, FUTURE_DIVISION) == 0) {
-                       ff->ff_division = 1;
+                       ff->ff_features |= CO_FUTURE_DIVISION;
                } else if (strcmp(feature, "braces") == 0) {
                        PyErr_SetString(PyExc_SyntaxError,
                                        "not a chance");
@@ -234,9 +234,7 @@ PyNode_Future(node *n, char *filename)
                return NULL;
        ff->ff_found_docstring = 0;
        ff->ff_last_lineno = -1;
-       ff->ff_nested_scopes = 0;
-       ff->ff_generators = 0;
-       ff->ff_division = 0;
+       ff->ff_features = 0;
 
        if (future_parse(ff, n, filename) < 0) {
                PyMem_Free((void *)ff);
index 69a7b512540ab6676207f3f20d940c071e99b81a..f5fcaf15de2764e513f723f45303cd3e23ec0d0f 100644 (file)
@@ -556,7 +556,7 @@ PyRun_InteractiveOneFlags(FILE *fp, char *filename, PyCompilerFlags *flags)
        n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar,
                                    Py_single_input, ps1, ps2, &err,
                                    (flags &&
-                                    flags->cf_flags & PyCF_GENERATORS) ?
+                                    flags->cf_flags & CO_GENERATOR_ALLOWED) ?
                                        PyPARSE_YIELD_IS_KEYWORD : 0);
        Py_XDECREF(v);
        Py_XDECREF(w);
@@ -1009,8 +1009,8 @@ PyRun_StringFlags(char *str, int start, PyObject *globals, PyObject *locals,
                  PyCompilerFlags *flags)
 {
        return run_err_node(PyParser_SimpleParseStringFlags(
-                               str, start,
-                               (flags && flags->cf_flags & PyCF_GENERATORS) ?
+                       str, start,
+                       (flags && flags->cf_flags & CO_GENERATOR_ALLOWED) ?
                                PyPARSE_YIELD_IS_KEYWORD : 0),
                            "<string>", globals, locals, flags);
 }
@@ -1028,7 +1028,7 @@ PyRun_FileExFlags(FILE *fp, char *filename, int start, PyObject *globals,
                  PyObject *locals, int closeit, PyCompilerFlags *flags)
 {
        node *n = PyParser_SimpleParseFileFlags(fp, filename, start,
-                       (flags && flags->cf_flags & PyCF_GENERATORS) ?
+                       (flags && flags->cf_flags & CO_GENERATOR_ALLOWED) ?
                                PyPARSE_YIELD_IS_KEYWORD : 0);
        if (closeit)
                fclose(fp);
@@ -1085,18 +1085,8 @@ run_pyc_file(FILE *fp, char *filename, PyObject *globals, PyObject *locals,
        }
        co = (PyCodeObject *)v;
        v = PyEval_EvalCode(co, globals, locals);
-       if (v && flags) {
-               if (co->co_flags & CO_NESTED)
-                       flags->cf_flags |= PyCF_NESTED_SCOPES;
-               if (co->co_flags & CO_GENERATOR_ALLOWED)
-                       flags->cf_flags |= PyCF_GENERATORS;
-#if 0
-               fprintf(stderr, "run_pyc_file: nested_scopes: %d\n",
-                       flags->cf_flags & PyCF_NESTED_SCOPES);
-               fprintf(stderr, "run_pyc_file: generators: %d\n",
-                       flags->cf_flags & PyCF_GENERATORS);
-#endif
-       }
+       if (v && flags)
+               flags->cf_flags |= (co->co_flags & PyCF_MASK);
        Py_DECREF(co);
        return v;
 }
@@ -1114,7 +1104,7 @@ Py_CompileStringFlags(char *str, char *filename, int start,
        node *n;
        PyCodeObject *co;
        n = PyParser_SimpleParseStringFlags(str, start,
-               (flags && flags->cf_flags & PyCF_GENERATORS) ?
+               (flags && flags->cf_flags & CO_GENERATOR_ALLOWED) ?
                        PyPARSE_YIELD_IS_KEYWORD : 0);
        if (n == NULL)
                return NULL;