Skip to content

Commit 29f2920

Browse files
add IsLValueReferenceType & GetReferencedType (#596)
1 parent 83b0429 commit 29f2920

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

include/CppInterOp/CppInterOp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,15 @@ CPPINTEROP_API TCppType_t GetPointeeType(TCppType_t type);
541541
/// Checks if type is a reference
542542
CPPINTEROP_API bool IsReferenceType(TCppType_t type);
543543

544+
/// Checks if type is a LValue reference
545+
CPPINTEROP_API bool IsLValueReferenceType(TCppType_t type);
546+
544547
/// Get the type that the reference refers to
545548
CPPINTEROP_API TCppType_t GetNonReferenceType(TCppType_t type);
546549

550+
/// Get lvalue referenced type
551+
CPPINTEROP_API TCppType_t GetReferencedType(TCppType_t type);
552+
547553
/// Gets the pure, Underlying Type (as opposed to the Using Type).
548554
CPPINTEROP_API TCppType_t GetUnderlyingType(TCppType_t type);
549555

lib/CppInterOp/CppInterOp.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,6 +1561,16 @@ bool IsReferenceType(TCppType_t type) {
15611561
return QT->isReferenceType();
15621562
}
15631563

1564+
bool IsLValueReferenceType(TCppType_t type) {
1565+
QualType QT = QualType::getFromOpaquePtr(type);
1566+
return QT->isLValueReferenceType();
1567+
}
1568+
1569+
TCppType_t GetReferencedType(TCppType_t type) {
1570+
QualType QT = QualType::getFromOpaquePtr(type);
1571+
return getASTContext().getLValueReferenceType(QT).getAsOpaquePtr();
1572+
}
1573+
15641574
TCppType_t GetNonReferenceType(TCppType_t type) {
15651575
if (!IsReferenceType(type))
15661576
return nullptr;

unittests/CppInterOp/VariableReflectionTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,4 +677,8 @@ TEST(VariableReflectionTest, Is_Get_Reference) {
677677
Cpp::GetVariableType(Decls[5]));
678678

679679
EXPECT_FALSE(Cpp::GetNonReferenceType(Cpp::GetVariableType(Decls[5])));
680+
681+
EXPECT_TRUE(Cpp::IsLValueReferenceType(Cpp::GetVariableType(Decls[2])));
682+
EXPECT_EQ(Cpp::GetReferencedType(Cpp::GetVariableType(Decls[1])),
683+
Cpp::GetVariableType(Decls[2]));
680684
}

0 commit comments

Comments
 (0)