Skip to content

Add conversion functions to ClassSymbol #528

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 2 commits into from
Apr 19, 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
15 changes: 6 additions & 9 deletions src/parser/cxx/control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ template <typename Literal>
using LiteralSet =
std::unordered_set<Literal, LiteralHash<Literal>, LiteralEqualTo<Literal>>;

template <typename Name>
using NameSet = std::set<Name>;

} // namespace

struct Control::Private {
Expand All @@ -75,12 +72,12 @@ struct Control::Private {
LiteralSet<Utf32StringLiteral> utf32StringLiterals;
LiteralSet<CommentLiteral> commentLiterals;

std::set<Identifier, std::less<>> identifiers;
std::set<OperatorId> operatorIds;
std::set<DestructorId> destructorIds;
std::set<LiteralOperatorId> literalOperatorIds;
std::set<ConversionFunctionId> conversionFunctionIds;
std::set<TemplateId> templateIds;
std::unordered_set<Identifier> identifiers;
std::unordered_set<OperatorId> operatorIds;
std::unordered_set<DestructorId> destructorIds;
std::unordered_set<LiteralOperatorId> literalOperatorIds;
std::unordered_set<ConversionFunctionId> conversionFunctionIds;
std::unordered_set<TemplateId> templateIds;

BuiltinVaListType builtinVaListType;
VoidType voidType;
Expand Down
60 changes: 60 additions & 0 deletions src/parser/cxx/names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,63 @@
#include <cxx/ast.h>
#include <cxx/control.h>
#include <cxx/literals.h>
#include <cxx/symbols.h>
#include <cxx/util.h>

#include <cstring>

namespace cxx {

namespace {

struct ConstValueHash {
auto operator()(bool value) const -> std::size_t {
return std::hash<bool>{}(value);
}
auto operator()(std::int32_t value) const -> std::size_t {
return std::hash<std::int32_t>{}(value);
}
auto operator()(std::uint32_t value) const -> std::size_t {
return std::hash<std::uint32_t>{}(value);
}
auto operator()(std::int64_t value) const -> std::size_t {
return std::hash<std::int64_t>{}(value);
}
auto operator()(std::uint64_t value) const -> std::size_t {
return std::hash<std::uint64_t>{}(value);
}
auto operator()(float value) const -> std::size_t {
return std::hash<float>{}(value);
}
auto operator()(double value) const -> std::size_t {
return std::hash<double>{}(value);
}
auto operator()(long double value) const -> std::size_t {
return std::hash<long double>{}(value);
}
auto operator()(const StringLiteral* value) const -> std::size_t {
return value->hashCode();
}
};

struct TemplateArgumentHash {
auto operator()(const Type* arg) const -> std::size_t {
return std::hash<const void*>{}(arg);
}

auto operator()(Symbol* arg) const -> std::size_t {
return arg->name() ? arg->name()->hashValue() : 0;
}

auto operator()(ConstValue arg) const -> std::size_t {
return std::visit(ConstValueHash{}, arg);
}

auto operator()(ExpressionAST* arg) const -> std::size_t {
return std::hash<const void*>{}(arg);
}
};

struct ConvertToName {
Control* control_;

Expand Down Expand Up @@ -107,4 +157,14 @@ auto Identifier::builtinTypeTrait() const -> BuiltinTypeTraitKind {
return static_cast<const TypeTraitIdentifierInfo*>(info_)->trait();
}

auto TemplateId::hash(const Name* name,
const std::vector<TemplateArgument>& args)
-> std::size_t {
std::size_t hash = name->hashValue();
for (const auto& arg : args) {
hash_combine(hash, std::visit(TemplateArgumentHash{}, arg));
}
return hash;
}

} // namespace cxx
Loading