/*1* Copyright 1998 Bertho A. Stultiens (BS)2* Copyright 2002 Alexandre Julliard3*4* This library is free software; you can redistribute it and/or5* modify it under the terms of the GNU Lesser General Public6* License as published by the Free Software Foundation; either7* version 2.1 of the License, or (at your option) any later version.8*9* This library is distributed in the hope that it will be useful,10* but WITHOUT ANY WARRANTY; without even the implied warranty of11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU12* Lesser General Public License for more details.13*14* You should have received a copy of the GNU Lesser General Public15* License along with this library; if not, write to the Free Software16* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA17*/1819#ifndef __WINE_WPP_PRIVATE_H20#define __WINE_WPP_PRIVATE_H2122#include <stdio.h>23#include <string.h>24#include "wine/list.h"2526extern void wpp_del_define( const char *name );27extern void wpp_add_cmdline_define( const char *value );28extern void wpp_set_debug( int lex_debug, int parser_debug, int msg_debug );29extern void wpp_add_include_path( const char *path );30extern char *wpp_find_include( const char *name, const char *parent_name );31/* Return value == 0 means successful execution */32extern int wpp_parse( const char *input, FILE *output );3334struct pp_entry; /* forward */35/*36* Include logic37* A stack of files which are already included and38* are protected in the #ifndef/#endif way.39*/40typedef struct includelogicentry {41struct list entry;42struct pp_entry *ppp; /* The define which protects the file */43char *filename; /* The filename of the include */44} includelogicentry_t;4546/*47* The expansiontext of a macro48*/49typedef enum {50exp_text, /* Simple text substitution */51exp_concat, /* Concat (##) operator requested */52exp_stringize, /* Stringize (#) operator requested */53exp_subst /* Substitute argument */54} def_exp_t;5556typedef struct mtext {57struct mtext *next;58struct mtext *prev;59def_exp_t type;60union {61char *text;62int argidx; /* For exp_subst and exp_stringize reference */63} subst;64} mtext_t;6566/*67* The define descriptor68*/69typedef enum {70def_none, /* Not-a-define; used as return value */71def_define, /* Simple defines */72def_macro, /* Macro defines */73def_special /* Special expansions like __LINE__ and __FILE__ */74} def_type_t;7576typedef struct pp_entry {77struct list entry;78def_type_t type; /* Define or macro */79char *ident; /* The key */80char **margs; /* Macro arguments array or NULL if none */81int nargs;82int variadic;83union {84mtext_t *mtext; /* The substitution sequence or NULL if none */85char *text;86} subst;87int expanding; /* Set when feeding substitution into the input */88char *filename; /* Filename where it was defined */89int linenumber; /* Linenumber where it was defined */90includelogicentry_t *iep; /* Points to the include it protects */91} pp_entry_t;929394/*95* If logic96*/97#define MAXIFSTACK 64 /* If this isn't enough you should alter the source... */9899typedef enum {100if_false,101if_true,102if_elif,103if_elsefalse,104if_elsetrue,105if_ignore,106if_error107} pp_if_state_t;108109110/*111* Trace the include files to prevent double reading.112* This save 20..30% of processing time for most stuff113* that uses complex includes.114* States:115* -1 Don't track or seen junk116* 0 New include, waiting for "#ifndef __xxx_h"117* 1 Seen #ifndef, waiting for "#define __xxx_h ..."118* 2 Seen #endif, waiting for EOF119*/120typedef struct121{122int state;123char *ppp; /* The define to be set from the #ifndef */124int ifdepth; /* The level of ifs at the #ifdef */125int seen_junk; /* Set when junk is seen */126} include_state_t;127128#define SIZE_INT 1129#define SIZE_LONG 2130#define SIZE_LONGLONG 3131#define SIZE_MASK 0x00ff132#define FLAG_SIGNED 0x0100133134typedef enum {135cv_sint = SIZE_INT + FLAG_SIGNED,136cv_uint = SIZE_INT,137cv_slong = SIZE_LONG + FLAG_SIGNED,138cv_ulong = SIZE_LONG,139cv_sll = SIZE_LONGLONG + FLAG_SIGNED,140cv_ull = SIZE_LONGLONG141} ctype_t;142143typedef struct cval {144ctype_t type;145union {146int si;147unsigned int ui;148long sl;149unsigned long ul;150__int64 sll;151unsigned __int64 ull;152} val;153} cval_t;154155156157pp_entry_t *pplookup(const char *ident);158pp_entry_t *pp_add_define(const char *def, const char *text);159pp_entry_t *pp_add_macro(char *ident, char *args[], int nargs, int variadic, mtext_t *exp);160void pp_del_define(const char *name);161void *pp_open_include(const char *name, int type, const char *parent_name, char **newpath);162void pp_push_if(pp_if_state_t s);163void pp_next_if_state(int);164pp_if_state_t pp_pop_if(void);165pp_if_state_t pp_if_state(void);166int pp_get_if_depth(void);167168int ppy_error(const char *s, ...) __attribute__((format (printf, 1, 2)));169int ppy_warning(const char *s, ...) __attribute__((format (printf, 1, 2)));170171/* current preprocessor state */172/* everything is in this structure to avoid polluting the global symbol space */173struct pp_status174{175char *input; /* current input file name */176FILE *file; /* current input file descriptor */177int line_number; /* current line number */178int char_number; /* current char number in line */179int debug; /* debug messages flag */180};181182extern struct pp_status pp_status;183extern include_state_t pp_incl_state;184extern int pedantic;185186/*187* From ppl.l188*/189extern FILE *ppy_in;190extern FILE *ppy_out;191extern char *ppy_text;192extern int pp_flex_debug;193int ppy_lex(void);194195void pp_do_include(char *fname, int type);196void pp_push_ignore_state(void);197void pp_pop_ignore_state(void);198199/*200* From ppy.y201*/202int ppy_parse(void);203extern int ppy_debug;204205#endif /* __WINE_WPP_PRIVATE_H */206207208