@@ -63,14 +63,21 @@ int magicVariableToID(std::string const& _name)
6363 else
6464 solAssert (false , " Unknown magic variable: \" " + _name + " \" ." );
6565}
66+ }
6667
67- inline std::vector<std::shared_ptr<MagicVariableDeclaration const >> constructMagicVariables ()
68+ GlobalContext::GlobalContext (langutil::EVMVersion _evmVersion):
69+ m_evmVersion (_evmVersion),
70+ m_magicVariables{constructMagicVariables ()}
6871{
69- static auto const magicVarDecl = [](std::string const & _name, Type const * _type) {
72+ }
73+
74+ std::vector<std::shared_ptr<MagicVariableDeclaration const >> GlobalContext::constructMagicVariables () const
75+ {
76+ static auto const magicVarDecl = [&](std::string const & _name, Type const * _type) {
7077 return std::make_shared<MagicVariableDeclaration>(magicVariableToID (_name), _name, _type);
7178 };
7279
73- return {
80+ std::vector<std::shared_ptr<MagicVariableDeclaration const >> magicVariableDeclarations = {
7481 magicVarDecl (" abi" , TypeProvider::magic (MagicType::Kind::ABI)),
7582 magicVarDecl (" addmod" , TypeProvider::function (strings{" uint256" , " uint256" , " uint256" }, strings{" uint256" }, FunctionType::Kind::AddMod, StateMutability::Pure)),
7683 magicVarDecl (" assert" , TypeProvider::function (strings{" bool" }, strings{}, FunctionType::Kind::Assert, StateMutability::Pure)),
@@ -92,7 +99,6 @@ inline std::vector<std::shared_ptr<MagicVariableDeclaration const>> constructMag
9299 magicVarDecl (" sha3" , TypeProvider::function (strings{" bytes memory" }, strings{" bytes32" }, FunctionType::Kind::KECCAK256, StateMutability::Pure)),
93100 magicVarDecl (" suicide" , TypeProvider::function (strings{" address payable" }, strings{}, FunctionType::Kind::Selfdestruct)),
94101 magicVarDecl (" tx" , TypeProvider::magic (MagicType::Kind::Transaction)),
95- magicVarDecl (" blobhash" , TypeProvider::function (strings{" uint256" }, strings{" bytes32" }, FunctionType::Kind::BlobHash, StateMutability::View)),
96102 // Accepts a MagicType that can be any contract type or an Integer type and returns a
97103 // MagicType. The TypeChecker handles the correctness of the input and output types.
98104 magicVarDecl (" type" , TypeProvider::function (
@@ -103,12 +109,13 @@ inline std::vector<std::shared_ptr<MagicVariableDeclaration const>> constructMag
103109 FunctionType::Options::withArbitraryParameters ()
104110 )),
105111 };
106- }
107112
108- }
113+ if (m_evmVersion >= langutil::EVMVersion::cancun ())
114+ magicVariableDeclarations.push_back (
115+ magicVarDecl (" blobhash" , TypeProvider::function (strings{" uint256" }, strings{" bytes32" }, FunctionType::Kind::BlobHash, StateMutability::View))
116+ );
109117
110- GlobalContext::GlobalContext (): m_magicVariables{constructMagicVariables ()}
111- {
118+ return magicVariableDeclarations;
112119}
113120
114121void GlobalContext::setCurrentContract (ContractDefinition const & _contract)
0 commit comments