clang  8.0.0svn
CodeCompleteConsumer.cpp
Go to the documentation of this file.
1 //===- CodeCompleteConsumer.cpp - Code Completion Interface ---------------===//
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 //===----------------------------------------------------------------------===//
13 
15 #include "clang-c/Index.h"
16 #include "clang/AST/Decl.h"
17 #include "clang/AST/DeclBase.h"
18 #include "clang/AST/DeclObjC.h"
19 #include "clang/AST/DeclTemplate.h"
21 #include "clang/AST/Type.h"
23 #include "clang/Lex/Preprocessor.h"
24 #include "clang/Sema/Sema.h"
25 #include "llvm/ADT/SmallString.h"
26 #include "llvm/ADT/SmallVector.h"
27 #include "llvm/ADT/StringRef.h"
28 #include "llvm/ADT/Twine.h"
29 #include "llvm/Support/Casting.h"
30 #include "llvm/Support/Compiler.h"
31 #include "llvm/Support/ErrorHandling.h"
32 #include "llvm/Support/FormatVariadic.h"
33 #include "llvm/Support/raw_ostream.h"
34 #include <algorithm>
35 #include <cassert>
36 #include <cstdint>
37 #include <string>
38 
39 using namespace clang;
40 
41 //===----------------------------------------------------------------------===//
42 // Code completion context implementation
43 //===----------------------------------------------------------------------===//
44 
46  switch (CCKind) {
47  case CCC_Recovery:
48  case CCC_Statement:
49  case CCC_Expression:
52  return true;
53 
54  case CCC_TopLevel:
55  case CCC_ObjCInterface:
57  case CCC_ObjCIvarList:
62  case CCC_EnumTag:
63  case CCC_UnionTag:
66  case CCC_Namespace:
67  case CCC_Type:
68  case CCC_Name:
70  case CCC_MacroName:
71  case CCC_MacroNameUse:
75  case CCC_SelectorName:
76  case CCC_TypeQualifiers:
77  case CCC_Other:
83  case CCC_IncludedFile:
84  return false;
85  }
86 
87  llvm_unreachable("Invalid CodeCompletionContext::Kind!");
88 }
89 
91  using CCKind = CodeCompletionContext::Kind;
92  switch (Kind) {
93  case CCKind::CCC_Other:
94  return "Other";
95  case CCKind::CCC_OtherWithMacros:
96  return "OtherWithMacros";
97  case CCKind::CCC_TopLevel:
98  return "TopLevel";
99  case CCKind::CCC_ObjCInterface:
100  return "ObjCInterface";
101  case CCKind::CCC_ObjCImplementation:
102  return "ObjCImplementation";
103  case CCKind::CCC_ObjCIvarList:
104  return "ObjCIvarList";
105  case CCKind::CCC_ClassStructUnion:
106  return "ClassStructUnion";
107  case CCKind::CCC_Statement:
108  return "Statement";
109  case CCKind::CCC_Expression:
110  return "Expression";
111  case CCKind::CCC_ObjCMessageReceiver:
112  return "ObjCMessageReceiver";
113  case CCKind::CCC_DotMemberAccess:
114  return "DotMemberAccess";
115  case CCKind::CCC_ArrowMemberAccess:
116  return "ArrowMemberAccess";
117  case CCKind::CCC_ObjCPropertyAccess:
118  return "ObjCPropertyAccess";
119  case CCKind::CCC_EnumTag:
120  return "EnumTag";
121  case CCKind::CCC_UnionTag:
122  return "UnionTag";
123  case CCKind::CCC_ClassOrStructTag:
124  return "ClassOrStructTag";
125  case CCKind::CCC_ObjCProtocolName:
126  return "ObjCProtocolName";
127  case CCKind::CCC_Namespace:
128  return "Namespace";
129  case CCKind::CCC_Type:
130  return "Type";
131  case CCKind::CCC_Name:
132  return "Name";
133  case CCKind::CCC_PotentiallyQualifiedName:
134  return "PotentiallyQualifiedName";
135  case CCKind::CCC_MacroName:
136  return "MacroName";
137  case CCKind::CCC_MacroNameUse:
138  return "MacroNameUse";
139  case CCKind::CCC_PreprocessorExpression:
140  return "PreprocessorExpression";
141  case CCKind::CCC_PreprocessorDirective:
142  return "PreprocessorDirective";
143  case CCKind::CCC_NaturalLanguage:
144  return "NaturalLanguage";
145  case CCKind::CCC_SelectorName:
146  return "SelectorName";
147  case CCKind::CCC_TypeQualifiers:
148  return "TypeQualifiers";
149  case CCKind::CCC_ParenthesizedExpression:
150  return "ParenthesizedExpression";
151  case CCKind::CCC_ObjCInstanceMessage:
152  return "ObjCInstanceMessage";
153  case CCKind::CCC_ObjCClassMessage:
154  return "ObjCClassMessage";
155  case CCKind::CCC_ObjCInterfaceName:
156  return "ObjCInterfaceName";
157  case CCKind::CCC_ObjCCategoryName:
158  return "ObjCCategoryName";
159  case CCKind::CCC_IncludedFile:
160  return "IncludedFile";
161  case CCKind::CCC_Recovery:
162  return "Recovery";
163  }
164  llvm_unreachable("Invalid CodeCompletionContext::Kind!");
165 }
166 
167 //===----------------------------------------------------------------------===//
168 // Code completion string implementation
169 //===----------------------------------------------------------------------===//
170 
172  : Kind(Kind), Text("") {
173  switch (Kind) {
174  case CK_TypedText:
175  case CK_Text:
176  case CK_Placeholder:
177  case CK_Informative:
178  case CK_ResultType:
179  case CK_CurrentParameter:
180  this->Text = Text;
181  break;
182 
183  case CK_Optional:
184  llvm_unreachable("Optional strings cannot be created from text");
185 
186  case CK_LeftParen:
187  this->Text = "(";
188  break;
189 
190  case CK_RightParen:
191  this->Text = ")";
192  break;
193 
194  case CK_LeftBracket:
195  this->Text = "[";
196  break;
197 
198  case CK_RightBracket:
199  this->Text = "]";
200  break;
201 
202  case CK_LeftBrace:
203  this->Text = "{";
204  break;
205 
206  case CK_RightBrace:
207  this->Text = "}";
208  break;
209 
210  case CK_LeftAngle:
211  this->Text = "<";
212  break;
213 
214  case CK_RightAngle:
215  this->Text = ">";
216  break;
217 
218  case CK_Comma:
219  this->Text = ", ";
220  break;
221 
222  case CK_Colon:
223  this->Text = ":";
224  break;
225 
226  case CK_SemiColon:
227  this->Text = ";";
228  break;
229 
230  case CK_Equal:
231  this->Text = " = ";
232  break;
233 
234  case CK_HorizontalSpace:
235  this->Text = " ";
236  break;
237 
238  case CK_VerticalSpace:
239  this->Text = "\n";
240  break;
241  }
242 }
243 
246  return Chunk(CK_Text, Text);
247 }
248 
251  Chunk Result;
252  Result.Kind = CK_Optional;
253  Result.Optional = Optional;
254  return Result;
255 }
256 
259  return Chunk(CK_Placeholder, Placeholder);
260 }
261 
264  return Chunk(CK_Informative, Informative);
265 }
266 
269  return Chunk(CK_ResultType, ResultType);
270 }
271 
274  const char *CurrentParameter) {
275  return Chunk(CK_CurrentParameter, CurrentParameter);
276 }
277 
278 CodeCompletionString::CodeCompletionString(const Chunk *Chunks,
279  unsigned NumChunks,
280  unsigned Priority,
281  CXAvailabilityKind Availability,
282  const char **Annotations,
283  unsigned NumAnnotations,
284  StringRef ParentName,
285  const char *BriefComment)
286  : NumChunks(NumChunks), NumAnnotations(NumAnnotations),
287  Priority(Priority), Availability(Availability),
288  ParentName(ParentName), BriefComment(BriefComment) {
289  assert(NumChunks <= 0xffff);
290  assert(NumAnnotations <= 0xffff);
291 
292  Chunk *StoredChunks = reinterpret_cast<Chunk *>(this + 1);
293  for (unsigned I = 0; I != NumChunks; ++I)
294  StoredChunks[I] = Chunks[I];
295 
296  const char **StoredAnnotations = reinterpret_cast<const char **>(StoredChunks + NumChunks);
297  for (unsigned I = 0; I != NumAnnotations; ++I)
298  StoredAnnotations[I] = Annotations[I];
299 }
300 
302  return NumAnnotations;
303 }
304 
305 const char *CodeCompletionString::getAnnotation(unsigned AnnotationNr) const {
306  if (AnnotationNr < NumAnnotations)
307  return reinterpret_cast<const char * const*>(end())[AnnotationNr];
308  else
309  return nullptr;
310 }
311 
313  std::string Result;
314  llvm::raw_string_ostream OS(Result);
315 
316  for (iterator C = begin(), CEnd = end(); C != CEnd; ++C) {
317  switch (C->Kind) {
318  case CK_Optional: OS << "{#" << C->Optional->getAsString() << "#}"; break;
319  case CK_Placeholder: OS << "<#" << C->Text << "#>"; break;
320 
321  case CK_Informative:
322  case CK_ResultType:
323  OS << "[#" << C->Text << "#]";
324  break;
325 
326  case CK_CurrentParameter: OS << "<#" << C->Text << "#>"; break;
327  default: OS << C->Text; break;
328  }
329  }
330  return OS.str();
331 }
332 
334  for (iterator C = begin(), CEnd = end(); C != CEnd; ++C)
335  if (C->Kind == CK_TypedText)
336  return C->Text;
337 
338  return nullptr;
339 }
340 
341 const char *CodeCompletionAllocator::CopyString(const Twine &String) {
342  SmallString<128> Data;
343  StringRef Ref = String.toStringRef(Data);
344  // FIXME: It would be more efficient to teach Twine to tell us its size and
345  // then add a routine there to fill in an allocated char* with the contents
346  // of the string.
347  char *Mem = (char *)Allocate(Ref.size() + 1, 1);
348  std::copy(Ref.begin(), Ref.end(), Mem);
349  Mem[Ref.size()] = 0;
350  return Mem;
351 }
352 
354  const NamedDecl *ND = dyn_cast<NamedDecl>(DC);
355  if (!ND)
356  return {};
357 
358  // Check whether we've already cached the parent name.
359  StringRef &CachedParentName = ParentNames[DC];
360  if (!CachedParentName.empty())
361  return CachedParentName;
362 
363  // If we already processed this DeclContext and assigned empty to it, the
364  // data pointer will be non-null.
365  if (CachedParentName.data() != nullptr)
366  return {};
367 
368  // Find the interesting names.
370  while (DC && !DC->isFunctionOrMethod()) {
371  if (const NamedDecl *ND = dyn_cast<NamedDecl>(DC)) {
372  if (ND->getIdentifier())
373  Contexts.push_back(DC);
374  }
375 
376  DC = DC->getParent();
377  }
378 
379  {
381  llvm::raw_svector_ostream OS(S);
382  bool First = true;
383  for (unsigned I = Contexts.size(); I != 0; --I) {
384  if (First)
385  First = false;
386  else {
387  OS << "::";
388  }
389 
390  const DeclContext *CurDC = Contexts[I-1];
391  if (const ObjCCategoryImplDecl *CatImpl = dyn_cast<ObjCCategoryImplDecl>(CurDC))
392  CurDC = CatImpl->getCategoryDecl();
393 
394  if (const ObjCCategoryDecl *Cat = dyn_cast<ObjCCategoryDecl>(CurDC)) {
395  const ObjCInterfaceDecl *Interface = Cat->getClassInterface();
396  if (!Interface) {
397  // Assign an empty StringRef but with non-null data to distinguish
398  // between empty because we didn't process the DeclContext yet.
399  CachedParentName = StringRef((const char *)(uintptr_t)~0U, 0);
400  return {};
401  }
402 
403  OS << Interface->getName() << '(' << Cat->getName() << ')';
404  } else {
405  OS << cast<NamedDecl>(CurDC)->getName();
406  }
407  }
408 
409  CachedParentName = AllocatorRef->CopyString(OS.str());
410  }
411 
412  return CachedParentName;
413 }
414 
416  void *Mem = getAllocator().Allocate(
417  sizeof(CodeCompletionString) + sizeof(Chunk) * Chunks.size() +
418  sizeof(const char *) * Annotations.size(),
419  alignof(CodeCompletionString));
421  = new (Mem) CodeCompletionString(Chunks.data(), Chunks.size(),
422  Priority, Availability,
423  Annotations.data(), Annotations.size(),
424  ParentName, BriefComment);
425  Chunks.clear();
426  return Result;
427 }
428 
430  Chunks.push_back(Chunk(CodeCompletionString::CK_TypedText, Text));
431 }
432 
434  Chunks.push_back(Chunk::CreateText(Text));
435 }
436 
438  Chunks.push_back(Chunk::CreateOptional(Optional));
439 }
440 
441 void CodeCompletionBuilder::AddPlaceholderChunk(const char *Placeholder) {
442  Chunks.push_back(Chunk::CreatePlaceholder(Placeholder));
443 }
444 
446  Chunks.push_back(Chunk::CreateInformative(Text));
447 }
448 
449 void CodeCompletionBuilder::AddResultTypeChunk(const char *ResultType) {
450  Chunks.push_back(Chunk::CreateResultType(ResultType));
451 }
452 
453 void
454 CodeCompletionBuilder::AddCurrentParameterChunk(const char *CurrentParameter) {
455  Chunks.push_back(Chunk::CreateCurrentParameter(CurrentParameter));
456 }
457 
459  const char *Text) {
460  Chunks.push_back(Chunk(CK, Text));
461 }
462 
464  if (DC->isTranslationUnit())
465  return;
466 
467  if (DC->isFunctionOrMethod())
468  return;
469 
470  const NamedDecl *ND = dyn_cast<NamedDecl>(DC);
471  if (!ND)
472  return;
473 
474  ParentName = getCodeCompletionTUInfo().getParentName(DC);
475 }
476 
477 void CodeCompletionBuilder::addBriefComment(StringRef Comment) {
478  BriefComment = Allocator.CopyString(Comment);
479 }
480 
481 //===----------------------------------------------------------------------===//
482 // Code completion overload candidate implementation
483 //===----------------------------------------------------------------------===//
484 FunctionDecl *
486  if (getKind() == CK_Function)
487  return Function;
488  else if (getKind() == CK_FunctionTemplate)
489  return FunctionTemplate->getTemplatedDecl();
490  else
491  return nullptr;
492 }
493 
494 const FunctionType *
496  switch (Kind) {
497  case CK_Function:
498  return Function->getType()->getAs<FunctionType>();
499 
500  case CK_FunctionTemplate:
501  return FunctionTemplate->getTemplatedDecl()->getType()
502  ->getAs<FunctionType>();
503 
504  case CK_FunctionType:
505  return Type;
506  }
507 
508  llvm_unreachable("Invalid CandidateKind!");
509 }
510 
511 //===----------------------------------------------------------------------===//
512 // Code completion consumer implementation
513 //===----------------------------------------------------------------------===//
514 
516 
519  switch (Result.Kind) {
521  return !(Result.Declaration->getIdentifier() &&
522  Result.Declaration->getIdentifier()->getName().startswith(Filter));
524  return !StringRef(Result.Keyword).startswith(Filter);
526  return !Result.Macro->getName().startswith(Filter);
528  return !(Result.Pattern->getTypedText() &&
529  StringRef(Result.Pattern->getTypedText()).startswith(Filter));
530  }
531  llvm_unreachable("Unknown code completion result Kind.");
532 }
533 
534 void
536  CodeCompletionContext Context,
537  CodeCompletionResult *Results,
538  unsigned NumResults) {
539  std::stable_sort(Results, Results + NumResults);
540 
541  StringRef Filter = SemaRef.getPreprocessor().getCodeCompletionFilter();
542 
543  // Print the results.
544  for (unsigned I = 0; I != NumResults; ++I) {
545  if(!Filter.empty() && isResultFilteredOut(Filter, Results[I]))
546  continue;
547  OS << "COMPLETION: ";
548  switch (Results[I].Kind) {
550  OS << *Results[I].Declaration;
551  if (Results[I].Hidden)
552  OS << " (Hidden)";
553  if (CodeCompletionString *CCS
554  = Results[I].CreateCodeCompletionString(SemaRef, Context,
555  getAllocator(),
556  CCTUInfo,
557  includeBriefComments())) {
558  OS << " : " << CCS->getAsString();
559  if (const char *BriefComment = CCS->getBriefComment())
560  OS << " : " << BriefComment;
561  }
562  for (const FixItHint &FixIt : Results[I].FixIts) {
563  const SourceLocation BLoc = FixIt.RemoveRange.getBegin();
564  const SourceLocation ELoc = FixIt.RemoveRange.getEnd();
565 
566  SourceManager &SM = SemaRef.SourceMgr;
567  std::pair<FileID, unsigned> BInfo = SM.getDecomposedLoc(BLoc);
568  std::pair<FileID, unsigned> EInfo = SM.getDecomposedLoc(ELoc);
569  // Adjust for token ranges.
570  if (FixIt.RemoveRange.isTokenRange())
571  EInfo.second += Lexer::MeasureTokenLength(ELoc, SM, SemaRef.LangOpts);
572 
573  OS << " (requires fix-it:"
574  << " {" << SM.getLineNumber(BInfo.first, BInfo.second) << ':'
575  << SM.getColumnNumber(BInfo.first, BInfo.second) << '-'
576  << SM.getLineNumber(EInfo.first, EInfo.second) << ':'
577  << SM.getColumnNumber(EInfo.first, EInfo.second) << "}"
578  << " to \"" << FixIt.CodeToInsert << "\")";
579  }
580  OS << '\n';
581  break;
582 
584  OS << Results[I].Keyword << '\n';
585  break;
586 
588  OS << Results[I].Macro->getName();
589  if (CodeCompletionString *CCS
590  = Results[I].CreateCodeCompletionString(SemaRef, Context,
591  getAllocator(),
592  CCTUInfo,
593  includeBriefComments())) {
594  OS << " : " << CCS->getAsString();
595  }
596  OS << '\n';
597  break;
598 
600  OS << "Pattern : "
601  << Results[I].Pattern->getAsString() << '\n';
602  break;
603  }
604  }
605 }
606 
607 // This function is used solely to preserve the former presentation of overloads
608 // by "clang -cc1 -code-completion-at", since CodeCompletionString::getAsString
609 // needs to be improved for printing the newer and more detailed overload
610 // chunks.
611 static std::string getOverloadAsString(const CodeCompletionString &CCS) {
612  std::string Result;
613  llvm::raw_string_ostream OS(Result);
614 
615  for (auto &C : CCS) {
616  switch (C.Kind) {
619  OS << "[#" << C.Text << "#]";
620  break;
621 
623  OS << "<#" << C.Text << "#>";
624  break;
625 
626  // FIXME: We can also print optional parameters of an overload.
628  break;
629 
630  default: OS << C.Text; break;
631  }
632  }
633  return OS.str();
634 }
635 
637  Sema &SemaRef, unsigned CurrentArg, OverloadCandidate *Candidates,
638  unsigned NumCandidates, SourceLocation OpenParLoc) {
639  OS << "OPENING_PAREN_LOC: ";
640  OpenParLoc.print(OS, SemaRef.getSourceManager());
641  OS << "\n";
642 
643  for (unsigned I = 0; I != NumCandidates; ++I) {
644  if (CodeCompletionString *CCS = Candidates[I].CreateSignatureString(
645  CurrentArg, SemaRef, getAllocator(), CCTUInfo,
646  includeBriefComments())) {
647  OS << "OVERLOAD: " << getOverloadAsString(*CCS) << "\n";
648  }
649  }
650 }
651 
652 /// Retrieve the effective availability of the given declaration.
655  if (isa<EnumConstantDecl>(D))
656  AR = std::max(AR, cast<Decl>(D->getDeclContext())->getAvailability());
657  return AR;
658 }
659 
660 void CodeCompletionResult::computeCursorKindAndAvailability(bool Accessible) {
661  switch (Kind) {
662  case RK_Pattern:
663  if (!Declaration) {
664  // Do nothing: Patterns can come with cursor kinds!
665  break;
666  }
667  LLVM_FALLTHROUGH;
668 
669  case RK_Declaration: {
670  // Set the availability based on attributes.
671  switch (getDeclAvailability(Declaration)) {
672  case AR_Available:
673  case AR_NotYetIntroduced:
674  Availability = CXAvailability_Available;
675  break;
676 
677  case AR_Deprecated:
678  Availability = CXAvailability_Deprecated;
679  break;
680 
681  case AR_Unavailable:
682  Availability = CXAvailability_NotAvailable;
683  break;
684  }
685 
686  if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(Declaration))
687  if (Function->isDeleted())
688  Availability = CXAvailability_NotAvailable;
689 
690  CursorKind = getCursorKindForDecl(Declaration);
691  if (CursorKind == CXCursor_UnexposedDecl) {
692  // FIXME: Forward declarations of Objective-C classes and protocols
693  // are not directly exposed, but we want code completion to treat them
694  // like a definition.
695  if (isa<ObjCInterfaceDecl>(Declaration))
696  CursorKind = CXCursor_ObjCInterfaceDecl;
697  else if (isa<ObjCProtocolDecl>(Declaration))
698  CursorKind = CXCursor_ObjCProtocolDecl;
699  else
700  CursorKind = CXCursor_NotImplemented;
701  }
702  break;
703  }
704 
705  case RK_Macro:
706  case RK_Keyword:
707  llvm_unreachable("Macro and keyword kinds are handled by the constructors");
708  }
709 
710  if (!Accessible)
711  Availability = CXAvailability_NotAccessible;
712 }
713 
714 /// Retrieve the name that should be used to order a result.
715 ///
716 /// If the name needs to be constructed as a string, that string will be
717 /// saved into Saved and the returned StringRef will refer to it.
718 StringRef CodeCompletionResult::getOrderedName(std::string &Saved) const {
719  switch (Kind) {
720  case RK_Keyword:
721  return Keyword;
722  case RK_Pattern:
723  return Pattern->getTypedText();
724  case RK_Macro:
725  return Macro->getName();
726  case RK_Declaration:
727  // Handle declarations below.
728  break;
729  }
730 
731  DeclarationName Name = Declaration->getDeclName();
732 
733  // If the name is a simple identifier (by far the common case), or a
734  // zero-argument selector, just return a reference to that identifier.
735  if (IdentifierInfo *Id = Name.getAsIdentifierInfo())
736  return Id->getName();
737  if (Name.isObjCZeroArgSelector())
738  if (IdentifierInfo *Id
740  return Id->getName();
741 
742  Saved = Name.getAsString();
743  return Saved;
744 }
745 
747  const CodeCompletionResult &Y) {
748  std::string XSaved, YSaved;
749  StringRef XStr = X.getOrderedName(XSaved);
750  StringRef YStr = Y.getOrderedName(YSaved);
751  int cmp = XStr.compare_lower(YStr);
752  if (cmp)
753  return cmp < 0;
754 
755  // If case-insensitive comparison fails, try case-sensitive comparison.
756  cmp = XStr.compare(YStr);
757  if (cmp)
758  return cmp < 0;
759 
760  return false;
761 }
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
Represents a function declaration or definition.
Definition: Decl.h:1732
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:3351
FunctionDecl * getFunction() const
Retrieve the function overload candidate or the templated function declaration for a function templat...
C Language Family Type Representation.
Code completion within a type-qualifier list.
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:87
void AddChunk(CodeCompletionString::ChunkKind CK, const char *Text="")
Add a new chunk.
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
Defines the C++ template declaration subclasses.
unsigned getColumnNumber(FileID FID, unsigned FilePos, bool *Invalid=nullptr) const
Return the column # for the specified file position.
static Chunk CreateText(const char *Text)
Create a new text chunk.
The base class of the type hierarchy.
Definition: Type.h:1415
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:6683
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
Parse and apply any fixits to the source.
std::string getName(ArrayRef< StringRef > Parts) const
Get the platform-specific name separator.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:269
One of these records is kept for each identifier that is lexed.
CodeCompletionString * TakeString()
Take the resulting completion string.
void print(raw_ostream &OS, const SourceManager &SM) const
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:1752
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:1164
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.
const LangOptions & LangOpts
Definition: Sema.h:318
AvailabilityResult
Captures the result of checking the availability of a declaration.
Definition: DeclBase.h:73
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:278
Code completion occurred within a "top-level" completion context, e.g., at namespace or global scope...
AvailabilityResult getAvailability(std::string *Message=nullptr, VersionTuple EnclosingVersion=VersionTuple(), StringRef *RealizedPlatform=nullptr) const
Determine the availability of the given declaration.
Definition: DeclBase.cpp:589
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.
llvm::StringRef getCompletionKindString(CodeCompletionContext::Kind Kind)
Get string representation of Kind, useful for for debugging.
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...
static unsigned MeasureTokenLength(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts)
MeasureTokenLength - Relex the token at the specified location and return its length in bytes in the ...
Definition: Lexer.cpp:436
const char * Text
The text string associated with a CK_Text, CK_Placeholder, CK_Informative, or CK_Comma chunk...
std::string getAsString() const
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:427
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn&#39;t...
Captures a result of code completion.
Code completion occurred where a new name is expected and a qualified name is permissible.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
bool isFunctionOrMethod() const
Definition: DeclBase.h:1799
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:1751
Code completion occurred in a context where natural language is expected, e.g., a comment or string l...
Preprocessor & getPreprocessor() const
Definition: Sema.h:1219
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.
const SourceManager & SM
Definition: Format.cpp:1490
__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.
Encodes a location in the source.
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.
unsigned getLineNumber(FileID FID, unsigned FilePos, bool *Invalid=nullptr) const
Given a SourceLocation, return the spelling line number for the position indicated.
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2272
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:1261
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.
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.
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:1725
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.
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:13803
Code completion occurred within a preprocessor expression.
Code completion occurred where an expression is expected.
Code completion inside the filename part of a #include directive.
An unspecified code-completion context where we should also add macro completions.
A left angle bracket (&#39;<&#39;).
void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, OverloadCandidate *Candidates, unsigned NumCandidates, SourceLocation OpenParLoc) override
A right angle bracket (&#39;>&#39;).
SourceManager & getSourceManager() const
Definition: Sema.h:1218
Vertical whitespace (&#39;\n&#39; or &#39;\r\n&#39;, depending on the platform).
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:275
__DEVICE__ int max(int __a, int __b)
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:954
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;).
SourceManager & SourceMgr
Definition: Sema.h:323
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
Definition: Diagnostic.h:66
StringRef Text
Definition: Format.cpp:1621
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
This represents a decl that may have a name.
Definition: Decl.h:248
bool isTranslationUnit() const
Definition: DeclBase.h:1822
An Objective-C @interface.
Definition: Index.h:1748
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:2491
This class handles loading and caching of source files into memory.
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.