Skip to content

Commit 7467cf7

Browse files
committed
[clang][ssaf] Add asTuple helper to EntityName and BuildNamespace
1 parent 6b840ce commit 7467cf7

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

clang/include/clang/Analysis/Scalable/Model/BuildNamespace.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ std::optional<BuildNamespaceKind> parseBuildNamespaceKind(llvm::StringRef Str);
3030
class BuildNamespace {
3131
BuildNamespaceKind Kind;
3232
std::string Name;
33+
34+
auto asTuple() const { return std::tie(Kind, Name); }
35+
3336
public:
3437
BuildNamespace(BuildNamespaceKind Kind, llvm::StringRef Name)
3538
: Kind(Kind), Name(Name.str()) {}

clang/include/clang/Analysis/Scalable/Model/EntityName.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class EntityName {
2626
llvm::SmallString<16> Suffix;
2727
NestedBuildNamespace Namespace;
2828

29+
auto asTuple() const { return std::tie(USR, Suffix, Namespace); }
30+
2931
public:
3032
EntityName(llvm::StringRef USR, llvm::StringRef Suffix,
3133
NestedBuildNamespace Namespace);

clang/lib/Analysis/Scalable/Model/BuildNamespace.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "clang/Analysis/Scalable/Model/BuildNamespace.h"
1010
#include "llvm/Support/ErrorHandling.h"
11+
#include <tuple>
1112

1213
namespace clang::ssaf {
1314

@@ -32,17 +33,15 @@ BuildNamespace BuildNamespace::makeTU(llvm::StringRef CompilationId) {
3233
}
3334

3435
bool BuildNamespace::operator==(const BuildNamespace& Other) const {
35-
return Kind == Other.Kind && Name == Other.Name;
36+
return asTuple() == Other.asTuple();
3637
}
3738

3839
bool BuildNamespace::operator!=(const BuildNamespace& Other) const {
3940
return !(*this == Other);
4041
}
4142

4243
bool BuildNamespace::operator<(const BuildNamespace& Other) const {
43-
if (Kind != Other.Kind)
44-
return Kind < Other.Kind;
45-
return Name < Other.Name;
44+
return asTuple() < Other.asTuple();
4645
}
4746

4847
NestedBuildNamespace NestedBuildNamespace::makeTU(llvm::StringRef CompilationId) {

clang/lib/Analysis/Scalable/Model/EntityName.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,15 @@ EntityName::EntityName(llvm::StringRef USR, llvm::StringRef Suffix,
1515
: USR(USR.str()), Suffix(Suffix), Namespace(std::move(Namespace)) {}
1616

1717
bool EntityName::operator==(const EntityName& Other) const {
18-
return USR == Other.USR &&
19-
Suffix == Other.Suffix &&
20-
Namespace == Other.Namespace;
18+
return asTuple() == Other.asTuple();
2119
}
2220

2321
bool EntityName::operator!=(const EntityName& Other) const {
2422
return !(*this == Other);
2523
}
2624

27-
bool EntityName::operator<(const EntityName& Other) const {
28-
if (USR != Other.USR)
29-
return USR < Other.USR;
30-
if (Suffix != Other.Suffix)
31-
return Suffix.str() < Other.Suffix.str();
32-
return Namespace < Other.Namespace;
25+
bool EntityName::operator<(const EntityName &Other) const {
26+
return asTuple() < Other.asTuple();
3327
}
3428

3529
EntityName EntityName::makeQualified(NestedBuildNamespace Namespace) const {

0 commit comments

Comments
 (0)