ccls/libclangmm/SourceLocation.h

42 lines
1.1 KiB
C
Raw Normal View History

2017-02-16 09:35:30 +00:00
#ifndef SOURCELOCATION_H_
#define SOURCELOCATION_H_
#include <clang-c/Index.h>
#include <string>
namespace clang {
class Offset {
public:
Offset() {}
Offset(unsigned line, unsigned index) : line(line), index(index) {}
bool operator==(const clang::Offset &o) { return (line == o.line && index == o.index); }
bool operator!=(const clang::Offset &o) { return !(*this == o); }
unsigned line;
unsigned index; //byte index in line (not char number)
};
class SourceLocation {
friend class TranslationUnit;
SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned offset);
SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned line, unsigned column);
public:
2017-02-20 00:56:56 +00:00
SourceLocation();
2017-02-18 19:37:24 +00:00
SourceLocation(const CXSourceLocation& cx_location);
2017-02-20 00:56:56 +00:00
SourceLocation(const CXIdxLoc& cx_location);
2017-02-18 19:37:24 +00:00
std::string path;
2017-02-20 00:56:56 +00:00
unsigned line = 0;
unsigned column = 0;
unsigned offset = 0;
2017-02-16 09:35:30 +00:00
2017-02-18 19:37:24 +00:00
std::string ToString() const;
2017-02-16 09:35:30 +00:00
};
2017-02-20 19:08:27 +00:00
bool operator==(const SourceLocation& a, const SourceLocation& b);
bool operator!=(const SourceLocation& a, const SourceLocation& b);
2017-02-16 09:35:30 +00:00
} // namespace clang
#endif // SOURCELOCATION_H_