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

Side by Side Diff: src/preparser.h

Issue 8417035: Introduce extended mode. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased to tip of tree. Created 9 years, 1 month 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
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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
Rico 2011/11/15 08:25:07 indention
Steven 2011/11/15 13:33:30 Done.
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_classic_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
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_classic_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
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_classic_mode() {
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_extended_mode() {
594 return scope_->language_mode() == i::EXTENDED_MODE;
595 }
596
597 i::LanguageMode language_mode() { return scope_->language_mode(); }
590 598
591 void Consume(i::Token::Value token) { Next(); } 599 void Consume(i::Token::Value token) { Next(); }
592 600
593 void Expect(i::Token::Value token, bool* ok) { 601 void Expect(i::Token::Value token, bool* ok) {
594 if (Next() != token) { 602 if (Next() != token) {
595 *ok = false; 603 *ok = false;
596 } 604 }
597 } 605 }
598 606
599 bool Check(i::Token::Value token) { 607 bool Check(i::Token::Value token) {
(...skipping 27 matching lines...) Expand all
627 const char* strict_mode_violation_type_; 635 const char* strict_mode_violation_type_;
628 bool stack_overflow_; 636 bool stack_overflow_;
629 bool allow_lazy_; 637 bool allow_lazy_;
630 bool allow_natives_syntax_; 638 bool allow_natives_syntax_;
631 bool parenthesized_function_; 639 bool parenthesized_function_;
632 bool harmony_scoping_; 640 bool harmony_scoping_;
633 }; 641 };
634 } } // v8::preparser 642 } } // v8::preparser
635 643
636 #endif // V8_PREPARSER_H 644 #endif // V8_PREPARSER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698