-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathconstant-evaluator.h
55 lines (42 loc) · 1.99 KB
/
constant-evaluator.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
/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "fwd-declarations.h"
#include "crypto/common/refint.h"
#include <variant>
namespace tolk {
class ConstantValue {
std::variant<
td::RefInt256, // is set for int, intN, coins, bool
std::string // is set for slice, bytesN
> value;
public:
ConstantValue() = default; // by default, not initialized
explicit ConstantValue(int value)
: value(td::make_refint(value)) {}
explicit ConstantValue(td::RefInt256 value)
: value(std::move(value)) {}
explicit ConstantValue(std::string value)
: value(std::move(value)) {}
bool initialized() const { return is_slice() || std::get<td::RefInt256>(value).not_null(); }
bool is_int() const { return std::holds_alternative<td::RefInt256>(value); }
bool is_slice() const { return std::holds_alternative<std::string>(value); }
td::RefInt256 as_int() const { return std::get<td::RefInt256>(value); }
const std::string& as_slice() const { return std::get<std::string>(value); }
};
ConstantValue eval_string_const_standalone(AnyExprV v_string);
ConstantValue eval_call_to_compile_time_function(AnyExprV v_call);
ConstantValue eval_expression_expected_to_be_constant(AnyExprV v);
void eval_and_assign_const_init_value(GlobalConstPtr const_ref);
} // namespace tolk