diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/CIndex/CIndex.cpp | 68 | ||||
-rw-r--r-- | tools/CIndex/CIndex.exports | 1 | ||||
-rw-r--r-- | tools/c-index-test/c-index-test.c | 28 | ||||
-rw-r--r-- | tools/driver/cc1_main.cpp | 3 | ||||
-rw-r--r-- | tools/driver/driver.cpp | 4 | ||||
l--------- | tools/scan-build/c++-analyzer | 1 | ||||
-rwxr-xr-x | tools/scan-build/ccc-analyzer | 2 |
7 files changed, 82 insertions, 25 deletions
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp index fe3aa37..9b2355d 100644 --- a/tools/CIndex/CIndex.cpp +++ b/tools/CIndex/CIndex.cpp @@ -1114,6 +1114,8 @@ clang_getCompletionChunkKind(CXCompletionString completion_string, return CXCompletionChunk_Placeholder; case CodeCompletionString::CK_Informative: return CXCompletionChunk_Informative; + case CodeCompletionString::CK_ResultType: + return CXCompletionChunk_ResultType; case CodeCompletionString::CK_CurrentParameter: return CXCompletionChunk_CurrentParameter; case CodeCompletionString::CK_LeftParen: @@ -1161,6 +1163,7 @@ const char *clang_getCompletionChunkText(CXCompletionString completion_string, case CodeCompletionString::CK_LeftAngle: case CodeCompletionString::CK_RightAngle: case CodeCompletionString::CK_Comma: + case CodeCompletionString::CK_ResultType: return (*CCStr)[chunk_number].Text; case CodeCompletionString::CK_Optional: @@ -1194,6 +1197,7 @@ clang_getCompletionChunkCompletionString(CXCompletionString completion_string, case CodeCompletionString::CK_LeftAngle: case CodeCompletionString::CK_RightAngle: case CodeCompletionString::CK_Comma: + case CodeCompletionString::CK_ResultType: return 0; case CodeCompletionString::CK_Optional: @@ -1220,17 +1224,23 @@ static bool ReadUnsigned(const char *&Memory, const char *MemoryEnd, return false; } -void clang_codeComplete(CXIndex CIdx, - const char *source_filename, - int num_command_line_args, - const char **command_line_args, - unsigned num_unsaved_files, - struct CXUnsavedFile *unsaved_files, - const char *complete_filename, - unsigned complete_line, - unsigned complete_column, - CXCompletionIterator completion_iterator, - CXClientData client_data) { +/// \brief The CXCodeCompleteResults structure we allocate internally; +/// the client only sees the initial CXCodeCompleteResults structure. +struct AllocatedCXCodeCompleteResults : public CXCodeCompleteResults { + /// \brief The memory buffer from which we parsed the results. We + /// retain this buffer because the completion strings point into it. + llvm::MemoryBuffer *Buffer; +}; + +CXCodeCompleteResults *clang_codeComplete(CXIndex CIdx, + const char *source_filename, + int num_command_line_args, + const char **command_line_args, + unsigned num_unsaved_files, + struct CXUnsavedFile *unsaved_files, + const char *complete_filename, + unsigned complete_line, + unsigned complete_column) { // The indexer, which is mainly used to determine where diagnostics go. CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx); @@ -1353,7 +1363,9 @@ void clang_codeComplete(CXIndex CIdx, // Parse the resulting source file to find code-completion results. using llvm::MemoryBuffer; using llvm::StringRef; + AllocatedCXCodeCompleteResults *Results = 0; if (MemoryBuffer *F = MemoryBuffer::getFile(ResultsFile.c_str())) { + llvm::SmallVector<CXCompletionResult, 4> CompletionResults; StringRef Buffer = F->getBuffer(); for (const char *Str = Buffer.data(), *StrEnd = Str + Buffer.size(); Str < StrEnd;) { @@ -1371,17 +1383,41 @@ void clang_codeComplete(CXIndex CIdx, CXCompletionResult Result; Result.CursorKind = (CXCursorKind)KindValue; Result.CompletionString = CCStr; - if (completion_iterator) - completion_iterator(&Result, client_data); + CompletionResults.push_back(Result); } - - delete CCStr; }; - delete F; + + // Allocate the results. + Results = new AllocatedCXCodeCompleteResults; + Results->Results = new CXCompletionResult [CompletionResults.size()]; + Results->NumResults = CompletionResults.size(); + memcpy(Results->Results, CompletionResults.data(), + CompletionResults.size() * sizeof(CXCompletionResult)); + Results->Buffer = F; } for (unsigned i = 0, e = TemporaryFiles.size(); i != e; ++i) TemporaryFiles[i].eraseFromDisk(); + + return Results; +} + +void clang_disposeCodeCompleteResults(CXCodeCompleteResults *ResultsIn) { + if (!ResultsIn) + return; + + AllocatedCXCodeCompleteResults *Results + = static_cast<AllocatedCXCodeCompleteResults*>(ResultsIn); + + for (unsigned I = 0, N = Results->NumResults; I != N; ++I) + delete (CXCompletionString *)Results->Results[I].CompletionString; + delete [] Results->Results; + + Results->Results = 0; + Results->NumResults = 0; + delete Results->Buffer; + Results->Buffer = 0; + delete Results; } } // end extern "C" diff --git a/tools/CIndex/CIndex.exports b/tools/CIndex/CIndex.exports index 458ad10..e925df9 100644 --- a/tools/CIndex/CIndex.exports +++ b/tools/CIndex/CIndex.exports @@ -2,6 +2,7 @@ _clang_codeComplete _clang_createIndex _clang_createTranslationUnit _clang_createTranslationUnitFromSourceFile +_clang_disposeCodeCompleteResults _clang_disposeIndex _clang_disposeString _clang_disposeTranslationUnit diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index 7300585..33013f3 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -355,6 +355,7 @@ clang_getCompletionChunkKindSpelling(enum CXCompletionChunkKind Kind) { case CXCompletionChunk_LeftAngle: return "LeftAngle"; case CXCompletionChunk_RightAngle: return "RightAngle"; case CXCompletionChunk_Comma: return "Comma"; + case CXCompletionChunk_ResultType: return "ResultType"; } return "Unknown"; @@ -461,7 +462,15 @@ int parse_remapped_files(int argc, const char **argv, int start_arg, /* Read the contents of the file we're remapping to. */ contents = (char *)malloc(unsaved->Length + 1); - fread(contents, 1, unsaved->Length, to_file); + if (fread(contents, 1, unsaved->Length, to_file) != unsaved->Length) { + fprintf(stderr, "error: unexpected %s reading 'to' file %s\n", + (feof(to_file) ? "EOF" : "error"), semi + 1); + fclose(to_file); + free_remapped_files(*unsaved_files, i); + *unsaved_files = 0; + *num_unsaved_files = 0; + return -1; + } contents[unsaved->Length] = 0; unsaved->Contents = contents; @@ -488,6 +497,7 @@ int perform_code_completion(int argc, const char **argv) { int errorCode; struct CXUnsavedFile *unsaved_files = 0; int num_unsaved_files = 0; + CXCodeCompleteResults *results = 0; input += strlen("-code-completion-at="); if ((errorCode = parse_file_line_column(input, &filename, &line, &column))) @@ -497,10 +507,18 @@ int perform_code_completion(int argc, const char **argv) { return -1; CIdx = clang_createIndex(0, 0); - clang_codeComplete(CIdx, argv[argc - 1], argc - num_unsaved_files - 3, - argv + num_unsaved_files + 2, - num_unsaved_files, unsaved_files, - filename, line, column, &print_completion_result, stdout); + results = clang_codeComplete(CIdx, + argv[argc - 1], argc - num_unsaved_files - 3, + argv + num_unsaved_files + 2, + num_unsaved_files, unsaved_files, + filename, line, column); + if (results) { + unsigned i, n = results->NumResults; + for (i = 0; i != n; ++i) + print_completion_result(results->Results + i, stdout); + clang_disposeCodeCompleteResults(results); + } + clang_disposeIndex(CIdx); free(filename); diff --git a/tools/driver/cc1_main.cpp b/tools/driver/cc1_main.cpp index 6e82c51..eb1f60c 100644 --- a/tools/driver/cc1_main.cpp +++ b/tools/driver/cc1_main.cpp @@ -110,7 +110,6 @@ static FrontendAction *CreateFrontendAction(CompilerInstance &CI) { case PrintDeclContext: return new DeclContextPrintAction(); case PrintPreprocessedInput: return new PrintPreprocessedAction(); - case RewriteBlocks: return new RewriteBlocksAction(); case RewriteMacros: return new RewriteMacrosAction(); case RewriteObjC: return new RewriteObjCAction(); case RewriteTest: return new RewriteTestAction(); @@ -187,8 +186,6 @@ static int cc1_test(Diagnostic &Diags, int cc1_main(const char **ArgBegin, const char **ArgEnd, const char *Argv0, void *MainAddr) { - llvm::sys::PrintStackTraceOnErrorSignal(); - llvm::PrettyStackTraceProgram X(ArgBegin - ArgEnd, ArgBegin); CompilerInstance Clang(&llvm::getGlobalContext(), false); // Run clang -cc1 test. diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp index cfdd9c3..b6fc981 100644 --- a/tools/driver/driver.cpp +++ b/tools/driver/driver.cpp @@ -225,8 +225,10 @@ int main(int argc, const char **argv) { // We use *argv instead of argv[0] to work around a bogus g++ warning. std::string ProgName(llvm::sys::Path(*argv).getBasename()); if (llvm::StringRef(ProgName).endswith("++") || - llvm::StringRef(ProgName).rsplit('-').first.endswith("++")) + llvm::StringRef(ProgName).rsplit('-').first.endswith("++")) { TheDriver.CCCIsCXX = true; + TheDriver.CCCGenericGCCName = "g++"; + } llvm::OwningPtr<Compilation> C; diff --git a/tools/scan-build/c++-analyzer b/tools/scan-build/c++-analyzer new file mode 120000 index 0000000..ca10bf5 --- /dev/null +++ b/tools/scan-build/c++-analyzer @@ -0,0 +1 @@ +ccc-analyzer
\ No newline at end of file diff --git a/tools/scan-build/ccc-analyzer b/tools/scan-build/ccc-analyzer index aca411f..f19dcb4 100755 --- a/tools/scan-build/ccc-analyzer +++ b/tools/scan-build/ccc-analyzer @@ -66,7 +66,9 @@ END { sub GetPPExt { my $Lang = shift; + if ($Lang =~ /objective-c\+\+/) { return ".mii" }; if ($Lang =~ /objective-c/) { return ".mi"; } + if ($Lang =~ /c\+\+/) { return ".ii"; } return ".i"; } |