Commit 688a6117 authored by Travis Hance's avatar Travis Hance

use future flags constants from cpython

parent 7cce54f1
......@@ -111,6 +111,8 @@
#include "pyfpe.h"
#include "code.h"
#define Py_single_input 256
#define Py_file_input 257
#define Py_eval_input 258
......
......@@ -16,6 +16,8 @@
#include <map>
#include "Python.h"
#include "core/ast.h"
namespace pyston {
......@@ -27,13 +29,15 @@ struct FutureOption {
};
const std::map<std::string, FutureOption> future_options
= { { "absolute_import", { version_hex(2, 5, 0), version_hex(3, 0, 0), FF_ABSOLUTE_IMPORT } },
{ "division", { version_hex(2, 2, 0), version_hex(3, 0, 0), FF_DIVISION } },
{ "generators", { version_hex(2, 2, 0), version_hex(3, 0, 0), FF_GENERATOR } },
{ "unicode_literals", { version_hex(2, 6, 0), version_hex(3, 0, 0), FF_UNICODE_LITERALS } },
{ "print_function", { version_hex(2, 6, 0), version_hex(3, 0, 0), FF_PRINT_FUNCTION } },
{ "nested_scopes", { version_hex(2, 1, 0), version_hex(2, 2, 0), FF_NESTED_SCOPES } },
{ "with_statement", { version_hex(2, 5, 0), version_hex(3, 6, 0), FF_WITH_STATEMENT } } };
= { { "absolute_import", { version_hex(2, 5, 0), version_hex(3, 0, 0), CO_FUTURE_ABSOLUTE_IMPORT } },
{ "division", { version_hex(2, 2, 0), version_hex(3, 0, 0), CO_FUTURE_DIVISION } },
{ "unicode_literals", { version_hex(2, 6, 0), version_hex(3, 0, 0), CO_FUTURE_UNICODE_LITERALS } },
{ "print_function", { version_hex(2, 6, 0), version_hex(3, 0, 0), CO_FUTURE_PRINT_FUNCTION } },
{ "with_statement", { version_hex(2, 5, 0), version_hex(3, 6, 0), CO_FUTURE_WITH_STATEMENT } },
// These are mandatory in all versions we care about (>= 2.3)
{ "generators", { version_hex(2, 2, 0), version_hex(3, 0, 0), CO_GENERATOR } },
{ "nested_scopes", { version_hex(2, 1, 0), version_hex(2, 2, 0), CO_NESTED } } };
void raiseFutureImportErrorNotFound(const char* file, AST* node, const char* name) {
raiseSyntaxErrorHelper(file, "", node, "future feature %s is not defined", name);
......
......@@ -21,14 +21,6 @@
namespace pyston {
#define FF_ABSOLUTE_IMPORT 0x01
#define FF_DIVISION 0x02
#define FF_GENERATOR 0x04
#define FF_UNICODE_LITERALS 0x08
#define FF_PRINT_FUNCTION 0x10
#define FF_NESTED_SCOPES 0x20
#define FF_WITH_STATEMENT 0x40
// Loop through import statements to find __future__ imports throwing errors for
// bad __future__ imports. Returns the futures that are turned on. This is used
// for irgeneration; the parser still has to handle some futures on its own,
......
......@@ -19,6 +19,8 @@
#include <cstdio>
#include <cstdlib>
#include "Python.h"
#include "analysis/scoping_analysis.h"
#include "core/ast.h"
#include "core/options.h"
......@@ -1481,7 +1483,7 @@ public:
// level == -1 means check both sys path and relative for imports.
// so if `from __future__ import absolute_import` was used in the file, set level to 0
int level;
if (!(future_flags & FF_ABSOLUTE_IMPORT))
if (!(future_flags & CO_FUTURE_ABSOLUTE_IMPORT))
level = -1;
else
level = 0;
......@@ -1532,7 +1534,7 @@ public:
// level == -1 means check both sys path and relative for imports.
// so if `from __future__ import absolute_import` was used in the file, set level to 0
int level;
if (node->level == 0 && !(future_flags & FF_ABSOLUTE_IMPORT))
if (node->level == 0 && !(future_flags & CO_FUTURE_ABSOLUTE_IMPORT))
level = -1;
else
level = node->level;
......@@ -1729,7 +1731,7 @@ public:
}
AST_TYPE::AST_TYPE remapBinOpType(AST_TYPE::AST_TYPE op_type) {
if (op_type == AST_TYPE::Div && (future_flags & (FF_DIVISION))) {
if (op_type == AST_TYPE::Div && (future_flags & (CO_FUTURE_DIVISION))) {
return AST_TYPE::TrueDiv;
} else {
return op_type;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment