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: evaluate program-defined metafunctions (based on #797) #907

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
887 changes: 887 additions & 0 deletions include/cpp2reflect.h

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions include/cpp2util.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,16 @@ constexpr auto gcc_clang_msvc_min_versions(
#define CPP2_CONSTEXPR constexpr
#endif


#if defined(_WIN32)
#define CPPFRONTAPI __declspec(dllexport)
#else
#define CPPFRONTAPI __attribute__ ((visibility ("default")))
#endif

#define CPP2_C_API extern "C" CPPFRONTAPI


namespace cpp2 {


Expand Down Expand Up @@ -2911,4 +2921,15 @@ using cpp2::cpp2_new;
#pragma clang diagnostic pop
#endif

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251)
#endif

#include "cpp2reflect.h"

#ifdef _MSC_VER
#pragma warning(pop)
#endif

#endif // CPP2_CPP2UTIL_H
57 changes: 35 additions & 22 deletions source/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// We want cppfront to build cleanly at very high warning levels, with warnings
// as errors -- so disable a handful that fire incorrectly due to compiler bugs
#ifdef _MSC_VER
#pragma warning(disable: 4456 4706)
#pragma warning(disable: 4456 4706 4996)
#endif
#if defined(__GNUC__) && __GNUC__ >= 13 && !defined(__clang_major__)
#pragma GCC diagnostic ignored "-Wdangling-reference"
Expand Down Expand Up @@ -103,28 +103,11 @@ struct source_line
};


using lineno_t = int32_t;
using colno_t = int32_t; // not int16_t... encountered >80,000 char line during testing
using index_t = int32_t;
using cpp2::meta::lineno_t;
using cpp2::meta::colno_t;
using cpp2::meta::index_t;

struct source_position
{
lineno_t lineno; // one-based offset into program source
colno_t colno; // one-based offset into line

source_position(lineno_t l = 1, colno_t c = 1 )
: lineno{ l }, colno{ c }
{
}

auto operator<=>(source_position const&) const = default;

auto to_string() const
-> std::string
{
return "(" + std::to_string(lineno) + "," + std::to_string(colno) + ")";
}
};
using cpp2::meta::source_position;

struct comment
{
Expand Down Expand Up @@ -521,6 +504,36 @@ auto to_upper_and_underbar(std::string_view s)
}


auto to_lower_and_collapsed_underbar(
std::string_view s,
bool prev_was_underbar = false,
bool drop_back_underbar = false
)
-> std::string
{
auto ret = std::string{};
for (char c : s) {
if (std::isalnum(c)) {
ret.push_back(string_util::safe_tolower(c));
prev_was_underbar = false;
}
else if (!prev_was_underbar) {
ret.push_back('_');
prev_was_underbar = true;
}
}
if (
drop_back_underbar
&& !ret.empty()
&& ret.back() == '_'
)
{
ret.pop_back();
}
return ret;
}


auto is_empty_or_a_decimal_number(std::string_view s)
-> bool
{
Expand Down
Loading