Chromium Code Reviews| 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 import 'package:analyzer/analyzer.dart' as analyzer; | 5 import 'package:analyzer/analyzer.dart' as analyzer; |
| 6 import 'package:analyzer/src/generated/ast.dart'; | 6 import 'package:analyzer/src/generated/ast.dart'; |
| 7 import 'package:analyzer/src/generated/element.dart'; | 7 import 'package:analyzer/src/generated/element.dart'; |
| 8 import 'package:analyzer/src/generated/type_system.dart' | 8 import 'package:analyzer/src/generated/type_system.dart' |
| 9 show StrongTypeSystemImpl; | 9 show StrongTypeSystemImpl; |
| 10 import 'package:analyzer/src/task/strong/info.dart'; | |
| 11 | |
| 10 import 'package:logging/logging.dart' as logger; | 12 import 'package:logging/logging.dart' as logger; |
| 11 | 13 |
| 12 import '../info.dart'; | |
| 13 | |
| 14 import 'ast_builder.dart'; | 14 import 'ast_builder.dart'; |
| 15 | 15 |
| 16 final _log = new logger.Logger('dev_compiler.reify_coercions'); | 16 final _log = new logger.Logger('dev_compiler.reify_coercions'); |
| 17 | 17 |
| 18 // TODO(leafp) Factor this out or use an existing library | 18 // TODO(leafp) Factor this out or use an existing library |
| 19 class Tuple2<T0, T1> { | 19 class Tuple2<T0, T1> { |
| 20 final T0 e0; | 20 final T0 e0; |
| 21 final T1 e1; | 21 final T1 e1; |
| 22 Tuple2(this.e0, this.e1); | 22 Tuple2(this.e0, this.e1); |
| 23 } | 23 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 36 bool synthetic; | 36 bool synthetic; |
| 37 NewTypeIdDesc({this.fromCurrent, this.importedFrom, this.synthetic}); | 37 NewTypeIdDesc({this.fromCurrent, this.importedFrom, this.synthetic}); |
| 38 } | 38 } |
| 39 | 39 |
| 40 // This class implements a pass which modifies (in place) the ast replacing | 40 // This class implements a pass which modifies (in place) the ast replacing |
| 41 // abstract coercion nodes with their dart implementations. | 41 // abstract coercion nodes with their dart implementations. |
| 42 class CoercionReifier extends analyzer.GeneralizingAstVisitor<Object> { | 42 class CoercionReifier extends analyzer.GeneralizingAstVisitor<Object> { |
| 43 final CoercionManager _cm; | 43 final CoercionManager _cm; |
| 44 final TypeManager _tm; | 44 final TypeManager _tm; |
| 45 final VariableManager _vm; | 45 final VariableManager _vm; |
| 46 final LibraryUnit _library; | |
| 47 final StrongTypeSystemImpl _typeSystem; | 46 final StrongTypeSystemImpl _typeSystem; |
| 48 | 47 |
| 49 CoercionReifier._( | 48 CoercionReifier._(this._cm, this._tm, this._vm, this._typeSystem); |
| 50 this._cm, this._tm, this._vm, this._library, this._typeSystem); | |
| 51 | 49 |
| 52 factory CoercionReifier( | 50 factory CoercionReifier( |
| 53 LibraryUnit library, StrongTypeSystemImpl typeSystem) { | 51 LibraryElement library, StrongTypeSystemImpl typeSystem) { |
| 54 var vm = new VariableManager(); | 52 var vm = new VariableManager(); |
| 55 var tm = new TypeManager(library.library.element.enclosingElement, vm); | 53 var tm = new TypeManager(library, vm); |
| 56 var cm = new CoercionManager(vm, tm); | 54 var cm = new CoercionManager(vm, tm); |
| 57 return new CoercionReifier._(cm, tm, vm, library, typeSystem); | 55 return new CoercionReifier._(cm, tm, vm, typeSystem); |
| 58 } | 56 } |
| 59 | 57 |
| 60 // This should be the entry point for this class. Entering via the | 58 // This should be the entry point for this class. Entering via the |
| 61 // visit functions directly may not do the right thing with respect | 59 // visit functions directly may not do the right thing with respect |
| 62 // to discharging the collected definitions. | 60 // to discharging the collected definitions. |
| 63 // Returns the set of new type identifiers added by the reifier | 61 // Returns the set of new type identifiers added by the reifier |
| 64 Map<Identifier, NewTypeIdDesc> reify() { | 62 Map<Identifier, NewTypeIdDesc> reify(List<CompilationUnit> units) { |
| 65 _library.partsThenLibrary.forEach(visitCompilationUnit); | 63 units.forEach(visitCompilationUnit); |
| 64 // TODO(jmesserly): what is going on here? We are dropping these typedefs | |
|
Jennifer Messerly
2016/03/12 01:37:36
Note, I actually fixed this TODO already in: https
| |
| 65 // on the floor. Either they aren't needed when compiling to JS, or we | |
| 66 // need to emit something for them. | |
| 66 return _tm.addedTypes; | 67 return _tm.addedTypes; |
| 67 } | 68 } |
| 68 | 69 |
| 69 @override | 70 @override |
| 70 Object visitExpression(Expression node) { | 71 Object visitExpression(Expression node) { |
| 71 var info = CoercionInfo.get(node); | 72 var info = CoercionInfo.get(node); |
| 72 if (info is InferredTypeBase) { | 73 if (info is InferredTypeBase) { |
| 73 return _visitInferredTypeBase(info, node); | 74 return _visitInferredTypeBase(info, node); |
| 74 } else if (info is DownCast) { | 75 } else if (info is DownCast) { |
| 75 return _visitDownCast(info, node); | 76 return _visitDownCast(info, node); |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 var t = _mkNewTypeName(dType, id, args); | 454 var t = _mkNewTypeName(dType, id, args); |
| 454 return t; | 455 return t; |
| 455 } | 456 } |
| 456 | 457 |
| 457 TypeName _mkNewTypeName(DartType type, Identifier id, List<TypeName> args) { | 458 TypeName _mkNewTypeName(DartType type, Identifier id, List<TypeName> args) { |
| 458 var t = AstBuilder.typeName(id, args); | 459 var t = AstBuilder.typeName(id, args); |
| 459 t.type = type; | 460 t.type = type; |
| 460 return t; | 461 return t; |
| 461 } | 462 } |
| 462 } | 463 } |
| OLD | NEW |