2018-11-26 23:21:53 +00:00
|
|
|
/*
|
|
|
|
This file is part of solidity.
|
|
|
|
|
|
|
|
solidity is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
solidity is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-07-17 14:54:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
2018-11-26 23:21:53 +00:00
|
|
|
/**
|
|
|
|
* Formatting functions for errors referencing positions and locations in the source.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <liblangutil/SourceReferenceExtractor.h>
|
|
|
|
#include <liblangutil/SourceReferenceFormatter.h> // SourceReferenceFormatterBase
|
|
|
|
|
2020-01-06 10:52:23 +00:00
|
|
|
#include <libsolutil/AnsiColorized.h>
|
2018-11-26 23:21:53 +00:00
|
|
|
|
|
|
|
#include <ostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <functional>
|
|
|
|
|
2019-12-11 16:31:36 +00:00
|
|
|
namespace solidity::langutil
|
2018-11-26 23:21:53 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
class SourceReferenceFormatterHuman: public SourceReferenceFormatter
|
|
|
|
{
|
|
|
|
public:
|
2020-06-04 01:19:47 +00:00
|
|
|
SourceReferenceFormatterHuman(std::ostream& _stream, bool _colored, bool _withErrorIds):
|
|
|
|
SourceReferenceFormatter{_stream}, m_colored{_colored}, m_withErrorIds(_withErrorIds)
|
2018-11-26 23:21:53 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
void printSourceLocation(SourceReference const& _ref) override;
|
|
|
|
void printExceptionInformation(SourceReferenceExtractor::Message const& _msg) override;
|
|
|
|
using SourceReferenceFormatter::printExceptionInformation;
|
|
|
|
|
|
|
|
static std::string formatExceptionInformation(
|
2019-12-11 16:31:36 +00:00
|
|
|
util::Exception const& _exception,
|
2018-11-26 23:21:53 +00:00
|
|
|
std::string const& _name,
|
2020-06-04 01:19:47 +00:00
|
|
|
bool _colored = false,
|
|
|
|
bool _withErrorIds = false
|
2018-11-26 23:21:53 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
std::ostringstream errorOutput;
|
|
|
|
|
2020-06-04 01:19:47 +00:00
|
|
|
SourceReferenceFormatterHuman formatter(errorOutput, _colored, _withErrorIds);
|
2018-11-26 23:21:53 +00:00
|
|
|
formatter.printExceptionInformation(_exception, _name);
|
|
|
|
return errorOutput.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-12-11 16:31:36 +00:00
|
|
|
util::AnsiColorized normalColored() const;
|
|
|
|
util::AnsiColorized frameColored() const;
|
|
|
|
util::AnsiColorized errorColored() const;
|
|
|
|
util::AnsiColorized messageColored() const;
|
|
|
|
util::AnsiColorized secondaryColored() const;
|
|
|
|
util::AnsiColorized highlightColored() const;
|
|
|
|
util::AnsiColorized diagColored() const;
|
2018-11-26 23:21:53 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_colored;
|
2020-06-04 01:19:47 +00:00
|
|
|
bool m_withErrorIds;
|
2018-11-26 23:21:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|