| 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 library_helper.ReadUntilExcluding(LibraryHelper::kClasses); | 252 library_helper.ReadUntilExcluding(LibraryHelper::kClasses); |
| 253 | 253 |
| 254 // Load all classes. | 254 // Load all classes. |
| 255 int class_count = builder_.ReadListLength(); // read list length. | 255 int class_count = builder_.ReadListLength(); // read list length. |
| 256 for (intptr_t i = 0; i < class_count; ++i) { | 256 for (intptr_t i = 0; i < class_count; ++i) { |
| 257 classes.Add(ReadClass(library, toplevel_class), Heap::kOld); | 257 classes.Add(ReadClass(library, toplevel_class), Heap::kOld); |
| 258 } | 258 } |
| 259 | 259 |
| 260 fields_.Clear(); | 260 fields_.Clear(); |
| 261 functions_.Clear(); | 261 functions_.Clear(); |
| 262 ActiveClassScope active_class_scope(&active_class_, 0, -1, &toplevel_class); | 262 ActiveClassScope active_class_scope(&active_class_, &toplevel_class); |
| 263 // Load toplevel fields. | 263 // Load toplevel fields. |
| 264 intptr_t field_count = builder_.ReadListLength(); // read list length. | 264 intptr_t field_count = builder_.ReadListLength(); // read list length. |
| 265 for (intptr_t i = 0; i < field_count; ++i) { | 265 for (intptr_t i = 0; i < field_count; ++i) { |
| 266 intptr_t field_offset = builder_.ReaderOffset(); | 266 intptr_t field_offset = builder_.ReaderOffset(); |
| 267 ActiveMemberScope active_member_scope(&active_class_, false, false, 0, -1); | 267 ActiveMemberScope active_member_scope(&active_class_, NULL); |
| 268 FieldHelper field_helper(&builder_); | 268 FieldHelper field_helper(&builder_); |
| 269 field_helper.ReadUntilExcluding(FieldHelper::kName); | 269 field_helper.ReadUntilExcluding(FieldHelper::kName); |
| 270 | 270 |
| 271 const dart::String& name = builder_.ReadNameAsFieldName(); | 271 const dart::String& name = builder_.ReadNameAsFieldName(); |
| 272 field_helper.SetJustRead(FieldHelper::kName); | 272 field_helper.SetJustRead(FieldHelper::kName); |
| 273 field_helper.ReadUntilExcluding(FieldHelper::kType); | 273 field_helper.ReadUntilExcluding(FieldHelper::kType); |
| 274 const Object& script_class = | 274 const Object& script_class = |
| 275 ClassForScriptAt(toplevel_class, field_helper.source_uri_index_); | 275 ClassForScriptAt(toplevel_class, field_helper.source_uri_index_); |
| 276 dart::Field& field = dart::Field::Handle( | 276 dart::Field& field = dart::Field::Handle( |
| 277 Z, dart::Field::NewTopLevel(name, field_helper.IsFinal(), | 277 Z, dart::Field::NewTopLevel(name, field_helper.IsFinal(), |
| (...skipping 27 matching lines...) Expand all Loading... |
| 305 } | 305 } |
| 306 | 306 |
| 307 void KernelReader::ReadPreliminaryClass(dart::Class* klass, | 307 void KernelReader::ReadPreliminaryClass(dart::Class* klass, |
| 308 ClassHelper* class_helper, | 308 ClassHelper* class_helper, |
| 309 intptr_t type_parameter_count) { | 309 intptr_t type_parameter_count) { |
| 310 // Note: This assumes that ClassHelper is exactly at the position where | 310 // Note: This assumes that ClassHelper is exactly at the position where |
| 311 // the length of the type parameters have been read, and that the order in | 311 // the length of the type parameters have been read, and that the order in |
| 312 // the binary is as follows: [...], kTypeParameters, kSuperClass, kMixinType, | 312 // the binary is as follows: [...], kTypeParameters, kSuperClass, kMixinType, |
| 313 // kImplementedClasses, [...]. | 313 // kImplementedClasses, [...]. |
| 314 | 314 |
| 315 // First setup the type parameters, so if any of the following code uses it | 315 // Set type parameters. |
| 316 // (in a recursive way) we're fine. | 316 ReadAndSetupTypeParameters(*klass, type_parameter_count, *klass, |
| 317 TypeArguments& type_parameters = | 317 Function::Handle(Z)); |
| 318 TypeArguments::Handle(Z, TypeArguments::null()); | |
| 319 if (type_parameter_count > 0) { | |
| 320 dart::TypeParameter& parameter = dart::TypeParameter::Handle(Z); | |
| 321 Type& null_bound = Type::Handle(Z, Type::null()); | |
| 322 | |
| 323 // Step a) Create array of [TypeParameter] objects (without bound). | |
| 324 type_parameters = TypeArguments::New(type_parameter_count); | |
| 325 { | |
| 326 AlternativeReadingScope alt(builder_.reader_); | |
| 327 for (intptr_t i = 0; i < type_parameter_count; i++) { | |
| 328 parameter = dart::TypeParameter::New( | |
| 329 *klass, Function::Handle(Z), i, | |
| 330 H.DartSymbol( | |
| 331 builder_.ReadStringReference()), // read ith name index. | |
| 332 null_bound, TokenPosition::kNoSource); | |
| 333 type_parameters.SetTypeAt(i, parameter); | |
| 334 builder_.SkipDartType(); // read guard. | |
| 335 } | |
| 336 } | |
| 337 klass->set_type_parameters(type_parameters); | |
| 338 | |
| 339 // Step b) Fill in the bounds of all [TypeParameter]s. | |
| 340 for (intptr_t i = 0; i < type_parameter_count; i++) { | |
| 341 builder_.SkipStringReference(); // read ith name index. | |
| 342 | |
| 343 // TODO(github.com/dart-lang/kernel/issues/42): This should be handled | |
| 344 // by the frontend. | |
| 345 parameter ^= type_parameters.TypeAt(i); | |
| 346 Tag tag = builder_.PeekTag(); // peek ith bound type. | |
| 347 if (tag == kDynamicType) { | |
| 348 builder_.SkipDartType(); // read ith bound. | |
| 349 parameter.set_bound(Type::Handle(Z, I->object_store()->object_type())); | |
| 350 } else { | |
| 351 AbstractType& bound = | |
| 352 T.BuildTypeWithoutFinalization(); // read ith bound. | |
| 353 if (bound.IsMalformedOrMalbounded()) { | |
| 354 bound = I->object_store()->object_type(); | |
| 355 } | |
| 356 parameter.set_bound(bound); | |
| 357 } | |
| 358 } | |
| 359 } | |
| 360 | 318 |
| 361 // Set super type. Some classes (e.g., Object) do not have one. | 319 // Set super type. Some classes (e.g., Object) do not have one. |
| 362 Tag type_tag = builder_.ReadTag(); // read super class type (part 1). | 320 Tag type_tag = builder_.ReadTag(); // read super class type (part 1). |
| 363 if (type_tag == kSomething) { | 321 if (type_tag == kSomething) { |
| 364 AbstractType& super_type = | 322 AbstractType& super_type = |
| 365 T.BuildTypeWithoutFinalization(); // read super class type (part 2). | 323 T.BuildTypeWithoutFinalization(); // read super class type (part 2). |
| 366 if (super_type.IsMalformed()) H.ReportError("Malformed super type"); | 324 if (super_type.IsMalformed()) H.ReportError("Malformed super type"); |
| 367 klass->set_super_type(super_type); | 325 klass->set_super_type(super_type); |
| 368 } | 326 } |
| 369 | 327 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 399 if (klass.script() == Script::null()) { | 357 if (klass.script() == Script::null()) { |
| 400 class_helper.ReadUntilIncluding(ClassHelper::kSourceUriIndex); | 358 class_helper.ReadUntilIncluding(ClassHelper::kSourceUriIndex); |
| 401 klass.set_script(ScriptAt(class_helper.source_uri_index_)); | 359 klass.set_script(ScriptAt(class_helper.source_uri_index_)); |
| 402 } | 360 } |
| 403 if (klass.token_pos() == TokenPosition::kNoSource) { | 361 if (klass.token_pos() == TokenPosition::kNoSource) { |
| 404 class_helper.ReadUntilIncluding(ClassHelper::kPosition); | 362 class_helper.ReadUntilIncluding(ClassHelper::kPosition); |
| 405 klass.set_token_pos(class_helper.position_); | 363 klass.set_token_pos(class_helper.position_); |
| 406 } | 364 } |
| 407 | 365 |
| 408 class_helper.ReadUntilExcluding(ClassHelper::kTypeParameters); | 366 class_helper.ReadUntilExcluding(ClassHelper::kTypeParameters); |
| 409 intptr_t type_paremeter_counts = | 367 intptr_t type_parameter_counts = |
| 410 builder_.ReadListLength(); // read type_parameters list length. | 368 builder_.ReadListLength(); // read type_parameters list length. |
| 411 intptr_t type_paremeter_offset = builder_.ReaderOffset(); | |
| 412 | 369 |
| 413 ActiveClassScope active_class_scope(&active_class_, type_paremeter_counts, | 370 ActiveClassScope active_class_scope(&active_class_, &klass); |
| 414 type_paremeter_offset, &klass); | |
| 415 if (!klass.is_cycle_free()) { | 371 if (!klass.is_cycle_free()) { |
| 416 ReadPreliminaryClass(&klass, &class_helper, type_paremeter_counts); | 372 ReadPreliminaryClass(&klass, &class_helper, type_parameter_counts); |
| 417 } else { | 373 } else { |
| 418 for (intptr_t i = 0; i < type_paremeter_counts; ++i) { | 374 for (intptr_t i = 0; i < type_parameter_counts; ++i) { |
| 419 builder_.SkipStringReference(); // read ith name index. | 375 builder_.SkipStringReference(); // read ith name index. |
| 420 builder_.SkipDartType(); // read ith bound. | 376 builder_.SkipDartType(); // read ith bound. |
| 421 } | 377 } |
| 422 class_helper.SetJustRead(ClassHelper::kTypeParameters); | 378 class_helper.SetJustRead(ClassHelper::kTypeParameters); |
| 423 } | 379 } |
| 424 | 380 |
| 425 fields_.Clear(); | 381 fields_.Clear(); |
| 426 functions_.Clear(); | 382 functions_.Clear(); |
| 427 | 383 |
| 428 if (library.raw() == dart::Library::InternalLibrary() && | 384 if (library.raw() == dart::Library::InternalLibrary() && |
| 429 klass.Name() == Symbols::ClassID().raw()) { | 385 klass.Name() == Symbols::ClassID().raw()) { |
| 430 // If this is a dart:internal.ClassID class ignore field declarations | 386 // If this is a dart:internal.ClassID class ignore field declarations |
| 431 // contained in the Kernel file and instead inject our own const | 387 // contained in the Kernel file and instead inject our own const |
| 432 // fields. | 388 // fields. |
| 433 klass.InjectCIDFields(); | 389 klass.InjectCIDFields(); |
| 434 } else { | 390 } else { |
| 435 class_helper.ReadUntilExcluding(ClassHelper::kFields); | 391 class_helper.ReadUntilExcluding(ClassHelper::kFields); |
| 436 int field_count = builder_.ReadListLength(); // read list length. | 392 int field_count = builder_.ReadListLength(); // read list length. |
| 437 for (intptr_t i = 0; i < field_count; ++i) { | 393 for (intptr_t i = 0; i < field_count; ++i) { |
| 438 intptr_t field_offset = builder_.ReaderOffset(); | 394 intptr_t field_offset = builder_.ReaderOffset(); |
| 439 ActiveMemberScope active_member(&active_class_, false, false, 0, -1); | 395 ActiveMemberScope active_member(&active_class_, NULL); |
| 440 FieldHelper field_helper(&builder_); | 396 FieldHelper field_helper(&builder_); |
| 441 field_helper.ReadUntilExcluding(FieldHelper::kName); | 397 field_helper.ReadUntilExcluding(FieldHelper::kName); |
| 442 | 398 |
| 443 const dart::String& name = builder_.ReadNameAsFieldName(); | 399 const dart::String& name = builder_.ReadNameAsFieldName(); |
| 444 field_helper.SetJustRead(FieldHelper::kName); | 400 field_helper.SetJustRead(FieldHelper::kName); |
| 445 field_helper.ReadUntilExcluding(FieldHelper::kType); | 401 field_helper.ReadUntilExcluding(FieldHelper::kType); |
| 446 const AbstractType& type = | 402 const AbstractType& type = |
| 447 T.BuildTypeWithoutFinalization(); // read type. | 403 T.BuildTypeWithoutFinalization(); // read type. |
| 448 field_helper.SetJustRead(FieldHelper::kType); | 404 field_helper.SetJustRead(FieldHelper::kType); |
| 449 const Object& script_class = | 405 const Object& script_class = |
| (...skipping 22 matching lines...) Expand all Loading... |
| 472 fields_.Add(&field); | 428 fields_.Add(&field); |
| 473 } | 429 } |
| 474 klass.AddFields(fields_); | 430 klass.AddFields(fields_); |
| 475 class_helper.SetJustRead(ClassHelper::kFields); | 431 class_helper.SetJustRead(ClassHelper::kFields); |
| 476 } | 432 } |
| 477 | 433 |
| 478 class_helper.ReadUntilExcluding(ClassHelper::kConstructors); | 434 class_helper.ReadUntilExcluding(ClassHelper::kConstructors); |
| 479 int constructor_count = builder_.ReadListLength(); // read list length. | 435 int constructor_count = builder_.ReadListLength(); // read list length. |
| 480 for (intptr_t i = 0; i < constructor_count; ++i) { | 436 for (intptr_t i = 0; i < constructor_count; ++i) { |
| 481 intptr_t constructor_offset = builder_.ReaderOffset(); | 437 intptr_t constructor_offset = builder_.ReaderOffset(); |
| 482 ActiveMemberScope active_member_scope(&active_class_, false, false, 0, -1); | 438 ActiveMemberScope active_member_scope(&active_class_, NULL); |
| 483 ConstructorHelper constructor_helper(&builder_); | 439 ConstructorHelper constructor_helper(&builder_); |
| 484 constructor_helper.ReadUntilExcluding(ConstructorHelper::kFunction); | 440 constructor_helper.ReadUntilExcluding(ConstructorHelper::kFunction); |
| 485 | 441 |
| 486 const dart::String& name = | 442 const dart::String& name = |
| 487 H.DartConstructorName(constructor_helper.canonical_name_); | 443 H.DartConstructorName(constructor_helper.canonical_name_); |
| 488 Function& function = dart::Function::ZoneHandle( | 444 Function& function = dart::Function::ZoneHandle( |
| 489 Z, dart::Function::New(name, RawFunction::kConstructor, | 445 Z, dart::Function::New(name, RawFunction::kConstructor, |
| 490 false, // is_static | 446 false, // is_static |
| 491 constructor_helper.IsConst(), | 447 constructor_helper.IsConst(), |
| 492 false, // is_abstract | 448 false, // is_abstract |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 | 494 |
| 539 return klass; | 495 return klass; |
| 540 } | 496 } |
| 541 | 497 |
| 542 void KernelReader::ReadProcedure(const dart::Library& library, | 498 void KernelReader::ReadProcedure(const dart::Library& library, |
| 543 const dart::Class& owner, | 499 const dart::Class& owner, |
| 544 bool in_class) { | 500 bool in_class) { |
| 545 intptr_t procedure_offset = builder_.ReaderOffset(); | 501 intptr_t procedure_offset = builder_.ReaderOffset(); |
| 546 ProcedureHelper procedure_helper(&builder_); | 502 ProcedureHelper procedure_helper(&builder_); |
| 547 | 503 |
| 548 bool member_is_procedure = false; | |
| 549 bool is_factory_procedure = false; | |
| 550 intptr_t member_type_parameters = 0; | |
| 551 intptr_t member_type_parameters_offset_start = -1; | |
| 552 builder_.GetTypeParameterInfoForPossibleProcedure( | |
| 553 builder_.ReaderOffset(), &member_is_procedure, &is_factory_procedure, | |
| 554 &member_type_parameters, &member_type_parameters_offset_start); | |
| 555 | |
| 556 ActiveMemberScope active_member(&active_class_, member_is_procedure, | |
| 557 is_factory_procedure, member_type_parameters, | |
| 558 member_type_parameters_offset_start); | |
| 559 | |
| 560 procedure_helper.ReadUntilExcluding(ProcedureHelper::kAnnotations); | 504 procedure_helper.ReadUntilExcluding(ProcedureHelper::kAnnotations); |
| 561 const dart::String& name = | 505 const dart::String& name = |
| 562 H.DartProcedureName(procedure_helper.canonical_name_); | 506 H.DartProcedureName(procedure_helper.canonical_name_); |
| 563 bool is_method = in_class && !procedure_helper.IsStatic(); | 507 bool is_method = in_class && !procedure_helper.IsStatic(); |
| 564 bool is_abstract = procedure_helper.IsAbstract(); | 508 bool is_abstract = procedure_helper.IsAbstract(); |
| 565 bool is_external = procedure_helper.IsExternal(); | 509 bool is_external = procedure_helper.IsExternal(); |
| 566 dart::String* native_name = NULL; | 510 dart::String* native_name = NULL; |
| 567 intptr_t annotation_count; | 511 intptr_t annotation_count; |
| 568 if (is_external) { | 512 if (is_external) { |
| 569 // Maybe it has a native implementation, which is not external as far as | 513 // Maybe it has a native implementation, which is not external as far as |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 Z, Function::New(name, GetFunctionType(procedure_helper.kind_), | 573 Z, Function::New(name, GetFunctionType(procedure_helper.kind_), |
| 630 !is_method, // is_static | 574 !is_method, // is_static |
| 631 false, // is_const | 575 false, // is_const |
| 632 is_abstract, is_external, | 576 is_abstract, is_external, |
| 633 native_name != NULL, // is_native | 577 native_name != NULL, // is_native |
| 634 script_class, procedure_helper.position_)); | 578 script_class, procedure_helper.position_)); |
| 635 function.set_end_token_pos(procedure_helper.end_position_); | 579 function.set_end_token_pos(procedure_helper.end_position_); |
| 636 functions_.Add(&function); | 580 functions_.Add(&function); |
| 637 function.set_kernel_offset(procedure_offset); | 581 function.set_kernel_offset(procedure_offset); |
| 638 | 582 |
| 583 ActiveMemberScope active_member(&active_class_, &function); |
| 584 |
| 639 procedure_helper.ReadUntilExcluding(ProcedureHelper::kFunction); | 585 procedure_helper.ReadUntilExcluding(ProcedureHelper::kFunction); |
| 640 Tag function_node_tag = builder_.ReadTag(); | 586 Tag function_node_tag = builder_.ReadTag(); |
| 641 ASSERT(function_node_tag == kSomething); | 587 ASSERT(function_node_tag == kSomething); |
| 642 FunctionNodeHelper function_node_helper(&builder_); | 588 FunctionNodeHelper function_node_helper(&builder_); |
| 643 function_node_helper.ReadUntilIncluding(FunctionNodeHelper::kDartAsyncMarker); | 589 function_node_helper.ReadUntilIncluding(FunctionNodeHelper::kDartAsyncMarker); |
| 644 function.set_is_debuggable(function_node_helper.dart_async_marker_ == | 590 function.set_is_debuggable(function_node_helper.dart_async_marker_ == |
| 645 FunctionNode::kSync); | 591 FunctionNode::kSync); |
| 646 switch (function_node_helper.dart_async_marker_) { | 592 switch (function_node_helper.dart_async_marker_) { |
| 647 case FunctionNode::kSyncStar: | 593 case FunctionNode::kSyncStar: |
| 648 function.set_modifier(RawFunction::kSyncGen); | 594 function.set_modifier(RawFunction::kSyncGen); |
| 649 break; | 595 break; |
| 650 case FunctionNode::kAsync: | 596 case FunctionNode::kAsync: |
| 651 function.set_modifier(RawFunction::kAsync); | 597 function.set_modifier(RawFunction::kAsync); |
| 652 function.set_is_inlinable(!FLAG_causal_async_stacks); | 598 function.set_is_inlinable(!FLAG_causal_async_stacks); |
| 653 break; | 599 break; |
| 654 case FunctionNode::kAsyncStar: | 600 case FunctionNode::kAsyncStar: |
| 655 function.set_modifier(RawFunction::kAsyncGen); | 601 function.set_modifier(RawFunction::kAsyncGen); |
| 656 function.set_is_inlinable(!FLAG_causal_async_stacks); | 602 function.set_is_inlinable(!FLAG_causal_async_stacks); |
| 657 break; | 603 break; |
| 658 default: | 604 default: |
| 659 // no special modifier | 605 // no special modifier |
| 660 break; | 606 break; |
| 661 } | 607 } |
| 662 ASSERT(function_node_helper.async_marker_ == FunctionNode::kSync); | 608 ASSERT(function_node_helper.async_marker_ == FunctionNode::kSync); |
| 663 | 609 |
| 664 if (native_name != NULL) { | 610 if (native_name != NULL) { |
| 665 function.set_native_name(*native_name); | 611 function.set_native_name(*native_name); |
| 666 } | 612 } |
| 667 | 613 |
| 614 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kTypeParameters); |
| 615 if (!function.IsFactory()) { |
| 616 // Read type_parameters list length. |
| 617 intptr_t type_parameter_count = builder_.ReadListLength(); |
| 618 // Set type parameters. |
| 619 ReadAndSetupTypeParameters(function, type_parameter_count, Class::Handle(Z), |
| 620 function); |
| 621 function_node_helper.SetJustRead(FunctionNodeHelper::kTypeParameters); |
| 622 } |
| 623 |
| 668 function_node_helper.ReadUntilExcluding( | 624 function_node_helper.ReadUntilExcluding( |
| 669 FunctionNodeHelper::kRequiredParameterCount); | 625 FunctionNodeHelper::kRequiredParameterCount); |
| 670 builder_.SetupFunctionParameters(owner, function, is_method, | 626 builder_.SetupFunctionParameters(owner, function, is_method, |
| 671 false, // is_closure | 627 false, // is_closure |
| 672 &function_node_helper); | 628 &function_node_helper); |
| 673 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kEnd); | 629 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kEnd); |
| 674 procedure_helper.SetJustRead(ProcedureHelper::kFunction); | 630 procedure_helper.SetJustRead(ProcedureHelper::kFunction); |
| 675 | 631 |
| 676 if (!in_class) { | 632 if (!in_class) { |
| 677 library.AddObject(function, name); | 633 library.AddObject(function, name); |
| 678 ASSERT(!Object::Handle( | 634 ASSERT(!Object::Handle( |
| 679 Z, library.LookupObjectAllowPrivate( | 635 Z, library.LookupObjectAllowPrivate( |
| 680 H.DartProcedureName(procedure_helper.canonical_name_))) | 636 H.DartProcedureName(procedure_helper.canonical_name_))) |
| 681 .IsNull()); | 637 .IsNull()); |
| 682 } | 638 } |
| 683 if (FLAG_enable_mirrors && annotation_count > 0) { | 639 if (FLAG_enable_mirrors && annotation_count > 0) { |
| 684 library.AddFunctionMetadata(function, TokenPosition::kNoSource, | 640 library.AddFunctionMetadata(function, TokenPosition::kNoSource, |
| 685 procedure_offset); | 641 procedure_offset); |
| 686 } | 642 } |
| 687 | 643 |
| 688 procedure_helper.ReadUntilExcluding(ProcedureHelper::kEnd); | 644 procedure_helper.ReadUntilExcluding(ProcedureHelper::kEnd); |
| 689 } | 645 } |
| 690 | 646 |
| 647 void KernelReader::ReadAndSetupTypeParameters( |
| 648 const Object& set_on, |
| 649 intptr_t type_parameter_count, |
| 650 const Class& parameterized_class, |
| 651 const Function& parameterized_function) { |
| 652 ASSERT(type_parameter_count >= 0); |
| 653 if (type_parameter_count == 0) { |
| 654 return; |
| 655 } |
| 656 // First setup the type parameters, so if any of the following code uses it |
| 657 // (in a recursive way) we're fine. |
| 658 TypeArguments& type_parameters = |
| 659 TypeArguments::Handle(Z, TypeArguments::null()); |
| 660 dart::TypeParameter& parameter = dart::TypeParameter::Handle(Z); |
| 661 Type& null_bound = Type::Handle(Z, Type::null()); |
| 662 |
| 663 // Step a) Create array of [TypeParameter] objects (without bound). |
| 664 type_parameters = TypeArguments::New(type_parameter_count); |
| 665 { |
| 666 AlternativeReadingScope alt(builder_.reader_); |
| 667 for (intptr_t i = 0; i < type_parameter_count; i++) { |
| 668 parameter = dart::TypeParameter::New( |
| 669 parameterized_class, parameterized_function, i, |
| 670 H.DartSymbol(builder_.ReadStringReference()), // read ith name index. |
| 671 null_bound, TokenPosition::kNoSource); |
| 672 type_parameters.SetTypeAt(i, parameter); |
| 673 builder_.SkipDartType(); // read guard. |
| 674 } |
| 675 } |
| 676 |
| 677 ASSERT(set_on.IsClass() || set_on.IsFunction()); |
| 678 if (set_on.IsClass()) { |
| 679 Class::Cast(set_on).set_type_parameters(type_parameters); |
| 680 } else { |
| 681 Function::Cast(set_on).set_type_parameters(type_parameters); |
| 682 } |
| 683 |
| 684 // Step b) Fill in the bounds of all [TypeParameter]s. |
| 685 for (intptr_t i = 0; i < type_parameter_count; i++) { |
| 686 builder_.SkipStringReference(); // read ith name index. |
| 687 |
| 688 // TODO(github.com/dart-lang/kernel/issues/42): This should be handled |
| 689 // by the frontend. |
| 690 parameter ^= type_parameters.TypeAt(i); |
| 691 Tag tag = builder_.PeekTag(); // peek ith bound type. |
| 692 if (tag == kDynamicType) { |
| 693 builder_.SkipDartType(); // read ith bound. |
| 694 parameter.set_bound(Type::Handle(Z, I->object_store()->object_type())); |
| 695 } else { |
| 696 AbstractType& bound = |
| 697 T.BuildTypeWithoutFinalization(); // read ith bound. |
| 698 if (bound.IsMalformedOrMalbounded()) { |
| 699 bound = I->object_store()->object_type(); |
| 700 } |
| 701 parameter.set_bound(bound); |
| 702 } |
| 703 } |
| 704 } |
| 705 |
| 691 const Object& KernelReader::ClassForScriptAt(const dart::Class& klass, | 706 const Object& KernelReader::ClassForScriptAt(const dart::Class& klass, |
| 692 intptr_t source_uri_index) { | 707 intptr_t source_uri_index) { |
| 693 Script& correct_script = ScriptAt(source_uri_index); | 708 Script& correct_script = ScriptAt(source_uri_index); |
| 694 if (klass.script() != correct_script.raw()) { | 709 if (klass.script() != correct_script.raw()) { |
| 695 // Use cache for patch classes. This works best for in-order usages. | 710 // Use cache for patch classes. This works best for in-order usages. |
| 696 PatchClass& patch_class = PatchClass::ZoneHandle(Z); | 711 PatchClass& patch_class = PatchClass::ZoneHandle(Z); |
| 697 patch_class ^= patch_classes_.At(source_uri_index); | 712 patch_class ^= patch_classes_.At(source_uri_index); |
| 698 if (patch_class.IsNull() || patch_class.origin_class() != klass.raw()) { | 713 if (patch_class.IsNull() || patch_class.origin_class() != klass.raw()) { |
| 699 patch_class = PatchClass::New(klass, correct_script); | 714 patch_class = PatchClass::New(klass, correct_script); |
| 700 patch_classes_.SetAt(source_uri_index, patch_class); | 715 patch_classes_.SetAt(source_uri_index, patch_class); |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 initializer_fun.set_result_type(AbstractType::Handle(zone, field.type())); | 955 initializer_fun.set_result_type(AbstractType::Handle(zone, field.type())); |
| 941 initializer_fun.set_is_debuggable(false); | 956 initializer_fun.set_is_debuggable(false); |
| 942 initializer_fun.set_is_reflectable(false); | 957 initializer_fun.set_is_reflectable(false); |
| 943 initializer_fun.set_is_inlinable(false); | 958 initializer_fun.set_is_inlinable(false); |
| 944 return new (zone) ParsedFunction(thread, initializer_fun); | 959 return new (zone) ParsedFunction(thread, initializer_fun); |
| 945 } | 960 } |
| 946 | 961 |
| 947 } // namespace kernel | 962 } // namespace kernel |
| 948 } // namespace dart | 963 } // namespace dart |
| 949 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 964 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| OLD | NEW |