mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Remove CharStream from SourceLocation.
This commit is contained in:
@@ -16,8 +16,9 @@
|
||||
*/
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
#include <liblangutil/SourceReferenceExtractor.h>
|
||||
#include <liblangutil/CharStream.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
#include <liblangutil/CharStreamProvider.h>
|
||||
#include <liblangutil/CharStream.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
@@ -26,46 +27,57 @@ using namespace std;
|
||||
using namespace solidity;
|
||||
using namespace solidity::langutil;
|
||||
|
||||
SourceReferenceExtractor::Message SourceReferenceExtractor::extract(util::Exception const& _exception, string _category)
|
||||
SourceReferenceExtractor::Message SourceReferenceExtractor::extract(
|
||||
CharStreamProvider const& _charStreamProvider,
|
||||
util::Exception const& _exception,
|
||||
string _category
|
||||
)
|
||||
{
|
||||
SourceLocation const* location = boost::get_error_info<errinfo_sourceLocation>(_exception);
|
||||
|
||||
string const* message = boost::get_error_info<util::errinfo_comment>(_exception);
|
||||
SourceReference primary = extract(location, message ? *message : "");
|
||||
SourceReference primary = extract(_charStreamProvider, location, message ? *message : "");
|
||||
|
||||
std::vector<SourceReference> secondary;
|
||||
auto secondaryLocation = boost::get_error_info<errinfo_secondarySourceLocation>(_exception);
|
||||
if (secondaryLocation && !secondaryLocation->infos.empty())
|
||||
for (auto const& info: secondaryLocation->infos)
|
||||
secondary.emplace_back(extract(&info.second, info.first));
|
||||
secondary.emplace_back(extract(_charStreamProvider, &info.second, info.first));
|
||||
|
||||
return Message{std::move(primary), _category, std::move(secondary), nullopt};
|
||||
}
|
||||
|
||||
SourceReferenceExtractor::Message SourceReferenceExtractor::extract(Error const& _error)
|
||||
SourceReferenceExtractor::Message SourceReferenceExtractor::extract(
|
||||
CharStreamProvider const& _charStreamProvider,
|
||||
Error const& _error
|
||||
)
|
||||
{
|
||||
string category = (_error.type() == Error::Type::Warning) ? "Warning" : "Error";
|
||||
Message message = extract(_error, category);
|
||||
Message message = extract(_charStreamProvider, _error, category);
|
||||
message.errorId = _error.errorId();
|
||||
return message;
|
||||
}
|
||||
|
||||
SourceReference SourceReferenceExtractor::extract(SourceLocation const* _location, std::string message)
|
||||
SourceReference SourceReferenceExtractor::extract(
|
||||
CharStreamProvider const& _charStreamProvider,
|
||||
SourceLocation const* _location,
|
||||
std::string message
|
||||
)
|
||||
{
|
||||
if (!_location || !_location->source.get()) // Nothing we can extract here
|
||||
if (!_location || !_location->sourceName) // Nothing we can extract here
|
||||
return SourceReference::MessageOnly(std::move(message));
|
||||
|
||||
if (!_location->hasText()) // No source text, so we can only extract the source name
|
||||
return SourceReference::MessageOnly(std::move(message), _location->source->name());
|
||||
return SourceReference::MessageOnly(std::move(message), *_location->sourceName);
|
||||
|
||||
shared_ptr<CharStream> const& source = _location->source;
|
||||
CharStream const& charStream = _charStreamProvider.charStream(*_location->sourceName);
|
||||
|
||||
LineColumn const interest = source->translatePositionToLineColumn(_location->start);
|
||||
LineColumn const interest = charStream.translatePositionToLineColumn(_location->start);
|
||||
LineColumn start = interest;
|
||||
LineColumn end = source->translatePositionToLineColumn(_location->end);
|
||||
LineColumn end = charStream.translatePositionToLineColumn(_location->end);
|
||||
bool const isMultiline = start.line != end.line;
|
||||
|
||||
string line = source->lineAtPosition(_location->start);
|
||||
string line = charStream.lineAtPosition(_location->start);
|
||||
|
||||
int locationLength =
|
||||
isMultiline ?
|
||||
@@ -102,7 +114,7 @@ SourceReference SourceReferenceExtractor::extract(SourceLocation const* _locatio
|
||||
|
||||
return SourceReference{
|
||||
std::move(message),
|
||||
source->name(),
|
||||
*_location->sourceName,
|
||||
interest,
|
||||
isMultiline,
|
||||
line,
|
||||
|
||||
Reference in New Issue
Block a user