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.
 
 

34 lines
989 B

#include "SourceLocation.h"
#include "Utility.h"
// // // // // // // //
// SourceLocation //
// // // // // // // //
clang::SourceLocation::SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned offset) {
CXFile file = clang_getFile(tu, filepath.c_str());
cx_location = clang_getLocationForOffset(tu, file, offset);
}
std::string clang::SourceLocation::get_path() {
std::string path;
get_data(&path, NULL, NULL, NULL);
return path;
}
unsigned clang::SourceLocation::get_offset() {
unsigned offset;
get_data(NULL, NULL, NULL, &offset);
return offset;
}
void clang::SourceLocation::get_data(std::string* path, unsigned *line, unsigned *column, unsigned *offset) {
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) {
*path=clang::to_string(clang_getFileName(file));
}
}
}