| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 analyzer2dart.convertedWorld; | 5 library analyzer2dart.convertedWorld; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
| 10 import 'package:compiler/src/dart_types.dart' as dart2js; |
| 10 import 'package:compiler/src/elements/elements.dart' as dart2js; | 11 import 'package:compiler/src/elements/elements.dart' as dart2js; |
| 11 import 'package:analyzer/src/generated/element.dart' as analyzer; | 12 import 'package:analyzer/src/generated/element.dart' as analyzer; |
| 12 import 'package:compiler/src/cps_ir/cps_ir_nodes.dart' as ir; | 13 import 'package:compiler/src/cps_ir/cps_ir_nodes.dart' as ir; |
| 13 | 14 |
| 14 import 'closed_world.dart'; | 15 import 'closed_world.dart'; |
| 15 import 'element_converter.dart'; | 16 import 'element_converter.dart'; |
| 16 import 'cps_generator.dart'; | 17 import 'cps_generator.dart'; |
| 17 import 'util.dart'; | 18 import 'util.dart'; |
| 18 | 19 |
| 19 /// A [ClosedWorld] converted to the dart2js element model. | 20 /// A [ClosedWorld] converted to the dart2js element model. |
| 20 abstract class ConvertedWorld { | 21 abstract class ConvertedWorld { |
| 21 Iterable<dart2js.LibraryElement> get libraries; | 22 Iterable<dart2js.LibraryElement> get libraries; |
| 22 Iterable<dart2js.AstElement> get resolvedElements; | 23 Iterable<dart2js.AstElement> get resolvedElements; |
| 23 Iterable<dart2js.ClassElement> get instantiatedClasses; | 24 Iterable<dart2js.ClassElement> get instantiatedClasses; |
| 24 dart2js.FunctionElement get mainFunction; | 25 dart2js.FunctionElement get mainFunction; |
| 25 ir.Node getIr(dart2js.Element element); | 26 ir.Node getIr(dart2js.Element element); |
| 26 | 27 dart2js.DartTypes get dartTypes; |
| 27 } | 28 } |
| 28 | 29 |
| 29 class _ConvertedWorldImpl implements ConvertedWorld { | 30 class _ConvertedWorldImpl implements ConvertedWorld { |
| 30 final dart2js.FunctionElement mainFunction; | 31 final dart2js.FunctionElement mainFunction; |
| 31 Map<dart2js.AstElement, ir.Node> executableElements = | 32 Map<dart2js.AstElement, ir.Node> executableElements = |
| 32 new HashMap<dart2js.AstElement, ir.Node>(); | 33 new HashMap<dart2js.AstElement, ir.Node>(); |
| 33 | 34 |
| 34 _ConvertedWorldImpl(this.mainFunction); | 35 _ConvertedWorldImpl(this.mainFunction); |
| 35 | 36 |
| 36 // TODO(johnniwinther): Add all used libraries and all SDK libraries to the | 37 // TODO(johnniwinther): Add all used libraries and all SDK libraries to the |
| 37 // set of libraries in the converted world. | 38 // set of libraries in the converted world. |
| 38 Iterable<dart2js.LibraryElement> get libraries => [mainFunction.library]; | 39 Iterable<dart2js.LibraryElement> get libraries => [mainFunction.library]; |
| 39 | 40 |
| 40 Iterable<dart2js.AstElement> get resolvedElements => executableElements.keys; | 41 Iterable<dart2js.AstElement> get resolvedElements => executableElements.keys; |
| 41 | 42 |
| 42 Iterable<dart2js.ClassElement> get instantiatedClasses => []; | 43 Iterable<dart2js.ClassElement> get instantiatedClasses => []; |
| 43 | 44 |
| 44 ir.Node getIr(dart2js.Element element) => executableElements[element]; | 45 ir.Node getIr(dart2js.Element element) => executableElements[element]; |
| 46 |
| 47 final dart2js.DartTypes dartTypes = new _DartTypes(); |
| 45 } | 48 } |
| 46 | 49 |
| 47 ConvertedWorld convertWorld(ClosedWorld closedWorld) { | 50 ConvertedWorld convertWorld(ClosedWorld closedWorld) { |
| 48 ElementConverter converter = new ElementConverter(); | 51 ElementConverter converter = new ElementConverter(); |
| 49 _ConvertedWorldImpl convertedWorld = new _ConvertedWorldImpl( | 52 _ConvertedWorldImpl convertedWorld = new _ConvertedWorldImpl( |
| 50 converter.convertElement(closedWorld.mainFunction)); | 53 converter.convertElement(closedWorld.mainFunction)); |
| 51 | 54 |
| 52 void convert(analyzer.Element analyzerElement, AstNode node) { | 55 void convert(analyzer.Element analyzerElement, AstNode node) { |
| 53 // Skip conversion of SDK sources since we don't generate code for it | 56 // Skip conversion of SDK sources since we don't generate code for it |
| 54 // anyway. | 57 // anyway. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 67 throw new UnimplementedError(message); | 70 throw new UnimplementedError(message); |
| 68 } | 71 } |
| 69 } | 72 } |
| 70 | 73 |
| 71 closedWorld.executableElements.forEach(convert); | 74 closedWorld.executableElements.forEach(convert); |
| 72 closedWorld.variables.forEach(convert); | 75 closedWorld.variables.forEach(convert); |
| 73 closedWorld.fields.forEach(convert); | 76 closedWorld.fields.forEach(convert); |
| 74 | 77 |
| 75 return convertedWorld; | 78 return convertedWorld; |
| 76 } | 79 } |
| 80 |
| 81 // TODO(johnniwinther): Implement [coreTypes] using [TypeProvider]. |
| 82 class _DartTypes implements dart2js.DartTypes { |
| 83 @override |
| 84 get coreTypes => throw new UnsupportedError("coreTypes"); |
| 85 |
| 86 @override |
| 87 bool isSubtype(dart2js.DartType t, dart2js.DartType s) { |
| 88 throw new UnsupportedError("isSubtype"); |
| 89 } |
| 90 } |
| OLD | NEW |