aboutsummaryrefslogtreecommitdiffstats
path: root/liblangutil/Scanner.h
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-12-01 06:45:31 +0800
committerGitHub <noreply@github.com>2018-12-01 06:45:31 +0800
commitaaeb74f59283486ee95d71f896cf2dd6cbe503f7 (patch)
tree062fbcc8d84ce2bfa5bb0bb2ef200ba402bb3e8b /liblangutil/Scanner.h
parentcc00d8172b6cd7f9fc032e4a21857455ace2f290 (diff)
parent757623e381aba24b81a2365cf19037d3d96bf945 (diff)
downloaddexon-solidity-aaeb74f59283486ee95d71f896cf2dd6cbe503f7.tar.gz
dexon-solidity-aaeb74f59283486ee95d71f896cf2dd6cbe503f7.tar.zst
dexon-solidity-aaeb74f59283486ee95d71f896cf2dd6cbe503f7.zip
Merge pull request #5537 from ethereum/cp-SourceLocation-related-refactoring
[1/3] SourceLocation related refactoring.
Diffstat (limited to 'liblangutil/Scanner.h')
-rw-r--r--liblangutil/Scanner.h34
1 files changed, 17 insertions, 17 deletions
diff --git a/liblangutil/Scanner.h b/liblangutil/Scanner.h
index d01e71e2..72d0072f 100644
--- a/liblangutil/Scanner.h
+++ b/liblangutil/Scanner.h
@@ -90,12 +90,16 @@ class Scanner
{
friend class LiteralScope;
public:
- explicit Scanner(CharStream _source = CharStream(), std::string _sourceName = "") { reset(std::move(_source), std::move(_sourceName)); }
+ explicit Scanner(std::shared_ptr<CharStream> _source) { reset(std::move(_source)); }
+ explicit Scanner(CharStream _source = CharStream()) { reset(std::move(_source)); }
- std::string source() const { return m_source.source(); }
+ std::string const& source() const noexcept { return m_source->source(); }
- /// Resets the scanner as if newly constructed with _source and _sourceName as input.
- void reset(CharStream _source, std::string _sourceName);
+ std::shared_ptr<CharStream> charStream() noexcept { return m_source; }
+
+ /// Resets the scanner as if newly constructed with _source as input.
+ void reset(CharStream _source);
+ void reset(std::shared_ptr<CharStream> _source);
/// Resets scanner to the start of input.
void reset();
@@ -146,20 +150,17 @@ public:
std::string const& peekLiteral() const { return m_nextToken.literal; }
///@}
- std::shared_ptr<std::string const> const& sourceName() const { return m_sourceName; }
-
///@{
///@name Error printing helper functions
/// Functions that help pretty-printing parse errors
/// Do only use in error cases, they are quite expensive.
- std::string lineAtPosition(int _position) const { return m_source.lineAtPosition(_position); }
- std::tuple<int, int> translatePositionToLineColumn(int _position) const { return m_source.translatePositionToLineColumn(_position); }
+ std::string lineAtPosition(int _position) const { return m_source->lineAtPosition(_position); }
+ std::tuple<int, int> translatePositionToLineColumn(int _position) const { return m_source->translatePositionToLineColumn(_position); }
std::string sourceAt(SourceLocation const& _location) const
{
solAssert(!_location.isEmpty(), "");
- solAssert(m_sourceName && _location.sourceName, "");
- solAssert(*m_sourceName == *_location.sourceName, "");
- return m_source.source().substr(_location.start, _location.end - _location.start);
+ solAssert(m_source.get() == _location.source.get(), "CharStream memory locations must match.");
+ return m_source->source().substr(_location.start, _location.end - _location.start);
}
///@}
@@ -188,8 +189,8 @@ private:
void addUnicodeAsUTF8(unsigned codepoint);
///@}
- bool advance() { m_char = m_source.advanceAndGet(); return !m_source.isPastEndOfInput(); }
- void rollback(int _amount) { m_char = m_source.rollback(_amount); }
+ bool advance() { m_char = m_source->advanceAndGet(); return !m_source->isPastEndOfInput(); }
+ void rollback(int _amount) { m_char = m_source->rollback(_amount); }
inline Token selectErrorToken(ScannerError _err) { advance(); return setError(_err); }
inline Token selectToken(Token _tok) { advance(); return _tok; }
@@ -229,8 +230,8 @@ private:
bool isUnicodeLinebreak();
/// Return the current source position.
- int sourcePos() const { return m_source.position(); }
- bool isSourcePastEndOfInput() const { return m_source.isPastEndOfInput(); }
+ int sourcePos() const { return m_source->position(); }
+ bool isSourcePastEndOfInput() const { return m_source->isPastEndOfInput(); }
TokenDesc m_skippedComment; // desc for current skipped comment
TokenDesc m_nextSkippedComment; // desc for next skipped comment
@@ -238,8 +239,7 @@ private:
TokenDesc m_currentToken; // desc for current token (as returned by Next())
TokenDesc m_nextToken; // desc for next token (one token look-ahead)
- CharStream m_source;
- std::shared_ptr<std::string const> m_sourceName;
+ std::shared_ptr<CharStream> m_source;
/// one character look-ahead, equals 0 at end of input
char m_char;