1198092Srdivacky//===---- CodeCompleteConsumer.h - Code Completion Interface ----*- C++ -*-===// 2198092Srdivacky// 3198092Srdivacky// The LLVM Compiler Infrastructure 4198092Srdivacky// 5198092Srdivacky// This file is distributed under the University of Illinois Open Source 6198092Srdivacky// License. See LICENSE.TXT for details. 7198092Srdivacky// 8198092Srdivacky//===----------------------------------------------------------------------===// 9198092Srdivacky// 10198092Srdivacky// This file defines the CodeCompleteConsumer class. 11198092Srdivacky// 12198092Srdivacky//===----------------------------------------------------------------------===// 13198092Srdivacky#ifndef LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H 14198092Srdivacky#define LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H 15198092Srdivacky 16249423Sdim#include "clang-c/Index.h" 17249423Sdim#include "clang/AST/CanonicalType.h" 18212904Sdim#include "clang/AST/Type.h" 19239462Sdim#include "clang/Sema/CodeCompleteOptions.h" 20198092Srdivacky#include "llvm/ADT/SmallVector.h" 21199482Srdivacky#include "llvm/ADT/StringRef.h" 22218893Sdim#include "llvm/Support/Allocator.h" 23198092Srdivacky#include <string> 24198092Srdivacky 25198092Srdivackynamespace clang { 26198092Srdivacky 27212904Sdimclass Decl; 28234353Sdim 29208600Srdivacky/// \brief Default priority values for code-completion results based 30208600Srdivacky/// on their kind. 31208600Srdivackyenum { 32212904Sdim /// \brief Priority for the next initialization in a constructor initializer 33212904Sdim /// list. 34212904Sdim CCP_NextInitializer = 7, 35234353Sdim /// \brief Priority for an enumeration constant inside a switch whose 36218893Sdim /// condition is of the enumeration type. 37218893Sdim CCP_EnumInCase = 7, 38212904Sdim /// \brief Priority for a send-to-super completion. 39218893Sdim CCP_SuperCompletion = 20, 40208600Srdivacky /// \brief Priority for a declaration that is in the local scope. 41218893Sdim CCP_LocalDeclaration = 34, 42208600Srdivacky /// \brief Priority for a member declaration found from the current 43208600Srdivacky /// method or member function. 44218893Sdim CCP_MemberDeclaration = 35, 45208600Srdivacky /// \brief Priority for a language keyword (that isn't any of the other 46208600Srdivacky /// categories). 47218893Sdim CCP_Keyword = 40, 48208600Srdivacky /// \brief Priority for a code pattern. 49218893Sdim CCP_CodePattern = 40, 50208600Srdivacky /// \brief Priority for a non-type declaration. 51208600Srdivacky CCP_Declaration = 50, 52218893Sdim /// \brief Priority for a type. 53218893Sdim CCP_Type = CCP_Declaration, 54208600Srdivacky /// \brief Priority for a constant value (e.g., enumerator). 55218893Sdim CCP_Constant = 65, 56208600Srdivacky /// \brief Priority for a preprocessor macro. 57208600Srdivacky CCP_Macro = 70, 58208600Srdivacky /// \brief Priority for a nested-name-specifier. 59208600Srdivacky CCP_NestedNameSpecifier = 75, 60208600Srdivacky /// \brief Priority for a result that isn't likely to be what the user wants, 61208600Srdivacky /// but is included for completeness. 62218893Sdim CCP_Unlikely = 80, 63234353Sdim 64218893Sdim /// \brief Priority for the Objective-C "_cmd" implicit parameter. 65218893Sdim CCP_ObjC_cmd = CCP_Unlikely 66208600Srdivacky}; 67208600Srdivacky 68212904Sdim/// \brief Priority value deltas that are added to code-completion results 69208600Srdivacky/// based on the context of the result. 70208600Srdivackyenum { 71208600Srdivacky /// \brief The result is in a base class. 72212904Sdim CCD_InBaseClass = 2, 73212904Sdim /// \brief The result is a C++ non-static member function whose qualifiers 74212904Sdim /// exactly match the object type on which the member function can be called. 75212904Sdim CCD_ObjectQualifierMatch = -1, 76212904Sdim /// \brief The selector of the given message exactly matches the selector 77212904Sdim /// of the current method, which might imply that some kind of delegation 78212904Sdim /// is occurring. 79218893Sdim CCD_SelectorMatch = -3, 80234353Sdim 81218893Sdim /// \brief Adjustment to the "bool" type in Objective-C, where the typedef 82218893Sdim /// "BOOL" is preferred. 83218893Sdim CCD_bool_in_ObjC = 1, 84234353Sdim 85218893Sdim /// \brief Adjustment for KVC code pattern priorities when it doesn't look 86218893Sdim /// like the 87223017Sdim CCD_ProbablyNotObjCCollection = 15, 88234353Sdim 89223017Sdim /// \brief An Objective-C method being used as a property. 90223017Sdim CCD_MethodAsProperty = 2 91208600Srdivacky}; 92208600Srdivacky 93210299Sed/// \brief Priority value factors by which we will divide or multiply the 94210299Sed/// priority of a code-completion result. 95210299Sedenum { 96210299Sed /// \brief Divide by this factor when a code-completion result's type exactly 97210299Sed /// matches the type we expect. 98210299Sed CCF_ExactTypeMatch = 4, 99210299Sed /// \brief Divide by this factor when a code-completion result's type is 100210299Sed /// similar to the type we expect (e.g., both arithmetic types, both 101210299Sed /// Objective-C object pointer types). 102210299Sed CCF_SimilarTypeMatch = 2 103210299Sed}; 104212904Sdim 105212904Sdim/// \brief A simplified classification of types used when determining 106212904Sdim/// "similar" types for code completion. 107212904Sdimenum SimplifiedTypeClass { 108212904Sdim STC_Arithmetic, 109212904Sdim STC_Array, 110212904Sdim STC_Block, 111212904Sdim STC_Function, 112212904Sdim STC_ObjectiveC, 113212904Sdim STC_Other, 114212904Sdim STC_Pointer, 115212904Sdim STC_Record, 116212904Sdim STC_Void 117212904Sdim}; 118234353Sdim 119212904Sdim/// \brief Determine the simplified type class of the given canonical type. 120212904SdimSimplifiedTypeClass getSimplifiedTypeClass(CanQualType T); 121234353Sdim 122212904Sdim/// \brief Determine the type that this declaration will have if it is used 123212904Sdim/// as a type or in an expression. 124249423SdimQualType getDeclUsageType(ASTContext &C, const NamedDecl *ND); 125234353Sdim 126212904Sdim/// \brief Determine the priority to be given to a macro code completion result 127212904Sdim/// with the given name. 128212904Sdim/// 129212904Sdim/// \param MacroName The name of the macro. 130212904Sdim/// 131218893Sdim/// \param LangOpts Options describing the current language dialect. 132218893Sdim/// 133212904Sdim/// \param PreferredTypeIsPointer Whether the preferred type for the context 134212904Sdim/// of this macro is a pointer type. 135234353Sdimunsigned getMacroUsagePriority(StringRef MacroName, 136218893Sdim const LangOptions &LangOpts, 137212904Sdim bool PreferredTypeIsPointer = false); 138212904Sdim 139212904Sdim/// \brief Determine the libclang cursor kind associated with the given 140212904Sdim/// declaration. 141249423SdimCXCursorKind getCursorKindForDecl(const Decl *D); 142234353Sdim 143198092Srdivackyclass FunctionDecl; 144198092Srdivackyclass FunctionType; 145198092Srdivackyclass FunctionTemplateDecl; 146198893Srdivackyclass IdentifierInfo; 147198092Srdivackyclass NamedDecl; 148198092Srdivackyclass NestedNameSpecifier; 149198092Srdivackyclass Sema; 150198092Srdivacky 151212904Sdim/// \brief The context in which code completion occurred, so that the 152212904Sdim/// code-completion consumer can process the results accordingly. 153212904Sdimclass CodeCompletionContext { 154212904Sdimpublic: 155212904Sdim enum Kind { 156212904Sdim /// \brief An unspecified code-completion context. 157212904Sdim CCC_Other, 158218893Sdim /// \brief An unspecified code-completion context where we should also add 159218893Sdim /// macro completions. 160218893Sdim CCC_OtherWithMacros, 161212904Sdim /// \brief Code completion occurred within a "top-level" completion context, 162212904Sdim /// e.g., at namespace or global scope. 163212904Sdim CCC_TopLevel, 164212904Sdim /// \brief Code completion occurred within an Objective-C interface, 165212904Sdim /// protocol, or category interface. 166212904Sdim CCC_ObjCInterface, 167212904Sdim /// \brief Code completion occurred within an Objective-C implementation 168212904Sdim /// or category implementation. 169212904Sdim CCC_ObjCImplementation, 170212904Sdim /// \brief Code completion occurred within the instance variable list of 171212904Sdim /// an Objective-C interface, implementation, or category implementation. 172212904Sdim CCC_ObjCIvarList, 173212904Sdim /// \brief Code completion occurred within a class, struct, or union. 174212904Sdim CCC_ClassStructUnion, 175212904Sdim /// \brief Code completion occurred where a statement (or declaration) is 176212904Sdim /// expected in a function, method, or block. 177212904Sdim CCC_Statement, 178212904Sdim /// \brief Code completion occurred where an expression is expected. 179212904Sdim CCC_Expression, 180212904Sdim /// \brief Code completion occurred where an Objective-C message receiver 181212904Sdim /// is expected. 182212904Sdim CCC_ObjCMessageReceiver, 183212904Sdim /// \brief Code completion occurred on the right-hand side of a member 184224145Sdim /// access expression using the dot operator. 185212904Sdim /// 186234353Sdim /// The results of this completion are the members of the type being 187234353Sdim /// accessed. The type itself is available via 188212904Sdim /// \c CodeCompletionContext::getType(). 189224145Sdim CCC_DotMemberAccess, 190224145Sdim /// \brief Code completion occurred on the right-hand side of a member 191224145Sdim /// access expression using the arrow operator. 192224145Sdim /// 193234353Sdim /// The results of this completion are the members of the type being 194234353Sdim /// accessed. The type itself is available via 195224145Sdim /// \c CodeCompletionContext::getType(). 196224145Sdim CCC_ArrowMemberAccess, 197224145Sdim /// \brief Code completion occurred on the right-hand side of an Objective-C 198224145Sdim /// property access expression. 199224145Sdim /// 200234353Sdim /// The results of this completion are the members of the type being 201234353Sdim /// accessed. The type itself is available via 202224145Sdim /// \c CodeCompletionContext::getType(). 203224145Sdim CCC_ObjCPropertyAccess, 204212904Sdim /// \brief Code completion occurred after the "enum" keyword, to indicate 205212904Sdim /// an enumeration name. 206212904Sdim CCC_EnumTag, 207212904Sdim /// \brief Code completion occurred after the "union" keyword, to indicate 208212904Sdim /// a union name. 209212904Sdim CCC_UnionTag, 210212904Sdim /// \brief Code completion occurred after the "struct" or "class" keyword, 211212904Sdim /// to indicate a struct or class name. 212212904Sdim CCC_ClassOrStructTag, 213212904Sdim /// \brief Code completion occurred where a protocol name is expected. 214212904Sdim CCC_ObjCProtocolName, 215212904Sdim /// \brief Code completion occurred where a namespace or namespace alias 216212904Sdim /// is expected. 217212904Sdim CCC_Namespace, 218212904Sdim /// \brief Code completion occurred where a type name is expected. 219212904Sdim CCC_Type, 220212904Sdim /// \brief Code completion occurred where a new name is expected. 221212904Sdim CCC_Name, 222212904Sdim /// \brief Code completion occurred where a new name is expected and a 223212904Sdim /// qualified name is permissible. 224212904Sdim CCC_PotentiallyQualifiedName, 225212904Sdim /// \brief Code completion occurred where an macro is being defined. 226212904Sdim CCC_MacroName, 227212904Sdim /// \brief Code completion occurred where a macro name is expected 228212904Sdim /// (without any arguments, in the case of a function-like macro). 229212904Sdim CCC_MacroNameUse, 230212904Sdim /// \brief Code completion occurred within a preprocessor expression. 231212904Sdim CCC_PreprocessorExpression, 232234353Sdim /// \brief Code completion occurred where a preprocessor directive is 233212904Sdim /// expected. 234212904Sdim CCC_PreprocessorDirective, 235212904Sdim /// \brief Code completion occurred in a context where natural language is 236212904Sdim /// expected, e.g., a comment or string literal. 237212904Sdim /// 238212904Sdim /// This context usually implies that no completions should be added, 239212904Sdim /// unless they come from an appropriate natural-language dictionary. 240212904Sdim CCC_NaturalLanguage, 241239462Sdim /// \brief Code completion for a selector, as in an \@selector expression. 242212904Sdim CCC_SelectorName, 243212904Sdim /// \brief Code completion within a type-qualifier list. 244218893Sdim CCC_TypeQualifiers, 245218893Sdim /// \brief Code completion in a parenthesized expression, which means that 246218893Sdim /// we may also have types here in C and Objective-C (as well as in C++). 247218893Sdim CCC_ParenthesizedExpression, 248249423Sdim /// \brief Code completion where an Objective-C instance message is 249249423Sdim /// expected. 250224145Sdim CCC_ObjCInstanceMessage, 251234353Sdim /// \brief Code completion where an Objective-C class message is expected. 252224145Sdim CCC_ObjCClassMessage, 253226633Sdim /// \brief Code completion where the name of an Objective-C class is 254224145Sdim /// expected. 255226633Sdim CCC_ObjCInterfaceName, 256224145Sdim /// \brief Code completion where an Objective-C category name is expected. 257224145Sdim CCC_ObjCCategoryName, 258234353Sdim /// \brief An unknown context, in which we are recovering from a parsing 259218893Sdim /// error and don't know which completions we should give. 260218893Sdim CCC_Recovery 261212904Sdim }; 262212904Sdim 263212904Sdimprivate: 264212904Sdim enum Kind Kind; 265212904Sdim 266212904Sdim /// \brief The type that would prefer to see at this point (e.g., the type 267212904Sdim /// of an initializer or function parameter). 268212904Sdim QualType PreferredType; 269234353Sdim 270212904Sdim /// \brief The type of the base object in a member access expression. 271212904Sdim QualType BaseType; 272234353Sdim 273226633Sdim /// \brief The identifiers for Objective-C selector parts. 274226633Sdim IdentifierInfo **SelIdents; 275234353Sdim 276226633Sdim /// \brief The number of Objective-C selector parts. 277226633Sdim unsigned NumSelIdents; 278234353Sdim 279212904Sdimpublic: 280212904Sdim /// \brief Construct a new code-completion context of the given kind. 281234353Sdim CodeCompletionContext(enum Kind Kind) : Kind(Kind), SelIdents(NULL), 282226633Sdim NumSelIdents(0) { } 283234353Sdim 284212904Sdim /// \brief Construct a new code-completion context of the given kind. 285226633Sdim CodeCompletionContext(enum Kind Kind, QualType T, 286226633Sdim IdentifierInfo **SelIdents = NULL, 287226633Sdim unsigned NumSelIdents = 0) : Kind(Kind), 288226633Sdim SelIdents(SelIdents), 289234353Sdim NumSelIdents(NumSelIdents) { 290224145Sdim if (Kind == CCC_DotMemberAccess || Kind == CCC_ArrowMemberAccess || 291226633Sdim Kind == CCC_ObjCPropertyAccess || Kind == CCC_ObjCClassMessage || 292226633Sdim Kind == CCC_ObjCInstanceMessage) 293212904Sdim BaseType = T; 294212904Sdim else 295212904Sdim PreferredType = T; 296212904Sdim } 297234353Sdim 298212904Sdim /// \brief Retrieve the kind of code-completion context. 299212904Sdim enum Kind getKind() const { return Kind; } 300234353Sdim 301212904Sdim /// \brief Retrieve the type that this expression would prefer to have, e.g., 302212904Sdim /// if the expression is a variable initializer or a function argument, the 303212904Sdim /// type of the corresponding variable or function parameter. 304212904Sdim QualType getPreferredType() const { return PreferredType; } 305234353Sdim 306234353Sdim /// \brief Retrieve the type of the base object in a member-access 307212904Sdim /// expression. 308212904Sdim QualType getBaseType() const { return BaseType; } 309234353Sdim 310226633Sdim /// \brief Retrieve the Objective-C selector identifiers. 311226633Sdim IdentifierInfo **getSelIdents() const { return SelIdents; } 312234353Sdim 313226633Sdim /// \brief Retrieve the number of Objective-C selector identifiers. 314226633Sdim unsigned getNumSelIdents() const { return NumSelIdents; } 315218893Sdim 316218893Sdim /// \brief Determines whether we want C++ constructors as results within this 317218893Sdim /// context. 318218893Sdim bool wantConstructorResults() const; 319212904Sdim}; 320212904Sdim 321212904Sdim 322198092Srdivacky/// \brief A "string" used to describe how code completion can 323198092Srdivacky/// be performed for an entity. 324198092Srdivacky/// 325234353Sdim/// A code completion string typically shows how a particular entity can be 326198092Srdivacky/// used. For example, the code completion string for a function would show 327234353Sdim/// the syntax to call it, including the parentheses, placeholders for the 328234353Sdim/// arguments, etc. 329198092Srdivackyclass CodeCompletionString { 330198092Srdivackypublic: 331198092Srdivacky /// \brief The different kinds of "chunks" that can occur within a code 332198092Srdivacky /// completion string. 333198092Srdivacky enum ChunkKind { 334199482Srdivacky /// \brief The piece of text that the user is expected to type to 335199482Srdivacky /// match the code-completion string, typically a keyword or the name of a 336199482Srdivacky /// declarator or macro. 337199482Srdivacky CK_TypedText, 338198092Srdivacky /// \brief A piece of text that should be placed in the buffer, e.g., 339198092Srdivacky /// parentheses or a comma in a function call. 340198092Srdivacky CK_Text, 341198092Srdivacky /// \brief A code completion string that is entirely optional. For example, 342198092Srdivacky /// an optional code completion string that describes the default arguments 343198092Srdivacky /// in a function call. 344198092Srdivacky CK_Optional, 345234353Sdim /// \brief A string that acts as a placeholder for, e.g., a function 346198092Srdivacky /// call argument. 347198092Srdivacky CK_Placeholder, 348198092Srdivacky /// \brief A piece of text that describes something about the result but 349198092Srdivacky /// should not be inserted into the buffer. 350199482Srdivacky CK_Informative, 351201361Srdivacky /// \brief A piece of text that describes the type of an entity or, for 352201361Srdivacky /// functions and methods, the return type. 353201361Srdivacky CK_ResultType, 354199482Srdivacky /// \brief A piece of text that describes the parameter that corresponds 355199482Srdivacky /// to the code-completion location within a function call, message send, 356199482Srdivacky /// macro invocation, etc. 357199482Srdivacky CK_CurrentParameter, 358199482Srdivacky /// \brief A left parenthesis ('('). 359199482Srdivacky CK_LeftParen, 360199482Srdivacky /// \brief A right parenthesis (')'). 361199482Srdivacky CK_RightParen, 362199482Srdivacky /// \brief A left bracket ('['). 363199482Srdivacky CK_LeftBracket, 364199482Srdivacky /// \brief A right bracket (']'). 365199482Srdivacky CK_RightBracket, 366199482Srdivacky /// \brief A left brace ('{'). 367199482Srdivacky CK_LeftBrace, 368199482Srdivacky /// \brief A right brace ('}'). 369199482Srdivacky CK_RightBrace, 370199482Srdivacky /// \brief A left angle bracket ('<'). 371199482Srdivacky CK_LeftAngle, 372199482Srdivacky /// \brief A right angle bracket ('>'). 373199482Srdivacky CK_RightAngle, 374199482Srdivacky /// \brief A comma separator (','). 375202379Srdivacky CK_Comma, 376202379Srdivacky /// \brief A colon (':'). 377202379Srdivacky CK_Colon, 378202379Srdivacky /// \brief A semicolon (';'). 379202379Srdivacky CK_SemiColon, 380202379Srdivacky /// \brief An '=' sign. 381202379Srdivacky CK_Equal, 382202379Srdivacky /// \brief Horizontal whitespace (' '). 383202379Srdivacky CK_HorizontalSpace, 384239462Sdim /// \brief Vertical whitespace ('\\n' or '\\r\\n', depending on the 385202379Srdivacky /// platform). 386202379Srdivacky CK_VerticalSpace 387198092Srdivacky }; 388234353Sdim 389198092Srdivacky /// \brief One piece of the code completion string. 390198092Srdivacky struct Chunk { 391234353Sdim /// \brief The kind of data stored in this piece of the code completion 392198092Srdivacky /// string. 393198092Srdivacky ChunkKind Kind; 394234353Sdim 395198092Srdivacky union { 396198092Srdivacky /// \brief The text string associated with a CK_Text, CK_Placeholder, 397199482Srdivacky /// CK_Informative, or CK_Comma chunk. 398234353Sdim /// The string is owned by the chunk and will be deallocated 399198092Srdivacky /// (with delete[]) when the chunk is destroyed. 400198092Srdivacky const char *Text; 401234353Sdim 402198092Srdivacky /// \brief The code completion string associated with a CK_Optional chunk. 403198092Srdivacky /// The optional code completion string is owned by the chunk, and will 404198092Srdivacky /// be deallocated (with delete) when the chunk is destroyed. 405198092Srdivacky CodeCompletionString *Optional; 406198092Srdivacky }; 407234353Sdim 408198092Srdivacky Chunk() : Kind(CK_Text), Text(0) { } 409234353Sdim 410234353Sdim explicit Chunk(ChunkKind Kind, const char *Text = ""); 411234353Sdim 412198092Srdivacky /// \brief Create a new text chunk. 413218893Sdim static Chunk CreateText(const char *Text); 414198092Srdivacky 415198092Srdivacky /// \brief Create a new optional chunk. 416218893Sdim static Chunk CreateOptional(CodeCompletionString *Optional); 417198092Srdivacky 418198092Srdivacky /// \brief Create a new placeholder chunk. 419218893Sdim static Chunk CreatePlaceholder(const char *Placeholder); 420198092Srdivacky 421198092Srdivacky /// \brief Create a new informative chunk. 422218893Sdim static Chunk CreateInformative(const char *Informative); 423198092Srdivacky 424201361Srdivacky /// \brief Create a new result type chunk. 425218893Sdim static Chunk CreateResultType(const char *ResultType); 426201361Srdivacky 427199482Srdivacky /// \brief Create a new current-parameter chunk. 428218893Sdim static Chunk CreateCurrentParameter(const char *CurrentParameter); 429198092Srdivacky }; 430234353Sdim 431198092Srdivackyprivate: 432218893Sdim /// \brief The number of chunks stored in this string. 433226633Sdim unsigned NumChunks : 16; 434234353Sdim 435226633Sdim /// \brief The number of annotations for this code-completion result. 436226633Sdim unsigned NumAnnotations : 16; 437226633Sdim 438218893Sdim /// \brief The priority of this code-completion string. 439234353Sdim unsigned Priority : 16; 440234353Sdim 441218893Sdim /// \brief The availability of this code-completion result. 442218893Sdim unsigned Availability : 2; 443234353Sdim 444234353Sdim /// \brief The name of the parent context. 445234353Sdim StringRef ParentName; 446239462Sdim 447239462Sdim /// \brief A brief documentation comment attached to the declaration of 448239462Sdim /// entity being completed by this result. 449239462Sdim const char *BriefComment; 450234353Sdim 451243830Sdim CodeCompletionString(const CodeCompletionString &) LLVM_DELETED_FUNCTION; 452243830Sdim void operator=(const CodeCompletionString &) LLVM_DELETED_FUNCTION; 453234353Sdim 454218893Sdim CodeCompletionString(const Chunk *Chunks, unsigned NumChunks, 455226633Sdim unsigned Priority, CXAvailabilityKind Availability, 456234353Sdim const char **Annotations, unsigned NumAnnotations, 457243830Sdim StringRef ParentName, 458239462Sdim const char *BriefComment); 459218893Sdim ~CodeCompletionString() { } 460234353Sdim 461218893Sdim friend class CodeCompletionBuilder; 462218893Sdim friend class CodeCompletionResult; 463234353Sdim 464198092Srdivackypublic: 465218893Sdim typedef const Chunk *iterator; 466218893Sdim iterator begin() const { return reinterpret_cast<const Chunk *>(this + 1); } 467218893Sdim iterator end() const { return begin() + NumChunks; } 468218893Sdim bool empty() const { return NumChunks == 0; } 469218893Sdim unsigned size() const { return NumChunks; } 470234353Sdim 471218893Sdim const Chunk &operator[](unsigned I) const { 472199482Srdivacky assert(I < size() && "Chunk index out-of-range"); 473218893Sdim return begin()[I]; 474199482Srdivacky } 475234353Sdim 476218893Sdim /// \brief Returns the text in the TypedText chunk. 477218893Sdim const char *getTypedText() const; 478199482Srdivacky 479218893Sdim /// \brief Retrieve the priority of this code completion result. 480218893Sdim unsigned getPriority() const { return Priority; } 481234353Sdim 482226633Sdim /// \brief Retrieve the availability of this code completion result. 483218893Sdim unsigned getAvailability() const { return Availability; } 484226633Sdim 485226633Sdim /// \brief Retrieve the number of annotations for this code completion result. 486226633Sdim unsigned getAnnotationCount() const; 487226633Sdim 488226633Sdim /// \brief Retrieve the annotation string specified by \c AnnotationNr. 489226633Sdim const char *getAnnotation(unsigned AnnotationNr) const; 490218893Sdim 491234353Sdim /// \brief Retrieve the name of the parent context. 492234353Sdim StringRef getParentContextName() const { 493234353Sdim return ParentName; 494234353Sdim } 495239462Sdim 496239462Sdim const char *getBriefComment() const { 497239462Sdim return BriefComment; 498239462Sdim } 499234353Sdim 500218893Sdim /// \brief Retrieve a string representation of the code completion string, 501218893Sdim /// which is mainly useful for debugging. 502234353Sdim std::string getAsString() const; 503218893Sdim}; 504218893Sdim 505218893Sdim/// \brief An allocator used specifically for the purpose of code completion. 506234353Sdimclass CodeCompletionAllocator : public llvm::BumpPtrAllocator { 507218893Sdimpublic: 508218893Sdim /// \brief Copy the given string into this allocator. 509226633Sdim const char *CopyString(StringRef String); 510218893Sdim 511218893Sdim /// \brief Copy the given string into this allocator. 512226633Sdim const char *CopyString(Twine String); 513234353Sdim 514218893Sdim // \brief Copy the given string into this allocator. 515218893Sdim const char *CopyString(const char *String) { 516226633Sdim return CopyString(StringRef(String)); 517199482Srdivacky } 518234353Sdim 519218893Sdim /// \brief Copy the given string into this allocator. 520218893Sdim const char *CopyString(const std::string &String) { 521226633Sdim return CopyString(StringRef(String)); 522218893Sdim } 523218893Sdim}; 524234353Sdim 525234353Sdim/// \brief Allocator for a cached set of global code completions. 526234353Sdimclass GlobalCodeCompletionAllocator 527234353Sdim : public CodeCompletionAllocator, 528234353Sdim public RefCountedBase<GlobalCodeCompletionAllocator> 529234353Sdim{ 530234353Sdim 531234353Sdim}; 532234353Sdim 533234353Sdimclass CodeCompletionTUInfo { 534249423Sdim llvm::DenseMap<const DeclContext *, StringRef> ParentNames; 535234353Sdim IntrusiveRefCntPtr<GlobalCodeCompletionAllocator> AllocatorRef; 536234353Sdim 537234353Sdimpublic: 538234353Sdim explicit CodeCompletionTUInfo( 539234353Sdim IntrusiveRefCntPtr<GlobalCodeCompletionAllocator> Allocator) 540234353Sdim : AllocatorRef(Allocator) { } 541234353Sdim 542234353Sdim IntrusiveRefCntPtr<GlobalCodeCompletionAllocator> getAllocatorRef() const { 543234353Sdim return AllocatorRef; 544234353Sdim } 545234353Sdim CodeCompletionAllocator &getAllocator() const { 546234353Sdim assert(AllocatorRef); 547234353Sdim return *AllocatorRef; 548234353Sdim } 549234353Sdim 550249423Sdim StringRef getParentName(const DeclContext *DC); 551234353Sdim}; 552234353Sdim 553234353Sdim} // end namespace clang 554234353Sdim 555234353Sdimnamespace llvm { 556234353Sdim template <> struct isPodLike<clang::CodeCompletionString::Chunk> { 557234353Sdim static const bool value = true; 558234353Sdim }; 559234353Sdim} 560234353Sdim 561234353Sdimnamespace clang { 562234353Sdim 563218893Sdim/// \brief A builder class used to construct new code-completion strings. 564218893Sdimclass CodeCompletionBuilder { 565234353Sdimpublic: 566218893Sdim typedef CodeCompletionString::Chunk Chunk; 567234353Sdim 568218893Sdimprivate: 569218893Sdim CodeCompletionAllocator &Allocator; 570234353Sdim CodeCompletionTUInfo &CCTUInfo; 571218893Sdim unsigned Priority; 572218893Sdim CXAvailabilityKind Availability; 573234353Sdim StringRef ParentName; 574239462Sdim const char *BriefComment; 575218893Sdim 576218893Sdim /// \brief The chunks stored in this string. 577226633Sdim SmallVector<Chunk, 4> Chunks; 578226633Sdim 579226633Sdim SmallVector<const char *, 2> Annotations; 580234353Sdim 581218893Sdimpublic: 582218893Sdim CodeCompletionBuilder(CodeCompletionAllocator &Allocator, 583234353Sdim CodeCompletionTUInfo &CCTUInfo) 584234353Sdim : Allocator(Allocator), CCTUInfo(CCTUInfo), 585234353Sdim Priority(0), Availability(CXAvailability_Available), 586243830Sdim BriefComment(NULL) { } 587218893Sdim 588234353Sdim CodeCompletionBuilder(CodeCompletionAllocator &Allocator, 589234353Sdim CodeCompletionTUInfo &CCTUInfo, 590234353Sdim unsigned Priority, CXAvailabilityKind Availability) 591234353Sdim : Allocator(Allocator), CCTUInfo(CCTUInfo), 592234353Sdim Priority(Priority), Availability(Availability), 593243830Sdim BriefComment(NULL) { } 594234353Sdim 595218893Sdim /// \brief Retrieve the allocator into which the code completion 596218893Sdim /// strings should be allocated. 597218893Sdim CodeCompletionAllocator &getAllocator() const { return Allocator; } 598234353Sdim 599234353Sdim CodeCompletionTUInfo &getCodeCompletionTUInfo() const { return CCTUInfo; } 600234353Sdim 601234353Sdim /// \brief Take the resulting completion string. 602218893Sdim /// 603218893Sdim /// This operation can only be performed once. 604218893Sdim CodeCompletionString *TakeString(); 605234353Sdim 606199482Srdivacky /// \brief Add a new typed-text chunk. 607234353Sdim void AddTypedTextChunk(const char *Text); 608234353Sdim 609198092Srdivacky /// \brief Add a new text chunk. 610234353Sdim void AddTextChunk(const char *Text); 611218893Sdim 612198092Srdivacky /// \brief Add a new optional chunk. 613234353Sdim void AddOptionalChunk(CodeCompletionString *Optional); 614234353Sdim 615198092Srdivacky /// \brief Add a new placeholder chunk. 616234353Sdim void AddPlaceholderChunk(const char *Placeholder); 617234353Sdim 618198092Srdivacky /// \brief Add a new informative chunk. 619234353Sdim void AddInformativeChunk(const char *Text); 620234353Sdim 621201361Srdivacky /// \brief Add a new result-type chunk. 622234353Sdim void AddResultTypeChunk(const char *ResultType); 623234353Sdim 624199482Srdivacky /// \brief Add a new current-parameter chunk. 625234353Sdim void AddCurrentParameterChunk(const char *CurrentParameter); 626234353Sdim 627199482Srdivacky /// \brief Add a new chunk. 628234353Sdim void AddChunk(CodeCompletionString::ChunkKind CK, const char *Text = ""); 629226633Sdim 630226633Sdim void AddAnnotation(const char *A) { Annotations.push_back(A); } 631234353Sdim 632234353Sdim /// \brief Add the parent context information to this code completion. 633249423Sdim void addParentContext(const DeclContext *DC); 634239462Sdim 635249423Sdim const char *getBriefComment() const { return BriefComment; } 636239462Sdim void addBriefComment(StringRef Comment); 637234353Sdim 638234353Sdim StringRef getParentName() const { return ParentName; } 639218893Sdim}; 640234353Sdim 641212904Sdim/// \brief Captures a result of code completion. 642212904Sdimclass CodeCompletionResult { 643198092Srdivackypublic: 644212904Sdim /// \brief Describes the kind of result generated. 645212904Sdim enum ResultKind { 646239462Sdim RK_Declaration = 0, ///< Refers to a declaration 647239462Sdim RK_Keyword, ///< Refers to a keyword or symbol. 648239462Sdim RK_Macro, ///< Refers to a macro 649239462Sdim RK_Pattern ///< Refers to a precomputed pattern. 650212904Sdim }; 651234353Sdim 652234353Sdim /// \brief When Kind == RK_Declaration or RK_Pattern, the declaration we are 653234353Sdim /// referring to. In the latter case, the declaration might be NULL. 654249423Sdim const NamedDecl *Declaration; 655234353Sdim 656212904Sdim union { 657234353Sdim /// \brief When Kind == RK_Keyword, the string representing the keyword 658212904Sdim /// or symbol's spelling. 659212904Sdim const char *Keyword; 660234353Sdim 661212904Sdim /// \brief When Kind == RK_Pattern, the code-completion string that 662212904Sdim /// describes the completion text to insert. 663212904Sdim CodeCompletionString *Pattern; 664234353Sdim 665212904Sdim /// \brief When Kind == RK_Macro, the identifier that refers to a macro. 666249423Sdim const IdentifierInfo *Macro; 667212904Sdim }; 668208600Srdivacky 669212904Sdim /// \brief The priority of this particular code-completion result. 670212904Sdim unsigned Priority; 671208600Srdivacky 672239462Sdim /// \brief Specifies which parameter (of a function, Objective-C method, 673239462Sdim /// macro, etc.) we should start with when formatting the result. 674239462Sdim unsigned StartParameter; 675239462Sdim 676239462Sdim /// \brief The kind of result stored here. 677239462Sdim ResultKind Kind; 678239462Sdim 679212904Sdim /// \brief The cursor kind that describes this result. 680212904Sdim CXCursorKind CursorKind; 681234353Sdim 682212904Sdim /// \brief The availability of this result. 683212904Sdim CXAvailabilityKind Availability; 684234353Sdim 685212904Sdim /// \brief Whether this result is hidden by another name. 686212904Sdim bool Hidden : 1; 687234353Sdim 688212904Sdim /// \brief Whether this result was found via lookup into a base class. 689212904Sdim bool QualifierIsInformative : 1; 690234353Sdim 691234353Sdim /// \brief Whether this declaration is the beginning of a 692212904Sdim /// nested-name-specifier and, therefore, should be followed by '::'. 693212904Sdim bool StartsNestedNameSpecifier : 1; 694199512Srdivacky 695212904Sdim /// \brief Whether all parameters (of a function, Objective-C 696212904Sdim /// method, etc.) should be considered "informative". 697212904Sdim bool AllParametersAreInformative : 1; 698199512Srdivacky 699212904Sdim /// \brief Whether we're completing a declaration of the given entity, 700212904Sdim /// rather than a use of that entity. 701212904Sdim bool DeclaringEntity : 1; 702234353Sdim 703212904Sdim /// \brief If the result should have a nested-name-specifier, this is it. 704234353Sdim /// When \c QualifierIsInformative, the nested-name-specifier is 705212904Sdim /// informative rather than required. 706212904Sdim NestedNameSpecifier *Qualifier; 707234353Sdim 708212904Sdim /// \brief Build a result that refers to a declaration. 709249423Sdim CodeCompletionResult(const NamedDecl *Declaration, 710249423Sdim unsigned Priority, 711212904Sdim NestedNameSpecifier *Qualifier = 0, 712226633Sdim bool QualifierIsInformative = false, 713226633Sdim bool Accessible = true) 714249423Sdim : Declaration(Declaration), Priority(Priority), 715239462Sdim StartParameter(0), Kind(RK_Declaration), 716239462Sdim Availability(CXAvailability_Available), Hidden(false), 717239462Sdim QualifierIsInformative(QualifierIsInformative), 718212904Sdim StartsNestedNameSpecifier(false), AllParametersAreInformative(false), 719234353Sdim DeclaringEntity(false), Qualifier(Qualifier) { 720226633Sdim computeCursorKindAndAvailability(Accessible); 721212904Sdim } 722234353Sdim 723212904Sdim /// \brief Build a result that refers to a keyword or symbol. 724212904Sdim CodeCompletionResult(const char *Keyword, unsigned Priority = CCP_Keyword) 725239462Sdim : Declaration(0), Keyword(Keyword), Priority(Priority), StartParameter(0), 726239462Sdim Kind(RK_Keyword), CursorKind(CXCursor_NotImplemented), 727239462Sdim Availability(CXAvailability_Available), Hidden(false), 728239462Sdim QualifierIsInformative(0), StartsNestedNameSpecifier(false), 729239462Sdim AllParametersAreInformative(false), DeclaringEntity(false), Qualifier(0) 730239462Sdim { 731212904Sdim } 732234353Sdim 733212904Sdim /// \brief Build a result that refers to a macro. 734249423Sdim CodeCompletionResult(const IdentifierInfo *Macro, 735249423Sdim unsigned Priority = CCP_Macro) 736239462Sdim : Declaration(0), Macro(Macro), Priority(Priority), StartParameter(0), 737239462Sdim Kind(RK_Macro), CursorKind(CXCursor_MacroDefinition), 738239462Sdim Availability(CXAvailability_Available), Hidden(false), 739239462Sdim QualifierIsInformative(0), StartsNestedNameSpecifier(false), 740239462Sdim AllParametersAreInformative(false), DeclaringEntity(false), Qualifier(0) 741239462Sdim { 742212904Sdim } 743199512Srdivacky 744212904Sdim /// \brief Build a result that refers to a pattern. 745212904Sdim CodeCompletionResult(CodeCompletionString *Pattern, 746212904Sdim unsigned Priority = CCP_CodePattern, 747212904Sdim CXCursorKind CursorKind = CXCursor_NotImplemented, 748234353Sdim CXAvailabilityKind Availability = CXAvailability_Available, 749249423Sdim const NamedDecl *D = 0) 750239462Sdim : Declaration(D), Pattern(Pattern), Priority(Priority), StartParameter(0), 751239462Sdim Kind(RK_Pattern), CursorKind(CursorKind), Availability(Availability), 752234353Sdim Hidden(false), QualifierIsInformative(0), 753234353Sdim StartsNestedNameSpecifier(false), AllParametersAreInformative(false), 754234353Sdim DeclaringEntity(false), Qualifier(0) 755234353Sdim { 756212904Sdim } 757234353Sdim 758234353Sdim /// \brief Build a result that refers to a pattern with an associated 759234353Sdim /// declaration. 760234353Sdim CodeCompletionResult(CodeCompletionString *Pattern, NamedDecl *D, 761234353Sdim unsigned Priority) 762239462Sdim : Declaration(D), Pattern(Pattern), Priority(Priority), StartParameter(0), 763239462Sdim Kind(RK_Pattern), Availability(CXAvailability_Available), Hidden(false), 764239462Sdim QualifierIsInformative(false), StartsNestedNameSpecifier(false), 765239462Sdim AllParametersAreInformative(false), DeclaringEntity(false), Qualifier(0) { 766234353Sdim computeCursorKindAndAvailability(); 767234353Sdim } 768234353Sdim 769212904Sdim /// \brief Retrieve the declaration stored in this result. 770249423Sdim const NamedDecl *getDeclaration() const { 771212904Sdim assert(Kind == RK_Declaration && "Not a declaration result"); 772212904Sdim return Declaration; 773212904Sdim } 774234353Sdim 775212904Sdim /// \brief Retrieve the keyword stored in this result. 776212904Sdim const char *getKeyword() const { 777212904Sdim assert(Kind == RK_Keyword && "Not a keyword result"); 778212904Sdim return Keyword; 779212904Sdim } 780234353Sdim 781212904Sdim /// \brief Create a new code-completion string that describes how to insert 782212904Sdim /// this result into a program. 783212904Sdim /// 784212904Sdim /// \param S The semantic analysis that created the result. 785212904Sdim /// 786218893Sdim /// \param Allocator The allocator that will be used to allocate the 787218893Sdim /// string itself. 788212904Sdim CodeCompletionString *CreateCodeCompletionString(Sema &S, 789234353Sdim CodeCompletionAllocator &Allocator, 790239462Sdim CodeCompletionTUInfo &CCTUInfo, 791239462Sdim bool IncludeBriefComments); 792234353Sdim CodeCompletionString *CreateCodeCompletionString(ASTContext &Ctx, 793234353Sdim Preprocessor &PP, 794234353Sdim CodeCompletionAllocator &Allocator, 795239462Sdim CodeCompletionTUInfo &CCTUInfo, 796239462Sdim bool IncludeBriefComments); 797234353Sdim 798212904Sdimprivate: 799226633Sdim void computeCursorKindAndAvailability(bool Accessible = true); 800212904Sdim}; 801234353Sdim 802212904Sdimbool operator<(const CodeCompletionResult &X, const CodeCompletionResult &Y); 803234353Sdim 804234353Sdiminline bool operator>(const CodeCompletionResult &X, 805212904Sdim const CodeCompletionResult &Y) { 806212904Sdim return Y < X; 807212904Sdim} 808234353Sdim 809234353Sdiminline bool operator<=(const CodeCompletionResult &X, 810212904Sdim const CodeCompletionResult &Y) { 811212904Sdim return !(Y < X); 812212904Sdim} 813212904Sdim 814234353Sdiminline bool operator>=(const CodeCompletionResult &X, 815212904Sdim const CodeCompletionResult &Y) { 816212904Sdim return !(X < Y); 817212904Sdim} 818212904Sdim 819234353Sdim 820234353Sdimraw_ostream &operator<<(raw_ostream &OS, 821212904Sdim const CodeCompletionString &CCS); 822212904Sdim 823234353Sdim/// \brief Abstract interface for a consumer of code-completion 824212904Sdim/// information. 825212904Sdimclass CodeCompleteConsumer { 826212904Sdimprotected: 827239462Sdim const CodeCompleteOptions CodeCompleteOpts; 828212904Sdim 829212904Sdim /// \brief Whether the output format for the code-completion consumer is 830212904Sdim /// binary. 831212904Sdim bool OutputIsBinary; 832234353Sdim 833212904Sdimpublic: 834198092Srdivacky class OverloadCandidate { 835198092Srdivacky public: 836198092Srdivacky /// \brief Describes the type of overload candidate. 837198092Srdivacky enum CandidateKind { 838198092Srdivacky /// \brief The candidate is a function declaration. 839198092Srdivacky CK_Function, 840198092Srdivacky /// \brief The candidate is a function template. 841198092Srdivacky CK_FunctionTemplate, 842198092Srdivacky /// \brief The "candidate" is actually a variable, expression, or block 843198092Srdivacky /// for which we only have a function prototype. 844198092Srdivacky CK_FunctionType 845198092Srdivacky }; 846234353Sdim 847198092Srdivacky private: 848198092Srdivacky /// \brief The kind of overload candidate. 849198092Srdivacky CandidateKind Kind; 850234353Sdim 851198092Srdivacky union { 852234353Sdim /// \brief The function overload candidate, available when 853198092Srdivacky /// Kind == CK_Function. 854198092Srdivacky FunctionDecl *Function; 855234353Sdim 856198092Srdivacky /// \brief The function template overload candidate, available when 857198092Srdivacky /// Kind == CK_FunctionTemplate. 858198092Srdivacky FunctionTemplateDecl *FunctionTemplate; 859234353Sdim 860198092Srdivacky /// \brief The function type that describes the entity being called, 861198092Srdivacky /// when Kind == CK_FunctionType. 862198092Srdivacky const FunctionType *Type; 863198092Srdivacky }; 864234353Sdim 865198092Srdivacky public: 866198092Srdivacky OverloadCandidate(FunctionDecl *Function) 867198092Srdivacky : Kind(CK_Function), Function(Function) { } 868198092Srdivacky 869198092Srdivacky OverloadCandidate(FunctionTemplateDecl *FunctionTemplateDecl) 870218893Sdim : Kind(CK_FunctionTemplate), FunctionTemplate(FunctionTemplateDecl) { } 871198092Srdivacky 872198092Srdivacky OverloadCandidate(const FunctionType *Type) 873198092Srdivacky : Kind(CK_FunctionType), Type(Type) { } 874198092Srdivacky 875198092Srdivacky /// \brief Determine the kind of overload candidate. 876198092Srdivacky CandidateKind getKind() const { return Kind; } 877234353Sdim 878234353Sdim /// \brief Retrieve the function overload candidate or the templated 879198092Srdivacky /// function declaration for a function template. 880198092Srdivacky FunctionDecl *getFunction() const; 881234353Sdim 882198092Srdivacky /// \brief Retrieve the function template overload candidate. 883198092Srdivacky FunctionTemplateDecl *getFunctionTemplate() const { 884198092Srdivacky assert(getKind() == CK_FunctionTemplate && "Not a function template"); 885198092Srdivacky return FunctionTemplate; 886198092Srdivacky } 887234353Sdim 888198092Srdivacky /// \brief Retrieve the function type of the entity, regardless of how the 889198092Srdivacky /// function is stored. 890198092Srdivacky const FunctionType *getFunctionType() const; 891234353Sdim 892198092Srdivacky /// \brief Create a new code-completion string that describes the function 893198092Srdivacky /// signature of this overload candidate. 894234353Sdim CodeCompletionString *CreateSignatureString(unsigned CurrentArg, 895218893Sdim Sema &S, 896234353Sdim CodeCompletionAllocator &Allocator, 897234353Sdim CodeCompletionTUInfo &CCTUInfo) const; 898198092Srdivacky }; 899234353Sdim 900239462Sdim CodeCompleteConsumer(const CodeCompleteOptions &CodeCompleteOpts, 901239462Sdim bool OutputIsBinary) 902239462Sdim : CodeCompleteOpts(CodeCompleteOpts), OutputIsBinary(OutputIsBinary) 903239462Sdim { } 904234353Sdim 905199482Srdivacky /// \brief Whether the code-completion consumer wants to see macros. 906239462Sdim bool includeMacros() const { 907239462Sdim return CodeCompleteOpts.IncludeMacros; 908239462Sdim } 909199990Srdivacky 910208600Srdivacky /// \brief Whether the code-completion consumer wants to see code patterns. 911239462Sdim bool includeCodePatterns() const { 912239462Sdim return CodeCompleteOpts.IncludeCodePatterns; 913239462Sdim } 914234353Sdim 915212904Sdim /// \brief Whether to include global (top-level) declaration results. 916239462Sdim bool includeGlobals() const { 917239462Sdim return CodeCompleteOpts.IncludeGlobals; 918239462Sdim } 919234353Sdim 920239462Sdim /// \brief Whether to include brief documentation comments within the set of 921239462Sdim /// code completions returned. 922239462Sdim bool includeBriefComments() const { 923239462Sdim return CodeCompleteOpts.IncludeBriefComments; 924239462Sdim } 925239462Sdim 926199990Srdivacky /// \brief Determine whether the output of this consumer is binary. 927199990Srdivacky bool isOutputBinary() const { return OutputIsBinary; } 928234353Sdim 929198092Srdivacky /// \brief Deregisters and destroys this code-completion consumer. 930198092Srdivacky virtual ~CodeCompleteConsumer(); 931199990Srdivacky 932198092Srdivacky /// \name Code-completion callbacks 933198092Srdivacky //@{ 934198092Srdivacky /// \brief Process the finalized code-completion results. 935234353Sdim virtual void ProcessCodeCompleteResults(Sema &S, 936212904Sdim CodeCompletionContext Context, 937212904Sdim CodeCompletionResult *Results, 938198092Srdivacky unsigned NumResults) { } 939199482Srdivacky 940199482Srdivacky /// \param S the semantic-analyzer object for which code-completion is being 941199482Srdivacky /// done. 942198092Srdivacky /// 943198092Srdivacky /// \param CurrentArg the index of the current argument. 944198092Srdivacky /// 945198092Srdivacky /// \param Candidates an array of overload candidates. 946198092Srdivacky /// 947198092Srdivacky /// \param NumCandidates the number of overload candidates 948199482Srdivacky virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, 949198092Srdivacky OverloadCandidate *Candidates, 950198092Srdivacky unsigned NumCandidates) { } 951198092Srdivacky //@} 952234353Sdim 953218893Sdim /// \brief Retrieve the allocator that will be used to allocate 954218893Sdim /// code completion strings. 955218893Sdim virtual CodeCompletionAllocator &getAllocator() = 0; 956234353Sdim 957234353Sdim virtual CodeCompletionTUInfo &getCodeCompletionTUInfo() = 0; 958198092Srdivacky}; 959212904Sdim 960234353Sdim/// \brief A simple code-completion consumer that prints the results it 961198092Srdivacky/// receives in a simple format. 962198092Srdivackyclass PrintingCodeCompleteConsumer : public CodeCompleteConsumer { 963198092Srdivacky /// \brief The raw output stream. 964226633Sdim raw_ostream &OS; 965234353Sdim 966234353Sdim CodeCompletionTUInfo CCTUInfo; 967234353Sdim 968198092Srdivackypublic: 969198092Srdivacky /// \brief Create a new printing code-completion consumer that prints its 970198092Srdivacky /// results to the given raw output stream. 971239462Sdim PrintingCodeCompleteConsumer(const CodeCompleteOptions &CodeCompleteOpts, 972226633Sdim raw_ostream &OS) 973239462Sdim : CodeCompleteConsumer(CodeCompleteOpts, false), OS(OS), 974234353Sdim CCTUInfo(new GlobalCodeCompletionAllocator) {} 975234353Sdim 976198092Srdivacky /// \brief Prints the finalized code-completion results. 977234353Sdim virtual void ProcessCodeCompleteResults(Sema &S, 978212904Sdim CodeCompletionContext Context, 979212904Sdim CodeCompletionResult *Results, 980198092Srdivacky unsigned NumResults); 981234353Sdim 982199482Srdivacky virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, 983198092Srdivacky OverloadCandidate *Candidates, 984234353Sdim unsigned NumCandidates); 985234353Sdim 986234353Sdim virtual CodeCompletionAllocator &getAllocator() { 987234353Sdim return CCTUInfo.getAllocator(); 988234353Sdim } 989234353Sdim 990234353Sdim virtual CodeCompletionTUInfo &getCodeCompletionTUInfo() { return CCTUInfo; } 991198092Srdivacky}; 992234353Sdim 993198092Srdivacky} // end namespace clang 994198092Srdivacky 995198092Srdivacky#endif // LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H 996