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_builder; | 5 library fasta.kernel_builder; |
6 | 6 |
7 export 'kernel_class_builder.dart' show KernelClassBuilder; | 7 export 'kernel_class_builder.dart' show KernelClassBuilder; |
8 | 8 |
9 export 'kernel_enum_builder.dart' show KernelEnumBuilder; | 9 export 'kernel_enum_builder.dart' show KernelEnumBuilder; |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 export 'kernel_type_builder.dart' show KernelTypeBuilder; | 33 export 'kernel_type_builder.dart' show KernelTypeBuilder; |
34 | 34 |
35 export 'kernel_type_variable_builder.dart' show KernelTypeVariableBuilder; | 35 export 'kernel_type_variable_builder.dart' show KernelTypeVariableBuilder; |
36 | 36 |
37 export '../builder/builder.dart'; | 37 export '../builder/builder.dart'; |
38 | 38 |
39 export 'kernel_variable_builder.dart' show KernelVariableBuilder; | 39 export 'kernel_variable_builder.dart' show KernelVariableBuilder; |
40 | 40 |
41 export 'kernel_invalid_type_builder.dart' show KernelInvalidTypeBuilder; | 41 export 'kernel_invalid_type_builder.dart' show KernelInvalidTypeBuilder; |
42 | 42 |
43 import 'package:kernel/text/ast_to_text.dart' show Printer; | |
44 | |
45 import 'package:kernel/ast.dart' | 43 import 'package:kernel/ast.dart' |
46 show | 44 show |
47 Class, | |
48 Constructor, | 45 Constructor, |
49 DartType, | 46 DartType, |
50 DynamicType, | 47 DynamicType, |
51 Field, | |
52 Initializer, | 48 Initializer, |
53 Library, | |
54 Member, | |
55 Procedure, | 49 Procedure, |
56 RedirectingInitializer, | 50 RedirectingInitializer, |
57 TypeParameter; | 51 TypeParameter; |
58 | 52 |
59 import '../deprecated_problems.dart' show deprecated_inputError; | |
60 | |
61 import '../builder/builder.dart' show LibraryBuilder; | 53 import '../builder/builder.dart' show LibraryBuilder; |
62 | 54 |
63 List<DartType> computeDefaultTypeArguments(LibraryBuilder library, | 55 List<DartType> computeDefaultTypeArguments(LibraryBuilder library, |
64 List<TypeParameter> typeParameters, List<DartType> arguments) { | 56 List<TypeParameter> typeParameters, List<DartType> arguments) { |
65 // TODO(ahe): Not sure what to do if `arguments.length != | 57 // TODO(ahe): Not sure what to do if `arguments.length != |
66 // cls.typeParameters.length`. | 58 // cls.typeParameters.length`. |
67 if (arguments == null) { | 59 if (arguments == null) { |
68 return new List<DartType>.filled( | 60 return new List<DartType>.filled( |
69 typeParameters.length, const DynamicType()); | 61 typeParameters.length, const DynamicType()); |
70 } | 62 } |
71 if (arguments.length < typeParameters.length) { | 63 if (arguments.length < typeParameters.length) { |
72 arguments = new List<DartType>.from(arguments); | 64 arguments = new List<DartType>.from(arguments); |
73 for (int i = arguments.length; i < typeParameters.length; i++) { | 65 for (int i = arguments.length; i < typeParameters.length; i++) { |
74 arguments.add(const DynamicType()); | 66 arguments.add(const DynamicType()); |
75 } | 67 } |
76 } else if (arguments.length > typeParameters.length) { | 68 } else if (arguments.length > typeParameters.length) { |
77 return arguments.sublist(0, typeParameters.length); | 69 return arguments.sublist(0, typeParameters.length); |
78 } | 70 } |
79 return arguments; | 71 return arguments; |
80 } | 72 } |
81 | 73 |
82 dynamic deprecated_memberError(Member member, Object error, [int charOffset]) { | |
83 String name = member.name?.name; | |
84 if (name == "") { | |
85 name = Printer.emptyNameString; | |
86 } else if (name == null) { | |
87 name = "<anon>"; | |
88 } | |
89 Library library = member.enclosingLibrary; | |
90 Class cls = member.enclosingClass; | |
91 String fileUri; | |
92 if (member is Procedure) { | |
93 fileUri = member.fileUri; | |
94 } else if (member is Field) { | |
95 fileUri = member.fileUri; | |
96 } | |
97 fileUri ??= cls?.fileUri ?? library.fileUri; | |
98 Uri uri = fileUri == null ? library.importUri : Uri.base.resolve(fileUri); | |
99 charOffset ??= -1; | |
100 if (charOffset == -1) { | |
101 charOffset = member.fileOffset ?? -1; | |
102 } | |
103 if (charOffset == -1) { | |
104 charOffset = cls?.fileOffset ?? -1; | |
105 } | |
106 name = (cls == null ? "" : "${cls.name}::") + name; | |
107 return deprecated_inputError(uri, charOffset, "Error in $name: $error"); | |
108 } | |
109 | |
110 int compareProcedures(Procedure a, Procedure b) { | 74 int compareProcedures(Procedure a, Procedure b) { |
111 int i = a.fileUri.compareTo(b.fileUri); | 75 int i = a.fileUri.compareTo(b.fileUri); |
112 if (i != 0) return i; | 76 if (i != 0) return i; |
113 return a.fileOffset.compareTo(b.fileOffset); | 77 return a.fileOffset.compareTo(b.fileOffset); |
114 } | 78 } |
115 | 79 |
116 bool isRedirectingGenerativeConstructorImplementation(Constructor constructor) { | 80 bool isRedirectingGenerativeConstructorImplementation(Constructor constructor) { |
117 List<Initializer> initializers = constructor.initializers; | 81 List<Initializer> initializers = constructor.initializers; |
118 return initializers.length == 1 && | 82 return initializers.length == 1 && |
119 initializers.single is RedirectingInitializer; | 83 initializers.single is RedirectingInitializer; |
120 } | 84 } |
OLD | NEW |