diff options
author | RJ Catalano <rcatalano@macsales.com> | 2016-03-08 02:29:41 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2016-03-12 00:49:32 +0800 |
commit | 953e92b6f53ffee90cac3a79828a668cf1a55435 (patch) | |
tree | bbddc34aeec1e0afe3b32f406727ad8fe6824c05 | |
parent | 29b74be413ea2661f2fa181bff89bef2371deb51 (diff) | |
download | dexon-solidity-953e92b6f53ffee90cac3a79828a668cf1a55435.tar.gz dexon-solidity-953e92b6f53ffee90cac3a79828a668cf1a55435.tar.zst dexon-solidity-953e92b6f53ffee90cac3a79828a668cf1a55435.zip |
added from identifier or keyword handling of fixed types
-rw-r--r-- | libsolidity/parsing/Token.cpp | 34 | ||||
-rw-r--r-- | libsolidity/parsing/Token.h | 9 |
2 files changed, 37 insertions, 6 deletions
diff --git a/libsolidity/parsing/Token.cpp b/libsolidity/parsing/Token.cpp index 78a90559..9e8bc503 100644 --- a/libsolidity/parsing/Token.cpp +++ b/libsolidity/parsing/Token.cpp @@ -66,6 +66,13 @@ void ElementaryTypeNameToken::assertDetails(Token::Value _baseType, unsigned con "No elementary type " + string(Token::toString(_baseType)) + to_string(_first) + "." ); } + else if (_baseType == Token::UFixedMxN || _baseType == Token::FixedMxN) + { + solAssert( + _first + _second <= 256 && _first % 8 == 0 && _second % 8 == 0, + "No elementary type " + string(Token::toString(_baseType)) + to_string(_first) + "x" + to_string(_second) + "." + ); + } m_token = _baseType; m_firstNumber = _first; m_secondNumber = _second; @@ -101,7 +108,7 @@ char const Token::m_tokenType[] = { TOKEN_LIST(KT, KK) }; -unsigned Token::extractM(string const& _literal) +unsigned Token::extractUnsigned(string const& _literal) { try { @@ -112,6 +119,10 @@ unsigned Token::extractM(string const& _literal) { return 0; } + catch (invalid_argument& e) + { + return 1; + } } tuple<Token::Value, unsigned short, unsigned short> Token::fromIdentifierOrKeyword(string const& _literal) { @@ -120,7 +131,7 @@ tuple<Token::Value, unsigned short, unsigned short> Token::fromIdentifierOrKeywo { string baseType(_literal.begin(), positionM); auto positionX = find_if_not(positionM, _literal.end(), ::isdigit); - unsigned short m = extractM(string(positionM, positionX)); + unsigned short m = extractUnsigned(string(positionM, positionX)); Token::Value keyword = keywordByName(baseType); if (keyword == Token::Bytes) { @@ -137,6 +148,25 @@ tuple<Token::Value, unsigned short, unsigned short> Token::fromIdentifierOrKeywo return make_tuple(Token::IntM, m, 0); } } + else if (keyword == Token::UFixed || keyword == Token::Fixed) + { + auto positionN = find_if_not(positionX + 1, _literal.end(), ::isdigit); + unsigned short n = extractUnsigned(string(positionX + 1, positionN)); + if ( + 0 < m + n && + m + n <= 256 && + m % 8 == 0 && + n % 8 == 0 && + positionN == _literal.end() && + *positionX == 'x' + ) + { + if (keyword == Token::UFixed) + return make_tuple(Token::UFixed, m, n); + else + return make_tuple(Token::Fixed, m, n); + } + } return make_tuple(Token::Identifier, 0, 0); } return make_tuple(keywordByName(_literal), 0, 0); diff --git a/libsolidity/parsing/Token.h b/libsolidity/parsing/Token.h index 59b5e520..c81e4210 100644 --- a/libsolidity/parsing/Token.h +++ b/libsolidity/parsing/Token.h @@ -305,10 +305,11 @@ public: static std::tuple<Token::Value, unsigned short, unsigned short> fromIdentifierOrKeyword(std::string const& _literal); private: - // extractM provides a safe way to extract numbers, - // if out_of_range error is thrown, they returns 0s, therefore securing - // the variable's identity as an identifier. - static unsigned extractM(std::string const& _literal); + // extractUnsigned provides a safe way to extract numbers, + // the variable's identity as an identifier. If an invalid conversion + // error is thrown (usually in the case of grabbing N from a fixed type) + // then a 1 is thrown to purposely ensure that it will declare itself as an identifier + static unsigned extractUnsigned(std::string const& _literal); // @returns the keyword with name @a _name or Token::Identifier of no such keyword exists. static Token::Value keywordByName(std::string const& _name); static char const* const m_name[NUM_TOKENS]; |