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

Side by Side Diff: src/parser.cc

Issue 9038: Create an abstraction for the string type flags so that they can be cached.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 years, 1 month 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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 return !scanner().stack_overflow(); 730 return !scanner().stack_overflow();
731 } 731 }
732 732
733 733
734 FunctionLiteral* Parser::ParseProgram(Handle<String> source, 734 FunctionLiteral* Parser::ParseProgram(Handle<String> source,
735 unibrow::CharacterStream* stream, 735 unibrow::CharacterStream* stream,
736 bool in_global_context) { 736 bool in_global_context) {
737 ZoneScope zone_scope(DONT_DELETE_ON_EXIT); 737 ZoneScope zone_scope(DONT_DELETE_ON_EXIT);
738 738
739 StatsRateScope timer(&Counters::parse); 739 StatsRateScope timer(&Counters::parse);
740 Counters::total_parse_size.Increment(source->length()); 740 StringShape shape(*source);
741 Counters::total_parse_size.Increment(source->length(shape));
741 742
742 // Initialize parser state. 743 // Initialize parser state.
743 source->TryFlatten(); 744 source->TryFlatten(shape);
744 scanner_.Init(source, stream, 0); 745 scanner_.Init(source, stream, 0);
745 ASSERT(target_stack_ == NULL); 746 ASSERT(target_stack_ == NULL);
746 747
747 // Compute the parsing mode. 748 // Compute the parsing mode.
748 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY; 749 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY;
749 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; 750 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY;
750 751
751 Scope::Type type = 752 Scope::Type type =
752 in_global_context 753 in_global_context
753 ? Scope::GLOBAL_SCOPE 754 ? Scope::GLOBAL_SCOPE
754 : Scope::EVAL_SCOPE; 755 : Scope::EVAL_SCOPE;
755 Handle<String> no_name = factory()->EmptySymbol(); 756 Handle<String> no_name = factory()->EmptySymbol();
756 757
757 FunctionLiteral* result = NULL; 758 FunctionLiteral* result = NULL;
758 { Scope* scope = factory()->NewScope(top_scope_, type, inside_with()); 759 { Scope* scope = factory()->NewScope(top_scope_, type, inside_with());
759 LexicalScope lexical_scope(this, scope); 760 LexicalScope lexical_scope(this, scope);
760 TemporaryScope temp_scope(this); 761 TemporaryScope temp_scope(this);
761 ZoneListWrapper<Statement> body(16); 762 ZoneListWrapper<Statement> body(16);
762 bool ok = true; 763 bool ok = true;
763 ParseSourceElements(&body, Token::EOS, &ok); 764 ParseSourceElements(&body, Token::EOS, &ok);
764 if (ok) { 765 if (ok) {
765 result = NEW(FunctionLiteral(no_name, top_scope_, 766 result = NEW(FunctionLiteral(no_name, top_scope_,
766 body.elements(), 767 body.elements(),
767 temp_scope.materialized_literal_count(), 768 temp_scope.materialized_literal_count(),
768 temp_scope.contains_array_literal(), 769 temp_scope.contains_array_literal(),
769 temp_scope.expected_property_count(), 770 temp_scope.expected_property_count(),
770 0, 0, source->length(), false)); 771 0, 0, source->length(shape), false));
771 } else if (scanner().stack_overflow()) { 772 } else if (scanner().stack_overflow()) {
772 Top::StackOverflow(); 773 Top::StackOverflow();
773 } 774 }
774 } 775 }
775 776
776 // Make sure the target stack is empty. 777 // Make sure the target stack is empty.
777 ASSERT(target_stack_ == NULL); 778 ASSERT(target_stack_ == NULL);
778 779
779 // If there was a syntax error we have to get rid of the AST 780 // If there was a syntax error we have to get rid of the AST
780 // and it is not safe to do so before the scope has been deleted. 781 // and it is not safe to do so before the scope has been deleted.
781 if (result == NULL) zone_scope.DeleteOnExit(); 782 if (result == NULL) zone_scope.DeleteOnExit();
782 return result; 783 return result;
783 } 784 }
784 785
785 786
786 FunctionLiteral* Parser::ParseLazy(Handle<String> source, 787 FunctionLiteral* Parser::ParseLazy(Handle<String> source,
787 Handle<String> name, 788 Handle<String> name,
788 int start_position, 789 int start_position,
789 bool is_expression) { 790 bool is_expression) {
790 ZoneScope zone_scope(DONT_DELETE_ON_EXIT); 791 ZoneScope zone_scope(DONT_DELETE_ON_EXIT);
791 StatsRateScope timer(&Counters::parse_lazy); 792 StatsRateScope timer(&Counters::parse_lazy);
792 Counters::total_parse_size.Increment(source->length()); 793 StringShape shape(*source);
794 source->TryFlatten(shape);
795 Counters::total_parse_size.Increment(source->length(shape));
793 SafeStringInputBuffer buffer(source.location()); 796 SafeStringInputBuffer buffer(source.location());
794 797
795 // Initialize parser state. 798 // Initialize parser state.
796 source->TryFlatten();
797 scanner_.Init(source, &buffer, start_position); 799 scanner_.Init(source, &buffer, start_position);
798 ASSERT(target_stack_ == NULL); 800 ASSERT(target_stack_ == NULL);
799 mode_ = PARSE_EAGERLY; 801 mode_ = PARSE_EAGERLY;
800 802
801 // Place holder for the result. 803 // Place holder for the result.
802 FunctionLiteral* result = NULL; 804 FunctionLiteral* result = NULL;
803 805
804 { 806 {
805 // Parse the function literal. 807 // Parse the function literal.
806 Handle<String> no_name = factory()->EmptySymbol(); 808 Handle<String> no_name = factory()->EmptySymbol();
(...skipping 2447 matching lines...) Expand 10 before | Expand all | Expand 10 after
3254 start_position, 3256 start_position,
3255 is_expression); 3257 is_expression);
3256 return result; 3258 return result;
3257 } 3259 }
3258 3260
3259 3261
3260 #undef NEW 3262 #undef NEW
3261 3263
3262 3264
3263 } } // namespace v8::internal 3265 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698