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

Side by Side Diff: src/parser.cc

Issue 272043: Remove a redundant field in the FunctionLiteral class. The boolean... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 2 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 | « src/parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 ~TemporaryScope(); 668 ~TemporaryScope();
669 669
670 int NextMaterializedLiteralIndex() { 670 int NextMaterializedLiteralIndex() {
671 int next_index = 671 int next_index =
672 materialized_literal_count_ + JSFunction::kLiteralsPrefixSize; 672 materialized_literal_count_ + JSFunction::kLiteralsPrefixSize;
673 materialized_literal_count_++; 673 materialized_literal_count_++;
674 return next_index; 674 return next_index;
675 } 675 }
676 int materialized_literal_count() { return materialized_literal_count_; } 676 int materialized_literal_count() { return materialized_literal_count_; }
677 677
678 void set_contains_array_literal() { contains_array_literal_ = true; }
679 bool contains_array_literal() { return contains_array_literal_; }
680
681 void SetThisPropertyAssignmentInfo( 678 void SetThisPropertyAssignmentInfo(
682 bool only_this_property_assignments, 679 bool only_this_property_assignments,
683 bool only_simple_this_property_assignments, 680 bool only_simple_this_property_assignments,
684 Handle<FixedArray> this_property_assignments) { 681 Handle<FixedArray> this_property_assignments) {
685 only_this_property_assignments_ = only_this_property_assignments; 682 only_this_property_assignments_ = only_this_property_assignments;
686 only_simple_this_property_assignments_ = 683 only_simple_this_property_assignments_ =
687 only_simple_this_property_assignments; 684 only_simple_this_property_assignments;
688 this_property_assignments_ = this_property_assignments; 685 this_property_assignments_ = this_property_assignments;
689 } 686 }
690 bool only_this_property_assignments() { 687 bool only_this_property_assignments() {
691 return only_this_property_assignments_; 688 return only_this_property_assignments_;
692 } 689 }
693 bool only_simple_this_property_assignments() { 690 bool only_simple_this_property_assignments() {
694 return only_simple_this_property_assignments_; 691 return only_simple_this_property_assignments_;
695 } 692 }
696 Handle<FixedArray> this_property_assignments() { 693 Handle<FixedArray> this_property_assignments() {
697 return this_property_assignments_; 694 return this_property_assignments_;
698 } 695 }
699 696
700 void AddProperty() { expected_property_count_++; } 697 void AddProperty() { expected_property_count_++; }
701 int expected_property_count() { return expected_property_count_; } 698 int expected_property_count() { return expected_property_count_; }
702 private: 699 private:
703 // Captures the number of nodes that need materialization in the 700 // Captures the number of literals that need materialization in the
704 // function. regexp literals, and boilerplate for object literals. 701 // function. Includes regexp literals, and boilerplate for object
702 // and array literals.
705 int materialized_literal_count_; 703 int materialized_literal_count_;
706 704
707 // Captures whether or not the function contains array literals. If
708 // the function contains array literals, we have to allocate space
709 // for the array constructor in the literals array of the function.
710 // This array constructor is used when creating the actual array
711 // literals.
712 bool contains_array_literal_;
713
714 // Properties count estimation. 705 // Properties count estimation.
715 int expected_property_count_; 706 int expected_property_count_;
716 707
717 bool only_this_property_assignments_; 708 bool only_this_property_assignments_;
718 bool only_simple_this_property_assignments_; 709 bool only_simple_this_property_assignments_;
719 Handle<FixedArray> this_property_assignments_; 710 Handle<FixedArray> this_property_assignments_;
720 711
721 // Bookkeeping 712 // Bookkeeping
722 Parser* parser_; 713 Parser* parser_;
723 TemporaryScope* parent_; 714 TemporaryScope* parent_;
724 715
725 friend class Parser; 716 friend class Parser;
726 }; 717 };
727 718
728 719
729 TemporaryScope::TemporaryScope(Parser* parser) 720 TemporaryScope::TemporaryScope(Parser* parser)
730 : materialized_literal_count_(0), 721 : materialized_literal_count_(0),
731 contains_array_literal_(false),
732 expected_property_count_(0), 722 expected_property_count_(0),
733 only_this_property_assignments_(false), 723 only_this_property_assignments_(false),
734 only_simple_this_property_assignments_(false), 724 only_simple_this_property_assignments_(false),
735 this_property_assignments_(Factory::empty_fixed_array()), 725 this_property_assignments_(Factory::empty_fixed_array()),
736 parser_(parser), 726 parser_(parser),
737 parent_(parser->temp_scope_) { 727 parent_(parser->temp_scope_) {
738 parser->temp_scope_ = this; 728 parser->temp_scope_ = this;
739 } 729 }
740 730
741 731
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
1229 TemporaryScope temp_scope(this); 1219 TemporaryScope temp_scope(this);
1230 ZoneListWrapper<Statement> body(16); 1220 ZoneListWrapper<Statement> body(16);
1231 bool ok = true; 1221 bool ok = true;
1232 ParseSourceElements(&body, Token::EOS, &ok); 1222 ParseSourceElements(&body, Token::EOS, &ok);
1233 if (ok) { 1223 if (ok) {
1234 result = NEW(FunctionLiteral( 1224 result = NEW(FunctionLiteral(
1235 no_name, 1225 no_name,
1236 top_scope_, 1226 top_scope_,
1237 body.elements(), 1227 body.elements(),
1238 temp_scope.materialized_literal_count(), 1228 temp_scope.materialized_literal_count(),
1239 temp_scope.contains_array_literal(),
1240 temp_scope.expected_property_count(), 1229 temp_scope.expected_property_count(),
1241 temp_scope.only_this_property_assignments(), 1230 temp_scope.only_this_property_assignments(),
1242 temp_scope.only_simple_this_property_assignments(), 1231 temp_scope.only_simple_this_property_assignments(),
1243 temp_scope.this_property_assignments(), 1232 temp_scope.this_property_assignments(),
1244 0, 1233 0,
1245 0, 1234 0,
1246 source->length(), 1235 source->length(),
1247 false)); 1236 false));
1248 } else if (scanner().stack_overflow()) { 1237 } else if (scanner().stack_overflow()) {
1249 Top::StackOverflow(); 1238 Top::StackOverflow();
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
1896 // Compute the function template for the native function. 1885 // Compute the function template for the native function.
1897 v8::Handle<v8::FunctionTemplate> fun_template = 1886 v8::Handle<v8::FunctionTemplate> fun_template =
1898 extension_->GetNativeFunction(v8::Utils::ToLocal(name)); 1887 extension_->GetNativeFunction(v8::Utils::ToLocal(name));
1899 ASSERT(!fun_template.IsEmpty()); 1888 ASSERT(!fun_template.IsEmpty());
1900 1889
1901 // Instantiate the function and create a boilerplate function from it. 1890 // Instantiate the function and create a boilerplate function from it.
1902 Handle<JSFunction> fun = Utils::OpenHandle(*fun_template->GetFunction()); 1891 Handle<JSFunction> fun = Utils::OpenHandle(*fun_template->GetFunction());
1903 const int literals = fun->NumberOfLiterals(); 1892 const int literals = fun->NumberOfLiterals();
1904 Handle<Code> code = Handle<Code>(fun->shared()->code()); 1893 Handle<Code> code = Handle<Code>(fun->shared()->code());
1905 Handle<JSFunction> boilerplate = 1894 Handle<JSFunction> boilerplate =
1906 Factory::NewFunctionBoilerplate(name, literals, false, code); 1895 Factory::NewFunctionBoilerplate(name, literals, code);
1907 1896
1908 // Copy the function data to the boilerplate. Used by 1897 // Copy the function data to the boilerplate. Used by
1909 // builtins.cc:HandleApiCall to perform argument type checks and to 1898 // builtins.cc:HandleApiCall to perform argument type checks and to
1910 // find the right native code to call. 1899 // find the right native code to call.
1911 boilerplate->shared()->set_function_data(fun->shared()->function_data()); 1900 boilerplate->shared()->set_function_data(fun->shared()->function_data());
1912 int parameters = fun->shared()->formal_parameter_count(); 1901 int parameters = fun->shared()->formal_parameter_count();
1913 boilerplate->shared()->set_formal_parameter_count(parameters); 1902 boilerplate->shared()->set_formal_parameter_count(parameters);
1914 1903
1915 // TODO(1240846): It's weird that native function declarations are 1904 // TODO(1240846): It's weird that native function declarations are
1916 // introduced dynamically when we meet their declarations, whereas 1905 // introduced dynamically when we meet their declarations, whereas
(...skipping 1382 matching lines...) Expand 10 before | Expand all | Expand 10 after
3299 elem = ParseAssignmentExpression(true, CHECK_OK); 3288 elem = ParseAssignmentExpression(true, CHECK_OK);
3300 } 3289 }
3301 values.Add(elem); 3290 values.Add(elem);
3302 if (peek() != Token::RBRACK) { 3291 if (peek() != Token::RBRACK) {
3303 Expect(Token::COMMA, CHECK_OK); 3292 Expect(Token::COMMA, CHECK_OK);
3304 } 3293 }
3305 } 3294 }
3306 Expect(Token::RBRACK, CHECK_OK); 3295 Expect(Token::RBRACK, CHECK_OK);
3307 3296
3308 // Update the scope information before the pre-parsing bailout. 3297 // Update the scope information before the pre-parsing bailout.
3309 temp_scope_->set_contains_array_literal();
3310 int literal_index = temp_scope_->NextMaterializedLiteralIndex(); 3298 int literal_index = temp_scope_->NextMaterializedLiteralIndex();
3311 3299
3312 if (is_pre_parsing_) return NULL; 3300 if (is_pre_parsing_) return NULL;
3313 3301
3314 // Allocate a fixed array with all the literals. 3302 // Allocate a fixed array with all the literals.
3315 Handle<FixedArray> literals = 3303 Handle<FixedArray> literals =
3316 Factory::NewFixedArray(values.length(), TENURED); 3304 Factory::NewFixedArray(values.length(), TENURED);
3317 3305
3318 // Fill in the literals. 3306 // Fill in the literals.
3319 bool is_simple = true; 3307 bool is_simple = true;
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
3629 RelocInfo::kNoPosition))); 3617 RelocInfo::kNoPosition)));
3630 } 3618 }
3631 3619
3632 // Determine if the function will be lazily compiled. The mode can 3620 // Determine if the function will be lazily compiled. The mode can
3633 // only be PARSE_LAZILY if the --lazy flag is true. 3621 // only be PARSE_LAZILY if the --lazy flag is true.
3634 bool is_lazily_compiled = 3622 bool is_lazily_compiled =
3635 mode() == PARSE_LAZILY && top_scope_->HasTrivialOuterContext(); 3623 mode() == PARSE_LAZILY && top_scope_->HasTrivialOuterContext();
3636 3624
3637 int materialized_literal_count; 3625 int materialized_literal_count;
3638 int expected_property_count; 3626 int expected_property_count;
3639 bool contains_array_literal;
3640 bool only_this_property_assignments; 3627 bool only_this_property_assignments;
3641 bool only_simple_this_property_assignments; 3628 bool only_simple_this_property_assignments;
3642 Handle<FixedArray> this_property_assignments; 3629 Handle<FixedArray> this_property_assignments;
3643 if (is_lazily_compiled && pre_data() != NULL) { 3630 if (is_lazily_compiled && pre_data() != NULL) {
3644 FunctionEntry entry = pre_data()->GetFunctionEnd(start_pos); 3631 FunctionEntry entry = pre_data()->GetFunctionEnd(start_pos);
3645 int end_pos = entry.end_pos(); 3632 int end_pos = entry.end_pos();
3646 Counters::total_preparse_skipped.Increment(end_pos - start_pos); 3633 Counters::total_preparse_skipped.Increment(end_pos - start_pos);
3647 scanner_.SeekForward(end_pos); 3634 scanner_.SeekForward(end_pos);
3648 materialized_literal_count = entry.literal_count(); 3635 materialized_literal_count = entry.literal_count();
3649 expected_property_count = entry.property_count(); 3636 expected_property_count = entry.property_count();
3650 only_this_property_assignments = false; 3637 only_this_property_assignments = false;
3651 only_simple_this_property_assignments = false; 3638 only_simple_this_property_assignments = false;
3652 this_property_assignments = Factory::empty_fixed_array(); 3639 this_property_assignments = Factory::empty_fixed_array();
3653 contains_array_literal = entry.contains_array_literal();
3654 } else { 3640 } else {
3655 ParseSourceElements(&body, Token::RBRACE, CHECK_OK); 3641 ParseSourceElements(&body, Token::RBRACE, CHECK_OK);
3656 materialized_literal_count = temp_scope.materialized_literal_count(); 3642 materialized_literal_count = temp_scope.materialized_literal_count();
3657 expected_property_count = temp_scope.expected_property_count(); 3643 expected_property_count = temp_scope.expected_property_count();
3658 contains_array_literal = temp_scope.contains_array_literal();
3659 only_this_property_assignments = 3644 only_this_property_assignments =
3660 temp_scope.only_this_property_assignments(); 3645 temp_scope.only_this_property_assignments();
3661 only_simple_this_property_assignments = 3646 only_simple_this_property_assignments =
3662 temp_scope.only_simple_this_property_assignments(); 3647 temp_scope.only_simple_this_property_assignments();
3663 this_property_assignments = temp_scope.this_property_assignments(); 3648 this_property_assignments = temp_scope.this_property_assignments();
3664 } 3649 }
3665 3650
3666 Expect(Token::RBRACE, CHECK_OK); 3651 Expect(Token::RBRACE, CHECK_OK);
3667 int end_pos = scanner_.location().end_pos; 3652 int end_pos = scanner_.location().end_pos;
3668 3653
3669 FunctionEntry entry = log()->LogFunction(start_pos); 3654 FunctionEntry entry = log()->LogFunction(start_pos);
3670 if (entry.is_valid()) { 3655 if (entry.is_valid()) {
3671 entry.set_end_pos(end_pos); 3656 entry.set_end_pos(end_pos);
3672 entry.set_literal_count(materialized_literal_count); 3657 entry.set_literal_count(materialized_literal_count);
3673 entry.set_property_count(expected_property_count); 3658 entry.set_property_count(expected_property_count);
3674 entry.set_contains_array_literal(contains_array_literal);
3675 } 3659 }
3676 3660
3677 FunctionLiteral* function_literal = 3661 FunctionLiteral* function_literal =
3678 NEW(FunctionLiteral(name, 3662 NEW(FunctionLiteral(name,
3679 top_scope_, 3663 top_scope_,
3680 body.elements(), 3664 body.elements(),
3681 materialized_literal_count, 3665 materialized_literal_count,
3682 contains_array_literal,
3683 expected_property_count, 3666 expected_property_count,
3684 only_this_property_assignments, 3667 only_this_property_assignments,
3685 only_simple_this_property_assignments, 3668 only_simple_this_property_assignments,
3686 this_property_assignments, 3669 this_property_assignments,
3687 num_parameters, 3670 num_parameters,
3688 start_pos, 3671 start_pos,
3689 end_pos, 3672 end_pos,
3690 function_name->length() > 0)); 3673 function_name->length() > 0));
3691 if (!is_pre_parsing_) { 3674 if (!is_pre_parsing_) {
3692 function_literal->set_function_token_position(function_token_position); 3675 function_literal->set_function_token_position(function_token_position);
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after
4828 start_position, 4811 start_position,
4829 is_expression); 4812 is_expression);
4830 return result; 4813 return result;
4831 } 4814 }
4832 4815
4833 4816
4834 #undef NEW 4817 #undef NEW
4835 4818
4836 4819
4837 } } // namespace v8::internal 4820 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698