Skip to content
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

feat: allow authoring module units #569

Closed
wants to merge 6 commits into from
Closed
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
14 changes: 7 additions & 7 deletions include/cpp2util.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
// in our -pure-cpp2 "import std;" simulation mode... if you need this,
// use mixed mode (not -pure-cpp2) and #include all the headers you need
// including this one
//
//
// #include <execution>
#endif

Expand Down Expand Up @@ -464,7 +464,7 @@ template<typename T>
auto Typeid() -> decltype(auto) {
#ifdef CPP2_NO_RTTI
Type.expects(
!"'any' dynamic casting is disabled with -fno-rtti", // more likely to appear on console
!"'any' dynamic casting is disabled with -fno-rtti", // more likely to appear on console
"'any' dynamic casting is disabled with -fno-rtti" // make message available to hooked handlers
);
#else
Expand Down Expand Up @@ -854,17 +854,17 @@ auto is( X const& ) -> bool {

template< typename C, typename X >
requires (
( std::is_base_of_v<X, C> ||
( std::is_polymorphic_v<C> && std::is_polymorphic_v<X>)
( std::is_base_of_v<X, C> ||
( std::is_polymorphic_v<C> && std::is_polymorphic_v<X>)
) && !std::is_same_v<C,X>)
auto is( X const& x ) -> bool {
return Dynamic_cast<C const*>(&x) != nullptr;
}

template< typename C, typename X >
requires (
( std::is_base_of_v<X, C> ||
( std::is_polymorphic_v<C> && std::is_polymorphic_v<X>)
( std::is_base_of_v<X, C> ||
( std::is_polymorphic_v<C> && std::is_polymorphic_v<X>)
) && !std::is_same_v<C,X>)
auto is( X const* x ) -> bool {
return Dynamic_cast<C const*>(x) != nullptr;
Expand Down Expand Up @@ -1452,7 +1452,7 @@ inline auto to_string(std::string const& s) -> std::string const&

template<typename T>
inline auto to_string(T const& sv) -> std::string
requires (std::is_convertible_v<T, std::string_view>
requires (std::is_convertible_v<T, std::string_view>
&& !std::is_convertible_v<T, const char*>)
{
return std::string{sv};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
//=== Cpp2 type definitions and function declarations ===========================

#line 1 "pure2-bugfix-for-requires-clause-unbraced-function-initializer.cpp2"
template<typename T> auto f() -> void;
template<typename T> auto f() -> void
CPP2_REQUIRES (std::regular<T>)
#line 1 "pure2-bugfix-for-requires-clause-unbraced-function-initializer.cpp2"
;
auto main() -> int;


Expand Down
32 changes: 17 additions & 15 deletions source/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct source_line
{
std::string text;

enum class category { empty, preprocessor, comment, import, cpp1, cpp2, rawstring };
enum class category { empty, preprocessor, comment, module_directive, module_declaration, import, cpp1, cpp2, rawstring };
category cat;

bool all_tokens_are_densely_spaced = true; // to be overridden in lexing if they're not
Expand All @@ -73,13 +73,15 @@ struct source_line
-> std::string
{
switch (cat) {
break;case category::empty: return "/* */ ";
break;case category::preprocessor: return "/* # */ ";
break;case category::comment: return "/* / */ ";
break;case category::import: return "/* i */ ";
break;case category::cpp1: return "/* 1 */ ";
break;case category::cpp2: return "/* 2 */ ";
break;case category::rawstring: return "/* R */ ";
break;case category::empty: return "/* */ ";
break;case category::preprocessor: return "/* # */ ";
break;case category::comment: return "/* / */ ";
break;case category::module_directive: return "/* m#*/ ";
break;case category::module_declaration: return "/* m */ ";
break;case category::import: return "/* i */ ";
break;case category::cpp1: return "/* 1 */ ";
break;case category::cpp2: return "/* 2 */ ";
break;case category::rawstring: return "/* R */ ";
break;default: assert(!"illegal category"); abort();
}
}
Expand Down Expand Up @@ -127,7 +129,7 @@ struct string_parts {

string_parts(const std::string& beginseq,
const std::string& endseq,
adds_sequences strateg)
adds_sequences strateg)
: begin_seq{beginseq}
, end_seq{endseq}
, strategy{strateg}
Expand All @@ -144,16 +146,16 @@ struct string_parts {
void clear() { parts.clear(); }

auto generate() const -> std::string {
if (parts.empty()) {
return (strategy & on_the_beginning ? begin_seq : std::string{})
+ (strategy & on_the_end ? end_seq : std::string{});

if (parts.empty()) {
return (strategy & on_the_beginning ? begin_seq : std::string{})
+ (strategy & on_the_end ? end_seq : std::string{});
}

auto result = std::visit(begin_visit{begin_seq, strategy},
auto result = std::visit(begin_visit{begin_seq, strategy},
parts.front());

if (std::ssize(parts) > 1) {
if (std::ssize(parts) > 1) {
auto it1 = parts.cbegin();
auto it2 = parts.cbegin()+1;
for(;it2 != parts.cend(); ++it1, ++it2) {
Expand Down
Loading