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