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

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

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