Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:59

0001 //===- CodeCompleteConsumer.h - Code Completion Interface -------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 //  This file defines the CodeCompleteConsumer class.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H
0014 #define LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H
0015 
0016 #include "clang-c/Index.h"
0017 #include "clang/AST/Type.h"
0018 #include "clang/Basic/LLVM.h"
0019 #include "clang/Lex/MacroInfo.h"
0020 #include "clang/Sema/CodeCompleteOptions.h"
0021 #include "clang/Sema/DeclSpec.h"
0022 #include "llvm/ADT/ArrayRef.h"
0023 #include "llvm/ADT/DenseMap.h"
0024 #include "llvm/ADT/SmallPtrSet.h"
0025 #include "llvm/ADT/SmallVector.h"
0026 #include "llvm/ADT/StringRef.h"
0027 #include "llvm/Support/Allocator.h"
0028 #include "llvm/Support/type_traits.h"
0029 #include <cassert>
0030 #include <memory>
0031 #include <optional>
0032 #include <string>
0033 #include <utility>
0034 
0035 namespace clang {
0036 
0037 class ASTContext;
0038 class Decl;
0039 class DeclContext;
0040 class FunctionDecl;
0041 class FunctionTemplateDecl;
0042 class IdentifierInfo;
0043 class LangOptions;
0044 class NamedDecl;
0045 class NestedNameSpecifier;
0046 class Preprocessor;
0047 class RawComment;
0048 class Sema;
0049 class UsingShadowDecl;
0050 
0051 /// Default priority values for code-completion results based
0052 /// on their kind.
0053 enum {
0054   /// Priority for the next initialization in a constructor initializer
0055   /// list.
0056   CCP_NextInitializer = 7,
0057 
0058   /// Priority for an enumeration constant inside a switch whose
0059   /// condition is of the enumeration type.
0060   CCP_EnumInCase = 7,
0061 
0062   /// Priority for a send-to-super completion.
0063   CCP_SuperCompletion = 20,
0064 
0065   /// Priority for a declaration that is in the local scope.
0066   CCP_LocalDeclaration = 34,
0067 
0068   /// Priority for a member declaration found from the current
0069   /// method or member function.
0070   CCP_MemberDeclaration = 35,
0071 
0072   /// Priority for a language keyword (that isn't any of the other
0073   /// categories).
0074   CCP_Keyword = 40,
0075 
0076   /// Priority for a code pattern.
0077   CCP_CodePattern = 40,
0078 
0079   /// Priority for a non-type declaration.
0080   CCP_Declaration = 50,
0081 
0082   /// Priority for a type.
0083   CCP_Type = CCP_Declaration,
0084 
0085   /// Priority for a constant value (e.g., enumerator).
0086   CCP_Constant = 65,
0087 
0088   /// Priority for a preprocessor macro.
0089   CCP_Macro = 70,
0090 
0091   /// Priority for a nested-name-specifier.
0092   CCP_NestedNameSpecifier = 75,
0093 
0094   /// Priority for a result that isn't likely to be what the user wants,
0095   /// but is included for completeness.
0096   CCP_Unlikely = 80,
0097 
0098   /// Priority for the Objective-C "_cmd" implicit parameter.
0099   CCP_ObjC_cmd = CCP_Unlikely
0100 };
0101 
0102 /// Priority value deltas that are added to code-completion results
0103 /// based on the context of the result.
0104 enum {
0105   /// The result is in a base class.
0106   CCD_InBaseClass = 2,
0107 
0108   /// The result is a C++ non-static member function whose qualifiers
0109   /// exactly match the object type on which the member function can be called.
0110   CCD_ObjectQualifierMatch = -1,
0111 
0112   /// The selector of the given message exactly matches the selector
0113   /// of the current method, which might imply that some kind of delegation
0114   /// is occurring.
0115   CCD_SelectorMatch = -3,
0116 
0117   /// Adjustment to the "bool" type in Objective-C, where the typedef
0118   /// "BOOL" is preferred.
0119   CCD_bool_in_ObjC = 1,
0120 
0121   /// Adjustment for KVC code pattern priorities when it doesn't look
0122   /// like the
0123   CCD_ProbablyNotObjCCollection = 15,
0124 
0125   /// An Objective-C method being used as a property.
0126   CCD_MethodAsProperty = 2,
0127 
0128   /// An Objective-C block property completed as a setter with a
0129   /// block placeholder.
0130   CCD_BlockPropertySetter = 3
0131 };
0132 
0133 /// Priority value factors by which we will divide or multiply the
0134 /// priority of a code-completion result.
0135 enum {
0136   /// Divide by this factor when a code-completion result's type exactly
0137   /// matches the type we expect.
0138   CCF_ExactTypeMatch = 4,
0139 
0140   /// Divide by this factor when a code-completion result's type is
0141   /// similar to the type we expect (e.g., both arithmetic types, both
0142   /// Objective-C object pointer types).
0143   CCF_SimilarTypeMatch = 2
0144 };
0145 
0146 /// A simplified classification of types used when determining
0147 /// "similar" types for code completion.
0148 enum SimplifiedTypeClass {
0149   STC_Arithmetic,
0150   STC_Array,
0151   STC_Block,
0152   STC_Function,
0153   STC_ObjectiveC,
0154   STC_Other,
0155   STC_Pointer,
0156   STC_Record,
0157   STC_Void
0158 };
0159 
0160 /// Determine the simplified type class of the given canonical type.
0161 SimplifiedTypeClass getSimplifiedTypeClass(CanQualType T);
0162 
0163 /// Determine the type that this declaration will have if it is used
0164 /// as a type or in an expression.
0165 QualType getDeclUsageType(ASTContext &C, const NamedDecl *ND);
0166 
0167 /// Determine the priority to be given to a macro code completion result
0168 /// with the given name.
0169 ///
0170 /// \param MacroName The name of the macro.
0171 ///
0172 /// \param LangOpts Options describing the current language dialect.
0173 ///
0174 /// \param PreferredTypeIsPointer Whether the preferred type for the context
0175 /// of this macro is a pointer type.
0176 unsigned getMacroUsagePriority(StringRef MacroName,
0177                                const LangOptions &LangOpts,
0178                                bool PreferredTypeIsPointer = false);
0179 
0180 /// Determine the libclang cursor kind associated with the given
0181 /// declaration.
0182 CXCursorKind getCursorKindForDecl(const Decl *D);
0183 
0184 /// The context in which code completion occurred, so that the
0185 /// code-completion consumer can process the results accordingly.
0186 class CodeCompletionContext {
0187 public:
0188   enum Kind {
0189     /// An unspecified code-completion context.
0190     CCC_Other,
0191 
0192     /// An unspecified code-completion context where we should also add
0193     /// macro completions.
0194     CCC_OtherWithMacros,
0195 
0196     /// Code completion occurred within a "top-level" completion context,
0197     /// e.g., at namespace or global scope.
0198     CCC_TopLevel,
0199 
0200     /// Code completion occurred within an Objective-C interface,
0201     /// protocol, or category interface.
0202     CCC_ObjCInterface,
0203 
0204     /// Code completion occurred within an Objective-C implementation
0205     /// or category implementation.
0206     CCC_ObjCImplementation,
0207 
0208     /// Code completion occurred within the instance variable list of
0209     /// an Objective-C interface, implementation, or category implementation.
0210     CCC_ObjCIvarList,
0211 
0212     /// Code completion occurred within a class, struct, or union.
0213     CCC_ClassStructUnion,
0214 
0215     /// Code completion occurred where a statement (or declaration) is
0216     /// expected in a function, method, or block.
0217     CCC_Statement,
0218 
0219     /// Code completion occurred where an expression is expected.
0220     CCC_Expression,
0221 
0222     /// Code completion occurred where an Objective-C message receiver
0223     /// is expected.
0224     CCC_ObjCMessageReceiver,
0225 
0226     /// Code completion occurred on the right-hand side of a member
0227     /// access expression using the dot operator.
0228     ///
0229     /// The results of this completion are the members of the type being
0230     /// accessed. The type itself is available via
0231     /// \c CodeCompletionContext::getType().
0232     CCC_DotMemberAccess,
0233 
0234     /// Code completion occurred on the right-hand side of a member
0235     /// access expression using the arrow operator.
0236     ///
0237     /// The results of this completion are the members of the type being
0238     /// accessed. The type itself is available via
0239     /// \c CodeCompletionContext::getType().
0240     CCC_ArrowMemberAccess,
0241 
0242     /// Code completion occurred on the right-hand side of an Objective-C
0243     /// property access expression.
0244     ///
0245     /// The results of this completion are the members of the type being
0246     /// accessed. The type itself is available via
0247     /// \c CodeCompletionContext::getType().
0248     CCC_ObjCPropertyAccess,
0249 
0250     /// Code completion occurred after the "enum" keyword, to indicate
0251     /// an enumeration name.
0252     CCC_EnumTag,
0253 
0254     /// Code completion occurred after the "union" keyword, to indicate
0255     /// a union name.
0256     CCC_UnionTag,
0257 
0258     /// Code completion occurred after the "struct" or "class" keyword,
0259     /// to indicate a struct or class name.
0260     CCC_ClassOrStructTag,
0261 
0262     /// Code completion occurred where a protocol name is expected.
0263     CCC_ObjCProtocolName,
0264 
0265     /// Code completion occurred where a namespace or namespace alias
0266     /// is expected.
0267     CCC_Namespace,
0268 
0269     /// Code completion occurred where a type name is expected.
0270     CCC_Type,
0271 
0272     /// Code completion occurred where a new name is expected.
0273     CCC_NewName,
0274 
0275     /// Code completion occurred where both a new name and an existing symbol is
0276     /// permissible.
0277     CCC_SymbolOrNewName,
0278 
0279     /// Code completion occurred where an existing name(such as type, function
0280     /// or variable) is expected.
0281     CCC_Symbol,
0282 
0283     /// Code completion occurred where an macro is being defined.
0284     CCC_MacroName,
0285 
0286     /// Code completion occurred where a macro name is expected
0287     /// (without any arguments, in the case of a function-like macro).
0288     CCC_MacroNameUse,
0289 
0290     /// Code completion occurred within a preprocessor expression.
0291     CCC_PreprocessorExpression,
0292 
0293     /// Code completion occurred where a preprocessor directive is
0294     /// expected.
0295     CCC_PreprocessorDirective,
0296 
0297     /// Code completion occurred in a context where natural language is
0298     /// expected, e.g., a comment or string literal.
0299     ///
0300     /// This context usually implies that no completions should be added,
0301     /// unless they come from an appropriate natural-language dictionary.
0302     CCC_NaturalLanguage,
0303 
0304     /// Code completion for a selector, as in an \@selector expression.
0305     CCC_SelectorName,
0306 
0307     /// Code completion within a type-qualifier list.
0308     CCC_TypeQualifiers,
0309 
0310     /// Code completion in a parenthesized expression, which means that
0311     /// we may also have types here in C and Objective-C (as well as in C++).
0312     CCC_ParenthesizedExpression,
0313 
0314     /// Code completion where an Objective-C instance message is
0315     /// expected.
0316     CCC_ObjCInstanceMessage,
0317 
0318     /// Code completion where an Objective-C class message is expected.
0319     CCC_ObjCClassMessage,
0320 
0321     /// Code completion where the name of an Objective-C class is
0322     /// expected.
0323     CCC_ObjCInterfaceName,
0324 
0325     /// Code completion where an Objective-C category name is expected.
0326     CCC_ObjCCategoryName,
0327 
0328     /// Code completion inside the filename part of a #include directive.
0329     CCC_IncludedFile,
0330 
0331     /// Code completion of an attribute name.
0332     CCC_Attribute,
0333 
0334     /// An unknown context, in which we are recovering from a parsing
0335     /// error and don't know which completions we should give.
0336     CCC_Recovery,
0337 
0338     /// Code completion in a @class forward declaration.
0339     CCC_ObjCClassForwardDecl,
0340 
0341     /// Code completion at a top level, i.e. in a namespace or global scope,
0342     /// but also in expression statements. This is because REPL inputs can be
0343     /// declarations or expression statements.
0344     CCC_TopLevelOrExpression,
0345   };
0346 
0347   using VisitedContextSet = llvm::SmallPtrSet<DeclContext *, 8>;
0348 
0349 private:
0350   Kind CCKind;
0351 
0352   /// Indicates whether we are completing a name of a using declaration, e.g.
0353   ///     using ^;
0354   ///     using a::^;
0355   bool IsUsingDeclaration;
0356 
0357   /// The type that would prefer to see at this point (e.g., the type
0358   /// of an initializer or function parameter).
0359   QualType PreferredType;
0360 
0361   /// The type of the base object in a member access expression.
0362   QualType BaseType;
0363 
0364   /// The identifiers for Objective-C selector parts.
0365   ArrayRef<const IdentifierInfo *> SelIdents;
0366 
0367   /// The scope specifier that comes before the completion token e.g.
0368   /// "a::b::"
0369   std::optional<CXXScopeSpec> ScopeSpecifier;
0370 
0371   /// A set of declaration contexts visited by Sema when doing lookup for
0372   /// code completion.
0373   VisitedContextSet VisitedContexts;
0374 
0375 public:
0376   /// Construct a new code-completion context of the given kind.
0377   CodeCompletionContext(Kind CCKind)
0378       : CCKind(CCKind), IsUsingDeclaration(false), SelIdents() {}
0379 
0380   /// Construct a new code-completion context of the given kind.
0381   CodeCompletionContext(Kind CCKind, QualType T,
0382                         ArrayRef<const IdentifierInfo *> SelIdents = {})
0383       : CCKind(CCKind), IsUsingDeclaration(false), SelIdents(SelIdents) {
0384     if (CCKind == CCC_DotMemberAccess || CCKind == CCC_ArrowMemberAccess ||
0385         CCKind == CCC_ObjCPropertyAccess || CCKind == CCC_ObjCClassMessage ||
0386         CCKind == CCC_ObjCInstanceMessage)
0387       BaseType = T;
0388     else
0389       PreferredType = T;
0390   }
0391 
0392   bool isUsingDeclaration() const { return IsUsingDeclaration; }
0393   void setIsUsingDeclaration(bool V) { IsUsingDeclaration = V; }
0394 
0395   /// Retrieve the kind of code-completion context.
0396   Kind getKind() const { return CCKind; }
0397 
0398   /// Retrieve the type that this expression would prefer to have, e.g.,
0399   /// if the expression is a variable initializer or a function argument, the
0400   /// type of the corresponding variable or function parameter.
0401   QualType getPreferredType() const { return PreferredType; }
0402   void setPreferredType(QualType T) { PreferredType = T; }
0403 
0404   /// Retrieve the type of the base object in a member-access
0405   /// expression.
0406   QualType getBaseType() const { return BaseType; }
0407 
0408   /// Retrieve the Objective-C selector identifiers.
0409   ArrayRef<const IdentifierInfo *> getSelIdents() const { return SelIdents; }
0410 
0411   /// Determines whether we want C++ constructors as results within this
0412   /// context.
0413   bool wantConstructorResults() const;
0414 
0415   /// Sets the scope specifier that comes before the completion token.
0416   /// This is expected to be set in code completions on qualfied specifiers
0417   /// (e.g. "a::b::").
0418   void setCXXScopeSpecifier(CXXScopeSpec SS) {
0419     this->ScopeSpecifier = std::move(SS);
0420   }
0421 
0422   /// Adds a visited context.
0423   void addVisitedContext(DeclContext *Ctx) {
0424     VisitedContexts.insert(Ctx);
0425   }
0426 
0427   /// Retrieves all visited contexts.
0428   const VisitedContextSet &getVisitedContexts() const {
0429     return VisitedContexts;
0430   }
0431 
0432   std::optional<const CXXScopeSpec *> getCXXScopeSpecifier() {
0433     if (ScopeSpecifier)
0434       return &*ScopeSpecifier;
0435     return std::nullopt;
0436   }
0437 };
0438 
0439 /// Get string representation of \p Kind, useful for debugging.
0440 llvm::StringRef getCompletionKindString(CodeCompletionContext::Kind Kind);
0441 
0442 /// A "string" used to describe how code completion can
0443 /// be performed for an entity.
0444 ///
0445 /// A code completion string typically shows how a particular entity can be
0446 /// used. For example, the code completion string for a function would show
0447 /// the syntax to call it, including the parentheses, placeholders for the
0448 /// arguments, etc.
0449 class CodeCompletionString {
0450 public:
0451   /// The different kinds of "chunks" that can occur within a code
0452   /// completion string.
0453   enum ChunkKind {
0454     /// The piece of text that the user is expected to type to
0455     /// match the code-completion string, typically a keyword or the name of a
0456     /// declarator or macro.
0457     CK_TypedText,
0458 
0459     /// A piece of text that should be placed in the buffer, e.g.,
0460     /// parentheses or a comma in a function call.
0461     CK_Text,
0462 
0463     /// A code completion string that is entirely optional. For example,
0464     /// an optional code completion string that describes the default arguments
0465     /// in a function call.
0466     CK_Optional,
0467 
0468     /// A string that acts as a placeholder for, e.g., a function
0469     /// call argument.
0470     CK_Placeholder,
0471 
0472     /// A piece of text that describes something about the result but
0473     /// should not be inserted into the buffer.
0474     CK_Informative,
0475     /// A piece of text that describes the type of an entity or, for
0476     /// functions and methods, the return type.
0477     CK_ResultType,
0478 
0479     /// A piece of text that describes the parameter that corresponds
0480     /// to the code-completion location within a function call, message send,
0481     /// macro invocation, etc.
0482     CK_CurrentParameter,
0483 
0484     /// A left parenthesis ('(').
0485     CK_LeftParen,
0486 
0487     /// A right parenthesis (')').
0488     CK_RightParen,
0489 
0490     /// A left bracket ('[').
0491     CK_LeftBracket,
0492 
0493     /// A right bracket (']').
0494     CK_RightBracket,
0495 
0496     /// A left brace ('{').
0497     CK_LeftBrace,
0498 
0499     /// A right brace ('}').
0500     CK_RightBrace,
0501 
0502     /// A left angle bracket ('<').
0503     CK_LeftAngle,
0504 
0505     /// A right angle bracket ('>').
0506     CK_RightAngle,
0507 
0508     /// A comma separator (',').
0509     CK_Comma,
0510 
0511     /// A colon (':').
0512     CK_Colon,
0513 
0514     /// A semicolon (';').
0515     CK_SemiColon,
0516 
0517     /// An '=' sign.
0518     CK_Equal,
0519 
0520     /// Horizontal whitespace (' ').
0521     CK_HorizontalSpace,
0522 
0523     /// Vertical whitespace ('\\n' or '\\r\\n', depending on the
0524     /// platform).
0525     CK_VerticalSpace
0526   };
0527 
0528   /// One piece of the code completion string.
0529   struct Chunk {
0530     /// The kind of data stored in this piece of the code completion
0531     /// string.
0532     ChunkKind Kind = CK_Text;
0533 
0534     union {
0535       /// The text string associated with a CK_Text, CK_Placeholder,
0536       /// CK_Informative, or CK_Comma chunk.
0537       /// The string is owned by the chunk and will be deallocated
0538       /// (with delete[]) when the chunk is destroyed.
0539       const char *Text;
0540 
0541       /// The code completion string associated with a CK_Optional chunk.
0542       /// The optional code completion string is owned by the chunk, and will
0543       /// be deallocated (with delete) when the chunk is destroyed.
0544       CodeCompletionString *Optional;
0545     };
0546 
0547     Chunk() : Text(nullptr) {}
0548 
0549     explicit Chunk(ChunkKind Kind, const char *Text = "");
0550 
0551     /// Create a new text chunk.
0552     static Chunk CreateText(const char *Text);
0553 
0554     /// Create a new optional chunk.
0555     static Chunk CreateOptional(CodeCompletionString *Optional);
0556 
0557     /// Create a new placeholder chunk.
0558     static Chunk CreatePlaceholder(const char *Placeholder);
0559 
0560     /// Create a new informative chunk.
0561     static Chunk CreateInformative(const char *Informative);
0562 
0563     /// Create a new result type chunk.
0564     static Chunk CreateResultType(const char *ResultType);
0565 
0566     /// Create a new current-parameter chunk.
0567     static Chunk CreateCurrentParameter(const char *CurrentParameter);
0568   };
0569 
0570 private:
0571   friend class CodeCompletionBuilder;
0572   friend class CodeCompletionResult;
0573 
0574   /// The number of chunks stored in this string.
0575   unsigned NumChunks : 16;
0576 
0577   /// The number of annotations for this code-completion result.
0578   unsigned NumAnnotations : 16;
0579 
0580   /// The priority of this code-completion string.
0581   unsigned Priority : 16;
0582 
0583   /// The availability of this code-completion result.
0584   LLVM_PREFERRED_TYPE(CXAvailabilityKind)
0585   unsigned Availability : 2;
0586 
0587   /// The name of the parent context.
0588   StringRef ParentName;
0589 
0590   /// A brief documentation comment attached to the declaration of
0591   /// entity being completed by this result.
0592   const char *BriefComment;
0593 
0594   CodeCompletionString(const Chunk *Chunks, unsigned NumChunks,
0595                        unsigned Priority, CXAvailabilityKind Availability,
0596                        const char **Annotations, unsigned NumAnnotations,
0597                        StringRef ParentName,
0598                        const char *BriefComment);
0599   ~CodeCompletionString() = default;
0600 
0601 public:
0602   CodeCompletionString(const CodeCompletionString &) = delete;
0603   CodeCompletionString &operator=(const CodeCompletionString &) = delete;
0604 
0605   using iterator = const Chunk *;
0606 
0607   iterator begin() const { return reinterpret_cast<const Chunk *>(this + 1); }
0608   iterator end() const { return begin() + NumChunks; }
0609   bool empty() const { return NumChunks == 0; }
0610   unsigned size() const { return NumChunks; }
0611 
0612   const Chunk &operator[](unsigned I) const {
0613     assert(I < size() && "Chunk index out-of-range");
0614     return begin()[I];
0615   }
0616 
0617   /// Returns the text in the first TypedText chunk.
0618   const char *getTypedText() const;
0619 
0620   /// Returns the combined text from all TypedText chunks.
0621   std::string getAllTypedText() const;
0622 
0623   /// Retrieve the priority of this code completion result.
0624   unsigned getPriority() const { return Priority; }
0625 
0626   /// Retrieve the availability of this code completion result.
0627   unsigned getAvailability() const { return Availability; }
0628 
0629   /// Retrieve the number of annotations for this code completion result.
0630   unsigned getAnnotationCount() const;
0631 
0632   /// Retrieve the annotation string specified by \c AnnotationNr.
0633   const char *getAnnotation(unsigned AnnotationNr) const;
0634 
0635   /// Retrieve the name of the parent context.
0636   StringRef getParentContextName() const {
0637     return ParentName;
0638   }
0639 
0640   const char *getBriefComment() const {
0641     return BriefComment;
0642   }
0643 
0644   /// Retrieve a string representation of the code completion string,
0645   /// which is mainly useful for debugging.
0646   std::string getAsString() const;
0647 };
0648 
0649 /// An allocator used specifically for the purpose of code completion.
0650 class CodeCompletionAllocator : public llvm::BumpPtrAllocator {
0651 public:
0652   /// Copy the given string into this allocator.
0653   const char *CopyString(const Twine &String);
0654 };
0655 
0656 /// Allocator for a cached set of global code completions.
0657 class GlobalCodeCompletionAllocator : public CodeCompletionAllocator {};
0658 
0659 class CodeCompletionTUInfo {
0660   llvm::DenseMap<const DeclContext *, StringRef> ParentNames;
0661   std::shared_ptr<GlobalCodeCompletionAllocator> AllocatorRef;
0662 
0663 public:
0664   explicit CodeCompletionTUInfo(
0665       std::shared_ptr<GlobalCodeCompletionAllocator> Allocator)
0666       : AllocatorRef(std::move(Allocator)) {}
0667 
0668   std::shared_ptr<GlobalCodeCompletionAllocator> getAllocatorRef() const {
0669     return AllocatorRef;
0670   }
0671 
0672   CodeCompletionAllocator &getAllocator() const {
0673     assert(AllocatorRef);
0674     return *AllocatorRef;
0675   }
0676 
0677   StringRef getParentName(const DeclContext *DC);
0678 };
0679 
0680 } // namespace clang
0681 
0682 namespace clang {
0683 
0684 /// A builder class used to construct new code-completion strings.
0685 class CodeCompletionBuilder {
0686 public:
0687   using Chunk = CodeCompletionString::Chunk;
0688 
0689 private:
0690   CodeCompletionAllocator &Allocator;
0691   CodeCompletionTUInfo &CCTUInfo;
0692   unsigned Priority = 0;
0693   CXAvailabilityKind Availability = CXAvailability_Available;
0694   StringRef ParentName;
0695   const char *BriefComment = nullptr;
0696 
0697   /// The chunks stored in this string.
0698   SmallVector<Chunk, 4> Chunks;
0699 
0700   SmallVector<const char *, 2> Annotations;
0701 
0702 public:
0703   CodeCompletionBuilder(CodeCompletionAllocator &Allocator,
0704                         CodeCompletionTUInfo &CCTUInfo)
0705       : Allocator(Allocator), CCTUInfo(CCTUInfo) {}
0706 
0707   CodeCompletionBuilder(CodeCompletionAllocator &Allocator,
0708                         CodeCompletionTUInfo &CCTUInfo,
0709                         unsigned Priority, CXAvailabilityKind Availability)
0710       : Allocator(Allocator), CCTUInfo(CCTUInfo), Priority(Priority),
0711         Availability(Availability) {}
0712 
0713   /// Retrieve the allocator into which the code completion
0714   /// strings should be allocated.
0715   CodeCompletionAllocator &getAllocator() const { return Allocator; }
0716 
0717   CodeCompletionTUInfo &getCodeCompletionTUInfo() const { return CCTUInfo; }
0718 
0719   /// Take the resulting completion string.
0720   ///
0721   /// This operation can only be performed once.
0722   CodeCompletionString *TakeString();
0723 
0724   /// Add a new typed-text chunk.
0725   void AddTypedTextChunk(const char *Text);
0726 
0727   /// Add a new text chunk.
0728   void AddTextChunk(const char *Text);
0729 
0730   /// Add a new optional chunk.
0731   void AddOptionalChunk(CodeCompletionString *Optional);
0732 
0733   /// Add a new placeholder chunk.
0734   void AddPlaceholderChunk(const char *Placeholder);
0735 
0736   /// Add a new informative chunk.
0737   void AddInformativeChunk(const char *Text);
0738 
0739   /// Add a new result-type chunk.
0740   void AddResultTypeChunk(const char *ResultType);
0741 
0742   /// Add a new current-parameter chunk.
0743   void AddCurrentParameterChunk(const char *CurrentParameter);
0744 
0745   /// Add a new chunk.
0746   void AddChunk(CodeCompletionString::ChunkKind CK, const char *Text = "");
0747 
0748   void AddAnnotation(const char *A) { Annotations.push_back(A); }
0749 
0750   /// Add the parent context information to this code completion.
0751   void addParentContext(const DeclContext *DC);
0752 
0753   const char *getBriefComment() const { return BriefComment; }
0754   void addBriefComment(StringRef Comment);
0755 
0756   StringRef getParentName() const { return ParentName; }
0757 };
0758 
0759 /// Captures a result of code completion.
0760 class CodeCompletionResult {
0761 public:
0762   /// Describes the kind of result generated.
0763   enum ResultKind {
0764     /// Refers to a declaration.
0765     RK_Declaration = 0,
0766 
0767     /// Refers to a keyword or symbol.
0768     RK_Keyword,
0769 
0770     /// Refers to a macro.
0771     RK_Macro,
0772 
0773     /// Refers to a precomputed pattern.
0774     RK_Pattern
0775   };
0776 
0777   /// When Kind == RK_Declaration or RK_Pattern, the declaration we are
0778   /// referring to. In the latter case, the declaration might be NULL.
0779   const NamedDecl *Declaration = nullptr;
0780 
0781   union {
0782     /// When Kind == RK_Keyword, the string representing the keyword
0783     /// or symbol's spelling.
0784     const char *Keyword;
0785 
0786     /// When Kind == RK_Pattern, the code-completion string that
0787     /// describes the completion text to insert.
0788     CodeCompletionString *Pattern;
0789 
0790     /// When Kind == RK_Macro, the identifier that refers to a macro.
0791     const IdentifierInfo *Macro;
0792   };
0793 
0794   /// The priority of this particular code-completion result.
0795   unsigned Priority;
0796 
0797   /// Specifies which parameter (of a function, Objective-C method,
0798   /// macro, etc.) we should start with when formatting the result.
0799   unsigned StartParameter = 0;
0800 
0801   /// The kind of result stored here.
0802   ResultKind Kind;
0803 
0804   /// The cursor kind that describes this result.
0805   CXCursorKind CursorKind;
0806 
0807   /// The availability of this result.
0808   CXAvailabilityKind Availability = CXAvailability_Available;
0809 
0810   /// Fix-its that *must* be applied before inserting the text for the
0811   /// corresponding completion.
0812   ///
0813   /// By default, CodeCompletionBuilder only returns completions with empty
0814   /// fix-its. Extra completions with non-empty fix-its should be explicitly
0815   /// requested by setting CompletionOptions::IncludeFixIts.
0816   ///
0817   /// For the clients to be able to compute position of the cursor after
0818   /// applying fix-its, the following conditions are guaranteed to hold for
0819   /// RemoveRange of the stored fix-its:
0820   ///  - Ranges in the fix-its are guaranteed to never contain the completion
0821   ///  point (or identifier under completion point, if any) inside them, except
0822   ///  at the start or at the end of the range.
0823   ///  - If a fix-it range starts or ends with completion point (or starts or
0824   ///  ends after the identifier under completion point), it will contain at
0825   ///  least one character. It allows to unambiguously recompute completion
0826   ///  point after applying the fix-it.
0827   ///
0828   /// The intuition is that provided fix-its change code around the identifier
0829   /// we complete, but are not allowed to touch the identifier itself or the
0830   /// completion point. One example of completions with corrections are the ones
0831   /// replacing '.' with '->' and vice versa:
0832   ///
0833   /// std::unique_ptr<std::vector<int>> vec_ptr;
0834   /// In 'vec_ptr.^', one of the completions is 'push_back', it requires
0835   /// replacing '.' with '->'.
0836   /// In 'vec_ptr->^', one of the completions is 'release', it requires
0837   /// replacing '->' with '.'.
0838   std::vector<FixItHint> FixIts;
0839 
0840   /// Whether this result is hidden by another name.
0841   bool Hidden : 1;
0842 
0843   /// Whether this is a class member from base class.
0844   bool InBaseClass : 1;
0845 
0846   /// Whether this result was found via lookup into a base class.
0847   bool QualifierIsInformative : 1;
0848 
0849   /// Whether this declaration is the beginning of a
0850   /// nested-name-specifier and, therefore, should be followed by '::'.
0851   bool StartsNestedNameSpecifier : 1;
0852 
0853   /// Whether all parameters (of a function, Objective-C
0854   /// method, etc.) should be considered "informative".
0855   bool AllParametersAreInformative : 1;
0856 
0857   /// Whether we're completing a declaration of the given entity,
0858   /// rather than a use of that entity.
0859   bool DeclaringEntity : 1;
0860 
0861   /// When completing a function, whether it can be a call. This will usually be
0862   /// true, but we have some heuristics, e.g. when a pointer to a non-static
0863   /// member function is completed outside of that class' scope, it can never
0864   /// be a call.
0865   bool FunctionCanBeCall : 1;
0866 
0867   /// If the result should have a nested-name-specifier, this is it.
0868   /// When \c QualifierIsInformative, the nested-name-specifier is
0869   /// informative rather than required.
0870   NestedNameSpecifier *Qualifier = nullptr;
0871 
0872   /// If this Decl was unshadowed by using declaration, this can store a
0873   /// pointer to the UsingShadowDecl which was used in the unshadowing process.
0874   /// This information can be used to uprank CodeCompletionResults / which have
0875   /// corresponding `using decl::qualified::name;` nearby.
0876   const UsingShadowDecl *ShadowDecl = nullptr;
0877 
0878   /// If the result is RK_Macro, this can store the information about the macro
0879   /// definition. This should be set in most cases but can be missing when
0880   /// the macro has been undefined.
0881   const MacroInfo *MacroDefInfo = nullptr;
0882 
0883   /// Build a result that refers to a declaration.
0884   CodeCompletionResult(const NamedDecl *Declaration, unsigned Priority,
0885                        NestedNameSpecifier *Qualifier = nullptr,
0886                        bool QualifierIsInformative = false,
0887                        bool Accessible = true,
0888                        std::vector<FixItHint> FixIts = std::vector<FixItHint>())
0889       : Declaration(Declaration), Priority(Priority), Kind(RK_Declaration),
0890         FixIts(std::move(FixIts)), Hidden(false), InBaseClass(false),
0891         QualifierIsInformative(QualifierIsInformative),
0892         StartsNestedNameSpecifier(false), AllParametersAreInformative(false),
0893         DeclaringEntity(false), FunctionCanBeCall(true), Qualifier(Qualifier) {
0894     // FIXME: Add assert to check FixIts range requirements.
0895     computeCursorKindAndAvailability(Accessible);
0896   }
0897 
0898   /// Build a result that refers to a keyword or symbol.
0899   CodeCompletionResult(const char *Keyword, unsigned Priority = CCP_Keyword)
0900       : Keyword(Keyword), Priority(Priority), Kind(RK_Keyword),
0901         CursorKind(CXCursor_NotImplemented), Hidden(false), InBaseClass(false),
0902         QualifierIsInformative(false), StartsNestedNameSpecifier(false),
0903         AllParametersAreInformative(false), DeclaringEntity(false),
0904         FunctionCanBeCall(true) {}
0905 
0906   /// Build a result that refers to a macro.
0907   CodeCompletionResult(const IdentifierInfo *Macro,
0908                        const MacroInfo *MI = nullptr,
0909                        unsigned Priority = CCP_Macro)
0910       : Macro(Macro), Priority(Priority), Kind(RK_Macro),
0911         CursorKind(CXCursor_MacroDefinition), Hidden(false), InBaseClass(false),
0912         QualifierIsInformative(false), StartsNestedNameSpecifier(false),
0913         AllParametersAreInformative(false), DeclaringEntity(false),
0914         FunctionCanBeCall(true), MacroDefInfo(MI) {}
0915 
0916   /// Build a result that refers to a pattern.
0917   CodeCompletionResult(
0918       CodeCompletionString *Pattern, unsigned Priority = CCP_CodePattern,
0919       CXCursorKind CursorKind = CXCursor_NotImplemented,
0920       CXAvailabilityKind Availability = CXAvailability_Available,
0921       const NamedDecl *D = nullptr)
0922       : Declaration(D), Pattern(Pattern), Priority(Priority), Kind(RK_Pattern),
0923         CursorKind(CursorKind), Availability(Availability), Hidden(false),
0924         InBaseClass(false), QualifierIsInformative(false),
0925         StartsNestedNameSpecifier(false), AllParametersAreInformative(false),
0926         DeclaringEntity(false), FunctionCanBeCall(true) {}
0927 
0928   /// Build a result that refers to a pattern with an associated
0929   /// declaration.
0930   CodeCompletionResult(CodeCompletionString *Pattern, const NamedDecl *D,
0931                        unsigned Priority)
0932       : Declaration(D), Pattern(Pattern), Priority(Priority), Kind(RK_Pattern),
0933         Hidden(false), InBaseClass(false), QualifierIsInformative(false),
0934         StartsNestedNameSpecifier(false), AllParametersAreInformative(false),
0935         DeclaringEntity(false), FunctionCanBeCall(true) {
0936     computeCursorKindAndAvailability();
0937   }
0938 
0939   /// Retrieve the declaration stored in this result. This might be nullptr if
0940   /// Kind is RK_Pattern.
0941   const NamedDecl *getDeclaration() const {
0942     assert(((Kind == RK_Declaration) || (Kind == RK_Pattern)) &&
0943            "Not a declaration or pattern result");
0944     return Declaration;
0945   }
0946 
0947   /// Retrieve the keyword stored in this result.
0948   const char *getKeyword() const {
0949     assert(Kind == RK_Keyword && "Not a keyword result");
0950     return Keyword;
0951   }
0952 
0953   /// Create a new code-completion string that describes how to insert
0954   /// this result into a program.
0955   ///
0956   /// \param S The semantic analysis that created the result.
0957   ///
0958   /// \param Allocator The allocator that will be used to allocate the
0959   /// string itself.
0960   CodeCompletionString *CreateCodeCompletionString(Sema &S,
0961                                          const CodeCompletionContext &CCContext,
0962                                            CodeCompletionAllocator &Allocator,
0963                                            CodeCompletionTUInfo &CCTUInfo,
0964                                            bool IncludeBriefComments);
0965   CodeCompletionString *CreateCodeCompletionString(ASTContext &Ctx,
0966                                                    Preprocessor &PP,
0967                                          const CodeCompletionContext &CCContext,
0968                                            CodeCompletionAllocator &Allocator,
0969                                            CodeCompletionTUInfo &CCTUInfo,
0970                                            bool IncludeBriefComments);
0971   /// Creates a new code-completion string for the macro result. Similar to the
0972   /// above overloads, except this only requires preprocessor information.
0973   /// The result kind must be `RK_Macro`.
0974   CodeCompletionString *
0975   CreateCodeCompletionStringForMacro(Preprocessor &PP,
0976                                      CodeCompletionAllocator &Allocator,
0977                                      CodeCompletionTUInfo &CCTUInfo);
0978 
0979   CodeCompletionString *createCodeCompletionStringForDecl(
0980       Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result,
0981       bool IncludeBriefComments, const CodeCompletionContext &CCContext,
0982       PrintingPolicy &Policy);
0983 
0984   CodeCompletionString *createCodeCompletionStringForOverride(
0985       Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result,
0986       bool IncludeBriefComments, const CodeCompletionContext &CCContext,
0987       PrintingPolicy &Policy);
0988 
0989   /// Retrieve the name that should be used to order a result.
0990   ///
0991   /// If the name needs to be constructed as a string, that string will be
0992   /// saved into Saved and the returned StringRef will refer to it.
0993   StringRef getOrderedName(std::string &Saved) const;
0994 
0995 private:
0996   void computeCursorKindAndAvailability(bool Accessible = true);
0997 };
0998 
0999 bool operator<(const CodeCompletionResult &X, const CodeCompletionResult &Y);
1000 
1001 inline bool operator>(const CodeCompletionResult &X,
1002                       const CodeCompletionResult &Y) {
1003   return Y < X;
1004 }
1005 
1006 inline bool operator<=(const CodeCompletionResult &X,
1007                       const CodeCompletionResult &Y) {
1008   return !(Y < X);
1009 }
1010 
1011 inline bool operator>=(const CodeCompletionResult &X,
1012                        const CodeCompletionResult &Y) {
1013   return !(X < Y);
1014 }
1015 
1016 /// Abstract interface for a consumer of code-completion
1017 /// information.
1018 class CodeCompleteConsumer {
1019 protected:
1020   const CodeCompleteOptions CodeCompleteOpts;
1021 
1022 public:
1023   class OverloadCandidate {
1024   public:
1025     /// Describes the type of overload candidate.
1026     enum CandidateKind {
1027       /// The candidate is a function declaration.
1028       CK_Function,
1029 
1030       /// The candidate is a function template, arguments are being completed.
1031       CK_FunctionTemplate,
1032 
1033       /// The "candidate" is actually a variable, expression, or block
1034       /// for which we only have a function prototype.
1035       CK_FunctionType,
1036 
1037       /// The candidate is a variable or expression of function type
1038       /// for which we have the location of the prototype declaration.
1039       CK_FunctionProtoTypeLoc,
1040 
1041       /// The candidate is a template, template arguments are being completed.
1042       CK_Template,
1043 
1044       /// The candidate is aggregate initialization of a record type.
1045       CK_Aggregate,
1046     };
1047 
1048   private:
1049     /// The kind of overload candidate.
1050     CandidateKind Kind;
1051 
1052     union {
1053       /// The function overload candidate, available when
1054       /// Kind == CK_Function.
1055       FunctionDecl *Function;
1056 
1057       /// The function template overload candidate, available when
1058       /// Kind == CK_FunctionTemplate.
1059       FunctionTemplateDecl *FunctionTemplate;
1060 
1061       /// The function type that describes the entity being called,
1062       /// when Kind == CK_FunctionType.
1063       const FunctionType *Type;
1064 
1065       /// The location of the function prototype that describes the entity being
1066       /// called, when Kind == CK_FunctionProtoTypeLoc.
1067       FunctionProtoTypeLoc ProtoTypeLoc;
1068 
1069       /// The template overload candidate, available when
1070       /// Kind == CK_Template.
1071       const TemplateDecl *Template;
1072 
1073       /// The class being aggregate-initialized,
1074       /// when Kind == CK_Aggregate
1075       const RecordDecl *AggregateType;
1076     };
1077 
1078   public:
1079     OverloadCandidate(FunctionDecl *Function)
1080         : Kind(CK_Function), Function(Function) {
1081       assert(Function != nullptr);
1082     }
1083 
1084     OverloadCandidate(FunctionTemplateDecl *FunctionTemplateDecl)
1085         : Kind(CK_FunctionTemplate), FunctionTemplate(FunctionTemplateDecl) {
1086       assert(FunctionTemplateDecl != nullptr);
1087     }
1088 
1089     OverloadCandidate(const FunctionType *Type)
1090         : Kind(CK_FunctionType), Type(Type) {
1091       assert(Type != nullptr);
1092     }
1093 
1094     OverloadCandidate(FunctionProtoTypeLoc Prototype)
1095         : Kind(CK_FunctionProtoTypeLoc), ProtoTypeLoc(Prototype) {
1096       assert(!Prototype.isNull());
1097     }
1098 
1099     OverloadCandidate(const RecordDecl *Aggregate)
1100         : Kind(CK_Aggregate), AggregateType(Aggregate) {
1101       assert(Aggregate != nullptr);
1102     }
1103 
1104     OverloadCandidate(const TemplateDecl *Template)
1105         : Kind(CK_Template), Template(Template) {}
1106 
1107     /// Determine the kind of overload candidate.
1108     CandidateKind getKind() const { return Kind; }
1109 
1110     /// Retrieve the function overload candidate or the templated
1111     /// function declaration for a function template.
1112     FunctionDecl *getFunction() const;
1113 
1114     /// Retrieve the function template overload candidate.
1115     FunctionTemplateDecl *getFunctionTemplate() const {
1116       assert(getKind() == CK_FunctionTemplate && "Not a function template");
1117       return FunctionTemplate;
1118     }
1119 
1120     /// Retrieve the function type of the entity, regardless of how the
1121     /// function is stored.
1122     const FunctionType *getFunctionType() const;
1123 
1124     /// Retrieve the function ProtoTypeLoc candidate.
1125     /// This can be called for any Kind, but returns null for kinds
1126     /// other than CK_FunctionProtoTypeLoc.
1127     const FunctionProtoTypeLoc getFunctionProtoTypeLoc() const;
1128 
1129     const TemplateDecl *getTemplate() const {
1130       assert(getKind() == CK_Template && "Not a template");
1131       return Template;
1132     }
1133 
1134     /// Retrieve the aggregate type being initialized.
1135     const RecordDecl *getAggregate() const {
1136       assert(getKind() == CK_Aggregate);
1137       return AggregateType;
1138     }
1139 
1140     /// Get the number of parameters in this signature.
1141     unsigned getNumParams() const;
1142 
1143     /// Get the type of the Nth parameter.
1144     /// Returns null if the type is unknown or N is out of range.
1145     QualType getParamType(unsigned N) const;
1146 
1147     /// Get the declaration of the Nth parameter.
1148     /// Returns null if the decl is unknown or N is out of range.
1149     const NamedDecl *getParamDecl(unsigned N) const;
1150 
1151     /// Create a new code-completion string that describes the function
1152     /// signature of this overload candidate.
1153     CodeCompletionString *
1154     CreateSignatureString(unsigned CurrentArg, Sema &S,
1155                           CodeCompletionAllocator &Allocator,
1156                           CodeCompletionTUInfo &CCTUInfo,
1157                           bool IncludeBriefComments, bool Braced) const;
1158   };
1159 
1160   CodeCompleteConsumer(const CodeCompleteOptions &CodeCompleteOpts)
1161       : CodeCompleteOpts(CodeCompleteOpts) {}
1162 
1163   /// Whether the code-completion consumer wants to see macros.
1164   bool includeMacros() const {
1165     return CodeCompleteOpts.IncludeMacros;
1166   }
1167 
1168   /// Whether the code-completion consumer wants to see code patterns.
1169   bool includeCodePatterns() const {
1170     return CodeCompleteOpts.IncludeCodePatterns;
1171   }
1172 
1173   /// Whether to include global (top-level) declaration results.
1174   bool includeGlobals() const { return CodeCompleteOpts.IncludeGlobals; }
1175 
1176   /// Whether to include declarations in namespace contexts (including
1177   /// the global namespace). If this is false, `includeGlobals()` will be
1178   /// ignored.
1179   bool includeNamespaceLevelDecls() const {
1180     return CodeCompleteOpts.IncludeNamespaceLevelDecls;
1181   }
1182 
1183   /// Whether to include brief documentation comments within the set of
1184   /// code completions returned.
1185   bool includeBriefComments() const {
1186     return CodeCompleteOpts.IncludeBriefComments;
1187   }
1188 
1189   /// Whether to include completion items with small fix-its, e.g. change
1190   /// '.' to '->' on member access, etc.
1191   bool includeFixIts() const { return CodeCompleteOpts.IncludeFixIts; }
1192 
1193   /// Hint whether to load data from the external AST in order to provide
1194   /// full results. If false, declarations from the preamble may be omitted.
1195   bool loadExternal() const {
1196     return CodeCompleteOpts.LoadExternal;
1197   }
1198 
1199   /// Deregisters and destroys this code-completion consumer.
1200   virtual ~CodeCompleteConsumer();
1201 
1202   /// \name Code-completion filtering
1203   /// Check if the result should be filtered out.
1204   virtual bool isResultFilteredOut(StringRef Filter,
1205                                    CodeCompletionResult Results) {
1206     return false;
1207   }
1208 
1209   /// \name Code-completion callbacks
1210   //@{
1211   /// Process the finalized code-completion results.
1212   virtual void ProcessCodeCompleteResults(Sema &S,
1213                                           CodeCompletionContext Context,
1214                                           CodeCompletionResult *Results,
1215                                           unsigned NumResults) {}
1216 
1217   /// \param S the semantic-analyzer object for which code-completion is being
1218   /// done.
1219   ///
1220   /// \param CurrentArg the index of the current argument.
1221   ///
1222   /// \param Candidates an array of overload candidates.
1223   ///
1224   /// \param NumCandidates the number of overload candidates
1225   ///
1226   /// \param OpenParLoc location of the opening parenthesis of the argument
1227   ///        list.
1228   virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
1229                                          OverloadCandidate *Candidates,
1230                                          unsigned NumCandidates,
1231                                          SourceLocation OpenParLoc,
1232                                          bool Braced) {}
1233   //@}
1234 
1235   /// Retrieve the allocator that will be used to allocate
1236   /// code completion strings.
1237   virtual CodeCompletionAllocator &getAllocator() = 0;
1238 
1239   virtual CodeCompletionTUInfo &getCodeCompletionTUInfo() = 0;
1240 };
1241 
1242 /// Get the documentation comment used to produce
1243 /// CodeCompletionString::BriefComment for RK_Declaration.
1244 const RawComment *getCompletionComment(const ASTContext &Ctx,
1245                                        const NamedDecl *Decl);
1246 
1247 /// Get the documentation comment used to produce
1248 /// CodeCompletionString::BriefComment for RK_Pattern.
1249 const RawComment *getPatternCompletionComment(const ASTContext &Ctx,
1250                                               const NamedDecl *Decl);
1251 
1252 /// Get the documentation comment used to produce
1253 /// CodeCompletionString::BriefComment for OverloadCandidate.
1254 const RawComment *
1255 getParameterComment(const ASTContext &Ctx,
1256                     const CodeCompleteConsumer::OverloadCandidate &Result,
1257                     unsigned ArgIndex);
1258 
1259 /// A simple code-completion consumer that prints the results it
1260 /// receives in a simple format.
1261 class PrintingCodeCompleteConsumer : public CodeCompleteConsumer {
1262   /// The raw output stream.
1263   raw_ostream &OS;
1264 
1265   CodeCompletionTUInfo CCTUInfo;
1266 
1267 public:
1268   /// Create a new printing code-completion consumer that prints its
1269   /// results to the given raw output stream.
1270   PrintingCodeCompleteConsumer(const CodeCompleteOptions &CodeCompleteOpts,
1271                                raw_ostream &OS)
1272       : CodeCompleteConsumer(CodeCompleteOpts), OS(OS),
1273         CCTUInfo(std::make_shared<GlobalCodeCompletionAllocator>()) {}
1274 
1275   /// Prints the finalized code-completion results.
1276   void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context,
1277                                   CodeCompletionResult *Results,
1278                                   unsigned NumResults) override;
1279 
1280   void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
1281                                  OverloadCandidate *Candidates,
1282                                  unsigned NumCandidates,
1283                                  SourceLocation OpenParLoc,
1284                                  bool Braced) override;
1285 
1286   bool isResultFilteredOut(StringRef Filter, CodeCompletionResult Results) override;
1287 
1288   CodeCompletionAllocator &getAllocator() override {
1289     return CCTUInfo.getAllocator();
1290   }
1291 
1292   CodeCompletionTUInfo &getCodeCompletionTUInfo() override { return CCTUInfo; }
1293 };
1294 
1295 } // namespace clang
1296 
1297 #endif // LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H