mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use LineColumn type.
This commit is contained in:
parent
622e89649f
commit
86ce5f1da5
@ -100,7 +100,7 @@ string CharStream::lineAtPosition(int _position) const
|
|||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
tuple<int, int> CharStream::translatePositionToLineColumn(int _position) const
|
LineColumn CharStream::translatePositionToLineColumn(int _position) const
|
||||||
{
|
{
|
||||||
using size_type = string::size_type;
|
using size_type = string::size_type;
|
||||||
using diff_type = string::difference_type;
|
using diff_type = string::difference_type;
|
||||||
@ -114,7 +114,7 @@ tuple<int, int> CharStream::translatePositionToLineColumn(int _position) const
|
|||||||
lineStart = m_source.rfind('\n', searchPosition - 1);
|
lineStart = m_source.rfind('\n', searchPosition - 1);
|
||||||
lineStart = lineStart == string::npos ? 0 : lineStart + 1;
|
lineStart = lineStart == string::npos ? 0 : lineStart + 1;
|
||||||
}
|
}
|
||||||
return tuple<int, int>(lineNumber, searchPosition - lineStart);
|
return LineColumn{lineNumber, static_cast<int>(searchPosition - lineStart)};
|
||||||
}
|
}
|
||||||
|
|
||||||
string_view CharStream::text(SourceLocation const& _location) const
|
string_view CharStream::text(SourceLocation const& _location) const
|
||||||
|
@ -59,6 +59,7 @@ namespace solidity::langutil
|
|||||||
{
|
{
|
||||||
|
|
||||||
struct SourceLocation;
|
struct SourceLocation;
|
||||||
|
struct LineColumn;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bidirectional stream of characters.
|
* Bidirectional stream of characters.
|
||||||
@ -97,7 +98,7 @@ public:
|
|||||||
/// Functions that help pretty-printing parse errors
|
/// Functions that help pretty-printing parse errors
|
||||||
/// Do only use in error cases, they are quite expensive.
|
/// Do only use in error cases, they are quite expensive.
|
||||||
std::string lineAtPosition(int _position) const;
|
std::string lineAtPosition(int _position) const;
|
||||||
std::tuple<int, int> translatePositionToLineColumn(int _position) const;
|
LineColumn translatePositionToLineColumn(int _position) const;
|
||||||
///@}
|
///@}
|
||||||
|
|
||||||
/// Tests whether or not given octet sequence is present at the current position in stream.
|
/// Tests whether or not given octet sequence is present at the current position in stream.
|
||||||
|
@ -119,4 +119,23 @@ SourceLocation parseSourceLocation(
|
|||||||
/// Stream output for Location (used e.g. in boost exceptions).
|
/// Stream output for Location (used e.g. in boost exceptions).
|
||||||
std::ostream& operator<<(std::ostream& _out, SourceLocation const& _location);
|
std::ostream& operator<<(std::ostream& _out, SourceLocation const& _location);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alternative, line-column-based representation for source locations.
|
||||||
|
* Both line and column are zero-based.
|
||||||
|
* If used as a range, the second location is considered exclusive.
|
||||||
|
* Negative values are invalid.
|
||||||
|
*/
|
||||||
|
struct LineColumn
|
||||||
|
{
|
||||||
|
/// Line value, can be between zero and number of `\n` characters in the source file.
|
||||||
|
int line = -1;
|
||||||
|
/// Column value, can be between zero and number of characters in the line (inclusive).
|
||||||
|
int column = -1;
|
||||||
|
|
||||||
|
LineColumn() = default;
|
||||||
|
explicit LineColumn(int _line, int _column): line(_line), column(_column) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,15 +30,6 @@ namespace solidity::langutil
|
|||||||
|
|
||||||
class CharStreamProvider;
|
class CharStreamProvider;
|
||||||
|
|
||||||
struct LineColumn
|
|
||||||
{
|
|
||||||
int line = {-1};
|
|
||||||
int column = {-1};
|
|
||||||
|
|
||||||
LineColumn() = default;
|
|
||||||
LineColumn(std::tuple<int, int> const& _t): line{std::get<0>(_t)}, column{std::get<1>(_t)} {}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SourceReference
|
struct SourceReference
|
||||||
{
|
{
|
||||||
std::string message; ///< A message that relates to this source reference (such as a warning, info or an error message).
|
std::string message; ///< A message that relates to this source reference (such as a warning, info or an error message).
|
||||||
|
Loading…
Reference in New Issue
Block a user