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

Side by Side Diff: src/parsing/preparser.h

Issue 2307073002: [parser] Refactor of Parse*Statement*, part 1 (Closed)
Patch Set: Fix weird compilation bug with line continuation in comment 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
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 #ifndef V8_PARSING_PREPARSER_H 5 #ifndef V8_PARSING_PREPARSER_H
6 #define V8_PARSING_PREPARSER_H 6 #define V8_PARSING_PREPARSER_H
7 7
8 #include "src/ast/scopes.h" 8 #include "src/ast/scopes.h"
9 #include "src/parsing/parser-base.h" 9 #include "src/parsing/parser-base.h"
10 10
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 154
155 static PreParserExpression StringLiteral() { 155 static PreParserExpression StringLiteral() {
156 return PreParserExpression(TypeField::encode(kStringLiteralExpression)); 156 return PreParserExpression(TypeField::encode(kStringLiteralExpression));
157 } 157 }
158 158
159 static PreParserExpression UseStrictStringLiteral() { 159 static PreParserExpression UseStrictStringLiteral() {
160 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | 160 return PreParserExpression(TypeField::encode(kStringLiteralExpression) |
161 IsUseStrictField::encode(true)); 161 IsUseStrictField::encode(true));
162 } 162 }
163 163
164 static PreParserExpression UseAsmStringLiteral() {
165 return PreParserExpression(TypeField::encode(kStringLiteralExpression) |
166 IsUseAsmField::encode(true));
167 }
168
164 static PreParserExpression This() { 169 static PreParserExpression This() {
165 return PreParserExpression(TypeField::encode(kExpression) | 170 return PreParserExpression(TypeField::encode(kExpression) |
166 ExpressionTypeField::encode(kThisExpression)); 171 ExpressionTypeField::encode(kThisExpression));
167 } 172 }
168 173
169 static PreParserExpression ThisProperty() { 174 static PreParserExpression ThisProperty() {
170 return PreParserExpression( 175 return PreParserExpression(
171 TypeField::encode(kExpression) | 176 TypeField::encode(kExpression) |
172 ExpressionTypeField::encode(kThisPropertyExpression)); 177 ExpressionTypeField::encode(kThisPropertyExpression));
173 } 178 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 232
228 bool IsStringLiteral() const { 233 bool IsStringLiteral() const {
229 return TypeField::decode(code_) == kStringLiteralExpression; 234 return TypeField::decode(code_) == kStringLiteralExpression;
230 } 235 }
231 236
232 bool IsUseStrictLiteral() const { 237 bool IsUseStrictLiteral() const {
233 return TypeField::decode(code_) == kStringLiteralExpression && 238 return TypeField::decode(code_) == kStringLiteralExpression &&
234 IsUseStrictField::decode(code_); 239 IsUseStrictField::decode(code_);
235 } 240 }
236 241
242 bool IsUseAsmLiteral() const {
243 return TypeField::decode(code_) == kStringLiteralExpression &&
244 IsUseAsmField::decode(code_);
245 }
246
237 bool IsThis() const { 247 bool IsThis() const {
238 return TypeField::decode(code_) == kExpression && 248 return TypeField::decode(code_) == kExpression &&
239 ExpressionTypeField::decode(code_) == kThisExpression; 249 ExpressionTypeField::decode(code_) == kThisExpression;
240 } 250 }
241 251
242 bool IsThisProperty() const { 252 bool IsThisProperty() const {
243 return TypeField::decode(code_) == kExpression && 253 return TypeField::decode(code_) == kExpression &&
244 ExpressionTypeField::decode(code_) == kThisPropertyExpression; 254 ExpressionTypeField::decode(code_) == kThisPropertyExpression;
245 } 255 }
246 256
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 // Expression ASTNode --- This is by necessity, due to the fact that 344 // Expression ASTNode --- This is by necessity, due to the fact that
335 // Expression nodes may be represented as multiple Types, not exclusively 345 // Expression nodes may be represented as multiple Types, not exclusively
336 // through kExpression. 346 // through kExpression.
337 // TODO(caitp, adamk): clean up PreParserExpression bitfields. 347 // TODO(caitp, adamk): clean up PreParserExpression bitfields.
338 typedef BitField<bool, 31, 1> ParenthesizedField; 348 typedef BitField<bool, 31, 1> ParenthesizedField;
339 349
340 // The rest of the bits are interpreted depending on the value 350 // The rest of the bits are interpreted depending on the value
341 // of the Type field, so they can share the storage. 351 // of the Type field, so they can share the storage.
342 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField; 352 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField;
343 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField; 353 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField;
354 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseAsmField;
344 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10> 355 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10>
345 IdentifierTypeField; 356 IdentifierTypeField;
346 typedef BitField<bool, TypeField::kNext, 1> HasCoverInitializedNameField; 357 typedef BitField<bool, TypeField::kNext, 1> HasCoverInitializedNameField;
347 358
348 uint32_t code_; 359 uint32_t code_;
349 }; 360 };
350 361
351 362
352 // The pre-parser doesn't need to build lists of expressions, identifiers, or 363 // The pre-parser doesn't need to build lists of expressions, identifiers, or
353 // the like. 364 // the like.
354 template <typename T> 365 template <typename T>
355 class PreParserList { 366 class PreParserList {
356 public: 367 public:
357 // These functions make list->Add(some_expression) work (and do nothing). 368 // These functions make list->Add(some_expression) work (and do nothing).
358 PreParserList() : length_(0) {} 369 PreParserList() : length_(0) {}
359 PreParserList* operator->() { return this; } 370 PreParserList* operator->() { return this; }
360 void Add(T, void*) { ++length_; } 371 void Add(T, void*) { ++length_; }
361 int length() const { return length_; } 372 int length() const { return length_; }
373 static PreParserList Null() { return PreParserList(-1); }
374 bool IsNull() const { return length_ == -1; }
375
362 private: 376 private:
377 explicit PreParserList(int n) : length_(n) {}
363 int length_; 378 int length_;
364 }; 379 };
365 380
366
367 typedef PreParserList<PreParserExpression> PreParserExpressionList; 381 typedef PreParserList<PreParserExpression> PreParserExpressionList;
368 382
383 class PreParserStatement;
384 typedef PreParserList<PreParserStatement> PreParserStatementList;
369 385
370 class PreParserStatement { 386 class PreParserStatement {
371 public: 387 public:
372 static PreParserStatement Default() { 388 static PreParserStatement Default() {
373 return PreParserStatement(kUnknownStatement); 389 return PreParserStatement(kUnknownStatement);
374 } 390 }
375 391
376 static PreParserStatement Jump() { 392 static PreParserStatement Jump() {
377 return PreParserStatement(kJumpStatement); 393 return PreParserStatement(kJumpStatement);
378 } 394 }
379 395
380 static PreParserStatement FunctionDeclaration() { 396 static PreParserStatement FunctionDeclaration() {
381 return PreParserStatement(kFunctionDeclaration); 397 return PreParserStatement(kFunctionDeclaration);
382 } 398 }
383 399
384 // Creates expression statement from expression. 400 // Creates expression statement from expression.
385 // Preserves being an unparenthesized string literal, possibly 401 // Preserves being an unparenthesized string literal, possibly
386 // "use strict". 402 // "use strict".
387 static PreParserStatement ExpressionStatement( 403 static PreParserStatement ExpressionStatement(
388 PreParserExpression expression) { 404 PreParserExpression expression) {
389 if (expression.IsUseStrictLiteral()) { 405 if (expression.IsUseStrictLiteral()) {
390 return PreParserStatement(kUseStrictExpressionStatement); 406 return PreParserStatement(kUseStrictExpressionStatement);
391 } 407 }
408 if (expression.IsUseAsmLiteral()) {
409 return PreParserStatement(kUseAsmExpressionStatement);
410 }
392 if (expression.IsStringLiteral()) { 411 if (expression.IsStringLiteral()) {
393 return PreParserStatement(kStringLiteralExpressionStatement); 412 return PreParserStatement(kStringLiteralExpressionStatement);
394 } 413 }
395 return Default(); 414 return Default();
396 } 415 }
397 416
398 bool IsStringLiteral() { 417 bool IsStringLiteral() {
399 return code_ == kStringLiteralExpressionStatement || IsUseStrictLiteral(); 418 return code_ == kStringLiteralExpressionStatement || IsUseStrictLiteral() ||
419 IsUseAsmLiteral();
400 } 420 }
401 421
402 bool IsUseStrictLiteral() { 422 bool IsUseStrictLiteral() {
403 return code_ == kUseStrictExpressionStatement; 423 return code_ == kUseStrictExpressionStatement;
404 } 424 }
405 425
426 bool IsUseAsmLiteral() { return code_ == kUseAsmExpressionStatement; }
427
406 bool IsFunctionDeclaration() { 428 bool IsFunctionDeclaration() {
407 return code_ == kFunctionDeclaration; 429 return code_ == kFunctionDeclaration;
408 } 430 }
409 431
410 bool IsJumpStatement() { 432 bool IsJumpStatement() {
411 return code_ == kJumpStatement; 433 return code_ == kJumpStatement;
412 } 434 }
413 435
436 // Dummy implementation for making statement->somefunc() work in both Parser
437 // and PreParser.
438 PreParserStatement* operator->() { return this; }
439
440 PreParserStatementList statements() { return PreParserStatementList(); }
441
414 private: 442 private:
415 enum Type { 443 enum Type {
416 kUnknownStatement, 444 kUnknownStatement,
417 kJumpStatement, 445 kJumpStatement,
418 kStringLiteralExpressionStatement, 446 kStringLiteralExpressionStatement,
419 kUseStrictExpressionStatement, 447 kUseStrictExpressionStatement,
448 kUseAsmExpressionStatement,
420 kFunctionDeclaration 449 kFunctionDeclaration
421 }; 450 };
422 451
423 explicit PreParserStatement(Type code) : code_(code) {} 452 explicit PreParserStatement(Type code) : code_(code) {}
424 Type code_; 453 Type code_;
425 }; 454 };
426 455
427 456
428 typedef PreParserList<PreParserStatement> PreParserStatementList;
429
430
431 class PreParserFactory { 457 class PreParserFactory {
432 public: 458 public:
433 explicit PreParserFactory(void* unused_value_factory) {} 459 explicit PreParserFactory(void* unused_value_factory) {}
434 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, 460 PreParserExpression NewStringLiteral(PreParserIdentifier identifier,
435 int pos) { 461 int pos) {
436 return PreParserExpression::Default(); 462 return PreParserExpression::Default();
437 } 463 }
438 PreParserExpression NewNumberLiteral(double number, 464 PreParserExpression NewNumberLiteral(double number,
439 int pos) { 465 int pos) {
440 return PreParserExpression::Default(); 466 return PreParserExpression::Default();
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 588
563 PreParserExpression NewSpread(PreParserExpression expression, int pos, 589 PreParserExpression NewSpread(PreParserExpression expression, int pos,
564 int expr_pos) { 590 int expr_pos) {
565 return PreParserExpression::Spread(expression); 591 return PreParserExpression::Spread(expression);
566 } 592 }
567 593
568 PreParserExpression NewEmptyParentheses(int pos) { 594 PreParserExpression NewEmptyParentheses(int pos) {
569 return PreParserExpression::Default(); 595 return PreParserExpression::Default();
570 } 596 }
571 597
598 PreParserStatement NewEmptyStatement(int pos) {
599 return PreParserStatement::Default();
600 }
601
602 PreParserStatement NewBlock(ZoneList<const AstRawString*>* labels,
603 int capacity, bool ignore_completion_value,
604 int pos) {
605 return PreParserStatement::Default();
606 }
607
572 // Return the object itself as AstVisitor and implement the needed 608 // Return the object itself as AstVisitor and implement the needed
573 // dummy method right in this class. 609 // dummy method right in this class.
574 PreParserFactory* visitor() { return this; } 610 PreParserFactory* visitor() { return this; }
575 int* ast_properties() { 611 int* ast_properties() {
576 static int dummy = 42; 612 static int dummy = 42;
577 return &dummy; 613 return &dummy;
578 } 614 }
579 }; 615 };
580 616
581 617
582 struct PreParserFormalParameters : FormalParametersBase { 618 struct PreParserFormalParameters : FormalParametersBase {
583 explicit PreParserFormalParameters(DeclarationScope* scope) 619 explicit PreParserFormalParameters(DeclarationScope* scope)
584 : FormalParametersBase(scope) {} 620 : FormalParametersBase(scope) {}
585 int arity = 0; 621 int arity = 0;
586 622
587 int Arity() const { return arity; } 623 int Arity() const { return arity; }
588 PreParserIdentifier at(int i) { return PreParserIdentifier(); } // Dummy 624 PreParserIdentifier at(int i) { return PreParserIdentifier(); } // Dummy
589 }; 625 };
590 626
591 627
592 class PreParser; 628 class PreParser;
593 629
630 class PreParserTarget {
631 public:
632 PreParserTarget(ParserBase<PreParser>* preparser,
633 PreParserStatement statement) {}
634 };
635
636 class PreParserTargetScope {
637 public:
638 explicit PreParserTargetScope(ParserBase<PreParser>* preparser) {}
639 };
640
594 template <> 641 template <>
595 struct ParserTypes<PreParser> { 642 struct ParserTypes<PreParser> {
596 typedef ParserBase<PreParser> Base; 643 typedef ParserBase<PreParser> Base;
597 typedef PreParser Impl; 644 typedef PreParser Impl;
598 645
599 // PreParser doesn't need to store generator variables. 646 // PreParser doesn't need to store generator variables.
600 typedef void GeneratorVariable; 647 typedef void GeneratorVariable;
601 648
602 // Return types for traversing functions. 649 // Return types for traversing functions.
603 typedef PreParserIdentifier Identifier; 650 typedef PreParserIdentifier Identifier;
604 typedef PreParserExpression Expression; 651 typedef PreParserExpression Expression;
605 typedef PreParserExpression FunctionLiteral; 652 typedef PreParserExpression FunctionLiteral;
606 typedef PreParserExpression ObjectLiteralProperty; 653 typedef PreParserExpression ObjectLiteralProperty;
607 typedef PreParserExpressionList ExpressionList; 654 typedef PreParserExpressionList ExpressionList;
608 typedef PreParserExpressionList PropertyList; 655 typedef PreParserExpressionList PropertyList;
609 typedef PreParserFormalParameters FormalParameters; 656 typedef PreParserFormalParameters FormalParameters;
657 typedef PreParserStatement Statement;
610 typedef PreParserStatementList StatementList; 658 typedef PreParserStatementList StatementList;
611 typedef PreParserStatement Block; 659 typedef PreParserStatement Block;
612 660
613 // For constructing objects returned by the traversing functions. 661 // For constructing objects returned by the traversing functions.
614 typedef PreParserFactory Factory; 662 typedef PreParserFactory Factory;
663
664 typedef PreParserTarget Target;
665 typedef PreParserTargetScope TargetScope;
615 }; 666 };
616 667
617 668
618 // Preparsing checks a JavaScript program and emits preparse-data that helps 669 // Preparsing checks a JavaScript program and emits preparse-data that helps
619 // a later parsing to be faster. 670 // a later parsing to be faster.
620 // See preparse-data-format.h for the data format. 671 // See preparse-data-format.h for the data format.
621 672
622 // The PreParser checks that the syntax follows the grammar for JavaScript, 673 // The PreParser checks that the syntax follows the grammar for JavaScript,
623 // and collects some information about the program along the way. 674 // and collects some information about the program along the way.
624 // The grammar check is only performed in order to understand the program 675 // The grammar check is only performed in order to understand the program
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 // ModuleDeclarationInstantiation for Source Text Module Records creates a 711 // ModuleDeclarationInstantiation for Source Text Module Records creates a
661 // new Module Environment Record whose outer lexical environment record is 712 // new Module Environment Record whose outer lexical environment record is
662 // the global scope. 713 // the global scope.
663 if (is_module) scope = NewModuleScope(scope); 714 if (is_module) scope = NewModuleScope(scope);
664 715
665 FunctionState top_scope(&function_state_, &scope_state_, scope, 716 FunctionState top_scope(&function_state_, &scope_state_, scope,
666 kNormalFunction); 717 kNormalFunction);
667 bool ok = true; 718 bool ok = true;
668 int start_position = scanner()->peek_location().beg_pos; 719 int start_position = scanner()->peek_location().beg_pos;
669 parsing_module_ = is_module; 720 parsing_module_ = is_module;
670 ParseStatementList(Token::EOS, &ok); 721 PreParserStatementList body;
722 ParseStatementList(body, Token::EOS, &ok);
671 if (stack_overflow()) return kPreParseStackOverflow; 723 if (stack_overflow()) return kPreParseStackOverflow;
672 if (!ok) { 724 if (!ok) {
673 ReportUnexpectedToken(scanner()->current_token()); 725 ReportUnexpectedToken(scanner()->current_token());
674 } else if (is_strict(this->scope()->language_mode())) { 726 } else if (is_strict(this->scope()->language_mode())) {
675 CheckStrictOctalLiteral(start_position, scanner()->location().end_pos, 727 CheckStrictOctalLiteral(start_position, scanner()->location().end_pos,
676 &ok); 728 &ok);
677 CheckDecimalLiteralWithLeadingZero(use_counts_, start_position, 729 CheckDecimalLiteralWithLeadingZero(use_counts_, start_position,
678 scanner()->location().end_pos); 730 scanner()->location().end_pos);
679 } 731 }
680 if (materialized_literals) { 732 if (materialized_literals) {
(...skipping 10 matching lines...) Expand all
691 // keyword and parameters, and have consumed the initial '{'. 743 // keyword and parameters, and have consumed the initial '{'.
692 // At return, unless an error occurred, the scanner is positioned before the 744 // At return, unless an error occurred, the scanner is positioned before the
693 // the final '}'. 745 // the final '}'.
694 PreParseResult PreParseLazyFunction(LanguageMode language_mode, 746 PreParseResult PreParseLazyFunction(LanguageMode language_mode,
695 FunctionKind kind, 747 FunctionKind kind,
696 bool has_simple_parameters, 748 bool has_simple_parameters,
697 bool parsing_module, ParserRecorder* log, 749 bool parsing_module, ParserRecorder* log,
698 bool may_abort, int* use_counts); 750 bool may_abort, int* use_counts);
699 751
700 private: 752 private:
701 static const int kLazyParseTrialLimit = 200;
702
703 // These types form an algebra over syntactic categories that is just 753 // These types form an algebra over syntactic categories that is just
704 // rich enough to let us recognize and propagate the constructs that 754 // rich enough to let us recognize and propagate the constructs that
705 // are either being counted in the preparser data, or is important 755 // are either being counted in the preparser data, or is important
706 // to throw the correct syntax error exceptions. 756 // to throw the correct syntax error exceptions.
707 757
708 // All ParseXXX functions take as the last argument an *ok parameter 758 // All ParseXXX functions take as the last argument an *ok parameter
709 // which is set to false if parsing failed; it is unchanged otherwise. 759 // which is set to false if parsing failed; it is unchanged otherwise.
710 // By making the 'exception handling' explicit, we are forced to check 760 // By making the 'exception handling' explicit, we are forced to check
711 // for failure at the call sites. 761 // for failure at the call sites.
712 Statement ParseStatementListItem(bool* ok);
713 V8_INLINE void ParseStatementList(int end_token, bool* ok) {
714 LazyParsingResult result = ParseStatementList(end_token, false, ok);
715 USE(result); // The result is just used in debug modes.
716 DCHECK_EQ(result, kLazyParsingComplete);
717 }
718 LazyParsingResult ParseStatementList(int end_token, bool may_abort, bool* ok);
719 Statement ParseStatement(AllowLabelledFunctionStatement allow_function,
720 bool* ok);
721 Statement ParseSubStatement(AllowLabelledFunctionStatement allow_function,
722 bool* ok);
723 Statement ParseScopedStatement(bool legacy, bool* ok); 762 Statement ParseScopedStatement(bool legacy, bool* ok);
724 Statement ParseHoistableDeclaration(bool* ok); 763 Statement ParseHoistableDeclaration(ZoneList<const AstRawString*>* names,
764 bool default_export, bool* ok);
725 Statement ParseHoistableDeclaration(int pos, ParseFunctionFlags flags, 765 Statement ParseHoistableDeclaration(int pos, ParseFunctionFlags flags,
726 bool* ok); 766 ZoneList<const AstRawString*>* names,
767 bool default_export, bool* ok);
727 Statement ParseFunctionDeclaration(bool* ok); 768 Statement ParseFunctionDeclaration(bool* ok);
728 Statement ParseAsyncFunctionDeclaration(bool* ok); 769 Statement ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names,
770 bool default_export, bool* ok);
729 Expression ParseAsyncFunctionExpression(bool* ok); 771 Expression ParseAsyncFunctionExpression(bool* ok);
730 Statement ParseClassDeclaration(bool* ok); 772 Statement ParseClassDeclaration(ZoneList<const AstRawString*>* names,
731 Statement ParseBlock(bool* ok); 773 bool default_export, bool* ok);
774 Statement ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok);
732 Statement ParseVariableStatement(VariableDeclarationContext var_context, 775 Statement ParseVariableStatement(VariableDeclarationContext var_context,
776 ZoneList<const AstRawString*>* names,
733 bool* ok); 777 bool* ok);
734 Statement ParseExpressionOrLabelledStatement( 778 Statement ParseExpressionOrLabelledStatement(
779 ZoneList<const AstRawString*>* names,
735 AllowLabelledFunctionStatement allow_function, bool* ok); 780 AllowLabelledFunctionStatement allow_function, bool* ok);
736 Statement ParseIfStatement(bool* ok); 781 Statement ParseIfStatement(ZoneList<const AstRawString*>* labels, bool* ok);
737 Statement ParseContinueStatement(bool* ok); 782 Statement ParseContinueStatement(bool* ok);
738 Statement ParseBreakStatement(bool* ok); 783 Statement ParseBreakStatement(ZoneList<const AstRawString*>* labels,
784 bool* ok);
739 Statement ParseReturnStatement(bool* ok); 785 Statement ParseReturnStatement(bool* ok);
740 Statement ParseWithStatement(bool* ok); 786 Statement ParseWithStatement(ZoneList<const AstRawString*>* labels, bool* ok);
741 Statement ParseSwitchStatement(bool* ok); 787 Statement ParseSwitchStatement(ZoneList<const AstRawString*>* labels,
742 Statement ParseDoWhileStatement(bool* ok); 788 bool* ok);
743 Statement ParseWhileStatement(bool* ok); 789 Statement ParseDoWhileStatement(ZoneList<const AstRawString*>* labels,
744 Statement ParseForStatement(bool* ok); 790 bool* ok);
791 Statement ParseWhileStatement(ZoneList<const AstRawString*>* labels,
792 bool* ok);
793 Statement ParseForStatement(ZoneList<const AstRawString*>* labels, bool* ok);
745 Statement ParseThrowStatement(bool* ok); 794 Statement ParseThrowStatement(bool* ok);
746 Statement ParseTryStatement(bool* ok); 795 Statement ParseTryStatement(bool* ok);
747 Statement ParseDebuggerStatement(bool* ok); 796 Statement ParseDebuggerStatement(bool* ok);
748 Expression ParseConditionalExpression(bool accept_IN, bool* ok); 797 Expression ParseConditionalExpression(bool accept_IN, bool* ok);
749 Expression ParseObjectLiteral(bool* ok); 798 Expression ParseObjectLiteral(bool* ok);
750 Expression ParseV8Intrinsic(bool* ok); 799 Expression ParseV8Intrinsic(bool* ok);
751 Expression ParseDoExpression(bool* ok); 800 Expression ParseDoExpression(bool* ok);
752 801
753 V8_INLINE PreParserStatementList ParseEagerFunctionBody( 802 V8_INLINE PreParserStatementList ParseEagerFunctionBody(
754 PreParserIdentifier function_name, int pos, 803 PreParserIdentifier function_name, int pos,
(...skipping 23 matching lines...) Expand all
778 V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos) { 827 V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos) {
779 return TemplateLiteralState(); 828 return TemplateLiteralState();
780 } 829 }
781 V8_INLINE void AddTemplateExpression(TemplateLiteralState* state, 830 V8_INLINE void AddTemplateExpression(TemplateLiteralState* state,
782 PreParserExpression expression) {} 831 PreParserExpression expression) {}
783 V8_INLINE void AddTemplateSpan(TemplateLiteralState* state, bool tail) {} 832 V8_INLINE void AddTemplateSpan(TemplateLiteralState* state, bool tail) {}
784 V8_INLINE PreParserExpression CloseTemplateLiteral( 833 V8_INLINE PreParserExpression CloseTemplateLiteral(
785 TemplateLiteralState* state, int start, PreParserExpression tag); 834 TemplateLiteralState* state, int start, PreParserExpression tag);
786 V8_INLINE void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} 835 V8_INLINE void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {}
787 836
837 V8_INLINE void SetLanguageMode(Scope* scope, LanguageMode mode) {
838 scope->SetLanguageMode(mode);
839 }
840 V8_INLINE void SetAsmModule() {}
841
788 V8_INLINE void MarkCollectedTailCallExpressions() {} 842 V8_INLINE void MarkCollectedTailCallExpressions() {}
789 V8_INLINE void MarkTailPosition(PreParserExpression expression) {} 843 V8_INLINE void MarkTailPosition(PreParserExpression expression) {}
790 844
791 void ParseAsyncArrowSingleExpressionBody(PreParserStatementList body, 845 void ParseAsyncArrowSingleExpressionBody(PreParserStatementList body,
792 bool accept_IN, 846 bool accept_IN,
793 int pos, bool* ok); 847 int pos, bool* ok);
794 848
795 V8_INLINE PreParserExpressionList 849 V8_INLINE PreParserExpressionList
796 PrepareSpreadArguments(PreParserExpressionList list) { 850 PrepareSpreadArguments(PreParserExpressionList list) {
797 return list; 851 return list;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 V8_INLINE static bool IsBoilerplateProperty(PreParserExpression property) { 946 V8_INLINE static bool IsBoilerplateProperty(PreParserExpression property) {
893 // PreParser doesn't count boilerplate properties. 947 // PreParser doesn't count boilerplate properties.
894 return false; 948 return false;
895 } 949 }
896 950
897 V8_INLINE static bool IsArrayIndex(PreParserIdentifier string, 951 V8_INLINE static bool IsArrayIndex(PreParserIdentifier string,
898 uint32_t* index) { 952 uint32_t* index) {
899 return false; 953 return false;
900 } 954 }
901 955
956 V8_INLINE bool IsUseStrictDirective(PreParserStatement statement) const {
957 return statement.IsUseStrictLiteral();
958 }
959
960 V8_INLINE bool IsUseAsmDirective(PreParserStatement statement) const {
961 return statement.IsUseAsmLiteral();
962 }
963
964 V8_INLINE bool IsStringLiteral(PreParserStatement statement) const {
965 return statement.IsStringLiteral();
966 }
967
902 V8_INLINE static PreParserExpression GetPropertyValue( 968 V8_INLINE static PreParserExpression GetPropertyValue(
903 PreParserExpression property) { 969 PreParserExpression property) {
904 return PreParserExpression::Default(); 970 return PreParserExpression::Default();
905 } 971 }
906 972
907 // Functions for encapsulating the differences between parsing and preparsing; 973 // Functions for encapsulating the differences between parsing and preparsing;
908 // operations interleaved with the recursive descent. 974 // operations interleaved with the recursive descent.
909 V8_INLINE static void PushLiteralName(FuncNameInferrer* fni, 975 V8_INLINE static void PushLiteralName(FuncNameInferrer* fni,
910 PreParserIdentifier id) { 976 PreParserIdentifier id) {
911 // PreParser should not use FuncNameInferrer. 977 // PreParser should not use FuncNameInferrer.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 } 1069 }
1004 V8_INLINE static PreParserExpression EmptyFunctionLiteral() { 1070 V8_INLINE static PreParserExpression EmptyFunctionLiteral() {
1005 return PreParserExpression::Default(); 1071 return PreParserExpression::Default();
1006 } 1072 }
1007 1073
1008 V8_INLINE static bool IsEmptyExpression(PreParserExpression expr) { 1074 V8_INLINE static bool IsEmptyExpression(PreParserExpression expr) {
1009 return expr.IsEmpty(); 1075 return expr.IsEmpty();
1010 } 1076 }
1011 1077
1012 V8_INLINE static PreParserExpressionList NullExpressionList() { 1078 V8_INLINE static PreParserExpressionList NullExpressionList() {
1013 return PreParserExpressionList(); 1079 return PreParserExpressionList::Null();
1080 }
1081
1082 V8_INLINE static bool IsNullExpressionList(PreParserExpressionList exprs) {
1083 return exprs.IsNull();
1014 } 1084 }
1015 1085
1016 V8_INLINE static PreParserStatementList NullStatementList() { 1086 V8_INLINE static PreParserStatementList NullStatementList() {
1017 return PreParserStatementList(); 1087 return PreParserStatementList::Null();
1088 }
1089
1090 V8_INLINE static bool IsNullStatementList(PreParserStatementList stmts) {
1091 return stmts.IsNull();
1092 }
1093
1094 V8_INLINE static PreParserStatement NullStatement() {
1095 return PreParserStatement::Default();
1096 }
1097
1098 V8_INLINE bool IsNullOrEmptyStatement(PreParserStatement stmt) {
1099 // TODO(nikolaos): See if this needs to be consistent for the preparser.
1100 return false;
1018 } 1101 }
1019 1102
1020 V8_INLINE static PreParserStatement NullBlock() { 1103 V8_INLINE static PreParserStatement NullBlock() {
1021 return PreParserStatement::Default(); 1104 return PreParserStatement::Default();
1022 } 1105 }
1023 1106
1024 V8_INLINE PreParserIdentifier EmptyIdentifierString() const { 1107 V8_INLINE PreParserIdentifier EmptyIdentifierString() const {
1025 return PreParserIdentifier::Default(); 1108 return PreParserIdentifier::Default();
1026 } 1109 }
1027 1110
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 PreParserExpressionList args, 1262 PreParserExpressionList args,
1180 int pos) { 1263 int pos) {
1181 return factory()->NewCallNew(function, args, pos); 1264 return factory()->NewCallNew(function, args, pos);
1182 } 1265 }
1183 1266
1184 PreParserStatementList PreParser::ParseEagerFunctionBody( 1267 PreParserStatementList PreParser::ParseEagerFunctionBody(
1185 PreParserIdentifier function_name, int pos, 1268 PreParserIdentifier function_name, int pos,
1186 const PreParserFormalParameters& parameters, FunctionKind kind, 1269 const PreParserFormalParameters& parameters, FunctionKind kind,
1187 FunctionLiteral::FunctionType function_type, bool* ok) { 1270 FunctionLiteral::FunctionType function_type, bool* ok) {
1188 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 1271 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
1272 PreParserStatementList result;
1189 1273
1190 Scope* inner_scope = scope(); 1274 Scope* inner_scope = scope();
1191 if (!parameters.is_simple) inner_scope = NewScope(BLOCK_SCOPE); 1275 if (!parameters.is_simple) inner_scope = NewScope(BLOCK_SCOPE);
1192 1276
1193 { 1277 {
1194 BlockState block_state(&scope_state_, inner_scope); 1278 BlockState block_state(&scope_state_, inner_scope);
1195 ParseStatementList(Token::RBRACE, ok); 1279 ParseStatementList(result, Token::RBRACE, ok);
1196 if (!*ok) return PreParserStatementList(); 1280 if (!*ok) return PreParserStatementList();
1197 } 1281 }
1198 1282
1199 Expect(Token::RBRACE, ok); 1283 Expect(Token::RBRACE, ok);
1200 return PreParserStatementList(); 1284 return result;
1201 } 1285 }
1202 1286
1203 PreParserExpression PreParser::CloseTemplateLiteral(TemplateLiteralState* state, 1287 PreParserExpression PreParser::CloseTemplateLiteral(TemplateLiteralState* state,
1204 int start, 1288 int start,
1205 PreParserExpression tag) { 1289 PreParserExpression tag) {
1206 if (IsTaggedTemplate(tag)) { 1290 if (IsTaggedTemplate(tag)) {
1207 // Emulate generation of array literals for tag callsite 1291 // Emulate generation of array literals for tag callsite
1208 // 1st is array of cooked strings, second is array of raw strings 1292 // 1st is array of cooked strings, second is array of raw strings
1209 function_state_->NextMaterializedLiteralIndex(); 1293 function_state_->NextMaterializedLiteralIndex();
1210 function_state_->NextMaterializedLiteralIndex(); 1294 function_state_->NextMaterializedLiteralIndex();
1211 } 1295 }
1212 return EmptyExpression(); 1296 return EmptyExpression();
1213 } 1297 }
1214 1298
1215 } // namespace internal 1299 } // namespace internal
1216 } // namespace v8 1300 } // namespace v8
1217 1301
1218 #endif // V8_PARSING_PREPARSER_H 1302 #endif // V8_PARSING_PREPARSER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698