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

Side by Side Diff: pkg/compiler/lib/src/kernel/closure.dart

Issue 2949293002: Add ScopeInfo class for variable information that doesn't actually involve closures. (Closed)
Patch Set: . Created 3 years, 5 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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:kernel/ast.dart' as ir; 5 import 'package:kernel/ast.dart' as ir;
6 6
7 import '../closure.dart'; 7 import '../closure.dart';
8 import '../common/tasks.dart'; 8 import '../common/tasks.dart';
9 import '../elements/entities.dart'; 9 import '../elements/entities.dart';
10 import '../world.dart'; 10 import '../world.dart';
(...skipping 26 matching lines...) Expand all
37 visitTryFinally(ir.TryFinally node) { 37 visitTryFinally(ir.TryFinally node) {
38 bool oldInTry = _inTry; 38 bool oldInTry = _inTry;
39 _inTry = true; 39 _inTry = true;
40 node.visitChildren(this); 40 node.visitChildren(this);
41 _inTry = oldInTry; 41 _inTry = oldInTry;
42 } 42 }
43 43
44 @override 44 @override
45 visitVariableGet(ir.VariableGet node) { 45 visitVariableGet(ir.VariableGet node) {
46 if (_inTry) { 46 if (_inTry) {
47 info.registerUsedInTryOrSync(_localsMap.getLocal(node.variable)); 47 info.variablesUsedInTryOrSync.add(_localsMap.getLocal(node.variable));
48 } 48 }
49 } 49 }
50 50
51 @override 51 @override
52 visitVariableSet(ir.VariableSet node) { 52 visitVariableSet(ir.VariableSet node) {
53 if (_inTry) { 53 if (_inTry) {
54 info.registerUsedInTryOrSync(_localsMap.getLocal(node.variable)); 54 info.variablesUsedInTryOrSync.add(_localsMap.getLocal(node.variable));
55 } 55 }
56 node.visitChildren(this); 56 node.visitChildren(this);
57 } 57 }
58 } 58 }
59 59
60 /// Closure conversion code using our new Entity model. Closure conversion is 60 /// Closure conversion code using our new Entity model. Closure conversion is
61 /// necessary because the semantics of closures are slightly different in Dart 61 /// necessary because the semantics of closures are slightly different in Dart
62 /// than JavaScript. Closure conversion is separated out into two phases: 62 /// than JavaScript. Closure conversion is separated out into two phases:
63 /// generation of a new (temporary) representation to store where variables need 63 /// generation of a new (temporary) representation to store where variables need
64 /// to be hoisted/captured up at another level to re-write the closure, and then 64 /// to be hoisted/captured up at another level to re-write the closure, and then
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 98 }
99 99
100 /// TODO(johnniwinther,efortuna): Implement this. 100 /// TODO(johnniwinther,efortuna): Implement this.
101 @override 101 @override
102 LoopClosureRepresentationInfo getClosureRepresentationInfoForLoop( 102 LoopClosureRepresentationInfo getClosureRepresentationInfoForLoop(
103 ir.Node loopNode) { 103 ir.Node loopNode) {
104 return const LoopClosureRepresentationInfo(); 104 return const LoopClosureRepresentationInfo();
105 } 105 }
106 106
107 @override 107 @override
108 ScopeInfo getScopeInfo(Entity entity) {
109 // TODO(efortuna): Specialize this function from the one below.
110 return getClosureRepresentationInfo(entity);
111 }
112
113 @override
108 ClosureRepresentationInfo getClosureRepresentationInfo(Entity entity) { 114 ClosureRepresentationInfo getClosureRepresentationInfo(Entity entity) {
109 return _infoMap.putIfAbsent(entity, () { 115 return _infoMap.putIfAbsent(entity, () {
110 if (entity is MemberEntity) { 116 if (entity is MemberEntity) {
111 ir.Member node = _elementMap.getMemberNode(entity); 117 ir.Member node = _elementMap.getMemberNode(entity);
112 ThisLocal thisLocal; 118 ThisLocal thisLocal;
113 if (entity.isInstanceMember) { 119 if (entity.isInstanceMember) {
114 thisLocal = new ThisLocal(entity); 120 thisLocal = new ThisLocal(entity);
115 } 121 }
116 KernelClosureDataBuilder builder = new KernelClosureDataBuilder( 122 KernelClosureDataBuilder builder = new KernelClosureDataBuilder(
117 _globalLocalsMap.getLocalsMap(entity), thisLocal); 123 _globalLocalsMap.getLocalsMap(entity), thisLocal);
118 node.accept(builder); 124 node.accept(builder);
119 return builder.info; 125 return builder.info;
120 } 126 }
121 127
122 /// TODO(johnniwinther,efortuna): Implement this. 128 /// TODO(johnniwinther,efortuna): Implement this.
123 return const ClosureRepresentationInfo(); 129 return const ClosureRepresentationInfo();
124 }); 130 });
125 } 131 }
126 } 132 }
127 133
128 // TODO(johnniwinther): Add unittest for the computed 134 // TODO(johnniwinther): Add unittest for the computed
129 // [ClosureRepresentationInfo]. 135 // [ClosureRepresentationInfo].
130 class KernelClosureRepresentationInfo extends ClosureRepresentationInfo { 136 class KernelClosureRepresentationInfo extends ClosureRepresentationInfo {
131 final ThisLocal thisLocal; 137 final ThisLocal thisLocal;
132 final Set<Local> _localsUsedInTryOrSync = new Set<Local>(); 138 final Set<Local> variablesUsedInTryOrSync = new Set<Local>();
133 139
134 KernelClosureRepresentationInfo(this.thisLocal); 140 KernelClosureRepresentationInfo(this.thisLocal);
135 141
136 void registerUsedInTryOrSync(Local local) {
137 _localsUsedInTryOrSync.add(local);
138 }
139
140 bool variableIsUsedInTryOrSync(Local variable) =>
141 _localsUsedInTryOrSync.contains(variable);
142
143 String toString() { 142 String toString() {
144 StringBuffer sb = new StringBuffer(); 143 StringBuffer sb = new StringBuffer();
145 sb.write('this=$thisLocal,'); 144 sb.write('this=$thisLocal,');
146 sb.write('localsUsedInTryOrSync={${_localsUsedInTryOrSync.join(', ')}}'); 145 sb.write(
146 'variablesUsedInTryOrSync={${variablesUsedInTryOrSync.join(', ')}}');
147 return sb.toString(); 147 return sb.toString();
148 } 148 }
149 } 149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698