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

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

Issue 2512653002: Merge of source position information from kernel-sdk. (Closed)
Patch Set: Created 4 years, 1 month 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 RawLibrary* BuildingTranslationHelper::LookupLibraryByKernelLibrary( 86 RawLibrary* BuildingTranslationHelper::LookupLibraryByKernelLibrary(
87 Library* library) { 87 Library* library) {
88 return reader_->LookupLibrary(library).raw(); 88 return reader_->LookupLibrary(library).raw();
89 } 89 }
90 90
91 91
92 RawClass* BuildingTranslationHelper::LookupClassByKernelClass(Class* klass) { 92 RawClass* BuildingTranslationHelper::LookupClassByKernelClass(Class* klass) {
93 return reader_->LookupClass(klass).raw(); 93 return reader_->LookupClass(klass).raw();
94 } 94 }
95 95
96 Program* KernelReader::ReadPrecompiledProgram() {
97 Program* program = ReadPrecompiledKernelFromBuffer(buffer_, buffer_length_);
98 if (program == NULL) return NULL;
99 intptr_t source_file_count = program->line_starting_table().size();
100 scripts_ = Array::New(source_file_count);
101 program_ = program;
102 return program;
103 }
96 104
97 Object& KernelReader::ReadProgram() { 105 Object& KernelReader::ReadProgram() {
98 ASSERT(!bootstrapping_); 106 ASSERT(!bootstrapping_);
99 Program* program = ReadPrecompiledKernelFromBuffer(buffer_, buffer_length_); 107 Program* program = ReadPrecompiledProgram();
100 if (program == NULL) { 108 if (program == NULL) {
101 const dart::String& error = H.DartString("Failed to read .kernell file"); 109 const dart::String& error = H.DartString("Failed to read .kernell file");
102 return Object::Handle(Z, ApiError::New(error)); 110 return Object::Handle(Z, ApiError::New(error));
103 } 111 }
104 112
105 LongJumpScope jump; 113 LongJumpScope jump;
106 if (setjmp(*jump.Set()) == 0) { 114 if (setjmp(*jump.Set()) == 0) {
107 Procedure* main = program->main_method(); 115 Procedure* main = program->main_method();
108 Library* kernel_main_library = Library::Cast(main->parent()); 116 Library* kernel_main_library = Library::Cast(main->parent());
109 117
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // The bootstrapper will take care of creating the native wrapper classes, but 161 // The bootstrapper will take care of creating the native wrapper classes, but
154 // we will add the synthetic constructors to them here. 162 // we will add the synthetic constructors to them here.
155 if (library.name() == 163 if (library.name() ==
156 Symbols::Symbol(Symbols::kDartNativeWrappersLibNameId).raw()) { 164 Symbols::Symbol(Symbols::kDartNativeWrappersLibNameId).raw()) {
157 ASSERT(library.LoadInProgress()); 165 ASSERT(library.LoadInProgress());
158 } else { 166 } else {
159 library.SetLoadInProgress(); 167 library.SetLoadInProgress();
160 } 168 }
161 // Setup toplevel class (which contains library fields/procedures). 169 // Setup toplevel class (which contains library fields/procedures).
162 170
163 // TODO(27590): Figure out why we need this script stuff here. 171 Script& script = ScriptAt(kernel_library->source_uri_index());
164 Script& script = Script::Handle(
165 Z,
166 Script::New(H.DartString(""), H.DartString(""), RawScript::kScriptTag));
167 script.SetLocationOffset(0, 0);
168 script.Tokenize(H.DartString("nop() {}"));
169 dart::Class& toplevel_class = dart::Class::Handle( 172 dart::Class& toplevel_class = dart::Class::Handle(
170 Z, dart::Class::New(library, Symbols::TopLevel(), script, 173 Z, dart::Class::New(library, Symbols::TopLevel(), script,
171 TokenPosition::kNoSource)); 174 TokenPosition::kNoSource));
172 toplevel_class.set_is_cycle_free(); 175 toplevel_class.set_is_cycle_free();
173 library.set_toplevel_class(toplevel_class); 176 library.set_toplevel_class(toplevel_class);
174 if (bootstrapping_) { 177 if (bootstrapping_) {
175 GrowableObjectArray::Handle(Z, I->object_store()->pending_classes()) 178 GrowableObjectArray::Handle(Z, I->object_store()->pending_classes())
176 .Add(toplevel_class, Heap::kOld); 179 .Add(toplevel_class, Heap::kOld);
177 } 180 }
178 181
179 ActiveClassScope active_class_scope(&active_class_, NULL, &toplevel_class); 182 ActiveClassScope active_class_scope(&active_class_, NULL, &toplevel_class);
180 // Load toplevel fields. 183 // Load toplevel fields.
181 for (intptr_t i = 0; i < kernel_library->fields().length(); i++) { 184 for (intptr_t i = 0; i < kernel_library->fields().length(); i++) {
182 Field* kernel_field = kernel_library->fields()[i]; 185 Field* kernel_field = kernel_library->fields()[i];
183 186
184 ActiveMemberScope active_member_scope(&active_class_, kernel_field); 187 ActiveMemberScope active_member_scope(&active_class_, kernel_field);
185 const dart::String& name = H.DartFieldName(kernel_field->name()); 188 const dart::String& name = H.DartFieldName(kernel_field->name());
189 const Object& script_class =
190 ClassForScriptAt(toplevel_class, kernel_field->source_uri_index());
186 dart::Field& field = dart::Field::Handle( 191 dart::Field& field = dart::Field::Handle(
187 Z, dart::Field::NewTopLevel(name, kernel_field->IsFinal(), 192 Z, dart::Field::NewTopLevel(name, kernel_field->IsFinal(),
188 kernel_field->IsConst(), toplevel_class, 193 kernel_field->IsConst(), script_class,
189 TokenPosition::kNoSource)); 194 kernel_field->position()));
190 field.set_kernel_field(kernel_field); 195 field.set_kernel_field(kernel_field);
191 const AbstractType& type = T.TranslateType(kernel_field->type()); 196 const AbstractType& type = T.TranslateType(kernel_field->type());
192 field.SetFieldType(type); 197 field.SetFieldType(type);
193 field.set_has_initializer(kernel_field->initializer() != NULL); 198 field.set_has_initializer(kernel_field->initializer() != NULL);
194 GenerateFieldAccessors(toplevel_class, field, kernel_field); 199 GenerateFieldAccessors(toplevel_class, field, kernel_field);
195 toplevel_class.AddField(field); 200 toplevel_class.AddField(field);
196 library.AddObject(field, name); 201 library.AddObject(field, name);
197 } 202 }
198 203
199 // Load toplevel procedures. 204 // Load toplevel procedures.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 291 }
287 292
288 293
289 dart::Class& KernelReader::ReadClass(const dart::Library& library, 294 dart::Class& KernelReader::ReadClass(const dart::Library& library,
290 Class* kernel_klass) { 295 Class* kernel_klass) {
291 // This will trigger a call to [ReadPreliminaryClass] if not already done. 296 // This will trigger a call to [ReadPreliminaryClass] if not already done.
292 dart::Class& klass = LookupClass(kernel_klass); 297 dart::Class& klass = LookupClass(kernel_klass);
293 298
294 ActiveClassScope active_class_scope(&active_class_, kernel_klass, &klass); 299 ActiveClassScope active_class_scope(&active_class_, kernel_klass, &klass);
295 300
296 TokenPosition pos(0);
297
298 for (intptr_t i = 0; i < kernel_klass->fields().length(); i++) { 301 for (intptr_t i = 0; i < kernel_klass->fields().length(); i++) {
299 Field* kernel_field = kernel_klass->fields()[i]; 302 Field* kernel_field = kernel_klass->fields()[i];
300 ActiveMemberScope active_member_scope(&active_class_, kernel_field); 303 ActiveMemberScope active_member_scope(&active_class_, kernel_field);
301 304
302 const dart::String& name = H.DartFieldName(kernel_field->name()); 305 const dart::String& name = H.DartFieldName(kernel_field->name());
303 const AbstractType& type = 306 const AbstractType& type =
304 T.TranslateTypeWithoutFinalization(kernel_field->type()); 307 T.TranslateTypeWithoutFinalization(kernel_field->type());
305 dart::Field& field = dart::Field::Handle( 308 dart::Field& field = dart::Field::Handle(
306 Z, dart::Field::New(name, kernel_field->IsStatic(), 309 Z, dart::Field::New(name, kernel_field->IsStatic(),
307 // In the VM all const fields are implicitly final 310 // In the VM all const fields are implicitly final
308 // whereas in Kernel they are not final because they 311 // whereas in Kernel they are not final because they
309 // are not explicitly declared that way. 312 // are not explicitly declared that way.
310 kernel_field->IsFinal() || kernel_field->IsConst(), 313 kernel_field->IsFinal() || kernel_field->IsConst(),
311 kernel_field->IsConst(), 314 kernel_field->IsConst(),
312 false, // is_reflectable 315 false, // is_reflectable
313 klass, type, pos)); 316 klass, type, kernel_field->position()));
314 field.set_kernel_field(kernel_field); 317 field.set_kernel_field(kernel_field);
315 field.set_has_initializer(kernel_field->initializer() != NULL); 318 field.set_has_initializer(kernel_field->initializer() != NULL);
316 GenerateFieldAccessors(klass, field, kernel_field); 319 GenerateFieldAccessors(klass, field, kernel_field);
317 klass.AddField(field); 320 klass.AddField(field);
318 } 321 }
319 322
320 for (intptr_t i = 0; i < kernel_klass->constructors().length(); i++) { 323 for (intptr_t i = 0; i < kernel_klass->constructors().length(); i++) {
321 Constructor* kernel_constructor = kernel_klass->constructors()[i]; 324 Constructor* kernel_constructor = kernel_klass->constructors()[i];
322 ActiveMemberScope active_member_scope(&active_class_, kernel_constructor); 325 ActiveMemberScope active_member_scope(&active_class_, kernel_constructor);
323 ActiveFunctionScope active_function_scope(&active_class_, 326 ActiveFunctionScope active_function_scope(&active_class_,
324 kernel_constructor->function()); 327 kernel_constructor->function());
325 328
326 const dart::String& name = H.DartConstructorName(kernel_constructor); 329 const dart::String& name = H.DartConstructorName(kernel_constructor);
327 Function& function = dart::Function::ZoneHandle( 330 Function& function = dart::Function::ZoneHandle(
328 Z, dart::Function::New(name, RawFunction::kConstructor, 331 Z, dart::Function::New(name, RawFunction::kConstructor,
329 false, // is_static 332 false, // is_static
330 kernel_constructor->IsConst(), 333 kernel_constructor->IsConst(),
331 false, // is_abstract 334 false, // is_abstract
332 kernel_constructor->IsExternal(), 335 kernel_constructor->IsExternal(),
333 false, // is_native 336 false, // is_native
334 klass, pos)); 337 klass, TokenPosition::kNoSource));
335 klass.AddFunction(function); 338 klass.AddFunction(function);
336 function.set_kernel_function(kernel_constructor); 339 function.set_kernel_function(kernel_constructor);
337 function.set_result_type(T.ReceiverType(klass)); 340 function.set_result_type(T.ReceiverType(klass));
338 SetupFunctionParameters(H, T, klass, function, 341 SetupFunctionParameters(H, T, klass, function,
339 kernel_constructor->function(), 342 kernel_constructor->function(),
340 true, // is_method 343 true, // is_method
341 false); // is_closure 344 false); // is_closure
342 } 345 }
343 346
344 for (intptr_t i = 0; i < kernel_klass->procedures().length(); i++) { 347 for (intptr_t i = 0; i < kernel_klass->procedures().length(); i++) {
(...skipping 15 matching lines...) Expand all
360 void KernelReader::ReadProcedure(const dart::Library& library, 363 void KernelReader::ReadProcedure(const dart::Library& library,
361 const dart::Class& owner, 364 const dart::Class& owner,
362 Procedure* kernel_procedure, 365 Procedure* kernel_procedure,
363 Class* kernel_klass) { 366 Class* kernel_klass) {
364 ActiveClassScope active_class_scope(&active_class_, kernel_klass, &owner); 367 ActiveClassScope active_class_scope(&active_class_, kernel_klass, &owner);
365 ActiveMemberScope active_member_scope(&active_class_, kernel_procedure); 368 ActiveMemberScope active_member_scope(&active_class_, kernel_procedure);
366 ActiveFunctionScope active_function_scope(&active_class_, 369 ActiveFunctionScope active_function_scope(&active_class_,
367 kernel_procedure->function()); 370 kernel_procedure->function());
368 371
369 const dart::String& name = H.DartProcedureName(kernel_procedure); 372 const dart::String& name = H.DartProcedureName(kernel_procedure);
370 TokenPosition pos(0);
371 bool is_method = kernel_klass != NULL && !kernel_procedure->IsStatic(); 373 bool is_method = kernel_klass != NULL && !kernel_procedure->IsStatic();
372 bool is_abstract = kernel_procedure->IsAbstract(); 374 bool is_abstract = kernel_procedure->IsAbstract();
373 bool is_external = kernel_procedure->IsExternal(); 375 bool is_external = kernel_procedure->IsExternal();
374 dart::String* native_name = NULL; 376 dart::String* native_name = NULL;
375 if (is_external) { 377 if (is_external) {
376 // Maybe it has a native implementation, which is not external as far as 378 // Maybe it has a native implementation, which is not external as far as
377 // the VM is concerned because it does have an implementation. Check for 379 // the VM is concerned because it does have an implementation. Check for
378 // an ExternalName annotation and extract the string from it. 380 // an ExternalName annotation and extract the string from it.
379 for (int i = 0; i < kernel_procedure->annotations().length(); ++i) { 381 for (int i = 0; i < kernel_procedure->annotations().length(); ++i) {
380 Expression* annotation = kernel_procedure->annotations()[i]; 382 Expression* annotation = kernel_procedure->annotations()[i];
(...skipping 15 matching lines...) Expand all
396 398
397 is_external = false; 399 is_external = false;
398 ASSERT(invocation->arguments()->positional().length() == 1 && 400 ASSERT(invocation->arguments()->positional().length() == 1 &&
399 invocation->arguments()->named().length() == 0); 401 invocation->arguments()->named().length() == 0);
400 StringLiteral* literal = 402 StringLiteral* literal =
401 StringLiteral::Cast(invocation->arguments()->positional()[0]); 403 StringLiteral::Cast(invocation->arguments()->positional()[0]);
402 native_name = &H.DartSymbol(literal->value()); 404 native_name = &H.DartSymbol(literal->value());
403 break; 405 break;
404 } 406 }
405 } 407 }
408 const Object& script_class =
409 ClassForScriptAt(owner, kernel_procedure->source_uri_index());
406 dart::Function& function = dart::Function::ZoneHandle( 410 dart::Function& function = dart::Function::ZoneHandle(
407 Z, Function::New(name, GetFunctionType(kernel_procedure), 411 Z, Function::New(name, GetFunctionType(kernel_procedure),
408 !is_method, // is_static 412 !is_method, // is_static
409 false, // is_const 413 false, // is_const
410 is_abstract, is_external, 414 is_abstract, is_external,
411 native_name != NULL, // is_native 415 native_name != NULL, // is_native
412 owner, pos)); 416 script_class, TokenPosition::kNoSource));
413 owner.AddFunction(function); 417 owner.AddFunction(function);
414 function.set_kernel_function(kernel_procedure); 418 function.set_kernel_function(kernel_procedure);
415 function.set_is_debuggable(false); 419 function.set_is_debuggable(false);
416 if (native_name != NULL) { 420 if (native_name != NULL) {
417 function.set_native_name(*native_name); 421 function.set_native_name(*native_name);
418 } 422 }
419 423
420 SetupFunctionParameters(H, T, owner, function, kernel_procedure->function(), 424 SetupFunctionParameters(H, T, owner, function, kernel_procedure->function(),
421 is_method, 425 is_method,
422 false); // is_closure 426 false); // is_closure
423 427
424 if (kernel_klass == NULL) { 428 if (kernel_klass == NULL) {
425 library.AddObject(function, name); 429 library.AddObject(function, name);
426 ASSERT(!Object::Handle(Z, library.LookupObjectAllowPrivate( 430 ASSERT(!Object::Handle(Z, library.LookupObjectAllowPrivate(
427 H.DartProcedureName(kernel_procedure))) 431 H.DartProcedureName(kernel_procedure)))
428 .IsNull()); 432 .IsNull());
429 } 433 }
430 } 434 }
431 435
436 const Object& KernelReader::ClassForScriptAt(const dart::Class& klass,
437 intptr_t source_uri_index) {
438 Script& correct_script = ScriptAt(source_uri_index);
439 if (klass.script() != correct_script.raw()) {
440 // TODO(jensj): We could probably cache this so we don't create
441 // new PatchClasses all the time
442 return PatchClass::ZoneHandle(Z, PatchClass::New(klass, correct_script));
443 }
444 return klass;
445 }
446
447 Script& KernelReader::ScriptAt(intptr_t source_uri_index) {
448 Script& script = Script::ZoneHandle(Z);
449 script ^= scripts_.At(source_uri_index);
450 if (script.IsNull()) {
451 String* uri = program_->source_uri_table().strings()[source_uri_index];
452 script = Script::New(H.DartString(uri), dart::String::ZoneHandle(Z),
453 RawScript::kKernelTag);
454 scripts_.SetAt(source_uri_index, script);
455 intptr_t* line_starts =
456 program_->line_starting_table().valuesFor(source_uri_index);
457 intptr_t line_count = line_starts[0];
458 Array& array_object = Array::Handle(Z, Array::New(line_count));
459 Smi& value = Smi::Handle(Z);
460 for (intptr_t i = 0; i < line_count; ++i) {
461 value = Smi::New(line_starts[i + 1]);
462 array_object.SetAt(i, value);
463 }
464 script.set_line_starts(array_object);
465 }
466 return script;
467 }
468
432 void KernelReader::GenerateFieldAccessors(const dart::Class& klass, 469 void KernelReader::GenerateFieldAccessors(const dart::Class& klass,
433 const dart::Field& field, 470 const dart::Field& field,
434 Field* kernel_field) { 471 Field* kernel_field) {
435 TokenPosition pos(0);
436
437 if (kernel_field->IsStatic() && kernel_field->initializer() != NULL) { 472 if (kernel_field->IsStatic() && kernel_field->initializer() != NULL) {
438 // Static fields with initializers either have the static value set to the 473 // Static fields with initializers either have the static value set to the
439 // initializer value if it is simple enough or else set to an uninitialized 474 // initializer value if it is simple enough or else set to an uninitialized
440 // sentinel. 475 // sentinel.
441 SimpleExpressionConverter converter(H.thread(), Z); 476 SimpleExpressionConverter converter(H.thread(), Z);
442 if (converter.IsSimple(kernel_field->initializer())) { 477 if (converter.IsSimple(kernel_field->initializer())) {
443 // We do not need a getter. 478 // We do not need a getter.
444 field.SetStaticValue(converter.SimpleValue(), true); 479 field.SetStaticValue(converter.SimpleValue(), true);
445 return; 480 return;
446 } 481 }
447 // We do need a getter that evaluates the initializer if necessary. 482 // We do need a getter that evaluates the initializer if necessary.
448 field.SetStaticValue(Object::sentinel(), true); 483 field.SetStaticValue(Object::sentinel(), true);
449 } 484 }
450 485
451 const dart::String& getter_name = H.DartGetterName(kernel_field->name()); 486 const dart::String& getter_name = H.DartGetterName(kernel_field->name());
487 const Object& script_class =
488 ClassForScriptAt(klass, kernel_field->source_uri_index());
452 Function& getter = Function::ZoneHandle( 489 Function& getter = Function::ZoneHandle(
453 Z, 490 Z,
454 Function::New( 491 Function::New(
455 getter_name, 492 getter_name,
456 kernel_field->IsStatic() ? RawFunction::kImplicitStaticFinalGetter 493 kernel_field->IsStatic() ? RawFunction::kImplicitStaticFinalGetter
457 : RawFunction::kImplicitGetter, 494 : RawFunction::kImplicitGetter,
458 kernel_field->IsStatic(), 495 kernel_field->IsStatic(),
459 // The functions created by the parser have is_const for static fields 496 // The functions created by the parser have is_const for static fields
460 // that are const (not just final) and they have is_const for 497 // that are const (not just final) and they have is_const for
461 // non-static 498 // non-static
462 // fields that are final. 499 // fields that are final.
463 kernel_field->IsStatic() ? kernel_field->IsConst() 500 kernel_field->IsStatic() ? kernel_field->IsConst()
464 : kernel_field->IsFinal(), 501 : kernel_field->IsFinal(),
465 false, // is_abstract 502 false, // is_abstract
466 false, // is_external 503 false, // is_external
467 false, // is_native 504 false, // is_native
468 klass, pos)); 505 script_class, kernel_field->position()));
469 klass.AddFunction(getter); 506 klass.AddFunction(getter);
470 if (klass.IsTopLevel()) { 507 if (klass.IsTopLevel()) {
471 dart::Library& library = dart::Library::Handle(Z, klass.library()); 508 dart::Library& library = dart::Library::Handle(Z, klass.library());
472 library.AddObject(getter, getter_name); 509 library.AddObject(getter, getter_name);
473 } 510 }
474 getter.set_kernel_function(kernel_field); 511 getter.set_kernel_function(kernel_field);
475 getter.set_result_type(AbstractType::Handle(Z, field.type())); 512 getter.set_result_type(AbstractType::Handle(Z, field.type()));
476 getter.set_is_debuggable(false); 513 getter.set_is_debuggable(false);
477 SetupFieldAccessorFunction(klass, getter); 514 SetupFieldAccessorFunction(klass, getter);
478 515
479 if (!kernel_field->IsStatic() && !kernel_field->IsFinal()) { 516 if (!kernel_field->IsStatic() && !kernel_field->IsFinal()) {
480 // Only static fields can be const. 517 // Only static fields can be const.
481 ASSERT(!kernel_field->IsConst()); 518 ASSERT(!kernel_field->IsConst());
482 const dart::String& setter_name = H.DartSetterName(kernel_field->name()); 519 const dart::String& setter_name = H.DartSetterName(kernel_field->name());
483 Function& setter = Function::ZoneHandle( 520 Function& setter = Function::ZoneHandle(
484 Z, Function::New(setter_name, RawFunction::kImplicitSetter, 521 Z, Function::New(setter_name, RawFunction::kImplicitSetter,
485 false, // is_static 522 false, // is_static
486 false, // is_const 523 false, // is_const
487 false, // is_abstract 524 false, // is_abstract
488 false, // is_external 525 false, // is_external
489 false, // is_native 526 false, // is_native
490 klass, pos)); 527 script_class, kernel_field->position()));
491 klass.AddFunction(setter); 528 klass.AddFunction(setter);
492 setter.set_kernel_function(kernel_field); 529 setter.set_kernel_function(kernel_field);
493 setter.set_result_type(Object::void_type()); 530 setter.set_result_type(Object::void_type());
494 setter.set_is_debuggable(false); 531 setter.set_is_debuggable(false);
495 SetupFieldAccessorFunction(klass, setter); 532 SetupFieldAccessorFunction(klass, setter);
496 } 533 }
497 } 534 }
498 535
499 536
500 void KernelReader::SetupFunctionParameters(TranslationHelper translation_helper, 537 void KernelReader::SetupFunctionParameters(TranslationHelper translation_helper,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 dart::Class& KernelReader::LookupClass(Class* klass) { 650 dart::Class& KernelReader::LookupClass(Class* klass) {
614 dart::Class* handle = NULL; 651 dart::Class* handle = NULL;
615 if (!classes_.Lookup(klass, &handle)) { 652 if (!classes_.Lookup(klass, &handle)) {
616 dart::Library& library = LookupLibrary(klass->parent()); 653 dart::Library& library = LookupLibrary(klass->parent());
617 const dart::String& name = H.DartClassName(klass); 654 const dart::String& name = H.DartClassName(klass);
618 handle = &dart::Class::Handle(Z, library.LookupClass(name)); 655 handle = &dart::Class::Handle(Z, library.LookupClass(name));
619 if (handle->IsNull()) { 656 if (handle->IsNull()) {
620 // The class needs to have a script because all the functions in the class 657 // The class needs to have a script because all the functions in the class
621 // will inherit it. The predicate Function::IsOptimizable uses the 658 // will inherit it. The predicate Function::IsOptimizable uses the
622 // absence of a script to detect test functions that should not be 659 // absence of a script to detect test functions that should not be
623 // optimized. Use a dummy script. 660 // optimized.
624 // 661 Script& script = ScriptAt(klass->source_uri_index());
625 // TODO(27590): We shouldn't need a dummy script per class. At the 662 handle = &dart::Class::Handle(
626 // least we could have a singleton. At best, we'd change IsOptimizable to 663 Z, dart::Class::New(library, name, script, TokenPosition::kNoSource));
627 // detect test functions some other way (like simply not setting the
628 // optimizable bit on those functions in the first place).
629 TokenPosition pos(0);
630 Script& script =
631 Script::Handle(Z, Script::New(H.DartString(""), H.DartString(""),
632 RawScript::kScriptTag));
633 handle =
634 &dart::Class::Handle(Z, dart::Class::New(library, name, script, pos));
635 library.AddClass(*handle); 664 library.AddClass(*handle);
636 } else if (handle->script() == Script::null()) { 665 } else if (handle->script() == Script::null()) {
637 // When bootstrapping we can encounter classes that do not yet have a 666 // When bootstrapping we can encounter classes that do not yet have a
638 // dummy script. 667 // dummy script.
639 TokenPosition pos(0); 668 Script& script = ScriptAt(klass->source_uri_index());
640 Script& script =
641 Script::Handle(Z, Script::New(H.DartString(""), H.DartString(""),
642 RawScript::kScriptTag));
643 handle->set_script(script); 669 handle->set_script(script);
644 } 670 }
645 // Insert the class in the cache before calling ReadPreliminaryClass so 671 // Insert the class in the cache before calling ReadPreliminaryClass so
646 // we do not risk allocating the class again by calling LookupClass 672 // we do not risk allocating the class again by calling LookupClass
647 // recursively from ReadPreliminaryClass for the same class. 673 // recursively from ReadPreliminaryClass for the same class.
648 classes_.Insert(klass, handle); 674 classes_.Insert(klass, handle);
649 if (!handle->is_type_finalized()) { 675 if (!handle->is_type_finalized()) {
650 ReadPreliminaryClass(handle, klass); 676 ReadPreliminaryClass(handle, klass);
651 } 677 }
652 } 678 }
(...skipping 15 matching lines...) Expand all
668 } else { 694 } else {
669 ASSERT(0 <= kind && kind <= Procedure::kFactory); 695 ASSERT(0 <= kind && kind <= Procedure::kFactory);
670 return static_cast<RawFunction::Kind>(lookuptable[kind]); 696 return static_cast<RawFunction::Kind>(lookuptable[kind]);
671 } 697 }
672 } 698 }
673 699
674 700
675 } // namespace kernel 701 } // namespace kernel
676 } // namespace dart 702 } // namespace dart
677 #endif // !defined(DART_PRECOMPILED_RUNTIME) 703 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « runtime/vm/kernel_reader.h ('k') | runtime/vm/kernel_to_il.h » ('j') | runtime/vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698