Skip to content
This repository was archived by the owner on Jul 5, 2023. It is now read-only.

Commit ae5c356

Browse files
emmatypingddfisher
authored andcommitted
Vs2010 compilation support (Python 3.3/3.4 support) (#47)
MSVC 9's weird C99 implementation means that identifiers must be declared at the beginning of a scope. This refactors the code to support that.
1 parent d4322a8 commit ae5c356

File tree

7 files changed

+25
-13
lines changed

7 files changed

+25
-13
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ parser similar to the standard `ast` library. Unlike `ast`, the parsers in
99
comments and are independent of the version of Python under which they are run.
1010
The `typed_ast` parsers produce the standard Python AST (plus type comments),
1111
and are both fast and correct, as they are based on the CPython 2.7 and 3.6
12-
parsers. `typed_ast` runs on Python 3.3-3.6 on Linux and OS X, and on Python
13-
3.5-3.6 on Windows.
12+
parsers. `typed_ast` runs on Python 3.3-3.6 on Linux, OS X and Windows.
1413

1514
## Submodules
1615
### ast3

appveyor.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
environment:
2-
32
matrix:
4-
53
# For Python versions available on Appveyor, see
64
# http://www.appveyor.com/docs/installed-software#python
7-
5+
- PYTHON: "C:\\Python33"
6+
- PYTHON: "C:\\Python33-x64"
7+
DISTUTILS_USE_SDK: 1
8+
- PYTHON: "C:\\Python34"
9+
- PYTHON: "C:\\Python34-x64"
10+
DISTUTILS_USE_SDK: 1
811
- PYTHON: "C:\\Python35"
912
- PYTHON: "C:\\Python35-x64"
1013
- PYTHON: "C:\\Python36"

ast27/Custom/typed_ast.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ string_object_to_py_ast(const char *str, PyObject *filename, int start,
239239
PyCompilerFlags *flags)
240240
{
241241
mod_ty mod;
242+
PyObject *result;
242243
PyArena *arena = PyArena_New();
243244
if (arena == NULL)
244245
return NULL;
@@ -249,7 +250,7 @@ string_object_to_py_ast(const char *str, PyObject *filename, int start,
249250
return NULL;
250251
}
251252

252-
PyObject *result = Ta27AST_mod2obj(mod);
253+
result = Ta27AST_mod2obj(mod);
253254
PyArena_Free(arena);
254255
return result;
255256
}

ast27/Parser/tokenizer.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,10 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end)
13521352
};
13531353
char cbuf[80];
13541354
char *tp, **cp;
1355+
1356+
/* used for type comment checks */
1357+
const char *prefix, *p, *type_start;
1358+
13551359
tp = cbuf;
13561360
do {
13571361
*tp++ = c = tok_nextc(tok);
@@ -1375,9 +1379,9 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end)
13751379
}
13761380
while (c != EOF && c != '\n')
13771381
c = tok_nextc(tok);
1378-
1382+
13791383
/* check for type comment */
1380-
const char *prefix, *p, *type_start;
1384+
13811385
p = tok->start;
13821386
prefix = type_comment_prefix;
13831387
while (*prefix && p < tok->cur) {

ast27/Python/ast.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,6 +2303,7 @@ ast_for_class_bases(struct compiling *c, const node* n)
23032303
static stmt_ty
23042304
ast_for_expr_stmt(struct compiling *c, const node *n)
23052305
{
2306+
int num;
23062307
REQ(n, expr_stmt);
23072308
/* expr_stmt: testlist (augassign (yield_expr|testlist)
23082309
| ('=' (yield_expr|testlist))* [TYPE_COMMENT])
@@ -2311,7 +2312,7 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
23112312
| '<<=' | '>>=' | '**=' | '//='
23122313
test: ... here starts the operator precendence dance
23132314
*/
2314-
int num = NCH(n);
2315+
num = NCH(n);
23152316

23162317
if (num == 1 || (num == 2 && TYPE(CHILD(n, 1)) == TYPE_COMMENT)) {
23172318
expr_ty e = ast_for_testlist(c, CHILD(n, 0));
@@ -3516,12 +3517,13 @@ parsenumber(struct compiling *c, const char *s)
35163517
/* Make a copy without the trailing 'L' */
35173518
size_t len = end - s + 1;
35183519
char *copy = malloc(len);
3520+
PyObject *result;
35193521
if (copy == NULL)
35203522
return PyErr_NoMemory();
35213523
memcpy(copy, s, len);
35223524
copy[len - 1] = '\0';
35233525
old_style_octal = len > 2 && copy[0] == '0' && copy[1] >= '0' && copy[1] <= '9';
3524-
PyObject *result = PyLong_FromString(copy, (char **)0, old_style_octal ? 8 : 0);
3526+
result = PyLong_FromString(copy, (char **)0, old_style_octal ? 8 : 0);
35253527
free(copy);
35263528
return result;
35273529
}

ast3/Custom/typed_ast.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ string_object_to_py_ast(const char *str, PyObject *filename, int start,
249249
PyCompilerFlags *flags, int feature_version)
250250
{
251251
mod_ty mod;
252+
PyObject *result;
252253
PyArena *arena = PyArena_New();
253254
if (arena == NULL)
254255
return NULL;
@@ -259,7 +260,7 @@ string_object_to_py_ast(const char *str, PyObject *filename, int start,
259260
return NULL;
260261
}
261262

262-
PyObject *result = Ta3AST_mod2obj(mod);
263+
result = Ta3AST_mod2obj(mod);
263264
PyArena_Free(arena);
264265
return result;
265266
}

ast3/Python/ast.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,6 +2274,7 @@ ast_for_atom(struct compiling *c, const node *n)
22742274
return str;
22752275
}
22762276
case NUMBER: {
2277+
PyObject *pynum;
22772278
const char *s = STR(ch);
22782279
/* Underscores in numeric literals are only allowed in Python 3.6 or greater */
22792280
/* Check for underscores here rather than in parse_number so we can report a line number on error */
@@ -2282,7 +2283,7 @@ ast_for_atom(struct compiling *c, const node *n)
22822283
"Underscores in numeric literals are only supported in Python 3.6 and greater");
22832284
return NULL;
22842285
}
2285-
PyObject *pynum = parsenumber(c, s);
2286+
pynum = parsenumber(c, s);
22862287
if (!pynum)
22872288
return NULL;
22882289

@@ -3040,6 +3041,7 @@ ast_for_testlist(struct compiling *c, const node* n)
30403041
static stmt_ty
30413042
ast_for_expr_stmt(struct compiling *c, const node *n)
30423043
{
3044+
int num;
30433045
REQ(n, expr_stmt);
30443046
/* expr_stmt: testlist_star_expr (annassign | augassign (yield_expr|testlist) |
30453047
('=' (yield_expr|testlist_star_expr))* [TYPE_COMMENT])
@@ -3049,7 +3051,7 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
30493051
| '<<=' | '>>=' | '**=' | '//='
30503052
test: ... here starts the operator precedence dance
30513053
*/
3052-
int num = NCH(n);
3054+
num = NCH(n);
30533055

30543056
if (num == 1 || (num == 2 && TYPE(CHILD(n, 1)) == TYPE_COMMENT)) {
30553057
expr_ty e = ast_for_testlist(c, CHILD(n, 0));

0 commit comments

Comments
 (0)