diff options
Diffstat (limited to 'src/output/amgc_output_compound.c')
-rw-r--r-- | src/output/amgc_output_compound.c | 112 |
1 files changed, 57 insertions, 55 deletions
diff --git a/src/output/amgc_output_compound.c b/src/output/amgc_output_compound.c index 312d475..1736a06 100644 --- a/src/output/amgc_output_compound.c +++ b/src/output/amgc_output_compound.c @@ -16,14 +16,14 @@ #include "apimagic_driver_impl.h" static int output_string( - FILE * fout, + int * fdout, const char * fmt, const char * string, const char * brace, int * len) { - int ret = fout - ? fprintf(fout,fmt,string,brace) + int ret = fdout + ? amgc_dprintf(*fdout,fmt,string,brace) : snprintf(0,0,fmt,string,brace); if (len && (ret > 0)) @@ -36,7 +36,7 @@ static int output_compound( union entity_t const * entity, int depth, const struct amgc_layout * layout, - FILE * fout) + int * fdout) { struct compound_t const * compound; type_qualifiers_t tquals; @@ -104,14 +104,14 @@ static int output_compound( } - if (depth && fout && (fputc('\n',fout) < 0)) + if (depth && fdout && (amgc_dprintf(*fdout,"\n") < 0)) return -1; for (i=0; i<depth; i++) - if (output_string(fout,"\t","","",0) < 0) + if (output_string(fdout,"\t","","",0) < 0) return -1; - if (output_string(fout,fmt,name,brace,&len) < 0) + if (output_string(fdout,fmt,name,brace,&len) < 0) return -1; @@ -156,7 +156,7 @@ static int output_compound( if (output_compound( entity,depth, - layout,fout) < 0) + layout,fdout) < 0) return -1; } @@ -171,8 +171,10 @@ static int output_compound( fmt = ""; name = ""; - if (fout) - fprintf(fout,"UNHANDLED TYPE! %d ", + if (fdout) + amgc_dprintf( + *fdout, + "UNHANDLED TYPE! %d ", type->kind); break; @@ -180,14 +182,14 @@ static int output_compound( if (ftabs) for (i=0; i<depth; i++) - if (output_string(fout,"\t","","",0) < 0) + if (output_string(fdout,"\t","","",0) < 0) return -1; if (tquals & TYPE_QUALIFIER_CONST) - if (output_string(fout,"const ","","",&len) < 0) + if (output_string(fdout,"const ","","",&len) < 0) return -1; - if (output_string(fout,fmt,name,"",&len) < 0) + if (output_string(fdout,fmt,name,"",&len) < 0) return -1; for (fspace=ptrdepth; ptrdepth; ptrdepth--) { @@ -201,18 +203,18 @@ static int output_compound( if (type->base.qualifiers & TYPE_QUALIFIER_CONST) if (type->kind == TYPE_POINTER) - if (output_string(fout," const ", + if (output_string(fdout," const ", "","",&len) < 0) return -1; - if (output_string(fout,"*","","",&len) < 0) + if (output_string(fdout,"*","","",&len) < 0) return -1; } if (fspace) len++; - if (fout) { + if (fdout) { symwidth = layout->symwidth; symwidth += layout->tabwidth; @@ -221,7 +223,7 @@ static int output_compound( len &= (~(layout->tabwidth-1)); while (len < symwidth) { - if (fputc('\t',fout) < 0) + if (amgc_dprintf(*fdout,"\t") < 0) return -1; else len += layout->tabwidth; @@ -229,15 +231,16 @@ static int output_compound( } else if (len > width) width = len; - if (output_string(fout,"%s", + if (output_string(fdout,"%s", entity->base.symbol->string, "",0) < 0) return -1; type = entity->declaration.type; - while (fout && type->kind == TYPE_ARRAY) { - if (fprintf(fout, + while (fdout && type->kind == TYPE_ARRAY) { + if (amgc_dprintf( + *fdout, type->array.size ? "[%zu]" : "[]", type->array.size) < 0) return -1; @@ -245,26 +248,26 @@ static int output_compound( type = type->array.element_type; } - if (fout && fputs(";\n",fout) < 0) + if (fdout && amgc_dprintf(*fdout,";\n") < 0) return -1; - if (!ftabs && fout && entity->base.next) - if (fputc('\n',fout) < 0) + if (!ftabs && fdout && entity->base.next) + if (amgc_dprintf(*fdout,"\n") < 0) return -1; } - if (!fout) + if (!fdout) return width; if (--depth) { for (i=0; i<depth; i++) - if (output_string(fout,"\t","","",0) < 0) + if (output_string(fdout,"\t","","",0) < 0) return -1; - if (output_string(fout,"} ","","",0) < 0) + if (output_string(fdout,"} ","","",0) < 0) return -1; } else { - if (output_string(fout,"};\n","","",0) < 0) + if (output_string(fdout,"};\n","","",0) < 0) return -1; } @@ -272,17 +275,18 @@ static int output_compound( } static int output_compound_entity( + const struct amgc_driver_ctx * dctx, const struct amgc_unit_ctx * uctx, const struct amgc_entity * aentity, - const struct amgc_layout * layout, - FILE * fout) + const struct amgc_layout * layout) { struct amgc_layout elayout; + int fdout = amgc_driver_fdout(dctx); (void)uctx; if (layout && layout->symwidth) - return output_compound(aentity->entity,0,layout,fout); + return output_compound(aentity->entity,0,layout,&fdout); if (layout) memcpy(&elayout,layout,sizeof(elayout)); @@ -295,83 +299,81 @@ static int output_compound_entity( if (elayout.tabwidth == 0) elayout.tabwidth = AMGC_TAB_WIDTH; - if (output_compound(aentity->entity,0,&elayout,fout) < 0) + if (output_compound(aentity->entity,0,&elayout,&fdout) < 0) return -1; return 0; } int amgc_output_compound( + const struct amgc_driver_ctx * dctx, const struct amgc_unit_ctx * uctx, const struct amgc_entity * aentity, - const struct amgc_layout * layout, - FILE * fout) + const struct amgc_layout * layout) { union entity_t const * entity; entity = aentity->entity; - if ((entity->kind == ENTITY_STRUCT) || (entity->kind == ENTITY_UNION)) - return output_compound_entity(uctx,aentity,layout,fout); - else - return -1; + return ((entity->kind == ENTITY_STRUCT) || (entity->kind == ENTITY_UNION)) + ? output_compound_entity(dctx,uctx,aentity,layout) + : -1; } int amgc_output_struct( + const struct amgc_driver_ctx * dctx, const struct amgc_unit_ctx * uctx, const struct amgc_entity * aentity, - const struct amgc_layout * layout, - FILE * fout) + const struct amgc_layout * layout) { union entity_t const * entity; entity = aentity->entity; - if (entity->kind == ENTITY_STRUCT) - return output_compound_entity(uctx,aentity,layout,fout); - else - return -1; + return (entity->kind == ENTITY_STRUCT) + ? output_compound_entity(dctx,uctx,aentity,layout) + : -1; } int amgc_output_union( + const struct amgc_driver_ctx * dctx, const struct amgc_unit_ctx * uctx, const struct amgc_entity * aentity, - const struct amgc_layout * layout, - FILE * fout) + const struct amgc_layout * layout) { union entity_t const * entity; entity = aentity->entity; - if (entity->kind == ENTITY_UNION) - return output_compound_entity(uctx,aentity,layout,fout); - else - return -1; + return (entity->kind == ENTITY_UNION) + ? output_compound_entity(dctx,uctx,aentity,layout) + : -1; + } int amgc_output_unit_structs( + const struct amgc_driver_ctx * dctx, const struct amgc_unit_ctx * uctx, - const struct amgc_layout * layout, - FILE * fout) + const struct amgc_layout * layout) { const struct amgc_entity * aentity; for (aentity=uctx->entities->structs; aentity->entity; aentity++) - if (output_compound_entity(uctx,aentity,layout,fout)) + if (output_compound_entity(dctx,uctx,aentity,layout) < 0) return -1; return 0; } int amgc_output_unit_unions( + const struct amgc_driver_ctx * dctx, const struct amgc_unit_ctx * uctx, - const struct amgc_layout * layout, - FILE * fout) + const struct amgc_layout * layout) { const struct amgc_entity * aentity; for (aentity=uctx->entities->unions; aentity->entity; aentity++) - if (output_compound_entity(uctx,aentity,layout,fout)) + if (output_compound_entity(dctx,uctx,aentity,layout) < 0) return -1; return 0; |