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