| 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_class_builder; | 5 library fasta.kernel_class_builder; |
| 6 | 6 |
| 7 import 'package:kernel/ast.dart' | 7 import 'package:kernel/ast.dart' |
| 8 show | 8 show |
| 9 Class, | 9 Class, |
| 10 Constructor, | 10 Constructor, |
| 11 DartType, | 11 DartType, |
| 12 Expression, | 12 Expression, |
| 13 ExpressionStatement, | |
| 14 Field, | 13 Field, |
| 15 FunctionNode, | 14 FunctionNode, |
| 16 InterfaceType, | 15 InterfaceType, |
| 17 ListLiteral, | 16 ListLiteral, |
| 18 Member, | 17 Member, |
| 19 Name, | 18 Name, |
| 20 Procedure, | 19 Procedure, |
| 21 ProcedureKind, | 20 ProcedureKind, |
| 22 StaticGet, | 21 StaticGet, |
| 23 StringLiteral, | |
| 24 Supertype, | 22 Supertype, |
| 25 Throw, | |
| 26 VariableDeclaration; | 23 VariableDeclaration; |
| 27 | 24 |
| 28 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; | 25 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; |
| 29 | 26 |
| 30 import '../errors.dart' show internalError; | 27 import '../errors.dart' show internalError; |
| 31 | 28 |
| 32 import '../messages.dart' show warning; | |
| 33 | |
| 34 import '../dill/dill_member_builder.dart' show DillMemberBuilder; | 29 import '../dill/dill_member_builder.dart' show DillMemberBuilder; |
| 35 | 30 |
| 36 import 'kernel_builder.dart' | 31 import 'kernel_builder.dart' |
| 37 show | 32 show |
| 38 Builder, | 33 Builder, |
| 39 ClassBuilder, | 34 ClassBuilder, |
| 40 ConstructorReferenceBuilder, | 35 ConstructorReferenceBuilder, |
| 41 KernelLibraryBuilder, | 36 KernelLibraryBuilder, |
| 42 KernelProcedureBuilder, | 37 KernelProcedureBuilder, |
| 43 KernelTypeBuilder, | 38 KernelTypeBuilder, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 if (redirectionTarget != null) { | 121 if (redirectionTarget != null) { |
| 127 assert(builder.actualBody == null); | 122 assert(builder.actualBody == null); |
| 128 Builder targetBuilder = redirectionTarget.target; | 123 Builder targetBuilder = redirectionTarget.target; |
| 129 addRedirectingConstructor(builder, library); | 124 addRedirectingConstructor(builder, library); |
| 130 if (targetBuilder is ProcedureBuilder) { | 125 if (targetBuilder is ProcedureBuilder) { |
| 131 Member target = targetBuilder.target; | 126 Member target = targetBuilder.target; |
| 132 builder.body = new RedirectingFactoryBody(target); | 127 builder.body = new RedirectingFactoryBody(target); |
| 133 } else if (targetBuilder is DillMemberBuilder) { | 128 } else if (targetBuilder is DillMemberBuilder) { |
| 134 builder.body = new RedirectingFactoryBody(targetBuilder.member); | 129 builder.body = new RedirectingFactoryBody(targetBuilder.member); |
| 135 } else { | 130 } else { |
| 136 // TODO(ahe): Throw NSM error. This requires access to core | |
| 137 // types. | |
| 138 String message = "Redirection constructor target not found: " | 131 String message = "Redirection constructor target not found: " |
| 139 "${redirectionTarget.fullNameForErrors}"; | 132 "${redirectionTarget.fullNameForErrors}"; |
| 140 warning(library.fileUri, -1, message); | 133 if (builder.isConst) { |
| 141 builder.body = new ExpressionStatement( | 134 addCompileTimeError(builder.charOffset, message); |
| 142 new Throw(new StringLiteral(message))); | 135 } else { |
| 136 addWarning(builder.charOffset, message); |
| 137 } |
| 138 // CoreTypes aren't computed yet, and this is the outline |
| 139 // phase. So we can't and shouldn't create a method body. |
| 140 builder.body = new RedirectingFactoryBody.unresolved( |
| 141 redirectionTarget.fullNameForErrors); |
| 143 } | 142 } |
| 144 } | 143 } |
| 145 } | 144 } |
| 146 } | 145 } |
| 147 } | 146 } |
| 148 return count; | 147 return count; |
| 149 } | 148 } |
| 150 | 149 |
| 151 void addRedirectingConstructor( | 150 void addRedirectingConstructor( |
| 152 KernelProcedureBuilder constructor, KernelLibraryBuilder library) { | 151 KernelProcedureBuilder constructor, KernelLibraryBuilder library) { |
| 153 // Add a new synthetic field to this class for representing factory | 152 // Add a new synthetic field to this class for representing factory |
| 154 // constructors. This is used to support resolving such constructors in | 153 // constructors. This is used to support resolving such constructors in |
| 155 // source code. | 154 // source code. |
| 156 // | 155 // |
| 157 // The synthetic field looks like this: | 156 // The synthetic field looks like this: |
| 158 // | 157 // |
| 159 // final _redirecting# = [c1, ..., cn]; | 158 // final _redirecting# = [c1, ..., cn]; |
| 160 // | 159 // |
| 161 // Where each c1 ... cn are an instance of [StaticGet] whose target is | 160 // Where each c1 ... cn are an instance of [StaticGet] whose target is |
| 162 // [constructor.target]. | 161 // [constructor.target]. |
| 163 // | 162 // |
| 164 // TODO(ahe): Generate the correct factory body instead. | 163 // TODO(ahe): Add a kernel node to represent redirecting factory bodies. |
| 165 DillMemberBuilder constructorsField = | 164 DillMemberBuilder constructorsField = |
| 166 scope.local.putIfAbsent("_redirecting#", () { | 165 scope.local.putIfAbsent("_redirecting#", () { |
| 167 ListLiteral literal = new ListLiteral(<Expression>[]); | 166 ListLiteral literal = new ListLiteral(<Expression>[]); |
| 168 Name name = new Name("_redirecting#", library.library); | 167 Name name = new Name("_redirecting#", library.library); |
| 169 Field field = new Field(name, | 168 Field field = new Field(name, |
| 170 isStatic: true, initializer: literal, fileUri: cls.fileUri) | 169 isStatic: true, initializer: literal, fileUri: cls.fileUri) |
| 171 ..fileOffset = cls.fileOffset; | 170 ..fileOffset = cls.fileOffset; |
| 172 cls.addMember(field); | 171 cls.addMember(field); |
| 173 return new DillMemberBuilder(field, this); | 172 return new DillMemberBuilder(field, this); |
| 174 }); | 173 }); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 } | 271 } |
| 273 } | 272 } |
| 274 } | 273 } |
| 275 | 274 |
| 276 String get fullNameForErrors { | 275 String get fullNameForErrors { |
| 277 return isMixinApplication | 276 return isMixinApplication |
| 278 ? "${supertype.fullNameForErrors} with ${mixedInType.fullNameForErrors}" | 277 ? "${supertype.fullNameForErrors} with ${mixedInType.fullNameForErrors}" |
| 279 : name; | 278 : name; |
| 280 } | 279 } |
| 281 } | 280 } |
| OLD | NEW |