~pythonregexp2.7/python/issue2636-09-01+10

« back to all changes in this revision

Viewing changes to Python/ast.c

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-05-24 18:56:40 UTC
  • mfrom: (39055.1.22 Regexp-2.6)
  • Revision ID: darklord@timehorse.com-20080524185640-59vz6l1f7qgixgal
Merged in changes from the Single-Loop Engine branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
/* Note different signature for ast_for_call */
37
37
static expr_ty ast_for_call(struct compiling *, const node *, expr_ty);
38
38
 
39
 
static PyObject *parsenumber(const char *);
 
39
static PyObject *parsenumber(struct compiling *, const char *);
40
40
static PyObject *parsestr(struct compiling *, const char *);
41
41
static PyObject *parsestrplus(struct compiling *, const node *n);
42
42
 
332
332
*/
333
333
 
334
334
static int
335
 
set_context(expr_ty e, expr_context_ty ctx, const node *n)
 
335
set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n)
336
336
{
337
337
    asdl_seq *s = NULL;
338
338
    /* If a particular expression type can't be used for assign / delete,
434
434
        int i;
435
435
 
436
436
        for (i = 0; i < asdl_seq_LEN(s); i++) {
437
 
            if (!set_context((expr_ty)asdl_seq_GET(s, i), ctx, n))
 
437
            if (!set_context(c, (expr_ty)asdl_seq_GET(s, i), ctx, n))
438
438
                return 0;
439
439
        }
440
440
    }
442
442
}
443
443
 
444
444
static operator_ty
445
 
ast_for_augassign(const node *n)
 
445
ast_for_augassign(struct compiling *c, const node *n)
446
446
{
447
447
    REQ(n, augassign);
448
448
    n = CHILD(n, 0);
480
480
}
481
481
 
482
482
static cmpop_ty
483
 
ast_for_comp_op(const node *n)
 
483
ast_for_comp_op(struct compiling *c, const node *n)
484
484
{
485
485
    /* comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'
486
486
               |'is' 'not'
606
606
    }
607
607
 
608
608
    result = Tuple(args, Store, LINENO(n), n->n_col_offset, c->c_arena);
609
 
    if (!set_context(result, Store, n))
 
609
    if (!set_context(c, result, Store, n))
610
610
        return NULL;
611
611
    return result;
612
612
}
947
947
*/
948
948
 
949
949
static int
950
 
count_list_fors(const node *n)
 
950
count_list_fors(struct compiling *c, const node *n)
951
951
{
952
952
    int n_fors = 0;
953
953
    node *ch = CHILD(n, 1);
984
984
*/
985
985
 
986
986
static int
987
 
count_list_ifs(const node *n)
 
987
count_list_ifs(struct compiling *c, const node *n)
988
988
{
989
989
    int n_ifs = 0;
990
990
 
1022
1022
    if (!elt)
1023
1023
        return NULL;
1024
1024
 
1025
 
    n_fors = count_list_fors(n);
 
1025
    n_fors = count_list_fors(c, n);
1026
1026
    if (n_fors == -1)
1027
1027
        return NULL;
1028
1028
 
1066
1066
            expr_ty list_for_expr;
1067
1067
 
1068
1068
            ch = CHILD(ch, 4);
1069
 
            n_ifs = count_list_ifs(ch);
 
1069
            n_ifs = count_list_ifs(c, ch);
1070
1070
            if (n_ifs == -1)
1071
1071
                return NULL;
1072
1072
 
1104
1104
*/
1105
1105
 
1106
1106
static int
1107
 
count_gen_fors(const node *n)
 
1107
count_gen_fors(struct compiling *c, const node *n)
1108
1108
{
1109
1109
    int n_fors = 0;
1110
1110
    node *ch = CHILD(n, 1);
1142
1142
*/
1143
1143
 
1144
1144
static int
1145
 
count_gen_ifs(const node *n)
 
1145
count_gen_ifs(struct compiling *c, const node *n)
1146
1146
{
1147
1147
    int n_ifs = 0;
1148
1148
 
1177
1177
    if (!elt)
1178
1178
        return NULL;
1179
1179
    
1180
 
    n_fors = count_gen_fors(n);
 
1180
    n_fors = count_gen_fors(c, n);
1181
1181
    if (n_fors == -1)
1182
1182
        return NULL;
1183
1183
 
1220
1220
            asdl_seq *ifs;
1221
1221
            
1222
1222
            ch = CHILD(ch, 4);
1223
 
            n_ifs = count_gen_ifs(ch);
 
1223
            n_ifs = count_gen_ifs(c, ch);
1224
1224
            if (n_ifs == -1)
1225
1225
                return NULL;
1226
1226
 
1293
1293
        return Str(str, LINENO(n), n->n_col_offset, c->c_arena);
1294
1294
    }
1295
1295
    case NUMBER: {
1296
 
        PyObject *pynum = parsenumber(STR(ch));
 
1296
        PyObject *pynum = parsenumber(c, STR(ch));
1297
1297
        if (!pynum)
1298
1298
            return NULL;
1299
1299
 
1766
1766
                for (i = 1; i < NCH(n); i += 2) {
1767
1767
                    cmpop_ty newoperator;
1768
1768
 
1769
 
                    newoperator = ast_for_comp_op(CHILD(n, i));
 
1769
                    newoperator = ast_for_comp_op(c, CHILD(n, i));
1770
1770
                    if (!newoperator) {
1771
1771
                        return NULL;
1772
1772
                    }
2065
2065
                          "assignment");
2066
2066
                return NULL;
2067
2067
        }
2068
 
        if(!set_context(expr1, Store, ch))
 
2068
        if(!set_context(c, expr1, Store, ch))
2069
2069
            return NULL;
2070
2070
 
2071
2071
        ch = CHILD(n, 2);
2076
2076
        if (!expr2)
2077
2077
            return NULL;
2078
2078
 
2079
 
        newoperator = ast_for_augassign(CHILD(n, 1));
 
2079
        newoperator = ast_for_augassign(c, CHILD(n, 1));
2080
2080
        if (!newoperator)
2081
2081
            return NULL;
2082
2082
 
2107
2107
            if (!e) 
2108
2108
                return NULL;
2109
2109
 
2110
 
            if (!set_context(e, Store, CHILD(n, i)))
 
2110
            if (!set_context(c, e, Store, CHILD(n, i)))
2111
2111
                return NULL;
2112
2112
 
2113
2113
            asdl_seq_SET(targets, i / 2, e);
2172
2172
        if (!e)
2173
2173
            return NULL;
2174
2174
        asdl_seq_SET(seq, i / 2, e);
2175
 
        if (context && !set_context(e, context, CHILD(n, i)))
 
2175
        if (context && !set_context(c, e, context, CHILD(n, i)))
2176
2176
            return NULL;
2177
2177
    }
2178
2178
    return seq;
2853
2853
        expr_ty e = ast_for_expr(c, CHILD(exc, 3));
2854
2854
        if (!e)
2855
2855
            return NULL;
2856
 
        if (!set_context(e, Store, CHILD(exc, 3)))
 
2856
        if (!set_context(c, e, Store, CHILD(exc, 3)))
2857
2857
            return NULL;
2858
2858
        expression = ast_for_expr(c, CHILD(exc, 1));
2859
2859
        if (!expression)
2975
2975
        if (!optional_vars) {
2976
2976
            return NULL;
2977
2977
        }
2978
 
        if (!set_context(optional_vars, Store, n)) {
 
2978
        if (!set_context(c, optional_vars, Store, n)) {
2979
2979
            return NULL;
2980
2980
        }
2981
2981
        suite_index = 4;
3107
3107
}
3108
3108
 
3109
3109
static PyObject *
3110
 
parsenumber(const char *s)
 
3110
parsenumber(struct compiling *c, const char *s)
3111
3111
{
3112
3112
        const char *end;
3113
3113
        long x;
3114
3114
        double dx;
3115
3115
#ifndef WITHOUT_COMPLEX
3116
 
        Py_complex c;
 
3116
        Py_complex complex;
3117
3117
        int imflag;
3118
3118
#endif
3119
3119
 
3142
3142
        /* XXX Huge floats may silently fail */
3143
3143
#ifndef WITHOUT_COMPLEX
3144
3144
        if (imflag) {
3145
 
                c.real = 0.;
 
3145
                complex.real = 0.;
3146
3146
                PyFPE_START_PROTECT("atof", return 0)
3147
 
                c.imag = PyOS_ascii_atof(s);
3148
 
                PyFPE_END_PROTECT(c)
3149
 
                return PyComplex_FromCComplex(c);
 
3147
                complex.imag = PyOS_ascii_atof(s);
 
3148
                PyFPE_END_PROTECT(complex)
 
3149
                return PyComplex_FromCComplex(complex);
3150
3150
        }
3151
3151
        else
3152
3152
#endif
3159
3159
}
3160
3160
 
3161
3161
static PyObject *
3162
 
decode_utf8(const char **sPtr, const char *end, char* encoding)
 
3162
decode_utf8(struct compiling *c, const char **sPtr, const char *end, char* encoding)
3163
3163
{
3164
3164
#ifndef Py_USING_UNICODE
3165
3165
        Py_FatalError("decode_utf8 should not be called in this build.");
3182
3182
 
3183
3183
#ifdef Py_USING_UNICODE
3184
3184
static PyObject *
3185
 
decode_unicode(const char *s, size_t len, int rawmode, const char *encoding)
 
3185
decode_unicode(struct compiling *c, const char *s, size_t len, int rawmode, const char *encoding)
3186
3186
{
3187
3187
        PyObject *v, *u;
3188
3188
        char *buf;
3213
3213
                                PyObject *w;
3214
3214
                                char *r;
3215
3215
                                Py_ssize_t rn, i;
3216
 
                                w = decode_utf8(&s, end, "utf-16-be");
 
3216
                                w = decode_utf8(c, &s, end, "utf-16-be");
3217
3217
                                if (w == NULL) {
3218
3218
                                        Py_DECREF(u);
3219
3219
                                        return NULL;
3296
3296
        }
3297
3297
#ifdef Py_USING_UNICODE
3298
3298
        if (unicode || Py_UnicodeFlag) {
3299
 
                return decode_unicode(s, len, rawmode, c->c_encoding);
 
3299
                return decode_unicode(c, s, len, rawmode, c->c_encoding);
3300
3300
        }
3301
3301
#endif
3302
3302
        need_encoding = (c->c_encoding != NULL &&