Coverage Report

Created: 2022-08-24 06:55

/src/solidity/liblangutil/CharStreamProvider.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
/**
19
 * Interface to retrieve the character stream by a source name.
20
 */
21
22
#pragma once
23
24
#include <liblangutil/CharStream.h>
25
#include <liblangutil/Exceptions.h>
26
27
#include <string>
28
29
namespace solidity::langutil
30
{
31
32
/**
33
 * Interface to retrieve a CharStream (source) from a source name.
34
 * Used especially for printing error information.
35
 */
36
class CharStreamProvider
37
{
38
public:
39
139k
  virtual ~CharStreamProvider() = default;
40
  virtual CharStream const& charStream(std::string const& _sourceName) const = 0;
41
};
42
43
class SingletonCharStreamProvider: public CharStreamProvider
44
{
45
public:
46
  explicit SingletonCharStreamProvider(CharStream const& _charStream):
47
0
    m_charStream(_charStream) {}
48
  CharStream const& charStream(std::string const& _sourceName) const override
49
0
  {
50
0
    solAssert(m_charStream.name() == _sourceName, "");
51
0
    return m_charStream;
52
0
  }
53
private:
54
  CharStream const& m_charStream;
55
};
56
57
}