Skip to content

Commit 78f9a13

Browse files
sudo-pandavgvassilev
authored andcommitted
Partially Revert: Fix GetScope returning TypedefDecl of non scopes
1 parent 3638ac4 commit 78f9a13

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/Interpreter/CppInterOp.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,18 +502,22 @@ namespace Cpp {
502502

503503
TCppScope_t GetScope(const std::string &name, TCppScope_t parent)
504504
{
505+
// FIXME: GetScope should be replaced by a general purpose lookup
506+
// and filter function. The function should be like GetNamed but
507+
// also take in a filter parameter which determines which results
508+
// to pass back
505509
if (name == "")
506510
return GetGlobalScope();
507511

508512
auto *ND = (NamedDecl*)GetNamed(name, parent);
509513

510-
ND = llvm::dyn_cast_or_null<NamedDecl>(GetUnderlyingScope(ND));
511-
512514
if (!ND || ND == (NamedDecl *) -1)
513515
return 0;
514516

515-
if (llvm::isa<NamespaceDecl>(ND) || llvm::isa<RecordDecl>(ND) ||
516-
llvm::isa<ClassTemplateDecl>(ND))
517+
if (llvm::isa<NamespaceDecl>(ND) ||
518+
llvm::isa<RecordDecl>(ND) ||
519+
llvm::isa<ClassTemplateDecl>(ND) ||
520+
llvm::isa<TypedefNameDecl>(ND))
517521
return (TCppScope_t)(ND->getCanonicalDecl());
518522

519523
return 0;

unittests/CppInterOp/ScopeReflectionTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,17 +369,21 @@ TEST(ScopeReflectionTest, GetScope) {
369369
enum E { A, B };
370370
};
371371
}
372+
373+
typedef N::C T;
372374
)";
373375

374376
Cpp::CreateInterpreter();
375377
Interp->declare(code);
376378
Cpp::TCppScope_t tu = Cpp::GetScope("", 0);
377379
Cpp::TCppScope_t ns_N = Cpp::GetScope("N", 0);
378380
Cpp::TCppScope_t cl_C = Cpp::GetScope("C", ns_N);
381+
Cpp::TCppScope_t td_T = Cpp::GetScope("T", 0);
379382

380383
EXPECT_EQ(Cpp::GetQualifiedName(tu), "");
381384
EXPECT_EQ(Cpp::GetQualifiedName(ns_N), "N");
382385
EXPECT_EQ(Cpp::GetQualifiedName(cl_C), "N::C");
386+
EXPECT_EQ(Cpp::GetQualifiedName(td_T), "T");
383387
}
384388

385389
TEST(ScopeReflectionTest, GetScopefromCompleteName) {

0 commit comments

Comments
 (0)