| 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/dart/ast/ast.dart'; | 6 import 'package:analyzer/dart/ast/ast.dart'; |
| 7 import 'package:analyzer/dart/element/element.dart'; | 7 import 'package:analyzer/dart/element/element.dart'; |
| 8 import 'package:analyzer/dart/element/type.dart'; | 8 import 'package:analyzer/dart/element/type.dart'; |
| 9 import 'package:analyzer/src/dart/ast/utilities.dart' show NodeReplacer; | 9 import 'package:analyzer/src/dart/ast/utilities.dart' show NodeReplacer; |
| 10 import 'package:analyzer/src/generated/type_system.dart' | 10 import 'package:analyzer/src/generated/type_system.dart' |
| 11 show StrongTypeSystemImpl; | 11 show StrongTypeSystemImpl; |
| 12 import 'package:analyzer/src/task/strong/info.dart'; |
| 12 import 'package:logging/logging.dart' as logger; | 13 import 'package:logging/logging.dart' as logger; |
| 13 | 14 |
| 14 import '../info.dart'; | 15 import 'ast_builder.dart'; |
| 15 import '../utils.dart' show getStaticType; | 16 import '../utils.dart' show getStaticType; |
| 16 import 'ast_builder.dart'; | |
| 17 | 17 |
| 18 final _log = new logger.Logger('dev_compiler.reify_coercions'); | 18 final _log = new logger.Logger('dev_compiler.reify_coercions'); |
| 19 | 19 |
| 20 class NewTypeIdDesc { | 20 class NewTypeIdDesc { |
| 21 /// If null, then this is not a library level identifier (i.e. it's | 21 /// If null, then this is not a library level identifier (i.e. it's |
| 22 /// a type parameter, or a special type like void, dynamic, etc) | 22 /// a type parameter, or a special type like void, dynamic, etc) |
| 23 LibraryElement importedFrom; | 23 LibraryElement importedFrom; |
| 24 | 24 |
| 25 /// True => use/def in same library | 25 /// True => use/def in same library |
| 26 bool fromCurrent; | 26 bool fromCurrent; |
| 27 | 27 |
| 28 /// True => not a source variable | 28 /// True => not a source variable |
| 29 bool synthetic; | 29 bool synthetic; |
| 30 NewTypeIdDesc({this.fromCurrent, this.importedFrom, this.synthetic}); | 30 NewTypeIdDesc({this.fromCurrent, this.importedFrom, this.synthetic}); |
| 31 } | 31 } |
| 32 | 32 |
| 33 // This class implements a pass which modifies (in place) the ast replacing | 33 // This class implements a pass which modifies (in place) the ast replacing |
| 34 // abstract coercion nodes with their dart implementations. | 34 // abstract coercion nodes with their dart implementations. |
| 35 class CoercionReifier extends analyzer.GeneralizingAstVisitor<Object> { | 35 class CoercionReifier extends analyzer.GeneralizingAstVisitor<Object> { |
| 36 final LibraryUnit _library; | |
| 37 final StrongTypeSystemImpl _typeSystem; | 36 final StrongTypeSystemImpl _typeSystem; |
| 38 | 37 |
| 39 CoercionReifier(this._library, this._typeSystem); | 38 CoercionReifier(this._typeSystem); |
| 40 | 39 |
| 41 // This should be the entry point for this class. Entering via the | 40 /// This should be the entry point for this class. |
| 42 // visit functions directly may not do the right thing with respect | 41 /// |
| 43 // to discharging the collected definitions. | 42 /// Entering via the visit functions directly may not do the right |
| 44 // Returns the set of new type identifiers added by the reifier | 43 /// thing with respect to discharging the collected definitions. |
| 45 void reify() { | 44 /// |
| 46 _library.partsThenLibrary.forEach(visitCompilationUnit); | 45 /// Returns the set of new type identifiers added by the reifier |
| 46 void reify(List<CompilationUnit> units) { |
| 47 units.forEach(visitCompilationUnit); |
| 47 } | 48 } |
| 48 | 49 |
| 49 @override | 50 @override |
| 50 Object visitExpression(Expression node) { | 51 Object visitExpression(Expression node) { |
| 51 var info = CoercionInfo.get(node); | 52 var info = CoercionInfo.get(node); |
| 52 if (info is InferredTypeBase) { | 53 if (info is InferredTypeBase) { |
| 53 return _visitInferredTypeBase(info, node); | 54 return _visitInferredTypeBase(info, node); |
| 54 } else if (info is DownCast) { | 55 } else if (info is DownCast) { |
| 55 return _visitDownCast(info, node); | 56 return _visitDownCast(info, node); |
| 56 } | 57 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 Expression _castExpression(Expression e, Cast c) { | 104 Expression _castExpression(Expression e, Cast c) { |
| 104 // We use an empty name in the AST, because the JS code generator only cares | 105 // We use an empty name in the AST, because the JS code generator only cares |
| 105 // about the target type. It does not look at the AST name. | 106 // about the target type. It does not look at the AST name. |
| 106 var typeName = new TypeName(AstBuilder.identifierFromString(''), null); | 107 var typeName = new TypeName(AstBuilder.identifierFromString(''), null); |
| 107 typeName.type = c.toType; | 108 typeName.type = c.toType; |
| 108 var cast = AstBuilder.asExpression(e, typeName); | 109 var cast = AstBuilder.asExpression(e, typeName); |
| 109 cast.staticType = c.toType; | 110 cast.staticType = c.toType; |
| 110 return cast; | 111 return cast; |
| 111 } | 112 } |
| 112 } | 113 } |
| OLD | NEW |