OLD | NEW |
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 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 DCHECK(expression.IsIdentifier() && expression.AsIdentifier().IsEval()); | 564 DCHECK(expression.IsIdentifier() && expression.AsIdentifier().IsEval()); |
565 return PreParserExpression::CallEval(); | 565 return PreParserExpression::CallEval(); |
566 } | 566 } |
567 return PreParserExpression::Call(); | 567 return PreParserExpression::Call(); |
568 } | 568 } |
569 PreParserExpression NewCallNew(PreParserExpression expression, | 569 PreParserExpression NewCallNew(PreParserExpression expression, |
570 PreParserExpressionList arguments, | 570 PreParserExpressionList arguments, |
571 int pos) { | 571 int pos) { |
572 return PreParserExpression::Default(); | 572 return PreParserExpression::Default(); |
573 } | 573 } |
574 PreParserExpression NewCallRuntime(const AstRawString* name, | |
575 const Runtime::Function* function, | |
576 PreParserExpressionList arguments, | |
577 int pos) { | |
578 return PreParserExpression::Default(); | |
579 } | |
580 PreParserStatement NewReturnStatement(PreParserExpression expression, | 574 PreParserStatement NewReturnStatement(PreParserExpression expression, |
581 int pos) { | 575 int pos) { |
582 return PreParserStatement::Default(); | 576 return PreParserStatement::Default(); |
583 } | 577 } |
584 PreParserExpression NewFunctionLiteral( | 578 PreParserExpression NewFunctionLiteral( |
585 PreParserIdentifier name, Scope* scope, PreParserStatementList body, | 579 PreParserIdentifier name, Scope* scope, PreParserStatementList body, |
586 int materialized_literal_count, int expected_property_count, | 580 int materialized_literal_count, int expected_property_count, |
587 int parameter_count, | 581 int parameter_count, |
588 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 582 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
589 FunctionLiteral::FunctionType function_type, | 583 FunctionLiteral::FunctionType function_type, |
(...skipping 14 matching lines...) Expand all Loading... |
604 PreParserStatement NewEmptyStatement(int pos) { | 598 PreParserStatement NewEmptyStatement(int pos) { |
605 return PreParserStatement::Default(); | 599 return PreParserStatement::Default(); |
606 } | 600 } |
607 | 601 |
608 PreParserStatement NewBlock(ZoneList<const AstRawString*>* labels, | 602 PreParserStatement NewBlock(ZoneList<const AstRawString*>* labels, |
609 int capacity, bool ignore_completion_value, | 603 int capacity, bool ignore_completion_value, |
610 int pos) { | 604 int pos) { |
611 return PreParserStatement::Default(); | 605 return PreParserStatement::Default(); |
612 } | 606 } |
613 | 607 |
| 608 PreParserStatement NewDebuggerStatement(int pos) { |
| 609 return PreParserStatement::Default(); |
| 610 } |
| 611 |
614 // Return the object itself as AstVisitor and implement the needed | 612 // Return the object itself as AstVisitor and implement the needed |
615 // dummy method right in this class. | 613 // dummy method right in this class. |
616 PreParserFactory* visitor() { return this; } | 614 PreParserFactory* visitor() { return this; } |
617 int* ast_properties() { | 615 int* ast_properties() { |
618 static int dummy = 42; | 616 static int dummy = 42; |
619 return &dummy; | 617 return &dummy; |
620 } | 618 } |
621 }; | 619 }; |
622 | 620 |
623 | 621 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 int start_position = scanner()->peek_location().beg_pos; | 724 int start_position = scanner()->peek_location().beg_pos; |
727 parsing_module_ = is_module; | 725 parsing_module_ = is_module; |
728 PreParserStatementList body; | 726 PreParserStatementList body; |
729 ParseStatementList(body, Token::EOS, &ok); | 727 ParseStatementList(body, Token::EOS, &ok); |
730 if (stack_overflow()) return kPreParseStackOverflow; | 728 if (stack_overflow()) return kPreParseStackOverflow; |
731 if (!ok) { | 729 if (!ok) { |
732 ReportUnexpectedToken(scanner()->current_token()); | 730 ReportUnexpectedToken(scanner()->current_token()); |
733 } else if (is_strict(this->scope()->language_mode())) { | 731 } else if (is_strict(this->scope()->language_mode())) { |
734 CheckStrictOctalLiteral(start_position, scanner()->location().end_pos, | 732 CheckStrictOctalLiteral(start_position, scanner()->location().end_pos, |
735 &ok); | 733 &ok); |
736 CheckDecimalLiteralWithLeadingZero(use_counts_, start_position, | 734 CheckDecimalLiteralWithLeadingZero(start_position, |
737 scanner()->location().end_pos); | 735 scanner()->location().end_pos); |
738 } | 736 } |
739 if (materialized_literals) { | 737 if (materialized_literals) { |
740 *materialized_literals = function_state_->materialized_literal_count(); | 738 *materialized_literals = function_state_->materialized_literal_count(); |
741 } | 739 } |
742 return kPreParseSuccess; | 740 return kPreParseSuccess; |
743 } | 741 } |
744 | 742 |
745 // Parses a single function literal, from the opening parentheses before | 743 // Parses a single function literal, from the opening parentheses before |
746 // parameters to the closing brace after the body. | 744 // parameters to the closing brace after the body. |
(...skipping 12 matching lines...) Expand all Loading... |
759 private: | 757 private: |
760 // These types form an algebra over syntactic categories that is just | 758 // These types form an algebra over syntactic categories that is just |
761 // rich enough to let us recognize and propagate the constructs that | 759 // rich enough to let us recognize and propagate the constructs that |
762 // are either being counted in the preparser data, or is important | 760 // are either being counted in the preparser data, or is important |
763 // to throw the correct syntax error exceptions. | 761 // to throw the correct syntax error exceptions. |
764 | 762 |
765 // All ParseXXX functions take as the last argument an *ok parameter | 763 // All ParseXXX functions take as the last argument an *ok parameter |
766 // which is set to false if parsing failed; it is unchanged otherwise. | 764 // which is set to false if parsing failed; it is unchanged otherwise. |
767 // By making the 'exception handling' explicit, we are forced to check | 765 // By making the 'exception handling' explicit, we are forced to check |
768 // for failure at the call sites. | 766 // for failure at the call sites. |
769 Statement ParseScopedStatement(bool legacy, bool* ok); | |
770 Statement ParseHoistableDeclaration(ZoneList<const AstRawString*>* names, | 767 Statement ParseHoistableDeclaration(ZoneList<const AstRawString*>* names, |
771 bool default_export, bool* ok); | 768 bool default_export, bool* ok); |
772 Statement ParseHoistableDeclaration(int pos, ParseFunctionFlags flags, | 769 Statement ParseHoistableDeclaration(int pos, ParseFunctionFlags flags, |
773 ZoneList<const AstRawString*>* names, | 770 ZoneList<const AstRawString*>* names, |
774 bool default_export, bool* ok); | 771 bool default_export, bool* ok); |
775 Statement ParseFunctionDeclaration(bool* ok); | 772 Statement ParseFunctionDeclaration(bool* ok); |
776 Statement ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, | 773 Statement ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, |
777 bool default_export, bool* ok); | 774 bool default_export, bool* ok); |
778 Expression ParseAsyncFunctionExpression(bool* ok); | 775 Expression ParseAsyncFunctionExpression(bool* ok); |
779 Statement ParseClassDeclaration(ZoneList<const AstRawString*>* names, | 776 Statement ParseClassDeclaration(ZoneList<const AstRawString*>* names, |
780 bool default_export, bool* ok); | 777 bool default_export, bool* ok); |
781 Statement ParseVariableStatement(VariableDeclarationContext var_context, | |
782 ZoneList<const AstRawString*>* names, | |
783 bool* ok); | |
784 Statement ParseExpressionOrLabelledStatement( | 778 Statement ParseExpressionOrLabelledStatement( |
785 ZoneList<const AstRawString*>* names, | 779 ZoneList<const AstRawString*>* names, |
786 AllowLabelledFunctionStatement allow_function, bool* ok); | 780 AllowLabelledFunctionStatement allow_function, bool* ok); |
787 Statement ParseIfStatement(ZoneList<const AstRawString*>* labels, bool* ok); | 781 Statement ParseIfStatement(ZoneList<const AstRawString*>* labels, bool* ok); |
788 Statement ParseContinueStatement(bool* ok); | 782 Statement ParseContinueStatement(bool* ok); |
789 Statement ParseBreakStatement(ZoneList<const AstRawString*>* labels, | 783 Statement ParseBreakStatement(ZoneList<const AstRawString*>* labels, |
790 bool* ok); | 784 bool* ok); |
791 Statement ParseReturnStatement(bool* ok); | 785 Statement ParseReturnStatement(bool* ok); |
792 Statement ParseWithStatement(ZoneList<const AstRawString*>* labels, bool* ok); | 786 Statement ParseWithStatement(ZoneList<const AstRawString*>* labels, bool* ok); |
793 Statement ParseSwitchStatement(ZoneList<const AstRawString*>* labels, | 787 Statement ParseSwitchStatement(ZoneList<const AstRawString*>* labels, |
794 bool* ok); | 788 bool* ok); |
795 Statement ParseDoWhileStatement(ZoneList<const AstRawString*>* labels, | 789 Statement ParseDoWhileStatement(ZoneList<const AstRawString*>* labels, |
796 bool* ok); | 790 bool* ok); |
797 Statement ParseWhileStatement(ZoneList<const AstRawString*>* labels, | 791 Statement ParseWhileStatement(ZoneList<const AstRawString*>* labels, |
798 bool* ok); | 792 bool* ok); |
799 Statement ParseForStatement(ZoneList<const AstRawString*>* labels, bool* ok); | 793 Statement ParseForStatement(ZoneList<const AstRawString*>* labels, bool* ok); |
800 Statement ParseThrowStatement(bool* ok); | 794 Statement ParseThrowStatement(bool* ok); |
801 Statement ParseTryStatement(bool* ok); | 795 Statement ParseTryStatement(bool* ok); |
802 Statement ParseDebuggerStatement(bool* ok); | |
803 Expression ParseConditionalExpression(bool accept_IN, bool* ok); | 796 Expression ParseConditionalExpression(bool accept_IN, bool* ok); |
804 Expression ParseObjectLiteral(bool* ok); | 797 Expression ParseObjectLiteral(bool* ok); |
805 Expression ParseV8Intrinsic(bool* ok); | |
806 Expression ParseDoExpression(bool* ok); | 798 Expression ParseDoExpression(bool* ok); |
807 | 799 |
808 V8_INLINE PreParserStatementList ParseEagerFunctionBody( | 800 V8_INLINE PreParserStatementList ParseEagerFunctionBody( |
809 PreParserIdentifier function_name, int pos, | 801 PreParserIdentifier function_name, int pos, |
810 const PreParserFormalParameters& parameters, FunctionKind kind, | 802 const PreParserFormalParameters& parameters, FunctionKind kind, |
811 FunctionLiteral::FunctionType function_type, bool* ok); | 803 FunctionLiteral::FunctionType function_type, bool* ok); |
812 | 804 |
813 V8_INLINE LazyParsingResult | 805 V8_INLINE LazyParsingResult |
814 SkipLazyFunctionBody(int* materialized_literal_count, | 806 SkipLazyFunctionBody(int* materialized_literal_count, |
815 int* expected_property_count, bool may_abort, bool* ok) { | 807 int* expected_property_count, bool may_abort, bool* ok) { |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 V8_INLINE PreParserStatementList NewStatementList(int size) const { | 1159 V8_INLINE PreParserStatementList NewStatementList(int size) const { |
1168 return PreParserStatementList(); | 1160 return PreParserStatementList(); |
1169 } | 1161 } |
1170 | 1162 |
1171 V8_INLINE static PreParserStatement NewBlock( | 1163 V8_INLINE static PreParserStatement NewBlock( |
1172 ZoneList<const AstRawString*>* labels, int capacity, | 1164 ZoneList<const AstRawString*>* labels, int capacity, |
1173 bool ignore_completion_value, int pos) { | 1165 bool ignore_completion_value, int pos) { |
1174 return PreParserStatement::Default(); | 1166 return PreParserStatement::Default(); |
1175 } | 1167 } |
1176 | 1168 |
| 1169 V8_INLINE PreParserExpression |
| 1170 NewV8Intrinsic(PreParserIdentifier name, PreParserExpressionList arguments, |
| 1171 int pos, bool* ok) { |
| 1172 return PreParserExpression::Default(); |
| 1173 } |
| 1174 |
1177 V8_INLINE void AddParameterInitializationBlock( | 1175 V8_INLINE void AddParameterInitializationBlock( |
1178 const PreParserFormalParameters& parameters, PreParserStatementList body, | 1176 const PreParserFormalParameters& parameters, PreParserStatementList body, |
1179 bool is_async, bool* ok) {} | 1177 bool is_async, bool* ok) {} |
1180 | 1178 |
1181 V8_INLINE void AddFormalParameter(PreParserFormalParameters* parameters, | 1179 V8_INLINE void AddFormalParameter(PreParserFormalParameters* parameters, |
1182 PreParserExpression pattern, | 1180 PreParserExpression pattern, |
1183 PreParserExpression initializer, | 1181 PreParserExpression initializer, |
1184 int initializer_end_position, | 1182 int initializer_end_position, |
1185 bool is_rest) { | 1183 bool is_rest) { |
1186 ++parameters->arity; | 1184 ++parameters->arity; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1233 | 1231 |
1234 V8_INLINE ZoneList<typename ExpressionClassifier::Error>* | 1232 V8_INLINE ZoneList<typename ExpressionClassifier::Error>* |
1235 GetReportedErrorList() const { | 1233 GetReportedErrorList() const { |
1236 return function_state_->GetReportedErrorList(); | 1234 return function_state_->GetReportedErrorList(); |
1237 } | 1235 } |
1238 | 1236 |
1239 V8_INLINE ZoneList<PreParserExpression>* GetNonPatternList() const { | 1237 V8_INLINE ZoneList<PreParserExpression>* GetNonPatternList() const { |
1240 return function_state_->non_patterns_to_rewrite(); | 1238 return function_state_->non_patterns_to_rewrite(); |
1241 } | 1239 } |
1242 | 1240 |
| 1241 V8_INLINE void CountUsage(v8::Isolate::UseCounterFeature feature) { |
| 1242 if (use_counts_ != nullptr) ++use_counts_[feature]; |
| 1243 } |
| 1244 |
1243 // Preparser's private field members. | 1245 // Preparser's private field members. |
1244 | 1246 |
1245 int* use_counts_; | 1247 int* use_counts_; |
1246 }; | 1248 }; |
1247 | 1249 |
1248 PreParserExpression PreParser::SpreadCall(PreParserExpression function, | 1250 PreParserExpression PreParser::SpreadCall(PreParserExpression function, |
1249 PreParserExpressionList args, | 1251 PreParserExpressionList args, |
1250 int pos) { | 1252 int pos) { |
1251 return factory()->NewCall(function, args, pos); | 1253 return factory()->NewCall(function, args, pos); |
1252 } | 1254 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1286 function_state_->NextMaterializedLiteralIndex(); | 1288 function_state_->NextMaterializedLiteralIndex(); |
1287 function_state_->NextMaterializedLiteralIndex(); | 1289 function_state_->NextMaterializedLiteralIndex(); |
1288 } | 1290 } |
1289 return EmptyExpression(); | 1291 return EmptyExpression(); |
1290 } | 1292 } |
1291 | 1293 |
1292 } // namespace internal | 1294 } // namespace internal |
1293 } // namespace v8 | 1295 } // namespace v8 |
1294 | 1296 |
1295 #endif // V8_PARSING_PREPARSER_H | 1297 #endif // V8_PARSING_PREPARSER_H |
OLD | NEW |