OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 allow_lazy_(false), | 92 allow_lazy_(false), |
93 allow_natives_(false), | 93 allow_natives_(false), |
94 allow_harmony_arrow_functions_(false), | 94 allow_harmony_arrow_functions_(false), |
95 allow_harmony_sloppy_(false), | 95 allow_harmony_sloppy_(false), |
96 allow_harmony_computed_property_names_(false), | 96 allow_harmony_computed_property_names_(false), |
97 allow_harmony_rest_params_(false), | 97 allow_harmony_rest_params_(false), |
98 allow_harmony_spreadcalls_(false), | 98 allow_harmony_spreadcalls_(false), |
99 allow_harmony_destructuring_(false), | 99 allow_harmony_destructuring_(false), |
100 allow_harmony_spread_arrays_(false), | 100 allow_harmony_spread_arrays_(false), |
101 allow_harmony_new_target_(false), | 101 allow_harmony_new_target_(false), |
102 allow_strong_mode_(false) {} | 102 allow_strong_mode_(false), |
| 103 allow_legacy_const_(true) {} |
103 | 104 |
104 #define ALLOW_ACCESSORS(name) \ | 105 #define ALLOW_ACCESSORS(name) \ |
105 bool allow_##name() const { return allow_##name##_; } \ | 106 bool allow_##name() const { return allow_##name##_; } \ |
106 void set_allow_##name(bool allow) { allow_##name##_ = allow; } | 107 void set_allow_##name(bool allow) { allow_##name##_ = allow; } |
107 | 108 |
108 ALLOW_ACCESSORS(lazy); | 109 ALLOW_ACCESSORS(lazy); |
109 ALLOW_ACCESSORS(natives); | 110 ALLOW_ACCESSORS(natives); |
110 ALLOW_ACCESSORS(harmony_arrow_functions); | 111 ALLOW_ACCESSORS(harmony_arrow_functions); |
111 ALLOW_ACCESSORS(harmony_sloppy); | 112 ALLOW_ACCESSORS(harmony_sloppy); |
112 ALLOW_ACCESSORS(harmony_computed_property_names); | 113 ALLOW_ACCESSORS(harmony_computed_property_names); |
113 ALLOW_ACCESSORS(harmony_rest_params); | 114 ALLOW_ACCESSORS(harmony_rest_params); |
114 ALLOW_ACCESSORS(harmony_spreadcalls); | 115 ALLOW_ACCESSORS(harmony_spreadcalls); |
115 ALLOW_ACCESSORS(harmony_destructuring); | 116 ALLOW_ACCESSORS(harmony_destructuring); |
116 ALLOW_ACCESSORS(harmony_spread_arrays); | 117 ALLOW_ACCESSORS(harmony_spread_arrays); |
117 ALLOW_ACCESSORS(harmony_new_target); | 118 ALLOW_ACCESSORS(harmony_new_target); |
118 ALLOW_ACCESSORS(strong_mode); | 119 ALLOW_ACCESSORS(strong_mode); |
| 120 ALLOW_ACCESSORS(legacy_const); |
119 #undef ALLOW_ACCESSORS | 121 #undef ALLOW_ACCESSORS |
120 | 122 |
121 bool allow_harmony_modules() const { return scanner()->HarmonyModules(); } | 123 bool allow_harmony_modules() const { return scanner()->HarmonyModules(); } |
122 bool allow_harmony_unicode() const { return scanner()->HarmonyUnicode(); } | 124 bool allow_harmony_unicode() const { return scanner()->HarmonyUnicode(); } |
123 | 125 |
124 void set_allow_harmony_modules(bool a) { scanner()->SetHarmonyModules(a); } | 126 void set_allow_harmony_modules(bool a) { scanner()->SetHarmonyModules(a); } |
125 void set_allow_harmony_unicode(bool a) { scanner()->SetHarmonyUnicode(a); } | 127 void set_allow_harmony_unicode(bool a) { scanner()->SetHarmonyUnicode(a); } |
126 | 128 |
127 protected: | 129 protected: |
128 enum AllowRestrictedIdentifiers { | 130 enum AllowRestrictedIdentifiers { |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 return Token::Precedence(token); | 486 return Token::Precedence(token); |
485 } | 487 } |
486 | 488 |
487 typename Traits::Type::Factory* factory() { | 489 typename Traits::Type::Factory* factory() { |
488 return function_state_->factory(); | 490 return function_state_->factory(); |
489 } | 491 } |
490 | 492 |
491 LanguageMode language_mode() { return scope_->language_mode(); } | 493 LanguageMode language_mode() { return scope_->language_mode(); } |
492 bool is_generator() const { return function_state_->is_generator(); } | 494 bool is_generator() const { return function_state_->is_generator(); } |
493 | 495 |
| 496 bool allow_const() { |
| 497 return is_strict(language_mode()) || allow_legacy_const(); |
| 498 } |
| 499 |
494 // Report syntax errors. | 500 // Report syntax errors. |
495 void ReportMessage(MessageTemplate::Template message, const char* arg = NULL, | 501 void ReportMessage(MessageTemplate::Template message, const char* arg = NULL, |
496 ParseErrorType error_type = kSyntaxError) { | 502 ParseErrorType error_type = kSyntaxError) { |
497 Scanner::Location source_location = scanner()->location(); | 503 Scanner::Location source_location = scanner()->location(); |
498 Traits::ReportMessageAt(source_location, message, arg, error_type); | 504 Traits::ReportMessageAt(source_location, message, arg, error_type); |
499 } | 505 } |
500 | 506 |
501 void ReportMessageAt(Scanner::Location location, | 507 void ReportMessageAt(Scanner::Location location, |
502 MessageTemplate::Template message, | 508 MessageTemplate::Template message, |
503 ParseErrorType error_type = kSyntaxError) { | 509 ParseErrorType error_type = kSyntaxError) { |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 bool allow_natives_; | 787 bool allow_natives_; |
782 bool allow_harmony_arrow_functions_; | 788 bool allow_harmony_arrow_functions_; |
783 bool allow_harmony_sloppy_; | 789 bool allow_harmony_sloppy_; |
784 bool allow_harmony_computed_property_names_; | 790 bool allow_harmony_computed_property_names_; |
785 bool allow_harmony_rest_params_; | 791 bool allow_harmony_rest_params_; |
786 bool allow_harmony_spreadcalls_; | 792 bool allow_harmony_spreadcalls_; |
787 bool allow_harmony_destructuring_; | 793 bool allow_harmony_destructuring_; |
788 bool allow_harmony_spread_arrays_; | 794 bool allow_harmony_spread_arrays_; |
789 bool allow_harmony_new_target_; | 795 bool allow_harmony_new_target_; |
790 bool allow_strong_mode_; | 796 bool allow_strong_mode_; |
| 797 bool allow_legacy_const_; |
791 }; | 798 }; |
792 | 799 |
793 | 800 |
794 class PreParserIdentifier { | 801 class PreParserIdentifier { |
795 public: | 802 public: |
796 PreParserIdentifier() : type_(kUnknownIdentifier) {} | 803 PreParserIdentifier() : type_(kUnknownIdentifier) {} |
797 static PreParserIdentifier Default() { | 804 static PreParserIdentifier Default() { |
798 return PreParserIdentifier(kUnknownIdentifier); | 805 return PreParserIdentifier(kUnknownIdentifier); |
799 } | 806 } |
800 static PreParserIdentifier Eval() { | 807 static PreParserIdentifier Eval() { |
(...skipping 3160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3961 *ok = false; | 3968 *ok = false; |
3962 return; | 3969 return; |
3963 } | 3970 } |
3964 has_seen_constructor_ = true; | 3971 has_seen_constructor_ = true; |
3965 return; | 3972 return; |
3966 } | 3973 } |
3967 } | 3974 } |
3968 } } // v8::internal | 3975 } } // v8::internal |
3969 | 3976 |
3970 #endif // V8_PREPARSER_H | 3977 #endif // V8_PREPARSER_H |
OLD | NEW |