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

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

Issue 2657413002: No need to collect literal counts.
Patch Set: Rebase. Created 3 years, 10 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/preparse-data.cc ('k') | src/parsing/preparser.cc » ('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 #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/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/scopes.h" 9 #include "src/ast/scopes.h"
10 #include "src/parsing/parser-base.h" 10 #include "src/parsing/parser-base.h"
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 PreParserStatement NewReturnStatement(PreParserExpression expression, 669 PreParserStatement NewReturnStatement(PreParserExpression expression,
670 int pos) { 670 int pos) {
671 return PreParserStatement::Jump(); 671 return PreParserStatement::Jump();
672 } 672 }
673 PreParserStatement NewAsyncReturnStatement(PreParserExpression expression, 673 PreParserStatement NewAsyncReturnStatement(PreParserExpression expression,
674 int pos) { 674 int pos) {
675 return PreParserStatement::Jump(); 675 return PreParserStatement::Jump();
676 } 676 }
677 PreParserExpression NewFunctionLiteral( 677 PreParserExpression NewFunctionLiteral(
678 PreParserIdentifier name, Scope* scope, PreParserStatementList body, 678 PreParserIdentifier name, Scope* scope, PreParserStatementList body,
679 int materialized_literal_count, int expected_property_count, 679 int expected_property_count, int parameter_count, int function_length,
680 int parameter_count, int function_length,
681 FunctionLiteral::ParameterFlag has_duplicate_parameters, 680 FunctionLiteral::ParameterFlag has_duplicate_parameters,
682 FunctionLiteral::FunctionType function_type, 681 FunctionLiteral::FunctionType function_type,
683 FunctionLiteral::EagerCompileHint eager_compile_hint, int position, 682 FunctionLiteral::EagerCompileHint eager_compile_hint, int position,
684 bool has_braces, int function_literal_id) { 683 bool has_braces, int function_literal_id) {
685 return PreParserExpression::Default(); 684 return PreParserExpression::Default();
686 } 685 }
687 686
688 PreParserExpression NewSpread(PreParserExpression expression, int pos, 687 PreParserExpression NewSpread(PreParserExpression expression, int pos,
689 int expr_pos) { 688 int expr_pos) {
690 return PreParserExpression::Spread(expression); 689 return PreParserExpression::Spread(expression);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 pending_error_handler_(pending_error_handler) {} 886 pending_error_handler_(pending_error_handler) {}
888 887
889 static bool const IsPreParser() { return true; } 888 static bool const IsPreParser() { return true; }
890 889
891 PreParserLogger* logger() { return &log_; } 890 PreParserLogger* logger() { return &log_; }
892 891
893 // Pre-parse the program from the character stream; returns true on 892 // Pre-parse the program from the character stream; returns true on
894 // success (even if parsing failed, the pre-parse data successfully 893 // success (even if parsing failed, the pre-parse data successfully
895 // captured the syntax error), and false if a stack-overflow happened 894 // captured the syntax error), and false if a stack-overflow happened
896 // during parsing. 895 // during parsing.
897 PreParseResult PreParseProgram(int* materialized_literals = 0, 896 PreParseResult PreParseProgram(bool is_module = false) {
898 bool is_module = false) {
899 DCHECK_NULL(scope_state_); 897 DCHECK_NULL(scope_state_);
900 DeclarationScope* scope = NewScriptScope(); 898 DeclarationScope* scope = NewScriptScope();
901 #ifdef DEBUG 899 #ifdef DEBUG
902 scope->set_is_being_lazily_parsed(true); 900 scope->set_is_being_lazily_parsed(true);
903 #endif 901 #endif
904 902
905 // ModuleDeclarationInstantiation for Source Text Module Records creates a 903 // ModuleDeclarationInstantiation for Source Text Module Records creates a
906 // new Module Environment Record whose outer lexical environment record is 904 // new Module Environment Record whose outer lexical environment record is
907 // the global scope. 905 // the global scope.
908 if (is_module) scope = NewModuleScope(scope); 906 if (is_module) scope = NewModuleScope(scope);
909 907
910 FunctionState top_scope(&function_state_, &scope_state_, scope); 908 FunctionState top_scope(&function_state_, &scope_state_, scope);
911 bool ok = true; 909 bool ok = true;
912 int start_position = scanner()->peek_location().beg_pos; 910 int start_position = scanner()->peek_location().beg_pos;
913 parsing_module_ = is_module; 911 parsing_module_ = is_module;
914 PreParserStatementList body; 912 PreParserStatementList body;
915 ParseStatementList(body, Token::EOS, &ok); 913 ParseStatementList(body, Token::EOS, &ok);
916 if (stack_overflow()) return kPreParseStackOverflow; 914 if (stack_overflow()) return kPreParseStackOverflow;
917 if (!ok) { 915 if (!ok) {
918 ReportUnexpectedToken(scanner()->current_token()); 916 ReportUnexpectedToken(scanner()->current_token());
919 } else if (is_strict(this->scope()->language_mode())) { 917 } else if (is_strict(this->scope()->language_mode())) {
920 CheckStrictOctalLiteral(start_position, scanner()->location().end_pos, 918 CheckStrictOctalLiteral(start_position, scanner()->location().end_pos,
921 &ok); 919 &ok);
922 } 920 }
923 if (materialized_literals) {
924 *materialized_literals = function_state_->materialized_literal_count();
925 }
926 return kPreParseSuccess; 921 return kPreParseSuccess;
927 } 922 }
928 923
929 // Parses a single function literal, from the opening parentheses before 924 // Parses a single function literal, from the opening parentheses before
930 // parameters to the closing brace after the body. 925 // parameters to the closing brace after the body.
931 // Returns a FunctionEntry describing the body of the function in enough 926 // Returns a FunctionEntry describing the body of the function in enough
932 // detail that it can be lazily compiled. 927 // detail that it can be lazily compiled.
933 // The scanner is expected to have matched the "function" or "function*" 928 // The scanner is expected to have matched the "function" or "function*"
934 // keyword and parameters, and have consumed the initial '{'. 929 // keyword and parameters, and have consumed the initial '{'.
935 // At return, unless an error occurred, the scanner is positioned before the 930 // At return, unless an error occurred, the scanner is positioned before the
(...skipping 13 matching lines...) Expand all
949 // All ParseXXX functions take as the last argument an *ok parameter 944 // All ParseXXX functions take as the last argument an *ok parameter
950 // which is set to false if parsing failed; it is unchanged otherwise. 945 // which is set to false if parsing failed; it is unchanged otherwise.
951 // By making the 'exception handling' explicit, we are forced to check 946 // By making the 'exception handling' explicit, we are forced to check
952 // for failure at the call sites. 947 // for failure at the call sites.
953 948
954 // Indicates that we won't switch from the preparser to the preparser; we'll 949 // Indicates that we won't switch from the preparser to the preparser; we'll
955 // just stay where we are. 950 // just stay where we are.
956 bool AllowsLazyParsingWithoutUnresolvedVariables() const { return false; } 951 bool AllowsLazyParsingWithoutUnresolvedVariables() const { return false; }
957 bool parse_lazily() const { return false; } 952 bool parse_lazily() const { return false; }
958 953
959 V8_INLINE LazyParsingResult SkipFunction( 954 V8_INLINE LazyParsingResult
960 FunctionKind kind, DeclarationScope* function_scope, int* num_parameters, 955 SkipFunction(FunctionKind kind, DeclarationScope* function_scope,
961 int* function_length, bool* has_duplicate_parameters, 956 int* num_parameters, int* function_length,
962 int* materialized_literal_count, int* expected_property_count, 957 bool* has_duplicate_parameters, int* expected_property_count,
963 bool is_inner_function, bool may_abort, bool* ok) { 958 bool is_inner_function, bool may_abort, bool* ok) {
964 UNREACHABLE(); 959 UNREACHABLE();
965 return kLazyParsingComplete; 960 return kLazyParsingComplete;
966 } 961 }
967 Expression ParseFunctionLiteral( 962 Expression ParseFunctionLiteral(
968 Identifier name, Scanner::Location function_name_location, 963 Identifier name, Scanner::Location function_name_location,
969 FunctionNameValidity function_name_validity, FunctionKind kind, 964 FunctionNameValidity function_name_validity, FunctionKind kind,
970 int function_token_pos, FunctionLiteral::FunctionType function_type, 965 int function_token_pos, FunctionLiteral::FunctionType function_type,
971 LanguageMode language_mode, bool* ok); 966 LanguageMode language_mode, bool* ok);
972 LazyParsingResult ParseStatementListAndLogFunction( 967 LazyParsingResult ParseStatementListAndLogFunction(
973 PreParserFormalParameters* formals, bool has_duplicate_parameters, 968 PreParserFormalParameters* formals, bool has_duplicate_parameters,
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 } 1627 }
1633 1628
1634 V8_INLINE PreParserExpression NoTemplateTag() { 1629 V8_INLINE PreParserExpression NoTemplateTag() {
1635 return PreParserExpression::NoTemplateTag(); 1630 return PreParserExpression::NoTemplateTag();
1636 } 1631 }
1637 1632
1638 V8_INLINE static bool IsTaggedTemplate(const PreParserExpression tag) { 1633 V8_INLINE static bool IsTaggedTemplate(const PreParserExpression tag) {
1639 return !tag.IsNoTemplateTag(); 1634 return !tag.IsNoTemplateTag();
1640 } 1635 }
1641 1636
1642 V8_INLINE void MaterializeUnspreadArgumentsLiterals(int count) {
1643 for (int i = 0; i < count; ++i) {
1644 function_state_->NextMaterializedLiteralIndex();
1645 }
1646 }
1647
1648 V8_INLINE PreParserExpression 1637 V8_INLINE PreParserExpression
1649 ExpressionListToExpression(PreParserExpressionList args) { 1638 ExpressionListToExpression(PreParserExpressionList args) {
1650 return PreParserExpression::Default(args.variables_); 1639 return PreParserExpression::Default(args.variables_);
1651 } 1640 }
1652 1641
1653 V8_INLINE void AddAccessorPrefixToFunctionName(bool is_get, 1642 V8_INLINE void AddAccessorPrefixToFunctionName(bool is_get,
1654 PreParserExpression function, 1643 PreParserExpression function,
1655 PreParserIdentifier name) {} 1644 PreParserIdentifier name) {}
1656 V8_INLINE void SetFunctionNameFromPropertyName(PreParserExpression property, 1645 V8_INLINE void SetFunctionNameFromPropertyName(PreParserExpression property,
1657 PreParserIdentifier name) {} 1646 PreParserIdentifier name) {}
(...skipping 29 matching lines...) Expand all
1687 1676
1688 PreParserExpression PreParser::SpreadCallNew(PreParserExpression function, 1677 PreParserExpression PreParser::SpreadCallNew(PreParserExpression function,
1689 PreParserExpressionList args, 1678 PreParserExpressionList args,
1690 int pos) { 1679 int pos) {
1691 return factory()->NewCallNew(function, args, pos); 1680 return factory()->NewCallNew(function, args, pos);
1692 } 1681 }
1693 1682
1694 PreParserExpression PreParser::CloseTemplateLiteral(TemplateLiteralState* state, 1683 PreParserExpression PreParser::CloseTemplateLiteral(TemplateLiteralState* state,
1695 int start, 1684 int start,
1696 PreParserExpression tag) { 1685 PreParserExpression tag) {
1697 if (IsTaggedTemplate(tag)) {
1698 // Emulate generation of array literals for tag callsite
1699 // 1st is array of cooked strings, second is array of raw strings
1700 function_state_->NextMaterializedLiteralIndex();
1701 function_state_->NextMaterializedLiteralIndex();
1702 }
1703 return EmptyExpression(); 1686 return EmptyExpression();
1704 } 1687 }
1705 1688
1706 } // namespace internal 1689 } // namespace internal
1707 } // namespace v8 1690 } // namespace v8
1708 1691
1709 #endif // V8_PARSING_PREPARSER_H 1692 #endif // V8_PARSING_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parsing/preparse-data.cc ('k') | src/parsing/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698