diff options
author | Yoichi Hirai <i@yoichihirai.com> | 2016-09-07 23:41:12 +0800 |
---|---|---|
committer | Yoichi Hirai <i@yoichihirai.com> | 2016-09-10 01:11:15 +0800 |
commit | c861cf579dc4c1303d6d215b5b31f930e1d6477e (patch) | |
tree | 0705a10a55d5a14696bb8b5a2fb0a858596f0666 /libsolidity/formal/Why3Translator.cpp | |
parent | 00e8b059ea0ecd4a945657eabed17293dc73024a (diff) | |
download | dexon-solidity-c861cf579dc4c1303d6d215b5b31f930e1d6477e.tar dexon-solidity-c861cf579dc4c1303d6d215b5b31f930e1d6477e.tar.gz dexon-solidity-c861cf579dc4c1303d6d215b5b31f930e1d6477e.tar.bz2 dexon-solidity-c861cf579dc4c1303d6d215b5b31f930e1d6477e.tar.lz dexon-solidity-c861cf579dc4c1303d6d215b5b31f930e1d6477e.tar.xz 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/Why3Translator.cpp')
-rw-r--r-- | libsolidity/formal/Why3Translator.cpp | 14 |
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 ""; } |