OLD | NEW |
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:js_runtime/shared/embedded_names.dart'; | 5 import 'package:js_runtime/shared/embedded_names.dart'; |
6 import 'package:kernel/ast.dart' as ir; | 6 import 'package:kernel/ast.dart' as ir; |
7 | 7 |
8 import '../common.dart'; | 8 import '../common.dart'; |
9 import '../common/names.dart'; | 9 import '../common/names.dart'; |
10 import '../compiler.dart'; | 10 import '../compiler.dart'; |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 Name getName(ir.Name name) { | 195 Name getName(ir.Name name) { |
196 return new Name( | 196 return new Name( |
197 name.name, name.isPrivate ? getElement(name.library) : null); | 197 name.name, name.isPrivate ? getElement(name.library) : null); |
198 } | 198 } |
199 | 199 |
200 ir.Field getFieldFromElement(FieldElement field) { | 200 ir.Field getFieldFromElement(FieldElement field) { |
201 return kernel.fields[field]; | 201 return kernel.fields[field]; |
202 } | 202 } |
203 | 203 |
204 Selector getSelector(ir.Expression node) { | 204 Selector getSelector(ir.Expression node) { |
205 if (node is ir.PropertyGet) return getGetterSelector(node); | 205 // TODO(efortuna): This is screaming for a common interface between |
206 if (node is ir.PropertySet) return getSetterSelector(node); | 206 // PropertyGet and SuperPropertyGet (and same for *Get). Talk to kernel |
| 207 // folks. |
| 208 if (node is ir.PropertyGet) { |
| 209 return getGetterSelector((node as ir.PropertyGet).name); |
| 210 } |
| 211 if (node is ir.SuperPropertyGet) { |
| 212 return getGetterSelector((node as ir.SuperPropertyGet).name); |
| 213 } |
| 214 if (node is ir.PropertySet || node is ir.SuperPropertySet) { |
| 215 return getSetterSelector(node); |
| 216 } |
207 if (node is ir.InvocationExpression) return getInvocationSelector(node); | 217 if (node is ir.InvocationExpression) return getInvocationSelector(node); |
208 _compiler.reporter.internalError(getNode(node), | 218 _compiler.reporter.internalError(getNode(node), |
209 "Can only get the selector for a property get or an invocation."); | 219 "Can only get the selector for a property get or an invocation."); |
210 return null; | 220 return null; |
211 } | 221 } |
212 | 222 |
213 Selector getInvocationSelector(ir.InvocationExpression invocation) { | 223 Selector getInvocationSelector(ir.InvocationExpression invocation) { |
214 Name name = getName(invocation.name); | 224 Name name = getName(invocation.name); |
215 SelectorKind kind; | 225 SelectorKind kind; |
216 if (Elements.isOperatorName(invocation.name.name)) { | 226 if (Elements.isOperatorName(invocation.name.name)) { |
217 if (name == Names.INDEX_NAME || name == Names.INDEX_SET_NAME) { | 227 if (name == Names.INDEX_NAME || name == Names.INDEX_SET_NAME) { |
218 kind = SelectorKind.INDEX; | 228 kind = SelectorKind.INDEX; |
219 } else { | 229 } else { |
220 kind = SelectorKind.OPERATOR; | 230 kind = SelectorKind.OPERATOR; |
221 } | 231 } |
222 } else { | 232 } else { |
223 kind = SelectorKind.CALL; | 233 kind = SelectorKind.CALL; |
224 } | 234 } |
225 | 235 |
226 CallStructure callStructure = getCallStructure(invocation.arguments); | 236 CallStructure callStructure = getCallStructure(invocation.arguments); |
227 return new Selector(kind, name, callStructure); | 237 return new Selector(kind, name, callStructure); |
228 } | 238 } |
229 | 239 |
230 Selector getGetterSelector(ir.PropertyGet getter) { | 240 Selector getGetterSelector(ir.Name irName) { |
231 ir.Name irName = getter.name; | |
232 Name name = new Name( | 241 Name name = new Name( |
233 irName.name, irName.isPrivate ? getElement(irName.library) : null); | 242 irName.name, irName.isPrivate ? getElement(irName.library) : null); |
234 return new Selector.getter(name); | 243 return new Selector.getter(name); |
235 } | 244 } |
236 | 245 |
237 Selector getSetterSelector(ir.PropertySet setter) { | 246 Selector getSetterSelector(ir.PropertySet setter) { |
238 ir.Name irName = setter.name; | 247 ir.Name irName = setter.name; |
239 Name name = new Name( | 248 Name name = new Name( |
240 irName.name, irName.isPrivate ? getElement(irName.library) : null); | 249 irName.name, irName.isPrivate ? getElement(irName.library) : null); |
241 return new Selector.setter(name); | 250 return new Selector.setter(name); |
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1109 JumpTarget continueTarget = | 1118 JumpTarget continueTarget = |
1110 astAdapter.getJumpTarget(switchCase, isContinueTarget: true); | 1119 astAdapter.getJumpTarget(switchCase, isContinueTarget: true); |
1111 assert(continueTarget is KernelJumpTarget); | 1120 assert(continueTarget is KernelJumpTarget); |
1112 targetIndexMap[continueTarget] = switchIndex; | 1121 targetIndexMap[continueTarget] = switchIndex; |
1113 assert(builder.jumpTargets[continueTarget] == null); | 1122 assert(builder.jumpTargets[continueTarget] == null); |
1114 builder.jumpTargets[continueTarget] = this; | 1123 builder.jumpTargets[continueTarget] = this; |
1115 switchIndex++; | 1124 switchIndex++; |
1116 } | 1125 } |
1117 } | 1126 } |
1118 } | 1127 } |
OLD | NEW |