| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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.kernel.env; | 5 library dart2js.kernel.env; |
| 6 | 6 |
| 7 import 'package:kernel/ast.dart' as ir; | 7 import 'package:kernel/ast.dart' as ir; |
| 8 import 'package:kernel/clone.dart'; | 8 import 'package:kernel/clone.dart'; |
| 9 import 'package:kernel/type_algebra.dart'; | 9 import 'package:kernel/type_algebra.dart'; |
| 10 | 10 |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 } | 323 } |
| 324 } | 324 } |
| 325 | 325 |
| 326 void forEachConstructor(void f(ir.Member member)) { | 326 void forEachConstructor(void f(ir.Member member)) { |
| 327 _ensureMaps(); | 327 _ensureMaps(); |
| 328 _constructorMap.values.forEach(f); | 328 _constructorMap.values.forEach(f); |
| 329 } | 329 } |
| 330 } | 330 } |
| 331 | 331 |
| 332 class ClassData { | 332 class ClassData { |
| 333 /// TODO(johnniwinther): Remove this from the [MemberData] interface. Use |
| 334 /// `definition.node` instead. |
| 333 final ir.Class cls; | 335 final ir.Class cls; |
| 336 final ClassDefinition definition; |
| 334 bool isMixinApplication; | 337 bool isMixinApplication; |
| 335 | 338 |
| 336 InterfaceType thisType; | 339 InterfaceType thisType; |
| 337 InterfaceType rawType; | 340 InterfaceType rawType; |
| 338 InterfaceType supertype; | 341 InterfaceType supertype; |
| 339 InterfaceType mixedInType; | 342 InterfaceType mixedInType; |
| 340 List<InterfaceType> interfaces; | 343 List<InterfaceType> interfaces; |
| 341 OrderedTypeSet orderedTypeSet; | 344 OrderedTypeSet orderedTypeSet; |
| 342 | 345 |
| 343 Iterable<ConstantValue> _metadata; | 346 Iterable<ConstantValue> _metadata; |
| 344 | 347 |
| 345 ClassData(this.cls); | 348 ClassData(this.cls, this.definition); |
| 346 | 349 |
| 347 Iterable<ConstantValue> getMetadata(KernelToElementMapBase elementMap) { | 350 Iterable<ConstantValue> getMetadata(KernelToElementMapBase elementMap) { |
| 348 return _metadata ??= elementMap.getMetadata(cls.annotations); | 351 return _metadata ??= elementMap.getMetadata(cls.annotations); |
| 349 } | 352 } |
| 350 | 353 |
| 351 ClassData copy() { | 354 ClassData copy() { |
| 352 return new ClassData(cls); | 355 return new ClassData(cls, definition); |
| 353 } | 356 } |
| 354 } | 357 } |
| 355 | 358 |
| 356 class MemberData { | 359 class MemberData { |
| 360 /// TODO(johnniwinther): Remove this from the [MemberData] interface. Use |
| 361 /// `definition.node` instead. |
| 357 final ir.Member node; | 362 final ir.Member node; |
| 363 |
| 364 final MemberDefinition definition; |
| 365 |
| 358 Iterable<ConstantValue> _metadata; | 366 Iterable<ConstantValue> _metadata; |
| 359 | 367 |
| 360 MemberData(this.node); | 368 MemberData(this.node, this.definition); |
| 361 | 369 |
| 362 ResolutionImpact getWorldImpact(KernelToElementMapForImpact elementMap) { | 370 ResolutionImpact getWorldImpact(KernelToElementMapForImpact elementMap) { |
| 363 return buildKernelImpact(node, elementMap); | 371 return buildKernelImpact(node, elementMap); |
| 364 } | 372 } |
| 365 | 373 |
| 366 Iterable<ConstantValue> getMetadata(KernelToElementMapBase elementMap) { | 374 Iterable<ConstantValue> getMetadata(KernelToElementMapBase elementMap) { |
| 367 return _metadata ??= elementMap.getMetadata(node.annotations); | 375 return _metadata ??= elementMap.getMetadata(node.annotations); |
| 368 } | 376 } |
| 369 | 377 |
| 370 MemberData copy() { | 378 MemberData copy() { |
| 371 return new MemberData(node); | 379 return new MemberData(node, definition); |
| 372 } | 380 } |
| 373 } | 381 } |
| 374 | 382 |
| 375 class FunctionData extends MemberData { | 383 class FunctionData extends MemberData { |
| 376 final ir.FunctionNode functionNode; | 384 final ir.FunctionNode functionNode; |
| 377 FunctionType _type; | 385 FunctionType _type; |
| 378 | 386 |
| 379 FunctionData(ir.Member node, this.functionNode) : super(node); | 387 FunctionData(ir.Member node, this.functionNode, MemberDefinition definition) |
| 388 : super(node, definition); |
| 380 | 389 |
| 381 FunctionType getFunctionType(KernelToElementMapBase elementMap) { | 390 FunctionType getFunctionType(KernelToElementMapBase elementMap) { |
| 382 return _type ??= elementMap.getFunctionType(functionNode); | 391 return _type ??= elementMap.getFunctionType(functionNode); |
| 383 } | 392 } |
| 384 | 393 |
| 385 void forEachParameter(KernelToElementMapForBuilding elementMap, | 394 void forEachParameter(KernelToElementMapForBuilding elementMap, |
| 386 void f(DartType type, String name, ConstantValue defaultValue)) { | 395 void f(DartType type, String name, ConstantValue defaultValue)) { |
| 387 void handleParameter(ir.VariableDeclaration node, {bool isOptional: true}) { | 396 void handleParameter(ir.VariableDeclaration node, {bool isOptional: true}) { |
| 388 DartType type = elementMap.getDartType(node.type); | 397 DartType type = elementMap.getDartType(node.type); |
| 389 String name = node.name; | 398 String name = node.name; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 402 handleParameter(functionNode.positionalParameters[i], | 411 handleParameter(functionNode.positionalParameters[i], |
| 403 isOptional: i < functionNode.requiredParameterCount); | 412 isOptional: i < functionNode.requiredParameterCount); |
| 404 } | 413 } |
| 405 functionNode.namedParameters.toList() | 414 functionNode.namedParameters.toList() |
| 406 ..sort(namedOrdering) | 415 ..sort(namedOrdering) |
| 407 ..forEach(handleParameter); | 416 ..forEach(handleParameter); |
| 408 } | 417 } |
| 409 | 418 |
| 410 @override | 419 @override |
| 411 FunctionData copy() { | 420 FunctionData copy() { |
| 412 return new FunctionData(node, functionNode); | 421 return new FunctionData(node, functionNode, definition); |
| 413 } | 422 } |
| 414 } | 423 } |
| 415 | 424 |
| 416 class ConstructorData extends FunctionData { | 425 class ConstructorData extends FunctionData { |
| 417 ConstantConstructor _constantConstructor; | 426 ConstantConstructor _constantConstructor; |
| 418 ConstructorBodyEntity constructorBody; | 427 ConstructorBodyEntity constructorBody; |
| 419 | 428 |
| 420 ConstructorData(ir.Member node, ir.FunctionNode functionNode) | 429 ConstructorData( |
| 421 : super(node, functionNode); | 430 ir.Member node, ir.FunctionNode functionNode, MemberDefinition definition) |
| 431 : super(node, functionNode, definition); |
| 422 | 432 |
| 423 ConstantConstructor getConstructorConstant( | 433 ConstantConstructor getConstructorConstant( |
| 424 KernelToElementMapBase elementMap, ConstructorEntity constructor) { | 434 KernelToElementMapBase elementMap, ConstructorEntity constructor) { |
| 425 if (_constantConstructor == null) { | 435 if (_constantConstructor == null) { |
| 426 if (node is ir.Constructor && constructor.isConst) { | 436 if (node is ir.Constructor && constructor.isConst) { |
| 427 _constantConstructor = | 437 _constantConstructor = |
| 428 new Constantifier(elementMap).computeConstantConstructor(node); | 438 new Constantifier(elementMap).computeConstantConstructor(node); |
| 429 } else { | 439 } else { |
| 430 failedAt( | 440 failedAt( |
| 431 constructor, | 441 constructor, |
| 432 "Unexpected constructor $constructor in " | 442 "Unexpected constructor $constructor in " |
| 433 "KernelWorldBuilder._getConstructorConstant"); | 443 "KernelWorldBuilder._getConstructorConstant"); |
| 434 } | 444 } |
| 435 } | 445 } |
| 436 return _constantConstructor; | 446 return _constantConstructor; |
| 437 } | 447 } |
| 438 | 448 |
| 439 @override | 449 @override |
| 440 ConstructorData copy() { | 450 ConstructorData copy() { |
| 441 return new ConstructorData(node, functionNode); | 451 return new ConstructorData(node, functionNode, definition); |
| 442 } | 452 } |
| 443 } | 453 } |
| 444 | 454 |
| 445 class FieldData extends MemberData { | 455 class FieldData extends MemberData { |
| 446 ConstantExpression _constant; | 456 ConstantExpression _constant; |
| 447 | 457 |
| 448 FieldData(ir.Field node) : super(node); | 458 FieldData(ir.Field node, MemberDefinition definition) |
| 459 : super(node, definition); |
| 449 | 460 |
| 450 ir.Field get node => super.node; | 461 ir.Field get node => super.node; |
| 451 | 462 |
| 452 ConstantExpression getFieldConstant( | 463 ConstantExpression getFieldConstant( |
| 453 KernelToElementMapBase elementMap, FieldEntity field) { | 464 KernelToElementMapBase elementMap, FieldEntity field) { |
| 454 if (_constant == null) { | 465 if (_constant == null) { |
| 455 if (node.isConst) { | 466 if (node.isConst) { |
| 456 _constant = new Constantifier(elementMap).visit(node.initializer); | 467 _constant = new Constantifier(elementMap).visit(node.initializer); |
| 457 } else { | 468 } else { |
| 458 failedAt( | 469 failedAt( |
| 459 field, | 470 field, |
| 460 "Unexpected field $field in " | 471 "Unexpected field $field in " |
| 461 "KernelWorldBuilder._getConstructorConstant"); | 472 "KernelWorldBuilder._getConstructorConstant"); |
| 462 } | 473 } |
| 463 } | 474 } |
| 464 return _constant; | 475 return _constant; |
| 465 } | 476 } |
| 466 | 477 |
| 467 @override | 478 @override |
| 468 FieldData copy() { | 479 FieldData copy() { |
| 469 return new FieldData(node); | 480 return new FieldData(node, definition); |
| 470 } | 481 } |
| 471 } | 482 } |
| OLD | NEW |