Browse Source

Added ostream operator overloads to Cursor and Token

merge-requests/37/head
eidheim 8 years ago
parent
commit
2010000696
  1. 10
      src/Cursor.h
  2. 10
      src/Token.h

10
src/Cursor.h

@ -6,6 +6,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <unordered_set> #include <unordered_set>
#include <ostream>
namespace clangmm { namespace clangmm {
class Cursor { class Cursor {
@ -212,6 +213,15 @@ namespace clangmm {
std::string get_type_description() const; std::string get_type_description() const;
std::string get_brief_comments() const; std::string get_brief_comments() const;
friend std::ostream &operator<<(std::ostream &os, const Cursor &cursor) {
auto offsets=cursor.get_source_range().get_offsets();
os << cursor.get_source_location().get_path() << ":"
<< offsets.first.line << ":" << offsets.first.index << "-"
<< offsets.second.line << ":" << offsets.second.index << " "
<< cursor.get_spelling();
return os;
}
CXCursor cx_cursor; CXCursor cx_cursor;
}; };
} // namespace clangmm } // namespace clangmm

10
src/Token.h

@ -5,6 +5,7 @@
#include "SourceRange.h" #include "SourceRange.h"
#include "Cursor.h" #include "Cursor.h"
#include <string> #include <string>
#include <ostream>
namespace clangmm { namespace clangmm {
class Token { class Token {
@ -29,6 +30,15 @@ namespace clangmm {
bool is_identifier() const; bool is_identifier() const;
friend std::ostream &operator<<(std::ostream &os, const Token &token) {
auto offsets=token.get_source_range().get_offsets();
os << token.get_source_location().get_path() << ":"
<< offsets.first.line << ":" << offsets.first.index << "-"
<< offsets.second.line << ":" << offsets.second.index << " "
<< token.get_spelling();
return os;
}
CXTranslationUnit &cx_tu; CXTranslationUnit &cx_tu;
CXToken& cx_token; CXToken& cx_token;
CXCursor& cx_cursor; CXCursor& cx_cursor;

Loading…
Cancel
Save