Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: src/parsing/parser.cc

Issue 2176653003: Wrap ClassLiterals in DoExpressions instead of giving them BlockScopes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: address comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/ast/ast.h" 10 #include "src/ast/ast.h"
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 FunctionLiteral* ParserTraits::ParseFunctionLiteral( 789 FunctionLiteral* ParserTraits::ParseFunctionLiteral(
790 const AstRawString* name, Scanner::Location function_name_location, 790 const AstRawString* name, Scanner::Location function_name_location,
791 FunctionNameValidity function_name_validity, FunctionKind kind, 791 FunctionNameValidity function_name_validity, FunctionKind kind,
792 int function_token_position, FunctionLiteral::FunctionType type, 792 int function_token_position, FunctionLiteral::FunctionType type,
793 LanguageMode language_mode, bool* ok) { 793 LanguageMode language_mode, bool* ok) {
794 return parser_->ParseFunctionLiteral( 794 return parser_->ParseFunctionLiteral(
795 name, function_name_location, function_name_validity, kind, 795 name, function_name_location, function_name_validity, kind,
796 function_token_position, type, language_mode, ok); 796 function_token_position, type, language_mode, ok);
797 } 797 }
798 798
799 ClassLiteral* ParserTraits::ParseClassLiteral( 799 Expression* ParserTraits::ParseClassLiteral(
800 Type::ExpressionClassifier* classifier, const AstRawString* name, 800 Type::ExpressionClassifier* classifier, const AstRawString* name,
801 Scanner::Location class_name_location, bool name_is_strict_reserved, 801 Scanner::Location class_name_location, bool name_is_strict_reserved,
802 int pos, bool* ok) { 802 int pos, bool* ok) {
803 return parser_->ParseClassLiteral(classifier, name, class_name_location, 803 return parser_->ParseClassLiteral(classifier, name, class_name_location,
804 name_is_strict_reserved, pos, ok); 804 name_is_strict_reserved, pos, ok);
805 } 805 }
806 806
807 void ParserTraits::MarkTailPosition(Expression* expression) { 807 void ParserTraits::MarkTailPosition(Expression* expression) {
808 expression->MarkTail(); 808 expression->MarkTail();
809 } 809 }
(...skipping 1450 matching lines...) Expand 10 before | Expand all | Expand 10 after
2260 const AstRawString* variable_name; 2260 const AstRawString* variable_name;
2261 if (default_export && (peek() == Token::EXTENDS || peek() == Token::LBRACE)) { 2261 if (default_export && (peek() == Token::EXTENDS || peek() == Token::LBRACE)) {
2262 name = ast_value_factory()->default_string(); 2262 name = ast_value_factory()->default_string();
2263 is_strict_reserved = false; 2263 is_strict_reserved = false;
2264 variable_name = ast_value_factory()->star_default_star_string(); 2264 variable_name = ast_value_factory()->star_default_star_string();
2265 } else { 2265 } else {
2266 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); 2266 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
2267 variable_name = name; 2267 variable_name = name;
2268 } 2268 }
2269 2269
2270 ClassLiteral* value = ParseClassLiteral(nullptr, name, scanner()->location(), 2270 Expression* value = ParseClassLiteral(nullptr, name, scanner()->location(),
2271 is_strict_reserved, pos, CHECK_OK); 2271 is_strict_reserved, pos, CHECK_OK);
2272 2272
2273 VariableProxy* proxy = NewUnresolved(variable_name, LET); 2273 VariableProxy* proxy = NewUnresolved(variable_name, LET);
2274 Declaration* declaration = 2274 Declaration* declaration =
2275 factory()->NewVariableDeclaration(proxy, LET, scope(), pos); 2275 factory()->NewVariableDeclaration(proxy, LET, scope(), pos);
2276 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 2276 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
2277 proxy->var()->set_initializer_position(position()); 2277 proxy->var()->set_initializer_position(position());
2278 Assignment* assignment = 2278 Assignment* assignment =
2279 factory()->NewAssignment(Token::INIT, proxy, value, pos); 2279 factory()->NewAssignment(Token::INIT, proxy, value, pos);
2280 Statement* assignment_statement = 2280 Statement* assignment_statement =
2281 factory()->NewExpressionStatement(assignment, kNoSourcePosition); 2281 factory()->NewExpressionStatement(assignment, kNoSourcePosition);
(...skipping 2716 matching lines...) Expand 10 before | Expand all | Expand 10 after
4998 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( 4998 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
4999 language_mode(), function_state_->kind(), 4999 language_mode(), function_state_->kind(),
5000 scope()->has_simple_parameters(), parsing_module_, logger, bookmark, 5000 scope()->has_simple_parameters(), parsing_module_, logger, bookmark,
5001 use_counts_); 5001 use_counts_);
5002 if (pre_parse_timer_ != NULL) { 5002 if (pre_parse_timer_ != NULL) {
5003 pre_parse_timer_->Stop(); 5003 pre_parse_timer_->Stop();
5004 } 5004 }
5005 return result; 5005 return result;
5006 } 5006 }
5007 5007
5008 ClassLiteral* Parser::ParseClassLiteral(ExpressionClassifier* classifier, 5008 Expression* Parser::ParseClassLiteral(ExpressionClassifier* classifier,
5009 const AstRawString* name, 5009 const AstRawString* name,
5010 Scanner::Location class_name_location, 5010 Scanner::Location class_name_location,
5011 bool name_is_strict_reserved, int pos, 5011 bool name_is_strict_reserved, int pos,
5012 bool* ok) { 5012 bool* ok) {
5013 // All parts of a ClassDeclaration and ClassExpression are strict code. 5013 // All parts of a ClassDeclaration and ClassExpression are strict code.
5014 if (name_is_strict_reserved) { 5014 if (name_is_strict_reserved) {
5015 ReportMessageAt(class_name_location, 5015 ReportMessageAt(class_name_location,
5016 MessageTemplate::kUnexpectedStrictReserved); 5016 MessageTemplate::kUnexpectedStrictReserved);
5017 *ok = false; 5017 *ok = false;
5018 return NULL; 5018 return NULL;
5019 } 5019 }
5020 if (IsEvalOrArguments(name)) { 5020 if (IsEvalOrArguments(name)) {
5021 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); 5021 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments);
5022 *ok = false; 5022 *ok = false;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
5104 5104
5105 // Note that we do not finalize this block scope because it is 5105 // Note that we do not finalize this block scope because it is
5106 // used as a sentinel value indicating an anonymous class. 5106 // used as a sentinel value indicating an anonymous class.
5107 block_scope->set_end_position(end_pos); 5107 block_scope->set_end_position(end_pos);
5108 5108
5109 if (name != NULL) { 5109 if (name != NULL) {
5110 DCHECK_NOT_NULL(proxy); 5110 DCHECK_NOT_NULL(proxy);
5111 proxy->var()->set_initializer_position(end_pos); 5111 proxy->var()->set_initializer_position(end_pos);
5112 } 5112 }
5113 5113
5114 return factory()->NewClassLiteral(block_scope, proxy, extends, constructor, 5114 Block* do_block = factory()->NewBlock(nullptr, 1, false, pos);
5115 properties, pos, end_pos); 5115 do_block->set_scope(block_scope);
5116 Variable* result_var =
5117 block_scope->NewTemporary(ast_value_factory()->empty_string());
5118 DoExpression* do_expr = factory()->NewDoExpression(do_block, result_var, pos);
5119
5120 ClassLiteral* class_literal = factory()->NewClassLiteral(
5121 proxy, extends, constructor, properties, pos, end_pos);
5122
5123 do_block->statements()->Add(
5124 factory()->NewExpressionStatement(class_literal, pos), zone());
5125 do_expr->set_represented_function(constructor);
5126 Rewriter::Rewrite(this, do_expr, ast_value_factory());
5127
5128 return do_expr;
5116 } 5129 }
5117 5130
5118 5131
5119 Expression* Parser::ParseV8Intrinsic(bool* ok) { 5132 Expression* Parser::ParseV8Intrinsic(bool* ok) {
5120 // CallRuntime :: 5133 // CallRuntime ::
5121 // '%' Identifier Arguments 5134 // '%' Identifier Arguments
5122 5135
5123 int pos = peek_position(); 5136 int pos = peek_position();
5124 Expect(Token::MOD, CHECK_OK); 5137 Expect(Token::MOD, CHECK_OK);
5125 // Allow "eval" or "arguments" for backward compatibility. 5138 // Allow "eval" or "arguments" for backward compatibility.
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
6099 6112
6100 6113
6101 void ParserTraits::SetFunctionName(Expression* value, 6114 void ParserTraits::SetFunctionName(Expression* value,
6102 const AstRawString* name) { 6115 const AstRawString* name) {
6103 DCHECK_NOT_NULL(name); 6116 DCHECK_NOT_NULL(name);
6104 if (!value->IsAnonymousFunctionDefinition()) return; 6117 if (!value->IsAnonymousFunctionDefinition()) return;
6105 auto function = value->AsFunctionLiteral(); 6118 auto function = value->AsFunctionLiteral();
6106 if (function != nullptr) { 6119 if (function != nullptr) {
6107 function->set_raw_name(name); 6120 function->set_raw_name(name);
6108 } else { 6121 } else {
6109 DCHECK(value->IsClassLiteral()); 6122 DCHECK(value->IsDoExpression());
6110 value->AsClassLiteral()->constructor()->set_raw_name(name); 6123 value->AsDoExpression()->represented_function()->set_raw_name(name);
6111 } 6124 }
6112 } 6125 }
6113 6126
6114 6127
6115 // Desugaring of yield* 6128 // Desugaring of yield*
6116 // ==================== 6129 // ====================
6117 // 6130 //
6118 // With the help of do-expressions and function.sent, we desugar yield* into a 6131 // With the help of do-expressions and function.sent, we desugar yield* into a
6119 // loop containing a "raw" yield (a yield that doesn't wrap an iterator result 6132 // loop containing a "raw" yield (a yield that doesn't wrap an iterator result
6120 // object around its argument). Concretely, "yield* iterable" turns into 6133 // object around its argument). Concretely, "yield* iterable" turns into
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after
7081 node->Print(Isolate::Current()); 7094 node->Print(Isolate::Current());
7082 } 7095 }
7083 #endif // DEBUG 7096 #endif // DEBUG
7084 7097
7085 #undef CHECK_OK 7098 #undef CHECK_OK
7086 #undef CHECK_OK_VOID 7099 #undef CHECK_OK_VOID
7087 #undef CHECK_FAILED 7100 #undef CHECK_FAILED
7088 7101
7089 } // namespace internal 7102 } // namespace internal
7090 } // namespace v8 7103 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.h ('k') | test/cctest/interpreter/bytecode_expectations/ClassDeclarations.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698