mirror of https://gitlab.com/cppit/libclangmm
27 changed files with 189 additions and 250 deletions
@ -1,41 +1,34 @@
|
||||
#include "SourceLocation.h" |
||||
#include "Utility.h" |
||||
|
||||
// // // // // // // //
|
||||
// SourceLocation //
|
||||
// // // // // // // //
|
||||
clang::SourceLocation:: |
||||
SourceLocation(CXTranslationUnit &tu, |
||||
const std::string &filename, |
||||
int line_number, |
||||
int line_offset) { |
||||
CXFile file = clang_getFile(tu, |
||||
filename.c_str()); |
||||
cx_location = clang_getLocation(tu, |
||||
file, |
||||
line_number, |
||||
line_offset); |
||||
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); |
||||
} |
||||
|
||||
clang::SourceLocation:: |
||||
SourceLocation(CXTranslationUnit &tu, |
||||
const std::string &filepath, |
||||
int 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_location_info(std::string* path, |
||||
unsigned *line, |
||||
unsigned *column, |
||||
unsigned *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 (path != NULL && file!=NULL) { |
||||
path->operator=(((clang_getCString((clang_getFileName(file)))))); |
||||
if (file!=NULL) { |
||||
*path=clang::to_string(clang_getFileName(file)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
#include "Utility.h" |
||||
|
||||
std::string clang::to_string(CXString cx_string) { |
||||
std::string string; |
||||
if(cx_string.data!=NULL) { |
||||
string=clang_getCString(cx_string); |
||||
clang_disposeString(cx_string); |
||||
} |
||||
return string; |
||||
} |
||||
@ -0,0 +1,10 @@
|
||||
#ifndef UTILITY_H_ |
||||
#define UTILITY_H_ |
||||
#include <clang-c/Index.h> |
||||
#include <string> |
||||
|
||||
namespace clang { |
||||
std::string to_string(CXString cx_string); |
||||
} |
||||
|
||||
#endif // UTILITY_H_
|
||||
Loading…
Reference in new issue