Skip to content

Commit

Permalink
Add add_runtime_support_include to meta
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
hsutter committed Aug 10, 2024
1 parent 0260d44 commit 5b6eda2
Show file tree
Hide file tree
Showing 31 changed files with 714 additions and 680 deletions.
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
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:241&&) 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:239> element::element(auto:239&&)’
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:242&&) 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:240> element& element::operator=(auto:240&&)’
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:240& ...) 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:239> static void outer::mytype::variadic(const auto:239& ...)’
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,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:237&, cpp2::impl::in<int>, cpp2::impl::in<int>) [with auto:237 = 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
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

0 comments on commit 5b6eda2

Please sign in to comment.