[flang] Add position.{h,cc}.
Original-commit: flang-compiler/f18@78c9c256ba
This commit is contained in:
parent
e76093ca67
commit
1651445fd3
7
flang/position.cc
Normal file
7
flang/position.cc
Normal file
|
@ -0,0 +1,7 @@
|
|||
#include "position.h"
|
||||
|
||||
namespace Fortran {
|
||||
std::ostream &operator<<(std::ostream &o, const Position &x) {
|
||||
return o << "(at line " << x.lineNumber() << ", column " << x.column() << ')';
|
||||
}
|
||||
} // namespace Fortran
|
70
flang/position.h
Normal file
70
flang/position.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
#ifndef FORTRAN_POSITION_H_
|
||||
#define FORTRAN_POSITION_H_
|
||||
|
||||
// Represents a position in a source file.
|
||||
// TODO: Support multiple source files for inclusion and support contextual
|
||||
// positions for macro expansions.
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace Fortran {
|
||||
|
||||
class Position {
|
||||
public:
|
||||
constexpr Position() = default;
|
||||
constexpr Position(int ln, int col)
|
||||
: lineNumber_{ln}, column_{col} {}
|
||||
|
||||
constexpr int lineNumber() const { return lineNumber_; }
|
||||
constexpr int column() const { return column_; }
|
||||
|
||||
constexpr bool operator<(const Position &that) const {
|
||||
return lineNumber_ < that.lineNumber_ ||
|
||||
(lineNumber_ == that.lineNumber_ &&
|
||||
column_ < that.column_);
|
||||
}
|
||||
|
||||
constexpr bool operator<=(const Position &that) const {
|
||||
return lineNumber_ < that.lineNumber_ ||
|
||||
(lineNumber_ == that.lineNumber_ &&
|
||||
column_ <= that.column_);
|
||||
}
|
||||
|
||||
constexpr bool operator==(const Position &that) const {
|
||||
return lineNumber_ == that.lineNumber_ &&
|
||||
column_ == that.column_;
|
||||
}
|
||||
|
||||
constexpr bool operator!=(const Position &that) const {
|
||||
return !operator==(that);
|
||||
}
|
||||
|
||||
constexpr bool operator>(const Position &that) const {
|
||||
return !operator<=(that);
|
||||
}
|
||||
|
||||
constexpr bool operator>=(const Position &that) const {
|
||||
return !operator<(that);
|
||||
}
|
||||
|
||||
void AdvanceColumn() {
|
||||
++column_;
|
||||
}
|
||||
|
||||
void TabAdvanceColumn() {
|
||||
column_ = ((column_ + 7) & -8) + 1;
|
||||
}
|
||||
|
||||
void AdvanceLine() {
|
||||
++lineNumber_;
|
||||
column_ = 1;
|
||||
}
|
||||
|
||||
private:
|
||||
int lineNumber_{1};
|
||||
int column_{1};
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &, const Position &);
|
||||
} // namespace Fortran
|
||||
#endif // FORTRAN_POSITION_H_
|
Loading…
Reference in a new issue