Add type info interfaces motivated by numba#534
Conversation
|
|
||
| TCppType_t GetUnqualifiedType(TCppType_t type) { | ||
| if (!type) | ||
| return 0; |
There was a problem hiding this comment.
warning: use nullptr [modernize-use-nullptr]
| return 0; | |
| return nullptr; |
| TCppType_t GetUnderlyingType(TCppType_t type) | ||
| { | ||
| if (!type) | ||
| return 0; |
There was a problem hiding this comment.
warning: use nullptr [modernize-use-nullptr]
| return 0; | |
| return nullptr; |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #534 +/- ##
==========================================
- Coverage 79.18% 79.08% -0.11%
==========================================
Files 9 9
Lines 3853 3882 +29
==========================================
+ Hits 3051 3070 +19
- Misses 802 812 +10
🚀 New features to boost your workflow:
|
|
We should add tests. |
|
Would love to have this. What's needed before we can merge? |
Hi! I have some unittests that I haven't pushed yet, and this PR should be ready to go. Will do in the next few hours once I have access to a laptop |
| CPPINTEROP_API bool IsPODType(TCppType_t type); | ||
|
|
||
| /// Checks if type has an integer representation | ||
| CPPINTEROP_API bool IsIntegerType(TCppType_t type); |
There was a problem hiding this comment.
Probably we should have an enum instead of many interfaces..
| return QT->hasSignedIntegerRepresentation(); | ||
| } | ||
|
|
||
| bool IsUnsignedIntegerType(TCppType_t type) { |
There was a problem hiding this comment.
warning: redundant boolean literal in conditional return statement [readability-simplify-boolean-expr]
lib/Interpreter/CppInterOp.cpp:1565:
- if (llvm::isa_and_nonnull<VarDecl>(D)) {
- return true;
- }
-
- return false;
+ return llvm::isa_and_nonnull<VarDecl>(D);| bool IsFloatingType(TCppType_t type) { | ||
| QualType QT = QualType::getFromOpaquePtr(type); | ||
| return QT->hasFloatingRepresentation(); | ||
| } |
There was a problem hiding this comment.
warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]
auto *D = (clang::Decl *) var;
^897cfb3 to
05eb59c
Compare
|
|
||
| /// Checks if type has an integer representation | ||
| CPPINTEROP_API bool IsIntegerType(TCppType_t type, | ||
| Signedness s = Signedness::kAny); |
There was a problem hiding this comment.
| Signedness s = Signedness::kAny); | |
| Signedness *s = nullptr); |
We should probably take that as an output argument because you can have an integer type that's of different signedness and is still an int type.
There was a problem hiding this comment.
Yes, what you describe will happen if the caller specifies signed or unsigned. I was of the opinion that if you call this by default (for kAny) it will return true if the qualtype has an integer representation which should cover the above scenario
There was a problem hiding this comment.
Yes, but if you don't know the underlying signedness you will get a false telling you that this is not an integral type. This assumes that you will call the function couple of times before you figure everything out. My proposal is to enable this in a single call.
There was a problem hiding this comment.
Done, I've opened a fresh PR instead since this was hard to rebase: #913
|
clang-tidy review says "All clean, LGTM! 👍" |
Adds tests for IsSameType, IsIntegerType, IsFloatingType, GetUnqualifiedType, IsVoidPointerType
|
clang-tidy review says "All clean, LGTM! 👍" |
|
Closing in favour of #913 |
IsSameTypeused for matching arg types between numba inferred signatures and CppOverloads in cppyy.IsIntegralandIsFloatingthat check if types have the respective representations. Used in the case of Numba where scoring based on reflection is required.will add tests