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 |
411 class Scope { | 421 class Scope { |
412 public: | 422 public: |
413 Scope(Scope** variable, ScopeType type) | 423 Scope(Scope** variable, ScopeType type) |
414 : variable_(variable), | 424 : variable_(variable), |
415 prev_(*variable), | 425 prev_(*variable), |
416 type_(type), | 426 type_(type), |
417 materialized_literal_count_(0), | 427 materialized_literal_count_(0), |
418 expected_properties_(0), | 428 expected_properties_(0), |
419 with_nesting_count_(0), | 429 with_nesting_count_(0), |
420 strict_((prev_ != NULL) && prev_->is_strict()) { | 430 strict_mode_flag_((prev_ != NULL) ? prev_->strict_mode_flag() |
| 431 : kNonStrictMode) { |
421 *variable = this; | 432 *variable = this; |
422 } | 433 } |
423 ~Scope() { *variable_ = prev_; } | 434 ~Scope() { *variable_ = prev_; } |
424 void NextMaterializedLiteralIndex() { materialized_literal_count_++; } | 435 void NextMaterializedLiteralIndex() { materialized_literal_count_++; } |
425 void AddProperty() { expected_properties_++; } | 436 void AddProperty() { expected_properties_++; } |
426 ScopeType type() { return type_; } | 437 ScopeType type() { return type_; } |
427 int expected_properties() { return expected_properties_; } | 438 int expected_properties() { return expected_properties_; } |
428 int materialized_literal_count() { return materialized_literal_count_; } | 439 int materialized_literal_count() { return materialized_literal_count_; } |
429 bool IsInsideWith() { return with_nesting_count_ != 0; } | 440 bool IsInsideWith() { return with_nesting_count_ != 0; } |
430 bool is_strict() { return strict_; } | 441 bool is_strict_mode() { return strict_mode_flag_ == kStrictMode; } |
431 void set_strict() { strict_ = true; } | 442 StrictModeFlag strict_mode_flag() { |
| 443 return strict_mode_flag_; |
| 444 } |
| 445 void set_strict_mode_flag(StrictModeFlag strict_mode_flag) { |
| 446 strict_mode_flag_ = strict_mode_flag; |
| 447 } |
432 void EnterWith() { with_nesting_count_++; } | 448 void EnterWith() { with_nesting_count_++; } |
433 void LeaveWith() { with_nesting_count_--; } | 449 void LeaveWith() { with_nesting_count_--; } |
434 | 450 |
435 private: | 451 private: |
436 Scope** const variable_; | 452 Scope** const variable_; |
437 Scope* const prev_; | 453 Scope* const prev_; |
438 const ScopeType type_; | 454 const ScopeType type_; |
439 int materialized_literal_count_; | 455 int materialized_literal_count_; |
440 int expected_properties_; | 456 int expected_properties_; |
441 int with_nesting_count_; | 457 int with_nesting_count_; |
442 bool strict_; | 458 StrictModeFlag strict_mode_flag_; |
443 }; | 459 }; |
444 | 460 |
445 // Private constructor only used in PreParseProgram. | 461 // Private constructor only used in PreParseProgram. |
446 PreParser(i::JavaScriptScanner* scanner, | 462 PreParser(i::JavaScriptScanner* scanner, |
447 i::ParserRecorder* log, | 463 i::ParserRecorder* log, |
448 uintptr_t stack_limit, | 464 uintptr_t stack_limit, |
449 bool allow_lazy, | 465 bool allow_lazy, |
450 bool allow_natives_syntax) | 466 bool allow_natives_syntax) |
451 : scanner_(scanner), | 467 : scanner_(scanner), |
452 log_(log), | 468 log_(log), |
(...skipping 10 matching lines...) Expand all Loading... |
463 // Preparse the program. Only called in PreParseProgram after creating | 479 // Preparse the program. Only called in PreParseProgram after creating |
464 // the instance. | 480 // the instance. |
465 PreParseResult PreParse() { | 481 PreParseResult PreParse() { |
466 Scope top_scope(&scope_, kTopLevelScope); | 482 Scope top_scope(&scope_, kTopLevelScope); |
467 bool ok = true; | 483 bool ok = true; |
468 int start_position = scanner_->peek_location().beg_pos; | 484 int start_position = scanner_->peek_location().beg_pos; |
469 ParseSourceElements(i::Token::EOS, &ok); | 485 ParseSourceElements(i::Token::EOS, &ok); |
470 if (stack_overflow_) return kPreParseStackOverflow; | 486 if (stack_overflow_) return kPreParseStackOverflow; |
471 if (!ok) { | 487 if (!ok) { |
472 ReportUnexpectedToken(scanner_->current_token()); | 488 ReportUnexpectedToken(scanner_->current_token()); |
473 } else if (scope_->is_strict()) { | 489 } else if (scope_->is_strict_mode()) { |
474 CheckOctalLiteral(start_position, scanner_->location().end_pos, &ok); | 490 CheckOctalLiteral(start_position, scanner_->location().end_pos, &ok); |
475 } | 491 } |
476 return kPreParseSuccess; | 492 return kPreParseSuccess; |
477 } | 493 } |
478 | 494 |
479 // Report syntax error | 495 // Report syntax error |
480 void ReportUnexpectedToken(i::Token::Value token); | 496 void ReportUnexpectedToken(i::Token::Value token); |
481 void ReportMessageAt(i::Scanner::Location location, | 497 void ReportMessageAt(i::Scanner::Location location, |
482 const char* type, | 498 const char* type, |
483 const char* name_opt) { | 499 const char* name_opt) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 // have been seen using peek. | 584 // have been seen using peek. |
569 stack_overflow_ = true; | 585 stack_overflow_ = true; |
570 } | 586 } |
571 } | 587 } |
572 return scanner_->Next(); | 588 return scanner_->Next(); |
573 } | 589 } |
574 | 590 |
575 bool peek_any_identifier(); | 591 bool peek_any_identifier(); |
576 | 592 |
577 void set_strict_mode() { | 593 void set_strict_mode() { |
578 scope_->set_strict(); | 594 scope_->set_strict_mode_flag(kStrictMode); |
579 } | 595 } |
580 | 596 |
581 bool strict_mode() { return scope_->is_strict(); } | 597 bool strict_mode() { return scope_->strict_mode_flag() == kStrictMode; } |
582 | 598 |
583 void Consume(i::Token::Value token) { Next(); } | 599 void Consume(i::Token::Value token) { Next(); } |
584 | 600 |
585 void Expect(i::Token::Value token, bool* ok) { | 601 void Expect(i::Token::Value token, bool* ok) { |
586 if (Next() != token) { | 602 if (Next() != token) { |
587 *ok = false; | 603 *ok = false; |
588 } | 604 } |
589 } | 605 } |
590 | 606 |
591 bool Check(i::Token::Value token) { | 607 bool Check(i::Token::Value token) { |
(...skipping 27 matching lines...) Expand all Loading... |
619 const char* strict_mode_violation_type_; | 635 const char* strict_mode_violation_type_; |
620 bool stack_overflow_; | 636 bool stack_overflow_; |
621 bool allow_lazy_; | 637 bool allow_lazy_; |
622 bool allow_natives_syntax_; | 638 bool allow_natives_syntax_; |
623 bool parenthesized_function_; | 639 bool parenthesized_function_; |
624 bool harmony_scoping_; | 640 bool harmony_scoping_; |
625 }; | 641 }; |
626 } } // v8::preparser | 642 } } // v8::preparser |
627 | 643 |
628 #endif // V8_PREPARSER_H | 644 #endif // V8_PREPARSER_H |
OLD | NEW |