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

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

Issue 267583002: Add some testing for the variable allocation code in the Parser. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: improve tests Created 6 years, 7 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 | « runtime/vm/debugger.cc ('k') | runtime/vm/parser_test.cc » ('j') | 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/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 10226 matching lines...) Expand 10 before | Expand all | Expand 10 after
10237 } 10237 }
10238 10238
10239 10239
10240 void LocalVarDescriptors::GetInfo(intptr_t var_index, 10240 void LocalVarDescriptors::GetInfo(intptr_t var_index,
10241 RawLocalVarDescriptors::VarInfo* info) const { 10241 RawLocalVarDescriptors::VarInfo* info) const {
10242 ASSERT(var_index < Length()); 10242 ASSERT(var_index < Length());
10243 *info = raw_ptr()->data_[var_index]; 10243 *info = raw_ptr()->data_[var_index];
10244 } 10244 }
10245 10245
10246 10246
10247 static const char* VarKindString(int kind) {
10248 switch (kind) {
10249 case RawLocalVarDescriptors::kStackVar:
10250 return "StackVar";
10251 break;
10252 case RawLocalVarDescriptors::kContextVar:
10253 return "ContextVar";
10254 break;
10255 case RawLocalVarDescriptors::kContextLevel:
10256 return "ContextLevel";
10257 break;
10258 case RawLocalVarDescriptors::kSavedEntryContext:
10259 return "SavedEntryCtx";
10260 break;
10261 case RawLocalVarDescriptors::kSavedCurrentContext:
10262 return "SavedCurrentCtx";
10263 break;
10264 default:
10265 UNREACHABLE();
10266 return "Unknown";
10267 }
10268 }
10269
10270
10247 const char* LocalVarDescriptors::ToCString() const { 10271 const char* LocalVarDescriptors::ToCString() const {
10248 intptr_t len = 1; // Trailing '\0'. 10272 intptr_t len = 1; // Trailing '\0'.
10249 const char* kFormat = 10273 const char* kFormat =
10250 "%2" Pd " kind=%d scope=0x%04x begin=%" Pd " end=%" Pd " name=%s\n"; 10274 "%2" Pd " %-13s scope=%-3d index=%-3" Pd ""
10275 " begin=%-3" Pd " end=%-3" Pd " name=%s\n";
10276 const char* kFormatCtxLevel =
10277 "%1$2" Pd " %2$-13s level=%4$-3" Pd " scope=%3$-3d"
10278 " begin=%5$-3" Pd " end=%6$" Pd "\n";
10279 const char* kFormatCtxVar =
10280 "%2" Pd " %-13s level=%-3d index=%-3" Pd ""
10281 " begin=%-3" Pd " end=%-3" Pd " name=%s\n";
10251 for (intptr_t i = 0; i < Length(); i++) { 10282 for (intptr_t i = 0; i < Length(); i++) {
10252 String& var_name = String::Handle(GetName(i)); 10283 String& var_name = String::Handle(GetName(i));
10253 if (var_name.IsNull()) { 10284 if (var_name.IsNull()) {
10254 var_name = Symbols::Empty().raw(); 10285 var_name = Symbols::Empty().raw();
10255 } 10286 }
10256 RawLocalVarDescriptors::VarInfo info; 10287 RawLocalVarDescriptors::VarInfo info;
10257 GetInfo(i, &info); 10288 GetInfo(i, &info);
10258 len += OS::SNPrint(NULL, 0, kFormat, 10289 const char* format = kFormat;
10290 if (info.kind == RawLocalVarDescriptors::kContextLevel) {
10291 format = kFormatCtxLevel;
10292 } else if (info.kind == RawLocalVarDescriptors::kContextVar) {
10293 format = kFormatCtxVar;
10294 }
10295 len += OS::SNPrint(NULL, 0,
10296 format,
10259 i, 10297 i,
10260 info.kind, 10298 VarKindString(info.kind),
10261 info.scope_id, 10299 info.scope_id,
10300 info.index,
10262 info.begin_pos, 10301 info.begin_pos,
10263 info.end_pos, 10302 info.end_pos,
10264 var_name.ToCString()); 10303 var_name.ToCString());
10265 } 10304 }
10266 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len); 10305 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len);
10267 intptr_t num_chars = 0; 10306 intptr_t num_chars = 0;
10268 for (intptr_t i = 0; i < Length(); i++) { 10307 for (intptr_t i = 0; i < Length(); i++) {
10269 String& var_name = String::Handle(GetName(i)); 10308 String& var_name = String::Handle(GetName(i));
10270 if (var_name.IsNull()) { 10309 if (var_name.IsNull()) {
10271 var_name = Symbols::Empty().raw(); 10310 var_name = Symbols::Empty().raw();
10272 } 10311 }
10273 RawLocalVarDescriptors::VarInfo info; 10312 RawLocalVarDescriptors::VarInfo info;
10274 GetInfo(i, &info); 10313 GetInfo(i, &info);
10314 const char* format = kFormat;
10315 if (info.kind == RawLocalVarDescriptors::kContextLevel) {
10316 format = kFormatCtxLevel;
10317 } else if (info.kind == RawLocalVarDescriptors::kContextVar) {
10318 format = kFormatCtxVar;
10319 }
10275 num_chars += OS::SNPrint((buffer + num_chars), 10320 num_chars += OS::SNPrint((buffer + num_chars),
10276 (len - num_chars), 10321 (len - num_chars),
10277 kFormat, 10322 format,
10278 i, 10323 i,
10279 info.kind, 10324 VarKindString(info.kind),
10280 info.scope_id, 10325 info.scope_id,
10326 info.index,
10281 info.begin_pos, 10327 info.begin_pos,
10282 info.end_pos, 10328 info.end_pos,
10283 var_name.ToCString()); 10329 var_name.ToCString());
10284 } 10330 }
10285 return buffer; 10331 return buffer;
10286 } 10332 }
10287 10333
10288 10334
10289 void LocalVarDescriptors::PrintJSONImpl(JSONStream* stream, 10335 void LocalVarDescriptors::PrintJSONImpl(JSONStream* stream,
10290 bool ref) const { 10336 bool ref) const {
(...skipping 8378 matching lines...) Expand 10 before | Expand all | Expand 10 after
18669 return tag_label.ToCString(); 18715 return tag_label.ToCString();
18670 } 18716 }
18671 18717
18672 18718
18673 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 18719 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
18674 Instance::PrintJSONImpl(stream, ref); 18720 Instance::PrintJSONImpl(stream, ref);
18675 } 18721 }
18676 18722
18677 18723
18678 } // namespace dart 18724 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/debugger.cc ('k') | runtime/vm/parser_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698