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