| 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 library fasta.kernel_library_builder; | 5 library fasta.kernel_library_builder; |
| 6 | 6 |
| 7 import 'package:front_end/src/fasta/dill/dill_library_builder.dart'; | 7 import 'package:front_end/src/fasta/dill/dill_library_builder.dart'; |
| 8 import 'package:front_end/src/fasta/export.dart'; | 8 import 'package:front_end/src/fasta/export.dart'; |
| 9 import 'package:front_end/src/fasta/import.dart'; | 9 import 'package:front_end/src/fasta/import.dart'; |
| 10 import 'package:kernel/ast.dart'; | 10 import 'package:kernel/ast.dart'; |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 name: name, | 495 name: name, |
| 496 typeVariables: typeVariables, | 496 typeVariables: typeVariables, |
| 497 modifiers: modifiers, | 497 modifiers: modifiers, |
| 498 interfaces: interfaces, | 498 interfaces: interfaces, |
| 499 charOffset: charOffset); | 499 charOffset: charOffset); |
| 500 checkTypeVariables(typeVariables, supertype.builder); | 500 checkTypeVariables(typeVariables, supertype.builder); |
| 501 } | 501 } |
| 502 | 502 |
| 503 @override | 503 @override |
| 504 void addField( | 504 void addField( |
| 505 String documentationComment, |
| 505 List<MetadataBuilder> metadata, | 506 List<MetadataBuilder> metadata, |
| 506 int modifiers, | 507 int modifiers, |
| 507 KernelTypeBuilder type, | 508 KernelTypeBuilder type, |
| 508 String name, | 509 String name, |
| 509 int charOffset, | 510 int charOffset, |
| 510 Token initializerTokenForInference, | 511 Token initializerTokenForInference, |
| 511 bool hasInitializer) { | 512 bool hasInitializer) { |
| 512 addBuilder( | 513 addBuilder( |
| 513 name, | 514 name, |
| 514 new KernelFieldBuilder(metadata, type, name, modifiers, this, | 515 new KernelFieldBuilder( |
| 515 charOffset, initializerTokenForInference, hasInitializer), | 516 documentationComment, |
| 517 metadata, |
| 518 type, |
| 519 name, |
| 520 modifiers, |
| 521 this, |
| 522 charOffset, |
| 523 initializerTokenForInference, |
| 524 hasInitializer), |
| 516 charOffset); | 525 charOffset); |
| 517 } | 526 } |
| 518 | 527 |
| 519 String computeAndValidateConstructorName(String name, int charOffset) { | 528 String computeAndValidateConstructorName(String name, int charOffset) { |
| 520 String className = currentDeclaration.name; | 529 String className = currentDeclaration.name; |
| 521 bool startsWithClassName = name.startsWith(className); | 530 bool startsWithClassName = name.startsWith(className); |
| 522 if (startsWithClassName && name.length == className.length) { | 531 if (startsWithClassName && name.length == className.length) { |
| 523 // Unnamed constructor or factory. | 532 // Unnamed constructor or factory. |
| 524 return ""; | 533 return ""; |
| 525 } | 534 } |
| 526 int index = name.indexOf("."); | 535 int index = name.indexOf("."); |
| 527 if (startsWithClassName && index == className.length) { | 536 if (startsWithClassName && index == className.length) { |
| 528 // Named constructor or factory. | 537 // Named constructor or factory. |
| 529 return name.substring(index + 1); | 538 return name.substring(index + 1); |
| 530 } | 539 } |
| 531 if (index == -1) { | 540 if (index == -1) { |
| 532 // A legal name for a regular method, but not for a constructor. | 541 // A legal name for a regular method, but not for a constructor. |
| 533 return null; | 542 return null; |
| 534 } | 543 } |
| 535 String suffix = name.substring(index + 1); | 544 String suffix = name.substring(index + 1); |
| 536 addCompileTimeError( | 545 addCompileTimeError( |
| 537 templateIllegalMethodName.withArguments(name, "$className.$suffix"), | 546 templateIllegalMethodName.withArguments(name, "$className.$suffix"), |
| 538 charOffset, | 547 charOffset, |
| 539 fileUri); | 548 fileUri); |
| 540 return suffix; | 549 return suffix; |
| 541 } | 550 } |
| 542 | 551 |
| 543 void addProcedure( | 552 void addProcedure( |
| 553 String documentationComment, |
| 544 List<MetadataBuilder> metadata, | 554 List<MetadataBuilder> metadata, |
| 545 int modifiers, | 555 int modifiers, |
| 546 KernelTypeBuilder returnType, | 556 KernelTypeBuilder returnType, |
| 547 String name, | 557 String name, |
| 548 List<TypeVariableBuilder> typeVariables, | 558 List<TypeVariableBuilder> typeVariables, |
| 549 List<FormalParameterBuilder> formals, | 559 List<FormalParameterBuilder> formals, |
| 550 ProcedureKind kind, | 560 ProcedureKind kind, |
| 551 int charOffset, | 561 int charOffset, |
| 552 int charOpenParenOffset, | 562 int charOpenParenOffset, |
| 553 int charEndOffset, | 563 int charEndOffset, |
| 554 String nativeMethodName, | 564 String nativeMethodName, |
| 555 {bool isTopLevel}) { | 565 {bool isTopLevel}) { |
| 556 // Nested declaration began in `OutlineBuilder.beginMethod` or | 566 // Nested declaration began in `OutlineBuilder.beginMethod` or |
| 557 // `OutlineBuilder.beginTopLevelMethod`. | 567 // `OutlineBuilder.beginTopLevelMethod`. |
| 558 endNestedDeclaration(name).resolveTypes(typeVariables, this); | 568 endNestedDeclaration(name).resolveTypes(typeVariables, this); |
| 559 ProcedureBuilder procedure; | 569 ProcedureBuilder procedure; |
| 560 String constructorName = | 570 String constructorName = |
| 561 isTopLevel ? null : computeAndValidateConstructorName(name, charOffset); | 571 isTopLevel ? null : computeAndValidateConstructorName(name, charOffset); |
| 562 if (constructorName != null) { | 572 if (constructorName != null) { |
| 563 name = constructorName; | 573 name = constructorName; |
| 564 procedure = new KernelConstructorBuilder( | 574 procedure = new KernelConstructorBuilder( |
| 575 documentationComment, |
| 565 metadata, | 576 metadata, |
| 566 modifiers & ~abstractMask, | 577 modifiers & ~abstractMask, |
| 567 returnType, | 578 returnType, |
| 568 name, | 579 name, |
| 569 typeVariables, | 580 typeVariables, |
| 570 formals, | 581 formals, |
| 571 this, | 582 this, |
| 572 charOffset, | 583 charOffset, |
| 573 charOpenParenOffset, | 584 charOpenParenOffset, |
| 574 charEndOffset, | 585 charEndOffset, |
| 575 nativeMethodName); | 586 nativeMethodName); |
| 576 } else { | 587 } else { |
| 577 procedure = new KernelProcedureBuilder( | 588 procedure = new KernelProcedureBuilder( |
| 589 documentationComment, |
| 578 metadata, | 590 metadata, |
| 579 modifiers, | 591 modifiers, |
| 580 returnType, | 592 returnType, |
| 581 name, | 593 name, |
| 582 typeVariables, | 594 typeVariables, |
| 583 formals, | 595 formals, |
| 584 kind, | 596 kind, |
| 585 this, | 597 this, |
| 586 charOffset, | 598 charOffset, |
| 587 charOpenParenOffset, | 599 charOpenParenOffset, |
| 588 charEndOffset, | 600 charEndOffset, |
| 589 nativeMethodName); | 601 nativeMethodName); |
| 590 } | 602 } |
| 591 checkTypeVariables(typeVariables, procedure); | 603 checkTypeVariables(typeVariables, procedure); |
| 592 addBuilder(name, procedure, charOffset); | 604 addBuilder(name, procedure, charOffset); |
| 593 if (nativeMethodName != null) { | 605 if (nativeMethodName != null) { |
| 594 addNativeMethod(procedure); | 606 addNativeMethod(procedure); |
| 595 } | 607 } |
| 596 } | 608 } |
| 597 | 609 |
| 598 void addFactoryMethod( | 610 void addFactoryMethod( |
| 611 String documentationComment, |
| 599 List<MetadataBuilder> metadata, | 612 List<MetadataBuilder> metadata, |
| 600 int modifiers, | 613 int modifiers, |
| 601 ConstructorReferenceBuilder constructorNameReference, | 614 ConstructorReferenceBuilder constructorNameReference, |
| 602 List<FormalParameterBuilder> formals, | 615 List<FormalParameterBuilder> formals, |
| 603 ConstructorReferenceBuilder redirectionTarget, | 616 ConstructorReferenceBuilder redirectionTarget, |
| 604 int charOffset, | 617 int charOffset, |
| 605 int charOpenParenOffset, | 618 int charOpenParenOffset, |
| 606 int charEndOffset, | 619 int charEndOffset, |
| 607 String nativeMethodName) { | 620 String nativeMethodName) { |
| 608 KernelTypeBuilder returnType = addNamedType( | 621 KernelTypeBuilder returnType = addNamedType( |
| 609 currentDeclaration.parent.name, <KernelTypeBuilder>[], charOffset); | 622 currentDeclaration.parent.name, <KernelTypeBuilder>[], charOffset); |
| 610 // Nested declaration began in `OutlineBuilder.beginFactoryMethod`. | 623 // Nested declaration began in `OutlineBuilder.beginFactoryMethod`. |
| 611 DeclarationBuilder<KernelTypeBuilder> factoryDeclaration = | 624 DeclarationBuilder<KernelTypeBuilder> factoryDeclaration = |
| 612 endNestedDeclaration("#factory_method"); | 625 endNestedDeclaration("#factory_method"); |
| 613 String name = constructorNameReference.name; | 626 String name = constructorNameReference.name; |
| 614 String constructorName = | 627 String constructorName = |
| 615 computeAndValidateConstructorName(name, charOffset); | 628 computeAndValidateConstructorName(name, charOffset); |
| 616 if (constructorName != null) { | 629 if (constructorName != null) { |
| 617 name = constructorName; | 630 name = constructorName; |
| 618 } | 631 } |
| 619 assert(constructorNameReference.suffix == null); | 632 assert(constructorNameReference.suffix == null); |
| 620 KernelProcedureBuilder procedure = new KernelProcedureBuilder( | 633 KernelProcedureBuilder procedure = new KernelProcedureBuilder( |
| 634 documentationComment, |
| 621 metadata, | 635 metadata, |
| 622 staticMask | modifiers, | 636 staticMask | modifiers, |
| 623 returnType, | 637 returnType, |
| 624 name, | 638 name, |
| 625 <TypeVariableBuilder>[], | 639 <TypeVariableBuilder>[], |
| 626 formals, | 640 formals, |
| 627 ProcedureKind.Factory, | 641 ProcedureKind.Factory, |
| 628 this, | 642 this, |
| 629 charOffset, | 643 charOffset, |
| 630 charOpenParenOffset, | 644 charOpenParenOffset, |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 mixinApplicationClasses.putIfAbsent(name, () => builder); | 924 mixinApplicationClasses.putIfAbsent(name, () => builder); |
| 911 if (existing != builder) { | 925 if (existing != builder) { |
| 912 part.scope.local.remove(name); | 926 part.scope.local.remove(name); |
| 913 } | 927 } |
| 914 }); | 928 }); |
| 915 super.includePart(part); | 929 super.includePart(part); |
| 916 nativeMethods.addAll(part.nativeMethods); | 930 nativeMethods.addAll(part.nativeMethods); |
| 917 boundlessTypeVariables.addAll(part.boundlessTypeVariables); | 931 boundlessTypeVariables.addAll(part.boundlessTypeVariables); |
| 918 } | 932 } |
| 919 } | 933 } |
| OLD | NEW |