Chromium Code Reviews| 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. | |
| 294 for (intptr_t start = 0; start < context_level_array->length();) { | |
|
Vyacheslav Egorov (Google)
2017/05/31 14:29:51
Maybe context_level_array tuples need to be sorted
rmacnak
2017/05/31 18:03:17
We don't depend on the order the AST is processed
Vyacheslav Egorov (Google)
2017/06/01 12:32:41
Yeah, I am not sure what I was thinking. GetNextDe
| |
| 295 intptr_t start_deopt_id = (*context_level_array)[start]; | |
| 296 intptr_t start_context_level = (*context_level_array)[start + 1]; | |
| 297 intptr_t end = start; | |
| 298 intptr_t end_deopt_id = start_deopt_id; | |
| 299 for (intptr_t peek = start + 2; peek < context_level_array->length(); | |
| 300 peek += 2) { | |
| 301 intptr_t peek_deopt_id = (*context_level_array)[peek]; | |
| 302 intptr_t peek_context_level = (*context_level_array)[peek + 1]; | |
| 303 ASSERT(peek_deopt_id > end_deopt_id); | |
| 304 if (peek_context_level != start_context_level) break; | |
| 305 end = peek; | |
| 306 end_deopt_id = peek_deopt_id; | |
| 307 } | |
| 308 | |
| 309 VarDesc desc; | |
| 310 desc.name = &Symbols::Empty(); // No name. | |
| 311 desc.info.set_kind(RawLocalVarDescriptors::kContextLevel); | |
| 312 desc.info.scope_id = 0; | |
| 313 desc.info.begin_pos = TokenPosition(start_deopt_id); | |
| 314 desc.info.end_pos = TokenPosition(end_deopt_id); | |
| 315 desc.info.set_index(start_context_level); | |
| 316 vars.Add(desc); | |
| 317 | |
| 318 start = end + 2; | |
| 319 } | |
| 320 | |
| 289 // First enter all variables from scopes of outer functions. | 321 // First enter all variables from scopes of outer functions. |
| 290 const ContextScope& context_scope = | 322 const ContextScope& context_scope = |
| 291 ContextScope::Handle(func.context_scope()); | 323 ContextScope::Handle(func.context_scope()); |
| 292 if (!context_scope.IsNull()) { | 324 if (!context_scope.IsNull()) { |
| 293 ASSERT(func.IsLocalFunction()); | 325 ASSERT(func.IsLocalFunction()); |
| 294 for (int i = 0; i < context_scope.num_variables(); i++) { | 326 for (int i = 0; i < context_scope.num_variables(); i++) { |
| 295 String& name = String::Handle(context_scope.NameAt(i)); | 327 String& name = String::Handle(context_scope.NameAt(i)); |
| 296 RawLocalVarDescriptors::VarInfoKind kind; | 328 RawLocalVarDescriptors::VarInfoKind kind; |
| 297 if (!IsFilteredIdentifier(name)) { | 329 if (!IsFilteredIdentifier(name)) { |
| 298 kind = RawLocalVarDescriptors::kContextVar; | 330 kind = RawLocalVarDescriptors::kContextVar; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 326 } | 358 } |
| 327 return var_desc.raw(); | 359 return var_desc.raw(); |
| 328 } | 360 } |
| 329 | 361 |
| 330 | 362 |
| 331 // Add visible variables that are declared in this scope to vars, then | 363 // Add visible variables that are declared in this scope to vars, then |
| 332 // collect visible variables of children, followed by siblings. | 364 // collect visible variables of children, followed by siblings. |
| 333 void LocalScope::CollectLocalVariables(GrowableArray<VarDesc>* vars, | 365 void LocalScope::CollectLocalVariables(GrowableArray<VarDesc>* vars, |
| 334 int16_t* scope_id) { | 366 int16_t* scope_id) { |
| 335 (*scope_id)++; | 367 (*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++) { | 368 for (int i = 0; i < this->variables_.length(); i++) { |
| 347 LocalVariable* var = variables_[i]; | 369 LocalVariable* var = variables_[i]; |
| 348 if ((var->owner() == this) && !var->is_invisible()) { | 370 if ((var->owner() == this) && !var->is_invisible()) { |
| 349 if (var->name().raw() == Symbols::CurrentContextVar().raw()) { | 371 if (var->name().raw() == Symbols::CurrentContextVar().raw()) { |
| 350 // This is the local variable in which the function saves its | 372 // This is the local variable in which the function saves its |
| 351 // own context before calling a closure function. | 373 // own context before calling a closure function. |
| 352 VarDesc desc; | 374 VarDesc desc; |
| 353 desc.name = &var->name(); | 375 desc.name = &var->name(); |
| 354 desc.info.set_kind(RawLocalVarDescriptors::kSavedCurrentContext); | 376 desc.info.set_kind(RawLocalVarDescriptors::kSavedCurrentContext); |
| 355 desc.info.scope_id = 0; | 377 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); | 724 return fixed_parameter_count - (index() - kParamEndSlotFromFp); |
| 703 } else { | 725 } else { |
| 704 // Shift negative indexes so that the lowest one is 0 (they are still | 726 // Shift negative indexes so that the lowest one is 0 (they are still |
| 705 // non-positive). | 727 // non-positive). |
| 706 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); | 728 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); |
| 707 } | 729 } |
| 708 } | 730 } |
| 709 | 731 |
| 710 | 732 |
| 711 } // namespace dart | 733 } // namespace dart |
| OLD | NEW |