2004-06-03 03:38:44 +00:00
|
|
|
|
#ifndef _ASN1_COMPILED_OUTPUT_H_
|
|
|
|
|
#define _ASN1_COMPILED_OUTPUT_H_
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* An elementary chunk of target language text.
|
|
|
|
|
*/
|
|
|
|
|
typedef struct out_chunk {
|
|
|
|
|
char *buf;
|
|
|
|
|
int len;
|
|
|
|
|
|
|
|
|
|
TQ_ENTRY(struct out_chunk) next;
|
|
|
|
|
} out_chunk_t;
|
|
|
|
|
|
|
|
|
|
typedef struct compiler_streams {
|
|
|
|
|
enum {
|
2004-09-08 00:28:47 +00:00
|
|
|
|
OT_IGNORE, /* Ignore this output */
|
2004-08-11 05:21:32 +00:00
|
|
|
|
OT_INCLUDES, /* #include files */
|
|
|
|
|
OT_DEPS, /* Dependencies (other than #includes) */
|
2004-06-03 03:38:44 +00:00
|
|
|
|
OT_TYPE_DECLS, /* Type declarations */
|
|
|
|
|
OT_FUNC_DECLS, /* Function declarations */
|
2004-08-20 13:37:01 +00:00
|
|
|
|
OT_CTABLES, /* Constraint tables */
|
2004-06-03 03:38:44 +00:00
|
|
|
|
OT_CODE, /* Some code */
|
2004-08-20 13:37:01 +00:00
|
|
|
|
OT_STAT_DEFS, /* Static definitions */
|
2004-06-03 03:38:44 +00:00
|
|
|
|
OT_MAX
|
|
|
|
|
} target;
|
2004-08-20 13:37:01 +00:00
|
|
|
|
|
|
|
|
|
struct compiler_stream_destination_s {
|
|
|
|
|
TQ_HEAD(out_chunk_t) chunks;
|
|
|
|
|
int indent_level;
|
|
|
|
|
int indented;
|
|
|
|
|
} destination[OT_MAX];
|
2004-06-03 03:38:44 +00:00
|
|
|
|
} compiler_streams_t;
|
|
|
|
|
|
|
|
|
|
static char *_compiler_stream2str[] __attribute__ ((unused))
|
2004-09-08 00:28:47 +00:00
|
|
|
|
= { "IGNORE", "INCLUDES", "DEPS", "TYPE-DECLS", "FUNC-DECLS", "CTABLES", "CODE", "STAT-DEFS" };
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
|
|
int asn1c_compiled_output(arg_t *arg, const char *fmt, ...);
|
|
|
|
|
|
2004-08-11 05:21:32 +00:00
|
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
|
* Useful macros for invoking asn1c_compiled_output() and friends.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Redirect output to a different stream. */
|
|
|
|
|
#define REDIR(foo) do { arg->target->target = foo; } while(0)
|
2004-08-20 13:37:01 +00:00
|
|
|
|
#define INDENT_LEVEL \
|
|
|
|
|
arg->target->destination[arg->target->target].indent_level
|
|
|
|
|
#define INDENT(val) INDENT_LEVEL += (val)
|
|
|
|
|
#define INDENTED(code) do { \
|
|
|
|
|
INDENT(+1); \
|
|
|
|
|
do { code; } while(0); \
|
|
|
|
|
INDENT(-1); \
|
2004-08-11 05:21:32 +00:00
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
#define EMBED(ev) do { \
|
|
|
|
|
int saved_target = arg->target->target; \
|
|
|
|
|
REDIR(OT_TYPE_DECLS); \
|
|
|
|
|
arg->embed++; \
|
|
|
|
|
INDENTED(arg_t _tmp = *arg; \
|
|
|
|
|
_tmp.expr = ev; \
|
|
|
|
|
_tmp.default_cb(&_tmp); \
|
|
|
|
|
); \
|
|
|
|
|
arg->embed--; \
|
2004-08-22 03:10:23 +00:00
|
|
|
|
if(ev->expr_type != A1TC_EXTENSIBLE) \
|
|
|
|
|
OUT(";\n"); \
|
2004-08-11 05:21:32 +00:00
|
|
|
|
assert(arg->target->target == OT_TYPE_DECLS); \
|
|
|
|
|
REDIR(saved_target); \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
/* Output a piece of text into a default stream */
|
|
|
|
|
#define OUT(fmt, args...) asn1c_compiled_output(arg, fmt, ##args)
|
2004-08-20 13:37:01 +00:00
|
|
|
|
#define OUT_NOINDENT(fmt, args...) do { \
|
|
|
|
|
int _saved_indent = INDENT_LEVEL; \
|
|
|
|
|
INDENT_LEVEL = 0; \
|
|
|
|
|
OUT(fmt, ##args); \
|
|
|
|
|
INDENT_LEVEL = _saved_indent; \
|
2004-08-11 05:21:32 +00:00
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
/* Generate #include line */
|
|
|
|
|
#define GEN_INCLUDE(filename) do { \
|
|
|
|
|
int saved_target = arg->target->target; \
|
|
|
|
|
REDIR(OT_INCLUDES); \
|
|
|
|
|
OUT_NOINDENT("#include <%s.h>\n", filename); \
|
|
|
|
|
REDIR(saved_target); \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
/* Generate ASN.1 type declaration */
|
|
|
|
|
#define GEN_DECLARE(expr) do { \
|
|
|
|
|
int saved_target = arg->target->target; \
|
|
|
|
|
REDIR(OT_DEPS); \
|
2004-09-29 13:16:40 +00:00
|
|
|
|
OUT_NOINDENT("extern asn_TYPE_descriptor_t " \
|
|
|
|
|
"asn_DEF_%s;\n", \
|
2004-08-11 05:21:32 +00:00
|
|
|
|
MKID(expr->Identifier)); \
|
|
|
|
|
REDIR(saved_target); \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
|
#endif /* _ASN1_COMPILED_OUTPUT_H_ */
|