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

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

Issue 2632183002: Debugging in kernel shaping up. (Closed)
Patch Set: Changed to TokenPosition::kMaxSourcePos Created 3 years, 10 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
« no previous file with comments | « runtime/vm/kernel_binary.cc ('k') | runtime/vm/kernel_to_il.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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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/kernel_reader.h" 5 #include "vm/kernel_reader.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/longjump.h" 10 #include "vm/longjump.h"
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 intptr_t source_uri_index) { 443 intptr_t source_uri_index) {
444 Script& correct_script = ScriptAt(source_uri_index); 444 Script& correct_script = ScriptAt(source_uri_index);
445 if (klass.script() != correct_script.raw()) { 445 if (klass.script() != correct_script.raw()) {
446 // TODO(jensj): We could probably cache this so we don't create 446 // TODO(jensj): We could probably cache this so we don't create
447 // new PatchClasses all the time 447 // new PatchClasses all the time
448 return PatchClass::ZoneHandle(Z, PatchClass::New(klass, correct_script)); 448 return PatchClass::ZoneHandle(Z, PatchClass::New(klass, correct_script));
449 } 449 }
450 return klass; 450 return klass;
451 } 451 }
452 452
453 static int LowestFirst(const intptr_t* a, const intptr_t* b) {
454 return *a - *b;
455 }
456
457 /**
458 * If index exists as sublist in list, sort the sublist from lowest to highest,
459 * then copy it, as Smis and without duplicates,
460 * to a new Array in Heap::kOld which is returned.
461 * Note that the source list is both sorted and de-duplicated as well, but will
462 * possibly contain duplicate and unsorted data at the end.
463 * Otherwise (when sublist doesn't exist in list) return new empty array.
464 */
465 static RawArray* AsSortedDuplicateFreeArray(
466 intptr_t index,
467 MallocGrowableArray<MallocGrowableArray<intptr_t>*>* list) {
468 if ((index < list->length()) && (list->At(index)->length() > 0)) {
469 MallocGrowableArray<intptr_t>* source = list->At(index);
470 source->Sort(LowestFirst);
471
472 intptr_t size = source->length();
473 intptr_t last = 0;
474 for (intptr_t current = 1; current < size; ++current) {
475 if (source->At(last) != source->At(current)) {
476 (*source)[++last] = source->At(current);
477 }
478 }
479 Array& array_object = Array::Handle();
480 array_object ^= Array::New(last + 1, Heap::kOld);
481 Smi& smi_value = Smi::Handle();
482 for (intptr_t i = 0; i <= last; ++i) {
483 smi_value = Smi::New(source->At(i));
484 array_object.SetAt(i, smi_value);
485 }
486 return array_object.raw();
487 } else {
488 return Array::New(0);
489 }
490 }
491
453 Script& KernelReader::ScriptAt(intptr_t source_uri_index, String* import_uri) { 492 Script& KernelReader::ScriptAt(intptr_t source_uri_index, String* import_uri) {
454 Script& script = Script::ZoneHandle(Z); 493 Script& script = Script::ZoneHandle(Z);
455 script ^= scripts_.At(source_uri_index); 494 script ^= scripts_.At(source_uri_index);
456 if (script.IsNull()) { 495 if (script.IsNull()) {
457 // Create script with correct uri(s). 496 // Create script with correct uri(s).
458 String* uri = program_->source_uri_table().strings()[source_uri_index]; 497 String* uri = program_->source_uri_table().strings()[source_uri_index];
459 dart::String& uri_string = H.DartString(uri, Heap::kOld); 498 dart::String& uri_string = H.DartString(uri, Heap::kOld);
460 dart::String& import_uri_string = 499 dart::String& import_uri_string =
461 import_uri == NULL ? uri_string : H.DartString(import_uri, Heap::kOld); 500 import_uri == NULL ? uri_string : H.DartString(import_uri, Heap::kOld);
462 dart::String& source_code = H.DartString( 501 dart::String& source_code = H.DartString(
463 program_->source_table().SourceFor(source_uri_index), Heap::kOld); 502 program_->source_table().SourceFor(source_uri_index), Heap::kOld);
464 script = Script::New(import_uri_string, uri_string, source_code, 503 script = Script::New(import_uri_string, uri_string, source_code,
465 RawScript::kKernelTag); 504 RawScript::kKernelTag);
466 scripts_.SetAt(source_uri_index, script); 505 scripts_.SetAt(source_uri_index, script);
467 506
468 // Create line_starts array for the script. 507 // Create line_starts array for the script.
469 intptr_t* line_starts = 508 intptr_t* line_starts =
470 program_->source_table().LineStartsFor(source_uri_index); 509 program_->source_table().LineStartsFor(source_uri_index);
471 intptr_t line_count = 510 intptr_t line_count =
472 program_->source_table().LineCountFor(source_uri_index); 511 program_->source_table().LineCountFor(source_uri_index);
473 Array& array_object = Array::Handle(Z, Array::New(line_count, Heap::kOld)); 512 Array& array_object = Array::Handle(Z, Array::New(line_count, Heap::kOld));
474 Smi& value = Smi::Handle(Z); 513 Smi& value = Smi::Handle(Z);
475 for (intptr_t i = 0; i < line_count; ++i) { 514 for (intptr_t i = 0; i < line_count; ++i) {
476 value = Smi::New(line_starts[i]); 515 value = Smi::New(line_starts[i]);
477 array_object.SetAt(i, value); 516 array_object.SetAt(i, value);
478 } 517 }
479 script.set_line_starts(array_object); 518 script.set_line_starts(array_object);
519
520 // Create tokens_seen array for the script.
521 array_object ^= AsSortedDuplicateFreeArray(
522 source_uri_index, &program_->valid_token_positions);
523 script.set_debug_positions(array_object);
524
525 // Create yield_positions array for the script.
526 array_object ^= AsSortedDuplicateFreeArray(
527 source_uri_index, &program_->yield_token_positions);
528 script.set_yield_positions(array_object);
480 } 529 }
481 return script; 530 return script;
482 } 531 }
483 532
484 void KernelReader::GenerateFieldAccessors(const dart::Class& klass, 533 void KernelReader::GenerateFieldAccessors(const dart::Class& klass,
485 const dart::Field& field, 534 const dart::Field& field,
486 Field* kernel_field) { 535 Field* kernel_field) {
487 if (kernel_field->IsStatic() && kernel_field->initializer() != NULL) { 536 if (kernel_field->IsStatic() && kernel_field->initializer() != NULL) {
488 // Static fields with initializers either have the static value set to the 537 // Static fields with initializers either have the static value set to the
489 // initializer value if it is simple enough or else set to an uninitialized 538 // initializer value if it is simple enough or else set to an uninitialized
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 initializer_fun.set_is_debuggable(false); 789 initializer_fun.set_is_debuggable(false);
741 initializer_fun.set_is_reflectable(false); 790 initializer_fun.set_is_reflectable(false);
742 initializer_fun.set_is_inlinable(false); 791 initializer_fun.set_is_inlinable(false);
743 return new (zone) ParsedFunction(thread, initializer_fun); 792 return new (zone) ParsedFunction(thread, initializer_fun);
744 } 793 }
745 794
746 795
747 } // namespace kernel 796 } // namespace kernel
748 } // namespace dart 797 } // namespace dart
749 #endif // !defined(DART_PRECOMPILED_RUNTIME) 798 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « runtime/vm/kernel_binary.cc ('k') | runtime/vm/kernel_to_il.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698