]> andersk Git - libyaml.git/blob - src/yaml_private.h
Fixed most compiler warnings -Wall -Wextra
[libyaml.git] / src / yaml_private.h
1 #if HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4
5 #include <yaml.h>
6
7 #include <assert.h>
8 #include <limits.h>
9 #include <stddef.h>
10
11 #ifndef _MSC_VER
12 #if defined(__sun) || defined(__sun__)
13 #include <sys/inttypes.h>
14 #define PTRDIFF_MAX INT_MAX
15 #else
16 #include <stdint.h>
17 #ifndef PTRDIFF_MAX /* gcc on HP-UX */
18 #ifdef _LP64
19 #define PTRDIFF_MAX 0x7FFFFFFFFFFFFFFFLL
20 #else
21 #define PTRDIFF_MAX 0x7FFFFFFFL
22 #endif
23 #endif
24 #endif
25 #else
26 #ifdef _WIN64
27 #define PTRDIFF_MAX _I64_MAX
28 #else
29 #define PTRDIFF_MAX INT_MAX
30 #endif
31 #endif
32
33 /*
34  * Memory management.
35  */
36
37 YAML_DECLARE(void *)
38 yaml_malloc(size_t size);
39
40 YAML_DECLARE(void *)
41 yaml_realloc(void *ptr, size_t size);
42
43 YAML_DECLARE(void)
44 yaml_free(void *ptr);
45
46 YAML_DECLARE(yaml_char_t *)
47 yaml_strdup(const yaml_char_t *);
48
49 /*
50  * Reader: Ensure that the buffer contains at least `length` characters.
51  */
52
53 YAML_DECLARE(int)
54 yaml_parser_update_buffer(yaml_parser_t *parser, size_t length);
55
56 /*
57  * Scanner: Ensure that the token stack contains at least one token ready.
58  */
59
60 YAML_DECLARE(int)
61 yaml_parser_fetch_more_tokens(yaml_parser_t *parser);
62
63 /*
64  * The size of the input raw buffer.
65  */
66
67 #define INPUT_RAW_BUFFER_SIZE   16384
68
69 /*
70  * The size of the input buffer.
71  *
72  * It should be possible to decode the whole raw buffer.
73  */
74
75 #define INPUT_BUFFER_SIZE       (INPUT_RAW_BUFFER_SIZE*3)
76
77 /*
78  * The size of the output buffer.
79  */
80
81 #define OUTPUT_BUFFER_SIZE      16384
82
83 /*
84  * The size of the output raw buffer.
85  *
86  * It should be possible to encode the whole output buffer.
87  */
88
89 #define OUTPUT_RAW_BUFFER_SIZE  (OUTPUT_BUFFER_SIZE*2+2)
90
91 /*
92  * The size of other stacks and queues.
93  */
94
95 #define INITIAL_STACK_SIZE  16
96 #define INITIAL_QUEUE_SIZE  16
97 #define INITIAL_STRING_SIZE 16
98
99 /*
100  * Buffer management.
101  */
102
103 #define BUFFER_INIT(context,buffer,size)                                        \
104   (((buffer).start = (yaml_char_t *)yaml_malloc(size)) ?                        \
105         ((buffer).last = (buffer).pointer = (buffer).start,                     \
106          (buffer).end = (buffer).start+(size),                                  \
107          1) :                                                                   \
108         ((context)->error = YAML_MEMORY_ERROR,                                  \
109          0))
110
111 #define BUFFER_DEL(context,buffer)                                              \
112     (yaml_free((buffer).start),                                                 \
113      (buffer).start = (buffer).pointer = (buffer).end = 0)
114
115 /*
116  * String management.
117  */
118
119 typedef struct {
120     yaml_char_t *start;
121     yaml_char_t *end;
122     yaml_char_t *pointer;
123 } yaml_string_t;
124
125 YAML_DECLARE(int)
126 yaml_string_extend(yaml_char_t **start,
127         yaml_char_t **pointer, yaml_char_t **end);
128
129 YAML_DECLARE(int)
130 yaml_string_join(
131         yaml_char_t **a_start, yaml_char_t **a_pointer, yaml_char_t **a_end,
132         yaml_char_t **b_start, yaml_char_t **b_pointer, yaml_char_t **b_end);
133
134 #define NULL_STRING { NULL, NULL, NULL }
135
136 #define STRING(string,length)   { (string), (string)+(length), (string) }
137
138 #define STRING_ASSIGN(value,string,length)                                      \
139     ((value).start = (string),                                                  \
140      (value).end = (string)+(length),                                           \
141      (value).pointer = (string))
142
143 #define STRING_INIT(context,string,size)                                        \
144     (((string).start = YAML_MALLOC(size)) ?                                     \
145         ((string).pointer = (string).start,                                     \
146          (string).end = (string).start+(size),                                  \
147          memset((string).start, 0, (size)),                                     \
148          1) :                                                                   \
149         ((context)->error = YAML_MEMORY_ERROR,                                  \
150          0))
151
152 #define STRING_DEL(context,string)                                              \
153     (yaml_free((string).start),                                                 \
154      (string).start = (string).pointer = (string).end = 0)
155
156 #define STRING_EXTEND(context,string)                                           \
157     ((((string).pointer+5 < (string).end)                                       \
158         || yaml_string_extend(&(string).start,                                  \
159             &(string).pointer, &(string).end)) ?                                \
160          1 :                                                                    \
161         ((context)->error = YAML_MEMORY_ERROR,                                  \
162          0))
163
164 #define CLEAR(context,string)                                                   \
165     ((string).pointer = (string).start,                                         \
166      memset((string).start, 0, (string).end-(string).start))
167
168 #define JOIN(context,string_a,string_b)                                         \
169     ((yaml_string_join(&(string_a).start, &(string_a).pointer,                  \
170                        &(string_a).end, &(string_b).start,                      \
171                        &(string_b).pointer, &(string_b).end)) ?                 \
172         ((string_b).pointer = (string_b).start,                                 \
173          1) :                                                                   \
174         ((context)->error = YAML_MEMORY_ERROR,                                  \
175          0))
176
177 /*
178  * String check operations.
179  */
180
181 /*
182  * Check the octet at the specified position.
183  */
184
185 #define CHECK_AT(string,octet,offset)                                           \
186     ((string).pointer[offset] == (yaml_char_t)(octet))
187
188 /*
189  * Check the current octet in the buffer.
190  */
191
192 #define CHECK(string,octet) CHECK_AT((string),(octet),0)
193
194 /*
195  * Check if the character at the specified position is an alphabetical
196  * character, a digit, '_', or '-'.
197  */
198
199 #define IS_ALPHA_AT(string,offset)                                              \
200      (((string).pointer[offset] >= (yaml_char_t) '0' &&                         \
201        (string).pointer[offset] <= (yaml_char_t) '9') ||                        \
202       ((string).pointer[offset] >= (yaml_char_t) 'A' &&                         \
203        (string).pointer[offset] <= (yaml_char_t) 'Z') ||                        \
204       ((string).pointer[offset] >= (yaml_char_t) 'a' &&                         \
205        (string).pointer[offset] <= (yaml_char_t) 'z') ||                        \
206       (string).pointer[offset] == '_' ||                                        \
207       (string).pointer[offset] == '-')
208
209 #define IS_ALPHA(string)    IS_ALPHA_AT((string),0)
210
211 /*
212  * Check if the character at the specified position is a digit.
213  */
214
215 #define IS_DIGIT_AT(string,offset)                                              \
216      (((string).pointer[offset] >= (yaml_char_t) '0' &&                         \
217        (string).pointer[offset] <= (yaml_char_t) '9'))
218
219 #define IS_DIGIT(string)    IS_DIGIT_AT((string),0)
220
221 /*
222  * Get the value of a digit.
223  */
224
225 #define AS_DIGIT_AT(string,offset)                                              \
226      ((string).pointer[offset] - (yaml_char_t) '0')
227
228 #define AS_DIGIT(string)    AS_DIGIT_AT((string),0)
229
230 /*
231  * Check if the character at the specified position is a hex-digit.
232  */
233
234 #define IS_HEX_AT(string,offset)                                                \
235      (((string).pointer[offset] >= (yaml_char_t) '0' &&                         \
236        (string).pointer[offset] <= (yaml_char_t) '9') ||                        \
237       ((string).pointer[offset] >= (yaml_char_t) 'A' &&                         \
238        (string).pointer[offset] <= (yaml_char_t) 'F') ||                        \
239       ((string).pointer[offset] >= (yaml_char_t) 'a' &&                         \
240        (string).pointer[offset] <= (yaml_char_t) 'f'))
241
242 #define IS_HEX(string)    IS_HEX_AT((string),0)
243
244 /*
245  * Get the value of a hex-digit.
246  */
247
248 #define AS_HEX_AT(string,offset)                                                \
249       (((string).pointer[offset] >= (yaml_char_t) 'A' &&                        \
250         (string).pointer[offset] <= (yaml_char_t) 'F') ?                        \
251        ((string).pointer[offset] - (yaml_char_t) 'A' + 10) :                    \
252        ((string).pointer[offset] >= (yaml_char_t) 'a' &&                        \
253         (string).pointer[offset] <= (yaml_char_t) 'f') ?                        \
254        ((string).pointer[offset] - (yaml_char_t) 'a' + 10) :                    \
255        ((string).pointer[offset] - (yaml_char_t) '0'))
256
257 #define AS_HEX(string)  AS_HEX_AT((string),0)
258
259 /*
260  * Check if the character is ASCII.
261  */
262
263 #define IS_ASCII_AT(string,offset)                                              \
264     ((string).pointer[offset] <= (yaml_char_t) '\x7F')
265
266 #define IS_ASCII(string)    IS_ASCII_AT((string),0)
267
268 /*
269  * Check if the character can be printed unescaped.
270  */
271
272 #define IS_PRINTABLE_AT(string,offset)                                          \
273     (((string).pointer[offset] == 0x0A)         /* . == #x0A */                 \
274      || ((string).pointer[offset] >= 0x20       /* #x20 <= . <= #x7E */         \
275          && (string).pointer[offset] <= 0x7E)                                   \
276      || ((string).pointer[offset] == 0xC2       /* #0xA0 <= . <= #xD7FF */      \
277          && (string).pointer[offset+1] >= 0xA0)                                 \
278      || ((string).pointer[offset] > 0xC2                                        \
279          && (string).pointer[offset] < 0xED)                                    \
280      || ((string).pointer[offset] == 0xED                                       \
281          && (string).pointer[offset+1] < 0xA0)                                  \
282      || ((string).pointer[offset] == 0xEE)                                      \
283      || ((string).pointer[offset] == 0xEF      /* #xE000 <= . <= #xFFFD */      \
284          && !((string).pointer[offset+1] == 0xBB        /* && . != #xFEFF */    \
285              && (string).pointer[offset+2] == 0xBF)                             \
286          && !((string).pointer[offset+1] == 0xBF                                \
287              && ((string).pointer[offset+2] == 0xBE                             \
288                  || (string).pointer[offset+2] == 0xBF))))
289
290 #define IS_PRINTABLE(string)    IS_PRINTABLE_AT((string),0)
291
292 /*
293  * Check if the character at the specified position is NUL.
294  */
295
296 #define IS_Z_AT(string,offset)    CHECK_AT((string),'\0',(offset))
297
298 #define IS_Z(string)    IS_Z_AT((string),0)
299
300 /*
301  * Check if the character at the specified position is BOM.
302  */
303
304 #define IS_BOM_AT(string,offset)                                                \
305      (CHECK_AT((string),'\xEF',(offset))                                        \
306       && CHECK_AT((string),'\xBB',(offset)+1)                                   \
307       && CHECK_AT((string),'\xBF',(offset)+2))  /* BOM (#xFEFF) */
308
309 #define IS_BOM(string)  IS_BOM_AT(string,0)
310
311 /*
312  * Check if the character at the specified position is space.
313  */
314
315 #define IS_SPACE_AT(string,offset)  CHECK_AT((string),' ',(offset))
316
317 #define IS_SPACE(string)    IS_SPACE_AT((string),0)
318
319 /*
320  * Check if the character at the specified position is tab.
321  */
322
323 #define IS_TAB_AT(string,offset)    CHECK_AT((string),'\t',(offset))
324
325 #define IS_TAB(string)  IS_TAB_AT((string),0)
326
327 /*
328  * Check if the character at the specified position is blank (space or tab).
329  */
330
331 #define IS_BLANK_AT(string,offset)                                              \
332     (IS_SPACE_AT((string),(offset)) || IS_TAB_AT((string),(offset)))
333
334 #define IS_BLANK(string)    IS_BLANK_AT((string),0)
335
336 /*
337  * Check if the character at the specified position is a line break.
338  */
339
340 #define IS_BREAK_AT(string,offset)                                              \
341     (CHECK_AT((string),'\r',(offset))               /* CR (#xD)*/               \
342      || CHECK_AT((string),'\n',(offset))            /* LF (#xA) */              \
343      || (CHECK_AT((string),'\xC2',(offset))                                     \
344          && CHECK_AT((string),'\x85',(offset)+1))   /* NEL (#x85) */            \
345      || (CHECK_AT((string),'\xE2',(offset))                                     \
346          && CHECK_AT((string),'\x80',(offset)+1)                                \
347          && CHECK_AT((string),'\xA8',(offset)+2))   /* LS (#x2028) */           \
348      || (CHECK_AT((string),'\xE2',(offset))                                     \
349          && CHECK_AT((string),'\x80',(offset)+1)                                \
350          && CHECK_AT((string),'\xA9',(offset)+2)))  /* PS (#x2029) */
351
352 #define IS_BREAK(string)    IS_BREAK_AT((string),0)
353
354 #define IS_CRLF_AT(string,offset)                                               \
355      (CHECK_AT((string),'\r',(offset)) && CHECK_AT((string),'\n',(offset)+1))
356
357 #define IS_CRLF(string) IS_CRLF_AT((string),0)
358
359 /*
360  * Check if the character is a line break or NUL.
361  */
362
363 #define IS_BREAKZ_AT(string,offset)                                             \
364     (IS_BREAK_AT((string),(offset)) || IS_Z_AT((string),(offset)))
365
366 #define IS_BREAKZ(string)   IS_BREAKZ_AT((string),0)
367
368 /*
369  * Check if the character is a line break, space, or NUL.
370  */
371
372 #define IS_SPACEZ_AT(string,offset)                                             \
373     (IS_SPACE_AT((string),(offset)) || IS_BREAKZ_AT((string),(offset)))
374
375 #define IS_SPACEZ(string)   IS_SPACEZ_AT((string),0)
376
377 /*
378  * Check if the character is a line break, space, tab, or NUL.
379  */
380
381 #define IS_BLANKZ_AT(string,offset)                                             \
382     (IS_BLANK_AT((string),(offset)) || IS_BREAKZ_AT((string),(offset)))
383
384 #define IS_BLANKZ(string)   IS_BLANKZ_AT((string),0)
385
386 /*
387  * Determine the width of the character.
388  */
389
390 #define WIDTH_AT(string,offset)                                                 \
391      (((string).pointer[offset] & 0x80) == 0x00 ? 1 :                           \
392       ((string).pointer[offset] & 0xE0) == 0xC0 ? 2 :                           \
393       ((string).pointer[offset] & 0xF0) == 0xE0 ? 3 :                           \
394       ((string).pointer[offset] & 0xF8) == 0xF0 ? 4 : 0)
395
396 #define WIDTH(string)   WIDTH_AT((string),0)
397
398 /*
399  * Move the string pointer to the next character.
400  */
401
402 #define MOVE(string)    ((string).pointer += WIDTH((string)))
403
404 /*
405  * Copy a character and move the pointers of both strings.
406  */
407
408 #define COPY(string_a,string_b)                                                 \
409     ((*(string_b).pointer & 0x80) == 0x00 ?                                     \
410      (*((string_a).pointer++) = *((string_b).pointer++)) :                      \
411      (*(string_b).pointer & 0xE0) == 0xC0 ?                                     \
412      (*((string_a).pointer++) = *((string_b).pointer++),                        \
413       *((string_a).pointer++) = *((string_b).pointer++)) :                      \
414      (*(string_b).pointer & 0xF0) == 0xE0 ?                                     \
415      (*((string_a).pointer++) = *((string_b).pointer++),                        \
416       *((string_a).pointer++) = *((string_b).pointer++),                        \
417       *((string_a).pointer++) = *((string_b).pointer++)) :                      \
418      (*(string_b).pointer & 0xF8) == 0xF0 ?                                     \
419      (*((string_a).pointer++) = *((string_b).pointer++),                        \
420       *((string_a).pointer++) = *((string_b).pointer++),                        \
421       *((string_a).pointer++) = *((string_b).pointer++),                        \
422       *((string_a).pointer++) = *((string_b).pointer++)) : 0)
423
424 /*
425  * Stack and queue management.
426  */
427
428 YAML_DECLARE(int)
429 yaml_stack_extend(void **start, void **top, void **end);
430
431 YAML_DECLARE(int)
432 yaml_queue_extend(void **start, void **head, void **tail, void **end);
433
434 #define STACK_INIT(context,stack,type)                                     \
435   (((stack).start = (type)yaml_malloc(INITIAL_STACK_SIZE*sizeof(*(stack).start))) ? \
436         ((stack).top = (stack).start,                                           \
437          (stack).end = (stack).start+INITIAL_STACK_SIZE,                        \
438          1) :                                                                   \
439         ((context)->error = YAML_MEMORY_ERROR,                                  \
440          0))
441
442 #define STACK_DEL(context,stack)                                                \
443     (yaml_free((stack).start),                                                  \
444      (stack).start = (stack).top = (stack).end = 0)
445
446 #define STACK_EMPTY(context,stack)                                              \
447     ((stack).start == (stack).top)
448
449 #define STACK_LIMIT(context,stack,size)                                         \
450     ((stack).top - (stack).start < (size) ?                                     \
451         1 :                                                                     \
452         ((context)->error = YAML_MEMORY_ERROR,                                  \
453          0))
454
455 #define PUSH(context,stack,value)                                               \
456     (((stack).top != (stack).end                                                \
457       || yaml_stack_extend((void **)&(stack).start,                             \
458               (void **)&(stack).top, (void **)&(stack).end)) ?                  \
459         (*((stack).top++) = value,                                              \
460          1) :                                                                   \
461         ((context)->error = YAML_MEMORY_ERROR,                                  \
462          0))
463
464 #define POP(context,stack)                                                      \
465     (*(--(stack).top))
466
467 #define QUEUE_INIT(context,queue,size,type)                                     \
468   (((queue).start = (type)yaml_malloc((size)*sizeof(*(queue).start))) ?         \
469         ((queue).head = (queue).tail = (queue).start,                           \
470          (queue).end = (queue).start+(size),                                    \
471          1) :                                                                   \
472         ((context)->error = YAML_MEMORY_ERROR,                                  \
473          0))
474
475 #define QUEUE_DEL(context,queue)                                                \
476     (yaml_free((queue).start),                                                  \
477      (queue).start = (queue).head = (queue).tail = (queue).end = 0)
478
479 #define QUEUE_EMPTY(context,queue)                                              \
480     ((queue).head == (queue).tail)
481
482 #define ENQUEUE(context,queue,value)                                            \
483     (((queue).tail != (queue).end                                               \
484       || yaml_queue_extend((void **)&(queue).start, (void **)&(queue).head,     \
485             (void **)&(queue).tail, (void **)&(queue).end)) ?                   \
486         (*((queue).tail++) = value,                                             \
487          1) :                                                                   \
488         ((context)->error = YAML_MEMORY_ERROR,                                  \
489          0))
490
491 #define DEQUEUE(context,queue)                                                  \
492     (*((queue).head++))
493
494 #define QUEUE_INSERT(context,queue,index,value)                                 \
495     (((queue).tail != (queue).end                                               \
496       || yaml_queue_extend((void **)&(queue).start, (void **)&(queue).head,     \
497             (void **)&(queue).tail, (void **)&(queue).end)) ?                   \
498         (memmove((queue).head+(index)+1,(queue).head+(index),                   \
499             ((queue).tail-(queue).head-(index))*sizeof(*(queue).start)),        \
500          *((queue).head+(index)) = value,                                       \
501          (queue).tail++,                                                        \
502          1) :                                                                   \
503         ((context)->error = YAML_MEMORY_ERROR,                                  \
504          0))
505
506 /*
507  * Token initializers.
508  */
509
510 #define TOKEN_INIT(token,token_type,token_start_mark,token_end_mark)            \
511     (memset(&(token), 0, sizeof(yaml_token_t)),                                 \
512      (token).type = (token_type),                                               \
513      (token).start_mark = (token_start_mark),                                   \
514      (token).end_mark = (token_end_mark))
515
516 #define STREAM_START_TOKEN_INIT(token,token_encoding,start_mark,end_mark)       \
517     (TOKEN_INIT((token),YAML_STREAM_START_TOKEN,(start_mark),(end_mark)),       \
518      (token).data.stream_start.encoding = (token_encoding))
519
520 #define STREAM_END_TOKEN_INIT(token,start_mark,end_mark)                        \
521     (TOKEN_INIT((token),YAML_STREAM_END_TOKEN,(start_mark),(end_mark)))
522
523 #define ALIAS_TOKEN_INIT(token,token_value,start_mark,end_mark)                 \
524     (TOKEN_INIT((token),YAML_ALIAS_TOKEN,(start_mark),(end_mark)),              \
525      (token).data.alias.value = (token_value))
526
527 #define ANCHOR_TOKEN_INIT(token,token_value,start_mark,end_mark)                \
528     (TOKEN_INIT((token),YAML_ANCHOR_TOKEN,(start_mark),(end_mark)),             \
529      (token).data.anchor.value = (token_value))
530
531 #define TAG_TOKEN_INIT(token,token_handle,token_suffix,start_mark,end_mark)     \
532     (TOKEN_INIT((token),YAML_TAG_TOKEN,(start_mark),(end_mark)),                \
533      (token).data.tag.handle = (token_handle),                                  \
534      (token).data.tag.suffix = (token_suffix))
535
536 #define SCALAR_TOKEN_INIT(token,token_value,token_length,token_style,start_mark,end_mark)   \
537     (TOKEN_INIT((token),YAML_SCALAR_TOKEN,(start_mark),(end_mark)),             \
538      (token).data.scalar.value = (token_value),                                 \
539      (token).data.scalar.length = (token_length),                               \
540      (token).data.scalar.style = (token_style))
541
542 #define VERSION_DIRECTIVE_TOKEN_INIT(token,token_major,token_minor,start_mark,end_mark)     \
543     (TOKEN_INIT((token),YAML_VERSION_DIRECTIVE_TOKEN,(start_mark),(end_mark)),  \
544      (token).data.version_directive.major = (token_major),                      \
545      (token).data.version_directive.minor = (token_minor))
546
547 #define TAG_DIRECTIVE_TOKEN_INIT(token,token_handle,token_prefix,start_mark,end_mark)       \
548     (TOKEN_INIT((token),YAML_TAG_DIRECTIVE_TOKEN,(start_mark),(end_mark)),      \
549      (token).data.tag_directive.handle = (token_handle),                        \
550      (token).data.tag_directive.prefix = (token_prefix))
551
552 /*
553  * Event initializers.
554  */
555
556 #define EVENT_INIT(event,event_type,event_start_mark,event_end_mark)            \
557     (memset(&(event), 0, sizeof(yaml_event_t)),                                 \
558      (event).type = (event_type),                                               \
559      (event).start_mark = (event_start_mark),                                   \
560      (event).end_mark = (event_end_mark))
561
562 #define STREAM_START_EVENT_INIT(event,event_encoding,start_mark,end_mark)       \
563     (EVENT_INIT((event),YAML_STREAM_START_EVENT,(start_mark),(end_mark)),       \
564      (event).data.stream_start.encoding = (event_encoding))
565
566 #define STREAM_END_EVENT_INIT(event,start_mark,end_mark)                        \
567     (EVENT_INIT((event),YAML_STREAM_END_EVENT,(start_mark),(end_mark)))
568
569 #define DOCUMENT_START_EVENT_INIT(event,event_version_directive,                \
570         event_tag_directives_start,event_tag_directives_end,event_implicit,start_mark,end_mark) \
571     (EVENT_INIT((event),YAML_DOCUMENT_START_EVENT,(start_mark),(end_mark)),     \
572      (event).data.document_start.version_directive = (event_version_directive), \
573      (event).data.document_start.tag_directives.start = (event_tag_directives_start),   \
574      (event).data.document_start.tag_directives.end = (event_tag_directives_end),   \
575      (event).data.document_start.implicit = (event_implicit))
576
577 #define DOCUMENT_END_EVENT_INIT(event,event_implicit,start_mark,end_mark)       \
578     (EVENT_INIT((event),YAML_DOCUMENT_END_EVENT,(start_mark),(end_mark)),       \
579      (event).data.document_end.implicit = (event_implicit))
580
581 #define ALIAS_EVENT_INIT(event,event_anchor,start_mark,end_mark)                \
582     (EVENT_INIT((event),YAML_ALIAS_EVENT,(start_mark),(end_mark)),              \
583      (event).data.alias.anchor = (event_anchor))
584
585 #define SCALAR_EVENT_INIT(event,event_anchor,event_tag,event_value,event_length,    \
586         event_plain_implicit, event_quoted_implicit,event_style,start_mark,end_mark)    \
587     (EVENT_INIT((event),YAML_SCALAR_EVENT,(start_mark),(end_mark)),             \
588      (event).data.scalar.anchor = (event_anchor),                               \
589      (event).data.scalar.tag = (event_tag),                                     \
590      (event).data.scalar.value = (event_value),                                 \
591      (event).data.scalar.length = (event_length),                               \
592      (event).data.scalar.plain_implicit = (event_plain_implicit),               \
593      (event).data.scalar.quoted_implicit = (event_quoted_implicit),             \
594      (event).data.scalar.style = (event_style))
595
596 #define SEQUENCE_START_EVENT_INIT(event,event_anchor,event_tag,                 \
597         event_implicit,event_style,start_mark,end_mark)                         \
598     (EVENT_INIT((event),YAML_SEQUENCE_START_EVENT,(start_mark),(end_mark)),     \
599      (event).data.sequence_start.anchor = (event_anchor),                       \
600      (event).data.sequence_start.tag = (event_tag),                             \
601      (event).data.sequence_start.implicit = (event_implicit),                   \
602      (event).data.sequence_start.style = (event_style))
603
604 #define SEQUENCE_END_EVENT_INIT(event,start_mark,end_mark)                      \
605     (EVENT_INIT((event),YAML_SEQUENCE_END_EVENT,(start_mark),(end_mark)))
606
607 #define MAPPING_START_EVENT_INIT(event,event_anchor,event_tag,                  \
608         event_implicit,event_style,start_mark,end_mark)                         \
609     (EVENT_INIT((event),YAML_MAPPING_START_EVENT,(start_mark),(end_mark)),      \
610      (event).data.mapping_start.anchor = (event_anchor),                        \
611      (event).data.mapping_start.tag = (event_tag),                              \
612      (event).data.mapping_start.implicit = (event_implicit),                    \
613      (event).data.mapping_start.style = (event_style))
614
615 #define MAPPING_END_EVENT_INIT(event,start_mark,end_mark)                       \
616     (EVENT_INIT((event),YAML_MAPPING_END_EVENT,(start_mark),(end_mark)))
617
618 /*
619  * Document initializer.
620  */
621
622 #define DOCUMENT_INIT(document,document_nodes_start,document_nodes_end,         \
623         document_version_directive,document_tag_directives_start,               \
624         document_tag_directives_end,document_start_implicit,                    \
625         document_end_implicit,document_start_mark,document_end_mark)            \
626     (memset(&(document), 0, sizeof(yaml_document_t)),                           \
627      (document).nodes.start = (document_nodes_start),                           \
628      (document).nodes.end = (document_nodes_end),                               \
629      (document).nodes.top = (document_nodes_start),                             \
630      (document).version_directive = (document_version_directive),               \
631      (document).tag_directives.start = (document_tag_directives_start),         \
632      (document).tag_directives.end = (document_tag_directives_end),             \
633      (document).start_implicit = (document_start_implicit),                     \
634      (document).end_implicit = (document_end_implicit),                         \
635      (document).start_mark = (document_start_mark),                             \
636      (document).end_mark = (document_end_mark))
637
638 /*
639  * Node initializers.
640  */
641
642 #define NODE_INIT(node,node_type,node_tag,node_start_mark,node_end_mark)        \
643     (memset(&(node), 0, sizeof(yaml_node_t)),                                   \
644      (node).type = (node_type),                                                 \
645      (node).tag = (node_tag),                                                   \
646      (node).start_mark = (node_start_mark),                                     \
647      (node).end_mark = (node_end_mark))
648
649 #define SCALAR_NODE_INIT(node,node_tag,node_value,node_length,                  \
650         node_style,start_mark,end_mark)                                         \
651     (NODE_INIT((node),YAML_SCALAR_NODE,(node_tag),(start_mark),(end_mark)),     \
652      (node).data.scalar.value = (node_value),                                   \
653      (node).data.scalar.length = (node_length),                                 \
654      (node).data.scalar.style = (node_style))
655
656 #define SEQUENCE_NODE_INIT(node,node_tag,node_items_start,node_items_end,       \
657         node_style,start_mark,end_mark)                                         \
658     (NODE_INIT((node),YAML_SEQUENCE_NODE,(node_tag),(start_mark),(end_mark)),   \
659      (node).data.sequence.items.start = (node_items_start),                     \
660      (node).data.sequence.items.end = (node_items_end),                         \
661      (node).data.sequence.items.top = (node_items_start),                       \
662      (node).data.sequence.style = (node_style))
663
664 #define MAPPING_NODE_INIT(node,node_tag,node_pairs_start,node_pairs_end,        \
665         node_style,start_mark,end_mark)                                         \
666     (NODE_INIT((node),YAML_MAPPING_NODE,(node_tag),(start_mark),(end_mark)),    \
667      (node).data.mapping.pairs.start = (node_pairs_start),                      \
668      (node).data.mapping.pairs.end = (node_pairs_end),                          \
669      (node).data.mapping.pairs.top = (node_pairs_start),                        \
670      (node).data.mapping.style = (node_style))
671
672 /* Strict C compiler warning helpers */
673
674 #if defined(__clang__) || defined(__GNUC__)
675 #  define HASATTRIBUTE_UNUSED
676 #endif
677 #ifdef HASATTRIBUTE_UNUSED
678 #  define __attribute__unused__             __attribute__((__unused__))
679 #else
680 #  define __attribute__unused__
681 #endif
682
683 /* Shim arguments are arguments that must be included in your function,
684  * but serve no purpose inside.  Silence compiler warnings. */
685 #define SHIM(a) /*@unused@*/ a __attribute__unused__
686
687 /* UNUSED_PARAM() marks a shim argument in the body to silence compiler warnings */
688 #ifdef __clang__
689 #  define UNUSED_PARAM(a) (void)(a);
690 #else
691 #  define UNUSED_PARAM(a) /*@-noeffect*/if (0) (void)(a)/*@=noeffect*/;
692 #endif
693
694 #define YAML_MALLOC_STATIC(type) (type*)yaml_malloc(sizeof(type))
695 #define YAML_MALLOC(size)        (yaml_char_t *)yaml_malloc(size)
This page took 0.193696 seconds and 5 git commands to generate.