Commit 4dcc4173 authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

[torque] Remove for-of loop from Torque

R=tebbi@chromium.org

Bug: v8:7793
Change-Id: Ibba7651f8bd6a8e06b7810a8190d210b4cd54be0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1645324
Auto-Submit: Simon Zünd <szuend@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62001}
parent 3416e1c1
......@@ -52,7 +52,6 @@ namespace torque {
V(IfStatement) \
V(WhileStatement) \
V(ForLoopStatement) \
V(ForOfLoopStatement) \
V(BreakStatement) \
V(ContinueStatement) \
V(ReturnStatement) \
......@@ -605,31 +604,6 @@ struct ForLoopStatement : Statement {
Statement* body;
};
struct RangeExpression {
base::Optional<Expression*> begin;
base::Optional<Expression*> end;
};
struct ForOfLoopStatement : Statement {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ForOfLoopStatement)
ForOfLoopStatement(SourcePosition pos, Statement* decl, Expression* iterable,
base::Optional<RangeExpression> range, Statement* body)
: Statement(kKind, pos),
var_declaration(VarDeclarationStatement::cast(decl)),
iterable(iterable),
body(body) {
if (range) {
begin = range->begin;
end = range->end;
}
}
VarDeclarationStatement* var_declaration;
Expression* iterable;
base::Optional<Expression*> begin;
base::Optional<Expression*> end;
Statement* body;
};
struct LabelBlock : AstNode {
DEFINE_AST_NODE_LEAF_BOILERPLATE(LabelBlock)
LabelBlock(SourcePosition pos, Identifier* label,
......
......@@ -70,8 +70,6 @@ enum class ParseResultHolderBase::TypeId {
kStdVectorOfExpressionPtr,
kExpressionWithSource,
kParameterList,
kRangeExpression,
kOptionalRangeExpression,
kTypeList,
kOptionalTypeList,
kLabelAndTypes,
......
......@@ -1016,81 +1016,6 @@ const Type* ImplementationVisitor::Visit(ReturnStatement* stmt) {
return TypeOracle::GetNeverType();
}
const Type* ImplementationVisitor::Visit(ForOfLoopStatement* stmt) {
VisitResult expression_result = Visit(stmt->iterable);
VisitResult begin = stmt->begin
? Visit(*stmt->begin)
: VisitResult(TypeOracle::GetConstInt31Type(), "0");
VisitResult end = stmt->end
? Visit(*stmt->end)
: GenerateCall(".length", {{expression_result}, {}});
const Type* common_type = GetCommonType(begin.type(), end.type());
VisitResult index = GenerateImplicitConvert(common_type, begin);
Block* body_block = assembler().NewBlock();
Block* increment_block = assembler().NewBlock(assembler().CurrentStack());
Block* exit_block = assembler().NewBlock(assembler().CurrentStack());
Block* header_block = assembler().NewBlock();
assembler().Goto(header_block);
assembler().Bind(header_block);
BreakContinueActivator activator(exit_block, increment_block);
{
StackScope comparison_scope(this);
VisitResult result = GenerateCall("<", {{index, end}, {}});
if (result.type() != TypeOracle::GetBoolType()) {
ReportError("operator < with arguments(", *index.type(), ", ",
*end.type(),
") used in for-of loop has to return type bool, but "
"returned type ",
*result.type());
}
comparison_scope.Yield(result);
}
assembler().Branch(body_block, exit_block);
assembler().Bind(body_block);
{
VisitResult element_result;
{
StackScope element_scope(this);
VisitResult result = GenerateCall("[]", {{expression_result, index}, {}});
if (stmt->var_declaration->type) {
const Type* declared_type =
TypeVisitor::ComputeType(*stmt->var_declaration->type);
result = GenerateImplicitConvert(declared_type, result);
}
element_result = element_scope.Yield(result);
}
Binding<LocalValue> element_var_binding{&ValueBindingsManager::Get(),
stmt->var_declaration->name->value,
LocalValue{true, element_result}};
Visit(stmt->body);
}
assembler().Goto(increment_block);
assembler().Bind(increment_block);
{
Arguments increment_args;
increment_args.parameters = {index, {TypeOracle::GetConstInt31Type(), "1"}};
VisitResult increment_result = GenerateCall("+", increment_args);
GenerateAssignToLocation(LocationReference::VariableAccess(index),
increment_result);
}
assembler().Goto(header_block);
assembler().Bind(exit_block);
return TypeOracle::GetVoidType();
}
VisitResult ImplementationVisitor::TemporaryUninitializedStruct(
const StructType* struct_type, const std::string& reason) {
StackRange range = assembler().TopRange(0);
......
......@@ -365,7 +365,6 @@ class ImplementationVisitor {
const Type* Visit(VarDeclarationStatement* stmt);
const Type* Visit(VarDeclarationStatement* stmt,
BlockBindings<LocalValue>* block_bindings);
const Type* Visit(ForOfLoopStatement* stmt);
const Type* Visit(BlockStatement* block);
const Type* Visit(ExpressionStatement* stmt);
const Type* Visit(DebugStatement* stmt);
......
......@@ -170,14 +170,6 @@ template <>
V8_EXPORT_PRIVATE const ParseResultTypeId ParseResultHolder<ParameterList>::id =
ParseResultTypeId::kParameterList;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<RangeExpression>::id =
ParseResultTypeId::kRangeExpression;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<base::Optional<RangeExpression>>::id =
ParseResultTypeId::kOptionalRangeExpression;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId ParseResultHolder<TypeList>::id =
ParseResultTypeId::kTypeList;
template <>
......@@ -1079,19 +1071,6 @@ base::Optional<ParseResult> MakeTryLabelExpression(
return ParseResult{result};
}
base::Optional<ParseResult> MakeForOfLoopStatement(
ParseResultIterator* child_results) {
auto var_decl = child_results->NextAs<Statement*>();
CheckNotDeferredStatement(var_decl);
auto iterable = child_results->NextAs<Expression*>();
auto range = child_results->NextAs<base::Optional<RangeExpression>>();
auto body = child_results->NextAs<Statement*>();
CheckNotDeferredStatement(body);
Statement* result =
MakeNode<ForOfLoopStatement>(var_decl, iterable, range, body);
return ParseResult{result};
}
base::Optional<ParseResult> MakeForLoopStatement(
ParseResultIterator* child_results) {
auto var_decl = child_results->NextAs<base::Optional<Statement*>>();
......@@ -1133,14 +1112,6 @@ base::Optional<ParseResult> MakeCatchBlock(ParseResultIterator* child_results) {
return ParseResult{result};
}
base::Optional<ParseResult> MakeRangeExpression(
ParseResultIterator* child_results) {
auto begin = child_results->NextAs<base::Optional<Expression*>>();
auto end = child_results->NextAs<base::Optional<Expression*>>();
RangeExpression result = {begin, end};
return ParseResult{result};
}
base::Optional<ParseResult> MakeExpressionWithSource(
ParseResultIterator* child_results) {
auto e = child_results->NextAs<Expression*>();
......@@ -1753,12 +1724,6 @@ struct TorqueGrammar : Grammar {
// Result: ExpressionWithSource
Symbol expressionWithSource = {Rule({expression}, MakeExpressionWithSource)};
// Result: RangeExpression
Symbol rangeSpecifier = {
Rule({Token("["), Optional<Expression*>(expression), Token(":"),
Optional<Expression*>(expression), Token("]")},
MakeRangeExpression)};
Symbol* optionalTypeSpecifier =
Optional<TypeExpression*>(Sequence({Token(":"), &type}));
......@@ -1811,9 +1776,6 @@ struct TorqueGrammar : Grammar {
MakeAssertStatement),
Rule({Token("while"), Token("("), expression, Token(")"), &statement},
MakeWhileStatement),
Rule({Token("for"), Token("("), &varDeclaration, Token("of"), expression,
Optional<RangeExpression>(&rangeSpecifier), Token(")"), &statement},
MakeForOfLoopStatement),
Rule({Token("for"), Token("("),
Optional<Statement*>(&varDeclarationWithInitialization), Token(";"),
Optional<Expression*>(expression), Token(";"),
......
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