Commit 7626fe35 authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

[torque] "OneOf" parser rule returns Identifier* instead of std::string

To obtain SourcePositions for unary and binary operators, this CL
changes the "OneOf" parser rule to produce an Identifier*. Forwarding
this new identifier as callee for a CallExpression enables
"goto Definition" support for operators in the Language Server.

Side note: VSCode won't highlight operators with an underlined font
when hovering with Ctrl pressed. "goto Definition" will work
nonetheless using default F12 or Ctrl-Click.

R=tebbi@chromium.org

Bug: v8:7793
Change-Id: Iada06009e324a3de8c453ec058427049e921a70d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1598690
Auto-Submit: Simon Zünd <szuend@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61263}
parent c1e08aa5
......@@ -249,12 +249,11 @@ Expression* MakeCall(IdentifierExpression* callee,
return result;
}
Expression* MakeCall(const std::string& callee,
Expression* MakeCall(Identifier* callee,
const std::vector<TypeExpression*>& generic_arguments,
const std::vector<Expression*>& arguments,
const std::vector<Statement*>& otherwise) {
return MakeCall(MakeNode<IdentifierExpression>(MakeNode<Identifier>(callee),
generic_arguments),
return MakeCall(MakeNode<IdentifierExpression>(callee, generic_arguments),
base::nullopt, arguments, otherwise);
}
......@@ -287,7 +286,7 @@ base::Optional<ParseResult> MakeNewExpression(
base::Optional<ParseResult> MakeBinaryOperator(
ParseResultIterator* child_results) {
auto left = child_results->NextAs<Expression*>();
auto op = child_results->NextAs<std::string>();
auto op = child_results->NextAs<Identifier*>();
auto right = child_results->NextAs<Expression*>();
return ParseResult{MakeCall(op, TypeList{},
std::vector<Expression*>{left, right},
......@@ -307,7 +306,7 @@ base::Optional<ParseResult> MakeIntrinsicCallExpression(
base::Optional<ParseResult> MakeUnaryOperator(
ParseResultIterator* child_results) {
auto op = child_results->NextAs<std::string>();
auto op = child_results->NextAs<Identifier*>();
auto e = child_results->NextAs<Expression*>();
return ParseResult{MakeCall(op, TypeList{}, std::vector<Expression*>{e},
std::vector<Statement*>{})};
......@@ -379,7 +378,7 @@ base::Optional<ParseResult> MakeParameterListFromNameAndTypeList(
base::Optional<ParseResult> MakeAssertStatement(
ParseResultIterator* child_results) {
auto kind = child_results->NextAs<std::string>();
auto kind = child_results->NextAs<Identifier*>()->value;
auto expr_with_source = child_results->NextAs<ExpressionWithSource>();
DCHECK(kind == "assert" || kind == "check");
Statement* result = MakeNode<AssertStatement>(
......@@ -389,7 +388,7 @@ base::Optional<ParseResult> MakeAssertStatement(
base::Optional<ParseResult> MakeDebugStatement(
ParseResultIterator* child_results) {
auto kind = child_results->NextAs<std::string>();
auto kind = child_results->NextAs<Identifier*>()->value;
DCHECK(kind == "unreachable" || kind == "debug");
Statement* result = MakeNode<DebugStatement>(kind, kind == "unreachable");
return ParseResult{result};
......@@ -795,7 +794,8 @@ base::Optional<ParseResult> MakeTypeswitchStatement(
}
BlockStatement* case_block;
if (i < cases.size() - 1) {
value = MakeCall("Cast", std::vector<TypeExpression*>{cases[i].type},
value = MakeCall(MakeNode<Identifier>("Cast"),
std::vector<TypeExpression*>{cases[i].type},
std::vector<Expression*>{value},
std::vector<Statement*>{MakeNode<ExpressionStatement>(
MakeNode<IdentifierExpression>(
......@@ -859,9 +859,9 @@ base::Optional<ParseResult> MakeTailCallStatement(
base::Optional<ParseResult> MakeVarDeclarationStatement(
ParseResultIterator* child_results) {
auto kind = child_results->NextAs<std::string>();
bool const_qualified = kind == "const";
if (!const_qualified) DCHECK_EQ("let", kind);
auto kind = child_results->NextAs<Identifier*>();
bool const_qualified = kind->value == "const";
if (!const_qualified) DCHECK_EQ("let", kind->value);
auto name = child_results->NextAs<Identifier*>();
if (!IsLowerCamelCase(name->value)) {
NamingConventionError("Variable", name->value, "lowerCamelCase");
......@@ -1003,6 +1003,12 @@ base::Optional<ParseResult> MakeIdentifier(ParseResultIterator* child_results) {
return ParseResult{result};
}
base::Optional<ParseResult> MakeIdentifierFromMatchedInput(
ParseResultIterator* child_results) {
return ParseResult{
MakeNode<Identifier>(child_results->matched_input().ToString())};
}
base::Optional<ParseResult> MakeIdentifierExpression(
ParseResultIterator* child_results) {
auto namespace_qualification =
......@@ -1172,8 +1178,9 @@ base::Optional<ParseResult> MakeStructField(
base::Optional<ParseResult> ExtractAssignmentOperator(
ParseResultIterator* child_results) {
auto op = child_results->NextAs<std::string>();
base::Optional<std::string> result = std::string(op.begin(), op.end() - 1);
auto op = child_results->NextAs<Identifier*>();
base::Optional<std::string> result =
std::string(op->value.begin(), op->value.end() - 1);
return ParseResult(std::move(result));
}
......@@ -1385,11 +1392,11 @@ struct TorqueGrammar : Grammar {
Token(","), Token("..."), &identifier, Token(")")},
MakeParameterListFromNameAndTypeList<true>)};
// Result: std::string
// Result: Identifier*
Symbol* OneOf(const std::vector<std::string>& alternatives) {
Symbol* result = NewSymbol();
for (const std::string& s : alternatives) {
result->AddRule(Rule({Token(s)}, YieldMatchedInput));
result->AddRule(Rule({Token(s)}, MakeIdentifierFromMatchedInput));
}
return result;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment