mirror of
https://github.com/github/codeql.git
synced 2026-04-25 16:55:19 +02:00
Swift: introduce type mangling
This commit is contained in:
@@ -30,3 +30,11 @@ std::string SwiftMangler::mangledName(const swift::Decl& decl) {
|
||||
}
|
||||
return ret.str();
|
||||
}
|
||||
|
||||
std::optional<std::string> SwiftMangler::mangleType(const swift::ModuleType& type) {
|
||||
auto key = type.getModule()->getRealName().str().str();
|
||||
if (type.getModule()->isNonSwiftModule()) {
|
||||
key += "|clang";
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <unordered_set>
|
||||
#include <filesystem>
|
||||
|
||||
#include <swift/AST/ASTMangler.h>
|
||||
#include <swift/AST/Types.h>
|
||||
|
||||
namespace codeql {
|
||||
class SwiftMangler {
|
||||
public:
|
||||
std::string mangledName(const swift::Decl& decl);
|
||||
|
||||
template <typename T>
|
||||
std::optional<std::string> mangleType(const T& type) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<std::string> mangleType(const swift::ModuleType& type);
|
||||
|
||||
private:
|
||||
swift::Mangle::ASTMangler mangler;
|
||||
};
|
||||
|
||||
@@ -242,11 +242,7 @@ codeql::OpenedArchetypeType TypeTranslator::translateOpenedArchetypeType(
|
||||
}
|
||||
|
||||
codeql::ModuleType TypeTranslator::translateModuleType(const swift::ModuleType& type) {
|
||||
auto key = type.getModule()->getRealName().str().str();
|
||||
if (type.getModule()->isNonSwiftModule()) {
|
||||
key += "|clang";
|
||||
}
|
||||
auto entry = createTypeEntry(type, key);
|
||||
auto entry = createTypeEntry(type);
|
||||
entry.module = dispatcher.fetchLabel(type.getModule());
|
||||
return entry;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "swift/extractor/translators/TranslatorBase.h"
|
||||
#include "swift/extractor/trap/generated/type/TrapClasses.h"
|
||||
#include "swift/extractor/mangler/SwiftMangler.h"
|
||||
|
||||
namespace codeql {
|
||||
class TypeTranslator : public TypeTranslatorBase<TypeTranslator> {
|
||||
@@ -87,12 +88,23 @@ class TypeTranslator : public TypeTranslatorBase<TypeTranslator> {
|
||||
void fillBoundGenericType(const swift::BoundGenericType& type, codeql::BoundGenericType& entry);
|
||||
void fillAnyGenericType(const swift::AnyGenericType& type, codeql::AnyGenericType& entry);
|
||||
|
||||
template <typename T, typename... Args>
|
||||
auto createTypeEntry(const T& type, const Args&... args) {
|
||||
auto entry = dispatcher.createEntry(type, args...);
|
||||
template <typename T>
|
||||
auto createMangledTypeEntry(const T& type) {
|
||||
auto mangledName = mangler.mangleType(type);
|
||||
if (mangledName) {
|
||||
return dispatcher.createEntry(type, mangledName.value());
|
||||
}
|
||||
return dispatcher.createEntry(type);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto createTypeEntry(const T& type) {
|
||||
auto entry = createMangledTypeEntry(type);
|
||||
fillType(type, entry);
|
||||
return entry;
|
||||
}
|
||||
|
||||
SwiftMangler mangler;
|
||||
};
|
||||
|
||||
} // namespace codeql
|
||||
|
||||
Reference in New Issue
Block a user