Coverage Report

Created: 2025-06-24 07:59

/src/solidity/liblangutil/SourceReferenceExtractor.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
  This file is part of solidity.
3
4
  solidity is free software: you can redistribute it and/or modify
5
  it under the terms of the GNU General Public License as published by
6
  the Free Software Foundation, either version 3 of the License, or
7
  (at your option) any later version.
8
9
  solidity is distributed in the hope that it will be useful,
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
  GNU General Public License for more details.
13
14
  You should have received a copy of the GNU General Public License
15
  along with solidity.  If not, see <http://www.gnu.org/licenses/>.
16
*/
17
// SPDX-License-Identifier: GPL-3.0
18
#pragma once
19
20
#include <liblangutil/Exceptions.h>
21
22
#include <iosfwd>
23
#include <optional>
24
#include <string>
25
#include <tuple>
26
#include <vector>
27
#include <variant>
28
29
namespace solidity::langutil
30
{
31
32
class CharStreamProvider;
33
34
struct SourceReference
35
{
36
  std::string message;      ///< A message that relates to this source reference (such as a warning, info or an error message).
37
  std::string sourceName;   ///< Underlying source name (for example the filename).
38
  LineColumn position;      ///< Actual (error) position this source reference is surrounding.
39
  bool multiline = {false}; ///< Indicates whether the actual SourceReference is truncated to one line.
40
  std::string text;         ///< Extracted source code text (potentially truncated if multiline or too long).
41
  int startColumn = {-1};   ///< Highlighting range-start of text field.
42
  int endColumn = {-1};     ///< Highlighting range-end of text field.
43
44
  /// Constructs a SourceReference containing a message only.
45
  static SourceReference MessageOnly(std::string _msg, std::string _sourceName = {})
46
0
  {
47
0
    SourceReference sref;
48
0
    sref.message = std::move(_msg);
49
0
    sref.sourceName = std::move(_sourceName);
50
0
    return sref;
51
0
  }
52
};
53
54
namespace SourceReferenceExtractor
55
{
56
  struct Message
57
  {
58
    SourceReference primary;
59
    std::variant<Error::Type, Error::Severity> _typeOrSeverity;
60
    std::vector<SourceReference> secondary;
61
    std::optional<ErrorId> errorId;
62
  };
63
64
  Message extract(
65
    CharStreamProvider const& _charStreamProvider,
66
    util::Exception const& _exception,
67
    std::variant<Error::Type, Error::Severity> _typeOrSeverity
68
  );
69
  Message extract(
70
    CharStreamProvider const& _charStreamProvider,
71
    Error const& _error,
72
    std::variant<Error::Type, Error::Severity> _typeOrSeverity
73
  );
74
  Message extract(CharStreamProvider const& _charStreamProvider, Error const& _error);
75
  SourceReference extract(CharStreamProvider const& _charStreamProvider, SourceLocation const* _location, std::string message = "");
76
}
77
78
}