OLD | NEW |
---|---|
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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 | 410 |
411 class Scope { | 411 class Scope { |
412 public: | 412 public: |
413 Scope(Scope** variable, ScopeType type) | 413 Scope(Scope** variable, ScopeType type) |
414 : variable_(variable), | 414 : variable_(variable), |
415 prev_(*variable), | 415 prev_(*variable), |
416 type_(type), | 416 type_(type), |
417 materialized_literal_count_(0), | 417 materialized_literal_count_(0), |
418 expected_properties_(0), | 418 expected_properties_(0), |
419 with_nesting_count_(0), | 419 with_nesting_count_(0), |
420 strict_mode_flag_((prev_ != NULL) ? prev_->strict_mode_flag() | 420 language_mode_((prev_ != NULL) ? prev_->language_mode() |
421 : i::kNonStrictMode) { | 421 : i::CLASSIC_MODE) { |
422 *variable = this; | 422 *variable = this; |
423 } | 423 } |
424 ~Scope() { *variable_ = prev_; } | 424 ~Scope() { *variable_ = prev_; } |
425 void NextMaterializedLiteralIndex() { materialized_literal_count_++; } | 425 void NextMaterializedLiteralIndex() { materialized_literal_count_++; } |
426 void AddProperty() { expected_properties_++; } | 426 void AddProperty() { expected_properties_++; } |
427 ScopeType type() { return type_; } | 427 ScopeType type() { return type_; } |
428 int expected_properties() { return expected_properties_; } | 428 int expected_properties() { return expected_properties_; } |
429 int materialized_literal_count() { return materialized_literal_count_; } | 429 int materialized_literal_count() { return materialized_literal_count_; } |
430 bool IsInsideWith() { return with_nesting_count_ != 0; } | 430 bool IsInsideWith() { return with_nesting_count_ != 0; } |
431 bool is_strict_mode() { return strict_mode_flag_ == i::kStrictMode; } | 431 bool is_strict_or_extended_mode() { |
432 i::StrictModeFlag strict_mode_flag() { | 432 return language_mode_ != i::CLASSIC_MODE; |
433 return strict_mode_flag_; | |
434 } | 433 } |
435 void set_strict_mode_flag(i::StrictModeFlag strict_mode_flag) { | 434 i::LanguageMode language_mode() { |
436 strict_mode_flag_ = strict_mode_flag; | 435 return language_mode_; |
436 } | |
437 void set_language_mode(i::LanguageMode language_mode) { | |
438 language_mode_ = language_mode; | |
437 } | 439 } |
438 void EnterWith() { with_nesting_count_++; } | 440 void EnterWith() { with_nesting_count_++; } |
439 void LeaveWith() { with_nesting_count_--; } | 441 void LeaveWith() { with_nesting_count_--; } |
440 | 442 |
441 private: | 443 private: |
442 Scope** const variable_; | 444 Scope** const variable_; |
443 Scope* const prev_; | 445 Scope* const prev_; |
444 const ScopeType type_; | 446 const ScopeType type_; |
445 int materialized_literal_count_; | 447 int materialized_literal_count_; |
446 int expected_properties_; | 448 int expected_properties_; |
447 int with_nesting_count_; | 449 int with_nesting_count_; |
448 i::StrictModeFlag strict_mode_flag_; | 450 i::LanguageMode language_mode_; |
449 }; | 451 }; |
450 | 452 |
451 // Private constructor only used in PreParseProgram. | 453 // Private constructor only used in PreParseProgram. |
452 PreParser(i::Scanner* scanner, | 454 PreParser(i::Scanner* scanner, |
453 i::ParserRecorder* log, | 455 i::ParserRecorder* log, |
454 uintptr_t stack_limit, | 456 uintptr_t stack_limit, |
455 bool allow_lazy, | 457 bool allow_lazy, |
456 bool allow_natives_syntax) | 458 bool allow_natives_syntax) |
457 : scanner_(scanner), | 459 : scanner_(scanner), |
458 log_(log), | 460 log_(log), |
(...skipping 10 matching lines...) Expand all Loading... | |
469 // Preparse the program. Only called in PreParseProgram after creating | 471 // Preparse the program. Only called in PreParseProgram after creating |
470 // the instance. | 472 // the instance. |
471 PreParseResult PreParse() { | 473 PreParseResult PreParse() { |
472 Scope top_scope(&scope_, kTopLevelScope); | 474 Scope top_scope(&scope_, kTopLevelScope); |
473 bool ok = true; | 475 bool ok = true; |
474 int start_position = scanner_->peek_location().beg_pos; | 476 int start_position = scanner_->peek_location().beg_pos; |
475 ParseSourceElements(i::Token::EOS, &ok); | 477 ParseSourceElements(i::Token::EOS, &ok); |
476 if (stack_overflow_) return kPreParseStackOverflow; | 478 if (stack_overflow_) return kPreParseStackOverflow; |
477 if (!ok) { | 479 if (!ok) { |
478 ReportUnexpectedToken(scanner_->current_token()); | 480 ReportUnexpectedToken(scanner_->current_token()); |
479 } else if (scope_->is_strict_mode()) { | 481 } else if (scope_->is_strict_or_extended_mode()) { |
480 CheckOctalLiteral(start_position, scanner_->location().end_pos, &ok); | 482 CheckOctalLiteral(start_position, scanner_->location().end_pos, &ok); |
481 } | 483 } |
482 return kPreParseSuccess; | 484 return kPreParseSuccess; |
483 } | 485 } |
484 | 486 |
485 // Report syntax error | 487 // Report syntax error |
486 void ReportUnexpectedToken(i::Token::Value token); | 488 void ReportUnexpectedToken(i::Token::Value token); |
487 void ReportMessageAt(i::Scanner::Location location, | 489 void ReportMessageAt(i::Scanner::Location location, |
488 const char* type, | 490 const char* type, |
489 const char* name_opt) { | 491 const char* name_opt) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
573 // The current one will still be returned. It might already | 575 // The current one will still be returned. It might already |
574 // have been seen using peek. | 576 // have been seen using peek. |
575 stack_overflow_ = true; | 577 stack_overflow_ = true; |
576 } | 578 } |
577 } | 579 } |
578 return scanner_->Next(); | 580 return scanner_->Next(); |
579 } | 581 } |
580 | 582 |
581 bool peek_any_identifier(); | 583 bool peek_any_identifier(); |
582 | 584 |
583 void set_strict_mode() { | 585 void set_language_mode(i::LanguageMode language_mode) { |
584 scope_->set_strict_mode_flag(i::kStrictMode); | 586 scope_->set_language_mode(language_mode); |
585 } | 587 } |
586 | 588 |
587 bool strict_mode() { return scope_->strict_mode_flag() == i::kStrictMode; } | 589 bool is_strict_or_extended_mode() { |
rossberg
2011/11/08 15:02:46
And here...
Steven
2011/11/08 16:13:49
Done.
| |
590 return scope_->language_mode() != i::CLASSIC_MODE; | |
591 } | |
588 | 592 |
589 i::StrictModeFlag strict_mode_flag() { return scope_->strict_mode_flag(); } | 593 bool is_classic_mode() { |
594 return scope_->language_mode() == i::CLASSIC_MODE; | |
595 } | |
596 | |
597 bool is_extended_mode() { | |
598 return scope_->language_mode() == i::EXTENDED_MODE; | |
599 } | |
600 | |
601 i::LanguageMode language_mode() { return scope_->language_mode(); } | |
590 | 602 |
591 void Consume(i::Token::Value token) { Next(); } | 603 void Consume(i::Token::Value token) { Next(); } |
592 | 604 |
593 void Expect(i::Token::Value token, bool* ok) { | 605 void Expect(i::Token::Value token, bool* ok) { |
594 if (Next() != token) { | 606 if (Next() != token) { |
595 *ok = false; | 607 *ok = false; |
596 } | 608 } |
597 } | 609 } |
598 | 610 |
599 bool Check(i::Token::Value token) { | 611 bool Check(i::Token::Value token) { |
(...skipping 27 matching lines...) Expand all Loading... | |
627 const char* strict_mode_violation_type_; | 639 const char* strict_mode_violation_type_; |
628 bool stack_overflow_; | 640 bool stack_overflow_; |
629 bool allow_lazy_; | 641 bool allow_lazy_; |
630 bool allow_natives_syntax_; | 642 bool allow_natives_syntax_; |
631 bool parenthesized_function_; | 643 bool parenthesized_function_; |
632 bool harmony_scoping_; | 644 bool harmony_scoping_; |
633 }; | 645 }; |
634 } } // v8::preparser | 646 } } // v8::preparser |
635 | 647 |
636 #endif // V8_PREPARSER_H | 648 #endif // V8_PREPARSER_H |
OLD | NEW |