diff --git a/include/CppInterOp/CppInterOp.h b/include/CppInterOp/CppInterOp.h index 58b6cc548..bcbe3e5e1 100644 --- a/include/CppInterOp/CppInterOp.h +++ b/include/CppInterOp/CppInterOp.h @@ -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); diff --git a/lib/CppInterOp/CppInterOp.cpp b/lib/CppInterOp/CppInterOp.cpp index 0bab8717d..a8bf9c064 100755 --- a/lib/CppInterOp/CppInterOp.cpp +++ b/lib/CppInterOp/CppInterOp.cpp @@ -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(var); diff --git a/unittests/CppInterOp/VariableReflectionTest.cpp b/unittests/CppInterOp/VariableReflectionTest.cpp index f75d1839a..1dfba0066 100644 --- a/unittests/CppInterOp/VariableReflectionTest.cpp +++ b/unittests/CppInterOp/VariableReflectionTest.cpp @@ -234,6 +234,7 @@ TEST(VariableReflectionTest, GetVariableType) { E e; E *f; int g[4]; + auto fn = []() { return 1; }; )"; GetAllTopLevelDecls(code, Decls); @@ -245,6 +246,9 @@ TEST(VariableReflectionTest, GetVariableType) { EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetVariableType(Decls[6])), "E"); EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetVariableType(Decls[7])), "E *"); 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 \