clang  6.0.0svn
CodeCompleteConsumer.cpp
Go to the documentation of this file.
1 //===--- CodeCompleteConsumer.cpp - Code Completion Interface ---*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the CodeCompleteConsumer class.
11 //
12 //===----------------------------------------------------------------------===//
14 #include "clang-c/Index.h"
15 #include "clang/AST/DeclCXX.h"
16 #include "clang/AST/DeclObjC.h"
17 #include "clang/AST/DeclTemplate.h"
18 #include "clang/Sema/Scope.h"
19 #include "clang/Sema/Sema.h"
20 #include "clang/Lex/Preprocessor.h"
21 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/ADT/SmallString.h"
23 #include "llvm/ADT/Twine.h"
24 #include "llvm/Support/raw_ostream.h"
25 #include <algorithm>
26 #include <cstring>
27 #include <functional>
28 
29 using namespace clang;
30 
31 //===----------------------------------------------------------------------===//
32 // Code completion context implementation
33 //===----------------------------------------------------------------------===//
34 
36  switch (Kind) {
37  case CCC_Recovery:
38  case CCC_Statement:
39  case CCC_Expression:
42  return true;
43 
44  case CCC_TopLevel:
45  case CCC_ObjCInterface:
47  case CCC_ObjCIvarList:
52  case CCC_EnumTag:
53  case CCC_UnionTag:
56  case CCC_Namespace:
57  case CCC_Type:
58  case CCC_Name:
60  case CCC_MacroName:
61  case CCC_MacroNameUse:
65  case CCC_SelectorName:
66  case CCC_TypeQualifiers:
67  case CCC_Other:
73  return false;
74  }
75 
76  llvm_unreachable("Invalid CodeCompletionContext::Kind!");
77 }
78 
79 //===----------------------------------------------------------------------===//
80 // Code completion string implementation
81 //===----------------------------------------------------------------------===//
83  : Kind(Kind), Text("")
84 {
85  switch (Kind) {
86  case CK_TypedText:
87  case CK_Text:
88  case CK_Placeholder:
89  case CK_Informative:
90  case CK_ResultType:
92  this->Text = Text;
93  break;
94 
95  case CK_Optional:
96  llvm_unreachable("Optional strings cannot be created from text");
97 
98  case CK_LeftParen:
99  this->Text = "(";
100  break;
101 
102  case CK_RightParen:
103  this->Text = ")";
104  break;
105 
106  case CK_LeftBracket:
107  this->Text = "[";
108  break;
109 
110  case CK_RightBracket:
111  this->Text = "]";
112  break;
113 
114  case CK_LeftBrace:
115  this->Text = "{";
116  break;
117 
118  case CK_RightBrace:
119  this->Text = "}";
120  break;
121 
122  case CK_LeftAngle:
123  this->Text = "<";
124  break;
125 
126  case CK_RightAngle:
127  this->Text = ">";
128  break;
129 
130  case CK_Comma:
131  this->Text = ", ";
132  break;
133 
134  case CK_Colon:
135  this->Text = ":";
136  break;
137 
138  case CK_SemiColon:
139  this->Text = ";";
140  break;
141 
142  case CK_Equal:
143  this->Text = " = ";
144  break;
145 
146  case CK_HorizontalSpace:
147  this->Text = " ";
148  break;
149 
150  case CK_VerticalSpace:
151  this->Text = "\n";
152  break;
153  }
154 }
155 
158  return Chunk(CK_Text, Text);
159 }
160 
163  Chunk Result;
164  Result.Kind = CK_Optional;
165  Result.Optional = Optional;
166  return Result;
167 }
168 
171  return Chunk(CK_Placeholder, Placeholder);
172 }
173 
176  return Chunk(CK_Informative, Informative);
177 }
178 
181  return Chunk(CK_ResultType, ResultType);
182 }
183 
186  const char *CurrentParameter) {
187  return Chunk(CK_CurrentParameter, CurrentParameter);
188 }
189 
190 CodeCompletionString::CodeCompletionString(const Chunk *Chunks,
191  unsigned NumChunks,
192  unsigned Priority,
193  CXAvailabilityKind Availability,
194  const char **Annotations,
195  unsigned NumAnnotations,
196  StringRef ParentName,
197  const char *BriefComment)
198  : NumChunks(NumChunks), NumAnnotations(NumAnnotations),
199  Priority(Priority), Availability(Availability),
200  ParentName(ParentName), BriefComment(BriefComment)
201 {
202  assert(NumChunks <= 0xffff);
203  assert(NumAnnotations <= 0xffff);
204 
205  Chunk *StoredChunks = reinterpret_cast<Chunk *>(this + 1);
206  for (unsigned I = 0; I != NumChunks; ++I)
207  StoredChunks[I] = Chunks[I];
208 
209  const char **StoredAnnotations = reinterpret_cast<const char **>(StoredChunks + NumChunks);
210  for (unsigned I = 0; I != NumAnnotations; ++I)
211  StoredAnnotations[I] = Annotations[I];
212 }
213 
215  return NumAnnotations;
216 }
217 
218 const char *CodeCompletionString::getAnnotation(unsigned AnnotationNr) const {
219  if (AnnotationNr < NumAnnotations)
220  return reinterpret_cast<const char * const*>(end())[AnnotationNr];
221  else
222  return nullptr;
223 }
224 
225 
227  std::string Result;
228  llvm::raw_string_ostream OS(Result);
229 
230  for (iterator C = begin(), CEnd = end(); C != CEnd; ++C) {
231  switch (C->Kind) {
232  case CK_Optional: OS << "{#" << C->Optional->getAsString() << "#}"; break;
233  case CK_Placeholder: OS << "<#" << C->Text << "#>"; break;
234 
235  case CK_Informative:
236  case CK_ResultType:
237  OS << "[#" << C->Text << "#]";
238  break;
239 
240  case CK_CurrentParameter: OS << "<#" << C->Text << "#>"; break;
241  default: OS << C->Text; break;
242  }
243  }
244  return OS.str();
245 }
246 
248  for (iterator C = begin(), CEnd = end(); C != CEnd; ++C)
249  if (C->Kind == CK_TypedText)
250  return C->Text;
251 
252  return nullptr;
253 }
254 
255 const char *CodeCompletionAllocator::CopyString(const Twine &String) {
256  SmallString<128> Data;
257  StringRef Ref = String.toStringRef(Data);
258  // FIXME: It would be more efficient to teach Twine to tell us its size and
259  // then add a routine there to fill in an allocated char* with the contents
260  // of the string.
261  char *Mem = (char *)Allocate(Ref.size() + 1, 1);
262  std::copy(Ref.begin(), Ref.end(), Mem);
263  Mem[Ref.size()] = 0;
264  return Mem;
265 }
266 
268  const NamedDecl *ND = dyn_cast<NamedDecl>(DC);
269  if (!ND)
270  return StringRef();
271 
272  // Check whether we've already cached the parent name.
273  StringRef &CachedParentName = ParentNames[DC];
274  if (!CachedParentName.empty())
275  return CachedParentName;
276 
277  // If we already processed this DeclContext and assigned empty to it, the
278  // data pointer will be non-null.
279  if (CachedParentName.data() != nullptr)
280  return StringRef();
281 
282  // Find the interesting names.
284  while (DC && !DC->isFunctionOrMethod()) {
285  if (const NamedDecl *ND = dyn_cast<NamedDecl>(DC)) {
286  if (ND->getIdentifier())
287  Contexts.push_back(DC);
288  }
289 
290  DC = DC->getParent();
291  }
292 
293  {
295  llvm::raw_svector_ostream OS(S);
296  bool First = true;
297  for (unsigned I = Contexts.size(); I != 0; --I) {
298  if (First)
299  First = false;
300  else {
301  OS << "::";
302  }
303 
304  const DeclContext *CurDC = Contexts[I-1];
305  if (const ObjCCategoryImplDecl *CatImpl = dyn_cast<ObjCCategoryImplDecl>(CurDC))
306  CurDC = CatImpl->getCategoryDecl();
307 
308  if (const ObjCCategoryDecl *Cat = dyn_cast<ObjCCategoryDecl>(CurDC)) {
309  const ObjCInterfaceDecl *Interface = Cat->getClassInterface();
310  if (!Interface) {
311  // Assign an empty StringRef but with non-null data to distinguish
312  // between empty because we didn't process the DeclContext yet.
313  CachedParentName = StringRef((const char *)(uintptr_t)~0U, 0);
314  return StringRef();
315  }
316 
317  OS << Interface->getName() << '(' << Cat->getName() << ')';
318  } else {
319  OS << cast<NamedDecl>(CurDC)->getName();
320  }
321  }
322 
323  CachedParentName = AllocatorRef->CopyString(OS.str());
324  }
325 
326  return CachedParentName;
327 }
328 
330  void *Mem = getAllocator().Allocate(
331  sizeof(CodeCompletionString) + sizeof(Chunk) * Chunks.size() +
332  sizeof(const char *) * Annotations.size(),
333  alignof(CodeCompletionString));
335  = new (Mem) CodeCompletionString(Chunks.data(), Chunks.size(),
336  Priority, Availability,
337  Annotations.data(), Annotations.size(),
338  ParentName, BriefComment);
339  Chunks.clear();
340  return Result;
341 }
342 
344  Chunks.push_back(Chunk(CodeCompletionString::CK_TypedText, Text));
345 }
346 
348  Chunks.push_back(Chunk::CreateText(Text));
349 }
350 
352  Chunks.push_back(Chunk::CreateOptional(Optional));
353 }
354 
355 void CodeCompletionBuilder::AddPlaceholderChunk(const char *Placeholder) {
356  Chunks.push_back(Chunk::CreatePlaceholder(Placeholder));
357 }
358 
360  Chunks.push_back(Chunk::CreateInformative(Text));
361 }
362 
363 void CodeCompletionBuilder::AddResultTypeChunk(const char *ResultType) {
364  Chunks.push_back(Chunk::CreateResultType(ResultType));
365 }
366 
367 void
368 CodeCompletionBuilder::AddCurrentParameterChunk(const char *CurrentParameter) {
369  Chunks.push_back(Chunk::CreateCurrentParameter(CurrentParameter));
370 }
371 
373  const char *Text) {
374  Chunks.push_back(Chunk(CK, Text));
375 }
376 
378  if (DC->isTranslationUnit()) {
379  return;
380  }
381 
382  if (DC->isFunctionOrMethod())
383  return;
384 
385  const NamedDecl *ND = dyn_cast<NamedDecl>(DC);
386  if (!ND)
387  return;
388 
389  ParentName = getCodeCompletionTUInfo().getParentName(DC);
390 }
391 
392 void CodeCompletionBuilder::addBriefComment(StringRef Comment) {
393  BriefComment = Allocator.CopyString(Comment);
394 }
395 
396 //===----------------------------------------------------------------------===//
397 // Code completion overload candidate implementation
398 //===----------------------------------------------------------------------===//
399 FunctionDecl *
401  if (getKind() == CK_Function)
402  return Function;
403  else if (getKind() == CK_FunctionTemplate)
404  return FunctionTemplate->getTemplatedDecl();
405  else
406  return nullptr;
407 }
408 
409 const FunctionType *
411  switch (Kind) {
412  case CK_Function:
413  return Function->getType()->getAs<FunctionType>();
414 
415  case CK_FunctionTemplate:
416  return FunctionTemplate->getTemplatedDecl()->getType()
417  ->getAs<FunctionType>();
418 
419  case CK_FunctionType:
420  return Type;
421  }
422 
423  llvm_unreachable("Invalid CandidateKind!");
424 }
425 
426 //===----------------------------------------------------------------------===//
427 // Code completion consumer implementation
428 //===----------------------------------------------------------------------===//
429 
431 
434  switch (Result.Kind) {
436  return !(Result.Declaration->getIdentifier() &&
437  Result.Declaration->getIdentifier()->getName().startswith(Filter));
438  }
440  return !StringRef(Result.Keyword).startswith(Filter);
441  }
443  return !Result.Macro->getName().startswith(Filter);
444  }
446  return !StringRef(Result.Pattern->getAsString()).startswith(Filter);
447  }
448  }
449  llvm_unreachable("Unknown code completion result Kind.");
450 }
451 
452 void
454  CodeCompletionContext Context,
455  CodeCompletionResult *Results,
456  unsigned NumResults) {
457  std::stable_sort(Results, Results + NumResults);
458 
459  StringRef Filter = SemaRef.getPreprocessor().getCodeCompletionFilter();
460 
461  // Print the results.
462  for (unsigned I = 0; I != NumResults; ++I) {
463  if(!Filter.empty() && isResultFilteredOut(Filter, Results[I]))
464  continue;
465  OS << "COMPLETION: ";
466  switch (Results[I].Kind) {
468  OS << *Results[I].Declaration;
469  if (Results[I].Hidden)
470  OS << " (Hidden)";
471  if (CodeCompletionString *CCS
472  = Results[I].CreateCodeCompletionString(SemaRef, Context,
473  getAllocator(),
474  CCTUInfo,
475  includeBriefComments())) {
476  OS << " : " << CCS->getAsString();
477  if (const char *BriefComment = CCS->getBriefComment())
478  OS << " : " << BriefComment;
479  }
480 
481  OS << '\n';
482  break;
483 
485  OS << Results[I].Keyword << '\n';
486  break;
487 
489  OS << Results[I].Macro->getName();
490  if (CodeCompletionString *CCS
491  = Results[I].CreateCodeCompletionString(SemaRef, Context,
492  getAllocator(),
493  CCTUInfo,
494  includeBriefComments())) {
495  OS << " : " << CCS->getAsString();
496  }
497  OS << '\n';
498  break;
499  }
500 
502  OS << "Pattern : "
503  << Results[I].Pattern->getAsString() << '\n';
504  break;
505  }
506  }
507  }
508 }
509 
510 // This function is used solely to preserve the former presentation of overloads
511 // by "clang -cc1 -code-completion-at", since CodeCompletionString::getAsString
512 // needs to be improved for printing the newer and more detailed overload
513 // chunks.
514 static std::string getOverloadAsString(const CodeCompletionString &CCS) {
515  std::string Result;
516  llvm::raw_string_ostream OS(Result);
517 
518  for (auto &C : CCS) {
519  switch (C.Kind) {
522  OS << "[#" << C.Text << "#]";
523  break;
524 
526  OS << "<#" << C.Text << "#>";
527  break;
528 
529  default: OS << C.Text; break;
530  }
531  }
532  return OS.str();
533 }
534 
535 void
537  unsigned CurrentArg,
538  OverloadCandidate *Candidates,
539  unsigned NumCandidates) {
540  for (unsigned I = 0; I != NumCandidates; ++I) {
541  if (CodeCompletionString *CCS
542  = Candidates[I].CreateSignatureString(CurrentArg, SemaRef,
543  getAllocator(), CCTUInfo,
544  includeBriefComments())) {
545  OS << "OVERLOAD: " << getOverloadAsString(*CCS) << "\n";
546  }
547  }
548 }
549 
550 /// \brief Retrieve the effective availability of the given declaration.
553  if (isa<EnumConstantDecl>(D))
554  AR = std::max(AR, cast<Decl>(D->getDeclContext())->getAvailability());
555  return AR;
556 }
557 
558 void CodeCompletionResult::computeCursorKindAndAvailability(bool Accessible) {
559  switch (Kind) {
560  case RK_Pattern:
561  if (!Declaration) {
562  // Do nothing: Patterns can come with cursor kinds!
563  break;
564  }
565  // Fall through
566 
567  case RK_Declaration: {
568  // Set the availability based on attributes.
569  switch (getDeclAvailability(Declaration)) {
570  case AR_Available:
571  case AR_NotYetIntroduced:
572  Availability = CXAvailability_Available;
573  break;
574 
575  case AR_Deprecated:
576  Availability = CXAvailability_Deprecated;
577  break;
578 
579  case AR_Unavailable:
580  Availability = CXAvailability_NotAvailable;
581  break;
582  }
583 
584  if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(Declaration))
585  if (Function->isDeleted())
586  Availability = CXAvailability_NotAvailable;
587 
588  CursorKind = getCursorKindForDecl(Declaration);
589  if (CursorKind == CXCursor_UnexposedDecl) {
590  // FIXME: Forward declarations of Objective-C classes and protocols
591  // are not directly exposed, but we want code completion to treat them
592  // like a definition.
593  if (isa<ObjCInterfaceDecl>(Declaration))
594  CursorKind = CXCursor_ObjCInterfaceDecl;
595  else if (isa<ObjCProtocolDecl>(Declaration))
596  CursorKind = CXCursor_ObjCProtocolDecl;
597  else
598  CursorKind = CXCursor_NotImplemented;
599  }
600  break;
601  }
602 
603  case RK_Macro:
604  case RK_Keyword:
605  llvm_unreachable("Macro and keyword kinds are handled by the constructors");
606  }
607 
608  if (!Accessible)
609  Availability = CXAvailability_NotAccessible;
610 }
611 
612 /// \brief Retrieve the name that should be used to order a result.
613 ///
614 /// If the name needs to be constructed as a string, that string will be
615 /// saved into Saved and the returned StringRef will refer to it.
616 StringRef CodeCompletionResult::getOrderedName(std::string &Saved) const {
617  switch (Kind) {
618  case RK_Keyword:
619  return Keyword;
620  case RK_Pattern:
621  return Pattern->getTypedText();
622  case RK_Macro:
623  return Macro->getName();
624  case RK_Declaration:
625  // Handle declarations below.
626  break;
627  }
628 
629  DeclarationName Name = Declaration->getDeclName();
630 
631  // If the name is a simple identifier (by far the common case), or a
632  // zero-argument selector, just return a reference to that identifier.
633  if (IdentifierInfo *Id = Name.getAsIdentifierInfo())
634  return Id->getName();
635  if (Name.isObjCZeroArgSelector())
636  if (IdentifierInfo *Id
638  return Id->getName();
639 
640  Saved = Name.getAsString();
641  return Saved;
642 }
643 
645  const CodeCompletionResult &Y) {
646  std::string XSaved, YSaved;
647  StringRef XStr = X.getOrderedName(XSaved);
648  StringRef YStr = Y.getOrderedName(YSaved);
649  int cmp = XStr.compare_lower(YStr);
650  if (cmp)
651  return cmp < 0;
652 
653  // If case-insensitive comparison fails, try case-sensitive comparison.
654  cmp = XStr.compare(YStr);
655  if (cmp)
656  return cmp < 0;
657 
658  return false;
659 }
One piece of the code completion string.
An unknown context, in which we are recovering from a parsing error and don&#39;t know which completions ...
A code completion string that is entirely optional.
CXAvailabilityKind
Describes the availability of a particular entity, which indicates whether the use of this entity wil...
Definition: Index.h:131
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1698
ResultKind Kind
The kind of result stored here.
StringRef getParentName(const DeclContext *DC)
Code completion for a selector, as in an @selector expression.
const FunctionType * getFunctionType() const
Retrieve the function type of the entity, regardless of how the function is stored.
void AddTextChunk(const char *Text)
Add a new text chunk.
Code completion where an Objective-C class message is expected.
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3058
FunctionDecl * getFunction() const
Retrieve the function overload candidate or the templated function declaration for a function templat...
Code completion within a type-qualifier list.
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
void AddChunk(CodeCompletionString::ChunkKind CK, const char *Text="")
Add a new chunk.
Selector getObjCSelector() const
getObjCSelector - Get the Objective-C selector stored in this declaration name.
Defines the C++ template declaration subclasses.
static Chunk CreateText(const char *Text)
Create a new text chunk.
The base class of the type hierarchy.
Definition: Type.h:1353
An unspecified code-completion context.
static Chunk CreateOptional(CodeCompletionString *Optional)
Create a new optional chunk.
Code completion occurred where an Objective-C message receiver is expected.
unsigned getAnnotationCount() const
Retrieve the number of annotations for this code completion result.
Code completion occurred on the right-hand side of a member access expression using the arrow operato...
ChunkKind
The different kinds of "chunks" that can occur within a code completion string.
Code completion occurred after the "enum" keyword, to indicate an enumeration name.
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6307
A piece of text that describes the type of an entity or, for functions and methods, the return type.
const char * Keyword
When Kind == RK_Keyword, the string representing the keyword or symbol&#39;s spelling.
static Chunk CreateResultType(const char *ResultType)
Create a new result type chunk.
void AddOptionalChunk(CodeCompletionString *Optional)
Add a new optional chunk.
Code completion occurred within the instance variable list of an Objective-C interface, implementation, or category implementation.
void AddTypedTextChunk(const char *Text)
Add a new typed-text chunk.
The entity is not available; any use of it will be an error.
Definition: Index.h:144
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
Definition: Decl.h:265
One of these records is kept for each identifier that is lexed.
CodeCompletionString * TakeString()
Take the resulting completion string.
static Chunk CreateInformative(const char *Informative)
Create a new informative chunk.
A "string" used to describe how code completion can be performed for an entity.
An Objective-C @protocol declaration.
Definition: Index.h:1728
void AddResultTypeChunk(const char *ResultType)
Add a new result-type chunk.
static Chunk CreatePlaceholder(const char *Placeholder)
Create a new placeholder chunk.
CodeCompletionString * Pattern
When Kind == RK_Pattern, the code-completion string that describes the completion text to insert...
Code completion occurred where a preprocessor directive is expected.
Code completion occurred within an Objective-C implementation or category implementation.
Code completion occurred where a namespace or namespace alias is expected.
static Chunk CreateCurrentParameter(const char *CurrentParameter)
Create a new current-parameter chunk.
Represents an ObjC class declaration.
Definition: DeclObjC.h:1191
The piece of text that the user is expected to type to match the code-completion string, typically a keyword or the name of a declarator or macro.
A comma separator (&#39;,&#39;).
bool wantConstructorResults() const
Determines whether we want C++ constructors as results within this context.
AvailabilityResult
Captures the result of checking the availability of a declaration.
Definition: DeclBase.h:72
A right parenthesis (&#39;)&#39;).
Code completion where an Objective-C category name is expected.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:274
Code completion occurred within a "top-level" completion context, e.g., at namespace or global scope...
static std::string getOverloadAsString(const CodeCompletionString &CCS)
Code completion occurred where a protocol name is expected.
CXCursorKind getCursorKindForDecl(const Decl *D)
Determine the libclang cursor kind associated with the given declaration.
Code completion occurred where a new name is expected.
int Id
Definition: ASTDiff.cpp:191
std::string getAsString() const
Retrieve a string representation of the code completion string, which is mainly useful for debugging...
const char * Text
The text string associated with a CK_Text, CK_Placeholder, CK_Informative, or CK_Comma chunk...
std::string getAsString() const
getNameAsString - Retrieve the human-readable string for this name.
Defines the clang::Preprocessor interface.
const NamedDecl * Declaration
When Kind == RK_Declaration or RK_Pattern, the declaration we are referring to.
DeclContext * getDeclContext()
Definition: DeclBase.h:425
IdentifierInfo * getAsIdentifierInfo() const
getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in this declaration name, or NULL if this declaration name isn&#39;t a simple identifier.
Captures a result of code completion.
Code completion occurred where a new name is expected and a qualified name is permissible.
bool isFunctionOrMethod() const
Definition: DeclBase.h:1380
Code completion in a parenthesized expression, which means that we may also have types here in C and ...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1331
Code completion occurred in a context where natural language is expected, e.g., a comment or string l...
Preprocessor & getPreprocessor() const
Definition: Sema.h:1199
A piece of text that should be placed in the buffer, e.g., parentheses or a comma in a function call...
The result type of a method or function.
const char * CopyString(const Twine &String)
Copy the given string into this allocator.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Definition: opencl-c.h:82
const char * getTypedText() const
Returns the text in the TypedText chunk.
CodeCompletionString * Optional
The code completion string associated with a CK_Optional chunk.
The context in which code completion occurred, so that the code-completion consumer can process the r...
const IdentifierInfo * Macro
When Kind == RK_Macro, the identifier that refers to a macro.
Code completion occurred within a class, struct, or union.
Kind
IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
const char * getAnnotation(unsigned AnnotationNr) const
Retrieve the annotation string specified by AnnotationNr.
Code completion where the name of an Objective-C class is expected.
Code completion occurred within an Objective-C interface, protocol, or category interface.
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2299
The entity is available.
Definition: Index.h:135
void addParentContext(const DeclContext *DC)
Add the parent context information to this code completion.
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
The entity is available, but not accessible; any use of it will be an error.
Definition: Index.h:149
ChunkKind Kind
The kind of data stored in this piece of the code completion string.
void addBriefComment(StringRef Comment)
StringRef getName() const
Return the actual identifier string.
Dataflow Directional Tag Classes.
Code completion occurred where an macro is being defined.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1252
A piece of text that describes something about the result but should not be inserted into the buffer...
Code completion occurred after the "struct" or "class" keyword, to indicate a struct or class name...
static AvailabilityResult getDeclAvailability(const Decl *D)
Retrieve the effective availability of the given declaration.
void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context, CodeCompletionResult *Results, unsigned NumResults) override
Prints the finalized code-completion results.
Code completion occurred after the "union" keyword, to indicate a union name.
Code completion occurred where a macro name is expected (without any arguments, in the case of a func...
Code completion where an Objective-C instance message is expected.
DeclarationName - The name of a declaration.
StringRef getCodeCompletionFilter()
Get the code completion token for filtering purposes.
Refers to a precomputed pattern.
Code completion occurred where a statement (or declaration) is expected in a function, method, or block.
Code completion occurred on the right-hand side of an Objective-C property access expression...
void AddInformativeChunk(const char *Text)
Add a new informative chunk.
AvailabilityResult getAvailability(std::string *Message=nullptr, VersionTuple EnclosingVersion=VersionTuple()) const
Determine the availability of the given declaration.
Definition: DeclBase.cpp:581
void AddCurrentParameterChunk(const char *CurrentParameter)
Add a new current-parameter chunk.
A declaration whose specific kind is not exposed via this interface.
Definition: Index.h:1701
A piece of text that describes the parameter that corresponds to the code-completion location within ...
A string that acts as a placeholder for, e.g., a function call argument.
unsigned getAvailability() const
Retrieve the availability of this code completion result.
char __ovld __cnfn max(char x, char y)
Returns y if x < y, otherwise it returns x.
A left parenthesis (&#39;(&#39;).
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
Definition: SemaDecl.cpp:13010
Code completion occurred within a preprocessor expression.
Code completion occurred where an expression is expected.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
An unspecified code-completion context where we should also add macro completions.
A left angle bracket (&#39;<&#39;).
A right angle bracket (&#39;>&#39;).
Vertical whitespace (&#39;\n&#39; or &#39;\r\n&#39;, depending on the platform).
void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, OverloadCandidate *Candidates, unsigned NumCandidates) override
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:270
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:915
StringRef getOrderedName(std::string &Saved) const
Retrieve the name that should be used to order a result.
Code completion occurred on the right-hand side of a member access expression using the dot operator...
void AddPlaceholderChunk(const char *Placeholder)
Add a new placeholder chunk.
Code completion occurred where a type name is expected.
Horizontal whitespace (&#39; &#39;).
StringRef Text
Definition: Format.cpp:1346
bool isResultFilteredOut(StringRef Filter, CodeCompletionResult Results) override
The entity is available, but has been deprecated (and its use is not recommended).
Definition: Index.h:140
NamedDecl - This represents a decl with a name.
Definition: Decl.h:245
bool isTranslationUnit() const
Definition: DeclBase.h:1401
An Objective-C @interface.
Definition: Index.h:1724
virtual ~CodeCompleteConsumer()
Deregisters and destroys this code-completion consumer.
bool isObjCZeroArgSelector() const
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
Definition: DeclObjC.h:2518