| OLD | NEW |
| 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 Loading... |
| 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 | |
| 492 Script& KernelReader::ScriptAt(intptr_t source_uri_index, String* import_uri) { | 453 Script& KernelReader::ScriptAt(intptr_t source_uri_index, String* import_uri) { |
| 493 Script& script = Script::ZoneHandle(Z); | 454 Script& script = Script::ZoneHandle(Z); |
| 494 script ^= scripts_.At(source_uri_index); | 455 script ^= scripts_.At(source_uri_index); |
| 495 if (script.IsNull()) { | 456 if (script.IsNull()) { |
| 496 // Create script with correct uri(s). | 457 // Create script with correct uri(s). |
| 497 String* uri = program_->source_uri_table().strings()[source_uri_index]; | 458 String* uri = program_->source_uri_table().strings()[source_uri_index]; |
| 498 dart::String& uri_string = H.DartString(uri, Heap::kOld); | 459 dart::String& uri_string = H.DartString(uri, Heap::kOld); |
| 499 dart::String& import_uri_string = | 460 dart::String& import_uri_string = |
| 500 import_uri == NULL ? uri_string : H.DartString(import_uri, Heap::kOld); | 461 import_uri == NULL ? uri_string : H.DartString(import_uri, Heap::kOld); |
| 501 dart::String& source_code = H.DartString( | 462 dart::String& source_code = H.DartString( |
| 502 program_->source_table().SourceFor(source_uri_index), Heap::kOld); | 463 program_->source_table().SourceFor(source_uri_index), Heap::kOld); |
| 503 script = Script::New(import_uri_string, uri_string, source_code, | 464 script = Script::New(import_uri_string, uri_string, source_code, |
| 504 RawScript::kKernelTag); | 465 RawScript::kKernelTag); |
| 505 scripts_.SetAt(source_uri_index, script); | 466 scripts_.SetAt(source_uri_index, script); |
| 506 | 467 |
| 507 // Create line_starts array for the script. | 468 // Create line_starts array for the script. |
| 508 intptr_t* line_starts = | 469 intptr_t* line_starts = |
| 509 program_->source_table().LineStartsFor(source_uri_index); | 470 program_->source_table().LineStartsFor(source_uri_index); |
| 510 intptr_t line_count = | 471 intptr_t line_count = |
| 511 program_->source_table().LineCountFor(source_uri_index); | 472 program_->source_table().LineCountFor(source_uri_index); |
| 512 Array& array_object = Array::Handle(Z, Array::New(line_count, Heap::kOld)); | 473 Array& array_object = Array::Handle(Z, Array::New(line_count, Heap::kOld)); |
| 513 Smi& value = Smi::Handle(Z); | 474 Smi& value = Smi::Handle(Z); |
| 514 for (intptr_t i = 0; i < line_count; ++i) { | 475 for (intptr_t i = 0; i < line_count; ++i) { |
| 515 value = Smi::New(line_starts[i]); | 476 value = Smi::New(line_starts[i]); |
| 516 array_object.SetAt(i, value); | 477 array_object.SetAt(i, value); |
| 517 } | 478 } |
| 518 script.set_line_starts(array_object); | 479 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); | |
| 529 } | 480 } |
| 530 return script; | 481 return script; |
| 531 } | 482 } |
| 532 | 483 |
| 533 void KernelReader::GenerateFieldAccessors(const dart::Class& klass, | 484 void KernelReader::GenerateFieldAccessors(const dart::Class& klass, |
| 534 const dart::Field& field, | 485 const dart::Field& field, |
| 535 Field* kernel_field) { | 486 Field* kernel_field) { |
| 536 if (kernel_field->IsStatic() && kernel_field->initializer() != NULL) { | 487 if (kernel_field->IsStatic() && kernel_field->initializer() != NULL) { |
| 537 // Static fields with initializers either have the static value set to the | 488 // Static fields with initializers either have the static value set to the |
| 538 // initializer value if it is simple enough or else set to an uninitialized | 489 // 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 Loading... |
| 789 initializer_fun.set_is_debuggable(false); | 740 initializer_fun.set_is_debuggable(false); |
| 790 initializer_fun.set_is_reflectable(false); | 741 initializer_fun.set_is_reflectable(false); |
| 791 initializer_fun.set_is_inlinable(false); | 742 initializer_fun.set_is_inlinable(false); |
| 792 return new (zone) ParsedFunction(thread, initializer_fun); | 743 return new (zone) ParsedFunction(thread, initializer_fun); |
| 793 } | 744 } |
| 794 | 745 |
| 795 | 746 |
| 796 } // namespace kernel | 747 } // namespace kernel |
| 797 } // namespace dart | 748 } // namespace dart |
| 798 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 749 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| OLD | NEW |