mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Source location for named mapping keys
This commit is contained in:
+10
-2
@@ -1428,28 +1428,36 @@ public:
|
||||
SourceLocation const& _location,
|
||||
ASTPointer<TypeName> _keyType,
|
||||
ASTPointer<ASTString> _keyName,
|
||||
SourceLocation _keyNameLocation,
|
||||
ASTPointer<TypeName> _valueType,
|
||||
ASTPointer<ASTString> _valueName
|
||||
ASTPointer<ASTString> _valueName,
|
||||
SourceLocation _valueNameLocation
|
||||
):
|
||||
TypeName(_id, _location),
|
||||
m_keyType(std::move(_keyType)),
|
||||
m_keyName(std::move(_keyName)),
|
||||
m_keyNameLocation(std::move(_keyNameLocation)),
|
||||
m_valueType(std::move(_valueType)),
|
||||
m_valueName(std::move(_valueName))
|
||||
m_valueName(std::move(_valueName)),
|
||||
m_valueNameLocation(std::move(_valueNameLocation))
|
||||
{}
|
||||
void accept(ASTVisitor& _visitor) override;
|
||||
void accept(ASTConstVisitor& _visitor) const override;
|
||||
|
||||
TypeName const& keyType() const { return *m_keyType; }
|
||||
ASTString keyName() const { return *m_keyName; }
|
||||
SourceLocation keyNameLocation() const { return m_keyNameLocation; }
|
||||
TypeName const& valueType() const { return *m_valueType; }
|
||||
ASTString valueName() const { return *m_valueName; }
|
||||
SourceLocation valueNameLocation() const { return m_valueNameLocation; }
|
||||
|
||||
private:
|
||||
ASTPointer<TypeName> m_keyType;
|
||||
ASTPointer<ASTString> m_keyName;
|
||||
SourceLocation m_keyNameLocation;
|
||||
ASTPointer<TypeName> m_valueType;
|
||||
ASTPointer<ASTString> m_valueName;
|
||||
SourceLocation m_valueNameLocation;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -599,8 +599,10 @@ bool ASTJsonExporter::visit(Mapping const& _node)
|
||||
setJsonNode(_node, "Mapping", {
|
||||
make_pair("keyType", toJson(_node.keyType())),
|
||||
make_pair("keyName", _node.keyName()),
|
||||
make_pair("keyNameLocation", sourceLocationToString(_node.keyNameLocation())),
|
||||
make_pair("valueType", toJson(_node.valueType())),
|
||||
make_pair("valueName", _node.valueName()),
|
||||
make_pair("valueNameLocation", sourceLocationToString(_node.valueNameLocation())),
|
||||
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true))
|
||||
});
|
||||
return false;
|
||||
|
||||
@@ -116,6 +116,20 @@ SourceLocation ASTJsonImporter::createNameSourceLocation(Json::Value const& _nod
|
||||
return solidity::langutil::parseSourceLocation(_node["nameLocation"].asString(), m_sourceNames);
|
||||
}
|
||||
|
||||
SourceLocation ASTJsonImporter::createKeyNameSourceLocation(Json::Value const& _node)
|
||||
{
|
||||
astAssert(member(_node, "keyNameLocation").isString(), "'keyNameLocation' must be a string");
|
||||
|
||||
return solidity::langutil::parseSourceLocation(_node["keyNameLocation"].asString(), m_sourceNames);
|
||||
}
|
||||
|
||||
SourceLocation ASTJsonImporter::createValueNameSourceLocation(Json::Value const& _node)
|
||||
{
|
||||
astAssert(member(_node, "valueNameLocation").isString(), "'valueNameLocation' must be a string");
|
||||
|
||||
return solidity::langutil::parseSourceLocation(_node["valueNameLocation"].asString(), m_sourceNames);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ASTPointer<T> ASTJsonImporter::convertJsonToASTNode(Json::Value const& _node)
|
||||
{
|
||||
@@ -649,8 +663,10 @@ ASTPointer<Mapping> ASTJsonImporter::createMapping(Json::Value const& _node)
|
||||
_node,
|
||||
convertJsonToASTNode<TypeName>(member(_node, "keyType")),
|
||||
memberAsASTString(_node, "keyName"),
|
||||
createKeyNameSourceLocation(_node),
|
||||
convertJsonToASTNode<TypeName>(member(_node, "valueType")),
|
||||
memberAsASTString(_node, "valueName")
|
||||
memberAsASTString(_node, "valueName"),
|
||||
createValueNameSourceLocation(_node)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,10 @@ private:
|
||||
ASTPointer<T> convertJsonToASTNode(Json::Value const& _node);
|
||||
|
||||
langutil::SourceLocation createNameSourceLocation(Json::Value const& _node);
|
||||
/// @returns source location of a mapping key name
|
||||
langutil::SourceLocation createKeyNameSourceLocation(Json::Value const& _node);
|
||||
/// @returns source location of a mapping value name
|
||||
langutil::SourceLocation createValueNameSourceLocation(Json::Value const& _node);
|
||||
|
||||
/// \defgroup nodeCreators JSON to AST-Nodes
|
||||
///@{
|
||||
|
||||
Reference in New Issue
Block a user