mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Make toString(visibility) a helper
This commit is contained in:
parent
efd45f64a5
commit
b210db8058
@ -152,6 +152,24 @@ public:
|
||||
/// Visibility ordered from restricted to unrestricted.
|
||||
enum class Visibility { Default, Private, Internal, Public, External };
|
||||
|
||||
static std::string visibilityToString(Declaration::Visibility _visibility)
|
||||
{
|
||||
switch(_visibility)
|
||||
{
|
||||
case Declaration::Visibility::Public:
|
||||
return "public";
|
||||
case Declaration::Visibility::Internal:
|
||||
return "internal";
|
||||
case Declaration::Visibility::Private:
|
||||
return "private";
|
||||
case Declaration::Visibility::External:
|
||||
return "external";
|
||||
default:
|
||||
solAssert(false, "Invalid visibility specifier.");
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
|
||||
Declaration(
|
||||
SourceLocation const& _location,
|
||||
ASTPointer<ASTString> const& _name,
|
||||
|
@ -285,7 +285,7 @@ bool ASTJsonConverter::visit(StructDefinition const& _node)
|
||||
{
|
||||
setJsonNode(_node, "StructDefinition", {
|
||||
make_pair("name", _node.name()),
|
||||
make_pair("visibility", visibility(_node.visibility())),
|
||||
make_pair("visibility", Declaration::visibilityToString(_node.visibility())),
|
||||
make_pair("canonicalName", _node.annotation().canonicalName),
|
||||
make_pair("members", toJson(_node.members())),
|
||||
make_pair("scope", idOrNull(_node.scope()))
|
||||
@ -325,7 +325,7 @@ bool ASTJsonConverter::visit(FunctionDefinition const& _node)
|
||||
make_pair("name", _node.name()),
|
||||
make_pair(m_legacy ? "constant" : "isDeclaredConst", _node.isDeclaredConst()),
|
||||
make_pair("payable", _node.isPayable()),
|
||||
make_pair("visibility", visibility(_node.visibility())),
|
||||
make_pair("visibility", Declaration::visibilityToString(_node.visibility())),
|
||||
make_pair("parameters", toJson(_node.parameterList())),
|
||||
make_pair("isConstructor", _node.isConstructor()),
|
||||
make_pair("returnParameters", toJson(*_node.returnParameterList())),
|
||||
@ -346,7 +346,7 @@ bool ASTJsonConverter::visit(VariableDeclaration const& _node)
|
||||
make_pair("constant", _node.isConstant()),
|
||||
make_pair("stateVariable", _node.isStateVariable()),
|
||||
make_pair("storageLocation", location(_node.referenceLocation())),
|
||||
make_pair("visibility", visibility(_node.visibility())),
|
||||
make_pair("visibility", Declaration::visibilityToString(_node.visibility())),
|
||||
make_pair("value", _node.value() ? toJson(*_node.value()) : Json::nullValue),
|
||||
make_pair("scope", idOrNull(_node.scope())),
|
||||
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type))
|
||||
@ -361,7 +361,7 @@ bool ASTJsonConverter::visit(ModifierDefinition const& _node)
|
||||
{
|
||||
setJsonNode(_node, "ModifierDefinition", {
|
||||
make_pair("name", _node.name()),
|
||||
make_pair("visibility", visibility(_node.visibility())),
|
||||
make_pair("visibility", Declaration::visibilityToString(_node.visibility())),
|
||||
make_pair("parameters", toJson(_node.parameterList())),
|
||||
make_pair("body", toJson(_node.body()))
|
||||
});
|
||||
@ -418,7 +418,7 @@ bool ASTJsonConverter::visit(FunctionTypeName const& _node)
|
||||
{
|
||||
setJsonNode(_node, "FunctionTypeName", {
|
||||
make_pair("payable", _node.isPayable()),
|
||||
make_pair("visibility", visibility(_node.visibility())),
|
||||
make_pair("visibility", Declaration::visibilityToString(_node.visibility())),
|
||||
make_pair(m_legacy ? "constant" : "isDeclaredConst", _node.isDeclaredConst()),
|
||||
make_pair("parameterTypes", toJson(*_node.parameterTypeList())),
|
||||
make_pair("returnParameterTypes", toJson(*_node.returnParameterTypeList())),
|
||||
@ -730,23 +730,6 @@ void ASTJsonConverter::endVisit(EventDefinition const&)
|
||||
m_inEvent = false;
|
||||
}
|
||||
|
||||
string ASTJsonConverter::visibility(Declaration::Visibility const& _visibility)
|
||||
{
|
||||
switch (_visibility)
|
||||
{
|
||||
case Declaration::Visibility::Private:
|
||||
return "private";
|
||||
case Declaration::Visibility::Internal:
|
||||
return "internal";
|
||||
case Declaration::Visibility::Public:
|
||||
return "public";
|
||||
case Declaration::Visibility::External:
|
||||
return "external";
|
||||
default:
|
||||
solAssert(false, "Unknown declaration visibility.");
|
||||
}
|
||||
}
|
||||
|
||||
string ASTJsonConverter::location(VariableDeclaration::Location _location)
|
||||
{
|
||||
switch (_location)
|
||||
|
@ -128,7 +128,6 @@ private:
|
||||
return _node ? toJson(*_node) : Json::nullValue;
|
||||
}
|
||||
Json::Value inlineAssemblyIdentifierToJson(std::pair<assembly::Identifier const* , InlineAssemblyAnnotation::ExternalIdentifierInfo> _info);
|
||||
std::string visibility(Declaration::Visibility const& _visibility);
|
||||
std::string location(VariableDeclaration::Location _location);
|
||||
std::string contractKind(ContractDefinition::ContractKind _kind);
|
||||
std::string functionCallKind(FunctionCallKind _kind);
|
||||
|
@ -307,24 +307,6 @@ Declaration::Visibility Parser::parseVisibilitySpecifier(Token::Value _token)
|
||||
return visibility;
|
||||
}
|
||||
|
||||
string Parser::visibilitySpecifierName(Declaration::Visibility _visibility)
|
||||
{
|
||||
switch(_visibility)
|
||||
{
|
||||
case Declaration::Visibility::Public:
|
||||
return "public";
|
||||
case Declaration::Visibility::Internal:
|
||||
return "internal";
|
||||
case Declaration::Visibility::Private:
|
||||
return "private";
|
||||
case Declaration::Visibility::External:
|
||||
return "external";
|
||||
default:
|
||||
solAssert(false, "Invalid visibility specifier.");
|
||||
}
|
||||
return string();
|
||||
}
|
||||
|
||||
Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _forceEmptyName, bool _allowModifiers)
|
||||
{
|
||||
FunctionHeaderParserResult result;
|
||||
@ -374,7 +356,7 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _forceEmptyN
|
||||
{
|
||||
parserError(string(
|
||||
"Visibility already specified as \"" +
|
||||
visibilitySpecifierName(result.visibility) +
|
||||
Declaration::visibilityToString(result.visibility) +
|
||||
"\"."
|
||||
));
|
||||
m_scanner->next();
|
||||
@ -536,7 +518,7 @@ ASTPointer<VariableDeclaration> Parser::parseVariableDeclaration(
|
||||
{
|
||||
parserError(string(
|
||||
"Visibility already specified as \"" +
|
||||
visibilitySpecifierName(visibility) +
|
||||
Declaration::visibilityToString(visibility) +
|
||||
"\"."
|
||||
));
|
||||
m_scanner->next();
|
||||
|
Loading…
Reference in New Issue
Block a user