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

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

Issue 900403003: Support default constructors in analyzer2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated to generate CPS for default constructors. Created 5 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analyzer2dart/lib/src/tree_shaker.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/dart_types.dart' as dart2js;
(...skipping 13 matching lines...) Expand all
24 Iterable<dart2js.ClassElement> get instantiatedClasses; 24 Iterable<dart2js.ClassElement> get instantiatedClasses;
25 dart2js.FunctionElement get mainFunction; 25 dart2js.FunctionElement get mainFunction;
26 ir.Node getIr(dart2js.Element element); 26 ir.Node getIr(dart2js.Element element);
27 dart2js.DartTypes get dartTypes; 27 dart2js.DartTypes get dartTypes;
28 } 28 }
29 29
30 class _ConvertedWorldImpl implements ConvertedWorld { 30 class _ConvertedWorldImpl implements ConvertedWorld {
31 final dart2js.FunctionElement mainFunction; 31 final dart2js.FunctionElement mainFunction;
32 Map<dart2js.AstElement, ir.Node> executableElements = 32 Map<dart2js.AstElement, ir.Node> executableElements =
33 new HashMap<dart2js.AstElement, ir.Node>(); 33 new HashMap<dart2js.AstElement, ir.Node>();
34 final List<dart2js.ClassElement> instantiatedClasses =
35 <dart2js.ClassElement>[];
34 36
35 _ConvertedWorldImpl(this.mainFunction); 37 _ConvertedWorldImpl(this.mainFunction);
36 38
37 // TODO(johnniwinther): Add all used libraries and all SDK libraries to the 39 // TODO(johnniwinther): Add all used libraries and all SDK libraries to the
38 // set of libraries in the converted world. 40 // set of libraries in the converted world.
39 Iterable<dart2js.LibraryElement> get libraries => [mainFunction.library]; 41 Iterable<dart2js.LibraryElement> get libraries => [mainFunction.library];
40 42
41 Iterable<dart2js.AstElement> get resolvedElements => executableElements.keys; 43 Iterable<dart2js.AstElement> get resolvedElements => executableElements.keys;
42 44
43 Iterable<dart2js.ClassElement> get instantiatedClasses => [];
44
45 ir.Node getIr(dart2js.Element element) => executableElements[element]; 45 ir.Node getIr(dart2js.Element element) => executableElements[element];
46 46
47 final dart2js.DartTypes dartTypes = new _DartTypes(); 47 final dart2js.DartTypes dartTypes = new _DartTypes();
48 } 48 }
49 49
50 ConvertedWorld convertWorld(ClosedWorld closedWorld) { 50 ConvertedWorld convertWorld(ClosedWorld closedWorld) {
51 ElementConverter converter = new ElementConverter(); 51 ElementConverter converter = new ElementConverter();
52 _ConvertedWorldImpl convertedWorld = new _ConvertedWorldImpl( 52 _ConvertedWorldImpl convertedWorld = new _ConvertedWorldImpl(
53 converter.convertElement(closedWorld.mainFunction)); 53 converter.convertElement(closedWorld.mainFunction));
54 54
55 void convert(analyzer.Element analyzerElement, AstNode node) { 55 void convert(analyzer.Element analyzerElement, AstNode node) {
56 // 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
57 // anyway. 57 // anyway.
58 if (analyzerElement.source.isInSystemLibrary) return; 58 if (analyzerElement.source.isInSystemLibrary) return;
59 59
60 dart2js.AstElement dart2jsElement = 60 dart2js.AstElement dart2jsElement =
61 converter.convertElement(analyzerElement); 61 converter.convertElement(analyzerElement);
62 CpsElementVisitor visitor = new CpsElementVisitor(converter, node); 62 CpsElementVisitor visitor = new CpsElementVisitor(converter, node);
63 ir.Node cpsNode = analyzerElement.accept(visitor); 63 ir.Node cpsNode = analyzerElement.accept(visitor);
64 if (cpsNode != null) { 64 convertedWorld.executableElements[dart2jsElement] = cpsNode;
65 convertedWorld.executableElements[dart2jsElement] = cpsNode; 65 if (cpsNode == null && !analyzerElement.isSynthetic) {
66 } else {
67 String message = 66 String message =
68 'No CPS node generated for $analyzerElement (${node.runtimeType}).'; 67 'No CPS node generated for $analyzerElement (${node.runtimeType}).';
69 reportSourceMessage(analyzerElement.source, node, message); 68 reportSourceMessage(analyzerElement.source, node, message);
70 throw new UnimplementedError(message); 69 throw new UnimplementedError(message);
71 } 70 }
72 } 71 }
73 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
74 closedWorld.executableElements.forEach(convert); 81 closedWorld.executableElements.forEach(convert);
75 closedWorld.variables.forEach(convert); 82 closedWorld.variables.forEach(convert);
76 closedWorld.fields.forEach(convert); 83 closedWorld.fields.forEach(convert);
84 closedWorld.instantiatedClasses.forEach(convertClass);
77 85
78 return convertedWorld; 86 return convertedWorld;
79 } 87 }
80 88
81 // TODO(johnniwinther): Implement [coreTypes] using [TypeProvider]. 89 // TODO(johnniwinther): Implement [coreTypes] using [TypeProvider].
82 class _DartTypes implements dart2js.DartTypes { 90 class _DartTypes implements dart2js.DartTypes {
83 @override 91 @override
84 get coreTypes => throw new UnsupportedError("coreTypes"); 92 get coreTypes => throw new UnsupportedError("coreTypes");
85 93
86 @override 94 @override
87 bool isSubtype(dart2js.DartType t, dart2js.DartType s) { 95 bool isSubtype(dart2js.DartType t, dart2js.DartType s) {
88 throw new UnsupportedError("isSubtype"); 96 throw new UnsupportedError("isSubtype");
89 } 97 }
90 } 98 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer2dart/lib/src/tree_shaker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698