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

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

Issue 2349473004: Revert of Preparse inner functions. (Closed)
Patch Set: 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-base.h ('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/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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 kEvalIdentifier, 105 kEvalIdentifier,
106 kArgumentsIdentifier, 106 kArgumentsIdentifier,
107 kUndefinedIdentifier, 107 kUndefinedIdentifier,
108 kPrototypeIdentifier, 108 kPrototypeIdentifier,
109 kConstructorIdentifier, 109 kConstructorIdentifier,
110 kEnumIdentifier, 110 kEnumIdentifier,
111 kAwaitIdentifier, 111 kAwaitIdentifier,
112 kAsyncIdentifier 112 kAsyncIdentifier
113 }; 113 };
114 114
115 explicit PreParserIdentifier(Type type) : type_(type), string_(nullptr) {} 115 explicit PreParserIdentifier(Type type) : type_(type) {}
116 Type type_; 116 Type type_;
117 // Only non-nullptr when PreParser.track_unresolved_variables_ is true. 117
118 const AstRawString* string_;
119 friend class PreParserExpression; 118 friend class PreParserExpression;
120 friend class PreParser;
121 }; 119 };
122 120
123 121
124 class PreParserExpression { 122 class PreParserExpression {
125 public: 123 public:
126 PreParserExpression() : code_(TypeField::encode(kEmpty)) {} 124 PreParserExpression() : code_(TypeField::encode(kEmpty)) {}
127 125
128 static PreParserExpression Empty() { return PreParserExpression(); } 126 static PreParserExpression Empty() { return PreParserExpression(); }
129 127
130 static PreParserExpression Default() { 128 static PreParserExpression Default() {
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 enum PreParseResult { 754 enum PreParseResult {
757 kPreParseStackOverflow, 755 kPreParseStackOverflow,
758 kPreParseAbort, 756 kPreParseAbort,
759 kPreParseSuccess 757 kPreParseSuccess
760 }; 758 };
761 759
762 PreParser(Zone* zone, Scanner* scanner, AstValueFactory* ast_value_factory, 760 PreParser(Zone* zone, Scanner* scanner, AstValueFactory* ast_value_factory,
763 ParserRecorder* log, uintptr_t stack_limit) 761 ParserRecorder* log, uintptr_t stack_limit)
764 : ParserBase<PreParser>(zone, scanner, stack_limit, NULL, 762 : ParserBase<PreParser>(zone, scanner, stack_limit, NULL,
765 ast_value_factory, log), 763 ast_value_factory, log),
766 use_counts_(nullptr), 764 use_counts_(nullptr) {}
767 track_unresolved_variables_(false) {}
768 765
769 // Pre-parse the program from the character stream; returns true on 766 // Pre-parse the program from the character stream; returns true on
770 // success (even if parsing failed, the pre-parse data successfully 767 // success (even if parsing failed, the pre-parse data successfully
771 // captured the syntax error), and false if a stack-overflow happened 768 // captured the syntax error), and false if a stack-overflow happened
772 // during parsing. 769 // during parsing.
773 PreParseResult PreParseProgram(int* materialized_literals = 0, 770 PreParseResult PreParseProgram(int* materialized_literals = 0,
774 bool is_module = false) { 771 bool is_module = false) {
775 DCHECK_NULL(scope_state_); 772 DCHECK_NULL(scope_state_);
776 DeclarationScope* scope = NewScriptScope(); 773 DeclarationScope* scope = NewScriptScope();
777 774
(...skipping 25 matching lines...) Expand all
803 } 800 }
804 801
805 // Parses a single function literal, from the opening parentheses before 802 // Parses a single function literal, from the opening parentheses before
806 // parameters to the closing brace after the body. 803 // parameters to the closing brace after the body.
807 // Returns a FunctionEntry describing the body of the function in enough 804 // Returns a FunctionEntry describing the body of the function in enough
808 // detail that it can be lazily compiled. 805 // detail that it can be lazily compiled.
809 // The scanner is expected to have matched the "function" or "function*" 806 // The scanner is expected to have matched the "function" or "function*"
810 // keyword and parameters, and have consumed the initial '{'. 807 // keyword and parameters, and have consumed the initial '{'.
811 // At return, unless an error occurred, the scanner is positioned before the 808 // At return, unless an error occurred, the scanner is positioned before the
812 // the final '}'. 809 // the final '}'.
813 PreParseResult PreParseLazyFunction(FunctionKind kind, 810 PreParseResult PreParseLazyFunction(LanguageMode language_mode,
814 DeclarationScope* function_scope, 811 FunctionKind kind,
812 bool has_simple_parameters,
815 bool parsing_module, ParserRecorder* log, 813 bool parsing_module, ParserRecorder* log,
816 bool track_unresolved_variables,
817 bool may_abort, int* use_counts); 814 bool may_abort, int* use_counts);
818 815
819 private: 816 private:
820 // These types form an algebra over syntactic categories that is just 817 // These types form an algebra over syntactic categories that is just
821 // rich enough to let us recognize and propagate the constructs that 818 // rich enough to let us recognize and propagate the constructs that
822 // are either being counted in the preparser data, or is important 819 // are either being counted in the preparser data, or is important
823 // to throw the correct syntax error exceptions. 820 // to throw the correct syntax error exceptions.
824 821
825 // All ParseXXX functions take as the last argument an *ok parameter 822 // All ParseXXX functions take as the last argument an *ok parameter
826 // which is set to false if parsing failed; it is unchanged otherwise. 823 // which is set to false if parsing failed; it is unchanged otherwise.
827 // By making the 'exception handling' explicit, we are forced to check 824 // By making the 'exception handling' explicit, we are forced to check
828 // for failure at the call sites. 825 // for failure at the call sites.
829 Statement ParseFunctionDeclaration(bool* ok); 826 Statement ParseFunctionDeclaration(bool* ok);
830 Statement ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, 827 Statement ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names,
831 bool default_export, bool* ok); 828 bool default_export, bool* ok);
832 Expression ParseAsyncFunctionExpression(bool* ok); 829 Expression ParseAsyncFunctionExpression(bool* ok);
833 Statement ParseClassDeclaration(ZoneList<const AstRawString*>* names, 830 Statement ParseClassDeclaration(ZoneList<const AstRawString*>* names,
834 bool default_export, bool* ok); 831 bool default_export, bool* ok);
835 Statement ParseForStatement(ZoneList<const AstRawString*>* labels, bool* ok); 832 Statement ParseForStatement(ZoneList<const AstRawString*>* labels, bool* ok);
836 Statement ParseTryStatement(bool* ok); 833 Statement ParseTryStatement(bool* ok);
837 Expression ParseConditionalExpression(bool accept_IN, bool* ok); 834 Expression ParseConditionalExpression(bool accept_IN, bool* ok);
838 Expression ParseObjectLiteral(bool* ok); 835 Expression ParseObjectLiteral(bool* ok);
839 836
840 V8_INLINE PreParserStatementList ParseEagerFunctionBody( 837 V8_INLINE PreParserStatementList ParseEagerFunctionBody(
841 PreParserIdentifier function_name, int pos, 838 PreParserIdentifier function_name, int pos,
842 const PreParserFormalParameters& parameters, FunctionKind kind, 839 const PreParserFormalParameters& parameters, FunctionKind kind,
843 FunctionLiteral::FunctionType function_type, bool* ok); 840 FunctionLiteral::FunctionType function_type, bool* ok);
844 841
845 V8_INLINE LazyParsingResult SkipLazyFunctionBody( 842 V8_INLINE LazyParsingResult
846 int* materialized_literal_count, int* expected_property_count, 843 SkipLazyFunctionBody(int* materialized_literal_count,
847 bool track_unresolved_variables, bool may_abort, bool* ok) { 844 int* expected_property_count, bool may_abort, bool* ok) {
848 UNREACHABLE(); 845 UNREACHABLE();
849 return kLazyParsingComplete; 846 return kLazyParsingComplete;
850 } 847 }
851 Expression ParseFunctionLiteral( 848 Expression ParseFunctionLiteral(
852 Identifier name, Scanner::Location function_name_location, 849 Identifier name, Scanner::Location function_name_location,
853 FunctionNameValidity function_name_validity, FunctionKind kind, 850 FunctionNameValidity function_name_validity, FunctionKind kind,
854 int function_token_pos, FunctionLiteral::FunctionType function_type, 851 int function_token_pos, FunctionLiteral::FunctionType function_type,
855 LanguageMode language_mode, bool* ok); 852 LanguageMode language_mode, bool* ok);
856 LazyParsingResult ParseLazyFunctionLiteralBody(bool may_abort, bool* ok); 853 LazyParsingResult ParseLazyFunctionLiteralBody(bool may_abort, bool* ok);
857 854
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 1247
1251 V8_INLINE PreParserExpression FunctionSentExpression(int pos) { 1248 V8_INLINE PreParserExpression FunctionSentExpression(int pos) {
1252 return PreParserExpression::Default(); 1249 return PreParserExpression::Default();
1253 } 1250 }
1254 1251
1255 V8_INLINE PreParserExpression ExpressionFromLiteral(Token::Value token, 1252 V8_INLINE PreParserExpression ExpressionFromLiteral(Token::Value token,
1256 int pos) { 1253 int pos) {
1257 return PreParserExpression::Default(); 1254 return PreParserExpression::Default();
1258 } 1255 }
1259 1256
1260 PreParserExpression ExpressionFromIdentifier( 1257 V8_INLINE PreParserExpression ExpressionFromIdentifier(
1261 PreParserIdentifier name, int start_position, int end_position, 1258 PreParserIdentifier name, int start_position, int end_position,
1262 InferName infer = InferName::kYes); 1259 InferName infer = InferName::kYes) {
1260 return PreParserExpression::FromIdentifier(name);
1261 }
1263 1262
1264 V8_INLINE PreParserExpression ExpressionFromString(int pos) { 1263 V8_INLINE PreParserExpression ExpressionFromString(int pos) {
1265 if (scanner()->UnescapedLiteralMatches("use strict", 10)) { 1264 if (scanner()->UnescapedLiteralMatches("use strict", 10)) {
1266 return PreParserExpression::UseStrictStringLiteral(); 1265 return PreParserExpression::UseStrictStringLiteral();
1267 } 1266 }
1268 return PreParserExpression::StringLiteral(); 1267 return PreParserExpression::StringLiteral();
1269 } 1268 }
1270 1269
1271 V8_INLINE PreParserExpressionList NewExpressionList(int size) const { 1270 V8_INLINE PreParserExpressionList NewExpressionList(int size) const {
1272 return PreParserExpressionList(); 1271 return PreParserExpressionList();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 return function_state_->non_patterns_to_rewrite(); 1366 return function_state_->non_patterns_to_rewrite();
1368 } 1367 }
1369 1368
1370 V8_INLINE void CountUsage(v8::Isolate::UseCounterFeature feature) { 1369 V8_INLINE void CountUsage(v8::Isolate::UseCounterFeature feature) {
1371 if (use_counts_ != nullptr) ++use_counts_[feature]; 1370 if (use_counts_ != nullptr) ++use_counts_[feature];
1372 } 1371 }
1373 1372
1374 // Preparser's private field members. 1373 // Preparser's private field members.
1375 1374
1376 int* use_counts_; 1375 int* use_counts_;
1377 bool track_unresolved_variables_;
1378 }; 1376 };
1379 1377
1380 PreParserExpression PreParser::SpreadCall(PreParserExpression function, 1378 PreParserExpression PreParser::SpreadCall(PreParserExpression function,
1381 PreParserExpressionList args, 1379 PreParserExpressionList args,
1382 int pos) { 1380 int pos) {
1383 return factory()->NewCall(function, args, pos); 1381 return factory()->NewCall(function, args, pos);
1384 } 1382 }
1385 1383
1386 PreParserExpression PreParser::SpreadCallNew(PreParserExpression function, 1384 PreParserExpression PreParser::SpreadCallNew(PreParserExpression function,
1387 PreParserExpressionList args, 1385 PreParserExpressionList args,
(...skipping 30 matching lines...) Expand all
1418 function_state_->NextMaterializedLiteralIndex(); 1416 function_state_->NextMaterializedLiteralIndex();
1419 function_state_->NextMaterializedLiteralIndex(); 1417 function_state_->NextMaterializedLiteralIndex();
1420 } 1418 }
1421 return EmptyExpression(); 1419 return EmptyExpression();
1422 } 1420 }
1423 1421
1424 } // namespace internal 1422 } // namespace internal
1425 } // namespace v8 1423 } // namespace v8
1426 1424
1427 #endif // V8_PARSING_PREPARSER_H 1425 #endif // V8_PARSING_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parsing/parser-base.h ('k') | src/parsing/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698