mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Move msg.gas to global function gasleft(). Closes #2971.
This commit is contained in:
@@ -39,6 +39,7 @@ m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{
|
||||
make_shared<MagicVariableDeclaration>("assert", make_shared<FunctionType>(strings{"bool"}, strings{}, FunctionType::Kind::Assert, false, StateMutability::Pure)),
|
||||
make_shared<MagicVariableDeclaration>("block", make_shared<MagicType>(MagicType::Kind::Block)),
|
||||
make_shared<MagicVariableDeclaration>("ecrecover", make_shared<FunctionType>(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Kind::ECRecover, false, StateMutability::Pure)),
|
||||
make_shared<MagicVariableDeclaration>("gasleft", make_shared<FunctionType>(strings(), strings{"uint256"}, FunctionType::Kind::GasLeft, false, StateMutability::View)),
|
||||
make_shared<MagicVariableDeclaration>("keccak256", make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Kind::SHA3, true, StateMutability::Pure)),
|
||||
make_shared<MagicVariableDeclaration>("log0", make_shared<FunctionType>(strings{"bytes32"}, strings{}, FunctionType::Kind::Log0)),
|
||||
make_shared<MagicVariableDeclaration>("log1", make_shared<FunctionType>(strings{"bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log1)),
|
||||
|
||||
@@ -3000,8 +3000,10 @@ bool MagicType::operator==(Type const& _other) const
|
||||
return other.m_kind == m_kind;
|
||||
}
|
||||
|
||||
MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const*) const
|
||||
MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const *_contract) const
|
||||
{
|
||||
solAssert(_contract, "");
|
||||
const bool v050 = _contract->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050);
|
||||
switch (m_kind)
|
||||
{
|
||||
case Kind::Block:
|
||||
@@ -3014,13 +3016,17 @@ MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const*) const
|
||||
{"gaslimit", make_shared<IntegerType>(256)}
|
||||
});
|
||||
case Kind::Message:
|
||||
return MemberList::MemberMap({
|
||||
{
|
||||
std::vector<MemberList::Member> members = {
|
||||
{"sender", make_shared<IntegerType>(160, IntegerType::Modifier::Address)},
|
||||
{"gas", make_shared<IntegerType>(256)},
|
||||
{"value", make_shared<IntegerType>(256)},
|
||||
{"data", make_shared<ArrayType>(DataLocation::CallData)},
|
||||
{"sig", make_shared<FixedBytesType>(4)}
|
||||
});
|
||||
};
|
||||
if (!v050)
|
||||
members.emplace_back("gas", make_shared<IntegerType>(256));
|
||||
return MemberList::MemberMap(members);
|
||||
}
|
||||
case Kind::Transaction:
|
||||
return MemberList::MemberMap({
|
||||
{"origin", make_shared<IntegerType>(160, IntegerType::Modifier::Address)},
|
||||
|
||||
@@ -902,7 +902,8 @@ public:
|
||||
ByteArrayPush, ///< .push() to a dynamically sized byte array in storage
|
||||
ObjectCreation, ///< array creation using new
|
||||
Assert, ///< assert()
|
||||
Require ///< require()
|
||||
Require, ///< require()
|
||||
GasLeft ///< gasleft()
|
||||
};
|
||||
|
||||
virtual Category category() const override { return Category::Function; }
|
||||
|
||||
@@ -906,6 +906,9 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
m_context << success;
|
||||
break;
|
||||
}
|
||||
case FunctionType::Kind::GasLeft:
|
||||
m_context << Instruction::GAS;
|
||||
break;
|
||||
default:
|
||||
solAssert(false, "Invalid function type.");
|
||||
}
|
||||
@@ -921,6 +924,8 @@ bool ExpressionCompiler::visit(NewExpression const&)
|
||||
|
||||
bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
|
||||
{
|
||||
const bool v050 = m_context.experimentalFeatureActive(ExperimentalFeature::V050);
|
||||
|
||||
CompilerContext::LocationSetter locationSetter(m_context, _memberAccess);
|
||||
// Check whether the member is a bound function.
|
||||
ASTString const& member = _memberAccess.memberName();
|
||||
@@ -1135,7 +1140,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
|
||||
m_context << Instruction::CALLVALUE;
|
||||
else if (member == "origin")
|
||||
m_context << Instruction::ORIGIN;
|
||||
else if (member == "gas")
|
||||
else if (!v050 && member == "gas")
|
||||
m_context << Instruction::GAS;
|
||||
else if (member == "gasprice")
|
||||
m_context << Instruction::GASPRICE;
|
||||
|
||||
Reference in New Issue
Block a user