diff --git a/src/CodeCompleteResults.cc b/src/CodeCompleteResults.cc index 3d6a931..38c90fd 100644 --- a/src/CodeCompleteResults.cc +++ b/src/CodeCompleteResults.cc @@ -23,29 +23,6 @@ clang::CodeCompleteResults::CodeCompleteResults(CXTranslationUnit &cx_tu, clang_sortCodeCompletionResults(cx_results->Results, cx_results->NumResults); } -clang::CodeCompleteResults::CodeCompleteResults(CXTranslationUnit &cx_tu, - const std::string &file_name, - const std::map &buffers, - unsigned line_num, unsigned column) { - std::vector files; - for (auto &buffer : buffers) { - CXUnsavedFile file; - file.Filename = buffer.first.c_str(); - file.Contents = buffer.second.c_str(); - file.Length = buffer.second.size(); - files.push_back(file); - } - cx_results = clang_codeCompleteAt(cx_tu, - file_name.c_str(), - line_num, - column, - files.data(), - files.size(), - clang_defaultCodeCompleteOptions()|CXCodeComplete_IncludeBriefComments); - if(cx_results!=NULL) - clang_sortCodeCompletionResults(cx_results->Results, cx_results->NumResults); -} - clang::CodeCompleteResults::~CodeCompleteResults() { clang_disposeCodeCompleteResults(cx_results); } diff --git a/src/CodeCompleteResults.h b/src/CodeCompleteResults.h index af0f536..64d855b 100644 --- a/src/CodeCompleteResults.h +++ b/src/CodeCompleteResults.h @@ -11,10 +11,6 @@ namespace clang { CodeCompleteResults(CXTranslationUnit &cx_tu, const std::string &buffer, unsigned line_num, unsigned column); - //TODO: remove - CodeCompleteResults(CXTranslationUnit &cx_tu, const std::string &file_path, - const std::map &buffers, - unsigned line_num, unsigned column); public: ~CodeCompleteResults(); CompletionString get(unsigned index) const; diff --git a/src/TranslationUnit.cc b/src/TranslationUnit.cc index af8140c..ab8a713 100644 --- a/src/TranslationUnit.cc +++ b/src/TranslationUnit.cc @@ -8,31 +8,6 @@ #include //TODO: remove using namespace std; //TODO: remove -clang::TranslationUnit:: -~TranslationUnit() { - clang_disposeTranslationUnit(cx_tu); -} - -clang::TranslationUnit:: -TranslationUnit(Index &index, const std::string &file_path, const std::vector &command_line_args) { - std::map buffers; - std::ifstream ifs(file_path, std::ifstream::in); - std::stringstream ss; - ss << ifs.rdbuf(); - buffers[file_path]=ss.str(); - parse(index, file_path, command_line_args, buffers); -} - -clang::TranslationUnit::TranslationUnit(Index &index, const std::string &file_path) { - std::vector command_line_args; - std::map buffers; - std::ifstream ifs(file_path, std::ifstream::in); - std::stringstream ss; - ss << ifs.rdbuf(); - buffers[file_path]=ss.str(); - parse(index, file_path, command_line_args, buffers); -} - clang::TranslationUnit::TranslationUnit(Index &index, const std::string &file_path, const std::vector &command_line_args, const std::string &buffer, unsigned flags) { @@ -50,10 +25,20 @@ clang::TranslationUnit::TranslationUnit(Index &index, const std::string &file_pa args.size(), files, 1, flags); } -clang::TranslationUnit::TranslationUnit(clang::Index &index, const std::string &file_path, - const std::vector &command_line_args, - const std::map &buffers, unsigned flags) { - parse(index, file_path, command_line_args, buffers, flags); +clang::TranslationUnit::TranslationUnit(Index &index, const std::string &file_path, + const std::vector &command_line_args, + unsigned flags) { + std::vector args; + for(auto &a: command_line_args) { + args.push_back(a.c_str()); + } + + cx_tu = clang_parseTranslationUnit(index.cx_index, file_path.c_str(), args.data(), + args.size(), NULL, 0, flags); +} + +clang::TranslationUnit::~TranslationUnit() { + clang_disposeTranslationUnit(cx_tu); } void clang::TranslationUnit::parse(Index &index, const std::string &file_path, @@ -87,18 +72,6 @@ int clang::TranslationUnit::ReparseTranslationUnit(const std::string &buffer, un return clang_reparseTranslationUnit(cx_tu, 1, files, flags); } -int clang::TranslationUnit::ReparseTranslationUnit(const std::map &buffers, unsigned flags) { - std::vector files; - for (auto &buffer : buffers) { - CXUnsavedFile file; - file.Filename = buffer.first.c_str(); - file.Contents = buffer.second.c_str(); - file.Length = buffer.second.size(); - files.push_back(file); - } - return clang_reparseTranslationUnit(cx_tu, files.size(), files.data(), flags); -} - unsigned clang::TranslationUnit::DefaultFlags() { return CXTranslationUnit_CacheCompletionResults | CXTranslationUnit_PrecompiledPreamble | CXTranslationUnit_Incomplete | CXTranslationUnit_IncludeBriefCommentsInCodeCompletion; } @@ -109,14 +82,6 @@ clang::CodeCompleteResults clang::TranslationUnit::get_code_completions(const st return results; } -clang::CodeCompleteResults clang::TranslationUnit::get_code_completions(const std::map &buffers, - unsigned line_number, unsigned column) { - auto path=clang::to_string(clang_getTranslationUnitSpelling(cx_tu)); - - clang::CodeCompleteResults results(cx_tu, path, buffers, line_number, column); - return results; -} - std::vector clang::TranslationUnit::get_diagnostics() { std::vector diagnostics; for(unsigned c=0;c &command_line_args); TranslationUnit(Index &index, const std::string &file_path, const std::vector &command_line_args, const std::string &buffer, unsigned flags=DefaultFlags()); - //TODO: remove TranslationUnit(Index &index, const std::string &file_path, const std::vector &command_line_args, - const std::map &buffers, unsigned flags=DefaultFlags()); - TranslationUnit(Index &index, const std::string &file_path); ~TranslationUnit(); int ReparseTranslationUnit(const std::string &buffer, unsigned flags=DefaultFlags()); - //TODO: remove - int ReparseTranslationUnit(const std::map &buffers, - unsigned flags=DefaultFlags()); static unsigned DefaultFlags(); @@ -47,9 +37,6 @@ namespace clang { clang::CodeCompleteResults get_code_completions(const std::string &buffer, unsigned line_number, unsigned column); - //TODO: remove - clang::CodeCompleteResults get_code_completions(const std::map &buffers, - unsigned line_number, unsigned column); std::vector get_diagnostics(); diff --git a/tests/CodeCompleteResults_H_Test.cc b/tests/CodeCompleteResults_H_Test.cc index bb75e07..12b6e74 100644 --- a/tests/CodeCompleteResults_H_Test.cc +++ b/tests/CodeCompleteResults_H_Test.cc @@ -9,26 +9,18 @@ BOOST_AUTO_TEST_CASE(code_complete_results) { std::string path("./case/main.cpp"); clang::Index index(0, 0); - clang::TranslationUnit tu(index, path); + clang::TranslationUnit tu(index, path, {}); - // ReparseTranslationUnit takes a map with filepath as key - // and buffer as value - std::map buffers; - - // create buffer - std::string file; - file.append("#include \n"); - file.append("int main(int argc, char *argv[]) {\n"); - file.append("std::string str;\n"); - file.append("str.\n"); - file.append("return 0\n"); - file.append("}"); - - buffers[path] = file; + std::string buffer="#include \n" + "int main(int argc, char *argv[]) {\n" + "std::string str;\n" + "str.\n" + "return 0\n" + "}"; // ] - auto results=tu.get_code_completions(buffers, 4, 5); + auto results=tu.get_code_completions(buffer, 4, 5); bool substr_found=false; for(unsigned c=0;c buffers; + std::string buffer="#include \n" + "int main(int argc, char *argv[]) {\n" + "std::string str;\n" + "str.\n" + "return 0\n" + "}"; - // create buffer - std::string file; - file.append("#include \n"); - file.append("int main(int argc, char *argv[]) {\n"); - file.append("std::string str;\n"); - file.append("str.\n"); - file.append("return 0\n"); - file.append("}"); - - buffers[path] = file; - - auto results=tu.get_code_completions(buffers, 4, 5); + auto results=tu.get_code_completions(buffer, 4, 5); // ] clang::CompletionString str = results.get(0); diff --git a/tests/Cursor_H_Test.cc b/tests/Cursor_H_Test.cc index 0edc1c3..ad56efd 100644 --- a/tests/Cursor_H_Test.cc +++ b/tests/Cursor_H_Test.cc @@ -8,7 +8,7 @@ BOOST_AUTO_TEST_CASE(cursor) { std::string path("./case/main.cpp"); clang::Index index(0, 0); - clang::TranslationUnit tu(index, path); + clang::TranslationUnit tu(index, path, {}); // ] diff --git a/tests/Diagnostics_Test.cc b/tests/Diagnostics_Test.cc index c56b6a6..253e4c2 100644 --- a/tests/Diagnostics_Test.cc +++ b/tests/Diagnostics_Test.cc @@ -10,15 +10,7 @@ BOOST_AUTO_TEST_CASE(diagnostics_test) { clang::Index index(0, 0); - std::map map_buffers; - ifstream ifs(path, ifstream::in); - stringstream ss; - ss << ifs.rdbuf(); - - map_buffers["./case/main_error.cpp"]=ss.str(); - - std::vector args; - clang::TranslationUnit tu(index, path, args, map_buffers); + clang::TranslationUnit tu(index, path, {}); auto diagnostics=tu.get_diagnostics(); BOOST_CHECK(diagnostics.size()==1); diff --git a/tests/SourceLocation_H_Test.cc b/tests/SourceLocation_H_Test.cc index f6982e8..82f088c 100644 --- a/tests/SourceLocation_H_Test.cc +++ b/tests/SourceLocation_H_Test.cc @@ -7,7 +7,7 @@ BOOST_AUTO_TEST_CASE(source_location) { clang::Index index(0, 0); - clang::TranslationUnit tu(index, path); + clang::TranslationUnit tu(index, path, {}); auto tokens=tu.get_tokens(0, 113); auto offsets=(*tokens)[28].offsets; diff --git a/tests/Token_H_Test.cc b/tests/Token_H_Test.cc index 6325062..91e8d48 100644 --- a/tests/Token_H_Test.cc +++ b/tests/Token_H_Test.cc @@ -7,7 +7,7 @@ BOOST_AUTO_TEST_CASE(token) { clang::Index index(0, 0); - clang::TranslationUnit tu(index, path); + clang::TranslationUnit tu(index, path, {}); auto tokens=tu.get_tokens(0, 113); diff --git a/tests/TranslationUnit_Test.cc b/tests/TranslationUnit_Test.cc index acd9fbd..868ab94 100644 --- a/tests/TranslationUnit_Test.cc +++ b/tests/TranslationUnit_Test.cc @@ -7,18 +7,13 @@ BOOST_AUTO_TEST_CASE(translation_unit) { std::string path("./case/main.cpp"); clang::Index index(0, 0); - clang::TranslationUnit tu(index, path); + + clang::TranslationUnit tu(index, path, {}); - // ReparseTranslationUnit takes a map with filepath as key - // and buffer as value - std::map buffers; + std::string buffer = "int main(int argc, char *argv[]) {\n" + "std::cout << \"Hello World!\" << std::endl;\n" + "return 0\n" + "}\n"; - // create buffer - std::string file = "int main(int argc, char *argv[]) {\n"; - file.append("std::cout << \"Hello World!\" << std::endl;\n"); - file.append("return 0\n"); - file.append("}"); - - buffers[path] = file; - BOOST_CHECK(tu.ReparseTranslationUnit(buffers) == 0); + BOOST_CHECK(tu.ReparseTranslationUnit(buffer) == 0); }