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

Side by Side Diff: src/parser.cc

Issue 6794050: Revert "[Arguments] Merge (7442,7496] from bleeding_edge." (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/arguments
Patch Set: Created 9 years, 8 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') | src/platform.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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 private: 82 private:
83 Element* top() { return top_; } 83 Element* top() { return top_; }
84 void set_top(Element* value) { top_ = value; } 84 void set_top(Element* value) { top_ = value; }
85 Element* top_; 85 Element* top_;
86 bool* ok_; 86 bool* ok_;
87 }; 87 };
88 88
89 89
90 RegExpBuilder::RegExpBuilder() 90 RegExpBuilder::RegExpBuilder()
91 : zone_(Isolate::Current()->zone()), 91 : pending_empty_(false),
92 pending_empty_(false), 92 characters_(NULL),
93 characters_(NULL), 93 terms_(),
94 terms_(), 94 alternatives_()
95 alternatives_()
96 #ifdef DEBUG 95 #ifdef DEBUG
97 , last_added_(ADD_NONE) 96 , last_added_(ADD_NONE)
98 #endif 97 #endif
99 {} 98 {}
100 99
101 100
102 void RegExpBuilder::FlushCharacters() { 101 void RegExpBuilder::FlushCharacters() {
103 pending_empty_ = false; 102 pending_empty_ = false;
104 if (characters_ != NULL) { 103 if (characters_ != NULL) {
105 RegExpTree* atom = new(zone()) RegExpAtom(characters_->ToConstVector()); 104 RegExpTree* atom = new RegExpAtom(characters_->ToConstVector());
106 characters_ = NULL; 105 characters_ = NULL;
107 text_.Add(atom); 106 text_.Add(atom);
108 LAST(ADD_ATOM); 107 LAST(ADD_ATOM);
109 } 108 }
110 } 109 }
111 110
112 111
113 void RegExpBuilder::FlushText() { 112 void RegExpBuilder::FlushText() {
114 FlushCharacters(); 113 FlushCharacters();
115 int num_text = text_.length(); 114 int num_text = text_.length();
116 if (num_text == 0) { 115 if (num_text == 0) {
117 return; 116 return;
118 } else if (num_text == 1) { 117 } else if (num_text == 1) {
119 terms_.Add(text_.last()); 118 terms_.Add(text_.last());
120 } else { 119 } else {
121 RegExpText* text = new(zone()) RegExpText(); 120 RegExpText* text = new RegExpText();
122 for (int i = 0; i < num_text; i++) 121 for (int i = 0; i < num_text; i++)
123 text_.Get(i)->AppendToText(text); 122 text_.Get(i)->AppendToText(text);
124 terms_.Add(text); 123 terms_.Add(text);
125 } 124 }
126 text_.Clear(); 125 text_.Clear();
127 } 126 }
128 127
129 128
130 void RegExpBuilder::AddCharacter(uc16 c) { 129 void RegExpBuilder::AddCharacter(uc16 c) {
131 pending_empty_ = false; 130 pending_empty_ = false;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 171
173 void RegExpBuilder::FlushTerms() { 172 void RegExpBuilder::FlushTerms() {
174 FlushText(); 173 FlushText();
175 int num_terms = terms_.length(); 174 int num_terms = terms_.length();
176 RegExpTree* alternative; 175 RegExpTree* alternative;
177 if (num_terms == 0) { 176 if (num_terms == 0) {
178 alternative = RegExpEmpty::GetInstance(); 177 alternative = RegExpEmpty::GetInstance();
179 } else if (num_terms == 1) { 178 } else if (num_terms == 1) {
180 alternative = terms_.last(); 179 alternative = terms_.last();
181 } else { 180 } else {
182 alternative = new(zone()) RegExpAlternative(terms_.GetList()); 181 alternative = new RegExpAlternative(terms_.GetList());
183 } 182 }
184 alternatives_.Add(alternative); 183 alternatives_.Add(alternative);
185 terms_.Clear(); 184 terms_.Clear();
186 LAST(ADD_NONE); 185 LAST(ADD_NONE);
187 } 186 }
188 187
189 188
190 RegExpTree* RegExpBuilder::ToRegExp() { 189 RegExpTree* RegExpBuilder::ToRegExp() {
191 FlushTerms(); 190 FlushTerms();
192 int num_alternatives = alternatives_.length(); 191 int num_alternatives = alternatives_.length();
193 if (num_alternatives == 0) { 192 if (num_alternatives == 0) {
194 return RegExpEmpty::GetInstance(); 193 return RegExpEmpty::GetInstance();
195 } 194 }
196 if (num_alternatives == 1) { 195 if (num_alternatives == 1) {
197 return alternatives_.last(); 196 return alternatives_.last();
198 } 197 }
199 return new(zone()) RegExpDisjunction(alternatives_.GetList()); 198 return new RegExpDisjunction(alternatives_.GetList());
200 } 199 }
201 200
202 201
203 void RegExpBuilder::AddQuantifierToAtom(int min, 202 void RegExpBuilder::AddQuantifierToAtom(int min,
204 int max, 203 int max,
205 RegExpQuantifier::Type type) { 204 RegExpQuantifier::Type type) {
206 if (pending_empty_) { 205 if (pending_empty_) {
207 pending_empty_ = false; 206 pending_empty_ = false;
208 return; 207 return;
209 } 208 }
210 RegExpTree* atom; 209 RegExpTree* atom;
211 if (characters_ != NULL) { 210 if (characters_ != NULL) {
212 ASSERT(last_added_ == ADD_CHAR); 211 ASSERT(last_added_ == ADD_CHAR);
213 // Last atom was character. 212 // Last atom was character.
214 Vector<const uc16> char_vector = characters_->ToConstVector(); 213 Vector<const uc16> char_vector = characters_->ToConstVector();
215 int num_chars = char_vector.length(); 214 int num_chars = char_vector.length();
216 if (num_chars > 1) { 215 if (num_chars > 1) {
217 Vector<const uc16> prefix = char_vector.SubVector(0, num_chars - 1); 216 Vector<const uc16> prefix = char_vector.SubVector(0, num_chars - 1);
218 text_.Add(new(zone()) RegExpAtom(prefix)); 217 text_.Add(new RegExpAtom(prefix));
219 char_vector = char_vector.SubVector(num_chars - 1, num_chars); 218 char_vector = char_vector.SubVector(num_chars - 1, num_chars);
220 } 219 }
221 characters_ = NULL; 220 characters_ = NULL;
222 atom = new(zone()) RegExpAtom(char_vector); 221 atom = new RegExpAtom(char_vector);
223 FlushText(); 222 FlushText();
224 } else if (text_.length() > 0) { 223 } else if (text_.length() > 0) {
225 ASSERT(last_added_ == ADD_ATOM); 224 ASSERT(last_added_ == ADD_ATOM);
226 atom = text_.RemoveLast(); 225 atom = text_.RemoveLast();
227 FlushText(); 226 FlushText();
228 } else if (terms_.length() > 0) { 227 } else if (terms_.length() > 0) {
229 ASSERT(last_added_ == ADD_ATOM); 228 ASSERT(last_added_ == ADD_ATOM);
230 atom = terms_.RemoveLast(); 229 atom = terms_.RemoveLast();
231 if (atom->max_match() == 0) { 230 if (atom->max_match() == 0) {
232 // Guaranteed to only match an empty string. 231 // Guaranteed to only match an empty string.
233 LAST(ADD_TERM); 232 LAST(ADD_TERM);
234 if (min == 0) { 233 if (min == 0) {
235 return; 234 return;
236 } 235 }
237 terms_.Add(atom); 236 terms_.Add(atom);
238 return; 237 return;
239 } 238 }
240 } else { 239 } else {
241 // Only call immediately after adding an atom or character! 240 // Only call immediately after adding an atom or character!
242 UNREACHABLE(); 241 UNREACHABLE();
243 return; 242 return;
244 } 243 }
245 terms_.Add(new(zone()) RegExpQuantifier(min, max, type, atom)); 244 terms_.Add(new RegExpQuantifier(min, max, type, atom));
246 LAST(ADD_TERM); 245 LAST(ADD_TERM);
247 } 246 }
248 247
249 248
250 Handle<String> Parser::LookupSymbol(int symbol_id) { 249 Handle<String> Parser::LookupSymbol(int symbol_id) {
251 // Length of symbol cache is the number of identified symbols. 250 // Length of symbol cache is the number of identified symbols.
252 // If we are larger than that, or negative, it's not a cached symbol. 251 // If we are larger than that, or negative, it's not a cached symbol.
253 // This might also happen if there is no preparser symbol data, even 252 // This might also happen if there is no preparser symbol data, even
254 // if there is some preparser data. 253 // if there is some preparser data.
255 if (static_cast<unsigned>(symbol_id) 254 if (static_cast<unsigned>(symbol_id)
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 return store_[PreparseDataConstants::kHeaderSize + position]; 401 return store_[PreparseDataConstants::kHeaderSize + position];
403 } 402 }
404 403
405 404
406 unsigned* ScriptDataImpl::ReadAddress(int position) { 405 unsigned* ScriptDataImpl::ReadAddress(int position) {
407 return &store_[PreparseDataConstants::kHeaderSize + position]; 406 return &store_[PreparseDataConstants::kHeaderSize + position];
408 } 407 }
409 408
410 409
411 Scope* Parser::NewScope(Scope* parent, Scope::Type type, bool inside_with) { 410 Scope* Parser::NewScope(Scope* parent, Scope::Type type, bool inside_with) {
412 Scope* result = new(zone()) Scope(parent, type); 411 Scope* result = new Scope(parent, type);
413 result->Initialize(inside_with); 412 result->Initialize(inside_with);
414 return result; 413 return result;
415 } 414 }
416 415
417 // ---------------------------------------------------------------------------- 416 // ----------------------------------------------------------------------------
418 // Target is a support class to facilitate manipulation of the 417 // Target is a support class to facilitate manipulation of the
419 // Parser's target_stack_ (the stack of potential 'break' and 418 // Parser's target_stack_ (the stack of potential 'break' and
420 // 'continue' statement targets). Upon construction, a new target is 419 // 'continue' statement targets). Upon construction, a new target is
421 // added; it is removed upon destruction. 420 // added; it is removed upon destruction.
422 421
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 } 594 }
596 595
597 596
598 FunctionLiteral* Parser::ParseProgram(Handle<String> source, 597 FunctionLiteral* Parser::ParseProgram(Handle<String> source,
599 bool in_global_context, 598 bool in_global_context,
600 StrictModeFlag strict_mode) { 599 StrictModeFlag strict_mode) {
601 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT); 600 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT);
602 601
603 HistogramTimerScope timer(isolate()->counters()->parse()); 602 HistogramTimerScope timer(isolate()->counters()->parse());
604 isolate()->counters()->total_parse_size()->Increment(source->length()); 603 isolate()->counters()->total_parse_size()->Increment(source->length());
605 fni_ = new(zone()) FuncNameInferrer(); 604 fni_ = new FuncNameInferrer();
606 605
607 // Initialize parser state. 606 // Initialize parser state.
608 source->TryFlatten(); 607 source->TryFlatten();
609 if (source->IsExternalTwoByteString()) { 608 if (source->IsExternalTwoByteString()) {
610 // Notice that the stream is destroyed at the end of the branch block. 609 // Notice that the stream is destroyed at the end of the branch block.
611 // The last line of the blocks can't be moved outside, even though they're 610 // The last line of the blocks can't be moved outside, even though they're
612 // identical calls. 611 // identical calls.
613 ExternalTwoByteStringUC16CharacterStream stream( 612 ExternalTwoByteStringUC16CharacterStream stream(
614 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); 613 Handle<ExternalTwoByteString>::cast(source), 0, source->length());
615 scanner_.Initialize(&stream); 614 scanner_.Initialize(&stream);
(...skipping 30 matching lines...) Expand all
646 top_scope_->EnableStrictMode(); 645 top_scope_->EnableStrictMode();
647 } 646 }
648 ZoneList<Statement*>* body = new ZoneList<Statement*>(16); 647 ZoneList<Statement*>* body = new ZoneList<Statement*>(16);
649 bool ok = true; 648 bool ok = true;
650 int beg_loc = scanner().location().beg_pos; 649 int beg_loc = scanner().location().beg_pos;
651 ParseSourceElements(body, Token::EOS, &ok); 650 ParseSourceElements(body, Token::EOS, &ok);
652 if (ok && top_scope_->is_strict_mode()) { 651 if (ok && top_scope_->is_strict_mode()) {
653 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); 652 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok);
654 } 653 }
655 if (ok) { 654 if (ok) {
656 result = new(zone()) FunctionLiteral( 655 result = new FunctionLiteral(
657 no_name, 656 no_name,
658 top_scope_, 657 top_scope_,
659 body, 658 body,
660 lexical_scope.materialized_literal_count(), 659 lexical_scope.materialized_literal_count(),
661 lexical_scope.expected_property_count(), 660 lexical_scope.expected_property_count(),
662 lexical_scope.only_simple_this_property_assignments(), 661 lexical_scope.only_simple_this_property_assignments(),
663 lexical_scope.this_property_assignments(), 662 lexical_scope.this_property_assignments(),
664 0, 663 0,
665 0, 664 0,
666 source->length(), 665 source->length(),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 706
708 707
709 FunctionLiteral* Parser::ParseLazy(CompilationInfo* info, 708 FunctionLiteral* Parser::ParseLazy(CompilationInfo* info,
710 UC16CharacterStream* source, 709 UC16CharacterStream* source,
711 ZoneScope* zone_scope) { 710 ZoneScope* zone_scope) {
712 Handle<SharedFunctionInfo> shared_info = info->shared_info(); 711 Handle<SharedFunctionInfo> shared_info = info->shared_info();
713 scanner_.Initialize(source); 712 scanner_.Initialize(source);
714 ASSERT(target_stack_ == NULL); 713 ASSERT(target_stack_ == NULL);
715 714
716 Handle<String> name(String::cast(shared_info->name())); 715 Handle<String> name(String::cast(shared_info->name()));
717 fni_ = new(zone()) FuncNameInferrer(); 716 fni_ = new FuncNameInferrer();
718 fni_->PushEnclosingName(name); 717 fni_->PushEnclosingName(name);
719 718
720 mode_ = PARSE_EAGERLY; 719 mode_ = PARSE_EAGERLY;
721 720
722 // Place holder for the result. 721 // Place holder for the result.
723 FunctionLiteral* result = NULL; 722 FunctionLiteral* result = NULL;
724 723
725 { 724 {
726 // Parse the function literal. 725 // Parse the function literal.
727 Handle<String> no_name = isolate()->factory()->empty_symbol(); 726 Handle<String> no_name = isolate()->factory()->empty_symbol();
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 case Token::THROW: 1245 case Token::THROW:
1247 stmt = ParseThrowStatement(ok); 1246 stmt = ParseThrowStatement(ok);
1248 break; 1247 break;
1249 1248
1250 case Token::TRY: { 1249 case Token::TRY: {
1251 // NOTE: It is somewhat complicated to have labels on 1250 // NOTE: It is somewhat complicated to have labels on
1252 // try-statements. When breaking out of a try-finally statement, 1251 // try-statements. When breaking out of a try-finally statement,
1253 // one must take great care not to treat it as a 1252 // one must take great care not to treat it as a
1254 // fall-through. It is much easier just to wrap the entire 1253 // fall-through. It is much easier just to wrap the entire
1255 // try-statement in a statement block and put the labels there 1254 // try-statement in a statement block and put the labels there
1256 Block* result = new(zone()) Block(labels, 1, false); 1255 Block* result = new Block(labels, 1, false);
1257 Target target(&this->target_stack_, result); 1256 Target target(&this->target_stack_, result);
1258 TryStatement* statement = ParseTryStatement(CHECK_OK); 1257 TryStatement* statement = ParseTryStatement(CHECK_OK);
1259 if (statement) { 1258 if (statement) {
1260 statement->set_statement_pos(statement_pos); 1259 statement->set_statement_pos(statement_pos);
1261 } 1260 }
1262 if (result) result->AddStatement(statement); 1261 if (result) result->AddStatement(statement);
1263 return result; 1262 return result;
1264 } 1263 }
1265 1264
1266 case Token::FUNCTION: { 1265 case Token::FUNCTION: {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 // parameters) if the proxy is needed or not. The proxy will be 1343 // parameters) if the proxy is needed or not. The proxy will be
1345 // bound during variable resolution time unless it was pre-bound 1344 // bound during variable resolution time unless it was pre-bound
1346 // below. 1345 // below.
1347 // 1346 //
1348 // WARNING: This will lead to multiple declaration nodes for the 1347 // WARNING: This will lead to multiple declaration nodes for the
1349 // same variable if it is declared several times. This is not a 1348 // same variable if it is declared several times. This is not a
1350 // semantic issue as long as we keep the source order, but it may be 1349 // semantic issue as long as we keep the source order, but it may be
1351 // a performance issue since it may lead to repeated 1350 // a performance issue since it may lead to repeated
1352 // Runtime::DeclareContextSlot() calls. 1351 // Runtime::DeclareContextSlot() calls.
1353 VariableProxy* proxy = top_scope_->NewUnresolved(name, inside_with()); 1352 VariableProxy* proxy = top_scope_->NewUnresolved(name, inside_with());
1354 top_scope_->AddDeclaration(new(zone()) Declaration(proxy, mode, fun)); 1353 top_scope_->AddDeclaration(new Declaration(proxy, mode, fun));
1355 1354
1356 // For global const variables we bind the proxy to a variable. 1355 // For global const variables we bind the proxy to a variable.
1357 if (mode == Variable::CONST && top_scope_->is_global_scope()) { 1356 if (mode == Variable::CONST && top_scope_->is_global_scope()) {
1358 ASSERT(resolve); // should be set by all callers 1357 ASSERT(resolve); // should be set by all callers
1359 Variable::Kind kind = Variable::NORMAL; 1358 Variable::Kind kind = Variable::NORMAL;
1360 var = new(zone()) Variable(top_scope_, name, Variable::CONST, true, kind); 1359 var = new Variable(top_scope_, name, Variable::CONST, true, kind);
1361 } 1360 }
1362 1361
1363 // If requested and we have a local variable, bind the proxy to the variable 1362 // If requested and we have a local variable, bind the proxy to the variable
1364 // at parse-time. This is used for functions (and consts) declared inside 1363 // at parse-time. This is used for functions (and consts) declared inside
1365 // statements: the corresponding function (or const) variable must be in the 1364 // statements: the corresponding function (or const) variable must be in the
1366 // function scope and not a statement-local scope, e.g. as provided with a 1365 // function scope and not a statement-local scope, e.g. as provided with a
1367 // 'with' statement: 1366 // 'with' statement:
1368 // 1367 //
1369 // with (obj) { 1368 // with (obj) {
1370 // function f() {} 1369 // function f() {}
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 shared->set_construct_stub(*construct_stub); 1437 shared->set_construct_stub(*construct_stub);
1439 1438
1440 // Copy the function data to the shared function info. 1439 // Copy the function data to the shared function info.
1441 shared->set_function_data(fun->shared()->function_data()); 1440 shared->set_function_data(fun->shared()->function_data());
1442 int parameters = fun->shared()->formal_parameter_count(); 1441 int parameters = fun->shared()->formal_parameter_count();
1443 shared->set_formal_parameter_count(parameters); 1442 shared->set_formal_parameter_count(parameters);
1444 1443
1445 // TODO(1240846): It's weird that native function declarations are 1444 // TODO(1240846): It's weird that native function declarations are
1446 // introduced dynamically when we meet their declarations, whereas 1445 // introduced dynamically when we meet their declarations, whereas
1447 // other functions are setup when entering the surrounding scope. 1446 // other functions are setup when entering the surrounding scope.
1448 SharedFunctionInfoLiteral* lit = 1447 SharedFunctionInfoLiteral* lit = new SharedFunctionInfoLiteral(shared);
1449 new(zone()) SharedFunctionInfoLiteral(shared);
1450 VariableProxy* var = Declare(name, Variable::VAR, NULL, true, CHECK_OK); 1448 VariableProxy* var = Declare(name, Variable::VAR, NULL, true, CHECK_OK);
1451 return new(zone()) ExpressionStatement(new(zone()) Assignment( 1449 return new ExpressionStatement(
1452 Token::INIT_VAR, var, lit, RelocInfo::kNoPosition)); 1450 new Assignment(Token::INIT_VAR, var, lit, RelocInfo::kNoPosition));
1453 } 1451 }
1454 1452
1455 1453
1456 Statement* Parser::ParseFunctionDeclaration(bool* ok) { 1454 Statement* Parser::ParseFunctionDeclaration(bool* ok) {
1457 // FunctionDeclaration :: 1455 // FunctionDeclaration ::
1458 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' 1456 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}'
1459 Expect(Token::FUNCTION, CHECK_OK); 1457 Expect(Token::FUNCTION, CHECK_OK);
1460 int function_token_position = scanner().location().beg_pos; 1458 int function_token_position = scanner().location().beg_pos;
1461 bool is_reserved = false; 1459 bool is_reserved = false;
1462 Handle<String> name = ParseIdentifierOrReservedWord(&is_reserved, CHECK_OK); 1460 Handle<String> name = ParseIdentifierOrReservedWord(&is_reserved, CHECK_OK);
(...skipping 11 matching lines...) Expand all
1474 1472
1475 1473
1476 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) { 1474 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) {
1477 // Block :: 1475 // Block ::
1478 // '{' Statement* '}' 1476 // '{' Statement* '}'
1479 1477
1480 // Note that a Block does not introduce a new execution scope! 1478 // Note that a Block does not introduce a new execution scope!
1481 // (ECMA-262, 3rd, 12.2) 1479 // (ECMA-262, 3rd, 12.2)
1482 // 1480 //
1483 // Construct block expecting 16 statements. 1481 // Construct block expecting 16 statements.
1484 Block* result = new(zone()) Block(labels, 16, false); 1482 Block* result = new Block(labels, 16, false);
1485 Target target(&this->target_stack_, result); 1483 Target target(&this->target_stack_, result);
1486 Expect(Token::LBRACE, CHECK_OK); 1484 Expect(Token::LBRACE, CHECK_OK);
1487 while (peek() != Token::RBRACE) { 1485 while (peek() != Token::RBRACE) {
1488 Statement* stat = ParseStatement(NULL, CHECK_OK); 1486 Statement* stat = ParseStatement(NULL, CHECK_OK);
1489 if (stat && !stat->IsEmpty()) result->AddStatement(stat); 1487 if (stat && !stat->IsEmpty()) result->AddStatement(stat);
1490 } 1488 }
1491 Expect(Token::RBRACE, CHECK_OK); 1489 Expect(Token::RBRACE, CHECK_OK);
1492 return result; 1490 return result;
1493 } 1491 }
1494 1492
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 // Scope declaration, and rewrite the source-level initialization into an 1542 // Scope declaration, and rewrite the source-level initialization into an
1545 // assignment statement. We use a block to collect multiple assignments. 1543 // assignment statement. We use a block to collect multiple assignments.
1546 // 1544 //
1547 // We mark the block as initializer block because we don't want the 1545 // We mark the block as initializer block because we don't want the
1548 // rewriter to add a '.result' assignment to such a block (to get compliant 1546 // rewriter to add a '.result' assignment to such a block (to get compliant
1549 // behavior for code such as print(eval('var x = 7')), and for cosmetic 1547 // behavior for code such as print(eval('var x = 7')), and for cosmetic
1550 // reasons when pretty-printing. Also, unless an assignment (initialization) 1548 // reasons when pretty-printing. Also, unless an assignment (initialization)
1551 // is inside an initializer block, it is ignored. 1549 // is inside an initializer block, it is ignored.
1552 // 1550 //
1553 // Create new block with one expected declaration. 1551 // Create new block with one expected declaration.
1554 Block* block = new(zone()) Block(NULL, 1, true); 1552 Block* block = new Block(NULL, 1, true);
1555 VariableProxy* last_var = NULL; // the last variable declared 1553 VariableProxy* last_var = NULL; // the last variable declared
1556 int nvars = 0; // the number of variables declared 1554 int nvars = 0; // the number of variables declared
1557 do { 1555 do {
1558 if (fni_ != NULL) fni_->Enter(); 1556 if (fni_ != NULL) fni_->Enter();
1559 1557
1560 // Parse variable name. 1558 // Parse variable name.
1561 if (nvars > 0) Consume(Token::COMMA); 1559 if (nvars > 0) Consume(Token::COMMA);
1562 Handle<String> name = ParseIdentifier(CHECK_OK); 1560 Handle<String> name = ParseIdentifier(CHECK_OK);
1563 if (fni_ != NULL) fni_->PushVariableName(name); 1561 if (fni_ != NULL) fni_->PushVariableName(name);
1564 1562
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1645 // variable defined in the global object and not in any 1643 // variable defined in the global object and not in any
1646 // prototype. This way, global variable declarations can shadow 1644 // prototype. This way, global variable declarations can shadow
1647 // properties in the prototype chain, but only after the variable 1645 // properties in the prototype chain, but only after the variable
1648 // declaration statement has been executed. This is important in 1646 // declaration statement has been executed. This is important in
1649 // browsers where the global object (window) has lots of 1647 // browsers where the global object (window) has lots of
1650 // properties defined in prototype objects. 1648 // properties defined in prototype objects.
1651 1649
1652 if (top_scope_->is_global_scope()) { 1650 if (top_scope_->is_global_scope()) {
1653 // Compute the arguments for the runtime call. 1651 // Compute the arguments for the runtime call.
1654 ZoneList<Expression*>* arguments = new ZoneList<Expression*>(3); 1652 ZoneList<Expression*>* arguments = new ZoneList<Expression*>(3);
1655 // We have at least 1 parameter. 1653 arguments->Add(new Literal(name)); // we have at least 1 parameter
1656 arguments->Add(new(zone()) Literal(name));
1657 CallRuntime* initialize; 1654 CallRuntime* initialize;
1658 1655
1659 if (is_const) { 1656 if (is_const) {
1660 arguments->Add(value); 1657 arguments->Add(value);
1661 value = NULL; // zap the value to avoid the unnecessary assignment 1658 value = NULL; // zap the value to avoid the unnecessary assignment
1662 1659
1663 // Construct the call to Runtime_InitializeConstGlobal 1660 // Construct the call to Runtime_InitializeConstGlobal
1664 // and add it to the initialization statement block. 1661 // and add it to the initialization statement block.
1665 // Note that the function does different things depending on 1662 // Note that the function does different things depending on
1666 // the number of arguments (1 or 2). 1663 // the number of arguments (1 or 2).
1667 initialize = 1664 initialize =
1668 new(zone()) CallRuntime( 1665 new CallRuntime(
1669 isolate()->factory()->InitializeConstGlobal_symbol(), 1666 isolate()->factory()->InitializeConstGlobal_symbol(),
1670 Runtime::FunctionForId(Runtime::kInitializeConstGlobal), 1667 Runtime::FunctionForId(Runtime::kInitializeConstGlobal),
1671 arguments); 1668 arguments);
1672 } else { 1669 } else {
1673 // Add strict mode. 1670 // Add strict mode.
1674 // We may want to pass singleton to avoid Literal allocations. 1671 // We may want to pass singleton to avoid Literal allocations.
1675 arguments->Add(NewNumberLiteral( 1672 arguments->Add(NewNumberLiteral(
1676 top_scope_->is_strict_mode() ? kStrictMode : kNonStrictMode)); 1673 top_scope_->is_strict_mode() ? kStrictMode : kNonStrictMode));
1677 1674
1678 // Be careful not to assign a value to the global variable if 1675 // Be careful not to assign a value to the global variable if
1679 // we're in a with. The initialization value should not 1676 // we're in a with. The initialization value should not
1680 // necessarily be stored in the global object in that case, 1677 // necessarily be stored in the global object in that case,
1681 // which is why we need to generate a separate assignment node. 1678 // which is why we need to generate a separate assignment node.
1682 if (value != NULL && !inside_with()) { 1679 if (value != NULL && !inside_with()) {
1683 arguments->Add(value); 1680 arguments->Add(value);
1684 value = NULL; // zap the value to avoid the unnecessary assignment 1681 value = NULL; // zap the value to avoid the unnecessary assignment
1685 } 1682 }
1686 1683
1687 // Construct the call to Runtime_InitializeVarGlobal 1684 // Construct the call to Runtime_InitializeVarGlobal
1688 // and add it to the initialization statement block. 1685 // and add it to the initialization statement block.
1689 // Note that the function does different things depending on 1686 // Note that the function does different things depending on
1690 // the number of arguments (2 or 3). 1687 // the number of arguments (2 or 3).
1691 initialize = 1688 initialize =
1692 new(zone()) CallRuntime( 1689 new CallRuntime(
1693 isolate()->factory()->InitializeVarGlobal_symbol(), 1690 isolate()->factory()->InitializeVarGlobal_symbol(),
1694 Runtime::FunctionForId(Runtime::kInitializeVarGlobal), 1691 Runtime::FunctionForId(Runtime::kInitializeVarGlobal),
1695 arguments); 1692 arguments);
1696 } 1693 }
1697 1694
1698 block->AddStatement(new(zone()) ExpressionStatement(initialize)); 1695 block->AddStatement(new ExpressionStatement(initialize));
1699 } 1696 }
1700 1697
1701 // Add an assignment node to the initialization statement block if 1698 // Add an assignment node to the initialization statement block if
1702 // we still have a pending initialization value. We must distinguish 1699 // we still have a pending initialization value. We must distinguish
1703 // between variables and constants: Variable initializations are simply 1700 // between variables and constants: Variable initializations are simply
1704 // assignments (with all the consequences if they are inside a 'with' 1701 // assignments (with all the consequences if they are inside a 'with'
1705 // statement - they may change a 'with' object property). Constant 1702 // statement - they may change a 'with' object property). Constant
1706 // initializations always assign to the declared constant which is 1703 // initializations always assign to the declared constant which is
1707 // always at the function scope level. This is only relevant for 1704 // always at the function scope level. This is only relevant for
1708 // dynamically looked-up variables and constants (the start context 1705 // dynamically looked-up variables and constants (the start context
1709 // for constant lookups is always the function context, while it is 1706 // for constant lookups is always the function context, while it is
1710 // the top context for variables). Sigh... 1707 // the top context for variables). Sigh...
1711 if (value != NULL) { 1708 if (value != NULL) {
1712 Token::Value op = (is_const ? Token::INIT_CONST : Token::INIT_VAR); 1709 Token::Value op = (is_const ? Token::INIT_CONST : Token::INIT_VAR);
1713 Assignment* assignment = 1710 Assignment* assignment = new Assignment(op, last_var, value, position);
1714 new(zone()) Assignment(op, last_var, value, position); 1711 if (block) block->AddStatement(new ExpressionStatement(assignment));
1715 if (block) {
1716 block->AddStatement(new(zone()) ExpressionStatement(assignment));
1717 }
1718 } 1712 }
1719 1713
1720 if (fni_ != NULL) fni_->Leave(); 1714 if (fni_ != NULL) fni_->Leave();
1721 } while (peek() == Token::COMMA); 1715 } while (peek() == Token::COMMA);
1722 1716
1723 if (!is_const && nvars == 1) { 1717 if (!is_const && nvars == 1) {
1724 // We have a single, non-const variable. 1718 // We have a single, non-const variable.
1725 ASSERT(last_var != NULL); 1719 ASSERT(last_var != NULL);
1726 *var = last_var; 1720 *var = last_var;
1727 } 1721 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1773 // Remove the "ghost" variable that turned out to be a label 1767 // Remove the "ghost" variable that turned out to be a label
1774 // from the top scope. This way, we don't try to resolve it 1768 // from the top scope. This way, we don't try to resolve it
1775 // during the scope processing. 1769 // during the scope processing.
1776 top_scope_->RemoveUnresolved(var); 1770 top_scope_->RemoveUnresolved(var);
1777 Expect(Token::COLON, CHECK_OK); 1771 Expect(Token::COLON, CHECK_OK);
1778 return ParseStatement(labels, ok); 1772 return ParseStatement(labels, ok);
1779 } 1773 }
1780 1774
1781 // Parsed expression statement. 1775 // Parsed expression statement.
1782 ExpectSemicolon(CHECK_OK); 1776 ExpectSemicolon(CHECK_OK);
1783 return new(zone()) ExpressionStatement(expr); 1777 return new ExpressionStatement(expr);
1784 } 1778 }
1785 1779
1786 1780
1787 IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) { 1781 IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) {
1788 // IfStatement :: 1782 // IfStatement ::
1789 // 'if' '(' Expression ')' Statement ('else' Statement)? 1783 // 'if' '(' Expression ')' Statement ('else' Statement)?
1790 1784
1791 Expect(Token::IF, CHECK_OK); 1785 Expect(Token::IF, CHECK_OK);
1792 Expect(Token::LPAREN, CHECK_OK); 1786 Expect(Token::LPAREN, CHECK_OK);
1793 Expression* condition = ParseExpression(true, CHECK_OK); 1787 Expression* condition = ParseExpression(true, CHECK_OK);
1794 Expect(Token::RPAREN, CHECK_OK); 1788 Expect(Token::RPAREN, CHECK_OK);
1795 Statement* then_statement = ParseStatement(labels, CHECK_OK); 1789 Statement* then_statement = ParseStatement(labels, CHECK_OK);
1796 Statement* else_statement = NULL; 1790 Statement* else_statement = NULL;
1797 if (peek() == Token::ELSE) { 1791 if (peek() == Token::ELSE) {
1798 Next(); 1792 Next();
1799 else_statement = ParseStatement(labels, CHECK_OK); 1793 else_statement = ParseStatement(labels, CHECK_OK);
1800 } else { 1794 } else {
1801 else_statement = EmptyStatement(); 1795 else_statement = EmptyStatement();
1802 } 1796 }
1803 return new(zone()) IfStatement(condition, then_statement, else_statement); 1797 return new IfStatement(condition, then_statement, else_statement);
1804 } 1798 }
1805 1799
1806 1800
1807 Statement* Parser::ParseContinueStatement(bool* ok) { 1801 Statement* Parser::ParseContinueStatement(bool* ok) {
1808 // ContinueStatement :: 1802 // ContinueStatement ::
1809 // 'continue' Identifier? ';' 1803 // 'continue' Identifier? ';'
1810 1804
1811 Expect(Token::CONTINUE, CHECK_OK); 1805 Expect(Token::CONTINUE, CHECK_OK);
1812 Handle<String> label = Handle<String>::null(); 1806 Handle<String> label = Handle<String>::null();
1813 Token::Value tok = peek(); 1807 Token::Value tok = peek();
1814 if (!scanner().has_line_terminator_before_next() && 1808 if (!scanner().has_line_terminator_before_next() &&
1815 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { 1809 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) {
1816 label = ParseIdentifier(CHECK_OK); 1810 label = ParseIdentifier(CHECK_OK);
1817 } 1811 }
1818 IterationStatement* target = NULL; 1812 IterationStatement* target = NULL;
1819 target = LookupContinueTarget(label, CHECK_OK); 1813 target = LookupContinueTarget(label, CHECK_OK);
1820 if (target == NULL) { 1814 if (target == NULL) {
1821 // Illegal continue statement. 1815 // Illegal continue statement.
1822 const char* message = "illegal_continue"; 1816 const char* message = "illegal_continue";
1823 Vector<Handle<String> > args; 1817 Vector<Handle<String> > args;
1824 if (!label.is_null()) { 1818 if (!label.is_null()) {
1825 message = "unknown_label"; 1819 message = "unknown_label";
1826 args = Vector<Handle<String> >(&label, 1); 1820 args = Vector<Handle<String> >(&label, 1);
1827 } 1821 }
1828 ReportMessageAt(scanner().location(), message, args); 1822 ReportMessageAt(scanner().location(), message, args);
1829 *ok = false; 1823 *ok = false;
1830 return NULL; 1824 return NULL;
1831 } 1825 }
1832 ExpectSemicolon(CHECK_OK); 1826 ExpectSemicolon(CHECK_OK);
1833 return new(zone()) ContinueStatement(target); 1827 return new ContinueStatement(target);
1834 } 1828 }
1835 1829
1836 1830
1837 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { 1831 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) {
1838 // BreakStatement :: 1832 // BreakStatement ::
1839 // 'break' Identifier? ';' 1833 // 'break' Identifier? ';'
1840 1834
1841 Expect(Token::BREAK, CHECK_OK); 1835 Expect(Token::BREAK, CHECK_OK);
1842 Handle<String> label; 1836 Handle<String> label;
1843 Token::Value tok = peek(); 1837 Token::Value tok = peek();
(...skipping 14 matching lines...) Expand all
1858 Vector<Handle<String> > args; 1852 Vector<Handle<String> > args;
1859 if (!label.is_null()) { 1853 if (!label.is_null()) {
1860 message = "unknown_label"; 1854 message = "unknown_label";
1861 args = Vector<Handle<String> >(&label, 1); 1855 args = Vector<Handle<String> >(&label, 1);
1862 } 1856 }
1863 ReportMessageAt(scanner().location(), message, args); 1857 ReportMessageAt(scanner().location(), message, args);
1864 *ok = false; 1858 *ok = false;
1865 return NULL; 1859 return NULL;
1866 } 1860 }
1867 ExpectSemicolon(CHECK_OK); 1861 ExpectSemicolon(CHECK_OK);
1868 return new(zone()) BreakStatement(target); 1862 return new BreakStatement(target);
1869 } 1863 }
1870 1864
1871 1865
1872 Statement* Parser::ParseReturnStatement(bool* ok) { 1866 Statement* Parser::ParseReturnStatement(bool* ok) {
1873 // ReturnStatement :: 1867 // ReturnStatement ::
1874 // 'return' Expression? ';' 1868 // 'return' Expression? ';'
1875 1869
1876 // Consume the return token. It is necessary to do the before 1870 // Consume the return token. It is necessary to do the before
1877 // reporting any errors on it, because of the way errors are 1871 // reporting any errors on it, because of the way errors are
1878 // reported (underlining). 1872 // reported (underlining).
1879 Expect(Token::RETURN, CHECK_OK); 1873 Expect(Token::RETURN, CHECK_OK);
1880 1874
1881 // An ECMAScript program is considered syntactically incorrect if it 1875 // An ECMAScript program is considered syntactically incorrect if it
1882 // contains a return statement that is not within the body of a 1876 // contains a return statement that is not within the body of a
1883 // function. See ECMA-262, section 12.9, page 67. 1877 // function. See ECMA-262, section 12.9, page 67.
1884 // 1878 //
1885 // To be consistent with KJS we report the syntax error at runtime. 1879 // To be consistent with KJS we report the syntax error at runtime.
1886 if (!top_scope_->is_function_scope()) { 1880 if (!top_scope_->is_function_scope()) {
1887 Handle<String> type = isolate()->factory()->illegal_return_symbol(); 1881 Handle<String> type = isolate()->factory()->illegal_return_symbol();
1888 Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null()); 1882 Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null());
1889 return new(zone()) ExpressionStatement(throw_error); 1883 return new ExpressionStatement(throw_error);
1890 } 1884 }
1891 1885
1892 Token::Value tok = peek(); 1886 Token::Value tok = peek();
1893 if (scanner().has_line_terminator_before_next() || 1887 if (scanner().has_line_terminator_before_next() ||
1894 tok == Token::SEMICOLON || 1888 tok == Token::SEMICOLON ||
1895 tok == Token::RBRACE || 1889 tok == Token::RBRACE ||
1896 tok == Token::EOS) { 1890 tok == Token::EOS) {
1897 ExpectSemicolon(CHECK_OK); 1891 ExpectSemicolon(CHECK_OK);
1898 return new(zone()) ReturnStatement(GetLiteralUndefined()); 1892 return new ReturnStatement(GetLiteralUndefined());
1899 } 1893 }
1900 1894
1901 Expression* expr = ParseExpression(true, CHECK_OK); 1895 Expression* expr = ParseExpression(true, CHECK_OK);
1902 ExpectSemicolon(CHECK_OK); 1896 ExpectSemicolon(CHECK_OK);
1903 return new(zone()) ReturnStatement(expr); 1897 return new ReturnStatement(expr);
1904 } 1898 }
1905 1899
1906 1900
1907 Block* Parser::WithHelper(Expression* obj, 1901 Block* Parser::WithHelper(Expression* obj,
1908 ZoneStringList* labels, 1902 ZoneStringList* labels,
1909 bool is_catch_block, 1903 bool is_catch_block,
1910 bool* ok) { 1904 bool* ok) {
1911 // Parse the statement and collect escaping labels. 1905 // Parse the statement and collect escaping labels.
1912 ZoneList<BreakTarget*>* target_list = new ZoneList<BreakTarget*>(0); 1906 ZoneList<BreakTarget*>* target_list = new ZoneList<BreakTarget*>(0);
1913 TargetCollector collector(target_list); 1907 TargetCollector collector(target_list);
1914 Statement* stat; 1908 Statement* stat;
1915 { Target target(&this->target_stack_, &collector); 1909 { Target target(&this->target_stack_, &collector);
1916 with_nesting_level_++; 1910 with_nesting_level_++;
1917 top_scope_->RecordWithStatement(); 1911 top_scope_->RecordWithStatement();
1918 stat = ParseStatement(labels, CHECK_OK); 1912 stat = ParseStatement(labels, CHECK_OK);
1919 with_nesting_level_--; 1913 with_nesting_level_--;
1920 } 1914 }
1921 // Create resulting block with two statements. 1915 // Create resulting block with two statements.
1922 // 1: Evaluate the with expression. 1916 // 1: Evaluate the with expression.
1923 // 2: The try-finally block evaluating the body. 1917 // 2: The try-finally block evaluating the body.
1924 Block* result = new(zone()) Block(NULL, 2, false); 1918 Block* result = new Block(NULL, 2, false);
1925 1919
1926 if (result != NULL) { 1920 if (result != NULL) {
1927 result->AddStatement(new(zone()) WithEnterStatement(obj, is_catch_block)); 1921 result->AddStatement(new WithEnterStatement(obj, is_catch_block));
1928 1922
1929 // Create body block. 1923 // Create body block.
1930 Block* body = new(zone()) Block(NULL, 1, false); 1924 Block* body = new Block(NULL, 1, false);
1931 body->AddStatement(stat); 1925 body->AddStatement(stat);
1932 1926
1933 // Create exit block. 1927 // Create exit block.
1934 Block* exit = new(zone()) Block(NULL, 1, false); 1928 Block* exit = new Block(NULL, 1, false);
1935 exit->AddStatement(new(zone()) WithExitStatement()); 1929 exit->AddStatement(new WithExitStatement());
1936 1930
1937 // Return a try-finally statement. 1931 // Return a try-finally statement.
1938 TryFinallyStatement* wrapper = new(zone()) TryFinallyStatement(body, exit); 1932 TryFinallyStatement* wrapper = new TryFinallyStatement(body, exit);
1939 wrapper->set_escaping_targets(collector.targets()); 1933 wrapper->set_escaping_targets(collector.targets());
1940 result->AddStatement(wrapper); 1934 result->AddStatement(wrapper);
1941 } 1935 }
1942 return result; 1936 return result;
1943 } 1937 }
1944 1938
1945 1939
1946 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { 1940 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) {
1947 // WithStatement :: 1941 // WithStatement ::
1948 // 'with' '(' Expression ')' Statement 1942 // 'with' '(' Expression ')' Statement
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1985 Expect(Token::COLON, CHECK_OK); 1979 Expect(Token::COLON, CHECK_OK);
1986 int pos = scanner().location().beg_pos; 1980 int pos = scanner().location().beg_pos;
1987 ZoneList<Statement*>* statements = new ZoneList<Statement*>(5); 1981 ZoneList<Statement*>* statements = new ZoneList<Statement*>(5);
1988 while (peek() != Token::CASE && 1982 while (peek() != Token::CASE &&
1989 peek() != Token::DEFAULT && 1983 peek() != Token::DEFAULT &&
1990 peek() != Token::RBRACE) { 1984 peek() != Token::RBRACE) {
1991 Statement* stat = ParseStatement(NULL, CHECK_OK); 1985 Statement* stat = ParseStatement(NULL, CHECK_OK);
1992 statements->Add(stat); 1986 statements->Add(stat);
1993 } 1987 }
1994 1988
1995 return new(zone()) CaseClause(label, statements, pos); 1989 return new CaseClause(label, statements, pos);
1996 } 1990 }
1997 1991
1998 1992
1999 SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels, 1993 SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels,
2000 bool* ok) { 1994 bool* ok) {
2001 // SwitchStatement :: 1995 // SwitchStatement ::
2002 // 'switch' '(' Expression ')' '{' CaseClause* '}' 1996 // 'switch' '(' Expression ')' '{' CaseClause* '}'
2003 1997
2004 SwitchStatement* statement = new(zone()) SwitchStatement(labels); 1998 SwitchStatement* statement = new SwitchStatement(labels);
2005 Target target(&this->target_stack_, statement); 1999 Target target(&this->target_stack_, statement);
2006 2000
2007 Expect(Token::SWITCH, CHECK_OK); 2001 Expect(Token::SWITCH, CHECK_OK);
2008 Expect(Token::LPAREN, CHECK_OK); 2002 Expect(Token::LPAREN, CHECK_OK);
2009 Expression* tag = ParseExpression(true, CHECK_OK); 2003 Expression* tag = ParseExpression(true, CHECK_OK);
2010 Expect(Token::RPAREN, CHECK_OK); 2004 Expect(Token::RPAREN, CHECK_OK);
2011 2005
2012 bool default_seen = false; 2006 bool default_seen = false;
2013 ZoneList<CaseClause*>* cases = new ZoneList<CaseClause*>(4); 2007 ZoneList<CaseClause*>* cases = new ZoneList<CaseClause*>(4);
2014 Expect(Token::LBRACE, CHECK_OK); 2008 Expect(Token::LBRACE, CHECK_OK);
(...skipping 15 matching lines...) Expand all
2030 Expect(Token::THROW, CHECK_OK); 2024 Expect(Token::THROW, CHECK_OK);
2031 int pos = scanner().location().beg_pos; 2025 int pos = scanner().location().beg_pos;
2032 if (scanner().has_line_terminator_before_next()) { 2026 if (scanner().has_line_terminator_before_next()) {
2033 ReportMessage("newline_after_throw", Vector<const char*>::empty()); 2027 ReportMessage("newline_after_throw", Vector<const char*>::empty());
2034 *ok = false; 2028 *ok = false;
2035 return NULL; 2029 return NULL;
2036 } 2030 }
2037 Expression* exception = ParseExpression(true, CHECK_OK); 2031 Expression* exception = ParseExpression(true, CHECK_OK);
2038 ExpectSemicolon(CHECK_OK); 2032 ExpectSemicolon(CHECK_OK);
2039 2033
2040 return new(zone()) ExpressionStatement(new(zone()) Throw(exception, pos)); 2034 return new ExpressionStatement(new Throw(exception, pos));
2041 } 2035 }
2042 2036
2043 2037
2044 TryStatement* Parser::ParseTryStatement(bool* ok) { 2038 TryStatement* Parser::ParseTryStatement(bool* ok) {
2045 // TryStatement :: 2039 // TryStatement ::
2046 // 'try' Block Catch 2040 // 'try' Block Catch
2047 // 'try' Block Finally 2041 // 'try' Block Finally
2048 // 'try' Block Catch Finally 2042 // 'try' Block Catch Finally
2049 // 2043 //
2050 // Catch :: 2044 // Catch ::
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2094 return NULL; 2088 return NULL;
2095 } 2089 }
2096 2090
2097 Expect(Token::RPAREN, CHECK_OK); 2091 Expect(Token::RPAREN, CHECK_OK);
2098 2092
2099 if (peek() == Token::LBRACE) { 2093 if (peek() == Token::LBRACE) {
2100 // Allocate a temporary for holding the finally state while 2094 // Allocate a temporary for holding the finally state while
2101 // executing the finally block. 2095 // executing the finally block.
2102 catch_var = 2096 catch_var =
2103 top_scope_->NewTemporary(isolate()->factory()->catch_var_symbol()); 2097 top_scope_->NewTemporary(isolate()->factory()->catch_var_symbol());
2104 Literal* name_literal = new(zone()) Literal(name); 2098 Literal* name_literal = new Literal(name);
2105 VariableProxy* catch_var_use = new(zone()) VariableProxy(catch_var); 2099 VariableProxy* catch_var_use = new VariableProxy(catch_var);
2106 Expression* obj = 2100 Expression* obj = new CatchExtensionObject(name_literal, catch_var_use);
2107 new(zone()) CatchExtensionObject(name_literal, catch_var_use);
2108 { Target target(&this->target_stack_, &catch_collector); 2101 { Target target(&this->target_stack_, &catch_collector);
2109 catch_block = WithHelper(obj, NULL, true, CHECK_OK); 2102 catch_block = WithHelper(obj, NULL, true, CHECK_OK);
2110 } 2103 }
2111 } else { 2104 } else {
2112 Expect(Token::LBRACE, CHECK_OK); 2105 Expect(Token::LBRACE, CHECK_OK);
2113 } 2106 }
2114 2107
2115 tok = peek(); 2108 tok = peek();
2116 } 2109 }
2117 2110
2118 if (tok == Token::FINALLY || !has_catch) { 2111 if (tok == Token::FINALLY || !has_catch) {
2119 Consume(Token::FINALLY); 2112 Consume(Token::FINALLY);
2120 // Declare a variable for holding the finally state while 2113 // Declare a variable for holding the finally state while
2121 // executing the finally block. 2114 // executing the finally block.
2122 finally_block = ParseBlock(NULL, CHECK_OK); 2115 finally_block = ParseBlock(NULL, CHECK_OK);
2123 } 2116 }
2124 2117
2125 // Simplify the AST nodes by converting: 2118 // Simplify the AST nodes by converting:
2126 // 'try { } catch { } finally { }' 2119 // 'try { } catch { } finally { }'
2127 // to: 2120 // to:
2128 // 'try { try { } catch { } } finally { }' 2121 // 'try { try { } catch { } } finally { }'
2129 2122
2130 if (catch_block != NULL && finally_block != NULL) { 2123 if (catch_block != NULL && finally_block != NULL) {
2131 VariableProxy* catch_var_defn = new(zone()) VariableProxy(catch_var); 2124 VariableProxy* catch_var_defn = new VariableProxy(catch_var);
2132 TryCatchStatement* statement = 2125 TryCatchStatement* statement =
2133 new(zone()) TryCatchStatement(try_block, catch_var_defn, catch_block); 2126 new TryCatchStatement(try_block, catch_var_defn, catch_block);
2134 statement->set_escaping_targets(collector.targets()); 2127 statement->set_escaping_targets(collector.targets());
2135 try_block = new(zone()) Block(NULL, 1, false); 2128 try_block = new Block(NULL, 1, false);
2136 try_block->AddStatement(statement); 2129 try_block->AddStatement(statement);
2137 catch_block = NULL; 2130 catch_block = NULL;
2138 } 2131 }
2139 2132
2140 TryStatement* result = NULL; 2133 TryStatement* result = NULL;
2141 if (catch_block != NULL) { 2134 if (catch_block != NULL) {
2142 ASSERT(finally_block == NULL); 2135 ASSERT(finally_block == NULL);
2143 VariableProxy* catch_var_defn = new(zone()) VariableProxy(catch_var); 2136 VariableProxy* catch_var_defn = new VariableProxy(catch_var);
2144 result = 2137 result = new TryCatchStatement(try_block, catch_var_defn, catch_block);
2145 new(zone()) TryCatchStatement(try_block, catch_var_defn, catch_block);
2146 result->set_escaping_targets(collector.targets()); 2138 result->set_escaping_targets(collector.targets());
2147 } else { 2139 } else {
2148 ASSERT(finally_block != NULL); 2140 ASSERT(finally_block != NULL);
2149 result = new(zone()) TryFinallyStatement(try_block, finally_block); 2141 result = new TryFinallyStatement(try_block, finally_block);
2150 // Add the jump targets of the try block and the catch block. 2142 // Add the jump targets of the try block and the catch block.
2151 for (int i = 0; i < collector.targets()->length(); i++) { 2143 for (int i = 0; i < collector.targets()->length(); i++) {
2152 catch_collector.AddTarget(collector.targets()->at(i)); 2144 catch_collector.AddTarget(collector.targets()->at(i));
2153 } 2145 }
2154 result->set_escaping_targets(catch_collector.targets()); 2146 result->set_escaping_targets(catch_collector.targets());
2155 } 2147 }
2156 2148
2157 return result; 2149 return result;
2158 } 2150 }
2159 2151
2160 2152
2161 DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels, 2153 DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels,
2162 bool* ok) { 2154 bool* ok) {
2163 // DoStatement :: 2155 // DoStatement ::
2164 // 'do' Statement 'while' '(' Expression ')' ';' 2156 // 'do' Statement 'while' '(' Expression ')' ';'
2165 2157
2166 lexical_scope_->AddLoop(); 2158 lexical_scope_->AddLoop();
2167 DoWhileStatement* loop = new(zone()) DoWhileStatement(labels); 2159 DoWhileStatement* loop = new DoWhileStatement(labels);
2168 Target target(&this->target_stack_, loop); 2160 Target target(&this->target_stack_, loop);
2169 2161
2170 Expect(Token::DO, CHECK_OK); 2162 Expect(Token::DO, CHECK_OK);
2171 Statement* body = ParseStatement(NULL, CHECK_OK); 2163 Statement* body = ParseStatement(NULL, CHECK_OK);
2172 Expect(Token::WHILE, CHECK_OK); 2164 Expect(Token::WHILE, CHECK_OK);
2173 Expect(Token::LPAREN, CHECK_OK); 2165 Expect(Token::LPAREN, CHECK_OK);
2174 2166
2175 if (loop != NULL) { 2167 if (loop != NULL) {
2176 int position = scanner().location().beg_pos; 2168 int position = scanner().location().beg_pos;
2177 loop->set_condition_position(position); 2169 loop->set_condition_position(position);
(...skipping 12 matching lines...) Expand all
2190 if (loop != NULL) loop->Initialize(cond, body); 2182 if (loop != NULL) loop->Initialize(cond, body);
2191 return loop; 2183 return loop;
2192 } 2184 }
2193 2185
2194 2186
2195 WhileStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) { 2187 WhileStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) {
2196 // WhileStatement :: 2188 // WhileStatement ::
2197 // 'while' '(' Expression ')' Statement 2189 // 'while' '(' Expression ')' Statement
2198 2190
2199 lexical_scope_->AddLoop(); 2191 lexical_scope_->AddLoop();
2200 WhileStatement* loop = new(zone()) WhileStatement(labels); 2192 WhileStatement* loop = new WhileStatement(labels);
2201 Target target(&this->target_stack_, loop); 2193 Target target(&this->target_stack_, loop);
2202 2194
2203 Expect(Token::WHILE, CHECK_OK); 2195 Expect(Token::WHILE, CHECK_OK);
2204 Expect(Token::LPAREN, CHECK_OK); 2196 Expect(Token::LPAREN, CHECK_OK);
2205 Expression* cond = ParseExpression(true, CHECK_OK); 2197 Expression* cond = ParseExpression(true, CHECK_OK);
2206 if (cond != NULL) cond->set_is_loop_condition(true); 2198 if (cond != NULL) cond->set_is_loop_condition(true);
2207 Expect(Token::RPAREN, CHECK_OK); 2199 Expect(Token::RPAREN, CHECK_OK);
2208 Statement* body = ParseStatement(NULL, CHECK_OK); 2200 Statement* body = ParseStatement(NULL, CHECK_OK);
2209 2201
2210 if (loop != NULL) loop->Initialize(cond, body); 2202 if (loop != NULL) loop->Initialize(cond, body);
2211 return loop; 2203 return loop;
2212 } 2204 }
2213 2205
2214 2206
2215 Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { 2207 Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
2216 // ForStatement :: 2208 // ForStatement ::
2217 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement 2209 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement
2218 2210
2219 lexical_scope_->AddLoop(); 2211 lexical_scope_->AddLoop();
2220 Statement* init = NULL; 2212 Statement* init = NULL;
2221 2213
2222 Expect(Token::FOR, CHECK_OK); 2214 Expect(Token::FOR, CHECK_OK);
2223 Expect(Token::LPAREN, CHECK_OK); 2215 Expect(Token::LPAREN, CHECK_OK);
2224 if (peek() != Token::SEMICOLON) { 2216 if (peek() != Token::SEMICOLON) {
2225 if (peek() == Token::VAR || peek() == Token::CONST) { 2217 if (peek() == Token::VAR || peek() == Token::CONST) {
2226 Expression* each = NULL; 2218 Expression* each = NULL;
2227 Block* variable_statement = 2219 Block* variable_statement =
2228 ParseVariableDeclarations(false, &each, CHECK_OK); 2220 ParseVariableDeclarations(false, &each, CHECK_OK);
2229 if (peek() == Token::IN && each != NULL) { 2221 if (peek() == Token::IN && each != NULL) {
2230 ForInStatement* loop = new(zone()) ForInStatement(labels); 2222 ForInStatement* loop = new ForInStatement(labels);
2231 Target target(&this->target_stack_, loop); 2223 Target target(&this->target_stack_, loop);
2232 2224
2233 Expect(Token::IN, CHECK_OK); 2225 Expect(Token::IN, CHECK_OK);
2234 Expression* enumerable = ParseExpression(true, CHECK_OK); 2226 Expression* enumerable = ParseExpression(true, CHECK_OK);
2235 Expect(Token::RPAREN, CHECK_OK); 2227 Expect(Token::RPAREN, CHECK_OK);
2236 2228
2237 Statement* body = ParseStatement(NULL, CHECK_OK); 2229 Statement* body = ParseStatement(NULL, CHECK_OK);
2238 loop->Initialize(each, enumerable, body); 2230 loop->Initialize(each, enumerable, body);
2239 Block* result = new(zone()) Block(NULL, 2, false); 2231 Block* result = new Block(NULL, 2, false);
2240 result->AddStatement(variable_statement); 2232 result->AddStatement(variable_statement);
2241 result->AddStatement(loop); 2233 result->AddStatement(loop);
2242 // Parsed for-in loop w/ variable/const declaration. 2234 // Parsed for-in loop w/ variable/const declaration.
2243 return result; 2235 return result;
2244 } else { 2236 } else {
2245 init = variable_statement; 2237 init = variable_statement;
2246 } 2238 }
2247 2239
2248 } else { 2240 } else {
2249 Expression* expression = ParseExpression(false, CHECK_OK); 2241 Expression* expression = ParseExpression(false, CHECK_OK);
2250 if (peek() == Token::IN) { 2242 if (peek() == Token::IN) {
2251 // Signal a reference error if the expression is an invalid 2243 // Signal a reference error if the expression is an invalid
2252 // left-hand side expression. We could report this as a syntax 2244 // left-hand side expression. We could report this as a syntax
2253 // error here but for compatibility with JSC we choose to report 2245 // error here but for compatibility with JSC we choose to report
2254 // the error at runtime. 2246 // the error at runtime.
2255 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2247 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2256 Handle<String> type = 2248 Handle<String> type =
2257 isolate()->factory()->invalid_lhs_in_for_in_symbol(); 2249 isolate()->factory()->invalid_lhs_in_for_in_symbol();
2258 expression = NewThrowReferenceError(type); 2250 expression = NewThrowReferenceError(type);
2259 } 2251 }
2260 ForInStatement* loop = new(zone()) ForInStatement(labels); 2252 ForInStatement* loop = new ForInStatement(labels);
2261 Target target(&this->target_stack_, loop); 2253 Target target(&this->target_stack_, loop);
2262 2254
2263 Expect(Token::IN, CHECK_OK); 2255 Expect(Token::IN, CHECK_OK);
2264 Expression* enumerable = ParseExpression(true, CHECK_OK); 2256 Expression* enumerable = ParseExpression(true, CHECK_OK);
2265 Expect(Token::RPAREN, CHECK_OK); 2257 Expect(Token::RPAREN, CHECK_OK);
2266 2258
2267 Statement* body = ParseStatement(NULL, CHECK_OK); 2259 Statement* body = ParseStatement(NULL, CHECK_OK);
2268 if (loop) loop->Initialize(expression, enumerable, body); 2260 if (loop) loop->Initialize(expression, enumerable, body);
2269 // Parsed for-in loop. 2261 // Parsed for-in loop.
2270 return loop; 2262 return loop;
2271 2263
2272 } else { 2264 } else {
2273 init = new(zone()) ExpressionStatement(expression); 2265 init = new ExpressionStatement(expression);
2274 } 2266 }
2275 } 2267 }
2276 } 2268 }
2277 2269
2278 // Standard 'for' loop 2270 // Standard 'for' loop
2279 ForStatement* loop = new(zone()) ForStatement(labels); 2271 ForStatement* loop = new ForStatement(labels);
2280 Target target(&this->target_stack_, loop); 2272 Target target(&this->target_stack_, loop);
2281 2273
2282 // Parsed initializer at this point. 2274 // Parsed initializer at this point.
2283 Expect(Token::SEMICOLON, CHECK_OK); 2275 Expect(Token::SEMICOLON, CHECK_OK);
2284 2276
2285 Expression* cond = NULL; 2277 Expression* cond = NULL;
2286 if (peek() != Token::SEMICOLON) { 2278 if (peek() != Token::SEMICOLON) {
2287 cond = ParseExpression(true, CHECK_OK); 2279 cond = ParseExpression(true, CHECK_OK);
2288 if (cond != NULL) cond->set_is_loop_condition(true); 2280 if (cond != NULL) cond->set_is_loop_condition(true);
2289 } 2281 }
2290 Expect(Token::SEMICOLON, CHECK_OK); 2282 Expect(Token::SEMICOLON, CHECK_OK);
2291 2283
2292 Statement* next = NULL; 2284 Statement* next = NULL;
2293 if (peek() != Token::RPAREN) { 2285 if (peek() != Token::RPAREN) {
2294 Expression* exp = ParseExpression(true, CHECK_OK); 2286 Expression* exp = ParseExpression(true, CHECK_OK);
2295 next = new(zone()) ExpressionStatement(exp); 2287 next = new ExpressionStatement(exp);
2296 } 2288 }
2297 Expect(Token::RPAREN, CHECK_OK); 2289 Expect(Token::RPAREN, CHECK_OK);
2298 2290
2299 Statement* body = ParseStatement(NULL, CHECK_OK); 2291 Statement* body = ParseStatement(NULL, CHECK_OK);
2300 if (loop) loop->Initialize(init, cond, next, body); 2292 if (loop) loop->Initialize(init, cond, next, body);
2301 return loop; 2293 return loop;
2302 } 2294 }
2303 2295
2304 2296
2305 // Precedence = 1 2297 // Precedence = 1
2306 Expression* Parser::ParseExpression(bool accept_IN, bool* ok) { 2298 Expression* Parser::ParseExpression(bool accept_IN, bool* ok) {
2307 // Expression :: 2299 // Expression ::
2308 // AssignmentExpression 2300 // AssignmentExpression
2309 // Expression ',' AssignmentExpression 2301 // Expression ',' AssignmentExpression
2310 2302
2311 Expression* result = ParseAssignmentExpression(accept_IN, CHECK_OK); 2303 Expression* result = ParseAssignmentExpression(accept_IN, CHECK_OK);
2312 while (peek() == Token::COMMA) { 2304 while (peek() == Token::COMMA) {
2313 Expect(Token::COMMA, CHECK_OK); 2305 Expect(Token::COMMA, CHECK_OK);
2314 int position = scanner().location().beg_pos; 2306 int position = scanner().location().beg_pos;
2315 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); 2307 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
2316 result = new(zone()) BinaryOperation(Token::COMMA, result, right, position); 2308 result = new BinaryOperation(Token::COMMA, result, right, position);
2317 } 2309 }
2318 return result; 2310 return result;
2319 } 2311 }
2320 2312
2321 2313
2322 // Precedence = 2 2314 // Precedence = 2
2323 Expression* Parser::ParseAssignmentExpression(bool accept_IN, bool* ok) { 2315 Expression* Parser::ParseAssignmentExpression(bool accept_IN, bool* ok) {
2324 // AssignmentExpression :: 2316 // AssignmentExpression ::
2325 // ConditionalExpression 2317 // ConditionalExpression
2326 // LeftHandSideExpression AssignmentOperator AssignmentExpression 2318 // LeftHandSideExpression AssignmentOperator AssignmentExpression
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2378 // expression. 2370 // expression.
2379 if ((op == Token::INIT_VAR 2371 if ((op == Token::INIT_VAR
2380 || op == Token::INIT_CONST 2372 || op == Token::INIT_CONST
2381 || op == Token::ASSIGN) 2373 || op == Token::ASSIGN)
2382 && (right->AsCall() == NULL)) { 2374 && (right->AsCall() == NULL)) {
2383 fni_->Infer(); 2375 fni_->Infer();
2384 } 2376 }
2385 fni_->Leave(); 2377 fni_->Leave();
2386 } 2378 }
2387 2379
2388 return new(zone()) Assignment(op, expression, right, pos); 2380 return new Assignment(op, expression, right, pos);
2389 } 2381 }
2390 2382
2391 2383
2392 // Precedence = 3 2384 // Precedence = 3
2393 Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) { 2385 Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) {
2394 // ConditionalExpression :: 2386 // ConditionalExpression ::
2395 // LogicalOrExpression 2387 // LogicalOrExpression
2396 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression 2388 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression
2397 2389
2398 // We start using the binary expression parser for prec >= 4 only! 2390 // We start using the binary expression parser for prec >= 4 only!
2399 Expression* expression = ParseBinaryExpression(4, accept_IN, CHECK_OK); 2391 Expression* expression = ParseBinaryExpression(4, accept_IN, CHECK_OK);
2400 if (peek() != Token::CONDITIONAL) return expression; 2392 if (peek() != Token::CONDITIONAL) return expression;
2401 Consume(Token::CONDITIONAL); 2393 Consume(Token::CONDITIONAL);
2402 // In parsing the first assignment expression in conditional 2394 // In parsing the first assignment expression in conditional
2403 // expressions we always accept the 'in' keyword; see ECMA-262, 2395 // expressions we always accept the 'in' keyword; see ECMA-262,
2404 // section 11.12, page 58. 2396 // section 11.12, page 58.
2405 int left_position = scanner().peek_location().beg_pos; 2397 int left_position = scanner().peek_location().beg_pos;
2406 Expression* left = ParseAssignmentExpression(true, CHECK_OK); 2398 Expression* left = ParseAssignmentExpression(true, CHECK_OK);
2407 Expect(Token::COLON, CHECK_OK); 2399 Expect(Token::COLON, CHECK_OK);
2408 int right_position = scanner().peek_location().beg_pos; 2400 int right_position = scanner().peek_location().beg_pos;
2409 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); 2401 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
2410 return new(zone()) Conditional(expression, left, right, 2402 return new Conditional(expression, left, right,
2411 left_position, right_position); 2403 left_position, right_position);
2412 } 2404 }
2413 2405
2414 2406
2415 static int Precedence(Token::Value tok, bool accept_IN) { 2407 static int Precedence(Token::Value tok, bool accept_IN) {
2416 if (tok == Token::IN && !accept_IN) 2408 if (tok == Token::IN && !accept_IN)
2417 return 0; // 0 precedence will terminate binary expression parsing 2409 return 0; // 0 precedence will terminate binary expression parsing
2418 2410
2419 return Token::Precedence(tok); 2411 return Token::Precedence(tok);
2420 } 2412 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2488 // We have a comparison. 2480 // We have a comparison.
2489 Token::Value cmp = op; 2481 Token::Value cmp = op;
2490 switch (op) { 2482 switch (op) {
2491 case Token::NE: cmp = Token::EQ; break; 2483 case Token::NE: cmp = Token::EQ; break;
2492 case Token::NE_STRICT: cmp = Token::EQ_STRICT; break; 2484 case Token::NE_STRICT: cmp = Token::EQ_STRICT; break;
2493 default: break; 2485 default: break;
2494 } 2486 }
2495 x = NewCompareNode(cmp, x, y, position); 2487 x = NewCompareNode(cmp, x, y, position);
2496 if (cmp != op) { 2488 if (cmp != op) {
2497 // The comparison was negated - add a NOT. 2489 // The comparison was negated - add a NOT.
2498 x = new(zone()) UnaryOperation(Token::NOT, x); 2490 x = new UnaryOperation(Token::NOT, x);
2499 } 2491 }
2500 2492
2501 } else { 2493 } else {
2502 // We have a "normal" binary operation. 2494 // We have a "normal" binary operation.
2503 x = new(zone()) BinaryOperation(op, x, y, position); 2495 x = new BinaryOperation(op, x, y, position);
2504 } 2496 }
2505 } 2497 }
2506 } 2498 }
2507 return x; 2499 return x;
2508 } 2500 }
2509 2501
2510 2502
2511 Expression* Parser::NewCompareNode(Token::Value op, 2503 Expression* Parser::NewCompareNode(Token::Value op,
2512 Expression* x, 2504 Expression* x,
2513 Expression* y, 2505 Expression* y,
2514 int position) { 2506 int position) {
2515 ASSERT(op != Token::NE && op != Token::NE_STRICT); 2507 ASSERT(op != Token::NE && op != Token::NE_STRICT);
2516 if (op == Token::EQ || op == Token::EQ_STRICT) { 2508 if (op == Token::EQ || op == Token::EQ_STRICT) {
2517 bool is_strict = (op == Token::EQ_STRICT); 2509 bool is_strict = (op == Token::EQ_STRICT);
2518 Literal* x_literal = x->AsLiteral(); 2510 Literal* x_literal = x->AsLiteral();
2519 if (x_literal != NULL && x_literal->IsNull()) { 2511 if (x_literal != NULL && x_literal->IsNull()) {
2520 return new(zone()) CompareToNull(is_strict, y); 2512 return new CompareToNull(is_strict, y);
2521 } 2513 }
2522 2514
2523 Literal* y_literal = y->AsLiteral(); 2515 Literal* y_literal = y->AsLiteral();
2524 if (y_literal != NULL && y_literal->IsNull()) { 2516 if (y_literal != NULL && y_literal->IsNull()) {
2525 return new(zone()) CompareToNull(is_strict, x); 2517 return new CompareToNull(is_strict, x);
2526 } 2518 }
2527 } 2519 }
2528 return new(zone()) CompareOperation(op, x, y, position); 2520 return new CompareOperation(op, x, y, position);
2529 } 2521 }
2530 2522
2531 2523
2532 Expression* Parser::ParseUnaryExpression(bool* ok) { 2524 Expression* Parser::ParseUnaryExpression(bool* ok) {
2533 // UnaryExpression :: 2525 // UnaryExpression ::
2534 // PostfixExpression 2526 // PostfixExpression
2535 // 'delete' UnaryExpression 2527 // 'delete' UnaryExpression
2536 // 'void' UnaryExpression 2528 // 'void' UnaryExpression
2537 // 'typeof' UnaryExpression 2529 // 'typeof' UnaryExpression
2538 // '++' UnaryExpression 2530 // '++' UnaryExpression
(...skipping 26 matching lines...) Expand all
2565 // "delete identifier" is a syntax error in strict mode. 2557 // "delete identifier" is a syntax error in strict mode.
2566 if (op == Token::DELETE && top_scope_->is_strict_mode()) { 2558 if (op == Token::DELETE && top_scope_->is_strict_mode()) {
2567 VariableProxy* operand = expression->AsVariableProxy(); 2559 VariableProxy* operand = expression->AsVariableProxy();
2568 if (operand != NULL && !operand->is_this()) { 2560 if (operand != NULL && !operand->is_this()) {
2569 ReportMessage("strict_delete", Vector<const char*>::empty()); 2561 ReportMessage("strict_delete", Vector<const char*>::empty());
2570 *ok = false; 2562 *ok = false;
2571 return NULL; 2563 return NULL;
2572 } 2564 }
2573 } 2565 }
2574 2566
2575 return new(zone()) UnaryOperation(op, expression); 2567 return new UnaryOperation(op, expression);
2576 2568
2577 } else if (Token::IsCountOp(op)) { 2569 } else if (Token::IsCountOp(op)) {
2578 op = Next(); 2570 op = Next();
2579 Expression* expression = ParseUnaryExpression(CHECK_OK); 2571 Expression* expression = ParseUnaryExpression(CHECK_OK);
2580 // Signal a reference error if the expression is an invalid 2572 // Signal a reference error if the expression is an invalid
2581 // left-hand side expression. We could report this as a syntax 2573 // left-hand side expression. We could report this as a syntax
2582 // error here but for compatibility with JSC we choose to report the 2574 // error here but for compatibility with JSC we choose to report the
2583 // error at runtime. 2575 // error at runtime.
2584 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2576 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2585 Handle<String> type = 2577 Handle<String> type =
2586 isolate()->factory()->invalid_lhs_in_prefix_op_symbol(); 2578 isolate()->factory()->invalid_lhs_in_prefix_op_symbol();
2587 expression = NewThrowReferenceError(type); 2579 expression = NewThrowReferenceError(type);
2588 } 2580 }
2589 2581
2590 if (top_scope_->is_strict_mode()) { 2582 if (top_scope_->is_strict_mode()) {
2591 // Prefix expression operand in strict mode may not be eval or arguments. 2583 // Prefix expression operand in strict mode may not be eval or arguments.
2592 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); 2584 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK);
2593 } 2585 }
2594 2586
2595 int position = scanner().location().beg_pos; 2587 int position = scanner().location().beg_pos;
2596 IncrementOperation* increment = 2588 IncrementOperation* increment = new IncrementOperation(op, expression);
2597 new(zone()) IncrementOperation(op, expression); 2589 return new CountOperation(true /* prefix */, increment, position);
2598 return new(zone()) CountOperation(true /* prefix */, increment, position);
2599 2590
2600 } else { 2591 } else {
2601 return ParsePostfixExpression(ok); 2592 return ParsePostfixExpression(ok);
2602 } 2593 }
2603 } 2594 }
2604 2595
2605 2596
2606 Expression* Parser::ParsePostfixExpression(bool* ok) { 2597 Expression* Parser::ParsePostfixExpression(bool* ok) {
2607 // PostfixExpression :: 2598 // PostfixExpression ::
2608 // LeftHandSideExpression ('++' | '--')? 2599 // LeftHandSideExpression ('++' | '--')?
(...skipping 11 matching lines...) Expand all
2620 expression = NewThrowReferenceError(type); 2611 expression = NewThrowReferenceError(type);
2621 } 2612 }
2622 2613
2623 if (top_scope_->is_strict_mode()) { 2614 if (top_scope_->is_strict_mode()) {
2624 // Postfix expression operand in strict mode may not be eval or arguments. 2615 // Postfix expression operand in strict mode may not be eval or arguments.
2625 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); 2616 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK);
2626 } 2617 }
2627 2618
2628 Token::Value next = Next(); 2619 Token::Value next = Next();
2629 int position = scanner().location().beg_pos; 2620 int position = scanner().location().beg_pos;
2630 IncrementOperation* increment = 2621 IncrementOperation* increment = new IncrementOperation(next, expression);
2631 new(zone()) IncrementOperation(next, expression); 2622 expression = new CountOperation(false /* postfix */, increment, position);
2632 expression =
2633 new(zone()) CountOperation(false /* postfix */, increment, position);
2634 } 2623 }
2635 return expression; 2624 return expression;
2636 } 2625 }
2637 2626
2638 2627
2639 Expression* Parser::ParseLeftHandSideExpression(bool* ok) { 2628 Expression* Parser::ParseLeftHandSideExpression(bool* ok) {
2640 // LeftHandSideExpression :: 2629 // LeftHandSideExpression ::
2641 // (NewExpression | MemberExpression) ... 2630 // (NewExpression | MemberExpression) ...
2642 2631
2643 Expression* result; 2632 Expression* result;
2644 if (peek() == Token::NEW) { 2633 if (peek() == Token::NEW) {
2645 result = ParseNewExpression(CHECK_OK); 2634 result = ParseNewExpression(CHECK_OK);
2646 } else { 2635 } else {
2647 result = ParseMemberExpression(CHECK_OK); 2636 result = ParseMemberExpression(CHECK_OK);
2648 } 2637 }
2649 2638
2650 while (true) { 2639 while (true) {
2651 switch (peek()) { 2640 switch (peek()) {
2652 case Token::LBRACK: { 2641 case Token::LBRACK: {
2653 Consume(Token::LBRACK); 2642 Consume(Token::LBRACK);
2654 int pos = scanner().location().beg_pos; 2643 int pos = scanner().location().beg_pos;
2655 Expression* index = ParseExpression(true, CHECK_OK); 2644 Expression* index = ParseExpression(true, CHECK_OK);
2656 result = new(zone()) Property(result, index, pos); 2645 result = new Property(result, index, pos);
2657 Expect(Token::RBRACK, CHECK_OK); 2646 Expect(Token::RBRACK, CHECK_OK);
2658 break; 2647 break;
2659 } 2648 }
2660 2649
2661 case Token::LPAREN: { 2650 case Token::LPAREN: {
2662 int pos = scanner().location().beg_pos; 2651 int pos = scanner().location().beg_pos;
2663 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); 2652 ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
2664 2653
2665 // Keep track of eval() calls since they disable all local variable 2654 // Keep track of eval() calls since they disable all local variable
2666 // optimizations. 2655 // optimizations.
(...skipping 17 matching lines...) Expand all
2684 } 2673 }
2685 } 2674 }
2686 result = NewCall(result, args, pos); 2675 result = NewCall(result, args, pos);
2687 break; 2676 break;
2688 } 2677 }
2689 2678
2690 case Token::PERIOD: { 2679 case Token::PERIOD: {
2691 Consume(Token::PERIOD); 2680 Consume(Token::PERIOD);
2692 int pos = scanner().location().beg_pos; 2681 int pos = scanner().location().beg_pos;
2693 Handle<String> name = ParseIdentifierName(CHECK_OK); 2682 Handle<String> name = ParseIdentifierName(CHECK_OK);
2694 result = new(zone()) Property(result, new(zone()) Literal(name), pos); 2683 result = new Property(result, new Literal(name), pos);
2695 if (fni_ != NULL) fni_->PushLiteralName(name); 2684 if (fni_ != NULL) fni_->PushLiteralName(name);
2696 break; 2685 break;
2697 } 2686 }
2698 2687
2699 default: 2688 default:
2700 return result; 2689 return result;
2701 } 2690 }
2702 } 2691 }
2703 } 2692 }
2704 2693
(...skipping 15 matching lines...) Expand all
2720 2709
2721 Expression* result; 2710 Expression* result;
2722 if (peek() == Token::NEW) { 2711 if (peek() == Token::NEW) {
2723 result = ParseNewPrefix(stack, CHECK_OK); 2712 result = ParseNewPrefix(stack, CHECK_OK);
2724 } else { 2713 } else {
2725 result = ParseMemberWithNewPrefixesExpression(stack, CHECK_OK); 2714 result = ParseMemberWithNewPrefixesExpression(stack, CHECK_OK);
2726 } 2715 }
2727 2716
2728 if (!stack->is_empty()) { 2717 if (!stack->is_empty()) {
2729 int last = stack->pop(); 2718 int last = stack->pop();
2730 result = new(zone()) CallNew(result, new ZoneList<Expression*>(0), last); 2719 result = new CallNew(result, new ZoneList<Expression*>(0), last);
2731 } 2720 }
2732 return result; 2721 return result;
2733 } 2722 }
2734 2723
2735 2724
2736 Expression* Parser::ParseNewExpression(bool* ok) { 2725 Expression* Parser::ParseNewExpression(bool* ok) {
2737 PositionStack stack(ok); 2726 PositionStack stack(ok);
2738 return ParseNewPrefix(&stack, ok); 2727 return ParseNewPrefix(&stack, ok);
2739 } 2728 }
2740 2729
(...skipping 24 matching lines...) Expand all
2765 } else { 2754 } else {
2766 result = ParsePrimaryExpression(CHECK_OK); 2755 result = ParsePrimaryExpression(CHECK_OK);
2767 } 2756 }
2768 2757
2769 while (true) { 2758 while (true) {
2770 switch (peek()) { 2759 switch (peek()) {
2771 case Token::LBRACK: { 2760 case Token::LBRACK: {
2772 Consume(Token::LBRACK); 2761 Consume(Token::LBRACK);
2773 int pos = scanner().location().beg_pos; 2762 int pos = scanner().location().beg_pos;
2774 Expression* index = ParseExpression(true, CHECK_OK); 2763 Expression* index = ParseExpression(true, CHECK_OK);
2775 result = new(zone()) Property(result, index, pos); 2764 result = new Property(result, index, pos);
2776 Expect(Token::RBRACK, CHECK_OK); 2765 Expect(Token::RBRACK, CHECK_OK);
2777 break; 2766 break;
2778 } 2767 }
2779 case Token::PERIOD: { 2768 case Token::PERIOD: {
2780 Consume(Token::PERIOD); 2769 Consume(Token::PERIOD);
2781 int pos = scanner().location().beg_pos; 2770 int pos = scanner().location().beg_pos;
2782 Handle<String> name = ParseIdentifierName(CHECK_OK); 2771 Handle<String> name = ParseIdentifierName(CHECK_OK);
2783 result = new(zone()) Property(result, new(zone()) Literal(name), pos); 2772 result = new Property(result, new Literal(name), pos);
2784 if (fni_ != NULL) fni_->PushLiteralName(name); 2773 if (fni_ != NULL) fni_->PushLiteralName(name);
2785 break; 2774 break;
2786 } 2775 }
2787 case Token::LPAREN: { 2776 case Token::LPAREN: {
2788 if ((stack == NULL) || stack->is_empty()) return result; 2777 if ((stack == NULL) || stack->is_empty()) return result;
2789 // Consume one of the new prefixes (already parsed). 2778 // Consume one of the new prefixes (already parsed).
2790 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); 2779 ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
2791 int last = stack->pop(); 2780 int last = stack->pop();
2792 result = new CallNew(result, args, last); 2781 result = new CallNew(result, args, last);
2793 break; 2782 break;
2794 } 2783 }
2795 default: 2784 default:
2796 return result; 2785 return result;
2797 } 2786 }
2798 } 2787 }
2799 } 2788 }
2800 2789
2801 2790
2802 DebuggerStatement* Parser::ParseDebuggerStatement(bool* ok) { 2791 DebuggerStatement* Parser::ParseDebuggerStatement(bool* ok) {
2803 // In ECMA-262 'debugger' is defined as a reserved keyword. In some browser 2792 // In ECMA-262 'debugger' is defined as a reserved keyword. In some browser
2804 // contexts this is used as a statement which invokes the debugger as i a 2793 // contexts this is used as a statement which invokes the debugger as i a
2805 // break point is present. 2794 // break point is present.
2806 // DebuggerStatement :: 2795 // DebuggerStatement ::
2807 // 'debugger' ';' 2796 // 'debugger' ';'
2808 2797
2809 Expect(Token::DEBUGGER, CHECK_OK); 2798 Expect(Token::DEBUGGER, CHECK_OK);
2810 ExpectSemicolon(CHECK_OK); 2799 ExpectSemicolon(CHECK_OK);
2811 return new(zone()) DebuggerStatement(); 2800 return new DebuggerStatement();
2812 } 2801 }
2813 2802
2814 2803
2815 void Parser::ReportUnexpectedToken(Token::Value token) { 2804 void Parser::ReportUnexpectedToken(Token::Value token) {
2816 // We don't report stack overflows here, to avoid increasing the 2805 // We don't report stack overflows here, to avoid increasing the
2817 // stack depth even further. Instead we report it after parsing is 2806 // stack depth even further. Instead we report it after parsing is
2818 // over, in ParseProgram/ParseJson. 2807 // over, in ParseProgram/ParseJson.
2819 if (token == Token::ILLEGAL && stack_overflow_) return; 2808 if (token == Token::ILLEGAL && stack_overflow_) return;
2820 // Four of the tokens are treated specially 2809 // Four of the tokens are treated specially
2821 switch (token) { 2810 switch (token) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2870 switch (peek()) { 2859 switch (peek()) {
2871 case Token::THIS: { 2860 case Token::THIS: {
2872 Consume(Token::THIS); 2861 Consume(Token::THIS);
2873 VariableProxy* recv = top_scope_->receiver(); 2862 VariableProxy* recv = top_scope_->receiver();
2874 result = recv; 2863 result = recv;
2875 break; 2864 break;
2876 } 2865 }
2877 2866
2878 case Token::NULL_LITERAL: 2867 case Token::NULL_LITERAL:
2879 Consume(Token::NULL_LITERAL); 2868 Consume(Token::NULL_LITERAL);
2880 result = new(zone()) Literal(isolate()->factory()->null_value()); 2869 result = new Literal(isolate()->factory()->null_value());
2881 break; 2870 break;
2882 2871
2883 case Token::TRUE_LITERAL: 2872 case Token::TRUE_LITERAL:
2884 Consume(Token::TRUE_LITERAL); 2873 Consume(Token::TRUE_LITERAL);
2885 result = new(zone()) Literal(isolate()->factory()->true_value()); 2874 result = new Literal(isolate()->factory()->true_value());
2886 break; 2875 break;
2887 2876
2888 case Token::FALSE_LITERAL: 2877 case Token::FALSE_LITERAL:
2889 Consume(Token::FALSE_LITERAL); 2878 Consume(Token::FALSE_LITERAL);
2890 result = new(zone()) Literal(isolate()->factory()->false_value()); 2879 result = new Literal(isolate()->factory()->false_value());
2891 break; 2880 break;
2892 2881
2893 case Token::IDENTIFIER: 2882 case Token::IDENTIFIER:
2894 case Token::FUTURE_RESERVED_WORD: { 2883 case Token::FUTURE_RESERVED_WORD: {
2895 Handle<String> name = ParseIdentifier(CHECK_OK); 2884 Handle<String> name = ParseIdentifier(CHECK_OK);
2896 if (fni_ != NULL) fni_->PushVariableName(name); 2885 if (fni_ != NULL) fni_->PushVariableName(name);
2897 result = top_scope_->NewUnresolved(name, 2886 result = top_scope_->NewUnresolved(name, inside_with());
2898 inside_with(),
2899 scanner().location().beg_pos);
2900 break; 2887 break;
2901 } 2888 }
2902 2889
2903 case Token::NUMBER: { 2890 case Token::NUMBER: {
2904 Consume(Token::NUMBER); 2891 Consume(Token::NUMBER);
2905 ASSERT(scanner().is_literal_ascii()); 2892 ASSERT(scanner().is_literal_ascii());
2906 double value = StringToDouble(scanner().literal_ascii_string(), 2893 double value = StringToDouble(scanner().literal_ascii_string(),
2907 ALLOW_HEX | ALLOW_OCTALS); 2894 ALLOW_HEX | ALLOW_OCTALS);
2908 result = NewNumberLiteral(value); 2895 result = NewNumberLiteral(value);
2909 break; 2896 break;
2910 } 2897 }
2911 2898
2912 case Token::STRING: { 2899 case Token::STRING: {
2913 Consume(Token::STRING); 2900 Consume(Token::STRING);
2914 Handle<String> symbol = GetSymbol(CHECK_OK); 2901 Handle<String> symbol = GetSymbol(CHECK_OK);
2915 result = new(zone()) Literal(symbol); 2902 result = new Literal(symbol);
2916 if (fni_ != NULL) fni_->PushLiteralName(symbol); 2903 if (fni_ != NULL) fni_->PushLiteralName(symbol);
2917 break; 2904 break;
2918 } 2905 }
2919 2906
2920 case Token::ASSIGN_DIV: 2907 case Token::ASSIGN_DIV:
2921 result = ParseRegExpLiteral(true, CHECK_OK); 2908 result = ParseRegExpLiteral(true, CHECK_OK);
2922 break; 2909 break;
2923 2910
2924 case Token::DIV: 2911 case Token::DIV:
2925 result = ParseRegExpLiteral(false, CHECK_OK); 2912 result = ParseRegExpLiteral(false, CHECK_OK);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
3032 literals->set(i, *boilerplate_value); 3019 literals->set(i, *boilerplate_value);
3033 } 3020 }
3034 } 3021 }
3035 3022
3036 // Simple and shallow arrays can be lazily copied, we transform the 3023 // Simple and shallow arrays can be lazily copied, we transform the
3037 // elements array to a copy-on-write array. 3024 // elements array to a copy-on-write array.
3038 if (is_simple && depth == 1 && values->length() > 0) { 3025 if (is_simple && depth == 1 && values->length() > 0) {
3039 literals->set_map(isolate()->heap()->fixed_cow_array_map()); 3026 literals->set_map(isolate()->heap()->fixed_cow_array_map());
3040 } 3027 }
3041 3028
3042 return new(zone()) ArrayLiteral(literals, values, 3029 return new ArrayLiteral(literals, values,
3043 literal_index, is_simple, depth); 3030 literal_index, is_simple, depth);
3044 } 3031 }
3045 3032
3046 3033
3047 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { 3034 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) {
3048 return property != NULL && 3035 return property != NULL &&
3049 property->kind() != ObjectLiteral::Property::PROTOTYPE; 3036 property->kind() != ObjectLiteral::Property::PROTOTYPE;
3050 } 3037 }
3051 3038
3052 3039
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
3310 } 3297 }
3311 FunctionLiteral* value = 3298 FunctionLiteral* value =
3312 ParseFunctionLiteral(name, 3299 ParseFunctionLiteral(name,
3313 false, // reserved words are allowed here 3300 false, // reserved words are allowed here
3314 RelocInfo::kNoPosition, 3301 RelocInfo::kNoPosition,
3315 DECLARATION, 3302 DECLARATION,
3316 CHECK_OK); 3303 CHECK_OK);
3317 // Allow any number of parameters for compatiabilty with JSC. 3304 // Allow any number of parameters for compatiabilty with JSC.
3318 // Specification only allows zero parameters for get and one for set. 3305 // Specification only allows zero parameters for get and one for set.
3319 ObjectLiteral::Property* property = 3306 ObjectLiteral::Property* property =
3320 new(zone()) ObjectLiteral::Property(is_getter, value); 3307 new ObjectLiteral::Property(is_getter, value);
3321 return property; 3308 return property;
3322 } else { 3309 } else {
3323 ReportUnexpectedToken(next); 3310 ReportUnexpectedToken(next);
3324 *ok = false; 3311 *ok = false;
3325 return NULL; 3312 return NULL;
3326 } 3313 }
3327 } 3314 }
3328 3315
3329 3316
3330 Expression* Parser::ParseObjectLiteral(bool* ok) { 3317 Expression* Parser::ParseObjectLiteral(bool* ok) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
3376 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); 3363 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK);
3377 3364
3378 if (fni_ != NULL) { 3365 if (fni_ != NULL) {
3379 fni_->Infer(); 3366 fni_->Infer();
3380 fni_->Leave(); 3367 fni_->Leave();
3381 } 3368 }
3382 continue; // restart the while 3369 continue; // restart the while
3383 } 3370 }
3384 // Failed to parse as get/set property, so it's just a property 3371 // Failed to parse as get/set property, so it's just a property
3385 // called "get" or "set". 3372 // called "get" or "set".
3386 key = new(zone()) Literal(id); 3373 key = new Literal(id);
3387 break; 3374 break;
3388 } 3375 }
3389 case Token::STRING: { 3376 case Token::STRING: {
3390 Consume(Token::STRING); 3377 Consume(Token::STRING);
3391 Handle<String> string = GetSymbol(CHECK_OK); 3378 Handle<String> string = GetSymbol(CHECK_OK);
3392 if (fni_ != NULL) fni_->PushLiteralName(string); 3379 if (fni_ != NULL) fni_->PushLiteralName(string);
3393 uint32_t index; 3380 uint32_t index;
3394 if (!string.is_null() && string->AsArrayIndex(&index)) { 3381 if (!string.is_null() && string->AsArrayIndex(&index)) {
3395 key = NewNumberLiteral(index); 3382 key = NewNumberLiteral(index);
3396 break; 3383 break;
3397 } 3384 }
3398 key = new(zone()) Literal(string); 3385 key = new Literal(string);
3399 break; 3386 break;
3400 } 3387 }
3401 case Token::NUMBER: { 3388 case Token::NUMBER: {
3402 Consume(Token::NUMBER); 3389 Consume(Token::NUMBER);
3403 ASSERT(scanner().is_literal_ascii()); 3390 ASSERT(scanner().is_literal_ascii());
3404 double value = StringToDouble(scanner().literal_ascii_string(), 3391 double value = StringToDouble(scanner().literal_ascii_string(),
3405 ALLOW_HEX | ALLOW_OCTALS); 3392 ALLOW_HEX | ALLOW_OCTALS);
3406 key = NewNumberLiteral(value); 3393 key = NewNumberLiteral(value);
3407 break; 3394 break;
3408 } 3395 }
3409 default: 3396 default:
3410 if (Token::IsKeyword(next)) { 3397 if (Token::IsKeyword(next)) {
3411 Consume(next); 3398 Consume(next);
3412 Handle<String> string = GetSymbol(CHECK_OK); 3399 Handle<String> string = GetSymbol(CHECK_OK);
3413 key = new(zone()) Literal(string); 3400 key = new Literal(string);
3414 } else { 3401 } else {
3415 // Unexpected token. 3402 // Unexpected token.
3416 Token::Value next = Next(); 3403 Token::Value next = Next();
3417 ReportUnexpectedToken(next); 3404 ReportUnexpectedToken(next);
3418 *ok = false; 3405 *ok = false;
3419 return NULL; 3406 return NULL;
3420 } 3407 }
3421 } 3408 }
3422 3409
3423 Expect(Token::COLON, CHECK_OK); 3410 Expect(Token::COLON, CHECK_OK);
3424 Expression* value = ParseAssignmentExpression(true, CHECK_OK); 3411 Expression* value = ParseAssignmentExpression(true, CHECK_OK);
3425 3412
3426 ObjectLiteral::Property* property = 3413 ObjectLiteral::Property* property =
3427 new(zone()) ObjectLiteral::Property(key, value); 3414 new ObjectLiteral::Property(key, value);
3428 3415
3429 // Mark object literals that contain function literals and pretenure the 3416 // Mark object literals that contain function literals and pretenure the
3430 // literal so it can be added as a constant function property. 3417 // literal so it can be added as a constant function property.
3431 if (value->AsFunctionLiteral() != NULL) { 3418 if (value->AsFunctionLiteral() != NULL) {
3432 has_function = true; 3419 has_function = true;
3433 value->AsFunctionLiteral()->set_pretenure(true); 3420 value->AsFunctionLiteral()->set_pretenure(true);
3434 } 3421 }
3435 3422
3436 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. 3423 // Count CONSTANT or COMPUTED properties to maintain the enumeration order.
3437 if (IsBoilerplateProperty(property)) number_of_boilerplate_properties++; 3424 if (IsBoilerplateProperty(property)) number_of_boilerplate_properties++;
(...skipping 18 matching lines...) Expand all
3456 number_of_boilerplate_properties * 2, TENURED); 3443 number_of_boilerplate_properties * 2, TENURED);
3457 3444
3458 bool is_simple = true; 3445 bool is_simple = true;
3459 bool fast_elements = true; 3446 bool fast_elements = true;
3460 int depth = 1; 3447 int depth = 1;
3461 BuildObjectLiteralConstantProperties(properties, 3448 BuildObjectLiteralConstantProperties(properties,
3462 constant_properties, 3449 constant_properties,
3463 &is_simple, 3450 &is_simple,
3464 &fast_elements, 3451 &fast_elements,
3465 &depth); 3452 &depth);
3466 return new(zone()) ObjectLiteral(constant_properties, 3453 return new ObjectLiteral(constant_properties,
3467 properties, 3454 properties,
3468 literal_index, 3455 literal_index,
3469 is_simple, 3456 is_simple,
3470 fast_elements, 3457 fast_elements,
3471 depth, 3458 depth,
3472 has_function); 3459 has_function);
3473 } 3460 }
3474 3461
3475 3462
3476 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { 3463 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) {
3477 if (!scanner().ScanRegExpPattern(seen_equal)) { 3464 if (!scanner().ScanRegExpPattern(seen_equal)) {
3478 Next(); 3465 Next();
3479 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); 3466 ReportMessage("unterminated_regexp", Vector<const char*>::empty());
3480 *ok = false; 3467 *ok = false;
3481 return NULL; 3468 return NULL;
3482 } 3469 }
3483 3470
3484 int literal_index = lexical_scope_->NextMaterializedLiteralIndex(); 3471 int literal_index = lexical_scope_->NextMaterializedLiteralIndex();
3485 3472
3486 Handle<String> js_pattern = NextLiteralString(TENURED); 3473 Handle<String> js_pattern = NextLiteralString(TENURED);
3487 scanner().ScanRegExpFlags(); 3474 scanner().ScanRegExpFlags();
3488 Handle<String> js_flags = NextLiteralString(TENURED); 3475 Handle<String> js_flags = NextLiteralString(TENURED);
3489 Next(); 3476 Next();
3490 3477
3491 return new(zone()) RegExpLiteral(js_pattern, js_flags, literal_index); 3478 return new RegExpLiteral(js_pattern, js_flags, literal_index);
3492 } 3479 }
3493 3480
3494 3481
3495 ZoneList<Expression*>* Parser::ParseArguments(bool* ok) { 3482 ZoneList<Expression*>* Parser::ParseArguments(bool* ok) {
3496 // Arguments :: 3483 // Arguments ::
3497 // '(' (AssignmentExpression)*[','] ')' 3484 // '(' (AssignmentExpression)*[','] ')'
3498 3485
3499 ZoneList<Expression*>* result = new ZoneList<Expression*>(4); 3486 ZoneList<Expression*>* result = new ZoneList<Expression*>(4);
3500 Expect(Token::LPAREN, CHECK_OK); 3487 Expect(Token::LPAREN, CHECK_OK);
3501 bool done = (peek() == Token::RPAREN); 3488 bool done = (peek() == Token::RPAREN);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
3584 // declaration to the body of the function with the name of the 3571 // declaration to the body of the function with the name of the
3585 // function and let it refer to the function itself (closure). 3572 // function and let it refer to the function itself (closure).
3586 // NOTE: We create a proxy and resolve it here so that in the 3573 // NOTE: We create a proxy and resolve it here so that in the
3587 // future we can change the AST to only refer to VariableProxies 3574 // future we can change the AST to only refer to VariableProxies
3588 // instead of Variables and Proxis as is the case now. 3575 // instead of Variables and Proxis as is the case now.
3589 if (!function_name.is_null() && function_name->length() > 0) { 3576 if (!function_name.is_null() && function_name->length() > 0) {
3590 Variable* fvar = top_scope_->DeclareFunctionVar(function_name); 3577 Variable* fvar = top_scope_->DeclareFunctionVar(function_name);
3591 VariableProxy* fproxy = 3578 VariableProxy* fproxy =
3592 top_scope_->NewUnresolved(function_name, inside_with()); 3579 top_scope_->NewUnresolved(function_name, inside_with());
3593 fproxy->BindTo(fvar); 3580 fproxy->BindTo(fvar);
3594 body->Add(new(zone()) ExpressionStatement( 3581 body->Add(new ExpressionStatement(
3595 new(zone()) Assignment(Token::INIT_CONST, fproxy, 3582 new Assignment(Token::INIT_CONST, fproxy,
3596 new(zone()) ThisFunction(), 3583 new ThisFunction(),
3597 RelocInfo::kNoPosition))); 3584 RelocInfo::kNoPosition)));
3598 } 3585 }
3599 3586
3600 // Determine if the function will be lazily compiled. The mode can 3587 // Determine if the function will be lazily compiled. The mode can
3601 // only be PARSE_LAZILY if the --lazy flag is true. 3588 // only be PARSE_LAZILY if the --lazy flag is true.
3602 bool is_lazily_compiled = (mode() == PARSE_LAZILY && 3589 bool is_lazily_compiled = (mode() == PARSE_LAZILY &&
3603 top_scope_->outer_scope()->is_global_scope() && 3590 top_scope_->outer_scope()->is_global_scope() &&
3604 top_scope_->HasTrivialOuterContext() && 3591 top_scope_->HasTrivialOuterContext() &&
3605 !parenthesized_function_); 3592 !parenthesized_function_);
3606 parenthesized_function_ = false; // The bit was set for this function only. 3593 parenthesized_function_ = false; // The bit was set for this function only.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
3680 if (reserved_loc.IsValid()) { 3667 if (reserved_loc.IsValid()) {
3681 ReportMessageAt(reserved_loc, "strict_reserved_word", 3668 ReportMessageAt(reserved_loc, "strict_reserved_word",
3682 Vector<const char*>::empty()); 3669 Vector<const char*>::empty());
3683 *ok = false; 3670 *ok = false;
3684 return NULL; 3671 return NULL;
3685 } 3672 }
3686 CheckOctalLiteral(start_pos, end_pos, CHECK_OK); 3673 CheckOctalLiteral(start_pos, end_pos, CHECK_OK);
3687 } 3674 }
3688 3675
3689 FunctionLiteral* function_literal = 3676 FunctionLiteral* function_literal =
3690 new(zone()) FunctionLiteral(name, 3677 new FunctionLiteral(name,
3691 top_scope_, 3678 top_scope_,
3692 body, 3679 body,
3693 materialized_literal_count, 3680 materialized_literal_count,
3694 expected_property_count, 3681 expected_property_count,
3695 only_simple_this_property_assignments, 3682 only_simple_this_property_assignments,
3696 this_property_assignments, 3683 this_property_assignments,
3697 num_parameters, 3684 num_parameters,
3698 start_pos, 3685 start_pos,
3699 end_pos, 3686 end_pos,
3700 function_name->length() > 0, 3687 function_name->length() > 0,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
3742 // Check that the expected number of arguments are being passed. 3729 // Check that the expected number of arguments are being passed.
3743 if (function != NULL && 3730 if (function != NULL &&
3744 function->nargs != -1 && 3731 function->nargs != -1 &&
3745 function->nargs != args->length()) { 3732 function->nargs != args->length()) {
3746 ReportMessage("illegal_access", Vector<const char*>::empty()); 3733 ReportMessage("illegal_access", Vector<const char*>::empty());
3747 *ok = false; 3734 *ok = false;
3748 return NULL; 3735 return NULL;
3749 } 3736 }
3750 3737
3751 // We have a valid intrinsics call or a call to a builtin. 3738 // We have a valid intrinsics call or a call to a builtin.
3752 return new(zone()) CallRuntime(name, function, args); 3739 return new CallRuntime(name, function, args);
3753 } 3740 }
3754 3741
3755 3742
3756 bool Parser::peek_any_identifier() { 3743 bool Parser::peek_any_identifier() {
3757 Token::Value next = peek(); 3744 Token::Value next = peek();
3758 return next == Token::IDENTIFIER || 3745 return next == Token::IDENTIFIER ||
3759 next == Token::FUTURE_RESERVED_WORD; 3746 next == Token::FUTURE_RESERVED_WORD;
3760 } 3747 }
3761 3748
3762 3749
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3797 if (scanner().has_line_terminator_before_next() || 3784 if (scanner().has_line_terminator_before_next() ||
3798 tok == Token::RBRACE || 3785 tok == Token::RBRACE ||
3799 tok == Token::EOS) { 3786 tok == Token::EOS) {
3800 return; 3787 return;
3801 } 3788 }
3802 Expect(Token::SEMICOLON, ok); 3789 Expect(Token::SEMICOLON, ok);
3803 } 3790 }
3804 3791
3805 3792
3806 Literal* Parser::GetLiteralUndefined() { 3793 Literal* Parser::GetLiteralUndefined() {
3807 return new(zone()) Literal(isolate()->factory()->undefined_value()); 3794 return new Literal(isolate()->factory()->undefined_value());
3808 } 3795 }
3809 3796
3810 3797
3811 Literal* Parser::GetLiteralTheHole() { 3798 Literal* Parser::GetLiteralTheHole() {
3812 return new(zone()) Literal(isolate()->factory()->the_hole_value()); 3799 return new Literal(isolate()->factory()->the_hole_value());
3813 } 3800 }
3814 3801
3815 3802
3816 Literal* Parser::GetLiteralNumber(double value) { 3803 Literal* Parser::GetLiteralNumber(double value) {
3817 return NewNumberLiteral(value); 3804 return NewNumberLiteral(value);
3818 } 3805 }
3819 3806
3820 3807
3821 Handle<String> Parser::ParseIdentifier(bool* ok) { 3808 Handle<String> Parser::ParseIdentifier(bool* ok) {
3822 bool is_reserved; 3809 bool is_reserved;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
3950 // target stack has been used from the top of the target stack. Add 3937 // target stack has been used from the top of the target stack. Add
3951 // the break target to any TargetCollectors passed on the stack. 3938 // the break target to any TargetCollectors passed on the stack.
3952 for (Target* t = target_stack_; t != stop; t = t->previous()) { 3939 for (Target* t = target_stack_; t != stop; t = t->previous()) {
3953 TargetCollector* collector = t->node()->AsTargetCollector(); 3940 TargetCollector* collector = t->node()->AsTargetCollector();
3954 if (collector != NULL) collector->AddTarget(target); 3941 if (collector != NULL) collector->AddTarget(target);
3955 } 3942 }
3956 } 3943 }
3957 3944
3958 3945
3959 Literal* Parser::NewNumberLiteral(double number) { 3946 Literal* Parser::NewNumberLiteral(double number) {
3960 return new(zone()) Literal(isolate()->factory()->NewNumber(number, TENURED)); 3947 return new Literal(isolate()->factory()->NewNumber(number, TENURED));
3961 } 3948 }
3962 3949
3963 3950
3964 Expression* Parser::NewThrowReferenceError(Handle<String> type) { 3951 Expression* Parser::NewThrowReferenceError(Handle<String> type) {
3965 return NewThrowError(isolate()->factory()->MakeReferenceError_symbol(), 3952 return NewThrowError(isolate()->factory()->MakeReferenceError_symbol(),
3966 type, HandleVector<Object>(NULL, 0)); 3953 type, HandleVector<Object>(NULL, 0));
3967 } 3954 }
3968 3955
3969 3956
3970 Expression* Parser::NewThrowSyntaxError(Handle<String> type, 3957 Expression* Parser::NewThrowSyntaxError(Handle<String> type,
(...skipping 26 matching lines...) Expand all
3997 for (int i = 0; i < argc; i++) { 3984 for (int i = 0; i < argc; i++) {
3998 Handle<Object> element = arguments[i]; 3985 Handle<Object> element = arguments[i];
3999 if (!element.is_null()) { 3986 if (!element.is_null()) {
4000 elements->set(i, *element); 3987 elements->set(i, *element);
4001 } 3988 }
4002 } 3989 }
4003 Handle<JSArray> array = isolate()->factory()->NewJSArrayWithElements(elements, 3990 Handle<JSArray> array = isolate()->factory()->NewJSArrayWithElements(elements,
4004 TENURED); 3991 TENURED);
4005 3992
4006 ZoneList<Expression*>* args = new ZoneList<Expression*>(2); 3993 ZoneList<Expression*>* args = new ZoneList<Expression*>(2);
4007 args->Add(new(zone()) Literal(type)); 3994 args->Add(new Literal(type));
4008 args->Add(new(zone()) Literal(array)); 3995 args->Add(new Literal(array));
4009 return new(zone()) Throw(new(zone()) CallRuntime(constructor, NULL, args), 3996 return new Throw(new CallRuntime(constructor, NULL, args),
4010 scanner().location().beg_pos); 3997 scanner().location().beg_pos);
4011 } 3998 }
4012 3999
4013 // ---------------------------------------------------------------------------- 4000 // ----------------------------------------------------------------------------
4014 // JSON 4001 // JSON
4015 4002
4016 Handle<Object> JsonParser::ParseJson(Handle<String> script, 4003 Handle<Object> JsonParser::ParseJson(Handle<String> script,
4017 UC16CharacterStream* source) { 4004 UC16CharacterStream* source) {
4018 scanner_.Initialize(source); 4005 scanner_.Initialize(source);
4019 stack_overflow_ = false; 4006 stack_overflow_ = false;
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
4322 4309
4323 int capture_index = stored_state->capture_index(); 4310 int capture_index = stored_state->capture_index();
4324 SubexpressionType type = stored_state->group_type(); 4311 SubexpressionType type = stored_state->group_type();
4325 4312
4326 // Restore previous state. 4313 // Restore previous state.
4327 stored_state = stored_state->previous_state(); 4314 stored_state = stored_state->previous_state();
4328 builder = stored_state->builder(); 4315 builder = stored_state->builder();
4329 4316
4330 // Build result of subexpression. 4317 // Build result of subexpression.
4331 if (type == CAPTURE) { 4318 if (type == CAPTURE) {
4332 RegExpCapture* capture = new(zone()) RegExpCapture(body, capture_index); 4319 RegExpCapture* capture = new RegExpCapture(body, capture_index);
4333 captures_->at(capture_index - 1) = capture; 4320 captures_->at(capture_index - 1) = capture;
4334 body = capture; 4321 body = capture;
4335 } else if (type != GROUPING) { 4322 } else if (type != GROUPING) {
4336 ASSERT(type == POSITIVE_LOOKAHEAD || type == NEGATIVE_LOOKAHEAD); 4323 ASSERT(type == POSITIVE_LOOKAHEAD || type == NEGATIVE_LOOKAHEAD);
4337 bool is_positive = (type == POSITIVE_LOOKAHEAD); 4324 bool is_positive = (type == POSITIVE_LOOKAHEAD);
4338 body = new(zone()) RegExpLookahead(body, 4325 body = new RegExpLookahead(body,
4339 is_positive, 4326 is_positive,
4340 end_capture_index - capture_index, 4327 end_capture_index - capture_index,
4341 capture_index); 4328 capture_index);
4342 } 4329 }
4343 builder->AddAtom(body); 4330 builder->AddAtom(body);
4344 // For compatability with JSC and ES3, we allow quantifiers after 4331 // For compatability with JSC and ES3, we allow quantifiers after
4345 // lookaheads, and break in all cases. 4332 // lookaheads, and break in all cases.
4346 break; 4333 break;
4347 } 4334 }
4348 case '|': { 4335 case '|': {
4349 Advance(); 4336 Advance();
4350 builder->NewAlternative(); 4337 builder->NewAlternative();
4351 continue; 4338 continue;
4352 } 4339 }
4353 case '*': 4340 case '*':
4354 case '+': 4341 case '+':
4355 case '?': 4342 case '?':
4356 return ReportError(CStrVector("Nothing to repeat")); 4343 return ReportError(CStrVector("Nothing to repeat"));
4357 case '^': { 4344 case '^': {
4358 Advance(); 4345 Advance();
4359 if (multiline_) { 4346 if (multiline_) {
4360 builder->AddAssertion( 4347 builder->AddAssertion(
4361 new(zone()) RegExpAssertion(RegExpAssertion::START_OF_LINE)); 4348 new RegExpAssertion(RegExpAssertion::START_OF_LINE));
4362 } else { 4349 } else {
4363 builder->AddAssertion( 4350 builder->AddAssertion(
4364 new(zone()) RegExpAssertion(RegExpAssertion::START_OF_INPUT)); 4351 new RegExpAssertion(RegExpAssertion::START_OF_INPUT));
4365 set_contains_anchor(); 4352 set_contains_anchor();
4366 } 4353 }
4367 continue; 4354 continue;
4368 } 4355 }
4369 case '$': { 4356 case '$': {
4370 Advance(); 4357 Advance();
4371 RegExpAssertion::Type type = 4358 RegExpAssertion::Type type =
4372 multiline_ ? RegExpAssertion::END_OF_LINE : 4359 multiline_ ? RegExpAssertion::END_OF_LINE :
4373 RegExpAssertion::END_OF_INPUT; 4360 RegExpAssertion::END_OF_INPUT;
4374 builder->AddAssertion(new(zone()) RegExpAssertion(type)); 4361 builder->AddAssertion(new RegExpAssertion(type));
4375 continue; 4362 continue;
4376 } 4363 }
4377 case '.': { 4364 case '.': {
4378 Advance(); 4365 Advance();
4379 // everything except \x0a, \x0d, \u2028 and \u2029 4366 // everything except \x0a, \x0d, \u2028 and \u2029
4380 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); 4367 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2);
4381 CharacterRange::AddClassEscape('.', ranges); 4368 CharacterRange::AddClassEscape('.', ranges);
4382 RegExpTree* atom = new(zone()) RegExpCharacterClass(ranges, false); 4369 RegExpTree* atom = new RegExpCharacterClass(ranges, false);
4383 builder->AddAtom(atom); 4370 builder->AddAtom(atom);
4384 break; 4371 break;
4385 } 4372 }
4386 case '(': { 4373 case '(': {
4387 SubexpressionType type = CAPTURE; 4374 SubexpressionType type = CAPTURE;
4388 Advance(); 4375 Advance();
4389 if (current() == '?') { 4376 if (current() == '?') {
4390 switch (Next()) { 4377 switch (Next()) {
4391 case ':': 4378 case ':':
4392 type = GROUPING; 4379 type = GROUPING;
(...skipping 12 matching lines...) Expand all
4405 } else { 4392 } else {
4406 if (captures_ == NULL) { 4393 if (captures_ == NULL) {
4407 captures_ = new ZoneList<RegExpCapture*>(2); 4394 captures_ = new ZoneList<RegExpCapture*>(2);
4408 } 4395 }
4409 if (captures_started() >= kMaxCaptures) { 4396 if (captures_started() >= kMaxCaptures) {
4410 ReportError(CStrVector("Too many captures") CHECK_FAILED); 4397 ReportError(CStrVector("Too many captures") CHECK_FAILED);
4411 } 4398 }
4412 captures_->Add(NULL); 4399 captures_->Add(NULL);
4413 } 4400 }
4414 // Store current state and begin new disjunction parsing. 4401 // Store current state and begin new disjunction parsing.
4415 stored_state = new(zone()) RegExpParserState(stored_state, 4402 stored_state = new RegExpParserState(stored_state,
4416 type, 4403 type,
4417 captures_started()); 4404 captures_started());
4418 builder = stored_state->builder(); 4405 builder = stored_state->builder();
4419 continue; 4406 continue;
4420 } 4407 }
4421 case '[': { 4408 case '[': {
4422 RegExpTree* atom = ParseCharacterClass(CHECK_FAILED); 4409 RegExpTree* atom = ParseCharacterClass(CHECK_FAILED);
4423 builder->AddAtom(atom); 4410 builder->AddAtom(atom);
4424 break; 4411 break;
4425 } 4412 }
4426 // Atom :: 4413 // Atom ::
4427 // \ AtomEscape 4414 // \ AtomEscape
4428 case '\\': 4415 case '\\':
4429 switch (Next()) { 4416 switch (Next()) {
4430 case kEndMarker: 4417 case kEndMarker:
4431 return ReportError(CStrVector("\\ at end of pattern")); 4418 return ReportError(CStrVector("\\ at end of pattern"));
4432 case 'b': 4419 case 'b':
4433 Advance(2); 4420 Advance(2);
4434 builder->AddAssertion( 4421 builder->AddAssertion(
4435 new(zone()) RegExpAssertion(RegExpAssertion::BOUNDARY)); 4422 new RegExpAssertion(RegExpAssertion::BOUNDARY));
4436 continue; 4423 continue;
4437 case 'B': 4424 case 'B':
4438 Advance(2); 4425 Advance(2);
4439 builder->AddAssertion( 4426 builder->AddAssertion(
4440 new(zone()) RegExpAssertion(RegExpAssertion::NON_BOUNDARY)); 4427 new RegExpAssertion(RegExpAssertion::NON_BOUNDARY));
4441 continue; 4428 continue;
4442 // AtomEscape :: 4429 // AtomEscape ::
4443 // CharacterClassEscape 4430 // CharacterClassEscape
4444 // 4431 //
4445 // CharacterClassEscape :: one of 4432 // CharacterClassEscape :: one of
4446 // d D s S w W 4433 // d D s S w W
4447 case 'd': case 'D': case 's': case 'S': case 'w': case 'W': { 4434 case 'd': case 'D': case 's': case 'S': case 'w': case 'W': {
4448 uc32 c = Next(); 4435 uc32 c = Next();
4449 Advance(2); 4436 Advance(2);
4450 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); 4437 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2);
4451 CharacterRange::AddClassEscape(c, ranges); 4438 CharacterRange::AddClassEscape(c, ranges);
4452 RegExpTree* atom = new(zone()) RegExpCharacterClass(ranges, false); 4439 RegExpTree* atom = new RegExpCharacterClass(ranges, false);
4453 builder->AddAtom(atom); 4440 builder->AddAtom(atom);
4454 break; 4441 break;
4455 } 4442 }
4456 case '1': case '2': case '3': case '4': case '5': case '6': 4443 case '1': case '2': case '3': case '4': case '5': case '6':
4457 case '7': case '8': case '9': { 4444 case '7': case '8': case '9': {
4458 int index = 0; 4445 int index = 0;
4459 if (ParseBackReferenceIndex(&index)) { 4446 if (ParseBackReferenceIndex(&index)) {
4460 RegExpCapture* capture = NULL; 4447 RegExpCapture* capture = NULL;
4461 if (captures_ != NULL && index <= captures_->length()) { 4448 if (captures_ != NULL && index <= captures_->length()) {
4462 capture = captures_->at(index - 1); 4449 capture = captures_->at(index - 1);
4463 } 4450 }
4464 if (capture == NULL) { 4451 if (capture == NULL) {
4465 builder->AddEmpty(); 4452 builder->AddEmpty();
4466 break; 4453 break;
4467 } 4454 }
4468 RegExpTree* atom = new(zone()) RegExpBackReference(capture); 4455 RegExpTree* atom = new RegExpBackReference(capture);
4469 builder->AddAtom(atom); 4456 builder->AddAtom(atom);
4470 break; 4457 break;
4471 } 4458 }
4472 uc32 first_digit = Next(); 4459 uc32 first_digit = Next();
4473 if (first_digit == '8' || first_digit == '9') { 4460 if (first_digit == '8' || first_digit == '9') {
4474 // Treat as identity escape 4461 // Treat as identity escape
4475 builder->AddCharacter(first_digit); 4462 builder->AddCharacter(first_digit);
4476 Advance(2); 4463 Advance(2);
4477 break; 4464 break;
4478 } 4465 }
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
4976 } 4963 }
4977 } 4964 }
4978 if (!has_more()) { 4965 if (!has_more()) {
4979 return ReportError(CStrVector(kUnterminated) CHECK_FAILED); 4966 return ReportError(CStrVector(kUnterminated) CHECK_FAILED);
4980 } 4967 }
4981 Advance(); 4968 Advance();
4982 if (ranges->length() == 0) { 4969 if (ranges->length() == 0) {
4983 ranges->Add(CharacterRange::Everything()); 4970 ranges->Add(CharacterRange::Everything());
4984 is_negated = !is_negated; 4971 is_negated = !is_negated;
4985 } 4972 }
4986 return new(zone()) RegExpCharacterClass(ranges, is_negated); 4973 return new RegExpCharacterClass(ranges, is_negated);
4987 } 4974 }
4988 4975
4989 4976
4990 // ---------------------------------------------------------------------------- 4977 // ----------------------------------------------------------------------------
4991 // The Parser interface. 4978 // The Parser interface.
4992 4979
4993 ParserMessage::~ParserMessage() { 4980 ParserMessage::~ParserMessage() {
4994 for (int i = 0; i < args().length(); i++) 4981 for (int i = 0; i < args().length(); i++)
4995 DeleteArray(args()[i]); 4982 DeleteArray(args()[i]);
4996 DeleteArray(args().start()); 4983 DeleteArray(args().start());
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
5159 info->is_global(), 5146 info->is_global(),
5160 info->StrictMode()); 5147 info->StrictMode());
5161 } 5148 }
5162 } 5149 }
5163 5150
5164 info->SetFunction(result); 5151 info->SetFunction(result);
5165 return (result != NULL); 5152 return (result != NULL);
5166 } 5153 }
5167 5154
5168 } } // namespace v8::internal 5155 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698