From 6a6840326e9b4ac8e81a5a212165f33743847ab8 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Mon, 28 Sep 2009 03:51:44 +0000 Subject: [PATCH] Determinism is for wimps. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82962 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaCodeComplete.cpp | 12 +++++++++++- test/CodeCompletion/member-access.cpp | 4 ++-- test/CodeCompletion/ordinary-name.c | 8 ++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 4c46696d1d..7a916ef036 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -14,6 +14,7 @@ #include "clang/Sema/CodeCompleteConsumer.h" #include "clang/AST/ExprCXX.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/StringExtras.h" #include #include #include @@ -948,6 +949,14 @@ namespace { struct SortCodeCompleteResult { typedef CodeCompleteConsumer::Result Result; + bool isEarlierDeclarationName(DeclarationName X, DeclarationName Y) const { + if (X.getNameKind() != Y.getNameKind()) + return X.getNameKind() < Y.getNameKind(); + + return llvm::LowercaseString(X.getAsString()) + < llvm::LowercaseString(Y.getAsString()); + } + bool operator()(const Result &X, const Result &Y) const { // Sort first by rank. if (X.Rank < Y.Rank) @@ -973,7 +982,8 @@ namespace { switch (X.Kind) { case Result::RK_Declaration: // Order based on the declaration names. - return X.Declaration->getDeclName() < Y.Declaration->getDeclName(); + return isEarlierDeclarationName(X.Declaration->getDeclName(), + Y.Declaration->getDeclName()); case Result::RK_Keyword: return strcmp(X.Keyword, Y.Keyword) == -1; diff --git a/test/CodeCompletion/member-access.cpp b/test/CodeCompletion/member-access.cpp index b0c1cf675b..b810366209 100644 --- a/test/CodeCompletion/member-access.cpp +++ b/test/CodeCompletion/member-access.cpp @@ -27,7 +27,7 @@ public: void test(const Proxy &p) { p-> - // RUN: clang-cc -fsyntax-only -code-completion-at=%s:29:6 %s -o - | FileCheck -check-prefix=CC1 %s && + // RUN: clang-cc -fsyntax-only -code-completion-at=%s:29:6 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s && // CHECK-CC1: member1 : 0 : [#Base1::#]member1 // CHECK-CC1: member1 : 0 : [#Base2::#]member1 // CHECK-CC1: member2 : 0 : [#Base1::#]member2 @@ -37,7 +37,7 @@ void test(const Proxy &p) { // CHECK-CC1: memfun1 : 0 : [#Base3::#]memfun1(<#double#>) // CHECK-CC1: memfun2 : 0 : [#Base3::#]memfun2(<#int#>) // CHECK-CC1: memfun3 : 0 : memfun3(<#int#>) - // CHECK-CC1-NEXT: Base1 : 0 : Base1:: + // CHECK-CC1: Base1 : 0 : Base1:: // CHECK-CC1: memfun1 : 0 (Hidden) : Base2::memfun1(<#int#>) // RUN: true diff --git a/test/CodeCompletion/ordinary-name.c b/test/CodeCompletion/ordinary-name.c index fb45477de1..586e2b371b 100644 --- a/test/CodeCompletion/ordinary-name.c +++ b/test/CodeCompletion/ordinary-name.c @@ -1,12 +1,12 @@ struct X { int x; }; -typedef struct X TYPEDEF; +typedef struct t TYPEDEF; void foo() { int y; - // RUN: clang-cc -fsyntax-only -code-completion-at=%s:6:9 %s -o - | FileCheck -check-prefix=CC1 %s && + // RUN: clang-cc -fsyntax-only -code-completion-at=%s:6:9 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s && // CHECK-CC1: y : 0 - // CHECK-CC1-NEXT: TYPEDEF : 2 - // CHECK-CC1-NOT: X // CHECK-CC1: foo : 2 + // CHECK-NOT-CC1: y : 2 + // CHECK-CC1-NEXT: TYPEDEF : 2 // RUN: true -- 2.40.0