Skip to content
Closed
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 @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is that different from IsComplete?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsComplete does what I want. Sorry, I missed that API. Will close this PR.


/// Checks if the scope is a function.
CPPINTEROP_API bool IsFunction(TCppScope_t scope);

Expand Down
8 changes: 8 additions & 0 deletions lib/CppInterOp/CppInterOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ bool IsClass(TCppScope_t scope) {
return isa<CXXRecordDecl>(D);
}

bool IsClassDefined(TCppScope_t klass) {
Decl* D = static_cast<Decl*>(klass);
if (auto* CXXRD = llvm::dyn_cast<CXXRecordDecl>(D)) {
return CXXRD->hasDefinition();
}
return false;
}

bool IsFunction(TCppScope_t scope) {
Decl* D = static_cast<Decl*>(scope);
return isa<FunctionDecl>(D);
Expand Down
4 changes: 4 additions & 0 deletions unittests/CppInterOp/VariableReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 \
Expand Down
Loading