void fold_expr_cast(expr *e, symtable *stab) { fold_expr(e->expr, stab); fold_disallow_st_un(e->expr, "cast-expr"); /* * if we don't have a valid tree_type, get one * this is only the case where we're involving a tdef or typeof */ if(e->tree_type->type->primitive == type_unknown) { decl_free(e->tree_type); e->tree_type = decl_copy(e->expr->tree_type); } fold_decl(e->tree_type, stab); /* struct lookup, etc */ fold_disallow_st_un(e, "cast-target"); #ifdef CAST_COLLAPSE if(expr_kind(e->expr, cast)) { /* get rid of e->expr, replace with e->expr->rhs */ expr *del = e->expr; e->expr = e->expr->expr; /*decl_free(del->tree_type); XXX: memleak */ expr_free(del); fold_expr_cast(e, stab); } #endif }
static void check_implicit_funcall(expr *e, symtable *stab, char **const psp) { struct symtab_entry ent; funcargs *args; decl *df, *owning_func; type *func_ty; if(e->expr->in_parens || !expr_kind(e->expr, identifier) /* not folded yet, hence no 'e->expr->bits.ident.type != IDENT_NORM' */ /* get the spel that parse stashes in the identifier expr: */ || !((*psp) = e->expr->bits.ident.bits.ident.spel)) { return; } /* check for implicit function */ if(symtab_search(stab, *psp, NULL, &ent) && ent.type == SYMTAB_ENT_DECL) { e->expr->bits.ident.bits.ident.sym = ent.bits.decl->sym; return; } args = funcargs_new(); /* set up the funcargs as if it's "x()" - i.e. any args */ funcargs_empty(args); func_ty = type_func_of( type_nav_btype(cc1_type_nav, type_int), args, symtab_new(stab, &e->where) /*new symtable for args*/); cc1_warn_at(&e->expr->where, implicit_func, "implicit declaration of function \"%s\"", *psp); df = decl_new(); memcpy_safe(&df->where, &e->where); df->ref = func_ty; df->spel = e->expr->bits.ident.bits.ident.spel; df->flags |= DECL_FLAGS_IMPLICIT; fold_decl(df, stab); /* update calling conv, for e.g. */ df->sym->type = sym_global; e->expr->bits.ident.bits.ident.sym = df->sym; e->expr->tree_type = func_ty; owning_func = symtab_func(stab); if(owning_func) symtab_insert_before(symtab_root(stab), owning_func, df); else symtab_add_to_scope(symtab_root(stab), df); /* function call at global scope */ }
expr *fold_for_if_init_decls(stmt *s) { decl **i; expr *init_exp = NULL; for(i = s->flow->for_init_decls; *i; i++){ decl *const d = *i; fold_decl(d, s->flow->for_init_symtab); switch(d->type->store){ case store_auto: case store_default: case store_register: break; default: DIE_AT(&d->where, "%s variable in %s declaration initialisation", type_store_to_str(d->type->store), s->f_str()); } SYMTAB_ADD(s->flow->for_init_symtab, d, sym_local); /* make the for-init a comma-exp with all our inits */ if(d->init){ expr *dinit = expr_new_decl_init(d); if(init_exp){ expr *comma = expr_new_comma(); /* change this to an &&-op for if(char *x = .., *y = ..) anding */ comma->lhs = init_exp; comma->rhs = dinit; init_exp = comma; }else{ init_exp = dinit; } } } return init_exp; }