|
|
|
@ -5,49 +5,43 @@ |
|
|
|
#include <fstream> |
|
|
|
#include <fstream> |
|
|
|
#include <sstream> |
|
|
|
#include <sstream> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream> //TODO: remove |
|
|
|
|
|
|
|
using namespace std; //TODO: remove
|
|
|
|
|
|
|
|
|
|
|
|
clang::TranslationUnit:: |
|
|
|
clang::TranslationUnit:: |
|
|
|
~TranslationUnit() { |
|
|
|
~TranslationUnit() { |
|
|
|
clang_disposeTranslationUnit(cx_tu); |
|
|
|
clang_disposeTranslationUnit(cx_tu); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
clang::TranslationUnit:: |
|
|
|
clang::TranslationUnit:: |
|
|
|
TranslationUnit(Index &index, |
|
|
|
TranslationUnit(Index &index, const std::string &file_path, const std::vector<std::string> &command_line_args) { |
|
|
|
const std::string &filepath, |
|
|
|
|
|
|
|
const std::vector<std::string> &command_line_args) { |
|
|
|
|
|
|
|
std::map<std::string, std::string> buffers; |
|
|
|
std::map<std::string, std::string> buffers; |
|
|
|
std::ifstream ifs(filepath, std::ifstream::in); |
|
|
|
std::ifstream ifs(file_path, std::ifstream::in); |
|
|
|
std::stringstream ss; |
|
|
|
std::stringstream ss; |
|
|
|
ss << ifs.rdbuf(); |
|
|
|
ss << ifs.rdbuf(); |
|
|
|
buffers[filepath]=ss.str(); |
|
|
|
buffers[file_path]=ss.str(); |
|
|
|
parse(index, filepath, command_line_args, buffers); |
|
|
|
parse(index, file_path, command_line_args, buffers); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
clang::TranslationUnit:: |
|
|
|
clang::TranslationUnit::TranslationUnit(Index &index, const std::string &file_path) { |
|
|
|
TranslationUnit(Index &index, |
|
|
|
|
|
|
|
const std::string &filepath) { |
|
|
|
|
|
|
|
std::vector<std::string> command_line_args; |
|
|
|
std::vector<std::string> command_line_args; |
|
|
|
std::map<std::string, std::string> buffers; |
|
|
|
std::map<std::string, std::string> buffers; |
|
|
|
std::ifstream ifs(filepath, std::ifstream::in); |
|
|
|
std::ifstream ifs(file_path, std::ifstream::in); |
|
|
|
std::stringstream ss; |
|
|
|
std::stringstream ss; |
|
|
|
ss << ifs.rdbuf(); |
|
|
|
ss << ifs.rdbuf(); |
|
|
|
buffers[filepath]=ss.str(); |
|
|
|
buffers[file_path]=ss.str(); |
|
|
|
parse(index, filepath, command_line_args, buffers); |
|
|
|
parse(index, file_path, command_line_args, buffers); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
clang::TranslationUnit:: |
|
|
|
clang::TranslationUnit::TranslationUnit(clang::Index &index, const std::string &file_path,
|
|
|
|
TranslationUnit(clang::Index &index, |
|
|
|
|
|
|
|
const std::string &filepath, |
|
|
|
|
|
|
|
const std::vector<std::string> &command_line_args,
|
|
|
|
const std::vector<std::string> &command_line_args,
|
|
|
|
const std::map<std::string, std::string> &buffers, |
|
|
|
const std::map<std::string, std::string> &buffers, unsigned flags) { |
|
|
|
unsigned flags) { |
|
|
|
parse(index, file_path, command_line_args, buffers, flags); |
|
|
|
parse(index, filepath, command_line_args, buffers, flags); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void clang::TranslationUnit::parse(Index &index, |
|
|
|
void clang::TranslationUnit::parse(Index &index, const std::string &file_path,
|
|
|
|
const std::string &filepath, |
|
|
|
|
|
|
|
const std::vector<std::string> &command_line_args, |
|
|
|
const std::vector<std::string> &command_line_args, |
|
|
|
const std::map<std::string, std::string> &buffers, |
|
|
|
const std::map<std::string, std::string> &buffers, unsigned flags) { |
|
|
|
unsigned flags) { |
|
|
|
|
|
|
|
std::vector<CXUnsavedFile> files; |
|
|
|
std::vector<CXUnsavedFile> files; |
|
|
|
for (auto &buffer : buffers) { |
|
|
|
for (auto &buffer : buffers) { |
|
|
|
CXUnsavedFile file; |
|
|
|
CXUnsavedFile file; |
|
|
|
@ -60,19 +54,11 @@ void clang::TranslationUnit::parse(Index &index, |
|
|
|
for(auto &a: command_line_args) { |
|
|
|
for(auto &a: command_line_args) { |
|
|
|
args.push_back(a.c_str()); |
|
|
|
args.push_back(a.c_str()); |
|
|
|
} |
|
|
|
} |
|
|
|
cx_tu = |
|
|
|
cx_tu = clang_parseTranslationUnit(index.cx_index, file_path.c_str(), args.data(),
|
|
|
|
clang_parseTranslationUnit(index.cx_index, |
|
|
|
args.size(), files.data(), files.size(), flags); |
|
|
|
filepath.c_str(), |
|
|
|
|
|
|
|
args.data(), |
|
|
|
|
|
|
|
args.size(), |
|
|
|
|
|
|
|
files.data(), |
|
|
|
|
|
|
|
files.size(), |
|
|
|
|
|
|
|
flags); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int clang::TranslationUnit:: |
|
|
|
int clang::TranslationUnit::ReparseTranslationUnit(const std::map<std::string, std::string> &buffers, unsigned flags) { |
|
|
|
ReparseTranslationUnit(const std::map<std::string, std::string> &buffers, |
|
|
|
|
|
|
|
unsigned flags) { |
|
|
|
|
|
|
|
std::vector<CXUnsavedFile> files; |
|
|
|
std::vector<CXUnsavedFile> files; |
|
|
|
for (auto &buffer : buffers) { |
|
|
|
for (auto &buffer : buffers) { |
|
|
|
CXUnsavedFile file; |
|
|
|
CXUnsavedFile file; |
|
|
|
@ -81,17 +67,15 @@ ReparseTranslationUnit(const std::map<std::string, std::string> &buffers, |
|
|
|
file.Length = buffer.second.size(); |
|
|
|
file.Length = buffer.second.size(); |
|
|
|
files.push_back(file); |
|
|
|
files.push_back(file); |
|
|
|
} |
|
|
|
} |
|
|
|
return clang_reparseTranslationUnit(cx_tu, |
|
|
|
return clang_reparseTranslationUnit(cx_tu, files.size(), files.data(), flags); |
|
|
|
files.size(), |
|
|
|
|
|
|
|
files.data(), |
|
|
|
|
|
|
|
flags); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unsigned clang::TranslationUnit::DefaultFlags() { |
|
|
|
unsigned clang::TranslationUnit::DefaultFlags() { |
|
|
|
return CXTranslationUnit_CacheCompletionResults | CXTranslationUnit_PrecompiledPreamble | CXTranslationUnit_Incomplete | CXTranslationUnit_IncludeBriefCommentsInCodeCompletion; |
|
|
|
return CXTranslationUnit_CacheCompletionResults | CXTranslationUnit_PrecompiledPreamble | CXTranslationUnit_Incomplete | CXTranslationUnit_IncludeBriefCommentsInCodeCompletion; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
clang::CodeCompleteResults clang::TranslationUnit::get_code_completions(const std::map<std::string, std::string> &buffers, unsigned line_number, unsigned column) { |
|
|
|
clang::CodeCompleteResults clang::TranslationUnit::get_code_completions(const std::map<std::string, std::string> &buffers,
|
|
|
|
|
|
|
|
unsigned line_number, unsigned column) { |
|
|
|
auto path=clang::to_string(clang_getTranslationUnitSpelling(cx_tu)); |
|
|
|
auto path=clang::to_string(clang_getTranslationUnitSpelling(cx_tu)); |
|
|
|
|
|
|
|
|
|
|
|
clang::CodeCompleteResults results(cx_tu, path, buffers, line_number, column); |
|
|
|
clang::CodeCompleteResults results(cx_tu, path, buffers, line_number, column); |
|
|
|
|