aboutsummaryrefslogtreecommitdiffstats
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
parent22eff22492b2d569fe56b59763ddc1cd1cf9ccf4 (diff)
downloaddexon-solidity-c48a5264be4221873fe02cac57f6a41a32010fea.tar
dexon-solidity-c48a5264be4221873fe02cac57f6a41a32010fea.tar.gz
dexon-solidity-c48a5264be4221873fe02cac57f6a41a32010fea.tar.bz2
dexon-solidity-c48a5264be4221873fe02cac57f6a41a32010fea.tar.lz
dexon-solidity-c48a5264be4221873fe02cac57f6a41a32010fea.tar.xz
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.
-rw-r--r--libevmasm/Assembly.cpp10
-rw-r--r--liblangutil/ParserBase.cpp4
-rw-r--r--liblangutil/ParserBase.h2
-rw-r--r--liblangutil/Scanner.cpp51
-rw-r--r--liblangutil/Scanner.h25
-rw-r--r--liblangutil/SourceLocation.h34
-rw-r--r--liblangutil/SourceReferenceFormatter.cpp10
-rw-r--r--libsolidity/analysis/NameAndTypeResolver.cpp6
-rw-r--r--libsolidity/ast/ASTJsonConverter.cpp4
-rw-r--r--libsolidity/interface/CompilerStack.cpp8
-rw-r--r--libsolidity/interface/StandardCompiler.cpp4
-rw-r--r--libsolidity/parsing/Parser.cpp4
-rw-r--r--libyul/AsmParser.h6
-rw-r--r--test/libevmasm/Assembler.cpp6
-rw-r--r--test/libevmasm/Optimiser.cpp2
-rw-r--r--test/liblangutil/SourceLocation.cpp14
-rw-r--r--test/libsolidity/Assembly.cpp39
17 files changed, 127 insertions, 102 deletions
diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp
index d80f97c4..29d9846d 100644
--- a/libevmasm/Assembly.cpp
+++ b/libevmasm/Assembly.cpp
@@ -114,10 +114,10 @@ namespace
string locationFromSources(StringMap const& _sourceCodes, SourceLocation const& _location)
{
- if (_location.isEmpty() || _sourceCodes.empty() || _location.start >= _location.end || _location.start < 0)
+ if (_location.isEmpty() || !_location.source.get() || _sourceCodes.empty() || _location.start >= _location.end || _location.start < 0)
return "";
- auto it = _sourceCodes.find(*_location.sourceName);
+ auto it = _sourceCodes.find(_location.source->name());
if (it == _sourceCodes.end())
return "";
@@ -186,11 +186,11 @@ public:
void printLocation()
{
- if (!m_location.sourceName && m_location.isEmpty())
+ if (!m_location.source && m_location.isEmpty())
return;
m_out << m_prefix << " /*";
- if (m_location.sourceName)
- m_out << " \"" + *m_location.sourceName + "\"";
+ if (m_location.source)
+ m_out << " \"" + m_location.source->name() + "\"";
if (!m_location.isEmpty())
m_out << ":" << to_string(m_location.start) + ":" + to_string(m_location.end);
m_out << " " << locationFromSources(m_sourceCodes, m_location);
diff --git a/liblangutil/ParserBase.cpp b/liblangutil/ParserBase.cpp
index 8156f9b9..c103475a 100644
--- a/liblangutil/ParserBase.cpp
+++ b/liblangutil/ParserBase.cpp
@@ -105,10 +105,10 @@ void ParserBase::decreaseRecursionDepth()
void ParserBase::parserError(string const& _description)
{
- m_errorReporter.parserError(SourceLocation(position(), endPosition(), sourceName()), _description);
+ m_errorReporter.parserError(SourceLocation(position(), endPosition(), source()), _description);
}
void ParserBase::fatalParserError(string const& _description)
{
- m_errorReporter.fatalParserError(SourceLocation(position(), endPosition(), sourceName()), _description);
+ m_errorReporter.fatalParserError(SourceLocation(position(), endPosition(), source()), _description);
}
diff --git a/liblangutil/ParserBase.h b/liblangutil/ParserBase.h
index 0007da63..f6315351 100644
--- a/liblangutil/ParserBase.h
+++ b/liblangutil/ParserBase.h
@@ -39,7 +39,7 @@ public:
explicit ParserBase(ErrorReporter& errorReporter): m_errorReporter(errorReporter) {}
std::shared_ptr<std::string const> const& sourceName() const;
- CharStream const* charStream() const { return &m_scanner->charStream(); }
+ std::shared_ptr<CharStream> source() const { return m_scanner->charStream(); }
protected:
/// Utility class that creates an error and throws an exception if the
diff --git a/liblangutil/Scanner.cpp b/liblangutil/Scanner.cpp
index 215171b3..5c0f356e 100644
--- a/liblangutil/Scanner.cpp
+++ b/liblangutil/Scanner.cpp
@@ -169,15 +169,22 @@ private:
void Scanner::reset(CharStream _source, string _sourceName)
{
- m_source = std::move(_source);
+ m_source = make_shared<CharStream>(std::move(_source));
m_sourceName = make_shared<string const>(std::move(_sourceName));
reset();
}
+void Scanner::reset(std::shared_ptr<CharStream> _source)
+{
+ solAssert(_source.get() != nullptr, "You MUST provide a CharStream when resetting.");
+ m_source = _source;
+ reset();
+}
+
void Scanner::reset()
{
- m_source.reset();
- m_char = m_source.get();
+ m_source->reset();
+ m_char = m_source->get();
skipWhitespace();
scanToken();
next();
@@ -296,13 +303,13 @@ Token Scanner::scanSingleLineDocComment()
{
// check if next line is also a documentation comment
skipWhitespace();
- if (!m_source.isPastEndOfInput(3) &&
- m_source.get(0) == '/' &&
- m_source.get(1) == '/' &&
- m_source.get(2) == '/')
+ if (!m_source->isPastEndOfInput(3) &&
+ m_source->get(0) == '/' &&
+ m_source->get(1) == '/' &&
+ m_source->get(2) == '/')
{
addCommentLiteralChar('\n');
- m_char = m_source.advanceAndGet(3);
+ m_char = m_source->advanceAndGet(3);
}
else
break; // next line is not a documentation comment, we are done
@@ -355,20 +362,20 @@ Token Scanner::scanMultiLineDocComment()
if (isLineTerminator(m_char))
{
skipWhitespace();
- if (!m_source.isPastEndOfInput(1) && m_source.get(0) == '*' && m_source.get(1) == '*')
+ if (!m_source->isPastEndOfInput(1) && m_source->get(0) == '*' && m_source->get(1) == '*')
{ // it is unknown if this leads to the end of the comment
addCommentLiteralChar('*');
advance();
}
- else if (!m_source.isPastEndOfInput(1) && m_source.get(0) == '*' && m_source.get(1) != '/')
+ else if (!m_source->isPastEndOfInput(1) && m_source->get(0) == '*' && m_source->get(1) != '/')
{ // skip first '*' in subsequent lines
if (charsAdded)
addCommentLiteralChar('\n');
- m_char = m_source.advanceAndGet(2);
+ m_char = m_source->advanceAndGet(2);
}
- else if (!m_source.isPastEndOfInput(1) && m_source.get(0) == '*' && m_source.get(1) == '/')
+ else if (!m_source->isPastEndOfInput(1) && m_source->get(0) == '*' && m_source->get(1) == '/')
{ // if after newline the comment ends, don't insert the newline
- m_char = m_source.advanceAndGet(2);
+ m_char = m_source->advanceAndGet(2);
endFound = true;
break;
}
@@ -376,9 +383,9 @@ Token Scanner::scanMultiLineDocComment()
addCommentLiteralChar('\n');
}
- if (!m_source.isPastEndOfInput(1) && m_source.get(0) == '*' && m_source.get(1) == '/')
+ if (!m_source->isPastEndOfInput(1) && m_source->get(0) == '*' && m_source->get(1) == '/')
{
- m_char = m_source.advanceAndGet(2);
+ m_char = m_source->advanceAndGet(2);
endFound = true;
break;
}
@@ -715,11 +722,11 @@ bool Scanner::isUnicodeLinebreak()
if (0x0a <= m_char && m_char <= 0x0d)
// line feed, vertical tab, form feed, carriage return
return true;
- else if (!m_source.isPastEndOfInput(1) && uint8_t(m_source.get(0)) == 0xc2 && uint8_t(m_source.get(1)) == 0x85)
+ else if (!m_source->isPastEndOfInput(1) && uint8_t(m_source->get(0)) == 0xc2 && uint8_t(m_source->get(1)) == 0x85)
// NEL - U+0085, C2 85 in utf8
return true;
- else if (!m_source.isPastEndOfInput(2) && uint8_t(m_source.get(0)) == 0xe2 && uint8_t(m_source.get(1)) == 0x80 && (
- uint8_t(m_source.get(2)) == 0xa8 || uint8_t(m_source.get(2)) == 0xa9
+ else if (!m_source->isPastEndOfInput(2) && uint8_t(m_source->get(0)) == 0xe2 && uint8_t(m_source->get(1)) == 0x80 && (
+ uint8_t(m_source->get(2)) == 0xa8 || uint8_t(m_source->get(2)) == 0xa9
))
// LS - U+2028, E2 80 A8 in utf8
// PS - U+2029, E2 80 A9 in utf8
@@ -783,7 +790,7 @@ void Scanner::scanDecimalDigits()
// May continue with decimal digit or underscore for grouping.
do addLiteralCharAndAdvance();
- while (!m_source.isPastEndOfInput() && (isDecimalDigit(m_char) || m_char == '_'));
+ while (!m_source->isPastEndOfInput() && (isDecimalDigit(m_char) || m_char == '_'));
// Defer further validation of underscore to SyntaxChecker.
}
@@ -829,7 +836,7 @@ Token Scanner::scanNumber(char _charSeen)
scanDecimalDigits(); // optional
if (m_char == '.')
{
- if (!m_source.isPastEndOfInput(1) && m_source.get(1) == '_')
+ if (!m_source->isPastEndOfInput(1) && m_source->get(1) == '_')
{
// Assume the input may be a floating point number with leading '_' in fraction part.
// Recover by consuming it all but returning `Illegal` right away.
@@ -837,7 +844,7 @@ Token Scanner::scanNumber(char _charSeen)
addLiteralCharAndAdvance(); // '_'
scanDecimalDigits();
}
- if (m_source.isPastEndOfInput() || !isDecimalDigit(m_source.get(1)))
+ if (m_source->isPastEndOfInput() || !isDecimalDigit(m_source->get(1)))
{
// A '.' has to be followed by a number.
literal.complete();
@@ -854,7 +861,7 @@ Token Scanner::scanNumber(char _charSeen)
solAssert(kind != HEX, "'e'/'E' must be scanned as part of the hex number");
if (kind != DECIMAL)
return setError(ScannerError::IllegalExponent);
- else if (!m_source.isPastEndOfInput(1) && m_source.get(1) == '_')
+ else if (!m_source->isPastEndOfInput(1) && m_source->get(1) == '_')
{
// Recover from wrongly placed underscore as delimiter in literal with scientific
// notation by consuming until the end.
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
diff --git a/liblangutil/SourceLocation.h b/liblangutil/SourceLocation.h
index eeb81e94..2dfd7123 100644
--- a/liblangutil/SourceLocation.h
+++ b/liblangutil/SourceLocation.h
@@ -23,6 +23,7 @@
#pragma once
#include <libdevcore/Common.h> // defines noexcept macro for MSVC
+#include <liblangutil/CharStream.h>
#include <memory>
#include <string>
#include <ostream>
@@ -37,13 +38,13 @@ namespace langutil
*/
struct SourceLocation
{
- SourceLocation(): start(-1), end(-1) { }
- SourceLocation(int _start, int _end, std::shared_ptr<std::string const> _sourceName):
- start(_start), end(_end), sourceName(_sourceName) { }
+ SourceLocation(): start(-1), end(-1), source{nullptr} { }
+ SourceLocation(int _start, int _end, std::shared_ptr<CharStream> _source):
+ start(_start), end(_end), source{std::move(_source)} { }
SourceLocation(SourceLocation&& _other) noexcept:
start(_other.start),
end(_other.end),
- sourceName(std::move(_other.sourceName))
+ source{std::move(_other.source)}
{}
SourceLocation(SourceLocation const&) = default;
SourceLocation& operator=(SourceLocation const&) = default;
@@ -51,14 +52,15 @@ struct SourceLocation
{
start = _other.start;
end = _other.end;
- sourceName = std::move(_other.sourceName);
+ source = std::move(_other.source);
return *this;
}
bool operator==(SourceLocation const& _other) const
{
return start == _other.start && end == _other.end &&
- ((!sourceName && !_other.sourceName) || (sourceName && _other.sourceName && *sourceName == *_other.sourceName));
+ ((!source.get() && !_other.source.get()) ||
+ (source.get() && _other.source.get() && source->name() == _other.source->name()));
}
bool operator!=(SourceLocation const& _other) const { return !operator==(_other); }
inline bool operator<(SourceLocation const& _other) const;
@@ -69,7 +71,7 @@ struct SourceLocation
int start;
int end;
- std::shared_ptr<std::string const> sourceName;
+ std::shared_ptr<CharStream> source;
};
/// Stream output for Location (used e.g. in boost exceptions).
@@ -77,27 +79,33 @@ inline std::ostream& operator<<(std::ostream& _out, SourceLocation const& _locat
{
if (_location.isEmpty())
return _out << "NO_LOCATION_SPECIFIED";
- return _out << *_location.sourceName << "[" << _location.start << "," << _location.end << ")";
+
+ if (_location.source)
+ _out << _location.source->name();
+
+ _out << "[" << _location.start << "," << _location.end << ")";
+
+ return _out;
}
bool SourceLocation::operator<(SourceLocation const& _other) const
{
- if (!sourceName || !_other.sourceName)
- return std::make_tuple(int(!!sourceName), start, end) < std::make_tuple(int(!!_other.sourceName), _other.start, _other.end);
+ if (!source|| !_other.source)
+ return std::make_tuple(int(!!source), start, end) < std::make_tuple(int(!!_other.source), _other.start, _other.end);
else
- return std::make_tuple(*sourceName, start, end) < std::make_tuple(*_other.sourceName, _other.start, _other.end);
+ return std::make_tuple(source->name(), start, end) < std::make_tuple(_other.source->name(), _other.start, _other.end);
}
bool SourceLocation::contains(SourceLocation const& _other) const
{
- if (isEmpty() || _other.isEmpty() || ((!sourceName || !_other.sourceName || *sourceName != *_other.sourceName) && (sourceName || _other.sourceName)))
+ if (isEmpty() || _other.isEmpty() || ((!source || !_other.source || source->name() != _other.source->name()) && (source || _other.source)))
return false;
return start <= _other.start && _other.end <= end;
}
bool SourceLocation::intersects(SourceLocation const& _other) const
{
- if (isEmpty() || _other.isEmpty() || ((!sourceName || !_other.sourceName || *sourceName != *_other.sourceName) && (sourceName || _other.sourceName)))
+ if (isEmpty() || _other.isEmpty() || ((!source || !_other.source || source->name() != _other.source->name()) && (source || _other.source)))
return false;
return _other.start < end && start < _other.end;
}
diff --git a/liblangutil/SourceReferenceFormatter.cpp b/liblangutil/SourceReferenceFormatter.cpp
index 58a65521..8ac05b4e 100644
--- a/liblangutil/SourceReferenceFormatter.cpp
+++ b/liblangutil/SourceReferenceFormatter.cpp
@@ -30,9 +30,9 @@ using namespace langutil;
void SourceReferenceFormatter::printSourceLocation(SourceLocation const* _location)
{
- if (!_location || !_location->sourceName)
+ if (!_location || !_location->source)
return; // Nothing we can print here
- auto const& scanner = m_scannerFromSourceName(*_location->sourceName);
+ auto const& scanner = m_scannerFromSourceName(_location->source->name());
int startLine;
int startColumn;
tie(startLine, startColumn) = scanner.translatePositionToLineColumn(_location->start);
@@ -89,13 +89,13 @@ void SourceReferenceFormatter::printSourceLocation(SourceLocation const* _locati
void SourceReferenceFormatter::printSourceName(SourceLocation const* _location)
{
- if (!_location || !_location->sourceName)
+ if (!_location || !_location->source)
return; // Nothing we can print here
- auto const& scanner = m_scannerFromSourceName(*_location->sourceName);
+ auto const& scanner = m_scannerFromSourceName(_location->source->name());
int startLine;
int startColumn;
tie(startLine, startColumn) = scanner.translatePositionToLineColumn(_location->start);
- m_stream << *_location->sourceName << ":" << (startLine + 1) << ":" << (startColumn + 1) << ": ";
+ m_stream << _location->source->name() << ":" << (startLine + 1) << ":" << (startColumn + 1) << ": ";
}
void SourceReferenceFormatter::printExceptionInformation(
diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp
index e40a2c97..0528a200 100644
--- a/libsolidity/analysis/NameAndTypeResolver.cpp
+++ b/libsolidity/analysis/NameAndTypeResolver.cpp
@@ -492,9 +492,9 @@ bool DeclarationRegistrationHelper::registerDeclaration(
Declaration const* conflictingDeclaration = _container.conflictingDeclaration(_declaration, _name);
solAssert(conflictingDeclaration, "");
bool const comparable =
- _errorLocation->sourceName &&
- conflictingDeclaration->location().sourceName &&
- *_errorLocation->sourceName == *conflictingDeclaration->location().sourceName;
+ _errorLocation->source &&
+ conflictingDeclaration->location().source &&
+ _errorLocation->source->name() == conflictingDeclaration->location().source->name();
if (comparable && _errorLocation->start < conflictingDeclaration->location().start)
{
firstDeclarationLocation = *_errorLocation;
diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp
index b9054692..cfb13271 100644
--- a/libsolidity/ast/ASTJsonConverter.cpp
+++ b/libsolidity/ast/ASTJsonConverter.cpp
@@ -122,8 +122,8 @@ void ASTJsonConverter::setJsonNode(
string ASTJsonConverter::sourceLocationToString(SourceLocation const& _location) const
{
int sourceIndex{-1};
- if (_location.sourceName && m_sourceIndices.count(*_location.sourceName))
- sourceIndex = m_sourceIndices.at(*_location.sourceName);
+ if (_location.source && m_sourceIndices.count(_location.source->name()))
+ sourceIndex = m_sourceIndices.at(_location.source->name());
int length = -1;
if (_location.start >= 0 && _location.end >= 0)
length = _location.end - _location.start;
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp
index cc5a2102..58229379 100644
--- a/libsolidity/interface/CompilerStack.cpp
+++ b/libsolidity/interface/CompilerStack.cpp
@@ -598,8 +598,8 @@ tuple<int, int, int, int> CompilerStack::positionFromSourceLocation(SourceLocati
int startColumn;
int endLine;
int endColumn;
- tie(startLine, startColumn) = scanner(*_sourceLocation.sourceName).translatePositionToLineColumn(_sourceLocation.start);
- tie(endLine, endColumn) = scanner(*_sourceLocation.sourceName).translatePositionToLineColumn(_sourceLocation.end);
+ tie(startLine, startColumn) = scanner(_sourceLocation.source->name()).translatePositionToLineColumn(_sourceLocation.start);
+ tie(endLine, endColumn) = scanner(_sourceLocation.source->name()).translatePositionToLineColumn(_sourceLocation.end);
return make_tuple(++startLine, ++startColumn, ++endLine, ++endColumn);
}
@@ -922,8 +922,8 @@ string CompilerStack::computeSourceMapping(eth::AssemblyItems const& _items) con
SourceLocation const& location = item.location();
int length = location.start != -1 && location.end != -1 ? location.end - location.start : -1;
int sourceIndex =
- location.sourceName && sourceIndicesMap.count(*location.sourceName) ?
- sourceIndicesMap.at(*location.sourceName) :
+ location.source && sourceIndicesMap.count(location.source->name()) ?
+ sourceIndicesMap.at(location.source->name()) :
-1;
char jump = '-';
if (item.getJumpType() == eth::AssemblyItem::JumpType::IntoFunction)
diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp
index 4a32d9f3..0eef50d2 100644
--- a/libsolidity/interface/StandardCompiler.cpp
+++ b/libsolidity/interface/StandardCompiler.cpp
@@ -85,9 +85,9 @@ Json::Value formatErrorWithException(
message = _message;
Json::Value sourceLocation;
- if (location && location->sourceName)
+ if (location && location->source && location->source->name() != "")
{
- sourceLocation["file"] = *location->sourceName;
+ sourceLocation["file"] = location->source->name();
sourceLocation["start"] = location->start;
sourceLocation["end"] = location->end;
}
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp
index 3f4a015b..6cab7be3 100644
--- a/libsolidity/parsing/Parser.cpp
+++ b/libsolidity/parsing/Parser.cpp
@@ -42,7 +42,7 @@ class Parser::ASTNodeFactory
{
public:
explicit ASTNodeFactory(Parser const& _parser):
- m_parser(_parser), m_location(_parser.position(), -1, _parser.sourceName()) {}
+ m_parser(_parser), m_location(_parser.position(), -1, _parser.source()) {}
ASTNodeFactory(Parser const& _parser, ASTPointer<ASTNode> const& _childNode):
m_parser(_parser), m_location(_childNode->location()) {}
@@ -55,7 +55,7 @@ public:
template <class NodeType, typename... Args>
ASTPointer<NodeType> createNode(Args&& ... _args)
{
- solAssert(m_location.sourceName, "");
+ solAssert(m_location.source, "");
if (m_location.end < 0)
markEndPosition();
return make_shared<NodeType>(m_location, std::forward<Args>(_args)...);
diff --git a/libyul/AsmParser.h b/libyul/AsmParser.h
index cea3b667..52166a20 100644
--- a/libyul/AsmParser.h
+++ b/libyul/AsmParser.h
@@ -56,11 +56,11 @@ protected:
r.location.start = position();
r.location.end = endPosition();
}
- if (!r.location.sourceName)
- r.location.sourceName = sourceName();
+ if (!r.location.source)
+ r.location.source = m_scanner->charStream();
return r;
}
- langutil::SourceLocation location() const { return {position(), endPosition(), sourceName()}; }
+ langutil::SourceLocation location() const { return {position(), endPosition(), m_scanner->charStream()}; }
Block parseBlock();
Statement parseStatement();
diff --git a/test/libevmasm/Assembler.cpp b/test/libevmasm/Assembler.cpp
index 5ad01594..bece2be4 100644
--- a/test/libevmasm/Assembler.cpp
+++ b/test/libevmasm/Assembler.cpp
@@ -55,10 +55,12 @@ BOOST_AUTO_TEST_SUITE(Assembler)
BOOST_AUTO_TEST_CASE(all_assembly_items)
{
Assembly _assembly;
- _assembly.setSourceLocation(SourceLocation(1, 3, make_shared<string>("root.asm")));
+ auto root_asm = make_shared<CharStream>("", "root.asm");
+ _assembly.setSourceLocation(SourceLocation(1, 3, root_asm));
Assembly _subAsm;
- _subAsm.setSourceLocation(SourceLocation(6, 8, make_shared<string>("sub.asm")));
+ auto sub_asm = make_shared<CharStream>("", "sub.asm");
+ _subAsm.setSourceLocation(SourceLocation(6, 8, sub_asm));
_subAsm.append(Instruction::INVALID);
shared_ptr<Assembly> _subAsmPtr = make_shared<Assembly>(_subAsm);
diff --git a/test/libevmasm/Optimiser.cpp b/test/libevmasm/Optimiser.cpp
index c061b783..7d102948 100644
--- a/test/libevmasm/Optimiser.cpp
+++ b/test/libevmasm/Optimiser.cpp
@@ -53,7 +53,7 @@ namespace
// add dummy locations to each item so that we can check that they are not deleted
AssemblyItems input = _input;
for (AssemblyItem& item: input)
- item.setLocation(SourceLocation(1, 3, make_shared<string>("")));
+ item.setLocation(SourceLocation(1, 3, nullptr));
return input;
}
diff --git a/test/liblangutil/SourceLocation.cpp b/test/liblangutil/SourceLocation.cpp
index ac7a2173..ef4103da 100644
--- a/test/liblangutil/SourceLocation.cpp
+++ b/test/liblangutil/SourceLocation.cpp
@@ -33,12 +33,16 @@ BOOST_AUTO_TEST_SUITE(SourceLocationTest)
BOOST_AUTO_TEST_CASE(test_fail)
{
+ auto const source = std::make_shared<CharStream>("", "source");
+ auto const sourceA = std::make_shared<CharStream>("", "sourceA");
+ auto const sourceB = std::make_shared<CharStream>("", "sourceB");
+
BOOST_CHECK(SourceLocation() == SourceLocation());
- BOOST_CHECK(SourceLocation(0, 3, std::make_shared<std::string>("sourceA")) != SourceLocation(0, 3, std::make_shared<std::string>("sourceB")));
- BOOST_CHECK(SourceLocation(0, 3, std::make_shared<std::string>("source")) == SourceLocation(0, 3, std::make_shared<std::string>("source")));
- BOOST_CHECK(SourceLocation(3, 7, std::make_shared<std::string>("source")).contains(SourceLocation(4, 6, std::make_shared<std::string>("source"))));
- BOOST_CHECK(!SourceLocation(3, 7, std::make_shared<std::string>("sourceA")).contains(SourceLocation(4, 6, std::make_shared<std::string>("sourceB"))));
- BOOST_CHECK(SourceLocation(3, 7, std::make_shared<std::string>("sourceA")) < SourceLocation(4, 6, std::make_shared<std::string>("sourceB")));
+ BOOST_CHECK(SourceLocation(0, 3, sourceA) != SourceLocation(0, 3, sourceB));
+ BOOST_CHECK(SourceLocation(0, 3, source) == SourceLocation(0, 3, source));
+ BOOST_CHECK(SourceLocation(3, 7, source).contains(SourceLocation(4, 6, source)));
+ BOOST_CHECK(!SourceLocation(3, 7, sourceA).contains(SourceLocation(4, 6, sourceB)));
+ BOOST_CHECK(SourceLocation(3, 7, sourceA) < SourceLocation(4, 6, sourceB));
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/libsolidity/Assembly.cpp b/test/libsolidity/Assembly.cpp
index 620f9661..004917d4 100644
--- a/test/libsolidity/Assembly.cpp
+++ b/test/libsolidity/Assembly.cpp
@@ -52,13 +52,13 @@ namespace test
namespace
{
-eth::AssemblyItems compileContract(string const& _sourceCode)
+eth::AssemblyItems compileContract(std::shared_ptr<CharStream> _sourceCode)
{
ErrorList errors;
ErrorReporter errorReporter(errors);
Parser parser(errorReporter);
ASTPointer<SourceUnit> sourceUnit;
- BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared<Scanner>(CharStream(_sourceCode, ""))));
+ BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared<Scanner>(_sourceCode)));
BOOST_CHECK(!!sourceUnit);
map<ASTNode const*, shared_ptr<DeclarationContainer>> scopes;
@@ -104,7 +104,7 @@ void printAssemblyLocations(AssemblyItems const& _items)
", " <<
_loc.end <<
", make_shared<string>(\"" <<
- *_loc.sourceName <<
+ _loc.source->name() <<
"\"))) +" << endl;
};
@@ -151,29 +151,32 @@ BOOST_AUTO_TEST_SUITE(Assembly)
BOOST_AUTO_TEST_CASE(location_test)
{
- char const* sourceCode = R"(
+ auto sourceCode = make_shared<CharStream>(R"(
contract test {
function f() public returns (uint256 a) {
return 16;
}
}
- )";
+ )", "");
AssemblyItems items = compileContract(sourceCode);
bool hasShifts = dev::test::Options::get().evmVersion().hasBitwiseShifting();
+
+ auto codegenCharStream = make_shared<CharStream>("", "--CODEGEN--");
+
vector<SourceLocation> locations =
- vector<SourceLocation>(hasShifts ? 21 : 22, SourceLocation(2, 82, make_shared<string>(""))) +
- vector<SourceLocation>(2, SourceLocation(20, 79, make_shared<string>(""))) +
- vector<SourceLocation>(1, SourceLocation(8, 17, make_shared<string>("--CODEGEN--"))) +
- vector<SourceLocation>(3, SourceLocation(5, 7, make_shared<string>("--CODEGEN--"))) +
- vector<SourceLocation>(1, SourceLocation(30, 31, make_shared<string>("--CODEGEN--"))) +
- vector<SourceLocation>(1, SourceLocation(27, 28, make_shared<string>("--CODEGEN--"))) +
- vector<SourceLocation>(1, SourceLocation(20, 32, make_shared<string>("--CODEGEN--"))) +
- vector<SourceLocation>(1, SourceLocation(5, 7, make_shared<string>("--CODEGEN--"))) +
- vector<SourceLocation>(24, SourceLocation(20, 79, make_shared<string>(""))) +
- vector<SourceLocation>(1, SourceLocation(49, 58, make_shared<string>(""))) +
- vector<SourceLocation>(1, SourceLocation(72, 74, make_shared<string>(""))) +
- vector<SourceLocation>(2, SourceLocation(65, 74, make_shared<string>(""))) +
- vector<SourceLocation>(2, SourceLocation(20, 79, make_shared<string>("")));
+ vector<SourceLocation>(hasShifts ? 21 : 22, SourceLocation(2, 82, sourceCode)) +
+ vector<SourceLocation>(2, SourceLocation(20, 79, sourceCode)) +
+ vector<SourceLocation>(1, SourceLocation(8, 17, codegenCharStream)) +
+ vector<SourceLocation>(3, SourceLocation(5, 7, codegenCharStream)) +
+ vector<SourceLocation>(1, SourceLocation(30, 31, codegenCharStream)) +
+ vector<SourceLocation>(1, SourceLocation(27, 28, codegenCharStream)) +
+ vector<SourceLocation>(1, SourceLocation(20, 32, codegenCharStream)) +
+ vector<SourceLocation>(1, SourceLocation(5, 7, codegenCharStream)) +
+ vector<SourceLocation>(24, SourceLocation(20, 79, sourceCode)) +
+ vector<SourceLocation>(1, SourceLocation(49, 58, sourceCode)) +
+ vector<SourceLocation>(1, SourceLocation(72, 74, sourceCode)) +
+ vector<SourceLocation>(2, SourceLocation(65, 74, sourceCode)) +
+ vector<SourceLocation>(2, SourceLocation(20, 79, sourceCode));
checkAssemblyLocations(items, locations);
}