Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: pkg/analyzer2dart/lib/src/converted_world.dart

Issue 2037123002: Cleanup: remove package "analyzer2dart". (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library analyzer2dart.convertedWorld;
6
7 import 'dart:collection';
8
9 import 'package:analyzer/analyzer.dart';
10 import 'package:compiler/src/dart_types.dart' as dart2js;
11 import 'package:compiler/src/elements/elements.dart' as dart2js;
12 import 'package:analyzer/src/generated/element.dart' as analyzer;
13 import 'package:compiler/src/cps_ir/cps_ir_nodes.dart' as ir;
14
15 import 'closed_world.dart';
16 import 'element_converter.dart';
17 import 'cps_generator.dart';
18 import 'util.dart';
19
20 /// A [ClosedWorld] converted to the dart2js element model.
21 abstract class ConvertedWorld {
22 Iterable<dart2js.LibraryElement> get libraries;
23 Iterable<dart2js.AstElement> get resolvedElements;
24 Iterable<dart2js.ClassElement> get instantiatedClasses;
25 dart2js.FunctionElement get mainFunction;
26 ir.Node getIr(dart2js.Element element);
27 dart2js.DartTypes get dartTypes;
28 }
29
30 class _ConvertedWorldImpl implements ConvertedWorld {
31 final dart2js.FunctionElement mainFunction;
32 Map<dart2js.AstElement, ir.Node> executableElements =
33 new HashMap<dart2js.AstElement, ir.Node>();
34 final List<dart2js.ClassElement> instantiatedClasses =
35 <dart2js.ClassElement>[];
36
37 _ConvertedWorldImpl(this.mainFunction);
38
39 // TODO(johnniwinther): Add all used libraries and all SDK libraries to the
40 // set of libraries in the converted world.
41 Iterable<dart2js.LibraryElement> get libraries => [mainFunction.library];
42
43 Iterable<dart2js.AstElement> get resolvedElements => executableElements.keys;
44
45 ir.Node getIr(dart2js.Element element) => executableElements[element];
46
47 final dart2js.DartTypes dartTypes = new _DartTypes();
48 }
49
50 ConvertedWorld convertWorld(ClosedWorld closedWorld) {
51 ElementConverter converter = new ElementConverter();
52 _ConvertedWorldImpl convertedWorld = new _ConvertedWorldImpl(
53 converter.convertElement(closedWorld.mainFunction));
54
55 void convert(analyzer.Element analyzerElement, AstNode node) {
56 // Skip conversion of SDK sources since we don't generate code for it
57 // anyway.
58 if (analyzerElement.source.isInSystemLibrary) return;
59
60 dart2js.AstElement dart2jsElement =
61 converter.convertElement(analyzerElement);
62 CpsElementVisitor visitor = new CpsElementVisitor(converter, node);
63 ir.Node cpsNode = analyzerElement.accept(visitor);
64 convertedWorld.executableElements[dart2jsElement] = cpsNode;
65 if (cpsNode == null && !analyzerElement.isSynthetic) {
66 String message =
67 'No CPS node generated for $analyzerElement (${node.runtimeType}).';
68 reportSourceMessage(analyzerElement.source, node, message);
69 throw new UnimplementedError(message);
70 }
71 }
72
73 void convertClass(analyzer.ClassElement analyzerElement, _) {
74 // Skip conversion of SDK sources since we don't generate code for it
75 // anyway.
76 if (analyzerElement.source.isInSystemLibrary) return;
77 convertedWorld.instantiatedClasses.add(
78 converter.convertElement(analyzerElement));
79 }
80
81 closedWorld.executableElements.forEach(convert);
82 closedWorld.variables.forEach(convert);
83 closedWorld.fields.forEach(convert);
84 closedWorld.instantiatedClasses.forEach(convertClass);
85
86 return convertedWorld;
87 }
88
89 // TODO(johnniwinther): Implement [coreTypes] using [TypeProvider].
90 class _DartTypes implements dart2js.DartTypes {
91 @override
92 get coreTypes => throw new UnsupportedError("coreTypes");
93
94 @override
95 bool isSubtype(dart2js.DartType t, dart2js.DartType s) {
96 throw new UnsupportedError("isSubtype");
97 }
98 }
OLDNEW
« no previous file with comments | « pkg/analyzer2dart/lib/src/closed_world.dart ('k') | pkg/analyzer2dart/lib/src/cps_generator.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698