| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 dart2js.constants.expressions; | 5 library dart2js.constants.expressions; |
| 6 | 6 |
| 7 import '../constants/constant_system.dart'; | 7 import '../constants/constant_system.dart'; |
| 8 import '../core_types.dart'; | 8 import '../core_types.dart'; |
| 9 import '../dart2jslib.dart' show assertDebugMode, Compiler; | 9 import '../dart2jslib.dart' show assertDebugMode, Compiler; |
| 10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 101 |
| 102 /// Computes the type of the instance created in a const constructor | 102 /// Computes the type of the instance created in a const constructor |
| 103 /// invocation with type [newType]. | 103 /// invocation with type [newType]. |
| 104 InterfaceType computeInstanceType(InterfaceType newType); | 104 InterfaceType computeInstanceType(InterfaceType newType); |
| 105 | 105 |
| 106 /// Computes the constant expressions of the fields of the created instance | 106 /// Computes the constant expressions of the fields of the created instance |
| 107 /// in a const constructor invocation with [arguments]. | 107 /// in a const constructor invocation with [arguments]. |
| 108 Map<FieldElement, ConstantExpression> computeInstanceFields( | 108 Map<FieldElement, ConstantExpression> computeInstanceFields( |
| 109 List<ConstantExpression> arguments, | 109 List<ConstantExpression> arguments, |
| 110 CallStructure callStructure); | 110 CallStructure callStructure); |
| 111 |
| 112 accept(ConstantConstructorVisitor visitor, arg); |
| 113 } |
| 114 |
| 115 abstract class ConstantConstructorVisitor<R, A> { |
| 116 const ConstantConstructorVisitor(); |
| 117 |
| 118 R visit(ConstantConstructor constantConstructor, A context) { |
| 119 return constantConstructor.accept(this, context); |
| 120 } |
| 121 |
| 122 R visitGenerative(GenerativeConstantConstructor constructor, A arg); |
| 123 R visitRedirectingGenerative( |
| 124 RedirectingGenerativeConstantConstructor constructor, A arg); |
| 125 R visitRedirectingFactory( |
| 126 RedirectingFactoryConstantConstructor constructor, A arg); |
| 111 } | 127 } |
| 112 | 128 |
| 113 /// A generative constant constructor. | 129 /// A generative constant constructor. |
| 114 class GenerativeConstantConstructor implements ConstantConstructor{ | 130 class GenerativeConstantConstructor implements ConstantConstructor{ |
| 115 final InterfaceType type; | 131 final InterfaceType type; |
| 116 final Map<dynamic/*int|String*/, ConstantExpression> defaultValues; | 132 final Map<dynamic/*int|String*/, ConstantExpression> defaultValues; |
| 117 final Map<FieldElement, ConstantExpression> fieldMap; | 133 final Map<FieldElement, ConstantExpression> fieldMap; |
| 118 final ConstructedConstantExpression superConstructorInvocation; | 134 final ConstructedConstantExpression superConstructorInvocation; |
| 119 | 135 |
| 120 GenerativeConstantConstructor( | 136 GenerativeConstantConstructor( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 135 NormalizedArguments args = new NormalizedArguments( | 151 NormalizedArguments args = new NormalizedArguments( |
| 136 defaultValues, callStructure, arguments); | 152 defaultValues, callStructure, arguments); |
| 137 Map<FieldElement, ConstantExpression> appliedFieldMap = | 153 Map<FieldElement, ConstantExpression> appliedFieldMap = |
| 138 applyFields(args, superConstructorInvocation); | 154 applyFields(args, superConstructorInvocation); |
| 139 fieldMap.forEach((FieldElement field, ConstantExpression constant) { | 155 fieldMap.forEach((FieldElement field, ConstantExpression constant) { |
| 140 appliedFieldMap[field] = constant.apply(args); | 156 appliedFieldMap[field] = constant.apply(args); |
| 141 }); | 157 }); |
| 142 return appliedFieldMap; | 158 return appliedFieldMap; |
| 143 } | 159 } |
| 144 | 160 |
| 161 accept(ConstantConstructorVisitor visitor, arg) { |
| 162 return visitor.visitGenerative(this, arg); |
| 163 } |
| 164 |
| 145 int get hashCode { | 165 int get hashCode { |
| 146 int hash = Hashing.objectHash(type); | 166 int hash = Hashing.objectHash(type); |
| 147 hash = Hashing.mapHash(defaultValues, hash); | 167 hash = Hashing.mapHash(defaultValues, hash); |
| 148 hash = Hashing.mapHash(fieldMap, hash); | 168 hash = Hashing.mapHash(fieldMap, hash); |
| 149 return Hashing.objectHash(superConstructorInvocation, hash); | 169 return Hashing.objectHash(superConstructorInvocation, hash); |
| 150 } | 170 } |
| 151 | 171 |
| 152 bool operator ==(other) { | 172 bool operator ==(other) { |
| 153 if (identical(this, other)) return true; | 173 if (identical(this, other)) return true; |
| 154 if (other is! GenerativeConstantConstructor) return false; | 174 if (other is! GenerativeConstantConstructor) return false; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 List<ConstantExpression> arguments, | 246 List<ConstantExpression> arguments, |
| 227 CallStructure callStructure) { | 247 CallStructure callStructure) { |
| 228 NormalizedArguments args = | 248 NormalizedArguments args = |
| 229 new NormalizedArguments(defaultValues, callStructure, arguments); | 249 new NormalizedArguments(defaultValues, callStructure, arguments); |
| 230 Map<FieldElement, ConstantExpression> appliedFieldMap = | 250 Map<FieldElement, ConstantExpression> appliedFieldMap = |
| 231 GenerativeConstantConstructor.applyFields( | 251 GenerativeConstantConstructor.applyFields( |
| 232 args, thisConstructorInvocation); | 252 args, thisConstructorInvocation); |
| 233 return appliedFieldMap; | 253 return appliedFieldMap; |
| 234 } | 254 } |
| 235 | 255 |
| 256 accept(ConstantConstructorVisitor visitor, arg) { |
| 257 return visitor.visitRedirectingGenerative(this, arg); |
| 258 } |
| 259 |
| 236 int get hashCode { | 260 int get hashCode { |
| 237 int hash = Hashing.objectHash(thisConstructorInvocation); | 261 int hash = Hashing.objectHash(thisConstructorInvocation); |
| 238 return Hashing.mapHash(defaultValues, hash); | 262 return Hashing.mapHash(defaultValues, hash); |
| 239 } | 263 } |
| 240 | 264 |
| 241 bool operator ==(other) { | 265 bool operator ==(other) { |
| 242 if (identical(this, other)) return true; | 266 if (identical(this, other)) return true; |
| 243 if (other is! RedirectingGenerativeConstantConstructor) return false; | 267 if (other is! RedirectingGenerativeConstantConstructor) return false; |
| 244 return | 268 return |
| 245 thisConstructorInvocation == other.thisConstructorInvocation && | 269 thisConstructorInvocation == other.thisConstructorInvocation && |
| (...skipping 29 matching lines...) Expand all Loading... |
| 275 } | 299 } |
| 276 | 300 |
| 277 Map<FieldElement, ConstantExpression> computeInstanceFields( | 301 Map<FieldElement, ConstantExpression> computeInstanceFields( |
| 278 List<ConstantExpression> arguments, | 302 List<ConstantExpression> arguments, |
| 279 CallStructure callStructure) { | 303 CallStructure callStructure) { |
| 280 ConstantConstructor constantConstructor = | 304 ConstantConstructor constantConstructor = |
| 281 targetConstructorInvocation.target.constantConstructor; | 305 targetConstructorInvocation.target.constantConstructor; |
| 282 return constantConstructor.computeInstanceFields(arguments, callStructure); | 306 return constantConstructor.computeInstanceFields(arguments, callStructure); |
| 283 } | 307 } |
| 284 | 308 |
| 309 accept(ConstantConstructorVisitor visitor, arg) { |
| 310 return visitor.visitRedirectingFactory(this, arg); |
| 311 } |
| 312 |
| 285 int get hashCode { | 313 int get hashCode { |
| 286 return Hashing.objectHash(targetConstructorInvocation); | 314 return Hashing.objectHash(targetConstructorInvocation); |
| 287 } | 315 } |
| 288 | 316 |
| 289 bool operator ==(other) { | 317 bool operator ==(other) { |
| 290 if (identical(this, other)) return true; | 318 if (identical(this, other)) return true; |
| 291 if (other is! RedirectingFactoryConstantConstructor) return false; | 319 if (other is! RedirectingFactoryConstantConstructor) return false; |
| 292 return targetConstructorInvocation == other.targetConstructorInvocation; | 320 return targetConstructorInvocation == other.targetConstructorInvocation; |
| 293 } | 321 } |
| 294 | 322 |
| (...skipping 1552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1847 visit(exp.name); | 1875 visit(exp.name); |
| 1848 if (exp.defaultValue != null) { | 1876 if (exp.defaultValue != null) { |
| 1849 sb.write(', defaultValue: '); | 1877 sb.write(', defaultValue: '); |
| 1850 visit(exp.defaultValue); | 1878 visit(exp.defaultValue); |
| 1851 } | 1879 } |
| 1852 sb.write(')'); | 1880 sb.write(')'); |
| 1853 } | 1881 } |
| 1854 | 1882 |
| 1855 String toString() => sb.toString(); | 1883 String toString() => sb.toString(); |
| 1856 } | 1884 } |
| OLD | NEW |