/src/solidity/libyul/Dialect.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 | | * Yul dialect. |
20 | | */ |
21 | | |
22 | | #include <libyul/Dialect.h> |
23 | | #include <libyul/AST.h> |
24 | | |
25 | | using namespace solidity::yul; |
26 | | using namespace std; |
27 | | using namespace solidity::langutil; |
28 | | |
29 | | Literal Dialect::zeroLiteralForType(solidity::yul::YulString _type) const |
30 | 42.0k | { |
31 | 42.0k | if (_type == boolType && _type != defaultType) |
32 | 0 | return {DebugData::create(), LiteralKind::Boolean, "false"_yulstring, _type}; |
33 | 42.0k | return {DebugData::create(), LiteralKind::Number, "0"_yulstring, _type}; |
34 | 42.0k | } |
35 | | |
36 | | |
37 | | Literal Dialect::trueLiteral() const |
38 | 0 | { |
39 | 0 | if (boolType != defaultType) |
40 | 0 | return {DebugData::create(), LiteralKind::Boolean, "true"_yulstring, boolType}; |
41 | 0 | else |
42 | 0 | return {DebugData::create(), LiteralKind::Number, "1"_yulstring, defaultType}; |
43 | 0 | } |
44 | | |
45 | | bool Dialect::validTypeForLiteral(LiteralKind _kind, YulString, YulString _type) const |
46 | 1.06M | { |
47 | 1.06M | if (_kind == LiteralKind::Boolean) |
48 | 5.24k | return _type == boolType; |
49 | 1.05M | else |
50 | 1.05M | return true; |
51 | 1.06M | } |
52 | | |
53 | | Dialect const& Dialect::yulDeprecated() |
54 | 0 | { |
55 | 0 | static unique_ptr<Dialect> dialect; |
56 | 0 | static YulStringRepository::ResetCallback callback{[&] { dialect.reset(); }}; |
57 | |
|
58 | 0 | if (!dialect) |
59 | 0 | { |
60 | | // TODO will probably change, especially the list of types. |
61 | 0 | dialect = make_unique<Dialect>(); |
62 | 0 | dialect->defaultType = "u256"_yulstring; |
63 | 0 | dialect->boolType = "bool"_yulstring; |
64 | 0 | dialect->types = { |
65 | 0 | "bool"_yulstring, |
66 | 0 | "u8"_yulstring, |
67 | 0 | "s8"_yulstring, |
68 | 0 | "u32"_yulstring, |
69 | 0 | "s32"_yulstring, |
70 | 0 | "u64"_yulstring, |
71 | 0 | "s64"_yulstring, |
72 | 0 | "u128"_yulstring, |
73 | 0 | "s128"_yulstring, |
74 | 0 | "u256"_yulstring, |
75 | 0 | "s256"_yulstring |
76 | 0 | }; |
77 | 0 | }; |
78 | |
|
79 | 0 | return *dialect; |
80 | 0 | } |