| 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 21 matching lines...) Expand all Loading... |
| 32 final Wrapper wrapper; | 32 final Wrapper wrapper; |
| 33 _LocatedWrapper(this.wrapper, this.loc); | 33 _LocatedWrapper(this.wrapper, this.loc); |
| 34 } | 34 } |
| 35 | 35 |
| 36 class _Inference extends DownwardsInference { | 36 class _Inference extends DownwardsInference { |
| 37 TypeManager _tm; | 37 TypeManager _tm; |
| 38 | 38 |
| 39 _Inference(TypeRules rules, this._tm) : super(rules); | 39 _Inference(TypeRules rules, this._tm) : super(rules); |
| 40 | 40 |
| 41 @override | 41 @override |
| 42 void annotateCastFromDynamic(Expression e, DartType t) { |
| 43 var cast = Coercion.cast(e.staticType, t); |
| 44 var node = new DynamicCast(rules, e, cast); |
| 45 if (!NodeReplacer.replace(e, node)) { |
| 46 _log.severe("Failed to replace node for DownCast"); |
| 47 } |
| 48 } |
| 49 |
| 50 @override |
| 42 void annotateListLiteral(ListLiteral e, List<DartType> targs) { | 51 void annotateListLiteral(ListLiteral e, List<DartType> targs) { |
| 43 var tNames = targs.map(_tm.typeNameFromDartType).toList(); | 52 var tNames = targs.map(_tm.typeNameFromDartType).toList(); |
| 44 e.typeArguments = AstBuilder.typeArgumentList(tNames); | 53 e.typeArguments = AstBuilder.typeArgumentList(tNames); |
| 45 var listT = rules.provider.listType.substitute4(targs); | 54 var listT = rules.provider.listType.substitute4(targs); |
| 46 e.staticType = listT; | 55 e.staticType = listT; |
| 47 } | 56 } |
| 48 | 57 |
| 49 @override | 58 @override |
| 50 void annotateMapLiteral(MapLiteral e, List<DartType> targs) { | 59 void annotateMapLiteral(MapLiteral e, List<DartType> targs) { |
| 51 var tNames = targs.map(_tm.typeNameFromDartType).toList(); | 60 var tNames = targs.map(_tm.typeNameFromDartType).toList(); |
| 52 e.typeArguments = AstBuilder.typeArgumentList(tNames); | 61 e.typeArguments = AstBuilder.typeArgumentList(tNames); |
| 53 var mapT = rules.provider.mapType.substitute4(targs); | 62 var mapT = rules.provider.mapType.substitute4(targs); |
| 54 e.staticType = mapT; | 63 e.staticType = mapT; |
| 55 } | 64 } |
| 56 | 65 |
| 57 @override | 66 @override |
| 58 void annotateInstanceCreationExpression( | 67 void annotateInstanceCreationExpression( |
| 59 InstanceCreationExpression e, List<DartType> targs) { | 68 InstanceCreationExpression e, List<DartType> targs) { |
| 60 var tNames = targs.map(_tm.typeNameFromDartType).toList(); | 69 var tNames = targs.map(_tm.typeNameFromDartType).toList(); |
| 61 var cName = e.constructorName; | 70 var cName = e.constructorName; |
| 62 var id = cName.type.name; | 71 var id = cName.type.name; |
| 63 var typeName = AstBuilder.typeName(id, tNames); | 72 var typeName = AstBuilder.typeName(id, tNames); |
| 64 cName.type = typeName; | 73 cName.type = typeName; |
| 65 var rawType = (e.staticType.element as ClassElement).type; | 74 var rawType = (e.staticType.element as ClassElement).type; |
| 66 e.staticType = rawType.substitute4(targs); | 75 e.staticType = rawType.substitute4(targs); |
| 67 } | 76 } |
| 77 |
| 78 @override |
| 79 void annotateFunctionExpression(FunctionExpression e, DartType returnType) { |
| 80 // Implicitly changes e.staticType |
| 81 (e.element as ExecutableElementImpl).returnType = returnType; |
| 82 } |
| 68 } | 83 } |
| 69 | 84 |
| 70 // This class implements a pass which modifies (in place) the ast replacing | 85 // This class implements a pass which modifies (in place) the ast replacing |
| 71 // abstract coercion nodes with their dart implementations. | 86 // abstract coercion nodes with their dart implementations. |
| 72 class UnitCoercionReifier extends analyzer.GeneralizingAstVisitor<Object> | 87 class UnitCoercionReifier extends analyzer.GeneralizingAstVisitor<Object> |
| 73 with ConversionVisitor<Object> { | 88 with ConversionVisitor<Object> { |
| 74 CoercionManager _cm; | 89 CoercionManager _cm; |
| 75 final TypeManager _tm; | 90 final TypeManager _tm; |
| 76 final VariableManager _vm; | 91 final VariableManager _vm; |
| 77 SourceFile _file; | 92 SourceFile _file; |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 Expression _typeExpression(TypeName t) { | 721 Expression _typeExpression(TypeName t) { |
| 707 if (t.typeArguments != null && t.typeArguments.length > 0) { | 722 if (t.typeArguments != null && t.typeArguments.length > 0) { |
| 708 var w = AstBuilder.identifierFromString("_"); | 723 var w = AstBuilder.identifierFromString("_"); |
| 709 var fp = AstBuilder.simpleFormal(w, t); | 724 var fp = AstBuilder.simpleFormal(w, t); |
| 710 var f = AstBuilder.blockFunction(<FormalParameter>[fp], <Statement>[]); | 725 var f = AstBuilder.blockFunction(<FormalParameter>[fp], <Statement>[]); |
| 711 return new RuntimeOperation("type", <Expression>[f]); | 726 return new RuntimeOperation("type", <Expression>[f]); |
| 712 } | 727 } |
| 713 return t.name; | 728 return t.name; |
| 714 } | 729 } |
| 715 } | 730 } |
| OLD | NEW |