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); | |
246 | |
247 // --------------------------------------------------------------------------- | 239 // --------------------------------------------------------------------------- |
248 // Scope-specific info. | 240 // Scope-specific info. |
249 | 241 |
250 // Inform the scope that the corresponding code contains an eval call. | 242 // Inform the scope that the corresponding code contains an eval call. |
251 void RecordEvalCall() { scope_calls_eval_ = true; } | 243 void RecordEvalCall() { scope_calls_eval_ = true; } |
252 | 244 |
253 // Inform the scope that the corresponding code uses "arguments". | 245 // Inform the scope that the corresponding code uses "arguments". |
254 void RecordArgumentsUsage() { scope_uses_arguments_ = true; } | 246 void RecordArgumentsUsage() { scope_uses_arguments_ = true; } |
255 | 247 |
256 // Inform the scope that the corresponding code uses "super". | 248 // Inform the scope that the corresponding code uses "super". |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 484 |
493 // Inner scope list. | 485 // Inner scope list. |
494 ZoneList<Scope*>* inner_scopes() { return &inner_scopes_; } | 486 ZoneList<Scope*>* inner_scopes() { return &inner_scopes_; } |
495 | 487 |
496 // The scope immediately surrounding this scope, or NULL. | 488 // The scope immediately surrounding this scope, or NULL. |
497 Scope* outer_scope() const { return outer_scope_; } | 489 Scope* outer_scope() const { return outer_scope_; } |
498 | 490 |
499 // The ModuleDescriptor for this scope; only for module scopes. | 491 // The ModuleDescriptor for this scope; only for module scopes. |
500 ModuleDescriptor* module() const { return module_descriptor_; } | 492 ModuleDescriptor* module() const { return module_descriptor_; } |
501 | 493 |
502 AstRawString* catch_variable_name() const { | |
503 DCHECK(is_catch_scope()); | |
504 DCHECK(num_var() == 1); | |
505 return static_cast<AstRawString*>(variables_.Start()->key); | |
506 } | |
507 | |
508 // --------------------------------------------------------------------------- | 494 // --------------------------------------------------------------------------- |
509 // Variable allocation. | 495 // Variable allocation. |
510 | 496 |
511 // Collect stack and context allocated local variables in this scope. Note | 497 // Collect stack and context allocated local variables in this scope. Note |
512 // that the function variable - if present - is not collected and should be | 498 // that the function variable - if present - is not collected and should be |
513 // handled separately. | 499 // handled separately. |
514 void CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals, | 500 void CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals, |
515 ZoneList<Variable*>* context_locals, | 501 ZoneList<Variable*>* context_locals, |
516 ZoneList<Variable*>* context_globals); | 502 ZoneList<Variable*>* context_globals); |
517 | 503 |
518 // Current number of var locals. | 504 // Current number of var or const locals. |
519 int num_var() const { return num_var_; } | 505 int num_var_or_const() { return num_var_or_const_; } |
520 | 506 |
521 // Result of variable allocation. | 507 // Result of variable allocation. |
522 int num_stack_slots() const { return num_stack_slots_; } | 508 int num_stack_slots() const { return num_stack_slots_; } |
523 int num_heap_slots() const { return num_heap_slots_; } | 509 int num_heap_slots() const { return num_heap_slots_; } |
524 int num_global_slots() const { return num_global_slots_; } | 510 int num_global_slots() const { return num_global_slots_; } |
525 | 511 |
526 int StackLocalCount() const; | 512 int StackLocalCount() const; |
527 int ContextLocalCount() const; | 513 int ContextLocalCount() const; |
528 int ContextGlobalCount() const; | 514 int ContextGlobalCount() const; |
529 | 515 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 bool force_context_allocation_; | 666 bool force_context_allocation_; |
681 | 667 |
682 // True if it doesn't need scope resolution (e.g., if the scope was | 668 // True if it doesn't need scope resolution (e.g., if the scope was |
683 // constructed based on a serialized scope info or a catch context). | 669 // constructed based on a serialized scope info or a catch context). |
684 bool already_resolved_; | 670 bool already_resolved_; |
685 | 671 |
686 // True if it holds 'var' declarations. | 672 // True if it holds 'var' declarations. |
687 bool is_declaration_scope_; | 673 bool is_declaration_scope_; |
688 | 674 |
689 // Computed as variables are declared. | 675 // Computed as variables are declared. |
690 int num_var_; | 676 int num_var_or_const_; |
691 | 677 |
692 // Computed via AllocateVariables; function, block and catch scopes only. | 678 // Computed via AllocateVariables; function, block and catch scopes only. |
693 int num_stack_slots_; | 679 int num_stack_slots_; |
694 int num_heap_slots_; | 680 int num_heap_slots_; |
695 int num_global_slots_; | 681 int num_global_slots_; |
696 | 682 |
697 // Info about the parameter list of a function. | 683 // Info about the parameter list of a function. |
698 int arity_; | 684 int arity_; |
699 bool has_simple_parameters_; | 685 bool has_simple_parameters_; |
700 Variable* rest_parameter_; | 686 Variable* rest_parameter_; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 AstValueFactory* ast_value_factory_; | 814 AstValueFactory* ast_value_factory_; |
829 Zone* zone_; | 815 Zone* zone_; |
830 | 816 |
831 PendingCompilationErrorHandler pending_error_handler_; | 817 PendingCompilationErrorHandler pending_error_handler_; |
832 }; | 818 }; |
833 | 819 |
834 } // namespace internal | 820 } // namespace internal |
835 } // namespace v8 | 821 } // namespace v8 |
836 | 822 |
837 #endif // V8_AST_SCOPES_H_ | 823 #endif // V8_AST_SCOPES_H_ |
OLD | NEW |