blob: 2334ab5128a70d9648ab1c57ea36e51b89966e50 [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"
John McCall19510852010-08-20 18:27:03 +000014#include "clang/Sema/Scope.h"
Douglas Gregore737f502010-08-12 20:07:10 +000015#include "clang/Sema/Sema.h"
Douglas Gregor75b71282009-09-18 17:54:00 +000016#include "clang/AST/DeclCXX.h"
John McCall7cd088e2010-08-24 07:21:54 +000017#include "clang/AST/DeclObjC.h"
John McCall2a7fb272010-08-25 05:32:35 +000018#include "clang/AST/DeclTemplate.h"
Douglas Gregor81b747b2009-09-17 21:32:03 +000019#include "clang/Lex/Preprocessor.h"
Douglas Gregor2b4074f2009-12-01 05:55:20 +000020#include "clang-c/Index.h"
Douglas Gregor81b747b2009-09-17 21:32:03 +000021#include "llvm/ADT/STLExtras.h"
Douglas Gregor577cdfd2011-02-17 00:22:45 +000022#include "llvm/ADT/Twine.h"
Douglas Gregor81b747b2009-09-17 21:32:03 +000023#include "llvm/Support/raw_ostream.h"
24#include <algorithm>
Douglas Gregore6e03612009-09-18 22:15:54 +000025#include <cstring>
26#include <functional>
Douglas Gregor92eff462009-11-17 16:43:05 +000027
Douglas Gregor81b747b2009-09-17 21:32:03 +000028using namespace clang;
Douglas Gregor92eff462009-11-17 16:43:05 +000029using llvm::StringRef;
Douglas Gregor81b747b2009-09-17 21:32:03 +000030
Douglas Gregore6e03612009-09-18 22:15:54 +000031//===----------------------------------------------------------------------===//
Douglas Gregor6f942b22010-09-21 16:06:22 +000032// Code completion context implementation
33//===----------------------------------------------------------------------===//
34
35bool CodeCompletionContext::wantConstructorResults() const {
36 switch (Kind) {
Douglas Gregor52779fb2010-09-23 23:01:17 +000037 case CCC_Recovery:
Douglas Gregor6f942b22010-09-21 16:06:22 +000038 case CCC_Statement:
39 case CCC_Expression:
40 case CCC_ObjCMessageReceiver:
41 case CCC_ParenthesizedExpression:
42 return true;
43
44 case CCC_TopLevel:
45 case CCC_ObjCInterface:
46 case CCC_ObjCImplementation:
47 case CCC_ObjCIvarList:
48 case CCC_ClassStructUnion:
49 case CCC_MemberAccess:
50 case CCC_EnumTag:
51 case CCC_UnionTag:
52 case CCC_ClassOrStructTag:
53 case CCC_ObjCProtocolName:
54 case CCC_Namespace:
55 case CCC_Type:
56 case CCC_Name:
57 case CCC_PotentiallyQualifiedName:
58 case CCC_MacroName:
59 case CCC_MacroNameUse:
60 case CCC_PreprocessorExpression:
61 case CCC_PreprocessorDirective:
62 case CCC_NaturalLanguage:
63 case CCC_SelectorName:
64 case CCC_TypeQualifiers:
Douglas Gregor52779fb2010-09-23 23:01:17 +000065 case CCC_Other:
Douglas Gregor5c722c702011-02-18 23:30:37 +000066 case CCC_OtherWithMacros:
Douglas Gregor6f942b22010-09-21 16:06:22 +000067 return false;
68 }
69
70 return false;
71}
72
73//===----------------------------------------------------------------------===//
Douglas Gregore6e03612009-09-18 22:15:54 +000074// Code completion string implementation
75//===----------------------------------------------------------------------===//
Douglas Gregor218937c2011-02-01 19:23:04 +000076CodeCompletionString::Chunk::Chunk(ChunkKind Kind, const char *Text)
Daniel Dunbarad5757f2009-11-12 18:40:12 +000077 : Kind(Kind), Text("")
Douglas Gregor0563c262009-09-22 23:15:58 +000078{
Douglas Gregor0c8296d2009-11-07 00:00:49 +000079 switch (Kind) {
80 case CK_TypedText:
81 case CK_Text:
82 case CK_Placeholder:
83 case CK_Informative:
Douglas Gregorff5ce6e2009-12-18 18:53:37 +000084 case CK_ResultType:
Douglas Gregor218937c2011-02-01 19:23:04 +000085 case CK_CurrentParameter:
86 this->Text = Text;
Douglas Gregor0c8296d2009-11-07 00:00:49 +000087 break;
Douglas Gregor0c8296d2009-11-07 00:00:49 +000088
89 case CK_Optional:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +000090 llvm_unreachable("Optional strings cannot be created from text");
Douglas Gregor0c8296d2009-11-07 00:00:49 +000091 break;
92
93 case CK_LeftParen:
94 this->Text = "(";
95 break;
96
97 case CK_RightParen:
98 this->Text = ")";
99 break;
100
101 case CK_LeftBracket:
102 this->Text = "[";
103 break;
104
105 case CK_RightBracket:
106 this->Text = "]";
107 break;
108
109 case CK_LeftBrace:
110 this->Text = "{";
111 break;
112
113 case CK_RightBrace:
114 this->Text = "}";
115 break;
116
117 case CK_LeftAngle:
118 this->Text = "<";
119 break;
120
121 case CK_RightAngle:
122 this->Text = ">";
123 break;
124
125 case CK_Comma:
126 this->Text = ", ";
127 break;
Douglas Gregor01dfea02010-01-10 23:08:15 +0000128
129 case CK_Colon:
Douglas Gregore8f5a172010-04-07 00:21:17 +0000130 this->Text = ":";
Douglas Gregor01dfea02010-01-10 23:08:15 +0000131 break;
132
133 case CK_SemiColon:
134 this->Text = ";";
135 break;
136
137 case CK_Equal:
138 this->Text = " = ";
139 break;
140
141 case CK_HorizontalSpace:
142 this->Text = " ";
143 break;
144
145 case CK_VerticalSpace:
146 this->Text = "\n";
147 break;
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000148 }
Douglas Gregor0563c262009-09-22 23:15:58 +0000149}
150
151CodeCompletionString::Chunk
Douglas Gregor218937c2011-02-01 19:23:04 +0000152CodeCompletionString::Chunk::CreateText(const char *Text) {
Douglas Gregor0563c262009-09-22 23:15:58 +0000153 return Chunk(CK_Text, Text);
Douglas Gregore6e03612009-09-18 22:15:54 +0000154}
155
156CodeCompletionString::Chunk
Douglas Gregor218937c2011-02-01 19:23:04 +0000157CodeCompletionString::Chunk::CreateOptional(CodeCompletionString *Optional) {
Douglas Gregore6e03612009-09-18 22:15:54 +0000158 Chunk Result;
159 Result.Kind = CK_Optional;
Douglas Gregor218937c2011-02-01 19:23:04 +0000160 Result.Optional = Optional;
Douglas Gregore6e03612009-09-18 22:15:54 +0000161 return Result;
162}
163
164CodeCompletionString::Chunk
Douglas Gregor218937c2011-02-01 19:23:04 +0000165CodeCompletionString::Chunk::CreatePlaceholder(const char *Placeholder) {
Douglas Gregor0563c262009-09-22 23:15:58 +0000166 return Chunk(CK_Placeholder, Placeholder);
167}
168
169CodeCompletionString::Chunk
Douglas Gregor218937c2011-02-01 19:23:04 +0000170CodeCompletionString::Chunk::CreateInformative(const char *Informative) {
Douglas Gregor0563c262009-09-22 23:15:58 +0000171 return Chunk(CK_Informative, Informative);
Douglas Gregore6e03612009-09-18 22:15:54 +0000172}
173
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000174CodeCompletionString::Chunk
Douglas Gregor218937c2011-02-01 19:23:04 +0000175CodeCompletionString::Chunk::CreateResultType(const char *ResultType) {
Douglas Gregorff5ce6e2009-12-18 18:53:37 +0000176 return Chunk(CK_ResultType, ResultType);
177}
178
179CodeCompletionString::Chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000180CodeCompletionString::Chunk::CreateCurrentParameter(
Douglas Gregor218937c2011-02-01 19:23:04 +0000181 const char *CurrentParameter) {
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000182 return Chunk(CK_CurrentParameter, CurrentParameter);
183}
184
Douglas Gregor218937c2011-02-01 19:23:04 +0000185CodeCompletionString::CodeCompletionString(const Chunk *Chunks,
186 unsigned NumChunks,
187 unsigned Priority,
188 CXAvailabilityKind Availability)
189 : NumChunks(NumChunks), Priority(Priority), Availability(Availability)
190{
191 Chunk *StoredChunks = reinterpret_cast<Chunk *>(this + 1);
192 for (unsigned I = 0; I != NumChunks; ++I)
193 StoredChunks[I] = Chunks[I];
Douglas Gregore6e03612009-09-18 22:15:54 +0000194}
195
196std::string CodeCompletionString::getAsString() const {
197 std::string Result;
198 llvm::raw_string_ostream OS(Result);
199
200 for (iterator C = begin(), CEnd = end(); C != CEnd; ++C) {
201 switch (C->Kind) {
Douglas Gregore6e03612009-09-18 22:15:54 +0000202 case CK_Optional: OS << "{#" << C->Optional->getAsString() << "#}"; break;
Douglas Gregor0563c262009-09-22 23:15:58 +0000203 case CK_Placeholder: OS << "<#" << C->Text << "#>"; break;
Douglas Gregorff5ce6e2009-12-18 18:53:37 +0000204
205 case CK_Informative:
206 case CK_ResultType:
207 OS << "[#" << C->Text << "#]";
208 break;
209
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000210 case CK_CurrentParameter: OS << "<#" << C->Text << "#>"; break;
211 default: OS << C->Text; break;
Douglas Gregore6e03612009-09-18 22:15:54 +0000212 }
213 }
Dan Gohman6bdeb402010-07-26 21:33:22 +0000214 return OS.str();
Douglas Gregore6e03612009-09-18 22:15:54 +0000215}
216
Douglas Gregor54f01612009-11-19 00:01:57 +0000217const char *CodeCompletionString::getTypedText() const {
218 for (iterator C = begin(), CEnd = end(); C != CEnd; ++C)
219 if (C->Kind == CK_TypedText)
220 return C->Text;
221
222 return 0;
223}
224
Douglas Gregordae68752011-02-01 22:57:45 +0000225const char *CodeCompletionAllocator::CopyString(llvm::StringRef String) {
226 char *Mem = (char *)Allocate(String.size() + 1, 1);
227 std::copy(String.begin(), String.end(), Mem);
228 Mem[String.size()] = 0;
229 return Mem;
230}
231
Douglas Gregor577cdfd2011-02-17 00:22:45 +0000232const char *CodeCompletionAllocator::CopyString(llvm::Twine String) {
233 // FIXME: It would be more efficient to teach Twine to tell us its size and
234 // then add a routine there to fill in an allocated char* with the contents
235 // of the string.
236 llvm::SmallString<128> Data;
237 return CopyString(String.toStringRef(Data));
238}
239
Douglas Gregor218937c2011-02-01 19:23:04 +0000240CodeCompletionString *CodeCompletionBuilder::TakeString() {
241 void *Mem = Allocator.Allocate(
242 sizeof(CodeCompletionString) + sizeof(Chunk) * Chunks.size(),
243 llvm::alignOf<CodeCompletionString>());
244 CodeCompletionString *Result
245 = new (Mem) CodeCompletionString(Chunks.data(), Chunks.size(),
246 Priority, Availability);
247 Chunks.clear();
Douglas Gregor54f01612009-11-19 00:01:57 +0000248 return Result;
249}
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000250
John McCall0a2c5e22010-08-25 06:19:51 +0000251unsigned CodeCompletionResult::getPriorityFromDecl(NamedDecl *ND) {
Douglas Gregor12e13132010-05-26 22:00:08 +0000252 if (!ND)
253 return CCP_Unlikely;
254
255 // Context-based decisions.
Sebastian Redl7a126a42010-08-31 00:36:30 +0000256 DeclContext *DC = ND->getDeclContext()->getRedeclContext();
Douglas Gregor97fe61c2010-09-18 15:16:27 +0000257 if (DC->isFunctionOrMethod() || isa<BlockDecl>(DC)) {
258 // _cmd is relatively rare
259 if (ImplicitParamDecl *ImplicitParam = dyn_cast<ImplicitParamDecl>(ND))
260 if (ImplicitParam->getIdentifier() &&
261 ImplicitParam->getIdentifier()->isStr("_cmd"))
262 return CCP_ObjC_cmd;
263
Douglas Gregor12e13132010-05-26 22:00:08 +0000264 return CCP_LocalDeclaration;
Douglas Gregor97fe61c2010-09-18 15:16:27 +0000265 }
Douglas Gregor12e13132010-05-26 22:00:08 +0000266 if (DC->isRecord() || isa<ObjCContainerDecl>(DC))
267 return CCP_MemberDeclaration;
268
269 // Content-based decisions.
270 if (isa<EnumConstantDecl>(ND))
271 return CCP_Constant;
272 if (isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND))
273 return CCP_Type;
Douglas Gregor97fe61c2010-09-18 15:16:27 +0000274
Douglas Gregor12e13132010-05-26 22:00:08 +0000275 return CCP_Declaration;
276}
277
Douglas Gregore6e03612009-09-18 22:15:54 +0000278//===----------------------------------------------------------------------===//
Douglas Gregor05944382009-09-23 00:16:58 +0000279// Code completion overload candidate implementation
280//===----------------------------------------------------------------------===//
281FunctionDecl *
282CodeCompleteConsumer::OverloadCandidate::getFunction() const {
283 if (getKind() == CK_Function)
284 return Function;
285 else if (getKind() == CK_FunctionTemplate)
286 return FunctionTemplate->getTemplatedDecl();
287 else
288 return 0;
289}
290
291const FunctionType *
292CodeCompleteConsumer::OverloadCandidate::getFunctionType() const {
293 switch (Kind) {
294 case CK_Function:
295 return Function->getType()->getAs<FunctionType>();
296
297 case CK_FunctionTemplate:
298 return FunctionTemplate->getTemplatedDecl()->getType()
299 ->getAs<FunctionType>();
300
301 case CK_FunctionType:
302 return Type;
303 }
304
305 return 0;
306}
307
308//===----------------------------------------------------------------------===//
Douglas Gregore6e03612009-09-18 22:15:54 +0000309// Code completion consumer implementation
310//===----------------------------------------------------------------------===//
311
Douglas Gregor86d9a522009-09-21 16:56:56 +0000312CodeCompleteConsumer::~CodeCompleteConsumer() { }
Douglas Gregore6e03612009-09-18 22:15:54 +0000313
Douglas Gregor81b747b2009-09-17 21:32:03 +0000314void
Daniel Dunbar3a2838d2009-11-13 08:58:20 +0000315PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &SemaRef,
Douglas Gregore6b1bb62010-08-11 21:23:17 +0000316 CodeCompletionContext Context,
John McCall0a2c5e22010-08-25 06:19:51 +0000317 CodeCompletionResult *Results,
Douglas Gregor81b747b2009-09-17 21:32:03 +0000318 unsigned NumResults) {
Douglas Gregor1e5e6682010-08-26 13:48:20 +0000319 std::stable_sort(Results, Results + NumResults);
320
Douglas Gregor81b747b2009-09-17 21:32:03 +0000321 // Print the results.
322 for (unsigned I = 0; I != NumResults; ++I) {
Douglas Gregorf52cede2009-10-09 22:16:47 +0000323 OS << "COMPLETION: ";
Douglas Gregor81b747b2009-09-17 21:32:03 +0000324 switch (Results[I].Kind) {
John McCall0a2c5e22010-08-25 06:19:51 +0000325 case CodeCompletionResult::RK_Declaration:
Benjamin Kramer900fc632010-04-17 09:33:03 +0000326 OS << Results[I].Declaration;
Douglas Gregor81b747b2009-09-17 21:32:03 +0000327 if (Results[I].Hidden)
328 OS << " (Hidden)";
Douglas Gregor86d9a522009-09-21 16:56:56 +0000329 if (CodeCompletionString *CCS
Douglas Gregor218937c2011-02-01 19:23:04 +0000330 = Results[I].CreateCodeCompletionString(SemaRef, Allocator)) {
Douglas Gregore6e03612009-09-18 22:15:54 +0000331 OS << " : " << CCS->getAsString();
Douglas Gregore6e03612009-09-18 22:15:54 +0000332 }
333
Douglas Gregor81b747b2009-09-17 21:32:03 +0000334 OS << '\n';
335 break;
336
John McCall0a2c5e22010-08-25 06:19:51 +0000337 case CodeCompletionResult::RK_Keyword:
Douglas Gregorab0b4f12010-01-13 23:24:38 +0000338 OS << Results[I].Keyword << '\n';
Douglas Gregor81b747b2009-09-17 21:32:03 +0000339 break;
Douglas Gregor3f7c7f42009-10-30 16:50:04 +0000340
John McCall0a2c5e22010-08-25 06:19:51 +0000341 case CodeCompletionResult::RK_Macro: {
Douglas Gregorab0b4f12010-01-13 23:24:38 +0000342 OS << Results[I].Macro->getName();
Douglas Gregor3f7c7f42009-10-30 16:50:04 +0000343 if (CodeCompletionString *CCS
Douglas Gregor218937c2011-02-01 19:23:04 +0000344 = Results[I].CreateCodeCompletionString(SemaRef, Allocator)) {
Douglas Gregor3f7c7f42009-10-30 16:50:04 +0000345 OS << " : " << CCS->getAsString();
Douglas Gregor3f7c7f42009-10-30 16:50:04 +0000346 }
347 OS << '\n';
348 break;
349 }
Douglas Gregor54f01612009-11-19 00:01:57 +0000350
John McCall0a2c5e22010-08-25 06:19:51 +0000351 case CodeCompletionResult::RK_Pattern: {
Douglas Gregorab0b4f12010-01-13 23:24:38 +0000352 OS << "Pattern : "
Douglas Gregor54f01612009-11-19 00:01:57 +0000353 << Results[I].Pattern->getAsString() << '\n';
354 break;
355 }
Douglas Gregor81b747b2009-09-17 21:32:03 +0000356 }
357 }
Douglas Gregor81b747b2009-09-17 21:32:03 +0000358}
Douglas Gregor05944382009-09-23 00:16:58 +0000359
360void
Daniel Dunbar3a2838d2009-11-13 08:58:20 +0000361PrintingCodeCompleteConsumer::ProcessOverloadCandidates(Sema &SemaRef,
362 unsigned CurrentArg,
Douglas Gregor05944382009-09-23 00:16:58 +0000363 OverloadCandidate *Candidates,
364 unsigned NumCandidates) {
365 for (unsigned I = 0; I != NumCandidates; ++I) {
Douglas Gregor86d802e2009-09-23 00:34:09 +0000366 if (CodeCompletionString *CCS
Douglas Gregor218937c2011-02-01 19:23:04 +0000367 = Candidates[I].CreateSignatureString(CurrentArg, SemaRef,
368 Allocator)) {
Douglas Gregorf52cede2009-10-09 22:16:47 +0000369 OS << "OVERLOAD: " << CCS->getAsString() << "\n";
Douglas Gregor05944382009-09-23 00:16:58 +0000370 }
371 }
Douglas Gregor05944382009-09-23 00:16:58 +0000372}
Douglas Gregor0c8296d2009-11-07 00:00:49 +0000373
John McCall0a2c5e22010-08-25 06:19:51 +0000374void CodeCompletionResult::computeCursorKindAndAvailability() {
Douglas Gregor87c08a52010-08-13 22:48:40 +0000375 switch (Kind) {
376 case RK_Declaration:
Douglas Gregor58ddb602010-08-23 23:00:57 +0000377 // Set the availability based on attributes.
Douglas Gregor0a0d2b12011-03-23 00:50:03 +0000378 switch (Declaration->getAvailability()) {
379 case AR_Available:
380 case AR_NotYetIntroduced:
381 Availability = CXAvailability_Available;
382 break;
Douglas Gregor58ddb602010-08-23 23:00:57 +0000383
Douglas Gregor0a0d2b12011-03-23 00:50:03 +0000384 case AR_Deprecated:
385 Availability = CXAvailability_Deprecated;
386 break;
387
388 case AR_Unavailable:
389 Availability = CXAvailability_NotAvailable;
390 break;
391 }
392
Douglas Gregore8d7beb2010-09-03 23:30:36 +0000393 if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Declaration))
394 if (Function->isDeleted())
Douglas Gregor58ddb602010-08-23 23:00:57 +0000395 Availability = CXAvailability_NotAvailable;
Douglas Gregore8d7beb2010-09-03 23:30:36 +0000396
397 CursorKind = getCursorKindForDecl(Declaration);
398 if (CursorKind == CXCursor_UnexposedDecl)
Douglas Gregor87c08a52010-08-13 22:48:40 +0000399 CursorKind = CXCursor_NotImplemented;
Douglas Gregor87c08a52010-08-13 22:48:40 +0000400 break;
401
John McCall0a2c5e22010-08-25 06:19:51 +0000402 case RK_Macro:
Douglas Gregor58ddb602010-08-23 23:00:57 +0000403 Availability = CXAvailability_Available;
Douglas Gregor87c08a52010-08-13 22:48:40 +0000404 CursorKind = CXCursor_MacroDefinition;
405 break;
406
John McCall0a2c5e22010-08-25 06:19:51 +0000407 case RK_Keyword:
Douglas Gregor58ddb602010-08-23 23:00:57 +0000408 Availability = CXAvailability_Available;
Douglas Gregor87c08a52010-08-13 22:48:40 +0000409 CursorKind = CXCursor_NotImplemented;
410 break;
411
John McCall0a2c5e22010-08-25 06:19:51 +0000412 case RK_Pattern:
Douglas Gregor87c08a52010-08-13 22:48:40 +0000413 // Do nothing: Patterns can come with cursor kinds!
414 break;
Douglas Gregor1abc6bc2010-08-04 16:47:14 +0000415 }
416}
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000417
Douglas Gregor721f3592010-08-25 18:41:16 +0000418/// \brief Retrieve the name that should be used to order a result.
419///
420/// If the name needs to be constructed as a string, that string will be
421/// saved into Saved and the returned StringRef will refer to it.
422static llvm::StringRef getOrderedName(const CodeCompletionResult &R,
423 std::string &Saved) {
424 switch (R.Kind) {
425 case CodeCompletionResult::RK_Keyword:
426 return R.Keyword;
427
428 case CodeCompletionResult::RK_Pattern:
429 return R.Pattern->getTypedText();
430
431 case CodeCompletionResult::RK_Macro:
432 return R.Macro->getName();
433
434 case CodeCompletionResult::RK_Declaration:
435 // Handle declarations below.
436 break;
437 }
438
439 DeclarationName Name = R.Declaration->getDeclName();
440
441 // If the name is a simple identifier (by far the common case), or a
442 // zero-argument selector, just return a reference to that identifier.
443 if (IdentifierInfo *Id = Name.getAsIdentifierInfo())
444 return Id->getName();
445 if (Name.isObjCZeroArgSelector())
446 if (IdentifierInfo *Id
447 = Name.getObjCSelector().getIdentifierInfoForSlot(0))
448 return Id->getName();
449
450 Saved = Name.getAsString();
451 return Saved;
452}
453
454bool clang::operator<(const CodeCompletionResult &X,
455 const CodeCompletionResult &Y) {
456 std::string XSaved, YSaved;
457 llvm::StringRef XStr = getOrderedName(X, XSaved);
458 llvm::StringRef YStr = getOrderedName(Y, YSaved);
459 int cmp = XStr.compare_lower(YStr);
460 if (cmp)
461 return cmp < 0;
462
Douglas Gregor1e5e6682010-08-26 13:48:20 +0000463 // If case-insensitive comparison fails, try case-sensitive comparison.
464 cmp = XStr.compare(YStr);
465 if (cmp)
466 return cmp < 0;
Douglas Gregor721f3592010-08-25 18:41:16 +0000467
468 return false;
469}