| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 dev_compiler.src.codegen.reify_coercions; | 5 library dev_compiler.src.codegen.reify_coercions; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart' as analyzer; | 7 import 'package:analyzer/analyzer.dart' as analyzer; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/element.dart'; | 9 import 'package:analyzer/src/generated/element.dart'; |
| 10 import 'package:logging/logging.dart' as logger; | 10 import 'package:logging/logging.dart' as logger; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 var s = span.message("Cast"); | 69 var s = span.message("Cast"); |
| 70 return s.substring(0, s.indexOf("Cast")); | 70 return s.substring(0, s.indexOf("Cast")); |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 return null; | 73 return null; |
| 74 } | 74 } |
| 75 | 75 |
| 76 static String _conversionKind(Conversion node) { | 76 static String _conversionKind(Conversion node) { |
| 77 if (node is ClosureWrapLiteral) return "WrapLiteral"; | 77 if (node is ClosureWrapLiteral) return "WrapLiteral"; |
| 78 if (node is ClosureWrap) return "Wrap"; | 78 if (node is ClosureWrap) return "Wrap"; |
| 79 if (node is DownCastDynamic) return "CastDynamic"; | 79 if (node is DynamicCast) return "DynamicCast"; |
| 80 if (node is DownCastLiteral) return "CastLiteral"; | 80 if (node is AssignmentCast) return "AssignmentCast"; |
| 81 if (node is DownCastExact) return "CastExact"; | 81 if (node is InferableLiteral) return "InferableLiteral"; |
| 82 if (node is DownCast) return "CastGeneral"; | 82 if (node is InferableClosure) return "InferableClosure"; |
| 83 if (node is InferableAllocation) return "InferableAllocation"; |
| 84 if (node is DownCastComposite) return "CompositeCast"; |
| 85 if (node is DownCastImplicit) return "ImplicitCast"; |
| 83 assert(false); | 86 assert(false); |
| 84 return ""; | 87 return ""; |
| 85 } | 88 } |
| 86 | 89 |
| 87 @override | 90 @override |
| 88 Object visitAsExpression(AsExpression e) { | 91 Object visitAsExpression(AsExpression e) { |
| 89 var cast = Coercion.cast(_rules.getStaticType(e.expression), e.type.type); | 92 var cast = Coercion.cast(_rules.getStaticType(e.expression), e.type.type); |
| 90 var loc = _locationInfo(e); | 93 var loc = _locationInfo(e); |
| 91 Expression castNode = | 94 Expression castNode = |
| 92 _cm.coerceExpression(e.expression, cast, "CastUser", loc); | 95 _cm.coerceExpression(e.expression, cast, "CastUser", loc); |
| 93 if (!NodeReplacer.replace(e, castNode)) { | 96 if (!NodeReplacer.replace(e, castNode)) { |
| 94 _log.severe("Failed to replace node for DownCast"); | 97 _log.severe("Failed to replace node for DownCast"); |
| 95 } | 98 } |
| 96 castNode.accept(this); | 99 castNode.accept(this); |
| 97 return null; | 100 return null; |
| 98 } | 101 } |
| 99 | 102 |
| 100 @override | 103 @override |
| 101 Object visitDownCastBase(DownCastBase node) { | 104 Object visitDownCast(DownCast node) { |
| 102 if (_skipCoercions) { | 105 if (_skipCoercions) { |
| 103 _log.severe("Skipping runtime downcast in constant context"); | 106 _log.severe("Skipping runtime downcast in constant context"); |
| 104 return null; | 107 return null; |
| 105 } | 108 } |
| 106 String kind = _conversionKind(node); | 109 String kind = _conversionKind(node); |
| 107 var loc = _locationInfo(node); | 110 var loc = _locationInfo(node); |
| 108 Expression castNode = _cm.coerceExpression(node.node, node.cast, kind, loc); | 111 Expression castNode = _cm.coerceExpression(node.node, node.cast, kind, loc); |
| 109 if (!NodeReplacer.replace(node, castNode)) { | 112 if (!NodeReplacer.replace(node, castNode)) { |
| 110 _log.severe("Failed to replace node for DownCast"); | 113 _log.severe("Failed to replace node for DownCast"); |
| 111 } | 114 } |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 Expression _typeExpression(TypeName t) { | 660 Expression _typeExpression(TypeName t) { |
| 658 if (t.typeArguments != null && t.typeArguments.length > 0) { | 661 if (t.typeArguments != null && t.typeArguments.length > 0) { |
| 659 var w = AstBuilder.identifierFromString("_"); | 662 var w = AstBuilder.identifierFromString("_"); |
| 660 var fp = AstBuilder.simpleFormal(w, t); | 663 var fp = AstBuilder.simpleFormal(w, t); |
| 661 var f = AstBuilder.blockFunction(<FormalParameter>[fp], <Statement>[]); | 664 var f = AstBuilder.blockFunction(<FormalParameter>[fp], <Statement>[]); |
| 662 return new RuntimeOperation("type", <Expression>[f]); | 665 return new RuntimeOperation("type", <Expression>[f]); |
| 663 } | 666 } |
| 664 return t.name; | 667 return t.name; |
| 665 } | 668 } |
| 666 } | 669 } |
| OLD | NEW |