source: trunk/tools/wrc/preproc.h@ 10367

Last change on this file since 10367 was 5522, checked in by sandervl, 24 years ago

updates

File size: 4.5 KB
Line 
1/*
2 * Copyright 1998 Bertho A. Stultiens (BS)
3 *
4 */
5
6#ifndef __WRC_PREPROC_H
7#define __WRC_PREPROC_H
8
9struct pp_entry; /* forward */
10/*
11 * Include logic
12 * A stack of files which are already included and
13 * are protected in the #ifndef/#endif way.
14 */
15typedef struct includelogicentry {
16 struct includelogicentry *next;
17 struct includelogicentry *prev;
18 struct pp_entry *ppp; /* The define which protects the file */
19 char *filename; /* The filename of the include */
20} includelogicentry_t;
21
22/*
23 * The arguments of a macrodefinition
24 */
25typedef enum {
26 arg_single,
27 arg_list
28} def_arg_t;
29
30typedef struct marg {
31 def_arg_t type; /* Normal or ... argument */
32 char *arg; /* The textual argument */
33 int nnl; /* Number of newlines in the text to subst */
34} marg_t;
35
36/*
37 * The expansiontext of a macro
38 */
39typedef enum {
40 exp_text, /* Simple text substitution */
41 exp_concat, /* Concat (##) operator requested */
42 exp_stringize, /* Stringize (#) operator requested */
43 exp_subst /* Substitute argument */
44} def_exp_t;
45
46typedef struct mtext {
47 struct mtext *next;
48 struct mtext *prev;
49 def_exp_t type;
50 union {
51 char *text;
52 int argidx; /* For exp_subst and exp_stringize reference */
53 } subst;
54} mtext_t;
55
56/*
57 * The define descriptor
58 */
59typedef enum {
60 def_none, /* Not-a-define; used as return value */
61 def_define, /* Simple defines */
62 def_macro, /* Macro defines */
63 def_special /* Special expansions like __LINE__ and __FILE__ */
64} def_type_t;
65
66typedef struct pp_entry {
67 struct pp_entry *next;
68 struct pp_entry *prev;
69 def_type_t type; /* Define or macro */
70 char *ident; /* The key */
71 marg_t **margs; /* Macro arguments array or NULL if none */
72 int nargs;
73 union {
74 mtext_t *mtext; /* The substitution sequence or NULL if none */
75 char *text;
76 } subst;
77 int expanding; /* Set when feeding substitution into the input */
78 char *filename; /* Filename where it was defined */
79 int linenumber; /* Linenumber where it was defined */
80 includelogicentry_t *iep; /* Points to the include it protects */
81} pp_entry_t;
82
83
84/*
85 * If logic
86 */
87#define MAXIFSTACK 64 /* If this isn't enough you should alter the source... */
88
89typedef enum {
90 if_false,
91 if_true,
92 if_elif,
93 if_elsefalse,
94 if_elsetrue,
95 if_ignore
96} if_state_t;
97
98/*
99 * I assume that 'long long' exists in the compiler when it has a size
100 * of 8 or bigger. If not, then we revert to a simple 'long' for now.
101 * This should prevent most unexpected things with other compilers than
102 * gcc and egcs for now.
103 * In the future it should be possible to use another way, like a
104 * structure, so that we can emulate the MS compiler.
105 */
106#if defined(SIZEOF_LONGLONG) && SIZEOF_LONGLONG >= 8
107typedef long long wrc_sll_t;
108typedef unsigned long long wrc_ull_t;
109#else
110typedef long wrc_sll_t;
111typedef unsigned long wrc_ull_t;
112#endif
113
114#define SIZE_CHAR 1
115#define SIZE_SHORT 2
116#define SIZE_INT 3
117#define SIZE_LONG 4
118#define SIZE_LONGLONG 5
119#define SIZE_MASK 0x00ff
120#define FLAG_SIGNED 0x0100
121
122typedef enum {
123#if 0
124 cv_schar = SIZE_CHAR + FLAG_SIGNED,
125 cv_uchar = SIZE_CHAR,
126 cv_sshort = SIZE_SHORT + FLAG_SIGNED,
127 cv_ushort = SIZE_SHORT,
128#endif
129 cv_sint = SIZE_INT + FLAG_SIGNED,
130 cv_uint = SIZE_INT,
131 cv_slong = SIZE_LONG + FLAG_SIGNED,
132 cv_ulong = SIZE_LONG,
133 cv_sll = SIZE_LONGLONG + FLAG_SIGNED,
134 cv_ull = SIZE_LONGLONG
135} ctype_t;
136
137typedef struct cval {
138 ctype_t type;
139 union {
140#if 0
141 signed char sc; /* Explicitely signed because compilers are stupid */
142 unsigned char uc;
143 short ss;
144 unsigned short us;
145#endif
146 int si;
147 unsigned int ui;
148 long sl;
149 unsigned long ul;
150 wrc_sll_t sll;
151 wrc_ull_t ull;
152 } val;
153} cval_t;
154
155
156
157pp_entry_t *pplookup(char *ident);
158pp_entry_t *add_define(char *def, char *text);
159pp_entry_t *add_cmdline_define(char *set);
160pp_entry_t *add_special_define(char *id);
161pp_entry_t *add_macro(char *ident, marg_t *args[], int nargs, mtext_t *exp);
162void del_define(char *name);
163FILE *open_include(const char *name, int search, char **newpath);
164void add_include_path(char *path);
165void push_if(if_state_t s);
166void next_if_state(int);
167if_state_t pop_if(void);
168if_state_t if_state(void);
169int get_if_depth(void);
170
171/*
172 * From ppl.l
173 */
174extern FILE *ppin;
175extern FILE *ppout;
176extern char *pptext;
177extern int pp_flex_debug;
178int pplex(void);
179
180void do_include(char *fname, int type);
181void push_ignore_state(void);
182void pop_ignore_state(void);
183
184extern int include_state;
185extern char *include_ppp;
186extern char *include_filename;
187extern int include_ifdepth;
188extern int seen_junk;
189extern includelogicentry_t *includelogiclist;
190
191/*
192 * From ppy.y
193 */
194int ppparse(void);
195extern int ppdebug;
196
197#endif
198
Note: See TracBrowser for help on using the repository browser.