aboutsummaryrefslogtreecommitdiffstats
path: root/liblangutil/Scanner.h
diff options
context:
space:
mode:
authorChristian Parpart <christian@ethereum.org>2018-11-28 23:19:22 +0800
committerChristian Parpart <christian@ethereum.org>2018-12-01 00:07:12 +0800
commitc48a5264be4221873fe02cac57f6a41a32010fea (patch)
tree441c9c554fb9521f41f4a143dc138a33afb03589 /liblangutil/Scanner.h
parent22eff22492b2d569fe56b59763ddc1cd1cf9ccf4 (diff)
downloaddexon-solidity-c48a5264be4221873fe02cac57f6a41a32010fea.tar.gz
dexon-solidity-c48a5264be4221873fe02cac57f6a41a32010fea.tar.zst
dexon-solidity-c48a5264be4221873fe02cac57f6a41a32010fea.zip
liblangutil: SourceLocation: adds (shared) pointer to underlying CharStream source, eliminating sourceName
Also, adapted affecting code to those changes.
Diffstat (limited to 'liblangutil/Scanner.h')
-rw-r--r--liblangutil/Scanner.h25
1 files changed, 13 insertions, 12 deletions
diff --git a/liblangutil/Scanner.h b/liblangutil/Scanner.h
index 9c29edfd..dc37745f 100644
--- a/liblangutil/Scanner.h
+++ b/liblangutil/Scanner.h
@@ -90,14 +90,16 @@ class Scanner
{
friend class LiteralScope;
public:
+ explicit Scanner(std::shared_ptr<CharStream> _source) { reset(std::move(_source)); }
explicit Scanner(CharStream _source = CharStream(), std::string _sourceName = "") { reset(std::move(_source), std::move(_sourceName)); }
- std::string source() const { return m_source.source(); }
+ std::string source() const { return m_source->source(); }
- CharStream const& charStream() const noexcept { return m_source; }
+ std::shared_ptr<CharStream> charStream() noexcept { return m_source; }
/// Resets the scanner as if newly constructed with _source and _sourceName as input.
void reset(CharStream _source, std::string _sourceName);
+ void reset(std::shared_ptr<CharStream> _source);
/// Resets scanner to the start of input.
void reset();
@@ -154,14 +156,13 @@ public:
///@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);
}
///@}
@@ -190,8 +191,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; }
@@ -231,8 +232,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
@@ -240,7 +241,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<CharStream> m_source;
std::shared_ptr<std::string const> m_sourceName;
/// one character look-ahead, equals 0 at end of input