Skip to content

Commit f4a6fa7

Browse files
sudo-pandavgvassilev
authored andcommitted
Strip typedefs and usings in GetFunctionsUsingName
1 parent c00a975 commit f4a6fa7

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

lib/Interpreter/CppInterOp.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,13 @@ namespace Cpp {
624624
TCppScope_t scope,
625625
const std::string &name) {
626626
auto *D = (Decl *) scope;
627+
628+
if (!scope || name.empty())
629+
return {};
630+
631+
if (auto *TD = llvm::dyn_cast<TypedefNameDecl>(D))
632+
D = GetScopeFromType(TD->getUnderlyingType());
633+
627634
std::vector<TCppFunction_t> funcs;
628635
llvm::StringRef Name(name);
629636
auto *S = (Sema *)sema;

unittests/CppInterOp/FunctionReflectionTest.cpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -142,34 +142,30 @@ TEST(FunctionReflectionTest, GetFunctionsUsingName) {
142142
int f4(int a) { return a + 1; }
143143
int f4() { return 0; }
144144
}
145+
146+
typedef A shadow_A;
145147
)";
146148

147149
GetAllTopLevelDecls(code, Decls);
148150

151+
Sema *S = &Interp->getCI()->getSema();
152+
149153
// This lambda can take in the scope and the name of the function
150-
// and check if GetFunctionsUsingName is returning a vector of functions
151-
// with size equal to number_of_overloads
152-
auto test_get_funcs_using_name = [&](Cpp::TCppScope_t scope,
153-
const std::string name,
154-
std::size_t number_of_overloads) {
155-
Sema *S = &Interp->getCI()->getSema();
154+
// and returns the size of the vector returned by GetFunctionsUsingName
155+
auto get_number_of_funcs_using_name = [&](Cpp::TCppScope_t scope,
156+
const std::string &name) {
156157
auto Funcs = Cpp::GetFunctionsUsingName(S, scope, name);
157158

158-
// Check if the number of functions returned is equal to the
159-
// number_of_overloads given by the user
160-
EXPECT_TRUE(Funcs.size() == number_of_overloads);
161-
for (auto *F : Funcs) {
162-
// Check if the fully scoped name of the function matches its
163-
// expected fully scoped name
164-
EXPECT_EQ(Cpp::GetQualifiedName(F),
165-
Cpp::GetQualifiedName(scope) + "::" + name);
166-
}
159+
return Funcs.size();
167160
};
168161

169-
test_get_funcs_using_name(Decls[0], "f1", 3);
170-
test_get_funcs_using_name(Decls[0], "f2", 1);
171-
test_get_funcs_using_name(Decls[0], "f3", 1);
172-
test_get_funcs_using_name(Decls[1], "f4", 2);
162+
EXPECT_EQ(get_number_of_funcs_using_name(Decls[0], "f1"), 3);
163+
EXPECT_EQ(get_number_of_funcs_using_name(Decls[0], "f2"), 1);
164+
EXPECT_EQ(get_number_of_funcs_using_name(Decls[0], "f3"), 1);
165+
EXPECT_EQ(get_number_of_funcs_using_name(Decls[1], "f4"), 2);
166+
EXPECT_EQ(get_number_of_funcs_using_name(Decls[2], "f1"), 3);
167+
EXPECT_EQ(get_number_of_funcs_using_name(Decls[2], "f2"), 1);
168+
EXPECT_EQ(get_number_of_funcs_using_name(Decls[2], "f3"), 1);
173169
}
174170

175171
TEST(FunctionReflectionTest, GetFunctionReturnType) {

0 commit comments

Comments
 (0)