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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 library rasta.kernel_visitor; | 5 library rasta.kernel_visitor; |
6 | 6 |
7 import 'package:kernel/ast.dart' as ir; | 7 import 'package:kernel/ast.dart' as ir; |
8 | 8 |
9 import 'package:kernel/accessors.dart' show | 9 import 'package:kernel/accessors.dart' show |
10 Accessor, | 10 Accessor, |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 ForIn node, | 415 ForIn node, |
416 VariableDefinitions declaration, | 416 VariableDefinitions declaration, |
417 {bool isAsync}) { | 417 {bool isAsync}) { |
418 ir.VariableDeclaration variable = buildStatementInBlock(declaration); | 418 ir.VariableDeclaration variable = buildStatementInBlock(declaration); |
419 return buildForInCommon( | 419 return buildForInCommon( |
420 node, variable, buildStatementInBlock(node.body), isAsync: isAsync); | 420 node, variable, buildStatementInBlock(node.body), isAsync: isAsync); |
421 } | 421 } |
422 | 422 |
423 Accessor computeAccessor(ForIn node, Element element) { | 423 Accessor computeAccessor(ForIn node, Element element) { |
424 if (element == null) { | 424 if (element == null) { |
| 425 Send send = node.declaredIdentifier.asSend(); |
| 426 if (send == null) { |
| 427 return new StaticAccessor(null, null); |
| 428 } |
425 // This should be the situation where `node.declaredIdentifier` is | 429 // This should be the situation where `node.declaredIdentifier` is |
426 // unresolved, but in an instance method context. If it is some different | 430 // unresolved, but in an instance method context. If it is some different |
427 // situation, the assignment to [ir.PropertyGet] should act as an | 431 // situation, the assignment to [ir.PropertyGet] should act as an |
428 // assertion. | 432 // assertion. |
429 ir.PropertyGet expression = node.declaredIdentifier.accept(this); | 433 ir.PropertyGet expression = send.accept(this); |
430 return PropertyAccessor.make(expression.receiver, expression.name); | 434 return PropertyAccessor.make(expression.receiver, expression.name); |
431 } else if (kernel.isSyntheticError(element)) { | 435 } else if (kernel.isSyntheticError(element)) { |
432 return new StaticAccessor(null, null); | 436 return new StaticAccessor(null, null); |
433 } else if (element.isGetter) { | 437 } else if (element.isGetter) { |
434 if (element.isInstanceMember) { | 438 if (element.isInstanceMember) { |
435 return new ThisPropertyAccessor(kernel.irName(element.name, element)); | 439 return new ThisPropertyAccessor(kernel.irName(element.name, element)); |
436 } else { | 440 } else { |
437 GetterElement getter = element; | 441 GetterElement getter = element; |
438 Element setter = getter.setter; | 442 Element setter = getter.setter; |
439 return new StaticAccessor( | 443 return new StaticAccessor( |
440 kernel.elementToIr(element), | 444 kernel.elementToIr(element), |
441 setter == null ? null : kernel.elementToIr(element)); | 445 setter == null ? null : kernel.elementToIr(element)); |
442 } | 446 } |
443 } else if (element.isLocal) { | 447 } else if (element.isLocal) { |
444 return new VariableAccessor(getLocal(element)); | 448 return new VariableAccessor(getLocal(element)); |
445 } else if (element.isField) { | 449 } else if (element.isField) { |
446 ir.Member member = kernel.elementToIr(element); | 450 ir.Member member = kernel.elementToIr(element); |
447 return new StaticAccessor( | 451 return new StaticAccessor( |
448 member, (element.isFinal || element.isConst) ? null : member); | 452 member, (element.isFinal || element.isConst) ? null : member); |
449 } else { | 453 } else { |
450 throw internalError(node, "Unhandled for-in variable: $element"); | 454 return new StaticAccessor(null, null); |
451 } | 455 } |
452 } | 456 } |
453 | 457 |
454 /// Builds a for-in statement for this case: | 458 /// Builds a for-in statement for this case: |
455 /// | 459 /// |
456 /// for (element in expression) body | 460 /// for (element in expression) body |
457 /// | 461 /// |
458 /// This is normalized to: | 462 /// This is normalized to: |
459 /// | 463 /// |
460 /// for (final #t in expression) { | 464 /// for (final #t in expression) { |
(...skipping 2551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3012 : this(null, true, node, initializers); | 3016 : this(null, true, node, initializers); |
3013 | 3017 |
3014 accept(ir.Visitor v) => throw "unsupported"; | 3018 accept(ir.Visitor v) => throw "unsupported"; |
3015 | 3019 |
3016 visitChildren(ir.Visitor v) => throw "unsupported"; | 3020 visitChildren(ir.Visitor v) => throw "unsupported"; |
3017 | 3021 |
3018 String toString() { | 3022 String toString() { |
3019 return "IrFunction($kind, $isConstructor, $node, $initializers)"; | 3023 return "IrFunction($kind, $isConstructor, $node, $initializers)"; |
3020 } | 3024 } |
3021 } | 3025 } |
OLD | NEW |