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

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

Issue 2267783002: [parser] Clean up (pre)parser traits (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@nickie-2267663002-crtp
Patch Set: Rebase Created 4 years, 3 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
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-expression-rewriter.h" 10 #include "src/ast/ast-expression-rewriter.h"
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 Zone* zone = delegate()->zone(); 671 Zone* zone = delegate()->zone();
672 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(0, zone); 672 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(0, zone);
673 return factory->NewCall(prop, args, pos); 673 return factory->NewCall(prop, args, pos);
674 } 674 }
675 675
676 Literal* ParserBaseTraits<Parser>::GetLiteralTheHole( 676 Literal* ParserBaseTraits<Parser>::GetLiteralTheHole(
677 int position, AstNodeFactory* factory) const { 677 int position, AstNodeFactory* factory) const {
678 return factory->NewTheHoleLiteral(kNoSourcePosition); 678 return factory->NewTheHoleLiteral(kNoSourcePosition);
679 } 679 }
680 680
681 Expression* ParserBaseTraits<Parser>::ParseV8Intrinsic(bool* ok) { 681 void Parser::MarkTailPosition(Expression* expression) {
682 return delegate()->ParseV8Intrinsic(ok);
683 }
684
685 FunctionLiteral* ParserBaseTraits<Parser>::ParseFunctionLiteral(
686 const AstRawString* name, Scanner::Location function_name_location,
687 FunctionNameValidity function_name_validity, FunctionKind kind,
688 int function_token_position, FunctionLiteral::FunctionType type,
689 LanguageMode language_mode, bool* ok) {
690 return delegate()->ParseFunctionLiteral(
691 name, function_name_location, function_name_validity, kind,
692 function_token_position, type, language_mode, ok);
693 }
694
695 Expression* ParserBaseTraits<Parser>::ParseClassLiteral(
696 Type::ExpressionClassifier* classifier, const AstRawString* name,
697 Scanner::Location class_name_location, bool name_is_strict_reserved,
698 int pos, bool* ok) {
699 return delegate()->ParseClassLiteral(classifier, name, class_name_location,
700 name_is_strict_reserved, pos, ok);
701 }
702
703 void ParserBaseTraits<Parser>::MarkTailPosition(Expression* expression) {
704 expression->MarkTail(); 682 expression->MarkTail();
705 } 683 }
706 684
707 void ParserBaseTraits<Parser>::MarkCollectedTailCallExpressions() {
708 delegate()->MarkCollectedTailCallExpressions();
709 }
710
711 Parser::Parser(ParseInfo* info) 685 Parser::Parser(ParseInfo* info)
712 : ParserBase<Parser>(info->zone(), &scanner_, info->stack_limit(), 686 : ParserBase<Parser>(info->zone(), &scanner_, info->stack_limit(),
713 info->extension(), info->ast_value_factory(), NULL), 687 info->extension(), info->ast_value_factory(), NULL),
714 scanner_(info->unicode_cache()), 688 scanner_(info->unicode_cache()),
715 reusable_preparser_(NULL), 689 reusable_preparser_(NULL),
716 original_scope_(NULL), 690 original_scope_(NULL),
717 target_stack_(NULL), 691 target_stack_(NULL),
718 compile_options_(info->compile_options()), 692 compile_options_(info->compile_options()),
719 cached_parse_data_(NULL), 693 cached_parse_data_(NULL),
720 total_preparse_skipped_(0), 694 total_preparse_skipped_(0),
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 if (body->length() != 1 || 907 if (body->length() != 1 ||
934 !body->at(0)->IsExpressionStatement() || 908 !body->at(0)->IsExpressionStatement() ||
935 !body->at(0)->AsExpressionStatement()-> 909 !body->at(0)->AsExpressionStatement()->
936 expression()->IsFunctionLiteral()) { 910 expression()->IsFunctionLiteral()) {
937 ReportMessage(MessageTemplate::kSingleFunctionLiteral); 911 ReportMessage(MessageTemplate::kSingleFunctionLiteral);
938 ok = false; 912 ok = false;
939 } 913 }
940 } 914 }
941 915
942 if (ok) { 916 if (ok) {
943 ParserBaseTraits<Parser>::RewriteDestructuringAssignments(); 917 RewriteDestructuringAssignments();
944 result = factory()->NewScriptOrEvalFunctionLiteral( 918 result = factory()->NewScriptOrEvalFunctionLiteral(
945 scope, body, function_state.materialized_literal_count(), 919 scope, body, function_state.materialized_literal_count(),
946 function_state.expected_property_count()); 920 function_state.expected_property_count());
947 } 921 }
948 } 922 }
949 923
950 // Make sure the target stack is empty. 924 // Make sure the target stack is empty.
951 DCHECK(target_stack_ == NULL); 925 DCHECK(target_stack_ == NULL);
952 926
953 return result; 927 return result;
(...skipping 3023 matching lines...) Expand 10 before | Expand all | Expand 10 after
3977 if (expr->IsAssignment()) { 3951 if (expr->IsAssignment()) {
3978 Assignment* assignment = expr->AsAssignment(); 3952 Assignment* assignment = expr->AsAssignment();
3979 DCHECK(!assignment->is_compound()); 3953 DCHECK(!assignment->is_compound());
3980 initializer = assignment->value(); 3954 initializer = assignment->value();
3981 expr = assignment->target(); 3955 expr = assignment->target();
3982 } 3956 }
3983 3957
3984 AddFormalParameter(parameters, expr, initializer, end_pos, is_rest); 3958 AddFormalParameter(parameters, expr, initializer, end_pos, is_rest);
3985 } 3959 }
3986 3960
3987 void ParserBaseTraits<Parser>::ParseAsyncArrowSingleExpressionBody(
3988 ZoneList<Statement*>* body, bool accept_IN,
3989 Type::ExpressionClassifier* classifier, int pos, bool* ok) {
3990 delegate()->DesugarAsyncFunctionBody(
3991 delegate()->ast_value_factory()->empty_string(), delegate()->scope(),
3992 body, classifier, kAsyncArrowFunction,
3993 Parser::FunctionBodyType::kSingleExpression, accept_IN, pos, ok);
3994 }
3995
3996 void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name, 3961 void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name,
3997 Scope* scope, ZoneList<Statement*>* body, 3962 Scope* scope, ZoneList<Statement*>* body,
3998 ExpressionClassifier* classifier, 3963 ExpressionClassifier* classifier,
3999 FunctionKind kind, 3964 FunctionKind kind,
4000 FunctionBodyType body_type, 3965 FunctionBodyType body_type,
4001 bool accept_IN, int pos, bool* ok) { 3966 bool accept_IN, int pos, bool* ok) {
4002 // function async_function() { 3967 // function async_function() {
4003 // try { 3968 // try {
4004 // .generator_object = %CreateGeneratorObject(); 3969 // .generator_object = %CreateGeneratorObject();
4005 // ... function body ... 3970 // ... function body ...
(...skipping 17 matching lines...) Expand all
4023 3988
4024 ZoneList<Statement*>* inner_body = try_block->statements(); 3989 ZoneList<Statement*>* inner_body = try_block->statements();
4025 3990
4026 Expression* return_value = nullptr; 3991 Expression* return_value = nullptr;
4027 if (body_type == FunctionBodyType::kNormal) { 3992 if (body_type == FunctionBodyType::kNormal) {
4028 ParseStatementList(inner_body, Token::RBRACE, CHECK_OK_VOID); 3993 ParseStatementList(inner_body, Token::RBRACE, CHECK_OK_VOID);
4029 return_value = factory()->NewUndefinedLiteral(kNoSourcePosition); 3994 return_value = factory()->NewUndefinedLiteral(kNoSourcePosition);
4030 } else { 3995 } else {
4031 return_value = 3996 return_value =
4032 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK_VOID); 3997 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK_VOID);
4033 ParserBaseTraits<Parser>::RewriteNonPattern(classifier, CHECK_OK_VOID); 3998 RewriteNonPattern(classifier, CHECK_OK_VOID);
4034 } 3999 }
4035 4000
4036 return_value = BuildPromiseResolve(return_value, return_value->position()); 4001 return_value = BuildPromiseResolve(return_value, return_value->position());
4037 inner_body->Add( 4002 inner_body->Add(
4038 factory()->NewReturnStatement(return_value, return_value->position()), 4003 factory()->NewReturnStatement(return_value, return_value->position()),
4039 zone()); 4004 zone());
4040 body->Add(BuildRejectPromiseOnException(try_block), zone()); 4005 body->Add(BuildRejectPromiseOnException(try_block), zone());
4041 scope->set_end_position(scanner()->location().end_pos); 4006 scope->set_end_position(scanner()->location().end_pos);
4042 } 4007 }
4043 4008
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
4327 if (is_strict(language_mode)) { 4292 if (is_strict(language_mode)) {
4328 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), 4293 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(),
4329 CHECK_OK); 4294 CHECK_OK);
4330 CheckDecimalLiteralWithLeadingZero(use_counts_, scope->start_position(), 4295 CheckDecimalLiteralWithLeadingZero(use_counts_, scope->start_position(),
4331 scope->end_position()); 4296 scope->end_position());
4332 } 4297 }
4333 CheckConflictingVarDeclarations(scope, CHECK_OK); 4298 CheckConflictingVarDeclarations(scope, CHECK_OK);
4334 4299
4335 if (body) { 4300 if (body) {
4336 // If body can be inspected, rewrite queued destructuring assignments 4301 // If body can be inspected, rewrite queued destructuring assignments
4337 ParserBaseTraits<Parser>::RewriteDestructuringAssignments(); 4302 RewriteDestructuringAssignments();
4338 } 4303 }
4339 has_duplicate_parameters = 4304 has_duplicate_parameters =
4340 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); 4305 !formals_classifier.is_valid_formal_parameter_list_without_duplicates();
4341 4306
4342 if (use_temp_zone) { 4307 if (use_temp_zone) {
4343 DCHECK(main_scope != scope); 4308 DCHECK(main_scope != scope);
4344 scope->AnalyzePartially(main_scope, &previous_zone_ast_node_factory); 4309 scope->AnalyzePartially(main_scope, &previous_zone_ast_node_factory);
4345 } 4310 }
4346 } // DiscardableZoneScope goes out of scope. 4311 } // DiscardableZoneScope goes out of scope.
4347 4312
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after
5349 5314
5350 // We cannot internalize on a background thread; a foreground task will take 5315 // We cannot internalize on a background thread; a foreground task will take
5351 // care of calling Parser::Internalize just before compilation. 5316 // care of calling Parser::Internalize just before compilation.
5352 5317
5353 if (produce_cached_parse_data()) { 5318 if (produce_cached_parse_data()) {
5354 if (result != NULL) *info->cached_data() = recorder.GetScriptData(); 5319 if (result != NULL) *info->cached_data() = recorder.GetScriptData();
5355 log_ = NULL; 5320 log_ = NULL;
5356 } 5321 }
5357 } 5322 }
5358 5323
5359 ParserBaseTraits<Parser>::TemplateLiteralState Parser::OpenTemplateLiteral( 5324 Parser::TemplateLiteralState Parser::OpenTemplateLiteral(int pos) {
5360 int pos) { 5325 return new (zone()) TemplateLiteral(zone(), pos);
5361 return new (zone()) ParserBaseTraits<Parser>::TemplateLiteral(zone(), pos);
5362 } 5326 }
5363 5327
5364 5328
5365 void Parser::AddTemplateSpan(TemplateLiteralState* state, bool tail) { 5329 void Parser::AddTemplateSpan(TemplateLiteralState* state, bool tail) {
5366 int pos = scanner()->location().beg_pos; 5330 int pos = scanner()->location().beg_pos;
5367 int end = scanner()->location().end_pos - (tail ? 1 : 2); 5331 int end = scanner()->location().end_pos - (tail ? 1 : 2);
5368 const AstRawString* tv = scanner()->CurrentSymbol(ast_value_factory()); 5332 const AstRawString* tv = scanner()->CurrentSymbol(ast_value_factory());
5369 const AstRawString* trv = scanner()->CurrentRawSymbol(ast_value_factory()); 5333 const AstRawString* trv = scanner()->CurrentRawSymbol(ast_value_factory());
5370 Literal* cooked = factory()->NewStringLiteral(tv, pos); 5334 Literal* cooked = factory()->NewStringLiteral(tv, pos);
5371 Literal* raw = factory()->NewStringLiteral(trv, pos); 5335 Literal* raw = factory()->NewStringLiteral(trv, pos);
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
5627 ZoneList<Expression*>* args) { 5591 ZoneList<Expression*>* args) {
5628 AstNodeFactory* factory = delegate()->factory(); 5592 AstNodeFactory* factory = delegate()->factory();
5629 Expression* expr = args->at(0); 5593 Expression* expr = args->at(0);
5630 for (int i = 1; i < args->length(); ++i) { 5594 for (int i = 1; i < args->length(); ++i) {
5631 expr = factory->NewBinaryOperation(Token::COMMA, expr, args->at(i), 5595 expr = factory->NewBinaryOperation(Token::COMMA, expr, args->at(i),
5632 expr->position()); 5596 expr->position());
5633 } 5597 }
5634 return expr; 5598 return expr;
5635 } 5599 }
5636 5600
5637 void ParserBaseTraits<Parser>::RewriteDestructuringAssignments() { 5601 Expression* Parser::RewriteAwaitExpression(Expression* value, int await_pos) {
5638 delegate()->RewriteDestructuringAssignments();
5639 }
5640
5641 Expression* ParserBaseTraits<Parser>::RewriteExponentiation(Expression* left,
5642 Expression* right,
5643 int pos) {
5644 return delegate()->RewriteExponentiation(left, right, pos);
5645 }
5646
5647 Expression* ParserBaseTraits<Parser>::RewriteAssignExponentiation(
5648 Expression* left, Expression* right, int pos) {
5649 return delegate()->RewriteAssignExponentiation(left, right, pos);
5650 }
5651
5652 void ParserBaseTraits<Parser>::RewriteNonPattern(
5653 Type::ExpressionClassifier* classifier, bool* ok) {
5654 delegate()->RewriteNonPattern(classifier, ok);
5655 }
5656
5657 Expression* ParserBaseTraits<Parser>::RewriteAwaitExpression(Expression* value,
5658 int await_pos) {
5659 // yield %AsyncFunctionAwait(.generator_object, <operand>) 5602 // yield %AsyncFunctionAwait(.generator_object, <operand>)
5660 Variable* generator_object_variable = 5603 Variable* generator_object_variable =
5661 delegate()->function_state_->generator_object_variable(); 5604 delegate()->function_state_->generator_object_variable();
5662 5605
5663 // If generator_object_variable is null, 5606 // If generator_object_variable is null,
5664 if (!generator_object_variable) return value; 5607 if (!generator_object_variable) return value;
5665 5608
5666 auto factory = delegate()->factory(); 5609 auto factory = delegate()->factory();
5667 const int nopos = kNoSourcePosition; 5610 const int nopos = kNoSourcePosition;
5668 5611
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
5900 append_body, finalize); 5843 append_body, finalize);
5901 do_block->statements()->Add(loop, zone()); 5844 do_block->statements()->Add(loop, zone());
5902 } 5845 }
5903 } 5846 }
5904 // Now, rewind the original array literal to truncate everything from the 5847 // Now, rewind the original array literal to truncate everything from the
5905 // first spread (included) until the end. This fixes $R's initialization. 5848 // first spread (included) until the end. This fixes $R's initialization.
5906 lit->RewindSpreads(); 5849 lit->RewindSpreads();
5907 return factory()->NewDoExpression(do_block, result, lit->position()); 5850 return factory()->NewDoExpression(do_block, result, lit->position());
5908 } 5851 }
5909 5852
5910 void ParserBaseTraits<Parser>::QueueDestructuringAssignmentForRewriting( 5853 void Parser::QueueDestructuringAssignmentForRewriting(Expression* expr) {
5911 Expression* expr) {
5912 DCHECK(expr->IsRewritableExpression()); 5854 DCHECK(expr->IsRewritableExpression());
5913 delegate()->function_state_->AddDestructuringAssignment( 5855 function_state_->AddDestructuringAssignment(
5914 Parser::DestructuringAssignment(expr, delegate()->scope())); 5856 DestructuringAssignment(expr, delegate()->scope()));
5915 } 5857 }
5916 5858
5917 void ParserBaseTraits<Parser>::QueueNonPatternForRewriting(Expression* expr, 5859 void Parser::QueueNonPatternForRewriting(Expression* expr, bool* ok) {
5918 bool* ok) {
5919 DCHECK(expr->IsRewritableExpression()); 5860 DCHECK(expr->IsRewritableExpression());
5920 delegate()->function_state_->AddNonPatternForRewriting(expr, ok); 5861 function_state_->AddNonPatternForRewriting(expr, ok);
5921 } 5862 }
5922 5863
5923 void ParserBaseTraits<Parser>::SetFunctionNameFromPropertyName( 5864 void ParserBaseTraits<Parser>::SetFunctionNameFromPropertyName(
5924 ObjectLiteralProperty* property, const AstRawString* name) { 5865 ObjectLiteralProperty* property, const AstRawString* name) {
5925 Expression* value = property->value(); 5866 Expression* value = property->value();
5926 5867
5927 // Computed name setting must happen at runtime. 5868 // Computed name setting must happen at runtime.
5928 if (property->is_computed_name()) return; 5869 if (property->is_computed_name()) return;
5929 5870
5930 // Getter and setter names are handled here because their names 5871 // Getter and setter names are handled here because their names
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after
6902 node->Print(Isolate::Current()); 6843 node->Print(Isolate::Current());
6903 } 6844 }
6904 #endif // DEBUG 6845 #endif // DEBUG
6905 6846
6906 #undef CHECK_OK 6847 #undef CHECK_OK
6907 #undef CHECK_OK_VOID 6848 #undef CHECK_OK_VOID
6908 #undef CHECK_FAILED 6849 #undef CHECK_FAILED
6909 6850
6910 } // namespace internal 6851 } // namespace internal
6911 } // namespace v8 6852 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698