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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 ReadLibrary(kernel_library); | 127 ReadLibrary(kernel_library); |
128 } | 128 } |
129 | 129 |
130 for (intptr_t i = 0; i < length; i++) { | 130 for (intptr_t i = 0; i < length; i++) { |
131 dart::Library& library = | 131 dart::Library& library = |
132 LookupLibrary(program_->libraries()[i]->canonical_name()); | 132 LookupLibrary(program_->libraries()[i]->canonical_name()); |
133 if (!library.Loaded()) library.SetLoaded(); | 133 if (!library.Loaded()) library.SetLoaded(); |
134 } | 134 } |
135 | 135 |
136 if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) { | 136 if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) { |
137 CanonicalName* main = program_->main_method(); | 137 Procedure* main = program_->main_method(); |
138 dart::Library& library = LookupLibrary(main->EnclosingName()); | 138 Library* kernel_main_library = Library::Cast(main->parent()); |
| 139 dart::Library& library = |
| 140 LookupLibrary(kernel_main_library->canonical_name()); |
139 | 141 |
140 // Sanity check that we can find the main entrypoint. | 142 // Sanity check that we can find the main entrypoint. |
141 Object& main_obj = Object::Handle( | 143 Object& main_obj = Object::Handle( |
142 Z, library.LookupObjectAllowPrivate(H.DartSymbol("main"))); | 144 Z, library.LookupObjectAllowPrivate(H.DartSymbol("main"))); |
143 ASSERT(!main_obj.IsNull()); | 145 ASSERT(!main_obj.IsNull()); |
144 return library; | 146 return library; |
145 } | 147 } |
146 } | 148 } |
147 | 149 |
148 // Either class finalization failed or we caught a compile error. | 150 // Either class finalization failed or we caught a compile error. |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 } | 353 } |
352 klass.AddFields(fields_); | 354 klass.AddFields(fields_); |
353 } | 355 } |
354 | 356 |
355 for (intptr_t i = 0; i < kernel_klass->constructors().length(); i++) { | 357 for (intptr_t i = 0; i < kernel_klass->constructors().length(); i++) { |
356 Constructor* kernel_constructor = kernel_klass->constructors()[i]; | 358 Constructor* kernel_constructor = kernel_klass->constructors()[i]; |
357 ActiveMemberScope active_member_scope(&active_class_, kernel_constructor); | 359 ActiveMemberScope active_member_scope(&active_class_, kernel_constructor); |
358 ActiveFunctionScope active_function_scope(&active_class_, | 360 ActiveFunctionScope active_function_scope(&active_class_, |
359 kernel_constructor->function()); | 361 kernel_constructor->function()); |
360 | 362 |
361 const dart::String& name = | 363 const dart::String& name = H.DartConstructorName(kernel_constructor); |
362 H.DartConstructorName(kernel_constructor->canonical_name()); | |
363 Function& function = dart::Function::ZoneHandle( | 364 Function& function = dart::Function::ZoneHandle( |
364 Z, dart::Function::New(name, RawFunction::kConstructor, | 365 Z, dart::Function::New(name, RawFunction::kConstructor, |
365 false, // is_static | 366 false, // is_static |
366 kernel_constructor->IsConst(), | 367 kernel_constructor->IsConst(), |
367 false, // is_abstract | 368 false, // is_abstract |
368 kernel_constructor->IsExternal(), | 369 kernel_constructor->IsExternal(), |
369 false, // is_native | 370 false, // is_native |
370 klass, kernel_constructor->position())); | 371 klass, kernel_constructor->position())); |
371 function.set_end_token_pos(kernel_constructor->end_position()); | 372 function.set_end_token_pos(kernel_constructor->end_position()); |
372 functions_.Add(&function); | 373 functions_.Add(&function); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 407 |
407 void KernelReader::ReadProcedure(const dart::Library& library, | 408 void KernelReader::ReadProcedure(const dart::Library& library, |
408 const dart::Class& owner, | 409 const dart::Class& owner, |
409 Procedure* kernel_procedure, | 410 Procedure* kernel_procedure, |
410 Class* kernel_klass) { | 411 Class* kernel_klass) { |
411 ActiveClassScope active_class_scope(&active_class_, kernel_klass, &owner); | 412 ActiveClassScope active_class_scope(&active_class_, kernel_klass, &owner); |
412 ActiveMemberScope active_member_scope(&active_class_, kernel_procedure); | 413 ActiveMemberScope active_member_scope(&active_class_, kernel_procedure); |
413 ActiveFunctionScope active_function_scope(&active_class_, | 414 ActiveFunctionScope active_function_scope(&active_class_, |
414 kernel_procedure->function()); | 415 kernel_procedure->function()); |
415 | 416 |
416 const dart::String& name = | 417 const dart::String& name = H.DartProcedureName(kernel_procedure); |
417 H.DartProcedureName(kernel_procedure->canonical_name()); | |
418 bool is_method = kernel_klass != NULL && !kernel_procedure->IsStatic(); | 418 bool is_method = kernel_klass != NULL && !kernel_procedure->IsStatic(); |
419 bool is_abstract = kernel_procedure->IsAbstract(); | 419 bool is_abstract = kernel_procedure->IsAbstract(); |
420 bool is_external = kernel_procedure->IsExternal(); | 420 bool is_external = kernel_procedure->IsExternal(); |
421 dart::String* native_name = NULL; | 421 dart::String* native_name = NULL; |
422 if (is_external) { | 422 if (is_external) { |
423 // Maybe it has a native implementation, which is not external as far as | 423 // Maybe it has a native implementation, which is not external as far as |
424 // the VM is concerned because it does have an implementation. Check for | 424 // the VM is concerned because it does have an implementation. Check for |
425 // an ExternalName annotation and extract the string from it. | 425 // an ExternalName annotation and extract the string from it. |
426 for (int i = 0; i < kernel_procedure->annotations().length(); ++i) { | 426 for (int i = 0; i < kernel_procedure->annotations().length(); ++i) { |
427 Expression* annotation = kernel_procedure->annotations()[i]; | 427 Expression* annotation = kernel_procedure->annotations()[i]; |
428 if (!annotation->IsConstructorInvocation()) continue; | 428 if (!annotation->IsConstructorInvocation()) continue; |
429 ConstructorInvocation* invocation = | 429 ConstructorInvocation* invocation = |
430 ConstructorInvocation::Cast(annotation); | 430 ConstructorInvocation::Cast(annotation); |
431 CanonicalName* annotation_class = invocation->target()->EnclosingName(); | 431 Class* annotation_class = Class::Cast(invocation->target()->parent()); |
432 ASSERT(annotation_class->IsClass()); | |
433 String* class_name = annotation_class->name(); | 432 String* class_name = annotation_class->name(); |
434 // Just compare by name, do not generate the annotation class. | 433 // Just compare by name, do not generate the annotation class. |
435 int length = sizeof("ExternalName") - 1; | 434 int length = sizeof("ExternalName") - 1; |
436 if (class_name->size() != length) continue; | 435 if (class_name->size() != length) continue; |
437 if (memcmp(class_name->buffer(), "ExternalName", length) != 0) continue; | 436 if (memcmp(class_name->buffer(), "ExternalName", length) != 0) continue; |
438 ASSERT(annotation_class->parent()->IsLibrary()); | |
439 String* library_name = annotation_class->parent()->name(); | 437 String* library_name = annotation_class->parent()->name(); |
440 length = sizeof("dart:_internal") - 1; | 438 length = sizeof("dart._internal") - 1; |
441 if (library_name->size() != length) continue; | 439 if (library_name->size() != length) continue; |
442 if (memcmp(library_name->buffer(), "dart:_internal", length) != 0) { | 440 if (memcmp(library_name->buffer(), "dart._internal", length) != 0) { |
443 continue; | 441 continue; |
444 } | 442 } |
445 | 443 |
446 is_external = false; | 444 is_external = false; |
447 ASSERT(invocation->arguments()->positional().length() == 1 && | 445 ASSERT(invocation->arguments()->positional().length() == 1 && |
448 invocation->arguments()->named().length() == 0); | 446 invocation->arguments()->named().length() == 0); |
449 StringLiteral* literal = | 447 StringLiteral* literal = |
450 StringLiteral::Cast(invocation->arguments()->positional()[0]); | 448 StringLiteral::Cast(invocation->arguments()->positional()[0]); |
451 native_name = &H.DartSymbol(literal->value()); | 449 native_name = &H.DartSymbol(literal->value()); |
452 break; | 450 break; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 if (native_name != NULL) { | 486 if (native_name != NULL) { |
489 function.set_native_name(*native_name); | 487 function.set_native_name(*native_name); |
490 } | 488 } |
491 | 489 |
492 SetupFunctionParameters(H, T, owner, function, kernel_procedure->function(), | 490 SetupFunctionParameters(H, T, owner, function, kernel_procedure->function(), |
493 is_method, | 491 is_method, |
494 false); // is_closure | 492 false); // is_closure |
495 | 493 |
496 if (kernel_klass == NULL) { | 494 if (kernel_klass == NULL) { |
497 library.AddObject(function, name); | 495 library.AddObject(function, name); |
498 ASSERT(!Object::Handle( | 496 ASSERT(!Object::Handle(Z, library.LookupObjectAllowPrivate( |
499 Z, library.LookupObjectAllowPrivate( | 497 H.DartProcedureName(kernel_procedure))) |
500 H.DartProcedureName(kernel_procedure->canonical_name()))) | |
501 .IsNull()); | 498 .IsNull()); |
502 } | 499 } |
503 if (FLAG_enable_mirrors) { | 500 if (FLAG_enable_mirrors) { |
504 library.AddFunctionMetadata(function, TokenPosition::kNoSource, | 501 library.AddFunctionMetadata(function, TokenPosition::kNoSource, |
505 kernel_procedure); | 502 kernel_procedure); |
506 } | 503 } |
507 } | 504 } |
508 | 505 |
509 const Object& KernelReader::ClassForScriptAt(const dart::Class& klass, | 506 const Object& KernelReader::ClassForScriptAt(const dart::Class& klass, |
510 intptr_t source_uri_index) { | 507 intptr_t source_uri_index) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 // Note: optimizer relies on DoubleInitialized bit in its field-unboxing | 622 // Note: optimizer relies on DoubleInitialized bit in its field-unboxing |
626 // heuristics. See JitOptimizer::VisitStoreInstanceField for more details. | 623 // heuristics. See JitOptimizer::VisitStoreInstanceField for more details. |
627 field.RecordStore(converter.SimpleValue()); | 624 field.RecordStore(converter.SimpleValue()); |
628 if (!converter.SimpleValue().IsNull() && | 625 if (!converter.SimpleValue().IsNull() && |
629 converter.SimpleValue().IsDouble()) { | 626 converter.SimpleValue().IsDouble()) { |
630 field.set_is_double_initialized(true); | 627 field.set_is_double_initialized(true); |
631 } | 628 } |
632 } | 629 } |
633 } | 630 } |
634 | 631 |
635 const dart::String& getter_name = | 632 const dart::String& getter_name = H.DartGetterName(kernel_field->name()); |
636 H.DartGetterName(kernel_field->canonical_name()); | |
637 const Object& script_class = | 633 const Object& script_class = |
638 ClassForScriptAt(klass, kernel_field->source_uri_index()); | 634 ClassForScriptAt(klass, kernel_field->source_uri_index()); |
639 Function& getter = Function::ZoneHandle( | 635 Function& getter = Function::ZoneHandle( |
640 Z, | 636 Z, |
641 Function::New( | 637 Function::New( |
642 getter_name, | 638 getter_name, |
643 kernel_field->IsStatic() ? RawFunction::kImplicitStaticFinalGetter | 639 kernel_field->IsStatic() ? RawFunction::kImplicitStaticFinalGetter |
644 : RawFunction::kImplicitGetter, | 640 : RawFunction::kImplicitGetter, |
645 kernel_field->IsStatic(), | 641 kernel_field->IsStatic(), |
646 // The functions created by the parser have is_const for static fields | 642 // The functions created by the parser have is_const for static fields |
647 // that are const (not just final) and they have is_const for | 643 // that are const (not just final) and they have is_const for |
648 // non-static | 644 // non-static |
649 // fields that are final. | 645 // fields that are final. |
650 kernel_field->IsStatic() ? kernel_field->IsConst() | 646 kernel_field->IsStatic() ? kernel_field->IsConst() |
651 : kernel_field->IsFinal(), | 647 : kernel_field->IsFinal(), |
652 false, // is_abstract | 648 false, // is_abstract |
653 false, // is_external | 649 false, // is_external |
654 false, // is_native | 650 false, // is_native |
655 script_class, kernel_field->position())); | 651 script_class, kernel_field->position())); |
656 functions_.Add(&getter); | 652 functions_.Add(&getter); |
657 getter.set_end_token_pos(kernel_field->end_position()); | 653 getter.set_end_token_pos(kernel_field->end_position()); |
658 getter.set_kernel_function(kernel_field); | 654 getter.set_kernel_function(kernel_field); |
659 getter.set_result_type(AbstractType::Handle(Z, field.type())); | 655 getter.set_result_type(AbstractType::Handle(Z, field.type())); |
660 getter.set_is_debuggable(false); | 656 getter.set_is_debuggable(false); |
661 SetupFieldAccessorFunction(klass, getter); | 657 SetupFieldAccessorFunction(klass, getter); |
662 | 658 |
663 if (!kernel_field->IsStatic() && !kernel_field->IsFinal()) { | 659 if (!kernel_field->IsStatic() && !kernel_field->IsFinal()) { |
664 // Only static fields can be const. | 660 // Only static fields can be const. |
665 ASSERT(!kernel_field->IsConst()); | 661 ASSERT(!kernel_field->IsConst()); |
666 const dart::String& setter_name = | 662 const dart::String& setter_name = H.DartSetterName(kernel_field->name()); |
667 H.DartSetterName(kernel_field->canonical_name()); | |
668 Function& setter = Function::ZoneHandle( | 663 Function& setter = Function::ZoneHandle( |
669 Z, Function::New(setter_name, RawFunction::kImplicitSetter, | 664 Z, Function::New(setter_name, RawFunction::kImplicitSetter, |
670 false, // is_static | 665 false, // is_static |
671 false, // is_const | 666 false, // is_const |
672 false, // is_abstract | 667 false, // is_abstract |
673 false, // is_external | 668 false, // is_external |
674 false, // is_native | 669 false, // is_native |
675 script_class, kernel_field->position())); | 670 script_class, kernel_field->position())); |
676 functions_.Add(&setter); | 671 functions_.Add(&setter); |
677 setter.set_end_token_pos(kernel_field->end_position()); | 672 setter.set_end_token_pos(kernel_field->end_position()); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 initializer_fun.set_is_debuggable(false); | 859 initializer_fun.set_is_debuggable(false); |
865 initializer_fun.set_is_reflectable(false); | 860 initializer_fun.set_is_reflectable(false); |
866 initializer_fun.set_is_inlinable(false); | 861 initializer_fun.set_is_inlinable(false); |
867 return new (zone) ParsedFunction(thread, initializer_fun); | 862 return new (zone) ParsedFunction(thread, initializer_fun); |
868 } | 863 } |
869 | 864 |
870 | 865 |
871 } // namespace kernel | 866 } // namespace kernel |
872 } // namespace dart | 867 } // namespace dart |
873 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 868 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |