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

Side by Side Diff: vm/scopes.h

Issue 10632009: Make the parser agnostic to the TokenStream implementation. This is the first step towards compacti… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « vm/raw_object_snapshot.cc ('k') | vm/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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_SCOPES_H_ 5 #ifndef VM_SCOPES_H_
6 #define VM_SCOPES_H_ 6 #define VM_SCOPES_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/growable_array.h" 10 #include "vm/growable_array.h"
11 11
12 namespace dart { 12 namespace dart {
13 13
14 class BitVector; 14 class BitVector;
15 class JoinEntryInstr; 15 class JoinEntryInstr;
16 class LocalScope; 16 class LocalScope;
17 class LocalVariable; 17 class LocalVariable;
18 class SourceLabel; 18 class SourceLabel;
19 19
20 20
21 class LocalVariable : public ZoneAllocated { 21 class LocalVariable : public ZoneAllocated {
22 public: 22 public:
23 LocalVariable(intptr_t token_index, 23 LocalVariable(intptr_t token_pos,
24 const String& name, 24 const String& name,
25 const AbstractType& type) 25 const AbstractType& type)
26 : token_index_(token_index), 26 : token_pos_(token_pos),
27 name_(name), 27 name_(name),
28 owner_(NULL), 28 owner_(NULL),
29 type_(type), 29 type_(type),
30 is_final_(false), 30 is_final_(false),
31 is_captured_(false), 31 is_captured_(false),
32 is_invisible_(false), 32 is_invisible_(false),
33 index_(LocalVariable::kUnitializedIndex) { 33 index_(LocalVariable::kUnitializedIndex) {
34 ASSERT(type.IsZoneHandle()); 34 ASSERT(type.IsZoneHandle());
35 ASSERT(type.IsFinalized()); 35 ASSERT(type.IsFinalized());
36 } 36 }
37 37
38 intptr_t token_index() const { return token_index_; } 38 intptr_t token_pos() const { return token_pos_; }
39 const String& name() const { return name_; } 39 const String& name() const { return name_; }
40 LocalScope* owner() const { return owner_; } 40 LocalScope* owner() const { return owner_; }
41 void set_owner(LocalScope* owner) { 41 void set_owner(LocalScope* owner) {
42 ASSERT(owner_ == NULL); 42 ASSERT(owner_ == NULL);
43 owner_ = owner; 43 owner_ = owner;
44 } 44 }
45 45
46 const AbstractType& type() const { return type_; } 46 const AbstractType& type() const { return type_; }
47 47
48 bool is_final() const { return is_final_; } 48 bool is_final() const { return is_final_; }
(...skipping 29 matching lines...) Expand all
78 // all parameters. 78 // all parameters.
79 int BitIndexIn(intptr_t var_count) const; 79 int BitIndexIn(intptr_t var_count) const;
80 80
81 // Name of the internal variable that is used to save the context chain 81 // Name of the internal variable that is used to save the context chain
82 // on function entry. 82 // on function entry.
83 static const char* kSavedContextVarName; 83 static const char* kSavedContextVarName;
84 84
85 private: 85 private:
86 static const int kUnitializedIndex = INT_MIN; 86 static const int kUnitializedIndex = INT_MIN;
87 87
88 const intptr_t token_index_; 88 const intptr_t token_pos_;
89 const String& name_; 89 const String& name_;
90 LocalScope* owner_; // Local scope declaring this variable. 90 LocalScope* owner_; // Local scope declaring this variable.
91 91
92 const AbstractType& type_; // Declaration type of local variable. 92 const AbstractType& type_; // Declaration type of local variable.
93 93
94 bool is_final_; // If true, this variable is readonly. 94 bool is_final_; // If true, this variable is readonly.
95 bool is_captured_; // If true, this variable lives in the context, otherwise 95 bool is_captured_; // If true, this variable lives in the context, otherwise
96 // in the stack frame. 96 // in the stack frame.
97 bool is_invisible_; 97 bool is_invisible_;
98 int index_; // Allocation index in words relative to frame pointer (if not 98 int index_; // Allocation index in words relative to frame pointer (if not
(...skipping 11 matching lines...) Expand all
110 kWhile, 110 kWhile,
111 kDoWhile, 111 kDoWhile,
112 kSwitch, 112 kSwitch,
113 kCase, 113 kCase,
114 kTry, 114 kTry,
115 kCatch, 115 kCatch,
116 kForward, 116 kForward,
117 kStatement // Any statement other than the above 117 kStatement // Any statement other than the above
118 }; 118 };
119 119
120 SourceLabel(intptr_t token_index, const String& name, Kind kind) 120 SourceLabel(intptr_t token_pos, const String& name, Kind kind)
121 : token_index_(token_index), 121 : token_pos_(token_pos),
122 name_(name), 122 name_(name),
123 owner_(NULL), 123 owner_(NULL),
124 kind_(kind), 124 kind_(kind),
125 continue_label_(), 125 continue_label_(),
126 break_label_(), 126 break_label_(),
127 join_for_break_(NULL), 127 join_for_break_(NULL),
128 join_for_continue_(NULL), 128 join_for_continue_(NULL),
129 is_continue_target_(false) { 129 is_continue_target_(false) {
130 } 130 }
131 131
132 static SourceLabel* New(intptr_t token_index, String* name, Kind kind) { 132 static SourceLabel* New(intptr_t token_pos, String* name, Kind kind) {
133 if (name != NULL) { 133 if (name != NULL) {
134 return new SourceLabel(token_index, *name, kind); 134 return new SourceLabel(token_pos, *name, kind);
135 } else { 135 } else {
136 return new SourceLabel(token_index, 136 return new SourceLabel(token_pos,
137 String::ZoneHandle(String::New(kDefaultLabelName)), 137 String::ZoneHandle(String::New(kDefaultLabelName)),
138 kind); 138 kind);
139 } 139 }
140 } 140 }
141 141
142 intptr_t token_index() const { return token_index_; } 142 intptr_t token_pos() const { return token_pos_; }
143 const String& name() const { return name_; } 143 const String& name() const { return name_; }
144 LocalScope* owner() const { return owner_; } 144 LocalScope* owner() const { return owner_; }
145 void set_owner(LocalScope* owner) { 145 void set_owner(LocalScope* owner) {
146 ASSERT(owner_ == NULL); 146 ASSERT(owner_ == NULL);
147 owner_ = owner; 147 owner_ = owner;
148 } 148 }
149 149
150 Kind kind() const { return kind_; } 150 Kind kind() const { return kind_; }
151 Label* break_label() { return &break_label_; } 151 Label* break_label() { return &break_label_; }
152 Label* continue_label() { return &continue_label_; } 152 Label* continue_label() { return &continue_label_; }
(...skipping 18 matching lines...) Expand all
171 JoinEntryInstr* join_for_break() const { 171 JoinEntryInstr* join_for_break() const {
172 return join_for_break_; 172 return join_for_break_;
173 } 173 }
174 174
175 // Returns the function level of the scope in which the label is defined. 175 // Returns the function level of the scope in which the label is defined.
176 int FunctionLevel() const; 176 int FunctionLevel() const;
177 177
178 void ResolveForwardReference() { kind_ = kCase; } 178 void ResolveForwardReference() { kind_ = kCase; }
179 179
180 private: 180 private:
181 const intptr_t token_index_; 181 const intptr_t token_pos_;
182 const String& name_; 182 const String& name_;
183 LocalScope* owner_; // Local scope declaring this label. 183 LocalScope* owner_; // Local scope declaring this label.
184 184
185 Kind kind_; 185 Kind kind_;
186 Label continue_label_; 186 Label continue_label_;
187 Label break_label_; 187 Label break_label_;
188 JoinEntryInstr* join_for_break_; 188 JoinEntryInstr* join_for_break_;
189 JoinEntryInstr* join_for_continue_; 189 JoinEntryInstr* join_for_continue_;
190 bool is_continue_target_; // Needed for CaseNode. 190 bool is_continue_target_; // Needed for CaseNode.
191 static const char* kDefaultLabelName; 191 static const char* kDefaultLabelName;
(...skipping 23 matching lines...) Expand all
215 int context_level() const { 215 int context_level() const {
216 ASSERT(HasContextLevel()); 216 ASSERT(HasContextLevel());
217 return context_level_; 217 return context_level_;
218 } 218 }
219 void set_context_level(int context_level) { 219 void set_context_level(int context_level) {
220 ASSERT(!HasContextLevel()); 220 ASSERT(!HasContextLevel());
221 ASSERT(context_level != kUnitializedContextLevel); 221 ASSERT(context_level != kUnitializedContextLevel);
222 context_level_ = context_level; 222 context_level_ = context_level;
223 } 223 }
224 224
225 intptr_t begin_token_index() const { return begin_token_index_; } 225 intptr_t begin_token_pos() const { return begin_token_pos_; }
226 void set_begin_token_index(intptr_t value) { begin_token_index_ = value; } 226 void set_begin_token_pos(intptr_t value) { begin_token_pos_ = value; }
227 227
228 intptr_t end_token_index() const { return end_token_index_; } 228 intptr_t end_token_pos() const { return end_token_pos_; }
229 void set_end_token_index(intptr_t value) { end_token_index_ = value; } 229 void set_end_token_pos(intptr_t value) { end_token_pos_ = value; }
230 230
231 // The number of variables allocated in the context and belonging to this 231 // The number of variables allocated in the context and belonging to this
232 // scope and to its children at the same loop level. 232 // scope and to its children at the same loop level.
233 int num_context_variables() const { return num_context_variables_; } 233 int num_context_variables() const { return num_context_variables_; }
234 234
235 // Add a variable to the scope. Returns false if a variable with the 235 // Add a variable to the scope. Returns false if a variable with the
236 // same name is already present. 236 // same name is already present.
237 bool AddVariable(LocalVariable* variable); 237 bool AddVariable(LocalVariable* variable);
238 238
239 // Add a label to the scope. Returns false if a label with the same name 239 // Add a label to the scope. Returns false if a label with the same name
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 void CollectLocalVariables(GrowableArray<VarDesc>* vars, int16_t* scope_id); 333 void CollectLocalVariables(GrowableArray<VarDesc>* vars, int16_t* scope_id);
334 334
335 static const int kUnitializedContextLevel = INT_MIN; 335 static const int kUnitializedContextLevel = INT_MIN;
336 LocalScope* parent_; 336 LocalScope* parent_;
337 LocalScope* child_; 337 LocalScope* child_;
338 LocalScope* sibling_; 338 LocalScope* sibling_;
339 int function_level_; // Reflects the nesting level of local functions. 339 int function_level_; // Reflects the nesting level of local functions.
340 int loop_level_; // Reflects the loop nesting level. 340 int loop_level_; // Reflects the loop nesting level.
341 int context_level_; // Reflects the level of the runtime context. 341 int context_level_; // Reflects the level of the runtime context.
342 int num_context_variables_; // Only set if this scope is a context owner. 342 int num_context_variables_; // Only set if this scope is a context owner.
343 intptr_t begin_token_index_; // Token index of beginning of scope. 343 intptr_t begin_token_pos_; // Token index of beginning of scope.
344 intptr_t end_token_index_; // Token index of end of scope. 344 intptr_t end_token_pos_; // Token index of end of scope.
345 GrowableArray<LocalVariable*> variables_; 345 GrowableArray<LocalVariable*> variables_;
346 GrowableArray<SourceLabel*> labels_; 346 GrowableArray<SourceLabel*> labels_;
347 347
348 DISALLOW_COPY_AND_ASSIGN(LocalScope); 348 DISALLOW_COPY_AND_ASSIGN(LocalScope);
349 }; 349 };
350 350
351 } // namespace dart 351 } // namespace dart
352 352
353 #endif // VM_SCOPES_H_ 353 #endif // VM_SCOPES_H_
OLDNEW
« no previous file with comments | « vm/raw_object_snapshot.cc ('k') | vm/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698