Skip to content

add IsLValueReferenceType & GetReferencedType #596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
6 changes: 6 additions & 0 deletions include/CppInterOp/CppInterOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,15 @@ CPPINTEROP_API TCppType_t GetPointeeType(TCppType_t type);
/// Checks if type is a reference
CPPINTEROP_API bool IsReferenceType(TCppType_t type);

/// Checks if type is a LValue reference
CPPINTEROP_API bool IsLValueReferenceType(TCppType_t type);

/// Get the type that the reference refers to
CPPINTEROP_API TCppType_t GetNonReferenceType(TCppType_t type);

/// Get lvalue referenced type
CPPINTEROP_API TCppType_t GetReferencedType(TCppType_t type);

/// Gets the pure, Underlying Type (as opposed to the Using Type).
CPPINTEROP_API TCppType_t GetUnderlyingType(TCppType_t type);

Expand Down
10 changes: 10 additions & 0 deletions lib/CppInterOp/CppInterOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,16 @@ bool IsReferenceType(TCppType_t type) {
return QT->isReferenceType();
}

bool IsLValueReferenceType(TCppType_t type) {
QualType QT = QualType::getFromOpaquePtr(type);
return QT->isLValueReferenceType();
}

TCppType_t GetReferencedType(TCppType_t type) {
QualType QT = QualType::getFromOpaquePtr(type);
return getASTContext().getLValueReferenceType(QT).getAsOpaquePtr();
}

TCppType_t GetNonReferenceType(TCppType_t type) {
if (!IsReferenceType(type))
return nullptr;
Expand Down
4 changes: 4 additions & 0 deletions unittests/CppInterOp/VariableReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,4 +677,8 @@ TEST(VariableReflectionTest, Is_Get_Reference) {
Cpp::GetVariableType(Decls[5]));

EXPECT_FALSE(Cpp::GetNonReferenceType(Cpp::GetVariableType(Decls[5])));

EXPECT_TRUE(Cpp::IsLValueReferenceType(Cpp::GetVariableType(Decls[2])));
EXPECT_EQ(Cpp::GetReferencedType(Cpp::GetVariableType(Decls[1])),
Cpp::GetVariableType(Decls[2]));
}
Loading