diff --git a/source/reflect.h b/source/reflect.h index b142219ab..e18339eae 100644 --- a/source/reflect.h +++ b/source/reflect.h @@ -63,77 +63,77 @@ class expression; #line 1395 "reflect.h2" class value_member_info; -#line 2267 "reflect.h2" +#line 2287 "reflect.h2" class expression_flags; -#line 2283 "reflect.h2" +#line 2303 "reflect.h2" class regex_token; -#line 2310 "reflect.h2" +#line 2330 "reflect.h2" class regex_token_check; -#line 2331 "reflect.h2" +#line 2351 "reflect.h2" class regex_token_code; -#line 2352 "reflect.h2" +#line 2372 "reflect.h2" class regex_token_empty; -#line 2370 "reflect.h2" +#line 2390 "reflect.h2" class regex_token_list; -#line 2422 "reflect.h2" +#line 2442 "reflect.h2" class parse_context_group_state; -#line 2483 "reflect.h2" +#line 2503 "reflect.h2" class parse_context_branch_reset_state; -#line 2526 "reflect.h2" +#line 2546 "reflect.h2" class parse_context; -#line 2927 "reflect.h2" +#line 2947 "reflect.h2" class generation_function_context; -#line 2945 "reflect.h2" +#line 2965 "reflect.h2" class generation_context; -#line 3144 "reflect.h2" +#line 3164 "reflect.h2" class alternative_token; -#line 3159 "reflect.h2" +#line 3179 "reflect.h2" class alternative_token_gen; -#line 3224 "reflect.h2" +#line 3244 "reflect.h2" class any_token; -#line 3241 "reflect.h2" +#line 3261 "reflect.h2" class atomic_group_token; -#line 3271 "reflect.h2" +#line 3291 "reflect.h2" class char_token; -#line 3386 "reflect.h2" +#line 3406 "reflect.h2" class class_token; -#line 3610 "reflect.h2" +#line 3630 "reflect.h2" class group_ref_token; -#line 3747 "reflect.h2" +#line 3767 "reflect.h2" class group_token; -#line 4094 "reflect.h2" +#line 4114 "reflect.h2" class lookahead_lookbehind_token; -#line 4189 "reflect.h2" +#line 4209 "reflect.h2" class range_token; -#line 4346 "reflect.h2" +#line 4366 "reflect.h2" class special_range_token; -#line 4432 "reflect.h2" +#line 4452 "reflect.h2" template class regex_generator; -#line 4683 "reflect.h2" +#line 4703 "reflect.h2" } } @@ -819,10 +819,10 @@ auto noisy(cpp2::impl::in t) -> void; #line 1921 "reflect.h2" auto autodiff(meta::type_declaration& t) -> void; -#line 2263 "reflect.h2" +#line 2283 "reflect.h2" using error_func = std::function x)>; -#line 2267 "reflect.h2" +#line 2287 "reflect.h2" class expression_flags { private: cpp2::u8 _value; private: constexpr expression_flags(cpp2::impl::in _val); @@ -857,20 +857,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 2275 "reflect.h2" +#line 2295 "reflect.h2" }; -#line 2283 "reflect.h2" +#line 2303 "reflect.h2" class regex_token { public: std::string string_rep; public: regex_token(cpp2::impl::in str); -#line 2291 "reflect.h2" +#line 2311 "reflect.h2" public: explicit regex_token(); -#line 2296 "reflect.h2" +#line 2316 "reflect.h2" public: virtual auto generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void = 0; public: [[nodiscard]] virtual auto reverse() const -> std::shared_ptr = 0; @@ -882,103 +882,103 @@ class regex_token public: regex_token(regex_token const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(regex_token const&) -> void = delete; -#line 2302 "reflect.h2" +#line 2322 "reflect.h2" }; using token_ptr = std::shared_ptr; using token_vec = std::vector; -#line 2308 "reflect.h2" +#line 2328 "reflect.h2" // Adds a check in code generation. // class regex_token_check : public regex_token { -#line 2314 "reflect.h2" +#line 2334 "reflect.h2" private: std::string check; public: regex_token_check(cpp2::impl::in str, cpp2::impl::in check_); -#line 2321 "reflect.h2" +#line 2341 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2325 "reflect.h2" +#line 2345 "reflect.h2" public: [[nodiscard]] auto reverse() const -> token_ptr override; public: virtual ~regex_token_check() noexcept; public: regex_token_check(regex_token_check const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(regex_token_check const&) -> void = delete; -#line 2326 "reflect.h2" +#line 2346 "reflect.h2" }; -#line 2329 "reflect.h2" +#line 2349 "reflect.h2" // Adds code in code generation. // class regex_token_code : public regex_token { -#line 2335 "reflect.h2" +#line 2355 "reflect.h2" private: std::string code; public: regex_token_code(cpp2::impl::in str, cpp2::impl::in code_); -#line 2342 "reflect.h2" +#line 2362 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2346 "reflect.h2" +#line 2366 "reflect.h2" public: [[nodiscard]] auto reverse() const -> token_ptr override; public: virtual ~regex_token_code() noexcept; public: regex_token_code(regex_token_code const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(regex_token_code const&) -> void = delete; -#line 2347 "reflect.h2" +#line 2367 "reflect.h2" }; -#line 2350 "reflect.h2" +#line 2370 "reflect.h2" // Token that does not influence the matching. E.g. comment. // class regex_token_empty : public regex_token { -#line 2356 "reflect.h2" +#line 2376 "reflect.h2" public: regex_token_empty(cpp2::impl::in str); -#line 2360 "reflect.h2" +#line 2380 "reflect.h2" public: auto generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void override; -#line 2364 "reflect.h2" +#line 2384 "reflect.h2" public: [[nodiscard]] auto reverse() const -> token_ptr override; public: virtual ~regex_token_empty() noexcept; public: regex_token_empty(regex_token_empty const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(regex_token_empty const&) -> void = delete; -#line 2365 "reflect.h2" +#line 2385 "reflect.h2" }; -#line 2368 "reflect.h2" +#line 2388 "reflect.h2" // Represents a list of regex tokens as one token. // class regex_token_list : public regex_token { -#line 2374 "reflect.h2" +#line 2394 "reflect.h2" public: token_vec tokens; public: regex_token_list(cpp2::impl::in t); -#line 2381 "reflect.h2" +#line 2401 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 2387 "reflect.h2" +#line 2407 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; -#line 2393 "reflect.h2" +#line 2413 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in vec) -> std::string; -#line 2401 "reflect.h2" +#line 2421 "reflect.h2" public: [[nodiscard]] auto reverse() const -> token_ptr override; public: virtual ~regex_token_list() noexcept; @@ -986,10 +986,10 @@ class regex_token_list public: auto operator=(regex_token_list const&) -> void = delete; -#line 2413 "reflect.h2" +#line 2433 "reflect.h2" }; -#line 2416 "reflect.h2" +#line 2436 "reflect.h2" // // Parse and generation context. // @@ -1005,33 +1005,33 @@ class parse_context_group_state // Start a new alternative. public: auto next_alternative() & -> void; -#line 2436 "reflect.h2" +#line 2456 "reflect.h2" // Swap this state with the other one. NOLINTNEXTLINE(performance-noexcept-swap) public: auto swap(parse_context_group_state& t) & -> void; -#line 2443 "reflect.h2" +#line 2463 "reflect.h2" // Convert this state into a regex token. public: [[nodiscard]] auto get_as_token() & -> token_ptr; -#line 2455 "reflect.h2" +#line 2475 "reflect.h2" // Add a token to the current matcher list. public: auto add(cpp2::impl::in token) & -> void; -#line 2460 "reflect.h2" +#line 2480 "reflect.h2" // True if current matcher list is empty. public: [[nodiscard]] auto empty() const& -> bool; -#line 2464 "reflect.h2" +#line 2484 "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 2478 "reflect.h2" +#line 2498 "reflect.h2" }; -#line 2481 "reflect.h2" +#line 2501 "reflect.h2" // State for the branch reset. Takes care of the group numbering. See '(|)'. // class parse_context_branch_reset_state @@ -1044,25 +1044,25 @@ class parse_context_branch_reset_state // Next group identifier. public: [[nodiscard]] auto next() & -> int; -#line 2499 "reflect.h2" +#line 2519 "reflect.h2" // Set next group identifier. public: auto set_next(cpp2::impl::in g) & -> void; -#line 2505 "reflect.h2" +#line 2525 "reflect.h2" // Start a new alternative branch. public: auto next_alternative() & -> void; -#line 2512 "reflect.h2" +#line 2532 "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 2519 "reflect.h2" +#line 2539 "reflect.h2" }; -#line 2522 "reflect.h2" +#line 2542 "reflect.h2" // Context during parsing of the regular expressions. // // Keeps track of the distributed group identifiers, current parsed group and branch resets. @@ -1078,7 +1078,7 @@ class parse_context private: parse_context_group_state cur_group_state {}; private: parse_context_branch_reset_state cur_branch_reset_state {}; -#line 2538 "reflect.h2" +#line 2558 "reflect.h2" public: std::map named_groups {}; private: error_func error_out; // TODO: Declaring std::function fails for cpp2. @@ -1086,64 +1086,64 @@ class parse_context public: parse_context(cpp2::impl::in r, auto const& e); -#line 2549 "reflect.h2" +#line 2569 "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 2562 "reflect.h2" +#line 2582 "reflect.h2" // `old_state` argument needs to be from start group. public: [[nodiscard]] auto end_group(cpp2::impl::in old_state) & -> token_ptr; -#line 2570 "reflect.h2" +#line 2590 "reflect.h2" public: [[nodiscard]] auto get_modifiers() const& -> expression_flags; -#line 2574 "reflect.h2" +#line 2594 "reflect.h2" public: auto set_modifiers(cpp2::impl::in mod) & -> void; -#line 2578 "reflect.h2" +#line 2598 "reflect.h2" // Branch reset management functions // public: [[nodiscard]] auto branch_reset_new_state() & -> parse_context_branch_reset_state; -#line 2590 "reflect.h2" +#line 2610 "reflect.h2" public: auto branch_reset_restore_state(cpp2::impl::in old_state) & -> void; -#line 2597 "reflect.h2" +#line 2617 "reflect.h2" public: auto next_alternative() & -> void; -#line 2603 "reflect.h2" +#line 2623 "reflect.h2" // Regex token management // public: auto add_token(cpp2::impl::in token) & -> void; -#line 2609 "reflect.h2" +#line 2629 "reflect.h2" public: [[nodiscard]] auto has_token() const& -> bool; -#line 2613 "reflect.h2" +#line 2633 "reflect.h2" public: [[nodiscard]] auto pop_token() & -> token_ptr; -#line 2624 "reflect.h2" +#line 2644 "reflect.h2" public: [[nodiscard]] auto get_as_token() & -> token_ptr; -#line 2628 "reflect.h2" +#line 2648 "reflect.h2" // Group management // public: [[nodiscard]] auto get_cur_group() const& -> int; -#line 2634 "reflect.h2" +#line 2654 "reflect.h2" public: [[nodiscard]] auto next_group() & -> int; -#line 2638 "reflect.h2" +#line 2658 "reflect.h2" public: auto set_named_group(cpp2::impl::in name, cpp2::impl::in id) & -> void; -#line 2645 "reflect.h2" +#line 2665 "reflect.h2" public: [[nodiscard]] auto get_named_group(cpp2::impl::in name) const& -> int; -#line 2656 "reflect.h2" +#line 2676 "reflect.h2" // Position management functions // public: [[nodiscard]] auto current() const& -> char; @@ -1151,51 +1151,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 2700 "reflect.h2" +#line 2720 "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 2712 "reflect.h2" +#line 2732 "reflect.h2" public: [[nodiscard]] auto next() & -> decltype(auto); public: [[nodiscard]] auto next_in_class() & -> decltype(auto); public: [[nodiscard]] auto next_no_skip() & -> decltype(auto); public: [[nodiscard]] auto next_n(cpp2::impl::in n) & -> bool; -#line 2725 "reflect.h2" +#line 2745 "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 2748 "reflect.h2" +#line 2768 "reflect.h2" public: [[nodiscard]] auto grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> decltype(auto); public: [[nodiscard]] auto grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> decltype(auto); public: [[nodiscard]] auto grab_until_one_of(cpp2::impl::in e, cpp2::impl::out r) & -> decltype(auto); public: [[nodiscard]] auto grab_n(cpp2::impl::in n, cpp2::impl::out r) & -> bool; -#line 2765 "reflect.h2" +#line 2785 "reflect.h2" public: [[nodiscard]] auto grab_number() & -> std::string; -#line 2786 "reflect.h2" +#line 2806 "reflect.h2" private: [[nodiscard]] auto peek_impl(cpp2::impl::in in_class) const& -> char; -#line 2796 "reflect.h2" +#line 2816 "reflect.h2" public: [[nodiscard]] auto peek() const& -> decltype(auto); public: [[nodiscard]] auto peek_in_class() const& -> decltype(auto); -#line 2800 "reflect.h2" +#line 2820 "reflect.h2" // Parsing functions // public: [[nodiscard]] auto parser_group_modifiers(cpp2::impl::in change_str, expression_flags& parser_modifiers) & -> bool; -#line 2856 "reflect.h2" +#line 2876 "reflect.h2" public: [[nodiscard]] auto parse_until(cpp2::impl::in term) & -> bool; -#line 2895 "reflect.h2" +#line 2915 "reflect.h2" public: [[nodiscard]] auto parse(cpp2::impl::in modifiers) & -> bool; -#line 2910 "reflect.h2" +#line 2930 "reflect.h2" // Misc functions public: [[nodiscard]] auto get_pos() const& -> decltype(auto); @@ -1207,10 +1207,10 @@ class parse_context public: auto operator=(parse_context const&) -> void = delete; -#line 2921 "reflect.h2" +#line 2941 "reflect.h2" }; -#line 2924 "reflect.h2" +#line 2944 "reflect.h2" // Context for one function generation. Generation of functions can be interleaved, // therefore we buffer the code for one function here. // @@ -1220,16 +1220,16 @@ class generation_function_context { public: auto add_tabs(cpp2::impl::in c) & -> void; -#line 2938 "reflect.h2" +#line 2958 "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 2941 "reflect.h2" +#line 2961 "reflect.h2" }; -#line 2944 "reflect.h2" +#line 2964 "reflect.h2" // Context for generating the state machine. class generation_context { @@ -1249,68 +1249,68 @@ class generation_context // Add code line. public: auto add(cpp2::impl::in s) & -> void; -#line 2966 "reflect.h2" +#line 2986 "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 2972 "reflect.h2" +#line 2992 "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 2981 "reflect.h2" +#line 3001 "reflect.h2" protected: auto start_func_named(cpp2::impl::in name) & -> void; -#line 2992 "reflect.h2" +#line 3012 "reflect.h2" protected: [[nodiscard]] auto start_func() & -> std::string; -#line 2999 "reflect.h2" +#line 3019 "reflect.h2" protected: auto end_func_statefull(cpp2::impl::in s) & -> void; -#line 3019 "reflect.h2" +#line 3039 "reflect.h2" // Generate the function for a token. public: [[nodiscard]] auto generate_func(cpp2::impl::in token) & -> std::string; -#line 3029 "reflect.h2" +#line 3049 "reflect.h2" // Generate the reset for a list of group identifiers. public: [[nodiscard]] auto generate_reset(cpp2::impl::in> groups) & -> std::string; -#line 3052 "reflect.h2" +#line 3072 "reflect.h2" // Name generation // protected: [[nodiscard]] auto gen_func_name() & -> std::string; -#line 3060 "reflect.h2" +#line 3080 "reflect.h2" public: [[nodiscard]] auto next_func_name() & -> std::string; -#line 3064 "reflect.h2" +#line 3084 "reflect.h2" protected: [[nodiscard]] auto gen_reset_func_name() & -> std::string; -#line 3070 "reflect.h2" +#line 3090 "reflect.h2" public: [[nodiscard]] auto gen_temp() & -> std::string; -#line 3076 "reflect.h2" +#line 3096 "reflect.h2" // Context management // public: [[nodiscard]] auto new_context() & -> generation_function_context*; -#line 3086 "reflect.h2" +#line 3106 "reflect.h2" public: auto finish_context() & -> void; -#line 3094 "reflect.h2" +#line 3114 "reflect.h2" // Misc functions // private: [[nodiscard]] auto get_current() & -> generation_function_context*; -#line 3100 "reflect.h2" +#line 3120 "reflect.h2" private: [[nodiscard]] auto get_base() & -> generation_function_context*; -#line 3104 "reflect.h2" +#line 3124 "reflect.h2" public: [[nodiscard]] auto get_entry_func() const& -> std::string; -#line 3108 "reflect.h2" +#line 3128 "reflect.h2" public: [[nodiscard]] auto create_named_group_lookup(cpp2::impl::in> named_groups) const& -> std::string; -#line 3132 "reflect.h2" +#line 3152 "reflect.h2" // Run the generation for the token. public: [[nodiscard]] auto run(cpp2::impl::in token) & -> std::string; public: generation_context() = default; @@ -1318,7 +1318,7 @@ class generation_context public: auto operator=(generation_context const&) -> void = delete; -#line 3138 "reflect.h2" +#line 3158 "reflect.h2" }; // Regex syntax: | Example: ab|ba @@ -1338,27 +1338,27 @@ class alternative_token public: auto operator=(alternative_token const&) -> void = delete; -#line 3157 "reflect.h2" +#line 3177 "reflect.h2" }; class alternative_token_gen : public regex_token { -#line 3163 "reflect.h2" +#line 3183 "reflect.h2" private: token_vec alternatives; public: alternative_token_gen(cpp2::impl::in a); -#line 3170 "reflect.h2" +#line 3190 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3187 "reflect.h2" +#line 3207 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; -#line 3194 "reflect.h2" +#line 3214 "reflect.h2" public: [[nodiscard]] static auto gen_string(cpp2::impl::in a) -> std::string; -#line 3207 "reflect.h2" +#line 3227 "reflect.h2" public: [[nodiscard]] auto reverse() const -> token_ptr override; public: virtual ~alternative_token_gen() noexcept; @@ -1366,19 +1366,19 @@ class alternative_token_gen public: auto operator=(alternative_token_gen const&) -> void = delete; -#line 3219 "reflect.h2" +#line 3239 "reflect.h2" }; -#line 3222 "reflect.h2" +#line 3242 "reflect.h2" // Regex syntax: . // class any_token : public regex_token_check { -#line 3228 "reflect.h2" +#line 3248 "reflect.h2" public: any_token(cpp2::impl::in single_line); -#line 3232 "reflect.h2" +#line 3252 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; public: virtual ~any_token() noexcept; @@ -1386,7 +1386,7 @@ class any_token public: auto operator=(any_token const&) -> void = delete; -#line 3237 "reflect.h2" +#line 3257 "reflect.h2" }; // Regex syntax: (?>) Example: a(?>bc|c)c @@ -1394,17 +1394,17 @@ class any_token class atomic_group_token : public regex_token { -#line 3245 "reflect.h2" +#line 3265 "reflect.h2" public: token_ptr inner_token {nullptr}; public: explicit atomic_group_token(); public: [[nodiscard]] auto reverse() const -> token_ptr override; -#line 3256 "reflect.h2" +#line 3276 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3264 "reflect.h2" +#line 3284 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~atomic_group_token() noexcept; @@ -1412,7 +1412,7 @@ class atomic_group_token public: auto operator=(atomic_group_token const&) -> void = delete; -#line 3267 "reflect.h2" +#line 3287 "reflect.h2" }; // Regex syntax: a @@ -1420,34 +1420,34 @@ class atomic_group_token class char_token : public regex_token { -#line 3275 "reflect.h2" +#line 3295 "reflect.h2" private: std::string token; private: bool ignore_case; public: char_token(cpp2::impl::in t, cpp2::impl::in ignore_case_); -#line 3284 "reflect.h2" +#line 3304 "reflect.h2" public: char_token(cpp2::impl::in t, cpp2::impl::in ignore_case_); -#line 3290 "reflect.h2" +#line 3310 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 3294 "reflect.h2" +#line 3314 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3317 "reflect.h2" +#line 3337 "reflect.h2" public: auto gen_case_insensitive(cpp2::impl::in lower, cpp2::impl::in upper, generation_context& ctx) const& -> void; -#line 3338 "reflect.h2" +#line 3358 "reflect.h2" public: auto gen_case_sensitive(generation_context& ctx) const& -> void; -#line 3356 "reflect.h2" +#line 3376 "reflect.h2" public: [[nodiscard]] auto add_escapes(std::string str) const& -> std::string; -#line 3371 "reflect.h2" +#line 3391 "reflect.h2" public: [[nodiscard]] auto reverse() const -> token_ptr override; -#line 3377 "reflect.h2" +#line 3397 "reflect.h2" public: auto append(char_token const& that) & -> void; public: virtual ~char_token() noexcept; @@ -1455,33 +1455,33 @@ class char_token public: auto operator=(char_token const&) -> void = delete; -#line 3381 "reflect.h2" +#line 3401 "reflect.h2" }; -#line 3384 "reflect.h2" +#line 3404 "reflect.h2" // Regex syntax: [] Example: [abcx-y[:digits:]] // class class_token : public regex_token { -#line 3390 "reflect.h2" +#line 3410 "reflect.h2" private: bool negate; private: bool case_insensitive; private: std::string class_str; public: class_token(cpp2::impl::in negate_, cpp2::impl::in case_insensitive_, cpp2::impl::in class_str_, cpp2::impl::in str); -#line 3402 "reflect.h2" +#line 3422 "reflect.h2" // TODO: Rework class generation: Generate check functions for classes. public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 3528 "reflect.h2" +#line 3548 "reflect.h2" public: [[nodiscard]] auto reverse() const -> token_ptr override; -#line 3537 "reflect.h2" +#line 3557 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 3542 "reflect.h2" +#line 3562 "reflect.h2" private: [[nodiscard]] static auto create_matcher(cpp2::impl::in name, cpp2::impl::in template_arguments) -> std::string; public: virtual ~class_token() noexcept; @@ -1489,20 +1489,20 @@ class class_token public: auto operator=(class_token const&) -> void = delete; -#line 3549 "reflect.h2" +#line 3569 "reflect.h2" }; -#line 3552 "reflect.h2" +#line 3572 "reflect.h2" // Regex syntax: \a or \n or \[ // [[nodiscard]] auto escape_token_parse(parse_context& ctx) -> token_ptr; -#line 3593 "reflect.h2" +#line 3613 "reflect.h2" // Regex syntax: \K Example: ab\Kcd // [[nodiscard]] auto global_group_reset_token_parse(parse_context& ctx) -> token_ptr; -#line 3604 "reflect.h2" +#line 3624 "reflect.h2" // Regex syntax: \ Example: \1 // \g{name_or_number} // \k{name_or_number} @@ -1512,20 +1512,20 @@ class class_token class group_ref_token : public regex_token { -#line 3614 "reflect.h2" +#line 3634 "reflect.h2" private: int id; private: bool case_insensitive; private: bool reverse_eval; public: group_ref_token(cpp2::impl::in id_, cpp2::impl::in case_insensitive_, cpp2::impl::in reverse_, cpp2::impl::in str); -#line 3626 "reflect.h2" +#line 3646 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 3727 "reflect.h2" +#line 3747 "reflect.h2" public: [[nodiscard]] auto reverse() const -> token_ptr override; -#line 3731 "reflect.h2" +#line 3751 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; public: virtual ~group_ref_token() noexcept; @@ -1533,10 +1533,10 @@ class group_ref_token public: auto operator=(group_ref_token const&) -> void = delete; -#line 3734 "reflect.h2" +#line 3754 "reflect.h2" }; -#line 3737 "reflect.h2" +#line 3757 "reflect.h2" // Regex syntax: () Example: (abc) // (?:) (?i:abc) @@ -1550,29 +1550,29 @@ class group_ref_token class group_token : public regex_token { -#line 3751 "reflect.h2" +#line 3771 "reflect.h2" private: int number {-1}; private: bool reverse_eval {false}; private: token_ptr inner {nullptr}; public: [[nodiscard]] static auto parse_lookahead_lookbehind(parse_context& ctx, cpp2::impl::in syntax, cpp2::impl::in lookahead, cpp2::impl::in positive) -> token_ptr; -#line 3773 "reflect.h2" +#line 3793 "reflect.h2" public: [[nodiscard]] static auto parse_atomic_pattern(parse_context& ctx, cpp2::impl::in syntax) -> token_ptr; -#line 3787 "reflect.h2" +#line 3807 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 3946 "reflect.h2" +#line 3966 "reflect.h2" public: [[nodiscard]] auto reverse() const -> token_ptr override; -#line 3954 "reflect.h2" +#line 3974 "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 3972 "reflect.h2" +#line 3992 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 4003 "reflect.h2" +#line 4023 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~group_token() noexcept; @@ -1581,25 +1581,25 @@ class group_token public: auto operator=(group_token const&) -> void = delete; -#line 4010 "reflect.h2" +#line 4030 "reflect.h2" }; -#line 4013 "reflect.h2" +#line 4033 "reflect.h2" // Regex syntax: \x or \x{} Example: \x{62} // [[nodiscard]] auto hexadecimal_token_parse(parse_context& ctx) -> token_ptr; -#line 4054 "reflect.h2" +#line 4074 "reflect.h2" // Regex syntax: $ Example: aa$ // [[nodiscard]] auto line_end_token_parse(parse_context& ctx) -> token_ptr; -#line 4074 "reflect.h2" +#line 4094 "reflect.h2" // Regex syntax: ^ Example: ^aa // [[nodiscard]] auto line_start_token_parse(parse_context& ctx) -> token_ptr; -#line 4090 "reflect.h2" +#line 4110 "reflect.h2" // Regex syntax: (?=) or (?!) or (*pla), etc. Example: (?=AA) // // Parsed in group_token. @@ -1607,20 +1607,20 @@ class group_token class lookahead_lookbehind_token : public regex_token { -#line 4098 "reflect.h2" +#line 4118 "reflect.h2" protected: bool lookahead; protected: bool positive; public: token_ptr inner {nullptr}; public: lookahead_lookbehind_token(cpp2::impl::in lookahead_, cpp2::impl::in positive_); -#line 4107 "reflect.h2" +#line 4127 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 4118 "reflect.h2" +#line 4138 "reflect.h2" public: [[nodiscard]] auto reverse() const -> token_ptr override; -#line 4125 "reflect.h2" +#line 4145 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~lookahead_lookbehind_token() noexcept; @@ -1628,26 +1628,26 @@ class lookahead_lookbehind_token public: auto operator=(lookahead_lookbehind_token const&) -> void = delete; -#line 4128 "reflect.h2" +#line 4148 "reflect.h2" }; -#line 4131 "reflect.h2" +#line 4151 "reflect.h2" // Named character classes // [[nodiscard]] auto named_class_token_parse(parse_context& ctx) -> token_ptr; -#line 4159 "reflect.h2" +#line 4179 "reflect.h2" // Regex syntax: \o{} Example: \o{142} // [[nodiscard]] auto octal_token_parse(parse_context& ctx) -> token_ptr; -#line 4187 "reflect.h2" +#line 4207 "reflect.h2" // Regex syntax: {min, max} Example: a{2,4} // class range_token : public regex_token { -#line 4193 "reflect.h2" +#line 4213 "reflect.h2" protected: int min_count {-1}; protected: int max_count {-1}; protected: int kind {range_flags::greedy}; @@ -1657,22 +1657,22 @@ class range_token public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; -#line 4273 "reflect.h2" +#line 4293 "reflect.h2" public: auto parse_modifier(parse_context& ctx) & -> void; -#line 4285 "reflect.h2" +#line 4305 "reflect.h2" public: [[nodiscard]] auto gen_mod_string() const& -> std::string; -#line 4298 "reflect.h2" +#line 4318 "reflect.h2" public: [[nodiscard]] auto gen_range_string() const& -> std::string; -#line 4317 "reflect.h2" +#line 4337 "reflect.h2" public: [[nodiscard]] auto reverse() const -> token_ptr override; -#line 4327 "reflect.h2" +#line 4347 "reflect.h2" public: auto generate_code(generation_context& ctx) const -> void override; -#line 4338 "reflect.h2" +#line 4358 "reflect.h2" public: auto add_groups(std::set& groups) const -> void override; public: virtual ~range_token() noexcept; @@ -1680,16 +1680,16 @@ class range_token public: auto operator=(range_token const&) -> void = delete; -#line 4341 "reflect.h2" +#line 4361 "reflect.h2" }; -#line 4344 "reflect.h2" +#line 4364 "reflect.h2" // Regex syntax: *, +, or ? Example: aa* // class special_range_token : public range_token { -#line 4350 "reflect.h2" +#line 4370 "reflect.h2" public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr; public: virtual ~special_range_token() noexcept; @@ -1698,7 +1698,7 @@ class special_range_token public: auto operator=(special_range_token const&) -> void = delete; -#line 4380 "reflect.h2" +#line 4400 "reflect.h2" }; // Regex syntax: \G Example: \Gaa @@ -1707,14 +1707,14 @@ class special_range_token // [[nodiscard]] auto start_match_parse(parse_context& ctx) -> token_ptr; -#line 4402 "reflect.h2" +#line 4422 "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 4424 "reflect.h2" +#line 4444 "reflect.h2" //----------------------------------------------------------------------- // // Parser for regular expression. @@ -1735,24 +1735,24 @@ template class regex_generator public: regex_generator(cpp2::impl::in r, Error_out const& e); -#line 4447 "reflect.h2" +#line 4467 "reflect.h2" public: [[nodiscard]] auto parse() & -> std::string; -#line 4482 "reflect.h2" +#line 4502 "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 4496 "reflect.h2" +#line 4516 "reflect.h2" }; template [[nodiscard]] auto generate_regex(cpp2::impl::in regex, Err const& err) -> std::string; -#line 4508 "reflect.h2" +#line 4528 "reflect.h2" auto regex_gen(meta::type_declaration& t) -> void; -#line 4563 "reflect.h2" +#line 4583 "reflect.h2" //----------------------------------------------------------------------- // // apply_metafunctions @@ -1763,7 +1763,7 @@ auto regex_gen(meta::type_declaration& t) -> void; auto const& error ) -> bool; -#line 4683 "reflect.h2" +#line 4703 "reflect.h2" } } @@ -4234,26 +4234,28 @@ auto autodiff(meta::type_declaration& t) -> void auto additive_terms {CPP2_UFCS(get_terms)(CPP2_UFCS(get_term)(CPP2_UFCS(front)(cpp2::move(shift_terms))))}; if (cpp2::impl::cmp_greater(CPP2_UFCS(ssize)(additive_terms),1)) { - if (CPP2_UFCS(ssize)(additive_terms) != 2 - || CPP2_UFCS(get_op)(CPP2_ASSERT_IN_BOUNDS_LITERAL(additive_terms, 1)) != "+") - { - CPP2_UFCS(error)(m, "temporary alpha limitation: this initial baby step only supports specifically 'a + b', not subtraction or chains of + and -"); - } + auto first {true}; + for ( auto const& term : additive_terms ) { + if (!(first)) { + auto op {CPP2_UFCS(to_string)(CPP2_UFCS(get_op)(term))}; + line1 += " " + cpp2::to_string(op) + " "; + line2 += " " + cpp2::to_string(cpp2::move(op)) + " "; + } - auto lhs {CPP2_UFCS(to_string)(CPP2_UFCS(get_term)(CPP2_ASSERT_IN_BOUNDS_LITERAL(additive_terms, 0)))}; - if (!(CPP2_UFCS(has_parameter_or_return_named)(mf, lhs))) { - CPP2_UFCS(error)(m, "temporary alpha limitation: the addition's left-hand side '" + cpp2::to_string(lhs) + "' must be a parameter or return name"); - } + auto var {CPP2_UFCS(to_string)(CPP2_UFCS(get_term)(term))}; + if (!(CPP2_UFCS(has_parameter_or_return_named)(mf, var))) { + CPP2_UFCS(error)(m, "temporary alpha limitation: the addition's left-hand side '" + cpp2::to_string(var) + "' must be a parameter or return name"); + } + line1 += "" + cpp2::to_string(var) + "_d"; + line2 += "" + cpp2::to_string(cpp2::move(var)) + ""; - auto rhs {CPP2_UFCS(to_string)(CPP2_UFCS(get_term)(CPP2_ASSERT_IN_BOUNDS_LITERAL(additive_terms, 1)))}; - if (!(CPP2_UFCS(has_parameter_or_return_named)(mf, rhs))) { - CPP2_UFCS(error)(m, "temporary alpha limitation: the addition's right-hand side '" + cpp2::to_string(rhs) + "' must be a parameter or return name"); + first = false; } - line1 += "" + cpp2::to_string(lhs) + " * " + cpp2::to_string(rhs) + "_d + " + cpp2::to_string(rhs) + " * " + cpp2::to_string(lhs) + "_d;"; - line2 += "" + cpp2::to_string(cpp2::move(lhs)) + " * " + cpp2::to_string(cpp2::move(rhs)) + ";"; + line1 += ";"; + line2 += ";"; - diff += cpp2::move(line1) + cpp2::move(line2); + diff += line1 + line2; goto CONTINUE_next_statement; } @@ -4265,17 +4267,35 @@ auto autodiff(meta::type_declaration& t) -> void auto multiplicative_terms {CPP2_UFCS(get_terms)(CPP2_UFCS(get_term)(CPP2_UFCS(front)(cpp2::move(additive_terms))))}; if (cpp2::impl::cmp_greater(CPP2_UFCS(ssize)(multiplicative_terms),1)) { - // TODO: Do whatever is appropriate here... - // For now, just list out what we found (visible via @print)... - diff += "found_multiplicative_with_____"; - auto count {0}; - for ( auto const& term : cpp2::move(multiplicative_terms) ) { - if (cpp2::impl::cmp_greater(++count,1)) { - diff += CPP2_UFCS(get_op)(term) + "___"; - } - diff += CPP2_UFCS(to_string)(CPP2_UFCS(get_term)(term)) + "___"; + if (CPP2_UFCS(ssize)(multiplicative_terms) != 2) + { + CPP2_UFCS(error)(m, "temporary alpha limitation: does not support chains of * and /"); } - diff += ";"; + + auto lhs {CPP2_UFCS(to_string)(CPP2_UFCS(get_term)(CPP2_ASSERT_IN_BOUNDS_LITERAL(multiplicative_terms, 0)))}; + if (!(CPP2_UFCS(has_parameter_or_return_named)(mf, lhs))) { + CPP2_UFCS(error)(m, "temporary alpha limitation: the addition's left-hand side '" + cpp2::to_string(lhs) + "' must be a parameter or return name"); + } + + auto rhs {CPP2_UFCS(to_string)(CPP2_UFCS(get_term)(CPP2_ASSERT_IN_BOUNDS_LITERAL(multiplicative_terms, 1)))}; + if (!(CPP2_UFCS(has_parameter_or_return_named)(mf, rhs))) { + CPP2_UFCS(error)(m, "temporary alpha limitation: the addition's right-hand side '" + cpp2::to_string(rhs) + "' must be a parameter or return name"); + } + + auto op {CPP2_UFCS(to_string)(CPP2_UFCS(get_op)(CPP2_ASSERT_IN_BOUNDS_LITERAL(cpp2::move(multiplicative_terms), 1)))}; + if ("*" == op) { + line1 += "" + cpp2::to_string(lhs) + " * " + cpp2::to_string(rhs) + "_d + " + cpp2::to_string(rhs) + " * " + cpp2::to_string(lhs) + "_d;"; + line2 += "" + cpp2::to_string(cpp2::move(lhs)) + " * " + cpp2::to_string(cpp2::move(rhs)) + ";"; + } + else {if ("/" == op) { + line1 += "" + cpp2::to_string(lhs) + "_d / " + cpp2::to_string(rhs) + " - " + cpp2::to_string(lhs) + " * " + cpp2::to_string(rhs) + "_d / (" + cpp2::to_string(rhs) + " * " + cpp2::to_string(rhs) + ");"; + line2 += "" + cpp2::to_string(cpp2::move(lhs)) + " / " + cpp2::to_string(cpp2::move(rhs)) + ";"; + } + else { + CPP2_UFCS(error)(m, "unkown multiplicative operator '" + cpp2::to_string(cpp2::move(op)) + "'"); + }} + + diff += cpp2::move(line1) + cpp2::move(line2); goto CONTINUE_next_statement; } @@ -4284,7 +4304,7 @@ auto autodiff(meta::type_declaration& t) -> void } } CPP2_CONTINUE_BREAK(next_statement) } -#line 2242 "reflect.h2" +#line 2262 "reflect.h2" diff += "}"; CPP2_UFCS(add_member)(t, cpp2::move(diff)); @@ -4382,7 +4402,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 2249 "reflect.h2" +#line 2269 "reflect.h2" //----------------------------------------------------------------------- // // regex - creates regular expressions from members @@ -4398,11 +4418,11 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov // ``` // -#line 2265 "reflect.h2" +#line 2285 "reflect.h2" // Possible modifiers for a regular expression. // -#line 2269 "reflect.h2" +#line 2289 "reflect.h2" // mod: i // mod: m // mod: s @@ -4410,116 +4430,116 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov // mod: x // mod: xx -#line 2278 "reflect.h2" +#line 2298 "reflect.h2" // Tokens for regular expressions. // // Basic class for a regex token. // -#line 2287 "reflect.h2" +#line 2307 "reflect.h2" regex_token::regex_token(cpp2::impl::in str) : string_rep{ str }{ -#line 2289 "reflect.h2" +#line 2309 "reflect.h2" } -#line 2291 "reflect.h2" +#line 2311 "reflect.h2" regex_token::regex_token() : string_rep{ "" }{ -#line 2293 "reflect.h2" +#line 2313 "reflect.h2" } //parse: (inout ctx: parse_context) -> token_ptr; // Generate the matching code. // Create a reverse token for look behind expressions. -#line 2299 "reflect.h2" +#line 2319 "reflect.h2" auto regex_token::add_groups([[maybe_unused]] std::set& unnamed_param_2) const -> void{}// Adds all group indices to the set. -#line 2300 "reflect.h2" +#line 2320 "reflect.h2" [[nodiscard]] auto regex_token::to_string() const& -> std::string{return string_rep; }// Create a string representation. -#line 2301 "reflect.h2" +#line 2321 "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 2316 "reflect.h2" +#line 2336 "reflect.h2" regex_token_check::regex_token_check(cpp2::impl::in str, cpp2::impl::in check_) : regex_token{ str } , check{ check_ }{ -#line 2319 "reflect.h2" +#line 2339 "reflect.h2" } -#line 2321 "reflect.h2" +#line 2341 "reflect.h2" auto regex_token_check::generate_code(generation_context& ctx) const -> void{ ctx.add_check(check + "(" + ctx.match_parameters() + ")"); } -#line 2325 "reflect.h2" +#line 2345 "reflect.h2" [[nodiscard]] auto regex_token_check::reverse() const -> token_ptr { return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, CPP2_UFCS(to_string)((*this)), (*this).check); } regex_token_check::~regex_token_check() noexcept{} -#line 2337 "reflect.h2" +#line 2357 "reflect.h2" regex_token_code::regex_token_code(cpp2::impl::in str, cpp2::impl::in code_) : regex_token{ str } , code{ code_ }{ -#line 2340 "reflect.h2" +#line 2360 "reflect.h2" } -#line 2342 "reflect.h2" +#line 2362 "reflect.h2" auto regex_token_code::generate_code(generation_context& ctx) const -> void{ ctx.add(code); } -#line 2346 "reflect.h2" +#line 2366 "reflect.h2" [[nodiscard]] auto regex_token_code::reverse() const -> token_ptr { return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, CPP2_UFCS(to_string)((*this)), (*this).code); } regex_token_code::~regex_token_code() noexcept{} -#line 2356 "reflect.h2" +#line 2376 "reflect.h2" regex_token_empty::regex_token_empty(cpp2::impl::in str) : regex_token{ str }{ -#line 2358 "reflect.h2" +#line 2378 "reflect.h2" } -#line 2360 "reflect.h2" +#line 2380 "reflect.h2" auto regex_token_empty::generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void{ // Nothing. } -#line 2364 "reflect.h2" +#line 2384 "reflect.h2" [[nodiscard]] auto regex_token_empty::reverse() const -> token_ptr { return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, CPP2_UFCS(to_string)((*this))); } regex_token_empty::~regex_token_empty() noexcept{} -#line 2376 "reflect.h2" +#line 2396 "reflect.h2" regex_token_list::regex_token_list(cpp2::impl::in t) : regex_token{ gen_string(t) } , tokens{ t }{ -#line 2379 "reflect.h2" +#line 2399 "reflect.h2" } -#line 2381 "reflect.h2" +#line 2401 "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 2387 "reflect.h2" +#line 2407 "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 2393 "reflect.h2" +#line 2413 "reflect.h2" [[nodiscard]] auto regex_token_list::gen_string(cpp2::impl::in vec) -> std::string{ std::string r {""}; for ( auto const& token : vec ) { @@ -4528,7 +4548,7 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov return r; } -#line 2401 "reflect.h2" +#line 2421 "reflect.h2" [[nodiscard]] auto regex_token_list::reverse() const -> token_ptr{ int s {cpp2::unchecked_narrow(tokens.size())}; @@ -4544,7 +4564,7 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov regex_token_list::~regex_token_list() noexcept{} -#line 2429 "reflect.h2" +#line 2449 "reflect.h2" auto parse_context_group_state::next_alternative() & -> void{ token_vec new_list {}; std::swap(new_list, cur_match_list); @@ -4552,14 +4572,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 2437 "reflect.h2" +#line 2457 "reflect.h2" auto parse_context_group_state::swap(parse_context_group_state& t) & -> void{// NOLINT(performance-noexcept-swap) std::swap(cur_match_list, t.cur_match_list); std::swap(alternate_match_lists, t.alternate_match_lists); std::swap(modifiers, t.modifiers); } -#line 2444 "reflect.h2" +#line 2464 "reflect.h2" [[nodiscard]] auto parse_context_group_state::get_as_token() & -> token_ptr{ if (alternate_match_lists.empty()) { post_process_list(cur_match_list); @@ -4571,15 +4591,15 @@ std::string str {s}; return from_string(cpp2::string_util::replace_all(cpp2::mov } } -#line 2456 "reflect.h2" +#line 2476 "reflect.h2" auto parse_context_group_state::add(cpp2::impl::in token) & -> void{ cur_match_list.push_back(token); } -#line 2461 "reflect.h2" +#line 2481 "reflect.h2" [[nodiscard]] auto parse_context_group_state::empty() const& -> bool { return cur_match_list.empty(); } -#line 2465 "reflect.h2" +#line 2485 "reflect.h2" auto parse_context_group_state::post_process_list(token_vec& list) -> void{ // Merge all characters auto merge_pos {list.begin()}; @@ -4600,7 +4620,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 2491 "reflect.h2" +#line 2511 "reflect.h2" [[nodiscard]] auto parse_context_branch_reset_state::next() & -> int{ auto g {cur_group}; cur_group += 1; @@ -4609,20 +4629,20 @@ parse_context_group_state::parse_context_group_state(){} return g; } -#line 2500 "reflect.h2" +#line 2520 "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 2506 "reflect.h2" +#line 2526 "reflect.h2" auto parse_context_branch_reset_state::next_alternative() & -> void{ if (is_active) { cur_group = from; } } -#line 2513 "reflect.h2" +#line 2533 "reflect.h2" auto parse_context_branch_reset_state::set_active_reset(cpp2::impl::in restart) & -> void{ is_active = true; cur_group = restart; @@ -4637,16 +4657,16 @@ parse_context_group_state::parse_context_group_state(){} , from{ from_ }{} parse_context_branch_reset_state::parse_context_branch_reset_state(){} -#line 2543 "reflect.h2" +#line 2563 "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 2547 "reflect.h2" +#line 2567 "reflect.h2" } -#line 2553 "reflect.h2" +#line 2573 "reflect.h2" [[nodiscard]] auto parse_context::start_group() & -> parse_context_group_state { parse_context_group_state old_state {}; @@ -4656,7 +4676,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return old_state; } -#line 2563 "reflect.h2" +#line 2583 "reflect.h2" [[nodiscard]] auto parse_context::end_group(cpp2::impl::in old_state) & -> token_ptr { auto inner {cur_group_state.get_as_token()}; @@ -4664,17 +4684,17 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return inner; } -#line 2570 "reflect.h2" +#line 2590 "reflect.h2" [[nodiscard]] auto parse_context::get_modifiers() const& -> expression_flags{ return cur_group_state.modifiers; } -#line 2574 "reflect.h2" +#line 2594 "reflect.h2" auto parse_context::set_modifiers(cpp2::impl::in mod) & -> void{ cur_group_state.modifiers = mod; } -#line 2581 "reflect.h2" +#line 2601 "reflect.h2" [[nodiscard]] auto parse_context::branch_reset_new_state() & -> parse_context_branch_reset_state { parse_context_branch_reset_state old_state {}; @@ -4684,7 +4704,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return old_state; } -#line 2590 "reflect.h2" +#line 2610 "reflect.h2" auto parse_context::branch_reset_restore_state(cpp2::impl::in old_state) & -> void { auto max_group {cur_branch_reset_state.max_group}; @@ -4692,24 +4712,24 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} cur_branch_reset_state.set_next(cpp2::move(max_group)); } -#line 2597 "reflect.h2" +#line 2617 "reflect.h2" auto parse_context::next_alternative() & -> void { cur_group_state.next_alternative(); cur_branch_reset_state.next_alternative(); } -#line 2605 "reflect.h2" +#line 2625 "reflect.h2" auto parse_context::add_token(cpp2::impl::in token) & -> void{ cur_group_state.add(token); } -#line 2609 "reflect.h2" +#line 2629 "reflect.h2" [[nodiscard]] auto parse_context::has_token() const& -> bool{ return !(cur_group_state.empty()); } -#line 2613 "reflect.h2" +#line 2633 "reflect.h2" [[nodiscard]] auto parse_context::pop_token() & -> token_ptr { token_ptr r {nullptr}; @@ -4721,22 +4741,22 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 2624 "reflect.h2" +#line 2644 "reflect.h2" [[nodiscard]] auto parse_context::get_as_token() & -> token_ptr{ return root; } -#line 2630 "reflect.h2" +#line 2650 "reflect.h2" [[nodiscard]] auto parse_context::get_cur_group() const& -> int{ return cur_branch_reset_state.cur_group; } -#line 2634 "reflect.h2" +#line 2654 "reflect.h2" [[nodiscard]] auto parse_context::next_group() & -> int{ return cur_branch_reset_state.next(); } -#line 2638 "reflect.h2" +#line 2658 "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. @@ -4744,7 +4764,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2645 "reflect.h2" +#line 2665 "reflect.h2" [[nodiscard]] auto parse_context::get_named_group(cpp2::impl::in name) const& -> int { auto iter {named_groups.find(name)}; @@ -4756,10 +4776,10 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2658 "reflect.h2" +#line 2678 "reflect.h2" [[nodiscard]] auto parse_context::current() const& -> char{return CPP2_ASSERT_IN_BOUNDS(regex, pos); } -#line 2661 "reflect.h2" +#line 2681 "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}; @@ -4799,7 +4819,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return cur; } -#line 2701 "reflect.h2" +#line 2721 "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); @@ -4811,14 +4831,14 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2712 "reflect.h2" +#line 2732 "reflect.h2" [[nodiscard]] auto parse_context::next() & -> decltype(auto) { return next_impl(false, false); } -#line 2713 "reflect.h2" +#line 2733 "reflect.h2" [[nodiscard]] auto parse_context::next_in_class() & -> decltype(auto) { return next_impl(true, false); } -#line 2714 "reflect.h2" +#line 2734 "reflect.h2" [[nodiscard]] auto parse_context::next_no_skip() & -> decltype(auto) { return next_impl(false, true); } -#line 2716 "reflect.h2" +#line 2736 "reflect.h2" [[nodiscard]] auto parse_context::next_n(cpp2::impl::in n) & -> bool{ auto r {true}; auto cur {0}; @@ -4828,10 +4848,10 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 2725 "reflect.h2" +#line 2745 "reflect.h2" [[nodiscard]] auto parse_context::has_next() const& -> bool{return cpp2::impl::cmp_less(pos,regex.size()); } -#line 2727 "reflect.h2" +#line 2747 "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}; // NOLINT(clang-analyzer-deadcode.DeadStores) @@ -4853,14 +4873,14 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2748 "reflect.h2" +#line 2768 "reflect.h2" [[nodiscard]] auto parse_context::grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> decltype(auto) { return grab_until_impl(e, cpp2::impl::out(&r), false); } -#line 2749 "reflect.h2" +#line 2769 "reflect.h2" [[nodiscard]] auto parse_context::grab_until(cpp2::impl::in e, cpp2::impl::out r) & -> decltype(auto) { return grab_until_impl(std::string(1, e), cpp2::impl::out(&r), false); } -#line 2750 "reflect.h2" +#line 2770 "reflect.h2" [[nodiscard]] auto parse_context::grab_until_one_of(cpp2::impl::in e, cpp2::impl::out r) & -> decltype(auto) { return grab_until_impl(e, cpp2::impl::out(&r), true); } -#line 2752 "reflect.h2" +#line 2772 "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())) { @@ -4874,7 +4894,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2765 "reflect.h2" +#line 2785 "reflect.h2" [[nodiscard]] auto parse_context::grab_number() & -> std::string { auto start {pos}; @@ -4896,7 +4916,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return cpp2::move(r.value()); } -#line 2786 "reflect.h2" +#line 2806 "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())) { @@ -4907,12 +4927,12 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2796 "reflect.h2" +#line 2816 "reflect.h2" [[nodiscard]] auto parse_context::peek() const& -> decltype(auto) { return peek_impl(false); } -#line 2797 "reflect.h2" +#line 2817 "reflect.h2" [[nodiscard]] auto parse_context::peek_in_class() const& -> decltype(auto) { return peek_impl(true); } -#line 2802 "reflect.h2" +#line 2822 "reflect.h2" [[nodiscard]] auto parse_context::parser_group_modifiers(cpp2::impl::in change_str, expression_flags& parser_modifiers) & -> bool { auto is_negative {false}; @@ -4967,7 +4987,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return true; } -#line 2856 "reflect.h2" +#line 2876 "reflect.h2" [[nodiscard]] auto parse_context::parse_until(cpp2::impl::in term) & -> bool{ token_ptr cur_token {}; @@ -5007,7 +5027,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return true; } -#line 2895 "reflect.h2" +#line 2915 "reflect.h2" [[nodiscard]] auto parse_context::parse(cpp2::impl::in modifiers) & -> bool { @@ -5023,21 +5043,21 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} return r; } -#line 2912 "reflect.h2" +#line 2932 "reflect.h2" [[nodiscard]] auto parse_context::get_pos() const& -> decltype(auto) { return pos; } -#line 2913 "reflect.h2" +#line 2933 "reflect.h2" [[nodiscard]] auto parse_context::get_range(cpp2::impl::in start, cpp2::impl::in end) const& -> decltype(auto) { return std::string(regex.substr(start, end - start + 1)); } -#line 2914 "reflect.h2" +#line 2934 "reflect.h2" [[nodiscard]] auto parse_context::valid() const& -> bool{return has_next() && !(has_error); } -#line 2916 "reflect.h2" +#line 2936 "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 2931 "reflect.h2" +#line 2951 "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 ) { @@ -5045,7 +5065,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} } } -#line 2938 "reflect.h2" +#line 2958 "reflect.h2" auto generation_function_context::remove_tabs(cpp2::impl::in c) & -> void{ tabs = tabs.substr(0, (cpp2::impl::as_(c)) * 2); } @@ -5055,22 +5075,22 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} , tabs{ tabs_ }{} generation_function_context::generation_function_context(){} -#line 2956 "reflect.h2" +#line 2976 "reflect.h2" [[nodiscard]] auto generation_context::match_parameters() const& -> std::string{return "r.pos, ctx"; } -#line 2961 "reflect.h2" +#line 2981 "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 2967 "reflect.h2" +#line 2987 "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 2973 "reflect.h2" +#line 2993 "reflect.h2" auto generation_context::add_statefull(cpp2::impl::in next_func, cpp2::impl::in check) & -> void { end_func_statefull(check); @@ -5079,7 +5099,7 @@ generation_function_context::generation_function_context(){} start_func_named(cpp2::move(name)); } -#line 2981 "reflect.h2" +#line 3001 "reflect.h2" auto generation_context::start_func_named(cpp2::impl::in name) & -> void { auto cur {new_context()}; @@ -5091,7 +5111,7 @@ generation_function_context::generation_function_context(){} (*cpp2::impl::assert_not_null(cpp2::move(cur))).add_tabs(3); } -#line 2992 "reflect.h2" +#line 3012 "reflect.h2" [[nodiscard]] auto generation_context::start_func() & -> std::string { auto name {gen_func_name()}; @@ -5099,7 +5119,7 @@ generation_function_context::generation_function_context(){} return cpp2::move(name) + "()"; } -#line 2999 "reflect.h2" +#line 3019 "reflect.h2" auto generation_context::end_func_statefull(cpp2::impl::in s) & -> void { auto cur {get_current()}; @@ -5120,7 +5140,7 @@ generation_function_context::generation_function_context(){} finish_context(); } -#line 3020 "reflect.h2" +#line 3040 "reflect.h2" [[nodiscard]] auto generation_context::generate_func(cpp2::impl::in token) & -> std::string { auto name {start_func()}; @@ -5130,7 +5150,7 @@ generation_function_context::generation_function_context(){} return name; } -#line 3030 "reflect.h2" +#line 3050 "reflect.h2" [[nodiscard]] auto generation_context::generate_reset(cpp2::impl::in> groups) & -> std::string { if (groups.empty()) { @@ -5153,33 +5173,33 @@ generation_function_context::generation_function_context(){} return cpp2::move(name) + "()"; } -#line 3054 "reflect.h2" +#line 3074 "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 3060 "reflect.h2" +#line 3080 "reflect.h2" [[nodiscard]] auto generation_context::next_func_name() & -> std::string{ return gen_func_name() + "()"; } -#line 3064 "reflect.h2" +#line 3084 "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 3070 "reflect.h2" +#line 3090 "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 3078 "reflect.h2" +#line 3098 "reflect.h2" [[nodiscard]] auto generation_context::new_context() & -> generation_function_context*{ gen_stack.push_back(generation_function_context()); auto cur {get_current()}; @@ -5188,7 +5208,7 @@ generation_function_context::generation_function_context(){} return cur; } -#line 3086 "reflect.h2" +#line 3106 "reflect.h2" auto generation_context::finish_context() & -> void{ auto cur {get_current()}; auto base {get_base()}; @@ -5197,22 +5217,22 @@ generation_function_context::generation_function_context(){} gen_stack.pop_back(); } -#line 3096 "reflect.h2" +#line 3116 "reflect.h2" [[nodiscard]] auto generation_context::get_current() & -> generation_function_context*{ return &gen_stack.back(); } -#line 3100 "reflect.h2" +#line 3120 "reflect.h2" [[nodiscard]] auto generation_context::get_base() & -> generation_function_context*{ return &CPP2_ASSERT_IN_BOUNDS_LITERAL(gen_stack, 0); } -#line 3104 "reflect.h2" +#line 3124 "reflect.h2" [[nodiscard]] auto generation_context::get_entry_func() const& -> std::string{ return entry_func; } -#line 3108 "reflect.h2" +#line 3128 "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"}; @@ -5236,18 +5256,18 @@ generation_function_context::generation_function_context(){} return res; } -#line 3133 "reflect.h2" +#line 3153 "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 3148 "reflect.h2" +#line 3168 "reflect.h2" alternative_token::alternative_token() : regex_token_empty{ "" }{} -#line 3150 "reflect.h2" +#line 3170 "reflect.h2" [[nodiscard]] auto alternative_token::parse(parse_context& ctx) -> token_ptr{ if (ctx.current() != '|') {return nullptr; } @@ -5258,15 +5278,15 @@ generation_function_context::generation_function_context(){} alternative_token::~alternative_token() noexcept{} -#line 3165 "reflect.h2" +#line 3185 "reflect.h2" alternative_token_gen::alternative_token_gen(cpp2::impl::in a) : regex_token{ gen_string(a) } , alternatives{ a }{ -#line 3168 "reflect.h2" +#line 3188 "reflect.h2" } -#line 3170 "reflect.h2" +#line 3190 "reflect.h2" auto alternative_token_gen::generate_code(generation_context& ctx) const -> void { std::string functions {""}; @@ -5284,7 +5304,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 3187 "reflect.h2" +#line 3207 "reflect.h2" auto alternative_token_gen::add_groups(std::set& groups) const -> void { for ( auto const& cur : alternatives ) { @@ -5292,7 +5312,7 @@ generation_function_context::generation_function_context(){} } } -#line 3194 "reflect.h2" +#line 3214 "reflect.h2" [[nodiscard]] auto alternative_token_gen::gen_string(cpp2::impl::in a) -> std::string { std::string r {""}; @@ -5306,7 +5326,7 @@ generation_function_context::generation_function_context(){} return r; } -#line 3207 "reflect.h2" +#line 3227 "reflect.h2" [[nodiscard]] auto alternative_token_gen::reverse() const -> token_ptr{ int s {cpp2::unchecked_narrow(alternatives.size())}; @@ -5322,14 +5342,14 @@ generation_function_context::generation_function_context(){} alternative_token_gen::~alternative_token_gen() noexcept{} -#line 3228 "reflect.h2" +#line 3248 "reflect.h2" any_token::any_token(cpp2::impl::in single_line) : regex_token_check{ ".", "any_token_matcher" }{ -#line 3230 "reflect.h2" +#line 3250 "reflect.h2" } -#line 3232 "reflect.h2" +#line 3252 "reflect.h2" [[nodiscard]] auto any_token::parse(parse_context& ctx) -> token_ptr{ if ('.' != ctx.current()) {return nullptr; } @@ -5338,11 +5358,11 @@ generation_function_context::generation_function_context(){} any_token::~any_token() noexcept{} -#line 3247 "reflect.h2" +#line 3267 "reflect.h2" atomic_group_token::atomic_group_token() : regex_token{ "" }{} -#line 3249 "reflect.h2" +#line 3269 "reflect.h2" [[nodiscard]] auto atomic_group_token::reverse() const -> token_ptr{ auto r {CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared)}; (*cpp2::impl::assert_not_null(r)).inner_token = CPP2_UFCS(reverse)((*cpp2::impl::assert_not_null(inner_token))); @@ -5350,7 +5370,7 @@ generation_function_context::generation_function_context(){} return r; } -#line 3256 "reflect.h2" +#line 3276 "reflect.h2" auto atomic_group_token::generate_code(generation_context& ctx) const -> void { auto inner_name {ctx.generate_func(inner_token)}; @@ -5359,37 +5379,37 @@ generation_function_context::generation_function_context(){} ctx.add_statefull(next_name, "cpp2::regex::atomic_group_matcher(" + cpp2::to_string(ctx.match_parameters()) + ", " + cpp2::to_string(cpp2::move(inner_name)) + ", other, " + cpp2::to_string(next_name) + ")"); } -#line 3264 "reflect.h2" +#line 3284 "reflect.h2" auto atomic_group_token::add_groups(std::set& groups) const -> void{ (*cpp2::impl::assert_not_null(inner_token)).add_groups(groups); } atomic_group_token::~atomic_group_token() noexcept{} -#line 3278 "reflect.h2" +#line 3298 "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 3282 "reflect.h2" +#line 3302 "reflect.h2" } -#line 3284 "reflect.h2" +#line 3304 "reflect.h2" char_token::char_token(cpp2::impl::in t, cpp2::impl::in ignore_case_) : regex_token{ t } , token{ t } , ignore_case{ ignore_case_ }{ -#line 3288 "reflect.h2" +#line 3308 "reflect.h2" } -#line 3290 "reflect.h2" +#line 3310 "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 3294 "reflect.h2" +#line 3314 "reflect.h2" auto char_token::generate_code(generation_context& ctx) const -> void { if (ignore_case) { @@ -5398,14 +5418,14 @@ generation_function_context::generation_function_context(){} { size_t i{0}; -#line 3300 "reflect.h2" +#line 3320 "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 3305 "reflect.h2" +#line 3325 "reflect.h2" if (upper != lower) { gen_case_insensitive(cpp2::move(lower), cpp2::move(upper), ctx); } @@ -5418,7 +5438,7 @@ size_t i{0}; } } -#line 3317 "reflect.h2" +#line 3337 "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()) + ""}; @@ -5440,7 +5460,7 @@ size_t i{0}; ctx.add("else { break; }"); } -#line 3338 "reflect.h2" +#line 3358 "reflect.h2" auto char_token::gen_case_sensitive(generation_context& ctx) const& -> void { std::string name {"str_" + cpp2::to_string(ctx.gen_temp()) + ""}; @@ -5459,7 +5479,7 @@ size_t i{0}; ctx.add("else { break; }"); } -#line 3356 "reflect.h2" +#line 3376 "reflect.h2" [[nodiscard]] auto char_token::add_escapes(std::string str) const& -> std::string { str = string_util::replace_all(str, "\\", "\\\\"); @@ -5475,14 +5495,14 @@ size_t i{0}; return cpp2::move(str); } -#line 3371 "reflect.h2" +#line 3391 "reflect.h2" [[nodiscard]] auto char_token::reverse() const -> token_ptr{ std::string reverse_str {token}; std::reverse(reverse_str.begin(), reverse_str.end()); return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, cpp2::move(reverse_str), ignore_case); } -#line 3377 "reflect.h2" +#line 3397 "reflect.h2" auto char_token::append(char_token const& that) & -> void{ (*this).token += that.token; (*this).string_rep += that.string_rep; @@ -5490,19 +5510,19 @@ size_t i{0}; char_token::~char_token() noexcept{} -#line 3394 "reflect.h2" +#line 3414 "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 3395 "reflect.h2" +#line 3415 "reflect.h2" { -#line 3400 "reflect.h2" +#line 3420 "reflect.h2" } -#line 3403 "reflect.h2" +#line 3423 "reflect.h2" [[nodiscard]] auto class_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '[') {return nullptr; } @@ -5628,7 +5648,7 @@ size_t i{0}; ); } -#line 3528 "reflect.h2" +#line 3548 "reflect.h2" [[nodiscard]] auto class_token::reverse() const -> token_ptr{ return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, negate, @@ -5638,13 +5658,13 @@ size_t i{0}; ); } -#line 3537 "reflect.h2" +#line 3557 "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 3542 "reflect.h2" +#line 3562 "reflect.h2" [[nodiscard]] auto class_token::create_matcher(cpp2::impl::in name, cpp2::impl::in template_arguments) -> std::string { auto sep {", "}; @@ -5655,12 +5675,12 @@ size_t i{0}; class_token::~class_token() noexcept{} -#line 3554 "reflect.h2" +#line 3574 "reflect.h2" [[nodiscard]] auto escape_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } -#line 3559 "reflect.h2" +#line 3579 "reflect.h2" if (std::string::npos == std::string("afenrt^.[]()*{}?+|\\").find(ctx.peek())) { return nullptr; } @@ -5694,7 +5714,7 @@ size_t i{0}; } -#line 3595 "reflect.h2" +#line 3615 "reflect.h2" [[nodiscard]] auto global_group_reset_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'K'))) {return nullptr; } @@ -5703,19 +5723,19 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, "\\K", "ctx..set_group_start(0, r.pos);"); } -#line 3618 "reflect.h2" +#line 3638 "reflect.h2" group_ref_token::group_ref_token(cpp2::impl::in id_, cpp2::impl::in case_insensitive_, cpp2::impl::in reverse_, cpp2::impl::in str) : regex_token{ str } , id{ id_ } , case_insensitive{ case_insensitive_ } , reverse_eval{ reverse_ } -#line 3619 "reflect.h2" +#line 3639 "reflect.h2" { -#line 3624 "reflect.h2" +#line 3644 "reflect.h2" } -#line 3626 "reflect.h2" +#line 3646 "reflect.h2" [[nodiscard]] auto group_ref_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -5817,19 +5837,19 @@ size_t i{0}; return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, cpp2::move(group_id), ctx.get_modifiers().has(expression_flags::case_insensitive), false, cpp2::move(str)); } -#line 3727 "reflect.h2" +#line 3747 "reflect.h2" [[nodiscard]] auto group_ref_token::reverse() const -> token_ptr{ return CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, id, case_insensitive, !(reverse_eval), to_string()); } -#line 3731 "reflect.h2" +#line 3751 "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 3755 "reflect.h2" +#line 3775 "reflect.h2" [[nodiscard]] auto group_token::parse_lookahead_lookbehind(parse_context& ctx, cpp2::impl::in syntax, cpp2::impl::in lookahead, cpp2::impl::in positive) -> token_ptr { static_cast(ctx.next());// Skip last token defining the syntax @@ -5848,7 +5868,7 @@ size_t i{0}; return r; } -#line 3773 "reflect.h2" +#line 3793 "reflect.h2" [[nodiscard]] auto group_token::parse_atomic_pattern(parse_context& ctx, cpp2::impl::in syntax) -> token_ptr { static_cast(ctx.next());// Skip last token defining the syntax @@ -5863,7 +5883,7 @@ size_t i{0}; return r; } -#line 3787 "reflect.h2" +#line 3807 "reflect.h2" [[nodiscard]] auto group_token::parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '(') {return nullptr; } @@ -6023,7 +6043,7 @@ size_t i{0}; } } -#line 3946 "reflect.h2" +#line 3966 "reflect.h2" [[nodiscard]] auto group_token::reverse() const -> token_ptr{ auto r {CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared)}; (*cpp2::impl::assert_not_null(r)).number = number; @@ -6032,7 +6052,7 @@ size_t i{0}; return r; } -#line 3954 "reflect.h2" +#line 3974 "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 {"("}; @@ -6051,7 +6071,7 @@ size_t i{0}; return cpp2::move(start) + (*cpp2::impl::assert_not_null(inner_)).to_string() + ")"; } -#line 3972 "reflect.h2" +#line 3992 "reflect.h2" auto group_token::generate_code(generation_context& ctx) const -> void { if (-1 != number) { @@ -6083,7 +6103,7 @@ size_t i{0}; } } -#line 4003 "reflect.h2" +#line 4023 "reflect.h2" auto group_token::add_groups(std::set& groups) const -> void { (*cpp2::impl::assert_not_null(inner)).add_groups(groups); @@ -6094,7 +6114,7 @@ size_t i{0}; group_token::~group_token() noexcept{} -#line 4015 "reflect.h2" +#line 4035 "reflect.h2" [[nodiscard]] auto hexadecimal_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'x'))) {return nullptr; } @@ -6133,7 +6153,7 @@ size_t i{0}; return r; } -#line 4056 "reflect.h2" +#line 4076 "reflect.h2" [[nodiscard]] auto line_end_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() == '$' || (ctx.current() == '\\' && ctx.peek() == '$')) { @@ -6151,7 +6171,7 @@ size_t i{0}; }} } -#line 4076 "reflect.h2" +#line 4096 "reflect.h2" [[nodiscard]] auto line_start_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '^' && !((ctx.current() == '\\' && ctx.peek() == 'A'))) {return nullptr; } @@ -6165,16 +6185,16 @@ size_t i{0}; } } -#line 4102 "reflect.h2" +#line 4122 "reflect.h2" lookahead_lookbehind_token::lookahead_lookbehind_token(cpp2::impl::in lookahead_, cpp2::impl::in positive_) : regex_token{ "" } , lookahead{ lookahead_ } , positive{ positive_ }{ -#line 4105 "reflect.h2" +#line 4125 "reflect.h2" } -#line 4107 "reflect.h2" +#line 4127 "reflect.h2" auto lookahead_lookbehind_token::generate_code(generation_context& ctx) const -> void{ auto inner_name {ctx.generate_func(inner)}; @@ -6186,7 +6206,7 @@ size_t i{0}; } } -#line 4118 "reflect.h2" +#line 4138 "reflect.h2" [[nodiscard]] auto lookahead_lookbehind_token::reverse() const -> token_ptr{ auto r {CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared, lookahead, positive)}; (*cpp2::impl::assert_not_null(r)).inner = inner;// We do not reverse here. Nested lookahead and lookbehind stay as they are. @@ -6194,14 +6214,14 @@ size_t i{0}; return r; } -#line 4125 "reflect.h2" +#line 4145 "reflect.h2" auto lookahead_lookbehind_token::add_groups(std::set& groups) const -> void{ (*cpp2::impl::assert_not_null(inner)).add_groups(groups); } lookahead_lookbehind_token::~lookahead_lookbehind_token() noexcept{} -#line 4133 "reflect.h2" +#line 4153 "reflect.h2" [[nodiscard]] auto named_class_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -6227,7 +6247,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 4161 "reflect.h2" +#line 4181 "reflect.h2" [[nodiscard]] auto octal_token_parse(parse_context& ctx) -> token_ptr { if (!((ctx.current() == '\\' && ctx.peek() == 'o'))) {return nullptr; } @@ -6253,11 +6273,11 @@ size_t i{0}; return r; } -#line 4198 "reflect.h2" +#line 4218 "reflect.h2" range_token::range_token() : regex_token{ "" }{} -#line 4200 "reflect.h2" +#line 4220 "reflect.h2" [[nodiscard]] auto range_token::parse(parse_context& ctx) -> token_ptr { auto r {CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared)}; @@ -6331,7 +6351,7 @@ size_t i{0}; return nullptr; } -#line 4273 "reflect.h2" +#line 4293 "reflect.h2" auto range_token::parse_modifier(parse_context& ctx) & -> void { if (ctx.peek() == '?') { @@ -6344,7 +6364,7 @@ size_t i{0}; }} } -#line 4285 "reflect.h2" +#line 4305 "reflect.h2" [[nodiscard]] auto range_token::gen_mod_string() const& -> std::string { if (kind == range_flags::not_greedy) { @@ -6358,7 +6378,7 @@ size_t i{0}; }} } -#line 4298 "reflect.h2" +#line 4318 "reflect.h2" [[nodiscard]] auto range_token::gen_range_string() const& -> std::string { std::string r {""}; @@ -6378,7 +6398,7 @@ size_t i{0}; return r; } -#line 4317 "reflect.h2" +#line 4337 "reflect.h2" [[nodiscard]] auto range_token::reverse() const -> token_ptr{ auto r {CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared)}; (*cpp2::impl::assert_not_null(r)).min_count = min_count; @@ -6389,7 +6409,7 @@ size_t i{0}; return r; } -#line 4327 "reflect.h2" +#line 4347 "reflect.h2" auto range_token::generate_code(generation_context& ctx) const -> void { auto inner_name {ctx.generate_func(inner_token)}; @@ -6401,14 +6421,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 4338 "reflect.h2" +#line 4358 "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 4350 "reflect.h2" +#line 4370 "reflect.h2" [[nodiscard]] auto special_range_token::parse(parse_context& ctx) -> token_ptr { auto r {CPP2_UFCS_TEMPLATE(cpp2_new)(cpp2::shared)}; @@ -6432,7 +6452,7 @@ size_t i{0}; if (!(ctx.has_token())) {return ctx.error("'" + cpp2::to_string(ctx.current()) + "' without previous element."); } -#line 4374 "reflect.h2" +#line 4394 "reflect.h2" (*cpp2::impl::assert_not_null(r)).parse_modifier(ctx); (*cpp2::impl::assert_not_null(r)).inner_token = ctx.pop_token(); @@ -6442,7 +6462,7 @@ size_t i{0}; special_range_token::~special_range_token() noexcept{} -#line 4386 "reflect.h2" +#line 4406 "reflect.h2" [[nodiscard]] auto start_match_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -6458,7 +6478,7 @@ size_t i{0}; } } -#line 4406 "reflect.h2" +#line 4426 "reflect.h2" [[nodiscard]] auto word_boundary_token_parse(parse_context& ctx) -> token_ptr { if (ctx.current() != '\\') {return nullptr; } @@ -6476,15 +6496,15 @@ size_t i{0}; }} } -#line 4442 "reflect.h2" +#line 4462 "reflect.h2" template regex_generator::regex_generator(cpp2::impl::in r, Error_out const& e) : regex{ r } , error_out{ e }{ -#line 4445 "reflect.h2" +#line 4465 "reflect.h2" } -#line 4447 "reflect.h2" +#line 4467 "reflect.h2" template [[nodiscard]] auto regex_generator::parse() & -> std::string { // Extract modifiers and adapt regex. @@ -6520,7 +6540,7 @@ size_t i{0}; return source; } -#line 4482 "reflect.h2" +#line 4502 "reflect.h2" template auto regex_generator::extract_modifiers() & -> void { if (regex.find_first_of("'/") == 0) { @@ -6536,7 +6556,7 @@ size_t i{0}; } } -#line 4498 "reflect.h2" +#line 4518 "reflect.h2" template [[nodiscard]] auto generate_regex(cpp2::impl::in regex, Err const& err) -> std::string { regex_generator parser {regex, err}; @@ -6545,7 +6565,7 @@ template [[nodiscard]] auto generate_regex(cpp2::impl::in void { auto has_default {false}; @@ -6600,7 +6620,7 @@ auto regex_gen(meta::type_declaration& t) -> void CPP2_UFCS(add_runtime_support_include)(t, "cpp2regex.h"); } -#line 4567 "reflect.h2" +#line 4587 "reflect.h2" [[nodiscard]] auto apply_metafunctions( declaration_node& n, type_declaration& rtype, @@ -6716,7 +6736,7 @@ auto regex_gen(meta::type_declaration& t) -> void return true; } -#line 4683 "reflect.h2" +#line 4703 "reflect.h2" } } diff --git a/source/reflect.h2 b/source/reflect.h2 index 4be9b59a0..219187f10 100644 --- a/source/reflect.h2 +++ b/source/reflect.h2 @@ -2189,24 +2189,26 @@ autodiff: (inout t: meta::type_declaration) = additive_terms := shift_terms.front().get_term().get_terms(); if additive_terms.ssize() > 1 { - if additive_terms.ssize() != 2 - || additive_terms[1].get_op() != "+" - { - m.error( "temporary alpha limitation: this initial baby step only supports specifically 'a + b', not subtraction or chains of + and -"); - } + first := true; + for additive_terms do (term) { + if !first { + op := term.get_op().to_string(); + line1 += " (op)$ "; + line2 += " (op)$ "; + } - lhs := additive_terms[0].get_term().to_string(); - if !mf.has_parameter_or_return_named(lhs) { - m.error( "temporary alpha limitation: the addition's left-hand side '(lhs)$' must be a parameter or return name"); - } + var := term.get_term().to_string(); + if !mf.has_parameter_or_return_named(var) { + m.error( "temporary alpha limitation: the addition's left-hand side '(var)$' must be a parameter or return name"); + } + line1 += "(var)$_d"; + line2 += "(var)$"; - rhs := additive_terms[1].get_term().to_string(); - if !mf.has_parameter_or_return_named(rhs) { - m.error( "temporary alpha limitation: the addition's right-hand side '(rhs)$' must be a parameter or return name"); + first = false; } - line1 += "(lhs)$ * (rhs)$_d + (rhs)$ * (lhs)$_d;"; - line2 += "(lhs)$ * (rhs)$;"; + line1 += ";"; + line2 += ";"; diff += line1 + line2; @@ -2220,17 +2222,35 @@ autodiff: (inout t: meta::type_declaration) = multiplicative_terms := additive_terms.front().get_term().get_terms(); if multiplicative_terms.ssize() > 1 { - // TODO: Do whatever is appropriate here... - // For now, just list out what we found (visible via @print)... - diff += "found_multiplicative_with_____"; - count := 0; - for multiplicative_terms do (term) { - if count++ > 1 { - diff += term.get_op() + "___"; - } - diff += term.get_term().to_string() + "___"; + if multiplicative_terms.ssize() != 2 + { + m.error( "temporary alpha limitation: does not support chains of * and /"); } - diff += ";"; + + lhs := multiplicative_terms[0].get_term().to_string(); + if !mf.has_parameter_or_return_named(lhs) { + m.error( "temporary alpha limitation: the addition's left-hand side '(lhs)$' must be a parameter or return name"); + } + + rhs := multiplicative_terms[1].get_term().to_string(); + if !mf.has_parameter_or_return_named(rhs) { + m.error( "temporary alpha limitation: the addition's right-hand side '(rhs)$' must be a parameter or return name"); + } + + op := multiplicative_terms[1].get_op().to_string(); + if "*" == op { + line1 += "(lhs)$ * (rhs)$_d + (rhs)$ * (lhs)$_d;"; + line2 += "(lhs)$ * (rhs)$;"; + } + else if "/" == op { + line1 += "(lhs)$_d / (rhs)$ - (lhs)$ * (rhs)$_d / ((rhs)$ * (rhs)$);"; + line2 += "(lhs)$ / (rhs)$;"; + } + else { + m.error( "unkown multiplicative operator '(op)$'"); + } + + diff += line1 + line2; continue next_statement; }