Add location for member in MemberAccess ASTNode

This commit is contained in:
Marenz 2022-06-14 16:02:05 +02:00
parent 4d8a14b653
commit ee710eadd4
6 changed files with 24 additions and 5 deletions

View File

@ -2190,19 +2190,27 @@ public:
int64_t _id,
SourceLocation const& _location,
ASTPointer<Expression> _expression,
ASTPointer<ASTString> _memberName
ASTPointer<ASTString> _memberName,
SourceLocation _memberLocation
):
Expression(_id, _location), m_expression(std::move(_expression)), m_memberName(std::move(_memberName)) {}
Expression(_id, _location),
m_expression(std::move(_expression)),
m_memberName(std::move(_memberName)),
m_memberLocation(std::move(_memberLocation))
{}
void accept(ASTVisitor& _visitor) override;
void accept(ASTConstVisitor& _visitor) const override;
Expression const& expression() const { return *m_expression; }
ASTString const& memberName() const { return *m_memberName; }
SourceLocation const& memberLocation() const { return m_memberLocation; }
MemberAccessAnnotation& annotation() const override;
private:
ASTPointer<Expression> m_expression;
ASTPointer<ASTString> m_memberName;
SourceLocation m_memberLocation;
};
/**

View File

@ -889,6 +889,7 @@ bool ASTJsonExporter::visit(MemberAccess const& _node)
{
std::vector<pair<string, Json::Value>> attributes = {
make_pair("memberName", _node.memberName()),
make_pair("memberLocation", Json::Value(sourceLocationToString(_node.memberLocation()))),
make_pair("expression", toJson(_node.expression())),
make_pair("referencedDeclaration", idOrNull(_node.annotation().referencedDeclaration)),
};

View File

@ -931,10 +931,15 @@ ASTPointer<NewExpression> ASTJsonImporter::createNewExpression(Json::Value const
ASTPointer<MemberAccess> ASTJsonImporter::createMemberAccess(Json::Value const& _node)
{
SourceLocation memberLocation;
if (member(_node, "memberLocation").isString())
memberLocation = solidity::langutil::parseSourceLocation(_node["memberLocation"].asString(), m_sourceNames);
return createASTNode<MemberAccess>(
_node,
convertJsonToASTNode<Expression>(member(_node, "expression")),
memberAsASTString(_node, "memberName")
memberAsASTString(_node, "memberName"),
std::move(memberLocation)
);
}

View File

@ -1897,7 +1897,9 @@ ASTPointer<Expression> Parser::parseLeftHandSideExpression(
{
advance();
nodeFactory.markEndPosition();
expression = nodeFactory.createNode<MemberAccess>(expression, expectIdentifierTokenOrAddress());
SourceLocation memberLocation = currentLocation();
ASTPointer<ASTString> memberName = expectIdentifierTokenOrAddress();
expression = nodeFactory.createNode<MemberAccess>(expression, std::move(memberName), std::move(memberLocation));
break;
}
case Token::LParen:
@ -2335,7 +2337,8 @@ ASTPointer<Expression> Parser::expressionFromIndexAccessStructure(
Identifier const& identifier = dynamic_cast<Identifier const&>(*_iap.path[i]);
expression = nodeFactory.createNode<MemberAccess>(
expression,
make_shared<ASTString>(identifier.name())
make_shared<ASTString>(identifier.name()),
identifier.location()
);
}
for (auto const& index: _iap.indices)

View File

@ -70,6 +70,7 @@
"isLValue": false,
"isPure": true,
"lValueRequested": false,
"memberLocation": "57:1:1",
"memberName": "X",
"nodeType": "MemberAccess",
"referencedDeclaration": 1,

View File

@ -49,6 +49,7 @@
"typeDescriptions": {}
},
"id": 10,
"memberLocation": "57:1:1",
"memberName": "X",
"nodeType": "MemberAccess",
"src": "55:3:1",