2017-02-18 19:37:24 +00:00
|
|
|
#include <cassert>
|
|
|
|
|
2017-02-16 09:35:30 +00:00
|
|
|
#include "SourceLocation.h"
|
|
|
|
#include "Utility.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
|
|
|
|
SourceLocation::SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned offset) {
|
|
|
|
CXFile file = clang_getFile(tu, filepath.c_str());
|
2017-02-18 19:37:24 +00:00
|
|
|
assert(false);
|
|
|
|
//cx_location = clang_getLocationForOffset(tu, file, offset);
|
2017-02-16 09:35:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SourceLocation::SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned line, unsigned column) {
|
|
|
|
CXFile file = clang_getFile(tu, filepath.c_str());
|
2017-02-18 19:37:24 +00:00
|
|
|
assert(false);
|
|
|
|
//cx_location = clang_getLocation(tu, file, line, column);
|
2017-02-16 09:35:30 +00:00
|
|
|
}
|
|
|
|
|
2017-02-20 00:56:56 +00:00
|
|
|
SourceLocation::SourceLocation() {}
|
|
|
|
|
2017-02-18 19:37:24 +00:00
|
|
|
SourceLocation::SourceLocation(const CXSourceLocation& cx_location) {
|
|
|
|
//clang_getExpansionLocation
|
|
|
|
|
|
|
|
CXFile file;
|
|
|
|
clang_getSpellingLocation(cx_location, &file, &line, &column, &offset);
|
|
|
|
if (file != nullptr)
|
|
|
|
path = clang::ToString(clang_getFileName(file));
|
2017-02-16 09:35:30 +00:00
|
|
|
}
|
|
|
|
|
2017-02-20 00:56:56 +00:00
|
|
|
SourceLocation::SourceLocation(const CXIdxLoc& cx_location)
|
|
|
|
: SourceLocation(clang_indexLoc_getCXSourceLocation(cx_location)) {
|
|
|
|
}
|
|
|
|
|
2017-02-20 19:08:27 +00:00
|
|
|
bool operator==(const SourceLocation& a, const SourceLocation& b) {
|
|
|
|
return a.path == b.path && a.line == b.line && a.column == b.column;
|
2017-02-20 00:56:56 +00:00
|
|
|
}
|
|
|
|
|
2017-02-20 19:08:27 +00:00
|
|
|
bool operator!=(const SourceLocation& a, const SourceLocation& b) {
|
|
|
|
return !(a == b);
|
2017-02-20 00:56:56 +00:00
|
|
|
}
|
|
|
|
|
2017-02-18 19:37:24 +00:00
|
|
|
std::string SourceLocation::ToString() const {
|
|
|
|
return path + ":" + std::to_string(line) + ":" + std::to_string(column);
|
2017-02-16 09:35:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|