Skip to content

Commit 7487a27

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 2595a1f commit 7487a27

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
@@ -523,15 +523,40 @@ namespace Cpp {
523523
/// Checks if the provided parameter is a Plain Old Data Type (POD).
524524
CPPINTEROP_API bool IsPODType(TCppType_t type);
525525

526+
/// Checks if type has an integer representation
527+
CPPINTEROP_API bool IsIntegerType(TCppType_t type);
528+
529+
/// Checks if type is an integral type
530+
CPPINTEROP_API bool IsIntegralType(TCppType_t type);
531+
532+
/// Checks if type is a signed integer
533+
CPPINTEROP_API bool IsSignedIntegerType(TCppType_t type);
534+
535+
/// Checks if type has an unsigned integer
536+
CPPINTEROP_API bool IsUnsignedIntegerType(TCppType_t type);
537+
538+
/// Checks if type has a floating representation
539+
CPPINTEROP_API bool IsFloatingType(TCppType_t type);
540+
541+
/// Checks if two types are the equivalent
542+
/// i.e. have the same canonical type
543+
CPPINTEROP_API bool IsSameType(TCppType_t type_a, TCppType_t type_b);
544+
526545
/// Checks if type is a pointer
527546
CPPINTEROP_API bool IsPointerType(TCppType_t type);
528547

548+
/// Checks if type is a void pointer
549+
CPPINTEROP_API bool IsVoidPointerType(TCppType_t type);
550+
529551
/// Get the underlying pointee type
530552
CPPINTEROP_API TCppType_t GetPointeeType(TCppType_t type);
531553

532554
/// Checks if type is a reference
533555
CPPINTEROP_API bool IsReferenceType(TCppType_t type);
534556

557+
/// Get the type handle to the unqualified type
558+
CPPINTEROP_API TCppType_t GetUnqualifiedType(TCppType_t type);
559+
535560
/// Get the type that the reference refers to
536561
CPPINTEROP_API TCppType_t GetNonReferenceType(TCppType_t type);
537562

lib/Interpreter/CppInterOp.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,11 +1597,47 @@ namespace Cpp {
15971597
return QT.isPODType(getASTContext());
15981598
}
15991599

1600+
bool IsIntegerType(TCppType_t type) {
1601+
QualType QT = QualType::getFromOpaquePtr(type);
1602+
return QT->hasIntegerRepresentation();
1603+
}
1604+
1605+
bool IsIntegralType(TCppType_t type) {
1606+
QualType QT = QualType::getFromOpaquePtr(type);
1607+
return QT->isIntegralType(getASTContext());
1608+
}
1609+
1610+
bool IsSignedIntegerType(TCppType_t type) {
1611+
QualType QT = QualType::getFromOpaquePtr(type);
1612+
return QT->hasSignedIntegerRepresentation();
1613+
}
1614+
1615+
bool IsUnsignedIntegerType(TCppType_t type) {
1616+
QualType QT = QualType::getFromOpaquePtr(type);
1617+
return QT->hasUnsignedIntegerRepresentation();
1618+
}
1619+
1620+
bool IsFloatingType(TCppType_t type) {
1621+
QualType QT = QualType::getFromOpaquePtr(type);
1622+
return QT->hasFloatingRepresentation();
1623+
}
1624+
1625+
bool IsSameType(TCppType_t type_a, TCppType_t type_b) {
1626+
clang::QualType QT1 = clang::QualType::getFromOpaquePtr(type_a);
1627+
clang::QualType QT2 = clang::QualType::getFromOpaquePtr(type_b);
1628+
return getASTContext().hasSameType(QT1, QT2);
1629+
}
1630+
16001631
bool IsPointerType(TCppType_t type) {
16011632
QualType QT = QualType::getFromOpaquePtr(type);
16021633
return QT->isPointerType();
16031634
}
16041635

1636+
bool IsVoidPointerType(TCppType_t type) {
1637+
QualType QT = QualType::getFromOpaquePtr(type);
1638+
return QT->isVoidPointerType();
1639+
}
1640+
16051641
TCppType_t GetPointeeType(TCppType_t type) {
16061642
if (!IsPointerType(type))
16071643
return nullptr;
@@ -1621,8 +1657,17 @@ namespace Cpp {
16211657
return QT.getNonReferenceType().getAsOpaquePtr();
16221658
}
16231659

1660+
TCppType_t GetUnqualifiedType(TCppType_t type) {
1661+
if (!type)
1662+
return 0;
1663+
QualType QT = QualType::getFromOpaquePtr(type);
1664+
return QT.getUnqualifiedType().getAsOpaquePtr();
1665+
}
1666+
16241667
TCppType_t GetUnderlyingType(TCppType_t type)
16251668
{
1669+
if (!type)
1670+
return 0;
16261671
QualType QT = QualType::getFromOpaquePtr(type);
16271672
QT = QT->getCanonicalTypeUnqualified();
16281673

0 commit comments

Comments
 (0)