| 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 // TODO(johnniwinther): Temporarily copied from analyzer2dart. Merge when | 5 // TODO(johnniwinther): Temporarily copied from analyzer2dart. Merge when |
| 6 // we shared code with the analyzer and this semantic visitor is complete. | 6 // we shared code with the analyzer and this semantic visitor is complete. |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Code for classifying the semantics of identifiers appearing in a Dart file. | 9 * Code for classifying the semantics of identifiers appearing in a Dart file. |
| 10 */ | 10 */ |
| 11 library dart2js.access_semantics; | 11 library dart2js.access_semantics; |
| 12 | 12 |
| 13 import '../constants/expressions.dart'; | 13 import '../constants/expressions.dart'; |
| 14 import '../elements/elements.dart'; | 14 import '../elements/elements.dart'; |
| 15 import '../dart_types.dart'; | 15 import '../dart_types.dart'; |
| 16 | 16 |
| 17 /// Enum representing the different kinds of destinations which a property | 17 /// Enum representing the different kinds of destinations which a property |
| 18 /// access or method or function invocation might refer to. | 18 /// access or method or function invocation might refer to. |
| 19 enum AccessKind { | 19 enum AccessKind { |
| 20 /// The destination of the access is an instance method, property, or field | 20 /// The destination of the access is an instance method, property, or field |
| 21 /// of a class, and thus must be determined dynamically. | 21 /// of a class, and thus must be determined dynamically. |
| 22 DYNAMIC_PROPERTY, | 22 DYNAMIC_PROPERTY, |
| 23 | 23 |
| 24 // TODO(johnniwinther): Split these cases into captured and non-captured | 24 // TODO(johnniwinther): Split these cases into captured and non-captured |
| 25 // local access. | 25 // local access. |
| 26 /// The destination of the access is a function that is defined locally within | 26 /// The destination of the access is a function that is defined locally within |
| 27 /// an enclosing function or method. | 27 /// an enclosing function or method. |
| 28 LOCAL_FUNCTION, | 28 LOCAL_FUNCTION, |
| 29 | 29 |
| 30 /// The destination of the access is a non-final variable that is defined | 30 /// The destination of the access is a variable that is defined locally within |
| 31 /// locally within an enclosing function or method. | 31 /// an enclosing function or method. |
| 32 LOCAL_VARIABLE, | 32 LOCAL_VARIABLE, |
| 33 | 33 |
| 34 /// The destination of the access is a final variable that is defined locally | 34 /// The destination of the access is a variable that is defined as a parameter |
| 35 /// within an enclosing function or method. | 35 /// to an enclosing function or method. |
| 36 FINAL_LOCAL_VARIABLE, | |
| 37 | |
| 38 /// The destination of the access is a variable that is defined as a non-final | |
| 39 /// parameter to an enclosing function or method. | |
| 40 PARAMETER, | 36 PARAMETER, |
| 41 | 37 |
| 42 /// The destination of the access is a variable that is defined as a final | 38 /// The destination of the access is a field that is defined statically within |
| 43 /// parameter to an enclosing function or method. | 39 /// a class. |
| 44 FINAL_PARAMETER, | |
| 45 | |
| 46 /// The destination of the access is a non-final field that is defined | |
| 47 /// statically within a class. | |
| 48 STATIC_FIELD, | 40 STATIC_FIELD, |
| 49 | 41 |
| 50 /// The destination of the access is a final field that is defined statically | |
| 51 /// within a class. | |
| 52 FINAL_STATIC_FIELD, | |
| 53 | |
| 54 /// The destination of the access is a method that is defined statically | 42 /// The destination of the access is a method that is defined statically |
| 55 /// within a class. | 43 /// within a class. |
| 56 STATIC_METHOD, | 44 STATIC_METHOD, |
| 57 | 45 |
| 58 /// The destination of the access is a property getter that is defined | 46 /// The destination of the access is a property getter that is defined |
| 59 /// statically within a class. | 47 /// statically within a class. |
| 60 STATIC_GETTER, | 48 STATIC_GETTER, |
| 61 | 49 |
| 62 /// The destination of the access is a property setter that is defined | 50 /// The destination of the access is a property setter that is defined |
| 63 /// statically within a class. | 51 /// statically within a class. |
| 64 STATIC_SETTER, | 52 STATIC_SETTER, |
| 65 | 53 |
| 66 /// The destination of the access is a non-final top level variable defined | 54 /// The destination of the access is a top level variable defined within a |
| 67 /// within a library. | 55 /// library. |
| 68 TOPLEVEL_FIELD, | 56 TOPLEVEL_FIELD, |
| 69 | 57 |
| 70 /// The destination of the access is a final top level variable defined within | |
| 71 /// a library. | |
| 72 FINAL_TOPLEVEL_FIELD, | |
| 73 | |
| 74 /// The destination of the access is a top level method defined within a | 58 /// The destination of the access is a top level method defined within a |
| 75 /// library. | 59 /// library. |
| 76 TOPLEVEL_METHOD, | 60 TOPLEVEL_METHOD, |
| 77 | 61 |
| 78 /// The destination of the access is a top level property getter defined | 62 /// The destination of the access is a top level property getter defined |
| 79 /// within a library. | 63 /// within a library. |
| 80 TOPLEVEL_GETTER, | 64 TOPLEVEL_GETTER, |
| 81 | 65 |
| 82 /// The destination of the access is a top level property setter defined | 66 /// The destination of the access is a top level property setter defined |
| 83 /// within a library. | 67 /// within a library. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 100 /// function expression `(){}` in the function expression invocation `(){}()`. | 84 /// function expression `(){}` in the function expression invocation `(){}()`. |
| 101 EXPRESSION, | 85 EXPRESSION, |
| 102 | 86 |
| 103 /// The destination of the access is `this` of the enclosing class. | 87 /// The destination of the access is `this` of the enclosing class. |
| 104 THIS, | 88 THIS, |
| 105 | 89 |
| 106 /// The destination of the access is an instance method, property, or field | 90 /// The destination of the access is an instance method, property, or field |
| 107 /// of the enclosing class. | 91 /// of the enclosing class. |
| 108 THIS_PROPERTY, | 92 THIS_PROPERTY, |
| 109 | 93 |
| 110 /// The destination of the access is a non-final field of the super class of | 94 /// The destination of the access is a field of the super class of the |
| 111 /// the enclosing class. | 95 /// enclosing class. |
| 112 SUPER_FIELD, | 96 SUPER_FIELD, |
| 113 | 97 |
| 114 /// The destination of the access is a final field of the super class of the | |
| 115 /// enclosing class. | |
| 116 SUPER_FINAL_FIELD, | |
| 117 | |
| 118 /// The destination of the access is a method of the super class of the | 98 /// The destination of the access is a method of the super class of the |
| 119 /// enclosing class. | 99 /// enclosing class. |
| 120 SUPER_METHOD, | 100 SUPER_METHOD, |
| 121 | 101 |
| 122 /// The destination of the access is a getter of the super class of the | 102 /// The destination of the access is a getter of the super class of the |
| 123 /// enclosing class. | 103 /// enclosing class. |
| 124 SUPER_GETTER, | 104 SUPER_GETTER, |
| 125 | 105 |
| 126 /// The destination of the access is a setter of the super class of the | 106 /// The destination of the access is a setter of the super class of the |
| 127 /// enclosing class. | 107 /// enclosing class. |
| 128 SUPER_SETTER, | 108 SUPER_SETTER, |
| 129 | 109 |
| 130 /// Compound access where read and write access different elements. | 110 /// Compound access where read and write access different elements. |
| 131 /// See [CompoundAccessKind]. | 111 /// See [CompoundAccessKind]. |
| 132 COMPOUND, | 112 COMPOUND, |
| 133 | 113 |
| 134 /// The destination of the access is a compile-time constant. | 114 /// The destination of the access is a compile-time constant. |
| 135 CONSTANT, | 115 CONSTANT, |
| 136 | 116 |
| 137 /// The destination of the access is unresolved in a static context. | 117 /// The destination of the access is unresolved in a static context. |
| 138 UNRESOLVED, | 118 UNRESOLVED, |
| 139 | 119 |
| 140 /// The destination of the access is unresolved super access. | 120 /// The destination of the access is unresolved super access. |
| 141 UNRESOLVED_SUPER, | 121 UNRESOLVED_SUPER, |
| 142 } | 122 } |
| 143 | 123 |
| 144 enum CompoundAccessKind { | 124 enum CompoundAccessKind { |
| 145 /// Read from a static getter and write to a static setter. | 125 /// Read from a static getter and write to static setter. |
| 146 STATIC_GETTER_SETTER, | 126 STATIC_GETTER_SETTER, |
| 147 /// Read from a static method (closurize) and write to a static setter. | 127 /// Read from a static method (closurize) and write to static setter. |
| 148 STATIC_METHOD_SETTER, | 128 STATIC_METHOD_SETTER, |
| 149 | 129 |
| 150 /// Read from an unresolved static getter and write to a static setter. | |
| 151 UNRESOLVED_STATIC_GETTER, | |
| 152 /// Read from a static getter and write to an unresolved static setter. | |
| 153 UNRESOLVED_STATIC_SETTER, | |
| 154 | |
| 155 /// Read from a top level getter and write to a top level setter. | 130 /// Read from a top level getter and write to a top level setter. |
| 156 TOPLEVEL_GETTER_SETTER, | 131 TOPLEVEL_GETTER_SETTER, |
| 157 /// Read from a top level method (closurize) and write to top level setter. | 132 /// Read from a top level method (closurize) and write to top level setter. |
| 158 TOPLEVEL_METHOD_SETTER, | 133 TOPLEVEL_METHOD_SETTER, |
| 159 | 134 |
| 160 /// Read from an unresolved top level getter and write to a top level setter. | |
| 161 UNRESOLVED_TOPLEVEL_GETTER, | |
| 162 /// Read from a top level getter and write to an unresolved top level setter. | |
| 163 UNRESOLVED_TOPLEVEL_SETTER, | |
| 164 | |
| 165 /// Read from one superclass field and write to another. | 135 /// Read from one superclass field and write to another. |
| 166 SUPER_FIELD_FIELD, | 136 SUPER_FIELD_FIELD, |
| 167 /// Read from a superclass field and write to a superclass setter. | 137 /// Read from a superclass field and write to a superclass setter. |
| 168 SUPER_FIELD_SETTER, | 138 SUPER_FIELD_SETTER, |
| 169 /// Read from a superclass getter and write to a superclass setter. | 139 /// Read from a superclass getter and write to a superclass setter. |
| 170 SUPER_GETTER_SETTER, | 140 SUPER_GETTER_SETTER, |
| 171 /// Read from a superclass method (closurize) and write to a superclass | 141 /// Read from a superclass method (closurize) and write to a superclass |
| 172 /// setter. | 142 /// setter. |
| 173 SUPER_METHOD_SETTER, | 143 SUPER_METHOD_SETTER, |
| 174 /// Read from a superclass getter and write to a superclass field. | 144 /// Read from a superclass getter and write to a superclass field. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 | 251 |
| 282 StaticAccess._(AccessKind kind, this.element) | 252 StaticAccess._(AccessKind kind, this.element) |
| 283 : super._(kind); | 253 : super._(kind); |
| 284 | 254 |
| 285 StaticAccess.superSetter(MethodElement this.element) | 255 StaticAccess.superSetter(MethodElement this.element) |
| 286 : super._(AccessKind.SUPER_SETTER); | 256 : super._(AccessKind.SUPER_SETTER); |
| 287 | 257 |
| 288 StaticAccess.superField(FieldElement this.element) | 258 StaticAccess.superField(FieldElement this.element) |
| 289 : super._(AccessKind.SUPER_FIELD); | 259 : super._(AccessKind.SUPER_FIELD); |
| 290 | 260 |
| 291 StaticAccess.superFinalField(FieldElement this.element) | |
| 292 : super._(AccessKind.SUPER_FINAL_FIELD); | |
| 293 | |
| 294 StaticAccess.superMethod(MethodElement this.element) | 261 StaticAccess.superMethod(MethodElement this.element) |
| 295 : super._(AccessKind.SUPER_METHOD); | 262 : super._(AccessKind.SUPER_METHOD); |
| 296 | 263 |
| 297 StaticAccess.superGetter(MethodElement this.element) | 264 StaticAccess.superGetter(MethodElement this.element) |
| 298 : super._(AccessKind.SUPER_GETTER); | 265 : super._(AccessKind.SUPER_GETTER); |
| 299 | 266 |
| 300 StaticAccess.typeParameterTypeLiteral(TypeVariableElement this.element) | 267 StaticAccess.typeParameterTypeLiteral(TypeVariableElement this.element) |
| 301 : super._(AccessKind.TYPE_PARAMETER_TYPE_LITERAL); | 268 : super._(AccessKind.TYPE_PARAMETER_TYPE_LITERAL); |
| 302 | 269 |
| 303 StaticAccess.localFunction(LocalFunctionElement this.element) | 270 StaticAccess.localFunction(LocalFunctionElement this.element) |
| 304 : super._(AccessKind.LOCAL_FUNCTION); | 271 : super._(AccessKind.LOCAL_FUNCTION); |
| 305 | 272 |
| 306 StaticAccess.localVariable(LocalVariableElement this.element) | 273 StaticAccess.localVariable(LocalVariableElement this.element) |
| 307 : super._(AccessKind.LOCAL_VARIABLE); | 274 : super._(AccessKind.LOCAL_VARIABLE); |
| 308 | 275 |
| 309 StaticAccess.finalLocalVariable(LocalVariableElement this.element) | |
| 310 : super._(AccessKind.FINAL_LOCAL_VARIABLE); | |
| 311 | |
| 312 StaticAccess.parameter(ParameterElement this.element) | 276 StaticAccess.parameter(ParameterElement this.element) |
| 313 : super._(AccessKind.PARAMETER); | 277 : super._(AccessKind.PARAMETER); |
| 314 | 278 |
| 315 StaticAccess.finalParameter(ParameterElement this.element) | |
| 316 : super._(AccessKind.FINAL_PARAMETER); | |
| 317 | |
| 318 StaticAccess.staticField(FieldElement this.element) | 279 StaticAccess.staticField(FieldElement this.element) |
| 319 : super._(AccessKind.STATIC_FIELD); | 280 : super._(AccessKind.STATIC_FIELD); |
| 320 | 281 |
| 321 StaticAccess.finalStaticField(FieldElement this.element) | |
| 322 : super._(AccessKind.FINAL_STATIC_FIELD); | |
| 323 | |
| 324 StaticAccess.staticMethod(MethodElement this.element) | 282 StaticAccess.staticMethod(MethodElement this.element) |
| 325 : super._(AccessKind.STATIC_METHOD); | 283 : super._(AccessKind.STATIC_METHOD); |
| 326 | 284 |
| 327 StaticAccess.staticGetter(MethodElement this.element) | 285 StaticAccess.staticGetter(MethodElement this.element) |
| 328 : super._(AccessKind.STATIC_GETTER); | 286 : super._(AccessKind.STATIC_GETTER); |
| 329 | 287 |
| 330 StaticAccess.staticSetter(MethodElement this.element) | 288 StaticAccess.staticSetter(MethodElement this.element) |
| 331 : super._(AccessKind.STATIC_SETTER); | 289 : super._(AccessKind.STATIC_SETTER); |
| 332 | 290 |
| 333 StaticAccess.topLevelField(FieldElement this.element) | 291 StaticAccess.topLevelField(FieldElement this.element) |
| 334 : super._(AccessKind.TOPLEVEL_FIELD); | 292 : super._(AccessKind.TOPLEVEL_FIELD); |
| 335 | 293 |
| 336 StaticAccess.finalTopLevelField(FieldElement this.element) | |
| 337 : super._(AccessKind.FINAL_TOPLEVEL_FIELD); | |
| 338 | |
| 339 StaticAccess.topLevelMethod(MethodElement this.element) | 294 StaticAccess.topLevelMethod(MethodElement this.element) |
| 340 : super._(AccessKind.TOPLEVEL_METHOD); | 295 : super._(AccessKind.TOPLEVEL_METHOD); |
| 341 | 296 |
| 342 StaticAccess.topLevelGetter(MethodElement this.element) | 297 StaticAccess.topLevelGetter(MethodElement this.element) |
| 343 : super._(AccessKind.TOPLEVEL_GETTER); | 298 : super._(AccessKind.TOPLEVEL_GETTER); |
| 344 | 299 |
| 345 StaticAccess.topLevelSetter(MethodElement this.element) | 300 StaticAccess.topLevelSetter(MethodElement this.element) |
| 346 : super._(AccessKind.TOPLEVEL_SETTER); | 301 : super._(AccessKind.TOPLEVEL_SETTER); |
| 347 | 302 |
| 348 StaticAccess.unresolved(this.element) | 303 StaticAccess.unresolved(this.element) |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 | 466 |
| 512 RedirectingFactoryConstructorAccessSemantics( | 467 RedirectingFactoryConstructorAccessSemantics( |
| 513 ConstructorAccessKind kind, | 468 ConstructorAccessKind kind, |
| 514 Element element, | 469 Element element, |
| 515 DartType type, | 470 DartType type, |
| 516 this.effectiveTargetSemantics) | 471 this.effectiveTargetSemantics) |
| 517 : super(kind, element, type); | 472 : super(kind, element, type); |
| 518 } | 473 } |
| 519 | 474 |
| 520 | 475 |
| OLD | NEW |