Skip to content

Commit 614eec5

Browse files
committed
Add various type check interfaces required by numba extension
1 parent 2585d0d commit 614eec5

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

include/CppInterOp/CppInterOp.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ enum Operator : unsigned char {
9393
};
9494

9595
enum OperatorArity : unsigned char { kUnary = 1, kBinary, kBoth };
96+
enum Signedness : unsigned char { kSigned = 1, kUnsigned, kAny };
9697

9798
/// A class modeling function calls for functions produced by the interpreter
9899
/// in compiled code. It provides an information if we are calling a standard
@@ -578,6 +579,22 @@ CPPINTEROP_API bool IsRecordType(TCppType_t type);
578579
/// Checks if the provided parameter is a Plain Old Data Type (POD).
579580
CPPINTEROP_API bool IsPODType(TCppType_t type);
580581

582+
/// Checks if type has an integer representation
583+
CPPINTEROP_API bool IsIntegerType(TCppType_t type,
584+
Signedness s = Signedness::kAny);
585+
586+
/// Checks if type has a floating representation
587+
CPPINTEROP_API bool IsFloatingType(TCppType_t type);
588+
589+
/// Checks if two types are the equivalent
590+
/// i.e. have the same canonical type
591+
CPPINTEROP_API bool IsSameType(TCppType_t type_a, TCppType_t type_b);
592+
593+
/// Checks if type is a void pointer
594+
CPPINTEROP_API bool IsVoidPointerType(TCppType_t type);
595+
596+
/// Get the type handle to the unqualified type
597+
CPPINTEROP_API TCppType_t GetUnqualifiedType(TCppType_t type);
581598
/// Checks if type is a pointer
582599
CPPINTEROP_API bool IsPointerType(TCppType_t type);
583600

lib/CppInterOp/CppInterOp.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,18 +1619,58 @@ bool IsPODType(TCppType_t type) {
16191619
return QT.isPODType(getASTContext());
16201620
}
16211621

1622+
bool IsIntegerType(TCppType_t type, Signedness s) {
1623+
if (!type)
1624+
return false;
1625+
QualType QT = QualType::getFromOpaquePtr(type);
1626+
switch (s) {
1627+
case Signedness::kAny:
1628+
return QT->hasIntegerRepresentation();
1629+
1630+
case Signedness::kSigned:
1631+
return QT->hasSignedIntegerRepresentation();
1632+
1633+
case Signedness::kUnsigned:
1634+
return QT->hasUnsignedIntegerRepresentation();
1635+
}
1636+
return false;
1637+
}
1638+
1639+
bool IsFloatingType(TCppType_t type) {
1640+
QualType QT = QualType::getFromOpaquePtr(type);
1641+
return QT->hasFloatingRepresentation();
1642+
}
1643+
1644+
bool IsSameType(TCppType_t type_a, TCppType_t type_b) {
1645+
clang::QualType QT1 = clang::QualType::getFromOpaquePtr(type_a);
1646+
clang::QualType QT2 = clang::QualType::getFromOpaquePtr(type_b);
1647+
return getASTContext().hasSameType(QT1, QT2);
1648+
}
1649+
16221650
bool IsPointerType(TCppType_t type) {
16231651
QualType QT = QualType::getFromOpaquePtr(type);
16241652
return QT->isPointerType();
16251653
}
16261654

1655+
bool IsVoidPointerType(TCppType_t type) {
1656+
QualType QT = QualType::getFromOpaquePtr(type);
1657+
return QT->isVoidPointerType();
1658+
}
1659+
16271660
TCppType_t GetPointeeType(TCppType_t type) {
16281661
if (!IsPointerType(type))
16291662
return nullptr;
16301663
QualType QT = QualType::getFromOpaquePtr(type);
16311664
return QT->getPointeeType().getAsOpaquePtr();
16321665
}
16331666

1667+
TCppType_t GetUnqualifiedType(TCppType_t type) {
1668+
if (!type)
1669+
return nullptr;
1670+
QualType QT = QualType::getFromOpaquePtr(type);
1671+
return QT.getUnqualifiedType().getAsOpaquePtr();
1672+
}
1673+
16341674
bool IsReferenceType(TCppType_t type) {
16351675
QualType QT = QualType::getFromOpaquePtr(type);
16361676
return QT->isReferenceType();
@@ -1666,6 +1706,8 @@ TCppType_t GetNonReferenceType(TCppType_t type) {
16661706
}
16671707

16681708
TCppType_t GetUnderlyingType(TCppType_t type) {
1709+
if (!type)
1710+
return nullptr;
16691711
QualType QT = QualType::getFromOpaquePtr(type);
16701712
QT = QT->getCanonicalTypeUnqualified();
16711713

0 commit comments

Comments
 (0)