1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | #ifndef LLVM_CLANG_DRIVER_MULTILIB_H |
10 | #define LLVM_CLANG_DRIVER_MULTILIB_H |
11 | |
12 | #include "clang/Basic/LLVM.h" |
13 | #include "llvm/ADT/ArrayRef.h" |
14 | #include "llvm/ADT/STLExtras.h" |
15 | #include "llvm/ADT/StringRef.h" |
16 | #include "llvm/Support/Compiler.h" |
17 | #include <cassert> |
18 | #include <functional> |
19 | #include <string> |
20 | #include <utility> |
21 | #include <vector> |
22 | |
23 | namespace clang { |
24 | namespace driver { |
25 | |
26 | |
27 | |
28 | class Multilib { |
29 | public: |
30 | using flags_list = std::vector<std::string>; |
31 | |
32 | private: |
33 | std::string GCCSuffix; |
34 | std::string OSSuffix; |
35 | std::string IncludeSuffix; |
36 | flags_list Flags; |
37 | |
38 | public: |
39 | Multilib(StringRef GCCSuffix = {}, StringRef OSSuffix = {}, |
40 | StringRef IncludeSuffix = {}); |
41 | |
42 | |
43 | |
44 | const std::string &gccSuffix() const { |
45 | 1)", "/home/seafit/code_projects/clang_source/clang/include/clang/Driver/Multilib.h", 46, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(GCCSuffix.empty() || |
46 | 1)", "/home/seafit/code_projects/clang_source/clang/include/clang/Driver/Multilib.h", 46, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> (StringRef(GCCSuffix).front() == '/' && GCCSuffix.size() > 1)); |
47 | return GCCSuffix; |
48 | } |
49 | |
50 | |
51 | Multilib &gccSuffix(StringRef S); |
52 | |
53 | |
54 | |
55 | const std::string &osSuffix() const { |
56 | 1)", "/home/seafit/code_projects/clang_source/clang/include/clang/Driver/Multilib.h", 57, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(OSSuffix.empty() || |
57 | 1)", "/home/seafit/code_projects/clang_source/clang/include/clang/Driver/Multilib.h", 57, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> (StringRef(OSSuffix).front() == '/' && OSSuffix.size() > 1)); |
58 | return OSSuffix; |
59 | } |
60 | |
61 | |
62 | Multilib &osSuffix(StringRef S); |
63 | |
64 | |
65 | |
66 | const std::string &includeSuffix() const { |
67 | 1)", "/home/seafit/code_projects/clang_source/clang/include/clang/Driver/Multilib.h", 68, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(IncludeSuffix.empty() || |
68 | 1)", "/home/seafit/code_projects/clang_source/clang/include/clang/Driver/Multilib.h", 68, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> (StringRef(IncludeSuffix).front() == '/' && IncludeSuffix.size() > 1)); |
69 | return IncludeSuffix; |
70 | } |
71 | |
72 | |
73 | Multilib &includeSuffix(StringRef S); |
74 | |
75 | |
76 | |
77 | const flags_list &flags() const { return Flags; } |
78 | flags_list &flags() { return Flags; } |
79 | |
80 | |
81 | |
82 | |
83 | |
84 | |
85 | |
86 | |
87 | Multilib &flag(StringRef F) { |
88 | assert(F.front() == '+' || F.front() == '-'); |
89 | Flags.push_back(F); |
90 | return *this; |
91 | } |
92 | |
93 | LLVM_DUMP_METHOD void dump() const; |
94 | |
95 | void print(raw_ostream &OS) const; |
96 | |
97 | |
98 | bool isValid() const; |
99 | |
100 | |
101 | bool isDefault() const |
102 | { return GCCSuffix.empty() && OSSuffix.empty() && IncludeSuffix.empty(); } |
103 | |
104 | bool operator==(const Multilib &Other) const; |
105 | }; |
106 | |
107 | raw_ostream &operator<<(raw_ostream &OS, const Multilib &M); |
108 | |
109 | class MultilibSet { |
110 | public: |
111 | using multilib_list = std::vector<Multilib>; |
112 | using iterator = multilib_list::iterator; |
113 | using const_iterator = multilib_list::const_iterator; |
114 | using IncludeDirsFunc = |
115 | std::function<std::vector<std::string>(const Multilib &M)>; |
116 | using FilterCallback = llvm::function_ref<bool(const Multilib &)>; |
117 | |
118 | private: |
119 | multilib_list Multilibs; |
120 | IncludeDirsFunc IncludeCallback; |
121 | IncludeDirsFunc FilePathsCallback; |
122 | |
123 | public: |
124 | MultilibSet() = default; |
125 | |
126 | |
127 | MultilibSet &Maybe(const Multilib &M); |
128 | |
129 | |
130 | MultilibSet &Either(const Multilib &M1, const Multilib &M2); |
131 | MultilibSet &Either(const Multilib &M1, const Multilib &M2, |
132 | const Multilib &M3); |
133 | MultilibSet &Either(const Multilib &M1, const Multilib &M2, |
134 | const Multilib &M3, const Multilib &M4); |
135 | MultilibSet &Either(const Multilib &M1, const Multilib &M2, |
136 | const Multilib &M3, const Multilib &M4, |
137 | const Multilib &M5); |
138 | MultilibSet &Either(ArrayRef<Multilib> Ms); |
139 | |
140 | |
141 | MultilibSet &FilterOut(FilterCallback F); |
142 | |
143 | |
144 | MultilibSet &FilterOut(const char *Regex); |
145 | |
146 | |
147 | void push_back(const Multilib &M); |
148 | |
149 | |
150 | void combineWith(const MultilibSet &MS); |
151 | |
152 | |
153 | void clear() { Multilibs.clear(); } |
154 | |
155 | iterator begin() { return Multilibs.begin(); } |
156 | const_iterator begin() const { return Multilibs.begin(); } |
157 | |
158 | iterator end() { return Multilibs.end(); } |
159 | const_iterator end() const { return Multilibs.end(); } |
160 | |
161 | |
162 | bool select(const Multilib::flags_list &Flags, Multilib &M) const; |
163 | |
164 | unsigned size() const { return Multilibs.size(); } |
165 | |
166 | LLVM_DUMP_METHOD void dump() const; |
167 | void print(raw_ostream &OS) const; |
168 | |
169 | MultilibSet &setIncludeDirsCallback(IncludeDirsFunc F) { |
170 | IncludeCallback = std::move(F); |
171 | return *this; |
172 | } |
173 | |
174 | const IncludeDirsFunc &includeDirsCallback() const { return IncludeCallback; } |
175 | |
176 | MultilibSet &setFilePathsCallback(IncludeDirsFunc F) { |
177 | FilePathsCallback = std::move(F); |
178 | return *this; |
179 | } |
180 | |
181 | const IncludeDirsFunc &filePathsCallback() const { return FilePathsCallback; } |
182 | |
183 | private: |
184 | |
185 | static multilib_list filterCopy(FilterCallback F, const multilib_list &Ms); |
186 | |
187 | |
188 | static void filterInPlace(FilterCallback F, multilib_list &Ms); |
189 | }; |
190 | |
191 | raw_ostream &operator<<(raw_ostream &OS, const MultilibSet &MS); |
192 | |
193 | } |
194 | } |
195 | |
196 | #endif |
197 | |