Coverage Report

Created: 2022-08-24 06:39

/src/solidity/liblangutil/Exceptions.cpp
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
/**
19
 * @author Liana <liana@ethdev.com>
20
 * @date 2015
21
 * Solidity exception hierarchy.
22
 */
23
24
#include <liblangutil/Exceptions.h>
25
26
#include <boost/algorithm/string/case_conv.hpp>
27
#include <boost/algorithm/string/trim.hpp>
28
29
using namespace std;
30
using namespace solidity;
31
using namespace solidity::langutil;
32
33
Error::Error(
34
  ErrorId _errorId, Error::Type _type,
35
  std::string const& _description,
36
  SourceLocation const& _location,
37
  SecondarySourceLocation const& _secondaryLocation
38
):
39
  m_errorId(_errorId),
40
  m_type(_type)
41
4.25k
{
42
4.25k
  switch (m_type)
43
4.25k
  {
44
0
  case Type::CodeGenerationError:
45
0
    m_typeName = "CodeGenerationError";
46
0
    break;
47
0
  case Type::DeclarationError:
48
0
    m_typeName = "DeclarationError";
49
0
    break;
50
0
  case Type::DocstringParsingError:
51
0
    m_typeName = "DocstringParsingError";
52
0
    break;
53
0
  case Type::Info:
54
0
    m_typeName = "Info";
55
0
    break;
56
0
  case Type::ParserError:
57
0
    m_typeName = "ParserError";
58
0
    break;
59
0
  case Type::SyntaxError:
60
0
    m_typeName = "SyntaxError";
61
0
    break;
62
0
  case Type::TypeError:
63
0
    m_typeName = "TypeError";
64
0
    break;
65
4.25k
  case Type::Warning:
66
4.25k
    m_typeName = "Warning";
67
4.25k
    break;
68
4.25k
  }
69
70
4.25k
  if (_location.isValid())
71
4.25k
    *this << errinfo_sourceLocation(_location);
72
4.25k
  if (!_secondaryLocation.infos.empty())
73
0
    *this << errinfo_secondarySourceLocation(_secondaryLocation);
74
4.25k
  if (!_description.empty())
75
4.25k
    *this << util::errinfo_comment(_description);
76
4.25k
}
Unexecuted instantiation: solidity::langutil::Error::Error(solidity::langutil::ErrorId, solidity::langutil::Error::Type, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, solidity::langutil::SourceLocation const&, solidity::langutil::SecondarySourceLocation const&)
solidity::langutil::Error::Error(solidity::langutil::ErrorId, solidity::langutil::Error::Type, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, solidity::langutil::SourceLocation const&, solidity::langutil::SecondarySourceLocation const&)
Line
Count
Source
41
4.25k
{
42
4.25k
  switch (m_type)
43
4.25k
  {
44
0
  case Type::CodeGenerationError:
45
0
    m_typeName = "CodeGenerationError";
46
0
    break;
47
0
  case Type::DeclarationError:
48
0
    m_typeName = "DeclarationError";
49
0
    break;
50
0
  case Type::DocstringParsingError:
51
0
    m_typeName = "DocstringParsingError";
52
0
    break;
53
0
  case Type::Info:
54
0
    m_typeName = "Info";
55
0
    break;
56
0
  case Type::ParserError:
57
0
    m_typeName = "ParserError";
58
0
    break;
59
0
  case Type::SyntaxError:
60
0
    m_typeName = "SyntaxError";
61
0
    break;
62
0
  case Type::TypeError:
63
0
    m_typeName = "TypeError";
64
0
    break;
65
4.25k
  case Type::Warning:
66
4.25k
    m_typeName = "Warning";
67
4.25k
    break;
68
4.25k
  }
69
70
4.25k
  if (_location.isValid())
71
4.25k
    *this << errinfo_sourceLocation(_location);
72
4.25k
  if (!_secondaryLocation.infos.empty())
73
0
    *this << errinfo_secondarySourceLocation(_secondaryLocation);
74
4.25k
  if (!_description.empty())
75
4.25k
    *this << util::errinfo_comment(_description);
76
4.25k
}
77
78
SourceLocation const* Error::sourceLocation() const noexcept
79
0
{
80
0
  return boost::get_error_info<errinfo_sourceLocation>(*this);
81
0
}
82
83
SecondarySourceLocation const* Error::secondarySourceLocation() const noexcept
84
0
{
85
0
  return boost::get_error_info<errinfo_secondarySourceLocation>(*this);
86
0
}
87
88
optional<Error::Severity> Error::severityFromString(string _input)
89
0
{
90
0
  boost::algorithm::to_lower(_input);
91
0
  boost::algorithm::trim(_input);
92
93
0
  for (Severity severity: {Severity::Error, Severity::Warning, Severity::Info})
94
0
    if (_input == formatErrorSeverityLowercase(severity))
95
0
      return severity;
96
97
0
  return nullopt;
98
0
}