Skip to content

reserved legible names are automatically generated #891

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 1 commit into from
Apr 1, 2025
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
7 changes: 5 additions & 2 deletions include/mrdocs/ADT/UnorderedStringMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace clang::mrdocs {

struct string_hash
struct StringHash
{
using hash_type = std::hash<std::string_view>;
using is_transparent = void;
Expand All @@ -27,7 +27,10 @@ struct string_hash
};

template <class T>
using UnorderedStringMap = std::unordered_map<std::string, T, string_hash, std::equal_to<>>;
using UnorderedStringMap = std::unordered_map<std::string, T, StringHash, std::equal_to<>>;

template <class T>
using UnorderedStringMultiMap = std::unordered_multimap<std::string, T, StringHash, std::equal_to<>>;

} // clang::mrdocs

Expand Down
54 changes: 53 additions & 1 deletion include/mrdocs/Metadata/Info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ tag_invoke(
v = toString(kind);
}

consteval
std::underlying_type_t<InfoKind>
countInfoKind()
{
std::underlying_type_t<InfoKind> count = 0;
#define INFO(Type) count++;
#include <mrdocs/Metadata/InfoNodesPascal.inc>
return count;
}

/** Base class with common properties of all symbols
*/
struct MRDOCS_VISIBLE Info
Expand Down Expand Up @@ -136,7 +146,49 @@ struct MRDOCS_VISIBLE Info
{
}

#define INFO(Type) constexpr bool is##Type() const noexcept { return Kind == InfoKind::Type; }
#define INFO(Type) constexpr bool is##Type() const noexcept { \
return Kind == InfoKind::Type; \
}
#include <mrdocs/Metadata/InfoNodesPascal.inc>

constexpr Info const& asInfo() const noexcept
{
return *this;
}

constexpr Info& asInfo() noexcept
{
return *this;
}

#define INFO(Type) \
constexpr Type##Info const& as##Type() const noexcept { \
if (Kind == InfoKind::Type) \
return reinterpret_cast<Type##Info const&>(*this); \
MRDOCS_UNREACHABLE(); \
}
#include <mrdocs/Metadata/InfoNodesPascal.inc>

#define INFO(Type) \
constexpr Type##Info & as##Type() noexcept { \
if (Kind == InfoKind::Type) \
return reinterpret_cast<Type##Info&>(*this); \
MRDOCS_UNREACHABLE(); \
}
#include <mrdocs/Metadata/InfoNodesPascal.inc>

#define INFO(Type) \
constexpr Type##Info const* as##Type##Ptr() const noexcept { \
if (Kind == InfoKind::Type) { return reinterpret_cast<Type##Info const*>(this); } \
return nullptr; \
}
#include <mrdocs/Metadata/InfoNodesPascal.inc>

#define INFO(Type) \
constexpr Type##Info * as##Type##Ptr() noexcept { \
if (Kind == InfoKind::Type) { return reinterpret_cast<Type##Info *>(this); } \
return nullptr; \
}
#include <mrdocs/Metadata/InfoNodesPascal.inc>

auto operator<=>(Info const&) const = default;
Expand Down
10 changes: 10 additions & 0 deletions include/mrdocs/Metadata/Source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ struct MRDOCS_DECL
*/
std::vector<Location> Loc;

constexpr SourceInfo const& asSourceInfo() const noexcept
{
return *this;
}

constexpr SourceInfo& asSourceInfo() noexcept
{
return *this;
}

constexpr virtual ~SourceInfo() = default;

auto operator<=>(SourceInfo const&) const = default;
Expand Down
277 changes: 277 additions & 0 deletions include/mrdocs/Support/String.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,283 @@ endsWithOneOf(std::string_view s, std::string_view chars) noexcept
return !s.empty() && chars.find(s.back()) != std::string_view::npos;
}

constexpr
bool
isLowerCase(char const c) noexcept
{
return c >= 'a' && c <= 'z';
}

constexpr
bool
isLowerCase(std::string_view const s) noexcept
{
for (char const c : s)
{
if (!isLowerCase(c))
{
return false;
}
}
return true;
}

constexpr
bool
isUpperCase(char const c) noexcept
{
return c >= 'A' && c <= 'Z';
}

constexpr
bool
isUpperCase(std::string_view const s) noexcept
{
for (char const c : s)
{
if (!isUpperCase(c))
{
return false;
}
}
return true;
}

constexpr
char
toLowerCase(char const c) noexcept
{
return isUpperCase(c) ? c + ('a' - 'A') : c;
}

constexpr
std::string
toLowerCase(std::string_view const s) noexcept
{
std::string result;
result.reserve(s.size());
for (char const c : s)
{
result.push_back(toLowerCase(c));
}
return result;
}

constexpr
char
toUpperCase(char const c) noexcept
{
return isLowerCase(c) ? c - ('a' - 'A') : c;
}

constexpr
std::string
toUpperCase(std::string_view const s) noexcept
{
std::string result;
result.reserve(s.size());
for (char const c : s)
{
result.push_back(toUpperCase(c));
}
return result;
}

constexpr
bool
isDigit(char const c) noexcept
{
return c >= '0' && c <= '9';
}

constexpr
bool
isDigit(std::string_view const s) noexcept
{
for (char const c : s)
{
if (!isDigit(c))
{
return false;
}
}
return true;
}

constexpr
bool
isAlphabetic(char const c) noexcept
{
return isLowerCase(c) || isUpperCase(c);
}

constexpr
bool
isAlphabetic(std::string_view const s) noexcept
{
for (char const c : s)
{
if (!isAlphabetic(c))
{
return false;
}
}
return true;
}

constexpr
bool
isAlphaNumeric(char const c) noexcept
{
return isAlphabetic(c) || isDigit(c);
}

constexpr
bool
isAlphaNumeric(std::string_view const s) noexcept
{
for (char const c : s)
{
if (!isAlphaNumeric(c))
{
return false;
}
}
return true;
}

constexpr
std::string
toKebabCase(std::string_view const input)
{
std::string result;
size_t extraSizeCount = 0;
for (std::size_t i = 1; i < input.size(); ++i) {
if (isUpperCase(input[i])) {
++extraSizeCount;
}
}
result.reserve(input.size() + extraSizeCount);
for (size_t i = 0; i < input.size(); ++i) {
if (char const c = input[i];
isUpperCase(c))
{
if (i != 0) {
result.push_back('-');
}
result.push_back(toLowerCase(c));
}
else if (isLowerCase(c) || isDigit(c))
{
result.push_back(c);
}
else
{
result.push_back('-');
}
}
return result;
}

constexpr
std::string
toSnakeCase(std::string_view const input)
{
std::string result;
size_t extraSizeCount = 0;
for (std::size_t i = 1; i < input.size(); ++i) {
if (isUpperCase(input[i]))
{
++extraSizeCount;
}
}
result.reserve(input.size() + extraSizeCount);
for (size_t i = 0; i < input.size(); ++i) {
if (char const c = input[i];
isUpperCase(c))
{
if (i != 0)
{
result.push_back('_');
}
result.push_back(toLowerCase(c));
}
else if (isLowerCase(c) || isDigit(c))
{
result.push_back(c);
}
else
{
result.push_back('_');
}
}
return result;
}

constexpr
std::string
toCamelCase(std::string_view const input)
{
std::string result;
result.reserve(input.size());
bool forceUppercaseNext = false;
for (char const c : input)
{
if (isAlphaNumeric(c))
{
if (result.empty())
{
result.push_back(toLowerCase(c));
forceUppercaseNext = false;
}
else if (forceUppercaseNext)
{
result.push_back(toUpperCase(c));
forceUppercaseNext = false;
}
else
{
result.push_back(c);
}
}
else
{
forceUppercaseNext = true;
}
}
return result;
}

constexpr
std::string
toPascalCase(std::string_view const input)
{
std::string result;
result.reserve(input.size());
bool forceUppercaseNext = true;
for (char const c : input)
{
if (isAlphaNumeric(c))
{
if (forceUppercaseNext)
{
result.push_back(toUpperCase(c));
forceUppercaseNext = false;
}
else
{
result.push_back(c);
}
}
else
{
forceUppercaseNext = true;
}
}
return result;
}


} // clang::mrdocs

#endif
Loading
Loading