Skip to content

Separation of metafunction and runtime regex code. #1219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,935 changes: 479 additions & 3,456 deletions include/cpp2regex.h

Large diffs are not rendered by default.

2,306 changes: 140 additions & 2,166 deletions include/cpp2regex.h2

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions include/cpp2util.h
Original file line number Diff line number Diff line change
Expand Up @@ -2813,8 +2813,6 @@ inline constexpr auto as_() -> decltype(auto)

}

#include "cpp2regex.h"

using cpp2::cpp2_new;


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pure2-default-arguments.cpp2:6:61: error: no member named 'source_location' in namespace 'std'
char const* fn = CPP2_UFCS_NONLOCAL(function_name)(std::source_location::current())
~~~~~^
1 error generated.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
calling:
012
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pure2-default-arguments.cpp2:6:61: error: no member named 'source_location' in namespace 'std'
char const* fn = CPP2_UFCS_NONLOCAL(function_name)(std::source_location::current())
~~~~~^
1 error generated.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
calling:
012
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pure2-default-arguments.cpp2:6:56: error: cannot take address of consteval function 'current' outside of an immediate invocation
6 | char const* fn = CPP2_UFCS_NONLOCAL(function_name)(std::source_location::current())
| ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/source_location:60:5: note: declared here
60 | current(__builtin_ret_type __p = __builtin_source_location()) noexcept
| ^
1 error generated.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pure2-default-arguments.cpp2:6:56: error: cannot take address of consteval function 'current' outside of an immediate invocation
6 | char const* fn = CPP2_UFCS_NONLOCAL(function_name)(std::source_location::current())
| ^
/usr/lib/llvm-18/bin/../include/c++/v1/source_location:60:36: note: declared here
60 | static consteval source_location current(__bsl_ty __ptr = __builtin_source_location()) noexcept {
| ^
1 error generated.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:46: error: expect
In file included from pure2-bugfix-for-requires-clause-in-forward-declaration.cpp:7:
../../../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.
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:4:1: note: in expansion of macro ‘CPP2_REQUIRES_’
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>’
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>’
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:5:11: note: candidates are: ‘element::element(const element&)’
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:20: note: ‘template<class auto:259> element::element(auto:259&&)’
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:20: note: ‘template<class auto:93> element::element(auto:93&&)’
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:1:7: note: ‘class element’ defined here
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:5:78: error: expected unqualified-id before ‘{’ token
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>’
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>’
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:6:16: note: candidates are: ‘void element::operator=(const element&)’
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:16: note: ‘template<class auto:260> element& element::operator=(auto:260&&)’
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:16: note: ‘template<class auto:94> element& element::operator=(auto:94&&)’
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:1:7: note: ‘class element’ defined here
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ pure2-print.cpp2:68:1: note: in expansion of macro ‘CPP2_REQUIRES_’
pure2-print.cpp2:97:1: note: in expansion of macro ‘CPP2_REQUIRES_’
pure2-print.cpp2:9:41: error: ‘constexpr const T outer::object_alias’ is not a static data member of ‘class outer’
pure2-print.cpp2:9:48: error: template definition of non-template ‘constexpr const T outer::object_alias’
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> && ...)’
pure2-print.cpp2:67:29: note: candidate is: ‘template<class ... auto:259> static void outer::mytype::variadic(const auto:259& ...)’
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> && ...)’
pure2-print.cpp2:67:29: note: candidate is: ‘template<class ... auto:93> static void outer::mytype::variadic(const auto:93& ...)’
pure2-print.cpp2:10:19: note: ‘class outer::mytype’ defined here
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)’
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)’
Expand Down
Original file line number Diff line number Diff line change
@@ -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
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 number Diff line number Diff line change
@@ -0,0 +1,2 @@
calling: int main(int, char**)
012
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
g++ (GCC) 14.1.1 20240701 (Red Hat 14.1.1-7)
g++ (GCC) 14.2.1 20240801 (Red Hat 14.2.1-1)
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Expand Down
Original file line number Diff line number Diff line change
@@ -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
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 number Diff line number Diff line change
@@ -0,0 +1,2 @@
calling: int __cdecl main(const int,char **)
012
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pure2-default-arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ Running tests_10_escapes:
08_y: OK regex: foo(\h)bar parsed_regex: foo(\h)bar str: foo bar result_expr: $1 expected_results
09_y: OK regex: (\H)(\h) parsed_regex: (\H)(\h) str: foo bar result_expr: $1-$2 expected_results o-
10_y: OK regex: (\h)(\H) parsed_regex: (\h)(\H) str: foo bar result_expr: $1-$2 expected_results -b
11_y: OK regex: foo(\v+)bar parsed_regex: foo(\v+)bar str: foo
11_y: OK regex: foo(\v+)bar parsed_regex: foo(\v+)bar str: foo


bar result_expr: $1 expected_results


bar result_expr: $1 expected_results

12_y: OK regex: (\V+)(\v) parsed_regex: (\V+)(\v) str: foo


bar result_expr: $1-$2 expected_results foo-
13_y: OK regex: (\v+)(\V) parsed_regex: (\v+)(\V) str: foo


12_y: OK regex: (\V+)(\v) parsed_regex: (\V+)(\v) str: foo


bar result_expr: $1-$2 expected_results foo-
13_y: OK regex: (\v+)(\V) parsed_regex: (\v+)(\V) str: foo


bar result_expr: $1-$2 expected_results

bar result_expr: $1-$2 expected_results


-b
14_y: OK regex: foo(\v)bar parsed_regex: foo(\v)bar str: foobar result_expr: $1 expected_results
15_y: OK regex: (\V)(\v) parsed_regex: (\V)(\v) str: foobar result_expr: $1-$2 expected_results o-
14_y: OK regex: foo(\v)bar parsed_regex: foo(\v)bar str: foobar result_expr: $1 expected_results
15_y: OK regex: (\V)(\v) parsed_regex: (\V)(\v) str: foobar result_expr: $1-$2 expected_results o-
16_y: OK regex: (\v)(\V) parsed_regex: (\v)(\V) str: foobar result_expr: $1-$2 expected_results -b
17_y: OK regex: foo\t\n\r\f\a\ebar parsed_regex: foo\t\n\r\f\a\ebar str: foo
bar result_expr: $& expected_results foo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#define CPP2_IMPORT_STD Yes
#include "cpp2regex.h"

//=== Cpp2 type declarations ====================================================

Expand Down
1 change: 1 addition & 0 deletions regression-tests/test-results/pure2-regex_02_ranges.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#define CPP2_IMPORT_STD Yes
#include "cpp2regex.h"

//=== Cpp2 type declarations ====================================================

Expand Down
1 change: 1 addition & 0 deletions regression-tests/test-results/pure2-regex_03_wildcard.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#define CPP2_IMPORT_STD Yes
#include "cpp2regex.h"

//=== Cpp2 type declarations ====================================================

Expand Down
1 change: 1 addition & 0 deletions regression-tests/test-results/pure2-regex_04_start_end.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#define CPP2_IMPORT_STD Yes
#include "cpp2regex.h"

//=== Cpp2 type declarations ====================================================

Expand Down
1 change: 1 addition & 0 deletions regression-tests/test-results/pure2-regex_05_classes.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#define CPP2_IMPORT_STD Yes
#include "cpp2regex.h"

//=== Cpp2 type declarations ====================================================

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#define CPP2_IMPORT_STD Yes
#include "cpp2regex.h"

//=== Cpp2 type declarations ====================================================

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#define CPP2_IMPORT_STD Yes
#include "cpp2regex.h"

//=== Cpp2 type declarations ====================================================

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#define CPP2_IMPORT_STD Yes
#include "cpp2regex.h"

//=== Cpp2 type declarations ====================================================

Expand Down
1 change: 1 addition & 0 deletions regression-tests/test-results/pure2-regex_09_groups.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#define CPP2_IMPORT_STD Yes
#include "cpp2regex.h"

//=== Cpp2 type declarations ====================================================

Expand Down
1 change: 1 addition & 0 deletions regression-tests/test-results/pure2-regex_10_escapes.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#define CPP2_IMPORT_STD Yes
#include "cpp2regex.h"

//=== Cpp2 type declarations ====================================================

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#define CPP2_IMPORT_STD Yes
#include "cpp2regex.h"

//=== Cpp2 type declarations ====================================================

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#define CPP2_IMPORT_STD Yes
#include "cpp2regex.h"

//=== Cpp2 type declarations ====================================================

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#define CPP2_IMPORT_STD Yes
#include "cpp2regex.h"

//=== Cpp2 type declarations ====================================================

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#define CPP2_IMPORT_STD Yes
#include "cpp2regex.h"

//=== Cpp2 type declarations ====================================================

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#define CPP2_IMPORT_STD Yes
#include "cpp2regex.h"

//=== Cpp2 type declarations ====================================================

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#define CPP2_IMPORT_STD Yes
#include "cpp2regex.h"

//=== Cpp2 type declarations ====================================================

Expand Down
1 change: 1 addition & 0 deletions regression-tests/test-results/pure2-regex_17_comments.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#define CPP2_IMPORT_STD Yes
#include "cpp2regex.h"

//=== Cpp2 type declarations ====================================================

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#define CPP2_IMPORT_STD Yes
#include "cpp2regex.h"

//=== Cpp2 type declarations ====================================================

Expand Down
1 change: 1 addition & 0 deletions regression-tests/test-results/pure2-regex_19_lookahead.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#define CPP2_IMPORT_STD Yes
#include "cpp2regex.h"

//=== Cpp2 type declarations ====================================================

Expand Down
9 changes: 0 additions & 9 deletions source/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,11 @@
#ifndef CPP2_COMMON_H
#define CPP2_COMMON_H

#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#include <compare>
#include <cstdint>
#include <iomanip>
#include <iterator>
#include <memory>
#include <map>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>

namespace cpp2 {

Expand Down
14 changes: 10 additions & 4 deletions source/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -5532,6 +5532,7 @@ auto pretty_print_visualize(translation_unit_node const& n)
class parser
{
std::vector<error_entry>& errors;
std::set<std::string>& includes;

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

Expand Down Expand Up @@ -5577,10 +5578,10 @@ class parser
}
};

std::vector<token> const* tokens = {};
std::vector<token> const* tokens = {};
stable_vector<token>* generated_tokens = {};
int pos = 0;
std::string parse_kind = {};
int pos = 0;
std::string parse_kind = {};

// Keep track of the function bodies' locations - used to emit comments
// in the right pass (decide whether it's a comment that belongs with
Expand Down Expand Up @@ -5656,13 +5657,18 @@ class parser
//
// errors error list
//
parser( std::vector<error_entry>& errors_ )
parser(
std::vector<error_entry>& errors_,
std::set<std::string>& includes_
)
: errors{ errors_ }
, includes{ includes_ }
, parse_tree{std::make_unique<translation_unit_node>()}
{ }

parser( parser const& that )
: errors{ that.errors }
, includes{ that.includes }
, parse_tree{std::make_unique<translation_unit_node>()}
{ }

Expand Down
Loading
Loading