From 39c11dbc0a70750b6c7d1ad6154cb0293fab5df5 Mon Sep 17 00:00:00 2001 From: Dylam De La Torre Date: Fri, 22 Mar 2024 22:51:15 +0100 Subject: [PATCH 1/9] Add support for applying metafunctions to functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Johel Ernesto Guerrero Peña --- source/parse.h | 22 +- source/reflect.h | 766 +++++++++++++++++++++++++--------------------- source/reflect.h2 | 64 +++- source/sema.h | 16 + 4 files changed, 509 insertions(+), 359 deletions(-) diff --git a/source/parse.h b/source/parse.h index 0930529e2..b9b19cd5e 100644 --- a/source/parse.h +++ b/source/parse.h @@ -8544,6 +8544,9 @@ class parser auto apply_type_metafunctions( declaration_node& decl ) -> bool; + auto apply_function_metafunctions( declaration_node& decl ) + -> bool; + //G unnamed-declaration: //G ':' meta-functions? template-parameters? function-type requires-clause? '=' statement @@ -8753,14 +8756,6 @@ class parser { n->type = std::move(t); assert (n->is_function()); - - if (!n->metafunctions.empty()) { - errors.emplace_back( - n->metafunctions.front()->position(), - "(temporary alpha limitation) metafunctions are currently not supported on functions, only on types" - ); - return {}; - } } // Or a namespace @@ -9123,6 +9118,17 @@ class parser ); } + // If this is a function with metafunctions, apply those + if (n->is_function()) { + if (!apply_function_metafunctions(*n)) { + error( + "error encountered while applying function metafunctions", + false, {}, true + ); + return {}; + } + } + return n; } diff --git a/source/reflect.h b/source/reflect.h index 759342845..303b138ef 100644 --- a/source/reflect.h +++ b/source/reflect.h @@ -39,74 +39,74 @@ class alias_declaration; #line 1012 "reflect.h2" class value_member_info; -#line 1530 "reflect.h2" +#line 1534 "reflect.h2" class expression_flags; -#line 1546 "reflect.h2" +#line 1550 "reflect.h2" class regex_token; -#line 1572 "reflect.h2" +#line 1576 "reflect.h2" class regex_token_check; -#line 1591 "reflect.h2" +#line 1595 "reflect.h2" class regex_token_code; -#line 1610 "reflect.h2" +#line 1614 "reflect.h2" class regex_token_empty; -#line 1626 "reflect.h2" +#line 1630 "reflect.h2" class regex_token_list; -#line 1665 "reflect.h2" +#line 1669 "reflect.h2" class parse_context_group_state; -#line 1726 "reflect.h2" +#line 1730 "reflect.h2" class parse_context_branch_reset_state; -#line 1769 "reflect.h2" +#line 1773 "reflect.h2" class parse_context; -#line 2167 "reflect.h2" +#line 2171 "reflect.h2" class generation_function_context; -#line 2185 "reflect.h2" +#line 2189 "reflect.h2" class generation_context; -#line 2383 "reflect.h2" +#line 2387 "reflect.h2" class alternative_token; -#line 2398 "reflect.h2" +#line 2402 "reflect.h2" class alternative_token_gen; -#line 2450 "reflect.h2" +#line 2454 "reflect.h2" class any_token; -#line 2468 "reflect.h2" +#line 2472 "reflect.h2" class char_token; -#line 2571 "reflect.h2" +#line 2575 "reflect.h2" class class_token; -#line 2786 "reflect.h2" +#line 2790 "reflect.h2" class group_ref_token; -#line 2917 "reflect.h2" +#line 2921 "reflect.h2" class group_token; -#line 3204 "reflect.h2" +#line 3208 "reflect.h2" class lookahead_token; -#line 3285 "reflect.h2" +#line 3289 "reflect.h2" class range_token; -#line 3433 "reflect.h2" +#line 3437 "reflect.h2" class special_range_token; -#line 3500 "reflect.h2" +#line 3504 "reflect.h2" template class regex_generator; -#line 3750 "reflect.h2" +#line 3808 "reflect.h2" } } @@ -543,10 +543,13 @@ auto cpp2_union(meta::type_declaration& t) -> void; #line 1506 "reflect.h2" auto print(cpp2::impl::in t) -> void; -#line 1526 "reflect.h2" -using error_func = std::function x)>; +#line 1511 "reflect.h2" +auto print(cpp2::impl::in f) -> void; #line 1530 "reflect.h2" +using error_func = std::function x)>; + +#line 1534 "reflect.h2" class expression_flags { private: cpp2::u8 _value; private: constexpr expression_flags(cpp2::impl::in _val); @@ -581,20 +584,20 @@ public: [[nodiscard]] auto to_code() const& -> std::string; public: [[nodiscard]] static auto from_string(cpp2::impl::in s) -> expression_flags; public: [[nodiscard]] static auto from_code(cpp2::impl::in s) -> expression_flags; -#line 1538 "reflect.h2" +#line 1542 "reflect.h2" }; -#line 1546 "reflect.h2" +#line 1550 "reflect.h2" class regex_token { public: std::string string_rep; public: explicit regex_token(cpp2::impl::in str); -#line 1554 "reflect.h2" +#line 1558 "reflect.h2" public: explicit regex_token(); -#line 1559 "reflect.h2" +#line 1563 "reflect.h2" public: virtual auto generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void = 0; public: virtual auto add_groups([[maybe_unused]] std::set& unnamed_param_2) const -> void; @@ -605,24 +608,24 @@ class regex_token public: regex_token(regex_token const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(regex_token const&) -> void = delete; -#line 1564 "reflect.h2" +#line 1568 "reflect.h2" }; using token_ptr = std::shared_ptr; using token_vec = std::vector; -#line 1570 "reflect.h2" +#line 1574 "reflect.h2" // Adds a check in code generation. // class regex_token_check : public regex_token { -#line 1576 "reflect.h2" +#line 1580 "reflect.h2" private: std::string check; public: explicit regex_token_check(cpp2::impl::in str, cpp2::impl::in check_); -#line 1583 "reflect.h2" +#line 1587 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~regex_token_check() noexcept; @@ -630,21 +633,21 @@ class regex_token_check public: auto operator=(regex_token_check const&) -> void = delete; -#line 1586 "reflect.h2" +#line 1590 "reflect.h2" }; -#line 1589 "reflect.h2" +#line 1593 "reflect.h2" // Adds code in code generation. // class regex_token_code : public regex_token { -#line 1595 "reflect.h2" +#line 1599 "reflect.h2" private: std::string code; public: explicit regex_token_code(cpp2::impl::in str, cpp2::impl::in code_); -#line 1602 "reflect.h2" +#line 1606 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~regex_token_code() noexcept; @@ -652,19 +655,19 @@ class regex_token_code public: auto operator=(regex_token_code const&) -> void = delete; -#line 1605 "reflect.h2" +#line 1609 "reflect.h2" }; -#line 1608 "reflect.h2" +#line 1612 "reflect.h2" // Token that does not influence the matching. E.g. comment. // class regex_token_empty : public regex_token { -#line 1614 "reflect.h2" +#line 1618 "reflect.h2" public: explicit regex_token_empty(cpp2::impl::in str); -#line 1618 "reflect.h2" +#line 1622 "reflect.h2" public: auto generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void override; public: virtual ~regex_token_empty() noexcept; @@ -672,27 +675,27 @@ class regex_token_empty public: auto operator=(regex_token_empty const&) -> void = delete; -#line 1621 "reflect.h2" +#line 1625 "reflect.h2" }; -#line 1624 "reflect.h2" +#line 1628 "reflect.h2" // Represents a list of regex tokens as one token. // class regex_token_list : public regex_token { -#line 1630 "reflect.h2" +#line 1634 "reflect.h2" public: token_vec tokens; public: explicit regex_token_list(cpp2::impl::in t); -#line 1637 "reflect.h2" +#line 1641 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 1643 "reflect.h2" +#line 1647 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; -#line 1649 "reflect.h2" +#line 1653 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in vec) -> std::string; public: virtual ~regex_token_list() noexcept; @@ -700,10 +703,10 @@ class regex_token_list public: auto operator=(regex_token_list const&) -> void = delete; -#line 1656 "reflect.h2" +#line 1660 "reflect.h2" }; -#line 1659 "reflect.h2" +#line 1663 "reflect.h2" // // Parse and generation context. // @@ -719,33 +722,33 @@ class parse_context_group_state // Start a new alternative. public: auto next_alternative() & -> void; -#line 1679 "reflect.h2" +#line 1683 "reflect.h2" // Swap this state with the other one. public: auto swap(parse_context_group_state& t) & -> void; -#line 1686 "reflect.h2" +#line 1690 "reflect.h2" // Convert this state into a regex token. public: [[nodiscard]] auto get_as_token() & -> token_ptr; -#line 1698 "reflect.h2" +#line 1702 "reflect.h2" // Add a token to the current matcher list. public: auto add(cpp2::impl::in token) & -> void; -#line 1703 "reflect.h2" +#line 1707 "reflect.h2" // True if current matcher list is empty. public: [[nodiscard]] auto empty() const& -> bool; -#line 1707 "reflect.h2" +#line 1711 "reflect.h2" // Apply optimizations to the matcher list. public: static auto post_process_list(token_vec& list) -> void; public: parse_context_group_state(auto const& cur_match_list_, auto const& alternate_match_lists_, auto const& modifiers_); public: parse_context_group_state(); -#line 1721 "reflect.h2" +#line 1725 "reflect.h2" }; -#line 1724 "reflect.h2" +#line 1728 "reflect.h2" // State for the branch reset. Takes care of the group numbering. See '(|)'. // class parse_context_branch_reset_state @@ -758,25 +761,25 @@ class parse_context_branch_reset_state // Next group identifier. public: [[nodiscard]] auto next() & -> int; -#line 1742 "reflect.h2" +#line 1746 "reflect.h2" // Set next group identifier. public: auto set_next(cpp2::impl::in g) & -> void; -#line 1748 "reflect.h2" +#line 1752 "reflect.h2" // Start a new alternative branch. public: auto next_alternative() & -> void; -#line 1755 "reflect.h2" +#line 1759 "reflect.h2" // Initialize for a branch reset group. public: auto set_active_reset(cpp2::impl::in restart) & -> void; public: parse_context_branch_reset_state(auto const& is_active_, auto const& cur_group_, auto const& max_group_, auto const& from_); public: parse_context_branch_reset_state(); -#line 1762 "reflect.h2" +#line 1766 "reflect.h2" }; -#line 1765 "reflect.h2" +#line 1769 "reflect.h2" // Context during parsing of the regular expressions. // // Keeps track of the distributed group identifiers, current parsed group and branch resets. @@ -790,7 +793,7 @@ class parse_context private: parse_context_group_state cur_group_state {}; private: parse_context_branch_reset_state cur_branch_reset_state {}; -#line 1779 "reflect.h2" +#line 1783 "reflect.h2" public: std::map named_groups {}; private: error_func error_out; // TODO: Declaring std::function fails for cpp2. @@ -798,64 +801,64 @@ class parse_context public: explicit parse_context(cpp2::impl::in r, auto const& e); -#line 1790 "reflect.h2" +#line 1794 "reflect.h2" // State management functions // // Returned group state needs to be stored and provided in `end_group`. public: [[nodiscard]] auto start_group() & -> parse_context_group_state; -#line 1803 "reflect.h2" +#line 1807 "reflect.h2" // `old_state` argument needs to be from start group. public: [[nodiscard]] auto end_group(cpp2::impl::in old_state) & -> token_ptr; -#line 1811 "reflect.h2" +#line 1815 "reflect.h2" public: [[nodiscard]] auto get_modifiers() const& -> expression_flags; -#line 1815 "reflect.h2" +#line 1819 "reflect.h2" public: auto set_modifiers(cpp2::impl::in mod) & -> void; -#line 1819 "reflect.h2" +#line 1823 "reflect.h2" // Branch reset management functions // public: [[nodiscard]] auto branch_reset_new_state() & -> parse_context_branch_reset_state; -#line 1831 "reflect.h2" +#line 1835 "reflect.h2" public: auto branch_reset_restore_state(cpp2::impl::in old_state) & -> void; -#line 1838 "reflect.h2" +#line 1842 "reflect.h2" public: auto next_alternative() & -> void; -#line 1844 "reflect.h2" +#line 1848 "reflect.h2" // Regex token management // public: auto add_token(cpp2::impl::in token) & -> void; -#line 1850 "reflect.h2" +#line 1854 "reflect.h2" public: [[nodiscard]] auto has_token() const& -> bool; -#line 1854 "reflect.h2" +#line 1858 "reflect.h2" public: [[nodiscard]] auto pop_token() & -> token_ptr; -#line 1865 "reflect.h2" +#line 1869 "reflect.h2" public: [[nodiscard]] auto get_as_token() & -> token_ptr; -#line 1869 "reflect.h2" +#line 1873 "reflect.h2" // Group management // public: [[nodiscard]] auto get_cur_group() const& -> int; -#line 1875 "reflect.h2" +#line 1879 "reflect.h2" public: [[nodiscard]] auto next_group() & -> int; -#line 1879 "reflect.h2" +#line 1883 "reflect.h2" public: auto set_named_group(cpp2::impl::in name, cpp2::impl::in id) & -> void; -#line 1886 "reflect.h2" +#line 1890 "reflect.h2" public: [[nodiscard]] auto get_named_group(cpp2::impl::in name) const& -> int; -#line 1897 "reflect.h2" +#line 1901 "reflect.h2" // Position management functions // public: [[nodiscard]] auto current() const& -> char; @@ -863,51 +866,51 @@ class parse_context // Get the next token in the regex, skipping spaces according to the parameters. See `x` and `xx` modifiers. private: [[nodiscard]] auto get_next_position(cpp2::impl::in in_class, cpp2::impl::in no_skip) const& -> size_t; -#line 1941 "reflect.h2" +#line 1945 "reflect.h2" // Return true if next token is available. private: [[nodiscard]] auto next_impl(cpp2::impl::in in_class, cpp2::impl::in no_skip) & -> bool; -#line 1953 "reflect.h2" +#line 1957 "reflect.h2" public: [[nodiscard]] auto next() & -> auto; public: [[nodiscard]] auto next_in_class() & -> auto; public: [[nodiscard]] auto next_no_skip() & -> auto; public: [[nodiscard]] auto next_n(cpp2::impl::in n) & -> bool; -#line 1966 "reflect.h2" +#line 1970 "reflect.h2" public: [[nodiscard]] auto has_next() const& -> bool; private: [[nodiscard]] auto grab_until_impl(cpp2::impl::in e, cpp2::impl::out r, cpp2::impl::in any) & -> bool; -#line 1989 "reflect.h2" +#line 1993 "reflect.h2" public: [[nodiscard]] auto grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_until_one_of(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_n(cpp2::impl::in n, cpp2::impl::out r) & -> bool; -#line 2006 "reflect.h2" +#line 2010 "reflect.h2" public: [[nodiscard]] auto grab_number() & -> std::string; -#line 2027 "reflect.h2" +#line 2031 "reflect.h2" private: [[nodiscard]] auto peek_impl(cpp2::impl::in in_class) const& -> char; -#line 2037 "reflect.h2" +#line 2041 "reflect.h2" public: [[nodiscard]] auto peek() const& -> auto; public: [[nodiscard]] auto peek_in_class() const& -> auto; -#line 2041 "reflect.h2" +#line 2045 "reflect.h2" // Parsing functions // public: [[nodiscard]] auto parser_group_modifiers(cpp2::impl::in change_str, expression_flags& parser_modifiers) & -> bool; -#line 2097 "reflect.h2" +#line 2101 "reflect.h2" public: [[nodiscard]] auto parse_until(cpp2::impl::in term) & -> bool; -#line 2135 "reflect.h2" +#line 2139 "reflect.h2" public: [[nodiscard]] auto parse(cpp2::impl::in modifiers) & -> bool; -#line 2150 "reflect.h2" +#line 2154 "reflect.h2" // Misc functions public: [[nodiscard]] auto get_pos() const& -> auto; @@ -919,10 +922,10 @@ class parse_context public: auto operator=(parse_context const&) -> void = delete; -#line 2161 "reflect.h2" +#line 2165 "reflect.h2" }; -#line 2164 "reflect.h2" +#line 2168 "reflect.h2" // Context for one function generation. Generation of functions can be interleaved, // therefore we buffer the code for one function here. // @@ -932,16 +935,16 @@ class generation_function_context { public: auto add_tabs(cpp2::impl::in c) & -> void; -#line 2178 "reflect.h2" +#line 2182 "reflect.h2" public: auto remove_tabs(cpp2::impl::in c) & -> void; public: generation_function_context(auto const& code_, auto const& tabs_); public: generation_function_context(); -#line 2181 "reflect.h2" +#line 2185 "reflect.h2" }; -#line 2184 "reflect.h2" +#line 2188 "reflect.h2" // Context for generating the state machine. class generation_context { @@ -961,68 +964,68 @@ class generation_context // Add code line. public: auto add(cpp2::impl::in s) & -> void; -#line 2206 "reflect.h2" +#line 2210 "reflect.h2" // Add check for token. The check needs to be a function call that returns a boolean. public: auto add_check(cpp2::impl::in check) & -> void; -#line 2212 "reflect.h2" +#line 2216 "reflect.h2" // Add a stateful check. The check needs to return a `match_return`. public: auto add_statefull(cpp2::impl::in next_func, cpp2::impl::in check) & -> void; -#line 2221 "reflect.h2" +#line 2225 "reflect.h2" protected: auto start_func_named(cpp2::impl::in name) & -> void; -#line 2232 "reflect.h2" +#line 2236 "reflect.h2" protected: [[nodiscard]] auto start_func() & -> std::string; -#line 2239 "reflect.h2" +#line 2243 "reflect.h2" protected: auto end_func_statefull(cpp2::impl::in s) & -> void; -#line 2258 "reflect.h2" +#line 2262 "reflect.h2" // Generate the function for a token. public: [[nodiscard]] auto generate_func(cpp2::impl::in token) & -> std::string; -#line 2268 "reflect.h2" +#line 2272 "reflect.h2" // Generate the reset for a list of group identifiers. public: [[nodiscard]] auto generate_reset(cpp2::impl::in> groups) & -> std::string; -#line 2291 "reflect.h2" +#line 2295 "reflect.h2" // Name generation // protected: [[nodiscard]] auto gen_func_name() & -> std::string; -#line 2299 "reflect.h2" +#line 2303 "reflect.h2" public: [[nodiscard]] auto next_func_name() & -> std::string; -#line 2303 "reflect.h2" +#line 2307 "reflect.h2" protected: [[nodiscard]] auto gen_reset_func_name() & -> std::string; -#line 2309 "reflect.h2" +#line 2313 "reflect.h2" public: [[nodiscard]] auto gen_temp() & -> std::string; -#line 2315 "reflect.h2" +#line 2319 "reflect.h2" // Context management // public: [[nodiscard]] auto new_context() & -> generation_function_context*; -#line 2325 "reflect.h2" +#line 2329 "reflect.h2" public: auto finish_context() & -> void; -#line 2333 "reflect.h2" +#line 2337 "reflect.h2" // Misc functions // private: [[nodiscard]] auto get_current() & -> generation_function_context*; -#line 2339 "reflect.h2" +#line 2343 "reflect.h2" private: [[nodiscard]] auto get_base() & -> generation_function_context*; -#line 2343 "reflect.h2" +#line 2347 "reflect.h2" public: [[nodiscard]] auto get_entry_func() const& -> std::string; -#line 2347 "reflect.h2" +#line 2351 "reflect.h2" public: [[nodiscard]] auto create_named_group_lookup(cpp2::impl::in> named_groups) const& -> std::string; -#line 2371 "reflect.h2" +#line 2375 "reflect.h2" // Run the generation for the token. public: [[nodiscard]] auto run(cpp2::impl::in token) & -> std::string; public: generation_context() = default; @@ -1030,7 +1033,7 @@ class generation_context public: auto operator=(generation_context const&) -> void = delete; -#line 2377 "reflect.h2" +#line 2381 "reflect.h2" }; // Regex syntax: | Example: ab|ba @@ -1050,24 +1053,24 @@ class alternative_token public: auto operator=(alternative_token const&) -> void = delete; -#line 2396 "reflect.h2" +#line 2400 "reflect.h2" }; class alternative_token_gen : public regex_token { -#line 2402 "reflect.h2" +#line 2406 "reflect.h2" private: token_vec alternatives; public: explicit alternative_token_gen(cpp2::impl::in a); -#line 2409 "reflect.h2" +#line 2413 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2426 "reflect.h2" +#line 2430 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; -#line 2433 "reflect.h2" +#line 2437 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in a) -> std::string; public: virtual ~alternative_token_gen() noexcept; @@ -1075,19 +1078,19 @@ class alternative_token_gen public: auto operator=(alternative_token_gen const&) -> void = delete; -#line 2445 "reflect.h2" +#line 2449 "reflect.h2" }; -#line 2448 "reflect.h2" +#line 2452 "reflect.h2" // Regex syntax: . // class any_token : public regex_token_check { -#line 2454 "reflect.h2" +#line 2458 "reflect.h2" public: explicit any_token(cpp2::impl::in single_line); -#line 2458 "reflect.h2" +#line 2462 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; public: virtual ~any_token() noexcept; @@ -1095,37 +1098,37 @@ class any_token public: auto operator=(any_token const&) -> void = delete; -#line 2463 "reflect.h2" +#line 2467 "reflect.h2" }; -#line 2466 "reflect.h2" +#line 2470 "reflect.h2" // Regex syntax: a // class char_token : public regex_token { -#line 2472 "reflect.h2" +#line 2476 "reflect.h2" private: std::string token; private: bool ignore_case; public: explicit char_token(cpp2::impl::in t, cpp2::impl::in ignore_case_); -#line 2481 "reflect.h2" +#line 2485 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 2485 "reflect.h2" +#line 2489 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2508 "reflect.h2" +#line 2512 "reflect.h2" public: auto gen_case_insensitive(cpp2::impl::in lower, cpp2::impl::in upper, generation_context& ctx) const& -> void; -#line 2529 "reflect.h2" +#line 2533 "reflect.h2" public: auto gen_case_sensitive(generation_context& ctx) const& -> void; -#line 2547 "reflect.h2" +#line 2551 "reflect.h2" public: [[nodiscard]] auto add_escapes(std::string str) const& -> std::string; -#line 2562 "reflect.h2" +#line 2566 "reflect.h2" public: auto append(char_token const& that) & -> void; public: virtual ~char_token() noexcept; @@ -1133,30 +1136,30 @@ class char_token public: auto operator=(char_token const&) -> void = delete; -#line 2566 "reflect.h2" +#line 2570 "reflect.h2" }; -#line 2569 "reflect.h2" +#line 2573 "reflect.h2" // Regex syntax: [] Example: [abcx-y[:digits:]] // class class_token : public regex_token { -#line 2575 "reflect.h2" +#line 2579 "reflect.h2" private: bool negate; private: bool case_insensitive; private: std::string class_str; public: explicit class_token(cpp2::impl::in negate_, cpp2::impl::in case_insensitive_, cpp2::impl::in class_str_, cpp2::impl::in str); -#line 2587 "reflect.h2" +#line 2591 "reflect.h2" // TODO: Rework class generation: Generate check functions for classes. public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 2713 "reflect.h2" +#line 2717 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2718 "reflect.h2" +#line 2722 "reflect.h2" private: [[nodiscard]] static auto create_matcher(cpp2::impl::in name, cpp2::impl::in template_arguments) -> std::string; public: virtual ~class_token() noexcept; @@ -1164,20 +1167,20 @@ class class_token public: auto operator=(class_token const&) -> void = delete; -#line 2725 "reflect.h2" +#line 2729 "reflect.h2" }; -#line 2728 "reflect.h2" +#line 2732 "reflect.h2" // Regex syntax: \a or \n or \[ // [[nodiscard]] auto escape_token_parse(parse_context& ctx) -> token_ptr; -#line 2769 "reflect.h2" +#line 2773 "reflect.h2" // Regex syntax: \K Example: ab\Kcd // [[nodiscard]] auto global_group_reset_token_parse(parse_context& ctx) -> token_ptr; -#line 2780 "reflect.h2" +#line 2784 "reflect.h2" // Regex syntax: \ Example: \1 // \g{name_or_number} // \k{name_or_number} @@ -1187,16 +1190,16 @@ class class_token class group_ref_token : public regex_token { -#line 2790 "reflect.h2" +#line 2794 "reflect.h2" private: int id; private: bool case_insensitive; public: explicit group_ref_token(cpp2::impl::in id_, cpp2::impl::in case_insensitive_, cpp2::impl::in str); -#line 2800 "reflect.h2" +#line 2804 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 2901 "reflect.h2" +#line 2905 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~group_ref_token() noexcept; @@ -1204,10 +1207,10 @@ class group_ref_token public: auto operator=(group_ref_token const&) -> void = delete; -#line 2904 "reflect.h2" +#line 2908 "reflect.h2" }; -#line 2907 "reflect.h2" +#line 2911 "reflect.h2" // Regex syntax: () Example: (abc) // (?:) (?i:abc) @@ -1221,22 +1224,22 @@ class group_ref_token class group_token : public regex_token { -#line 2921 "reflect.h2" +#line 2925 "reflect.h2" private: int number {-1}; private: token_ptr inner {nullptr}; public: [[nodiscard]] static auto parse_lookahead(parse_context& ctx, cpp2::impl::in syntax, cpp2::impl::in positive) -> token_ptr; -#line 2938 "reflect.h2" +#line 2942 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 3075 "reflect.h2" +#line 3079 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in name, cpp2::impl::in name_brackets, cpp2::impl::in has_modifier, cpp2::impl::in modifiers, cpp2::impl::in inner_) -> std::string; -#line 3093 "reflect.h2" +#line 3097 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3113 "reflect.h2" +#line 3117 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~group_token() noexcept; @@ -1245,25 +1248,25 @@ class group_token public: auto operator=(group_token const&) -> void = delete; -#line 3120 "reflect.h2" +#line 3124 "reflect.h2" }; -#line 3123 "reflect.h2" +#line 3127 "reflect.h2" // Regex syntax: \x or \x{} Example: \x{62} // [[nodiscard]] auto hexadecimal_token_parse(parse_context& ctx) -> token_ptr; -#line 3164 "reflect.h2" +#line 3168 "reflect.h2" // Regex syntax: $ Example: aa$ // [[nodiscard]] auto line_end_token_parse(parse_context& ctx) -> token_ptr; -#line 3184 "reflect.h2" +#line 3188 "reflect.h2" // Regex syntax: ^ Example: ^aa // [[nodiscard]] auto line_start_token_parse(parse_context& ctx) -> token_ptr; -#line 3200 "reflect.h2" +#line 3204 "reflect.h2" // Regex syntax: (?=) or (?!) or (*pla), etc. Example: (?=AA) // // Parsed in group_token. @@ -1271,16 +1274,16 @@ class group_token class lookahead_token : public regex_token { -#line 3208 "reflect.h2" +#line 3212 "reflect.h2" protected: bool positive; public: token_ptr inner {nullptr}; public: explicit lookahead_token(cpp2::impl::in positive_); -#line 3215 "reflect.h2" +#line 3219 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3221 "reflect.h2" +#line 3225 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~lookahead_token() noexcept; @@ -1288,26 +1291,26 @@ class lookahead_token public: auto operator=(lookahead_token const&) -> void = delete; -#line 3224 "reflect.h2" +#line 3228 "reflect.h2" }; -#line 3227 "reflect.h2" +#line 3231 "reflect.h2" // Named character classes // [[nodiscard]] auto named_class_token_parse(parse_context& ctx) -> token_ptr; -#line 3255 "reflect.h2" +#line 3259 "reflect.h2" // Regex syntax: \o{} Example: \o{142} // [[nodiscard]] auto octal_token_parse(parse_context& ctx) -> token_ptr; -#line 3283 "reflect.h2" +#line 3287 "reflect.h2" // Regex syntax: {min, max} Example: a{2,4} // class range_token : public regex_token { -#line 3289 "reflect.h2" +#line 3293 "reflect.h2" protected: int min_count {-1}; protected: int max_count {-1}; protected: int kind {range_flags::greedy}; @@ -1317,19 +1320,19 @@ class range_token public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 3369 "reflect.h2" +#line 3373 "reflect.h2" public: auto parse_modifier(parse_context& ctx) & -> void; -#line 3381 "reflect.h2" +#line 3385 "reflect.h2" public: [[nodiscard]] auto gen_mod_string() const& -> std::string; -#line 3394 "reflect.h2" +#line 3398 "reflect.h2" public: [[nodiscard]] auto gen_range_string() const& -> std::string; -#line 3413 "reflect.h2" +#line 3417 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3424 "reflect.h2" +#line 3428 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~range_token() noexcept; @@ -1337,16 +1340,16 @@ class range_token public: auto operator=(range_token const&) -> void = delete; -#line 3428 "reflect.h2" +#line 3432 "reflect.h2" }; -#line 3431 "reflect.h2" +#line 3435 "reflect.h2" // Regex syntax: *, +, or ? Example: aa* // class special_range_token : public range_token { -#line 3437 "reflect.h2" +#line 3441 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; public: virtual ~special_range_token() noexcept; @@ -1355,17 +1358,17 @@ class special_range_token public: auto operator=(special_range_token const&) -> void = delete; -#line 3467 "reflect.h2" +#line 3471 "reflect.h2" }; -#line 3470 "reflect.h2" +#line 3474 "reflect.h2" // Regex syntax: \b or \B Example: \bword\b // // Matches the start end end of word boundaries. // [[nodiscard]] auto word_boundary_token_parse(parse_context& ctx) -> token_ptr; -#line 3492 "reflect.h2" +#line 3496 "reflect.h2" //----------------------------------------------------------------------- // // Parser for regular expression. @@ -1386,27 +1389,27 @@ template class regex_generator public: explicit regex_generator(cpp2::impl::in r, Error_out const& e); -#line 3515 "reflect.h2" +#line 3519 "reflect.h2" public: [[nodiscard]] auto parse() & -> std::string; -#line 3550 "reflect.h2" +#line 3554 "reflect.h2" private: auto extract_modifiers() & -> void; public: regex_generator(regex_generator const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(regex_generator const&) -> void = delete; -#line 3564 "reflect.h2" +#line 3568 "reflect.h2" }; template [[nodiscard]] auto generate_regex(cpp2::impl::in regex, Err const& err) -> std::string; -#line 3576 "reflect.h2" +#line 3580 "reflect.h2" auto regex_gen(meta::type_declaration& t) -> void; -#line 3631 "reflect.h2" +#line 3635 "reflect.h2" //----------------------------------------------------------------------- // -// apply_metafunctions +// apply_metafunctions - for types // [[nodiscard]] auto apply_metafunctions( declaration_node& n, @@ -1414,7 +1417,18 @@ auto regex_gen(meta::type_declaration& t) -> void; auto const& error ) -> bool; -#line 3750 "reflect.h2" +#line 3754 "reflect.h2" +//----------------------------------------------------------------------- +// +// apply_metafunctions - for functions +// +[[nodiscard]] auto apply_metafunctions( + declaration_node& n, + function_declaration& rfunc, + auto const& error + ) -> bool; + +#line 3808 "reflect.h2" } } @@ -3105,7 +3119,7 @@ std::string value_set{""}; #line 1502 "reflect.h2" //----------------------------------------------------------------------- // -// print - output a pretty-printed visualization of t +// print - output a pretty-printed visualization of t or f // #line 1506 "reflect.h2" auto print(cpp2::impl::in t) -> void @@ -3113,6 +3127,12 @@ auto print(cpp2::impl::in t) -> void std::cout << CPP2_UFCS(print)(t) << "\n"; } +#line 1511 "reflect.h2" +auto print(cpp2::impl::in f) -> void +{ + std::cout << CPP2_UFCS(print)(f) << "\n"; +} + constexpr expression_flags::expression_flags(cpp2::impl::in _val) : _value{ cpp2::unsafe_narrow(_val) } { } @@ -3204,7 +3224,7 @@ return none; [[nodiscard]] auto expression_flags::from_code(cpp2::impl::in s) -> expression_flags{ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::move(str), "expression_flags::", "")); } -#line 1512 "reflect.h2" +#line 1516 "reflect.h2" //----------------------------------------------------------------------- // // regex - creates regular expressions from members @@ -3220,11 +3240,11 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov // ``` // -#line 1528 "reflect.h2" +#line 1532 "reflect.h2" // Possible modifiers for a regular expression. // -#line 1532 "reflect.h2" +#line 1536 "reflect.h2" // mod: i // mod: m // mod: s @@ -3232,106 +3252,106 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov // mod: x // mod: xx -#line 1541 "reflect.h2" +#line 1545 "reflect.h2" // Tokens for regular expressions. // // Basic class for a regex token. // -#line 1550 "reflect.h2" +#line 1554 "reflect.h2" regex_token::regex_token(cpp2::impl::in str) : string_rep{ str }{ -#line 1552 "reflect.h2" +#line 1556 "reflect.h2" } -#line 1554 "reflect.h2" +#line 1558 "reflect.h2" regex_token::regex_token() : string_rep{ "" }{ -#line 1556 "reflect.h2" +#line 1560 "reflect.h2" } //parse: (inout ctx: parse_context) -> token_ptr; // Generate the matching code. -#line 1561 "reflect.h2" +#line 1565 "reflect.h2" auto regex_token::add_groups([[maybe_unused]] std::set& unnamed_param_2) const -> void{}// Adds all group indices to the set. -#line 1562 "reflect.h2" +#line 1566 "reflect.h2" [[nodiscard]] auto regex_token::to_string() const& -> std::string{return string_rep; }// Create a string representation. -#line 1563 "reflect.h2" +#line 1567 "reflect.h2" auto regex_token::set_string(cpp2::impl::in s) & -> void{string_rep = s; } regex_token::~regex_token() noexcept{}// Set the string representation. -#line 1578 "reflect.h2" +#line 1582 "reflect.h2" regex_token_check::regex_token_check(cpp2::impl::in str, cpp2::impl::in check_) : regex_token{ str } , check{ check_ }{ -#line 1581 "reflect.h2" +#line 1585 "reflect.h2" } -#line 1583 "reflect.h2" +#line 1587 "reflect.h2" auto regex_token_check::generate_code(generation_context& ctx) const -> void{ ctx.add_check(check + "(" + ctx.match_parameters() + ")"); } regex_token_check::~regex_token_check() noexcept{} -#line 1597 "reflect.h2" +#line 1601 "reflect.h2" regex_token_code::regex_token_code(cpp2::impl::in str, cpp2::impl::in code_) : regex_token{ str } , code{ code_ }{ -#line 1600 "reflect.h2" +#line 1604 "reflect.h2" } -#line 1602 "reflect.h2" +#line 1606 "reflect.h2" auto regex_token_code::generate_code(generation_context& ctx) const -> void{ ctx.add(code); } regex_token_code::~regex_token_code() noexcept{} -#line 1614 "reflect.h2" +#line 1618 "reflect.h2" regex_token_empty::regex_token_empty(cpp2::impl::in str) : regex_token{ str }{ -#line 1616 "reflect.h2" +#line 1620 "reflect.h2" } -#line 1618 "reflect.h2" +#line 1622 "reflect.h2" auto regex_token_empty::generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void{ // Nothing. } regex_token_empty::~regex_token_empty() noexcept{} -#line 1632 "reflect.h2" +#line 1636 "reflect.h2" regex_token_list::regex_token_list(cpp2::impl::in t) : regex_token{ gen_string(t) } , tokens{ t }{ -#line 1635 "reflect.h2" +#line 1639 "reflect.h2" } -#line 1637 "reflect.h2" +#line 1641 "reflect.h2" auto regex_token_list::generate_code(generation_context& ctx) const -> void{ for ( auto const& token : tokens ) { (*cpp2::impl::assert_not_null(token)).generate_code(ctx); } } -#line 1643 "reflect.h2" +#line 1647 "reflect.h2" auto regex_token_list::add_groups(std::set& groups) const -> void{ for ( auto const& token : tokens ) { (*cpp2::impl::assert_not_null(token)).add_groups(groups); } } -#line 1649 "reflect.h2" +#line 1653 "reflect.h2" [[nodiscard]] auto regex_token_list::gen_string(cpp2::impl::in vec) -> std::string{ std::string r {""}; for ( auto const& token : vec ) { @@ -3342,7 +3362,7 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov regex_token_list::~regex_token_list() noexcept{} -#line 1672 "reflect.h2" +#line 1676 "reflect.h2" auto parse_context_group_state::next_alternative() & -> void{ token_vec new_list {}; std::swap(new_list, cur_match_list); @@ -3350,14 +3370,14 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov static_cast(alternate_match_lists.insert(alternate_match_lists.end(), CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, cpp2::move(new_list)))); } -#line 1680 "reflect.h2" +#line 1684 "reflect.h2" auto parse_context_group_state::swap(parse_context_group_state& t) & -> void{ std::swap(cur_match_list, t.cur_match_list); std::swap(alternate_match_lists, t.alternate_match_lists); std::swap(modifiers, t.modifiers); } -#line 1687 "reflect.h2" +#line 1691 "reflect.h2" [[nodiscard]] auto parse_context_group_state::get_as_token() & -> token_ptr{ if (alternate_match_lists.empty()) { post_process_list(cur_match_list); @@ -3369,15 +3389,15 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov } } -#line 1699 "reflect.h2" +#line 1703 "reflect.h2" auto parse_context_group_state::add(cpp2::impl::in token) & -> void{ cur_match_list.push_back(token); } -#line 1704 "reflect.h2" +#line 1708 "reflect.h2" [[nodiscard]] auto parse_context_group_state::empty() const& -> bool { return cur_match_list.empty(); } -#line 1708 "reflect.h2" +#line 1712 "reflect.h2" auto parse_context_group_state::post_process_list(token_vec& list) -> void{ // Merge all characters auto merge_pos {list.begin()}; @@ -3398,7 +3418,7 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov , modifiers{ modifiers_ }{} parse_context_group_state::parse_context_group_state(){} -#line 1734 "reflect.h2" +#line 1738 "reflect.h2" [[nodiscard]] auto parse_context_branch_reset_state::next() & -> int{ auto g {cur_group}; cur_group += 1; @@ -3407,20 +3427,20 @@ parse_context_group_state::parse_context_group_state(){} return g; } -#line 1743 "reflect.h2" +#line 1747 "reflect.h2" auto parse_context_branch_reset_state::set_next(cpp2::impl::in g) & -> void{ cur_group = g; max_group = max(max_group, g); } -#line 1749 "reflect.h2" +#line 1753 "reflect.h2" auto parse_context_branch_reset_state::next_alternative() & -> void{ if (is_active) { cur_group = from; } } -#line 1756 "reflect.h2" +#line 1760 "reflect.h2" auto parse_context_branch_reset_state::set_active_reset(cpp2::impl::in restart) & -> void{ is_active = true; cur_group = restart; @@ -3435,16 +3455,16 @@ parse_context_group_state::parse_context_group_state(){} , from{ from_ }{} parse_context_branch_reset_state::parse_context_branch_reset_state(){} -#line 1784 "reflect.h2" +#line 1788 "reflect.h2" parse_context::parse_context(cpp2::impl::in r, auto const& e) : regex{ r } , root{ CPP2_UFCS_TEMPLATE_NONLOCAL(cpp2_new)(cpp2::shared, "") } , error_out{ e }{ -#line 1788 "reflect.h2" +#line 1792 "reflect.h2" } -#line 1794 "reflect.h2" +#line 1798 "reflect.h2" [[nodiscard]] auto parse_context::start_group() & -> parse_context_group_state { parse_context_group_state old_state {}; @@ -3454,7 +3474,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return old_state; } -#line 1804 "reflect.h2" +#line 1808 "reflect.h2" [[nodiscard]] auto parse_context::end_group(cpp2::impl::in old_state) & -> token_ptr { auto inner {cur_group_state.get_as_token()}; @@ -3462,17 +3482,17 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return inner; } -#line 1811 "reflect.h2" +#line 1815 "reflect.h2" [[nodiscard]] auto parse_context::get_modifiers() const& -> expression_flags{ return cur_group_state.modifiers; } -#line 1815 "reflect.h2" +#line 1819 "reflect.h2" auto parse_context::set_modifiers(cpp2::impl::in mod) & -> void{ cur_group_state.modifiers = mod; } -#line 1822 "reflect.h2" +#line 1826 "reflect.h2" [[nodiscard]] auto parse_context::branch_reset_new_state() & -> parse_context_branch_reset_state { parse_context_branch_reset_state old_state {}; @@ -3482,7 +3502,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return old_state; } -#line 1831 "reflect.h2" +#line 1835 "reflect.h2" auto parse_context::branch_reset_restore_state(cpp2::impl::in old_state) & -> void { auto max_group {cur_branch_reset_state.max_group}; @@ -3490,24 +3510,24 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} cur_branch_reset_state.set_next(cpp2::move(max_group)); } -#line 1838 "reflect.h2" +#line 1842 "reflect.h2" auto parse_context::next_alternative() & -> void { cur_group_state.next_alternative(); cur_branch_reset_state.next_alternative(); } -#line 1846 "reflect.h2" +#line 1850 "reflect.h2" auto parse_context::add_token(cpp2::impl::in token) & -> void{ cur_group_state.add(token); } -#line 1850 "reflect.h2" +#line 1854 "reflect.h2" [[nodiscard]] auto parse_context::has_token() const& -> bool{ return !(cur_group_state.empty()); } -#line 1854 "reflect.h2" +#line 1858 "reflect.h2" [[nodiscard]] auto parse_context::pop_token() & -> token_ptr { token_ptr r {nullptr}; @@ -3519,22 +3539,22 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 1865 "reflect.h2" +#line 1869 "reflect.h2" [[nodiscard]] auto parse_context::get_as_token() & -> token_ptr{ return root; } -#line 1871 "reflect.h2" +#line 1875 "reflect.h2" [[nodiscard]] auto parse_context::get_cur_group() const& -> int{ return cur_branch_reset_state.cur_group; } -#line 1875 "reflect.h2" +#line 1879 "reflect.h2" [[nodiscard]] auto parse_context::next_group() & -> int{ return cur_branch_reset_state.next(); } -#line 1879 "reflect.h2" +#line 1883 "reflect.h2" auto parse_context::set_named_group(cpp2::impl::in name, cpp2::impl::in id) & -> void { if (!(named_groups.contains(name))) {// Redefinition of group name is not an error. The left most one is retained. @@ -3542,7 +3562,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 1886 "reflect.h2" +#line 1890 "reflect.h2" [[nodiscard]] auto parse_context::get_named_group(cpp2::impl::in name) const& -> int { auto iter {named_groups.find(name)}; @@ -3554,10 +3574,10 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 1899 "reflect.h2" +#line 1903 "reflect.h2" [[nodiscard]] auto parse_context::current() const& -> char{return CPP2_ASSERT_IN_BOUNDS(regex, pos); } -#line 1902 "reflect.h2" +#line 1906 "reflect.h2" [[nodiscard]] auto parse_context::get_next_position(cpp2::impl::in in_class, cpp2::impl::in no_skip) const& -> size_t { auto perl_syntax {false}; @@ -3597,7 +3617,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return cur; } -#line 1942 "reflect.h2" +#line 1946 "reflect.h2" [[nodiscard]] auto parse_context::next_impl(cpp2::impl::in in_class, cpp2::impl::in no_skip) & -> bool { pos = get_next_position(in_class, no_skip); @@ -3609,14 +3629,14 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 1953 "reflect.h2" +#line 1957 "reflect.h2" [[nodiscard]] auto parse_context::next() & -> auto { return next_impl(false, false); } -#line 1954 "reflect.h2" +#line 1958 "reflect.h2" [[nodiscard]] auto parse_context::next_in_class() & -> auto { return next_impl(true, false); } -#line 1955 "reflect.h2" +#line 1959 "reflect.h2" [[nodiscard]] auto parse_context::next_no_skip() & -> auto { return next_impl(false, true); } -#line 1957 "reflect.h2" +#line 1961 "reflect.h2" [[nodiscard]] auto parse_context::next_n(cpp2::impl::in n) & -> bool{ auto r {true}; auto cur {0}; @@ -3626,10 +3646,10 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 1966 "reflect.h2" +#line 1970 "reflect.h2" [[nodiscard]] auto parse_context::has_next() const& -> bool{return cpp2::impl::cmp_less(pos,regex.size()); } -#line 1968 "reflect.h2" +#line 1972 "reflect.h2" [[nodiscard]] auto parse_context::grab_until_impl(cpp2::impl::in e, cpp2::impl::out r, cpp2::impl::in any) & -> bool { auto end {pos}; @@ -3651,14 +3671,14 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 1989 "reflect.h2" +#line 1993 "reflect.h2" [[nodiscard]] auto parse_context::grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(e, cpp2::impl::out(&r), false); } -#line 1990 "reflect.h2" +#line 1994 "reflect.h2" [[nodiscard]] auto parse_context::grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(std::string(1, e), cpp2::impl::out(&r), false); } -#line 1991 "reflect.h2" +#line 1995 "reflect.h2" [[nodiscard]] auto parse_context::grab_until_one_of(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(e, cpp2::impl::out(&r), true); } -#line 1993 "reflect.h2" +#line 1997 "reflect.h2" [[nodiscard]] auto parse_context::grab_n(cpp2::impl::in n, cpp2::impl::out r) & -> bool { if (cpp2::impl::cmp_less_eq(pos + cpp2::impl::as_(n),regex.size())) { @@ -3672,7 +3692,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2006 "reflect.h2" +#line 2010 "reflect.h2" [[nodiscard]] auto parse_context::grab_number() & -> std::string { auto start {pos}; @@ -3694,7 +3714,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return cpp2::move(r.value()); } -#line 2027 "reflect.h2" +#line 2031 "reflect.h2" [[nodiscard]] auto parse_context::peek_impl(cpp2::impl::in in_class) const& -> char{ auto next_pos {get_next_position(in_class, false)}; if (cpp2::impl::cmp_less(next_pos,regex.size())) { @@ -3705,12 +3725,12 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2037 "reflect.h2" +#line 2041 "reflect.h2" [[nodiscard]] auto parse_context::peek() const& -> auto { return peek_impl(false); } -#line 2038 "reflect.h2" +#line 2042 "reflect.h2" [[nodiscard]] auto parse_context::peek_in_class() const& -> auto { return peek_impl(true); } -#line 2043 "reflect.h2" +#line 2047 "reflect.h2" [[nodiscard]] auto parse_context::parser_group_modifiers(cpp2::impl::in change_str, expression_flags& parser_modifiers) & -> bool { auto is_negative {false}; @@ -3765,7 +3785,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return true; } -#line 2097 "reflect.h2" +#line 2101 "reflect.h2" [[nodiscard]] auto parse_context::parse_until(cpp2::impl::in term) & -> bool{ token_ptr cur_token {}; @@ -3804,7 +3824,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return true; } -#line 2135 "reflect.h2" +#line 2139 "reflect.h2" [[nodiscard]] auto parse_context::parse(cpp2::impl::in modifiers) & -> bool { @@ -3820,21 +3840,21 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 2152 "reflect.h2" +#line 2156 "reflect.h2" [[nodiscard]] auto parse_context::get_pos() const& -> auto { return pos; } -#line 2153 "reflect.h2" +#line 2157 "reflect.h2" [[nodiscard]] auto parse_context::get_range(cpp2::impl::in start, cpp2::impl::in end) const& -> auto { return std::string(regex.substr(start, end - start + 1)); } -#line 2154 "reflect.h2" +#line 2158 "reflect.h2" [[nodiscard]] auto parse_context::valid() const& -> bool{return has_next() && !(has_error); } -#line 2156 "reflect.h2" +#line 2160 "reflect.h2" [[nodiscard]] auto parse_context::error(cpp2::impl::in err) & -> token_ptr{ has_error = true; error_out("Error during parsing of regex '" + cpp2::to_string(regex) + "' at position '" + cpp2::to_string(pos) + "': " + cpp2::to_string(err) + ""); return nullptr; } -#line 2171 "reflect.h2" +#line 2175 "reflect.h2" auto generation_function_context::add_tabs(cpp2::impl::in c) & -> void{ int i {0}; for( ; cpp2::impl::cmp_less(i,c); i += 1 ) { @@ -3842,7 +3862,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2178 "reflect.h2" +#line 2182 "reflect.h2" auto generation_function_context::remove_tabs(cpp2::impl::in c) & -> void{ tabs = tabs.substr(0, (cpp2::impl::as_(c)) * 2); } @@ -3852,22 +3872,22 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} , tabs{ tabs_ }{} generation_function_context::generation_function_context(){} -#line 2196 "reflect.h2" +#line 2200 "reflect.h2" [[nodiscard]] auto generation_context::match_parameters() const& -> std::string{return "r.pos, ctx"; } -#line 2201 "reflect.h2" +#line 2205 "reflect.h2" auto generation_context::add(cpp2::impl::in s) & -> void{ auto cur {get_current()}; (*cpp2::impl::assert_not_null(cur)).code += "" + cpp2::to_string((*cpp2::impl::assert_not_null(cur)).tabs) + cpp2::to_string(s) + "\n"; } -#line 2207 "reflect.h2" +#line 2211 "reflect.h2" auto generation_context::add_check(cpp2::impl::in check) & -> void{ auto cur {get_current()}; (*cpp2::impl::assert_not_null(cur)).code += "" + cpp2::to_string((*cpp2::impl::assert_not_null(cur)).tabs) + "if !cpp2::regex::" + cpp2::to_string(check) + " { r.matched = false; break; }\n"; } -#line 2213 "reflect.h2" +#line 2217 "reflect.h2" auto generation_context::add_statefull(cpp2::impl::in next_func, cpp2::impl::in check) & -> void { end_func_statefull(check); @@ -3876,7 +3896,7 @@ generation_function_context::generation_function_context(){} start_func_named(cpp2::move(name)); } -#line 2221 "reflect.h2" +#line 2225 "reflect.h2" auto generation_context::start_func_named(cpp2::impl::in name) & -> void { auto cur {new_context()}; @@ -3888,7 +3908,7 @@ generation_function_context::generation_function_context(){} (*cpp2::impl::assert_not_null(cpp2::move(cur))).add_tabs(3); } -#line 2232 "reflect.h2" +#line 2236 "reflect.h2" [[nodiscard]] auto generation_context::start_func() & -> std::string { auto name {gen_func_name()}; @@ -3896,7 +3916,7 @@ generation_function_context::generation_function_context(){} return cpp2::move(name) + "()"; } -#line 2239 "reflect.h2" +#line 2243 "reflect.h2" auto generation_context::end_func_statefull(cpp2::impl::in s) & -> void { auto cur {get_current()}; @@ -3916,7 +3936,7 @@ generation_function_context::generation_function_context(){} finish_context(); } -#line 2259 "reflect.h2" +#line 2263 "reflect.h2" [[nodiscard]] auto generation_context::generate_func(cpp2::impl::in token) & -> std::string { auto name {start_func()}; @@ -3926,7 +3946,7 @@ generation_function_context::generation_function_context(){} return name; } -#line 2269 "reflect.h2" +#line 2273 "reflect.h2" [[nodiscard]] auto generation_context::generate_reset(cpp2::impl::in> groups) & -> std::string { if (groups.empty()) { @@ -3949,33 +3969,33 @@ generation_function_context::generation_function_context(){} return cpp2::move(name) + "()"; } -#line 2293 "reflect.h2" +#line 2297 "reflect.h2" [[nodiscard]] auto generation_context::gen_func_name() & -> std::string{ auto cur_id {matcher_func}; matcher_func += 1; return "func_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2299 "reflect.h2" +#line 2303 "reflect.h2" [[nodiscard]] auto generation_context::next_func_name() & -> std::string{ return gen_func_name() + "()"; } -#line 2303 "reflect.h2" +#line 2307 "reflect.h2" [[nodiscard]] auto generation_context::gen_reset_func_name() & -> std::string{ auto cur_id {reset_func}; reset_func += 1; return "reset_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2309 "reflect.h2" +#line 2313 "reflect.h2" [[nodiscard]] auto generation_context::gen_temp() & -> std::string{ auto cur_id {temp_name}; temp_name += 1; return "tmp_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2317 "reflect.h2" +#line 2321 "reflect.h2" [[nodiscard]] auto generation_context::new_context() & -> generation_function_context*{ gen_stack.push_back(generation_function_context()); auto cur {get_current()}; @@ -3984,7 +4004,7 @@ generation_function_context::generation_function_context(){} return cur; } -#line 2325 "reflect.h2" +#line 2329 "reflect.h2" auto generation_context::finish_context() & -> void{ auto cur {get_current()}; auto base {get_base()}; @@ -3993,22 +4013,22 @@ generation_function_context::generation_function_context(){} gen_stack.pop_back(); } -#line 2335 "reflect.h2" +#line 2339 "reflect.h2" [[nodiscard]] auto generation_context::get_current() & -> generation_function_context*{ return &gen_stack.back(); } -#line 2339 "reflect.h2" +#line 2343 "reflect.h2" [[nodiscard]] auto generation_context::get_base() & -> generation_function_context*{ return &CPP2_ASSERT_IN_BOUNDS_LITERAL(gen_stack, 0); } -#line 2343 "reflect.h2" +#line 2347 "reflect.h2" [[nodiscard]] auto generation_context::get_entry_func() const& -> std::string{ return entry_func; } -#line 2347 "reflect.h2" +#line 2351 "reflect.h2" [[nodiscard]] auto generation_context::create_named_group_lookup(cpp2::impl::in> named_groups) const& -> std::string { std::string res {"get_named_group_index: (name) -> int = {\n"}; @@ -4032,18 +4052,18 @@ generation_function_context::generation_function_context(){} return res; } -#line 2372 "reflect.h2" +#line 2376 "reflect.h2" [[nodiscard]] auto generation_context::run(cpp2::impl::in token) & -> std::string{ entry_func = generate_func(token); return (*cpp2::impl::assert_not_null(get_base())).code; } -#line 2387 "reflect.h2" +#line 2391 "reflect.h2" alternative_token::alternative_token() : regex_token_empty{ "" }{} -#line 2389 "reflect.h2" +#line 2393 "reflect.h2" [[nodiscard]] auto alternative_token::parse(parse_context& ctx) -> token_ptr{ if (ctx.current() != '|') {return nullptr; } @@ -4054,15 +4074,15 @@ generation_function_context::generation_function_context(){} alternative_token::~alternative_token() noexcept{} -#line 2404 "reflect.h2" +#line 2408 "reflect.h2" alternative_token_gen::alternative_token_gen(cpp2::impl::in a) : regex_token{ gen_string(a) } , alternatives{ a }{ -#line 2407 "reflect.h2" +#line 2411 "reflect.h2" } -#line 2409 "reflect.h2" +#line 2413 "reflect.h2" auto alternative_token_gen::generate_code(generation_context& ctx) const -> void { std::string functions {""}; @@ -4080,7 +4100,7 @@ generation_function_context::generation_function_context(){} ctx.add_statefull(next_name, "cpp2::regex::alternative_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ", other, " + cpp2::to_string(next_name) + " " + cpp2::to_string(cpp2::move(functions)) + ")"); } -#line 2426 "reflect.h2" +#line 2430 "reflect.h2" auto alternative_token_gen::add_groups(std::set& groups) const -> void { for ( auto const& cur : alternatives ) { @@ -4088,7 +4108,7 @@ generation_function_context::generation_function_context(){} } } -#line 2433 "reflect.h2" +#line 2437 "reflect.h2" [[nodiscard]] auto alternative_token_gen::gen_string(cpp2::impl::in a) -> std::string { std::string r {""}; @@ -4104,14 +4124,14 @@ generation_function_context::generation_function_context(){} alternative_token_gen::~alternative_token_gen() noexcept{} -#line 2454 "reflect.h2" +#line 2458 "reflect.h2" any_token::any_token(cpp2::impl::in single_line) : regex_token_check{ ".", "any_token_matcher" }{ -#line 2456 "reflect.h2" +#line 2460 "reflect.h2" } -#line 2458 "reflect.h2" +#line 2462 "reflect.h2" [[nodiscard]] auto any_token::parse(parse_context& ctx) -> token_ptr{ if ('.' != ctx.current()) {return nullptr; } @@ -4120,21 +4140,21 @@ generation_function_context::generation_function_context(){} any_token::~any_token() noexcept{} -#line 2475 "reflect.h2" +#line 2479 "reflect.h2" char_token::char_token(cpp2::impl::in t, cpp2::impl::in ignore_case_) : regex_token{ std::string(1, t) } , token{ t } , ignore_case{ ignore_case_ }{ -#line 2479 "reflect.h2" +#line 2483 "reflect.h2" } -#line 2481 "reflect.h2" +#line 2485 "reflect.h2" [[nodiscard]] auto char_token::parse(parse_context& ctx) -> token_ptr{ return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, ctx.current(), ctx.get_modifiers().has(expression_flags::case_insensitive)); } -#line 2485 "reflect.h2" +#line 2489 "reflect.h2" auto char_token::generate_code(generation_context& ctx) const -> void { if (ignore_case) { @@ -4143,14 +4163,14 @@ generation_function_context::generation_function_context(){} { size_t i{0}; -#line 2491 "reflect.h2" +#line 2495 "reflect.h2" for( ; cpp2::impl::cmp_less(i,token.size()); i += 1 ) { CPP2_ASSERT_IN_BOUNDS(lower, i) = string_util::safe_tolower(CPP2_ASSERT_IN_BOUNDS(token, i)); CPP2_ASSERT_IN_BOUNDS(upper, i) = string_util::safe_toupper(CPP2_ASSERT_IN_BOUNDS(token, i)); } } -#line 2496 "reflect.h2" +#line 2500 "reflect.h2" if (upper != lower) { gen_case_insensitive(cpp2::move(lower), cpp2::move(upper), ctx); } @@ -4163,7 +4183,7 @@ size_t i{0}; } } -#line 2508 "reflect.h2" +#line 2512 "reflect.h2" auto char_token::gen_case_insensitive(cpp2::impl::in lower, cpp2::impl::in upper, generation_context& ctx) const& -> void { std::string name {"str_" + cpp2::to_string(ctx.gen_temp()) + ""}; @@ -4185,7 +4205,7 @@ size_t i{0}; ctx.add("else { break; }"); } -#line 2529 "reflect.h2" +#line 2533 "reflect.h2" auto char_token::gen_case_sensitive(generation_context& ctx) const& -> void { std::string name {"str_" + cpp2::to_string(ctx.gen_temp()) + ""}; @@ -4204,7 +4224,7 @@ size_t i{0}; ctx.add("else { break; }"); } -#line 2547 "reflect.h2" +#line 2551 "reflect.h2" [[nodiscard]] auto char_token::add_escapes(std::string str) const& -> std::string { str = string_util::replace_all(str, "\\", "\\\\"); @@ -4220,7 +4240,7 @@ size_t i{0}; return cpp2::move(str); } -#line 2562 "reflect.h2" +#line 2566 "reflect.h2" auto char_token::append(char_token const& that) & -> void{ (*this).token += that.token; (*this).string_rep += that.string_rep; @@ -4228,19 +4248,19 @@ size_t i{0}; char_token::~char_token() noexcept{} -#line 2579 "reflect.h2" +#line 2583 "reflect.h2" class_token::class_token(cpp2::impl::in negate_, cpp2::impl::in case_insensitive_, cpp2::impl::in class_str_, cpp2::impl::in str) : regex_token{ str } , negate{ negate_ } , case_insensitive{ case_insensitive_ } , class_str{ class_str_ } -#line 2580 "reflect.h2" +#line 2584 "reflect.h2" { -#line 2585 "reflect.h2" +#line 2589 "reflect.h2" } -#line 2588 "reflect.h2" +#line 2592 "reflect.h2" [[nodiscard]] auto class_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '[') {return nullptr; } @@ -4366,13 +4386,13 @@ size_t i{0}; ); } -#line 2713 "reflect.h2" +#line 2717 "reflect.h2" auto class_token::generate_code(generation_context& ctx) const -> void { ctx.add_check("class_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ")"); } -#line 2718 "reflect.h2" +#line 2722 "reflect.h2" [[nodiscard]] auto class_token::create_matcher(cpp2::impl::in name, cpp2::impl::in template_arguments) -> std::string { auto sep {", "}; @@ -4383,12 +4403,12 @@ size_t i{0}; class_token::~class_token() noexcept{} -#line 2730 "reflect.h2" +#line 2734 "reflect.h2" [[nodiscard]] auto escape_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } -#line 2735 "reflect.h2" +#line 2739 "reflect.h2" if (std::string::npos == std::string("afenrt^.[]()*{}?+|\\").find(ctx.peek())) { return nullptr; } @@ -4422,7 +4442,7 @@ size_t i{0}; } -#line 2771 "reflect.h2" +#line 2775 "reflect.h2" [[nodiscard]] auto global_group_reset_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'K'))) {return nullptr; } @@ -4431,18 +4451,18 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, "\\K", "ctx..set_group_start(0, r.pos);"); } -#line 2793 "reflect.h2" +#line 2797 "reflect.h2" group_ref_token::group_ref_token(cpp2::impl::in id_, cpp2::impl::in case_insensitive_, cpp2::impl::in str) : regex_token{ str } , id{ id_ } , case_insensitive{ case_insensitive_ } -#line 2794 "reflect.h2" +#line 2798 "reflect.h2" { -#line 2798 "reflect.h2" +#line 2802 "reflect.h2" } -#line 2800 "reflect.h2" +#line 2804 "reflect.h2" [[nodiscard]] auto group_ref_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -4544,14 +4564,14 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, cpp2::move(group_id), ctx.get_modifiers().has(expression_flags::case_insensitive), cpp2::move(str)); } -#line 2901 "reflect.h2" +#line 2905 "reflect.h2" auto group_ref_token::generate_code(generation_context& ctx) const -> void{ ctx.add_check("group_ref_token_matcher(" + cpp2::to_string(ctx.match_parameters()) + ")"); } group_ref_token::~group_ref_token() noexcept{} -#line 2924 "reflect.h2" +#line 2928 "reflect.h2" [[nodiscard]] auto group_token::parse_lookahead(parse_context& ctx, cpp2::impl::in syntax, cpp2::impl::in positive) -> token_ptr { static_cast(ctx.next());// Skip last token defining the syntax @@ -4566,7 +4586,7 @@ size_t i{0}; return r; } -#line 2938 "reflect.h2" +#line 2942 "reflect.h2" [[nodiscard]] auto group_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '(') {return nullptr; } @@ -4704,7 +4724,7 @@ size_t i{0}; } } -#line 3075 "reflect.h2" +#line 3079 "reflect.h2" [[nodiscard]] auto group_token::gen_string(cpp2::impl::in name, cpp2::impl::in name_brackets, cpp2::impl::in has_modifier, cpp2::impl::in modifiers, cpp2::impl::in inner_) -> std::string { std::string start {"("}; @@ -4723,7 +4743,7 @@ size_t i{0}; return cpp2::move(start) + (*cpp2::impl::assert_not_null(inner_)).to_string() + ")"; } -#line 3093 "reflect.h2" +#line 3097 "reflect.h2" auto group_token::generate_code(generation_context& ctx) const -> void { if (-1 != number) { @@ -4744,7 +4764,7 @@ size_t i{0}; } } -#line 3113 "reflect.h2" +#line 3117 "reflect.h2" auto group_token::add_groups(std::set& groups) const -> void { (*cpp2::impl::assert_not_null(inner)).add_groups(groups); @@ -4755,7 +4775,7 @@ size_t i{0}; group_token::~group_token() noexcept{} -#line 3125 "reflect.h2" +#line 3129 "reflect.h2" [[nodiscard]] auto hexadecimal_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'x'))) {return nullptr; } @@ -4794,7 +4814,7 @@ size_t i{0}; return r; } -#line 3166 "reflect.h2" +#line 3170 "reflect.h2" [[nodiscard]] auto line_end_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() == '$' || (ctx.current() == '\\' && ctx.peek() == '$')) { @@ -4812,7 +4832,7 @@ size_t i{0}; }} } -#line 3186 "reflect.h2" +#line 3190 "reflect.h2" [[nodiscard]] auto line_start_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '^' && !((ctx.current() == '\\' && ctx.peek() == 'A'))) {return nullptr; } @@ -4826,29 +4846,29 @@ size_t i{0}; } } -#line 3211 "reflect.h2" +#line 3215 "reflect.h2" lookahead_token::lookahead_token(cpp2::impl::in positive_) : regex_token{ "" } , positive{ positive_ }{ -#line 3213 "reflect.h2" +#line 3217 "reflect.h2" } -#line 3215 "reflect.h2" +#line 3219 "reflect.h2" auto lookahead_token::generate_code(generation_context& ctx) const -> void{ auto inner_name {ctx.generate_func(inner)}; ctx.add_check("lookahead_token_matcher(" + cpp2::to_string(ctx.match_parameters()) + ", " + cpp2::to_string(cpp2::move(inner_name)) + ")"); } -#line 3221 "reflect.h2" +#line 3225 "reflect.h2" auto lookahead_token::add_groups(std::set& groups) const -> void{ (*cpp2::impl::assert_not_null(inner)).add_groups(groups); } lookahead_token::~lookahead_token() noexcept{} -#line 3229 "reflect.h2" +#line 3233 "reflect.h2" [[nodiscard]] auto named_class_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -4874,7 +4894,7 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, "\\" + cpp2::to_string(ctx.current()) + "", "" + cpp2::to_string(cpp2::move(name)) + "::match"); } -#line 3257 "reflect.h2" +#line 3261 "reflect.h2" [[nodiscard]] auto octal_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'o'))) {return nullptr; } @@ -4900,11 +4920,11 @@ size_t i{0}; return r; } -#line 3294 "reflect.h2" +#line 3298 "reflect.h2" range_token::range_token() : regex_token{ "" }{} -#line 3296 "reflect.h2" +#line 3300 "reflect.h2" [[nodiscard]] auto range_token::parse(parse_context& ctx) -> token_ptr { auto r {CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared)}; @@ -4978,7 +4998,7 @@ size_t i{0}; return nullptr; } -#line 3369 "reflect.h2" +#line 3373 "reflect.h2" auto range_token::parse_modifier(parse_context& ctx) & -> void { if (ctx.peek() == '?') { @@ -4991,7 +5011,7 @@ size_t i{0}; }} } -#line 3381 "reflect.h2" +#line 3385 "reflect.h2" [[nodiscard]] auto range_token::gen_mod_string() const& -> std::string { if (kind == range_flags::not_greedy) { @@ -5005,7 +5025,7 @@ size_t i{0}; }} } -#line 3394 "reflect.h2" +#line 3398 "reflect.h2" [[nodiscard]] auto range_token::gen_range_string() const& -> std::string { std::string r {""}; @@ -5025,7 +5045,7 @@ size_t i{0}; return r; } -#line 3413 "reflect.h2" +#line 3417 "reflect.h2" auto range_token::generate_code(generation_context& ctx) const -> void { auto inner_name {ctx.generate_func(inner_token)}; @@ -5037,14 +5057,14 @@ size_t i{0}; ctx.add_statefull(next_name, "cpp2::regex::range_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ", " + cpp2::to_string(cpp2::move(inner_name)) + ", " + cpp2::to_string(cpp2::move(reset_name)) + ", other, " + cpp2::to_string(next_name) + ")"); } -#line 3424 "reflect.h2" +#line 3428 "reflect.h2" auto range_token::add_groups(std::set& groups) const -> void{ (*cpp2::impl::assert_not_null(inner_token)).add_groups(groups); } range_token::~range_token() noexcept{} -#line 3437 "reflect.h2" +#line 3441 "reflect.h2" [[nodiscard]] auto special_range_token::parse(parse_context& ctx) -> token_ptr { auto r {CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared)}; @@ -5068,7 +5088,7 @@ size_t i{0}; if (!(ctx.has_token())) {return ctx.error("'" + cpp2::to_string(ctx.current()) + "' without previous element."); } -#line 3461 "reflect.h2" +#line 3465 "reflect.h2" (*cpp2::impl::assert_not_null(r)).parse_modifier(ctx); (*cpp2::impl::assert_not_null(r)).inner_token = ctx.pop_token(); @@ -5078,7 +5098,7 @@ size_t i{0}; special_range_token::~special_range_token() noexcept{} -#line 3474 "reflect.h2" +#line 3478 "reflect.h2" [[nodiscard]] auto word_boundary_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -5096,15 +5116,15 @@ size_t i{0}; }} } -#line 3510 "reflect.h2" +#line 3514 "reflect.h2" template regex_generator::regex_generator(cpp2::impl::in r, Error_out const& e) : regex{ r } , error_out{ e }{ -#line 3513 "reflect.h2" +#line 3517 "reflect.h2" } -#line 3515 "reflect.h2" +#line 3519 "reflect.h2" template [[nodiscard]] auto regex_generator::parse() & -> std::string { // Extract modifiers and adapt regex. @@ -5140,7 +5160,7 @@ size_t i{0}; return source; } -#line 3550 "reflect.h2" +#line 3554 "reflect.h2" template auto regex_generator::extract_modifiers() & -> void { if (regex.find_first_of("'/") == 0) { @@ -5156,7 +5176,7 @@ size_t i{0}; } } -#line 3566 "reflect.h2" +#line 3570 "reflect.h2" template [[nodiscard]] auto generate_regex(cpp2::impl::in regex, Err const& err) -> std::string { regex_generator parser {regex, err}; @@ -5165,7 +5185,7 @@ template [[nodiscard]] auto generate_regex(cpp2::impl::in void { auto has_default {false}; @@ -5220,7 +5240,7 @@ auto regex_gen(meta::type_declaration& t) -> void CPP2_UFCS(add_runtime_support_include)(t, "cpp2regex.h"); } -#line 3635 "reflect.h2" +#line 3639 "reflect.h2" [[nodiscard]] auto apply_metafunctions( declaration_node& n, type_declaration& rtype, @@ -5312,7 +5332,7 @@ auto regex_gen(meta::type_declaration& t) -> void regex_gen(rtype); } else { - error("unrecognized metafunction name: " + name); + error("unrecognized metafunction name: '" + name + "' for type declaration"); error( "(temporary alpha limitation) currently the supported names are: " "interface, polymorphic_base, ordered, weakly_ordered, partially_ordered, " @@ -5335,7 +5355,57 @@ auto regex_gen(meta::type_declaration& t) -> void return true; } -#line 3750 "reflect.h2" +#line 3758 "reflect.h2" +[[nodiscard]] auto apply_metafunctions( + declaration_node& n, + function_declaration& rfunc, + auto const& error + ) -> bool + +{ + if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(is_function)(n)) ) { cpp2::cpp2_default.report_violation(""); } + + // For each metafunction, apply it + for ( + auto const& meta : n.metafunctions ) + { + // Convert the name and any template arguments to strings + // and record that in rfunc + auto name {CPP2_UFCS(to_string)((*cpp2::impl::assert_not_null(meta)))}; + name = CPP2_UFCS(substr)(name, 0, CPP2_UFCS(find)(name, '<')); + + std::vector args {}; + for ( + auto const& arg : CPP2_UFCS(template_arguments)((*cpp2::impl::assert_not_null(meta))) ) + CPP2_UFCS(push_back)(args, CPP2_UFCS(to_string)(arg)); + + CPP2_UFCS(set_metafunction_name)(rfunc, name, args); + + // Dispatch + // + if (name == "print") { + print(rfunc); + } + else { + error("unrecognized metafunction name '" + name + "' for function declaration"); + error("(temporary alpha limitation) currently the supported names are: print"); + return false; + } + + if (( + !(CPP2_UFCS(empty)(args)) + && !(CPP2_UFCS(arguments_were_used)(rfunc)))) + + { + error(name + " did not use its template arguments - did you mean to write '" + name + " <" + CPP2_ASSERT_IN_BOUNDS_LITERAL(cpp2::move(args), 0) + "> ()' (with the spaces)?"); + return false; + } + } + + return true; +} + +#line 3808 "reflect.h2" } } diff --git a/source/reflect.h2 b/source/reflect.h2 index e9830f4f8..1de380dc5 100644 --- a/source/reflect.h2 +++ b/source/reflect.h2 @@ -1501,13 +1501,17 @@ union: (inout t : meta::type_declaration) //----------------------------------------------------------------------- // -// print - output a pretty-printed visualization of t +// print - output a pretty-printed visualization of t or f // print: (t: meta::type_declaration) = { std::cout << t.print() << "\n"; } +print: (f: meta::function_declaration) = +{ + std::cout << f.print() << "\n"; +} //----------------------------------------------------------------------- // @@ -3630,7 +3634,7 @@ regex_gen: (inout t: meta::type_declaration) = //----------------------------------------------------------------------- // -// apply_metafunctions +// apply_metafunctions - for types // apply_metafunctions: ( inout n : declaration_node, @@ -3723,7 +3727,7 @@ apply_metafunctions: ( regex_gen( rtype ); } else { - error( "unrecognized metafunction name: " + name ); + error( "unrecognized metafunction name: '" + name + "' for type declaration" ); error( "(temporary alpha limitation) currently the supported names are: " "interface, polymorphic_base, ordered, weakly_ordered, partially_ordered, " @@ -3747,6 +3751,60 @@ apply_metafunctions: ( } +//----------------------------------------------------------------------- +// +// apply_metafunctions - for functions +// +apply_metafunctions: ( + inout n : declaration_node, + inout rfunc : function_declaration, + error + ) + -> bool += { + assert( n.is_function() ); + + // For each metafunction, apply it + for n.metafunctions + do (meta) + { + // Convert the name and any template arguments to strings + // and record that in rfunc + name := meta*.to_string(); + name = name.substr(0, name.find('<')); + + args: std::vector = (); + for meta*.template_arguments() + do (arg) + args.push_back( arg.to_string() ); + + rfunc.set_metafunction_name( name, args ); + + // Dispatch + // + if name == "print" { + print( rfunc ); + } + else { + error( "unrecognized metafunction name '" + name + "' for function declaration" ); + error( "(temporary alpha limitation) currently the supported names are: print" ); + return false; + } + + if ( + !args.empty() + && !rfunc.arguments_were_used() + ) + { + error( name + " did not use its template arguments - did you mean to write '" + name + " <" + args[0] + "> ()' (with the spaces)?"); + return false; + } + } + + return true; +} + + } } diff --git a/source/sema.h b/source/sema.h index 08f1690e7..1060ec64e 100644 --- a/source/sema.h +++ b/source/sema.h @@ -39,6 +39,22 @@ auto parser::apply_type_metafunctions( declaration_node& n ) ); } +auto parser::apply_function_metafunctions( declaration_node& n ) + -> bool +{ + assert(n.is_function()); + + // Get the reflection state ready to pass to the function + auto cs = meta::compiler_services{ &errors, &includes, generated_tokens }; + auto rfunc = meta::function_declaration{ &n, cs }; + + return apply_metafunctions( + n, + rfunc, + [&](std::string const& msg) { error( msg, false ); } + ); +} + //----------------------------------------------------------------------- // From a45a3abf525dd70f298d6ca289a9823cc28ee348 Mon Sep 17 00:00:00 2001 From: Dylam De La Torre Date: Sat, 23 Mar 2024 20:30:07 +0100 Subject: [PATCH 2/9] Add ability for metafunctions to generate non-member declarations Co-authored-by: Max Sagebaum --- source/parse.h | 82 ++- source/reflect.h | 1315 +++++++++++++++++++++++---------------------- source/reflect.h2 | 96 +++- source/sema.h | 4 +- 4 files changed, 831 insertions(+), 666 deletions(-) diff --git a/source/parse.h b/source/parse.h index b9b19cd5e..3c3ed7564 100644 --- a/source/parse.h +++ b/source/parse.h @@ -5616,6 +5616,11 @@ class parser int pos = 0; std::string parse_kind = {}; + // Keep declarations generated by a metafunction - to be appended to + // translation unit after the metafunction invocations for a given + // declaration have been finished + std::vector> generated_declarations = {}; + // Keep track of the function bodies' locations - used to emit comments // in the right pass (decide whether it's a comment that belongs with // the declaration or is part of the definition) @@ -5754,24 +5759,56 @@ class parser // // Each call parses one statement and returns its parse tree. // - auto parse_one_declaration( + auto parse_one_statement( std::vector const& tokens_, stable_vector& generated_tokens_ ) -> std::unique_ptr { - parse_kind = "source string during code generation"; + prepare_parse_one(tokens_, generated_tokens_); + + try { + // Parse one statement - we succeed if the parse succeeded, + // and there were no new errors, and all tokens were consumed + auto errors_size = std::ssize(errors); + if (auto d = statement(); + d + && std::ssize(errors) == errors_size + && done() + ) + { + return d; + } + } + catch(std::runtime_error& e) { + error(e.what(), true, {}, true); + } + + return {}; + } - // Set per-parse state for the duration of this call - tokens = &tokens_; - generated_tokens = &generated_tokens_; + + //----------------------------------------------------------------------- + // parse_one_declaration + // + // tokens input tokens for this section of Cpp2 source code + // generated_tokens a shared place to store generated tokens + // + // Each call parses one declaration and returns its parse tree. + // + auto parse_one_declaration( + std::vector const& tokens_, + stable_vector& generated_tokens_ + ) + -> std::unique_ptr + { + prepare_parse_one(tokens_, generated_tokens_); try { // Parse one declaration - we succeed if the parse succeeded, // and there were no new errors, and all tokens were consumed auto errors_size = std::ssize(errors); - pos = 0; - if (auto d = statement(); + if (auto d = declaration(); d && std::ssize(errors) == errors_size && done() @@ -5809,7 +5846,10 @@ class parser if (decl->position().lineno > last_line) { break; } - if (decl->position().lineno >= first_line) { + if (decl->position().lineno >= first_line || + decl->position().lineno < 0 // Generated decl by metafunction + ) + { ret.push_back( decl.get() ); } } @@ -5878,6 +5918,25 @@ class parser return !errors.empty(); } + //----------------------------------------------------------------------- + // Preparation for generated token parsing + // + // tokens input tokens for this section of Cpp2 source code + // generated_tokens a shared place to store generated tokens + // + // Sets per-parse state for the duration of the next parse_one* call. + auto prepare_parse_one( + std::vector const& tokens_, + stable_vector& generated_tokens_ + ) + -> void + { + parse_kind = "source string during code generation"; + tokens = &tokens_; + generated_tokens = &generated_tokens_; + pos = 0; + } + //----------------------------------------------------------------------- // Token navigation: Only these functions should access this->token_ @@ -9543,6 +9602,13 @@ class parser auto n = std::make_unique(); for (auto d = declaration(); d; d = declaration()) { n->declarations.push_back( std::move(d) ); + + // Add declarations generated by metafunctions + for(auto& gd : generated_declarations) { + n->declarations.push_back( std::move(gd) ); + } + + generated_declarations.clear(); } return n; } diff --git a/source/reflect.h b/source/reflect.h index 303b138ef..6c4c87972 100644 --- a/source/reflect.h +++ b/source/reflect.h @@ -18,95 +18,95 @@ namespace meta { #line 34 "reflect.h2" class compiler_services; -#line 233 "reflect.h2" +#line 273 "reflect.h2" class declaration_base; -#line 259 "reflect.h2" +#line 299 "reflect.h2" class declaration; -#line 341 "reflect.h2" +#line 381 "reflect.h2" class function_declaration; -#line 431 "reflect.h2" +#line 471 "reflect.h2" class object_declaration; -#line 467 "reflect.h2" +#line 507 "reflect.h2" class type_declaration; -#line 604 "reflect.h2" +#line 644 "reflect.h2" class alias_declaration; -#line 1012 "reflect.h2" +#line 1052 "reflect.h2" class value_member_info; -#line 1534 "reflect.h2" +#line 1574 "reflect.h2" class expression_flags; -#line 1550 "reflect.h2" +#line 1590 "reflect.h2" class regex_token; -#line 1576 "reflect.h2" +#line 1616 "reflect.h2" class regex_token_check; -#line 1595 "reflect.h2" +#line 1635 "reflect.h2" class regex_token_code; -#line 1614 "reflect.h2" +#line 1654 "reflect.h2" class regex_token_empty; -#line 1630 "reflect.h2" +#line 1670 "reflect.h2" class regex_token_list; -#line 1669 "reflect.h2" +#line 1709 "reflect.h2" class parse_context_group_state; -#line 1730 "reflect.h2" +#line 1770 "reflect.h2" class parse_context_branch_reset_state; -#line 1773 "reflect.h2" +#line 1813 "reflect.h2" class parse_context; -#line 2171 "reflect.h2" +#line 2211 "reflect.h2" class generation_function_context; -#line 2189 "reflect.h2" +#line 2229 "reflect.h2" class generation_context; -#line 2387 "reflect.h2" +#line 2427 "reflect.h2" class alternative_token; -#line 2402 "reflect.h2" +#line 2442 "reflect.h2" class alternative_token_gen; -#line 2454 "reflect.h2" +#line 2494 "reflect.h2" class any_token; -#line 2472 "reflect.h2" +#line 2512 "reflect.h2" class char_token; -#line 2575 "reflect.h2" +#line 2615 "reflect.h2" class class_token; -#line 2790 "reflect.h2" +#line 2830 "reflect.h2" class group_ref_token; -#line 2921 "reflect.h2" +#line 2961 "reflect.h2" class group_token; -#line 3208 "reflect.h2" +#line 3248 "reflect.h2" class lookahead_token; -#line 3289 "reflect.h2" +#line 3329 "reflect.h2" class range_token; -#line 3437 "reflect.h2" +#line 3477 "reflect.h2" class special_range_token; -#line 3504 "reflect.h2" +#line 3544 "reflect.h2" template class regex_generator; -#line 3808 "reflect.h2" +#line 3848 "reflect.h2" } } @@ -150,72 +150,88 @@ class compiler_services private: std::set* includes; private: int errors_original_size; private: stable_vector* generated_tokens; + private: std::vector>* generated_declarations; private: cpp2::parser parser; private: std::string metafunction_name {}; private: std::vector metafunction_args {}; private: bool metafunctions_used {false}; -#line 49 "reflect.h2" +#line 50 "reflect.h2" public: explicit compiler_services( std::vector* errors_, std::set* includes_, - stable_vector* generated_tokens_ + stable_vector* generated_tokens_, + std::vector>* generated_declarations_ ); -#line 65 "reflect.h2" +#line 68 "reflect.h2" public: auto set_metafunction_name(cpp2::impl::in name, cpp2::impl::in> args) & -> void; -#line 71 "reflect.h2" +#line 74 "reflect.h2" public: [[nodiscard]] auto get_metafunction_name() const& -> std::string_view; public: [[nodiscard]] auto get_argument(cpp2::impl::in index) & -> std::string; -#line 81 "reflect.h2" +#line 84 "reflect.h2" public: [[nodiscard]] auto get_arguments() & -> std::vector; -#line 86 "reflect.h2" +#line 89 "reflect.h2" public: [[nodiscard]] auto arguments_were_used() const& -> bool; + + private: [[nodiscard]] auto lex_multiline( + + std::string_view source + ) & -> tokens*; using parse_statement_ret = std::unique_ptr; -#line 88 "reflect.h2" +#line 132 "reflect.h2" protected: [[nodiscard]] auto parse_statement( std::string_view source ) & -> parse_statement_ret; -#line 141 "reflect.h2" +#line 152 "reflect.h2" public: auto add_runtime_support_include(cpp2::impl::in s) & -> void; + protected: [[nodiscard]] auto parse_and_add_declaration( + + std::string_view source + ) & -> bool; + +#line 176 "reflect.h2" public: [[nodiscard]] virtual auto position() const -> source_position; -#line 152 "reflect.h2" +#line 185 "reflect.h2" public: auto require( cpp2::impl::in b, cpp2::impl::in msg ) const& -> void; -#line 163 "reflect.h2" +#line 196 "reflect.h2" public: auto error(cpp2::impl::in msg) const& -> void; -#line 175 "reflect.h2" +#line 208 "reflect.h2" public: auto report_violation(auto const& msg) const& -> void; -#line 183 "reflect.h2" +#line 216 "reflect.h2" public: [[nodiscard]] auto is_active() const& -> auto; + + public: auto append_declaration_to_translation_unit(cpp2::impl::in source) & -> void; public: virtual ~compiler_services() noexcept; public: compiler_services(compiler_services const& that); -#line 184 "reflect.h2" + +#line 224 "reflect.h2" }; -#line 233 "reflect.h2" +#line 273 "reflect.h2" class declaration_base : public compiler_services { -#line 237 "reflect.h2" +#line 277 "reflect.h2" protected: declaration_node* n; protected: explicit declaration_base( @@ -224,28 +240,28 @@ class declaration_base cpp2::impl::in s ); -#line 250 "reflect.h2" +#line 290 "reflect.h2" public: [[nodiscard]] auto position() const -> source_position override; public: [[nodiscard]] auto print() const& -> std::string; public: virtual ~declaration_base() noexcept; public: declaration_base(declaration_base const& that); -#line 253 "reflect.h2" +#line 293 "reflect.h2" }; -#line 259 "reflect.h2" +#line 299 "reflect.h2" class declaration : public declaration_base { -#line 263 "reflect.h2" +#line 303 "reflect.h2" public: explicit declaration( declaration_node* n_, cpp2::impl::in s ); -#line 272 "reflect.h2" +#line 312 "reflect.h2" public: [[nodiscard]] auto is_public() const& -> bool; public: [[nodiscard]] auto is_protected() const& -> bool; public: [[nodiscard]] auto is_private() const& -> bool; @@ -264,7 +280,7 @@ class declaration public: [[nodiscard]] auto name() const& -> std::string_view; -#line 293 "reflect.h2" +#line 333 "reflect.h2" public: [[nodiscard]] auto has_initializer() const& -> bool; public: [[nodiscard]] auto is_global() const& -> bool; @@ -306,21 +322,21 @@ class declaration public: declaration(declaration const& that); -#line 335 "reflect.h2" +#line 375 "reflect.h2" }; -#line 341 "reflect.h2" +#line 381 "reflect.h2" class function_declaration : public declaration { -#line 345 "reflect.h2" +#line 385 "reflect.h2" public: explicit function_declaration( declaration_node* n_, cpp2::impl::in s ); -#line 355 "reflect.h2" +#line 395 "reflect.h2" public: [[nodiscard]] auto index_of_parameter_named(cpp2::impl::in s) const& -> int; public: [[nodiscard]] auto has_parameter_named(cpp2::impl::in s) const& -> bool; public: [[nodiscard]] auto has_in_parameter_named(cpp2::impl::in s) const& -> bool; @@ -360,7 +376,7 @@ class function_declaration public: [[nodiscard]] auto get_parameters() const& -> std::vector; -#line 402 "reflect.h2" +#line 442 "reflect.h2" public: [[nodiscard]] auto is_binary_comparison_function() const& -> bool; public: auto default_to_virtual() & -> void; @@ -371,94 +387,94 @@ class function_declaration public: function_declaration(function_declaration const& that); -#line 425 "reflect.h2" +#line 465 "reflect.h2" }; -#line 431 "reflect.h2" +#line 471 "reflect.h2" class object_declaration : public declaration { -#line 435 "reflect.h2" +#line 475 "reflect.h2" public: explicit object_declaration( declaration_node* n_, cpp2::impl::in s ); -#line 445 "reflect.h2" +#line 485 "reflect.h2" public: [[nodiscard]] auto is_const() const& -> bool; public: [[nodiscard]] auto has_wildcard_type() const& -> bool; public: [[nodiscard]] auto type() const& -> std::string; -#line 455 "reflect.h2" +#line 495 "reflect.h2" public: [[nodiscard]] auto initializer() const& -> std::string; public: object_declaration(object_declaration const& that); -#line 461 "reflect.h2" +#line 501 "reflect.h2" }; -#line 467 "reflect.h2" +#line 507 "reflect.h2" class type_declaration : public declaration { -#line 471 "reflect.h2" +#line 511 "reflect.h2" public: explicit type_declaration( declaration_node* n_, cpp2::impl::in s ); -#line 481 "reflect.h2" +#line 521 "reflect.h2" public: auto reserve_names(cpp2::impl::in name, auto&& ...etc) const& -> void; -#line 495 "reflect.h2" +#line 535 "reflect.h2" public: [[nodiscard]] auto is_polymorphic() const& -> bool; public: [[nodiscard]] auto is_final() const& -> bool; public: [[nodiscard]] auto make_final() & -> bool; public: [[nodiscard]] auto get_member_functions() const& -> std::vector; -#line 510 "reflect.h2" +#line 550 "reflect.h2" public: [[nodiscard]] auto get_member_functions_needing_initializer() const& -> std::vector; -#line 525 "reflect.h2" +#line 565 "reflect.h2" public: [[nodiscard]] auto get_member_objects() const& -> std::vector; -#line 535 "reflect.h2" +#line 575 "reflect.h2" public: [[nodiscard]] auto get_member_types() const& -> std::vector; -#line 545 "reflect.h2" +#line 585 "reflect.h2" public: [[nodiscard]] auto get_member_aliases() const& -> std::vector; -#line 555 "reflect.h2" +#line 595 "reflect.h2" public: [[nodiscard]] auto get_members() const& -> std::vector; struct query_declared_value_set_functions_ret { bool out_this_in_that; bool out_this_move_that; bool inout_this_in_that; bool inout_this_move_that; }; -#line 565 "reflect.h2" +#line 605 "reflect.h2" public: [[nodiscard]] auto query_declared_value_set_functions() const& -> query_declared_value_set_functions_ret; -#line 580 "reflect.h2" +#line 620 "reflect.h2" public: auto add_member(cpp2::impl::in source) & -> void; -#line 594 "reflect.h2" +#line 634 "reflect.h2" public: auto remove_marked_members() & -> void; public: auto remove_all_members() & -> void; public: auto disable_member_function_generation() & -> void; public: type_declaration(type_declaration const& that); -#line 598 "reflect.h2" +#line 638 "reflect.h2" }; -#line 604 "reflect.h2" +#line 644 "reflect.h2" class alias_declaration : public declaration { -#line 608 "reflect.h2" +#line 648 "reflect.h2" public: explicit alias_declaration( declaration_node* n_, @@ -467,62 +483,62 @@ class alias_declaration public: alias_declaration(alias_declaration const& that); -#line 617 "reflect.h2" +#line 657 "reflect.h2" }; -#line 632 "reflect.h2" +#line 672 "reflect.h2" auto add_virtual_destructor(meta::type_declaration& t) -> void; -#line 650 "reflect.h2" +#line 690 "reflect.h2" auto interface(meta::type_declaration& t) -> void; -#line 696 "reflect.h2" +#line 736 "reflect.h2" auto polymorphic_base(meta::type_declaration& t) -> void; -#line 741 "reflect.h2" +#line 781 "reflect.h2" auto ordered_impl( meta::type_declaration& t, cpp2::impl::in ordering ) -> void; -#line 770 "reflect.h2" +#line 810 "reflect.h2" auto ordered(meta::type_declaration& t) -> void; -#line 778 "reflect.h2" +#line 818 "reflect.h2" auto weakly_ordered(meta::type_declaration& t) -> void; -#line 786 "reflect.h2" +#line 826 "reflect.h2" auto partially_ordered(meta::type_declaration& t) -> void; -#line 808 "reflect.h2" +#line 848 "reflect.h2" auto copyable(meta::type_declaration& t) -> void; -#line 842 "reflect.h2" +#line 882 "reflect.h2" auto basic_value(meta::type_declaration& t) -> void; -#line 870 "reflect.h2" +#line 910 "reflect.h2" auto value(meta::type_declaration& t) -> void; -#line 876 "reflect.h2" +#line 916 "reflect.h2" auto weakly_ordered_value(meta::type_declaration& t) -> void; -#line 882 "reflect.h2" +#line 922 "reflect.h2" auto partially_ordered_value(meta::type_declaration& t) -> void; -#line 911 "reflect.h2" +#line 951 "reflect.h2" auto cpp1_rule_of_zero(meta::type_declaration& t) -> void; -#line 948 "reflect.h2" +#line 988 "reflect.h2" auto cpp2_struct(meta::type_declaration& t) -> void; -#line 1012 "reflect.h2" +#line 1052 "reflect.h2" class value_member_info { public: std::string name; public: std::string type; public: std::string value; public: value_member_info(auto const& name_, auto const& type_, auto const& value_); -#line 1016 "reflect.h2" +#line 1056 "reflect.h2" }; auto basic_enum( @@ -531,25 +547,25 @@ auto basic_enum( cpp2::impl::in bitwise ) -> void; -#line 1282 "reflect.h2" +#line 1322 "reflect.h2" auto cpp2_enum(meta::type_declaration& t) -> void; -#line 1309 "reflect.h2" +#line 1349 "reflect.h2" auto flag_enum(meta::type_declaration& t) -> void; -#line 1355 "reflect.h2" +#line 1395 "reflect.h2" auto cpp2_union(meta::type_declaration& t) -> void; -#line 1506 "reflect.h2" +#line 1546 "reflect.h2" auto print(cpp2::impl::in t) -> void; -#line 1511 "reflect.h2" +#line 1551 "reflect.h2" auto print(cpp2::impl::in f) -> void; -#line 1530 "reflect.h2" +#line 1570 "reflect.h2" using error_func = std::function x)>; -#line 1534 "reflect.h2" +#line 1574 "reflect.h2" class expression_flags { private: cpp2::u8 _value; private: constexpr expression_flags(cpp2::impl::in _val); @@ -584,20 +600,20 @@ public: [[nodiscard]] auto to_code() const& -> std::string; public: [[nodiscard]] static auto from_string(cpp2::impl::in s) -> expression_flags; public: [[nodiscard]] static auto from_code(cpp2::impl::in s) -> expression_flags; -#line 1542 "reflect.h2" +#line 1582 "reflect.h2" }; -#line 1550 "reflect.h2" +#line 1590 "reflect.h2" class regex_token { public: std::string string_rep; public: explicit regex_token(cpp2::impl::in str); -#line 1558 "reflect.h2" +#line 1598 "reflect.h2" public: explicit regex_token(); -#line 1563 "reflect.h2" +#line 1603 "reflect.h2" public: virtual auto generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void = 0; public: virtual auto add_groups([[maybe_unused]] std::set& unnamed_param_2) const -> void; @@ -608,24 +624,24 @@ class regex_token public: regex_token(regex_token const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(regex_token const&) -> void = delete; -#line 1568 "reflect.h2" +#line 1608 "reflect.h2" }; using token_ptr = std::shared_ptr; using token_vec = std::vector; -#line 1574 "reflect.h2" +#line 1614 "reflect.h2" // Adds a check in code generation. // class regex_token_check : public regex_token { -#line 1580 "reflect.h2" +#line 1620 "reflect.h2" private: std::string check; public: explicit regex_token_check(cpp2::impl::in str, cpp2::impl::in check_); -#line 1587 "reflect.h2" +#line 1627 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~regex_token_check() noexcept; @@ -633,21 +649,21 @@ class regex_token_check public: auto operator=(regex_token_check const&) -> void = delete; -#line 1590 "reflect.h2" +#line 1630 "reflect.h2" }; -#line 1593 "reflect.h2" +#line 1633 "reflect.h2" // Adds code in code generation. // class regex_token_code : public regex_token { -#line 1599 "reflect.h2" +#line 1639 "reflect.h2" private: std::string code; public: explicit regex_token_code(cpp2::impl::in str, cpp2::impl::in code_); -#line 1606 "reflect.h2" +#line 1646 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~regex_token_code() noexcept; @@ -655,19 +671,19 @@ class regex_token_code public: auto operator=(regex_token_code const&) -> void = delete; -#line 1609 "reflect.h2" +#line 1649 "reflect.h2" }; -#line 1612 "reflect.h2" +#line 1652 "reflect.h2" // Token that does not influence the matching. E.g. comment. // class regex_token_empty : public regex_token { -#line 1618 "reflect.h2" +#line 1658 "reflect.h2" public: explicit regex_token_empty(cpp2::impl::in str); -#line 1622 "reflect.h2" +#line 1662 "reflect.h2" public: auto generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void override; public: virtual ~regex_token_empty() noexcept; @@ -675,27 +691,27 @@ class regex_token_empty public: auto operator=(regex_token_empty const&) -> void = delete; -#line 1625 "reflect.h2" +#line 1665 "reflect.h2" }; -#line 1628 "reflect.h2" +#line 1668 "reflect.h2" // Represents a list of regex tokens as one token. // class regex_token_list : public regex_token { -#line 1634 "reflect.h2" +#line 1674 "reflect.h2" public: token_vec tokens; public: explicit regex_token_list(cpp2::impl::in t); -#line 1641 "reflect.h2" +#line 1681 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 1647 "reflect.h2" +#line 1687 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; -#line 1653 "reflect.h2" +#line 1693 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in vec) -> std::string; public: virtual ~regex_token_list() noexcept; @@ -703,10 +719,10 @@ class regex_token_list public: auto operator=(regex_token_list const&) -> void = delete; -#line 1660 "reflect.h2" +#line 1700 "reflect.h2" }; -#line 1663 "reflect.h2" +#line 1703 "reflect.h2" // // Parse and generation context. // @@ -722,33 +738,33 @@ class parse_context_group_state // Start a new alternative. public: auto next_alternative() & -> void; -#line 1683 "reflect.h2" +#line 1723 "reflect.h2" // Swap this state with the other one. public: auto swap(parse_context_group_state& t) & -> void; -#line 1690 "reflect.h2" +#line 1730 "reflect.h2" // Convert this state into a regex token. public: [[nodiscard]] auto get_as_token() & -> token_ptr; -#line 1702 "reflect.h2" +#line 1742 "reflect.h2" // Add a token to the current matcher list. public: auto add(cpp2::impl::in token) & -> void; -#line 1707 "reflect.h2" +#line 1747 "reflect.h2" // True if current matcher list is empty. public: [[nodiscard]] auto empty() const& -> bool; -#line 1711 "reflect.h2" +#line 1751 "reflect.h2" // Apply optimizations to the matcher list. public: static auto post_process_list(token_vec& list) -> void; public: parse_context_group_state(auto const& cur_match_list_, auto const& alternate_match_lists_, auto const& modifiers_); public: parse_context_group_state(); -#line 1725 "reflect.h2" +#line 1765 "reflect.h2" }; -#line 1728 "reflect.h2" +#line 1768 "reflect.h2" // State for the branch reset. Takes care of the group numbering. See '(|)'. // class parse_context_branch_reset_state @@ -761,25 +777,25 @@ class parse_context_branch_reset_state // Next group identifier. public: [[nodiscard]] auto next() & -> int; -#line 1746 "reflect.h2" +#line 1786 "reflect.h2" // Set next group identifier. public: auto set_next(cpp2::impl::in g) & -> void; -#line 1752 "reflect.h2" +#line 1792 "reflect.h2" // Start a new alternative branch. public: auto next_alternative() & -> void; -#line 1759 "reflect.h2" +#line 1799 "reflect.h2" // Initialize for a branch reset group. public: auto set_active_reset(cpp2::impl::in restart) & -> void; public: parse_context_branch_reset_state(auto const& is_active_, auto const& cur_group_, auto const& max_group_, auto const& from_); public: parse_context_branch_reset_state(); -#line 1766 "reflect.h2" +#line 1806 "reflect.h2" }; -#line 1769 "reflect.h2" +#line 1809 "reflect.h2" // Context during parsing of the regular expressions. // // Keeps track of the distributed group identifiers, current parsed group and branch resets. @@ -793,7 +809,7 @@ class parse_context private: parse_context_group_state cur_group_state {}; private: parse_context_branch_reset_state cur_branch_reset_state {}; -#line 1783 "reflect.h2" +#line 1823 "reflect.h2" public: std::map named_groups {}; private: error_func error_out; // TODO: Declaring std::function fails for cpp2. @@ -801,64 +817,64 @@ class parse_context public: explicit parse_context(cpp2::impl::in r, auto const& e); -#line 1794 "reflect.h2" +#line 1834 "reflect.h2" // State management functions // // Returned group state needs to be stored and provided in `end_group`. public: [[nodiscard]] auto start_group() & -> parse_context_group_state; -#line 1807 "reflect.h2" +#line 1847 "reflect.h2" // `old_state` argument needs to be from start group. public: [[nodiscard]] auto end_group(cpp2::impl::in old_state) & -> token_ptr; -#line 1815 "reflect.h2" +#line 1855 "reflect.h2" public: [[nodiscard]] auto get_modifiers() const& -> expression_flags; -#line 1819 "reflect.h2" +#line 1859 "reflect.h2" public: auto set_modifiers(cpp2::impl::in mod) & -> void; -#line 1823 "reflect.h2" +#line 1863 "reflect.h2" // Branch reset management functions // public: [[nodiscard]] auto branch_reset_new_state() & -> parse_context_branch_reset_state; -#line 1835 "reflect.h2" +#line 1875 "reflect.h2" public: auto branch_reset_restore_state(cpp2::impl::in old_state) & -> void; -#line 1842 "reflect.h2" +#line 1882 "reflect.h2" public: auto next_alternative() & -> void; -#line 1848 "reflect.h2" +#line 1888 "reflect.h2" // Regex token management // public: auto add_token(cpp2::impl::in token) & -> void; -#line 1854 "reflect.h2" +#line 1894 "reflect.h2" public: [[nodiscard]] auto has_token() const& -> bool; -#line 1858 "reflect.h2" +#line 1898 "reflect.h2" public: [[nodiscard]] auto pop_token() & -> token_ptr; -#line 1869 "reflect.h2" +#line 1909 "reflect.h2" public: [[nodiscard]] auto get_as_token() & -> token_ptr; -#line 1873 "reflect.h2" +#line 1913 "reflect.h2" // Group management // public: [[nodiscard]] auto get_cur_group() const& -> int; -#line 1879 "reflect.h2" +#line 1919 "reflect.h2" public: [[nodiscard]] auto next_group() & -> int; -#line 1883 "reflect.h2" +#line 1923 "reflect.h2" public: auto set_named_group(cpp2::impl::in name, cpp2::impl::in id) & -> void; -#line 1890 "reflect.h2" +#line 1930 "reflect.h2" public: [[nodiscard]] auto get_named_group(cpp2::impl::in name) const& -> int; -#line 1901 "reflect.h2" +#line 1941 "reflect.h2" // Position management functions // public: [[nodiscard]] auto current() const& -> char; @@ -866,51 +882,51 @@ class parse_context // Get the next token in the regex, skipping spaces according to the parameters. See `x` and `xx` modifiers. private: [[nodiscard]] auto get_next_position(cpp2::impl::in in_class, cpp2::impl::in no_skip) const& -> size_t; -#line 1945 "reflect.h2" +#line 1985 "reflect.h2" // Return true if next token is available. private: [[nodiscard]] auto next_impl(cpp2::impl::in in_class, cpp2::impl::in no_skip) & -> bool; -#line 1957 "reflect.h2" +#line 1997 "reflect.h2" public: [[nodiscard]] auto next() & -> auto; public: [[nodiscard]] auto next_in_class() & -> auto; public: [[nodiscard]] auto next_no_skip() & -> auto; public: [[nodiscard]] auto next_n(cpp2::impl::in n) & -> bool; -#line 1970 "reflect.h2" +#line 2010 "reflect.h2" public: [[nodiscard]] auto has_next() const& -> bool; private: [[nodiscard]] auto grab_until_impl(cpp2::impl::in e, cpp2::impl::out r, cpp2::impl::in any) & -> bool; -#line 1993 "reflect.h2" +#line 2033 "reflect.h2" public: [[nodiscard]] auto grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_until_one_of(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_n(cpp2::impl::in n, cpp2::impl::out r) & -> bool; -#line 2010 "reflect.h2" +#line 2050 "reflect.h2" public: [[nodiscard]] auto grab_number() & -> std::string; -#line 2031 "reflect.h2" +#line 2071 "reflect.h2" private: [[nodiscard]] auto peek_impl(cpp2::impl::in in_class) const& -> char; -#line 2041 "reflect.h2" +#line 2081 "reflect.h2" public: [[nodiscard]] auto peek() const& -> auto; public: [[nodiscard]] auto peek_in_class() const& -> auto; -#line 2045 "reflect.h2" +#line 2085 "reflect.h2" // Parsing functions // public: [[nodiscard]] auto parser_group_modifiers(cpp2::impl::in change_str, expression_flags& parser_modifiers) & -> bool; -#line 2101 "reflect.h2" +#line 2141 "reflect.h2" public: [[nodiscard]] auto parse_until(cpp2::impl::in term) & -> bool; -#line 2139 "reflect.h2" +#line 2179 "reflect.h2" public: [[nodiscard]] auto parse(cpp2::impl::in modifiers) & -> bool; -#line 2154 "reflect.h2" +#line 2194 "reflect.h2" // Misc functions public: [[nodiscard]] auto get_pos() const& -> auto; @@ -922,10 +938,10 @@ class parse_context public: auto operator=(parse_context const&) -> void = delete; -#line 2165 "reflect.h2" +#line 2205 "reflect.h2" }; -#line 2168 "reflect.h2" +#line 2208 "reflect.h2" // Context for one function generation. Generation of functions can be interleaved, // therefore we buffer the code for one function here. // @@ -935,16 +951,16 @@ class generation_function_context { public: auto add_tabs(cpp2::impl::in c) & -> void; -#line 2182 "reflect.h2" +#line 2222 "reflect.h2" public: auto remove_tabs(cpp2::impl::in c) & -> void; public: generation_function_context(auto const& code_, auto const& tabs_); public: generation_function_context(); -#line 2185 "reflect.h2" +#line 2225 "reflect.h2" }; -#line 2188 "reflect.h2" +#line 2228 "reflect.h2" // Context for generating the state machine. class generation_context { @@ -964,68 +980,68 @@ class generation_context // Add code line. public: auto add(cpp2::impl::in s) & -> void; -#line 2210 "reflect.h2" +#line 2250 "reflect.h2" // Add check for token. The check needs to be a function call that returns a boolean. public: auto add_check(cpp2::impl::in check) & -> void; -#line 2216 "reflect.h2" +#line 2256 "reflect.h2" // Add a stateful check. The check needs to return a `match_return`. public: auto add_statefull(cpp2::impl::in next_func, cpp2::impl::in check) & -> void; -#line 2225 "reflect.h2" +#line 2265 "reflect.h2" protected: auto start_func_named(cpp2::impl::in name) & -> void; -#line 2236 "reflect.h2" +#line 2276 "reflect.h2" protected: [[nodiscard]] auto start_func() & -> std::string; -#line 2243 "reflect.h2" +#line 2283 "reflect.h2" protected: auto end_func_statefull(cpp2::impl::in s) & -> void; -#line 2262 "reflect.h2" +#line 2302 "reflect.h2" // Generate the function for a token. public: [[nodiscard]] auto generate_func(cpp2::impl::in token) & -> std::string; -#line 2272 "reflect.h2" +#line 2312 "reflect.h2" // Generate the reset for a list of group identifiers. public: [[nodiscard]] auto generate_reset(cpp2::impl::in> groups) & -> std::string; -#line 2295 "reflect.h2" +#line 2335 "reflect.h2" // Name generation // protected: [[nodiscard]] auto gen_func_name() & -> std::string; -#line 2303 "reflect.h2" +#line 2343 "reflect.h2" public: [[nodiscard]] auto next_func_name() & -> std::string; -#line 2307 "reflect.h2" +#line 2347 "reflect.h2" protected: [[nodiscard]] auto gen_reset_func_name() & -> std::string; -#line 2313 "reflect.h2" +#line 2353 "reflect.h2" public: [[nodiscard]] auto gen_temp() & -> std::string; -#line 2319 "reflect.h2" +#line 2359 "reflect.h2" // Context management // public: [[nodiscard]] auto new_context() & -> generation_function_context*; -#line 2329 "reflect.h2" +#line 2369 "reflect.h2" public: auto finish_context() & -> void; -#line 2337 "reflect.h2" +#line 2377 "reflect.h2" // Misc functions // private: [[nodiscard]] auto get_current() & -> generation_function_context*; -#line 2343 "reflect.h2" +#line 2383 "reflect.h2" private: [[nodiscard]] auto get_base() & -> generation_function_context*; -#line 2347 "reflect.h2" +#line 2387 "reflect.h2" public: [[nodiscard]] auto get_entry_func() const& -> std::string; -#line 2351 "reflect.h2" +#line 2391 "reflect.h2" public: [[nodiscard]] auto create_named_group_lookup(cpp2::impl::in> named_groups) const& -> std::string; -#line 2375 "reflect.h2" +#line 2415 "reflect.h2" // Run the generation for the token. public: [[nodiscard]] auto run(cpp2::impl::in token) & -> std::string; public: generation_context() = default; @@ -1033,7 +1049,7 @@ class generation_context public: auto operator=(generation_context const&) -> void = delete; -#line 2381 "reflect.h2" +#line 2421 "reflect.h2" }; // Regex syntax: | Example: ab|ba @@ -1053,24 +1069,24 @@ class alternative_token public: auto operator=(alternative_token const&) -> void = delete; -#line 2400 "reflect.h2" +#line 2440 "reflect.h2" }; class alternative_token_gen : public regex_token { -#line 2406 "reflect.h2" +#line 2446 "reflect.h2" private: token_vec alternatives; public: explicit alternative_token_gen(cpp2::impl::in a); -#line 2413 "reflect.h2" +#line 2453 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2430 "reflect.h2" +#line 2470 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; -#line 2437 "reflect.h2" +#line 2477 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in a) -> std::string; public: virtual ~alternative_token_gen() noexcept; @@ -1078,19 +1094,19 @@ class alternative_token_gen public: auto operator=(alternative_token_gen const&) -> void = delete; -#line 2449 "reflect.h2" +#line 2489 "reflect.h2" }; -#line 2452 "reflect.h2" +#line 2492 "reflect.h2" // Regex syntax: . // class any_token : public regex_token_check { -#line 2458 "reflect.h2" +#line 2498 "reflect.h2" public: explicit any_token(cpp2::impl::in single_line); -#line 2462 "reflect.h2" +#line 2502 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; public: virtual ~any_token() noexcept; @@ -1098,37 +1114,37 @@ class any_token public: auto operator=(any_token const&) -> void = delete; -#line 2467 "reflect.h2" +#line 2507 "reflect.h2" }; -#line 2470 "reflect.h2" +#line 2510 "reflect.h2" // Regex syntax: a // class char_token : public regex_token { -#line 2476 "reflect.h2" +#line 2516 "reflect.h2" private: std::string token; private: bool ignore_case; public: explicit char_token(cpp2::impl::in t, cpp2::impl::in ignore_case_); -#line 2485 "reflect.h2" +#line 2525 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 2489 "reflect.h2" +#line 2529 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2512 "reflect.h2" +#line 2552 "reflect.h2" public: auto gen_case_insensitive(cpp2::impl::in lower, cpp2::impl::in upper, generation_context& ctx) const& -> void; -#line 2533 "reflect.h2" +#line 2573 "reflect.h2" public: auto gen_case_sensitive(generation_context& ctx) const& -> void; -#line 2551 "reflect.h2" +#line 2591 "reflect.h2" public: [[nodiscard]] auto add_escapes(std::string str) const& -> std::string; -#line 2566 "reflect.h2" +#line 2606 "reflect.h2" public: auto append(char_token const& that) & -> void; public: virtual ~char_token() noexcept; @@ -1136,30 +1152,30 @@ class char_token public: auto operator=(char_token const&) -> void = delete; -#line 2570 "reflect.h2" +#line 2610 "reflect.h2" }; -#line 2573 "reflect.h2" +#line 2613 "reflect.h2" // Regex syntax: [] Example: [abcx-y[:digits:]] // class class_token : public regex_token { -#line 2579 "reflect.h2" +#line 2619 "reflect.h2" private: bool negate; private: bool case_insensitive; private: std::string class_str; public: explicit class_token(cpp2::impl::in negate_, cpp2::impl::in case_insensitive_, cpp2::impl::in class_str_, cpp2::impl::in str); -#line 2591 "reflect.h2" +#line 2631 "reflect.h2" // TODO: Rework class generation: Generate check functions for classes. public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 2717 "reflect.h2" +#line 2757 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2722 "reflect.h2" +#line 2762 "reflect.h2" private: [[nodiscard]] static auto create_matcher(cpp2::impl::in name, cpp2::impl::in template_arguments) -> std::string; public: virtual ~class_token() noexcept; @@ -1167,20 +1183,20 @@ class class_token public: auto operator=(class_token const&) -> void = delete; -#line 2729 "reflect.h2" +#line 2769 "reflect.h2" }; -#line 2732 "reflect.h2" +#line 2772 "reflect.h2" // Regex syntax: \a or \n or \[ // [[nodiscard]] auto escape_token_parse(parse_context& ctx) -> token_ptr; -#line 2773 "reflect.h2" +#line 2813 "reflect.h2" // Regex syntax: \K Example: ab\Kcd // [[nodiscard]] auto global_group_reset_token_parse(parse_context& ctx) -> token_ptr; -#line 2784 "reflect.h2" +#line 2824 "reflect.h2" // Regex syntax: \ Example: \1 // \g{name_or_number} // \k{name_or_number} @@ -1190,16 +1206,16 @@ class class_token class group_ref_token : public regex_token { -#line 2794 "reflect.h2" +#line 2834 "reflect.h2" private: int id; private: bool case_insensitive; public: explicit group_ref_token(cpp2::impl::in id_, cpp2::impl::in case_insensitive_, cpp2::impl::in str); -#line 2804 "reflect.h2" +#line 2844 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 2905 "reflect.h2" +#line 2945 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~group_ref_token() noexcept; @@ -1207,10 +1223,10 @@ class group_ref_token public: auto operator=(group_ref_token const&) -> void = delete; -#line 2908 "reflect.h2" +#line 2948 "reflect.h2" }; -#line 2911 "reflect.h2" +#line 2951 "reflect.h2" // Regex syntax: () Example: (abc) // (?:) (?i:abc) @@ -1224,22 +1240,22 @@ class group_ref_token class group_token : public regex_token { -#line 2925 "reflect.h2" +#line 2965 "reflect.h2" private: int number {-1}; private: token_ptr inner {nullptr}; public: [[nodiscard]] static auto parse_lookahead(parse_context& ctx, cpp2::impl::in syntax, cpp2::impl::in positive) -> token_ptr; -#line 2942 "reflect.h2" +#line 2982 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 3079 "reflect.h2" +#line 3119 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in name, cpp2::impl::in name_brackets, cpp2::impl::in has_modifier, cpp2::impl::in modifiers, cpp2::impl::in inner_) -> std::string; -#line 3097 "reflect.h2" +#line 3137 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3117 "reflect.h2" +#line 3157 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~group_token() noexcept; @@ -1248,25 +1264,25 @@ class group_token public: auto operator=(group_token const&) -> void = delete; -#line 3124 "reflect.h2" +#line 3164 "reflect.h2" }; -#line 3127 "reflect.h2" +#line 3167 "reflect.h2" // Regex syntax: \x or \x{} Example: \x{62} // [[nodiscard]] auto hexadecimal_token_parse(parse_context& ctx) -> token_ptr; -#line 3168 "reflect.h2" +#line 3208 "reflect.h2" // Regex syntax: $ Example: aa$ // [[nodiscard]] auto line_end_token_parse(parse_context& ctx) -> token_ptr; -#line 3188 "reflect.h2" +#line 3228 "reflect.h2" // Regex syntax: ^ Example: ^aa // [[nodiscard]] auto line_start_token_parse(parse_context& ctx) -> token_ptr; -#line 3204 "reflect.h2" +#line 3244 "reflect.h2" // Regex syntax: (?=) or (?!) or (*pla), etc. Example: (?=AA) // // Parsed in group_token. @@ -1274,16 +1290,16 @@ class group_token class lookahead_token : public regex_token { -#line 3212 "reflect.h2" +#line 3252 "reflect.h2" protected: bool positive; public: token_ptr inner {nullptr}; public: explicit lookahead_token(cpp2::impl::in positive_); -#line 3219 "reflect.h2" +#line 3259 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3225 "reflect.h2" +#line 3265 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~lookahead_token() noexcept; @@ -1291,26 +1307,26 @@ class lookahead_token public: auto operator=(lookahead_token const&) -> void = delete; -#line 3228 "reflect.h2" +#line 3268 "reflect.h2" }; -#line 3231 "reflect.h2" +#line 3271 "reflect.h2" // Named character classes // [[nodiscard]] auto named_class_token_parse(parse_context& ctx) -> token_ptr; -#line 3259 "reflect.h2" +#line 3299 "reflect.h2" // Regex syntax: \o{} Example: \o{142} // [[nodiscard]] auto octal_token_parse(parse_context& ctx) -> token_ptr; -#line 3287 "reflect.h2" +#line 3327 "reflect.h2" // Regex syntax: {min, max} Example: a{2,4} // class range_token : public regex_token { -#line 3293 "reflect.h2" +#line 3333 "reflect.h2" protected: int min_count {-1}; protected: int max_count {-1}; protected: int kind {range_flags::greedy}; @@ -1320,19 +1336,19 @@ class range_token public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 3373 "reflect.h2" +#line 3413 "reflect.h2" public: auto parse_modifier(parse_context& ctx) & -> void; -#line 3385 "reflect.h2" +#line 3425 "reflect.h2" public: [[nodiscard]] auto gen_mod_string() const& -> std::string; -#line 3398 "reflect.h2" +#line 3438 "reflect.h2" public: [[nodiscard]] auto gen_range_string() const& -> std::string; -#line 3417 "reflect.h2" +#line 3457 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3428 "reflect.h2" +#line 3468 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~range_token() noexcept; @@ -1340,16 +1356,16 @@ class range_token public: auto operator=(range_token const&) -> void = delete; -#line 3432 "reflect.h2" +#line 3472 "reflect.h2" }; -#line 3435 "reflect.h2" +#line 3475 "reflect.h2" // Regex syntax: *, +, or ? Example: aa* // class special_range_token : public range_token { -#line 3441 "reflect.h2" +#line 3481 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; public: virtual ~special_range_token() noexcept; @@ -1358,17 +1374,17 @@ class special_range_token public: auto operator=(special_range_token const&) -> void = delete; -#line 3471 "reflect.h2" +#line 3511 "reflect.h2" }; -#line 3474 "reflect.h2" +#line 3514 "reflect.h2" // Regex syntax: \b or \B Example: \bword\b // // Matches the start end end of word boundaries. // [[nodiscard]] auto word_boundary_token_parse(parse_context& ctx) -> token_ptr; -#line 3496 "reflect.h2" +#line 3536 "reflect.h2" //----------------------------------------------------------------------- // // Parser for regular expression. @@ -1389,24 +1405,24 @@ template class regex_generator public: explicit regex_generator(cpp2::impl::in r, Error_out const& e); -#line 3519 "reflect.h2" +#line 3559 "reflect.h2" public: [[nodiscard]] auto parse() & -> std::string; -#line 3554 "reflect.h2" +#line 3594 "reflect.h2" private: auto extract_modifiers() & -> void; public: regex_generator(regex_generator const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(regex_generator const&) -> void = delete; -#line 3568 "reflect.h2" +#line 3608 "reflect.h2" }; template [[nodiscard]] auto generate_regex(cpp2::impl::in regex, Err const& err) -> std::string; -#line 3580 "reflect.h2" +#line 3620 "reflect.h2" auto regex_gen(meta::type_declaration& t) -> void; -#line 3635 "reflect.h2" +#line 3675 "reflect.h2" //----------------------------------------------------------------------- // // apply_metafunctions - for types @@ -1417,7 +1433,7 @@ auto regex_gen(meta::type_declaration& t) -> void; auto const& error ) -> bool; -#line 3754 "reflect.h2" +#line 3794 "reflect.h2" //----------------------------------------------------------------------- // // apply_metafunctions - for functions @@ -1428,7 +1444,7 @@ auto regex_gen(meta::type_declaration& t) -> void; auto const& error ) -> bool; -#line 3808 "reflect.h2" +#line 3848 "reflect.h2" } } @@ -1455,40 +1471,42 @@ namespace meta { // Common data members // -#line 47 "reflect.h2" +#line 48 "reflect.h2" // Constructor // -#line 49 "reflect.h2" +#line 50 "reflect.h2" compiler_services::compiler_services( std::vector* errors_, std::set* includes_, - stable_vector* generated_tokens_ + stable_vector* generated_tokens_, + std::vector>* generated_declarations_ ) : errors{ errors_ } , includes{ includes_ } , errors_original_size{ cpp2::unsafe_narrow(std::ssize(*cpp2::impl::assert_not_null(errors))) } , generated_tokens{ generated_tokens_ } + , generated_declarations{ generated_declarations_ } , parser{ *cpp2::impl::assert_not_null(errors), *cpp2::impl::assert_not_null(includes) } -#line 55 "reflect.h2" +#line 57 "reflect.h2" { -#line 61 "reflect.h2" +#line 64 "reflect.h2" } // Common API // -#line 65 "reflect.h2" +#line 68 "reflect.h2" auto compiler_services::set_metafunction_name(cpp2::impl::in name, cpp2::impl::in> args) & -> void{ metafunction_name = name; metafunction_args = args; metafunctions_used = CPP2_UFCS(empty)(args); } -#line 71 "reflect.h2" +#line 74 "reflect.h2" [[nodiscard]] auto compiler_services::get_metafunction_name() const& -> std::string_view { return metafunction_name; } -#line 73 "reflect.h2" +#line 76 "reflect.h2" [[nodiscard]] auto compiler_services::get_argument(cpp2::impl::in index) & -> std::string{ metafunctions_used = true; if (([_0 = 0, _1 = index, _2 = CPP2_UFCS(ssize)(metafunction_args)]{ return cpp2::impl::cmp_less_eq(_0,_1) && cpp2::impl::cmp_less(_1,_2); }())) { @@ -1497,28 +1515,23 @@ namespace meta { return ""; } -#line 81 "reflect.h2" +#line 84 "reflect.h2" [[nodiscard]] auto compiler_services::get_arguments() & -> std::vector{ metafunctions_used = true; return metafunction_args; } -#line 86 "reflect.h2" +#line 89 "reflect.h2" [[nodiscard]] auto compiler_services::arguments_were_used() const& -> bool { return metafunctions_used; } -#line 88 "reflect.h2" - [[nodiscard]] auto compiler_services::parse_statement( +#line 91 "reflect.h2" + [[nodiscard]] auto compiler_services::lex_multiline( std::string_view source - ) & -> parse_statement_ret + ) & -> tokens* { - cpp2::impl::deferred_init> ret; -#line 94 "reflect.h2" - auto original_source {source}; - - CPP2_UFCS(push_back)(generated_lines, std::vector()); - auto lines {&CPP2_UFCS(back)(generated_lines)}; + auto lines {&CPP2_UFCS(emplace_back)(generated_lines)}; auto add_line {[&, _1 = lines](cpp2::impl::in s) mutable -> void{ static_cast(CPP2_UFCS(emplace_back)((*cpp2::impl::assert_not_null(_1)), s, source_line::category::cpp2)); @@ -1527,9 +1540,8 @@ namespace meta { auto newline_pos{CPP2_UFCS(find)(source, '\n')}; // First split this string into source_lines - // -#line 106 "reflect.h2" +#line 105 "reflect.h2" if ( cpp2::impl::cmp_greater(CPP2_UFCS(ssize)(source),1) && newline_pos != source.npos) { @@ -1542,7 +1554,7 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; } } -#line 117 "reflect.h2" +#line 116 "reflect.h2" if (!(CPP2_UFCS(empty)(source))) { cpp2::move(add_line)(cpp2::move(source)); } @@ -1556,21 +1568,59 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; if (cpp2::cpp2_default.is_active() && !(std::ssize(CPP2_UFCS(get_map)((*cpp2::impl::assert_not_null(tokens)))) == 1) ) { cpp2::cpp2_default.report_violation(""); } - // Now parse this single declaration from - // the lexed tokens - ret.construct(CPP2_UFCS(parse_one_declaration)(parser, + return tokens; + } + +#line 132 "reflect.h2" + [[nodiscard]] auto compiler_services::parse_statement( + + std::string_view source + ) & -> parse_statement_ret + + { + cpp2::impl::deferred_init> stmt; +#line 138 "reflect.h2" + auto original_source {source}; + + auto tokens {lex_multiline(cpp2::move(source))}; + + // Now parse a single *statement* from the lexed tokens + stmt.construct(CPP2_UFCS(parse_one_statement)(parser, (*cpp2::impl::assert_not_null(CPP2_UFCS(begin)(CPP2_UFCS(get_map)(*cpp2::impl::assert_not_null(cpp2::move(tokens)))))).second, *cpp2::impl::assert_not_null(generated_tokens) )); - if (!(ret.value())) { + if (!(stmt.value())) { error("parse failed - the source string is not a valid statement:\n" + cpp2::to_string(cpp2::move(original_source)) + ""); - }return std::move(ret.value()); + }return std::move(stmt.value()); } -#line 141 "reflect.h2" +#line 152 "reflect.h2" auto compiler_services::add_runtime_support_include(cpp2::impl::in s) & -> void { static_cast(CPP2_UFCS(emplace)((*cpp2::impl::assert_not_null(includes)), s)); } -#line 143 "reflect.h2" +#line 154 "reflect.h2" + [[nodiscard]] auto compiler_services::parse_and_add_declaration( + + std::string_view source + ) & -> bool + + { + auto tokens {lex_multiline(cpp2::move(source))}; + + // Now parse a single *declaration* from the lexed tokens + auto decl {CPP2_UFCS(parse_one_declaration)(parser, + (*cpp2::impl::assert_not_null(CPP2_UFCS(begin)(CPP2_UFCS(get_map)(*cpp2::impl::assert_not_null(cpp2::move(tokens)))))).second, + *cpp2::impl::assert_not_null(generated_tokens) + )}; + + auto result {cpp2::impl::as_(decl)}; + + // Save it aside to be added later to the translation unit + if (decl) {CPP2_UFCS(push_back)((*cpp2::impl::assert_not_null(generated_declarations)), std::move(cpp2::move(decl))); } + + return result; + } + +#line 176 "reflect.h2" [[nodiscard]] auto compiler_services::position() const -> source_position { @@ -1580,7 +1630,7 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; // Error diagnosis and handling, integrated with compiler output // Unlike a contract violation, .requires continues further processing // -#line 152 "reflect.h2" +#line 185 "reflect.h2" auto compiler_services::require( cpp2::impl::in b, @@ -1592,7 +1642,7 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; } } -#line 163 "reflect.h2" +#line 196 "reflect.h2" auto compiler_services::error(cpp2::impl::in msg) const& -> void { auto message {cpp2::impl::as_(msg)}; @@ -1605,7 +1655,7 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; // Enable custom contracts on this object, integrated with compiler output // Unlike .requires, a contract violation stops further processing // -#line 175 "reflect.h2" +#line 208 "reflect.h2" auto compiler_services::report_violation(auto const& msg) const& -> void{ error(msg); throw(std::runtime_error( @@ -1614,21 +1664,30 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; )); } -#line 183 "reflect.h2" +#line 216 "reflect.h2" [[nodiscard]] auto compiler_services::is_active() const& -> auto { return true; } +#line 218 "reflect.h2" + auto compiler_services::append_declaration_to_translation_unit(cpp2::impl::in source) & -> void + { + if (!(parse_and_add_declaration(source))) { + error("error attempting to add declaration:\n\t" + cpp2::to_string(source) + ""); + } + } + compiler_services::~compiler_services() noexcept{} compiler_services::compiler_services(compiler_services const& that) : errors{ that.errors } , includes{ that.includes } , errors_original_size{ that.errors_original_size } , generated_tokens{ that.generated_tokens } + , generated_declarations{ that.generated_declarations } , parser{ that.parser } , metafunction_name{ that.metafunction_name } , metafunction_args{ that.metafunction_args } , metafunctions_used{ that.metafunctions_used }{} -#line 187 "reflect.h2" +#line 227 "reflect.h2" /* //----------------------------------------------------------------------- // @@ -1665,7 +1724,7 @@ type_id: @polymorphic_base @copyable type = } */ -#line 224 "reflect.h2" +#line 264 "reflect.h2" //----------------------------------------------------------------------- // // Declarations @@ -1676,7 +1735,7 @@ type_id: @polymorphic_base @copyable type = // All declarations are wrappers around a pointer to node // -#line 239 "reflect.h2" +#line 279 "reflect.h2" declaration_base::declaration_base( declaration_node* n_, @@ -1684,17 +1743,17 @@ type_id: @polymorphic_base @copyable type = ) : compiler_services{ s } , n{ n_ } -#line 244 "reflect.h2" +#line 284 "reflect.h2" { -#line 247 "reflect.h2" +#line 287 "reflect.h2" if (cpp2::cpp2_default.is_active() && !(n) ) { cpp2::cpp2_default.report_violation(CPP2_CONTRACT_MSG("a meta::declaration must point to a valid declaration_node, not null")); } } -#line 250 "reflect.h2" +#line 290 "reflect.h2" [[nodiscard]] auto declaration_base::position() const -> source_position { return CPP2_UFCS(position)((*cpp2::impl::assert_not_null(n))); } -#line 252 "reflect.h2" +#line 292 "reflect.h2" [[nodiscard]] auto declaration_base::print() const& -> std::string { return CPP2_UFCS(pretty_print_visualize)((*cpp2::impl::assert_not_null(n)), 0); } declaration_base::~declaration_base() noexcept{} @@ -1702,126 +1761,126 @@ declaration_base::declaration_base(declaration_base const& that) : compiler_services{ static_cast(that) } , n{ that.n }{} -#line 256 "reflect.h2" +#line 296 "reflect.h2" //----------------------------------------------------------------------- // All declarations // -#line 263 "reflect.h2" +#line 303 "reflect.h2" declaration::declaration( declaration_node* n_, cpp2::impl::in s ) : declaration_base{ n_, s } -#line 268 "reflect.h2" +#line 308 "reflect.h2" { } -#line 272 "reflect.h2" +#line 312 "reflect.h2" [[nodiscard]] auto declaration::is_public() const& -> bool { return CPP2_UFCS(is_public)((*cpp2::impl::assert_not_null(n))); } -#line 273 "reflect.h2" +#line 313 "reflect.h2" [[nodiscard]] auto declaration::is_protected() const& -> bool { return CPP2_UFCS(is_protected)((*cpp2::impl::assert_not_null(n))); } -#line 274 "reflect.h2" +#line 314 "reflect.h2" [[nodiscard]] auto declaration::is_private() const& -> bool { return CPP2_UFCS(is_private)((*cpp2::impl::assert_not_null(n))); } -#line 275 "reflect.h2" +#line 315 "reflect.h2" [[nodiscard]] auto declaration::is_default_access() const& -> bool { return CPP2_UFCS(is_default_access)((*cpp2::impl::assert_not_null(n))); } -#line 277 "reflect.h2" +#line 317 "reflect.h2" auto declaration::default_to_public() & -> void { static_cast(CPP2_UFCS(make_public)((*cpp2::impl::assert_not_null(n)))); } -#line 278 "reflect.h2" +#line 318 "reflect.h2" auto declaration::default_to_protected() & -> void { static_cast(CPP2_UFCS(make_protected)((*cpp2::impl::assert_not_null(n)))); } -#line 279 "reflect.h2" +#line 319 "reflect.h2" auto declaration::default_to_private() & -> void { static_cast(CPP2_UFCS(make_private)((*cpp2::impl::assert_not_null(n)))); } -#line 281 "reflect.h2" +#line 321 "reflect.h2" [[nodiscard]] auto declaration::make_public() & -> bool { return CPP2_UFCS(make_public)((*cpp2::impl::assert_not_null(n))); } -#line 282 "reflect.h2" +#line 322 "reflect.h2" [[nodiscard]] auto declaration::make_protected() & -> bool { return CPP2_UFCS(make_protected)((*cpp2::impl::assert_not_null(n))); } -#line 283 "reflect.h2" +#line 323 "reflect.h2" [[nodiscard]] auto declaration::make_private() & -> bool { return CPP2_UFCS(make_private)((*cpp2::impl::assert_not_null(n))); } -#line 285 "reflect.h2" +#line 325 "reflect.h2" [[nodiscard]] auto declaration::has_name() const& -> bool { return CPP2_UFCS(has_name)((*cpp2::impl::assert_not_null(n))); } -#line 286 "reflect.h2" +#line 326 "reflect.h2" [[nodiscard]] auto declaration::has_name(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_name)((*cpp2::impl::assert_not_null(n)), s); } -#line 288 "reflect.h2" +#line 328 "reflect.h2" [[nodiscard]] auto declaration::name() const& -> std::string_view{ if (has_name()) {return CPP2_UFCS(as_string_view)((*cpp2::impl::assert_not_null(CPP2_UFCS(name)(*cpp2::impl::assert_not_null(n))))); } else { return ""; } } -#line 293 "reflect.h2" +#line 333 "reflect.h2" [[nodiscard]] auto declaration::has_initializer() const& -> bool { return CPP2_UFCS(has_initializer)((*cpp2::impl::assert_not_null(n))); } -#line 295 "reflect.h2" +#line 335 "reflect.h2" [[nodiscard]] auto declaration::is_global() const& -> bool { return CPP2_UFCS(is_global)((*cpp2::impl::assert_not_null(n))); } -#line 296 "reflect.h2" +#line 336 "reflect.h2" [[nodiscard]] auto declaration::is_function() const& -> bool { return CPP2_UFCS(is_function)((*cpp2::impl::assert_not_null(n))); } -#line 297 "reflect.h2" +#line 337 "reflect.h2" [[nodiscard]] auto declaration::is_object() const& -> bool { return CPP2_UFCS(is_object)((*cpp2::impl::assert_not_null(n))); } -#line 298 "reflect.h2" +#line 338 "reflect.h2" [[nodiscard]] auto declaration::is_base_object() const& -> bool { return CPP2_UFCS(is_base_object)((*cpp2::impl::assert_not_null(n))); } -#line 299 "reflect.h2" +#line 339 "reflect.h2" [[nodiscard]] auto declaration::is_member_object() const& -> bool { return CPP2_UFCS(is_member_object)((*cpp2::impl::assert_not_null(n))); } -#line 300 "reflect.h2" +#line 340 "reflect.h2" [[nodiscard]] auto declaration::is_type() const& -> bool { return CPP2_UFCS(is_type)((*cpp2::impl::assert_not_null(n))); } -#line 301 "reflect.h2" +#line 341 "reflect.h2" [[nodiscard]] auto declaration::is_namespace() const& -> bool { return CPP2_UFCS(is_namespace)((*cpp2::impl::assert_not_null(n))); } -#line 302 "reflect.h2" +#line 342 "reflect.h2" [[nodiscard]] auto declaration::is_alias() const& -> bool { return CPP2_UFCS(is_alias)((*cpp2::impl::assert_not_null(n))); } -#line 304 "reflect.h2" +#line 344 "reflect.h2" [[nodiscard]] auto declaration::is_type_alias() const& -> bool { return CPP2_UFCS(is_type_alias)((*cpp2::impl::assert_not_null(n))); } -#line 305 "reflect.h2" +#line 345 "reflect.h2" [[nodiscard]] auto declaration::is_namespace_alias() const& -> bool { return CPP2_UFCS(is_namespace_alias)((*cpp2::impl::assert_not_null(n))); } -#line 306 "reflect.h2" +#line 346 "reflect.h2" [[nodiscard]] auto declaration::is_object_alias() const& -> bool { return CPP2_UFCS(is_object_alias)((*cpp2::impl::assert_not_null(n))); } -#line 308 "reflect.h2" +#line 348 "reflect.h2" [[nodiscard]] auto declaration::is_function_expression() const& -> bool { return CPP2_UFCS(is_function_expression)((*cpp2::impl::assert_not_null(n))); } -#line 310 "reflect.h2" +#line 350 "reflect.h2" [[nodiscard]] auto declaration::as_function() const& -> function_declaration { return function_declaration(n, (*this)); } -#line 311 "reflect.h2" +#line 351 "reflect.h2" [[nodiscard]] auto declaration::as_object() const& -> object_declaration { return object_declaration(n, (*this)); } -#line 312 "reflect.h2" +#line 352 "reflect.h2" [[nodiscard]] auto declaration::as_type() const& -> type_declaration { return type_declaration(n, (*this)); } -#line 313 "reflect.h2" +#line 353 "reflect.h2" [[nodiscard]] auto declaration::as_alias() const& -> alias_declaration { return alias_declaration(n, (*this)); } -#line 315 "reflect.h2" +#line 355 "reflect.h2" [[nodiscard]] auto declaration::get_parent() const& -> declaration { return declaration((*cpp2::impl::assert_not_null(n)).parent_declaration, (*this)); } -#line 317 "reflect.h2" +#line 357 "reflect.h2" [[nodiscard]] auto declaration::parent_is_function() const& -> bool { return CPP2_UFCS(parent_is_function)((*cpp2::impl::assert_not_null(n))); } -#line 318 "reflect.h2" +#line 358 "reflect.h2" [[nodiscard]] auto declaration::parent_is_object() const& -> bool { return CPP2_UFCS(parent_is_object)((*cpp2::impl::assert_not_null(n))); } -#line 319 "reflect.h2" +#line 359 "reflect.h2" [[nodiscard]] auto declaration::parent_is_type() const& -> bool { return CPP2_UFCS(parent_is_type)((*cpp2::impl::assert_not_null(n))); } -#line 320 "reflect.h2" +#line 360 "reflect.h2" [[nodiscard]] auto declaration::parent_is_namespace() const& -> bool { return CPP2_UFCS(parent_is_namespace)((*cpp2::impl::assert_not_null(n))); } -#line 321 "reflect.h2" +#line 361 "reflect.h2" [[nodiscard]] auto declaration::parent_is_alias() const& -> bool { return CPP2_UFCS(parent_is_alias)((*cpp2::impl::assert_not_null(n))); } -#line 323 "reflect.h2" +#line 363 "reflect.h2" [[nodiscard]] auto declaration::parent_is_type_alias() const& -> bool { return CPP2_UFCS(parent_is_type_alias)((*cpp2::impl::assert_not_null(n))); } -#line 324 "reflect.h2" +#line 364 "reflect.h2" [[nodiscard]] auto declaration::parent_is_namespace_alias() const& -> bool { return CPP2_UFCS(parent_is_namespace_alias)((*cpp2::impl::assert_not_null(n))); } -#line 325 "reflect.h2" +#line 365 "reflect.h2" [[nodiscard]] auto declaration::parent_is_object_alias() const& -> bool { return CPP2_UFCS(parent_is_object_alias)((*cpp2::impl::assert_not_null(n))); } -#line 327 "reflect.h2" +#line 367 "reflect.h2" [[nodiscard]] auto declaration::parent_is_polymorphic() const& -> bool { return CPP2_UFCS(parent_is_polymorphic)((*cpp2::impl::assert_not_null(n))); } -#line 329 "reflect.h2" +#line 369 "reflect.h2" auto declaration::mark_for_removal_from_enclosing_type() & -> void // this precondition should be sufficient ... { if (cpp2::type_safety.is_active() && !(parent_is_type()) ) { cpp2::type_safety.report_violation(""); } -#line 332 "reflect.h2" +#line 372 "reflect.h2" auto test {CPP2_UFCS(type_member_mark_for_removal)((*cpp2::impl::assert_not_null(n)))}; if (cpp2::cpp2_default.is_active() && !(cpp2::move(test)) ) { cpp2::cpp2_default.report_violation(""); }// ... to ensure this assert is true } @@ -1830,93 +1889,93 @@ declaration_base::declaration_base(declaration_base const& that) declaration::declaration(declaration const& that) : declaration_base{ static_cast(that) }{} -#line 338 "reflect.h2" +#line 378 "reflect.h2" //----------------------------------------------------------------------- // Function declarations // -#line 345 "reflect.h2" +#line 385 "reflect.h2" function_declaration::function_declaration( declaration_node* n_, cpp2::impl::in s ) : declaration{ n_, s } -#line 350 "reflect.h2" +#line 390 "reflect.h2" { if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(is_function)((*cpp2::impl::assert_not_null(n)))) ) { cpp2::cpp2_default.report_violation(""); } } -#line 355 "reflect.h2" +#line 395 "reflect.h2" [[nodiscard]] auto function_declaration::index_of_parameter_named(cpp2::impl::in s) const& -> int { return CPP2_UFCS(index_of_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } -#line 356 "reflect.h2" +#line 396 "reflect.h2" [[nodiscard]] auto function_declaration::has_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } -#line 357 "reflect.h2" +#line 397 "reflect.h2" [[nodiscard]] auto function_declaration::has_in_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_in_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } -#line 358 "reflect.h2" +#line 398 "reflect.h2" [[nodiscard]] auto function_declaration::has_copy_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_copy_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } -#line 359 "reflect.h2" +#line 399 "reflect.h2" [[nodiscard]] auto function_declaration::has_inout_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_inout_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } -#line 360 "reflect.h2" +#line 400 "reflect.h2" [[nodiscard]] auto function_declaration::has_out_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_out_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } -#line 361 "reflect.h2" +#line 401 "reflect.h2" [[nodiscard]] auto function_declaration::has_move_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_move_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } -#line 362 "reflect.h2" +#line 402 "reflect.h2" [[nodiscard]] auto function_declaration::has_forward_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_forward_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } -#line 363 "reflect.h2" +#line 403 "reflect.h2" [[nodiscard]] auto function_declaration::first_parameter_name() const& -> std::string { return CPP2_UFCS(first_parameter_name)((*cpp2::impl::assert_not_null(n))); } -#line 365 "reflect.h2" +#line 405 "reflect.h2" [[nodiscard]] auto function_declaration::has_parameter_with_name_and_pass(cpp2::impl::in s, cpp2::impl::in pass) const& -> bool { return CPP2_UFCS(has_parameter_with_name_and_pass)((*cpp2::impl::assert_not_null(n)), s, pass); } -#line 367 "reflect.h2" +#line 407 "reflect.h2" [[nodiscard]] auto function_declaration::is_function_with_this() const& -> bool { return CPP2_UFCS(is_function_with_this)((*cpp2::impl::assert_not_null(n))); } -#line 368 "reflect.h2" +#line 408 "reflect.h2" [[nodiscard]] auto function_declaration::is_virtual() const& -> bool { return CPP2_UFCS(is_virtual_function)((*cpp2::impl::assert_not_null(n))); } -#line 369 "reflect.h2" +#line 409 "reflect.h2" [[nodiscard]] auto function_declaration::is_defaultable() const& -> bool { return CPP2_UFCS(is_defaultable_function)((*cpp2::impl::assert_not_null(n))); } -#line 370 "reflect.h2" +#line 410 "reflect.h2" [[nodiscard]] auto function_declaration::is_constructor() const& -> bool { return CPP2_UFCS(is_constructor)((*cpp2::impl::assert_not_null(n))); } -#line 371 "reflect.h2" +#line 411 "reflect.h2" [[nodiscard]] auto function_declaration::is_default_constructor() const& -> bool { return CPP2_UFCS(is_default_constructor)((*cpp2::impl::assert_not_null(n))); } -#line 372 "reflect.h2" +#line 412 "reflect.h2" [[nodiscard]] auto function_declaration::is_move() const& -> bool { return CPP2_UFCS(is_move)((*cpp2::impl::assert_not_null(n))); } -#line 373 "reflect.h2" +#line 413 "reflect.h2" [[nodiscard]] auto function_declaration::is_swap() const& -> bool { return CPP2_UFCS(is_swap)((*cpp2::impl::assert_not_null(n))); } -#line 374 "reflect.h2" +#line 414 "reflect.h2" [[nodiscard]] auto function_declaration::is_constructor_with_that() const& -> bool { return CPP2_UFCS(is_constructor_with_that)((*cpp2::impl::assert_not_null(n))); } -#line 375 "reflect.h2" +#line 415 "reflect.h2" [[nodiscard]] auto function_declaration::is_constructor_with_in_that() const& -> bool { return CPP2_UFCS(is_constructor_with_in_that)((*cpp2::impl::assert_not_null(n))); } -#line 376 "reflect.h2" +#line 416 "reflect.h2" [[nodiscard]] auto function_declaration::is_constructor_with_move_that() const& -> bool { return CPP2_UFCS(is_constructor_with_move_that)((*cpp2::impl::assert_not_null(n))); } -#line 377 "reflect.h2" +#line 417 "reflect.h2" [[nodiscard]] auto function_declaration::is_assignment() const& -> bool { return CPP2_UFCS(is_assignment)((*cpp2::impl::assert_not_null(n))); } -#line 378 "reflect.h2" +#line 418 "reflect.h2" [[nodiscard]] auto function_declaration::is_assignment_with_that() const& -> bool { return CPP2_UFCS(is_assignment_with_that)((*cpp2::impl::assert_not_null(n))); } -#line 379 "reflect.h2" +#line 419 "reflect.h2" [[nodiscard]] auto function_declaration::is_assignment_with_in_that() const& -> bool { return CPP2_UFCS(is_assignment_with_in_that)((*cpp2::impl::assert_not_null(n))); } -#line 380 "reflect.h2" +#line 420 "reflect.h2" [[nodiscard]] auto function_declaration::is_assignment_with_move_that() const& -> bool { return CPP2_UFCS(is_assignment_with_move_that)((*cpp2::impl::assert_not_null(n))); } -#line 381 "reflect.h2" +#line 421 "reflect.h2" [[nodiscard]] auto function_declaration::is_destructor() const& -> bool { return CPP2_UFCS(is_destructor)((*cpp2::impl::assert_not_null(n))); } -#line 383 "reflect.h2" +#line 423 "reflect.h2" [[nodiscard]] auto function_declaration::is_copy_or_move() const& -> bool { return is_constructor_with_that() || is_assignment_with_that(); } -#line 385 "reflect.h2" +#line 425 "reflect.h2" [[nodiscard]] auto function_declaration::has_declared_return_type() const& -> bool { return CPP2_UFCS(has_declared_return_type)((*cpp2::impl::assert_not_null(n))); } -#line 386 "reflect.h2" +#line 426 "reflect.h2" [[nodiscard]] auto function_declaration::has_deduced_return_type() const& -> bool { return CPP2_UFCS(has_deduced_return_type)((*cpp2::impl::assert_not_null(n))); } -#line 387 "reflect.h2" +#line 427 "reflect.h2" [[nodiscard]] auto function_declaration::has_bool_return_type() const& -> bool { return CPP2_UFCS(has_bool_return_type)((*cpp2::impl::assert_not_null(n))); } -#line 388 "reflect.h2" +#line 428 "reflect.h2" [[nodiscard]] auto function_declaration::has_non_void_return_type() const& -> bool { return CPP2_UFCS(has_non_void_return_type)((*cpp2::impl::assert_not_null(n))); } -#line 390 "reflect.h2" +#line 430 "reflect.h2" [[nodiscard]] auto function_declaration::unnamed_return_type() const& -> std::string { return CPP2_UFCS(unnamed_return_type_to_string)((*cpp2::impl::assert_not_null(n))); } -#line 392 "reflect.h2" +#line 432 "reflect.h2" [[nodiscard]] auto function_declaration::get_parameters() const& -> std::vector { @@ -1927,19 +1986,19 @@ declaration::declaration(declaration const& that) return ret; } -#line 402 "reflect.h2" +#line 442 "reflect.h2" [[nodiscard]] auto function_declaration::is_binary_comparison_function() const& -> bool { return CPP2_UFCS(is_binary_comparison_function)((*cpp2::impl::assert_not_null(n))); } -#line 404 "reflect.h2" +#line 444 "reflect.h2" auto function_declaration::default_to_virtual() & -> void { static_cast(CPP2_UFCS(make_function_virtual)((*cpp2::impl::assert_not_null(n)))); } -#line 406 "reflect.h2" +#line 446 "reflect.h2" [[nodiscard]] auto function_declaration::make_virtual() & -> bool { return CPP2_UFCS(make_function_virtual)((*cpp2::impl::assert_not_null(n))); } -#line 408 "reflect.h2" +#line 448 "reflect.h2" auto function_declaration::add_initializer(cpp2::impl::in source) & -> void -#line 411 "reflect.h2" +#line 451 "reflect.h2" { if ((*this).is_active() && !(!(has_initializer())) ) { (*this).report_violation(CPP2_CONTRACT_MSG("cannot add an initializer to a function that already has one")); } if ((*this).is_active() && !(parent_is_type()) ) { (*this).report_violation(CPP2_CONTRACT_MSG("cannot add an initializer to a function that isn't in a type scope")); } @@ -1948,7 +2007,7 @@ declaration::declaration(declaration const& that) //require( parent_is_type(), // "cannot add an initializer to a function that isn't in a type scope"); -#line 417 "reflect.h2" +#line 457 "reflect.h2" auto stmt {parse_statement(source)}; if (!((cpp2::impl::as_(stmt)))) { error("cannot add an initializer that is not a valid statement"); @@ -1961,30 +2020,30 @@ declaration::declaration(declaration const& that) function_declaration::function_declaration(function_declaration const& that) : declaration{ static_cast(that) }{} -#line 428 "reflect.h2" +#line 468 "reflect.h2" //----------------------------------------------------------------------- // Object declarations // -#line 435 "reflect.h2" +#line 475 "reflect.h2" object_declaration::object_declaration( declaration_node* n_, cpp2::impl::in s ) : declaration{ n_, s } -#line 440 "reflect.h2" +#line 480 "reflect.h2" { if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(is_object)((*cpp2::impl::assert_not_null(n)))) ) { cpp2::cpp2_default.report_violation(""); } } -#line 445 "reflect.h2" +#line 485 "reflect.h2" [[nodiscard]] auto object_declaration::is_const() const& -> bool { return CPP2_UFCS(is_const)((*cpp2::impl::assert_not_null(n))); } -#line 446 "reflect.h2" +#line 486 "reflect.h2" [[nodiscard]] auto object_declaration::has_wildcard_type() const& -> bool { return CPP2_UFCS(has_wildcard_type)((*cpp2::impl::assert_not_null(n))); } -#line 448 "reflect.h2" +#line 488 "reflect.h2" [[nodiscard]] auto object_declaration::type() const& -> std::string{ auto ret {CPP2_UFCS(object_type)((*cpp2::impl::assert_not_null(n)))}; require(!(contains(ret, "(*ERROR*)")), @@ -1992,7 +2051,7 @@ declaration::declaration(declaration const& that) return ret; } -#line 455 "reflect.h2" +#line 495 "reflect.h2" [[nodiscard]] auto object_declaration::initializer() const& -> std::string{ auto ret {CPP2_UFCS(object_initializer)((*cpp2::impl::assert_not_null(n)))}; require(!(contains(ret, "(*ERROR*)")), @@ -2003,25 +2062,25 @@ declaration::declaration(declaration const& that) object_declaration::object_declaration(object_declaration const& that) : declaration{ static_cast(that) }{} -#line 464 "reflect.h2" +#line 504 "reflect.h2" //----------------------------------------------------------------------- // Type declarations // -#line 471 "reflect.h2" +#line 511 "reflect.h2" type_declaration::type_declaration( declaration_node* n_, cpp2::impl::in s ) : declaration{ n_, s } -#line 476 "reflect.h2" +#line 516 "reflect.h2" { if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(is_type)((*cpp2::impl::assert_not_null(n)))) ) { cpp2::cpp2_default.report_violation(""); } } -#line 481 "reflect.h2" +#line 521 "reflect.h2" auto type_declaration::reserve_names(cpp2::impl::in name, auto&& ...etc) const& -> void { // etc is not declared ':string_view' for compatibility with GCC 10.x for ( @@ -2036,14 +2095,14 @@ declaration::declaration(declaration const& that) } } -#line 495 "reflect.h2" +#line 535 "reflect.h2" [[nodiscard]] auto type_declaration::is_polymorphic() const& -> bool { return CPP2_UFCS(is_polymorphic)((*cpp2::impl::assert_not_null(n))); } -#line 496 "reflect.h2" +#line 536 "reflect.h2" [[nodiscard]] auto type_declaration::is_final() const& -> bool { return CPP2_UFCS(is_type_final)((*cpp2::impl::assert_not_null(n))); } -#line 497 "reflect.h2" +#line 537 "reflect.h2" [[nodiscard]] auto type_declaration::make_final() & -> bool { return CPP2_UFCS(make_type_final)((*cpp2::impl::assert_not_null(n))); } -#line 499 "reflect.h2" +#line 539 "reflect.h2" [[nodiscard]] auto type_declaration::get_member_functions() const& -> std::vector { @@ -2055,7 +2114,7 @@ declaration::declaration(declaration const& that) return ret; } -#line 510 "reflect.h2" +#line 550 "reflect.h2" [[nodiscard]] auto type_declaration::get_member_functions_needing_initializer() const& -> std::vector { @@ -2071,7 +2130,7 @@ declaration::declaration(declaration const& that) return ret; } -#line 525 "reflect.h2" +#line 565 "reflect.h2" [[nodiscard]] auto type_declaration::get_member_objects() const& -> std::vector { @@ -2082,7 +2141,7 @@ declaration::declaration(declaration const& that) return ret; } -#line 535 "reflect.h2" +#line 575 "reflect.h2" [[nodiscard]] auto type_declaration::get_member_types() const& -> std::vector { @@ -2093,7 +2152,7 @@ declaration::declaration(declaration const& that) return ret; } -#line 545 "reflect.h2" +#line 585 "reflect.h2" [[nodiscard]] auto type_declaration::get_member_aliases() const& -> std::vector { @@ -2104,7 +2163,7 @@ declaration::declaration(declaration const& that) return ret; } -#line 555 "reflect.h2" +#line 595 "reflect.h2" [[nodiscard]] auto type_declaration::get_members() const& -> std::vector { @@ -2115,16 +2174,16 @@ declaration::declaration(declaration const& that) return ret; } -#line 565 "reflect.h2" +#line 605 "reflect.h2" [[nodiscard]] auto type_declaration::query_declared_value_set_functions() const& -> query_declared_value_set_functions_ret -#line 572 "reflect.h2" +#line 612 "reflect.h2" { cpp2::impl::deferred_init out_this_in_that; cpp2::impl::deferred_init out_this_move_that; cpp2::impl::deferred_init inout_this_in_that; cpp2::impl::deferred_init inout_this_move_that; -#line 573 "reflect.h2" +#line 613 "reflect.h2" auto declared {CPP2_UFCS(find_declared_value_set_functions)((*cpp2::impl::assert_not_null(n)))}; out_this_in_that.construct(declared.out_this_in_that != nullptr); out_this_move_that.construct(declared.out_this_move_that != nullptr); @@ -2132,7 +2191,7 @@ declaration::declaration(declaration const& that) inout_this_move_that.construct(cpp2::move(declared).inout_this_move_that != nullptr); return { std::move(out_this_in_that.value()), std::move(out_this_move_that.value()), std::move(inout_this_in_that.value()), std::move(inout_this_move_that.value()) }; } -#line 580 "reflect.h2" +#line 620 "reflect.h2" auto type_declaration::add_member(cpp2::impl::in source) & -> void { auto decl {parse_statement(source)}; @@ -2147,30 +2206,30 @@ declaration::declaration(declaration const& that) std::string("unexpected error while attempting to add member:\n") + source); } -#line 594 "reflect.h2" +#line 634 "reflect.h2" auto type_declaration::remove_marked_members() & -> void { CPP2_UFCS(type_remove_marked_members)((*cpp2::impl::assert_not_null(n))); } -#line 595 "reflect.h2" +#line 635 "reflect.h2" auto type_declaration::remove_all_members() & -> void { CPP2_UFCS(type_remove_all_members)((*cpp2::impl::assert_not_null(n))); } -#line 597 "reflect.h2" +#line 637 "reflect.h2" auto type_declaration::disable_member_function_generation() & -> void { CPP2_UFCS(type_disable_member_function_generation)((*cpp2::impl::assert_not_null(n))); } type_declaration::type_declaration(type_declaration const& that) : declaration{ static_cast(that) }{} -#line 601 "reflect.h2" +#line 641 "reflect.h2" //----------------------------------------------------------------------- // Alias declarations // -#line 608 "reflect.h2" +#line 648 "reflect.h2" alias_declaration::alias_declaration( declaration_node* n_, cpp2::impl::in s ) : declaration{ n_, s } -#line 613 "reflect.h2" +#line 653 "reflect.h2" { if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(is_alias)((*cpp2::impl::assert_not_null(n)))) ) { cpp2::cpp2_default.report_violation(""); } @@ -2179,7 +2238,7 @@ declaration::declaration(declaration const& that) alias_declaration::alias_declaration(alias_declaration const& that) : declaration{ static_cast(that) }{} -#line 620 "reflect.h2" +#line 660 "reflect.h2" //----------------------------------------------------------------------- // // Metafunctions - these are hardwired for now until we get to the @@ -2192,13 +2251,13 @@ declaration::declaration(declaration const& that) // Some common metafunction helpers (metafunctions are just functions, // so they can be factored as usual) // -#line 632 "reflect.h2" +#line 672 "reflect.h2" auto add_virtual_destructor(meta::type_declaration& t) -> void { CPP2_UFCS(add_member)(t, "operator=: (virtual move this) = { }"); } -#line 638 "reflect.h2" +#line 678 "reflect.h2" //----------------------------------------------------------------------- // // "... an abstract base class defines an interface ..." @@ -2211,7 +2270,7 @@ auto add_virtual_destructor(meta::type_declaration& t) -> void // // an abstract base class having only pure virtual functions // -#line 650 "reflect.h2" +#line 690 "reflect.h2" auto interface(meta::type_declaration& t) -> void { auto has_dtor {false}; @@ -2238,7 +2297,7 @@ auto interface(meta::type_declaration& t) -> void } } -#line 677 "reflect.h2" +#line 717 "reflect.h2" //----------------------------------------------------------------------- // // "C.35: A base class destructor should be either public and @@ -2258,7 +2317,7 @@ auto interface(meta::type_declaration& t) -> void // // Unlike an interface, it can have nonpublic and nonvirtual functions. // -#line 696 "reflect.h2" +#line 736 "reflect.h2" auto polymorphic_base(meta::type_declaration& t) -> void { auto has_dtor {false}; @@ -2283,7 +2342,7 @@ auto polymorphic_base(meta::type_declaration& t) -> void } } -#line 721 "reflect.h2" +#line 761 "reflect.h2" //----------------------------------------------------------------------- // // "... A totally ordered type ... requires operator<=> that @@ -2304,7 +2363,7 @@ auto polymorphic_base(meta::type_declaration& t) -> void //----------------------------------------------------------------------- // -#line 741 "reflect.h2" +#line 781 "reflect.h2" auto ordered_impl( meta::type_declaration& t, cpp2::impl::in ordering// must be "strong_ordering" etc. @@ -2334,7 +2393,7 @@ auto ordered_impl( // // Note: the ordering that should be encouraged as default gets the nice name // -#line 770 "reflect.h2" +#line 810 "reflect.h2" auto ordered(meta::type_declaration& t) -> void { ordered_impl(t, "strong_ordering"); @@ -2343,7 +2402,7 @@ auto ordered(meta::type_declaration& t) -> void //----------------------------------------------------------------------- // weakly_ordered - a weakly ordered type // -#line 778 "reflect.h2" +#line 818 "reflect.h2" auto weakly_ordered(meta::type_declaration& t) -> void { ordered_impl(t, "weak_ordering"); @@ -2352,13 +2411,13 @@ auto weakly_ordered(meta::type_declaration& t) -> void //----------------------------------------------------------------------- // partially_ordered - a partially ordered type // -#line 786 "reflect.h2" +#line 826 "reflect.h2" auto partially_ordered(meta::type_declaration& t) -> void { ordered_impl(t, "partial_ordering"); } -#line 792 "reflect.h2" +#line 832 "reflect.h2" //----------------------------------------------------------------------- // // "A value is ... a regular type. It must have all public @@ -2375,7 +2434,7 @@ auto partially_ordered(meta::type_declaration& t) -> void // // A type with (copy and move) x (construction and assignment) // -#line 808 "reflect.h2" +#line 848 "reflect.h2" auto copyable(meta::type_declaration& t) -> void { // If the user explicitly wrote any of the copy/move functions, @@ -2410,7 +2469,7 @@ auto copyable(meta::type_declaration& t) -> void // A regular type: copyable, plus has public default construction // and no protected or virtual functions // -#line 842 "reflect.h2" +#line 882 "reflect.h2" auto basic_value(meta::type_declaration& t) -> void { CPP2_UFCS(copyable)(t); @@ -2439,28 +2498,28 @@ auto basic_value(meta::type_declaration& t) -> void // // Note: the ordering that should be encouraged as default gets the nice name // -#line 870 "reflect.h2" +#line 910 "reflect.h2" auto value(meta::type_declaration& t) -> void { CPP2_UFCS(ordered)(t); CPP2_UFCS(basic_value)(t); } -#line 876 "reflect.h2" +#line 916 "reflect.h2" auto weakly_ordered_value(meta::type_declaration& t) -> void { CPP2_UFCS(weakly_ordered)(t); CPP2_UFCS(basic_value)(t); } -#line 882 "reflect.h2" +#line 922 "reflect.h2" auto partially_ordered_value(meta::type_declaration& t) -> void { CPP2_UFCS(partially_ordered)(t); CPP2_UFCS(basic_value)(t); } -#line 889 "reflect.h2" +#line 929 "reflect.h2" //----------------------------------------------------------------------- // // C.20: If you can avoid defining default operations, do @@ -2483,7 +2542,7 @@ auto partially_ordered_value(meta::type_declaration& t) -> void // // a type without declared copy/move/destructor functions // -#line 911 "reflect.h2" +#line 951 "reflect.h2" auto cpp1_rule_of_zero(meta::type_declaration& t) -> void { for ( auto& mf : CPP2_UFCS(get_member_functions)(t) ) @@ -2521,7 +2580,7 @@ auto cpp1_rule_of_zero(meta::type_declaration& t) -> void // no virtual functions, and no user-defined constructors // (i.e., no invariants) or assignment or destructors. // -#line 948 "reflect.h2" +#line 988 "reflect.h2" auto cpp2_struct(meta::type_declaration& t) -> void { std::string ctor_params {}; @@ -2573,7 +2632,7 @@ value_member_info::value_member_info(auto const& name_, auto const& type_, auto , type{ type_ } , value{ value_ }{} -#line 995 "reflect.h2" +#line 1035 "reflect.h2" //----------------------------------------------------------------------- // // "C enumerations constitute a curiously half-baked concept. ... @@ -2592,7 +2651,7 @@ value_member_info::value_member_info(auto const& name_, auto const& type_, auto // a type together with named constants that are its possible values // -#line 1018 "reflect.h2" +#line 1058 "reflect.h2" auto basic_enum( meta::type_declaration& t, auto const& nextval, @@ -2617,7 +2676,7 @@ auto basic_enum( { std::string value{"-1"}; -#line 1041 "reflect.h2" +#line 1081 "reflect.h2" for ( auto const& m : CPP2_UFCS(get_members)(t) ) if ( CPP2_UFCS(is_member_object)(m)) @@ -2659,7 +2718,7 @@ std::string value{"-1"}; } } -#line 1081 "reflect.h2" +#line 1121 "reflect.h2" if ((CPP2_UFCS(empty)(enumerators))) { CPP2_UFCS(error)(t, "an enumeration must contain at least one enumerator value"); return ; @@ -2710,7 +2769,7 @@ std::string value{"-1"}; } } -#line 1132 "reflect.h2" +#line 1172 "reflect.h2" // 2. Replace: Erase the contents and replace with modified contents // // Note that most values and functions are declared as '==' compile-time values, i.e. Cpp1 'constexpr' @@ -2760,7 +2819,7 @@ std::string to_string_impl{" to_string_impl: (this, prefix: std::string_view" // Provide 'to_string' and 'to_code' functions to print enumerator // name(s) as human-readable strings or as code expressions -#line 1179 "reflect.h2" +#line 1219 "reflect.h2" { if (bitwise) { to_string_impl += ", separator: std::string_view ) -> std::string = { \n" @@ -2801,7 +2860,7 @@ std::string to_string_impl{" to_string_impl: (this, prefix: std::string_view" } } -#line 1218 "reflect.h2" +#line 1258 "reflect.h2" if (bitwise) { CPP2_UFCS(add_member)(t, " to_string: (this) -> std::string = to_string_impl( \"\", \", \" );"); CPP2_UFCS(add_member)(t, " to_code : (this) -> std::string = to_string_impl( \"" + cpp2::to_string(CPP2_UFCS(name)(t)) + "::\", \" | \" );"); @@ -2815,7 +2874,7 @@ std::string from_string{" from_string: (s: std::string_view) -> " + cpp2::to_ // Provide a 'from_string' function to parse strings into enumerators -#line 1229 "reflect.h2" +#line 1269 "reflect.h2" { std::string_view prefix {""}; std::string_view combine_op {"return"}; @@ -2837,7 +2896,7 @@ std::string from_string{" from_string: (s: std::string_view) -> " + cpp2::to_ { std::string_view else_{""}; -#line 1249 "reflect.h2" +#line 1289 "reflect.h2" for ( auto const& e : cpp2::move(enumerators) ) { from_string += " " + cpp2::to_string(else_) + "if \"" + cpp2::to_string(e.name) + "\" == x { " + cpp2::to_string(combine_op) + " " + cpp2::to_string(e.name) + "; }\n"; @@ -2845,7 +2904,7 @@ std::string_view else_{""}; } } -#line 1255 "reflect.h2" +#line 1295 "reflect.h2" if (bitwise) { from_string += " else { break outer; }\n" " }\n" @@ -2861,11 +2920,11 @@ std::string_view else_{""}; } } -#line 1269 "reflect.h2" +#line 1309 "reflect.h2" CPP2_UFCS(add_member)(t, " from_code: (s: std::string_view) -> " + cpp2::to_string(CPP2_UFCS(name)(t)) + " = { str: std::string = s; return from_string( cpp2::string_util::replace_all(str, \"" + cpp2::to_string(CPP2_UFCS(name)(t)) + "::\", \"\" ) ); }"); } -#line 1273 "reflect.h2" +#line 1313 "reflect.h2" //----------------------------------------------------------------------- // // "An enum[...] is a totally ordered value type that stores a @@ -2875,7 +2934,7 @@ std::string_view else_{""}; // // -- P0707R4, section 3 // -#line 1282 "reflect.h2" +#line 1322 "reflect.h2" auto cpp2_enum(meta::type_declaration& t) -> void { // Let basic_enum do its thing, with an incrementing value generator @@ -2892,7 +2951,7 @@ auto cpp2_enum(meta::type_declaration& t) -> void ); } -#line 1299 "reflect.h2" +#line 1339 "reflect.h2" //----------------------------------------------------------------------- // // "flag_enum expresses an enumeration that stores values @@ -2903,7 +2962,7 @@ auto cpp2_enum(meta::type_declaration& t) -> void // // -- P0707R4, section 3 // -#line 1309 "reflect.h2" +#line 1349 "reflect.h2" auto flag_enum(meta::type_declaration& t) -> void { // Let basic_enum do its thing, with a power-of-two value generator @@ -2925,7 +2984,7 @@ auto flag_enum(meta::type_declaration& t) -> void ); } -#line 1331 "reflect.h2" +#line 1371 "reflect.h2" //----------------------------------------------------------------------- // // "As with void*, programmers should know that unions [...] are @@ -2950,7 +3009,7 @@ auto flag_enum(meta::type_declaration& t) -> void // a type that contains exactly one of a fixed set of values at a time // -#line 1355 "reflect.h2" +#line 1395 "reflect.h2" auto cpp2_union(meta::type_declaration& t) -> void { std::vector alternatives {}; @@ -2959,7 +3018,7 @@ auto value{0}; // 1. Gather: All the user-written members, and find/compute the max size -#line 1362 "reflect.h2" +#line 1402 "reflect.h2" for ( auto const& m : CPP2_UFCS(get_members)(t) ) { do @@ -2989,7 +3048,7 @@ auto value{0}; } while (false); ++value; } } -#line 1390 "reflect.h2" +#line 1430 "reflect.h2" std::string discriminator_type {}; if (cpp2::impl::cmp_less(CPP2_UFCS(ssize)(alternatives),std::numeric_limits::max())) { discriminator_type = "i8"; @@ -3004,7 +3063,7 @@ auto value{0}; discriminator_type = "i64"; }}} -#line 1405 "reflect.h2" +#line 1445 "reflect.h2" // 2. Replace: Erase the contents and replace with modified contents CPP2_UFCS(remove_marked_members)(t); @@ -3013,7 +3072,7 @@ std::string storage{" _storage: cpp2::aligned_storage t) -> void { std::cout << CPP2_UFCS(print)(t) << "\n"; } -#line 1511 "reflect.h2" +#line 1551 "reflect.h2" auto print(cpp2::impl::in f) -> void { std::cout << CPP2_UFCS(print)(f) << "\n"; @@ -3224,7 +3283,7 @@ return none; [[nodiscard]] auto expression_flags::from_code(cpp2::impl::in s) -> expression_flags{ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::move(str), "expression_flags::", "")); } -#line 1516 "reflect.h2" +#line 1556 "reflect.h2" //----------------------------------------------------------------------- // // regex - creates regular expressions from members @@ -3240,11 +3299,11 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov // ``` // -#line 1532 "reflect.h2" +#line 1572 "reflect.h2" // Possible modifiers for a regular expression. // -#line 1536 "reflect.h2" +#line 1576 "reflect.h2" // mod: i // mod: m // mod: s @@ -3252,106 +3311,106 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov // mod: x // mod: xx -#line 1545 "reflect.h2" +#line 1585 "reflect.h2" // Tokens for regular expressions. // // Basic class for a regex token. // -#line 1554 "reflect.h2" +#line 1594 "reflect.h2" regex_token::regex_token(cpp2::impl::in str) : string_rep{ str }{ -#line 1556 "reflect.h2" +#line 1596 "reflect.h2" } -#line 1558 "reflect.h2" +#line 1598 "reflect.h2" regex_token::regex_token() : string_rep{ "" }{ -#line 1560 "reflect.h2" +#line 1600 "reflect.h2" } //parse: (inout ctx: parse_context) -> token_ptr; // Generate the matching code. -#line 1565 "reflect.h2" +#line 1605 "reflect.h2" auto regex_token::add_groups([[maybe_unused]] std::set& unnamed_param_2) const -> void{}// Adds all group indices to the set. -#line 1566 "reflect.h2" +#line 1606 "reflect.h2" [[nodiscard]] auto regex_token::to_string() const& -> std::string{return string_rep; }// Create a string representation. -#line 1567 "reflect.h2" +#line 1607 "reflect.h2" auto regex_token::set_string(cpp2::impl::in s) & -> void{string_rep = s; } regex_token::~regex_token() noexcept{}// Set the string representation. -#line 1582 "reflect.h2" +#line 1622 "reflect.h2" regex_token_check::regex_token_check(cpp2::impl::in str, cpp2::impl::in check_) : regex_token{ str } , check{ check_ }{ -#line 1585 "reflect.h2" +#line 1625 "reflect.h2" } -#line 1587 "reflect.h2" +#line 1627 "reflect.h2" auto regex_token_check::generate_code(generation_context& ctx) const -> void{ ctx.add_check(check + "(" + ctx.match_parameters() + ")"); } regex_token_check::~regex_token_check() noexcept{} -#line 1601 "reflect.h2" +#line 1641 "reflect.h2" regex_token_code::regex_token_code(cpp2::impl::in str, cpp2::impl::in code_) : regex_token{ str } , code{ code_ }{ -#line 1604 "reflect.h2" +#line 1644 "reflect.h2" } -#line 1606 "reflect.h2" +#line 1646 "reflect.h2" auto regex_token_code::generate_code(generation_context& ctx) const -> void{ ctx.add(code); } regex_token_code::~regex_token_code() noexcept{} -#line 1618 "reflect.h2" +#line 1658 "reflect.h2" regex_token_empty::regex_token_empty(cpp2::impl::in str) : regex_token{ str }{ -#line 1620 "reflect.h2" +#line 1660 "reflect.h2" } -#line 1622 "reflect.h2" +#line 1662 "reflect.h2" auto regex_token_empty::generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void{ // Nothing. } regex_token_empty::~regex_token_empty() noexcept{} -#line 1636 "reflect.h2" +#line 1676 "reflect.h2" regex_token_list::regex_token_list(cpp2::impl::in t) : regex_token{ gen_string(t) } , tokens{ t }{ -#line 1639 "reflect.h2" +#line 1679 "reflect.h2" } -#line 1641 "reflect.h2" +#line 1681 "reflect.h2" auto regex_token_list::generate_code(generation_context& ctx) const -> void{ for ( auto const& token : tokens ) { (*cpp2::impl::assert_not_null(token)).generate_code(ctx); } } -#line 1647 "reflect.h2" +#line 1687 "reflect.h2" auto regex_token_list::add_groups(std::set& groups) const -> void{ for ( auto const& token : tokens ) { (*cpp2::impl::assert_not_null(token)).add_groups(groups); } } -#line 1653 "reflect.h2" +#line 1693 "reflect.h2" [[nodiscard]] auto regex_token_list::gen_string(cpp2::impl::in vec) -> std::string{ std::string r {""}; for ( auto const& token : vec ) { @@ -3362,7 +3421,7 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov regex_token_list::~regex_token_list() noexcept{} -#line 1676 "reflect.h2" +#line 1716 "reflect.h2" auto parse_context_group_state::next_alternative() & -> void{ token_vec new_list {}; std::swap(new_list, cur_match_list); @@ -3370,14 +3429,14 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov static_cast(alternate_match_lists.insert(alternate_match_lists.end(), CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, cpp2::move(new_list)))); } -#line 1684 "reflect.h2" +#line 1724 "reflect.h2" auto parse_context_group_state::swap(parse_context_group_state& t) & -> void{ std::swap(cur_match_list, t.cur_match_list); std::swap(alternate_match_lists, t.alternate_match_lists); std::swap(modifiers, t.modifiers); } -#line 1691 "reflect.h2" +#line 1731 "reflect.h2" [[nodiscard]] auto parse_context_group_state::get_as_token() & -> token_ptr{ if (alternate_match_lists.empty()) { post_process_list(cur_match_list); @@ -3389,15 +3448,15 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov } } -#line 1703 "reflect.h2" +#line 1743 "reflect.h2" auto parse_context_group_state::add(cpp2::impl::in token) & -> void{ cur_match_list.push_back(token); } -#line 1708 "reflect.h2" +#line 1748 "reflect.h2" [[nodiscard]] auto parse_context_group_state::empty() const& -> bool { return cur_match_list.empty(); } -#line 1712 "reflect.h2" +#line 1752 "reflect.h2" auto parse_context_group_state::post_process_list(token_vec& list) -> void{ // Merge all characters auto merge_pos {list.begin()}; @@ -3418,7 +3477,7 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov , modifiers{ modifiers_ }{} parse_context_group_state::parse_context_group_state(){} -#line 1738 "reflect.h2" +#line 1778 "reflect.h2" [[nodiscard]] auto parse_context_branch_reset_state::next() & -> int{ auto g {cur_group}; cur_group += 1; @@ -3427,20 +3486,20 @@ parse_context_group_state::parse_context_group_state(){} return g; } -#line 1747 "reflect.h2" +#line 1787 "reflect.h2" auto parse_context_branch_reset_state::set_next(cpp2::impl::in g) & -> void{ cur_group = g; max_group = max(max_group, g); } -#line 1753 "reflect.h2" +#line 1793 "reflect.h2" auto parse_context_branch_reset_state::next_alternative() & -> void{ if (is_active) { cur_group = from; } } -#line 1760 "reflect.h2" +#line 1800 "reflect.h2" auto parse_context_branch_reset_state::set_active_reset(cpp2::impl::in restart) & -> void{ is_active = true; cur_group = restart; @@ -3455,16 +3514,16 @@ parse_context_group_state::parse_context_group_state(){} , from{ from_ }{} parse_context_branch_reset_state::parse_context_branch_reset_state(){} -#line 1788 "reflect.h2" +#line 1828 "reflect.h2" parse_context::parse_context(cpp2::impl::in r, auto const& e) : regex{ r } , root{ CPP2_UFCS_TEMPLATE_NONLOCAL(cpp2_new)(cpp2::shared, "") } , error_out{ e }{ -#line 1792 "reflect.h2" +#line 1832 "reflect.h2" } -#line 1798 "reflect.h2" +#line 1838 "reflect.h2" [[nodiscard]] auto parse_context::start_group() & -> parse_context_group_state { parse_context_group_state old_state {}; @@ -3474,7 +3533,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return old_state; } -#line 1808 "reflect.h2" +#line 1848 "reflect.h2" [[nodiscard]] auto parse_context::end_group(cpp2::impl::in old_state) & -> token_ptr { auto inner {cur_group_state.get_as_token()}; @@ -3482,17 +3541,17 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return inner; } -#line 1815 "reflect.h2" +#line 1855 "reflect.h2" [[nodiscard]] auto parse_context::get_modifiers() const& -> expression_flags{ return cur_group_state.modifiers; } -#line 1819 "reflect.h2" +#line 1859 "reflect.h2" auto parse_context::set_modifiers(cpp2::impl::in mod) & -> void{ cur_group_state.modifiers = mod; } -#line 1826 "reflect.h2" +#line 1866 "reflect.h2" [[nodiscard]] auto parse_context::branch_reset_new_state() & -> parse_context_branch_reset_state { parse_context_branch_reset_state old_state {}; @@ -3502,7 +3561,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return old_state; } -#line 1835 "reflect.h2" +#line 1875 "reflect.h2" auto parse_context::branch_reset_restore_state(cpp2::impl::in old_state) & -> void { auto max_group {cur_branch_reset_state.max_group}; @@ -3510,24 +3569,24 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} cur_branch_reset_state.set_next(cpp2::move(max_group)); } -#line 1842 "reflect.h2" +#line 1882 "reflect.h2" auto parse_context::next_alternative() & -> void { cur_group_state.next_alternative(); cur_branch_reset_state.next_alternative(); } -#line 1850 "reflect.h2" +#line 1890 "reflect.h2" auto parse_context::add_token(cpp2::impl::in token) & -> void{ cur_group_state.add(token); } -#line 1854 "reflect.h2" +#line 1894 "reflect.h2" [[nodiscard]] auto parse_context::has_token() const& -> bool{ return !(cur_group_state.empty()); } -#line 1858 "reflect.h2" +#line 1898 "reflect.h2" [[nodiscard]] auto parse_context::pop_token() & -> token_ptr { token_ptr r {nullptr}; @@ -3539,22 +3598,22 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 1869 "reflect.h2" +#line 1909 "reflect.h2" [[nodiscard]] auto parse_context::get_as_token() & -> token_ptr{ return root; } -#line 1875 "reflect.h2" +#line 1915 "reflect.h2" [[nodiscard]] auto parse_context::get_cur_group() const& -> int{ return cur_branch_reset_state.cur_group; } -#line 1879 "reflect.h2" +#line 1919 "reflect.h2" [[nodiscard]] auto parse_context::next_group() & -> int{ return cur_branch_reset_state.next(); } -#line 1883 "reflect.h2" +#line 1923 "reflect.h2" auto parse_context::set_named_group(cpp2::impl::in name, cpp2::impl::in id) & -> void { if (!(named_groups.contains(name))) {// Redefinition of group name is not an error. The left most one is retained. @@ -3562,7 +3621,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 1890 "reflect.h2" +#line 1930 "reflect.h2" [[nodiscard]] auto parse_context::get_named_group(cpp2::impl::in name) const& -> int { auto iter {named_groups.find(name)}; @@ -3574,10 +3633,10 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 1903 "reflect.h2" +#line 1943 "reflect.h2" [[nodiscard]] auto parse_context::current() const& -> char{return CPP2_ASSERT_IN_BOUNDS(regex, pos); } -#line 1906 "reflect.h2" +#line 1946 "reflect.h2" [[nodiscard]] auto parse_context::get_next_position(cpp2::impl::in in_class, cpp2::impl::in no_skip) const& -> size_t { auto perl_syntax {false}; @@ -3617,7 +3676,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return cur; } -#line 1946 "reflect.h2" +#line 1986 "reflect.h2" [[nodiscard]] auto parse_context::next_impl(cpp2::impl::in in_class, cpp2::impl::in no_skip) & -> bool { pos = get_next_position(in_class, no_skip); @@ -3629,14 +3688,14 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 1957 "reflect.h2" +#line 1997 "reflect.h2" [[nodiscard]] auto parse_context::next() & -> auto { return next_impl(false, false); } -#line 1958 "reflect.h2" +#line 1998 "reflect.h2" [[nodiscard]] auto parse_context::next_in_class() & -> auto { return next_impl(true, false); } -#line 1959 "reflect.h2" +#line 1999 "reflect.h2" [[nodiscard]] auto parse_context::next_no_skip() & -> auto { return next_impl(false, true); } -#line 1961 "reflect.h2" +#line 2001 "reflect.h2" [[nodiscard]] auto parse_context::next_n(cpp2::impl::in n) & -> bool{ auto r {true}; auto cur {0}; @@ -3646,10 +3705,10 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 1970 "reflect.h2" +#line 2010 "reflect.h2" [[nodiscard]] auto parse_context::has_next() const& -> bool{return cpp2::impl::cmp_less(pos,regex.size()); } -#line 1972 "reflect.h2" +#line 2012 "reflect.h2" [[nodiscard]] auto parse_context::grab_until_impl(cpp2::impl::in e, cpp2::impl::out r, cpp2::impl::in any) & -> bool { auto end {pos}; @@ -3671,14 +3730,14 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 1993 "reflect.h2" +#line 2033 "reflect.h2" [[nodiscard]] auto parse_context::grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(e, cpp2::impl::out(&r), false); } -#line 1994 "reflect.h2" +#line 2034 "reflect.h2" [[nodiscard]] auto parse_context::grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(std::string(1, e), cpp2::impl::out(&r), false); } -#line 1995 "reflect.h2" +#line 2035 "reflect.h2" [[nodiscard]] auto parse_context::grab_until_one_of(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(e, cpp2::impl::out(&r), true); } -#line 1997 "reflect.h2" +#line 2037 "reflect.h2" [[nodiscard]] auto parse_context::grab_n(cpp2::impl::in n, cpp2::impl::out r) & -> bool { if (cpp2::impl::cmp_less_eq(pos + cpp2::impl::as_(n),regex.size())) { @@ -3692,7 +3751,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2010 "reflect.h2" +#line 2050 "reflect.h2" [[nodiscard]] auto parse_context::grab_number() & -> std::string { auto start {pos}; @@ -3714,7 +3773,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return cpp2::move(r.value()); } -#line 2031 "reflect.h2" +#line 2071 "reflect.h2" [[nodiscard]] auto parse_context::peek_impl(cpp2::impl::in in_class) const& -> char{ auto next_pos {get_next_position(in_class, false)}; if (cpp2::impl::cmp_less(next_pos,regex.size())) { @@ -3725,12 +3784,12 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2041 "reflect.h2" +#line 2081 "reflect.h2" [[nodiscard]] auto parse_context::peek() const& -> auto { return peek_impl(false); } -#line 2042 "reflect.h2" +#line 2082 "reflect.h2" [[nodiscard]] auto parse_context::peek_in_class() const& -> auto { return peek_impl(true); } -#line 2047 "reflect.h2" +#line 2087 "reflect.h2" [[nodiscard]] auto parse_context::parser_group_modifiers(cpp2::impl::in change_str, expression_flags& parser_modifiers) & -> bool { auto is_negative {false}; @@ -3785,7 +3844,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return true; } -#line 2101 "reflect.h2" +#line 2141 "reflect.h2" [[nodiscard]] auto parse_context::parse_until(cpp2::impl::in term) & -> bool{ token_ptr cur_token {}; @@ -3824,7 +3883,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return true; } -#line 2139 "reflect.h2" +#line 2179 "reflect.h2" [[nodiscard]] auto parse_context::parse(cpp2::impl::in modifiers) & -> bool { @@ -3840,21 +3899,21 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 2156 "reflect.h2" +#line 2196 "reflect.h2" [[nodiscard]] auto parse_context::get_pos() const& -> auto { return pos; } -#line 2157 "reflect.h2" +#line 2197 "reflect.h2" [[nodiscard]] auto parse_context::get_range(cpp2::impl::in start, cpp2::impl::in end) const& -> auto { return std::string(regex.substr(start, end - start + 1)); } -#line 2158 "reflect.h2" +#line 2198 "reflect.h2" [[nodiscard]] auto parse_context::valid() const& -> bool{return has_next() && !(has_error); } -#line 2160 "reflect.h2" +#line 2200 "reflect.h2" [[nodiscard]] auto parse_context::error(cpp2::impl::in err) & -> token_ptr{ has_error = true; error_out("Error during parsing of regex '" + cpp2::to_string(regex) + "' at position '" + cpp2::to_string(pos) + "': " + cpp2::to_string(err) + ""); return nullptr; } -#line 2175 "reflect.h2" +#line 2215 "reflect.h2" auto generation_function_context::add_tabs(cpp2::impl::in c) & -> void{ int i {0}; for( ; cpp2::impl::cmp_less(i,c); i += 1 ) { @@ -3862,7 +3921,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2182 "reflect.h2" +#line 2222 "reflect.h2" auto generation_function_context::remove_tabs(cpp2::impl::in c) & -> void{ tabs = tabs.substr(0, (cpp2::impl::as_(c)) * 2); } @@ -3872,22 +3931,22 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} , tabs{ tabs_ }{} generation_function_context::generation_function_context(){} -#line 2200 "reflect.h2" +#line 2240 "reflect.h2" [[nodiscard]] auto generation_context::match_parameters() const& -> std::string{return "r.pos, ctx"; } -#line 2205 "reflect.h2" +#line 2245 "reflect.h2" auto generation_context::add(cpp2::impl::in s) & -> void{ auto cur {get_current()}; (*cpp2::impl::assert_not_null(cur)).code += "" + cpp2::to_string((*cpp2::impl::assert_not_null(cur)).tabs) + cpp2::to_string(s) + "\n"; } -#line 2211 "reflect.h2" +#line 2251 "reflect.h2" auto generation_context::add_check(cpp2::impl::in check) & -> void{ auto cur {get_current()}; (*cpp2::impl::assert_not_null(cur)).code += "" + cpp2::to_string((*cpp2::impl::assert_not_null(cur)).tabs) + "if !cpp2::regex::" + cpp2::to_string(check) + " { r.matched = false; break; }\n"; } -#line 2217 "reflect.h2" +#line 2257 "reflect.h2" auto generation_context::add_statefull(cpp2::impl::in next_func, cpp2::impl::in check) & -> void { end_func_statefull(check); @@ -3896,7 +3955,7 @@ generation_function_context::generation_function_context(){} start_func_named(cpp2::move(name)); } -#line 2225 "reflect.h2" +#line 2265 "reflect.h2" auto generation_context::start_func_named(cpp2::impl::in name) & -> void { auto cur {new_context()}; @@ -3908,7 +3967,7 @@ generation_function_context::generation_function_context(){} (*cpp2::impl::assert_not_null(cpp2::move(cur))).add_tabs(3); } -#line 2236 "reflect.h2" +#line 2276 "reflect.h2" [[nodiscard]] auto generation_context::start_func() & -> std::string { auto name {gen_func_name()}; @@ -3916,7 +3975,7 @@ generation_function_context::generation_function_context(){} return cpp2::move(name) + "()"; } -#line 2243 "reflect.h2" +#line 2283 "reflect.h2" auto generation_context::end_func_statefull(cpp2::impl::in s) & -> void { auto cur {get_current()}; @@ -3936,7 +3995,7 @@ generation_function_context::generation_function_context(){} finish_context(); } -#line 2263 "reflect.h2" +#line 2303 "reflect.h2" [[nodiscard]] auto generation_context::generate_func(cpp2::impl::in token) & -> std::string { auto name {start_func()}; @@ -3946,7 +4005,7 @@ generation_function_context::generation_function_context(){} return name; } -#line 2273 "reflect.h2" +#line 2313 "reflect.h2" [[nodiscard]] auto generation_context::generate_reset(cpp2::impl::in> groups) & -> std::string { if (groups.empty()) { @@ -3969,33 +4028,33 @@ generation_function_context::generation_function_context(){} return cpp2::move(name) + "()"; } -#line 2297 "reflect.h2" +#line 2337 "reflect.h2" [[nodiscard]] auto generation_context::gen_func_name() & -> std::string{ auto cur_id {matcher_func}; matcher_func += 1; return "func_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2303 "reflect.h2" +#line 2343 "reflect.h2" [[nodiscard]] auto generation_context::next_func_name() & -> std::string{ return gen_func_name() + "()"; } -#line 2307 "reflect.h2" +#line 2347 "reflect.h2" [[nodiscard]] auto generation_context::gen_reset_func_name() & -> std::string{ auto cur_id {reset_func}; reset_func += 1; return "reset_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2313 "reflect.h2" +#line 2353 "reflect.h2" [[nodiscard]] auto generation_context::gen_temp() & -> std::string{ auto cur_id {temp_name}; temp_name += 1; return "tmp_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2321 "reflect.h2" +#line 2361 "reflect.h2" [[nodiscard]] auto generation_context::new_context() & -> generation_function_context*{ gen_stack.push_back(generation_function_context()); auto cur {get_current()}; @@ -4004,7 +4063,7 @@ generation_function_context::generation_function_context(){} return cur; } -#line 2329 "reflect.h2" +#line 2369 "reflect.h2" auto generation_context::finish_context() & -> void{ auto cur {get_current()}; auto base {get_base()}; @@ -4013,22 +4072,22 @@ generation_function_context::generation_function_context(){} gen_stack.pop_back(); } -#line 2339 "reflect.h2" +#line 2379 "reflect.h2" [[nodiscard]] auto generation_context::get_current() & -> generation_function_context*{ return &gen_stack.back(); } -#line 2343 "reflect.h2" +#line 2383 "reflect.h2" [[nodiscard]] auto generation_context::get_base() & -> generation_function_context*{ return &CPP2_ASSERT_IN_BOUNDS_LITERAL(gen_stack, 0); } -#line 2347 "reflect.h2" +#line 2387 "reflect.h2" [[nodiscard]] auto generation_context::get_entry_func() const& -> std::string{ return entry_func; } -#line 2351 "reflect.h2" +#line 2391 "reflect.h2" [[nodiscard]] auto generation_context::create_named_group_lookup(cpp2::impl::in> named_groups) const& -> std::string { std::string res {"get_named_group_index: (name) -> int = {\n"}; @@ -4052,18 +4111,18 @@ generation_function_context::generation_function_context(){} return res; } -#line 2376 "reflect.h2" +#line 2416 "reflect.h2" [[nodiscard]] auto generation_context::run(cpp2::impl::in token) & -> std::string{ entry_func = generate_func(token); return (*cpp2::impl::assert_not_null(get_base())).code; } -#line 2391 "reflect.h2" +#line 2431 "reflect.h2" alternative_token::alternative_token() : regex_token_empty{ "" }{} -#line 2393 "reflect.h2" +#line 2433 "reflect.h2" [[nodiscard]] auto alternative_token::parse(parse_context& ctx) -> token_ptr{ if (ctx.current() != '|') {return nullptr; } @@ -4074,15 +4133,15 @@ generation_function_context::generation_function_context(){} alternative_token::~alternative_token() noexcept{} -#line 2408 "reflect.h2" +#line 2448 "reflect.h2" alternative_token_gen::alternative_token_gen(cpp2::impl::in a) : regex_token{ gen_string(a) } , alternatives{ a }{ -#line 2411 "reflect.h2" +#line 2451 "reflect.h2" } -#line 2413 "reflect.h2" +#line 2453 "reflect.h2" auto alternative_token_gen::generate_code(generation_context& ctx) const -> void { std::string functions {""}; @@ -4100,7 +4159,7 @@ generation_function_context::generation_function_context(){} ctx.add_statefull(next_name, "cpp2::regex::alternative_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ", other, " + cpp2::to_string(next_name) + " " + cpp2::to_string(cpp2::move(functions)) + ")"); } -#line 2430 "reflect.h2" +#line 2470 "reflect.h2" auto alternative_token_gen::add_groups(std::set& groups) const -> void { for ( auto const& cur : alternatives ) { @@ -4108,7 +4167,7 @@ generation_function_context::generation_function_context(){} } } -#line 2437 "reflect.h2" +#line 2477 "reflect.h2" [[nodiscard]] auto alternative_token_gen::gen_string(cpp2::impl::in a) -> std::string { std::string r {""}; @@ -4124,14 +4183,14 @@ generation_function_context::generation_function_context(){} alternative_token_gen::~alternative_token_gen() noexcept{} -#line 2458 "reflect.h2" +#line 2498 "reflect.h2" any_token::any_token(cpp2::impl::in single_line) : regex_token_check{ ".", "any_token_matcher" }{ -#line 2460 "reflect.h2" +#line 2500 "reflect.h2" } -#line 2462 "reflect.h2" +#line 2502 "reflect.h2" [[nodiscard]] auto any_token::parse(parse_context& ctx) -> token_ptr{ if ('.' != ctx.current()) {return nullptr; } @@ -4140,21 +4199,21 @@ generation_function_context::generation_function_context(){} any_token::~any_token() noexcept{} -#line 2479 "reflect.h2" +#line 2519 "reflect.h2" char_token::char_token(cpp2::impl::in t, cpp2::impl::in ignore_case_) : regex_token{ std::string(1, t) } , token{ t } , ignore_case{ ignore_case_ }{ -#line 2483 "reflect.h2" +#line 2523 "reflect.h2" } -#line 2485 "reflect.h2" +#line 2525 "reflect.h2" [[nodiscard]] auto char_token::parse(parse_context& ctx) -> token_ptr{ return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, ctx.current(), ctx.get_modifiers().has(expression_flags::case_insensitive)); } -#line 2489 "reflect.h2" +#line 2529 "reflect.h2" auto char_token::generate_code(generation_context& ctx) const -> void { if (ignore_case) { @@ -4163,14 +4222,14 @@ generation_function_context::generation_function_context(){} { size_t i{0}; -#line 2495 "reflect.h2" +#line 2535 "reflect.h2" for( ; cpp2::impl::cmp_less(i,token.size()); i += 1 ) { CPP2_ASSERT_IN_BOUNDS(lower, i) = string_util::safe_tolower(CPP2_ASSERT_IN_BOUNDS(token, i)); CPP2_ASSERT_IN_BOUNDS(upper, i) = string_util::safe_toupper(CPP2_ASSERT_IN_BOUNDS(token, i)); } } -#line 2500 "reflect.h2" +#line 2540 "reflect.h2" if (upper != lower) { gen_case_insensitive(cpp2::move(lower), cpp2::move(upper), ctx); } @@ -4183,7 +4242,7 @@ size_t i{0}; } } -#line 2512 "reflect.h2" +#line 2552 "reflect.h2" auto char_token::gen_case_insensitive(cpp2::impl::in lower, cpp2::impl::in upper, generation_context& ctx) const& -> void { std::string name {"str_" + cpp2::to_string(ctx.gen_temp()) + ""}; @@ -4205,7 +4264,7 @@ size_t i{0}; ctx.add("else { break; }"); } -#line 2533 "reflect.h2" +#line 2573 "reflect.h2" auto char_token::gen_case_sensitive(generation_context& ctx) const& -> void { std::string name {"str_" + cpp2::to_string(ctx.gen_temp()) + ""}; @@ -4224,7 +4283,7 @@ size_t i{0}; ctx.add("else { break; }"); } -#line 2551 "reflect.h2" +#line 2591 "reflect.h2" [[nodiscard]] auto char_token::add_escapes(std::string str) const& -> std::string { str = string_util::replace_all(str, "\\", "\\\\"); @@ -4240,7 +4299,7 @@ size_t i{0}; return cpp2::move(str); } -#line 2566 "reflect.h2" +#line 2606 "reflect.h2" auto char_token::append(char_token const& that) & -> void{ (*this).token += that.token; (*this).string_rep += that.string_rep; @@ -4248,19 +4307,19 @@ size_t i{0}; char_token::~char_token() noexcept{} -#line 2583 "reflect.h2" +#line 2623 "reflect.h2" class_token::class_token(cpp2::impl::in negate_, cpp2::impl::in case_insensitive_, cpp2::impl::in class_str_, cpp2::impl::in str) : regex_token{ str } , negate{ negate_ } , case_insensitive{ case_insensitive_ } , class_str{ class_str_ } -#line 2584 "reflect.h2" +#line 2624 "reflect.h2" { -#line 2589 "reflect.h2" +#line 2629 "reflect.h2" } -#line 2592 "reflect.h2" +#line 2632 "reflect.h2" [[nodiscard]] auto class_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '[') {return nullptr; } @@ -4386,13 +4445,13 @@ size_t i{0}; ); } -#line 2717 "reflect.h2" +#line 2757 "reflect.h2" auto class_token::generate_code(generation_context& ctx) const -> void { ctx.add_check("class_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ")"); } -#line 2722 "reflect.h2" +#line 2762 "reflect.h2" [[nodiscard]] auto class_token::create_matcher(cpp2::impl::in name, cpp2::impl::in template_arguments) -> std::string { auto sep {", "}; @@ -4403,12 +4462,12 @@ size_t i{0}; class_token::~class_token() noexcept{} -#line 2734 "reflect.h2" +#line 2774 "reflect.h2" [[nodiscard]] auto escape_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } -#line 2739 "reflect.h2" +#line 2779 "reflect.h2" if (std::string::npos == std::string("afenrt^.[]()*{}?+|\\").find(ctx.peek())) { return nullptr; } @@ -4442,7 +4501,7 @@ size_t i{0}; } -#line 2775 "reflect.h2" +#line 2815 "reflect.h2" [[nodiscard]] auto global_group_reset_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'K'))) {return nullptr; } @@ -4451,18 +4510,18 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, "\\K", "ctx..set_group_start(0, r.pos);"); } -#line 2797 "reflect.h2" +#line 2837 "reflect.h2" group_ref_token::group_ref_token(cpp2::impl::in id_, cpp2::impl::in case_insensitive_, cpp2::impl::in str) : regex_token{ str } , id{ id_ } , case_insensitive{ case_insensitive_ } -#line 2798 "reflect.h2" +#line 2838 "reflect.h2" { -#line 2802 "reflect.h2" +#line 2842 "reflect.h2" } -#line 2804 "reflect.h2" +#line 2844 "reflect.h2" [[nodiscard]] auto group_ref_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -4564,14 +4623,14 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, cpp2::move(group_id), ctx.get_modifiers().has(expression_flags::case_insensitive), cpp2::move(str)); } -#line 2905 "reflect.h2" +#line 2945 "reflect.h2" auto group_ref_token::generate_code(generation_context& ctx) const -> void{ ctx.add_check("group_ref_token_matcher(" + cpp2::to_string(ctx.match_parameters()) + ")"); } group_ref_token::~group_ref_token() noexcept{} -#line 2928 "reflect.h2" +#line 2968 "reflect.h2" [[nodiscard]] auto group_token::parse_lookahead(parse_context& ctx, cpp2::impl::in syntax, cpp2::impl::in positive) -> token_ptr { static_cast(ctx.next());// Skip last token defining the syntax @@ -4586,7 +4645,7 @@ size_t i{0}; return r; } -#line 2942 "reflect.h2" +#line 2982 "reflect.h2" [[nodiscard]] auto group_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '(') {return nullptr; } @@ -4724,7 +4783,7 @@ size_t i{0}; } } -#line 3079 "reflect.h2" +#line 3119 "reflect.h2" [[nodiscard]] auto group_token::gen_string(cpp2::impl::in name, cpp2::impl::in name_brackets, cpp2::impl::in has_modifier, cpp2::impl::in modifiers, cpp2::impl::in inner_) -> std::string { std::string start {"("}; @@ -4743,7 +4802,7 @@ size_t i{0}; return cpp2::move(start) + (*cpp2::impl::assert_not_null(inner_)).to_string() + ")"; } -#line 3097 "reflect.h2" +#line 3137 "reflect.h2" auto group_token::generate_code(generation_context& ctx) const -> void { if (-1 != number) { @@ -4764,7 +4823,7 @@ size_t i{0}; } } -#line 3117 "reflect.h2" +#line 3157 "reflect.h2" auto group_token::add_groups(std::set& groups) const -> void { (*cpp2::impl::assert_not_null(inner)).add_groups(groups); @@ -4775,7 +4834,7 @@ size_t i{0}; group_token::~group_token() noexcept{} -#line 3129 "reflect.h2" +#line 3169 "reflect.h2" [[nodiscard]] auto hexadecimal_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'x'))) {return nullptr; } @@ -4814,7 +4873,7 @@ size_t i{0}; return r; } -#line 3170 "reflect.h2" +#line 3210 "reflect.h2" [[nodiscard]] auto line_end_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() == '$' || (ctx.current() == '\\' && ctx.peek() == '$')) { @@ -4832,7 +4891,7 @@ size_t i{0}; }} } -#line 3190 "reflect.h2" +#line 3230 "reflect.h2" [[nodiscard]] auto line_start_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '^' && !((ctx.current() == '\\' && ctx.peek() == 'A'))) {return nullptr; } @@ -4846,29 +4905,29 @@ size_t i{0}; } } -#line 3215 "reflect.h2" +#line 3255 "reflect.h2" lookahead_token::lookahead_token(cpp2::impl::in positive_) : regex_token{ "" } , positive{ positive_ }{ -#line 3217 "reflect.h2" +#line 3257 "reflect.h2" } -#line 3219 "reflect.h2" +#line 3259 "reflect.h2" auto lookahead_token::generate_code(generation_context& ctx) const -> void{ auto inner_name {ctx.generate_func(inner)}; ctx.add_check("lookahead_token_matcher(" + cpp2::to_string(ctx.match_parameters()) + ", " + cpp2::to_string(cpp2::move(inner_name)) + ")"); } -#line 3225 "reflect.h2" +#line 3265 "reflect.h2" auto lookahead_token::add_groups(std::set& groups) const -> void{ (*cpp2::impl::assert_not_null(inner)).add_groups(groups); } lookahead_token::~lookahead_token() noexcept{} -#line 3233 "reflect.h2" +#line 3273 "reflect.h2" [[nodiscard]] auto named_class_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -4894,7 +4953,7 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, "\\" + cpp2::to_string(ctx.current()) + "", "" + cpp2::to_string(cpp2::move(name)) + "::match"); } -#line 3261 "reflect.h2" +#line 3301 "reflect.h2" [[nodiscard]] auto octal_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'o'))) {return nullptr; } @@ -4920,11 +4979,11 @@ size_t i{0}; return r; } -#line 3298 "reflect.h2" +#line 3338 "reflect.h2" range_token::range_token() : regex_token{ "" }{} -#line 3300 "reflect.h2" +#line 3340 "reflect.h2" [[nodiscard]] auto range_token::parse(parse_context& ctx) -> token_ptr { auto r {CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared)}; @@ -4998,7 +5057,7 @@ size_t i{0}; return nullptr; } -#line 3373 "reflect.h2" +#line 3413 "reflect.h2" auto range_token::parse_modifier(parse_context& ctx) & -> void { if (ctx.peek() == '?') { @@ -5011,7 +5070,7 @@ size_t i{0}; }} } -#line 3385 "reflect.h2" +#line 3425 "reflect.h2" [[nodiscard]] auto range_token::gen_mod_string() const& -> std::string { if (kind == range_flags::not_greedy) { @@ -5025,7 +5084,7 @@ size_t i{0}; }} } -#line 3398 "reflect.h2" +#line 3438 "reflect.h2" [[nodiscard]] auto range_token::gen_range_string() const& -> std::string { std::string r {""}; @@ -5045,7 +5104,7 @@ size_t i{0}; return r; } -#line 3417 "reflect.h2" +#line 3457 "reflect.h2" auto range_token::generate_code(generation_context& ctx) const -> void { auto inner_name {ctx.generate_func(inner_token)}; @@ -5057,14 +5116,14 @@ size_t i{0}; ctx.add_statefull(next_name, "cpp2::regex::range_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ", " + cpp2::to_string(cpp2::move(inner_name)) + ", " + cpp2::to_string(cpp2::move(reset_name)) + ", other, " + cpp2::to_string(next_name) + ")"); } -#line 3428 "reflect.h2" +#line 3468 "reflect.h2" auto range_token::add_groups(std::set& groups) const -> void{ (*cpp2::impl::assert_not_null(inner_token)).add_groups(groups); } range_token::~range_token() noexcept{} -#line 3441 "reflect.h2" +#line 3481 "reflect.h2" [[nodiscard]] auto special_range_token::parse(parse_context& ctx) -> token_ptr { auto r {CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared)}; @@ -5088,7 +5147,7 @@ size_t i{0}; if (!(ctx.has_token())) {return ctx.error("'" + cpp2::to_string(ctx.current()) + "' without previous element."); } -#line 3465 "reflect.h2" +#line 3505 "reflect.h2" (*cpp2::impl::assert_not_null(r)).parse_modifier(ctx); (*cpp2::impl::assert_not_null(r)).inner_token = ctx.pop_token(); @@ -5098,7 +5157,7 @@ size_t i{0}; special_range_token::~special_range_token() noexcept{} -#line 3478 "reflect.h2" +#line 3518 "reflect.h2" [[nodiscard]] auto word_boundary_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -5116,15 +5175,15 @@ size_t i{0}; }} } -#line 3514 "reflect.h2" +#line 3554 "reflect.h2" template regex_generator::regex_generator(cpp2::impl::in r, Error_out const& e) : regex{ r } , error_out{ e }{ -#line 3517 "reflect.h2" +#line 3557 "reflect.h2" } -#line 3519 "reflect.h2" +#line 3559 "reflect.h2" template [[nodiscard]] auto regex_generator::parse() & -> std::string { // Extract modifiers and adapt regex. @@ -5160,7 +5219,7 @@ size_t i{0}; return source; } -#line 3554 "reflect.h2" +#line 3594 "reflect.h2" template auto regex_generator::extract_modifiers() & -> void { if (regex.find_first_of("'/") == 0) { @@ -5176,7 +5235,7 @@ size_t i{0}; } } -#line 3570 "reflect.h2" +#line 3610 "reflect.h2" template [[nodiscard]] auto generate_regex(cpp2::impl::in regex, Err const& err) -> std::string { regex_generator parser {regex, err}; @@ -5185,7 +5244,7 @@ template [[nodiscard]] auto generate_regex(cpp2::impl::in void { auto has_default {false}; @@ -5240,7 +5299,7 @@ auto regex_gen(meta::type_declaration& t) -> void CPP2_UFCS(add_runtime_support_include)(t, "cpp2regex.h"); } -#line 3639 "reflect.h2" +#line 3679 "reflect.h2" [[nodiscard]] auto apply_metafunctions( declaration_node& n, type_declaration& rtype, @@ -5355,7 +5414,7 @@ auto regex_gen(meta::type_declaration& t) -> void return true; } -#line 3758 "reflect.h2" +#line 3798 "reflect.h2" [[nodiscard]] auto apply_metafunctions( declaration_node& n, function_declaration& rfunc, @@ -5405,7 +5464,7 @@ auto regex_gen(meta::type_declaration& t) -> void return true; } -#line 3808 "reflect.h2" +#line 3848 "reflect.h2" } } diff --git a/source/reflect.h2 b/source/reflect.h2 index 1de380dc5..dbab4e77c 100644 --- a/source/reflect.h2 +++ b/source/reflect.h2 @@ -35,29 +35,32 @@ compiler_services: @polymorphic_base @copyable type = { // Common data members // - errors : *std::vector; - includes : *std::set; - errors_original_size : int; - generated_tokens : *stable_vector; - parser : cpp2::parser; - metafunction_name : std::string = (); - metafunction_args : std::vector = (); - metafunctions_used : bool = false; + errors : *std::vector; + includes : *std::set; + errors_original_size : int; + generated_tokens : *stable_vector; + generated_declarations: *std::vector>; + parser : cpp2::parser; + metafunction_name : std::string = (); + metafunction_args : std::vector = (); + metafunctions_used : bool = false; // Constructor // operator=: ( out this, - errors_ : *std::vector, - includes_ : *std::set, - generated_tokens_: *stable_vector + errors_ : *std::vector, + includes_ : *std::set, + generated_tokens_ : *stable_vector, + generated_declarations_ : *std::vector>, ) = { - errors = errors_; - includes = includes_; - errors_original_size = cpp2::unsafe_narrow(std::ssize(errors*)); - generated_tokens = generated_tokens_; - parser = (errors*, includes*); + errors = errors_; + includes = includes_; + errors_original_size = cpp2::unsafe_narrow(std::ssize(errors*)); + generated_tokens = generated_tokens_; + generated_declarations = generated_declarations_; + parser = (errors*, includes*); } // Common API @@ -85,23 +88,19 @@ compiler_services: @polymorphic_base @copyable type = arguments_were_used: (this) -> bool = metafunctions_used; - protected parse_statement: ( + private lex_multiline: ( inout this, copy source: std::string_view ) - -> (ret: std::unique_ptr) + -> *tokens = { - original_source := source; - - generated_lines.push_back( std::vector() ); - lines := generated_lines.back()&; + lines := generated_lines.emplace_back()&; add_line := :(s: std::string_view) = { _ = lines$*.emplace_back( s, source_line::category::cpp2 ); }; // First split this string into source_lines - // (copy newline_pos := source.find('\n')) if source.ssize() > 1 && newline_pos != source.npos @@ -125,21 +124,55 @@ compiler_services: @polymorphic_base @copyable type = tokens := generated_lexers.back()&; tokens*.lex( lines*, true ); - assert( std::ssize(tokens* .get_map()) == 1 ); + assert( std::ssize(tokens*.get_map()) == 1 ); - // Now parse this single declaration from - // the lexed tokens - ret = parser.parse_one_declaration( + return tokens; + } + + protected parse_statement: ( + inout this, + copy source: std::string_view + ) + -> (stmt: std::unique_ptr) + = { + original_source := source; + + tokens := lex_multiline(source); + + // Now parse a single *statement* from the lexed tokens + stmt = parser.parse_one_statement( tokens*.get_map().begin()*.second, generated_tokens* ); - if !ret { + if !stmt { error( "parse failed - the source string is not a valid statement:\n(original_source)$"); } } add_runtime_support_include: (inout this, s: std::string_view) = _=includes*.emplace( s ); + protected parse_and_add_declaration: ( + inout this, + copy source: std::string_view + ) + -> bool + = { + tokens := lex_multiline(source); + + // Now parse a single *declaration* from the lexed tokens + decl := parser.parse_one_declaration( + tokens*.get_map().begin()*.second, + generated_tokens* + ); + + result := decl as bool; + + // Save it aside to be added later to the translation unit + if decl { generated_declarations*.push_back(move decl); } + + return result; + } + position: (virtual this) -> source_position = { @@ -181,6 +214,13 @@ compiler_services: @polymorphic_base @copyable type = } is_active:(this) true; + + append_declaration_to_translation_unit: (inout this, source: std::string_view) + = { + if !parse_and_add_declaration(source) { + error( "error attempting to add declaration:\n\t(source)$" ); + } + } } diff --git a/source/sema.h b/source/sema.h index 1060ec64e..f8fd2e68d 100644 --- a/source/sema.h +++ b/source/sema.h @@ -29,7 +29,7 @@ auto parser::apply_type_metafunctions( declaration_node& n ) assert(n.is_type()); // Get the reflection state ready to pass to the function - auto cs = meta::compiler_services{ &errors, &includes, generated_tokens }; + auto cs = meta::compiler_services{ &errors, &includes, generated_tokens, &generated_declarations }; auto rtype = meta::type_declaration{ &n, cs }; return apply_metafunctions( @@ -45,7 +45,7 @@ auto parser::apply_function_metafunctions( declaration_node& n ) assert(n.is_function()); // Get the reflection state ready to pass to the function - auto cs = meta::compiler_services{ &errors, &includes, generated_tokens }; + auto cs = meta::compiler_services{ &errors, &includes, generated_tokens, &generated_declarations }; auto rfunc = meta::function_declaration{ &n, cs }; return apply_metafunctions( From a6d0093382bb643c183fc5171b41b0b85ad2afcd Mon Sep 17 00:00:00 2001 From: Dylam De La Torre Date: Sun, 24 Mar 2024 01:17:22 +0100 Subject: [PATCH 3/9] Add fully_qualified_name() to reflection API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Johel Ernesto Guerrero Peña --- source/parse.h | 19 + source/reflect.h | 1104 +++++++++++++++++++++++---------------------- source/reflect.h2 | 1 + 3 files changed, 574 insertions(+), 550 deletions(-) diff --git a/source/parse.h b/source/parse.h index 3c3ed7564..225028883 100644 --- a/source/parse.h +++ b/source/parse.h @@ -3063,6 +3063,25 @@ struct declaration_node ; } + auto fully_qualified_name() const + -> std::string + { + if (!has_name()) { + return {}; + } + + auto res = std::string{}; + for (auto n = this; n; n = n->parent_declaration) + { + assert(n->identifier); + if(auto id = n->identifier->to_string(); id != "_") { + res.insert(0, id); + res.insert(0, "::"); + } + } + return res; + } + auto has_initializer() const -> bool { diff --git a/source/reflect.h b/source/reflect.h index 6c4c87972..f3d9f1f8e 100644 --- a/source/reflect.h +++ b/source/reflect.h @@ -24,89 +24,89 @@ class declaration_base; #line 299 "reflect.h2" class declaration; -#line 381 "reflect.h2" +#line 382 "reflect.h2" class function_declaration; -#line 471 "reflect.h2" +#line 472 "reflect.h2" class object_declaration; -#line 507 "reflect.h2" +#line 508 "reflect.h2" class type_declaration; -#line 644 "reflect.h2" +#line 645 "reflect.h2" class alias_declaration; -#line 1052 "reflect.h2" +#line 1053 "reflect.h2" class value_member_info; -#line 1574 "reflect.h2" +#line 1575 "reflect.h2" class expression_flags; -#line 1590 "reflect.h2" +#line 1591 "reflect.h2" class regex_token; -#line 1616 "reflect.h2" +#line 1617 "reflect.h2" class regex_token_check; -#line 1635 "reflect.h2" +#line 1636 "reflect.h2" class regex_token_code; -#line 1654 "reflect.h2" +#line 1655 "reflect.h2" class regex_token_empty; -#line 1670 "reflect.h2" +#line 1671 "reflect.h2" class regex_token_list; -#line 1709 "reflect.h2" +#line 1710 "reflect.h2" class parse_context_group_state; -#line 1770 "reflect.h2" +#line 1771 "reflect.h2" class parse_context_branch_reset_state; -#line 1813 "reflect.h2" +#line 1814 "reflect.h2" class parse_context; -#line 2211 "reflect.h2" +#line 2212 "reflect.h2" class generation_function_context; -#line 2229 "reflect.h2" +#line 2230 "reflect.h2" class generation_context; -#line 2427 "reflect.h2" +#line 2428 "reflect.h2" class alternative_token; -#line 2442 "reflect.h2" +#line 2443 "reflect.h2" class alternative_token_gen; -#line 2494 "reflect.h2" +#line 2495 "reflect.h2" class any_token; -#line 2512 "reflect.h2" +#line 2513 "reflect.h2" class char_token; -#line 2615 "reflect.h2" +#line 2616 "reflect.h2" class class_token; -#line 2830 "reflect.h2" +#line 2831 "reflect.h2" class group_ref_token; -#line 2961 "reflect.h2" +#line 2962 "reflect.h2" class group_token; -#line 3248 "reflect.h2" +#line 3249 "reflect.h2" class lookahead_token; -#line 3329 "reflect.h2" +#line 3330 "reflect.h2" class range_token; -#line 3477 "reflect.h2" +#line 3478 "reflect.h2" class special_range_token; -#line 3544 "reflect.h2" +#line 3545 "reflect.h2" template class regex_generator; -#line 3848 "reflect.h2" +#line 3849 "reflect.h2" } } @@ -280,7 +280,9 @@ class declaration public: [[nodiscard]] auto name() const& -> std::string_view; -#line 333 "reflect.h2" +#line 332 "reflect.h2" + public: [[nodiscard]] auto fully_qualified_name() const& -> std::string; + public: [[nodiscard]] auto has_initializer() const& -> bool; public: [[nodiscard]] auto is_global() const& -> bool; @@ -322,21 +324,21 @@ class declaration public: declaration(declaration const& that); -#line 375 "reflect.h2" +#line 376 "reflect.h2" }; -#line 381 "reflect.h2" +#line 382 "reflect.h2" class function_declaration : public declaration { -#line 385 "reflect.h2" +#line 386 "reflect.h2" public: explicit function_declaration( declaration_node* n_, cpp2::impl::in s ); -#line 395 "reflect.h2" +#line 396 "reflect.h2" public: [[nodiscard]] auto index_of_parameter_named(cpp2::impl::in s) const& -> int; public: [[nodiscard]] auto has_parameter_named(cpp2::impl::in s) const& -> bool; public: [[nodiscard]] auto has_in_parameter_named(cpp2::impl::in s) const& -> bool; @@ -376,7 +378,7 @@ class function_declaration public: [[nodiscard]] auto get_parameters() const& -> std::vector; -#line 442 "reflect.h2" +#line 443 "reflect.h2" public: [[nodiscard]] auto is_binary_comparison_function() const& -> bool; public: auto default_to_virtual() & -> void; @@ -387,94 +389,94 @@ class function_declaration public: function_declaration(function_declaration const& that); -#line 465 "reflect.h2" +#line 466 "reflect.h2" }; -#line 471 "reflect.h2" +#line 472 "reflect.h2" class object_declaration : public declaration { -#line 475 "reflect.h2" +#line 476 "reflect.h2" public: explicit object_declaration( declaration_node* n_, cpp2::impl::in s ); -#line 485 "reflect.h2" +#line 486 "reflect.h2" public: [[nodiscard]] auto is_const() const& -> bool; public: [[nodiscard]] auto has_wildcard_type() const& -> bool; public: [[nodiscard]] auto type() const& -> std::string; -#line 495 "reflect.h2" +#line 496 "reflect.h2" public: [[nodiscard]] auto initializer() const& -> std::string; public: object_declaration(object_declaration const& that); -#line 501 "reflect.h2" +#line 502 "reflect.h2" }; -#line 507 "reflect.h2" +#line 508 "reflect.h2" class type_declaration : public declaration { -#line 511 "reflect.h2" +#line 512 "reflect.h2" public: explicit type_declaration( declaration_node* n_, cpp2::impl::in s ); -#line 521 "reflect.h2" +#line 522 "reflect.h2" public: auto reserve_names(cpp2::impl::in name, auto&& ...etc) const& -> void; -#line 535 "reflect.h2" +#line 536 "reflect.h2" public: [[nodiscard]] auto is_polymorphic() const& -> bool; public: [[nodiscard]] auto is_final() const& -> bool; public: [[nodiscard]] auto make_final() & -> bool; public: [[nodiscard]] auto get_member_functions() const& -> std::vector; -#line 550 "reflect.h2" +#line 551 "reflect.h2" public: [[nodiscard]] auto get_member_functions_needing_initializer() const& -> std::vector; -#line 565 "reflect.h2" +#line 566 "reflect.h2" public: [[nodiscard]] auto get_member_objects() const& -> std::vector; -#line 575 "reflect.h2" +#line 576 "reflect.h2" public: [[nodiscard]] auto get_member_types() const& -> std::vector; -#line 585 "reflect.h2" +#line 586 "reflect.h2" public: [[nodiscard]] auto get_member_aliases() const& -> std::vector; -#line 595 "reflect.h2" +#line 596 "reflect.h2" public: [[nodiscard]] auto get_members() const& -> std::vector; struct query_declared_value_set_functions_ret { bool out_this_in_that; bool out_this_move_that; bool inout_this_in_that; bool inout_this_move_that; }; -#line 605 "reflect.h2" +#line 606 "reflect.h2" public: [[nodiscard]] auto query_declared_value_set_functions() const& -> query_declared_value_set_functions_ret; -#line 620 "reflect.h2" +#line 621 "reflect.h2" public: auto add_member(cpp2::impl::in source) & -> void; -#line 634 "reflect.h2" +#line 635 "reflect.h2" public: auto remove_marked_members() & -> void; public: auto remove_all_members() & -> void; public: auto disable_member_function_generation() & -> void; public: type_declaration(type_declaration const& that); -#line 638 "reflect.h2" +#line 639 "reflect.h2" }; -#line 644 "reflect.h2" +#line 645 "reflect.h2" class alias_declaration : public declaration { -#line 648 "reflect.h2" +#line 649 "reflect.h2" public: explicit alias_declaration( declaration_node* n_, @@ -483,62 +485,62 @@ class alias_declaration public: alias_declaration(alias_declaration const& that); -#line 657 "reflect.h2" +#line 658 "reflect.h2" }; -#line 672 "reflect.h2" +#line 673 "reflect.h2" auto add_virtual_destructor(meta::type_declaration& t) -> void; -#line 690 "reflect.h2" +#line 691 "reflect.h2" auto interface(meta::type_declaration& t) -> void; -#line 736 "reflect.h2" +#line 737 "reflect.h2" auto polymorphic_base(meta::type_declaration& t) -> void; -#line 781 "reflect.h2" +#line 782 "reflect.h2" auto ordered_impl( meta::type_declaration& t, cpp2::impl::in ordering ) -> void; -#line 810 "reflect.h2" +#line 811 "reflect.h2" auto ordered(meta::type_declaration& t) -> void; -#line 818 "reflect.h2" +#line 819 "reflect.h2" auto weakly_ordered(meta::type_declaration& t) -> void; -#line 826 "reflect.h2" +#line 827 "reflect.h2" auto partially_ordered(meta::type_declaration& t) -> void; -#line 848 "reflect.h2" +#line 849 "reflect.h2" auto copyable(meta::type_declaration& t) -> void; -#line 882 "reflect.h2" +#line 883 "reflect.h2" auto basic_value(meta::type_declaration& t) -> void; -#line 910 "reflect.h2" +#line 911 "reflect.h2" auto value(meta::type_declaration& t) -> void; -#line 916 "reflect.h2" +#line 917 "reflect.h2" auto weakly_ordered_value(meta::type_declaration& t) -> void; -#line 922 "reflect.h2" +#line 923 "reflect.h2" auto partially_ordered_value(meta::type_declaration& t) -> void; -#line 951 "reflect.h2" +#line 952 "reflect.h2" auto cpp1_rule_of_zero(meta::type_declaration& t) -> void; -#line 988 "reflect.h2" +#line 989 "reflect.h2" auto cpp2_struct(meta::type_declaration& t) -> void; -#line 1052 "reflect.h2" +#line 1053 "reflect.h2" class value_member_info { public: std::string name; public: std::string type; public: std::string value; public: value_member_info(auto const& name_, auto const& type_, auto const& value_); -#line 1056 "reflect.h2" +#line 1057 "reflect.h2" }; auto basic_enum( @@ -547,25 +549,25 @@ auto basic_enum( cpp2::impl::in bitwise ) -> void; -#line 1322 "reflect.h2" +#line 1323 "reflect.h2" auto cpp2_enum(meta::type_declaration& t) -> void; -#line 1349 "reflect.h2" +#line 1350 "reflect.h2" auto flag_enum(meta::type_declaration& t) -> void; -#line 1395 "reflect.h2" +#line 1396 "reflect.h2" auto cpp2_union(meta::type_declaration& t) -> void; -#line 1546 "reflect.h2" +#line 1547 "reflect.h2" auto print(cpp2::impl::in t) -> void; -#line 1551 "reflect.h2" +#line 1552 "reflect.h2" auto print(cpp2::impl::in f) -> void; -#line 1570 "reflect.h2" +#line 1571 "reflect.h2" using error_func = std::function x)>; -#line 1574 "reflect.h2" +#line 1575 "reflect.h2" class expression_flags { private: cpp2::u8 _value; private: constexpr expression_flags(cpp2::impl::in _val); @@ -600,20 +602,20 @@ public: [[nodiscard]] auto to_code() const& -> std::string; public: [[nodiscard]] static auto from_string(cpp2::impl::in s) -> expression_flags; public: [[nodiscard]] static auto from_code(cpp2::impl::in s) -> expression_flags; -#line 1582 "reflect.h2" +#line 1583 "reflect.h2" }; -#line 1590 "reflect.h2" +#line 1591 "reflect.h2" class regex_token { public: std::string string_rep; public: explicit regex_token(cpp2::impl::in str); -#line 1598 "reflect.h2" +#line 1599 "reflect.h2" public: explicit regex_token(); -#line 1603 "reflect.h2" +#line 1604 "reflect.h2" public: virtual auto generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void = 0; public: virtual auto add_groups([[maybe_unused]] std::set& unnamed_param_2) const -> void; @@ -624,24 +626,24 @@ class regex_token public: regex_token(regex_token const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(regex_token const&) -> void = delete; -#line 1608 "reflect.h2" +#line 1609 "reflect.h2" }; using token_ptr = std::shared_ptr; using token_vec = std::vector; -#line 1614 "reflect.h2" +#line 1615 "reflect.h2" // Adds a check in code generation. // class regex_token_check : public regex_token { -#line 1620 "reflect.h2" +#line 1621 "reflect.h2" private: std::string check; public: explicit regex_token_check(cpp2::impl::in str, cpp2::impl::in check_); -#line 1627 "reflect.h2" +#line 1628 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~regex_token_check() noexcept; @@ -649,21 +651,21 @@ class regex_token_check public: auto operator=(regex_token_check const&) -> void = delete; -#line 1630 "reflect.h2" +#line 1631 "reflect.h2" }; -#line 1633 "reflect.h2" +#line 1634 "reflect.h2" // Adds code in code generation. // class regex_token_code : public regex_token { -#line 1639 "reflect.h2" +#line 1640 "reflect.h2" private: std::string code; public: explicit regex_token_code(cpp2::impl::in str, cpp2::impl::in code_); -#line 1646 "reflect.h2" +#line 1647 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~regex_token_code() noexcept; @@ -671,19 +673,19 @@ class regex_token_code public: auto operator=(regex_token_code const&) -> void = delete; -#line 1649 "reflect.h2" +#line 1650 "reflect.h2" }; -#line 1652 "reflect.h2" +#line 1653 "reflect.h2" // Token that does not influence the matching. E.g. comment. // class regex_token_empty : public regex_token { -#line 1658 "reflect.h2" +#line 1659 "reflect.h2" public: explicit regex_token_empty(cpp2::impl::in str); -#line 1662 "reflect.h2" +#line 1663 "reflect.h2" public: auto generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void override; public: virtual ~regex_token_empty() noexcept; @@ -691,27 +693,27 @@ class regex_token_empty public: auto operator=(regex_token_empty const&) -> void = delete; -#line 1665 "reflect.h2" +#line 1666 "reflect.h2" }; -#line 1668 "reflect.h2" +#line 1669 "reflect.h2" // Represents a list of regex tokens as one token. // class regex_token_list : public regex_token { -#line 1674 "reflect.h2" +#line 1675 "reflect.h2" public: token_vec tokens; public: explicit regex_token_list(cpp2::impl::in t); -#line 1681 "reflect.h2" +#line 1682 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 1687 "reflect.h2" +#line 1688 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; -#line 1693 "reflect.h2" +#line 1694 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in vec) -> std::string; public: virtual ~regex_token_list() noexcept; @@ -719,10 +721,10 @@ class regex_token_list public: auto operator=(regex_token_list const&) -> void = delete; -#line 1700 "reflect.h2" +#line 1701 "reflect.h2" }; -#line 1703 "reflect.h2" +#line 1704 "reflect.h2" // // Parse and generation context. // @@ -738,33 +740,33 @@ class parse_context_group_state // Start a new alternative. public: auto next_alternative() & -> void; -#line 1723 "reflect.h2" +#line 1724 "reflect.h2" // Swap this state with the other one. public: auto swap(parse_context_group_state& t) & -> void; -#line 1730 "reflect.h2" +#line 1731 "reflect.h2" // Convert this state into a regex token. public: [[nodiscard]] auto get_as_token() & -> token_ptr; -#line 1742 "reflect.h2" +#line 1743 "reflect.h2" // Add a token to the current matcher list. public: auto add(cpp2::impl::in token) & -> void; -#line 1747 "reflect.h2" +#line 1748 "reflect.h2" // True if current matcher list is empty. public: [[nodiscard]] auto empty() const& -> bool; -#line 1751 "reflect.h2" +#line 1752 "reflect.h2" // Apply optimizations to the matcher list. public: static auto post_process_list(token_vec& list) -> void; public: parse_context_group_state(auto const& cur_match_list_, auto const& alternate_match_lists_, auto const& modifiers_); public: parse_context_group_state(); -#line 1765 "reflect.h2" +#line 1766 "reflect.h2" }; -#line 1768 "reflect.h2" +#line 1769 "reflect.h2" // State for the branch reset. Takes care of the group numbering. See '(|)'. // class parse_context_branch_reset_state @@ -777,25 +779,25 @@ class parse_context_branch_reset_state // Next group identifier. public: [[nodiscard]] auto next() & -> int; -#line 1786 "reflect.h2" +#line 1787 "reflect.h2" // Set next group identifier. public: auto set_next(cpp2::impl::in g) & -> void; -#line 1792 "reflect.h2" +#line 1793 "reflect.h2" // Start a new alternative branch. public: auto next_alternative() & -> void; -#line 1799 "reflect.h2" +#line 1800 "reflect.h2" // Initialize for a branch reset group. public: auto set_active_reset(cpp2::impl::in restart) & -> void; public: parse_context_branch_reset_state(auto const& is_active_, auto const& cur_group_, auto const& max_group_, auto const& from_); public: parse_context_branch_reset_state(); -#line 1806 "reflect.h2" +#line 1807 "reflect.h2" }; -#line 1809 "reflect.h2" +#line 1810 "reflect.h2" // Context during parsing of the regular expressions. // // Keeps track of the distributed group identifiers, current parsed group and branch resets. @@ -809,7 +811,7 @@ class parse_context private: parse_context_group_state cur_group_state {}; private: parse_context_branch_reset_state cur_branch_reset_state {}; -#line 1823 "reflect.h2" +#line 1824 "reflect.h2" public: std::map named_groups {}; private: error_func error_out; // TODO: Declaring std::function fails for cpp2. @@ -817,64 +819,64 @@ class parse_context public: explicit parse_context(cpp2::impl::in r, auto const& e); -#line 1834 "reflect.h2" +#line 1835 "reflect.h2" // State management functions // // Returned group state needs to be stored and provided in `end_group`. public: [[nodiscard]] auto start_group() & -> parse_context_group_state; -#line 1847 "reflect.h2" +#line 1848 "reflect.h2" // `old_state` argument needs to be from start group. public: [[nodiscard]] auto end_group(cpp2::impl::in old_state) & -> token_ptr; -#line 1855 "reflect.h2" +#line 1856 "reflect.h2" public: [[nodiscard]] auto get_modifiers() const& -> expression_flags; -#line 1859 "reflect.h2" +#line 1860 "reflect.h2" public: auto set_modifiers(cpp2::impl::in mod) & -> void; -#line 1863 "reflect.h2" +#line 1864 "reflect.h2" // Branch reset management functions // public: [[nodiscard]] auto branch_reset_new_state() & -> parse_context_branch_reset_state; -#line 1875 "reflect.h2" +#line 1876 "reflect.h2" public: auto branch_reset_restore_state(cpp2::impl::in old_state) & -> void; -#line 1882 "reflect.h2" +#line 1883 "reflect.h2" public: auto next_alternative() & -> void; -#line 1888 "reflect.h2" +#line 1889 "reflect.h2" // Regex token management // public: auto add_token(cpp2::impl::in token) & -> void; -#line 1894 "reflect.h2" +#line 1895 "reflect.h2" public: [[nodiscard]] auto has_token() const& -> bool; -#line 1898 "reflect.h2" +#line 1899 "reflect.h2" public: [[nodiscard]] auto pop_token() & -> token_ptr; -#line 1909 "reflect.h2" +#line 1910 "reflect.h2" public: [[nodiscard]] auto get_as_token() & -> token_ptr; -#line 1913 "reflect.h2" +#line 1914 "reflect.h2" // Group management // public: [[nodiscard]] auto get_cur_group() const& -> int; -#line 1919 "reflect.h2" +#line 1920 "reflect.h2" public: [[nodiscard]] auto next_group() & -> int; -#line 1923 "reflect.h2" +#line 1924 "reflect.h2" public: auto set_named_group(cpp2::impl::in name, cpp2::impl::in id) & -> void; -#line 1930 "reflect.h2" +#line 1931 "reflect.h2" public: [[nodiscard]] auto get_named_group(cpp2::impl::in name) const& -> int; -#line 1941 "reflect.h2" +#line 1942 "reflect.h2" // Position management functions // public: [[nodiscard]] auto current() const& -> char; @@ -882,51 +884,51 @@ class parse_context // Get the next token in the regex, skipping spaces according to the parameters. See `x` and `xx` modifiers. private: [[nodiscard]] auto get_next_position(cpp2::impl::in in_class, cpp2::impl::in no_skip) const& -> size_t; -#line 1985 "reflect.h2" +#line 1986 "reflect.h2" // Return true if next token is available. private: [[nodiscard]] auto next_impl(cpp2::impl::in in_class, cpp2::impl::in no_skip) & -> bool; -#line 1997 "reflect.h2" +#line 1998 "reflect.h2" public: [[nodiscard]] auto next() & -> auto; public: [[nodiscard]] auto next_in_class() & -> auto; public: [[nodiscard]] auto next_no_skip() & -> auto; public: [[nodiscard]] auto next_n(cpp2::impl::in n) & -> bool; -#line 2010 "reflect.h2" +#line 2011 "reflect.h2" public: [[nodiscard]] auto has_next() const& -> bool; private: [[nodiscard]] auto grab_until_impl(cpp2::impl::in e, cpp2::impl::out r, cpp2::impl::in any) & -> bool; -#line 2033 "reflect.h2" +#line 2034 "reflect.h2" public: [[nodiscard]] auto grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_until_one_of(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_n(cpp2::impl::in n, cpp2::impl::out r) & -> bool; -#line 2050 "reflect.h2" +#line 2051 "reflect.h2" public: [[nodiscard]] auto grab_number() & -> std::string; -#line 2071 "reflect.h2" +#line 2072 "reflect.h2" private: [[nodiscard]] auto peek_impl(cpp2::impl::in in_class) const& -> char; -#line 2081 "reflect.h2" +#line 2082 "reflect.h2" public: [[nodiscard]] auto peek() const& -> auto; public: [[nodiscard]] auto peek_in_class() const& -> auto; -#line 2085 "reflect.h2" +#line 2086 "reflect.h2" // Parsing functions // public: [[nodiscard]] auto parser_group_modifiers(cpp2::impl::in change_str, expression_flags& parser_modifiers) & -> bool; -#line 2141 "reflect.h2" +#line 2142 "reflect.h2" public: [[nodiscard]] auto parse_until(cpp2::impl::in term) & -> bool; -#line 2179 "reflect.h2" +#line 2180 "reflect.h2" public: [[nodiscard]] auto parse(cpp2::impl::in modifiers) & -> bool; -#line 2194 "reflect.h2" +#line 2195 "reflect.h2" // Misc functions public: [[nodiscard]] auto get_pos() const& -> auto; @@ -938,10 +940,10 @@ class parse_context public: auto operator=(parse_context const&) -> void = delete; -#line 2205 "reflect.h2" +#line 2206 "reflect.h2" }; -#line 2208 "reflect.h2" +#line 2209 "reflect.h2" // Context for one function generation. Generation of functions can be interleaved, // therefore we buffer the code for one function here. // @@ -951,16 +953,16 @@ class generation_function_context { public: auto add_tabs(cpp2::impl::in c) & -> void; -#line 2222 "reflect.h2" +#line 2223 "reflect.h2" public: auto remove_tabs(cpp2::impl::in c) & -> void; public: generation_function_context(auto const& code_, auto const& tabs_); public: generation_function_context(); -#line 2225 "reflect.h2" +#line 2226 "reflect.h2" }; -#line 2228 "reflect.h2" +#line 2229 "reflect.h2" // Context for generating the state machine. class generation_context { @@ -980,68 +982,68 @@ class generation_context // Add code line. public: auto add(cpp2::impl::in s) & -> void; -#line 2250 "reflect.h2" +#line 2251 "reflect.h2" // Add check for token. The check needs to be a function call that returns a boolean. public: auto add_check(cpp2::impl::in check) & -> void; -#line 2256 "reflect.h2" +#line 2257 "reflect.h2" // Add a stateful check. The check needs to return a `match_return`. public: auto add_statefull(cpp2::impl::in next_func, cpp2::impl::in check) & -> void; -#line 2265 "reflect.h2" +#line 2266 "reflect.h2" protected: auto start_func_named(cpp2::impl::in name) & -> void; -#line 2276 "reflect.h2" +#line 2277 "reflect.h2" protected: [[nodiscard]] auto start_func() & -> std::string; -#line 2283 "reflect.h2" +#line 2284 "reflect.h2" protected: auto end_func_statefull(cpp2::impl::in s) & -> void; -#line 2302 "reflect.h2" +#line 2303 "reflect.h2" // Generate the function for a token. public: [[nodiscard]] auto generate_func(cpp2::impl::in token) & -> std::string; -#line 2312 "reflect.h2" +#line 2313 "reflect.h2" // Generate the reset for a list of group identifiers. public: [[nodiscard]] auto generate_reset(cpp2::impl::in> groups) & -> std::string; -#line 2335 "reflect.h2" +#line 2336 "reflect.h2" // Name generation // protected: [[nodiscard]] auto gen_func_name() & -> std::string; -#line 2343 "reflect.h2" +#line 2344 "reflect.h2" public: [[nodiscard]] auto next_func_name() & -> std::string; -#line 2347 "reflect.h2" +#line 2348 "reflect.h2" protected: [[nodiscard]] auto gen_reset_func_name() & -> std::string; -#line 2353 "reflect.h2" +#line 2354 "reflect.h2" public: [[nodiscard]] auto gen_temp() & -> std::string; -#line 2359 "reflect.h2" +#line 2360 "reflect.h2" // Context management // public: [[nodiscard]] auto new_context() & -> generation_function_context*; -#line 2369 "reflect.h2" +#line 2370 "reflect.h2" public: auto finish_context() & -> void; -#line 2377 "reflect.h2" +#line 2378 "reflect.h2" // Misc functions // private: [[nodiscard]] auto get_current() & -> generation_function_context*; -#line 2383 "reflect.h2" +#line 2384 "reflect.h2" private: [[nodiscard]] auto get_base() & -> generation_function_context*; -#line 2387 "reflect.h2" +#line 2388 "reflect.h2" public: [[nodiscard]] auto get_entry_func() const& -> std::string; -#line 2391 "reflect.h2" +#line 2392 "reflect.h2" public: [[nodiscard]] auto create_named_group_lookup(cpp2::impl::in> named_groups) const& -> std::string; -#line 2415 "reflect.h2" +#line 2416 "reflect.h2" // Run the generation for the token. public: [[nodiscard]] auto run(cpp2::impl::in token) & -> std::string; public: generation_context() = default; @@ -1049,7 +1051,7 @@ class generation_context public: auto operator=(generation_context const&) -> void = delete; -#line 2421 "reflect.h2" +#line 2422 "reflect.h2" }; // Regex syntax: | Example: ab|ba @@ -1069,24 +1071,24 @@ class alternative_token public: auto operator=(alternative_token const&) -> void = delete; -#line 2440 "reflect.h2" +#line 2441 "reflect.h2" }; class alternative_token_gen : public regex_token { -#line 2446 "reflect.h2" +#line 2447 "reflect.h2" private: token_vec alternatives; public: explicit alternative_token_gen(cpp2::impl::in a); -#line 2453 "reflect.h2" +#line 2454 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2470 "reflect.h2" +#line 2471 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; -#line 2477 "reflect.h2" +#line 2478 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in a) -> std::string; public: virtual ~alternative_token_gen() noexcept; @@ -1094,19 +1096,19 @@ class alternative_token_gen public: auto operator=(alternative_token_gen const&) -> void = delete; -#line 2489 "reflect.h2" +#line 2490 "reflect.h2" }; -#line 2492 "reflect.h2" +#line 2493 "reflect.h2" // Regex syntax: . // class any_token : public regex_token_check { -#line 2498 "reflect.h2" +#line 2499 "reflect.h2" public: explicit any_token(cpp2::impl::in single_line); -#line 2502 "reflect.h2" +#line 2503 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; public: virtual ~any_token() noexcept; @@ -1114,37 +1116,37 @@ class any_token public: auto operator=(any_token const&) -> void = delete; -#line 2507 "reflect.h2" +#line 2508 "reflect.h2" }; -#line 2510 "reflect.h2" +#line 2511 "reflect.h2" // Regex syntax: a // class char_token : public regex_token { -#line 2516 "reflect.h2" +#line 2517 "reflect.h2" private: std::string token; private: bool ignore_case; public: explicit char_token(cpp2::impl::in t, cpp2::impl::in ignore_case_); -#line 2525 "reflect.h2" +#line 2526 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 2529 "reflect.h2" +#line 2530 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2552 "reflect.h2" +#line 2553 "reflect.h2" public: auto gen_case_insensitive(cpp2::impl::in lower, cpp2::impl::in upper, generation_context& ctx) const& -> void; -#line 2573 "reflect.h2" +#line 2574 "reflect.h2" public: auto gen_case_sensitive(generation_context& ctx) const& -> void; -#line 2591 "reflect.h2" +#line 2592 "reflect.h2" public: [[nodiscard]] auto add_escapes(std::string str) const& -> std::string; -#line 2606 "reflect.h2" +#line 2607 "reflect.h2" public: auto append(char_token const& that) & -> void; public: virtual ~char_token() noexcept; @@ -1152,30 +1154,30 @@ class char_token public: auto operator=(char_token const&) -> void = delete; -#line 2610 "reflect.h2" +#line 2611 "reflect.h2" }; -#line 2613 "reflect.h2" +#line 2614 "reflect.h2" // Regex syntax: [] Example: [abcx-y[:digits:]] // class class_token : public regex_token { -#line 2619 "reflect.h2" +#line 2620 "reflect.h2" private: bool negate; private: bool case_insensitive; private: std::string class_str; public: explicit class_token(cpp2::impl::in negate_, cpp2::impl::in case_insensitive_, cpp2::impl::in class_str_, cpp2::impl::in str); -#line 2631 "reflect.h2" +#line 2632 "reflect.h2" // TODO: Rework class generation: Generate check functions for classes. public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 2757 "reflect.h2" +#line 2758 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2762 "reflect.h2" +#line 2763 "reflect.h2" private: [[nodiscard]] static auto create_matcher(cpp2::impl::in name, cpp2::impl::in template_arguments) -> std::string; public: virtual ~class_token() noexcept; @@ -1183,20 +1185,20 @@ class class_token public: auto operator=(class_token const&) -> void = delete; -#line 2769 "reflect.h2" +#line 2770 "reflect.h2" }; -#line 2772 "reflect.h2" +#line 2773 "reflect.h2" // Regex syntax: \a or \n or \[ // [[nodiscard]] auto escape_token_parse(parse_context& ctx) -> token_ptr; -#line 2813 "reflect.h2" +#line 2814 "reflect.h2" // Regex syntax: \K Example: ab\Kcd // [[nodiscard]] auto global_group_reset_token_parse(parse_context& ctx) -> token_ptr; -#line 2824 "reflect.h2" +#line 2825 "reflect.h2" // Regex syntax: \ Example: \1 // \g{name_or_number} // \k{name_or_number} @@ -1206,16 +1208,16 @@ class class_token class group_ref_token : public regex_token { -#line 2834 "reflect.h2" +#line 2835 "reflect.h2" private: int id; private: bool case_insensitive; public: explicit group_ref_token(cpp2::impl::in id_, cpp2::impl::in case_insensitive_, cpp2::impl::in str); -#line 2844 "reflect.h2" +#line 2845 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 2945 "reflect.h2" +#line 2946 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~group_ref_token() noexcept; @@ -1223,10 +1225,10 @@ class group_ref_token public: auto operator=(group_ref_token const&) -> void = delete; -#line 2948 "reflect.h2" +#line 2949 "reflect.h2" }; -#line 2951 "reflect.h2" +#line 2952 "reflect.h2" // Regex syntax: () Example: (abc) // (?:) (?i:abc) @@ -1240,22 +1242,22 @@ class group_ref_token class group_token : public regex_token { -#line 2965 "reflect.h2" +#line 2966 "reflect.h2" private: int number {-1}; private: token_ptr inner {nullptr}; public: [[nodiscard]] static auto parse_lookahead(parse_context& ctx, cpp2::impl::in syntax, cpp2::impl::in positive) -> token_ptr; -#line 2982 "reflect.h2" +#line 2983 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 3119 "reflect.h2" +#line 3120 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in name, cpp2::impl::in name_brackets, cpp2::impl::in has_modifier, cpp2::impl::in modifiers, cpp2::impl::in inner_) -> std::string; -#line 3137 "reflect.h2" +#line 3138 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3157 "reflect.h2" +#line 3158 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~group_token() noexcept; @@ -1264,25 +1266,25 @@ class group_token public: auto operator=(group_token const&) -> void = delete; -#line 3164 "reflect.h2" +#line 3165 "reflect.h2" }; -#line 3167 "reflect.h2" +#line 3168 "reflect.h2" // Regex syntax: \x or \x{} Example: \x{62} // [[nodiscard]] auto hexadecimal_token_parse(parse_context& ctx) -> token_ptr; -#line 3208 "reflect.h2" +#line 3209 "reflect.h2" // Regex syntax: $ Example: aa$ // [[nodiscard]] auto line_end_token_parse(parse_context& ctx) -> token_ptr; -#line 3228 "reflect.h2" +#line 3229 "reflect.h2" // Regex syntax: ^ Example: ^aa // [[nodiscard]] auto line_start_token_parse(parse_context& ctx) -> token_ptr; -#line 3244 "reflect.h2" +#line 3245 "reflect.h2" // Regex syntax: (?=) or (?!) or (*pla), etc. Example: (?=AA) // // Parsed in group_token. @@ -1290,16 +1292,16 @@ class group_token class lookahead_token : public regex_token { -#line 3252 "reflect.h2" +#line 3253 "reflect.h2" protected: bool positive; public: token_ptr inner {nullptr}; public: explicit lookahead_token(cpp2::impl::in positive_); -#line 3259 "reflect.h2" +#line 3260 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3265 "reflect.h2" +#line 3266 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~lookahead_token() noexcept; @@ -1307,26 +1309,26 @@ class lookahead_token public: auto operator=(lookahead_token const&) -> void = delete; -#line 3268 "reflect.h2" +#line 3269 "reflect.h2" }; -#line 3271 "reflect.h2" +#line 3272 "reflect.h2" // Named character classes // [[nodiscard]] auto named_class_token_parse(parse_context& ctx) -> token_ptr; -#line 3299 "reflect.h2" +#line 3300 "reflect.h2" // Regex syntax: \o{} Example: \o{142} // [[nodiscard]] auto octal_token_parse(parse_context& ctx) -> token_ptr; -#line 3327 "reflect.h2" +#line 3328 "reflect.h2" // Regex syntax: {min, max} Example: a{2,4} // class range_token : public regex_token { -#line 3333 "reflect.h2" +#line 3334 "reflect.h2" protected: int min_count {-1}; protected: int max_count {-1}; protected: int kind {range_flags::greedy}; @@ -1336,19 +1338,19 @@ class range_token public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 3413 "reflect.h2" +#line 3414 "reflect.h2" public: auto parse_modifier(parse_context& ctx) & -> void; -#line 3425 "reflect.h2" +#line 3426 "reflect.h2" public: [[nodiscard]] auto gen_mod_string() const& -> std::string; -#line 3438 "reflect.h2" +#line 3439 "reflect.h2" public: [[nodiscard]] auto gen_range_string() const& -> std::string; -#line 3457 "reflect.h2" +#line 3458 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3468 "reflect.h2" +#line 3469 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~range_token() noexcept; @@ -1356,16 +1358,16 @@ class range_token public: auto operator=(range_token const&) -> void = delete; -#line 3472 "reflect.h2" +#line 3473 "reflect.h2" }; -#line 3475 "reflect.h2" +#line 3476 "reflect.h2" // Regex syntax: *, +, or ? Example: aa* // class special_range_token : public range_token { -#line 3481 "reflect.h2" +#line 3482 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; public: virtual ~special_range_token() noexcept; @@ -1374,17 +1376,17 @@ class special_range_token public: auto operator=(special_range_token const&) -> void = delete; -#line 3511 "reflect.h2" +#line 3512 "reflect.h2" }; -#line 3514 "reflect.h2" +#line 3515 "reflect.h2" // Regex syntax: \b or \B Example: \bword\b // // Matches the start end end of word boundaries. // [[nodiscard]] auto word_boundary_token_parse(parse_context& ctx) -> token_ptr; -#line 3536 "reflect.h2" +#line 3537 "reflect.h2" //----------------------------------------------------------------------- // // Parser for regular expression. @@ -1405,24 +1407,24 @@ template class regex_generator public: explicit regex_generator(cpp2::impl::in r, Error_out const& e); -#line 3559 "reflect.h2" +#line 3560 "reflect.h2" public: [[nodiscard]] auto parse() & -> std::string; -#line 3594 "reflect.h2" +#line 3595 "reflect.h2" private: auto extract_modifiers() & -> void; public: regex_generator(regex_generator const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(regex_generator const&) -> void = delete; -#line 3608 "reflect.h2" +#line 3609 "reflect.h2" }; template [[nodiscard]] auto generate_regex(cpp2::impl::in regex, Err const& err) -> std::string; -#line 3620 "reflect.h2" +#line 3621 "reflect.h2" auto regex_gen(meta::type_declaration& t) -> void; -#line 3675 "reflect.h2" +#line 3676 "reflect.h2" //----------------------------------------------------------------------- // // apply_metafunctions - for types @@ -1433,7 +1435,7 @@ auto regex_gen(meta::type_declaration& t) -> void; auto const& error ) -> bool; -#line 3794 "reflect.h2" +#line 3795 "reflect.h2" //----------------------------------------------------------------------- // // apply_metafunctions - for functions @@ -1444,7 +1446,7 @@ auto regex_gen(meta::type_declaration& t) -> void; auto const& error ) -> bool; -#line 3848 "reflect.h2" +#line 3849 "reflect.h2" } } @@ -1811,76 +1813,78 @@ declaration_base::declaration_base(declaration_base const& that) if (has_name()) {return CPP2_UFCS(as_string_view)((*cpp2::impl::assert_not_null(CPP2_UFCS(name)(*cpp2::impl::assert_not_null(n))))); } else { return ""; } } +#line 332 "reflect.h2" + [[nodiscard]] auto declaration::fully_qualified_name() const& -> std::string { return CPP2_UFCS(fully_qualified_name)((*cpp2::impl::assert_not_null(n))); } -#line 333 "reflect.h2" +#line 334 "reflect.h2" [[nodiscard]] auto declaration::has_initializer() const& -> bool { return CPP2_UFCS(has_initializer)((*cpp2::impl::assert_not_null(n))); } -#line 335 "reflect.h2" - [[nodiscard]] auto declaration::is_global() const& -> bool { return CPP2_UFCS(is_global)((*cpp2::impl::assert_not_null(n))); } #line 336 "reflect.h2" - [[nodiscard]] auto declaration::is_function() const& -> bool { return CPP2_UFCS(is_function)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration::is_global() const& -> bool { return CPP2_UFCS(is_global)((*cpp2::impl::assert_not_null(n))); } #line 337 "reflect.h2" - [[nodiscard]] auto declaration::is_object() const& -> bool { return CPP2_UFCS(is_object)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration::is_function() const& -> bool { return CPP2_UFCS(is_function)((*cpp2::impl::assert_not_null(n))); } #line 338 "reflect.h2" - [[nodiscard]] auto declaration::is_base_object() const& -> bool { return CPP2_UFCS(is_base_object)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration::is_object() const& -> bool { return CPP2_UFCS(is_object)((*cpp2::impl::assert_not_null(n))); } #line 339 "reflect.h2" - [[nodiscard]] auto declaration::is_member_object() const& -> bool { return CPP2_UFCS(is_member_object)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration::is_base_object() const& -> bool { return CPP2_UFCS(is_base_object)((*cpp2::impl::assert_not_null(n))); } #line 340 "reflect.h2" - [[nodiscard]] auto declaration::is_type() const& -> bool { return CPP2_UFCS(is_type)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration::is_member_object() const& -> bool { return CPP2_UFCS(is_member_object)((*cpp2::impl::assert_not_null(n))); } #line 341 "reflect.h2" - [[nodiscard]] auto declaration::is_namespace() const& -> bool { return CPP2_UFCS(is_namespace)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration::is_type() const& -> bool { return CPP2_UFCS(is_type)((*cpp2::impl::assert_not_null(n))); } #line 342 "reflect.h2" + [[nodiscard]] auto declaration::is_namespace() const& -> bool { return CPP2_UFCS(is_namespace)((*cpp2::impl::assert_not_null(n))); } +#line 343 "reflect.h2" [[nodiscard]] auto declaration::is_alias() const& -> bool { return CPP2_UFCS(is_alias)((*cpp2::impl::assert_not_null(n))); } -#line 344 "reflect.h2" - [[nodiscard]] auto declaration::is_type_alias() const& -> bool { return CPP2_UFCS(is_type_alias)((*cpp2::impl::assert_not_null(n))); } #line 345 "reflect.h2" - [[nodiscard]] auto declaration::is_namespace_alias() const& -> bool { return CPP2_UFCS(is_namespace_alias)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration::is_type_alias() const& -> bool { return CPP2_UFCS(is_type_alias)((*cpp2::impl::assert_not_null(n))); } #line 346 "reflect.h2" + [[nodiscard]] auto declaration::is_namespace_alias() const& -> bool { return CPP2_UFCS(is_namespace_alias)((*cpp2::impl::assert_not_null(n))); } +#line 347 "reflect.h2" [[nodiscard]] auto declaration::is_object_alias() const& -> bool { return CPP2_UFCS(is_object_alias)((*cpp2::impl::assert_not_null(n))); } -#line 348 "reflect.h2" +#line 349 "reflect.h2" [[nodiscard]] auto declaration::is_function_expression() const& -> bool { return CPP2_UFCS(is_function_expression)((*cpp2::impl::assert_not_null(n))); } -#line 350 "reflect.h2" - [[nodiscard]] auto declaration::as_function() const& -> function_declaration { return function_declaration(n, (*this)); } #line 351 "reflect.h2" - [[nodiscard]] auto declaration::as_object() const& -> object_declaration { return object_declaration(n, (*this)); } + [[nodiscard]] auto declaration::as_function() const& -> function_declaration { return function_declaration(n, (*this)); } #line 352 "reflect.h2" - [[nodiscard]] auto declaration::as_type() const& -> type_declaration { return type_declaration(n, (*this)); } + [[nodiscard]] auto declaration::as_object() const& -> object_declaration { return object_declaration(n, (*this)); } #line 353 "reflect.h2" + [[nodiscard]] auto declaration::as_type() const& -> type_declaration { return type_declaration(n, (*this)); } +#line 354 "reflect.h2" [[nodiscard]] auto declaration::as_alias() const& -> alias_declaration { return alias_declaration(n, (*this)); } -#line 355 "reflect.h2" +#line 356 "reflect.h2" [[nodiscard]] auto declaration::get_parent() const& -> declaration { return declaration((*cpp2::impl::assert_not_null(n)).parent_declaration, (*this)); } -#line 357 "reflect.h2" - [[nodiscard]] auto declaration::parent_is_function() const& -> bool { return CPP2_UFCS(parent_is_function)((*cpp2::impl::assert_not_null(n))); } #line 358 "reflect.h2" - [[nodiscard]] auto declaration::parent_is_object() const& -> bool { return CPP2_UFCS(parent_is_object)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration::parent_is_function() const& -> bool { return CPP2_UFCS(parent_is_function)((*cpp2::impl::assert_not_null(n))); } #line 359 "reflect.h2" - [[nodiscard]] auto declaration::parent_is_type() const& -> bool { return CPP2_UFCS(parent_is_type)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration::parent_is_object() const& -> bool { return CPP2_UFCS(parent_is_object)((*cpp2::impl::assert_not_null(n))); } #line 360 "reflect.h2" - [[nodiscard]] auto declaration::parent_is_namespace() const& -> bool { return CPP2_UFCS(parent_is_namespace)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration::parent_is_type() const& -> bool { return CPP2_UFCS(parent_is_type)((*cpp2::impl::assert_not_null(n))); } #line 361 "reflect.h2" + [[nodiscard]] auto declaration::parent_is_namespace() const& -> bool { return CPP2_UFCS(parent_is_namespace)((*cpp2::impl::assert_not_null(n))); } +#line 362 "reflect.h2" [[nodiscard]] auto declaration::parent_is_alias() const& -> bool { return CPP2_UFCS(parent_is_alias)((*cpp2::impl::assert_not_null(n))); } -#line 363 "reflect.h2" - [[nodiscard]] auto declaration::parent_is_type_alias() const& -> bool { return CPP2_UFCS(parent_is_type_alias)((*cpp2::impl::assert_not_null(n))); } #line 364 "reflect.h2" - [[nodiscard]] auto declaration::parent_is_namespace_alias() const& -> bool { return CPP2_UFCS(parent_is_namespace_alias)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration::parent_is_type_alias() const& -> bool { return CPP2_UFCS(parent_is_type_alias)((*cpp2::impl::assert_not_null(n))); } #line 365 "reflect.h2" + [[nodiscard]] auto declaration::parent_is_namespace_alias() const& -> bool { return CPP2_UFCS(parent_is_namespace_alias)((*cpp2::impl::assert_not_null(n))); } +#line 366 "reflect.h2" [[nodiscard]] auto declaration::parent_is_object_alias() const& -> bool { return CPP2_UFCS(parent_is_object_alias)((*cpp2::impl::assert_not_null(n))); } -#line 367 "reflect.h2" +#line 368 "reflect.h2" [[nodiscard]] auto declaration::parent_is_polymorphic() const& -> bool { return CPP2_UFCS(parent_is_polymorphic)((*cpp2::impl::assert_not_null(n))); } -#line 369 "reflect.h2" +#line 370 "reflect.h2" auto declaration::mark_for_removal_from_enclosing_type() & -> void // this precondition should be sufficient ... { if (cpp2::type_safety.is_active() && !(parent_is_type()) ) { cpp2::type_safety.report_violation(""); } -#line 372 "reflect.h2" +#line 373 "reflect.h2" auto test {CPP2_UFCS(type_member_mark_for_removal)((*cpp2::impl::assert_not_null(n)))}; if (cpp2::cpp2_default.is_active() && !(cpp2::move(test)) ) { cpp2::cpp2_default.report_violation(""); }// ... to ensure this assert is true } @@ -1889,93 +1893,93 @@ declaration_base::declaration_base(declaration_base const& that) declaration::declaration(declaration const& that) : declaration_base{ static_cast(that) }{} -#line 378 "reflect.h2" +#line 379 "reflect.h2" //----------------------------------------------------------------------- // Function declarations // -#line 385 "reflect.h2" +#line 386 "reflect.h2" function_declaration::function_declaration( declaration_node* n_, cpp2::impl::in s ) : declaration{ n_, s } -#line 390 "reflect.h2" +#line 391 "reflect.h2" { if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(is_function)((*cpp2::impl::assert_not_null(n)))) ) { cpp2::cpp2_default.report_violation(""); } } -#line 395 "reflect.h2" - [[nodiscard]] auto function_declaration::index_of_parameter_named(cpp2::impl::in s) const& -> int { return CPP2_UFCS(index_of_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } #line 396 "reflect.h2" - [[nodiscard]] auto function_declaration::has_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } + [[nodiscard]] auto function_declaration::index_of_parameter_named(cpp2::impl::in s) const& -> int { return CPP2_UFCS(index_of_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } #line 397 "reflect.h2" - [[nodiscard]] auto function_declaration::has_in_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_in_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } + [[nodiscard]] auto function_declaration::has_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } #line 398 "reflect.h2" - [[nodiscard]] auto function_declaration::has_copy_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_copy_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } + [[nodiscard]] auto function_declaration::has_in_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_in_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } #line 399 "reflect.h2" - [[nodiscard]] auto function_declaration::has_inout_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_inout_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } + [[nodiscard]] auto function_declaration::has_copy_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_copy_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } #line 400 "reflect.h2" - [[nodiscard]] auto function_declaration::has_out_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_out_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } + [[nodiscard]] auto function_declaration::has_inout_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_inout_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } #line 401 "reflect.h2" - [[nodiscard]] auto function_declaration::has_move_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_move_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } + [[nodiscard]] auto function_declaration::has_out_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_out_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } #line 402 "reflect.h2" - [[nodiscard]] auto function_declaration::has_forward_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_forward_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } + [[nodiscard]] auto function_declaration::has_move_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_move_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } #line 403 "reflect.h2" + [[nodiscard]] auto function_declaration::has_forward_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_forward_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } +#line 404 "reflect.h2" [[nodiscard]] auto function_declaration::first_parameter_name() const& -> std::string { return CPP2_UFCS(first_parameter_name)((*cpp2::impl::assert_not_null(n))); } -#line 405 "reflect.h2" +#line 406 "reflect.h2" [[nodiscard]] auto function_declaration::has_parameter_with_name_and_pass(cpp2::impl::in s, cpp2::impl::in pass) const& -> bool { return CPP2_UFCS(has_parameter_with_name_and_pass)((*cpp2::impl::assert_not_null(n)), s, pass); } -#line 407 "reflect.h2" - [[nodiscard]] auto function_declaration::is_function_with_this() const& -> bool { return CPP2_UFCS(is_function_with_this)((*cpp2::impl::assert_not_null(n))); } #line 408 "reflect.h2" - [[nodiscard]] auto function_declaration::is_virtual() const& -> bool { return CPP2_UFCS(is_virtual_function)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration::is_function_with_this() const& -> bool { return CPP2_UFCS(is_function_with_this)((*cpp2::impl::assert_not_null(n))); } #line 409 "reflect.h2" - [[nodiscard]] auto function_declaration::is_defaultable() const& -> bool { return CPP2_UFCS(is_defaultable_function)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration::is_virtual() const& -> bool { return CPP2_UFCS(is_virtual_function)((*cpp2::impl::assert_not_null(n))); } #line 410 "reflect.h2" - [[nodiscard]] auto function_declaration::is_constructor() const& -> bool { return CPP2_UFCS(is_constructor)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration::is_defaultable() const& -> bool { return CPP2_UFCS(is_defaultable_function)((*cpp2::impl::assert_not_null(n))); } #line 411 "reflect.h2" - [[nodiscard]] auto function_declaration::is_default_constructor() const& -> bool { return CPP2_UFCS(is_default_constructor)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration::is_constructor() const& -> bool { return CPP2_UFCS(is_constructor)((*cpp2::impl::assert_not_null(n))); } #line 412 "reflect.h2" - [[nodiscard]] auto function_declaration::is_move() const& -> bool { return CPP2_UFCS(is_move)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration::is_default_constructor() const& -> bool { return CPP2_UFCS(is_default_constructor)((*cpp2::impl::assert_not_null(n))); } #line 413 "reflect.h2" - [[nodiscard]] auto function_declaration::is_swap() const& -> bool { return CPP2_UFCS(is_swap)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration::is_move() const& -> bool { return CPP2_UFCS(is_move)((*cpp2::impl::assert_not_null(n))); } #line 414 "reflect.h2" - [[nodiscard]] auto function_declaration::is_constructor_with_that() const& -> bool { return CPP2_UFCS(is_constructor_with_that)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration::is_swap() const& -> bool { return CPP2_UFCS(is_swap)((*cpp2::impl::assert_not_null(n))); } #line 415 "reflect.h2" - [[nodiscard]] auto function_declaration::is_constructor_with_in_that() const& -> bool { return CPP2_UFCS(is_constructor_with_in_that)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration::is_constructor_with_that() const& -> bool { return CPP2_UFCS(is_constructor_with_that)((*cpp2::impl::assert_not_null(n))); } #line 416 "reflect.h2" - [[nodiscard]] auto function_declaration::is_constructor_with_move_that() const& -> bool { return CPP2_UFCS(is_constructor_with_move_that)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration::is_constructor_with_in_that() const& -> bool { return CPP2_UFCS(is_constructor_with_in_that)((*cpp2::impl::assert_not_null(n))); } #line 417 "reflect.h2" - [[nodiscard]] auto function_declaration::is_assignment() const& -> bool { return CPP2_UFCS(is_assignment)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration::is_constructor_with_move_that() const& -> bool { return CPP2_UFCS(is_constructor_with_move_that)((*cpp2::impl::assert_not_null(n))); } #line 418 "reflect.h2" - [[nodiscard]] auto function_declaration::is_assignment_with_that() const& -> bool { return CPP2_UFCS(is_assignment_with_that)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration::is_assignment() const& -> bool { return CPP2_UFCS(is_assignment)((*cpp2::impl::assert_not_null(n))); } #line 419 "reflect.h2" - [[nodiscard]] auto function_declaration::is_assignment_with_in_that() const& -> bool { return CPP2_UFCS(is_assignment_with_in_that)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration::is_assignment_with_that() const& -> bool { return CPP2_UFCS(is_assignment_with_that)((*cpp2::impl::assert_not_null(n))); } #line 420 "reflect.h2" - [[nodiscard]] auto function_declaration::is_assignment_with_move_that() const& -> bool { return CPP2_UFCS(is_assignment_with_move_that)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration::is_assignment_with_in_that() const& -> bool { return CPP2_UFCS(is_assignment_with_in_that)((*cpp2::impl::assert_not_null(n))); } #line 421 "reflect.h2" + [[nodiscard]] auto function_declaration::is_assignment_with_move_that() const& -> bool { return CPP2_UFCS(is_assignment_with_move_that)((*cpp2::impl::assert_not_null(n))); } +#line 422 "reflect.h2" [[nodiscard]] auto function_declaration::is_destructor() const& -> bool { return CPP2_UFCS(is_destructor)((*cpp2::impl::assert_not_null(n))); } -#line 423 "reflect.h2" +#line 424 "reflect.h2" [[nodiscard]] auto function_declaration::is_copy_or_move() const& -> bool { return is_constructor_with_that() || is_assignment_with_that(); } -#line 425 "reflect.h2" - [[nodiscard]] auto function_declaration::has_declared_return_type() const& -> bool { return CPP2_UFCS(has_declared_return_type)((*cpp2::impl::assert_not_null(n))); } #line 426 "reflect.h2" - [[nodiscard]] auto function_declaration::has_deduced_return_type() const& -> bool { return CPP2_UFCS(has_deduced_return_type)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration::has_declared_return_type() const& -> bool { return CPP2_UFCS(has_declared_return_type)((*cpp2::impl::assert_not_null(n))); } #line 427 "reflect.h2" - [[nodiscard]] auto function_declaration::has_bool_return_type() const& -> bool { return CPP2_UFCS(has_bool_return_type)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration::has_deduced_return_type() const& -> bool { return CPP2_UFCS(has_deduced_return_type)((*cpp2::impl::assert_not_null(n))); } #line 428 "reflect.h2" + [[nodiscard]] auto function_declaration::has_bool_return_type() const& -> bool { return CPP2_UFCS(has_bool_return_type)((*cpp2::impl::assert_not_null(n))); } +#line 429 "reflect.h2" [[nodiscard]] auto function_declaration::has_non_void_return_type() const& -> bool { return CPP2_UFCS(has_non_void_return_type)((*cpp2::impl::assert_not_null(n))); } -#line 430 "reflect.h2" +#line 431 "reflect.h2" [[nodiscard]] auto function_declaration::unnamed_return_type() const& -> std::string { return CPP2_UFCS(unnamed_return_type_to_string)((*cpp2::impl::assert_not_null(n))); } -#line 432 "reflect.h2" +#line 433 "reflect.h2" [[nodiscard]] auto function_declaration::get_parameters() const& -> std::vector { @@ -1986,19 +1990,19 @@ declaration::declaration(declaration const& that) return ret; } -#line 442 "reflect.h2" +#line 443 "reflect.h2" [[nodiscard]] auto function_declaration::is_binary_comparison_function() const& -> bool { return CPP2_UFCS(is_binary_comparison_function)((*cpp2::impl::assert_not_null(n))); } -#line 444 "reflect.h2" +#line 445 "reflect.h2" auto function_declaration::default_to_virtual() & -> void { static_cast(CPP2_UFCS(make_function_virtual)((*cpp2::impl::assert_not_null(n)))); } -#line 446 "reflect.h2" +#line 447 "reflect.h2" [[nodiscard]] auto function_declaration::make_virtual() & -> bool { return CPP2_UFCS(make_function_virtual)((*cpp2::impl::assert_not_null(n))); } -#line 448 "reflect.h2" +#line 449 "reflect.h2" auto function_declaration::add_initializer(cpp2::impl::in source) & -> void -#line 451 "reflect.h2" +#line 452 "reflect.h2" { if ((*this).is_active() && !(!(has_initializer())) ) { (*this).report_violation(CPP2_CONTRACT_MSG("cannot add an initializer to a function that already has one")); } if ((*this).is_active() && !(parent_is_type()) ) { (*this).report_violation(CPP2_CONTRACT_MSG("cannot add an initializer to a function that isn't in a type scope")); } @@ -2007,7 +2011,7 @@ declaration::declaration(declaration const& that) //require( parent_is_type(), // "cannot add an initializer to a function that isn't in a type scope"); -#line 457 "reflect.h2" +#line 458 "reflect.h2" auto stmt {parse_statement(source)}; if (!((cpp2::impl::as_(stmt)))) { error("cannot add an initializer that is not a valid statement"); @@ -2020,30 +2024,30 @@ declaration::declaration(declaration const& that) function_declaration::function_declaration(function_declaration const& that) : declaration{ static_cast(that) }{} -#line 468 "reflect.h2" +#line 469 "reflect.h2" //----------------------------------------------------------------------- // Object declarations // -#line 475 "reflect.h2" +#line 476 "reflect.h2" object_declaration::object_declaration( declaration_node* n_, cpp2::impl::in s ) : declaration{ n_, s } -#line 480 "reflect.h2" +#line 481 "reflect.h2" { if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(is_object)((*cpp2::impl::assert_not_null(n)))) ) { cpp2::cpp2_default.report_violation(""); } } -#line 485 "reflect.h2" - [[nodiscard]] auto object_declaration::is_const() const& -> bool { return CPP2_UFCS(is_const)((*cpp2::impl::assert_not_null(n))); } #line 486 "reflect.h2" + [[nodiscard]] auto object_declaration::is_const() const& -> bool { return CPP2_UFCS(is_const)((*cpp2::impl::assert_not_null(n))); } +#line 487 "reflect.h2" [[nodiscard]] auto object_declaration::has_wildcard_type() const& -> bool { return CPP2_UFCS(has_wildcard_type)((*cpp2::impl::assert_not_null(n))); } -#line 488 "reflect.h2" +#line 489 "reflect.h2" [[nodiscard]] auto object_declaration::type() const& -> std::string{ auto ret {CPP2_UFCS(object_type)((*cpp2::impl::assert_not_null(n)))}; require(!(contains(ret, "(*ERROR*)")), @@ -2051,7 +2055,7 @@ declaration::declaration(declaration const& that) return ret; } -#line 495 "reflect.h2" +#line 496 "reflect.h2" [[nodiscard]] auto object_declaration::initializer() const& -> std::string{ auto ret {CPP2_UFCS(object_initializer)((*cpp2::impl::assert_not_null(n)))}; require(!(contains(ret, "(*ERROR*)")), @@ -2062,25 +2066,25 @@ declaration::declaration(declaration const& that) object_declaration::object_declaration(object_declaration const& that) : declaration{ static_cast(that) }{} -#line 504 "reflect.h2" +#line 505 "reflect.h2" //----------------------------------------------------------------------- // Type declarations // -#line 511 "reflect.h2" +#line 512 "reflect.h2" type_declaration::type_declaration( declaration_node* n_, cpp2::impl::in s ) : declaration{ n_, s } -#line 516 "reflect.h2" +#line 517 "reflect.h2" { if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(is_type)((*cpp2::impl::assert_not_null(n)))) ) { cpp2::cpp2_default.report_violation(""); } } -#line 521 "reflect.h2" +#line 522 "reflect.h2" auto type_declaration::reserve_names(cpp2::impl::in name, auto&& ...etc) const& -> void { // etc is not declared ':string_view' for compatibility with GCC 10.x for ( @@ -2095,14 +2099,14 @@ declaration::declaration(declaration const& that) } } -#line 535 "reflect.h2" - [[nodiscard]] auto type_declaration::is_polymorphic() const& -> bool { return CPP2_UFCS(is_polymorphic)((*cpp2::impl::assert_not_null(n))); } #line 536 "reflect.h2" - [[nodiscard]] auto type_declaration::is_final() const& -> bool { return CPP2_UFCS(is_type_final)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto type_declaration::is_polymorphic() const& -> bool { return CPP2_UFCS(is_polymorphic)((*cpp2::impl::assert_not_null(n))); } #line 537 "reflect.h2" + [[nodiscard]] auto type_declaration::is_final() const& -> bool { return CPP2_UFCS(is_type_final)((*cpp2::impl::assert_not_null(n))); } +#line 538 "reflect.h2" [[nodiscard]] auto type_declaration::make_final() & -> bool { return CPP2_UFCS(make_type_final)((*cpp2::impl::assert_not_null(n))); } -#line 539 "reflect.h2" +#line 540 "reflect.h2" [[nodiscard]] auto type_declaration::get_member_functions() const& -> std::vector { @@ -2114,7 +2118,7 @@ declaration::declaration(declaration const& that) return ret; } -#line 550 "reflect.h2" +#line 551 "reflect.h2" [[nodiscard]] auto type_declaration::get_member_functions_needing_initializer() const& -> std::vector { @@ -2130,7 +2134,7 @@ declaration::declaration(declaration const& that) return ret; } -#line 565 "reflect.h2" +#line 566 "reflect.h2" [[nodiscard]] auto type_declaration::get_member_objects() const& -> std::vector { @@ -2141,7 +2145,7 @@ declaration::declaration(declaration const& that) return ret; } -#line 575 "reflect.h2" +#line 576 "reflect.h2" [[nodiscard]] auto type_declaration::get_member_types() const& -> std::vector { @@ -2152,7 +2156,7 @@ declaration::declaration(declaration const& that) return ret; } -#line 585 "reflect.h2" +#line 586 "reflect.h2" [[nodiscard]] auto type_declaration::get_member_aliases() const& -> std::vector { @@ -2163,7 +2167,7 @@ declaration::declaration(declaration const& that) return ret; } -#line 595 "reflect.h2" +#line 596 "reflect.h2" [[nodiscard]] auto type_declaration::get_members() const& -> std::vector { @@ -2174,16 +2178,16 @@ declaration::declaration(declaration const& that) return ret; } -#line 605 "reflect.h2" +#line 606 "reflect.h2" [[nodiscard]] auto type_declaration::query_declared_value_set_functions() const& -> query_declared_value_set_functions_ret -#line 612 "reflect.h2" +#line 613 "reflect.h2" { cpp2::impl::deferred_init out_this_in_that; cpp2::impl::deferred_init out_this_move_that; cpp2::impl::deferred_init inout_this_in_that; cpp2::impl::deferred_init inout_this_move_that; -#line 613 "reflect.h2" +#line 614 "reflect.h2" auto declared {CPP2_UFCS(find_declared_value_set_functions)((*cpp2::impl::assert_not_null(n)))}; out_this_in_that.construct(declared.out_this_in_that != nullptr); out_this_move_that.construct(declared.out_this_move_that != nullptr); @@ -2191,7 +2195,7 @@ declaration::declaration(declaration const& that) inout_this_move_that.construct(cpp2::move(declared).inout_this_move_that != nullptr); return { std::move(out_this_in_that.value()), std::move(out_this_move_that.value()), std::move(inout_this_in_that.value()), std::move(inout_this_move_that.value()) }; } -#line 620 "reflect.h2" +#line 621 "reflect.h2" auto type_declaration::add_member(cpp2::impl::in source) & -> void { auto decl {parse_statement(source)}; @@ -2206,30 +2210,30 @@ declaration::declaration(declaration const& that) std::string("unexpected error while attempting to add member:\n") + source); } -#line 634 "reflect.h2" - auto type_declaration::remove_marked_members() & -> void { CPP2_UFCS(type_remove_marked_members)((*cpp2::impl::assert_not_null(n))); } #line 635 "reflect.h2" + auto type_declaration::remove_marked_members() & -> void { CPP2_UFCS(type_remove_marked_members)((*cpp2::impl::assert_not_null(n))); } +#line 636 "reflect.h2" auto type_declaration::remove_all_members() & -> void { CPP2_UFCS(type_remove_all_members)((*cpp2::impl::assert_not_null(n))); } -#line 637 "reflect.h2" +#line 638 "reflect.h2" auto type_declaration::disable_member_function_generation() & -> void { CPP2_UFCS(type_disable_member_function_generation)((*cpp2::impl::assert_not_null(n))); } type_declaration::type_declaration(type_declaration const& that) : declaration{ static_cast(that) }{} -#line 641 "reflect.h2" +#line 642 "reflect.h2" //----------------------------------------------------------------------- // Alias declarations // -#line 648 "reflect.h2" +#line 649 "reflect.h2" alias_declaration::alias_declaration( declaration_node* n_, cpp2::impl::in s ) : declaration{ n_, s } -#line 653 "reflect.h2" +#line 654 "reflect.h2" { if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(is_alias)((*cpp2::impl::assert_not_null(n)))) ) { cpp2::cpp2_default.report_violation(""); } @@ -2238,7 +2242,7 @@ declaration::declaration(declaration const& that) alias_declaration::alias_declaration(alias_declaration const& that) : declaration{ static_cast(that) }{} -#line 660 "reflect.h2" +#line 661 "reflect.h2" //----------------------------------------------------------------------- // // Metafunctions - these are hardwired for now until we get to the @@ -2251,13 +2255,13 @@ declaration::declaration(declaration const& that) // Some common metafunction helpers (metafunctions are just functions, // so they can be factored as usual) // -#line 672 "reflect.h2" +#line 673 "reflect.h2" auto add_virtual_destructor(meta::type_declaration& t) -> void { CPP2_UFCS(add_member)(t, "operator=: (virtual move this) = { }"); } -#line 678 "reflect.h2" +#line 679 "reflect.h2" //----------------------------------------------------------------------- // // "... an abstract base class defines an interface ..." @@ -2270,7 +2274,7 @@ auto add_virtual_destructor(meta::type_declaration& t) -> void // // an abstract base class having only pure virtual functions // -#line 690 "reflect.h2" +#line 691 "reflect.h2" auto interface(meta::type_declaration& t) -> void { auto has_dtor {false}; @@ -2297,7 +2301,7 @@ auto interface(meta::type_declaration& t) -> void } } -#line 717 "reflect.h2" +#line 718 "reflect.h2" //----------------------------------------------------------------------- // // "C.35: A base class destructor should be either public and @@ -2317,7 +2321,7 @@ auto interface(meta::type_declaration& t) -> void // // Unlike an interface, it can have nonpublic and nonvirtual functions. // -#line 736 "reflect.h2" +#line 737 "reflect.h2" auto polymorphic_base(meta::type_declaration& t) -> void { auto has_dtor {false}; @@ -2342,7 +2346,7 @@ auto polymorphic_base(meta::type_declaration& t) -> void } } -#line 761 "reflect.h2" +#line 762 "reflect.h2" //----------------------------------------------------------------------- // // "... A totally ordered type ... requires operator<=> that @@ -2363,7 +2367,7 @@ auto polymorphic_base(meta::type_declaration& t) -> void //----------------------------------------------------------------------- // -#line 781 "reflect.h2" +#line 782 "reflect.h2" auto ordered_impl( meta::type_declaration& t, cpp2::impl::in ordering// must be "strong_ordering" etc. @@ -2393,7 +2397,7 @@ auto ordered_impl( // // Note: the ordering that should be encouraged as default gets the nice name // -#line 810 "reflect.h2" +#line 811 "reflect.h2" auto ordered(meta::type_declaration& t) -> void { ordered_impl(t, "strong_ordering"); @@ -2402,7 +2406,7 @@ auto ordered(meta::type_declaration& t) -> void //----------------------------------------------------------------------- // weakly_ordered - a weakly ordered type // -#line 818 "reflect.h2" +#line 819 "reflect.h2" auto weakly_ordered(meta::type_declaration& t) -> void { ordered_impl(t, "weak_ordering"); @@ -2411,13 +2415,13 @@ auto weakly_ordered(meta::type_declaration& t) -> void //----------------------------------------------------------------------- // partially_ordered - a partially ordered type // -#line 826 "reflect.h2" +#line 827 "reflect.h2" auto partially_ordered(meta::type_declaration& t) -> void { ordered_impl(t, "partial_ordering"); } -#line 832 "reflect.h2" +#line 833 "reflect.h2" //----------------------------------------------------------------------- // // "A value is ... a regular type. It must have all public @@ -2434,7 +2438,7 @@ auto partially_ordered(meta::type_declaration& t) -> void // // A type with (copy and move) x (construction and assignment) // -#line 848 "reflect.h2" +#line 849 "reflect.h2" auto copyable(meta::type_declaration& t) -> void { // If the user explicitly wrote any of the copy/move functions, @@ -2469,7 +2473,7 @@ auto copyable(meta::type_declaration& t) -> void // A regular type: copyable, plus has public default construction // and no protected or virtual functions // -#line 882 "reflect.h2" +#line 883 "reflect.h2" auto basic_value(meta::type_declaration& t) -> void { CPP2_UFCS(copyable)(t); @@ -2498,28 +2502,28 @@ auto basic_value(meta::type_declaration& t) -> void // // Note: the ordering that should be encouraged as default gets the nice name // -#line 910 "reflect.h2" +#line 911 "reflect.h2" auto value(meta::type_declaration& t) -> void { CPP2_UFCS(ordered)(t); CPP2_UFCS(basic_value)(t); } -#line 916 "reflect.h2" +#line 917 "reflect.h2" auto weakly_ordered_value(meta::type_declaration& t) -> void { CPP2_UFCS(weakly_ordered)(t); CPP2_UFCS(basic_value)(t); } -#line 922 "reflect.h2" +#line 923 "reflect.h2" auto partially_ordered_value(meta::type_declaration& t) -> void { CPP2_UFCS(partially_ordered)(t); CPP2_UFCS(basic_value)(t); } -#line 929 "reflect.h2" +#line 930 "reflect.h2" //----------------------------------------------------------------------- // // C.20: If you can avoid defining default operations, do @@ -2542,7 +2546,7 @@ auto partially_ordered_value(meta::type_declaration& t) -> void // // a type without declared copy/move/destructor functions // -#line 951 "reflect.h2" +#line 952 "reflect.h2" auto cpp1_rule_of_zero(meta::type_declaration& t) -> void { for ( auto& mf : CPP2_UFCS(get_member_functions)(t) ) @@ -2580,7 +2584,7 @@ auto cpp1_rule_of_zero(meta::type_declaration& t) -> void // no virtual functions, and no user-defined constructors // (i.e., no invariants) or assignment or destructors. // -#line 988 "reflect.h2" +#line 989 "reflect.h2" auto cpp2_struct(meta::type_declaration& t) -> void { std::string ctor_params {}; @@ -2632,7 +2636,7 @@ value_member_info::value_member_info(auto const& name_, auto const& type_, auto , type{ type_ } , value{ value_ }{} -#line 1035 "reflect.h2" +#line 1036 "reflect.h2" //----------------------------------------------------------------------- // // "C enumerations constitute a curiously half-baked concept. ... @@ -2651,7 +2655,7 @@ value_member_info::value_member_info(auto const& name_, auto const& type_, auto // a type together with named constants that are its possible values // -#line 1058 "reflect.h2" +#line 1059 "reflect.h2" auto basic_enum( meta::type_declaration& t, auto const& nextval, @@ -2676,7 +2680,7 @@ auto basic_enum( { std::string value{"-1"}; -#line 1081 "reflect.h2" +#line 1082 "reflect.h2" for ( auto const& m : CPP2_UFCS(get_members)(t) ) if ( CPP2_UFCS(is_member_object)(m)) @@ -2718,7 +2722,7 @@ std::string value{"-1"}; } } -#line 1121 "reflect.h2" +#line 1122 "reflect.h2" if ((CPP2_UFCS(empty)(enumerators))) { CPP2_UFCS(error)(t, "an enumeration must contain at least one enumerator value"); return ; @@ -2769,7 +2773,7 @@ std::string value{"-1"}; } } -#line 1172 "reflect.h2" +#line 1173 "reflect.h2" // 2. Replace: Erase the contents and replace with modified contents // // Note that most values and functions are declared as '==' compile-time values, i.e. Cpp1 'constexpr' @@ -2819,7 +2823,7 @@ std::string to_string_impl{" to_string_impl: (this, prefix: std::string_view" // Provide 'to_string' and 'to_code' functions to print enumerator // name(s) as human-readable strings or as code expressions -#line 1219 "reflect.h2" +#line 1220 "reflect.h2" { if (bitwise) { to_string_impl += ", separator: std::string_view ) -> std::string = { \n" @@ -2860,7 +2864,7 @@ std::string to_string_impl{" to_string_impl: (this, prefix: std::string_view" } } -#line 1258 "reflect.h2" +#line 1259 "reflect.h2" if (bitwise) { CPP2_UFCS(add_member)(t, " to_string: (this) -> std::string = to_string_impl( \"\", \", \" );"); CPP2_UFCS(add_member)(t, " to_code : (this) -> std::string = to_string_impl( \"" + cpp2::to_string(CPP2_UFCS(name)(t)) + "::\", \" | \" );"); @@ -2874,7 +2878,7 @@ std::string from_string{" from_string: (s: std::string_view) -> " + cpp2::to_ // Provide a 'from_string' function to parse strings into enumerators -#line 1269 "reflect.h2" +#line 1270 "reflect.h2" { std::string_view prefix {""}; std::string_view combine_op {"return"}; @@ -2896,7 +2900,7 @@ std::string from_string{" from_string: (s: std::string_view) -> " + cpp2::to_ { std::string_view else_{""}; -#line 1289 "reflect.h2" +#line 1290 "reflect.h2" for ( auto const& e : cpp2::move(enumerators) ) { from_string += " " + cpp2::to_string(else_) + "if \"" + cpp2::to_string(e.name) + "\" == x { " + cpp2::to_string(combine_op) + " " + cpp2::to_string(e.name) + "; }\n"; @@ -2904,7 +2908,7 @@ std::string_view else_{""}; } } -#line 1295 "reflect.h2" +#line 1296 "reflect.h2" if (bitwise) { from_string += " else { break outer; }\n" " }\n" @@ -2920,11 +2924,11 @@ std::string_view else_{""}; } } -#line 1309 "reflect.h2" +#line 1310 "reflect.h2" CPP2_UFCS(add_member)(t, " from_code: (s: std::string_view) -> " + cpp2::to_string(CPP2_UFCS(name)(t)) + " = { str: std::string = s; return from_string( cpp2::string_util::replace_all(str, \"" + cpp2::to_string(CPP2_UFCS(name)(t)) + "::\", \"\" ) ); }"); } -#line 1313 "reflect.h2" +#line 1314 "reflect.h2" //----------------------------------------------------------------------- // // "An enum[...] is a totally ordered value type that stores a @@ -2934,7 +2938,7 @@ std::string_view else_{""}; // // -- P0707R4, section 3 // -#line 1322 "reflect.h2" +#line 1323 "reflect.h2" auto cpp2_enum(meta::type_declaration& t) -> void { // Let basic_enum do its thing, with an incrementing value generator @@ -2951,7 +2955,7 @@ auto cpp2_enum(meta::type_declaration& t) -> void ); } -#line 1339 "reflect.h2" +#line 1340 "reflect.h2" //----------------------------------------------------------------------- // // "flag_enum expresses an enumeration that stores values @@ -2962,7 +2966,7 @@ auto cpp2_enum(meta::type_declaration& t) -> void // // -- P0707R4, section 3 // -#line 1349 "reflect.h2" +#line 1350 "reflect.h2" auto flag_enum(meta::type_declaration& t) -> void { // Let basic_enum do its thing, with a power-of-two value generator @@ -2984,7 +2988,7 @@ auto flag_enum(meta::type_declaration& t) -> void ); } -#line 1371 "reflect.h2" +#line 1372 "reflect.h2" //----------------------------------------------------------------------- // // "As with void*, programmers should know that unions [...] are @@ -3009,7 +3013,7 @@ auto flag_enum(meta::type_declaration& t) -> void // a type that contains exactly one of a fixed set of values at a time // -#line 1395 "reflect.h2" +#line 1396 "reflect.h2" auto cpp2_union(meta::type_declaration& t) -> void { std::vector alternatives {}; @@ -3018,7 +3022,7 @@ auto value{0}; // 1. Gather: All the user-written members, and find/compute the max size -#line 1402 "reflect.h2" +#line 1403 "reflect.h2" for ( auto const& m : CPP2_UFCS(get_members)(t) ) { do @@ -3048,7 +3052,7 @@ auto value{0}; } while (false); ++value; } } -#line 1430 "reflect.h2" +#line 1431 "reflect.h2" std::string discriminator_type {}; if (cpp2::impl::cmp_less(CPP2_UFCS(ssize)(alternatives),std::numeric_limits::max())) { discriminator_type = "i8"; @@ -3063,7 +3067,7 @@ auto value{0}; discriminator_type = "i64"; }}} -#line 1445 "reflect.h2" +#line 1446 "reflect.h2" // 2. Replace: Erase the contents and replace with modified contents CPP2_UFCS(remove_marked_members)(t); @@ -3072,7 +3076,7 @@ std::string storage{" _storage: cpp2::aligned_storage t) -> void { std::cout << CPP2_UFCS(print)(t) << "\n"; } -#line 1551 "reflect.h2" +#line 1552 "reflect.h2" auto print(cpp2::impl::in f) -> void { std::cout << CPP2_UFCS(print)(f) << "\n"; @@ -3283,7 +3287,7 @@ return none; [[nodiscard]] auto expression_flags::from_code(cpp2::impl::in s) -> expression_flags{ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::move(str), "expression_flags::", "")); } -#line 1556 "reflect.h2" +#line 1557 "reflect.h2" //----------------------------------------------------------------------- // // regex - creates regular expressions from members @@ -3299,11 +3303,11 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov // ``` // -#line 1572 "reflect.h2" +#line 1573 "reflect.h2" // Possible modifiers for a regular expression. // -#line 1576 "reflect.h2" +#line 1577 "reflect.h2" // mod: i // mod: m // mod: s @@ -3311,106 +3315,106 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov // mod: x // mod: xx -#line 1585 "reflect.h2" +#line 1586 "reflect.h2" // Tokens for regular expressions. // // Basic class for a regex token. // -#line 1594 "reflect.h2" +#line 1595 "reflect.h2" regex_token::regex_token(cpp2::impl::in str) : string_rep{ str }{ -#line 1596 "reflect.h2" +#line 1597 "reflect.h2" } -#line 1598 "reflect.h2" +#line 1599 "reflect.h2" regex_token::regex_token() : string_rep{ "" }{ -#line 1600 "reflect.h2" +#line 1601 "reflect.h2" } //parse: (inout ctx: parse_context) -> token_ptr; // Generate the matching code. -#line 1605 "reflect.h2" - auto regex_token::add_groups([[maybe_unused]] std::set& unnamed_param_2) const -> void{}// Adds all group indices to the set. #line 1606 "reflect.h2" - [[nodiscard]] auto regex_token::to_string() const& -> std::string{return string_rep; }// Create a string representation. + auto regex_token::add_groups([[maybe_unused]] std::set& unnamed_param_2) const -> void{}// Adds all group indices to the set. #line 1607 "reflect.h2" + [[nodiscard]] auto regex_token::to_string() const& -> std::string{return string_rep; }// Create a string representation. +#line 1608 "reflect.h2" auto regex_token::set_string(cpp2::impl::in s) & -> void{string_rep = s; } regex_token::~regex_token() noexcept{}// Set the string representation. -#line 1622 "reflect.h2" +#line 1623 "reflect.h2" regex_token_check::regex_token_check(cpp2::impl::in str, cpp2::impl::in check_) : regex_token{ str } , check{ check_ }{ -#line 1625 "reflect.h2" +#line 1626 "reflect.h2" } -#line 1627 "reflect.h2" +#line 1628 "reflect.h2" auto regex_token_check::generate_code(generation_context& ctx) const -> void{ ctx.add_check(check + "(" + ctx.match_parameters() + ")"); } regex_token_check::~regex_token_check() noexcept{} -#line 1641 "reflect.h2" +#line 1642 "reflect.h2" regex_token_code::regex_token_code(cpp2::impl::in str, cpp2::impl::in code_) : regex_token{ str } , code{ code_ }{ -#line 1644 "reflect.h2" +#line 1645 "reflect.h2" } -#line 1646 "reflect.h2" +#line 1647 "reflect.h2" auto regex_token_code::generate_code(generation_context& ctx) const -> void{ ctx.add(code); } regex_token_code::~regex_token_code() noexcept{} -#line 1658 "reflect.h2" +#line 1659 "reflect.h2" regex_token_empty::regex_token_empty(cpp2::impl::in str) : regex_token{ str }{ -#line 1660 "reflect.h2" +#line 1661 "reflect.h2" } -#line 1662 "reflect.h2" +#line 1663 "reflect.h2" auto regex_token_empty::generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void{ // Nothing. } regex_token_empty::~regex_token_empty() noexcept{} -#line 1676 "reflect.h2" +#line 1677 "reflect.h2" regex_token_list::regex_token_list(cpp2::impl::in t) : regex_token{ gen_string(t) } , tokens{ t }{ -#line 1679 "reflect.h2" +#line 1680 "reflect.h2" } -#line 1681 "reflect.h2" +#line 1682 "reflect.h2" auto regex_token_list::generate_code(generation_context& ctx) const -> void{ for ( auto const& token : tokens ) { (*cpp2::impl::assert_not_null(token)).generate_code(ctx); } } -#line 1687 "reflect.h2" +#line 1688 "reflect.h2" auto regex_token_list::add_groups(std::set& groups) const -> void{ for ( auto const& token : tokens ) { (*cpp2::impl::assert_not_null(token)).add_groups(groups); } } -#line 1693 "reflect.h2" +#line 1694 "reflect.h2" [[nodiscard]] auto regex_token_list::gen_string(cpp2::impl::in vec) -> std::string{ std::string r {""}; for ( auto const& token : vec ) { @@ -3421,7 +3425,7 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov regex_token_list::~regex_token_list() noexcept{} -#line 1716 "reflect.h2" +#line 1717 "reflect.h2" auto parse_context_group_state::next_alternative() & -> void{ token_vec new_list {}; std::swap(new_list, cur_match_list); @@ -3429,14 +3433,14 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov static_cast(alternate_match_lists.insert(alternate_match_lists.end(), CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, cpp2::move(new_list)))); } -#line 1724 "reflect.h2" +#line 1725 "reflect.h2" auto parse_context_group_state::swap(parse_context_group_state& t) & -> void{ std::swap(cur_match_list, t.cur_match_list); std::swap(alternate_match_lists, t.alternate_match_lists); std::swap(modifiers, t.modifiers); } -#line 1731 "reflect.h2" +#line 1732 "reflect.h2" [[nodiscard]] auto parse_context_group_state::get_as_token() & -> token_ptr{ if (alternate_match_lists.empty()) { post_process_list(cur_match_list); @@ -3448,15 +3452,15 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov } } -#line 1743 "reflect.h2" +#line 1744 "reflect.h2" auto parse_context_group_state::add(cpp2::impl::in token) & -> void{ cur_match_list.push_back(token); } -#line 1748 "reflect.h2" +#line 1749 "reflect.h2" [[nodiscard]] auto parse_context_group_state::empty() const& -> bool { return cur_match_list.empty(); } -#line 1752 "reflect.h2" +#line 1753 "reflect.h2" auto parse_context_group_state::post_process_list(token_vec& list) -> void{ // Merge all characters auto merge_pos {list.begin()}; @@ -3477,7 +3481,7 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov , modifiers{ modifiers_ }{} parse_context_group_state::parse_context_group_state(){} -#line 1778 "reflect.h2" +#line 1779 "reflect.h2" [[nodiscard]] auto parse_context_branch_reset_state::next() & -> int{ auto g {cur_group}; cur_group += 1; @@ -3486,20 +3490,20 @@ parse_context_group_state::parse_context_group_state(){} return g; } -#line 1787 "reflect.h2" +#line 1788 "reflect.h2" auto parse_context_branch_reset_state::set_next(cpp2::impl::in g) & -> void{ cur_group = g; max_group = max(max_group, g); } -#line 1793 "reflect.h2" +#line 1794 "reflect.h2" auto parse_context_branch_reset_state::next_alternative() & -> void{ if (is_active) { cur_group = from; } } -#line 1800 "reflect.h2" +#line 1801 "reflect.h2" auto parse_context_branch_reset_state::set_active_reset(cpp2::impl::in restart) & -> void{ is_active = true; cur_group = restart; @@ -3514,16 +3518,16 @@ parse_context_group_state::parse_context_group_state(){} , from{ from_ }{} parse_context_branch_reset_state::parse_context_branch_reset_state(){} -#line 1828 "reflect.h2" +#line 1829 "reflect.h2" parse_context::parse_context(cpp2::impl::in r, auto const& e) : regex{ r } , root{ CPP2_UFCS_TEMPLATE_NONLOCAL(cpp2_new)(cpp2::shared, "") } , error_out{ e }{ -#line 1832 "reflect.h2" +#line 1833 "reflect.h2" } -#line 1838 "reflect.h2" +#line 1839 "reflect.h2" [[nodiscard]] auto parse_context::start_group() & -> parse_context_group_state { parse_context_group_state old_state {}; @@ -3533,7 +3537,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return old_state; } -#line 1848 "reflect.h2" +#line 1849 "reflect.h2" [[nodiscard]] auto parse_context::end_group(cpp2::impl::in old_state) & -> token_ptr { auto inner {cur_group_state.get_as_token()}; @@ -3541,17 +3545,17 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return inner; } -#line 1855 "reflect.h2" +#line 1856 "reflect.h2" [[nodiscard]] auto parse_context::get_modifiers() const& -> expression_flags{ return cur_group_state.modifiers; } -#line 1859 "reflect.h2" +#line 1860 "reflect.h2" auto parse_context::set_modifiers(cpp2::impl::in mod) & -> void{ cur_group_state.modifiers = mod; } -#line 1866 "reflect.h2" +#line 1867 "reflect.h2" [[nodiscard]] auto parse_context::branch_reset_new_state() & -> parse_context_branch_reset_state { parse_context_branch_reset_state old_state {}; @@ -3561,7 +3565,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return old_state; } -#line 1875 "reflect.h2" +#line 1876 "reflect.h2" auto parse_context::branch_reset_restore_state(cpp2::impl::in old_state) & -> void { auto max_group {cur_branch_reset_state.max_group}; @@ -3569,24 +3573,24 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} cur_branch_reset_state.set_next(cpp2::move(max_group)); } -#line 1882 "reflect.h2" +#line 1883 "reflect.h2" auto parse_context::next_alternative() & -> void { cur_group_state.next_alternative(); cur_branch_reset_state.next_alternative(); } -#line 1890 "reflect.h2" +#line 1891 "reflect.h2" auto parse_context::add_token(cpp2::impl::in token) & -> void{ cur_group_state.add(token); } -#line 1894 "reflect.h2" +#line 1895 "reflect.h2" [[nodiscard]] auto parse_context::has_token() const& -> bool{ return !(cur_group_state.empty()); } -#line 1898 "reflect.h2" +#line 1899 "reflect.h2" [[nodiscard]] auto parse_context::pop_token() & -> token_ptr { token_ptr r {nullptr}; @@ -3598,22 +3602,22 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 1909 "reflect.h2" +#line 1910 "reflect.h2" [[nodiscard]] auto parse_context::get_as_token() & -> token_ptr{ return root; } -#line 1915 "reflect.h2" +#line 1916 "reflect.h2" [[nodiscard]] auto parse_context::get_cur_group() const& -> int{ return cur_branch_reset_state.cur_group; } -#line 1919 "reflect.h2" +#line 1920 "reflect.h2" [[nodiscard]] auto parse_context::next_group() & -> int{ return cur_branch_reset_state.next(); } -#line 1923 "reflect.h2" +#line 1924 "reflect.h2" auto parse_context::set_named_group(cpp2::impl::in name, cpp2::impl::in id) & -> void { if (!(named_groups.contains(name))) {// Redefinition of group name is not an error. The left most one is retained. @@ -3621,7 +3625,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 1930 "reflect.h2" +#line 1931 "reflect.h2" [[nodiscard]] auto parse_context::get_named_group(cpp2::impl::in name) const& -> int { auto iter {named_groups.find(name)}; @@ -3633,10 +3637,10 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 1943 "reflect.h2" +#line 1944 "reflect.h2" [[nodiscard]] auto parse_context::current() const& -> char{return CPP2_ASSERT_IN_BOUNDS(regex, pos); } -#line 1946 "reflect.h2" +#line 1947 "reflect.h2" [[nodiscard]] auto parse_context::get_next_position(cpp2::impl::in in_class, cpp2::impl::in no_skip) const& -> size_t { auto perl_syntax {false}; @@ -3676,7 +3680,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return cur; } -#line 1986 "reflect.h2" +#line 1987 "reflect.h2" [[nodiscard]] auto parse_context::next_impl(cpp2::impl::in in_class, cpp2::impl::in no_skip) & -> bool { pos = get_next_position(in_class, no_skip); @@ -3688,14 +3692,14 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 1997 "reflect.h2" - [[nodiscard]] auto parse_context::next() & -> auto { return next_impl(false, false); } #line 1998 "reflect.h2" - [[nodiscard]] auto parse_context::next_in_class() & -> auto { return next_impl(true, false); } + [[nodiscard]] auto parse_context::next() & -> auto { return next_impl(false, false); } #line 1999 "reflect.h2" + [[nodiscard]] auto parse_context::next_in_class() & -> auto { return next_impl(true, false); } +#line 2000 "reflect.h2" [[nodiscard]] auto parse_context::next_no_skip() & -> auto { return next_impl(false, true); } -#line 2001 "reflect.h2" +#line 2002 "reflect.h2" [[nodiscard]] auto parse_context::next_n(cpp2::impl::in n) & -> bool{ auto r {true}; auto cur {0}; @@ -3705,10 +3709,10 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 2010 "reflect.h2" +#line 2011 "reflect.h2" [[nodiscard]] auto parse_context::has_next() const& -> bool{return cpp2::impl::cmp_less(pos,regex.size()); } -#line 2012 "reflect.h2" +#line 2013 "reflect.h2" [[nodiscard]] auto parse_context::grab_until_impl(cpp2::impl::in e, cpp2::impl::out r, cpp2::impl::in any) & -> bool { auto end {pos}; @@ -3730,14 +3734,14 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2033 "reflect.h2" - [[nodiscard]] auto parse_context::grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(e, cpp2::impl::out(&r), false); } #line 2034 "reflect.h2" - [[nodiscard]] auto parse_context::grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(std::string(1, e), cpp2::impl::out(&r), false); } + [[nodiscard]] auto parse_context::grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(e, cpp2::impl::out(&r), false); } #line 2035 "reflect.h2" + [[nodiscard]] auto parse_context::grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(std::string(1, e), cpp2::impl::out(&r), false); } +#line 2036 "reflect.h2" [[nodiscard]] auto parse_context::grab_until_one_of(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(e, cpp2::impl::out(&r), true); } -#line 2037 "reflect.h2" +#line 2038 "reflect.h2" [[nodiscard]] auto parse_context::grab_n(cpp2::impl::in n, cpp2::impl::out r) & -> bool { if (cpp2::impl::cmp_less_eq(pos + cpp2::impl::as_(n),regex.size())) { @@ -3751,7 +3755,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2050 "reflect.h2" +#line 2051 "reflect.h2" [[nodiscard]] auto parse_context::grab_number() & -> std::string { auto start {pos}; @@ -3773,7 +3777,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return cpp2::move(r.value()); } -#line 2071 "reflect.h2" +#line 2072 "reflect.h2" [[nodiscard]] auto parse_context::peek_impl(cpp2::impl::in in_class) const& -> char{ auto next_pos {get_next_position(in_class, false)}; if (cpp2::impl::cmp_less(next_pos,regex.size())) { @@ -3784,12 +3788,12 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2081 "reflect.h2" - [[nodiscard]] auto parse_context::peek() const& -> auto { return peek_impl(false); } #line 2082 "reflect.h2" + [[nodiscard]] auto parse_context::peek() const& -> auto { return peek_impl(false); } +#line 2083 "reflect.h2" [[nodiscard]] auto parse_context::peek_in_class() const& -> auto { return peek_impl(true); } -#line 2087 "reflect.h2" +#line 2088 "reflect.h2" [[nodiscard]] auto parse_context::parser_group_modifiers(cpp2::impl::in change_str, expression_flags& parser_modifiers) & -> bool { auto is_negative {false}; @@ -3844,7 +3848,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return true; } -#line 2141 "reflect.h2" +#line 2142 "reflect.h2" [[nodiscard]] auto parse_context::parse_until(cpp2::impl::in term) & -> bool{ token_ptr cur_token {}; @@ -3883,7 +3887,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return true; } -#line 2179 "reflect.h2" +#line 2180 "reflect.h2" [[nodiscard]] auto parse_context::parse(cpp2::impl::in modifiers) & -> bool { @@ -3899,21 +3903,21 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 2196 "reflect.h2" - [[nodiscard]] auto parse_context::get_pos() const& -> auto { return pos; } #line 2197 "reflect.h2" - [[nodiscard]] auto parse_context::get_range(cpp2::impl::in start, cpp2::impl::in end) const& -> auto { return std::string(regex.substr(start, end - start + 1)); } + [[nodiscard]] auto parse_context::get_pos() const& -> auto { return pos; } #line 2198 "reflect.h2" + [[nodiscard]] auto parse_context::get_range(cpp2::impl::in start, cpp2::impl::in end) const& -> auto { return std::string(regex.substr(start, end - start + 1)); } +#line 2199 "reflect.h2" [[nodiscard]] auto parse_context::valid() const& -> bool{return has_next() && !(has_error); } -#line 2200 "reflect.h2" +#line 2201 "reflect.h2" [[nodiscard]] auto parse_context::error(cpp2::impl::in err) & -> token_ptr{ has_error = true; error_out("Error during parsing of regex '" + cpp2::to_string(regex) + "' at position '" + cpp2::to_string(pos) + "': " + cpp2::to_string(err) + ""); return nullptr; } -#line 2215 "reflect.h2" +#line 2216 "reflect.h2" auto generation_function_context::add_tabs(cpp2::impl::in c) & -> void{ int i {0}; for( ; cpp2::impl::cmp_less(i,c); i += 1 ) { @@ -3921,7 +3925,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2222 "reflect.h2" +#line 2223 "reflect.h2" auto generation_function_context::remove_tabs(cpp2::impl::in c) & -> void{ tabs = tabs.substr(0, (cpp2::impl::as_(c)) * 2); } @@ -3931,22 +3935,22 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} , tabs{ tabs_ }{} generation_function_context::generation_function_context(){} -#line 2240 "reflect.h2" +#line 2241 "reflect.h2" [[nodiscard]] auto generation_context::match_parameters() const& -> std::string{return "r.pos, ctx"; } -#line 2245 "reflect.h2" +#line 2246 "reflect.h2" auto generation_context::add(cpp2::impl::in s) & -> void{ auto cur {get_current()}; (*cpp2::impl::assert_not_null(cur)).code += "" + cpp2::to_string((*cpp2::impl::assert_not_null(cur)).tabs) + cpp2::to_string(s) + "\n"; } -#line 2251 "reflect.h2" +#line 2252 "reflect.h2" auto generation_context::add_check(cpp2::impl::in check) & -> void{ auto cur {get_current()}; (*cpp2::impl::assert_not_null(cur)).code += "" + cpp2::to_string((*cpp2::impl::assert_not_null(cur)).tabs) + "if !cpp2::regex::" + cpp2::to_string(check) + " { r.matched = false; break; }\n"; } -#line 2257 "reflect.h2" +#line 2258 "reflect.h2" auto generation_context::add_statefull(cpp2::impl::in next_func, cpp2::impl::in check) & -> void { end_func_statefull(check); @@ -3955,7 +3959,7 @@ generation_function_context::generation_function_context(){} start_func_named(cpp2::move(name)); } -#line 2265 "reflect.h2" +#line 2266 "reflect.h2" auto generation_context::start_func_named(cpp2::impl::in name) & -> void { auto cur {new_context()}; @@ -3967,7 +3971,7 @@ generation_function_context::generation_function_context(){} (*cpp2::impl::assert_not_null(cpp2::move(cur))).add_tabs(3); } -#line 2276 "reflect.h2" +#line 2277 "reflect.h2" [[nodiscard]] auto generation_context::start_func() & -> std::string { auto name {gen_func_name()}; @@ -3975,7 +3979,7 @@ generation_function_context::generation_function_context(){} return cpp2::move(name) + "()"; } -#line 2283 "reflect.h2" +#line 2284 "reflect.h2" auto generation_context::end_func_statefull(cpp2::impl::in s) & -> void { auto cur {get_current()}; @@ -3995,7 +3999,7 @@ generation_function_context::generation_function_context(){} finish_context(); } -#line 2303 "reflect.h2" +#line 2304 "reflect.h2" [[nodiscard]] auto generation_context::generate_func(cpp2::impl::in token) & -> std::string { auto name {start_func()}; @@ -4005,7 +4009,7 @@ generation_function_context::generation_function_context(){} return name; } -#line 2313 "reflect.h2" +#line 2314 "reflect.h2" [[nodiscard]] auto generation_context::generate_reset(cpp2::impl::in> groups) & -> std::string { if (groups.empty()) { @@ -4028,33 +4032,33 @@ generation_function_context::generation_function_context(){} return cpp2::move(name) + "()"; } -#line 2337 "reflect.h2" +#line 2338 "reflect.h2" [[nodiscard]] auto generation_context::gen_func_name() & -> std::string{ auto cur_id {matcher_func}; matcher_func += 1; return "func_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2343 "reflect.h2" +#line 2344 "reflect.h2" [[nodiscard]] auto generation_context::next_func_name() & -> std::string{ return gen_func_name() + "()"; } -#line 2347 "reflect.h2" +#line 2348 "reflect.h2" [[nodiscard]] auto generation_context::gen_reset_func_name() & -> std::string{ auto cur_id {reset_func}; reset_func += 1; return "reset_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2353 "reflect.h2" +#line 2354 "reflect.h2" [[nodiscard]] auto generation_context::gen_temp() & -> std::string{ auto cur_id {temp_name}; temp_name += 1; return "tmp_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2361 "reflect.h2" +#line 2362 "reflect.h2" [[nodiscard]] auto generation_context::new_context() & -> generation_function_context*{ gen_stack.push_back(generation_function_context()); auto cur {get_current()}; @@ -4063,7 +4067,7 @@ generation_function_context::generation_function_context(){} return cur; } -#line 2369 "reflect.h2" +#line 2370 "reflect.h2" auto generation_context::finish_context() & -> void{ auto cur {get_current()}; auto base {get_base()}; @@ -4072,22 +4076,22 @@ generation_function_context::generation_function_context(){} gen_stack.pop_back(); } -#line 2379 "reflect.h2" +#line 2380 "reflect.h2" [[nodiscard]] auto generation_context::get_current() & -> generation_function_context*{ return &gen_stack.back(); } -#line 2383 "reflect.h2" +#line 2384 "reflect.h2" [[nodiscard]] auto generation_context::get_base() & -> generation_function_context*{ return &CPP2_ASSERT_IN_BOUNDS_LITERAL(gen_stack, 0); } -#line 2387 "reflect.h2" +#line 2388 "reflect.h2" [[nodiscard]] auto generation_context::get_entry_func() const& -> std::string{ return entry_func; } -#line 2391 "reflect.h2" +#line 2392 "reflect.h2" [[nodiscard]] auto generation_context::create_named_group_lookup(cpp2::impl::in> named_groups) const& -> std::string { std::string res {"get_named_group_index: (name) -> int = {\n"}; @@ -4111,18 +4115,18 @@ generation_function_context::generation_function_context(){} return res; } -#line 2416 "reflect.h2" +#line 2417 "reflect.h2" [[nodiscard]] auto generation_context::run(cpp2::impl::in token) & -> std::string{ entry_func = generate_func(token); return (*cpp2::impl::assert_not_null(get_base())).code; } -#line 2431 "reflect.h2" +#line 2432 "reflect.h2" alternative_token::alternative_token() : regex_token_empty{ "" }{} -#line 2433 "reflect.h2" +#line 2434 "reflect.h2" [[nodiscard]] auto alternative_token::parse(parse_context& ctx) -> token_ptr{ if (ctx.current() != '|') {return nullptr; } @@ -4133,15 +4137,15 @@ generation_function_context::generation_function_context(){} alternative_token::~alternative_token() noexcept{} -#line 2448 "reflect.h2" +#line 2449 "reflect.h2" alternative_token_gen::alternative_token_gen(cpp2::impl::in a) : regex_token{ gen_string(a) } , alternatives{ a }{ -#line 2451 "reflect.h2" +#line 2452 "reflect.h2" } -#line 2453 "reflect.h2" +#line 2454 "reflect.h2" auto alternative_token_gen::generate_code(generation_context& ctx) const -> void { std::string functions {""}; @@ -4159,7 +4163,7 @@ generation_function_context::generation_function_context(){} ctx.add_statefull(next_name, "cpp2::regex::alternative_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ", other, " + cpp2::to_string(next_name) + " " + cpp2::to_string(cpp2::move(functions)) + ")"); } -#line 2470 "reflect.h2" +#line 2471 "reflect.h2" auto alternative_token_gen::add_groups(std::set& groups) const -> void { for ( auto const& cur : alternatives ) { @@ -4167,7 +4171,7 @@ generation_function_context::generation_function_context(){} } } -#line 2477 "reflect.h2" +#line 2478 "reflect.h2" [[nodiscard]] auto alternative_token_gen::gen_string(cpp2::impl::in a) -> std::string { std::string r {""}; @@ -4183,14 +4187,14 @@ generation_function_context::generation_function_context(){} alternative_token_gen::~alternative_token_gen() noexcept{} -#line 2498 "reflect.h2" +#line 2499 "reflect.h2" any_token::any_token(cpp2::impl::in single_line) : regex_token_check{ ".", "any_token_matcher" }{ -#line 2500 "reflect.h2" +#line 2501 "reflect.h2" } -#line 2502 "reflect.h2" +#line 2503 "reflect.h2" [[nodiscard]] auto any_token::parse(parse_context& ctx) -> token_ptr{ if ('.' != ctx.current()) {return nullptr; } @@ -4199,21 +4203,21 @@ generation_function_context::generation_function_context(){} any_token::~any_token() noexcept{} -#line 2519 "reflect.h2" +#line 2520 "reflect.h2" char_token::char_token(cpp2::impl::in t, cpp2::impl::in ignore_case_) : regex_token{ std::string(1, t) } , token{ t } , ignore_case{ ignore_case_ }{ -#line 2523 "reflect.h2" +#line 2524 "reflect.h2" } -#line 2525 "reflect.h2" +#line 2526 "reflect.h2" [[nodiscard]] auto char_token::parse(parse_context& ctx) -> token_ptr{ return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, ctx.current(), ctx.get_modifiers().has(expression_flags::case_insensitive)); } -#line 2529 "reflect.h2" +#line 2530 "reflect.h2" auto char_token::generate_code(generation_context& ctx) const -> void { if (ignore_case) { @@ -4222,14 +4226,14 @@ generation_function_context::generation_function_context(){} { size_t i{0}; -#line 2535 "reflect.h2" +#line 2536 "reflect.h2" for( ; cpp2::impl::cmp_less(i,token.size()); i += 1 ) { CPP2_ASSERT_IN_BOUNDS(lower, i) = string_util::safe_tolower(CPP2_ASSERT_IN_BOUNDS(token, i)); CPP2_ASSERT_IN_BOUNDS(upper, i) = string_util::safe_toupper(CPP2_ASSERT_IN_BOUNDS(token, i)); } } -#line 2540 "reflect.h2" +#line 2541 "reflect.h2" if (upper != lower) { gen_case_insensitive(cpp2::move(lower), cpp2::move(upper), ctx); } @@ -4242,7 +4246,7 @@ size_t i{0}; } } -#line 2552 "reflect.h2" +#line 2553 "reflect.h2" auto char_token::gen_case_insensitive(cpp2::impl::in lower, cpp2::impl::in upper, generation_context& ctx) const& -> void { std::string name {"str_" + cpp2::to_string(ctx.gen_temp()) + ""}; @@ -4264,7 +4268,7 @@ size_t i{0}; ctx.add("else { break; }"); } -#line 2573 "reflect.h2" +#line 2574 "reflect.h2" auto char_token::gen_case_sensitive(generation_context& ctx) const& -> void { std::string name {"str_" + cpp2::to_string(ctx.gen_temp()) + ""}; @@ -4283,7 +4287,7 @@ size_t i{0}; ctx.add("else { break; }"); } -#line 2591 "reflect.h2" +#line 2592 "reflect.h2" [[nodiscard]] auto char_token::add_escapes(std::string str) const& -> std::string { str = string_util::replace_all(str, "\\", "\\\\"); @@ -4299,7 +4303,7 @@ size_t i{0}; return cpp2::move(str); } -#line 2606 "reflect.h2" +#line 2607 "reflect.h2" auto char_token::append(char_token const& that) & -> void{ (*this).token += that.token; (*this).string_rep += that.string_rep; @@ -4307,19 +4311,19 @@ size_t i{0}; char_token::~char_token() noexcept{} -#line 2623 "reflect.h2" +#line 2624 "reflect.h2" class_token::class_token(cpp2::impl::in negate_, cpp2::impl::in case_insensitive_, cpp2::impl::in class_str_, cpp2::impl::in str) : regex_token{ str } , negate{ negate_ } , case_insensitive{ case_insensitive_ } , class_str{ class_str_ } -#line 2624 "reflect.h2" +#line 2625 "reflect.h2" { -#line 2629 "reflect.h2" +#line 2630 "reflect.h2" } -#line 2632 "reflect.h2" +#line 2633 "reflect.h2" [[nodiscard]] auto class_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '[') {return nullptr; } @@ -4445,13 +4449,13 @@ size_t i{0}; ); } -#line 2757 "reflect.h2" +#line 2758 "reflect.h2" auto class_token::generate_code(generation_context& ctx) const -> void { ctx.add_check("class_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ")"); } -#line 2762 "reflect.h2" +#line 2763 "reflect.h2" [[nodiscard]] auto class_token::create_matcher(cpp2::impl::in name, cpp2::impl::in template_arguments) -> std::string { auto sep {", "}; @@ -4462,12 +4466,12 @@ size_t i{0}; class_token::~class_token() noexcept{} -#line 2774 "reflect.h2" +#line 2775 "reflect.h2" [[nodiscard]] auto escape_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } -#line 2779 "reflect.h2" +#line 2780 "reflect.h2" if (std::string::npos == std::string("afenrt^.[]()*{}?+|\\").find(ctx.peek())) { return nullptr; } @@ -4501,7 +4505,7 @@ size_t i{0}; } -#line 2815 "reflect.h2" +#line 2816 "reflect.h2" [[nodiscard]] auto global_group_reset_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'K'))) {return nullptr; } @@ -4510,18 +4514,18 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, "\\K", "ctx..set_group_start(0, r.pos);"); } -#line 2837 "reflect.h2" +#line 2838 "reflect.h2" group_ref_token::group_ref_token(cpp2::impl::in id_, cpp2::impl::in case_insensitive_, cpp2::impl::in str) : regex_token{ str } , id{ id_ } , case_insensitive{ case_insensitive_ } -#line 2838 "reflect.h2" +#line 2839 "reflect.h2" { -#line 2842 "reflect.h2" +#line 2843 "reflect.h2" } -#line 2844 "reflect.h2" +#line 2845 "reflect.h2" [[nodiscard]] auto group_ref_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -4623,14 +4627,14 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, cpp2::move(group_id), ctx.get_modifiers().has(expression_flags::case_insensitive), cpp2::move(str)); } -#line 2945 "reflect.h2" +#line 2946 "reflect.h2" auto group_ref_token::generate_code(generation_context& ctx) const -> void{ ctx.add_check("group_ref_token_matcher(" + cpp2::to_string(ctx.match_parameters()) + ")"); } group_ref_token::~group_ref_token() noexcept{} -#line 2968 "reflect.h2" +#line 2969 "reflect.h2" [[nodiscard]] auto group_token::parse_lookahead(parse_context& ctx, cpp2::impl::in syntax, cpp2::impl::in positive) -> token_ptr { static_cast(ctx.next());// Skip last token defining the syntax @@ -4645,7 +4649,7 @@ size_t i{0}; return r; } -#line 2982 "reflect.h2" +#line 2983 "reflect.h2" [[nodiscard]] auto group_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '(') {return nullptr; } @@ -4783,7 +4787,7 @@ size_t i{0}; } } -#line 3119 "reflect.h2" +#line 3120 "reflect.h2" [[nodiscard]] auto group_token::gen_string(cpp2::impl::in name, cpp2::impl::in name_brackets, cpp2::impl::in has_modifier, cpp2::impl::in modifiers, cpp2::impl::in inner_) -> std::string { std::string start {"("}; @@ -4802,7 +4806,7 @@ size_t i{0}; return cpp2::move(start) + (*cpp2::impl::assert_not_null(inner_)).to_string() + ")"; } -#line 3137 "reflect.h2" +#line 3138 "reflect.h2" auto group_token::generate_code(generation_context& ctx) const -> void { if (-1 != number) { @@ -4823,7 +4827,7 @@ size_t i{0}; } } -#line 3157 "reflect.h2" +#line 3158 "reflect.h2" auto group_token::add_groups(std::set& groups) const -> void { (*cpp2::impl::assert_not_null(inner)).add_groups(groups); @@ -4834,7 +4838,7 @@ size_t i{0}; group_token::~group_token() noexcept{} -#line 3169 "reflect.h2" +#line 3170 "reflect.h2" [[nodiscard]] auto hexadecimal_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'x'))) {return nullptr; } @@ -4873,7 +4877,7 @@ size_t i{0}; return r; } -#line 3210 "reflect.h2" +#line 3211 "reflect.h2" [[nodiscard]] auto line_end_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() == '$' || (ctx.current() == '\\' && ctx.peek() == '$')) { @@ -4891,7 +4895,7 @@ size_t i{0}; }} } -#line 3230 "reflect.h2" +#line 3231 "reflect.h2" [[nodiscard]] auto line_start_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '^' && !((ctx.current() == '\\' && ctx.peek() == 'A'))) {return nullptr; } @@ -4905,29 +4909,29 @@ size_t i{0}; } } -#line 3255 "reflect.h2" +#line 3256 "reflect.h2" lookahead_token::lookahead_token(cpp2::impl::in positive_) : regex_token{ "" } , positive{ positive_ }{ -#line 3257 "reflect.h2" +#line 3258 "reflect.h2" } -#line 3259 "reflect.h2" +#line 3260 "reflect.h2" auto lookahead_token::generate_code(generation_context& ctx) const -> void{ auto inner_name {ctx.generate_func(inner)}; ctx.add_check("lookahead_token_matcher(" + cpp2::to_string(ctx.match_parameters()) + ", " + cpp2::to_string(cpp2::move(inner_name)) + ")"); } -#line 3265 "reflect.h2" +#line 3266 "reflect.h2" auto lookahead_token::add_groups(std::set& groups) const -> void{ (*cpp2::impl::assert_not_null(inner)).add_groups(groups); } lookahead_token::~lookahead_token() noexcept{} -#line 3273 "reflect.h2" +#line 3274 "reflect.h2" [[nodiscard]] auto named_class_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -4953,7 +4957,7 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, "\\" + cpp2::to_string(ctx.current()) + "", "" + cpp2::to_string(cpp2::move(name)) + "::match"); } -#line 3301 "reflect.h2" +#line 3302 "reflect.h2" [[nodiscard]] auto octal_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'o'))) {return nullptr; } @@ -4979,11 +4983,11 @@ size_t i{0}; return r; } -#line 3338 "reflect.h2" +#line 3339 "reflect.h2" range_token::range_token() : regex_token{ "" }{} -#line 3340 "reflect.h2" +#line 3341 "reflect.h2" [[nodiscard]] auto range_token::parse(parse_context& ctx) -> token_ptr { auto r {CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared)}; @@ -5057,7 +5061,7 @@ size_t i{0}; return nullptr; } -#line 3413 "reflect.h2" +#line 3414 "reflect.h2" auto range_token::parse_modifier(parse_context& ctx) & -> void { if (ctx.peek() == '?') { @@ -5070,7 +5074,7 @@ size_t i{0}; }} } -#line 3425 "reflect.h2" +#line 3426 "reflect.h2" [[nodiscard]] auto range_token::gen_mod_string() const& -> std::string { if (kind == range_flags::not_greedy) { @@ -5084,7 +5088,7 @@ size_t i{0}; }} } -#line 3438 "reflect.h2" +#line 3439 "reflect.h2" [[nodiscard]] auto range_token::gen_range_string() const& -> std::string { std::string r {""}; @@ -5104,7 +5108,7 @@ size_t i{0}; return r; } -#line 3457 "reflect.h2" +#line 3458 "reflect.h2" auto range_token::generate_code(generation_context& ctx) const -> void { auto inner_name {ctx.generate_func(inner_token)}; @@ -5116,14 +5120,14 @@ size_t i{0}; ctx.add_statefull(next_name, "cpp2::regex::range_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ", " + cpp2::to_string(cpp2::move(inner_name)) + ", " + cpp2::to_string(cpp2::move(reset_name)) + ", other, " + cpp2::to_string(next_name) + ")"); } -#line 3468 "reflect.h2" +#line 3469 "reflect.h2" auto range_token::add_groups(std::set& groups) const -> void{ (*cpp2::impl::assert_not_null(inner_token)).add_groups(groups); } range_token::~range_token() noexcept{} -#line 3481 "reflect.h2" +#line 3482 "reflect.h2" [[nodiscard]] auto special_range_token::parse(parse_context& ctx) -> token_ptr { auto r {CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared)}; @@ -5147,7 +5151,7 @@ size_t i{0}; if (!(ctx.has_token())) {return ctx.error("'" + cpp2::to_string(ctx.current()) + "' without previous element."); } -#line 3505 "reflect.h2" +#line 3506 "reflect.h2" (*cpp2::impl::assert_not_null(r)).parse_modifier(ctx); (*cpp2::impl::assert_not_null(r)).inner_token = ctx.pop_token(); @@ -5157,7 +5161,7 @@ size_t i{0}; special_range_token::~special_range_token() noexcept{} -#line 3518 "reflect.h2" +#line 3519 "reflect.h2" [[nodiscard]] auto word_boundary_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -5175,15 +5179,15 @@ size_t i{0}; }} } -#line 3554 "reflect.h2" +#line 3555 "reflect.h2" template regex_generator::regex_generator(cpp2::impl::in r, Error_out const& e) : regex{ r } , error_out{ e }{ -#line 3557 "reflect.h2" +#line 3558 "reflect.h2" } -#line 3559 "reflect.h2" +#line 3560 "reflect.h2" template [[nodiscard]] auto regex_generator::parse() & -> std::string { // Extract modifiers and adapt regex. @@ -5219,7 +5223,7 @@ size_t i{0}; return source; } -#line 3594 "reflect.h2" +#line 3595 "reflect.h2" template auto regex_generator::extract_modifiers() & -> void { if (regex.find_first_of("'/") == 0) { @@ -5235,7 +5239,7 @@ size_t i{0}; } } -#line 3610 "reflect.h2" +#line 3611 "reflect.h2" template [[nodiscard]] auto generate_regex(cpp2::impl::in regex, Err const& err) -> std::string { regex_generator parser {regex, err}; @@ -5244,7 +5248,7 @@ template [[nodiscard]] auto generate_regex(cpp2::impl::in void { auto has_default {false}; @@ -5299,7 +5303,7 @@ auto regex_gen(meta::type_declaration& t) -> void CPP2_UFCS(add_runtime_support_include)(t, "cpp2regex.h"); } -#line 3679 "reflect.h2" +#line 3680 "reflect.h2" [[nodiscard]] auto apply_metafunctions( declaration_node& n, type_declaration& rtype, @@ -5414,7 +5418,7 @@ auto regex_gen(meta::type_declaration& t) -> void return true; } -#line 3798 "reflect.h2" +#line 3799 "reflect.h2" [[nodiscard]] auto apply_metafunctions( declaration_node& n, function_declaration& rfunc, @@ -5464,7 +5468,7 @@ auto regex_gen(meta::type_declaration& t) -> void return true; } -#line 3848 "reflect.h2" +#line 3849 "reflect.h2" } } diff --git a/source/reflect.h2 b/source/reflect.h2 index dbab4e77c..daf73d84a 100644 --- a/source/reflect.h2 +++ b/source/reflect.h2 @@ -329,6 +329,7 @@ declaration: @polymorphic_base @copyable type = if has_name() { return n*.name()*.as_string_view(); } else { return ""; } } + fully_qualified_name: (this) -> std::string = n*.fully_qualified_name(); has_initializer: (this) -> bool = n*.has_initializer(); From e3e33ddb68e2339784a9039cb82f1c2dc20ab95b Mon Sep 17 00:00:00 2001 From: Dylam De La Torre Date: Wed, 15 May 2024 20:17:03 +0200 Subject: [PATCH 4/9] Add implementation of `@meta` metafunction --- source/reflect.h | 739 ++++++++++++++++++++++++---------------------- source/reflect.h2 | 40 ++- 2 files changed, 415 insertions(+), 364 deletions(-) diff --git a/source/reflect.h b/source/reflect.h index f3d9f1f8e..fe2a1d272 100644 --- a/source/reflect.h +++ b/source/reflect.h @@ -39,74 +39,74 @@ class alias_declaration; #line 1053 "reflect.h2" class value_member_info; -#line 1575 "reflect.h2" +#line 1596 "reflect.h2" class expression_flags; -#line 1591 "reflect.h2" +#line 1612 "reflect.h2" class regex_token; -#line 1617 "reflect.h2" +#line 1638 "reflect.h2" class regex_token_check; -#line 1636 "reflect.h2" +#line 1657 "reflect.h2" class regex_token_code; -#line 1655 "reflect.h2" +#line 1676 "reflect.h2" class regex_token_empty; -#line 1671 "reflect.h2" +#line 1692 "reflect.h2" class regex_token_list; -#line 1710 "reflect.h2" +#line 1731 "reflect.h2" class parse_context_group_state; -#line 1771 "reflect.h2" +#line 1792 "reflect.h2" class parse_context_branch_reset_state; -#line 1814 "reflect.h2" +#line 1835 "reflect.h2" class parse_context; -#line 2212 "reflect.h2" +#line 2233 "reflect.h2" class generation_function_context; -#line 2230 "reflect.h2" +#line 2251 "reflect.h2" class generation_context; -#line 2428 "reflect.h2" +#line 2449 "reflect.h2" class alternative_token; -#line 2443 "reflect.h2" +#line 2464 "reflect.h2" class alternative_token_gen; -#line 2495 "reflect.h2" +#line 2516 "reflect.h2" class any_token; -#line 2513 "reflect.h2" +#line 2534 "reflect.h2" class char_token; -#line 2616 "reflect.h2" +#line 2637 "reflect.h2" class class_token; -#line 2831 "reflect.h2" +#line 2852 "reflect.h2" class group_ref_token; -#line 2962 "reflect.h2" +#line 2983 "reflect.h2" class group_token; -#line 3249 "reflect.h2" +#line 3270 "reflect.h2" class lookahead_token; -#line 3330 "reflect.h2" +#line 3351 "reflect.h2" class range_token; -#line 3478 "reflect.h2" +#line 3499 "reflect.h2" class special_range_token; -#line 3545 "reflect.h2" +#line 3566 "reflect.h2" template class regex_generator; -#line 3849 "reflect.h2" +#line 3873 "reflect.h2" } } @@ -564,10 +564,13 @@ auto print(cpp2::impl::in t) -> void; #line 1552 "reflect.h2" auto print(cpp2::impl::in f) -> void; -#line 1571 "reflect.h2" +#line 1562 "reflect.h2" +auto meta(meta::function_declaration& f) -> void; + +#line 1592 "reflect.h2" using error_func = std::function x)>; -#line 1575 "reflect.h2" +#line 1596 "reflect.h2" class expression_flags { private: cpp2::u8 _value; private: constexpr expression_flags(cpp2::impl::in _val); @@ -602,20 +605,20 @@ public: [[nodiscard]] auto to_code() const& -> std::string; public: [[nodiscard]] static auto from_string(cpp2::impl::in s) -> expression_flags; public: [[nodiscard]] static auto from_code(cpp2::impl::in s) -> expression_flags; -#line 1583 "reflect.h2" +#line 1604 "reflect.h2" }; -#line 1591 "reflect.h2" +#line 1612 "reflect.h2" class regex_token { public: std::string string_rep; public: explicit regex_token(cpp2::impl::in str); -#line 1599 "reflect.h2" +#line 1620 "reflect.h2" public: explicit regex_token(); -#line 1604 "reflect.h2" +#line 1625 "reflect.h2" public: virtual auto generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void = 0; public: virtual auto add_groups([[maybe_unused]] std::set& unnamed_param_2) const -> void; @@ -626,24 +629,24 @@ class regex_token public: regex_token(regex_token const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(regex_token const&) -> void = delete; -#line 1609 "reflect.h2" +#line 1630 "reflect.h2" }; using token_ptr = std::shared_ptr; using token_vec = std::vector; -#line 1615 "reflect.h2" +#line 1636 "reflect.h2" // Adds a check in code generation. // class regex_token_check : public regex_token { -#line 1621 "reflect.h2" +#line 1642 "reflect.h2" private: std::string check; public: explicit regex_token_check(cpp2::impl::in str, cpp2::impl::in check_); -#line 1628 "reflect.h2" +#line 1649 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~regex_token_check() noexcept; @@ -651,21 +654,21 @@ class regex_token_check public: auto operator=(regex_token_check const&) -> void = delete; -#line 1631 "reflect.h2" +#line 1652 "reflect.h2" }; -#line 1634 "reflect.h2" +#line 1655 "reflect.h2" // Adds code in code generation. // class regex_token_code : public regex_token { -#line 1640 "reflect.h2" +#line 1661 "reflect.h2" private: std::string code; public: explicit regex_token_code(cpp2::impl::in str, cpp2::impl::in code_); -#line 1647 "reflect.h2" +#line 1668 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~regex_token_code() noexcept; @@ -673,19 +676,19 @@ class regex_token_code public: auto operator=(regex_token_code const&) -> void = delete; -#line 1650 "reflect.h2" +#line 1671 "reflect.h2" }; -#line 1653 "reflect.h2" +#line 1674 "reflect.h2" // Token that does not influence the matching. E.g. comment. // class regex_token_empty : public regex_token { -#line 1659 "reflect.h2" +#line 1680 "reflect.h2" public: explicit regex_token_empty(cpp2::impl::in str); -#line 1663 "reflect.h2" +#line 1684 "reflect.h2" public: auto generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void override; public: virtual ~regex_token_empty() noexcept; @@ -693,27 +696,27 @@ class regex_token_empty public: auto operator=(regex_token_empty const&) -> void = delete; -#line 1666 "reflect.h2" +#line 1687 "reflect.h2" }; -#line 1669 "reflect.h2" +#line 1690 "reflect.h2" // Represents a list of regex tokens as one token. // class regex_token_list : public regex_token { -#line 1675 "reflect.h2" +#line 1696 "reflect.h2" public: token_vec tokens; public: explicit regex_token_list(cpp2::impl::in t); -#line 1682 "reflect.h2" +#line 1703 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 1688 "reflect.h2" +#line 1709 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; -#line 1694 "reflect.h2" +#line 1715 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in vec) -> std::string; public: virtual ~regex_token_list() noexcept; @@ -721,10 +724,10 @@ class regex_token_list public: auto operator=(regex_token_list const&) -> void = delete; -#line 1701 "reflect.h2" +#line 1722 "reflect.h2" }; -#line 1704 "reflect.h2" +#line 1725 "reflect.h2" // // Parse and generation context. // @@ -740,33 +743,33 @@ class parse_context_group_state // Start a new alternative. public: auto next_alternative() & -> void; -#line 1724 "reflect.h2" +#line 1745 "reflect.h2" // Swap this state with the other one. public: auto swap(parse_context_group_state& t) & -> void; -#line 1731 "reflect.h2" +#line 1752 "reflect.h2" // Convert this state into a regex token. public: [[nodiscard]] auto get_as_token() & -> token_ptr; -#line 1743 "reflect.h2" +#line 1764 "reflect.h2" // Add a token to the current matcher list. public: auto add(cpp2::impl::in token) & -> void; -#line 1748 "reflect.h2" +#line 1769 "reflect.h2" // True if current matcher list is empty. public: [[nodiscard]] auto empty() const& -> bool; -#line 1752 "reflect.h2" +#line 1773 "reflect.h2" // Apply optimizations to the matcher list. public: static auto post_process_list(token_vec& list) -> void; public: parse_context_group_state(auto const& cur_match_list_, auto const& alternate_match_lists_, auto const& modifiers_); public: parse_context_group_state(); -#line 1766 "reflect.h2" +#line 1787 "reflect.h2" }; -#line 1769 "reflect.h2" +#line 1790 "reflect.h2" // State for the branch reset. Takes care of the group numbering. See '(|)'. // class parse_context_branch_reset_state @@ -779,25 +782,25 @@ class parse_context_branch_reset_state // Next group identifier. public: [[nodiscard]] auto next() & -> int; -#line 1787 "reflect.h2" +#line 1808 "reflect.h2" // Set next group identifier. public: auto set_next(cpp2::impl::in g) & -> void; -#line 1793 "reflect.h2" +#line 1814 "reflect.h2" // Start a new alternative branch. public: auto next_alternative() & -> void; -#line 1800 "reflect.h2" +#line 1821 "reflect.h2" // Initialize for a branch reset group. public: auto set_active_reset(cpp2::impl::in restart) & -> void; public: parse_context_branch_reset_state(auto const& is_active_, auto const& cur_group_, auto const& max_group_, auto const& from_); public: parse_context_branch_reset_state(); -#line 1807 "reflect.h2" +#line 1828 "reflect.h2" }; -#line 1810 "reflect.h2" +#line 1831 "reflect.h2" // Context during parsing of the regular expressions. // // Keeps track of the distributed group identifiers, current parsed group and branch resets. @@ -811,7 +814,7 @@ class parse_context private: parse_context_group_state cur_group_state {}; private: parse_context_branch_reset_state cur_branch_reset_state {}; -#line 1824 "reflect.h2" +#line 1845 "reflect.h2" public: std::map named_groups {}; private: error_func error_out; // TODO: Declaring std::function fails for cpp2. @@ -819,64 +822,64 @@ class parse_context public: explicit parse_context(cpp2::impl::in r, auto const& e); -#line 1835 "reflect.h2" +#line 1856 "reflect.h2" // State management functions // // Returned group state needs to be stored and provided in `end_group`. public: [[nodiscard]] auto start_group() & -> parse_context_group_state; -#line 1848 "reflect.h2" +#line 1869 "reflect.h2" // `old_state` argument needs to be from start group. public: [[nodiscard]] auto end_group(cpp2::impl::in old_state) & -> token_ptr; -#line 1856 "reflect.h2" +#line 1877 "reflect.h2" public: [[nodiscard]] auto get_modifiers() const& -> expression_flags; -#line 1860 "reflect.h2" +#line 1881 "reflect.h2" public: auto set_modifiers(cpp2::impl::in mod) & -> void; -#line 1864 "reflect.h2" +#line 1885 "reflect.h2" // Branch reset management functions // public: [[nodiscard]] auto branch_reset_new_state() & -> parse_context_branch_reset_state; -#line 1876 "reflect.h2" +#line 1897 "reflect.h2" public: auto branch_reset_restore_state(cpp2::impl::in old_state) & -> void; -#line 1883 "reflect.h2" +#line 1904 "reflect.h2" public: auto next_alternative() & -> void; -#line 1889 "reflect.h2" +#line 1910 "reflect.h2" // Regex token management // public: auto add_token(cpp2::impl::in token) & -> void; -#line 1895 "reflect.h2" +#line 1916 "reflect.h2" public: [[nodiscard]] auto has_token() const& -> bool; -#line 1899 "reflect.h2" +#line 1920 "reflect.h2" public: [[nodiscard]] auto pop_token() & -> token_ptr; -#line 1910 "reflect.h2" +#line 1931 "reflect.h2" public: [[nodiscard]] auto get_as_token() & -> token_ptr; -#line 1914 "reflect.h2" +#line 1935 "reflect.h2" // Group management // public: [[nodiscard]] auto get_cur_group() const& -> int; -#line 1920 "reflect.h2" +#line 1941 "reflect.h2" public: [[nodiscard]] auto next_group() & -> int; -#line 1924 "reflect.h2" +#line 1945 "reflect.h2" public: auto set_named_group(cpp2::impl::in name, cpp2::impl::in id) & -> void; -#line 1931 "reflect.h2" +#line 1952 "reflect.h2" public: [[nodiscard]] auto get_named_group(cpp2::impl::in name) const& -> int; -#line 1942 "reflect.h2" +#line 1963 "reflect.h2" // Position management functions // public: [[nodiscard]] auto current() const& -> char; @@ -884,51 +887,51 @@ class parse_context // Get the next token in the regex, skipping spaces according to the parameters. See `x` and `xx` modifiers. private: [[nodiscard]] auto get_next_position(cpp2::impl::in in_class, cpp2::impl::in no_skip) const& -> size_t; -#line 1986 "reflect.h2" +#line 2007 "reflect.h2" // Return true if next token is available. private: [[nodiscard]] auto next_impl(cpp2::impl::in in_class, cpp2::impl::in no_skip) & -> bool; -#line 1998 "reflect.h2" +#line 2019 "reflect.h2" public: [[nodiscard]] auto next() & -> auto; public: [[nodiscard]] auto next_in_class() & -> auto; public: [[nodiscard]] auto next_no_skip() & -> auto; public: [[nodiscard]] auto next_n(cpp2::impl::in n) & -> bool; -#line 2011 "reflect.h2" +#line 2032 "reflect.h2" public: [[nodiscard]] auto has_next() const& -> bool; private: [[nodiscard]] auto grab_until_impl(cpp2::impl::in e, cpp2::impl::out r, cpp2::impl::in any) & -> bool; -#line 2034 "reflect.h2" +#line 2055 "reflect.h2" public: [[nodiscard]] auto grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_until_one_of(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_n(cpp2::impl::in n, cpp2::impl::out r) & -> bool; -#line 2051 "reflect.h2" +#line 2072 "reflect.h2" public: [[nodiscard]] auto grab_number() & -> std::string; -#line 2072 "reflect.h2" +#line 2093 "reflect.h2" private: [[nodiscard]] auto peek_impl(cpp2::impl::in in_class) const& -> char; -#line 2082 "reflect.h2" +#line 2103 "reflect.h2" public: [[nodiscard]] auto peek() const& -> auto; public: [[nodiscard]] auto peek_in_class() const& -> auto; -#line 2086 "reflect.h2" +#line 2107 "reflect.h2" // Parsing functions // public: [[nodiscard]] auto parser_group_modifiers(cpp2::impl::in change_str, expression_flags& parser_modifiers) & -> bool; -#line 2142 "reflect.h2" +#line 2163 "reflect.h2" public: [[nodiscard]] auto parse_until(cpp2::impl::in term) & -> bool; -#line 2180 "reflect.h2" +#line 2201 "reflect.h2" public: [[nodiscard]] auto parse(cpp2::impl::in modifiers) & -> bool; -#line 2195 "reflect.h2" +#line 2216 "reflect.h2" // Misc functions public: [[nodiscard]] auto get_pos() const& -> auto; @@ -940,10 +943,10 @@ class parse_context public: auto operator=(parse_context const&) -> void = delete; -#line 2206 "reflect.h2" +#line 2227 "reflect.h2" }; -#line 2209 "reflect.h2" +#line 2230 "reflect.h2" // Context for one function generation. Generation of functions can be interleaved, // therefore we buffer the code for one function here. // @@ -953,16 +956,16 @@ class generation_function_context { public: auto add_tabs(cpp2::impl::in c) & -> void; -#line 2223 "reflect.h2" +#line 2244 "reflect.h2" public: auto remove_tabs(cpp2::impl::in c) & -> void; public: generation_function_context(auto const& code_, auto const& tabs_); public: generation_function_context(); -#line 2226 "reflect.h2" +#line 2247 "reflect.h2" }; -#line 2229 "reflect.h2" +#line 2250 "reflect.h2" // Context for generating the state machine. class generation_context { @@ -982,68 +985,68 @@ class generation_context // Add code line. public: auto add(cpp2::impl::in s) & -> void; -#line 2251 "reflect.h2" +#line 2272 "reflect.h2" // Add check for token. The check needs to be a function call that returns a boolean. public: auto add_check(cpp2::impl::in check) & -> void; -#line 2257 "reflect.h2" +#line 2278 "reflect.h2" // Add a stateful check. The check needs to return a `match_return`. public: auto add_statefull(cpp2::impl::in next_func, cpp2::impl::in check) & -> void; -#line 2266 "reflect.h2" +#line 2287 "reflect.h2" protected: auto start_func_named(cpp2::impl::in name) & -> void; -#line 2277 "reflect.h2" +#line 2298 "reflect.h2" protected: [[nodiscard]] auto start_func() & -> std::string; -#line 2284 "reflect.h2" +#line 2305 "reflect.h2" protected: auto end_func_statefull(cpp2::impl::in s) & -> void; -#line 2303 "reflect.h2" +#line 2324 "reflect.h2" // Generate the function for a token. public: [[nodiscard]] auto generate_func(cpp2::impl::in token) & -> std::string; -#line 2313 "reflect.h2" +#line 2334 "reflect.h2" // Generate the reset for a list of group identifiers. public: [[nodiscard]] auto generate_reset(cpp2::impl::in> groups) & -> std::string; -#line 2336 "reflect.h2" +#line 2357 "reflect.h2" // Name generation // protected: [[nodiscard]] auto gen_func_name() & -> std::string; -#line 2344 "reflect.h2" +#line 2365 "reflect.h2" public: [[nodiscard]] auto next_func_name() & -> std::string; -#line 2348 "reflect.h2" +#line 2369 "reflect.h2" protected: [[nodiscard]] auto gen_reset_func_name() & -> std::string; -#line 2354 "reflect.h2" +#line 2375 "reflect.h2" public: [[nodiscard]] auto gen_temp() & -> std::string; -#line 2360 "reflect.h2" +#line 2381 "reflect.h2" // Context management // public: [[nodiscard]] auto new_context() & -> generation_function_context*; -#line 2370 "reflect.h2" +#line 2391 "reflect.h2" public: auto finish_context() & -> void; -#line 2378 "reflect.h2" +#line 2399 "reflect.h2" // Misc functions // private: [[nodiscard]] auto get_current() & -> generation_function_context*; -#line 2384 "reflect.h2" +#line 2405 "reflect.h2" private: [[nodiscard]] auto get_base() & -> generation_function_context*; -#line 2388 "reflect.h2" +#line 2409 "reflect.h2" public: [[nodiscard]] auto get_entry_func() const& -> std::string; -#line 2392 "reflect.h2" +#line 2413 "reflect.h2" public: [[nodiscard]] auto create_named_group_lookup(cpp2::impl::in> named_groups) const& -> std::string; -#line 2416 "reflect.h2" +#line 2437 "reflect.h2" // Run the generation for the token. public: [[nodiscard]] auto run(cpp2::impl::in token) & -> std::string; public: generation_context() = default; @@ -1051,7 +1054,7 @@ class generation_context public: auto operator=(generation_context const&) -> void = delete; -#line 2422 "reflect.h2" +#line 2443 "reflect.h2" }; // Regex syntax: | Example: ab|ba @@ -1071,24 +1074,24 @@ class alternative_token public: auto operator=(alternative_token const&) -> void = delete; -#line 2441 "reflect.h2" +#line 2462 "reflect.h2" }; class alternative_token_gen : public regex_token { -#line 2447 "reflect.h2" +#line 2468 "reflect.h2" private: token_vec alternatives; public: explicit alternative_token_gen(cpp2::impl::in a); -#line 2454 "reflect.h2" +#line 2475 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2471 "reflect.h2" +#line 2492 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; -#line 2478 "reflect.h2" +#line 2499 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in a) -> std::string; public: virtual ~alternative_token_gen() noexcept; @@ -1096,19 +1099,19 @@ class alternative_token_gen public: auto operator=(alternative_token_gen const&) -> void = delete; -#line 2490 "reflect.h2" +#line 2511 "reflect.h2" }; -#line 2493 "reflect.h2" +#line 2514 "reflect.h2" // Regex syntax: . // class any_token : public regex_token_check { -#line 2499 "reflect.h2" +#line 2520 "reflect.h2" public: explicit any_token(cpp2::impl::in single_line); -#line 2503 "reflect.h2" +#line 2524 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; public: virtual ~any_token() noexcept; @@ -1116,37 +1119,37 @@ class any_token public: auto operator=(any_token const&) -> void = delete; -#line 2508 "reflect.h2" +#line 2529 "reflect.h2" }; -#line 2511 "reflect.h2" +#line 2532 "reflect.h2" // Regex syntax: a // class char_token : public regex_token { -#line 2517 "reflect.h2" +#line 2538 "reflect.h2" private: std::string token; private: bool ignore_case; public: explicit char_token(cpp2::impl::in t, cpp2::impl::in ignore_case_); -#line 2526 "reflect.h2" +#line 2547 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 2530 "reflect.h2" +#line 2551 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2553 "reflect.h2" +#line 2574 "reflect.h2" public: auto gen_case_insensitive(cpp2::impl::in lower, cpp2::impl::in upper, generation_context& ctx) const& -> void; -#line 2574 "reflect.h2" +#line 2595 "reflect.h2" public: auto gen_case_sensitive(generation_context& ctx) const& -> void; -#line 2592 "reflect.h2" +#line 2613 "reflect.h2" public: [[nodiscard]] auto add_escapes(std::string str) const& -> std::string; -#line 2607 "reflect.h2" +#line 2628 "reflect.h2" public: auto append(char_token const& that) & -> void; public: virtual ~char_token() noexcept; @@ -1154,30 +1157,30 @@ class char_token public: auto operator=(char_token const&) -> void = delete; -#line 2611 "reflect.h2" +#line 2632 "reflect.h2" }; -#line 2614 "reflect.h2" +#line 2635 "reflect.h2" // Regex syntax: [] Example: [abcx-y[:digits:]] // class class_token : public regex_token { -#line 2620 "reflect.h2" +#line 2641 "reflect.h2" private: bool negate; private: bool case_insensitive; private: std::string class_str; public: explicit class_token(cpp2::impl::in negate_, cpp2::impl::in case_insensitive_, cpp2::impl::in class_str_, cpp2::impl::in str); -#line 2632 "reflect.h2" +#line 2653 "reflect.h2" // TODO: Rework class generation: Generate check functions for classes. public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 2758 "reflect.h2" +#line 2779 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2763 "reflect.h2" +#line 2784 "reflect.h2" private: [[nodiscard]] static auto create_matcher(cpp2::impl::in name, cpp2::impl::in template_arguments) -> std::string; public: virtual ~class_token() noexcept; @@ -1185,20 +1188,20 @@ class class_token public: auto operator=(class_token const&) -> void = delete; -#line 2770 "reflect.h2" +#line 2791 "reflect.h2" }; -#line 2773 "reflect.h2" +#line 2794 "reflect.h2" // Regex syntax: \a or \n or \[ // [[nodiscard]] auto escape_token_parse(parse_context& ctx) -> token_ptr; -#line 2814 "reflect.h2" +#line 2835 "reflect.h2" // Regex syntax: \K Example: ab\Kcd // [[nodiscard]] auto global_group_reset_token_parse(parse_context& ctx) -> token_ptr; -#line 2825 "reflect.h2" +#line 2846 "reflect.h2" // Regex syntax: \ Example: \1 // \g{name_or_number} // \k{name_or_number} @@ -1208,16 +1211,16 @@ class class_token class group_ref_token : public regex_token { -#line 2835 "reflect.h2" +#line 2856 "reflect.h2" private: int id; private: bool case_insensitive; public: explicit group_ref_token(cpp2::impl::in id_, cpp2::impl::in case_insensitive_, cpp2::impl::in str); -#line 2845 "reflect.h2" +#line 2866 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 2946 "reflect.h2" +#line 2967 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~group_ref_token() noexcept; @@ -1225,10 +1228,10 @@ class group_ref_token public: auto operator=(group_ref_token const&) -> void = delete; -#line 2949 "reflect.h2" +#line 2970 "reflect.h2" }; -#line 2952 "reflect.h2" +#line 2973 "reflect.h2" // Regex syntax: () Example: (abc) // (?:) (?i:abc) @@ -1242,22 +1245,22 @@ class group_ref_token class group_token : public regex_token { -#line 2966 "reflect.h2" +#line 2987 "reflect.h2" private: int number {-1}; private: token_ptr inner {nullptr}; public: [[nodiscard]] static auto parse_lookahead(parse_context& ctx, cpp2::impl::in syntax, cpp2::impl::in positive) -> token_ptr; -#line 2983 "reflect.h2" +#line 3004 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 3120 "reflect.h2" +#line 3141 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in name, cpp2::impl::in name_brackets, cpp2::impl::in has_modifier, cpp2::impl::in modifiers, cpp2::impl::in inner_) -> std::string; -#line 3138 "reflect.h2" +#line 3159 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3158 "reflect.h2" +#line 3179 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~group_token() noexcept; @@ -1266,25 +1269,25 @@ class group_token public: auto operator=(group_token const&) -> void = delete; -#line 3165 "reflect.h2" +#line 3186 "reflect.h2" }; -#line 3168 "reflect.h2" +#line 3189 "reflect.h2" // Regex syntax: \x or \x{} Example: \x{62} // [[nodiscard]] auto hexadecimal_token_parse(parse_context& ctx) -> token_ptr; -#line 3209 "reflect.h2" +#line 3230 "reflect.h2" // Regex syntax: $ Example: aa$ // [[nodiscard]] auto line_end_token_parse(parse_context& ctx) -> token_ptr; -#line 3229 "reflect.h2" +#line 3250 "reflect.h2" // Regex syntax: ^ Example: ^aa // [[nodiscard]] auto line_start_token_parse(parse_context& ctx) -> token_ptr; -#line 3245 "reflect.h2" +#line 3266 "reflect.h2" // Regex syntax: (?=) or (?!) or (*pla), etc. Example: (?=AA) // // Parsed in group_token. @@ -1292,16 +1295,16 @@ class group_token class lookahead_token : public regex_token { -#line 3253 "reflect.h2" +#line 3274 "reflect.h2" protected: bool positive; public: token_ptr inner {nullptr}; public: explicit lookahead_token(cpp2::impl::in positive_); -#line 3260 "reflect.h2" +#line 3281 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3266 "reflect.h2" +#line 3287 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~lookahead_token() noexcept; @@ -1309,26 +1312,26 @@ class lookahead_token public: auto operator=(lookahead_token const&) -> void = delete; -#line 3269 "reflect.h2" +#line 3290 "reflect.h2" }; -#line 3272 "reflect.h2" +#line 3293 "reflect.h2" // Named character classes // [[nodiscard]] auto named_class_token_parse(parse_context& ctx) -> token_ptr; -#line 3300 "reflect.h2" +#line 3321 "reflect.h2" // Regex syntax: \o{} Example: \o{142} // [[nodiscard]] auto octal_token_parse(parse_context& ctx) -> token_ptr; -#line 3328 "reflect.h2" +#line 3349 "reflect.h2" // Regex syntax: {min, max} Example: a{2,4} // class range_token : public regex_token { -#line 3334 "reflect.h2" +#line 3355 "reflect.h2" protected: int min_count {-1}; protected: int max_count {-1}; protected: int kind {range_flags::greedy}; @@ -1338,19 +1341,19 @@ class range_token public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 3414 "reflect.h2" +#line 3435 "reflect.h2" public: auto parse_modifier(parse_context& ctx) & -> void; -#line 3426 "reflect.h2" +#line 3447 "reflect.h2" public: [[nodiscard]] auto gen_mod_string() const& -> std::string; -#line 3439 "reflect.h2" +#line 3460 "reflect.h2" public: [[nodiscard]] auto gen_range_string() const& -> std::string; -#line 3458 "reflect.h2" +#line 3479 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3469 "reflect.h2" +#line 3490 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~range_token() noexcept; @@ -1358,16 +1361,16 @@ class range_token public: auto operator=(range_token const&) -> void = delete; -#line 3473 "reflect.h2" +#line 3494 "reflect.h2" }; -#line 3476 "reflect.h2" +#line 3497 "reflect.h2" // Regex syntax: *, +, or ? Example: aa* // class special_range_token : public range_token { -#line 3482 "reflect.h2" +#line 3503 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; public: virtual ~special_range_token() noexcept; @@ -1376,17 +1379,17 @@ class special_range_token public: auto operator=(special_range_token const&) -> void = delete; -#line 3512 "reflect.h2" +#line 3533 "reflect.h2" }; -#line 3515 "reflect.h2" +#line 3536 "reflect.h2" // Regex syntax: \b or \B Example: \bword\b // // Matches the start end end of word boundaries. // [[nodiscard]] auto word_boundary_token_parse(parse_context& ctx) -> token_ptr; -#line 3537 "reflect.h2" +#line 3558 "reflect.h2" //----------------------------------------------------------------------- // // Parser for regular expression. @@ -1407,24 +1410,24 @@ template class regex_generator public: explicit regex_generator(cpp2::impl::in r, Error_out const& e); -#line 3560 "reflect.h2" +#line 3581 "reflect.h2" public: [[nodiscard]] auto parse() & -> std::string; -#line 3595 "reflect.h2" +#line 3616 "reflect.h2" private: auto extract_modifiers() & -> void; public: regex_generator(regex_generator const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(regex_generator const&) -> void = delete; -#line 3609 "reflect.h2" +#line 3630 "reflect.h2" }; template [[nodiscard]] auto generate_regex(cpp2::impl::in regex, Err const& err) -> std::string; -#line 3621 "reflect.h2" +#line 3642 "reflect.h2" auto regex_gen(meta::type_declaration& t) -> void; -#line 3676 "reflect.h2" +#line 3697 "reflect.h2" //----------------------------------------------------------------------- // // apply_metafunctions - for types @@ -1435,7 +1438,7 @@ auto regex_gen(meta::type_declaration& t) -> void; auto const& error ) -> bool; -#line 3795 "reflect.h2" +#line 3816 "reflect.h2" //----------------------------------------------------------------------- // // apply_metafunctions - for functions @@ -1446,7 +1449,7 @@ auto regex_gen(meta::type_declaration& t) -> void; auto const& error ) -> bool; -#line 3849 "reflect.h2" +#line 3873 "reflect.h2" } } @@ -3196,6 +3199,27 @@ auto print(cpp2::impl::in f) -> void std::cout << CPP2_UFCS(print)(f) << "\n"; } +#line 1558 "reflect.h2" +//----------------------------------------------------------------------- +// +// meta - mark f as a metafunction and generate registration code for it +// +#line 1562 "reflect.h2" +auto meta(meta::function_declaration& f) -> void +{ + // TODO(DyXel): Check that the function: + // * has ::cpp2::meta::function_declaration as only parameter, OR, + // * has ::cpp2::meta::type_declaration as only paramater, OR, + // * function_declaration or type_declaration (implicitly deduced to be the above), AND, + // * either in or inout paramater passing style, AND, + // * to be publicly accessible, AND, + // * to not be on header file, AND, + // * to have void return type. + auto fqn {CPP2_UFCS(fully_qualified_name)(f)}; + CPP2_UFCS(append_declaration_to_translation_unit)(f, "_: namespace = { _: ::cpp2::meta::register_metafunction = (\"" + cpp2::to_string(fqn) + "\"," + cpp2::to_string(fqn) + "&); }"); + CPP2_UFCS(add_runtime_support_include)(f, "cpp2reflect_api.h"); +} + constexpr expression_flags::expression_flags(cpp2::impl::in _val) : _value{ cpp2::unsafe_narrow(_val) } { } @@ -3287,7 +3311,7 @@ return none; [[nodiscard]] auto expression_flags::from_code(cpp2::impl::in s) -> expression_flags{ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::move(str), "expression_flags::", "")); } -#line 1557 "reflect.h2" +#line 1578 "reflect.h2" //----------------------------------------------------------------------- // // regex - creates regular expressions from members @@ -3303,11 +3327,11 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov // ``` // -#line 1573 "reflect.h2" +#line 1594 "reflect.h2" // Possible modifiers for a regular expression. // -#line 1577 "reflect.h2" +#line 1598 "reflect.h2" // mod: i // mod: m // mod: s @@ -3315,106 +3339,106 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov // mod: x // mod: xx -#line 1586 "reflect.h2" +#line 1607 "reflect.h2" // Tokens for regular expressions. // // Basic class for a regex token. // -#line 1595 "reflect.h2" +#line 1616 "reflect.h2" regex_token::regex_token(cpp2::impl::in str) : string_rep{ str }{ -#line 1597 "reflect.h2" +#line 1618 "reflect.h2" } -#line 1599 "reflect.h2" +#line 1620 "reflect.h2" regex_token::regex_token() : string_rep{ "" }{ -#line 1601 "reflect.h2" +#line 1622 "reflect.h2" } //parse: (inout ctx: parse_context) -> token_ptr; // Generate the matching code. -#line 1606 "reflect.h2" +#line 1627 "reflect.h2" auto regex_token::add_groups([[maybe_unused]] std::set& unnamed_param_2) const -> void{}// Adds all group indices to the set. -#line 1607 "reflect.h2" +#line 1628 "reflect.h2" [[nodiscard]] auto regex_token::to_string() const& -> std::string{return string_rep; }// Create a string representation. -#line 1608 "reflect.h2" +#line 1629 "reflect.h2" auto regex_token::set_string(cpp2::impl::in s) & -> void{string_rep = s; } regex_token::~regex_token() noexcept{}// Set the string representation. -#line 1623 "reflect.h2" +#line 1644 "reflect.h2" regex_token_check::regex_token_check(cpp2::impl::in str, cpp2::impl::in check_) : regex_token{ str } , check{ check_ }{ -#line 1626 "reflect.h2" +#line 1647 "reflect.h2" } -#line 1628 "reflect.h2" +#line 1649 "reflect.h2" auto regex_token_check::generate_code(generation_context& ctx) const -> void{ ctx.add_check(check + "(" + ctx.match_parameters() + ")"); } regex_token_check::~regex_token_check() noexcept{} -#line 1642 "reflect.h2" +#line 1663 "reflect.h2" regex_token_code::regex_token_code(cpp2::impl::in str, cpp2::impl::in code_) : regex_token{ str } , code{ code_ }{ -#line 1645 "reflect.h2" +#line 1666 "reflect.h2" } -#line 1647 "reflect.h2" +#line 1668 "reflect.h2" auto regex_token_code::generate_code(generation_context& ctx) const -> void{ ctx.add(code); } regex_token_code::~regex_token_code() noexcept{} -#line 1659 "reflect.h2" +#line 1680 "reflect.h2" regex_token_empty::regex_token_empty(cpp2::impl::in str) : regex_token{ str }{ -#line 1661 "reflect.h2" +#line 1682 "reflect.h2" } -#line 1663 "reflect.h2" +#line 1684 "reflect.h2" auto regex_token_empty::generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void{ // Nothing. } regex_token_empty::~regex_token_empty() noexcept{} -#line 1677 "reflect.h2" +#line 1698 "reflect.h2" regex_token_list::regex_token_list(cpp2::impl::in t) : regex_token{ gen_string(t) } , tokens{ t }{ -#line 1680 "reflect.h2" +#line 1701 "reflect.h2" } -#line 1682 "reflect.h2" +#line 1703 "reflect.h2" auto regex_token_list::generate_code(generation_context& ctx) const -> void{ for ( auto const& token : tokens ) { (*cpp2::impl::assert_not_null(token)).generate_code(ctx); } } -#line 1688 "reflect.h2" +#line 1709 "reflect.h2" auto regex_token_list::add_groups(std::set& groups) const -> void{ for ( auto const& token : tokens ) { (*cpp2::impl::assert_not_null(token)).add_groups(groups); } } -#line 1694 "reflect.h2" +#line 1715 "reflect.h2" [[nodiscard]] auto regex_token_list::gen_string(cpp2::impl::in vec) -> std::string{ std::string r {""}; for ( auto const& token : vec ) { @@ -3425,7 +3449,7 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov regex_token_list::~regex_token_list() noexcept{} -#line 1717 "reflect.h2" +#line 1738 "reflect.h2" auto parse_context_group_state::next_alternative() & -> void{ token_vec new_list {}; std::swap(new_list, cur_match_list); @@ -3433,14 +3457,14 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov static_cast(alternate_match_lists.insert(alternate_match_lists.end(), CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, cpp2::move(new_list)))); } -#line 1725 "reflect.h2" +#line 1746 "reflect.h2" auto parse_context_group_state::swap(parse_context_group_state& t) & -> void{ std::swap(cur_match_list, t.cur_match_list); std::swap(alternate_match_lists, t.alternate_match_lists); std::swap(modifiers, t.modifiers); } -#line 1732 "reflect.h2" +#line 1753 "reflect.h2" [[nodiscard]] auto parse_context_group_state::get_as_token() & -> token_ptr{ if (alternate_match_lists.empty()) { post_process_list(cur_match_list); @@ -3452,15 +3476,15 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov } } -#line 1744 "reflect.h2" +#line 1765 "reflect.h2" auto parse_context_group_state::add(cpp2::impl::in token) & -> void{ cur_match_list.push_back(token); } -#line 1749 "reflect.h2" +#line 1770 "reflect.h2" [[nodiscard]] auto parse_context_group_state::empty() const& -> bool { return cur_match_list.empty(); } -#line 1753 "reflect.h2" +#line 1774 "reflect.h2" auto parse_context_group_state::post_process_list(token_vec& list) -> void{ // Merge all characters auto merge_pos {list.begin()}; @@ -3481,7 +3505,7 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov , modifiers{ modifiers_ }{} parse_context_group_state::parse_context_group_state(){} -#line 1779 "reflect.h2" +#line 1800 "reflect.h2" [[nodiscard]] auto parse_context_branch_reset_state::next() & -> int{ auto g {cur_group}; cur_group += 1; @@ -3490,20 +3514,20 @@ parse_context_group_state::parse_context_group_state(){} return g; } -#line 1788 "reflect.h2" +#line 1809 "reflect.h2" auto parse_context_branch_reset_state::set_next(cpp2::impl::in g) & -> void{ cur_group = g; max_group = max(max_group, g); } -#line 1794 "reflect.h2" +#line 1815 "reflect.h2" auto parse_context_branch_reset_state::next_alternative() & -> void{ if (is_active) { cur_group = from; } } -#line 1801 "reflect.h2" +#line 1822 "reflect.h2" auto parse_context_branch_reset_state::set_active_reset(cpp2::impl::in restart) & -> void{ is_active = true; cur_group = restart; @@ -3518,16 +3542,16 @@ parse_context_group_state::parse_context_group_state(){} , from{ from_ }{} parse_context_branch_reset_state::parse_context_branch_reset_state(){} -#line 1829 "reflect.h2" +#line 1850 "reflect.h2" parse_context::parse_context(cpp2::impl::in r, auto const& e) : regex{ r } , root{ CPP2_UFCS_TEMPLATE_NONLOCAL(cpp2_new)(cpp2::shared, "") } , error_out{ e }{ -#line 1833 "reflect.h2" +#line 1854 "reflect.h2" } -#line 1839 "reflect.h2" +#line 1860 "reflect.h2" [[nodiscard]] auto parse_context::start_group() & -> parse_context_group_state { parse_context_group_state old_state {}; @@ -3537,7 +3561,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return old_state; } -#line 1849 "reflect.h2" +#line 1870 "reflect.h2" [[nodiscard]] auto parse_context::end_group(cpp2::impl::in old_state) & -> token_ptr { auto inner {cur_group_state.get_as_token()}; @@ -3545,17 +3569,17 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return inner; } -#line 1856 "reflect.h2" +#line 1877 "reflect.h2" [[nodiscard]] auto parse_context::get_modifiers() const& -> expression_flags{ return cur_group_state.modifiers; } -#line 1860 "reflect.h2" +#line 1881 "reflect.h2" auto parse_context::set_modifiers(cpp2::impl::in mod) & -> void{ cur_group_state.modifiers = mod; } -#line 1867 "reflect.h2" +#line 1888 "reflect.h2" [[nodiscard]] auto parse_context::branch_reset_new_state() & -> parse_context_branch_reset_state { parse_context_branch_reset_state old_state {}; @@ -3565,7 +3589,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return old_state; } -#line 1876 "reflect.h2" +#line 1897 "reflect.h2" auto parse_context::branch_reset_restore_state(cpp2::impl::in old_state) & -> void { auto max_group {cur_branch_reset_state.max_group}; @@ -3573,24 +3597,24 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} cur_branch_reset_state.set_next(cpp2::move(max_group)); } -#line 1883 "reflect.h2" +#line 1904 "reflect.h2" auto parse_context::next_alternative() & -> void { cur_group_state.next_alternative(); cur_branch_reset_state.next_alternative(); } -#line 1891 "reflect.h2" +#line 1912 "reflect.h2" auto parse_context::add_token(cpp2::impl::in token) & -> void{ cur_group_state.add(token); } -#line 1895 "reflect.h2" +#line 1916 "reflect.h2" [[nodiscard]] auto parse_context::has_token() const& -> bool{ return !(cur_group_state.empty()); } -#line 1899 "reflect.h2" +#line 1920 "reflect.h2" [[nodiscard]] auto parse_context::pop_token() & -> token_ptr { token_ptr r {nullptr}; @@ -3602,22 +3626,22 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 1910 "reflect.h2" +#line 1931 "reflect.h2" [[nodiscard]] auto parse_context::get_as_token() & -> token_ptr{ return root; } -#line 1916 "reflect.h2" +#line 1937 "reflect.h2" [[nodiscard]] auto parse_context::get_cur_group() const& -> int{ return cur_branch_reset_state.cur_group; } -#line 1920 "reflect.h2" +#line 1941 "reflect.h2" [[nodiscard]] auto parse_context::next_group() & -> int{ return cur_branch_reset_state.next(); } -#line 1924 "reflect.h2" +#line 1945 "reflect.h2" auto parse_context::set_named_group(cpp2::impl::in name, cpp2::impl::in id) & -> void { if (!(named_groups.contains(name))) {// Redefinition of group name is not an error. The left most one is retained. @@ -3625,7 +3649,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 1931 "reflect.h2" +#line 1952 "reflect.h2" [[nodiscard]] auto parse_context::get_named_group(cpp2::impl::in name) const& -> int { auto iter {named_groups.find(name)}; @@ -3637,10 +3661,10 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 1944 "reflect.h2" +#line 1965 "reflect.h2" [[nodiscard]] auto parse_context::current() const& -> char{return CPP2_ASSERT_IN_BOUNDS(regex, pos); } -#line 1947 "reflect.h2" +#line 1968 "reflect.h2" [[nodiscard]] auto parse_context::get_next_position(cpp2::impl::in in_class, cpp2::impl::in no_skip) const& -> size_t { auto perl_syntax {false}; @@ -3680,7 +3704,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return cur; } -#line 1987 "reflect.h2" +#line 2008 "reflect.h2" [[nodiscard]] auto parse_context::next_impl(cpp2::impl::in in_class, cpp2::impl::in no_skip) & -> bool { pos = get_next_position(in_class, no_skip); @@ -3692,14 +3716,14 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 1998 "reflect.h2" +#line 2019 "reflect.h2" [[nodiscard]] auto parse_context::next() & -> auto { return next_impl(false, false); } -#line 1999 "reflect.h2" +#line 2020 "reflect.h2" [[nodiscard]] auto parse_context::next_in_class() & -> auto { return next_impl(true, false); } -#line 2000 "reflect.h2" +#line 2021 "reflect.h2" [[nodiscard]] auto parse_context::next_no_skip() & -> auto { return next_impl(false, true); } -#line 2002 "reflect.h2" +#line 2023 "reflect.h2" [[nodiscard]] auto parse_context::next_n(cpp2::impl::in n) & -> bool{ auto r {true}; auto cur {0}; @@ -3709,10 +3733,10 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 2011 "reflect.h2" +#line 2032 "reflect.h2" [[nodiscard]] auto parse_context::has_next() const& -> bool{return cpp2::impl::cmp_less(pos,regex.size()); } -#line 2013 "reflect.h2" +#line 2034 "reflect.h2" [[nodiscard]] auto parse_context::grab_until_impl(cpp2::impl::in e, cpp2::impl::out r, cpp2::impl::in any) & -> bool { auto end {pos}; @@ -3734,14 +3758,14 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2034 "reflect.h2" +#line 2055 "reflect.h2" [[nodiscard]] auto parse_context::grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(e, cpp2::impl::out(&r), false); } -#line 2035 "reflect.h2" +#line 2056 "reflect.h2" [[nodiscard]] auto parse_context::grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(std::string(1, e), cpp2::impl::out(&r), false); } -#line 2036 "reflect.h2" +#line 2057 "reflect.h2" [[nodiscard]] auto parse_context::grab_until_one_of(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(e, cpp2::impl::out(&r), true); } -#line 2038 "reflect.h2" +#line 2059 "reflect.h2" [[nodiscard]] auto parse_context::grab_n(cpp2::impl::in n, cpp2::impl::out r) & -> bool { if (cpp2::impl::cmp_less_eq(pos + cpp2::impl::as_(n),regex.size())) { @@ -3755,7 +3779,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2051 "reflect.h2" +#line 2072 "reflect.h2" [[nodiscard]] auto parse_context::grab_number() & -> std::string { auto start {pos}; @@ -3777,7 +3801,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return cpp2::move(r.value()); } -#line 2072 "reflect.h2" +#line 2093 "reflect.h2" [[nodiscard]] auto parse_context::peek_impl(cpp2::impl::in in_class) const& -> char{ auto next_pos {get_next_position(in_class, false)}; if (cpp2::impl::cmp_less(next_pos,regex.size())) { @@ -3788,12 +3812,12 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2082 "reflect.h2" +#line 2103 "reflect.h2" [[nodiscard]] auto parse_context::peek() const& -> auto { return peek_impl(false); } -#line 2083 "reflect.h2" +#line 2104 "reflect.h2" [[nodiscard]] auto parse_context::peek_in_class() const& -> auto { return peek_impl(true); } -#line 2088 "reflect.h2" +#line 2109 "reflect.h2" [[nodiscard]] auto parse_context::parser_group_modifiers(cpp2::impl::in change_str, expression_flags& parser_modifiers) & -> bool { auto is_negative {false}; @@ -3848,7 +3872,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return true; } -#line 2142 "reflect.h2" +#line 2163 "reflect.h2" [[nodiscard]] auto parse_context::parse_until(cpp2::impl::in term) & -> bool{ token_ptr cur_token {}; @@ -3887,7 +3911,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return true; } -#line 2180 "reflect.h2" +#line 2201 "reflect.h2" [[nodiscard]] auto parse_context::parse(cpp2::impl::in modifiers) & -> bool { @@ -3903,21 +3927,21 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 2197 "reflect.h2" +#line 2218 "reflect.h2" [[nodiscard]] auto parse_context::get_pos() const& -> auto { return pos; } -#line 2198 "reflect.h2" +#line 2219 "reflect.h2" [[nodiscard]] auto parse_context::get_range(cpp2::impl::in start, cpp2::impl::in end) const& -> auto { return std::string(regex.substr(start, end - start + 1)); } -#line 2199 "reflect.h2" +#line 2220 "reflect.h2" [[nodiscard]] auto parse_context::valid() const& -> bool{return has_next() && !(has_error); } -#line 2201 "reflect.h2" +#line 2222 "reflect.h2" [[nodiscard]] auto parse_context::error(cpp2::impl::in err) & -> token_ptr{ has_error = true; error_out("Error during parsing of regex '" + cpp2::to_string(regex) + "' at position '" + cpp2::to_string(pos) + "': " + cpp2::to_string(err) + ""); return nullptr; } -#line 2216 "reflect.h2" +#line 2237 "reflect.h2" auto generation_function_context::add_tabs(cpp2::impl::in c) & -> void{ int i {0}; for( ; cpp2::impl::cmp_less(i,c); i += 1 ) { @@ -3925,7 +3949,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2223 "reflect.h2" +#line 2244 "reflect.h2" auto generation_function_context::remove_tabs(cpp2::impl::in c) & -> void{ tabs = tabs.substr(0, (cpp2::impl::as_(c)) * 2); } @@ -3935,22 +3959,22 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} , tabs{ tabs_ }{} generation_function_context::generation_function_context(){} -#line 2241 "reflect.h2" +#line 2262 "reflect.h2" [[nodiscard]] auto generation_context::match_parameters() const& -> std::string{return "r.pos, ctx"; } -#line 2246 "reflect.h2" +#line 2267 "reflect.h2" auto generation_context::add(cpp2::impl::in s) & -> void{ auto cur {get_current()}; (*cpp2::impl::assert_not_null(cur)).code += "" + cpp2::to_string((*cpp2::impl::assert_not_null(cur)).tabs) + cpp2::to_string(s) + "\n"; } -#line 2252 "reflect.h2" +#line 2273 "reflect.h2" auto generation_context::add_check(cpp2::impl::in check) & -> void{ auto cur {get_current()}; (*cpp2::impl::assert_not_null(cur)).code += "" + cpp2::to_string((*cpp2::impl::assert_not_null(cur)).tabs) + "if !cpp2::regex::" + cpp2::to_string(check) + " { r.matched = false; break; }\n"; } -#line 2258 "reflect.h2" +#line 2279 "reflect.h2" auto generation_context::add_statefull(cpp2::impl::in next_func, cpp2::impl::in check) & -> void { end_func_statefull(check); @@ -3959,7 +3983,7 @@ generation_function_context::generation_function_context(){} start_func_named(cpp2::move(name)); } -#line 2266 "reflect.h2" +#line 2287 "reflect.h2" auto generation_context::start_func_named(cpp2::impl::in name) & -> void { auto cur {new_context()}; @@ -3971,7 +3995,7 @@ generation_function_context::generation_function_context(){} (*cpp2::impl::assert_not_null(cpp2::move(cur))).add_tabs(3); } -#line 2277 "reflect.h2" +#line 2298 "reflect.h2" [[nodiscard]] auto generation_context::start_func() & -> std::string { auto name {gen_func_name()}; @@ -3979,7 +4003,7 @@ generation_function_context::generation_function_context(){} return cpp2::move(name) + "()"; } -#line 2284 "reflect.h2" +#line 2305 "reflect.h2" auto generation_context::end_func_statefull(cpp2::impl::in s) & -> void { auto cur {get_current()}; @@ -3999,7 +4023,7 @@ generation_function_context::generation_function_context(){} finish_context(); } -#line 2304 "reflect.h2" +#line 2325 "reflect.h2" [[nodiscard]] auto generation_context::generate_func(cpp2::impl::in token) & -> std::string { auto name {start_func()}; @@ -4009,7 +4033,7 @@ generation_function_context::generation_function_context(){} return name; } -#line 2314 "reflect.h2" +#line 2335 "reflect.h2" [[nodiscard]] auto generation_context::generate_reset(cpp2::impl::in> groups) & -> std::string { if (groups.empty()) { @@ -4032,33 +4056,33 @@ generation_function_context::generation_function_context(){} return cpp2::move(name) + "()"; } -#line 2338 "reflect.h2" +#line 2359 "reflect.h2" [[nodiscard]] auto generation_context::gen_func_name() & -> std::string{ auto cur_id {matcher_func}; matcher_func += 1; return "func_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2344 "reflect.h2" +#line 2365 "reflect.h2" [[nodiscard]] auto generation_context::next_func_name() & -> std::string{ return gen_func_name() + "()"; } -#line 2348 "reflect.h2" +#line 2369 "reflect.h2" [[nodiscard]] auto generation_context::gen_reset_func_name() & -> std::string{ auto cur_id {reset_func}; reset_func += 1; return "reset_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2354 "reflect.h2" +#line 2375 "reflect.h2" [[nodiscard]] auto generation_context::gen_temp() & -> std::string{ auto cur_id {temp_name}; temp_name += 1; return "tmp_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2362 "reflect.h2" +#line 2383 "reflect.h2" [[nodiscard]] auto generation_context::new_context() & -> generation_function_context*{ gen_stack.push_back(generation_function_context()); auto cur {get_current()}; @@ -4067,7 +4091,7 @@ generation_function_context::generation_function_context(){} return cur; } -#line 2370 "reflect.h2" +#line 2391 "reflect.h2" auto generation_context::finish_context() & -> void{ auto cur {get_current()}; auto base {get_base()}; @@ -4076,22 +4100,22 @@ generation_function_context::generation_function_context(){} gen_stack.pop_back(); } -#line 2380 "reflect.h2" +#line 2401 "reflect.h2" [[nodiscard]] auto generation_context::get_current() & -> generation_function_context*{ return &gen_stack.back(); } -#line 2384 "reflect.h2" +#line 2405 "reflect.h2" [[nodiscard]] auto generation_context::get_base() & -> generation_function_context*{ return &CPP2_ASSERT_IN_BOUNDS_LITERAL(gen_stack, 0); } -#line 2388 "reflect.h2" +#line 2409 "reflect.h2" [[nodiscard]] auto generation_context::get_entry_func() const& -> std::string{ return entry_func; } -#line 2392 "reflect.h2" +#line 2413 "reflect.h2" [[nodiscard]] auto generation_context::create_named_group_lookup(cpp2::impl::in> named_groups) const& -> std::string { std::string res {"get_named_group_index: (name) -> int = {\n"}; @@ -4115,18 +4139,18 @@ generation_function_context::generation_function_context(){} return res; } -#line 2417 "reflect.h2" +#line 2438 "reflect.h2" [[nodiscard]] auto generation_context::run(cpp2::impl::in token) & -> std::string{ entry_func = generate_func(token); return (*cpp2::impl::assert_not_null(get_base())).code; } -#line 2432 "reflect.h2" +#line 2453 "reflect.h2" alternative_token::alternative_token() : regex_token_empty{ "" }{} -#line 2434 "reflect.h2" +#line 2455 "reflect.h2" [[nodiscard]] auto alternative_token::parse(parse_context& ctx) -> token_ptr{ if (ctx.current() != '|') {return nullptr; } @@ -4137,15 +4161,15 @@ generation_function_context::generation_function_context(){} alternative_token::~alternative_token() noexcept{} -#line 2449 "reflect.h2" +#line 2470 "reflect.h2" alternative_token_gen::alternative_token_gen(cpp2::impl::in a) : regex_token{ gen_string(a) } , alternatives{ a }{ -#line 2452 "reflect.h2" +#line 2473 "reflect.h2" } -#line 2454 "reflect.h2" +#line 2475 "reflect.h2" auto alternative_token_gen::generate_code(generation_context& ctx) const -> void { std::string functions {""}; @@ -4163,7 +4187,7 @@ generation_function_context::generation_function_context(){} ctx.add_statefull(next_name, "cpp2::regex::alternative_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ", other, " + cpp2::to_string(next_name) + " " + cpp2::to_string(cpp2::move(functions)) + ")"); } -#line 2471 "reflect.h2" +#line 2492 "reflect.h2" auto alternative_token_gen::add_groups(std::set& groups) const -> void { for ( auto const& cur : alternatives ) { @@ -4171,7 +4195,7 @@ generation_function_context::generation_function_context(){} } } -#line 2478 "reflect.h2" +#line 2499 "reflect.h2" [[nodiscard]] auto alternative_token_gen::gen_string(cpp2::impl::in a) -> std::string { std::string r {""}; @@ -4187,14 +4211,14 @@ generation_function_context::generation_function_context(){} alternative_token_gen::~alternative_token_gen() noexcept{} -#line 2499 "reflect.h2" +#line 2520 "reflect.h2" any_token::any_token(cpp2::impl::in single_line) : regex_token_check{ ".", "any_token_matcher" }{ -#line 2501 "reflect.h2" +#line 2522 "reflect.h2" } -#line 2503 "reflect.h2" +#line 2524 "reflect.h2" [[nodiscard]] auto any_token::parse(parse_context& ctx) -> token_ptr{ if ('.' != ctx.current()) {return nullptr; } @@ -4203,21 +4227,21 @@ generation_function_context::generation_function_context(){} any_token::~any_token() noexcept{} -#line 2520 "reflect.h2" +#line 2541 "reflect.h2" char_token::char_token(cpp2::impl::in t, cpp2::impl::in ignore_case_) : regex_token{ std::string(1, t) } , token{ t } , ignore_case{ ignore_case_ }{ -#line 2524 "reflect.h2" +#line 2545 "reflect.h2" } -#line 2526 "reflect.h2" +#line 2547 "reflect.h2" [[nodiscard]] auto char_token::parse(parse_context& ctx) -> token_ptr{ return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, ctx.current(), ctx.get_modifiers().has(expression_flags::case_insensitive)); } -#line 2530 "reflect.h2" +#line 2551 "reflect.h2" auto char_token::generate_code(generation_context& ctx) const -> void { if (ignore_case) { @@ -4226,14 +4250,14 @@ generation_function_context::generation_function_context(){} { size_t i{0}; -#line 2536 "reflect.h2" +#line 2557 "reflect.h2" for( ; cpp2::impl::cmp_less(i,token.size()); i += 1 ) { CPP2_ASSERT_IN_BOUNDS(lower, i) = string_util::safe_tolower(CPP2_ASSERT_IN_BOUNDS(token, i)); CPP2_ASSERT_IN_BOUNDS(upper, i) = string_util::safe_toupper(CPP2_ASSERT_IN_BOUNDS(token, i)); } } -#line 2541 "reflect.h2" +#line 2562 "reflect.h2" if (upper != lower) { gen_case_insensitive(cpp2::move(lower), cpp2::move(upper), ctx); } @@ -4246,7 +4270,7 @@ size_t i{0}; } } -#line 2553 "reflect.h2" +#line 2574 "reflect.h2" auto char_token::gen_case_insensitive(cpp2::impl::in lower, cpp2::impl::in upper, generation_context& ctx) const& -> void { std::string name {"str_" + cpp2::to_string(ctx.gen_temp()) + ""}; @@ -4268,7 +4292,7 @@ size_t i{0}; ctx.add("else { break; }"); } -#line 2574 "reflect.h2" +#line 2595 "reflect.h2" auto char_token::gen_case_sensitive(generation_context& ctx) const& -> void { std::string name {"str_" + cpp2::to_string(ctx.gen_temp()) + ""}; @@ -4287,7 +4311,7 @@ size_t i{0}; ctx.add("else { break; }"); } -#line 2592 "reflect.h2" +#line 2613 "reflect.h2" [[nodiscard]] auto char_token::add_escapes(std::string str) const& -> std::string { str = string_util::replace_all(str, "\\", "\\\\"); @@ -4303,7 +4327,7 @@ size_t i{0}; return cpp2::move(str); } -#line 2607 "reflect.h2" +#line 2628 "reflect.h2" auto char_token::append(char_token const& that) & -> void{ (*this).token += that.token; (*this).string_rep += that.string_rep; @@ -4311,19 +4335,19 @@ size_t i{0}; char_token::~char_token() noexcept{} -#line 2624 "reflect.h2" +#line 2645 "reflect.h2" class_token::class_token(cpp2::impl::in negate_, cpp2::impl::in case_insensitive_, cpp2::impl::in class_str_, cpp2::impl::in str) : regex_token{ str } , negate{ negate_ } , case_insensitive{ case_insensitive_ } , class_str{ class_str_ } -#line 2625 "reflect.h2" +#line 2646 "reflect.h2" { -#line 2630 "reflect.h2" +#line 2651 "reflect.h2" } -#line 2633 "reflect.h2" +#line 2654 "reflect.h2" [[nodiscard]] auto class_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '[') {return nullptr; } @@ -4449,13 +4473,13 @@ size_t i{0}; ); } -#line 2758 "reflect.h2" +#line 2779 "reflect.h2" auto class_token::generate_code(generation_context& ctx) const -> void { ctx.add_check("class_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ")"); } -#line 2763 "reflect.h2" +#line 2784 "reflect.h2" [[nodiscard]] auto class_token::create_matcher(cpp2::impl::in name, cpp2::impl::in template_arguments) -> std::string { auto sep {", "}; @@ -4466,12 +4490,12 @@ size_t i{0}; class_token::~class_token() noexcept{} -#line 2775 "reflect.h2" +#line 2796 "reflect.h2" [[nodiscard]] auto escape_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } -#line 2780 "reflect.h2" +#line 2801 "reflect.h2" if (std::string::npos == std::string("afenrt^.[]()*{}?+|\\").find(ctx.peek())) { return nullptr; } @@ -4505,7 +4529,7 @@ size_t i{0}; } -#line 2816 "reflect.h2" +#line 2837 "reflect.h2" [[nodiscard]] auto global_group_reset_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'K'))) {return nullptr; } @@ -4514,18 +4538,18 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, "\\K", "ctx..set_group_start(0, r.pos);"); } -#line 2838 "reflect.h2" +#line 2859 "reflect.h2" group_ref_token::group_ref_token(cpp2::impl::in id_, cpp2::impl::in case_insensitive_, cpp2::impl::in str) : regex_token{ str } , id{ id_ } , case_insensitive{ case_insensitive_ } -#line 2839 "reflect.h2" +#line 2860 "reflect.h2" { -#line 2843 "reflect.h2" +#line 2864 "reflect.h2" } -#line 2845 "reflect.h2" +#line 2866 "reflect.h2" [[nodiscard]] auto group_ref_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -4627,14 +4651,14 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, cpp2::move(group_id), ctx.get_modifiers().has(expression_flags::case_insensitive), cpp2::move(str)); } -#line 2946 "reflect.h2" +#line 2967 "reflect.h2" auto group_ref_token::generate_code(generation_context& ctx) const -> void{ ctx.add_check("group_ref_token_matcher(" + cpp2::to_string(ctx.match_parameters()) + ")"); } group_ref_token::~group_ref_token() noexcept{} -#line 2969 "reflect.h2" +#line 2990 "reflect.h2" [[nodiscard]] auto group_token::parse_lookahead(parse_context& ctx, cpp2::impl::in syntax, cpp2::impl::in positive) -> token_ptr { static_cast(ctx.next());// Skip last token defining the syntax @@ -4649,7 +4673,7 @@ size_t i{0}; return r; } -#line 2983 "reflect.h2" +#line 3004 "reflect.h2" [[nodiscard]] auto group_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '(') {return nullptr; } @@ -4787,7 +4811,7 @@ size_t i{0}; } } -#line 3120 "reflect.h2" +#line 3141 "reflect.h2" [[nodiscard]] auto group_token::gen_string(cpp2::impl::in name, cpp2::impl::in name_brackets, cpp2::impl::in has_modifier, cpp2::impl::in modifiers, cpp2::impl::in inner_) -> std::string { std::string start {"("}; @@ -4806,7 +4830,7 @@ size_t i{0}; return cpp2::move(start) + (*cpp2::impl::assert_not_null(inner_)).to_string() + ")"; } -#line 3138 "reflect.h2" +#line 3159 "reflect.h2" auto group_token::generate_code(generation_context& ctx) const -> void { if (-1 != number) { @@ -4827,7 +4851,7 @@ size_t i{0}; } } -#line 3158 "reflect.h2" +#line 3179 "reflect.h2" auto group_token::add_groups(std::set& groups) const -> void { (*cpp2::impl::assert_not_null(inner)).add_groups(groups); @@ -4838,7 +4862,7 @@ size_t i{0}; group_token::~group_token() noexcept{} -#line 3170 "reflect.h2" +#line 3191 "reflect.h2" [[nodiscard]] auto hexadecimal_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'x'))) {return nullptr; } @@ -4877,7 +4901,7 @@ size_t i{0}; return r; } -#line 3211 "reflect.h2" +#line 3232 "reflect.h2" [[nodiscard]] auto line_end_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() == '$' || (ctx.current() == '\\' && ctx.peek() == '$')) { @@ -4895,7 +4919,7 @@ size_t i{0}; }} } -#line 3231 "reflect.h2" +#line 3252 "reflect.h2" [[nodiscard]] auto line_start_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '^' && !((ctx.current() == '\\' && ctx.peek() == 'A'))) {return nullptr; } @@ -4909,29 +4933,29 @@ size_t i{0}; } } -#line 3256 "reflect.h2" +#line 3277 "reflect.h2" lookahead_token::lookahead_token(cpp2::impl::in positive_) : regex_token{ "" } , positive{ positive_ }{ -#line 3258 "reflect.h2" +#line 3279 "reflect.h2" } -#line 3260 "reflect.h2" +#line 3281 "reflect.h2" auto lookahead_token::generate_code(generation_context& ctx) const -> void{ auto inner_name {ctx.generate_func(inner)}; ctx.add_check("lookahead_token_matcher(" + cpp2::to_string(ctx.match_parameters()) + ", " + cpp2::to_string(cpp2::move(inner_name)) + ")"); } -#line 3266 "reflect.h2" +#line 3287 "reflect.h2" auto lookahead_token::add_groups(std::set& groups) const -> void{ (*cpp2::impl::assert_not_null(inner)).add_groups(groups); } lookahead_token::~lookahead_token() noexcept{} -#line 3274 "reflect.h2" +#line 3295 "reflect.h2" [[nodiscard]] auto named_class_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -4957,7 +4981,7 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, "\\" + cpp2::to_string(ctx.current()) + "", "" + cpp2::to_string(cpp2::move(name)) + "::match"); } -#line 3302 "reflect.h2" +#line 3323 "reflect.h2" [[nodiscard]] auto octal_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'o'))) {return nullptr; } @@ -4983,11 +5007,11 @@ size_t i{0}; return r; } -#line 3339 "reflect.h2" +#line 3360 "reflect.h2" range_token::range_token() : regex_token{ "" }{} -#line 3341 "reflect.h2" +#line 3362 "reflect.h2" [[nodiscard]] auto range_token::parse(parse_context& ctx) -> token_ptr { auto r {CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared)}; @@ -5061,7 +5085,7 @@ size_t i{0}; return nullptr; } -#line 3414 "reflect.h2" +#line 3435 "reflect.h2" auto range_token::parse_modifier(parse_context& ctx) & -> void { if (ctx.peek() == '?') { @@ -5074,7 +5098,7 @@ size_t i{0}; }} } -#line 3426 "reflect.h2" +#line 3447 "reflect.h2" [[nodiscard]] auto range_token::gen_mod_string() const& -> std::string { if (kind == range_flags::not_greedy) { @@ -5088,7 +5112,7 @@ size_t i{0}; }} } -#line 3439 "reflect.h2" +#line 3460 "reflect.h2" [[nodiscard]] auto range_token::gen_range_string() const& -> std::string { std::string r {""}; @@ -5108,7 +5132,7 @@ size_t i{0}; return r; } -#line 3458 "reflect.h2" +#line 3479 "reflect.h2" auto range_token::generate_code(generation_context& ctx) const -> void { auto inner_name {ctx.generate_func(inner_token)}; @@ -5120,14 +5144,14 @@ size_t i{0}; ctx.add_statefull(next_name, "cpp2::regex::range_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ", " + cpp2::to_string(cpp2::move(inner_name)) + ", " + cpp2::to_string(cpp2::move(reset_name)) + ", other, " + cpp2::to_string(next_name) + ")"); } -#line 3469 "reflect.h2" +#line 3490 "reflect.h2" auto range_token::add_groups(std::set& groups) const -> void{ (*cpp2::impl::assert_not_null(inner_token)).add_groups(groups); } range_token::~range_token() noexcept{} -#line 3482 "reflect.h2" +#line 3503 "reflect.h2" [[nodiscard]] auto special_range_token::parse(parse_context& ctx) -> token_ptr { auto r {CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared)}; @@ -5151,7 +5175,7 @@ size_t i{0}; if (!(ctx.has_token())) {return ctx.error("'" + cpp2::to_string(ctx.current()) + "' without previous element."); } -#line 3506 "reflect.h2" +#line 3527 "reflect.h2" (*cpp2::impl::assert_not_null(r)).parse_modifier(ctx); (*cpp2::impl::assert_not_null(r)).inner_token = ctx.pop_token(); @@ -5161,7 +5185,7 @@ size_t i{0}; special_range_token::~special_range_token() noexcept{} -#line 3519 "reflect.h2" +#line 3540 "reflect.h2" [[nodiscard]] auto word_boundary_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -5179,15 +5203,15 @@ size_t i{0}; }} } -#line 3555 "reflect.h2" +#line 3576 "reflect.h2" template regex_generator::regex_generator(cpp2::impl::in r, Error_out const& e) : regex{ r } , error_out{ e }{ -#line 3558 "reflect.h2" +#line 3579 "reflect.h2" } -#line 3560 "reflect.h2" +#line 3581 "reflect.h2" template [[nodiscard]] auto regex_generator::parse() & -> std::string { // Extract modifiers and adapt regex. @@ -5223,7 +5247,7 @@ size_t i{0}; return source; } -#line 3595 "reflect.h2" +#line 3616 "reflect.h2" template auto regex_generator::extract_modifiers() & -> void { if (regex.find_first_of("'/") == 0) { @@ -5239,7 +5263,7 @@ size_t i{0}; } } -#line 3611 "reflect.h2" +#line 3632 "reflect.h2" template [[nodiscard]] auto generate_regex(cpp2::impl::in regex, Err const& err) -> std::string { regex_generator parser {regex, err}; @@ -5248,7 +5272,7 @@ template [[nodiscard]] auto generate_regex(cpp2::impl::in void { auto has_default {false}; @@ -5303,7 +5327,7 @@ auto regex_gen(meta::type_declaration& t) -> void CPP2_UFCS(add_runtime_support_include)(t, "cpp2regex.h"); } -#line 3680 "reflect.h2" +#line 3701 "reflect.h2" [[nodiscard]] auto apply_metafunctions( declaration_node& n, type_declaration& rtype, @@ -5327,16 +5351,16 @@ auto regex_gen(meta::type_declaration& t) -> void // For each metafunction, apply it for ( - auto const& meta : n.metafunctions ) + auto const& metafunc : n.metafunctions ) { // Convert the name and any template arguments to strings // and record that in rtype - auto name {CPP2_UFCS(to_string)((*cpp2::impl::assert_not_null(meta)))}; + auto name {CPP2_UFCS(to_string)((*cpp2::impl::assert_not_null(metafunc)))}; name = CPP2_UFCS(substr)(name, 0, CPP2_UFCS(find)(name, '<')); std::vector args {}; for ( - auto const& arg : CPP2_UFCS(template_arguments)((*cpp2::impl::assert_not_null(meta))) ) + auto const& arg : CPP2_UFCS(template_arguments)((*cpp2::impl::assert_not_null(metafunc))) ) CPP2_UFCS(push_back)(args, CPP2_UFCS(to_string)(arg)); CPP2_UFCS(set_metafunction_name)(rtype, name, args); @@ -5418,7 +5442,7 @@ auto regex_gen(meta::type_declaration& t) -> void return true; } -#line 3799 "reflect.h2" +#line 3820 "reflect.h2" [[nodiscard]] auto apply_metafunctions( declaration_node& n, function_declaration& rfunc, @@ -5430,30 +5454,33 @@ auto regex_gen(meta::type_declaration& t) -> void // For each metafunction, apply it for ( - auto const& meta : n.metafunctions ) + auto const& metafunc : n.metafunctions ) { // Convert the name and any template arguments to strings // and record that in rfunc - auto name {CPP2_UFCS(to_string)((*cpp2::impl::assert_not_null(meta)))}; + auto name {CPP2_UFCS(to_string)((*cpp2::impl::assert_not_null(metafunc)))}; name = CPP2_UFCS(substr)(name, 0, CPP2_UFCS(find)(name, '<')); std::vector args {}; for ( - auto const& arg : CPP2_UFCS(template_arguments)((*cpp2::impl::assert_not_null(meta))) ) + auto const& arg : CPP2_UFCS(template_arguments)((*cpp2::impl::assert_not_null(metafunc))) ) CPP2_UFCS(push_back)(args, CPP2_UFCS(to_string)(arg)); CPP2_UFCS(set_metafunction_name)(rfunc, name, args); // Dispatch // - if (name == "print") { + if (name == "meta") { + meta(rfunc); + } + else {if (name == "print") { print(rfunc); } else { error("unrecognized metafunction name '" + name + "' for function declaration"); - error("(temporary alpha limitation) currently the supported names are: print"); + error("(temporary alpha limitation) currently the supported names are: meta, print"); return false; - } + }} if (( !(CPP2_UFCS(empty)(args)) @@ -5468,7 +5495,7 @@ auto regex_gen(meta::type_declaration& t) -> void return true; } -#line 3849 "reflect.h2" +#line 3873 "reflect.h2" } } diff --git a/source/reflect.h2 b/source/reflect.h2 index daf73d84a..29915e40d 100644 --- a/source/reflect.h2 +++ b/source/reflect.h2 @@ -1554,6 +1554,27 @@ print: (f: meta::function_declaration) = std::cout << f.print() << "\n"; } + +//----------------------------------------------------------------------- +// +// meta - mark f as a metafunction and generate registration code for it +// +meta: (inout f: meta::function_declaration) = +{ + // TODO(DyXel): Check that the function: + // * has ::cpp2::meta::function_declaration as only parameter, OR, + // * has ::cpp2::meta::type_declaration as only paramater, OR, + // * function_declaration or type_declaration (implicitly deduced to be the above), AND, + // * either in or inout paramater passing style, AND, + // * to be publicly accessible, AND, + // * to not be on header file, AND, + // * to have void return type. + fqn := f.fully_qualified_name(); + f.append_declaration_to_translation_unit("_: namespace = { _: ::cpp2::meta::register_metafunction = (\"(fqn)$\",(fqn)$&); }"); + f.add_runtime_support_include("cpp2reflect_api.h"); +} + + //----------------------------------------------------------------------- // // regex - creates regular expressions from members @@ -3700,15 +3721,15 @@ apply_metafunctions: ( // For each metafunction, apply it for n.metafunctions - do (meta) + do (metafunc) { // Convert the name and any template arguments to strings // and record that in rtype - name := meta*.to_string(); + name := metafunc*.to_string(); name = name.substr(0, name.find('<')); args: std::vector = (); - for meta*.template_arguments() + for metafunc*.template_arguments() do (arg) args.push_back( arg.to_string() ); @@ -3807,15 +3828,15 @@ apply_metafunctions: ( // For each metafunction, apply it for n.metafunctions - do (meta) + do (metafunc) { // Convert the name and any template arguments to strings // and record that in rfunc - name := meta*.to_string(); + name := metafunc*.to_string(); name = name.substr(0, name.find('<')); args: std::vector = (); - for meta*.template_arguments() + for metafunc*.template_arguments() do (arg) args.push_back( arg.to_string() ); @@ -3823,12 +3844,15 @@ apply_metafunctions: ( // Dispatch // - if name == "print" { + if name == "meta" { + meta( rfunc ); + } + else if name == "print" { print( rfunc ); } else { error( "unrecognized metafunction name '" + name + "' for function declaration" ); - error( "(temporary alpha limitation) currently the supported names are: print" ); + error( "(temporary alpha limitation) currently the supported names are: meta, print" ); return false; } From 3d14ded497b3901416d9e615a879315a3971eff7 Mon Sep 17 00:00:00 2001 From: Dylam De La Torre Date: Sun, 18 Aug 2024 21:17:03 +0200 Subject: [PATCH 5/9] Add metafunction to help declaring reflection public API Very internal to cppfront, to decide if we later want this to be usable by end users. --- source/reflect.h | 921 +++++++++++++++++++++++++--------------------- source/reflect.h2 | 79 ++++ 2 files changed, 581 insertions(+), 419 deletions(-) diff --git a/source/reflect.h b/source/reflect.h index fe2a1d272..ab3f0c9dd 100644 --- a/source/reflect.h +++ b/source/reflect.h @@ -36,77 +36,77 @@ class type_declaration; #line 645 "reflect.h2" class alias_declaration; -#line 1053 "reflect.h2" +#line 1129 "reflect.h2" class value_member_info; -#line 1596 "reflect.h2" +#line 1672 "reflect.h2" class expression_flags; -#line 1612 "reflect.h2" +#line 1688 "reflect.h2" class regex_token; -#line 1638 "reflect.h2" +#line 1714 "reflect.h2" class regex_token_check; -#line 1657 "reflect.h2" +#line 1733 "reflect.h2" class regex_token_code; -#line 1676 "reflect.h2" +#line 1752 "reflect.h2" class regex_token_empty; -#line 1692 "reflect.h2" +#line 1768 "reflect.h2" class regex_token_list; -#line 1731 "reflect.h2" +#line 1807 "reflect.h2" class parse_context_group_state; -#line 1792 "reflect.h2" +#line 1868 "reflect.h2" class parse_context_branch_reset_state; -#line 1835 "reflect.h2" +#line 1911 "reflect.h2" class parse_context; -#line 2233 "reflect.h2" +#line 2309 "reflect.h2" class generation_function_context; -#line 2251 "reflect.h2" +#line 2327 "reflect.h2" class generation_context; -#line 2449 "reflect.h2" +#line 2525 "reflect.h2" class alternative_token; -#line 2464 "reflect.h2" +#line 2540 "reflect.h2" class alternative_token_gen; -#line 2516 "reflect.h2" +#line 2592 "reflect.h2" class any_token; -#line 2534 "reflect.h2" +#line 2610 "reflect.h2" class char_token; -#line 2637 "reflect.h2" +#line 2713 "reflect.h2" class class_token; -#line 2852 "reflect.h2" +#line 2928 "reflect.h2" class group_ref_token; -#line 2983 "reflect.h2" +#line 3059 "reflect.h2" class group_token; -#line 3270 "reflect.h2" +#line 3346 "reflect.h2" class lookahead_token; -#line 3351 "reflect.h2" +#line 3427 "reflect.h2" class range_token; -#line 3499 "reflect.h2" +#line 3575 "reflect.h2" class special_range_token; -#line 3566 "reflect.h2" +#line 3642 "reflect.h2" template class regex_generator; -#line 3873 "reflect.h2" +#line 3952 "reflect.h2" } } @@ -491,56 +491,59 @@ class alias_declaration #line 673 "reflect.h2" auto add_virtual_destructor(meta::type_declaration& t) -> void; -#line 691 "reflect.h2" +#line 693 "reflect.h2" +auto foreign_interface_pseudovalue(meta::type_declaration& t) -> void; + +#line 767 "reflect.h2" auto interface(meta::type_declaration& t) -> void; -#line 737 "reflect.h2" +#line 813 "reflect.h2" auto polymorphic_base(meta::type_declaration& t) -> void; -#line 782 "reflect.h2" +#line 858 "reflect.h2" auto ordered_impl( meta::type_declaration& t, cpp2::impl::in ordering ) -> void; -#line 811 "reflect.h2" +#line 887 "reflect.h2" auto ordered(meta::type_declaration& t) -> void; -#line 819 "reflect.h2" +#line 895 "reflect.h2" auto weakly_ordered(meta::type_declaration& t) -> void; -#line 827 "reflect.h2" +#line 903 "reflect.h2" auto partially_ordered(meta::type_declaration& t) -> void; -#line 849 "reflect.h2" +#line 925 "reflect.h2" auto copyable(meta::type_declaration& t) -> void; -#line 883 "reflect.h2" +#line 959 "reflect.h2" auto basic_value(meta::type_declaration& t) -> void; -#line 911 "reflect.h2" +#line 987 "reflect.h2" auto value(meta::type_declaration& t) -> void; -#line 917 "reflect.h2" +#line 993 "reflect.h2" auto weakly_ordered_value(meta::type_declaration& t) -> void; -#line 923 "reflect.h2" +#line 999 "reflect.h2" auto partially_ordered_value(meta::type_declaration& t) -> void; -#line 952 "reflect.h2" +#line 1028 "reflect.h2" auto cpp1_rule_of_zero(meta::type_declaration& t) -> void; -#line 989 "reflect.h2" +#line 1065 "reflect.h2" auto cpp2_struct(meta::type_declaration& t) -> void; -#line 1053 "reflect.h2" +#line 1129 "reflect.h2" class value_member_info { public: std::string name; public: std::string type; public: std::string value; public: value_member_info(auto const& name_, auto const& type_, auto const& value_); -#line 1057 "reflect.h2" +#line 1133 "reflect.h2" }; auto basic_enum( @@ -549,28 +552,28 @@ auto basic_enum( cpp2::impl::in bitwise ) -> void; -#line 1323 "reflect.h2" +#line 1399 "reflect.h2" auto cpp2_enum(meta::type_declaration& t) -> void; -#line 1350 "reflect.h2" +#line 1426 "reflect.h2" auto flag_enum(meta::type_declaration& t) -> void; -#line 1396 "reflect.h2" +#line 1472 "reflect.h2" auto cpp2_union(meta::type_declaration& t) -> void; -#line 1547 "reflect.h2" +#line 1623 "reflect.h2" auto print(cpp2::impl::in t) -> void; -#line 1552 "reflect.h2" +#line 1628 "reflect.h2" auto print(cpp2::impl::in f) -> void; -#line 1562 "reflect.h2" +#line 1638 "reflect.h2" auto meta(meta::function_declaration& f) -> void; -#line 1592 "reflect.h2" +#line 1668 "reflect.h2" using error_func = std::function x)>; -#line 1596 "reflect.h2" +#line 1672 "reflect.h2" class expression_flags { private: cpp2::u8 _value; private: constexpr expression_flags(cpp2::impl::in _val); @@ -605,20 +608,20 @@ public: [[nodiscard]] auto to_code() const& -> std::string; public: [[nodiscard]] static auto from_string(cpp2::impl::in s) -> expression_flags; public: [[nodiscard]] static auto from_code(cpp2::impl::in s) -> expression_flags; -#line 1604 "reflect.h2" +#line 1680 "reflect.h2" }; -#line 1612 "reflect.h2" +#line 1688 "reflect.h2" class regex_token { public: std::string string_rep; public: explicit regex_token(cpp2::impl::in str); -#line 1620 "reflect.h2" +#line 1696 "reflect.h2" public: explicit regex_token(); -#line 1625 "reflect.h2" +#line 1701 "reflect.h2" public: virtual auto generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void = 0; public: virtual auto add_groups([[maybe_unused]] std::set& unnamed_param_2) const -> void; @@ -629,24 +632,24 @@ class regex_token public: regex_token(regex_token const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(regex_token const&) -> void = delete; -#line 1630 "reflect.h2" +#line 1706 "reflect.h2" }; using token_ptr = std::shared_ptr; using token_vec = std::vector; -#line 1636 "reflect.h2" +#line 1712 "reflect.h2" // Adds a check in code generation. // class regex_token_check : public regex_token { -#line 1642 "reflect.h2" +#line 1718 "reflect.h2" private: std::string check; public: explicit regex_token_check(cpp2::impl::in str, cpp2::impl::in check_); -#line 1649 "reflect.h2" +#line 1725 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~regex_token_check() noexcept; @@ -654,21 +657,21 @@ class regex_token_check public: auto operator=(regex_token_check const&) -> void = delete; -#line 1652 "reflect.h2" +#line 1728 "reflect.h2" }; -#line 1655 "reflect.h2" +#line 1731 "reflect.h2" // Adds code in code generation. // class regex_token_code : public regex_token { -#line 1661 "reflect.h2" +#line 1737 "reflect.h2" private: std::string code; public: explicit regex_token_code(cpp2::impl::in str, cpp2::impl::in code_); -#line 1668 "reflect.h2" +#line 1744 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~regex_token_code() noexcept; @@ -676,19 +679,19 @@ class regex_token_code public: auto operator=(regex_token_code const&) -> void = delete; -#line 1671 "reflect.h2" +#line 1747 "reflect.h2" }; -#line 1674 "reflect.h2" +#line 1750 "reflect.h2" // Token that does not influence the matching. E.g. comment. // class regex_token_empty : public regex_token { -#line 1680 "reflect.h2" +#line 1756 "reflect.h2" public: explicit regex_token_empty(cpp2::impl::in str); -#line 1684 "reflect.h2" +#line 1760 "reflect.h2" public: auto generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void override; public: virtual ~regex_token_empty() noexcept; @@ -696,27 +699,27 @@ class regex_token_empty public: auto operator=(regex_token_empty const&) -> void = delete; -#line 1687 "reflect.h2" +#line 1763 "reflect.h2" }; -#line 1690 "reflect.h2" +#line 1766 "reflect.h2" // Represents a list of regex tokens as one token. // class regex_token_list : public regex_token { -#line 1696 "reflect.h2" +#line 1772 "reflect.h2" public: token_vec tokens; public: explicit regex_token_list(cpp2::impl::in t); -#line 1703 "reflect.h2" +#line 1779 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 1709 "reflect.h2" +#line 1785 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; -#line 1715 "reflect.h2" +#line 1791 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in vec) -> std::string; public: virtual ~regex_token_list() noexcept; @@ -724,10 +727,10 @@ class regex_token_list public: auto operator=(regex_token_list const&) -> void = delete; -#line 1722 "reflect.h2" +#line 1798 "reflect.h2" }; -#line 1725 "reflect.h2" +#line 1801 "reflect.h2" // // Parse and generation context. // @@ -743,33 +746,33 @@ class parse_context_group_state // Start a new alternative. public: auto next_alternative() & -> void; -#line 1745 "reflect.h2" +#line 1821 "reflect.h2" // Swap this state with the other one. public: auto swap(parse_context_group_state& t) & -> void; -#line 1752 "reflect.h2" +#line 1828 "reflect.h2" // Convert this state into a regex token. public: [[nodiscard]] auto get_as_token() & -> token_ptr; -#line 1764 "reflect.h2" +#line 1840 "reflect.h2" // Add a token to the current matcher list. public: auto add(cpp2::impl::in token) & -> void; -#line 1769 "reflect.h2" +#line 1845 "reflect.h2" // True if current matcher list is empty. public: [[nodiscard]] auto empty() const& -> bool; -#line 1773 "reflect.h2" +#line 1849 "reflect.h2" // Apply optimizations to the matcher list. public: static auto post_process_list(token_vec& list) -> void; public: parse_context_group_state(auto const& cur_match_list_, auto const& alternate_match_lists_, auto const& modifiers_); public: parse_context_group_state(); -#line 1787 "reflect.h2" +#line 1863 "reflect.h2" }; -#line 1790 "reflect.h2" +#line 1866 "reflect.h2" // State for the branch reset. Takes care of the group numbering. See '(|)'. // class parse_context_branch_reset_state @@ -782,25 +785,25 @@ class parse_context_branch_reset_state // Next group identifier. public: [[nodiscard]] auto next() & -> int; -#line 1808 "reflect.h2" +#line 1884 "reflect.h2" // Set next group identifier. public: auto set_next(cpp2::impl::in g) & -> void; -#line 1814 "reflect.h2" +#line 1890 "reflect.h2" // Start a new alternative branch. public: auto next_alternative() & -> void; -#line 1821 "reflect.h2" +#line 1897 "reflect.h2" // Initialize for a branch reset group. public: auto set_active_reset(cpp2::impl::in restart) & -> void; public: parse_context_branch_reset_state(auto const& is_active_, auto const& cur_group_, auto const& max_group_, auto const& from_); public: parse_context_branch_reset_state(); -#line 1828 "reflect.h2" +#line 1904 "reflect.h2" }; -#line 1831 "reflect.h2" +#line 1907 "reflect.h2" // Context during parsing of the regular expressions. // // Keeps track of the distributed group identifiers, current parsed group and branch resets. @@ -814,7 +817,7 @@ class parse_context private: parse_context_group_state cur_group_state {}; private: parse_context_branch_reset_state cur_branch_reset_state {}; -#line 1845 "reflect.h2" +#line 1921 "reflect.h2" public: std::map named_groups {}; private: error_func error_out; // TODO: Declaring std::function fails for cpp2. @@ -822,64 +825,64 @@ class parse_context public: explicit parse_context(cpp2::impl::in r, auto const& e); -#line 1856 "reflect.h2" +#line 1932 "reflect.h2" // State management functions // // Returned group state needs to be stored and provided in `end_group`. public: [[nodiscard]] auto start_group() & -> parse_context_group_state; -#line 1869 "reflect.h2" +#line 1945 "reflect.h2" // `old_state` argument needs to be from start group. public: [[nodiscard]] auto end_group(cpp2::impl::in old_state) & -> token_ptr; -#line 1877 "reflect.h2" +#line 1953 "reflect.h2" public: [[nodiscard]] auto get_modifiers() const& -> expression_flags; -#line 1881 "reflect.h2" +#line 1957 "reflect.h2" public: auto set_modifiers(cpp2::impl::in mod) & -> void; -#line 1885 "reflect.h2" +#line 1961 "reflect.h2" // Branch reset management functions // public: [[nodiscard]] auto branch_reset_new_state() & -> parse_context_branch_reset_state; -#line 1897 "reflect.h2" +#line 1973 "reflect.h2" public: auto branch_reset_restore_state(cpp2::impl::in old_state) & -> void; -#line 1904 "reflect.h2" +#line 1980 "reflect.h2" public: auto next_alternative() & -> void; -#line 1910 "reflect.h2" +#line 1986 "reflect.h2" // Regex token management // public: auto add_token(cpp2::impl::in token) & -> void; -#line 1916 "reflect.h2" +#line 1992 "reflect.h2" public: [[nodiscard]] auto has_token() const& -> bool; -#line 1920 "reflect.h2" +#line 1996 "reflect.h2" public: [[nodiscard]] auto pop_token() & -> token_ptr; -#line 1931 "reflect.h2" +#line 2007 "reflect.h2" public: [[nodiscard]] auto get_as_token() & -> token_ptr; -#line 1935 "reflect.h2" +#line 2011 "reflect.h2" // Group management // public: [[nodiscard]] auto get_cur_group() const& -> int; -#line 1941 "reflect.h2" +#line 2017 "reflect.h2" public: [[nodiscard]] auto next_group() & -> int; -#line 1945 "reflect.h2" +#line 2021 "reflect.h2" public: auto set_named_group(cpp2::impl::in name, cpp2::impl::in id) & -> void; -#line 1952 "reflect.h2" +#line 2028 "reflect.h2" public: [[nodiscard]] auto get_named_group(cpp2::impl::in name) const& -> int; -#line 1963 "reflect.h2" +#line 2039 "reflect.h2" // Position management functions // public: [[nodiscard]] auto current() const& -> char; @@ -887,51 +890,51 @@ class parse_context // Get the next token in the regex, skipping spaces according to the parameters. See `x` and `xx` modifiers. private: [[nodiscard]] auto get_next_position(cpp2::impl::in in_class, cpp2::impl::in no_skip) const& -> size_t; -#line 2007 "reflect.h2" +#line 2083 "reflect.h2" // Return true if next token is available. private: [[nodiscard]] auto next_impl(cpp2::impl::in in_class, cpp2::impl::in no_skip) & -> bool; -#line 2019 "reflect.h2" +#line 2095 "reflect.h2" public: [[nodiscard]] auto next() & -> auto; public: [[nodiscard]] auto next_in_class() & -> auto; public: [[nodiscard]] auto next_no_skip() & -> auto; public: [[nodiscard]] auto next_n(cpp2::impl::in n) & -> bool; -#line 2032 "reflect.h2" +#line 2108 "reflect.h2" public: [[nodiscard]] auto has_next() const& -> bool; private: [[nodiscard]] auto grab_until_impl(cpp2::impl::in e, cpp2::impl::out r, cpp2::impl::in any) & -> bool; -#line 2055 "reflect.h2" +#line 2131 "reflect.h2" public: [[nodiscard]] auto grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_until_one_of(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_n(cpp2::impl::in n, cpp2::impl::out r) & -> bool; -#line 2072 "reflect.h2" +#line 2148 "reflect.h2" public: [[nodiscard]] auto grab_number() & -> std::string; -#line 2093 "reflect.h2" +#line 2169 "reflect.h2" private: [[nodiscard]] auto peek_impl(cpp2::impl::in in_class) const& -> char; -#line 2103 "reflect.h2" +#line 2179 "reflect.h2" public: [[nodiscard]] auto peek() const& -> auto; public: [[nodiscard]] auto peek_in_class() const& -> auto; -#line 2107 "reflect.h2" +#line 2183 "reflect.h2" // Parsing functions // public: [[nodiscard]] auto parser_group_modifiers(cpp2::impl::in change_str, expression_flags& parser_modifiers) & -> bool; -#line 2163 "reflect.h2" +#line 2239 "reflect.h2" public: [[nodiscard]] auto parse_until(cpp2::impl::in term) & -> bool; -#line 2201 "reflect.h2" +#line 2277 "reflect.h2" public: [[nodiscard]] auto parse(cpp2::impl::in modifiers) & -> bool; -#line 2216 "reflect.h2" +#line 2292 "reflect.h2" // Misc functions public: [[nodiscard]] auto get_pos() const& -> auto; @@ -943,10 +946,10 @@ class parse_context public: auto operator=(parse_context const&) -> void = delete; -#line 2227 "reflect.h2" +#line 2303 "reflect.h2" }; -#line 2230 "reflect.h2" +#line 2306 "reflect.h2" // Context for one function generation. Generation of functions can be interleaved, // therefore we buffer the code for one function here. // @@ -956,16 +959,16 @@ class generation_function_context { public: auto add_tabs(cpp2::impl::in c) & -> void; -#line 2244 "reflect.h2" +#line 2320 "reflect.h2" public: auto remove_tabs(cpp2::impl::in c) & -> void; public: generation_function_context(auto const& code_, auto const& tabs_); public: generation_function_context(); -#line 2247 "reflect.h2" +#line 2323 "reflect.h2" }; -#line 2250 "reflect.h2" +#line 2326 "reflect.h2" // Context for generating the state machine. class generation_context { @@ -985,68 +988,68 @@ class generation_context // Add code line. public: auto add(cpp2::impl::in s) & -> void; -#line 2272 "reflect.h2" +#line 2348 "reflect.h2" // Add check for token. The check needs to be a function call that returns a boolean. public: auto add_check(cpp2::impl::in check) & -> void; -#line 2278 "reflect.h2" +#line 2354 "reflect.h2" // Add a stateful check. The check needs to return a `match_return`. public: auto add_statefull(cpp2::impl::in next_func, cpp2::impl::in check) & -> void; -#line 2287 "reflect.h2" +#line 2363 "reflect.h2" protected: auto start_func_named(cpp2::impl::in name) & -> void; -#line 2298 "reflect.h2" +#line 2374 "reflect.h2" protected: [[nodiscard]] auto start_func() & -> std::string; -#line 2305 "reflect.h2" +#line 2381 "reflect.h2" protected: auto end_func_statefull(cpp2::impl::in s) & -> void; -#line 2324 "reflect.h2" +#line 2400 "reflect.h2" // Generate the function for a token. public: [[nodiscard]] auto generate_func(cpp2::impl::in token) & -> std::string; -#line 2334 "reflect.h2" +#line 2410 "reflect.h2" // Generate the reset for a list of group identifiers. public: [[nodiscard]] auto generate_reset(cpp2::impl::in> groups) & -> std::string; -#line 2357 "reflect.h2" +#line 2433 "reflect.h2" // Name generation // protected: [[nodiscard]] auto gen_func_name() & -> std::string; -#line 2365 "reflect.h2" +#line 2441 "reflect.h2" public: [[nodiscard]] auto next_func_name() & -> std::string; -#line 2369 "reflect.h2" +#line 2445 "reflect.h2" protected: [[nodiscard]] auto gen_reset_func_name() & -> std::string; -#line 2375 "reflect.h2" +#line 2451 "reflect.h2" public: [[nodiscard]] auto gen_temp() & -> std::string; -#line 2381 "reflect.h2" +#line 2457 "reflect.h2" // Context management // public: [[nodiscard]] auto new_context() & -> generation_function_context*; -#line 2391 "reflect.h2" +#line 2467 "reflect.h2" public: auto finish_context() & -> void; -#line 2399 "reflect.h2" +#line 2475 "reflect.h2" // Misc functions // private: [[nodiscard]] auto get_current() & -> generation_function_context*; -#line 2405 "reflect.h2" +#line 2481 "reflect.h2" private: [[nodiscard]] auto get_base() & -> generation_function_context*; -#line 2409 "reflect.h2" +#line 2485 "reflect.h2" public: [[nodiscard]] auto get_entry_func() const& -> std::string; -#line 2413 "reflect.h2" +#line 2489 "reflect.h2" public: [[nodiscard]] auto create_named_group_lookup(cpp2::impl::in> named_groups) const& -> std::string; -#line 2437 "reflect.h2" +#line 2513 "reflect.h2" // Run the generation for the token. public: [[nodiscard]] auto run(cpp2::impl::in token) & -> std::string; public: generation_context() = default; @@ -1054,7 +1057,7 @@ class generation_context public: auto operator=(generation_context const&) -> void = delete; -#line 2443 "reflect.h2" +#line 2519 "reflect.h2" }; // Regex syntax: | Example: ab|ba @@ -1074,24 +1077,24 @@ class alternative_token public: auto operator=(alternative_token const&) -> void = delete; -#line 2462 "reflect.h2" +#line 2538 "reflect.h2" }; class alternative_token_gen : public regex_token { -#line 2468 "reflect.h2" +#line 2544 "reflect.h2" private: token_vec alternatives; public: explicit alternative_token_gen(cpp2::impl::in a); -#line 2475 "reflect.h2" +#line 2551 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2492 "reflect.h2" +#line 2568 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; -#line 2499 "reflect.h2" +#line 2575 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in a) -> std::string; public: virtual ~alternative_token_gen() noexcept; @@ -1099,19 +1102,19 @@ class alternative_token_gen public: auto operator=(alternative_token_gen const&) -> void = delete; -#line 2511 "reflect.h2" +#line 2587 "reflect.h2" }; -#line 2514 "reflect.h2" +#line 2590 "reflect.h2" // Regex syntax: . // class any_token : public regex_token_check { -#line 2520 "reflect.h2" +#line 2596 "reflect.h2" public: explicit any_token(cpp2::impl::in single_line); -#line 2524 "reflect.h2" +#line 2600 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; public: virtual ~any_token() noexcept; @@ -1119,37 +1122,37 @@ class any_token public: auto operator=(any_token const&) -> void = delete; -#line 2529 "reflect.h2" +#line 2605 "reflect.h2" }; -#line 2532 "reflect.h2" +#line 2608 "reflect.h2" // Regex syntax: a // class char_token : public regex_token { -#line 2538 "reflect.h2" +#line 2614 "reflect.h2" private: std::string token; private: bool ignore_case; public: explicit char_token(cpp2::impl::in t, cpp2::impl::in ignore_case_); -#line 2547 "reflect.h2" +#line 2623 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 2551 "reflect.h2" +#line 2627 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2574 "reflect.h2" +#line 2650 "reflect.h2" public: auto gen_case_insensitive(cpp2::impl::in lower, cpp2::impl::in upper, generation_context& ctx) const& -> void; -#line 2595 "reflect.h2" +#line 2671 "reflect.h2" public: auto gen_case_sensitive(generation_context& ctx) const& -> void; -#line 2613 "reflect.h2" +#line 2689 "reflect.h2" public: [[nodiscard]] auto add_escapes(std::string str) const& -> std::string; -#line 2628 "reflect.h2" +#line 2704 "reflect.h2" public: auto append(char_token const& that) & -> void; public: virtual ~char_token() noexcept; @@ -1157,30 +1160,30 @@ class char_token public: auto operator=(char_token const&) -> void = delete; -#line 2632 "reflect.h2" +#line 2708 "reflect.h2" }; -#line 2635 "reflect.h2" +#line 2711 "reflect.h2" // Regex syntax: [] Example: [abcx-y[:digits:]] // class class_token : public regex_token { -#line 2641 "reflect.h2" +#line 2717 "reflect.h2" private: bool negate; private: bool case_insensitive; private: std::string class_str; public: explicit class_token(cpp2::impl::in negate_, cpp2::impl::in case_insensitive_, cpp2::impl::in class_str_, cpp2::impl::in str); -#line 2653 "reflect.h2" +#line 2729 "reflect.h2" // TODO: Rework class generation: Generate check functions for classes. public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 2779 "reflect.h2" +#line 2855 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2784 "reflect.h2" +#line 2860 "reflect.h2" private: [[nodiscard]] static auto create_matcher(cpp2::impl::in name, cpp2::impl::in template_arguments) -> std::string; public: virtual ~class_token() noexcept; @@ -1188,20 +1191,20 @@ class class_token public: auto operator=(class_token const&) -> void = delete; -#line 2791 "reflect.h2" +#line 2867 "reflect.h2" }; -#line 2794 "reflect.h2" +#line 2870 "reflect.h2" // Regex syntax: \a or \n or \[ // [[nodiscard]] auto escape_token_parse(parse_context& ctx) -> token_ptr; -#line 2835 "reflect.h2" +#line 2911 "reflect.h2" // Regex syntax: \K Example: ab\Kcd // [[nodiscard]] auto global_group_reset_token_parse(parse_context& ctx) -> token_ptr; -#line 2846 "reflect.h2" +#line 2922 "reflect.h2" // Regex syntax: \ Example: \1 // \g{name_or_number} // \k{name_or_number} @@ -1211,16 +1214,16 @@ class class_token class group_ref_token : public regex_token { -#line 2856 "reflect.h2" +#line 2932 "reflect.h2" private: int id; private: bool case_insensitive; public: explicit group_ref_token(cpp2::impl::in id_, cpp2::impl::in case_insensitive_, cpp2::impl::in str); -#line 2866 "reflect.h2" +#line 2942 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 2967 "reflect.h2" +#line 3043 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~group_ref_token() noexcept; @@ -1228,10 +1231,10 @@ class group_ref_token public: auto operator=(group_ref_token const&) -> void = delete; -#line 2970 "reflect.h2" +#line 3046 "reflect.h2" }; -#line 2973 "reflect.h2" +#line 3049 "reflect.h2" // Regex syntax: () Example: (abc) // (?:) (?i:abc) @@ -1245,22 +1248,22 @@ class group_ref_token class group_token : public regex_token { -#line 2987 "reflect.h2" +#line 3063 "reflect.h2" private: int number {-1}; private: token_ptr inner {nullptr}; public: [[nodiscard]] static auto parse_lookahead(parse_context& ctx, cpp2::impl::in syntax, cpp2::impl::in positive) -> token_ptr; -#line 3004 "reflect.h2" +#line 3080 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 3141 "reflect.h2" +#line 3217 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in name, cpp2::impl::in name_brackets, cpp2::impl::in has_modifier, cpp2::impl::in modifiers, cpp2::impl::in inner_) -> std::string; -#line 3159 "reflect.h2" +#line 3235 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3179 "reflect.h2" +#line 3255 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~group_token() noexcept; @@ -1269,25 +1272,25 @@ class group_token public: auto operator=(group_token const&) -> void = delete; -#line 3186 "reflect.h2" +#line 3262 "reflect.h2" }; -#line 3189 "reflect.h2" +#line 3265 "reflect.h2" // Regex syntax: \x or \x{} Example: \x{62} // [[nodiscard]] auto hexadecimal_token_parse(parse_context& ctx) -> token_ptr; -#line 3230 "reflect.h2" +#line 3306 "reflect.h2" // Regex syntax: $ Example: aa$ // [[nodiscard]] auto line_end_token_parse(parse_context& ctx) -> token_ptr; -#line 3250 "reflect.h2" +#line 3326 "reflect.h2" // Regex syntax: ^ Example: ^aa // [[nodiscard]] auto line_start_token_parse(parse_context& ctx) -> token_ptr; -#line 3266 "reflect.h2" +#line 3342 "reflect.h2" // Regex syntax: (?=) or (?!) or (*pla), etc. Example: (?=AA) // // Parsed in group_token. @@ -1295,16 +1298,16 @@ class group_token class lookahead_token : public regex_token { -#line 3274 "reflect.h2" +#line 3350 "reflect.h2" protected: bool positive; public: token_ptr inner {nullptr}; public: explicit lookahead_token(cpp2::impl::in positive_); -#line 3281 "reflect.h2" +#line 3357 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3287 "reflect.h2" +#line 3363 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~lookahead_token() noexcept; @@ -1312,26 +1315,26 @@ class lookahead_token public: auto operator=(lookahead_token const&) -> void = delete; -#line 3290 "reflect.h2" +#line 3366 "reflect.h2" }; -#line 3293 "reflect.h2" +#line 3369 "reflect.h2" // Named character classes // [[nodiscard]] auto named_class_token_parse(parse_context& ctx) -> token_ptr; -#line 3321 "reflect.h2" +#line 3397 "reflect.h2" // Regex syntax: \o{} Example: \o{142} // [[nodiscard]] auto octal_token_parse(parse_context& ctx) -> token_ptr; -#line 3349 "reflect.h2" +#line 3425 "reflect.h2" // Regex syntax: {min, max} Example: a{2,4} // class range_token : public regex_token { -#line 3355 "reflect.h2" +#line 3431 "reflect.h2" protected: int min_count {-1}; protected: int max_count {-1}; protected: int kind {range_flags::greedy}; @@ -1341,19 +1344,19 @@ class range_token public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 3435 "reflect.h2" +#line 3511 "reflect.h2" public: auto parse_modifier(parse_context& ctx) & -> void; -#line 3447 "reflect.h2" +#line 3523 "reflect.h2" public: [[nodiscard]] auto gen_mod_string() const& -> std::string; -#line 3460 "reflect.h2" +#line 3536 "reflect.h2" public: [[nodiscard]] auto gen_range_string() const& -> std::string; -#line 3479 "reflect.h2" +#line 3555 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3490 "reflect.h2" +#line 3566 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~range_token() noexcept; @@ -1361,16 +1364,16 @@ class range_token public: auto operator=(range_token const&) -> void = delete; -#line 3494 "reflect.h2" +#line 3570 "reflect.h2" }; -#line 3497 "reflect.h2" +#line 3573 "reflect.h2" // Regex syntax: *, +, or ? Example: aa* // class special_range_token : public range_token { -#line 3503 "reflect.h2" +#line 3579 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; public: virtual ~special_range_token() noexcept; @@ -1379,17 +1382,17 @@ class special_range_token public: auto operator=(special_range_token const&) -> void = delete; -#line 3533 "reflect.h2" +#line 3609 "reflect.h2" }; -#line 3536 "reflect.h2" +#line 3612 "reflect.h2" // Regex syntax: \b or \B Example: \bword\b // // Matches the start end end of word boundaries. // [[nodiscard]] auto word_boundary_token_parse(parse_context& ctx) -> token_ptr; -#line 3558 "reflect.h2" +#line 3634 "reflect.h2" //----------------------------------------------------------------------- // // Parser for regular expression. @@ -1410,24 +1413,24 @@ template class regex_generator public: explicit regex_generator(cpp2::impl::in r, Error_out const& e); -#line 3581 "reflect.h2" +#line 3657 "reflect.h2" public: [[nodiscard]] auto parse() & -> std::string; -#line 3616 "reflect.h2" +#line 3692 "reflect.h2" private: auto extract_modifiers() & -> void; public: regex_generator(regex_generator const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(regex_generator const&) -> void = delete; -#line 3630 "reflect.h2" +#line 3706 "reflect.h2" }; template [[nodiscard]] auto generate_regex(cpp2::impl::in regex, Err const& err) -> std::string; -#line 3642 "reflect.h2" +#line 3718 "reflect.h2" auto regex_gen(meta::type_declaration& t) -> void; -#line 3697 "reflect.h2" +#line 3773 "reflect.h2" //----------------------------------------------------------------------- // // apply_metafunctions - for types @@ -1438,7 +1441,7 @@ auto regex_gen(meta::type_declaration& t) -> void; auto const& error ) -> bool; -#line 3816 "reflect.h2" +#line 3895 "reflect.h2" //----------------------------------------------------------------------- // // apply_metafunctions - for functions @@ -1449,7 +1452,7 @@ auto regex_gen(meta::type_declaration& t) -> void; auto const& error ) -> bool; -#line 3873 "reflect.h2" +#line 3952 "reflect.h2" } } @@ -2264,7 +2267,84 @@ auto add_virtual_destructor(meta::type_declaration& t) -> void CPP2_UFCS(add_member)(t, "operator=: (virtual move this) = { }"); } -#line 679 "reflect.h2" +//----------------------------------------------------------------------- +// +// foreign_interface_pseudovalue +// +// Internal metafunction to help with public reflection API declaration. +// +// * "foreign interface" because the interface its declaring will be +// defined somewhere else outside the metaprogram. +// +// * "pseudovalue" because the resulting type behaves like a value, +// you can copy, move it, etc. But its not an actual value type, +// as all of its "guts" are behind pointers to the implementation. +// +// The verbose name is on purpose, lets try to give it a better name if it +// can be generalized into something useful for all developers. +#line 693 "reflect.h2" +auto foreign_interface_pseudovalue(meta::type_declaration& t) -> void +{ + std::vector interface_funcs {}; + std::string parent {}; + + for ( auto& m : CPP2_UFCS(get_members)(t) ) + { + if (CPP2_UFCS(is_object)(m)) { + auto mo {CPP2_UFCS(as_object)(m)}; + CPP2_UFCS(require)(mo, CPP2_UFCS(name)(mo) == "this", + "only member object that foreing value can have is a parent"); + CPP2_UFCS(require)(mo, CPP2_UFCS(empty)(parent), + "foreign value can only have 1 parent (which must also be a @foreing_value)"); + parent = CPP2_UFCS(type)(cpp2::move(mo)); + } + if (CPP2_UFCS(is_function)(m)) { + auto mf {CPP2_UFCS(as_function)(m)}; + if (CPP2_UFCS(has_initializer)(mf)) { + // foreign value functions will be provided a dummy implementation, + // unless they already have one (used for templated functions) + continue; + } + CPP2_UFCS(require)(mf, CPP2_UFCS(make_public)(mf), + "foreign value functions must be public"); + CPP2_UFCS(require)(mf, CPP2_UFCS(is_function_with_this)(mf), + "foreign value functions must have 'this'"); + static_cast(CPP2_UFCS(emplace_back)(interface_funcs, CPP2_UFCS(print)(mf))); + auto name {mf.name()}; + std::string params_as_string {}; + // imf := interface_funcs.emplace_back(); + // imf.append("(name)$ : ("); + for ( auto const& p : CPP2_UFCS(get_parameters)(mf) ) + { + // imf.append("(p.name())$ : ()$,"); + if (CPP2_UFCS(name)(p) == "this") {continue; } + static_cast(CPP2_UFCS(append)(params_as_string, "" + cpp2::to_string(CPP2_UFCS(name)(p)) + ",")); + } + // imf.append(");"); + CPP2_UFCS(add_initializer)(mf, "_pimpl*." + cpp2::to_string(cpp2::move(name)) + "(" + cpp2::to_string(cpp2::move(params_as_string)) + ");"); + static_cast(cpp2::move(mf)); + } + } + + std::string interface_to_add {"public interface: @interface type = {\n"}; + for ( auto const& iff : cpp2::move(interface_funcs) ) {static_cast(CPP2_UFCS(append)(interface_to_add, iff)); } + static_cast(CPP2_UFCS(append)(interface_to_add, "}\n")); + + CPP2_UFCS(add_member)(t, cpp2::move(interface_to_add)); + CPP2_UFCS(add_member)(t, "private _pimpl: std::unique_ptr;\n"); + if (CPP2_UFCS(empty)(parent)) { + CPP2_UFCS(add_member)(t, "operator=: (out this, copy pimpl: std::unique_ptr) = _pimpl = (move pimpl);\n"); + }else { + CPP2_UFCS(add_member)(t, + "operator=: (out this, copy pimpl: std::unique_ptr, forward parent_pimpls...) = " + "{ " + cpp2::to_string(cpp2::move(parent)) + " = parent_pimpls...; _pimpl = pimpl; }\n" + ); + } + CPP2_UFCS(add_member)(t, "operator=: (out this, move that) = { _pimpl = (move that._pimpl); }\n"); + CPP2_UFCS(add_member)(t, "operator=: (move this) = { }\n"); +} + +#line 755 "reflect.h2" //----------------------------------------------------------------------- // // "... an abstract base class defines an interface ..." @@ -2277,7 +2357,7 @@ auto add_virtual_destructor(meta::type_declaration& t) -> void // // an abstract base class having only pure virtual functions // -#line 691 "reflect.h2" +#line 767 "reflect.h2" auto interface(meta::type_declaration& t) -> void { auto has_dtor {false}; @@ -2304,7 +2384,7 @@ auto interface(meta::type_declaration& t) -> void } } -#line 718 "reflect.h2" +#line 794 "reflect.h2" //----------------------------------------------------------------------- // // "C.35: A base class destructor should be either public and @@ -2324,7 +2404,7 @@ auto interface(meta::type_declaration& t) -> void // // Unlike an interface, it can have nonpublic and nonvirtual functions. // -#line 737 "reflect.h2" +#line 813 "reflect.h2" auto polymorphic_base(meta::type_declaration& t) -> void { auto has_dtor {false}; @@ -2349,7 +2429,7 @@ auto polymorphic_base(meta::type_declaration& t) -> void } } -#line 762 "reflect.h2" +#line 838 "reflect.h2" //----------------------------------------------------------------------- // // "... A totally ordered type ... requires operator<=> that @@ -2370,7 +2450,7 @@ auto polymorphic_base(meta::type_declaration& t) -> void //----------------------------------------------------------------------- // -#line 782 "reflect.h2" +#line 858 "reflect.h2" auto ordered_impl( meta::type_declaration& t, cpp2::impl::in ordering// must be "strong_ordering" etc. @@ -2400,7 +2480,7 @@ auto ordered_impl( // // Note: the ordering that should be encouraged as default gets the nice name // -#line 811 "reflect.h2" +#line 887 "reflect.h2" auto ordered(meta::type_declaration& t) -> void { ordered_impl(t, "strong_ordering"); @@ -2409,7 +2489,7 @@ auto ordered(meta::type_declaration& t) -> void //----------------------------------------------------------------------- // weakly_ordered - a weakly ordered type // -#line 819 "reflect.h2" +#line 895 "reflect.h2" auto weakly_ordered(meta::type_declaration& t) -> void { ordered_impl(t, "weak_ordering"); @@ -2418,13 +2498,13 @@ auto weakly_ordered(meta::type_declaration& t) -> void //----------------------------------------------------------------------- // partially_ordered - a partially ordered type // -#line 827 "reflect.h2" +#line 903 "reflect.h2" auto partially_ordered(meta::type_declaration& t) -> void { ordered_impl(t, "partial_ordering"); } -#line 833 "reflect.h2" +#line 909 "reflect.h2" //----------------------------------------------------------------------- // // "A value is ... a regular type. It must have all public @@ -2441,7 +2521,7 @@ auto partially_ordered(meta::type_declaration& t) -> void // // A type with (copy and move) x (construction and assignment) // -#line 849 "reflect.h2" +#line 925 "reflect.h2" auto copyable(meta::type_declaration& t) -> void { // If the user explicitly wrote any of the copy/move functions, @@ -2476,7 +2556,7 @@ auto copyable(meta::type_declaration& t) -> void // A regular type: copyable, plus has public default construction // and no protected or virtual functions // -#line 883 "reflect.h2" +#line 959 "reflect.h2" auto basic_value(meta::type_declaration& t) -> void { CPP2_UFCS(copyable)(t); @@ -2505,28 +2585,28 @@ auto basic_value(meta::type_declaration& t) -> void // // Note: the ordering that should be encouraged as default gets the nice name // -#line 911 "reflect.h2" +#line 987 "reflect.h2" auto value(meta::type_declaration& t) -> void { CPP2_UFCS(ordered)(t); CPP2_UFCS(basic_value)(t); } -#line 917 "reflect.h2" +#line 993 "reflect.h2" auto weakly_ordered_value(meta::type_declaration& t) -> void { CPP2_UFCS(weakly_ordered)(t); CPP2_UFCS(basic_value)(t); } -#line 923 "reflect.h2" +#line 999 "reflect.h2" auto partially_ordered_value(meta::type_declaration& t) -> void { CPP2_UFCS(partially_ordered)(t); CPP2_UFCS(basic_value)(t); } -#line 930 "reflect.h2" +#line 1006 "reflect.h2" //----------------------------------------------------------------------- // // C.20: If you can avoid defining default operations, do @@ -2549,7 +2629,7 @@ auto partially_ordered_value(meta::type_declaration& t) -> void // // a type without declared copy/move/destructor functions // -#line 952 "reflect.h2" +#line 1028 "reflect.h2" auto cpp1_rule_of_zero(meta::type_declaration& t) -> void { for ( auto& mf : CPP2_UFCS(get_member_functions)(t) ) @@ -2587,7 +2667,7 @@ auto cpp1_rule_of_zero(meta::type_declaration& t) -> void // no virtual functions, and no user-defined constructors // (i.e., no invariants) or assignment or destructors. // -#line 989 "reflect.h2" +#line 1065 "reflect.h2" auto cpp2_struct(meta::type_declaration& t) -> void { std::string ctor_params {}; @@ -2639,7 +2719,7 @@ value_member_info::value_member_info(auto const& name_, auto const& type_, auto , type{ type_ } , value{ value_ }{} -#line 1036 "reflect.h2" +#line 1112 "reflect.h2" //----------------------------------------------------------------------- // // "C enumerations constitute a curiously half-baked concept. ... @@ -2658,7 +2738,7 @@ value_member_info::value_member_info(auto const& name_, auto const& type_, auto // a type together with named constants that are its possible values // -#line 1059 "reflect.h2" +#line 1135 "reflect.h2" auto basic_enum( meta::type_declaration& t, auto const& nextval, @@ -2683,7 +2763,7 @@ auto basic_enum( { std::string value{"-1"}; -#line 1082 "reflect.h2" +#line 1158 "reflect.h2" for ( auto const& m : CPP2_UFCS(get_members)(t) ) if ( CPP2_UFCS(is_member_object)(m)) @@ -2725,7 +2805,7 @@ std::string value{"-1"}; } } -#line 1122 "reflect.h2" +#line 1198 "reflect.h2" if ((CPP2_UFCS(empty)(enumerators))) { CPP2_UFCS(error)(t, "an enumeration must contain at least one enumerator value"); return ; @@ -2776,7 +2856,7 @@ std::string value{"-1"}; } } -#line 1173 "reflect.h2" +#line 1249 "reflect.h2" // 2. Replace: Erase the contents and replace with modified contents // // Note that most values and functions are declared as '==' compile-time values, i.e. Cpp1 'constexpr' @@ -2826,7 +2906,7 @@ std::string to_string_impl{" to_string_impl: (this, prefix: std::string_view" // Provide 'to_string' and 'to_code' functions to print enumerator // name(s) as human-readable strings or as code expressions -#line 1220 "reflect.h2" +#line 1296 "reflect.h2" { if (bitwise) { to_string_impl += ", separator: std::string_view ) -> std::string = { \n" @@ -2867,7 +2947,7 @@ std::string to_string_impl{" to_string_impl: (this, prefix: std::string_view" } } -#line 1259 "reflect.h2" +#line 1335 "reflect.h2" if (bitwise) { CPP2_UFCS(add_member)(t, " to_string: (this) -> std::string = to_string_impl( \"\", \", \" );"); CPP2_UFCS(add_member)(t, " to_code : (this) -> std::string = to_string_impl( \"" + cpp2::to_string(CPP2_UFCS(name)(t)) + "::\", \" | \" );"); @@ -2881,7 +2961,7 @@ std::string from_string{" from_string: (s: std::string_view) -> " + cpp2::to_ // Provide a 'from_string' function to parse strings into enumerators -#line 1270 "reflect.h2" +#line 1346 "reflect.h2" { std::string_view prefix {""}; std::string_view combine_op {"return"}; @@ -2903,7 +2983,7 @@ std::string from_string{" from_string: (s: std::string_view) -> " + cpp2::to_ { std::string_view else_{""}; -#line 1290 "reflect.h2" +#line 1366 "reflect.h2" for ( auto const& e : cpp2::move(enumerators) ) { from_string += " " + cpp2::to_string(else_) + "if \"" + cpp2::to_string(e.name) + "\" == x { " + cpp2::to_string(combine_op) + " " + cpp2::to_string(e.name) + "; }\n"; @@ -2911,7 +2991,7 @@ std::string_view else_{""}; } } -#line 1296 "reflect.h2" +#line 1372 "reflect.h2" if (bitwise) { from_string += " else { break outer; }\n" " }\n" @@ -2927,11 +3007,11 @@ std::string_view else_{""}; } } -#line 1310 "reflect.h2" +#line 1386 "reflect.h2" CPP2_UFCS(add_member)(t, " from_code: (s: std::string_view) -> " + cpp2::to_string(CPP2_UFCS(name)(t)) + " = { str: std::string = s; return from_string( cpp2::string_util::replace_all(str, \"" + cpp2::to_string(CPP2_UFCS(name)(t)) + "::\", \"\" ) ); }"); } -#line 1314 "reflect.h2" +#line 1390 "reflect.h2" //----------------------------------------------------------------------- // // "An enum[...] is a totally ordered value type that stores a @@ -2941,7 +3021,7 @@ std::string_view else_{""}; // // -- P0707R4, section 3 // -#line 1323 "reflect.h2" +#line 1399 "reflect.h2" auto cpp2_enum(meta::type_declaration& t) -> void { // Let basic_enum do its thing, with an incrementing value generator @@ -2958,7 +3038,7 @@ auto cpp2_enum(meta::type_declaration& t) -> void ); } -#line 1340 "reflect.h2" +#line 1416 "reflect.h2" //----------------------------------------------------------------------- // // "flag_enum expresses an enumeration that stores values @@ -2969,7 +3049,7 @@ auto cpp2_enum(meta::type_declaration& t) -> void // // -- P0707R4, section 3 // -#line 1350 "reflect.h2" +#line 1426 "reflect.h2" auto flag_enum(meta::type_declaration& t) -> void { // Let basic_enum do its thing, with a power-of-two value generator @@ -2991,7 +3071,7 @@ auto flag_enum(meta::type_declaration& t) -> void ); } -#line 1372 "reflect.h2" +#line 1448 "reflect.h2" //----------------------------------------------------------------------- // // "As with void*, programmers should know that unions [...] are @@ -3016,7 +3096,7 @@ auto flag_enum(meta::type_declaration& t) -> void // a type that contains exactly one of a fixed set of values at a time // -#line 1396 "reflect.h2" +#line 1472 "reflect.h2" auto cpp2_union(meta::type_declaration& t) -> void { std::vector alternatives {}; @@ -3025,7 +3105,7 @@ auto value{0}; // 1. Gather: All the user-written members, and find/compute the max size -#line 1403 "reflect.h2" +#line 1479 "reflect.h2" for ( auto const& m : CPP2_UFCS(get_members)(t) ) { do @@ -3055,7 +3135,7 @@ auto value{0}; } while (false); ++value; } } -#line 1431 "reflect.h2" +#line 1507 "reflect.h2" std::string discriminator_type {}; if (cpp2::impl::cmp_less(CPP2_UFCS(ssize)(alternatives),std::numeric_limits::max())) { discriminator_type = "i8"; @@ -3070,7 +3150,7 @@ auto value{0}; discriminator_type = "i64"; }}} -#line 1446 "reflect.h2" +#line 1522 "reflect.h2" // 2. Replace: Erase the contents and replace with modified contents CPP2_UFCS(remove_marked_members)(t); @@ -3079,7 +3159,7 @@ std::string storage{" _storage: cpp2::aligned_storage t) -> void { std::cout << CPP2_UFCS(print)(t) << "\n"; } -#line 1552 "reflect.h2" +#line 1628 "reflect.h2" auto print(cpp2::impl::in f) -> void { std::cout << CPP2_UFCS(print)(f) << "\n"; } -#line 1558 "reflect.h2" +#line 1634 "reflect.h2" //----------------------------------------------------------------------- // // meta - mark f as a metafunction and generate registration code for it // -#line 1562 "reflect.h2" +#line 1638 "reflect.h2" auto meta(meta::function_declaration& f) -> void { // TODO(DyXel): Check that the function: @@ -3311,7 +3391,7 @@ return none; [[nodiscard]] auto expression_flags::from_code(cpp2::impl::in s) -> expression_flags{ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::move(str), "expression_flags::", "")); } -#line 1578 "reflect.h2" +#line 1654 "reflect.h2" //----------------------------------------------------------------------- // // regex - creates regular expressions from members @@ -3327,11 +3407,11 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov // ``` // -#line 1594 "reflect.h2" +#line 1670 "reflect.h2" // Possible modifiers for a regular expression. // -#line 1598 "reflect.h2" +#line 1674 "reflect.h2" // mod: i // mod: m // mod: s @@ -3339,106 +3419,106 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov // mod: x // mod: xx -#line 1607 "reflect.h2" +#line 1683 "reflect.h2" // Tokens for regular expressions. // // Basic class for a regex token. // -#line 1616 "reflect.h2" +#line 1692 "reflect.h2" regex_token::regex_token(cpp2::impl::in str) : string_rep{ str }{ -#line 1618 "reflect.h2" +#line 1694 "reflect.h2" } -#line 1620 "reflect.h2" +#line 1696 "reflect.h2" regex_token::regex_token() : string_rep{ "" }{ -#line 1622 "reflect.h2" +#line 1698 "reflect.h2" } //parse: (inout ctx: parse_context) -> token_ptr; // Generate the matching code. -#line 1627 "reflect.h2" +#line 1703 "reflect.h2" auto regex_token::add_groups([[maybe_unused]] std::set& unnamed_param_2) const -> void{}// Adds all group indices to the set. -#line 1628 "reflect.h2" +#line 1704 "reflect.h2" [[nodiscard]] auto regex_token::to_string() const& -> std::string{return string_rep; }// Create a string representation. -#line 1629 "reflect.h2" +#line 1705 "reflect.h2" auto regex_token::set_string(cpp2::impl::in s) & -> void{string_rep = s; } regex_token::~regex_token() noexcept{}// Set the string representation. -#line 1644 "reflect.h2" +#line 1720 "reflect.h2" regex_token_check::regex_token_check(cpp2::impl::in str, cpp2::impl::in check_) : regex_token{ str } , check{ check_ }{ -#line 1647 "reflect.h2" +#line 1723 "reflect.h2" } -#line 1649 "reflect.h2" +#line 1725 "reflect.h2" auto regex_token_check::generate_code(generation_context& ctx) const -> void{ ctx.add_check(check + "(" + ctx.match_parameters() + ")"); } regex_token_check::~regex_token_check() noexcept{} -#line 1663 "reflect.h2" +#line 1739 "reflect.h2" regex_token_code::regex_token_code(cpp2::impl::in str, cpp2::impl::in code_) : regex_token{ str } , code{ code_ }{ -#line 1666 "reflect.h2" +#line 1742 "reflect.h2" } -#line 1668 "reflect.h2" +#line 1744 "reflect.h2" auto regex_token_code::generate_code(generation_context& ctx) const -> void{ ctx.add(code); } regex_token_code::~regex_token_code() noexcept{} -#line 1680 "reflect.h2" +#line 1756 "reflect.h2" regex_token_empty::regex_token_empty(cpp2::impl::in str) : regex_token{ str }{ -#line 1682 "reflect.h2" +#line 1758 "reflect.h2" } -#line 1684 "reflect.h2" +#line 1760 "reflect.h2" auto regex_token_empty::generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void{ // Nothing. } regex_token_empty::~regex_token_empty() noexcept{} -#line 1698 "reflect.h2" +#line 1774 "reflect.h2" regex_token_list::regex_token_list(cpp2::impl::in t) : regex_token{ gen_string(t) } , tokens{ t }{ -#line 1701 "reflect.h2" +#line 1777 "reflect.h2" } -#line 1703 "reflect.h2" +#line 1779 "reflect.h2" auto regex_token_list::generate_code(generation_context& ctx) const -> void{ for ( auto const& token : tokens ) { (*cpp2::impl::assert_not_null(token)).generate_code(ctx); } } -#line 1709 "reflect.h2" +#line 1785 "reflect.h2" auto regex_token_list::add_groups(std::set& groups) const -> void{ for ( auto const& token : tokens ) { (*cpp2::impl::assert_not_null(token)).add_groups(groups); } } -#line 1715 "reflect.h2" +#line 1791 "reflect.h2" [[nodiscard]] auto regex_token_list::gen_string(cpp2::impl::in vec) -> std::string{ std::string r {""}; for ( auto const& token : vec ) { @@ -3449,7 +3529,7 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov regex_token_list::~regex_token_list() noexcept{} -#line 1738 "reflect.h2" +#line 1814 "reflect.h2" auto parse_context_group_state::next_alternative() & -> void{ token_vec new_list {}; std::swap(new_list, cur_match_list); @@ -3457,14 +3537,14 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov static_cast(alternate_match_lists.insert(alternate_match_lists.end(), CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, cpp2::move(new_list)))); } -#line 1746 "reflect.h2" +#line 1822 "reflect.h2" auto parse_context_group_state::swap(parse_context_group_state& t) & -> void{ std::swap(cur_match_list, t.cur_match_list); std::swap(alternate_match_lists, t.alternate_match_lists); std::swap(modifiers, t.modifiers); } -#line 1753 "reflect.h2" +#line 1829 "reflect.h2" [[nodiscard]] auto parse_context_group_state::get_as_token() & -> token_ptr{ if (alternate_match_lists.empty()) { post_process_list(cur_match_list); @@ -3476,15 +3556,15 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov } } -#line 1765 "reflect.h2" +#line 1841 "reflect.h2" auto parse_context_group_state::add(cpp2::impl::in token) & -> void{ cur_match_list.push_back(token); } -#line 1770 "reflect.h2" +#line 1846 "reflect.h2" [[nodiscard]] auto parse_context_group_state::empty() const& -> bool { return cur_match_list.empty(); } -#line 1774 "reflect.h2" +#line 1850 "reflect.h2" auto parse_context_group_state::post_process_list(token_vec& list) -> void{ // Merge all characters auto merge_pos {list.begin()}; @@ -3505,7 +3585,7 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov , modifiers{ modifiers_ }{} parse_context_group_state::parse_context_group_state(){} -#line 1800 "reflect.h2" +#line 1876 "reflect.h2" [[nodiscard]] auto parse_context_branch_reset_state::next() & -> int{ auto g {cur_group}; cur_group += 1; @@ -3514,20 +3594,20 @@ parse_context_group_state::parse_context_group_state(){} return g; } -#line 1809 "reflect.h2" +#line 1885 "reflect.h2" auto parse_context_branch_reset_state::set_next(cpp2::impl::in g) & -> void{ cur_group = g; max_group = max(max_group, g); } -#line 1815 "reflect.h2" +#line 1891 "reflect.h2" auto parse_context_branch_reset_state::next_alternative() & -> void{ if (is_active) { cur_group = from; } } -#line 1822 "reflect.h2" +#line 1898 "reflect.h2" auto parse_context_branch_reset_state::set_active_reset(cpp2::impl::in restart) & -> void{ is_active = true; cur_group = restart; @@ -3542,16 +3622,16 @@ parse_context_group_state::parse_context_group_state(){} , from{ from_ }{} parse_context_branch_reset_state::parse_context_branch_reset_state(){} -#line 1850 "reflect.h2" +#line 1926 "reflect.h2" parse_context::parse_context(cpp2::impl::in r, auto const& e) : regex{ r } , root{ CPP2_UFCS_TEMPLATE_NONLOCAL(cpp2_new)(cpp2::shared, "") } , error_out{ e }{ -#line 1854 "reflect.h2" +#line 1930 "reflect.h2" } -#line 1860 "reflect.h2" +#line 1936 "reflect.h2" [[nodiscard]] auto parse_context::start_group() & -> parse_context_group_state { parse_context_group_state old_state {}; @@ -3561,7 +3641,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return old_state; } -#line 1870 "reflect.h2" +#line 1946 "reflect.h2" [[nodiscard]] auto parse_context::end_group(cpp2::impl::in old_state) & -> token_ptr { auto inner {cur_group_state.get_as_token()}; @@ -3569,17 +3649,17 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return inner; } -#line 1877 "reflect.h2" +#line 1953 "reflect.h2" [[nodiscard]] auto parse_context::get_modifiers() const& -> expression_flags{ return cur_group_state.modifiers; } -#line 1881 "reflect.h2" +#line 1957 "reflect.h2" auto parse_context::set_modifiers(cpp2::impl::in mod) & -> void{ cur_group_state.modifiers = mod; } -#line 1888 "reflect.h2" +#line 1964 "reflect.h2" [[nodiscard]] auto parse_context::branch_reset_new_state() & -> parse_context_branch_reset_state { parse_context_branch_reset_state old_state {}; @@ -3589,7 +3669,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return old_state; } -#line 1897 "reflect.h2" +#line 1973 "reflect.h2" auto parse_context::branch_reset_restore_state(cpp2::impl::in old_state) & -> void { auto max_group {cur_branch_reset_state.max_group}; @@ -3597,24 +3677,24 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} cur_branch_reset_state.set_next(cpp2::move(max_group)); } -#line 1904 "reflect.h2" +#line 1980 "reflect.h2" auto parse_context::next_alternative() & -> void { cur_group_state.next_alternative(); cur_branch_reset_state.next_alternative(); } -#line 1912 "reflect.h2" +#line 1988 "reflect.h2" auto parse_context::add_token(cpp2::impl::in token) & -> void{ cur_group_state.add(token); } -#line 1916 "reflect.h2" +#line 1992 "reflect.h2" [[nodiscard]] auto parse_context::has_token() const& -> bool{ return !(cur_group_state.empty()); } -#line 1920 "reflect.h2" +#line 1996 "reflect.h2" [[nodiscard]] auto parse_context::pop_token() & -> token_ptr { token_ptr r {nullptr}; @@ -3626,22 +3706,22 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 1931 "reflect.h2" +#line 2007 "reflect.h2" [[nodiscard]] auto parse_context::get_as_token() & -> token_ptr{ return root; } -#line 1937 "reflect.h2" +#line 2013 "reflect.h2" [[nodiscard]] auto parse_context::get_cur_group() const& -> int{ return cur_branch_reset_state.cur_group; } -#line 1941 "reflect.h2" +#line 2017 "reflect.h2" [[nodiscard]] auto parse_context::next_group() & -> int{ return cur_branch_reset_state.next(); } -#line 1945 "reflect.h2" +#line 2021 "reflect.h2" auto parse_context::set_named_group(cpp2::impl::in name, cpp2::impl::in id) & -> void { if (!(named_groups.contains(name))) {// Redefinition of group name is not an error. The left most one is retained. @@ -3649,7 +3729,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 1952 "reflect.h2" +#line 2028 "reflect.h2" [[nodiscard]] auto parse_context::get_named_group(cpp2::impl::in name) const& -> int { auto iter {named_groups.find(name)}; @@ -3661,10 +3741,10 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 1965 "reflect.h2" +#line 2041 "reflect.h2" [[nodiscard]] auto parse_context::current() const& -> char{return CPP2_ASSERT_IN_BOUNDS(regex, pos); } -#line 1968 "reflect.h2" +#line 2044 "reflect.h2" [[nodiscard]] auto parse_context::get_next_position(cpp2::impl::in in_class, cpp2::impl::in no_skip) const& -> size_t { auto perl_syntax {false}; @@ -3704,7 +3784,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return cur; } -#line 2008 "reflect.h2" +#line 2084 "reflect.h2" [[nodiscard]] auto parse_context::next_impl(cpp2::impl::in in_class, cpp2::impl::in no_skip) & -> bool { pos = get_next_position(in_class, no_skip); @@ -3716,14 +3796,14 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2019 "reflect.h2" +#line 2095 "reflect.h2" [[nodiscard]] auto parse_context::next() & -> auto { return next_impl(false, false); } -#line 2020 "reflect.h2" +#line 2096 "reflect.h2" [[nodiscard]] auto parse_context::next_in_class() & -> auto { return next_impl(true, false); } -#line 2021 "reflect.h2" +#line 2097 "reflect.h2" [[nodiscard]] auto parse_context::next_no_skip() & -> auto { return next_impl(false, true); } -#line 2023 "reflect.h2" +#line 2099 "reflect.h2" [[nodiscard]] auto parse_context::next_n(cpp2::impl::in n) & -> bool{ auto r {true}; auto cur {0}; @@ -3733,10 +3813,10 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 2032 "reflect.h2" +#line 2108 "reflect.h2" [[nodiscard]] auto parse_context::has_next() const& -> bool{return cpp2::impl::cmp_less(pos,regex.size()); } -#line 2034 "reflect.h2" +#line 2110 "reflect.h2" [[nodiscard]] auto parse_context::grab_until_impl(cpp2::impl::in e, cpp2::impl::out r, cpp2::impl::in any) & -> bool { auto end {pos}; @@ -3758,14 +3838,14 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2055 "reflect.h2" +#line 2131 "reflect.h2" [[nodiscard]] auto parse_context::grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(e, cpp2::impl::out(&r), false); } -#line 2056 "reflect.h2" +#line 2132 "reflect.h2" [[nodiscard]] auto parse_context::grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(std::string(1, e), cpp2::impl::out(&r), false); } -#line 2057 "reflect.h2" +#line 2133 "reflect.h2" [[nodiscard]] auto parse_context::grab_until_one_of(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(e, cpp2::impl::out(&r), true); } -#line 2059 "reflect.h2" +#line 2135 "reflect.h2" [[nodiscard]] auto parse_context::grab_n(cpp2::impl::in n, cpp2::impl::out r) & -> bool { if (cpp2::impl::cmp_less_eq(pos + cpp2::impl::as_(n),regex.size())) { @@ -3779,7 +3859,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2072 "reflect.h2" +#line 2148 "reflect.h2" [[nodiscard]] auto parse_context::grab_number() & -> std::string { auto start {pos}; @@ -3801,7 +3881,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return cpp2::move(r.value()); } -#line 2093 "reflect.h2" +#line 2169 "reflect.h2" [[nodiscard]] auto parse_context::peek_impl(cpp2::impl::in in_class) const& -> char{ auto next_pos {get_next_position(in_class, false)}; if (cpp2::impl::cmp_less(next_pos,regex.size())) { @@ -3812,12 +3892,12 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2103 "reflect.h2" +#line 2179 "reflect.h2" [[nodiscard]] auto parse_context::peek() const& -> auto { return peek_impl(false); } -#line 2104 "reflect.h2" +#line 2180 "reflect.h2" [[nodiscard]] auto parse_context::peek_in_class() const& -> auto { return peek_impl(true); } -#line 2109 "reflect.h2" +#line 2185 "reflect.h2" [[nodiscard]] auto parse_context::parser_group_modifiers(cpp2::impl::in change_str, expression_flags& parser_modifiers) & -> bool { auto is_negative {false}; @@ -3872,7 +3952,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return true; } -#line 2163 "reflect.h2" +#line 2239 "reflect.h2" [[nodiscard]] auto parse_context::parse_until(cpp2::impl::in term) & -> bool{ token_ptr cur_token {}; @@ -3911,7 +3991,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return true; } -#line 2201 "reflect.h2" +#line 2277 "reflect.h2" [[nodiscard]] auto parse_context::parse(cpp2::impl::in modifiers) & -> bool { @@ -3927,21 +4007,21 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 2218 "reflect.h2" +#line 2294 "reflect.h2" [[nodiscard]] auto parse_context::get_pos() const& -> auto { return pos; } -#line 2219 "reflect.h2" +#line 2295 "reflect.h2" [[nodiscard]] auto parse_context::get_range(cpp2::impl::in start, cpp2::impl::in end) const& -> auto { return std::string(regex.substr(start, end - start + 1)); } -#line 2220 "reflect.h2" +#line 2296 "reflect.h2" [[nodiscard]] auto parse_context::valid() const& -> bool{return has_next() && !(has_error); } -#line 2222 "reflect.h2" +#line 2298 "reflect.h2" [[nodiscard]] auto parse_context::error(cpp2::impl::in err) & -> token_ptr{ has_error = true; error_out("Error during parsing of regex '" + cpp2::to_string(regex) + "' at position '" + cpp2::to_string(pos) + "': " + cpp2::to_string(err) + ""); return nullptr; } -#line 2237 "reflect.h2" +#line 2313 "reflect.h2" auto generation_function_context::add_tabs(cpp2::impl::in c) & -> void{ int i {0}; for( ; cpp2::impl::cmp_less(i,c); i += 1 ) { @@ -3949,7 +4029,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2244 "reflect.h2" +#line 2320 "reflect.h2" auto generation_function_context::remove_tabs(cpp2::impl::in c) & -> void{ tabs = tabs.substr(0, (cpp2::impl::as_(c)) * 2); } @@ -3959,22 +4039,22 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} , tabs{ tabs_ }{} generation_function_context::generation_function_context(){} -#line 2262 "reflect.h2" +#line 2338 "reflect.h2" [[nodiscard]] auto generation_context::match_parameters() const& -> std::string{return "r.pos, ctx"; } -#line 2267 "reflect.h2" +#line 2343 "reflect.h2" auto generation_context::add(cpp2::impl::in s) & -> void{ auto cur {get_current()}; (*cpp2::impl::assert_not_null(cur)).code += "" + cpp2::to_string((*cpp2::impl::assert_not_null(cur)).tabs) + cpp2::to_string(s) + "\n"; } -#line 2273 "reflect.h2" +#line 2349 "reflect.h2" auto generation_context::add_check(cpp2::impl::in check) & -> void{ auto cur {get_current()}; (*cpp2::impl::assert_not_null(cur)).code += "" + cpp2::to_string((*cpp2::impl::assert_not_null(cur)).tabs) + "if !cpp2::regex::" + cpp2::to_string(check) + " { r.matched = false; break; }\n"; } -#line 2279 "reflect.h2" +#line 2355 "reflect.h2" auto generation_context::add_statefull(cpp2::impl::in next_func, cpp2::impl::in check) & -> void { end_func_statefull(check); @@ -3983,7 +4063,7 @@ generation_function_context::generation_function_context(){} start_func_named(cpp2::move(name)); } -#line 2287 "reflect.h2" +#line 2363 "reflect.h2" auto generation_context::start_func_named(cpp2::impl::in name) & -> void { auto cur {new_context()}; @@ -3995,7 +4075,7 @@ generation_function_context::generation_function_context(){} (*cpp2::impl::assert_not_null(cpp2::move(cur))).add_tabs(3); } -#line 2298 "reflect.h2" +#line 2374 "reflect.h2" [[nodiscard]] auto generation_context::start_func() & -> std::string { auto name {gen_func_name()}; @@ -4003,7 +4083,7 @@ generation_function_context::generation_function_context(){} return cpp2::move(name) + "()"; } -#line 2305 "reflect.h2" +#line 2381 "reflect.h2" auto generation_context::end_func_statefull(cpp2::impl::in s) & -> void { auto cur {get_current()}; @@ -4023,7 +4103,7 @@ generation_function_context::generation_function_context(){} finish_context(); } -#line 2325 "reflect.h2" +#line 2401 "reflect.h2" [[nodiscard]] auto generation_context::generate_func(cpp2::impl::in token) & -> std::string { auto name {start_func()}; @@ -4033,7 +4113,7 @@ generation_function_context::generation_function_context(){} return name; } -#line 2335 "reflect.h2" +#line 2411 "reflect.h2" [[nodiscard]] auto generation_context::generate_reset(cpp2::impl::in> groups) & -> std::string { if (groups.empty()) { @@ -4056,33 +4136,33 @@ generation_function_context::generation_function_context(){} return cpp2::move(name) + "()"; } -#line 2359 "reflect.h2" +#line 2435 "reflect.h2" [[nodiscard]] auto generation_context::gen_func_name() & -> std::string{ auto cur_id {matcher_func}; matcher_func += 1; return "func_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2365 "reflect.h2" +#line 2441 "reflect.h2" [[nodiscard]] auto generation_context::next_func_name() & -> std::string{ return gen_func_name() + "()"; } -#line 2369 "reflect.h2" +#line 2445 "reflect.h2" [[nodiscard]] auto generation_context::gen_reset_func_name() & -> std::string{ auto cur_id {reset_func}; reset_func += 1; return "reset_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2375 "reflect.h2" +#line 2451 "reflect.h2" [[nodiscard]] auto generation_context::gen_temp() & -> std::string{ auto cur_id {temp_name}; temp_name += 1; return "tmp_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2383 "reflect.h2" +#line 2459 "reflect.h2" [[nodiscard]] auto generation_context::new_context() & -> generation_function_context*{ gen_stack.push_back(generation_function_context()); auto cur {get_current()}; @@ -4091,7 +4171,7 @@ generation_function_context::generation_function_context(){} return cur; } -#line 2391 "reflect.h2" +#line 2467 "reflect.h2" auto generation_context::finish_context() & -> void{ auto cur {get_current()}; auto base {get_base()}; @@ -4100,22 +4180,22 @@ generation_function_context::generation_function_context(){} gen_stack.pop_back(); } -#line 2401 "reflect.h2" +#line 2477 "reflect.h2" [[nodiscard]] auto generation_context::get_current() & -> generation_function_context*{ return &gen_stack.back(); } -#line 2405 "reflect.h2" +#line 2481 "reflect.h2" [[nodiscard]] auto generation_context::get_base() & -> generation_function_context*{ return &CPP2_ASSERT_IN_BOUNDS_LITERAL(gen_stack, 0); } -#line 2409 "reflect.h2" +#line 2485 "reflect.h2" [[nodiscard]] auto generation_context::get_entry_func() const& -> std::string{ return entry_func; } -#line 2413 "reflect.h2" +#line 2489 "reflect.h2" [[nodiscard]] auto generation_context::create_named_group_lookup(cpp2::impl::in> named_groups) const& -> std::string { std::string res {"get_named_group_index: (name) -> int = {\n"}; @@ -4139,18 +4219,18 @@ generation_function_context::generation_function_context(){} return res; } -#line 2438 "reflect.h2" +#line 2514 "reflect.h2" [[nodiscard]] auto generation_context::run(cpp2::impl::in token) & -> std::string{ entry_func = generate_func(token); return (*cpp2::impl::assert_not_null(get_base())).code; } -#line 2453 "reflect.h2" +#line 2529 "reflect.h2" alternative_token::alternative_token() : regex_token_empty{ "" }{} -#line 2455 "reflect.h2" +#line 2531 "reflect.h2" [[nodiscard]] auto alternative_token::parse(parse_context& ctx) -> token_ptr{ if (ctx.current() != '|') {return nullptr; } @@ -4161,15 +4241,15 @@ generation_function_context::generation_function_context(){} alternative_token::~alternative_token() noexcept{} -#line 2470 "reflect.h2" +#line 2546 "reflect.h2" alternative_token_gen::alternative_token_gen(cpp2::impl::in a) : regex_token{ gen_string(a) } , alternatives{ a }{ -#line 2473 "reflect.h2" +#line 2549 "reflect.h2" } -#line 2475 "reflect.h2" +#line 2551 "reflect.h2" auto alternative_token_gen::generate_code(generation_context& ctx) const -> void { std::string functions {""}; @@ -4187,7 +4267,7 @@ generation_function_context::generation_function_context(){} ctx.add_statefull(next_name, "cpp2::regex::alternative_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ", other, " + cpp2::to_string(next_name) + " " + cpp2::to_string(cpp2::move(functions)) + ")"); } -#line 2492 "reflect.h2" +#line 2568 "reflect.h2" auto alternative_token_gen::add_groups(std::set& groups) const -> void { for ( auto const& cur : alternatives ) { @@ -4195,7 +4275,7 @@ generation_function_context::generation_function_context(){} } } -#line 2499 "reflect.h2" +#line 2575 "reflect.h2" [[nodiscard]] auto alternative_token_gen::gen_string(cpp2::impl::in a) -> std::string { std::string r {""}; @@ -4211,14 +4291,14 @@ generation_function_context::generation_function_context(){} alternative_token_gen::~alternative_token_gen() noexcept{} -#line 2520 "reflect.h2" +#line 2596 "reflect.h2" any_token::any_token(cpp2::impl::in single_line) : regex_token_check{ ".", "any_token_matcher" }{ -#line 2522 "reflect.h2" +#line 2598 "reflect.h2" } -#line 2524 "reflect.h2" +#line 2600 "reflect.h2" [[nodiscard]] auto any_token::parse(parse_context& ctx) -> token_ptr{ if ('.' != ctx.current()) {return nullptr; } @@ -4227,21 +4307,21 @@ generation_function_context::generation_function_context(){} any_token::~any_token() noexcept{} -#line 2541 "reflect.h2" +#line 2617 "reflect.h2" char_token::char_token(cpp2::impl::in t, cpp2::impl::in ignore_case_) : regex_token{ std::string(1, t) } , token{ t } , ignore_case{ ignore_case_ }{ -#line 2545 "reflect.h2" +#line 2621 "reflect.h2" } -#line 2547 "reflect.h2" +#line 2623 "reflect.h2" [[nodiscard]] auto char_token::parse(parse_context& ctx) -> token_ptr{ return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, ctx.current(), ctx.get_modifiers().has(expression_flags::case_insensitive)); } -#line 2551 "reflect.h2" +#line 2627 "reflect.h2" auto char_token::generate_code(generation_context& ctx) const -> void { if (ignore_case) { @@ -4250,14 +4330,14 @@ generation_function_context::generation_function_context(){} { size_t i{0}; -#line 2557 "reflect.h2" +#line 2633 "reflect.h2" for( ; cpp2::impl::cmp_less(i,token.size()); i += 1 ) { CPP2_ASSERT_IN_BOUNDS(lower, i) = string_util::safe_tolower(CPP2_ASSERT_IN_BOUNDS(token, i)); CPP2_ASSERT_IN_BOUNDS(upper, i) = string_util::safe_toupper(CPP2_ASSERT_IN_BOUNDS(token, i)); } } -#line 2562 "reflect.h2" +#line 2638 "reflect.h2" if (upper != lower) { gen_case_insensitive(cpp2::move(lower), cpp2::move(upper), ctx); } @@ -4270,7 +4350,7 @@ size_t i{0}; } } -#line 2574 "reflect.h2" +#line 2650 "reflect.h2" auto char_token::gen_case_insensitive(cpp2::impl::in lower, cpp2::impl::in upper, generation_context& ctx) const& -> void { std::string name {"str_" + cpp2::to_string(ctx.gen_temp()) + ""}; @@ -4292,7 +4372,7 @@ size_t i{0}; ctx.add("else { break; }"); } -#line 2595 "reflect.h2" +#line 2671 "reflect.h2" auto char_token::gen_case_sensitive(generation_context& ctx) const& -> void { std::string name {"str_" + cpp2::to_string(ctx.gen_temp()) + ""}; @@ -4311,7 +4391,7 @@ size_t i{0}; ctx.add("else { break; }"); } -#line 2613 "reflect.h2" +#line 2689 "reflect.h2" [[nodiscard]] auto char_token::add_escapes(std::string str) const& -> std::string { str = string_util::replace_all(str, "\\", "\\\\"); @@ -4327,7 +4407,7 @@ size_t i{0}; return cpp2::move(str); } -#line 2628 "reflect.h2" +#line 2704 "reflect.h2" auto char_token::append(char_token const& that) & -> void{ (*this).token += that.token; (*this).string_rep += that.string_rep; @@ -4335,19 +4415,19 @@ size_t i{0}; char_token::~char_token() noexcept{} -#line 2645 "reflect.h2" +#line 2721 "reflect.h2" class_token::class_token(cpp2::impl::in negate_, cpp2::impl::in case_insensitive_, cpp2::impl::in class_str_, cpp2::impl::in str) : regex_token{ str } , negate{ negate_ } , case_insensitive{ case_insensitive_ } , class_str{ class_str_ } -#line 2646 "reflect.h2" +#line 2722 "reflect.h2" { -#line 2651 "reflect.h2" +#line 2727 "reflect.h2" } -#line 2654 "reflect.h2" +#line 2730 "reflect.h2" [[nodiscard]] auto class_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '[') {return nullptr; } @@ -4473,13 +4553,13 @@ size_t i{0}; ); } -#line 2779 "reflect.h2" +#line 2855 "reflect.h2" auto class_token::generate_code(generation_context& ctx) const -> void { ctx.add_check("class_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ")"); } -#line 2784 "reflect.h2" +#line 2860 "reflect.h2" [[nodiscard]] auto class_token::create_matcher(cpp2::impl::in name, cpp2::impl::in template_arguments) -> std::string { auto sep {", "}; @@ -4490,12 +4570,12 @@ size_t i{0}; class_token::~class_token() noexcept{} -#line 2796 "reflect.h2" +#line 2872 "reflect.h2" [[nodiscard]] auto escape_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } -#line 2801 "reflect.h2" +#line 2877 "reflect.h2" if (std::string::npos == std::string("afenrt^.[]()*{}?+|\\").find(ctx.peek())) { return nullptr; } @@ -4529,7 +4609,7 @@ size_t i{0}; } -#line 2837 "reflect.h2" +#line 2913 "reflect.h2" [[nodiscard]] auto global_group_reset_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'K'))) {return nullptr; } @@ -4538,18 +4618,18 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, "\\K", "ctx..set_group_start(0, r.pos);"); } -#line 2859 "reflect.h2" +#line 2935 "reflect.h2" group_ref_token::group_ref_token(cpp2::impl::in id_, cpp2::impl::in case_insensitive_, cpp2::impl::in str) : regex_token{ str } , id{ id_ } , case_insensitive{ case_insensitive_ } -#line 2860 "reflect.h2" +#line 2936 "reflect.h2" { -#line 2864 "reflect.h2" +#line 2940 "reflect.h2" } -#line 2866 "reflect.h2" +#line 2942 "reflect.h2" [[nodiscard]] auto group_ref_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -4651,14 +4731,14 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, cpp2::move(group_id), ctx.get_modifiers().has(expression_flags::case_insensitive), cpp2::move(str)); } -#line 2967 "reflect.h2" +#line 3043 "reflect.h2" auto group_ref_token::generate_code(generation_context& ctx) const -> void{ ctx.add_check("group_ref_token_matcher(" + cpp2::to_string(ctx.match_parameters()) + ")"); } group_ref_token::~group_ref_token() noexcept{} -#line 2990 "reflect.h2" +#line 3066 "reflect.h2" [[nodiscard]] auto group_token::parse_lookahead(parse_context& ctx, cpp2::impl::in syntax, cpp2::impl::in positive) -> token_ptr { static_cast(ctx.next());// Skip last token defining the syntax @@ -4673,7 +4753,7 @@ size_t i{0}; return r; } -#line 3004 "reflect.h2" +#line 3080 "reflect.h2" [[nodiscard]] auto group_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '(') {return nullptr; } @@ -4811,7 +4891,7 @@ size_t i{0}; } } -#line 3141 "reflect.h2" +#line 3217 "reflect.h2" [[nodiscard]] auto group_token::gen_string(cpp2::impl::in name, cpp2::impl::in name_brackets, cpp2::impl::in has_modifier, cpp2::impl::in modifiers, cpp2::impl::in inner_) -> std::string { std::string start {"("}; @@ -4830,7 +4910,7 @@ size_t i{0}; return cpp2::move(start) + (*cpp2::impl::assert_not_null(inner_)).to_string() + ")"; } -#line 3159 "reflect.h2" +#line 3235 "reflect.h2" auto group_token::generate_code(generation_context& ctx) const -> void { if (-1 != number) { @@ -4851,7 +4931,7 @@ size_t i{0}; } } -#line 3179 "reflect.h2" +#line 3255 "reflect.h2" auto group_token::add_groups(std::set& groups) const -> void { (*cpp2::impl::assert_not_null(inner)).add_groups(groups); @@ -4862,7 +4942,7 @@ size_t i{0}; group_token::~group_token() noexcept{} -#line 3191 "reflect.h2" +#line 3267 "reflect.h2" [[nodiscard]] auto hexadecimal_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'x'))) {return nullptr; } @@ -4901,7 +4981,7 @@ size_t i{0}; return r; } -#line 3232 "reflect.h2" +#line 3308 "reflect.h2" [[nodiscard]] auto line_end_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() == '$' || (ctx.current() == '\\' && ctx.peek() == '$')) { @@ -4919,7 +4999,7 @@ size_t i{0}; }} } -#line 3252 "reflect.h2" +#line 3328 "reflect.h2" [[nodiscard]] auto line_start_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '^' && !((ctx.current() == '\\' && ctx.peek() == 'A'))) {return nullptr; } @@ -4933,29 +5013,29 @@ size_t i{0}; } } -#line 3277 "reflect.h2" +#line 3353 "reflect.h2" lookahead_token::lookahead_token(cpp2::impl::in positive_) : regex_token{ "" } , positive{ positive_ }{ -#line 3279 "reflect.h2" +#line 3355 "reflect.h2" } -#line 3281 "reflect.h2" +#line 3357 "reflect.h2" auto lookahead_token::generate_code(generation_context& ctx) const -> void{ auto inner_name {ctx.generate_func(inner)}; ctx.add_check("lookahead_token_matcher(" + cpp2::to_string(ctx.match_parameters()) + ", " + cpp2::to_string(cpp2::move(inner_name)) + ")"); } -#line 3287 "reflect.h2" +#line 3363 "reflect.h2" auto lookahead_token::add_groups(std::set& groups) const -> void{ (*cpp2::impl::assert_not_null(inner)).add_groups(groups); } lookahead_token::~lookahead_token() noexcept{} -#line 3295 "reflect.h2" +#line 3371 "reflect.h2" [[nodiscard]] auto named_class_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -4981,7 +5061,7 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, "\\" + cpp2::to_string(ctx.current()) + "", "" + cpp2::to_string(cpp2::move(name)) + "::match"); } -#line 3323 "reflect.h2" +#line 3399 "reflect.h2" [[nodiscard]] auto octal_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'o'))) {return nullptr; } @@ -5007,11 +5087,11 @@ size_t i{0}; return r; } -#line 3360 "reflect.h2" +#line 3436 "reflect.h2" range_token::range_token() : regex_token{ "" }{} -#line 3362 "reflect.h2" +#line 3438 "reflect.h2" [[nodiscard]] auto range_token::parse(parse_context& ctx) -> token_ptr { auto r {CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared)}; @@ -5085,7 +5165,7 @@ size_t i{0}; return nullptr; } -#line 3435 "reflect.h2" +#line 3511 "reflect.h2" auto range_token::parse_modifier(parse_context& ctx) & -> void { if (ctx.peek() == '?') { @@ -5098,7 +5178,7 @@ size_t i{0}; }} } -#line 3447 "reflect.h2" +#line 3523 "reflect.h2" [[nodiscard]] auto range_token::gen_mod_string() const& -> std::string { if (kind == range_flags::not_greedy) { @@ -5112,7 +5192,7 @@ size_t i{0}; }} } -#line 3460 "reflect.h2" +#line 3536 "reflect.h2" [[nodiscard]] auto range_token::gen_range_string() const& -> std::string { std::string r {""}; @@ -5132,7 +5212,7 @@ size_t i{0}; return r; } -#line 3479 "reflect.h2" +#line 3555 "reflect.h2" auto range_token::generate_code(generation_context& ctx) const -> void { auto inner_name {ctx.generate_func(inner_token)}; @@ -5144,14 +5224,14 @@ size_t i{0}; ctx.add_statefull(next_name, "cpp2::regex::range_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ", " + cpp2::to_string(cpp2::move(inner_name)) + ", " + cpp2::to_string(cpp2::move(reset_name)) + ", other, " + cpp2::to_string(next_name) + ")"); } -#line 3490 "reflect.h2" +#line 3566 "reflect.h2" auto range_token::add_groups(std::set& groups) const -> void{ (*cpp2::impl::assert_not_null(inner_token)).add_groups(groups); } range_token::~range_token() noexcept{} -#line 3503 "reflect.h2" +#line 3579 "reflect.h2" [[nodiscard]] auto special_range_token::parse(parse_context& ctx) -> token_ptr { auto r {CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared)}; @@ -5175,7 +5255,7 @@ size_t i{0}; if (!(ctx.has_token())) {return ctx.error("'" + cpp2::to_string(ctx.current()) + "' without previous element."); } -#line 3527 "reflect.h2" +#line 3603 "reflect.h2" (*cpp2::impl::assert_not_null(r)).parse_modifier(ctx); (*cpp2::impl::assert_not_null(r)).inner_token = ctx.pop_token(); @@ -5185,7 +5265,7 @@ size_t i{0}; special_range_token::~special_range_token() noexcept{} -#line 3540 "reflect.h2" +#line 3616 "reflect.h2" [[nodiscard]] auto word_boundary_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -5203,15 +5283,15 @@ size_t i{0}; }} } -#line 3576 "reflect.h2" +#line 3652 "reflect.h2" template regex_generator::regex_generator(cpp2::impl::in r, Error_out const& e) : regex{ r } , error_out{ e }{ -#line 3579 "reflect.h2" +#line 3655 "reflect.h2" } -#line 3581 "reflect.h2" +#line 3657 "reflect.h2" template [[nodiscard]] auto regex_generator::parse() & -> std::string { // Extract modifiers and adapt regex. @@ -5247,7 +5327,7 @@ size_t i{0}; return source; } -#line 3616 "reflect.h2" +#line 3692 "reflect.h2" template auto regex_generator::extract_modifiers() & -> void { if (regex.find_first_of("'/") == 0) { @@ -5263,7 +5343,7 @@ size_t i{0}; } } -#line 3632 "reflect.h2" +#line 3708 "reflect.h2" template [[nodiscard]] auto generate_regex(cpp2::impl::in regex, Err const& err) -> std::string { regex_generator parser {regex, err}; @@ -5272,7 +5352,7 @@ template [[nodiscard]] auto generate_regex(cpp2::impl::in void { auto has_default {false}; @@ -5327,7 +5407,7 @@ auto regex_gen(meta::type_declaration& t) -> void CPP2_UFCS(add_runtime_support_include)(t, "cpp2regex.h"); } -#line 3701 "reflect.h2" +#line 3777 "reflect.h2" [[nodiscard]] auto apply_metafunctions( declaration_node& n, type_declaration& rtype, @@ -5418,6 +5498,9 @@ auto regex_gen(meta::type_declaration& t) -> void else {if (name == "regex") { regex_gen(rtype); } + else {if (name == "_internal_foreign_interface_pseudovalue") { + foreign_interface_pseudovalue(rtype); + } else { error("unrecognized metafunction name: '" + name + "' for type declaration"); error( @@ -5427,7 +5510,7 @@ auto regex_gen(meta::type_declaration& t) -> void "struct, enum, flag_enum, union, cpp1_rule_of_zero, regex, print" ); return false; - }}}}}}}}}}}}}}}}} + }}}}}}}}}}}}}}}}}} if (( !(CPP2_UFCS(empty)(args)) @@ -5442,7 +5525,7 @@ auto regex_gen(meta::type_declaration& t) -> void return true; } -#line 3820 "reflect.h2" +#line 3899 "reflect.h2" [[nodiscard]] auto apply_metafunctions( declaration_node& n, function_declaration& rfunc, @@ -5495,7 +5578,7 @@ auto regex_gen(meta::type_declaration& t) -> void return true; } -#line 3873 "reflect.h2" +#line 3952 "reflect.h2" } } diff --git a/source/reflect.h2 b/source/reflect.h2 index 29915e40d..ee5a672f6 100644 --- a/source/reflect.h2 +++ b/source/reflect.h2 @@ -675,6 +675,82 @@ add_virtual_destructor: (inout t: meta::type_declaration) = t.add_member( "operator=: (virtual move this) = { }"); } +//----------------------------------------------------------------------- +// +// foreign_interface_pseudovalue +// +// Internal metafunction to help with public reflection API declaration. +// +// * "foreign interface" because the interface its declaring will be +// defined somewhere else outside the metaprogram. +// +// * "pseudovalue" because the resulting type behaves like a value, +// you can copy, move it, etc. But its not an actual value type, +// as all of its "guts" are behind pointers to the implementation. +// +// The verbose name is on purpose, lets try to give it a better name if it +// can be generalized into something useful for all developers. +foreign_interface_pseudovalue: (inout t : meta::type_declaration) = +{ + interface_funcs: std::vector = (); + parent: std::string = (); + + for t.get_members() do (inout m) + { + if m.is_object() { + mo := m.as_object(); + mo.require(mo.name() == "this", + "only member object that foreing value can have is a parent"); + mo.require(parent.empty(), + "foreign value can only have 1 parent (which must also be a @foreing_value)"); + parent = mo.type(); + } + if m.is_function() { + mf := m.as_function(); + if mf.has_initializer() { + // foreign value functions will be provided a dummy implementation, + // unless they already have one (used for templated functions) + continue; + } + mf.require( mf.make_public(), + "foreign value functions must be public"); + mf.require( mf.is_function_with_this(), + "foreign value functions must have 'this'"); + _ = interface_funcs.emplace_back(mf.print()); + name := mf.name(); + params_as_string: std::string = (); + // imf := interface_funcs.emplace_back(); + // imf.append("(name)$ : ("); + for mf.get_parameters() do (p) + { + // imf.append("(p.name())$ : ()$,"); + if p.name() == "this" { continue; } + _ = params_as_string.append("(p.name())$,"); + } + // imf.append(");"); + mf.add_initializer("_pimpl*.(name)$((params_as_string)$);"); + _ = mf; + } + } + + interface_to_add : std::string = ("public interface: @interface type = {\n"); + for interface_funcs do (iff) { _ = interface_to_add.append(iff); } + _ = interface_to_add.append("}\n"); + + t.add_member(interface_to_add); + t.add_member("private _pimpl: std::unique_ptr;\n"); + if parent.empty() { + t.add_member("operator=: (out this, copy pimpl: std::unique_ptr) = _pimpl = (move pimpl);\n"); + } else { + t.add_member( + "operator=: (out this, copy pimpl: std::unique_ptr, forward parent_pimpls...) = " + "{ (parent)$ = parent_pimpls...; _pimpl = pimpl; }\n" + ); + } + t.add_member("operator=: (out this, move that) = { _pimpl = (move that._pimpl); }\n"); + t.add_member("operator=: (move this) = { }\n"); +} + //----------------------------------------------------------------------- // @@ -3788,6 +3864,9 @@ apply_metafunctions: ( else if name == "regex" { regex_gen( rtype ); } + else if name == "_internal_foreign_interface_pseudovalue" { + foreign_interface_pseudovalue( rtype ); + } else { error( "unrecognized metafunction name: '" + name + "' for type declaration" ); error( From 9cd6759f7dedeca5edde962fc3402357f8550aa9 Mon Sep 17 00:00:00 2001 From: Dylam De La Torre Date: Sat, 24 Aug 2024 00:25:37 +0200 Subject: [PATCH 6/9] Add reflection public API header --- include/cpp2reflect_api.h | 1244 ++++++++++++++++++++++++++++++++++++ include/cpp2reflect_api.h2 | 264 ++++++++ 2 files changed, 1508 insertions(+) create mode 100644 include/cpp2reflect_api.h create mode 100644 include/cpp2reflect_api.h2 diff --git a/include/cpp2reflect_api.h b/include/cpp2reflect_api.h new file mode 100644 index 000000000..3ad971349 --- /dev/null +++ b/include/cpp2reflect_api.h @@ -0,0 +1,1244 @@ + +#ifndef CPP2REFLECT_API_H_CPP2 +#define CPP2REFLECT_API_H_CPP2 + + +//=== Cpp2 type declarations ==================================================== + + +#include "cpp2util.h" + +#line 1 "cpp2reflect_api.h2" + +#line 47 "cpp2reflect_api.h2" +namespace cpp2 { + +#line 51 "cpp2reflect_api.h2" +namespace meta { + +class compiler_services; + +#line 77 "cpp2reflect_api.h2" +class declaration; + +#line 142 "cpp2reflect_api.h2" +class function_declaration; + +#line 195 "cpp2reflect_api.h2" +class object_declaration; + +#line 208 "cpp2reflect_api.h2" +class _query_declared_value_set_functions_ret; + + +#line 215 "cpp2reflect_api.h2" +class type_declaration; + +#line 241 "cpp2reflect_api.h2" +class alias_declaration; + +#line 262 "cpp2reflect_api.h2" +} + +} + + +//=== Cpp2 type definitions and function declarations =========================== + +#line 1 "cpp2reflect_api.h2" + +// Copyright (c) Herb Sutter +// SPDX-License-Identifier: CC-BY-NC-ND-4.0 + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +//=========================================================================== +// Cpp2 reflection (meta and generation) public interface declaration file: +// This file contains only declarations (not definitions) usable by +// authors of metafunctions. See documentation for more details. +// + +namespace cpp2::meta { + +//----------------------------------------------------------------------- +// +// Metafunction registration support. Definitions are provided by the +// implementation (cppfront). +// + +using mf_sign_type_in = void(cpp2::impl::in); +using mf_sign_type_inout = void(type_declaration&); +using mf_sign_func_in = void(cpp2::impl::in); +using mf_sign_func_inout = void(function_declaration&); + +struct register_metafunction { + register_metafunction(const char* name, mf_sign_type_in* f); + register_metafunction(const char* name, mf_sign_type_inout* f); + register_metafunction(const char* name, mf_sign_func_in* f); + register_metafunction(const char* name, mf_sign_func_inout* f); +}; + +} // cpp2::meta + +#line 47 "cpp2reflect_api.h2" +namespace cpp2 { + +#line 51 "cpp2reflect_api.h2" +namespace meta { + +class compiler_services + { + +#line 57 "cpp2reflect_api.h2" + public: [[nodiscard]] auto get_metafunction_name() const& -> std::string_view; + + public: [[nodiscard]] auto get_argument(cpp2::impl::in index) & -> std::string; + public: [[nodiscard]] auto get_arguments() & -> std::vector; + + public: auto add_runtime_support_include(cpp2::impl::in s) & -> void; + + public: auto append_declaration_to_translation_unit(cpp2::impl::in source) & -> void; + +#line 69 "cpp2reflect_api.h2" + public: auto require(cpp2::impl::in b, cpp2::impl::in msg) const& -> void; + public: auto error(cpp2::impl::in msg) const& -> void; + +#line 74 "cpp2reflect_api.h2" + public: auto report_violation(cpp2::impl::in msg) const& -> void; + public: class interface { + public: [[nodiscard]] virtual auto get_metafunction_name() const -> std::string_view = 0; + + public: [[nodiscard]] virtual auto get_argument( + cpp2::impl::in index + ) + -> std::string = 0; + + public: [[nodiscard]] virtual auto get_arguments() -> std::vector = 0; + + public: virtual auto add_runtime_support_include( + cpp2::impl::in s + ) + -> void = 0; + + public: virtual auto append_declaration_to_translation_unit( + cpp2::impl::in source + ) + -> void = 0; + + public: virtual auto require( + cpp2::impl::in b, + cpp2::impl::in msg + ) + const -> void = 0; + + public: virtual auto error( + cpp2::impl::in msg + ) + const -> void = 0; + + public: virtual auto report_violation( + cpp2::impl::in msg + ) + const -> void = 0; + + public: virtual ~interface() noexcept; + + public: interface() = default; + public: interface(interface const&) = delete; /* No 'that' constructor, suppress copy */ + public: auto operator=(interface const&) -> void = delete; + + }; + + private: std::unique_ptr _pimpl; public: explicit compiler_services(std::unique_ptr pimpl); + +public: auto operator=(std::unique_ptr pimpl) -> compiler_services& ; +public: compiler_services(compiler_services&& that) noexcept; +public: auto operator=(compiler_services&& that) noexcept -> compiler_services& ; +public: ~compiler_services() noexcept; + +#line 75 "cpp2reflect_api.h2" +}; + +class declaration +: public compiler_services { + +#line 81 "cpp2reflect_api.h2" + public: [[nodiscard]] auto print() const& -> std::string; + + public: [[nodiscard]] auto is_public() const& -> bool; + public: [[nodiscard]] auto is_protected() const& -> bool; + public: [[nodiscard]] auto is_private() const& -> bool; + public: [[nodiscard]] auto is_default_access() const& -> bool; + + public: auto default_to_public() & -> void; + public: auto default_to_protected() & -> void; + public: auto default_to_private() & -> void; + + public: [[nodiscard]] auto make_public() & -> bool; + public: [[nodiscard]] auto make_protected() & -> bool; + public: [[nodiscard]] auto make_private() & -> bool; + + public: [[nodiscard]] auto has_name() const& -> bool; + public: [[nodiscard]] auto has_name(cpp2::impl::in s) const& -> bool; + + public: [[nodiscard]] auto name() const& -> std::string_view; + public: [[nodiscard]] auto fully_qualified_name() const& -> std::string; + + public: [[nodiscard]] auto has_initializer() const& -> bool; + + public: [[nodiscard]] auto is_global() const& -> bool; + public: [[nodiscard]] auto is_function() const& -> bool; + public: [[nodiscard]] auto is_object() const& -> bool; + public: [[nodiscard]] auto is_base_object() const& -> bool; + public: [[nodiscard]] auto is_member_object() const& -> bool; + public: [[nodiscard]] auto is_type() const& -> bool; + public: [[nodiscard]] auto is_namespace() const& -> bool; + public: [[nodiscard]] auto is_alias() const& -> bool; + + public: [[nodiscard]] auto is_type_alias() const& -> bool; + public: [[nodiscard]] auto is_namespace_alias() const& -> bool; + public: [[nodiscard]] auto is_object_alias() const& -> bool; + + public: [[nodiscard]] auto is_function_expression() const& -> bool; + + public: [[nodiscard]] auto as_function() const& -> function_declaration; + public: [[nodiscard]] auto as_object() const& -> object_declaration; + public: [[nodiscard]] auto as_type() const& -> type_declaration; + public: [[nodiscard]] auto as_alias() const& -> alias_declaration; + + public: [[nodiscard]] auto get_parent() const& -> declaration; + + public: [[nodiscard]] auto parent_is_function() const& -> bool; + public: [[nodiscard]] auto parent_is_object() const& -> bool; + public: [[nodiscard]] auto parent_is_type() const& -> bool; + public: [[nodiscard]] auto parent_is_namespace() const& -> bool; + public: [[nodiscard]] auto parent_is_alias() const& -> bool; + + public: [[nodiscard]] auto parent_is_type_alias() const& -> bool; + public: [[nodiscard]] auto parent_is_namespace_alias() const& -> bool; + public: [[nodiscard]] auto parent_is_object_alias() const& -> bool; + + public: [[nodiscard]] auto parent_is_polymorphic() const& -> bool; + + public: auto mark_for_removal_from_enclosing_type() & -> void; + public: class interface { + public: [[nodiscard]] virtual auto print() const -> std::string = 0; + + public: [[nodiscard]] virtual auto is_public() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_protected() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_private() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_default_access() const -> bool = 0; + + public: virtual auto default_to_public() -> void = 0; + + public: virtual auto default_to_protected() -> void = 0; + + public: virtual auto default_to_private() -> void = 0; + + public: [[nodiscard]] virtual auto make_public() -> bool = 0; + + public: [[nodiscard]] virtual auto make_protected() -> bool = 0; + + public: [[nodiscard]] virtual auto make_private() -> bool = 0; + + public: [[nodiscard]] virtual auto has_name() const -> bool = 0; + + public: [[nodiscard]] virtual auto has_name( + cpp2::impl::in s + ) + const -> bool = 0; + + public: [[nodiscard]] virtual auto name() const -> std::string_view = 0; + + public: [[nodiscard]] virtual auto fully_qualified_name() const -> std::string = 0; + + public: [[nodiscard]] virtual auto has_initializer() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_global() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_function() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_object() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_base_object() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_member_object() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_type() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_namespace() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_alias() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_type_alias() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_namespace_alias() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_object_alias() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_function_expression() const -> bool = 0; + + public: [[nodiscard]] virtual auto as_function() const -> function_declaration = 0; + + public: [[nodiscard]] virtual auto as_object() const -> object_declaration = 0; + + public: [[nodiscard]] virtual auto as_type() const -> type_declaration = 0; + + public: [[nodiscard]] virtual auto as_alias() const -> alias_declaration = 0; + + public: [[nodiscard]] virtual auto get_parent() const -> declaration = 0; + + public: [[nodiscard]] virtual auto parent_is_function() const -> bool = 0; + + public: [[nodiscard]] virtual auto parent_is_object() const -> bool = 0; + + public: [[nodiscard]] virtual auto parent_is_type() const -> bool = 0; + + public: [[nodiscard]] virtual auto parent_is_namespace() const -> bool = 0; + + public: [[nodiscard]] virtual auto parent_is_alias() const -> bool = 0; + + public: [[nodiscard]] virtual auto parent_is_type_alias() const -> bool = 0; + + public: [[nodiscard]] virtual auto parent_is_namespace_alias() const -> bool = 0; + + public: [[nodiscard]] virtual auto parent_is_object_alias() const -> bool = 0; + + public: [[nodiscard]] virtual auto parent_is_polymorphic() const -> bool = 0; + + public: virtual auto mark_for_removal_from_enclosing_type() -> void = 0; + + public: virtual ~interface() noexcept; + + public: interface() = default; + public: interface(interface const&) = delete; /* No 'that' constructor, suppress copy */ + public: auto operator=(interface const&) -> void = delete; + + }; + + private: std::unique_ptr _pimpl; public: explicit declaration(std::unique_ptr pimpl, auto&& ...parent_pimpls); +public: declaration(declaration&& that) noexcept; +public: ~declaration() noexcept; + +#line 139 "cpp2reflect_api.h2" +}; + +#line 142 "cpp2reflect_api.h2" +class function_declaration +: public declaration { + +#line 146 "cpp2reflect_api.h2" + public: [[nodiscard]] auto index_of_parameter_named(cpp2::impl::in s) const& -> int; + public: [[nodiscard]] auto has_parameter_named(cpp2::impl::in s) const& -> bool; + public: [[nodiscard]] auto has_in_parameter_named(cpp2::impl::in s) const& -> bool; + public: [[nodiscard]] auto has_copy_parameter_named(cpp2::impl::in s) const& -> bool; + public: [[nodiscard]] auto has_inout_parameter_named(cpp2::impl::in s) const& -> bool; + public: [[nodiscard]] auto has_out_parameter_named(cpp2::impl::in s) const& -> bool; + public: [[nodiscard]] auto has_move_parameter_named(cpp2::impl::in s) const& -> bool; + public: [[nodiscard]] auto has_forward_parameter_named(cpp2::impl::in s) const& -> bool; + public: [[nodiscard]] auto first_parameter_name() const& -> std::string; + +#line 158 "cpp2reflect_api.h2" + public: [[nodiscard]] auto is_function_with_this() const& -> bool; + public: [[nodiscard]] auto is_virtual() const& -> bool; + public: [[nodiscard]] auto is_defaultable() const& -> bool; + public: [[nodiscard]] auto is_constructor() const& -> bool; + public: [[nodiscard]] auto is_default_constructor() const& -> bool; + public: [[nodiscard]] auto is_move() const& -> bool; + public: [[nodiscard]] auto is_swap() const& -> bool; + public: [[nodiscard]] auto is_constructor_with_that() const& -> bool; + public: [[nodiscard]] auto is_constructor_with_in_that() const& -> bool; + public: [[nodiscard]] auto is_constructor_with_move_that() const& -> bool; + public: [[nodiscard]] auto is_assignment() const& -> bool; + public: [[nodiscard]] auto is_assignment_with_that() const& -> bool; + public: [[nodiscard]] auto is_assignment_with_in_that() const& -> bool; + public: [[nodiscard]] auto is_assignment_with_move_that() const& -> bool; + public: [[nodiscard]] auto is_destructor() const& -> bool; + + public: [[nodiscard]] auto is_copy_or_move() const& -> bool; + + public: [[nodiscard]] auto has_declared_return_type() const& -> bool; + public: [[nodiscard]] auto has_deduced_return_type() const& -> bool; + public: [[nodiscard]] auto has_bool_return_type() const& -> bool; + public: [[nodiscard]] auto has_non_void_return_type() const& -> bool; + + public: [[nodiscard]] auto unnamed_return_type() const& -> std::string; + + public: [[nodiscard]] auto get_parameters() const& -> std::vector; + + public: [[nodiscard]] auto is_binary_comparison_function() const& -> bool; + + public: auto default_to_virtual() & -> void; + + public: [[nodiscard]] auto make_virtual() & -> bool; + + public: auto add_initializer(cpp2::impl::in source) & -> void; + public: class interface { + public: [[nodiscard]] virtual auto index_of_parameter_named( + cpp2::impl::in s + ) + const -> int = 0; + + public: [[nodiscard]] virtual auto has_parameter_named( + cpp2::impl::in s + ) + const -> bool = 0; + + public: [[nodiscard]] virtual auto has_in_parameter_named( + cpp2::impl::in s + ) + const -> bool = 0; + + public: [[nodiscard]] virtual auto has_copy_parameter_named( + cpp2::impl::in s + ) + const -> bool = 0; + + public: [[nodiscard]] virtual auto has_inout_parameter_named( + cpp2::impl::in s + ) + const -> bool = 0; + + public: [[nodiscard]] virtual auto has_out_parameter_named( + cpp2::impl::in s + ) + const -> bool = 0; + + public: [[nodiscard]] virtual auto has_move_parameter_named( + cpp2::impl::in s + ) + const -> bool = 0; + + public: [[nodiscard]] virtual auto has_forward_parameter_named( + cpp2::impl::in s + ) + const -> bool = 0; + + public: [[nodiscard]] virtual auto first_parameter_name() const -> std::string = 0; + + public: [[nodiscard]] virtual auto is_function_with_this() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_virtual() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_defaultable() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_constructor() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_default_constructor() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_move() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_swap() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_constructor_with_that() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_constructor_with_in_that() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_constructor_with_move_that() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_assignment() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_assignment_with_that() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_assignment_with_in_that() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_assignment_with_move_that() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_destructor() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_copy_or_move() const -> bool = 0; + + public: [[nodiscard]] virtual auto has_declared_return_type() const -> bool = 0; + + public: [[nodiscard]] virtual auto has_deduced_return_type() const -> bool = 0; + + public: [[nodiscard]] virtual auto has_bool_return_type() const -> bool = 0; + + public: [[nodiscard]] virtual auto has_non_void_return_type() const -> bool = 0; + + public: [[nodiscard]] virtual auto unnamed_return_type() const -> std::string = 0; + + public: [[nodiscard]] virtual auto get_parameters() const -> std::vector = 0; + + public: [[nodiscard]] virtual auto is_binary_comparison_function() const -> bool = 0; + + public: virtual auto default_to_virtual() -> void = 0; + + public: [[nodiscard]] virtual auto make_virtual() -> bool = 0; + + public: virtual auto add_initializer( + cpp2::impl::in source + ) + -> void = 0; + + public: virtual ~interface() noexcept; + + public: interface() = default; + public: interface(interface const&) = delete; /* No 'that' constructor, suppress copy */ + public: auto operator=(interface const&) -> void = delete; + + }; + + private: std::unique_ptr _pimpl; public: explicit function_declaration(std::unique_ptr pimpl, auto&& ...parent_pimpls); +public: function_declaration(function_declaration&& that) noexcept; +public: ~function_declaration() noexcept; + +#line 192 "cpp2reflect_api.h2" +}; + +#line 195 "cpp2reflect_api.h2" +class object_declaration +: public declaration { + +#line 199 "cpp2reflect_api.h2" + public: [[nodiscard]] auto is_const() const& -> bool; + public: [[nodiscard]] auto has_wildcard_type() const& -> bool; + + public: [[nodiscard]] auto type() const& -> std::string; + + public: [[nodiscard]] auto initializer() const& -> std::string; + public: class interface { + public: [[nodiscard]] virtual auto is_const() const -> bool = 0; + + public: [[nodiscard]] virtual auto has_wildcard_type() const -> bool = 0; + + public: [[nodiscard]] virtual auto type() const -> std::string = 0; + + public: [[nodiscard]] virtual auto initializer() const -> std::string = 0; + + public: virtual ~interface() noexcept; + + public: interface() = default; + public: interface(interface const&) = delete; /* No 'that' constructor, suppress copy */ + public: auto operator=(interface const&) -> void = delete; + + }; + + private: std::unique_ptr _pimpl; public: explicit object_declaration(std::unique_ptr pimpl, auto&& ...parent_pimpls); +public: object_declaration(object_declaration&& that) noexcept; +public: ~object_declaration() noexcept; + +#line 205 "cpp2reflect_api.h2" +}; + +#line 208 "cpp2reflect_api.h2" +class _query_declared_value_set_functions_ret { + public: bool out_this_in_that {false}; + public: bool out_this_move_that {false}; + public: bool inout_this_in_that {false}; + public: bool inout_this_move_that {false}; + public: [[nodiscard]] auto operator<=>(_query_declared_value_set_functions_ret const& that) const& -> std::strong_ordering = default; +public: _query_declared_value_set_functions_ret(_query_declared_value_set_functions_ret const& that); + +public: auto operator=(_query_declared_value_set_functions_ret const& that) -> _query_declared_value_set_functions_ret& ; +public: _query_declared_value_set_functions_ret(_query_declared_value_set_functions_ret&& that) noexcept; +public: auto operator=(_query_declared_value_set_functions_ret&& that) noexcept -> _query_declared_value_set_functions_ret& ; +public: explicit _query_declared_value_set_functions_ret(); + +#line 213 "cpp2reflect_api.h2" +}; + +class type_declaration +: public declaration { + +#line 219 "cpp2reflect_api.h2" + public: [[nodiscard]] auto is_polymorphic() const& -> bool; + public: [[nodiscard]] auto is_final() const& -> bool; + public: [[nodiscard]] auto make_final() & -> bool; + + public: [[nodiscard]] auto get_member_functions() const& -> std::vector; + public: [[nodiscard]] auto get_member_functions_needing_initializer() const& -> std::vector; + public: [[nodiscard]] auto get_member_objects() const& -> std::vector; + public: [[nodiscard]] auto get_member_types() const& -> std::vector; + public: [[nodiscard]] auto get_member_aliases() const& -> std::vector; + public: [[nodiscard]] auto get_members () const& -> std::vector; + + public: [[nodiscard]] auto query_declared_value_set_functions() const& -> _query_declared_value_set_functions_ret; + + public: auto add_member(cpp2::impl::in source) & -> void; + + public: auto remove_marked_members() & -> void; + public: auto remove_all_members() & -> void; + + public: auto disable_member_function_generation() & -> void; + public: class interface { + public: [[nodiscard]] virtual auto is_polymorphic() const -> bool = 0; + + public: [[nodiscard]] virtual auto is_final() const -> bool = 0; + + public: [[nodiscard]] virtual auto make_final() -> bool = 0; + + public: [[nodiscard]] virtual auto get_member_functions() const -> std::vector = 0; + + public: [[nodiscard]] virtual auto get_member_functions_needing_initializer() const -> std::vector = 0; + + public: [[nodiscard]] virtual auto get_member_objects() const -> std::vector = 0; + + public: [[nodiscard]] virtual auto get_member_types() const -> std::vector = 0; + + public: [[nodiscard]] virtual auto get_member_aliases() const -> std::vector = 0; + + public: [[nodiscard]] virtual auto get_members() const -> std::vector = 0; + + public: [[nodiscard]] virtual auto query_declared_value_set_functions() const -> _query_declared_value_set_functions_ret = 0; + + public: virtual auto add_member( + cpp2::impl::in source + ) + -> void = 0; + + public: virtual auto remove_marked_members() -> void = 0; + + public: virtual auto remove_all_members() -> void = 0; + + public: virtual auto disable_member_function_generation() -> void = 0; + + public: virtual ~interface() noexcept; + + public: interface() = default; + public: interface(interface const&) = delete; /* No 'that' constructor, suppress copy */ + public: auto operator=(interface const&) -> void = delete; + + }; + + private: std::unique_ptr _pimpl; public: explicit type_declaration(std::unique_ptr pimpl, auto&& ...parent_pimpls); +public: type_declaration(type_declaration&& that) noexcept; +public: ~type_declaration() noexcept; + +#line 238 "cpp2reflect_api.h2" +}; + +#line 241 "cpp2reflect_api.h2" +class alias_declaration +: public declaration { +public: class interface {public: virtual ~interface() noexcept; + + public: interface() = default; + public: interface(interface const&) = delete; /* No 'that' constructor, suppress copy */ + public: auto operator=(interface const&) -> void = delete; + +}; + +private: std::unique_ptr _pimpl; public: explicit alias_declaration(std::unique_ptr pimpl, auto&& ...parent_pimpls); +public: alias_declaration(alias_declaration&& that) noexcept; +public: ~alias_declaration() noexcept; + + +#line 244 "cpp2reflect_api.h2" +}; + +#line 247 "cpp2reflect_api.h2" +auto reserve_names(type_declaration& t, cpp2::impl::in name, auto&& ...etc) -> void; + +#line 262 "cpp2reflect_api.h2" +} // meta + +} // cpp2 + + +//=== Cpp2 function definitions ================================================= + +#line 1 "cpp2reflect_api.h2" + +#line 41 "cpp2reflect_api.h2" +//----------------------------------------------------------------------- +// +// Metafunction objects. Expanded to complete definitions that use a +// interface, which is provided by the implementation (cppfront). +// + +#line 47 "cpp2reflect_api.h2" +namespace cpp2 { + +// TODO(DyXel): put passing_style here, maybe? + +namespace meta { + +#line 55 "cpp2reflect_api.h2" + // Common API + // +#line 57 "cpp2reflect_api.h2" + [[nodiscard]] auto compiler_services::get_metafunction_name() const& -> std::string_view { + return CPP2_UFCS(get_metafunction_name)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 59 "cpp2reflect_api.h2" + [[nodiscard]] auto compiler_services::get_argument(cpp2::impl::in index) & -> std::string { + return CPP2_UFCS(get_argument)((*cpp2::impl::assert_not_null(_pimpl)), index); } +#line 60 "cpp2reflect_api.h2" + [[nodiscard]] auto compiler_services::get_arguments() & -> std::vector { + return CPP2_UFCS(get_arguments)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 62 "cpp2reflect_api.h2" + auto compiler_services::add_runtime_support_include(cpp2::impl::in s) & -> void { + CPP2_UFCS(add_runtime_support_include)((*cpp2::impl::assert_not_null(_pimpl)), s); } + +#line 64 "cpp2reflect_api.h2" + auto compiler_services::append_declaration_to_translation_unit(cpp2::impl::in source) & -> void { + CPP2_UFCS(append_declaration_to_translation_unit)((*cpp2::impl::assert_not_null(_pimpl)), source); } + + // Error diagnosis and handling, integrated with compiler output + // Unlike a contract violation, .require continues further processing + // +#line 69 "cpp2reflect_api.h2" + auto compiler_services::require(cpp2::impl::in b, cpp2::impl::in msg) const& -> void { + CPP2_UFCS(require)((*cpp2::impl::assert_not_null(_pimpl)), b, msg); } +#line 70 "cpp2reflect_api.h2" + auto compiler_services::error(cpp2::impl::in msg) const& -> void { + CPP2_UFCS(error)((*cpp2::impl::assert_not_null(_pimpl)), msg); } + // Enable custom contracts on this object, integrated with compiler output + // Unlike .require, a contract violation stops further processing + // +#line 74 "cpp2reflect_api.h2" + auto compiler_services::report_violation(cpp2::impl::in msg) const& -> void { + CPP2_UFCS(report_violation)((*cpp2::impl::assert_not_null(_pimpl)), msg); } + + + + + + + + + +compiler_services::interface::~interface() noexcept{} + +compiler_services::compiler_services(std::unique_ptr pimpl) + : _pimpl{ std::move(cpp2::move(pimpl)) } { } + +auto compiler_services::operator=(std::unique_ptr pimpl) -> compiler_services& { + _pimpl = std::move(cpp2::move(pimpl)); + return *this; } +compiler_services::compiler_services(compiler_services&& that) noexcept + : _pimpl{ std::move(cpp2::move(that)._pimpl) }{} +auto compiler_services::operator=(compiler_services&& that) noexcept -> compiler_services& { + _pimpl = std::move(cpp2::move(that)._pimpl); + return *this;} +compiler_services::~compiler_services() noexcept{} +#line 81 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::print() const& -> std::string { + return CPP2_UFCS(print)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 83 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::is_public() const& -> bool { + return CPP2_UFCS(is_public)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 84 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::is_protected() const& -> bool { + return CPP2_UFCS(is_protected)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 85 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::is_private() const& -> bool { + return CPP2_UFCS(is_private)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 86 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::is_default_access() const& -> bool { + return CPP2_UFCS(is_default_access)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 88 "cpp2reflect_api.h2" + auto declaration::default_to_public() & -> void { + CPP2_UFCS(default_to_public)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 89 "cpp2reflect_api.h2" + auto declaration::default_to_protected() & -> void { + CPP2_UFCS(default_to_protected)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 90 "cpp2reflect_api.h2" + auto declaration::default_to_private() & -> void { + CPP2_UFCS(default_to_private)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 92 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::make_public() & -> bool { + return CPP2_UFCS(make_public)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 93 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::make_protected() & -> bool { + return CPP2_UFCS(make_protected)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 94 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::make_private() & -> bool { + return CPP2_UFCS(make_private)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 96 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::has_name() const& -> bool { + return CPP2_UFCS(has_name)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 97 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::has_name(cpp2::impl::in s) const& -> bool { + return CPP2_UFCS(has_name)((*cpp2::impl::assert_not_null(_pimpl)), s); } + +#line 99 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::name() const& -> std::string_view { + return CPP2_UFCS(name)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 100 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::fully_qualified_name() const& -> std::string { + return CPP2_UFCS(fully_qualified_name)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 102 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::has_initializer() const& -> bool { + return CPP2_UFCS(has_initializer)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 104 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::is_global() const& -> bool { + return CPP2_UFCS(is_global)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 105 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::is_function() const& -> bool { + return CPP2_UFCS(is_function)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 106 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::is_object() const& -> bool { + return CPP2_UFCS(is_object)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 107 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::is_base_object() const& -> bool { + return CPP2_UFCS(is_base_object)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 108 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::is_member_object() const& -> bool { + return CPP2_UFCS(is_member_object)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 109 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::is_type() const& -> bool { + return CPP2_UFCS(is_type)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 110 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::is_namespace() const& -> bool { + return CPP2_UFCS(is_namespace)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 111 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::is_alias() const& -> bool { + return CPP2_UFCS(is_alias)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 113 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::is_type_alias() const& -> bool { + return CPP2_UFCS(is_type_alias)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 114 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::is_namespace_alias() const& -> bool { + return CPP2_UFCS(is_namespace_alias)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 115 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::is_object_alias() const& -> bool { + return CPP2_UFCS(is_object_alias)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 117 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::is_function_expression() const& -> bool { + return CPP2_UFCS(is_function_expression)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 119 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::as_function() const& -> function_declaration { + return CPP2_UFCS(as_function)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 120 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::as_object() const& -> object_declaration { + return CPP2_UFCS(as_object)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 121 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::as_type() const& -> type_declaration { + return CPP2_UFCS(as_type)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 122 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::as_alias() const& -> alias_declaration { + return CPP2_UFCS(as_alias)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 124 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::get_parent() const& -> declaration { + return CPP2_UFCS(get_parent)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 126 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::parent_is_function() const& -> bool { + return CPP2_UFCS(parent_is_function)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 127 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::parent_is_object() const& -> bool { + return CPP2_UFCS(parent_is_object)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 128 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::parent_is_type() const& -> bool { + return CPP2_UFCS(parent_is_type)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 129 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::parent_is_namespace() const& -> bool { + return CPP2_UFCS(parent_is_namespace)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 130 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::parent_is_alias() const& -> bool { + return CPP2_UFCS(parent_is_alias)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 132 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::parent_is_type_alias() const& -> bool { + return CPP2_UFCS(parent_is_type_alias)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 133 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::parent_is_namespace_alias() const& -> bool { + return CPP2_UFCS(parent_is_namespace_alias)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 134 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::parent_is_object_alias() const& -> bool { + return CPP2_UFCS(parent_is_object_alias)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 136 "cpp2reflect_api.h2" + [[nodiscard]] auto declaration::parent_is_polymorphic() const& -> bool { + return CPP2_UFCS(parent_is_polymorphic)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 138 "cpp2reflect_api.h2" + auto declaration::mark_for_removal_from_enclosing_type() & -> void { + CPP2_UFCS(mark_for_removal_from_enclosing_type)((*cpp2::impl::assert_not_null(_pimpl))); } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +declaration::interface::~interface() noexcept{} + +declaration::declaration(std::unique_ptr pimpl, auto&& ...parent_pimpls) + : compiler_services{ CPP2_FORWARD(parent_pimpls)... } + , _pimpl{ cpp2::move(pimpl) }{} +declaration::declaration(declaration&& that) noexcept + : compiler_services{ static_cast(that) } + , _pimpl{ std::move(cpp2::move(that)._pimpl) }{} +declaration::~declaration() noexcept{} + +#line 146 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::index_of_parameter_named(cpp2::impl::in s) const& -> int { + return CPP2_UFCS(index_of_parameter_named)((*cpp2::impl::assert_not_null(_pimpl)), s); } +#line 147 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::has_parameter_named(cpp2::impl::in s) const& -> bool { + return CPP2_UFCS(has_parameter_named)((*cpp2::impl::assert_not_null(_pimpl)), s); } +#line 148 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::has_in_parameter_named(cpp2::impl::in s) const& -> bool { + return CPP2_UFCS(has_in_parameter_named)((*cpp2::impl::assert_not_null(_pimpl)), s); } +#line 149 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::has_copy_parameter_named(cpp2::impl::in s) const& -> bool { + return CPP2_UFCS(has_copy_parameter_named)((*cpp2::impl::assert_not_null(_pimpl)), s); } +#line 150 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::has_inout_parameter_named(cpp2::impl::in s) const& -> bool { + return CPP2_UFCS(has_inout_parameter_named)((*cpp2::impl::assert_not_null(_pimpl)), s); } +#line 151 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::has_out_parameter_named(cpp2::impl::in s) const& -> bool { + return CPP2_UFCS(has_out_parameter_named)((*cpp2::impl::assert_not_null(_pimpl)), s); } +#line 152 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::has_move_parameter_named(cpp2::impl::in s) const& -> bool { + return CPP2_UFCS(has_move_parameter_named)((*cpp2::impl::assert_not_null(_pimpl)), s); } +#line 153 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::has_forward_parameter_named(cpp2::impl::in s) const& -> bool { + return CPP2_UFCS(has_forward_parameter_named)((*cpp2::impl::assert_not_null(_pimpl)), s); } +#line 154 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::first_parameter_name() const& -> std::string { + return CPP2_UFCS(first_parameter_name)((*cpp2::impl::assert_not_null(_pimpl))); } + + // has_parameter_with_name_and_pass: (this, s: std::string_view, pass: passing_style) -> bool; // TODO + +#line 158 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::is_function_with_this() const& -> bool { + return CPP2_UFCS(is_function_with_this)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 159 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::is_virtual() const& -> bool { + return CPP2_UFCS(is_virtual)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 160 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::is_defaultable() const& -> bool { + return CPP2_UFCS(is_defaultable)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 161 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::is_constructor() const& -> bool { + return CPP2_UFCS(is_constructor)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 162 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::is_default_constructor() const& -> bool { + return CPP2_UFCS(is_default_constructor)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 163 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::is_move() const& -> bool { + return CPP2_UFCS(is_move)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 164 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::is_swap() const& -> bool { + return CPP2_UFCS(is_swap)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 165 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::is_constructor_with_that() const& -> bool { + return CPP2_UFCS(is_constructor_with_that)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 166 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::is_constructor_with_in_that() const& -> bool { + return CPP2_UFCS(is_constructor_with_in_that)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 167 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::is_constructor_with_move_that() const& -> bool { + return CPP2_UFCS(is_constructor_with_move_that)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 168 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::is_assignment() const& -> bool { + return CPP2_UFCS(is_assignment)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 169 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::is_assignment_with_that() const& -> bool { + return CPP2_UFCS(is_assignment_with_that)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 170 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::is_assignment_with_in_that() const& -> bool { + return CPP2_UFCS(is_assignment_with_in_that)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 171 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::is_assignment_with_move_that() const& -> bool { + return CPP2_UFCS(is_assignment_with_move_that)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 172 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::is_destructor() const& -> bool { + return CPP2_UFCS(is_destructor)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 174 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::is_copy_or_move() const& -> bool { + return CPP2_UFCS(is_copy_or_move)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 176 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::has_declared_return_type() const& -> bool { + return CPP2_UFCS(has_declared_return_type)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 177 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::has_deduced_return_type() const& -> bool { + return CPP2_UFCS(has_deduced_return_type)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 178 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::has_bool_return_type() const& -> bool { + return CPP2_UFCS(has_bool_return_type)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 179 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::has_non_void_return_type() const& -> bool { + return CPP2_UFCS(has_non_void_return_type)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 181 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::unnamed_return_type() const& -> std::string { + return CPP2_UFCS(unnamed_return_type)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 183 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::get_parameters() const& -> std::vector { + return CPP2_UFCS(get_parameters)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 185 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::is_binary_comparison_function() const& -> bool { + return CPP2_UFCS(is_binary_comparison_function)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 187 "cpp2reflect_api.h2" + auto function_declaration::default_to_virtual() & -> void { + CPP2_UFCS(default_to_virtual)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 189 "cpp2reflect_api.h2" + [[nodiscard]] auto function_declaration::make_virtual() & -> bool { + return CPP2_UFCS(make_virtual)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 191 "cpp2reflect_api.h2" + auto function_declaration::add_initializer(cpp2::impl::in source) & -> void { + CPP2_UFCS(add_initializer)((*cpp2::impl::assert_not_null(_pimpl)), source); } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +function_declaration::interface::~interface() noexcept{} + +function_declaration::function_declaration(std::unique_ptr pimpl, auto&& ...parent_pimpls) + : declaration{ CPP2_FORWARD(parent_pimpls)... } + , _pimpl{ cpp2::move(pimpl) }{} +function_declaration::function_declaration(function_declaration&& that) noexcept + : declaration{ static_cast(that) } + , _pimpl{ std::move(cpp2::move(that)._pimpl) }{} +function_declaration::~function_declaration() noexcept{} + +#line 199 "cpp2reflect_api.h2" + [[nodiscard]] auto object_declaration::is_const() const& -> bool { + return CPP2_UFCS(is_const)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 200 "cpp2reflect_api.h2" + [[nodiscard]] auto object_declaration::has_wildcard_type() const& -> bool { + return CPP2_UFCS(has_wildcard_type)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 202 "cpp2reflect_api.h2" + [[nodiscard]] auto object_declaration::type() const& -> std::string { + return CPP2_UFCS(type)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 204 "cpp2reflect_api.h2" + [[nodiscard]] auto object_declaration::initializer() const& -> std::string { + return CPP2_UFCS(initializer)((*cpp2::impl::assert_not_null(_pimpl))); } + + + + + +object_declaration::interface::~interface() noexcept{} + +object_declaration::object_declaration(std::unique_ptr pimpl, auto&& ...parent_pimpls) + : declaration{ CPP2_FORWARD(parent_pimpls)... } + , _pimpl{ cpp2::move(pimpl) }{} +object_declaration::object_declaration(object_declaration&& that) noexcept + : declaration{ static_cast(that) } + , _pimpl{ std::move(cpp2::move(that)._pimpl) }{} +object_declaration::~object_declaration() noexcept{} + +_query_declared_value_set_functions_ret::_query_declared_value_set_functions_ret(_query_declared_value_set_functions_ret const& that) + : out_this_in_that{ that.out_this_in_that } + , out_this_move_that{ that.out_this_move_that } + , inout_this_in_that{ that.inout_this_in_that } + , inout_this_move_that{ that.inout_this_move_that }{} + +auto _query_declared_value_set_functions_ret::operator=(_query_declared_value_set_functions_ret const& that) -> _query_declared_value_set_functions_ret& { + out_this_in_that = that.out_this_in_that; + out_this_move_that = that.out_this_move_that; + inout_this_in_that = that.inout_this_in_that; + inout_this_move_that = that.inout_this_move_that; + return *this;} +_query_declared_value_set_functions_ret::_query_declared_value_set_functions_ret(_query_declared_value_set_functions_ret&& that) noexcept + : out_this_in_that{ std::move(that).out_this_in_that } + , out_this_move_that{ std::move(that).out_this_move_that } + , inout_this_in_that{ std::move(that).inout_this_in_that } + , inout_this_move_that{ std::move(that).inout_this_move_that }{} +auto _query_declared_value_set_functions_ret::operator=(_query_declared_value_set_functions_ret&& that) noexcept -> _query_declared_value_set_functions_ret& { + out_this_in_that = std::move(that).out_this_in_that; + out_this_move_that = std::move(that).out_this_move_that; + inout_this_in_that = std::move(that).inout_this_in_that; + inout_this_move_that = std::move(that).inout_this_move_that; + return *this;} +_query_declared_value_set_functions_ret::_query_declared_value_set_functions_ret(){} +#line 207 "cpp2reflect_api.h2" +// Workaround due to https://github.com/hsutter/cppfront/issues/1109 + +#line 219 "cpp2reflect_api.h2" + [[nodiscard]] auto type_declaration::is_polymorphic() const& -> bool { + return CPP2_UFCS(is_polymorphic)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 220 "cpp2reflect_api.h2" + [[nodiscard]] auto type_declaration::is_final() const& -> bool { + return CPP2_UFCS(is_final)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 221 "cpp2reflect_api.h2" + [[nodiscard]] auto type_declaration::make_final() & -> bool { + return CPP2_UFCS(make_final)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 223 "cpp2reflect_api.h2" + [[nodiscard]] auto type_declaration::get_member_functions() const& -> std::vector { + return CPP2_UFCS(get_member_functions)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 224 "cpp2reflect_api.h2" + [[nodiscard]] auto type_declaration::get_member_functions_needing_initializer() const& -> std::vector { + return CPP2_UFCS(get_member_functions_needing_initializer)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 225 "cpp2reflect_api.h2" + [[nodiscard]] auto type_declaration::get_member_objects() const& -> std::vector { + return CPP2_UFCS(get_member_objects)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 226 "cpp2reflect_api.h2" + [[nodiscard]] auto type_declaration::get_member_types() const& -> std::vector { + return CPP2_UFCS(get_member_types)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 227 "cpp2reflect_api.h2" + [[nodiscard]] auto type_declaration::get_member_aliases() const& -> std::vector { + return CPP2_UFCS(get_member_aliases)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 228 "cpp2reflect_api.h2" + [[nodiscard]] auto type_declaration::get_members() const& -> std::vector { + return CPP2_UFCS(get_members)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 230 "cpp2reflect_api.h2" + [[nodiscard]] auto type_declaration::query_declared_value_set_functions() const& -> _query_declared_value_set_functions_ret { + return CPP2_UFCS(query_declared_value_set_functions)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 232 "cpp2reflect_api.h2" + auto type_declaration::add_member(cpp2::impl::in source) & -> void { + CPP2_UFCS(add_member)((*cpp2::impl::assert_not_null(_pimpl)), source); } + +#line 234 "cpp2reflect_api.h2" + auto type_declaration::remove_marked_members() & -> void { + CPP2_UFCS(remove_marked_members)((*cpp2::impl::assert_not_null(_pimpl))); } +#line 235 "cpp2reflect_api.h2" + auto type_declaration::remove_all_members() & -> void { + CPP2_UFCS(remove_all_members)((*cpp2::impl::assert_not_null(_pimpl))); } + +#line 237 "cpp2reflect_api.h2" + auto type_declaration::disable_member_function_generation() & -> void { + CPP2_UFCS(disable_member_function_generation)((*cpp2::impl::assert_not_null(_pimpl))); } + + + + + + + + + + + + + + + +type_declaration::interface::~interface() noexcept{} + +type_declaration::type_declaration(std::unique_ptr pimpl, auto&& ...parent_pimpls) + : declaration{ CPP2_FORWARD(parent_pimpls)... } + , _pimpl{ cpp2::move(pimpl) }{} +type_declaration::type_declaration(type_declaration&& that) noexcept + : declaration{ static_cast(that) } + , _pimpl{ std::move(cpp2::move(that)._pimpl) }{} +type_declaration::~type_declaration() noexcept{} + +alias_declaration::interface::~interface() noexcept{} + +alias_declaration::alias_declaration(std::unique_ptr pimpl, auto&& ...parent_pimpls) + : declaration{ CPP2_FORWARD(parent_pimpls)... } + , _pimpl{ cpp2::move(pimpl) }{} +alias_declaration::alias_declaration(alias_declaration&& that) noexcept + : declaration{ static_cast(that) } + , _pimpl{ std::move(cpp2::move(that)._pimpl) }{} +alias_declaration::~alias_declaration() noexcept{} + +#line 247 "cpp2reflect_api.h2" +auto reserve_names(type_declaration& t, cpp2::impl::in name, auto&& ...etc) -> void +{ // etc is not declared ':string_view' for compatibility with GCC 10.x + for ( + auto const& m : CPP2_UFCS(get_members)(t) ) { + auto n {CPP2_UFCS(get_metafunction_name)(t)}; + CPP2_UFCS(require)(m, !(CPP2_UFCS(has_name)(m, name)), + "in a '" + cpp2::to_string(n) + "' type, the name '" + cpp2::to_string(name) + "' " + "is reserved for use by the '" + cpp2::to_string(n) + "' implementation" + ); + } + if constexpr (!(CPP2_PACK_EMPTY(etc))) { + CPP2_UFCS(reserve_names)(t, CPP2_FORWARD(etc)...); + } +} + +} + +} + +#endif diff --git a/include/cpp2reflect_api.h2 b/include/cpp2reflect_api.h2 new file mode 100644 index 000000000..37fbea9bd --- /dev/null +++ b/include/cpp2reflect_api.h2 @@ -0,0 +1,264 @@ + +// Copyright (c) Herb Sutter +// SPDX-License-Identifier: CC-BY-NC-ND-4.0 + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +//=========================================================================== +// Cpp2 reflection (meta and generation) public interface declaration file: +// This file contains only declarations (not definitions) usable by +// authors of metafunctions. See documentation for more details. +// + +namespace cpp2::meta { + +//----------------------------------------------------------------------- +// +// Metafunction registration support. Definitions are provided by the +// implementation (cppfront). +// + +using mf_sign_type_in = void(cpp2::impl::in); +using mf_sign_type_inout = void(type_declaration&); +using mf_sign_func_in = void(cpp2::impl::in); +using mf_sign_func_inout = void(function_declaration&); + +struct register_metafunction { + register_metafunction(const char* name, mf_sign_type_in* f); + register_metafunction(const char* name, mf_sign_type_inout* f); + register_metafunction(const char* name, mf_sign_func_in* f); + register_metafunction(const char* name, mf_sign_func_inout* f); +}; + +} // cpp2::meta + +//----------------------------------------------------------------------- +// +// Metafunction objects. Expanded to complete definitions that use a +// interface, which is provided by the implementation (cppfront). +// + +cpp2: namespace = { + +// TODO(DyXel): put passing_style here, maybe? + +meta: namespace = { + +compiler_services: @_internal_foreign_interface_pseudovalue type = +{ + // Common API + // + get_metafunction_name: (this) -> std::string_view; + + get_argument : (inout this, index: int) -> std::string; + get_arguments: (inout this) -> std::vector; + + add_runtime_support_include: (inout this, s: std::string_view); + + append_declaration_to_translation_unit: (inout this, source: std::string_view); + + // Error diagnosis and handling, integrated with compiler output + // Unlike a contract violation, .require continues further processing + // + require : (this, b: bool, msg: std::string_view); + error : (this, msg: std::string_view); + // Enable custom contracts on this object, integrated with compiler output + // Unlike .require, a contract violation stops further processing + // + report_violation: (this, msg: std::string_view); +} + +declaration: @_internal_foreign_interface_pseudovalue type = +{ + this: compiler_services; + + print: (this) -> std::string; + + is_public : (this) -> bool; + is_protected : (this) -> bool; + is_private : (this) -> bool; + is_default_access: (this) -> bool; + + default_to_public : (inout this); + default_to_protected: (inout this); + default_to_private : (inout this); + + make_public : (inout this) -> bool; + make_protected: (inout this) -> bool; + make_private : (inout this) -> bool; + + has_name: (this) -> bool; + has_name: (this, s: std::string_view) -> bool; + + name : (this) -> std::string_view; + fully_qualified_name: (this) -> std::string; + + has_initializer: (this) -> bool; + + is_global : (this) -> bool; + is_function : (this) -> bool; + is_object : (this) -> bool; + is_base_object : (this) -> bool; + is_member_object : (this) -> bool; + is_type : (this) -> bool; + is_namespace : (this) -> bool; + is_alias : (this) -> bool; + + is_type_alias : (this) -> bool; + is_namespace_alias : (this) -> bool; + is_object_alias : (this) -> bool; + + is_function_expression: (this) -> bool; + + as_function: (this) -> function_declaration; + as_object : (this) -> object_declaration; + as_type : (this) -> type_declaration; + as_alias : (this) -> alias_declaration; + + get_parent: (this) -> declaration; + + parent_is_function : (this) -> bool; + parent_is_object : (this) -> bool; + parent_is_type : (this) -> bool; + parent_is_namespace: (this) -> bool; + parent_is_alias : (this) -> bool; + + parent_is_type_alias : (this) -> bool; + parent_is_namespace_alias: (this) -> bool; + parent_is_object_alias : (this) -> bool; + + parent_is_polymorphic: (this) -> bool; + + mark_for_removal_from_enclosing_type: (inout this); +} + + +function_declaration: @_internal_foreign_interface_pseudovalue type = +{ + this: declaration; + + index_of_parameter_named : (this, s: std::string_view) -> int; + has_parameter_named : (this, s: std::string_view) -> bool; + has_in_parameter_named : (this, s: std::string_view) -> bool; + has_copy_parameter_named : (this, s: std::string_view) -> bool; + has_inout_parameter_named : (this, s: std::string_view) -> bool; + has_out_parameter_named : (this, s: std::string_view) -> bool; + has_move_parameter_named : (this, s: std::string_view) -> bool; + has_forward_parameter_named: (this, s: std::string_view) -> bool; + first_parameter_name : (this) -> std::string; + + // has_parameter_with_name_and_pass: (this, s: std::string_view, pass: passing_style) -> bool; // TODO + + is_function_with_this : (this) -> bool; + is_virtual : (this) -> bool; + is_defaultable : (this) -> bool; + is_constructor : (this) -> bool; + is_default_constructor : (this) -> bool; + is_move : (this) -> bool; + is_swap : (this) -> bool; + is_constructor_with_that : (this) -> bool; + is_constructor_with_in_that : (this) -> bool; + is_constructor_with_move_that: (this) -> bool; + is_assignment : (this) -> bool; + is_assignment_with_that : (this) -> bool; + is_assignment_with_in_that : (this) -> bool; + is_assignment_with_move_that : (this) -> bool; + is_destructor : (this) -> bool; + + is_copy_or_move : (this) -> bool; + + has_declared_return_type: (this) -> bool; + has_deduced_return_type : (this) -> bool; + has_bool_return_type : (this) -> bool; + has_non_void_return_type: (this) -> bool; + + unnamed_return_type: (this) -> std::string; + + get_parameters: (this) -> std::vector; + + is_binary_comparison_function: (this) -> bool; + + default_to_virtual: (inout this); + + make_virtual: (inout this) -> bool; + + add_initializer: (inout this, source: std::string_view); +} + + +object_declaration: @_internal_foreign_interface_pseudovalue type = +{ + this: declaration; + + is_const : (this) -> bool; + has_wildcard_type: (this) -> bool; + + type: (this) -> std::string; + + initializer: (this) -> std::string; +} + +// Workaround due to https://github.com/hsutter/cppfront/issues/1109 +_query_declared_value_set_functions_ret: @value type = { + public out_this_in_that: bool = false; + public out_this_move_that: bool = false; + public inout_this_in_that: bool = false; + public inout_this_move_that: bool = false; +} + +type_declaration: @_internal_foreign_interface_pseudovalue type = +{ + this: declaration; + + is_polymorphic: (this) -> bool; + is_final : (this) -> bool; + make_final : (inout this) -> bool; + + get_member_functions : (this) -> std::vector; + get_member_functions_needing_initializer: (this) -> std::vector; + get_member_objects : (this) -> std::vector; + get_member_types : (this) -> std::vector; + get_member_aliases : (this) -> std::vector; + get_members : (this) -> std::vector; + + query_declared_value_set_functions: (this) -> _query_declared_value_set_functions_ret; + + add_member : (inout this, source: std::string_view); + + remove_marked_members: (inout this); + remove_all_members : (inout this); + + disable_member_function_generation: (inout this); +} + + +alias_declaration: @_internal_foreign_interface_pseudovalue type = +{ + this: declaration; +} + + +reserve_names: (inout t: type_declaration, name: std::string_view, forward etc...) = +{ // etc is not declared ':string_view' for compatibility with GCC 10.x + for t.get_members() + do (m) { + n := t.get_metafunction_name(); + m.require( !m.has_name( name ), + "in a '(n)$' type, the name '(name)$' " + "is reserved for use by the '(n)$' implementation" + ); + } + if constexpr !CPP2_PACK_EMPTY(etc) { + t.reserve_names( etc... ); + } +} + +} // meta + +} // cpp2 From abcf1d5a20fa1bb39a823f6d8f4fe72ffed4dfc7 Mon Sep 17 00:00:00 2001 From: Dylam De La Torre Date: Sat, 24 Aug 2024 00:28:00 +0200 Subject: [PATCH 7/9] Refactor compiler reflection to use new public header --- source/cpp2reflect_api.h | 1 + source/reflect.h | 2178 ++++++++++++++++++++------------------ source/reflect.h2 | 521 +++++---- source/sema.h | 12 +- 4 files changed, 1423 insertions(+), 1289 deletions(-) create mode 100644 source/cpp2reflect_api.h diff --git a/source/cpp2reflect_api.h b/source/cpp2reflect_api.h new file mode 100644 index 000000000..847fd11bb --- /dev/null +++ b/source/cpp2reflect_api.h @@ -0,0 +1 @@ +#include "../include/cpp2reflect_api.h" diff --git a/source/reflect.h b/source/reflect.h index ab3f0c9dd..8388cdcad 100644 --- a/source/reflect.h +++ b/source/reflect.h @@ -10,103 +10,106 @@ #line 1 "reflect.h2" -#line 22 "reflect.h2" +#line 23 "reflect.h2" namespace cpp2 { namespace meta { -#line 34 "reflect.h2" -class compiler_services; +#line 35 "reflect.h2" +class compiler_services_base; -#line 273 "reflect.h2" +#line 189 "reflect.h2" +class compiler_services_impl; + +#line 283 "reflect.h2" class declaration_base; -#line 299 "reflect.h2" -class declaration; +#line 343 "reflect.h2" +class declaration_impl; -#line 382 "reflect.h2" -class function_declaration; +#line 430 "reflect.h2" +class function_declaration_impl; -#line 472 "reflect.h2" -class object_declaration; +#line 520 "reflect.h2" +class object_declaration_impl; -#line 508 "reflect.h2" -class type_declaration; +#line 558 "reflect.h2" +class type_declaration_impl; -#line 645 "reflect.h2" -class alias_declaration; +#line 686 "reflect.h2" +class alias_declaration_impl; -#line 1129 "reflect.h2" +#line 1172 "reflect.h2" class value_member_info; -#line 1672 "reflect.h2" +#line 1715 "reflect.h2" class expression_flags; -#line 1688 "reflect.h2" +#line 1731 "reflect.h2" class regex_token; -#line 1714 "reflect.h2" +#line 1757 "reflect.h2" class regex_token_check; -#line 1733 "reflect.h2" +#line 1776 "reflect.h2" class regex_token_code; -#line 1752 "reflect.h2" +#line 1795 "reflect.h2" class regex_token_empty; -#line 1768 "reflect.h2" +#line 1811 "reflect.h2" class regex_token_list; -#line 1807 "reflect.h2" +#line 1850 "reflect.h2" class parse_context_group_state; -#line 1868 "reflect.h2" +#line 1911 "reflect.h2" class parse_context_branch_reset_state; -#line 1911 "reflect.h2" +#line 1954 "reflect.h2" class parse_context; -#line 2309 "reflect.h2" +#line 2352 "reflect.h2" class generation_function_context; -#line 2327 "reflect.h2" +#line 2370 "reflect.h2" class generation_context; -#line 2525 "reflect.h2" +#line 2568 "reflect.h2" class alternative_token; -#line 2540 "reflect.h2" +#line 2583 "reflect.h2" class alternative_token_gen; -#line 2592 "reflect.h2" +#line 2635 "reflect.h2" class any_token; -#line 2610 "reflect.h2" +#line 2653 "reflect.h2" class char_token; -#line 2713 "reflect.h2" +#line 2756 "reflect.h2" class class_token; -#line 2928 "reflect.h2" +#line 2971 "reflect.h2" class group_ref_token; -#line 3059 "reflect.h2" +#line 3102 "reflect.h2" class group_token; -#line 3346 "reflect.h2" +#line 3389 "reflect.h2" class lookahead_token; -#line 3427 "reflect.h2" +#line 3470 "reflect.h2" class range_token; -#line 3575 "reflect.h2" +#line 3618 "reflect.h2" class special_range_token; -#line 3642 "reflect.h2" +#line 3685 "reflect.h2" template class regex_generator; -#line 3952 "reflect.h2" +#line 4003 "reflect.h2" } } @@ -133,31 +136,32 @@ template class regex_generator; //=========================================================================== #include "parse.h" +#include "cpp2reflect_api.h" #include "cpp2regex.h" using namespace cpp2::regex; -#line 22 "reflect.h2" +#line 23 "reflect.h2" namespace cpp2 { namespace meta { -#line 34 "reflect.h2" -class compiler_services +#line 35 "reflect.h2" +class compiler_services_base { -#line 38 "reflect.h2" - private: std::vector* errors; - private: std::set* includes; - private: int errors_original_size; - private: stable_vector* generated_tokens; - private: std::vector>* generated_declarations; - private: cpp2::parser parser; - private: std::string metafunction_name {}; - private: std::vector metafunction_args {}; - private: bool metafunctions_used {false}; +#line 39 "reflect.h2" + protected: std::vector* errors; + protected: std::set* includes; + protected: int errors_original_size; + protected: stable_vector* generated_tokens; + protected: std::vector>* generated_declarations; + protected: cpp2::parser parser; + protected: std::string metafunction_name {}; + protected: std::vector metafunction_args {}; + protected: bool metafunctions_used {false}; -#line 50 "reflect.h2" - public: explicit compiler_services( +#line 51 "reflect.h2" + public: explicit compiler_services_base( std::vector* errors_, std::set* includes_, @@ -165,18 +169,12 @@ class compiler_services std::vector>* generated_declarations_ ); -#line 68 "reflect.h2" +#line 67 "reflect.h2" public: auto set_metafunction_name(cpp2::impl::in name, cpp2::impl::in> args) & -> void; -#line 74 "reflect.h2" +#line 73 "reflect.h2" public: [[nodiscard]] auto get_metafunction_name() const& -> std::string_view; - public: [[nodiscard]] auto get_argument(cpp2::impl::in index) & -> std::string; - -#line 84 "reflect.h2" - public: [[nodiscard]] auto get_arguments() & -> std::vector; - -#line 89 "reflect.h2" public: [[nodiscard]] auto arguments_were_used() const& -> bool; private: [[nodiscard]] auto lex_multiline( @@ -186,364 +184,414 @@ class compiler_services using parse_statement_ret = std::unique_ptr; -#line 132 "reflect.h2" +#line 118 "reflect.h2" protected: [[nodiscard]] auto parse_statement( std::string_view source ) & -> parse_statement_ret; -#line 152 "reflect.h2" - public: auto add_runtime_support_include(cpp2::impl::in s) & -> void; - +#line 138 "reflect.h2" protected: [[nodiscard]] auto parse_and_add_declaration( std::string_view source ) & -> bool; -#line 176 "reflect.h2" +#line 160 "reflect.h2" public: [[nodiscard]] virtual auto position() const -> source_position; -#line 185 "reflect.h2" +#line 166 "reflect.h2" public: auto require( cpp2::impl::in b, cpp2::impl::in msg ) const& -> void; -#line 196 "reflect.h2" +#line 177 "reflect.h2" public: auto error(cpp2::impl::in msg) const& -> void; -#line 208 "reflect.h2" - public: auto report_violation(auto const& msg) const& -> void; +#line 186 "reflect.h2" + public: [[nodiscard]] auto is_active() const& -> bool; + public: virtual ~compiler_services_base() noexcept; +public: compiler_services_base(compiler_services_base const& that); -#line 216 "reflect.h2" - public: [[nodiscard]] auto is_active() const& -> auto; +#line 187 "reflect.h2" +}; + +class compiler_services_impl +: public compiler_services_base, public compiler_services::interface { + +#line 195 "reflect.h2" + public: explicit compiler_services_impl(cpp2::impl::in csb); + +#line 199 "reflect.h2" + public: [[nodiscard]] auto get_metafunction_name() const -> std::string_view override; + + public: [[nodiscard]] auto get_argument(cpp2::impl::in index) -> std::string override; + +#line 209 "reflect.h2" + public: [[nodiscard]] auto get_arguments() -> std::vector override; - public: auto append_declaration_to_translation_unit(cpp2::impl::in source) & -> void; - public: virtual ~compiler_services() noexcept; -public: compiler_services(compiler_services const& that); +#line 214 "reflect.h2" + public: auto add_runtime_support_include(cpp2::impl::in s) -> void override; + public: auto append_declaration_to_translation_unit(cpp2::impl::in source) -> void override; -#line 224 "reflect.h2" +#line 223 "reflect.h2" + public: auto require(cpp2::impl::in b, cpp2::impl::in msg) const -> void override; + + public: auto error(cpp2::impl::in msg) const -> void override; + + public: auto report_violation(cpp2::impl::in msg) const -> void override; + public: virtual ~compiler_services_impl() noexcept; + + public: compiler_services_impl(compiler_services_impl const&) = delete; /* No 'that' constructor, suppress copy */ + public: auto operator=(compiler_services_impl const&) -> void = delete; + + +#line 234 "reflect.h2" }; -#line 273 "reflect.h2" +#line 283 "reflect.h2" class declaration_base -: public compiler_services { +: public compiler_services_base { -#line 277 "reflect.h2" +#line 287 "reflect.h2" protected: declaration_node* n; protected: explicit declaration_base( - declaration_node* n_, - cpp2::impl::in s + cpp2::impl::in csb, + declaration_node* n_ ); -#line 290 "reflect.h2" - public: [[nodiscard]] auto position() const -> source_position override; - - public: [[nodiscard]] auto print() const& -> std::string; +#line 300 "reflect.h2" + private: [[nodiscard]] auto position() const -> source_position override; public: virtual ~declaration_base() noexcept; -public: declaration_base(declaration_base const& that); -#line 293 "reflect.h2" + public: declaration_base(declaration_base const&) = delete; /* No 'that' constructor, suppress copy */ + public: auto operator=(declaration_base const&) -> void = delete; + +#line 301 "reflect.h2" }; -#line 299 "reflect.h2" -class declaration -: public declaration_base { +#line 306 "reflect.h2" +[[nodiscard]] auto make_declaration(cpp2::impl::in csb, declaration_node* n) -> auto; -#line 303 "reflect.h2" - public: explicit declaration( +#line 312 "reflect.h2" +[[nodiscard]] auto make_function_declaration(cpp2::impl::in csb, declaration_node* n) -> auto; + +#line 319 "reflect.h2" +[[nodiscard]] auto make_object_declaration(cpp2::impl::in csb, declaration_node* n) -> auto; + +#line 326 "reflect.h2" +[[nodiscard]] auto make_type_declaration(cpp2::impl::in csb, declaration_node* n) -> auto; + +#line 333 "reflect.h2" +[[nodiscard]] auto make_alias_declaration(cpp2::impl::in csb, declaration_node* n) -> auto; + +#line 343 "reflect.h2" +class declaration_impl +: public declaration_base, public declaration::interface { - declaration_node* n_, - cpp2::impl::in s +#line 349 "reflect.h2" + public: explicit declaration_impl( + + cpp2::impl::in csb, + declaration_node* n_ ); -#line 312 "reflect.h2" - public: [[nodiscard]] auto is_public() const& -> bool; - public: [[nodiscard]] auto is_protected() const& -> bool; - public: [[nodiscard]] auto is_private() const& -> bool; - public: [[nodiscard]] auto is_default_access() const& -> bool; +#line 358 "reflect.h2" + public: [[nodiscard]] auto is_public() const -> bool override; + public: [[nodiscard]] auto is_protected() const -> bool override; + public: [[nodiscard]] auto is_private() const -> bool override; + public: [[nodiscard]] auto is_default_access() const -> bool override; + + public: auto default_to_public() -> void override; + public: auto default_to_protected() -> void override; + public: auto default_to_private() -> void override; - public: auto default_to_public() & -> void; - public: auto default_to_protected() & -> void; - public: auto default_to_private() & -> void; + public: [[nodiscard]] auto make_public() -> bool override; + public: [[nodiscard]] auto make_protected() -> bool override; + public: [[nodiscard]] auto make_private() -> bool override; - public: [[nodiscard]] auto make_public() & -> bool; - public: [[nodiscard]] auto make_protected() & -> bool; - public: [[nodiscard]] auto make_private() & -> bool; + public: [[nodiscard]] auto has_name() const -> bool override; + public: [[nodiscard]] auto has_name(cpp2::impl::in s) const -> bool override; - public: [[nodiscard]] auto has_name() const& -> bool; - public: [[nodiscard]] auto has_name(cpp2::impl::in s) const& -> bool; + public: [[nodiscard]] auto name() const -> std::string_view override; - public: [[nodiscard]] auto name() const& -> std::string_view; +#line 378 "reflect.h2" + public: [[nodiscard]] auto fully_qualified_name() const -> std::string override; -#line 332 "reflect.h2" - public: [[nodiscard]] auto fully_qualified_name() const& -> std::string; + public: [[nodiscard]] auto has_initializer() const -> bool override; - public: [[nodiscard]] auto has_initializer() const& -> bool; + public: [[nodiscard]] auto is_global() const -> bool override; + public: [[nodiscard]] auto is_function() const -> bool override; + public: [[nodiscard]] auto is_object() const -> bool override; + public: [[nodiscard]] auto is_base_object() const -> bool override; + public: [[nodiscard]] auto is_member_object() const -> bool override; + public: [[nodiscard]] auto is_type() const -> bool override; + public: [[nodiscard]] auto is_namespace() const -> bool override; + public: [[nodiscard]] auto is_alias() const -> bool override; - public: [[nodiscard]] auto is_global() const& -> bool; - public: [[nodiscard]] auto is_function() const& -> bool; - public: [[nodiscard]] auto is_object() const& -> bool; - public: [[nodiscard]] auto is_base_object() const& -> bool; - public: [[nodiscard]] auto is_member_object() const& -> bool; - public: [[nodiscard]] auto is_type() const& -> bool; - public: [[nodiscard]] auto is_namespace() const& -> bool; - public: [[nodiscard]] auto is_alias() const& -> bool; + public: [[nodiscard]] auto is_type_alias() const -> bool override; + public: [[nodiscard]] auto is_namespace_alias() const -> bool override; + public: [[nodiscard]] auto is_object_alias() const -> bool override; - public: [[nodiscard]] auto is_type_alias() const& -> bool; - public: [[nodiscard]] auto is_namespace_alias() const& -> bool; - public: [[nodiscard]] auto is_object_alias() const& -> bool; + public: [[nodiscard]] auto is_function_expression() const -> bool override; - public: [[nodiscard]] auto is_function_expression() const& -> bool; + public: [[nodiscard]] auto as_function() const -> function_declaration override; + public: [[nodiscard]] auto as_object() const -> object_declaration override; + public: [[nodiscard]] auto as_type() const -> type_declaration override; + public: [[nodiscard]] auto as_alias() const -> alias_declaration override; - public: [[nodiscard]] auto as_function() const& -> function_declaration; - public: [[nodiscard]] auto as_object() const& -> object_declaration; - public: [[nodiscard]] auto as_type() const& -> type_declaration; - public: [[nodiscard]] auto as_alias() const& -> alias_declaration; + public: [[nodiscard]] auto get_parent() const -> declaration override; - public: [[nodiscard]] auto get_parent() const& -> declaration; + public: [[nodiscard]] auto parent_is_function() const -> bool override; + public: [[nodiscard]] auto parent_is_object() const -> bool override; + public: [[nodiscard]] auto parent_is_type() const -> bool override; + public: [[nodiscard]] auto parent_is_namespace() const -> bool override; + public: [[nodiscard]] auto parent_is_alias() const -> bool override; - public: [[nodiscard]] auto parent_is_function() const& -> bool; - public: [[nodiscard]] auto parent_is_object() const& -> bool; - public: [[nodiscard]] auto parent_is_type() const& -> bool; - public: [[nodiscard]] auto parent_is_namespace() const& -> bool; - public: [[nodiscard]] auto parent_is_alias() const& -> bool; + public: [[nodiscard]] auto parent_is_type_alias() const -> bool override; + public: [[nodiscard]] auto parent_is_namespace_alias() const -> bool override; + public: [[nodiscard]] auto parent_is_object_alias() const -> bool override; - public: [[nodiscard]] auto parent_is_type_alias() const& -> bool; - public: [[nodiscard]] auto parent_is_namespace_alias() const& -> bool; - public: [[nodiscard]] auto parent_is_object_alias() const& -> bool; + public: [[nodiscard]] auto parent_is_polymorphic() const -> bool override; - public: [[nodiscard]] auto parent_is_polymorphic() const& -> bool; + public: auto mark_for_removal_from_enclosing_type() -> void override; - public: auto mark_for_removal_from_enclosing_type() & -> void; - public: virtual ~declaration() noexcept; -public: declaration(declaration const& that); +#line 423 "reflect.h2" + public: [[nodiscard]] auto print() const -> std::string override; + public: virtual ~declaration_impl() noexcept; + public: declaration_impl(declaration_impl const&) = delete; /* No 'that' constructor, suppress copy */ + public: auto operator=(declaration_impl const&) -> void = delete; -#line 376 "reflect.h2" +#line 424 "reflect.h2" }; -#line 382 "reflect.h2" -class function_declaration -: public declaration { +#line 430 "reflect.h2" +class function_declaration_impl +: public declaration_base, public function_declaration::interface { -#line 386 "reflect.h2" - public: explicit function_declaration( +#line 436 "reflect.h2" + public: explicit function_declaration_impl( - declaration_node* n_, - cpp2::impl::in s + cpp2::impl::in csb, + declaration_node* n_ ); -#line 396 "reflect.h2" - public: [[nodiscard]] auto index_of_parameter_named(cpp2::impl::in s) const& -> int; - public: [[nodiscard]] auto has_parameter_named(cpp2::impl::in s) const& -> bool; - public: [[nodiscard]] auto has_in_parameter_named(cpp2::impl::in s) const& -> bool; - public: [[nodiscard]] auto has_copy_parameter_named(cpp2::impl::in s) const& -> bool; - public: [[nodiscard]] auto has_inout_parameter_named(cpp2::impl::in s) const& -> bool; - public: [[nodiscard]] auto has_out_parameter_named(cpp2::impl::in s) const& -> bool; - public: [[nodiscard]] auto has_move_parameter_named(cpp2::impl::in s) const& -> bool; - public: [[nodiscard]] auto has_forward_parameter_named(cpp2::impl::in s) const& -> bool; - public: [[nodiscard]] auto first_parameter_name() const& -> std::string; +#line 446 "reflect.h2" + public: [[nodiscard]] auto index_of_parameter_named(cpp2::impl::in s) const -> int override; + public: [[nodiscard]] auto has_parameter_named(cpp2::impl::in s) const -> bool override; + public: [[nodiscard]] auto has_in_parameter_named(cpp2::impl::in s) const -> bool override; + public: [[nodiscard]] auto has_copy_parameter_named(cpp2::impl::in s) const -> bool override; + public: [[nodiscard]] auto has_inout_parameter_named(cpp2::impl::in s) const -> bool override; + public: [[nodiscard]] auto has_out_parameter_named(cpp2::impl::in s) const -> bool override; + public: [[nodiscard]] auto has_move_parameter_named(cpp2::impl::in s) const -> bool override; + public: [[nodiscard]] auto has_forward_parameter_named(cpp2::impl::in s) const -> bool override; + public: [[nodiscard]] auto first_parameter_name() const -> std::string override; - public: [[nodiscard]] auto has_parameter_with_name_and_pass(cpp2::impl::in s, cpp2::impl::in pass) const& -> bool; +#line 458 "reflect.h2" + public: [[nodiscard]] auto is_function_with_this() const -> bool override; + public: [[nodiscard]] auto is_virtual() const -> bool override; + public: [[nodiscard]] auto is_defaultable() const -> bool override; + public: [[nodiscard]] auto is_constructor() const -> bool override; + public: [[nodiscard]] auto is_default_constructor() const -> bool override; + public: [[nodiscard]] auto is_move() const -> bool override; + public: [[nodiscard]] auto is_swap() const -> bool override; + public: [[nodiscard]] auto is_constructor_with_that() const -> bool override; + public: [[nodiscard]] auto is_constructor_with_in_that() const -> bool override; + public: [[nodiscard]] auto is_constructor_with_move_that() const -> bool override; + public: [[nodiscard]] auto is_assignment() const -> bool override; + public: [[nodiscard]] auto is_assignment_with_that() const -> bool override; + public: [[nodiscard]] auto is_assignment_with_in_that() const -> bool override; + public: [[nodiscard]] auto is_assignment_with_move_that() const -> bool override; + public: [[nodiscard]] auto is_destructor() const -> bool override; - public: [[nodiscard]] auto is_function_with_this() const& -> bool; - public: [[nodiscard]] auto is_virtual() const& -> bool; - public: [[nodiscard]] auto is_defaultable() const& -> bool; - public: [[nodiscard]] auto is_constructor() const& -> bool; - public: [[nodiscard]] auto is_default_constructor() const& -> bool; - public: [[nodiscard]] auto is_move() const& -> bool; - public: [[nodiscard]] auto is_swap() const& -> bool; - public: [[nodiscard]] auto is_constructor_with_that() const& -> bool; - public: [[nodiscard]] auto is_constructor_with_in_that() const& -> bool; - public: [[nodiscard]] auto is_constructor_with_move_that() const& -> bool; - public: [[nodiscard]] auto is_assignment() const& -> bool; - public: [[nodiscard]] auto is_assignment_with_that() const& -> bool; - public: [[nodiscard]] auto is_assignment_with_in_that() const& -> bool; - public: [[nodiscard]] auto is_assignment_with_move_that() const& -> bool; - public: [[nodiscard]] auto is_destructor() const& -> bool; + public: [[nodiscard]] auto is_copy_or_move() const -> bool override; - public: [[nodiscard]] auto is_copy_or_move() const& -> bool; + public: [[nodiscard]] auto has_declared_return_type() const -> bool override; + public: [[nodiscard]] auto has_deduced_return_type() const -> bool override; + public: [[nodiscard]] auto has_bool_return_type() const -> bool override; + public: [[nodiscard]] auto has_non_void_return_type() const -> bool override; - public: [[nodiscard]] auto has_declared_return_type() const& -> bool; - public: [[nodiscard]] auto has_deduced_return_type() const& -> bool; - public: [[nodiscard]] auto has_bool_return_type() const& -> bool; - public: [[nodiscard]] auto has_non_void_return_type() const& -> bool; + public: [[nodiscard]] auto unnamed_return_type() const -> std::string override; - public: [[nodiscard]] auto unnamed_return_type() const& -> std::string; + public: [[nodiscard]] auto get_parameters() const -> std::vector override; - public: [[nodiscard]] auto get_parameters() const& -> std::vector; +#line 493 "reflect.h2" + public: [[nodiscard]] auto is_binary_comparison_function() const -> bool override; -#line 443 "reflect.h2" - public: [[nodiscard]] auto is_binary_comparison_function() const& -> bool; + public: auto default_to_virtual() -> void override; - public: auto default_to_virtual() & -> void; + public: [[nodiscard]] auto make_virtual() -> bool override; - public: [[nodiscard]] auto make_virtual() & -> bool; + public: auto add_initializer(cpp2::impl::in source) -> void override; + public: virtual ~function_declaration_impl() noexcept; - public: auto add_initializer(cpp2::impl::in source) & -> void; - public: function_declaration(function_declaration const& that); + public: function_declaration_impl(function_declaration_impl const&) = delete; /* No 'that' constructor, suppress copy */ + public: auto operator=(function_declaration_impl const&) -> void = delete; -#line 466 "reflect.h2" +#line 514 "reflect.h2" }; -#line 472 "reflect.h2" -class object_declaration -: public declaration { +#line 520 "reflect.h2" +class object_declaration_impl +: public declaration_base, public object_declaration::interface { -#line 476 "reflect.h2" - public: explicit object_declaration( +#line 526 "reflect.h2" + public: explicit object_declaration_impl( - declaration_node* n_, - cpp2::impl::in s + cpp2::impl::in csb, + declaration_node* n_ ); -#line 486 "reflect.h2" - public: [[nodiscard]] auto is_const() const& -> bool; - public: [[nodiscard]] auto has_wildcard_type() const& -> bool; +#line 536 "reflect.h2" + public: [[nodiscard]] auto is_const() const -> bool override; + public: [[nodiscard]] auto has_wildcard_type() const -> bool override; + + public: [[nodiscard]] auto type() const -> std::string override; - public: [[nodiscard]] auto type() const& -> std::string; +#line 546 "reflect.h2" + public: [[nodiscard]] auto initializer() const -> std::string override; + public: virtual ~object_declaration_impl() noexcept; -#line 496 "reflect.h2" - public: [[nodiscard]] auto initializer() const& -> std::string; - public: object_declaration(object_declaration const& that); + public: object_declaration_impl(object_declaration_impl const&) = delete; /* No 'that' constructor, suppress copy */ + public: auto operator=(object_declaration_impl const&) -> void = delete; -#line 502 "reflect.h2" +#line 552 "reflect.h2" }; -#line 508 "reflect.h2" -class type_declaration -: public declaration { +#line 558 "reflect.h2" +class type_declaration_impl +: public declaration_base, public type_declaration::interface { -#line 512 "reflect.h2" - public: explicit type_declaration( +#line 564 "reflect.h2" + public: explicit type_declaration_impl( - declaration_node* n_, - cpp2::impl::in s + cpp2::impl::in csb, + declaration_node* n_ ); -#line 522 "reflect.h2" - public: auto reserve_names(cpp2::impl::in name, auto&& ...etc) const& -> void; - -#line 536 "reflect.h2" - public: [[nodiscard]] auto is_polymorphic() const& -> bool; - public: [[nodiscard]] auto is_final() const& -> bool; - public: [[nodiscard]] auto make_final() & -> bool; - - public: [[nodiscard]] auto get_member_functions() const& -> std::vector; +#line 574 "reflect.h2" + public: [[nodiscard]] auto is_polymorphic() const -> bool override; + public: [[nodiscard]] auto is_final() const -> bool override; + public: [[nodiscard]] auto make_final() -> bool override; -#line 551 "reflect.h2" - public: [[nodiscard]] auto get_member_functions_needing_initializer() const& -> std::vector; + public: [[nodiscard]] auto get_member_functions() const -> std::vector override; -#line 566 "reflect.h2" - public: [[nodiscard]] auto get_member_objects() const& -> std::vector; +#line 595 "reflect.h2" + public: [[nodiscard]] auto get_member_functions_needing_initializer() const -> std::vector override; -#line 576 "reflect.h2" - public: [[nodiscard]] auto get_member_types() const& -> std::vector; +#line 610 "reflect.h2" + public: [[nodiscard]] auto get_member_objects() const -> std::vector override; -#line 586 "reflect.h2" - public: [[nodiscard]] auto get_member_aliases() const& -> std::vector; +#line 620 "reflect.h2" + public: [[nodiscard]] auto get_member_types() const -> std::vector override; -#line 596 "reflect.h2" - public: [[nodiscard]] auto get_members() const& -> std::vector; -struct query_declared_value_set_functions_ret { bool out_this_in_that; bool out_this_move_that; bool inout_this_in_that; bool inout_this_move_that; }; +#line 630 "reflect.h2" + public: [[nodiscard]] auto get_member_aliases() const -> std::vector override; +#line 640 "reflect.h2" + public: [[nodiscard]] auto get_members() const -> std::vector override; +#line 650 "reflect.h2" + public: [[nodiscard]] auto query_declared_value_set_functions() const -> _query_declared_value_set_functions_ret override; -#line 606 "reflect.h2" - public: [[nodiscard]] auto query_declared_value_set_functions() const& -> query_declared_value_set_functions_ret; +#line 662 "reflect.h2" + public: auto add_member(cpp2::impl::in source) -> void override; -#line 621 "reflect.h2" - public: auto add_member(cpp2::impl::in source) & -> void; +#line 676 "reflect.h2" + public: auto remove_marked_members() -> void override; + public: auto remove_all_members() -> void override; -#line 635 "reflect.h2" - public: auto remove_marked_members() & -> void; - public: auto remove_all_members() & -> void; + public: auto disable_member_function_generation() -> void override; + public: virtual ~type_declaration_impl() noexcept; - public: auto disable_member_function_generation() & -> void; - public: type_declaration(type_declaration const& that); + public: type_declaration_impl(type_declaration_impl const&) = delete; /* No 'that' constructor, suppress copy */ + public: auto operator=(type_declaration_impl const&) -> void = delete; -#line 639 "reflect.h2" +#line 680 "reflect.h2" }; -#line 645 "reflect.h2" -class alias_declaration -: public declaration { +#line 686 "reflect.h2" +class alias_declaration_impl +: public declaration_base, public alias_declaration::interface { -#line 649 "reflect.h2" - public: explicit alias_declaration( +#line 692 "reflect.h2" + public: explicit alias_declaration_impl( - declaration_node* n_, - cpp2::impl::in s + cpp2::impl::in csb, + declaration_node* n_ ); - public: alias_declaration(alias_declaration const& that); + public: virtual ~alias_declaration_impl() noexcept; + + public: alias_declaration_impl(alias_declaration_impl const&) = delete; /* No 'that' constructor, suppress copy */ + public: auto operator=(alias_declaration_impl const&) -> void = delete; -#line 658 "reflect.h2" +#line 701 "reflect.h2" }; -#line 673 "reflect.h2" +#line 716 "reflect.h2" auto add_virtual_destructor(meta::type_declaration& t) -> void; -#line 693 "reflect.h2" +#line 736 "reflect.h2" auto foreign_interface_pseudovalue(meta::type_declaration& t) -> void; -#line 767 "reflect.h2" +#line 810 "reflect.h2" auto interface(meta::type_declaration& t) -> void; -#line 813 "reflect.h2" +#line 856 "reflect.h2" auto polymorphic_base(meta::type_declaration& t) -> void; -#line 858 "reflect.h2" +#line 901 "reflect.h2" auto ordered_impl( meta::type_declaration& t, cpp2::impl::in ordering ) -> void; -#line 887 "reflect.h2" +#line 930 "reflect.h2" auto ordered(meta::type_declaration& t) -> void; -#line 895 "reflect.h2" +#line 938 "reflect.h2" auto weakly_ordered(meta::type_declaration& t) -> void; -#line 903 "reflect.h2" +#line 946 "reflect.h2" auto partially_ordered(meta::type_declaration& t) -> void; -#line 925 "reflect.h2" +#line 968 "reflect.h2" auto copyable(meta::type_declaration& t) -> void; -#line 959 "reflect.h2" +#line 1002 "reflect.h2" auto basic_value(meta::type_declaration& t) -> void; -#line 987 "reflect.h2" +#line 1030 "reflect.h2" auto value(meta::type_declaration& t) -> void; -#line 993 "reflect.h2" +#line 1036 "reflect.h2" auto weakly_ordered_value(meta::type_declaration& t) -> void; -#line 999 "reflect.h2" +#line 1042 "reflect.h2" auto partially_ordered_value(meta::type_declaration& t) -> void; -#line 1028 "reflect.h2" +#line 1071 "reflect.h2" auto cpp1_rule_of_zero(meta::type_declaration& t) -> void; -#line 1065 "reflect.h2" +#line 1108 "reflect.h2" auto cpp2_struct(meta::type_declaration& t) -> void; -#line 1129 "reflect.h2" +#line 1172 "reflect.h2" class value_member_info { public: std::string name; public: std::string type; public: std::string value; public: value_member_info(auto const& name_, auto const& type_, auto const& value_); -#line 1133 "reflect.h2" +#line 1176 "reflect.h2" }; auto basic_enum( @@ -552,28 +600,28 @@ auto basic_enum( cpp2::impl::in bitwise ) -> void; -#line 1399 "reflect.h2" +#line 1442 "reflect.h2" auto cpp2_enum(meta::type_declaration& t) -> void; -#line 1426 "reflect.h2" +#line 1469 "reflect.h2" auto flag_enum(meta::type_declaration& t) -> void; -#line 1472 "reflect.h2" +#line 1515 "reflect.h2" auto cpp2_union(meta::type_declaration& t) -> void; -#line 1623 "reflect.h2" +#line 1666 "reflect.h2" auto print(cpp2::impl::in t) -> void; -#line 1628 "reflect.h2" +#line 1671 "reflect.h2" auto print(cpp2::impl::in f) -> void; -#line 1638 "reflect.h2" +#line 1681 "reflect.h2" auto meta(meta::function_declaration& f) -> void; -#line 1668 "reflect.h2" +#line 1711 "reflect.h2" using error_func = std::function x)>; -#line 1672 "reflect.h2" +#line 1715 "reflect.h2" class expression_flags { private: cpp2::u8 _value; private: constexpr expression_flags(cpp2::impl::in _val); @@ -608,20 +656,20 @@ public: [[nodiscard]] auto to_code() const& -> std::string; public: [[nodiscard]] static auto from_string(cpp2::impl::in s) -> expression_flags; public: [[nodiscard]] static auto from_code(cpp2::impl::in s) -> expression_flags; -#line 1680 "reflect.h2" +#line 1723 "reflect.h2" }; -#line 1688 "reflect.h2" +#line 1731 "reflect.h2" class regex_token { public: std::string string_rep; public: explicit regex_token(cpp2::impl::in str); -#line 1696 "reflect.h2" +#line 1739 "reflect.h2" public: explicit regex_token(); -#line 1701 "reflect.h2" +#line 1744 "reflect.h2" public: virtual auto generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void = 0; public: virtual auto add_groups([[maybe_unused]] std::set& unnamed_param_2) const -> void; @@ -632,24 +680,24 @@ class regex_token public: regex_token(regex_token const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(regex_token const&) -> void = delete; -#line 1706 "reflect.h2" +#line 1749 "reflect.h2" }; using token_ptr = std::shared_ptr; using token_vec = std::vector; -#line 1712 "reflect.h2" +#line 1755 "reflect.h2" // Adds a check in code generation. // class regex_token_check : public regex_token { -#line 1718 "reflect.h2" +#line 1761 "reflect.h2" private: std::string check; public: explicit regex_token_check(cpp2::impl::in str, cpp2::impl::in check_); -#line 1725 "reflect.h2" +#line 1768 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~regex_token_check() noexcept; @@ -657,21 +705,21 @@ class regex_token_check public: auto operator=(regex_token_check const&) -> void = delete; -#line 1728 "reflect.h2" +#line 1771 "reflect.h2" }; -#line 1731 "reflect.h2" +#line 1774 "reflect.h2" // Adds code in code generation. // class regex_token_code : public regex_token { -#line 1737 "reflect.h2" +#line 1780 "reflect.h2" private: std::string code; public: explicit regex_token_code(cpp2::impl::in str, cpp2::impl::in code_); -#line 1744 "reflect.h2" +#line 1787 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~regex_token_code() noexcept; @@ -679,19 +727,19 @@ class regex_token_code public: auto operator=(regex_token_code const&) -> void = delete; -#line 1747 "reflect.h2" +#line 1790 "reflect.h2" }; -#line 1750 "reflect.h2" +#line 1793 "reflect.h2" // Token that does not influence the matching. E.g. comment. // class regex_token_empty : public regex_token { -#line 1756 "reflect.h2" +#line 1799 "reflect.h2" public: explicit regex_token_empty(cpp2::impl::in str); -#line 1760 "reflect.h2" +#line 1803 "reflect.h2" public: auto generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void override; public: virtual ~regex_token_empty() noexcept; @@ -699,27 +747,27 @@ class regex_token_empty public: auto operator=(regex_token_empty const&) -> void = delete; -#line 1763 "reflect.h2" +#line 1806 "reflect.h2" }; -#line 1766 "reflect.h2" +#line 1809 "reflect.h2" // Represents a list of regex tokens as one token. // class regex_token_list : public regex_token { -#line 1772 "reflect.h2" +#line 1815 "reflect.h2" public: token_vec tokens; public: explicit regex_token_list(cpp2::impl::in t); -#line 1779 "reflect.h2" +#line 1822 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 1785 "reflect.h2" +#line 1828 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; -#line 1791 "reflect.h2" +#line 1834 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in vec) -> std::string; public: virtual ~regex_token_list() noexcept; @@ -727,10 +775,10 @@ class regex_token_list public: auto operator=(regex_token_list const&) -> void = delete; -#line 1798 "reflect.h2" +#line 1841 "reflect.h2" }; -#line 1801 "reflect.h2" +#line 1844 "reflect.h2" // // Parse and generation context. // @@ -746,33 +794,33 @@ class parse_context_group_state // Start a new alternative. public: auto next_alternative() & -> void; -#line 1821 "reflect.h2" +#line 1864 "reflect.h2" // Swap this state with the other one. public: auto swap(parse_context_group_state& t) & -> void; -#line 1828 "reflect.h2" +#line 1871 "reflect.h2" // Convert this state into a regex token. public: [[nodiscard]] auto get_as_token() & -> token_ptr; -#line 1840 "reflect.h2" +#line 1883 "reflect.h2" // Add a token to the current matcher list. public: auto add(cpp2::impl::in token) & -> void; -#line 1845 "reflect.h2" +#line 1888 "reflect.h2" // True if current matcher list is empty. public: [[nodiscard]] auto empty() const& -> bool; -#line 1849 "reflect.h2" +#line 1892 "reflect.h2" // Apply optimizations to the matcher list. public: static auto post_process_list(token_vec& list) -> void; public: parse_context_group_state(auto const& cur_match_list_, auto const& alternate_match_lists_, auto const& modifiers_); public: parse_context_group_state(); -#line 1863 "reflect.h2" +#line 1906 "reflect.h2" }; -#line 1866 "reflect.h2" +#line 1909 "reflect.h2" // State for the branch reset. Takes care of the group numbering. See '(|)'. // class parse_context_branch_reset_state @@ -785,25 +833,25 @@ class parse_context_branch_reset_state // Next group identifier. public: [[nodiscard]] auto next() & -> int; -#line 1884 "reflect.h2" +#line 1927 "reflect.h2" // Set next group identifier. public: auto set_next(cpp2::impl::in g) & -> void; -#line 1890 "reflect.h2" +#line 1933 "reflect.h2" // Start a new alternative branch. public: auto next_alternative() & -> void; -#line 1897 "reflect.h2" +#line 1940 "reflect.h2" // Initialize for a branch reset group. public: auto set_active_reset(cpp2::impl::in restart) & -> void; public: parse_context_branch_reset_state(auto const& is_active_, auto const& cur_group_, auto const& max_group_, auto const& from_); public: parse_context_branch_reset_state(); -#line 1904 "reflect.h2" +#line 1947 "reflect.h2" }; -#line 1907 "reflect.h2" +#line 1950 "reflect.h2" // Context during parsing of the regular expressions. // // Keeps track of the distributed group identifiers, current parsed group and branch resets. @@ -817,7 +865,7 @@ class parse_context private: parse_context_group_state cur_group_state {}; private: parse_context_branch_reset_state cur_branch_reset_state {}; -#line 1921 "reflect.h2" +#line 1964 "reflect.h2" public: std::map named_groups {}; private: error_func error_out; // TODO: Declaring std::function fails for cpp2. @@ -825,64 +873,64 @@ class parse_context public: explicit parse_context(cpp2::impl::in r, auto const& e); -#line 1932 "reflect.h2" +#line 1975 "reflect.h2" // State management functions // // Returned group state needs to be stored and provided in `end_group`. public: [[nodiscard]] auto start_group() & -> parse_context_group_state; -#line 1945 "reflect.h2" +#line 1988 "reflect.h2" // `old_state` argument needs to be from start group. public: [[nodiscard]] auto end_group(cpp2::impl::in old_state) & -> token_ptr; -#line 1953 "reflect.h2" +#line 1996 "reflect.h2" public: [[nodiscard]] auto get_modifiers() const& -> expression_flags; -#line 1957 "reflect.h2" +#line 2000 "reflect.h2" public: auto set_modifiers(cpp2::impl::in mod) & -> void; -#line 1961 "reflect.h2" +#line 2004 "reflect.h2" // Branch reset management functions // public: [[nodiscard]] auto branch_reset_new_state() & -> parse_context_branch_reset_state; -#line 1973 "reflect.h2" +#line 2016 "reflect.h2" public: auto branch_reset_restore_state(cpp2::impl::in old_state) & -> void; -#line 1980 "reflect.h2" +#line 2023 "reflect.h2" public: auto next_alternative() & -> void; -#line 1986 "reflect.h2" +#line 2029 "reflect.h2" // Regex token management // public: auto add_token(cpp2::impl::in token) & -> void; -#line 1992 "reflect.h2" +#line 2035 "reflect.h2" public: [[nodiscard]] auto has_token() const& -> bool; -#line 1996 "reflect.h2" +#line 2039 "reflect.h2" public: [[nodiscard]] auto pop_token() & -> token_ptr; -#line 2007 "reflect.h2" +#line 2050 "reflect.h2" public: [[nodiscard]] auto get_as_token() & -> token_ptr; -#line 2011 "reflect.h2" +#line 2054 "reflect.h2" // Group management // public: [[nodiscard]] auto get_cur_group() const& -> int; -#line 2017 "reflect.h2" +#line 2060 "reflect.h2" public: [[nodiscard]] auto next_group() & -> int; -#line 2021 "reflect.h2" +#line 2064 "reflect.h2" public: auto set_named_group(cpp2::impl::in name, cpp2::impl::in id) & -> void; -#line 2028 "reflect.h2" +#line 2071 "reflect.h2" public: [[nodiscard]] auto get_named_group(cpp2::impl::in name) const& -> int; -#line 2039 "reflect.h2" +#line 2082 "reflect.h2" // Position management functions // public: [[nodiscard]] auto current() const& -> char; @@ -890,51 +938,51 @@ class parse_context // Get the next token in the regex, skipping spaces according to the parameters. See `x` and `xx` modifiers. private: [[nodiscard]] auto get_next_position(cpp2::impl::in in_class, cpp2::impl::in no_skip) const& -> size_t; -#line 2083 "reflect.h2" +#line 2126 "reflect.h2" // Return true if next token is available. private: [[nodiscard]] auto next_impl(cpp2::impl::in in_class, cpp2::impl::in no_skip) & -> bool; -#line 2095 "reflect.h2" +#line 2138 "reflect.h2" public: [[nodiscard]] auto next() & -> auto; public: [[nodiscard]] auto next_in_class() & -> auto; public: [[nodiscard]] auto next_no_skip() & -> auto; public: [[nodiscard]] auto next_n(cpp2::impl::in n) & -> bool; -#line 2108 "reflect.h2" +#line 2151 "reflect.h2" public: [[nodiscard]] auto has_next() const& -> bool; private: [[nodiscard]] auto grab_until_impl(cpp2::impl::in e, cpp2::impl::out r, cpp2::impl::in any) & -> bool; -#line 2131 "reflect.h2" +#line 2174 "reflect.h2" public: [[nodiscard]] auto grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_until_one_of(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_n(cpp2::impl::in n, cpp2::impl::out r) & -> bool; -#line 2148 "reflect.h2" +#line 2191 "reflect.h2" public: [[nodiscard]] auto grab_number() & -> std::string; -#line 2169 "reflect.h2" +#line 2212 "reflect.h2" private: [[nodiscard]] auto peek_impl(cpp2::impl::in in_class) const& -> char; -#line 2179 "reflect.h2" +#line 2222 "reflect.h2" public: [[nodiscard]] auto peek() const& -> auto; public: [[nodiscard]] auto peek_in_class() const& -> auto; -#line 2183 "reflect.h2" +#line 2226 "reflect.h2" // Parsing functions // public: [[nodiscard]] auto parser_group_modifiers(cpp2::impl::in change_str, expression_flags& parser_modifiers) & -> bool; -#line 2239 "reflect.h2" +#line 2282 "reflect.h2" public: [[nodiscard]] auto parse_until(cpp2::impl::in term) & -> bool; -#line 2277 "reflect.h2" +#line 2320 "reflect.h2" public: [[nodiscard]] auto parse(cpp2::impl::in modifiers) & -> bool; -#line 2292 "reflect.h2" +#line 2335 "reflect.h2" // Misc functions public: [[nodiscard]] auto get_pos() const& -> auto; @@ -946,10 +994,10 @@ class parse_context public: auto operator=(parse_context const&) -> void = delete; -#line 2303 "reflect.h2" +#line 2346 "reflect.h2" }; -#line 2306 "reflect.h2" +#line 2349 "reflect.h2" // Context for one function generation. Generation of functions can be interleaved, // therefore we buffer the code for one function here. // @@ -959,16 +1007,16 @@ class generation_function_context { public: auto add_tabs(cpp2::impl::in c) & -> void; -#line 2320 "reflect.h2" +#line 2363 "reflect.h2" public: auto remove_tabs(cpp2::impl::in c) & -> void; public: generation_function_context(auto const& code_, auto const& tabs_); public: generation_function_context(); -#line 2323 "reflect.h2" +#line 2366 "reflect.h2" }; -#line 2326 "reflect.h2" +#line 2369 "reflect.h2" // Context for generating the state machine. class generation_context { @@ -988,68 +1036,68 @@ class generation_context // Add code line. public: auto add(cpp2::impl::in s) & -> void; -#line 2348 "reflect.h2" +#line 2391 "reflect.h2" // Add check for token. The check needs to be a function call that returns a boolean. public: auto add_check(cpp2::impl::in check) & -> void; -#line 2354 "reflect.h2" +#line 2397 "reflect.h2" // Add a stateful check. The check needs to return a `match_return`. public: auto add_statefull(cpp2::impl::in next_func, cpp2::impl::in check) & -> void; -#line 2363 "reflect.h2" +#line 2406 "reflect.h2" protected: auto start_func_named(cpp2::impl::in name) & -> void; -#line 2374 "reflect.h2" +#line 2417 "reflect.h2" protected: [[nodiscard]] auto start_func() & -> std::string; -#line 2381 "reflect.h2" +#line 2424 "reflect.h2" protected: auto end_func_statefull(cpp2::impl::in s) & -> void; -#line 2400 "reflect.h2" +#line 2443 "reflect.h2" // Generate the function for a token. public: [[nodiscard]] auto generate_func(cpp2::impl::in token) & -> std::string; -#line 2410 "reflect.h2" +#line 2453 "reflect.h2" // Generate the reset for a list of group identifiers. public: [[nodiscard]] auto generate_reset(cpp2::impl::in> groups) & -> std::string; -#line 2433 "reflect.h2" +#line 2476 "reflect.h2" // Name generation // protected: [[nodiscard]] auto gen_func_name() & -> std::string; -#line 2441 "reflect.h2" +#line 2484 "reflect.h2" public: [[nodiscard]] auto next_func_name() & -> std::string; -#line 2445 "reflect.h2" +#line 2488 "reflect.h2" protected: [[nodiscard]] auto gen_reset_func_name() & -> std::string; -#line 2451 "reflect.h2" +#line 2494 "reflect.h2" public: [[nodiscard]] auto gen_temp() & -> std::string; -#line 2457 "reflect.h2" +#line 2500 "reflect.h2" // Context management // public: [[nodiscard]] auto new_context() & -> generation_function_context*; -#line 2467 "reflect.h2" +#line 2510 "reflect.h2" public: auto finish_context() & -> void; -#line 2475 "reflect.h2" +#line 2518 "reflect.h2" // Misc functions // private: [[nodiscard]] auto get_current() & -> generation_function_context*; -#line 2481 "reflect.h2" +#line 2524 "reflect.h2" private: [[nodiscard]] auto get_base() & -> generation_function_context*; -#line 2485 "reflect.h2" +#line 2528 "reflect.h2" public: [[nodiscard]] auto get_entry_func() const& -> std::string; -#line 2489 "reflect.h2" +#line 2532 "reflect.h2" public: [[nodiscard]] auto create_named_group_lookup(cpp2::impl::in> named_groups) const& -> std::string; -#line 2513 "reflect.h2" +#line 2556 "reflect.h2" // Run the generation for the token. public: [[nodiscard]] auto run(cpp2::impl::in token) & -> std::string; public: generation_context() = default; @@ -1057,7 +1105,7 @@ class generation_context public: auto operator=(generation_context const&) -> void = delete; -#line 2519 "reflect.h2" +#line 2562 "reflect.h2" }; // Regex syntax: | Example: ab|ba @@ -1077,24 +1125,24 @@ class alternative_token public: auto operator=(alternative_token const&) -> void = delete; -#line 2538 "reflect.h2" +#line 2581 "reflect.h2" }; class alternative_token_gen : public regex_token { -#line 2544 "reflect.h2" +#line 2587 "reflect.h2" private: token_vec alternatives; public: explicit alternative_token_gen(cpp2::impl::in a); -#line 2551 "reflect.h2" +#line 2594 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2568 "reflect.h2" +#line 2611 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; -#line 2575 "reflect.h2" +#line 2618 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in a) -> std::string; public: virtual ~alternative_token_gen() noexcept; @@ -1102,19 +1150,19 @@ class alternative_token_gen public: auto operator=(alternative_token_gen const&) -> void = delete; -#line 2587 "reflect.h2" +#line 2630 "reflect.h2" }; -#line 2590 "reflect.h2" +#line 2633 "reflect.h2" // Regex syntax: . // class any_token : public regex_token_check { -#line 2596 "reflect.h2" +#line 2639 "reflect.h2" public: explicit any_token(cpp2::impl::in single_line); -#line 2600 "reflect.h2" +#line 2643 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; public: virtual ~any_token() noexcept; @@ -1122,37 +1170,37 @@ class any_token public: auto operator=(any_token const&) -> void = delete; -#line 2605 "reflect.h2" +#line 2648 "reflect.h2" }; -#line 2608 "reflect.h2" +#line 2651 "reflect.h2" // Regex syntax: a // class char_token : public regex_token { -#line 2614 "reflect.h2" +#line 2657 "reflect.h2" private: std::string token; private: bool ignore_case; public: explicit char_token(cpp2::impl::in t, cpp2::impl::in ignore_case_); -#line 2623 "reflect.h2" +#line 2666 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 2627 "reflect.h2" +#line 2670 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2650 "reflect.h2" +#line 2693 "reflect.h2" public: auto gen_case_insensitive(cpp2::impl::in lower, cpp2::impl::in upper, generation_context& ctx) const& -> void; -#line 2671 "reflect.h2" +#line 2714 "reflect.h2" public: auto gen_case_sensitive(generation_context& ctx) const& -> void; -#line 2689 "reflect.h2" +#line 2732 "reflect.h2" public: [[nodiscard]] auto add_escapes(std::string str) const& -> std::string; -#line 2704 "reflect.h2" +#line 2747 "reflect.h2" public: auto append(char_token const& that) & -> void; public: virtual ~char_token() noexcept; @@ -1160,30 +1208,30 @@ class char_token public: auto operator=(char_token const&) -> void = delete; -#line 2708 "reflect.h2" +#line 2751 "reflect.h2" }; -#line 2711 "reflect.h2" +#line 2754 "reflect.h2" // Regex syntax: [] Example: [abcx-y[:digits:]] // class class_token : public regex_token { -#line 2717 "reflect.h2" +#line 2760 "reflect.h2" private: bool negate; private: bool case_insensitive; private: std::string class_str; public: explicit class_token(cpp2::impl::in negate_, cpp2::impl::in case_insensitive_, cpp2::impl::in class_str_, cpp2::impl::in str); -#line 2729 "reflect.h2" +#line 2772 "reflect.h2" // TODO: Rework class generation: Generate check functions for classes. public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 2855 "reflect.h2" +#line 2898 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2860 "reflect.h2" +#line 2903 "reflect.h2" private: [[nodiscard]] static auto create_matcher(cpp2::impl::in name, cpp2::impl::in template_arguments) -> std::string; public: virtual ~class_token() noexcept; @@ -1191,20 +1239,20 @@ class class_token public: auto operator=(class_token const&) -> void = delete; -#line 2867 "reflect.h2" +#line 2910 "reflect.h2" }; -#line 2870 "reflect.h2" +#line 2913 "reflect.h2" // Regex syntax: \a or \n or \[ // [[nodiscard]] auto escape_token_parse(parse_context& ctx) -> token_ptr; -#line 2911 "reflect.h2" +#line 2954 "reflect.h2" // Regex syntax: \K Example: ab\Kcd // [[nodiscard]] auto global_group_reset_token_parse(parse_context& ctx) -> token_ptr; -#line 2922 "reflect.h2" +#line 2965 "reflect.h2" // Regex syntax: \ Example: \1 // \g{name_or_number} // \k{name_or_number} @@ -1214,16 +1262,16 @@ class class_token class group_ref_token : public regex_token { -#line 2932 "reflect.h2" +#line 2975 "reflect.h2" private: int id; private: bool case_insensitive; public: explicit group_ref_token(cpp2::impl::in id_, cpp2::impl::in case_insensitive_, cpp2::impl::in str); -#line 2942 "reflect.h2" +#line 2985 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 3043 "reflect.h2" +#line 3086 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~group_ref_token() noexcept; @@ -1231,10 +1279,10 @@ class group_ref_token public: auto operator=(group_ref_token const&) -> void = delete; -#line 3046 "reflect.h2" +#line 3089 "reflect.h2" }; -#line 3049 "reflect.h2" +#line 3092 "reflect.h2" // Regex syntax: () Example: (abc) // (?:) (?i:abc) @@ -1248,22 +1296,22 @@ class group_ref_token class group_token : public regex_token { -#line 3063 "reflect.h2" +#line 3106 "reflect.h2" private: int number {-1}; private: token_ptr inner {nullptr}; public: [[nodiscard]] static auto parse_lookahead(parse_context& ctx, cpp2::impl::in syntax, cpp2::impl::in positive) -> token_ptr; -#line 3080 "reflect.h2" +#line 3123 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 3217 "reflect.h2" +#line 3260 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in name, cpp2::impl::in name_brackets, cpp2::impl::in has_modifier, cpp2::impl::in modifiers, cpp2::impl::in inner_) -> std::string; -#line 3235 "reflect.h2" +#line 3278 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3255 "reflect.h2" +#line 3298 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~group_token() noexcept; @@ -1272,25 +1320,25 @@ class group_token public: auto operator=(group_token const&) -> void = delete; -#line 3262 "reflect.h2" +#line 3305 "reflect.h2" }; -#line 3265 "reflect.h2" +#line 3308 "reflect.h2" // Regex syntax: \x or \x{} Example: \x{62} // [[nodiscard]] auto hexadecimal_token_parse(parse_context& ctx) -> token_ptr; -#line 3306 "reflect.h2" +#line 3349 "reflect.h2" // Regex syntax: $ Example: aa$ // [[nodiscard]] auto line_end_token_parse(parse_context& ctx) -> token_ptr; -#line 3326 "reflect.h2" +#line 3369 "reflect.h2" // Regex syntax: ^ Example: ^aa // [[nodiscard]] auto line_start_token_parse(parse_context& ctx) -> token_ptr; -#line 3342 "reflect.h2" +#line 3385 "reflect.h2" // Regex syntax: (?=) or (?!) or (*pla), etc. Example: (?=AA) // // Parsed in group_token. @@ -1298,16 +1346,16 @@ class group_token class lookahead_token : public regex_token { -#line 3350 "reflect.h2" +#line 3393 "reflect.h2" protected: bool positive; public: token_ptr inner {nullptr}; public: explicit lookahead_token(cpp2::impl::in positive_); -#line 3357 "reflect.h2" +#line 3400 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3363 "reflect.h2" +#line 3406 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~lookahead_token() noexcept; @@ -1315,26 +1363,26 @@ class lookahead_token public: auto operator=(lookahead_token const&) -> void = delete; -#line 3366 "reflect.h2" +#line 3409 "reflect.h2" }; -#line 3369 "reflect.h2" +#line 3412 "reflect.h2" // Named character classes // [[nodiscard]] auto named_class_token_parse(parse_context& ctx) -> token_ptr; -#line 3397 "reflect.h2" +#line 3440 "reflect.h2" // Regex syntax: \o{} Example: \o{142} // [[nodiscard]] auto octal_token_parse(parse_context& ctx) -> token_ptr; -#line 3425 "reflect.h2" +#line 3468 "reflect.h2" // Regex syntax: {min, max} Example: a{2,4} // class range_token : public regex_token { -#line 3431 "reflect.h2" +#line 3474 "reflect.h2" protected: int min_count {-1}; protected: int max_count {-1}; protected: int kind {range_flags::greedy}; @@ -1344,19 +1392,19 @@ class range_token public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 3511 "reflect.h2" +#line 3554 "reflect.h2" public: auto parse_modifier(parse_context& ctx) & -> void; -#line 3523 "reflect.h2" +#line 3566 "reflect.h2" public: [[nodiscard]] auto gen_mod_string() const& -> std::string; -#line 3536 "reflect.h2" +#line 3579 "reflect.h2" public: [[nodiscard]] auto gen_range_string() const& -> std::string; -#line 3555 "reflect.h2" +#line 3598 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3566 "reflect.h2" +#line 3609 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~range_token() noexcept; @@ -1364,16 +1412,16 @@ class range_token public: auto operator=(range_token const&) -> void = delete; -#line 3570 "reflect.h2" +#line 3613 "reflect.h2" }; -#line 3573 "reflect.h2" +#line 3616 "reflect.h2" // Regex syntax: *, +, or ? Example: aa* // class special_range_token : public range_token { -#line 3579 "reflect.h2" +#line 3622 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; public: virtual ~special_range_token() noexcept; @@ -1382,17 +1430,17 @@ class special_range_token public: auto operator=(special_range_token const&) -> void = delete; -#line 3609 "reflect.h2" +#line 3652 "reflect.h2" }; -#line 3612 "reflect.h2" +#line 3655 "reflect.h2" // Regex syntax: \b or \B Example: \bword\b // // Matches the start end end of word boundaries. // [[nodiscard]] auto word_boundary_token_parse(parse_context& ctx) -> token_ptr; -#line 3634 "reflect.h2" +#line 3677 "reflect.h2" //----------------------------------------------------------------------- // // Parser for regular expression. @@ -1413,46 +1461,46 @@ template class regex_generator public: explicit regex_generator(cpp2::impl::in r, Error_out const& e); -#line 3657 "reflect.h2" +#line 3700 "reflect.h2" public: [[nodiscard]] auto parse() & -> std::string; -#line 3692 "reflect.h2" +#line 3735 "reflect.h2" private: auto extract_modifiers() & -> void; public: regex_generator(regex_generator const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(regex_generator const&) -> void = delete; -#line 3706 "reflect.h2" +#line 3749 "reflect.h2" }; template [[nodiscard]] auto generate_regex(cpp2::impl::in regex, Err const& err) -> std::string; -#line 3718 "reflect.h2" +#line 3761 "reflect.h2" auto regex_gen(meta::type_declaration& t) -> void; -#line 3773 "reflect.h2" +#line 3816 "reflect.h2" //----------------------------------------------------------------------- // // apply_metafunctions - for types // [[nodiscard]] auto apply_metafunctions( declaration_node& n, - type_declaration& rtype, + type_declaration_impl& rtypeimpl, auto const& error ) -> bool; -#line 3895 "reflect.h2" +#line 3942 "reflect.h2" //----------------------------------------------------------------------- // // apply_metafunctions - for functions // [[nodiscard]] auto apply_metafunctions( declaration_node& n, - function_declaration& rfunc, + function_declaration_impl& rfuncimpl, auto const& error ) -> bool; -#line 3952 "reflect.h2" +#line 4003 "reflect.h2" } } @@ -1462,12 +1510,12 @@ auto regex_gen(meta::type_declaration& t) -> void; #line 1 "reflect.h2" -#line 22 "reflect.h2" +#line 23 "reflect.h2" namespace cpp2 { namespace meta { -#line 27 "reflect.h2" +#line 28 "reflect.h2" //----------------------------------------------------------------------- // // Compiler services @@ -1475,15 +1523,15 @@ namespace meta { //----------------------------------------------------------------------- // -#line 36 "reflect.h2" +#line 37 "reflect.h2" // Common data members // -#line 48 "reflect.h2" +#line 49 "reflect.h2" // Constructor // -#line 50 "reflect.h2" - compiler_services::compiler_services( +#line 51 "reflect.h2" + compiler_services_base::compiler_services_base( std::vector* errors_, std::set* includes_, @@ -1496,44 +1544,27 @@ namespace meta { , generated_tokens{ generated_tokens_ } , generated_declarations{ generated_declarations_ } , parser{ *cpp2::impl::assert_not_null(errors), *cpp2::impl::assert_not_null(includes) } -#line 57 "reflect.h2" +#line 58 "reflect.h2" { -#line 64 "reflect.h2" +#line 65 "reflect.h2" } - // Common API - // -#line 68 "reflect.h2" - auto compiler_services::set_metafunction_name(cpp2::impl::in name, cpp2::impl::in> args) & -> void{ +#line 67 "reflect.h2" + auto compiler_services_base::set_metafunction_name(cpp2::impl::in name, cpp2::impl::in> args) & -> void{ metafunction_name = name; metafunction_args = args; metafunctions_used = CPP2_UFCS(empty)(args); } -#line 74 "reflect.h2" - [[nodiscard]] auto compiler_services::get_metafunction_name() const& -> std::string_view { return metafunction_name; } +#line 73 "reflect.h2" + [[nodiscard]] auto compiler_services_base::get_metafunction_name() const& -> std::string_view { return metafunction_name; } -#line 76 "reflect.h2" - [[nodiscard]] auto compiler_services::get_argument(cpp2::impl::in index) & -> std::string{ - metafunctions_used = true; - if (([_0 = 0, _1 = index, _2 = CPP2_UFCS(ssize)(metafunction_args)]{ return cpp2::impl::cmp_less_eq(_0,_1) && cpp2::impl::cmp_less(_1,_2); }())) { - return CPP2_ASSERT_IN_BOUNDS(metafunction_args, index); - } - return ""; - } - -#line 84 "reflect.h2" - [[nodiscard]] auto compiler_services::get_arguments() & -> std::vector{ - metafunctions_used = true; - return metafunction_args; - } - -#line 89 "reflect.h2" - [[nodiscard]] auto compiler_services::arguments_were_used() const& -> bool { return metafunctions_used; } +#line 75 "reflect.h2" + [[nodiscard]] auto compiler_services_base::arguments_were_used() const& -> bool { return metafunctions_used; } -#line 91 "reflect.h2" - [[nodiscard]] auto compiler_services::lex_multiline( +#line 77 "reflect.h2" + [[nodiscard]] auto compiler_services_base::lex_multiline( std::string_view source ) & -> tokens* @@ -1549,7 +1580,7 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; // First split this string into source_lines -#line 105 "reflect.h2" +#line 91 "reflect.h2" if ( cpp2::impl::cmp_greater(CPP2_UFCS(ssize)(source),1) && newline_pos != source.npos) { @@ -1562,7 +1593,7 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; } } -#line 116 "reflect.h2" +#line 102 "reflect.h2" if (!(CPP2_UFCS(empty)(source))) { cpp2::move(add_line)(cpp2::move(source)); } @@ -1579,15 +1610,15 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; return tokens; } -#line 132 "reflect.h2" - [[nodiscard]] auto compiler_services::parse_statement( +#line 118 "reflect.h2" + [[nodiscard]] auto compiler_services_base::parse_statement( std::string_view source ) & -> parse_statement_ret { cpp2::impl::deferred_init> stmt; -#line 138 "reflect.h2" +#line 124 "reflect.h2" auto original_source {source}; auto tokens {lex_multiline(cpp2::move(source))}; @@ -1602,11 +1633,8 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; }return std::move(stmt.value()); } -#line 152 "reflect.h2" - auto compiler_services::add_runtime_support_include(cpp2::impl::in s) & -> void { static_cast(CPP2_UFCS(emplace)((*cpp2::impl::assert_not_null(includes)), s)); } - -#line 154 "reflect.h2" - [[nodiscard]] auto compiler_services::parse_and_add_declaration( +#line 138 "reflect.h2" + [[nodiscard]] auto compiler_services_base::parse_and_add_declaration( std::string_view source ) & -> bool @@ -1628,18 +1656,15 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; return result; } -#line 176 "reflect.h2" - [[nodiscard]] auto compiler_services::position() const -> source_position +#line 160 "reflect.h2" + [[nodiscard]] auto compiler_services_base::position() const -> source_position { return { }; } - // Error diagnosis and handling, integrated with compiler output - // Unlike a contract violation, .requires continues further processing - // -#line 185 "reflect.h2" - auto compiler_services::require( +#line 166 "reflect.h2" + auto compiler_services_base::require( cpp2::impl::in b, cpp2::impl::in msg @@ -1650,8 +1675,8 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; } } -#line 196 "reflect.h2" - auto compiler_services::error(cpp2::impl::in msg) const& -> void +#line 177 "reflect.h2" + auto compiler_services_base::error(cpp2::impl::in msg) const& -> void { auto message {cpp2::impl::as_(msg)}; if (!(CPP2_UFCS(empty)(metafunction_name))) { @@ -1660,31 +1685,11 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; static_cast(CPP2_UFCS(emplace_back)((*cpp2::impl::assert_not_null(errors)), position(), cpp2::move(message))); } - // Enable custom contracts on this object, integrated with compiler output - // Unlike .requires, a contract violation stops further processing - // -#line 208 "reflect.h2" - auto compiler_services::report_violation(auto const& msg) const& -> void{ - error(msg); - throw(std::runtime_error( - " ==> programming bug found in metafunction @" + cpp2::to_string(metafunction_name) + " " - "- contract violation - see previous errors" - )); - } - -#line 216 "reflect.h2" - [[nodiscard]] auto compiler_services::is_active() const& -> auto { return true; } +#line 186 "reflect.h2" + [[nodiscard]] auto compiler_services_base::is_active() const& -> bool { return true; } -#line 218 "reflect.h2" - auto compiler_services::append_declaration_to_translation_unit(cpp2::impl::in source) & -> void - { - if (!(parse_and_add_declaration(source))) { - error("error attempting to add declaration:\n\t" + cpp2::to_string(source) + ""); - } - } - - compiler_services::~compiler_services() noexcept{} -compiler_services::compiler_services(compiler_services const& that) + compiler_services_base::~compiler_services_base() noexcept{} +compiler_services_base::compiler_services_base(compiler_services_base const& that) : errors{ that.errors } , includes{ that.includes } , errors_original_size{ that.errors_original_size } @@ -1695,7 +1700,61 @@ compiler_services::compiler_services(compiler_services const& that) , metafunction_args{ that.metafunction_args } , metafunctions_used{ that.metafunctions_used }{} +#line 195 "reflect.h2" + compiler_services_impl::compiler_services_impl(cpp2::impl::in csb) + : compiler_services_base{ csb } + , compiler_services::interface{ }{ + +#line 197 "reflect.h2" + } + +#line 199 "reflect.h2" + [[nodiscard]] auto compiler_services_impl::get_metafunction_name() const -> std::string_view { return metafunction_name; } + +#line 201 "reflect.h2" + [[nodiscard]] auto compiler_services_impl::get_argument(cpp2::impl::in index) -> std::string{ + metafunctions_used = true; + if (([_0 = 0, _1 = index, _2 = CPP2_UFCS(ssize)(metafunction_args)]{ return cpp2::impl::cmp_less_eq(_0,_1) && cpp2::impl::cmp_less(_1,_2); }())) { + return CPP2_ASSERT_IN_BOUNDS(metafunction_args, index); + } + return ""; + } + +#line 209 "reflect.h2" + [[nodiscard]] auto compiler_services_impl::get_arguments() -> std::vector{ + metafunctions_used = true; + return metafunction_args; + } + +#line 214 "reflect.h2" + auto compiler_services_impl::add_runtime_support_include(cpp2::impl::in s) -> void { static_cast(CPP2_UFCS(emplace)((*cpp2::impl::assert_not_null(includes)), s)); } + +#line 216 "reflect.h2" + auto compiler_services_impl::append_declaration_to_translation_unit(cpp2::impl::in source) -> void + { + if (!(parse_and_add_declaration(source))) { + error("error attempting to add declaration:\n\t" + cpp2::to_string(source) + ""); + } + } + +#line 223 "reflect.h2" + auto compiler_services_impl::require(cpp2::impl::in b, cpp2::impl::in msg) const -> void { compiler_services_base::require(b, msg); } + +#line 225 "reflect.h2" + auto compiler_services_impl::error(cpp2::impl::in msg) const -> void { compiler_services_base::error(msg); } + #line 227 "reflect.h2" + auto compiler_services_impl::report_violation(cpp2::impl::in msg) const -> void{ + error(msg); + throw(std::runtime_error( + " ==> programming bug found in metafunction @" + cpp2::to_string(metafunction_name) + " " + "- contract violation - see previous errors" + )); + } + + compiler_services_impl::~compiler_services_impl() noexcept{} + +#line 237 "reflect.h2" /* //----------------------------------------------------------------------- // @@ -1732,7 +1791,7 @@ type_id: @polymorphic_base @copyable type = } */ -#line 264 "reflect.h2" +#line 274 "reflect.h2" //----------------------------------------------------------------------- // // Declarations @@ -1743,281 +1802,310 @@ type_id: @polymorphic_base @copyable type = // All declarations are wrappers around a pointer to node // -#line 279 "reflect.h2" +#line 289 "reflect.h2" declaration_base::declaration_base( - declaration_node* n_, - cpp2::impl::in s + cpp2::impl::in csb, + declaration_node* n_ ) - : compiler_services{ s } + : compiler_services_base{ csb } , n{ n_ } -#line 284 "reflect.h2" +#line 294 "reflect.h2" { -#line 287 "reflect.h2" +#line 297 "reflect.h2" if (cpp2::cpp2_default.is_active() && !(n) ) { cpp2::cpp2_default.report_violation(CPP2_CONTRACT_MSG("a meta::declaration must point to a valid declaration_node, not null")); } } -#line 290 "reflect.h2" +#line 300 "reflect.h2" [[nodiscard]] auto declaration_base::position() const -> source_position { return CPP2_UFCS(position)((*cpp2::impl::assert_not_null(n))); } -#line 292 "reflect.h2" - [[nodiscard]] auto declaration_base::print() const& -> std::string { return CPP2_UFCS(pretty_print_visualize)((*cpp2::impl::assert_not_null(n)), 0); } - declaration_base::~declaration_base() noexcept{} -declaration_base::declaration_base(declaration_base const& that) - : compiler_services{ static_cast(that) } - , n{ that.n }{} -#line 296 "reflect.h2" +#line 303 "reflect.h2" //----------------------------------------------------------------------- -// All declarations +// Declaration factories // - -#line 303 "reflect.h2" - declaration::declaration( - - declaration_node* n_, - cpp2::impl::in s - ) - : declaration_base{ n_, s } -#line 308 "reflect.h2" - { - - } +#line 306 "reflect.h2" +[[nodiscard]] auto make_declaration(cpp2::impl::in csb, declaration_node* n) -> auto { + return declaration{ + cpp2_new(csb, n), + cpp2_new(csb)}; } #line 312 "reflect.h2" - [[nodiscard]] auto declaration::is_public() const& -> bool { return CPP2_UFCS(is_public)((*cpp2::impl::assert_not_null(n))); } -#line 313 "reflect.h2" - [[nodiscard]] auto declaration::is_protected() const& -> bool { return CPP2_UFCS(is_protected)((*cpp2::impl::assert_not_null(n))); } -#line 314 "reflect.h2" - [[nodiscard]] auto declaration::is_private() const& -> bool { return CPP2_UFCS(is_private)((*cpp2::impl::assert_not_null(n))); } -#line 315 "reflect.h2" - [[nodiscard]] auto declaration::is_default_access() const& -> bool { return CPP2_UFCS(is_default_access)((*cpp2::impl::assert_not_null(n))); } - -#line 317 "reflect.h2" - auto declaration::default_to_public() & -> void { static_cast(CPP2_UFCS(make_public)((*cpp2::impl::assert_not_null(n)))); } -#line 318 "reflect.h2" - auto declaration::default_to_protected() & -> void { static_cast(CPP2_UFCS(make_protected)((*cpp2::impl::assert_not_null(n)))); } -#line 319 "reflect.h2" - auto declaration::default_to_private() & -> void { static_cast(CPP2_UFCS(make_private)((*cpp2::impl::assert_not_null(n)))); } +[[nodiscard]] auto make_function_declaration(cpp2::impl::in csb, declaration_node* n) -> auto { + return function_declaration{ + cpp2_new(csb, n), + cpp2_new(csb, n), + cpp2_new(csb)}; } -#line 321 "reflect.h2" - [[nodiscard]] auto declaration::make_public() & -> bool { return CPP2_UFCS(make_public)((*cpp2::impl::assert_not_null(n))); } -#line 322 "reflect.h2" - [[nodiscard]] auto declaration::make_protected() & -> bool { return CPP2_UFCS(make_protected)((*cpp2::impl::assert_not_null(n))); } -#line 323 "reflect.h2" - [[nodiscard]] auto declaration::make_private() & -> bool { return CPP2_UFCS(make_private)((*cpp2::impl::assert_not_null(n))); } +#line 319 "reflect.h2" +[[nodiscard]] auto make_object_declaration(cpp2::impl::in csb, declaration_node* n) -> auto { + return object_declaration{ + cpp2_new(csb, n), + cpp2_new(csb, n), + cpp2_new(csb)}; } -#line 325 "reflect.h2" - [[nodiscard]] auto declaration::has_name() const& -> bool { return CPP2_UFCS(has_name)((*cpp2::impl::assert_not_null(n))); } #line 326 "reflect.h2" - [[nodiscard]] auto declaration::has_name(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_name)((*cpp2::impl::assert_not_null(n)), s); } - -#line 328 "reflect.h2" - [[nodiscard]] auto declaration::name() const& -> std::string_view{ - if (has_name()) {return CPP2_UFCS(as_string_view)((*cpp2::impl::assert_not_null(CPP2_UFCS(name)(*cpp2::impl::assert_not_null(n))))); } - else { return ""; } - } -#line 332 "reflect.h2" - [[nodiscard]] auto declaration::fully_qualified_name() const& -> std::string { return CPP2_UFCS(fully_qualified_name)((*cpp2::impl::assert_not_null(n))); } +[[nodiscard]] auto make_type_declaration(cpp2::impl::in csb, declaration_node* n) -> auto { + return type_declaration{ + cpp2_new(csb, n), + cpp2_new(csb, n), + cpp2_new(csb)}; } + +#line 333 "reflect.h2" +[[nodiscard]] auto make_alias_declaration(cpp2::impl::in csb, declaration_node* n) -> auto { + return alias_declaration{ + cpp2_new(csb, n), + cpp2_new(csb, n), + cpp2_new(csb)}; } -#line 334 "reflect.h2" - [[nodiscard]] auto declaration::has_initializer() const& -> bool { return CPP2_UFCS(has_initializer)((*cpp2::impl::assert_not_null(n))); } - -#line 336 "reflect.h2" - [[nodiscard]] auto declaration::is_global() const& -> bool { return CPP2_UFCS(is_global)((*cpp2::impl::assert_not_null(n))); } -#line 337 "reflect.h2" - [[nodiscard]] auto declaration::is_function() const& -> bool { return CPP2_UFCS(is_function)((*cpp2::impl::assert_not_null(n))); } -#line 338 "reflect.h2" - [[nodiscard]] auto declaration::is_object() const& -> bool { return CPP2_UFCS(is_object)((*cpp2::impl::assert_not_null(n))); } -#line 339 "reflect.h2" - [[nodiscard]] auto declaration::is_base_object() const& -> bool { return CPP2_UFCS(is_base_object)((*cpp2::impl::assert_not_null(n))); } #line 340 "reflect.h2" - [[nodiscard]] auto declaration::is_member_object() const& -> bool { return CPP2_UFCS(is_member_object)((*cpp2::impl::assert_not_null(n))); } -#line 341 "reflect.h2" - [[nodiscard]] auto declaration::is_type() const& -> bool { return CPP2_UFCS(is_type)((*cpp2::impl::assert_not_null(n))); } -#line 342 "reflect.h2" - [[nodiscard]] auto declaration::is_namespace() const& -> bool { return CPP2_UFCS(is_namespace)((*cpp2::impl::assert_not_null(n))); } -#line 343 "reflect.h2" - [[nodiscard]] auto declaration::is_alias() const& -> bool { return CPP2_UFCS(is_alias)((*cpp2::impl::assert_not_null(n))); } - -#line 345 "reflect.h2" - [[nodiscard]] auto declaration::is_type_alias() const& -> bool { return CPP2_UFCS(is_type_alias)((*cpp2::impl::assert_not_null(n))); } -#line 346 "reflect.h2" - [[nodiscard]] auto declaration::is_namespace_alias() const& -> bool { return CPP2_UFCS(is_namespace_alias)((*cpp2::impl::assert_not_null(n))); } -#line 347 "reflect.h2" - [[nodiscard]] auto declaration::is_object_alias() const& -> bool { return CPP2_UFCS(is_object_alias)((*cpp2::impl::assert_not_null(n))); } +//----------------------------------------------------------------------- +// All declarations +// #line 349 "reflect.h2" - [[nodiscard]] auto declaration::is_function_expression() const& -> bool { return CPP2_UFCS(is_function_expression)((*cpp2::impl::assert_not_null(n))); } - -#line 351 "reflect.h2" - [[nodiscard]] auto declaration::as_function() const& -> function_declaration { return function_declaration(n, (*this)); } -#line 352 "reflect.h2" - [[nodiscard]] auto declaration::as_object() const& -> object_declaration { return object_declaration(n, (*this)); } -#line 353 "reflect.h2" - [[nodiscard]] auto declaration::as_type() const& -> type_declaration { return type_declaration(n, (*this)); } + declaration_impl::declaration_impl( + + cpp2::impl::in csb, + declaration_node* n_ + ) + : declaration_base{ csb, n_ } + , declaration::interface{ } #line 354 "reflect.h2" - [[nodiscard]] auto declaration::as_alias() const& -> alias_declaration { return alias_declaration(n, (*this)); } + { -#line 356 "reflect.h2" - [[nodiscard]] auto declaration::get_parent() const& -> declaration { return declaration((*cpp2::impl::assert_not_null(n)).parent_declaration, (*this)); } + } #line 358 "reflect.h2" - [[nodiscard]] auto declaration::parent_is_function() const& -> bool { return CPP2_UFCS(parent_is_function)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::is_public() const -> bool { return CPP2_UFCS(is_public)((*cpp2::impl::assert_not_null(n))); } #line 359 "reflect.h2" - [[nodiscard]] auto declaration::parent_is_object() const& -> bool { return CPP2_UFCS(parent_is_object)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::is_protected() const -> bool { return CPP2_UFCS(is_protected)((*cpp2::impl::assert_not_null(n))); } #line 360 "reflect.h2" - [[nodiscard]] auto declaration::parent_is_type() const& -> bool { return CPP2_UFCS(parent_is_type)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::is_private() const -> bool { return CPP2_UFCS(is_private)((*cpp2::impl::assert_not_null(n))); } #line 361 "reflect.h2" - [[nodiscard]] auto declaration::parent_is_namespace() const& -> bool { return CPP2_UFCS(parent_is_namespace)((*cpp2::impl::assert_not_null(n))); } -#line 362 "reflect.h2" - [[nodiscard]] auto declaration::parent_is_alias() const& -> bool { return CPP2_UFCS(parent_is_alias)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::is_default_access() const -> bool { return CPP2_UFCS(is_default_access)((*cpp2::impl::assert_not_null(n))); } +#line 363 "reflect.h2" + auto declaration_impl::default_to_public() -> void { static_cast(CPP2_UFCS(make_public)((*cpp2::impl::assert_not_null(n)))); } #line 364 "reflect.h2" - [[nodiscard]] auto declaration::parent_is_type_alias() const& -> bool { return CPP2_UFCS(parent_is_type_alias)((*cpp2::impl::assert_not_null(n))); } + auto declaration_impl::default_to_protected() -> void { static_cast(CPP2_UFCS(make_protected)((*cpp2::impl::assert_not_null(n)))); } #line 365 "reflect.h2" - [[nodiscard]] auto declaration::parent_is_namespace_alias() const& -> bool { return CPP2_UFCS(parent_is_namespace_alias)((*cpp2::impl::assert_not_null(n))); } -#line 366 "reflect.h2" - [[nodiscard]] auto declaration::parent_is_object_alias() const& -> bool { return CPP2_UFCS(parent_is_object_alias)((*cpp2::impl::assert_not_null(n))); } + auto declaration_impl::default_to_private() -> void { static_cast(CPP2_UFCS(make_private)((*cpp2::impl::assert_not_null(n)))); } +#line 367 "reflect.h2" + [[nodiscard]] auto declaration_impl::make_public() -> bool { return CPP2_UFCS(make_public)((*cpp2::impl::assert_not_null(n))); } #line 368 "reflect.h2" - [[nodiscard]] auto declaration::parent_is_polymorphic() const& -> bool { return CPP2_UFCS(parent_is_polymorphic)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::make_protected() -> bool { return CPP2_UFCS(make_protected)((*cpp2::impl::assert_not_null(n))); } +#line 369 "reflect.h2" + [[nodiscard]] auto declaration_impl::make_private() -> bool { return CPP2_UFCS(make_private)((*cpp2::impl::assert_not_null(n))); } -#line 370 "reflect.h2" - auto declaration::mark_for_removal_from_enclosing_type() & -> void - // this precondition should be sufficient ... - { - if (cpp2::type_safety.is_active() && !(parent_is_type()) ) { cpp2::type_safety.report_violation(""); } -#line 373 "reflect.h2" - auto test {CPP2_UFCS(type_member_mark_for_removal)((*cpp2::impl::assert_not_null(n)))}; - if (cpp2::cpp2_default.is_active() && !(cpp2::move(test)) ) { cpp2::cpp2_default.report_violation(""); }// ... to ensure this assert is true - } +#line 371 "reflect.h2" + [[nodiscard]] auto declaration_impl::has_name() const -> bool { return CPP2_UFCS(has_name)((*cpp2::impl::assert_not_null(n))); } +#line 372 "reflect.h2" + [[nodiscard]] auto declaration_impl::has_name(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_name)((*cpp2::impl::assert_not_null(n)), s); } - declaration::~declaration() noexcept{} -declaration::declaration(declaration const& that) - : declaration_base{ static_cast(that) }{} +#line 374 "reflect.h2" + [[nodiscard]] auto declaration_impl::name() const -> std::string_view{ + if (has_name()) {return CPP2_UFCS(as_string_view)((*cpp2::impl::assert_not_null(CPP2_UFCS(name)(*cpp2::impl::assert_not_null(n))))); } + else { return ""; } + } +#line 378 "reflect.h2" + [[nodiscard]] auto declaration_impl::fully_qualified_name() const -> std::string { return CPP2_UFCS(fully_qualified_name)((*cpp2::impl::assert_not_null(n))); } -#line 379 "reflect.h2" -//----------------------------------------------------------------------- -// Function declarations -// +#line 380 "reflect.h2" + [[nodiscard]] auto declaration_impl::has_initializer() const -> bool { return CPP2_UFCS(has_initializer)((*cpp2::impl::assert_not_null(n))); } +#line 382 "reflect.h2" + [[nodiscard]] auto declaration_impl::is_global() const -> bool { return CPP2_UFCS(is_global)((*cpp2::impl::assert_not_null(n))); } +#line 383 "reflect.h2" + [[nodiscard]] auto declaration_impl::is_function() const -> bool { return CPP2_UFCS(is_function)((*cpp2::impl::assert_not_null(n))); } +#line 384 "reflect.h2" + [[nodiscard]] auto declaration_impl::is_object() const -> bool { return CPP2_UFCS(is_object)((*cpp2::impl::assert_not_null(n))); } +#line 385 "reflect.h2" + [[nodiscard]] auto declaration_impl::is_base_object() const -> bool { return CPP2_UFCS(is_base_object)((*cpp2::impl::assert_not_null(n))); } #line 386 "reflect.h2" - function_declaration::function_declaration( + [[nodiscard]] auto declaration_impl::is_member_object() const -> bool { return CPP2_UFCS(is_member_object)((*cpp2::impl::assert_not_null(n))); } +#line 387 "reflect.h2" + [[nodiscard]] auto declaration_impl::is_type() const -> bool { return CPP2_UFCS(is_type)((*cpp2::impl::assert_not_null(n))); } +#line 388 "reflect.h2" + [[nodiscard]] auto declaration_impl::is_namespace() const -> bool { return CPP2_UFCS(is_namespace)((*cpp2::impl::assert_not_null(n))); } +#line 389 "reflect.h2" + [[nodiscard]] auto declaration_impl::is_alias() const -> bool { return CPP2_UFCS(is_alias)((*cpp2::impl::assert_not_null(n))); } - declaration_node* n_, - cpp2::impl::in s - ) - : declaration{ n_, s } #line 391 "reflect.h2" - { + [[nodiscard]] auto declaration_impl::is_type_alias() const -> bool { return CPP2_UFCS(is_type_alias)((*cpp2::impl::assert_not_null(n))); } +#line 392 "reflect.h2" + [[nodiscard]] auto declaration_impl::is_namespace_alias() const -> bool { return CPP2_UFCS(is_namespace_alias)((*cpp2::impl::assert_not_null(n))); } +#line 393 "reflect.h2" + [[nodiscard]] auto declaration_impl::is_object_alias() const -> bool { return CPP2_UFCS(is_object_alias)((*cpp2::impl::assert_not_null(n))); } - if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(is_function)((*cpp2::impl::assert_not_null(n)))) ) { cpp2::cpp2_default.report_violation(""); } - } +#line 395 "reflect.h2" + [[nodiscard]] auto declaration_impl::is_function_expression() const -> bool { return CPP2_UFCS(is_function_expression)((*cpp2::impl::assert_not_null(n))); } -#line 396 "reflect.h2" - [[nodiscard]] auto function_declaration::index_of_parameter_named(cpp2::impl::in s) const& -> int { return CPP2_UFCS(index_of_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } #line 397 "reflect.h2" - [[nodiscard]] auto function_declaration::has_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } + [[nodiscard]] auto declaration_impl::as_function() const -> function_declaration { return make_function_declaration((*this), n); } #line 398 "reflect.h2" - [[nodiscard]] auto function_declaration::has_in_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_in_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } + [[nodiscard]] auto declaration_impl::as_object() const -> object_declaration { return make_object_declaration((*this), n); } #line 399 "reflect.h2" - [[nodiscard]] auto function_declaration::has_copy_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_copy_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } + [[nodiscard]] auto declaration_impl::as_type() const -> type_declaration { return make_type_declaration((*this), n); } #line 400 "reflect.h2" - [[nodiscard]] auto function_declaration::has_inout_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_inout_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } -#line 401 "reflect.h2" - [[nodiscard]] auto function_declaration::has_out_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_out_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } + [[nodiscard]] auto declaration_impl::as_alias() const -> alias_declaration { return make_alias_declaration((*this), n); } + #line 402 "reflect.h2" - [[nodiscard]] auto function_declaration::has_move_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_move_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } -#line 403 "reflect.h2" - [[nodiscard]] auto function_declaration::has_forward_parameter_named(cpp2::impl::in s) const& -> bool { return CPP2_UFCS(has_forward_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } -#line 404 "reflect.h2" - [[nodiscard]] auto function_declaration::first_parameter_name() const& -> std::string { return CPP2_UFCS(first_parameter_name)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::get_parent() const -> declaration { return make_declaration((*this), n); } +#line 404 "reflect.h2" + [[nodiscard]] auto declaration_impl::parent_is_function() const -> bool { return CPP2_UFCS(parent_is_function)((*cpp2::impl::assert_not_null(n))); } +#line 405 "reflect.h2" + [[nodiscard]] auto declaration_impl::parent_is_object() const -> bool { return CPP2_UFCS(parent_is_object)((*cpp2::impl::assert_not_null(n))); } #line 406 "reflect.h2" - [[nodiscard]] auto function_declaration::has_parameter_with_name_and_pass(cpp2::impl::in s, cpp2::impl::in pass) const& -> bool { - return CPP2_UFCS(has_parameter_with_name_and_pass)((*cpp2::impl::assert_not_null(n)), s, pass); } + [[nodiscard]] auto declaration_impl::parent_is_type() const -> bool { return CPP2_UFCS(parent_is_type)((*cpp2::impl::assert_not_null(n))); } +#line 407 "reflect.h2" + [[nodiscard]] auto declaration_impl::parent_is_namespace() const -> bool { return CPP2_UFCS(parent_is_namespace)((*cpp2::impl::assert_not_null(n))); } #line 408 "reflect.h2" - [[nodiscard]] auto function_declaration::is_function_with_this() const& -> bool { return CPP2_UFCS(is_function_with_this)((*cpp2::impl::assert_not_null(n))); } -#line 409 "reflect.h2" - [[nodiscard]] auto function_declaration::is_virtual() const& -> bool { return CPP2_UFCS(is_virtual_function)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::parent_is_alias() const -> bool { return CPP2_UFCS(parent_is_alias)((*cpp2::impl::assert_not_null(n))); } + #line 410 "reflect.h2" - [[nodiscard]] auto function_declaration::is_defaultable() const& -> bool { return CPP2_UFCS(is_defaultable_function)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::parent_is_type_alias() const -> bool { return CPP2_UFCS(parent_is_type_alias)((*cpp2::impl::assert_not_null(n))); } #line 411 "reflect.h2" - [[nodiscard]] auto function_declaration::is_constructor() const& -> bool { return CPP2_UFCS(is_constructor)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::parent_is_namespace_alias() const -> bool { return CPP2_UFCS(parent_is_namespace_alias)((*cpp2::impl::assert_not_null(n))); } #line 412 "reflect.h2" - [[nodiscard]] auto function_declaration::is_default_constructor() const& -> bool { return CPP2_UFCS(is_default_constructor)((*cpp2::impl::assert_not_null(n))); } -#line 413 "reflect.h2" - [[nodiscard]] auto function_declaration::is_move() const& -> bool { return CPP2_UFCS(is_move)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::parent_is_object_alias() const -> bool { return CPP2_UFCS(parent_is_object_alias)((*cpp2::impl::assert_not_null(n))); } + #line 414 "reflect.h2" - [[nodiscard]] auto function_declaration::is_swap() const& -> bool { return CPP2_UFCS(is_swap)((*cpp2::impl::assert_not_null(n))); } -#line 415 "reflect.h2" - [[nodiscard]] auto function_declaration::is_constructor_with_that() const& -> bool { return CPP2_UFCS(is_constructor_with_that)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::parent_is_polymorphic() const -> bool { return CPP2_UFCS(parent_is_polymorphic)((*cpp2::impl::assert_not_null(n))); } + #line 416 "reflect.h2" - [[nodiscard]] auto function_declaration::is_constructor_with_in_that() const& -> bool { return CPP2_UFCS(is_constructor_with_in_that)((*cpp2::impl::assert_not_null(n))); } -#line 417 "reflect.h2" - [[nodiscard]] auto function_declaration::is_constructor_with_move_that() const& -> bool { return CPP2_UFCS(is_constructor_with_move_that)((*cpp2::impl::assert_not_null(n))); } -#line 418 "reflect.h2" - [[nodiscard]] auto function_declaration::is_assignment() const& -> bool { return CPP2_UFCS(is_assignment)((*cpp2::impl::assert_not_null(n))); } + auto declaration_impl::mark_for_removal_from_enclosing_type() -> void + // this precondition should be sufficient ... + { + if (cpp2::type_safety.is_active() && !(parent_is_type()) ) { cpp2::type_safety.report_violation(""); } #line 419 "reflect.h2" - [[nodiscard]] auto function_declaration::is_assignment_with_that() const& -> bool { return CPP2_UFCS(is_assignment_with_that)((*cpp2::impl::assert_not_null(n))); } -#line 420 "reflect.h2" - [[nodiscard]] auto function_declaration::is_assignment_with_in_that() const& -> bool { return CPP2_UFCS(is_assignment_with_in_that)((*cpp2::impl::assert_not_null(n))); } -#line 421 "reflect.h2" - [[nodiscard]] auto function_declaration::is_assignment_with_move_that() const& -> bool { return CPP2_UFCS(is_assignment_with_move_that)((*cpp2::impl::assert_not_null(n))); } -#line 422 "reflect.h2" - [[nodiscard]] auto function_declaration::is_destructor() const& -> bool { return CPP2_UFCS(is_destructor)((*cpp2::impl::assert_not_null(n))); } + auto test {CPP2_UFCS(type_member_mark_for_removal)((*cpp2::impl::assert_not_null(n)))}; + if (cpp2::cpp2_default.is_active() && !(cpp2::move(test)) ) { cpp2::cpp2_default.report_violation(""); }// ... to ensure this assert is true + } -#line 424 "reflect.h2" - [[nodiscard]] auto function_declaration::is_copy_or_move() const& -> bool { return is_constructor_with_that() || is_assignment_with_that(); } +#line 423 "reflect.h2" + [[nodiscard]] auto declaration_impl::print() const -> std::string { return CPP2_UFCS(pretty_print_visualize)((*cpp2::impl::assert_not_null(n)), 0); } + + declaration_impl::~declaration_impl() noexcept{} -#line 426 "reflect.h2" - [[nodiscard]] auto function_declaration::has_declared_return_type() const& -> bool { return CPP2_UFCS(has_declared_return_type)((*cpp2::impl::assert_not_null(n))); } #line 427 "reflect.h2" - [[nodiscard]] auto function_declaration::has_deduced_return_type() const& -> bool { return CPP2_UFCS(has_deduced_return_type)((*cpp2::impl::assert_not_null(n))); } -#line 428 "reflect.h2" - [[nodiscard]] auto function_declaration::has_bool_return_type() const& -> bool { return CPP2_UFCS(has_bool_return_type)((*cpp2::impl::assert_not_null(n))); } -#line 429 "reflect.h2" - [[nodiscard]] auto function_declaration::has_non_void_return_type() const& -> bool { return CPP2_UFCS(has_non_void_return_type)((*cpp2::impl::assert_not_null(n))); } +//----------------------------------------------------------------------- +// Function declarations +// -#line 431 "reflect.h2" - [[nodiscard]] auto function_declaration::unnamed_return_type() const& -> std::string { return CPP2_UFCS(unnamed_return_type_to_string)((*cpp2::impl::assert_not_null(n))); } +#line 436 "reflect.h2" + function_declaration_impl::function_declaration_impl( -#line 433 "reflect.h2" - [[nodiscard]] auto function_declaration::get_parameters() const& -> std::vector + cpp2::impl::in csb, + declaration_node* n_ + ) + : declaration_base{ csb, n_ } + , function_declaration::interface{ } +#line 441 "reflect.h2" + { + + if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(is_function)((*cpp2::impl::assert_not_null(n)))) ) { cpp2::cpp2_default.report_violation(""); } + } + +#line 446 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::index_of_parameter_named(cpp2::impl::in s) const -> int { return CPP2_UFCS(index_of_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } +#line 447 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::has_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } +#line 448 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::has_in_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_in_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } +#line 449 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::has_copy_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_copy_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } +#line 450 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::has_inout_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_inout_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } +#line 451 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::has_out_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_out_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } +#line 452 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::has_move_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_move_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } +#line 453 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::has_forward_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_forward_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } +#line 454 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::first_parameter_name() const -> std::string { return CPP2_UFCS(first_parameter_name)((*cpp2::impl::assert_not_null(n))); } + + // has_parameter_with_name_and_pass: (override this, s: std::string_view, pass: passing_style) -> bool // TODO(DyXel) + // = n*.has_parameter_with_name_and_pass(s, pass); +#line 458 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::is_function_with_this() const -> bool { return CPP2_UFCS(is_function_with_this)((*cpp2::impl::assert_not_null(n))); } +#line 459 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::is_virtual() const -> bool { return CPP2_UFCS(is_virtual_function)((*cpp2::impl::assert_not_null(n))); } +#line 460 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::is_defaultable() const -> bool { return CPP2_UFCS(is_defaultable_function)((*cpp2::impl::assert_not_null(n))); } +#line 461 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::is_constructor() const -> bool { return CPP2_UFCS(is_constructor)((*cpp2::impl::assert_not_null(n))); } +#line 462 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::is_default_constructor() const -> bool { return CPP2_UFCS(is_default_constructor)((*cpp2::impl::assert_not_null(n))); } +#line 463 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::is_move() const -> bool { return CPP2_UFCS(is_move)((*cpp2::impl::assert_not_null(n))); } +#line 464 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::is_swap() const -> bool { return CPP2_UFCS(is_swap)((*cpp2::impl::assert_not_null(n))); } +#line 465 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::is_constructor_with_that() const -> bool { return CPP2_UFCS(is_constructor_with_that)((*cpp2::impl::assert_not_null(n))); } +#line 466 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::is_constructor_with_in_that() const -> bool { return CPP2_UFCS(is_constructor_with_in_that)((*cpp2::impl::assert_not_null(n))); } +#line 467 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::is_constructor_with_move_that() const -> bool { return CPP2_UFCS(is_constructor_with_move_that)((*cpp2::impl::assert_not_null(n))); } +#line 468 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::is_assignment() const -> bool { return CPP2_UFCS(is_assignment)((*cpp2::impl::assert_not_null(n))); } +#line 469 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::is_assignment_with_that() const -> bool { return CPP2_UFCS(is_assignment_with_that)((*cpp2::impl::assert_not_null(n))); } +#line 470 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::is_assignment_with_in_that() const -> bool { return CPP2_UFCS(is_assignment_with_in_that)((*cpp2::impl::assert_not_null(n))); } +#line 471 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::is_assignment_with_move_that() const -> bool { return CPP2_UFCS(is_assignment_with_move_that)((*cpp2::impl::assert_not_null(n))); } +#line 472 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::is_destructor() const -> bool { return CPP2_UFCS(is_destructor)((*cpp2::impl::assert_not_null(n))); } + +#line 474 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::is_copy_or_move() const -> bool { return is_constructor_with_that() || is_assignment_with_that(); } + +#line 476 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::has_declared_return_type() const -> bool { return CPP2_UFCS(has_declared_return_type)((*cpp2::impl::assert_not_null(n))); } +#line 477 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::has_deduced_return_type() const -> bool { return CPP2_UFCS(has_deduced_return_type)((*cpp2::impl::assert_not_null(n))); } +#line 478 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::has_bool_return_type() const -> bool { return CPP2_UFCS(has_bool_return_type)((*cpp2::impl::assert_not_null(n))); } +#line 479 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::has_non_void_return_type() const -> bool { return CPP2_UFCS(has_non_void_return_type)((*cpp2::impl::assert_not_null(n))); } + +#line 481 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::unnamed_return_type() const -> std::string { return CPP2_UFCS(unnamed_return_type_to_string)((*cpp2::impl::assert_not_null(n))); } + +#line 483 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::get_parameters() const -> std::vector { std::vector ret {}; for ( auto const& param : CPP2_UFCS(get_function_parameters)((*cpp2::impl::assert_not_null(n))) ) { - static_cast(CPP2_UFCS(emplace_back)(ret, &*cpp2::impl::assert_not_null((*cpp2::impl::assert_not_null(param)).declaration), (*this))); + static_cast(CPP2_UFCS(emplace_back)(ret, make_object_declaration((*this), &*cpp2::impl::assert_not_null((*cpp2::impl::assert_not_null(param)).declaration)))); } return ret; } -#line 443 "reflect.h2" - [[nodiscard]] auto function_declaration::is_binary_comparison_function() const& -> bool { return CPP2_UFCS(is_binary_comparison_function)((*cpp2::impl::assert_not_null(n))); } +#line 493 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::is_binary_comparison_function() const -> bool { return CPP2_UFCS(is_binary_comparison_function)((*cpp2::impl::assert_not_null(n))); } -#line 445 "reflect.h2" - auto function_declaration::default_to_virtual() & -> void { static_cast(CPP2_UFCS(make_function_virtual)((*cpp2::impl::assert_not_null(n)))); } - -#line 447 "reflect.h2" - [[nodiscard]] auto function_declaration::make_virtual() & -> bool { return CPP2_UFCS(make_function_virtual)((*cpp2::impl::assert_not_null(n))); } +#line 495 "reflect.h2" + auto function_declaration_impl::default_to_virtual() -> void { static_cast(CPP2_UFCS(make_function_virtual)((*cpp2::impl::assert_not_null(n)))); } -#line 449 "reflect.h2" - auto function_declaration::add_initializer(cpp2::impl::in source) & -> void +#line 497 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::make_virtual() -> bool { return CPP2_UFCS(make_function_virtual)((*cpp2::impl::assert_not_null(n))); } -#line 452 "reflect.h2" +#line 499 "reflect.h2" + auto function_declaration_impl::add_initializer(cpp2::impl::in source) -> void { - if ((*this).is_active() && !(!(has_initializer())) ) { (*this).report_violation(CPP2_CONTRACT_MSG("cannot add an initializer to a function that already has one")); } - if ((*this).is_active() && !(parent_is_type()) ) { (*this).report_violation(CPP2_CONTRACT_MSG("cannot add an initializer to a function that isn't in a type scope")); } - //require( !has_initializer(), - // "cannot add an initializer to a function that already has one"); - //require( parent_is_type(), - // "cannot add an initializer to a function that isn't in a type scope"); + require(!(CPP2_UFCS(has_initializer)((*cpp2::impl::assert_not_null(n)))), + "cannot add an initializer to a function that already has one"); + require(CPP2_UFCS(parent_is_type)((*cpp2::impl::assert_not_null(n))), + "cannot add an initializer to a function that isn't in a type scope"); -#line 458 "reflect.h2" auto stmt {parse_statement(source)}; if (!((cpp2::impl::as_(stmt)))) { error("cannot add an initializer that is not a valid statement"); @@ -2027,105 +2115,96 @@ declaration::declaration(declaration const& that) std::string("unexpected error while attempting to add initializer")); } - function_declaration::function_declaration(function_declaration const& that) - : declaration{ static_cast(that) }{} + function_declaration_impl::~function_declaration_impl() noexcept{} -#line 469 "reflect.h2" +#line 517 "reflect.h2" //----------------------------------------------------------------------- // Object declarations // -#line 476 "reflect.h2" - object_declaration::object_declaration( +#line 526 "reflect.h2" + object_declaration_impl::object_declaration_impl( - declaration_node* n_, - cpp2::impl::in s + cpp2::impl::in csb, + declaration_node* n_ ) - : declaration{ n_, s } -#line 481 "reflect.h2" + : declaration_base{ csb, n_ } + , object_declaration::interface{ } +#line 531 "reflect.h2" { if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(is_object)((*cpp2::impl::assert_not_null(n)))) ) { cpp2::cpp2_default.report_violation(""); } } -#line 486 "reflect.h2" - [[nodiscard]] auto object_declaration::is_const() const& -> bool { return CPP2_UFCS(is_const)((*cpp2::impl::assert_not_null(n))); } -#line 487 "reflect.h2" - [[nodiscard]] auto object_declaration::has_wildcard_type() const& -> bool { return CPP2_UFCS(has_wildcard_type)((*cpp2::impl::assert_not_null(n))); } +#line 536 "reflect.h2" + [[nodiscard]] auto object_declaration_impl::is_const() const -> bool { return CPP2_UFCS(is_const)((*cpp2::impl::assert_not_null(n))); } +#line 537 "reflect.h2" + [[nodiscard]] auto object_declaration_impl::has_wildcard_type() const -> bool { return CPP2_UFCS(has_wildcard_type)((*cpp2::impl::assert_not_null(n))); } -#line 489 "reflect.h2" - [[nodiscard]] auto object_declaration::type() const& -> std::string{ +#line 539 "reflect.h2" + [[nodiscard]] auto object_declaration_impl::type() const -> std::string{ auto ret {CPP2_UFCS(object_type)((*cpp2::impl::assert_not_null(n)))}; require(!(contains(ret, "(*ERROR*)")), "cannot to_string this type: " + ret); return ret; } -#line 496 "reflect.h2" - [[nodiscard]] auto object_declaration::initializer() const& -> std::string{ +#line 546 "reflect.h2" + [[nodiscard]] auto object_declaration_impl::initializer() const -> std::string{ auto ret {CPP2_UFCS(object_initializer)((*cpp2::impl::assert_not_null(n)))}; require(!(contains(ret, "(*ERROR*)")), "cannot to_string this initializer: " + ret); return ret; } - object_declaration::object_declaration(object_declaration const& that) - : declaration{ static_cast(that) }{} + object_declaration_impl::~object_declaration_impl() noexcept{} -#line 505 "reflect.h2" +#line 555 "reflect.h2" //----------------------------------------------------------------------- // Type declarations // -#line 512 "reflect.h2" - type_declaration::type_declaration( +#line 564 "reflect.h2" + type_declaration_impl::type_declaration_impl( - declaration_node* n_, - cpp2::impl::in s + cpp2::impl::in csb, + declaration_node* n_ ) - : declaration{ n_, s } -#line 517 "reflect.h2" + : declaration_base{ csb, n_ } + , type_declaration::interface{ } +#line 569 "reflect.h2" { if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(is_type)((*cpp2::impl::assert_not_null(n)))) ) { cpp2::cpp2_default.report_violation(""); } } -#line 522 "reflect.h2" - auto type_declaration::reserve_names(cpp2::impl::in name, auto&& ...etc) const& -> void - { // etc is not declared ':string_view' for compatibility with GCC 10.x - for ( - auto const& m : get_members() ) { - CPP2_UFCS(require)(m, !(CPP2_UFCS(has_name)(m, name)), - "in a '" + cpp2::to_string(get_metafunction_name()) + "' type, the name '" + cpp2::to_string(name) + "' " - "is reserved for use by the '" + cpp2::to_string(get_metafunction_name()) + "' implementation" - ); - } - if constexpr (!(CPP2_PACK_EMPTY(etc))) { - reserve_names(CPP2_FORWARD(etc)...); - } - } - -#line 536 "reflect.h2" - [[nodiscard]] auto type_declaration::is_polymorphic() const& -> bool { return CPP2_UFCS(is_polymorphic)((*cpp2::impl::assert_not_null(n))); } -#line 537 "reflect.h2" - [[nodiscard]] auto type_declaration::is_final() const& -> bool { return CPP2_UFCS(is_type_final)((*cpp2::impl::assert_not_null(n))); } -#line 538 "reflect.h2" - [[nodiscard]] auto type_declaration::make_final() & -> bool { return CPP2_UFCS(make_type_final)((*cpp2::impl::assert_not_null(n))); } +#line 574 "reflect.h2" + [[nodiscard]] auto type_declaration_impl::is_polymorphic() const -> bool { return CPP2_UFCS(is_polymorphic)((*cpp2::impl::assert_not_null(n))); } +#line 575 "reflect.h2" + [[nodiscard]] auto type_declaration_impl::is_final() const -> bool { return CPP2_UFCS(is_type_final)((*cpp2::impl::assert_not_null(n))); } +#line 576 "reflect.h2" + [[nodiscard]] auto type_declaration_impl::make_final() -> bool { return CPP2_UFCS(make_type_final)((*cpp2::impl::assert_not_null(n))); } -#line 540 "reflect.h2" - [[nodiscard]] auto type_declaration::get_member_functions() const& -> std::vector +#line 578 "reflect.h2" + [[nodiscard]] auto type_declaration_impl::get_member_functions() const -> std::vector { std::vector ret {}; for ( auto const& d : CPP2_UFCS(get_type_scope_declarations)((*cpp2::impl::assert_not_null(n)), declaration_node::functions) ) { - static_cast(CPP2_UFCS(emplace_back)(ret, d, (*this))); + static_cast(CPP2_UFCS(emplace_back)(ret, + function_declaration{ + cpp2_new((*this), d), + cpp2_new((*this), d), + cpp2_new((*this))} + + )); } return ret; } -#line 551 "reflect.h2" - [[nodiscard]] auto type_declaration::get_member_functions_needing_initializer() const& -> std::vector +#line 595 "reflect.h2" + [[nodiscard]] auto type_declaration_impl::get_member_functions_needing_initializer() const -> std::vector { std::vector ret {}; @@ -2135,74 +2214,70 @@ declaration::declaration(declaration const& that) && !(CPP2_UFCS(is_virtual_function)((*cpp2::impl::assert_not_null(d)))) && !(CPP2_UFCS(is_defaultable_function)((*cpp2::impl::assert_not_null(d))))) { - static_cast(CPP2_UFCS(emplace_back)(ret, d, (*this))); + static_cast(CPP2_UFCS(emplace_back)(ret, make_function_declaration((*this), d))); } return ret; } -#line 566 "reflect.h2" - [[nodiscard]] auto type_declaration::get_member_objects() const& -> std::vector +#line 610 "reflect.h2" + [[nodiscard]] auto type_declaration_impl::get_member_objects() const -> std::vector { std::vector ret {}; for ( auto const& d : CPP2_UFCS(get_type_scope_declarations)((*cpp2::impl::assert_not_null(n)), declaration_node::objects) ) { - static_cast(CPP2_UFCS(emplace_back)(ret, d, (*this))); + static_cast(CPP2_UFCS(emplace_back)(ret, make_object_declaration((*this), d))); } return ret; } -#line 576 "reflect.h2" - [[nodiscard]] auto type_declaration::get_member_types() const& -> std::vector +#line 620 "reflect.h2" + [[nodiscard]] auto type_declaration_impl::get_member_types() const -> std::vector { std::vector ret {}; for ( auto const& d : CPP2_UFCS(get_type_scope_declarations)((*cpp2::impl::assert_not_null(n)), declaration_node::types) ) { - static_cast(CPP2_UFCS(emplace_back)(ret, d, (*this))); + static_cast(CPP2_UFCS(emplace_back)(ret, make_type_declaration((*this), d))); } return ret; } -#line 586 "reflect.h2" - [[nodiscard]] auto type_declaration::get_member_aliases() const& -> std::vector +#line 630 "reflect.h2" + [[nodiscard]] auto type_declaration_impl::get_member_aliases() const -> std::vector { std::vector ret {}; for ( auto const& d : CPP2_UFCS(get_type_scope_declarations)((*cpp2::impl::assert_not_null(n)), declaration_node::aliases) ) { - static_cast(CPP2_UFCS(emplace_back)(ret, d, (*this))); + static_cast(CPP2_UFCS(emplace_back)(ret, make_alias_declaration((*this), d))); } return ret; } -#line 596 "reflect.h2" - [[nodiscard]] auto type_declaration::get_members() const& -> std::vector +#line 640 "reflect.h2" + [[nodiscard]] auto type_declaration_impl::get_members() const -> std::vector { std::vector ret {}; for ( auto const& d : CPP2_UFCS(get_type_scope_declarations)((*cpp2::impl::assert_not_null(n)), declaration_node::all) ) { - static_cast(CPP2_UFCS(emplace_back)(ret, d, (*this))); + static_cast(CPP2_UFCS(emplace_back)(ret, make_declaration((*this), d))); } return ret; } -#line 606 "reflect.h2" - [[nodiscard]] auto type_declaration::query_declared_value_set_functions() const& -> query_declared_value_set_functions_ret +#line 650 "reflect.h2" + [[nodiscard]] auto type_declaration_impl::query_declared_value_set_functions() const -> _query_declared_value_set_functions_ret -#line 613 "reflect.h2" { - cpp2::impl::deferred_init out_this_in_that; - cpp2::impl::deferred_init out_this_move_that; - cpp2::impl::deferred_init inout_this_in_that; - cpp2::impl::deferred_init inout_this_move_that; -#line 614 "reflect.h2" + _query_declared_value_set_functions_ret ret {}; auto declared {CPP2_UFCS(find_declared_value_set_functions)((*cpp2::impl::assert_not_null(n)))}; - out_this_in_that.construct(declared.out_this_in_that != nullptr); - out_this_move_that.construct(declared.out_this_move_that != nullptr); - inout_this_in_that.construct(declared.inout_this_in_that != nullptr); - inout_this_move_that.construct(cpp2::move(declared).inout_this_move_that != nullptr); - return { std::move(out_this_in_that.value()), std::move(out_this_move_that.value()), std::move(inout_this_in_that.value()), std::move(inout_this_move_that.value()) }; } - -#line 621 "reflect.h2" - auto type_declaration::add_member(cpp2::impl::in source) & -> void + ret.out_this_in_that = declared.out_this_in_that != nullptr; + ret.out_this_move_that = declared.out_this_move_that != nullptr; + ret.inout_this_in_that = declared.inout_this_in_that != nullptr; + ret.inout_this_move_that = cpp2::move(declared).inout_this_move_that != nullptr; + return ret; + } + +#line 662 "reflect.h2" + auto type_declaration_impl::add_member(cpp2::impl::in source) -> void { auto decl {parse_statement(source)}; if (!((cpp2::impl::as_(decl)))) { @@ -2216,41 +2291,40 @@ declaration::declaration(declaration const& that) std::string("unexpected error while attempting to add member:\n") + source); } -#line 635 "reflect.h2" - auto type_declaration::remove_marked_members() & -> void { CPP2_UFCS(type_remove_marked_members)((*cpp2::impl::assert_not_null(n))); } -#line 636 "reflect.h2" - auto type_declaration::remove_all_members() & -> void { CPP2_UFCS(type_remove_all_members)((*cpp2::impl::assert_not_null(n))); } +#line 676 "reflect.h2" + auto type_declaration_impl::remove_marked_members() -> void { CPP2_UFCS(type_remove_marked_members)((*cpp2::impl::assert_not_null(n))); } +#line 677 "reflect.h2" + auto type_declaration_impl::remove_all_members() -> void { CPP2_UFCS(type_remove_all_members)((*cpp2::impl::assert_not_null(n))); } -#line 638 "reflect.h2" - auto type_declaration::disable_member_function_generation() & -> void { CPP2_UFCS(type_disable_member_function_generation)((*cpp2::impl::assert_not_null(n))); } +#line 679 "reflect.h2" + auto type_declaration_impl::disable_member_function_generation() -> void { CPP2_UFCS(type_disable_member_function_generation)((*cpp2::impl::assert_not_null(n))); } - type_declaration::type_declaration(type_declaration const& that) - : declaration{ static_cast(that) }{} + type_declaration_impl::~type_declaration_impl() noexcept{} -#line 642 "reflect.h2" +#line 683 "reflect.h2" //----------------------------------------------------------------------- // Alias declarations // -#line 649 "reflect.h2" - alias_declaration::alias_declaration( +#line 692 "reflect.h2" + alias_declaration_impl::alias_declaration_impl( - declaration_node* n_, - cpp2::impl::in s + cpp2::impl::in csb, + declaration_node* n_ ) - : declaration{ n_, s } -#line 654 "reflect.h2" + : declaration_base{ csb, n_ } + , alias_declaration::interface{ } +#line 697 "reflect.h2" { if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(is_alias)((*cpp2::impl::assert_not_null(n)))) ) { cpp2::cpp2_default.report_violation(""); } } - alias_declaration::alias_declaration(alias_declaration const& that) - : declaration{ static_cast(that) }{} + alias_declaration_impl::~alias_declaration_impl() noexcept{} -#line 661 "reflect.h2" +#line 704 "reflect.h2" //----------------------------------------------------------------------- -// +// TODO(DyXel): Update this with something more apt? // Metafunctions - these are hardwired for now until we get to the // step of writing a Cpp2 interpreter to run inside the compiler // @@ -2261,7 +2335,7 @@ declaration::declaration(declaration const& that) // Some common metafunction helpers (metafunctions are just functions, // so they can be factored as usual) // -#line 673 "reflect.h2" +#line 716 "reflect.h2" auto add_virtual_destructor(meta::type_declaration& t) -> void { CPP2_UFCS(add_member)(t, "operator=: (virtual move this) = { }"); @@ -2282,7 +2356,7 @@ auto add_virtual_destructor(meta::type_declaration& t) -> void // // The verbose name is on purpose, lets try to give it a better name if it // can be generalized into something useful for all developers. -#line 693 "reflect.h2" +#line 736 "reflect.h2" auto foreign_interface_pseudovalue(meta::type_declaration& t) -> void { std::vector interface_funcs {}; @@ -2344,7 +2418,7 @@ auto foreign_interface_pseudovalue(meta::type_declaration& t) -> void CPP2_UFCS(add_member)(t, "operator=: (move this) = { }\n"); } -#line 755 "reflect.h2" +#line 798 "reflect.h2" //----------------------------------------------------------------------- // // "... an abstract base class defines an interface ..." @@ -2357,7 +2431,7 @@ auto foreign_interface_pseudovalue(meta::type_declaration& t) -> void // // an abstract base class having only pure virtual functions // -#line 767 "reflect.h2" +#line 810 "reflect.h2" auto interface(meta::type_declaration& t) -> void { auto has_dtor {false}; @@ -2384,7 +2458,7 @@ auto interface(meta::type_declaration& t) -> void } } -#line 794 "reflect.h2" +#line 837 "reflect.h2" //----------------------------------------------------------------------- // // "C.35: A base class destructor should be either public and @@ -2404,7 +2478,7 @@ auto interface(meta::type_declaration& t) -> void // // Unlike an interface, it can have nonpublic and nonvirtual functions. // -#line 813 "reflect.h2" +#line 856 "reflect.h2" auto polymorphic_base(meta::type_declaration& t) -> void { auto has_dtor {false}; @@ -2429,7 +2503,7 @@ auto polymorphic_base(meta::type_declaration& t) -> void } } -#line 838 "reflect.h2" +#line 881 "reflect.h2" //----------------------------------------------------------------------- // // "... A totally ordered type ... requires operator<=> that @@ -2450,7 +2524,7 @@ auto polymorphic_base(meta::type_declaration& t) -> void //----------------------------------------------------------------------- // -#line 858 "reflect.h2" +#line 901 "reflect.h2" auto ordered_impl( meta::type_declaration& t, cpp2::impl::in ordering// must be "strong_ordering" etc. @@ -2480,7 +2554,7 @@ auto ordered_impl( // // Note: the ordering that should be encouraged as default gets the nice name // -#line 887 "reflect.h2" +#line 930 "reflect.h2" auto ordered(meta::type_declaration& t) -> void { ordered_impl(t, "strong_ordering"); @@ -2489,7 +2563,7 @@ auto ordered(meta::type_declaration& t) -> void //----------------------------------------------------------------------- // weakly_ordered - a weakly ordered type // -#line 895 "reflect.h2" +#line 938 "reflect.h2" auto weakly_ordered(meta::type_declaration& t) -> void { ordered_impl(t, "weak_ordering"); @@ -2498,13 +2572,13 @@ auto weakly_ordered(meta::type_declaration& t) -> void //----------------------------------------------------------------------- // partially_ordered - a partially ordered type // -#line 903 "reflect.h2" +#line 946 "reflect.h2" auto partially_ordered(meta::type_declaration& t) -> void { ordered_impl(t, "partial_ordering"); } -#line 909 "reflect.h2" +#line 952 "reflect.h2" //----------------------------------------------------------------------- // // "A value is ... a regular type. It must have all public @@ -2521,7 +2595,7 @@ auto partially_ordered(meta::type_declaration& t) -> void // // A type with (copy and move) x (construction and assignment) // -#line 925 "reflect.h2" +#line 968 "reflect.h2" auto copyable(meta::type_declaration& t) -> void { // If the user explicitly wrote any of the copy/move functions, @@ -2556,7 +2630,7 @@ auto copyable(meta::type_declaration& t) -> void // A regular type: copyable, plus has public default construction // and no protected or virtual functions // -#line 959 "reflect.h2" +#line 1002 "reflect.h2" auto basic_value(meta::type_declaration& t) -> void { CPP2_UFCS(copyable)(t); @@ -2585,28 +2659,28 @@ auto basic_value(meta::type_declaration& t) -> void // // Note: the ordering that should be encouraged as default gets the nice name // -#line 987 "reflect.h2" +#line 1030 "reflect.h2" auto value(meta::type_declaration& t) -> void { CPP2_UFCS(ordered)(t); CPP2_UFCS(basic_value)(t); } -#line 993 "reflect.h2" +#line 1036 "reflect.h2" auto weakly_ordered_value(meta::type_declaration& t) -> void { CPP2_UFCS(weakly_ordered)(t); CPP2_UFCS(basic_value)(t); } -#line 999 "reflect.h2" +#line 1042 "reflect.h2" auto partially_ordered_value(meta::type_declaration& t) -> void { CPP2_UFCS(partially_ordered)(t); CPP2_UFCS(basic_value)(t); } -#line 1006 "reflect.h2" +#line 1049 "reflect.h2" //----------------------------------------------------------------------- // // C.20: If you can avoid defining default operations, do @@ -2629,7 +2703,7 @@ auto partially_ordered_value(meta::type_declaration& t) -> void // // a type without declared copy/move/destructor functions // -#line 1028 "reflect.h2" +#line 1071 "reflect.h2" auto cpp1_rule_of_zero(meta::type_declaration& t) -> void { for ( auto& mf : CPP2_UFCS(get_member_functions)(t) ) @@ -2667,7 +2741,7 @@ auto cpp1_rule_of_zero(meta::type_declaration& t) -> void // no virtual functions, and no user-defined constructors // (i.e., no invariants) or assignment or destructors. // -#line 1065 "reflect.h2" +#line 1108 "reflect.h2" auto cpp2_struct(meta::type_declaration& t) -> void { std::string ctor_params {}; @@ -2719,7 +2793,7 @@ value_member_info::value_member_info(auto const& name_, auto const& type_, auto , type{ type_ } , value{ value_ }{} -#line 1112 "reflect.h2" +#line 1155 "reflect.h2" //----------------------------------------------------------------------- // // "C enumerations constitute a curiously half-baked concept. ... @@ -2738,7 +2812,7 @@ value_member_info::value_member_info(auto const& name_, auto const& type_, auto // a type together with named constants that are its possible values // -#line 1135 "reflect.h2" +#line 1178 "reflect.h2" auto basic_enum( meta::type_declaration& t, auto const& nextval, @@ -2763,7 +2837,7 @@ auto basic_enum( { std::string value{"-1"}; -#line 1158 "reflect.h2" +#line 1201 "reflect.h2" for ( auto const& m : CPP2_UFCS(get_members)(t) ) if ( CPP2_UFCS(is_member_object)(m)) @@ -2805,7 +2879,7 @@ std::string value{"-1"}; } } -#line 1198 "reflect.h2" +#line 1241 "reflect.h2" if ((CPP2_UFCS(empty)(enumerators))) { CPP2_UFCS(error)(t, "an enumeration must contain at least one enumerator value"); return ; @@ -2856,7 +2930,7 @@ std::string value{"-1"}; } } -#line 1249 "reflect.h2" +#line 1292 "reflect.h2" // 2. Replace: Erase the contents and replace with modified contents // // Note that most values and functions are declared as '==' compile-time values, i.e. Cpp1 'constexpr' @@ -2906,7 +2980,7 @@ std::string to_string_impl{" to_string_impl: (this, prefix: std::string_view" // Provide 'to_string' and 'to_code' functions to print enumerator // name(s) as human-readable strings or as code expressions -#line 1296 "reflect.h2" +#line 1339 "reflect.h2" { if (bitwise) { to_string_impl += ", separator: std::string_view ) -> std::string = { \n" @@ -2947,7 +3021,7 @@ std::string to_string_impl{" to_string_impl: (this, prefix: std::string_view" } } -#line 1335 "reflect.h2" +#line 1378 "reflect.h2" if (bitwise) { CPP2_UFCS(add_member)(t, " to_string: (this) -> std::string = to_string_impl( \"\", \", \" );"); CPP2_UFCS(add_member)(t, " to_code : (this) -> std::string = to_string_impl( \"" + cpp2::to_string(CPP2_UFCS(name)(t)) + "::\", \" | \" );"); @@ -2961,7 +3035,7 @@ std::string from_string{" from_string: (s: std::string_view) -> " + cpp2::to_ // Provide a 'from_string' function to parse strings into enumerators -#line 1346 "reflect.h2" +#line 1389 "reflect.h2" { std::string_view prefix {""}; std::string_view combine_op {"return"}; @@ -2983,7 +3057,7 @@ std::string from_string{" from_string: (s: std::string_view) -> " + cpp2::to_ { std::string_view else_{""}; -#line 1366 "reflect.h2" +#line 1409 "reflect.h2" for ( auto const& e : cpp2::move(enumerators) ) { from_string += " " + cpp2::to_string(else_) + "if \"" + cpp2::to_string(e.name) + "\" == x { " + cpp2::to_string(combine_op) + " " + cpp2::to_string(e.name) + "; }\n"; @@ -2991,7 +3065,7 @@ std::string_view else_{""}; } } -#line 1372 "reflect.h2" +#line 1415 "reflect.h2" if (bitwise) { from_string += " else { break outer; }\n" " }\n" @@ -3007,11 +3081,11 @@ std::string_view else_{""}; } } -#line 1386 "reflect.h2" +#line 1429 "reflect.h2" CPP2_UFCS(add_member)(t, " from_code: (s: std::string_view) -> " + cpp2::to_string(CPP2_UFCS(name)(t)) + " = { str: std::string = s; return from_string( cpp2::string_util::replace_all(str, \"" + cpp2::to_string(CPP2_UFCS(name)(t)) + "::\", \"\" ) ); }"); } -#line 1390 "reflect.h2" +#line 1433 "reflect.h2" //----------------------------------------------------------------------- // // "An enum[...] is a totally ordered value type that stores a @@ -3021,7 +3095,7 @@ std::string_view else_{""}; // // -- P0707R4, section 3 // -#line 1399 "reflect.h2" +#line 1442 "reflect.h2" auto cpp2_enum(meta::type_declaration& t) -> void { // Let basic_enum do its thing, with an incrementing value generator @@ -3038,7 +3112,7 @@ auto cpp2_enum(meta::type_declaration& t) -> void ); } -#line 1416 "reflect.h2" +#line 1459 "reflect.h2" //----------------------------------------------------------------------- // // "flag_enum expresses an enumeration that stores values @@ -3049,7 +3123,7 @@ auto cpp2_enum(meta::type_declaration& t) -> void // // -- P0707R4, section 3 // -#line 1426 "reflect.h2" +#line 1469 "reflect.h2" auto flag_enum(meta::type_declaration& t) -> void { // Let basic_enum do its thing, with a power-of-two value generator @@ -3071,7 +3145,7 @@ auto flag_enum(meta::type_declaration& t) -> void ); } -#line 1448 "reflect.h2" +#line 1491 "reflect.h2" //----------------------------------------------------------------------- // // "As with void*, programmers should know that unions [...] are @@ -3096,7 +3170,7 @@ auto flag_enum(meta::type_declaration& t) -> void // a type that contains exactly one of a fixed set of values at a time // -#line 1472 "reflect.h2" +#line 1515 "reflect.h2" auto cpp2_union(meta::type_declaration& t) -> void { std::vector alternatives {}; @@ -3105,7 +3179,7 @@ auto value{0}; // 1. Gather: All the user-written members, and find/compute the max size -#line 1479 "reflect.h2" +#line 1522 "reflect.h2" for ( auto const& m : CPP2_UFCS(get_members)(t) ) { do @@ -3135,7 +3209,7 @@ auto value{0}; } while (false); ++value; } } -#line 1507 "reflect.h2" +#line 1550 "reflect.h2" std::string discriminator_type {}; if (cpp2::impl::cmp_less(CPP2_UFCS(ssize)(alternatives),std::numeric_limits::max())) { discriminator_type = "i8"; @@ -3150,7 +3224,7 @@ auto value{0}; discriminator_type = "i64"; }}} -#line 1522 "reflect.h2" +#line 1565 "reflect.h2" // 2. Replace: Erase the contents and replace with modified contents CPP2_UFCS(remove_marked_members)(t); @@ -3159,7 +3233,7 @@ std::string storage{" _storage: cpp2::aligned_storage t) -> void { std::cout << CPP2_UFCS(print)(t) << "\n"; } -#line 1628 "reflect.h2" +#line 1671 "reflect.h2" auto print(cpp2::impl::in f) -> void { std::cout << CPP2_UFCS(print)(f) << "\n"; } -#line 1634 "reflect.h2" +#line 1677 "reflect.h2" //----------------------------------------------------------------------- // // meta - mark f as a metafunction and generate registration code for it // -#line 1638 "reflect.h2" +#line 1681 "reflect.h2" auto meta(meta::function_declaration& f) -> void { // TODO(DyXel): Check that the function: @@ -3391,7 +3465,7 @@ return none; [[nodiscard]] auto expression_flags::from_code(cpp2::impl::in s) -> expression_flags{ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::move(str), "expression_flags::", "")); } -#line 1654 "reflect.h2" +#line 1697 "reflect.h2" //----------------------------------------------------------------------- // // regex - creates regular expressions from members @@ -3407,11 +3481,11 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov // ``` // -#line 1670 "reflect.h2" +#line 1713 "reflect.h2" // Possible modifiers for a regular expression. // -#line 1674 "reflect.h2" +#line 1717 "reflect.h2" // mod: i // mod: m // mod: s @@ -3419,106 +3493,106 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov // mod: x // mod: xx -#line 1683 "reflect.h2" +#line 1726 "reflect.h2" // Tokens for regular expressions. // // Basic class for a regex token. // -#line 1692 "reflect.h2" +#line 1735 "reflect.h2" regex_token::regex_token(cpp2::impl::in str) : string_rep{ str }{ -#line 1694 "reflect.h2" +#line 1737 "reflect.h2" } -#line 1696 "reflect.h2" +#line 1739 "reflect.h2" regex_token::regex_token() : string_rep{ "" }{ -#line 1698 "reflect.h2" +#line 1741 "reflect.h2" } //parse: (inout ctx: parse_context) -> token_ptr; // Generate the matching code. -#line 1703 "reflect.h2" +#line 1746 "reflect.h2" auto regex_token::add_groups([[maybe_unused]] std::set& unnamed_param_2) const -> void{}// Adds all group indices to the set. -#line 1704 "reflect.h2" +#line 1747 "reflect.h2" [[nodiscard]] auto regex_token::to_string() const& -> std::string{return string_rep; }// Create a string representation. -#line 1705 "reflect.h2" +#line 1748 "reflect.h2" auto regex_token::set_string(cpp2::impl::in s) & -> void{string_rep = s; } regex_token::~regex_token() noexcept{}// Set the string representation. -#line 1720 "reflect.h2" +#line 1763 "reflect.h2" regex_token_check::regex_token_check(cpp2::impl::in str, cpp2::impl::in check_) : regex_token{ str } , check{ check_ }{ -#line 1723 "reflect.h2" +#line 1766 "reflect.h2" } -#line 1725 "reflect.h2" +#line 1768 "reflect.h2" auto regex_token_check::generate_code(generation_context& ctx) const -> void{ ctx.add_check(check + "(" + ctx.match_parameters() + ")"); } regex_token_check::~regex_token_check() noexcept{} -#line 1739 "reflect.h2" +#line 1782 "reflect.h2" regex_token_code::regex_token_code(cpp2::impl::in str, cpp2::impl::in code_) : regex_token{ str } , code{ code_ }{ -#line 1742 "reflect.h2" +#line 1785 "reflect.h2" } -#line 1744 "reflect.h2" +#line 1787 "reflect.h2" auto regex_token_code::generate_code(generation_context& ctx) const -> void{ ctx.add(code); } regex_token_code::~regex_token_code() noexcept{} -#line 1756 "reflect.h2" +#line 1799 "reflect.h2" regex_token_empty::regex_token_empty(cpp2::impl::in str) : regex_token{ str }{ -#line 1758 "reflect.h2" +#line 1801 "reflect.h2" } -#line 1760 "reflect.h2" +#line 1803 "reflect.h2" auto regex_token_empty::generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void{ // Nothing. } regex_token_empty::~regex_token_empty() noexcept{} -#line 1774 "reflect.h2" +#line 1817 "reflect.h2" regex_token_list::regex_token_list(cpp2::impl::in t) : regex_token{ gen_string(t) } , tokens{ t }{ -#line 1777 "reflect.h2" +#line 1820 "reflect.h2" } -#line 1779 "reflect.h2" +#line 1822 "reflect.h2" auto regex_token_list::generate_code(generation_context& ctx) const -> void{ for ( auto const& token : tokens ) { (*cpp2::impl::assert_not_null(token)).generate_code(ctx); } } -#line 1785 "reflect.h2" +#line 1828 "reflect.h2" auto regex_token_list::add_groups(std::set& groups) const -> void{ for ( auto const& token : tokens ) { (*cpp2::impl::assert_not_null(token)).add_groups(groups); } } -#line 1791 "reflect.h2" +#line 1834 "reflect.h2" [[nodiscard]] auto regex_token_list::gen_string(cpp2::impl::in vec) -> std::string{ std::string r {""}; for ( auto const& token : vec ) { @@ -3529,7 +3603,7 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov regex_token_list::~regex_token_list() noexcept{} -#line 1814 "reflect.h2" +#line 1857 "reflect.h2" auto parse_context_group_state::next_alternative() & -> void{ token_vec new_list {}; std::swap(new_list, cur_match_list); @@ -3537,14 +3611,14 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov static_cast(alternate_match_lists.insert(alternate_match_lists.end(), CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, cpp2::move(new_list)))); } -#line 1822 "reflect.h2" +#line 1865 "reflect.h2" auto parse_context_group_state::swap(parse_context_group_state& t) & -> void{ std::swap(cur_match_list, t.cur_match_list); std::swap(alternate_match_lists, t.alternate_match_lists); std::swap(modifiers, t.modifiers); } -#line 1829 "reflect.h2" +#line 1872 "reflect.h2" [[nodiscard]] auto parse_context_group_state::get_as_token() & -> token_ptr{ if (alternate_match_lists.empty()) { post_process_list(cur_match_list); @@ -3556,15 +3630,15 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov } } -#line 1841 "reflect.h2" +#line 1884 "reflect.h2" auto parse_context_group_state::add(cpp2::impl::in token) & -> void{ cur_match_list.push_back(token); } -#line 1846 "reflect.h2" +#line 1889 "reflect.h2" [[nodiscard]] auto parse_context_group_state::empty() const& -> bool { return cur_match_list.empty(); } -#line 1850 "reflect.h2" +#line 1893 "reflect.h2" auto parse_context_group_state::post_process_list(token_vec& list) -> void{ // Merge all characters auto merge_pos {list.begin()}; @@ -3585,7 +3659,7 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov , modifiers{ modifiers_ }{} parse_context_group_state::parse_context_group_state(){} -#line 1876 "reflect.h2" +#line 1919 "reflect.h2" [[nodiscard]] auto parse_context_branch_reset_state::next() & -> int{ auto g {cur_group}; cur_group += 1; @@ -3594,20 +3668,20 @@ parse_context_group_state::parse_context_group_state(){} return g; } -#line 1885 "reflect.h2" +#line 1928 "reflect.h2" auto parse_context_branch_reset_state::set_next(cpp2::impl::in g) & -> void{ cur_group = g; max_group = max(max_group, g); } -#line 1891 "reflect.h2" +#line 1934 "reflect.h2" auto parse_context_branch_reset_state::next_alternative() & -> void{ if (is_active) { cur_group = from; } } -#line 1898 "reflect.h2" +#line 1941 "reflect.h2" auto parse_context_branch_reset_state::set_active_reset(cpp2::impl::in restart) & -> void{ is_active = true; cur_group = restart; @@ -3622,16 +3696,16 @@ parse_context_group_state::parse_context_group_state(){} , from{ from_ }{} parse_context_branch_reset_state::parse_context_branch_reset_state(){} -#line 1926 "reflect.h2" +#line 1969 "reflect.h2" parse_context::parse_context(cpp2::impl::in r, auto const& e) : regex{ r } , root{ CPP2_UFCS_TEMPLATE_NONLOCAL(cpp2_new)(cpp2::shared, "") } , error_out{ e }{ -#line 1930 "reflect.h2" +#line 1973 "reflect.h2" } -#line 1936 "reflect.h2" +#line 1979 "reflect.h2" [[nodiscard]] auto parse_context::start_group() & -> parse_context_group_state { parse_context_group_state old_state {}; @@ -3641,7 +3715,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return old_state; } -#line 1946 "reflect.h2" +#line 1989 "reflect.h2" [[nodiscard]] auto parse_context::end_group(cpp2::impl::in old_state) & -> token_ptr { auto inner {cur_group_state.get_as_token()}; @@ -3649,17 +3723,17 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return inner; } -#line 1953 "reflect.h2" +#line 1996 "reflect.h2" [[nodiscard]] auto parse_context::get_modifiers() const& -> expression_flags{ return cur_group_state.modifiers; } -#line 1957 "reflect.h2" +#line 2000 "reflect.h2" auto parse_context::set_modifiers(cpp2::impl::in mod) & -> void{ cur_group_state.modifiers = mod; } -#line 1964 "reflect.h2" +#line 2007 "reflect.h2" [[nodiscard]] auto parse_context::branch_reset_new_state() & -> parse_context_branch_reset_state { parse_context_branch_reset_state old_state {}; @@ -3669,7 +3743,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return old_state; } -#line 1973 "reflect.h2" +#line 2016 "reflect.h2" auto parse_context::branch_reset_restore_state(cpp2::impl::in old_state) & -> void { auto max_group {cur_branch_reset_state.max_group}; @@ -3677,24 +3751,24 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} cur_branch_reset_state.set_next(cpp2::move(max_group)); } -#line 1980 "reflect.h2" +#line 2023 "reflect.h2" auto parse_context::next_alternative() & -> void { cur_group_state.next_alternative(); cur_branch_reset_state.next_alternative(); } -#line 1988 "reflect.h2" +#line 2031 "reflect.h2" auto parse_context::add_token(cpp2::impl::in token) & -> void{ cur_group_state.add(token); } -#line 1992 "reflect.h2" +#line 2035 "reflect.h2" [[nodiscard]] auto parse_context::has_token() const& -> bool{ return !(cur_group_state.empty()); } -#line 1996 "reflect.h2" +#line 2039 "reflect.h2" [[nodiscard]] auto parse_context::pop_token() & -> token_ptr { token_ptr r {nullptr}; @@ -3706,22 +3780,22 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 2007 "reflect.h2" +#line 2050 "reflect.h2" [[nodiscard]] auto parse_context::get_as_token() & -> token_ptr{ return root; } -#line 2013 "reflect.h2" +#line 2056 "reflect.h2" [[nodiscard]] auto parse_context::get_cur_group() const& -> int{ return cur_branch_reset_state.cur_group; } -#line 2017 "reflect.h2" +#line 2060 "reflect.h2" [[nodiscard]] auto parse_context::next_group() & -> int{ return cur_branch_reset_state.next(); } -#line 2021 "reflect.h2" +#line 2064 "reflect.h2" auto parse_context::set_named_group(cpp2::impl::in name, cpp2::impl::in id) & -> void { if (!(named_groups.contains(name))) {// Redefinition of group name is not an error. The left most one is retained. @@ -3729,7 +3803,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2028 "reflect.h2" +#line 2071 "reflect.h2" [[nodiscard]] auto parse_context::get_named_group(cpp2::impl::in name) const& -> int { auto iter {named_groups.find(name)}; @@ -3741,10 +3815,10 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2041 "reflect.h2" +#line 2084 "reflect.h2" [[nodiscard]] auto parse_context::current() const& -> char{return CPP2_ASSERT_IN_BOUNDS(regex, pos); } -#line 2044 "reflect.h2" +#line 2087 "reflect.h2" [[nodiscard]] auto parse_context::get_next_position(cpp2::impl::in in_class, cpp2::impl::in no_skip) const& -> size_t { auto perl_syntax {false}; @@ -3784,7 +3858,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return cur; } -#line 2084 "reflect.h2" +#line 2127 "reflect.h2" [[nodiscard]] auto parse_context::next_impl(cpp2::impl::in in_class, cpp2::impl::in no_skip) & -> bool { pos = get_next_position(in_class, no_skip); @@ -3796,14 +3870,14 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2095 "reflect.h2" +#line 2138 "reflect.h2" [[nodiscard]] auto parse_context::next() & -> auto { return next_impl(false, false); } -#line 2096 "reflect.h2" +#line 2139 "reflect.h2" [[nodiscard]] auto parse_context::next_in_class() & -> auto { return next_impl(true, false); } -#line 2097 "reflect.h2" +#line 2140 "reflect.h2" [[nodiscard]] auto parse_context::next_no_skip() & -> auto { return next_impl(false, true); } -#line 2099 "reflect.h2" +#line 2142 "reflect.h2" [[nodiscard]] auto parse_context::next_n(cpp2::impl::in n) & -> bool{ auto r {true}; auto cur {0}; @@ -3813,10 +3887,10 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 2108 "reflect.h2" +#line 2151 "reflect.h2" [[nodiscard]] auto parse_context::has_next() const& -> bool{return cpp2::impl::cmp_less(pos,regex.size()); } -#line 2110 "reflect.h2" +#line 2153 "reflect.h2" [[nodiscard]] auto parse_context::grab_until_impl(cpp2::impl::in e, cpp2::impl::out r, cpp2::impl::in any) & -> bool { auto end {pos}; @@ -3838,14 +3912,14 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2131 "reflect.h2" +#line 2174 "reflect.h2" [[nodiscard]] auto parse_context::grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(e, cpp2::impl::out(&r), false); } -#line 2132 "reflect.h2" +#line 2175 "reflect.h2" [[nodiscard]] auto parse_context::grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(std::string(1, e), cpp2::impl::out(&r), false); } -#line 2133 "reflect.h2" +#line 2176 "reflect.h2" [[nodiscard]] auto parse_context::grab_until_one_of(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(e, cpp2::impl::out(&r), true); } -#line 2135 "reflect.h2" +#line 2178 "reflect.h2" [[nodiscard]] auto parse_context::grab_n(cpp2::impl::in n, cpp2::impl::out r) & -> bool { if (cpp2::impl::cmp_less_eq(pos + cpp2::impl::as_(n),regex.size())) { @@ -3859,7 +3933,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2148 "reflect.h2" +#line 2191 "reflect.h2" [[nodiscard]] auto parse_context::grab_number() & -> std::string { auto start {pos}; @@ -3881,7 +3955,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return cpp2::move(r.value()); } -#line 2169 "reflect.h2" +#line 2212 "reflect.h2" [[nodiscard]] auto parse_context::peek_impl(cpp2::impl::in in_class) const& -> char{ auto next_pos {get_next_position(in_class, false)}; if (cpp2::impl::cmp_less(next_pos,regex.size())) { @@ -3892,12 +3966,12 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2179 "reflect.h2" +#line 2222 "reflect.h2" [[nodiscard]] auto parse_context::peek() const& -> auto { return peek_impl(false); } -#line 2180 "reflect.h2" +#line 2223 "reflect.h2" [[nodiscard]] auto parse_context::peek_in_class() const& -> auto { return peek_impl(true); } -#line 2185 "reflect.h2" +#line 2228 "reflect.h2" [[nodiscard]] auto parse_context::parser_group_modifiers(cpp2::impl::in change_str, expression_flags& parser_modifiers) & -> bool { auto is_negative {false}; @@ -3952,7 +4026,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return true; } -#line 2239 "reflect.h2" +#line 2282 "reflect.h2" [[nodiscard]] auto parse_context::parse_until(cpp2::impl::in term) & -> bool{ token_ptr cur_token {}; @@ -3991,7 +4065,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return true; } -#line 2277 "reflect.h2" +#line 2320 "reflect.h2" [[nodiscard]] auto parse_context::parse(cpp2::impl::in modifiers) & -> bool { @@ -4007,21 +4081,21 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 2294 "reflect.h2" +#line 2337 "reflect.h2" [[nodiscard]] auto parse_context::get_pos() const& -> auto { return pos; } -#line 2295 "reflect.h2" +#line 2338 "reflect.h2" [[nodiscard]] auto parse_context::get_range(cpp2::impl::in start, cpp2::impl::in end) const& -> auto { return std::string(regex.substr(start, end - start + 1)); } -#line 2296 "reflect.h2" +#line 2339 "reflect.h2" [[nodiscard]] auto parse_context::valid() const& -> bool{return has_next() && !(has_error); } -#line 2298 "reflect.h2" +#line 2341 "reflect.h2" [[nodiscard]] auto parse_context::error(cpp2::impl::in err) & -> token_ptr{ has_error = true; error_out("Error during parsing of regex '" + cpp2::to_string(regex) + "' at position '" + cpp2::to_string(pos) + "': " + cpp2::to_string(err) + ""); return nullptr; } -#line 2313 "reflect.h2" +#line 2356 "reflect.h2" auto generation_function_context::add_tabs(cpp2::impl::in c) & -> void{ int i {0}; for( ; cpp2::impl::cmp_less(i,c); i += 1 ) { @@ -4029,7 +4103,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2320 "reflect.h2" +#line 2363 "reflect.h2" auto generation_function_context::remove_tabs(cpp2::impl::in c) & -> void{ tabs = tabs.substr(0, (cpp2::impl::as_(c)) * 2); } @@ -4039,22 +4113,22 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} , tabs{ tabs_ }{} generation_function_context::generation_function_context(){} -#line 2338 "reflect.h2" +#line 2381 "reflect.h2" [[nodiscard]] auto generation_context::match_parameters() const& -> std::string{return "r.pos, ctx"; } -#line 2343 "reflect.h2" +#line 2386 "reflect.h2" auto generation_context::add(cpp2::impl::in s) & -> void{ auto cur {get_current()}; (*cpp2::impl::assert_not_null(cur)).code += "" + cpp2::to_string((*cpp2::impl::assert_not_null(cur)).tabs) + cpp2::to_string(s) + "\n"; } -#line 2349 "reflect.h2" +#line 2392 "reflect.h2" auto generation_context::add_check(cpp2::impl::in check) & -> void{ auto cur {get_current()}; (*cpp2::impl::assert_not_null(cur)).code += "" + cpp2::to_string((*cpp2::impl::assert_not_null(cur)).tabs) + "if !cpp2::regex::" + cpp2::to_string(check) + " { r.matched = false; break; }\n"; } -#line 2355 "reflect.h2" +#line 2398 "reflect.h2" auto generation_context::add_statefull(cpp2::impl::in next_func, cpp2::impl::in check) & -> void { end_func_statefull(check); @@ -4063,7 +4137,7 @@ generation_function_context::generation_function_context(){} start_func_named(cpp2::move(name)); } -#line 2363 "reflect.h2" +#line 2406 "reflect.h2" auto generation_context::start_func_named(cpp2::impl::in name) & -> void { auto cur {new_context()}; @@ -4075,7 +4149,7 @@ generation_function_context::generation_function_context(){} (*cpp2::impl::assert_not_null(cpp2::move(cur))).add_tabs(3); } -#line 2374 "reflect.h2" +#line 2417 "reflect.h2" [[nodiscard]] auto generation_context::start_func() & -> std::string { auto name {gen_func_name()}; @@ -4083,7 +4157,7 @@ generation_function_context::generation_function_context(){} return cpp2::move(name) + "()"; } -#line 2381 "reflect.h2" +#line 2424 "reflect.h2" auto generation_context::end_func_statefull(cpp2::impl::in s) & -> void { auto cur {get_current()}; @@ -4103,7 +4177,7 @@ generation_function_context::generation_function_context(){} finish_context(); } -#line 2401 "reflect.h2" +#line 2444 "reflect.h2" [[nodiscard]] auto generation_context::generate_func(cpp2::impl::in token) & -> std::string { auto name {start_func()}; @@ -4113,7 +4187,7 @@ generation_function_context::generation_function_context(){} return name; } -#line 2411 "reflect.h2" +#line 2454 "reflect.h2" [[nodiscard]] auto generation_context::generate_reset(cpp2::impl::in> groups) & -> std::string { if (groups.empty()) { @@ -4136,33 +4210,33 @@ generation_function_context::generation_function_context(){} return cpp2::move(name) + "()"; } -#line 2435 "reflect.h2" +#line 2478 "reflect.h2" [[nodiscard]] auto generation_context::gen_func_name() & -> std::string{ auto cur_id {matcher_func}; matcher_func += 1; return "func_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2441 "reflect.h2" +#line 2484 "reflect.h2" [[nodiscard]] auto generation_context::next_func_name() & -> std::string{ return gen_func_name() + "()"; } -#line 2445 "reflect.h2" +#line 2488 "reflect.h2" [[nodiscard]] auto generation_context::gen_reset_func_name() & -> std::string{ auto cur_id {reset_func}; reset_func += 1; return "reset_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2451 "reflect.h2" +#line 2494 "reflect.h2" [[nodiscard]] auto generation_context::gen_temp() & -> std::string{ auto cur_id {temp_name}; temp_name += 1; return "tmp_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2459 "reflect.h2" +#line 2502 "reflect.h2" [[nodiscard]] auto generation_context::new_context() & -> generation_function_context*{ gen_stack.push_back(generation_function_context()); auto cur {get_current()}; @@ -4171,7 +4245,7 @@ generation_function_context::generation_function_context(){} return cur; } -#line 2467 "reflect.h2" +#line 2510 "reflect.h2" auto generation_context::finish_context() & -> void{ auto cur {get_current()}; auto base {get_base()}; @@ -4180,22 +4254,22 @@ generation_function_context::generation_function_context(){} gen_stack.pop_back(); } -#line 2477 "reflect.h2" +#line 2520 "reflect.h2" [[nodiscard]] auto generation_context::get_current() & -> generation_function_context*{ return &gen_stack.back(); } -#line 2481 "reflect.h2" +#line 2524 "reflect.h2" [[nodiscard]] auto generation_context::get_base() & -> generation_function_context*{ return &CPP2_ASSERT_IN_BOUNDS_LITERAL(gen_stack, 0); } -#line 2485 "reflect.h2" +#line 2528 "reflect.h2" [[nodiscard]] auto generation_context::get_entry_func() const& -> std::string{ return entry_func; } -#line 2489 "reflect.h2" +#line 2532 "reflect.h2" [[nodiscard]] auto generation_context::create_named_group_lookup(cpp2::impl::in> named_groups) const& -> std::string { std::string res {"get_named_group_index: (name) -> int = {\n"}; @@ -4219,18 +4293,18 @@ generation_function_context::generation_function_context(){} return res; } -#line 2514 "reflect.h2" +#line 2557 "reflect.h2" [[nodiscard]] auto generation_context::run(cpp2::impl::in token) & -> std::string{ entry_func = generate_func(token); return (*cpp2::impl::assert_not_null(get_base())).code; } -#line 2529 "reflect.h2" +#line 2572 "reflect.h2" alternative_token::alternative_token() : regex_token_empty{ "" }{} -#line 2531 "reflect.h2" +#line 2574 "reflect.h2" [[nodiscard]] auto alternative_token::parse(parse_context& ctx) -> token_ptr{ if (ctx.current() != '|') {return nullptr; } @@ -4241,15 +4315,15 @@ generation_function_context::generation_function_context(){} alternative_token::~alternative_token() noexcept{} -#line 2546 "reflect.h2" +#line 2589 "reflect.h2" alternative_token_gen::alternative_token_gen(cpp2::impl::in a) : regex_token{ gen_string(a) } , alternatives{ a }{ -#line 2549 "reflect.h2" +#line 2592 "reflect.h2" } -#line 2551 "reflect.h2" +#line 2594 "reflect.h2" auto alternative_token_gen::generate_code(generation_context& ctx) const -> void { std::string functions {""}; @@ -4267,7 +4341,7 @@ generation_function_context::generation_function_context(){} ctx.add_statefull(next_name, "cpp2::regex::alternative_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ", other, " + cpp2::to_string(next_name) + " " + cpp2::to_string(cpp2::move(functions)) + ")"); } -#line 2568 "reflect.h2" +#line 2611 "reflect.h2" auto alternative_token_gen::add_groups(std::set& groups) const -> void { for ( auto const& cur : alternatives ) { @@ -4275,7 +4349,7 @@ generation_function_context::generation_function_context(){} } } -#line 2575 "reflect.h2" +#line 2618 "reflect.h2" [[nodiscard]] auto alternative_token_gen::gen_string(cpp2::impl::in a) -> std::string { std::string r {""}; @@ -4291,14 +4365,14 @@ generation_function_context::generation_function_context(){} alternative_token_gen::~alternative_token_gen() noexcept{} -#line 2596 "reflect.h2" +#line 2639 "reflect.h2" any_token::any_token(cpp2::impl::in single_line) : regex_token_check{ ".", "any_token_matcher" }{ -#line 2598 "reflect.h2" +#line 2641 "reflect.h2" } -#line 2600 "reflect.h2" +#line 2643 "reflect.h2" [[nodiscard]] auto any_token::parse(parse_context& ctx) -> token_ptr{ if ('.' != ctx.current()) {return nullptr; } @@ -4307,21 +4381,21 @@ generation_function_context::generation_function_context(){} any_token::~any_token() noexcept{} -#line 2617 "reflect.h2" +#line 2660 "reflect.h2" char_token::char_token(cpp2::impl::in t, cpp2::impl::in ignore_case_) : regex_token{ std::string(1, t) } , token{ t } , ignore_case{ ignore_case_ }{ -#line 2621 "reflect.h2" +#line 2664 "reflect.h2" } -#line 2623 "reflect.h2" +#line 2666 "reflect.h2" [[nodiscard]] auto char_token::parse(parse_context& ctx) -> token_ptr{ return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, ctx.current(), ctx.get_modifiers().has(expression_flags::case_insensitive)); } -#line 2627 "reflect.h2" +#line 2670 "reflect.h2" auto char_token::generate_code(generation_context& ctx) const -> void { if (ignore_case) { @@ -4330,14 +4404,14 @@ generation_function_context::generation_function_context(){} { size_t i{0}; -#line 2633 "reflect.h2" +#line 2676 "reflect.h2" for( ; cpp2::impl::cmp_less(i,token.size()); i += 1 ) { CPP2_ASSERT_IN_BOUNDS(lower, i) = string_util::safe_tolower(CPP2_ASSERT_IN_BOUNDS(token, i)); CPP2_ASSERT_IN_BOUNDS(upper, i) = string_util::safe_toupper(CPP2_ASSERT_IN_BOUNDS(token, i)); } } -#line 2638 "reflect.h2" +#line 2681 "reflect.h2" if (upper != lower) { gen_case_insensitive(cpp2::move(lower), cpp2::move(upper), ctx); } @@ -4350,7 +4424,7 @@ size_t i{0}; } } -#line 2650 "reflect.h2" +#line 2693 "reflect.h2" auto char_token::gen_case_insensitive(cpp2::impl::in lower, cpp2::impl::in upper, generation_context& ctx) const& -> void { std::string name {"str_" + cpp2::to_string(ctx.gen_temp()) + ""}; @@ -4372,7 +4446,7 @@ size_t i{0}; ctx.add("else { break; }"); } -#line 2671 "reflect.h2" +#line 2714 "reflect.h2" auto char_token::gen_case_sensitive(generation_context& ctx) const& -> void { std::string name {"str_" + cpp2::to_string(ctx.gen_temp()) + ""}; @@ -4391,7 +4465,7 @@ size_t i{0}; ctx.add("else { break; }"); } -#line 2689 "reflect.h2" +#line 2732 "reflect.h2" [[nodiscard]] auto char_token::add_escapes(std::string str) const& -> std::string { str = string_util::replace_all(str, "\\", "\\\\"); @@ -4407,7 +4481,7 @@ size_t i{0}; return cpp2::move(str); } -#line 2704 "reflect.h2" +#line 2747 "reflect.h2" auto char_token::append(char_token const& that) & -> void{ (*this).token += that.token; (*this).string_rep += that.string_rep; @@ -4415,19 +4489,19 @@ size_t i{0}; char_token::~char_token() noexcept{} -#line 2721 "reflect.h2" +#line 2764 "reflect.h2" class_token::class_token(cpp2::impl::in negate_, cpp2::impl::in case_insensitive_, cpp2::impl::in class_str_, cpp2::impl::in str) : regex_token{ str } , negate{ negate_ } , case_insensitive{ case_insensitive_ } , class_str{ class_str_ } -#line 2722 "reflect.h2" +#line 2765 "reflect.h2" { -#line 2727 "reflect.h2" +#line 2770 "reflect.h2" } -#line 2730 "reflect.h2" +#line 2773 "reflect.h2" [[nodiscard]] auto class_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '[') {return nullptr; } @@ -4553,13 +4627,13 @@ size_t i{0}; ); } -#line 2855 "reflect.h2" +#line 2898 "reflect.h2" auto class_token::generate_code(generation_context& ctx) const -> void { ctx.add_check("class_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ")"); } -#line 2860 "reflect.h2" +#line 2903 "reflect.h2" [[nodiscard]] auto class_token::create_matcher(cpp2::impl::in name, cpp2::impl::in template_arguments) -> std::string { auto sep {", "}; @@ -4570,12 +4644,12 @@ size_t i{0}; class_token::~class_token() noexcept{} -#line 2872 "reflect.h2" +#line 2915 "reflect.h2" [[nodiscard]] auto escape_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } -#line 2877 "reflect.h2" +#line 2920 "reflect.h2" if (std::string::npos == std::string("afenrt^.[]()*{}?+|\\").find(ctx.peek())) { return nullptr; } @@ -4609,7 +4683,7 @@ size_t i{0}; } -#line 2913 "reflect.h2" +#line 2956 "reflect.h2" [[nodiscard]] auto global_group_reset_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'K'))) {return nullptr; } @@ -4618,18 +4692,18 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, "\\K", "ctx..set_group_start(0, r.pos);"); } -#line 2935 "reflect.h2" +#line 2978 "reflect.h2" group_ref_token::group_ref_token(cpp2::impl::in id_, cpp2::impl::in case_insensitive_, cpp2::impl::in str) : regex_token{ str } , id{ id_ } , case_insensitive{ case_insensitive_ } -#line 2936 "reflect.h2" +#line 2979 "reflect.h2" { -#line 2940 "reflect.h2" +#line 2983 "reflect.h2" } -#line 2942 "reflect.h2" +#line 2985 "reflect.h2" [[nodiscard]] auto group_ref_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -4731,14 +4805,14 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, cpp2::move(group_id), ctx.get_modifiers().has(expression_flags::case_insensitive), cpp2::move(str)); } -#line 3043 "reflect.h2" +#line 3086 "reflect.h2" auto group_ref_token::generate_code(generation_context& ctx) const -> void{ ctx.add_check("group_ref_token_matcher(" + cpp2::to_string(ctx.match_parameters()) + ")"); } group_ref_token::~group_ref_token() noexcept{} -#line 3066 "reflect.h2" +#line 3109 "reflect.h2" [[nodiscard]] auto group_token::parse_lookahead(parse_context& ctx, cpp2::impl::in syntax, cpp2::impl::in positive) -> token_ptr { static_cast(ctx.next());// Skip last token defining the syntax @@ -4753,7 +4827,7 @@ size_t i{0}; return r; } -#line 3080 "reflect.h2" +#line 3123 "reflect.h2" [[nodiscard]] auto group_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '(') {return nullptr; } @@ -4891,7 +4965,7 @@ size_t i{0}; } } -#line 3217 "reflect.h2" +#line 3260 "reflect.h2" [[nodiscard]] auto group_token::gen_string(cpp2::impl::in name, cpp2::impl::in name_brackets, cpp2::impl::in has_modifier, cpp2::impl::in modifiers, cpp2::impl::in inner_) -> std::string { std::string start {"("}; @@ -4910,7 +4984,7 @@ size_t i{0}; return cpp2::move(start) + (*cpp2::impl::assert_not_null(inner_)).to_string() + ")"; } -#line 3235 "reflect.h2" +#line 3278 "reflect.h2" auto group_token::generate_code(generation_context& ctx) const -> void { if (-1 != number) { @@ -4931,7 +5005,7 @@ size_t i{0}; } } -#line 3255 "reflect.h2" +#line 3298 "reflect.h2" auto group_token::add_groups(std::set& groups) const -> void { (*cpp2::impl::assert_not_null(inner)).add_groups(groups); @@ -4942,7 +5016,7 @@ size_t i{0}; group_token::~group_token() noexcept{} -#line 3267 "reflect.h2" +#line 3310 "reflect.h2" [[nodiscard]] auto hexadecimal_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'x'))) {return nullptr; } @@ -4981,7 +5055,7 @@ size_t i{0}; return r; } -#line 3308 "reflect.h2" +#line 3351 "reflect.h2" [[nodiscard]] auto line_end_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() == '$' || (ctx.current() == '\\' && ctx.peek() == '$')) { @@ -4999,7 +5073,7 @@ size_t i{0}; }} } -#line 3328 "reflect.h2" +#line 3371 "reflect.h2" [[nodiscard]] auto line_start_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '^' && !((ctx.current() == '\\' && ctx.peek() == 'A'))) {return nullptr; } @@ -5013,29 +5087,29 @@ size_t i{0}; } } -#line 3353 "reflect.h2" +#line 3396 "reflect.h2" lookahead_token::lookahead_token(cpp2::impl::in positive_) : regex_token{ "" } , positive{ positive_ }{ -#line 3355 "reflect.h2" +#line 3398 "reflect.h2" } -#line 3357 "reflect.h2" +#line 3400 "reflect.h2" auto lookahead_token::generate_code(generation_context& ctx) const -> void{ auto inner_name {ctx.generate_func(inner)}; ctx.add_check("lookahead_token_matcher(" + cpp2::to_string(ctx.match_parameters()) + ", " + cpp2::to_string(cpp2::move(inner_name)) + ")"); } -#line 3363 "reflect.h2" +#line 3406 "reflect.h2" auto lookahead_token::add_groups(std::set& groups) const -> void{ (*cpp2::impl::assert_not_null(inner)).add_groups(groups); } lookahead_token::~lookahead_token() noexcept{} -#line 3371 "reflect.h2" +#line 3414 "reflect.h2" [[nodiscard]] auto named_class_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -5061,7 +5135,7 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, "\\" + cpp2::to_string(ctx.current()) + "", "" + cpp2::to_string(cpp2::move(name)) + "::match"); } -#line 3399 "reflect.h2" +#line 3442 "reflect.h2" [[nodiscard]] auto octal_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'o'))) {return nullptr; } @@ -5087,11 +5161,11 @@ size_t i{0}; return r; } -#line 3436 "reflect.h2" +#line 3479 "reflect.h2" range_token::range_token() : regex_token{ "" }{} -#line 3438 "reflect.h2" +#line 3481 "reflect.h2" [[nodiscard]] auto range_token::parse(parse_context& ctx) -> token_ptr { auto r {CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared)}; @@ -5165,7 +5239,7 @@ size_t i{0}; return nullptr; } -#line 3511 "reflect.h2" +#line 3554 "reflect.h2" auto range_token::parse_modifier(parse_context& ctx) & -> void { if (ctx.peek() == '?') { @@ -5178,7 +5252,7 @@ size_t i{0}; }} } -#line 3523 "reflect.h2" +#line 3566 "reflect.h2" [[nodiscard]] auto range_token::gen_mod_string() const& -> std::string { if (kind == range_flags::not_greedy) { @@ -5192,7 +5266,7 @@ size_t i{0}; }} } -#line 3536 "reflect.h2" +#line 3579 "reflect.h2" [[nodiscard]] auto range_token::gen_range_string() const& -> std::string { std::string r {""}; @@ -5212,7 +5286,7 @@ size_t i{0}; return r; } -#line 3555 "reflect.h2" +#line 3598 "reflect.h2" auto range_token::generate_code(generation_context& ctx) const -> void { auto inner_name {ctx.generate_func(inner_token)}; @@ -5224,14 +5298,14 @@ size_t i{0}; ctx.add_statefull(next_name, "cpp2::regex::range_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ", " + cpp2::to_string(cpp2::move(inner_name)) + ", " + cpp2::to_string(cpp2::move(reset_name)) + ", other, " + cpp2::to_string(next_name) + ")"); } -#line 3566 "reflect.h2" +#line 3609 "reflect.h2" auto range_token::add_groups(std::set& groups) const -> void{ (*cpp2::impl::assert_not_null(inner_token)).add_groups(groups); } range_token::~range_token() noexcept{} -#line 3579 "reflect.h2" +#line 3622 "reflect.h2" [[nodiscard]] auto special_range_token::parse(parse_context& ctx) -> token_ptr { auto r {CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared)}; @@ -5255,7 +5329,7 @@ size_t i{0}; if (!(ctx.has_token())) {return ctx.error("'" + cpp2::to_string(ctx.current()) + "' without previous element."); } -#line 3603 "reflect.h2" +#line 3646 "reflect.h2" (*cpp2::impl::assert_not_null(r)).parse_modifier(ctx); (*cpp2::impl::assert_not_null(r)).inner_token = ctx.pop_token(); @@ -5265,7 +5339,7 @@ size_t i{0}; special_range_token::~special_range_token() noexcept{} -#line 3616 "reflect.h2" +#line 3659 "reflect.h2" [[nodiscard]] auto word_boundary_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -5283,15 +5357,15 @@ size_t i{0}; }} } -#line 3652 "reflect.h2" +#line 3695 "reflect.h2" template regex_generator::regex_generator(cpp2::impl::in r, Error_out const& e) : regex{ r } , error_out{ e }{ -#line 3655 "reflect.h2" +#line 3698 "reflect.h2" } -#line 3657 "reflect.h2" +#line 3700 "reflect.h2" template [[nodiscard]] auto regex_generator::parse() & -> std::string { // Extract modifiers and adapt regex. @@ -5327,7 +5401,7 @@ size_t i{0}; return source; } -#line 3692 "reflect.h2" +#line 3735 "reflect.h2" template auto regex_generator::extract_modifiers() & -> void { if (regex.find_first_of("'/") == 0) { @@ -5343,7 +5417,7 @@ size_t i{0}; } } -#line 3708 "reflect.h2" +#line 3751 "reflect.h2" template [[nodiscard]] auto generate_regex(cpp2::impl::in regex, Err const& err) -> std::string { regex_generator parser {regex, err}; @@ -5352,7 +5426,7 @@ template [[nodiscard]] auto generate_regex(cpp2::impl::in void { auto has_default {false}; @@ -5396,7 +5470,7 @@ auto regex_gen(meta::type_declaration& t) -> void CPP2_UFCS(remove_marked_members)(t); for ( auto const& expr : cpp2::move(expressions) ) { - auto regular_expression {generate_regex(expr.second, [_0 = t](auto const& message) mutable -> void { CPP2_UFCS(error)(_0, message); })}; + auto regular_expression {generate_regex(expr.second, [_0 = (&t)](auto const& message) mutable -> void { CPP2_UFCS(error)((*cpp2::impl::assert_not_null(_0)), message); })}; if (!(regular_expression.empty())) { CPP2_UFCS(add_member)(t, "public " + cpp2::to_string(expr.first) + "_matcher: type = " + cpp2::to_string(cpp2::move(regular_expression)) + ""); @@ -5407,10 +5481,10 @@ auto regex_gen(meta::type_declaration& t) -> void CPP2_UFCS(add_runtime_support_include)(t, "cpp2regex.h"); } -#line 3777 "reflect.h2" +#line 3820 "reflect.h2" [[nodiscard]] auto apply_metafunctions( declaration_node& n, - type_declaration& rtype, + type_declaration_impl& rtypeimpl, auto const& error ) -> bool @@ -5419,7 +5493,7 @@ auto regex_gen(meta::type_declaration& t) -> void // Check for _names reserved for the metafunction implementation for ( - auto const& m : CPP2_UFCS(get_members)(rtype) ) + auto const& m : CPP2_UFCS(get_members)(rtypeimpl) ) { CPP2_UFCS(require)(m, !(CPP2_UFCS(starts_with)(CPP2_UFCS(name)(m), "_")) || CPP2_UFCS(ssize)(CPP2_UFCS(name)(m)) == 1, @@ -5434,7 +5508,7 @@ auto regex_gen(meta::type_declaration& t) -> void auto const& metafunc : n.metafunctions ) { // Convert the name and any template arguments to strings - // and record that in rtype + // and record that in rtypeimpl auto name {CPP2_UFCS(to_string)((*cpp2::impl::assert_not_null(metafunc)))}; name = CPP2_UFCS(substr)(name, 0, CPP2_UFCS(find)(name, '<')); @@ -5443,7 +5517,9 @@ auto regex_gen(meta::type_declaration& t) -> void auto const& arg : CPP2_UFCS(template_arguments)((*cpp2::impl::assert_not_null(metafunc))) ) CPP2_UFCS(push_back)(args, CPP2_UFCS(to_string)(arg)); - CPP2_UFCS(set_metafunction_name)(rtype, name, args); + CPP2_UFCS(set_metafunction_name)(rtypeimpl, name, cpp2::move(args)); + + auto rtype {make_type_declaration(rtypeimpl, &n)}; // Dispatch // @@ -5502,7 +5578,7 @@ auto regex_gen(meta::type_declaration& t) -> void foreign_interface_pseudovalue(rtype); } else { - error("unrecognized metafunction name: '" + name + "' for type declaration"); + error("unrecognized metafunction name: '" + cpp2::move(name) + "' for type declaration"); error( "(temporary alpha limitation) currently the supported names are: " "interface, polymorphic_base, ordered, weakly_ordered, partially_ordered, " @@ -5512,23 +5588,25 @@ auto regex_gen(meta::type_declaration& t) -> void return false; }}}}}}}}}}}}}}}}}} - if (( - !(CPP2_UFCS(empty)(args)) - && !(CPP2_UFCS(arguments_were_used)(rtype)))) + static_cast(cpp2::move(rtype)); - { - error(name + " did not use its template arguments - did you mean to write '" + name + " <" + CPP2_ASSERT_IN_BOUNDS_LITERAL(cpp2::move(args), 0) + "> type' (with the spaces)?"); - return false; - } + // if ( // TODO(DyXel) + // !args.empty() + // && !rtypeimpl.arguments_were_used() + // ) + // { + // error( name + " did not use its template arguments - did you mean to write '" + name + " <" + args[0] + "> type' (with the spaces)?"); + // return false; + // } } return true; } -#line 3899 "reflect.h2" +#line 3946 "reflect.h2" [[nodiscard]] auto apply_metafunctions( declaration_node& n, - function_declaration& rfunc, + function_declaration_impl& rfuncimpl, auto const& error ) -> bool @@ -5540,7 +5618,7 @@ auto regex_gen(meta::type_declaration& t) -> void auto const& metafunc : n.metafunctions ) { // Convert the name and any template arguments to strings - // and record that in rfunc + // and record that in rfuncimpl auto name {CPP2_UFCS(to_string)((*cpp2::impl::assert_not_null(metafunc)))}; name = CPP2_UFCS(substr)(name, 0, CPP2_UFCS(find)(name, '<')); @@ -5549,7 +5627,9 @@ auto regex_gen(meta::type_declaration& t) -> void auto const& arg : CPP2_UFCS(template_arguments)((*cpp2::impl::assert_not_null(metafunc))) ) CPP2_UFCS(push_back)(args, CPP2_UFCS(to_string)(arg)); - CPP2_UFCS(set_metafunction_name)(rfunc, name, args); + CPP2_UFCS(set_metafunction_name)(rfuncimpl, name, cpp2::move(args)); + + auto rfunc {make_function_declaration(rfuncimpl, &n)}; // Dispatch // @@ -5560,25 +5640,27 @@ auto regex_gen(meta::type_declaration& t) -> void print(rfunc); } else { - error("unrecognized metafunction name '" + name + "' for function declaration"); + error("unrecognized metafunction name '" + cpp2::move(name) + "' for function declaration"); error("(temporary alpha limitation) currently the supported names are: meta, print"); return false; }} - if (( - !(CPP2_UFCS(empty)(args)) - && !(CPP2_UFCS(arguments_were_used)(rfunc)))) + static_cast(cpp2::move(rfunc)); - { - error(name + " did not use its template arguments - did you mean to write '" + name + " <" + CPP2_ASSERT_IN_BOUNDS_LITERAL(cpp2::move(args), 0) + "> ()' (with the spaces)?"); - return false; - } + // if ( // TODO(DyXel) + // !args.empty() + // && !rfuncimpl.arguments_were_used() + // ) + // { + // error( name + " did not use its template arguments - did you mean to write '" + name + " <" + args[0] + "> ()' (with the spaces)?"); + // return false; + // } } return true; } -#line 3952 "reflect.h2" +#line 4003 "reflect.h2" } } diff --git a/source/reflect.h2 b/source/reflect.h2 index ee5a672f6..15a8f0876 100644 --- a/source/reflect.h2 +++ b/source/reflect.h2 @@ -16,6 +16,7 @@ //=========================================================================== #include "parse.h" +#include "cpp2reflect_api.h" #include "cpp2regex.h" using namespace cpp2::regex; @@ -31,19 +32,19 @@ meta: namespace = { //----------------------------------------------------------------------- // -compiler_services: @polymorphic_base @copyable type = +compiler_services_base: @polymorphic_base @copyable type = { // Common data members // - errors : *std::vector; - includes : *std::set; - errors_original_size : int; - generated_tokens : *stable_vector; - generated_declarations: *std::vector>; - parser : cpp2::parser; - metafunction_name : std::string = (); - metafunction_args : std::vector = (); - metafunctions_used : bool = false; + protected errors : *std::vector; + protected includes : *std::set; + protected errors_original_size : int; + protected generated_tokens : *stable_vector; + protected generated_declarations: *std::vector>; + protected parser : cpp2::parser; + protected metafunction_name : std::string = (); + protected metafunction_args : std::vector = (); + protected metafunctions_used : bool = false; // Constructor // @@ -63,8 +64,6 @@ compiler_services: @polymorphic_base @copyable type = parser = (errors*, includes*); } - // Common API - // set_metafunction_name: (inout this, name: std::string_view, args: std::vector) = { metafunction_name = name; metafunction_args = args; @@ -73,19 +72,6 @@ compiler_services: @polymorphic_base @copyable type = get_metafunction_name: (this) -> std::string_view = metafunction_name; - get_argument: (inout this, index: int) -> std::string = { - metafunctions_used = true; - if (0 <= index < metafunction_args.ssize()) { - return metafunction_args[index]; - } - return ""; - } - - get_arguments: (inout this) -> std::vector = { - metafunctions_used = true; - return metafunction_args; - } - arguments_were_used: (this) -> bool = metafunctions_used; private lex_multiline: ( @@ -149,8 +135,6 @@ compiler_services: @polymorphic_base @copyable type = } } - add_runtime_support_include: (inout this, s: std::string_view) = _=includes*.emplace( s ); - protected parse_and_add_declaration: ( inout this, copy source: std::string_view @@ -179,9 +163,6 @@ compiler_services: @polymorphic_base @copyable type = return (); } - // Error diagnosis and handling, integrated with compiler output - // Unlike a contract violation, .requires continues further processing - // require:( this, b : bool, @@ -202,25 +183,54 @@ compiler_services: @polymorphic_base @copyable type = _ = errors*.emplace_back( position(), message); } - // Enable custom contracts on this object, integrated with compiler output - // Unlike .requires, a contract violation stops further processing - // - report_violation: (this, msg) = { - error(msg); - throw( std::runtime_error( - " ==> programming bug found in metafunction @(metafunction_name)$ " - "- contract violation - see previous errors" - ) ); + is_active: (this) -> bool = true; +} + +compiler_services_impl: @polymorphic_base type = +{ + this: compiler_services_base; + + this: compiler_services::interface = (); + + operator=: (out this, csb: compiler_services_base) = { + compiler_services_base = csb; } - is_active:(this) true; + get_metafunction_name: (override this) -> std::string_view = metafunction_name; + + get_argument: (override inout this, index: int) -> std::string = { + metafunctions_used = true; + if (0 <= index < metafunction_args.ssize()) { + return metafunction_args[index]; + } + return ""; + } - append_declaration_to_translation_unit: (inout this, source: std::string_view) + get_arguments: (override inout this) -> std::vector = { + metafunctions_used = true; + return metafunction_args; + } + + add_runtime_support_include: (override inout this, s: std::string_view) = _=includes*.emplace( s ); + + append_declaration_to_translation_unit: (override inout this, source: std::string_view) = { if !parse_and_add_declaration(source) { error( "error attempting to add declaration:\n\t(source)$" ); } } + + require: (override this, b: bool, msg: std::string_view) = compiler_services_base::require(b, msg); + + error: (override this, msg: std::string_view) = compiler_services_base::error(msg); + + report_violation: (override this, msg: std::string_view) = { + error(msg); + throw( std::runtime_error( + " ==> programming bug found in metafunction @(metafunction_name)$ " + "- contract violation - see previous errors" + ) ); + } } @@ -270,190 +280,228 @@ type_id: @polymorphic_base @copyable type = // All declarations are wrappers around a pointer to node // -declaration_base: @polymorphic_base @copyable type = +declaration_base: @polymorphic_base type = { - this: compiler_services = (); + this: compiler_services_base; protected n: *declaration_node; protected operator=: ( out this, - n_: *declaration_node, - s : compiler_services + csb: compiler_services_base, + n_ : *declaration_node, ) = { - compiler_services = s; + compiler_services_base = csb; n = n_; assert( n, "a meta::declaration must point to a valid declaration_node, not null" ); } - position: (override this) -> source_position = n*.position(); - - print: (this) -> std::string = n*.pretty_print_visualize(0); + private position: (override this) -> source_position = n*.position(); } +//----------------------------------------------------------------------- +// Declaration factories +// +make_declaration: (csb: compiler_services_base, n: *declaration_node) -> _ = + : declaration = ( + new(csb, n), + new(csb), + ); + +make_function_declaration: (csb: compiler_services_base, n: *declaration_node) -> _ = + : function_declaration = ( + new(csb, n), + new(csb, n), + new(csb), + ); + +make_object_declaration: (csb: compiler_services_base, n: *declaration_node) -> _ = + : object_declaration = ( + new(csb, n), + new(csb, n), + new(csb), + ); + +make_type_declaration: (csb: compiler_services_base, n: *declaration_node) -> _ = + : type_declaration = ( + new(csb, n), + new(csb, n), + new(csb), + ); + +make_alias_declaration: (csb: compiler_services_base, n: *declaration_node) -> _ = + : alias_declaration = ( + new(csb, n), + new(csb, n), + new(csb), + ); //----------------------------------------------------------------------- // All declarations // -declaration: @polymorphic_base @copyable type = +declaration_impl: @polymorphic_base type = { - this: declaration_base = (); + this: declaration_base; + + this: declaration::interface = (); operator=: ( out this, + csb: compiler_services_base, n_: *declaration_node, - s : compiler_services ) = { - declaration_base = (n_, s); + declaration_base = (csb, n_); } - is_public : (this) -> bool = n*.is_public(); - is_protected : (this) -> bool = n*.is_protected(); - is_private : (this) -> bool = n*.is_private(); - is_default_access: (this) -> bool = n*.is_default_access(); + is_public : (override this) -> bool = n*.is_public(); + is_protected : (override this) -> bool = n*.is_protected(); + is_private : (override this) -> bool = n*.is_private(); + is_default_access: (override this) -> bool = n*.is_default_access(); - default_to_public : (inout this) = _ = n*.make_public(); - default_to_protected: (inout this) = _ = n*.make_protected(); - default_to_private : (inout this) = _ = n*.make_private(); + default_to_public : (override inout this) = _ = n*.make_public(); + default_to_protected: (override inout this) = _ = n*.make_protected(); + default_to_private : (override inout this) = _ = n*.make_private(); - make_public : (inout this) -> bool = n*.make_public(); - make_protected : (inout this) -> bool = n*.make_protected(); - make_private : (inout this) -> bool = n*.make_private(); + make_public : (override inout this) -> bool = n*.make_public(); + make_protected : (override inout this) -> bool = n*.make_protected(); + make_private : (override inout this) -> bool = n*.make_private(); - has_name : (this) -> bool = n*.has_name(); - has_name : (this, s: std::string_view) -> bool = n*.has_name(s); + has_name : (override this) -> bool = n*.has_name(); + has_name : (override this, s: std::string_view) -> bool = n*.has_name(s); - name: (this) -> std::string_view = { + name: (override this) -> std::string_view = { if has_name() { return n*.name()*.as_string_view(); } else { return ""; } } - fully_qualified_name: (this) -> std::string = n*.fully_qualified_name(); + fully_qualified_name: (override this) -> std::string = n*.fully_qualified_name(); - has_initializer: (this) -> bool = n*.has_initializer(); + has_initializer: (override this) -> bool = n*.has_initializer(); - is_global : (this) -> bool = n*.is_global(); - is_function : (this) -> bool = n*.is_function(); - is_object : (this) -> bool = n*.is_object(); - is_base_object : (this) -> bool = n*.is_base_object(); - is_member_object : (this) -> bool = n*.is_member_object(); - is_type : (this) -> bool = n*.is_type(); - is_namespace : (this) -> bool = n*.is_namespace(); - is_alias : (this) -> bool = n*.is_alias(); + is_global : (override this) -> bool = n*.is_global(); + is_function : (override this) -> bool = n*.is_function(); + is_object : (override this) -> bool = n*.is_object(); + is_base_object : (override this) -> bool = n*.is_base_object(); + is_member_object : (override this) -> bool = n*.is_member_object(); + is_type : (override this) -> bool = n*.is_type(); + is_namespace : (override this) -> bool = n*.is_namespace(); + is_alias : (override this) -> bool = n*.is_alias(); - is_type_alias : (this) -> bool = n*.is_type_alias(); - is_namespace_alias : (this) -> bool = n*.is_namespace_alias(); - is_object_alias : (this) -> bool = n*.is_object_alias(); + is_type_alias : (override this) -> bool = n*.is_type_alias(); + is_namespace_alias : (override this) -> bool = n*.is_namespace_alias(); + is_object_alias : (override this) -> bool = n*.is_object_alias(); - is_function_expression : (this) -> bool = n*.is_function_expression(); + is_function_expression : (override this) -> bool = n*.is_function_expression(); - as_function : (this) -> function_declaration = function_declaration(n, this); - as_object : (this) -> object_declaration = object_declaration(n, this); - as_type : (this) -> type_declaration = type_declaration(n, this); - as_alias : (this) -> alias_declaration = alias_declaration(n, this); + as_function: (override this) -> function_declaration = make_function_declaration(this, n); + as_object: (override this) -> object_declaration = make_object_declaration(this, n); + as_type: (override this) -> type_declaration = make_type_declaration(this, n); + as_alias: (override this) -> alias_declaration = make_alias_declaration(this, n); - get_parent : (this) -> declaration = declaration(n*.parent_declaration, this); + get_parent: (override this) -> declaration = make_declaration(this, n); - parent_is_function : (this) -> bool = n*.parent_is_function(); - parent_is_object : (this) -> bool = n*.parent_is_object(); - parent_is_type : (this) -> bool = n*.parent_is_type(); - parent_is_namespace : (this) -> bool = n*.parent_is_namespace(); - parent_is_alias : (this) -> bool = n*.parent_is_alias(); + parent_is_function : (override this) -> bool = n*.parent_is_function(); + parent_is_object : (override this) -> bool = n*.parent_is_object(); + parent_is_type : (override this) -> bool = n*.parent_is_type(); + parent_is_namespace : (override this) -> bool = n*.parent_is_namespace(); + parent_is_alias : (override this) -> bool = n*.parent_is_alias(); - parent_is_type_alias : (this) -> bool = n*.parent_is_type_alias(); - parent_is_namespace_alias : (this) -> bool = n*.parent_is_namespace_alias(); - parent_is_object_alias : (this) -> bool = n*.parent_is_object_alias(); + parent_is_type_alias : (override this) -> bool = n*.parent_is_type_alias(); + parent_is_namespace_alias : (override this) -> bool = n*.parent_is_namespace_alias(); + parent_is_object_alias : (override this) -> bool = n*.parent_is_object_alias(); - parent_is_polymorphic: (this) -> bool = n*.parent_is_polymorphic(); + parent_is_polymorphic: (override this) -> bool = n*.parent_is_polymorphic(); - mark_for_removal_from_enclosing_type: (inout this) + mark_for_removal_from_enclosing_type: (override inout this) pre( parent_is_type() ) // this precondition should be sufficient ... = { test := n*.type_member_mark_for_removal(); assert( test ); // ... to ensure this assert is true } + + print: (override this) -> std::string = n*.pretty_print_visualize(0); } //----------------------------------------------------------------------- // Function declarations // -function_declaration: @copyable type = +function_declaration_impl: @polymorphic_base type = { - this: declaration = (); + this: declaration_base; + + this: function_declaration::interface = (); operator=: ( out this, + csb: compiler_services_base, n_: *declaration_node, - s : compiler_services ) = { - declaration = (n_, s); + declaration_base = (csb, n_); assert( n*.is_function() ); } - index_of_parameter_named : (this, s: std::string_view) -> int = n*.index_of_parameter_named(s); - has_parameter_named : (this, s: std::string_view) -> bool = n*.has_parameter_named(s); - has_in_parameter_named : (this, s: std::string_view) -> bool = n*.has_in_parameter_named(s); - has_copy_parameter_named : (this, s: std::string_view) -> bool = n*.has_copy_parameter_named(s); - has_inout_parameter_named : (this, s: std::string_view) -> bool = n*.has_inout_parameter_named(s); - has_out_parameter_named : (this, s: std::string_view) -> bool = n*.has_out_parameter_named(s); - has_move_parameter_named : (this, s: std::string_view) -> bool = n*.has_move_parameter_named(s); - has_forward_parameter_named : (this, s: std::string_view) -> bool = n*.has_forward_parameter_named(s); - first_parameter_name : (this) -> std::string = n*.first_parameter_name(); - - has_parameter_with_name_and_pass: (this, s: std::string_view, pass: passing_style) -> bool - = n*.has_parameter_with_name_and_pass(s, pass); - is_function_with_this : (this) -> bool = n*.is_function_with_this(); - is_virtual : (this) -> bool = n*.is_virtual_function(); - is_defaultable : (this) -> bool = n*.is_defaultable_function(); - is_constructor : (this) -> bool = n*.is_constructor(); - is_default_constructor : (this) -> bool = n*.is_default_constructor(); - is_move : (this) -> bool = n*.is_move(); - is_swap : (this) -> bool = n*.is_swap(); - is_constructor_with_that : (this) -> bool = n*.is_constructor_with_that(); - is_constructor_with_in_that : (this) -> bool = n*.is_constructor_with_in_that(); - is_constructor_with_move_that: (this) -> bool = n*.is_constructor_with_move_that(); - is_assignment : (this) -> bool = n*.is_assignment(); - is_assignment_with_that : (this) -> bool = n*.is_assignment_with_that(); - is_assignment_with_in_that : (this) -> bool = n*.is_assignment_with_in_that(); - is_assignment_with_move_that : (this) -> bool = n*.is_assignment_with_move_that(); - is_destructor : (this) -> bool = n*.is_destructor(); - - is_copy_or_move : (this) -> bool = is_constructor_with_that() || is_assignment_with_that(); - - has_declared_return_type : (this) -> bool = n*.has_declared_return_type(); - has_deduced_return_type : (this) -> bool = n*.has_deduced_return_type(); - has_bool_return_type : (this) -> bool = n*.has_bool_return_type(); - has_non_void_return_type : (this) -> bool = n*.has_non_void_return_type(); - - unnamed_return_type : (this) -> std::string = n*.unnamed_return_type_to_string(); - - get_parameters: (this) + index_of_parameter_named : (override this, s: std::string_view) -> int = n*.index_of_parameter_named(s); + has_parameter_named : (override this, s: std::string_view) -> bool = n*.has_parameter_named(s); + has_in_parameter_named : (override this, s: std::string_view) -> bool = n*.has_in_parameter_named(s); + has_copy_parameter_named : (override this, s: std::string_view) -> bool = n*.has_copy_parameter_named(s); + has_inout_parameter_named : (override this, s: std::string_view) -> bool = n*.has_inout_parameter_named(s); + has_out_parameter_named : (override this, s: std::string_view) -> bool = n*.has_out_parameter_named(s); + has_move_parameter_named : (override this, s: std::string_view) -> bool = n*.has_move_parameter_named(s); + has_forward_parameter_named : (override this, s: std::string_view) -> bool = n*.has_forward_parameter_named(s); + first_parameter_name : (override this) -> std::string = n*.first_parameter_name(); + + // has_parameter_with_name_and_pass: (override this, s: std::string_view, pass: passing_style) -> bool // TODO(DyXel) + // = n*.has_parameter_with_name_and_pass(s, pass); + is_function_with_this : (override this) -> bool = n*.is_function_with_this(); + is_virtual : (override this) -> bool = n*.is_virtual_function(); + is_defaultable : (override this) -> bool = n*.is_defaultable_function(); + is_constructor : (override this) -> bool = n*.is_constructor(); + is_default_constructor : (override this) -> bool = n*.is_default_constructor(); + is_move : (override this) -> bool = n*.is_move(); + is_swap : (override this) -> bool = n*.is_swap(); + is_constructor_with_that : (override this) -> bool = n*.is_constructor_with_that(); + is_constructor_with_in_that : (override this) -> bool = n*.is_constructor_with_in_that(); + is_constructor_with_move_that: (override this) -> bool = n*.is_constructor_with_move_that(); + is_assignment : (override this) -> bool = n*.is_assignment(); + is_assignment_with_that : (override this) -> bool = n*.is_assignment_with_that(); + is_assignment_with_in_that : (override this) -> bool = n*.is_assignment_with_in_that(); + is_assignment_with_move_that : (override this) -> bool = n*.is_assignment_with_move_that(); + is_destructor : (override this) -> bool = n*.is_destructor(); + + is_copy_or_move : (override this) -> bool = is_constructor_with_that() || is_assignment_with_that(); + + has_declared_return_type : (override this) -> bool = n*.has_declared_return_type(); + has_deduced_return_type : (override this) -> bool = n*.has_deduced_return_type(); + has_bool_return_type : (override this) -> bool = n*.has_bool_return_type(); + has_non_void_return_type : (override this) -> bool = n*.has_non_void_return_type(); + + unnamed_return_type : (override this) -> std::string = n*.unnamed_return_type_to_string(); + + get_parameters: (override this) -> std::vector = { ret: std::vector = (); for n*.get_function_parameters() do (param) { - _ = ret.emplace_back( param*.declaration*&, this ); + _ = ret.emplace_back(make_object_declaration(this, param*.declaration*&)); } return ret; } - is_binary_comparison_function: (this) -> bool = n*.is_binary_comparison_function(); + is_binary_comparison_function: (override this) -> bool = n*.is_binary_comparison_function(); - default_to_virtual : (inout this) = _ = n*.make_function_virtual(); + default_to_virtual : (override inout this) = _ = n*.make_function_virtual(); - make_virtual : (inout this) -> bool = n*.make_function_virtual(); + make_virtual : (override inout this) -> bool = n*.make_function_virtual(); - add_initializer: (inout this, source: std::string_view) - pre (!has_initializer(), "cannot add an initializer to a function that already has one") - pre (parent_is_type(), "cannot add an initializer to a function that isn't in a type scope") + add_initializer: (override inout this, source: std::string_view) = { - //require( !has_initializer(), - // "cannot add an initializer to a function that already has one"); - //require( parent_is_type(), - // "cannot add an initializer to a function that isn't in a type scope"); + require( !n*.has_initializer(), + "cannot add an initializer to a function that already has one"); + require( n*.parent_is_type(), + "cannot add an initializer to a function that isn't in a type scope"); stmt := parse_statement(source); if !(stmt as bool) { @@ -469,31 +517,33 @@ function_declaration: @copyable type = //----------------------------------------------------------------------- // Object declarations // -object_declaration: @copyable type = +object_declaration_impl: @polymorphic_base type = { - this: declaration = (); + this: declaration_base; + + this: object_declaration::interface = (); operator=: ( out this, + csb: compiler_services_base, n_: *declaration_node, - s : compiler_services ) = { - declaration = (n_, s); + declaration_base = (csb, n_); assert( n*.is_object() ); } - is_const : (this) -> bool = n*.is_const(); - has_wildcard_type: (this) -> bool = n*.has_wildcard_type(); + is_const : (override this) -> bool = n*.is_const(); + has_wildcard_type: (override this) -> bool = n*.has_wildcard_type(); - type: (this) -> std::string = { + type: (override this) -> std::string = { ret := n*.object_type(); require( !contains(ret, "(*ERROR*)"), "cannot to_string this type: " + ret); return ret; } - initializer: (this) -> std::string = { + initializer: (override this) -> std::string = { ret := n*.object_initializer(); require( !contains(ret, "(*ERROR*)"), "cannot to_string this initializer: " + ret); @@ -505,50 +555,44 @@ object_declaration: @copyable type = //----------------------------------------------------------------------- // Type declarations // -type_declaration: @copyable type = +type_declaration_impl: @polymorphic_base type = { - this: declaration = (); + this: declaration_base; + + this: type_declaration::interface = (); operator=: ( out this, + csb: compiler_services_base, n_: *declaration_node, - s : compiler_services ) = { - declaration = (n_, s); + declaration_base = (csb, n_); assert( n*.is_type() ); } - reserve_names: (this, name: std::string_view, forward etc...) = - { // etc is not declared ':string_view' for compatibility with GCC 10.x - for get_members() - do (m) { - m.require( !m.has_name( name ), - "in a '(get_metafunction_name())$' type, the name '(name)$' " - "is reserved for use by the '(get_metafunction_name())$' implementation" - ); - } - if constexpr !CPP2_PACK_EMPTY(etc) { - reserve_names( etc... ); - } - } - - is_polymorphic: (this) -> bool = n*.is_polymorphic(); - is_final : (this) -> bool = n*.is_type_final(); - make_final : (inout this) -> bool = n*.make_type_final(); + is_polymorphic: (override this) -> bool = n*.is_polymorphic(); + is_final : (override this) -> bool = n*.is_type_final(); + make_final : (override inout this) -> bool = n*.make_type_final(); - get_member_functions: (this) + get_member_functions: (override this) -> std::vector = { ret: std::vector = (); for n*.get_type_scope_declarations(declaration_node::functions) do (d) { - _ = ret.emplace_back( d, this ); + _ = ret.emplace_back( + : function_declaration = ( + new(this, d), + new(this, d), + new(this), + ) + ); } return ret; } - get_member_functions_needing_initializer: (this) + get_member_functions_needing_initializer: (override this) -> std::vector = { ret: std::vector = (); @@ -558,67 +602,64 @@ type_declaration: @copyable type = && !d*.is_virtual_function() && !d*.is_defaultable_function() { - _ = ret.emplace_back( d, this ); + _ = ret.emplace_back(make_function_declaration(this, d)); } return ret; } - get_member_objects: (this) + get_member_objects: (override this) -> std::vector = { ret: std::vector = (); for n*.get_type_scope_declarations(declaration_node::objects) do (d) { - _ = ret.emplace_back( d, this ); + _ = ret.emplace_back(make_object_declaration(this, d)); } return ret; } - get_member_types: (this) + get_member_types: (override this) -> std::vector = { ret: std::vector = (); for n*.get_type_scope_declarations(declaration_node::types) do (d) { - _ = ret.emplace_back( d, this ); + _ = ret.emplace_back(make_type_declaration(this, d)); } return ret; } - get_member_aliases: (this) + get_member_aliases: (override this) -> std::vector = { ret: std::vector = (); for n*.get_type_scope_declarations(declaration_node::aliases) do (d) { - _ = ret.emplace_back( d, this ); + _ = ret.emplace_back(make_alias_declaration(this, d)); } return ret; } - get_members: (this) + get_members: (override this) -> std::vector = { ret: std::vector = (); for n*.get_type_scope_declarations(declaration_node::all) do (d) { - _ = ret.emplace_back( d, this ); + _ = ret.emplace_back(make_declaration(this, d)); } return ret; } - query_declared_value_set_functions: (this) - -> ( - out_this_in_that : bool, - out_this_move_that : bool, - inout_this_in_that : bool, - inout_this_move_that : bool - ) + query_declared_value_set_functions: (override this) + -> _query_declared_value_set_functions_ret = { + ret: _query_declared_value_set_functions_ret = (); declared := n*.find_declared_value_set_functions(); - out_this_in_that = declared.out_this_in_that != nullptr; - out_this_move_that = declared.out_this_move_that != nullptr; - inout_this_in_that = declared.inout_this_in_that != nullptr; - inout_this_move_that = declared.inout_this_move_that != nullptr; + ret.out_this_in_that = declared.out_this_in_that != nullptr; + ret.out_this_move_that = declared.out_this_move_that != nullptr; + ret.inout_this_in_that = declared.inout_this_in_that != nullptr; + ret.inout_this_move_that = declared.inout_this_move_that != nullptr; + return ret; } - add_member: (inout this, source: std::string_view) + add_member: (override inout this, source: std::string_view) = { decl := parse_statement(source); if !(decl as bool) { @@ -632,34 +673,36 @@ type_declaration: @copyable type = std::string("unexpected error while attempting to add member:\n") + source ); } - remove_marked_members: (inout this) = n*.type_remove_marked_members(); - remove_all_members : (inout this) = n*.type_remove_all_members(); + remove_marked_members: (override inout this) = n*.type_remove_marked_members(); + remove_all_members : (override inout this) = n*.type_remove_all_members(); - disable_member_function_generation: (inout this) = n*.type_disable_member_function_generation(); + disable_member_function_generation: (override inout this) = n*.type_disable_member_function_generation(); } //----------------------------------------------------------------------- // Alias declarations // -alias_declaration: @copyable type = +alias_declaration_impl: @polymorphic_base type = { - this: declaration = (); + this: declaration_base; + + this: alias_declaration::interface = (); operator=: ( out this, + csb: compiler_services_base, n_: *declaration_node, - s : compiler_services ) = { - declaration = (n_, s); + declaration_base = (csb, n_); assert( n*.is_alias() ); } } //----------------------------------------------------------------------- -// +// TODO(DyXel): Update this with something more apt? // Metafunctions - these are hardwired for now until we get to the // step of writing a Cpp2 interpreter to run inside the compiler // @@ -3758,7 +3801,7 @@ regex_gen: (inout t: meta::type_declaration) = t.remove_marked_members(); for expressions do (expr) { - regular_expression := generate_regex(expr.second, :(message) = t$.error(message);); + regular_expression := generate_regex(expr.second, :(message) = t&$*.error(message);); if !regular_expression..empty() { t.add_member("public (expr.first)$_matcher: type = (regular_expression)$"); @@ -3775,8 +3818,8 @@ regex_gen: (inout t: meta::type_declaration) = // apply_metafunctions - for types // apply_metafunctions: ( - inout n : declaration_node, - inout rtype : type_declaration, + inout n : declaration_node, + inout rtypeimpl : type_declaration_impl, error ) -> bool @@ -3784,7 +3827,7 @@ apply_metafunctions: ( assert( n.is_type() ); // Check for _names reserved for the metafunction implementation - for rtype.get_members() + for rtypeimpl.get_members() do (m) { m.require( @@ -3800,7 +3843,7 @@ apply_metafunctions: ( do (metafunc) { // Convert the name and any template arguments to strings - // and record that in rtype + // and record that in rtypeimpl name := metafunc*.to_string(); name = name.substr(0, name.find('<')); @@ -3809,7 +3852,9 @@ apply_metafunctions: ( do (arg) args.push_back( arg.to_string() ); - rtype.set_metafunction_name( name, args ); + rtypeimpl.set_metafunction_name( name, args ); + + rtype := make_type_declaration(rtypeimpl, n&); // Dispatch // @@ -3878,14 +3923,16 @@ apply_metafunctions: ( return false; } - if ( - !args.empty() - && !rtype.arguments_were_used() - ) - { - error( name + " did not use its template arguments - did you mean to write '" + name + " <" + args[0] + "> type' (with the spaces)?"); - return false; - } + _ = rtype; + + // if ( // TODO(DyXel) + // !args.empty() + // && !rtypeimpl.arguments_were_used() + // ) + // { + // error( name + " did not use its template arguments - did you mean to write '" + name + " <" + args[0] + "> type' (with the spaces)?"); + // return false; + // } } return true; @@ -3897,8 +3944,8 @@ apply_metafunctions: ( // apply_metafunctions - for functions // apply_metafunctions: ( - inout n : declaration_node, - inout rfunc : function_declaration, + inout n : declaration_node, + inout rfuncimpl : function_declaration_impl, error ) -> bool @@ -3910,7 +3957,7 @@ apply_metafunctions: ( do (metafunc) { // Convert the name and any template arguments to strings - // and record that in rfunc + // and record that in rfuncimpl name := metafunc*.to_string(); name = name.substr(0, name.find('<')); @@ -3919,7 +3966,9 @@ apply_metafunctions: ( do (arg) args.push_back( arg.to_string() ); - rfunc.set_metafunction_name( name, args ); + rfuncimpl.set_metafunction_name( name, args ); + + rfunc := make_function_declaration(rfuncimpl, n&); // Dispatch // @@ -3935,14 +3984,16 @@ apply_metafunctions: ( return false; } - if ( - !args.empty() - && !rfunc.arguments_were_used() - ) - { - error( name + " did not use its template arguments - did you mean to write '" + name + " <" + args[0] + "> ()' (with the spaces)?"); - return false; - } + _ = rfunc; + + // if ( // TODO(DyXel) + // !args.empty() + // && !rfuncimpl.arguments_were_used() + // ) + // { + // error( name + " did not use its template arguments - did you mean to write '" + name + " <" + args[0] + "> ()' (with the spaces)?"); + // return false; + // } } return true; diff --git a/source/sema.h b/source/sema.h index f8fd2e68d..08bb94b13 100644 --- a/source/sema.h +++ b/source/sema.h @@ -29,12 +29,12 @@ auto parser::apply_type_metafunctions( declaration_node& n ) assert(n.is_type()); // Get the reflection state ready to pass to the function - auto cs = meta::compiler_services{ &errors, &includes, generated_tokens, &generated_declarations }; - auto rtype = meta::type_declaration{ &n, cs }; + auto csb = meta::compiler_services_base{ &errors, &includes, generated_tokens, &generated_declarations }; + auto rtypeimpl = meta::type_declaration_impl{ csb, &n }; return apply_metafunctions( n, - rtype, + rtypeimpl, [&](std::string const& msg) { error( msg, false ); } ); } @@ -45,12 +45,12 @@ auto parser::apply_function_metafunctions( declaration_node& n ) assert(n.is_function()); // Get the reflection state ready to pass to the function - auto cs = meta::compiler_services{ &errors, &includes, generated_tokens, &generated_declarations }; - auto rfunc = meta::function_declaration{ &n, cs }; + auto csb = meta::compiler_services_base{ &errors, &includes, generated_tokens, &generated_declarations }; + auto rfuncimpl = meta::function_declaration_impl{ csb, &n }; return apply_metafunctions( n, - rfunc, + rfuncimpl, [&](std::string const& msg) { error( msg, false ); } ); } From 2c5f2bbf01e68568fe9e2dcaa5fad1e8f6ad3a21 Mon Sep 17 00:00:00 2001 From: Dylam De La Torre Date: Sat, 24 Aug 2024 23:12:43 +0200 Subject: [PATCH 8/9] Add standalone DLL library `get_alias` unused, but left for completeness in case its useful later. Co-authored-by: Edoardo Lolletti --- source/dll.h | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 source/dll.h diff --git a/source/dll.h b/source/dll.h new file mode 100644 index 000000000..fc6cd21ad --- /dev/null +++ b/source/dll.h @@ -0,0 +1,124 @@ + +// Copyright (c) Herb Sutter +// SPDX-License-Identifier: CC-BY-NC-ND-4.0 + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +//=========================================================================== +// Dynamic Library Loading +//=========================================================================== + +#ifndef CPP2_DLL_H +#define CPP2_DLL_H + +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX +#include +#else +#include +#endif // _WIN32 + +namespace cpp2 { + +class dll +{ + void* handle = {}; +public: + dll(std::string const& path) + { +#ifdef _WIN32 + handle = static_cast(LoadLibraryA(path.c_str())); +#else + handle = static_cast(dlopen(path.c_str(), RTLD_NOW|RTLD_LOCAL)); +#endif // _WIN32 + } + + ~dll() noexcept + { + if(handle != nullptr) + { +#ifdef _WIN32 + FreeLibrary(static_cast(handle)); +#else + dlclose(handle); +#endif // _WIN32 + } + } + + // Uncopyable + dll(dll&) = delete; + dll(dll const&) = delete; + auto operator=(dll const&) -> dll& = delete; + // Movable + dll(dll&& from) noexcept + { + handle = from.handle; + from.handle = nullptr; + } + auto operator=(dll&& from) noexcept -> dll& + { + handle = from.handle; + from.handle = nullptr; + return *this; + } + + auto is_open() noexcept -> bool { return handle != nullptr; } + + static auto get_last_error() noexcept -> std::string { +#ifdef _WIN32 + DWORD error_msg_id = GetLastError(); + if(error_msg_id == 0) + return {}; // No error message has been recorded + LPSTR msg_buffer = nullptr; + auto size = FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, + nullptr, + error_msg_id, + MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), + &msg_buffer, + 0, + nullptr + ); + std::string message(msg_buffer, static_cast(size)); + LocalFree(msg_buffer); + return message; +#else + return std::string{dlerror()}; +#endif // _WIN32 + } + + template + auto get_alias(std::string const& name) noexcept -> T* + { +#ifdef _WIN32 + auto symbol = GetProcAddress(static_cast(handle), name.c_str()); +#else + auto symbol = dlsym(handle, name.c_str()); + if(symbol == nullptr) + { + // Some platforms export with additional underscore, so try that. + auto const us_name = "_" + name; + symbol = dlsym(handle, us_name.c_str()); + } +#endif // _WIN32 + return function_cast_(symbol); + } +private: + + template + static auto function_cast_(auto ptr) noexcept -> T { + using generic_function_ptr = void (*)(void); + return reinterpret_cast(reinterpret_cast(ptr)); + } +}; + +} + +#endif // CPP2_DLL_H From d4beefff098808bc630814e53a8f990f9080c0a5 Mon Sep 17 00:00:00 2001 From: Dylam De La Torre Date: Sat, 24 Aug 2024 23:22:47 +0200 Subject: [PATCH 9/9] Add reflection libraries loading and basic look-up mechanism --- source/parse.h | 11 +- source/reflect.h | 1292 +++++++++++++++++++++++---------------------- source/reflect.h2 | 11 +- source/sema.h | 116 +++- source/to_cpp1.h | 31 +- 5 files changed, 805 insertions(+), 656 deletions(-) diff --git a/source/parse.h b/source/parse.h index 225028883..3aaf8523a 100644 --- a/source/parse.h +++ b/source/parse.h @@ -5574,6 +5574,7 @@ auto pretty_print_visualize(translation_unit_node const& n) return ret; } +class reflect_libraries; //----------------------------------------------------------------------- // @@ -5583,6 +5584,7 @@ auto pretty_print_visualize(translation_unit_node const& n) // class parser { + reflect_libraries& libraries; std::vector& errors; std::set& includes; @@ -5714,17 +5716,20 @@ class parser // // errors error list // - parser( + parser( + reflect_libraries& libraries_, std::vector& errors_, std::set& includes_ ) - : errors{ errors_ } + : libraries{ libraries_ } + , errors{ errors_ } , includes{ includes_ } , parse_tree{std::make_unique()} { } parser( parser const& that ) - : errors{ that.errors } + : libraries{ that.libraries } + , errors{ that.errors } , includes{ that.includes } , parse_tree{std::make_unique()} { } diff --git a/source/reflect.h b/source/reflect.h index 8388cdcad..b4f78fa43 100644 --- a/source/reflect.h +++ b/source/reflect.h @@ -18,98 +18,98 @@ namespace meta { #line 35 "reflect.h2" class compiler_services_base; -#line 189 "reflect.h2" +#line 190 "reflect.h2" class compiler_services_impl; -#line 283 "reflect.h2" +#line 284 "reflect.h2" class declaration_base; -#line 343 "reflect.h2" +#line 344 "reflect.h2" class declaration_impl; -#line 430 "reflect.h2" +#line 431 "reflect.h2" class function_declaration_impl; -#line 520 "reflect.h2" +#line 521 "reflect.h2" class object_declaration_impl; -#line 558 "reflect.h2" +#line 559 "reflect.h2" class type_declaration_impl; -#line 686 "reflect.h2" +#line 687 "reflect.h2" class alias_declaration_impl; -#line 1172 "reflect.h2" +#line 1173 "reflect.h2" class value_member_info; -#line 1715 "reflect.h2" +#line 1716 "reflect.h2" class expression_flags; -#line 1731 "reflect.h2" +#line 1732 "reflect.h2" class regex_token; -#line 1757 "reflect.h2" +#line 1758 "reflect.h2" class regex_token_check; -#line 1776 "reflect.h2" +#line 1777 "reflect.h2" class regex_token_code; -#line 1795 "reflect.h2" +#line 1796 "reflect.h2" class regex_token_empty; -#line 1811 "reflect.h2" +#line 1812 "reflect.h2" class regex_token_list; -#line 1850 "reflect.h2" +#line 1851 "reflect.h2" class parse_context_group_state; -#line 1911 "reflect.h2" +#line 1912 "reflect.h2" class parse_context_branch_reset_state; -#line 1954 "reflect.h2" +#line 1955 "reflect.h2" class parse_context; -#line 2352 "reflect.h2" +#line 2353 "reflect.h2" class generation_function_context; -#line 2370 "reflect.h2" +#line 2371 "reflect.h2" class generation_context; -#line 2568 "reflect.h2" +#line 2569 "reflect.h2" class alternative_token; -#line 2583 "reflect.h2" +#line 2584 "reflect.h2" class alternative_token_gen; -#line 2635 "reflect.h2" +#line 2636 "reflect.h2" class any_token; -#line 2653 "reflect.h2" +#line 2654 "reflect.h2" class char_token; -#line 2756 "reflect.h2" +#line 2757 "reflect.h2" class class_token; -#line 2971 "reflect.h2" +#line 2972 "reflect.h2" class group_ref_token; -#line 3102 "reflect.h2" +#line 3103 "reflect.h2" class group_token; -#line 3389 "reflect.h2" +#line 3390 "reflect.h2" class lookahead_token; -#line 3470 "reflect.h2" +#line 3471 "reflect.h2" class range_token; -#line 3618 "reflect.h2" +#line 3619 "reflect.h2" class special_range_token; -#line 3685 "reflect.h2" +#line 3686 "reflect.h2" template class regex_generator; -#line 4003 "reflect.h2" +#line 4008 "reflect.h2" } } @@ -163,16 +163,17 @@ class compiler_services_base #line 51 "reflect.h2" public: explicit compiler_services_base( + reflect_libraries* libraries, std::vector* errors_, std::set* includes_, stable_vector* generated_tokens_, std::vector>* generated_declarations_ ); -#line 67 "reflect.h2" +#line 68 "reflect.h2" public: auto set_metafunction_name(cpp2::impl::in name, cpp2::impl::in> args) & -> void; -#line 73 "reflect.h2" +#line 74 "reflect.h2" public: [[nodiscard]] auto get_metafunction_name() const& -> std::string_view; public: [[nodiscard]] auto arguments_were_used() const& -> bool; @@ -184,59 +185,59 @@ class compiler_services_base using parse_statement_ret = std::unique_ptr; -#line 118 "reflect.h2" +#line 119 "reflect.h2" protected: [[nodiscard]] auto parse_statement( std::string_view source ) & -> parse_statement_ret; -#line 138 "reflect.h2" +#line 139 "reflect.h2" protected: [[nodiscard]] auto parse_and_add_declaration( std::string_view source ) & -> bool; -#line 160 "reflect.h2" +#line 161 "reflect.h2" public: [[nodiscard]] virtual auto position() const -> source_position; -#line 166 "reflect.h2" +#line 167 "reflect.h2" public: auto require( cpp2::impl::in b, cpp2::impl::in msg ) const& -> void; -#line 177 "reflect.h2" +#line 178 "reflect.h2" public: auto error(cpp2::impl::in msg) const& -> void; -#line 186 "reflect.h2" +#line 187 "reflect.h2" public: [[nodiscard]] auto is_active() const& -> bool; public: virtual ~compiler_services_base() noexcept; public: compiler_services_base(compiler_services_base const& that); -#line 187 "reflect.h2" +#line 188 "reflect.h2" }; class compiler_services_impl : public compiler_services_base, public compiler_services::interface { -#line 195 "reflect.h2" +#line 196 "reflect.h2" public: explicit compiler_services_impl(cpp2::impl::in csb); -#line 199 "reflect.h2" +#line 200 "reflect.h2" public: [[nodiscard]] auto get_metafunction_name() const -> std::string_view override; public: [[nodiscard]] auto get_argument(cpp2::impl::in index) -> std::string override; -#line 209 "reflect.h2" +#line 210 "reflect.h2" public: [[nodiscard]] auto get_arguments() -> std::vector override; -#line 214 "reflect.h2" +#line 215 "reflect.h2" public: auto add_runtime_support_include(cpp2::impl::in s) -> void override; public: auto append_declaration_to_translation_unit(cpp2::impl::in source) -> void override; -#line 223 "reflect.h2" +#line 224 "reflect.h2" public: auto require(cpp2::impl::in b, cpp2::impl::in msg) const -> void override; public: auto error(cpp2::impl::in msg) const -> void override; @@ -248,14 +249,14 @@ class compiler_services_impl public: auto operator=(compiler_services_impl const&) -> void = delete; -#line 234 "reflect.h2" +#line 235 "reflect.h2" }; -#line 283 "reflect.h2" +#line 284 "reflect.h2" class declaration_base : public compiler_services_base { -#line 287 "reflect.h2" +#line 288 "reflect.h2" protected: declaration_node* n; protected: explicit declaration_base( @@ -264,43 +265,43 @@ class declaration_base declaration_node* n_ ); -#line 300 "reflect.h2" +#line 301 "reflect.h2" private: [[nodiscard]] auto position() const -> source_position override; public: virtual ~declaration_base() noexcept; public: declaration_base(declaration_base const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(declaration_base const&) -> void = delete; -#line 301 "reflect.h2" +#line 302 "reflect.h2" }; -#line 306 "reflect.h2" +#line 307 "reflect.h2" [[nodiscard]] auto make_declaration(cpp2::impl::in csb, declaration_node* n) -> auto; -#line 312 "reflect.h2" +#line 313 "reflect.h2" [[nodiscard]] auto make_function_declaration(cpp2::impl::in csb, declaration_node* n) -> auto; -#line 319 "reflect.h2" +#line 320 "reflect.h2" [[nodiscard]] auto make_object_declaration(cpp2::impl::in csb, declaration_node* n) -> auto; -#line 326 "reflect.h2" +#line 327 "reflect.h2" [[nodiscard]] auto make_type_declaration(cpp2::impl::in csb, declaration_node* n) -> auto; -#line 333 "reflect.h2" +#line 334 "reflect.h2" [[nodiscard]] auto make_alias_declaration(cpp2::impl::in csb, declaration_node* n) -> auto; -#line 343 "reflect.h2" +#line 344 "reflect.h2" class declaration_impl : public declaration_base, public declaration::interface { -#line 349 "reflect.h2" +#line 350 "reflect.h2" public: explicit declaration_impl( cpp2::impl::in csb, declaration_node* n_ ); -#line 358 "reflect.h2" +#line 359 "reflect.h2" public: [[nodiscard]] auto is_public() const -> bool override; public: [[nodiscard]] auto is_protected() const -> bool override; public: [[nodiscard]] auto is_private() const -> bool override; @@ -319,7 +320,7 @@ class declaration_impl public: [[nodiscard]] auto name() const -> std::string_view override; -#line 378 "reflect.h2" +#line 379 "reflect.h2" public: [[nodiscard]] auto fully_qualified_name() const -> std::string override; public: [[nodiscard]] auto has_initializer() const -> bool override; @@ -360,28 +361,28 @@ class declaration_impl public: auto mark_for_removal_from_enclosing_type() -> void override; -#line 423 "reflect.h2" +#line 424 "reflect.h2" public: [[nodiscard]] auto print() const -> std::string override; public: virtual ~declaration_impl() noexcept; public: declaration_impl(declaration_impl const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(declaration_impl const&) -> void = delete; -#line 424 "reflect.h2" +#line 425 "reflect.h2" }; -#line 430 "reflect.h2" +#line 431 "reflect.h2" class function_declaration_impl : public declaration_base, public function_declaration::interface { -#line 436 "reflect.h2" +#line 437 "reflect.h2" public: explicit function_declaration_impl( cpp2::impl::in csb, declaration_node* n_ ); -#line 446 "reflect.h2" +#line 447 "reflect.h2" public: [[nodiscard]] auto index_of_parameter_named(cpp2::impl::in s) const -> int override; public: [[nodiscard]] auto has_parameter_named(cpp2::impl::in s) const -> bool override; public: [[nodiscard]] auto has_in_parameter_named(cpp2::impl::in s) const -> bool override; @@ -392,7 +393,7 @@ class function_declaration_impl public: [[nodiscard]] auto has_forward_parameter_named(cpp2::impl::in s) const -> bool override; public: [[nodiscard]] auto first_parameter_name() const -> std::string override; -#line 458 "reflect.h2" +#line 459 "reflect.h2" public: [[nodiscard]] auto is_function_with_this() const -> bool override; public: [[nodiscard]] auto is_virtual() const -> bool override; public: [[nodiscard]] auto is_defaultable() const -> bool override; @@ -420,7 +421,7 @@ class function_declaration_impl public: [[nodiscard]] auto get_parameters() const -> std::vector override; -#line 493 "reflect.h2" +#line 494 "reflect.h2" public: [[nodiscard]] auto is_binary_comparison_function() const -> bool override; public: auto default_to_virtual() -> void override; @@ -434,27 +435,27 @@ class function_declaration_impl public: auto operator=(function_declaration_impl const&) -> void = delete; -#line 514 "reflect.h2" +#line 515 "reflect.h2" }; -#line 520 "reflect.h2" +#line 521 "reflect.h2" class object_declaration_impl : public declaration_base, public object_declaration::interface { -#line 526 "reflect.h2" +#line 527 "reflect.h2" public: explicit object_declaration_impl( cpp2::impl::in csb, declaration_node* n_ ); -#line 536 "reflect.h2" +#line 537 "reflect.h2" public: [[nodiscard]] auto is_const() const -> bool override; public: [[nodiscard]] auto has_wildcard_type() const -> bool override; public: [[nodiscard]] auto type() const -> std::string override; -#line 546 "reflect.h2" +#line 547 "reflect.h2" public: [[nodiscard]] auto initializer() const -> std::string override; public: virtual ~object_declaration_impl() noexcept; @@ -462,49 +463,49 @@ class object_declaration_impl public: auto operator=(object_declaration_impl const&) -> void = delete; -#line 552 "reflect.h2" +#line 553 "reflect.h2" }; -#line 558 "reflect.h2" +#line 559 "reflect.h2" class type_declaration_impl : public declaration_base, public type_declaration::interface { -#line 564 "reflect.h2" +#line 565 "reflect.h2" public: explicit type_declaration_impl( cpp2::impl::in csb, declaration_node* n_ ); -#line 574 "reflect.h2" +#line 575 "reflect.h2" public: [[nodiscard]] auto is_polymorphic() const -> bool override; public: [[nodiscard]] auto is_final() const -> bool override; public: [[nodiscard]] auto make_final() -> bool override; public: [[nodiscard]] auto get_member_functions() const -> std::vector override; -#line 595 "reflect.h2" +#line 596 "reflect.h2" public: [[nodiscard]] auto get_member_functions_needing_initializer() const -> std::vector override; -#line 610 "reflect.h2" +#line 611 "reflect.h2" public: [[nodiscard]] auto get_member_objects() const -> std::vector override; -#line 620 "reflect.h2" +#line 621 "reflect.h2" public: [[nodiscard]] auto get_member_types() const -> std::vector override; -#line 630 "reflect.h2" +#line 631 "reflect.h2" public: [[nodiscard]] auto get_member_aliases() const -> std::vector override; -#line 640 "reflect.h2" +#line 641 "reflect.h2" public: [[nodiscard]] auto get_members() const -> std::vector override; -#line 650 "reflect.h2" +#line 651 "reflect.h2" public: [[nodiscard]] auto query_declared_value_set_functions() const -> _query_declared_value_set_functions_ret override; -#line 662 "reflect.h2" +#line 663 "reflect.h2" public: auto add_member(cpp2::impl::in source) -> void override; -#line 676 "reflect.h2" +#line 677 "reflect.h2" public: auto remove_marked_members() -> void override; public: auto remove_all_members() -> void override; @@ -514,14 +515,14 @@ class type_declaration_impl public: type_declaration_impl(type_declaration_impl const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(type_declaration_impl const&) -> void = delete; -#line 680 "reflect.h2" +#line 681 "reflect.h2" }; -#line 686 "reflect.h2" +#line 687 "reflect.h2" class alias_declaration_impl : public declaration_base, public alias_declaration::interface { -#line 692 "reflect.h2" +#line 693 "reflect.h2" public: explicit alias_declaration_impl( cpp2::impl::in csb, @@ -533,65 +534,65 @@ class alias_declaration_impl public: auto operator=(alias_declaration_impl const&) -> void = delete; -#line 701 "reflect.h2" +#line 702 "reflect.h2" }; -#line 716 "reflect.h2" +#line 717 "reflect.h2" auto add_virtual_destructor(meta::type_declaration& t) -> void; -#line 736 "reflect.h2" +#line 737 "reflect.h2" auto foreign_interface_pseudovalue(meta::type_declaration& t) -> void; -#line 810 "reflect.h2" +#line 811 "reflect.h2" auto interface(meta::type_declaration& t) -> void; -#line 856 "reflect.h2" +#line 857 "reflect.h2" auto polymorphic_base(meta::type_declaration& t) -> void; -#line 901 "reflect.h2" +#line 902 "reflect.h2" auto ordered_impl( meta::type_declaration& t, cpp2::impl::in ordering ) -> void; -#line 930 "reflect.h2" +#line 931 "reflect.h2" auto ordered(meta::type_declaration& t) -> void; -#line 938 "reflect.h2" +#line 939 "reflect.h2" auto weakly_ordered(meta::type_declaration& t) -> void; -#line 946 "reflect.h2" +#line 947 "reflect.h2" auto partially_ordered(meta::type_declaration& t) -> void; -#line 968 "reflect.h2" +#line 969 "reflect.h2" auto copyable(meta::type_declaration& t) -> void; -#line 1002 "reflect.h2" +#line 1003 "reflect.h2" auto basic_value(meta::type_declaration& t) -> void; -#line 1030 "reflect.h2" +#line 1031 "reflect.h2" auto value(meta::type_declaration& t) -> void; -#line 1036 "reflect.h2" +#line 1037 "reflect.h2" auto weakly_ordered_value(meta::type_declaration& t) -> void; -#line 1042 "reflect.h2" +#line 1043 "reflect.h2" auto partially_ordered_value(meta::type_declaration& t) -> void; -#line 1071 "reflect.h2" +#line 1072 "reflect.h2" auto cpp1_rule_of_zero(meta::type_declaration& t) -> void; -#line 1108 "reflect.h2" +#line 1109 "reflect.h2" auto cpp2_struct(meta::type_declaration& t) -> void; -#line 1172 "reflect.h2" +#line 1173 "reflect.h2" class value_member_info { public: std::string name; public: std::string type; public: std::string value; public: value_member_info(auto const& name_, auto const& type_, auto const& value_); -#line 1176 "reflect.h2" +#line 1177 "reflect.h2" }; auto basic_enum( @@ -600,28 +601,28 @@ auto basic_enum( cpp2::impl::in bitwise ) -> void; -#line 1442 "reflect.h2" +#line 1443 "reflect.h2" auto cpp2_enum(meta::type_declaration& t) -> void; -#line 1469 "reflect.h2" +#line 1470 "reflect.h2" auto flag_enum(meta::type_declaration& t) -> void; -#line 1515 "reflect.h2" +#line 1516 "reflect.h2" auto cpp2_union(meta::type_declaration& t) -> void; -#line 1666 "reflect.h2" +#line 1667 "reflect.h2" auto print(cpp2::impl::in t) -> void; -#line 1671 "reflect.h2" +#line 1672 "reflect.h2" auto print(cpp2::impl::in f) -> void; -#line 1681 "reflect.h2" +#line 1682 "reflect.h2" auto meta(meta::function_declaration& f) -> void; -#line 1711 "reflect.h2" +#line 1712 "reflect.h2" using error_func = std::function x)>; -#line 1715 "reflect.h2" +#line 1716 "reflect.h2" class expression_flags { private: cpp2::u8 _value; private: constexpr expression_flags(cpp2::impl::in _val); @@ -656,20 +657,20 @@ public: [[nodiscard]] auto to_code() const& -> std::string; public: [[nodiscard]] static auto from_string(cpp2::impl::in s) -> expression_flags; public: [[nodiscard]] static auto from_code(cpp2::impl::in s) -> expression_flags; -#line 1723 "reflect.h2" +#line 1724 "reflect.h2" }; -#line 1731 "reflect.h2" +#line 1732 "reflect.h2" class regex_token { public: std::string string_rep; public: explicit regex_token(cpp2::impl::in str); -#line 1739 "reflect.h2" +#line 1740 "reflect.h2" public: explicit regex_token(); -#line 1744 "reflect.h2" +#line 1745 "reflect.h2" public: virtual auto generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void = 0; public: virtual auto add_groups([[maybe_unused]] std::set& unnamed_param_2) const -> void; @@ -680,24 +681,24 @@ class regex_token public: regex_token(regex_token const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(regex_token const&) -> void = delete; -#line 1749 "reflect.h2" +#line 1750 "reflect.h2" }; using token_ptr = std::shared_ptr; using token_vec = std::vector; -#line 1755 "reflect.h2" +#line 1756 "reflect.h2" // Adds a check in code generation. // class regex_token_check : public regex_token { -#line 1761 "reflect.h2" +#line 1762 "reflect.h2" private: std::string check; public: explicit regex_token_check(cpp2::impl::in str, cpp2::impl::in check_); -#line 1768 "reflect.h2" +#line 1769 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~regex_token_check() noexcept; @@ -705,21 +706,21 @@ class regex_token_check public: auto operator=(regex_token_check const&) -> void = delete; -#line 1771 "reflect.h2" +#line 1772 "reflect.h2" }; -#line 1774 "reflect.h2" +#line 1775 "reflect.h2" // Adds code in code generation. // class regex_token_code : public regex_token { -#line 1780 "reflect.h2" +#line 1781 "reflect.h2" private: std::string code; public: explicit regex_token_code(cpp2::impl::in str, cpp2::impl::in code_); -#line 1787 "reflect.h2" +#line 1788 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~regex_token_code() noexcept; @@ -727,19 +728,19 @@ class regex_token_code public: auto operator=(regex_token_code const&) -> void = delete; -#line 1790 "reflect.h2" +#line 1791 "reflect.h2" }; -#line 1793 "reflect.h2" +#line 1794 "reflect.h2" // Token that does not influence the matching. E.g. comment. // class regex_token_empty : public regex_token { -#line 1799 "reflect.h2" +#line 1800 "reflect.h2" public: explicit regex_token_empty(cpp2::impl::in str); -#line 1803 "reflect.h2" +#line 1804 "reflect.h2" public: auto generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void override; public: virtual ~regex_token_empty() noexcept; @@ -747,27 +748,27 @@ class regex_token_empty public: auto operator=(regex_token_empty const&) -> void = delete; -#line 1806 "reflect.h2" +#line 1807 "reflect.h2" }; -#line 1809 "reflect.h2" +#line 1810 "reflect.h2" // Represents a list of regex tokens as one token. // class regex_token_list : public regex_token { -#line 1815 "reflect.h2" +#line 1816 "reflect.h2" public: token_vec tokens; public: explicit regex_token_list(cpp2::impl::in t); -#line 1822 "reflect.h2" +#line 1823 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 1828 "reflect.h2" +#line 1829 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; -#line 1834 "reflect.h2" +#line 1835 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in vec) -> std::string; public: virtual ~regex_token_list() noexcept; @@ -775,10 +776,10 @@ class regex_token_list public: auto operator=(regex_token_list const&) -> void = delete; -#line 1841 "reflect.h2" +#line 1842 "reflect.h2" }; -#line 1844 "reflect.h2" +#line 1845 "reflect.h2" // // Parse and generation context. // @@ -794,33 +795,33 @@ class parse_context_group_state // Start a new alternative. public: auto next_alternative() & -> void; -#line 1864 "reflect.h2" +#line 1865 "reflect.h2" // Swap this state with the other one. public: auto swap(parse_context_group_state& t) & -> void; -#line 1871 "reflect.h2" +#line 1872 "reflect.h2" // Convert this state into a regex token. public: [[nodiscard]] auto get_as_token() & -> token_ptr; -#line 1883 "reflect.h2" +#line 1884 "reflect.h2" // Add a token to the current matcher list. public: auto add(cpp2::impl::in token) & -> void; -#line 1888 "reflect.h2" +#line 1889 "reflect.h2" // True if current matcher list is empty. public: [[nodiscard]] auto empty() const& -> bool; -#line 1892 "reflect.h2" +#line 1893 "reflect.h2" // Apply optimizations to the matcher list. public: static auto post_process_list(token_vec& list) -> void; public: parse_context_group_state(auto const& cur_match_list_, auto const& alternate_match_lists_, auto const& modifiers_); public: parse_context_group_state(); -#line 1906 "reflect.h2" +#line 1907 "reflect.h2" }; -#line 1909 "reflect.h2" +#line 1910 "reflect.h2" // State for the branch reset. Takes care of the group numbering. See '(|)'. // class parse_context_branch_reset_state @@ -833,25 +834,25 @@ class parse_context_branch_reset_state // Next group identifier. public: [[nodiscard]] auto next() & -> int; -#line 1927 "reflect.h2" +#line 1928 "reflect.h2" // Set next group identifier. public: auto set_next(cpp2::impl::in g) & -> void; -#line 1933 "reflect.h2" +#line 1934 "reflect.h2" // Start a new alternative branch. public: auto next_alternative() & -> void; -#line 1940 "reflect.h2" +#line 1941 "reflect.h2" // Initialize for a branch reset group. public: auto set_active_reset(cpp2::impl::in restart) & -> void; public: parse_context_branch_reset_state(auto const& is_active_, auto const& cur_group_, auto const& max_group_, auto const& from_); public: parse_context_branch_reset_state(); -#line 1947 "reflect.h2" +#line 1948 "reflect.h2" }; -#line 1950 "reflect.h2" +#line 1951 "reflect.h2" // Context during parsing of the regular expressions. // // Keeps track of the distributed group identifiers, current parsed group and branch resets. @@ -865,7 +866,7 @@ class parse_context private: parse_context_group_state cur_group_state {}; private: parse_context_branch_reset_state cur_branch_reset_state {}; -#line 1964 "reflect.h2" +#line 1965 "reflect.h2" public: std::map named_groups {}; private: error_func error_out; // TODO: Declaring std::function fails for cpp2. @@ -873,64 +874,64 @@ class parse_context public: explicit parse_context(cpp2::impl::in r, auto const& e); -#line 1975 "reflect.h2" +#line 1976 "reflect.h2" // State management functions // // Returned group state needs to be stored and provided in `end_group`. public: [[nodiscard]] auto start_group() & -> parse_context_group_state; -#line 1988 "reflect.h2" +#line 1989 "reflect.h2" // `old_state` argument needs to be from start group. public: [[nodiscard]] auto end_group(cpp2::impl::in old_state) & -> token_ptr; -#line 1996 "reflect.h2" +#line 1997 "reflect.h2" public: [[nodiscard]] auto get_modifiers() const& -> expression_flags; -#line 2000 "reflect.h2" +#line 2001 "reflect.h2" public: auto set_modifiers(cpp2::impl::in mod) & -> void; -#line 2004 "reflect.h2" +#line 2005 "reflect.h2" // Branch reset management functions // public: [[nodiscard]] auto branch_reset_new_state() & -> parse_context_branch_reset_state; -#line 2016 "reflect.h2" +#line 2017 "reflect.h2" public: auto branch_reset_restore_state(cpp2::impl::in old_state) & -> void; -#line 2023 "reflect.h2" +#line 2024 "reflect.h2" public: auto next_alternative() & -> void; -#line 2029 "reflect.h2" +#line 2030 "reflect.h2" // Regex token management // public: auto add_token(cpp2::impl::in token) & -> void; -#line 2035 "reflect.h2" +#line 2036 "reflect.h2" public: [[nodiscard]] auto has_token() const& -> bool; -#line 2039 "reflect.h2" +#line 2040 "reflect.h2" public: [[nodiscard]] auto pop_token() & -> token_ptr; -#line 2050 "reflect.h2" +#line 2051 "reflect.h2" public: [[nodiscard]] auto get_as_token() & -> token_ptr; -#line 2054 "reflect.h2" +#line 2055 "reflect.h2" // Group management // public: [[nodiscard]] auto get_cur_group() const& -> int; -#line 2060 "reflect.h2" +#line 2061 "reflect.h2" public: [[nodiscard]] auto next_group() & -> int; -#line 2064 "reflect.h2" +#line 2065 "reflect.h2" public: auto set_named_group(cpp2::impl::in name, cpp2::impl::in id) & -> void; -#line 2071 "reflect.h2" +#line 2072 "reflect.h2" public: [[nodiscard]] auto get_named_group(cpp2::impl::in name) const& -> int; -#line 2082 "reflect.h2" +#line 2083 "reflect.h2" // Position management functions // public: [[nodiscard]] auto current() const& -> char; @@ -938,51 +939,51 @@ class parse_context // Get the next token in the regex, skipping spaces according to the parameters. See `x` and `xx` modifiers. private: [[nodiscard]] auto get_next_position(cpp2::impl::in in_class, cpp2::impl::in no_skip) const& -> size_t; -#line 2126 "reflect.h2" +#line 2127 "reflect.h2" // Return true if next token is available. private: [[nodiscard]] auto next_impl(cpp2::impl::in in_class, cpp2::impl::in no_skip) & -> bool; -#line 2138 "reflect.h2" +#line 2139 "reflect.h2" public: [[nodiscard]] auto next() & -> auto; public: [[nodiscard]] auto next_in_class() & -> auto; public: [[nodiscard]] auto next_no_skip() & -> auto; public: [[nodiscard]] auto next_n(cpp2::impl::in n) & -> bool; -#line 2151 "reflect.h2" +#line 2152 "reflect.h2" public: [[nodiscard]] auto has_next() const& -> bool; private: [[nodiscard]] auto grab_until_impl(cpp2::impl::in e, cpp2::impl::out r, cpp2::impl::in any) & -> bool; -#line 2174 "reflect.h2" +#line 2175 "reflect.h2" public: [[nodiscard]] auto grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_until_one_of(cpp2::impl::in e, cpp2::impl::out r) & -> auto; public: [[nodiscard]] auto grab_n(cpp2::impl::in n, cpp2::impl::out r) & -> bool; -#line 2191 "reflect.h2" +#line 2192 "reflect.h2" public: [[nodiscard]] auto grab_number() & -> std::string; -#line 2212 "reflect.h2" +#line 2213 "reflect.h2" private: [[nodiscard]] auto peek_impl(cpp2::impl::in in_class) const& -> char; -#line 2222 "reflect.h2" +#line 2223 "reflect.h2" public: [[nodiscard]] auto peek() const& -> auto; public: [[nodiscard]] auto peek_in_class() const& -> auto; -#line 2226 "reflect.h2" +#line 2227 "reflect.h2" // Parsing functions // public: [[nodiscard]] auto parser_group_modifiers(cpp2::impl::in change_str, expression_flags& parser_modifiers) & -> bool; -#line 2282 "reflect.h2" +#line 2283 "reflect.h2" public: [[nodiscard]] auto parse_until(cpp2::impl::in term) & -> bool; -#line 2320 "reflect.h2" +#line 2321 "reflect.h2" public: [[nodiscard]] auto parse(cpp2::impl::in modifiers) & -> bool; -#line 2335 "reflect.h2" +#line 2336 "reflect.h2" // Misc functions public: [[nodiscard]] auto get_pos() const& -> auto; @@ -994,10 +995,10 @@ class parse_context public: auto operator=(parse_context const&) -> void = delete; -#line 2346 "reflect.h2" +#line 2347 "reflect.h2" }; -#line 2349 "reflect.h2" +#line 2350 "reflect.h2" // Context for one function generation. Generation of functions can be interleaved, // therefore we buffer the code for one function here. // @@ -1007,16 +1008,16 @@ class generation_function_context { public: auto add_tabs(cpp2::impl::in c) & -> void; -#line 2363 "reflect.h2" +#line 2364 "reflect.h2" public: auto remove_tabs(cpp2::impl::in c) & -> void; public: generation_function_context(auto const& code_, auto const& tabs_); public: generation_function_context(); -#line 2366 "reflect.h2" +#line 2367 "reflect.h2" }; -#line 2369 "reflect.h2" +#line 2370 "reflect.h2" // Context for generating the state machine. class generation_context { @@ -1036,68 +1037,68 @@ class generation_context // Add code line. public: auto add(cpp2::impl::in s) & -> void; -#line 2391 "reflect.h2" +#line 2392 "reflect.h2" // Add check for token. The check needs to be a function call that returns a boolean. public: auto add_check(cpp2::impl::in check) & -> void; -#line 2397 "reflect.h2" +#line 2398 "reflect.h2" // Add a stateful check. The check needs to return a `match_return`. public: auto add_statefull(cpp2::impl::in next_func, cpp2::impl::in check) & -> void; -#line 2406 "reflect.h2" +#line 2407 "reflect.h2" protected: auto start_func_named(cpp2::impl::in name) & -> void; -#line 2417 "reflect.h2" +#line 2418 "reflect.h2" protected: [[nodiscard]] auto start_func() & -> std::string; -#line 2424 "reflect.h2" +#line 2425 "reflect.h2" protected: auto end_func_statefull(cpp2::impl::in s) & -> void; -#line 2443 "reflect.h2" +#line 2444 "reflect.h2" // Generate the function for a token. public: [[nodiscard]] auto generate_func(cpp2::impl::in token) & -> std::string; -#line 2453 "reflect.h2" +#line 2454 "reflect.h2" // Generate the reset for a list of group identifiers. public: [[nodiscard]] auto generate_reset(cpp2::impl::in> groups) & -> std::string; -#line 2476 "reflect.h2" +#line 2477 "reflect.h2" // Name generation // protected: [[nodiscard]] auto gen_func_name() & -> std::string; -#line 2484 "reflect.h2" +#line 2485 "reflect.h2" public: [[nodiscard]] auto next_func_name() & -> std::string; -#line 2488 "reflect.h2" +#line 2489 "reflect.h2" protected: [[nodiscard]] auto gen_reset_func_name() & -> std::string; -#line 2494 "reflect.h2" +#line 2495 "reflect.h2" public: [[nodiscard]] auto gen_temp() & -> std::string; -#line 2500 "reflect.h2" +#line 2501 "reflect.h2" // Context management // public: [[nodiscard]] auto new_context() & -> generation_function_context*; -#line 2510 "reflect.h2" +#line 2511 "reflect.h2" public: auto finish_context() & -> void; -#line 2518 "reflect.h2" +#line 2519 "reflect.h2" // Misc functions // private: [[nodiscard]] auto get_current() & -> generation_function_context*; -#line 2524 "reflect.h2" +#line 2525 "reflect.h2" private: [[nodiscard]] auto get_base() & -> generation_function_context*; -#line 2528 "reflect.h2" +#line 2529 "reflect.h2" public: [[nodiscard]] auto get_entry_func() const& -> std::string; -#line 2532 "reflect.h2" +#line 2533 "reflect.h2" public: [[nodiscard]] auto create_named_group_lookup(cpp2::impl::in> named_groups) const& -> std::string; -#line 2556 "reflect.h2" +#line 2557 "reflect.h2" // Run the generation for the token. public: [[nodiscard]] auto run(cpp2::impl::in token) & -> std::string; public: generation_context() = default; @@ -1105,7 +1106,7 @@ class generation_context public: auto operator=(generation_context const&) -> void = delete; -#line 2562 "reflect.h2" +#line 2563 "reflect.h2" }; // Regex syntax: | Example: ab|ba @@ -1125,24 +1126,24 @@ class alternative_token public: auto operator=(alternative_token const&) -> void = delete; -#line 2581 "reflect.h2" +#line 2582 "reflect.h2" }; class alternative_token_gen : public regex_token { -#line 2587 "reflect.h2" +#line 2588 "reflect.h2" private: token_vec alternatives; public: explicit alternative_token_gen(cpp2::impl::in a); -#line 2594 "reflect.h2" +#line 2595 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2611 "reflect.h2" +#line 2612 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; -#line 2618 "reflect.h2" +#line 2619 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in a) -> std::string; public: virtual ~alternative_token_gen() noexcept; @@ -1150,19 +1151,19 @@ class alternative_token_gen public: auto operator=(alternative_token_gen const&) -> void = delete; -#line 2630 "reflect.h2" +#line 2631 "reflect.h2" }; -#line 2633 "reflect.h2" +#line 2634 "reflect.h2" // Regex syntax: . // class any_token : public regex_token_check { -#line 2639 "reflect.h2" +#line 2640 "reflect.h2" public: explicit any_token(cpp2::impl::in single_line); -#line 2643 "reflect.h2" +#line 2644 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; public: virtual ~any_token() noexcept; @@ -1170,37 +1171,37 @@ class any_token public: auto operator=(any_token const&) -> void = delete; -#line 2648 "reflect.h2" +#line 2649 "reflect.h2" }; -#line 2651 "reflect.h2" +#line 2652 "reflect.h2" // Regex syntax: a // class char_token : public regex_token { -#line 2657 "reflect.h2" +#line 2658 "reflect.h2" private: std::string token; private: bool ignore_case; public: explicit char_token(cpp2::impl::in t, cpp2::impl::in ignore_case_); -#line 2666 "reflect.h2" +#line 2667 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 2670 "reflect.h2" +#line 2671 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2693 "reflect.h2" +#line 2694 "reflect.h2" public: auto gen_case_insensitive(cpp2::impl::in lower, cpp2::impl::in upper, generation_context& ctx) const& -> void; -#line 2714 "reflect.h2" +#line 2715 "reflect.h2" public: auto gen_case_sensitive(generation_context& ctx) const& -> void; -#line 2732 "reflect.h2" +#line 2733 "reflect.h2" public: [[nodiscard]] auto add_escapes(std::string str) const& -> std::string; -#line 2747 "reflect.h2" +#line 2748 "reflect.h2" public: auto append(char_token const& that) & -> void; public: virtual ~char_token() noexcept; @@ -1208,30 +1209,30 @@ class char_token public: auto operator=(char_token const&) -> void = delete; -#line 2751 "reflect.h2" +#line 2752 "reflect.h2" }; -#line 2754 "reflect.h2" +#line 2755 "reflect.h2" // Regex syntax: [] Example: [abcx-y[:digits:]] // class class_token : public regex_token { -#line 2760 "reflect.h2" +#line 2761 "reflect.h2" private: bool negate; private: bool case_insensitive; private: std::string class_str; public: explicit class_token(cpp2::impl::in negate_, cpp2::impl::in case_insensitive_, cpp2::impl::in class_str_, cpp2::impl::in str); -#line 2772 "reflect.h2" +#line 2773 "reflect.h2" // TODO: Rework class generation: Generate check functions for classes. public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 2898 "reflect.h2" +#line 2899 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2903 "reflect.h2" +#line 2904 "reflect.h2" private: [[nodiscard]] static auto create_matcher(cpp2::impl::in name, cpp2::impl::in template_arguments) -> std::string; public: virtual ~class_token() noexcept; @@ -1239,20 +1240,20 @@ class class_token public: auto operator=(class_token const&) -> void = delete; -#line 2910 "reflect.h2" +#line 2911 "reflect.h2" }; -#line 2913 "reflect.h2" +#line 2914 "reflect.h2" // Regex syntax: \a or \n or \[ // [[nodiscard]] auto escape_token_parse(parse_context& ctx) -> token_ptr; -#line 2954 "reflect.h2" +#line 2955 "reflect.h2" // Regex syntax: \K Example: ab\Kcd // [[nodiscard]] auto global_group_reset_token_parse(parse_context& ctx) -> token_ptr; -#line 2965 "reflect.h2" +#line 2966 "reflect.h2" // Regex syntax: \ Example: \1 // \g{name_or_number} // \k{name_or_number} @@ -1262,16 +1263,16 @@ class class_token class group_ref_token : public regex_token { -#line 2975 "reflect.h2" +#line 2976 "reflect.h2" private: int id; private: bool case_insensitive; public: explicit group_ref_token(cpp2::impl::in id_, cpp2::impl::in case_insensitive_, cpp2::impl::in str); -#line 2985 "reflect.h2" +#line 2986 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 3086 "reflect.h2" +#line 3087 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~group_ref_token() noexcept; @@ -1279,10 +1280,10 @@ class group_ref_token public: auto operator=(group_ref_token const&) -> void = delete; -#line 3089 "reflect.h2" +#line 3090 "reflect.h2" }; -#line 3092 "reflect.h2" +#line 3093 "reflect.h2" // Regex syntax: () Example: (abc) // (?:) (?i:abc) @@ -1296,22 +1297,22 @@ class group_ref_token class group_token : public regex_token { -#line 3106 "reflect.h2" +#line 3107 "reflect.h2" private: int number {-1}; private: token_ptr inner {nullptr}; public: [[nodiscard]] static auto parse_lookahead(parse_context& ctx, cpp2::impl::in syntax, cpp2::impl::in positive) -> token_ptr; -#line 3123 "reflect.h2" +#line 3124 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 3260 "reflect.h2" +#line 3261 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in name, cpp2::impl::in name_brackets, cpp2::impl::in has_modifier, cpp2::impl::in modifiers, cpp2::impl::in inner_) -> std::string; -#line 3278 "reflect.h2" +#line 3279 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3298 "reflect.h2" +#line 3299 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~group_token() noexcept; @@ -1320,25 +1321,25 @@ class group_token public: auto operator=(group_token const&) -> void = delete; -#line 3305 "reflect.h2" +#line 3306 "reflect.h2" }; -#line 3308 "reflect.h2" +#line 3309 "reflect.h2" // Regex syntax: \x or \x{} Example: \x{62} // [[nodiscard]] auto hexadecimal_token_parse(parse_context& ctx) -> token_ptr; -#line 3349 "reflect.h2" +#line 3350 "reflect.h2" // Regex syntax: $ Example: aa$ // [[nodiscard]] auto line_end_token_parse(parse_context& ctx) -> token_ptr; -#line 3369 "reflect.h2" +#line 3370 "reflect.h2" // Regex syntax: ^ Example: ^aa // [[nodiscard]] auto line_start_token_parse(parse_context& ctx) -> token_ptr; -#line 3385 "reflect.h2" +#line 3386 "reflect.h2" // Regex syntax: (?=) or (?!) or (*pla), etc. Example: (?=AA) // // Parsed in group_token. @@ -1346,16 +1347,16 @@ class group_token class lookahead_token : public regex_token { -#line 3393 "reflect.h2" +#line 3394 "reflect.h2" protected: bool positive; public: token_ptr inner {nullptr}; public: explicit lookahead_token(cpp2::impl::in positive_); -#line 3400 "reflect.h2" +#line 3401 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3406 "reflect.h2" +#line 3407 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~lookahead_token() noexcept; @@ -1363,26 +1364,26 @@ class lookahead_token public: auto operator=(lookahead_token const&) -> void = delete; -#line 3409 "reflect.h2" +#line 3410 "reflect.h2" }; -#line 3412 "reflect.h2" +#line 3413 "reflect.h2" // Named character classes // [[nodiscard]] auto named_class_token_parse(parse_context& ctx) -> token_ptr; -#line 3440 "reflect.h2" +#line 3441 "reflect.h2" // Regex syntax: \o{} Example: \o{142} // [[nodiscard]] auto octal_token_parse(parse_context& ctx) -> token_ptr; -#line 3468 "reflect.h2" +#line 3469 "reflect.h2" // Regex syntax: {min, max} Example: a{2,4} // class range_token : public regex_token { -#line 3474 "reflect.h2" +#line 3475 "reflect.h2" protected: int min_count {-1}; protected: int max_count {-1}; protected: int kind {range_flags::greedy}; @@ -1392,19 +1393,19 @@ class range_token public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 3554 "reflect.h2" +#line 3555 "reflect.h2" public: auto parse_modifier(parse_context& ctx) & -> void; -#line 3566 "reflect.h2" +#line 3567 "reflect.h2" public: [[nodiscard]] auto gen_mod_string() const& -> std::string; -#line 3579 "reflect.h2" +#line 3580 "reflect.h2" public: [[nodiscard]] auto gen_range_string() const& -> std::string; -#line 3598 "reflect.h2" +#line 3599 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3609 "reflect.h2" +#line 3610 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~range_token() noexcept; @@ -1412,16 +1413,16 @@ class range_token public: auto operator=(range_token const&) -> void = delete; -#line 3613 "reflect.h2" +#line 3614 "reflect.h2" }; -#line 3616 "reflect.h2" +#line 3617 "reflect.h2" // Regex syntax: *, +, or ? Example: aa* // class special_range_token : public range_token { -#line 3622 "reflect.h2" +#line 3623 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; public: virtual ~special_range_token() noexcept; @@ -1430,17 +1431,17 @@ class special_range_token public: auto operator=(special_range_token const&) -> void = delete; -#line 3652 "reflect.h2" +#line 3653 "reflect.h2" }; -#line 3655 "reflect.h2" +#line 3656 "reflect.h2" // Regex syntax: \b or \B Example: \bword\b // // Matches the start end end of word boundaries. // [[nodiscard]] auto word_boundary_token_parse(parse_context& ctx) -> token_ptr; -#line 3677 "reflect.h2" +#line 3678 "reflect.h2" //----------------------------------------------------------------------- // // Parser for regular expression. @@ -1461,24 +1462,24 @@ template class regex_generator public: explicit regex_generator(cpp2::impl::in r, Error_out const& e); -#line 3700 "reflect.h2" +#line 3701 "reflect.h2" public: [[nodiscard]] auto parse() & -> std::string; -#line 3735 "reflect.h2" +#line 3736 "reflect.h2" private: auto extract_modifiers() & -> void; public: regex_generator(regex_generator const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(regex_generator const&) -> void = delete; -#line 3749 "reflect.h2" +#line 3750 "reflect.h2" }; template [[nodiscard]] auto generate_regex(cpp2::impl::in regex, Err const& err) -> std::string; -#line 3761 "reflect.h2" +#line 3762 "reflect.h2" auto regex_gen(meta::type_declaration& t) -> void; -#line 3816 "reflect.h2" +#line 3817 "reflect.h2" //----------------------------------------------------------------------- // // apply_metafunctions - for types @@ -1486,10 +1487,11 @@ auto regex_gen(meta::type_declaration& t) -> void; [[nodiscard]] auto apply_metafunctions( declaration_node& n, type_declaration_impl& rtypeimpl, - auto const& error + auto const& error, + auto const& libraries_try_apply ) -> bool; -#line 3942 "reflect.h2" +#line 3945 "reflect.h2" //----------------------------------------------------------------------- // // apply_metafunctions - for functions @@ -1497,10 +1499,11 @@ auto regex_gen(meta::type_declaration& t) -> void; [[nodiscard]] auto apply_metafunctions( declaration_node& n, function_declaration_impl& rfuncimpl, - auto const& error + auto const& error, + auto const& libraries_try_apply ) -> bool; -#line 4003 "reflect.h2" +#line 4008 "reflect.h2" } } @@ -1533,6 +1536,7 @@ namespace meta { #line 51 "reflect.h2" compiler_services_base::compiler_services_base( + reflect_libraries* libraries, std::vector* errors_, std::set* includes_, stable_vector* generated_tokens_, @@ -1543,27 +1547,27 @@ namespace meta { , errors_original_size{ cpp2::unsafe_narrow(std::ssize(*cpp2::impl::assert_not_null(errors))) } , generated_tokens{ generated_tokens_ } , generated_declarations{ generated_declarations_ } - , parser{ *cpp2::impl::assert_not_null(errors), *cpp2::impl::assert_not_null(includes) } -#line 58 "reflect.h2" + , parser{ *cpp2::impl::assert_not_null(libraries), *cpp2::impl::assert_not_null(errors), *cpp2::impl::assert_not_null(includes) } +#line 59 "reflect.h2" { -#line 65 "reflect.h2" +#line 66 "reflect.h2" } -#line 67 "reflect.h2" +#line 68 "reflect.h2" auto compiler_services_base::set_metafunction_name(cpp2::impl::in name, cpp2::impl::in> args) & -> void{ metafunction_name = name; metafunction_args = args; metafunctions_used = CPP2_UFCS(empty)(args); } -#line 73 "reflect.h2" +#line 74 "reflect.h2" [[nodiscard]] auto compiler_services_base::get_metafunction_name() const& -> std::string_view { return metafunction_name; } -#line 75 "reflect.h2" +#line 76 "reflect.h2" [[nodiscard]] auto compiler_services_base::arguments_were_used() const& -> bool { return metafunctions_used; } -#line 77 "reflect.h2" +#line 78 "reflect.h2" [[nodiscard]] auto compiler_services_base::lex_multiline( std::string_view source @@ -1580,7 +1584,7 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; // First split this string into source_lines -#line 91 "reflect.h2" +#line 92 "reflect.h2" if ( cpp2::impl::cmp_greater(CPP2_UFCS(ssize)(source),1) && newline_pos != source.npos) { @@ -1593,7 +1597,7 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; } } -#line 102 "reflect.h2" +#line 103 "reflect.h2" if (!(CPP2_UFCS(empty)(source))) { cpp2::move(add_line)(cpp2::move(source)); } @@ -1610,7 +1614,7 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; return tokens; } -#line 118 "reflect.h2" +#line 119 "reflect.h2" [[nodiscard]] auto compiler_services_base::parse_statement( std::string_view source @@ -1618,7 +1622,7 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; { cpp2::impl::deferred_init> stmt; -#line 124 "reflect.h2" +#line 125 "reflect.h2" auto original_source {source}; auto tokens {lex_multiline(cpp2::move(source))}; @@ -1633,7 +1637,7 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; }return std::move(stmt.value()); } -#line 138 "reflect.h2" +#line 139 "reflect.h2" [[nodiscard]] auto compiler_services_base::parse_and_add_declaration( std::string_view source @@ -1656,14 +1660,14 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; return result; } -#line 160 "reflect.h2" +#line 161 "reflect.h2" [[nodiscard]] auto compiler_services_base::position() const -> source_position { return { }; } -#line 166 "reflect.h2" +#line 167 "reflect.h2" auto compiler_services_base::require( cpp2::impl::in b, @@ -1675,7 +1679,7 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; } } -#line 177 "reflect.h2" +#line 178 "reflect.h2" auto compiler_services_base::error(cpp2::impl::in msg) const& -> void { auto message {cpp2::impl::as_(msg)}; @@ -1685,7 +1689,7 @@ auto newline_pos{CPP2_UFCS(find)(source, '\n')}; static_cast(CPP2_UFCS(emplace_back)((*cpp2::impl::assert_not_null(errors)), position(), cpp2::move(message))); } -#line 186 "reflect.h2" +#line 187 "reflect.h2" [[nodiscard]] auto compiler_services_base::is_active() const& -> bool { return true; } compiler_services_base::~compiler_services_base() noexcept{} @@ -1700,18 +1704,18 @@ compiler_services_base::compiler_services_base(compiler_services_base const& tha , metafunction_args{ that.metafunction_args } , metafunctions_used{ that.metafunctions_used }{} -#line 195 "reflect.h2" +#line 196 "reflect.h2" compiler_services_impl::compiler_services_impl(cpp2::impl::in csb) : compiler_services_base{ csb } , compiler_services::interface{ }{ -#line 197 "reflect.h2" +#line 198 "reflect.h2" } -#line 199 "reflect.h2" +#line 200 "reflect.h2" [[nodiscard]] auto compiler_services_impl::get_metafunction_name() const -> std::string_view { return metafunction_name; } -#line 201 "reflect.h2" +#line 202 "reflect.h2" [[nodiscard]] auto compiler_services_impl::get_argument(cpp2::impl::in index) -> std::string{ metafunctions_used = true; if (([_0 = 0, _1 = index, _2 = CPP2_UFCS(ssize)(metafunction_args)]{ return cpp2::impl::cmp_less_eq(_0,_1) && cpp2::impl::cmp_less(_1,_2); }())) { @@ -1720,16 +1724,16 @@ compiler_services_base::compiler_services_base(compiler_services_base const& tha return ""; } -#line 209 "reflect.h2" +#line 210 "reflect.h2" [[nodiscard]] auto compiler_services_impl::get_arguments() -> std::vector{ metafunctions_used = true; return metafunction_args; } -#line 214 "reflect.h2" +#line 215 "reflect.h2" auto compiler_services_impl::add_runtime_support_include(cpp2::impl::in s) -> void { static_cast(CPP2_UFCS(emplace)((*cpp2::impl::assert_not_null(includes)), s)); } -#line 216 "reflect.h2" +#line 217 "reflect.h2" auto compiler_services_impl::append_declaration_to_translation_unit(cpp2::impl::in source) -> void { if (!(parse_and_add_declaration(source))) { @@ -1737,13 +1741,13 @@ compiler_services_base::compiler_services_base(compiler_services_base const& tha } } -#line 223 "reflect.h2" +#line 224 "reflect.h2" auto compiler_services_impl::require(cpp2::impl::in b, cpp2::impl::in msg) const -> void { compiler_services_base::require(b, msg); } -#line 225 "reflect.h2" +#line 226 "reflect.h2" auto compiler_services_impl::error(cpp2::impl::in msg) const -> void { compiler_services_base::error(msg); } -#line 227 "reflect.h2" +#line 228 "reflect.h2" auto compiler_services_impl::report_violation(cpp2::impl::in msg) const -> void{ error(msg); throw(std::runtime_error( @@ -1754,7 +1758,7 @@ compiler_services_base::compiler_services_base(compiler_services_base const& tha compiler_services_impl::~compiler_services_impl() noexcept{} -#line 237 "reflect.h2" +#line 238 "reflect.h2" /* //----------------------------------------------------------------------- // @@ -1791,7 +1795,7 @@ type_id: @polymorphic_base @copyable type = } */ -#line 274 "reflect.h2" +#line 275 "reflect.h2" //----------------------------------------------------------------------- // // Declarations @@ -1802,7 +1806,7 @@ type_id: @polymorphic_base @copyable type = // All declarations are wrappers around a pointer to node // -#line 289 "reflect.h2" +#line 290 "reflect.h2" declaration_base::declaration_base( cpp2::impl::in csb, @@ -1810,62 +1814,62 @@ type_id: @polymorphic_base @copyable type = ) : compiler_services_base{ csb } , n{ n_ } -#line 294 "reflect.h2" +#line 295 "reflect.h2" { -#line 297 "reflect.h2" +#line 298 "reflect.h2" if (cpp2::cpp2_default.is_active() && !(n) ) { cpp2::cpp2_default.report_violation(CPP2_CONTRACT_MSG("a meta::declaration must point to a valid declaration_node, not null")); } } -#line 300 "reflect.h2" +#line 301 "reflect.h2" [[nodiscard]] auto declaration_base::position() const -> source_position { return CPP2_UFCS(position)((*cpp2::impl::assert_not_null(n))); } declaration_base::~declaration_base() noexcept{} -#line 303 "reflect.h2" +#line 304 "reflect.h2" //----------------------------------------------------------------------- // Declaration factories // -#line 306 "reflect.h2" +#line 307 "reflect.h2" [[nodiscard]] auto make_declaration(cpp2::impl::in csb, declaration_node* n) -> auto { return declaration{ cpp2_new(csb, n), cpp2_new(csb)}; } -#line 312 "reflect.h2" +#line 313 "reflect.h2" [[nodiscard]] auto make_function_declaration(cpp2::impl::in csb, declaration_node* n) -> auto { return function_declaration{ cpp2_new(csb, n), cpp2_new(csb, n), cpp2_new(csb)}; } -#line 319 "reflect.h2" +#line 320 "reflect.h2" [[nodiscard]] auto make_object_declaration(cpp2::impl::in csb, declaration_node* n) -> auto { return object_declaration{ cpp2_new(csb, n), cpp2_new(csb, n), cpp2_new(csb)}; } -#line 326 "reflect.h2" +#line 327 "reflect.h2" [[nodiscard]] auto make_type_declaration(cpp2::impl::in csb, declaration_node* n) -> auto { return type_declaration{ cpp2_new(csb, n), cpp2_new(csb, n), cpp2_new(csb)}; } -#line 333 "reflect.h2" +#line 334 "reflect.h2" [[nodiscard]] auto make_alias_declaration(cpp2::impl::in csb, declaration_node* n) -> auto { return alias_declaration{ cpp2_new(csb, n), cpp2_new(csb, n), cpp2_new(csb)}; } -#line 340 "reflect.h2" +#line 341 "reflect.h2" //----------------------------------------------------------------------- // All declarations // -#line 349 "reflect.h2" +#line 350 "reflect.h2" declaration_impl::declaration_impl( cpp2::impl::in csb, @@ -1873,131 +1877,131 @@ type_id: @polymorphic_base @copyable type = ) : declaration_base{ csb, n_ } , declaration::interface{ } -#line 354 "reflect.h2" +#line 355 "reflect.h2" { } -#line 358 "reflect.h2" - [[nodiscard]] auto declaration_impl::is_public() const -> bool { return CPP2_UFCS(is_public)((*cpp2::impl::assert_not_null(n))); } #line 359 "reflect.h2" - [[nodiscard]] auto declaration_impl::is_protected() const -> bool { return CPP2_UFCS(is_protected)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::is_public() const -> bool { return CPP2_UFCS(is_public)((*cpp2::impl::assert_not_null(n))); } #line 360 "reflect.h2" - [[nodiscard]] auto declaration_impl::is_private() const -> bool { return CPP2_UFCS(is_private)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::is_protected() const -> bool { return CPP2_UFCS(is_protected)((*cpp2::impl::assert_not_null(n))); } #line 361 "reflect.h2" + [[nodiscard]] auto declaration_impl::is_private() const -> bool { return CPP2_UFCS(is_private)((*cpp2::impl::assert_not_null(n))); } +#line 362 "reflect.h2" [[nodiscard]] auto declaration_impl::is_default_access() const -> bool { return CPP2_UFCS(is_default_access)((*cpp2::impl::assert_not_null(n))); } -#line 363 "reflect.h2" - auto declaration_impl::default_to_public() -> void { static_cast(CPP2_UFCS(make_public)((*cpp2::impl::assert_not_null(n)))); } #line 364 "reflect.h2" - auto declaration_impl::default_to_protected() -> void { static_cast(CPP2_UFCS(make_protected)((*cpp2::impl::assert_not_null(n)))); } + auto declaration_impl::default_to_public() -> void { static_cast(CPP2_UFCS(make_public)((*cpp2::impl::assert_not_null(n)))); } #line 365 "reflect.h2" + auto declaration_impl::default_to_protected() -> void { static_cast(CPP2_UFCS(make_protected)((*cpp2::impl::assert_not_null(n)))); } +#line 366 "reflect.h2" auto declaration_impl::default_to_private() -> void { static_cast(CPP2_UFCS(make_private)((*cpp2::impl::assert_not_null(n)))); } -#line 367 "reflect.h2" - [[nodiscard]] auto declaration_impl::make_public() -> bool { return CPP2_UFCS(make_public)((*cpp2::impl::assert_not_null(n))); } #line 368 "reflect.h2" - [[nodiscard]] auto declaration_impl::make_protected() -> bool { return CPP2_UFCS(make_protected)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::make_public() -> bool { return CPP2_UFCS(make_public)((*cpp2::impl::assert_not_null(n))); } #line 369 "reflect.h2" + [[nodiscard]] auto declaration_impl::make_protected() -> bool { return CPP2_UFCS(make_protected)((*cpp2::impl::assert_not_null(n))); } +#line 370 "reflect.h2" [[nodiscard]] auto declaration_impl::make_private() -> bool { return CPP2_UFCS(make_private)((*cpp2::impl::assert_not_null(n))); } -#line 371 "reflect.h2" - [[nodiscard]] auto declaration_impl::has_name() const -> bool { return CPP2_UFCS(has_name)((*cpp2::impl::assert_not_null(n))); } #line 372 "reflect.h2" + [[nodiscard]] auto declaration_impl::has_name() const -> bool { return CPP2_UFCS(has_name)((*cpp2::impl::assert_not_null(n))); } +#line 373 "reflect.h2" [[nodiscard]] auto declaration_impl::has_name(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_name)((*cpp2::impl::assert_not_null(n)), s); } -#line 374 "reflect.h2" +#line 375 "reflect.h2" [[nodiscard]] auto declaration_impl::name() const -> std::string_view{ if (has_name()) {return CPP2_UFCS(as_string_view)((*cpp2::impl::assert_not_null(CPP2_UFCS(name)(*cpp2::impl::assert_not_null(n))))); } else { return ""; } } -#line 378 "reflect.h2" +#line 379 "reflect.h2" [[nodiscard]] auto declaration_impl::fully_qualified_name() const -> std::string { return CPP2_UFCS(fully_qualified_name)((*cpp2::impl::assert_not_null(n))); } -#line 380 "reflect.h2" +#line 381 "reflect.h2" [[nodiscard]] auto declaration_impl::has_initializer() const -> bool { return CPP2_UFCS(has_initializer)((*cpp2::impl::assert_not_null(n))); } -#line 382 "reflect.h2" - [[nodiscard]] auto declaration_impl::is_global() const -> bool { return CPP2_UFCS(is_global)((*cpp2::impl::assert_not_null(n))); } #line 383 "reflect.h2" - [[nodiscard]] auto declaration_impl::is_function() const -> bool { return CPP2_UFCS(is_function)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::is_global() const -> bool { return CPP2_UFCS(is_global)((*cpp2::impl::assert_not_null(n))); } #line 384 "reflect.h2" - [[nodiscard]] auto declaration_impl::is_object() const -> bool { return CPP2_UFCS(is_object)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::is_function() const -> bool { return CPP2_UFCS(is_function)((*cpp2::impl::assert_not_null(n))); } #line 385 "reflect.h2" - [[nodiscard]] auto declaration_impl::is_base_object() const -> bool { return CPP2_UFCS(is_base_object)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::is_object() const -> bool { return CPP2_UFCS(is_object)((*cpp2::impl::assert_not_null(n))); } #line 386 "reflect.h2" - [[nodiscard]] auto declaration_impl::is_member_object() const -> bool { return CPP2_UFCS(is_member_object)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::is_base_object() const -> bool { return CPP2_UFCS(is_base_object)((*cpp2::impl::assert_not_null(n))); } #line 387 "reflect.h2" - [[nodiscard]] auto declaration_impl::is_type() const -> bool { return CPP2_UFCS(is_type)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::is_member_object() const -> bool { return CPP2_UFCS(is_member_object)((*cpp2::impl::assert_not_null(n))); } #line 388 "reflect.h2" - [[nodiscard]] auto declaration_impl::is_namespace() const -> bool { return CPP2_UFCS(is_namespace)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::is_type() const -> bool { return CPP2_UFCS(is_type)((*cpp2::impl::assert_not_null(n))); } #line 389 "reflect.h2" + [[nodiscard]] auto declaration_impl::is_namespace() const -> bool { return CPP2_UFCS(is_namespace)((*cpp2::impl::assert_not_null(n))); } +#line 390 "reflect.h2" [[nodiscard]] auto declaration_impl::is_alias() const -> bool { return CPP2_UFCS(is_alias)((*cpp2::impl::assert_not_null(n))); } -#line 391 "reflect.h2" - [[nodiscard]] auto declaration_impl::is_type_alias() const -> bool { return CPP2_UFCS(is_type_alias)((*cpp2::impl::assert_not_null(n))); } #line 392 "reflect.h2" - [[nodiscard]] auto declaration_impl::is_namespace_alias() const -> bool { return CPP2_UFCS(is_namespace_alias)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::is_type_alias() const -> bool { return CPP2_UFCS(is_type_alias)((*cpp2::impl::assert_not_null(n))); } #line 393 "reflect.h2" + [[nodiscard]] auto declaration_impl::is_namespace_alias() const -> bool { return CPP2_UFCS(is_namespace_alias)((*cpp2::impl::assert_not_null(n))); } +#line 394 "reflect.h2" [[nodiscard]] auto declaration_impl::is_object_alias() const -> bool { return CPP2_UFCS(is_object_alias)((*cpp2::impl::assert_not_null(n))); } -#line 395 "reflect.h2" +#line 396 "reflect.h2" [[nodiscard]] auto declaration_impl::is_function_expression() const -> bool { return CPP2_UFCS(is_function_expression)((*cpp2::impl::assert_not_null(n))); } -#line 397 "reflect.h2" - [[nodiscard]] auto declaration_impl::as_function() const -> function_declaration { return make_function_declaration((*this), n); } #line 398 "reflect.h2" - [[nodiscard]] auto declaration_impl::as_object() const -> object_declaration { return make_object_declaration((*this), n); } + [[nodiscard]] auto declaration_impl::as_function() const -> function_declaration { return make_function_declaration((*this), n); } #line 399 "reflect.h2" - [[nodiscard]] auto declaration_impl::as_type() const -> type_declaration { return make_type_declaration((*this), n); } + [[nodiscard]] auto declaration_impl::as_object() const -> object_declaration { return make_object_declaration((*this), n); } #line 400 "reflect.h2" + [[nodiscard]] auto declaration_impl::as_type() const -> type_declaration { return make_type_declaration((*this), n); } +#line 401 "reflect.h2" [[nodiscard]] auto declaration_impl::as_alias() const -> alias_declaration { return make_alias_declaration((*this), n); } -#line 402 "reflect.h2" +#line 403 "reflect.h2" [[nodiscard]] auto declaration_impl::get_parent() const -> declaration { return make_declaration((*this), n); } -#line 404 "reflect.h2" - [[nodiscard]] auto declaration_impl::parent_is_function() const -> bool { return CPP2_UFCS(parent_is_function)((*cpp2::impl::assert_not_null(n))); } #line 405 "reflect.h2" - [[nodiscard]] auto declaration_impl::parent_is_object() const -> bool { return CPP2_UFCS(parent_is_object)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::parent_is_function() const -> bool { return CPP2_UFCS(parent_is_function)((*cpp2::impl::assert_not_null(n))); } #line 406 "reflect.h2" - [[nodiscard]] auto declaration_impl::parent_is_type() const -> bool { return CPP2_UFCS(parent_is_type)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::parent_is_object() const -> bool { return CPP2_UFCS(parent_is_object)((*cpp2::impl::assert_not_null(n))); } #line 407 "reflect.h2" - [[nodiscard]] auto declaration_impl::parent_is_namespace() const -> bool { return CPP2_UFCS(parent_is_namespace)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::parent_is_type() const -> bool { return CPP2_UFCS(parent_is_type)((*cpp2::impl::assert_not_null(n))); } #line 408 "reflect.h2" + [[nodiscard]] auto declaration_impl::parent_is_namespace() const -> bool { return CPP2_UFCS(parent_is_namespace)((*cpp2::impl::assert_not_null(n))); } +#line 409 "reflect.h2" [[nodiscard]] auto declaration_impl::parent_is_alias() const -> bool { return CPP2_UFCS(parent_is_alias)((*cpp2::impl::assert_not_null(n))); } -#line 410 "reflect.h2" - [[nodiscard]] auto declaration_impl::parent_is_type_alias() const -> bool { return CPP2_UFCS(parent_is_type_alias)((*cpp2::impl::assert_not_null(n))); } #line 411 "reflect.h2" - [[nodiscard]] auto declaration_impl::parent_is_namespace_alias() const -> bool { return CPP2_UFCS(parent_is_namespace_alias)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto declaration_impl::parent_is_type_alias() const -> bool { return CPP2_UFCS(parent_is_type_alias)((*cpp2::impl::assert_not_null(n))); } #line 412 "reflect.h2" + [[nodiscard]] auto declaration_impl::parent_is_namespace_alias() const -> bool { return CPP2_UFCS(parent_is_namespace_alias)((*cpp2::impl::assert_not_null(n))); } +#line 413 "reflect.h2" [[nodiscard]] auto declaration_impl::parent_is_object_alias() const -> bool { return CPP2_UFCS(parent_is_object_alias)((*cpp2::impl::assert_not_null(n))); } -#line 414 "reflect.h2" +#line 415 "reflect.h2" [[nodiscard]] auto declaration_impl::parent_is_polymorphic() const -> bool { return CPP2_UFCS(parent_is_polymorphic)((*cpp2::impl::assert_not_null(n))); } -#line 416 "reflect.h2" +#line 417 "reflect.h2" auto declaration_impl::mark_for_removal_from_enclosing_type() -> void // this precondition should be sufficient ... { if (cpp2::type_safety.is_active() && !(parent_is_type()) ) { cpp2::type_safety.report_violation(""); } -#line 419 "reflect.h2" +#line 420 "reflect.h2" auto test {CPP2_UFCS(type_member_mark_for_removal)((*cpp2::impl::assert_not_null(n)))}; if (cpp2::cpp2_default.is_active() && !(cpp2::move(test)) ) { cpp2::cpp2_default.report_violation(""); }// ... to ensure this assert is true } -#line 423 "reflect.h2" +#line 424 "reflect.h2" [[nodiscard]] auto declaration_impl::print() const -> std::string { return CPP2_UFCS(pretty_print_visualize)((*cpp2::impl::assert_not_null(n)), 0); } declaration_impl::~declaration_impl() noexcept{} -#line 427 "reflect.h2" +#line 428 "reflect.h2" //----------------------------------------------------------------------- // Function declarations // -#line 436 "reflect.h2" +#line 437 "reflect.h2" function_declaration_impl::function_declaration_impl( cpp2::impl::in csb, @@ -2005,80 +2009,80 @@ type_id: @polymorphic_base @copyable type = ) : declaration_base{ csb, n_ } , function_declaration::interface{ } -#line 441 "reflect.h2" +#line 442 "reflect.h2" { if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(is_function)((*cpp2::impl::assert_not_null(n)))) ) { cpp2::cpp2_default.report_violation(""); } } -#line 446 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::index_of_parameter_named(cpp2::impl::in s) const -> int { return CPP2_UFCS(index_of_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } #line 447 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::has_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } + [[nodiscard]] auto function_declaration_impl::index_of_parameter_named(cpp2::impl::in s) const -> int { return CPP2_UFCS(index_of_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } #line 448 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::has_in_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_in_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } + [[nodiscard]] auto function_declaration_impl::has_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } #line 449 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::has_copy_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_copy_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } + [[nodiscard]] auto function_declaration_impl::has_in_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_in_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } #line 450 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::has_inout_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_inout_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } + [[nodiscard]] auto function_declaration_impl::has_copy_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_copy_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } #line 451 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::has_out_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_out_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } + [[nodiscard]] auto function_declaration_impl::has_inout_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_inout_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } #line 452 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::has_move_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_move_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } + [[nodiscard]] auto function_declaration_impl::has_out_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_out_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } #line 453 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::has_forward_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_forward_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } + [[nodiscard]] auto function_declaration_impl::has_move_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_move_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } #line 454 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::has_forward_parameter_named(cpp2::impl::in s) const -> bool { return CPP2_UFCS(has_forward_parameter_named)((*cpp2::impl::assert_not_null(n)), s); } +#line 455 "reflect.h2" [[nodiscard]] auto function_declaration_impl::first_parameter_name() const -> std::string { return CPP2_UFCS(first_parameter_name)((*cpp2::impl::assert_not_null(n))); } // has_parameter_with_name_and_pass: (override this, s: std::string_view, pass: passing_style) -> bool // TODO(DyXel) // = n*.has_parameter_with_name_and_pass(s, pass); -#line 458 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::is_function_with_this() const -> bool { return CPP2_UFCS(is_function_with_this)((*cpp2::impl::assert_not_null(n))); } #line 459 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::is_virtual() const -> bool { return CPP2_UFCS(is_virtual_function)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration_impl::is_function_with_this() const -> bool { return CPP2_UFCS(is_function_with_this)((*cpp2::impl::assert_not_null(n))); } #line 460 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::is_defaultable() const -> bool { return CPP2_UFCS(is_defaultable_function)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration_impl::is_virtual() const -> bool { return CPP2_UFCS(is_virtual_function)((*cpp2::impl::assert_not_null(n))); } #line 461 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::is_constructor() const -> bool { return CPP2_UFCS(is_constructor)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration_impl::is_defaultable() const -> bool { return CPP2_UFCS(is_defaultable_function)((*cpp2::impl::assert_not_null(n))); } #line 462 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::is_default_constructor() const -> bool { return CPP2_UFCS(is_default_constructor)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration_impl::is_constructor() const -> bool { return CPP2_UFCS(is_constructor)((*cpp2::impl::assert_not_null(n))); } #line 463 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::is_move() const -> bool { return CPP2_UFCS(is_move)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration_impl::is_default_constructor() const -> bool { return CPP2_UFCS(is_default_constructor)((*cpp2::impl::assert_not_null(n))); } #line 464 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::is_swap() const -> bool { return CPP2_UFCS(is_swap)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration_impl::is_move() const -> bool { return CPP2_UFCS(is_move)((*cpp2::impl::assert_not_null(n))); } #line 465 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::is_constructor_with_that() const -> bool { return CPP2_UFCS(is_constructor_with_that)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration_impl::is_swap() const -> bool { return CPP2_UFCS(is_swap)((*cpp2::impl::assert_not_null(n))); } #line 466 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::is_constructor_with_in_that() const -> bool { return CPP2_UFCS(is_constructor_with_in_that)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration_impl::is_constructor_with_that() const -> bool { return CPP2_UFCS(is_constructor_with_that)((*cpp2::impl::assert_not_null(n))); } #line 467 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::is_constructor_with_move_that() const -> bool { return CPP2_UFCS(is_constructor_with_move_that)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration_impl::is_constructor_with_in_that() const -> bool { return CPP2_UFCS(is_constructor_with_in_that)((*cpp2::impl::assert_not_null(n))); } #line 468 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::is_assignment() const -> bool { return CPP2_UFCS(is_assignment)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration_impl::is_constructor_with_move_that() const -> bool { return CPP2_UFCS(is_constructor_with_move_that)((*cpp2::impl::assert_not_null(n))); } #line 469 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::is_assignment_with_that() const -> bool { return CPP2_UFCS(is_assignment_with_that)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration_impl::is_assignment() const -> bool { return CPP2_UFCS(is_assignment)((*cpp2::impl::assert_not_null(n))); } #line 470 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::is_assignment_with_in_that() const -> bool { return CPP2_UFCS(is_assignment_with_in_that)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration_impl::is_assignment_with_that() const -> bool { return CPP2_UFCS(is_assignment_with_that)((*cpp2::impl::assert_not_null(n))); } #line 471 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::is_assignment_with_move_that() const -> bool { return CPP2_UFCS(is_assignment_with_move_that)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration_impl::is_assignment_with_in_that() const -> bool { return CPP2_UFCS(is_assignment_with_in_that)((*cpp2::impl::assert_not_null(n))); } #line 472 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::is_assignment_with_move_that() const -> bool { return CPP2_UFCS(is_assignment_with_move_that)((*cpp2::impl::assert_not_null(n))); } +#line 473 "reflect.h2" [[nodiscard]] auto function_declaration_impl::is_destructor() const -> bool { return CPP2_UFCS(is_destructor)((*cpp2::impl::assert_not_null(n))); } -#line 474 "reflect.h2" +#line 475 "reflect.h2" [[nodiscard]] auto function_declaration_impl::is_copy_or_move() const -> bool { return is_constructor_with_that() || is_assignment_with_that(); } -#line 476 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::has_declared_return_type() const -> bool { return CPP2_UFCS(has_declared_return_type)((*cpp2::impl::assert_not_null(n))); } #line 477 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::has_deduced_return_type() const -> bool { return CPP2_UFCS(has_deduced_return_type)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration_impl::has_declared_return_type() const -> bool { return CPP2_UFCS(has_declared_return_type)((*cpp2::impl::assert_not_null(n))); } #line 478 "reflect.h2" - [[nodiscard]] auto function_declaration_impl::has_bool_return_type() const -> bool { return CPP2_UFCS(has_bool_return_type)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto function_declaration_impl::has_deduced_return_type() const -> bool { return CPP2_UFCS(has_deduced_return_type)((*cpp2::impl::assert_not_null(n))); } #line 479 "reflect.h2" + [[nodiscard]] auto function_declaration_impl::has_bool_return_type() const -> bool { return CPP2_UFCS(has_bool_return_type)((*cpp2::impl::assert_not_null(n))); } +#line 480 "reflect.h2" [[nodiscard]] auto function_declaration_impl::has_non_void_return_type() const -> bool { return CPP2_UFCS(has_non_void_return_type)((*cpp2::impl::assert_not_null(n))); } -#line 481 "reflect.h2" +#line 482 "reflect.h2" [[nodiscard]] auto function_declaration_impl::unnamed_return_type() const -> std::string { return CPP2_UFCS(unnamed_return_type_to_string)((*cpp2::impl::assert_not_null(n))); } -#line 483 "reflect.h2" +#line 484 "reflect.h2" [[nodiscard]] auto function_declaration_impl::get_parameters() const -> std::vector { @@ -2089,16 +2093,16 @@ type_id: @polymorphic_base @copyable type = return ret; } -#line 493 "reflect.h2" +#line 494 "reflect.h2" [[nodiscard]] auto function_declaration_impl::is_binary_comparison_function() const -> bool { return CPP2_UFCS(is_binary_comparison_function)((*cpp2::impl::assert_not_null(n))); } -#line 495 "reflect.h2" +#line 496 "reflect.h2" auto function_declaration_impl::default_to_virtual() -> void { static_cast(CPP2_UFCS(make_function_virtual)((*cpp2::impl::assert_not_null(n)))); } -#line 497 "reflect.h2" +#line 498 "reflect.h2" [[nodiscard]] auto function_declaration_impl::make_virtual() -> bool { return CPP2_UFCS(make_function_virtual)((*cpp2::impl::assert_not_null(n))); } -#line 499 "reflect.h2" +#line 500 "reflect.h2" auto function_declaration_impl::add_initializer(cpp2::impl::in source) -> void { require(!(CPP2_UFCS(has_initializer)((*cpp2::impl::assert_not_null(n)))), @@ -2117,12 +2121,12 @@ type_id: @polymorphic_base @copyable type = function_declaration_impl::~function_declaration_impl() noexcept{} -#line 517 "reflect.h2" +#line 518 "reflect.h2" //----------------------------------------------------------------------- // Object declarations // -#line 526 "reflect.h2" +#line 527 "reflect.h2" object_declaration_impl::object_declaration_impl( cpp2::impl::in csb, @@ -2130,18 +2134,18 @@ type_id: @polymorphic_base @copyable type = ) : declaration_base{ csb, n_ } , object_declaration::interface{ } -#line 531 "reflect.h2" +#line 532 "reflect.h2" { if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(is_object)((*cpp2::impl::assert_not_null(n)))) ) { cpp2::cpp2_default.report_violation(""); } } -#line 536 "reflect.h2" - [[nodiscard]] auto object_declaration_impl::is_const() const -> bool { return CPP2_UFCS(is_const)((*cpp2::impl::assert_not_null(n))); } #line 537 "reflect.h2" + [[nodiscard]] auto object_declaration_impl::is_const() const -> bool { return CPP2_UFCS(is_const)((*cpp2::impl::assert_not_null(n))); } +#line 538 "reflect.h2" [[nodiscard]] auto object_declaration_impl::has_wildcard_type() const -> bool { return CPP2_UFCS(has_wildcard_type)((*cpp2::impl::assert_not_null(n))); } -#line 539 "reflect.h2" +#line 540 "reflect.h2" [[nodiscard]] auto object_declaration_impl::type() const -> std::string{ auto ret {CPP2_UFCS(object_type)((*cpp2::impl::assert_not_null(n)))}; require(!(contains(ret, "(*ERROR*)")), @@ -2149,7 +2153,7 @@ type_id: @polymorphic_base @copyable type = return ret; } -#line 546 "reflect.h2" +#line 547 "reflect.h2" [[nodiscard]] auto object_declaration_impl::initializer() const -> std::string{ auto ret {CPP2_UFCS(object_initializer)((*cpp2::impl::assert_not_null(n)))}; require(!(contains(ret, "(*ERROR*)")), @@ -2159,12 +2163,12 @@ type_id: @polymorphic_base @copyable type = object_declaration_impl::~object_declaration_impl() noexcept{} -#line 555 "reflect.h2" +#line 556 "reflect.h2" //----------------------------------------------------------------------- // Type declarations // -#line 564 "reflect.h2" +#line 565 "reflect.h2" type_declaration_impl::type_declaration_impl( cpp2::impl::in csb, @@ -2172,20 +2176,20 @@ type_id: @polymorphic_base @copyable type = ) : declaration_base{ csb, n_ } , type_declaration::interface{ } -#line 569 "reflect.h2" +#line 570 "reflect.h2" { if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(is_type)((*cpp2::impl::assert_not_null(n)))) ) { cpp2::cpp2_default.report_violation(""); } } -#line 574 "reflect.h2" - [[nodiscard]] auto type_declaration_impl::is_polymorphic() const -> bool { return CPP2_UFCS(is_polymorphic)((*cpp2::impl::assert_not_null(n))); } #line 575 "reflect.h2" - [[nodiscard]] auto type_declaration_impl::is_final() const -> bool { return CPP2_UFCS(is_type_final)((*cpp2::impl::assert_not_null(n))); } + [[nodiscard]] auto type_declaration_impl::is_polymorphic() const -> bool { return CPP2_UFCS(is_polymorphic)((*cpp2::impl::assert_not_null(n))); } #line 576 "reflect.h2" + [[nodiscard]] auto type_declaration_impl::is_final() const -> bool { return CPP2_UFCS(is_type_final)((*cpp2::impl::assert_not_null(n))); } +#line 577 "reflect.h2" [[nodiscard]] auto type_declaration_impl::make_final() -> bool { return CPP2_UFCS(make_type_final)((*cpp2::impl::assert_not_null(n))); } -#line 578 "reflect.h2" +#line 579 "reflect.h2" [[nodiscard]] auto type_declaration_impl::get_member_functions() const -> std::vector { @@ -2203,7 +2207,7 @@ type_id: @polymorphic_base @copyable type = return ret; } -#line 595 "reflect.h2" +#line 596 "reflect.h2" [[nodiscard]] auto type_declaration_impl::get_member_functions_needing_initializer() const -> std::vector { @@ -2219,7 +2223,7 @@ type_id: @polymorphic_base @copyable type = return ret; } -#line 610 "reflect.h2" +#line 611 "reflect.h2" [[nodiscard]] auto type_declaration_impl::get_member_objects() const -> std::vector { @@ -2230,7 +2234,7 @@ type_id: @polymorphic_base @copyable type = return ret; } -#line 620 "reflect.h2" +#line 621 "reflect.h2" [[nodiscard]] auto type_declaration_impl::get_member_types() const -> std::vector { @@ -2241,7 +2245,7 @@ type_id: @polymorphic_base @copyable type = return ret; } -#line 630 "reflect.h2" +#line 631 "reflect.h2" [[nodiscard]] auto type_declaration_impl::get_member_aliases() const -> std::vector { @@ -2252,7 +2256,7 @@ type_id: @polymorphic_base @copyable type = return ret; } -#line 640 "reflect.h2" +#line 641 "reflect.h2" [[nodiscard]] auto type_declaration_impl::get_members() const -> std::vector { @@ -2263,7 +2267,7 @@ type_id: @polymorphic_base @copyable type = return ret; } -#line 650 "reflect.h2" +#line 651 "reflect.h2" [[nodiscard]] auto type_declaration_impl::query_declared_value_set_functions() const -> _query_declared_value_set_functions_ret { @@ -2276,7 +2280,7 @@ type_id: @polymorphic_base @copyable type = return ret; } -#line 662 "reflect.h2" +#line 663 "reflect.h2" auto type_declaration_impl::add_member(cpp2::impl::in source) -> void { auto decl {parse_statement(source)}; @@ -2291,22 +2295,22 @@ type_id: @polymorphic_base @copyable type = std::string("unexpected error while attempting to add member:\n") + source); } -#line 676 "reflect.h2" - auto type_declaration_impl::remove_marked_members() -> void { CPP2_UFCS(type_remove_marked_members)((*cpp2::impl::assert_not_null(n))); } #line 677 "reflect.h2" + auto type_declaration_impl::remove_marked_members() -> void { CPP2_UFCS(type_remove_marked_members)((*cpp2::impl::assert_not_null(n))); } +#line 678 "reflect.h2" auto type_declaration_impl::remove_all_members() -> void { CPP2_UFCS(type_remove_all_members)((*cpp2::impl::assert_not_null(n))); } -#line 679 "reflect.h2" +#line 680 "reflect.h2" auto type_declaration_impl::disable_member_function_generation() -> void { CPP2_UFCS(type_disable_member_function_generation)((*cpp2::impl::assert_not_null(n))); } type_declaration_impl::~type_declaration_impl() noexcept{} -#line 683 "reflect.h2" +#line 684 "reflect.h2" //----------------------------------------------------------------------- // Alias declarations // -#line 692 "reflect.h2" +#line 693 "reflect.h2" alias_declaration_impl::alias_declaration_impl( cpp2::impl::in csb, @@ -2314,7 +2318,7 @@ type_id: @polymorphic_base @copyable type = ) : declaration_base{ csb, n_ } , alias_declaration::interface{ } -#line 697 "reflect.h2" +#line 698 "reflect.h2" { if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(is_alias)((*cpp2::impl::assert_not_null(n)))) ) { cpp2::cpp2_default.report_violation(""); } @@ -2322,7 +2326,7 @@ type_id: @polymorphic_base @copyable type = alias_declaration_impl::~alias_declaration_impl() noexcept{} -#line 704 "reflect.h2" +#line 705 "reflect.h2" //----------------------------------------------------------------------- // TODO(DyXel): Update this with something more apt? // Metafunctions - these are hardwired for now until we get to the @@ -2335,7 +2339,7 @@ type_id: @polymorphic_base @copyable type = // Some common metafunction helpers (metafunctions are just functions, // so they can be factored as usual) // -#line 716 "reflect.h2" +#line 717 "reflect.h2" auto add_virtual_destructor(meta::type_declaration& t) -> void { CPP2_UFCS(add_member)(t, "operator=: (virtual move this) = { }"); @@ -2356,7 +2360,7 @@ auto add_virtual_destructor(meta::type_declaration& t) -> void // // The verbose name is on purpose, lets try to give it a better name if it // can be generalized into something useful for all developers. -#line 736 "reflect.h2" +#line 737 "reflect.h2" auto foreign_interface_pseudovalue(meta::type_declaration& t) -> void { std::vector interface_funcs {}; @@ -2418,7 +2422,7 @@ auto foreign_interface_pseudovalue(meta::type_declaration& t) -> void CPP2_UFCS(add_member)(t, "operator=: (move this) = { }\n"); } -#line 798 "reflect.h2" +#line 799 "reflect.h2" //----------------------------------------------------------------------- // // "... an abstract base class defines an interface ..." @@ -2431,7 +2435,7 @@ auto foreign_interface_pseudovalue(meta::type_declaration& t) -> void // // an abstract base class having only pure virtual functions // -#line 810 "reflect.h2" +#line 811 "reflect.h2" auto interface(meta::type_declaration& t) -> void { auto has_dtor {false}; @@ -2458,7 +2462,7 @@ auto interface(meta::type_declaration& t) -> void } } -#line 837 "reflect.h2" +#line 838 "reflect.h2" //----------------------------------------------------------------------- // // "C.35: A base class destructor should be either public and @@ -2478,7 +2482,7 @@ auto interface(meta::type_declaration& t) -> void // // Unlike an interface, it can have nonpublic and nonvirtual functions. // -#line 856 "reflect.h2" +#line 857 "reflect.h2" auto polymorphic_base(meta::type_declaration& t) -> void { auto has_dtor {false}; @@ -2503,7 +2507,7 @@ auto polymorphic_base(meta::type_declaration& t) -> void } } -#line 881 "reflect.h2" +#line 882 "reflect.h2" //----------------------------------------------------------------------- // // "... A totally ordered type ... requires operator<=> that @@ -2524,7 +2528,7 @@ auto polymorphic_base(meta::type_declaration& t) -> void //----------------------------------------------------------------------- // -#line 901 "reflect.h2" +#line 902 "reflect.h2" auto ordered_impl( meta::type_declaration& t, cpp2::impl::in ordering// must be "strong_ordering" etc. @@ -2554,7 +2558,7 @@ auto ordered_impl( // // Note: the ordering that should be encouraged as default gets the nice name // -#line 930 "reflect.h2" +#line 931 "reflect.h2" auto ordered(meta::type_declaration& t) -> void { ordered_impl(t, "strong_ordering"); @@ -2563,7 +2567,7 @@ auto ordered(meta::type_declaration& t) -> void //----------------------------------------------------------------------- // weakly_ordered - a weakly ordered type // -#line 938 "reflect.h2" +#line 939 "reflect.h2" auto weakly_ordered(meta::type_declaration& t) -> void { ordered_impl(t, "weak_ordering"); @@ -2572,13 +2576,13 @@ auto weakly_ordered(meta::type_declaration& t) -> void //----------------------------------------------------------------------- // partially_ordered - a partially ordered type // -#line 946 "reflect.h2" +#line 947 "reflect.h2" auto partially_ordered(meta::type_declaration& t) -> void { ordered_impl(t, "partial_ordering"); } -#line 952 "reflect.h2" +#line 953 "reflect.h2" //----------------------------------------------------------------------- // // "A value is ... a regular type. It must have all public @@ -2595,7 +2599,7 @@ auto partially_ordered(meta::type_declaration& t) -> void // // A type with (copy and move) x (construction and assignment) // -#line 968 "reflect.h2" +#line 969 "reflect.h2" auto copyable(meta::type_declaration& t) -> void { // If the user explicitly wrote any of the copy/move functions, @@ -2630,7 +2634,7 @@ auto copyable(meta::type_declaration& t) -> void // A regular type: copyable, plus has public default construction // and no protected or virtual functions // -#line 1002 "reflect.h2" +#line 1003 "reflect.h2" auto basic_value(meta::type_declaration& t) -> void { CPP2_UFCS(copyable)(t); @@ -2659,28 +2663,28 @@ auto basic_value(meta::type_declaration& t) -> void // // Note: the ordering that should be encouraged as default gets the nice name // -#line 1030 "reflect.h2" +#line 1031 "reflect.h2" auto value(meta::type_declaration& t) -> void { CPP2_UFCS(ordered)(t); CPP2_UFCS(basic_value)(t); } -#line 1036 "reflect.h2" +#line 1037 "reflect.h2" auto weakly_ordered_value(meta::type_declaration& t) -> void { CPP2_UFCS(weakly_ordered)(t); CPP2_UFCS(basic_value)(t); } -#line 1042 "reflect.h2" +#line 1043 "reflect.h2" auto partially_ordered_value(meta::type_declaration& t) -> void { CPP2_UFCS(partially_ordered)(t); CPP2_UFCS(basic_value)(t); } -#line 1049 "reflect.h2" +#line 1050 "reflect.h2" //----------------------------------------------------------------------- // // C.20: If you can avoid defining default operations, do @@ -2703,7 +2707,7 @@ auto partially_ordered_value(meta::type_declaration& t) -> void // // a type without declared copy/move/destructor functions // -#line 1071 "reflect.h2" +#line 1072 "reflect.h2" auto cpp1_rule_of_zero(meta::type_declaration& t) -> void { for ( auto& mf : CPP2_UFCS(get_member_functions)(t) ) @@ -2741,7 +2745,7 @@ auto cpp1_rule_of_zero(meta::type_declaration& t) -> void // no virtual functions, and no user-defined constructors // (i.e., no invariants) or assignment or destructors. // -#line 1108 "reflect.h2" +#line 1109 "reflect.h2" auto cpp2_struct(meta::type_declaration& t) -> void { std::string ctor_params {}; @@ -2793,7 +2797,7 @@ value_member_info::value_member_info(auto const& name_, auto const& type_, auto , type{ type_ } , value{ value_ }{} -#line 1155 "reflect.h2" +#line 1156 "reflect.h2" //----------------------------------------------------------------------- // // "C enumerations constitute a curiously half-baked concept. ... @@ -2812,7 +2816,7 @@ value_member_info::value_member_info(auto const& name_, auto const& type_, auto // a type together with named constants that are its possible values // -#line 1178 "reflect.h2" +#line 1179 "reflect.h2" auto basic_enum( meta::type_declaration& t, auto const& nextval, @@ -2837,7 +2841,7 @@ auto basic_enum( { std::string value{"-1"}; -#line 1201 "reflect.h2" +#line 1202 "reflect.h2" for ( auto const& m : CPP2_UFCS(get_members)(t) ) if ( CPP2_UFCS(is_member_object)(m)) @@ -2879,7 +2883,7 @@ std::string value{"-1"}; } } -#line 1241 "reflect.h2" +#line 1242 "reflect.h2" if ((CPP2_UFCS(empty)(enumerators))) { CPP2_UFCS(error)(t, "an enumeration must contain at least one enumerator value"); return ; @@ -2930,7 +2934,7 @@ std::string value{"-1"}; } } -#line 1292 "reflect.h2" +#line 1293 "reflect.h2" // 2. Replace: Erase the contents and replace with modified contents // // Note that most values and functions are declared as '==' compile-time values, i.e. Cpp1 'constexpr' @@ -2980,7 +2984,7 @@ std::string to_string_impl{" to_string_impl: (this, prefix: std::string_view" // Provide 'to_string' and 'to_code' functions to print enumerator // name(s) as human-readable strings or as code expressions -#line 1339 "reflect.h2" +#line 1340 "reflect.h2" { if (bitwise) { to_string_impl += ", separator: std::string_view ) -> std::string = { \n" @@ -3021,7 +3025,7 @@ std::string to_string_impl{" to_string_impl: (this, prefix: std::string_view" } } -#line 1378 "reflect.h2" +#line 1379 "reflect.h2" if (bitwise) { CPP2_UFCS(add_member)(t, " to_string: (this) -> std::string = to_string_impl( \"\", \", \" );"); CPP2_UFCS(add_member)(t, " to_code : (this) -> std::string = to_string_impl( \"" + cpp2::to_string(CPP2_UFCS(name)(t)) + "::\", \" | \" );"); @@ -3035,7 +3039,7 @@ std::string from_string{" from_string: (s: std::string_view) -> " + cpp2::to_ // Provide a 'from_string' function to parse strings into enumerators -#line 1389 "reflect.h2" +#line 1390 "reflect.h2" { std::string_view prefix {""}; std::string_view combine_op {"return"}; @@ -3057,7 +3061,7 @@ std::string from_string{" from_string: (s: std::string_view) -> " + cpp2::to_ { std::string_view else_{""}; -#line 1409 "reflect.h2" +#line 1410 "reflect.h2" for ( auto const& e : cpp2::move(enumerators) ) { from_string += " " + cpp2::to_string(else_) + "if \"" + cpp2::to_string(e.name) + "\" == x { " + cpp2::to_string(combine_op) + " " + cpp2::to_string(e.name) + "; }\n"; @@ -3065,7 +3069,7 @@ std::string_view else_{""}; } } -#line 1415 "reflect.h2" +#line 1416 "reflect.h2" if (bitwise) { from_string += " else { break outer; }\n" " }\n" @@ -3081,11 +3085,11 @@ std::string_view else_{""}; } } -#line 1429 "reflect.h2" +#line 1430 "reflect.h2" CPP2_UFCS(add_member)(t, " from_code: (s: std::string_view) -> " + cpp2::to_string(CPP2_UFCS(name)(t)) + " = { str: std::string = s; return from_string( cpp2::string_util::replace_all(str, \"" + cpp2::to_string(CPP2_UFCS(name)(t)) + "::\", \"\" ) ); }"); } -#line 1433 "reflect.h2" +#line 1434 "reflect.h2" //----------------------------------------------------------------------- // // "An enum[...] is a totally ordered value type that stores a @@ -3095,7 +3099,7 @@ std::string_view else_{""}; // // -- P0707R4, section 3 // -#line 1442 "reflect.h2" +#line 1443 "reflect.h2" auto cpp2_enum(meta::type_declaration& t) -> void { // Let basic_enum do its thing, with an incrementing value generator @@ -3112,7 +3116,7 @@ auto cpp2_enum(meta::type_declaration& t) -> void ); } -#line 1459 "reflect.h2" +#line 1460 "reflect.h2" //----------------------------------------------------------------------- // // "flag_enum expresses an enumeration that stores values @@ -3123,7 +3127,7 @@ auto cpp2_enum(meta::type_declaration& t) -> void // // -- P0707R4, section 3 // -#line 1469 "reflect.h2" +#line 1470 "reflect.h2" auto flag_enum(meta::type_declaration& t) -> void { // Let basic_enum do its thing, with a power-of-two value generator @@ -3145,7 +3149,7 @@ auto flag_enum(meta::type_declaration& t) -> void ); } -#line 1491 "reflect.h2" +#line 1492 "reflect.h2" //----------------------------------------------------------------------- // // "As with void*, programmers should know that unions [...] are @@ -3170,7 +3174,7 @@ auto flag_enum(meta::type_declaration& t) -> void // a type that contains exactly one of a fixed set of values at a time // -#line 1515 "reflect.h2" +#line 1516 "reflect.h2" auto cpp2_union(meta::type_declaration& t) -> void { std::vector alternatives {}; @@ -3179,7 +3183,7 @@ auto value{0}; // 1. Gather: All the user-written members, and find/compute the max size -#line 1522 "reflect.h2" +#line 1523 "reflect.h2" for ( auto const& m : CPP2_UFCS(get_members)(t) ) { do @@ -3209,7 +3213,7 @@ auto value{0}; } while (false); ++value; } } -#line 1550 "reflect.h2" +#line 1551 "reflect.h2" std::string discriminator_type {}; if (cpp2::impl::cmp_less(CPP2_UFCS(ssize)(alternatives),std::numeric_limits::max())) { discriminator_type = "i8"; @@ -3224,7 +3228,7 @@ auto value{0}; discriminator_type = "i64"; }}} -#line 1565 "reflect.h2" +#line 1566 "reflect.h2" // 2. Replace: Erase the contents and replace with modified contents CPP2_UFCS(remove_marked_members)(t); @@ -3233,7 +3237,7 @@ std::string storage{" _storage: cpp2::aligned_storage t) -> void { std::cout << CPP2_UFCS(print)(t) << "\n"; } -#line 1671 "reflect.h2" +#line 1672 "reflect.h2" auto print(cpp2::impl::in f) -> void { std::cout << CPP2_UFCS(print)(f) << "\n"; } -#line 1677 "reflect.h2" +#line 1678 "reflect.h2" //----------------------------------------------------------------------- // // meta - mark f as a metafunction and generate registration code for it // -#line 1681 "reflect.h2" +#line 1682 "reflect.h2" auto meta(meta::function_declaration& f) -> void { // TODO(DyXel): Check that the function: @@ -3465,7 +3469,7 @@ return none; [[nodiscard]] auto expression_flags::from_code(cpp2::impl::in s) -> expression_flags{ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::move(str), "expression_flags::", "")); } -#line 1697 "reflect.h2" +#line 1698 "reflect.h2" //----------------------------------------------------------------------- // // regex - creates regular expressions from members @@ -3481,11 +3485,11 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov // ``` // -#line 1713 "reflect.h2" +#line 1714 "reflect.h2" // Possible modifiers for a regular expression. // -#line 1717 "reflect.h2" +#line 1718 "reflect.h2" // mod: i // mod: m // mod: s @@ -3493,106 +3497,106 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov // mod: x // mod: xx -#line 1726 "reflect.h2" +#line 1727 "reflect.h2" // Tokens for regular expressions. // // Basic class for a regex token. // -#line 1735 "reflect.h2" +#line 1736 "reflect.h2" regex_token::regex_token(cpp2::impl::in str) : string_rep{ str }{ -#line 1737 "reflect.h2" +#line 1738 "reflect.h2" } -#line 1739 "reflect.h2" +#line 1740 "reflect.h2" regex_token::regex_token() : string_rep{ "" }{ -#line 1741 "reflect.h2" +#line 1742 "reflect.h2" } //parse: (inout ctx: parse_context) -> token_ptr; // Generate the matching code. -#line 1746 "reflect.h2" - auto regex_token::add_groups([[maybe_unused]] std::set& unnamed_param_2) const -> void{}// Adds all group indices to the set. #line 1747 "reflect.h2" - [[nodiscard]] auto regex_token::to_string() const& -> std::string{return string_rep; }// Create a string representation. + auto regex_token::add_groups([[maybe_unused]] std::set& unnamed_param_2) const -> void{}// Adds all group indices to the set. #line 1748 "reflect.h2" + [[nodiscard]] auto regex_token::to_string() const& -> std::string{return string_rep; }// Create a string representation. +#line 1749 "reflect.h2" auto regex_token::set_string(cpp2::impl::in s) & -> void{string_rep = s; } regex_token::~regex_token() noexcept{}// Set the string representation. -#line 1763 "reflect.h2" +#line 1764 "reflect.h2" regex_token_check::regex_token_check(cpp2::impl::in str, cpp2::impl::in check_) : regex_token{ str } , check{ check_ }{ -#line 1766 "reflect.h2" +#line 1767 "reflect.h2" } -#line 1768 "reflect.h2" +#line 1769 "reflect.h2" auto regex_token_check::generate_code(generation_context& ctx) const -> void{ ctx.add_check(check + "(" + ctx.match_parameters() + ")"); } regex_token_check::~regex_token_check() noexcept{} -#line 1782 "reflect.h2" +#line 1783 "reflect.h2" regex_token_code::regex_token_code(cpp2::impl::in str, cpp2::impl::in code_) : regex_token{ str } , code{ code_ }{ -#line 1785 "reflect.h2" +#line 1786 "reflect.h2" } -#line 1787 "reflect.h2" +#line 1788 "reflect.h2" auto regex_token_code::generate_code(generation_context& ctx) const -> void{ ctx.add(code); } regex_token_code::~regex_token_code() noexcept{} -#line 1799 "reflect.h2" +#line 1800 "reflect.h2" regex_token_empty::regex_token_empty(cpp2::impl::in str) : regex_token{ str }{ -#line 1801 "reflect.h2" +#line 1802 "reflect.h2" } -#line 1803 "reflect.h2" +#line 1804 "reflect.h2" auto regex_token_empty::generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void{ // Nothing. } regex_token_empty::~regex_token_empty() noexcept{} -#line 1817 "reflect.h2" +#line 1818 "reflect.h2" regex_token_list::regex_token_list(cpp2::impl::in t) : regex_token{ gen_string(t) } , tokens{ t }{ -#line 1820 "reflect.h2" +#line 1821 "reflect.h2" } -#line 1822 "reflect.h2" +#line 1823 "reflect.h2" auto regex_token_list::generate_code(generation_context& ctx) const -> void{ for ( auto const& token : tokens ) { (*cpp2::impl::assert_not_null(token)).generate_code(ctx); } } -#line 1828 "reflect.h2" +#line 1829 "reflect.h2" auto regex_token_list::add_groups(std::set& groups) const -> void{ for ( auto const& token : tokens ) { (*cpp2::impl::assert_not_null(token)).add_groups(groups); } } -#line 1834 "reflect.h2" +#line 1835 "reflect.h2" [[nodiscard]] auto regex_token_list::gen_string(cpp2::impl::in vec) -> std::string{ std::string r {""}; for ( auto const& token : vec ) { @@ -3603,7 +3607,7 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov regex_token_list::~regex_token_list() noexcept{} -#line 1857 "reflect.h2" +#line 1858 "reflect.h2" auto parse_context_group_state::next_alternative() & -> void{ token_vec new_list {}; std::swap(new_list, cur_match_list); @@ -3611,14 +3615,14 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov static_cast(alternate_match_lists.insert(alternate_match_lists.end(), CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, cpp2::move(new_list)))); } -#line 1865 "reflect.h2" +#line 1866 "reflect.h2" auto parse_context_group_state::swap(parse_context_group_state& t) & -> void{ std::swap(cur_match_list, t.cur_match_list); std::swap(alternate_match_lists, t.alternate_match_lists); std::swap(modifiers, t.modifiers); } -#line 1872 "reflect.h2" +#line 1873 "reflect.h2" [[nodiscard]] auto parse_context_group_state::get_as_token() & -> token_ptr{ if (alternate_match_lists.empty()) { post_process_list(cur_match_list); @@ -3630,15 +3634,15 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov } } -#line 1884 "reflect.h2" +#line 1885 "reflect.h2" auto parse_context_group_state::add(cpp2::impl::in token) & -> void{ cur_match_list.push_back(token); } -#line 1889 "reflect.h2" +#line 1890 "reflect.h2" [[nodiscard]] auto parse_context_group_state::empty() const& -> bool { return cur_match_list.empty(); } -#line 1893 "reflect.h2" +#line 1894 "reflect.h2" auto parse_context_group_state::post_process_list(token_vec& list) -> void{ // Merge all characters auto merge_pos {list.begin()}; @@ -3659,7 +3663,7 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov , modifiers{ modifiers_ }{} parse_context_group_state::parse_context_group_state(){} -#line 1919 "reflect.h2" +#line 1920 "reflect.h2" [[nodiscard]] auto parse_context_branch_reset_state::next() & -> int{ auto g {cur_group}; cur_group += 1; @@ -3668,20 +3672,20 @@ parse_context_group_state::parse_context_group_state(){} return g; } -#line 1928 "reflect.h2" +#line 1929 "reflect.h2" auto parse_context_branch_reset_state::set_next(cpp2::impl::in g) & -> void{ cur_group = g; max_group = max(max_group, g); } -#line 1934 "reflect.h2" +#line 1935 "reflect.h2" auto parse_context_branch_reset_state::next_alternative() & -> void{ if (is_active) { cur_group = from; } } -#line 1941 "reflect.h2" +#line 1942 "reflect.h2" auto parse_context_branch_reset_state::set_active_reset(cpp2::impl::in restart) & -> void{ is_active = true; cur_group = restart; @@ -3696,16 +3700,16 @@ parse_context_group_state::parse_context_group_state(){} , from{ from_ }{} parse_context_branch_reset_state::parse_context_branch_reset_state(){} -#line 1969 "reflect.h2" +#line 1970 "reflect.h2" parse_context::parse_context(cpp2::impl::in r, auto const& e) : regex{ r } , root{ CPP2_UFCS_TEMPLATE_NONLOCAL(cpp2_new)(cpp2::shared, "") } , error_out{ e }{ -#line 1973 "reflect.h2" +#line 1974 "reflect.h2" } -#line 1979 "reflect.h2" +#line 1980 "reflect.h2" [[nodiscard]] auto parse_context::start_group() & -> parse_context_group_state { parse_context_group_state old_state {}; @@ -3715,7 +3719,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return old_state; } -#line 1989 "reflect.h2" +#line 1990 "reflect.h2" [[nodiscard]] auto parse_context::end_group(cpp2::impl::in old_state) & -> token_ptr { auto inner {cur_group_state.get_as_token()}; @@ -3723,17 +3727,17 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return inner; } -#line 1996 "reflect.h2" +#line 1997 "reflect.h2" [[nodiscard]] auto parse_context::get_modifiers() const& -> expression_flags{ return cur_group_state.modifiers; } -#line 2000 "reflect.h2" +#line 2001 "reflect.h2" auto parse_context::set_modifiers(cpp2::impl::in mod) & -> void{ cur_group_state.modifiers = mod; } -#line 2007 "reflect.h2" +#line 2008 "reflect.h2" [[nodiscard]] auto parse_context::branch_reset_new_state() & -> parse_context_branch_reset_state { parse_context_branch_reset_state old_state {}; @@ -3743,7 +3747,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return old_state; } -#line 2016 "reflect.h2" +#line 2017 "reflect.h2" auto parse_context::branch_reset_restore_state(cpp2::impl::in old_state) & -> void { auto max_group {cur_branch_reset_state.max_group}; @@ -3751,24 +3755,24 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} cur_branch_reset_state.set_next(cpp2::move(max_group)); } -#line 2023 "reflect.h2" +#line 2024 "reflect.h2" auto parse_context::next_alternative() & -> void { cur_group_state.next_alternative(); cur_branch_reset_state.next_alternative(); } -#line 2031 "reflect.h2" +#line 2032 "reflect.h2" auto parse_context::add_token(cpp2::impl::in token) & -> void{ cur_group_state.add(token); } -#line 2035 "reflect.h2" +#line 2036 "reflect.h2" [[nodiscard]] auto parse_context::has_token() const& -> bool{ return !(cur_group_state.empty()); } -#line 2039 "reflect.h2" +#line 2040 "reflect.h2" [[nodiscard]] auto parse_context::pop_token() & -> token_ptr { token_ptr r {nullptr}; @@ -3780,22 +3784,22 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 2050 "reflect.h2" +#line 2051 "reflect.h2" [[nodiscard]] auto parse_context::get_as_token() & -> token_ptr{ return root; } -#line 2056 "reflect.h2" +#line 2057 "reflect.h2" [[nodiscard]] auto parse_context::get_cur_group() const& -> int{ return cur_branch_reset_state.cur_group; } -#line 2060 "reflect.h2" +#line 2061 "reflect.h2" [[nodiscard]] auto parse_context::next_group() & -> int{ return cur_branch_reset_state.next(); } -#line 2064 "reflect.h2" +#line 2065 "reflect.h2" auto parse_context::set_named_group(cpp2::impl::in name, cpp2::impl::in id) & -> void { if (!(named_groups.contains(name))) {// Redefinition of group name is not an error. The left most one is retained. @@ -3803,7 +3807,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2071 "reflect.h2" +#line 2072 "reflect.h2" [[nodiscard]] auto parse_context::get_named_group(cpp2::impl::in name) const& -> int { auto iter {named_groups.find(name)}; @@ -3815,10 +3819,10 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2084 "reflect.h2" +#line 2085 "reflect.h2" [[nodiscard]] auto parse_context::current() const& -> char{return CPP2_ASSERT_IN_BOUNDS(regex, pos); } -#line 2087 "reflect.h2" +#line 2088 "reflect.h2" [[nodiscard]] auto parse_context::get_next_position(cpp2::impl::in in_class, cpp2::impl::in no_skip) const& -> size_t { auto perl_syntax {false}; @@ -3858,7 +3862,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return cur; } -#line 2127 "reflect.h2" +#line 2128 "reflect.h2" [[nodiscard]] auto parse_context::next_impl(cpp2::impl::in in_class, cpp2::impl::in no_skip) & -> bool { pos = get_next_position(in_class, no_skip); @@ -3870,14 +3874,14 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2138 "reflect.h2" - [[nodiscard]] auto parse_context::next() & -> auto { return next_impl(false, false); } #line 2139 "reflect.h2" - [[nodiscard]] auto parse_context::next_in_class() & -> auto { return next_impl(true, false); } + [[nodiscard]] auto parse_context::next() & -> auto { return next_impl(false, false); } #line 2140 "reflect.h2" + [[nodiscard]] auto parse_context::next_in_class() & -> auto { return next_impl(true, false); } +#line 2141 "reflect.h2" [[nodiscard]] auto parse_context::next_no_skip() & -> auto { return next_impl(false, true); } -#line 2142 "reflect.h2" +#line 2143 "reflect.h2" [[nodiscard]] auto parse_context::next_n(cpp2::impl::in n) & -> bool{ auto r {true}; auto cur {0}; @@ -3887,10 +3891,10 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 2151 "reflect.h2" +#line 2152 "reflect.h2" [[nodiscard]] auto parse_context::has_next() const& -> bool{return cpp2::impl::cmp_less(pos,regex.size()); } -#line 2153 "reflect.h2" +#line 2154 "reflect.h2" [[nodiscard]] auto parse_context::grab_until_impl(cpp2::impl::in e, cpp2::impl::out r, cpp2::impl::in any) & -> bool { auto end {pos}; @@ -3912,14 +3916,14 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2174 "reflect.h2" - [[nodiscard]] auto parse_context::grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(e, cpp2::impl::out(&r), false); } #line 2175 "reflect.h2" - [[nodiscard]] auto parse_context::grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(std::string(1, e), cpp2::impl::out(&r), false); } + [[nodiscard]] auto parse_context::grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(e, cpp2::impl::out(&r), false); } #line 2176 "reflect.h2" + [[nodiscard]] auto parse_context::grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(std::string(1, e), cpp2::impl::out(&r), false); } +#line 2177 "reflect.h2" [[nodiscard]] auto parse_context::grab_until_one_of(cpp2::impl::in e, cpp2::impl::out r) & -> auto { return grab_until_impl(e, cpp2::impl::out(&r), true); } -#line 2178 "reflect.h2" +#line 2179 "reflect.h2" [[nodiscard]] auto parse_context::grab_n(cpp2::impl::in n, cpp2::impl::out r) & -> bool { if (cpp2::impl::cmp_less_eq(pos + cpp2::impl::as_(n),regex.size())) { @@ -3933,7 +3937,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2191 "reflect.h2" +#line 2192 "reflect.h2" [[nodiscard]] auto parse_context::grab_number() & -> std::string { auto start {pos}; @@ -3955,7 +3959,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return cpp2::move(r.value()); } -#line 2212 "reflect.h2" +#line 2213 "reflect.h2" [[nodiscard]] auto parse_context::peek_impl(cpp2::impl::in in_class) const& -> char{ auto next_pos {get_next_position(in_class, false)}; if (cpp2::impl::cmp_less(next_pos,regex.size())) { @@ -3966,12 +3970,12 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2222 "reflect.h2" - [[nodiscard]] auto parse_context::peek() const& -> auto { return peek_impl(false); } #line 2223 "reflect.h2" + [[nodiscard]] auto parse_context::peek() const& -> auto { return peek_impl(false); } +#line 2224 "reflect.h2" [[nodiscard]] auto parse_context::peek_in_class() const& -> auto { return peek_impl(true); } -#line 2228 "reflect.h2" +#line 2229 "reflect.h2" [[nodiscard]] auto parse_context::parser_group_modifiers(cpp2::impl::in change_str, expression_flags& parser_modifiers) & -> bool { auto is_negative {false}; @@ -4026,7 +4030,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return true; } -#line 2282 "reflect.h2" +#line 2283 "reflect.h2" [[nodiscard]] auto parse_context::parse_until(cpp2::impl::in term) & -> bool{ token_ptr cur_token {}; @@ -4065,7 +4069,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return true; } -#line 2320 "reflect.h2" +#line 2321 "reflect.h2" [[nodiscard]] auto parse_context::parse(cpp2::impl::in modifiers) & -> bool { @@ -4081,21 +4085,21 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 2337 "reflect.h2" - [[nodiscard]] auto parse_context::get_pos() const& -> auto { return pos; } #line 2338 "reflect.h2" - [[nodiscard]] auto parse_context::get_range(cpp2::impl::in start, cpp2::impl::in end) const& -> auto { return std::string(regex.substr(start, end - start + 1)); } + [[nodiscard]] auto parse_context::get_pos() const& -> auto { return pos; } #line 2339 "reflect.h2" + [[nodiscard]] auto parse_context::get_range(cpp2::impl::in start, cpp2::impl::in end) const& -> auto { return std::string(regex.substr(start, end - start + 1)); } +#line 2340 "reflect.h2" [[nodiscard]] auto parse_context::valid() const& -> bool{return has_next() && !(has_error); } -#line 2341 "reflect.h2" +#line 2342 "reflect.h2" [[nodiscard]] auto parse_context::error(cpp2::impl::in err) & -> token_ptr{ has_error = true; error_out("Error during parsing of regex '" + cpp2::to_string(regex) + "' at position '" + cpp2::to_string(pos) + "': " + cpp2::to_string(err) + ""); return nullptr; } -#line 2356 "reflect.h2" +#line 2357 "reflect.h2" auto generation_function_context::add_tabs(cpp2::impl::in c) & -> void{ int i {0}; for( ; cpp2::impl::cmp_less(i,c); i += 1 ) { @@ -4103,7 +4107,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2363 "reflect.h2" +#line 2364 "reflect.h2" auto generation_function_context::remove_tabs(cpp2::impl::in c) & -> void{ tabs = tabs.substr(0, (cpp2::impl::as_(c)) * 2); } @@ -4113,22 +4117,22 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} , tabs{ tabs_ }{} generation_function_context::generation_function_context(){} -#line 2381 "reflect.h2" +#line 2382 "reflect.h2" [[nodiscard]] auto generation_context::match_parameters() const& -> std::string{return "r.pos, ctx"; } -#line 2386 "reflect.h2" +#line 2387 "reflect.h2" auto generation_context::add(cpp2::impl::in s) & -> void{ auto cur {get_current()}; (*cpp2::impl::assert_not_null(cur)).code += "" + cpp2::to_string((*cpp2::impl::assert_not_null(cur)).tabs) + cpp2::to_string(s) + "\n"; } -#line 2392 "reflect.h2" +#line 2393 "reflect.h2" auto generation_context::add_check(cpp2::impl::in check) & -> void{ auto cur {get_current()}; (*cpp2::impl::assert_not_null(cur)).code += "" + cpp2::to_string((*cpp2::impl::assert_not_null(cur)).tabs) + "if !cpp2::regex::" + cpp2::to_string(check) + " { r.matched = false; break; }\n"; } -#line 2398 "reflect.h2" +#line 2399 "reflect.h2" auto generation_context::add_statefull(cpp2::impl::in next_func, cpp2::impl::in check) & -> void { end_func_statefull(check); @@ -4137,7 +4141,7 @@ generation_function_context::generation_function_context(){} start_func_named(cpp2::move(name)); } -#line 2406 "reflect.h2" +#line 2407 "reflect.h2" auto generation_context::start_func_named(cpp2::impl::in name) & -> void { auto cur {new_context()}; @@ -4149,7 +4153,7 @@ generation_function_context::generation_function_context(){} (*cpp2::impl::assert_not_null(cpp2::move(cur))).add_tabs(3); } -#line 2417 "reflect.h2" +#line 2418 "reflect.h2" [[nodiscard]] auto generation_context::start_func() & -> std::string { auto name {gen_func_name()}; @@ -4157,7 +4161,7 @@ generation_function_context::generation_function_context(){} return cpp2::move(name) + "()"; } -#line 2424 "reflect.h2" +#line 2425 "reflect.h2" auto generation_context::end_func_statefull(cpp2::impl::in s) & -> void { auto cur {get_current()}; @@ -4177,7 +4181,7 @@ generation_function_context::generation_function_context(){} finish_context(); } -#line 2444 "reflect.h2" +#line 2445 "reflect.h2" [[nodiscard]] auto generation_context::generate_func(cpp2::impl::in token) & -> std::string { auto name {start_func()}; @@ -4187,7 +4191,7 @@ generation_function_context::generation_function_context(){} return name; } -#line 2454 "reflect.h2" +#line 2455 "reflect.h2" [[nodiscard]] auto generation_context::generate_reset(cpp2::impl::in> groups) & -> std::string { if (groups.empty()) { @@ -4210,33 +4214,33 @@ generation_function_context::generation_function_context(){} return cpp2::move(name) + "()"; } -#line 2478 "reflect.h2" +#line 2479 "reflect.h2" [[nodiscard]] auto generation_context::gen_func_name() & -> std::string{ auto cur_id {matcher_func}; matcher_func += 1; return "func_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2484 "reflect.h2" +#line 2485 "reflect.h2" [[nodiscard]] auto generation_context::next_func_name() & -> std::string{ return gen_func_name() + "()"; } -#line 2488 "reflect.h2" +#line 2489 "reflect.h2" [[nodiscard]] auto generation_context::gen_reset_func_name() & -> std::string{ auto cur_id {reset_func}; reset_func += 1; return "reset_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2494 "reflect.h2" +#line 2495 "reflect.h2" [[nodiscard]] auto generation_context::gen_temp() & -> std::string{ auto cur_id {temp_name}; temp_name += 1; return "tmp_" + cpp2::to_string(cpp2::move(cur_id)) + ""; } -#line 2502 "reflect.h2" +#line 2503 "reflect.h2" [[nodiscard]] auto generation_context::new_context() & -> generation_function_context*{ gen_stack.push_back(generation_function_context()); auto cur {get_current()}; @@ -4245,7 +4249,7 @@ generation_function_context::generation_function_context(){} return cur; } -#line 2510 "reflect.h2" +#line 2511 "reflect.h2" auto generation_context::finish_context() & -> void{ auto cur {get_current()}; auto base {get_base()}; @@ -4254,22 +4258,22 @@ generation_function_context::generation_function_context(){} gen_stack.pop_back(); } -#line 2520 "reflect.h2" +#line 2521 "reflect.h2" [[nodiscard]] auto generation_context::get_current() & -> generation_function_context*{ return &gen_stack.back(); } -#line 2524 "reflect.h2" +#line 2525 "reflect.h2" [[nodiscard]] auto generation_context::get_base() & -> generation_function_context*{ return &CPP2_ASSERT_IN_BOUNDS_LITERAL(gen_stack, 0); } -#line 2528 "reflect.h2" +#line 2529 "reflect.h2" [[nodiscard]] auto generation_context::get_entry_func() const& -> std::string{ return entry_func; } -#line 2532 "reflect.h2" +#line 2533 "reflect.h2" [[nodiscard]] auto generation_context::create_named_group_lookup(cpp2::impl::in> named_groups) const& -> std::string { std::string res {"get_named_group_index: (name) -> int = {\n"}; @@ -4293,18 +4297,18 @@ generation_function_context::generation_function_context(){} return res; } -#line 2557 "reflect.h2" +#line 2558 "reflect.h2" [[nodiscard]] auto generation_context::run(cpp2::impl::in token) & -> std::string{ entry_func = generate_func(token); return (*cpp2::impl::assert_not_null(get_base())).code; } -#line 2572 "reflect.h2" +#line 2573 "reflect.h2" alternative_token::alternative_token() : regex_token_empty{ "" }{} -#line 2574 "reflect.h2" +#line 2575 "reflect.h2" [[nodiscard]] auto alternative_token::parse(parse_context& ctx) -> token_ptr{ if (ctx.current() != '|') {return nullptr; } @@ -4315,15 +4319,15 @@ generation_function_context::generation_function_context(){} alternative_token::~alternative_token() noexcept{} -#line 2589 "reflect.h2" +#line 2590 "reflect.h2" alternative_token_gen::alternative_token_gen(cpp2::impl::in a) : regex_token{ gen_string(a) } , alternatives{ a }{ -#line 2592 "reflect.h2" +#line 2593 "reflect.h2" } -#line 2594 "reflect.h2" +#line 2595 "reflect.h2" auto alternative_token_gen::generate_code(generation_context& ctx) const -> void { std::string functions {""}; @@ -4341,7 +4345,7 @@ generation_function_context::generation_function_context(){} ctx.add_statefull(next_name, "cpp2::regex::alternative_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ", other, " + cpp2::to_string(next_name) + " " + cpp2::to_string(cpp2::move(functions)) + ")"); } -#line 2611 "reflect.h2" +#line 2612 "reflect.h2" auto alternative_token_gen::add_groups(std::set& groups) const -> void { for ( auto const& cur : alternatives ) { @@ -4349,7 +4353,7 @@ generation_function_context::generation_function_context(){} } } -#line 2618 "reflect.h2" +#line 2619 "reflect.h2" [[nodiscard]] auto alternative_token_gen::gen_string(cpp2::impl::in a) -> std::string { std::string r {""}; @@ -4365,14 +4369,14 @@ generation_function_context::generation_function_context(){} alternative_token_gen::~alternative_token_gen() noexcept{} -#line 2639 "reflect.h2" +#line 2640 "reflect.h2" any_token::any_token(cpp2::impl::in single_line) : regex_token_check{ ".", "any_token_matcher" }{ -#line 2641 "reflect.h2" +#line 2642 "reflect.h2" } -#line 2643 "reflect.h2" +#line 2644 "reflect.h2" [[nodiscard]] auto any_token::parse(parse_context& ctx) -> token_ptr{ if ('.' != ctx.current()) {return nullptr; } @@ -4381,21 +4385,21 @@ generation_function_context::generation_function_context(){} any_token::~any_token() noexcept{} -#line 2660 "reflect.h2" +#line 2661 "reflect.h2" char_token::char_token(cpp2::impl::in t, cpp2::impl::in ignore_case_) : regex_token{ std::string(1, t) } , token{ t } , ignore_case{ ignore_case_ }{ -#line 2664 "reflect.h2" +#line 2665 "reflect.h2" } -#line 2666 "reflect.h2" +#line 2667 "reflect.h2" [[nodiscard]] auto char_token::parse(parse_context& ctx) -> token_ptr{ return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, ctx.current(), ctx.get_modifiers().has(expression_flags::case_insensitive)); } -#line 2670 "reflect.h2" +#line 2671 "reflect.h2" auto char_token::generate_code(generation_context& ctx) const -> void { if (ignore_case) { @@ -4404,14 +4408,14 @@ generation_function_context::generation_function_context(){} { size_t i{0}; -#line 2676 "reflect.h2" +#line 2677 "reflect.h2" for( ; cpp2::impl::cmp_less(i,token.size()); i += 1 ) { CPP2_ASSERT_IN_BOUNDS(lower, i) = string_util::safe_tolower(CPP2_ASSERT_IN_BOUNDS(token, i)); CPP2_ASSERT_IN_BOUNDS(upper, i) = string_util::safe_toupper(CPP2_ASSERT_IN_BOUNDS(token, i)); } } -#line 2681 "reflect.h2" +#line 2682 "reflect.h2" if (upper != lower) { gen_case_insensitive(cpp2::move(lower), cpp2::move(upper), ctx); } @@ -4424,7 +4428,7 @@ size_t i{0}; } } -#line 2693 "reflect.h2" +#line 2694 "reflect.h2" auto char_token::gen_case_insensitive(cpp2::impl::in lower, cpp2::impl::in upper, generation_context& ctx) const& -> void { std::string name {"str_" + cpp2::to_string(ctx.gen_temp()) + ""}; @@ -4446,7 +4450,7 @@ size_t i{0}; ctx.add("else { break; }"); } -#line 2714 "reflect.h2" +#line 2715 "reflect.h2" auto char_token::gen_case_sensitive(generation_context& ctx) const& -> void { std::string name {"str_" + cpp2::to_string(ctx.gen_temp()) + ""}; @@ -4465,7 +4469,7 @@ size_t i{0}; ctx.add("else { break; }"); } -#line 2732 "reflect.h2" +#line 2733 "reflect.h2" [[nodiscard]] auto char_token::add_escapes(std::string str) const& -> std::string { str = string_util::replace_all(str, "\\", "\\\\"); @@ -4481,7 +4485,7 @@ size_t i{0}; return cpp2::move(str); } -#line 2747 "reflect.h2" +#line 2748 "reflect.h2" auto char_token::append(char_token const& that) & -> void{ (*this).token += that.token; (*this).string_rep += that.string_rep; @@ -4489,19 +4493,19 @@ size_t i{0}; char_token::~char_token() noexcept{} -#line 2764 "reflect.h2" +#line 2765 "reflect.h2" class_token::class_token(cpp2::impl::in negate_, cpp2::impl::in case_insensitive_, cpp2::impl::in class_str_, cpp2::impl::in str) : regex_token{ str } , negate{ negate_ } , case_insensitive{ case_insensitive_ } , class_str{ class_str_ } -#line 2765 "reflect.h2" +#line 2766 "reflect.h2" { -#line 2770 "reflect.h2" +#line 2771 "reflect.h2" } -#line 2773 "reflect.h2" +#line 2774 "reflect.h2" [[nodiscard]] auto class_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '[') {return nullptr; } @@ -4627,13 +4631,13 @@ size_t i{0}; ); } -#line 2898 "reflect.h2" +#line 2899 "reflect.h2" auto class_token::generate_code(generation_context& ctx) const -> void { ctx.add_check("class_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ")"); } -#line 2903 "reflect.h2" +#line 2904 "reflect.h2" [[nodiscard]] auto class_token::create_matcher(cpp2::impl::in name, cpp2::impl::in template_arguments) -> std::string { auto sep {", "}; @@ -4644,12 +4648,12 @@ size_t i{0}; class_token::~class_token() noexcept{} -#line 2915 "reflect.h2" +#line 2916 "reflect.h2" [[nodiscard]] auto escape_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } -#line 2920 "reflect.h2" +#line 2921 "reflect.h2" if (std::string::npos == std::string("afenrt^.[]()*{}?+|\\").find(ctx.peek())) { return nullptr; } @@ -4683,7 +4687,7 @@ size_t i{0}; } -#line 2956 "reflect.h2" +#line 2957 "reflect.h2" [[nodiscard]] auto global_group_reset_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'K'))) {return nullptr; } @@ -4692,18 +4696,18 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, "\\K", "ctx..set_group_start(0, r.pos);"); } -#line 2978 "reflect.h2" +#line 2979 "reflect.h2" group_ref_token::group_ref_token(cpp2::impl::in id_, cpp2::impl::in case_insensitive_, cpp2::impl::in str) : regex_token{ str } , id{ id_ } , case_insensitive{ case_insensitive_ } -#line 2979 "reflect.h2" +#line 2980 "reflect.h2" { -#line 2983 "reflect.h2" +#line 2984 "reflect.h2" } -#line 2985 "reflect.h2" +#line 2986 "reflect.h2" [[nodiscard]] auto group_ref_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -4805,14 +4809,14 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, cpp2::move(group_id), ctx.get_modifiers().has(expression_flags::case_insensitive), cpp2::move(str)); } -#line 3086 "reflect.h2" +#line 3087 "reflect.h2" auto group_ref_token::generate_code(generation_context& ctx) const -> void{ ctx.add_check("group_ref_token_matcher(" + cpp2::to_string(ctx.match_parameters()) + ")"); } group_ref_token::~group_ref_token() noexcept{} -#line 3109 "reflect.h2" +#line 3110 "reflect.h2" [[nodiscard]] auto group_token::parse_lookahead(parse_context& ctx, cpp2::impl::in syntax, cpp2::impl::in positive) -> token_ptr { static_cast(ctx.next());// Skip last token defining the syntax @@ -4827,7 +4831,7 @@ size_t i{0}; return r; } -#line 3123 "reflect.h2" +#line 3124 "reflect.h2" [[nodiscard]] auto group_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '(') {return nullptr; } @@ -4965,7 +4969,7 @@ size_t i{0}; } } -#line 3260 "reflect.h2" +#line 3261 "reflect.h2" [[nodiscard]] auto group_token::gen_string(cpp2::impl::in name, cpp2::impl::in name_brackets, cpp2::impl::in has_modifier, cpp2::impl::in modifiers, cpp2::impl::in inner_) -> std::string { std::string start {"("}; @@ -4984,7 +4988,7 @@ size_t i{0}; return cpp2::move(start) + (*cpp2::impl::assert_not_null(inner_)).to_string() + ")"; } -#line 3278 "reflect.h2" +#line 3279 "reflect.h2" auto group_token::generate_code(generation_context& ctx) const -> void { if (-1 != number) { @@ -5005,7 +5009,7 @@ size_t i{0}; } } -#line 3298 "reflect.h2" +#line 3299 "reflect.h2" auto group_token::add_groups(std::set& groups) const -> void { (*cpp2::impl::assert_not_null(inner)).add_groups(groups); @@ -5016,7 +5020,7 @@ size_t i{0}; group_token::~group_token() noexcept{} -#line 3310 "reflect.h2" +#line 3311 "reflect.h2" [[nodiscard]] auto hexadecimal_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'x'))) {return nullptr; } @@ -5055,7 +5059,7 @@ size_t i{0}; return r; } -#line 3351 "reflect.h2" +#line 3352 "reflect.h2" [[nodiscard]] auto line_end_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() == '$' || (ctx.current() == '\\' && ctx.peek() == '$')) { @@ -5073,7 +5077,7 @@ size_t i{0}; }} } -#line 3371 "reflect.h2" +#line 3372 "reflect.h2" [[nodiscard]] auto line_start_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '^' && !((ctx.current() == '\\' && ctx.peek() == 'A'))) {return nullptr; } @@ -5087,29 +5091,29 @@ size_t i{0}; } } -#line 3396 "reflect.h2" +#line 3397 "reflect.h2" lookahead_token::lookahead_token(cpp2::impl::in positive_) : regex_token{ "" } , positive{ positive_ }{ -#line 3398 "reflect.h2" +#line 3399 "reflect.h2" } -#line 3400 "reflect.h2" +#line 3401 "reflect.h2" auto lookahead_token::generate_code(generation_context& ctx) const -> void{ auto inner_name {ctx.generate_func(inner)}; ctx.add_check("lookahead_token_matcher(" + cpp2::to_string(ctx.match_parameters()) + ", " + cpp2::to_string(cpp2::move(inner_name)) + ")"); } -#line 3406 "reflect.h2" +#line 3407 "reflect.h2" auto lookahead_token::add_groups(std::set& groups) const -> void{ (*cpp2::impl::assert_not_null(inner)).add_groups(groups); } lookahead_token::~lookahead_token() noexcept{} -#line 3414 "reflect.h2" +#line 3415 "reflect.h2" [[nodiscard]] auto named_class_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -5135,7 +5139,7 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, "\\" + cpp2::to_string(ctx.current()) + "", "" + cpp2::to_string(cpp2::move(name)) + "::match"); } -#line 3442 "reflect.h2" +#line 3443 "reflect.h2" [[nodiscard]] auto octal_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'o'))) {return nullptr; } @@ -5161,11 +5165,11 @@ size_t i{0}; return r; } -#line 3479 "reflect.h2" +#line 3480 "reflect.h2" range_token::range_token() : regex_token{ "" }{} -#line 3481 "reflect.h2" +#line 3482 "reflect.h2" [[nodiscard]] auto range_token::parse(parse_context& ctx) -> token_ptr { auto r {CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared)}; @@ -5239,7 +5243,7 @@ size_t i{0}; return nullptr; } -#line 3554 "reflect.h2" +#line 3555 "reflect.h2" auto range_token::parse_modifier(parse_context& ctx) & -> void { if (ctx.peek() == '?') { @@ -5252,7 +5256,7 @@ size_t i{0}; }} } -#line 3566 "reflect.h2" +#line 3567 "reflect.h2" [[nodiscard]] auto range_token::gen_mod_string() const& -> std::string { if (kind == range_flags::not_greedy) { @@ -5266,7 +5270,7 @@ size_t i{0}; }} } -#line 3579 "reflect.h2" +#line 3580 "reflect.h2" [[nodiscard]] auto range_token::gen_range_string() const& -> std::string { std::string r {""}; @@ -5286,7 +5290,7 @@ size_t i{0}; return r; } -#line 3598 "reflect.h2" +#line 3599 "reflect.h2" auto range_token::generate_code(generation_context& ctx) const -> void { auto inner_name {ctx.generate_func(inner_token)}; @@ -5298,14 +5302,14 @@ size_t i{0}; ctx.add_statefull(next_name, "cpp2::regex::range_token_matcher::match(" + cpp2::to_string(ctx.match_parameters()) + ", " + cpp2::to_string(cpp2::move(inner_name)) + ", " + cpp2::to_string(cpp2::move(reset_name)) + ", other, " + cpp2::to_string(next_name) + ")"); } -#line 3609 "reflect.h2" +#line 3610 "reflect.h2" auto range_token::add_groups(std::set& groups) const -> void{ (*cpp2::impl::assert_not_null(inner_token)).add_groups(groups); } range_token::~range_token() noexcept{} -#line 3622 "reflect.h2" +#line 3623 "reflect.h2" [[nodiscard]] auto special_range_token::parse(parse_context& ctx) -> token_ptr { auto r {CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared)}; @@ -5329,7 +5333,7 @@ size_t i{0}; if (!(ctx.has_token())) {return ctx.error("'" + cpp2::to_string(ctx.current()) + "' without previous element."); } -#line 3646 "reflect.h2" +#line 3647 "reflect.h2" (*cpp2::impl::assert_not_null(r)).parse_modifier(ctx); (*cpp2::impl::assert_not_null(r)).inner_token = ctx.pop_token(); @@ -5339,7 +5343,7 @@ size_t i{0}; special_range_token::~special_range_token() noexcept{} -#line 3659 "reflect.h2" +#line 3660 "reflect.h2" [[nodiscard]] auto word_boundary_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -5357,15 +5361,15 @@ size_t i{0}; }} } -#line 3695 "reflect.h2" +#line 3696 "reflect.h2" template regex_generator::regex_generator(cpp2::impl::in r, Error_out const& e) : regex{ r } , error_out{ e }{ -#line 3698 "reflect.h2" +#line 3699 "reflect.h2" } -#line 3700 "reflect.h2" +#line 3701 "reflect.h2" template [[nodiscard]] auto regex_generator::parse() & -> std::string { // Extract modifiers and adapt regex. @@ -5401,7 +5405,7 @@ size_t i{0}; return source; } -#line 3735 "reflect.h2" +#line 3736 "reflect.h2" template auto regex_generator::extract_modifiers() & -> void { if (regex.find_first_of("'/") == 0) { @@ -5417,7 +5421,7 @@ size_t i{0}; } } -#line 3751 "reflect.h2" +#line 3752 "reflect.h2" template [[nodiscard]] auto generate_regex(cpp2::impl::in regex, Err const& err) -> std::string { regex_generator parser {regex, err}; @@ -5426,7 +5430,7 @@ template [[nodiscard]] auto generate_regex(cpp2::impl::in void { auto has_default {false}; @@ -5481,11 +5485,12 @@ auto regex_gen(meta::type_declaration& t) -> void CPP2_UFCS(add_runtime_support_include)(t, "cpp2regex.h"); } -#line 3820 "reflect.h2" +#line 3821 "reflect.h2" [[nodiscard]] auto apply_metafunctions( declaration_node& n, type_declaration_impl& rtypeimpl, - auto const& error + auto const& error, + auto const& libraries_try_apply ) -> bool { @@ -5577,6 +5582,7 @@ auto regex_gen(meta::type_declaration& t) -> void else {if (name == "_internal_foreign_interface_pseudovalue") { foreign_interface_pseudovalue(rtype); } + else {if (libraries_try_apply(CPP2_UFCS(fully_qualified_name)(n), name, rtype)) {} else { error("unrecognized metafunction name: '" + cpp2::move(name) + "' for type declaration"); error( @@ -5586,7 +5592,7 @@ auto regex_gen(meta::type_declaration& t) -> void "struct, enum, flag_enum, union, cpp1_rule_of_zero, regex, print" ); return false; - }}}}}}}}}}}}}}}}}} + }}}}}}}}}}}}}}}}}}} static_cast(cpp2::move(rtype)); @@ -5603,11 +5609,12 @@ auto regex_gen(meta::type_declaration& t) -> void return true; } -#line 3946 "reflect.h2" +#line 3949 "reflect.h2" [[nodiscard]] auto apply_metafunctions( declaration_node& n, function_declaration_impl& rfuncimpl, - auto const& error + auto const& error, + auto const& libraries_try_apply ) -> bool { @@ -5639,11 +5646,12 @@ auto regex_gen(meta::type_declaration& t) -> void else {if (name == "print") { print(rfunc); } + else {if (libraries_try_apply(CPP2_UFCS(fully_qualified_name)(n), name, rfunc)) {} else { error("unrecognized metafunction name '" + cpp2::move(name) + "' for function declaration"); error("(temporary alpha limitation) currently the supported names are: meta, print"); return false; - }} + }}} static_cast(cpp2::move(rfunc)); @@ -5660,7 +5668,7 @@ auto regex_gen(meta::type_declaration& t) -> void return true; } -#line 4003 "reflect.h2" +#line 4008 "reflect.h2" } } diff --git a/source/reflect.h2 b/source/reflect.h2 index 15a8f0876..acad83b41 100644 --- a/source/reflect.h2 +++ b/source/reflect.h2 @@ -50,6 +50,7 @@ compiler_services_base: @polymorphic_base @copyable type = // operator=: ( out this, + libraries : *reflect_libraries, errors_ : *std::vector, includes_ : *std::set, generated_tokens_ : *stable_vector, @@ -61,7 +62,7 @@ compiler_services_base: @polymorphic_base @copyable type = errors_original_size = cpp2::unsafe_narrow(std::ssize(errors*)); generated_tokens = generated_tokens_; generated_declarations = generated_declarations_; - parser = (errors*, includes*); + parser = (libraries*, errors*, includes*); } set_metafunction_name: (inout this, name: std::string_view, args: std::vector) = { @@ -3820,7 +3821,8 @@ regex_gen: (inout t: meta::type_declaration) = apply_metafunctions: ( inout n : declaration_node, inout rtypeimpl : type_declaration_impl, - error + error, + libraries_try_apply, ) -> bool = { @@ -3912,6 +3914,7 @@ apply_metafunctions: ( else if name == "_internal_foreign_interface_pseudovalue" { foreign_interface_pseudovalue( rtype ); } + else if libraries_try_apply(n.fully_qualified_name(), name, rtype) {} else { error( "unrecognized metafunction name: '" + name + "' for type declaration" ); error( @@ -3946,7 +3949,8 @@ apply_metafunctions: ( apply_metafunctions: ( inout n : declaration_node, inout rfuncimpl : function_declaration_impl, - error + error, + libraries_try_apply, ) -> bool = { @@ -3978,6 +3982,7 @@ apply_metafunctions: ( else if name == "print" { print( rfunc ); } + else if libraries_try_apply(n.fully_qualified_name(), name, rfunc) {} else { error( "unrecognized metafunction name '" + name + "' for function declaration" ); error( "(temporary alpha limitation) currently the supported names are: meta, print" ); diff --git a/source/sema.h b/source/sema.h index 08bb94b13..ee91948cb 100644 --- a/source/sema.h +++ b/source/sema.h @@ -19,23 +19,126 @@ #define CPP2_SEMA_H #include "reflect.h" +#include "dll.h" namespace cpp2 { +static reflect_libraries* active_instance = nullptr; + +class reflect_libraries +{ + std::vector& errors; + std::string in_progress = {}; + std::vector loaded = {}; + + struct function_entry + { + std::variant< + std::monostate, + meta::mf_sign_type_in*, + meta::mf_sign_type_inout* + > type = {}; + std::variant< + std::monostate, + meta::mf_sign_func_in*, + meta::mf_sign_func_inout* + > func = {}; + }; + + std::map functions = {}; + +public: + reflect_libraries(std::vector& errors_) + : errors{ errors_ } + { } + + void load(std::string_view lib) { + active_instance = this; + in_progress = lib; + finally _{ [&](){ active_instance = nullptr; in_progress = ""; } }; + auto& dl = loaded.emplace_back(in_progress); + if(!dl.is_open()) { + errors.emplace_back( + source_position(-1, -1), + "unable to load library '" + in_progress + "': " + dll::get_last_error() + ); + } + } + + bool try_apply( + [[maybe_unused]] std::string_view caller, + std::string const& name, + auto& decl + ) const { + // TODO(DyXel): Do full/better name look-up. + auto search = functions.find(name); + if(search == functions.end()) return false; + auto& entry = search->second; + auto visitor = [&](auto&& v) -> bool { + if constexpr(requires { v(decl); }) { + v(decl); + return true; + } + return false; + }; + if constexpr(std::is_same_v) + return std::visit(visitor, entry.type); + else + return std::visit(visitor, entry.func); + } + +private: + friend meta::register_metafunction; + + void register_one(std::string name, auto* func) { + // TODO(DyXel): Check if already registered + auto& entry = functions[name]; + if constexpr(requires { entry.type = func; }) + entry.type = func; + else + entry.func = func; + } +}; + +namespace meta { + +register_metafunction::register_metafunction(const char* name, mf_sign_type_in* f) { + active_instance->register_one(name, f); +} + +register_metafunction::register_metafunction(const char* name, mf_sign_type_inout* f) { + active_instance->register_one(name, f); +} + +register_metafunction::register_metafunction(const char* name, mf_sign_func_in* f) { + active_instance->register_one(name, f); +} + +register_metafunction::register_metafunction(const char* name, mf_sign_func_inout* f) { + active_instance->register_one(name, f); +} + +} // namespace meta + auto parser::apply_type_metafunctions( declaration_node& n ) -> bool { assert(n.is_type()); // Get the reflection state ready to pass to the function - auto csb = meta::compiler_services_base{ &errors, &includes, generated_tokens, &generated_declarations }; + auto csb = meta::compiler_services_base{ &libraries, &errors, &includes, generated_tokens, &generated_declarations }; auto rtypeimpl = meta::type_declaration_impl{ csb, &n }; return apply_metafunctions( n, rtypeimpl, - [&](std::string const& msg) { error( msg, false ); } + [&](std::string const& msg) { error( msg, false ); }, + [&]( + std::string_view caller, + std::string const& name, + meta::type_declaration& decl + ) -> bool { return libraries.try_apply(caller, name, decl); } ); } @@ -45,13 +148,18 @@ auto parser::apply_function_metafunctions( declaration_node& n ) assert(n.is_function()); // Get the reflection state ready to pass to the function - auto csb = meta::compiler_services_base{ &errors, &includes, generated_tokens, &generated_declarations }; + auto csb = meta::compiler_services_base{ &libraries, &errors, &includes, generated_tokens, &generated_declarations }; auto rfuncimpl = meta::function_declaration_impl{ csb, &n }; return apply_metafunctions( n, rfuncimpl, - [&](std::string const& msg) { error( msg, false ); } + [&](std::string const& msg) { error( msg, false ); }, + [&]( + std::string_view caller, + std::string const& name, + meta::function_declaration& decl + ) -> bool { return libraries.try_apply(caller, name, decl); } ); } diff --git a/source/to_cpp1.h b/source/to_cpp1.h index 569198e29..a595aa4ec 100644 --- a/source/to_cpp1.h +++ b/source/to_cpp1.h @@ -1012,8 +1012,9 @@ struct function_prolog { class cppfront { - std::string sourcefile; std::vector errors; + reflect_libraries libraries; + std::string sourcefile; std::set includes; // For building @@ -1164,16 +1165,38 @@ class cppfront // filename the source file to be processed // cppfront(std::string const& filename) - : sourcefile{ filename } + : libraries { errors } + , sourcefile{ filename } , source { errors } , tokens { errors } - , parser { errors, includes } + , parser { libraries, errors, includes } , sema { errors } { + // Load metafunction libraries, if any. + // + if(auto* envvar = std::getenv("CPPFRONT_METAFUNCTION_LIBRARIES"); envvar) { + auto lib_paths = std::string_view{envvar}; + while(!lib_paths.empty()) { + auto colon = lib_paths.find(':'); + auto lp = lib_paths.substr(0, colon); + lib_paths.remove_prefix(lp.size() + size_t{colon != lp.npos}); + + libraries.load(lp); + } + } + + if (!errors.empty()) + { + errors.emplace_back( + source_position(-1, -1), + "could not load one or more libraries" + ); + } + // "Constraints enable creativity in the right directions" // sort of applies here // - if ( + else if ( !sourcefile.ends_with(".cpp2") && !sourcefile.ends_with(".h2") )