wpp_private.h 5.8 KB

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