[Python-checkins] r43614 - in python/trunk: Include/Python-ast.h Lib/test/test_ast.py Parser/Python.asdl Parser/asdl_c.py Python/Python-ast.c Python/ast.c (original) (raw)

jeremy.hylton python-checkins at python.org
Tue Apr 4 06:00:25 CEST 2006


Author: jeremy.hylton Date: Tue Apr 4 06:00:23 2006 New Revision: 43614

Modified: python/trunk/Include/Python-ast.h python/trunk/Lib/test/test_ast.py python/trunk/Parser/Python.asdl python/trunk/Parser/asdl_c.py python/trunk/Python/Python-ast.c python/trunk/Python/ast.c Log: Add lineno, col_offset to excephandler to enable future fix for tracing/line number table in except blocks.

Reflow long lines introduced by col_offset changes. Update test_ast to handle new fields in excepthandler.

As note in Python.asdl says, we might want to rethink how attributes are handled. Perhaps they should be the same as other fields, with the primary difference being how they are defined for all types within a sum.

Also fix asdl_c so that constructors with int fields don't fail when passed a zero value.

Modified: python/trunk/Include/Python-ast.h

--- python/trunk/Include/Python-ast.h (original) +++ python/trunk/Include/Python-ast.h Tue Apr 4 06:00:23 2006 @@ -323,6 +323,8 @@ expr_ty type; expr_ty name; asdl_seq *body;

};

struct _arguments { @@ -427,8 +429,8 @@ slice_ty Index(expr_ty value, PyArena *arena); comprehension_ty comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena); -excepthandler_ty excepthandler(expr_ty type, expr_ty name, asdl_seq * body,

+excepthandler_ty excepthandler(expr_ty type, expr_ty name, asdl_seq * body, int

arguments_ty arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq * defaults, PyArena *arena); keyword_ty keyword(identifier arg, expr_ty value, PyArena *arena);

Modified: python/trunk/Lib/test/test_ast.py

--- python/trunk/Lib/test/test_ast.py (original) +++ python/trunk/Lib/test/test_ast.py Tue Apr 4 06:00:23 2006 @@ -119,7 +119,8 @@

excepthandler, arguments, keywords, alias

if name=='main' and sys.argv[1:] == ['-g']:

@@ -131,7 +132,7 @@

 if not isinstance(ast_node, _ast.AST) or ast_node._fields == None:
     return

@@ -145,10 +146,12 @@

def run_tests(): for input, output, kind in ((exec_tests, exec_results, "exec"),

@@ -165,7 +168,7 @@ ('Module', [('While', (1, 0), ('Name', (1, 6), 'v', ('Load',)), [('Pass', (1, 8))], [])]), ('Module', [('If', (1, 0), ('Name', (1, 3), 'v', ('Load',)), [('Pass', (1, 5))], [])]), ('Module', [('Raise', (1, 0), ('Name', (1, 6), 'Exception', ('Load',)), ('Str', (1, 17), 'string'), None)]), -('Module', [('TryExcept', (1, 0), [('Pass', (2, 2))], [('excepthandler', ('Name', (3, 7), 'Exception', ('Load',)), None, [('Pass', (4, 2))])], [])]), +('Module', [('TryExcept', (1, 0), [('Pass', (2, 2))], [('excepthandler', (3, 0), ('Name', (3, 7), 'Exception', ('Load',)), None, [('Pass', (4, 2))], 3, 0)], [])]), ('Module', [('TryFinally', (1, 0), [('Pass', (2, 2))], [('Pass', (4, 2))])]), ('Module', [('Assert', (1, 0), ('Name', (1, 7), 'v', ('Load',)), None)]), ('Module', [('Import', (1, 0), [('alias', 'sys', None)])]),

Modified: python/trunk/Parser/Python.asdl

--- python/trunk/Parser/Python.asdl (original) +++ python/trunk/Parser/Python.asdl Tue Apr 4 06:00:23 2006 @@ -98,8 +98,11 @@ comprehension = (expr target, expr iter, expr* ifs) -- not sure what to call the first argument for raise and except

Modified: python/trunk/Parser/asdl_c.py

--- python/trunk/Parser/asdl_c.py (original) +++ python/trunk/Parser/asdl_c.py Tue Apr 4 06:00:23 2006 @@ -276,7 +276,7 @@ emit("%s p;" % ctype, 1) for argtype, argname, opt in args: # XXX hack alert: false is allowed for a bool

Modified: python/trunk/Python/Python-ast.c

--- python/trunk/Python/Python-ast.c (original) +++ python/trunk/Python/Python-ast.c Tue Apr 4 06:00:23 2006 @@ -331,6 +331,8 @@ "type", "name", "body",

}; static PyTypeObject arguments_type; static PyObject ast2obj_arguments(void*); @@ -712,7 +714,7 @@ comprehension_fields, 3); if (!comprehension_type) return 0; excepthandler_type = make_type("excepthandler", AST_type,

@@ -1843,7 +1845,8 @@ }

excepthandler_ty -excepthandler(expr_ty type, expr_ty name, asdl_seq * body, PyArena *arena) +excepthandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int

{ excepthandler_ty p; p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1854,6 +1857,8 @@ p->type = type; p->name = name; p->body = body;

}

@@ -2917,6 +2922,16 @@ if (PyObject_SetAttrString(result, "body", value) == -1) goto failed; Py_DECREF(value);

failed: Py_XDECREF(value); @@ -3033,7 +3048,7 @@ if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return; if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) return;

Modified: python/trunk/Python/ast.c

--- python/trunk/Python/ast.c (original) +++ python/trunk/Python/ast.c Tue Apr 4 06:00:23 2006 @@ -247,7 +247,8 @@ stmts = asdl_seq_new(1, arena); if (!stmts) goto error;

@@ -568,8 +569,8 @@ ast_error(child, "assignment to None"); return NULL; }

@@ -662,7 +663,8 @@ goto error; } name = Name(NEW_IDENTIFIER(CHILD(ch, 0)),

@@ -754,7 +756,8 @@ name_expr = NULL; } else if (NCH(n) == 5) { /* Call with no arguments */ - d = Call(name_expr, NULL, NULL, NULL, NULL, LINENO(n), n->n_col_offset, c->c_arena); + d = Call(name_expr, NULL, NULL, NULL, NULL, LINENO(n),

}

static expr_ty @@ -872,7 +876,8 @@ orelse = ast_for_expr(c, CHILD(n, 4)); if (!orelse) return NULL;

}

/* Count the number of 'for' loop in a list comprehension. @@ -983,7 +988,8 @@ lc = comprehension(asdl_seq_GET(t, 0), expression, NULL, c->c_arena); else - lc = comprehension(Tuple(t, Store, LINENO(ch), ch->n_col_offset, c->c_arena), + lc = comprehension(Tuple(t, Store, LINENO(ch), ch->n_col_offset,

@@ -1128,7 +1134,8 @@ ge = comprehension(asdl_seq_GET(t, 0), expression, NULL, c->c_arena); else

@@ -1372,7 +1379,8 @@ if (!operator) return NULL;

@@ -1390,7 +1398,8 @@ return NULL;

             tmp_result = BinOp(result, operator, tmp, 

@@ -1408,7 +1417,8 @@ REQ(n, trailer); if (TYPE(CHILD(n, 0)) == LPAR) { if (NCH(n) == 2)

@@ -1565,7 +1576,8 @@ asdl_seq_SET(seq, i / 2, e); } if (!strcmp(STR(CHILD(n, 1)), "and"))

@@ -1578,7 +1590,8 @@ if (!expression) return NULL;

@@ -1617,7 +1630,8 @@ return NULL; }

@@ -2623,7 +2637,8 @@ if (!suite_seq) return NULL;

}

static excepthandler_ty @@ -2638,7 +2653,8 @@ if (!suite_seq) return NULL;

@@ -2651,7 +2667,8 @@ if (!suite_seq) return NULL;

@@ -2668,7 +2685,8 @@ if (!suite_seq) return NULL;

@@ -2737,7 +2755,8 @@ asdl_seq_SET(handlers, i, e); }

@@ -2812,16 +2831,16 @@ s = ast_for_suite(c, CHILD(n, 3)); if (!s) return NULL; - return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, s, LINENO(n), n->n_col_offset,

@@ -2832,8 +2851,8 @@ s = ast_for_suite(c, CHILD(n, 6)); if (!s) return NULL;

}

static stmt_ty @@ -3105,7 +3124,8 @@ #ifndef Py_USING_UNICODE /* This should not happen - we never see any other encoding. */ - Py_FatalError("cannot deal with encodings in this build."); + Py_FatalError(

#else PyObject *v, *u = PyUnicode_DecodeUTF8(s, len, NULL); if (u == NULL)



More information about the Python-checkins mailing list