Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 1 | //===- CIndexCodeCompletion.cpp - Code Completion API hooks ---------------===// |
| 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 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Clang-C Source Indexing library hooks for |
| 11 | // code completion. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "CIndexer.h" |
Ted Kremenek | 0a90d32 | 2010-11-17 23:24:11 +0000 | [diff] [blame] | 16 | #include "CXTranslationUnit.h" |
Ted Kremenek | ed12273 | 2010-11-16 01:56:27 +0000 | [diff] [blame] | 17 | #include "CXString.h" |
Douglas Gregor | e081a61 | 2011-07-21 01:05:26 +0000 | [diff] [blame] | 18 | #include "CXCursor.h" |
Ted Kremenek | baf82b0 | 2011-08-17 22:19:53 +0000 | [diff] [blame] | 19 | #include "CXString.h" |
Douglas Gregor | 936ea3b | 2010-01-28 00:56:43 +0000 | [diff] [blame] | 20 | #include "CIndexDiagnostic.h" |
Douglas Gregor | e081a61 | 2011-07-21 01:05:26 +0000 | [diff] [blame] | 21 | #include "clang/AST/Type.h" |
| 22 | #include "clang/AST/Decl.h" |
| 23 | #include "clang/AST/DeclObjC.h" |
Benjamin Kramer | b846deb | 2010-04-12 19:45:50 +0000 | [diff] [blame] | 24 | #include "clang/Basic/SourceManager.h" |
| 25 | #include "clang/Basic/FileManager.h" |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 26 | #include "clang/Frontend/ASTUnit.h" |
Benjamin Kramer | b846deb | 2010-04-12 19:45:50 +0000 | [diff] [blame] | 27 | #include "clang/Frontend/CompilerInstance.h" |
Douglas Gregor | 936ea3b | 2010-01-28 00:56:43 +0000 | [diff] [blame] | 28 | #include "clang/Frontend/FrontendDiagnostic.h" |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 29 | #include "clang/Sema/CodeCompleteConsumer.h" |
Douglas Gregor | df95a13 | 2010-08-09 20:45:32 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/SmallString.h" |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 1fd9e0d | 2010-12-07 00:05:48 +0000 | [diff] [blame] | 32 | #include "llvm/Support/Atomic.h" |
Daniel Dunbar | b1fd345 | 2010-08-19 23:44:10 +0000 | [diff] [blame] | 33 | #include "llvm/Support/CrashRecoveryContext.h" |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 34 | #include "llvm/Support/MemoryBuffer.h" |
Douglas Gregor | df95a13 | 2010-08-09 20:45:32 +0000 | [diff] [blame] | 35 | #include "llvm/Support/Timer.h" |
| 36 | #include "llvm/Support/raw_ostream.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 37 | #include "llvm/Support/Program.h" |
Douglas Gregor | 3d398aa | 2010-07-26 16:29:14 +0000 | [diff] [blame] | 38 | #include <cstdlib> |
| 39 | #include <cstdio> |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 40 | |
Douglas Gregor | df95a13 | 2010-08-09 20:45:32 +0000 | [diff] [blame] | 41 | |
Ted Kremenek | da7af32 | 2010-04-15 01:02:28 +0000 | [diff] [blame] | 42 | #ifdef UDP_CODE_COMPLETION_LOGGER |
| 43 | #include "clang/Basic/Version.h" |
Ted Kremenek | da7af32 | 2010-04-15 01:02:28 +0000 | [diff] [blame] | 44 | #include <arpa/inet.h> |
| 45 | #include <sys/socket.h> |
| 46 | #include <sys/types.h> |
| 47 | #include <unistd.h> |
| 48 | #endif |
| 49 | |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 50 | using namespace clang; |
Ted Kremenek | 2ef6f8f | 2010-02-17 01:42:24 +0000 | [diff] [blame] | 51 | using namespace clang::cxstring; |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 52 | |
| 53 | extern "C" { |
| 54 | |
| 55 | enum CXCompletionChunkKind |
| 56 | clang_getCompletionChunkKind(CXCompletionString completion_string, |
| 57 | unsigned chunk_number) { |
Douglas Gregor | 218937c | 2011-02-01 19:23:04 +0000 | [diff] [blame] | 58 | CodeCompletionString *CCStr = (CodeCompletionString *)completion_string; |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 59 | if (!CCStr || chunk_number >= CCStr->size()) |
| 60 | return CXCompletionChunk_Text; |
| 61 | |
| 62 | switch ((*CCStr)[chunk_number].Kind) { |
| 63 | case CodeCompletionString::CK_TypedText: |
| 64 | return CXCompletionChunk_TypedText; |
| 65 | case CodeCompletionString::CK_Text: |
| 66 | return CXCompletionChunk_Text; |
| 67 | case CodeCompletionString::CK_Optional: |
| 68 | return CXCompletionChunk_Optional; |
| 69 | case CodeCompletionString::CK_Placeholder: |
| 70 | return CXCompletionChunk_Placeholder; |
| 71 | case CodeCompletionString::CK_Informative: |
| 72 | return CXCompletionChunk_Informative; |
| 73 | case CodeCompletionString::CK_ResultType: |
| 74 | return CXCompletionChunk_ResultType; |
| 75 | case CodeCompletionString::CK_CurrentParameter: |
| 76 | return CXCompletionChunk_CurrentParameter; |
| 77 | case CodeCompletionString::CK_LeftParen: |
| 78 | return CXCompletionChunk_LeftParen; |
| 79 | case CodeCompletionString::CK_RightParen: |
| 80 | return CXCompletionChunk_RightParen; |
| 81 | case CodeCompletionString::CK_LeftBracket: |
| 82 | return CXCompletionChunk_LeftBracket; |
| 83 | case CodeCompletionString::CK_RightBracket: |
| 84 | return CXCompletionChunk_RightBracket; |
| 85 | case CodeCompletionString::CK_LeftBrace: |
| 86 | return CXCompletionChunk_LeftBrace; |
| 87 | case CodeCompletionString::CK_RightBrace: |
| 88 | return CXCompletionChunk_RightBrace; |
| 89 | case CodeCompletionString::CK_LeftAngle: |
| 90 | return CXCompletionChunk_LeftAngle; |
| 91 | case CodeCompletionString::CK_RightAngle: |
| 92 | return CXCompletionChunk_RightAngle; |
| 93 | case CodeCompletionString::CK_Comma: |
| 94 | return CXCompletionChunk_Comma; |
Douglas Gregor | 01dfea0 | 2010-01-10 23:08:15 +0000 | [diff] [blame] | 95 | case CodeCompletionString::CK_Colon: |
| 96 | return CXCompletionChunk_Colon; |
| 97 | case CodeCompletionString::CK_SemiColon: |
| 98 | return CXCompletionChunk_SemiColon; |
| 99 | case CodeCompletionString::CK_Equal: |
| 100 | return CXCompletionChunk_Equal; |
| 101 | case CodeCompletionString::CK_HorizontalSpace: |
| 102 | return CXCompletionChunk_HorizontalSpace; |
| 103 | case CodeCompletionString::CK_VerticalSpace: |
| 104 | return CXCompletionChunk_VerticalSpace; |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 105 | } |
| 106 | |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 107 | llvm_unreachable("Invalid CompletionKind!"); |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Ted Kremenek | 2ef6f8f | 2010-02-17 01:42:24 +0000 | [diff] [blame] | 110 | CXString clang_getCompletionChunkText(CXCompletionString completion_string, |
| 111 | unsigned chunk_number) { |
Douglas Gregor | 218937c | 2011-02-01 19:23:04 +0000 | [diff] [blame] | 112 | CodeCompletionString *CCStr = (CodeCompletionString *)completion_string; |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 113 | if (!CCStr || chunk_number >= CCStr->size()) |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 114 | return createCXString((const char*)0); |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 115 | |
| 116 | switch ((*CCStr)[chunk_number].Kind) { |
| 117 | case CodeCompletionString::CK_TypedText: |
| 118 | case CodeCompletionString::CK_Text: |
| 119 | case CodeCompletionString::CK_Placeholder: |
| 120 | case CodeCompletionString::CK_CurrentParameter: |
| 121 | case CodeCompletionString::CK_Informative: |
| 122 | case CodeCompletionString::CK_LeftParen: |
| 123 | case CodeCompletionString::CK_RightParen: |
| 124 | case CodeCompletionString::CK_LeftBracket: |
| 125 | case CodeCompletionString::CK_RightBracket: |
| 126 | case CodeCompletionString::CK_LeftBrace: |
| 127 | case CodeCompletionString::CK_RightBrace: |
| 128 | case CodeCompletionString::CK_LeftAngle: |
| 129 | case CodeCompletionString::CK_RightAngle: |
| 130 | case CodeCompletionString::CK_Comma: |
| 131 | case CodeCompletionString::CK_ResultType: |
Douglas Gregor | 01dfea0 | 2010-01-10 23:08:15 +0000 | [diff] [blame] | 132 | case CodeCompletionString::CK_Colon: |
| 133 | case CodeCompletionString::CK_SemiColon: |
| 134 | case CodeCompletionString::CK_Equal: |
| 135 | case CodeCompletionString::CK_HorizontalSpace: |
Douglas Gregor | 21c241f | 2010-05-25 06:14:46 +0000 | [diff] [blame] | 136 | case CodeCompletionString::CK_VerticalSpace: |
Douglas Gregor | 5a9c0bc | 2010-10-08 20:39:29 +0000 | [diff] [blame] | 137 | return createCXString((*CCStr)[chunk_number].Text, false); |
Douglas Gregor | 21c241f | 2010-05-25 06:14:46 +0000 | [diff] [blame] | 138 | |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 139 | case CodeCompletionString::CK_Optional: |
| 140 | // Note: treated as an empty text block. |
Ted Kremenek | 2ef6f8f | 2010-02-17 01:42:24 +0000 | [diff] [blame] | 141 | return createCXString(""); |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 142 | } |
| 143 | |
David Blaikie | 3026348 | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 144 | llvm_unreachable("Invalid CodeCompletionString Kind!"); |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Ted Kremenek | 2ef6f8f | 2010-02-17 01:42:24 +0000 | [diff] [blame] | 147 | |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 148 | CXCompletionString |
| 149 | clang_getCompletionChunkCompletionString(CXCompletionString completion_string, |
| 150 | unsigned chunk_number) { |
Douglas Gregor | 218937c | 2011-02-01 19:23:04 +0000 | [diff] [blame] | 151 | CodeCompletionString *CCStr = (CodeCompletionString *)completion_string; |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 152 | if (!CCStr || chunk_number >= CCStr->size()) |
| 153 | return 0; |
| 154 | |
| 155 | switch ((*CCStr)[chunk_number].Kind) { |
| 156 | case CodeCompletionString::CK_TypedText: |
| 157 | case CodeCompletionString::CK_Text: |
| 158 | case CodeCompletionString::CK_Placeholder: |
| 159 | case CodeCompletionString::CK_CurrentParameter: |
| 160 | case CodeCompletionString::CK_Informative: |
| 161 | case CodeCompletionString::CK_LeftParen: |
| 162 | case CodeCompletionString::CK_RightParen: |
| 163 | case CodeCompletionString::CK_LeftBracket: |
| 164 | case CodeCompletionString::CK_RightBracket: |
| 165 | case CodeCompletionString::CK_LeftBrace: |
| 166 | case CodeCompletionString::CK_RightBrace: |
| 167 | case CodeCompletionString::CK_LeftAngle: |
| 168 | case CodeCompletionString::CK_RightAngle: |
| 169 | case CodeCompletionString::CK_Comma: |
| 170 | case CodeCompletionString::CK_ResultType: |
Douglas Gregor | 01dfea0 | 2010-01-10 23:08:15 +0000 | [diff] [blame] | 171 | case CodeCompletionString::CK_Colon: |
| 172 | case CodeCompletionString::CK_SemiColon: |
| 173 | case CodeCompletionString::CK_Equal: |
| 174 | case CodeCompletionString::CK_HorizontalSpace: |
| 175 | case CodeCompletionString::CK_VerticalSpace: |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 176 | return 0; |
| 177 | |
| 178 | case CodeCompletionString::CK_Optional: |
| 179 | // Note: treated as an empty text block. |
| 180 | return (*CCStr)[chunk_number].Optional; |
| 181 | } |
| 182 | |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 183 | llvm_unreachable("Invalid CompletionKind!"); |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | unsigned clang_getNumCompletionChunks(CXCompletionString completion_string) { |
Douglas Gregor | 218937c | 2011-02-01 19:23:04 +0000 | [diff] [blame] | 187 | CodeCompletionString *CCStr = (CodeCompletionString *)completion_string; |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 188 | return CCStr? CCStr->size() : 0; |
| 189 | } |
| 190 | |
Douglas Gregor | 12e1313 | 2010-05-26 22:00:08 +0000 | [diff] [blame] | 191 | unsigned clang_getCompletionPriority(CXCompletionString completion_string) { |
Douglas Gregor | 218937c | 2011-02-01 19:23:04 +0000 | [diff] [blame] | 192 | CodeCompletionString *CCStr = (CodeCompletionString *)completion_string; |
Bill Wendling | a2ace58 | 2010-05-27 18:35:05 +0000 | [diff] [blame] | 193 | return CCStr? CCStr->getPriority() : unsigned(CCP_Unlikely); |
Douglas Gregor | 12e1313 | 2010-05-26 22:00:08 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Douglas Gregor | 58ddb60 | 2010-08-23 23:00:57 +0000 | [diff] [blame] | 196 | enum CXAvailabilityKind |
| 197 | clang_getCompletionAvailability(CXCompletionString completion_string) { |
Douglas Gregor | 218937c | 2011-02-01 19:23:04 +0000 | [diff] [blame] | 198 | CodeCompletionString *CCStr = (CodeCompletionString *)completion_string; |
| 199 | return CCStr? static_cast<CXAvailabilityKind>(CCStr->getAvailability()) |
| 200 | : CXAvailability_Available; |
Douglas Gregor | 58ddb60 | 2010-08-23 23:00:57 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Erik Verbruggen | 6164ea1 | 2011-10-14 15:31:08 +0000 | [diff] [blame] | 203 | unsigned clang_getCompletionNumAnnotations(CXCompletionString completion_string) |
| 204 | { |
| 205 | CodeCompletionString *CCStr = (CodeCompletionString *)completion_string; |
| 206 | return CCStr ? CCStr->getAnnotationCount() : 0; |
| 207 | } |
| 208 | |
| 209 | CXString clang_getCompletionAnnotation(CXCompletionString completion_string, |
| 210 | unsigned annotation_number) { |
| 211 | CodeCompletionString *CCStr = (CodeCompletionString *)completion_string; |
| 212 | return CCStr ? createCXString(CCStr->getAnnotation(annotation_number)) |
| 213 | : createCXString((const char *) 0); |
| 214 | } |
| 215 | |
Douglas Gregor | ba10306 | 2012-03-27 23:34:16 +0000 | [diff] [blame^] | 216 | CXString |
| 217 | clang_getCompletionParent(CXCompletionString completion_string, |
| 218 | CXCursorKind *kind) { |
| 219 | if (kind) |
| 220 | *kind = CXCursor_NotImplemented; |
| 221 | |
| 222 | CodeCompletionString *CCStr = (CodeCompletionString *)completion_string; |
| 223 | if (!CCStr) |
| 224 | return createCXString((const char *)0); |
| 225 | |
| 226 | if (kind) |
| 227 | *kind = CCStr->getParentContextKind(); |
| 228 | return createCXString(CCStr->getParentContextName(), /*DupString=*/false); |
| 229 | } |
| 230 | |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 231 | /// \brief The CXCodeCompleteResults structure we allocate internally; |
| 232 | /// the client only sees the initial CXCodeCompleteResults structure. |
| 233 | struct AllocatedCXCodeCompleteResults : public CXCodeCompleteResults { |
Anders Carlsson | 0d8d7e6 | 2011-03-18 18:22:40 +0000 | [diff] [blame] | 234 | AllocatedCXCodeCompleteResults(const FileSystemOptions& FileSystemOpts); |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 235 | ~AllocatedCXCodeCompleteResults(); |
| 236 | |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 237 | /// \brief Diagnostics produced while performing code completion. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 238 | SmallVector<StoredDiagnostic, 8> Diagnostics; |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 239 | |
Douglas Gregor | f715ca1 | 2010-03-16 00:06:06 +0000 | [diff] [blame] | 240 | /// \brief Diag object |
Dylan Noblesmith | c93dc78 | 2012-02-20 14:00:23 +0000 | [diff] [blame] | 241 | IntrusiveRefCntPtr<DiagnosticsEngine> Diag; |
Douglas Gregor | f715ca1 | 2010-03-16 00:06:06 +0000 | [diff] [blame] | 242 | |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 243 | /// \brief Language options used to adjust source locations. |
Daniel Dunbar | 35b8440 | 2010-01-30 23:31:40 +0000 | [diff] [blame] | 244 | LangOptions LangOpts; |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 245 | |
| 246 | FileSystemOptions FileSystemOpts; |
| 247 | |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 248 | /// \brief File manager, used for diagnostics. |
Dylan Noblesmith | c93dc78 | 2012-02-20 14:00:23 +0000 | [diff] [blame] | 249 | IntrusiveRefCntPtr<FileManager> FileMgr; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 250 | |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 251 | /// \brief Source manager, used for diagnostics. |
Dylan Noblesmith | c93dc78 | 2012-02-20 14:00:23 +0000 | [diff] [blame] | 252 | IntrusiveRefCntPtr<SourceManager> SourceMgr; |
Douglas Gregor | 313e26c | 2010-02-18 23:35:40 +0000 | [diff] [blame] | 253 | |
| 254 | /// \brief Temporary files that should be removed once we have finished |
| 255 | /// with the code-completion results. |
| 256 | std::vector<llvm::sys::Path> TemporaryFiles; |
Douglas Gregor | b75d3df | 2010-08-04 17:07:00 +0000 | [diff] [blame] | 257 | |
Chris Lattner | 7ad97ff | 2010-11-23 07:51:02 +0000 | [diff] [blame] | 258 | /// \brief Temporary buffers that will be deleted once we have finished with |
| 259 | /// the code-completion results. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 260 | SmallVector<const llvm::MemoryBuffer *, 1> TemporaryBuffers; |
Douglas Gregor | 218937c | 2011-02-01 19:23:04 +0000 | [diff] [blame] | 261 | |
Douglas Gregor | 48601b3 | 2011-02-16 19:08:06 +0000 | [diff] [blame] | 262 | /// \brief Allocator used to store globally cached code-completion results. |
Dylan Noblesmith | c93dc78 | 2012-02-20 14:00:23 +0000 | [diff] [blame] | 263 | IntrusiveRefCntPtr<clang::GlobalCodeCompletionAllocator> |
Douglas Gregor | 48601b3 | 2011-02-16 19:08:06 +0000 | [diff] [blame] | 264 | CachedCompletionAllocator; |
| 265 | |
Douglas Gregor | 218937c | 2011-02-01 19:23:04 +0000 | [diff] [blame] | 266 | /// \brief Allocator used to store code completion results. |
Douglas Gregor | 110a68e | 2011-02-01 23:14:23 +0000 | [diff] [blame] | 267 | clang::CodeCompletionAllocator CodeCompletionAllocator; |
Douglas Gregor | 3da626b | 2011-07-07 16:03:39 +0000 | [diff] [blame] | 268 | |
| 269 | /// \brief Context under which completion occurred. |
| 270 | enum clang::CodeCompletionContext::Kind ContextKind; |
| 271 | |
| 272 | /// \brief A bitfield representing the acceptable completions for the |
| 273 | /// current context. |
| 274 | unsigned long long Contexts; |
Douglas Gregor | e081a61 | 2011-07-21 01:05:26 +0000 | [diff] [blame] | 275 | |
Douglas Gregor | 0a47d69 | 2011-07-26 15:24:30 +0000 | [diff] [blame] | 276 | /// \brief The kind of the container for the current context for completions. |
Douglas Gregor | e081a61 | 2011-07-21 01:05:26 +0000 | [diff] [blame] | 277 | enum CXCursorKind ContainerKind; |
Douglas Gregor | 0a47d69 | 2011-07-26 15:24:30 +0000 | [diff] [blame] | 278 | /// \brief The USR of the container for the current context for completions. |
Douglas Gregor | e081a61 | 2011-07-21 01:05:26 +0000 | [diff] [blame] | 279 | CXString ContainerUSR; |
Douglas Gregor | 0a47d69 | 2011-07-26 15:24:30 +0000 | [diff] [blame] | 280 | /// \brief a boolean value indicating whether there is complete information |
| 281 | /// about the container |
Douglas Gregor | e081a61 | 2011-07-21 01:05:26 +0000 | [diff] [blame] | 282 | unsigned ContainerIsIncomplete; |
Douglas Gregor | 0a47d69 | 2011-07-26 15:24:30 +0000 | [diff] [blame] | 283 | |
| 284 | /// \brief A string containing the Objective-C selector entered thus far for a |
| 285 | /// message send. |
| 286 | std::string Selector; |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 287 | }; |
| 288 | |
Douglas Gregor | e3c60a7 | 2010-11-17 00:13:31 +0000 | [diff] [blame] | 289 | /// \brief Tracks the number of code-completion result objects that are |
| 290 | /// currently active. |
| 291 | /// |
| 292 | /// Used for debugging purposes only. |
Douglas Gregor | 1fd9e0d | 2010-12-07 00:05:48 +0000 | [diff] [blame] | 293 | static llvm::sys::cas_flag CodeCompletionResultObjects; |
Douglas Gregor | e3c60a7 | 2010-11-17 00:13:31 +0000 | [diff] [blame] | 294 | |
Anders Carlsson | 0d8d7e6 | 2011-03-18 18:22:40 +0000 | [diff] [blame] | 295 | AllocatedCXCodeCompleteResults::AllocatedCXCodeCompleteResults( |
| 296 | const FileSystemOptions& FileSystemOpts) |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 297 | : CXCodeCompleteResults(), |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 298 | Diag(new DiagnosticsEngine( |
Dylan Noblesmith | c93dc78 | 2012-02-20 14:00:23 +0000 | [diff] [blame] | 299 | IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs))), |
Anders Carlsson | 0d8d7e6 | 2011-03-18 18:22:40 +0000 | [diff] [blame] | 300 | FileSystemOpts(FileSystemOpts), |
Ted Kremenek | 4f32786 | 2011-03-21 18:40:17 +0000 | [diff] [blame] | 301 | FileMgr(new FileManager(FileSystemOpts)), |
Douglas Gregor | b77d197 | 2011-10-10 23:37:54 +0000 | [diff] [blame] | 302 | SourceMgr(new SourceManager(*Diag, *FileMgr)), |
| 303 | Contexts(CXCompletionContext_Unknown), |
| 304 | ContainerKind(CXCursor_InvalidCode), |
| 305 | ContainerUSR(createCXString("")), |
| 306 | ContainerIsIncomplete(1) |
| 307 | { |
Douglas Gregor | e3c60a7 | 2010-11-17 00:13:31 +0000 | [diff] [blame] | 308 | if (getenv("LIBCLANG_OBJTRACKING")) { |
Douglas Gregor | 1fd9e0d | 2010-12-07 00:05:48 +0000 | [diff] [blame] | 309 | llvm::sys::AtomicIncrement(&CodeCompletionResultObjects); |
Douglas Gregor | e3c60a7 | 2010-11-17 00:13:31 +0000 | [diff] [blame] | 310 | fprintf(stderr, "+++ %d completion results\n", CodeCompletionResultObjects); |
| 311 | } |
| 312 | } |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 313 | |
| 314 | AllocatedCXCodeCompleteResults::~AllocatedCXCodeCompleteResults() { |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 315 | delete [] Results; |
Douglas Gregor | 313e26c | 2010-02-18 23:35:40 +0000 | [diff] [blame] | 316 | |
Douglas Gregor | e081a61 | 2011-07-21 01:05:26 +0000 | [diff] [blame] | 317 | clang_disposeString(ContainerUSR); |
| 318 | |
Douglas Gregor | 313e26c | 2010-02-18 23:35:40 +0000 | [diff] [blame] | 319 | for (unsigned I = 0, N = TemporaryFiles.size(); I != N; ++I) |
| 320 | TemporaryFiles[I].eraseFromDisk(); |
Douglas Gregor | b75d3df | 2010-08-04 17:07:00 +0000 | [diff] [blame] | 321 | for (unsigned I = 0, N = TemporaryBuffers.size(); I != N; ++I) |
| 322 | delete TemporaryBuffers[I]; |
Douglas Gregor | e3c60a7 | 2010-11-17 00:13:31 +0000 | [diff] [blame] | 323 | |
| 324 | if (getenv("LIBCLANG_OBJTRACKING")) { |
Douglas Gregor | 1fd9e0d | 2010-12-07 00:05:48 +0000 | [diff] [blame] | 325 | llvm::sys::AtomicDecrement(&CodeCompletionResultObjects); |
Douglas Gregor | e3c60a7 | 2010-11-17 00:13:31 +0000 | [diff] [blame] | 326 | fprintf(stderr, "--- %d completion results\n", CodeCompletionResultObjects); |
| 327 | } |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 328 | } |
| 329 | |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 330 | } // end extern "C" |
| 331 | |
Douglas Gregor | 3da626b | 2011-07-07 16:03:39 +0000 | [diff] [blame] | 332 | static unsigned long long getContextsForContextKind( |
| 333 | enum CodeCompletionContext::Kind kind, |
| 334 | Sema &S) { |
| 335 | unsigned long long contexts = 0; |
| 336 | switch (kind) { |
| 337 | case CodeCompletionContext::CCC_OtherWithMacros: { |
| 338 | //We can allow macros here, but we don't know what else is permissible |
| 339 | //So we'll say the only thing permissible are macros |
| 340 | contexts = CXCompletionContext_MacroName; |
| 341 | break; |
| 342 | } |
| 343 | case CodeCompletionContext::CCC_TopLevel: |
| 344 | case CodeCompletionContext::CCC_ObjCIvarList: |
| 345 | case CodeCompletionContext::CCC_ClassStructUnion: |
| 346 | case CodeCompletionContext::CCC_Type: { |
| 347 | contexts = CXCompletionContext_AnyType | |
| 348 | CXCompletionContext_ObjCInterface; |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 349 | if (S.getLangOpts().CPlusPlus) { |
Douglas Gregor | 3da626b | 2011-07-07 16:03:39 +0000 | [diff] [blame] | 350 | contexts |= CXCompletionContext_EnumTag | |
| 351 | CXCompletionContext_UnionTag | |
| 352 | CXCompletionContext_StructTag | |
| 353 | CXCompletionContext_ClassTag | |
| 354 | CXCompletionContext_NestedNameSpecifier; |
| 355 | } |
| 356 | break; |
| 357 | } |
| 358 | case CodeCompletionContext::CCC_Statement: { |
| 359 | contexts = CXCompletionContext_AnyType | |
| 360 | CXCompletionContext_ObjCInterface | |
| 361 | CXCompletionContext_AnyValue; |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 362 | if (S.getLangOpts().CPlusPlus) { |
Douglas Gregor | 3da626b | 2011-07-07 16:03:39 +0000 | [diff] [blame] | 363 | contexts |= CXCompletionContext_EnumTag | |
| 364 | CXCompletionContext_UnionTag | |
| 365 | CXCompletionContext_StructTag | |
| 366 | CXCompletionContext_ClassTag | |
| 367 | CXCompletionContext_NestedNameSpecifier; |
| 368 | } |
| 369 | break; |
| 370 | } |
| 371 | case CodeCompletionContext::CCC_Expression: { |
| 372 | contexts = CXCompletionContext_AnyValue; |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 373 | if (S.getLangOpts().CPlusPlus) { |
Douglas Gregor | 3da626b | 2011-07-07 16:03:39 +0000 | [diff] [blame] | 374 | contexts |= CXCompletionContext_AnyType | |
| 375 | CXCompletionContext_ObjCInterface | |
| 376 | CXCompletionContext_EnumTag | |
| 377 | CXCompletionContext_UnionTag | |
| 378 | CXCompletionContext_StructTag | |
| 379 | CXCompletionContext_ClassTag | |
| 380 | CXCompletionContext_NestedNameSpecifier; |
| 381 | } |
| 382 | break; |
| 383 | } |
| 384 | case CodeCompletionContext::CCC_ObjCMessageReceiver: { |
| 385 | contexts = CXCompletionContext_ObjCObjectValue | |
| 386 | CXCompletionContext_ObjCSelectorValue | |
| 387 | CXCompletionContext_ObjCInterface; |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 388 | if (S.getLangOpts().CPlusPlus) { |
Douglas Gregor | 3da626b | 2011-07-07 16:03:39 +0000 | [diff] [blame] | 389 | contexts |= CXCompletionContext_CXXClassTypeValue | |
| 390 | CXCompletionContext_AnyType | |
| 391 | CXCompletionContext_EnumTag | |
| 392 | CXCompletionContext_UnionTag | |
| 393 | CXCompletionContext_StructTag | |
| 394 | CXCompletionContext_ClassTag | |
| 395 | CXCompletionContext_NestedNameSpecifier; |
| 396 | } |
| 397 | break; |
| 398 | } |
| 399 | case CodeCompletionContext::CCC_DotMemberAccess: { |
| 400 | contexts = CXCompletionContext_DotMemberAccess; |
| 401 | break; |
| 402 | } |
| 403 | case CodeCompletionContext::CCC_ArrowMemberAccess: { |
| 404 | contexts = CXCompletionContext_ArrowMemberAccess; |
| 405 | break; |
| 406 | } |
| 407 | case CodeCompletionContext::CCC_ObjCPropertyAccess: { |
| 408 | contexts = CXCompletionContext_ObjCPropertyAccess; |
| 409 | break; |
| 410 | } |
| 411 | case CodeCompletionContext::CCC_EnumTag: { |
| 412 | contexts = CXCompletionContext_EnumTag | |
| 413 | CXCompletionContext_NestedNameSpecifier; |
| 414 | break; |
| 415 | } |
| 416 | case CodeCompletionContext::CCC_UnionTag: { |
| 417 | contexts = CXCompletionContext_UnionTag | |
| 418 | CXCompletionContext_NestedNameSpecifier; |
| 419 | break; |
| 420 | } |
| 421 | case CodeCompletionContext::CCC_ClassOrStructTag: { |
| 422 | contexts = CXCompletionContext_StructTag | |
| 423 | CXCompletionContext_ClassTag | |
| 424 | CXCompletionContext_NestedNameSpecifier; |
| 425 | break; |
| 426 | } |
| 427 | case CodeCompletionContext::CCC_ObjCProtocolName: { |
| 428 | contexts = CXCompletionContext_ObjCProtocol; |
| 429 | break; |
| 430 | } |
| 431 | case CodeCompletionContext::CCC_Namespace: { |
| 432 | contexts = CXCompletionContext_Namespace; |
| 433 | break; |
| 434 | } |
| 435 | case CodeCompletionContext::CCC_PotentiallyQualifiedName: { |
| 436 | contexts = CXCompletionContext_NestedNameSpecifier; |
| 437 | break; |
| 438 | } |
| 439 | case CodeCompletionContext::CCC_MacroNameUse: { |
| 440 | contexts = CXCompletionContext_MacroName; |
| 441 | break; |
| 442 | } |
| 443 | case CodeCompletionContext::CCC_NaturalLanguage: { |
| 444 | contexts = CXCompletionContext_NaturalLanguage; |
| 445 | break; |
| 446 | } |
| 447 | case CodeCompletionContext::CCC_SelectorName: { |
| 448 | contexts = CXCompletionContext_ObjCSelectorName; |
| 449 | break; |
| 450 | } |
| 451 | case CodeCompletionContext::CCC_ParenthesizedExpression: { |
| 452 | contexts = CXCompletionContext_AnyType | |
| 453 | CXCompletionContext_ObjCInterface | |
| 454 | CXCompletionContext_AnyValue; |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 455 | if (S.getLangOpts().CPlusPlus) { |
Douglas Gregor | 3da626b | 2011-07-07 16:03:39 +0000 | [diff] [blame] | 456 | contexts |= CXCompletionContext_EnumTag | |
| 457 | CXCompletionContext_UnionTag | |
| 458 | CXCompletionContext_StructTag | |
| 459 | CXCompletionContext_ClassTag | |
| 460 | CXCompletionContext_NestedNameSpecifier; |
| 461 | } |
| 462 | break; |
| 463 | } |
| 464 | case CodeCompletionContext::CCC_ObjCInstanceMessage: { |
| 465 | contexts = CXCompletionContext_ObjCInstanceMessage; |
| 466 | break; |
| 467 | } |
| 468 | case CodeCompletionContext::CCC_ObjCClassMessage: { |
| 469 | contexts = CXCompletionContext_ObjCClassMessage; |
| 470 | break; |
| 471 | } |
Douglas Gregor | 0f91c8c | 2011-07-30 06:55:39 +0000 | [diff] [blame] | 472 | case CodeCompletionContext::CCC_ObjCInterfaceName: { |
Douglas Gregor | 3da626b | 2011-07-07 16:03:39 +0000 | [diff] [blame] | 473 | contexts = CXCompletionContext_ObjCInterface; |
| 474 | break; |
| 475 | } |
| 476 | case CodeCompletionContext::CCC_ObjCCategoryName: { |
| 477 | contexts = CXCompletionContext_ObjCCategory; |
| 478 | break; |
| 479 | } |
| 480 | case CodeCompletionContext::CCC_Other: |
| 481 | case CodeCompletionContext::CCC_ObjCInterface: |
| 482 | case CodeCompletionContext::CCC_ObjCImplementation: |
| 483 | case CodeCompletionContext::CCC_Name: |
| 484 | case CodeCompletionContext::CCC_MacroName: |
| 485 | case CodeCompletionContext::CCC_PreprocessorExpression: |
| 486 | case CodeCompletionContext::CCC_PreprocessorDirective: |
| 487 | case CodeCompletionContext::CCC_TypeQualifiers: { |
| 488 | //Only Clang results should be accepted, so we'll set all of the other |
| 489 | //context bits to 0 (i.e. the empty set) |
| 490 | contexts = CXCompletionContext_Unexposed; |
| 491 | break; |
| 492 | } |
| 493 | case CodeCompletionContext::CCC_Recovery: { |
| 494 | //We don't know what the current context is, so we'll return unknown |
| 495 | //This is the equivalent of setting all of the other context bits |
| 496 | contexts = CXCompletionContext_Unknown; |
| 497 | break; |
| 498 | } |
| 499 | } |
| 500 | return contexts; |
| 501 | } |
| 502 | |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 503 | namespace { |
| 504 | class CaptureCompletionResults : public CodeCompleteConsumer { |
| 505 | AllocatedCXCodeCompleteResults &AllocatedResults; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 506 | SmallVector<CXCompletionResult, 16> StoredResults; |
Douglas Gregor | e081a61 | 2011-07-21 01:05:26 +0000 | [diff] [blame] | 507 | CXTranslationUnit *TU; |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 508 | public: |
Douglas Gregor | e081a61 | 2011-07-21 01:05:26 +0000 | [diff] [blame] | 509 | CaptureCompletionResults(AllocatedCXCodeCompleteResults &Results, |
| 510 | CXTranslationUnit *TranslationUnit) |
Douglas Gregor | 8071e42 | 2010-08-15 06:18:01 +0000 | [diff] [blame] | 511 | : CodeCompleteConsumer(true, false, true, false), |
Douglas Gregor | e081a61 | 2011-07-21 01:05:26 +0000 | [diff] [blame] | 512 | AllocatedResults(Results), TU(TranslationUnit) { } |
Douglas Gregor | 32be4a5 | 2010-10-11 21:37:58 +0000 | [diff] [blame] | 513 | ~CaptureCompletionResults() { Finish(); } |
| 514 | |
Douglas Gregor | e6b1bb6 | 2010-08-11 21:23:17 +0000 | [diff] [blame] | 515 | virtual void ProcessCodeCompleteResults(Sema &S, |
| 516 | CodeCompletionContext Context, |
John McCall | 0a2c5e2 | 2010-08-25 06:19:51 +0000 | [diff] [blame] | 517 | CodeCompletionResult *Results, |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 518 | unsigned NumResults) { |
Douglas Gregor | 32be4a5 | 2010-10-11 21:37:58 +0000 | [diff] [blame] | 519 | StoredResults.reserve(StoredResults.size() + NumResults); |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 520 | for (unsigned I = 0; I != NumResults; ++I) { |
Douglas Gregor | 218937c | 2011-02-01 19:23:04 +0000 | [diff] [blame] | 521 | CodeCompletionString *StoredCompletion |
| 522 | = Results[I].CreateCodeCompletionString(S, |
| 523 | AllocatedResults.CodeCompletionAllocator); |
Douglas Gregor | 32be4a5 | 2010-10-11 21:37:58 +0000 | [diff] [blame] | 524 | |
| 525 | CXCompletionResult R; |
| 526 | R.CursorKind = Results[I].CursorKind; |
| 527 | R.CompletionString = StoredCompletion; |
| 528 | StoredResults.push_back(R); |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 529 | } |
Douglas Gregor | 3da626b | 2011-07-07 16:03:39 +0000 | [diff] [blame] | 530 | |
Douglas Gregor | e081a61 | 2011-07-21 01:05:26 +0000 | [diff] [blame] | 531 | enum CodeCompletionContext::Kind contextKind = Context.getKind(); |
Douglas Gregor | 3da626b | 2011-07-07 16:03:39 +0000 | [diff] [blame] | 532 | |
Douglas Gregor | e081a61 | 2011-07-21 01:05:26 +0000 | [diff] [blame] | 533 | AllocatedResults.ContextKind = contextKind; |
| 534 | AllocatedResults.Contexts = getContextsForContextKind(contextKind, S); |
| 535 | |
Douglas Gregor | 0a47d69 | 2011-07-26 15:24:30 +0000 | [diff] [blame] | 536 | AllocatedResults.Selector = ""; |
| 537 | if (Context.getNumSelIdents() > 0) { |
| 538 | for (unsigned i = 0; i < Context.getNumSelIdents(); i++) { |
| 539 | IdentifierInfo *selIdent = Context.getSelIdents()[i]; |
| 540 | if (selIdent != NULL) { |
| 541 | StringRef selectorString = Context.getSelIdents()[i]->getName(); |
Benjamin Kramer | a0651c5 | 2011-07-26 16:59:25 +0000 | [diff] [blame] | 542 | AllocatedResults.Selector += selectorString; |
Douglas Gregor | 0a47d69 | 2011-07-26 15:24:30 +0000 | [diff] [blame] | 543 | } |
| 544 | AllocatedResults.Selector += ":"; |
| 545 | } |
| 546 | } |
| 547 | |
Douglas Gregor | e081a61 | 2011-07-21 01:05:26 +0000 | [diff] [blame] | 548 | QualType baseType = Context.getBaseType(); |
| 549 | NamedDecl *D = NULL; |
| 550 | |
| 551 | if (!baseType.isNull()) { |
| 552 | // Get the declaration for a class/struct/union/enum type |
| 553 | if (const TagType *Tag = baseType->getAs<TagType>()) |
| 554 | D = Tag->getDecl(); |
| 555 | // Get the @interface declaration for a (possibly-qualified) Objective-C |
| 556 | // object pointer type, e.g., NSString* |
| 557 | else if (const ObjCObjectPointerType *ObjPtr = |
| 558 | baseType->getAs<ObjCObjectPointerType>()) |
| 559 | D = ObjPtr->getInterfaceDecl(); |
| 560 | // Get the @interface declaration for an Objective-C object type |
| 561 | else if (const ObjCObjectType *Obj = baseType->getAs<ObjCObjectType>()) |
| 562 | D = Obj->getInterface(); |
| 563 | // Get the class for a C++ injected-class-name |
| 564 | else if (const InjectedClassNameType *Injected = |
| 565 | baseType->getAs<InjectedClassNameType>()) |
| 566 | D = Injected->getDecl(); |
| 567 | } |
| 568 | |
| 569 | if (D != NULL) { |
| 570 | CXCursor cursor = cxcursor::MakeCXCursor(D, *TU); |
| 571 | |
| 572 | CXCursorKind cursorKind = clang_getCursorKind(cursor); |
| 573 | CXString cursorUSR = clang_getCursorUSR(cursor); |
| 574 | |
Ted Kremenek | baf82b0 | 2011-08-17 22:19:53 +0000 | [diff] [blame] | 575 | // Normally, clients of CXString shouldn't care whether or not |
| 576 | // a CXString is managed by a pool or by explicitly malloc'ed memory. |
| 577 | // However, there are cases when AllocatedResults outlives the |
| 578 | // CXTranslationUnit. This is a workaround that failure mode. |
| 579 | if (cxstring::isManagedByPool(cursorUSR)) { |
| 580 | CXString heapStr = |
| 581 | cxstring::createCXString(clang_getCString(cursorUSR), true); |
| 582 | clang_disposeString(cursorUSR); |
| 583 | cursorUSR = heapStr; |
| 584 | } |
| 585 | |
Douglas Gregor | e081a61 | 2011-07-21 01:05:26 +0000 | [diff] [blame] | 586 | AllocatedResults.ContainerKind = cursorKind; |
| 587 | AllocatedResults.ContainerUSR = cursorUSR; |
Ted Kremenek | baf82b0 | 2011-08-17 22:19:53 +0000 | [diff] [blame] | 588 | |
Douglas Gregor | e081a61 | 2011-07-21 01:05:26 +0000 | [diff] [blame] | 589 | const Type *type = baseType.getTypePtrOrNull(); |
| 590 | if (type != NULL) { |
| 591 | AllocatedResults.ContainerIsIncomplete = type->isIncompleteType(); |
| 592 | } |
| 593 | else { |
| 594 | AllocatedResults.ContainerIsIncomplete = 1; |
| 595 | } |
| 596 | } |
| 597 | else { |
| 598 | AllocatedResults.ContainerKind = CXCursor_InvalidCode; |
| 599 | AllocatedResults.ContainerUSR = createCXString(""); |
| 600 | AllocatedResults.ContainerIsIncomplete = 1; |
| 601 | } |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 602 | } |
Douglas Gregor | 1e5e668 | 2010-08-26 13:48:20 +0000 | [diff] [blame] | 603 | |
Douglas Gregor | 32be4a5 | 2010-10-11 21:37:58 +0000 | [diff] [blame] | 604 | virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, |
| 605 | OverloadCandidate *Candidates, |
| 606 | unsigned NumCandidates) { |
| 607 | StoredResults.reserve(StoredResults.size() + NumCandidates); |
| 608 | for (unsigned I = 0; I != NumCandidates; ++I) { |
Douglas Gregor | 218937c | 2011-02-01 19:23:04 +0000 | [diff] [blame] | 609 | CodeCompletionString *StoredCompletion |
| 610 | = Candidates[I].CreateSignatureString(CurrentArg, S, |
| 611 | AllocatedResults.CodeCompletionAllocator); |
Douglas Gregor | 32be4a5 | 2010-10-11 21:37:58 +0000 | [diff] [blame] | 612 | |
| 613 | CXCompletionResult R; |
| 614 | R.CursorKind = CXCursor_NotImplemented; |
| 615 | R.CompletionString = StoredCompletion; |
| 616 | StoredResults.push_back(R); |
| 617 | } |
| 618 | } |
| 619 | |
Douglas Gregor | dae6875 | 2011-02-01 22:57:45 +0000 | [diff] [blame] | 620 | virtual CodeCompletionAllocator &getAllocator() { |
Douglas Gregor | 218937c | 2011-02-01 19:23:04 +0000 | [diff] [blame] | 621 | return AllocatedResults.CodeCompletionAllocator; |
| 622 | } |
| 623 | |
Douglas Gregor | 32be4a5 | 2010-10-11 21:37:58 +0000 | [diff] [blame] | 624 | private: |
| 625 | void Finish() { |
| 626 | AllocatedResults.Results = new CXCompletionResult [StoredResults.size()]; |
| 627 | AllocatedResults.NumResults = StoredResults.size(); |
| 628 | std::memcpy(AllocatedResults.Results, StoredResults.data(), |
| 629 | StoredResults.size() * sizeof(CXCompletionResult)); |
| 630 | StoredResults.clear(); |
| 631 | } |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 632 | }; |
| 633 | } |
| 634 | |
| 635 | extern "C" { |
Daniel Dunbar | b1fd345 | 2010-08-19 23:44:10 +0000 | [diff] [blame] | 636 | struct CodeCompleteAtInfo { |
| 637 | CXTranslationUnit TU; |
| 638 | const char *complete_filename; |
| 639 | unsigned complete_line; |
| 640 | unsigned complete_column; |
| 641 | struct CXUnsavedFile *unsaved_files; |
| 642 | unsigned num_unsaved_files; |
| 643 | unsigned options; |
| 644 | CXCodeCompleteResults *result; |
| 645 | }; |
| 646 | void clang_codeCompleteAt_Impl(void *UserData) { |
| 647 | CodeCompleteAtInfo *CCAI = static_cast<CodeCompleteAtInfo*>(UserData); |
| 648 | CXTranslationUnit TU = CCAI->TU; |
| 649 | const char *complete_filename = CCAI->complete_filename; |
| 650 | unsigned complete_line = CCAI->complete_line; |
| 651 | unsigned complete_column = CCAI->complete_column; |
| 652 | struct CXUnsavedFile *unsaved_files = CCAI->unsaved_files; |
| 653 | unsigned num_unsaved_files = CCAI->num_unsaved_files; |
| 654 | unsigned options = CCAI->options; |
| 655 | CCAI->result = 0; |
| 656 | |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 657 | #ifdef UDP_CODE_COMPLETION_LOGGER |
| 658 | #ifdef UDP_CODE_COMPLETION_LOGGER_PORT |
| 659 | const llvm::TimeRecord &StartTime = llvm::TimeRecord::getCurrentTime(); |
| 660 | #endif |
| 661 | #endif |
| 662 | |
| 663 | bool EnableLogging = getenv("LIBCLANG_CODE_COMPLETION_LOGGING") != 0; |
| 664 | |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 665 | ASTUnit *AST = static_cast<ASTUnit *>(TU->TUData); |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 666 | if (!AST) |
Daniel Dunbar | b1fd345 | 2010-08-19 23:44:10 +0000 | [diff] [blame] | 667 | return; |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 668 | |
Douglas Gregor | 593b0c1 | 2010-09-23 18:47:53 +0000 | [diff] [blame] | 669 | ASTUnit::ConcurrencyCheck Check(*AST); |
| 670 | |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 671 | // Perform the remapping of source files. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 672 | SmallVector<ASTUnit::RemappedFile, 4> RemappedFiles; |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 673 | for (unsigned I = 0; I != num_unsaved_files; ++I) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 674 | StringRef Data(unsaved_files[I].Contents, unsaved_files[I].Length); |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 675 | const llvm::MemoryBuffer *Buffer |
| 676 | = llvm::MemoryBuffer::getMemBufferCopy(Data, unsaved_files[I].Filename); |
| 677 | RemappedFiles.push_back(std::make_pair(unsaved_files[I].Filename, |
| 678 | Buffer)); |
| 679 | } |
| 680 | |
| 681 | if (EnableLogging) { |
| 682 | // FIXME: Add logging. |
| 683 | } |
| 684 | |
| 685 | // Parse the resulting source file to find code-completion results. |
Anders Carlsson | 0d8d7e6 | 2011-03-18 18:22:40 +0000 | [diff] [blame] | 686 | AllocatedCXCodeCompleteResults *Results = |
| 687 | new AllocatedCXCodeCompleteResults(AST->getFileSystemOpts()); |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 688 | Results->Results = 0; |
| 689 | Results->NumResults = 0; |
Douglas Gregor | 48601b3 | 2011-02-16 19:08:06 +0000 | [diff] [blame] | 690 | |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 691 | // Create a code-completion consumer to capture the results. |
Douglas Gregor | e081a61 | 2011-07-21 01:05:26 +0000 | [diff] [blame] | 692 | CaptureCompletionResults Capture(*Results, &TU); |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 693 | |
| 694 | // Perform completion. |
| 695 | AST->CodeComplete(complete_filename, complete_line, complete_column, |
Douglas Gregor | cee235c | 2010-08-05 09:09:23 +0000 | [diff] [blame] | 696 | RemappedFiles.data(), RemappedFiles.size(), |
| 697 | (options & CXCodeComplete_IncludeMacros), |
| 698 | (options & CXCodeComplete_IncludeCodePatterns), |
| 699 | Capture, |
Ted Kremenek | 4f32786 | 2011-03-21 18:40:17 +0000 | [diff] [blame] | 700 | *Results->Diag, Results->LangOpts, *Results->SourceMgr, |
| 701 | *Results->FileMgr, Results->Diagnostics, |
Douglas Gregor | 2283d79 | 2010-08-20 00:59:43 +0000 | [diff] [blame] | 702 | Results->TemporaryBuffers); |
Douglas Gregor | 48601b3 | 2011-02-16 19:08:06 +0000 | [diff] [blame] | 703 | |
| 704 | // Keep a reference to the allocator used for cached global completions, so |
| 705 | // that we can be sure that the memory used by our code completion strings |
| 706 | // doesn't get freed due to subsequent reparses (while the code completion |
| 707 | // results are still active). |
| 708 | Results->CachedCompletionAllocator = AST->getCachedCompletionAllocator(); |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 709 | |
| 710 | |
| 711 | |
| 712 | #ifdef UDP_CODE_COMPLETION_LOGGER |
| 713 | #ifdef UDP_CODE_COMPLETION_LOGGER_PORT |
| 714 | const llvm::TimeRecord &EndTime = llvm::TimeRecord::getCurrentTime(); |
Dylan Noblesmith | 36d5927 | 2012-02-13 12:32:26 +0000 | [diff] [blame] | 715 | SmallString<256> LogResult; |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 716 | llvm::raw_svector_ostream os(LogResult); |
| 717 | |
| 718 | // Figure out the language and whether or not it uses PCH. |
| 719 | const char *lang = 0; |
| 720 | bool usesPCH = false; |
| 721 | |
| 722 | for (std::vector<const char*>::iterator I = argv.begin(), E = argv.end(); |
| 723 | I != E; ++I) { |
| 724 | if (*I == 0) |
| 725 | continue; |
| 726 | if (strcmp(*I, "-x") == 0) { |
| 727 | if (I + 1 != E) { |
| 728 | lang = *(++I); |
| 729 | continue; |
| 730 | } |
| 731 | } |
| 732 | else if (strcmp(*I, "-include") == 0) { |
| 733 | if (I+1 != E) { |
| 734 | const char *arg = *(++I); |
Dylan Noblesmith | 36d5927 | 2012-02-13 12:32:26 +0000 | [diff] [blame] | 735 | SmallString<512> pchName; |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 736 | { |
| 737 | llvm::raw_svector_ostream os(pchName); |
| 738 | os << arg << ".pth"; |
| 739 | } |
| 740 | pchName.push_back('\0'); |
| 741 | struct stat stat_results; |
Douglas Gregor | 0a47d69 | 2011-07-26 15:24:30 +0000 | [diff] [blame] | 742 | if (stat(pchName.str().c_str(), &stat_results) == 0) |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 743 | usesPCH = true; |
| 744 | continue; |
| 745 | } |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | os << "{ "; |
| 750 | os << "\"wall\": " << (EndTime.getWallTime() - StartTime.getWallTime()); |
| 751 | os << ", \"numRes\": " << Results->NumResults; |
| 752 | os << ", \"diags\": " << Results->Diagnostics.size(); |
| 753 | os << ", \"pch\": " << (usesPCH ? "true" : "false"); |
| 754 | os << ", \"lang\": \"" << (lang ? lang : "<unknown>") << '"'; |
| 755 | const char *name = getlogin(); |
| 756 | os << ", \"user\": \"" << (name ? name : "unknown") << '"'; |
| 757 | os << ", \"clangVer\": \"" << getClangFullVersion() << '"'; |
| 758 | os << " }"; |
| 759 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 760 | StringRef res = os.str(); |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 761 | if (res.size() > 0) { |
| 762 | do { |
| 763 | // Setup the UDP socket. |
| 764 | struct sockaddr_in servaddr; |
| 765 | bzero(&servaddr, sizeof(servaddr)); |
| 766 | servaddr.sin_family = AF_INET; |
| 767 | servaddr.sin_port = htons(UDP_CODE_COMPLETION_LOGGER_PORT); |
| 768 | if (inet_pton(AF_INET, UDP_CODE_COMPLETION_LOGGER, |
| 769 | &servaddr.sin_addr) <= 0) |
| 770 | break; |
| 771 | |
| 772 | int sockfd = socket(AF_INET, SOCK_DGRAM, 0); |
| 773 | if (sockfd < 0) |
| 774 | break; |
| 775 | |
| 776 | sendto(sockfd, res.data(), res.size(), 0, |
| 777 | (struct sockaddr *)&servaddr, sizeof(servaddr)); |
| 778 | close(sockfd); |
| 779 | } |
| 780 | while (false); |
| 781 | } |
| 782 | #endif |
| 783 | #endif |
Daniel Dunbar | b1fd345 | 2010-08-19 23:44:10 +0000 | [diff] [blame] | 784 | CCAI->result = Results; |
| 785 | } |
| 786 | CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU, |
| 787 | const char *complete_filename, |
| 788 | unsigned complete_line, |
| 789 | unsigned complete_column, |
| 790 | struct CXUnsavedFile *unsaved_files, |
| 791 | unsigned num_unsaved_files, |
| 792 | unsigned options) { |
| 793 | CodeCompleteAtInfo CCAI = { TU, complete_filename, complete_line, |
| 794 | complete_column, unsaved_files, num_unsaved_files, |
| 795 | options, 0 }; |
| 796 | llvm::CrashRecoveryContext CRC; |
| 797 | |
Daniel Dunbar | bf44c3b | 2010-11-05 07:19:31 +0000 | [diff] [blame] | 798 | if (!RunSafely(CRC, clang_codeCompleteAt_Impl, &CCAI)) { |
Daniel Dunbar | b1fd345 | 2010-08-19 23:44:10 +0000 | [diff] [blame] | 799 | fprintf(stderr, "libclang: crash detected in code completion\n"); |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 800 | static_cast<ASTUnit *>(TU->TUData)->setUnsafeToFree(true); |
Daniel Dunbar | b1fd345 | 2010-08-19 23:44:10 +0000 | [diff] [blame] | 801 | return 0; |
Douglas Gregor | 6df7873 | 2011-05-05 20:27:22 +0000 | [diff] [blame] | 802 | } else if (getenv("LIBCLANG_RESOURCE_USAGE")) |
| 803 | PrintLibclangResourceUsage(TU); |
Daniel Dunbar | b1fd345 | 2010-08-19 23:44:10 +0000 | [diff] [blame] | 804 | |
| 805 | return CCAI.result; |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 806 | } |
| 807 | |
Douglas Gregor | cee235c | 2010-08-05 09:09:23 +0000 | [diff] [blame] | 808 | unsigned clang_defaultCodeCompleteOptions(void) { |
| 809 | return CXCodeComplete_IncludeMacros; |
| 810 | } |
| 811 | |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 812 | void clang_disposeCodeCompleteResults(CXCodeCompleteResults *ResultsIn) { |
| 813 | if (!ResultsIn) |
| 814 | return; |
| 815 | |
| 816 | AllocatedCXCodeCompleteResults *Results |
| 817 | = static_cast<AllocatedCXCodeCompleteResults*>(ResultsIn); |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 818 | delete Results; |
| 819 | } |
Douglas Gregor | 58ddb60 | 2010-08-23 23:00:57 +0000 | [diff] [blame] | 820 | |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 821 | unsigned |
| 822 | clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *ResultsIn) { |
| 823 | AllocatedCXCodeCompleteResults *Results |
| 824 | = static_cast<AllocatedCXCodeCompleteResults*>(ResultsIn); |
| 825 | if (!Results) |
| 826 | return 0; |
| 827 | |
| 828 | return Results->Diagnostics.size(); |
| 829 | } |
| 830 | |
| 831 | CXDiagnostic |
| 832 | clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *ResultsIn, |
| 833 | unsigned Index) { |
| 834 | AllocatedCXCodeCompleteResults *Results |
| 835 | = static_cast<AllocatedCXCodeCompleteResults*>(ResultsIn); |
| 836 | if (!Results || Index >= Results->Diagnostics.size()) |
| 837 | return 0; |
| 838 | |
| 839 | return new CXStoredDiagnostic(Results->Diagnostics[Index], Results->LangOpts); |
| 840 | } |
| 841 | |
Douglas Gregor | 3da626b | 2011-07-07 16:03:39 +0000 | [diff] [blame] | 842 | unsigned long long |
| 843 | clang_codeCompleteGetContexts(CXCodeCompleteResults *ResultsIn) { |
| 844 | AllocatedCXCodeCompleteResults *Results |
| 845 | = static_cast<AllocatedCXCodeCompleteResults*>(ResultsIn); |
| 846 | if (!Results) |
| 847 | return 0; |
| 848 | |
| 849 | return Results->Contexts; |
| 850 | } |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 851 | |
Douglas Gregor | e081a61 | 2011-07-21 01:05:26 +0000 | [diff] [blame] | 852 | enum CXCursorKind clang_codeCompleteGetContainerKind( |
| 853 | CXCodeCompleteResults *ResultsIn, |
| 854 | unsigned *IsIncomplete) { |
| 855 | AllocatedCXCodeCompleteResults *Results = |
| 856 | static_cast<AllocatedCXCodeCompleteResults *>(ResultsIn); |
| 857 | if (!Results) |
| 858 | return CXCursor_InvalidCode; |
| 859 | |
| 860 | if (IsIncomplete != NULL) { |
| 861 | *IsIncomplete = Results->ContainerIsIncomplete; |
| 862 | } |
| 863 | |
| 864 | return Results->ContainerKind; |
| 865 | } |
| 866 | |
| 867 | CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *ResultsIn) { |
| 868 | AllocatedCXCodeCompleteResults *Results = |
| 869 | static_cast<AllocatedCXCodeCompleteResults *>(ResultsIn); |
| 870 | if (!Results) |
| 871 | return createCXString(""); |
| 872 | |
| 873 | return createCXString(clang_getCString(Results->ContainerUSR)); |
| 874 | } |
Douglas Gregor | 0a47d69 | 2011-07-26 15:24:30 +0000 | [diff] [blame] | 875 | |
| 876 | |
| 877 | CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *ResultsIn) { |
| 878 | AllocatedCXCodeCompleteResults *Results = |
| 879 | static_cast<AllocatedCXCodeCompleteResults *>(ResultsIn); |
| 880 | if (!Results) |
| 881 | return createCXString(""); |
| 882 | |
| 883 | return createCXString(Results->Selector); |
| 884 | } |
Douglas Gregor | e081a61 | 2011-07-21 01:05:26 +0000 | [diff] [blame] | 885 | |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 886 | } // end extern "C" |
Douglas Gregor | 1e5e668 | 2010-08-26 13:48:20 +0000 | [diff] [blame] | 887 | |
Douglas Gregor | c7b7b7a | 2010-10-18 21:05:04 +0000 | [diff] [blame] | 888 | /// \brief Simple utility function that appends a \p New string to the given |
| 889 | /// \p Old string, using the \p Buffer for storage. |
| 890 | /// |
| 891 | /// \param Old The string to which we are appending. This parameter will be |
| 892 | /// updated to reflect the complete string. |
| 893 | /// |
| 894 | /// |
| 895 | /// \param New The string to append to \p Old. |
| 896 | /// |
| 897 | /// \param Buffer A buffer that stores the actual, concatenated string. It will |
| 898 | /// be used if the old string is already-non-empty. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 899 | static void AppendToString(StringRef &Old, StringRef New, |
Dylan Noblesmith | 36d5927 | 2012-02-13 12:32:26 +0000 | [diff] [blame] | 900 | SmallString<256> &Buffer) { |
Douglas Gregor | c7b7b7a | 2010-10-18 21:05:04 +0000 | [diff] [blame] | 901 | if (Old.empty()) { |
| 902 | Old = New; |
| 903 | return; |
| 904 | } |
| 905 | |
| 906 | if (Buffer.empty()) |
| 907 | Buffer.append(Old.begin(), Old.end()); |
| 908 | Buffer.append(New.begin(), New.end()); |
| 909 | Old = Buffer.str(); |
| 910 | } |
| 911 | |
| 912 | /// \brief Get the typed-text blocks from the given code-completion string |
| 913 | /// and return them as a single string. |
| 914 | /// |
| 915 | /// \param String The code-completion string whose typed-text blocks will be |
| 916 | /// concatenated. |
| 917 | /// |
| 918 | /// \param Buffer A buffer used for storage of the completed name. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 919 | static StringRef GetTypedName(CodeCompletionString *String, |
Dylan Noblesmith | 36d5927 | 2012-02-13 12:32:26 +0000 | [diff] [blame] | 920 | SmallString<256> &Buffer) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 921 | StringRef Result; |
Douglas Gregor | c7b7b7a | 2010-10-18 21:05:04 +0000 | [diff] [blame] | 922 | for (CodeCompletionString::iterator C = String->begin(), CEnd = String->end(); |
| 923 | C != CEnd; ++C) { |
| 924 | if (C->Kind == CodeCompletionString::CK_TypedText) |
| 925 | AppendToString(Result, C->Text, Buffer); |
| 926 | } |
| 927 | |
| 928 | return Result; |
| 929 | } |
| 930 | |
Douglas Gregor | 1e5e668 | 2010-08-26 13:48:20 +0000 | [diff] [blame] | 931 | namespace { |
| 932 | struct OrderCompletionResults { |
| 933 | bool operator()(const CXCompletionResult &XR, |
| 934 | const CXCompletionResult &YR) const { |
Douglas Gregor | 218937c | 2011-02-01 19:23:04 +0000 | [diff] [blame] | 935 | CodeCompletionString *X |
| 936 | = (CodeCompletionString *)XR.CompletionString; |
| 937 | CodeCompletionString *Y |
| 938 | = (CodeCompletionString *)YR.CompletionString; |
Douglas Gregor | 1e5e668 | 2010-08-26 13:48:20 +0000 | [diff] [blame] | 939 | |
Dylan Noblesmith | 36d5927 | 2012-02-13 12:32:26 +0000 | [diff] [blame] | 940 | SmallString<256> XBuffer; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 941 | StringRef XText = GetTypedName(X, XBuffer); |
Dylan Noblesmith | 36d5927 | 2012-02-13 12:32:26 +0000 | [diff] [blame] | 942 | SmallString<256> YBuffer; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 943 | StringRef YText = GetTypedName(Y, YBuffer); |
Douglas Gregor | 1e5e668 | 2010-08-26 13:48:20 +0000 | [diff] [blame] | 944 | |
Douglas Gregor | c7b7b7a | 2010-10-18 21:05:04 +0000 | [diff] [blame] | 945 | if (XText.empty() || YText.empty()) |
| 946 | return !XText.empty(); |
| 947 | |
| 948 | int result = XText.compare_lower(YText); |
Douglas Gregor | 1e5e668 | 2010-08-26 13:48:20 +0000 | [diff] [blame] | 949 | if (result < 0) |
| 950 | return true; |
| 951 | if (result > 0) |
| 952 | return false; |
| 953 | |
Douglas Gregor | c7b7b7a | 2010-10-18 21:05:04 +0000 | [diff] [blame] | 954 | result = XText.compare(YText); |
Douglas Gregor | 1aad340 | 2010-09-10 23:05:54 +0000 | [diff] [blame] | 955 | return result < 0; |
Douglas Gregor | 1e5e668 | 2010-08-26 13:48:20 +0000 | [diff] [blame] | 956 | } |
| 957 | }; |
| 958 | } |
| 959 | |
| 960 | extern "C" { |
| 961 | void clang_sortCodeCompletionResults(CXCompletionResult *Results, |
| 962 | unsigned NumResults) { |
| 963 | std::stable_sort(Results, Results + NumResults, OrderCompletionResults()); |
| 964 | } |
Douglas Gregor | 458433d | 2010-08-26 15:07:07 +0000 | [diff] [blame] | 965 | } |