OLD | NEW |
1 #include "Python.h" | 1 #include "Python.h" |
2 #include "Python-ast.h" | 2 #include "Python-ast.h" |
3 #include "node.h" | 3 #include "node.h" |
4 #include "token.h" | 4 #include "token.h" |
5 #include "graminit.h" | 5 #include "graminit.h" |
6 #include "code.h" | 6 #include "code.h" |
7 #include "symtable.h" | 7 #include "symtable.h" |
8 | 8 |
9 #define UNDEFINED_FUTURE_FEATURE "future feature %.100s is not defined" | 9 #define UNDEFINED_FUTURE_FEATURE "future feature %.100s is not defined" |
10 #define ERR_LATE_FUTURE \ | 10 #define ERR_LATE_FUTURE \ |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 PyErr_SyntaxLocationEx(filename, s->lineno, s->col_offset); | 51 PyErr_SyntaxLocationEx(filename, s->lineno, s->col_offset); |
52 return 0; | 52 return 0; |
53 } | 53 } |
54 } | 54 } |
55 return 1; | 55 return 1; |
56 } | 56 } |
57 | 57 |
58 static int | 58 static int |
59 future_parse(PyFutureFeatures *ff, mod_ty mod, const char *filename) | 59 future_parse(PyFutureFeatures *ff, mod_ty mod, const char *filename) |
60 { | 60 { |
61 int i, found_docstring = 0, done = 0, prev_line = 0; | 61 int i, done = 0, prev_line = 0; |
62 | 62 |
63 static PyObject *future; | 63 static PyObject *future; |
64 if (!future) { | 64 if (!future) { |
65 future = PyUnicode_InternFromString("__future__"); | 65 future = PyUnicode_InternFromString("__future__"); |
66 if (!future) | 66 if (!future) |
67 return 0; | 67 return 0; |
68 } | 68 } |
69 | 69 |
70 if (!(mod->kind == Module_kind || mod->kind == Interactive_kind)) | 70 if (!(mod->kind == Module_kind || mod->kind == Interactive_kind)) |
71 return 1; | 71 return 1; |
(...skipping 28 matching lines...) Expand all Loading... |
100 PyErr_SyntaxLocationEx(filename, s->lineno, s->col_offset); | 100 PyErr_SyntaxLocationEx(filename, s->lineno, s->col_offset); |
101 return 0; | 101 return 0; |
102 } | 102 } |
103 if (!future_check_features(ff, s, filename)) | 103 if (!future_check_features(ff, s, filename)) |
104 return 0; | 104 return 0; |
105 ff->ff_lineno = s->lineno; | 105 ff->ff_lineno = s->lineno; |
106 } | 106 } |
107 else | 107 else |
108 done = 1; | 108 done = 1; |
109 } | 109 } |
110 else if (s->kind == Expr_kind && !found_docstring) { | 110 else if (s->kind == Expr_kind) { |
111 expr_ty e = s->v.Expr.value; | 111 done = 1; |
112 if (e->kind != Str_kind) | |
113 done = 1; | |
114 else | |
115 found_docstring = 1; | |
116 } | 112 } |
117 else | 113 else |
118 done = 1; | 114 done = 1; |
119 } | 115 } |
120 return 1; | 116 return 1; |
121 } | 117 } |
122 | 118 |
123 | 119 |
124 PyFutureFeatures * | 120 PyFutureFeatures * |
125 PyFuture_FromAST(mod_ty mod, const char *filename) | 121 PyFuture_FromAST(mod_ty mod, const char *filename) |
126 { | 122 { |
127 PyFutureFeatures *ff; | 123 PyFutureFeatures *ff; |
128 | 124 |
129 ff = (PyFutureFeatures *)PyObject_Malloc(sizeof(PyFutureFeatures)); | 125 ff = (PyFutureFeatures *)PyObject_Malloc(sizeof(PyFutureFeatures)); |
130 if (ff == NULL) { | 126 if (ff == NULL) { |
131 PyErr_NoMemory(); | 127 PyErr_NoMemory(); |
132 return NULL; | 128 return NULL; |
133 } | 129 } |
134 ff->ff_features = 0; | 130 ff->ff_features = 0; |
135 ff->ff_lineno = -1; | 131 ff->ff_lineno = -1; |
136 | 132 |
137 if (!future_parse(ff, mod, filename)) { | 133 if (!future_parse(ff, mod, filename)) { |
138 PyObject_Free(ff); | 134 PyObject_Free(ff); |
139 return NULL; | 135 return NULL; |
140 } | 136 } |
141 return ff; | 137 return ff; |
142 } | 138 } |
OLD | NEW |