blob: fb986cbf3a387c3873c81709762f67adcc19a11e [file] [log] [blame]
vlmfa67ddc2004-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 {
vlm9cb78772004-09-08 00:28:47 +000016 OT_IGNORE, /* Ignore this output */
vlm33a4ff12004-08-11 05:21:32 +000017 OT_INCLUDES, /* #include files */
18 OT_DEPS, /* Dependencies (other than #includes) */
vlm0b567bf2005-03-04 22:18:20 +000019 OT_FWD_DECLS, /* Forward declarations */
vlmfa67ddc2004-06-03 03:38:44 +000020 OT_TYPE_DECLS, /* Type declarations */
21 OT_FUNC_DECLS, /* Function declarations */
vlm0b567bf2005-03-04 22:18:20 +000022 OT_POST_INCLUDE,/* #include after type definition */
vlmb2839012004-08-20 13:37:01 +000023 OT_CTABLES, /* Constraint tables */
vlmfa67ddc2004-06-03 03:38:44 +000024 OT_CODE, /* Some code */
vlmb2839012004-08-20 13:37:01 +000025 OT_STAT_DEFS, /* Static definitions */
vlmfa67ddc2004-06-03 03:38:44 +000026 OT_MAX
27 } target;
vlmb2839012004-08-20 13:37:01 +000028
29 struct compiler_stream_destination_s {
30 TQ_HEAD(out_chunk_t) chunks;
31 int indent_level;
32 int indented;
33 } destination[OT_MAX];
vlmfa67ddc2004-06-03 03:38:44 +000034} compiler_streams_t;
35
36static char *_compiler_stream2str[] __attribute__ ((unused))
vlm0b567bf2005-03-04 22:18:20 +000037 = { "IGNORE", "INCLUDES", "DEPS", "FWD-DECLS", "TYPE-DECLS", "FUNC-DECLS", "POST-INCLUDE", "CTABLES", "CODE", "STAT-DEFS" };
vlmfa67ddc2004-06-03 03:38:44 +000038
39int asn1c_compiled_output(arg_t *arg, const char *fmt, ...);
40
vlm33a4ff12004-08-11 05:21:32 +000041
42/*****************************************************************
43 * Useful macros for invoking asn1c_compiled_output() and friends.
44 */
45
46/* Redirect output to a different stream. */
47#define REDIR(foo) do { arg->target->target = foo; } while(0)
vlmb2839012004-08-20 13:37:01 +000048#define INDENT_LEVEL \
49 arg->target->destination[arg->target->target].indent_level
50#define INDENT(val) INDENT_LEVEL += (val)
51#define INDENTED(code) do { \
52 INDENT(+1); \
53 do { code; } while(0); \
54 INDENT(-1); \
vlm33a4ff12004-08-11 05:21:32 +000055 } while(0)
56
vlm33a4ff12004-08-11 05:21:32 +000057#define EMBED(ev) do { \
58 int saved_target = arg->target->target; \
59 REDIR(OT_TYPE_DECLS); \
60 arg->embed++; \
61 INDENTED(arg_t _tmp = *arg; \
62 _tmp.expr = ev; \
63 _tmp.default_cb(&_tmp); \
64 ); \
65 arg->embed--; \
vlm2e0c1942004-08-22 03:10:23 +000066 if(ev->expr_type != A1TC_EXTENSIBLE) \
67 OUT(";\n"); \
vlm33a4ff12004-08-11 05:21:32 +000068 assert(arg->target->target == OT_TYPE_DECLS); \
69 REDIR(saved_target); \
70 } while(0)
71
72/* Output a piece of text into a default stream */
73#define OUT(fmt, args...) asn1c_compiled_output(arg, fmt, ##args)
vlmb2839012004-08-20 13:37:01 +000074#define OUT_NOINDENT(fmt, args...) do { \
75 int _saved_indent = INDENT_LEVEL; \
76 INDENT_LEVEL = 0; \
77 OUT(fmt, ##args); \
78 INDENT_LEVEL = _saved_indent; \
vlm33a4ff12004-08-11 05:21:32 +000079} while(0)
vlm80a48592005-02-25 12:10:27 +000080#define OUT_DEBUG(fmt, args...) do { \
81 if(arg->flags & A1C_DEBUG) OUT(fmt, ##args); \
82 } while(0)
vlm33a4ff12004-08-11 05:21:32 +000083
84/* Generate #include line */
85#define GEN_INCLUDE(filename) do { \
86 int saved_target = arg->target->target; \
vlmfe03aba2006-03-06 00:30:30 +000087 if(!filename) break; \
vlm33a4ff12004-08-11 05:21:32 +000088 REDIR(OT_INCLUDES); \
89 OUT_NOINDENT("#include <%s.h>\n", filename); \
90 REDIR(saved_target); \
91} while(0)
vlm0b567bf2005-03-04 22:18:20 +000092#define GEN_POSTINCLUDE(filename) do { \
93 int saved_target = arg->target->target; \
vlmfe03aba2006-03-06 00:30:30 +000094 if(!filename) break; \
vlm0b567bf2005-03-04 22:18:20 +000095 REDIR(OT_POST_INCLUDE); \
96 OUT_NOINDENT("#include <%s.h>\n", filename); \
97 REDIR(saved_target); \
98} while(0)
vlm33a4ff12004-08-11 05:21:32 +000099
100/* Generate ASN.1 type declaration */
101#define GEN_DECLARE(expr) do { \
102 int saved_target = arg->target->target; \
vlm0b567bf2005-03-04 22:18:20 +0000103 REDIR(OT_FUNC_DECLS); \
vlma5dcb912004-09-29 13:16:40 +0000104 OUT_NOINDENT("extern asn_TYPE_descriptor_t " \
vlm0c6d3812006-03-21 03:40:38 +0000105 "asn_DEF_%s;\n", MKID(expr)); \
vlm33a4ff12004-08-11 05:21:32 +0000106 REDIR(saved_target); \
107} while(0)
108
vlmfa67ddc2004-06-03 03:38:44 +0000109#endif /* _ASN1_COMPILED_OUTPUT_H_ */