Skip to content

Commit c00a975

Browse files
sudo-pandavgvassilev
authored andcommitted
Strip typedefs and usings in GetClassMethods
1 parent 79933ec commit c00a975

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

lib/Interpreter/CppInterOp.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,15 @@ namespace Cpp {
573573
// avoid copies.
574574
std::vector<TCppFunction_t> GetClassMethods(TCppSema_t sema,
575575
TCppScope_t klass) {
576-
auto *D = (clang::Decl *) klass;
576+
auto *D = (clang::Decl *)klass;
577577
auto *S = (Sema *)sema;
578578

579+
if (!klass)
580+
return {};
581+
582+
if (auto *TD = llvm::dyn_cast<TypedefNameDecl>(D))
583+
D = GetScopeFromType(TD->getUnderlyingType());
584+
579585
if (auto *CXXRD = llvm::dyn_cast_or_null<CXXRecordDecl>(D)) {
580586
S->ForceDeclarationOfImplicitMembers(CXXRD);
581587
std::vector<TCppFunction_t> methods;

unittests/CppInterOp/FunctionReflectionTest.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,31 @@ TEST(FunctionReflectionTest, GetClassMethods) {
2626
protected:
2727
int f5(int i) { return i; }
2828
};
29+
30+
typedef A shadow_A;
2931
)";
3032

3133
GetAllTopLevelDecls(code, Decls);
3234
Sema *S = &Interp->getCI()->getSema();
33-
auto methods = Cpp::GetClassMethods(S, Decls[0]);
35+
auto methods0 = Cpp::GetClassMethods(S, Decls[0]);
3436

3537
auto get_method_name = [](Cpp::TCppFunction_t method) {
3638
return Cpp::GetQualifiedName(method);
3739
};
3840

39-
EXPECT_EQ(get_method_name(methods[0]), "A::f1");
40-
EXPECT_EQ(get_method_name(methods[1]), "A::f2");
41-
EXPECT_EQ(get_method_name(methods[2]), "A::f3");
42-
EXPECT_EQ(get_method_name(methods[3]), "A::f4");
43-
EXPECT_EQ(get_method_name(methods[4]), "A::f5");
41+
EXPECT_EQ(get_method_name(methods0[0]), "A::f1");
42+
EXPECT_EQ(get_method_name(methods0[1]), "A::f2");
43+
EXPECT_EQ(get_method_name(methods0[2]), "A::f3");
44+
EXPECT_EQ(get_method_name(methods0[3]), "A::f4");
45+
EXPECT_EQ(get_method_name(methods0[4]), "A::f5");
46+
47+
auto methods1 = Cpp::GetClassMethods(S, Decls[1]);
48+
EXPECT_EQ(methods0.size(), methods1.size());
49+
EXPECT_EQ(methods0[0], methods1[0]);
50+
EXPECT_EQ(methods0[1], methods1[1]);
51+
EXPECT_EQ(methods0[2], methods1[2]);
52+
EXPECT_EQ(methods0[3], methods1[3]);
53+
EXPECT_EQ(methods0[4], methods1[4]);
4454
}
4555

4656
TEST(FunctionReflectionTest, ConstructorInGetClassMethods) {

0 commit comments

Comments
 (0)