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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 | 431 |
432 // Check that all Scopes in the scope tree use the same Zone. | 432 // Check that all Scopes in the scope tree use the same Zone. |
433 void CheckZones(); | 433 void CheckZones(); |
434 #endif | 434 #endif |
435 | 435 |
436 // Retrieve `IsSimpleParameterList` of current or outer function. | 436 // Retrieve `IsSimpleParameterList` of current or outer function. |
437 bool HasSimpleParameters(); | 437 bool HasSimpleParameters(); |
438 void set_is_debug_evaluate_scope() { is_debug_evaluate_scope_ = true; } | 438 void set_is_debug_evaluate_scope() { is_debug_evaluate_scope_ = true; } |
439 | 439 |
440 protected: | 440 protected: |
441 // Creates a script scope. | 441 explicit Scope(Zone* zone, ScopeType scope_type = SCRIPT_SCOPE); |
442 explicit Scope(Zone* zone); | |
443 | 442 |
444 void set_language_mode(LanguageMode language_mode) { | 443 void set_language_mode(LanguageMode language_mode) { |
445 is_strict_ = is_strict(language_mode); | 444 is_strict_ = is_strict(language_mode); |
446 } | 445 } |
447 | 446 |
448 private: | 447 private: |
449 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, | 448 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, |
450 VariableMode mode, Variable::Kind kind, | 449 VariableMode mode, Variable::Kind kind, |
451 InitializationFlag initialization_flag, | 450 InitializationFlag initialization_flag, |
452 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned) { | 451 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 | 558 |
560 // Variable allocation. | 559 // Variable allocation. |
561 void AllocateStackSlot(Variable* var); | 560 void AllocateStackSlot(Variable* var); |
562 void AllocateHeapSlot(Variable* var); | 561 void AllocateHeapSlot(Variable* var); |
563 void AllocateNonParameterLocal(Variable* var); | 562 void AllocateNonParameterLocal(Variable* var); |
564 void AllocateDeclaredGlobal(Variable* var); | 563 void AllocateDeclaredGlobal(Variable* var); |
565 void AllocateNonParameterLocalsAndDeclaredGlobals(); | 564 void AllocateNonParameterLocalsAndDeclaredGlobals(); |
566 void AllocateVariablesRecursively(); | 565 void AllocateVariablesRecursively(); |
567 | 566 |
568 // Construct a scope based on the scope info. | 567 // Construct a scope based on the scope info. |
569 Scope(Zone* zone, Scope* inner_scope, ScopeType type, | 568 Scope(Zone* zone, ScopeType type, Handle<ScopeInfo> scope_info); |
570 Handle<ScopeInfo> scope_info); | |
571 | 569 |
572 // Construct a catch scope with a binding for the name. | 570 // Construct a catch scope with a binding for the name. |
573 Scope(Zone* zone, Scope* inner_scope, | 571 Scope(Zone* zone, const AstRawString* catch_variable_name); |
574 const AstRawString* catch_variable_name); | |
575 | 572 |
576 void AddInnerScope(Scope* inner_scope) { | 573 void AddInnerScope(Scope* inner_scope) { |
577 inner_scope->sibling_ = inner_scope_; | 574 inner_scope->sibling_ = inner_scope_; |
578 inner_scope_ = inner_scope; | 575 inner_scope_ = inner_scope; |
579 inner_scope->outer_scope_ = this; | 576 inner_scope->outer_scope_ = this; |
580 } | 577 } |
581 | 578 |
582 void RemoveInnerScope(Scope* inner_scope) { | 579 void RemoveInnerScope(Scope* inner_scope) { |
583 DCHECK_NOT_NULL(inner_scope); | 580 DCHECK_NOT_NULL(inner_scope); |
584 if (inner_scope == inner_scope_) { | 581 if (inner_scope == inner_scope_) { |
(...skipping 14 matching lines...) Expand all Loading... |
599 void DeserializeScopeInfo(Isolate* isolate, | 596 void DeserializeScopeInfo(Isolate* isolate, |
600 AstValueFactory* ast_value_factory); | 597 AstValueFactory* ast_value_factory); |
601 | 598 |
602 friend class DeclarationScope; | 599 friend class DeclarationScope; |
603 }; | 600 }; |
604 | 601 |
605 class DeclarationScope : public Scope { | 602 class DeclarationScope : public Scope { |
606 public: | 603 public: |
607 DeclarationScope(Zone* zone, Scope* outer_scope, ScopeType scope_type, | 604 DeclarationScope(Zone* zone, Scope* outer_scope, ScopeType scope_type, |
608 FunctionKind function_kind = kNormalFunction); | 605 FunctionKind function_kind = kNormalFunction); |
609 DeclarationScope(Zone* zone, Scope* inner_scope, ScopeType scope_type, | 606 DeclarationScope(Zone* zone, ScopeType scope_type, |
610 Handle<ScopeInfo> scope_info); | 607 Handle<ScopeInfo> scope_info); |
611 // Creates a script scope. | 608 // Creates a script scope. |
612 explicit DeclarationScope(Zone* zone); | 609 explicit DeclarationScope(Zone* zone); |
613 | 610 |
614 bool IsDeclaredParameter(const AstRawString* name) { | 611 bool IsDeclaredParameter(const AstRawString* name) { |
615 // If IsSimpleParameterList is false, duplicate parameters are not allowed, | 612 // If IsSimpleParameterList is false, duplicate parameters are not allowed, |
616 // however `arguments` may be allowed if function is not strict code. Thus, | 613 // however `arguments` may be allowed if function is not strict code. Thus, |
617 // the assumptions explained above do not hold. | 614 // the assumptions explained above do not hold. |
618 return params_.Contains(variables_.Lookup(name)); | 615 return params_.Contains(variables_.Lookup(name)); |
619 } | 616 } |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 void AllocateModuleVariables(); | 881 void AllocateModuleVariables(); |
885 | 882 |
886 private: | 883 private: |
887 ModuleDescriptor* module_descriptor_; | 884 ModuleDescriptor* module_descriptor_; |
888 }; | 885 }; |
889 | 886 |
890 } // namespace internal | 887 } // namespace internal |
891 } // namespace v8 | 888 } // namespace v8 |
892 | 889 |
893 #endif // V8_AST_SCOPES_H_ | 890 #endif // V8_AST_SCOPES_H_ |
OLD | NEW |