mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
helper function in scanner and corresponding edits to parserBase
This commit is contained in:
parent
427b9557d6
commit
9404600b3f
@ -49,10 +49,7 @@ void ParserBase::expectToken(Token::Value _value)
|
|||||||
{
|
{
|
||||||
if (Token::isElementaryTypeName(tok)) //for the sake of accuracy in reporting
|
if (Token::isElementaryTypeName(tok)) //for the sake of accuracy in reporting
|
||||||
{
|
{
|
||||||
unsigned firstSize;
|
ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken();
|
||||||
unsigned secondSize;
|
|
||||||
tie(firstSize, secondSize) = m_scanner->currentTokenInfo();
|
|
||||||
ElementaryTypeNameToken elemTypeName(tok, firstSize, secondSize);
|
|
||||||
fatalParserError(
|
fatalParserError(
|
||||||
string("Expected token ") +
|
string("Expected token ") +
|
||||||
string(Token::name(_value)) +
|
string(Token::name(_value)) +
|
||||||
@ -80,10 +77,7 @@ Token::Value ParserBase::expectAssignmentOperator()
|
|||||||
{
|
{
|
||||||
if (Token::isElementaryTypeName(op)) //for the sake of accuracy in reporting
|
if (Token::isElementaryTypeName(op)) //for the sake of accuracy in reporting
|
||||||
{
|
{
|
||||||
unsigned firstSize;
|
ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken();
|
||||||
unsigned secondSize;
|
|
||||||
tie(firstSize, secondSize) = m_scanner->currentTokenInfo();
|
|
||||||
ElementaryTypeNameToken elemTypeName(op, firstSize, secondSize);
|
|
||||||
fatalParserError(
|
fatalParserError(
|
||||||
string("Expected assignment operator, got '") +
|
string("Expected assignment operator, got '") +
|
||||||
elemTypeName.toString() +
|
elemTypeName.toString() +
|
||||||
@ -108,10 +102,7 @@ ASTPointer<ASTString> ParserBase::expectIdentifierToken()
|
|||||||
{
|
{
|
||||||
if (Token::isElementaryTypeName(id)) //for the sake of accuracy in reporting
|
if (Token::isElementaryTypeName(id)) //for the sake of accuracy in reporting
|
||||||
{
|
{
|
||||||
unsigned firstSize;
|
ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken();
|
||||||
unsigned secondSize;
|
|
||||||
tie(firstSize, secondSize) = m_scanner->currentTokenInfo();
|
|
||||||
ElementaryTypeNameToken elemTypeName(id, firstSize, secondSize);
|
|
||||||
fatalParserError(
|
fatalParserError(
|
||||||
string("Expected identifier, got '") +
|
string("Expected identifier, got '") +
|
||||||
elemTypeName.toString() +
|
elemTypeName.toString() +
|
||||||
|
@ -119,6 +119,13 @@ public:
|
|||||||
{
|
{
|
||||||
return m_currentToken.token;
|
return m_currentToken.token;
|
||||||
}
|
}
|
||||||
|
ElementaryTypeNameToken currentElementaryTypeNameToken()
|
||||||
|
{
|
||||||
|
unsigned firstSize;
|
||||||
|
unsigned secondSize;
|
||||||
|
std::tie(firstSize, secondSize) = m_currentToken.extendedTokenInfo;
|
||||||
|
return ElementaryTypeNameToken(m_currentToken.token, firstSize, secondSize);
|
||||||
|
}
|
||||||
|
|
||||||
SourceLocation currentLocation() const { return m_currentToken.location; }
|
SourceLocation currentLocation() const { return m_currentToken.location; }
|
||||||
std::string const& currentLiteral() const { return m_currentToken.literal; }
|
std::string const& currentLiteral() const { return m_currentToken.literal; }
|
||||||
|
@ -132,6 +132,7 @@ tuple<Token::Value, unsigned int, unsigned int> Token::fromIdentifierOrKeyword(s
|
|||||||
Token::Value keyword = keywordByName(baseType);
|
Token::Value keyword = keywordByName(baseType);
|
||||||
if (keyword == Token::Bytes)
|
if (keyword == Token::Bytes)
|
||||||
{
|
{
|
||||||
|
solAssert(m != -1, "Invalid type M in fixed command. Should not reach here.");
|
||||||
if (0 < m && m <= 32 && positionX == _literal.end())
|
if (0 < m && m <= 32 && positionX == _literal.end())
|
||||||
return make_tuple(Token::BytesM, m, 0);
|
return make_tuple(Token::BytesM, m, 0);
|
||||||
}
|
}
|
||||||
@ -139,6 +140,7 @@ tuple<Token::Value, unsigned int, unsigned int> Token::fromIdentifierOrKeyword(s
|
|||||||
{
|
{
|
||||||
if (0 < m && m <= 256 && m % 8 == 0 && positionX == _literal.end())
|
if (0 < m && m <= 256 && m % 8 == 0 && positionX == _literal.end())
|
||||||
{
|
{
|
||||||
|
solAssert(m != -1, "Invalid type M in fixed command. Should not reach here.");
|
||||||
if (keyword == Token::UInt)
|
if (keyword == Token::UInt)
|
||||||
return make_tuple(Token::UIntM, m, 0);
|
return make_tuple(Token::UIntM, m, 0);
|
||||||
else
|
else
|
||||||
@ -160,6 +162,7 @@ tuple<Token::Value, unsigned int, unsigned int> Token::fromIdentifierOrKeyword(s
|
|||||||
m % 8 == 0 &&
|
m % 8 == 0 &&
|
||||||
n % 8 == 0
|
n % 8 == 0
|
||||||
) {
|
) {
|
||||||
|
solAssert(n != -1, "Invalid type N in fixed command. Should not reach here.");
|
||||||
if (keyword == Token::UFixed)
|
if (keyword == Token::UFixed)
|
||||||
return make_tuple(Token::UFixedMxN, m, n);
|
return make_tuple(Token::UFixedMxN, m, n);
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user