lldb-moduleimport-test: Add support for testing Demangle::getTypeForMangling()

The -type-from-mangled flag now uses the new API. The -type-from-mangled-old flag
uses the old API, ide::getTypeFromMangledSymbolname().

For now, just change all existing tests to use the -type-from-mangled-old flag;
I'll be adding new tests for the new API shortly.
This commit is contained in:
Slava Pestov
2019-01-24 11:32:16 -05:00
parent ed209084f9
commit a14f345c82
4 changed files with 32 additions and 4 deletions

View File

@@ -16,6 +16,7 @@
//
//===----------------------------------------------------------------------===//
#include "swift/AST/ASTDemangler.h"
#include "swift/ASTSectionImporter/ASTSectionImporter.h"
#include "swift/Frontend/Frontend.h"
#include "swift/IDE/Utils.h"
@@ -92,6 +93,20 @@ static void resolveDeclFromMangledNameList(
static void resolveTypeFromMangledNameList(
swift::ASTContext &Ctx, llvm::ArrayRef<std::string> MangledNames) {
for (auto &Mangled : MangledNames) {
swift::Type ResolvedType =
swift::Demangle::getTypeForMangling(Ctx, Mangled);
if (!ResolvedType) {
llvm::outs() << "Can't resolve type of " << Mangled << "\n";
} else {
ResolvedType->print(llvm::outs());
llvm::outs() << "\n";
}
}
}
static void resolveTypeFromMangledNameListOld(
swift::ASTContext &Ctx, llvm::ArrayRef<std::string> MangledNames) {
std::string Error;
for (auto &Mangled : MangledNames) {
swift::Type ResolvedType =
@@ -207,6 +222,11 @@ int main(int argc, char **argv) {
"type-from-mangled", desc("dump type from mangled names list"),
cat(Visible));
opt<std::string> DumpTypeFromMangledOld(
"type-from-mangled-old", desc("dump type from mangled names list using old "
"TypeReconstruction API"),
cat(Visible));
opt<std::string> ResourceDir(
"resource-dir",
desc("The directory that holds the compiler resource files"),
@@ -223,6 +243,7 @@ int main(int argc, char **argv) {
ModuleCachePath.removeArgument();
DumpModule.removeArgument();
DumpTypeFromMangled.removeArgument();
DumpTypeFromMangledOld.removeArgument();
InputNames.removeArgument();
auto validateInputFile = [](std::string Filename) {
@@ -241,6 +262,8 @@ int main(int argc, char **argv) {
if (!validateInputFile(DumpTypeFromMangled))
return 1;
if (!validateInputFile(DumpTypeFromMangledOld))
return 1;
if (!validateInputFile(DumpDeclFromMangled))
return 1;
@@ -330,6 +353,11 @@ int main(int argc, char **argv) {
collectMangledNames(DumpTypeFromMangled, MangledNames);
resolveTypeFromMangledNameList(CI.getASTContext(), MangledNames);
}
if (!DumpTypeFromMangledOld.empty()) {
llvm::SmallVector<std::string, 8> MangledNames;
collectMangledNames(DumpTypeFromMangledOld, MangledNames);
resolveTypeFromMangledNameListOld(CI.getASTContext(), MangledNames);
}
if (!DumpDeclFromMangled.empty()) {
llvm::SmallVector<std::string, 8> MangledNames;
collectMangledNames(DumpDeclFromMangled, MangledNames);