/src/solidity/libyul/optimiser/Disambiguator.cpp
Line | Count | Source |
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 | | * Optimiser component that makes all identifiers unique. |
20 | | */ |
21 | | |
22 | | #include <libyul/optimiser/Disambiguator.h> |
23 | | |
24 | | #include <libyul/AST.h> |
25 | | #include <libyul/Dialect.h> |
26 | | #include <libyul/Exceptions.h> |
27 | | #include <libyul/Scope.h> |
28 | | |
29 | | using namespace solidity; |
30 | | using namespace solidity::yul; |
31 | | using namespace solidity::util; |
32 | | |
33 | | YulName Disambiguator::translateIdentifier(YulName const _originalName) |
34 | 4.96M | { |
35 | 4.96M | if (m_externallyUsedIdentifiers.contains(_originalName)) |
36 | 6.82k | return _originalName; |
37 | | |
38 | 4.95M | assertThrow(!m_scopes.empty() && m_scopes.back(), OptimizerException, ""); |
39 | 4.95M | Scope::Identifier const* id = m_scopes.back()->lookup(_originalName); |
40 | 4.95M | assertThrow(id, OptimizerException, ""); |
41 | 4.95M | if (!m_translations.contains(id)) |
42 | 2.52M | m_translations[id] = m_nameDispenser.newName(_originalName); |
43 | 4.95M | return m_translations.at(id); |
44 | 4.96M | } |
45 | | |
46 | | void Disambiguator::enterScope(Block const& _block) |
47 | 1.51M | { |
48 | 1.51M | enterScopeInternal(*m_info.scopes.at(&_block)); |
49 | 1.51M | } |
50 | | |
51 | | void Disambiguator::leaveScope(Block const& _block) |
52 | 1.51M | { |
53 | 1.51M | leaveScopeInternal(*m_info.scopes.at(&_block)); |
54 | 1.51M | } |
55 | | |
56 | | void Disambiguator::enterFunction(FunctionDefinition const& _function) |
57 | 409k | { |
58 | 409k | enterScopeInternal(*m_info.scopes.at(m_info.virtualBlocks.at(&_function).get())); |
59 | 409k | } |
60 | | |
61 | | void Disambiguator::leaveFunction(FunctionDefinition const& _function) |
62 | 409k | { |
63 | 409k | leaveScopeInternal(*m_info.scopes.at(m_info.virtualBlocks.at(&_function).get())); |
64 | 409k | } |
65 | | |
66 | | void Disambiguator::enterScopeInternal(Scope& _scope) |
67 | 1.92M | { |
68 | 1.92M | m_scopes.push_back(&_scope); |
69 | 1.92M | } |
70 | | |
71 | | void Disambiguator::leaveScopeInternal(Scope& _scope) |
72 | 1.92M | { |
73 | 1.92M | assertThrow(!m_scopes.empty(), OptimizerException, ""); |
74 | 1.92M | assertThrow(m_scopes.back() == &_scope, OptimizerException, ""); |
75 | 1.92M | m_scopes.pop_back(); |
76 | 1.92M | } |