Files
codeql/swift/extractor/infra/SwiftMangledName.cpp
Paolo Tranquilli 70ff401f21 Swift: replace internal swift mangler with our own
Our mangler is split in two version:
* `SwiftTrapMangler`, with the same behaviour as the previous
  `SwiftMangler`, constructing mangled names with trap label references
* `SwiftRecursiveMangler` that replaces trap label references with
  recursive calls to its own `mangle` functions, effectively rolling out
  the entire chain of references

The latter is used to create lazy trap file names. Hashing is used to
avoid excessively long filenames.
2023-05-31 09:52:20 +02:00

26 lines
610 B
C++

#include "swift/extractor/infra/SwiftMangledName.h"
#include "absl/strings/str_cat.h"
#include <picosha2.h>
namespace codeql {
std::string SwiftMangledName::hash() const {
auto ret = picosha2::hash256_hex_string(value);
// half a hash is already enough for disambuiguation
ret.resize(ret.size() / 2);
return ret;
}
SwiftMangledName& SwiftMangledName::operator<<(UntypedTrapLabel label) & {
absl::StrAppend(&value, "{", label.str(), "}");
return *this;
}
SwiftMangledName& SwiftMangledName::operator<<(unsigned int i) & {
absl::StrAppend(&value, i);
return *this;
}
} // namespace codeql