-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathSwiftMangledName.h
More file actions
60 lines (45 loc) · 1.56 KB
/
SwiftMangledName.h
File metadata and controls
60 lines (45 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once
#include <iostream>
#include <vector>
#include <variant>
#include <string>
#include "swift/extractor/trap/TrapLabel.h"
namespace codeql {
class SwiftMangledName {
public:
using Part = std::variant<UntypedTrapLabel, std::string, unsigned>;
explicit operator bool() const { return !value.empty(); }
const std::string& str() const { return value; }
operator std::string_view() const { return value; }
std::string hash() const;
// let's avoid copying as long as we don't need it
SwiftMangledName() = default;
SwiftMangledName(const SwiftMangledName&) = delete;
SwiftMangledName& operator=(const SwiftMangledName&) = delete;
SwiftMangledName(SwiftMangledName&&) = default;
SwiftMangledName& operator=(SwiftMangledName&&) = default;
template <typename... Args>
SwiftMangledName(Args&&... args) {
(operator<<(std::forward<Args>(args)), ...);
}
SwiftMangledName& operator<<(UntypedTrapLabel label) &;
SwiftMangledName& operator<<(unsigned i) &;
template <typename Tag>
SwiftMangledName& operator<<(TrapLabel<Tag> label) & {
return operator<<(static_cast<UntypedTrapLabel>(label));
}
// streaming string-like stuff will add a new part it only if strictly required, otherwise it will
// append to the last part if it is a string
template <typename T>
SwiftMangledName& operator<<(T&& arg) & {
value += arg;
return *this;
}
template <typename T>
SwiftMangledName&& operator<<(T&& arg) && {
return std::move(operator<<(std::forward<T>(arg)));
}
private:
std::string value;
};
} // namespace codeql