2021-08-27 09:40:20 +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/>.
|
|
|
|
*/
|
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <liblangutil/ErrorReporter.h>
|
|
|
|
#include <liblangutil/Exceptions.h>
|
|
|
|
|
|
|
|
namespace solidity::langutil
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wrapper for ErrorReporter that removes duplicates.
|
|
|
|
* Two errors are considered the same if their error ID and location are the same.
|
|
|
|
*/
|
|
|
|
class UniqueErrorReporter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UniqueErrorReporter(): m_errorReporter(m_uniqueErrors) {}
|
|
|
|
|
2023-03-06 13:19:58 +00:00
|
|
|
void append(UniqueErrorReporter const& _other)
|
|
|
|
{
|
|
|
|
m_errorReporter.append(_other.m_errorReporter.errors());
|
|
|
|
}
|
|
|
|
|
2021-08-27 09:40:20 +00:00
|
|
|
void warning(ErrorId _error, SourceLocation const& _location, std::string const& _description)
|
|
|
|
{
|
|
|
|
if (!seen(_error, _location, _description))
|
|
|
|
{
|
|
|
|
m_errorReporter.warning(_error, _location, _description);
|
|
|
|
markAsSeen(_error, _location, _description);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void warning(
|
|
|
|
ErrorId _error,
|
|
|
|
SourceLocation const& _location,
|
|
|
|
std::string const& _description,
|
|
|
|
SecondarySourceLocation const& _secondaryLocation
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (!seen(_error, _location, _description))
|
|
|
|
{
|
|
|
|
m_errorReporter.warning(_error, _location, _description, _secondaryLocation);
|
|
|
|
markAsSeen(_error, _location, _description);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void warning(ErrorId _error, std::string const& _description)
|
|
|
|
{
|
2021-09-06 20:23:24 +00:00
|
|
|
m_errorReporter.warning(_error, _description);
|
2021-08-27 09:40:20 +00:00
|
|
|
}
|
|
|
|
|
2021-10-06 09:42:05 +00:00
|
|
|
void info(ErrorId _error, SourceLocation const& _location, std::string const& _description)
|
|
|
|
{
|
|
|
|
if (!seen(_error, _location, _description))
|
|
|
|
{
|
|
|
|
m_errorReporter.info(_error, _location, _description);
|
|
|
|
markAsSeen(_error, _location, _description);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void info(ErrorId _error, std::string const& _description)
|
|
|
|
{
|
|
|
|
m_errorReporter.info(_error, _description);
|
|
|
|
}
|
|
|
|
|
2021-08-27 09:40:20 +00:00
|
|
|
bool seen(ErrorId _error, SourceLocation const& _location, std::string const& _description) const
|
|
|
|
{
|
|
|
|
if (m_seenErrors.count({_error, _location}))
|
|
|
|
{
|
|
|
|
solAssert(m_seenErrors.at({_error, _location}) == _description, "");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void markAsSeen(ErrorId _error, SourceLocation const& _location, std::string const& _description)
|
|
|
|
{
|
2021-09-06 20:23:24 +00:00
|
|
|
if (_location != SourceLocation{})
|
|
|
|
m_seenErrors[{_error, _location}] = _description;
|
2021-08-27 09:40:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ErrorList const& errors() const { return m_errorReporter.errors(); }
|
|
|
|
|
|
|
|
void clear() { m_errorReporter.clear(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
ErrorList m_uniqueErrors;
|
2022-05-11 11:40:02 +00:00
|
|
|
ErrorReporter m_errorReporter;
|
2021-08-27 09:40:20 +00:00
|
|
|
std::map<std::pair<ErrorId, SourceLocation>, std::string> m_seenErrors;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|