wpp_private.h 5.6 KB

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