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.
43 lines
1.4 KiB
43 lines
1.4 KiB
|
11 years ago
|
#ifndef SOURCELOCATION_H_
|
||
|
|
#define SOURCELOCATION_H_
|
||
|
11 years ago
|
#include <clang-c/Index.h>
|
||
|
|
#include <string>
|
||
|
8 years ago
|
#include <ostream>
|
||
|
11 years ago
|
|
||
|
9 years ago
|
namespace clangmm {
|
||
|
10 years ago
|
class Offset {
|
||
|
|
public:
|
||
|
8 years ago
|
bool operator==(const Offset &o) const {return line==o.line && index==o.index;}
|
||
|
|
bool operator!=(const Offset &o) const {return !(*this==o);}
|
||
|
|
bool operator<(const Offset &o) const {return line<o.line || (line==o.line && index<o.index);}
|
||
|
10 years ago
|
unsigned line;
|
||
|
|
unsigned index; //byte index in line (not char number)
|
||
|
|
};
|
||
|
11 years ago
|
|
||
|
11 years ago
|
class SourceLocation {
|
||
|
11 years ago
|
friend class TranslationUnit;
|
||
|
8 years ago
|
friend class Diagnostic;
|
||
|
11 years ago
|
SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned offset);
|
||
|
10 years ago
|
SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned line, unsigned column);
|
||
|
11 years ago
|
public:
|
||
|
11 years ago
|
SourceLocation(const CXSourceLocation& cx_location) : cx_location(cx_location) {}
|
||
|
11 years ago
|
|
||
|
11 years ago
|
public:
|
||
|
8 years ago
|
std::string get_path() const;
|
||
|
|
clangmm::Offset get_offset() const;
|
||
|
|
|
||
|
|
friend std::ostream &operator<<(std::ostream &os, const SourceLocation &location) {
|
||
|
|
auto offset=location.get_offset();
|
||
|
|
os << location.get_path() << ':' << offset.line << ':' << offset.index;
|
||
|
|
return os;
|
||
|
|
}
|
||
|
11 years ago
|
|
||
|
11 years ago
|
CXSourceLocation cx_location;
|
||
|
11 years ago
|
|
||
|
|
private:
|
||
|
8 years ago
|
void get_data(std::string *path, unsigned *line, unsigned *column, unsigned *offset) const;
|
||
|
11 years ago
|
};
|
||
|
|
|
||
|
9 years ago
|
} // namespace clangmm
|
||
|
11 years ago
|
#endif // SOURCELOCATION_H_
|