mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Upgrade dot syntax for gas and value
This commit is contained in:
parent
0eec87bb97
commit
eb4cff56f7
@ -5,6 +5,7 @@ add_executable(solidity-upgrade
|
||||
solidityUpgrade/UpgradeSuite.h
|
||||
solidityUpgrade/Upgrade050.cpp
|
||||
solidityUpgrade/Upgrade060.cpp
|
||||
solidityUpgrade/Upgrade070.cpp
|
||||
solidityUpgrade/SourceTransform.h
|
||||
solidityUpgrade/SourceUpgrade.cpp
|
||||
)
|
||||
|
@ -19,11 +19,32 @@
|
||||
|
||||
#include <libsolidity/ast/AST.h>
|
||||
|
||||
#include <sstream>
|
||||
#include <regex>
|
||||
|
||||
namespace solidity::tools
|
||||
{
|
||||
|
||||
/**
|
||||
* Helper for displaying location during asserts
|
||||
*/
|
||||
class LocationHelper
|
||||
{
|
||||
std::stringstream m_stream;
|
||||
|
||||
public:
|
||||
|
||||
template <typename T>
|
||||
LocationHelper& operator<<(T const& data)
|
||||
{
|
||||
m_stream << data;
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator std::string() { return m_stream.str(); }
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Helper that provides functions which analyze certain source locations
|
||||
* on a textual base. They utilize regular expression to search for
|
||||
@ -154,6 +175,59 @@ public:
|
||||
_expression
|
||||
);
|
||||
}
|
||||
|
||||
static std::string gasUpdate(langutil::SourceLocation const& _location)
|
||||
{
|
||||
// dot, "gas", any number of whitespaces, left bracket
|
||||
std::regex gasReg{"\\.gas\\s*\\("};
|
||||
|
||||
if (regex_search(_location.text(), gasReg))
|
||||
{
|
||||
std::string out = regex_replace(
|
||||
_location.text(),
|
||||
gasReg,
|
||||
"{gas: ",
|
||||
std::regex_constants::format_first_only
|
||||
);
|
||||
return regex_replace(out, std::regex{"\\)$"}, "}");
|
||||
}
|
||||
else
|
||||
solAssert(
|
||||
false,
|
||||
LocationHelper()
|
||||
<< "Regex count not match: " << _location.text() << " at " << _location
|
||||
<< "\nNeeds to be fixed manually."
|
||||
);
|
||||
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
static std::string valueUpdate(langutil::SourceLocation const& _location)
|
||||
{
|
||||
// dot, "value", any number of whitespaces, left bracket
|
||||
std::regex valueReg{"\\.value\\s*\\("};
|
||||
|
||||
if (regex_search(_location.text(), valueReg))
|
||||
{
|
||||
std::string out = regex_replace(
|
||||
_location.text(),
|
||||
valueReg,
|
||||
"{value: ",
|
||||
std::regex_constants::format_first_only
|
||||
);
|
||||
return regex_replace(out, std::regex{"\\)$"}, "}");
|
||||
}
|
||||
else
|
||||
solAssert(
|
||||
false,
|
||||
LocationHelper()
|
||||
<< "Regex count not match: " << _location.text() << " at " << _location
|
||||
<< "\nNeeds to be fixed manually"
|
||||
);
|
||||
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -194,6 +194,8 @@ Allowed options)",
|
||||
m_suite.activateModule(Module::OverridingFunction);
|
||||
else if (module == "virtual")
|
||||
m_suite.activateModule(Module::VirtualFunction);
|
||||
else if (module == "dotsyntax")
|
||||
m_suite.activateModule(Module::DotSyntax);
|
||||
else
|
||||
{
|
||||
error() << "Unknown upgrade module \"" + module + "\"" << endl;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
This file is part of solidity.
|
||||
|
||||
solidity is free software: you can redistribute it and/or modify
|
||||
@ -19,6 +19,7 @@
|
||||
#include <tools/solidityUpgrade/UpgradeChange.h>
|
||||
#include <tools/solidityUpgrade/Upgrade050.h>
|
||||
#include <tools/solidityUpgrade/Upgrade060.h>
|
||||
#include <tools/solidityUpgrade/Upgrade070.h>
|
||||
|
||||
#include <libsolidity/interface/CompilerStack.h>
|
||||
#include <libsolidity/interface/DebugSettings.h>
|
||||
@ -56,7 +57,8 @@ private:
|
||||
VisibilitySpecifier,
|
||||
AbstractContract,
|
||||
OverridingFunction,
|
||||
VirtualFunction
|
||||
VirtualFunction,
|
||||
DotSyntax
|
||||
};
|
||||
|
||||
/// Upgrade suite that hosts all available modules.
|
||||
@ -78,6 +80,10 @@ private:
|
||||
OverridingFunction{m_changes}.analyze(_sourceUnit);
|
||||
if (isActivated(Module::VirtualFunction))
|
||||
VirtualFunction{m_changes}.analyze(_sourceUnit);
|
||||
|
||||
/// Solidity 0.7.0
|
||||
if (isActivated(Module::DotSyntax))
|
||||
DotSyntax{m_changes}.analyze(_sourceUnit);
|
||||
}
|
||||
|
||||
void activateModule(Module _module) { m_modules.insert(_module); }
|
||||
@ -96,7 +102,8 @@ private:
|
||||
Module::VisibilitySpecifier,
|
||||
Module::AbstractContract,
|
||||
Module::OverridingFunction,
|
||||
Module::VirtualFunction
|
||||
Module::VirtualFunction,
|
||||
Module::DotSyntax
|
||||
};
|
||||
};
|
||||
|
||||
|
42
tools/solidityUpgrade/Upgrade070.cpp
Normal file
42
tools/solidityUpgrade/Upgrade070.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
This file is part of solidity.
|
||||
|
||||
solidity is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
solidity is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
n You should have received a copy of the GNU General Public License
|
||||
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <tools/solidityUpgrade/Upgrade070.h>
|
||||
#include <tools/solidityUpgrade/SourceTransform.h>
|
||||
|
||||
using namespace solidity::frontend;
|
||||
using namespace solidity::tools;
|
||||
|
||||
void DotSyntax::endVisit(FunctionCall const& _functionCall)
|
||||
{
|
||||
TypePointer type = _functionCall.annotation().type;
|
||||
if (auto const funcType = dynamic_cast<FunctionType const*>(type))
|
||||
{
|
||||
if (funcType->valueSet())
|
||||
m_changes.emplace_back(
|
||||
UpgradeChange::Level::Safe,
|
||||
_functionCall.location(),
|
||||
SourceTransform::valueUpdate(_functionCall.location())
|
||||
);
|
||||
|
||||
if (funcType->gasSet())
|
||||
m_changes.emplace_back(
|
||||
UpgradeChange::Level::Safe,
|
||||
_functionCall.location(),
|
||||
SourceTransform::gasUpdate(_functionCall.location())
|
||||
);
|
||||
}
|
||||
}
|
35
tools/solidityUpgrade/Upgrade070.h
Normal file
35
tools/solidityUpgrade/Upgrade070.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
This file is part of solidity.
|
||||
|
||||
solidity is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
solidity is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <tools/solidityUpgrade/UpgradeSuite.h>
|
||||
|
||||
#include <libsolidity/ast/AST.h>
|
||||
|
||||
namespace solidity::tools
|
||||
{
|
||||
|
||||
class DotSyntax: public AnalysisUpgrade
|
||||
{
|
||||
public:
|
||||
using AnalysisUpgrade::AnalysisUpgrade;
|
||||
void analyze(frontend::SourceUnit const& _sourceUnit) { _sourceUnit.accept(*this); }
|
||||
private:
|
||||
void endVisit(frontend::FunctionCall const& _expression) override;
|
||||
};
|
||||
|
||||
}
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/exception/all.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
@ -74,8 +75,16 @@ int main(int argc, char** argv)
|
||||
if (!upgrade.parseArguments(argc, argv))
|
||||
return 1;
|
||||
upgrade.printPrologue();
|
||||
if (!upgrade.processInput())
|
||||
return 1;
|
||||
|
||||
try
|
||||
{
|
||||
if (!upgrade.processInput())
|
||||
return 1;
|
||||
}
|
||||
catch (boost::exception const& _exception)
|
||||
{
|
||||
cerr << "Exception while processing input: " << boost::diagnostic_information(_exception) << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user