summaryrefslogtreecommitdiff
path: root/src/logic/amgc_init_unit_meta.c
blob: 8cfd44b1b4ee4ab1e7ec3a02e502f7166f73337c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**********************************************************/
/*  apimagic: cparser-based API normalization utility     */
/*  Copyright (C) 2015--2021  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;
}