| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | #ifndef LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H |
| 14 | #define LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H |
| 15 | |
| 16 | #include "clang-c/Index.h" |
| 17 | #include "clang/AST/Type.h" |
| 18 | #include "clang/Basic/LLVM.h" |
| 19 | #include "clang/Lex/MacroInfo.h" |
| 20 | #include "clang/Sema/CodeCompleteOptions.h" |
| 21 | #include "clang/Sema/DeclSpec.h" |
| 22 | #include "llvm/ADT/ArrayRef.h" |
| 23 | #include "llvm/ADT/DenseMap.h" |
| 24 | #include "llvm/ADT/None.h" |
| 25 | #include "llvm/ADT/Optional.h" |
| 26 | #include "llvm/ADT/SmallPtrSet.h" |
| 27 | #include "llvm/ADT/SmallVector.h" |
| 28 | #include "llvm/ADT/StringRef.h" |
| 29 | #include "llvm/Support/Allocator.h" |
| 30 | #include "llvm/Support/type_traits.h" |
| 31 | #include <cassert> |
| 32 | #include <memory> |
| 33 | #include <string> |
| 34 | #include <utility> |
| 35 | |
| 36 | namespace clang { |
| 37 | |
| 38 | class ASTContext; |
| 39 | class Decl; |
| 40 | class DeclContext; |
| 41 | class FunctionDecl; |
| 42 | class FunctionTemplateDecl; |
| 43 | class IdentifierInfo; |
| 44 | class LangOptions; |
| 45 | class NamedDecl; |
| 46 | class NestedNameSpecifier; |
| 47 | class Preprocessor; |
| 48 | class ; |
| 49 | class Sema; |
| 50 | class UsingShadowDecl; |
| 51 | |
| 52 | |
| 53 | |
| 54 | enum { |
| 55 | |
| 56 | |
| 57 | CCP_NextInitializer = 7, |
| 58 | |
| 59 | |
| 60 | |
| 61 | CCP_EnumInCase = 7, |
| 62 | |
| 63 | |
| 64 | CCP_SuperCompletion = 20, |
| 65 | |
| 66 | |
| 67 | CCP_LocalDeclaration = 34, |
| 68 | |
| 69 | |
| 70 | |
| 71 | CCP_MemberDeclaration = 35, |
| 72 | |
| 73 | |
| 74 | |
| 75 | CCP_Keyword = 40, |
| 76 | |
| 77 | |
| 78 | CCP_CodePattern = 40, |
| 79 | |
| 80 | |
| 81 | CCP_Declaration = 50, |
| 82 | |
| 83 | |
| 84 | CCP_Type = CCP_Declaration, |
| 85 | |
| 86 | |
| 87 | CCP_Constant = 65, |
| 88 | |
| 89 | |
| 90 | CCP_Macro = 70, |
| 91 | |
| 92 | |
| 93 | CCP_NestedNameSpecifier = 75, |
| 94 | |
| 95 | |
| 96 | |
| 97 | CCP_Unlikely = 80, |
| 98 | |
| 99 | |
| 100 | CCP_ObjC_cmd = CCP_Unlikely |
| 101 | }; |
| 102 | |
| 103 | |
| 104 | |
| 105 | enum { |
| 106 | |
| 107 | CCD_InBaseClass = 2, |
| 108 | |
| 109 | |
| 110 | |
| 111 | CCD_ObjectQualifierMatch = -1, |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | CCD_SelectorMatch = -3, |
| 117 | |
| 118 | |
| 119 | |
| 120 | CCD_bool_in_ObjC = 1, |
| 121 | |
| 122 | |
| 123 | |
| 124 | CCD_ProbablyNotObjCCollection = 15, |
| 125 | |
| 126 | |
| 127 | CCD_MethodAsProperty = 2, |
| 128 | |
| 129 | |
| 130 | |
| 131 | CCD_BlockPropertySetter = 3 |
| 132 | }; |
| 133 | |
| 134 | |
| 135 | |
| 136 | enum { |
| 137 | |
| 138 | |
| 139 | CCF_ExactTypeMatch = 4, |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | CCF_SimilarTypeMatch = 2 |
| 145 | }; |
| 146 | |
| 147 | |
| 148 | |
| 149 | enum SimplifiedTypeClass { |
| 150 | STC_Arithmetic, |
| 151 | STC_Array, |
| 152 | STC_Block, |
| 153 | STC_Function, |
| 154 | STC_ObjectiveC, |
| 155 | STC_Other, |
| 156 | STC_Pointer, |
| 157 | STC_Record, |
| 158 | STC_Void |
| 159 | }; |
| 160 | |
| 161 | |
| 162 | SimplifiedTypeClass getSimplifiedTypeClass(CanQualType T); |
| 163 | |
| 164 | |
| 165 | |
| 166 | QualType getDeclUsageType(ASTContext &C, const NamedDecl *ND); |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | unsigned getMacroUsagePriority(StringRef MacroName, |
| 178 | const LangOptions &LangOpts, |
| 179 | bool PreferredTypeIsPointer = false); |
| 180 | |
| 181 | |
| 182 | |
| 183 | CXCursorKind getCursorKindForDecl(const Decl *D); |
| 184 | |
| 185 | |
| 186 | |
| 187 | class CodeCompletionContext { |
| 188 | public: |
| 189 | enum Kind { |
| 190 | |
| 191 | CCC_Other, |
| 192 | |
| 193 | |
| 194 | |
| 195 | CCC_OtherWithMacros, |
| 196 | |
| 197 | |
| 198 | |
| 199 | CCC_TopLevel, |
| 200 | |
| 201 | |
| 202 | |
| 203 | CCC_ObjCInterface, |
| 204 | |
| 205 | |
| 206 | |
| 207 | CCC_ObjCImplementation, |
| 208 | |
| 209 | |
| 210 | |
| 211 | CCC_ObjCIvarList, |
| 212 | |
| 213 | |
| 214 | CCC_ClassStructUnion, |
| 215 | |
| 216 | |
| 217 | |
| 218 | CCC_Statement, |
| 219 | |
| 220 | |
| 221 | CCC_Expression, |
| 222 | |
| 223 | |
| 224 | |
| 225 | CCC_ObjCMessageReceiver, |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | CCC_DotMemberAccess, |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | CCC_ArrowMemberAccess, |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | CCC_ObjCPropertyAccess, |
| 250 | |
| 251 | |
| 252 | |
| 253 | CCC_EnumTag, |
| 254 | |
| 255 | |
| 256 | |
| 257 | CCC_UnionTag, |
| 258 | |
| 259 | |
| 260 | |
| 261 | CCC_ClassOrStructTag, |
| 262 | |
| 263 | |
| 264 | CCC_ObjCProtocolName, |
| 265 | |
| 266 | |
| 267 | |
| 268 | CCC_Namespace, |
| 269 | |
| 270 | |
| 271 | CCC_Type, |
| 272 | |
| 273 | |
| 274 | CCC_NewName, |
| 275 | |
| 276 | |
| 277 | |
| 278 | CCC_SymbolOrNewName, |
| 279 | |
| 280 | |
| 281 | |
| 282 | CCC_Symbol, |
| 283 | |
| 284 | |
| 285 | CCC_MacroName, |
| 286 | |
| 287 | |
| 288 | |
| 289 | CCC_MacroNameUse, |
| 290 | |
| 291 | |
| 292 | CCC_PreprocessorExpression, |
| 293 | |
| 294 | |
| 295 | |
| 296 | CCC_PreprocessorDirective, |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | CCC_NaturalLanguage, |
| 304 | |
| 305 | |
| 306 | CCC_SelectorName, |
| 307 | |
| 308 | |
| 309 | CCC_TypeQualifiers, |
| 310 | |
| 311 | |
| 312 | |
| 313 | CCC_ParenthesizedExpression, |
| 314 | |
| 315 | |
| 316 | |
| 317 | CCC_ObjCInstanceMessage, |
| 318 | |
| 319 | |
| 320 | CCC_ObjCClassMessage, |
| 321 | |
| 322 | |
| 323 | |
| 324 | CCC_ObjCInterfaceName, |
| 325 | |
| 326 | |
| 327 | CCC_ObjCCategoryName, |
| 328 | |
| 329 | |
| 330 | CCC_IncludedFile, |
| 331 | |
| 332 | |
| 333 | |
| 334 | CCC_Recovery |
| 335 | }; |
| 336 | |
| 337 | using VisitedContextSet = llvm::SmallPtrSet<DeclContext *, 8>; |
| 338 | |
| 339 | private: |
| 340 | Kind CCKind; |
| 341 | |
| 342 | |
| 343 | |
| 344 | QualType PreferredType; |
| 345 | |
| 346 | |
| 347 | QualType BaseType; |
| 348 | |
| 349 | |
| 350 | ArrayRef<IdentifierInfo *> SelIdents; |
| 351 | |
| 352 | |
| 353 | |
| 354 | llvm::Optional<CXXScopeSpec> ScopeSpecifier; |
| 355 | |
| 356 | |
| 357 | |
| 358 | VisitedContextSet VisitedContexts; |
| 359 | |
| 360 | public: |
| 361 | |
| 362 | CodeCompletionContext(Kind CCKind) : CCKind(CCKind), SelIdents(None) {} |
| 363 | |
| 364 | |
| 365 | CodeCompletionContext(Kind CCKind, QualType T, |
| 366 | ArrayRef<IdentifierInfo *> SelIdents = None) |
| 367 | : CCKind(CCKind), SelIdents(SelIdents) { |
| 368 | if (CCKind == CCC_DotMemberAccess || CCKind == CCC_ArrowMemberAccess || |
| 369 | CCKind == CCC_ObjCPropertyAccess || CCKind == CCC_ObjCClassMessage || |
| 370 | CCKind == CCC_ObjCInstanceMessage) |
| 371 | BaseType = T; |
| 372 | else |
| 373 | PreferredType = T; |
| 374 | } |
| 375 | |
| 376 | |
| 377 | Kind getKind() const { return CCKind; } |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | QualType getPreferredType() const { return PreferredType; } |
| 383 | void setPreferredType(QualType T) { PreferredType = T; } |
| 384 | |
| 385 | |
| 386 | |
| 387 | QualType getBaseType() const { return BaseType; } |
| 388 | |
| 389 | |
| 390 | ArrayRef<IdentifierInfo *> getSelIdents() const { return SelIdents; } |
| 391 | |
| 392 | |
| 393 | |
| 394 | bool wantConstructorResults() const; |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | void setCXXScopeSpecifier(CXXScopeSpec SS) { |
| 400 | this->ScopeSpecifier = std::move(SS); |
| 401 | } |
| 402 | |
| 403 | |
| 404 | void addVisitedContext(DeclContext *Ctx) { |
| 405 | VisitedContexts.insert(Ctx); |
| 406 | } |
| 407 | |
| 408 | |
| 409 | const VisitedContextSet &getVisitedContexts() const { |
| 410 | return VisitedContexts; |
| 411 | } |
| 412 | |
| 413 | llvm::Optional<const CXXScopeSpec *> getCXXScopeSpecifier() { |
| 414 | if (ScopeSpecifier) |
| 415 | return ScopeSpecifier.getPointer(); |
| 416 | return llvm::None; |
| 417 | } |
| 418 | }; |
| 419 | |
| 420 | |
| 421 | llvm::StringRef getCompletionKindString(CodeCompletionContext::Kind Kind); |
| 422 | |
| 423 | |
| 424 | |
| 425 | |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 | class CodeCompletionString { |
| 431 | public: |
| 432 | |
| 433 | |
| 434 | enum ChunkKind { |
| 435 | |
| 436 | |
| 437 | |
| 438 | CK_TypedText, |
| 439 | |
| 440 | |
| 441 | |
| 442 | CK_Text, |
| 443 | |
| 444 | |
| 445 | |
| 446 | |
| 447 | CK_Optional, |
| 448 | |
| 449 | |
| 450 | |
| 451 | CK_Placeholder, |
| 452 | |
| 453 | |
| 454 | |
| 455 | CK_Informative, |
| 456 | |
| 457 | |
| 458 | CK_ResultType, |
| 459 | |
| 460 | |
| 461 | |
| 462 | |
| 463 | CK_CurrentParameter, |
| 464 | |
| 465 | |
| 466 | CK_LeftParen, |
| 467 | |
| 468 | |
| 469 | CK_RightParen, |
| 470 | |
| 471 | |
| 472 | CK_LeftBracket, |
| 473 | |
| 474 | |
| 475 | CK_RightBracket, |
| 476 | |
| 477 | |
| 478 | CK_LeftBrace, |
| 479 | |
| 480 | |
| 481 | CK_RightBrace, |
| 482 | |
| 483 | |
| 484 | CK_LeftAngle, |
| 485 | |
| 486 | |
| 487 | CK_RightAngle, |
| 488 | |
| 489 | |
| 490 | CK_Comma, |
| 491 | |
| 492 | |
| 493 | CK_Colon, |
| 494 | |
| 495 | |
| 496 | CK_SemiColon, |
| 497 | |
| 498 | |
| 499 | CK_Equal, |
| 500 | |
| 501 | |
| 502 | CK_HorizontalSpace, |
| 503 | |
| 504 | |
| 505 | |
| 506 | CK_VerticalSpace |
| 507 | }; |
| 508 | |
| 509 | |
| 510 | struct Chunk { |
| 511 | |
| 512 | |
| 513 | ChunkKind Kind = CK_Text; |
| 514 | |
| 515 | union { |
| 516 | |
| 517 | |
| 518 | |
| 519 | |
| 520 | const char *Text; |
| 521 | |
| 522 | |
| 523 | |
| 524 | |
| 525 | CodeCompletionString *Optional; |
| 526 | }; |
| 527 | |
| 528 | Chunk() : Text(nullptr) {} |
| 529 | |
| 530 | explicit Chunk(ChunkKind Kind, const char *Text = ""); |
| 531 | |
| 532 | |
| 533 | static Chunk CreateText(const char *Text); |
| 534 | |
| 535 | |
| 536 | static Chunk CreateOptional(CodeCompletionString *Optional); |
| 537 | |
| 538 | |
| 539 | static Chunk CreatePlaceholder(const char *Placeholder); |
| 540 | |
| 541 | |
| 542 | static Chunk CreateInformative(const char *Informative); |
| 543 | |
| 544 | |
| 545 | static Chunk CreateResultType(const char *ResultType); |
| 546 | |
| 547 | |
| 548 | static Chunk CreateCurrentParameter(const char *CurrentParameter); |
| 549 | }; |
| 550 | |
| 551 | private: |
| 552 | friend class CodeCompletionBuilder; |
| 553 | friend class CodeCompletionResult; |
| 554 | |
| 555 | |
| 556 | unsigned NumChunks : 16; |
| 557 | |
| 558 | |
| 559 | unsigned NumAnnotations : 16; |
| 560 | |
| 561 | |
| 562 | unsigned Priority : 16; |
| 563 | |
| 564 | |
| 565 | unsigned Availability : 2; |
| 566 | |
| 567 | |
| 568 | StringRef ParentName; |
| 569 | |
| 570 | |
| 571 | |
| 572 | const char *; |
| 573 | |
| 574 | CodeCompletionString(const Chunk *Chunks, unsigned NumChunks, |
| 575 | unsigned Priority, CXAvailabilityKind Availability, |
| 576 | const char **Annotations, unsigned NumAnnotations, |
| 577 | StringRef ParentName, |
| 578 | const char *); |
| 579 | ~CodeCompletionString() = default; |
| 580 | |
| 581 | public: |
| 582 | CodeCompletionString(const CodeCompletionString &) = delete; |
| 583 | CodeCompletionString &operator=(const CodeCompletionString &) = delete; |
| 584 | |
| 585 | using iterator = const Chunk *; |
| 586 | |
| 587 | iterator begin() const { return reinterpret_cast<const Chunk *>(this + 1); } |
| 588 | iterator end() const { return begin() + NumChunks; } |
| 589 | bool empty() const { return NumChunks == 0; } |
| 590 | unsigned size() const { return NumChunks; } |
| 591 | |
| 592 | const Chunk &operator[](unsigned I) const { |
| 593 | (0) . __assert_fail ("I < size() && \"Chunk index out-of-range\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/CodeCompleteConsumer.h", 593, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(I < size() && "Chunk index out-of-range"); |
| 594 | return begin()[I]; |
| 595 | } |
| 596 | |
| 597 | |
| 598 | const char *getTypedText() const; |
| 599 | |
| 600 | |
| 601 | unsigned getPriority() const { return Priority; } |
| 602 | |
| 603 | |
| 604 | unsigned getAvailability() const { return Availability; } |
| 605 | |
| 606 | |
| 607 | unsigned getAnnotationCount() const; |
| 608 | |
| 609 | |
| 610 | const char *getAnnotation(unsigned AnnotationNr) const; |
| 611 | |
| 612 | |
| 613 | StringRef getParentContextName() const { |
| 614 | return ParentName; |
| 615 | } |
| 616 | |
| 617 | const char *() const { |
| 618 | return BriefComment; |
| 619 | } |
| 620 | |
| 621 | |
| 622 | |
| 623 | std::string getAsString() const; |
| 624 | }; |
| 625 | |
| 626 | |
| 627 | class CodeCompletionAllocator : public llvm::BumpPtrAllocator { |
| 628 | public: |
| 629 | |
| 630 | const char *CopyString(const Twine &String); |
| 631 | }; |
| 632 | |
| 633 | |
| 634 | class GlobalCodeCompletionAllocator : public CodeCompletionAllocator {}; |
| 635 | |
| 636 | class CodeCompletionTUInfo { |
| 637 | llvm::DenseMap<const DeclContext *, StringRef> ParentNames; |
| 638 | std::shared_ptr<GlobalCodeCompletionAllocator> AllocatorRef; |
| 639 | |
| 640 | public: |
| 641 | explicit CodeCompletionTUInfo( |
| 642 | std::shared_ptr<GlobalCodeCompletionAllocator> Allocator) |
| 643 | : AllocatorRef(std::move(Allocator)) {} |
| 644 | |
| 645 | std::shared_ptr<GlobalCodeCompletionAllocator> getAllocatorRef() const { |
| 646 | return AllocatorRef; |
| 647 | } |
| 648 | |
| 649 | CodeCompletionAllocator &getAllocator() const { |
| 650 | assert(AllocatorRef); |
| 651 | return *AllocatorRef; |
| 652 | } |
| 653 | |
| 654 | StringRef getParentName(const DeclContext *DC); |
| 655 | }; |
| 656 | |
| 657 | } |
| 658 | |
| 659 | namespace clang { |
| 660 | |
| 661 | |
| 662 | class CodeCompletionBuilder { |
| 663 | public: |
| 664 | using Chunk = CodeCompletionString::Chunk; |
| 665 | |
| 666 | private: |
| 667 | CodeCompletionAllocator &Allocator; |
| 668 | CodeCompletionTUInfo &CCTUInfo; |
| 669 | unsigned Priority = 0; |
| 670 | CXAvailabilityKind Availability = CXAvailability_Available; |
| 671 | StringRef ParentName; |
| 672 | const char * = nullptr; |
| 673 | |
| 674 | |
| 675 | SmallVector<Chunk, 4> Chunks; |
| 676 | |
| 677 | SmallVector<const char *, 2> Annotations; |
| 678 | |
| 679 | public: |
| 680 | CodeCompletionBuilder(CodeCompletionAllocator &Allocator, |
| 681 | CodeCompletionTUInfo &CCTUInfo) |
| 682 | : Allocator(Allocator), CCTUInfo(CCTUInfo) {} |
| 683 | |
| 684 | CodeCompletionBuilder(CodeCompletionAllocator &Allocator, |
| 685 | CodeCompletionTUInfo &CCTUInfo, |
| 686 | unsigned Priority, CXAvailabilityKind Availability) |
| 687 | : Allocator(Allocator), CCTUInfo(CCTUInfo), Priority(Priority), |
| 688 | Availability(Availability) {} |
| 689 | |
| 690 | |
| 691 | |
| 692 | CodeCompletionAllocator &getAllocator() const { return Allocator; } |
| 693 | |
| 694 | CodeCompletionTUInfo &getCodeCompletionTUInfo() const { return CCTUInfo; } |
| 695 | |
| 696 | |
| 697 | |
| 698 | |
| 699 | CodeCompletionString *TakeString(); |
| 700 | |
| 701 | |
| 702 | void AddTypedTextChunk(const char *Text); |
| 703 | |
| 704 | |
| 705 | void AddTextChunk(const char *Text); |
| 706 | |
| 707 | |
| 708 | void AddOptionalChunk(CodeCompletionString *Optional); |
| 709 | |
| 710 | |
| 711 | void AddPlaceholderChunk(const char *Placeholder); |
| 712 | |
| 713 | |
| 714 | void AddInformativeChunk(const char *Text); |
| 715 | |
| 716 | |
| 717 | void AddResultTypeChunk(const char *ResultType); |
| 718 | |
| 719 | |
| 720 | void AddCurrentParameterChunk(const char *CurrentParameter); |
| 721 | |
| 722 | |
| 723 | void AddChunk(CodeCompletionString::ChunkKind CK, const char *Text = ""); |
| 724 | |
| 725 | void AddAnnotation(const char *A) { Annotations.push_back(A); } |
| 726 | |
| 727 | |
| 728 | void addParentContext(const DeclContext *DC); |
| 729 | |
| 730 | const char *() const { return BriefComment; } |
| 731 | void (StringRef ); |
| 732 | |
| 733 | StringRef getParentName() const { return ParentName; } |
| 734 | }; |
| 735 | |
| 736 | |
| 737 | class CodeCompletionResult { |
| 738 | public: |
| 739 | |
| 740 | enum ResultKind { |
| 741 | |
| 742 | RK_Declaration = 0, |
| 743 | |
| 744 | |
| 745 | RK_Keyword, |
| 746 | |
| 747 | |
| 748 | RK_Macro, |
| 749 | |
| 750 | |
| 751 | RK_Pattern |
| 752 | }; |
| 753 | |
| 754 | |
| 755 | |
| 756 | const NamedDecl *Declaration = nullptr; |
| 757 | |
| 758 | union { |
| 759 | |
| 760 | |
| 761 | const char *Keyword; |
| 762 | |
| 763 | |
| 764 | |
| 765 | CodeCompletionString *Pattern; |
| 766 | |
| 767 | |
| 768 | const IdentifierInfo *Macro; |
| 769 | }; |
| 770 | |
| 771 | |
| 772 | unsigned Priority; |
| 773 | |
| 774 | |
| 775 | |
| 776 | unsigned StartParameter = 0; |
| 777 | |
| 778 | |
| 779 | ResultKind Kind; |
| 780 | |
| 781 | |
| 782 | CXCursorKind CursorKind; |
| 783 | |
| 784 | |
| 785 | CXAvailabilityKind Availability = CXAvailability_Available; |
| 786 | |
| 787 | |
| 788 | |
| 789 | |
| 790 | |
| 791 | |
| 792 | |
| 793 | |
| 794 | |
| 795 | |
| 796 | |
| 797 | |
| 798 | |
| 799 | |
| 800 | |
| 801 | |
| 802 | |
| 803 | |
| 804 | |
| 805 | |
| 806 | |
| 807 | |
| 808 | |
| 809 | |
| 810 | |
| 811 | |
| 812 | |
| 813 | |
| 814 | |
| 815 | std::vector<FixItHint> FixIts; |
| 816 | |
| 817 | |
| 818 | bool Hidden : 1; |
| 819 | |
| 820 | |
| 821 | bool InBaseClass : 1; |
| 822 | |
| 823 | |
| 824 | bool QualifierIsInformative : 1; |
| 825 | |
| 826 | |
| 827 | |
| 828 | bool StartsNestedNameSpecifier : 1; |
| 829 | |
| 830 | |
| 831 | |
| 832 | bool AllParametersAreInformative : 1; |
| 833 | |
| 834 | |
| 835 | |
| 836 | bool DeclaringEntity : 1; |
| 837 | |
| 838 | |
| 839 | |
| 840 | |
| 841 | NestedNameSpecifier *Qualifier = nullptr; |
| 842 | |
| 843 | |
| 844 | |
| 845 | |
| 846 | |
| 847 | const UsingShadowDecl *ShadowDecl = nullptr; |
| 848 | |
| 849 | |
| 850 | |
| 851 | |
| 852 | const MacroInfo *MacroDefInfo = nullptr; |
| 853 | |
| 854 | |
| 855 | CodeCompletionResult(const NamedDecl *Declaration, unsigned Priority, |
| 856 | NestedNameSpecifier *Qualifier = nullptr, |
| 857 | bool QualifierIsInformative = false, |
| 858 | bool Accessible = true, |
| 859 | std::vector<FixItHint> FixIts = std::vector<FixItHint>()) |
| 860 | : Declaration(Declaration), Priority(Priority), Kind(RK_Declaration), |
| 861 | FixIts(std::move(FixIts)), Hidden(false), InBaseClass(false), |
| 862 | QualifierIsInformative(QualifierIsInformative), |
| 863 | StartsNestedNameSpecifier(false), AllParametersAreInformative(false), |
| 864 | DeclaringEntity(false), Qualifier(Qualifier) { |
| 865 | |
| 866 | computeCursorKindAndAvailability(Accessible); |
| 867 | } |
| 868 | |
| 869 | |
| 870 | CodeCompletionResult(const char *Keyword, unsigned Priority = CCP_Keyword) |
| 871 | : Keyword(Keyword), Priority(Priority), Kind(RK_Keyword), |
| 872 | CursorKind(CXCursor_NotImplemented), Hidden(false), InBaseClass(false), |
| 873 | QualifierIsInformative(false), StartsNestedNameSpecifier(false), |
| 874 | AllParametersAreInformative(false), DeclaringEntity(false) {} |
| 875 | |
| 876 | |
| 877 | CodeCompletionResult(const IdentifierInfo *Macro, |
| 878 | const MacroInfo *MI = nullptr, |
| 879 | unsigned Priority = CCP_Macro) |
| 880 | : Macro(Macro), Priority(Priority), Kind(RK_Macro), |
| 881 | CursorKind(CXCursor_MacroDefinition), Hidden(false), InBaseClass(false), |
| 882 | QualifierIsInformative(false), StartsNestedNameSpecifier(false), |
| 883 | AllParametersAreInformative(false), DeclaringEntity(false), |
| 884 | MacroDefInfo(MI) {} |
| 885 | |
| 886 | |
| 887 | CodeCompletionResult( |
| 888 | CodeCompletionString *Pattern, unsigned Priority = CCP_CodePattern, |
| 889 | CXCursorKind CursorKind = CXCursor_NotImplemented, |
| 890 | CXAvailabilityKind Availability = CXAvailability_Available, |
| 891 | const NamedDecl *D = nullptr) |
| 892 | : Declaration(D), Pattern(Pattern), Priority(Priority), Kind(RK_Pattern), |
| 893 | CursorKind(CursorKind), Availability(Availability), Hidden(false), |
| 894 | InBaseClass(false), QualifierIsInformative(false), |
| 895 | StartsNestedNameSpecifier(false), AllParametersAreInformative(false), |
| 896 | DeclaringEntity(false) {} |
| 897 | |
| 898 | |
| 899 | |
| 900 | CodeCompletionResult(CodeCompletionString *Pattern, const NamedDecl *D, |
| 901 | unsigned Priority) |
| 902 | : Declaration(D), Pattern(Pattern), Priority(Priority), Kind(RK_Pattern), |
| 903 | Hidden(false), InBaseClass(false), QualifierIsInformative(false), |
| 904 | StartsNestedNameSpecifier(false), AllParametersAreInformative(false), |
| 905 | DeclaringEntity(false) { |
| 906 | computeCursorKindAndAvailability(); |
| 907 | } |
| 908 | |
| 909 | |
| 910 | |
| 911 | const NamedDecl *getDeclaration() const { |
| 912 | (0) . __assert_fail ("((Kind == RK_Declaration) || (Kind == RK_Pattern)) && \"Not a declaration or pattern result\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/CodeCompleteConsumer.h", 913, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(((Kind == RK_Declaration) || (Kind == RK_Pattern)) && |
| 913 | (0) . __assert_fail ("((Kind == RK_Declaration) || (Kind == RK_Pattern)) && \"Not a declaration or pattern result\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/CodeCompleteConsumer.h", 913, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Not a declaration or pattern result"); |
| 914 | return Declaration; |
| 915 | } |
| 916 | |
| 917 | |
| 918 | const char *getKeyword() const { |
| 919 | (0) . __assert_fail ("Kind == RK_Keyword && \"Not a keyword result\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/CodeCompleteConsumer.h", 919, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Kind == RK_Keyword && "Not a keyword result"); |
| 920 | return Keyword; |
| 921 | } |
| 922 | |
| 923 | |
| 924 | |
| 925 | |
| 926 | |
| 927 | |
| 928 | |
| 929 | |
| 930 | CodeCompletionString *CreateCodeCompletionString(Sema &S, |
| 931 | const CodeCompletionContext &CCContext, |
| 932 | CodeCompletionAllocator &Allocator, |
| 933 | CodeCompletionTUInfo &CCTUInfo, |
| 934 | bool ); |
| 935 | CodeCompletionString *CreateCodeCompletionString(ASTContext &Ctx, |
| 936 | Preprocessor &PP, |
| 937 | const CodeCompletionContext &CCContext, |
| 938 | CodeCompletionAllocator &Allocator, |
| 939 | CodeCompletionTUInfo &CCTUInfo, |
| 940 | bool ); |
| 941 | |
| 942 | |
| 943 | |
| 944 | CodeCompletionString * |
| 945 | CreateCodeCompletionStringForMacro(Preprocessor &PP, |
| 946 | CodeCompletionAllocator &Allocator, |
| 947 | CodeCompletionTUInfo &CCTUInfo); |
| 948 | |
| 949 | CodeCompletionString *createCodeCompletionStringForDecl( |
| 950 | Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result, |
| 951 | bool , const CodeCompletionContext &CCContext, |
| 952 | PrintingPolicy &Policy); |
| 953 | |
| 954 | CodeCompletionString *createCodeCompletionStringForOverride( |
| 955 | Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result, |
| 956 | bool , const CodeCompletionContext &CCContext, |
| 957 | PrintingPolicy &Policy); |
| 958 | |
| 959 | |
| 960 | |
| 961 | |
| 962 | |
| 963 | StringRef getOrderedName(std::string &Saved) const; |
| 964 | |
| 965 | private: |
| 966 | void computeCursorKindAndAvailability(bool Accessible = true); |
| 967 | }; |
| 968 | |
| 969 | bool operator<(const CodeCompletionResult &X, const CodeCompletionResult &Y); |
| 970 | |
| 971 | inline bool operator>(const CodeCompletionResult &X, |
| 972 | const CodeCompletionResult &Y) { |
| 973 | return Y < X; |
| 974 | } |
| 975 | |
| 976 | inline bool operator<=(const CodeCompletionResult &X, |
| 977 | const CodeCompletionResult &Y) { |
| 978 | return !(Y < X); |
| 979 | } |
| 980 | |
| 981 | inline bool operator>=(const CodeCompletionResult &X, |
| 982 | const CodeCompletionResult &Y) { |
| 983 | return !(X < Y); |
| 984 | } |
| 985 | |
| 986 | raw_ostream &operator<<(raw_ostream &OS, |
| 987 | const CodeCompletionString &CCS); |
| 988 | |
| 989 | |
| 990 | |
| 991 | class CodeCompleteConsumer { |
| 992 | protected: |
| 993 | const CodeCompleteOptions CodeCompleteOpts; |
| 994 | |
| 995 | |
| 996 | |
| 997 | bool OutputIsBinary; |
| 998 | |
| 999 | public: |
| 1000 | class OverloadCandidate { |
| 1001 | public: |
| 1002 | |
| 1003 | enum CandidateKind { |
| 1004 | |
| 1005 | CK_Function, |
| 1006 | |
| 1007 | |
| 1008 | CK_FunctionTemplate, |
| 1009 | |
| 1010 | |
| 1011 | |
| 1012 | CK_FunctionType |
| 1013 | }; |
| 1014 | |
| 1015 | private: |
| 1016 | |
| 1017 | CandidateKind Kind; |
| 1018 | |
| 1019 | union { |
| 1020 | |
| 1021 | |
| 1022 | FunctionDecl *Function; |
| 1023 | |
| 1024 | |
| 1025 | |
| 1026 | FunctionTemplateDecl *FunctionTemplate; |
| 1027 | |
| 1028 | |
| 1029 | |
| 1030 | const FunctionType *Type; |
| 1031 | }; |
| 1032 | |
| 1033 | public: |
| 1034 | OverloadCandidate(FunctionDecl *Function) |
| 1035 | : Kind(CK_Function), Function(Function) {} |
| 1036 | |
| 1037 | OverloadCandidate(FunctionTemplateDecl *FunctionTemplateDecl) |
| 1038 | : Kind(CK_FunctionTemplate), FunctionTemplate(FunctionTemplateDecl) {} |
| 1039 | |
| 1040 | OverloadCandidate(const FunctionType *Type) |
| 1041 | : Kind(CK_FunctionType), Type(Type) {} |
| 1042 | |
| 1043 | |
| 1044 | CandidateKind getKind() const { return Kind; } |
| 1045 | |
| 1046 | |
| 1047 | |
| 1048 | FunctionDecl *getFunction() const; |
| 1049 | |
| 1050 | |
| 1051 | FunctionTemplateDecl *getFunctionTemplate() const { |
| 1052 | (0) . __assert_fail ("getKind() == CK_FunctionTemplate && \"Not a function template\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/CodeCompleteConsumer.h", 1052, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getKind() == CK_FunctionTemplate && "Not a function template"); |
| 1053 | return FunctionTemplate; |
| 1054 | } |
| 1055 | |
| 1056 | |
| 1057 | |
| 1058 | const FunctionType *getFunctionType() const; |
| 1059 | |
| 1060 | |
| 1061 | |
| 1062 | CodeCompletionString *CreateSignatureString(unsigned CurrentArg, |
| 1063 | Sema &S, |
| 1064 | CodeCompletionAllocator &Allocator, |
| 1065 | CodeCompletionTUInfo &CCTUInfo, |
| 1066 | bool ) const; |
| 1067 | }; |
| 1068 | |
| 1069 | CodeCompleteConsumer(const CodeCompleteOptions &CodeCompleteOpts, |
| 1070 | bool OutputIsBinary) |
| 1071 | : CodeCompleteOpts(CodeCompleteOpts), OutputIsBinary(OutputIsBinary) {} |
| 1072 | |
| 1073 | |
| 1074 | bool includeMacros() const { |
| 1075 | return CodeCompleteOpts.IncludeMacros; |
| 1076 | } |
| 1077 | |
| 1078 | |
| 1079 | bool includeCodePatterns() const { |
| 1080 | return CodeCompleteOpts.IncludeCodePatterns; |
| 1081 | } |
| 1082 | |
| 1083 | |
| 1084 | bool includeGlobals() const { return CodeCompleteOpts.IncludeGlobals; } |
| 1085 | |
| 1086 | |
| 1087 | |
| 1088 | |
| 1089 | bool includeNamespaceLevelDecls() const { |
| 1090 | return CodeCompleteOpts.IncludeNamespaceLevelDecls; |
| 1091 | } |
| 1092 | |
| 1093 | |
| 1094 | |
| 1095 | bool () const { |
| 1096 | return CodeCompleteOpts.IncludeBriefComments; |
| 1097 | } |
| 1098 | |
| 1099 | |
| 1100 | |
| 1101 | bool includeFixIts() const { return CodeCompleteOpts.IncludeFixIts; } |
| 1102 | |
| 1103 | |
| 1104 | |
| 1105 | bool loadExternal() const { |
| 1106 | return CodeCompleteOpts.LoadExternal; |
| 1107 | } |
| 1108 | |
| 1109 | |
| 1110 | bool isOutputBinary() const { return OutputIsBinary; } |
| 1111 | |
| 1112 | |
| 1113 | virtual ~CodeCompleteConsumer(); |
| 1114 | |
| 1115 | |
| 1116 | |
| 1117 | virtual bool isResultFilteredOut(StringRef Filter, |
| 1118 | CodeCompletionResult Results) { |
| 1119 | return false; |
| 1120 | } |
| 1121 | |
| 1122 | |
| 1123 | |
| 1124 | |
| 1125 | virtual void ProcessCodeCompleteResults(Sema &S, |
| 1126 | CodeCompletionContext Context, |
| 1127 | CodeCompletionResult *Results, |
| 1128 | unsigned NumResults) {} |
| 1129 | |
| 1130 | |
| 1131 | |
| 1132 | |
| 1133 | |
| 1134 | |
| 1135 | |
| 1136 | |
| 1137 | |
| 1138 | |
| 1139 | |
| 1140 | |
| 1141 | virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, |
| 1142 | OverloadCandidate *Candidates, |
| 1143 | unsigned NumCandidates, |
| 1144 | SourceLocation OpenParLoc) {} |
| 1145 | |
| 1146 | |
| 1147 | |
| 1148 | |
| 1149 | virtual CodeCompletionAllocator &getAllocator() = 0; |
| 1150 | |
| 1151 | virtual CodeCompletionTUInfo &getCodeCompletionTUInfo() = 0; |
| 1152 | }; |
| 1153 | |
| 1154 | |
| 1155 | |
| 1156 | const RawComment *(const ASTContext &Ctx, |
| 1157 | const NamedDecl *Decl); |
| 1158 | |
| 1159 | |
| 1160 | |
| 1161 | const RawComment *(const ASTContext &Ctx, |
| 1162 | const NamedDecl *Decl); |
| 1163 | |
| 1164 | |
| 1165 | |
| 1166 | const RawComment * |
| 1167 | getParameterComment(const ASTContext &Ctx, |
| 1168 | const CodeCompleteConsumer::OverloadCandidate &Result, |
| 1169 | unsigned ArgIndex); |
| 1170 | |
| 1171 | |
| 1172 | |
| 1173 | class PrintingCodeCompleteConsumer : public CodeCompleteConsumer { |
| 1174 | |
| 1175 | raw_ostream &OS; |
| 1176 | |
| 1177 | CodeCompletionTUInfo CCTUInfo; |
| 1178 | |
| 1179 | public: |
| 1180 | |
| 1181 | |
| 1182 | PrintingCodeCompleteConsumer(const CodeCompleteOptions &CodeCompleteOpts, |
| 1183 | raw_ostream &OS) |
| 1184 | : CodeCompleteConsumer(CodeCompleteOpts, false), OS(OS), |
| 1185 | CCTUInfo(std::make_shared<GlobalCodeCompletionAllocator>()) {} |
| 1186 | |
| 1187 | |
| 1188 | void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context, |
| 1189 | CodeCompletionResult *Results, |
| 1190 | unsigned NumResults) override; |
| 1191 | |
| 1192 | void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, |
| 1193 | OverloadCandidate *Candidates, |
| 1194 | unsigned NumCandidates, |
| 1195 | SourceLocation OpenParLoc) override; |
| 1196 | |
| 1197 | bool isResultFilteredOut(StringRef Filter, CodeCompletionResult Results) override; |
| 1198 | |
| 1199 | CodeCompletionAllocator &getAllocator() override { |
| 1200 | return CCTUInfo.getAllocator(); |
| 1201 | } |
| 1202 | |
| 1203 | CodeCompletionTUInfo &getCodeCompletionTUInfo() override { return CCTUInfo; } |
| 1204 | }; |
| 1205 | |
| 1206 | } |
| 1207 | |
| 1208 | #endif |
| 1209 | |