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 '../constants/expressions.dart'; | 8 import '../constants/expressions.dart'; |
9 import '../common.dart'; | 9 import '../common.dart'; |
10 import '../common/names.dart'; | 10 import '../common/names.dart'; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 } | 89 } |
90 | 90 |
91 MemberElement getMember(ir.Node node) => getElement(node).declaration; | 91 MemberElement getMember(ir.Node node) => getElement(node).declaration; |
92 | 92 |
93 MethodElement getMethod(ir.Node node) => getElement(node).declaration; | 93 MethodElement getMethod(ir.Node node) => getElement(node).declaration; |
94 | 94 |
95 ClassElement getClass(ir.Node node) => getElement(node).declaration; | 95 ClassElement getClass(ir.Node node) => getElement(node).declaration; |
96 | 96 |
97 ast.Node getNode(ir.Node node) { | 97 ast.Node getNode(ir.Node node) { |
98 ast.Node result = _nodeToAst[node]; | 98 ast.Node result = _nodeToAst[node]; |
99 assert(result != null); | 99 assert(invariant(CURRENT_ELEMENT_SPANNABLE, result != null, |
| 100 message: "No node found for $node")); |
100 return result; | 101 return result; |
101 } | 102 } |
102 | 103 |
103 Local getLocal(ir.VariableDeclaration variable) { | 104 Local getLocal(ir.VariableDeclaration variable) { |
104 // If this is a synthetic local, return the synthetic local | 105 // If this is a synthetic local, return the synthetic local |
105 if (variable.name == null) { | 106 if (variable.name == null) { |
106 return _syntheticLocals.putIfAbsent( | 107 return _syntheticLocals.putIfAbsent( |
107 variable, () => new SyntheticLocal("x", null)); | 108 variable, () => new SyntheticLocal("x", null)); |
108 } | 109 } |
109 return getElement(variable) as LocalElement; | 110 return getElement(variable) as LocalElement; |
(...skipping 27 matching lines...) Expand all Loading... |
137 return new Name( | 138 return new Name( |
138 name.name, name.isPrivate ? getElement(name.library) : null); | 139 name.name, name.isPrivate ? getElement(name.library) : null); |
139 } | 140 } |
140 | 141 |
141 ir.Field getFieldFromElement(FieldElement field) { | 142 ir.Field getFieldFromElement(FieldElement field) { |
142 return kernel.fields[field]; | 143 return kernel.fields[field]; |
143 } | 144 } |
144 | 145 |
145 Selector getSelector(ir.Expression node) { | 146 Selector getSelector(ir.Expression node) { |
146 if (node is ir.PropertyGet) return getGetterSelector(node); | 147 if (node is ir.PropertyGet) return getGetterSelector(node); |
| 148 if (node is ir.PropertySet) return getSetterSelector(node); |
147 if (node is ir.InvocationExpression) return getInvocationSelector(node); | 149 if (node is ir.InvocationExpression) return getInvocationSelector(node); |
148 _compiler.reporter.internalError(getNode(node), | 150 _compiler.reporter.internalError(getNode(node), |
149 "Can only get the selector for a property get or an invocation."); | 151 "Can only get the selector for a property get or an invocation."); |
150 return null; | 152 return null; |
151 } | 153 } |
152 | 154 |
153 Selector getInvocationSelector(ir.InvocationExpression invocation) { | 155 Selector getInvocationSelector(ir.InvocationExpression invocation) { |
154 Name name = getName(invocation.name); | 156 Name name = getName(invocation.name); |
155 SelectorKind kind; | 157 SelectorKind kind; |
156 if (Elements.isOperatorName(invocation.name.name)) { | 158 if (Elements.isOperatorName(invocation.name.name)) { |
(...skipping 10 matching lines...) Expand all Loading... |
167 return new Selector(kind, name, callStructure); | 169 return new Selector(kind, name, callStructure); |
168 } | 170 } |
169 | 171 |
170 Selector getGetterSelector(ir.PropertyGet getter) { | 172 Selector getGetterSelector(ir.PropertyGet getter) { |
171 ir.Name irName = getter.name; | 173 ir.Name irName = getter.name; |
172 Name name = new Name( | 174 Name name = new Name( |
173 irName.name, irName.isPrivate ? getElement(irName.library) : null); | 175 irName.name, irName.isPrivate ? getElement(irName.library) : null); |
174 return new Selector.getter(name); | 176 return new Selector.getter(name); |
175 } | 177 } |
176 | 178 |
| 179 Selector getSetterSelector(ir.PropertySet setter) { |
| 180 ir.Name irName = setter.name; |
| 181 Name name = new Name( |
| 182 irName.name, irName.isPrivate ? getElement(irName.library) : null); |
| 183 return new Selector.setter(name); |
| 184 } |
| 185 |
177 TypeMask typeOfInvocation(ir.Expression send) { | 186 TypeMask typeOfInvocation(ir.Expression send) { |
| 187 ast.Node operatorNode = kernel.nodeToAstOperator[send]; |
| 188 if (operatorNode != null) { |
| 189 return _resultOf(_target).typeOfOperator(operatorNode); |
| 190 } |
178 return _resultOf(_target).typeOfSend(getNode(send)); | 191 return _resultOf(_target).typeOfSend(getNode(send)); |
179 } | 192 } |
180 | 193 |
181 TypeMask typeOfGet(ir.PropertyGet getter) { | 194 TypeMask typeOfGet(ir.PropertyGet getter) { |
182 return _resultOf(_target).typeOfSend(getNode(getter)); | 195 return _resultOf(_target).typeOfSend(getNode(getter)); |
183 } | 196 } |
184 | 197 |
| 198 TypeMask typeOfSet(ir.PropertySet setter) { |
| 199 return _compiler.closedWorld.commonMasks.dynamicType; |
| 200 } |
| 201 |
185 TypeMask typeOfSend(ir.Expression send) { | 202 TypeMask typeOfSend(ir.Expression send) { |
186 assert(send is ir.InvocationExpression || send is ir.PropertyGet); | 203 assert(send is ir.InvocationExpression || send is ir.PropertyGet); |
187 return _resultOf(_target).typeOfSend(getNode(send)); | 204 return _resultOf(_target).typeOfSend(getNode(send)); |
188 } | 205 } |
189 | 206 |
190 TypeMask typeOfNewList(Element owner, ir.ListLiteral listLiteral) { | 207 TypeMask typeOfNewList(Element owner, ir.ListLiteral listLiteral) { |
191 return _resultOf(owner).typeOfNewList(getNode(listLiteral)) ?? | 208 return _resultOf(owner).typeOfNewList(getNode(listLiteral)) ?? |
192 _compiler.closedWorld.commonMasks.dynamicType; | 209 _compiler.closedWorld.commonMasks.dynamicType; |
193 } | 210 } |
194 | 211 |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 astAdapter.reporter.internalError( | 761 astAdapter.reporter.internalError( |
745 CURRENT_ELEMENT_SPANNABLE, "Unexpected constant target: $element."); | 762 CURRENT_ELEMENT_SPANNABLE, "Unexpected constant target: $element."); |
746 return null; | 763 return null; |
747 } | 764 } |
748 | 765 |
749 @override | 766 @override |
750 ConstantExpression visitStringLiteral(ir.StringLiteral node) { | 767 ConstantExpression visitStringLiteral(ir.StringLiteral node) { |
751 return new StringConstantExpression(node.value); | 768 return new StringConstantExpression(node.value); |
752 } | 769 } |
753 } | 770 } |
OLD | NEW |