| 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.class_builder; | 5 library fasta.class_builder; |
| 6 | 6 |
| 7 import '../errors.dart' show internalError; |
| 8 |
| 7 import 'builder.dart' | 9 import 'builder.dart' |
| 8 show | 10 show |
| 9 Builder, | 11 Builder, |
| 10 ConstructorReferenceBuilder, | 12 ConstructorReferenceBuilder, |
| 11 LibraryBuilder, | 13 LibraryBuilder, |
| 12 MetadataBuilder, | 14 MetadataBuilder, |
| 15 MixinApplicationBuilder, |
| 16 NamedTypeBuilder, |
| 13 TypeBuilder, | 17 TypeBuilder, |
| 14 TypeDeclarationBuilder, | 18 TypeDeclarationBuilder, |
| 15 TypeVariableBuilder; | 19 TypeVariableBuilder; |
| 16 | 20 |
| 17 import 'scope.dart' show AmbiguousBuilder, Scope; | 21 import 'scope.dart' show AmbiguousBuilder, Scope; |
| 18 | 22 |
| 19 abstract class ClassBuilder<T extends TypeBuilder, R> | 23 abstract class ClassBuilder<T extends TypeBuilder, R> |
| 20 extends TypeDeclarationBuilder<T, R> { | 24 extends TypeDeclarationBuilder<T, R> { |
| 21 final List<TypeVariableBuilder> typeVariables; | 25 final List<TypeVariableBuilder> typeVariables; |
| 22 | 26 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 if (builder == null) { | 97 if (builder == null) { |
| 94 return null; | 98 return null; |
| 95 } else if (isSetter && builder.isGetter) { | 99 } else if (isSetter && builder.isGetter) { |
| 96 return null; | 100 return null; |
| 97 } else { | 101 } else { |
| 98 return builder.isInstanceMember ? null : builder; | 102 return builder.isInstanceMember ? null : builder; |
| 99 } | 103 } |
| 100 } | 104 } |
| 101 | 105 |
| 102 Builder findConstructorOrFactory(String name); | 106 Builder findConstructorOrFactory(String name); |
| 107 |
| 108 /// Returns a map which maps the type variables of [superclass] to their |
| 109 /// respective values as defined by the superclass clause of this class (and |
| 110 /// its superclasses). |
| 111 /// |
| 112 /// It's assumed that [superclass] is a superclass of this class. |
| 113 /// |
| 114 /// For example, given: |
| 115 /// |
| 116 /// class Box<T> {} |
| 117 /// class BeatBox extends Box<Beat> {} |
| 118 /// class Beat {} |
| 119 /// |
| 120 /// We have: |
| 121 /// |
| 122 /// [[BeatBox]].getSubstitutionMap([[Box]]) -> {[[Box::T]]: Beat]]}. |
| 123 /// |
| 124 /// This method returns null if the map is empty, and it's an error if |
| 125 /// [superclass] isn't a superclass. |
| 126 Map<TypeVariableBuilder, TypeBuilder> getSubstitutionMap( |
| 127 ClassBuilder superclass, |
| 128 Uri fileUri, |
| 129 int charOffset, |
| 130 TypeBuilder dynamicType) { |
| 131 TypeBuilder supertype = this.supertype; |
| 132 Map<TypeVariableBuilder, TypeBuilder> substitutionMap; |
| 133 List arguments; |
| 134 List variables; |
| 135 Builder builder; |
| 136 while (builder != superclass) { |
| 137 if (supertype is NamedTypeBuilder) { |
| 138 NamedTypeBuilder t = supertype; |
| 139 builder = t.builder; |
| 140 arguments = t.arguments; |
| 141 if (builder is ClassBuilder) { |
| 142 variables = builder.typeVariables; |
| 143 if (builder != superclass) { |
| 144 supertype = builder.supertype; |
| 145 } |
| 146 } |
| 147 } else if (supertype is MixinApplicationBuilder) { |
| 148 MixinApplicationBuilder t = supertype; |
| 149 supertype = t.supertype; |
| 150 } else { |
| 151 internalError("Superclass not found.", fileUri, charOffset); |
| 152 } |
| 153 if (variables != null) { |
| 154 Map<TypeVariableBuilder, TypeBuilder> directSubstitutionMap = |
| 155 <TypeVariableBuilder, TypeBuilder>{}; |
| 156 arguments ??= const []; |
| 157 for (int i = 0; i < variables.length; i++) { |
| 158 TypeBuilder argument = |
| 159 arguments.length < i ? arguments[i] : dynamicType; |
| 160 if (substitutionMap != null) { |
| 161 argument = argument.subst(substitutionMap); |
| 162 } |
| 163 directSubstitutionMap[variables[i]] = argument; |
| 164 } |
| 165 substitutionMap = directSubstitutionMap; |
| 166 } |
| 167 } |
| 168 return substitutionMap; |
| 169 } |
| 103 } | 170 } |
| OLD | NEW |