diff options
author | RJ Catalano <rcatalano@macsales.com> | 2016-03-11 03:25:14 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2016-03-12 00:50:09 +0800 |
commit | d0054a8d294901a0107e37d19ab6cb858d3a72f1 (patch) | |
tree | 07d9f524454b5cd70607f88b4232fb5da9469729 /libsolidity | |
parent | d0bb87ae88602f4afc091d9cda1be352258a6df9 (diff) | |
download | dexon-solidity-d0054a8d294901a0107e37d19ab6cb858d3a72f1.tar dexon-solidity-d0054a8d294901a0107e37d19ab6cb858d3a72f1.tar.gz dexon-solidity-d0054a8d294901a0107e37d19ab6cb858d3a72f1.tar.bz2 dexon-solidity-d0054a8d294901a0107e37d19ab6cb858d3a72f1.tar.lz dexon-solidity-d0054a8d294901a0107e37d19ab6cb858d3a72f1.tar.xz dexon-solidity-d0054a8d294901a0107e37d19ab6cb858d3a72f1.tar.zst dexon-solidity-d0054a8d294901a0107e37d19ab6cb858d3a72f1.zip |
added keyword type and some tests, changes in lexical cast
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/parsing/Token.cpp | 16 | ||||
-rw-r--r-- | libsolidity/parsing/Token.h | 7 |
2 files changed, 12 insertions, 11 deletions
diff --git a/libsolidity/parsing/Token.cpp b/libsolidity/parsing/Token.cpp index 4634c510..158ce516 100644 --- a/libsolidity/parsing/Token.cpp +++ b/libsolidity/parsing/Token.cpp @@ -109,26 +109,26 @@ char const Token::m_tokenType[] = { TOKEN_LIST(KT, KK) }; -unsigned Token::extractUnsigned(string::const_iterator _begin, string::const_iterator _end) +int Token::parseSize(string::const_iterator _begin, string::const_iterator _end) { try { - unsigned short m = boost::lexical_cast<unsigned short>(boost::make_iterator_range(_begin, _end)); + unsigned int m = boost::lexical_cast<int>(boost::make_iterator_range(_begin, _end)); return m; } - catch(const boost::bad_lexical_cast &) + catch(boost::bad_lexical_cast const&) { - return 0; + return -1; } } -tuple<Token::Value, unsigned short, unsigned short> Token::fromIdentifierOrKeyword(string const& _literal) +tuple<Token::Value, unsigned int, unsigned int> Token::fromIdentifierOrKeyword(string const& _literal) { auto positionM = find_if(_literal.begin(), _literal.end(), ::isdigit); if (positionM != _literal.end()) { string baseType(_literal.begin(), positionM); auto positionX = find_if_not(positionM, _literal.end(), ::isdigit); - unsigned short m = extractUnsigned(positionM, positionX); + int m = parseSize(positionM, positionX); Token::Value keyword = keywordByName(baseType); if (keyword == Token::Bytes) { @@ -147,8 +147,8 @@ tuple<Token::Value, unsigned short, unsigned short> Token::fromIdentifierOrKeywo } else if (keyword == Token::UFixed || keyword == Token::Fixed) { - auto positionN = find_if_not(positionX++, _literal.end(), ::isdigit); - unsigned short n = extractUnsigned(positionX++, positionN); + auto positionN = find_if_not(++positionX, _literal.end(), ::isdigit); + int n = parseSize(++positionX, positionN); if ( 0 < m + n && m + n <= 256 && diff --git a/libsolidity/parsing/Token.h b/libsolidity/parsing/Token.h index 64a3447a..b8ad7471 100644 --- a/libsolidity/parsing/Token.h +++ b/libsolidity/parsing/Token.h @@ -231,6 +231,7 @@ namespace solidity K(Type, "type", 0) \ K(TypeOf, "typeof", 0) \ K(Using, "using", 0) \ + T(Timestamp, "timestamp", 0) \ /* Illegal token - not able to scan. */ \ T(Illegal, "ILLEGAL", 0) \ \ @@ -304,11 +305,11 @@ public: return m_precedence[tok]; } - static std::tuple<Token::Value, unsigned short, unsigned short> fromIdentifierOrKeyword(std::string const& _literal); + static std::tuple<Token::Value, unsigned int, unsigned int> fromIdentifierOrKeyword(std::string const& _literal); private: - // @returns 0 on error (invalid digit or number too large) - static unsigned extractUnsigned(std::string::const_iterator _begin, std::string::const_iterator _end); + // @returns -1 on error (invalid digit or number too large) + static int parseSize(std::string::const_iterator _begin, std::string::const_iterator _end); // @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]; |