Chromium Code Reviews| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 kernel_constructor->function()); | 316 kernel_constructor->function()); |
| 316 | 317 |
| 317 const dart::String& name = H.DartConstructorName(kernel_constructor); | 318 const dart::String& name = H.DartConstructorName(kernel_constructor); |
| 318 Function& function = dart::Function::ZoneHandle( | 319 Function& function = dart::Function::ZoneHandle( |
| 319 Z, dart::Function::New(name, RawFunction::kConstructor, | 320 Z, dart::Function::New(name, RawFunction::kConstructor, |
| 320 false, // is_static | 321 false, // is_static |
| 321 kernel_constructor->IsConst(), | 322 kernel_constructor->IsConst(), |
| 322 false, // is_abstract | 323 false, // is_abstract |
| 323 kernel_constructor->IsExternal(), | 324 kernel_constructor->IsExternal(), |
| 324 false, // is_native | 325 false, // is_native |
| 325 klass, TokenPosition::kNoSource)); | 326 klass, TokenPosition::kMinSource)); |
| 327 function.set_end_token_pos(TokenPosition::kMinSource); | |
| 326 klass.AddFunction(function); | 328 klass.AddFunction(function); |
| 327 function.set_kernel_function(kernel_constructor); | 329 function.set_kernel_function(kernel_constructor); |
| 328 function.set_result_type(T.ReceiverType(klass)); | 330 function.set_result_type(T.ReceiverType(klass)); |
| 329 SetupFunctionParameters(H, T, klass, function, | 331 SetupFunctionParameters(H, T, klass, function, |
| 330 kernel_constructor->function(), | 332 kernel_constructor->function(), |
| 331 true, // is_method | 333 true, // is_method |
| 332 false); // is_closure | 334 false); // is_closure |
| 333 } | 335 } |
| 334 | 336 |
| 335 for (intptr_t i = 0; i < kernel_klass->procedures().length(); i++) { | 337 for (intptr_t i = 0; i < kernel_klass->procedures().length(); i++) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 } | 394 } |
| 393 } | 395 } |
| 394 const Object& script_class = | 396 const Object& script_class = |
| 395 ClassForScriptAt(owner, kernel_procedure->source_uri_index()); | 397 ClassForScriptAt(owner, kernel_procedure->source_uri_index()); |
| 396 dart::Function& function = dart::Function::ZoneHandle( | 398 dart::Function& function = dart::Function::ZoneHandle( |
| 397 Z, Function::New(name, GetFunctionType(kernel_procedure), | 399 Z, Function::New(name, GetFunctionType(kernel_procedure), |
| 398 !is_method, // is_static | 400 !is_method, // is_static |
| 399 false, // is_const | 401 false, // is_const |
| 400 is_abstract, is_external, | 402 is_abstract, is_external, |
| 401 native_name != NULL, // is_native | 403 native_name != NULL, // is_native |
| 402 script_class, TokenPosition::kNoSource)); | 404 script_class, TokenPosition::kMinSource)); |
| 405 function.set_end_token_pos(TokenPosition::kMinSource); | |
|
Cutch
2016/12/21 00:27:12
Observatory relies on knowing start / end token po
| |
| 403 owner.AddFunction(function); | 406 owner.AddFunction(function); |
| 404 function.set_kernel_function(kernel_procedure); | 407 function.set_kernel_function(kernel_procedure); |
| 405 function.set_is_debuggable(false); | 408 function.set_is_debuggable(false); |
| 406 if (native_name != NULL) { | 409 if (native_name != NULL) { |
| 407 function.set_native_name(*native_name); | 410 function.set_native_name(*native_name); |
| 408 } | 411 } |
| 409 | 412 |
| 410 SetupFunctionParameters(H, T, owner, function, kernel_procedure->function(), | 413 SetupFunctionParameters(H, T, owner, function, kernel_procedure->function(), |
| 411 is_method, | 414 is_method, |
| 412 false); // is_closure | 415 false); // is_closure |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 423 intptr_t source_uri_index) { | 426 intptr_t source_uri_index) { |
| 424 Script& correct_script = ScriptAt(source_uri_index); | 427 Script& correct_script = ScriptAt(source_uri_index); |
| 425 if (klass.script() != correct_script.raw()) { | 428 if (klass.script() != correct_script.raw()) { |
| 426 // TODO(jensj): We could probably cache this so we don't create | 429 // TODO(jensj): We could probably cache this so we don't create |
| 427 // new PatchClasses all the time | 430 // new PatchClasses all the time |
| 428 return PatchClass::ZoneHandle(Z, PatchClass::New(klass, correct_script)); | 431 return PatchClass::ZoneHandle(Z, PatchClass::New(klass, correct_script)); |
| 429 } | 432 } |
| 430 return klass; | 433 return klass; |
| 431 } | 434 } |
| 432 | 435 |
| 433 Script& KernelReader::ScriptAt(intptr_t source_uri_index) { | 436 Script& KernelReader::ScriptAt(intptr_t source_uri_index, String* import_uri) { |
| 434 Script& script = Script::ZoneHandle(Z); | 437 Script& script = Script::ZoneHandle(Z); |
| 435 script ^= scripts_.At(source_uri_index); | 438 script ^= scripts_.At(source_uri_index); |
| 436 if (script.IsNull()) { | 439 if (script.IsNull()) { |
| 440 // Create script with correct uri(s). | |
| 437 String* uri = program_->source_uri_table().strings()[source_uri_index]; | 441 String* uri = program_->source_uri_table().strings()[source_uri_index]; |
| 438 script = Script::New(H.DartString(uri, Heap::kOld), | 442 dart::String& uri_string = H.DartString(uri, Heap::kOld); |
| 439 dart::String::ZoneHandle(Z), RawScript::kKernelTag); | 443 dart::String& import_uri_string = |
| 444 import_uri == NULL ? uri_string : H.DartString(import_uri, Heap::kOld); | |
| 445 dart::String& source_code = H.DartString( | |
| 446 program_->source_table().SourceFor(source_uri_index), Heap::kOld); | |
| 447 script = Script::New(import_uri_string, uri_string, source_code, | |
| 448 RawScript::kKernelTag); | |
| 440 scripts_.SetAt(source_uri_index, script); | 449 scripts_.SetAt(source_uri_index, script); |
| 450 | |
| 451 // Create line_starts array for the script. | |
| 441 intptr_t* line_starts = | 452 intptr_t* line_starts = |
| 442 program_->line_starting_table().valuesFor(source_uri_index); | 453 program_->source_table().LineStartsFor(source_uri_index); |
| 443 intptr_t line_count = line_starts[0]; | 454 intptr_t line_count = |
| 455 program_->source_table().LineCountFor(source_uri_index); | |
| 444 Array& array_object = Array::Handle(Z, Array::New(line_count, Heap::kOld)); | 456 Array& array_object = Array::Handle(Z, Array::New(line_count, Heap::kOld)); |
| 445 Smi& value = Smi::Handle(Z); | 457 Smi& value = Smi::Handle(Z); |
| 446 for (intptr_t i = 0; i < line_count; ++i) { | 458 for (intptr_t i = 0; i < line_count; ++i) { |
| 447 value = Smi::New(line_starts[i + 1]); | 459 value = Smi::New(line_starts[i]); |
| 448 array_object.SetAt(i, value); | 460 array_object.SetAt(i, value); |
| 449 } | 461 } |
| 450 script.set_line_starts(array_object); | 462 script.set_line_starts(array_object); |
| 451 } | 463 } |
| 452 return script; | 464 return script; |
| 453 } | 465 } |
| 454 | 466 |
| 455 void KernelReader::GenerateFieldAccessors(const dart::Class& klass, | 467 void KernelReader::GenerateFieldAccessors(const dart::Class& klass, |
| 456 const dart::Field& field, | 468 const dart::Field& field, |
| 457 Field* kernel_field) { | 469 Field* kernel_field) { |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 708 initializer_fun.set_is_debuggable(false); | 720 initializer_fun.set_is_debuggable(false); |
| 709 initializer_fun.set_is_reflectable(false); | 721 initializer_fun.set_is_reflectable(false); |
| 710 initializer_fun.set_is_inlinable(false); | 722 initializer_fun.set_is_inlinable(false); |
| 711 return new (zone) ParsedFunction(thread, initializer_fun); | 723 return new (zone) ParsedFunction(thread, initializer_fun); |
| 712 } | 724 } |
| 713 | 725 |
| 714 | 726 |
| 715 } // namespace kernel | 727 } // namespace kernel |
| 716 } // namespace dart | 728 } // namespace dart |
| 717 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 729 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| OLD | NEW |