88#include < iostream> // TODO: remove
99using namespace std ; // TODO: remove
1010
11- clang::TranslationUnit::
12- ~TranslationUnit () {
13- clang_disposeTranslationUnit (cx_tu);
14- }
15-
16- clang::TranslationUnit::
17- TranslationUnit (Index &index, const std::string &file_path, const std::vector<std::string> &command_line_args) {
18- std::map<std::string, std::string> buffers;
19- std::ifstream ifs (file_path, std::ifstream::in);
20- std::stringstream ss;
21- ss << ifs.rdbuf ();
22- buffers[file_path]=ss.str ();
23- parse (index, file_path, command_line_args, buffers);
24- }
25-
26- clang::TranslationUnit::TranslationUnit (Index &index, const std::string &file_path) {
27- std::vector<std::string> command_line_args;
28- std::map<std::string, std::string> buffers;
29- std::ifstream ifs (file_path, std::ifstream::in);
30- std::stringstream ss;
31- ss << ifs.rdbuf ();
32- buffers[file_path]=ss.str ();
33- parse (index, file_path, command_line_args, buffers);
34- }
35-
3611clang::TranslationUnit::TranslationUnit (Index &index, const std::string &file_path,
3712 const std::vector<std::string> &command_line_args,
3813 const std::string &buffer, unsigned flags) {
@@ -50,10 +25,20 @@ clang::TranslationUnit::TranslationUnit(Index &index, const std::string &file_pa
5025 args.size (), files, 1 , flags);
5126}
5227
53- clang::TranslationUnit::TranslationUnit (clang::Index &index, const std::string &file_path,
54- const std::vector<std::string> &command_line_args,
55- const std::map<std::string, std::string> &buffers, unsigned flags) {
56- parse (index, file_path, command_line_args, buffers, flags);
28+ clang::TranslationUnit::TranslationUnit (Index &index, const std::string &file_path,
29+ const std::vector<std::string> &command_line_args,
30+ unsigned flags) {
31+ std::vector<const char *> args;
32+ for (auto &a: command_line_args) {
33+ args.push_back (a.c_str ());
34+ }
35+
36+ cx_tu = clang_parseTranslationUnit (index.cx_index , file_path.c_str (), args.data (),
37+ args.size (), NULL , 0 , flags);
38+ }
39+
40+ clang::TranslationUnit::~TranslationUnit () {
41+ clang_disposeTranslationUnit (cx_tu);
5742}
5843
5944void clang::TranslationUnit::parse (Index &index, const std::string &file_path,
@@ -87,18 +72,6 @@ int clang::TranslationUnit::ReparseTranslationUnit(const std::string &buffer, un
8772 return clang_reparseTranslationUnit (cx_tu, 1 , files, flags);
8873}
8974
90- int clang::TranslationUnit::ReparseTranslationUnit (const std::map<std::string, std::string> &buffers, unsigned flags) {
91- std::vector<CXUnsavedFile> files;
92- for (auto &buffer : buffers) {
93- CXUnsavedFile file;
94- file.Filename = buffer.first .c_str ();
95- file.Contents = buffer.second .c_str ();
96- file.Length = buffer.second .size ();
97- files.push_back (file);
98- }
99- return clang_reparseTranslationUnit (cx_tu, files.size (), files.data (), flags);
100- }
101-
10275unsigned clang::TranslationUnit::DefaultFlags () {
10376 return CXTranslationUnit_CacheCompletionResults | CXTranslationUnit_PrecompiledPreamble | CXTranslationUnit_Incomplete | CXTranslationUnit_IncludeBriefCommentsInCodeCompletion;
10477}
@@ -109,14 +82,6 @@ clang::CodeCompleteResults clang::TranslationUnit::get_code_completions(const st
10982 return results;
11083}
11184
112- clang::CodeCompleteResults clang::TranslationUnit::get_code_completions (const std::map<std::string, std::string> &buffers,
113- unsigned line_number, unsigned column) {
114- auto path=clang::to_string (clang_getTranslationUnitSpelling (cx_tu));
115-
116- clang::CodeCompleteResults results (cx_tu, path, buffers, line_number, column);
117- return results;
118- }
119-
12085std::vector<clang::Diagnostic> clang::TranslationUnit::get_diagnostics () {
12186 std::vector<clang::Diagnostic> diagnostics;
12287 for (unsigned c=0 ;c<clang_getNumDiagnostics (cx_tu);c++) {
0 commit comments