Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_compile_internal.h
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Adaptive Framework Compiler Internal
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
9 #ifndef __AFW_COMPILE_INTERNAL_H__
10 #define __AFW_COMPILE_INTERNAL_H__
11 
12 #include "afw.h"
13 
29 typedef enum {
30 
31  /* Invalid token. */
32  afw_compile_token_type_invalid,
33 
34  /*
35  * End of input. Should only be returned by get_token() after parsing
36  * is complete.
37  */
38  afw_compile_token_type_end,
39 
40  /* This token is set on call to afw_compile_get_raw_line_impl() */
41  afw_compile_token_type_raw_line,
42 
43  /*
44  * This can only be returned if afw_compile_get_token_before_eol() is
45  * called. It indicates that no token was found before the end of line.
46  */
47  afw_compile_token_type_eol,
48 
49  /* Token types with additional information. See afw_compile_token_t. */
50  afw_compile_token_type_boolean,
51  afw_compile_token_type_identifier,
52  afw_compile_token_type_integer,
53  afw_compile_token_type_number,
54  afw_compile_token_type_binary_string,
55  afw_compile_token_type_utf8_string,
56  afw_compile_token_type_template_string,
57  afw_compile_token_type_null,
58  afw_compile_token_type_undefined,
59 
60  /* Miscellaneous symbols. */
61  afw_compile_token_type_ampersand, /* & */
62  afw_compile_token_type_back_slash, /* \ */
63  afw_compile_token_type_caret, /* ^ */
64  afw_compile_token_type_colon, /* : */
65  afw_compile_token_type_comma, /* , */
66  afw_compile_token_type_dollar_sign, /* $ */
67  afw_compile_token_type_ellipsis, /* ... */
68  afw_compile_token_type_fat_arrow, /* => */
69  afw_compile_token_type_grave, /* ` */
70  afw_compile_token_type_nullish_coalescing, /* ?? */
71  afw_compile_token_type_optional_chaining, /* ?. */
72  afw_compile_token_type_optional_chaining_thin_arrow, /* ?-> */
73  afw_compile_token_type_percent, /* % */
74  afw_compile_token_type_period, /* . */
75  afw_compile_token_type_question_mark, /* ? */
76  afw_compile_token_type_semicolon, /* ; */
77  afw_compile_token_type_slash, /* / */
78  afw_compile_token_type_thin_arrow, /* -> */
79  afw_compile_token_type_tilde, /* ~ */
80  afw_compile_token_type_substitute_start, /* ${ */
81  afw_compile_token_type_vertical_bar, /* | */
82 
83  /* Unary operators */
84  afw_compile_token_type_unary_plus, /* + */
85  afw_compile_token_type_unary_minus, /* - */
86  afw_compile_token_type_unary_not, /* ! */
87 
88  /* Open/close symbols. */
89  afw_compile_token_type_open_brace, /* { */
90  afw_compile_token_type_close_brace, /* } */
91  afw_compile_token_type_open_parenthesis, /* ( */
92  afw_compile_token_type_close_parenthesis, /* ) */
93  afw_compile_token_type_open_bracket, /* [ */
94  afw_compile_token_type_close_bracket, /* ] */
95  afw_compile_token_type_open_angle_bracket, /* < */
96  afw_compile_token_type_close_angle_bracket, /* > */
97 
98  /* Arithmetic operators. */
99  afw_compile_token_type_add, /* + */
100  afw_compile_token_type_subtract, /* - */
101  afw_compile_token_type_multiply, /* * */
102  afw_compile_token_type_divide, /* / */
103  afw_compile_token_type_modulus, /* % */
104  afw_compile_token_type_exponentiation, /* ** */
105  afw_compile_token_type_increment, /* ++ */
106  afw_compile_token_type_decrement, /* -- */
107 
108  /* Logical operators. */
109  afw_compile_token_type_and, /* && */
110  afw_compile_token_type_or, /* || */
111 
112  /* Assignment operators. */
113  afw_compile_token_type_equal, /* = */
114  afw_compile_token_type_plus_equal, /* += */
115  afw_compile_token_type_minus_equal, /* -= */
116  afw_compile_token_type_multiply_equal, /* *= */
117  afw_compile_token_type_divide_equal, /* /= */
118  afw_compile_token_type_modulus_equal, /* %= */
119  afw_compile_token_type_exponentiation_equal, /* **= */
120  afw_compile_token_type_and_equal, /* &&= */
121  afw_compile_token_type_or_equal, /* ||= */
122  afw_compile_token_type_nullish_equal, /* ??= */
123 
124  /* Comparison operators. */
125  afw_compile_token_type_equal_to, /* == */
126  afw_compile_token_type_equal_value_and_type, /* === */
127  afw_compile_token_type_not_equal_to, /* != */
128  afw_compile_token_type_not_equal_value_and_type, /* !== */
129  afw_compile_token_type_less_than, /* < */
130  afw_compile_token_type_less_than_or_equal_to, /* <= */
131  afw_compile_token_type_greater_than, /* > */
132  afw_compile_token_type_greater_than_or_equal_to /* >= */
133 
134 } afw_compile_internal_token_type_t;
135 
136 
152 
153  /*
154  * This is the pool that all calls to afw_compile_* with a shared
155  * parameter pointing to this must use. If the shared parameter
156  * for one of these calls is NULL, a new one will be created.
157  *
158  * The purpose of this is to allow multiple of compiles that have a
159  * p with the same lifetime to share strings, literals, etc.
160  *
161  * This struct will be destroyed when the p of the original call
162  * to a afw_compile_* call with a shared parameter of NULL is
163  * destroyed.
164  */
165  const afw_pool_t *p;
166 
167  /*
168  * Temporary pool that will be released when
169  * afw_compile_shared_release_temp() is called.
170  */
171  const afw_pool_t *temp_p;
172 
173  /*
174  * This is a hash table of string literals that can be reused. The
175  * key is the string and the value is the string. Use
176  * afw_compile_get_string_literal() to access;
177  */
178  apr_hash_t *string_literals;
179 
180 };
181 
182 
183 
185 
186  afw_compile_internal_token_type_t type;
187 
188  afw_size_t token_source_offset;
189 
190  afw_size_t token_source_len;
191 
192  /* Additional information for some tokens. */
193  union {
194 
195  /*
196  * If type is identifier this is the name and qualifier. Member
197  * identifier includes the identifier including optional qualifier
198  * followed by '::'. If qualifier is not specified,
199  * identifier_qualifier.len will be 0.
200  *
201  */
202  struct {
203  const afw_utf8_t *identifier;
204  const afw_utf8_t *identifier_name;
205  const afw_utf8_t *identifier_qualifier;
206  };
207 
208  /* If type is boolean, this is its boolean value. */
209  afw_boolean_t boolean;
210 
211  /* If type is integer, this is its integer value. */
212  afw_integer_t integer;
213 
214  /* If type is null, this is NULL. */
215  void *null;
216 
217  /* If type is undefined, use identifier to hold 'undefined'. */
218 
219  /* If type is number, this is the double value. */
220  afw_double_t number;
221 
222  /*
223  * If type is quoted string, this is the decoded string and quote
224  * character (single (') or double (") quote)*/
225  struct {
226  const afw_utf8_t *string;
227  afw_utf8_octet_t string_quote_character;
228  };
229 
230  /* Used for afw_compile_token_type_raw_line. */
231  afw_utf8_t raw_line;
232  };
233 
234 };
235 
236 
237 #define AFW_COMPILE_MAX_TOKENS 5
238 
239 
240 
248 
251 
254 
257 
260 };
261 
262 
263 
265 
266  /* Pool used for everything returned. */
267  const afw_pool_t *p;
268 
269  /* Some things still use apr pools. */
270  apr_pool_t *apr_p;
271 
272  /* The execution context (xctx) of caller to parser. */
273  afw_xctx_t *xctx;
274 
275  /* Shared resources. */
276  const afw_compile_shared_t *shared;
277 
278  /* This is the value returned by the compiler. */
279  afw_value_compiled_value_t *compiled_value;
280 
282 
283  const afw_utf8_t *passed_source;
284 
285  afw_size_t estimated_size;
286 
287  afw_utf8_octet_get_cb_t callback;
288 
289  void *callback_data;
290 
291  /*
292  * Full source as it is retrieved.
293  *
294  * IMPORTANT: This must continue to point to the same exact memory since
295  * its value is copied into many value structs that exist
296  * after parsing is finished.
297  *
298  * Only afw_compile_get_code_point_impl() should modify this.
299  */
300  afw_utf8_t *full_source;
301 
302  /* Current cursor within source of next octet. */
303  afw_size_t cursor;
304 
305  /* If all_eof occurred, this is the total length of the source. */
306  afw_size_t cursor_eof;
307 
308  /*
309  * Only used if callback specified and will include passed_source followed
310  * by octets retrieved via callback.
311  *
312  * Only afw_compile_get_code_point_impl() should directly access this.
313  */
314  apr_array_header_t *source_buffer;
315 
316  /* Used for parsing strings. */
317  apr_array_header_t *s;
318 
319  /*
320  * Temporary array used for building list of values.
321  *
322  * Each function that uses the array should reset nelts to entry
323  * value on return.
324  */
325  apr_array_header_t *values;
326 
327  afw_size_t hybrid_start_offset;
328 
329  afw_error_t *error;
330 
331  const afw_object_t *embedding_object;
332 
333  const afw_utf8_t *property_name;
334 
335  afw_compile_token_t token_storage;
336 
337  afw_compile_token_t *token;
338 
339  afw_size_t cursors[AFW_COMPILE_MAX_TOKENS];
340 
341  afw_size_t block_count;
342 
343  int cursor_count;
344 
345  int current_cursor_index;
346 
347  afw_compile_type_t compile_type;
348 
349  afw_compile_residual_check_t residual_check;
350 
351  afw_boolean_t strict;
352 
353  afw_boolean_t cede_p;
354 
355  /*
356  * This is used for context of operators:
357  * +, -, %, /, **, ||, &&, <, and >
358  */
359  afw_boolean_t next_can_be_nonunary_operator;
360 
361  /* When this is true, grave symbol starts a grave string. */
362  afw_boolean_t next_can_be_template_string;
363 
364  /* Next identifier is not a special literal (true, NaN, ...) . */
365  afw_boolean_t next_identifier_is_not_special_literal;
366 
367  afw_boolean_t all_eof;
368 
369  afw_boolean_t last_octet_eof;
370 
371  afw_boolean_t callback_eof;
372 
373  afw_boolean_t scanning_for_residual;
374 
375  afw_boolean_t has_called_callback;
376 
377  /*
378  * Set while parsing object spread to change behavior of
379  * AFW_MEMORY_OBJECT_CREATE_ENTITY_OR_EMBEDDED_P()
380  */
381  afw_boolean_t doing_object_spread;
382 
383  /*
384  * Set by afw_compile_get_token_before_eol() and reset in
385  * afw_compile_get_token_impl().
386  */
387  afw_boolean_t get_token_before_eol;
388 
389  /*
390  * Set by afw_compile_skip_ws() when end of line found and
391  * parser->get_token_before_eol is on.
392  */
393  afw_boolean_t get_token_found_eol;
394 
395 };
396 
397 
398 
404 #define AFW_COMPILE_INTERNAL_ASSIGNMENT_TYPE_MAP(XX) \
405  \
406  XX(assign_only, \
407  "This is an assignment to an existing variable.") \
408  \
409  XX(const, \
410  "This is an assignment to a new const variable.") \
411  \
412  XX(declare_only, \
413  "This is a declare of a new variable without assignment.") \
414  \
415  XX(define_loc_if_needed, \
416  "This is an assignment to a new or existing local variable. ") \
417  \
418  XX(loc, \
419  "This is an assignment to a new local variable. ") \
420  \
421  XX(reference_only, \
422  "No assignment, just reference.") \
423  \
424  XX(use_assignment_targets, \
425  "Use the assignment type from assignment target.") \
426  \
427 
429 typedef enum {
430 #define XX(id, description) \
431  afw_compile_assignment_type_ ## id,
433 #undef XX
434  afw_compile_assignment_type_max_type
436 
437 
443 #define AFW_COMPILE_INTERNAL_ASSIGNMENT_TARGET_TYPE_MAP(XX) \
444  \
445  XX(list_destructure, \
446  "This is a list destructure.") \
447  \
448  XX(object_destructure, \
449  "This is a object destructure.") \
450  \
451  XX(variable_reference, \
452  "This is a variable reference.") \
453 
455 typedef enum {
456 #define XX(id, description) \
457  afw_compile_assignment_target_type_ ## id,
459 #undef XX
460  afw_compile_assignment_target_type_max_type
462 
463 
464 
465 /* See AssignmentTarget */
469  union {
470  const afw_compile_list_destructure_t *list_destructure;
471  const afw_compile_object_destructure_t *object_destructure;
472  union {
473  const afw_value_type_t *variable_type;
474  const afw_value_variable_reference_t *variable_reference;
475  };
476  };
477 };
478 
479 
480 /* See AssignmentListDestructureTarget */
482 
483  /* AssignmentElement or NULL */
484  const afw_compile_assignment_element_t *assignment_element;
485 
486  /* AssignmentTarget for ... Type? VariableName or NULL */
487  const afw_value_type_t *rest_type;
488  const afw_value_t *rest;
489 };
490 
491 
492 /* See AssignmentElement */
495  const afw_value_type_t *type;
496  const afw_value_t *assignment_target;
497  const afw_value_t *default_value;
498 };
499 
500 
501 /* See AssignmentProperty */
504  const afw_value_type_t *type;
505  afw_boolean_t is_rename;
506  union {
507  /* If is_rename is true. */
508  struct {
509  const afw_utf8_t *property_name;
510  const afw_compile_assignment_element_t *assignment_element;
511  };
512  /* If is_rename is false. */
513  struct {
514  const afw_value_variable_reference_t *variable_reference;
515  const afw_value_t *default_value;
516  };
517  };
518 };
519 
520 
521 
522 /* See AssignmentObjectDestructureTarget */
524 
525  /* AssignmentProperty or NULL */
526  const afw_compile_assignment_property_t *assignment_property;
527 
528  /* AssignmentTarget for ...VariableName or NULL */
529  const afw_value_type_t *rest_type;
530  const afw_value_t *rest;
531 };
532 
533 
534 
535 #define afw_value_contextual_resolve_value_source( \
536  value_source, contextual) \
537 do { \
538  if ((contextual)->compiled_value && \
539  (contextual)->compiled_value->full_source) \
540  { \
541  (value_source)->s = (((contextual)->compiled_value->full_source)->s) + \
542  (contextual)->value_offset; \
543  (value_source)->len = (contextual)->value_size; \
544  } \
545  else { \
546  memset((value_source), 0, sizeof(afw_utf8_t)); \
547  } \
548 } while (0)
549 
550 
551 
552 #define afw_compile_token_is(token_type) \
553  (parser->token->type == afw_compile_token_type_##token_type)
554 
555 
556 
557 #define afw_compile_token_is_unqualified_identifier() \
558  (parser->token->type == afw_compile_token_type_identifier && \
559  !parser->token->identifier_qualifier)
560 
561 
562 
563 #define afw_compile_token_is_name(string) \
564  (afw_compile_token_is_unqualified_identifier() && \
565  afw_utf8_equal(parser->token->identifier_name, (string)))
566 
567 
568 
569 #define afw_compile_token_is_name_z(string_z) \
570  (afw_compile_token_is_unqualified_identifier() && \
571  afw_utf8_equal_utf8_z(parser->token->identifier_name, (string_z)))
572 
573 
574 afw_compile_internal_token_type_t
575 afw_compile_peek_next_token_impl(afw_compile_parser_t *parser);
576 
577 
578 
579 #define afw_compile_is_at_eof() \
580  (parser->last_octet_eof)
581 
582 
583 
584 #define afw_compile_next_is_at_eof() \
585  (parser->last_octet_eof || \
586  (parser->all_eof && (parser->cursor == parser->cursor_eof)) )
587 
588 
589 
590 #define afw_compile_peek_next_token() \
591  afw_compile_peek_next_token_impl(parser)
592 
593 
594 
595 #define afw_compile_peek_next_token_is(token_type) \
596  (afw_compile_peek_next_token_impl(parser) == \
597  afw_compile_token_type_##token_type)
598 
599 
600 
601 #define afw_compile_set_contextual() \
602  parser->xctx->error->contextual = &parser->contextual; \
603  parser->xctx->error->parser_cursor = parser->cursor
604 
607 
608 
609 /* Macro used to set parse error in xctx and throw it. */
610 #define AFW_COMPILE_THROW_ERROR_Z(message_z) \
611 do { \
612  afw_compile_parse_set_error_z(parser, \
613  AFW__FILE_LINE__, message_z); \
614  longjmp(((parser->xctx)->current_try->throw_jmp_buf), \
615  (afw_error_code_syntax)); \
616 } while (0)
617 
618 
619 /* Macro used to set parse error in xctx and throw it. */
620 #define AFW_COMPILE_THROW_ERROR_FZ(format_z, ...) \
621 do { \
622  afw_compile_parse_set_error_fz(parser, \
623  AFW__FILE_LINE__, format_z, __VA_ARGS__); \
624  longjmp(((parser->xctx)->current_try->throw_jmp_buf), \
625  (afw_error_code_syntax)); \
626 } while (0)
627 
628 
629 
630 /* Check of unexpected end. */
631 #define AFW_COMPILE_EOF_IS_ERROR() \
632 if (afw_compile_is_at_eof()) \
633  AFW_COMPILE_THROW_ERROR_Z("Unexpected end")
634 
635 
636 
638 afw_compile_get_code_point_impl(afw_compile_parser_t *parser);
639 
640 #define afw_compile_get_code_point() \
641  afw_compile_get_code_point_impl(parser)
642 
644 afw_compile_get_unescaped_code_point_impl(afw_compile_parser_t *parser);
645 
646 #define afw_compile_get_unescaped_code_point() \
647  afw_compile_get_unescaped_code_point_impl(parser)
648 
649 
651 afw_compile_is_reserved_word(
652  afw_compile_parser_t *parser,
653  const afw_utf8_t *s);
654 
655 
657 afw_compile_next_raw_starts_with_impl(
658  afw_compile_parser_t *parser,
659  const afw_utf8_t *s);
660 
661 
662 
663 #define afw_compile_next_raw_starts_with(s) \
664  afw_compile_next_raw_starts_with_impl(parser, s)
665 
666 
667 
669 afw_compile_next_raw_starts_with_z_impl(
670  afw_compile_parser_t *parser,
671  const afw_utf8_z_t *s_z);
672 
673 
674 
675 #define afw_compile_next_raw_starts_with_z(s_z) \
676  afw_compile_next_raw_starts_with_z_impl(parser, s_z)
677 
678 
679 
681 afw_compile_parse_list_of_statements(
682  afw_compile_parser_t *parser,
683  afw_boolean_t end_is_close_brace,
684  afw_boolean_t can_be_single_return_expression);
685 
686 
687 
689 afw_compile_get_raw_line_impl(
690  afw_compile_parser_t *parser,
691  afw_utf8_t *line);
692 
693 
694 
695 #define afw_compile_get_raw_line(line) \
696  afw_compile_get_raw_line_impl(parser, line)
697 
698 
699 
701 afw_compile_current_raw_token(
702  afw_compile_parser_t *parser);
703 
704 
705 
707 afw_compile_get_string_literal(
708  afw_compile_parser_t *parser,
709  const afw_utf8_octet_t *s,
710  afw_size_t len);
711 
712 
713 
715 afw_compile_get_token_impl(
716  afw_compile_parser_t *parser);
717 
718 
719 
720 /* Get the next token. */
721 #define afw_compile_get_token() \
722  afw_compile_get_token_impl(parser)
723 
724 
725 
726 /* Get the next token before end of line. */
727 #define afw_compile_get_token_before_eol() \
728  parser->get_token_before_eol = true; \
729  afw_compile_get_token_impl(parser)
730 
731 
732 
733 #define afw_compile_save_offset(save) \
734  save = parser->token->token_source_offset
735 
736 
737 
738 #define afw_compile_get_token_and_save_offset(save) \
739  afw_compile_get_token_impl(parser); \
740  save = parser->token->token_source_offset
741 
742 
743 
744 void
745 afw_compile_reuse_token_impl(afw_compile_parser_t *parser);
746 
747 
748 
749 /*
750  * Set in parse and reset in afw_compile_get_token() to indicate that next
751  * token can be an operator. This is used to determine if '+' and '-' are
752  * unary and if '<' and '>' are comparisons.
753  */
754 #define afw_compile_next_can_be_operator() \
755  parser->next_can_be_nonunary_operator = true
756 
757 
758 
759 /*
760  * Set in parse and reset in afw_compile_get_token() to indicate that next
761  * token can be a grave string. This is used to determine if '`' is just
762  * a grave token or a grave string.
763  */
764 #define afw_compile_next_can_be_template_string() \
765  parser->next_can_be_template_string = true
766 
767 
768 /*
769  * Set in parse and reset in afw_compile_get_token() to indicate that next
770  * identifier is not be interpreted as a literal. Therefore, true, NaN and other
771  * special literals will be returned as an identifier instead of their
772  * corresponding value.
773  */
774 #define afw_compile_next_identifier_is_not_special_literal() \
775  parser->next_identifier_is_not_special_literal = true
776 
777 
778 #define afw_compile_reuse_token() \
779  afw_compile_reuse_token_impl(parser)
780 
781 
782 
783 #define afw_compile_save_cursor(save) \
784  save = parser->cursor
785 
786 
787 
788 #define afw_compile_restore_cursor(save) \
789 do { \
790  parser->last_octet_eof = false; \
791  parser->cursor = save; \
792 } while (0)
793 
794 
795 
796 #define afw_compile_cursor_equal(save) \
797  (parser->cursor == save)
798 
799 
800 
801 #define afw_compile_source_buffer_at(save) \
802  (parser->full_source->s + save)
803 
804 
805 
806 #define afw_compile_source_buffer_length_from(save) \
807  (parser->cursor - save)
808 
809 
810 
812 afw_compile_create_contextual(
813  afw_compile_parser_t *parser,
814  afw_size_t start_offset,
815  afw_size_t size);
816 
817 
818 #define afw_compile_create_contextual_to_cursor(start_offset) \
819  afw_compile_create_contextual(parser, start_offset, \
820  parser->cursor - start_offset)
821 
822 
823 
825 afw_compile_create_source_location_impl(
826  afw_compile_parser_t *parser,
827  afw_size_t start_offset);
828 
829 
830 
831 #define afw_compile_create_source_location(start_offset) \
832  afw_compile_create_source_location_impl(parser, \
833  start_offset)
834 
835 
836 AFW_DEFINE_STATIC_INLINE(afw_code_point_t)
837 afw_compile_peek_code_point(afw_compile_parser_t *parser)
838 {
839  afw_size_t cursor;
840  afw_code_point_t cp;
841 
842  afw_compile_save_cursor(cursor);
843  cp = afw_compile_get_code_point();
844  afw_compile_restore_cursor(cursor);
845  return cp;
846 }
847 
848 
849 /* Push cp on parser->s */
851 afw_compile_internal_s_push_code_point(
852  afw_compile_parser_t *parser,
853  afw_code_point_t cp);
854 
855 
856 
857 /* Parse error. */
859 afw_compile_parse_set_error_z(
860  afw_compile_parser_t *parser,
861  const afw_utf8_z_t *source_z,
862  const afw_utf8_z_t *message_z);
863 
864 
865 
866 /* Parse error with format. */
868 afw_compile_parse_set_error_fz(
869  afw_compile_parser_t *parser,
870  const afw_utf8_z_t *source_z,
871  const afw_utf8_z_t *format_z, ...);
872 
873 
874 
876 afw_compile_parse_get_symbol_entry(
877  afw_compile_parser_t *parser,
878  const afw_utf8_t *name);
879 
880 
881 
883 afw_compile_parse_get_local_symbol_entry(
884  afw_compile_parser_t *parser,
885  const afw_utf8_t *name);
886 
887 
888 
890 afw_compile_parse_add_symbol_entry(
891  afw_compile_parser_t *parser,
892  const afw_utf8_t *name);
893 
894 
895 
897 afw_compile_parse_link_new_value_block(
898  afw_compile_parser_t *parser,
899  afw_size_t start_offset);
900 
901 
902 
903 #define afw_compile_parse_pop_value_block(parser) \
904  (parser)->compiled_value->current_block = \
905  (parser)->compiled_value->current_block->parent_block
906 
907 
908 
909 /*
910  * Create the appropriate value for identifier passed. Either
911  * variable_reference, qualified_variable_reference, or
912  * function_definition.
913  */
915 afw_compile_parse_reference_create(
916  afw_compile_parser_t *parser,
917  const afw_compile_value_contextual_t *contextual,
918  const afw_utf8_t *identifier);
919 
920 
921 
923 afw_compile_parse_check_symbol(
924  afw_compile_parser_t *parser,
925  const afw_utf8_t *name,
926  const afw_value_t *value,
928  afw_size_t symbol_cursor);
929 
930 
931 
933 afw_compile_parse_Assignment(
934  afw_compile_parser_t *parser,
935  afw_boolean_t *was_expression);
936 
937 
938 
940 afw_compile_parse_AssignmentBindingTarget(
941  afw_compile_parser_t *parser,
943  const afw_value_type_t **type,
944  const afw_value_t **value);
945 
946 
947 
949 afw_compile_parse_AssignmentListDestructureTarget(
950  afw_compile_parser_t *parser,
952 
953 
954 
956 afw_compile_parse_AssignmentElement(
957  afw_compile_parser_t *parser,
959 
960 
961 
963 afw_compile_parse_AssignmentExpression(
964  afw_compile_parser_t *parser);
965 
966 
967 
969 afw_compile_parse_AssignmentObjectDestructureTarget(
970  afw_compile_parser_t *parser,
972 
973 
974 
976 afw_compile_parse_AssignmentProperty(
977  afw_compile_parser_t *parser,
979 
980 
981 
982 /* Parameter was_expression is used to support single return expression */
984 afw_compile_parse_AssignmentStatement(
985  afw_compile_parser_t *parser,
986  afw_boolean_t *was_expression);
987 
988 
989 
991 afw_compile_parse_AssignmentTarget(
992  afw_compile_parser_t *parser,
994 
995 
996 
998 afw_compile_parse_Comparison(afw_compile_parser_t *parser);
999 
1000 
1001 
1003 afw_compile_parse_EntryFunctionLambdaOrVariableReference(
1004  afw_compile_parser_t *parser);
1005 
1006 
1007 
1009 afw_compile_parse_Equality(afw_compile_parser_t *parser);
1010 
1011 
1012 
1014 afw_compile_parse_Exponentiation(afw_compile_parser_t *parser);
1015 
1016 
1017 
1019 afw_compile_parse_Evaluation(afw_compile_parser_t *parser);
1020 
1021 
1022 
1024 afw_compile_parse_Expression(afw_compile_parser_t *parser);
1025 
1026 
1027 
1029 afw_compile_parse_ExpressionTuple(afw_compile_parser_t *parser);
1030 
1031 
1032 
1034 afw_compile_parse_ExpressionTupleAnnotation(afw_compile_parser_t *parser);
1035 
1036 
1037 
1039 afw_compile_parse_ExpressionTupleOperation(afw_compile_parser_t *parser);
1040 
1041 
1042 
1044 afw_compile_parse_ExpressionTupleParameter(afw_compile_parser_t *parser);
1045 
1046 
1047 
1049 afw_compile_parse_Factor(afw_compile_parser_t *parser);
1050 
1051 
1052 
1054 afw_compile_parse_FunctionSignature(
1055  afw_compile_parser_t *parser,
1056  const afw_value_block_t **block);
1057 
1058 
1059 
1061 afw_compile_parse_FunctionSignatureAndBody(afw_compile_parser_t *parser);
1062 
1063 
1064 
1066 afw_compile_parse_Json(afw_compile_parser_t *parser);
1067 
1068 
1069 
1071 afw_compile_parse_Literal(
1072  afw_compile_parser_t *parser,
1073  afw_boolean_t *is_Literal,
1074  afw_boolean_t must_be_literal,
1075  afw_boolean_t scalar_only);
1076 
1077 
1078 
1080 afw_compile_parse_Lambda(afw_compile_parser_t *parser);
1081 
1082 
1083 
1085 afw_compile_parse_List(
1086  afw_compile_parser_t *parser,
1087  afw_boolean_t allow_expression,
1088  afw_boolean_t allow_enhanced_literals);
1089 
1090 
1091 
1093 afw_compile_parse_LogicalExpression(afw_compile_parser_t *parser);
1094 
1095 
1096 
1098 afw_compile_parse_LogicalAnd(afw_compile_parser_t *parser);
1099 
1100 
1101 
1103 afw_compile_parse_NullishCoalescing(afw_compile_parser_t *parser);
1104 
1105 
1106 
1108 afw_compile_parse_Object(
1109  afw_compile_parser_t *parser,
1110  afw_boolean_t allow_expression,
1111  afw_boolean_t allow_enhanced_literals);
1112 
1113 
1114 
1116 afw_compile_parse_OptionalDefineAssignment(
1117  afw_compile_parser_t *parser);
1118 
1119 
1121 afw_compile_parse_OptionalDefineTarget(
1122  afw_compile_parser_t *parser);
1123 
1126  afw_compile_parser_t *parser,
1127  afw_boolean_t is_return);
1128 
1130 afw_compile_parse_Parameters(
1131  afw_compile_parser_t *parser,
1132  afw_compile_args_t *args);
1133 
1134 
1135 
1137 afw_compile_parse_ParenthesizedExpression(afw_compile_parser_t *parser);
1138 
1139 
1140 
1142 afw_compile_parse_Prefixed(afw_compile_parser_t *parser);
1143 
1144 
1145 
1147 afw_compile_parse_Reference(afw_compile_parser_t *parser);
1148 
1149 
1150 
1152 afw_compile_parse_Script(
1153  afw_compile_parser_t *parser);
1154 
1155 
1156 
1157 /* If was_expression is NULL, statement can not be Expression. */
1159 afw_compile_parse_Statement(
1160  afw_compile_parser_t *parser,
1161  afw_boolean_t *was_expression);
1162 
1163 
1164 
1166 afw_compile_parse_Substitution(afw_compile_parser_t *parser);
1167 
1168 
1169 
1171 afw_compile_parse_Template(afw_compile_parser_t *parser);
1172 
1173 
1174 
1176 afw_compile_parse_TemplateString(afw_compile_parser_t *parser);
1177 
1178 
1179 
1181 afw_compile_parse_Term(afw_compile_parser_t *parser);
1182 
1183 
1184 
1186 afw_compile_parse_TestScript(
1187  afw_compile_parser_t *parser);
1188 
1189 
1190 
1192 afw_compile_parse_Type(afw_compile_parser_t *parser);
1193 
1194 
1195 
1197 afw_compile_parse_Value(afw_compile_parser_t *parser);
1198 
1199 
1200 
1202 afw_compile_parse_Hybrid(afw_compile_parser_t *parser);
1203 
1204 
1206 afw_compile_parse_variable_reference_create(
1207  afw_compile_parser_t *parser,
1208  const afw_compile_value_contextual_t *contextual,
1210  const afw_utf8_t *identifier);
1211 
1212 
1213 /* Skip white space and comments. */
1215 afw_compile_skip_ws(afw_compile_parser_t *parser);
1216 
1217 
1218 
1219 /* Make sure there is no residual data. */
1221 afw_compile_check_for_residual(afw_compile_parser_t *parser);
1222 
1223 
1224 AFW_STACK_STRUCT(afw_compile_internal_args_s, const afw_value_t *);
1225 
1226 
1227 /* Create instance of args. */
1228 #define afw_compile_args_create(parser) \
1229 afw_stack_create(afw_compile_args_t, 10, 0, true, \
1230  (parser)->p, (parser)->xctx)
1231 
1232 
1233 
1234 /* Add a value to args. */
1235 #define afw_compile_args_add_value(args, value) \
1236 afw_stack_push(args, (parser)->xctx) = value
1237 
1238 
1239 
1240 /* Get argc and argv from args and release work resources. */
1241 #define afw_compile_args_finalize(args, argc, argv) \
1242 afw_stack_copy_and_release((args), (argc), (argv), \
1243  (parser)->p, (parser)->xctx)
1244 
1245 
1246 /* Make sure there is no residual data. */
1248 afw_compile_check_for_residual(afw_compile_parser_t *parser);
1249 
1250 
1251 
1252 /* Create a parser. */
1254 afw_compile_lexical_parser_create(
1255  const afw_utf8_t *source,
1256  afw_utf8_octet_get_cb_t callback,
1257  void *callback_data,
1258  const afw_utf8_t *source_location,
1259  afw_compile_type_t compile_type,
1260  afw_compile_residual_check_t residual_check,
1261  afw_boolean_t cede_p,
1262  const afw_value_compiled_value_t *parent,
1263  const afw_compile_shared_t *shared,
1264  const afw_pool_t *p,
1265  afw_xctx_t *xctx);
1266 
1267 
1268 /* Call when finished with parser. */
1270 afw_compile_lexical_parser_finish_and_release(
1271  afw_compile_parser_t *parser,
1272  afw_xctx_t *xctx);
1273 
1274 
1275 
1276 #define AFW_COMPILE_THROW_EXPECTING_SEMICOLON \
1277  AFW_COMPILE_THROW_ERROR_Z("Expecting statement terminator ';'")
1278 
1279 
1280 
1281 #define AFW_COMPILE_ASSERT_TOKEN_IS_SEMICOLON \
1282  if (!afw_compile_token_is(semicolon)) \
1283  AFW_COMPILE_THROW_EXPECTING_SEMICOLON
1284 
1285 
1286 
1287 #define AFW_COMPILE_ASSERT_NEXT_TOKEN_IS_SEMICOLON \
1288  afw_compile_get_token(); \
1289  AFW_COMPILE_ASSERT_TOKEN_IS_SEMICOLON
1290 
1291 
1292 
1293 AFW_END_DECLARES
1294 
1297 #endif /* __AFW_COMPILE_INTERNAL_H__ */
Adaptive Framework Core API.
#define AFW_DEFINE_INTERNAL(type)
Define an internal function for /src/afw/ source*.c files.
#define AFW_BEGIN_DECLARES
#define AFW_DECLARE_INTERNAL(type)
Declare an internal function for /src/afw/ source*.h files.
#define AFW_STACK_STRUCT(struct_name, entry_type)
Define a struct for a stack with the specified entry type.
Definition: afw_common.h:718
double afw_double_t
Normal AFW number is double.
Definition: afw_common.h:202
_Bool afw_boolean_t
Definition: afw_common.h:373
afw_int32_t afw_code_point_t
Unicode code point.
Definition: afw_common.h:205
int(* afw_utf8_octet_get_cb_t)(afw_utf8_octet_t *octet, void *data, afw_xctx_t *xctx)
Get an utf-8 octet (8 bits).
Definition: afw_common.h:255
afw_utf8_octet_t afw_utf8_z_t
NFC normalized UTF-8 null terminated string.
Definition: afw_common.h:523
enum afw_compile_type_e afw_compile_type_t
Compile type enum.
char afw_utf8_octet_t
8 bits of utf-8 codepoint.
Definition: afw_common.h:236
struct afw_compile_internal_args_s afw_compile_args_t
apr_size_t afw_size_t
size_t.
Definition: afw_common.h:151
apr_int64_t afw_integer_t
typedef for big signed int.
Definition: afw_common.h:321
afw_compile_parse_OptionalType(afw_compile_parser_t *parser, afw_boolean_t is_return)
afw_compile_assignment_target_type_t
Enum for assignment target types.
afw_compile_internal_assignment_type_t
Enum for assignment types.
#define AFW_COMPILE_INTERNAL_ASSIGNMENT_TYPE_MAP(XX)
Assignment type Map.
#define AFW_COMPILE_INTERNAL_ASSIGNMENT_TARGET_TYPE_MAP(XX)
Assignment target type Map.
enum afw_compile_residual_check_e afw_compile_residual_check_t
Residual checking options.
Resources that can be shared by multiple compiles.
Contextual information provided in some values.
afw_size_t value_size
Size in full_source of value source.
const afw_utf8_t * source_location
Source location.
const afw_value_compiled_value_t * compiled_value
Compiled value this value is part of.
afw_size_t value_offset
Offset in full source of compiled value to this value.
Adaptive Framework Error.
Definition: afw_error.h:65
Interface afw_object public struct.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
struct for afw_value_block_t
struct for afw_value_block_symbol_t
Struct for compiled value value.
Interface afw_value public struct.
Type meta (data type, data type parameters, and value meta object.
Interface afw_xctx public struct.