Skip to content

Commit d38caa4

Browse files
add IsClassDefined
1 parent 180869d commit d38caa4

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
@@ -265,6 +265,9 @@ CPPINTEROP_API bool IsNamespace(TCppScope_t scope);
265265
/// Checks if the scope is a class or not.
266266
CPPINTEROP_API bool IsClass(TCppScope_t scope);
267267

268+
/// Checks if the klass has a definition
269+
CPPINTEROP_API bool IsClassDefined(TCppScope_t klass);
270+
268271
/// Checks if the scope is a function.
269272
CPPINTEROP_API bool IsFunction(TCppScope_t scope);
270273

lib/CppInterOp/CppInterOp.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ bool IsClass(TCppScope_t scope) {
271271
return isa<CXXRecordDecl>(D);
272272
}
273273

274+
bool IsClassDefined(TCppScope_t klass) {
275+
Decl* D = static_cast<Decl*>(klass);
276+
if (auto* CXXRD = llvm::dyn_cast<CXXRecordDecl>(D)) {
277+
return CXXRD->hasDefinition();
278+
}
279+
return false;
280+
}
281+
274282
bool IsFunction(TCppScope_t scope) {
275283
Decl* D = static_cast<Decl*>(scope);
276284
return isa<FunctionDecl>(D);

unittests/CppInterOp/VariableReflectionTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,11 @@ TEST(VariableReflectionTest, GetVariableOffset) {
308308
Cpp::Declare("struct K;");
309309
Cpp::TCppScope_t k = Cpp::GetNamed("K");
310310
EXPECT_TRUE(k);
311+
EXPECT_TRUE(Cpp::IsClass(k));
312+
EXPECT_FALSE(Cpp::IsClassDefined(k));
311313

312314
Cpp::Declare("struct K { int x; int y; int z; };");
315+
EXPECT_TRUE(Cpp::IsClassDefined(k));
313316

314317
datamembers.clear();
315318
Cpp::GetDatamembers(k, datamembers);
@@ -318,6 +321,7 @@ TEST(VariableReflectionTest, GetVariableOffset) {
318321
EXPECT_EQ(Cpp::GetVariableOffset(datamembers[0]), offsetof(K, x));
319322
EXPECT_EQ(Cpp::GetVariableOffset(datamembers[1]), offsetof(K, y));
320323
EXPECT_EQ(Cpp::GetVariableOffset(datamembers[2]), offsetof(K, z));
324+
EXPECT_FALSE(Cpp::IsClassDefined(datamembers[2]));
321325
}
322326

323327
#define CODE \

0 commit comments

Comments
 (0)