/src/solidity/libsolidity/analysis/GlobalContext.h
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 | | * @author Christian <c@ethdev.com> |
20 | | * @date 2014 |
21 | | * Container of the (implicit and explicit) global objects. |
22 | | */ |
23 | | |
24 | | #pragma once |
25 | | |
26 | | #include <liblangutil/EVMVersion.h> |
27 | | #include <libsolidity/ast/ASTForward.h> |
28 | | #include <map> |
29 | | #include <memory> |
30 | | #include <string> |
31 | | #include <vector> |
32 | | |
33 | | namespace solidity::frontend |
34 | | { |
35 | | |
36 | | class Type; // forward |
37 | | |
38 | | /** |
39 | | * Container for all global objects which look like AST nodes, but are not part of the AST |
40 | | * that is currently being compiled. |
41 | | * @note must not be destroyed or moved during compilation as its objects can be referenced from |
42 | | * other objects. |
43 | | */ |
44 | | class GlobalContext |
45 | | { |
46 | | public: |
47 | | /// Noncopyable. |
48 | | GlobalContext(GlobalContext const&) = delete; |
49 | | GlobalContext& operator=(GlobalContext const&) = delete; |
50 | | |
51 | | GlobalContext(langutil::EVMVersion _evmVersion); |
52 | | void setCurrentContract(ContractDefinition const& _contract); |
53 | 55.1k | void resetCurrentContract() { m_currentContract = nullptr; } |
54 | | MagicVariableDeclaration const* currentThis() const; |
55 | | MagicVariableDeclaration const* currentSuper() const; |
56 | | |
57 | | /// @returns a vector of all implicit global declarations excluding "this". |
58 | | std::vector<Declaration const*> declarations() const; |
59 | | |
60 | | private: |
61 | | std::vector<std::shared_ptr<MagicVariableDeclaration const>> m_magicVariables; |
62 | | ContractDefinition const* m_currentContract = nullptr; |
63 | | std::map<ContractDefinition const*, std::shared_ptr<MagicVariableDeclaration const>> mutable m_thisPointer; |
64 | | std::map<ContractDefinition const*, std::shared_ptr<MagicVariableDeclaration const>> mutable m_superPointer; |
65 | | }; |
66 | | |
67 | | } |