| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 var cm = new CoercionManager(vm, tm); | 104 var cm = new CoercionManager(vm, tm); |
| 105 var inferrer = new _Inference(compiler.rules, tm); | 105 var inferrer = new _Inference(compiler.rules, tm); |
| 106 return new CoercionReifier._(cm, tm, vm, library, inferrer); | 106 return new CoercionReifier._(cm, tm, vm, library, inferrer); |
| 107 } | 107 } |
| 108 | 108 |
| 109 // This should be the entry point for this class. Entering via the | 109 // This should be the entry point for this class. Entering via the |
| 110 // visit functions directly may not do the right thing with respect | 110 // visit functions directly may not do the right thing with respect |
| 111 // to discharging the collected definitions. | 111 // to discharging the collected definitions. |
| 112 // Returns the set of new type identifiers added by the reifier | 112 // Returns the set of new type identifiers added by the reifier |
| 113 Map<Identifier, NewTypeIdDesc> reify() { | 113 Map<Identifier, NewTypeIdDesc> reify() { |
| 114 _library.partsThenLibrary.forEach(generateUnit); | 114 _library.partsThenLibrary.forEach(visitCompilationUnit); |
| 115 return _tm.addedTypes; | 115 return _tm.addedTypes; |
| 116 } | 116 } |
| 117 | 117 |
| 118 void generateUnit(CompilationUnit unit) { | |
| 119 visitCompilationUnit(unit); | |
| 120 } | |
| 121 | |
| 122 @override | 118 @override |
| 123 Object visitExpression(Expression node) { | 119 Object visitExpression(Expression node) { |
| 124 var info = CoercionInfo.get(node); | 120 var info = CoercionInfo.get(node); |
| 125 if (info is InferredTypeBase) { | 121 if (info is InferredTypeBase) { |
| 126 return _visitInferredTypeBase(info); | 122 return _visitInferredTypeBase(info, node); |
| 127 } else if (info is DownCast) { | 123 } else if (info is DownCast) { |
| 128 return _visitDownCast(info); | 124 return _visitDownCast(info, node); |
| 129 } | 125 } |
| 130 return super.visitExpression(node); | 126 return super.visitExpression(node); |
| 131 } | 127 } |
| 132 | 128 |
| 133 ///////////////// Private ////////////////////////////////// | 129 ///////////////// Private ////////////////////////////////// |
| 134 | 130 |
| 135 Object _visitInferredTypeBase(InferredTypeBase node) { | 131 Object _visitInferredTypeBase(InferredTypeBase node, Expression expr) { |
| 136 var expr = node.node; | |
| 137 var success = _inferrer.inferExpression(expr, node.type, <String>[]); | 132 var success = _inferrer.inferExpression(expr, node.type, <String>[]); |
| 138 assert(success); | 133 assert(success); |
| 139 expr.visitChildren(this); | 134 expr.visitChildren(this); |
| 140 return null; | 135 return null; |
| 141 } | 136 } |
| 142 | 137 |
| 143 Object _visitDownCast(DownCast node) { | 138 Object _visitDownCast(DownCast node, Expression expr) { |
| 144 var expr = node.node; | |
| 145 var parent = expr.parent; | 139 var parent = expr.parent; |
| 146 expr.visitChildren(this); | 140 expr.visitChildren(this); |
| 147 Expression newE = _cm.coerceExpression(expr, node.cast); | 141 Expression newE = _cm.coerceExpression(expr, node.cast); |
| 148 if (!identical(expr, newE)) { | 142 if (!identical(expr, newE)) { |
| 149 var replaced = parent.accept(new NodeReplacer(expr, newE)); | 143 var replaced = parent.accept(new NodeReplacer(expr, newE)); |
| 150 // It looks like NodeReplacer will always return true. | 144 // It looks like NodeReplacer will always return true. |
| 151 // It does throw IllegalArgumentException though, if child is not found. | 145 // It does throw IllegalArgumentException though, if child is not found. |
| 152 assert(replaced); | 146 assert(replaced); |
| 153 } | 147 } |
| 154 return null; | 148 return null; |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 var t = _mkNewTypeName(dType, id, args); | 492 var t = _mkNewTypeName(dType, id, args); |
| 499 return t; | 493 return t; |
| 500 } | 494 } |
| 501 | 495 |
| 502 TypeName _mkNewTypeName(DartType type, Identifier id, List<TypeName> args) { | 496 TypeName _mkNewTypeName(DartType type, Identifier id, List<TypeName> args) { |
| 503 var t = AstBuilder.typeName(id, args); | 497 var t = AstBuilder.typeName(id, args); |
| 504 t.type = type; | 498 t.type = type; |
| 505 return t; | 499 return t; |
| 506 } | 500 } |
| 507 } | 501 } |
| OLD | NEW |