mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #13185 from ethereum/functionCall_locations
Add location for parameter names in FunctionCall ASTNode
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
#include <cctype>
|
||||
#include <vector>
|
||||
#include <regex>
|
||||
#include <tuple>
|
||||
|
||||
using namespace std;
|
||||
using namespace solidity::langutil;
|
||||
@@ -1542,13 +1543,16 @@ ASTPointer<EmitStatement> Parser::parseEmitStatement(ASTPointer<ASTString> const
|
||||
auto eventName = expressionFromIndexAccessStructure(iap);
|
||||
expectToken(Token::LParen);
|
||||
|
||||
vector<ASTPointer<Expression>> arguments;
|
||||
vector<ASTPointer<ASTString>> names;
|
||||
std::tie(arguments, names) = parseFunctionCallArguments();
|
||||
auto functionCallArguments = parseFunctionCallArguments();
|
||||
eventCallNodeFactory.markEndPosition();
|
||||
nodeFactory.markEndPosition();
|
||||
expectToken(Token::RParen);
|
||||
auto eventCall = eventCallNodeFactory.createNode<FunctionCall>(eventName, arguments, names);
|
||||
auto eventCall = eventCallNodeFactory.createNode<FunctionCall>(
|
||||
eventName,
|
||||
functionCallArguments.arguments,
|
||||
functionCallArguments.parameterNames,
|
||||
functionCallArguments.parameterNameLocations
|
||||
);
|
||||
return nodeFactory.createNode<EmitStatement>(_docString, eventCall);
|
||||
}
|
||||
|
||||
@@ -1573,13 +1577,16 @@ ASTPointer<RevertStatement> Parser::parseRevertStatement(ASTPointer<ASTString> c
|
||||
auto errorName = expressionFromIndexAccessStructure(iap);
|
||||
expectToken(Token::LParen);
|
||||
|
||||
vector<ASTPointer<Expression>> arguments;
|
||||
vector<ASTPointer<ASTString>> names;
|
||||
std::tie(arguments, names) = parseFunctionCallArguments();
|
||||
auto functionCallArguments = parseFunctionCallArguments();
|
||||
errorCallNodeFactory.markEndPosition();
|
||||
nodeFactory.markEndPosition();
|
||||
expectToken(Token::RParen);
|
||||
auto errorCall = errorCallNodeFactory.createNode<FunctionCall>(errorName, arguments, names);
|
||||
auto errorCall = errorCallNodeFactory.createNode<FunctionCall>(
|
||||
errorName,
|
||||
functionCallArguments.arguments,
|
||||
functionCallArguments.parameterNames,
|
||||
functionCallArguments.parameterNameLocations
|
||||
);
|
||||
return nodeFactory.createNode<RevertStatement>(_docString, errorCall);
|
||||
}
|
||||
|
||||
@@ -1905,12 +1912,14 @@ ASTPointer<Expression> Parser::parseLeftHandSideExpression(
|
||||
case Token::LParen:
|
||||
{
|
||||
advance();
|
||||
vector<ASTPointer<Expression>> arguments;
|
||||
vector<ASTPointer<ASTString>> names;
|
||||
std::tie(arguments, names) = parseFunctionCallArguments();
|
||||
auto functionCallArguments = parseFunctionCallArguments();
|
||||
nodeFactory.markEndPosition();
|
||||
expectToken(Token::RParen);
|
||||
expression = nodeFactory.createNode<FunctionCall>(expression, arguments, names);
|
||||
expression = nodeFactory.createNode<FunctionCall>(
|
||||
expression,
|
||||
functionCallArguments.arguments,
|
||||
functionCallArguments.parameterNames,
|
||||
functionCallArguments.parameterNameLocations);
|
||||
break;
|
||||
}
|
||||
case Token::LBrace:
|
||||
@@ -1929,7 +1938,7 @@ ASTPointer<Expression> Parser::parseLeftHandSideExpression(
|
||||
nodeFactory.markEndPosition();
|
||||
expectToken(Token::RBrace);
|
||||
|
||||
expression = nodeFactory.createNode<FunctionCallOptions>(expression, optionList.first, optionList.second);
|
||||
expression = nodeFactory.createNode<FunctionCallOptions>(expression, optionList.arguments, optionList.parameterNames);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -2073,10 +2082,11 @@ vector<ASTPointer<Expression>> Parser::parseFunctionCallListArguments()
|
||||
return arguments;
|
||||
}
|
||||
|
||||
pair<vector<ASTPointer<Expression>>, vector<ASTPointer<ASTString>>> Parser::parseFunctionCallArguments()
|
||||
Parser::FunctionCallArguments Parser::parseFunctionCallArguments()
|
||||
{
|
||||
RecursionGuard recursionGuard(*this);
|
||||
pair<vector<ASTPointer<Expression>>, vector<ASTPointer<ASTString>>> ret;
|
||||
FunctionCallArguments ret;
|
||||
|
||||
Token token = m_scanner->currentToken();
|
||||
if (token == Token::LBrace)
|
||||
{
|
||||
@@ -2086,13 +2096,13 @@ pair<vector<ASTPointer<Expression>>, vector<ASTPointer<ASTString>>> Parser::pars
|
||||
expectToken(Token::RBrace);
|
||||
}
|
||||
else
|
||||
ret.first = parseFunctionCallListArguments();
|
||||
ret.arguments = parseFunctionCallListArguments();
|
||||
return ret;
|
||||
}
|
||||
|
||||
pair<vector<ASTPointer<Expression>>, vector<ASTPointer<ASTString>>> Parser::parseNamedArguments()
|
||||
Parser::FunctionCallArguments Parser::parseNamedArguments()
|
||||
{
|
||||
pair<vector<ASTPointer<Expression>>, vector<ASTPointer<ASTString>>> ret;
|
||||
FunctionCallArguments ret;
|
||||
|
||||
bool first = true;
|
||||
while (m_scanner->currentToken() != Token::RBrace)
|
||||
@@ -2100,9 +2110,15 @@ pair<vector<ASTPointer<Expression>>, vector<ASTPointer<ASTString>>> Parser::pars
|
||||
if (!first)
|
||||
expectToken(Token::Comma);
|
||||
|
||||
ret.second.push_back(expectIdentifierToken());
|
||||
auto identifierWithLocation = expectIdentifierWithLocation();
|
||||
|
||||
// Add name
|
||||
ret.parameterNames.emplace_back(std::move(identifierWithLocation.first));
|
||||
// Add location
|
||||
ret.parameterNameLocations.emplace_back(std::move(identifierWithLocation.second));
|
||||
|
||||
expectToken(Token::Colon);
|
||||
ret.first.push_back(parseExpression());
|
||||
ret.arguments.emplace_back(parseExpression());
|
||||
|
||||
if (
|
||||
m_scanner->currentToken() == Token::Comma &&
|
||||
|
||||
@@ -77,6 +77,14 @@ private:
|
||||
std::vector<ASTPointer<ModifierInvocation>> modifiers;
|
||||
};
|
||||
|
||||
/// Struct to share parsed function call arguments.
|
||||
struct FunctionCallArguments
|
||||
{
|
||||
std::vector<ASTPointer<Expression>> arguments;
|
||||
std::vector<ASTPointer<ASTString>> parameterNames;
|
||||
std::vector<langutil::SourceLocation> parameterNameLocations;
|
||||
};
|
||||
|
||||
///@{
|
||||
///@name Parsing functions for the AST nodes
|
||||
void parsePragmaVersion(langutil::SourceLocation const& _location, std::vector<Token> const& _tokens, std::vector<std::string> const& _literals);
|
||||
@@ -153,8 +161,9 @@ private:
|
||||
);
|
||||
ASTPointer<Expression> parsePrimaryExpression();
|
||||
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>>> parseNamedArguments();
|
||||
|
||||
FunctionCallArguments parseFunctionCallArguments();
|
||||
FunctionCallArguments parseNamedArguments();
|
||||
std::pair<ASTPointer<ASTString>, langutil::SourceLocation> expectIdentifierWithLocation();
|
||||
///@}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user