9 #ifndef __AFW_COMPILE_INTERNAL_H__
10 #define __AFW_COMPILE_INTERNAL_H__
32 afw_compile_token_type_invalid,
38 afw_compile_token_type_end,
41 afw_compile_token_type_raw_line,
47 afw_compile_token_type_eol,
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,
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,
84 afw_compile_token_type_unary_plus,
85 afw_compile_token_type_unary_minus,
86 afw_compile_token_type_unary_not,
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,
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,
109 afw_compile_token_type_and,
110 afw_compile_token_type_or,
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,
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
134 } afw_compile_internal_token_type_t;
178 apr_hash_t *string_literals;
186 afw_compile_internal_token_type_t type;
237 #define AFW_COMPILE_MAX_TOKENS 5
314 apr_array_header_t *source_buffer;
317 apr_array_header_t *s;
325 apr_array_header_t *values;
345 int current_cursor_index;
404 #define AFW_COMPILE_INTERNAL_ASSIGNMENT_TYPE_MAP(XX) \
407 "This is an assignment to an existing variable.") \
410 "This is an assignment to a new const variable.") \
413 "This is a declare of a new variable without assignment.") \
415 XX(define_loc_if_needed, \
416 "This is an assignment to a new or existing local variable. ") \
419 "This is an assignment to a new local variable. ") \
422 "No assignment, just reference.") \
424 XX(use_assignment_targets, \
425 "Use the assignment type from assignment target.") \
430 #define XX(id, description) \
431 afw_compile_assignment_type_ ## id,
434 afw_compile_assignment_type_max_type
443 #define AFW_COMPILE_INTERNAL_ASSIGNMENT_TARGET_TYPE_MAP(XX) \
445 XX(list_destructure, \
446 "This is a list destructure.") \
448 XX(object_destructure, \
449 "This is a object destructure.") \
451 XX(variable_reference, \
452 "This is a variable reference.") \
456 #define XX(id, description) \
457 afw_compile_assignment_target_type_ ## id,
460 afw_compile_assignment_target_type_max_type
535 #define afw_value_contextual_resolve_value_source( \
536 value_source, contextual) \
538 if ((contextual)->compiled_value && \
539 (contextual)->compiled_value->full_source) \
541 (value_source)->s = (((contextual)->compiled_value->full_source)->s) + \
542 (contextual)->value_offset; \
543 (value_source)->len = (contextual)->value_size; \
546 memset((value_source), 0, sizeof(afw_utf8_t)); \
552 #define afw_compile_token_is(token_type) \
553 (parser->token->type == afw_compile_token_type_##token_type)
557 #define afw_compile_token_is_unqualified_identifier() \
558 (parser->token->type == afw_compile_token_type_identifier && \
559 !parser->token->identifier_qualifier)
563 #define afw_compile_token_is_name(string) \
564 (afw_compile_token_is_unqualified_identifier() && \
565 afw_utf8_equal(parser->token->identifier_name, (string)))
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)))
574 afw_compile_internal_token_type_t
579 #define afw_compile_is_at_eof() \
580 (parser->last_octet_eof)
584 #define afw_compile_next_is_at_eof() \
585 (parser->last_octet_eof || \
586 (parser->all_eof && (parser->cursor == parser->cursor_eof)) )
590 #define afw_compile_peek_next_token() \
591 afw_compile_peek_next_token_impl(parser)
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)
601 #define afw_compile_set_contextual() \
602 parser->xctx->error->contextual = &parser->contextual; \
603 parser->xctx->error->parser_cursor = parser->cursor
610 #define AFW_COMPILE_THROW_ERROR_Z(message_z) \
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)); \
620 #define AFW_COMPILE_THROW_ERROR_FZ(format_z, ...) \
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)); \
631 #define AFW_COMPILE_EOF_IS_ERROR() \
632 if (afw_compile_is_at_eof()) \
633 AFW_COMPILE_THROW_ERROR_Z("Unexpected end")
640 #define afw_compile_get_code_point() \
641 afw_compile_get_code_point_impl(parser)
646 #define afw_compile_get_unescaped_code_point() \
647 afw_compile_get_unescaped_code_point_impl(parser)
651 afw_compile_is_reserved_word(
657 afw_compile_next_raw_starts_with_impl(
663 #define afw_compile_next_raw_starts_with(s) \
664 afw_compile_next_raw_starts_with_impl(parser, s)
669 afw_compile_next_raw_starts_with_z_impl(
675 #define afw_compile_next_raw_starts_with_z(s_z) \
676 afw_compile_next_raw_starts_with_z_impl(parser, s_z)
681 afw_compile_parse_list_of_statements(
689 afw_compile_get_raw_line_impl(
695 #define afw_compile_get_raw_line(line) \
696 afw_compile_get_raw_line_impl(parser, line)
701 afw_compile_current_raw_token(
707 afw_compile_get_string_literal(
715 afw_compile_get_token_impl(
721 #define afw_compile_get_token() \
722 afw_compile_get_token_impl(parser)
727 #define afw_compile_get_token_before_eol() \
728 parser->get_token_before_eol = true; \
729 afw_compile_get_token_impl(parser)
733 #define afw_compile_save_offset(save) \
734 save = parser->token->token_source_offset
738 #define afw_compile_get_token_and_save_offset(save) \
739 afw_compile_get_token_impl(parser); \
740 save = parser->token->token_source_offset
754 #define afw_compile_next_can_be_operator() \
755 parser->next_can_be_nonunary_operator = true
764 #define afw_compile_next_can_be_template_string() \
765 parser->next_can_be_template_string = true
774 #define afw_compile_next_identifier_is_not_special_literal() \
775 parser->next_identifier_is_not_special_literal = true
778 #define afw_compile_reuse_token() \
779 afw_compile_reuse_token_impl(parser)
783 #define afw_compile_save_cursor(save) \
784 save = parser->cursor
788 #define afw_compile_restore_cursor(save) \
790 parser->last_octet_eof = false; \
791 parser->cursor = save; \
796 #define afw_compile_cursor_equal(save) \
797 (parser->cursor == save)
801 #define afw_compile_source_buffer_at(save) \
802 (parser->full_source->s + save)
806 #define afw_compile_source_buffer_length_from(save) \
807 (parser->cursor - save)
812 afw_compile_create_contextual(
818 #define afw_compile_create_contextual_to_cursor(start_offset) \
819 afw_compile_create_contextual(parser, start_offset, \
820 parser->cursor - start_offset)
825 afw_compile_create_source_location_impl(
831 #define afw_compile_create_source_location(start_offset) \
832 afw_compile_create_source_location_impl(parser, \
842 afw_compile_save_cursor(cursor);
843 cp = afw_compile_get_code_point();
844 afw_compile_restore_cursor(cursor);
851 afw_compile_internal_s_push_code_point(
859 afw_compile_parse_set_error_z(
868 afw_compile_parse_set_error_fz(
876 afw_compile_parse_get_symbol_entry(
883 afw_compile_parse_get_local_symbol_entry(
890 afw_compile_parse_add_symbol_entry(
897 afw_compile_parse_link_new_value_block(
903 #define afw_compile_parse_pop_value_block(parser) \
904 (parser)->compiled_value->current_block = \
905 (parser)->compiled_value->current_block->parent_block
915 afw_compile_parse_reference_create(
923 afw_compile_parse_check_symbol(
933 afw_compile_parse_Assignment(
940 afw_compile_parse_AssignmentBindingTarget(
949 afw_compile_parse_AssignmentListDestructureTarget(
956 afw_compile_parse_AssignmentElement(
963 afw_compile_parse_AssignmentExpression(
969 afw_compile_parse_AssignmentObjectDestructureTarget(
976 afw_compile_parse_AssignmentProperty(
984 afw_compile_parse_AssignmentStatement(
991 afw_compile_parse_AssignmentTarget(
1003 afw_compile_parse_EntryFunctionLambdaOrVariableReference(
1054 afw_compile_parse_FunctionSignature(
1071 afw_compile_parse_Literal(
1085 afw_compile_parse_List(
1108 afw_compile_parse_Object(
1116 afw_compile_parse_OptionalDefineAssignment(
1121 afw_compile_parse_OptionalDefineTarget(
1130 afw_compile_parse_Parameters(
1152 afw_compile_parse_Script(
1159 afw_compile_parse_Statement(
1186 afw_compile_parse_TestScript(
1206 afw_compile_parse_variable_reference_create(
1228 #define afw_compile_args_create(parser) \
1229 afw_stack_create(afw_compile_args_t, 10, 0, true, \
1230 (parser)->p, (parser)->xctx)
1235 #define afw_compile_args_add_value(args, value) \
1236 afw_stack_push(args, (parser)->xctx) = value
1241 #define afw_compile_args_finalize(args, argc, argv) \
1242 afw_stack_copy_and_release((args), (argc), (argv), \
1243 (parser)->p, (parser)->xctx)
1254 afw_compile_lexical_parser_create(
1257 void *callback_data,
1270 afw_compile_lexical_parser_finish_and_release(
1276 #define AFW_COMPILE_THROW_EXPECTING_SEMICOLON \
1277 AFW_COMPILE_THROW_ERROR_Z("Expecting statement terminator ';'")
1281 #define AFW_COMPILE_ASSERT_TOKEN_IS_SEMICOLON \
1282 if (!afw_compile_token_is(semicolon)) \
1283 AFW_COMPILE_THROW_EXPECTING_SEMICOLON
1287 #define AFW_COMPILE_ASSERT_NEXT_TOKEN_IS_SEMICOLON \
1288 afw_compile_get_token(); \
1289 AFW_COMPILE_ASSERT_TOKEN_IS_SEMICOLON
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.
double afw_double_t
Normal AFW number is double.
afw_int32_t afw_code_point_t
Unicode code point.
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).
afw_utf8_octet_t afw_utf8_z_t
NFC normalized UTF-8 null terminated string.
enum afw_compile_type_e afw_compile_type_t
Compile type enum.
char afw_utf8_octet_t
8 bits of utf-8 codepoint.
struct afw_compile_internal_args_s afw_compile_args_t
apr_size_t afw_size_t
size_t.
apr_int64_t afw_integer_t
typedef for big signed int.
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.
Interface afw_object public struct.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
struct for afw_value_block_t
struct for afw_value_block_symbol_t
Struct for compiled value value.
Interface afw_value public struct.
Struct for lambda parameter.
Type meta (data type, data type parameters, and value meta object.
Interface afw_xctx public struct.