summaryrefslogtreecommitdiff
path: root/src/output/amgc_output_typedef.c
blob: f7b39d42af36751ebb3160614ea8deeda6fbcd30 (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
/**********************************************************/
/*  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;

	(void)fout;

	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;

	(void)uctx;

	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;

		default:
			ret = -1;
	}

	if (ret)
		return ret;

	if (layout && layout->footer && (fputs(layout->footer,fout) < 0))
		return -1;


	return ret;
}