Framework for the doppler effect.
[wine] / tools / wpp / wpp_private.h
1 /*
2  * Copyright 1998 Bertho A. Stultiens (BS)
3  * Copyright 2002 Alexandre Julliard
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #ifndef __WINE_WPP_PRIVATE_H
21 #define __WINE_WPP_PRIVATE_H
22
23 #include <stdio.h>
24 #include <string.h>
25
26 struct pp_entry;        /* forward */
27 /*
28  * Include logic
29  * A stack of files which are already included and
30  * are protected in the #ifndef/#endif way.
31  */
32 typedef struct includelogicentry {
33         struct includelogicentry *next;
34         struct includelogicentry *prev;
35         struct pp_entry *ppp;           /* The define which protects the file */
36         char            *filename;      /* The filename of the include */
37 } includelogicentry_t;
38
39 /*
40  * The arguments of a macrodefinition
41  */
42 typedef enum {
43         arg_single,
44         arg_list
45 } def_arg_t;
46
47 typedef struct marg {
48         def_arg_t       type;   /* Normal or ... argument */
49         char            *arg;   /* The textual argument */
50         int             nnl;    /* Number of newlines in the text to subst */
51 } marg_t;
52
53 /*
54  * The expansiontext of a macro
55  */
56 typedef enum {
57         exp_text,       /* Simple text substitution */
58         exp_concat,     /* Concat (##) operator requested */
59         exp_stringize,  /* Stringize (#) operator requested */
60         exp_subst       /* Substitute argument */
61 } def_exp_t;
62
63 typedef struct mtext {
64         struct mtext    *next;
65         struct mtext    *prev;
66         def_exp_t       type;
67         union {
68                 char    *text;
69                 int     argidx;         /* For exp_subst and exp_stringize reference */
70         } subst;
71 } mtext_t;
72
73 /*
74  * The define descriptor
75  */
76 typedef enum {
77         def_none,       /* Not-a-define; used as return value */
78         def_define,     /* Simple defines */
79         def_macro,      /* Macro defines */
80         def_special     /* Special expansions like __LINE__ and __FILE__ */
81 } def_type_t;
82
83 typedef struct pp_entry {
84         struct pp_entry *next;
85         struct pp_entry *prev;
86         def_type_t      type;           /* Define or macro */
87         char            *ident;         /* The key */
88         marg_t          **margs;        /* Macro arguments array or NULL if none */
89         int             nargs;
90         union {
91                 mtext_t *mtext;         /* The substitution sequence or NULL if none */
92                 char    *text;
93         } subst;
94         int             expanding;      /* Set when feeding substitution into the input */
95         char            *filename;      /* Filename where it was defined */
96         int             linenumber;     /* Linenumber where it was defined */
97         includelogicentry_t *iep;       /* Points to the include it protects */
98 } pp_entry_t;
99
100
101 /*
102  * If logic
103  */
104 #define MAXIFSTACK      64      /* If this isn't enough you should alter the source... */
105
106 typedef enum {
107         if_false,
108         if_true,
109         if_elif,
110         if_elsefalse,
111         if_elsetrue,
112         if_ignore
113 } pp_if_state_t;
114
115
116 /*
117  * Trace the include files to prevent double reading.
118  * This save 20..30% of processing time for most stuff
119  * that uses complex includes.
120  * States:
121  * -1   Don't track or seen junk
122  *  0   New include, waiting for "#ifndef __xxx_h"
123  *  1   Seen #ifndef, waiting for "#define __xxx_h ..."
124  *  2   Seen #endif, waiting for EOF
125  */
126 typedef struct
127 {
128     int state;
129     char *ppp;             /* The define to be set from the #ifndef */
130     int ifdepth;           /* The level of ifs at the #ifdef */
131     int seen_junk;         /* Set when junk is seen */
132 } include_state_t;
133
134
135 /*
136  * I assume that 'long long' exists in the compiler when it has a size
137  * of 8 or bigger. If not, then we revert to a simple 'long' for now.
138  * This should prevent most unexpected things with other compilers than
139  * gcc and egcs for now.
140  * In the future it should be possible to use another way, like a
141  * structure, so that we can emulate the MS compiler.
142  */
143 #if defined(SIZEOF_LONGLONG) && SIZEOF_LONGLONG >= 8
144 typedef long long wrc_sll_t;
145 typedef unsigned long long wrc_ull_t;
146 #else
147 typedef long wrc_sll_t;
148 typedef unsigned long wrc_ull_t;
149 #endif
150
151 #define SIZE_CHAR       1
152 #define SIZE_SHORT      2
153 #define SIZE_INT        3
154 #define SIZE_LONG       4
155 #define SIZE_LONGLONG   5
156 #define SIZE_MASK       0x00ff
157 #define FLAG_SIGNED     0x0100
158
159 typedef enum {
160 #if 0
161         cv_schar  = SIZE_CHAR + FLAG_SIGNED,
162         cv_uchar  = SIZE_CHAR,
163         cv_sshort = SIZE_SHORT + FLAG_SIGNED,
164         cv_ushort = SIZE_SHORT,
165 #endif
166         cv_sint   = SIZE_INT + FLAG_SIGNED,
167         cv_uint   = SIZE_INT,
168         cv_slong  = SIZE_LONG + FLAG_SIGNED,
169         cv_ulong  = SIZE_LONG,
170         cv_sll    = SIZE_LONGLONG + FLAG_SIGNED,
171         cv_ull    = SIZE_LONGLONG
172 } ctype_t;
173
174 typedef struct cval {
175         ctype_t type;
176         union {
177 #if 0
178                 signed char     sc;     /* Explicitely signed because compilers are stupid */
179                 unsigned char   uc;
180                 short           ss;
181                 unsigned short  us;
182 #endif
183                 int             si;
184                 unsigned int    ui;
185                 long            sl;
186                 unsigned long   ul;
187                 wrc_sll_t       sll;
188                 wrc_ull_t       ull;
189         } val;
190 } cval_t;
191
192
193
194 void *pp_xmalloc(size_t);
195 void *pp_xrealloc(void *, size_t);
196 char *pp_xstrdup(const char *str);
197 pp_entry_t *pplookup(const char *ident);
198 pp_entry_t *pp_add_define(char *def, char *text);
199 pp_entry_t *pp_add_macro(char *ident, marg_t *args[], int nargs, mtext_t *exp);
200 void pp_del_define(const char *name);
201 FILE *pp_open_include(const char *name, int search, char **newpath);
202 void pp_push_if(pp_if_state_t s);
203 void pp_next_if_state(int);
204 pp_if_state_t pp_pop_if(void);
205 pp_if_state_t pp_if_state(void);
206 int pp_get_if_depth(void);
207
208 #ifndef __GNUC__
209 #define __attribute__(x)  /*nothing*/
210 #endif
211
212 int pperror(const char *s, ...) __attribute__((format (printf, 1, 2)));
213 int ppwarning(const char *s, ...) __attribute__((format (printf, 1, 2)));
214 void pp_internal_error(const char *file, int line, const char *s, ...) __attribute__((format (printf, 3, 4)));
215
216 /* current preprocessor state */
217 /* everything is in this structure to avoid polluting the global symbol space */
218 struct pp_status
219 {
220     const char *input;  /* current input file name */
221     int line_number;    /* current line number */
222     int char_number;    /* current char number in line */
223     int pedantic;       /* pedantic option */
224     int debug;          /* debug messages flag */
225 };
226
227 extern struct pp_status pp_status;
228 extern include_state_t pp_incl_state;
229 extern includelogicentry_t *pp_includelogiclist;
230
231 /*
232  * From ppl.l
233  */
234 extern FILE *ppin;
235 extern FILE *ppout;
236 extern char *pptext;
237 extern int pp_flex_debug;
238 int pplex(void);
239
240 void pp_do_include(char *fname, int type);
241 void pp_push_ignore_state(void);
242 void pp_pop_ignore_state(void);
243
244
245 /*
246  * From ppy.y
247  */
248 int ppparse(void);
249 extern int ppdebug;
250
251 #endif  /* __WINE_WPP_PRIVATE_H */