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/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 : scope_state_(nullptr), | 177 : scope_state_(nullptr), |
178 function_state_(nullptr), | 178 function_state_(nullptr), |
179 extension_(extension), | 179 extension_(extension), |
180 fni_(nullptr), | 180 fni_(nullptr), |
181 ast_value_factory_(ast_value_factory), | 181 ast_value_factory_(ast_value_factory), |
182 ast_node_factory_(ast_value_factory), | 182 ast_node_factory_(ast_value_factory), |
183 log_(log), | 183 log_(log), |
184 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. | 184 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. |
185 parsing_module_(false), | 185 parsing_module_(false), |
186 stack_limit_(stack_limit), | 186 stack_limit_(stack_limit), |
187 outer_most_receivers_function_kind_(kNormalFunction), | |
188 outer_most_receivers_scope_type_(SCRIPT_SCOPE), | |
187 zone_(zone), | 189 zone_(zone), |
188 classifier_(nullptr), | 190 classifier_(nullptr), |
189 scanner_(scanner), | 191 scanner_(scanner), |
190 stack_overflow_(false), | 192 stack_overflow_(false), |
191 allow_lazy_(false), | 193 allow_lazy_(false), |
192 allow_natives_(false), | 194 allow_natives_(false), |
193 allow_tailcalls_(false), | 195 allow_tailcalls_(false), |
194 allow_harmony_restrictive_declarations_(false), | 196 allow_harmony_restrictive_declarations_(false), |
195 allow_harmony_do_expressions_(false), | 197 allow_harmony_do_expressions_(false), |
196 allow_harmony_for_in_(false), | 198 allow_harmony_for_in_(false), |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
859 | 861 |
860 // Determine precedence of given token. | 862 // Determine precedence of given token. |
861 static int Precedence(Token::Value token, bool accept_IN) { | 863 static int Precedence(Token::Value token, bool accept_IN) { |
862 if (token == Token::IN && !accept_IN) | 864 if (token == Token::IN && !accept_IN) |
863 return 0; // 0 precedence will terminate binary expression parsing | 865 return 0; // 0 precedence will terminate binary expression parsing |
864 return Token::Precedence(token); | 866 return Token::Precedence(token); |
865 } | 867 } |
866 | 868 |
867 typename Types::Factory* factory() { return &ast_node_factory_; } | 869 typename Types::Factory* factory() { return &ast_node_factory_; } |
868 | 870 |
869 DeclarationScope* GetReceiverScope() const { | 871 FunctionKind GetReceiverScopeFunctionKind() const { |
870 return scope()->GetReceiverScope(); | 872 DeclarationScope* receiver_scope = scope()->GetReceiverScope(); |
873 if (receiver_scope->outer_scope()) return receiver_scope->function_kind(); | |
marja
2016/09/12 07:50:32
Style nit: != nullptr (in several places)
| |
874 return outer_most_receivers_function_kind_; | |
875 } | |
876 void RecordSuperPropertyUsage() { | |
877 DeclarationScope* receiver_scope = scope()->GetReceiverScope(); | |
878 if (receiver_scope->outer_scope()) { | |
marja
2016/09/12 07:50:33
Why is this correct? If there's no outer scope, th
jochen (gone - plz use gerrit)
2016/09/12 08:18:18
done
| |
879 return receiver_scope->RecordSuperPropertyUsage(); | |
marja
2016/09/12 07:50:32
Nit: "return" is unnecessary here.
jochen (gone - plz use gerrit)
2016/09/12 08:18:18
done
| |
880 } | |
881 } | |
882 ScopeType GetReceiverScopeType() const { | |
883 Scope* receiver_scope = scope()->GetReceiverScope(); | |
884 if (receiver_scope->outer_scope()) return receiver_scope->scope_type(); | |
885 return outer_most_receivers_scope_type_; | |
871 } | 886 } |
872 LanguageMode language_mode() { return scope()->language_mode(); } | 887 LanguageMode language_mode() { return scope()->language_mode(); } |
873 void RaiseLanguageMode(LanguageMode mode) { | 888 void RaiseLanguageMode(LanguageMode mode) { |
874 LanguageMode old = scope()->language_mode(); | 889 LanguageMode old = scope()->language_mode(); |
875 impl()->SetLanguageMode(scope(), old > mode ? old : mode); | 890 impl()->SetLanguageMode(scope(), old > mode ? old : mode); |
876 } | 891 } |
877 bool is_generator() const { return function_state_->is_generator(); } | 892 bool is_generator() const { return function_state_->is_generator(); } |
878 bool is_async_function() const { | 893 bool is_async_function() const { |
879 return function_state_->is_async_function(); | 894 return function_state_->is_async_function(); |
880 } | 895 } |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1330 ScopeState* scope_state_; // Scope stack. | 1345 ScopeState* scope_state_; // Scope stack. |
1331 FunctionState* function_state_; // Function state stack. | 1346 FunctionState* function_state_; // Function state stack. |
1332 v8::Extension* extension_; | 1347 v8::Extension* extension_; |
1333 FuncNameInferrer* fni_; | 1348 FuncNameInferrer* fni_; |
1334 AstValueFactory* ast_value_factory_; // Not owned. | 1349 AstValueFactory* ast_value_factory_; // Not owned. |
1335 typename Types::Factory ast_node_factory_; | 1350 typename Types::Factory ast_node_factory_; |
1336 ParserRecorder* log_; | 1351 ParserRecorder* log_; |
1337 Mode mode_; | 1352 Mode mode_; |
1338 bool parsing_module_; | 1353 bool parsing_module_; |
1339 uintptr_t stack_limit_; | 1354 uintptr_t stack_limit_; |
1355 FunctionKind outer_most_receivers_function_kind_; | |
marja
2016/09/12 07:50:32
Naming nit: "outermost" is one word, so outermost_
jochen (gone - plz use gerrit)
2016/09/12 08:18:18
done
| |
1356 ScopeType outer_most_receivers_scope_type_; | |
1340 | 1357 |
1341 // Parser base's private field members. | 1358 // Parser base's private field members. |
1342 | 1359 |
1343 private: | 1360 private: |
1344 Zone* zone_; | 1361 Zone* zone_; |
1345 ExpressionClassifier* classifier_; | 1362 ExpressionClassifier* classifier_; |
1346 | 1363 |
1347 Scanner* scanner_; | 1364 Scanner* scanner_; |
1348 bool stack_overflow_; | 1365 bool stack_overflow_; |
1349 | 1366 |
(...skipping 1888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3238 result = ParseMemberExpressionContinuation(result, is_async, CHECK_OK); | 3255 result = ParseMemberExpressionContinuation(result, is_async, CHECK_OK); |
3239 return result; | 3256 return result; |
3240 } | 3257 } |
3241 | 3258 |
3242 template <typename Impl> | 3259 template <typename Impl> |
3243 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseSuperExpression( | 3260 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseSuperExpression( |
3244 bool is_new, bool* ok) { | 3261 bool is_new, bool* ok) { |
3245 Expect(Token::SUPER, CHECK_OK); | 3262 Expect(Token::SUPER, CHECK_OK); |
3246 int pos = position(); | 3263 int pos = position(); |
3247 | 3264 |
3248 DeclarationScope* scope = GetReceiverScope(); | 3265 FunctionKind kind = GetReceiverScopeFunctionKind(); |
3249 FunctionKind kind = scope->function_kind(); | |
3250 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || | 3266 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || |
3251 IsClassConstructor(kind)) { | 3267 IsClassConstructor(kind)) { |
3252 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { | 3268 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { |
3253 scope->RecordSuperPropertyUsage(); | 3269 RecordSuperPropertyUsage(); |
3254 return impl()->NewSuperPropertyReference(pos); | 3270 return impl()->NewSuperPropertyReference(pos); |
3255 } | 3271 } |
3256 // new super() is never allowed. | 3272 // new super() is never allowed. |
3257 // super() is only allowed in derived constructor | 3273 // super() is only allowed in derived constructor |
3258 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { | 3274 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { |
3259 // TODO(rossberg): This might not be the correct FunctionState for the | 3275 // TODO(rossberg): This might not be the correct FunctionState for the |
3260 // method here. | 3276 // method here. |
3261 return impl()->NewSuperCallReference(pos); | 3277 return impl()->NewSuperCallReference(pos); |
3262 } | 3278 } |
3263 } | 3279 } |
(...skipping 17 matching lines...) Expand all Loading... | |
3281 *ok = false; | 3297 *ok = false; |
3282 } | 3298 } |
3283 } | 3299 } |
3284 | 3300 |
3285 template <typename Impl> | 3301 template <typename Impl> |
3286 typename ParserBase<Impl>::ExpressionT | 3302 typename ParserBase<Impl>::ExpressionT |
3287 ParserBase<Impl>::ParseNewTargetExpression(bool* ok) { | 3303 ParserBase<Impl>::ParseNewTargetExpression(bool* ok) { |
3288 int pos = position(); | 3304 int pos = position(); |
3289 ExpectMetaProperty(CStrVector("target"), "new.target", pos, CHECK_OK); | 3305 ExpectMetaProperty(CStrVector("target"), "new.target", pos, CHECK_OK); |
3290 | 3306 |
3291 if (!GetReceiverScope()->is_function_scope()) { | 3307 if (GetReceiverScopeType() != FUNCTION_SCOPE) { |
3292 impl()->ReportMessageAt(scanner()->location(), | 3308 impl()->ReportMessageAt(scanner()->location(), |
3293 MessageTemplate::kUnexpectedNewTarget); | 3309 MessageTemplate::kUnexpectedNewTarget); |
3294 *ok = false; | 3310 *ok = false; |
3295 return impl()->EmptyExpression(); | 3311 return impl()->EmptyExpression(); |
3296 } | 3312 } |
3297 | 3313 |
3298 return impl()->NewTargetExpression(pos); | 3314 return impl()->NewTargetExpression(pos); |
3299 } | 3315 } |
3300 | 3316 |
3301 template <typename Impl> | 3317 template <typename Impl> |
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4436 has_seen_constructor_ = true; | 4452 has_seen_constructor_ = true; |
4437 return; | 4453 return; |
4438 } | 4454 } |
4439 } | 4455 } |
4440 | 4456 |
4441 | 4457 |
4442 } // namespace internal | 4458 } // namespace internal |
4443 } // namespace v8 | 4459 } // namespace v8 |
4444 | 4460 |
4445 #endif // V8_PARSING_PARSER_BASE_H | 4461 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |