static void dump_sue(dump *ctx, type *ty) { struct_union_enum_st *sue = type_is_s_or_u_or_e(ty); sue_member **mi; if(!sue) return; dump_inc(ctx); for(mi = sue->members; mi && *mi; mi++){ if(sue->primitive == type_enum){ enum_member *emem = (*mi)->enum_member; dump_desc(ctx, emem->spel, emem, &emem->where); if(emem->val && emem->val != (expr *)-1){ dump_inc(ctx); dump_expr(emem->val, ctx); dump_dec(ctx); } dump_attributes(emem->attr, ctx); }else{ decl *d = (*mi)->struct_member; dump_decl(d, ctx, "member"); dump_sue(ctx, d->ref); } } dump_dec(ctx); }
void dump_expr_assign(const expr *e, dump *ctx) { dump_desc_expr(ctx, "assignment", e); dump_inc(ctx); dump_expr(e->lhs, ctx); dump_dec(ctx); dump_inc(ctx); dump_expr(e->rhs, ctx); dump_dec(ctx); }
void dump_expr_addr(const expr *e, dump *ctx) { if(e->bits.lbl.spel){ dump_desc_expr(ctx, "label address", e); dump_inc(ctx); dump_strliteral(ctx, e->bits.lbl.spel, strlen(e->bits.lbl.spel)); dump_dec(ctx); }else{ dump_desc_expr(ctx, "address-of", e); dump_inc(ctx); dump_expr(e->lhs, ctx); dump_dec(ctx); } }
void dump_expr_funcall(const expr *e, dump *ctx) { expr **iter; dump_desc_expr(ctx, "call", e); dump_inc(ctx); dump_expr(e->expr, ctx); dump_dec(ctx); dump_inc(ctx); for(iter = e->funcargs; iter && *iter; iter++) dump_expr(*iter, ctx); dump_dec(ctx); }
void dump_expr_stmt(const expr *e, dump *ctx) { dump_desc_expr(ctx, "statement expression", e); dump_inc(ctx); dump_stmt(e->code, ctx); dump_dec(ctx); }
static void dump_gasm(symtable_gasm *gasm, dump *ctx) { dump_desc(ctx, "global asm", gasm, &gasm->where); dump_inc(ctx); dump_strliteral(ctx, gasm->asm_str, strlen(gasm->asm_str)); dump_dec(ctx); }
void dump_stmt_label(const stmt *s, dump *ctx) { dump_desc_stmt_newline(ctx, "label", s, 0); dump_printf_indent(ctx, 0, " %s\n", s->bits.lbl.spel); dump_inc(ctx); dump_stmt(s->lhs, ctx); dump_dec(ctx); }
void dump_expr_compound_lit(const expr *e, dump *ctx) { decl *const d = e->bits.complit.decl; dump_desc_expr(ctx, "compound literal", e); dump_inc(ctx); dump_init(ctx, d->bits.var.init.dinit); dump_dec(ctx); }
void dump_stmt_goto(const stmt *s, dump *ctx) { if(s->expr){ dump_desc_stmt(ctx, "computed-goto", s); dump_inc(ctx); dump_expr(s->expr, ctx); dump_dec(ctx); }else{ dump_desc_stmt_newline(ctx, "goto", s, 0); dump_printf_indent(ctx, 0, " %s\n", s->bits.lbl.spel); } }
void dump_stmt_if(const stmt *s, dump *ctx) { dump_desc_stmt(ctx, "if", s); dump_inc(ctx); dump_flow(s->flow, ctx); dump_expr(s->expr, ctx); dump_stmt(s->lhs, ctx); if(s->rhs) dump_stmt(s->rhs, ctx); dump_dec(ctx); }
void dump_stmt_for(const stmt *s, dump *ctx) { dump_desc_stmt(ctx, "for", s); dump_inc(ctx); dump_flow(s->flow, ctx); if(s->flow->for_init) dump_expr(s->flow->for_init, ctx); if(s->flow->for_while) dump_expr(s->flow->for_while, ctx); if(s->flow->for_inc) dump_expr(s->flow->for_inc, ctx); dump_stmt(s->lhs, ctx); dump_dec(ctx); }
void dump_expr_if(const expr *e, dump *ctx) { dump_desc_expr(ctx, "conditional", e); dump_inc(ctx); dump_expr(e->expr, ctx); if(e->lhs) dump_expr(e->lhs, ctx); else dump_printf(ctx, "?: lhs\n"); dump_expr(e->rhs, ctx); dump_dec(ctx); }
void dump_expr_assign_compound(const expr *e, dump *ctx) { dump_desc_expr_newline(ctx, "compound assignment", e, 0); dump_printf_indent(ctx, 0, " %s%s=", e->assign_is_post ? "post-assignment " : "", op_to_str(e->bits.compoundop.op)); if(e->bits.compoundop.upcast_ty){ dump_printf_indent(ctx, 0, " upcast='%s'", type_to_str(e->bits.compoundop.upcast_ty)); } dump_printf_indent(ctx, 0, "\n"); dump_inc(ctx); dump_expr(e->lhs, ctx); dump_expr(e->rhs, ctx); dump_dec(ctx); }
void dump_init(dump *ctx, decl_init *dinit) { if(dinit == DYNARRAY_NULL){ dump_printf(ctx, "<null init>\n"); return; } switch(dinit->type){ case decl_init_scalar: { dump_expr(dinit->bits.expr, ctx); break; } case decl_init_brace: { decl_init **i; dump_desc(ctx, "brace init", dinit, &dinit->where); dump_inc(ctx); for(i = dinit->bits.ar.inits; i && *i; i++) dump_init(ctx, *i); dump_dec(ctx); break; } case decl_init_copy: { struct init_cpy *cpy = *dinit->bits.range_copy; dump_init(ctx, cpy->range_init); break; } } }
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); } }