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

Side by Side Diff: src/parsing/parser-base.h

Issue 2169823002: FunctionState doesn't need to know AstNodeFactory. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix Created 4 years, 5 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.cc ('k') | src/parsing/preparser.h » ('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_PARSER_BASE_H 5 #ifndef V8_PARSING_PARSER_BASE_H
6 #define V8_PARSING_PARSER_BASE_H 6 #define V8_PARSING_PARSER_BASE_H
7 7
8 #include "src/ast/scopes.h" 8 #include "src/ast/scopes.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/base/hashmap.h" 10 #include "src/base/hashmap.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 199
200 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, 200 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit,
201 v8::Extension* extension, AstValueFactory* ast_value_factory, 201 v8::Extension* extension, AstValueFactory* ast_value_factory,
202 ParserRecorder* log, typename Traits::Type::Parser this_object) 202 ParserRecorder* log, typename Traits::Type::Parser this_object)
203 : Traits(this_object), 203 : Traits(this_object),
204 scope_state_(nullptr), 204 scope_state_(nullptr),
205 function_state_(nullptr), 205 function_state_(nullptr),
206 extension_(extension), 206 extension_(extension),
207 fni_(nullptr), 207 fni_(nullptr),
208 ast_value_factory_(ast_value_factory), 208 ast_value_factory_(ast_value_factory),
209 ast_node_factory_(ast_value_factory),
209 log_(log), 210 log_(log),
210 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. 211 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly.
211 parsing_module_(false), 212 parsing_module_(false),
212 stack_limit_(stack_limit), 213 stack_limit_(stack_limit),
213 zone_(zone), 214 zone_(zone),
214 scanner_(scanner), 215 scanner_(scanner),
215 stack_overflow_(false), 216 stack_overflow_(false),
216 allow_lazy_(false), 217 allow_lazy_(false),
217 allow_natives_(false), 218 allow_natives_(false),
218 allow_tailcalls_(false), 219 allow_tailcalls_(false),
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 kInsideValidBlock, 366 kInsideValidBlock,
366 367
367 // Tail call expressions are not allowed in the following blocks. 368 // Tail call expressions are not allowed in the following blocks.
368 kInsideTryBlock, 369 kInsideTryBlock,
369 kInsideForInOfBody, 370 kInsideForInOfBody,
370 }; 371 };
371 372
372 class FunctionState final : public ScopeState { 373 class FunctionState final : public ScopeState {
373 public: 374 public:
374 FunctionState(FunctionState** function_state_stack, 375 FunctionState(FunctionState** function_state_stack,
375 ScopeState** scope_stack, Scope* scope, FunctionKind kind, 376 ScopeState** scope_stack, Scope* scope, FunctionKind kind);
376 typename Traits::Type::Factory* factory);
377 ~FunctionState(); 377 ~FunctionState();
378 378
379 int NextMaterializedLiteralIndex() { 379 int NextMaterializedLiteralIndex() {
380 return next_materialized_literal_index_++; 380 return next_materialized_literal_index_++;
381 } 381 }
382 int materialized_literal_count() { 382 int materialized_literal_count() {
383 return next_materialized_literal_index_; 383 return next_materialized_literal_index_;
384 } 384 }
385 385
386 void SkipMaterializedLiterals(int count) { 386 void SkipMaterializedLiterals(int count) {
(...skipping 27 matching lines...) Expand all
414 typename Traits::Type::GeneratorVariable* variable) { 414 typename Traits::Type::GeneratorVariable* variable) {
415 DCHECK(variable != NULL); 415 DCHECK(variable != NULL);
416 DCHECK(is_resumable()); 416 DCHECK(is_resumable());
417 generator_object_variable_ = variable; 417 generator_object_variable_ = variable;
418 } 418 }
419 typename Traits::Type::GeneratorVariable* generator_object_variable() 419 typename Traits::Type::GeneratorVariable* generator_object_variable()
420 const { 420 const {
421 return generator_object_variable_; 421 return generator_object_variable_;
422 } 422 }
423 423
424 typename Traits::Type::Factory* factory() { return factory_; }
425
426 const ZoneList<DestructuringAssignment>& 424 const ZoneList<DestructuringAssignment>&
427 destructuring_assignments_to_rewrite() const { 425 destructuring_assignments_to_rewrite() const {
428 return destructuring_assignments_to_rewrite_; 426 return destructuring_assignments_to_rewrite_;
429 } 427 }
430 428
431 TailCallExpressionList& tail_call_expressions() { 429 TailCallExpressionList& tail_call_expressions() {
432 return tail_call_expressions_; 430 return tail_call_expressions_;
433 } 431 }
434 void AddImplicitTailCallExpression(ExpressionT expression) { 432 void AddImplicitTailCallExpression(ExpressionT expression) {
435 if (return_expr_context() == 433 if (return_expr_context() ==
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 FunctionState** function_state_stack_; 505 FunctionState** function_state_stack_;
508 FunctionState* outer_function_state_; 506 FunctionState* outer_function_state_;
509 507
510 ZoneList<DestructuringAssignment> destructuring_assignments_to_rewrite_; 508 ZoneList<DestructuringAssignment> destructuring_assignments_to_rewrite_;
511 TailCallExpressionList tail_call_expressions_; 509 TailCallExpressionList tail_call_expressions_;
512 ReturnExprContext return_expr_context_; 510 ReturnExprContext return_expr_context_;
513 ZoneList<ExpressionT> non_patterns_to_rewrite_; 511 ZoneList<ExpressionT> non_patterns_to_rewrite_;
514 512
515 ZoneList<typename ExpressionClassifier::Error> reported_errors_; 513 ZoneList<typename ExpressionClassifier::Error> reported_errors_;
516 514
517 typename Traits::Type::Factory* factory_;
518
519 // If true, the next (and immediately following) function literal is 515 // If true, the next (and immediately following) function literal is
520 // preceded by a parenthesis. 516 // preceded by a parenthesis.
521 bool next_function_is_parenthesized_; 517 bool next_function_is_parenthesized_;
522 518
523 // The value of the parents' next_function_is_parenthesized_, as it applies 519 // The value of the parents' next_function_is_parenthesized_, as it applies
524 // to this function. Filled in by constructor. 520 // to this function. Filled in by constructor.
525 bool this_function_is_parenthesized_; 521 bool this_function_is_parenthesized_;
526 522
527 friend class ParserTraits; 523 friend class ParserTraits;
528 friend class PreParserTraits; 524 friend class PreParserTraits;
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 } 828 }
833 } 829 }
834 830
835 // Determine precedence of given token. 831 // Determine precedence of given token.
836 static int Precedence(Token::Value token, bool accept_IN) { 832 static int Precedence(Token::Value token, bool accept_IN) {
837 if (token == Token::IN && !accept_IN) 833 if (token == Token::IN && !accept_IN)
838 return 0; // 0 precedence will terminate binary expression parsing 834 return 0; // 0 precedence will terminate binary expression parsing
839 return Token::Precedence(token); 835 return Token::Precedence(token);
840 } 836 }
841 837
842 typename Traits::Type::Factory* factory() { 838 typename Traits::Type::Factory* factory() { return &ast_node_factory_; }
843 return function_state_->factory();
844 }
845 839
846 LanguageMode language_mode() { return scope()->language_mode(); } 840 LanguageMode language_mode() { return scope()->language_mode(); }
847 bool is_generator() const { return function_state_->is_generator(); } 841 bool is_generator() const { return function_state_->is_generator(); }
848 bool is_async_function() const { 842 bool is_async_function() const {
849 return function_state_->is_async_function(); 843 return function_state_->is_async_function();
850 } 844 }
851 bool is_resumable() const { return function_state_->is_resumable(); } 845 bool is_resumable() const { return function_state_->is_resumable(); }
852 846
853 // Report syntax errors. 847 // Report syntax errors.
854 void ReportMessage(MessageTemplate::Template message, const char* arg = NULL, 848 void ReportMessage(MessageTemplate::Template message, const char* arg = NULL,
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 }; 1214 };
1221 1215
1222 ModuleDescriptor* module() const { return scope()->module(); } 1216 ModuleDescriptor* module() const { return scope()->module(); }
1223 Scope* scope() const { return scope_state_->scope(); } 1217 Scope* scope() const { return scope_state_->scope(); }
1224 1218
1225 ScopeState* scope_state_; // Scope stack. 1219 ScopeState* scope_state_; // Scope stack.
1226 FunctionState* function_state_; // Function state stack. 1220 FunctionState* function_state_; // Function state stack.
1227 v8::Extension* extension_; 1221 v8::Extension* extension_;
1228 FuncNameInferrer* fni_; 1222 FuncNameInferrer* fni_;
1229 AstValueFactory* ast_value_factory_; // Not owned. 1223 AstValueFactory* ast_value_factory_; // Not owned.
1224 typename Traits::Type::Factory ast_node_factory_;
1230 ParserRecorder* log_; 1225 ParserRecorder* log_;
1231 Mode mode_; 1226 Mode mode_;
1232 bool parsing_module_; 1227 bool parsing_module_;
1233 uintptr_t stack_limit_; 1228 uintptr_t stack_limit_;
1234 1229
1235 private: 1230 private:
1236 Zone* zone_; 1231 Zone* zone_;
1237 1232
1238 Scanner* scanner_; 1233 Scanner* scanner_;
1239 bool stack_overflow_; 1234 bool stack_overflow_;
1240 1235
1241 bool allow_lazy_; 1236 bool allow_lazy_;
1242 bool allow_natives_; 1237 bool allow_natives_;
1243 bool allow_tailcalls_; 1238 bool allow_tailcalls_;
1244 bool allow_harmony_restrictive_declarations_; 1239 bool allow_harmony_restrictive_declarations_;
1245 bool allow_harmony_do_expressions_; 1240 bool allow_harmony_do_expressions_;
1246 bool allow_harmony_for_in_; 1241 bool allow_harmony_for_in_;
1247 bool allow_harmony_function_sent_; 1242 bool allow_harmony_function_sent_;
1248 bool allow_harmony_async_await_; 1243 bool allow_harmony_async_await_;
1249 bool allow_harmony_restrictive_generators_; 1244 bool allow_harmony_restrictive_generators_;
1250 bool allow_harmony_trailing_commas_; 1245 bool allow_harmony_trailing_commas_;
1251 }; 1246 };
1252 1247
1253 template <class Traits> 1248 template <class Traits>
1254 ParserBase<Traits>::FunctionState::FunctionState( 1249 ParserBase<Traits>::FunctionState::FunctionState(
1255 FunctionState** function_state_stack, ScopeState** scope_stack, 1250 FunctionState** function_state_stack, ScopeState** scope_stack,
1256 Scope* scope, FunctionKind kind, typename Traits::Type::Factory* factory) 1251 Scope* scope, FunctionKind kind)
1257 : ScopeState(scope_stack, scope), 1252 : ScopeState(scope_stack, scope),
1258 next_materialized_literal_index_(0), 1253 next_materialized_literal_index_(0),
1259 expected_property_count_(0), 1254 expected_property_count_(0),
1260 this_location_(Scanner::Location::invalid()), 1255 this_location_(Scanner::Location::invalid()),
1261 return_location_(Scanner::Location::invalid()), 1256 return_location_(Scanner::Location::invalid()),
1262 super_location_(Scanner::Location::invalid()), 1257 super_location_(Scanner::Location::invalid()),
1263 kind_(kind), 1258 kind_(kind),
1264 generator_object_variable_(NULL), 1259 generator_object_variable_(NULL),
1265 function_state_stack_(function_state_stack), 1260 function_state_stack_(function_state_stack),
1266 outer_function_state_(*function_state_stack), 1261 outer_function_state_(*function_state_stack),
1267 destructuring_assignments_to_rewrite_(16, scope->zone()), 1262 destructuring_assignments_to_rewrite_(16, scope->zone()),
1268 tail_call_expressions_(scope->zone()), 1263 tail_call_expressions_(scope->zone()),
1269 return_expr_context_(ReturnExprContext::kInsideValidBlock), 1264 return_expr_context_(ReturnExprContext::kInsideValidBlock),
1270 non_patterns_to_rewrite_(0, scope->zone()), 1265 non_patterns_to_rewrite_(0, scope->zone()),
1271 reported_errors_(16, scope->zone()), 1266 reported_errors_(16, scope->zone()),
1272 factory_(factory),
1273 next_function_is_parenthesized_(false), 1267 next_function_is_parenthesized_(false),
1274 this_function_is_parenthesized_(false) { 1268 this_function_is_parenthesized_(false) {
1275 *function_state_stack = this; 1269 *function_state_stack = this;
1276 if (outer_function_state_) { 1270 if (outer_function_state_) {
1277 this_function_is_parenthesized_ = 1271 this_function_is_parenthesized_ =
1278 outer_function_state_->next_function_is_parenthesized_; 1272 outer_function_state_->next_function_is_parenthesized_;
1279 outer_function_state_->next_function_is_parenthesized_ = false; 1273 outer_function_state_->next_function_is_parenthesized_ = false;
1280 } 1274 }
1281 } 1275 }
1282 1276
(...skipping 2095 matching lines...) Expand 10 before | Expand all | Expand 10 after
3378 } 3372 }
3379 3373
3380 typename Traits::Type::StatementList body; 3374 typename Traits::Type::StatementList body;
3381 int num_parameters = formal_parameters.scope->num_parameters(); 3375 int num_parameters = formal_parameters.scope->num_parameters();
3382 int materialized_literal_count = -1; 3376 int materialized_literal_count = -1;
3383 int expected_property_count = -1; 3377 int expected_property_count = -1;
3384 Scanner::Location super_loc; 3378 Scanner::Location super_loc;
3385 3379
3386 FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction; 3380 FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction;
3387 { 3381 {
3388 typename Traits::Type::Factory function_factory(ast_value_factory());
3389 FunctionState function_state(&function_state_, &scope_state_, 3382 FunctionState function_state(&function_state_, &scope_state_,
3390 formal_parameters.scope, arrow_kind, 3383 formal_parameters.scope, arrow_kind);
3391 &function_factory);
3392 3384
3393 function_state.SkipMaterializedLiterals( 3385 function_state.SkipMaterializedLiterals(
3394 formal_parameters.materialized_literals_count); 3386 formal_parameters.materialized_literals_count);
3395 3387
3396 this->ReindexLiterals(formal_parameters); 3388 this->ReindexLiterals(formal_parameters);
3397 3389
3398 Expect(Token::ARROW, CHECK_OK); 3390 Expect(Token::ARROW, CHECK_OK);
3399 3391
3400 if (peek() == Token::LBRACE) { 3392 if (peek() == Token::LBRACE) {
3401 // Multiple statement body 3393 // Multiple statement body
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
3697 has_seen_constructor_ = true; 3689 has_seen_constructor_ = true;
3698 return; 3690 return;
3699 } 3691 }
3700 } 3692 }
3701 3693
3702 3694
3703 } // namespace internal 3695 } // namespace internal
3704 } // namespace v8 3696 } // namespace v8
3705 3697
3706 #endif // V8_PARSING_PARSER_BASE_H 3698 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698