Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/kernel_library_builder.dart

Issue 2970273004: Deprecate all diagnostics methods that use strings. (Closed)
Patch Set: Merged with 4df146dd9a465d63344330bf3e45524b927c92ec Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/scanner/token.dart' show Token; 7 import 'package:front_end/src/scanner/token.dart' show Token;
8 8
9 import 'package:kernel/ast.dart'; 9 import 'package:kernel/ast.dart';
10 10
11 import 'package:kernel/clone.dart' show CloneVisitor; 11 import 'package:kernel/clone.dart' show CloneVisitor;
12 12
13 import '../errors.dart' show internalError; 13 import '../deprecated_problems.dart' show deprecated_internalProblem;
14 14
15 import '../loader.dart' show Loader; 15 import '../loader.dart' show Loader;
16 16
17 import '../modifier.dart' 17 import '../modifier.dart'
18 show abstractMask, namedMixinApplicationMask, staticMask; 18 show abstractMask, namedMixinApplicationMask, staticMask;
19 19
20 import '../source/source_library_builder.dart' 20 import '../source/source_library_builder.dart'
21 show DeclarationBuilder, SourceLibraryBuilder; 21 show DeclarationBuilder, SourceLibraryBuilder;
22 22
23 import '../source/source_class_builder.dart' show SourceClassBuilder; 23 import '../source/source_class_builder.dart' show SourceClassBuilder;
24 24
25 import '../util/relativize.dart' show relativizeUri; 25 import '../util/relativize.dart' show relativizeUri;
26 26
27 import 'kernel_builder.dart' 27 import 'kernel_builder.dart'
28 show 28 show
29 AccessErrorBuilder, 29 deprecated_AccessErrorBuilder,
30 Builder, 30 Builder,
31 BuiltinTypeBuilder, 31 BuiltinTypeBuilder,
32 ClassBuilder, 32 ClassBuilder,
33 ConstructorReferenceBuilder, 33 ConstructorReferenceBuilder,
34 FormalParameterBuilder, 34 FormalParameterBuilder,
35 InvalidTypeBuilder, 35 InvalidTypeBuilder,
36 KernelConstructorBuilder, 36 KernelConstructorBuilder,
37 KernelEnumBuilder, 37 KernelEnumBuilder,
38 KernelFieldBuilder, 38 KernelFieldBuilder,
39 KernelFormalParameterBuilder, 39 KernelFormalParameterBuilder,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 while (member != null) { 141 while (member != null) {
142 member.parent = cls; 142 member.parent = cls;
143 member = member.next; 143 member = member.next;
144 } 144 }
145 } 145 }
146 146
147 void setParentAndCheckConflicts(String name, MemberBuilder member) { 147 void setParentAndCheckConflicts(String name, MemberBuilder member) {
148 if (typeVariablesByName != null) { 148 if (typeVariablesByName != null) {
149 TypeVariableBuilder tv = typeVariablesByName[name]; 149 TypeVariableBuilder tv = typeVariablesByName[name];
150 if (tv != null) { 150 if (tv != null) {
151 cls.addCompileTimeError( 151 cls.deprecated_addCompileTimeError(
152 member.charOffset, "Conflict with type variable '$name'."); 152 member.charOffset, "Conflict with type variable '$name'.");
153 cls.addCompileTimeError(tv.charOffset, "This is the type variable."); 153 cls.deprecated_addCompileTimeError(
154 tv.charOffset, "This is the type variable.");
154 } 155 }
155 } 156 }
156 setParent(name, member); 157 setParent(name, member);
157 } 158 }
158 159
159 members.forEach(setParentAndCheckConflicts); 160 members.forEach(setParentAndCheckConflicts);
160 constructors.forEach(setParentAndCheckConflicts); 161 constructors.forEach(setParentAndCheckConflicts);
161 // Formally, a setter has the name `id=`, so it can never conflict with a 162 // Formally, a setter has the name `id=`, so it can never conflict with a
162 // type variable. 163 // type variable.
163 setters.forEach(setParent); 164 setters.forEach(setParent);
164 addBuilder(className, cls, charOffset); 165 addBuilder(className, cls, charOffset);
165 } 166 }
166 167
167 Map<String, TypeVariableBuilder> checkTypeVariables( 168 Map<String, TypeVariableBuilder> checkTypeVariables(
168 List<TypeVariableBuilder> typeVariables, Builder owner) { 169 List<TypeVariableBuilder> typeVariables, Builder owner) {
169 if (typeVariables?.isEmpty ?? true) return null; 170 if (typeVariables?.isEmpty ?? true) return null;
170 Map<String, TypeVariableBuilder> typeVariablesByName = 171 Map<String, TypeVariableBuilder> typeVariablesByName =
171 <String, TypeVariableBuilder>{}; 172 <String, TypeVariableBuilder>{};
172 for (TypeVariableBuilder tv in typeVariables) { 173 for (TypeVariableBuilder tv in typeVariables) {
173 TypeVariableBuilder existing = typeVariablesByName[tv.name]; 174 TypeVariableBuilder existing = typeVariablesByName[tv.name];
174 if (existing != null) { 175 if (existing != null) {
175 addCompileTimeError(tv.charOffset, 176 deprecated_addCompileTimeError(tv.charOffset,
176 "A type variable can't have the same name as another."); 177 "A type variable can't have the same name as another.");
177 addCompileTimeError( 178 deprecated_addCompileTimeError(
178 existing.charOffset, "The other type variable named '${tv.name}'."); 179 existing.charOffset, "The other type variable named '${tv.name}'.");
179 } else { 180 } else {
180 typeVariablesByName[tv.name] = tv; 181 typeVariablesByName[tv.name] = tv;
181 if (owner is ClassBuilder) { 182 if (owner is ClassBuilder) {
182 // Only classes and type variables can't have the same name. See 183 // Only classes and type variables can't have the same name. See
183 // [#29555](https://github.com/dart-lang/sdk/issues/29555). 184 // [#29555](https://github.com/dart-lang/sdk/issues/29555).
184 if (tv.name == owner.name) { 185 if (tv.name == owner.name) {
185 addCompileTimeError( 186 deprecated_addCompileTimeError(
186 tv.charOffset, 187 tv.charOffset,
187 "A type variable can't have the same name as its enclosing " 188 "A type variable can't have the same name as its enclosing "
188 "declaration."); 189 "declaration.");
189 } 190 }
190 } 191 }
191 } 192 }
192 } 193 }
193 return typeVariablesByName; 194 return typeVariablesByName;
194 } 195 }
195 196
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 int index = name.indexOf("."); 490 int index = name.indexOf(".");
490 if (startsWithClassName && index == className.length) { 491 if (startsWithClassName && index == className.length) {
491 // Named constructor or factory. 492 // Named constructor or factory.
492 return name.substring(index + 1); 493 return name.substring(index + 1);
493 } 494 }
494 if (index == -1) { 495 if (index == -1) {
495 // A legal name for a regular method, but not for a constructor. 496 // A legal name for a regular method, but not for a constructor.
496 return null; 497 return null;
497 } 498 }
498 String suffix = name.substring(index + 1); 499 String suffix = name.substring(index + 1);
499 addCompileTimeError( 500 deprecated_addCompileTimeError(
500 charOffset, 501 charOffset,
501 "'$name' isn't a legal method name.\n" 502 "'$name' isn't a legal method name.\n"
502 "Did you mean '$className.$suffix'?"); 503 "Did you mean '$className.$suffix'?");
503 return suffix; 504 return suffix;
504 } 505 }
505 506
506 void addProcedure( 507 void addProcedure(
507 List<MetadataBuilder> metadata, 508 List<MetadataBuilder> metadata,
508 int modifiers, 509 int modifiers,
509 KernelTypeBuilder returnType, 510 KernelTypeBuilder returnType,
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 library.addMember(builder.build(this)..isStatic = true); 668 library.addMember(builder.build(this)..isStatic = true);
668 } else if (builder is KernelFunctionTypeAliasBuilder) { 669 } else if (builder is KernelFunctionTypeAliasBuilder) {
669 library.addTypedef(builder.build(this)); 670 library.addTypedef(builder.build(this));
670 } else if (builder is KernelEnumBuilder) { 671 } else if (builder is KernelEnumBuilder) {
671 library.addClass(builder.build(this, coreLibrary)); 672 library.addClass(builder.build(this, coreLibrary));
672 } else if (builder is PrefixBuilder) { 673 } else if (builder is PrefixBuilder) {
673 // Ignored. Kernel doesn't represent prefixes. 674 // Ignored. Kernel doesn't represent prefixes.
674 } else if (builder is BuiltinTypeBuilder) { 675 } else if (builder is BuiltinTypeBuilder) {
675 // Nothing needed. 676 // Nothing needed.
676 } else { 677 } else {
677 internalError("Unhandled builder: ${builder.runtimeType}"); 678 deprecated_internalProblem("Unhandled builder: ${builder.runtimeType}");
678 } 679 }
679 } 680 }
680 681
681 @override 682 @override
682 Library build(LibraryBuilder coreLibrary) { 683 Library build(LibraryBuilder coreLibrary) {
683 super.build(coreLibrary); 684 super.build(coreLibrary);
684 library.name = name; 685 library.name = name;
685 library.procedures.sort(compareProcedures); 686 library.procedures.sort(compareProcedures);
686 return library; 687 return library;
687 } 688 }
688 689
689 @override 690 @override
690 Builder buildAmbiguousBuilder( 691 Builder buildAmbiguousBuilder(
691 String name, Builder builder, Builder other, int charOffset, 692 String name, Builder builder, Builder other, int charOffset,
692 {bool isExport: false, bool isImport: false}) { 693 {bool isExport: false, bool isImport: false}) {
693 // TODO(ahe): Can I move this to Scope or Prefix? 694 // TODO(ahe): Can I move this to Scope or Prefix?
694 if (builder == other) return builder; 695 if (builder == other) return builder;
695 if (builder is InvalidTypeBuilder) return builder; 696 if (builder is InvalidTypeBuilder) return builder;
696 if (other is InvalidTypeBuilder) return other; 697 if (other is InvalidTypeBuilder) return other;
697 if (builder is AccessErrorBuilder) { 698 if (builder is deprecated_AccessErrorBuilder) {
698 AccessErrorBuilder error = builder; 699 deprecated_AccessErrorBuilder error = builder;
699 builder = error.builder; 700 builder = error.builder;
700 } 701 }
701 if (other is AccessErrorBuilder) { 702 if (other is deprecated_AccessErrorBuilder) {
702 AccessErrorBuilder error = other; 703 deprecated_AccessErrorBuilder error = other;
703 other = error.builder; 704 other = error.builder;
704 } 705 }
705 bool isLocal = false; 706 bool isLocal = false;
706 Builder preferred; 707 Builder preferred;
707 Uri uri; 708 Uri uri;
708 Uri otherUri; 709 Uri otherUri;
709 Uri preferredUri; 710 Uri preferredUri;
710 Uri hiddenUri; 711 Uri hiddenUri;
711 if (scope.local[name] == builder) { 712 if (scope.local[name] == builder) {
712 isLocal = true; 713 isLocal = true;
713 preferred = builder; 714 preferred = builder;
714 hiddenUri = other.computeLibraryUri(); 715 hiddenUri = other.computeLibraryUri();
715 } else { 716 } else {
716 uri = builder.computeLibraryUri(); 717 uri = builder.computeLibraryUri();
717 otherUri = other.computeLibraryUri(); 718 otherUri = other.computeLibraryUri();
718 if (otherUri?.scheme == "dart" && uri?.scheme != "dart") { 719 if (otherUri?.scheme == "dart" && uri?.scheme != "dart") {
719 preferred = builder; 720 preferred = builder;
720 preferredUri = uri; 721 preferredUri = uri;
721 hiddenUri = otherUri; 722 hiddenUri = otherUri;
722 } else if (uri?.scheme == "dart" && otherUri?.scheme != "dart") { 723 } else if (uri?.scheme == "dart" && otherUri?.scheme != "dart") {
723 preferred = other; 724 preferred = other;
724 preferredUri = otherUri; 725 preferredUri = otherUri;
725 hiddenUri = uri; 726 hiddenUri = uri;
726 } 727 }
727 } 728 }
728 if (preferred != null) { 729 if (preferred != null) {
729 if (isLocal) { 730 if (isLocal) {
730 if (isExport) { 731 if (isExport) {
731 addNit(charOffset, 732 deprecated_addNit(charOffset,
732 "Local definition of '$name' hides export from '${hiddenUri}'."); 733 "Local definition of '$name' hides export from '${hiddenUri}'.");
733 } else { 734 } else {
734 addNit(charOffset, 735 deprecated_addNit(charOffset,
735 "Local definition of '$name' hides import from '${hiddenUri}'."); 736 "Local definition of '$name' hides import from '${hiddenUri}'.");
736 } 737 }
737 } else { 738 } else {
738 if (isExport) { 739 if (isExport) {
739 addNit( 740 deprecated_addNit(
740 charOffset, 741 charOffset,
741 "Export of '$name' (from '${preferredUri}') hides export from " 742 "Export of '$name' (from '${preferredUri}') hides export from "
742 "'${hiddenUri}'."); 743 "'${hiddenUri}'.");
743 } else { 744 } else {
744 addNit( 745 deprecated_addNit(
745 charOffset, 746 charOffset,
746 "Import of '$name' (from '${preferredUri}') hides import from " 747 "Import of '$name' (from '${preferredUri}') hides import from "
747 "'${hiddenUri}'."); 748 "'${hiddenUri}'.");
748 } 749 }
749 } 750 }
750 return preferred; 751 return preferred;
751 } 752 }
752 if (builder.next == null && other.next == null) { 753 if (builder.next == null && other.next == null) {
753 if (isImport && builder is PrefixBuilder && other is PrefixBuilder) { 754 if (isImport && builder is PrefixBuilder && other is PrefixBuilder) {
754 // Handles the case where the same prefix is used for different 755 // Handles the case where the same prefix is used for different
755 // imports. 756 // imports.
756 return builder 757 return builder
757 ..exports.merge(other.exports, 758 ..exports.merge(other.exports,
758 (String name, Builder existing, Builder member) { 759 (String name, Builder existing, Builder member) {
759 return buildAmbiguousBuilder(name, existing, member, charOffset, 760 return buildAmbiguousBuilder(name, existing, member, charOffset,
760 isExport: isExport, isImport: isImport); 761 isExport: isExport, isImport: isImport);
761 }); 762 });
762 } 763 }
763 } 764 }
764 String message = isExport 765 String message = isExport
765 ? "'$name' is exported from both '${uri}' and '${otherUri}'." 766 ? "'$name' is exported from both '${uri}' and '${otherUri}'."
766 : "'$name' is imported from both '${uri}' and '${otherUri}'."; 767 : "'$name' is imported from both '${uri}' and '${otherUri}'.";
767 addNit(charOffset, message); 768 deprecated_addNit(charOffset, message);
768 return new KernelInvalidTypeBuilder(name, charOffset, fileUri, message); 769 return new KernelInvalidTypeBuilder(name, charOffset, fileUri, message);
769 } 770 }
770 771
771 int finishStaticInvocations() { 772 int finishStaticInvocations() {
772 CloneVisitor cloner; 773 CloneVisitor cloner;
773 for (var list in argumentsWithMissingDefaultValues) { 774 for (var list in argumentsWithMissingDefaultValues) {
774 final Arguments arguments = list[0]; 775 final Arguments arguments = list[0];
775 final FunctionNode function = list[1]; 776 final FunctionNode function = list[1];
776 777
777 Expression defaultArgumentFrom(Expression expression) { 778 Expression defaultArgumentFrom(Expression expression) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 mixinApplicationClasses.putIfAbsent(name, () => builder); 858 mixinApplicationClasses.putIfAbsent(name, () => builder);
858 if (existing != builder) { 859 if (existing != builder) {
859 part.scope.local.remove(name); 860 part.scope.local.remove(name);
860 } 861 }
861 }); 862 });
862 super.includePart(part); 863 super.includePart(part);
863 nativeMethods.addAll(part.nativeMethods); 864 nativeMethods.addAll(part.nativeMethods);
864 boundlessTypeVariables.addAll(part.boundlessTypeVariables); 865 boundlessTypeVariables.addAll(part.boundlessTypeVariables);
865 } 866 }
866 } 867 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698