-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpgradeChange.h
79 lines (65 loc) · 2.3 KB
/
UpgradeChange.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
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/>.
*/
#pragma once
#include <libsolutil/AnsiColorized.h>
#include <liblangutil/SourceLocation.h>
#include <liblangutil/CharStreamProvider.h>
#include <algorithm>
#include <utility>
namespace solidity::tools
{
/**
* Models a single source code change, based on the initial source location
* and a patch, which needs to be applied.
* It implements the concept of level of confidence in the change and distiguishes
* safe from unsafe changes. A "safe" change is considered to not break
* compilation or change semantics. An "unsafe" change is considered to potentially
* change semantics or require further manual management.
*/
class UpgradeChange
{
public:
enum class Level
{
Safe,
Unsafe
};
UpgradeChange(
Level _level,
langutil::SourceLocation _location,
std::string _patch
):
m_location(_location),
m_patch(std::move(_patch)),
m_level(_level)
{}
~UpgradeChange() {}
langutil::SourceLocation const& location() const { return m_location; }
std::string patch() const { return m_patch; }
Level level() const { return m_level; }
/// Performs the actual replacement on the provided original source code
/// and returns the modified source code.
std::string apply(std::string _source) const;
/// Does a pretty-print of this upgrade change. Since the patch
/// can contain a lot of code lines, it can be shortened, which is signaled
/// by setting the flag.
void log(langutil::CharStreamProvider const& _charStreamProvider, bool const _shorten = true) const;
private:
langutil::SourceLocation m_location;
std::string m_patch;
Level m_level;
/// Shortens the given source to a constant limit.
static std::string shortenSource(std::string const& _source);
};
}