Skip to content

Commit f809fce

Browse files
Add IsRestrictQualifiedType & GetNonRestrictQualifiedType functions
1 parent 951775f commit f809fce

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

include/clang/Interpreter/CppInterOp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,12 @@ namespace Cpp {
546546
/// out of it.
547547
CPPINTEROP_API TCppType_t GetCanonicalType(TCppType_t type);
548548

549+
/// Get non restrict qualified version of the given type
550+
CPPINTEROP_API TCppType_t GetNonRestrictQualifiedType(TCppType_t type);
551+
552+
/// check if the type is restrict qualified i.e. __restrict
553+
CPPINTEROP_API bool IsRestrictQualifiedType(TCppType_t type);
554+
549555
/// Used to either get the built-in type of the provided string, or
550556
/// use the name to lookup the actual type.
551557
CPPINTEROP_API TCppType_t GetType(const std::string& type);

lib/Interpreter/CppInterOp.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,25 @@ namespace Cpp {
16571657
return QT.getCanonicalType().getAsOpaquePtr();
16581658
}
16591659

1660+
bool IsRestrictQualifiedType(TCppType_t type) {
1661+
if (!type)
1662+
return 0;
1663+
QualType QT = QualType::getFromOpaquePtr(type);
1664+
return QT.isRestrictQualified();
1665+
}
1666+
1667+
TCppType_t GetNonRestrictQualifiedType(TCppType_t type) {
1668+
if (!type)
1669+
return 0;
1670+
QualType QT = QualType::getFromOpaquePtr(type);
1671+
if (QT.isRestrictQualified()) {
1672+
QualType NonRestrictType(QT);
1673+
NonRestrictType.removeLocalRestrict();
1674+
return NonRestrictType.getAsOpaquePtr();
1675+
}
1676+
return nullptr;
1677+
}
1678+
16601679
// Internal functions that are not needed outside the library are
16611680
// encompassed in an anonymous namespace as follows. This function converts
16621681
// from a string to the actual type. It is used in the GetType() function.

unittests/CppInterOp/TypeReflectionTest.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,3 +610,21 @@ TEST(TypeReflectionTest, IsFunctionPointerType) {
610610
EXPECT_FALSE(
611611
Cpp::IsFunctionPointerType(Cpp::GetVariableType(Cpp::GetNamed("i"))));
612612
}
613+
614+
TEST(TypeReflectionTest, RestrictQualifiedType) {
615+
Cpp::CreateInterpreter();
616+
Cpp::Declare(R"(
617+
int *x;
618+
int *__restrict y;
619+
)");
620+
621+
Cpp::TCppType_t x = Cpp::GetVariableType(Cpp::GetNamed("x"));
622+
Cpp::TCppType_t y = Cpp::GetVariableType(Cpp::GetNamed("y"));
623+
624+
EXPECT_FALSE(Cpp::IsRestrictQualifiedType(x));
625+
EXPECT_TRUE(Cpp::IsRestrictQualifiedType(y));
626+
627+
EXPECT_FALSE(Cpp::GetNonRestrictQualifiedType(x));
628+
EXPECT_EQ(Cpp::GetCanonicalType(Cpp::GetNonRestrictQualifiedType(y)),
629+
Cpp::GetCanonicalType(x));
630+
}

0 commit comments

Comments
 (0)