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

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

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

Powered by Google App Engine
This is Rietveld 408576698