diff options
author | RJ Catalano <rcatalano@macsales.com> | 2016-02-19 00:34:07 +0800 |
---|---|---|
committer | RJ Catalano <rcatalano@macsales.com> | 2016-02-19 01:23:00 +0800 |
commit | 9b67969fd648fd5477e9b5d90870fddbd187e4d6 (patch) | |
tree | f826c1b99fec02e0cde7770f6cd121e99e56b595 /libsolidity/parsing/Token.cpp | |
parent | d2c0712f36ce4a9148756458533a91bca1cfe44b (diff) | |
download | dexon-solidity-9b67969fd648fd5477e9b5d90870fddbd187e4d6.tar dexon-solidity-9b67969fd648fd5477e9b5d90870fddbd187e4d6.tar.gz dexon-solidity-9b67969fd648fd5477e9b5d90870fddbd187e4d6.tar.bz2 dexon-solidity-9b67969fd648fd5477e9b5d90870fddbd187e4d6.tar.lz dexon-solidity-9b67969fd648fd5477e9b5d90870fddbd187e4d6.tar.xz dexon-solidity-9b67969fd648fd5477e9b5d90870fddbd187e4d6.tar.zst dexon-solidity-9b67969fd648fd5477e9b5d90870fddbd187e4d6.zip |
further optimization, splitting function into pieces
generating strings on the fly, changed name, and added two tests
Diffstat (limited to 'libsolidity/parsing/Token.cpp')
-rw-r--r-- | libsolidity/parsing/Token.cpp | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/libsolidity/parsing/Token.cpp b/libsolidity/parsing/Token.cpp index 693ed420..78a90559 100644 --- a/libsolidity/parsing/Token.cpp +++ b/libsolidity/parsing/Token.cpp @@ -53,7 +53,6 @@ namespace solidity void ElementaryTypeNameToken::assertDetails(Token::Value _baseType, unsigned const& _first, unsigned const& _second) { solAssert(Token::isElementaryTypeName(_baseType), ""); - string tokenString = Token::toString(_baseType); if (_baseType == Token::BytesM) { solAssert(_second == 0, "There should not be a second size argument to type bytesM."); @@ -61,10 +60,10 @@ void ElementaryTypeNameToken::assertDetails(Token::Value _baseType, unsigned con } else if (_baseType == Token::UIntM || _baseType == Token::IntM) { - solAssert(_second == 0, "There should not be a second size argument to type " + tokenString + "."); + solAssert(_second == 0, "There should not be a second size argument to type " + string(Token::toString(_baseType)) + "."); solAssert( _first <= 256 && _first % 8 == 0, - "No elementary type " + tokenString + to_string(_first) + "." + "No elementary type " + string(Token::toString(_baseType)) + to_string(_first) + "." ); } m_token = _baseType; @@ -120,26 +119,30 @@ tuple<Token::Value, unsigned short, unsigned short> Token::fromIdentifierOrKeywo if (positionM != _literal.end()) { string baseType(_literal.begin(), positionM); - auto positionX = find(positionM, _literal.end(), 'x'); + auto positionX = find_if_not(positionM, _literal.end(), ::isdigit); unsigned short m = extractM(string(positionM, positionX)); - if (baseType == toString(Token::Bytes)) + Token::Value keyword = keywordByName(baseType); + if (keyword == Token::Bytes) { - if (0 < m && m <= 32) + if (0 < m && m <= 32 && positionX == _literal.end()) return make_tuple(Token::BytesM, m, 0); - return make_tuple(Token::Identifier, 0, 0); } - else if (baseType == toString(Token::UInt) || baseType == toString(Token::Int)) + else if (keyword == Token::UInt || keyword == Token::Int) { - if (0 < m && m <= 256 && m % 8 == 0) + if (0 < m && m <= 256 && m % 8 == 0 && positionX == _literal.end()) { - if (baseType == toString(Token::UInt)) + if (keyword == Token::UInt) return make_tuple(Token::UIntM, m, 0); else return make_tuple(Token::IntM, m, 0); } - return make_tuple(Token::Identifier, 0, 0); } + return make_tuple(Token::Identifier, 0, 0); } + return make_tuple(keywordByName(_literal), 0, 0); +} +Token::Value Token::keywordByName(string const& _name) +{ // The following macros are used inside TOKEN_LIST and cause non-keyword tokens to be ignored // and keywords to be put inside the keywords variable. #define KEYWORD(name, string, precedence) {string, Token::name}, @@ -147,12 +150,11 @@ tuple<Token::Value, unsigned short, unsigned short> Token::fromIdentifierOrKeywo static const map<string, Token::Value> keywords({TOKEN_LIST(TOKEN, KEYWORD)}); #undef KEYWORD #undef TOKEN - auto it = keywords.find(_literal); - return it == keywords.end() ? make_tuple(Token::Identifier, 0, 0) : make_tuple(it->second, 0, 0); + auto it = keywords.find(_name); + return it == keywords.end() ? Token::Identifier : it->second; } #undef KT #undef KK - } } |