Skip to content

Commit a882d9d

Browse files
add GetReferenceValueKind
and remove `IsLValueReferenceType` & `IsRValueReferenceType`
1 parent 2df83a9 commit a882d9d

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

include/CppInterOp/CppInterOp.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ inline QualKind operator|(QualKind a, QualKind b) {
107107
static_cast<unsigned char>(b));
108108
}
109109

110+
enum class ValueKind : std::uint8_t {
111+
None,
112+
LValue,
113+
RValue,
114+
};
115+
110116
/// A class modeling function calls for functions produced by the interpreter
111117
/// in compiled code. It provides an information if we are calling a standard
112118
/// function, constructor or destructor.
@@ -615,11 +621,8 @@ CPPINTEROP_API TCppType_t GetPointeeType(TCppType_t type);
615621
/// Checks if type is a reference
616622
CPPINTEROP_API bool IsReferenceType(TCppType_t type);
617623

618-
/// Checks if type is a LValue reference
619-
CPPINTEROP_API bool IsLValueReferenceType(TCppType_t type);
620-
621-
/// Checks if type is a LValue reference
622-
CPPINTEROP_API bool IsRValueReferenceType(TCppType_t type);
624+
/// Get if lvalue or rvalue reference
625+
CPPINTEROP_API ValueKind GetValueKind(TCppType_t type);
623626

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

lib/CppInterOp/CppInterOp.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,14 +1696,13 @@ bool IsReferenceType(TCppType_t type) {
16961696
return QT->isReferenceType();
16971697
}
16981698

1699-
bool IsLValueReferenceType(TCppType_t type) {
1699+
ValueKind GetValueKind(TCppType_t type) {
17001700
QualType QT = QualType::getFromOpaquePtr(type);
1701-
return QT->isLValueReferenceType();
1702-
}
1703-
1704-
bool IsRValueReferenceType(TCppType_t type) {
1705-
QualType QT = QualType::getFromOpaquePtr(type);
1706-
return QT->isRValueReferenceType();
1701+
if (QT->isRValueReferenceType())
1702+
return ValueKind::RValue;
1703+
if (QT->isLValueReferenceType())
1704+
return ValueKind::LValue;
1705+
return ValueKind::None;
17071706
}
17081707

17091708
TCppType_t GetPointerType(TCppType_t type) {

unittests/CppInterOp/VariableReflectionTest.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,11 +723,13 @@ TYPED_TEST(CppInterOpTest, VariableReflectionTestIs_Get_Reference) {
723723

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

726-
EXPECT_TRUE(Cpp::IsLValueReferenceType(Cpp::GetVariableType(Decls[2])));
726+
EXPECT_EQ(Cpp::GetValueKind(Cpp::GetVariableType(Decls[2])),
727+
Cpp::ValueKind::LValue);
727728
EXPECT_EQ(Cpp::GetReferencedType(Cpp::GetVariableType(Decls[1])),
728729
Cpp::GetVariableType(Decls[2]));
729-
EXPECT_TRUE(Cpp::IsRValueReferenceType(
730-
Cpp::GetReferencedType(Cpp::GetVariableType(Decls[1]), true)));
730+
EXPECT_EQ(Cpp::GetValueKind(
731+
Cpp::GetReferencedType(Cpp::GetVariableType(Decls[1]), true)),
732+
Cpp::ValueKind::RValue);
731733
}
732734

733735
TYPED_TEST(CppInterOpTest, VariableReflectionTestGetPointerType) {

0 commit comments

Comments
 (0)