| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 KernelReader::KernelReader(Program* program) | 96 KernelReader::KernelReader(Program* program) |
| 97 : program_(program), | 97 : program_(program), |
| 98 thread_(dart::Thread::Current()), | 98 thread_(dart::Thread::Current()), |
| 99 zone_(thread_->zone()), | 99 zone_(thread_->zone()), |
| 100 isolate_(thread_->isolate()), | 100 isolate_(thread_->isolate()), |
| 101 scripts_(Array::ZoneHandle(zone_)), | 101 scripts_(Array::ZoneHandle(zone_)), |
| 102 translation_helper_(this, thread_, zone_, isolate_), | 102 translation_helper_(this, thread_, zone_, isolate_), |
| 103 type_translator_(&translation_helper_, | 103 type_translator_(&translation_helper_, |
| 104 &active_class_, | 104 &active_class_, |
| 105 /*finalize=*/false) { | 105 /*finalize=*/false) { |
| 106 intptr_t source_file_count = program_->line_starting_table().size(); | 106 intptr_t source_file_count = program_->source_table().size(); |
| 107 scripts_ = Array::New(source_file_count, Heap::kOld); | 107 scripts_ = Array::New(source_file_count, Heap::kOld); |
| 108 } | 108 } |
| 109 | 109 |
| 110 Object& KernelReader::ReadProgram() { | 110 Object& KernelReader::ReadProgram() { |
| 111 LongJumpScope jump; | 111 LongJumpScope jump; |
| 112 if (setjmp(*jump.Set()) == 0) { | 112 if (setjmp(*jump.Set()) == 0) { |
| 113 Procedure* main = program_->main_method(); | 113 Procedure* main = program_->main_method(); |
| 114 Library* kernel_main_library = Library::Cast(main->parent()); | 114 Library* kernel_main_library = Library::Cast(main->parent()); |
| 115 | 115 |
| 116 intptr_t length = program_->libraries().length(); | 116 intptr_t length = program_->libraries().length(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 // The bootstrapper will take care of creating the native wrapper classes, but | 151 // The bootstrapper will take care of creating the native wrapper classes, but |
| 152 // we will add the synthetic constructors to them here. | 152 // we will add the synthetic constructors to them here. |
| 153 if (library.name() == | 153 if (library.name() == |
| 154 Symbols::Symbol(Symbols::kDartNativeWrappersLibNameId).raw()) { | 154 Symbols::Symbol(Symbols::kDartNativeWrappersLibNameId).raw()) { |
| 155 ASSERT(library.LoadInProgress()); | 155 ASSERT(library.LoadInProgress()); |
| 156 } else { | 156 } else { |
| 157 library.SetLoadInProgress(); | 157 library.SetLoadInProgress(); |
| 158 } | 158 } |
| 159 // Setup toplevel class (which contains library fields/procedures). | 159 // Setup toplevel class (which contains library fields/procedures). |
| 160 | 160 |
| 161 Script& script = ScriptAt(kernel_library->source_uri_index()); | 161 Script& script = ScriptAt(kernel_library->source_uri_index(), |
| 162 kernel_library->import_uri()); |
| 162 dart::Class& toplevel_class = dart::Class::Handle( | 163 dart::Class& toplevel_class = dart::Class::Handle( |
| 163 Z, dart::Class::New(library, Symbols::TopLevel(), script, | 164 Z, dart::Class::New(library, Symbols::TopLevel(), script, |
| 164 TokenPosition::kNoSource)); | 165 TokenPosition::kNoSource)); |
| 165 toplevel_class.set_is_cycle_free(); | 166 toplevel_class.set_is_cycle_free(); |
| 166 library.set_toplevel_class(toplevel_class); | 167 library.set_toplevel_class(toplevel_class); |
| 167 | 168 |
| 168 ActiveClassScope active_class_scope(&active_class_, NULL, &toplevel_class); | 169 ActiveClassScope active_class_scope(&active_class_, NULL, &toplevel_class); |
| 169 // Load toplevel fields. | 170 // Load toplevel fields. |
| 170 for (intptr_t i = 0; i < kernel_library->fields().length(); i++) { | 171 for (intptr_t i = 0; i < kernel_library->fields().length(); i++) { |
| 171 Field* kernel_field = kernel_library->fields()[i]; | 172 Field* kernel_field = kernel_library->fields()[i]; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 kernel_constructor->function()); | 318 kernel_constructor->function()); |
| 318 | 319 |
| 319 const dart::String& name = H.DartConstructorName(kernel_constructor); | 320 const dart::String& name = H.DartConstructorName(kernel_constructor); |
| 320 Function& function = dart::Function::ZoneHandle( | 321 Function& function = dart::Function::ZoneHandle( |
| 321 Z, dart::Function::New(name, RawFunction::kConstructor, | 322 Z, dart::Function::New(name, RawFunction::kConstructor, |
| 322 false, // is_static | 323 false, // is_static |
| 323 kernel_constructor->IsConst(), | 324 kernel_constructor->IsConst(), |
| 324 false, // is_abstract | 325 false, // is_abstract |
| 325 kernel_constructor->IsExternal(), | 326 kernel_constructor->IsExternal(), |
| 326 false, // is_native | 327 false, // is_native |
| 327 klass, TokenPosition::kNoSource)); | 328 klass, TokenPosition::kMinSource)); |
| 329 function.set_end_token_pos(TokenPosition::kMinSource); |
| 328 klass.AddFunction(function); | 330 klass.AddFunction(function); |
| 329 function.set_kernel_function(kernel_constructor); | 331 function.set_kernel_function(kernel_constructor); |
| 330 function.set_result_type(T.ReceiverType(klass)); | 332 function.set_result_type(T.ReceiverType(klass)); |
| 331 SetupFunctionParameters(H, T, klass, function, | 333 SetupFunctionParameters(H, T, klass, function, |
| 332 kernel_constructor->function(), | 334 kernel_constructor->function(), |
| 333 true, // is_method | 335 true, // is_method |
| 334 false); // is_closure | 336 false); // is_closure |
| 335 } | 337 } |
| 336 | 338 |
| 337 for (intptr_t i = 0; i < kernel_klass->procedures().length(); i++) { | 339 for (intptr_t i = 0; i < kernel_klass->procedures().length(); i++) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 } | 396 } |
| 395 } | 397 } |
| 396 const Object& script_class = | 398 const Object& script_class = |
| 397 ClassForScriptAt(owner, kernel_procedure->source_uri_index()); | 399 ClassForScriptAt(owner, kernel_procedure->source_uri_index()); |
| 398 dart::Function& function = dart::Function::ZoneHandle( | 400 dart::Function& function = dart::Function::ZoneHandle( |
| 399 Z, Function::New(name, GetFunctionType(kernel_procedure), | 401 Z, Function::New(name, GetFunctionType(kernel_procedure), |
| 400 !is_method, // is_static | 402 !is_method, // is_static |
| 401 false, // is_const | 403 false, // is_const |
| 402 is_abstract, is_external, | 404 is_abstract, is_external, |
| 403 native_name != NULL, // is_native | 405 native_name != NULL, // is_native |
| 404 script_class, TokenPosition::kNoSource)); | 406 script_class, TokenPosition::kMinSource)); |
| 407 function.set_end_token_pos(TokenPosition::kMinSource); |
| 405 owner.AddFunction(function); | 408 owner.AddFunction(function); |
| 406 function.set_kernel_function(kernel_procedure); | 409 function.set_kernel_function(kernel_procedure); |
| 407 function.set_is_debuggable(false); | 410 function.set_is_debuggable(false); |
| 408 if (native_name != NULL) { | 411 if (native_name != NULL) { |
| 409 function.set_native_name(*native_name); | 412 function.set_native_name(*native_name); |
| 410 } | 413 } |
| 411 | 414 |
| 412 SetupFunctionParameters(H, T, owner, function, kernel_procedure->function(), | 415 SetupFunctionParameters(H, T, owner, function, kernel_procedure->function(), |
| 413 is_method, | 416 is_method, |
| 414 false); // is_closure | 417 false); // is_closure |
| (...skipping 10 matching lines...) Expand all Loading... |
| 425 intptr_t source_uri_index) { | 428 intptr_t source_uri_index) { |
| 426 Script& correct_script = ScriptAt(source_uri_index); | 429 Script& correct_script = ScriptAt(source_uri_index); |
| 427 if (klass.script() != correct_script.raw()) { | 430 if (klass.script() != correct_script.raw()) { |
| 428 // TODO(jensj): We could probably cache this so we don't create | 431 // TODO(jensj): We could probably cache this so we don't create |
| 429 // new PatchClasses all the time | 432 // new PatchClasses all the time |
| 430 return PatchClass::ZoneHandle(Z, PatchClass::New(klass, correct_script)); | 433 return PatchClass::ZoneHandle(Z, PatchClass::New(klass, correct_script)); |
| 431 } | 434 } |
| 432 return klass; | 435 return klass; |
| 433 } | 436 } |
| 434 | 437 |
| 435 Script& KernelReader::ScriptAt(intptr_t source_uri_index) { | 438 Script& KernelReader::ScriptAt(intptr_t source_uri_index, String* import_uri) { |
| 436 Script& script = Script::ZoneHandle(Z); | 439 Script& script = Script::ZoneHandle(Z); |
| 437 script ^= scripts_.At(source_uri_index); | 440 script ^= scripts_.At(source_uri_index); |
| 438 if (script.IsNull()) { | 441 if (script.IsNull()) { |
| 442 // Create script with correct uri(s). |
| 439 String* uri = program_->source_uri_table().strings()[source_uri_index]; | 443 String* uri = program_->source_uri_table().strings()[source_uri_index]; |
| 440 script = Script::New(H.DartString(uri, Heap::kOld), | 444 dart::String& uri_string = H.DartString(uri, Heap::kOld); |
| 441 dart::String::ZoneHandle(Z), RawScript::kKernelTag); | 445 dart::String& import_uri_string = |
| 446 import_uri == NULL ? uri_string : H.DartString(import_uri, Heap::kOld); |
| 447 dart::String& source_code = H.DartString( |
| 448 program_->source_table().SourceFor(source_uri_index), Heap::kOld); |
| 449 script = Script::New(import_uri_string, uri_string, source_code, |
| 450 RawScript::kKernelTag); |
| 442 scripts_.SetAt(source_uri_index, script); | 451 scripts_.SetAt(source_uri_index, script); |
| 452 |
| 453 // Create line_starts array for the script. |
| 443 intptr_t* line_starts = | 454 intptr_t* line_starts = |
| 444 program_->line_starting_table().valuesFor(source_uri_index); | 455 program_->source_table().LineStartsFor(source_uri_index); |
| 445 intptr_t line_count = line_starts[0]; | 456 intptr_t line_count = |
| 457 program_->source_table().LineCountFor(source_uri_index); |
| 446 Array& array_object = Array::Handle(Z, Array::New(line_count, Heap::kOld)); | 458 Array& array_object = Array::Handle(Z, Array::New(line_count, Heap::kOld)); |
| 447 Smi& value = Smi::Handle(Z); | 459 Smi& value = Smi::Handle(Z); |
| 448 for (intptr_t i = 0; i < line_count; ++i) { | 460 for (intptr_t i = 0; i < line_count; ++i) { |
| 449 value = Smi::New(line_starts[i + 1]); | 461 value = Smi::New(line_starts[i]); |
| 450 array_object.SetAt(i, value); | 462 array_object.SetAt(i, value); |
| 451 } | 463 } |
| 452 script.set_line_starts(array_object); | 464 script.set_line_starts(array_object); |
| 453 } | 465 } |
| 454 return script; | 466 return script; |
| 455 } | 467 } |
| 456 | 468 |
| 457 void KernelReader::GenerateFieldAccessors(const dart::Class& klass, | 469 void KernelReader::GenerateFieldAccessors(const dart::Class& klass, |
| 458 const dart::Field& field, | 470 const dart::Field& field, |
| 459 Field* kernel_field) { | 471 Field* kernel_field) { |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 initializer_fun.set_is_debuggable(false); | 722 initializer_fun.set_is_debuggable(false); |
| 711 initializer_fun.set_is_reflectable(false); | 723 initializer_fun.set_is_reflectable(false); |
| 712 initializer_fun.set_is_inlinable(false); | 724 initializer_fun.set_is_inlinable(false); |
| 713 return new (zone) ParsedFunction(thread, initializer_fun); | 725 return new (zone) ParsedFunction(thread, initializer_fun); |
| 714 } | 726 } |
| 715 | 727 |
| 716 | 728 |
| 717 } // namespace kernel | 729 } // namespace kernel |
| 718 } // namespace dart | 730 } // namespace dart |
| 719 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 731 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| OLD | NEW |