summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/apimagic/apimagic.h15
-rw-r--r--project/common.mk1
-rw-r--r--src/driver/amgc_unit_ctx.c4
-rw-r--r--src/internal/apimagic_driver_impl.h1
-rw-r--r--src/logic/amgc_init_unit_meta.c62
5 files changed, 83 insertions, 0 deletions
diff --git a/include/apimagic/apimagic.h b/include/apimagic/apimagic.h
index 7d17211..500463c 100644
--- a/include/apimagic/apimagic.h
+++ b/include/apimagic/apimagic.h
@@ -65,10 +65,22 @@ struct amgc_driver_ctx {
int nerrors;
};
+struct amgc_unit_meta {
+ int ndefines;
+ int nenums;
+ int nenumvals;
+ int ntypedefs;
+ int nstructs;
+ int nunions;
+ int nfunctions;
+ int ngenerated;
+};
+
struct amgc_unit_ctx {
const char * const * path;
const struct amgc_input * map;
const struct amgc_common_ctx * cctx;
+ const struct amgc_unit_meta * meta;
const struct compilation_unit_t*ccunit;
void * any;
int status;
@@ -91,6 +103,9 @@ amgc_api int amgc_lang_std_from_string (const char * std);
/* utility api */
+/* low-level api */
+amgc_api int amgc_init_unit_meta (const struct amgc_unit_ctx *, struct amgc_unit_meta *);
+
#ifdef __cplusplus
}
#endif
diff --git a/project/common.mk b/project/common.mk
index a717358..7179244 100644
--- a/project/common.mk
+++ b/project/common.mk
@@ -2,6 +2,7 @@ COMMON_SRCS = \
src/driver/amgc_driver_ctx.c \
src/driver/amgc_paradigm_meta.c \
src/driver/amgc_unit_ctx.c \
+ src/logic/amgc_init_unit_meta.c \
src/logic/amgc_map_input.c \
src/skin/amgc_skin_default.c \
diff --git a/src/driver/amgc_unit_ctx.c b/src/driver/amgc_unit_ctx.c
index a37706c..4da986a 100644
--- a/src/driver/amgc_unit_ctx.c
+++ b/src/driver/amgc_unit_ctx.c
@@ -154,8 +154,12 @@ int amgc_get_unit_ctx(
ctx->uctx.path = &ctx->path;
ctx->uctx.map = &ctx->map;
ctx->uctx.cctx = &ctx->cctx;
+ ctx->uctx.meta = &ctx->meta;
ctx->uctx.ccunit= &ctx->ccunit;
+ if (amgc_init_unit_meta(&ctx->uctx,&ctx->meta))
+ return amgc_free_unit_ctx_impl(ctx,-1);
+
*pctx = &ctx->uctx;
return 0;
}
diff --git a/src/internal/apimagic_driver_impl.h b/src/internal/apimagic_driver_impl.h
index beb12b7..98f4465 100644
--- a/src/internal/apimagic_driver_impl.h
+++ b/src/internal/apimagic_driver_impl.h
@@ -25,6 +25,7 @@ struct amgc_unit_ctx_impl {
struct amgc_input map;
struct amgc_common_ctx cctx;
struct amgc_unit_ctx uctx;
+ struct amgc_unit_meta meta;
struct compilation_unit_t ccunit;
};
diff --git a/src/logic/amgc_init_unit_meta.c b/src/logic/amgc_init_unit_meta.c
new file mode 100644
index 0000000..fec660d
--- /dev/null
+++ b/src/logic/amgc_init_unit_meta.c
@@ -0,0 +1,62 @@
+/**********************************************************/
+/* apimagic: cparser-based API normalization utility */
+/* Copyright (C) 2015--2016 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.APIMAGIC. */
+/**********************************************************/
+
+#include <cparser/ast/ast_t.h>
+#include <cparser/ast/entity_t.h>
+
+#include <apimagic/apimagic.h>
+
+int amgc_init_unit_meta(
+ const struct amgc_unit_ctx * uctx,
+ struct amgc_unit_meta * meta)
+{
+ union entity_t * entity;
+
+ entity = uctx->ccunit->ast->scope.first_entity;
+
+ for (; entity; entity=entity->base.next) {
+ if (strcmp(*uctx->path,entity->base.pos.input_name))
+ continue;
+
+ if ((is_declaration(entity)) && (entity->declaration.implicit))
+ meta->ngenerated++;
+
+ else {
+ switch (entity->kind) {
+ case ENTITY_ENUM:
+ meta->nenums++;
+ break;
+
+ case ENTITY_ENUM_VALUE:
+ meta->nenumvals++;
+ break;
+
+ case ENTITY_TYPEDEF:
+ meta->ntypedefs++;
+ break;
+
+ case ENTITY_STRUCT:
+ if (entity->base.symbol || entity->compound.alias)
+ meta->nstructs++;
+ break;
+
+ case ENTITY_UNION:
+ if (entity->base.symbol || entity->compound.alias)
+ meta->nunions++;
+ break;
+
+ case ENTITY_FUNCTION:
+ meta->nfunctions++;
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+
+ return 0;
+}