| 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 */ |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 /// Read from a superclass where the getter is unresolved. | 185 /// Read from a superclass where the getter is unresolved. |
| 186 UNRESOLVED_SUPER_GETTER, | 186 UNRESOLVED_SUPER_GETTER, |
| 187 /// Read from a superclass getter and write to an unresolved setter. | 187 /// Read from a superclass getter and write to an unresolved setter. |
| 188 UNRESOLVED_SUPER_SETTER, | 188 UNRESOLVED_SUPER_SETTER, |
| 189 } | 189 } |
| 190 | 190 |
| 191 /** | 191 /** |
| 192 * Data structure used to classify the semantics of a property access or method | 192 * Data structure used to classify the semantics of a property access or method |
| 193 * or function invocation. | 193 * or function invocation. |
| 194 */ | 194 */ |
| 195 class AccessSemantics { | 195 abstract class AccessSemantics { |
| 196 /** | 196 /** |
| 197 * The kind of access. | 197 * The kind of access. |
| 198 */ | 198 */ |
| 199 final AccessKind kind; | 199 final AccessKind kind; |
| 200 | 200 |
| 201 /** | 201 /** |
| 202 * The element being accessed, if statically known. This will be null if | 202 * The element being accessed, if statically known. This will be null if |
| 203 * [kind] is DYNAMIC or if the element is undefined (e.g. an attempt to | 203 * [kind] is DYNAMIC or if the element is undefined (e.g. an attempt to |
| 204 * access a non-existent static method in a class). | 204 * access a non-existent static method in a class). |
| 205 */ | 205 */ |
| 206 Element get element => null; | 206 Element get element => null; |
| 207 | 207 |
| 208 /** | |
| 209 * The class containing the element being accessed, if this is a static | |
| 210 * reference to an element in a class. This will be null if [kind] is | |
| 211 * DYNAMIC, LOCAL_FUNCTION, LOCAL_VARIABLE, PARAMETER, TOPLEVEL_CLASS, or | |
| 212 * TYPE_PARAMETER, or if the element being accessed is defined at toplevel | |
| 213 * within a library. | |
| 214 * | |
| 215 * Note: it is possible for [classElement] to be non-null and for [element] | |
| 216 * to be null; for example this occurs if the element being accessed is a | |
| 217 * non-existent static method or field inside an existing class. | |
| 218 */ | |
| 219 ClassElement get classElement => null; | |
| 220 | |
| 221 // TODO(paulberry): would it also be useful to store the libraryElement? | |
| 222 | |
| 223 // TODO(johnniwinther): Do we need this? | |
| 224 /** | |
| 225 * When [kind] is DYNAMIC_PROPERTY, the expression whose runtime type | |
| 226 * determines the class in which [identifier] should be looked up. | |
| 227 * | |
| 228 * When [kind] is not DYNAMIC_PROPERTY, this field is always null. | |
| 229 */ | |
| 230 /*Expression*/ get target => null; | |
| 231 | |
| 232 ConstantExpression get constant => null; | 208 ConstantExpression get constant => null; |
| 233 | 209 |
| 234 /// The element for the getter in case of a compound access, | 210 /// The element for the getter in case of a compound access, |
| 235 /// [element] otherwise. | 211 /// [element] otherwise. |
| 236 Element get getter => element; | 212 Element get getter => element; |
| 237 | 213 |
| 238 /// The element for the setter in case of a compound access, | 214 /// The element for the setter in case of a compound access, |
| 239 /// [element] otherwise. | 215 /// [element] otherwise. |
| 240 Element get setter => element; | 216 Element get setter => element; |
| 241 | 217 |
| 242 // TODO(johnniwinther): Make access semantics getter/setter specific. | 218 // TODO(johnniwinther): Make access semantics getter/setter specific. |
| 243 /// `true` if the [element] of this access is accessed statically. | 219 /// `true` if the [element] of this access is accessed statically. |
| 244 bool get isAccessedStatically => false; | 220 bool get isAccessedStatically => false; |
| 245 | 221 |
| 246 AccessSemantics.expression() | 222 const AccessSemantics._(this.kind); |
| 247 : kind = AccessKind.EXPRESSION; | |
| 248 | |
| 249 AccessSemantics.thisAccess() | |
| 250 : kind = AccessKind.THIS; | |
| 251 | |
| 252 AccessSemantics.thisProperty() | |
| 253 : kind = AccessKind.THIS_PROPERTY; | |
| 254 | |
| 255 AccessSemantics._(this.kind); | |
| 256 | 223 |
| 257 String toString() { | 224 String toString() { |
| 258 StringBuffer sb = new StringBuffer(); | 225 StringBuffer sb = new StringBuffer(); |
| 259 sb.write('AccessSemantics['); | 226 sb.write('AccessSemantics['); |
| 260 sb.write('kind=$kind,'); | 227 sb.write('kind=$kind,'); |
| 261 if (element != null) { | 228 if (element != null) { |
| 262 sb.write('element='); | 229 sb.write('element='); |
| 263 if (classElement != null) { | 230 if (element.enclosingClass != null) { |
| 264 sb.write('${classElement.name}.'); | 231 sb.write('${element.enclosingClass.name}.'); |
| 265 } | 232 } |
| 266 sb.write('${element}'); | 233 sb.write('${element}'); |
| 267 } | 234 } |
| 268 sb.write(']'); | 235 sb.write(']'); |
| 269 return sb.toString(); | 236 return sb.toString(); |
| 270 } | 237 } |
| 271 } | 238 } |
| 272 | 239 |
| 273 | 240 |
| 274 class DynamicAccess extends AccessSemantics { | 241 class DynamicAccess extends AccessSemantics { |
| 275 final target; | 242 const DynamicAccess.expression() |
| 243 : super._(AccessKind.EXPRESSION); |
| 276 | 244 |
| 277 DynamicAccess.dynamicProperty(this.target) | 245 const DynamicAccess.thisAccess() |
| 246 : super._(AccessKind.THIS); |
| 247 |
| 248 const DynamicAccess.thisProperty() |
| 249 : super._(AccessKind.THIS_PROPERTY); |
| 250 |
| 251 const DynamicAccess.dynamicProperty() |
| 278 : super._(AccessKind.DYNAMIC_PROPERTY); | 252 : super._(AccessKind.DYNAMIC_PROPERTY); |
| 279 | 253 |
| 280 DynamicAccess.ifNotNullProperty(this.target) | 254 const DynamicAccess.ifNotNullProperty() |
| 281 : super._(AccessKind.CONDITIONAL_DYNAMIC_PROPERTY); | 255 : super._(AccessKind.CONDITIONAL_DYNAMIC_PROPERTY); |
| 282 | 256 |
| 283 bool get isAccessedStatically => false; | 257 bool get isAccessedStatically => false; |
| 284 } | 258 } |
| 285 | 259 |
| 286 class ConstantAccess extends AccessSemantics { | 260 class ConstantAccess extends AccessSemantics { |
| 287 final ConstantExpression constant; | 261 final ConstantExpression constant; |
| 288 | 262 |
| 289 ConstantAccess(AccessKind kind, this.constant) | 263 ConstantAccess(AccessKind kind, this.constant) |
| 290 : super._(kind); | 264 : super._(kind); |
| 291 | 265 |
| 292 ConstantAccess.classTypeLiteral(this.constant) | 266 ConstantAccess.classTypeLiteral(this.constant) |
| 293 : super._(AccessKind.CLASS_TYPE_LITERAL); | 267 : super._(AccessKind.CLASS_TYPE_LITERAL); |
| 294 | 268 |
| 295 ConstantAccess.typedefTypeLiteral(this.constant) | 269 ConstantAccess.typedefTypeLiteral(this.constant) |
| 296 : super._(AccessKind.TYPEDEF_TYPE_LITERAL); | 270 : super._(AccessKind.TYPEDEF_TYPE_LITERAL); |
| 297 | 271 |
| 298 ConstantAccess.dynamicTypeLiteral(this.constant) | 272 ConstantAccess.dynamicTypeLiteral(this.constant) |
| 299 : super._(AccessKind.DYNAMIC_TYPE_LITERAL); | 273 : super._(AccessKind.DYNAMIC_TYPE_LITERAL); |
| 300 | 274 |
| 301 bool get isAccessedStatically => false; | 275 bool get isAccessedStatically => false; |
| 302 } | 276 } |
| 303 | 277 |
| 304 class StaticAccess extends AccessSemantics { | 278 class StaticAccess extends AccessSemantics { |
| 305 final Element element; | 279 final Element element; |
| 306 | 280 |
| 307 ClassElement get classElement => element.enclosingClass; | |
| 308 | |
| 309 StaticAccess._(AccessKind kind, this.element) | 281 StaticAccess._(AccessKind kind, this.element) |
| 310 : super._(kind); | 282 : super._(kind); |
| 311 | 283 |
| 312 StaticAccess.superSetter(MethodElement this.element) | 284 StaticAccess.superSetter(MethodElement this.element) |
| 313 : super._(AccessKind.SUPER_SETTER); | 285 : super._(AccessKind.SUPER_SETTER); |
| 314 | 286 |
| 315 StaticAccess.superField(FieldElement this.element) | 287 StaticAccess.superField(FieldElement this.element) |
| 316 : super._(AccessKind.SUPER_FIELD); | 288 : super._(AccessKind.SUPER_FIELD); |
| 317 | 289 |
| 318 StaticAccess.superFinalField(FieldElement this.element) | 290 StaticAccess.superFinalField(FieldElement this.element) |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 | 542 |
| 571 RedirectingFactoryConstructorAccessSemantics( | 543 RedirectingFactoryConstructorAccessSemantics( |
| 572 ConstructorAccessKind kind, | 544 ConstructorAccessKind kind, |
| 573 Element element, | 545 Element element, |
| 574 DartType type, | 546 DartType type, |
| 575 this.effectiveTargetSemantics) | 547 this.effectiveTargetSemantics) |
| 576 : super(kind, element, type); | 548 : super(kind, element, type); |
| 577 } | 549 } |
| 578 | 550 |
| 579 | 551 |
| OLD | NEW |