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

Side by Side Diff: src/parser.h

Issue 527763002: Refactor Parser to make it usable on a background thread. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: whitespace Created 6 years, 3 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
« no previous file with comments | « no previous file | 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 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_PARSER_H_ 5 #ifndef V8_PARSER_H_
6 #define V8_PARSER_H_ 6 #define V8_PARSER_H_
7 7
8 #include "src/allocation.h" 8 #include "src/allocation.h"
9 #include "src/ast.h" 9 #include "src/ast.h"
10 #include "src/compiler.h" // For CachedDataMode 10 #include "src/compiler.h" // For CachedDataMode
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 V8_INLINE void CheckConflictingVarDeclarations(v8::internal::Scope* scope, 590 V8_INLINE void CheckConflictingVarDeclarations(v8::internal::Scope* scope,
591 bool* ok); 591 bool* ok);
592 592
593 private: 593 private:
594 Parser* parser_; 594 Parser* parser_;
595 }; 595 };
596 596
597 597
598 class Parser : public ParserBase<ParserTraits> { 598 class Parser : public ParserBase<ParserTraits> {
599 public: 599 public:
600 explicit Parser(CompilationInfo* info); 600 // Note that the hash seed in ParseInfo must be the hash seed from the
601 // Isolate's heap, otherwise the heap will be in an inconsistent state once
602 // the strings created by the Parser are internalized.
603 struct ParseInfo {
604 uintptr_t stack_limit;
605 uint32_t hash_seed;
606 UnicodeCache* unicode_cache;
607 };
608
609 Parser(CompilationInfo* info, ParseInfo* parse_info);
601 ~Parser() { 610 ~Parser() {
602 delete reusable_preparser_; 611 delete reusable_preparser_;
603 reusable_preparser_ = NULL; 612 reusable_preparser_ = NULL;
604 delete cached_parse_data_; 613 delete cached_parse_data_;
605 cached_parse_data_ = NULL; 614 cached_parse_data_ = NULL;
606 } 615 }
607 616
608 // Parses the source code represented by the compilation info and sets its 617 // Parses the source code represented by the compilation info and sets its
609 // function literal. Returns false (and deallocates any allocated AST 618 // function literal. Returns false (and deallocates any allocated AST
610 // nodes) if parsing failed. 619 // nodes) if parsing failed.
611 static bool Parse(CompilationInfo* info, 620 static bool Parse(CompilationInfo* info,
612 bool allow_lazy = false) { 621 bool allow_lazy = false) {
613 Parser parser(info); 622 ParseInfo parse_info = {info->isolate()->stack_guard()->real_climit(),
623 info->isolate()->heap()->HashSeed(),
624 info->isolate()->unicode_cache()};
625 Parser parser(info, &parse_info);
614 parser.set_allow_lazy(allow_lazy); 626 parser.set_allow_lazy(allow_lazy);
615 return parser.Parse(); 627 return parser.Parse();
616 } 628 }
617 bool Parse(); 629 bool Parse();
618 630
619 private: 631 private:
620 friend class ParserTraits; 632 friend class ParserTraits;
621 633
622 // Limit the allowed number of local variables in a function. The hard limit 634 // Limit the allowed number of local variables in a function. The hard limit
623 // is that offsets computed by FullCodeGenerator::StackOperand and similar 635 // is that offsets computed by FullCodeGenerator::StackOperand and similar
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 802
791 // Consumes the ending }. 803 // Consumes the ending }.
792 ZoneList<Statement*>* ParseEagerFunctionBody( 804 ZoneList<Statement*>* ParseEagerFunctionBody(
793 const AstRawString* function_name, int pos, Variable* fvar, 805 const AstRawString* function_name, int pos, Variable* fvar,
794 Token::Value fvar_init_op, bool is_generator, bool* ok); 806 Token::Value fvar_init_op, bool is_generator, bool* ok);
795 807
796 void HandleSourceURLComments(); 808 void HandleSourceURLComments();
797 809
798 void ThrowPendingError(); 810 void ThrowPendingError();
799 811
800 void InternalizeUseCounts(); 812 // Handle errors detected during parsing, move statistics to Isolate,
813 // internalize strings (move them to the heap).
814 void Internalize();
801 815
802 Isolate* isolate_; 816 Isolate* isolate_;
803 817
804 Handle<Script> script_; 818 Handle<Script> script_;
805 Scanner scanner_; 819 Scanner scanner_;
806 PreParser* reusable_preparser_; 820 PreParser* reusable_preparser_;
807 Scope* original_scope_; // for ES5 function declarations in sloppy eval 821 Scope* original_scope_; // for ES5 function declarations in sloppy eval
808 Target* target_stack_; // for break, continue statements 822 Target* target_stack_; // for break, continue statements
809 ParseData* cached_parse_data_; 823 ParseData* cached_parse_data_;
810 AstValueFactory* ast_value_factory_; 824 AstValueFactory* ast_value_factory_;
811 825
812 CompilationInfo* info_; 826 CompilationInfo* info_;
813 827
814 // Pending errors. 828 // Pending errors.
815 bool has_pending_error_; 829 bool has_pending_error_;
816 Scanner::Location pending_error_location_; 830 Scanner::Location pending_error_location_;
817 const char* pending_error_message_; 831 const char* pending_error_message_;
818 const AstRawString* pending_error_arg_; 832 const AstRawString* pending_error_arg_;
819 const char* pending_error_char_arg_; 833 const char* pending_error_char_arg_;
820 bool pending_error_is_reference_error_; 834 bool pending_error_is_reference_error_;
821 835
836 // Other information which will be stored in Parser and moved to Isolate after
837 // parsing.
822 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; 838 int use_counts_[v8::Isolate::kUseCounterFeatureCount];
839 int total_preparse_skipped_;
840 HistogramTimer* pre_parse_timer_;
823 }; 841 };
824 842
825 843
826 bool ParserTraits::IsFutureStrictReserved( 844 bool ParserTraits::IsFutureStrictReserved(
827 const AstRawString* identifier) const { 845 const AstRawString* identifier) const {
828 return identifier->IsOneByteEqualTo("yield") || 846 return identifier->IsOneByteEqualTo("yield") ||
829 parser_->scanner()->IdentifierIsFutureStrictReserved(identifier); 847 parser_->scanner()->IdentifierIsFutureStrictReserved(identifier);
830 } 848 }
831 849
832 850
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 private: 909 private:
892 static const int kLiteralTypeSlot = 0; 910 static const int kLiteralTypeSlot = 0;
893 static const int kElementsSlot = 1; 911 static const int kElementsSlot = 1;
894 912
895 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 913 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
896 }; 914 };
897 915
898 } } // namespace v8::internal 916 } } // namespace v8::internal
899 917
900 #endif // V8_PARSER_H_ 918 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « no previous file | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698