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

Side by Side Diff: pkg/kernel/lib/transformations/method_call.dart

Issue 2904203003: Don't recreate CoreTypes in transformers. Pass it in. (Closed)
Patch Set: Created 3 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
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 kernel.transformations.method_call; 5 library kernel.transformations.method_call;
6 6
7 import 'dart:math' as math; 7 import 'dart:math' as math;
8 8
9 import '../ast.dart'; 9 import '../ast.dart';
10 import '../class_hierarchy.dart'; 10 import '../class_hierarchy.dart';
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 /// } 46 /// }
47 /// 47 ///
48 /// class B extends A { 48 /// class B extends A {
49 /// foo(required1) => print("Hello from class B"); 49 /// foo(required1) => print("Hello from class B");
50 /// } 50 /// }
51 /// 51 ///
52 /// main() { 52 /// main() {
53 /// var b = new B(); 53 /// var b = new B();
54 /// b.foo(499, named1: 88); 54 /// b.foo(499, named1: 88);
55 /// } 55 /// }
56 Program transformProgram(Program program, [debug = false]) { 56 Program transformProgram(CoreTypes coreTypes, Program program,
57 new MethodCallTransformer(debug).visitProgram(program); 57 [debug = false]) {
58 new MethodCallTransformer(coreTypes, debug).visitProgram(program);
58 return program; 59 return program;
59 } 60 }
60 61
61 class MethodCallTransformer extends Transformer { 62 class MethodCallTransformer extends Transformer {
63 final CoreTypes coreTypes;
64
62 /// Keep track of "visited" procedures and constructors to not visit already 65 /// Keep track of "visited" procedures and constructors to not visit already
63 /// visited stuff, nor visit newly created stubs. 66 /// visited stuff, nor visit newly created stubs.
64 Set<Member> _visited = new Set<Member>(); 67 Set<Member> _visited = new Set<Member>();
65 68
66 /// Some things currently cannot be rewritten. Calls to methods called "call" 69 /// Some things currently cannot be rewritten. Calls to methods called "call"
67 /// (because invoking tear-offs and closures and whatnot becomes .call) 70 /// (because invoking tear-offs and closures and whatnot becomes .call)
68 /// as well as clashes with field names as a field can contain a function 71 /// as well as clashes with field names as a field can contain a function
69 /// and one can then do a clazz.fieldName(...). 72 /// and one can then do a clazz.fieldName(...).
70 Set<String> blacklistedSelectors = new Set<String>.from(["call"]); 73 Set<String> blacklistedSelectors = new Set<String>.from(["call"]);
71 74
(...skipping 26 matching lines...) Expand all
98 /// For non-static method transformations: 101 /// For non-static method transformations:
99 /// Maps a procedure to the mapping of argument signature to procedure stub. 102 /// Maps a procedure to the mapping of argument signature to procedure stub.
100 Map<Procedure, Map<String, Procedure>> _superProcedureCalls = {}; 103 Map<Procedure, Map<String, Procedure>> _superProcedureCalls = {};
101 104
102 /// Whether in debug mode, i.e. if we can insert extra print statements for 105 /// Whether in debug mode, i.e. if we can insert extra print statements for
103 /// debugging purposes. 106 /// debugging purposes.
104 bool _debug; 107 bool _debug;
105 108
106 /// For noSuchMethod calls. 109 /// For noSuchMethod calls.
107 ClassHierarchy hierarchy; 110 ClassHierarchy hierarchy;
108 CoreTypes coreTypes;
109 Constructor _invocationMirrorConstructor; // cached 111 Constructor _invocationMirrorConstructor; // cached
110 Procedure _listFrom; // cached 112 Procedure _listFrom; // cached
111 113
112 MethodCallTransformer(this._debug); 114 MethodCallTransformer(this.coreTypes, this._debug);
113 115
114 @override 116 @override
115 TreeNode visitProgram(Program node) { 117 TreeNode visitProgram(Program node) {
116 hierarchy = new ClassHierarchy(node); 118 hierarchy = new ClassHierarchy(node);
117 coreTypes = new CoreTypes(node);
118 119
119 // First move body of all procedures that takes optional positional or named 120 // First move body of all procedures that takes optional positional or named
120 // parameters and record which non-static procedure names have optional 121 // parameters and record which non-static procedure names have optional
121 // positional arguments. 122 // positional arguments.
122 // Do the same for constructors. Then also rewrite constructor initializers 123 // Do the same for constructors. Then also rewrite constructor initializers
123 // using LocalInitializer and sort named arguments in those initializers 124 // using LocalInitializer and sort named arguments in those initializers
124 for (final library in node.libraries) { 125 for (final library in node.libraries) {
125 for (final procedure in new List<Procedure>.from(library.procedures)) { 126 for (final procedure in new List<Procedure>.from(library.procedures)) {
126 _moveAndTransformProcedure(procedure); 127 _moveAndTransformProcedure(procedure);
127 } 128 }
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 return printStackTrace; 1307 return printStackTrace;
1307 } 1308 }
1308 } 1309 }
1309 1310
1310 class _Pair<K, V> { 1311 class _Pair<K, V> {
1311 final K key; 1312 final K key;
1312 final V value; 1313 final V value;
1313 1314
1314 _Pair(this.key, this.value); 1315 _Pair(this.key, this.value);
1315 } 1316 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698