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

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

Issue 10697011: Include variable names with _ (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 207
208 const LocalVarDescriptors& var_desc = 208 const LocalVarDescriptors& var_desc =
209 LocalVarDescriptors::Handle(LocalVarDescriptors::New(vars.length())); 209 LocalVarDescriptors::Handle(LocalVarDescriptors::New(vars.length()));
210 for (int i = 0; i < vars.length(); i++) { 210 for (int i = 0; i < vars.length(); i++) {
211 var_desc.SetVar(i, *(vars[i].name), &vars[i].info); 211 var_desc.SetVar(i, *(vars[i].name), &vars[i].info);
212 } 212 }
213 return var_desc.raw(); 213 return var_desc.raw();
214 } 214 }
215 215
216 216
217 // The parser creates internal variables that start with ":"
218 static bool IsInternalIdentifier(const String& str) {
219 ASSERT(str.Length() > 0);
220 return str.CharAt(0) == ':';
221 }
222
223
217 // Add variables that are declared in this scope to vars, then collect 224 // Add variables that are declared in this scope to vars, then collect
218 // variables of children, followed by siblings. 225 // variables of children, followed by siblings.
219 void LocalScope::CollectLocalVariables(GrowableArray<VarDesc>* vars, 226 void LocalScope::CollectLocalVariables(GrowableArray<VarDesc>* vars,
220 int16_t* scope_id) { 227 int16_t* scope_id) {
221 (*scope_id)++; 228 (*scope_id)++;
222 if (HasContextLevel() && 229 if (HasContextLevel() &&
223 ((parent() == NULL) || 230 ((parent() == NULL) ||
224 (!parent()->HasContextLevel()) || 231 (!parent()->HasContextLevel()) ||
225 (parent()->context_level() != context_level()))) { 232 (parent()->context_level() != context_level()))) {
226 // This is the outermost scope with a context level or this scope's 233 // This is the outermost scope with a context level or this scope's
227 // context level differes from its parent's level. 234 // context level differes from its parent's level.
228 VarDesc desc; 235 VarDesc desc;
229 desc.name = &String::Handle(); // No name. 236 desc.name = &String::Handle(); // No name.
230 desc.info.kind = RawLocalVarDescriptors::kContextLevel; 237 desc.info.kind = RawLocalVarDescriptors::kContextLevel;
231 desc.info.scope_id = *scope_id; 238 desc.info.scope_id = *scope_id;
232 desc.info.begin_pos = begin_token_pos(); 239 desc.info.begin_pos = begin_token_pos();
233 desc.info.end_pos = end_token_pos(); 240 desc.info.end_pos = end_token_pos();
234 desc.info.index = context_level(); 241 desc.info.index = context_level();
235 vars->Add(desc); 242 vars->Add(desc);
236 } 243 }
237 for (int i = 0; i < this->variables_.length(); i++) { 244 for (int i = 0; i < this->variables_.length(); i++) {
238 LocalVariable* var = variables_[i]; 245 LocalVariable* var = variables_[i];
239 if (var->owner() == this) { 246 if (var->owner() == this) {
240 if (Scanner::IsIdent(var->name())) { 247 if (!IsInternalIdentifier(var->name())) {
241 // This is a regular Dart variable, either stack-based or captured. 248 // This is a regular Dart variable, either stack-based or captured.
242 VarDesc desc; 249 VarDesc desc;
243 desc.name = &var->name(); 250 desc.name = &var->name();
244 if (var->is_captured()) { 251 if (var->is_captured()) {
245 desc.info.kind = RawLocalVarDescriptors::kContextVar; 252 desc.info.kind = RawLocalVarDescriptors::kContextVar;
246 ASSERT(var->owner() != NULL); 253 ASSERT(var->owner() != NULL);
247 ASSERT(var->owner()->context_level() >= 0); 254 ASSERT(var->owner()->context_level() >= 0);
248 desc.info.scope_id = var->owner()->context_level(); 255 desc.info.scope_id = var->owner()->context_level();
249 } else { 256 } else {
250 desc.info.kind = RawLocalVarDescriptors::kStackVar; 257 desc.info.kind = RawLocalVarDescriptors::kStackVar;
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 } else { 551 } else {
545 // Shift negative indexes so that the lowest one is 0 (they are still 552 // Shift negative indexes so that the lowest one is 0 (they are still
546 // non-positive) and index them backward from the end of the vector. 553 // non-positive) and index them backward from the end of the vector.
547 return (var_count - 1) + 554 return (var_count - 1) +
548 (index() - ParsedFunction::kFirstLocalSlotIndex); 555 (index() - ParsedFunction::kFirstLocalSlotIndex);
549 } 556 }
550 } 557 }
551 558
552 559
553 } // namespace dart 560 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698