1 | /* |
---|
2 | * Copyright © 2012 International Characters. |
---|
3 | * This software is licensed to the public under the Open Software License 3.0. |
---|
4 | * icXML is a trademark of International Characters. |
---|
5 | */ |
---|
6 | |
---|
7 | /* |
---|
8 | * @author Nigel Medforth, nigelm -at- interational-characters.com |
---|
9 | * @version $Id: XMLConfig.hpp 224 2012-12-12 03:31:56Z nigelm $ |
---|
10 | * |
---|
11 | */ |
---|
12 | |
---|
13 | /*********************************** FUNCTIONALITY CONFIGURATIONS *************************************/ |
---|
14 | |
---|
15 | #include <xercesc/util/XercesDefs.hpp> |
---|
16 | |
---|
17 | #ifndef SHOW_CALLSTACK_FOR_DEPRECATED_FEATURES |
---|
18 | #define SHOW_CALLSTACK_FOR_DEPRECATED_FEATURES |
---|
19 | #endif |
---|
20 | |
---|
21 | #ifndef PRINT_DEBUG_MESSAGE |
---|
22 | //#define PRINT_DEBUG_MESSAGE |
---|
23 | #endif |
---|
24 | |
---|
25 | #ifndef PRINT_DEBUG_IGNORE_TRANSITION_STREAM_MESSAGES |
---|
26 | //#define PRINT_DEBUG_IGNORE_TRANSITION_STREAM_MESSAGES |
---|
27 | #endif |
---|
28 | |
---|
29 | #ifndef PRINT_DEBUG_IGNORE_GRAMMAR_MESSAGES |
---|
30 | #define PRINT_DEBUG_IGNORE_GRAMMAR_MESSAGES |
---|
31 | #endif |
---|
32 | |
---|
33 | #ifndef PRINT_DEBUG_IGNORE_NAMESPACE_MESSAGES |
---|
34 | #define PRINT_DEBUG_IGNORE_NAMESPACE_MESSAGES |
---|
35 | #endif |
---|
36 | |
---|
37 | #ifndef PRINT_DEBUG_IGNORE_SYMBOL_STREAM_MESSAGES |
---|
38 | //#define PRINT_DEBUG_IGNORE_SYMBOL_STREAM_MESSAGES |
---|
39 | #endif |
---|
40 | |
---|
41 | #ifndef DISABLE_PARSER_LINE_COLUMN_CALCULATION |
---|
42 | #define DISABLE_PARSER_LINE_COLUMN_CALCULATION |
---|
43 | #endif |
---|
44 | |
---|
45 | #ifndef USE_SIMPLE_HASH_TABLE_LOOKUP |
---|
46 | #define USE_SIMPLE_HASH_TABLE_LOOKUP |
---|
47 | #endif |
---|
48 | |
---|
49 | #ifndef TEST_NAMESPACE_RESOLVER |
---|
50 | #define TEST_NAMESPACE_RESOLVER |
---|
51 | #endif |
---|
52 | |
---|
53 | #ifndef TEST_CUCKOO_HASH_TABLE |
---|
54 | #define TEST_CUCKOO_HASH_TABLE |
---|
55 | #endif |
---|
56 | |
---|
57 | #ifndef TEST_PER_SYMBOL_ELEM_DECL_LISTS |
---|
58 | #define TEST_PER_SYMBOL_ELEM_DECL_LISTS |
---|
59 | #endif |
---|
60 | |
---|
61 | #if !defined(STORE_CHILDREN_INFORMATION_IN_PARSER) |
---|
62 | #define STORE_CHILDREN_INFORMATION_IN_PARSER |
---|
63 | #endif |
---|
64 | |
---|
65 | #if !defined(PERFORM_ELEMENT_STACK_MATCHING_IN_PARSER) |
---|
66 | #define PERFORM_ELEMENT_STACK_MATCHING_IN_PARSER |
---|
67 | #endif |
---|
68 | |
---|
69 | #if !defined(TEST_ENTITY_EXPANSION) |
---|
70 | #define TEST_ENTITY_EXPANSION |
---|
71 | #endif |
---|
72 | |
---|
73 | #if !defined(INTERGRATE_SYMBOL_RESOLUTION_INTO_CHARACTER_SET_ADAPTER) |
---|
74 | #define INTERGRATE_SYMBOL_RESOLUTION_INTO_CHARACTER_SET_ADAPTER |
---|
75 | #endif |
---|
76 | |
---|
77 | #if !defined(CALCULATE_COPY_BACK_POSITION) |
---|
78 | //#define CALCULATE_COPY_BACK_POSITION |
---|
79 | #endif |
---|
80 | |
---|
81 | #if !defined(USE_UTF16_BIG_ENDIAN) |
---|
82 | // #define USE_UTF16_BIG_ENDIAN |
---|
83 | #endif |
---|
84 | |
---|
85 | #if !defined(ICXML_ENABLE_VERSION1_1) |
---|
86 | #define ICXML_ENABLE_VERSION1_1 // to safely turn this on, any symbol ending with a NEL must be 'truncated' to remove the erroneous bytes. |
---|
87 | #endif |
---|
88 | |
---|
89 | /* does nothing so far; there is an advantage in replacing the internal attr list functionality |
---|
90 | with a more refined one--but this will require modifying the /internal/VecAttrListImpl and |
---|
91 | /internal/VecAttributesImpl classes to support the new type */ |
---|
92 | //#define REPLACE_INTERNAL_SCANNER_ATTRIBUTE_LIST |
---|
93 | |
---|
94 | #ifndef XML_CONFIG_HPP_GUARD |
---|
95 | #define XML_CONFIG_HPP_GUARD |
---|
96 | |
---|
97 | #include <simd-lib/bitblock.hpp> |
---|
98 | |
---|
99 | typedef ScanWord scanword_t; |
---|
100 | |
---|
101 | #include <icxmlc/clog2.h> |
---|
102 | #include <xercesc/util/XercesDefs.hpp> |
---|
103 | #include <cstddef> |
---|
104 | |
---|
105 | enum |
---|
106 | { |
---|
107 | LOG_2_BLOCK_SIZE = CONST_LOG_2(BLOCK_SIZE) |
---|
108 | }; |
---|
109 | |
---|
110 | #ifdef __ARCH_64 |
---|
111 | #undef __ARCH_64 |
---|
112 | #endif |
---|
113 | |
---|
114 | #if defined (_MSC_VER) && defined(_M_X64) |
---|
115 | #define __ARCH_64 |
---|
116 | #elif defined (__GNUC__) && defined(__x86_64__) |
---|
117 | #define __ARCH_64 |
---|
118 | #endif |
---|
119 | |
---|
120 | /************************************ BUFFER SIZE CONFIGURATIONS **************************************/ |
---|
121 | |
---|
122 | #define BUFFER_BLOCKS ((16 * 1024) / BLOCK_SIZE) |
---|
123 | |
---|
124 | #define INITIAL_CONTENT_BUFFER_SIZE (2 * BUFFER_BLOCKS * BLOCK_SIZE) |
---|
125 | |
---|
126 | #define INITIAL_SYMBOL_TABLE_CAPACITY 101 |
---|
127 | |
---|
128 | #define INITIAL_SYMBOL_TABLE_STRING_POOL_SIZE (1024) |
---|
129 | |
---|
130 | #define INITIAL_MAX_SCOPE 16 |
---|
131 | |
---|
132 | #define EXPECTED_LEAF_NODE_COUNT 32 |
---|
133 | |
---|
134 | #define INITIAL_ATTRIBUTE_LIST_SIZE 16 |
---|
135 | |
---|
136 | #define INITIAL_NAMESPACE_RESOLVER_STRING_POOL_SIZE 2048 |
---|
137 | |
---|
138 | #define GET_CONTEXT_ID_FOR_EACH_ELEMENT |
---|
139 | |
---|
140 | #if INITIAL_CONTENT_BUFFER_SIZE > (64 * 1024) |
---|
141 | #define USE_HEAP_ALLOCATION_FOR_XML_PARSER |
---|
142 | #endif |
---|
143 | |
---|
144 | /* PREFETCH */ |
---|
145 | #ifdef __GNUC__ |
---|
146 | #define PREFETCH(x) __builtin_prefetch((void*)(x)); |
---|
147 | #elif defined _MSC_VER |
---|
148 | #define PREFETCH(x) _mm_prefetch((char*)(x), _MM_HINT_NTA); |
---|
149 | #else |
---|
150 | #define PREFETCH(x) |
---|
151 | #endif |
---|
152 | |
---|
153 | /* UNREACHABLE */ |
---|
154 | #ifdef _DEBUG |
---|
155 | #define UNREACHABLE assert(!"UNREACHABLE CODE EXECUTED!"); |
---|
156 | #elif defined(__GNUC__) |
---|
157 | // built-in unreachable is only valid from gcc 4.5 and above |
---|
158 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) |
---|
159 | #define UNREACHABLE __builtin_unreachable(); // requires -Wunreachable-code? |
---|
160 | #else |
---|
161 | #define UNREACHABLE abort(); |
---|
162 | #endif |
---|
163 | #elif defined _MSC_VER |
---|
164 | #define UNREACHABLE __assume(0); |
---|
165 | #else |
---|
166 | #define UNREACHABLE |
---|
167 | #endif |
---|
168 | |
---|
169 | /* ASSUME */ |
---|
170 | #ifdef __GNUC__ |
---|
171 | // built-in unreachable is only valid from gcc 4.5 and above |
---|
172 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) |
---|
173 | #define ASSUME(cond) // do { if (!(cond)) { UNREACHABLE } } while (0); |
---|
174 | #else |
---|
175 | #define ASSUME(cond) |
---|
176 | #endif |
---|
177 | #elif defined _MSC_VER |
---|
178 | #define ASSUME(cond) __assume(cond); |
---|
179 | #else |
---|
180 | #define ASSUME(cond) |
---|
181 | #endif |
---|
182 | |
---|
183 | /* IS_COMPILE_TIME_CONSTANT */ |
---|
184 | #define IS_COMPILE_TIME_CONSTANT(x) x//__builtin_constant_p(x) |
---|
185 | |
---|
186 | /* DEPRECATED_FEATURE_IN_ICXML */ |
---|
187 | #ifdef SHOW_CALLSTACK_FOR_DEPRECATED_FEATURES |
---|
188 | #include <icxmlc/backtrace.h> |
---|
189 | #define DEPRECATED_FEATURE_IN_ICXML assert(deprecatedFeatureUsed()); throw; |
---|
190 | #else |
---|
191 | #define DEPRECATED_FEATURE_IN_ICXML throw;/* TODO: create xerces-compatible exception to throw */ |
---|
192 | #endif |
---|
193 | |
---|
194 | #ifdef USE_SIMPLE_HASH_TABLE_LOOKUP |
---|
195 | typedef uint32_t gid_t; |
---|
196 | #else |
---|
197 | #include <icxmlc/symbol_table/src/gid.hpp> |
---|
198 | typedef gid_type gid_t; |
---|
199 | #endif |
---|
200 | |
---|
201 | #ifdef PRINT_DEBUG_MESSAGE |
---|
202 | |
---|
203 | #include <icxercesc/util/XMLString.hpp> |
---|
204 | #include <iostream> |
---|
205 | #include <iomanip> |
---|
206 | |
---|
207 | #define DEBUG_MESSAGE(MSG) \ |
---|
208 | try \ |
---|
209 | { \ |
---|
210 | XERCES_STD_QUALIFIER clog << MSG << XERCES_STD_QUALIFIER endl; \ |
---|
211 | } \ |
---|
212 | catch (...) \ |
---|
213 | { \ |
---|
214 | XERCES_STD_QUALIFIER clog << "!! DEBUG MESSAGE ERROR: " << __FILE__ << "." << __LINE__ << " !!" << XERCES_STD_QUALIFIER endl; \ |
---|
215 | exit(-2); \ |
---|
216 | } |
---|
217 | |
---|
218 | XERCES_CPP_NAMESPACE_BEGIN |
---|
219 | |
---|
220 | inline void __normalize_whitespace(std::ostream & out, char * string) |
---|
221 | { |
---|
222 | char * ptr = string; |
---|
223 | out << '"'; |
---|
224 | while (*ptr) |
---|
225 | { |
---|
226 | if (unlikely(*ptr < 0x20)) |
---|
227 | { |
---|
228 | unsigned int val = *ptr; |
---|
229 | *ptr = 0; |
---|
230 | |
---|
231 | out << string << '\\' << std::hex << val << std::dec; |
---|
232 | |
---|
233 | string = ptr + 1; |
---|
234 | } |
---|
235 | ptr++; |
---|
236 | } |
---|
237 | out << string << '"'; |
---|
238 | } |
---|
239 | |
---|
240 | inline static std::ostream & operator << (std::ostream & out, const XMLCh * const string) |
---|
241 | { |
---|
242 | if (string) |
---|
243 | { |
---|
244 | try |
---|
245 | { |
---|
246 | |
---|
247 | char buf[1024]; |
---|
248 | char * output; |
---|
249 | XMLSize_t len = XMLString::stringLen(string); |
---|
250 | |
---|
251 | if (len < 1024) |
---|
252 | { |
---|
253 | XMLString::transcode(string, &buf[0], 1024); |
---|
254 | __normalize_whitespace(out, &buf[0]); |
---|
255 | } |
---|
256 | else |
---|
257 | { |
---|
258 | output = XMLString::transcode(string); |
---|
259 | __normalize_whitespace(out, output); |
---|
260 | XMLString::release(&output); |
---|
261 | } |
---|
262 | |
---|
263 | // const XMLCh * ptr = string; |
---|
264 | |
---|
265 | // char buf[257] = {0}; |
---|
266 | |
---|
267 | // const char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7' |
---|
268 | // , '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; |
---|
269 | |
---|
270 | // size_t i = 0; |
---|
271 | // bool done = 0; |
---|
272 | // while (!done) |
---|
273 | // { |
---|
274 | // for (int j = 0; j < 8; j++) |
---|
275 | // { |
---|
276 | // XMLCh ch = *ptr++; |
---|
277 | |
---|
278 | // done |= (*ptr == 0); |
---|
279 | |
---|
280 | // XMLCh d = ch & 15; |
---|
281 | // XMLCh c = (ch >> 4) & 15; |
---|
282 | // XMLCh b = (ch >> 8) & 15; |
---|
283 | // XMLCh a = (ch >> 12) & 15; |
---|
284 | |
---|
285 | // buf[i + 0] = hex[a]; |
---|
286 | // buf[i + 1] = hex[b]; |
---|
287 | // buf[i + 2] = hex[c]; |
---|
288 | // buf[i + 3] = hex[d]; |
---|
289 | |
---|
290 | // i += 4; |
---|
291 | |
---|
292 | // if (i == 256) |
---|
293 | // { |
---|
294 | // out << (const char*)&buf[0]; |
---|
295 | // i = 0; |
---|
296 | // } |
---|
297 | // } |
---|
298 | // } |
---|
299 | // buf[i] = 0; |
---|
300 | // out << (const char*)&buf[0]; |
---|
301 | } |
---|
302 | catch (std::exception & e) |
---|
303 | { |
---|
304 | out << '|' << e.what() << '|'; |
---|
305 | } |
---|
306 | catch (...) |
---|
307 | { |
---|
308 | /* do nothing */ |
---|
309 | } |
---|
310 | } |
---|
311 | return out; |
---|
312 | } |
---|
313 | |
---|
314 | inline static std::ostream & operator << (std::ostream & out, const BytePack & block) |
---|
315 | { |
---|
316 | char output[sizeof(BytePack) * 3] = {0}; |
---|
317 | |
---|
318 | const char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7' |
---|
319 | , '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; |
---|
320 | |
---|
321 | ubitblock value; |
---|
322 | value._128 = block; |
---|
323 | |
---|
324 | for(unsigned int i = 0; i < sizeof(BytePack); i++) |
---|
325 | { |
---|
326 | const char c = value._8[i]; |
---|
327 | const size_t offset = (sizeof(BytePack) - 1 - i) * 3; |
---|
328 | output[offset] = hex[(c & 0xF0) >> 4]; |
---|
329 | output[offset + 1] = hex[c & 0x0F]; |
---|
330 | output[offset + 2] = ' '; |
---|
331 | } |
---|
332 | |
---|
333 | out << output; |
---|
334 | |
---|
335 | return out; |
---|
336 | } |
---|
337 | |
---|
338 | XERCES_CPP_NAMESPACE_END |
---|
339 | |
---|
340 | #else |
---|
341 | #define DEBUG_MESSAGE(MSG) |
---|
342 | #endif |
---|
343 | |
---|
344 | #if !defined(PRINT_DEBUG_IGNORE_TRANSITION_STREAM_MESSAGES) |
---|
345 | #define DEBUG_TRANSITION_MESSAGE(MSG) DEBUG_MESSAGE(MSG) |
---|
346 | #else |
---|
347 | #define DEBUG_TRANSITION_MESSAGE(MSG) |
---|
348 | #endif |
---|
349 | |
---|
350 | #if !defined(PRINT_DEBUG_IGNORE_GRAMMAR_MESSAGES) |
---|
351 | #define DEBUG_GRAMMAR_MESSAGE(MSG) DEBUG_MESSAGE(MSG) |
---|
352 | #else |
---|
353 | #define DEBUG_GRAMMAR_MESSAGE(MSG) |
---|
354 | #endif |
---|
355 | |
---|
356 | #if !defined(PRINT_DEBUG_IGNORE_NAMESPACE_MESSAGES) |
---|
357 | #define DEBUG_NAMESPACE_MESSAGE(MSG) DEBUG_MESSAGE(MSG) |
---|
358 | #else |
---|
359 | #define DEBUG_NAMESPACE_MESSAGE(MSG) |
---|
360 | #endif |
---|
361 | |
---|
362 | #if !defined(PRINT_DEBUG_IGNORE_SYMBOL_STREAM_MESSAGES) |
---|
363 | #define DEBUG_SYMBOL_MESSAGE(MSG) DEBUG_MESSAGE(MSG) |
---|
364 | #else |
---|
365 | #define DEBUG_SYMBOL_MESSAGE(MSG) |
---|
366 | #endif |
---|
367 | |
---|
368 | IDISA_ALWAYS_INLINE |
---|
369 | static BitBlock maskli(const uint64_t position) |
---|
370 | { |
---|
371 | return bitblock::sll(simd<1>::constant<1>(), convert(position)); |
---|
372 | } |
---|
373 | |
---|
374 | IDISA_ALWAYS_INLINE |
---|
375 | static BitBlock maskre(const uint64_t position) |
---|
376 | { |
---|
377 | return simd_not(maskli(position)); |
---|
378 | } |
---|
379 | |
---|
380 | IDISA_ALWAYS_INLINE |
---|
381 | static BitBlock maskri(const uint64_t position) |
---|
382 | { |
---|
383 | return bitblock::srl(simd<1>::constant<1>(), convert(BLOCK_SIZE - 1 - position)); |
---|
384 | } |
---|
385 | |
---|
386 | IDISA_ALWAYS_INLINE |
---|
387 | static BitBlock maskle(const uint64_t position) |
---|
388 | { |
---|
389 | return simd_not(maskri(position)); |
---|
390 | } |
---|
391 | |
---|
392 | IDISA_ALWAYS_INLINE |
---|
393 | static void store_aligned_bypass_cache(const BitBlock reg, BitBlock * const output) |
---|
394 | { |
---|
395 | #ifndef IGNORE_CACHE_BYPASS |
---|
396 | _mm_stream_si128(output, reg); |
---|
397 | #else |
---|
398 | bitblock::store_aligned(reg, output); |
---|
399 | #endif |
---|
400 | } |
---|
401 | |
---|
402 | IDISA_ALWAYS_INLINE |
---|
403 | static void load_fence() |
---|
404 | { |
---|
405 | #ifndef IGNORE_CACHE_BYPASS |
---|
406 | _mm_lfence(); |
---|
407 | #endif |
---|
408 | } |
---|
409 | |
---|
410 | IDISA_ALWAYS_INLINE |
---|
411 | static void store_fence() |
---|
412 | { |
---|
413 | #ifndef IGNORE_CACHE_BYPASS |
---|
414 | _mm_mfence(); |
---|
415 | #endif |
---|
416 | } |
---|
417 | |
---|
418 | #endif |
---|