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

Side by Side Diff: src/parser.cc

Issue 7904008: Introduce with scope and rework variable resolution. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Removed tracking of 'with' from parser and variable proxies. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | src/scopes.h » ('j') | src/scopes.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 unsigned ScriptDataImpl::Read(int position) { 400 unsigned ScriptDataImpl::Read(int position) {
401 return store_[PreparseDataConstants::kHeaderSize + position]; 401 return store_[PreparseDataConstants::kHeaderSize + position];
402 } 402 }
403 403
404 404
405 unsigned* ScriptDataImpl::ReadAddress(int position) { 405 unsigned* ScriptDataImpl::ReadAddress(int position) {
406 return &store_[PreparseDataConstants::kHeaderSize + position]; 406 return &store_[PreparseDataConstants::kHeaderSize + position];
407 } 407 }
408 408
409 409
410 Scope* Parser::NewScope(Scope* parent, Scope::Type type, bool inside_with) { 410 Scope* Parser::NewScope(Scope* parent, Scope::Type type) {
411 Scope* result = new(zone()) Scope(parent, type); 411 Scope* result = new(zone()) Scope(parent, type);
412 result->Initialize(inside_with); 412 result->Initialize();
413 return result; 413 return result;
414 } 414 }
415 415
416 416
417 // ---------------------------------------------------------------------------- 417 // ----------------------------------------------------------------------------
418 // Target is a support class to facilitate manipulation of the 418 // Target is a support class to facilitate manipulation of the
419 // Parser's target_stack_ (the stack of potential 'break' and 419 // Parser's target_stack_ (the stack of potential 'break' and
420 // 'continue' statement targets). Upon construction, a new target is 420 // 'continue' statement targets). Upon construction, a new target is
421 // added; it is removed upon destruction. 421 // added; it is removed upon destruction.
422 422
(...skipping 29 matching lines...) Expand all
452 *variable_ = previous_; 452 *variable_ = previous_;
453 } 453 }
454 454
455 private: 455 private:
456 Target** variable_; 456 Target** variable_;
457 Target* previous_; 457 Target* previous_;
458 }; 458 };
459 459
460 460
461 // ---------------------------------------------------------------------------- 461 // ----------------------------------------------------------------------------
462 // LexicalScope is a support class to facilitate manipulation of the 462 // LexicalScope and SaveScope are support classes to facilitate manipulation of
463 // Parser's scope stack. The constructor sets the parser's top scope 463 // the Parser's scope stack. The constructor sets the parser's top scope to the
464 // to the incoming scope, and the destructor resets it. 464 // incoming scope, and the destructor resets it.
465 // 465 //
466 // Additionally, it stores transient information used during parsing. 466 // Additionally, LexicalScope stores transient information used during parsing.
467 // These scopes are not kept around after parsing or referenced by syntax 467 // These scopes are not kept around after parsing or referenced by syntax trees
Kevin Millikin (Chromium) 2011/09/16 12:58:19 Does the preparser still use these guys? If not w
Steven 2011/09/16 18:29:52 There is PreParser::Scope that remotely correspond
468 // trees so they can be stack-allocated and hence used by the pre-parser. 468 // so they can be stack-allocated and hence used by the pre-parser.
469
470
471 class SaveScope BASE_EMBEDDED {
472 public:
473 SaveScope(Parser* parser, Scope* scope)
474 : parser_(parser),
475 previous_top_scope_(parser->top_scope_) {
476 parser->top_scope_ = scope;
477 }
478
479 ~SaveScope() {
480 parser_->top_scope_ = previous_top_scope_;
481 }
482
483 private:
484 // Bookkeeping
485 Parser* parser_;
486 // Previous values
487 Scope* previous_top_scope_;
488 };
489
469 490
470 class LexicalScope BASE_EMBEDDED { 491 class LexicalScope BASE_EMBEDDED {
471 public: 492 public:
472 LexicalScope(Parser* parser, Scope* scope, Isolate* isolate); 493 LexicalScope(Parser* parser, Scope* scope, Isolate* isolate);
473 ~LexicalScope(); 494 ~LexicalScope();
474 495
475 int NextMaterializedLiteralIndex() { 496 int NextMaterializedLiteralIndex() {
476 int next_index = 497 int next_index =
477 materialized_literal_count_ + JSFunction::kLiteralsPrefixSize; 498 materialized_literal_count_ + JSFunction::kLiteralsPrefixSize;
478 materialized_literal_count_++; 499 materialized_literal_count_++;
(...skipping 30 matching lines...) Expand all
509 // Keeps track of assignments to properties of this. Used for 530 // Keeps track of assignments to properties of this. Used for
510 // optimizing constructors. 531 // optimizing constructors.
511 bool only_simple_this_property_assignments_; 532 bool only_simple_this_property_assignments_;
512 Handle<FixedArray> this_property_assignments_; 533 Handle<FixedArray> this_property_assignments_;
513 534
514 // Bookkeeping 535 // Bookkeeping
515 Parser* parser_; 536 Parser* parser_;
516 // Previous values 537 // Previous values
517 LexicalScope* lexical_scope_parent_; 538 LexicalScope* lexical_scope_parent_;
518 Scope* previous_scope_; 539 Scope* previous_scope_;
519 int previous_with_nesting_level_;
520 unsigned previous_ast_node_id_; 540 unsigned previous_ast_node_id_;
521 }; 541 };
522 542
523 543
524 LexicalScope::LexicalScope(Parser* parser, Scope* scope, Isolate* isolate) 544 LexicalScope::LexicalScope(Parser* parser, Scope* scope, Isolate* isolate)
525 : materialized_literal_count_(0), 545 : materialized_literal_count_(0),
526 expected_property_count_(0), 546 expected_property_count_(0),
527 only_simple_this_property_assignments_(false), 547 only_simple_this_property_assignments_(false),
528 this_property_assignments_(isolate->factory()->empty_fixed_array()), 548 this_property_assignments_(isolate->factory()->empty_fixed_array()),
529 parser_(parser), 549 parser_(parser),
530 lexical_scope_parent_(parser->lexical_scope_), 550 lexical_scope_parent_(parser->lexical_scope_),
531 previous_scope_(parser->top_scope_), 551 previous_scope_(parser->top_scope_),
532 previous_with_nesting_level_(parser->with_nesting_level_),
533 previous_ast_node_id_(isolate->ast_node_id()) { 552 previous_ast_node_id_(isolate->ast_node_id()) {
534 parser->top_scope_ = scope; 553 parser->top_scope_ = scope;
535 parser->lexical_scope_ = this; 554 parser->lexical_scope_ = this;
536 parser->with_nesting_level_ = 0;
537 isolate->set_ast_node_id(AstNode::kDeclarationsId + 1); 555 isolate->set_ast_node_id(AstNode::kDeclarationsId + 1);
538 } 556 }
539 557
540 558
541 LexicalScope::~LexicalScope() { 559 LexicalScope::~LexicalScope() {
542 parser_->top_scope_ = previous_scope_; 560 parser_->top_scope_ = previous_scope_;
543 parser_->lexical_scope_ = lexical_scope_parent_; 561 parser_->lexical_scope_ = lexical_scope_parent_;
544 parser_->with_nesting_level_ = previous_with_nesting_level_;
545 parser_->isolate()->set_ast_node_id(previous_ast_node_id_); 562 parser_->isolate()->set_ast_node_id(previous_ast_node_id_);
546 } 563 }
547 564
548 565
549 // ---------------------------------------------------------------------------- 566 // ----------------------------------------------------------------------------
550 // The CHECK_OK macro is a convenient macro to enforce error 567 // The CHECK_OK macro is a convenient macro to enforce error
551 // handling for functions that may fail (by returning !*ok). 568 // handling for functions that may fail (by returning !*ok).
552 // 569 //
553 // CAUTION: This macro appends extra statements after a call, 570 // CAUTION: This macro appends extra statements after a call,
554 // thus it must never be used where only a single statement 571 // thus it must never be used where only a single statement
(...skipping 16 matching lines...) Expand all
571 588
572 Parser::Parser(Handle<Script> script, 589 Parser::Parser(Handle<Script> script,
573 bool allow_natives_syntax, 590 bool allow_natives_syntax,
574 v8::Extension* extension, 591 v8::Extension* extension,
575 ScriptDataImpl* pre_data) 592 ScriptDataImpl* pre_data)
576 : isolate_(script->GetIsolate()), 593 : isolate_(script->GetIsolate()),
577 symbol_cache_(pre_data ? pre_data->symbol_count() : 0), 594 symbol_cache_(pre_data ? pre_data->symbol_count() : 0),
578 script_(script), 595 script_(script),
579 scanner_(isolate_->unicode_cache()), 596 scanner_(isolate_->unicode_cache()),
580 top_scope_(NULL), 597 top_scope_(NULL),
581 with_nesting_level_(0),
582 lexical_scope_(NULL), 598 lexical_scope_(NULL),
583 target_stack_(NULL), 599 target_stack_(NULL),
584 allow_natives_syntax_(allow_natives_syntax), 600 allow_natives_syntax_(allow_natives_syntax),
585 extension_(extension), 601 extension_(extension),
586 pre_data_(pre_data), 602 pre_data_(pre_data),
587 fni_(NULL), 603 fni_(NULL),
588 stack_overflow_(false), 604 stack_overflow_(false),
589 parenthesized_function_(false), 605 parenthesized_function_(false),
590 harmony_block_scoping_(false) { 606 harmony_block_scoping_(false) {
591 AstNode::ResetIds(); 607 AstNode::ResetIds();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY; 646 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY;
631 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; 647 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY;
632 648
633 Scope::Type type = 649 Scope::Type type =
634 in_global_context 650 in_global_context
635 ? Scope::GLOBAL_SCOPE 651 ? Scope::GLOBAL_SCOPE
636 : Scope::EVAL_SCOPE; 652 : Scope::EVAL_SCOPE;
637 Handle<String> no_name = isolate()->factory()->empty_symbol(); 653 Handle<String> no_name = isolate()->factory()->empty_symbol();
638 654
639 FunctionLiteral* result = NULL; 655 FunctionLiteral* result = NULL;
640 { Scope* scope = NewScope(top_scope_, type, inside_with()); 656 { Scope* scope = NewScope(top_scope_, type);
641 LexicalScope lexical_scope(this, scope, isolate()); 657 LexicalScope lexical_scope(this, scope, isolate());
642 if (strict_mode == kStrictMode) { 658 if (strict_mode == kStrictMode) {
643 top_scope_->EnableStrictMode(); 659 top_scope_->EnableStrictMode();
644 } 660 }
645 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16); 661 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16);
646 bool ok = true; 662 bool ok = true;
647 int beg_loc = scanner().location().beg_pos; 663 int beg_loc = scanner().location().beg_pos;
648 ParseSourceElements(body, Token::EOS, &ok); 664 ParseSourceElements(body, Token::EOS, &ok);
649 if (ok && top_scope_->is_strict_mode()) { 665 if (ok && top_scope_->is_strict_mode()) {
650 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); 666 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 fni_ = new(zone()) FuncNameInferrer(isolate()); 736 fni_ = new(zone()) FuncNameInferrer(isolate());
721 fni_->PushEnclosingName(name); 737 fni_->PushEnclosingName(name);
722 738
723 mode_ = PARSE_EAGERLY; 739 mode_ = PARSE_EAGERLY;
724 740
725 // Place holder for the result. 741 // Place holder for the result.
726 FunctionLiteral* result = NULL; 742 FunctionLiteral* result = NULL;
727 743
728 { 744 {
729 // Parse the function literal. 745 // Parse the function literal.
730 Scope* scope = NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with()); 746 Scope* scope = NewScope(top_scope_, Scope::GLOBAL_SCOPE);
731 if (!info->closure().is_null()) { 747 if (!info->closure().is_null()) {
732 scope = Scope::DeserializeScopeChain(info, scope); 748 scope = Scope::DeserializeScopeChain(info, scope);
733 } 749 }
734 LexicalScope lexical_scope(this, scope, isolate()); 750 LexicalScope lexical_scope(this, scope, isolate());
735 751
736 if (shared_info->strict_mode()) { 752 if (shared_info->strict_mode()) {
737 top_scope_->EnableStrictMode(); 753 top_scope_->EnableStrictMode();
738 } 754 }
739 755
740 FunctionLiteral::Type type = shared_info->is_expression() 756 FunctionLiteral::Type type = shared_info->is_expression()
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 // parameters) if the proxy is needed or not. The proxy will be 1414 // parameters) if the proxy is needed or not. The proxy will be
1399 // bound during variable resolution time unless it was pre-bound 1415 // bound during variable resolution time unless it was pre-bound
1400 // below. 1416 // below.
1401 // 1417 //
1402 // WARNING: This will lead to multiple declaration nodes for the 1418 // WARNING: This will lead to multiple declaration nodes for the
1403 // same variable if it is declared several times. This is not a 1419 // same variable if it is declared several times. This is not a
1404 // semantic issue as long as we keep the source order, but it may be 1420 // semantic issue as long as we keep the source order, but it may be
1405 // a performance issue since it may lead to repeated 1421 // a performance issue since it may lead to repeated
1406 // Runtime::DeclareContextSlot() calls. 1422 // Runtime::DeclareContextSlot() calls.
1407 VariableProxy* proxy = declaration_scope->NewUnresolved( 1423 VariableProxy* proxy = declaration_scope->NewUnresolved(
1408 name, false, scanner().location().beg_pos); 1424 name, scanner().location().beg_pos);
1409 declaration_scope->AddDeclaration( 1425 declaration_scope->AddDeclaration(
1410 new(zone()) Declaration(proxy, mode, fun, top_scope_)); 1426 new(zone()) Declaration(proxy, mode, fun, top_scope_));
1411 1427
1412 // For global const variables we bind the proxy to a variable. 1428 // For global const variables we bind the proxy to a variable.
1413 if (mode == Variable::CONST && declaration_scope->is_global_scope()) { 1429 if (mode == Variable::CONST && declaration_scope->is_global_scope()) {
1414 ASSERT(resolve); // should be set by all callers 1430 ASSERT(resolve); // should be set by all callers
1415 Variable::Kind kind = Variable::NORMAL; 1431 Variable::Kind kind = Variable::NORMAL;
1416 var = new(zone()) Variable(declaration_scope, 1432 var = new(zone()) Variable(declaration_scope,
1417 name, 1433 name,
1418 Variable::CONST, 1434 Variable::CONST,
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 } 1566 }
1551 } 1567 }
1552 Expect(Token::RBRACE, CHECK_OK); 1568 Expect(Token::RBRACE, CHECK_OK);
1553 return result; 1569 return result;
1554 } 1570 }
1555 1571
1556 1572
1557 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) { 1573 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) {
1558 // Construct block expecting 16 statements. 1574 // Construct block expecting 16 statements.
1559 Block* body = new(zone()) Block(isolate(), labels, 16, false); 1575 Block* body = new(zone()) Block(isolate(), labels, 16, false);
1560 Scope* saved_scope = top_scope_; 1576 Scope* block_scope = NewScope(top_scope_, Scope::BLOCK_SCOPE);
1561 Scope* block_scope = NewScope(top_scope_,
1562 Scope::BLOCK_SCOPE,
1563 inside_with());
1564 if (top_scope_->is_strict_mode()) { 1577 if (top_scope_->is_strict_mode()) {
1565 block_scope->EnableStrictMode(); 1578 block_scope->EnableStrictMode();
1566 } 1579 }
1567 top_scope_ = block_scope;
1568 1580
1569 // Parse the statements and collect escaping labels. 1581 // Parse the statements and collect escaping labels.
1570 TargetCollector collector;
1571 Target target(&this->target_stack_, &collector);
1572 Expect(Token::LBRACE, CHECK_OK); 1582 Expect(Token::LBRACE, CHECK_OK);
1573 { 1583 { SaveScope save_scope(this, block_scope);
1584 TargetCollector collector;
1585 Target target(&this->target_stack_, &collector);
1574 Target target_body(&this->target_stack_, body); 1586 Target target_body(&this->target_stack_, body);
1575 InitializationBlockFinder block_finder(top_scope_, target_stack_); 1587 InitializationBlockFinder block_finder(top_scope_, target_stack_);
1576 1588
1577 while (peek() != Token::RBRACE) { 1589 while (peek() != Token::RBRACE) {
1578 Statement* stat = ParseSourceElement(NULL, CHECK_OK); 1590 Statement* stat = ParseSourceElement(NULL, CHECK_OK);
1579 if (stat && !stat->IsEmpty()) { 1591 if (stat && !stat->IsEmpty()) {
1580 body->AddStatement(stat); 1592 body->AddStatement(stat);
1581 block_finder.Update(stat); 1593 block_finder.Update(stat);
1582 } 1594 }
1583 } 1595 }
1584 } 1596 }
1585 Expect(Token::RBRACE, CHECK_OK); 1597 Expect(Token::RBRACE, CHECK_OK);
1586 top_scope_ = saved_scope;
1587 1598
1588 block_scope = block_scope->FinalizeBlockScope(); 1599 block_scope = block_scope->FinalizeBlockScope();
1589 body->set_block_scope(block_scope); 1600 body->set_block_scope(block_scope);
1590 return body; 1601 return body;
1591 } 1602 }
1592 1603
1593 1604
1594 Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context, 1605 Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context,
1595 bool* ok) { 1606 bool* ok) {
1596 // VariableStatement :: 1607 // VariableStatement ::
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
2071 if (top_scope_->is_strict_mode()) { 2082 if (top_scope_->is_strict_mode()) {
2072 ReportMessage("strict_mode_with", Vector<const char*>::empty()); 2083 ReportMessage("strict_mode_with", Vector<const char*>::empty());
2073 *ok = false; 2084 *ok = false;
2074 return NULL; 2085 return NULL;
2075 } 2086 }
2076 2087
2077 Expect(Token::LPAREN, CHECK_OK); 2088 Expect(Token::LPAREN, CHECK_OK);
2078 Expression* expr = ParseExpression(true, CHECK_OK); 2089 Expression* expr = ParseExpression(true, CHECK_OK);
2079 Expect(Token::RPAREN, CHECK_OK); 2090 Expect(Token::RPAREN, CHECK_OK);
2080 2091
2081 ++with_nesting_level_;
2082 top_scope_->DeclarationScope()->RecordWithStatement(); 2092 top_scope_->DeclarationScope()->RecordWithStatement();
2083 Statement* stmt = ParseStatement(labels, CHECK_OK); 2093 Scope* with_scope = NewScope(top_scope_, Scope::WITH_SCOPE);
2084 --with_nesting_level_; 2094 Statement* stmt;
2095 { SaveScope save_scope(this, with_scope);
2096 stmt = ParseStatement(labels, CHECK_OK);
2097 }
2085 return new(zone()) WithStatement(expr, stmt); 2098 return new(zone()) WithStatement(expr, stmt);
2086 } 2099 }
2087 2100
2088 2101
2089 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { 2102 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) {
2090 // CaseClause :: 2103 // CaseClause ::
2091 // 'case' Expression ':' Statement* 2104 // 'case' Expression ':' Statement*
2092 // 'default' ':' Statement* 2105 // 'default' ':' Statement*
2093 2106
2094 Expression* label = NULL; // NULL expression indicates default case 2107 Expression* label = NULL; // NULL expression indicates default case
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
2211 if (top_scope_->is_strict_mode() && IsEvalOrArguments(name)) { 2224 if (top_scope_->is_strict_mode() && IsEvalOrArguments(name)) {
2212 ReportMessage("strict_catch_variable", Vector<const char*>::empty()); 2225 ReportMessage("strict_catch_variable", Vector<const char*>::empty());
2213 *ok = false; 2226 *ok = false;
2214 return NULL; 2227 return NULL;
2215 } 2228 }
2216 2229
2217 Expect(Token::RPAREN, CHECK_OK); 2230 Expect(Token::RPAREN, CHECK_OK);
2218 2231
2219 if (peek() == Token::LBRACE) { 2232 if (peek() == Token::LBRACE) {
2220 Target target(&this->target_stack_, &catch_collector); 2233 Target target(&this->target_stack_, &catch_collector);
2221 catch_scope = NewScope(top_scope_, Scope::CATCH_SCOPE, inside_with()); 2234 catch_scope = NewScope(top_scope_, Scope::CATCH_SCOPE);
2222 if (top_scope_->is_strict_mode()) { 2235 if (top_scope_->is_strict_mode()) {
2223 catch_scope->EnableStrictMode(); 2236 catch_scope->EnableStrictMode();
2224 } 2237 }
2225 Variable::Mode mode = harmony_block_scoping_ 2238 Variable::Mode mode = harmony_block_scoping_
2226 ? Variable::LET : Variable::VAR; 2239 ? Variable::LET : Variable::VAR;
2227 catch_variable = catch_scope->DeclareLocal(name, mode); 2240 catch_variable = catch_scope->DeclareLocal(name, mode);
2228 2241
2229 Scope* saved_scope = top_scope_; 2242 SaveScope save_scope(this, catch_scope);
2230 top_scope_ = catch_scope;
2231 catch_block = ParseBlock(NULL, CHECK_OK); 2243 catch_block = ParseBlock(NULL, CHECK_OK);
2232 top_scope_ = saved_scope;
2233 } else { 2244 } else {
2234 Expect(Token::LBRACE, CHECK_OK); 2245 Expect(Token::LBRACE, CHECK_OK);
2235 } 2246 }
2236 2247
2237 tok = peek(); 2248 tok = peek();
2238 } 2249 }
2239 2250
2240 Block* finally_block = NULL; 2251 Block* finally_block = NULL;
2241 if (tok == Token::FINALLY || catch_block == NULL) { 2252 if (tok == Token::FINALLY || catch_block == NULL) {
2242 Consume(Token::FINALLY); 2253 Consume(Token::FINALLY);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2341 2352
2342 Expect(Token::FOR, CHECK_OK); 2353 Expect(Token::FOR, CHECK_OK);
2343 Expect(Token::LPAREN, CHECK_OK); 2354 Expect(Token::LPAREN, CHECK_OK);
2344 if (peek() != Token::SEMICOLON) { 2355 if (peek() != Token::SEMICOLON) {
2345 if (peek() == Token::VAR || peek() == Token::CONST) { 2356 if (peek() == Token::VAR || peek() == Token::CONST) {
2346 Handle<String> name; 2357 Handle<String> name;
2347 Block* variable_statement = 2358 Block* variable_statement =
2348 ParseVariableDeclarations(kForStatement, &name, CHECK_OK); 2359 ParseVariableDeclarations(kForStatement, &name, CHECK_OK);
2349 2360
2350 if (peek() == Token::IN && !name.is_null()) { 2361 if (peek() == Token::IN && !name.is_null()) {
2351 VariableProxy* each = top_scope_->NewUnresolved(name, inside_with()); 2362 VariableProxy* each = top_scope_->NewUnresolved(name);
2352 ForInStatement* loop = new(zone()) ForInStatement(isolate(), labels); 2363 ForInStatement* loop = new(zone()) ForInStatement(isolate(), labels);
2353 Target target(&this->target_stack_, loop); 2364 Target target(&this->target_stack_, loop);
2354 2365
2355 Expect(Token::IN, CHECK_OK); 2366 Expect(Token::IN, CHECK_OK);
2356 Expression* enumerable = ParseExpression(true, CHECK_OK); 2367 Expression* enumerable = ParseExpression(true, CHECK_OK);
2357 Expect(Token::RPAREN, CHECK_OK); 2368 Expect(Token::RPAREN, CHECK_OK);
2358 2369
2359 Statement* body = ParseStatement(NULL, CHECK_OK); 2370 Statement* body = ParseStatement(NULL, CHECK_OK);
2360 loop->Initialize(each, enumerable, body); 2371 loop->Initialize(each, enumerable, body);
2361 Block* result = new(zone()) Block(isolate(), NULL, 2, false); 2372 Block* result = new(zone()) Block(isolate(), NULL, 2, false);
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
3051 case Token::FALSE_LITERAL: 3062 case Token::FALSE_LITERAL:
3052 Consume(Token::FALSE_LITERAL); 3063 Consume(Token::FALSE_LITERAL);
3053 result = new(zone()) Literal( 3064 result = new(zone()) Literal(
3054 isolate(), isolate()->factory()->false_value()); 3065 isolate(), isolate()->factory()->false_value());
3055 break; 3066 break;
3056 3067
3057 case Token::IDENTIFIER: 3068 case Token::IDENTIFIER:
3058 case Token::FUTURE_STRICT_RESERVED_WORD: { 3069 case Token::FUTURE_STRICT_RESERVED_WORD: {
3059 Handle<String> name = ParseIdentifier(CHECK_OK); 3070 Handle<String> name = ParseIdentifier(CHECK_OK);
3060 if (fni_ != NULL) fni_->PushVariableName(name); 3071 if (fni_ != NULL) fni_->PushVariableName(name);
3061 result = top_scope_->NewUnresolved(name, 3072 result = top_scope_->NewUnresolved(name, scanner().location().beg_pos);
3062 inside_with(),
3063 scanner().location().beg_pos);
3064 break; 3073 break;
3065 } 3074 }
3066 3075
3067 case Token::NUMBER: { 3076 case Token::NUMBER: {
3068 Consume(Token::NUMBER); 3077 Consume(Token::NUMBER);
3069 ASSERT(scanner().is_literal_ascii()); 3078 ASSERT(scanner().is_literal_ascii());
3070 double value = StringToDouble(isolate()->unicode_cache(), 3079 double value = StringToDouble(isolate()->unicode_cache(),
3071 scanner().literal_ascii_string(), 3080 scanner().literal_ascii_string(),
3072 ALLOW_HEX | ALLOW_OCTALS); 3081 ALLOW_HEX | ALLOW_OCTALS);
3073 result = NewNumberLiteral(value); 3082 result = NewNumberLiteral(value);
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
3702 if (should_infer_name) { 3711 if (should_infer_name) {
3703 function_name = isolate()->factory()->empty_symbol(); 3712 function_name = isolate()->factory()->empty_symbol();
3704 } 3713 }
3705 3714
3706 int num_parameters = 0; 3715 int num_parameters = 0;
3707 // Function declarations are function scoped in normal mode, so they are 3716 // Function declarations are function scoped in normal mode, so they are
3708 // hoisted. In harmony block scoping mode they are block scoped, so they 3717 // hoisted. In harmony block scoping mode they are block scoped, so they
3709 // are not hoisted. 3718 // are not hoisted.
3710 Scope* scope = (type == FunctionLiteral::DECLARATION && 3719 Scope* scope = (type == FunctionLiteral::DECLARATION &&
3711 !harmony_block_scoping_) 3720 !harmony_block_scoping_)
3712 ? NewScope(top_scope_->DeclarationScope(), Scope::FUNCTION_SCOPE, false) 3721 ? NewScope(top_scope_->DeclarationScope(), Scope::FUNCTION_SCOPE)
3713 : NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with()); 3722 : NewScope(top_scope_, Scope::FUNCTION_SCOPE);
3714 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8); 3723 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8);
3715 int materialized_literal_count; 3724 int materialized_literal_count;
3716 int expected_property_count; 3725 int expected_property_count;
3717 int start_pos; 3726 int start_pos;
3718 int end_pos; 3727 int end_pos;
3719 bool only_simple_this_property_assignments; 3728 bool only_simple_this_property_assignments;
3720 Handle<FixedArray> this_property_assignments; 3729 Handle<FixedArray> this_property_assignments;
3721 bool has_duplicate_parameters = false; 3730 bool has_duplicate_parameters = false;
3722 // Parse function body. 3731 // Parse function body.
3723 { LexicalScope lexical_scope(this, scope, isolate()); 3732 { LexicalScope lexical_scope(this, scope, isolate());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
3769 Expect(Token::LBRACE, CHECK_OK); 3778 Expect(Token::LBRACE, CHECK_OK);
3770 3779
3771 // If we have a named function expression, we add a local variable 3780 // If we have a named function expression, we add a local variable
3772 // declaration to the body of the function with the name of the 3781 // declaration to the body of the function with the name of the
3773 // function and let it refer to the function itself (closure). 3782 // function and let it refer to the function itself (closure).
3774 // NOTE: We create a proxy and resolve it here so that in the 3783 // NOTE: We create a proxy and resolve it here so that in the
3775 // future we can change the AST to only refer to VariableProxies 3784 // future we can change the AST to only refer to VariableProxies
3776 // instead of Variables and Proxis as is the case now. 3785 // instead of Variables and Proxis as is the case now.
3777 if (type == FunctionLiteral::NAMED_EXPRESSION) { 3786 if (type == FunctionLiteral::NAMED_EXPRESSION) {
3778 Variable* fvar = top_scope_->DeclareFunctionVar(function_name); 3787 Variable* fvar = top_scope_->DeclareFunctionVar(function_name);
3779 VariableProxy* fproxy = 3788 VariableProxy* fproxy = top_scope_->NewUnresolved(function_name);
3780 top_scope_->NewUnresolved(function_name, inside_with());
3781 fproxy->BindTo(fvar); 3789 fproxy->BindTo(fvar);
3782 body->Add(new(zone()) ExpressionStatement( 3790 body->Add(new(zone()) ExpressionStatement(
3783 new(zone()) Assignment(isolate(), 3791 new(zone()) Assignment(isolate(),
3784 Token::INIT_CONST, 3792 Token::INIT_CONST,
3785 fproxy, 3793 fproxy,
3786 new(zone()) ThisFunction(isolate()), 3794 new(zone()) ThisFunction(isolate()),
3787 RelocInfo::kNoPosition))); 3795 RelocInfo::kNoPosition)));
3788 } 3796 }
3789 3797
3790 // Determine if the function will be lazily compiled. The mode can only 3798 // Determine if the function will be lazily compiled. The mode can only
(...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after
5223 result = parser.ParseProgram(source, 5231 result = parser.ParseProgram(source,
5224 info->is_global(), 5232 info->is_global(),
5225 info->StrictMode()); 5233 info->StrictMode());
5226 } 5234 }
5227 } 5235 }
5228 info->SetFunction(result); 5236 info->SetFunction(result);
5229 return (result != NULL); 5237 return (result != NULL);
5230 } 5238 }
5231 5239
5232 } } // namespace v8::internal 5240 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/scopes.h » ('j') | src/scopes.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698