Esempio n. 1
0
static int 
symtable_visit_genexp(struct symtable *st, expr_ty e)
{
	comprehension_ty outermost = ((comprehension_ty)
			 (asdl_seq_GET(e->v.GeneratorExp.generators, 0)));
	/* Outermost iterator is evaluated in current scope */
	VISIT(st, expr, outermost->iter);
	/* Create generator scope for the rest */
	if (!GET_IDENTIFIER(genexpr) ||
	    !symtable_enter_block(st, genexpr, FunctionBlock, (void *)e, 0)) {
		return 0;
	}
	st->st_cur->ste_generator = 1;
	/* Outermost iter is received as an argument */
	if (!symtable_implicit_arg(st, 0)) {
		symtable_exit_block(st, (void *)e);
		return 0;
	}
	VISIT_IN_BLOCK(st, expr, outermost->target, (void*)e);
	VISIT_SEQ_IN_BLOCK(st, expr, outermost->ifs, (void*)e);
	VISIT_SEQ_TAIL_IN_BLOCK(st, comprehension,
				e->v.GeneratorExp.generators, 1, (void*)e);
	VISIT_IN_BLOCK(st, expr, e->v.GeneratorExp.elt, (void*)e);
	return symtable_exit_block(st, (void *)e);
}
Esempio n. 2
0
static int
symtable_visit_params(struct symtable *st, asdl_seq *args, int toplevel)
{
    int i;

    /* go through all the toplevel arguments first */
    for (i = 0; i < asdl_seq_LEN(args); i++) {
        expr_ty arg = (expr_ty)asdl_seq_GET(args, i);
        if (arg->kind == Name_kind) {
            assert(arg->v.Name.ctx == Param ||
                   (arg->v.Name.ctx == Store && !toplevel));
            if (!symtable_add_def(st, arg->v.Name.id, DEF_PARAM))
                return 0;
        }
        else if (arg->kind == Tuple_kind) {
            assert(arg->v.Tuple.ctx == Store);
            if (toplevel) {
                if (!symtable_implicit_arg(st, i))
                    return 0;
            }
        }
        else {
            PyErr_SetString(PyExc_SyntaxError,
                            "invalid expression in parameter list");
            PyErr_SyntaxLocation(st->st_filename,
                                 st->st_cur->ste_lineno);
            return 0;
        }
    }

    if (!toplevel) {
        if (!symtable_visit_params_nested(st, args))
            return 0;
    }

    return 1;
}
Esempio n. 3
0
static int
symtable_handle_comprehension(struct symtable *st, expr_ty e,
                              identifier scope_name, asdl_seq *generators,
                              expr_ty elt, expr_ty value)
{
    int is_generator = (e->kind == GeneratorExp_kind);
    int needs_tmp = !is_generator;
    comprehension_ty outermost = ((comprehension_ty)
                                    asdl_seq_GET(generators, 0));
    /* Outermost iterator is evaluated in current scope */
    VISIT(st, expr, outermost->iter);
    /* Create comprehension scope for the rest */
    if (!scope_name ||
        !symtable_enter_block(st, scope_name, FunctionBlock, (void *)e, 0)) {
        return 0;
    }
    st->st_cur->ste_generator = is_generator;
    /* Outermost iter is received as an argument */
    if (!symtable_implicit_arg(st, 0)) {
        symtable_exit_block(st, (void *)e);
        return 0;
    }
    /* Allocate temporary name if needed */
    if (needs_tmp && !symtable_new_tmpname(st)) {
        symtable_exit_block(st, (void *)e);
        return 0;
    }
    VISIT_IN_BLOCK(st, expr, outermost->target, (void*)e);
    VISIT_SEQ_IN_BLOCK(st, expr, outermost->ifs, (void*)e);
    VISIT_SEQ_TAIL_IN_BLOCK(st, comprehension,
                            generators, 1, (void*)e);
    if (value)
        VISIT_IN_BLOCK(st, expr, value, (void*)e);
    VISIT_IN_BLOCK(st, expr, elt, (void*)e);
    return symtable_exit_block(st, (void *)e);
}