~ubuntu-branches/ubuntu/oneiric/python2.5/oneiric

« back to all changes in this revision

Viewing changes to Python/ast.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2008-12-21 08:57:49 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20081221085749-bijjr25h8na5jdsu
Tags: 2.5.3-0ubuntu1
* New upstream version.
* Regenerate the included documentation.
* Add an option --install-layout=deb, which is ignored for 2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
static identifier
50
50
new_identifier(const char* n, PyArena *arena) {
51
51
    PyObject* id = PyString_InternFromString(n);
52
 
    PyArena_AddPyObject(arena, id);
 
52
    if (id != NULL)
 
53
        PyArena_AddPyObject(arena, id);
53
54
    return id;
54
55
}
55
56
 
249
250
                    goto error;
250
251
                asdl_seq_SET(stmts, 0, Pass(n->n_lineno, n->n_col_offset,
251
252
                                            arena));
 
253
                if (!asdl_seq_GET(stmts, 0))
 
254
                    goto error;
252
255
                return Interactive(stmts, arena);
253
256
            }
254
257
            else {
572
575
    */
573
576
    REQ(n, fplist);
574
577
    for (i = 0; i < len; i++) {
 
578
        PyObject *arg_id;
575
579
        const node *fpdef_node = CHILD(n, 2*i);
576
580
        const node *child;
577
581
        expr_ty arg;
579
583
        /* fpdef_node is either a NAME or an fplist */
580
584
        child = CHILD(fpdef_node, 0);
581
585
        if (TYPE(child) == NAME) {
582
 
                if (!strcmp(STR(child), "None")) {
583
 
                        ast_error(child, "assignment to None");
584
 
                        return NULL;
585
 
                    }   
586
 
            arg = Name(NEW_IDENTIFIER(child), Store, LINENO(child),
587
 
                       child->n_col_offset, c->c_arena);
588
 
            }
 
586
            if (!strcmp(STR(child), "None")) {
 
587
                    ast_error(child, "assignment to None");
 
588
                    return NULL;
 
589
            }   
 
590
            arg_id = NEW_IDENTIFIER(child);
 
591
            if (!arg_id)
 
592
                return NULL;
 
593
            arg = Name(arg_id, Store, LINENO(child), child->n_col_offset,
 
594
                       c->c_arena);
 
595
        }
589
596
        else {
590
597
            assert(TYPE(fpdef_node) == fpdef);
591
598
            /* fpdef_node[0] is not a name, so it must be a '(', get CHILD[1] */
679
686
                    if (NCH(ch) != 1) {
680
687
                        /* We have complex arguments, setup for unpacking. */
681
688
                        asdl_seq_SET(args, k++, compiler_complex_args(c, ch));
 
689
                        if (!asdl_seq_GET(args, k-1))
 
690
                            goto error;
682
691
                    } else {
683
692
                        /* def foo((x)): setup for checking NAME below. */
684
693
                        /* Loop because there can be many parens and tuple
689
698
                    }
690
699
                }
691
700
                if (TYPE(CHILD(ch, 0)) == NAME) {
 
701
                    PyObject *id;
692
702
                    expr_ty name;
693
703
                    if (!strcmp(STR(CHILD(ch, 0)), "None")) {
694
704
                            ast_error(CHILD(ch, 0), "assignment to None");
695
705
                            goto error;
696
706
                    }
697
 
                    name = Name(NEW_IDENTIFIER(CHILD(ch, 0)),
698
 
                                Param, LINENO(ch), ch->n_col_offset,
 
707
                    id = NEW_IDENTIFIER(CHILD(ch, 0));
 
708
                    if (!id)
 
709
                        goto error;
 
710
                    name = Name(id, Param, LINENO(ch), ch->n_col_offset,
699
711
                                c->c_arena);
700
712
                    if (!name)
701
713
                        goto error;
710
722
                        goto error;
711
723
                }
712
724
                vararg = NEW_IDENTIFIER(CHILD(n, i+1));
 
725
                if (!vararg)
 
726
                    goto error;
713
727
                i += 3;
714
728
                break;
715
729
            case DOUBLESTAR:
718
732
                        goto error;
719
733
                }
720
734
                kwarg = NEW_IDENTIFIER(CHILD(n, i+1));
 
735
                if (!kwarg)
 
736
                    goto error;
721
737
                i += 3;
722
738
                break;
723
739
            default:
1231
1247
    node *ch = CHILD(n, 0);
1232
1248
    
1233
1249
    switch (TYPE(ch)) {
1234
 
    case NAME:
1235
 
        /* All names start in Load context, but may later be
1236
 
           changed. */
1237
 
        return Name(NEW_IDENTIFIER(ch), Load, LINENO(n), n->n_col_offset, c->c_arena);
 
1250
    case NAME: {
 
1251
        /* All names start in Load context, but may later be
 
1252
           changed. */
 
1253
        PyObject *id = NEW_IDENTIFIER(ch);
 
1254
        if (!id)
 
1255
            return NULL;
 
1256
        return Name(id, Load, LINENO(n), n->n_col_offset, c->c_arena);
 
1257
    }
1238
1258
    case STRING: {
1239
1259
        PyObject *str = parsestrplus(c, n);
1240
1260
        if (!str)
1468
1488
            return ast_for_call(c, CHILD(n, 1), left_expr);
1469
1489
    }
1470
1490
    else if (TYPE(CHILD(n, 0)) == DOT ) {
1471
 
        return Attribute(left_expr, NEW_IDENTIFIER(CHILD(n, 1)), Load,
 
1491
        PyObject *attr_id = NEW_IDENTIFIER(CHILD(n, 1));
 
1492
        if (!attr_id)
 
1493
            return NULL;
 
1494
        return Attribute(left_expr, attr_id, Load,
1472
1495
                         LINENO(n), n->n_col_offset, c->c_arena);
1473
1496
    }
1474
1497
    else {
1878
1901
        }
1879
1902
        else if (TYPE(ch) == STAR) {
1880
1903
            vararg = ast_for_expr(c, CHILD(n, i+1));
 
1904
            if (!vararg)
 
1905
                return NULL;
1881
1906
            i++;
1882
1907
        }
1883
1908
        else if (TYPE(ch) == DOUBLESTAR) {
1884
1909
            kwarg = ast_for_expr(c, CHILD(n, i+1));
 
1910
            if (!kwarg)
 
1911
                return NULL;
1885
1912
            i++;
1886
1913
        }
1887
1914
    }
2218
2245
      dotted_as_name: dotted_name ['as' NAME]
2219
2246
      dotted_name: NAME ('.' NAME)*
2220
2247
    */
2221
 
    PyObject *str;
 
2248
    PyObject *str, *name;
2222
2249
 
2223
2250
 loop:
2224
2251
    switch (TYPE(n)) {
2230
2257
                    return NULL;
2231
2258
                }
2232
2259
                str = NEW_IDENTIFIER(CHILD(n, 2));
 
2260
                if (!str)
 
2261
                    return NULL;
2233
2262
            }
2234
 
            return alias(NEW_IDENTIFIER(CHILD(n, 0)), str, c->c_arena);
 
2263
            name = NEW_IDENTIFIER(CHILD(n, 0));
 
2264
            if (!name)
 
2265
                return NULL;
 
2266
            return alias(name, str, c->c_arena);
2235
2267
        case dotted_as_name:
2236
2268
            if (NCH(n) == 1) {
2237
2269
                n = CHILD(n, 0);
2247
2279
                }
2248
2280
                assert(!a->asname);
2249
2281
                a->asname = NEW_IDENTIFIER(CHILD(n, 2));
 
2282
                if (!a->asname)
 
2283
                    return NULL;
2250
2284
                return a;
2251
2285
            }
2252
2286
            break;
2253
2287
        case dotted_name:
2254
 
            if (NCH(n) == 1)
2255
 
                return alias(NEW_IDENTIFIER(CHILD(n, 0)), NULL, c->c_arena);
 
2288
            if (NCH(n) == 1) {
 
2289
                name = NEW_IDENTIFIER(CHILD(n, 0));
 
2290
                if (!name)
 
2291
                    return NULL;
 
2292
                return alias(name, NULL, c->c_arena);
 
2293
            }
2256
2294
            else {
2257
2295
                /* Create a string of the form "a.b.c" */
2258
2296
                int i;
2930
2968
ast_for_classdef(struct compiling *c, const node *n)
2931
2969
{
2932
2970
    /* classdef: 'class' NAME ['(' testlist ')'] ':' suite */
 
2971
    PyObject *classname;
2933
2972
    asdl_seq *bases, *s;
2934
2973
    
2935
2974
    REQ(n, classdef);
2943
2982
        s = ast_for_suite(c, CHILD(n, 3));
2944
2983
        if (!s)
2945
2984
            return NULL;
2946
 
        return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, s, LINENO(n),
 
2985
        classname = NEW_IDENTIFIER(CHILD(n, 1));
 
2986
        if (!classname)
 
2987
            return NULL;
 
2988
        return ClassDef(classname, NULL, s, LINENO(n),
2947
2989
                        n->n_col_offset, c->c_arena);
2948
2990
    }
2949
2991
    /* check for empty base list */
2950
2992
    if (TYPE(CHILD(n,3)) == RPAR) {
2951
 
        s = ast_for_suite(c, CHILD(n,5));
2952
 
        if (!s)
2953
 
                return NULL;
2954
 
        return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, s, LINENO(n),
 
2993
        s = ast_for_suite(c, CHILD(n, 5));
 
2994
        if (!s)
 
2995
            return NULL;
 
2996
        classname = NEW_IDENTIFIER(CHILD(n, 1));
 
2997
        if (!classname)
 
2998
            return NULL;
 
2999
        return ClassDef(classname, NULL, s, LINENO(n),
2955
3000
                        n->n_col_offset, c->c_arena);
2956
3001
    }
2957
3002
 
2963
3008
    s = ast_for_suite(c, CHILD(n, 6));
2964
3009
    if (!s)
2965
3010
        return NULL;
2966
 
    return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), bases, s, LINENO(n),
 
3011
    classname = NEW_IDENTIFIER(CHILD(n, 1));
 
3012
    if (!classname)
 
3013
        return NULL;
 
3014
    return ClassDef(classname, bases, s, LINENO(n),
2967
3015
                    n->n_col_offset, c->c_arena);
2968
3016
}
2969
3017
 
3059
3107
#endif
3060
3108
        if (*end == 'l' || *end == 'L')
3061
3109
                return PyLong_FromString((char *)s, (char **)0, 0);
3062
 
        if (s[0] == '0') {
3063
 
                x = (long) PyOS_strtoul((char *)s, (char **)&end, 0);
3064
 
                if (x < 0 && errno == 0) {
3065
 
                                return PyLong_FromString((char *)s,
3066
 
                                                         (char **)0,
3067
 
                                                         0);
3068
 
                }
3069
 
        }
3070
 
        else
3071
 
                x = PyOS_strtol((char *)s, (char **)&end, 0);
 
3110
        x = PyOS_strtol((char *)s, (char **)&end, 0);
3072
3111
        if (*end == '\0') {
3073
3112
                if (errno != 0)
3074
3113
                        return PyLong_FromString((char *)s, (char **)0, 0);