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

Side by Side Diff: src/parser.h

Issue 9221011: Collect AstNode type information (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: removed VariableProxy::ast_properties_ Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 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
11 // with the distribution. 11 // with the distribution.
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 // Forward declaration. 428 // Forward declaration.
429 class SingletonLogger; 429 class SingletonLogger;
430 430
431 class Parser { 431 class Parser {
432 public: 432 public:
433 Parser(Handle<Script> script, 433 Parser(Handle<Script> script,
434 int parsing_flags, // Combination of ParsingFlags 434 int parsing_flags, // Combination of ParsingFlags
435 v8::Extension* extension, 435 v8::Extension* extension,
436 ScriptDataImpl* pre_data); 436 ScriptDataImpl* pre_data);
437 virtual ~Parser() { 437 virtual ~Parser() {
438 if (reusable_preparser_ != NULL) { 438 delete reusable_preparser_;
439 delete reusable_preparser_; 439 reusable_preparser_ = NULL;
440 }
441 } 440 }
442 441
443 // Returns NULL if parsing failed. 442 // Returns NULL if parsing failed.
444 FunctionLiteral* ParseProgram(CompilationInfo* info); 443 FunctionLiteral* ParseProgram(CompilationInfo* info);
445 FunctionLiteral* ParseLazy(CompilationInfo* info); 444 FunctionLiteral* ParseLazy(CompilationInfo* info);
446 445
447 void ReportMessageAt(Scanner::Location loc, 446 void ReportMessageAt(Scanner::Location loc,
448 const char* message, 447 const char* message,
449 Vector<const char*> args); 448 Vector<const char*> args);
450 void ReportMessageAt(Scanner::Location loc, 449 void ReportMessageAt(Scanner::Location loc,
(...skipping 19 matching lines...) Expand all
470 kForStatement 469 kForStatement
471 }; 470 };
472 471
473 // If a list of variable declarations includes any initializers. 472 // If a list of variable declarations includes any initializers.
474 enum VariableDeclarationProperties { 473 enum VariableDeclarationProperties {
475 kHasInitializers, 474 kHasInitializers,
476 kHasNoInitializers 475 kHasNoInitializers
477 }; 476 };
478 477
479 class BlockState; 478 class BlockState;
480 class FunctionState; 479
480 class FunctionState BASE_EMBEDDED {
481 public:
482 FunctionState(Parser* parser,
483 Scope* scope,
484 Isolate* isolate);
485 ~FunctionState();
486
487 int NextMaterializedLiteralIndex() {
488 return next_materialized_literal_index_++;
489 }
490 int materialized_literal_count() {
491 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize;
492 }
493
494 int NextHandlerIndex() { return next_handler_index_++; }
495 int handler_count() { return next_handler_index_; }
496
497 void SetThisPropertyAssignmentInfo(
498 bool only_simple_this_property_assignments,
499 Handle<FixedArray> this_property_assignments) {
500 only_simple_this_property_assignments_ =
501 only_simple_this_property_assignments;
502 this_property_assignments_ = this_property_assignments;
503 }
504 bool only_simple_this_property_assignments() {
505 return only_simple_this_property_assignments_;
506 }
507 Handle<FixedArray> this_property_assignments() {
508 return this_property_assignments_;
509 }
510
511 void AddProperty() { expected_property_count_++; }
512 int expected_property_count() { return expected_property_count_; }
513
514 private:
515 // Used to assign an index to each literal that needs materialization in
516 // the function. Includes regexp literals, and boilerplate for object and
517 // array literals.
518 int next_materialized_literal_index_;
519
520 // Used to assign a per-function index to try and catch handlers.
521 int next_handler_index_;
522
523 // Properties count estimation.
524 int expected_property_count_;
525
526 // Keeps track of assignments to properties of this. Used for
527 // optimizing constructors.
528 bool only_simple_this_property_assignments_;
529 Handle<FixedArray> this_property_assignments_;
530
531 Parser* parser_;
532 FunctionState* outer_function_state_;
533 Scope* outer_scope_;
534 unsigned saved_ast_node_id_;
535 AstConstructionVisitor visitor_;
536 AstConstructionVisitor* saved_visitor_;
537 };
538
539
540
481 541
482 FunctionLiteral* ParseLazy(CompilationInfo* info, 542 FunctionLiteral* ParseLazy(CompilationInfo* info,
483 UC16CharacterStream* source, 543 UC16CharacterStream* source,
484 ZoneScope* zone_scope); 544 ZoneScope* zone_scope);
485 545
486 Isolate* isolate() { return isolate_; } 546 Isolate* isolate() { return isolate_; }
487 Zone* zone() { return isolate_->zone(); } 547 Zone* zone() { return isolate_->zone(); }
488 548
489 // Called by ParseProgram after setting up the scanner. 549 // Called by ParseProgram after setting up the scanner.
490 FunctionLiteral* DoParseProgram(CompilationInfo* info, 550 FunctionLiteral* DoParseProgram(CompilationInfo* info,
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 return isolate_->factory()->NewStringFromTwoByte( 704 return isolate_->factory()->NewStringFromTwoByte(
645 scanner().next_literal_uc16_string(), tenured); 705 scanner().next_literal_uc16_string(), tenured);
646 } 706 }
647 } 707 }
648 708
649 Handle<String> GetSymbol(bool* ok); 709 Handle<String> GetSymbol(bool* ok);
650 710
651 // Get odd-ball literals. 711 // Get odd-ball literals.
652 Literal* GetLiteralUndefined(); 712 Literal* GetLiteralUndefined();
653 Literal* GetLiteralTheHole(); 713 Literal* GetLiteralTheHole();
654 Literal* GetLiteralNumber(double value);
655 714
656 Handle<String> ParseIdentifier(bool* ok); 715 Handle<String> ParseIdentifier(bool* ok);
657 Handle<String> ParseIdentifierOrStrictReservedWord( 716 Handle<String> ParseIdentifierOrStrictReservedWord(
658 bool* is_strict_reserved, bool* ok); 717 bool* is_strict_reserved, bool* ok);
659 Handle<String> ParseIdentifierName(bool* ok); 718 Handle<String> ParseIdentifierName(bool* ok);
660 Handle<String> ParseIdentifierNameOrGetOrSet(bool* is_get, 719 Handle<String> ParseIdentifierNameOrGetOrSet(bool* is_get,
661 bool* is_set, 720 bool* is_set,
662 bool* ok); 721 bool* ok);
663 722
664 // Determine if the expression is a variable proxy and mark it as being used 723 // Determine if the expression is a variable proxy and mark it as being used
(...skipping 27 matching lines...) Expand all
692 bool* ok); 751 bool* ok);
693 752
694 bool TargetStackContainsLabel(Handle<String> label); 753 bool TargetStackContainsLabel(Handle<String> label);
695 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok); 754 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok);
696 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok); 755 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok);
697 756
698 void RegisterTargetUse(Label* target, Target* stop); 757 void RegisterTargetUse(Label* target, Target* stop);
699 758
700 // Factory methods. 759 // Factory methods.
701 760
702 Statement* EmptyStatement() {
703 static v8::internal::EmptyStatement* empty =
704 ::new v8::internal::EmptyStatement();
705 return empty;
706 }
707
708 Scope* NewScope(Scope* parent, ScopeType type); 761 Scope* NewScope(Scope* parent, ScopeType type);
709 762
710 Handle<String> LookupSymbol(int symbol_id); 763 Handle<String> LookupSymbol(int symbol_id);
711 764
712 Handle<String> LookupCachedSymbol(int symbol_id); 765 Handle<String> LookupCachedSymbol(int symbol_id);
713 766
714 Expression* NewCall(Expression* expression,
715 ZoneList<Expression*>* arguments,
716 int pos) {
717 return new(zone()) Call(isolate(), expression, arguments, pos);
718 }
719
720 inline Literal* NewLiteral(Handle<Object> handle) {
721 return new(zone()) Literal(isolate(), handle);
722 }
723
724 // Create a number literal.
725 Literal* NewNumberLiteral(double value);
726
727 // Generate AST node that throw a ReferenceError with the given type. 767 // Generate AST node that throw a ReferenceError with the given type.
728 Expression* NewThrowReferenceError(Handle<String> type); 768 Expression* NewThrowReferenceError(Handle<String> type);
729 769
730 // Generate AST node that throw a SyntaxError with the given 770 // Generate AST node that throw a SyntaxError with the given
731 // type. The first argument may be null (in the handle sense) in 771 // type. The first argument may be null (in the handle sense) in
732 // which case no arguments are passed to the constructor. 772 // which case no arguments are passed to the constructor.
733 Expression* NewThrowSyntaxError(Handle<String> type, Handle<Object> first); 773 Expression* NewThrowSyntaxError(Handle<String> type, Handle<Object> first);
734 774
735 // Generate AST node that throw a TypeError with the given 775 // Generate AST node that throw a TypeError with the given
736 // type. Both arguments must be non-null (in the handle sense). 776 // type. Both arguments must be non-null (in the handle sense).
737 Expression* NewThrowTypeError(Handle<String> type, 777 Expression* NewThrowTypeError(Handle<String> type,
738 Handle<Object> first, 778 Handle<Object> first,
739 Handle<Object> second); 779 Handle<Object> second);
740 780
741 // Generic AST generator for throwing errors from compiled code. 781 // Generic AST generator for throwing errors from compiled code.
742 Expression* NewThrowError(Handle<String> constructor, 782 Expression* NewThrowError(Handle<String> constructor,
743 Handle<String> type, 783 Handle<String> type,
744 Vector< Handle<Object> > arguments); 784 Vector< Handle<Object> > arguments);
745 785
746 preparser::PreParser::PreParseResult LazyParseFunctionLiteral( 786 preparser::PreParser::PreParseResult LazyParseFunctionLiteral(
747 SingletonLogger* logger); 787 SingletonLogger* logger);
748 788
789 AstNodeFactory* factory() { return &ast_node_factory_; }
790
749 Isolate* isolate_; 791 Isolate* isolate_;
750 ZoneList<Handle<String> > symbol_cache_; 792 ZoneList<Handle<String> > symbol_cache_;
751 793
752 Handle<Script> script_; 794 Handle<Script> script_;
753 Scanner scanner_; 795 Scanner scanner_;
754 preparser::PreParser* reusable_preparser_; 796 preparser::PreParser* reusable_preparser_;
755 Scope* top_scope_; 797 Scope* top_scope_;
756 FunctionState* current_function_state_; 798 FunctionState* current_function_state_;
799 AstNodeFactory ast_node_factory_;
757 Target* target_stack_; // for break, continue statements 800 Target* target_stack_; // for break, continue statements
758 v8::Extension* extension_; 801 v8::Extension* extension_;
759 ScriptDataImpl* pre_data_; 802 ScriptDataImpl* pre_data_;
760 FuncNameInferrer* fni_; 803 FuncNameInferrer* fni_;
761 804
762 Mode mode_; 805 Mode mode_;
763 bool allow_natives_syntax_; 806 bool allow_natives_syntax_;
764 bool allow_lazy_; 807 bool allow_lazy_;
765 bool stack_overflow_; 808 bool stack_overflow_;
766 // If true, the next (and immediately following) function literal is 809 // If true, the next (and immediately following) function literal is
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 private: 843 private:
801 static const int kTypeSlot = 0; 844 static const int kTypeSlot = 0;
802 static const int kElementsSlot = 1; 845 static const int kElementsSlot = 1;
803 846
804 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 847 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
805 }; 848 };
806 849
807 } } // namespace v8::internal 850 } } // namespace v8::internal
808 851
809 #endif // V8_PARSER_H_ 852 #endif // V8_PARSER_H_
OLDNEW
« src/compiler.h ('K') | « src/objects-inl.h ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698