Clean up formatting of this file.

The file should now follow PEP 7, except that it uses 4 space indents
(in the style of Py3k).  This particular code would be really hard to
read with the regular tab idents.

Other changes:
 - reflow long lines
 - change multi-line conditionals to have test at end of line
This commit is contained in:
Jeremy Hylton 2007-03-16 15:59:47 +00:00
parent 26ca925838
commit dd2cf1cb84

View file

@ -25,7 +25,8 @@ static asdl_seq *seq_for_testlist(struct compiling *, const node *);
static expr_ty ast_for_expr(struct compiling *, const node *); static expr_ty ast_for_expr(struct compiling *, const node *);
static stmt_ty ast_for_stmt(struct compiling *, const node *); static stmt_ty ast_for_stmt(struct compiling *, const node *);
static asdl_seq *ast_for_suite(struct compiling *, const node *); static asdl_seq *ast_for_suite(struct compiling *, const node *);
static asdl_seq *ast_for_exprlist(struct compiling *, const node *, expr_context_ty); static asdl_seq *ast_for_exprlist(struct compiling *, const node *,
expr_context_ty);
static expr_ty ast_for_testlist(struct compiling *, const node *); static expr_ty ast_for_testlist(struct compiling *, const node *);
static expr_ty ast_for_testlist_gexp(struct compiling *, const node *); static expr_ty ast_for_testlist_gexp(struct compiling *, const node *);
@ -528,12 +529,11 @@ seq_for_testlist(struct compiling *c, const node *n)
asdl_seq *seq; asdl_seq *seq;
expr_ty expression; expr_ty expression;
int i; int i;
assert(TYPE(n) == testlist assert(TYPE(n) == testlist ||
|| TYPE(n) == listmaker TYPE(n) == listmaker ||
|| TYPE(n) == testlist_gexp TYPE(n) == testlist_gexp ||
|| TYPE(n) == testlist_safe TYPE(n) == testlist_safe ||
|| TYPE(n) == testlist1 TYPE(n) == testlist1);
);
seq = asdl_seq_new((NCH(n) + 1) / 2, c->c_arena); seq = asdl_seq_new((NCH(n) + 1) / 2, c->c_arena);
if (!seq) if (!seq)
@ -582,7 +582,7 @@ set_name:
} }
else { else {
assert(TYPE(fpdef_node) == fpdef); assert(TYPE(fpdef_node) == fpdef);
/* fpdef_node[0] is not a name, so it must be a '(', get CHILD[1] */ /* fpdef_node[0] is not a name, so it must be '(', get CHILD[1] */
child = CHILD(fpdef_node, 1); child = CHILD(fpdef_node, 1);
assert(TYPE(child) == fplist); assert(TYPE(child) == fplist);
/* NCH == 1 means we have (x), we need to elide the extra parens */ /* NCH == 1 means we have (x), we need to elide the extra parens */
@ -1018,7 +1018,8 @@ ast_for_listcomp(struct compiling *c, const node *n)
return NULL; return NULL;
/* Check the # of children rather than the length of t, since /* Check the # of children rather than the length of t, since
[x for x, in ... ] has 1 element in t, but still requires a Tuple. */ [x for x, in ... ] has 1 element in t, but still requires a Tuple.
*/
if (NCH(for_ch) == 1) if (NCH(for_ch) == 1)
lc = comprehension((expr_ty)asdl_seq_GET(t, 0), expression, NULL, lc = comprehension((expr_ty)asdl_seq_GET(t, 0), expression, NULL,
c->c_arena); c->c_arena);
@ -1067,8 +1068,7 @@ ast_for_listcomp(struct compiling *c, const node *n)
return ListComp(elt, listcomps, LINENO(n), n->n_col_offset, c->c_arena); return ListComp(elt, listcomps, LINENO(n), n->n_col_offset, c->c_arena);
} }
/* /* Count the number of 'for' loops in a generator expression.
Count the number of 'for' loops in a generator expression.
Helper for ast_for_genexp(). Helper for ast_for_genexp().
*/ */
@ -1233,7 +1233,8 @@ ast_for_atom(struct compiling *c, const node *n)
case NAME: case NAME:
/* All names start in Load context, but may later be /* All names start in Load context, but may later be
changed. */ changed. */
return Name(NEW_IDENTIFIER(ch), Load, LINENO(n), n->n_col_offset, c->c_arena); return Name(NEW_IDENTIFIER(ch), Load, LINENO(n), n->n_col_offset,
c->c_arena);
case STRING: { case STRING: {
PyObject *str = parsestrplus(c, n); PyObject *str = parsestrplus(c, n);
if (!str) if (!str)
@ -1537,14 +1538,14 @@ ast_for_factor(struct compiling *c, const node *n)
(sys.maxint - 1). In that case, we want a PyIntObject, not a (sys.maxint - 1). In that case, we want a PyIntObject, not a
PyLongObject. PyLongObject.
*/ */
if (TYPE(CHILD(n, 0)) == MINUS if (TYPE(CHILD(n, 0)) == MINUS &&
&& NCH(n) == 2 NCH(n) == 2 &&
&& TYPE((pfactor = CHILD(n, 1))) == factor TYPE((pfactor = CHILD(n, 1))) == factor &&
&& NCH(pfactor) == 1 NCH(pfactor) == 1 &&
&& TYPE((ppower = CHILD(pfactor, 0))) == power TYPE((ppower = CHILD(pfactor, 0))) == power &&
&& NCH(ppower) == 1 NCH(ppower) == 1 &&
&& TYPE((patom = CHILD(ppower, 0))) == atom TYPE((patom = CHILD(ppower, 0))) == atom &&
&& TYPE((pnum = CHILD(patom, 0))) == NUMBER) { TYPE((pnum = CHILD(patom, 0))) == NUMBER) {
char *s = PyObject_MALLOC(strlen(STR(pnum)) + 2); char *s = PyObject_MALLOC(strlen(STR(pnum)) + 2);
if (s == NULL) if (s == NULL)
return NULL; return NULL;
@ -1854,7 +1855,8 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
* then is very confusing. * then is very confusing.
*/ */
if (e->kind == Lambda_kind) { if (e->kind == Lambda_kind) {
ast_error(CHILD(ch, 0), "lambda cannot contain assignment"); ast_error(CHILD(ch, 0),
"lambda cannot contain assignment");
return NULL; return NULL;
} else if (e->kind != Name_kind) { } else if (e->kind != Name_kind) {
ast_error(CHILD(ch, 0), "keyword can't be an expression"); ast_error(CHILD(ch, 0), "keyword can't be an expression");
@ -1880,7 +1882,8 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
} }
} }
return Call(func, args, keywords, vararg, kwarg, func->lineno, func->col_offset, c->c_arena); return Call(func, args, keywords, vararg, kwarg, func->lineno,
func->col_offset, c->c_arena);
} }
static expr_ty static expr_ty
@ -2011,7 +2014,8 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
if (!newoperator) if (!newoperator)
return NULL; return NULL;
return AugAssign(expr1, newoperator, expr2, LINENO(n), n->n_col_offset, c->c_arena); return AugAssign(expr1, newoperator, expr2, LINENO(n), n->n_col_offset,
c->c_arena);
} }
else { else {
int i; int i;
@ -2049,7 +2053,8 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
expression = ast_for_expr(c, value); expression = ast_for_expr(c, value);
if (!expression) if (!expression)
return NULL; return NULL;
return Assign(targets, expression, LINENO(n), n->n_col_offset, c->c_arena); return Assign(targets, expression, LINENO(n), n->n_col_offset,
c->c_arena);
} }
} }
@ -2156,16 +2161,19 @@ ast_for_flow_stmt(struct compiling *c, const node *n)
expr_ty expression = ast_for_testlist(c, CHILD(ch, 1)); expr_ty expression = ast_for_testlist(c, CHILD(ch, 1));
if (!expression) if (!expression)
return NULL; return NULL;
return Return(expression, LINENO(n), n->n_col_offset, c->c_arena); return Return(expression, LINENO(n), n->n_col_offset,
c->c_arena);
} }
case raise_stmt: case raise_stmt:
if (NCH(ch) == 1) if (NCH(ch) == 1)
return Raise(NULL, NULL, NULL, LINENO(n), n->n_col_offset, c->c_arena); return Raise(NULL, NULL, NULL, LINENO(n), n->n_col_offset,
c->c_arena);
else if (NCH(ch) == 2) { else if (NCH(ch) == 2) {
expr_ty expression = ast_for_expr(c, CHILD(ch, 1)); expr_ty expression = ast_for_expr(c, CHILD(ch, 1));
if (!expression) if (!expression)
return NULL; return NULL;
return Raise(expression, NULL, NULL, LINENO(n), n->n_col_offset, c->c_arena); return Raise(expression, NULL, NULL, LINENO(n),
n->n_col_offset, c->c_arena);
} }
else if (NCH(ch) == 4) { else if (NCH(ch) == 4) {
expr_ty expr1, expr2; expr_ty expr1, expr2;
@ -2177,7 +2185,8 @@ ast_for_flow_stmt(struct compiling *c, const node *n)
if (!expr2) if (!expr2)
return NULL; return NULL;
return Raise(expr1, expr2, NULL, LINENO(n), n->n_col_offset, c->c_arena); return Raise(expr1, expr2, NULL, LINENO(n), n->n_col_offset,
c->c_arena);
} }
else if (NCH(ch) == 6) { else if (NCH(ch) == 6) {
expr_ty expr1, expr2, expr3; expr_ty expr1, expr2, expr3;
@ -2192,7 +2201,8 @@ ast_for_flow_stmt(struct compiling *c, const node *n)
if (!expr3) if (!expr3)
return NULL; return NULL;
return Raise(expr1, expr2, expr3, LINENO(n), n->n_col_offset, c->c_arena); return Raise(expr1, expr2, expr3, LINENO(n), n->n_col_offset,
c->c_arena);
} }
default: default:
PyErr_Format(PyExc_SystemError, PyErr_Format(PyExc_SystemError,
@ -2445,7 +2455,8 @@ ast_for_exec_stmt(struct compiling *c, const node *n)
return NULL; return NULL;
} }
return Exec(expr1, globals, locals, LINENO(n), n->n_col_offset, c->c_arena); return Exec(expr1, globals, locals, LINENO(n), n->n_col_offset,
c->c_arena);
} }
static stmt_ty static stmt_ty
@ -2457,7 +2468,8 @@ ast_for_assert_stmt(struct compiling *c, const node *n)
expr_ty expression = ast_for_expr(c, CHILD(n, 1)); expr_ty expression = ast_for_expr(c, CHILD(n, 1));
if (!expression) if (!expression)
return NULL; return NULL;
return Assert(expression, NULL, LINENO(n), n->n_col_offset, c->c_arena); return Assert(expression, NULL, LINENO(n), n->n_col_offset,
c->c_arena);
} }
else if (NCH(n) == 4) { else if (NCH(n) == 4) {
expr_ty expr1, expr2; expr_ty expr1, expr2;
@ -2564,7 +2576,8 @@ ast_for_if_stmt(struct compiling *c, const node *n)
if (!suite_seq) if (!suite_seq)
return NULL; return NULL;
return If(expression, suite_seq, NULL, LINENO(n), n->n_col_offset, c->c_arena); return If(expression, suite_seq, NULL, LINENO(n), n->n_col_offset,
c->c_arena);
} }
s = STR(CHILD(n, 4)); s = STR(CHILD(n, 4));
@ -2586,7 +2599,8 @@ ast_for_if_stmt(struct compiling *c, const node *n)
if (!seq2) if (!seq2)
return NULL; return NULL;
return If(expression, seq1, seq2, LINENO(n), n->n_col_offset, c->c_arena); return If(expression, seq1, seq2, LINENO(n), n->n_col_offset,
c->c_arena);
} }
else if (s[2] == 'i') { else if (s[2] == 'i') {
int i, n_elif, has_else = 0; int i, n_elif, has_else = 0;
@ -2619,8 +2633,10 @@ ast_for_if_stmt(struct compiling *c, const node *n)
if (!suite_seq2) if (!suite_seq2)
return NULL; return NULL;
asdl_seq_SET(orelse, 0, If(expression, suite_seq, suite_seq2, asdl_seq_SET(orelse, 0,
LINENO(CHILD(n, NCH(n) - 6)), CHILD(n, NCH(n) - 6)->n_col_offset, If(expression, suite_seq, suite_seq2,
LINENO(CHILD(n, NCH(n) - 6)),
CHILD(n, NCH(n) - 6)->n_col_offset,
c->c_arena)); c->c_arena));
/* the just-created orelse handled the last elif */ /* the just-created orelse handled the last elif */
n_elif--; n_elif--;
@ -2640,7 +2656,8 @@ ast_for_if_stmt(struct compiling *c, const node *n)
asdl_seq_SET(newobj, 0, 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)); LINENO(CHILD(n, off)),
CHILD(n, off)->n_col_offset, c->c_arena));
orelse = newobj; orelse = newobj;
} }
expression = ast_for_expr(c, CHILD(n, 1)); expression = ast_for_expr(c, CHILD(n, 1));
@ -2674,7 +2691,8 @@ ast_for_while_stmt(struct compiling *c, const node *n)
suite_seq = ast_for_suite(c, CHILD(n, 3)); suite_seq = ast_for_suite(c, CHILD(n, 3));
if (!suite_seq) if (!suite_seq)
return NULL; return NULL;
return While(expression, suite_seq, NULL, LINENO(n), n->n_col_offset, c->c_arena); return While(expression, suite_seq, NULL, LINENO(n), n->n_col_offset,
c->c_arena);
} }
else if (NCH(n) == 7) { else if (NCH(n) == 7) {
expr_ty expression; expr_ty expression;
@ -2690,7 +2708,8 @@ ast_for_while_stmt(struct compiling *c, const node *n)
if (!seq2) if (!seq2)
return NULL; return NULL;
return While(expression, seq1, seq2, LINENO(n), n->n_col_offset, c->c_arena); return While(expression, seq1, seq2, LINENO(n), n->n_col_offset,
c->c_arena);
} }
PyErr_Format(PyExc_SystemError, PyErr_Format(PyExc_SystemError,