diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-08-26 02:23:45 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-08-26 02:23:45 +0000 |
| commit | 78ecc499eb0ac8053cb200f6939640ff0d0e72a0 (patch) | |
| tree | c47a050a3ed25157a0f9e950ca61032d92c81126 /clang/tools/libclang | |
| parent | b45a1e735ae5d4438d10aea6ff1caee9f105b3b4 (diff) | |
| download | bcm5719-llvm-78ecc499eb0ac8053cb200f6939640ff0d0e72a0.tar.gz bcm5719-llvm-78ecc499eb0ac8053cb200f6939640ff0d0e72a0.zip | |
Move the sorting of code-completion results out of the main path and
into the clients, e.g., the printing code-completion consumer and
c-index-test. Clients may want to re-sort the results anyway.
Provide a libclang function that sorts the results.
llvm-svn: 112149
Diffstat (limited to 'clang/tools/libclang')
| -rw-r--r-- | clang/tools/libclang/CIndexCodeCompletion.cpp | 35 | ||||
| -rw-r--r-- | clang/tools/libclang/libclang.darwin.exports | 1 | ||||
| -rw-r--r-- | clang/tools/libclang/libclang.exports | 1 |
3 files changed, 37 insertions, 0 deletions
diff --git a/clang/tools/libclang/CIndexCodeCompletion.cpp b/clang/tools/libclang/CIndexCodeCompletion.cpp index 026d0be4ba4..825031bd4b4 100644 --- a/clang/tools/libclang/CIndexCodeCompletion.cpp +++ b/clang/tools/libclang/CIndexCodeCompletion.cpp @@ -582,6 +582,8 @@ namespace { AllocatedResults.Results[I].CompletionString = StoredCompletion; } } + + // FIXME: Add ProcessOverloadCandidates? }; } @@ -784,3 +786,36 @@ clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *ResultsIn, } // end extern "C" + +namespace { + struct OrderCompletionResults { + bool operator()(const CXCompletionResult &XR, + const CXCompletionResult &YR) const { + CXStoredCodeCompletionString *X + = (CXStoredCodeCompletionString *)XR.CompletionString; + CXStoredCodeCompletionString *Y + = (CXStoredCodeCompletionString *)YR.CompletionString; + + const char *XText = X->getTypedText(); + const char *YText = Y->getTypedText(); + if (!XText || !YText) + return XText != 0; + + int result = llvm::StringRef(XText).compare_lower(YText); + if (result < 0) + return true; + if (result > 0) + return false; + + result = llvm::StringRef(XText).compare(YText); + return result; + } + }; +} + +extern "C" { + void clang_sortCodeCompletionResults(CXCompletionResult *Results, + unsigned NumResults) { + std::stable_sort(Results, Results + NumResults, OrderCompletionResults()); + } +}
\ No newline at end of file diff --git a/clang/tools/libclang/libclang.darwin.exports b/clang/tools/libclang/libclang.darwin.exports index 6a369665017..d779190cc1b 100644 --- a/clang/tools/libclang/libclang.darwin.exports +++ b/clang/tools/libclang/libclang.darwin.exports @@ -99,5 +99,6 @@ _clang_parseTranslationUnit _clang_reparseTranslationUnit _clang_saveTranslationUnit _clang_setUseExternalASTGeneration +_clang_sortCodeCompletionResults _clang_tokenize _clang_visitChildren diff --git a/clang/tools/libclang/libclang.exports b/clang/tools/libclang/libclang.exports index 8f1d6269574..df93a799f7e 100644 --- a/clang/tools/libclang/libclang.exports +++ b/clang/tools/libclang/libclang.exports @@ -99,5 +99,6 @@ clang_parseTranslationUnit clang_reparseTranslationUnit clang_saveTranslationUnit clang_setUseExternalASTGeneration +clang_sortCodeCompletionResults clang_tokenize clang_visitChildren |

