You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.0 KiB

11 years ago
#include "TranslationUnit.h"
const int TranslationUnitOptions = CXTranslationUnit_CacheCompletionResults | CXTranslationUnit_PrecompiledPreamble | CXTranslationUnit_Incomplete;
11 years ago
clang::TranslationUnit::
~TranslationUnit() {
11 years ago
// clang_disposeTranslationUnit(tu_);
11 years ago
}
clang::TranslationUnit& clang::TranslationUnit::
operator=(const clang::TranslationUnit &tu) {
tu_ = tu.tu_;
return *this;
}
clang::TranslationUnit::
TranslationUnit(Index *index,
const std::string &filepath,
const std::vector<std::string> &command_line_args) {
std::vector<const char*> args;
for(auto &a: command_line_args) {
args.push_back(a.c_str());
}
11 years ago
tu_ = clang_createTranslationUnitFromSourceFile(index->index_,
filepath.c_str(),
args.size(),
args.data(),
11 years ago
0,
NULL);
}
clang::TranslationUnit::
TranslationUnit(Index *index,
const std::string &filepath) {
tu_ = clang_createTranslationUnitFromSourceFile(index->index_,
filepath.c_str(),
0,
NULL,
0,
NULL);
}
clang::TranslationUnit::
TranslationUnit(clang::Index *index,
const std::string &filepath,
const std::vector<std::string> &command_line_args,
11 years ago
const std::map<std::string, std::string> &buffers) {
std::vector<CXUnsavedFile> 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);
}
std::vector<const char*> args;
for(auto &a: command_line_args) {
args.push_back(a.c_str());
}
11 years ago
tu_ =
clang_parseTranslationUnit(index->index_,
filepath.c_str(),
args.data(),
args.size(),
11 years ago
files.data(),
files.size(),
TranslationUnitOptions);
11 years ago
}
int clang::TranslationUnit::
ReparseTranslationUnit(const std::string &file_path,
const std::map<std::string, std::string> &buffers) {
std::vector<CXUnsavedFile> 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(tu_,
files.size(),
files.data(),
TranslationUnitOptions);
11 years ago
}