diff --git a/include/CppInterOp/CppInterOp.h b/include/CppInterOp/CppInterOp.h index 2f3d330db..bb8da1bb7 100644 --- a/include/CppInterOp/CppInterOp.h +++ b/include/CppInterOp/CppInterOp.h @@ -265,6 +265,9 @@ CPPINTEROP_API bool IsNamespace(TCppScope_t scope); /// Checks if the scope is a class or not. CPPINTEROP_API bool IsClass(TCppScope_t scope); +/// Checks if the klass has a definition +CPPINTEROP_API bool IsClassDefined(TCppScope_t klass); + /// Checks if the scope is a function. CPPINTEROP_API bool IsFunction(TCppScope_t scope); diff --git a/lib/CppInterOp/CppInterOp.cpp b/lib/CppInterOp/CppInterOp.cpp index f0d7b2b38..1a1c0796e 100755 --- a/lib/CppInterOp/CppInterOp.cpp +++ b/lib/CppInterOp/CppInterOp.cpp @@ -271,6 +271,14 @@ bool IsClass(TCppScope_t scope) { return isa(D); } +bool IsClassDefined(TCppScope_t klass) { + Decl* D = static_cast(klass); + if (auto* CXXRD = llvm::dyn_cast(D)) { + return CXXRD->hasDefinition(); + } + return false; +} + bool IsFunction(TCppScope_t scope) { Decl* D = static_cast(scope); return isa(D); diff --git a/unittests/CppInterOp/VariableReflectionTest.cpp b/unittests/CppInterOp/VariableReflectionTest.cpp index f75d1839a..0665d9e17 100644 --- a/unittests/CppInterOp/VariableReflectionTest.cpp +++ b/unittests/CppInterOp/VariableReflectionTest.cpp @@ -308,8 +308,11 @@ TEST(VariableReflectionTest, GetVariableOffset) { Cpp::Declare("struct K;"); Cpp::TCppScope_t k = Cpp::GetNamed("K"); EXPECT_TRUE(k); + EXPECT_TRUE(Cpp::IsClass(k)); + EXPECT_FALSE(Cpp::IsClassDefined(k)); Cpp::Declare("struct K { int x; int y; int z; };"); + EXPECT_TRUE(Cpp::IsClassDefined(k)); datamembers.clear(); Cpp::GetDatamembers(k, datamembers); @@ -318,6 +321,7 @@ TEST(VariableReflectionTest, GetVariableOffset) { EXPECT_EQ(Cpp::GetVariableOffset(datamembers[0]), offsetof(K, x)); EXPECT_EQ(Cpp::GetVariableOffset(datamembers[1]), offsetof(K, y)); EXPECT_EQ(Cpp::GetVariableOffset(datamembers[2]), offsetof(K, z)); + EXPECT_FALSE(Cpp::IsClassDefined(datamembers[2])); } #define CODE \