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

Side by Side Diff: src/variables.h

Issue 943543002: [strong] Declaration-after-use errors. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: more fixes + tests Created 5 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
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_VARIABLES_H_ 5 #ifndef V8_VARIABLES_H_
6 #define V8_VARIABLES_H_ 6 #define V8_VARIABLES_H_
7 7
8 #include "src/ast-value-factory.h" 8 #include "src/ast-value-factory.h"
9 #include "src/zone.h" 9 #include "src/zone.h"
10 10
11 namespace v8 { 11 namespace v8 {
12 namespace internal { 12 namespace internal {
13 13
14 // The AST refers to variables via VariableProxies - placeholders for the actual 14 // The AST refers to variables via VariableProxies - placeholders for the actual
15 // variables. Variables themselves are never directly referred to from the AST, 15 // variables. Variables themselves are never directly referred to from the AST,
16 // they are maintained by scopes, and referred to from VariableProxies and Slots 16 // they are maintained by scopes, and referred to from VariableProxies and Slots
17 // after binding and variable allocation. 17 // after binding and variable allocation.
18 18
19 class Variable: public ZoneObject { 19 class Variable: public ZoneObject {
20 public: 20 public:
21 enum Kind { NORMAL, THIS, NEW_TARGET, ARGUMENTS }; 21 enum Kind { NORMAL, FUNCTION, THIS, NEW_TARGET, ARGUMENTS };
arv (Not doing code reviews) 2015/02/23 14:45:55 I find this change strange. How is FUNCTION relate
marja 2015/02/24 13:29:35 The previous NORMAL is split into NORMAL and FUNCT
22 22
23 enum Location { 23 enum Location {
24 // Before and during variable allocation, a variable whose location is 24 // Before and during variable allocation, a variable whose location is
25 // not yet determined. After allocation, a variable looked up as a 25 // not yet determined. After allocation, a variable looked up as a
26 // property on the global object (and possibly absent). name() is the 26 // property on the global object (and possibly absent). name() is the
27 // variable name, index() is invalid. 27 // variable name, index() is invalid.
28 UNALLOCATED, 28 UNALLOCATED,
29 29
30 // A slot in the parameter section on the stack. index() is the 30 // A slot in the parameter section on the stack. index() is the
31 // parameter index, counting left-to-right. The receiver is index -1; 31 // parameter index, counting left-to-right. The receiver is index -1;
(...skipping 10 matching lines...) Expand all
42 CONTEXT, 42 CONTEXT,
43 43
44 // A named slot in a heap context. name() is the variable name in the 44 // A named slot in a heap context. name() is the variable name in the
45 // context object on the heap, with lookup starting at the current 45 // context object on the heap, with lookup starting at the current
46 // context. index() is invalid. 46 // context. index() is invalid.
47 LOOKUP 47 LOOKUP
48 }; 48 };
49 49
50 Variable(Scope* scope, const AstRawString* name, VariableMode mode, 50 Variable(Scope* scope, const AstRawString* name, VariableMode mode,
51 bool is_valid_ref, Kind kind, InitializationFlag initialization_flag, 51 bool is_valid_ref, Kind kind, InitializationFlag initialization_flag,
52 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); 52 int position, MaybeAssignedFlag maybe_assigned_flag = kNotAssigned);
53 53
54 // Printing support 54 // Printing support
55 static const char* Mode2String(VariableMode mode); 55 static const char* Mode2String(VariableMode mode);
56 56
57 bool IsValidReference() { return is_valid_ref_; } 57 bool IsValidReference() { return is_valid_ref_; }
58 58
59 // The source code for an eval() call may refer to a variable that is 59 // The source code for an eval() call may refer to a variable that is
60 // in an outer scope about which we don't know anything (it may not 60 // in an outer scope about which we don't know anything (it may not
61 // be the script scope). scope() is NULL in that case. Currently the 61 // be the script scope). scope() is NULL in that case. Currently the
62 // scope is only used to follow the context chain length. 62 // scope is only used to follow the context chain length.
63 Scope* scope() const { return scope_; } 63 Scope* scope() const { return scope_; }
64 64
65 Handle<String> name() const { return name_->string(); } 65 Handle<String> name() const { return name_->string(); }
66 const AstRawString* raw_name() const { return name_; } 66 const AstRawString* raw_name() const { return name_; }
67 VariableMode mode() const { return mode_; } 67 VariableMode mode() const { return mode_; }
68 int position() const { return position_; }
68 bool has_forced_context_allocation() const { 69 bool has_forced_context_allocation() const {
69 return force_context_allocation_; 70 return force_context_allocation_;
70 } 71 }
71 void ForceContextAllocation() { 72 void ForceContextAllocation() {
72 DCHECK(mode_ != TEMPORARY); 73 DCHECK(mode_ != TEMPORARY);
73 force_context_allocation_ = true; 74 force_context_allocation_ = true;
74 } 75 }
75 bool is_used() { return is_used_; } 76 bool is_used() { return is_used_; }
76 void set_is_used() { is_used_ = true; } 77 void set_is_used() { is_used_ = true; }
77 MaybeAssignedFlag maybe_assigned() const { return maybe_assigned_; } 78 MaybeAssignedFlag maybe_assigned() const { return maybe_assigned_; }
(...skipping 13 matching lines...) Expand all
91 bool IsContextSlot() const { return location_ == CONTEXT; } 92 bool IsContextSlot() const { return location_ == CONTEXT; }
92 bool IsLookupSlot() const { return location_ == LOOKUP; } 93 bool IsLookupSlot() const { return location_ == LOOKUP; }
93 bool IsGlobalObjectProperty() const; 94 bool IsGlobalObjectProperty() const;
94 95
95 bool is_dynamic() const { return IsDynamicVariableMode(mode_); } 96 bool is_dynamic() const { return IsDynamicVariableMode(mode_); }
96 bool is_const_mode() const { return IsImmutableVariableMode(mode_); } 97 bool is_const_mode() const { return IsImmutableVariableMode(mode_); }
97 bool binding_needs_init() const { 98 bool binding_needs_init() const {
98 return initialization_flag_ == kNeedsInitialization; 99 return initialization_flag_ == kNeedsInitialization;
99 } 100 }
100 101
102 bool is_function() const { return kind_ == FUNCTION; }
101 bool is_this() const { return kind_ == THIS; } 103 bool is_this() const { return kind_ == THIS; }
102 bool is_new_target() const { return kind_ == NEW_TARGET; } 104 bool is_new_target() const { return kind_ == NEW_TARGET; }
103 bool is_arguments() const { return kind_ == ARGUMENTS; } 105 bool is_arguments() const { return kind_ == ARGUMENTS; }
104 106
105 // True if the variable is named eval and not known to be shadowed. 107 // True if the variable is named eval and not known to be shadowed.
106 bool is_possibly_eval(Isolate* isolate) const { 108 bool is_possibly_eval(Isolate* isolate) const {
107 return IsVariable(isolate->factory()->eval_string()); 109 return IsVariable(isolate->factory()->eval_string());
108 } 110 }
109 111
110 Variable* local_if_not_shadowed() const { 112 Variable* local_if_not_shadowed() const {
(...skipping 16 matching lines...) Expand all
127 index_ = index; 129 index_ = index;
128 } 130 }
129 131
130 static int CompareIndex(Variable* const* v, Variable* const* w); 132 static int CompareIndex(Variable* const* v, Variable* const* w);
131 133
132 private: 134 private:
133 Scope* scope_; 135 Scope* scope_;
134 const AstRawString* name_; 136 const AstRawString* name_;
135 VariableMode mode_; 137 VariableMode mode_;
136 Kind kind_; 138 Kind kind_;
139 int position_;
137 Location location_; 140 Location location_;
138 int index_; 141 int index_;
139 int initializer_position_; 142 int initializer_position_;
140 143
141 // If this field is set, this variable references the stored locally bound 144 // If this field is set, this variable references the stored locally bound
142 // variable, but it might be shadowed by variable bindings introduced by 145 // variable, but it might be shadowed by variable bindings introduced by
143 // sloppy 'eval' calls between the reference scope (inclusive) and the 146 // sloppy 'eval' calls between the reference scope (inclusive) and the
144 // binding scope (exclusive). 147 // binding scope (exclusive).
145 Variable* local_if_not_shadowed_; 148 Variable* local_if_not_shadowed_;
146 149
147 // Valid as a reference? (const and this are not valid, for example) 150 // Valid as a reference? (const and this are not valid, for example)
148 bool is_valid_ref_; 151 bool is_valid_ref_;
149 152
150 // Usage info. 153 // Usage info.
151 bool force_context_allocation_; // set by variable resolver 154 bool force_context_allocation_; // set by variable resolver
152 bool is_used_; 155 bool is_used_;
153 InitializationFlag initialization_flag_; 156 InitializationFlag initialization_flag_;
154 MaybeAssignedFlag maybe_assigned_; 157 MaybeAssignedFlag maybe_assigned_;
155 }; 158 };
156 159
157 160
158 } } // namespace v8::internal 161 } } // namespace v8::internal
159 162
160 #endif // V8_VARIABLES_H_ 163 #endif // V8_VARIABLES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698