2018-11-30 13:34:08 +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-30 13:34:08 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-06-04 01:19:47 +00:00
|
|
|
#include <liblangutil/Exceptions.h>
|
|
|
|
|
2018-11-30 13:34:08 +00:00
|
|
|
#include <iosfwd>
|
2020-06-04 01:19:47 +00:00
|
|
|
#include <optional>
|
2018-11-30 13:34:08 +00:00
|
|
|
#include <string>
|
|
|
|
#include <tuple>
|
|
|
|
#include <vector>
|
2022-09-06 10:12:15 +00:00
|
|
|
#include <variant>
|
2018-11-30 13:34:08 +00:00
|
|
|
|
2019-12-11 16:31:36 +00:00
|
|
|
namespace solidity::langutil
|
2018-11-30 13:34:08 +00:00
|
|
|
{
|
|
|
|
|
2021-06-29 12:38:59 +00:00
|
|
|
class CharStreamProvider;
|
|
|
|
|
2018-11-30 13:34:08 +00:00
|
|
|
struct SourceReference
|
|
|
|
{
|
2021-06-30 12:48:45 +00:00
|
|
|
std::string message; ///< A message that relates to this source reference (such as a warning, info or an error message).
|
2018-12-12 13:51:22 +00:00
|
|
|
std::string sourceName; ///< Underlying source name (for example the filename).
|
|
|
|
LineColumn position; ///< Actual (error) position this source reference is surrounding.
|
|
|
|
bool multiline = {false}; ///< Indicates whether the actual SourceReference is truncated to one line.
|
|
|
|
std::string text; ///< Extracted source code text (potentially truncated if multiline or too long).
|
|
|
|
int startColumn = {-1}; ///< Highlighting range-start of text field.
|
|
|
|
int endColumn = {-1}; ///< Highlighting range-end of text field.
|
2018-11-30 13:34:08 +00:00
|
|
|
|
|
|
|
/// Constructs a SourceReference containing a message only.
|
2020-01-09 13:18:54 +00:00
|
|
|
static SourceReference MessageOnly(std::string _msg, std::string _sourceName = {})
|
2018-11-30 13:34:08 +00:00
|
|
|
{
|
2018-12-12 13:51:22 +00:00
|
|
|
SourceReference sref;
|
|
|
|
sref.message = std::move(_msg);
|
2020-01-09 13:18:54 +00:00
|
|
|
sref.sourceName = std::move(_sourceName);
|
2018-12-12 13:51:22 +00:00
|
|
|
return sref;
|
2018-11-30 13:34:08 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace SourceReferenceExtractor
|
|
|
|
{
|
|
|
|
struct Message
|
|
|
|
{
|
|
|
|
SourceReference primary;
|
2022-09-06 10:12:15 +00:00
|
|
|
std::variant<Error::Type, Error::Severity> _typeOrSeverity;
|
2018-11-30 13:34:08 +00:00
|
|
|
std::vector<SourceReference> secondary;
|
2020-06-04 01:19:47 +00:00
|
|
|
std::optional<ErrorId> errorId;
|
2018-11-30 13:34:08 +00:00
|
|
|
};
|
|
|
|
|
2022-09-06 10:12:15 +00:00
|
|
|
Message extract(
|
|
|
|
CharStreamProvider const& _charStreamProvider,
|
|
|
|
util::Exception const& _exception,
|
|
|
|
std::variant<Error::Type, Error::Severity> _typeOrSeverity
|
|
|
|
);
|
|
|
|
Message extract(
|
|
|
|
CharStreamProvider const& _charStreamProvider,
|
|
|
|
Error const& _error,
|
|
|
|
std::variant<Error::Type, Error::Severity> _typeOrSeverity
|
|
|
|
);
|
2021-06-29 12:38:59 +00:00
|
|
|
Message extract(CharStreamProvider const& _charStreamProvider, Error const& _error);
|
|
|
|
SourceReference extract(CharStreamProvider const& _charStreamProvider, SourceLocation const* _location, std::string message = "");
|
2018-11-30 13:34:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|