mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #13384 from zemse/develop
Allow named parameters in mapping types
This commit is contained in:
+13
-2
@@ -1427,18 +1427,29 @@ public:
|
||||
int64_t _id,
|
||||
SourceLocation const& _location,
|
||||
ASTPointer<TypeName> _keyType,
|
||||
ASTPointer<TypeName> _valueType
|
||||
ASTPointer<ASTString> _keyName,
|
||||
ASTPointer<TypeName> _valueType,
|
||||
ASTPointer<ASTString> _valueName
|
||||
):
|
||||
TypeName(_id, _location), m_keyType(std::move(_keyType)), m_valueType(std::move(_valueType)) {}
|
||||
TypeName(_id, _location),
|
||||
m_keyType(std::move(_keyType)),
|
||||
m_keyName(std::move(_keyName)),
|
||||
m_valueType(std::move(_valueType)),
|
||||
m_valueName(std::move(_valueName))
|
||||
{}
|
||||
void accept(ASTVisitor& _visitor) override;
|
||||
void accept(ASTConstVisitor& _visitor) const override;
|
||||
|
||||
TypeName const& keyType() const { return *m_keyType; }
|
||||
ASTString keyName() const { return *m_keyName; }
|
||||
TypeName const& valueType() const { return *m_valueType; }
|
||||
ASTString valueName() const { return *m_valueName; }
|
||||
|
||||
private:
|
||||
ASTPointer<TypeName> m_keyType;
|
||||
ASTPointer<ASTString> m_keyName;
|
||||
ASTPointer<TypeName> m_valueType;
|
||||
ASTPointer<ASTString> m_valueName;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -598,7 +598,9 @@ bool ASTJsonExporter::visit(Mapping const& _node)
|
||||
{
|
||||
setJsonNode(_node, "Mapping", {
|
||||
make_pair("keyType", toJson(_node.keyType())),
|
||||
make_pair("keyName", _node.keyName()),
|
||||
make_pair("valueType", toJson(_node.valueType())),
|
||||
make_pair("valueName", _node.valueName()),
|
||||
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true))
|
||||
});
|
||||
return false;
|
||||
|
||||
@@ -648,7 +648,9 @@ ASTPointer<Mapping> ASTJsonImporter::createMapping(Json::Value const& _node)
|
||||
return createASTNode<Mapping>(
|
||||
_node,
|
||||
convertJsonToASTNode<TypeName>(member(_node, "keyType")),
|
||||
convertJsonToASTNode<TypeName>(member(_node, "valueType"))
|
||||
memberAsASTString(_node, "keyName"),
|
||||
convertJsonToASTNode<TypeName>(member(_node, "valueType")),
|
||||
memberAsASTString(_node, "valueName")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -571,9 +571,9 @@ MagicType const* TypeProvider::meta(Type const* _type)
|
||||
return createAndGet<MagicType>(_type);
|
||||
}
|
||||
|
||||
MappingType const* TypeProvider::mapping(Type const* _keyType, Type const* _valueType)
|
||||
MappingType const* TypeProvider::mapping(Type const* _keyType, ASTString _keyName, Type const* _valueType, ASTString _valueName)
|
||||
{
|
||||
return createAndGet<MappingType>(_keyType, _valueType);
|
||||
return createAndGet<MappingType>(_keyType, _keyName, _valueType, _valueName);
|
||||
}
|
||||
|
||||
UserDefinedValueType const* TypeProvider::userDefinedValueType(UserDefinedValueTypeDefinition const& _definition)
|
||||
|
||||
@@ -195,7 +195,7 @@ public:
|
||||
|
||||
static MagicType const* meta(Type const* _type);
|
||||
|
||||
static MappingType const* mapping(Type const* _keyType, Type const* _valueType);
|
||||
static MappingType const* mapping(Type const* _keyType, ASTString _keyName, Type const* _valueType, ASTString _valueName);
|
||||
|
||||
static UserDefinedValueType const* userDefinedValueType(UserDefinedValueTypeDefinition const& _definition);
|
||||
|
||||
|
||||
@@ -2788,14 +2788,16 @@ FunctionType::FunctionType(VariableDeclaration const& _varDecl):
|
||||
m_declaration(&_varDecl)
|
||||
{
|
||||
auto returnType = _varDecl.annotation().type;
|
||||
ASTString returnName;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (auto mappingType = dynamic_cast<MappingType const*>(returnType))
|
||||
{
|
||||
m_parameterTypes.push_back(mappingType->keyType());
|
||||
m_parameterNames.emplace_back("");
|
||||
m_parameterNames.push_back(mappingType->keyName());
|
||||
returnType = mappingType->valueType();
|
||||
returnName = mappingType->valueName();
|
||||
}
|
||||
else if (auto arrayType = dynamic_cast<ArrayType const*>(returnType))
|
||||
{
|
||||
@@ -2834,7 +2836,7 @@ FunctionType::FunctionType(VariableDeclaration const& _varDecl):
|
||||
DataLocation::Memory,
|
||||
returnType
|
||||
));
|
||||
m_returnParameterNames.emplace_back("");
|
||||
m_returnParameterNames.emplace_back(returnName);
|
||||
}
|
||||
|
||||
solAssert(
|
||||
|
||||
@@ -1510,8 +1510,8 @@ private:
|
||||
class MappingType: public CompositeType
|
||||
{
|
||||
public:
|
||||
MappingType(Type const* _keyType, Type const* _valueType):
|
||||
m_keyType(_keyType), m_valueType(_valueType) {}
|
||||
MappingType(Type const* _keyType, ASTString _keyName, Type const* _valueType, ASTString _valueName):
|
||||
m_keyType(_keyType), m_keyName(_keyName), m_valueType(_valueType), m_valueName(_valueName) {}
|
||||
|
||||
Category category() const override { return Category::Mapping; }
|
||||
|
||||
@@ -1531,14 +1531,18 @@ public:
|
||||
std::vector<std::tuple<std::string, Type const*>> makeStackItems() const override;
|
||||
|
||||
Type const* keyType() const { return m_keyType; }
|
||||
ASTString keyName() const { return m_keyName; }
|
||||
Type const* valueType() const { return m_valueType; }
|
||||
ASTString valueName() const { return m_valueName; }
|
||||
|
||||
protected:
|
||||
std::vector<Type const*> decomposition() const override { return {m_valueType}; }
|
||||
|
||||
private:
|
||||
Type const* m_keyType;
|
||||
ASTString m_keyName;
|
||||
Type const* m_valueType;
|
||||
ASTString m_valueName;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user