| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 dart2js.send_structure; | 5 library dart2js.send_structure; |
| 6 | 6 |
| 7 import 'access_semantics.dart'; | 7 import 'access_semantics.dart'; |
| 8 import 'operators.dart'; | 8 import 'operators.dart'; |
| 9 import 'semantic_visitor.dart'; | 9 import 'semantic_visitor.dart'; |
| 10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 142 |
| 143 String toString() => 'as $type'; | 143 String toString() => 'as $type'; |
| 144 } | 144 } |
| 145 | 145 |
| 146 /// The structure for a [Send] that is an invocation. | 146 /// The structure for a [Send] that is an invocation. |
| 147 class InvokeStructure<R, A> implements SendStructure<R, A> { | 147 class InvokeStructure<R, A> implements SendStructure<R, A> { |
| 148 /// The target of the invocation. | 148 /// The target of the invocation. |
| 149 final AccessSemantics semantics; | 149 final AccessSemantics semantics; |
| 150 | 150 |
| 151 /// The [Selector] for the invocation. | 151 /// The [Selector] for the invocation. |
| 152 // TODO(johnniwinther): Store this only for dynamic invocations. |
| 152 final Selector selector; | 153 final Selector selector; |
| 153 | 154 |
| 155 /// The [CallStructure] of the invocation. |
| 156 // TODO(johnniwinther): Store this directly for static invocations. |
| 157 CallStructure get callStructure => selector.callStructure; |
| 158 |
| 154 InvokeStructure(this.semantics, this.selector); | 159 InvokeStructure(this.semantics, this.selector); |
| 155 | 160 |
| 156 R dispatch(SemanticSendVisitor<R, A> visitor, Send node, A arg) { | 161 R dispatch(SemanticSendVisitor<R, A> visitor, Send node, A arg) { |
| 157 switch (semantics.kind) { | 162 switch (semantics.kind) { |
| 158 case AccessKind.DYNAMIC_PROPERTY: | 163 case AccessKind.DYNAMIC_PROPERTY: |
| 159 return visitor.visitDynamicPropertyInvoke( | 164 return visitor.visitDynamicPropertyInvoke( |
| 160 node, | 165 node, |
| 161 node.receiver, | 166 node.receiver, |
| 162 node.argumentsNode, | 167 node.argumentsNode, |
| 163 selector, | 168 selector, |
| 164 arg); | 169 arg); |
| 165 case AccessKind.LOCAL_FUNCTION: | 170 case AccessKind.LOCAL_FUNCTION: |
| 166 return visitor.visitLocalFunctionInvoke( | 171 return visitor.visitLocalFunctionInvoke( |
| 167 node, | 172 node, |
| 168 semantics.element, | 173 semantics.element, |
| 169 node.argumentsNode, | 174 node.argumentsNode, |
| 170 // TODO(johnniwinther): Store the call selector instead of the | 175 // TODO(johnniwinther): Store the call selector instead of the |
| 171 // selector using the name of the function. | 176 // selector using the name of the function. |
| 172 new Selector.callClosureFrom(selector), | 177 callStructure, |
| 173 arg); | 178 arg); |
| 174 case AccessKind.LOCAL_VARIABLE: | 179 case AccessKind.LOCAL_VARIABLE: |
| 175 return visitor.visitLocalVariableInvoke( | 180 return visitor.visitLocalVariableInvoke( |
| 176 node, | 181 node, |
| 177 semantics.element, | 182 semantics.element, |
| 178 node.argumentsNode, | 183 node.argumentsNode, |
| 179 // TODO(johnniwinther): Store the call selector instead of the | 184 // TODO(johnniwinther): Store the call selector instead of the |
| 180 // selector using the name of the variable. | 185 // selector using the name of the variable. |
| 181 new Selector.callClosureFrom(selector), | 186 callStructure, |
| 182 arg); | 187 arg); |
| 183 case AccessKind.PARAMETER: | 188 case AccessKind.PARAMETER: |
| 184 return visitor.visitParameterInvoke( | 189 return visitor.visitParameterInvoke( |
| 185 node, | 190 node, |
| 186 semantics.element, | 191 semantics.element, |
| 187 node.argumentsNode, | 192 node.argumentsNode, |
| 188 // TODO(johnniwinther): Store the call selector instead of the | 193 // TODO(johnniwinther): Store the call selector instead of the |
| 189 // selector using the name of the parameter. | 194 // selector using the name of the parameter. |
| 190 new Selector.callClosureFrom(selector), | 195 callStructure, |
| 191 arg); | 196 arg); |
| 192 case AccessKind.STATIC_FIELD: | 197 case AccessKind.STATIC_FIELD: |
| 193 return visitor.visitStaticFieldInvoke( | 198 return visitor.visitStaticFieldInvoke( |
| 194 node, | 199 node, |
| 195 semantics.element, | 200 semantics.element, |
| 196 node.argumentsNode, | 201 node.argumentsNode, |
| 197 selector, | 202 callStructure, |
| 198 arg); | 203 arg); |
| 199 case AccessKind.STATIC_METHOD: | 204 case AccessKind.STATIC_METHOD: |
| 200 return visitor.visitStaticFunctionInvoke( | 205 return visitor.visitStaticFunctionInvoke( |
| 201 node, | 206 node, |
| 202 semantics.element, | 207 semantics.element, |
| 203 node.argumentsNode, | 208 node.argumentsNode, |
| 204 selector, | 209 callStructure, |
| 205 arg); | 210 arg); |
| 206 case AccessKind.STATIC_GETTER: | 211 case AccessKind.STATIC_GETTER: |
| 207 return visitor.visitStaticGetterInvoke( | 212 return visitor.visitStaticGetterInvoke( |
| 208 node, | 213 node, |
| 209 semantics.element, | 214 semantics.element, |
| 210 node.argumentsNode, | 215 node.argumentsNode, |
| 211 selector, | 216 callStructure, |
| 212 arg); | 217 arg); |
| 213 case AccessKind.STATIC_SETTER: | 218 case AccessKind.STATIC_SETTER: |
| 214 return visitor.errorStaticSetterInvoke( | 219 return visitor.errorStaticSetterInvoke( |
| 215 node, | 220 node, |
| 216 semantics.element, | 221 semantics.element, |
| 217 node.argumentsNode, | 222 node.argumentsNode, |
| 218 selector, | 223 callStructure, |
| 219 arg); | 224 arg); |
| 220 case AccessKind.TOPLEVEL_FIELD: | 225 case AccessKind.TOPLEVEL_FIELD: |
| 221 return visitor.visitTopLevelFieldInvoke( | 226 return visitor.visitTopLevelFieldInvoke( |
| 222 node, | 227 node, |
| 223 semantics.element, | 228 semantics.element, |
| 224 node.argumentsNode, | 229 node.argumentsNode, |
| 225 selector, | 230 callStructure, |
| 226 arg); | 231 arg); |
| 227 case AccessKind.TOPLEVEL_METHOD: | 232 case AccessKind.TOPLEVEL_METHOD: |
| 228 return visitor.visitTopLevelFunctionInvoke( | 233 return visitor.visitTopLevelFunctionInvoke( |
| 229 node, | 234 node, |
| 230 semantics.element, | 235 semantics.element, |
| 231 node.argumentsNode, | 236 node.argumentsNode, |
| 232 selector, | 237 callStructure, |
| 233 arg); | 238 arg); |
| 234 case AccessKind.TOPLEVEL_GETTER: | 239 case AccessKind.TOPLEVEL_GETTER: |
| 235 return visitor.visitTopLevelGetterInvoke( | 240 return visitor.visitTopLevelGetterInvoke( |
| 236 node, | 241 node, |
| 237 semantics.element, | 242 semantics.element, |
| 238 node.argumentsNode, | 243 node.argumentsNode, |
| 239 selector, | 244 callStructure, |
| 240 arg); | 245 arg); |
| 241 case AccessKind.TOPLEVEL_SETTER: | 246 case AccessKind.TOPLEVEL_SETTER: |
| 242 return visitor.errorTopLevelSetterInvoke( | 247 return visitor.errorTopLevelSetterInvoke( |
| 243 node, | 248 node, |
| 244 semantics.element, | 249 semantics.element, |
| 245 node.argumentsNode, | 250 node.argumentsNode, |
| 246 selector, | 251 callStructure, |
| 247 arg); | 252 arg); |
| 248 case AccessKind.CLASS_TYPE_LITERAL: | 253 case AccessKind.CLASS_TYPE_LITERAL: |
| 249 return visitor.visitClassTypeLiteralInvoke( | 254 return visitor.visitClassTypeLiteralInvoke( |
| 250 node, | 255 node, |
| 251 semantics.constant, | 256 semantics.constant, |
| 252 node.argumentsNode, | 257 node.argumentsNode, |
| 253 selector, | 258 callStructure, |
| 254 arg); | 259 arg); |
| 255 case AccessKind.TYPEDEF_TYPE_LITERAL: | 260 case AccessKind.TYPEDEF_TYPE_LITERAL: |
| 256 return visitor.visitTypedefTypeLiteralInvoke( | 261 return visitor.visitTypedefTypeLiteralInvoke( |
| 257 node, | 262 node, |
| 258 semantics.constant, | 263 semantics.constant, |
| 259 node.argumentsNode, | 264 node.argumentsNode, |
| 260 selector, | 265 callStructure, |
| 261 arg); | 266 arg); |
| 262 case AccessKind.DYNAMIC_TYPE_LITERAL: | 267 case AccessKind.DYNAMIC_TYPE_LITERAL: |
| 263 return visitor.visitDynamicTypeLiteralInvoke( | 268 return visitor.visitDynamicTypeLiteralInvoke( |
| 264 node, | 269 node, |
| 265 semantics.constant, | 270 semantics.constant, |
| 266 node.argumentsNode, | 271 node.argumentsNode, |
| 267 selector, | 272 callStructure, |
| 268 arg); | 273 arg); |
| 269 case AccessKind.TYPE_PARAMETER_TYPE_LITERAL: | 274 case AccessKind.TYPE_PARAMETER_TYPE_LITERAL: |
| 270 return visitor.visitTypeVariableTypeLiteralInvoke( | 275 return visitor.visitTypeVariableTypeLiteralInvoke( |
| 271 node, | 276 node, |
| 272 semantics.element, | 277 semantics.element, |
| 273 node.argumentsNode, | 278 node.argumentsNode, |
| 274 selector, | 279 callStructure, |
| 275 arg); | 280 arg); |
| 276 case AccessKind.EXPRESSION: | 281 case AccessKind.EXPRESSION: |
| 277 return visitor.visitExpressionInvoke( | 282 return visitor.visitExpressionInvoke( |
| 278 node, | 283 node, |
| 279 node.selector, | 284 node.selector, |
| 280 node.argumentsNode, | 285 node.argumentsNode, |
| 281 selector, | 286 selector, |
| 282 arg); | 287 arg); |
| 283 case AccessKind.THIS: | 288 case AccessKind.THIS: |
| 284 return visitor.visitThisInvoke( | 289 return visitor.visitThisInvoke( |
| 285 node, | 290 node, |
| 286 node.argumentsNode, | 291 node.argumentsNode, |
| 287 selector, | 292 callStructure, |
| 288 arg); | 293 arg); |
| 289 case AccessKind.THIS_PROPERTY: | 294 case AccessKind.THIS_PROPERTY: |
| 290 return visitor.visitThisPropertyInvoke( | 295 return visitor.visitThisPropertyInvoke( |
| 291 node, | 296 node, |
| 292 node.argumentsNode, | 297 node.argumentsNode, |
| 293 selector, | 298 selector, |
| 294 arg); | 299 arg); |
| 295 case AccessKind.SUPER_FIELD: | 300 case AccessKind.SUPER_FIELD: |
| 296 return visitor.visitSuperFieldInvoke( | 301 return visitor.visitSuperFieldInvoke( |
| 297 node, | 302 node, |
| 298 semantics.element, | 303 semantics.element, |
| 299 node.argumentsNode, | 304 node.argumentsNode, |
| 300 selector, | 305 callStructure, |
| 301 arg); | 306 arg); |
| 302 case AccessKind.SUPER_METHOD: | 307 case AccessKind.SUPER_METHOD: |
| 303 return visitor.visitSuperMethodInvoke( | 308 return visitor.visitSuperMethodInvoke( |
| 304 node, | 309 node, |
| 305 semantics.element, | 310 semantics.element, |
| 306 node.argumentsNode, | 311 node.argumentsNode, |
| 307 selector, | 312 callStructure, |
| 308 arg); | 313 arg); |
| 309 case AccessKind.SUPER_GETTER: | 314 case AccessKind.SUPER_GETTER: |
| 310 return visitor.visitSuperGetterInvoke( | 315 return visitor.visitSuperGetterInvoke( |
| 311 node, | 316 node, |
| 312 semantics.element, | 317 semantics.element, |
| 313 node.argumentsNode, | 318 node.argumentsNode, |
| 314 selector, | 319 callStructure, |
| 315 arg); | 320 arg); |
| 316 case AccessKind.SUPER_SETTER: | 321 case AccessKind.SUPER_SETTER: |
| 317 return visitor.errorSuperSetterInvoke( | 322 return visitor.errorSuperSetterInvoke( |
| 318 node, | 323 node, |
| 319 semantics.element, | 324 semantics.element, |
| 320 node.argumentsNode, | 325 node.argumentsNode, |
| 321 selector, | 326 callStructure, |
| 322 arg); | 327 arg); |
| 323 case AccessKind.CONSTANT: | 328 case AccessKind.CONSTANT: |
| 324 return visitor.visitConstantInvoke( | 329 return visitor.visitConstantInvoke( |
| 325 node, | 330 node, |
| 326 semantics.constant, | 331 semantics.constant, |
| 327 node.argumentsNode, | 332 node.argumentsNode, |
| 328 selector, | 333 callStructure, |
| 329 arg); | 334 arg); |
| 330 case AccessKind.UNRESOLVED: | 335 case AccessKind.UNRESOLVED: |
| 331 return visitor.errorUnresolvedInvoke( | 336 return visitor.errorUnresolvedInvoke( |
| 332 node, | 337 node, |
| 333 semantics.element, | 338 semantics.element, |
| 334 node.argumentsNode, | 339 node.argumentsNode, |
| 335 selector, | 340 selector, |
| 336 arg); | 341 arg); |
| 337 case AccessKind.COMPOUND: | 342 case AccessKind.COMPOUND: |
| 338 // This is not a valid case. | 343 // This is not a valid case. |
| (...skipping 1485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1824 } | 1829 } |
| 1825 | 1830 |
| 1826 /// The structure for a [NewExpression] of a new invocation. For instance | 1831 /// The structure for a [NewExpression] of a new invocation. For instance |
| 1827 /// `new C()`. | 1832 /// `new C()`. |
| 1828 class NewInvokeStructure<R, A> extends NewStructure<R, A> { | 1833 class NewInvokeStructure<R, A> extends NewStructure<R, A> { |
| 1829 final ConstructorAccessSemantics semantics; | 1834 final ConstructorAccessSemantics semantics; |
| 1830 final Selector selector; | 1835 final Selector selector; |
| 1831 | 1836 |
| 1832 NewInvokeStructure(this.semantics, this.selector); | 1837 NewInvokeStructure(this.semantics, this.selector); |
| 1833 | 1838 |
| 1839 CallStructure get callStructure => selector.callStructure; |
| 1840 |
| 1834 R dispatch(SemanticSendVisitor<R, A> visitor, NewExpression node, A arg) { | 1841 R dispatch(SemanticSendVisitor<R, A> visitor, NewExpression node, A arg) { |
| 1835 switch (semantics.kind) { | 1842 switch (semantics.kind) { |
| 1836 case ConstructorAccessKind.GENERATIVE: | 1843 case ConstructorAccessKind.GENERATIVE: |
| 1837 return visitor.visitGenerativeConstructorInvoke( | 1844 return visitor.visitGenerativeConstructorInvoke( |
| 1838 node, semantics.element, semantics.type, | 1845 node, semantics.element, semantics.type, |
| 1839 node.send.argumentsNode, selector, arg); | 1846 node.send.argumentsNode, callStructure, arg); |
| 1840 case ConstructorAccessKind.REDIRECTING_GENERATIVE: | 1847 case ConstructorAccessKind.REDIRECTING_GENERATIVE: |
| 1841 return visitor.visitRedirectingGenerativeConstructorInvoke( | 1848 return visitor.visitRedirectingGenerativeConstructorInvoke( |
| 1842 node, semantics.element, semantics.type, | 1849 node, semantics.element, semantics.type, |
| 1843 node.send.argumentsNode, selector, arg); | 1850 node.send.argumentsNode, callStructure, arg); |
| 1844 case ConstructorAccessKind.FACTORY: | 1851 case ConstructorAccessKind.FACTORY: |
| 1845 return visitor.visitFactoryConstructorInvoke( | 1852 return visitor.visitFactoryConstructorInvoke( |
| 1846 node, semantics.element, semantics.type, | 1853 node, semantics.element, semantics.type, |
| 1847 node.send.argumentsNode, selector, arg); | 1854 node.send.argumentsNode, callStructure, arg); |
| 1848 case ConstructorAccessKind.REDIRECTING_FACTORY: | 1855 case ConstructorAccessKind.REDIRECTING_FACTORY: |
| 1849 return visitor.visitRedirectingFactoryConstructorInvoke( | 1856 return visitor.visitRedirectingFactoryConstructorInvoke( |
| 1850 node, semantics.element, semantics.type, | 1857 node, semantics.element, semantics.type, |
| 1851 semantics.effectiveTargetSemantics.element, | 1858 semantics.effectiveTargetSemantics.element, |
| 1852 semantics.effectiveTargetSemantics.type, | 1859 semantics.effectiveTargetSemantics.type, |
| 1853 node.send.argumentsNode, selector, arg); | 1860 node.send.argumentsNode, callStructure, arg); |
| 1854 case ConstructorAccessKind.ABSTRACT: | 1861 case ConstructorAccessKind.ABSTRACT: |
| 1855 return visitor.errorAbstractClassConstructorInvoke( | 1862 return visitor.errorAbstractClassConstructorInvoke( |
| 1856 node, semantics.element, semantics.type, | 1863 node, semantics.element, semantics.type, |
| 1857 node.send.argumentsNode, selector, arg); | 1864 node.send.argumentsNode, callStructure, arg); |
| 1858 case ConstructorAccessKind.ERRONEOUS: | 1865 case ConstructorAccessKind.ERRONEOUS: |
| 1859 return visitor.errorUnresolvedConstructorInvoke( | 1866 return visitor.errorUnresolvedConstructorInvoke( |
| 1860 node, semantics.element, semantics.type, | 1867 node, semantics.element, semantics.type, |
| 1861 node.send.argumentsNode, selector, arg); | 1868 node.send.argumentsNode, selector, arg); |
| 1862 case ConstructorAccessKind.ERRONEOUS_REDIRECTING_FACTORY: | 1869 case ConstructorAccessKind.ERRONEOUS_REDIRECTING_FACTORY: |
| 1863 return visitor.errorUnresolvedRedirectingFactoryConstructorInvoke( | 1870 return visitor.errorUnresolvedRedirectingFactoryConstructorInvoke( |
| 1864 node, semantics.element, semantics.type, | 1871 node, semantics.element, semantics.type, |
| 1865 node.send.argumentsNode, selector, arg); | 1872 node.send.argumentsNode, selector, arg); |
| 1866 } | 1873 } |
| 1867 throw new SpannableAssertionFailure(node, | 1874 throw new SpannableAssertionFailure(node, |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2077 final ConstructorElement constructor; | 2084 final ConstructorElement constructor; |
| 2078 final Selector selector; | 2085 final Selector selector; |
| 2079 | 2086 |
| 2080 ThisConstructorInvokeStructure(this.constructor, this.selector); | 2087 ThisConstructorInvokeStructure(this.constructor, this.selector); |
| 2081 | 2088 |
| 2082 R dispatch(SemanticDeclarationVisitor<R, A> visitor, Send node, A arg) { | 2089 R dispatch(SemanticDeclarationVisitor<R, A> visitor, Send node, A arg) { |
| 2083 return visitor.visitThisConstructorInvoke( | 2090 return visitor.visitThisConstructorInvoke( |
| 2084 node, constructor, node.argumentsNode, selector, arg); | 2091 node, constructor, node.argumentsNode, selector, arg); |
| 2085 } | 2092 } |
| 2086 } | 2093 } |
| OLD | NEW |