* @return whether @p result is a builtin provided by KDevelop's automatically included GCC * compatibility header, which libclang does not recognize as a builtin. */
| 508 | * compatibility header, which libclang does not recognize as a builtin. |
| 509 | */ |
| 510 | bool isGccCompatibilityBuiltin(CXCompletionResult result) |
| 511 | { |
| 512 | // The "#pragma clang system_header" line in plugins/clang/duchain/gccCompatibility/additional_floating_types.h |
| 513 | // suppresses __KDevelopClangGccCompat Namespace and __float80 TypedefDecl completions, but not _FloatX TypedefDecl |
| 514 | // completions. That's because clang_codeCompleteAt() filters out identifiers declared in a system header that start |
| 515 | // with two underscores, but not an underscore followed by a capital letter, possibly due to a libclang bug. |
| 516 | // The included typedefs substitute for separate floating-point types provided by GCC. Thus they are similar to |
| 517 | // other builtin completions, such as int and double. For this reason, they are marked as builtins rather than |
| 518 | // simply removed. The missing __float80 builtin completion shouldn't be a problem in practice, so we keep the |
| 519 | // "#pragma clang system_header" line to make this function slightly simpler and more efficient. |
| 520 | |
| 521 | if (result.CursorKind != CXCursor_TypedefDecl || clang_getNumCompletionChunks(result.CompletionString) != 1 |
| 522 | || clang_getCompletionChunkKind(result.CompletionString, 0) != CXCompletionChunk_TypedText) { |
| 523 | return false; |
| 524 | } |
| 525 | |
| 526 | const ClangString clangString{clang_getCompletionChunkText(result.CompletionString, 0)}; |
| 527 | const auto text = clangString.c_str(); |
| 528 | const auto textSize = std::strlen(text); |
| 529 | |
| 530 | if (textSize != 8 && textSize != 9) { |
| 531 | return false; |
| 532 | } |
| 533 | |
| 534 | constexpr auto prefixSize = 6; |
| 535 | if (!std::equal(text, text + prefixSize, "_Float")) { |
| 536 | return false; |
| 537 | } |
| 538 | // TODO: explicitly capture [text, textSize] once building KDevelop with Visual Studio 2019 is no longer supported. |
| 539 | const auto suffixEquals = [=](const char* suffix) { |
| 540 | Q_ASSERT(std::strlen(suffix) == textSize - prefixSize); |
| 541 | return std::equal(text + prefixSize, text + textSize, suffix); |
| 542 | }; |
| 543 | if (textSize == 8) { |
| 544 | return suffixEquals("32") || suffixEquals("64"); |
| 545 | } else { |
| 546 | return suffixEquals("32x") || suffixEquals("64x") || suffixEquals("128"); |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | QString& elideStringRight(QString& str, int length) |
| 551 | { |
no test coverage detected