aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorRJ Catalano <rcatalano@macsales.com>2016-02-19 00:34:07 +0800
committerRJ Catalano <rcatalano@macsales.com>2016-02-19 01:23:00 +0800
commit9b67969fd648fd5477e9b5d90870fddbd187e4d6 (patch)
treef826c1b99fec02e0cde7770f6cd121e99e56b595 /libsolidity
parentd2c0712f36ce4a9148756458533a91bca1cfe44b (diff)
downloaddexon-solidity-9b67969fd648fd5477e9b5d90870fddbd187e4d6.tar.gz
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')
-rw-r--r--libsolidity/ast/Types.cpp4
-rw-r--r--libsolidity/parsing/Token.cpp30
-rw-r--r--libsolidity/parsing/Token.h2
3 files changed, 20 insertions, 16 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index 250ec102..bca83d59 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -117,9 +117,9 @@ u256 const& MemberList::storageSize() const
TypePointer Type::fromElementaryTypeName(ElementaryTypeNameToken const& _type)
{
- string tokenString = _type.toString();
solAssert(Token::isElementaryTypeName(_type.token()),
- "Expected an elementary type name but got " + tokenString);
+ "Expected an elementary type name but got " + _type.toString()
+ );
Token::Value token = _type.token();
unsigned int m = _type.firstNumber();
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
-
}
}
diff --git a/libsolidity/parsing/Token.h b/libsolidity/parsing/Token.h
index 3de204e0..a64eded5 100644
--- a/libsolidity/parsing/Token.h
+++ b/libsolidity/parsing/Token.h
@@ -307,6 +307,8 @@ private:
// 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 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];
static char const* const m_string[NUM_TOKENS];
static int8_t const m_precedence[NUM_TOKENS];