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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 found_captured_variables); | 242 found_captured_variables); |
243 if (child_frame_index < min_frame_index) { | 243 if (child_frame_index < min_frame_index) { |
244 min_frame_index = child_frame_index; | 244 min_frame_index = child_frame_index; |
245 } | 245 } |
246 child = child->sibling(); | 246 child = child->sibling(); |
247 } | 247 } |
248 return min_frame_index; | 248 return min_frame_index; |
249 } | 249 } |
250 | 250 |
251 | 251 |
| 252 // The parser creates internal variables that start with ":" |
| 253 static bool IsInternalIdentifier(const String& str) { |
| 254 ASSERT(str.Length() > 0); |
| 255 return str.CharAt(0) == ':'; |
| 256 } |
| 257 |
| 258 |
252 RawLocalVarDescriptors* LocalScope::GetVarDescriptors(const Function& func) { | 259 RawLocalVarDescriptors* LocalScope::GetVarDescriptors(const Function& func) { |
253 GrowableArray<VarDesc> vars(8); | 260 GrowableArray<VarDesc> vars(8); |
254 // First enter all variables from scopes of outer functions. | 261 // First enter all variables from scopes of outer functions. |
255 const ContextScope& context_scope = | 262 const ContextScope& context_scope = |
256 ContextScope::Handle(func.context_scope()); | 263 ContextScope::Handle(func.context_scope()); |
257 if (!context_scope.IsNull()) { | 264 if (!context_scope.IsNull()) { |
258 ASSERT(func.IsLocalFunction()); | 265 ASSERT(func.IsLocalFunction()); |
259 for (int i = 0; i < context_scope.num_variables(); i++) { | 266 for (int i = 0; i < context_scope.num_variables(); i++) { |
| 267 String& name = String::Handle(context_scope.NameAt(i)); |
| 268 RawLocalVarDescriptors::VarInfoKind kind; |
| 269 if (!IsInternalIdentifier(name)) { |
| 270 kind = RawLocalVarDescriptors::kContextVar; |
| 271 } else if (name.raw() == Symbols::AsyncOperation().raw()) { |
| 272 kind = RawLocalVarDescriptors::kAsyncOperation; |
| 273 } else { |
| 274 continue; |
| 275 } |
| 276 |
260 VarDesc desc; | 277 VarDesc desc; |
261 desc.name = &String::Handle(context_scope.NameAt(i)); | 278 desc.name = &name; |
262 desc.info.set_kind(RawLocalVarDescriptors::kContextVar); | 279 desc.info.set_kind(kind); |
263 desc.info.scope_id = context_scope.ContextLevelAt(i); | 280 desc.info.scope_id = context_scope.ContextLevelAt(i); |
264 desc.info.begin_pos = begin_token_pos(); | 281 desc.info.begin_pos = begin_token_pos(); |
265 desc.info.end_pos = end_token_pos(); | 282 desc.info.end_pos = end_token_pos(); |
266 ASSERT(desc.info.begin_pos <= desc.info.end_pos); | 283 ASSERT(desc.info.begin_pos <= desc.info.end_pos); |
267 desc.info.set_index(context_scope.ContextIndexAt(i)); | 284 desc.info.set_index(context_scope.ContextIndexAt(i)); |
268 vars.Add(desc); | 285 vars.Add(desc); |
269 } | 286 } |
270 } | 287 } |
271 // Now collect all variables from local scopes. | 288 // Now collect all variables from local scopes. |
272 int16_t scope_id = 0; | 289 int16_t scope_id = 0; |
273 CollectLocalVariables(&vars, &scope_id); | 290 CollectLocalVariables(&vars, &scope_id); |
274 | 291 |
275 if (vars.length() == 0) { | 292 if (vars.length() == 0) { |
276 return Object::empty_var_descriptors().raw(); | 293 return Object::empty_var_descriptors().raw(); |
277 } | 294 } |
278 const LocalVarDescriptors& var_desc = | 295 const LocalVarDescriptors& var_desc = |
279 LocalVarDescriptors::Handle(LocalVarDescriptors::New(vars.length())); | 296 LocalVarDescriptors::Handle(LocalVarDescriptors::New(vars.length())); |
280 for (int i = 0; i < vars.length(); i++) { | 297 for (int i = 0; i < vars.length(); i++) { |
281 var_desc.SetVar(i, *(vars[i].name), &vars[i].info); | 298 var_desc.SetVar(i, *(vars[i].name), &vars[i].info); |
282 } | 299 } |
283 return var_desc.raw(); | 300 return var_desc.raw(); |
284 } | 301 } |
285 | 302 |
286 | 303 |
287 // The parser creates internal variables that start with ":" | |
288 static bool IsInternalIdentifier(const String& str) { | |
289 ASSERT(str.Length() > 0); | |
290 return str.CharAt(0) == ':'; | |
291 } | |
292 | |
293 | |
294 // Add visible variables that are declared in this scope to vars, then | 304 // Add visible variables that are declared in this scope to vars, then |
295 // collect visible variables of children, followed by siblings. | 305 // collect visible variables of children, followed by siblings. |
296 void LocalScope::CollectLocalVariables(GrowableArray<VarDesc>* vars, | 306 void LocalScope::CollectLocalVariables(GrowableArray<VarDesc>* vars, |
297 int16_t* scope_id) { | 307 int16_t* scope_id) { |
298 (*scope_id)++; | 308 (*scope_id)++; |
299 if (num_context_variables() > 0) { | 309 if (num_context_variables() > 0) { |
300 VarDesc desc; | 310 VarDesc desc; |
301 desc.name = &Symbols::Empty(); // No name. | 311 desc.name = &Symbols::Empty(); // No name. |
302 desc.info.set_kind(RawLocalVarDescriptors::kContextLevel); | 312 desc.info.set_kind(RawLocalVarDescriptors::kContextLevel); |
303 desc.info.scope_id = *scope_id; | 313 desc.info.scope_id = *scope_id; |
(...skipping 26 matching lines...) Expand all Loading... |
330 // This is the local variable in which the function saves its | 340 // This is the local variable in which the function saves its |
331 // own context before calling a closure function. | 341 // own context before calling a closure function. |
332 VarDesc desc; | 342 VarDesc desc; |
333 desc.name = &var->name(); | 343 desc.name = &var->name(); |
334 desc.info.set_kind(RawLocalVarDescriptors::kSavedCurrentContext); | 344 desc.info.set_kind(RawLocalVarDescriptors::kSavedCurrentContext); |
335 desc.info.scope_id = 0; | 345 desc.info.scope_id = 0; |
336 desc.info.begin_pos = 0; | 346 desc.info.begin_pos = 0; |
337 desc.info.end_pos = 0; | 347 desc.info.end_pos = 0; |
338 desc.info.set_index(var->index()); | 348 desc.info.set_index(var->index()); |
339 vars->Add(desc); | 349 vars->Add(desc); |
| 350 } else if (var->name().raw() == Symbols::AsyncOperation().raw()) { |
| 351 // The async continuation. |
| 352 ASSERT(var->is_captured()); |
| 353 VarDesc desc; |
| 354 desc.name = &var->name(); |
| 355 desc.info.set_kind(RawLocalVarDescriptors::kAsyncOperation); |
| 356 if (var->is_captured()) { |
| 357 ASSERT(var->owner() != NULL); |
| 358 ASSERT(var->owner()->context_level() >= 0); |
| 359 desc.info.scope_id = var->owner()->context_level(); |
| 360 } else { |
| 361 desc.info.scope_id = *scope_id; |
| 362 } |
| 363 desc.info.begin_pos = 0; |
| 364 desc.info.end_pos = 0; |
| 365 desc.info.set_index(var->index()); |
| 366 vars->Add(desc); |
340 } | 367 } |
341 } | 368 } |
342 } | 369 } |
343 LocalScope* child = this->child(); | 370 LocalScope* child = this->child(); |
344 while (child != NULL) { | 371 while (child != NULL) { |
345 child->CollectLocalVariables(vars, scope_id); | 372 child->CollectLocalVariables(vars, scope_id); |
346 child = child->sibling(); | 373 child = child->sibling(); |
347 } | 374 } |
348 } | 375 } |
349 | 376 |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 return fixed_parameter_count - (index() - kParamEndSlotFromFp); | 689 return fixed_parameter_count - (index() - kParamEndSlotFromFp); |
663 } else { | 690 } else { |
664 // Shift negative indexes so that the lowest one is 0 (they are still | 691 // Shift negative indexes so that the lowest one is 0 (they are still |
665 // non-positive). | 692 // non-positive). |
666 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); | 693 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); |
667 } | 694 } |
668 } | 695 } |
669 | 696 |
670 | 697 |
671 } // namespace dart | 698 } // namespace dart |
OLD | NEW |