Skip to content

Commit 903210f

Browse files
jckingcopybara-github
authored andcommitted
Internal change
PiperOrigin-RevId: 933263369
1 parent c8c187f commit 903210f

3 files changed

Lines changed: 66 additions & 0 deletions

File tree

checker/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ cc_library(
4949
deps = [
5050
":type_check_issue",
5151
"//common:ast",
52+
"//common:decl",
5253
"//common:source",
5354
"//common:type",
5455
"@com_google_absl//absl/base:nullability",

checker/validation_result.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "absl/types/span.h"
2929
#include "checker/type_check_issue.h"
3030
#include "common/ast.h"
31+
#include "common/decl.h"
3132
#include "common/source.h"
3233
#include "common/type.h"
3334

common/decl.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,70 @@ bool TypeIsAssignable(const Type& to, const Type& from);
377377

378378
} // namespace common_internal
379379

380+
struct VariableDeclEqualTo {
381+
using is_transparent = void;
382+
383+
bool operator()(const cel::VariableDecl& lhs,
384+
const cel::VariableDecl& rhs) const {
385+
return lhs.name() == rhs.name();
386+
}
387+
388+
bool operator()(const cel::VariableDecl& lhs, std::string_view rhs) const {
389+
return lhs.name() == rhs;
390+
}
391+
392+
bool operator()(std::string_view lhs, const cel::VariableDecl& rhs) const {
393+
return lhs == rhs.name();
394+
}
395+
};
396+
397+
struct VariableDeclHash {
398+
using is_transparent = void;
399+
400+
size_t operator()(const cel::VariableDecl& decl) const {
401+
return (*this)(decl.name());
402+
}
403+
404+
size_t operator()(std::string_view name) const { return absl::HashOf(name); }
405+
};
406+
407+
using VariableDeclSet = absl::flat_hash_set<cel::VariableDecl, VariableDeclHash,
408+
VariableDeclEqualTo>;
409+
410+
struct FunctionDeclEqualTo {
411+
using is_transparent = void;
412+
413+
bool operator()(const cel::FunctionDecl& lhs,
414+
const cel::FunctionDecl& rhs) const {
415+
return (*this)(lhs.name(), rhs.name());
416+
}
417+
418+
bool operator()(const cel::FunctionDecl& lhs, std::string_view rhs) const {
419+
return (*this)(lhs.name(), rhs);
420+
}
421+
422+
bool operator()(std::string_view lhs, const cel::FunctionDecl& rhs) const {
423+
return (*this)(lhs, rhs.name());
424+
}
425+
426+
bool operator()(std::string_view lhs, std::string_view rhs) const {
427+
return lhs == rhs;
428+
}
429+
};
430+
431+
struct FunctionDeclHash {
432+
using is_transparent = void;
433+
434+
size_t operator()(const cel::FunctionDecl& decl) const {
435+
return absl::HashOf(decl.name());
436+
}
437+
438+
size_t operator()(std::string_view name) const { return absl::HashOf(name); }
439+
};
440+
441+
using FunctionDeclSet = absl::flat_hash_set<cel::FunctionDecl, FunctionDeclHash,
442+
FunctionDeclEqualTo>;
443+
380444
} // namespace cel
381445

382446
#endif // THIRD_PARTY_CEL_CPP_COMMON_DECL_H_

0 commit comments

Comments
 (0)