aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/formal
diff options
context:
space:
mode:
authorYoichi Hirai <i@yoichihirai.com>2016-09-07 23:41:12 +0800
committerYoichi Hirai <i@yoichihirai.com>2016-09-10 01:11:15 +0800
commitc861cf579dc4c1303d6d215b5b31f930e1d6477e (patch)
tree0705a10a55d5a14696bb8b5a2fb0a858596f0666 /libsolidity/formal
parent00e8b059ea0ecd4a945657eabed17293dc73024a (diff)
downloaddexon-solidity-c861cf579dc4c1303d6d215b5b31f930e1d6477e.tar.gz
dexon-solidity-c861cf579dc4c1303d6d215b5b31f930e1d6477e.tar.zst
dexon-solidity-c861cf579dc4c1303d6d215b5b31f930e1d6477e.zip
Translate mapping types into Why3 arrays when keys are integers
Even when the keys are signed the translation is supposed to work because Why3 arrays allow negative indices.
Diffstat (limited to 'libsolidity/formal')
-rw-r--r--libsolidity/formal/Why3Translator.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/libsolidity/formal/Why3Translator.cpp b/libsolidity/formal/Why3Translator.cpp
index b441b150..9a4a5cf5 100644
--- a/libsolidity/formal/Why3Translator.cpp
+++ b/libsolidity/formal/Why3Translator.cpp
@@ -77,12 +77,26 @@ string Why3Translator::toFormalType(Type const& _type) const
return "uint256";
}
else if (auto type = dynamic_cast<ArrayType const*>(&_type))
+ {
if (!type->isByteArray() && type->isDynamicallySized() && type->dataStoredIn(DataLocation::Memory))
{
string base = toFormalType(*type->baseType());
if (!base.empty())
return "array " + base;
}
+ }
+ else if (auto mappingType = dynamic_cast<MappingType const*>(&_type))
+ {
+ solAssert(mappingType->keyType(), "A mappingType misses a keyType.");
+ if (dynamic_cast<IntegerType const*>(&*mappingType->keyType()))
+ {
+ //@TODO Use the information from the key type and specify the length of the array as an invariant.
+ // Also the constructor need to specify the length of the array.
+ string valueType = toFormalType(*mappingType->valueType());
+ if (!valueType.empty())
+ return "array " + valueType;
+ }
+ }
return "";
}