| 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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 return false; | 277 return false; |
| 278 } | 278 } |
| 279 if (str.raw() == Symbols::AsyncStackTraceVar().raw()) { | 279 if (str.raw() == Symbols::AsyncStackTraceVar().raw()) { |
| 280 // Keep :async_stack_trace for asynchronous debugging. | 280 // Keep :async_stack_trace for asynchronous debugging. |
| 281 return false; | 281 return false; |
| 282 } | 282 } |
| 283 return str.CharAt(0) == ':'; | 283 return str.CharAt(0) == ':'; |
| 284 } | 284 } |
| 285 | 285 |
| 286 | 286 |
| 287 RawLocalVarDescriptors* LocalScope::GetVarDescriptors(const Function& func) { | 287 RawLocalVarDescriptors* LocalScope::GetVarDescriptors( |
| 288 const Function& func, |
| 289 ZoneGrowableArray<intptr_t>* context_level_array) { |
| 288 GrowableArray<VarDesc> vars(8); | 290 GrowableArray<VarDesc> vars(8); |
| 291 |
| 292 // Record deopt-id -> context-level mappings, using ranges of deopt-ids with |
| 293 // the same context-level. [context_level_array] contains (deopt_id, |
| 294 // context_level) tuples. |
| 295 for (intptr_t start = 0; start < context_level_array->length();) { |
| 296 intptr_t start_deopt_id = (*context_level_array)[start]; |
| 297 intptr_t start_context_level = (*context_level_array)[start + 1]; |
| 298 intptr_t end = start; |
| 299 intptr_t end_deopt_id = start_deopt_id; |
| 300 for (intptr_t peek = start + 2; peek < context_level_array->length(); |
| 301 peek += 2) { |
| 302 intptr_t peek_deopt_id = (*context_level_array)[peek]; |
| 303 intptr_t peek_context_level = (*context_level_array)[peek + 1]; |
| 304 // The range encoding assumes the tuples have ascending deopt_ids. |
| 305 ASSERT(peek_deopt_id > end_deopt_id); |
| 306 if (peek_context_level != start_context_level) break; |
| 307 end = peek; |
| 308 end_deopt_id = peek_deopt_id; |
| 309 } |
| 310 |
| 311 VarDesc desc; |
| 312 desc.name = &Symbols::Empty(); // No name. |
| 313 desc.info.set_kind(RawLocalVarDescriptors::kContextLevel); |
| 314 desc.info.scope_id = 0; |
| 315 desc.info.begin_pos = TokenPosition(start_deopt_id); |
| 316 desc.info.end_pos = TokenPosition(end_deopt_id); |
| 317 desc.info.set_index(start_context_level); |
| 318 vars.Add(desc); |
| 319 |
| 320 start = end + 2; |
| 321 } |
| 322 |
| 289 // First enter all variables from scopes of outer functions. | 323 // First enter all variables from scopes of outer functions. |
| 290 const ContextScope& context_scope = | 324 const ContextScope& context_scope = |
| 291 ContextScope::Handle(func.context_scope()); | 325 ContextScope::Handle(func.context_scope()); |
| 292 if (!context_scope.IsNull()) { | 326 if (!context_scope.IsNull()) { |
| 293 ASSERT(func.IsLocalFunction()); | 327 ASSERT(func.IsLocalFunction()); |
| 294 for (int i = 0; i < context_scope.num_variables(); i++) { | 328 for (int i = 0; i < context_scope.num_variables(); i++) { |
| 295 String& name = String::Handle(context_scope.NameAt(i)); | 329 String& name = String::Handle(context_scope.NameAt(i)); |
| 296 RawLocalVarDescriptors::VarInfoKind kind; | 330 RawLocalVarDescriptors::VarInfoKind kind; |
| 297 if (!IsFilteredIdentifier(name)) { | 331 if (!IsFilteredIdentifier(name)) { |
| 298 kind = RawLocalVarDescriptors::kContextVar; | 332 kind = RawLocalVarDescriptors::kContextVar; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 326 } | 360 } |
| 327 return var_desc.raw(); | 361 return var_desc.raw(); |
| 328 } | 362 } |
| 329 | 363 |
| 330 | 364 |
| 331 // Add visible variables that are declared in this scope to vars, then | 365 // Add visible variables that are declared in this scope to vars, then |
| 332 // collect visible variables of children, followed by siblings. | 366 // collect visible variables of children, followed by siblings. |
| 333 void LocalScope::CollectLocalVariables(GrowableArray<VarDesc>* vars, | 367 void LocalScope::CollectLocalVariables(GrowableArray<VarDesc>* vars, |
| 334 int16_t* scope_id) { | 368 int16_t* scope_id) { |
| 335 (*scope_id)++; | 369 (*scope_id)++; |
| 336 if (num_context_variables() > 0) { | |
| 337 VarDesc desc; | |
| 338 desc.name = &Symbols::Empty(); // No name. | |
| 339 desc.info.set_kind(RawLocalVarDescriptors::kContextLevel); | |
| 340 desc.info.scope_id = *scope_id; | |
| 341 desc.info.begin_pos = begin_token_pos(); | |
| 342 desc.info.end_pos = end_token_pos(); | |
| 343 desc.info.set_index(context_level()); | |
| 344 vars->Add(desc); | |
| 345 } | |
| 346 for (int i = 0; i < this->variables_.length(); i++) { | 370 for (int i = 0; i < this->variables_.length(); i++) { |
| 347 LocalVariable* var = variables_[i]; | 371 LocalVariable* var = variables_[i]; |
| 348 if ((var->owner() == this) && !var->is_invisible()) { | 372 if ((var->owner() == this) && !var->is_invisible()) { |
| 349 if (var->name().raw() == Symbols::CurrentContextVar().raw()) { | 373 if (var->name().raw() == Symbols::CurrentContextVar().raw()) { |
| 350 // This is the local variable in which the function saves its | 374 // This is the local variable in which the function saves its |
| 351 // own context before calling a closure function. | 375 // own context before calling a closure function. |
| 352 VarDesc desc; | 376 VarDesc desc; |
| 353 desc.name = &var->name(); | 377 desc.name = &var->name(); |
| 354 desc.info.set_kind(RawLocalVarDescriptors::kSavedCurrentContext); | 378 desc.info.set_kind(RawLocalVarDescriptors::kSavedCurrentContext); |
| 355 desc.info.scope_id = 0; | 379 desc.info.scope_id = 0; |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 return fixed_parameter_count - (index() - kParamEndSlotFromFp); | 726 return fixed_parameter_count - (index() - kParamEndSlotFromFp); |
| 703 } else { | 727 } else { |
| 704 // Shift negative indexes so that the lowest one is 0 (they are still | 728 // Shift negative indexes so that the lowest one is 0 (they are still |
| 705 // non-positive). | 729 // non-positive). |
| 706 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); | 730 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); |
| 707 } | 731 } |
| 708 } | 732 } |
| 709 | 733 |
| 710 | 734 |
| 711 } // namespace dart | 735 } // namespace dart |
| OLD | NEW |