diff options
author | chriseth <c@ethdev.com> | 2016-03-12 00:53:33 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2016-03-12 00:53:33 +0800 |
commit | 1f9578cea3f7ea1982ba2288cd3238bfe791b348 (patch) | |
tree | 9cc3e20fde1c8c89afd3ca33a6c4b067c448e4bc /libsolidity/parsing | |
parent | 60a21c6487743578af6fd4e1540a36a2b80fcac7 (diff) | |
parent | 1bf87c6c2b90406d8a59aa928a9fe43a169e157a (diff) | |
download | dexon-solidity-1f9578cea3f7ea1982ba2288cd3238bfe791b348.tar dexon-solidity-1f9578cea3f7ea1982ba2288cd3238bfe791b348.tar.gz dexon-solidity-1f9578cea3f7ea1982ba2288cd3238bfe791b348.tar.bz2 dexon-solidity-1f9578cea3f7ea1982ba2288cd3238bfe791b348.tar.lz dexon-solidity-1f9578cea3f7ea1982ba2288cd3238bfe791b348.tar.xz dexon-solidity-1f9578cea3f7ea1982ba2288cd3238bfe791b348.tar.zst dexon-solidity-1f9578cea3f7ea1982ba2288cd3238bfe791b348.zip |
Merge pull request #429 from chriseth/keywords
Breaking changes for version 0.3.0
Diffstat (limited to 'libsolidity/parsing')
-rw-r--r-- | libsolidity/parsing/Parser.h | 4 | ||||
-rw-r--r-- | libsolidity/parsing/Scanner.h | 6 | ||||
-rw-r--r-- | libsolidity/parsing/Token.cpp | 43 | ||||
-rw-r--r-- | libsolidity/parsing/Token.h | 22 |
4 files changed, 54 insertions, 21 deletions
diff --git a/libsolidity/parsing/Parser.h b/libsolidity/parsing/Parser.h index 9db3b3c4..a093cc5b 100644 --- a/libsolidity/parsing/Parser.h +++ b/libsolidity/parsing/Parser.h @@ -124,12 +124,12 @@ private: /// For source code of the form "a[][8]" ("IndexAccessStructure"), this is not possible to /// decide with constant look-ahead. LookAheadInfo peekStatementType() const; - /// Returns a typename parsed in look-ahead fashion from something like "a.b[8][2**70]". + /// @returns a typename parsed in look-ahead fashion from something like "a.b[8][2**70]". ASTPointer<TypeName> typeNameIndexAccessStructure( std::vector<ASTPointer<PrimaryExpression>> const& _path, std::vector<std::pair<ASTPointer<Expression>, SourceLocation>> const& _indices ); - /// Returns an expression parsed in look-ahead fashion from something like "a.b[8][2**70]". + /// @returns an expression parsed in look-ahead fashion from something like "a.b[8][2**70]". ASTPointer<Expression> expressionFromIndexAccessStructure( std::vector<ASTPointer<PrimaryExpression>> const& _path, std::vector<std::pair<ASTPointer<Expression>, SourceLocation>> const& _indices diff --git a/libsolidity/parsing/Scanner.h b/libsolidity/parsing/Scanner.h index 8dde922d..cffcec8e 100644 --- a/libsolidity/parsing/Scanner.h +++ b/libsolidity/parsing/Scanner.h @@ -108,13 +108,13 @@ public: /// Resets scanner to the start of input. void reset(); - /// Returns the next token and advances input + /// @returns the next token and advances input Token::Value next(); ///@{ ///@name Information about the current token - /// Returns the current token + /// @returns the current token Token::Value currentToken() { return m_currentToken.token; @@ -138,7 +138,7 @@ public: ///@{ ///@name Information about the next token - /// Returns the next token without advancing input. + /// @returns the next token without advancing input. Token::Value peekNextToken() const { return m_nextToken.token; } SourceLocation peekLocation() const { return m_nextToken.location; } std::string const& peekLiteral() const { return m_nextToken.literal; } diff --git a/libsolidity/parsing/Token.cpp b/libsolidity/parsing/Token.cpp index 78a90559..3812a83f 100644 --- a/libsolidity/parsing/Token.cpp +++ b/libsolidity/parsing/Token.cpp @@ -42,6 +42,7 @@ #include <map> #include <libsolidity/parsing/Token.h> +#include <boost/range/iterator_range.hpp> using namespace std; @@ -66,6 +67,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,26 +109,26 @@ char const Token::m_tokenType[] = { TOKEN_LIST(KT, KK) }; -unsigned Token::extractM(string const& _literal) +int Token::parseSize(string::const_iterator _begin, string::const_iterator _end) { try { - unsigned short m = stoi(_literal); + unsigned int m = boost::lexical_cast<int>(boost::make_iterator_range(_begin, _end)); return m; } - catch(out_of_range& e) + 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 = extractM(string(positionM, positionX)); + int m = parseSize(positionM, positionX); Token::Value keyword = keywordByName(baseType); if (keyword == Token::Bytes) { @@ -137,6 +145,29 @@ tuple<Token::Value, unsigned short, unsigned short> Token::fromIdentifierOrKeywo return make_tuple(Token::IntM, m, 0); } } + else if (keyword == Token::UFixed || keyword == Token::Fixed) + { + if ( + positionM < positionX && + positionX < _literal.end() && + *positionX == 'x' && + all_of(positionX + 1, _literal.end(), ::isdigit) + ) { + int n = parseSize(positionX + 1, _literal.end()); + if ( + 0 < m && m < 256 && + 0 < n && n < 256 && + m + n <= 256 && + m % 8 == 0 && + n % 8 == 0 + ) { + 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 a64eded5..31646f8d 100644 --- a/libsolidity/parsing/Token.h +++ b/libsolidity/parsing/Token.h @@ -143,6 +143,7 @@ namespace solidity \ /* Keywords */ \ K(Anonymous, "anonymous", 0) \ + K(Assembly, "assembly", 0) \ K(Break, "break", 0) \ K(Const, "constant", 0) \ K(Continue, "continue", 0) \ @@ -198,8 +199,10 @@ namespace solidity K(String, "string", 0) \ K(Address, "address", 0) \ K(Bool, "bool", 0) \ - K(Real, "real", 0) \ - K(UReal, "ureal", 0) \ + K(Fixed, "fixed", 0) \ + T(FixedMxN, "fixedMxN", 0) \ + K(UFixed, "ufixed", 0) \ + T(UFixedMxN, "ufixedMxN", 0) \ T(TypesEnd, NULL, 0) /* used as type enum end marker */ \ \ /* Literals */ \ @@ -218,6 +221,7 @@ namespace solidity K(Case, "case", 0) \ K(Catch, "catch", 0) \ K(Final, "final", 0) \ + K(Inline, "inline", 0) \ K(Let, "let", 0) \ K(Match, "match", 0) \ K(Of, "of", 0) \ @@ -249,7 +253,7 @@ public: }; #undef T - // Returns a string corresponding to the C++ token name + // @returns a string corresponding to the C++ token name // (e.g. "LT" for the token LT). static char const* name(Value tok) { @@ -283,7 +287,7 @@ public: static bool isEtherSubdenomination(Value op) { return op == SubWei || op == SubSzabo || op == SubFinney || op == SubEther; } static bool isTimeSubdenomination(Value op) { return op == SubSecond || op == SubMinute || op == SubHour || op == SubDay || op == SubWeek || op == SubYear; } - // Returns a string corresponding to the JS token string + // @returns a string corresponding to the JS token string // (.e., "<" for the token LT) or NULL if the token doesn't // have a (unique) string (e.g. an IDENTIFIER). static char const* toString(Value tok) @@ -292,7 +296,7 @@ public: return m_string[tok]; } - // Returns the precedence > 0 for binary and compare + // @returns the precedence > 0 for binary and compare // operators; returns 0 otherwise. static int precedence(Value tok) { @@ -300,13 +304,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: - // 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); + // @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]; |