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

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: review feedback (embedded AstProperties and AstConstructionVisitor) 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
« src/ast.h ('K') | « src/objects-inl.h ('k') | src/parser.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 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 AstNodeFactory<AstConstructionVisitor>* factory() { return &factory_; }
515
516 private:
517 // Used to assign an index to each literal that needs materialization in
518 // the function. Includes regexp literals, and boilerplate for object and
519 // array literals.
520 int next_materialized_literal_index_;
521
522 // Used to assign a per-function index to try and catch handlers.
523 int next_handler_index_;
524
525 // Properties count estimation.
526 int expected_property_count_;
527
528 // Keeps track of assignments to properties of this. Used for
529 // optimizing constructors.
530 bool only_simple_this_property_assignments_;
531 Handle<FixedArray> this_property_assignments_;
532
533 Parser* parser_;
534 FunctionState* outer_function_state_;
535 Scope* outer_scope_;
536 int saved_ast_node_id_;
537 AstNodeFactory<AstConstructionVisitor> factory_;
538 };
539
540
541
481 542
482 FunctionLiteral* ParseLazy(CompilationInfo* info, 543 FunctionLiteral* ParseLazy(CompilationInfo* info,
483 UC16CharacterStream* source, 544 UC16CharacterStream* source,
484 ZoneScope* zone_scope); 545 ZoneScope* zone_scope);
485 546
486 Isolate* isolate() { return isolate_; } 547 Isolate* isolate() { return isolate_; }
487 Zone* zone() { return isolate_->zone(); } 548 Zone* zone() { return isolate_->zone(); }
488 549
489 // Called by ParseProgram after setting up the scanner. 550 // Called by ParseProgram after setting up the scanner.
490 FunctionLiteral* DoParseProgram(CompilationInfo* info, 551 FunctionLiteral* DoParseProgram(CompilationInfo* info,
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 return isolate_->factory()->NewStringFromTwoByte( 705 return isolate_->factory()->NewStringFromTwoByte(
645 scanner().next_literal_uc16_string(), tenured); 706 scanner().next_literal_uc16_string(), tenured);
646 } 707 }
647 } 708 }
648 709
649 Handle<String> GetSymbol(bool* ok); 710 Handle<String> GetSymbol(bool* ok);
650 711
651 // Get odd-ball literals. 712 // Get odd-ball literals.
652 Literal* GetLiteralUndefined(); 713 Literal* GetLiteralUndefined();
653 Literal* GetLiteralTheHole(); 714 Literal* GetLiteralTheHole();
654 Literal* GetLiteralNumber(double value);
655 715
656 Handle<String> ParseIdentifier(bool* ok); 716 Handle<String> ParseIdentifier(bool* ok);
657 Handle<String> ParseIdentifierOrStrictReservedWord( 717 Handle<String> ParseIdentifierOrStrictReservedWord(
658 bool* is_strict_reserved, bool* ok); 718 bool* is_strict_reserved, bool* ok);
659 Handle<String> ParseIdentifierName(bool* ok); 719 Handle<String> ParseIdentifierName(bool* ok);
660 Handle<String> ParseIdentifierNameOrGetOrSet(bool* is_get, 720 Handle<String> ParseIdentifierNameOrGetOrSet(bool* is_get,
661 bool* is_set, 721 bool* is_set,
662 bool* ok); 722 bool* ok);
663 723
664 // Determine if the expression is a variable proxy and mark it as being used 724 // Determine if the expression is a variable proxy and mark it as being used
(...skipping 27 matching lines...) Expand all
692 bool* ok); 752 bool* ok);
693 753
694 bool TargetStackContainsLabel(Handle<String> label); 754 bool TargetStackContainsLabel(Handle<String> label);
695 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok); 755 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok);
696 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok); 756 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok);
697 757
698 void RegisterTargetUse(Label* target, Target* stop); 758 void RegisterTargetUse(Label* target, Target* stop);
699 759
700 // Factory methods. 760 // Factory methods.
701 761
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); 762 Scope* NewScope(Scope* parent, ScopeType type);
709 763
710 Handle<String> LookupSymbol(int symbol_id); 764 Handle<String> LookupSymbol(int symbol_id);
711 765
712 Handle<String> LookupCachedSymbol(int symbol_id); 766 Handle<String> LookupCachedSymbol(int symbol_id);
713 767
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. 768 // Generate AST node that throw a ReferenceError with the given type.
728 Expression* NewThrowReferenceError(Handle<String> type); 769 Expression* NewThrowReferenceError(Handle<String> type);
729 770
730 // Generate AST node that throw a SyntaxError with the given 771 // Generate AST node that throw a SyntaxError with the given
731 // type. The first argument may be null (in the handle sense) in 772 // type. The first argument may be null (in the handle sense) in
732 // which case no arguments are passed to the constructor. 773 // which case no arguments are passed to the constructor.
733 Expression* NewThrowSyntaxError(Handle<String> type, Handle<Object> first); 774 Expression* NewThrowSyntaxError(Handle<String> type, Handle<Object> first);
734 775
735 // Generate AST node that throw a TypeError with the given 776 // Generate AST node that throw a TypeError with the given
736 // type. Both arguments must be non-null (in the handle sense). 777 // type. Both arguments must be non-null (in the handle sense).
737 Expression* NewThrowTypeError(Handle<String> type, 778 Expression* NewThrowTypeError(Handle<String> type,
738 Handle<Object> first, 779 Handle<Object> first,
739 Handle<Object> second); 780 Handle<Object> second);
740 781
741 // Generic AST generator for throwing errors from compiled code. 782 // Generic AST generator for throwing errors from compiled code.
742 Expression* NewThrowError(Handle<String> constructor, 783 Expression* NewThrowError(Handle<String> constructor,
743 Handle<String> type, 784 Handle<String> type,
744 Vector< Handle<Object> > arguments); 785 Vector< Handle<Object> > arguments);
745 786
746 preparser::PreParser::PreParseResult LazyParseFunctionLiteral( 787 preparser::PreParser::PreParseResult LazyParseFunctionLiteral(
747 SingletonLogger* logger); 788 SingletonLogger* logger);
748 789
790 AstNodeFactory<AstConstructionVisitor>* factory() {
791 return current_function_state_->factory();
792 }
793
749 Isolate* isolate_; 794 Isolate* isolate_;
750 ZoneList<Handle<String> > symbol_cache_; 795 ZoneList<Handle<String> > symbol_cache_;
751 796
752 Handle<Script> script_; 797 Handle<Script> script_;
753 Scanner scanner_; 798 Scanner scanner_;
754 preparser::PreParser* reusable_preparser_; 799 preparser::PreParser* reusable_preparser_;
755 Scope* top_scope_; 800 Scope* top_scope_;
756 FunctionState* current_function_state_; 801 FunctionState* current_function_state_;
757 Target* target_stack_; // for break, continue statements 802 Target* target_stack_; // for break, continue statements
758 v8::Extension* extension_; 803 v8::Extension* extension_;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 private: 845 private:
801 static const int kTypeSlot = 0; 846 static const int kTypeSlot = 0;
802 static const int kElementsSlot = 1; 847 static const int kElementsSlot = 1;
803 848
804 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 849 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
805 }; 850 };
806 851
807 } } // namespace v8::internal 852 } } // namespace v8::internal
808 853
809 #endif // V8_PARSER_H_ 854 #endif // V8_PARSER_H_
OLDNEW
« src/ast.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