mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Renames and comments.
This commit is contained in:
parent
261786d909
commit
c8b03c51a0
56
Parser.cpp
56
Parser.cpp
@ -625,11 +625,13 @@ ASTPointer<Statement> Parser::parseSimpleStatement()
|
|||||||
// These two cases are very hard to distinguish:
|
// These two cases are very hard to distinguish:
|
||||||
// x[7 * 20 + 3] a; - x[7 * 20 + 3] = 9;
|
// x[7 * 20 + 3] a; - x[7 * 20 + 3] = 9;
|
||||||
// In the first case, x is a type name, in the second it is the name of a variable.
|
// In the first case, x is a type name, in the second it is the name of a variable.
|
||||||
int isVariableDeclaration = peekVariableDeclarationStatement();
|
switch (peekStatementType())
|
||||||
if (isVariableDeclaration == 1)
|
{
|
||||||
|
case LookAheadInfo::VariableDeclarationStatement:
|
||||||
return parseVariableDeclarationStatement();
|
return parseVariableDeclarationStatement();
|
||||||
else if (isVariableDeclaration == -1)
|
case LookAheadInfo::ExpressionStatement:
|
||||||
return parseExpressionStatement();
|
return parseExpressionStatement();
|
||||||
|
}
|
||||||
|
|
||||||
// At this point, we have '(Identifier|ElementaryTypeName) "["'.
|
// At this point, we have '(Identifier|ElementaryTypeName) "["'.
|
||||||
// We parse '(Identifier|ElementaryTypeName) ( "[" Expression "]" )+' and then decide whether to hand this over
|
// We parse '(Identifier|ElementaryTypeName) ( "[" Expression "]" )+' and then decide whether to hand this over
|
||||||
@ -658,9 +660,9 @@ ASTPointer<Statement> Parser::parseSimpleStatement()
|
|||||||
while (m_scanner->getCurrentToken() == Token::LBrack);
|
while (m_scanner->getCurrentToken() == Token::LBrack);
|
||||||
|
|
||||||
if (m_scanner->getCurrentToken() == Token::Identifier)
|
if (m_scanner->getCurrentToken() == Token::Identifier)
|
||||||
return parseVariableDeclarationStatement(typeNameFromArrayIndexStructure(primary, indices));
|
return parseVariableDeclarationStatement(typeNameIndexAccessStructure(primary, indices));
|
||||||
else
|
else
|
||||||
return parseExpressionStatement(expressionFromArrayIndexStructure(primary, indices));
|
return parseExpressionStatement(expressionFromIndexAccessStructure(primary, indices));
|
||||||
}
|
}
|
||||||
|
|
||||||
ASTPointer<VariableDeclarationStatement> Parser::parseVariableDeclarationStatement(
|
ASTPointer<VariableDeclarationStatement> Parser::parseVariableDeclarationStatement(
|
||||||
@ -675,16 +677,16 @@ ASTPointer<VariableDeclarationStatement> Parser::parseVariableDeclarationStateme
|
|||||||
}
|
}
|
||||||
|
|
||||||
ASTPointer<ExpressionStatement> Parser::parseExpressionStatement(
|
ASTPointer<ExpressionStatement> Parser::parseExpressionStatement(
|
||||||
ASTPointer<Expression> const& _lookAheadArrayExpression)
|
ASTPointer<Expression> const& _lookAheadIndexAccessStructure)
|
||||||
{
|
{
|
||||||
ASTPointer<Expression> expression = parseExpression(_lookAheadArrayExpression);
|
ASTPointer<Expression> expression = parseExpression(_lookAheadIndexAccessStructure);
|
||||||
return ASTNodeFactory(*this, expression).createNode<ExpressionStatement>(expression);
|
return ASTNodeFactory(*this, expression).createNode<ExpressionStatement>(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASTPointer<Expression> Parser::parseExpression(
|
ASTPointer<Expression> Parser::parseExpression(
|
||||||
ASTPointer<Expression> const& _lookAheadArrayExpression)
|
ASTPointer<Expression> const& _lookAheadIndexAccessStructure)
|
||||||
{
|
{
|
||||||
ASTPointer<Expression> expression = parseBinaryExpression(4, _lookAheadArrayExpression);
|
ASTPointer<Expression> expression = parseBinaryExpression(4, _lookAheadIndexAccessStructure);
|
||||||
if (!Token::isAssignmentOp(m_scanner->getCurrentToken()))
|
if (!Token::isAssignmentOp(m_scanner->getCurrentToken()))
|
||||||
return expression;
|
return expression;
|
||||||
Token::Value assignmentOperator = expectAssignmentOperator();
|
Token::Value assignmentOperator = expectAssignmentOperator();
|
||||||
@ -695,9 +697,9 @@ ASTPointer<Expression> Parser::parseExpression(
|
|||||||
}
|
}
|
||||||
|
|
||||||
ASTPointer<Expression> Parser::parseBinaryExpression(int _minPrecedence,
|
ASTPointer<Expression> Parser::parseBinaryExpression(int _minPrecedence,
|
||||||
ASTPointer<Expression> const& _lookAheadArrayExpression)
|
ASTPointer<Expression> const& _lookAheadIndexAccessStructure)
|
||||||
{
|
{
|
||||||
ASTPointer<Expression> expression = parseUnaryExpression(_lookAheadArrayExpression);
|
ASTPointer<Expression> expression = parseUnaryExpression(_lookAheadIndexAccessStructure);
|
||||||
ASTNodeFactory nodeFactory(*this, expression);
|
ASTNodeFactory nodeFactory(*this, expression);
|
||||||
int precedence = Token::precedence(m_scanner->getCurrentToken());
|
int precedence = Token::precedence(m_scanner->getCurrentToken());
|
||||||
for (; precedence >= _minPrecedence; --precedence)
|
for (; precedence >= _minPrecedence; --precedence)
|
||||||
@ -713,12 +715,12 @@ ASTPointer<Expression> Parser::parseBinaryExpression(int _minPrecedence,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ASTPointer<Expression> Parser::parseUnaryExpression(
|
ASTPointer<Expression> Parser::parseUnaryExpression(
|
||||||
ASTPointer<Expression> const& _lookAheadArrayExpression)
|
ASTPointer<Expression> const& _lookAheadIndexAccessStructure)
|
||||||
{
|
{
|
||||||
ASTNodeFactory nodeFactory = _lookAheadArrayExpression ?
|
ASTNodeFactory nodeFactory = _lookAheadIndexAccessStructure ?
|
||||||
ASTNodeFactory(*this, _lookAheadArrayExpression) : ASTNodeFactory(*this);
|
ASTNodeFactory(*this, _lookAheadIndexAccessStructure) : ASTNodeFactory(*this);
|
||||||
Token::Value token = m_scanner->getCurrentToken();
|
Token::Value token = m_scanner->getCurrentToken();
|
||||||
if (!_lookAheadArrayExpression && (Token::isUnaryOp(token) || Token::isCountOp(token)))
|
if (!_lookAheadIndexAccessStructure && (Token::isUnaryOp(token) || Token::isCountOp(token)))
|
||||||
{
|
{
|
||||||
// prefix expression
|
// prefix expression
|
||||||
m_scanner->next();
|
m_scanner->next();
|
||||||
@ -729,7 +731,7 @@ ASTPointer<Expression> Parser::parseUnaryExpression(
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// potential postfix expression
|
// potential postfix expression
|
||||||
ASTPointer<Expression> subExpression = parseLeftHandSideExpression(_lookAheadArrayExpression);
|
ASTPointer<Expression> subExpression = parseLeftHandSideExpression(_lookAheadIndexAccessStructure);
|
||||||
token = m_scanner->getCurrentToken();
|
token = m_scanner->getCurrentToken();
|
||||||
if (!Token::isCountOp(token))
|
if (!Token::isCountOp(token))
|
||||||
return subExpression;
|
return subExpression;
|
||||||
@ -740,14 +742,14 @@ ASTPointer<Expression> Parser::parseUnaryExpression(
|
|||||||
}
|
}
|
||||||
|
|
||||||
ASTPointer<Expression> Parser::parseLeftHandSideExpression(
|
ASTPointer<Expression> Parser::parseLeftHandSideExpression(
|
||||||
ASTPointer<Expression> const& _lookAheadArrayExpression)
|
ASTPointer<Expression> const& _lookAheadIndexAccessStructure)
|
||||||
{
|
{
|
||||||
ASTNodeFactory nodeFactory = _lookAheadArrayExpression ?
|
ASTNodeFactory nodeFactory = _lookAheadIndexAccessStructure ?
|
||||||
ASTNodeFactory(*this, _lookAheadArrayExpression) : ASTNodeFactory(*this);
|
ASTNodeFactory(*this, _lookAheadIndexAccessStructure) : ASTNodeFactory(*this);
|
||||||
|
|
||||||
ASTPointer<Expression> expression;
|
ASTPointer<Expression> expression;
|
||||||
if (_lookAheadArrayExpression)
|
if (_lookAheadIndexAccessStructure)
|
||||||
expression = _lookAheadArrayExpression;
|
expression = _lookAheadIndexAccessStructure;
|
||||||
else if (m_scanner->getCurrentToken() == Token::New)
|
else if (m_scanner->getCurrentToken() == Token::New)
|
||||||
{
|
{
|
||||||
expectToken(Token::New);
|
expectToken(Token::New);
|
||||||
@ -889,7 +891,7 @@ pair<vector<ASTPointer<Expression>>, vector<ASTPointer<ASTString>>> Parser::pars
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Parser::peekVariableDeclarationStatement() const
|
Parser::LookAheadInfo Parser::peekStatementType() const
|
||||||
{
|
{
|
||||||
// Distinguish between variable declaration (and potentially assignment) and expression statement
|
// Distinguish between variable declaration (and potentially assignment) and expression statement
|
||||||
// (which include assignments to other expressions and pre-declared variables).
|
// (which include assignments to other expressions and pre-declared variables).
|
||||||
@ -902,13 +904,13 @@ int Parser::peekVariableDeclarationStatement() const
|
|||||||
bool mightBeTypeName = (Token::isElementaryTypeName(token) || token == Token::Identifier);
|
bool mightBeTypeName = (Token::isElementaryTypeName(token) || token == Token::Identifier);
|
||||||
if (token == Token::Mapping || token == Token::Var ||
|
if (token == Token::Mapping || token == Token::Var ||
|
||||||
(mightBeTypeName && m_scanner->peekNextToken() == Token::Identifier))
|
(mightBeTypeName && m_scanner->peekNextToken() == Token::Identifier))
|
||||||
return 1;
|
return LookAheadInfo::VariableDeclarationStatement;
|
||||||
if (mightBeTypeName && m_scanner->peekNextToken() == Token::LBrack)
|
if (mightBeTypeName && m_scanner->peekNextToken() == Token::LBrack)
|
||||||
return 0;
|
return LookAheadInfo::IndexAccessStructure;
|
||||||
return -1;
|
return LookAheadInfo::ExpressionStatement;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASTPointer<TypeName> Parser::typeNameFromArrayIndexStructure(
|
ASTPointer<TypeName> Parser::typeNameIndexAccessStructure(
|
||||||
ASTPointer<PrimaryExpression> const& _primary, vector<pair<ASTPointer<Expression>, Location>> const& _indices)
|
ASTPointer<PrimaryExpression> const& _primary, vector<pair<ASTPointer<Expression>, Location>> const& _indices)
|
||||||
{
|
{
|
||||||
ASTNodeFactory nodeFactory(*this, _primary);
|
ASTNodeFactory nodeFactory(*this, _primary);
|
||||||
@ -927,7 +929,7 @@ ASTPointer<TypeName> Parser::typeNameFromArrayIndexStructure(
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASTPointer<Expression> Parser::expressionFromArrayIndexStructure(
|
ASTPointer<Expression> Parser::expressionFromIndexAccessStructure(
|
||||||
ASTPointer<PrimaryExpression> const& _primary, vector<pair<ASTPointer<Expression>, Location>> const& _indices)
|
ASTPointer<PrimaryExpression> const& _primary, vector<pair<ASTPointer<Expression>, Location>> const& _indices)
|
||||||
{
|
{
|
||||||
ASTNodeFactory nodeFactory(*this, _primary);
|
ASTNodeFactory nodeFactory(*this, _primary);
|
||||||
|
26
Parser.h
26
Parser.h
@ -84,15 +84,15 @@ private:
|
|||||||
ASTPointer<VariableDeclarationStatement> parseVariableDeclarationStatement(
|
ASTPointer<VariableDeclarationStatement> parseVariableDeclarationStatement(
|
||||||
ASTPointer<TypeName> const& _lookAheadArrayType = ASTPointer<TypeName>());
|
ASTPointer<TypeName> const& _lookAheadArrayType = ASTPointer<TypeName>());
|
||||||
ASTPointer<ExpressionStatement> parseExpressionStatement(
|
ASTPointer<ExpressionStatement> parseExpressionStatement(
|
||||||
ASTPointer<Expression> const& _lookAheadArrayExpression = ASTPointer<Expression>());
|
ASTPointer<Expression> const& _lookAheadIndexAccessStructure = ASTPointer<Expression>());
|
||||||
ASTPointer<Expression> parseExpression(
|
ASTPointer<Expression> parseExpression(
|
||||||
ASTPointer<Expression> const& _lookAheadArrayExpression = ASTPointer<Expression>());
|
ASTPointer<Expression> const& _lookAheadIndexAccessStructure = ASTPointer<Expression>());
|
||||||
ASTPointer<Expression> parseBinaryExpression(int _minPrecedence = 4,
|
ASTPointer<Expression> parseBinaryExpression(int _minPrecedence = 4,
|
||||||
ASTPointer<Expression> const& _lookAheadArrayExpression = ASTPointer<Expression>());
|
ASTPointer<Expression> const& _lookAheadIndexAccessStructure = ASTPointer<Expression>());
|
||||||
ASTPointer<Expression> parseUnaryExpression(
|
ASTPointer<Expression> parseUnaryExpression(
|
||||||
ASTPointer<Expression> const& _lookAheadArrayExpression = ASTPointer<Expression>());
|
ASTPointer<Expression> const& _lookAheadIndexAccessStructure = ASTPointer<Expression>());
|
||||||
ASTPointer<Expression> parseLeftHandSideExpression(
|
ASTPointer<Expression> parseLeftHandSideExpression(
|
||||||
ASTPointer<Expression> const& _lookAheadArrayExpression = ASTPointer<Expression>());
|
ASTPointer<Expression> const& _lookAheadIndexAccessStructure = ASTPointer<Expression>());
|
||||||
ASTPointer<Expression> parsePrimaryExpression();
|
ASTPointer<Expression> parsePrimaryExpression();
|
||||||
std::vector<ASTPointer<Expression>> parseFunctionCallListArguments();
|
std::vector<ASTPointer<Expression>> parseFunctionCallListArguments();
|
||||||
std::pair<std::vector<ASTPointer<Expression>>, std::vector<ASTPointer<ASTString>>> parseFunctionCallArguments();
|
std::pair<std::vector<ASTPointer<Expression>>, std::vector<ASTPointer<ASTString>>> parseFunctionCallArguments();
|
||||||
@ -101,16 +101,22 @@ private:
|
|||||||
///@{
|
///@{
|
||||||
///@name Helper functions
|
///@name Helper functions
|
||||||
|
|
||||||
|
/// Used as return value of @see peekStatementType.
|
||||||
|
enum class LookAheadInfo
|
||||||
|
{
|
||||||
|
IndexAccessStructure, VariableDeclarationStatement, ExpressionStatement
|
||||||
|
};
|
||||||
|
|
||||||
/// Performs limited look-ahead to distinguish between variable declaration and expression statement.
|
/// Performs limited look-ahead to distinguish between variable declaration and expression statement.
|
||||||
/// @returns 1 if it is a variable declaration, -1 if it is an expression statement and 0 if
|
/// For source code of the form "a[][8]" ("IndexAccessStructure"), this it is not possible to
|
||||||
/// it might be an array-typed variable declaration or an index access to an existing variable.
|
/// decide with constant look-ahead.
|
||||||
int peekVariableDeclarationStatement() const;
|
LookAheadInfo peekStatementType() const;
|
||||||
/// Returns a typename parsed in look-ahead fashion from something like "a[8][2**70]".
|
/// Returns a typename parsed in look-ahead fashion from something like "a[8][2**70]".
|
||||||
ASTPointer<TypeName> typeNameFromArrayIndexStructure(
|
ASTPointer<TypeName> typeNameIndexAccessStructure(
|
||||||
ASTPointer<PrimaryExpression> const& _primary,
|
ASTPointer<PrimaryExpression> const& _primary,
|
||||||
std::vector<std::pair<ASTPointer<Expression>, Location>> const& _indices);
|
std::vector<std::pair<ASTPointer<Expression>, Location>> const& _indices);
|
||||||
/// Returns an expression parsed in look-ahead fashion from something like "a[8][2**70]".
|
/// Returns an expression parsed in look-ahead fashion from something like "a[8][2**70]".
|
||||||
ASTPointer<Expression> expressionFromArrayIndexStructure(
|
ASTPointer<Expression> expressionFromIndexAccessStructure(
|
||||||
ASTPointer<PrimaryExpression> const& _primary,
|
ASTPointer<PrimaryExpression> const& _primary,
|
||||||
std::vector<std::pair<ASTPointer<Expression>, Location>> const& _indices);
|
std::vector<std::pair<ASTPointer<Expression>, Location>> const& _indices);
|
||||||
/// If current token value is not _value, throw exception otherwise advance token.
|
/// If current token value is not _value, throw exception otherwise advance token.
|
||||||
|
3
Types.h
3
Types.h
@ -279,7 +279,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of a byte array, prototype for a general array.
|
* The type of an array, the flavours are byte array (bytes), statically- (<type>[<length>])
|
||||||
|
* and dynamically-sized array (<type>[]).
|
||||||
*/
|
*/
|
||||||
class ArrayType: public Type
|
class ArrayType: public Type
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user