[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: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62001}
This commit is contained in:
Simon Zünd 2019-06-05 15:28:45 +02:00 committed by Commit Bot
parent 3416e1c11d
commit 4dcc417335
5 changed files with 0 additions and 142 deletions

View File

@ -52,7 +52,6 @@ namespace torque {
V(IfStatement) \ V(IfStatement) \
V(WhileStatement) \ V(WhileStatement) \
V(ForLoopStatement) \ V(ForLoopStatement) \
V(ForOfLoopStatement) \
V(BreakStatement) \ V(BreakStatement) \
V(ContinueStatement) \ V(ContinueStatement) \
V(ReturnStatement) \ V(ReturnStatement) \
@ -605,31 +604,6 @@ struct ForLoopStatement : Statement {
Statement* body; 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 { struct LabelBlock : AstNode {
DEFINE_AST_NODE_LEAF_BOILERPLATE(LabelBlock) DEFINE_AST_NODE_LEAF_BOILERPLATE(LabelBlock)
LabelBlock(SourcePosition pos, Identifier* label, LabelBlock(SourcePosition pos, Identifier* label,

View File

@ -70,8 +70,6 @@ enum class ParseResultHolderBase::TypeId {
kStdVectorOfExpressionPtr, kStdVectorOfExpressionPtr,
kExpressionWithSource, kExpressionWithSource,
kParameterList, kParameterList,
kRangeExpression,
kOptionalRangeExpression,
kTypeList, kTypeList,
kOptionalTypeList, kOptionalTypeList,
kLabelAndTypes, kLabelAndTypes,

View File

@ -1016,81 +1016,6 @@ const Type* ImplementationVisitor::Visit(ReturnStatement* stmt) {
return TypeOracle::GetNeverType(); 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( VisitResult ImplementationVisitor::TemporaryUninitializedStruct(
const StructType* struct_type, const std::string& reason) { const StructType* struct_type, const std::string& reason) {
StackRange range = assembler().TopRange(0); StackRange range = assembler().TopRange(0);

View File

@ -365,7 +365,6 @@ class ImplementationVisitor {
const Type* Visit(VarDeclarationStatement* stmt); const Type* Visit(VarDeclarationStatement* stmt);
const Type* Visit(VarDeclarationStatement* stmt, const Type* Visit(VarDeclarationStatement* stmt,
BlockBindings<LocalValue>* block_bindings); BlockBindings<LocalValue>* block_bindings);
const Type* Visit(ForOfLoopStatement* stmt);
const Type* Visit(BlockStatement* block); const Type* Visit(BlockStatement* block);
const Type* Visit(ExpressionStatement* stmt); const Type* Visit(ExpressionStatement* stmt);
const Type* Visit(DebugStatement* stmt); const Type* Visit(DebugStatement* stmt);

View File

@ -170,14 +170,6 @@ template <>
V8_EXPORT_PRIVATE const ParseResultTypeId ParseResultHolder<ParameterList>::id = V8_EXPORT_PRIVATE const ParseResultTypeId ParseResultHolder<ParameterList>::id =
ParseResultTypeId::kParameterList; ParseResultTypeId::kParameterList;
template <> 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 = V8_EXPORT_PRIVATE const ParseResultTypeId ParseResultHolder<TypeList>::id =
ParseResultTypeId::kTypeList; ParseResultTypeId::kTypeList;
template <> template <>
@ -1079,19 +1071,6 @@ base::Optional<ParseResult> MakeTryLabelExpression(
return ParseResult{result}; 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( base::Optional<ParseResult> MakeForLoopStatement(
ParseResultIterator* child_results) { ParseResultIterator* child_results) {
auto var_decl = child_results->NextAs<base::Optional<Statement*>>(); auto var_decl = child_results->NextAs<base::Optional<Statement*>>();
@ -1133,14 +1112,6 @@ base::Optional<ParseResult> MakeCatchBlock(ParseResultIterator* child_results) {
return ParseResult{result}; 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( base::Optional<ParseResult> MakeExpressionWithSource(
ParseResultIterator* child_results) { ParseResultIterator* child_results) {
auto e = child_results->NextAs<Expression*>(); auto e = child_results->NextAs<Expression*>();
@ -1753,12 +1724,6 @@ struct TorqueGrammar : Grammar {
// Result: ExpressionWithSource // Result: ExpressionWithSource
Symbol expressionWithSource = {Rule({expression}, MakeExpressionWithSource)}; Symbol expressionWithSource = {Rule({expression}, MakeExpressionWithSource)};
// Result: RangeExpression
Symbol rangeSpecifier = {
Rule({Token("["), Optional<Expression*>(expression), Token(":"),
Optional<Expression*>(expression), Token("]")},
MakeRangeExpression)};
Symbol* optionalTypeSpecifier = Symbol* optionalTypeSpecifier =
Optional<TypeExpression*>(Sequence({Token(":"), &type})); Optional<TypeExpression*>(Sequence({Token(":"), &type}));
@ -1811,9 +1776,6 @@ struct TorqueGrammar : Grammar {
MakeAssertStatement), MakeAssertStatement),
Rule({Token("while"), Token("("), expression, Token(")"), &statement}, Rule({Token("while"), Token("("), expression, Token(")"), &statement},
MakeWhileStatement), MakeWhileStatement),
Rule({Token("for"), Token("("), &varDeclaration, Token("of"), expression,
Optional<RangeExpression>(&rangeSpecifier), Token(")"), &statement},
MakeForOfLoopStatement),
Rule({Token("for"), Token("("), Rule({Token("for"), Token("("),
Optional<Statement*>(&varDeclarationWithInitialization), Token(";"), Optional<Statement*>(&varDeclarationWithInitialization), Token(";"),
Optional<Expression*>(expression), Token(";"), Optional<Expression*>(expression), Token(";"),