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_AST_SCOPES_H_ | 5 #ifndef V8_AST_SCOPES_H_ |
6 #define V8_AST_SCOPES_H_ | 6 #define V8_AST_SCOPES_H_ |
7 | 7 |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/base/hashmap.h" | 9 #include "src/base/hashmap.h" |
10 #include "src/globals.h" | 10 #include "src/globals.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 void AddDeclaration(Declaration* declaration); | 229 void AddDeclaration(Declaration* declaration); |
230 | 230 |
231 // --------------------------------------------------------------------------- | 231 // --------------------------------------------------------------------------- |
232 // Illegal redeclaration support. | 232 // Illegal redeclaration support. |
233 | 233 |
234 // Check if the scope has conflicting var | 234 // Check if the scope has conflicting var |
235 // declarations, i.e. a var declaration that has been hoisted from a nested | 235 // declarations, i.e. a var declaration that has been hoisted from a nested |
236 // scope over a let binding of the same name. | 236 // scope over a let binding of the same name. |
237 Declaration* CheckConflictingVarDeclarations(); | 237 Declaration* CheckConflictingVarDeclarations(); |
238 | 238 |
239 // Check if the scope has a conflicting lexical declaration that has a name in | |
240 // the given list. This is used to catch patterns like | |
241 // `try{}catch(e){let e;}`, | |
242 // which is an error even though the two 'e's are declared in different | |
243 // scopes. | |
244 Declaration* CheckLexDeclarationsConflictingWith( | |
245 ZoneList<const AstRawString*>* names); | |
adamk
2016/07/01 19:14:04
Style: given that this arg isn't mutated by the ca
| |
246 | |
239 // --------------------------------------------------------------------------- | 247 // --------------------------------------------------------------------------- |
240 // Scope-specific info. | 248 // Scope-specific info. |
241 | 249 |
242 // Inform the scope that the corresponding code contains an eval call. | 250 // Inform the scope that the corresponding code contains an eval call. |
243 void RecordEvalCall() { scope_calls_eval_ = true; } | 251 void RecordEvalCall() { scope_calls_eval_ = true; } |
244 | 252 |
245 // Inform the scope that the corresponding code uses "arguments". | 253 // Inform the scope that the corresponding code uses "arguments". |
246 void RecordArgumentsUsage() { scope_uses_arguments_ = true; } | 254 void RecordArgumentsUsage() { scope_uses_arguments_ = true; } |
247 | 255 |
248 // Inform the scope that the corresponding code uses "super". | 256 // Inform the scope that the corresponding code uses "super". |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 | 492 |
485 // Inner scope list. | 493 // Inner scope list. |
486 ZoneList<Scope*>* inner_scopes() { return &inner_scopes_; } | 494 ZoneList<Scope*>* inner_scopes() { return &inner_scopes_; } |
487 | 495 |
488 // The scope immediately surrounding this scope, or NULL. | 496 // The scope immediately surrounding this scope, or NULL. |
489 Scope* outer_scope() const { return outer_scope_; } | 497 Scope* outer_scope() const { return outer_scope_; } |
490 | 498 |
491 // The ModuleDescriptor for this scope; only for module scopes. | 499 // The ModuleDescriptor for this scope; only for module scopes. |
492 ModuleDescriptor* module() const { return module_descriptor_; } | 500 ModuleDescriptor* module() const { return module_descriptor_; } |
493 | 501 |
502 AstRawString* catch_variable_name() const { | |
adamk
2016/07/01 19:14:04
this should return a "const AstRawString*", non-co
| |
503 DCHECK(is_catch_scope()); | |
504 DCHECK(num_var() == 1); | |
505 return static_cast<AstRawString*>(variables_.Start()->key); | |
506 } | |
507 | |
494 // --------------------------------------------------------------------------- | 508 // --------------------------------------------------------------------------- |
495 // Variable allocation. | 509 // Variable allocation. |
496 | 510 |
497 // Collect stack and context allocated local variables in this scope. Note | 511 // Collect stack and context allocated local variables in this scope. Note |
498 // that the function variable - if present - is not collected and should be | 512 // that the function variable - if present - is not collected and should be |
499 // handled separately. | 513 // handled separately. |
500 void CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals, | 514 void CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals, |
501 ZoneList<Variable*>* context_locals, | 515 ZoneList<Variable*>* context_locals, |
502 ZoneList<Variable*>* context_globals); | 516 ZoneList<Variable*>* context_globals); |
503 | 517 |
504 // Current number of var or const locals. | 518 // Current number of var locals. |
505 int num_var_or_const() { return num_var_or_const_; } | 519 int num_var() const { return num_var_; } |
506 | 520 |
507 // Result of variable allocation. | 521 // Result of variable allocation. |
508 int num_stack_slots() const { return num_stack_slots_; } | 522 int num_stack_slots() const { return num_stack_slots_; } |
509 int num_heap_slots() const { return num_heap_slots_; } | 523 int num_heap_slots() const { return num_heap_slots_; } |
510 int num_global_slots() const { return num_global_slots_; } | 524 int num_global_slots() const { return num_global_slots_; } |
511 | 525 |
512 int StackLocalCount() const; | 526 int StackLocalCount() const; |
513 int ContextLocalCount() const; | 527 int ContextLocalCount() const; |
514 int ContextGlobalCount() const; | 528 int ContextGlobalCount() const; |
515 | 529 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
666 bool force_context_allocation_; | 680 bool force_context_allocation_; |
667 | 681 |
668 // True if it doesn't need scope resolution (e.g., if the scope was | 682 // True if it doesn't need scope resolution (e.g., if the scope was |
669 // constructed based on a serialized scope info or a catch context). | 683 // constructed based on a serialized scope info or a catch context). |
670 bool already_resolved_; | 684 bool already_resolved_; |
671 | 685 |
672 // True if it holds 'var' declarations. | 686 // True if it holds 'var' declarations. |
673 bool is_declaration_scope_; | 687 bool is_declaration_scope_; |
674 | 688 |
675 // Computed as variables are declared. | 689 // Computed as variables are declared. |
676 int num_var_or_const_; | 690 int num_var_; |
677 | 691 |
678 // Computed via AllocateVariables; function, block and catch scopes only. | 692 // Computed via AllocateVariables; function, block and catch scopes only. |
679 int num_stack_slots_; | 693 int num_stack_slots_; |
680 int num_heap_slots_; | 694 int num_heap_slots_; |
681 int num_global_slots_; | 695 int num_global_slots_; |
682 | 696 |
683 // Info about the parameter list of a function. | 697 // Info about the parameter list of a function. |
684 int arity_; | 698 int arity_; |
685 bool has_simple_parameters_; | 699 bool has_simple_parameters_; |
686 Variable* rest_parameter_; | 700 Variable* rest_parameter_; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
814 AstValueFactory* ast_value_factory_; | 828 AstValueFactory* ast_value_factory_; |
815 Zone* zone_; | 829 Zone* zone_; |
816 | 830 |
817 PendingCompilationErrorHandler pending_error_handler_; | 831 PendingCompilationErrorHandler pending_error_handler_; |
818 }; | 832 }; |
819 | 833 |
820 } // namespace internal | 834 } // namespace internal |
821 } // namespace v8 | 835 } // namespace v8 |
822 | 836 |
823 #endif // V8_AST_SCOPES_H_ | 837 #endif // V8_AST_SCOPES_H_ |
OLD | NEW |