Skip to content
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
11 changes: 9 additions & 2 deletions include/CppInterOp/CppInterOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,18 @@ 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 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);
/// Get lvalue referenced type, or rvalue if rvalue is true
CPPINTEROP_API TCppType_t GetReferencedType(TCppType_t type,
bool rvalue = false);

/// Get the pointer to type
CPPINTEROP_API TCppType_t GetPointerType(TCppType_t type);

/// Gets the pure, Underlying Type (as opposed to the Using Type).
CPPINTEROP_API TCppType_t GetUnderlyingType(TCppType_t type);
Expand Down
14 changes: 13 additions & 1 deletion lib/CppInterOp/CppInterOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1615,8 +1615,20 @@ bool IsLValueReferenceType(TCppType_t type) {
return QT->isLValueReferenceType();
}

TCppType_t GetReferencedType(TCppType_t type) {
bool IsRValueReferenceType(TCppType_t type) {
QualType QT = QualType::getFromOpaquePtr(type);
return QT->isRValueReferenceType();
}

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

TCppType_t GetReferencedType(TCppType_t type, bool rvalue) {
QualType QT = QualType::getFromOpaquePtr(type);
if (rvalue)
return getASTContext().getRValueReferenceType(QT).getAsOpaquePtr();
return getASTContext().getLValueReferenceType(QT).getAsOpaquePtr();
}

Expand Down
25 changes: 25 additions & 0 deletions unittests/CppInterOp/VariableReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,4 +681,29 @@ TEST(VariableReflectionTest, Is_Get_Reference) {
EXPECT_TRUE(Cpp::IsLValueReferenceType(Cpp::GetVariableType(Decls[2])));
EXPECT_EQ(Cpp::GetReferencedType(Cpp::GetVariableType(Decls[1])),
Cpp::GetVariableType(Decls[2]));
EXPECT_TRUE(Cpp::IsRValueReferenceType(
Cpp::GetReferencedType(Cpp::GetVariableType(Decls[1]), true)));
}

TEST(VariableReflectionTest, GetPointerType) {
Cpp::CreateInterpreter();
std::vector<Decl*> Decls;
std::string code = R"(
class A {};
int a;
int *b = &a;
double c;
double *d = &c;
A e;
A *f = &e;
)";

GetAllTopLevelDecls(code, Decls);

EXPECT_EQ(Cpp::GetPointerType(Cpp::GetVariableType(Decls[1])),
Cpp::GetVariableType(Decls[2]));
EXPECT_EQ(Cpp::GetPointerType(Cpp::GetVariableType(Decls[3])),
Cpp::GetVariableType(Decls[4]));
EXPECT_EQ(Cpp::GetPointerType(Cpp::GetVariableType(Decls[5])),
Cpp::GetVariableType(Decls[6]));
}
Loading