Coverage Report

Created: 2025-06-24 07:59

/src/solidity/libsolidity/interface/ImportRemapper.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 <optional>
21
#include <string>
22
#include <vector>
23
24
namespace solidity::frontend
25
{
26
27
// Some helper typedefs to make reading the signatures more self explaining.
28
using SourceUnitName = std::string;
29
using SourceCode = std::string;
30
using ImportPath = std::string;
31
32
/// The ImportRemapper is being used on imported file paths for being remapped to source unit IDs before being loaded.
33
class ImportRemapper
34
{
35
public:
36
  struct Remapping
37
  {
38
0
    bool operator!=(Remapping const& _other) const noexcept { return !(*this == _other); }
39
    bool operator==(Remapping const& _other) const noexcept
40
0
    {
41
0
      return
42
0
        context == _other.context &&
43
0
        prefix == _other.prefix &&
44
0
        target == _other.target;
45
0
    }
46
47
    std::string context;
48
    std::string prefix;
49
    std::string target;
50
  };
51
52
0
  void clear() { m_remappings.clear(); }
53
54
  void setRemappings(std::vector<Remapping> _remappings);
55
16.4k
  std::vector<Remapping> const& remappings() const noexcept { return m_remappings; }
56
57
  SourceUnitName apply(ImportPath const& _path, std::string const& _context) const;
58
59
  /// @returns true if the string can be parsed as a remapping
60
  static bool isRemapping(std::string_view _input);
61
62
  /// Parses a remapping of the format "context:prefix=target".
63
  static std::optional<Remapping> parseRemapping(std::string_view _input);
64
65
private:
66
  /// list of path prefix remappings, e.g. mylibrary: github.com/ethereum = /usr/local/ethereum
67
  /// "context:prefix=target"
68
  std::vector<Remapping> m_remappings = {};
69
};
70
71
}