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

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

Issue 2407163003: PreParser: track variable declarations and parameters (Closed)
Patch Set: more tests Created 4 years 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 | « no previous file | src/ast/scopes.cc » ('j') | src/parsing/preparser.h » ('J')
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/base/compiler-specific.h" 8 #include "src/base/compiler-specific.h"
9 #include "src/base/hashmap.h" 9 #include "src/base/hashmap.h"
10 #include "src/globals.h" 10 #include "src/globals.h"
(...skipping 16 matching lines...) Expand all
27 class VariableMap: public ZoneHashMap { 27 class VariableMap: public ZoneHashMap {
28 public: 28 public:
29 explicit VariableMap(Zone* zone); 29 explicit VariableMap(Zone* zone);
30 30
31 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, 31 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name,
32 VariableMode mode, VariableKind kind, 32 VariableMode mode, VariableKind kind,
33 InitializationFlag initialization_flag, 33 InitializationFlag initialization_flag,
34 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, 34 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned,
35 bool* added = nullptr); 35 bool* added = nullptr);
36 36
37 // Records that "name" exists but doesn't create a Variable. Useful for
38 // preparsing.
39 void DeclareName(Zone* zone, const AstRawString* name);
40
37 Variable* Lookup(const AstRawString* name); 41 Variable* Lookup(const AstRawString* name);
38 void Remove(Variable* var); 42 void Remove(Variable* var);
39 void Add(Zone* zone, Variable* var); 43 void Add(Zone* zone, Variable* var);
40 }; 44 };
41 45
42 46
43 // Sloppy block-scoped function declarations to var-bind 47 // Sloppy block-scoped function declarations to var-bind
44 class SloppyBlockFunctionMap : public ZoneHashMap { 48 class SloppyBlockFunctionMap : public ZoneHashMap {
45 public: 49 public:
46 explicit SloppyBlockFunctionMap(Zone* zone); 50 explicit SloppyBlockFunctionMap(Zone* zone);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, 154 Variable* DeclareLocal(const AstRawString* name, VariableMode mode,
151 InitializationFlag init_flag, VariableKind kind, 155 InitializationFlag init_flag, VariableKind kind,
152 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); 156 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned);
153 157
154 Variable* DeclareVariable(Declaration* declaration, VariableMode mode, 158 Variable* DeclareVariable(Declaration* declaration, VariableMode mode,
155 InitializationFlag init, 159 InitializationFlag init,
156 bool allow_harmony_restrictive_generators, 160 bool allow_harmony_restrictive_generators,
157 bool* sloppy_mode_block_scope_function_redefinition, 161 bool* sloppy_mode_block_scope_function_redefinition,
158 bool* ok); 162 bool* ok);
159 163
164 void DeclareVariableName(const AstRawString* name, VariableMode mode);
165
160 // Declarations list. 166 // Declarations list.
161 ThreadedList<Declaration>* declarations() { return &decls_; } 167 ThreadedList<Declaration>* declarations() { return &decls_; }
162 168
163 ThreadedList<Variable>* locals() { return &locals_; } 169 ThreadedList<Variable>* locals() { return &locals_; }
164 170
165 // Create a new unresolved variable. 171 // Create a new unresolved variable.
166 VariableProxy* NewUnresolved(AstNodeFactory* factory, 172 VariableProxy* NewUnresolved(AstNodeFactory* factory,
167 const AstRawString* name, 173 const AstRawString* name,
168 int start_position = kNoSourcePosition, 174 int start_position = kNoSourcePosition,
169 VariableKind kind = NORMAL_VARIABLE); 175 VariableKind kind = NORMAL_VARIABLE);
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 // to the calling context of 'eval'. 525 // to the calling context of 'eval'.
520 Variable* LookupRecursive(VariableProxy* proxy, Scope* outer_scope_end); 526 Variable* LookupRecursive(VariableProxy* proxy, Scope* outer_scope_end);
521 void ResolveTo(ParseInfo* info, VariableProxy* proxy, Variable* var); 527 void ResolveTo(ParseInfo* info, VariableProxy* proxy, Variable* var);
522 void ResolveVariable(ParseInfo* info, VariableProxy* proxy); 528 void ResolveVariable(ParseInfo* info, VariableProxy* proxy);
523 void ResolveVariablesRecursively(ParseInfo* info); 529 void ResolveVariablesRecursively(ParseInfo* info);
524 530
525 // Finds free variables of this scope. This mutates the unresolved variables 531 // Finds free variables of this scope. This mutates the unresolved variables
526 // list along the way, so full resolution cannot be done afterwards. 532 // list along the way, so full resolution cannot be done afterwards.
527 // If a ParseInfo* is passed, non-free variables will be resolved. 533 // If a ParseInfo* is passed, non-free variables will be resolved.
528 VariableProxy* FetchFreeVariables(DeclarationScope* max_outer_scope, 534 VariableProxy* FetchFreeVariables(DeclarationScope* max_outer_scope,
529 bool try_to_resolve = true,
530 ParseInfo* info = nullptr, 535 ParseInfo* info = nullptr,
531 VariableProxy* stack = nullptr); 536 VariableProxy* stack = nullptr);
532 537
533 // Predicates. 538 // Predicates.
534 bool MustAllocate(Variable* var); 539 bool MustAllocate(Variable* var);
535 bool MustAllocateInContext(Variable* var); 540 bool MustAllocateInContext(Variable* var);
536 541
537 // Variable allocation. 542 // Variable allocation.
538 void AllocateStackSlot(Variable* var); 543 void AllocateStackSlot(Variable* var);
539 void AllocateHeapSlot(Variable* var); 544 void AllocateHeapSlot(Variable* var);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 if (scope->sibling_ == inner_scope) { 576 if (scope->sibling_ == inner_scope) {
572 scope->sibling_ = scope->sibling_->sibling_; 577 scope->sibling_ = scope->sibling_->sibling_;
573 return; 578 return;
574 } 579 }
575 } 580 }
576 } 581 }
577 582
578 void SetDefaults(); 583 void SetDefaults();
579 584
580 friend class DeclarationScope; 585 friend class DeclarationScope;
586 friend class ScopeTestHelper;
581 }; 587 };
582 588
583 class DeclarationScope : public Scope { 589 class DeclarationScope : public Scope {
584 public: 590 public:
585 DeclarationScope(Zone* zone, Scope* outer_scope, ScopeType scope_type, 591 DeclarationScope(Zone* zone, Scope* outer_scope, ScopeType scope_type,
586 FunctionKind function_kind = kNormalFunction); 592 FunctionKind function_kind = kNormalFunction);
587 DeclarationScope(Zone* zone, ScopeType scope_type, 593 DeclarationScope(Zone* zone, ScopeType scope_type,
588 Handle<ScopeInfo> scope_info); 594 Handle<ScopeInfo> scope_info);
589 // Creates a script scope. 595 // Creates a script scope.
590 DeclarationScope(Zone* zone, AstValueFactory* ast_value_factory); 596 DeclarationScope(Zone* zone, AstValueFactory* ast_value_factory);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 // either the function variable itself, or a non-local in case the function 648 // either the function variable itself, or a non-local in case the function
643 // calls sloppy eval. 649 // calls sloppy eval.
644 Variable* DeclareFunctionVar(const AstRawString* name); 650 Variable* DeclareFunctionVar(const AstRawString* name);
645 651
646 // Declare a parameter in this scope. When there are duplicated 652 // Declare a parameter in this scope. When there are duplicated
647 // parameters the rightmost one 'wins'. However, the implementation 653 // parameters the rightmost one 'wins'. However, the implementation
648 // expects all parameters to be declared and from left to right. 654 // expects all parameters to be declared and from left to right.
649 Variable* DeclareParameter(const AstRawString* name, VariableMode mode, 655 Variable* DeclareParameter(const AstRawString* name, VariableMode mode,
650 bool is_optional, bool is_rest, bool* is_duplicate, 656 bool is_optional, bool is_rest, bool* is_duplicate,
651 AstValueFactory* ast_value_factory); 657 AstValueFactory* ast_value_factory);
658 void DeclareParameterName(const AstRawString* name, bool is_optional,
659 bool is_rest, bool* is_duplicate,
660 AstValueFactory* ast_value_factory);
652 661
653 // Declare an implicit global variable in this scope which must be a 662 // Declare an implicit global variable in this scope which must be a
654 // script scope. The variable was introduced (possibly from an inner 663 // script scope. The variable was introduced (possibly from an inner
655 // scope) by a reference to an unresolved variable with no intervening 664 // scope) by a reference to an unresolved variable with no intervening
656 // with statements or eval calls. 665 // with statements or eval calls.
657 Variable* DeclareDynamicGlobal(const AstRawString* name, 666 Variable* DeclareDynamicGlobal(const AstRawString* name,
658 VariableKind variable_kind); 667 VariableKind variable_kind);
659 668
660 // The variable corresponding to the 'this' value. 669 // The variable corresponding to the 'this' value.
661 Variable* receiver() { 670 Variable* receiver() {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 void AllocateModuleVariables(); 866 void AllocateModuleVariables();
858 867
859 private: 868 private:
860 ModuleDescriptor* module_descriptor_; 869 ModuleDescriptor* module_descriptor_;
861 }; 870 };
862 871
863 } // namespace internal 872 } // namespace internal
864 } // namespace v8 873 } // namespace v8
865 874
866 #endif // V8_AST_SCOPES_H_ 875 #endif // V8_AST_SCOPES_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast/scopes.cc » ('j') | src/parsing/preparser.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698