| 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/bailout-reason.h" | 8 #include "src/bailout-reason.h" | 
| 9 #include "src/expression-classifier.h" | 9 #include "src/expression-classifier.h" | 
| 10 #include "src/func-name-inferrer.h" | 10 #include "src/func-name-inferrer.h" | 
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 106         zone_(zone), | 106         zone_(zone), | 
| 107         scanner_(scanner), | 107         scanner_(scanner), | 
| 108         stack_overflow_(false), | 108         stack_overflow_(false), | 
| 109         allow_lazy_(false), | 109         allow_lazy_(false), | 
| 110         allow_natives_(false), | 110         allow_natives_(false), | 
| 111         allow_harmony_sloppy_(false), | 111         allow_harmony_sloppy_(false), | 
| 112         allow_harmony_sloppy_function_(false), | 112         allow_harmony_sloppy_function_(false), | 
| 113         allow_harmony_sloppy_let_(false), | 113         allow_harmony_sloppy_let_(false), | 
| 114         allow_harmony_rest_parameters_(false), | 114         allow_harmony_rest_parameters_(false), | 
| 115         allow_harmony_default_parameters_(false), | 115         allow_harmony_default_parameters_(false), | 
| 116         allow_harmony_destructuring_(false), | 116         allow_harmony_destructuring_bind_(false), | 
| 117         allow_strong_mode_(false), | 117         allow_strong_mode_(false), | 
| 118         allow_legacy_const_(true), | 118         allow_legacy_const_(true), | 
| 119         allow_harmony_do_expressions_(false) {} | 119         allow_harmony_do_expressions_(false) {} | 
| 120 | 120 | 
| 121 #define ALLOW_ACCESSORS(name)                           \ | 121 #define ALLOW_ACCESSORS(name)                           \ | 
| 122   bool allow_##name() const { return allow_##name##_; } \ | 122   bool allow_##name() const { return allow_##name##_; } \ | 
| 123   void set_allow_##name(bool allow) { allow_##name##_ = allow; } | 123   void set_allow_##name(bool allow) { allow_##name##_ = allow; } | 
| 124 | 124 | 
| 125   ALLOW_ACCESSORS(lazy); | 125   ALLOW_ACCESSORS(lazy); | 
| 126   ALLOW_ACCESSORS(natives); | 126   ALLOW_ACCESSORS(natives); | 
| 127   ALLOW_ACCESSORS(harmony_sloppy); | 127   ALLOW_ACCESSORS(harmony_sloppy); | 
| 128   ALLOW_ACCESSORS(harmony_sloppy_function); | 128   ALLOW_ACCESSORS(harmony_sloppy_function); | 
| 129   ALLOW_ACCESSORS(harmony_sloppy_let); | 129   ALLOW_ACCESSORS(harmony_sloppy_let); | 
| 130   ALLOW_ACCESSORS(harmony_rest_parameters); | 130   ALLOW_ACCESSORS(harmony_rest_parameters); | 
| 131   ALLOW_ACCESSORS(harmony_default_parameters); | 131   ALLOW_ACCESSORS(harmony_default_parameters); | 
| 132   ALLOW_ACCESSORS(harmony_destructuring); | 132   ALLOW_ACCESSORS(harmony_destructuring_bind); | 
| 133   ALLOW_ACCESSORS(strong_mode); | 133   ALLOW_ACCESSORS(strong_mode); | 
| 134   ALLOW_ACCESSORS(legacy_const); | 134   ALLOW_ACCESSORS(legacy_const); | 
| 135   ALLOW_ACCESSORS(harmony_do_expressions); | 135   ALLOW_ACCESSORS(harmony_do_expressions); | 
| 136 #undef ALLOW_ACCESSORS | 136 #undef ALLOW_ACCESSORS | 
| 137 | 137 | 
| 138   uintptr_t stack_limit() const { return stack_limit_; } | 138   uintptr_t stack_limit() const { return stack_limit_; } | 
| 139 | 139 | 
| 140  protected: | 140  protected: | 
| 141   enum AllowRestrictedIdentifiers { | 141   enum AllowRestrictedIdentifiers { | 
| 142     kAllowRestrictedIdentifiers, | 142     kAllowRestrictedIdentifiers, | 
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 827   Scanner* scanner_; | 827   Scanner* scanner_; | 
| 828   bool stack_overflow_; | 828   bool stack_overflow_; | 
| 829 | 829 | 
| 830   bool allow_lazy_; | 830   bool allow_lazy_; | 
| 831   bool allow_natives_; | 831   bool allow_natives_; | 
| 832   bool allow_harmony_sloppy_; | 832   bool allow_harmony_sloppy_; | 
| 833   bool allow_harmony_sloppy_function_; | 833   bool allow_harmony_sloppy_function_; | 
| 834   bool allow_harmony_sloppy_let_; | 834   bool allow_harmony_sloppy_let_; | 
| 835   bool allow_harmony_rest_parameters_; | 835   bool allow_harmony_rest_parameters_; | 
| 836   bool allow_harmony_default_parameters_; | 836   bool allow_harmony_default_parameters_; | 
| 837   bool allow_harmony_destructuring_; | 837   bool allow_harmony_destructuring_bind_; | 
| 838   bool allow_strong_mode_; | 838   bool allow_strong_mode_; | 
| 839   bool allow_legacy_const_; | 839   bool allow_legacy_const_; | 
| 840   bool allow_harmony_do_expressions_; | 840   bool allow_harmony_do_expressions_; | 
| 841 }; | 841 }; | 
| 842 | 842 | 
| 843 | 843 | 
| 844 class PreParserIdentifier { | 844 class PreParserIdentifier { | 
| 845  public: | 845  public: | 
| 846   PreParserIdentifier() : type_(kUnknownIdentifier) {} | 846   PreParserIdentifier() : type_(kUnknownIdentifier) {} | 
| 847   static PreParserIdentifier Default() { | 847   static PreParserIdentifier Default() { | 
| (...skipping 1448 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2296       classifier->RecordBindingPatternError( | 2296       classifier->RecordBindingPatternError( | 
| 2297           scanner()->peek_location(), MessageTemplate::kUnexpectedTokenRegExp); | 2297           scanner()->peek_location(), MessageTemplate::kUnexpectedTokenRegExp); | 
| 2298       return this->ParseRegExpLiteral(true, classifier, ok); | 2298       return this->ParseRegExpLiteral(true, classifier, ok); | 
| 2299 | 2299 | 
| 2300     case Token::DIV: | 2300     case Token::DIV: | 
| 2301       classifier->RecordBindingPatternError( | 2301       classifier->RecordBindingPatternError( | 
| 2302           scanner()->peek_location(), MessageTemplate::kUnexpectedTokenRegExp); | 2302           scanner()->peek_location(), MessageTemplate::kUnexpectedTokenRegExp); | 
| 2303       return this->ParseRegExpLiteral(false, classifier, ok); | 2303       return this->ParseRegExpLiteral(false, classifier, ok); | 
| 2304 | 2304 | 
| 2305     case Token::LBRACK: | 2305     case Token::LBRACK: | 
| 2306       if (!allow_harmony_destructuring()) { | 2306       if (!allow_harmony_destructuring_bind()) { | 
| 2307         BindingPatternUnexpectedToken(classifier); | 2307         BindingPatternUnexpectedToken(classifier); | 
| 2308       } | 2308       } | 
| 2309       return this->ParseArrayLiteral(classifier, ok); | 2309       return this->ParseArrayLiteral(classifier, ok); | 
| 2310 | 2310 | 
| 2311     case Token::LBRACE: | 2311     case Token::LBRACE: | 
| 2312       if (!allow_harmony_destructuring()) { | 2312       if (!allow_harmony_destructuring_bind()) { | 
| 2313         BindingPatternUnexpectedToken(classifier); | 2313         BindingPatternUnexpectedToken(classifier); | 
| 2314       } | 2314       } | 
| 2315       return this->ParseObjectLiteral(classifier, ok); | 2315       return this->ParseObjectLiteral(classifier, ok); | 
| 2316 | 2316 | 
| 2317     case Token::LPAREN: { | 2317     case Token::LPAREN: { | 
| 2318       // Arrow function formal parameters are either a single identifier or a | 2318       // Arrow function formal parameters are either a single identifier or a | 
| 2319       // list of BindingPattern productions enclosed in parentheses. | 2319       // list of BindingPattern productions enclosed in parentheses. | 
| 2320       // Parentheses are not valid on the LHS of a BindingPattern, so we use the | 2320       // Parentheses are not valid on the LHS of a BindingPattern, so we use the | 
| 2321       // is_valid_binding_pattern() check to detect multiple levels of | 2321       // is_valid_binding_pattern() check to detect multiple levels of | 
| 2322       // parenthesization. | 2322       // parenthesization. | 
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2968   classifier->Accumulate(arrow_formals_classifier, | 2968   classifier->Accumulate(arrow_formals_classifier, | 
| 2969                          ExpressionClassifier::StandardProductions | | 2969                          ExpressionClassifier::StandardProductions | | 
| 2970                              ExpressionClassifier::FormalParametersProductions); | 2970                              ExpressionClassifier::FormalParametersProductions); | 
| 2971 | 2971 | 
| 2972   if (!Token::IsAssignmentOp(peek())) { | 2972   if (!Token::IsAssignmentOp(peek())) { | 
| 2973     if (fni_ != NULL) fni_->Leave(); | 2973     if (fni_ != NULL) fni_->Leave(); | 
| 2974     // Parsed conditional expression only (no assignment). | 2974     // Parsed conditional expression only (no assignment). | 
| 2975     return expression; | 2975     return expression; | 
| 2976   } | 2976   } | 
| 2977 | 2977 | 
| 2978   if (!(allow_harmony_destructuring() || allow_harmony_default_parameters())) { | 2978   if (!(allow_harmony_destructuring_bind() || | 
|  | 2979         allow_harmony_default_parameters())) { | 
| 2979     BindingPatternUnexpectedToken(classifier); | 2980     BindingPatternUnexpectedToken(classifier); | 
| 2980   } | 2981   } | 
| 2981 | 2982 | 
| 2982   expression = this->CheckAndRewriteReferenceExpression( | 2983   expression = this->CheckAndRewriteReferenceExpression( | 
| 2983       expression, lhs_beg_pos, scanner()->location().end_pos, | 2984       expression, lhs_beg_pos, scanner()->location().end_pos, | 
| 2984       MessageTemplate::kInvalidLhsInAssignment, CHECK_OK); | 2985       MessageTemplate::kInvalidLhsInAssignment, CHECK_OK); | 
| 2985   expression = this->MarkExpressionAsAssigned(expression); | 2986   expression = this->MarkExpressionAsAssigned(expression); | 
| 2986 | 2987 | 
| 2987   Token::Value op = Next();  // Get assignment operator. | 2988   Token::Value op = Next();  // Get assignment operator. | 
| 2988   if (op != Token::ASSIGN) { | 2989   if (op != Token::ASSIGN) { | 
| (...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 3748   bool is_rest = parameters->has_rest; | 3749   bool is_rest = parameters->has_rest; | 
| 3749 | 3750 | 
| 3750   Token::Value next = peek(); | 3751   Token::Value next = peek(); | 
| 3751   ExpressionT pattern = ParsePrimaryExpression(classifier, ok); | 3752   ExpressionT pattern = ParsePrimaryExpression(classifier, ok); | 
| 3752   if (!*ok) return; | 3753   if (!*ok) return; | 
| 3753 | 3754 | 
| 3754   ValidateBindingPattern(classifier, ok); | 3755   ValidateBindingPattern(classifier, ok); | 
| 3755   if (!*ok) return; | 3756   if (!*ok) return; | 
| 3756 | 3757 | 
| 3757   if (!Traits::IsIdentifier(pattern)) { | 3758   if (!Traits::IsIdentifier(pattern)) { | 
| 3758     if (is_rest || !allow_harmony_destructuring()) { | 3759     if (is_rest || !allow_harmony_destructuring_bind()) { | 
| 3759       ReportUnexpectedToken(next); | 3760       ReportUnexpectedToken(next); | 
| 3760       *ok = false; | 3761       *ok = false; | 
| 3761       return; | 3762       return; | 
| 3762     } | 3763     } | 
| 3763     parameters->is_simple = false; | 3764     parameters->is_simple = false; | 
| 3764     ValidateFormalParameterInitializer(classifier, ok); | 3765     ValidateFormalParameterInitializer(classifier, ok); | 
| 3765     if (!*ok) return; | 3766     if (!*ok) return; | 
| 3766     classifier->RecordNonSimpleParameter(); | 3767     classifier->RecordNonSimpleParameter(); | 
| 3767   } | 3768   } | 
| 3768 | 3769 | 
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 4197       return; | 4198       return; | 
| 4198     } | 4199     } | 
| 4199     has_seen_constructor_ = true; | 4200     has_seen_constructor_ = true; | 
| 4200     return; | 4201     return; | 
| 4201   } | 4202   } | 
| 4202 } | 4203 } | 
| 4203 }  // namespace internal | 4204 }  // namespace internal | 
| 4204 }  // namespace v8 | 4205 }  // namespace v8 | 
| 4205 | 4206 | 
| 4206 #endif  // V8_PREPARSER_H | 4207 #endif  // V8_PREPARSER_H | 
| OLD | NEW | 
|---|