LLVM: lib/TextAPI/Utils.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
16
17using namespace llvm;
19
21 const Twine &Extension) {
22 StringRef P(Path.begin(), Path.size());
25
26 if (!ParentPath.ends_with(Filename.str() + ".framework")) {
28 return;
29 }
30
31
32
34 StringRef Ext = Extension.toStringRef(Storage);
35
36
37 if (!Ext.empty() && Ext[0] != '.')
38 Path.push_back('.');
39
40
41 Path.append(Ext.begin(), Ext.end());
42}
43
45 bool &Result) {
46 Result = false;
48 auto P = Path.toNullTerminatedStringRef(Storage);
51 if (EC == std::errc::too_many_symbolic_link_levels) {
52 Result = true;
53 return {};
54 }
55
56 if (EC)
57 return EC;
58
60 while (!Parent.empty()) {
63 return ec;
64
66 Result = true;
67 return {};
68 }
69
71 }
72 return {};
73}
74
75std::error_code
81 return EC;
82
84 return EC;
85
90
91 for (; IT1 != IE1 && IT2 != IE2; ++IT1, ++IT2) {
92 if (*IT1 != *IT2)
93 break;
94 }
95
96 for (; IT1 != IE1; ++IT1)
98
99 for (; IT2 != IE2; ++IT2)
101
102 if (Result.empty())
103 Result = ".";
104
105 RelativePath.swap(Result);
106
107 return {};
108}
109
111
114
115 Path.consume_front("/Library/Apple");
116
117 if (Path.starts_with("/usr/local/lib"))
118 return true;
119
120 if (Path.starts_with("/System/Library/PrivateFrameworks"))
121 return true;
122
123 if (Path.starts_with("/System/Library/SubFrameworks"))
124 return true;
125
126
127
128 if (Path.consume_front("/usr/lib/swift/"))
129 return false;
130
131
132
133 if (Path.consume_front("/usr/lib/"))
134 return Path.contains('/');
135
136
137 if (Path.starts_with("/System/Library/Frameworks/")) {
139 std::tie(Name, Rest) =
140 Path.drop_front(sizeof("/System/Library/Frameworks")).split('.');
141
142
143 if (IsSymLink && Rest == "framework")
144 return false;
145
146
147
148
149
150
151
152
153
154 return !(Rest.starts_with("framework/") &&
156 (IsSymLink && Rest.ends_with("Current"))));
157 }
158 return false;
159}
160
162
165 unsigned NumWildcards = 0;
166 for (unsigned i = 0; i < Glob.size(); ++i) {
167 char C = Glob[i];
168 switch (C) {
169 case '?':
170 RegexString += '.';
171 break;
172 case '*': {
173 const char *PrevChar = i > 0 ? Glob.data() + i - 1 : nullptr;
174 NumWildcards = 1;
175 ++i;
176 while (i < Glob.size() && Glob[i] == '*') {
177 ++NumWildcards;
178 ++i;
179 }
180 const char *NextChar = i < Glob.size() ? Glob.data() + i : nullptr;
181
182 if ((NumWildcards > 1) && (PrevChar == nullptr || *PrevChar == '/') &&
183 (NextChar == nullptr || *NextChar == '/')) {
184 RegexString += "(([^/]*(/|$))*)";
185 } else
186 RegexString += "([^/]*)";
187 break;
188 }
189 default:
193 }
194 }
196 if (NumWildcards == 0)
198
200 std::string Error;
203
204 return std::move(Rule);
205}
206
211 Buffer->getBuffer().split(Lines, "\n", -1,
212 false);
213 for (const StringRef Line : Lines) {
215 if (L.empty())
216 continue;
217
218 if (L.starts_with("#"))
219 continue;
221
222 std::tie(Symbol, Remain) = getToken(L);
223
224 std::tie(Alias, Remain) = getToken(Remain, "#");
225 Alias = Alias.trim();
226 if (Alias.empty())
227 return make_error(
228 TextAPIError(TextAPIErrorCode::InvalidInputFormat,
229 ("missing alias for: " + Symbol).str()));
233 BaseSym.Kind};
234 }
235
236 return Aliases;
237}
238
242 for (const auto &[Path, CurrP] : Paths) {
243 if (!CurrP.has_value() || CurrP.value() == Platform)
244 Result.push_back(Path);
245 }
246 return Result;
247}
BlockVerifier::State From
Define TAPI specific error codes.
static StringLiteral RegexMetachars
#define DRIVERKIT_PREFIX_PATH
#define MACCATALYST_PREFIX_PATH
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
bool isValid(std::string &Error) const
isValid - returns the error encountered during regex compilation, if any.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void swap(SmallVectorImpl &RHS)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Represents the result of a call to sys::fs::status().
@ C
The default llvm calling convention, compatible with C.
std::map< AliasEntry, AliasEntry > AliasMap
std::error_code make_relative(StringRef From, StringRef To, SmallVectorImpl< char > &RelativePath)
Turn absolute symlink into relative.
void replace_extension(SmallVectorImpl< char > &Path, const Twine &Extension)
Replace extension considering frameworks.
std::vector< PathToPlatform > PathToPlatformSeq
bool isPrivateLibrary(StringRef Path, bool IsSymLink=false)
Determine if library is private by parsing file path.
std::vector< std::string > PathSeq
llvm::Expected< llvm::Regex > createRegexFromGlob(llvm::StringRef Glob)
Create a regex rule from provided glob string.
SimpleSymbol parseSymbol(StringRef SymName)
Get symbol classification by parsing the name of a symbol.
PathSeq getPathsForPlatform(const PathToPlatformSeq &Paths, PlatformType Platform)
Pickup active paths for a given platform.
std::error_code shouldSkipSymLink(const Twine &Path, bool &Result)
Determine whether to skip over symlink due to either too many symlink levels or is cyclic.
Expected< AliasMap > parseAliasList(std::unique_ptr< llvm::MemoryBuffer > &Buffer)
Parse input list and capture symbols and their alias.
bool equivalent(file_status A, file_status B)
Do file_status's represent the same thing?
void make_absolute(const Twine ¤t_directory, SmallVectorImpl< char > &path)
Make path an absolute path.
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
void replace_extension(SmallVectorImpl< char > &path, const Twine &extension, Style style=Style::native)
Replace the file extension of path with extension.
const_iterator begin(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get begin iterator over path.
StringRef parent_path(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get parent path.
StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
const_iterator end(StringRef path LLVM_LIFETIME_BOUND)
Get end iterator over path.
This is an optimization pass for GlobalISel generic memory operations.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Lightweight struct for passing around symbol information.