Skip to content

Commit 5b6285f

Browse files
authored
Merge pull request #15431 from dcci/reconstructdecl
2 parents 4e104e8 + 9dbd966 commit 5b6285f

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// %t.input: "A ---> B" ==> "A"
4+
// RUN: sed -ne '/--->/s/ *--->.*$//p' < %S/Inputs/decl-reconstr-names.txt > %t.input
5+
6+
// %t.check: "A ---> B" ==> "B"
7+
// RUN: sed -ne '/--->/s/^.*---> *//p' < %S/Inputs/decl-reconstr-names.txt > %t.check
8+
9+
// RUN: %target-build-swift -emit-executable %s -g -o %t/DeclReconstr -emit-module
10+
// RUN: %lldb-moduleimport-test %t/DeclReconstr \
11+
// RUN: -decl-from-mangled=%t.input > %t.output 2>&1
12+
// RUN: diff %t.check %t.output
13+
14+
// REQUIRES: executable_test
15+
struct S {
16+
init() {
17+
}
18+
}
19+
20+
func patatino() -> Int {
21+
let s = S()
22+
return 0
23+
}
24+
25+
patatino()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
$S12DeclReconstr8patatinoSiyF ---> func patatino() -> Int
2+
$S12DeclReconstr1SVACycfC ---> Can't resolve decl of $S12DeclReconstr1SVACycfC

tools/lldb-moduleimport-test/lldb-moduleimport-test.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,23 @@ static void printValidationInfo(llvm::StringRef data) {
6262
}
6363
}
6464

65+
static void resolveDeclFromMangledNameList(
66+
swift::ASTContext &Ctx, llvm::ArrayRef<std::string> MangledNames) {
67+
std::string Error;
68+
for (auto &Mangled : MangledNames) {
69+
swift::Decl *ResolvedDecl =
70+
swift::ide::getDeclFromMangledSymbolName(Ctx, Mangled, Error);
71+
if (!ResolvedDecl) {
72+
llvm::errs() << "Can't resolve decl of " << Mangled << "\n";
73+
} else {
74+
ResolvedDecl->print(llvm::errs());
75+
llvm::errs() << "\n";
76+
}
77+
}
78+
}
79+
6580
static void resolveTypeFromMangledNameList(
66-
swift::ASTContext &Ctx, llvm::SmallVector<std::string, 8> &MangledNames) {
81+
swift::ASTContext &Ctx, llvm::ArrayRef<std::string> MangledNames) {
6782
std::string Error;
6883
for (auto &Mangled : MangledNames) {
6984
swift::Type ResolvedType =
@@ -78,8 +93,8 @@ static void resolveTypeFromMangledNameList(
7893
}
7994

8095
static void
81-
collectMangledNames(std::string &FilePath,
82-
llvm::SmallVector<std::string, 8> &MangledNames) {
96+
collectMangledNames(const std::string &FilePath,
97+
llvm::SmallVectorImpl<std::string> &MangledNames) {
8398
std::string Name;
8499
std::ifstream InputStream(FilePath);
85100
while (std::getline(InputStream, Name)) {
@@ -117,8 +132,11 @@ int main(int argc, char **argv) {
117132
llvm::cl::list<std::string> FrameworkPaths(
118133
"F", llvm::cl::desc("add a directory to the framework search path"));
119134

135+
llvm::cl::opt<std::string> DumpDeclFromMangled(
136+
"decl-from-mangled", llvm::cl::desc("dump decl from mangled names list"));
137+
120138
llvm::cl::opt<std::string> DumpTypeFromMangled(
121-
"type-from-mangled", llvm::cl::desc("dump type from mangled name"));
139+
"type-from-mangled", llvm::cl::desc("dump type from mangled names list"));
122140

123141
llvm::cl::ParseCommandLineOptions(argc, argv);
124142
// Unregister our options so they don't interfere with the command line
@@ -269,6 +287,11 @@ int main(int argc, char **argv) {
269287
collectMangledNames(DumpTypeFromMangled, MangledNames);
270288
resolveTypeFromMangledNameList(CI.getASTContext(), MangledNames);
271289
}
290+
if (!DumpDeclFromMangled.empty()) {
291+
llvm::SmallVector<std::string, 8> MangledNames;
292+
collectMangledNames(DumpDeclFromMangled, MangledNames);
293+
resolveDeclFromMangledNameList(CI.getASTContext(), MangledNames);
294+
}
272295
}
273296
return 0;
274297
}

0 commit comments

Comments
 (0)