1 //===---- CodeCompleteConsumer.h - Code Completion Interface ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the CodeCompleteConsumer class.
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H
14 #define LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H
16 #include "clang/AST/Type.h"
17 #include "clang/AST/CanonicalType.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Support/Allocator.h"
21 #include "clang-c/Index.h"
33 /// \brief Default priority values for code-completion results based
36 /// \brief Priority for the next initialization in a constructor initializer
38 CCP_NextInitializer = 7,
39 /// \brief Priority for an enumeration constant inside a switch whose
40 /// condition is of the enumeration type.
42 /// \brief Priority for a send-to-super completion.
43 CCP_SuperCompletion = 20,
44 /// \brief Priority for a declaration that is in the local scope.
45 CCP_LocalDeclaration = 34,
46 /// \brief Priority for a member declaration found from the current
47 /// method or member function.
48 CCP_MemberDeclaration = 35,
49 /// \brief Priority for a language keyword (that isn't any of the other
52 /// \brief Priority for a code pattern.
54 /// \brief Priority for a non-type declaration.
56 /// \brief Priority for a type.
57 CCP_Type = CCP_Declaration,
58 /// \brief Priority for a constant value (e.g., enumerator).
60 /// \brief Priority for a preprocessor macro.
62 /// \brief Priority for a nested-name-specifier.
63 CCP_NestedNameSpecifier = 75,
64 /// \brief Priority for a result that isn't likely to be what the user wants,
65 /// but is included for completeness.
68 /// \brief Priority for the Objective-C "_cmd" implicit parameter.
69 CCP_ObjC_cmd = CCP_Unlikely
72 /// \brief Priority value deltas that are added to code-completion results
73 /// based on the context of the result.
75 /// \brief The result is in a base class.
77 /// \brief The result is a C++ non-static member function whose qualifiers
78 /// exactly match the object type on which the member function can be called.
79 CCD_ObjectQualifierMatch = -1,
80 /// \brief The selector of the given message exactly matches the selector
81 /// of the current method, which might imply that some kind of delegation
83 CCD_SelectorMatch = -3,
85 /// \brief Adjustment to the "bool" type in Objective-C, where the typedef
86 /// "BOOL" is preferred.
89 /// \brief Adjustment for KVC code pattern priorities when it doesn't look
91 CCD_ProbablyNotObjCCollection = 15,
93 /// \brief An Objective-C method being used as a property.
94 CCD_MethodAsProperty = 2
97 /// \brief Priority value factors by which we will divide or multiply the
98 /// priority of a code-completion result.
100 /// \brief Divide by this factor when a code-completion result's type exactly
101 /// matches the type we expect.
102 CCF_ExactTypeMatch = 4,
103 /// \brief Divide by this factor when a code-completion result's type is
104 /// similar to the type we expect (e.g., both arithmetic types, both
105 /// Objective-C object pointer types).
106 CCF_SimilarTypeMatch = 2
109 /// \brief A simplified classification of types used when determining
110 /// "similar" types for code completion.
111 enum SimplifiedTypeClass {
123 /// \brief Determine the simplified type class of the given canonical type.
124 SimplifiedTypeClass getSimplifiedTypeClass(CanQualType T);
126 /// \brief Determine the type that this declaration will have if it is used
127 /// as a type or in an expression.
128 QualType getDeclUsageType(ASTContext &C, NamedDecl *ND);
130 /// \brief Determine the priority to be given to a macro code completion result
131 /// with the given name.
133 /// \param MacroName The name of the macro.
135 /// \param LangOpts Options describing the current language dialect.
137 /// \param PreferredTypeIsPointer Whether the preferred type for the context
138 /// of this macro is a pointer type.
139 unsigned getMacroUsagePriority(llvm::StringRef MacroName,
140 const LangOptions &LangOpts,
141 bool PreferredTypeIsPointer = false);
143 /// \brief Determine the libclang cursor kind associated with the given
145 CXCursorKind getCursorKindForDecl(Decl *D);
149 class FunctionTemplateDecl;
150 class IdentifierInfo;
152 class NestedNameSpecifier;
155 /// \brief The context in which code completion occurred, so that the
156 /// code-completion consumer can process the results accordingly.
157 class CodeCompletionContext {
160 /// \brief An unspecified code-completion context.
162 /// \brief An unspecified code-completion context where we should also add
163 /// macro completions.
165 /// \brief Code completion occurred within a "top-level" completion context,
166 /// e.g., at namespace or global scope.
168 /// \brief Code completion occurred within an Objective-C interface,
169 /// protocol, or category interface.
171 /// \brief Code completion occurred within an Objective-C implementation
172 /// or category implementation.
173 CCC_ObjCImplementation,
174 /// \brief Code completion occurred within the instance variable list of
175 /// an Objective-C interface, implementation, or category implementation.
177 /// \brief Code completion occurred within a class, struct, or union.
178 CCC_ClassStructUnion,
179 /// \brief Code completion occurred where a statement (or declaration) is
180 /// expected in a function, method, or block.
182 /// \brief Code completion occurred where an expression is expected.
184 /// \brief Code completion occurred where an Objective-C message receiver
186 CCC_ObjCMessageReceiver,
187 /// \brief Code completion occurred on the right-hand side of a member
188 /// access expression using the dot operator.
190 /// The results of this completion are the members of the type being
191 /// accessed. The type itself is available via
192 /// \c CodeCompletionContext::getType().
194 /// \brief Code completion occurred on the right-hand side of a member
195 /// access expression using the arrow operator.
197 /// The results of this completion are the members of the type being
198 /// accessed. The type itself is available via
199 /// \c CodeCompletionContext::getType().
200 CCC_ArrowMemberAccess,
201 /// \brief Code completion occurred on the right-hand side of an Objective-C
202 /// property access expression.
204 /// The results of this completion are the members of the type being
205 /// accessed. The type itself is available via
206 /// \c CodeCompletionContext::getType().
207 CCC_ObjCPropertyAccess,
208 /// \brief Code completion occurred after the "enum" keyword, to indicate
209 /// an enumeration name.
211 /// \brief Code completion occurred after the "union" keyword, to indicate
214 /// \brief Code completion occurred after the "struct" or "class" keyword,
215 /// to indicate a struct or class name.
216 CCC_ClassOrStructTag,
217 /// \brief Code completion occurred where a protocol name is expected.
218 CCC_ObjCProtocolName,
219 /// \brief Code completion occurred where a namespace or namespace alias
222 /// \brief Code completion occurred where a type name is expected.
224 /// \brief Code completion occurred where a new name is expected.
226 /// \brief Code completion occurred where a new name is expected and a
227 /// qualified name is permissible.
228 CCC_PotentiallyQualifiedName,
229 /// \brief Code completion occurred where an macro is being defined.
231 /// \brief Code completion occurred where a macro name is expected
232 /// (without any arguments, in the case of a function-like macro).
234 /// \brief Code completion occurred within a preprocessor expression.
235 CCC_PreprocessorExpression,
236 /// \brief Code completion occurred where a preprocessor directive is
238 CCC_PreprocessorDirective,
239 /// \brief Code completion occurred in a context where natural language is
240 /// expected, e.g., a comment or string literal.
242 /// This context usually implies that no completions should be added,
243 /// unless they come from an appropriate natural-language dictionary.
245 /// \brief Code completion for a selector, as in an @selector expression.
247 /// \brief Code completion within a type-qualifier list.
249 /// \brief Code completion in a parenthesized expression, which means that
250 /// we may also have types here in C and Objective-C (as well as in C++).
251 CCC_ParenthesizedExpression,
252 /// \brief Code completion where an Objective-C instance message is expcted.
253 CCC_ObjCInstanceMessage,
254 /// \brief Code completion where an Objective-C class message is expected.
255 CCC_ObjCClassMessage,
256 /// \brief Code completion where a superclass of an Objective-C class is
259 /// \brief Code completion where an Objective-C category name is expected.
260 CCC_ObjCCategoryName,
261 /// \brief An unknown context, in which we are recovering from a parsing
262 /// error and don't know which completions we should give.
269 /// \brief The type that would prefer to see at this point (e.g., the type
270 /// of an initializer or function parameter).
271 QualType PreferredType;
273 /// \brief The type of the base object in a member access expression.
277 /// \brief Construct a new code-completion context of the given kind.
278 CodeCompletionContext(enum Kind Kind) : Kind(Kind) { }
280 /// \brief Construct a new code-completion context of the given kind.
281 CodeCompletionContext(enum Kind Kind, QualType T) : Kind(Kind) {
282 if (Kind == CCC_DotMemberAccess || Kind == CCC_ArrowMemberAccess ||
283 Kind == CCC_ObjCPropertyAccess)
289 /// \brief Retrieve the kind of code-completion context.
290 enum Kind getKind() const { return Kind; }
292 /// \brief Retrieve the type that this expression would prefer to have, e.g.,
293 /// if the expression is a variable initializer or a function argument, the
294 /// type of the corresponding variable or function parameter.
295 QualType getPreferredType() const { return PreferredType; }
297 /// \brief Retrieve the type of the base object in a member-access
299 QualType getBaseType() const { return BaseType; }
301 /// \brief Determines whether we want C++ constructors as results within this
303 bool wantConstructorResults() const;
307 /// \brief A "string" used to describe how code completion can
308 /// be performed for an entity.
310 /// A code completion string typically shows how a particular entity can be
311 /// used. For example, the code completion string for a function would show
312 /// the syntax to call it, including the parentheses, placeholders for the
314 class CodeCompletionString {
316 /// \brief The different kinds of "chunks" that can occur within a code
317 /// completion string.
319 /// \brief The piece of text that the user is expected to type to
320 /// match the code-completion string, typically a keyword or the name of a
321 /// declarator or macro.
323 /// \brief A piece of text that should be placed in the buffer, e.g.,
324 /// parentheses or a comma in a function call.
326 /// \brief A code completion string that is entirely optional. For example,
327 /// an optional code completion string that describes the default arguments
328 /// in a function call.
330 /// \brief A string that acts as a placeholder for, e.g., a function
333 /// \brief A piece of text that describes something about the result but
334 /// should not be inserted into the buffer.
336 /// \brief A piece of text that describes the type of an entity or, for
337 /// functions and methods, the return type.
339 /// \brief A piece of text that describes the parameter that corresponds
340 /// to the code-completion location within a function call, message send,
341 /// macro invocation, etc.
343 /// \brief A left parenthesis ('(').
345 /// \brief A right parenthesis (')').
347 /// \brief A left bracket ('[').
349 /// \brief A right bracket (']').
351 /// \brief A left brace ('{').
353 /// \brief A right brace ('}').
355 /// \brief A left angle bracket ('<').
357 /// \brief A right angle bracket ('>').
359 /// \brief A comma separator (',').
361 /// \brief A colon (':').
363 /// \brief A semicolon (';').
365 /// \brief An '=' sign.
367 /// \brief Horizontal whitespace (' ').
369 /// \brief Verticle whitespace ('\n' or '\r\n', depending on the
374 /// \brief One piece of the code completion string.
376 /// \brief The kind of data stored in this piece of the code completion
381 /// \brief The text string associated with a CK_Text, CK_Placeholder,
382 /// CK_Informative, or CK_Comma chunk.
383 /// The string is owned by the chunk and will be deallocated
384 /// (with delete[]) when the chunk is destroyed.
387 /// \brief The code completion string associated with a CK_Optional chunk.
388 /// The optional code completion string is owned by the chunk, and will
389 /// be deallocated (with delete) when the chunk is destroyed.
390 CodeCompletionString *Optional;
393 Chunk() : Kind(CK_Text), Text(0) { }
395 Chunk(ChunkKind Kind, const char *Text = "");
397 /// \brief Create a new text chunk.
398 static Chunk CreateText(const char *Text);
400 /// \brief Create a new optional chunk.
401 static Chunk CreateOptional(CodeCompletionString *Optional);
403 /// \brief Create a new placeholder chunk.
404 static Chunk CreatePlaceholder(const char *Placeholder);
406 /// \brief Create a new informative chunk.
407 static Chunk CreateInformative(const char *Informative);
409 /// \brief Create a new result type chunk.
410 static Chunk CreateResultType(const char *ResultType);
412 /// \brief Create a new current-parameter chunk.
413 static Chunk CreateCurrentParameter(const char *CurrentParameter);
417 /// \brief The number of chunks stored in this string.
420 /// \brief The priority of this code-completion string.
421 unsigned Priority : 30;
423 /// \brief The availability of this code-completion result.
424 unsigned Availability : 2;
426 CodeCompletionString(const CodeCompletionString &); // DO NOT IMPLEMENT
427 CodeCompletionString &operator=(const CodeCompletionString &); // DITTO
429 CodeCompletionString(const Chunk *Chunks, unsigned NumChunks,
430 unsigned Priority, CXAvailabilityKind Availability);
431 ~CodeCompletionString() { }
433 friend class CodeCompletionBuilder;
434 friend class CodeCompletionResult;
437 typedef const Chunk *iterator;
438 iterator begin() const { return reinterpret_cast<const Chunk *>(this + 1); }
439 iterator end() const { return begin() + NumChunks; }
440 bool empty() const { return NumChunks == 0; }
441 unsigned size() const { return NumChunks; }
443 const Chunk &operator[](unsigned I) const {
444 assert(I < size() && "Chunk index out-of-range");
448 /// \brief Returns the text in the TypedText chunk.
449 const char *getTypedText() const;
451 /// \brief Retrieve the priority of this code completion result.
452 unsigned getPriority() const { return Priority; }
454 /// \brief Reteirve the availability of this code completion result.
455 unsigned getAvailability() const { return Availability; }
457 /// \brief Retrieve a string representation of the code completion string,
458 /// which is mainly useful for debugging.
459 std::string getAsString() const;
462 /// \brief An allocator used specifically for the purpose of code completion.
463 class CodeCompletionAllocator : public llvm::BumpPtrAllocator {
465 /// \brief Copy the given string into this allocator.
466 const char *CopyString(llvm::StringRef String);
468 /// \brief Copy the given string into this allocator.
469 const char *CopyString(llvm::Twine String);
471 // \brief Copy the given string into this allocator.
472 const char *CopyString(const char *String) {
473 return CopyString(llvm::StringRef(String));
476 /// \brief Copy the given string into this allocator.
477 const char *CopyString(const std::string &String) {
478 return CopyString(llvm::StringRef(String));
482 /// \brief A builder class used to construct new code-completion strings.
483 class CodeCompletionBuilder {
485 typedef CodeCompletionString::Chunk Chunk;
488 CodeCompletionAllocator &Allocator;
490 CXAvailabilityKind Availability;
492 /// \brief The chunks stored in this string.
493 llvm::SmallVector<Chunk, 4> Chunks;
496 CodeCompletionBuilder(CodeCompletionAllocator &Allocator)
497 : Allocator(Allocator), Priority(0), Availability(CXAvailability_Available){
500 CodeCompletionBuilder(CodeCompletionAllocator &Allocator,
501 unsigned Priority, CXAvailabilityKind Availability)
502 : Allocator(Allocator), Priority(Priority), Availability(Availability) { }
504 /// \brief Retrieve the allocator into which the code completion
505 /// strings should be allocated.
506 CodeCompletionAllocator &getAllocator() const { return Allocator; }
508 /// \brief Take the resulting completion string.
510 /// This operation can only be performed once.
511 CodeCompletionString *TakeString();
513 /// \brief Add a new typed-text chunk.
514 void AddTypedTextChunk(const char *Text) {
515 Chunks.push_back(Chunk(CodeCompletionString::CK_TypedText, Text));
518 /// \brief Add a new text chunk.
519 void AddTextChunk(const char *Text) {
520 Chunks.push_back(Chunk::CreateText(Text));
523 /// \brief Add a new optional chunk.
524 void AddOptionalChunk(CodeCompletionString *Optional) {
525 Chunks.push_back(Chunk::CreateOptional(Optional));
528 /// \brief Add a new placeholder chunk.
529 void AddPlaceholderChunk(const char *Placeholder) {
530 Chunks.push_back(Chunk::CreatePlaceholder(Placeholder));
533 /// \brief Add a new informative chunk.
534 void AddInformativeChunk(const char *Text) {
535 Chunks.push_back(Chunk::CreateInformative(Text));
538 /// \brief Add a new result-type chunk.
539 void AddResultTypeChunk(const char *ResultType) {
540 Chunks.push_back(Chunk::CreateResultType(ResultType));
543 /// \brief Add a new current-parameter chunk.
544 void AddCurrentParameterChunk(const char *CurrentParameter) {
545 Chunks.push_back(Chunk::CreateCurrentParameter(CurrentParameter));
548 /// \brief Add a new chunk.
549 void AddChunk(Chunk C) { Chunks.push_back(C); }
552 /// \brief Captures a result of code completion.
553 class CodeCompletionResult {
555 /// \brief Describes the kind of result generated.
557 RK_Declaration = 0, //< Refers to a declaration
558 RK_Keyword, //< Refers to a keyword or symbol.
559 RK_Macro, //< Refers to a macro
560 RK_Pattern //< Refers to a precomputed pattern.
563 /// \brief The kind of result stored here.
567 /// \brief When Kind == RK_Declaration, the declaration we are referring
569 NamedDecl *Declaration;
571 /// \brief When Kind == RK_Keyword, the string representing the keyword
572 /// or symbol's spelling.
575 /// \brief When Kind == RK_Pattern, the code-completion string that
576 /// describes the completion text to insert.
577 CodeCompletionString *Pattern;
579 /// \brief When Kind == RK_Macro, the identifier that refers to a macro.
580 IdentifierInfo *Macro;
583 /// \brief The priority of this particular code-completion result.
586 /// \brief The cursor kind that describes this result.
587 CXCursorKind CursorKind;
589 /// \brief The availability of this result.
590 CXAvailabilityKind Availability;
592 /// \brief Specifies which parameter (of a function, Objective-C method,
593 /// macro, etc.) we should start with when formatting the result.
594 unsigned StartParameter;
596 /// \brief Whether this result is hidden by another name.
599 /// \brief Whether this result was found via lookup into a base class.
600 bool QualifierIsInformative : 1;
602 /// \brief Whether this declaration is the beginning of a
603 /// nested-name-specifier and, therefore, should be followed by '::'.
604 bool StartsNestedNameSpecifier : 1;
606 /// \brief Whether all parameters (of a function, Objective-C
607 /// method, etc.) should be considered "informative".
608 bool AllParametersAreInformative : 1;
610 /// \brief Whether we're completing a declaration of the given entity,
611 /// rather than a use of that entity.
612 bool DeclaringEntity : 1;
614 /// \brief If the result should have a nested-name-specifier, this is it.
615 /// When \c QualifierIsInformative, the nested-name-specifier is
616 /// informative rather than required.
617 NestedNameSpecifier *Qualifier;
619 /// \brief Build a result that refers to a declaration.
620 CodeCompletionResult(NamedDecl *Declaration,
621 NestedNameSpecifier *Qualifier = 0,
622 bool QualifierIsInformative = false)
623 : Kind(RK_Declaration), Declaration(Declaration),
624 Priority(getPriorityFromDecl(Declaration)),
625 Availability(CXAvailability_Available), StartParameter(0),
626 Hidden(false), QualifierIsInformative(QualifierIsInformative),
627 StartsNestedNameSpecifier(false), AllParametersAreInformative(false),
628 DeclaringEntity(false), Qualifier(Qualifier) {
629 computeCursorKindAndAvailability();
632 /// \brief Build a result that refers to a keyword or symbol.
633 CodeCompletionResult(const char *Keyword, unsigned Priority = CCP_Keyword)
634 : Kind(RK_Keyword), Keyword(Keyword), Priority(Priority),
635 Availability(CXAvailability_Available),
636 StartParameter(0), Hidden(false), QualifierIsInformative(0),
637 StartsNestedNameSpecifier(false), AllParametersAreInformative(false),
638 DeclaringEntity(false), Qualifier(0) {
639 computeCursorKindAndAvailability();
642 /// \brief Build a result that refers to a macro.
643 CodeCompletionResult(IdentifierInfo *Macro, unsigned Priority = CCP_Macro)
644 : Kind(RK_Macro), Macro(Macro), Priority(Priority),
645 Availability(CXAvailability_Available), StartParameter(0),
646 Hidden(false), QualifierIsInformative(0),
647 StartsNestedNameSpecifier(false), AllParametersAreInformative(false),
648 DeclaringEntity(false), Qualifier(0) {
649 computeCursorKindAndAvailability();
652 /// \brief Build a result that refers to a pattern.
653 CodeCompletionResult(CodeCompletionString *Pattern,
654 unsigned Priority = CCP_CodePattern,
655 CXCursorKind CursorKind = CXCursor_NotImplemented,
656 CXAvailabilityKind Availability = CXAvailability_Available)
657 : Kind(RK_Pattern), Pattern(Pattern), Priority(Priority),
658 CursorKind(CursorKind), Availability(Availability), StartParameter(0),
659 Hidden(false), QualifierIsInformative(0),
660 StartsNestedNameSpecifier(false), AllParametersAreInformative(false),
661 DeclaringEntity(false), Qualifier(0)
665 /// \brief Retrieve the declaration stored in this result.
666 NamedDecl *getDeclaration() const {
667 assert(Kind == RK_Declaration && "Not a declaration result");
671 /// \brief Retrieve the keyword stored in this result.
672 const char *getKeyword() const {
673 assert(Kind == RK_Keyword && "Not a keyword result");
677 /// \brief Create a new code-completion string that describes how to insert
678 /// this result into a program.
680 /// \param S The semantic analysis that created the result.
682 /// \param Allocator The allocator that will be used to allocate the
684 CodeCompletionString *CreateCodeCompletionString(Sema &S,
685 CodeCompletionAllocator &Allocator);
687 /// \brief Determine a base priority for the given declaration.
688 static unsigned getPriorityFromDecl(NamedDecl *ND);
691 void computeCursorKindAndAvailability();
694 bool operator<(const CodeCompletionResult &X, const CodeCompletionResult &Y);
696 inline bool operator>(const CodeCompletionResult &X,
697 const CodeCompletionResult &Y) {
701 inline bool operator<=(const CodeCompletionResult &X,
702 const CodeCompletionResult &Y) {
706 inline bool operator>=(const CodeCompletionResult &X,
707 const CodeCompletionResult &Y) {
712 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
713 const CodeCompletionString &CCS);
715 /// \brief Abstract interface for a consumer of code-completion
717 class CodeCompleteConsumer {
719 /// \brief Whether to include macros in the code-completion results.
722 /// \brief Whether to include code patterns (such as for loops) within
723 /// the completion results.
724 bool IncludeCodePatterns;
726 /// \brief Whether to include global (top-level) declarations and names in
727 /// the completion results.
730 /// \brief Whether the output format for the code-completion consumer is
735 class OverloadCandidate {
737 /// \brief Describes the type of overload candidate.
739 /// \brief The candidate is a function declaration.
741 /// \brief The candidate is a function template.
743 /// \brief The "candidate" is actually a variable, expression, or block
744 /// for which we only have a function prototype.
749 /// \brief The kind of overload candidate.
753 /// \brief The function overload candidate, available when
754 /// Kind == CK_Function.
755 FunctionDecl *Function;
757 /// \brief The function template overload candidate, available when
758 /// Kind == CK_FunctionTemplate.
759 FunctionTemplateDecl *FunctionTemplate;
761 /// \brief The function type that describes the entity being called,
762 /// when Kind == CK_FunctionType.
763 const FunctionType *Type;
767 OverloadCandidate(FunctionDecl *Function)
768 : Kind(CK_Function), Function(Function) { }
770 OverloadCandidate(FunctionTemplateDecl *FunctionTemplateDecl)
771 : Kind(CK_FunctionTemplate), FunctionTemplate(FunctionTemplateDecl) { }
773 OverloadCandidate(const FunctionType *Type)
774 : Kind(CK_FunctionType), Type(Type) { }
776 /// \brief Determine the kind of overload candidate.
777 CandidateKind getKind() const { return Kind; }
779 /// \brief Retrieve the function overload candidate or the templated
780 /// function declaration for a function template.
781 FunctionDecl *getFunction() const;
783 /// \brief Retrieve the function template overload candidate.
784 FunctionTemplateDecl *getFunctionTemplate() const {
785 assert(getKind() == CK_FunctionTemplate && "Not a function template");
786 return FunctionTemplate;
789 /// \brief Retrieve the function type of the entity, regardless of how the
790 /// function is stored.
791 const FunctionType *getFunctionType() const;
793 /// \brief Create a new code-completion string that describes the function
794 /// signature of this overload candidate.
795 CodeCompletionString *CreateSignatureString(unsigned CurrentArg,
797 CodeCompletionAllocator &Allocator) const;
800 CodeCompleteConsumer() : IncludeMacros(false), IncludeCodePatterns(false),
801 IncludeGlobals(true), OutputIsBinary(false) { }
803 CodeCompleteConsumer(bool IncludeMacros, bool IncludeCodePatterns,
804 bool IncludeGlobals, bool OutputIsBinary)
805 : IncludeMacros(IncludeMacros), IncludeCodePatterns(IncludeCodePatterns),
806 IncludeGlobals(IncludeGlobals), OutputIsBinary(OutputIsBinary) { }
808 /// \brief Whether the code-completion consumer wants to see macros.
809 bool includeMacros() const { return IncludeMacros; }
811 /// \brief Whether the code-completion consumer wants to see code patterns.
812 bool includeCodePatterns() const { return IncludeCodePatterns; }
814 /// \brief Whether to include global (top-level) declaration results.
815 bool includeGlobals() const { return IncludeGlobals; }
817 /// \brief Determine whether the output of this consumer is binary.
818 bool isOutputBinary() const { return OutputIsBinary; }
820 /// \brief Deregisters and destroys this code-completion consumer.
821 virtual ~CodeCompleteConsumer();
823 /// \name Code-completion callbacks
825 /// \brief Process the finalized code-completion results.
826 virtual void ProcessCodeCompleteResults(Sema &S,
827 CodeCompletionContext Context,
828 CodeCompletionResult *Results,
829 unsigned NumResults) { }
831 /// \param S the semantic-analyzer object for which code-completion is being
834 /// \param CurrentArg the index of the current argument.
836 /// \param Candidates an array of overload candidates.
838 /// \param NumCandidates the number of overload candidates
839 virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
840 OverloadCandidate *Candidates,
841 unsigned NumCandidates) { }
844 /// \brief Retrieve the allocator that will be used to allocate
845 /// code completion strings.
846 virtual CodeCompletionAllocator &getAllocator() = 0;
849 /// \brief A simple code-completion consumer that prints the results it
850 /// receives in a simple format.
851 class PrintingCodeCompleteConsumer : public CodeCompleteConsumer {
852 /// \brief The raw output stream.
853 llvm::raw_ostream &OS;
855 CodeCompletionAllocator Allocator;
858 /// \brief Create a new printing code-completion consumer that prints its
859 /// results to the given raw output stream.
860 PrintingCodeCompleteConsumer(bool IncludeMacros, bool IncludeCodePatterns,
862 llvm::raw_ostream &OS)
863 : CodeCompleteConsumer(IncludeMacros, IncludeCodePatterns, IncludeGlobals,
866 /// \brief Prints the finalized code-completion results.
867 virtual void ProcessCodeCompleteResults(Sema &S,
868 CodeCompletionContext Context,
869 CodeCompletionResult *Results,
870 unsigned NumResults);
872 virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
873 OverloadCandidate *Candidates,
874 unsigned NumCandidates);
876 virtual CodeCompletionAllocator &getAllocator() { return Allocator; }
879 } // end namespace clang
881 #endif // LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H