Skip to content

[lldb-moduleimport-test] Refactor dump of types from mangled name. #15425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions tools/lldb-moduleimport-test/lldb-moduleimport-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,33 @@ static void printValidationInfo(llvm::StringRef data) {
}
}

static void resolveTypeFromMangledNameList(
swift::ASTContext &Ctx, llvm::SmallVector<std::string, 8> &MangledNames) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLVM style nitpicks: ArrayRef here…

std::string Error;
for (auto &Mangled : MangledNames) {
swift::Type ResolvedType =
swift::ide::getTypeFromMangledSymbolname(Ctx, Mangled, Error);
if (!ResolvedType) {
llvm::errs() << "Can't resolve type of " << Mangled << "\n";
} else {
ResolvedType->print(llvm::errs());
llvm::errs() << "\n";
}
}
}

static void
collectMangledNames(std::string &FilePath,
llvm::SmallVector<std::string, 8> &MangledNames) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…and SmallVectorImpl here (don't need to hardcode the size). Also, const on FilePath.

std::string Name;
std::ifstream InputStream(FilePath);
while (std::getline(InputStream, Name)) {
if (Name.empty())
continue;
MangledNames.push_back(Name);
}
}

int main(int argc, char **argv) {
PROGRAM_START(argc, argv);
INITIALIZE_LLVM();
Expand Down Expand Up @@ -238,28 +265,9 @@ int main(int argc, char **argv) {
}
}
if (!DumpTypeFromMangled.empty()) {
std::string Error;
std::string Name;
swift::ASTContext &Ctx = CI.getASTContext();
llvm::SmallVector<std::string, 8> MangledNames;

std::ifstream InputStream(DumpTypeFromMangled);
while (std::getline(InputStream, Name)) {
if (Name.empty())
continue;
MangledNames.push_back(Name);
}

for (auto &Mangled : MangledNames) {
swift::Type ResolvedType = swift::ide::getTypeFromMangledSymbolname(
Ctx, Mangled, Error);
if (!ResolvedType) {
llvm::errs() << "Can't resolve type of " << Mangled << "\n";
} else {
ResolvedType->print(llvm::errs());
llvm::errs() << "\n";
}
}
collectMangledNames(DumpTypeFromMangled, MangledNames);
resolveTypeFromMangledNameList(CI.getASTContext(), MangledNames);
}
}
return 0;
Expand Down