mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Export immutability.
This commit is contained in:
+17
-6
@@ -854,7 +854,17 @@ class VariableDeclaration: public Declaration
|
||||
{
|
||||
public:
|
||||
enum Location { Unspecified, Storage, Memory, CallData };
|
||||
enum class Constantness { Mutable, Immutable, Constant };
|
||||
enum class Mutability { Mutable, Immutable, Constant };
|
||||
static std::string mutabilityToString(Mutability _mutability)
|
||||
{
|
||||
switch (_mutability)
|
||||
{
|
||||
case Mutability::Mutable: return "mutable";
|
||||
case Mutability::Immutable: return "immutable";
|
||||
case Mutability::Constant: return "constant";
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
VariableDeclaration(
|
||||
int64_t _id,
|
||||
@@ -865,7 +875,7 @@ public:
|
||||
Visibility _visibility,
|
||||
bool _isStateVar = false,
|
||||
bool _isIndexed = false,
|
||||
Constantness _constantness = Constantness::Mutable,
|
||||
Mutability _mutability = Mutability::Mutable,
|
||||
ASTPointer<OverrideSpecifier> const& _overrides = nullptr,
|
||||
Location _referenceLocation = Location::Unspecified
|
||||
):
|
||||
@@ -874,7 +884,7 @@ public:
|
||||
m_value(_value),
|
||||
m_isStateVariable(_isStateVar),
|
||||
m_isIndexed(_isIndexed),
|
||||
m_constantness(_constantness),
|
||||
m_mutability(_mutability),
|
||||
m_overrides(_overrides),
|
||||
m_location(_referenceLocation) {}
|
||||
|
||||
@@ -918,8 +928,9 @@ public:
|
||||
bool hasReferenceOrMappingType() const;
|
||||
bool isStateVariable() const { return m_isStateVariable; }
|
||||
bool isIndexed() const { return m_isIndexed; }
|
||||
bool isConstant() const { return m_constantness == Constantness::Constant; }
|
||||
bool immutable() const { return m_constantness == Constantness::Immutable; }
|
||||
Mutability mutability() const { return m_mutability; }
|
||||
bool isConstant() const { return m_mutability == Mutability::Constant; }
|
||||
bool immutable() const { return m_mutability == Mutability::Immutable; }
|
||||
ASTPointer<OverrideSpecifier> const& overrides() const { return m_overrides; }
|
||||
Location referenceLocation() const { return m_location; }
|
||||
/// @returns a set of allowed storage locations for the variable.
|
||||
@@ -947,7 +958,7 @@ private:
|
||||
bool m_isStateVariable = false; ///< Whether or not this is a contract state variable
|
||||
bool m_isIndexed = false; ///< Whether this is an indexed variable (used by events).
|
||||
/// Whether the variable is "constant", "immutable" or non-marked (mutable).
|
||||
Constantness m_constantness = Constantness::Mutable;
|
||||
Mutability m_mutability = Mutability::Mutable;
|
||||
ASTPointer<OverrideSpecifier> m_overrides; ///< Contains the override specifier node
|
||||
Location m_location = Location::Unspecified; ///< Location of the variable if it is of reference type.
|
||||
};
|
||||
|
||||
@@ -378,6 +378,7 @@ bool ASTJsonConverter::visit(VariableDeclaration const& _node)
|
||||
make_pair("name", _node.name()),
|
||||
make_pair("typeName", toJsonOrNull(_node.typeName())),
|
||||
make_pair("constant", _node.isConstant()),
|
||||
make_pair("mutability", VariableDeclaration::mutabilityToString(_node.mutability())),
|
||||
make_pair("stateVariable", _node.isStateVariable()),
|
||||
make_pair("storageLocation", location(_node.referenceLocation())),
|
||||
make_pair("overrides", _node.overrides() ? toJson(*_node.overrides()) : Json::nullValue),
|
||||
|
||||
@@ -411,11 +411,24 @@ ASTPointer<VariableDeclaration> ASTJsonImporter::createVariableDeclaration(Json:
|
||||
{
|
||||
astAssert(_node["name"].isString(), "Expected 'name' to be a string!");
|
||||
|
||||
VariableDeclaration::Constantness constantness{};
|
||||
if (memberAsBool(_node, "constant"))
|
||||
constantness = VariableDeclaration::Constantness::Constant;
|
||||
VariableDeclaration::Mutability mutability{};
|
||||
astAssert(member(_node, "mutability").isString(), "'mutability' expected to be string.");
|
||||
string const mutabilityStr = member(_node, "mutability").asString();
|
||||
if (mutabilityStr == "constant")
|
||||
{
|
||||
mutability = VariableDeclaration::Mutability::Constant;
|
||||
astAssert(memberAsBool(_node, "constant"), "");
|
||||
}
|
||||
else
|
||||
constantness = VariableDeclaration::Constantness::Mutable;
|
||||
{
|
||||
astAssert(!memberAsBool(_node, "constant"), "");
|
||||
if (mutabilityStr == "mutable")
|
||||
mutability = VariableDeclaration::Mutability::Mutable;
|
||||
else if (mutabilityStr == "immutable")
|
||||
mutability = VariableDeclaration::Mutability::Immutable;
|
||||
else
|
||||
astAssert(false, "");
|
||||
}
|
||||
|
||||
return createASTNode<VariableDeclaration>(
|
||||
_node,
|
||||
@@ -425,7 +438,7 @@ ASTPointer<VariableDeclaration> ASTJsonImporter::createVariableDeclaration(Json:
|
||||
visibility(_node),
|
||||
memberAsBool(_node, "stateVariable"),
|
||||
_node.isMember("indexed") ? memberAsBool(_node, "indexed") : false,
|
||||
constantness,
|
||||
mutability,
|
||||
_node["overrides"].isNull() ? nullptr : createOverrideSpecifier(member(_node, "overrides")),
|
||||
location(_node)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user