File tree Expand file tree Collapse file tree 3 files changed +47
-3
lines changed
Expand file tree Collapse file tree 3 files changed +47
-3
lines changed Original file line number Diff line number Diff line change @@ -544,11 +544,18 @@ CPPINTEROP_API bool IsReferenceType(TCppType_t type);
544544// / Checks if type is a LValue reference
545545CPPINTEROP_API bool IsLValueReferenceType (TCppType_t type);
546546
547+ // / Checks if type is a LValue reference
548+ CPPINTEROP_API bool IsRValueReferenceType (TCppType_t type);
549+
547550// / Get the type that the reference refers to
548551CPPINTEROP_API TCppType_t GetNonReferenceType (TCppType_t type);
549552
550- // / Get lvalue referenced type
551- CPPINTEROP_API TCppType_t GetReferencedType (TCppType_t type);
553+ // / Get lvalue referenced type, or rvalue if rvalue is true
554+ CPPINTEROP_API TCppType_t GetReferencedType (TCppType_t type,
555+ bool rvalue = false );
556+
557+ // / Get the pointer to type
558+ CPPINTEROP_API TCppType_t GetPointerType (TCppType_t type);
552559
553560// / Gets the pure, Underlying Type (as opposed to the Using Type).
554561CPPINTEROP_API TCppType_t GetUnderlyingType (TCppType_t type);
Original file line number Diff line number Diff line change @@ -1615,8 +1615,20 @@ bool IsLValueReferenceType(TCppType_t type) {
16151615 return QT->isLValueReferenceType ();
16161616}
16171617
1618- TCppType_t GetReferencedType (TCppType_t type) {
1618+ bool IsRValueReferenceType (TCppType_t type) {
16191619 QualType QT = QualType::getFromOpaquePtr (type);
1620+ return QT->isRValueReferenceType ();
1621+ }
1622+
1623+ TCppType_t GetPointerType (TCppType_t type) {
1624+ QualType QT = QualType::getFromOpaquePtr (type);
1625+ return getASTContext ().getPointerType (QT).getAsOpaquePtr ();
1626+ }
1627+
1628+ TCppType_t GetReferencedType (TCppType_t type, bool rvalue) {
1629+ QualType QT = QualType::getFromOpaquePtr (type);
1630+ if (rvalue)
1631+ return getASTContext ().getRValueReferenceType (QT).getAsOpaquePtr ();
16201632 return getASTContext ().getLValueReferenceType (QT).getAsOpaquePtr ();
16211633}
16221634
Original file line number Diff line number Diff line change @@ -681,4 +681,29 @@ TEST(VariableReflectionTest, Is_Get_Reference) {
681681 EXPECT_TRUE (Cpp::IsLValueReferenceType (Cpp::GetVariableType (Decls[2 ])));
682682 EXPECT_EQ (Cpp::GetReferencedType (Cpp::GetVariableType (Decls[1 ])),
683683 Cpp::GetVariableType (Decls[2 ]));
684+ EXPECT_TRUE (Cpp::IsRValueReferenceType (
685+ Cpp::GetReferencedType (Cpp::GetVariableType (Decls[1 ]), true )));
686+ }
687+
688+ TEST (VariableReflectionTest, GetPointerType) {
689+ Cpp::CreateInterpreter ();
690+ std::vector<Decl*> Decls;
691+ std::string code = R"(
692+ class A {};
693+ int a;
694+ int *b = &a;
695+ double c;
696+ double *d = &c;
697+ A e;
698+ A *f = &e;
699+ )" ;
700+
701+ GetAllTopLevelDecls (code, Decls);
702+
703+ EXPECT_EQ (Cpp::GetPointerType (Cpp::GetVariableType (Decls[1 ])),
704+ Cpp::GetVariableType (Decls[2 ]));
705+ EXPECT_EQ (Cpp::GetPointerType (Cpp::GetVariableType (Decls[3 ])),
706+ Cpp::GetVariableType (Decls[4 ]));
707+ EXPECT_EQ (Cpp::GetPointerType (Cpp::GetVariableType (Decls[5 ])),
708+ Cpp::GetVariableType (Decls[6 ]));
684709}
You can’t perform that action at this time.
0 commit comments