blob: b9b85dfb8084e9e2e05e63340cf033e7fcb68207 [file] [log] [blame]
Douglas Gregor86d9a522009-09-21 16:56:56 +00001//===--- CodeCompleteConsumer.cpp - Code Completion Interface ---*- C++ -*-===//
Douglas Gregor81b747b2009-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 Gregor75b71282009-09-18 17:54:00 +000014#include "clang/AST/DeclCXX.h"
Douglas Gregor374929f2009-09-18 15:37:17 +000015#include "clang/Parse/Scope.h"
Douglas Gregor81b747b2009-09-17 21:32:03 +000016#include "clang/Lex/Preprocessor.h"
Douglas Gregor2b4074f2009-12-01 05:55:20 +000017#include "clang-c/Index.h"
Douglas Gregor81b747b2009-09-17 21:32:03 +000018#include "Sema.h"
19#include "llvm/ADT/STLExtras.h"
Douglas Gregor0c8296d2009-11-07 00:00:49 +000020#include "llvm/ADT/StringSwitch.h"
Douglas Gregor81b747b2009-09-17 21:32:03 +000021#include "llvm/Support/raw_ostream.h"
22#include <algorithm>
Douglas Gregore6e03612009-09-18 22:15:54 +000023#include <cstring>
24#include <functional>
Douglas Gregor92eff462009-11-17 16:43:05 +000025
Douglas Gregor81b747b2009-09-17 21:32:03 +000026using namespace clang;
Douglas Gregor92eff462009-11-17 16:43:05 +000027using llvm::StringRef;
Douglas Gregor81b747b2009-09-17 21:32:03 +000028
Douglas Gregore6e03612009-09-18 22:15:54 +000029//===----------------------------------------------------------------------===//
30// Code completion string implementation
31//===----------------------------------------------------------------------===//
Douglas Gregor0c8296d2009-11-07 00:00:49 +000032CodeCompletionString::Chunk::Chunk(ChunkKind Kind, llvm::StringRef Text)
Daniel Dunbarad5757f2009-11-12 18:40:12 +000033 : Kind(Kind), Text("")
Douglas Gregor0563c262009-09-22 23:15:58 +000034{
Douglas Gregor0c8296d2009-11-07 00:00:49 +000035 switch (Kind) {
36 case CK_TypedText:
37 case CK_Text:
38 case CK_Placeholder:
39 case CK_Informative:
Douglas Gregorff5ce6e2009-12-18 18:53:37 +000040 case CK_ResultType:
Douglas Gregor0c8296d2009-11-07 00:00:49 +000041 case CK_CurrentParameter: {
42 char *New = new char [Text.size() + 1];
43 std::memcpy(New, Text.data(), Text.size());
44 New[Text.size()] = '\0';
45 this->Text = New;
46 break;
47 }
48
49 case CK_Optional:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +000050 llvm_unreachable("Optional strings cannot be created from text");
Douglas Gregor0c8296d2009-11-07 00:00:49 +000051 break;
52
53 case CK_LeftParen:
54 this->Text = "(";
55 break;
56
57 case CK_RightParen:
58 this->Text = ")";
59 break;
60
61 case CK_LeftBracket:
62 this->Text = "[";
63 break;
64
65 case CK_RightBracket:
66 this->Text = "]";
67 break;
68
69 case CK_LeftBrace:
70 this->Text = "{";
71 break;
72
73 case CK_RightBrace:
74 this->Text = "}";
75 break;
76
77 case CK_LeftAngle:
78 this->Text = "<";
79 break;
80
81 case CK_RightAngle:
82 this->Text = ">";
83 break;
84
85 case CK_Comma:
86 this->Text = ", ";
87 break;
88 }
Douglas Gregor0563c262009-09-22 23:15:58 +000089}
90
91CodeCompletionString::Chunk
Douglas Gregor92eff462009-11-17 16:43:05 +000092CodeCompletionString::Chunk::CreateText(StringRef Text) {
Douglas Gregor0563c262009-09-22 23:15:58 +000093 return Chunk(CK_Text, Text);
Douglas Gregore6e03612009-09-18 22:15:54 +000094}
95
96CodeCompletionString::Chunk
97CodeCompletionString::Chunk::CreateOptional(
98 std::auto_ptr<CodeCompletionString> Optional) {
99 Chunk Result;
100 Result.Kind = CK_Optional;
101 Result.Optional = Optional.release();
102 return Result;
103}
104
105CodeCompletionString::Chunk
Douglas Gregor92eff462009-11-17 16:43:05 +0000106CodeCompletionString::Chunk::CreatePlaceholder(StringRef Placeholder) {
Douglas Gregor0563c262009-09-22 23:15:58 +0000107 return Chunk(CK_Placeholder, Placeholder);
108}
109
110CodeCompletionString::Chunk
Douglas Gregor92eff462009-11-17 16:43:05 +0000111CodeCompletionString::Chunk::CreateInformative(StringRef Informative) {
Douglas Gregor0563c262009-09-22 23:15:58 +0000112 return Chunk(CK_Informative, Informative);
Douglas Gregore6e03612009-09-18 22:15:54 +0000113}
114
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000115CodeCompletionString::Chunk
Douglas Gregorff5ce6e2009-12-18 18:53:37 +0000116CodeCompletionString::Chunk::CreateResultType(StringRef ResultType) {
117 return Chunk(CK_ResultType, ResultType);
118}
119
120CodeCompletionString::Chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000121CodeCompletionString::Chunk::CreateCurrentParameter(
Douglas Gregor92eff462009-11-17 16:43:05 +0000122 StringRef CurrentParameter) {
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000123 return Chunk(CK_CurrentParameter, CurrentParameter);
124}
125
Douglas Gregor54f01612009-11-19 00:01:57 +0000126CodeCompletionString::Chunk CodeCompletionString::Chunk::Clone() const {
127 switch (Kind) {
128 case CK_TypedText:
129 case CK_Text:
130 case CK_Placeholder:
131 case CK_Informative:
Douglas Gregorff5ce6e2009-12-18 18:53:37 +0000132 case CK_ResultType:
Douglas Gregor54f01612009-11-19 00:01:57 +0000133 case CK_CurrentParameter:
134 case CK_LeftParen:
135 case CK_RightParen:
136 case CK_LeftBracket:
137 case CK_RightBracket:
138 case CK_LeftBrace:
139 case CK_RightBrace:
140 case CK_LeftAngle:
141 case CK_RightAngle:
142 case CK_Comma:
143 return Chunk(Kind, Text);
144
145 case CK_Optional: {
146 std::auto_ptr<CodeCompletionString> Opt(Optional->Clone());
147 return CreateOptional(Opt);
148 }
149 }
150
151 // Silence GCC warning.
152 return Chunk();
153}
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000154
Douglas Gregore6e03612009-09-18 22:15:54 +0000155void
156CodeCompletionString::Chunk::Destroy() {
157 switch (Kind) {
Douglas Gregor0563c262009-09-22 23:15:58 +0000158 case CK_Optional:
159 delete Optional;
160 break;
161
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000162 case CK_TypedText:
Douglas Gregor0563c262009-09-22 23:15:58 +0000163 case CK_Text:
164 case CK_Placeholder:
165 case CK_Informative:
Douglas Gregorff5ce6e2009-12-18 18:53:37 +0000166 case CK_ResultType:
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000167 case CK_CurrentParameter:
168 delete [] Text;
169 break;
170
171 case CK_LeftParen:
172 case CK_RightParen:
173 case CK_LeftBracket:
174 case CK_RightBracket:
175 case CK_LeftBrace:
176 case CK_RightBrace:
177 case CK_LeftAngle:
178 case CK_RightAngle:
179 case CK_Comma:
Douglas Gregor0563c262009-09-22 23:15:58 +0000180 break;
Douglas Gregore6e03612009-09-18 22:15:54 +0000181 }
182}
183
184CodeCompletionString::~CodeCompletionString() {
185 std::for_each(Chunks.begin(), Chunks.end(),
186 std::mem_fun_ref(&Chunk::Destroy));
187}
188
189std::string CodeCompletionString::getAsString() const {
190 std::string Result;
191 llvm::raw_string_ostream OS(Result);
192
193 for (iterator C = begin(), CEnd = end(); C != CEnd; ++C) {
194 switch (C->Kind) {
Douglas Gregore6e03612009-09-18 22:15:54 +0000195 case CK_Optional: OS << "{#" << C->Optional->getAsString() << "#}"; break;
Douglas Gregor0563c262009-09-22 23:15:58 +0000196 case CK_Placeholder: OS << "<#" << C->Text << "#>"; break;
Douglas Gregorff5ce6e2009-12-18 18:53:37 +0000197
198 case CK_Informative:
199 case CK_ResultType:
200 OS << "[#" << C->Text << "#]";
201 break;
202
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000203 case CK_CurrentParameter: OS << "<#" << C->Text << "#>"; break;
204 default: OS << C->Text; break;
Douglas Gregore6e03612009-09-18 22:15:54 +0000205 }
206 }
Douglas Gregore2b7eea2009-09-29 15:13:39 +0000207 OS.flush();
Douglas Gregore6e03612009-09-18 22:15:54 +0000208 return Result;
209}
210
Douglas Gregor54f01612009-11-19 00:01:57 +0000211const char *CodeCompletionString::getTypedText() const {
212 for (iterator C = begin(), CEnd = end(); C != CEnd; ++C)
213 if (C->Kind == CK_TypedText)
214 return C->Text;
215
216 return 0;
217}
218
219CodeCompletionString *CodeCompletionString::Clone() const {
220 CodeCompletionString *Result = new CodeCompletionString;
221 for (iterator C = begin(), CEnd = end(); C != CEnd; ++C)
222 Result->AddChunk(C->Clone());
223 return Result;
224}
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000225
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000226static void WriteUnsigned(llvm::raw_ostream &OS, unsigned Value) {
227 OS.write((const char *)&Value, sizeof(unsigned));
228}
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000229
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000230static bool ReadUnsigned(const char *&Memory, const char *MemoryEnd,
231 unsigned &Value) {
232 if (Memory + sizeof(unsigned) > MemoryEnd)
233 return true;
234
235 memmove(&Value, Memory, sizeof(unsigned));
236 Memory += sizeof(unsigned);
237 return false;
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000238}
239
240void CodeCompletionString::Serialize(llvm::raw_ostream &OS) const {
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000241 // Write the number of chunks.
242 WriteUnsigned(OS, size());
243
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000244 for (iterator C = begin(), CEnd = end(); C != CEnd; ++C) {
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000245 WriteUnsigned(OS, C->Kind);
246
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000247 switch (C->Kind) {
248 case CK_TypedText:
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000249 case CK_Text:
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000250 case CK_Placeholder:
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000251 case CK_Informative:
Douglas Gregorff5ce6e2009-12-18 18:53:37 +0000252 case CK_ResultType:
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000253 case CK_CurrentParameter: {
254 const char *Text = C->Text;
255 unsigned StrLen = strlen(Text);
256 WriteUnsigned(OS, StrLen);
257 OS.write(Text, StrLen);
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000258 break;
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000259 }
260
261 case CK_Optional:
262 C->Optional->Serialize(OS);
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000263 break;
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000264
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000265 case CK_LeftParen:
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000266 case CK_RightParen:
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000267 case CK_LeftBracket:
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000268 case CK_RightBracket:
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000269 case CK_LeftBrace:
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000270 case CK_RightBrace:
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000271 case CK_LeftAngle:
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000272 case CK_RightAngle:
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000273 case CK_Comma:
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000274 break;
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000275 }
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000276 }
277}
278
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000279CodeCompletionString *CodeCompletionString::Deserialize(const char *&Str,
280 const char *StrEnd) {
281 if (Str == StrEnd || *Str == 0)
282 return 0;
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000283
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000284 CodeCompletionString *Result = new CodeCompletionString;
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000285 unsigned NumBlocks;
286 if (ReadUnsigned(Str, StrEnd, NumBlocks))
287 return Result;
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000288
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000289 for (unsigned I = 0; I != NumBlocks; ++I) {
290 if (Str + 1 >= StrEnd)
291 break;
292
293 // Parse the next kind.
294 unsigned KindValue;
295 if (ReadUnsigned(Str, StrEnd, KindValue))
296 return Result;
297
298 switch (ChunkKind Kind = (ChunkKind)KindValue) {
299 case CK_TypedText:
300 case CK_Text:
301 case CK_Placeholder:
302 case CK_Informative:
Douglas Gregorff5ce6e2009-12-18 18:53:37 +0000303 case CK_ResultType:
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000304 case CK_CurrentParameter: {
305 unsigned StrLen;
306 if (ReadUnsigned(Str, StrEnd, StrLen) || (Str + StrLen > StrEnd))
307 return Result;
308
309 Result->AddChunk(Chunk(Kind, StringRef(Str, StrLen)));
310 Str += StrLen;
311 break;
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000312 }
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000313
314 case CK_Optional: {
315 std::auto_ptr<CodeCompletionString> Optional(Deserialize(Str, StrEnd));
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000316 Result->AddOptionalChunk(Optional);
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000317 break;
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000318 }
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000319
320 case CK_LeftParen:
321 case CK_RightParen:
322 case CK_LeftBracket:
323 case CK_RightBracket:
324 case CK_LeftBrace:
325 case CK_RightBrace:
326 case CK_LeftAngle:
327 case CK_RightAngle:
328 case CK_Comma:
329 Result->AddChunk(Chunk(Kind));
330 break;
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000331 }
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000332 };
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000333
334 return Result;
335}
336
Douglas Gregor54f01612009-11-19 00:01:57 +0000337void CodeCompleteConsumer::Result::Destroy() {
338 if (Kind == RK_Pattern) {
339 delete Pattern;
340 Pattern = 0;
341 }
342}
343
Douglas Gregore6e03612009-09-18 22:15:54 +0000344//===----------------------------------------------------------------------===//
Douglas Gregor05944382009-09-23 00:16:58 +0000345// Code completion overload candidate implementation
346//===----------------------------------------------------------------------===//
347FunctionDecl *
348CodeCompleteConsumer::OverloadCandidate::getFunction() const {
349 if (getKind() == CK_Function)
350 return Function;
351 else if (getKind() == CK_FunctionTemplate)
352 return FunctionTemplate->getTemplatedDecl();
353 else
354 return 0;
355}
356
357const FunctionType *
358CodeCompleteConsumer::OverloadCandidate::getFunctionType() const {
359 switch (Kind) {
360 case CK_Function:
361 return Function->getType()->getAs<FunctionType>();
362
363 case CK_FunctionTemplate:
364 return FunctionTemplate->getTemplatedDecl()->getType()
365 ->getAs<FunctionType>();
366
367 case CK_FunctionType:
368 return Type;
369 }
370
371 return 0;
372}
373
374//===----------------------------------------------------------------------===//
Douglas Gregore6e03612009-09-18 22:15:54 +0000375// Code completion consumer implementation
376//===----------------------------------------------------------------------===//
377
Douglas Gregor86d9a522009-09-21 16:56:56 +0000378CodeCompleteConsumer::~CodeCompleteConsumer() { }
Douglas Gregore6e03612009-09-18 22:15:54 +0000379
Douglas Gregor81b747b2009-09-17 21:32:03 +0000380void
Daniel Dunbar3a2838d2009-11-13 08:58:20 +0000381PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &SemaRef,
382 Result *Results,
Douglas Gregor81b747b2009-09-17 21:32:03 +0000383 unsigned NumResults) {
Douglas Gregor81b747b2009-09-17 21:32:03 +0000384 // Print the results.
385 for (unsigned I = 0; I != NumResults; ++I) {
Douglas Gregorf52cede2009-10-09 22:16:47 +0000386 OS << "COMPLETION: ";
Douglas Gregor81b747b2009-09-17 21:32:03 +0000387 switch (Results[I].Kind) {
388 case Result::RK_Declaration:
389 OS << Results[I].Declaration->getNameAsString() << " : "
390 << Results[I].Rank;
391 if (Results[I].Hidden)
392 OS << " (Hidden)";
Douglas Gregor86d9a522009-09-21 16:56:56 +0000393 if (CodeCompletionString *CCS
394 = Results[I].CreateCodeCompletionString(SemaRef)) {
Douglas Gregore6e03612009-09-18 22:15:54 +0000395 OS << " : " << CCS->getAsString();
396 delete CCS;
397 }
398
Douglas Gregor81b747b2009-09-17 21:32:03 +0000399 OS << '\n';
400 break;
401
402 case Result::RK_Keyword:
403 OS << Results[I].Keyword << " : " << Results[I].Rank << '\n';
404 break;
Douglas Gregor3f7c7f42009-10-30 16:50:04 +0000405
406 case Result::RK_Macro: {
407 OS << Results[I].Macro->getName() << " : " << Results[I].Rank;
408 if (CodeCompletionString *CCS
409 = Results[I].CreateCodeCompletionString(SemaRef)) {
410 OS << " : " << CCS->getAsString();
411 delete CCS;
412 }
413 OS << '\n';
414 break;
415 }
Douglas Gregor54f01612009-11-19 00:01:57 +0000416
417 case Result::RK_Pattern: {
418 OS << "Pattern : " << Results[I].Rank << " : "
419 << Results[I].Pattern->getAsString() << '\n';
420 break;
421 }
Douglas Gregor81b747b2009-09-17 21:32:03 +0000422 }
423 }
424
425 // Once we've printed the code-completion results, suppress remaining
426 // diagnostics.
427 // FIXME: Move this somewhere else!
Douglas Gregor86d9a522009-09-21 16:56:56 +0000428 SemaRef.PP.getDiagnostics().setSuppressAllDiagnostics();
Douglas Gregor81b747b2009-09-17 21:32:03 +0000429}
Douglas Gregor05944382009-09-23 00:16:58 +0000430
431void
Daniel Dunbar3a2838d2009-11-13 08:58:20 +0000432PrintingCodeCompleteConsumer::ProcessOverloadCandidates(Sema &SemaRef,
433 unsigned CurrentArg,
Douglas Gregor05944382009-09-23 00:16:58 +0000434 OverloadCandidate *Candidates,
435 unsigned NumCandidates) {
436 for (unsigned I = 0; I != NumCandidates; ++I) {
Douglas Gregor86d802e2009-09-23 00:34:09 +0000437 if (CodeCompletionString *CCS
438 = Candidates[I].CreateSignatureString(CurrentArg, SemaRef)) {
Douglas Gregorf52cede2009-10-09 22:16:47 +0000439 OS << "OVERLOAD: " << CCS->getAsString() << "\n";
Douglas Gregor86d802e2009-09-23 00:34:09 +0000440 delete CCS;
Douglas Gregor05944382009-09-23 00:16:58 +0000441 }
442 }
443
444 // Once we've printed the code-completion results, suppress remaining
445 // diagnostics.
446 // FIXME: Move this somewhere else!
447 SemaRef.PP.getDiagnostics().setSuppressAllDiagnostics();
448}
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000449
450void
Daniel Dunbar3a2838d2009-11-13 08:58:20 +0000451CIndexCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &SemaRef,
452 Result *Results,
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000453 unsigned NumResults) {
454 // Print the results.
455 for (unsigned I = 0; I != NumResults; ++I) {
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000456 CXCursorKind Kind = CXCursor_NotImplemented;
457
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000458 switch (Results[I].Kind) {
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000459 case Result::RK_Declaration:
460 switch (Results[I].Declaration->getKind()) {
461 case Decl::Record:
462 case Decl::CXXRecord:
463 case Decl::ClassTemplateSpecialization: {
464 RecordDecl *Record = cast<RecordDecl>(Results[I].Declaration);
465 if (Record->isStruct())
466 Kind = CXCursor_StructDecl;
467 else if (Record->isUnion())
468 Kind = CXCursor_UnionDecl;
469 else
470 Kind = CXCursor_ClassDecl;
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000471 break;
472 }
Douglas Gregor54f01612009-11-19 00:01:57 +0000473
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000474 case Decl::ObjCMethod: {
475 ObjCMethodDecl *Method = cast<ObjCMethodDecl>(Results[I].Declaration);
476 if (Method->isInstanceMethod())
477 Kind = CXCursor_ObjCInstanceMethodDecl;
478 else
479 Kind = CXCursor_ObjCClassMethodDecl;
Douglas Gregor54f01612009-11-19 00:01:57 +0000480 break;
481 }
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000482
483 case Decl::Typedef:
484 Kind = CXCursor_TypedefDecl;
485 break;
486
487 case Decl::Enum:
488 Kind = CXCursor_EnumDecl;
489 break;
490
491 case Decl::Field:
492 Kind = CXCursor_FieldDecl;
493 break;
494
495 case Decl::EnumConstant:
496 Kind = CXCursor_EnumConstantDecl;
497 break;
498
499 case Decl::Function:
500 case Decl::CXXMethod:
501 case Decl::CXXConstructor:
502 case Decl::CXXDestructor:
503 case Decl::CXXConversion:
504 Kind = CXCursor_FunctionDecl;
505 break;
506
507 case Decl::Var:
508 Kind = CXCursor_VarDecl;
509 break;
510
511 case Decl::ParmVar:
512 Kind = CXCursor_ParmDecl;
513 break;
514
515 case Decl::ObjCInterface:
516 Kind = CXCursor_ObjCInterfaceDecl;
517 break;
518
519 case Decl::ObjCCategory:
520 Kind = CXCursor_ObjCCategoryDecl;
521 break;
522
523 case Decl::ObjCProtocol:
524 Kind = CXCursor_ObjCProtocolDecl;
525 break;
526
527 case Decl::ObjCProperty:
528 Kind = CXCursor_ObjCPropertyDecl;
529 break;
530
531 case Decl::ObjCIvar:
532 Kind = CXCursor_ObjCIvarDecl;
533 break;
534
535 case Decl::ObjCImplementation:
536 Kind = CXCursor_ObjCClassDefn;
537 break;
538
539 case Decl::ObjCCategoryImpl:
540 Kind = CXCursor_ObjCCategoryDefn;
541 break;
542
543 default:
544 break;
545 }
546 break;
547
548 case Result::RK_Keyword:
549 case Result::RK_Macro:
550 case Result::RK_Pattern:
551 Kind = CXCursor_NotImplemented;
552 break;
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000553 }
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000554
555 WriteUnsigned(OS, Kind);
556 CodeCompletionString *CCS = Results[I].CreateCodeCompletionString(SemaRef);
557 assert(CCS && "No code-completion string?");
558 CCS->Serialize(OS);
559 delete CCS;
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000560 }
561
562 // Once we've printed the code-completion results, suppress remaining
563 // diagnostics.
564 // FIXME: Move this somewhere else!
565 SemaRef.PP.getDiagnostics().setSuppressAllDiagnostics();
566}
567
568void
Daniel Dunbar3a2838d2009-11-13 08:58:20 +0000569CIndexCodeCompleteConsumer::ProcessOverloadCandidates(Sema &SemaRef,
570 unsigned CurrentArg,
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000571 OverloadCandidate *Candidates,
572 unsigned NumCandidates) {
573 for (unsigned I = 0; I != NumCandidates; ++I) {
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000574 WriteUnsigned(OS, CXCursor_NotImplemented);
575 CodeCompletionString *CCS
576 = Candidates[I].CreateSignatureString(CurrentArg, SemaRef);
577 assert(CCS && "No code-completion string?");
578 CCS->Serialize(OS);
579 delete CCS;
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000580 }
581
582 // Once we've printed the code-completion results, suppress remaining
583 // diagnostics.
584 // FIXME: Move this somewhere else!
585 SemaRef.PP.getDiagnostics().setSuppressAllDiagnostics();
586}