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_SCOPES_H_ | 5 #ifndef V8_SCOPES_H_ |
6 #define V8_SCOPES_H_ | 6 #define V8_SCOPES_H_ |
7 | 7 |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
9 #include "src/pending-compilation-error-handler.h" | 9 #include "src/pending-compilation-error-handler.h" |
10 #include "src/zone.h" | 10 #include "src/zone.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // doesn't re-allocate variables repeatedly. | 80 // doesn't re-allocate variables repeatedly. |
81 static bool Analyze(ParseInfo* info); | 81 static bool Analyze(ParseInfo* info); |
82 | 82 |
83 static Scope* DeserializeScopeChain(Isolate* isolate, Zone* zone, | 83 static Scope* DeserializeScopeChain(Isolate* isolate, Zone* zone, |
84 Context* context, Scope* script_scope); | 84 Context* context, Scope* script_scope); |
85 | 85 |
86 // The scope name is only used for printing/debugging. | 86 // The scope name is only used for printing/debugging. |
87 void SetScopeName(const AstRawString* scope_name) { | 87 void SetScopeName(const AstRawString* scope_name) { |
88 scope_name_ = scope_name; | 88 scope_name_ = scope_name; |
89 } | 89 } |
90 | 90 const AstRawString* scope_name() const { return scope_name_; } |
91 void Initialize(); | 91 void Initialize(); |
92 | 92 |
93 // Checks if the block scope is redundant, i.e. it does not contain any | 93 // Checks if the block scope is redundant, i.e. it does not contain any |
94 // block scoped declarations. In that case it is removed from the scope | 94 // block scoped declarations. In that case it is removed from the scope |
95 // tree and its children are reparented. | 95 // tree and its children are reparented. |
96 Scope* FinalizeBlockScope(); | 96 Scope* FinalizeBlockScope(); |
97 | 97 |
98 Zone* zone() const { return zone_; } | 98 Zone* zone() const { return zone_; } |
99 | 99 |
100 // --------------------------------------------------------------------------- | 100 // --------------------------------------------------------------------------- |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 } | 269 } |
270 | 270 |
271 // --------------------------------------------------------------------------- | 271 // --------------------------------------------------------------------------- |
272 // Predicates. | 272 // Predicates. |
273 | 273 |
274 // Specific scope types. | 274 // Specific scope types. |
275 bool is_eval_scope() const { return scope_type_ == EVAL_SCOPE; } | 275 bool is_eval_scope() const { return scope_type_ == EVAL_SCOPE; } |
276 bool is_function_scope() const { | 276 bool is_function_scope() const { |
277 return scope_type_ == FUNCTION_SCOPE || scope_type_ == ARROW_SCOPE; | 277 return scope_type_ == FUNCTION_SCOPE || scope_type_ == ARROW_SCOPE; |
278 } | 278 } |
| 279 bool is_function_body_scope() const { |
| 280 return scope_type_ == FUNCTION_BODY_SCOPE; |
| 281 } |
279 bool is_module_scope() const { return scope_type_ == MODULE_SCOPE; } | 282 bool is_module_scope() const { return scope_type_ == MODULE_SCOPE; } |
280 bool is_script_scope() const { return scope_type_ == SCRIPT_SCOPE; } | 283 bool is_script_scope() const { return scope_type_ == SCRIPT_SCOPE; } |
281 bool is_catch_scope() const { return scope_type_ == CATCH_SCOPE; } | 284 bool is_catch_scope() const { return scope_type_ == CATCH_SCOPE; } |
282 bool is_block_scope() const { return scope_type_ == BLOCK_SCOPE; } | 285 bool is_block_scope() const { |
| 286 return scope_type_ == BLOCK_SCOPE || scope_type_ == FUNCTION_BODY_SCOPE; |
| 287 } |
283 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; } | 288 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; } |
284 bool is_arrow_scope() const { return scope_type_ == ARROW_SCOPE; } | 289 bool is_arrow_scope() const { return scope_type_ == ARROW_SCOPE; } |
285 void tag_as_class_scope() { | 290 void tag_as_class_scope() { |
286 DCHECK(is_block_scope()); | 291 DCHECK(is_block_scope()); |
287 block_scope_is_class_scope_ = true; | 292 block_scope_is_class_scope_ = true; |
288 } | 293 } |
289 bool is_class_scope() const { | 294 bool is_class_scope() const { |
290 return is_block_scope() && block_scope_is_class_scope_; | 295 return is_block_scope() && block_scope_is_class_scope_; |
291 } | 296 } |
292 bool is_declaration_scope() const { | 297 bool is_declaration_scope() const { |
293 return is_eval_scope() || is_function_scope() || | 298 return is_eval_scope() || is_function_scope() || is_module_scope() || |
294 is_module_scope() || is_script_scope(); | 299 is_script_scope() || is_function_body_scope(); |
295 } | 300 } |
296 bool is_strict_eval_scope() const { | 301 bool is_strict_eval_scope() const { |
297 return is_eval_scope() && is_strict(language_mode_); | 302 return is_eval_scope() && is_strict(language_mode_); |
298 } | 303 } |
299 | 304 |
300 // Information about which scopes calls eval. | 305 // Information about which scopes calls eval. |
301 bool calls_eval() const { return scope_calls_eval_; } | 306 bool calls_eval() const { return scope_calls_eval_; } |
302 bool calls_sloppy_eval() { | 307 bool calls_sloppy_eval() { |
303 return scope_calls_eval_ && is_sloppy(language_mode_); | 308 return scope_calls_eval_ && is_sloppy(language_mode_); |
304 } | 309 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 | 408 |
404 // Declarations list. | 409 // Declarations list. |
405 ZoneList<Declaration*>* declarations() { return &decls_; } | 410 ZoneList<Declaration*>* declarations() { return &decls_; } |
406 | 411 |
407 // Inner scope list. | 412 // Inner scope list. |
408 ZoneList<Scope*>* inner_scopes() { return &inner_scopes_; } | 413 ZoneList<Scope*>* inner_scopes() { return &inner_scopes_; } |
409 | 414 |
410 // The scope immediately surrounding this scope, or NULL. | 415 // The scope immediately surrounding this scope, or NULL. |
411 Scope* outer_scope() const { return outer_scope_; } | 416 Scope* outer_scope() const { return outer_scope_; } |
412 | 417 |
| 418 // The inner scope which contains the main "body" of a function (may be null) |
| 419 Scope* function_body() const { return function_body_; } |
| 420 |
413 // The ModuleDescriptor for this scope; only for module scopes. | 421 // The ModuleDescriptor for this scope; only for module scopes. |
414 ModuleDescriptor* module() const { return module_descriptor_; } | 422 ModuleDescriptor* module() const { return module_descriptor_; } |
415 | 423 |
416 | 424 |
417 void set_class_declaration_group_start(int position) { | 425 void set_class_declaration_group_start(int position) { |
418 class_declaration_group_start_ = position; | 426 class_declaration_group_start_ = position; |
419 } | 427 } |
420 | 428 |
421 int class_declaration_group_start() const { | 429 int class_declaration_group_start() const { |
422 return class_declaration_group_start_; | 430 return class_declaration_group_start_; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 #endif | 522 #endif |
515 | 523 |
516 // --------------------------------------------------------------------------- | 524 // --------------------------------------------------------------------------- |
517 // Implementation. | 525 // Implementation. |
518 protected: | 526 protected: |
519 friend class ParserFactory; | 527 friend class ParserFactory; |
520 | 528 |
521 // Scope tree. | 529 // Scope tree. |
522 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL | 530 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL |
523 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes | 531 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes |
| 532 Scope* function_body_; // The scope for a function body |
524 | 533 |
525 // The scope type. | 534 // The scope type. |
526 ScopeType scope_type_; | 535 ScopeType scope_type_; |
527 // Some block scopes are tagged as class scopes. | 536 // Some block scopes are tagged as class scopes. |
528 bool block_scope_is_class_scope_; | 537 bool block_scope_is_class_scope_; |
529 // If the scope is a function scope, this is the function kind. | 538 // If the scope is a function scope, this is the function kind. |
530 FunctionKind function_kind_; | 539 FunctionKind function_kind_; |
531 | 540 |
532 // Debugging support. | 541 // Debugging support. |
533 const AstRawString* scope_name_; | 542 const AstRawString* scope_name_; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 PendingCompilationErrorHandler pending_error_handler_; | 754 PendingCompilationErrorHandler pending_error_handler_; |
746 | 755 |
747 // For tracking which classes are declared consecutively. Needed for strong | 756 // For tracking which classes are declared consecutively. Needed for strong |
748 // mode. | 757 // mode. |
749 int class_declaration_group_start_; | 758 int class_declaration_group_start_; |
750 }; | 759 }; |
751 | 760 |
752 } } // namespace v8::internal | 761 } } // namespace v8::internal |
753 | 762 |
754 #endif // V8_SCOPES_H_ | 763 #endif // V8_SCOPES_H_ |
OLD | NEW |