| 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 DartType, | 10 DartType, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 : super(metadata, modifiers, name, typeVariables, supertype, interfaces, | 57 : super(metadata, modifiers, name, typeVariables, supertype, interfaces, |
| 58 members, parent, charOffset); | 58 members, parent, charOffset); |
| 59 | 59 |
| 60 Class get cls; | 60 Class get cls; |
| 61 | 61 |
| 62 Class get target => cls; | 62 Class get target => cls; |
| 63 | 63 |
| 64 /// [arguments] have already been built. | 64 /// [arguments] have already been built. |
| 65 InterfaceType buildTypesWithBuiltArguments( | 65 InterfaceType buildTypesWithBuiltArguments( |
| 66 LibraryBuilder library, List<DartType> arguments) { | 66 LibraryBuilder library, List<DartType> arguments) { |
| 67 return arguments == null | 67 assert(arguments == null || cls.typeParameters.length == arguments.length); |
| 68 ? cls.rawType | 68 return arguments == null ? cls.rawType : new InterfaceType(cls, arguments); |
| 69 : new InterfaceType( | 69 } |
| 70 cls, | 70 |
| 71 // TODO(ahe): Not sure what to do if `arguments.length != | 71 List<DartType> buildTypeArguments( |
| 72 // cls.typeParameters.length`. | 72 LibraryBuilder library, List<KernelTypeBuilder> arguments) { |
| 73 computeDefaultTypeArguments(cls.typeParameters, arguments)); | 73 List<DartType> typeArguments = <DartType>[]; |
| 74 for (KernelTypeBuilder builder in arguments) { |
| 75 DartType type = builder.build(library); |
| 76 if (type == null) { |
| 77 internalError("Bad type: ${builder.runtimeType}"); |
| 78 } |
| 79 typeArguments.add(type); |
| 80 } |
| 81 return computeDefaultTypeArguments( |
| 82 library, cls.typeParameters, typeArguments); |
| 74 } | 83 } |
| 75 | 84 |
| 76 InterfaceType buildType( | 85 InterfaceType buildType( |
| 77 LibraryBuilder library, List<KernelTypeBuilder> arguments) { | 86 LibraryBuilder library, List<KernelTypeBuilder> arguments) { |
| 78 List<DartType> typeArguments; | 87 List<DartType> typeArguments; |
| 79 if (arguments != null) { | 88 if (arguments != null) { |
| 80 typeArguments = <DartType>[]; | 89 typeArguments = buildTypeArguments(library, arguments); |
| 81 for (KernelTypeBuilder builder in arguments) { | |
| 82 DartType type = builder.build(library); | |
| 83 if (type == null) { | |
| 84 internalError("Bad type: ${builder.runtimeType}"); | |
| 85 } | |
| 86 typeArguments.add(type); | |
| 87 } | |
| 88 } | 90 } |
| 89 return buildTypesWithBuiltArguments(library, typeArguments); | 91 return buildTypesWithBuiltArguments(library, typeArguments); |
| 90 } | 92 } |
| 91 | 93 |
| 92 Supertype buildSupertype( | 94 Supertype buildSupertype( |
| 93 LibraryBuilder library, List<KernelTypeBuilder> arguments) { | 95 LibraryBuilder library, List<KernelTypeBuilder> arguments) { |
| 94 List<DartType> typeArguments; | |
| 95 if (arguments != null) { | 96 if (arguments != null) { |
| 96 typeArguments = <DartType>[]; | 97 return new Supertype(cls, buildTypeArguments(library, arguments)); |
| 97 for (KernelTypeBuilder builder in arguments) { | |
| 98 DartType type = builder.build(library); | |
| 99 if (type == null) { | |
| 100 internalError("Bad type: ${builder.runtimeType}"); | |
| 101 } | |
| 102 typeArguments.add(type); | |
| 103 } | |
| 104 return new Supertype(cls, typeArguments); | |
| 105 } else { | 98 } else { |
| 106 return cls.asRawSupertype; | 99 return cls.asRawSupertype; |
| 107 } | 100 } |
| 108 } | 101 } |
| 109 | 102 |
| 110 int resolveConstructors(KernelLibraryBuilder library) { | 103 int resolveConstructors(KernelLibraryBuilder library) { |
| 111 int count = super.resolveConstructors(library); | 104 int count = super.resolveConstructors(library); |
| 112 if (count != 0) { | 105 if (count != 0) { |
| 113 // Copy keys to avoid concurrent modification error. | 106 // Copy keys to avoid concurrent modification error. |
| 114 List<String> names = members.keys.toList(); | 107 List<String> names = members.keys.toList(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 fileUri: cls.fileUri)..fileOffset = cls.fileOffset; | 160 fileUri: cls.fileUri)..fileOffset = cls.fileOffset; |
| 168 cls.addMember(field); | 161 cls.addMember(field); |
| 169 return new DillMemberBuilder(field, this); | 162 return new DillMemberBuilder(field, this); |
| 170 }); | 163 }); |
| 171 Field field = constructorsField.target; | 164 Field field = constructorsField.target; |
| 172 ListLiteral literal = field.initializer; | 165 ListLiteral literal = field.initializer; |
| 173 literal.expressions | 166 literal.expressions |
| 174 .add(new StaticGet(constructor.target)..parent = literal); | 167 .add(new StaticGet(constructor.target)..parent = literal); |
| 175 } | 168 } |
| 176 } | 169 } |
| OLD | NEW |