summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/apimagic/apimagic.h1
-rw-r--r--project/common.mk1
-rw-r--r--src/output/amgc_output_typedef.c64
3 files changed, 66 insertions, 0 deletions
diff --git a/include/apimagic/apimagic.h b/include/apimagic/apimagic.h
index 7876527..23e8a48 100644
--- a/include/apimagic/apimagic.h
+++ b/include/apimagic/apimagic.h
@@ -192,6 +192,7 @@ amgc_api int amgc_get_function_index (const struct amgc_unit_ctx *, const char
amgc_api int amgc_output_pad_symbol (const char *, const struct amgc_layout *, FILE *);
amgc_api int amgc_output_unit_enum (const struct amgc_unit_ctx *, const union entity_t *, const struct amgc_layout *, FILE *);
amgc_api int amgc_output_custom_enum (const struct amgc_entity *, const struct amgc_entity[], const struct amgc_layout *, FILE *);
+amgc_api int amgc_output_typedef (const struct amgc_unit_ctx *, const struct amgc_entity *, const struct amgc_layout *, FILE *);
/* low-level api */
amgc_api int amgc_init_unit_meta (const struct amgc_unit_ctx *, struct amgc_unit_meta *);
diff --git a/project/common.mk b/project/common.mk
index 1f75489..8a14c46 100644
--- a/project/common.mk
+++ b/project/common.mk
@@ -8,6 +8,7 @@ COMMON_SRCS = \
src/logic/amgc_unit_entities.c \
src/output/amgc_output_enum.c \
src/output/amgc_output_pad_symbol.c \
+ src/output/amgc_output_typedef.c \
src/skin/amgc_skin_default.c \
APP_SRCS = \
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;
+}