summaryrefslogtreecommitdiffstats
path: root/Python/ast.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-05-09 16:14:21 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-05-09 16:14:21 (GMT)
commit7f14f0d8a0228c50d5b5de2acbfe9a64ebc6749a (patch)
treed25489e9531c01f1e9244012bbfaa929f382883e /Python/ast.c
parentb7d943625cf4353f6cb72df16252759f2dbd8e06 (diff)
downloadcpython-7f14f0d8a0228c50d5b5de2acbfe9a64ebc6749a.zip
cpython-7f14f0d8a0228c50d5b5de2acbfe9a64ebc6749a.tar.gz
cpython-7f14f0d8a0228c50d5b5de2acbfe9a64ebc6749a.tar.bz2
Recorded merge of revisions 81032 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r81032 | antoine.pitrou | 2010-05-09 17:52:27 +0200 (dim., 09 mai 2010) | 9 lines Recorded merge of revisions 81029 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r81029 | antoine.pitrou | 2010-05-09 16:46:46 +0200 (dim., 09 mai 2010) | 3 lines Untabify C files. Will watch buildbots. ........ ................
Diffstat (limited to 'Python/ast.c')
-rw-r--r--Python/ast.c188
1 files changed, 94 insertions, 94 deletions
diff --git a/Python/ast.c b/Python/ast.c
index 2a806af..b8cb565 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -58,19 +58,19 @@ new_identifier(const char* n, PyArena *arena)
/* Check whether there are non-ASCII characters in the
identifier; if so, normalize to NFKC. */
for (; *u; u++) {
- if (*u >= 128) {
- PyObject *m = PyImport_ImportModuleNoBlock("unicodedata");
- PyObject *id2;
- if (!m)
- return NULL;
- id2 = PyObject_CallMethod(m, "normalize", "sO", "NFKC", id);
- Py_DECREF(m);
- if (!id2)
- return NULL;
- Py_DECREF(id);
- id = id2;
- break;
- }
+ if (*u >= 128) {
+ PyObject *m = PyImport_ImportModuleNoBlock("unicodedata");
+ PyObject *id2;
+ if (!m)
+ return NULL;
+ id2 = PyObject_CallMethod(m, "normalize", "sO", "NFKC", id);
+ Py_DECREF(m);
+ if (!id2)
+ return NULL;
+ Py_DECREF(id);
+ id = id2;
+ break;
+ }
}
PyUnicode_InternInPlace(&id);
PyArena_AddPyObject(arena, id);
@@ -226,7 +226,7 @@ PyAST_FromNode(const node *n, PyCompilerFlags *flags, const char *filename,
c.c_encoding = STR(n);
n = CHILD(n, 0);
} else {
- /* PEP 3120 */
+ /* PEP 3120 */
c.c_encoding = "utf-8";
}
c.c_arena = arena;
@@ -424,7 +424,7 @@ set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n)
s = e->v.List.elts;
break;
case Tuple_kind:
- if (asdl_seq_LEN(e->v.Tuple.elts) == 0)
+ if (asdl_seq_LEN(e->v.Tuple.elts) == 0)
return ast_error(n, "can't assign to ()");
e->v.Tuple.ctx = ctx;
s = e->v.Tuple.elts;
@@ -471,8 +471,8 @@ set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n)
expr_name = "conditional expression";
break;
default:
- PyErr_Format(PyExc_SystemError,
- "unexpected expression in assignment %d (line %d)",
+ PyErr_Format(PyExc_SystemError,
+ "unexpected expression in assignment %d (line %d)",
e->kind, e->lineno);
return 0;
}
@@ -487,7 +487,7 @@ set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n)
}
/* If the LHS is a list or tuple, we need to set the assignment
- context for all the contained elements.
+ context for all the contained elements.
*/
if (s) {
int i;
@@ -709,7 +709,7 @@ handle_keywordonly_args(struct compiling *c, const node *n, int start,
}
return i;
error:
- return -1;
+ return -1;
}
/* Create AST for argument list. */
@@ -722,12 +722,12 @@ ast_for_arguments(struct compiling *c, const node *n)
parameters: '(' [typedargslist] ')'
typedargslist: ((tfpdef ['=' test] ',')*
- ('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef]
+ ('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef]
| '**' tfpdef)
| tfpdef ['=' test] (',' tfpdef ['=' test])* [','])
tfpdef: NAME [':' test]
varargslist: ((vfpdef ['=' test] ',')*
- ('*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef]
+ ('*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef]
| '**' vfpdef)
| vfpdef ['=' test] (',' vfpdef ['=' test])* [','])
vfpdef: NAME
@@ -768,7 +768,7 @@ ast_for_arguments(struct compiling *c, const node *n)
if (TYPE(ch) == vfpdef || TYPE(ch) == tfpdef) nposargs++;
if (TYPE(ch) == EQUAL) nposdefaults++;
}
- /* count the number of keyword only args &
+ /* count the number of keyword only args &
defaults for keyword only args */
for ( ; i < NCH(n); ++i) {
ch = CHILD(n, i);
@@ -782,11 +782,11 @@ ast_for_arguments(struct compiling *c, const node *n)
asdl_seq_new(nkwonlyargs, c->c_arena) : NULL);
if (!kwonlyargs && nkwonlyargs)
goto error;
- posdefaults = (nposdefaults ?
+ posdefaults = (nposdefaults ?
asdl_seq_new(nposdefaults, c->c_arena) : NULL);
if (!posdefaults && nposdefaults)
goto error;
- /* The length of kwonlyargs and kwdefaults are same
+ /* The length of kwonlyargs and kwdefaults are same
since we set NULL as default for keyword only argument w/o default
- we have sequence data structure, but no dictionary */
kwdefaults = (nkwonlyargs ?
@@ -823,7 +823,7 @@ ast_for_arguments(struct compiling *c, const node *n)
found_default = 1;
}
else if (found_default) {
- ast_error(n,
+ ast_error(n,
"non-default argument follows default argument");
goto error;
}
@@ -835,7 +835,7 @@ ast_for_arguments(struct compiling *c, const node *n)
break;
case STAR:
if (i+1 >= NCH(n)) {
- ast_error(CHILD(n, i),
+ ast_error(CHILD(n, i),
"named arguments must follow bare *");
goto error;
}
@@ -932,15 +932,15 @@ ast_for_decorator(struct compiling *c, const node *n)
/* decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE */
expr_ty d = NULL;
expr_ty name_expr;
-
+
REQ(n, decorator);
REQ(CHILD(n, 0), AT);
REQ(RCHILD(n, -1), NEWLINE);
-
+
name_expr = ast_for_dotted_name(c, CHILD(n, 1));
if (!name_expr)
return NULL;
-
+
if (NCH(n) == 3) { /* No arguments */
d = name_expr;
name_expr = NULL;
@@ -968,12 +968,12 @@ ast_for_decorators(struct compiling *c, const node *n)
asdl_seq* decorator_seq;
expr_ty d;
int i;
-
+
REQ(n, decorators);
decorator_seq = asdl_seq_new(NCH(n), c->c_arena);
if (!decorator_seq)
return NULL;
-
+
for (i = 0; i < NCH(n); i++) {
d = ast_for_decorator(c, CHILD(n, i));
if (!d)
@@ -1029,7 +1029,7 @@ ast_for_decorated(struct compiling *c, const node *n)
return NULL;
assert(TYPE(CHILD(n, 1)) == funcdef ||
- TYPE(CHILD(n, 1)) == classdef);
+ TYPE(CHILD(n, 1)) == classdef);
if (TYPE(CHILD(n, 1)) == funcdef) {
thing = ast_for_funcdef(c, CHILD(n, 1), decorator_seq);
@@ -1077,7 +1077,7 @@ ast_for_lambdef(struct compiling *c, const node *n)
static expr_ty
ast_for_ifexpr(struct compiling *c, const node *n)
{
- /* test: or_test 'if' or_test 'else' test */
+ /* test: or_test 'if' or_test 'else' test */
expr_ty expression, body, orelse;
assert(NCH(n) == 5);
@@ -1174,9 +1174,9 @@ ast_for_comprehension(struct compiling *c, const node *n)
asdl_seq *t;
expr_ty expression;
node *for_ch;
-
+
REQ(n, comp_for);
-
+
for_ch = CHILD(n, 1);
t = ast_for_exprlist(c, for_ch, Store);
if (!t)
@@ -1201,7 +1201,7 @@ ast_for_comprehension(struct compiling *c, const node *n)
if (NCH(n) == 5) {
int j, n_ifs;
asdl_seq *ifs;
-
+
n = CHILD(n, 4);
n_ifs = count_comp_ifs(c, n);
if (n_ifs == -1)
@@ -1215,7 +1215,7 @@ ast_for_comprehension(struct compiling *c, const node *n)
REQ(n, comp_iter);
n = CHILD(n, 0);
REQ(n, comp_if);
-
+
expression = ast_for_expr(c, CHILD(n, 1));
if (!expression)
return NULL;
@@ -1240,13 +1240,13 @@ ast_for_itercomp(struct compiling *c, const node *n, int type)
argument: [test '='] test [comp_for] # Really [keyword '='] test */
expr_ty elt;
asdl_seq *comps;
-
+
assert(NCH(n) > 1);
-
+
elt = ast_for_expr(c, CHILD(n, 0));
if (!elt)
return NULL;
-
+
comps = ast_for_comprehension(c, CHILD(n, 1));
if (!comps)
return NULL;
@@ -1267,10 +1267,10 @@ ast_for_dictcomp(struct compiling *c, const node *n)
{
expr_ty key, value;
asdl_seq *comps;
-
+
assert(NCH(n) > 3);
REQ(CHILD(n, 1), COLON);
-
+
key = ast_for_expr(c, CHILD(n, 0));
if (!key)
return NULL;
@@ -1278,11 +1278,11 @@ ast_for_dictcomp(struct compiling *c, const node *n)
value = ast_for_expr(c, CHILD(n, 2));
if (!value)
return NULL;
-
+
comps = ast_for_comprehension(c, CHILD(n, 3));
if (!comps)
return NULL;
-
+
return DictComp(key, value, comps, LINENO(n), n->n_col_offset, c->c_arena);
}
@@ -1317,7 +1317,7 @@ ast_for_atom(struct compiling *c, const node *n)
*/
node *ch = CHILD(n, 0);
int bytesmode = 0;
-
+
switch (TYPE(ch)) {
case NAME: {
/* All names start in Load context, but may later be
@@ -1368,24 +1368,24 @@ ast_for_atom(struct compiling *c, const node *n)
return Ellipsis(LINENO(n), n->n_col_offset, c->c_arena);
case LPAR: /* some parenthesized expressions */
ch = CHILD(n, 1);
-
+
if (TYPE(ch) == RPAR)
return Tuple(NULL, Load, LINENO(n), n->n_col_offset, c->c_arena);
-
+
if (TYPE(ch) == yield_expr)
return ast_for_expr(c, ch);
- /* testlist_comp: test ( comp_for | (',' test)* [','] ) */
+ /* testlist_comp: test ( comp_for | (',' test)* [','] ) */
if ((NCH(ch) > 1) && (TYPE(CHILD(ch, 1)) == comp_for))
return ast_for_genexp(c, ch);
-
+
return ast_for_testlist(c, ch);
case LSQB: /* list (or list comprehension) */
ch = CHILD(n, 1);
-
+
if (TYPE(ch) == RSQB)
return List(NULL, Load, LINENO(n), n->n_col_offset, c->c_arena);
-
+
REQ(ch, testlist_comp);
if (NCH(ch) == 1 || TYPE(CHILD(ch, 1)) == COMMA) {
asdl_seq *elts = seq_for_testlist(c, ch);
@@ -1432,14 +1432,14 @@ ast_for_atom(struct compiling *c, const node *n)
keys = asdl_seq_new(size, c->c_arena);
if (!keys)
return NULL;
-
+
values = asdl_seq_new(size, c->c_arena);
if (!values)
return NULL;
-
+
for (i = 0; i < NCH(ch); i += 4) {
expr_ty expression;
-
+
expression = ast_for_expr(c, CHILD(ch, i));
if (!expression)
return NULL;
@@ -1477,10 +1477,10 @@ ast_for_slice(struct compiling *c, const node *n)
if (NCH(n) == 1 && TYPE(ch) == test) {
/* 'step' variable hold no significance in terms of being used over
other vars */
- step = ast_for_expr(c, ch);
+ step = ast_for_expr(c, ch);
if (!step)
return NULL;
-
+
return Index(step, c->c_arena);
}
@@ -1537,7 +1537,7 @@ static expr_ty
ast_for_binop(struct compiling *c, const node *n)
{
/* Must account for a sequence of expressions.
- How should A op B op C by represented?
+ How should A op B op C by represented?
BinOp(BinOp(A, op, B), op, C).
*/
@@ -1575,10 +1575,10 @@ ast_for_binop(struct compiling *c, const node *n)
if (!tmp)
return NULL;
- tmp_result = BinOp(result, newoperator, tmp,
+ tmp_result = BinOp(result, newoperator, tmp,
LINENO(next_oper), next_oper->n_col_offset,
c->c_arena);
- if (!tmp_result)
+ if (!tmp_result)
return NULL;
result = tmp_result;
}
@@ -1588,7 +1588,7 @@ ast_for_binop(struct compiling *c, const node *n)
static expr_ty
ast_for_trailer(struct compiling *c, const node *n, expr_ty left_expr)
{
- /* trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
+ /* trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
subscriptlist: subscript (',' subscript)* [',']
subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop]
*/
@@ -1619,7 +1619,7 @@ ast_for_trailer(struct compiling *c, const node *n, expr_ty left_expr)
c->c_arena);
}
else {
- /* The grammar is ambiguous here. The ambiguity is resolved
+ /* The grammar is ambiguous here. The ambiguity is resolved
by treating the sequence as a tuple literal if there are
no slice features.
*/
@@ -1772,7 +1772,7 @@ ast_for_expr(struct compiling *c, const node *n)
/* handle the full range of simple expressions
test: or_test ['if' or_test 'else' test] | lambdef
test_nocond: or_test | lambdef_nocond
- or_test: and_test ('or' and_test)*
+ or_test: and_test ('or' and_test)*
and_test: not_test ('and' not_test)*
not_test: 'not' not_test | comparison
comparison: expr (comp_op expr)*
@@ -1860,7 +1860,7 @@ ast_for_expr(struct compiling *c, const node *n)
if (!expression) {
return NULL;
}
-
+
asdl_seq_SET(ops, i / 2, newoperator);
asdl_seq_SET(cmps, i / 2, expression);
}
@@ -1868,7 +1868,7 @@ ast_for_expr(struct compiling *c, const node *n)
if (!expression) {
return NULL;
}
-
+
return Compare(expression, ops, cmps, LINENO(n),
n->n_col_offset, c->c_arena);
}
@@ -1987,7 +1987,7 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
if (!e)
return NULL;
asdl_seq_SET(args, nargs++, e);
- }
+ }
else if (TYPE(CHILD(ch, 1)) == comp_for) {
e = ast_for_genexp(c, ch);
if (!e)
@@ -1999,7 +1999,7 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
identifier key, tmp;
int k;
- /* CHILD(ch, 0) is test, but must be an identifier? */
+ /* CHILD(ch, 0) is test, but must be an identifier? */
e = ast_for_expr(c, CHILD(ch, 0));
if (!e)
return NULL;
@@ -2015,8 +2015,8 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
ast_error(CHILD(ch, 0), "keyword can't be an expression");
return NULL;
} else if (forbidden_name(e, ch)) {
- return NULL;
- }
+ return NULL;
+ }
key = e->v.Name.id;
for (k = 0; k < nkeywords; k++) {
tmp = ((keyword_ty)asdl_seq_GET(keywords, k))->arg;
@@ -2080,7 +2080,7 @@ static stmt_ty
ast_for_expr_stmt(struct compiling *c, const node *n)
{
REQ(n, expr_stmt);
- /* expr_stmt: testlist (augassign (yield_expr|testlist)
+ /* expr_stmt: testlist (augassign (yield_expr|testlist)
| ('=' (yield_expr|testlist))*)
testlist: test (',' test)* [',']
augassign: '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^='
@@ -2154,7 +2154,7 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
e = ast_for_testlist(c, ch);
/* set context to assign */
- if (!e)
+ if (!e)
return NULL;
if (!set_context(c, e, Store, CHILD(n, i)))
@@ -2200,7 +2200,7 @@ static stmt_ty
ast_for_del_stmt(struct compiling *c, const node *n)
{
asdl_seq *expr_list;
-
+
/* del_stmt: 'del' exprlist */
REQ(n, del_stmt);
@@ -2323,7 +2323,7 @@ alias_for_import_name(struct compiling *c, const node *n)
int i;
size_t len;
char *s;
- PyObject *uni;
+ PyObject *uni;
len = 0;
for (i = 0; i < NCH(n); i += 2)
@@ -2344,13 +2344,13 @@ alias_for_import_name(struct compiling *c, const node *n)
}
--s;
*s = '\0';
- uni = PyUnicode_DecodeUTF8(PyBytes_AS_STRING(str),
- PyBytes_GET_SIZE(str),
- NULL);
- Py_DECREF(str);
- if (!uni)
- return NULL;
- str = uni;
+ uni = PyUnicode_DecodeUTF8(PyBytes_AS_STRING(str),
+ PyBytes_GET_SIZE(str),
+ NULL);
+ Py_DECREF(str);
+ if (!uni)
+ return NULL;
+ str = uni;
PyUnicode_InternInPlace(&str);
PyArena_AddPyObject(c->c_arena, str);
return alias(str, NULL, c->c_arena);
@@ -2407,7 +2407,7 @@ ast_for_import_stmt(struct compiling *c, const node *n)
int idx, ndots = 0;
alias_ty mod = NULL;
identifier modname;
-
+
/* Count the number of dots (for relative imports) and check for the
optional module name */
for (idx = 1; idx < NCH(n); idx++) {
@@ -2416,7 +2416,7 @@ ast_for_import_stmt(struct compiling *c, const node *n)
idx++;
break;
} else if (TYPE(CHILD(n, idx)) == ELLIPSIS) {
- /* three consecutive dots are tokenized as one ELLIPSIS */
+ /* three consecutive dots are tokenized as one ELLIPSIS */
ndots += 3;
continue;
} else if (TYPE(CHILD(n, idx)) != DOT) {
@@ -2545,7 +2545,7 @@ ast_for_assert_stmt(struct compiling *c, const node *n)
expr2 = ast_for_expr(c, CHILD(n, 3));
if (!expr2)
return NULL;
-
+
return Assert(expr1, expr2, LINENO(n), n->n_col_offset, c->c_arena);
}
PyErr_Format(PyExc_SystemError,
@@ -2572,7 +2572,7 @@ ast_for_suite(struct compiling *c, const node *n)
if (TYPE(CHILD(n, 0)) == simple_stmt) {
n = CHILD(n, 0);
/* simple_stmt always ends with a NEWLINE,
- and may have a trailing SEMI
+ and may have a trailing SEMI
*/
end = NCH(n) - 1;
if (TYPE(CHILD(n, end - 1)) == SEMI)
@@ -2637,10 +2637,10 @@ ast_for_if_stmt(struct compiling *c, const node *n)
expression = ast_for_expr(c, CHILD(n, 1));
if (!expression)
return NULL;
- suite_seq = ast_for_suite(c, CHILD(n, 3));
+ suite_seq = ast_for_suite(c, CHILD(n, 3));
if (!suite_seq)
return NULL;
-
+
return If(expression, suite_seq, NULL, LINENO(n), n->n_col_offset,
c->c_arena);
}
@@ -2698,8 +2698,8 @@ ast_for_if_stmt(struct compiling *c, const node *n)
if (!suite_seq2)
return NULL;
- asdl_seq_SET(orelse, 0,
- If(expression, suite_seq, suite_seq2,
+ asdl_seq_SET(orelse, 0,
+ If(expression, suite_seq, suite_seq2,
LINENO(CHILD(n, NCH(n) - 6)),
CHILD(n, NCH(n) - 6)->n_col_offset,
c->c_arena));
@@ -2720,7 +2720,7 @@ ast_for_if_stmt(struct compiling *c, const node *n)
return NULL;
asdl_seq_SET(newobj, 0,
- If(expression, suite_seq, orelse,
+ If(expression, suite_seq, orelse,
LINENO(CHILD(n, off)),
CHILD(n, off)->n_col_offset, c->c_arena));
orelse = newobj;
@@ -2914,7 +2914,7 @@ ast_for_try_stmt(struct compiling *c, const node *n)
ast_error(n, "malformed 'try' statement");
return NULL;
}
-
+
if (n_except > 0) {
int i;
stmt_ty except_st;
@@ -3125,8 +3125,8 @@ ast_for_stmt(struct compiling *c, const node *n)
return ast_for_funcdef(c, ch, NULL);
case classdef:
return ast_for_classdef(c, ch, NULL);
- case decorated:
- return ast_for_decorated(c, ch);
+ case decorated:
+ return ast_for_decorated(c, ch);
default:
PyErr_Format(PyExc_SystemError,
"unhandled small_stmt: TYPE=%d NCH=%d\n",
@@ -3288,7 +3288,7 @@ parsestr(struct compiling *c, const node *n, int *bytesmode)
if (quote == 'b' || quote == 'B') {
quote = *++s;
*bytesmode = 1;
- }
+ }
if (quote == 'r' || quote == 'R') {
quote = *++s;
rawmode = 1;
@@ -3301,7 +3301,7 @@ parsestr(struct compiling *c, const node *n, int *bytesmode)
s++;
len = strlen(s);
if (len > INT_MAX) {
- PyErr_SetString(PyExc_OverflowError,
+ PyErr_SetString(PyExc_OverflowError,
"string to parse is too long");
return NULL;
}
@@ -3345,7 +3345,7 @@ parsestr(struct compiling *c, const node *n, int *bytesmode)
return PyBytes_FromStringAndSize(s, len);
} else if (strcmp(c->c_encoding, "utf-8") == 0) {
return PyUnicode_FromStringAndSize(s, len);
- } else {
+ } else {
return PyUnicode_DecodeLatin1(s, len, NULL);
}
}