aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-04-05 23:02:43 +0800
committerGitHub <noreply@github.com>2018-04-05 23:02:43 +0800
commit543e1e19c73776939bb9a6c244b9749a33f3d61b (patch)
treeb2af65c50b957246fa563dc7008c4d207d58440c /libsolidity
parentd74b71a554395de42ee53ce1d16a03b7cef3fd92 (diff)
parent5b1c0506faf865d5ff056bec8094211f0fa90600 (diff)
downloaddexon-solidity-543e1e19c73776939bb9a6c244b9749a33f3d61b.tar.gz
dexon-solidity-543e1e19c73776939bb9a6c244b9749a33f3d61b.tar.zst
dexon-solidity-543e1e19c73776939bb9a6c244b9749a33f3d61b.zip
Merge pull request #3831 from ethereum/memory-suffix
Allow ``memory`` suffix for internal elementary type parsing.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/ast/Types.cpp15
-rw-r--r--libsolidity/ast/Types.h1
-rw-r--r--libsolidity/parsing/Token.cpp2
3 files changed, 15 insertions, 3 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index ac1d3b01..de359ec6 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -233,11 +233,22 @@ TypePointer Type::fromElementaryTypeName(ElementaryTypeNameToken const& _type)
TypePointer Type::fromElementaryTypeName(string const& _name)
{
+ string name = _name;
+ DataLocation location = DataLocation::Storage;
+ if (boost::algorithm::ends_with(name, " memory"))
+ {
+ name = name.substr(0, name.length() - 7);
+ location = DataLocation::Memory;
+ }
unsigned short firstNum;
unsigned short secondNum;
Token::Value token;
- tie(token, firstNum, secondNum) = Token::fromIdentifierOrKeyword(_name);
- return fromElementaryTypeName(ElementaryTypeNameToken(token, firstNum, secondNum));
+ tie(token, firstNum, secondNum) = Token::fromIdentifierOrKeyword(name);
+ auto t = fromElementaryTypeName(ElementaryTypeNameToken(token, firstNum, secondNum));
+ if (auto* ref = dynamic_cast<ReferenceType const*>(t.get()))
+ return ref->copyForLocation(location, true);
+ else
+ return t;
}
TypePointer Type::forLiteral(Literal const& _literal)
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index 2c392705..aa46520f 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -150,6 +150,7 @@ public:
/// @name Factory functions
/// Factory functions that convert an AST @ref TypeName to a Type.
static TypePointer fromElementaryTypeName(ElementaryTypeNameToken const& _type);
+ /// Converts a given elementary type name with optional suffix " memory" to a type pointer.
static TypePointer fromElementaryTypeName(std::string const& _name);
/// @}
diff --git a/libsolidity/parsing/Token.cpp b/libsolidity/parsing/Token.cpp
index 9cec0303..5ce74316 100644
--- a/libsolidity/parsing/Token.cpp
+++ b/libsolidity/parsing/Token.cpp
@@ -53,7 +53,7 @@ namespace solidity
void ElementaryTypeNameToken::assertDetails(Token::Value _baseType, unsigned const& _first, unsigned const& _second)
{
- solAssert(Token::isElementaryTypeName(_baseType), "");
+ solAssert(Token::isElementaryTypeName(_baseType), "Expected elementary type name: " + string(Token::toString(_baseType)));
if (_baseType == Token::BytesM)
{
solAssert(_second == 0, "There should not be a second size argument to type bytesM.");