aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/parsing/Token.cpp
diff options
context:
space:
mode:
authorRJ Catalano <rcatalano@macsales.com>2016-02-09 05:43:22 +0800
committerRJ Catalano <rcatalano@macsales.com>2016-02-19 01:22:52 +0800
commit7b918a7bc7a3c619682266b1c2566dacb9dcc765 (patch)
treea8763b90b26cafff938c3cbc261fa85627ac4a8a /libsolidity/parsing/Token.cpp
parentfca27b9ea00eb580f771820e967f62b58478c9a2 (diff)
downloaddexon-solidity-7b918a7bc7a3c619682266b1c2566dacb9dcc765.tar
dexon-solidity-7b918a7bc7a3c619682266b1c2566dacb9dcc765.tar.gz
dexon-solidity-7b918a7bc7a3c619682266b1c2566dacb9dcc765.tar.bz2
dexon-solidity-7b918a7bc7a3c619682266b1c2566dacb9dcc765.tar.lz
dexon-solidity-7b918a7bc7a3c619682266b1c2566dacb9dcc765.tar.xz
dexon-solidity-7b918a7bc7a3c619682266b1c2566dacb9dcc765.tar.zst
dexon-solidity-7b918a7bc7a3c619682266b1c2566dacb9dcc765.zip
changes to redefine the token list, the scanner, and the parser and how they pass around variable types of different sizes
not ready for change to FixedPoint just yet made this more const correct and added a switch statement for easier reading
Diffstat (limited to 'libsolidity/parsing/Token.cpp')
-rw-r--r--libsolidity/parsing/Token.cpp40
1 files changed, 39 insertions, 1 deletions
diff --git a/libsolidity/parsing/Token.cpp b/libsolidity/parsing/Token.cpp
index cda639fb..7ea94112 100644
--- a/libsolidity/parsing/Token.cpp
+++ b/libsolidity/parsing/Token.cpp
@@ -50,6 +50,44 @@ namespace dev
namespace solidity
{
+bool ElementaryTypeNameToken::isElementaryTypeName(Token::Value _baseType, string const& _info)
+{
+ if (!Token::isElementaryTypeName(_baseType))
+ return false;
+ string baseType = Token::toString(_baseType);
+ if (baseType.find('M') == string::npos)
+ return true;
+ short m;
+ m = stoi(_info.substr(_info.find_first_of("0123456789")));
+
+ if (baseType == "bytesM")
+ return (0 < m && m <= 32) ? true : false;
+ else if (baseType == "uintM" || baseType == "intM")
+ return (0 < m && m <= 256 && m % 8 == 0) ? true : false;
+ else if (baseType == "ufixedMxN" || baseType == "fixedMxN")
+ {
+ short n;
+ m = stoi(_info.substr(_info.find_first_of("0123456789"), _info.find_last_of("x") - 1));
+ n = stoi(_info.substr(_info.find_last_of("x") + 1));
+ return (0 < n + m && n + m <= 256 && ((n % 8 == 0) && (m % 8 == 0)));
+ }
+ return false;
+}
+
+tuple<string, unsigned int, unsigned int> ElementaryTypeNameToken::setTypes(Token::Value _baseType, string const& _toSet)
+{
+ string baseType = Token::toString(_baseType);
+ if (_toSet.find_first_of("0123456789") == string::npos)
+ return make_tuple(baseType, 0, 0);
+ baseType = baseType.substr(0, baseType.find('M') - 1) + _toSet;
+ size_t index = _toSet.find('x') == string::npos ? string::npos : _toSet.find('x') - 1;
+ unsigned int m = stoi(_toSet.substr(0, index));
+ unsigned int n = 0;
+ if (baseType == "fixed" || baseType == "ufixed")
+ n = stoi(_toSet.substr(_toSet.find('x') + 1));
+ return make_tuple(baseType, m, n);
+}
+
#define T(name, string, precedence) #name,
char const* const Token::m_name[NUM_TOKENS] =
{
@@ -80,7 +118,7 @@ char const Token::m_tokenType[] =
{
TOKEN_LIST(KT, KK)
};
-Token::Value Token::fromIdentifierOrKeyword(const std::string& _name)
+Token::Value Token::fromIdentifierOrKeyword(const string& _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.