Skip to content
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
1 change: 1 addition & 0 deletions checker/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ cc_library(
deps = [
":type_check_issue",
"//common:ast",
"//common:decl",
"//common:source",
"//common:type",
"@com_google_absl//absl/base:nullability",
Expand Down
1 change: 1 addition & 0 deletions checker/validation_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "absl/types/span.h"
#include "checker/type_check_issue.h"
#include "common/ast.h"
#include "common/decl.h"
#include "common/source.h"
#include "common/type.h"

Expand Down
64 changes: 64 additions & 0 deletions common/decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,70 @@ bool TypeIsAssignable(const Type& to, const Type& from);

} // namespace common_internal

struct VariableDeclEqualTo {
using is_transparent = void;

bool operator()(const cel::VariableDecl& lhs,
const cel::VariableDecl& rhs) const {
return lhs.name() == rhs.name();
}

bool operator()(const cel::VariableDecl& lhs, std::string_view rhs) const {
return lhs.name() == rhs;
}

bool operator()(std::string_view lhs, const cel::VariableDecl& rhs) const {
return lhs == rhs.name();
}
};

struct VariableDeclHash {
using is_transparent = void;

size_t operator()(const cel::VariableDecl& decl) const {
return (*this)(decl.name());
}

size_t operator()(std::string_view name) const { return absl::HashOf(name); }
};

using VariableDeclSet = absl::flat_hash_set<cel::VariableDecl, VariableDeclHash,
VariableDeclEqualTo>;

struct FunctionDeclEqualTo {
using is_transparent = void;

bool operator()(const cel::FunctionDecl& lhs,
const cel::FunctionDecl& rhs) const {
return (*this)(lhs.name(), rhs.name());
}

bool operator()(const cel::FunctionDecl& lhs, std::string_view rhs) const {
return (*this)(lhs.name(), rhs);
}

bool operator()(std::string_view lhs, const cel::FunctionDecl& rhs) const {
return (*this)(lhs, rhs.name());
}

bool operator()(std::string_view lhs, std::string_view rhs) const {
return lhs == rhs;
}
};

struct FunctionDeclHash {
using is_transparent = void;

size_t operator()(const cel::FunctionDecl& decl) const {
return absl::HashOf(decl.name());
}

size_t operator()(std::string_view name) const { return absl::HashOf(name); }
};

using FunctionDeclSet = absl::flat_hash_set<cel::FunctionDecl, FunctionDeclHash,
FunctionDeclEqualTo>;

} // namespace cel

#endif // THIRD_PARTY_CEL_CPP_COMMON_DECL_H_