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

Side by Side Diff: src/parser.cc

Issue 7059012: Use placement new for ZoneLists in the parser. (Closed)
Patch Set: Created 9 years, 7 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
« no previous file with comments | « no previous file | src/zone.h » ('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 2011 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 text_.Get(i)->AppendToText(text); 120 text_.Get(i)->AppendToText(text);
121 terms_.Add(text); 121 terms_.Add(text);
122 } 122 }
123 text_.Clear(); 123 text_.Clear();
124 } 124 }
125 125
126 126
127 void RegExpBuilder::AddCharacter(uc16 c) { 127 void RegExpBuilder::AddCharacter(uc16 c) {
128 pending_empty_ = false; 128 pending_empty_ = false;
129 if (characters_ == NULL) { 129 if (characters_ == NULL) {
130 characters_ = new ZoneList<uc16>(4); 130 characters_ = new(zone()) ZoneList<uc16>(4);
131 } 131 }
132 characters_->Add(c); 132 characters_->Add(c);
133 LAST(ADD_CHAR); 133 LAST(ADD_CHAR);
134 } 134 }
135 135
136 136
137 void RegExpBuilder::AddEmpty() { 137 void RegExpBuilder::AddEmpty() {
138 pending_empty_ = true; 138 pending_empty_ = true;
139 } 139 }
140 140
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 ? Scope::GLOBAL_SCOPE 632 ? Scope::GLOBAL_SCOPE
633 : Scope::EVAL_SCOPE; 633 : Scope::EVAL_SCOPE;
634 Handle<String> no_name = isolate()->factory()->empty_symbol(); 634 Handle<String> no_name = isolate()->factory()->empty_symbol();
635 635
636 FunctionLiteral* result = NULL; 636 FunctionLiteral* result = NULL;
637 { Scope* scope = NewScope(top_scope_, type, inside_with()); 637 { Scope* scope = NewScope(top_scope_, type, inside_with());
638 LexicalScope lexical_scope(this, scope, isolate()); 638 LexicalScope lexical_scope(this, scope, isolate());
639 if (strict_mode == kStrictMode) { 639 if (strict_mode == kStrictMode) {
640 top_scope_->EnableStrictMode(); 640 top_scope_->EnableStrictMode();
641 } 641 }
642 ZoneList<Statement*>* body = new ZoneList<Statement*>(16); 642 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16);
643 bool ok = true; 643 bool ok = true;
644 int beg_loc = scanner().location().beg_pos; 644 int beg_loc = scanner().location().beg_pos;
645 ParseSourceElements(body, Token::EOS, &ok); 645 ParseSourceElements(body, Token::EOS, &ok);
646 if (ok && top_scope_->is_strict_mode()) { 646 if (ok && top_scope_->is_strict_mode()) {
647 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); 647 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok);
648 } 648 }
649 if (ok) { 649 if (ok) {
650 result = new(zone()) FunctionLiteral( 650 result = new(zone()) FunctionLiteral(
651 no_name, 651 no_name,
652 top_scope_, 652 top_scope_,
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 1042
1043 void AssignmentFromSomethingElse() { 1043 void AssignmentFromSomethingElse() {
1044 // The this assignment is not a simple one. 1044 // The this assignment is not a simple one.
1045 only_simple_this_property_assignments_ = false; 1045 only_simple_this_property_assignments_ = false;
1046 } 1046 }
1047 1047
1048 void EnsureAllocation() { 1048 void EnsureAllocation() {
1049 if (names_ == NULL) { 1049 if (names_ == NULL) {
1050 ASSERT(assigned_arguments_ == NULL); 1050 ASSERT(assigned_arguments_ == NULL);
1051 ASSERT(assigned_constants_ == NULL); 1051 ASSERT(assigned_constants_ == NULL);
1052 names_ = new ZoneStringList(4); 1052 Zone* zone = isolate_->zone();
1053 assigned_arguments_ = new ZoneList<int>(4); 1053 names_ = new(zone) ZoneStringList(4);
1054 assigned_constants_ = new ZoneObjectList(4); 1054 assigned_arguments_ = new(zone) ZoneList<int>(4);
1055 assigned_constants_ = new(zone) ZoneObjectList(4);
1055 } 1056 }
1056 } 1057 }
1057 1058
1058 Isolate* isolate_; 1059 Isolate* isolate_;
1059 bool only_simple_this_property_assignments_; 1060 bool only_simple_this_property_assignments_;
1060 ZoneStringList* names_; 1061 ZoneStringList* names_;
1061 ZoneList<int>* assigned_arguments_; 1062 ZoneList<int>* assigned_arguments_;
1062 ZoneObjectList* assigned_constants_; 1063 ZoneObjectList* assigned_constants_;
1063 }; 1064 };
1064 1065
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
1646 // guarantee to give the global object a "local" variable; a 1647 // guarantee to give the global object a "local" variable; a
1647 // variable defined in the global object and not in any 1648 // variable defined in the global object and not in any
1648 // prototype. This way, global variable declarations can shadow 1649 // prototype. This way, global variable declarations can shadow
1649 // properties in the prototype chain, but only after the variable 1650 // properties in the prototype chain, but only after the variable
1650 // declaration statement has been executed. This is important in 1651 // declaration statement has been executed. This is important in
1651 // browsers where the global object (window) has lots of 1652 // browsers where the global object (window) has lots of
1652 // properties defined in prototype objects. 1653 // properties defined in prototype objects.
1653 1654
1654 if (top_scope_->is_global_scope()) { 1655 if (top_scope_->is_global_scope()) {
1655 // Compute the arguments for the runtime call. 1656 // Compute the arguments for the runtime call.
1656 ZoneList<Expression*>* arguments = new ZoneList<Expression*>(3); 1657 ZoneList<Expression*>* arguments = new(zone()) ZoneList<Expression*>(3);
1657 // We have at least 1 parameter. 1658 // We have at least 1 parameter.
1658 arguments->Add(new(zone()) Literal(name)); 1659 arguments->Add(new(zone()) Literal(name));
1659 CallRuntime* initialize; 1660 CallRuntime* initialize;
1660 1661
1661 if (is_const) { 1662 if (is_const) {
1662 arguments->Add(value); 1663 arguments->Add(value);
1663 value = NULL; // zap the value to avoid the unnecessary assignment 1664 value = NULL; // zap the value to avoid the unnecessary assignment
1664 1665
1665 // Construct the call to Runtime_InitializeConstGlobal 1666 // Construct the call to Runtime_InitializeConstGlobal
1666 // and add it to the initialization statement block. 1667 // and add it to the initialization statement block.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1763 // structured. However, these are probably changes we want to 1764 // structured. However, these are probably changes we want to
1764 // make later anyway so we should go back and fix this then. 1765 // make later anyway so we should go back and fix this then.
1765 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) { 1766 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) {
1766 SmartPointer<char> c_string = label->ToCString(DISALLOW_NULLS); 1767 SmartPointer<char> c_string = label->ToCString(DISALLOW_NULLS);
1767 const char* elms[2] = { "Label", *c_string }; 1768 const char* elms[2] = { "Label", *c_string };
1768 Vector<const char*> args(elms, 2); 1769 Vector<const char*> args(elms, 2);
1769 ReportMessage("redeclaration", args); 1770 ReportMessage("redeclaration", args);
1770 *ok = false; 1771 *ok = false;
1771 return NULL; 1772 return NULL;
1772 } 1773 }
1773 if (labels == NULL) labels = new ZoneStringList(4); 1774 if (labels == NULL) labels = new(zone()) ZoneStringList(4);
1774 labels->Add(label); 1775 labels->Add(label);
1775 // Remove the "ghost" variable that turned out to be a label 1776 // Remove the "ghost" variable that turned out to be a label
1776 // from the top scope. This way, we don't try to resolve it 1777 // from the top scope. This way, we don't try to resolve it
1777 // during the scope processing. 1778 // during the scope processing.
1778 top_scope_->RemoveUnresolved(var); 1779 top_scope_->RemoveUnresolved(var);
1779 Expect(Token::COLON, CHECK_OK); 1780 Expect(Token::COLON, CHECK_OK);
1780 return ParseStatement(labels, ok); 1781 return ParseStatement(labels, ok);
1781 } 1782 }
1782 1783
1783 // Parsed expression statement. 1784 // Parsed expression statement.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1904 ExpectSemicolon(CHECK_OK); 1905 ExpectSemicolon(CHECK_OK);
1905 return new(zone()) ReturnStatement(expr); 1906 return new(zone()) ReturnStatement(expr);
1906 } 1907 }
1907 1908
1908 1909
1909 Block* Parser::WithHelper(Expression* obj, 1910 Block* Parser::WithHelper(Expression* obj,
1910 ZoneStringList* labels, 1911 ZoneStringList* labels,
1911 bool is_catch_block, 1912 bool is_catch_block,
1912 bool* ok) { 1913 bool* ok) {
1913 // Parse the statement and collect escaping labels. 1914 // Parse the statement and collect escaping labels.
1914 ZoneList<Label*>* target_list = new ZoneList<Label*>(0); 1915 ZoneList<Label*>* target_list = new(zone()) ZoneList<Label*>(0);
1915 TargetCollector collector(target_list); 1916 TargetCollector collector(target_list);
1916 Statement* stat; 1917 Statement* stat;
1917 { Target target(&this->target_stack_, &collector); 1918 { Target target(&this->target_stack_, &collector);
1918 with_nesting_level_++; 1919 with_nesting_level_++;
1919 top_scope_->RecordWithStatement(); 1920 top_scope_->RecordWithStatement();
1920 stat = ParseStatement(labels, CHECK_OK); 1921 stat = ParseStatement(labels, CHECK_OK);
1921 with_nesting_level_--; 1922 with_nesting_level_--;
1922 } 1923 }
1923 // Create resulting block with two statements. 1924 // Create resulting block with two statements.
1924 // 1: Evaluate the with expression. 1925 // 1: Evaluate the with expression.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1979 if (*default_seen_ptr) { 1980 if (*default_seen_ptr) {
1980 ReportMessage("multiple_defaults_in_switch", 1981 ReportMessage("multiple_defaults_in_switch",
1981 Vector<const char*>::empty()); 1982 Vector<const char*>::empty());
1982 *ok = false; 1983 *ok = false;
1983 return NULL; 1984 return NULL;
1984 } 1985 }
1985 *default_seen_ptr = true; 1986 *default_seen_ptr = true;
1986 } 1987 }
1987 Expect(Token::COLON, CHECK_OK); 1988 Expect(Token::COLON, CHECK_OK);
1988 int pos = scanner().location().beg_pos; 1989 int pos = scanner().location().beg_pos;
1989 ZoneList<Statement*>* statements = new ZoneList<Statement*>(5); 1990 ZoneList<Statement*>* statements = new(zone()) ZoneList<Statement*>(5);
1990 while (peek() != Token::CASE && 1991 while (peek() != Token::CASE &&
1991 peek() != Token::DEFAULT && 1992 peek() != Token::DEFAULT &&
1992 peek() != Token::RBRACE) { 1993 peek() != Token::RBRACE) {
1993 Statement* stat = ParseStatement(NULL, CHECK_OK); 1994 Statement* stat = ParseStatement(NULL, CHECK_OK);
1994 statements->Add(stat); 1995 statements->Add(stat);
1995 } 1996 }
1996 1997
1997 return new(zone()) CaseClause(label, statements, pos); 1998 return new(zone()) CaseClause(label, statements, pos);
1998 } 1999 }
1999 2000
2000 2001
2001 SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels, 2002 SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels,
2002 bool* ok) { 2003 bool* ok) {
2003 // SwitchStatement :: 2004 // SwitchStatement ::
2004 // 'switch' '(' Expression ')' '{' CaseClause* '}' 2005 // 'switch' '(' Expression ')' '{' CaseClause* '}'
2005 2006
2006 SwitchStatement* statement = new(zone()) SwitchStatement(labels); 2007 SwitchStatement* statement = new(zone()) SwitchStatement(labels);
2007 Target target(&this->target_stack_, statement); 2008 Target target(&this->target_stack_, statement);
2008 2009
2009 Expect(Token::SWITCH, CHECK_OK); 2010 Expect(Token::SWITCH, CHECK_OK);
2010 Expect(Token::LPAREN, CHECK_OK); 2011 Expect(Token::LPAREN, CHECK_OK);
2011 Expression* tag = ParseExpression(true, CHECK_OK); 2012 Expression* tag = ParseExpression(true, CHECK_OK);
2012 Expect(Token::RPAREN, CHECK_OK); 2013 Expect(Token::RPAREN, CHECK_OK);
2013 2014
2014 bool default_seen = false; 2015 bool default_seen = false;
2015 ZoneList<CaseClause*>* cases = new ZoneList<CaseClause*>(4); 2016 ZoneList<CaseClause*>* cases = new(zone()) ZoneList<CaseClause*>(4);
2016 Expect(Token::LBRACE, CHECK_OK); 2017 Expect(Token::LBRACE, CHECK_OK);
2017 while (peek() != Token::RBRACE) { 2018 while (peek() != Token::RBRACE) {
2018 CaseClause* clause = ParseCaseClause(&default_seen, CHECK_OK); 2019 CaseClause* clause = ParseCaseClause(&default_seen, CHECK_OK);
2019 cases->Add(clause); 2020 cases->Add(clause);
2020 } 2021 }
2021 Expect(Token::RBRACE, CHECK_OK); 2022 Expect(Token::RBRACE, CHECK_OK);
2022 2023
2023 if (statement) statement->Initialize(tag, cases); 2024 if (statement) statement->Initialize(tag, cases);
2024 return statement; 2025 return statement;
2025 } 2026 }
(...skipping 24 matching lines...) Expand all
2050 // 'try' Block Catch Finally 2051 // 'try' Block Catch Finally
2051 // 2052 //
2052 // Catch :: 2053 // Catch ::
2053 // 'catch' '(' Identifier ')' Block 2054 // 'catch' '(' Identifier ')' Block
2054 // 2055 //
2055 // Finally :: 2056 // Finally ::
2056 // 'finally' Block 2057 // 'finally' Block
2057 2058
2058 Expect(Token::TRY, CHECK_OK); 2059 Expect(Token::TRY, CHECK_OK);
2059 2060
2060 ZoneList<Label*>* target_list = new ZoneList<Label*>(0); 2061 ZoneList<Label*>* target_list = new(zone()) ZoneList<Label*>(0);
2061 TargetCollector collector(target_list); 2062 TargetCollector collector(target_list);
2062 Block* try_block; 2063 Block* try_block;
2063 2064
2064 { Target target(&this->target_stack_, &collector); 2065 { Target target(&this->target_stack_, &collector);
2065 try_block = ParseBlock(NULL, CHECK_OK); 2066 try_block = ParseBlock(NULL, CHECK_OK);
2066 } 2067 }
2067 2068
2068 Block* catch_block = NULL; 2069 Block* catch_block = NULL;
2069 Variable* catch_var = NULL; 2070 Variable* catch_var = NULL;
2070 Block* finally_block = NULL; 2071 Block* finally_block = NULL;
2071 2072
2072 Token::Value tok = peek(); 2073 Token::Value tok = peek();
2073 if (tok != Token::CATCH && tok != Token::FINALLY) { 2074 if (tok != Token::CATCH && tok != Token::FINALLY) {
2074 ReportMessage("no_catch_or_finally", Vector<const char*>::empty()); 2075 ReportMessage("no_catch_or_finally", Vector<const char*>::empty());
2075 *ok = false; 2076 *ok = false;
2076 return NULL; 2077 return NULL;
2077 } 2078 }
2078 2079
2079 // If we can break out from the catch block and there is a finally block, 2080 // If we can break out from the catch block and there is a finally block,
2080 // then we will need to collect jump targets from the catch block. Since 2081 // then we will need to collect jump targets from the catch block. Since
2081 // we don't know yet if there will be a finally block, we always collect 2082 // we don't know yet if there will be a finally block, we always collect
2082 // the jump targets. 2083 // the jump targets.
2083 ZoneList<Label*>* catch_target_list = new ZoneList<Label*>(0); 2084 ZoneList<Label*>* catch_target_list = new(zone()) ZoneList<Label*>(0);
2084 TargetCollector catch_collector(catch_target_list); 2085 TargetCollector catch_collector(catch_target_list);
2085 bool has_catch = false; 2086 bool has_catch = false;
2086 if (tok == Token::CATCH) { 2087 if (tok == Token::CATCH) {
2087 has_catch = true; 2088 has_catch = true;
2088 Consume(Token::CATCH); 2089 Consume(Token::CATCH);
2089 2090
2090 Expect(Token::LPAREN, CHECK_OK); 2091 Expect(Token::LPAREN, CHECK_OK);
2091 Handle<String> name = ParseIdentifier(CHECK_OK); 2092 Handle<String> name = ParseIdentifier(CHECK_OK);
2092 2093
2093 if (top_scope_->is_strict_mode() && IsEvalOrArguments(name)) { 2094 if (top_scope_->is_strict_mode() && IsEvalOrArguments(name)) {
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
2719 2720
2720 Expression* result; 2721 Expression* result;
2721 if (peek() == Token::NEW) { 2722 if (peek() == Token::NEW) {
2722 result = ParseNewPrefix(stack, CHECK_OK); 2723 result = ParseNewPrefix(stack, CHECK_OK);
2723 } else { 2724 } else {
2724 result = ParseMemberWithNewPrefixesExpression(stack, CHECK_OK); 2725 result = ParseMemberWithNewPrefixesExpression(stack, CHECK_OK);
2725 } 2726 }
2726 2727
2727 if (!stack->is_empty()) { 2728 if (!stack->is_empty()) {
2728 int last = stack->pop(); 2729 int last = stack->pop();
2729 result = new(zone()) CallNew(result, new ZoneList<Expression*>(0), last); 2730 result = new(zone()) CallNew(result,
2731 new(zone()) ZoneList<Expression*>(0),
2732 last);
2730 } 2733 }
2731 return result; 2734 return result;
2732 } 2735 }
2733 2736
2734 2737
2735 Expression* Parser::ParseNewExpression(bool* ok) { 2738 Expression* Parser::ParseNewExpression(bool* ok) {
2736 PositionStack stack(ok); 2739 PositionStack stack(ok);
2737 return ParseNewPrefix(&stack, ok); 2740 return ParseNewPrefix(&stack, ok);
2738 } 2741 }
2739 2742
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
2986 2989
2987 *is_simple = is_simple_acc; 2990 *is_simple = is_simple_acc;
2988 *depth = depth_acc; 2991 *depth = depth_acc;
2989 } 2992 }
2990 2993
2991 2994
2992 Expression* Parser::ParseArrayLiteral(bool* ok) { 2995 Expression* Parser::ParseArrayLiteral(bool* ok) {
2993 // ArrayLiteral :: 2996 // ArrayLiteral ::
2994 // '[' Expression? (',' Expression?)* ']' 2997 // '[' Expression? (',' Expression?)* ']'
2995 2998
2996 ZoneList<Expression*>* values = new ZoneList<Expression*>(4); 2999 ZoneList<Expression*>* values = new(zone()) ZoneList<Expression*>(4);
2997 Expect(Token::LBRACK, CHECK_OK); 3000 Expect(Token::LBRACK, CHECK_OK);
2998 while (peek() != Token::RBRACK) { 3001 while (peek() != Token::RBRACK) {
2999 Expression* elem; 3002 Expression* elem;
3000 if (peek() == Token::COMMA) { 3003 if (peek() == Token::COMMA) {
3001 elem = GetLiteralTheHole(); 3004 elem = GetLiteralTheHole();
3002 } else { 3005 } else {
3003 elem = ParseAssignmentExpression(true, CHECK_OK); 3006 elem = ParseAssignmentExpression(true, CHECK_OK);
3004 } 3007 }
3005 values->Add(elem); 3008 values->Add(elem);
3006 if (peek() != Token::RBRACK) { 3009 if (peek() != Token::RBRACK) {
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
3328 3331
3329 3332
3330 Expression* Parser::ParseObjectLiteral(bool* ok) { 3333 Expression* Parser::ParseObjectLiteral(bool* ok) {
3331 // ObjectLiteral :: 3334 // ObjectLiteral ::
3332 // '{' ( 3335 // '{' (
3333 // ((IdentifierName | String | Number) ':' AssignmentExpression) 3336 // ((IdentifierName | String | Number) ':' AssignmentExpression)
3334 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral) 3337 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral)
3335 // )*[','] '}' 3338 // )*[','] '}'
3336 3339
3337 ZoneList<ObjectLiteral::Property*>* properties = 3340 ZoneList<ObjectLiteral::Property*>* properties =
3338 new ZoneList<ObjectLiteral::Property*>(4); 3341 new(zone()) ZoneList<ObjectLiteral::Property*>(4);
3339 int number_of_boilerplate_properties = 0; 3342 int number_of_boilerplate_properties = 0;
3340 bool has_function = false; 3343 bool has_function = false;
3341 3344
3342 ObjectLiteralPropertyChecker checker(this, top_scope_->is_strict_mode()); 3345 ObjectLiteralPropertyChecker checker(this, top_scope_->is_strict_mode());
3343 3346
3344 Expect(Token::LBRACE, CHECK_OK); 3347 Expect(Token::LBRACE, CHECK_OK);
3345 Scanner::Location loc = scanner().location(); 3348 Scanner::Location loc = scanner().location();
3346 3349
3347 while (peek() != Token::RBRACE) { 3350 while (peek() != Token::RBRACE) {
3348 if (fni_ != NULL) fni_->Enter(); 3351 if (fni_ != NULL) fni_->Enter();
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
3490 Next(); 3493 Next();
3491 3494
3492 return new(zone()) RegExpLiteral(js_pattern, js_flags, literal_index); 3495 return new(zone()) RegExpLiteral(js_pattern, js_flags, literal_index);
3493 } 3496 }
3494 3497
3495 3498
3496 ZoneList<Expression*>* Parser::ParseArguments(bool* ok) { 3499 ZoneList<Expression*>* Parser::ParseArguments(bool* ok) {
3497 // Arguments :: 3500 // Arguments ::
3498 // '(' (AssignmentExpression)*[','] ')' 3501 // '(' (AssignmentExpression)*[','] ')'
3499 3502
3500 ZoneList<Expression*>* result = new ZoneList<Expression*>(4); 3503 ZoneList<Expression*>* result = new(zone()) ZoneList<Expression*>(4);
3501 Expect(Token::LPAREN, CHECK_OK); 3504 Expect(Token::LPAREN, CHECK_OK);
3502 bool done = (peek() == Token::RPAREN); 3505 bool done = (peek() == Token::RPAREN);
3503 while (!done) { 3506 while (!done) {
3504 Expression* argument = ParseAssignmentExpression(true, CHECK_OK); 3507 Expression* argument = ParseAssignmentExpression(true, CHECK_OK);
3505 result->Add(argument); 3508 result->Add(argument);
3506 done = (peek() == Token::RPAREN); 3509 done = (peek() == Token::RPAREN);
3507 if (!done) Expect(Token::COMMA, CHECK_OK); 3510 if (!done) Expect(Token::COMMA, CHECK_OK);
3508 } 3511 }
3509 Expect(Token::RPAREN, CHECK_OK); 3512 Expect(Token::RPAREN, CHECK_OK);
3510 return result; 3513 return result;
(...skipping 16 matching lines...) Expand all
3527 Handle<String> name = 3530 Handle<String> name =
3528 is_named ? var_name : isolate()->factory()->empty_symbol(); 3531 is_named ? var_name : isolate()->factory()->empty_symbol();
3529 // The function name, if any. 3532 // The function name, if any.
3530 Handle<String> function_name = isolate()->factory()->empty_symbol(); 3533 Handle<String> function_name = isolate()->factory()->empty_symbol();
3531 if (is_named && (type == EXPRESSION || type == NESTED)) { 3534 if (is_named && (type == EXPRESSION || type == NESTED)) {
3532 function_name = name; 3535 function_name = name;
3533 } 3536 }
3534 3537
3535 int num_parameters = 0; 3538 int num_parameters = 0;
3536 Scope* scope = NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with()); 3539 Scope* scope = NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with());
3537 ZoneList<Statement*>* body = new ZoneList<Statement*>(8); 3540 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8);
3538 int materialized_literal_count; 3541 int materialized_literal_count;
3539 int expected_property_count; 3542 int expected_property_count;
3540 int start_pos; 3543 int start_pos;
3541 int end_pos; 3544 int end_pos;
3542 bool only_simple_this_property_assignments; 3545 bool only_simple_this_property_assignments;
3543 Handle<FixedArray> this_property_assignments; 3546 Handle<FixedArray> this_property_assignments;
3544 // Parse function body. 3547 // Parse function body.
3545 { LexicalScope lexical_scope(this, scope, isolate()); 3548 { LexicalScope lexical_scope(this, scope, isolate());
3546 top_scope_->SetScopeName(name); 3549 top_scope_->SetScopeName(name);
3547 3550
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
4000 TENURED); 4003 TENURED);
4001 for (int i = 0; i < argc; i++) { 4004 for (int i = 0; i < argc; i++) {
4002 Handle<Object> element = arguments[i]; 4005 Handle<Object> element = arguments[i];
4003 if (!element.is_null()) { 4006 if (!element.is_null()) {
4004 elements->set(i, *element); 4007 elements->set(i, *element);
4005 } 4008 }
4006 } 4009 }
4007 Handle<JSArray> array = isolate()->factory()->NewJSArrayWithElements(elements, 4010 Handle<JSArray> array = isolate()->factory()->NewJSArrayWithElements(elements,
4008 TENURED); 4011 TENURED);
4009 4012
4010 ZoneList<Expression*>* args = new ZoneList<Expression*>(2); 4013 ZoneList<Expression*>* args = new(zone()) ZoneList<Expression*>(2);
4011 args->Add(new(zone()) Literal(type)); 4014 args->Add(new(zone()) Literal(type));
4012 args->Add(new(zone()) Literal(array)); 4015 args->Add(new(zone()) Literal(array));
4013 return new(zone()) Throw(new(zone()) CallRuntime(constructor, NULL, args), 4016 return new(zone()) Throw(new(zone()) CallRuntime(constructor, NULL, args),
4014 scanner().location().beg_pos); 4017 scanner().location().beg_pos);
4015 } 4018 }
4016 4019
4017 // ---------------------------------------------------------------------------- 4020 // ----------------------------------------------------------------------------
4018 // JSON 4021 // JSON
4019 4022
4020 Handle<Object> JsonParser::ParseJson(Handle<String> script, 4023 Handle<Object> JsonParser::ParseJson(Handle<String> script,
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
4389 Advance(); 4392 Advance();
4390 RegExpAssertion::Type type = 4393 RegExpAssertion::Type type =
4391 multiline_ ? RegExpAssertion::END_OF_LINE : 4394 multiline_ ? RegExpAssertion::END_OF_LINE :
4392 RegExpAssertion::END_OF_INPUT; 4395 RegExpAssertion::END_OF_INPUT;
4393 builder->AddAssertion(new(zone()) RegExpAssertion(type)); 4396 builder->AddAssertion(new(zone()) RegExpAssertion(type));
4394 continue; 4397 continue;
4395 } 4398 }
4396 case '.': { 4399 case '.': {
4397 Advance(); 4400 Advance();
4398 // everything except \x0a, \x0d, \u2028 and \u2029 4401 // everything except \x0a, \x0d, \u2028 and \u2029
4399 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); 4402 ZoneList<CharacterRange>* ranges =
4403 new(zone()) ZoneList<CharacterRange>(2);
4400 CharacterRange::AddClassEscape('.', ranges); 4404 CharacterRange::AddClassEscape('.', ranges);
4401 RegExpTree* atom = new(zone()) RegExpCharacterClass(ranges, false); 4405 RegExpTree* atom = new(zone()) RegExpCharacterClass(ranges, false);
4402 builder->AddAtom(atom); 4406 builder->AddAtom(atom);
4403 break; 4407 break;
4404 } 4408 }
4405 case '(': { 4409 case '(': {
4406 SubexpressionType type = CAPTURE; 4410 SubexpressionType type = CAPTURE;
4407 Advance(); 4411 Advance();
4408 if (current() == '?') { 4412 if (current() == '?') {
4409 switch (Next()) { 4413 switch (Next()) {
4410 case ':': 4414 case ':':
4411 type = GROUPING; 4415 type = GROUPING;
4412 break; 4416 break;
4413 case '=': 4417 case '=':
4414 type = POSITIVE_LOOKAHEAD; 4418 type = POSITIVE_LOOKAHEAD;
4415 break; 4419 break;
4416 case '!': 4420 case '!':
4417 type = NEGATIVE_LOOKAHEAD; 4421 type = NEGATIVE_LOOKAHEAD;
4418 break; 4422 break;
4419 default: 4423 default:
4420 ReportError(CStrVector("Invalid group") CHECK_FAILED); 4424 ReportError(CStrVector("Invalid group") CHECK_FAILED);
4421 break; 4425 break;
4422 } 4426 }
4423 Advance(2); 4427 Advance(2);
4424 } else { 4428 } else {
4425 if (captures_ == NULL) { 4429 if (captures_ == NULL) {
4426 captures_ = new ZoneList<RegExpCapture*>(2); 4430 captures_ = new(zone()) ZoneList<RegExpCapture*>(2);
4427 } 4431 }
4428 if (captures_started() >= kMaxCaptures) { 4432 if (captures_started() >= kMaxCaptures) {
4429 ReportError(CStrVector("Too many captures") CHECK_FAILED); 4433 ReportError(CStrVector("Too many captures") CHECK_FAILED);
4430 } 4434 }
4431 captures_->Add(NULL); 4435 captures_->Add(NULL);
4432 } 4436 }
4433 // Store current state and begin new disjunction parsing. 4437 // Store current state and begin new disjunction parsing.
4434 stored_state = new(zone()) RegExpParserState(stored_state, 4438 stored_state = new(zone()) RegExpParserState(stored_state,
4435 type, 4439 type,
4436 captures_started()); 4440 captures_started());
(...skipping 22 matching lines...) Expand all
4459 new(zone()) RegExpAssertion(RegExpAssertion::NON_BOUNDARY)); 4463 new(zone()) RegExpAssertion(RegExpAssertion::NON_BOUNDARY));
4460 continue; 4464 continue;
4461 // AtomEscape :: 4465 // AtomEscape ::
4462 // CharacterClassEscape 4466 // CharacterClassEscape
4463 // 4467 //
4464 // CharacterClassEscape :: one of 4468 // CharacterClassEscape :: one of
4465 // d D s S w W 4469 // d D s S w W
4466 case 'd': case 'D': case 's': case 'S': case 'w': case 'W': { 4470 case 'd': case 'D': case 's': case 'S': case 'w': case 'W': {
4467 uc32 c = Next(); 4471 uc32 c = Next();
4468 Advance(2); 4472 Advance(2);
4469 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); 4473 ZoneList<CharacterRange>* ranges =
4474 new(zone()) ZoneList<CharacterRange>(2);
4470 CharacterRange::AddClassEscape(c, ranges); 4475 CharacterRange::AddClassEscape(c, ranges);
4471 RegExpTree* atom = new(zone()) RegExpCharacterClass(ranges, false); 4476 RegExpTree* atom = new(zone()) RegExpCharacterClass(ranges, false);
4472 builder->AddAtom(atom); 4477 builder->AddAtom(atom);
4473 break; 4478 break;
4474 } 4479 }
4475 case '1': case '2': case '3': case '4': case '5': case '6': 4480 case '1': case '2': case '3': case '4': case '5': case '6':
4476 case '7': case '8': case '9': { 4481 case '7': case '8': case '9': {
4477 int index = 0; 4482 int index = 0;
4478 if (ParseBackReferenceIndex(&index)) { 4483 if (ParseBackReferenceIndex(&index)) {
4479 RegExpCapture* capture = NULL; 4484 RegExpCapture* capture = NULL;
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
4955 static const char* kUnterminated = "Unterminated character class"; 4960 static const char* kUnterminated = "Unterminated character class";
4956 static const char* kRangeOutOfOrder = "Range out of order in character class"; 4961 static const char* kRangeOutOfOrder = "Range out of order in character class";
4957 4962
4958 ASSERT_EQ(current(), '['); 4963 ASSERT_EQ(current(), '[');
4959 Advance(); 4964 Advance();
4960 bool is_negated = false; 4965 bool is_negated = false;
4961 if (current() == '^') { 4966 if (current() == '^') {
4962 is_negated = true; 4967 is_negated = true;
4963 Advance(); 4968 Advance();
4964 } 4969 }
4965 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); 4970 ZoneList<CharacterRange>* ranges = new(zone()) ZoneList<CharacterRange>(2);
4966 while (has_more() && current() != ']') { 4971 while (has_more() && current() != ']') {
4967 uc16 char_class = kNoCharClass; 4972 uc16 char_class = kNoCharClass;
4968 CharacterRange first = ParseClassAtom(&char_class CHECK_FAILED); 4973 CharacterRange first = ParseClassAtom(&char_class CHECK_FAILED);
4969 if (current() == '-') { 4974 if (current() == '-') {
4970 Advance(); 4975 Advance();
4971 if (current() == kEndMarker) { 4976 if (current() == kEndMarker) {
4972 // If we reach the end we break out of the loop and let the 4977 // If we reach the end we break out of the loop and let the
4973 // following code report an error. 4978 // following code report an error.
4974 break; 4979 break;
4975 } else if (current() == ']') { 4980 } else if (current() == ']') {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
5178 info->is_global(), 5183 info->is_global(),
5179 info->StrictMode()); 5184 info->StrictMode());
5180 } 5185 }
5181 } 5186 }
5182 5187
5183 info->SetFunction(result); 5188 info->SetFunction(result);
5184 return (result != NULL); 5189 return (result != NULL);
5185 } 5190 }
5186 5191
5187 } } // namespace v8::internal 5192 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/zone.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698