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

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

Powered by Google App Engine
This is Rietveld 408576698