Release 5.9.
[wine/zf.git] / libs / wpp / wpp_private.h
blobab4296bb4d52d568052f3c5ad4d64f23164a95e3
1 /*
2 * Copyright 1998 Bertho A. Stultiens (BS)
3 * Copyright 2002 Alexandre Julliard
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #ifndef __WINE_WPP_PRIVATE_H
21 #define __WINE_WPP_PRIVATE_H
23 #include <stdio.h>
24 #include <string.h>
26 struct pp_entry; /* forward */
28 * Include logic
29 * A stack of files which are already included and
30 * are protected in the #ifndef/#endif way.
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;
40 * The arguments of a macrodefinition
42 typedef enum {
43 arg_single,
44 arg_list
45 } def_arg_t;
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;
54 * The expansiontext of a macro
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;
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;
74 * The define descriptor
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;
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;
102 * If logic
104 #define MAXIFSTACK 64 /* If this isn't enough you should alter the source... */
106 typedef enum {
107 if_false,
108 if_true,
109 if_elif,
110 if_elsefalse,
111 if_elsetrue,
112 if_ignore,
113 if_error
114 } pp_if_state_t;
118 * Trace the include files to prevent double reading.
119 * This save 20..30% of processing time for most stuff
120 * that uses complex includes.
121 * States:
122 * -1 Don't track or seen junk
123 * 0 New include, waiting for "#ifndef __xxx_h"
124 * 1 Seen #ifndef, waiting for "#define __xxx_h ..."
125 * 2 Seen #endif, waiting for EOF
127 typedef struct
129 int state;
130 char *ppp; /* The define to be set from the #ifndef */
131 int ifdepth; /* The level of ifs at the #ifdef */
132 int seen_junk; /* Set when junk is seen */
133 } include_state_t;
135 #define SIZE_CHAR 1
136 #define SIZE_SHORT 2
137 #define SIZE_INT 3
138 #define SIZE_LONG 4
139 #define SIZE_LONGLONG 5
140 #define SIZE_MASK 0x00ff
141 #define FLAG_SIGNED 0x0100
143 typedef enum {
144 #if 0
145 cv_schar = SIZE_CHAR + FLAG_SIGNED,
146 cv_uchar = SIZE_CHAR,
147 cv_sshort = SIZE_SHORT + FLAG_SIGNED,
148 cv_ushort = SIZE_SHORT,
149 #endif
150 cv_sint = SIZE_INT + FLAG_SIGNED,
151 cv_uint = SIZE_INT,
152 cv_slong = SIZE_LONG + FLAG_SIGNED,
153 cv_ulong = SIZE_LONG,
154 cv_sll = SIZE_LONGLONG + FLAG_SIGNED,
155 cv_ull = SIZE_LONGLONG
156 } ctype_t;
158 typedef struct cval {
159 ctype_t type;
160 union {
161 #if 0
162 signed char sc; /* Explicitly signed because compilers are stupid */
163 unsigned char uc;
164 short ss;
165 unsigned short us;
166 #endif
167 int si;
168 unsigned int ui;
169 long sl;
170 unsigned long ul;
171 __int64 sll;
172 unsigned __int64 ull;
173 } val;
174 } cval_t;
178 void *pp_xmalloc(size_t);
179 void *pp_xrealloc(void *, size_t);
180 char *pp_xstrdup(const char *str);
181 pp_entry_t *pplookup(const char *ident);
182 int pp_push_define_state(void);
183 void pp_pop_define_state(void);
184 pp_entry_t *pp_add_define(const char *def, const char *text);
185 pp_entry_t *pp_add_macro(char *ident, marg_t *args[], int nargs, mtext_t *exp);
186 void pp_del_define(const char *name);
187 void *pp_open_include(const char *name, int type, const char *parent_name, char **newpath);
188 void pp_push_if(pp_if_state_t s);
189 void pp_next_if_state(int);
190 pp_if_state_t pp_pop_if(void);
191 pp_if_state_t pp_if_state(void);
192 int pp_get_if_depth(void);
193 char *wpp_lookup(const char *name, int type, const char *parent_name,
194 char **include_path, int include_path_count);
196 #ifndef __GNUC__
197 #define __attribute__(x) /*nothing*/
198 #endif
200 extern const struct wpp_callbacks *wpp_callbacks;
202 int ppy_error(const char *s, ...) __attribute__((format (printf, 1, 2)));
203 int ppy_warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
204 void pp_internal_error(const char *file, int line, const char *s, ...) __attribute__((format (printf, 3, 4)));
206 /* current preprocessor state */
207 /* everything is in this structure to avoid polluting the global symbol space */
208 struct pp_status
210 char *input; /* current input file name */
211 void *file; /* current input file descriptor */
212 int line_number; /* current line number */
213 int char_number; /* current char number in line */
214 int state; /* current error state */
215 int pedantic; /* pedantic option */
216 int debug; /* debug messages flag */
219 extern struct pp_status pp_status;
220 extern include_state_t pp_incl_state;
221 extern includelogicentry_t *pp_includelogiclist;
224 * From ppl.l
226 extern FILE *ppy_in;
227 extern FILE *ppy_out;
228 extern char *ppy_text;
229 extern int pp_flex_debug;
230 int ppy_lex(void);
232 void pp_do_include(char *fname, int type);
233 void pp_push_ignore_state(void);
234 void pp_pop_ignore_state(void);
236 void pp_writestring(const char *format, ...) __attribute__((format (printf, 1, 2)));
239 * From ppy.y
241 int ppy_parse(void);
242 extern int ppy_debug;
244 #endif /* __WINE_WPP_PRIVATE_H */