mirror of https://gitlab.com/cppit/libclangmm
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.
40 lines
1.3 KiB
40 lines
1.3 KiB
|
8 years ago
|
#include "source_location.h"
|
||
|
|
#include "utility.h"
|
||
|
11 years ago
|
|
||
|
|
// // // // // // // //
|
||
|
|
// SourceLocation //
|
||
|
|
// // // // // // // //
|
||
|
9 years ago
|
clangmm::SourceLocation::SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned offset) {
|
||
|
11 years ago
|
CXFile file = clang_getFile(tu, filepath.c_str());
|
||
|
|
cx_location = clang_getLocationForOffset(tu, file, offset);
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
9 years ago
|
clangmm::SourceLocation::SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned line, unsigned column) {
|
||
|
10 years ago
|
CXFile file = clang_getFile(tu, filepath.c_str());
|
||
|
|
cx_location = clang_getLocation(tu, file, line, column);
|
||
|
|
}
|
||
|
|
|
||
|
8 years ago
|
std::string clangmm::SourceLocation::get_path() const {
|
||
|
11 years ago
|
std::string path;
|
||
|
8 years ago
|
get_data(&path, nullptr, nullptr, nullptr);
|
||
|
11 years ago
|
return path;
|
||
|
|
}
|
||
|
8 years ago
|
clangmm::Offset clangmm::SourceLocation::get_offset() const {
|
||
|
8 years ago
|
unsigned line, index;
|
||
|
|
get_data(nullptr, &line, &index, nullptr);
|
||
|
|
return {line, index};
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
8 years ago
|
void clangmm::SourceLocation::get_data(std::string* path, unsigned *line, unsigned *column, unsigned *offset) const {
|
||
|
11 years ago
|
if(path==nullptr)
|
||
|
|
clang_getExpansionLocation(cx_location, NULL, line, column, offset);
|
||
|
|
else {
|
||
|
|
CXFile file;
|
||
|
|
clang_getExpansionLocation(cx_location, &file, line, column, offset);
|
||
|
|
if (file!=NULL) {
|
||
|
10 years ago
|
*path=to_string(clang_getFileName(file));
|
||
|
11 years ago
|
}
|
||
|
|
}
|
||
|
11 years ago
|
}
|
||
|
|
|