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_PARSING_PARSER_BASE_H | 5 #ifndef V8_PARSING_PARSER_BASE_H |
6 #define V8_PARSING_PARSER_BASE_H | 6 #define V8_PARSING_PARSER_BASE_H |
7 | 7 |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/hashmap.h" | 10 #include "src/base/hashmap.h" |
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 | 846 |
847 // Determine precedence of given token. | 847 // Determine precedence of given token. |
848 static int Precedence(Token::Value token, bool accept_IN) { | 848 static int Precedence(Token::Value token, bool accept_IN) { |
849 if (token == Token::IN && !accept_IN) | 849 if (token == Token::IN && !accept_IN) |
850 return 0; // 0 precedence will terminate binary expression parsing | 850 return 0; // 0 precedence will terminate binary expression parsing |
851 return Token::Precedence(token); | 851 return Token::Precedence(token); |
852 } | 852 } |
853 | 853 |
854 typename Traits::Type::Factory* factory() { return &ast_node_factory_; } | 854 typename Traits::Type::Factory* factory() { return &ast_node_factory_; } |
855 | 855 |
| 856 DeclarationScope* GetReceiverScope() const { |
| 857 return scope()->GetReceiverScope(); |
| 858 } |
856 LanguageMode language_mode() { return scope()->language_mode(); } | 859 LanguageMode language_mode() { return scope()->language_mode(); } |
857 bool is_generator() const { return function_state_->is_generator(); } | 860 bool is_generator() const { return function_state_->is_generator(); } |
858 bool is_async_function() const { | 861 bool is_async_function() const { |
859 return function_state_->is_async_function(); | 862 return function_state_->is_async_function(); |
860 } | 863 } |
861 bool is_resumable() const { return function_state_->is_resumable(); } | 864 bool is_resumable() const { return function_state_->is_resumable(); } |
862 | 865 |
863 // Report syntax errors. | 866 // Report syntax errors. |
864 void ReportMessage(MessageTemplate::Template message, const char* arg = NULL, | 867 void ReportMessage(MessageTemplate::Template message, const char* arg = NULL, |
865 ParseErrorType error_type = kSyntaxError) { | 868 ParseErrorType error_type = kSyntaxError) { |
(...skipping 2223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3089 ParseMemberExpressionContinuation(result, is_async, classifier, CHECK_OK); | 3092 ParseMemberExpressionContinuation(result, is_async, classifier, CHECK_OK); |
3090 return result; | 3093 return result; |
3091 } | 3094 } |
3092 | 3095 |
3093 template <class Traits> | 3096 template <class Traits> |
3094 typename ParserBase<Traits>::ExpressionT | 3097 typename ParserBase<Traits>::ExpressionT |
3095 ParserBase<Traits>::ParseSuperExpression(bool is_new, bool* ok) { | 3098 ParserBase<Traits>::ParseSuperExpression(bool is_new, bool* ok) { |
3096 Expect(Token::SUPER, CHECK_OK); | 3099 Expect(Token::SUPER, CHECK_OK); |
3097 int pos = position(); | 3100 int pos = position(); |
3098 | 3101 |
3099 DeclarationScope* scope = this->scope()->GetReceiverScope(); | 3102 DeclarationScope* scope = GetReceiverScope(); |
3100 FunctionKind kind = scope->function_kind(); | 3103 FunctionKind kind = scope->function_kind(); |
3101 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || | 3104 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || |
3102 IsClassConstructor(kind)) { | 3105 IsClassConstructor(kind)) { |
3103 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { | 3106 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { |
3104 scope->RecordSuperPropertyUsage(); | 3107 scope->RecordSuperPropertyUsage(); |
3105 return this->NewSuperPropertyReference(factory(), pos); | 3108 return this->NewSuperPropertyReference(factory(), pos); |
3106 } | 3109 } |
3107 // new super() is never allowed. | 3110 // new super() is never allowed. |
3108 // super() is only allowed in derived constructor | 3111 // super() is only allowed in derived constructor |
3109 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { | 3112 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { |
(...skipping 21 matching lines...) Expand all Loading... |
3131 *ok = false; | 3134 *ok = false; |
3132 } | 3135 } |
3133 } | 3136 } |
3134 | 3137 |
3135 template <class Traits> | 3138 template <class Traits> |
3136 typename ParserBase<Traits>::ExpressionT | 3139 typename ParserBase<Traits>::ExpressionT |
3137 ParserBase<Traits>::ParseNewTargetExpression(bool* ok) { | 3140 ParserBase<Traits>::ParseNewTargetExpression(bool* ok) { |
3138 int pos = position(); | 3141 int pos = position(); |
3139 ExpectMetaProperty(CStrVector("target"), "new.target", pos, CHECK_OK); | 3142 ExpectMetaProperty(CStrVector("target"), "new.target", pos, CHECK_OK); |
3140 | 3143 |
3141 if (!scope()->GetReceiverScope()->is_function_scope()) { | 3144 if (!GetReceiverScope()->is_function_scope()) { |
3142 ReportMessageAt(scanner()->location(), | 3145 ReportMessageAt(scanner()->location(), |
3143 MessageTemplate::kUnexpectedNewTarget); | 3146 MessageTemplate::kUnexpectedNewTarget); |
3144 *ok = false; | 3147 *ok = false; |
3145 return this->EmptyExpression(); | 3148 return this->EmptyExpression(); |
3146 } | 3149 } |
3147 | 3150 |
3148 return this->NewTargetExpression(factory(), pos); | 3151 return this->NewTargetExpression(factory(), pos); |
3149 } | 3152 } |
3150 | 3153 |
3151 template <class Traits> | 3154 template <class Traits> |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3693 has_seen_constructor_ = true; | 3696 has_seen_constructor_ = true; |
3694 return; | 3697 return; |
3695 } | 3698 } |
3696 } | 3699 } |
3697 | 3700 |
3698 | 3701 |
3699 } // namespace internal | 3702 } // namespace internal |
3700 } // namespace v8 | 3703 } // namespace v8 |
3701 | 3704 |
3702 #endif // V8_PARSING_PARSER_BASE_H | 3705 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |