diff options
author | midipix <writeonce@midipix.org> | 2016-01-08 11:46:57 -0500 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2016-01-09 05:32:49 -0500 |
commit | 25ada875049465fcdd5cce98e7f879d6713b654f (patch) | |
tree | 4ec1cbcd297dbced12950e3986b9a64ea37c70df /src/output | |
parent | 91ea2cf923f5f365244d457b828f4dbc1c23cc76 (diff) | |
download | apimagic-25ada875049465fcdd5cce98e7f879d6713b654f.tar.bz2 apimagic-25ada875049465fcdd5cce98e7f879d6713b654f.tar.xz |
amgc_output_typedef(): initial implementation.
Diffstat (limited to 'src/output')
-rw-r--r-- | src/output/amgc_output_typedef.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/output/amgc_output_typedef.c b/src/output/amgc_output_typedef.c new file mode 100644 index 0000000..2400916 --- /dev/null +++ b/src/output/amgc_output_typedef.c @@ -0,0 +1,64 @@ +/**********************************************************/ +/* apimagic: cparser-based API normalization utility */ +/* Copyright (C) 2015--2016 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.APIMAGIC. */ +/**********************************************************/ + +#include <stdio.h> + +#include <cparser/ast/ast_t.h> +#include <cparser/ast/type_t.h> +#include <cparser/ast/entity_t.h> +#include <cparser/ast/symbol_t.h> + +#include <apimagic/apimagic.h> +#include "apimagic_driver_impl.h" + +static int output_atomic_typedef( + const struct amgc_entity * aentity, + FILE * fout) +{ + int i; + const char * reftype; + + reftype = get_atomic_kind_name(aentity->reftype->atomic.akind); + + if (fprintf(stdout,"typedef %s ",reftype) < 0) + return -1; + + for (i=0; (i < aentity->ptrdepth); i++) + if (fputc('*',stdout) < 0) + return -1; + + if (fprintf(stdout," %s;\n",aentity->entity->base.symbol->string) < 0) + return -1; + + return 0; +} + +int amgc_output_typedef( + const struct amgc_unit_ctx * uctx, + const struct amgc_entity * aentity, + const struct amgc_layout * layout, + FILE * fout) +{ + int ret = 0; + + if (layout && layout->header && (fputs(layout->header,fout) < 0)) + return -1; + + switch (aentity->reftype->kind) { + case TYPE_ATOMIC: + ret = output_atomic_typedef(aentity,fout); + break; + } + + if (ret) + return ret; + + if (layout && layout->footer && (fputs(layout->footer,fout) < 0)) + return -1; + + + return ret; +} |