Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 5 additions & 3 deletions include/clang/Interpreter/CppInterOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,13 @@ namespace Cpp {
/// Checks if the provided parameter is a 'Virtual' method.
CPPINTEROP_API bool IsVirtualMethod(TCppFunction_t method);

/// Gets all the Fields/Data Members of a Class. For now, it
/// only gets non-static data members but in a future update,
/// it may support getting static data members as well.
/// Gets all the Fields/Data Members of a Class
CPPINTEROP_API std::vector<TCppScope_t> GetDatamembers(TCppScope_t scope);

/// Gets all the Static Fields/Data Members of a Class
CPPINTEROP_API std::vector<TCppScope_t>
GetStaticDatamembers(TCppScope_t scope);

/// This is a Lookup function to be used specifically for data members.
CPPINTEROP_API TCppScope_t LookupDatamember(const std::string& name,
TCppScope_t parent);
Expand Down
6 changes: 6 additions & 0 deletions lib/Interpreter/CppInterOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,12 @@ namespace Cpp {
return {};
}

std::vector<TCppScope_t> GetStaticDatamembers(TCppScope_t scope) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should pass the std::vector as an out parameter.

std::vector<TCppScope_t> datamembers;
GetClassDecls<VarDecl>(scope, datamembers);
return datamembers;
}

TCppScope_t LookupDatamember(const std::string& name, TCppScope_t parent) {
clang::DeclContext *Within = 0;
if (parent) {
Expand Down
10 changes: 10 additions & 0 deletions unittests/CppInterOp/VariableReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,22 @@ TEST(VariableReflectionTest, GetDatamembers) {
GetAllTopLevelDecls(code, Decls);
auto datamembers = Cpp::GetDatamembers(Decls[0]);
auto datamembers1 = Cpp::GetDatamembers(Decls[1]);
auto static_datamembers = Cpp::GetStaticDatamembers(Decls[0]);
auto static_datamembers1 = Cpp::GetStaticDatamembers(Decls[1]);

// non static field first
EXPECT_EQ(Cpp::GetQualifiedName(datamembers[0]), "C::a");
EXPECT_EQ(Cpp::GetQualifiedName(datamembers[1]), "C::c");
EXPECT_EQ(Cpp::GetQualifiedName(datamembers[2]), "C::e");
EXPECT_EQ(datamembers.size(), 3);
EXPECT_EQ(datamembers1.size(), 0);

// static fields
EXPECT_EQ(Cpp::GetQualifiedName(static_datamembers[0]), "C::b");
EXPECT_EQ(Cpp::GetQualifiedName(static_datamembers[1]), "C::d");
EXPECT_EQ(Cpp::GetQualifiedName(static_datamembers[2]), "C::f");
EXPECT_EQ(static_datamembers.size(), 3);
EXPECT_EQ(static_datamembers1.size(), 0);
}

#define CODE \
Expand Down
Loading