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

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

Issue 2242583003: [Parser] Remove Variable::is_possibly_eval. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@toon_cl
Patch Set: Address comment Created 4 years, 4 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/ast.cc ('k') | src/compiler/ast-graph-builder.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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_VARIABLES_H_ 5 #ifndef V8_AST_VARIABLES_H_
6 #define V8_AST_VARIABLES_H_ 6 #define V8_AST_VARIABLES_H_
7 7
8 #include "src/ast/ast-value-factory.h" 8 #include "src/ast/ast-value-factory.h"
9 #include "src/zone.h" 9 #include "src/zone.h"
10 10
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 bool binding_needs_init() const { 75 bool binding_needs_init() const {
76 DCHECK(initialization_flag_ != kNeedsInitialization || 76 DCHECK(initialization_flag_ != kNeedsInitialization ||
77 IsLexicalVariableMode(mode_)); 77 IsLexicalVariableMode(mode_));
78 return initialization_flag_ == kNeedsInitialization; 78 return initialization_flag_ == kNeedsInitialization;
79 } 79 }
80 80
81 bool is_function() const { return kind_ == FUNCTION; } 81 bool is_function() const { return kind_ == FUNCTION; }
82 bool is_this() const { return kind_ == THIS; } 82 bool is_this() const { return kind_ == THIS; }
83 bool is_arguments() const { return kind_ == ARGUMENTS; } 83 bool is_arguments() const { return kind_ == ARGUMENTS; }
84 84
85 // True if the variable is named eval and not known to be shadowed.
86 bool is_possibly_eval(Isolate* isolate,
87 HandleDereferenceMode deref_mode =
88 HandleDereferenceMode::kAllowed) const {
89 // Note: it is safe to dereference isolate->factory()->eval_string() here
90 // regardless of |deref_mode| because it is a constant root and so will
91 // never be updated or moved.
92 return !is_this() &&
93 name_is_identical_to(isolate->factory()->eval_string(), deref_mode);
94 }
95
96 Variable* local_if_not_shadowed() const { 85 Variable* local_if_not_shadowed() const {
97 DCHECK(mode_ == DYNAMIC_LOCAL && local_if_not_shadowed_ != NULL); 86 DCHECK(mode_ == DYNAMIC_LOCAL && local_if_not_shadowed_ != NULL);
98 return local_if_not_shadowed_; 87 return local_if_not_shadowed_;
99 } 88 }
100 89
101 void set_local_if_not_shadowed(Variable* local) { 90 void set_local_if_not_shadowed(Variable* local) {
102 local_if_not_shadowed_ = local; 91 local_if_not_shadowed_ = local;
103 } 92 }
104 93
105 VariableLocation location() const { return location_; } 94 VariableLocation location() const { return location_; }
106 int index() const { return index_; } 95 int index() const { return index_; }
107 InitializationFlag initialization_flag() const { 96 InitializationFlag initialization_flag() const {
108 return initialization_flag_; 97 return initialization_flag_;
109 } 98 }
110 99
111 void AllocateTo(VariableLocation location, int index) { 100 void AllocateTo(VariableLocation location, int index) {
112 location_ = location; 101 location_ = location;
113 index_ = index; 102 index_ = index;
114 } 103 }
115 104
116 static int CompareIndex(Variable* const* v, Variable* const* w); 105 static int CompareIndex(Variable* const* v, Variable* const* w);
117 106
118 private: 107 private:
119 bool name_is_identical_to(Handle<Object> object,
120 HandleDereferenceMode deref_mode) const {
121 if (deref_mode == HandleDereferenceMode::kAllowed) {
122 return *name() == *object;
123 } else {
124 // If handle dereference isn't allowed use the handle address for
125 // identity. This depends on the variable name being internalized in a
126 // CanonicalHandleScope, so that all handles created during the
127 // internalization with identical values have identical locations, and any
128 // handles created which point to roots have the root handle's location.
129 return name().address() == object.address();
130 }
131 }
132
133 Scope* scope_; 108 Scope* scope_;
134 const AstRawString* name_; 109 const AstRawString* name_;
135 VariableMode mode_; 110 VariableMode mode_;
136 Kind kind_; 111 Kind kind_;
137 VariableLocation location_; 112 VariableLocation location_;
138 int index_; 113 int index_;
139 int initializer_position_; 114 int initializer_position_;
140 115
141 // If this field is set, this variable references the stored locally bound 116 // If this field is set, this variable references the stored locally bound
142 // variable, but it might be shadowed by variable bindings introduced by 117 // variable, but it might be shadowed by variable bindings introduced by
143 // sloppy 'eval' calls between the reference scope (inclusive) and the 118 // sloppy 'eval' calls between the reference scope (inclusive) and the
144 // binding scope (exclusive). 119 // binding scope (exclusive).
145 Variable* local_if_not_shadowed_; 120 Variable* local_if_not_shadowed_;
146 121
147 // Usage info. 122 // Usage info.
148 bool force_context_allocation_; // set by variable resolver 123 bool force_context_allocation_; // set by variable resolver
149 bool is_used_; 124 bool is_used_;
150 InitializationFlag initialization_flag_; 125 InitializationFlag initialization_flag_;
151 MaybeAssignedFlag maybe_assigned_; 126 MaybeAssignedFlag maybe_assigned_;
152 }; 127 };
153 } // namespace internal 128 } // namespace internal
154 } // namespace v8 129 } // namespace v8
155 130
156 #endif // V8_AST_VARIABLES_H_ 131 #endif // V8_AST_VARIABLES_H_
OLDNEW
« no previous file with comments | « src/ast/ast.cc ('k') | src/compiler/ast-graph-builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698