summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/output/amgc_output_typedef.c64
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;
+}