Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions include/CppInterOp/CppInterOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,9 @@ void GetEnumConstantDatamembers(TCppScope_t scope,
CPPINTEROP_API TCppScope_t LookupDatamember(const std::string& name,
TCppScope_t parent);

/// Check if the given type is a lamda class
CPPINTEROP_API bool IsLambdaClass(TCppType_t type);

/// Gets the type of the variable that is passed as a parameter.
CPPINTEROP_API TCppType_t GetVariableType(TCppScope_t var);

Expand Down
8 changes: 8 additions & 0 deletions lib/CppInterOp/CppInterOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,14 @@ TCppScope_t LookupDatamember(const std::string& name, TCppScope_t parent) {
return 0;
}

bool IsLambdaClass(TCppType_t type) {
QualType QT = QualType::getFromOpaquePtr(type);
if (auto* CXXRD = QT->getAsCXXRecordDecl()) {
return CXXRD->isLambda();
}
return false;
}

TCppType_t GetVariableType(TCppScope_t var) {
auto* D = static_cast<Decl*>(var);

Expand Down
4 changes: 4 additions & 0 deletions unittests/CppInterOp/VariableReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ TEST(VariableReflectionTest, GetVariableType) {
E<int> e;
E<int> *f;
int g[4];
auto fn = []() { return 1; };
)";

GetAllTopLevelDecls(code, Decls);
Expand All @@ -245,6 +246,9 @@ TEST(VariableReflectionTest, GetVariableType) {
EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetVariableType(Decls[6])), "E<int>");
EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetVariableType(Decls[7])), "E<int> *");
EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetVariableType(Decls[8])), "int[4]");

EXPECT_FALSE(Cpp::IsLambdaClass(Cpp::GetVariableType(Decls[8])));
EXPECT_TRUE(Cpp::IsLambdaClass(Cpp::GetVariableType(Decls[9])));
}

#define CODE \
Expand Down
Loading