Commit c9d88eed authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[parser] Move literal initialization to parser

Move literal initialization out of AST numbering and into the parser.
The initialization includes setting the depth and flags of Object and
Array literals, and calculating the emit store of object literals.

Bug: v8:7178
Change-Id: I9af59a2fea44f8a1adcc5a0261f29ce97fa8da92
Reviewed-on: https://chromium-review.googlesource.com/814634
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50168}
parent 0298df88
......@@ -326,11 +326,6 @@ void AstNumberingVisitor::VisitObjectLiteral(ObjectLiteral* node) {
for (int i = 0; i < node->properties()->length(); i++) {
VisitLiteralProperty(node->properties()->at(i));
}
node->InitDepthAndFlags();
// Mark all computed expressions that are bound to a key that
// is shadowed by a later occurrence of the same key. For the
// marked expressions, no store code will be is emitted.
node->CalculateEmitStore(zone_);
}
void AstNumberingVisitor::VisitLiteralProperty(LiteralProperty* node) {
......@@ -342,7 +337,6 @@ void AstNumberingVisitor::VisitArrayLiteral(ArrayLiteral* node) {
for (int i = 0; i < node->values()->length(); i++) {
Visit(node->values()->at(i));
}
node->InitDepthAndFlags();
}
void AstNumberingVisitor::VisitCall(Call* node) {
......
......@@ -516,10 +516,11 @@ bool ArrayLiteral::is_empty() const {
int ArrayLiteral::InitDepthAndFlags() {
if (is_initialized()) return depth();
int constants_length = values()->length();
int constants_length =
first_spread_index_ >= 0 ? first_spread_index_ : values()->length();
// Fill in the literals.
bool is_simple = true;
bool is_simple = first_spread_index_ < 0;
int depth_acc = 1;
int array_index = 0;
for (; array_index < constants_length; array_index++) {
......
......@@ -1361,6 +1361,7 @@ class ObjectLiteral final : public AggregateLiteral {
HasRestPropertyField::encode(has_rest_property) |
FastElementsField::encode(false) |
HasNullPrototypeField::encode(false);
InitDepthAndFlags();
}
void InitFlagsForPendingNullPrototype(int i);
......@@ -1465,7 +1466,9 @@ class ArrayLiteral final : public AggregateLiteral {
ArrayLiteral(ZoneList<Expression*>* values, int first_spread_index, int pos)
: AggregateLiteral(pos, kArrayLiteral),
first_spread_index_(first_spread_index),
values_(values) {}
values_(values) {
InitDepthAndFlags();
}
int first_spread_index_;
Handle<ConstantElementsPair> constant_elements_;
......
......@@ -2683,8 +2683,8 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseObjectLiteral(
MessageTemplate::kTooManyArguments);
}
return factory()->NewObjectLiteral(
properties, number_of_boilerplate_properties, pos, has_rest_property);
return impl()->InitializeObjectLiteral(factory()->NewObjectLiteral(
properties, number_of_boilerplate_properties, pos, has_rest_property));
}
template <typename Impl>
......
......@@ -437,6 +437,11 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
LanguageMode language_mode,
ZoneList<const AstRawString*>* arguments_for_wrapped_function, bool* ok);
ObjectLiteral* InitializeObjectLiteral(ObjectLiteral* object_literal) {
object_literal->CalculateEmitStore(main_zone());
return object_literal;
}
// Check if the scope has conflicting var/let declarations from different
// scopes. This covers for example
//
......
......@@ -956,12 +956,18 @@ class PreParser : public ParserBase<PreParser> {
bool is_inner_function, bool may_abort, bool* ok) {
UNREACHABLE();
}
Expression ParseFunctionLiteral(
Identifier name, Scanner::Location function_name_location,
FunctionNameValidity function_name_validity, FunctionKind kind,
int function_token_pos, FunctionLiteral::FunctionType function_type,
LanguageMode language_mode,
ZoneList<const AstRawString*>* arguments_for_wrapped_function, bool* ok);
PreParserExpression InitializeObjectLiteral(PreParserExpression literal) {
return literal;
}
LazyParsingResult ParseStatementListAndLogFunction(
PreParserFormalParameters* formals, bool maybe_abort, bool* ok);
......
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