blob: 8f032211ec4765f3cc756256b50ab5f96030cf20 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001#ifndef _ASN1_COMPILED_OUTPUT_H_
2#define _ASN1_COMPILED_OUTPUT_H_
3
4/*
5 * An elementary chunk of target language text.
6 */
7typedef struct out_chunk {
8 char *buf;
9 int len;
10
11 TQ_ENTRY(struct out_chunk) next;
12} out_chunk_t;
13
14typedef struct compiler_streams {
15 enum {
Lev Walkin61c70692004-09-08 00:28:47 +000016 OT_IGNORE, /* Ignore this output */
Lev Walkin3dcaafa2004-08-11 05:21:32 +000017 OT_INCLUDES, /* #include files */
18 OT_DEPS, /* Dependencies (other than #includes) */
Lev Walkinf15320b2004-06-03 03:38:44 +000019 OT_TYPE_DECLS, /* Type declarations */
20 OT_FUNC_DECLS, /* Function declarations */
Lev Walkin59004fa2004-08-20 13:37:01 +000021 OT_CTABLES, /* Constraint tables */
Lev Walkinf15320b2004-06-03 03:38:44 +000022 OT_CODE, /* Some code */
Lev Walkin59004fa2004-08-20 13:37:01 +000023 OT_STAT_DEFS, /* Static definitions */
Lev Walkinf15320b2004-06-03 03:38:44 +000024 OT_MAX
25 } target;
Lev Walkin59004fa2004-08-20 13:37:01 +000026
27 struct compiler_stream_destination_s {
28 TQ_HEAD(out_chunk_t) chunks;
29 int indent_level;
30 int indented;
31 } destination[OT_MAX];
Lev Walkinf15320b2004-06-03 03:38:44 +000032} compiler_streams_t;
33
34static char *_compiler_stream2str[] __attribute__ ((unused))
Lev Walkin61c70692004-09-08 00:28:47 +000035 = { "IGNORE", "INCLUDES", "DEPS", "TYPE-DECLS", "FUNC-DECLS", "CTABLES", "CODE", "STAT-DEFS" };
Lev Walkinf15320b2004-06-03 03:38:44 +000036
37int asn1c_compiled_output(arg_t *arg, const char *fmt, ...);
38
Lev Walkin3dcaafa2004-08-11 05:21:32 +000039
40/*****************************************************************
41 * Useful macros for invoking asn1c_compiled_output() and friends.
42 */
43
44/* Redirect output to a different stream. */
45#define REDIR(foo) do { arg->target->target = foo; } while(0)
Lev Walkin59004fa2004-08-20 13:37:01 +000046#define INDENT_LEVEL \
47 arg->target->destination[arg->target->target].indent_level
48#define INDENT(val) INDENT_LEVEL += (val)
49#define INDENTED(code) do { \
50 INDENT(+1); \
51 do { code; } while(0); \
52 INDENT(-1); \
Lev Walkin3dcaafa2004-08-11 05:21:32 +000053 } while(0)
54
Lev Walkin3dcaafa2004-08-11 05:21:32 +000055#define EMBED(ev) do { \
56 int saved_target = arg->target->target; \
57 REDIR(OT_TYPE_DECLS); \
58 arg->embed++; \
59 INDENTED(arg_t _tmp = *arg; \
60 _tmp.expr = ev; \
61 _tmp.default_cb(&_tmp); \
62 ); \
63 arg->embed--; \
Lev Walkin6fec44d2004-08-22 03:10:23 +000064 if(ev->expr_type != A1TC_EXTENSIBLE) \
65 OUT(";\n"); \
Lev Walkin3dcaafa2004-08-11 05:21:32 +000066 assert(arg->target->target == OT_TYPE_DECLS); \
67 REDIR(saved_target); \
68 } while(0)
69
70/* Output a piece of text into a default stream */
71#define OUT(fmt, args...) asn1c_compiled_output(arg, fmt, ##args)
Lev Walkin59004fa2004-08-20 13:37:01 +000072#define OUT_NOINDENT(fmt, args...) do { \
73 int _saved_indent = INDENT_LEVEL; \
74 INDENT_LEVEL = 0; \
75 OUT(fmt, ##args); \
76 INDENT_LEVEL = _saved_indent; \
Lev Walkin3dcaafa2004-08-11 05:21:32 +000077} while(0)
78
79/* Generate #include line */
80#define GEN_INCLUDE(filename) do { \
81 int saved_target = arg->target->target; \
82 REDIR(OT_INCLUDES); \
83 OUT_NOINDENT("#include <%s.h>\n", filename); \
84 REDIR(saved_target); \
85} while(0)
86
87/* Generate ASN.1 type declaration */
88#define GEN_DECLARE(expr) do { \
89 int saved_target = arg->target->target; \
90 REDIR(OT_DEPS); \
Lev Walkin05363a72004-09-29 13:16:40 +000091 OUT_NOINDENT("extern asn_TYPE_descriptor_t " \
92 "asn_DEF_%s;\n", \
Lev Walkin3dcaafa2004-08-11 05:21:32 +000093 MKID(expr->Identifier)); \
94 REDIR(saved_target); \
95} while(0)
96
Lev Walkinf15320b2004-06-03 03:38:44 +000097#endif /* _ASN1_COMPILED_OUTPUT_H_ */