diff options
Diffstat (limited to 'include/clang/Sema/CodeCompleteConsumer.h')
-rw-r--r-- | include/clang/Sema/CodeCompleteConsumer.h | 469 |
1 files changed, 276 insertions, 193 deletions
diff --git a/include/clang/Sema/CodeCompleteConsumer.h b/include/clang/Sema/CodeCompleteConsumer.h index 9e2d60d3e015..fe9bed5c8693 100644 --- a/include/clang/Sema/CodeCompleteConsumer.h +++ b/include/clang/Sema/CodeCompleteConsumer.h @@ -24,14 +24,14 @@ namespace clang { class Decl; - + /// \brief Default priority values for code-completion results based /// on their kind. enum { /// \brief Priority for the next initialization in a constructor initializer /// list. CCP_NextInitializer = 7, - /// \brief Priority for an enumeration constant inside a switch whose + /// \brief Priority for an enumeration constant inside a switch whose /// condition is of the enumeration type. CCP_EnumInCase = 7, /// \brief Priority for a send-to-super completion. @@ -59,7 +59,7 @@ enum { /// \brief Priority for a result that isn't likely to be what the user wants, /// but is included for completeness. CCP_Unlikely = 80, - + /// \brief Priority for the Objective-C "_cmd" implicit parameter. CCP_ObjC_cmd = CCP_Unlikely }; @@ -76,15 +76,15 @@ enum { /// of the current method, which might imply that some kind of delegation /// is occurring. CCD_SelectorMatch = -3, - + /// \brief Adjustment to the "bool" type in Objective-C, where the typedef /// "BOOL" is preferred. CCD_bool_in_ObjC = 1, - + /// \brief Adjustment for KVC code pattern priorities when it doesn't look /// like the CCD_ProbablyNotObjCCollection = 15, - + /// \brief An Objective-C method being used as a property. CCD_MethodAsProperty = 2 }; @@ -114,14 +114,14 @@ enum SimplifiedTypeClass { STC_Record, STC_Void }; - + /// \brief Determine the simplified type class of the given canonical type. SimplifiedTypeClass getSimplifiedTypeClass(CanQualType T); - + /// \brief Determine the type that this declaration will have if it is used /// as a type or in an expression. QualType getDeclUsageType(ASTContext &C, NamedDecl *ND); - + /// \brief Determine the priority to be given to a macro code completion result /// with the given name. /// @@ -131,14 +131,14 @@ QualType getDeclUsageType(ASTContext &C, NamedDecl *ND); /// /// \param PreferredTypeIsPointer Whether the preferred type for the context /// of this macro is a pointer type. -unsigned getMacroUsagePriority(StringRef MacroName, +unsigned getMacroUsagePriority(StringRef MacroName, const LangOptions &LangOpts, bool PreferredTypeIsPointer = false); /// \brief Determine the libclang cursor kind associated with the given /// declaration. CXCursorKind getCursorKindForDecl(Decl *D); - + class FunctionDecl; class FunctionType; class FunctionTemplateDecl; @@ -182,22 +182,22 @@ public: /// \brief Code completion occurred on the right-hand side of a member /// access expression using the dot operator. /// - /// The results of this completion are the members of the type being - /// accessed. The type itself is available via + /// The results of this completion are the members of the type being + /// accessed. The type itself is available via /// \c CodeCompletionContext::getType(). CCC_DotMemberAccess, /// \brief Code completion occurred on the right-hand side of a member /// access expression using the arrow operator. /// - /// The results of this completion are the members of the type being - /// accessed. The type itself is available via + /// The results of this completion are the members of the type being + /// accessed. The type itself is available via /// \c CodeCompletionContext::getType(). CCC_ArrowMemberAccess, /// \brief Code completion occurred on the right-hand side of an Objective-C /// property access expression. /// - /// The results of this completion are the members of the type being - /// accessed. The type itself is available via + /// The results of this completion are the members of the type being + /// accessed. The type itself is available via /// \c CodeCompletionContext::getType(). CCC_ObjCPropertyAccess, /// \brief Code completion occurred after the "enum" keyword, to indicate @@ -228,7 +228,7 @@ public: CCC_MacroNameUse, /// \brief Code completion occurred within a preprocessor expression. CCC_PreprocessorExpression, - /// \brief Code completion occurred where a preprocessor directive is + /// \brief Code completion occurred where a preprocessor directive is /// expected. CCC_PreprocessorDirective, /// \brief Code completion occurred in a context where natural language is @@ -246,14 +246,14 @@ public: CCC_ParenthesizedExpression, /// \brief Code completion where an Objective-C instance message is expcted. CCC_ObjCInstanceMessage, - /// \brief Code completion where an Objective-C class message is expected. + /// \brief Code completion where an Objective-C class message is expected. CCC_ObjCClassMessage, /// \brief Code completion where the name of an Objective-C class is /// expected. CCC_ObjCInterfaceName, /// \brief Code completion where an Objective-C category name is expected. CCC_ObjCCategoryName, - /// \brief An unknown context, in which we are recovering from a parsing + /// \brief An unknown context, in which we are recovering from a parsing /// error and don't know which completions we should give. CCC_Recovery }; @@ -264,27 +264,27 @@ private: /// \brief The type that would prefer to see at this point (e.g., the type /// of an initializer or function parameter). QualType PreferredType; - + /// \brief The type of the base object in a member access expression. QualType BaseType; - + /// \brief The identifiers for Objective-C selector parts. IdentifierInfo **SelIdents; - + /// \brief The number of Objective-C selector parts. unsigned NumSelIdents; - + public: /// \brief Construct a new code-completion context of the given kind. - CodeCompletionContext(enum Kind Kind) : Kind(Kind), SelIdents(NULL), + CodeCompletionContext(enum Kind Kind) : Kind(Kind), SelIdents(NULL), NumSelIdents(0) { } - + /// \brief Construct a new code-completion context of the given kind. CodeCompletionContext(enum Kind Kind, QualType T, IdentifierInfo **SelIdents = NULL, unsigned NumSelIdents = 0) : Kind(Kind), SelIdents(SelIdents), - NumSelIdents(NumSelIdents) { + NumSelIdents(NumSelIdents) { if (Kind == CCC_DotMemberAccess || Kind == CCC_ArrowMemberAccess || Kind == CCC_ObjCPropertyAccess || Kind == CCC_ObjCClassMessage || Kind == CCC_ObjCInstanceMessage) @@ -292,22 +292,22 @@ public: else PreferredType = T; } - + /// \brief Retrieve the kind of code-completion context. enum Kind getKind() const { return Kind; } - + /// \brief Retrieve the type that this expression would prefer to have, e.g., /// if the expression is a variable initializer or a function argument, the /// type of the corresponding variable or function parameter. QualType getPreferredType() const { return PreferredType; } - - /// \brief Retrieve the type of the base object in a member-access + + /// \brief Retrieve the type of the base object in a member-access /// expression. QualType getBaseType() const { return BaseType; } - + /// \brief Retrieve the Objective-C selector identifiers. IdentifierInfo **getSelIdents() const { return SelIdents; } - + /// \brief Retrieve the number of Objective-C selector identifiers. unsigned getNumSelIdents() const { return NumSelIdents; } @@ -320,10 +320,10 @@ public: /// \brief A "string" used to describe how code completion can /// be performed for an entity. /// -/// A code completion string typically shows how a particular entity can be +/// A code completion string typically shows how a particular entity can be /// used. For example, the code completion string for a function would show -/// the syntax to call it, including the parentheses, placeholders for the -/// arguments, etc. +/// the syntax to call it, including the parentheses, placeholders for the +/// arguments, etc. class CodeCompletionString { public: /// \brief The different kinds of "chunks" that can occur within a code @@ -340,7 +340,7 @@ public: /// an optional code completion string that describes the default arguments /// in a function call. CK_Optional, - /// \brief A string that acts as a placeholder for, e.g., a function + /// \brief A string that acts as a placeholder for, e.g., a function /// call argument. CK_Placeholder, /// \brief A piece of text that describes something about the result but @@ -383,30 +383,30 @@ public: /// platform). CK_VerticalSpace }; - + /// \brief One piece of the code completion string. struct Chunk { - /// \brief The kind of data stored in this piece of the code completion + /// \brief The kind of data stored in this piece of the code completion /// string. ChunkKind Kind; - + union { /// \brief The text string associated with a CK_Text, CK_Placeholder, /// CK_Informative, or CK_Comma chunk. - /// The string is owned by the chunk and will be deallocated + /// The string is owned by the chunk and will be deallocated /// (with delete[]) when the chunk is destroyed. const char *Text; - + /// \brief The code completion string associated with a CK_Optional chunk. /// The optional code completion string is owned by the chunk, and will /// be deallocated (with delete) when the chunk is destroyed. CodeCompletionString *Optional; }; - + Chunk() : Kind(CK_Text), Text(0) { } - - Chunk(ChunkKind Kind, const char *Text = ""); - + + explicit Chunk(ChunkKind Kind, const char *Text = ""); + /// \brief Create a new text chunk. static Chunk CreateText(const char *Text); @@ -425,49 +425,56 @@ public: /// \brief Create a new current-parameter chunk. static Chunk CreateCurrentParameter(const char *CurrentParameter); }; - + private: /// \brief The number of chunks stored in this string. unsigned NumChunks : 16; - + /// \brief The number of annotations for this code-completion result. unsigned NumAnnotations : 16; /// \brief The priority of this code-completion string. - unsigned Priority : 30; - + unsigned Priority : 16; + /// \brief The availability of this code-completion result. unsigned Availability : 2; + /// \brief The kind of the parent context. + unsigned ParentKind : 14; + + /// \brief The name of the parent context. + StringRef ParentName; + CodeCompletionString(const CodeCompletionString &); // DO NOT IMPLEMENT CodeCompletionString &operator=(const CodeCompletionString &); // DITTO - + CodeCompletionString(const Chunk *Chunks, unsigned NumChunks, unsigned Priority, CXAvailabilityKind Availability, - const char **Annotations, unsigned NumAnnotations); + const char **Annotations, unsigned NumAnnotations, + CXCursorKind ParentKind, StringRef ParentName); ~CodeCompletionString() { } - + friend class CodeCompletionBuilder; friend class CodeCompletionResult; - + public: typedef const Chunk *iterator; iterator begin() const { return reinterpret_cast<const Chunk *>(this + 1); } iterator end() const { return begin() + NumChunks; } bool empty() const { return NumChunks == 0; } unsigned size() const { return NumChunks; } - + const Chunk &operator[](unsigned I) const { assert(I < size() && "Chunk index out-of-range"); return begin()[I]; } - + /// \brief Returns the text in the TypedText chunk. const char *getTypedText() const; /// \brief Retrieve the priority of this code completion result. unsigned getPriority() const { return Priority; } - + /// \brief Retrieve the availability of this code completion result. unsigned getAvailability() const { return Availability; } @@ -476,106 +483,156 @@ public: /// \brief Retrieve the annotation string specified by \c AnnotationNr. const char *getAnnotation(unsigned AnnotationNr) const; + + /// \brief Retrieve parent context's cursor kind. + CXCursorKind getParentContextKind() const { + return (CXCursorKind)ParentKind; + } + + /// \brief Retrieve the name of the parent context. + StringRef getParentContextName() const { + return ParentName; + } /// \brief Retrieve a string representation of the code completion string, /// which is mainly useful for debugging. - std::string getAsString() const; + std::string getAsString() const; }; /// \brief An allocator used specifically for the purpose of code completion. -class CodeCompletionAllocator : public llvm::BumpPtrAllocator { +class CodeCompletionAllocator : public llvm::BumpPtrAllocator { public: /// \brief Copy the given string into this allocator. const char *CopyString(StringRef String); /// \brief Copy the given string into this allocator. const char *CopyString(Twine String); - + // \brief Copy the given string into this allocator. const char *CopyString(const char *String) { return CopyString(StringRef(String)); } - + /// \brief Copy the given string into this allocator. const char *CopyString(const std::string &String) { return CopyString(StringRef(String)); } }; - + +/// \brief Allocator for a cached set of global code completions. +class GlobalCodeCompletionAllocator + : public CodeCompletionAllocator, + public RefCountedBase<GlobalCodeCompletionAllocator> +{ + +}; + +class CodeCompletionTUInfo { + llvm::DenseMap<DeclContext *, StringRef> ParentNames; + IntrusiveRefCntPtr<GlobalCodeCompletionAllocator> AllocatorRef; + +public: + explicit CodeCompletionTUInfo( + IntrusiveRefCntPtr<GlobalCodeCompletionAllocator> Allocator) + : AllocatorRef(Allocator) { } + + IntrusiveRefCntPtr<GlobalCodeCompletionAllocator> getAllocatorRef() const { + return AllocatorRef; + } + CodeCompletionAllocator &getAllocator() const { + assert(AllocatorRef); + return *AllocatorRef; + } + + StringRef getParentName(DeclContext *DC); +}; + +} // end namespace clang + +namespace llvm { + template <> struct isPodLike<clang::CodeCompletionString::Chunk> { + static const bool value = true; + }; +} + +namespace clang { + /// \brief A builder class used to construct new code-completion strings. class CodeCompletionBuilder { -public: +public: typedef CodeCompletionString::Chunk Chunk; - + private: CodeCompletionAllocator &Allocator; + CodeCompletionTUInfo &CCTUInfo; unsigned Priority; CXAvailabilityKind Availability; + CXCursorKind ParentKind; + StringRef ParentName; /// \brief The chunks stored in this string. SmallVector<Chunk, 4> Chunks; SmallVector<const char *, 2> Annotations; - + public: - CodeCompletionBuilder(CodeCompletionAllocator &Allocator) - : Allocator(Allocator), Priority(0), Availability(CXAvailability_Available){ - } - CodeCompletionBuilder(CodeCompletionAllocator &Allocator, - unsigned Priority, CXAvailabilityKind Availability) - : Allocator(Allocator), Priority(Priority), Availability(Availability) { } + CodeCompletionTUInfo &CCTUInfo) + : Allocator(Allocator), CCTUInfo(CCTUInfo), + Priority(0), Availability(CXAvailability_Available), + ParentKind(CXCursor_NotImplemented) { } + + CodeCompletionBuilder(CodeCompletionAllocator &Allocator, + CodeCompletionTUInfo &CCTUInfo, + unsigned Priority, CXAvailabilityKind Availability) + : Allocator(Allocator), CCTUInfo(CCTUInfo), + Priority(Priority), Availability(Availability), + ParentKind(CXCursor_NotImplemented) { } /// \brief Retrieve the allocator into which the code completion /// strings should be allocated. CodeCompletionAllocator &getAllocator() const { return Allocator; } - - /// \brief Take the resulting completion string. + + CodeCompletionTUInfo &getCodeCompletionTUInfo() const { return CCTUInfo; } + + /// \brief Take the resulting completion string. /// /// This operation can only be performed once. CodeCompletionString *TakeString(); - + /// \brief Add a new typed-text chunk. - void AddTypedTextChunk(const char *Text) { - Chunks.push_back(Chunk(CodeCompletionString::CK_TypedText, Text)); - } - + void AddTypedTextChunk(const char *Text); + /// \brief Add a new text chunk. - void AddTextChunk(const char *Text) { - Chunks.push_back(Chunk::CreateText(Text)); - } + void AddTextChunk(const char *Text); /// \brief Add a new optional chunk. - void AddOptionalChunk(CodeCompletionString *Optional) { - Chunks.push_back(Chunk::CreateOptional(Optional)); - } - + void AddOptionalChunk(CodeCompletionString *Optional); + /// \brief Add a new placeholder chunk. - void AddPlaceholderChunk(const char *Placeholder) { - Chunks.push_back(Chunk::CreatePlaceholder(Placeholder)); - } - + void AddPlaceholderChunk(const char *Placeholder); + /// \brief Add a new informative chunk. - void AddInformativeChunk(const char *Text) { - Chunks.push_back(Chunk::CreateInformative(Text)); - } - + void AddInformativeChunk(const char *Text); + /// \brief Add a new result-type chunk. - void AddResultTypeChunk(const char *ResultType) { - Chunks.push_back(Chunk::CreateResultType(ResultType)); - } - + void AddResultTypeChunk(const char *ResultType); + /// \brief Add a new current-parameter chunk. - void AddCurrentParameterChunk(const char *CurrentParameter) { - Chunks.push_back(Chunk::CreateCurrentParameter(CurrentParameter)); - } - + void AddCurrentParameterChunk(const char *CurrentParameter); + /// \brief Add a new chunk. - void AddChunk(Chunk C) { Chunks.push_back(C); } + void AddChunk(CodeCompletionString::ChunkKind CK, const char *Text = ""); void AddAnnotation(const char *A) { Annotations.push_back(A); } -}; + + /// \brief Add the parent context information to this code completion. + void addParentContext(DeclContext *DC); + CXCursorKind getParentKind() const { return ParentKind; } + StringRef getParentName() const { return ParentName; } +}; + /// \brief Captures a result of code completion. class CodeCompletionResult { public: @@ -586,23 +643,23 @@ public: RK_Macro, //< Refers to a macro RK_Pattern //< Refers to a precomputed pattern. }; - + /// \brief The kind of result stored here. ResultKind Kind; - + + /// \brief When Kind == RK_Declaration or RK_Pattern, the declaration we are + /// referring to. In the latter case, the declaration might be NULL. + NamedDecl *Declaration; + union { - /// \brief When Kind == RK_Declaration, the declaration we are referring - /// to. - NamedDecl *Declaration; - - /// \brief When Kind == RK_Keyword, the string representing the keyword + /// \brief When Kind == RK_Keyword, the string representing the keyword /// or symbol's spelling. const char *Keyword; - + /// \brief When Kind == RK_Pattern, the code-completion string that /// describes the completion text to insert. CodeCompletionString *Pattern; - + /// \brief When Kind == RK_Macro, the identifier that refers to a macro. IdentifierInfo *Macro; }; @@ -612,21 +669,21 @@ public: /// \brief The cursor kind that describes this result. CXCursorKind CursorKind; - + /// \brief The availability of this result. CXAvailabilityKind Availability; - + /// \brief Specifies which parameter (of a function, Objective-C method, /// macro, etc.) we should start with when formatting the result. unsigned StartParameter; - + /// \brief Whether this result is hidden by another name. bool Hidden : 1; - + /// \brief Whether this result was found via lookup into a base class. bool QualifierIsInformative : 1; - - /// \brief Whether this declaration is the beginning of a + + /// \brief Whether this declaration is the beginning of a /// nested-name-specifier and, therefore, should be followed by '::'. bool StartsNestedNameSpecifier : 1; @@ -637,43 +694,43 @@ public: /// \brief Whether we're completing a declaration of the given entity, /// rather than a use of that entity. bool DeclaringEntity : 1; - + /// \brief If the result should have a nested-name-specifier, this is it. - /// When \c QualifierIsInformative, the nested-name-specifier is + /// When \c QualifierIsInformative, the nested-name-specifier is /// informative rather than required. NestedNameSpecifier *Qualifier; - + /// \brief Build a result that refers to a declaration. - CodeCompletionResult(NamedDecl *Declaration, + CodeCompletionResult(NamedDecl *Declaration, NestedNameSpecifier *Qualifier = 0, bool QualifierIsInformative = false, bool Accessible = true) - : Kind(RK_Declaration), Declaration(Declaration), - Priority(getPriorityFromDecl(Declaration)), - Availability(CXAvailability_Available), StartParameter(0), + : Kind(RK_Declaration), Declaration(Declaration), + Priority(getPriorityFromDecl(Declaration)), + Availability(CXAvailability_Available), StartParameter(0), Hidden(false), QualifierIsInformative(QualifierIsInformative), StartsNestedNameSpecifier(false), AllParametersAreInformative(false), - DeclaringEntity(false), Qualifier(Qualifier) { + DeclaringEntity(false), Qualifier(Qualifier) { computeCursorKindAndAvailability(Accessible); } - + /// \brief Build a result that refers to a keyword or symbol. CodeCompletionResult(const char *Keyword, unsigned Priority = CCP_Keyword) - : Kind(RK_Keyword), Keyword(Keyword), Priority(Priority), - Availability(CXAvailability_Available), - StartParameter(0), Hidden(false), QualifierIsInformative(0), + : Kind(RK_Keyword), Declaration(0), Keyword(Keyword), Priority(Priority), + Availability(CXAvailability_Available), + StartParameter(0), Hidden(false), QualifierIsInformative(0), StartsNestedNameSpecifier(false), AllParametersAreInformative(false), DeclaringEntity(false), Qualifier(0) { computeCursorKindAndAvailability(); } - + /// \brief Build a result that refers to a macro. CodeCompletionResult(IdentifierInfo *Macro, unsigned Priority = CCP_Macro) - : Kind(RK_Macro), Macro(Macro), Priority(Priority), - Availability(CXAvailability_Available), StartParameter(0), - Hidden(false), QualifierIsInformative(0), + : Kind(RK_Macro), Declaration(0), Macro(Macro), Priority(Priority), + Availability(CXAvailability_Available), StartParameter(0), + Hidden(false), QualifierIsInformative(0), StartsNestedNameSpecifier(false), AllParametersAreInformative(false), - DeclaringEntity(false), Qualifier(0) { + DeclaringEntity(false), Qualifier(0) { computeCursorKindAndAvailability(); } @@ -681,27 +738,40 @@ public: CodeCompletionResult(CodeCompletionString *Pattern, unsigned Priority = CCP_CodePattern, CXCursorKind CursorKind = CXCursor_NotImplemented, - CXAvailabilityKind Availability = CXAvailability_Available) - : Kind(RK_Pattern), Pattern(Pattern), Priority(Priority), - CursorKind(CursorKind), Availability(Availability), StartParameter(0), - Hidden(false), QualifierIsInformative(0), - StartsNestedNameSpecifier(false), AllParametersAreInformative(false), - DeclaringEntity(false), Qualifier(0) - { + CXAvailabilityKind Availability = CXAvailability_Available, + NamedDecl *D = 0) + : Kind(RK_Pattern), Declaration(D), Pattern(Pattern), Priority(Priority), + CursorKind(CursorKind), Availability(Availability), StartParameter(0), + Hidden(false), QualifierIsInformative(0), + StartsNestedNameSpecifier(false), AllParametersAreInformative(false), + DeclaringEntity(false), Qualifier(0) + { } - + + /// \brief Build a result that refers to a pattern with an associated + /// declaration. + CodeCompletionResult(CodeCompletionString *Pattern, NamedDecl *D, + unsigned Priority) + : Kind(RK_Pattern), Declaration(D), Pattern(Pattern), Priority(Priority), + Availability(CXAvailability_Available), StartParameter(0), + Hidden(false), QualifierIsInformative(false), + StartsNestedNameSpecifier(false), AllParametersAreInformative(false), + DeclaringEntity(false), Qualifier(0) { + computeCursorKindAndAvailability(); + } + /// \brief Retrieve the declaration stored in this result. NamedDecl *getDeclaration() const { assert(Kind == RK_Declaration && "Not a declaration result"); return Declaration; } - + /// \brief Retrieve the keyword stored in this result. const char *getKeyword() const { assert(Kind == RK_Keyword && "Not a keyword result"); return Keyword; } - + /// \brief Create a new code-completion string that describes how to insert /// this result into a program. /// @@ -710,37 +780,42 @@ public: /// \param Allocator The allocator that will be used to allocate the /// string itself. CodeCompletionString *CreateCodeCompletionString(Sema &S, - CodeCompletionAllocator &Allocator); - + CodeCompletionAllocator &Allocator, + CodeCompletionTUInfo &CCTUInfo); + CodeCompletionString *CreateCodeCompletionString(ASTContext &Ctx, + Preprocessor &PP, + CodeCompletionAllocator &Allocator, + CodeCompletionTUInfo &CCTUInfo); + /// \brief Determine a base priority for the given declaration. static unsigned getPriorityFromDecl(NamedDecl *ND); - + private: void computeCursorKindAndAvailability(bool Accessible = true); }; - + bool operator<(const CodeCompletionResult &X, const CodeCompletionResult &Y); - -inline bool operator>(const CodeCompletionResult &X, + +inline bool operator>(const CodeCompletionResult &X, const CodeCompletionResult &Y) { return Y < X; } - -inline bool operator<=(const CodeCompletionResult &X, + +inline bool operator<=(const CodeCompletionResult &X, const CodeCompletionResult &Y) { return !(Y < X); } -inline bool operator>=(const CodeCompletionResult &X, +inline bool operator>=(const CodeCompletionResult &X, const CodeCompletionResult &Y) { return !(X < Y); } - -raw_ostream &operator<<(raw_ostream &OS, + +raw_ostream &operator<<(raw_ostream &OS, const CodeCompletionString &CCS); -/// \brief Abstract interface for a consumer of code-completion +/// \brief Abstract interface for a consumer of code-completion /// information. class CodeCompleteConsumer { protected: @@ -750,15 +825,15 @@ protected: /// \brief Whether to include code patterns (such as for loops) within /// the completion results. bool IncludeCodePatterns; - + /// \brief Whether to include global (top-level) declarations and names in /// the completion results. bool IncludeGlobals; - + /// \brief Whether the output format for the code-completion consumer is /// binary. bool OutputIsBinary; - + public: class OverloadCandidate { public: @@ -772,25 +847,25 @@ public: /// for which we only have a function prototype. CK_FunctionType }; - + private: /// \brief The kind of overload candidate. CandidateKind Kind; - + union { - /// \brief The function overload candidate, available when + /// \brief The function overload candidate, available when /// Kind == CK_Function. FunctionDecl *Function; - + /// \brief The function template overload candidate, available when /// Kind == CK_FunctionTemplate. FunctionTemplateDecl *FunctionTemplate; - + /// \brief The function type that describes the entity being called, /// when Kind == CK_FunctionType. const FunctionType *Type; }; - + public: OverloadCandidate(FunctionDecl *Function) : Kind(CK_Function), Function(Function) { } @@ -803,55 +878,56 @@ public: /// \brief Determine the kind of overload candidate. CandidateKind getKind() const { return Kind; } - - /// \brief Retrieve the function overload candidate or the templated + + /// \brief Retrieve the function overload candidate or the templated /// function declaration for a function template. FunctionDecl *getFunction() const; - + /// \brief Retrieve the function template overload candidate. FunctionTemplateDecl *getFunctionTemplate() const { assert(getKind() == CK_FunctionTemplate && "Not a function template"); return FunctionTemplate; } - + /// \brief Retrieve the function type of the entity, regardless of how the /// function is stored. const FunctionType *getFunctionType() const; - + /// \brief Create a new code-completion string that describes the function /// signature of this overload candidate. - CodeCompletionString *CreateSignatureString(unsigned CurrentArg, + CodeCompletionString *CreateSignatureString(unsigned CurrentArg, Sema &S, - CodeCompletionAllocator &Allocator) const; + CodeCompletionAllocator &Allocator, + CodeCompletionTUInfo &CCTUInfo) const; }; - + CodeCompleteConsumer() : IncludeMacros(false), IncludeCodePatterns(false), IncludeGlobals(true), OutputIsBinary(false) { } - + CodeCompleteConsumer(bool IncludeMacros, bool IncludeCodePatterns, bool IncludeGlobals, bool OutputIsBinary) : IncludeMacros(IncludeMacros), IncludeCodePatterns(IncludeCodePatterns), IncludeGlobals(IncludeGlobals), OutputIsBinary(OutputIsBinary) { } - + /// \brief Whether the code-completion consumer wants to see macros. bool includeMacros() const { return IncludeMacros; } /// \brief Whether the code-completion consumer wants to see code patterns. bool includeCodePatterns() const { return IncludeCodePatterns; } - + /// \brief Whether to include global (top-level) declaration results. bool includeGlobals() const { return IncludeGlobals; } - + /// \brief Determine whether the output of this consumer is binary. bool isOutputBinary() const { return OutputIsBinary; } - + /// \brief Deregisters and destroys this code-completion consumer. virtual ~CodeCompleteConsumer(); /// \name Code-completion callbacks //@{ /// \brief Process the finalized code-completion results. - virtual void ProcessCodeCompleteResults(Sema &S, + virtual void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context, CodeCompletionResult *Results, unsigned NumResults) { } @@ -868,20 +944,22 @@ public: OverloadCandidate *Candidates, unsigned NumCandidates) { } //@} - + /// \brief Retrieve the allocator that will be used to allocate /// code completion strings. virtual CodeCompletionAllocator &getAllocator() = 0; + + virtual CodeCompletionTUInfo &getCodeCompletionTUInfo() = 0; }; -/// \brief A simple code-completion consumer that prints the results it +/// \brief A simple code-completion consumer that prints the results it /// receives in a simple format. class PrintingCodeCompleteConsumer : public CodeCompleteConsumer { /// \brief The raw output stream. raw_ostream &OS; - - CodeCompletionAllocator Allocator; - + + CodeCompletionTUInfo CCTUInfo; + public: /// \brief Create a new printing code-completion consumer that prints its /// results to the given raw output stream. @@ -889,21 +967,26 @@ public: bool IncludeGlobals, raw_ostream &OS) : CodeCompleteConsumer(IncludeMacros, IncludeCodePatterns, IncludeGlobals, - false), OS(OS) {} - + false), OS(OS), + CCTUInfo(new GlobalCodeCompletionAllocator) {} + /// \brief Prints the finalized code-completion results. - virtual void ProcessCodeCompleteResults(Sema &S, + virtual void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context, CodeCompletionResult *Results, unsigned NumResults); - + virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, OverloadCandidate *Candidates, - unsigned NumCandidates); - - virtual CodeCompletionAllocator &getAllocator() { return Allocator; } + unsigned NumCandidates); + + virtual CodeCompletionAllocator &getAllocator() { + return CCTUInfo.getAllocator(); + } + + virtual CodeCompletionTUInfo &getCodeCompletionTUInfo() { return CCTUInfo; } }; - + } // end namespace clang #endif // LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H |