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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 explicit Statement(Type code) : code_(code) {} | 401 explicit Statement(Type code) : code_(code) {} |
402 Type code_; | 402 Type code_; |
403 }; | 403 }; |
404 | 404 |
405 enum SourceElements { | 405 enum SourceElements { |
406 kUnknownSourceElements | 406 kUnknownSourceElements |
407 }; | 407 }; |
408 | 408 |
409 typedef int Arguments; | 409 typedef int Arguments; |
410 | 410 |
411 // The Strict Mode (ECMA-262 5th edition, 4.2.2). | |
412 enum StrictModeFlag { | |
413 kNonStrictMode, | |
414 kStrictMode, | |
415 // This value is never used, but is needed to prevent GCC 4.5 from failing | |
416 // to compile when we assert that a flag is either kNonStrictMode or | |
417 // kStrictMode. | |
418 kInvalidStrictFlag | |
419 }; | |
420 | |
421 class Scope { | 411 class Scope { |
422 public: | 412 public: |
423 Scope(Scope** variable, ScopeType type) | 413 Scope(Scope** variable, ScopeType type) |
424 : variable_(variable), | 414 : variable_(variable), |
425 prev_(*variable), | 415 prev_(*variable), |
426 type_(type), | 416 type_(type), |
427 materialized_literal_count_(0), | 417 materialized_literal_count_(0), |
428 expected_properties_(0), | 418 expected_properties_(0), |
429 with_nesting_count_(0), | 419 with_nesting_count_(0), |
430 strict_mode_flag_((prev_ != NULL) ? prev_->strict_mode_flag() | 420 strict_mode_flag_((prev_ != NULL) ? prev_->strict_mode_flag() |
431 : kNonStrictMode) { | 421 : i::kNonStrictMode) { |
432 *variable = this; | 422 *variable = this; |
433 } | 423 } |
434 ~Scope() { *variable_ = prev_; } | 424 ~Scope() { *variable_ = prev_; } |
435 void NextMaterializedLiteralIndex() { materialized_literal_count_++; } | 425 void NextMaterializedLiteralIndex() { materialized_literal_count_++; } |
436 void AddProperty() { expected_properties_++; } | 426 void AddProperty() { expected_properties_++; } |
437 ScopeType type() { return type_; } | 427 ScopeType type() { return type_; } |
438 int expected_properties() { return expected_properties_; } | 428 int expected_properties() { return expected_properties_; } |
439 int materialized_literal_count() { return materialized_literal_count_; } | 429 int materialized_literal_count() { return materialized_literal_count_; } |
440 bool IsInsideWith() { return with_nesting_count_ != 0; } | 430 bool IsInsideWith() { return with_nesting_count_ != 0; } |
441 bool is_strict_mode() { return strict_mode_flag_ == kStrictMode; } | 431 bool is_strict_mode() { return strict_mode_flag_ == i::kStrictMode; } |
442 StrictModeFlag strict_mode_flag() { | 432 i::StrictModeFlag strict_mode_flag() { |
443 return strict_mode_flag_; | 433 return strict_mode_flag_; |
444 } | 434 } |
445 void set_strict_mode_flag(StrictModeFlag strict_mode_flag) { | 435 void set_strict_mode_flag(i::StrictModeFlag strict_mode_flag) { |
446 strict_mode_flag_ = strict_mode_flag; | 436 strict_mode_flag_ = strict_mode_flag; |
447 } | 437 } |
448 void EnterWith() { with_nesting_count_++; } | 438 void EnterWith() { with_nesting_count_++; } |
449 void LeaveWith() { with_nesting_count_--; } | 439 void LeaveWith() { with_nesting_count_--; } |
450 | 440 |
451 private: | 441 private: |
452 Scope** const variable_; | 442 Scope** const variable_; |
453 Scope* const prev_; | 443 Scope* const prev_; |
454 const ScopeType type_; | 444 const ScopeType type_; |
455 int materialized_literal_count_; | 445 int materialized_literal_count_; |
456 int expected_properties_; | 446 int expected_properties_; |
457 int with_nesting_count_; | 447 int with_nesting_count_; |
458 StrictModeFlag strict_mode_flag_; | 448 i::StrictModeFlag strict_mode_flag_; |
459 }; | 449 }; |
460 | 450 |
461 // Private constructor only used in PreParseProgram. | 451 // Private constructor only used in PreParseProgram. |
462 PreParser(i::JavaScriptScanner* scanner, | 452 PreParser(i::JavaScriptScanner* scanner, |
463 i::ParserRecorder* log, | 453 i::ParserRecorder* log, |
464 uintptr_t stack_limit, | 454 uintptr_t stack_limit, |
465 bool allow_lazy, | 455 bool allow_lazy, |
466 bool allow_natives_syntax) | 456 bool allow_natives_syntax) |
467 : scanner_(scanner), | 457 : scanner_(scanner), |
468 log_(log), | 458 log_(log), |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 // have been seen using peek. | 574 // have been seen using peek. |
585 stack_overflow_ = true; | 575 stack_overflow_ = true; |
586 } | 576 } |
587 } | 577 } |
588 return scanner_->Next(); | 578 return scanner_->Next(); |
589 } | 579 } |
590 | 580 |
591 bool peek_any_identifier(); | 581 bool peek_any_identifier(); |
592 | 582 |
593 void set_strict_mode() { | 583 void set_strict_mode() { |
594 scope_->set_strict_mode_flag(kStrictMode); | 584 scope_->set_strict_mode_flag(i::kStrictMode); |
595 } | 585 } |
596 | 586 |
597 bool strict_mode() { return scope_->strict_mode_flag() == kStrictMode; } | 587 bool strict_mode() { return scope_->strict_mode_flag() == i::kStrictMode; } |
| 588 |
| 589 i::StrictModeFlag strict_mode_flag() { return scope_->strict_mode_flag(); } |
598 | 590 |
599 void Consume(i::Token::Value token) { Next(); } | 591 void Consume(i::Token::Value token) { Next(); } |
600 | 592 |
601 void Expect(i::Token::Value token, bool* ok) { | 593 void Expect(i::Token::Value token, bool* ok) { |
602 if (Next() != token) { | 594 if (Next() != token) { |
603 *ok = false; | 595 *ok = false; |
604 } | 596 } |
605 } | 597 } |
606 | 598 |
607 bool Check(i::Token::Value token) { | 599 bool Check(i::Token::Value token) { |
(...skipping 27 matching lines...) Expand all Loading... |
635 const char* strict_mode_violation_type_; | 627 const char* strict_mode_violation_type_; |
636 bool stack_overflow_; | 628 bool stack_overflow_; |
637 bool allow_lazy_; | 629 bool allow_lazy_; |
638 bool allow_natives_syntax_; | 630 bool allow_natives_syntax_; |
639 bool parenthesized_function_; | 631 bool parenthesized_function_; |
640 bool harmony_scoping_; | 632 bool harmony_scoping_; |
641 }; | 633 }; |
642 } } // v8::preparser | 634 } } // v8::preparser |
643 | 635 |
644 #endif // V8_PREPARSER_H | 636 #endif // V8_PREPARSER_H |
OLD | NEW |