| OLD | NEW |
| 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 #include "vm/scopes.h" | 5 #include "vm/scopes.h" |
| 6 | 6 |
| 7 #include "vm/object.h" | 7 #include "vm/object.h" |
| 8 #include "vm/stack_frame.h" | 8 #include "vm/stack_frame.h" |
| 9 #include "vm/symbols.h" | 9 #include "vm/symbols.h" |
| 10 | 10 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 RawLocalVarDescriptors* LocalScope::GetVarDescriptors(const Function& func) { | 246 RawLocalVarDescriptors* LocalScope::GetVarDescriptors(const Function& func) { |
| 247 GrowableArray<VarDesc> vars(8); | 247 GrowableArray<VarDesc> vars(8); |
| 248 // First enter all variables from scopes of outer functions. | 248 // First enter all variables from scopes of outer functions. |
| 249 const ContextScope& context_scope = | 249 const ContextScope& context_scope = |
| 250 ContextScope::Handle(func.context_scope()); | 250 ContextScope::Handle(func.context_scope()); |
| 251 if (!context_scope.IsNull()) { | 251 if (!context_scope.IsNull()) { |
| 252 ASSERT(func.IsLocalFunction()); | 252 ASSERT(func.IsLocalFunction()); |
| 253 for (int i = 0; i < context_scope.num_variables(); i++) { | 253 for (int i = 0; i < context_scope.num_variables(); i++) { |
| 254 VarDesc desc; | 254 VarDesc desc; |
| 255 desc.name = &String::Handle(context_scope.NameAt(i)); | 255 desc.name = &String::Handle(context_scope.NameAt(i)); |
| 256 desc.info.kind = RawLocalVarDescriptors::kContextVar; | 256 desc.info.set_kind(RawLocalVarDescriptors::kContextVar); |
| 257 desc.info.scope_id = context_scope.ContextLevelAt(i); | 257 desc.info.scope_id = context_scope.ContextLevelAt(i); |
| 258 desc.info.begin_pos = begin_token_pos(); | 258 desc.info.begin_pos = begin_token_pos(); |
| 259 desc.info.end_pos = end_token_pos(); | 259 desc.info.end_pos = end_token_pos(); |
| 260 ASSERT(desc.info.begin_pos <= desc.info.end_pos); | 260 ASSERT(desc.info.begin_pos <= desc.info.end_pos); |
| 261 desc.info.index = context_scope.ContextIndexAt(i); | 261 desc.info.set_index(context_scope.ContextIndexAt(i)); |
| 262 vars.Add(desc); | 262 vars.Add(desc); |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 // Now collect all variables from local scopes. | 265 // Now collect all variables from local scopes. |
| 266 int16_t scope_id = 0; | 266 int16_t scope_id = 0; |
| 267 CollectLocalVariables(&vars, &scope_id); | 267 CollectLocalVariables(&vars, &scope_id); |
| 268 | 268 |
| 269 const LocalVarDescriptors& var_desc = | 269 const LocalVarDescriptors& var_desc = |
| 270 LocalVarDescriptors::Handle(LocalVarDescriptors::New(vars.length())); | 270 LocalVarDescriptors::Handle(LocalVarDescriptors::New(vars.length())); |
| 271 for (int i = 0; i < vars.length(); i++) { | 271 for (int i = 0; i < vars.length(); i++) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 288 int16_t* scope_id) { | 288 int16_t* scope_id) { |
| 289 (*scope_id)++; | 289 (*scope_id)++; |
| 290 if (HasContextLevel() && | 290 if (HasContextLevel() && |
| 291 ((parent() == NULL) || | 291 ((parent() == NULL) || |
| 292 (!parent()->HasContextLevel()) || | 292 (!parent()->HasContextLevel()) || |
| 293 (parent()->context_level() != context_level()))) { | 293 (parent()->context_level() != context_level()))) { |
| 294 // This is the outermost scope with a context level or this scope's | 294 // This is the outermost scope with a context level or this scope's |
| 295 // context level differs from its parent's level. | 295 // context level differs from its parent's level. |
| 296 VarDesc desc; | 296 VarDesc desc; |
| 297 desc.name = &String::Handle(); // No name. | 297 desc.name = &String::Handle(); // No name. |
| 298 desc.info.kind = RawLocalVarDescriptors::kContextLevel; | 298 desc.info.set_kind(RawLocalVarDescriptors::kContextLevel); |
| 299 desc.info.scope_id = *scope_id; | 299 desc.info.scope_id = *scope_id; |
| 300 desc.info.begin_pos = begin_token_pos(); | 300 desc.info.begin_pos = begin_token_pos(); |
| 301 desc.info.end_pos = end_token_pos(); | 301 desc.info.end_pos = end_token_pos(); |
| 302 desc.info.index = context_level(); | 302 desc.info.set_index(context_level()); |
| 303 vars->Add(desc); | 303 vars->Add(desc); |
| 304 } | 304 } |
| 305 for (int i = 0; i < this->variables_.length(); i++) { | 305 for (int i = 0; i < this->variables_.length(); i++) { |
| 306 LocalVariable* var = variables_[i]; | 306 LocalVariable* var = variables_[i]; |
| 307 if ((var->owner() == this) && !var->is_invisible()) { | 307 if ((var->owner() == this) && !var->is_invisible()) { |
| 308 if (!IsInternalIdentifier(var->name())) { | 308 if (!IsInternalIdentifier(var->name())) { |
| 309 // This is a regular Dart variable, either stack-based or captured. | 309 // This is a regular Dart variable, either stack-based or captured. |
| 310 VarDesc desc; | 310 VarDesc desc; |
| 311 desc.name = &var->name(); | 311 desc.name = &var->name(); |
| 312 if (var->is_captured()) { | 312 if (var->is_captured()) { |
| 313 desc.info.kind = RawLocalVarDescriptors::kContextVar; | 313 desc.info.set_kind(RawLocalVarDescriptors::kContextVar); |
| 314 ASSERT(var->owner() != NULL); | 314 ASSERT(var->owner() != NULL); |
| 315 ASSERT(var->owner()->context_level() >= 0); | 315 ASSERT(var->owner()->context_level() >= 0); |
| 316 desc.info.scope_id = var->owner()->context_level(); | 316 desc.info.scope_id = var->owner()->context_level(); |
| 317 } else { | 317 } else { |
| 318 desc.info.kind = RawLocalVarDescriptors::kStackVar; | 318 desc.info.set_kind(RawLocalVarDescriptors::kStackVar); |
| 319 desc.info.scope_id = *scope_id; | 319 desc.info.scope_id = *scope_id; |
| 320 } | 320 } |
| 321 desc.info.begin_pos = var->token_pos(); | 321 desc.info.begin_pos = var->token_pos(); |
| 322 desc.info.end_pos = var->owner()->end_token_pos(); | 322 desc.info.end_pos = var->owner()->end_token_pos(); |
| 323 desc.info.index = var->index(); | 323 desc.info.set_index(var->index()); |
| 324 vars->Add(desc); | 324 vars->Add(desc); |
| 325 } else if (var->name().raw() == Symbols::SavedEntryContextVar().raw()) { | 325 } else if (var->name().raw() == Symbols::SavedEntryContextVar().raw()) { |
| 326 // This is the local variable in which the function saves the | 326 // This is the local variable in which the function saves the |
| 327 // caller's chain of closure contexts (caller's CTX register). | 327 // caller's chain of closure contexts (caller's CTX register). |
| 328 VarDesc desc; | 328 VarDesc desc; |
| 329 desc.name = &var->name(); | 329 desc.name = &var->name(); |
| 330 desc.info.kind = RawLocalVarDescriptors::kSavedEntryContext; | 330 desc.info.set_kind(RawLocalVarDescriptors::kSavedEntryContext); |
| 331 desc.info.scope_id = 0; | 331 desc.info.scope_id = 0; |
| 332 desc.info.begin_pos = 0; | 332 desc.info.begin_pos = 0; |
| 333 desc.info.end_pos = 0; | 333 desc.info.end_pos = 0; |
| 334 desc.info.index = var->index(); | 334 desc.info.set_index(var->index()); |
| 335 vars->Add(desc); | 335 vars->Add(desc); |
| 336 } else if (var->name().raw() == Symbols::SavedCurrentContextVar().raw()) { | 336 } else if (var->name().raw() == Symbols::SavedCurrentContextVar().raw()) { |
| 337 // This is the local variable in which the function saves its | 337 // This is the local variable in which the function saves its |
| 338 // own context before calling a closure function. | 338 // own context before calling a closure function. |
| 339 VarDesc desc; | 339 VarDesc desc; |
| 340 desc.name = &var->name(); | 340 desc.name = &var->name(); |
| 341 desc.info.kind = RawLocalVarDescriptors::kSavedCurrentContext; | 341 desc.info.set_kind(RawLocalVarDescriptors::kSavedCurrentContext); |
| 342 desc.info.scope_id = 0; | 342 desc.info.scope_id = 0; |
| 343 desc.info.begin_pos = 0; | 343 desc.info.begin_pos = 0; |
| 344 desc.info.end_pos = 0; | 344 desc.info.end_pos = 0; |
| 345 desc.info.index = var->index(); | 345 desc.info.set_index(var->index()); |
| 346 vars->Add(desc); | 346 vars->Add(desc); |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 } | 349 } |
| 350 LocalScope* child = this->child(); | 350 LocalScope* child = this->child(); |
| 351 while (child != NULL) { | 351 while (child != NULL) { |
| 352 child->CollectLocalVariables(vars, scope_id); | 352 child->CollectLocalVariables(vars, scope_id); |
| 353 child = child->sibling(); | 353 child = child->sibling(); |
| 354 } | 354 } |
| 355 } | 355 } |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 return fixed_parameter_count - (index() - kParamEndSlotFromFp); | 669 return fixed_parameter_count - (index() - kParamEndSlotFromFp); |
| 670 } else { | 670 } else { |
| 671 // Shift negative indexes so that the lowest one is 0 (they are still | 671 // Shift negative indexes so that the lowest one is 0 (they are still |
| 672 // non-positive). | 672 // non-positive). |
| 673 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); | 673 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); |
| 674 } | 674 } |
| 675 } | 675 } |
| 676 | 676 |
| 677 | 677 |
| 678 } // namespace dart | 678 } // namespace dart |
| OLD | NEW |