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