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

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

Issue 2512653002: Merge of source position information from kernel-sdk. (Closed)
Patch Set: Changed how GetTokenLocation was called back to original to fix failing failing tests. 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
« no previous file with comments | « runtime/vm/kernel_reader.h ('k') | runtime/vm/kernel_to_il.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 Script& script = 171 Script& script = ScriptAt(kernel_library->source_uri_index());
164 Script::Handle(Z, Script::New(Symbols::KernelScriptUri(),
165 Symbols::Empty(), RawScript::kScriptTag));
166 script.SetLocationOffset(0, 0);
167 script.Tokenize(H.DartString("nop() {}"));
168 dart::Class& toplevel_class = dart::Class::Handle( 172 dart::Class& toplevel_class = dart::Class::Handle(
169 Z, dart::Class::New(library, Symbols::TopLevel(), script, 173 Z, dart::Class::New(library, Symbols::TopLevel(), script,
170 TokenPosition::kNoSource)); 174 TokenPosition::kNoSource));
171 toplevel_class.set_is_cycle_free(); 175 toplevel_class.set_is_cycle_free();
172 library.set_toplevel_class(toplevel_class); 176 library.set_toplevel_class(toplevel_class);
173 if (bootstrapping_) { 177 if (bootstrapping_) {
174 GrowableObjectArray::Handle(Z, I->object_store()->pending_classes()) 178 GrowableObjectArray::Handle(Z, I->object_store()->pending_classes())
175 .Add(toplevel_class, Heap::kOld); 179 .Add(toplevel_class, Heap::kOld);
176 } 180 }
177 181
178 ActiveClassScope active_class_scope(&active_class_, NULL, &toplevel_class); 182 ActiveClassScope active_class_scope(&active_class_, NULL, &toplevel_class);
179 // Load toplevel fields. 183 // Load toplevel fields.
180 for (intptr_t i = 0; i < kernel_library->fields().length(); i++) { 184 for (intptr_t i = 0; i < kernel_library->fields().length(); i++) {
181 Field* kernel_field = kernel_library->fields()[i]; 185 Field* kernel_field = kernel_library->fields()[i];
182 186
183 ActiveMemberScope active_member_scope(&active_class_, kernel_field); 187 ActiveMemberScope active_member_scope(&active_class_, kernel_field);
184 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());
185 dart::Field& field = dart::Field::Handle( 191 dart::Field& field = dart::Field::Handle(
186 Z, dart::Field::NewTopLevel(name, kernel_field->IsFinal(), 192 Z, dart::Field::NewTopLevel(name, kernel_field->IsFinal(),
187 kernel_field->IsConst(), toplevel_class, 193 kernel_field->IsConst(), script_class,
188 TokenPosition::kNoSource)); 194 kernel_field->position()));
189 field.set_kernel_field(kernel_field); 195 field.set_kernel_field(kernel_field);
190 const AbstractType& type = T.TranslateType(kernel_field->type()); 196 const AbstractType& type = T.TranslateType(kernel_field->type());
191 field.SetFieldType(type); 197 field.SetFieldType(type);
192 field.set_has_initializer(kernel_field->initializer() != NULL); 198 field.set_has_initializer(kernel_field->initializer() != NULL);
193 GenerateFieldAccessors(toplevel_class, field, kernel_field); 199 GenerateFieldAccessors(toplevel_class, field, kernel_field);
194 toplevel_class.AddField(field); 200 toplevel_class.AddField(field);
195 library.AddObject(field, name); 201 library.AddObject(field, name);
196 } 202 }
197 203
198 // Load toplevel procedures. 204 // Load toplevel procedures.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } 291 }
286 292
287 293
288 dart::Class& KernelReader::ReadClass(const dart::Library& library, 294 dart::Class& KernelReader::ReadClass(const dart::Library& library,
289 Class* kernel_klass) { 295 Class* kernel_klass) {
290 // This will trigger a call to [ReadPreliminaryClass] if not already done. 296 // This will trigger a call to [ReadPreliminaryClass] if not already done.
291 dart::Class& klass = LookupClass(kernel_klass); 297 dart::Class& klass = LookupClass(kernel_klass);
292 298
293 ActiveClassScope active_class_scope(&active_class_, kernel_klass, &klass); 299 ActiveClassScope active_class_scope(&active_class_, kernel_klass, &klass);
294 300
295 TokenPosition pos(0);
296
297 for (intptr_t i = 0; i < kernel_klass->fields().length(); i++) { 301 for (intptr_t i = 0; i < kernel_klass->fields().length(); i++) {
298 Field* kernel_field = kernel_klass->fields()[i]; 302 Field* kernel_field = kernel_klass->fields()[i];
299 ActiveMemberScope active_member_scope(&active_class_, kernel_field); 303 ActiveMemberScope active_member_scope(&active_class_, kernel_field);
300 304
301 const dart::String& name = H.DartFieldName(kernel_field->name()); 305 const dart::String& name = H.DartFieldName(kernel_field->name());
302 const AbstractType& type = 306 const AbstractType& type =
303 T.TranslateTypeWithoutFinalization(kernel_field->type()); 307 T.TranslateTypeWithoutFinalization(kernel_field->type());
304 dart::Field& field = dart::Field::Handle( 308 dart::Field& field = dart::Field::Handle(
305 Z, dart::Field::New(name, kernel_field->IsStatic(), 309 Z, dart::Field::New(name, kernel_field->IsStatic(),
306 // In the VM all const fields are implicitly final 310 // In the VM all const fields are implicitly final
307 // whereas in Kernel they are not final because they 311 // whereas in Kernel they are not final because they
308 // are not explicitly declared that way. 312 // are not explicitly declared that way.
309 kernel_field->IsFinal() || kernel_field->IsConst(), 313 kernel_field->IsFinal() || kernel_field->IsConst(),
310 kernel_field->IsConst(), 314 kernel_field->IsConst(),
311 false, // is_reflectable 315 false, // is_reflectable
312 klass, type, pos)); 316 klass, type, kernel_field->position()));
313 field.set_kernel_field(kernel_field); 317 field.set_kernel_field(kernel_field);
314 field.set_has_initializer(kernel_field->initializer() != NULL); 318 field.set_has_initializer(kernel_field->initializer() != NULL);
315 GenerateFieldAccessors(klass, field, kernel_field); 319 GenerateFieldAccessors(klass, field, kernel_field);
316 klass.AddField(field); 320 klass.AddField(field);
317 } 321 }
318 322
319 for (intptr_t i = 0; i < kernel_klass->constructors().length(); i++) { 323 for (intptr_t i = 0; i < kernel_klass->constructors().length(); i++) {
320 Constructor* kernel_constructor = kernel_klass->constructors()[i]; 324 Constructor* kernel_constructor = kernel_klass->constructors()[i];
321 ActiveMemberScope active_member_scope(&active_class_, kernel_constructor); 325 ActiveMemberScope active_member_scope(&active_class_, kernel_constructor);
322 ActiveFunctionScope active_function_scope(&active_class_, 326 ActiveFunctionScope active_function_scope(&active_class_,
323 kernel_constructor->function()); 327 kernel_constructor->function());
324 328
325 const dart::String& name = H.DartConstructorName(kernel_constructor); 329 const dart::String& name = H.DartConstructorName(kernel_constructor);
326 Function& function = dart::Function::ZoneHandle( 330 Function& function = dart::Function::ZoneHandle(
327 Z, dart::Function::New(name, RawFunction::kConstructor, 331 Z, dart::Function::New(name, RawFunction::kConstructor,
328 false, // is_static 332 false, // is_static
329 kernel_constructor->IsConst(), 333 kernel_constructor->IsConst(),
330 false, // is_abstract 334 false, // is_abstract
331 kernel_constructor->IsExternal(), 335 kernel_constructor->IsExternal(),
332 false, // is_native 336 false, // is_native
333 klass, pos)); 337 klass, TokenPosition::kNoSource));
334 klass.AddFunction(function); 338 klass.AddFunction(function);
335 function.set_kernel_function(kernel_constructor); 339 function.set_kernel_function(kernel_constructor);
336 function.set_result_type(T.ReceiverType(klass)); 340 function.set_result_type(T.ReceiverType(klass));
337 SetupFunctionParameters(H, T, klass, function, 341 SetupFunctionParameters(H, T, klass, function,
338 kernel_constructor->function(), 342 kernel_constructor->function(),
339 true, // is_method 343 true, // is_method
340 false); // is_closure 344 false); // is_closure
341 } 345 }
342 346
343 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
359 void KernelReader::ReadProcedure(const dart::Library& library, 363 void KernelReader::ReadProcedure(const dart::Library& library,
360 const dart::Class& owner, 364 const dart::Class& owner,
361 Procedure* kernel_procedure, 365 Procedure* kernel_procedure,
362 Class* kernel_klass) { 366 Class* kernel_klass) {
363 ActiveClassScope active_class_scope(&active_class_, kernel_klass, &owner); 367 ActiveClassScope active_class_scope(&active_class_, kernel_klass, &owner);
364 ActiveMemberScope active_member_scope(&active_class_, kernel_procedure); 368 ActiveMemberScope active_member_scope(&active_class_, kernel_procedure);
365 ActiveFunctionScope active_function_scope(&active_class_, 369 ActiveFunctionScope active_function_scope(&active_class_,
366 kernel_procedure->function()); 370 kernel_procedure->function());
367 371
368 const dart::String& name = H.DartProcedureName(kernel_procedure); 372 const dart::String& name = H.DartProcedureName(kernel_procedure);
369 TokenPosition pos(0);
370 bool is_method = kernel_klass != NULL && !kernel_procedure->IsStatic(); 373 bool is_method = kernel_klass != NULL && !kernel_procedure->IsStatic();
371 bool is_abstract = kernel_procedure->IsAbstract(); 374 bool is_abstract = kernel_procedure->IsAbstract();
372 bool is_external = kernel_procedure->IsExternal(); 375 bool is_external = kernel_procedure->IsExternal();
373 dart::String* native_name = NULL; 376 dart::String* native_name = NULL;
374 if (is_external) { 377 if (is_external) {
375 // 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
376 // 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
377 // an ExternalName annotation and extract the string from it. 380 // an ExternalName annotation and extract the string from it.
378 for (int i = 0; i < kernel_procedure->annotations().length(); ++i) { 381 for (int i = 0; i < kernel_procedure->annotations().length(); ++i) {
379 Expression* annotation = kernel_procedure->annotations()[i]; 382 Expression* annotation = kernel_procedure->annotations()[i];
(...skipping 15 matching lines...) Expand all
395 398
396 is_external = false; 399 is_external = false;
397 ASSERT(invocation->arguments()->positional().length() == 1 && 400 ASSERT(invocation->arguments()->positional().length() == 1 &&
398 invocation->arguments()->named().length() == 0); 401 invocation->arguments()->named().length() == 0);
399 StringLiteral* literal = 402 StringLiteral* literal =
400 StringLiteral::Cast(invocation->arguments()->positional()[0]); 403 StringLiteral::Cast(invocation->arguments()->positional()[0]);
401 native_name = &H.DartSymbol(literal->value()); 404 native_name = &H.DartSymbol(literal->value());
402 break; 405 break;
403 } 406 }
404 } 407 }
408 const Object& script_class =
409 ClassForScriptAt(owner, kernel_procedure->source_uri_index());
405 dart::Function& function = dart::Function::ZoneHandle( 410 dart::Function& function = dart::Function::ZoneHandle(
406 Z, Function::New(name, GetFunctionType(kernel_procedure), 411 Z, Function::New(name, GetFunctionType(kernel_procedure),
407 !is_method, // is_static 412 !is_method, // is_static
408 false, // is_const 413 false, // is_const
409 is_abstract, is_external, 414 is_abstract, is_external,
410 native_name != NULL, // is_native 415 native_name != NULL, // is_native
411 owner, pos)); 416 script_class, TokenPosition::kNoSource));
412 owner.AddFunction(function); 417 owner.AddFunction(function);
413 function.set_kernel_function(kernel_procedure); 418 function.set_kernel_function(kernel_procedure);
414 function.set_is_debuggable(false); 419 function.set_is_debuggable(false);
415 if (native_name != NULL) { 420 if (native_name != NULL) {
416 function.set_native_name(*native_name); 421 function.set_native_name(*native_name);
417 } 422 }
418 423
419 SetupFunctionParameters(H, T, owner, function, kernel_procedure->function(), 424 SetupFunctionParameters(H, T, owner, function, kernel_procedure->function(),
420 is_method, 425 is_method,
421 false); // is_closure 426 false); // is_closure
422 427
423 if (kernel_klass == NULL) { 428 if (kernel_klass == NULL) {
424 library.AddObject(function, name); 429 library.AddObject(function, name);
425 ASSERT(!Object::Handle(Z, library.LookupObjectAllowPrivate( 430 ASSERT(!Object::Handle(Z, library.LookupObjectAllowPrivate(
426 H.DartProcedureName(kernel_procedure))) 431 H.DartProcedureName(kernel_procedure)))
427 .IsNull()); 432 .IsNull());
428 } 433 }
429 } 434 }
430 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
431 void KernelReader::GenerateFieldAccessors(const dart::Class& klass, 469 void KernelReader::GenerateFieldAccessors(const dart::Class& klass,
432 const dart::Field& field, 470 const dart::Field& field,
433 Field* kernel_field) { 471 Field* kernel_field) {
434 TokenPosition pos(0);
435
436 if (kernel_field->IsStatic() && kernel_field->initializer() != NULL) { 472 if (kernel_field->IsStatic() && kernel_field->initializer() != NULL) {
437 // 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
438 // 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
439 // sentinel. 475 // sentinel.
440 SimpleExpressionConverter converter(H.thread(), Z); 476 SimpleExpressionConverter converter(H.thread(), Z);
441 if (converter.IsSimple(kernel_field->initializer())) { 477 if (converter.IsSimple(kernel_field->initializer())) {
442 // We do not need a getter. 478 // We do not need a getter.
443 field.SetStaticValue(converter.SimpleValue(), true); 479 field.SetStaticValue(converter.SimpleValue(), true);
444 return; 480 return;
445 } 481 }
446 // We do need a getter that evaluates the initializer if necessary. 482 // We do need a getter that evaluates the initializer if necessary.
447 field.SetStaticValue(Object::sentinel(), true); 483 field.SetStaticValue(Object::sentinel(), true);
448 } 484 }
449 485
450 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());
451 Function& getter = Function::ZoneHandle( 489 Function& getter = Function::ZoneHandle(
452 Z, 490 Z,
453 Function::New( 491 Function::New(
454 getter_name, 492 getter_name,
455 kernel_field->IsStatic() ? RawFunction::kImplicitStaticFinalGetter 493 kernel_field->IsStatic() ? RawFunction::kImplicitStaticFinalGetter
456 : RawFunction::kImplicitGetter, 494 : RawFunction::kImplicitGetter,
457 kernel_field->IsStatic(), 495 kernel_field->IsStatic(),
458 // 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
459 // 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
460 // non-static 498 // non-static
461 // fields that are final. 499 // fields that are final.
462 kernel_field->IsStatic() ? kernel_field->IsConst() 500 kernel_field->IsStatic() ? kernel_field->IsConst()
463 : kernel_field->IsFinal(), 501 : kernel_field->IsFinal(),
464 false, // is_abstract 502 false, // is_abstract
465 false, // is_external 503 false, // is_external
466 false, // is_native 504 false, // is_native
467 klass, pos)); 505 script_class, kernel_field->position()));
468 klass.AddFunction(getter); 506 klass.AddFunction(getter);
469 if (klass.IsTopLevel()) { 507 if (klass.IsTopLevel()) {
470 dart::Library& library = dart::Library::Handle(Z, klass.library()); 508 dart::Library& library = dart::Library::Handle(Z, klass.library());
471 library.AddObject(getter, getter_name); 509 library.AddObject(getter, getter_name);
472 } 510 }
473 getter.set_kernel_function(kernel_field); 511 getter.set_kernel_function(kernel_field);
474 getter.set_result_type(AbstractType::Handle(Z, field.type())); 512 getter.set_result_type(AbstractType::Handle(Z, field.type()));
475 getter.set_is_debuggable(false); 513 getter.set_is_debuggable(false);
476 SetupFieldAccessorFunction(klass, getter); 514 SetupFieldAccessorFunction(klass, getter);
477 515
478 if (!kernel_field->IsStatic() && !kernel_field->IsFinal()) { 516 if (!kernel_field->IsStatic() && !kernel_field->IsFinal()) {
479 // Only static fields can be const. 517 // Only static fields can be const.
480 ASSERT(!kernel_field->IsConst()); 518 ASSERT(!kernel_field->IsConst());
481 const dart::String& setter_name = H.DartSetterName(kernel_field->name()); 519 const dart::String& setter_name = H.DartSetterName(kernel_field->name());
482 Function& setter = Function::ZoneHandle( 520 Function& setter = Function::ZoneHandle(
483 Z, Function::New(setter_name, RawFunction::kImplicitSetter, 521 Z, Function::New(setter_name, RawFunction::kImplicitSetter,
484 false, // is_static 522 false, // is_static
485 false, // is_const 523 false, // is_const
486 false, // is_abstract 524 false, // is_abstract
487 false, // is_external 525 false, // is_external
488 false, // is_native 526 false, // is_native
489 klass, pos)); 527 script_class, kernel_field->position()));
490 klass.AddFunction(setter); 528 klass.AddFunction(setter);
491 setter.set_kernel_function(kernel_field); 529 setter.set_kernel_function(kernel_field);
492 setter.set_result_type(Object::void_type()); 530 setter.set_result_type(Object::void_type());
493 setter.set_is_debuggable(false); 531 setter.set_is_debuggable(false);
494 SetupFieldAccessorFunction(klass, setter); 532 SetupFieldAccessorFunction(klass, setter);
495 } 533 }
496 } 534 }
497 535
498 536
499 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
612 dart::Class& KernelReader::LookupClass(Class* klass) { 650 dart::Class& KernelReader::LookupClass(Class* klass) {
613 dart::Class* handle = NULL; 651 dart::Class* handle = NULL;
614 if (!classes_.Lookup(klass, &handle)) { 652 if (!classes_.Lookup(klass, &handle)) {
615 dart::Library& library = LookupLibrary(klass->parent()); 653 dart::Library& library = LookupLibrary(klass->parent());
616 const dart::String& name = H.DartClassName(klass); 654 const dart::String& name = H.DartClassName(klass);
617 handle = &dart::Class::Handle(Z, library.LookupClass(name)); 655 handle = &dart::Class::Handle(Z, library.LookupClass(name));
618 if (handle->IsNull()) { 656 if (handle->IsNull()) {
619 // 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
620 // will inherit it. The predicate Function::IsOptimizable uses the 658 // will inherit it. The predicate Function::IsOptimizable uses the
621 // 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
622 // optimized. Use a dummy script. 660 // optimized.
623 // 661 Script& script = ScriptAt(klass->source_uri_index());
624 // TODO(27590): We shouldn't need a dummy script per class. At the 662 handle = &dart::Class::Handle(
625 // least we could have a singleton. At best, we'd change IsOptimizable to 663 Z, dart::Class::New(library, name, script, TokenPosition::kNoSource));
626 // detect test functions some other way (like simply not setting the
627 // optimizable bit on those functions in the first place).
628 TokenPosition pos(0);
629 Script& script = Script::Handle(
630 Z, Script::New(Symbols::KernelScriptUri(), Symbols::Empty(),
631 RawScript::kScriptTag));
632 handle =
633 &dart::Class::Handle(Z, dart::Class::New(library, name, script, pos));
634 library.AddClass(*handle); 664 library.AddClass(*handle);
635 } else if (handle->script() == Script::null()) { 665 } else if (handle->script() == Script::null()) {
636 // 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
637 // dummy script. 667 // dummy script.
638 TokenPosition pos(0); 668 Script& script = ScriptAt(klass->source_uri_index());
639 Script& script = Script::Handle(
640 Z, Script::New(Symbols::KernelScriptUri(), Symbols::Empty(),
641 RawScript::kScriptTag));
642 handle->set_script(script); 669 handle->set_script(script);
643 } 670 }
644 // Insert the class in the cache before calling ReadPreliminaryClass so 671 // Insert the class in the cache before calling ReadPreliminaryClass so
645 // we do not risk allocating the class again by calling LookupClass 672 // we do not risk allocating the class again by calling LookupClass
646 // recursively from ReadPreliminaryClass for the same class. 673 // recursively from ReadPreliminaryClass for the same class.
647 classes_.Insert(klass, handle); 674 classes_.Insert(klass, handle);
648 if (!handle->is_type_finalized()) { 675 if (!handle->is_type_finalized()) {
649 ReadPreliminaryClass(handle, klass); 676 ReadPreliminaryClass(handle, klass);
650 } 677 }
651 } 678 }
(...skipping 15 matching lines...) Expand all
667 } else { 694 } else {
668 ASSERT(0 <= kind && kind <= Procedure::kFactory); 695 ASSERT(0 <= kind && kind <= Procedure::kFactory);
669 return static_cast<RawFunction::Kind>(lookuptable[kind]); 696 return static_cast<RawFunction::Kind>(lookuptable[kind]);
670 } 697 }
671 } 698 }
672 699
673 700
674 } // namespace kernel 701 } // namespace kernel
675 } // namespace dart 702 } // namespace dart
676 #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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698