summaryrefslogtreecommitdiffhomepage
path: root/src/output/amgc_output_typedef.c
blob: 76f69625c659fccd9e113ffb9dac27f654795492 (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
63
64
65
66
67
68
69
70
71
72
73
/**********************************************************/
/*  apimagic: cparser-based API normalization utility     */
/*  Copyright (C) 2015--2021  SysDeer Technologies, LLC   */
/*  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(int fdout, const struct amgc_entity * aentity)
{
	int		i;
	const char *	reftype;

	reftype = get_atomic_kind_name(aentity->reftype->atomic.akind);

	if (amgc_dprintf(fdout,"typedef %s ",reftype) < 0)
		return -1;

	for (i=0; (i < aentity->ptrdepth); i++)
		if (amgc_dprintf(fdout,"*") < 0)
			return -1;

	if (amgc_dprintf(
			fdout," %s;\n",
			aentity->entity->base.symbol->string) < 0)
		return -1;

	return 0;
}

int amgc_output_typedef(
	const struct amgc_driver_ctx *	dctx,
	const struct amgc_unit_ctx *	uctx,
	const struct amgc_entity *	aentity,
	const struct amgc_layout *	layout)
{
	int ret   = 0;
	int fdout = amgc_driver_fdout(dctx);

	(void)uctx;

	switch (aentity->reftype->kind) {
		case TYPE_ATOMIC:
			break;

		default:
			return -1;
	}

	if (layout && layout->header)
		if (amgc_dprintf(fdout,layout->header) < 0)
			return -1;

	if (aentity->reftype->kind == TYPE_ATOMIC)
		ret = output_atomic_typedef(fdout,aentity);

	if (ret < 0)
		return ret;

	if (layout && layout->footer)
		if (amgc_dprintf(fdout,layout->footer) < 0)
			return -1;

	return 0;
}