Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/tools/wrc/wpp_private.h
4388 views
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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
#include "wine/list.h"
26
27
extern void wpp_del_define( const char *name );
28
extern void wpp_add_cmdline_define( const char *value );
29
extern void wpp_set_debug( int lex_debug, int parser_debug, int msg_debug );
30
extern void wpp_add_include_path( const char *path );
31
extern char *wpp_find_include( const char *name, const char *parent_name );
32
/* Return value == 0 means successful execution */
33
extern int wpp_parse( const char *input, FILE *output );
34
35
struct pp_entry; /* forward */
36
/*
37
* Include logic
38
* A stack of files which are already included and
39
* are protected in the #ifndef/#endif way.
40
*/
41
typedef struct includelogicentry {
42
struct list entry;
43
struct pp_entry *ppp; /* The define which protects the file */
44
char *filename; /* The filename of the include */
45
} includelogicentry_t;
46
47
/*
48
* The expansiontext of a macro
49
*/
50
typedef enum {
51
exp_text, /* Simple text substitution */
52
exp_concat, /* Concat (##) operator requested */
53
exp_stringize, /* Stringize (#) operator requested */
54
exp_subst /* Substitute argument */
55
} def_exp_t;
56
57
typedef struct mtext {
58
struct mtext *next;
59
struct mtext *prev;
60
def_exp_t type;
61
union {
62
char *text;
63
int argidx; /* For exp_subst and exp_stringize reference */
64
} subst;
65
} mtext_t;
66
67
/*
68
* The define descriptor
69
*/
70
typedef enum {
71
def_none, /* Not-a-define; used as return value */
72
def_define, /* Simple defines */
73
def_macro, /* Macro defines */
74
def_special /* Special expansions like __LINE__ and __FILE__ */
75
} def_type_t;
76
77
typedef struct pp_entry {
78
struct list entry;
79
def_type_t type; /* Define or macro */
80
char *ident; /* The key */
81
char **margs; /* Macro arguments array or NULL if none */
82
int nargs;
83
int variadic;
84
union {
85
mtext_t *mtext; /* The substitution sequence or NULL if none */
86
char *text;
87
} subst;
88
int expanding; /* Set when feeding substitution into the input */
89
char *filename; /* Filename where it was defined */
90
int linenumber; /* Linenumber where it was defined */
91
includelogicentry_t *iep; /* Points to the include it protects */
92
} pp_entry_t;
93
94
95
/*
96
* If logic
97
*/
98
#define MAXIFSTACK 64 /* If this isn't enough you should alter the source... */
99
100
typedef enum {
101
if_false,
102
if_true,
103
if_elif,
104
if_elsefalse,
105
if_elsetrue,
106
if_ignore,
107
if_error
108
} pp_if_state_t;
109
110
111
/*
112
* Trace the include files to prevent double reading.
113
* This save 20..30% of processing time for most stuff
114
* that uses complex includes.
115
* States:
116
* -1 Don't track or seen junk
117
* 0 New include, waiting for "#ifndef __xxx_h"
118
* 1 Seen #ifndef, waiting for "#define __xxx_h ..."
119
* 2 Seen #endif, waiting for EOF
120
*/
121
typedef struct
122
{
123
int state;
124
char *ppp; /* The define to be set from the #ifndef */
125
int ifdepth; /* The level of ifs at the #ifdef */
126
int seen_junk; /* Set when junk is seen */
127
} include_state_t;
128
129
#define SIZE_INT 1
130
#define SIZE_LONG 2
131
#define SIZE_LONGLONG 3
132
#define SIZE_MASK 0x00ff
133
#define FLAG_SIGNED 0x0100
134
135
typedef enum {
136
cv_sint = SIZE_INT + FLAG_SIGNED,
137
cv_uint = SIZE_INT,
138
cv_slong = SIZE_LONG + FLAG_SIGNED,
139
cv_ulong = SIZE_LONG,
140
cv_sll = SIZE_LONGLONG + FLAG_SIGNED,
141
cv_ull = SIZE_LONGLONG
142
} ctype_t;
143
144
typedef struct cval {
145
ctype_t type;
146
union {
147
int si;
148
unsigned int ui;
149
long sl;
150
unsigned long ul;
151
__int64 sll;
152
unsigned __int64 ull;
153
} val;
154
} cval_t;
155
156
157
158
pp_entry_t *pplookup(const char *ident);
159
pp_entry_t *pp_add_define(const char *def, const char *text);
160
pp_entry_t *pp_add_macro(char *ident, char *args[], int nargs, int variadic, mtext_t *exp);
161
void pp_del_define(const char *name);
162
void *pp_open_include(const char *name, int type, const char *parent_name, char **newpath);
163
void pp_push_if(pp_if_state_t s);
164
void pp_next_if_state(int);
165
pp_if_state_t pp_pop_if(void);
166
pp_if_state_t pp_if_state(void);
167
int pp_get_if_depth(void);
168
169
int ppy_error(const char *s, ...) __attribute__((format (printf, 1, 2)));
170
int ppy_warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
171
172
/* current preprocessor state */
173
/* everything is in this structure to avoid polluting the global symbol space */
174
struct pp_status
175
{
176
char *input; /* current input file name */
177
FILE *file; /* current input file descriptor */
178
int line_number; /* current line number */
179
int char_number; /* current char number in line */
180
int debug; /* debug messages flag */
181
};
182
183
extern struct pp_status pp_status;
184
extern include_state_t pp_incl_state;
185
extern int pedantic;
186
187
/*
188
* From ppl.l
189
*/
190
extern FILE *ppy_in;
191
extern FILE *ppy_out;
192
extern char *ppy_text;
193
extern int pp_flex_debug;
194
int ppy_lex(void);
195
196
void pp_do_include(char *fname, int type);
197
void pp_push_ignore_state(void);
198
void pp_pop_ignore_state(void);
199
200
/*
201
* From ppy.y
202
*/
203
int ppy_parse(void);
204
extern int ppy_debug;
205
206
#endif /* __WINE_WPP_PRIVATE_H */
207
208