Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Python/ast.c

    r2 r391  
    3232static expr_ty ast_for_testlist(struct compiling *, const node *);
    3333static stmt_ty ast_for_classdef(struct compiling *, const node *, asdl_seq *);
    34 static expr_ty ast_for_testlist_gexp(struct compiling *, const node *);
     34static expr_ty ast_for_testlist_comp(struct compiling *, const node *);
    3535
    3636/* Note different signature for ast_for_call */
     
    4444#define LINENO(n)       ((n)->n_lineno)
    4545#endif
     46
     47#define COMP_GENEXP 0
     48#define COMP_SETCOMP  1
    4649
    4750static identifier
     
    132135{
    133136    if (!strcmp(x, "None"))
    134         return ast_error(n, "assignment to None");
    135     if (Py_Py3kWarningFlag && !(strcmp(x, "True") && strcmp(x, "False")) &&
    136         !ast_warn(c, n, "assignment to True or False is forbidden in 3.x"))
    137         return 0;
     137        return ast_error(n, "cannot assign to None");
     138    if (!strcmp(x, "__debug__"))
     139        return ast_error(n, "cannot assign to __debug__");
     140    if (Py_Py3kWarningFlag) {
     141        if (!(strcmp(x, "True") && strcmp(x, "False")) &&
     142            !ast_warn(c, n, "assignment to True or False is forbidden in 3.x"))
     143            return 0;
     144        if (!strcmp(x, "nonlocal") &&
     145            !ast_warn(c, n, "nonlocal is a keyword in 3.x"))
     146            return 0;
     147    }
    138148    return 1;
    139149}
     
    191201            char buf[128];
    192202
    193             sprintf(buf, "Non-statement found: %d %d\n",
     203            sprintf(buf, "Non-statement found: %d %d",
    194204                    TYPE(n), NCH(n));
    195205            Py_FatalError(buf);
     
    262272            expr_ty testlist_ast;
    263273
    264             /* XXX Why not gen_for here? */
     274            /* XXX Why not comp_for here? */
    265275            testlist_ast = ast_for_testlist(&c, CHILD(n, 0));
    266276            if (!testlist_ast)
     
    396406            break;
    397407        case Tuple_kind:
    398             if (asdl_seq_LEN(e->v.Tuple.elts) == 0)
    399                 return ast_error(n, "can't assign to ()");
    400             e->v.Tuple.ctx = ctx;
    401             s = e->v.Tuple.elts;
     408            if (asdl_seq_LEN(e->v.Tuple.elts))  {
     409                e->v.Tuple.ctx = ctx;
     410                s = e->v.Tuple.elts;
     411            }
     412            else {
     413                expr_name = "()";
     414            }
    402415            break;
    403416        case Lambda_kind:
     
    421434            expr_name = "list comprehension";
    422435            break;
     436        case SetComp_kind:
     437            expr_name = "set comprehension";
     438            break;
     439        case DictComp_kind:
     440            expr_name = "dict comprehension";
     441            break;
    423442        case Dict_kind:
     443        case Set_kind:
    424444        case Num_kind:
    425445        case Str_kind:
     
    436456            break;
    437457        default:
    438             PyErr_Format(PyExc_SystemError, 
    439                          "unexpected expression in assignment %d (line %d)", 
     458            PyErr_Format(PyExc_SystemError,
     459                         "unexpected expression in assignment %d (line %d)",
    440460                         e->kind, e->lineno);
    441461            return 0;
     
    452472
    453473    /* If the LHS is a list or tuple, we need to set the assignment
    454        context for all the contained elements. 
     474       context for all the contained elements.
    455475    */
    456476    if (s) {
     
    564584    assert(TYPE(n) == testlist ||
    565585           TYPE(n) == listmaker ||
    566            TYPE(n) == testlist_gexp ||
     586           TYPE(n) == testlist_comp ||
    567587           TYPE(n) == testlist_safe ||
    568588           TYPE(n) == testlist1);
     
    669689    args = (n_args ? asdl_seq_new(n_args, c->c_arena) : NULL);
    670690    if (!args && n_args)
    671         return NULL; /* Don't need to goto error; no objects allocated */
     691        return NULL;
    672692    defaults = (n_defaults ? asdl_seq_new(n_defaults, c->c_arena) : NULL);
    673693    if (!defaults && n_defaults)
    674         return NULL; /* Don't need to goto error; no objects allocated */
     694        return NULL;
    675695
    676696    /* fpdef: NAME | '(' fplist ')'
     
    692712                    expr_ty expression = ast_for_expr(c, CHILD(n, i + 2));
    693713                    if (!expression)
    694                         goto error;
     714                        return NULL;
    695715                    assert(defaults != NULL);
    696716                    asdl_seq_SET(defaults, j++, expression);
     
    703723                    if (parenthesized && !complex_args) {
    704724                        ast_error(n, "parenthesized arg with default");
    705                         goto error;
     725                        return NULL;
    706726                    }
    707                     ast_error(n, 
     727                    ast_error(n,
    708728                             "non-default argument follows default argument");
    709                     goto error;
     729                    return NULL;
    710730                }
    711731                if (NCH(ch) == 3) {
     
    716736                        if (Py_Py3kWarningFlag && !ast_warn(c, ch,
    717737                            "tuple parameter unpacking has been removed in 3.x"))
    718                             goto error;
     738                            return NULL;
    719739                        complex_args = 1;
    720740                        asdl_seq_SET(args, k++, compiler_complex_args(c, ch));
    721741                        if (!asdl_seq_GET(args, k-1))
    722                                 goto error;
     742                                return NULL;
    723743                    } else {
    724744                        /* def foo((x)): setup for checking NAME below. */
     
    735755                    expr_ty name;
    736756                    if (!forbidden_check(c, n, STR(CHILD(ch, 0))))
    737                         goto error;
     757                        return NULL;
    738758                    id = NEW_IDENTIFIER(CHILD(ch, 0));
    739759                    if (!id)
    740                         goto error;
     760                        return NULL;
    741761                    name = Name(id, Param, LINENO(ch), ch->n_col_offset,
    742762                                c->c_arena);
    743763                    if (!name)
    744                         goto error;
     764                        return NULL;
    745765                    asdl_seq_SET(args, k++, name);
    746                                          
     766
    747767                }
    748768                i += 2; /* the name and the comma */
     
    750770                    !ast_warn(c, ch, "parenthesized argument names "
    751771                              "are invalid in 3.x"))
    752                     goto error;
     772                    return NULL;
    753773
    754774                break;
     
    756776            case STAR:
    757777                if (!forbidden_check(c, CHILD(n, i+1), STR(CHILD(n, i+1))))
    758                     goto error;
     778                    return NULL;
    759779                vararg = NEW_IDENTIFIER(CHILD(n, i+1));
    760780                if (!vararg)
    761                     goto error;
     781                    return NULL;
    762782                i += 3;
    763783                break;
    764784            case DOUBLESTAR:
    765785                if (!forbidden_check(c, CHILD(n, i+1), STR(CHILD(n, i+1))))
    766                     goto error;
     786                    return NULL;
    767787                kwarg = NEW_IDENTIFIER(CHILD(n, i+1));
    768788                if (!kwarg)
    769                     goto error;
     789                    return NULL;
    770790                i += 3;
    771791                break;
     
    774794                             "unexpected node in varargslist: %d @ %d",
    775795                             TYPE(ch), i);
    776                 goto error;
     796                return NULL;
    777797        }
    778798    }
    779799
    780800    return arguments(args, vararg, kwarg, defaults, c->c_arena);
    781 
    782  error:
    783     Py_XDECREF(vararg);
    784     Py_XDECREF(kwarg);
    785     return NULL;
    786801}
    787802
     
    824839    expr_ty d = NULL;
    825840    expr_ty name_expr;
    826    
     841
    827842    REQ(n, decorator);
    828843    REQ(CHILD(n, 0), AT);
    829844    REQ(RCHILD(n, -1), NEWLINE);
    830    
     845
    831846    name_expr = ast_for_dotted_name(c, CHILD(n, 1));
    832847    if (!name_expr)
    833848        return NULL;
    834        
     849
    835850    if (NCH(n) == 3) { /* No arguments */
    836851        d = name_expr;
     
    860875    expr_ty d;
    861876    int i;
    862    
     877
    863878    REQ(n, decorators);
    864879    decorator_seq = asdl_seq_new(NCH(n), c->c_arena);
    865880    if (!decorator_seq)
    866881        return NULL;
    867        
     882
    868883    for (i = 0; i < NCH(n); i++) {
    869884        d = ast_for_decorator(c, CHILD(n, i));
    870             if (!d)
    871                 return NULL;
    872             asdl_seq_SET(decorator_seq, i, d);
     885        if (!d)
     886            return NULL;
     887        asdl_seq_SET(decorator_seq, i, d);
    873888    }
    874889    return decorator_seq;
     
    916931
    917932    assert(TYPE(CHILD(n, 1)) == funcdef ||
    918            TYPE(CHILD(n, 1)) == classdef);
     933           TYPE(CHILD(n, 1)) == classdef);
    919934
    920935    if (TYPE(CHILD(n, 1)) == funcdef) {
     
    962977ast_for_ifexpr(struct compiling *c, const node *n)
    963978{
    964     /* test: or_test 'if' or_test 'else' test */ 
     979    /* test: or_test 'if' or_test 'else' test */
    965980    expr_ty expression, body, orelse;
    966981
     
    10531068       testlist_safe: test [(',' test)+ [',']]
    10541069    */
    1055     expr_ty elt;
     1070    expr_ty elt, first;
    10561071    asdl_seq *listcomps;
    10571072    int i, n_fors;
     
    10791094        expr_ty expression;
    10801095        node *for_ch;
    1081        
     1096
    10821097        REQ(ch, list_for);
    1083        
     1098
    10841099        for_ch = CHILD(ch, 1);
    10851100        t = ast_for_exprlist(c, for_ch, Store);
     
    10891104        if (!expression)
    10901105            return NULL;
    1091        
     1106
    10921107        /* Check the # of children rather than the length of t, since
    10931108           [x for x, in ... ] has 1 element in t, but still requires a Tuple.
    10941109        */
     1110        first = (expr_ty)asdl_seq_GET(t, 0);
    10951111        if (NCH(for_ch) == 1)
    1096             lc = comprehension((expr_ty)asdl_seq_GET(t, 0), expression, NULL,
    1097                                c->c_arena);
     1112            lc = comprehension(first, expression, NULL, c->c_arena);
    10981113        else
    1099             lc = comprehension(Tuple(t, Store, LINENO(ch), ch->n_col_offset,
     1114            lc = comprehension(Tuple(t, Store, first->lineno, first->col_offset,
    11001115                                     c->c_arena),
    11011116                               expression, NULL, c->c_arena);
     
    11211136                ch = CHILD(ch, 0);
    11221137                REQ(ch, list_if);
    1123                
     1138
    11241139                list_for_expr = ast_for_expr(c, CHILD(ch, 1));
    11251140                if (!list_for_expr)
    11261141                    return NULL;
    1127                
     1142
    11281143                asdl_seq_SET(ifs, j, list_for_expr);
    11291144                if (NCH(ch) == 3)
     
    11411156}
    11421157
    1143 /* Count the number of 'for' loops in a generator expression.
    1144 
    1145    Helper for ast_for_genexp().
     1158/*
     1159   Count the number of 'for' loops in a comprehension.
     1160
     1161   Helper for ast_for_comprehension().
    11461162*/
    11471163
    11481164static int
    1149 count_gen_fors(struct compiling *c, const node *n)
     1165count_comp_fors(struct compiling *c, const node *n)
    11501166{
    11511167    int n_fors = 0;
    1152     node *ch = CHILD(n, 1);
    1153 
    1154  count_gen_for:
     1168
     1169  count_comp_for:
    11551170    n_fors++;
    1156     REQ(ch, gen_for);
    1157     if (NCH(ch) == 5)
    1158         ch = CHILD(ch, 4);
     1171    REQ(n, comp_for);
     1172    if (NCH(n) == 5)
     1173        n = CHILD(n, 4);
    11591174    else
    11601175        return n_fors;
    1161  count_gen_iter:
    1162     REQ(ch, gen_iter);
    1163     ch = CHILD(ch, 0);
    1164     if (TYPE(ch) == gen_for)
    1165         goto count_gen_for;
    1166     else if (TYPE(ch) == gen_if) {
    1167         if (NCH(ch) == 3) {
    1168             ch = CHILD(ch, 2);
    1169             goto count_gen_iter;
     1176  count_comp_iter:
     1177    REQ(n, comp_iter);
     1178    n = CHILD(n, 0);
     1179    if (TYPE(n) == comp_for)
     1180        goto count_comp_for;
     1181    else if (TYPE(n) == comp_if) {
     1182        if (NCH(n) == 3) {
     1183            n = CHILD(n, 2);
     1184            goto count_comp_iter;
    11701185        }
    11711186        else
    11721187            return n_fors;
    11731188    }
    1174    
     1189
    11751190    /* Should never be reached */
    11761191    PyErr_SetString(PyExc_SystemError,
    1177                     "logic error in count_gen_fors");
     1192                    "logic error in count_comp_fors");
    11781193    return -1;
    11791194}
    11801195
    1181 /* Count the number of 'if' statements in a generator expression.
    1182 
    1183    Helper for ast_for_genexp().
     1196/* Count the number of 'if' statements in a comprehension.
     1197
     1198   Helper for ast_for_comprehension().
    11841199*/
    11851200
    11861201static int
    1187 count_gen_ifs(struct compiling *c, const node *n)
     1202count_comp_ifs(struct compiling *c, const node *n)
    11881203{
    11891204    int n_ifs = 0;
    11901205
    11911206    while (1) {
    1192         REQ(n, gen_iter);
    1193         if (TYPE(CHILD(n, 0)) == gen_for)
     1207        REQ(n, comp_iter);
     1208        if (TYPE(CHILD(n, 0)) == comp_for)
    11941209            return n_ifs;
    11951210        n = CHILD(n, 0);
    1196         REQ(n, gen_if);
     1211        REQ(n, comp_if);
    11971212        n_ifs++;
    11981213        if (NCH(n) == 2)
     
    12021217}
    12031218
    1204 /* TODO(jhylton): Combine with list comprehension code? */
     1219static asdl_seq *
     1220ast_for_comprehension(struct compiling *c, const node *n)
     1221{
     1222    int i, n_fors;
     1223    asdl_seq *comps;
     1224
     1225    n_fors = count_comp_fors(c, n);
     1226    if (n_fors == -1)
     1227        return NULL;
     1228
     1229    comps = asdl_seq_new(n_fors, c->c_arena);
     1230    if (!comps)
     1231        return NULL;
     1232
     1233    for (i = 0; i < n_fors; i++) {
     1234        comprehension_ty comp;
     1235        asdl_seq *t;
     1236        expr_ty expression, first;
     1237        node *for_ch;
     1238
     1239        REQ(n, comp_for);
     1240
     1241        for_ch = CHILD(n, 1);
     1242        t = ast_for_exprlist(c, for_ch, Store);
     1243        if (!t)
     1244            return NULL;
     1245        expression = ast_for_expr(c, CHILD(n, 3));
     1246        if (!expression)
     1247            return NULL;
     1248
     1249        /* Check the # of children rather than the length of t, since
     1250           (x for x, in ...) has 1 element in t, but still requires a Tuple. */
     1251        first = (expr_ty)asdl_seq_GET(t, 0);
     1252        if (NCH(for_ch) == 1)
     1253            comp = comprehension(first, expression, NULL, c->c_arena);
     1254        else
     1255            comp = comprehension(Tuple(t, Store, first->lineno, first->col_offset,
     1256                                     c->c_arena),
     1257                               expression, NULL, c->c_arena);
     1258        if (!comp)
     1259            return NULL;
     1260
     1261        if (NCH(n) == 5) {
     1262            int j, n_ifs;
     1263            asdl_seq *ifs;
     1264
     1265            n = CHILD(n, 4);
     1266            n_ifs = count_comp_ifs(c, n);
     1267            if (n_ifs == -1)
     1268                return NULL;
     1269
     1270            ifs = asdl_seq_new(n_ifs, c->c_arena);
     1271            if (!ifs)
     1272                return NULL;
     1273
     1274            for (j = 0; j < n_ifs; j++) {
     1275                REQ(n, comp_iter);
     1276                n = CHILD(n, 0);
     1277                REQ(n, comp_if);
     1278
     1279                expression = ast_for_expr(c, CHILD(n, 1));
     1280                if (!expression)
     1281                    return NULL;
     1282                asdl_seq_SET(ifs, j, expression);
     1283                if (NCH(n) == 3)
     1284                    n = CHILD(n, 2);
     1285            }
     1286            /* on exit, must guarantee that n is a comp_for */
     1287            if (TYPE(n) == comp_iter)
     1288                n = CHILD(n, 0);
     1289            comp->ifs = ifs;
     1290        }
     1291        asdl_seq_SET(comps, i, comp);
     1292    }
     1293    return comps;
     1294}
     1295
     1296static expr_ty
     1297ast_for_itercomp(struct compiling *c, const node *n, int type)
     1298{
     1299    expr_ty elt;
     1300    asdl_seq *comps;
     1301
     1302    assert(NCH(n) > 1);
     1303
     1304    elt = ast_for_expr(c, CHILD(n, 0));
     1305    if (!elt)
     1306        return NULL;
     1307
     1308    comps = ast_for_comprehension(c, CHILD(n, 1));
     1309    if (!comps)
     1310        return NULL;
     1311
     1312    if (type == COMP_GENEXP)
     1313        return GeneratorExp(elt, comps, LINENO(n), n->n_col_offset, c->c_arena);
     1314    else if (type == COMP_SETCOMP)
     1315        return SetComp(elt, comps, LINENO(n), n->n_col_offset, c->c_arena);
     1316    else
     1317        /* Should never happen */
     1318        return NULL;
     1319}
     1320
     1321static expr_ty
     1322ast_for_dictcomp(struct compiling *c, const node *n)
     1323{
     1324    expr_ty key, value;
     1325    asdl_seq *comps;
     1326
     1327    assert(NCH(n) > 3);
     1328    REQ(CHILD(n, 1), COLON);
     1329
     1330    key = ast_for_expr(c, CHILD(n, 0));
     1331    if (!key)
     1332        return NULL;
     1333
     1334    value = ast_for_expr(c, CHILD(n, 2));
     1335    if (!value)
     1336        return NULL;
     1337
     1338    comps = ast_for_comprehension(c, CHILD(n, 3));
     1339    if (!comps)
     1340        return NULL;
     1341
     1342    return DictComp(key, value, comps, LINENO(n), n->n_col_offset, c->c_arena);
     1343}
     1344
    12051345static expr_ty
    12061346ast_for_genexp(struct compiling *c, const node *n)
    12071347{
    1208     /* testlist_gexp: test ( gen_for | (',' test)* [','] )
    1209        argument: [test '='] test [gen_for]       # Really [keyword '='] test */
    1210     expr_ty elt;
    1211     asdl_seq *genexps;
    1212     int i, n_fors;
    1213     node *ch;
    1214    
    1215     assert(TYPE(n) == (testlist_gexp) || TYPE(n) == (argument));
    1216     assert(NCH(n) > 1);
    1217    
    1218     elt = ast_for_expr(c, CHILD(n, 0));
    1219     if (!elt)
    1220         return NULL;
    1221    
    1222     n_fors = count_gen_fors(c, n);
    1223     if (n_fors == -1)
    1224         return NULL;
    1225 
    1226     genexps = asdl_seq_new(n_fors, c->c_arena);
    1227     if (!genexps)
    1228         return NULL;
    1229 
    1230     ch = CHILD(n, 1);
    1231     for (i = 0; i < n_fors; i++) {
    1232         comprehension_ty ge;
    1233         asdl_seq *t;
    1234         expr_ty expression;
    1235         node *for_ch;
    1236        
    1237         REQ(ch, gen_for);
    1238        
    1239         for_ch = CHILD(ch, 1);
    1240         t = ast_for_exprlist(c, for_ch, Store);
    1241         if (!t)
    1242             return NULL;
    1243         expression = ast_for_expr(c, CHILD(ch, 3));
    1244         if (!expression)
    1245             return NULL;
    1246 
    1247         /* Check the # of children rather than the length of t, since
    1248            (x for x, in ...) has 1 element in t, but still requires a Tuple. */
    1249         if (NCH(for_ch) == 1)
    1250             ge = comprehension((expr_ty)asdl_seq_GET(t, 0), expression,
    1251                                NULL, c->c_arena);
    1252         else
    1253             ge = comprehension(Tuple(t, Store, LINENO(ch), ch->n_col_offset,
    1254                                      c->c_arena),
    1255                                expression, NULL, c->c_arena);
    1256 
    1257         if (!ge)
    1258             return NULL;
    1259 
    1260         if (NCH(ch) == 5) {
    1261             int j, n_ifs;
    1262             asdl_seq *ifs;
    1263            
    1264             ch = CHILD(ch, 4);
    1265             n_ifs = count_gen_ifs(c, ch);
    1266             if (n_ifs == -1)
    1267                 return NULL;
    1268 
    1269             ifs = asdl_seq_new(n_ifs, c->c_arena);
    1270             if (!ifs)
    1271                 return NULL;
    1272 
    1273             for (j = 0; j < n_ifs; j++) {
    1274                 REQ(ch, gen_iter);
    1275                 ch = CHILD(ch, 0);
    1276                 REQ(ch, gen_if);
    1277                
    1278                 expression = ast_for_expr(c, CHILD(ch, 1));
    1279                 if (!expression)
    1280                     return NULL;
    1281                 asdl_seq_SET(ifs, j, expression);
    1282                 if (NCH(ch) == 3)
    1283                     ch = CHILD(ch, 2);
    1284             }
    1285             /* on exit, must guarantee that ch is a gen_for */
    1286             if (TYPE(ch) == gen_iter)
    1287                 ch = CHILD(ch, 0);
    1288             ge->ifs = ifs;
    1289         }
    1290         asdl_seq_SET(genexps, i, ge);
    1291     }
    1292    
    1293     return GeneratorExp(elt, genexps, LINENO(n), n->n_col_offset, c->c_arena);
     1348    assert(TYPE(n) == (testlist_comp) || TYPE(n) == (argument));
     1349    return ast_for_itercomp(c, n, COMP_GENEXP);
     1350}
     1351
     1352static expr_ty
     1353ast_for_setcomp(struct compiling *c, const node *n)
     1354{
     1355    assert(TYPE(n) == (dictorsetmaker));
     1356    return ast_for_itercomp(c, n, COMP_SETCOMP);
    12941357}
    12951358
     
    12971360ast_for_atom(struct compiling *c, const node *n)
    12981361{
    1299     /* atom: '(' [yield_expr|testlist_gexp] ')' | '[' [listmaker] ']'
     1362    /* atom: '(' [yield_expr|testlist_comp] ')' | '[' [listmaker] ']'
    13001363       | '{' [dictmaker] '}' | '`' testlist '`' | NAME | NUMBER | STRING+
    13011364    */
    13021365    node *ch = CHILD(n, 0);
    1303    
     1366
    13041367    switch (TYPE(ch)) {
    13051368    case NAME: {
     
    13491412    case LPAR: /* some parenthesized expressions */
    13501413        ch = CHILD(n, 1);
    1351        
     1414
    13521415        if (TYPE(ch) == RPAR)
    13531416            return Tuple(NULL, Load, LINENO(n), n->n_col_offset, c->c_arena);
    1354        
     1417
    13551418        if (TYPE(ch) == yield_expr)
    13561419            return ast_for_expr(c, ch);
    1357        
    1358         if ((NCH(ch) > 1) && (TYPE(CHILD(ch, 1)) == gen_for))
    1359             return ast_for_genexp(c, ch);
    1360        
    1361         return ast_for_testlist_gexp(c, ch);
     1420
     1421        return ast_for_testlist_comp(c, ch);
    13621422    case LSQB: /* list (or list comprehension) */
    13631423        ch = CHILD(n, 1);
    1364        
     1424
    13651425        if (TYPE(ch) == RSQB)
    13661426            return List(NULL, Load, LINENO(n), n->n_col_offset, c->c_arena);
    1367        
     1427
    13681428        REQ(ch, listmaker);
    13691429        if (NCH(ch) == 1 || TYPE(CHILD(ch, 1)) == COMMA) {
     
    13771437            return ast_for_listcomp(c, ch);
    13781438    case LBRACE: {
    1379         /* dictmaker: test ':' test (',' test ':' test)* [','] */
     1439        /* dictorsetmaker:
     1440         *    (test ':' test (comp_for | (',' test ':' test)* [','])) |
     1441         *    (test (comp_for | (',' test)* [',']))
     1442         */
    13801443        int i, size;
    13811444        asdl_seq *keys, *values;
    1382        
     1445
    13831446        ch = CHILD(n, 1);
    1384         size = (NCH(ch) + 1) / 4; /* +1 in case no trailing comma */
    1385         keys = asdl_seq_new(size, c->c_arena);
    1386         if (!keys)
    1387             return NULL;
    1388        
    1389         values = asdl_seq_new(size, c->c_arena);
    1390         if (!values)
    1391             return NULL;
    1392        
    1393         for (i = 0; i < NCH(ch); i += 4) {
    1394             expr_ty expression;
    1395            
    1396             expression = ast_for_expr(c, CHILD(ch, i));
    1397             if (!expression)
    1398                 return NULL;
    1399 
    1400             asdl_seq_SET(keys, i / 4, expression);
    1401 
    1402             expression = ast_for_expr(c, CHILD(ch, i + 2));
    1403             if (!expression)
    1404                 return NULL;
    1405 
    1406             asdl_seq_SET(values, i / 4, expression);
    1407         }
    1408         return Dict(keys, values, LINENO(n), n->n_col_offset, c->c_arena);
     1447        if (TYPE(ch) == RBRACE) {
     1448            /* it's an empty dict */
     1449            return Dict(NULL, NULL, LINENO(n), n->n_col_offset, c->c_arena);
     1450        } else if (NCH(ch) == 1 || TYPE(CHILD(ch, 1)) == COMMA) {
     1451            /* it's a simple set */
     1452            asdl_seq *elts;
     1453            size = (NCH(ch) + 1) / 2; /* +1 in case no trailing comma */
     1454            elts = asdl_seq_new(size, c->c_arena);
     1455            if (!elts)
     1456                return NULL;
     1457            for (i = 0; i < NCH(ch); i += 2) {
     1458                expr_ty expression;
     1459                expression = ast_for_expr(c, CHILD(ch, i));
     1460                if (!expression)
     1461                    return NULL;
     1462                asdl_seq_SET(elts, i / 2, expression);
     1463            }
     1464            return Set(elts, LINENO(n), n->n_col_offset, c->c_arena);
     1465        } else if (TYPE(CHILD(ch, 1)) == comp_for) {
     1466            /* it's a set comprehension */
     1467            return ast_for_setcomp(c, ch);
     1468        } else if (NCH(ch) > 3 && TYPE(CHILD(ch, 3)) == comp_for) {
     1469            return ast_for_dictcomp(c, ch);
     1470        } else {
     1471            /* it's a dict */
     1472            size = (NCH(ch) + 1) / 4; /* +1 in case no trailing comma */
     1473            keys = asdl_seq_new(size, c->c_arena);
     1474            if (!keys)
     1475                return NULL;
     1476
     1477            values = asdl_seq_new(size, c->c_arena);
     1478            if (!values)
     1479                return NULL;
     1480
     1481            for (i = 0; i < NCH(ch); i += 4) {
     1482                expr_ty expression;
     1483
     1484                expression = ast_for_expr(c, CHILD(ch, i));
     1485                if (!expression)
     1486                    return NULL;
     1487
     1488                asdl_seq_SET(keys, i / 4, expression);
     1489
     1490                expression = ast_for_expr(c, CHILD(ch, i + 2));
     1491                if (!expression)
     1492                    return NULL;
     1493
     1494                asdl_seq_SET(values, i / 4, expression);
     1495            }
     1496            return Dict(keys, values, LINENO(n), n->n_col_offset, c->c_arena);
     1497        }
    14091498    }
    14101499    case BACKQUOTE: { /* repr */
     
    14441533        /* 'step' variable hold no significance in terms of being used over
    14451534           other vars */
    1446         step = ast_for_expr(c, ch); 
     1535        step = ast_for_expr(c, ch);
    14471536        if (!step)
    14481537            return NULL;
    1449            
     1538
    14501539        return Index(step, c->c_arena);
    14511540    }
     
    14811570    if (TYPE(ch) == sliceop) {
    14821571        if (NCH(ch) == 1) {
    1483             /* No expression, so step is None */
     1572            /*
     1573              This is an extended slice (ie "x[::]") with no expression in the
     1574              step field. We set this literally to "None" in order to
     1575              disambiguate it from x[:]. (The interpreter might have to call
     1576              __getslice__ for x[:], but it must call __getitem__ for x[::].)
     1577            */
     1578            identifier none = new_identifier("None", c->c_arena);
     1579            if (!none)
     1580                return NULL;
    14841581            ch = CHILD(ch, 0);
    1485             step = Name(new_identifier("None", c->c_arena), Load,
    1486                         LINENO(ch), ch->n_col_offset, c->c_arena);
     1582            step = Name(none, Load, LINENO(ch), ch->n_col_offset, c->c_arena);
    14871583            if (!step)
    14881584                return NULL;
     
    15041600{
    15051601        /* Must account for a sequence of expressions.
    1506            How should A op B op C by represented? 
     1602           How should A op B op C by represented?
    15071603           BinOp(BinOp(A, op, B), op, C).
    15081604        */
     
    15421638                    return NULL;
    15431639
    1544                 tmp_result = BinOp(result, newoperator, tmp, 
     1640                tmp_result = BinOp(result, newoperator, tmp,
    15451641                                   LINENO(next_oper), next_oper->n_col_offset,
    15461642                                   c->c_arena);
    1547                 if (!tmp_result) 
     1643                if (!tmp_result)
    15481644                        return NULL;
    15491645                result = tmp_result;
     
    15551651ast_for_trailer(struct compiling *c, const node *n, expr_ty left_expr)
    15561652{
    1557     /* trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME 
     1653    /* trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
    15581654       subscriptlist: subscript (',' subscript)* [',']
    15591655       subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop]
     
    15861682        }
    15871683        else {
    1588             /* The grammar is ambiguous here. The ambiguity is resolved 
     1684            /* The grammar is ambiguous here. The ambiguity is resolved
    15891685               by treating the sequence as a tuple literal if there are
    15901686               no slice features.
     
    16491745        TYPE((patom = CHILD(ppower, 0))) == atom &&
    16501746        TYPE((pnum = CHILD(patom, 0))) == NUMBER) {
     1747        PyObject *pynum;
    16511748        char *s = PyObject_MALLOC(strlen(STR(pnum)) + 2);
    16521749        if (s == NULL)
     
    16541751        s[0] = '-';
    16551752        strcpy(s + 1, STR(pnum));
    1656         PyObject_FREE(STR(pnum));
    1657         STR(pnum) = s;
    1658         return ast_for_atom(c, patom);
     1753        pynum = parsenumber(c, s);
     1754        PyObject_FREE(s);
     1755        if (!pynum)
     1756            return NULL;
     1757
     1758        PyArena_AddPyObject(c->c_arena, pynum);
     1759        return Num(pynum, LINENO(n), n->n_col_offset, c->c_arena);
    16591760    }
    16601761
     
    17231824    /* handle the full range of simple expressions
    17241825       test: or_test ['if' or_test 'else' test] | lambdef
    1725        or_test: and_test ('or' and_test)* 
     1826       or_test: and_test ('or' and_test)*
    17261827       and_test: not_test ('and' not_test)*
    17271828       not_test: 'not' not_test | comparison
     
    17401841       [ x for x in lambda: 0, lambda: 1 ]
    17411842       (which would be ambiguous without these extra rules)
    1742        
     1843
    17431844       old_test: or_test | old_lambdef
    17441845       old_lambdef: 'lambda' [vararglist] ':' old_test
     
    18201921                        return NULL;
    18211922                    }
    1822                        
     1923
    18231924                    asdl_seq_SET(ops, i / 2, newoperator);
    18241925                    asdl_seq_SET(cmps, i / 2, expression);
     
    18281929                    return NULL;
    18291930                }
    1830                    
     1931
    18311932                return Compare(expression, ops, cmps, LINENO(n),
    18321933                               n->n_col_offset, c->c_arena);
     
    18801981      arglist: (argument ',')* (argument [',']| '*' test [',' '**' test]
    18811982               | '**' test)
    1882       argument: [test '='] test [gen_for]        # Really [keyword '='] test
     1983      argument: [test '='] test [comp_for]        # Really [keyword '='] test
    18831984    */
    18841985
     
    18981999            if (NCH(ch) == 1)
    18992000                nargs++;
    1900             else if (TYPE(CHILD(ch, 1)) == gen_for)
     2001            else if (TYPE(CHILD(ch, 1)) == comp_for)
    19012002                ngens++;
    19022003            else
     
    19422043                    return NULL;
    19432044                asdl_seq_SET(args, nargs++, e);
    1944             } 
    1945             else if (TYPE(CHILD(ch, 1)) == gen_for) {
     2045            }
     2046            else if (TYPE(CHILD(ch, 1)) == comp_for) {
    19462047                e = ast_for_genexp(c, ch);
    19472048                if (!e)
     
    19552056                char *tmp;
    19562057
    1957                 /* CHILD(ch, 0) is test, but must be an identifier? */ 
     2058                /* CHILD(ch, 0) is test, but must be an identifier? */
    19582059                e = ast_for_expr(c, CHILD(ch, 0));
    19592060                if (!e)
     
    20132114ast_for_testlist(struct compiling *c, const node* n)
    20142115{
    2015     /* testlist_gexp: test (',' test)* [','] */
     2116    /* testlist_comp: test (',' test)* [','] */
    20162117    /* testlist: test (',' test)* [','] */
    20172118    /* testlist_safe: test (',' test)+ [','] */
    20182119    /* testlist1: test (',' test)* */
    20192120    assert(NCH(n) > 0);
    2020     if (TYPE(n) == testlist_gexp) {
     2121    if (TYPE(n) == testlist_comp) {
    20212122        if (NCH(n) > 1)
    2022             assert(TYPE(CHILD(n, 1)) != gen_for);
     2123            assert(TYPE(CHILD(n, 1)) != comp_for);
    20232124    }
    20242125    else {
     
    20382139
    20392140static expr_ty
    2040 ast_for_testlist_gexp(struct compiling *c, const node* n)
    2041 {
    2042     /* testlist_gexp: test ( gen_for | (',' test)* [','] ) */
    2043     /* argument: test [ gen_for ] */
    2044     assert(TYPE(n) == testlist_gexp || TYPE(n) == argument);
    2045     if (NCH(n) > 1 && TYPE(CHILD(n, 1)) == gen_for)
     2141ast_for_testlist_comp(struct compiling *c, const node* n)
     2142{
     2143    /* testlist_comp: test ( comp_for | (',' test)* [','] ) */
     2144    /* argument: test [ comp_for ] */
     2145    assert(TYPE(n) == testlist_comp || TYPE(n) == argument);
     2146    if (NCH(n) > 1 && TYPE(CHILD(n, 1)) == comp_for)
    20462147        return ast_for_genexp(c, n);
    20472148    return ast_for_testlist(c, n);
     
    20742175{
    20752176    REQ(n, expr_stmt);
    2076     /* expr_stmt: testlist (augassign (yield_expr|testlist) 
     2177    /* expr_stmt: testlist (augassign (yield_expr|testlist)
    20772178                | ('=' (yield_expr|testlist))*)
    20782179       testlist: test (',' test)* [',']
     
    20972198        if (!expr1)
    20982199            return NULL;
    2099         /* TODO(nas): Remove duplicated error checks (set_context does it) */
     2200        if(!set_context(c, expr1, Store, ch))
     2201            return NULL;
     2202        /* set_context checks that most expressions are not the left side.
     2203          Augmented assignments can only have a name, a subscript, or an
     2204          attribute on the left, though, so we have to explicitly check for
     2205          those. */
    21002206        switch (expr1->kind) {
    2101             case GeneratorExp_kind:
    2102                 ast_error(ch, "augmented assignment to generator "
    2103                           "expression not possible");
    2104                 return NULL;
    2105             case Yield_kind:
    2106                 ast_error(ch, "augmented assignment to yield "
    2107                           "expression not possible");
    2108                 return NULL;
    2109             case Name_kind: {
    2110                 const char *var_name = PyBytes_AS_STRING(expr1->v.Name.id);
    2111                 if ((var_name[0] == 'N' || var_name[0] == 'T' || var_name[0] == 'F') &&
    2112                     !forbidden_check(c, ch, var_name))
    2113                     return NULL;
    2114                 break;
    2115             }
     2207            case Name_kind:
    21162208            case Attribute_kind:
    21172209            case Subscript_kind:
    21182210                break;
    21192211            default:
    2120                 ast_error(ch, "illegal expression for augmented "
    2121                           "assignment");
    2122                 return NULL;
    2123         }
    2124         if(!set_context(c, expr1, Store, ch))
    2125             return NULL;
     2212                ast_error(ch, "illegal expression for augmented assignment");
     2213                return NULL;
     2214        }
    21262215
    21272216        ch = CHILD(n, 2);
     
    21592248            }
    21602249            e = ast_for_testlist(c, ch);
     2250            if (!e)
     2251                return NULL;
    21612252
    21622253            /* set context to assign */
    2163             if (!e)
    2164                 return NULL;
    2165 
    21662254            if (!set_context(c, e, Store, CHILD(n, i)))
    21672255                return NULL;
     
    21882276     */
    21892277    expr_ty dest = NULL, expression;
    2190     asdl_seq *seq;
     2278    asdl_seq *seq = NULL;
    21912279    bool nl;
    2192     int i, j, start = 1;
     2280    int i, j, values_count, start = 1;
    21932281
    21942282    REQ(n, print_stmt);
     
    21992287            start = 4;
    22002288    }
    2201     seq = asdl_seq_new((NCH(n) + 1 - start) / 2, c->c_arena);
    2202     if (!seq)
    2203         return NULL;
    2204     for (i = start, j = 0; i < NCH(n); i += 2, ++j) {
    2205         expression = ast_for_expr(c, CHILD(n, i));
    2206         if (!expression)
    2207             return NULL;
    2208         asdl_seq_SET(seq, j, expression);
     2289    values_count = (NCH(n) + 1 - start) / 2;
     2290    if (values_count) {
     2291        seq = asdl_seq_new(values_count, c->c_arena);
     2292        if (!seq)
     2293            return NULL;
     2294        for (i = start, j = 0; i < NCH(n); i += 2, ++j) {
     2295            expression = ast_for_expr(c, CHILD(n, i));
     2296            if (!expression)
     2297                return NULL;
     2298            asdl_seq_SET(seq, j, expression);
     2299        }
    22092300    }
    22102301    nl = (TYPE(CHILD(n, NCH(n) - 1)) == COMMA) ? false : true;
     
    22392330{
    22402331    asdl_seq *expr_list;
    2241    
     2332
    22422333    /* del_stmt: 'del' exprlist */
    22432334    REQ(n, del_stmt);
     
    23232414                if (!expr3)
    23242415                    return NULL;
    2325                    
     2416
    23262417                return Raise(expr1, expr2, expr3, LINENO(n), n->n_col_offset,
    23272418                             c->c_arena);
     
    23382429
    23392430static alias_ty
    2340 alias_for_import_name(struct compiling *c, const node *n)
     2431alias_for_import_name(struct compiling *c, const node *n, int store)
    23412432{
    23422433    /*
     
    23492440 loop:
    23502441    switch (TYPE(n)) {
    2351         case import_as_name:
     2442         case import_as_name: {
     2443            node *name_node = CHILD(n, 0);
    23522444            str = NULL;
    23532445            if (NCH(n) == 3) {
    2354                 str = NEW_IDENTIFIER(CHILD(n, 2));
     2446                node *str_node = CHILD(n, 2);
     2447                if (store && !forbidden_check(c, str_node, STR(str_node)))
     2448                    return NULL;
     2449                str = NEW_IDENTIFIER(str_node);
    23552450                if (!str)
    23562451                    return NULL;
    23572452            }
    2358             name = NEW_IDENTIFIER(CHILD(n, 0));
     2453            else {
     2454                if (!forbidden_check(c, name_node, STR(name_node)))
     2455                    return NULL;
     2456            }
     2457            name = NEW_IDENTIFIER(name_node);
    23592458            if (!name)
    23602459                return NULL;
    23612460            return alias(name, str, c->c_arena);
     2461        }
    23622462        case dotted_as_name:
    23632463            if (NCH(n) == 1) {
     
    23662466            }
    23672467            else {
    2368                 alias_ty a = alias_for_import_name(c, CHILD(n, 0));
     2468                node *asname_node = CHILD(n, 2);
     2469                alias_ty a = alias_for_import_name(c, CHILD(n, 0), 0);
    23692470                if (!a)
    23702471                    return NULL;
    23712472                assert(!a->asname);
    2372                 a->asname = NEW_IDENTIFIER(CHILD(n, 2));
     2473                if (!forbidden_check(c, asname_node, STR(asname_node)))
     2474                    return NULL;
     2475                a->asname = NEW_IDENTIFIER(asname_node);
    23732476                if (!a->asname)
    23742477                    return NULL;
     
    23782481        case dotted_name:
    23792482            if (NCH(n) == 1) {
    2380                 name = NEW_IDENTIFIER(CHILD(n, 0));
     2483                node *name_node = CHILD(n, 0);
     2484                if (store && !forbidden_check(c, name_node, STR(name_node)))
     2485                    return NULL;
     2486                name = NEW_IDENTIFIER(name_node);
    23812487                if (!name)
    23822488                    return NULL;
     
    24522558            return NULL;
    24532559        for (i = 0; i < NCH(n); i += 2) {
    2454             alias_ty import_alias = alias_for_import_name(c, CHILD(n, i));
     2560            alias_ty import_alias = alias_for_import_name(c, CHILD(n, i), 1);
    24552561            if (!import_alias)
    24562562                return NULL;
     
    24632569        int idx, ndots = 0;
    24642570        alias_ty mod = NULL;
    2465         identifier modname;
    2466        
     2571        identifier modname = NULL;
     2572
    24672573       /* Count the number of dots (for relative imports) and check for the
    24682574          optional module name */
    24692575        for (idx = 1; idx < NCH(n); idx++) {
    24702576            if (TYPE(CHILD(n, idx)) == dotted_name) {
    2471                 mod = alias_for_import_name(c, CHILD(n, idx));
     2577                mod = alias_for_import_name(c, CHILD(n, idx), 0);
     2578                if (!mod)
     2579                    return NULL;
    24722580                idx++;
    24732581                break;
     
    25102618        /* handle "from ... import *" special b/c there's no children */
    25112619        if (TYPE(n) == STAR) {
    2512             alias_ty import_alias = alias_for_import_name(c, n);
     2620            alias_ty import_alias = alias_for_import_name(c, n, 1);
    25132621            if (!import_alias)
    25142622                return NULL;
     
    25172625        else {
    25182626            for (i = 0; i < NCH(n); i += 2) {
    2519                 alias_ty import_alias = alias_for_import_name(c, CHILD(n, i));
     2627                alias_ty import_alias = alias_for_import_name(c, CHILD(n, i), 1);
    25202628                if (!import_alias)
    25212629                    return NULL;
     
    25252633        if (mod != NULL)
    25262634            modname = mod->name;
    2527         else
    2528             modname = new_identifier("", c->c_arena);
    25292635        return ImportFrom(modname, aliases, ndots, lineno, col_offset,
    25302636                          c->c_arena);
     
    26102716        if (!expr2)
    26112717            return NULL;
    2612            
     2718
    26132719        return Assert(expr1, expr2, LINENO(n), n->n_col_offset, c->c_arena);
    26142720    }
     
    26372743        n = CHILD(n, 0);
    26382744        /* simple_stmt always ends with a NEWLINE,
    2639            and may have a trailing SEMI 
     2745           and may have a trailing SEMI
    26402746        */
    26412747        end = NCH(n) - 1;
     
    27022808        if (!expression)
    27032809            return NULL;
    2704         suite_seq = ast_for_suite(c, CHILD(n, 3)); 
     2810        suite_seq = ast_for_suite(c, CHILD(n, 3));
    27052811        if (!suite_seq)
    27062812            return NULL;
    2707            
     2813
    27082814        return If(expression, suite_seq, NULL, LINENO(n), n->n_col_offset,
    27092815                  c->c_arena);
     
    27632869                return NULL;
    27642870
    2765             asdl_seq_SET(orelse, 0, 
    2766                          If(expression, suite_seq, suite_seq2, 
     2871            asdl_seq_SET(orelse, 0,
     2872                         If(expression, suite_seq, suite_seq2,
    27672873                            LINENO(CHILD(n, NCH(n) - 6)),
    27682874                            CHILD(n, NCH(n) - 6)->n_col_offset,
     
    27852891
    27862892            asdl_seq_SET(newobj, 0,
    2787                          If(expression, suite_seq, orelse, 
     2893                         If(expression, suite_seq, orelse,
    27882894                            LINENO(CHILD(n, off)),
    27892895                            CHILD(n, off)->n_col_offset, c->c_arena));
     
    28532959    asdl_seq *_target, *seq = NULL, *suite_seq;
    28542960    expr_ty expression;
    2855     expr_ty target;
     2961    expr_ty target, first;
    28562962    const node *node_target;
    28572963    /* for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] */
     
    28702976    /* Check the # of children rather than the length of _target, since
    28712977       for x, in ... has 1 element in _target, but still requires a Tuple. */
     2978    first = (expr_ty)asdl_seq_GET(_target, 0);
    28722979    if (NCH(node_target) == 1)
    2873         target = (expr_ty)asdl_seq_GET(_target, 0);
     2980        target = first;
    28742981    else
    2875         target = Tuple(_target, Store, LINENO(n), n->n_col_offset, c->c_arena);
     2982        target = Tuple(_target, Store, first->lineno, first->col_offset, c->c_arena);
    28762983
    28772984    expression = ast_for_testlist(c, CHILD(n, 3));
     
    29833090        return NULL;
    29843091    }
    2985    
     3092
    29863093    if (n_except > 0) {
    29873094        int i;
     
    30183125}
    30193126
    3020 static expr_ty
    3021 ast_for_with_var(struct compiling *c, const node *n)
    3022 {
    3023     REQ(n, with_var);
    3024     return ast_for_expr(c, CHILD(n, 1));
    3025 }
    3026 
    3027 /* with_stmt: 'with' test [ with_var ] ':' suite */
     3127/* with_item: test ['as' expr] */
     3128static stmt_ty
     3129ast_for_with_item(struct compiling *c, const node *n, asdl_seq *content)
     3130{
     3131    expr_ty context_expr, optional_vars = NULL;
     3132
     3133    REQ(n, with_item);
     3134    context_expr = ast_for_expr(c, CHILD(n, 0));
     3135    if (!context_expr)
     3136        return NULL;
     3137    if (NCH(n) == 3) {
     3138        optional_vars = ast_for_expr(c, CHILD(n, 2));
     3139
     3140        if (!optional_vars) {
     3141            return NULL;
     3142        }
     3143        if (!set_context(c, optional_vars, Store, n)) {
     3144            return NULL;
     3145        }
     3146    }
     3147
     3148    return With(context_expr, optional_vars, content, LINENO(n),
     3149                n->n_col_offset, c->c_arena);
     3150}
     3151
     3152/* with_stmt: 'with' with_item (',' with_item)* ':' suite */
    30283153static stmt_ty
    30293154ast_for_with_stmt(struct compiling *c, const node *n)
    30303155{
    3031     expr_ty context_expr, optional_vars = NULL;
    3032     int suite_index = 3;    /* skip 'with', test, and ':' */
    3033     asdl_seq *suite_seq;
    3034 
    3035     assert(TYPE(n) == with_stmt);
    3036     context_expr = ast_for_expr(c, CHILD(n, 1));
    3037     if (!context_expr)
    3038         return NULL;
    3039     if (TYPE(CHILD(n, 2)) == with_var) {
    3040         optional_vars = ast_for_with_var(c, CHILD(n, 2));
    3041 
    3042         if (!optional_vars) {
    3043             return NULL;
    3044         }
    3045         if (!set_context(c, optional_vars, Store, n)) {
    3046             return NULL;
    3047         }
    3048         suite_index = 4;
    3049     }
    3050 
    3051     suite_seq = ast_for_suite(c, CHILD(n, suite_index));
    3052     if (!suite_seq) {
    3053         return NULL;
    3054     }
    3055     return With(context_expr, optional_vars, suite_seq, LINENO(n),
    3056                 n->n_col_offset, c->c_arena);
     3156    int i;
     3157    stmt_ty ret;
     3158    asdl_seq *inner;
     3159
     3160    REQ(n, with_stmt);
     3161
     3162    /* process the with items inside-out */
     3163    i = NCH(n) - 1;
     3164    /* the suite of the innermost with item is the suite of the with stmt */
     3165    inner = ast_for_suite(c, CHILD(n, i));
     3166    if (!inner)
     3167        return NULL;
     3168
     3169    for (;;) {
     3170        i -= 2;
     3171        ret = ast_for_with_item(c, CHILD(n, i), inner);
     3172        if (!ret)
     3173            return NULL;
     3174        /* was this the last item? */
     3175        if (i == 1)
     3176            break;
     3177        /* if not, wrap the result so far in a new sequence */
     3178        inner = asdl_seq_new(1, c->c_arena);
     3179        if (!inner)
     3180            return NULL;
     3181        asdl_seq_SET(inner, 0, ret);
     3182    }
     3183
     3184    return ret;
    30573185}
    30583186
     
    30633191    PyObject *classname;
    30643192    asdl_seq *bases, *s;
    3065    
     3193
    30663194    REQ(n, classdef);
    30673195
     
    31183246    }
    31193247    if (TYPE(n) == small_stmt) {
    3120         REQ(n, small_stmt);
    31213248        n = CHILD(n, 0);
    31223249        /* small_stmt: expr_stmt | print_stmt  | del_stmt | pass_stmt
     
    31713298            case classdef:
    31723299                return ast_for_classdef(c, ch, NULL);
    3173             case decorated:
    3174                 return ast_for_decorated(c, ch);
     3300            case decorated:
     3301                return ast_for_decorated(c, ch);
    31753302            default:
    31763303                PyErr_Format(PyExc_SystemError,
     
    32113338        if (imflag) {
    32123339                complex.real = 0.;
    3213                 PyFPE_START_PROTECT("atof", return 0)
    3214                 complex.imag = PyOS_ascii_atof(s);
    3215                 PyFPE_END_PROTECT(complex)
     3340                complex.imag = PyOS_string_to_double(s, (char **)&end, NULL);
     3341                if (complex.imag == -1.0 && PyErr_Occurred())
     3342                        return NULL;
    32163343                return PyComplex_FromCComplex(complex);
    32173344        }
     
    32193346#endif
    32203347        {
    3221                 PyFPE_START_PROTECT("atof", return 0)
    3222                 dx = PyOS_ascii_atof(s);
    3223                 PyFPE_END_PROTECT(dx)
     3348                dx = PyOS_string_to_double(s, NULL, NULL);
     3349                if (dx == -1.0 && PyErr_Occurred())
     3350                        return NULL;
    32243351                return PyFloat_FromDouble(dx);
    32253352        }
     
    32523379decode_unicode(struct compiling *c, const char *s, size_t len, int rawmode, const char *encoding)
    32533380{
    3254         PyObject *v, *u;
     3381        PyObject *v;
     3382        PyObject *u = NULL;
    32553383        char *buf;
    32563384        char *p;
    32573385        const char *end;
    3258         if (encoding == NULL) {
    3259                 buf = (char *)s;
    3260                 u = NULL;
    3261         } else if (strcmp(encoding, "iso-8859-1") == 0) {
    3262                 buf = (char *)s;
    3263                 u = NULL;
    3264         } else {
     3386        if (encoding != NULL && strcmp(encoding, "iso-8859-1")) {
    32653387                /* check for integer overflow */
    32663388                if (len > PY_SIZE_MAX / 6)
    32673389                        return NULL;
    3268                 /* "<C3><A4>" (2 bytes) may become "\U000000E4" (10 bytes), or 1:5
    3269                    "\À" (3 bytes) may become "\u005c\U000000E4" (16 bytes), or ~1:6 */
     3390                /* "<C3><A4>" (2 bytes) may become "\U000000E4" (10 bytes), or 1:5
     3391                   "\À" (3 bytes) may become "\u005c\U000000E4" (16 bytes), or ~1:6 */
    32703392                u = PyString_FromStringAndSize((char *)NULL, len * 6);
    32713393                if (u == NULL)
     
    32973419                                                r[i + 0] & 0xFF,
    32983420                                                r[i + 1] & 0xFF,
    3299                                                 r[i + 2] & 0xFF,
    3300                                                 r[i + 3] & 0xFF);
     3421                                                r[i + 2] & 0xFF,
     3422                                                r[i + 3] & 0xFF);
    33013423                                        p += 10;
    33023424                                }
     
    33523474        len = strlen(s);
    33533475        if (len > INT_MAX) {
    3354                 PyErr_SetString(PyExc_OverflowError, 
     3476                PyErr_SetString(PyExc_OverflowError,
    33553477                                "string to parse is too long");
    33563478                return NULL;
Note: See TracChangeset for help on using the changeset viewer.