mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
solidity-upgrade: added module to remove visibility of constructors
This commit is contained in:
@@ -132,7 +132,8 @@ public:
|
||||
return regex_replace(
|
||||
_location.text(),
|
||||
_regex,
|
||||
_expression + " " + _keyword
|
||||
_expression + " " + _keyword,
|
||||
std::regex_constants::format_first_only
|
||||
);
|
||||
else
|
||||
solAssert(
|
||||
@@ -274,6 +275,14 @@ public:
|
||||
{
|
||||
return regex_replace(_location.text(), std::regex{"now"}, "block.timestamp");
|
||||
}
|
||||
|
||||
static std::string removeVisibility(langutil::SourceLocation const& _location)
|
||||
{
|
||||
std::string replacement = _location.text();
|
||||
for (auto const& replace: {"public ", "public", "internal ", "internal", "external ", "external"})
|
||||
replacement = regex_replace(replacement, std::regex{replace}, "");
|
||||
return replacement;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -198,6 +198,8 @@ Allowed options)",
|
||||
m_suite.activateModule(Module::DotSyntax);
|
||||
else if (module == "now")
|
||||
m_suite.activateModule(Module::NowKeyword);
|
||||
else if (module == "constructor-visibility")
|
||||
m_suite.activateModule(Module::ConstrutorVisibility);
|
||||
else
|
||||
{
|
||||
error() << "Unknown upgrade module \"" + module + "\"" << endl;
|
||||
|
||||
@@ -59,7 +59,8 @@ private:
|
||||
OverridingFunction,
|
||||
VirtualFunction,
|
||||
DotSyntax,
|
||||
NowKeyword
|
||||
NowKeyword,
|
||||
ConstrutorVisibility
|
||||
};
|
||||
|
||||
/// Upgrade suite that hosts all available modules.
|
||||
@@ -87,6 +88,8 @@ private:
|
||||
DotSyntax{m_changes}.analyze(_sourceUnit);
|
||||
if (isActivated(Module::NowKeyword))
|
||||
NowKeyword{m_changes}.analyze(_sourceUnit);
|
||||
if (isActivated(Module::ConstrutorVisibility))
|
||||
ConstructorVisibility{m_changes}.analyze(_sourceUnit);
|
||||
}
|
||||
|
||||
void activateModule(Module _module) { m_modules.insert(_module); }
|
||||
@@ -107,7 +110,8 @@ private:
|
||||
Module::OverridingFunction,
|
||||
Module::VirtualFunction,
|
||||
Module::DotSyntax,
|
||||
Module::NowKeyword
|
||||
Module::NowKeyword,
|
||||
Module::ConstrutorVisibility
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -59,3 +59,27 @@ void NowKeyword::endVisit(Identifier const& _identifier)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void ConstructorVisibility::endVisit(ContractDefinition const& _contract)
|
||||
{
|
||||
if (!_contract.abstract())
|
||||
for (FunctionDefinition const* function: _contract.definedFunctions())
|
||||
if (
|
||||
function->isConstructor() &&
|
||||
!function->noVisibilitySpecified() &&
|
||||
function->visibility() == Visibility::Internal
|
||||
)
|
||||
m_changes.emplace_back(
|
||||
UpgradeChange::Level::Safe,
|
||||
_contract.location(),
|
||||
SourceTransform::insertBeforeKeyword(_contract.location(), "contract", "abstract")
|
||||
);
|
||||
|
||||
for (FunctionDefinition const* function: _contract.definedFunctions())
|
||||
if (function->isConstructor() && !function->noVisibilitySpecified())
|
||||
m_changes.emplace_back(
|
||||
UpgradeChange::Level::Safe,
|
||||
function->location(),
|
||||
SourceTransform::removeVisibility(function->location())
|
||||
);
|
||||
}
|
||||
|
||||
@@ -41,4 +41,13 @@ private:
|
||||
void endVisit(frontend::Identifier const& _expression) override;
|
||||
};
|
||||
|
||||
class ConstructorVisibility: public AnalysisUpgrade
|
||||
{
|
||||
public:
|
||||
using AnalysisUpgrade::AnalysisUpgrade;
|
||||
void analyze(frontend::SourceUnit const& _sourceUnit) { _sourceUnit.accept(*this); }
|
||||
private:
|
||||
void endVisit(frontend::ContractDefinition const& _contract) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user