support for creating template instance classes
[lqt/mk.git] / cpptoxml / parser / rpp / pp-engine.h
blob1e01a9370c05dd57c829cfc0988a3c6b62e9ada3
1 /****************************************************************************
2 **
3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4 ** Copyright 2005 Roberto Raggi <roberto@kdevelop.org>
5 **
6 ** This file is part of $PRODUCT$.
7 **
8 ** $CPP_LICENSE$
9 **
10 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 ****************************************************************************/
15 #ifndef PP_ENGINE_H
16 #define PP_ENGINE_H
18 namespace rpp {
20 struct Value
22 enum Kind {
23 Kind_Long,
24 Kind_ULong
27 Kind kind;
29 union {
30 long l;
31 unsigned long ul;
34 inline bool is_ulong () const { return kind == Kind_ULong; }
36 inline void set_ulong (unsigned long v)
38 ul = v;
39 kind = Kind_ULong;
42 inline void set_long (long v)
44 l = v;
45 kind = Kind_Long;
48 inline bool is_zero () const { return l == 0; }
50 #define PP_DEFINE_BIN_OP(name, op) \
51 inline Value &name (const Value &other) \
52 { \
53 if (is_ulong () || other.is_ulong ()) \
54 set_ulong (ul op other.ul); \
55 else \
56 set_long (l op other.l); \
57 return *this; \
60 PP_DEFINE_BIN_OP(op_add, +)
61 PP_DEFINE_BIN_OP(op_sub, -)
62 PP_DEFINE_BIN_OP(op_mult, *)
63 PP_DEFINE_BIN_OP(op_div, /)
64 PP_DEFINE_BIN_OP(op_mod, %)
65 PP_DEFINE_BIN_OP(op_lhs, <<)
66 PP_DEFINE_BIN_OP(op_rhs, >>)
67 PP_DEFINE_BIN_OP(op_lt, <)
68 PP_DEFINE_BIN_OP(op_gt, >)
69 PP_DEFINE_BIN_OP(op_le, <=)
70 PP_DEFINE_BIN_OP(op_ge, >=)
71 PP_DEFINE_BIN_OP(op_eq, ==)
72 PP_DEFINE_BIN_OP(op_ne, !=)
73 PP_DEFINE_BIN_OP(op_bit_and, &)
74 PP_DEFINE_BIN_OP(op_bit_or, |)
75 PP_DEFINE_BIN_OP(op_bit_xor, ^)
76 PP_DEFINE_BIN_OP(op_and, &&)
77 PP_DEFINE_BIN_OP(op_or, ||)
79 #undef PP_DEFINE_BIN_OP
82 class pp
84 pp_environment &env;
85 pp_macro_expander expand;
86 pp_skip_identifier skip_identifier;
87 pp_skip_comment_or_divop skip_comment_or_divop;
88 pp_skip_blanks skip_blanks;
89 pp_skip_number skip_number;
90 std::vector<std::string> include_paths;
91 std::string _M_current_text;
93 enum { MAX_LEVEL = 512 };
94 int _M_skipping[MAX_LEVEL];
95 int _M_true_test[MAX_LEVEL];
96 int iflevel;
98 union
100 long token_value;
101 unsigned long token_uvalue;
102 std::string *token_text;
105 enum INCLUDE_POLICY
107 INCLUDE_GLOBAL,
108 INCLUDE_LOCAL
111 enum TOKEN_TYPE
113 TOKEN_NUMBER = 1000,
114 TOKEN_UNUMBER,
115 TOKEN_IDENTIFIER,
116 TOKEN_DEFINED,
117 TOKEN_LT_LT,
118 TOKEN_LT_EQ,
119 TOKEN_GT_GT,
120 TOKEN_GT_EQ,
121 TOKEN_EQ_EQ,
122 TOKEN_NOT_EQ,
123 TOKEN_OR_OR,
124 TOKEN_AND_AND
127 enum PP_DIRECTIVE_TYPE
129 PP_UNKNOWN_DIRECTIVE,
130 PP_DEFINE,
131 PP_INCLUDE,
132 PP_INCLUDE_NEXT,
133 PP_ELIF,
134 PP_ELSE,
135 PP_ENDIF,
136 PP_IF,
137 PP_IFDEF,
138 PP_IFNDEF,
139 PP_UNDEF,
140 PP_PRAGMA,
141 PP_WARNING,
142 PP_ERROR
145 public:
146 pp (pp_environment &__env);
148 inline std::back_insert_iterator<std::vector<std::string> > include_paths_inserter ();
150 inline void push_include_path (std::string const &__path);
152 inline std::vector<std::string>::iterator include_paths_begin ();
153 inline std::vector<std::string>::iterator include_paths_end ();
155 inline std::vector<std::string>::const_iterator include_paths_begin () const;
156 inline std::vector<std::string>::const_iterator include_paths_end () const;
158 template <typename _InputIterator>
159 inline _InputIterator eval_expression (_InputIterator __first, _InputIterator __last, Value *result);
161 template <typename _OutputIterator>
162 void file (std::string const &filename, _OutputIterator __result);
164 template <typename _OutputIterator>
165 void file (FILE *fp, _OutputIterator __result);
167 template <typename _InputIterator, typename _OutputIterator>
168 void operator () (_InputIterator __first, _InputIterator __last, _OutputIterator __result);
170 private:
171 inline bool file_isdir (std::string const &__filename) const;
172 inline bool file_exists (std::string const &__filename) const;
173 FILE *find_include_file (std::string const &__filename, std::string *__filepath,
174 INCLUDE_POLICY __include_policy, bool __skip_current_path = false) const;
176 inline int skipping() const;
177 bool test_if_level();
179 inline std::string fix_file_path (std::string const &filename) const;
180 inline bool is_absolute (std::string const &filename) const;
182 PP_DIRECTIVE_TYPE find_directive (char const *__directive, std::size_t __size) const;
184 template <typename _InputIterator>
185 bool find_header_protection (_InputIterator __first, _InputIterator __last, std::string *__prot);
187 template <typename _InputIterator>
188 _InputIterator skip (_InputIterator __first, _InputIterator __last);
190 template <typename _InputIterator>
191 _InputIterator eval_primary(_InputIterator __first, _InputIterator __last, Value *result);
193 template <typename _InputIterator>
194 _InputIterator eval_multiplicative(_InputIterator __first, _InputIterator __last, Value *result);
196 template <typename _InputIterator>
197 _InputIterator eval_additive(_InputIterator __first, _InputIterator __last, Value *result);
199 template <typename _InputIterator>
200 _InputIterator eval_shift(_InputIterator __first, _InputIterator __last, Value *result);
202 template <typename _InputIterator>
203 _InputIterator eval_relational(_InputIterator __first, _InputIterator __last, Value *result);
205 template <typename _InputIterator>
206 _InputIterator eval_equality(_InputIterator __first, _InputIterator __last, Value *result);
208 template <typename _InputIterator>
209 _InputIterator eval_and(_InputIterator __first, _InputIterator __last, Value *result);
211 template <typename _InputIterator>
212 _InputIterator eval_xor(_InputIterator __first, _InputIterator __last, Value *result);
214 template <typename _InputIterator>
215 _InputIterator eval_or(_InputIterator __first, _InputIterator __last, Value *result);
217 template <typename _InputIterator>
218 _InputIterator eval_logical_and(_InputIterator __first, _InputIterator __last, Value *result);
220 template <typename _InputIterator>
221 _InputIterator eval_logical_or(_InputIterator __first, _InputIterator __last, Value *result);
223 template <typename _InputIterator>
224 _InputIterator eval_constant_expression(_InputIterator __first, _InputIterator __last, Value *result);
226 template <typename _InputIterator, typename _OutputIterator>
227 _InputIterator handle_directive(char const *__directive, std::size_t __size,
228 _InputIterator __first, _InputIterator __last, _OutputIterator __result);
230 template <typename _InputIterator, typename _OutputIterator>
231 _InputIterator handle_include(bool skip_current_path, _InputIterator __first, _InputIterator __last,
232 _OutputIterator __result);
234 template <typename _InputIterator>
235 _InputIterator handle_define (_InputIterator __first, _InputIterator __last);
237 template <typename _InputIterator>
238 _InputIterator handle_if (_InputIterator __first, _InputIterator __last);
240 template <typename _InputIterator>
241 _InputIterator handle_else (_InputIterator __first, _InputIterator __last);
243 template <typename _InputIterator>
244 _InputIterator handle_elif (_InputIterator __first, _InputIterator __last);
246 template <typename _InputIterator>
247 _InputIterator handle_endif (_InputIterator __first, _InputIterator __last);
249 template <typename _InputIterator>
250 _InputIterator handle_ifdef (bool check_undefined, _InputIterator __first, _InputIterator __last);
252 template <typename _InputIterator>
253 _InputIterator handle_undef(_InputIterator __first, _InputIterator __last);
255 template <typename _InputIterator>
256 inline char peek_char (_InputIterator __first, _InputIterator __last);
258 template <typename _InputIterator>
259 _InputIterator next_token (_InputIterator __first, _InputIterator __last, int *kind);
262 } // namespace rpp
264 #endif // PP_ENGINE_H
266 // kate: space-indent on; indent-width 2; replace-tabs on;