Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 int context_level() const { | 172 int context_level() const { |
| 173 ASSERT(HasContextLevel()); | 173 ASSERT(HasContextLevel()); |
| 174 return context_level_; | 174 return context_level_; |
| 175 } | 175 } |
| 176 void set_context_level(int context_level) { | 176 void set_context_level(int context_level) { |
| 177 ASSERT(!HasContextLevel()); | 177 ASSERT(!HasContextLevel()); |
| 178 ASSERT(context_level != kUnitializedContextLevel_); | 178 ASSERT(context_level != kUnitializedContextLevel_); |
| 179 context_level_ = context_level; | 179 context_level_ = context_level; |
| 180 } | 180 } |
| 181 | 181 |
| 182 intptr_t end_token_index() const { return end_token_index_; } | |
| 183 void set_end_token_index(intptr_t value) { end_token_index_ = value; } | |
| 184 | |
| 182 // The number of variables allocated in the context and belonging to this | 185 // The number of variables allocated in the context and belonging to this |
| 183 // scope and to its children at the same loop level. | 186 // scope and to its children at the same loop level. |
| 184 int num_context_variables() const { return num_context_variables_; } | 187 int num_context_variables() const { return num_context_variables_; } |
| 185 | 188 |
| 186 // Add a variable to the scope. Returns false if a variable with the | 189 // Add a variable to the scope. Returns false if a variable with the |
| 187 // same name is already present. | 190 // same name is already present. |
| 188 bool AddVariable(LocalVariable* variable); | 191 bool AddVariable(LocalVariable* variable); |
| 189 | 192 |
| 190 // Add a label to the scope. Returns false if a label with the same name | 193 // Add a label to the scope. Returns false if a label with the same name |
| 191 // is already present. | 194 // is already present. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 // and not in its children (we do not yet handle register parameters). | 245 // and not in its children (we do not yet handle register parameters). |
| 243 // Locals must be listed after parameters in top scope and in its children. | 246 // Locals must be listed after parameters in top scope and in its children. |
| 244 // Two locals in different sibling scopes may share the same frame slot. | 247 // Two locals in different sibling scopes may share the same frame slot. |
| 245 // Return the index of the next available frame slot. | 248 // Return the index of the next available frame slot. |
| 246 int AllocateVariables(int first_parameter_index, | 249 int AllocateVariables(int first_parameter_index, |
| 247 int num_parameters, | 250 int num_parameters, |
| 248 int first_frame_index, | 251 int first_frame_index, |
| 249 LocalScope* loop_owner, | 252 LocalScope* loop_owner, |
| 250 LocalScope** context_owner); | 253 LocalScope** context_owner); |
| 251 | 254 |
| 255 // Creates variable info for the scope and all its nested scopes. | |
| 256 // Must be called after AllocateVariables() has been called. | |
| 257 RawLocalVarDescriptors* GetVarDescriptors(); | |
| 258 | |
| 252 // Create a ContextScope object describing all captured variables referenced | 259 // Create a ContextScope object describing all captured variables referenced |
| 253 // from this scope and belonging to outer scopes. | 260 // from this scope and belonging to outer scopes. |
| 254 RawContextScope* PreserveOuterScope(int current_context_level) const; | 261 RawContextScope* PreserveOuterScope(int current_context_level) const; |
| 255 | 262 |
| 256 // Creates a LocalScope representing the outer scope of a local function to be | 263 // Creates a LocalScope representing the outer scope of a local function to be |
| 257 // compiled. This outer scope contains the variables captured by the function | 264 // compiled. This outer scope contains the variables captured by the function |
| 258 // as specified by the given ContextScope, which was created during the | 265 // as specified by the given ContextScope, which was created during the |
| 259 // compilation of the enclosing function. | 266 // compilation of the enclosing function. |
| 260 static LocalScope* RestoreOuterScope(const ContextScope& context_scope); | 267 static LocalScope* RestoreOuterScope(const ContextScope& context_scope); |
| 261 | 268 |
| 262 // Create a ContextScope object which will capture "this" for an implicit | 269 // Create a ContextScope object which will capture "this" for an implicit |
| 263 // closure object. | 270 // closure object. |
| 264 static RawContextScope* CreateImplicitClosureScope(const Function& func); | 271 static RawContextScope* CreateImplicitClosureScope(const Function& func); |
| 265 | 272 |
| 266 private: | 273 private: |
| 267 // Allocate the variable in the current context, possibly updating the current | 274 // Allocate the variable in the current context, possibly updating the current |
| 268 // context owner scope, if the variable is the first one to be allocated at | 275 // context owner scope, if the variable is the first one to be allocated at |
| 269 // this loop level. | 276 // this loop level. |
| 270 // The variable may belong to this scope or to any of its children, but at the | 277 // The variable may belong to this scope or to any of its children, but at the |
| 271 // same loop level. | 278 // same loop level. |
| 272 void AllocateContextVariable(LocalVariable* variable, | 279 void AllocateContextVariable(LocalVariable* variable, |
| 273 LocalScope** context_owner); | 280 LocalScope** context_owner); |
| 274 | 281 |
| 282 void CollectLocalVariables(GrowableArray<LocalVariable*>* vars); | |
| 283 | |
| 275 static const int kUnitializedContextLevel_ = INT_MIN; | 284 static const int kUnitializedContextLevel_ = INT_MIN; |
| 276 LocalScope* parent_; | 285 LocalScope* parent_; |
| 277 LocalScope* child_; | 286 LocalScope* child_; |
| 278 LocalScope* sibling_; | 287 LocalScope* sibling_; |
| 279 int function_level_; // Reflects the nesting level of local functions. | 288 int function_level_; // Reflects the nesting level of local functions. |
| 280 int loop_level_; // Reflects the loop nesting level. | 289 int loop_level_; // Reflects the loop nesting level. |
| 281 int context_level_; // Reflects the level of the runtime context. | 290 int context_level_; // Reflects the level of the runtime context. |
| 282 int num_context_variables_; // Only set if this scope is a context owner. | 291 int num_context_variables_; // Only set if this scope is a context owner. |
| 292 intptr_t end_token_index_; // Token index of end of scope. | |
|
srdjan
2011/12/20 22:07:04
Inclusive or exclusive?
hausner
2011/12/20 22:13:29
Inclusive, but it depends on what the parser assig
| |
| 283 GrowableArray<LocalVariable*> variables_; | 293 GrowableArray<LocalVariable*> variables_; |
| 284 GrowableArray<SourceLabel*> labels_; | 294 GrowableArray<SourceLabel*> labels_; |
| 285 | 295 |
| 286 DISALLOW_COPY_AND_ASSIGN(LocalScope); | 296 DISALLOW_COPY_AND_ASSIGN(LocalScope); |
| 287 }; | 297 }; |
| 288 | 298 |
| 289 } // namespace dart | 299 } // namespace dart |
| 290 | 300 |
| 291 #endif // VM_SCOPES_H_ | 301 #endif // VM_SCOPES_H_ |
| OLD | NEW |