From 43f1fe141e92f84bef0a7402bf3179e50b3c7995 Mon Sep 17 00:00:00 2001 From: Vipul Cariappa Date: Wed, 26 Nov 2025 15:19:41 +0100 Subject: [PATCH] add `GetReferenceValueKind` and remove `IsLValueReferenceType` & `IsRValueReferenceType` --- include/CppInterOp/CppInterOp.h | 13 ++++++++----- lib/CppInterOp/CppInterOp.cpp | 13 ++++++------- unittests/CppInterOp/VariableReflectionTest.cpp | 10 +++++++--- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/include/CppInterOp/CppInterOp.h b/include/CppInterOp/CppInterOp.h index 79cffad12..1d85df305 100644 --- a/include/CppInterOp/CppInterOp.h +++ b/include/CppInterOp/CppInterOp.h @@ -107,6 +107,12 @@ inline QualKind operator|(QualKind a, QualKind b) { static_cast(b)); } +enum class ValueKind : std::uint8_t { + None, + LValue, + RValue, +}; + /// A class modeling function calls for functions produced by the interpreter /// in compiled code. It provides an information if we are calling a standard /// function, constructor or destructor. @@ -615,11 +621,8 @@ 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); - -/// Checks if type is a LValue reference -CPPINTEROP_API bool IsRValueReferenceType(TCppType_t type); +/// Get if lvalue or rvalue reference +CPPINTEROP_API ValueKind GetValueKind(TCppType_t type); /// Get the type that the reference refers to CPPINTEROP_API TCppType_t GetNonReferenceType(TCppType_t type); diff --git a/lib/CppInterOp/CppInterOp.cpp b/lib/CppInterOp/CppInterOp.cpp index 3a5a345f4..38d2f1cf5 100755 --- a/lib/CppInterOp/CppInterOp.cpp +++ b/lib/CppInterOp/CppInterOp.cpp @@ -1696,14 +1696,13 @@ bool IsReferenceType(TCppType_t type) { return QT->isReferenceType(); } -bool IsLValueReferenceType(TCppType_t type) { +ValueKind GetValueKind(TCppType_t type) { QualType QT = QualType::getFromOpaquePtr(type); - return QT->isLValueReferenceType(); -} - -bool IsRValueReferenceType(TCppType_t type) { - QualType QT = QualType::getFromOpaquePtr(type); - return QT->isRValueReferenceType(); + if (QT->isRValueReferenceType()) + return ValueKind::RValue; + if (QT->isLValueReferenceType()) + return ValueKind::LValue; + return ValueKind::None; } TCppType_t GetPointerType(TCppType_t type) { diff --git a/unittests/CppInterOp/VariableReflectionTest.cpp b/unittests/CppInterOp/VariableReflectionTest.cpp index 15bfef163..581dab7e4 100644 --- a/unittests/CppInterOp/VariableReflectionTest.cpp +++ b/unittests/CppInterOp/VariableReflectionTest.cpp @@ -723,11 +723,15 @@ TYPED_TEST(CppInterOpTest, VariableReflectionTestIs_Get_Reference) { EXPECT_FALSE(Cpp::GetNonReferenceType(Cpp::GetVariableType(Decls[5]))); - EXPECT_TRUE(Cpp::IsLValueReferenceType(Cpp::GetVariableType(Decls[2]))); + EXPECT_EQ(Cpp::GetValueKind(Cpp::GetVariableType(Decls[2])), + Cpp::ValueKind::LValue); EXPECT_EQ(Cpp::GetReferencedType(Cpp::GetVariableType(Decls[1])), Cpp::GetVariableType(Decls[2])); - EXPECT_TRUE(Cpp::IsRValueReferenceType( - Cpp::GetReferencedType(Cpp::GetVariableType(Decls[1]), true))); + EXPECT_EQ(Cpp::GetValueKind( + Cpp::GetReferencedType(Cpp::GetVariableType(Decls[1]), true)), + Cpp::ValueKind::RValue); + EXPECT_EQ(Cpp::GetValueKind(Cpp::GetVariableType(Decls[1])), + Cpp::ValueKind::None); } TYPED_TEST(CppInterOpTest, VariableReflectionTestGetPointerType) {