Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1595)

Side by Side Diff: src/ast/scopes.h

Issue 1704223002: Remove strong mode support from Scope and Variable (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove test-parsing test Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ast/scopeinfo.cc ('k') | src/ast/scopes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/hashmap.h" 9 #include "src/hashmap.h"
10 #include "src/pending-compilation-error-handler.h" 10 #include "src/pending-compilation-error-handler.h"
11 #include "src/zone.h" 11 #include "src/zone.h"
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 15
16 class ParseInfo; 16 class ParseInfo;
17 17
18 // A hash map to support fast variable declaration and lookup. 18 // A hash map to support fast variable declaration and lookup.
19 class VariableMap: public ZoneHashMap { 19 class VariableMap: public ZoneHashMap {
20 public: 20 public:
21 explicit VariableMap(Zone* zone); 21 explicit VariableMap(Zone* zone);
22 22
23 virtual ~VariableMap(); 23 virtual ~VariableMap();
24 24
25 Variable* Declare(Scope* scope, const AstRawString* name, VariableMode mode, 25 Variable* Declare(Scope* scope, const AstRawString* name, VariableMode mode,
26 Variable::Kind kind, InitializationFlag initialization_flag, 26 Variable::Kind kind, InitializationFlag initialization_flag,
27 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, 27 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned);
28 int declaration_group_start = -1);
29 28
30 Variable* Lookup(const AstRawString* name); 29 Variable* Lookup(const AstRawString* name);
31 30
32 Zone* zone() const { return zone_; } 31 Zone* zone() const { return zone_; }
33 32
34 private: 33 private:
35 Zone* zone_; 34 Zone* zone_;
36 }; 35 };
37 36
38 37
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // parameters the rightmost one 'wins'. However, the implementation 155 // parameters the rightmost one 'wins'. However, the implementation
157 // expects all parameters to be declared and from left to right. 156 // expects all parameters to be declared and from left to right.
158 Variable* DeclareParameter( 157 Variable* DeclareParameter(
159 const AstRawString* name, VariableMode mode, 158 const AstRawString* name, VariableMode mode,
160 bool is_optional, bool is_rest, bool* is_duplicate); 159 bool is_optional, bool is_rest, bool* is_duplicate);
161 160
162 // Declare a local variable in this scope. If the variable has been 161 // Declare a local variable in this scope. If the variable has been
163 // declared before, the previously declared variable is returned. 162 // declared before, the previously declared variable is returned.
164 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, 163 Variable* DeclareLocal(const AstRawString* name, VariableMode mode,
165 InitializationFlag init_flag, Variable::Kind kind, 164 InitializationFlag init_flag, Variable::Kind kind,
166 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, 165 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned);
167 int declaration_group_start = -1);
168 166
169 // Declare an implicit global variable in this scope which must be a 167 // Declare an implicit global variable in this scope which must be a
170 // script scope. The variable was introduced (possibly from an inner 168 // script scope. The variable was introduced (possibly from an inner
171 // scope) by a reference to an unresolved variable with no intervening 169 // scope) by a reference to an unresolved variable with no intervening
172 // with statements or eval calls. 170 // with statements or eval calls.
173 Variable* DeclareDynamicGlobal(const AstRawString* name); 171 Variable* DeclareDynamicGlobal(const AstRawString* name);
174 172
175 // Create a new unresolved variable. 173 // Create a new unresolved variable.
176 VariableProxy* NewUnresolved(AstNodeFactory* factory, 174 VariableProxy* NewUnresolved(AstNodeFactory* factory,
177 const AstRawString* name, 175 const AstRawString* name,
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 } 368 }
371 369
372 bool NeedsHomeObject() const { 370 bool NeedsHomeObject() const {
373 return scope_uses_super_property_ || 371 return scope_uses_super_property_ ||
374 ((scope_calls_eval_ || inner_scope_calls_eval_) && 372 ((scope_calls_eval_ || inner_scope_calls_eval_) &&
375 (IsConciseMethod(function_kind()) || 373 (IsConciseMethod(function_kind()) ||
376 IsAccessorFunction(function_kind()) || 374 IsAccessorFunction(function_kind()) ||
377 IsClassConstructor(function_kind()))); 375 IsClassConstructor(function_kind())));
378 } 376 }
379 377
380 const Scope* NearestOuterEvalScope() const {
381 if (is_eval_scope()) return this;
382 if (outer_scope() == nullptr) return nullptr;
383 return outer_scope()->NearestOuterEvalScope();
384 }
385
386 // --------------------------------------------------------------------------- 378 // ---------------------------------------------------------------------------
387 // Accessors. 379 // Accessors.
388 380
389 // The type of this scope. 381 // The type of this scope.
390 ScopeType scope_type() const { return scope_type_; } 382 ScopeType scope_type() const { return scope_type_; }
391 383
392 FunctionKind function_kind() const { return function_kind_; } 384 FunctionKind function_kind() const { return function_kind_; }
393 385
394 // The language mode of this scope. 386 // The language mode of this scope.
395 LanguageMode language_mode() const { return language_mode_; } 387 LanguageMode language_mode() const { return language_mode_; }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 488
497 // Inner scope list. 489 // Inner scope list.
498 ZoneList<Scope*>* inner_scopes() { return &inner_scopes_; } 490 ZoneList<Scope*>* inner_scopes() { return &inner_scopes_; }
499 491
500 // The scope immediately surrounding this scope, or NULL. 492 // The scope immediately surrounding this scope, or NULL.
501 Scope* outer_scope() const { return outer_scope_; } 493 Scope* outer_scope() const { return outer_scope_; }
502 494
503 // The ModuleDescriptor for this scope; only for module scopes. 495 // The ModuleDescriptor for this scope; only for module scopes.
504 ModuleDescriptor* module() const { return module_descriptor_; } 496 ModuleDescriptor* module() const { return module_descriptor_; }
505 497
506
507 void set_class_declaration_group_start(int position) {
508 class_declaration_group_start_ = position;
509 }
510
511 int class_declaration_group_start() const {
512 return class_declaration_group_start_;
513 }
514
515 // --------------------------------------------------------------------------- 498 // ---------------------------------------------------------------------------
516 // Variable allocation. 499 // Variable allocation.
517 500
518 // Collect stack and context allocated local variables in this scope. Note 501 // Collect stack and context allocated local variables in this scope. Note
519 // that the function variable - if present - is not collected and should be 502 // that the function variable - if present - is not collected and should be
520 // handled separately. 503 // handled separately.
521 void CollectStackAndContextLocals( 504 void CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals,
522 ZoneList<Variable*>* stack_locals, ZoneList<Variable*>* context_locals, 505 ZoneList<Variable*>* context_locals,
523 ZoneList<Variable*>* context_globals, 506 ZoneList<Variable*>* context_globals);
524 ZoneList<Variable*>* strong_mode_free_variables = nullptr);
525 507
526 // Current number of var or const locals. 508 // Current number of var or const locals.
527 int num_var_or_const() { return num_var_or_const_; } 509 int num_var_or_const() { return num_var_or_const_; }
528 510
529 // Result of variable allocation. 511 // Result of variable allocation.
530 int num_stack_slots() const { return num_stack_slots_; } 512 int num_stack_slots() const { return num_stack_slots_; }
531 int num_heap_slots() const { return num_heap_slots_; } 513 int num_heap_slots() const { return num_heap_slots_; }
532 int num_global_slots() const { return num_global_slots_; } 514 int num_global_slots() const { return num_global_slots_; }
533 515
534 int StackLocalCount() const; 516 int StackLocalCount() const;
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 // scope. If the code is executed because of a call to 'eval', the context 759 // scope. If the code is executed because of a call to 'eval', the context
778 // parameter should be set to the calling context of 'eval'. 760 // parameter should be set to the calling context of 'eval'.
779 Variable* LookupRecursive(VariableProxy* proxy, BindingKind* binding_kind, 761 Variable* LookupRecursive(VariableProxy* proxy, BindingKind* binding_kind,
780 AstNodeFactory* factory); 762 AstNodeFactory* factory);
781 MUST_USE_RESULT 763 MUST_USE_RESULT
782 bool ResolveVariable(ParseInfo* info, VariableProxy* proxy, 764 bool ResolveVariable(ParseInfo* info, VariableProxy* proxy,
783 AstNodeFactory* factory); 765 AstNodeFactory* factory);
784 MUST_USE_RESULT 766 MUST_USE_RESULT
785 bool ResolveVariablesRecursively(ParseInfo* info, AstNodeFactory* factory); 767 bool ResolveVariablesRecursively(ParseInfo* info, AstNodeFactory* factory);
786 768
787 bool CheckStrongModeDeclaration(VariableProxy* proxy, Variable* var);
788
789 // If this scope is a method scope of a class, return the corresponding
790 // class variable, otherwise nullptr.
791 ClassVariable* ClassVariableForMethod() const;
792
793 // Scope analysis. 769 // Scope analysis.
794 void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval); 770 void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval);
795 bool HasTrivialContext() const; 771 bool HasTrivialContext() const;
796 772
797 // Predicates. 773 // Predicates.
798 bool MustAllocate(Variable* var); 774 bool MustAllocate(Variable* var);
799 bool MustAllocateInContext(Variable* var); 775 bool MustAllocateInContext(Variable* var);
800 bool HasArgumentsParameter(Isolate* isolate); 776 bool HasArgumentsParameter(Isolate* isolate);
801 777
802 // Variable allocation. 778 // Variable allocation.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 } 823 }
848 824
849 void SetDefaults(ScopeType type, Scope* outer_scope, 825 void SetDefaults(ScopeType type, Scope* outer_scope,
850 Handle<ScopeInfo> scope_info, 826 Handle<ScopeInfo> scope_info,
851 FunctionKind function_kind = kNormalFunction); 827 FunctionKind function_kind = kNormalFunction);
852 828
853 AstValueFactory* ast_value_factory_; 829 AstValueFactory* ast_value_factory_;
854 Zone* zone_; 830 Zone* zone_;
855 831
856 PendingCompilationErrorHandler pending_error_handler_; 832 PendingCompilationErrorHandler pending_error_handler_;
857
858 // For tracking which classes are declared consecutively. Needed for strong
859 // mode.
860 int class_declaration_group_start_;
861 }; 833 };
862 834
863 } // namespace internal 835 } // namespace internal
864 } // namespace v8 836 } // namespace v8
865 837
866 #endif // V8_AST_SCOPES_H_ 838 #endif // V8_AST_SCOPES_H_
OLDNEW
« no previous file with comments | « src/ast/scopeinfo.cc ('k') | src/ast/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698