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.index_kind = RawLocalVarDescriptors::KindBits::update( |
| 257 RawLocalVarDescriptors::kContextVar, desc.info.index_kind); |
257 desc.info.scope_id = context_scope.ContextLevelAt(i); | 258 desc.info.scope_id = context_scope.ContextLevelAt(i); |
258 desc.info.begin_pos = begin_token_pos(); | 259 desc.info.begin_pos = begin_token_pos(); |
259 desc.info.end_pos = end_token_pos(); | 260 desc.info.end_pos = end_token_pos(); |
260 ASSERT(desc.info.begin_pos <= desc.info.end_pos); | 261 ASSERT(desc.info.begin_pos <= desc.info.end_pos); |
261 desc.info.index = context_scope.ContextIndexAt(i); | 262 desc.info.index_kind = RawLocalVarDescriptors::IndexBits::update( |
| 263 context_scope.ContextIndexAt(i), desc.info.index_kind); |
262 vars.Add(desc); | 264 vars.Add(desc); |
263 } | 265 } |
264 } | 266 } |
265 // Now collect all variables from local scopes. | 267 // Now collect all variables from local scopes. |
266 int16_t scope_id = 0; | 268 int16_t scope_id = 0; |
267 CollectLocalVariables(&vars, &scope_id); | 269 CollectLocalVariables(&vars, &scope_id); |
268 | 270 |
269 const LocalVarDescriptors& var_desc = | 271 const LocalVarDescriptors& var_desc = |
270 LocalVarDescriptors::Handle(LocalVarDescriptors::New(vars.length())); | 272 LocalVarDescriptors::Handle(LocalVarDescriptors::New(vars.length())); |
271 for (int i = 0; i < vars.length(); i++) { | 273 for (int i = 0; i < vars.length(); i++) { |
(...skipping 16 matching lines...) Expand all Loading... |
288 int16_t* scope_id) { | 290 int16_t* scope_id) { |
289 (*scope_id)++; | 291 (*scope_id)++; |
290 if (HasContextLevel() && | 292 if (HasContextLevel() && |
291 ((parent() == NULL) || | 293 ((parent() == NULL) || |
292 (!parent()->HasContextLevel()) || | 294 (!parent()->HasContextLevel()) || |
293 (parent()->context_level() != context_level()))) { | 295 (parent()->context_level() != context_level()))) { |
294 // This is the outermost scope with a context level or this scope's | 296 // This is the outermost scope with a context level or this scope's |
295 // context level differs from its parent's level. | 297 // context level differs from its parent's level. |
296 VarDesc desc; | 298 VarDesc desc; |
297 desc.name = &String::Handle(); // No name. | 299 desc.name = &String::Handle(); // No name. |
298 desc.info.kind = RawLocalVarDescriptors::kContextLevel; | 300 desc.info.index_kind = RawLocalVarDescriptors::KindBits::update( |
| 301 RawLocalVarDescriptors::kContextLevel, desc.info.index_kind); |
299 desc.info.scope_id = *scope_id; | 302 desc.info.scope_id = *scope_id; |
300 desc.info.begin_pos = begin_token_pos(); | 303 desc.info.begin_pos = begin_token_pos(); |
301 desc.info.end_pos = end_token_pos(); | 304 desc.info.end_pos = end_token_pos(); |
302 desc.info.index = context_level(); | 305 desc.info.index_kind = RawLocalVarDescriptors::IndexBits::update( |
| 306 context_level(), desc.info.index_kind); |
303 vars->Add(desc); | 307 vars->Add(desc); |
304 } | 308 } |
305 for (int i = 0; i < this->variables_.length(); i++) { | 309 for (int i = 0; i < this->variables_.length(); i++) { |
306 LocalVariable* var = variables_[i]; | 310 LocalVariable* var = variables_[i]; |
307 if ((var->owner() == this) && !var->is_invisible()) { | 311 if ((var->owner() == this) && !var->is_invisible()) { |
308 if (!IsInternalIdentifier(var->name())) { | 312 if (!IsInternalIdentifier(var->name())) { |
309 // This is a regular Dart variable, either stack-based or captured. | 313 // This is a regular Dart variable, either stack-based or captured. |
310 VarDesc desc; | 314 VarDesc desc; |
311 desc.name = &var->name(); | 315 desc.name = &var->name(); |
312 if (var->is_captured()) { | 316 if (var->is_captured()) { |
313 desc.info.kind = RawLocalVarDescriptors::kContextVar; | 317 desc.info.index_kind = RawLocalVarDescriptors::KindBits::update( |
| 318 RawLocalVarDescriptors::kContextVar, desc.info.index_kind); |
314 ASSERT(var->owner() != NULL); | 319 ASSERT(var->owner() != NULL); |
315 ASSERT(var->owner()->context_level() >= 0); | 320 ASSERT(var->owner()->context_level() >= 0); |
316 desc.info.scope_id = var->owner()->context_level(); | 321 desc.info.scope_id = var->owner()->context_level(); |
317 } else { | 322 } else { |
318 desc.info.kind = RawLocalVarDescriptors::kStackVar; | 323 desc.info.index_kind = RawLocalVarDescriptors::KindBits::update( |
| 324 RawLocalVarDescriptors::kStackVar, desc.info.index_kind); |
319 desc.info.scope_id = *scope_id; | 325 desc.info.scope_id = *scope_id; |
320 } | 326 } |
321 desc.info.begin_pos = var->token_pos(); | 327 desc.info.begin_pos = var->token_pos(); |
322 desc.info.end_pos = var->owner()->end_token_pos(); | 328 desc.info.end_pos = var->owner()->end_token_pos(); |
323 desc.info.index = var->index(); | 329 desc.info.index_kind = RawLocalVarDescriptors::IndexBits::update( |
| 330 var->index(), desc.info.index_kind); |
324 vars->Add(desc); | 331 vars->Add(desc); |
325 } else if (var->name().raw() == Symbols::SavedEntryContextVar().raw()) { | 332 } else if (var->name().raw() == Symbols::SavedEntryContextVar().raw()) { |
326 // This is the local variable in which the function saves the | 333 // This is the local variable in which the function saves the |
327 // caller's chain of closure contexts (caller's CTX register). | 334 // caller's chain of closure contexts (caller's CTX register). |
328 VarDesc desc; | 335 VarDesc desc; |
329 desc.name = &var->name(); | 336 desc.name = &var->name(); |
330 desc.info.kind = RawLocalVarDescriptors::kSavedEntryContext; | 337 desc.info.index_kind = RawLocalVarDescriptors::KindBits::update( |
| 338 RawLocalVarDescriptors::kSavedEntryContext, desc.info.index_kind); |
331 desc.info.scope_id = 0; | 339 desc.info.scope_id = 0; |
332 desc.info.begin_pos = 0; | 340 desc.info.begin_pos = 0; |
333 desc.info.end_pos = 0; | 341 desc.info.end_pos = 0; |
334 desc.info.index = var->index(); | 342 desc.info.index_kind = RawLocalVarDescriptors::IndexBits::update( |
| 343 var->index(), desc.info.index_kind); |
335 vars->Add(desc); | 344 vars->Add(desc); |
336 } else if (var->name().raw() == Symbols::SavedCurrentContextVar().raw()) { | 345 } else if (var->name().raw() == Symbols::SavedCurrentContextVar().raw()) { |
337 // This is the local variable in which the function saves its | 346 // This is the local variable in which the function saves its |
338 // own context before calling a closure function. | 347 // own context before calling a closure function. |
339 VarDesc desc; | 348 VarDesc desc; |
340 desc.name = &var->name(); | 349 desc.name = &var->name(); |
341 desc.info.kind = RawLocalVarDescriptors::kSavedCurrentContext; | 350 desc.info.index_kind = RawLocalVarDescriptors::KindBits::update( |
| 351 RawLocalVarDescriptors::kSavedCurrentContext, desc.info.index_kind); |
342 desc.info.scope_id = 0; | 352 desc.info.scope_id = 0; |
343 desc.info.begin_pos = 0; | 353 desc.info.begin_pos = 0; |
344 desc.info.end_pos = 0; | 354 desc.info.end_pos = 0; |
345 desc.info.index = var->index(); | 355 desc.info.index_kind = RawLocalVarDescriptors::IndexBits::update( |
| 356 var->index(), desc.info.index_kind); |
346 vars->Add(desc); | 357 vars->Add(desc); |
347 } | 358 } |
348 } | 359 } |
349 } | 360 } |
350 LocalScope* child = this->child(); | 361 LocalScope* child = this->child(); |
351 while (child != NULL) { | 362 while (child != NULL) { |
352 child->CollectLocalVariables(vars, scope_id); | 363 child->CollectLocalVariables(vars, scope_id); |
353 child = child->sibling(); | 364 child = child->sibling(); |
354 } | 365 } |
355 } | 366 } |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 return fixed_parameter_count - (index() - kParamEndSlotFromFp); | 659 return fixed_parameter_count - (index() - kParamEndSlotFromFp); |
649 } else { | 660 } else { |
650 // Shift negative indexes so that the lowest one is 0 (they are still | 661 // Shift negative indexes so that the lowest one is 0 (they are still |
651 // non-positive). | 662 // non-positive). |
652 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); | 663 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); |
653 } | 664 } |
654 } | 665 } |
655 | 666 |
656 | 667 |
657 } // namespace dart | 668 } // namespace dart |
OLD | NEW |