CodeCompleteConsumer.cpp (207619) | CodeCompleteConsumer.cpp (208600) |
---|---|
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//===----------------------------------------------------------------------===// --- 196 unchanged lines hidden (view full) --- 205 case CK_SemiColon: 206 case CK_Equal: 207 case CK_HorizontalSpace: 208 case CK_VerticalSpace: 209 break; 210 } 211} 212 | 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//===----------------------------------------------------------------------===// --- 196 unchanged lines hidden (view full) --- 205 case CK_SemiColon: 206 case CK_Equal: 207 case CK_HorizontalSpace: 208 case CK_VerticalSpace: 209 break; 210 } 211} 212 |
213CodeCompletionString::~CodeCompletionString() { | 213void CodeCompletionString::clear() { |
214 std::for_each(Chunks.begin(), Chunks.end(), 215 std::mem_fun_ref(&Chunk::Destroy)); | 214 std::for_each(Chunks.begin(), Chunks.end(), 215 std::mem_fun_ref(&Chunk::Destroy)); |
216 Chunks.clear(); |
|
216} 217 218std::string CodeCompletionString::getAsString() const { 219 std::string Result; 220 llvm::raw_string_ostream OS(Result); 221 222 for (iterator C = begin(), CEnd = end(); C != CEnd; ++C) { 223 switch (C->Kind) { --- 81 unchanged lines hidden (view full) --- 305 case CK_Equal: 306 case CK_HorizontalSpace: 307 case CK_VerticalSpace: 308 break; 309 } 310 } 311} 312 | 217} 218 219std::string CodeCompletionString::getAsString() const { 220 std::string Result; 221 llvm::raw_string_ostream OS(Result); 222 223 for (iterator C = begin(), CEnd = end(); C != CEnd; ++C) { 224 switch (C->Kind) { --- 81 unchanged lines hidden (view full) --- 306 case CK_Equal: 307 case CK_HorizontalSpace: 308 case CK_VerticalSpace: 309 break; 310 } 311 } 312} 313 |
313CodeCompletionString *CodeCompletionString::Deserialize(const char *&Str, 314 const char *StrEnd) { | 314bool CodeCompletionString::Deserialize(const char *&Str, const char *StrEnd) { |
315 if (Str == StrEnd || *Str == 0) | 315 if (Str == StrEnd || *Str == 0) |
316 return 0; | 316 return false; |
317 | 317 |
318 CodeCompletionString *Result = new CodeCompletionString; | |
319 unsigned NumBlocks; 320 if (ReadUnsigned(Str, StrEnd, NumBlocks)) | 318 unsigned NumBlocks; 319 if (ReadUnsigned(Str, StrEnd, NumBlocks)) |
321 return Result; | 320 return false; |
322 323 for (unsigned I = 0; I != NumBlocks; ++I) { 324 if (Str + 1 >= StrEnd) 325 break; 326 327 // Parse the next kind. 328 unsigned KindValue; 329 if (ReadUnsigned(Str, StrEnd, KindValue)) | 321 322 for (unsigned I = 0; I != NumBlocks; ++I) { 323 if (Str + 1 >= StrEnd) 324 break; 325 326 // Parse the next kind. 327 unsigned KindValue; 328 if (ReadUnsigned(Str, StrEnd, KindValue)) |
330 return Result; | 329 return false; |
331 332 switch (ChunkKind Kind = (ChunkKind)KindValue) { 333 case CK_TypedText: 334 case CK_Text: 335 case CK_Placeholder: 336 case CK_Informative: 337 case CK_ResultType: 338 case CK_CurrentParameter: { 339 unsigned StrLen; 340 if (ReadUnsigned(Str, StrEnd, StrLen) || (Str + StrLen > StrEnd)) | 330 331 switch (ChunkKind Kind = (ChunkKind)KindValue) { 332 case CK_TypedText: 333 case CK_Text: 334 case CK_Placeholder: 335 case CK_Informative: 336 case CK_ResultType: 337 case CK_CurrentParameter: { 338 unsigned StrLen; 339 if (ReadUnsigned(Str, StrEnd, StrLen) || (Str + StrLen > StrEnd)) |
341 return Result; | 340 return false; |
342 | 341 |
343 Result->AddChunk(Chunk(Kind, StringRef(Str, StrLen))); | 342 AddChunk(Chunk(Kind, StringRef(Str, StrLen))); |
344 Str += StrLen; 345 break; 346 } 347 348 case CK_Optional: { | 343 Str += StrLen; 344 break; 345 } 346 347 case CK_Optional: { |
349 std::auto_ptr<CodeCompletionString> Optional(Deserialize(Str, StrEnd)); 350 Result->AddOptionalChunk(Optional); | 348 std::auto_ptr<CodeCompletionString> Optional(new CodeCompletionString()); 349 if (Optional->Deserialize(Str, StrEnd)) 350 AddOptionalChunk(Optional); |
351 break; 352 } 353 354 case CK_LeftParen: 355 case CK_RightParen: 356 case CK_LeftBracket: 357 case CK_RightBracket: 358 case CK_LeftBrace: 359 case CK_RightBrace: 360 case CK_LeftAngle: 361 case CK_RightAngle: 362 case CK_Comma: 363 case CK_Colon: 364 case CK_SemiColon: 365 case CK_Equal: 366 case CK_HorizontalSpace: 367 case CK_VerticalSpace: | 351 break; 352 } 353 354 case CK_LeftParen: 355 case CK_RightParen: 356 case CK_LeftBracket: 357 case CK_RightBracket: 358 case CK_LeftBrace: 359 case CK_RightBrace: 360 case CK_LeftAngle: 361 case CK_RightAngle: 362 case CK_Comma: 363 case CK_Colon: 364 case CK_SemiColon: 365 case CK_Equal: 366 case CK_HorizontalSpace: 367 case CK_VerticalSpace: |
368 Result->AddChunk(Chunk(Kind)); | 368 AddChunk(Chunk(Kind)); |
369 break; 370 } 371 }; 372 | 369 break; 370 } 371 }; 372 |
373 return Result; | 373 return true; |
374} 375 376void CodeCompleteConsumer::Result::Destroy() { 377 if (Kind == RK_Pattern) { 378 delete Pattern; 379 Pattern = 0; 380 } 381} 382 | 374} 375 376void CodeCompleteConsumer::Result::Destroy() { 377 if (Kind == RK_Pattern) { 378 delete Pattern; 379 Pattern = 0; 380 } 381} 382 |
383unsigned CodeCompleteConsumer::Result::getPriorityFromDecl(NamedDecl *ND) { 384 if (!ND) 385 return CCP_Unlikely; 386 387 // Context-based decisions. 388 DeclContext *DC = ND->getDeclContext()->getLookupContext(); 389 if (DC->isFunctionOrMethod() || isa<BlockDecl>(DC)) 390 return CCP_LocalDeclaration; 391 if (DC->isRecord() || isa<ObjCContainerDecl>(DC)) 392 return CCP_MemberDeclaration; 393 394 // Content-based decisions. 395 if (isa<EnumConstantDecl>(ND)) 396 return CCP_Constant; 397 if (isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND)) 398 return CCP_Type; 399 return CCP_Declaration; 400} 401 |
|
383//===----------------------------------------------------------------------===// 384// Code completion overload candidate implementation 385//===----------------------------------------------------------------------===// 386FunctionDecl * 387CodeCompleteConsumer::OverloadCandidate::getFunction() const { 388 if (getKind() == CK_Function) 389 return Function; 390 else if (getKind() == CK_FunctionTemplate) --- 63 unchanged lines hidden (view full) --- 454 455 case Result::RK_Pattern: { 456 OS << "Pattern : " 457 << Results[I].Pattern->getAsString() << '\n'; 458 break; 459 } 460 } 461 } | 402//===----------------------------------------------------------------------===// 403// Code completion overload candidate implementation 404//===----------------------------------------------------------------------===// 405FunctionDecl * 406CodeCompleteConsumer::OverloadCandidate::getFunction() const { 407 if (getKind() == CK_Function) 408 return Function; 409 else if (getKind() == CK_FunctionTemplate) --- 63 unchanged lines hidden (view full) --- 473 474 case Result::RK_Pattern: { 475 OS << "Pattern : " 476 << Results[I].Pattern->getAsString() << '\n'; 477 break; 478 } 479 } 480 } |
462 463 // Once we've printed the code-completion results, suppress remaining 464 // diagnostics. 465 // FIXME: Move this somewhere else! 466 SemaRef.PP.getDiagnostics().setSuppressAllDiagnostics(); | |
467} 468 469void 470PrintingCodeCompleteConsumer::ProcessOverloadCandidates(Sema &SemaRef, 471 unsigned CurrentArg, 472 OverloadCandidate *Candidates, 473 unsigned NumCandidates) { 474 for (unsigned I = 0; I != NumCandidates; ++I) { 475 if (CodeCompletionString *CCS 476 = Candidates[I].CreateSignatureString(CurrentArg, SemaRef)) { 477 OS << "OVERLOAD: " << CCS->getAsString() << "\n"; 478 delete CCS; 479 } 480 } | 481} 482 483void 484PrintingCodeCompleteConsumer::ProcessOverloadCandidates(Sema &SemaRef, 485 unsigned CurrentArg, 486 OverloadCandidate *Candidates, 487 unsigned NumCandidates) { 488 for (unsigned I = 0; I != NumCandidates; ++I) { 489 if (CodeCompletionString *CCS 490 = Candidates[I].CreateSignatureString(CurrentArg, SemaRef)) { 491 OS << "OVERLOAD: " << CCS->getAsString() << "\n"; 492 delete CCS; 493 } 494 } |
481 482 // Once we've printed the code-completion results, suppress remaining 483 // diagnostics. 484 // FIXME: Move this somewhere else! 485 SemaRef.PP.getDiagnostics().setSuppressAllDiagnostics(); | |
486} 487 488void 489CIndexCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &SemaRef, 490 Result *Results, 491 unsigned NumResults) { 492 // Print the results. 493 for (unsigned I = 0; I != NumResults; ++I) { --- 95 unchanged lines hidden (view full) --- 589 590 case Result::RK_Keyword: 591 case Result::RK_Pattern: 592 Kind = CXCursor_NotImplemented; 593 break; 594 } 595 596 WriteUnsigned(OS, Kind); | 495} 496 497void 498CIndexCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &SemaRef, 499 Result *Results, 500 unsigned NumResults) { 501 // Print the results. 502 for (unsigned I = 0; I != NumResults; ++I) { --- 95 unchanged lines hidden (view full) --- 598 599 case Result::RK_Keyword: 600 case Result::RK_Pattern: 601 Kind = CXCursor_NotImplemented; 602 break; 603 } 604 605 WriteUnsigned(OS, Kind); |
606 WriteUnsigned(OS, Results[I].Priority); |
|
597 CodeCompletionString *CCS = Results[I].CreateCodeCompletionString(SemaRef); 598 assert(CCS && "No code-completion string?"); 599 CCS->Serialize(OS); 600 delete CCS; 601 } | 607 CodeCompletionString *CCS = Results[I].CreateCodeCompletionString(SemaRef); 608 assert(CCS && "No code-completion string?"); 609 CCS->Serialize(OS); 610 delete CCS; 611 } |
602 603 // Once we've printed the code-completion results, suppress remaining 604 // diagnostics. 605 // FIXME: Move this somewhere else! 606 SemaRef.PP.getDiagnostics().setSuppressAllDiagnostics(); | |
607} 608 609void 610CIndexCodeCompleteConsumer::ProcessOverloadCandidates(Sema &SemaRef, 611 unsigned CurrentArg, 612 OverloadCandidate *Candidates, 613 unsigned NumCandidates) { 614 for (unsigned I = 0; I != NumCandidates; ++I) { 615 WriteUnsigned(OS, CXCursor_NotImplemented); | 612} 613 614void 615CIndexCodeCompleteConsumer::ProcessOverloadCandidates(Sema &SemaRef, 616 unsigned CurrentArg, 617 OverloadCandidate *Candidates, 618 unsigned NumCandidates) { 619 for (unsigned I = 0; I != NumCandidates; ++I) { 620 WriteUnsigned(OS, CXCursor_NotImplemented); |
621 WriteUnsigned(OS, /*Priority=*/0); |
|
616 CodeCompletionString *CCS 617 = Candidates[I].CreateSignatureString(CurrentArg, SemaRef); 618 assert(CCS && "No code-completion string?"); 619 CCS->Serialize(OS); 620 delete CCS; 621 } | 622 CodeCompletionString *CCS 623 = Candidates[I].CreateSignatureString(CurrentArg, SemaRef); 624 assert(CCS && "No code-completion string?"); 625 CCS->Serialize(OS); 626 delete CCS; 627 } |
622 623 // Once we've printed the code-completion results, suppress remaining 624 // diagnostics. 625 // FIXME: Move this somewhere else! 626 SemaRef.PP.getDiagnostics().setSuppressAllDiagnostics(); | |
627} | 628} |