Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library fasta.kernel_class_builder; | |
| 6 | |
| 7 import 'package:kernel/ast.dart' show | |
| 8 Class, | |
| 9 DartType, | |
| 10 ExpressionStatement, | |
| 11 InterfaceType, | |
| 12 Member, | |
| 13 StringLiteral, | |
| 14 Supertype, | |
| 15 Throw; | |
| 16 | |
| 17 import '../errors.dart' show | |
| 18 internalError; | |
| 19 | |
| 20 import 'kernel_builder.dart' show | |
| 21 Builder, | |
| 22 ClassBuilder, | |
| 23 ConstructorReferenceBuilder, | |
| 24 KernelProcedureBuilder, | |
| 25 KernelTypeBuilder, | |
| 26 LibraryBuilder, | |
| 27 MetadataBuilder, | |
| 28 ProcedureBuilder, | |
| 29 TypeVariableBuilder, | |
| 30 computeDefaultTypeArguments; | |
| 31 | |
| 32 import 'redirecting_factory_body.dart' show | |
| 33 RedirectingFactoryBody; | |
| 34 | |
| 35 abstract class KernelClassBuilder | |
| 36 extends ClassBuilder<KernelTypeBuilder, InterfaceType> { | |
| 37 KernelClassBuilder( | |
| 38 List<MetadataBuilder> metadata, int modifiers, | |
| 39 String name, List<TypeVariableBuilder> typeVariables, | |
| 40 KernelTypeBuilder supertype, List<KernelTypeBuilder> interfaces, | |
| 41 Map<String, Builder> members, List<KernelTypeBuilder> types, | |
| 42 LibraryBuilder parent) | |
| 43 : super(metadata, modifiers, name, typeVariables, supertype, interfaces, | |
| 44 members, types, parent); | |
| 45 | |
| 46 Class get cls; | |
| 47 | |
| 48 Class get target => cls; | |
| 49 | |
| 50 /// [arguments] have already been built. | |
| 51 InterfaceType buildTypesWithBuiltArguments(List<DartType> arguments) { | |
| 52 return arguments == null | |
| 53 ? cls.rawType | |
| 54 : new InterfaceType(cls, | |
| 55 computeDefaultTypeArguments(cls.typeParameters, arguments)); | |
|
Johnni Winther
2017/01/18 12:42:39
Why do we allow discrepancies and effective treat
ahe
2017/01/18 15:21:50
We need to do something, and I'm not sure what the
| |
| 56 } | |
| 57 | |
| 58 InterfaceType buildType(List<KernelTypeBuilder> arguments) { | |
| 59 List<DartType> typeArguments; | |
| 60 if (arguments != null) { | |
| 61 typeArguments = <DartType>[]; | |
| 62 for (KernelTypeBuilder builder in arguments) { | |
| 63 DartType type = builder.build(); | |
| 64 if (type == null) { | |
| 65 internalError("Bad type: ${builder.runtimeType}"); | |
| 66 } | |
| 67 typeArguments.add(type); | |
| 68 } | |
| 69 } | |
| 70 return buildTypesWithBuiltArguments(typeArguments); | |
| 71 } | |
| 72 | |
| 73 Supertype buildSupertype(List<KernelTypeBuilder> arguments) { | |
| 74 List<DartType> typeArguments; | |
| 75 if (arguments != null) { | |
| 76 typeArguments = <DartType>[]; | |
| 77 for (KernelTypeBuilder builder in arguments) { | |
| 78 DartType type = builder.build(); | |
| 79 if (type == null) { | |
| 80 internalError("Bad type: ${builder.runtimeType}"); | |
| 81 } | |
| 82 typeArguments.add(type); | |
| 83 } | |
| 84 return new Supertype(cls, typeArguments); | |
| 85 } else { | |
| 86 return cls.asRawSupertype; | |
| 87 } | |
| 88 } | |
| 89 | |
| 90 int resolveConstructors(LibraryBuilder library) { | |
| 91 int count = super.resolveConstructors(library); | |
| 92 if (count != 0) { | |
| 93 members.forEach((String name, Builder builder) { | |
| 94 if (builder is KernelProcedureBuilder && builder.isFactory) { | |
| 95 ConstructorReferenceBuilder redirectionTarget = | |
| 96 builder.redirectionTarget; | |
| 97 if (redirectionTarget != null) { | |
| 98 assert(builder.actualBody == null); | |
| 99 Builder targetBuilder = redirectionTarget.target; | |
| 100 if (targetBuilder is ProcedureBuilder) { | |
| 101 Member target = targetBuilder.target; | |
|
Johnni Winther
2017/01/18 12:42:39
Does this handle multiple steps (is .target the ef
ahe
2017/01/18 15:21:50
It computes the immediate target. Added a comment
| |
| 102 builder.body = new RedirectingFactoryBody(target); | |
| 103 } else { | |
| 104 // TODO(ahe): Throw NSM error. This requires access to core | |
| 105 // types. | |
| 106 String message = | |
| 107 "Missing constructor: ${redirectionTarget.fullNameForErrors}"; | |
| 108 print(message); | |
| 109 builder.body = new ExpressionStatement( | |
| 110 new Throw(new StringLiteral(message))); | |
| 111 } | |
| 112 } | |
| 113 } | |
| 114 }); | |
| 115 } | |
| 116 return count; | |
| 117 } | |
| 118 } | |
| OLD | NEW |