blob: 31bf69773ea12052de9f5a0ef14997a82e2c0f1d [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001#ifndef _ASN1_COMPILER_INTERNAL_H_
2#define _ASN1_COMPILER_INTERNAL_H_
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <sys/stat.h> /* for fstat(2) */
7#include <unistd.h> /* for unlink(2) */
8#include <fcntl.h> /* for open(2) */
9#include <glob.h> /* for glob(3) */
10#include <libgen.h> /* for basename(3) */
11#include <string.h>
12#include <ctype.h> /* for isalnum(3) */
13#include <stdarg.h>
14#include <errno.h>
15#include <assert.h>
16
17#include "asn1compiler.h"
18
19typedef struct arg_s {
20
21 enum asn1c_flags flags;
22
23 void (*logger_cb)(int _severity, const char *fmt, ...);
24
25 int (*default_cb)(struct arg_s *);
26
27 struct compiler_streams *target;
28
29 asn1p_t *asn;
30 asn1p_module_t *mod;
31 asn1p_expr_t *expr;
32
33 int indent_level;
34 int indented;
35 int embed;
36} arg_t;
37
38#include "asn1c_lang.h" /* Target language initialization */
39#include "asn1c_misc.h" /* Miscellaneous functions */
40#include "asn1c_out.h" /* Handle output during compilation */
41#include "asn1c_save.h" /* Save compiled output */
42
43#define INDENT(val) arg->indent_level += (val)
44#define INDENTED(code) do { \
45 INDENT(+1); \
46 do { code; } while(0); \
47 INDENT(-1); \
48 } while(0)
49#define FLAT(code) do { \
50 int _il = arg->indent_level; \
51 arg->indent_level = 0; \
52 do { code; } while(0); \
53 arg->indent_level = _il; \
54 } while(0)
55#define EMBED(ev) do { \
56 REDIR(OT_TYPE_DECLS); \
57 arg->embed++; \
58 INDENTED(arg_t _tmp = *arg; \
59 _tmp.expr = ev; \
60 _tmp.default_cb(&_tmp); \
61 ); \
62 arg->embed--; \
63 } while(0)
64#define OUT(fmt, args...) asn1c_compiled_output(arg, fmt, ##args)
Lev Walkin27ea3802004-06-28 21:13:46 +000065#define OUT_NOINDENT(fmt, args...) do { \
66 int _saved_indent = arg->indent_level; \
67 arg->indent_level = 0; \
68 asn1c_compiled_output(arg, fmt, ##args);\
69 arg->indent_level = _saved_indent; \
70} while(0)
Lev Walkinf15320b2004-06-03 03:38:44 +000071
72#define REDIR(foo) do { arg->target->target = foo; } while(0)
73
74/*
75 * Logging.
76 */
77#define LOG(ll, fmt, args...) do { \
78 arg->logger_cb(ll, fmt, ##args); \
79 } while(0)
80#define DEBUG(fmt, args...) do { \
81 if(arg->flags & A1C_DEBUG) \
82 LOG(-1, fmt, ##args); \
83 } while(0)
84#define WARNING(fmt, args...) LOG(0, fmt, ##args);
85#define FATAL(fmt, args...) LOG(1, fmt, ##args);
86
87#endif /* _ASN1_COMPILER_INTERNAL_H_ */