mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
solidity-upgrade can now change now to block.timestamp
This commit is contained in:
@@ -267,6 +267,24 @@ public:
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
static std::string nowUpdate(langutil::SourceLocation const& _location)
|
||||
{
|
||||
std::regex nowRegex{"now"};
|
||||
|
||||
if (regex_search(_location.text(), nowRegex))
|
||||
{
|
||||
return regex_replace(_location.text(), nowRegex, "block.timestamp");
|
||||
}
|
||||
else
|
||||
solAssert(
|
||||
false,
|
||||
LocationHelper() << "Could not fix: " << _location.text() << " at " << _location <<
|
||||
"\nNeeds to be fixed manually."
|
||||
);
|
||||
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -196,6 +196,8 @@ Allowed options)",
|
||||
m_suite.activateModule(Module::VirtualFunction);
|
||||
else if (module == "dotsyntax")
|
||||
m_suite.activateModule(Module::DotSyntax);
|
||||
else if (module == "now")
|
||||
m_suite.activateModule(Module::NowKeyword);
|
||||
else
|
||||
{
|
||||
error() << "Unknown upgrade module \"" + module + "\"" << endl;
|
||||
|
||||
@@ -58,7 +58,8 @@ private:
|
||||
AbstractContract,
|
||||
OverridingFunction,
|
||||
VirtualFunction,
|
||||
DotSyntax
|
||||
DotSyntax,
|
||||
NowKeyword
|
||||
};
|
||||
|
||||
/// Upgrade suite that hosts all available modules.
|
||||
@@ -84,6 +85,8 @@ private:
|
||||
/// Solidity 0.7.0
|
||||
if (isActivated(Module::DotSyntax))
|
||||
DotSyntax{m_changes}.analyze(_sourceUnit);
|
||||
if (isActivated(Module::NowKeyword))
|
||||
NowKeyword{m_changes}.analyze(_sourceUnit);
|
||||
}
|
||||
|
||||
void activateModule(Module _module) { m_modules.insert(_module); }
|
||||
@@ -103,7 +106,8 @@ private:
|
||||
Module::AbstractContract,
|
||||
Module::OverridingFunction,
|
||||
Module::VirtualFunction,
|
||||
Module::DotSyntax
|
||||
Module::DotSyntax,
|
||||
Module::NowKeyword
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -40,3 +40,22 @@ void DotSyntax::endVisit(FunctionCall const& _functionCall)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void NowKeyword::endVisit(Identifier const& _identifier)
|
||||
{
|
||||
IdentifierAnnotation& annotation = _identifier.annotation();
|
||||
|
||||
if (MagicVariableDeclaration const* magicVar
|
||||
= dynamic_cast<MagicVariableDeclaration const*>(annotation.referencedDeclaration))
|
||||
{
|
||||
if (magicVar->type()->category() == Type::Category::Integer)
|
||||
{
|
||||
solAssert(_identifier.name() == "now", "");
|
||||
m_changes.emplace_back(
|
||||
UpgradeChange::Level::Safe,
|
||||
_identifier.location(),
|
||||
SourceTransform::nowUpdate(_identifier.location())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,4 +32,13 @@ private:
|
||||
void endVisit(frontend::FunctionCall const& _expression) override;
|
||||
};
|
||||
|
||||
class NowKeyword: public AnalysisUpgrade
|
||||
{
|
||||
public:
|
||||
using AnalysisUpgrade::AnalysisUpgrade;
|
||||
void analyze(frontend::SourceUnit const& _sourceUnit) { _sourceUnit.accept(*this); }
|
||||
private:
|
||||
void endVisit(frontend::Identifier const& _expression) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user