blob: 91b16d3774d4a42e1e2064c33241f0c69be08dfa [file] [log] [blame]
Douglas Gregor3545ff42009-09-21 16:56:56 +00001//===--- CodeCompleteConsumer.cpp - Code Completion Interface ---*- C++ -*-===//
Douglas Gregor2436e712009-09-17 21:32:03 +00002//
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#include "clang/Sema/CodeCompleteConsumer.h"
Douglas Gregor56c2dbc2009-09-18 17:54:00 +000014#include "clang/AST/DeclCXX.h"
Douglas Gregorf45b0cf2009-09-18 15:37:17 +000015#include "clang/Parse/Scope.h"
Douglas Gregor2436e712009-09-17 21:32:03 +000016#include "clang/Lex/Preprocessor.h"
Douglas Gregorf09935f2009-12-01 05:55:20 +000017#include "clang-c/Index.h"
Douglas Gregor2436e712009-09-17 21:32:03 +000018#include "Sema.h"
19#include "llvm/ADT/STLExtras.h"
Douglas Gregor9eb77012009-11-07 00:00:49 +000020#include "llvm/ADT/StringSwitch.h"
Douglas Gregor2436e712009-09-17 21:32:03 +000021#include "llvm/Support/raw_ostream.h"
22#include <algorithm>
Douglas Gregorfedc3282009-09-18 22:15:54 +000023#include <cstring>
24#include <functional>
Douglas Gregorab6ccb52009-11-17 16:43:05 +000025
Douglas Gregor2436e712009-09-17 21:32:03 +000026using namespace clang;
Douglas Gregorab6ccb52009-11-17 16:43:05 +000027using llvm::StringRef;
Douglas Gregor2436e712009-09-17 21:32:03 +000028
Douglas Gregorfedc3282009-09-18 22:15:54 +000029//===----------------------------------------------------------------------===//
30// Code completion string implementation
31//===----------------------------------------------------------------------===//
Douglas Gregor9eb77012009-11-07 00:00:49 +000032CodeCompletionString::Chunk::Chunk(ChunkKind Kind, llvm::StringRef Text)
Daniel Dunbarb0a19422009-11-12 18:40:12 +000033 : Kind(Kind), Text("")
Douglas Gregor5bf52692009-09-22 23:15:58 +000034{
Douglas Gregor9eb77012009-11-07 00:00:49 +000035 switch (Kind) {
36 case CK_TypedText:
37 case CK_Text:
38 case CK_Placeholder:
39 case CK_Informative:
40 case CK_CurrentParameter: {
41 char *New = new char [Text.size() + 1];
42 std::memcpy(New, Text.data(), Text.size());
43 New[Text.size()] = '\0';
44 this->Text = New;
45 break;
46 }
47
48 case CK_Optional:
49 llvm::llvm_unreachable("Optional strings cannot be created from text");
50 break;
51
52 case CK_LeftParen:
53 this->Text = "(";
54 break;
55
56 case CK_RightParen:
57 this->Text = ")";
58 break;
59
60 case CK_LeftBracket:
61 this->Text = "[";
62 break;
63
64 case CK_RightBracket:
65 this->Text = "]";
66 break;
67
68 case CK_LeftBrace:
69 this->Text = "{";
70 break;
71
72 case CK_RightBrace:
73 this->Text = "}";
74 break;
75
76 case CK_LeftAngle:
77 this->Text = "<";
78 break;
79
80 case CK_RightAngle:
81 this->Text = ">";
82 break;
83
84 case CK_Comma:
85 this->Text = ", ";
86 break;
87 }
Douglas Gregor5bf52692009-09-22 23:15:58 +000088}
89
90CodeCompletionString::Chunk
Douglas Gregorab6ccb52009-11-17 16:43:05 +000091CodeCompletionString::Chunk::CreateText(StringRef Text) {
Douglas Gregor5bf52692009-09-22 23:15:58 +000092 return Chunk(CK_Text, Text);
Douglas Gregorfedc3282009-09-18 22:15:54 +000093}
94
95CodeCompletionString::Chunk
96CodeCompletionString::Chunk::CreateOptional(
97 std::auto_ptr<CodeCompletionString> Optional) {
98 Chunk Result;
99 Result.Kind = CK_Optional;
100 Result.Optional = Optional.release();
101 return Result;
102}
103
104CodeCompletionString::Chunk
Douglas Gregorab6ccb52009-11-17 16:43:05 +0000105CodeCompletionString::Chunk::CreatePlaceholder(StringRef Placeholder) {
Douglas Gregor5bf52692009-09-22 23:15:58 +0000106 return Chunk(CK_Placeholder, Placeholder);
107}
108
109CodeCompletionString::Chunk
Douglas Gregorab6ccb52009-11-17 16:43:05 +0000110CodeCompletionString::Chunk::CreateInformative(StringRef Informative) {
Douglas Gregor5bf52692009-09-22 23:15:58 +0000111 return Chunk(CK_Informative, Informative);
Douglas Gregorfedc3282009-09-18 22:15:54 +0000112}
113
Douglas Gregor9eb77012009-11-07 00:00:49 +0000114CodeCompletionString::Chunk
115CodeCompletionString::Chunk::CreateCurrentParameter(
Douglas Gregorab6ccb52009-11-17 16:43:05 +0000116 StringRef CurrentParameter) {
Douglas Gregor9eb77012009-11-07 00:00:49 +0000117 return Chunk(CK_CurrentParameter, CurrentParameter);
118}
119
Douglas Gregor45f83ee2009-11-19 00:01:57 +0000120CodeCompletionString::Chunk CodeCompletionString::Chunk::Clone() const {
121 switch (Kind) {
122 case CK_TypedText:
123 case CK_Text:
124 case CK_Placeholder:
125 case CK_Informative:
126 case CK_CurrentParameter:
127 case CK_LeftParen:
128 case CK_RightParen:
129 case CK_LeftBracket:
130 case CK_RightBracket:
131 case CK_LeftBrace:
132 case CK_RightBrace:
133 case CK_LeftAngle:
134 case CK_RightAngle:
135 case CK_Comma:
136 return Chunk(Kind, Text);
137
138 case CK_Optional: {
139 std::auto_ptr<CodeCompletionString> Opt(Optional->Clone());
140 return CreateOptional(Opt);
141 }
142 }
143
144 // Silence GCC warning.
145 return Chunk();
146}
Douglas Gregor9eb77012009-11-07 00:00:49 +0000147
Douglas Gregorfedc3282009-09-18 22:15:54 +0000148void
149CodeCompletionString::Chunk::Destroy() {
150 switch (Kind) {
Douglas Gregor5bf52692009-09-22 23:15:58 +0000151 case CK_Optional:
152 delete Optional;
153 break;
154
Douglas Gregor9eb77012009-11-07 00:00:49 +0000155 case CK_TypedText:
Douglas Gregor5bf52692009-09-22 23:15:58 +0000156 case CK_Text:
157 case CK_Placeholder:
158 case CK_Informative:
Douglas Gregor9eb77012009-11-07 00:00:49 +0000159 case CK_CurrentParameter:
160 delete [] Text;
161 break;
162
163 case CK_LeftParen:
164 case CK_RightParen:
165 case CK_LeftBracket:
166 case CK_RightBracket:
167 case CK_LeftBrace:
168 case CK_RightBrace:
169 case CK_LeftAngle:
170 case CK_RightAngle:
171 case CK_Comma:
Douglas Gregor5bf52692009-09-22 23:15:58 +0000172 break;
Douglas Gregorfedc3282009-09-18 22:15:54 +0000173 }
174}
175
176CodeCompletionString::~CodeCompletionString() {
177 std::for_each(Chunks.begin(), Chunks.end(),
178 std::mem_fun_ref(&Chunk::Destroy));
179}
180
181std::string CodeCompletionString::getAsString() const {
182 std::string Result;
183 llvm::raw_string_ostream OS(Result);
184
185 for (iterator C = begin(), CEnd = end(); C != CEnd; ++C) {
186 switch (C->Kind) {
Douglas Gregorfedc3282009-09-18 22:15:54 +0000187 case CK_Optional: OS << "{#" << C->Optional->getAsString() << "#}"; break;
Douglas Gregor5bf52692009-09-22 23:15:58 +0000188 case CK_Placeholder: OS << "<#" << C->Text << "#>"; break;
189 case CK_Informative: OS << "[#" << C->Text << "#]"; break;
Douglas Gregor9eb77012009-11-07 00:00:49 +0000190 case CK_CurrentParameter: OS << "<#" << C->Text << "#>"; break;
191 default: OS << C->Text; break;
Douglas Gregorfedc3282009-09-18 22:15:54 +0000192 }
193 }
Douglas Gregor78f0fa52009-09-29 15:13:39 +0000194 OS.flush();
Douglas Gregorfedc3282009-09-18 22:15:54 +0000195 return Result;
196}
197
Douglas Gregor45f83ee2009-11-19 00:01:57 +0000198const char *CodeCompletionString::getTypedText() const {
199 for (iterator C = begin(), CEnd = end(); C != CEnd; ++C)
200 if (C->Kind == CK_TypedText)
201 return C->Text;
202
203 return 0;
204}
205
206CodeCompletionString *CodeCompletionString::Clone() const {
207 CodeCompletionString *Result = new CodeCompletionString;
208 for (iterator C = begin(), CEnd = end(); C != CEnd; ++C)
209 Result->AddChunk(C->Clone());
210 return Result;
211}
Douglas Gregor9eb77012009-11-07 00:00:49 +0000212
Douglas Gregorf09935f2009-12-01 05:55:20 +0000213static void WriteUnsigned(llvm::raw_ostream &OS, unsigned Value) {
214 OS.write((const char *)&Value, sizeof(unsigned));
215}
Douglas Gregor9eb77012009-11-07 00:00:49 +0000216
Douglas Gregorf09935f2009-12-01 05:55:20 +0000217static bool ReadUnsigned(const char *&Memory, const char *MemoryEnd,
218 unsigned &Value) {
219 if (Memory + sizeof(unsigned) > MemoryEnd)
220 return true;
221
222 memmove(&Value, Memory, sizeof(unsigned));
223 Memory += sizeof(unsigned);
224 return false;
Douglas Gregor9eb77012009-11-07 00:00:49 +0000225}
226
227void CodeCompletionString::Serialize(llvm::raw_ostream &OS) const {
Douglas Gregorf09935f2009-12-01 05:55:20 +0000228 // Write the number of chunks.
229 WriteUnsigned(OS, size());
230
Douglas Gregor9eb77012009-11-07 00:00:49 +0000231 for (iterator C = begin(), CEnd = end(); C != CEnd; ++C) {
Douglas Gregorf09935f2009-12-01 05:55:20 +0000232 WriteUnsigned(OS, C->Kind);
233
Douglas Gregor9eb77012009-11-07 00:00:49 +0000234 switch (C->Kind) {
235 case CK_TypedText:
Douglas Gregor9eb77012009-11-07 00:00:49 +0000236 case CK_Text:
Douglas Gregor9eb77012009-11-07 00:00:49 +0000237 case CK_Placeholder:
Douglas Gregor9eb77012009-11-07 00:00:49 +0000238 case CK_Informative:
Douglas Gregorf09935f2009-12-01 05:55:20 +0000239 case CK_CurrentParameter: {
240 const char *Text = C->Text;
241 unsigned StrLen = strlen(Text);
242 WriteUnsigned(OS, StrLen);
243 OS.write(Text, StrLen);
Douglas Gregor9eb77012009-11-07 00:00:49 +0000244 break;
Douglas Gregorf09935f2009-12-01 05:55:20 +0000245 }
246
247 case CK_Optional:
248 C->Optional->Serialize(OS);
Douglas Gregor9eb77012009-11-07 00:00:49 +0000249 break;
Douglas Gregorf09935f2009-12-01 05:55:20 +0000250
Douglas Gregor9eb77012009-11-07 00:00:49 +0000251 case CK_LeftParen:
Douglas Gregor9eb77012009-11-07 00:00:49 +0000252 case CK_RightParen:
Douglas Gregor9eb77012009-11-07 00:00:49 +0000253 case CK_LeftBracket:
Douglas Gregor9eb77012009-11-07 00:00:49 +0000254 case CK_RightBracket:
Douglas Gregor9eb77012009-11-07 00:00:49 +0000255 case CK_LeftBrace:
Douglas Gregor9eb77012009-11-07 00:00:49 +0000256 case CK_RightBrace:
Douglas Gregor9eb77012009-11-07 00:00:49 +0000257 case CK_LeftAngle:
Douglas Gregor9eb77012009-11-07 00:00:49 +0000258 case CK_RightAngle:
Douglas Gregor9eb77012009-11-07 00:00:49 +0000259 case CK_Comma:
Douglas Gregor9eb77012009-11-07 00:00:49 +0000260 break;
Douglas Gregorf09935f2009-12-01 05:55:20 +0000261 }
Douglas Gregor9eb77012009-11-07 00:00:49 +0000262 }
263}
264
Douglas Gregorf09935f2009-12-01 05:55:20 +0000265CodeCompletionString *CodeCompletionString::Deserialize(const char *&Str,
266 const char *StrEnd) {
267 if (Str == StrEnd || *Str == 0)
268 return 0;
Douglas Gregor9eb77012009-11-07 00:00:49 +0000269
Douglas Gregor9eb77012009-11-07 00:00:49 +0000270 CodeCompletionString *Result = new CodeCompletionString;
Douglas Gregorf09935f2009-12-01 05:55:20 +0000271 unsigned NumBlocks;
272 if (ReadUnsigned(Str, StrEnd, NumBlocks))
273 return Result;
Douglas Gregor9eb77012009-11-07 00:00:49 +0000274
Douglas Gregorf09935f2009-12-01 05:55:20 +0000275 for (unsigned I = 0; I != NumBlocks; ++I) {
276 if (Str + 1 >= StrEnd)
277 break;
278
279 // Parse the next kind.
280 unsigned KindValue;
281 if (ReadUnsigned(Str, StrEnd, KindValue))
282 return Result;
283
284 switch (ChunkKind Kind = (ChunkKind)KindValue) {
285 case CK_TypedText:
286 case CK_Text:
287 case CK_Placeholder:
288 case CK_Informative:
289 case CK_CurrentParameter: {
290 unsigned StrLen;
291 if (ReadUnsigned(Str, StrEnd, StrLen) || (Str + StrLen > StrEnd))
292 return Result;
293
294 Result->AddChunk(Chunk(Kind, StringRef(Str, StrLen)));
295 Str += StrLen;
296 break;
Douglas Gregor9eb77012009-11-07 00:00:49 +0000297 }
Douglas Gregorf09935f2009-12-01 05:55:20 +0000298
299 case CK_Optional: {
300 std::auto_ptr<CodeCompletionString> Optional(Deserialize(Str, StrEnd));
Douglas Gregor9eb77012009-11-07 00:00:49 +0000301 Result->AddOptionalChunk(Optional);
Douglas Gregorf09935f2009-12-01 05:55:20 +0000302 break;
Douglas Gregor9eb77012009-11-07 00:00:49 +0000303 }
Douglas Gregorf09935f2009-12-01 05:55:20 +0000304
305 case CK_LeftParen:
306 case CK_RightParen:
307 case CK_LeftBracket:
308 case CK_RightBracket:
309 case CK_LeftBrace:
310 case CK_RightBrace:
311 case CK_LeftAngle:
312 case CK_RightAngle:
313 case CK_Comma:
314 Result->AddChunk(Chunk(Kind));
315 break;
Douglas Gregor9eb77012009-11-07 00:00:49 +0000316 }
Douglas Gregorf09935f2009-12-01 05:55:20 +0000317 };
Douglas Gregor9eb77012009-11-07 00:00:49 +0000318
319 return Result;
320}
321
Douglas Gregor45f83ee2009-11-19 00:01:57 +0000322void CodeCompleteConsumer::Result::Destroy() {
323 if (Kind == RK_Pattern) {
324 delete Pattern;
325 Pattern = 0;
326 }
327}
328
Douglas Gregorfedc3282009-09-18 22:15:54 +0000329//===----------------------------------------------------------------------===//
Douglas Gregor05f477c2009-09-23 00:16:58 +0000330// Code completion overload candidate implementation
331//===----------------------------------------------------------------------===//
332FunctionDecl *
333CodeCompleteConsumer::OverloadCandidate::getFunction() const {
334 if (getKind() == CK_Function)
335 return Function;
336 else if (getKind() == CK_FunctionTemplate)
337 return FunctionTemplate->getTemplatedDecl();
338 else
339 return 0;
340}
341
342const FunctionType *
343CodeCompleteConsumer::OverloadCandidate::getFunctionType() const {
344 switch (Kind) {
345 case CK_Function:
346 return Function->getType()->getAs<FunctionType>();
347
348 case CK_FunctionTemplate:
349 return FunctionTemplate->getTemplatedDecl()->getType()
350 ->getAs<FunctionType>();
351
352 case CK_FunctionType:
353 return Type;
354 }
355
356 return 0;
357}
358
359//===----------------------------------------------------------------------===//
Douglas Gregorfedc3282009-09-18 22:15:54 +0000360// Code completion consumer implementation
361//===----------------------------------------------------------------------===//
362
Douglas Gregor3545ff42009-09-21 16:56:56 +0000363CodeCompleteConsumer::~CodeCompleteConsumer() { }
Douglas Gregorfedc3282009-09-18 22:15:54 +0000364
Douglas Gregor2436e712009-09-17 21:32:03 +0000365void
Daniel Dunbar242ea9a2009-11-13 08:58:20 +0000366PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &SemaRef,
367 Result *Results,
Douglas Gregor2436e712009-09-17 21:32:03 +0000368 unsigned NumResults) {
Douglas Gregor2436e712009-09-17 21:32:03 +0000369 // Print the results.
370 for (unsigned I = 0; I != NumResults; ++I) {
Douglas Gregor58acf322009-10-09 22:16:47 +0000371 OS << "COMPLETION: ";
Douglas Gregor2436e712009-09-17 21:32:03 +0000372 switch (Results[I].Kind) {
373 case Result::RK_Declaration:
374 OS << Results[I].Declaration->getNameAsString() << " : "
375 << Results[I].Rank;
376 if (Results[I].Hidden)
377 OS << " (Hidden)";
Douglas Gregor3545ff42009-09-21 16:56:56 +0000378 if (CodeCompletionString *CCS
379 = Results[I].CreateCodeCompletionString(SemaRef)) {
Douglas Gregorfedc3282009-09-18 22:15:54 +0000380 OS << " : " << CCS->getAsString();
381 delete CCS;
382 }
383
Douglas Gregor2436e712009-09-17 21:32:03 +0000384 OS << '\n';
385 break;
386
387 case Result::RK_Keyword:
388 OS << Results[I].Keyword << " : " << Results[I].Rank << '\n';
389 break;
Douglas Gregorf329c7c2009-10-30 16:50:04 +0000390
391 case Result::RK_Macro: {
392 OS << Results[I].Macro->getName() << " : " << Results[I].Rank;
393 if (CodeCompletionString *CCS
394 = Results[I].CreateCodeCompletionString(SemaRef)) {
395 OS << " : " << CCS->getAsString();
396 delete CCS;
397 }
398 OS << '\n';
399 break;
400 }
Douglas Gregor45f83ee2009-11-19 00:01:57 +0000401
402 case Result::RK_Pattern: {
403 OS << "Pattern : " << Results[I].Rank << " : "
404 << Results[I].Pattern->getAsString() << '\n';
405 break;
406 }
Douglas Gregor2436e712009-09-17 21:32:03 +0000407 }
408 }
409
410 // Once we've printed the code-completion results, suppress remaining
411 // diagnostics.
412 // FIXME: Move this somewhere else!
Douglas Gregor3545ff42009-09-21 16:56:56 +0000413 SemaRef.PP.getDiagnostics().setSuppressAllDiagnostics();
Douglas Gregor2436e712009-09-17 21:32:03 +0000414}
Douglas Gregor05f477c2009-09-23 00:16:58 +0000415
416void
Daniel Dunbar242ea9a2009-11-13 08:58:20 +0000417PrintingCodeCompleteConsumer::ProcessOverloadCandidates(Sema &SemaRef,
418 unsigned CurrentArg,
Douglas Gregor05f477c2009-09-23 00:16:58 +0000419 OverloadCandidate *Candidates,
420 unsigned NumCandidates) {
421 for (unsigned I = 0; I != NumCandidates; ++I) {
Douglas Gregorf0f51982009-09-23 00:34:09 +0000422 if (CodeCompletionString *CCS
423 = Candidates[I].CreateSignatureString(CurrentArg, SemaRef)) {
Douglas Gregor58acf322009-10-09 22:16:47 +0000424 OS << "OVERLOAD: " << CCS->getAsString() << "\n";
Douglas Gregorf0f51982009-09-23 00:34:09 +0000425 delete CCS;
Douglas Gregor05f477c2009-09-23 00:16:58 +0000426 }
427 }
428
429 // Once we've printed the code-completion results, suppress remaining
430 // diagnostics.
431 // FIXME: Move this somewhere else!
432 SemaRef.PP.getDiagnostics().setSuppressAllDiagnostics();
433}
Douglas Gregor9eb77012009-11-07 00:00:49 +0000434
435void
Daniel Dunbar242ea9a2009-11-13 08:58:20 +0000436CIndexCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &SemaRef,
437 Result *Results,
Douglas Gregor9eb77012009-11-07 00:00:49 +0000438 unsigned NumResults) {
439 // Print the results.
440 for (unsigned I = 0; I != NumResults; ++I) {
Douglas Gregorf09935f2009-12-01 05:55:20 +0000441 CXCursorKind Kind = CXCursor_NotImplemented;
442
Douglas Gregor9eb77012009-11-07 00:00:49 +0000443 switch (Results[I].Kind) {
Douglas Gregorf09935f2009-12-01 05:55:20 +0000444 case Result::RK_Declaration:
445 switch (Results[I].Declaration->getKind()) {
446 case Decl::Record:
447 case Decl::CXXRecord:
448 case Decl::ClassTemplateSpecialization: {
449 RecordDecl *Record = cast<RecordDecl>(Results[I].Declaration);
450 if (Record->isStruct())
451 Kind = CXCursor_StructDecl;
452 else if (Record->isUnion())
453 Kind = CXCursor_UnionDecl;
454 else
455 Kind = CXCursor_ClassDecl;
Douglas Gregor9eb77012009-11-07 00:00:49 +0000456 break;
457 }
Douglas Gregor45f83ee2009-11-19 00:01:57 +0000458
Douglas Gregorf09935f2009-12-01 05:55:20 +0000459 case Decl::ObjCMethod: {
460 ObjCMethodDecl *Method = cast<ObjCMethodDecl>(Results[I].Declaration);
461 if (Method->isInstanceMethod())
462 Kind = CXCursor_ObjCInstanceMethodDecl;
463 else
464 Kind = CXCursor_ObjCClassMethodDecl;
Douglas Gregor45f83ee2009-11-19 00:01:57 +0000465 break;
466 }
Douglas Gregorf09935f2009-12-01 05:55:20 +0000467
468 case Decl::Typedef:
469 Kind = CXCursor_TypedefDecl;
470 break;
471
472 case Decl::Enum:
473 Kind = CXCursor_EnumDecl;
474 break;
475
476 case Decl::Field:
477 Kind = CXCursor_FieldDecl;
478 break;
479
480 case Decl::EnumConstant:
481 Kind = CXCursor_EnumConstantDecl;
482 break;
483
484 case Decl::Function:
485 case Decl::CXXMethod:
486 case Decl::CXXConstructor:
487 case Decl::CXXDestructor:
488 case Decl::CXXConversion:
489 Kind = CXCursor_FunctionDecl;
490 break;
491
492 case Decl::Var:
493 Kind = CXCursor_VarDecl;
494 break;
495
496 case Decl::ParmVar:
497 Kind = CXCursor_ParmDecl;
498 break;
499
500 case Decl::ObjCInterface:
501 Kind = CXCursor_ObjCInterfaceDecl;
502 break;
503
504 case Decl::ObjCCategory:
505 Kind = CXCursor_ObjCCategoryDecl;
506 break;
507
508 case Decl::ObjCProtocol:
509 Kind = CXCursor_ObjCProtocolDecl;
510 break;
511
512 case Decl::ObjCProperty:
513 Kind = CXCursor_ObjCPropertyDecl;
514 break;
515
516 case Decl::ObjCIvar:
517 Kind = CXCursor_ObjCIvarDecl;
518 break;
519
520 case Decl::ObjCImplementation:
521 Kind = CXCursor_ObjCClassDefn;
522 break;
523
524 case Decl::ObjCCategoryImpl:
525 Kind = CXCursor_ObjCCategoryDefn;
526 break;
527
528 default:
529 break;
530 }
531 break;
532
533 case Result::RK_Keyword:
534 case Result::RK_Macro:
535 case Result::RK_Pattern:
536 Kind = CXCursor_NotImplemented;
537 break;
Douglas Gregor9eb77012009-11-07 00:00:49 +0000538 }
Douglas Gregorf09935f2009-12-01 05:55:20 +0000539
540 WriteUnsigned(OS, Kind);
541 CodeCompletionString *CCS = Results[I].CreateCodeCompletionString(SemaRef);
542 assert(CCS && "No code-completion string?");
543 CCS->Serialize(OS);
544 delete CCS;
Douglas Gregor9eb77012009-11-07 00:00:49 +0000545 }
546
547 // Once we've printed the code-completion results, suppress remaining
548 // diagnostics.
549 // FIXME: Move this somewhere else!
550 SemaRef.PP.getDiagnostics().setSuppressAllDiagnostics();
551}
552
553void
Daniel Dunbar242ea9a2009-11-13 08:58:20 +0000554CIndexCodeCompleteConsumer::ProcessOverloadCandidates(Sema &SemaRef,
555 unsigned CurrentArg,
Douglas Gregor9eb77012009-11-07 00:00:49 +0000556 OverloadCandidate *Candidates,
557 unsigned NumCandidates) {
558 for (unsigned I = 0; I != NumCandidates; ++I) {
Douglas Gregorf09935f2009-12-01 05:55:20 +0000559 WriteUnsigned(OS, CXCursor_NotImplemented);
560 CodeCompletionString *CCS
561 = Candidates[I].CreateSignatureString(CurrentArg, SemaRef);
562 assert(CCS && "No code-completion string?");
563 CCS->Serialize(OS);
564 delete CCS;
Douglas Gregor9eb77012009-11-07 00:00:49 +0000565 }
566
567 // Once we've printed the code-completion results, suppress remaining
568 // diagnostics.
569 // FIXME: Move this somewhere else!
570 SemaRef.PP.getDiagnostics().setSuppressAllDiagnostics();
571}