Skip to content

Commit d70601e

Browse files
MaxSagebaumhsutter
andauthored
Separation of metafunction and runtime regex code. (#1219)
* Separation of metafunction and runtime regex code. * Move metafunction work into reflect.h2 Instead of a separate file in ./source * Update of regression tests. * Merge regex metafunction into cpp2::meta namespace The run-time support library stays in `cpp2util.h` and can use the `cpp2::regex::` subnamespace there The compile-time parts stay in `reflect.h2` and use the `cpp2::meta::` namespace there Eventually this can be generalized for user-written metafunctions when those are supported, but for right now this keeps things consistent for the metafunctions supplied in-the-box with cppfront * Add `add_runtime_support_include` to meta For metafunctions that require runtime support via #includes to be injected into lowered Cpp1 programs Also cleanup while I'm at it: - remove headers from `common.h` that are now already included via `cpp2util.h` - line up some thing that got un-lined-up (OCD) --------- Co-authored-by: Herb Sutter <herb.sutter@gmail.com>
1 parent df73616 commit d70601e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+7266
-7156
lines changed

include/cpp2regex.h

+479-3,456
Large diffs are not rendered by default.

include/cpp2regex.h2

+140-2,166
Large diffs are not rendered by default.

include/cpp2util.h

-2
Original file line numberDiff line numberDiff line change
@@ -2824,8 +2824,6 @@ inline constexpr auto as_() -> decltype(auto)
28242824

28252825
}
28262826

2827-
#include "cpp2regex.h"
2828-
28292827
using cpp2::cpp2_new;
28302828

28312829

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pure2-default-arguments.cpp2:6:61: error: no member named 'source_location' in namespace 'std'
2+
char const* fn = CPP2_UFCS_NONLOCAL(function_name)(std::source_location::current())
3+
~~~~~^
4+
1 error generated.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
calling:
2+
012
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pure2-default-arguments.cpp2:6:61: error: no member named 'source_location' in namespace 'std'
2+
char const* fn = CPP2_UFCS_NONLOCAL(function_name)(std::source_location::current())
3+
~~~~~^
4+
1 error generated.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
calling:
2+
012
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pure2-default-arguments.cpp2:6:56: error: cannot take address of consteval function 'current' outside of an immediate invocation
2+
6 | char const* fn = CPP2_UFCS_NONLOCAL(function_name)(std::source_location::current())
3+
| ^
4+
/usr/bin/../lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/source_location:60:5: note: declared here
5+
60 | current(__builtin_ret_type __p = __builtin_source_location()) noexcept
6+
| ^
7+
1 error generated.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pure2-default-arguments.cpp2:6:56: error: cannot take address of consteval function 'current' outside of an immediate invocation
2+
6 | char const* fn = CPP2_UFCS_NONLOCAL(function_name)(std::source_location::current())
3+
| ^
4+
/usr/lib/llvm-18/bin/../include/c++/v1/source_location:60:36: note: declared here
5+
60 | static consteval source_location current(__bsl_ty __ptr = __builtin_source_location()) noexcept {
6+
| ^
7+
1 error generated.

regression-tests/test-results/gcc-10-c++20/pure2-bugfix-for-requires-clause-in-forward-declaration.cpp.output

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:46: error: expect
66
In file included from pure2-bugfix-for-requires-clause-in-forward-declaration.cpp:7:
77
../../../include/cpp2util.h:10005:47: error: static assertion failed: GCC 11 or higher is required to support variables and type-scope functions that have a 'requires' clause. This includes a type-scope 'forward' parameter of non-wildcard type, such as 'func: (this, forward s: std::string)', which relies on being able to add a 'requires' clause - in that case, use 'forward s: _' instead if you need the result to compile with GCC 10.
88
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:4:1: note: in expansion of macro ‘CPP2_REQUIRES_’
9-
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:3: error: no declaration matches ‘element::element(auto:261&&) requires is_same_v<std::__cxx11::string, typename std::remove_cv<typename std::remove_reference<decltype(element::__ct ::n)>::type>::type>’
9+
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:3: error: no declaration matches ‘element::element(auto:95&&) requires is_same_v<std::__cxx11::string, typename std::remove_cv<typename std::remove_reference<decltype(element::__ct ::n)>::type>::type>’
1010
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:5:11: note: candidates are: ‘element::element(const element&)’
11-
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:20: note: ‘template<class auto:259> element::element(auto:259&&)’
11+
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:20: note: ‘template<class auto:93> element::element(auto:93&&)’
1212
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:1:7: note: ‘class element’ defined here
1313
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:5:78: error: expected unqualified-id before ‘{’ token
14-
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:8: error: no declaration matches ‘element& element::operator=(auto:262&&) requires is_same_v<std::__cxx11::string, typename std::remove_cv<typename std::remove_reference<decltype(element::operator=::n)>::type>::type>’
14+
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:8: error: no declaration matches ‘element& element::operator=(auto:96&&) requires is_same_v<std::__cxx11::string, typename std::remove_cv<typename std::remove_reference<decltype(element::operator=::n)>::type>::type>’
1515
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:6:16: note: candidates are: ‘void element::operator=(const element&)’
16-
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:16: note: ‘template<class auto:260> element& element::operator=(auto:260&&)’
16+
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:16: note: ‘template<class auto:94> element& element::operator=(auto:94&&)’
1717
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:1:7: note: ‘class element’ defined here

regression-tests/test-results/gcc-10-c++20/pure2-print.cpp.output

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ pure2-print.cpp2:68:1: note: in expansion of macro ‘CPP2_REQUIRES_’
99
pure2-print.cpp2:97:1: note: in expansion of macro ‘CPP2_REQUIRES_’
1010
pure2-print.cpp2:9:41: error: ‘constexpr const T outer::object_alias’ is not a static data member of ‘class outer’
1111
pure2-print.cpp2:9:48: error: template definition of non-template ‘constexpr const T outer::object_alias’
12-
pure2-print.cpp2:67:14: error: no declaration matches ‘void outer::mytype::variadic(const auto:260& ...) requires (is_convertible_v<typename std::remove_cv<typename std::remove_reference<decltype(outer::mytype::variadic::x)>::type>::type, int> && ...)’
13-
pure2-print.cpp2:67:29: note: candidate is: ‘template<class ... auto:259> static void outer::mytype::variadic(const auto:259& ...)’
12+
pure2-print.cpp2:67:14: error: no declaration matches ‘void outer::mytype::variadic(const auto:94& ...) requires (is_convertible_v<typename std::remove_cv<typename std::remove_reference<decltype(outer::mytype::variadic::x)>::type>::type, int> && ...)’
13+
pure2-print.cpp2:67:29: note: candidate is: ‘template<class ... auto:93> static void outer::mytype::variadic(const auto:93& ...)’
1414
pure2-print.cpp2:10:19: note: ‘class outer::mytype’ defined here
1515
pure2-print.cpp2:96:37: error: no declaration matches ‘void outer::print(std::ostream&, const Args& ...) requires cpp2::impl::cmp_greater_eq(sizeof ... (Args ...), 0)’
1616
pure2-print.cpp2:96:37: note: no functions named ‘void outer::print(std::ostream&, const Args& ...) requires cpp2::impl::cmp_greater_eq(sizeof ... (Args ...), 0)’
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
mixed-bounds-safety-with-assert.cpp2(11) void print_subrange(const auto:263&, cpp2::impl::in<int>, cpp2::impl::in<int>) [with auto:263 = std::vector<int>; cpp2::impl::in<int> = const int]: Bounds safety violation
1+
mixed-bounds-safety-with-assert.cpp2(11) void print_subrange(const auto:243&, cpp2::impl::in<int>, cpp2::impl::in<int>) [with auto:243 = std::vector<int>; cpp2::impl::in<int> = const int]: Bounds safety violation
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
calling: int main(int, char**)
2+
012

regression-tests/test-results/gcc-14-c++2b/gcc-version.output

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
g++ (GCC) 14.1.1 20240701 (Red Hat 14.1.1-7)
1+
g++ (GCC) 14.2.1 20240801 (Red Hat 14.2.1-1)
22
Copyright (C) 2024 Free Software Foundation, Inc.
33
This is free software; see the source for copying conditions. There is NO
44
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
mixed-bounds-safety-with-assert.cpp2(11) void print_subrange(const auto:257&, cpp2::impl::in<int>, cpp2::impl::in<int>) [with auto:257 = std::vector<int>; cpp2::impl::in<int> = const int]: Bounds safety violation
1+
mixed-bounds-safety-with-assert.cpp2(11) void print_subrange(const auto:91&, cpp2::impl::in<int>, cpp2::impl::in<int>) [with auto:91 = std::vector<int>; cpp2::impl::in<int> = const int]: Bounds safety violation
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
calling: int __cdecl main(const int,char **)
2+
012
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pure2-default-arguments.cpp

regression-tests/test-results/pure2-regex_01_char_matcher.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#define CPP2_IMPORT_STD Yes
3+
#include "cpp2regex.h"
34

45
//=== Cpp2 type declarations ====================================================
56

regression-tests/test-results/pure2-regex_02_ranges.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#define CPP2_IMPORT_STD Yes
3+
#include "cpp2regex.h"
34

45
//=== Cpp2 type declarations ====================================================
56

regression-tests/test-results/pure2-regex_03_wildcard.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#define CPP2_IMPORT_STD Yes
3+
#include "cpp2regex.h"
34

45
//=== Cpp2 type declarations ====================================================
56

regression-tests/test-results/pure2-regex_04_start_end.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#define CPP2_IMPORT_STD Yes
3+
#include "cpp2regex.h"
34

45
//=== Cpp2 type declarations ====================================================
56

regression-tests/test-results/pure2-regex_05_classes.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#define CPP2_IMPORT_STD Yes
3+
#include "cpp2regex.h"
34

45
//=== Cpp2 type declarations ====================================================
56

regression-tests/test-results/pure2-regex_06_boundaries.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#define CPP2_IMPORT_STD Yes
3+
#include "cpp2regex.h"
34

45
//=== Cpp2 type declarations ====================================================
56

regression-tests/test-results/pure2-regex_07_short_classes.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#define CPP2_IMPORT_STD Yes
3+
#include "cpp2regex.h"
34

45
//=== Cpp2 type declarations ====================================================
56

regression-tests/test-results/pure2-regex_08_alternatives.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#define CPP2_IMPORT_STD Yes
3+
#include "cpp2regex.h"
34

45
//=== Cpp2 type declarations ====================================================
56

regression-tests/test-results/pure2-regex_09_groups.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#define CPP2_IMPORT_STD Yes
3+
#include "cpp2regex.h"
34

45
//=== Cpp2 type declarations ====================================================
56

regression-tests/test-results/pure2-regex_10_escapes.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#define CPP2_IMPORT_STD Yes
3+
#include "cpp2regex.h"
34

45
//=== Cpp2 type declarations ====================================================
56

regression-tests/test-results/pure2-regex_11_group_references.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#define CPP2_IMPORT_STD Yes
3+
#include "cpp2regex.h"
34

45
//=== Cpp2 type declarations ====================================================
56

regression-tests/test-results/pure2-regex_12_case_insensitive.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#define CPP2_IMPORT_STD Yes
3+
#include "cpp2regex.h"
34

45
//=== Cpp2 type declarations ====================================================
56

regression-tests/test-results/pure2-regex_13_possessive_modifier.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#define CPP2_IMPORT_STD Yes
3+
#include "cpp2regex.h"
34

45
//=== Cpp2 type declarations ====================================================
56

regression-tests/test-results/pure2-regex_14_multiline_modifier.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#define CPP2_IMPORT_STD Yes
3+
#include "cpp2regex.h"
34

45
//=== Cpp2 type declarations ====================================================
56

regression-tests/test-results/pure2-regex_15_group_modifiers.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#define CPP2_IMPORT_STD Yes
3+
#include "cpp2regex.h"
34

45
//=== Cpp2 type declarations ====================================================
56

regression-tests/test-results/pure2-regex_16_perl_syntax_modifier.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#define CPP2_IMPORT_STD Yes
3+
#include "cpp2regex.h"
34

45
//=== Cpp2 type declarations ====================================================
56

regression-tests/test-results/pure2-regex_17_comments.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#define CPP2_IMPORT_STD Yes
3+
#include "cpp2regex.h"
34

45
//=== Cpp2 type declarations ====================================================
56

regression-tests/test-results/pure2-regex_18_branch_reset.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#define CPP2_IMPORT_STD Yes
3+
#include "cpp2regex.h"
34

45
//=== Cpp2 type declarations ====================================================
56

regression-tests/test-results/pure2-regex_19_lookahead.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#define CPP2_IMPORT_STD Yes
3+
#include "cpp2regex.h"
34

45
//=== Cpp2 type declarations ====================================================
56

source/common.h

-9
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,11 @@
4747
#ifndef CPP2_COMMON_H
4848
#define CPP2_COMMON_H
4949

50-
#include <algorithm>
5150
#include <cassert>
5251
#include <cctype>
5352
#include <chrono>
54-
#include <compare>
55-
#include <cstdint>
5653
#include <iomanip>
57-
#include <iterator>
58-
#include <memory>
59-
#include <map>
60-
#include <string>
61-
#include <string_view>
6254
#include <unordered_map>
63-
#include <vector>
6455

6556
namespace cpp2 {
6657

source/parse.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -5539,6 +5539,7 @@ auto pretty_print_visualize(translation_unit_node const& n)
55395539
class parser
55405540
{
55415541
std::vector<error_entry>& errors;
5542+
std::set<std::string>& includes;
55425543

55435544
std::unique_ptr<translation_unit_node> parse_tree = {};
55445545

@@ -5584,10 +5585,10 @@ class parser
55845585
}
55855586
};
55865587

5587-
std::vector<token> const* tokens = {};
5588+
std::vector<token> const* tokens = {};
55885589
stable_vector<token>* generated_tokens = {};
5589-
int pos = 0;
5590-
std::string parse_kind = {};
5590+
int pos = 0;
5591+
std::string parse_kind = {};
55915592

55925593
// Keep track of the function bodies' locations - used to emit comments
55935594
// in the right pass (decide whether it's a comment that belongs with
@@ -5663,13 +5664,18 @@ class parser
56635664
//
56645665
// errors error list
56655666
//
5666-
parser( std::vector<error_entry>& errors_ )
5667+
parser(
5668+
std::vector<error_entry>& errors_,
5669+
std::set<std::string>& includes_
5670+
)
56675671
: errors{ errors_ }
5672+
, includes{ includes_ }
56685673
, parse_tree{std::make_unique<translation_unit_node>()}
56695674
{ }
56705675

56715676
parser( parser const& that )
56725677
: errors{ that.errors }
5678+
, includes{ that.includes }
56735679
, parse_tree{std::make_unique<translation_unit_node>()}
56745680
{ }
56755681

0 commit comments

Comments
 (0)