Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: pkg/compiler/lib/src/resolution/members.dart

Issue 1258073010: Refactor resolution index SendSet operations. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add TODO. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/language/language_dart2js.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of resolution; 5 part of resolution;
6 6
7 /// The state of constants in resolutions. 7 /// The state of constants in resolutions.
8 enum ConstantState { 8 enum ConstantState {
9 /// Expressions are not required to be constants. 9 /// Expressions are not required to be constants.
10 NON_CONSTANT, 10 NON_CONSTANT,
(...skipping 2518 matching lines...) Expand 10 before | Expand all | Expand 10 after
2529 /// Callback for native enqueuer to parse a type. Returns [:null:] on error. 2529 /// Callback for native enqueuer to parse a type. Returns [:null:] on error.
2530 DartType resolveTypeFromString(Node node, String typeName) { 2530 DartType resolveTypeFromString(Node node, String typeName) {
2531 Element element = lookupInScope(compiler, node, scope, typeName); 2531 Element element = lookupInScope(compiler, node, scope, typeName);
2532 if (element == null) return null; 2532 if (element == null) return null;
2533 if (element is! ClassElement) return null; 2533 if (element is! ClassElement) return null;
2534 ClassElement cls = element; 2534 ClassElement cls = element;
2535 cls.ensureResolved(compiler); 2535 cls.ensureResolved(compiler);
2536 return cls.computeType(compiler); 2536 return cls.computeType(compiler);
2537 } 2537 }
2538 2538
2539 /// Handle index operations like `a[b] = c`, `a[b] += c`, and `a[b]++`.
2540 ResolutionResult handleIndexSendSet(SendSet node) {
2541 String operatorText = node.assignmentOperator.source;
2542 Node receiver = node.receiver;
2543 Node index = node.arguments.head;
2544 visitExpression(receiver);
2545 visitExpression(index);
2546 if (node.isPrefix || node.isPostfix) {
2547 // `a[b]++` or `++a[b]`.
2548 IncDecOperator operator = IncDecOperator.parse(operatorText);
2549 AccessSemantics semantics = new DynamicAccess.dynamicProperty(receiver);
2550 Selector getterSelector = new Selector.index();
2551 Selector setterSelector = new Selector.indexSet();
2552 Selector operatorSelector =
2553 new Selector.binaryOperator(operator.selectorName);
2554
2555 // TODO(johnniwinther): Remove these when selectors are only accessed
2556 // through the send structure.
2557 registry.setGetterSelectorInComplexSendSet(node, getterSelector);
2558 registry.setSelector(node, setterSelector);
2559 registry.setOperatorSelectorInComplexSendSet(node, operatorSelector);
2560
2561 registry.registerDynamicInvocation(
2562 new UniverseSelector(getterSelector, null));
2563 registry.registerDynamicInvocation(
2564 new UniverseSelector(setterSelector, null));
2565 registry.registerDynamicInvocation(
2566 new UniverseSelector(operatorSelector, null));
2567
2568 SendStructure sendStructure = node.isPrefix
2569 ? new IndexPrefixStructure(
2570 semantics, operator, getterSelector, setterSelector)
2571 : new IndexPostfixStructure(
2572 semantics, operator, getterSelector, setterSelector);
2573 registry.registerSendStructure(node, sendStructure);
2574 return const NoneResult();
2575 } else {
2576 Node rhs = node.arguments.tail.head;
2577 visitExpression(rhs);
2578
2579 AssignmentOperator operator = AssignmentOperator.parse(operatorText);
2580 if (operator.kind == AssignmentOperatorKind.ASSIGN) {
2581 // `a[b] = c`.
2582 AccessSemantics semantics = new DynamicAccess.dynamicProperty(receiver);
2583 Selector setterSelector = new Selector.indexSet();
2584
2585 // TODO(johnniwinther): Remove this when selectors are only accessed
2586 // through the send structure.
2587 registry.setSelector(node, setterSelector);
2588 registry.registerDynamicInvocation(
2589 new UniverseSelector(setterSelector, null));
2590
2591 SendStructure sendStructure =
2592 new IndexSetStructure(semantics, setterSelector);
2593 registry.registerSendStructure(node, sendStructure);
2594 return const NoneResult();
2595 } else {
2596 // `a[b] += c`.
2597 AccessSemantics semantics = new DynamicAccess.dynamicProperty(receiver);
2598 Selector getterSelector = new Selector.index();
2599 Selector setterSelector = new Selector.indexSet();
2600 Selector operatorSelector =
2601 new Selector.binaryOperator(operator.selectorName);
2602
2603 // TODO(johnniwinther): Remove these when selectors are only accessed
2604 // through the send structure.
2605 registry.setGetterSelectorInComplexSendSet(node, getterSelector);
2606 registry.setSelector(node, setterSelector);
2607 registry.setOperatorSelectorInComplexSendSet(node, operatorSelector);
2608
2609 registry.registerDynamicInvocation(
2610 new UniverseSelector(getterSelector, null));
2611 registry.registerDynamicInvocation(
2612 new UniverseSelector(setterSelector, null));
2613 registry.registerDynamicInvocation(
2614 new UniverseSelector(operatorSelector, null));
2615
2616 SendStructure sendStructure = new CompoundIndexSetStructure(
2617 semantics, operator, getterSelector, setterSelector);
2618 registry.registerSendStructure(node, sendStructure);
2619 return const NoneResult();
2620 }
2621 }
2622 }
2623
2539 ResolutionResult visitSendSet(SendSet node) { 2624 ResolutionResult visitSendSet(SendSet node) {
2625 if (node.isIndex) {
2626 if (node.isSuperCall) {
2627 // TODO(johnniwinther): Refactor index operations on super.
2628 } else {
2629 return handleIndexSendSet(node);
2630 }
2631 }
2632 return oldVisitSendSet(node);
2633 }
2634
2635 ResolutionResult oldVisitSendSet(SendSet node) {
2540 bool oldSendIsMemberAccess = sendIsMemberAccess; 2636 bool oldSendIsMemberAccess = sendIsMemberAccess;
2541 sendIsMemberAccess = node.isPropertyAccess || node.isCall; 2637 sendIsMemberAccess = node.isPropertyAccess || node.isCall;
2542 ResolutionResult result = resolveSend(node); 2638 ResolutionResult result = resolveSend(node);
2543 sendIsMemberAccess = oldSendIsMemberAccess; 2639 sendIsMemberAccess = oldSendIsMemberAccess;
2544 Element target = result.element; 2640 Element target = result.element;
2545 Element setter = target; 2641 Element setter = target;
2546 Element getter = target; 2642 Element getter = target;
2547 String operatorName = node.assignmentOperator.source; 2643 String operatorName = node.assignmentOperator.source;
2548 String source = operatorName; 2644 String source = operatorName;
2549 bool isComplex = !identical(source, '='); 2645 bool isComplex = !identical(source, '=');
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after
3821 } 3917 }
3822 return const NoneResult(); 3918 return const NoneResult();
3823 } 3919 }
3824 } 3920 }
3825 3921
3826 /// Looks up [name] in [scope] and unwraps the result. 3922 /// Looks up [name] in [scope] and unwraps the result.
3827 Element lookupInScope(Compiler compiler, Node node, 3923 Element lookupInScope(Compiler compiler, Node node,
3828 Scope scope, String name) { 3924 Scope scope, String name) {
3829 return Elements.unwrap(scope.lookup(name), compiler, node); 3925 return Elements.unwrap(scope.lookup(name), compiler, node);
3830 } 3926 }
OLDNEW
« no previous file with comments | « no previous file | tests/language/language_dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698