blob: b7037ce83e7fdbfe8da2a56ae691b98911aa3628 [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"
John McCall8b0666c2010-08-20 18:27:03 +000014#include "clang/Sema/Scope.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000015#include "clang/Sema/Sema.h"
Douglas Gregor56c2dbc2009-09-18 17:54:00 +000016#include "clang/AST/DeclCXX.h"
John McCallde6836a2010-08-24 07:21:54 +000017#include "clang/AST/DeclObjC.h"
John McCall19c1bfd2010-08-25 05:32:35 +000018#include "clang/AST/DeclTemplate.h"
Douglas Gregor2436e712009-09-17 21:32:03 +000019#include "clang/Lex/Preprocessor.h"
Douglas Gregorf09935f2009-12-01 05:55:20 +000020#include "clang-c/Index.h"
Douglas Gregor2436e712009-09-17 21:32:03 +000021#include "llvm/ADT/STLExtras.h"
Douglas Gregor669a25a2011-02-17 00:22:45 +000022#include "llvm/ADT/Twine.h"
Douglas Gregor2436e712009-09-17 21:32:03 +000023#include "llvm/Support/raw_ostream.h"
24#include <algorithm>
Douglas Gregorfedc3282009-09-18 22:15:54 +000025#include <cstring>
26#include <functional>
Douglas Gregorab6ccb52009-11-17 16:43:05 +000027
Douglas Gregor2436e712009-09-17 21:32:03 +000028using namespace clang;
Douglas Gregorab6ccb52009-11-17 16:43:05 +000029using llvm::StringRef;
Douglas Gregor2436e712009-09-17 21:32:03 +000030
Douglas Gregorfedc3282009-09-18 22:15:54 +000031//===----------------------------------------------------------------------===//
Douglas Gregor0212fd72010-09-21 16:06:22 +000032// Code completion context implementation
33//===----------------------------------------------------------------------===//
34
35bool CodeCompletionContext::wantConstructorResults() const {
36 switch (Kind) {
Douglas Gregor0ac41382010-09-23 23:01:17 +000037 case CCC_Recovery:
Douglas Gregor0212fd72010-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 Gregor0ac41382010-09-23 23:01:17 +000065 case CCC_Other:
Douglas Gregor3a69eaf2011-02-18 23:30:37 +000066 case CCC_OtherWithMacros:
Douglas Gregor0212fd72010-09-21 16:06:22 +000067 return false;
68 }
69
70 return false;
71}
72
73//===----------------------------------------------------------------------===//
Douglas Gregorfedc3282009-09-18 22:15:54 +000074// Code completion string implementation
75//===----------------------------------------------------------------------===//
Douglas Gregorb278aaf2011-02-01 19:23:04 +000076CodeCompletionString::Chunk::Chunk(ChunkKind Kind, const char *Text)
Daniel Dunbarb0a19422009-11-12 18:40:12 +000077 : Kind(Kind), Text("")
Douglas Gregor5bf52692009-09-22 23:15:58 +000078{
Douglas Gregor9eb77012009-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 Gregorb3fa9192009-12-18 18:53:37 +000084 case CK_ResultType:
Douglas Gregorb278aaf2011-02-01 19:23:04 +000085 case CK_CurrentParameter:
86 this->Text = Text;
Douglas Gregor9eb77012009-11-07 00:00:49 +000087 break;
Douglas Gregor9eb77012009-11-07 00:00:49 +000088
89 case CK_Optional:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +000090 llvm_unreachable("Optional strings cannot be created from text");
Douglas Gregor9eb77012009-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 Gregor504a6ae2010-01-10 23:08:15 +0000128
129 case CK_Colon:
Douglas Gregor636a61e2010-04-07 00:21:17 +0000130 this->Text = ":";
Douglas Gregor504a6ae2010-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 Gregor9eb77012009-11-07 00:00:49 +0000148 }
Douglas Gregor5bf52692009-09-22 23:15:58 +0000149}
150
151CodeCompletionString::Chunk
Douglas Gregorb278aaf2011-02-01 19:23:04 +0000152CodeCompletionString::Chunk::CreateText(const char *Text) {
Douglas Gregor5bf52692009-09-22 23:15:58 +0000153 return Chunk(CK_Text, Text);
Douglas Gregorfedc3282009-09-18 22:15:54 +0000154}
155
156CodeCompletionString::Chunk
Douglas Gregorb278aaf2011-02-01 19:23:04 +0000157CodeCompletionString::Chunk::CreateOptional(CodeCompletionString *Optional) {
Douglas Gregorfedc3282009-09-18 22:15:54 +0000158 Chunk Result;
159 Result.Kind = CK_Optional;
Douglas Gregorb278aaf2011-02-01 19:23:04 +0000160 Result.Optional = Optional;
Douglas Gregorfedc3282009-09-18 22:15:54 +0000161 return Result;
162}
163
164CodeCompletionString::Chunk
Douglas Gregorb278aaf2011-02-01 19:23:04 +0000165CodeCompletionString::Chunk::CreatePlaceholder(const char *Placeholder) {
Douglas Gregor5bf52692009-09-22 23:15:58 +0000166 return Chunk(CK_Placeholder, Placeholder);
167}
168
169CodeCompletionString::Chunk
Douglas Gregorb278aaf2011-02-01 19:23:04 +0000170CodeCompletionString::Chunk::CreateInformative(const char *Informative) {
Douglas Gregor5bf52692009-09-22 23:15:58 +0000171 return Chunk(CK_Informative, Informative);
Douglas Gregorfedc3282009-09-18 22:15:54 +0000172}
173
Douglas Gregor9eb77012009-11-07 00:00:49 +0000174CodeCompletionString::Chunk
Douglas Gregorb278aaf2011-02-01 19:23:04 +0000175CodeCompletionString::Chunk::CreateResultType(const char *ResultType) {
Douglas Gregorb3fa9192009-12-18 18:53:37 +0000176 return Chunk(CK_ResultType, ResultType);
177}
178
179CodeCompletionString::Chunk
Douglas Gregor9eb77012009-11-07 00:00:49 +0000180CodeCompletionString::Chunk::CreateCurrentParameter(
Douglas Gregorb278aaf2011-02-01 19:23:04 +0000181 const char *CurrentParameter) {
Douglas Gregor9eb77012009-11-07 00:00:49 +0000182 return Chunk(CK_CurrentParameter, CurrentParameter);
183}
184
Douglas Gregorb278aaf2011-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 Gregorfedc3282009-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 Gregorfedc3282009-09-18 22:15:54 +0000202 case CK_Optional: OS << "{#" << C->Optional->getAsString() << "#}"; break;
Douglas Gregor5bf52692009-09-22 23:15:58 +0000203 case CK_Placeholder: OS << "<#" << C->Text << "#>"; break;
Douglas Gregorb3fa9192009-12-18 18:53:37 +0000204
205 case CK_Informative:
206 case CK_ResultType:
207 OS << "[#" << C->Text << "#]";
208 break;
209
Douglas Gregor9eb77012009-11-07 00:00:49 +0000210 case CK_CurrentParameter: OS << "<#" << C->Text << "#>"; break;
211 default: OS << C->Text; break;
Douglas Gregorfedc3282009-09-18 22:15:54 +0000212 }
213 }
Dan Gohman4888f1a2010-07-26 21:33:22 +0000214 return OS.str();
Douglas Gregorfedc3282009-09-18 22:15:54 +0000215}
216
Douglas Gregor45f83ee2009-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 Gregorbcbf46c2011-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 Gregor669a25a2011-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 Gregorb278aaf2011-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 Gregor45f83ee2009-11-19 00:01:57 +0000248 return Result;
249}
Douglas Gregor9eb77012009-11-07 00:00:49 +0000250
John McCall276321a2010-08-25 06:19:51 +0000251unsigned CodeCompletionResult::getPriorityFromDecl(NamedDecl *ND) {
Douglas Gregora2db7932010-05-26 22:00:08 +0000252 if (!ND)
253 return CCP_Unlikely;
254
255 // Context-based decisions.
Sebastian Redl50c68252010-08-31 00:36:30 +0000256 DeclContext *DC = ND->getDeclContext()->getRedeclContext();
Douglas Gregor521db402010-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 Gregora2db7932010-05-26 22:00:08 +0000264 return CCP_LocalDeclaration;
Douglas Gregor521db402010-09-18 15:16:27 +0000265 }
Douglas Gregora2db7932010-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 Gregor521db402010-09-18 15:16:27 +0000274
Douglas Gregora2db7932010-05-26 22:00:08 +0000275 return CCP_Declaration;
276}
277
Douglas Gregorfedc3282009-09-18 22:15:54 +0000278//===----------------------------------------------------------------------===//
Douglas Gregor05f477c2009-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 Gregorfedc3282009-09-18 22:15:54 +0000309// Code completion consumer implementation
310//===----------------------------------------------------------------------===//
311
Douglas Gregor3545ff42009-09-21 16:56:56 +0000312CodeCompleteConsumer::~CodeCompleteConsumer() { }
Douglas Gregorfedc3282009-09-18 22:15:54 +0000313
Douglas Gregor2436e712009-09-17 21:32:03 +0000314void
Daniel Dunbar242ea9a2009-11-13 08:58:20 +0000315PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &SemaRef,
Douglas Gregor00c37ef2010-08-11 21:23:17 +0000316 CodeCompletionContext Context,
John McCall276321a2010-08-25 06:19:51 +0000317 CodeCompletionResult *Results,
Douglas Gregor2436e712009-09-17 21:32:03 +0000318 unsigned NumResults) {
Douglas Gregor49f67ce2010-08-26 13:48:20 +0000319 std::stable_sort(Results, Results + NumResults);
320
Douglas Gregor2436e712009-09-17 21:32:03 +0000321 // Print the results.
322 for (unsigned I = 0; I != NumResults; ++I) {
Douglas Gregor58acf322009-10-09 22:16:47 +0000323 OS << "COMPLETION: ";
Douglas Gregor2436e712009-09-17 21:32:03 +0000324 switch (Results[I].Kind) {
John McCall276321a2010-08-25 06:19:51 +0000325 case CodeCompletionResult::RK_Declaration:
Benjamin Kramerb11416d2010-04-17 09:33:03 +0000326 OS << Results[I].Declaration;
Douglas Gregor2436e712009-09-17 21:32:03 +0000327 if (Results[I].Hidden)
328 OS << " (Hidden)";
Douglas Gregor3545ff42009-09-21 16:56:56 +0000329 if (CodeCompletionString *CCS
Douglas Gregorb278aaf2011-02-01 19:23:04 +0000330 = Results[I].CreateCodeCompletionString(SemaRef, Allocator)) {
Douglas Gregorfedc3282009-09-18 22:15:54 +0000331 OS << " : " << CCS->getAsString();
Douglas Gregorfedc3282009-09-18 22:15:54 +0000332 }
333
Douglas Gregor2436e712009-09-17 21:32:03 +0000334 OS << '\n';
335 break;
336
John McCall276321a2010-08-25 06:19:51 +0000337 case CodeCompletionResult::RK_Keyword:
Douglas Gregor52ce62f2010-01-13 23:24:38 +0000338 OS << Results[I].Keyword << '\n';
Douglas Gregor2436e712009-09-17 21:32:03 +0000339 break;
Douglas Gregorf329c7c2009-10-30 16:50:04 +0000340
John McCall276321a2010-08-25 06:19:51 +0000341 case CodeCompletionResult::RK_Macro: {
Douglas Gregor52ce62f2010-01-13 23:24:38 +0000342 OS << Results[I].Macro->getName();
Douglas Gregorf329c7c2009-10-30 16:50:04 +0000343 if (CodeCompletionString *CCS
Douglas Gregorb278aaf2011-02-01 19:23:04 +0000344 = Results[I].CreateCodeCompletionString(SemaRef, Allocator)) {
Douglas Gregorf329c7c2009-10-30 16:50:04 +0000345 OS << " : " << CCS->getAsString();
Douglas Gregorf329c7c2009-10-30 16:50:04 +0000346 }
347 OS << '\n';
348 break;
349 }
Douglas Gregor45f83ee2009-11-19 00:01:57 +0000350
John McCall276321a2010-08-25 06:19:51 +0000351 case CodeCompletionResult::RK_Pattern: {
Douglas Gregor52ce62f2010-01-13 23:24:38 +0000352 OS << "Pattern : "
Douglas Gregor45f83ee2009-11-19 00:01:57 +0000353 << Results[I].Pattern->getAsString() << '\n';
354 break;
355 }
Douglas Gregor2436e712009-09-17 21:32:03 +0000356 }
357 }
Douglas Gregor2436e712009-09-17 21:32:03 +0000358}
Douglas Gregor05f477c2009-09-23 00:16:58 +0000359
360void
Daniel Dunbar242ea9a2009-11-13 08:58:20 +0000361PrintingCodeCompleteConsumer::ProcessOverloadCandidates(Sema &SemaRef,
362 unsigned CurrentArg,
Douglas Gregor05f477c2009-09-23 00:16:58 +0000363 OverloadCandidate *Candidates,
364 unsigned NumCandidates) {
365 for (unsigned I = 0; I != NumCandidates; ++I) {
Douglas Gregorf0f51982009-09-23 00:34:09 +0000366 if (CodeCompletionString *CCS
Douglas Gregorb278aaf2011-02-01 19:23:04 +0000367 = Candidates[I].CreateSignatureString(CurrentArg, SemaRef,
368 Allocator)) {
Douglas Gregor58acf322009-10-09 22:16:47 +0000369 OS << "OVERLOAD: " << CCS->getAsString() << "\n";
Douglas Gregor05f477c2009-09-23 00:16:58 +0000370 }
371 }
Douglas Gregor05f477c2009-09-23 00:16:58 +0000372}
Douglas Gregor9eb77012009-11-07 00:00:49 +0000373
John McCall276321a2010-08-25 06:19:51 +0000374void CodeCompletionResult::computeCursorKindAndAvailability() {
Douglas Gregorb14904c2010-08-13 22:48:40 +0000375 switch (Kind) {
376 case RK_Declaration:
Douglas Gregorf757a122010-08-23 23:00:57 +0000377 // Set the availability based on attributes.
378 Availability = CXAvailability_Available;
379 if (Declaration->getAttr<UnavailableAttr>())
380 Availability = CXAvailability_NotAvailable;
381 else if (Declaration->getAttr<DeprecatedAttr>())
382 Availability = CXAvailability_Deprecated;
383
Douglas Gregor09c0eb12010-09-03 23:30:36 +0000384 if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Declaration))
385 if (Function->isDeleted())
Douglas Gregorf757a122010-08-23 23:00:57 +0000386 Availability = CXAvailability_NotAvailable;
Douglas Gregor09c0eb12010-09-03 23:30:36 +0000387
388 CursorKind = getCursorKindForDecl(Declaration);
389 if (CursorKind == CXCursor_UnexposedDecl)
Douglas Gregorb14904c2010-08-13 22:48:40 +0000390 CursorKind = CXCursor_NotImplemented;
Douglas Gregorb14904c2010-08-13 22:48:40 +0000391 break;
392
John McCall276321a2010-08-25 06:19:51 +0000393 case RK_Macro:
Douglas Gregorf757a122010-08-23 23:00:57 +0000394 Availability = CXAvailability_Available;
Douglas Gregorb14904c2010-08-13 22:48:40 +0000395 CursorKind = CXCursor_MacroDefinition;
396 break;
397
John McCall276321a2010-08-25 06:19:51 +0000398 case RK_Keyword:
Douglas Gregorf757a122010-08-23 23:00:57 +0000399 Availability = CXAvailability_Available;
Douglas Gregorb14904c2010-08-13 22:48:40 +0000400 CursorKind = CXCursor_NotImplemented;
401 break;
402
John McCall276321a2010-08-25 06:19:51 +0000403 case RK_Pattern:
Douglas Gregorb14904c2010-08-13 22:48:40 +0000404 // Do nothing: Patterns can come with cursor kinds!
405 break;
Douglas Gregor8e984da2010-08-04 16:47:14 +0000406 }
407}
Douglas Gregorf09935f2009-12-01 05:55:20 +0000408
Douglas Gregor0de55ce2010-08-25 18:41:16 +0000409/// \brief Retrieve the name that should be used to order a result.
410///
411/// If the name needs to be constructed as a string, that string will be
412/// saved into Saved and the returned StringRef will refer to it.
413static llvm::StringRef getOrderedName(const CodeCompletionResult &R,
414 std::string &Saved) {
415 switch (R.Kind) {
416 case CodeCompletionResult::RK_Keyword:
417 return R.Keyword;
418
419 case CodeCompletionResult::RK_Pattern:
420 return R.Pattern->getTypedText();
421
422 case CodeCompletionResult::RK_Macro:
423 return R.Macro->getName();
424
425 case CodeCompletionResult::RK_Declaration:
426 // Handle declarations below.
427 break;
428 }
429
430 DeclarationName Name = R.Declaration->getDeclName();
431
432 // If the name is a simple identifier (by far the common case), or a
433 // zero-argument selector, just return a reference to that identifier.
434 if (IdentifierInfo *Id = Name.getAsIdentifierInfo())
435 return Id->getName();
436 if (Name.isObjCZeroArgSelector())
437 if (IdentifierInfo *Id
438 = Name.getObjCSelector().getIdentifierInfoForSlot(0))
439 return Id->getName();
440
441 Saved = Name.getAsString();
442 return Saved;
443}
444
445bool clang::operator<(const CodeCompletionResult &X,
446 const CodeCompletionResult &Y) {
447 std::string XSaved, YSaved;
448 llvm::StringRef XStr = getOrderedName(X, XSaved);
449 llvm::StringRef YStr = getOrderedName(Y, YSaved);
450 int cmp = XStr.compare_lower(YStr);
451 if (cmp)
452 return cmp < 0;
453
Douglas Gregor49f67ce2010-08-26 13:48:20 +0000454 // If case-insensitive comparison fails, try case-sensitive comparison.
455 cmp = XStr.compare(YStr);
456 if (cmp)
457 return cmp < 0;
Douglas Gregor0de55ce2010-08-25 18:41:16 +0000458
459 return false;
460}