mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
experimental flag
This commit is contained in:
parent
3ed9a38abc
commit
e0727076d3
@ -65,19 +65,18 @@ int magicVariableToID(std::string const& _name)
|
||||
solAssert(false, "Unknown magic variable: \"" + _name + "\".");
|
||||
}
|
||||
|
||||
inline vector<shared_ptr<MagicVariableDeclaration const>> constructMagicVariables()
|
||||
inline vector<shared_ptr<MagicVariableDeclaration const>> constructMagicVariables(bool _stdlib)
|
||||
{
|
||||
static auto const magicVarDecl = [](string const& _name, Type const* _type) {
|
||||
return make_shared<MagicVariableDeclaration>(magicVariableToID(_name), _name, _type);
|
||||
};
|
||||
|
||||
return {
|
||||
vector<shared_ptr<MagicVariableDeclaration const>> list = {
|
||||
magicVarDecl("abi", TypeProvider::magic(MagicType::Kind::ABI)),
|
||||
magicVarDecl("addmod", TypeProvider::function(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::AddMod, StateMutability::Pure)),
|
||||
magicVarDecl("assert", TypeProvider::function(strings{"bool"}, strings{}, FunctionType::Kind::Assert, StateMutability::Pure)),
|
||||
magicVarDecl("block", TypeProvider::magic(MagicType::Kind::Block)),
|
||||
magicVarDecl("blockhash", TypeProvider::function(strings{"uint256"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, StateMutability::View)),
|
||||
magicVarDecl("ecrecover", TypeProvider::function(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Kind::ECRecover, StateMutability::Pure)),
|
||||
magicVarDecl("gasleft", TypeProvider::function(strings(), strings{"uint256"}, FunctionType::Kind::GasLeft, StateMutability::View)),
|
||||
magicVarDecl("keccak256", TypeProvider::function(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::KECCAK256, StateMutability::Pure)),
|
||||
magicVarDecl("msg", TypeProvider::magic(MagicType::Kind::Message)),
|
||||
@ -87,10 +86,7 @@ inline vector<shared_ptr<MagicVariableDeclaration const>> constructMagicVariable
|
||||
magicVarDecl("require", TypeProvider::function(strings{"bool", "string memory"}, strings{}, FunctionType::Kind::Require, StateMutability::Pure)),
|
||||
magicVarDecl("revert", TypeProvider::function(strings(), strings(), FunctionType::Kind::Revert, StateMutability::Pure)),
|
||||
magicVarDecl("revert", TypeProvider::function(strings{"string memory"}, strings(), FunctionType::Kind::Revert, StateMutability::Pure)),
|
||||
magicVarDecl("ripemd160", TypeProvider::function(strings{"bytes memory"}, strings{"bytes20"}, FunctionType::Kind::RIPEMD160, StateMutability::Pure)),
|
||||
magicVarDecl("selfdestruct", TypeProvider::function(strings{"address payable"}, strings{}, FunctionType::Kind::Selfdestruct)),
|
||||
magicVarDecl("sha256", TypeProvider::function(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::SHA256, StateMutability::Pure)),
|
||||
magicVarDecl("sha3", TypeProvider::function(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::KECCAK256, StateMutability::Pure)),
|
||||
magicVarDecl("suicide", TypeProvider::function(strings{"address payable"}, strings{}, FunctionType::Kind::Selfdestruct)),
|
||||
magicVarDecl("tx", TypeProvider::magic(MagicType::Kind::Transaction)),
|
||||
// Accepts a MagicType that can be any contract type or an Integer type and returns a
|
||||
@ -103,11 +99,21 @@ inline vector<shared_ptr<MagicVariableDeclaration const>> constructMagicVariable
|
||||
FunctionType::Options::withArbitraryParameters()
|
||||
)),
|
||||
};
|
||||
vector<shared_ptr<MagicVariableDeclaration const>> precompiles = {
|
||||
magicVarDecl("ecrecover", TypeProvider::function(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Kind::ECRecover, StateMutability::Pure)),
|
||||
magicVarDecl("ripemd160", TypeProvider::function(strings{"bytes memory"}, strings{"bytes20"}, FunctionType::Kind::RIPEMD160, StateMutability::Pure)),
|
||||
magicVarDecl("sha256", TypeProvider::function(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::SHA256, StateMutability::Pure)),
|
||||
magicVarDecl("sha3", TypeProvider::function(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::KECCAK256, StateMutability::Pure)),
|
||||
};
|
||||
if (!_stdlib) {
|
||||
return list;
|
||||
}
|
||||
return list + precompiles;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
GlobalContext::GlobalContext(): m_magicVariables{constructMagicVariables()}
|
||||
GlobalContext::GlobalContext(bool _stdlib): m_magicVariables{constructMagicVariables(_stdlib)}
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@ -47,7 +47,9 @@ public:
|
||||
GlobalContext(GlobalContext const&) = delete;
|
||||
GlobalContext& operator=(GlobalContext const&) = delete;
|
||||
|
||||
GlobalContext();
|
||||
/// Set the stdlib flag to true if globals should not be populated by features provided
|
||||
/// in the stdlib.
|
||||
GlobalContext(bool _stdlib);
|
||||
void setCurrentContract(ContractDefinition const& _contract);
|
||||
void resetCurrentContract() { m_currentContract = nullptr; }
|
||||
MagicVariableDeclaration const* currentThis() const;
|
||||
|
||||
@ -31,6 +31,7 @@ enum class ExperimentalFeature
|
||||
{
|
||||
ABIEncoderV2, // new ABI encoder that makes use of Yul
|
||||
SMTChecker,
|
||||
Stdlib,
|
||||
Test,
|
||||
TestOnlyAnalysis
|
||||
};
|
||||
@ -46,6 +47,7 @@ static std::map<std::string, ExperimentalFeature> const ExperimentalFeatureNames
|
||||
{
|
||||
{ "ABIEncoderV2", ExperimentalFeature::ABIEncoderV2 },
|
||||
{ "SMTChecker", ExperimentalFeature::SMTChecker },
|
||||
{ "stdlib", ExperimentalFeature::Stdlib },
|
||||
{ "__test", ExperimentalFeature::Test },
|
||||
{ "__testOnlyAnalysis", ExperimentalFeature::TestOnlyAnalysis },
|
||||
};
|
||||
|
||||
@ -433,7 +433,7 @@ bool CompilerStack::analyze()
|
||||
if (source->ast && !syntaxChecker.checkSyntax(*source->ast))
|
||||
noErrors = false;
|
||||
|
||||
m_globalContext = make_shared<GlobalContext>();
|
||||
m_globalContext = make_shared<GlobalContext>(false);
|
||||
// We need to keep the same resolver during the whole process.
|
||||
NameAndTypeResolver resolver(*m_globalContext, m_evmVersion, m_errorReporter);
|
||||
for (Source const* source: m_sourceOrder)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user