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

Side by Side Diff: src/parser.h

Issue 12646003: Add parser support for generators. (Closed) Base URL: git://github.com/v8/v8.git@bleeding_edge
Patch Set: Fix bad initialization list in last preparser commit Created 7 years, 8 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 kHasInitializers, 472 kHasInitializers,
473 kHasNoInitializers 473 kHasNoInitializers
474 }; 474 };
475 475
476 class BlockState; 476 class BlockState;
477 477
478 class FunctionState BASE_EMBEDDED { 478 class FunctionState BASE_EMBEDDED {
479 public: 479 public:
480 FunctionState(Parser* parser, 480 FunctionState(Parser* parser,
481 Scope* scope, 481 Scope* scope,
482 bool is_generator,
482 Isolate* isolate); 483 Isolate* isolate);
483 ~FunctionState(); 484 ~FunctionState();
484 485
485 int NextMaterializedLiteralIndex() { 486 int NextMaterializedLiteralIndex() {
486 return next_materialized_literal_index_++; 487 return next_materialized_literal_index_++;
487 } 488 }
488 int materialized_literal_count() { 489 int materialized_literal_count() {
489 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize; 490 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize;
490 } 491 }
491 492
(...skipping 10 matching lines...) Expand all
502 bool only_simple_this_property_assignments() { 503 bool only_simple_this_property_assignments() {
503 return only_simple_this_property_assignments_; 504 return only_simple_this_property_assignments_;
504 } 505 }
505 Handle<FixedArray> this_property_assignments() { 506 Handle<FixedArray> this_property_assignments() {
506 return this_property_assignments_; 507 return this_property_assignments_;
507 } 508 }
508 509
509 void AddProperty() { expected_property_count_++; } 510 void AddProperty() { expected_property_count_++; }
510 int expected_property_count() { return expected_property_count_; } 511 int expected_property_count() { return expected_property_count_; }
511 512
513 bool is_generator() const { return is_generator_; }
514
512 AstNodeFactory<AstConstructionVisitor>* factory() { return &factory_; } 515 AstNodeFactory<AstConstructionVisitor>* factory() { return &factory_; }
513 516
514 private: 517 private:
515 // Used to assign an index to each literal that needs materialization in 518 // Used to assign an index to each literal that needs materialization in
516 // the function. Includes regexp literals, and boilerplate for object and 519 // the function. Includes regexp literals, and boilerplate for object and
517 // array literals. 520 // array literals.
518 int next_materialized_literal_index_; 521 int next_materialized_literal_index_;
519 522
520 // Used to assign a per-function index to try and catch handlers. 523 // Used to assign a per-function index to try and catch handlers.
521 int next_handler_index_; 524 int next_handler_index_;
522 525
523 // Properties count estimation. 526 // Properties count estimation.
524 int expected_property_count_; 527 int expected_property_count_;
525 528
529 // Indicates that this function is a generator.
530 bool is_generator_;
531
526 // Keeps track of assignments to properties of this. Used for 532 // Keeps track of assignments to properties of this. Used for
527 // optimizing constructors. 533 // optimizing constructors.
528 bool only_simple_this_property_assignments_; 534 bool only_simple_this_property_assignments_;
529 Handle<FixedArray> this_property_assignments_; 535 Handle<FixedArray> this_property_assignments_;
530 536
531 Parser* parser_; 537 Parser* parser_;
532 FunctionState* outer_function_state_; 538 FunctionState* outer_function_state_;
533 Scope* outer_scope_; 539 Scope* outer_scope_;
534 int saved_ast_node_id_; 540 int saved_ast_node_id_;
535 AstNodeFactory<AstConstructionVisitor> factory_; 541 AstNodeFactory<AstConstructionVisitor> factory_;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 Statement* ParseThrowStatement(bool* ok); 635 Statement* ParseThrowStatement(bool* ok);
630 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value); 636 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value);
631 TryStatement* ParseTryStatement(bool* ok); 637 TryStatement* ParseTryStatement(bool* ok);
632 DebuggerStatement* ParseDebuggerStatement(bool* ok); 638 DebuggerStatement* ParseDebuggerStatement(bool* ok);
633 639
634 // Support for hamony block scoped bindings. 640 // Support for hamony block scoped bindings.
635 Block* ParseScopedBlock(ZoneStringList* labels, bool* ok); 641 Block* ParseScopedBlock(ZoneStringList* labels, bool* ok);
636 642
637 Expression* ParseExpression(bool accept_IN, bool* ok); 643 Expression* ParseExpression(bool accept_IN, bool* ok);
638 Expression* ParseAssignmentExpression(bool accept_IN, bool* ok); 644 Expression* ParseAssignmentExpression(bool accept_IN, bool* ok);
645 Expression* ParseYieldExpression(bool* ok);
639 Expression* ParseConditionalExpression(bool accept_IN, bool* ok); 646 Expression* ParseConditionalExpression(bool accept_IN, bool* ok);
640 Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok); 647 Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok);
641 Expression* ParseUnaryExpression(bool* ok); 648 Expression* ParseUnaryExpression(bool* ok);
642 Expression* ParsePostfixExpression(bool* ok); 649 Expression* ParsePostfixExpression(bool* ok);
643 Expression* ParseLeftHandSideExpression(bool* ok); 650 Expression* ParseLeftHandSideExpression(bool* ok);
644 Expression* ParseNewExpression(bool* ok); 651 Expression* ParseNewExpression(bool* ok);
645 Expression* ParseMemberExpression(bool* ok); 652 Expression* ParseMemberExpression(bool* ok);
646 Expression* ParseNewPrefix(PositionStack* stack, bool* ok); 653 Expression* ParseNewPrefix(PositionStack* stack, bool* ok);
647 Expression* ParseMemberWithNewPrefixesExpression(PositionStack* stack, 654 Expression* ParseMemberWithNewPrefixesExpression(PositionStack* stack,
648 bool* ok); 655 bool* ok);
(...skipping 23 matching lines...) Expand all
672 // If the expression is a literal, return the literal value; 679 // If the expression is a literal, return the literal value;
673 // if the expression is a materialized literal and is simple return a 680 // if the expression is a materialized literal and is simple return a
674 // compile time value as encoded by CompileTimeValue::GetValue(). 681 // compile time value as encoded by CompileTimeValue::GetValue().
675 // Otherwise, return undefined literal as the placeholder 682 // Otherwise, return undefined literal as the placeholder
676 // in the object literal boilerplate. 683 // in the object literal boilerplate.
677 Handle<Object> GetBoilerplateValue(Expression* expression); 684 Handle<Object> GetBoilerplateValue(Expression* expression);
678 685
679 ZoneList<Expression*>* ParseArguments(bool* ok); 686 ZoneList<Expression*>* ParseArguments(bool* ok);
680 FunctionLiteral* ParseFunctionLiteral(Handle<String> var_name, 687 FunctionLiteral* ParseFunctionLiteral(Handle<String> var_name,
681 bool name_is_reserved, 688 bool name_is_reserved,
689 bool is_generator,
682 int function_token_position, 690 int function_token_position,
683 FunctionLiteral::Type type, 691 FunctionLiteral::Type type,
684 bool* ok); 692 bool* ok);
685 693
686 694
687 // Magical syntax support. 695 // Magical syntax support.
688 Expression* ParseV8Intrinsic(bool* ok); 696 Expression* ParseV8Intrinsic(bool* ok);
689 697
690 INLINE(Token::Value peek()) { 698 INLINE(Token::Value peek()) {
691 if (stack_overflow_) return Token::ILLEGAL; 699 if (stack_overflow_) return Token::ILLEGAL;
692 return scanner().peek(); 700 return scanner().peek();
693 } 701 }
694 702
695 INLINE(Token::Value Next()) { 703 INLINE(Token::Value Next()) {
696 // BUG 1215673: Find a thread safe way to set a stack limit in 704 // BUG 1215673: Find a thread safe way to set a stack limit in
697 // pre-parse mode. Otherwise, we cannot safely pre-parse from other 705 // pre-parse mode. Otherwise, we cannot safely pre-parse from other
698 // threads. 706 // threads.
699 if (stack_overflow_) { 707 if (stack_overflow_) {
700 return Token::ILLEGAL; 708 return Token::ILLEGAL;
701 } 709 }
702 if (StackLimitCheck(isolate()).HasOverflowed()) { 710 if (StackLimitCheck(isolate()).HasOverflowed()) {
703 // Any further calls to Next or peek will return the illegal token. 711 // Any further calls to Next or peek will return the illegal token.
704 // The current call must return the next token, which might already 712 // The current call must return the next token, which might already
705 // have been peek'ed. 713 // have been peek'ed.
706 stack_overflow_ = true; 714 stack_overflow_ = true;
707 } 715 }
708 return scanner().Next(); 716 return scanner().Next();
709 } 717 }
710 718
719 bool is_generator() const { return current_function_state_->is_generator(); }
720
711 bool peek_any_identifier(); 721 bool peek_any_identifier();
712 722
713 INLINE(void Consume(Token::Value token)); 723 INLINE(void Consume(Token::Value token));
714 void Expect(Token::Value token, bool* ok); 724 void Expect(Token::Value token, bool* ok);
715 bool Check(Token::Value token); 725 bool Check(Token::Value token);
716 void ExpectSemicolon(bool* ok); 726 void ExpectSemicolon(bool* ok);
717 void ExpectContextualKeyword(const char* keyword, bool* ok); 727 void ExpectContextualKeyword(const char* keyword, bool* ok);
718 728
719 Handle<String> LiteralString(PretenureFlag tenured) { 729 Handle<String> LiteralString(PretenureFlag tenured) {
720 if (scanner().is_literal_ascii()) { 730 if (scanner().is_literal_ascii()) {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 private: 887 private:
878 static const int kTypeSlot = 0; 888 static const int kTypeSlot = 0;
879 static const int kElementsSlot = 1; 889 static const int kElementsSlot = 1;
880 890
881 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 891 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
882 }; 892 };
883 893
884 } } // namespace v8::internal 894 } } // namespace v8::internal
885 895
886 #endif // V8_PARSER_H_ 896 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | src/parser.cc » ('j') | test/mjsunit/harmony/generators-parsing.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698