const char *decl_store_to_str(const enum decl_storage s) { static char buf[16]; /* "inline register" is the longest - just a fit */ if(s & STORE_MASK_EXTRA){ char *trail_space = NULL; *buf = '\0'; if((s & STORE_MASK_EXTRA) == store_inline){ strcpy(buf, "inline "); trail_space = buf + strlen("inline"); } strcpy(buf + strlen(buf), decl_store_to_str(s & STORE_MASK_STORE)); if(trail_space && trail_space[1] == '\0') *trail_space = '\0'; return buf; } switch(s){ case store_inline: ICE("inline"); case store_default: return ""; CASE_STR_PREFIX(store, auto); CASE_STR_PREFIX(store, static); CASE_STR_PREFIX(store, extern); CASE_STR_PREFIX(store, register); CASE_STR_PREFIX(store, typedef); } return NULL; }
enum visibility decl_visibility(decl *d) { attribute *visibility = attribute_present(d, attr_visibility); if(visibility) return visibility->bits.visibility; switch((d->store & STORE_MASK_STORE)){ case store_extern: /* no explicit visibility, -fvisibility doesn't affect extern decls */ return VISIBILITY_DEFAULT; case store_default: /* if it's not in this translation unit it's essentially an extern decl */ if(!decl_defined(d, 0)) return VISIBILITY_DEFAULT; break; case store_static: break; case store_auto: case store_register: case store_typedef: ICE("shouldn't be calling decl_visibility() on a %s decl", decl_store_to_str(d->store & STORE_MASK_STORE)); } return cc1_visibility_default; }
void flow_fold(stmt_flow *flow, symtable **pstab) { if(flow){ decl **i; *pstab = flow->for_init_symtab; fold_shadow_dup_check_block_decls(*pstab); /* sanity check on _flow_ vars only */ for(i = symtab_decls(*pstab); i && *i; i++){ decl *const d = *i; switch((enum decl_storage)(d->store & STORE_MASK_STORE)){ case store_auto: case store_default: case store_register: break; default: die_at(&d->where, "%s variable in statement-initialisation", decl_store_to_str(d->store)); } /* block decls/for-init decls must be complete */ fold_check_decl_complete(d); if(d->bits.var.init.expr) FOLD_EXPR(d->bits.var.init.expr, *pstab); } } }
const char *decl_store_spel_type_to_str_r( char buf[DECL_STATIC_BUFSIZ], enum decl_storage store, const char *spel, type *ty) { char *bufp = buf; if(store) bufp += snprintf(bufp, DECL_STATIC_BUFSIZ, "%s ", decl_store_to_str(store)); type_to_str_r_spel(bufp, ty, spel); return buf; }
void print_decl(decl *d, enum pdeclargs mode) { if(mode & PDECL_INDENT) idt_print(); if(d->store) fprintf(cc1_out, "%s ", decl_store_to_str(d->store)); if(fopt_mode & FOPT_ENGLISH){ print_decl_eng(d); }else{ print_type(d->ref, d); } if(mode & PDECL_SYM_OFFSET){ if(d->sym){ const int off = d->sym->type == sym_arg ? d->sym->loc.arg_offset : (int)d->sym->loc.stack_pos; fprintf(cc1_out, " (sym %s, pos = %d)", sym_to_str(d->sym->type), off); }else{ fprintf(cc1_out, " (no sym)"); } } if(mode & PDECL_SIZE && !type_is(d->ref, type_func)){ if(type_is_complete(d->ref)){ const unsigned sz = decl_size(d); const unsigned align = decl_align(d); fprintf(cc1_out, " size %u, align %u", sz, align); }else{ fprintf(cc1_out, " incomplete decl"); } } if(mode & PDECL_NEWLINE) fputc('\n', cc1_out); if(!type_is(d->ref, type_func) && d->bits.var.init.dinit && mode & PDECL_PINIT) { gen_str_indent++; print_decl_init(d->bits.var.init.dinit); gen_str_indent--; } if(mode & PDECL_ATTR){ gen_str_indent++; if(!type_is(d->ref, type_func) && d->bits.var.align) idt_printf("[align={as_int=%d, resolved=%d}]\n", d->bits.var.align->as_int, d->bits.var.align->resolved); print_attribute(d->attr); print_type_attr(d->ref); gen_str_indent--; } if((mode & PDECL_FUNC_DESCEND) && DECL_HAS_FUNC_CODE(d)){ decl **iter; gen_str_indent++; for(iter = d->bits.func.code->symtab->decls; iter && *iter; iter++){ sym *s = (*iter)->sym; if(s) idt_printf("offset of %s = %d\n", (*iter)->spel, s->loc.stack_pos); } idt_printf("function stack space %d\n", d->bits.func.code->symtab->auto_total_size); print_stmt(d->bits.func.code); gen_str_indent--; } }
void dump_decl(decl *d, dump *ctx, const char *desc) { const int is_func = !!type_is(d->ref, type_func); type *ty; if(!desc){ if(d->spel){ desc = is_func ? "function" : "variable"; }else{ desc = "type"; } } dump_desc_colour_newline(ctx, desc, d, &d->where, maybe_colour(ctx->fout, col_desc_decl), 0); if(d->proto) dump_printf_indent(ctx, 0, " prev %p", (void *)d->proto); if(d->spel) dump_printf_indent(ctx, 0, " %s", d->spel); dump_type(ctx, d->ref); if(d->store) dump_printf_indent(ctx, 0, " %s", decl_store_to_str(d->store)); dump_printf_indent(ctx, 0, "\n"); if(!is_func){ type *tof = type_skip_non_tdefs(d->ref); if(tof->type == type_tdef && !tof->bits.tdef.decl){ /* show typeof expr */ dump_inc(ctx); dump_expr(tof->bits.tdef.type_of, ctx); dump_dec(ctx); } if(d->bits.var.field_width){ dump_inc(ctx); dump_expr(d->bits.var.field_width, ctx); dump_dec(ctx); } if(!d->spel){ dump_sue(ctx, d->ref); }else if(d->bits.var.init.dinit){ dump_inc(ctx); dump_init(ctx, d->bits.var.init.dinit); dump_dec(ctx); } } dump_inc(ctx); dump_attributes(d->attr, ctx); ty = type_skip_non_attr(d->ref); if(ty && ty->type == type_attr) dump_attributes(ty->bits.attr, ctx); dump_dec(ctx); if(is_func && d->bits.func.code){ funcargs *fa = type_funcargs(d->ref); dump_inc(ctx); dump_args(fa, ctx); dump_stmt(d->bits.func.code, ctx); dump_dec(ctx); } }