Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(777)

Side by Side Diff: runtime/vm/scopes.cc

Issue 10915022: Implement argument definition test in the vm. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/ast.h" 7 #include "vm/ast.h"
8 #include "vm/bit_vector.h" 8 #include "vm/bit_vector.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 #include "vm/parser.h" 10 #include "vm/parser.h"
11 #include "vm/symbols.h" 11 #include "vm/symbols.h"
12 12
13 namespace dart { 13 namespace dart {
14 14
15 const char* SourceLabel::kDefaultLabelName = ":L";
16
17 const char* LocalVariable::kSavedContextVarName = ":saved_entry_context_var";
18
19
20 int SourceLabel::FunctionLevel() const { 15 int SourceLabel::FunctionLevel() const {
21 ASSERT(owner() != NULL); 16 ASSERT(owner() != NULL);
22 return owner()->function_level(); 17 return owner()->function_level();
23 } 18 }
24 19
25 20
26 LocalScope::LocalScope(LocalScope* parent, int function_level, int loop_level) 21 LocalScope::LocalScope(LocalScope* parent, int function_level, int loop_level)
27 : parent_(parent), 22 : parent_(parent),
28 child_(NULL), 23 child_(NULL),
29 sibling_(NULL), 24 sibling_(NULL),
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 // Add variables that are declared in this scope to vars, then collect 221 // Add variables that are declared in this scope to vars, then collect
227 // variables of children, followed by siblings. 222 // variables of children, followed by siblings.
228 void LocalScope::CollectLocalVariables(GrowableArray<VarDesc>* vars, 223 void LocalScope::CollectLocalVariables(GrowableArray<VarDesc>* vars,
229 int16_t* scope_id) { 224 int16_t* scope_id) {
230 (*scope_id)++; 225 (*scope_id)++;
231 if (HasContextLevel() && 226 if (HasContextLevel() &&
232 ((parent() == NULL) || 227 ((parent() == NULL) ||
233 (!parent()->HasContextLevel()) || 228 (!parent()->HasContextLevel()) ||
234 (parent()->context_level() != context_level()))) { 229 (parent()->context_level() != context_level()))) {
235 // This is the outermost scope with a context level or this scope's 230 // This is the outermost scope with a context level or this scope's
236 // context level differes from its parent's level. 231 // context level differs from its parent's level.
237 VarDesc desc; 232 VarDesc desc;
238 desc.name = &String::Handle(); // No name. 233 desc.name = &String::Handle(); // No name.
239 desc.info.kind = RawLocalVarDescriptors::kContextLevel; 234 desc.info.kind = RawLocalVarDescriptors::kContextLevel;
240 desc.info.scope_id = *scope_id; 235 desc.info.scope_id = *scope_id;
241 desc.info.begin_pos = begin_token_pos(); 236 desc.info.begin_pos = begin_token_pos();
242 desc.info.end_pos = end_token_pos(); 237 desc.info.end_pos = end_token_pos();
243 desc.info.index = context_level(); 238 desc.info.index = context_level();
244 vars->Add(desc); 239 vars->Add(desc);
245 } 240 }
246 for (int i = 0; i < this->variables_.length(); i++) { 241 for (int i = 0; i < this->variables_.length(); i++) {
247 LocalVariable* var = variables_[i]; 242 LocalVariable* var = variables_[i];
248 if (var->owner() == this) { 243 if (var->owner() == this) {
249 if (!IsInternalIdentifier(var->name())) { 244 if (!IsInternalIdentifier(var->name())) {
250 // This is a regular Dart variable, either stack-based or captured. 245 // This is a regular Dart variable, either stack-based or captured.
251 VarDesc desc; 246 VarDesc desc;
252 desc.name = &var->name(); 247 desc.name = &var->name();
253 if (var->is_captured()) { 248 if (var->is_captured()) {
254 desc.info.kind = RawLocalVarDescriptors::kContextVar; 249 desc.info.kind = RawLocalVarDescriptors::kContextVar;
255 ASSERT(var->owner() != NULL); 250 ASSERT(var->owner() != NULL);
256 ASSERT(var->owner()->context_level() >= 0); 251 ASSERT(var->owner()->context_level() >= 0);
257 desc.info.scope_id = var->owner()->context_level(); 252 desc.info.scope_id = var->owner()->context_level();
258 } else { 253 } else {
259 desc.info.kind = RawLocalVarDescriptors::kStackVar; 254 desc.info.kind = RawLocalVarDescriptors::kStackVar;
260 desc.info.scope_id = *scope_id; 255 desc.info.scope_id = *scope_id;
261 } 256 }
262 desc.info.begin_pos = var->token_pos(); 257 desc.info.begin_pos = var->token_pos();
263 desc.info.end_pos = var->owner()->end_token_pos(); 258 desc.info.end_pos = var->owner()->end_token_pos();
264 desc.info.index = var->index(); 259 desc.info.index = var->index();
265 vars->Add(desc); 260 vars->Add(desc);
266 } else if (var->name().Equals(LocalVariable::kSavedContextVarName)) { 261 } else if (var->name().Equals(
262 Symbols::Name(Symbols::kSavedEntryContextVar))) {
hausner 2012/08/31 00:34:55 Isn't it enough to just allocate a string handle f
regis 2012/08/31 01:36:18 Yes, but it seems like a waste to allocate all the
hausner 2012/08/31 05:56:26 Ok, that's a valid reason that I buy. I hope Equal
267 // This is the local variable in which the function saves the 263 // This is the local variable in which the function saves the
268 // caller's chain of closure contexts (caller's CTX register). 264 // caller's chain of closure contexts (caller's CTX register).
269 VarDesc desc; 265 VarDesc desc;
270 desc.name = &var->name(); 266 desc.name = &var->name();
271 desc.info.kind = RawLocalVarDescriptors::kContextChain; 267 desc.info.kind = RawLocalVarDescriptors::kContextChain;
272 desc.info.scope_id = 0; 268 desc.info.scope_id = 0;
273 desc.info.begin_pos = 0; 269 desc.info.begin_pos = 0;
274 desc.info.end_pos = 0; 270 desc.info.end_pos = 0;
275 desc.info.index = var->index(); 271 desc.info.index = var->index();
276 vars->Add(desc); 272 vars->Add(desc);
277 } 273 }
274 // The saved arguments descriptor variable is not currently collected.
278 } 275 }
279 } 276 }
280 LocalScope* child = this->child(); 277 LocalScope* child = this->child();
281 while (child != NULL) { 278 while (child != NULL) {
282 child->CollectLocalVariables(vars, scope_id); 279 child->CollectLocalVariables(vars, scope_id);
283 child = child->sibling(); 280 child = child->sibling();
284 } 281 }
285 } 282 }
286 283
287 284
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 } else { 549 } else {
553 // Shift negative indexes so that the lowest one is 0 (they are still 550 // Shift negative indexes so that the lowest one is 0 (they are still
554 // non-positive). 551 // non-positive).
555 return fixed_parameter_count - 552 return fixed_parameter_count -
556 (index() - ParsedFunction::kFirstLocalSlotIndex); 553 (index() - ParsedFunction::kFirstLocalSlotIndex);
557 } 554 }
558 } 555 }
559 556
560 557
561 } // namespace dart 558 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698