Skip to content

Commit 21266fe

Browse files
committed
Add type info interfaces motivated by numba
- Add `IsSameType` used for matching arg types between numba inferred signatures and CppOverloads in cppyy. - Add type info reflection interfaces for integer, void pointer, signed and unsigned types. - Also added interfaces `IsIntegral` and `IsFloating` that check if types have the respective representations. Used in the case of Numba where scoring based on reflection is required.
1 parent f0f59f2 commit 21266fe

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

include/clang/Interpreter/CppInterOp.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,15 +509,40 @@ namespace Cpp {
509509
/// Checks if the provided parameter is a Plain Old Data Type (POD).
510510
CPPINTEROP_API bool IsPODType(TCppType_t type);
511511

512+
/// Checks if type has an integer representation
513+
CPPINTEROP_API bool IsIntegerType(TCppType_t type);
514+
515+
/// Checks if type is an integral type
516+
CPPINTEROP_API bool IsIntegralType(TCppType_t type);
517+
518+
/// Checks if type is a signed integer
519+
CPPINTEROP_API bool IsSignedIntegerType(TCppType_t type);
520+
521+
/// Checks if type has an unsigned integer
522+
CPPINTEROP_API bool IsUnsignedIntegerType(TCppType_t type);
523+
524+
/// Checks if type has a floating representation
525+
CPPINTEROP_API bool IsFloatingType(TCppType_t type);
526+
527+
/// Checks if two types are the equivalent
528+
/// i.e. have the same canonical type
529+
CPPINTEROP_API bool IsSameType(TCppType_t type_a, TCppType_t type_b);
530+
512531
/// Checks if type is a pointer
513532
CPPINTEROP_API bool IsPointerType(TCppType_t type);
514533

534+
/// Checks if type is a void pointer
535+
CPPINTEROP_API bool IsVoidPointerType(TCppType_t type);
536+
515537
/// Get the underlying pointee type
516538
CPPINTEROP_API TCppType_t GetPointeeType(TCppType_t type);
517539

518540
/// Checks if type is a reference
519541
CPPINTEROP_API bool IsReferenceType(TCppType_t type);
520542

543+
/// Get the type handle to the unqualified type
544+
CPPINTEROP_API TCppType_t GetUnqualifiedType(TCppType_t type);
545+
521546
/// Get the type that the reference refers to
522547
CPPINTEROP_API TCppType_t GetNonReferenceType(TCppType_t type);
523548

lib/Interpreter/CppInterOp.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,11 +1549,47 @@ namespace Cpp {
15491549
return QT.isPODType(getASTContext());
15501550
}
15511551

1552+
bool IsIntegerType(TCppType_t type) {
1553+
QualType QT = QualType::getFromOpaquePtr(type);
1554+
return QT->hasIntegerRepresentation();
1555+
}
1556+
1557+
bool IsIntegralType(TCppType_t type) {
1558+
QualType QT = QualType::getFromOpaquePtr(type);
1559+
return QT->isIntegralType(getASTContext());
1560+
}
1561+
1562+
bool IsSignedIntegerType(TCppType_t type) {
1563+
QualType QT = QualType::getFromOpaquePtr(type);
1564+
return QT->hasSignedIntegerRepresentation();
1565+
}
1566+
1567+
bool IsUnsignedIntegerType(TCppType_t type) {
1568+
QualType QT = QualType::getFromOpaquePtr(type);
1569+
return QT->hasUnsignedIntegerRepresentation();
1570+
}
1571+
1572+
bool IsFloatingType(TCppType_t type) {
1573+
QualType QT = QualType::getFromOpaquePtr(type);
1574+
return QT->hasFloatingRepresentation();
1575+
}
1576+
1577+
bool IsSameType(TCppType_t type_a, TCppType_t type_b) {
1578+
clang::QualType QT1 = clang::QualType::getFromOpaquePtr(type_a);
1579+
clang::QualType QT2 = clang::QualType::getFromOpaquePtr(type_b);
1580+
return getASTContext().hasSameType(QT1, QT2);
1581+
}
1582+
15521583
bool IsPointerType(TCppType_t type) {
15531584
QualType QT = QualType::getFromOpaquePtr(type);
15541585
return QT->isPointerType();
15551586
}
15561587

1588+
bool IsVoidPointerType(TCppType_t type) {
1589+
QualType QT = QualType::getFromOpaquePtr(type);
1590+
return QT->isVoidPointerType();
1591+
}
1592+
15571593
TCppType_t GetPointeeType(TCppType_t type) {
15581594
if (!IsPointerType(type))
15591595
return nullptr;
@@ -1573,8 +1609,17 @@ namespace Cpp {
15731609
return QT.getNonReferenceType().getAsOpaquePtr();
15741610
}
15751611

1612+
TCppType_t GetUnqualifiedType(TCppType_t type) {
1613+
if (!type)
1614+
return 0;
1615+
QualType QT = QualType::getFromOpaquePtr(type);
1616+
return QT.getUnqualifiedType().getAsOpaquePtr();
1617+
}
1618+
15761619
TCppType_t GetUnderlyingType(TCppType_t type)
15771620
{
1621+
if (!type)
1622+
return 0;
15781623
QualType QT = QualType::getFromOpaquePtr(type);
15791624
QT = QT->getCanonicalTypeUnqualified();
15801625

0 commit comments

Comments
 (0)