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.source_class_builder; | 5 library fasta.source_class_builder; |
6 | 6 |
7 import 'package:front_end/src/fasta/builder/class_builder.dart' | 7 import 'package:front_end/src/fasta/builder/class_builder.dart' |
8 show ClassBuilder; | 8 show ClassBuilder; |
9 | 9 |
10 import 'package:front_end/src/fasta/source/source_library_builder.dart' | 10 import 'package:front_end/src/fasta/source/source_library_builder.dart' |
11 show SourceLibraryBuilder; | 11 show SourceLibraryBuilder; |
12 | 12 |
13 import 'package:kernel/ast.dart' | 13 import 'package:kernel/ast.dart' |
14 show Class, Constructor, Supertype, TreeNode, setParents; | 14 show Class, Constructor, Supertype, TreeNode, setParents; |
15 | 15 |
16 import '../errors.dart' show internalError; | 16 import '../deprecated_problems.dart' show deprecated_internalProblem; |
17 | 17 |
18 import '../kernel/kernel_builder.dart' | 18 import '../kernel/kernel_builder.dart' |
19 show | 19 show |
20 Builder, | 20 Builder, |
21 ConstructorReferenceBuilder, | 21 ConstructorReferenceBuilder, |
22 KernelClassBuilder, | 22 KernelClassBuilder, |
23 KernelFieldBuilder, | 23 KernelFieldBuilder, |
24 KernelFunctionBuilder, | 24 KernelFunctionBuilder, |
25 KernelLibraryBuilder, | 25 KernelLibraryBuilder, |
26 KernelTypeBuilder, | 26 KernelTypeBuilder, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 Class build(KernelLibraryBuilder library, LibraryBuilder coreLibrary) { | 84 Class build(KernelLibraryBuilder library, LibraryBuilder coreLibrary) { |
85 void buildBuilders(String name, Builder builder) { | 85 void buildBuilders(String name, Builder builder) { |
86 do { | 86 do { |
87 if (builder is KernelFieldBuilder) { | 87 if (builder is KernelFieldBuilder) { |
88 // TODO(ahe): It would be nice to have a common interface for the | 88 // TODO(ahe): It would be nice to have a common interface for the |
89 // build method to avoid duplicating these two cases. | 89 // build method to avoid duplicating these two cases. |
90 cls.addMember(builder.build(library)); | 90 cls.addMember(builder.build(library)); |
91 } else if (builder is KernelFunctionBuilder) { | 91 } else if (builder is KernelFunctionBuilder) { |
92 cls.addMember(builder.build(library)); | 92 cls.addMember(builder.build(library)); |
93 } else { | 93 } else { |
94 internalError("Unhandled builder: ${builder.runtimeType}"); | 94 deprecated_internalProblem( |
| 95 "Unhandled builder: ${builder.runtimeType}"); |
95 } | 96 } |
96 builder = builder.next; | 97 builder = builder.next; |
97 } while (builder != null); | 98 } while (builder != null); |
98 } | 99 } |
99 | 100 |
100 scope.forEach(buildBuilders); | 101 scope.forEach(buildBuilders); |
101 constructors.forEach(buildBuilders); | 102 constructors.forEach(buildBuilders); |
102 cls.supertype = supertype?.buildSupertype(library); | 103 cls.supertype = supertype?.buildSupertype(library); |
103 cls.mixedInType = mixedInType?.buildSupertype(library); | 104 cls.mixedInType = mixedInType?.buildSupertype(library); |
104 // TODO(ahe): If `cls.supertype` is null, and this isn't Object, report a | 105 // TODO(ahe): If `cls.supertype` is null, and this isn't Object, report a |
105 // compile-time error. | 106 // compile-time error. |
106 cls.isAbstract = isAbstract; | 107 cls.isAbstract = isAbstract; |
107 if (interfaces != null) { | 108 if (interfaces != null) { |
108 for (KernelTypeBuilder interface in interfaces) { | 109 for (KernelTypeBuilder interface in interfaces) { |
109 Supertype supertype = interface.buildSupertype(library); | 110 Supertype supertype = interface.buildSupertype(library); |
110 if (supertype != null) { | 111 if (supertype != null) { |
111 // TODO(ahe): Report an error if supertype is null. | 112 // TODO(ahe): Report an error if supertype is null. |
112 cls.implementedTypes.add(supertype); | 113 cls.implementedTypes.add(supertype); |
113 } | 114 } |
114 } | 115 } |
115 } | 116 } |
116 | 117 |
117 constructors.forEach((String name, Builder constructor) { | 118 constructors.forEach((String name, Builder constructor) { |
118 Builder member = scopeBuilder[name]; | 119 Builder member = scopeBuilder[name]; |
119 if (member == null) return; | 120 if (member == null) return; |
120 // TODO(ahe): charOffset is missing. | 121 // TODO(ahe): charOffset is missing. |
121 addCompileTimeError( | 122 deprecated_addCompileTimeError( |
122 constructor.charOffset, "Conflicts with member '${name}'."); | 123 constructor.charOffset, "Conflicts with member '${name}'."); |
123 if (constructor.isFactory) { | 124 if (constructor.isFactory) { |
124 addCompileTimeError(member.charOffset, | 125 deprecated_addCompileTimeError(member.charOffset, |
125 "Conflicts with factory '${this.name}.${name}'."); | 126 "Conflicts with factory '${this.name}.${name}'."); |
126 } else { | 127 } else { |
127 addCompileTimeError(member.charOffset, | 128 deprecated_addCompileTimeError(member.charOffset, |
128 "Conflicts with constructor '${this.name}.${name}'."); | 129 "Conflicts with constructor '${this.name}.${name}'."); |
129 } | 130 } |
130 }); | 131 }); |
131 | 132 |
132 scope.setters.forEach((String name, Builder setter) { | 133 scope.setters.forEach((String name, Builder setter) { |
133 Builder member = scopeBuilder[name]; | 134 Builder member = scopeBuilder[name]; |
134 if (member == null || !member.isField || member.isFinal) return; | 135 if (member == null || !member.isField || member.isFinal) return; |
135 // TODO(ahe): charOffset is missing. | 136 // TODO(ahe): charOffset is missing. |
136 var report = member.isInstanceMember != setter.isInstanceMember | 137 var report = member.isInstanceMember != setter.isInstanceMember |
137 ? addWarning | 138 ? deprecated_addWarning |
138 : addCompileTimeError; | 139 : deprecated_addCompileTimeError; |
139 report(setter.charOffset, "Conflicts with member '${name}'."); | 140 report(setter.charOffset, "Conflicts with member '${name}'."); |
140 report(member.charOffset, "Conflicts with setter '${name}'."); | 141 report(member.charOffset, "Conflicts with setter '${name}'."); |
141 }); | 142 }); |
142 | 143 |
143 cls.procedures.sort(compareProcedures); | 144 cls.procedures.sort(compareProcedures); |
144 return cls; | 145 return cls; |
145 } | 146 } |
146 | 147 |
147 void addSyntheticConstructor(Constructor constructor) { | 148 void addSyntheticConstructor(Constructor constructor) { |
148 String name = constructor.name.name; | 149 String name = constructor.name.name; |
149 cls.constructors.add(constructor); | 150 cls.constructors.add(constructor); |
150 constructor.parent = cls; | 151 constructor.parent = cls; |
151 DillMemberBuilder memberBuilder = new DillMemberBuilder(constructor, this); | 152 DillMemberBuilder memberBuilder = new DillMemberBuilder(constructor, this); |
152 memberBuilder.next = constructorScopeBuilder[name]; | 153 memberBuilder.next = constructorScopeBuilder[name]; |
153 constructorScopeBuilder.addMember(name, memberBuilder); | 154 constructorScopeBuilder.addMember(name, memberBuilder); |
154 } | 155 } |
155 | 156 |
156 @override | 157 @override |
157 void prepareInitializerInference( | 158 void prepareInitializerInference( |
158 SourceLibraryBuilder library, ClassBuilder currentClass) { | 159 SourceLibraryBuilder library, ClassBuilder currentClass) { |
159 scope.forEach((name, builder) { | 160 scope.forEach((name, builder) { |
160 builder.prepareInitializerInference(library, this); | 161 builder.prepareInitializerInference(library, this); |
161 }); | 162 }); |
162 } | 163 } |
163 } | 164 } |
OLD | NEW |