| 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/kernel_binary.h" | 10 #include "vm/kernel_binary.h" |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 field_helper.IsConst(), script_class, | 276 field_helper.IsConst(), script_class, |
| 277 field_helper.position_)); | 277 field_helper.position_)); |
| 278 field.set_kernel_offset(field_offset); | 278 field.set_kernel_offset(field_offset); |
| 279 const AbstractType& type = T.BuildType(); // read type. | 279 const AbstractType& type = T.BuildType(); // read type. |
| 280 field.SetFieldType(type); | 280 field.SetFieldType(type); |
| 281 field_helper.SetJustRead(FieldHelper::kType); | 281 field_helper.SetJustRead(FieldHelper::kType); |
| 282 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); | 282 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); |
| 283 field.set_has_initializer(builder_.PeekTag() == kSomething); | 283 field.set_has_initializer(builder_.PeekTag() == kSomething); |
| 284 GenerateFieldAccessors(toplevel_class, field, &field_helper, field_offset); | 284 GenerateFieldAccessors(toplevel_class, field, &field_helper, field_offset); |
| 285 field_helper.ReadUntilExcluding(FieldHelper::kEnd); | 285 field_helper.ReadUntilExcluding(FieldHelper::kEnd); |
| 286 if (FLAG_enable_mirrors) { | 286 if (FLAG_enable_mirrors && field_helper.annotation_count_ > 0) { |
| 287 library.AddFieldMetadata(field, TokenPosition::kNoSource, field_offset); | 287 library.AddFieldMetadata(field, TokenPosition::kNoSource, field_offset); |
| 288 } | 288 } |
| 289 fields_.Add(&field); | 289 fields_.Add(&field); |
| 290 library.AddObject(field, name); | 290 library.AddObject(field, name); |
| 291 } | 291 } |
| 292 toplevel_class.AddFields(fields_); | 292 toplevel_class.AddFields(fields_); |
| 293 | 293 |
| 294 // Load toplevel procedures. | 294 // Load toplevel procedures. |
| 295 intptr_t procedure_count = builder_.ReadListLength(); // read list length. | 295 intptr_t procedure_count = builder_.ReadListLength(); // read list length. |
| 296 for (intptr_t i = 0; i < procedure_count; ++i) { | 296 for (intptr_t i = 0; i < procedure_count; ++i) { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 // whereas in Kernel they are not final because they | 459 // whereas in Kernel they are not final because they |
| 460 // are not explicitly declared that way. | 460 // are not explicitly declared that way. |
| 461 field_helper.IsFinal() || field_helper.IsConst(), | 461 field_helper.IsFinal() || field_helper.IsConst(), |
| 462 field_helper.IsConst(), is_reflectable, script_class, | 462 field_helper.IsConst(), is_reflectable, script_class, |
| 463 type, field_helper.position_)); | 463 type, field_helper.position_)); |
| 464 field.set_kernel_offset(field_offset); | 464 field.set_kernel_offset(field_offset); |
| 465 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); | 465 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); |
| 466 field.set_has_initializer(builder_.PeekTag() == kSomething); | 466 field.set_has_initializer(builder_.PeekTag() == kSomething); |
| 467 GenerateFieldAccessors(klass, field, &field_helper, field_offset); | 467 GenerateFieldAccessors(klass, field, &field_helper, field_offset); |
| 468 field_helper.ReadUntilExcluding(FieldHelper::kEnd); | 468 field_helper.ReadUntilExcluding(FieldHelper::kEnd); |
| 469 if (FLAG_enable_mirrors) { | 469 if (FLAG_enable_mirrors && field_helper.annotation_count_ > 0) { |
| 470 library.AddFieldMetadata(field, TokenPosition::kNoSource, field_offset); | 470 library.AddFieldMetadata(field, TokenPosition::kNoSource, field_offset); |
| 471 } | 471 } |
| 472 fields_.Add(&field); | 472 fields_.Add(&field); |
| 473 } | 473 } |
| 474 klass.AddFields(fields_); | 474 klass.AddFields(fields_); |
| 475 class_helper.SetJustRead(ClassHelper::kFields); | 475 class_helper.SetJustRead(ClassHelper::kFields); |
| 476 } | 476 } |
| 477 | 477 |
| 478 class_helper.ReadUntilExcluding(ClassHelper::kConstructors); | 478 class_helper.ReadUntilExcluding(ClassHelper::kConstructors); |
| 479 int constructor_count = builder_.ReadListLength(); // read list length. | 479 int constructor_count = builder_.ReadListLength(); // read list length. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 502 function_node_helper.ReadUntilExcluding( | 502 function_node_helper.ReadUntilExcluding( |
| 503 FunctionNodeHelper::kRequiredParameterCount); | 503 FunctionNodeHelper::kRequiredParameterCount); |
| 504 builder_.SetupFunctionParameters(klass, function, | 504 builder_.SetupFunctionParameters(klass, function, |
| 505 true, // is_method | 505 true, // is_method |
| 506 false, // is_closure | 506 false, // is_closure |
| 507 &function_node_helper); | 507 &function_node_helper); |
| 508 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kEnd); | 508 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kEnd); |
| 509 constructor_helper.SetJustRead(ConstructorHelper::kFunction); | 509 constructor_helper.SetJustRead(ConstructorHelper::kFunction); |
| 510 constructor_helper.ReadUntilExcluding(ConstructorHelper::kEnd); | 510 constructor_helper.ReadUntilExcluding(ConstructorHelper::kEnd); |
| 511 | 511 |
| 512 if (FLAG_enable_mirrors) { | 512 if (FLAG_enable_mirrors && constructor_helper.annotation_count_ > 0) { |
| 513 library.AddFunctionMetadata(function, TokenPosition::kNoSource, | 513 library.AddFunctionMetadata(function, TokenPosition::kNoSource, |
| 514 constructor_offset); | 514 constructor_offset); |
| 515 } | 515 } |
| 516 } | 516 } |
| 517 class_helper.SetJustRead(ClassHelper::kConstructors); | 517 class_helper.SetJustRead(ClassHelper::kConstructors); |
| 518 | 518 |
| 519 class_helper.ReadUntilExcluding(ClassHelper::kProcedures); | 519 class_helper.ReadUntilExcluding(ClassHelper::kProcedures); |
| 520 int procedure_count = builder_.ReadListLength(); // read list length. | 520 int procedure_count = builder_.ReadListLength(); // read list length. |
| 521 for (intptr_t i = 0; i < procedure_count; ++i) { | 521 for (intptr_t i = 0; i < procedure_count; ++i) { |
| 522 ReadProcedure(library, klass, true); | 522 ReadProcedure(library, klass, true); |
| 523 } | 523 } |
| 524 class_helper.SetJustRead(ClassHelper::kProcedures); | 524 class_helper.SetJustRead(ClassHelper::kProcedures); |
| 525 | 525 |
| 526 klass.SetFunctions(Array::Handle(MakeFunctionsArray())); | 526 klass.SetFunctions(Array::Handle(MakeFunctionsArray())); |
| 527 | 527 |
| 528 if (!klass.is_marked_for_parsing()) { | 528 if (!klass.is_marked_for_parsing()) { |
| 529 klass.set_is_marked_for_parsing(); | 529 klass.set_is_marked_for_parsing(); |
| 530 } | 530 } |
| 531 | 531 |
| 532 if (FLAG_enable_mirrors) { | 532 if (FLAG_enable_mirrors && class_helper.annotation_count_ > 0) { |
| 533 library.AddClassMetadata(klass, toplevel_class, TokenPosition::kNoSource, | 533 library.AddClassMetadata(klass, toplevel_class, TokenPosition::kNoSource, |
| 534 class_offset); | 534 class_offset); |
| 535 } | 535 } |
| 536 | 536 |
| 537 class_helper.ReadUntilExcluding(ClassHelper::kEnd); | 537 class_helper.ReadUntilExcluding(ClassHelper::kEnd); |
| 538 | 538 |
| 539 return klass; | 539 return klass; |
| 540 } | 540 } |
| 541 | 541 |
| 542 | 542 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 558 is_factory_procedure, member_type_parameters, | 558 is_factory_procedure, member_type_parameters, |
| 559 member_type_parameters_offset_start); | 559 member_type_parameters_offset_start); |
| 560 | 560 |
| 561 procedure_helper.ReadUntilExcluding(ProcedureHelper::kAnnotations); | 561 procedure_helper.ReadUntilExcluding(ProcedureHelper::kAnnotations); |
| 562 const dart::String& name = | 562 const dart::String& name = |
| 563 H.DartProcedureName(procedure_helper.canonical_name_); | 563 H.DartProcedureName(procedure_helper.canonical_name_); |
| 564 bool is_method = in_class && !procedure_helper.IsStatic(); | 564 bool is_method = in_class && !procedure_helper.IsStatic(); |
| 565 bool is_abstract = procedure_helper.IsAbstract(); | 565 bool is_abstract = procedure_helper.IsAbstract(); |
| 566 bool is_external = procedure_helper.IsExternal(); | 566 bool is_external = procedure_helper.IsExternal(); |
| 567 dart::String* native_name = NULL; | 567 dart::String* native_name = NULL; |
| 568 intptr_t annotation_count; |
| 568 if (is_external) { | 569 if (is_external) { |
| 569 // Maybe it has a native implementation, which is not external as far as | 570 // Maybe it has a native implementation, which is not external as far as |
| 570 // the VM is concerned because it does have an implementation. Check for | 571 // the VM is concerned because it does have an implementation. Check for |
| 571 // an ExternalName annotation and extract the string from it. | 572 // an ExternalName annotation and extract the string from it. |
| 572 intptr_t annotation_count = builder_.ReadListLength(); // read list length. | 573 annotation_count = builder_.ReadListLength(); // read list length. |
| 573 for (int i = 0; i < annotation_count; ++i) { | 574 for (int i = 0; i < annotation_count; ++i) { |
| 574 if (builder_.PeekTag() != kConstructorInvocation && | 575 if (builder_.PeekTag() != kConstructorInvocation && |
| 575 builder_.PeekTag() != kConstConstructorInvocation) { | 576 builder_.PeekTag() != kConstConstructorInvocation) { |
| 576 builder_.SkipExpression(); | 577 builder_.SkipExpression(); |
| 577 continue; | 578 continue; |
| 578 } | 579 } |
| 579 builder_.ReadTag(); | 580 builder_.ReadTag(); |
| 580 builder_.ReadPosition(); | 581 builder_.ReadPosition(); |
| 581 NameIndex annotation_class = H.EnclosingName( | 582 NameIndex annotation_class = H.EnclosingName( |
| 582 builder_.ReadCanonicalNameReference()); // read target reference, | 583 builder_.ReadCanonicalNameReference()); // read target reference, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 612 ASSERT(list_length == 0); | 613 ASSERT(list_length == 0); |
| 613 | 614 |
| 614 // Skip remaining annotations | 615 // Skip remaining annotations |
| 615 for (++i; i < annotation_count; ++i) { | 616 for (++i; i < annotation_count; ++i) { |
| 616 builder_.SkipExpression(); // read ith annotation. | 617 builder_.SkipExpression(); // read ith annotation. |
| 617 } | 618 } |
| 618 | 619 |
| 619 break; | 620 break; |
| 620 } | 621 } |
| 621 procedure_helper.SetJustRead(ProcedureHelper::kAnnotations); | 622 procedure_helper.SetJustRead(ProcedureHelper::kAnnotations); |
| 623 } else { |
| 624 procedure_helper.ReadUntilIncluding(ProcedureHelper::kAnnotations); |
| 625 annotation_count = procedure_helper.annotation_count_; |
| 622 } | 626 } |
| 623 const Object& script_class = | 627 const Object& script_class = |
| 624 ClassForScriptAt(owner, procedure_helper.source_uri_index_); | 628 ClassForScriptAt(owner, procedure_helper.source_uri_index_); |
| 625 dart::Function& function = dart::Function::ZoneHandle( | 629 dart::Function& function = dart::Function::ZoneHandle( |
| 626 Z, Function::New(name, GetFunctionType(procedure_helper.kind_), | 630 Z, Function::New(name, GetFunctionType(procedure_helper.kind_), |
| 627 !is_method, // is_static | 631 !is_method, // is_static |
| 628 false, // is_const | 632 false, // is_const |
| 629 is_abstract, is_external, | 633 is_abstract, is_external, |
| 630 native_name != NULL, // is_native | 634 native_name != NULL, // is_native |
| 631 script_class, procedure_helper.position_)); | 635 script_class, procedure_helper.position_)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kEnd); | 674 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kEnd); |
| 671 procedure_helper.SetJustRead(ProcedureHelper::kFunction); | 675 procedure_helper.SetJustRead(ProcedureHelper::kFunction); |
| 672 | 676 |
| 673 if (!in_class) { | 677 if (!in_class) { |
| 674 library.AddObject(function, name); | 678 library.AddObject(function, name); |
| 675 ASSERT(!Object::Handle( | 679 ASSERT(!Object::Handle( |
| 676 Z, library.LookupObjectAllowPrivate( | 680 Z, library.LookupObjectAllowPrivate( |
| 677 H.DartProcedureName(procedure_helper.canonical_name_))) | 681 H.DartProcedureName(procedure_helper.canonical_name_))) |
| 678 .IsNull()); | 682 .IsNull()); |
| 679 } | 683 } |
| 680 if (FLAG_enable_mirrors) { | 684 if (FLAG_enable_mirrors && annotation_count > 0) { |
| 681 library.AddFunctionMetadata(function, TokenPosition::kNoSource, | 685 library.AddFunctionMetadata(function, TokenPosition::kNoSource, |
| 682 procedure_offset); | 686 procedure_offset); |
| 683 } | 687 } |
| 684 | 688 |
| 685 procedure_helper.ReadUntilExcluding(ProcedureHelper::kEnd); | 689 procedure_helper.ReadUntilExcluding(ProcedureHelper::kEnd); |
| 686 } | 690 } |
| 687 | 691 |
| 688 const Object& KernelReader::ClassForScriptAt(const dart::Class& klass, | 692 const Object& KernelReader::ClassForScriptAt(const dart::Class& klass, |
| 689 intptr_t source_uri_index) { | 693 intptr_t source_uri_index) { |
| 690 Script& correct_script = ScriptAt(source_uri_index); | 694 Script& correct_script = ScriptAt(source_uri_index); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 initializer_fun.set_is_debuggable(false); | 919 initializer_fun.set_is_debuggable(false); |
| 916 initializer_fun.set_is_reflectable(false); | 920 initializer_fun.set_is_reflectable(false); |
| 917 initializer_fun.set_is_inlinable(false); | 921 initializer_fun.set_is_inlinable(false); |
| 918 return new (zone) ParsedFunction(thread, initializer_fun); | 922 return new (zone) ParsedFunction(thread, initializer_fun); |
| 919 } | 923 } |
| 920 | 924 |
| 921 | 925 |
| 922 } // namespace kernel | 926 } // namespace kernel |
| 923 } // namespace dart | 927 } // namespace dart |
| 924 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 928 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| OLD | NEW |