Skip to content

Commit 7902b82

Browse files
Add IsLambdaClass (#691)
1 parent bf10f8a commit 7902b82

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

include/CppInterOp/CppInterOp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,9 @@ void GetEnumConstantDatamembers(TCppScope_t scope,
573573
CPPINTEROP_API TCppScope_t LookupDatamember(const std::string& name,
574574
TCppScope_t parent);
575575

576+
/// Check if the given type is a lamda class
577+
CPPINTEROP_API bool IsLambdaClass(TCppType_t type);
578+
576579
/// Gets the type of the variable that is passed as a parameter.
577580
CPPINTEROP_API TCppType_t GetVariableType(TCppScope_t var);
578581

lib/CppInterOp/CppInterOp.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,14 @@ TCppScope_t LookupDatamember(const std::string& name, TCppScope_t parent) {
14061406
return 0;
14071407
}
14081408

1409+
bool IsLambdaClass(TCppType_t type) {
1410+
QualType QT = QualType::getFromOpaquePtr(type);
1411+
if (auto* CXXRD = QT->getAsCXXRecordDecl()) {
1412+
return CXXRD->isLambda();
1413+
}
1414+
return false;
1415+
}
1416+
14091417
TCppType_t GetVariableType(TCppScope_t var) {
14101418
auto* D = static_cast<Decl*>(var);
14111419

unittests/CppInterOp/VariableReflectionTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ TEST(VariableReflectionTest, GetVariableType) {
234234
E<int> e;
235235
E<int> *f;
236236
int g[4];
237+
auto fn = []() { return 1; };
237238
)";
238239

239240
GetAllTopLevelDecls(code, Decls);
@@ -245,6 +246,9 @@ TEST(VariableReflectionTest, GetVariableType) {
245246
EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetVariableType(Decls[6])), "E<int>");
246247
EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetVariableType(Decls[7])), "E<int> *");
247248
EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetVariableType(Decls[8])), "int[4]");
249+
250+
EXPECT_FALSE(Cpp::IsLambdaClass(Cpp::GetVariableType(Decls[8])));
251+
EXPECT_TRUE(Cpp::IsLambdaClass(Cpp::GetVariableType(Decls[9])));
248252
}
249253

250254
#define CODE \

0 commit comments

Comments
 (0)