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

Side by Side Diff: lib/src/codegen/js_codegen.dart

Issue 1071773002: metalet with postfix improvement (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 8 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
OLDNEW
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 dev_compiler.src.codegen.js_codegen; 5 library dev_compiler.src.codegen.js_codegen;
6 6
7 import 'dart:collection' show HashSet, HashMap; 7 import 'dart:collection' show HashSet, HashMap;
8 import 'dart:io' show Directory, File; 8 import 'dart:io' show Directory, File;
9 9
10 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 10 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
(...skipping 1525 matching lines...) Expand 10 before | Expand all | Expand 10 after
1536 } 1536 }
1537 1537
1538 JS.Expression notNull(Expression expr) { 1538 JS.Expression notNull(Expression expr) {
1539 if (_isNonNullableExpression(expr)) { 1539 if (_isNonNullableExpression(expr)) {
1540 return _visit(expr); 1540 return _visit(expr);
1541 } else { 1541 } else {
1542 return js.call('dart.notNull(#)', _visit(expr)); 1542 return js.call('dart.notNull(#)', _visit(expr));
1543 } 1543 }
1544 } 1544 }
1545 1545
1546 JS.Expression _assignableNotNull(Expression expr) {
1547 if (expr is IndexExpression) {
1548 IndexExpression i = expr;
1549 return js.call(
1550 'dart.index(#, #).notNull', [_visit(i.target), _visit(i.index)]);
1551 } else if (expr is PropertyAccess) {
1552 PropertyAccess p = expr;
1553 return js.call('dart.prop(#, #).notNull', [
1554 _visit(p.target),
1555 _emitMemberName(p.propertyName.name)
1556 ]);
1557 } else if (expr is PrefixedIdentifier) {
1558 PrefixedIdentifier p = expr;
1559 return js.call('dart.prop(#, #).notNull', [
1560 _visit(p.prefix),
1561 _emitMemberName(p.identifier.name)
1562 ]);
1563 }
1564 return null;
1565 }
1566
1546 @override 1567 @override
1547 JS.Expression visitBinaryExpression(BinaryExpression node) { 1568 JS.Expression visitBinaryExpression(BinaryExpression node) {
1548 var op = node.operator; 1569 var op = node.operator;
1549 var left = node.leftOperand; 1570 var left = node.leftOperand;
1550 var right = node.rightOperand; 1571 var right = node.rightOperand;
1551 var leftType = rules.getStaticType(left); 1572 var leftType = rules.getStaticType(left);
1552 var rightType = rules.getStaticType(right); 1573 var rightType = rules.getStaticType(right);
1553 1574
1554 var code; 1575 var code;
1555 if (op.type.isEqualityOperator) { 1576 if (op.type.isEqualityOperator) {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1740 return t; 1761 return t;
1741 } 1762 }
1742 1763
1743 @override 1764 @override
1744 JS.Expression visitPostfixExpression(PostfixExpression node) { 1765 JS.Expression visitPostfixExpression(PostfixExpression node) {
1745 var op = node.operator; 1766 var op = node.operator;
1746 var expr = node.operand; 1767 var expr = node.operand;
1747 1768
1748 var dispatchType = rules.getStaticType(expr); 1769 var dispatchType = rules.getStaticType(expr);
1749 if (unaryOperationIsPrimitive(dispatchType)) { 1770 if (unaryOperationIsPrimitive(dispatchType)) {
1771 JS.Expression lvalue;
1750 if (_isNonNullableExpression(expr)) { 1772 if (_isNonNullableExpression(expr)) {
1751 return js.call('#$op', _visit(expr)); 1773 // TODO(jmesserly): ensure that expr is generated as a lvalue.
1774 // I think this works today because if the result type is primitive,
1775 // it can't be a dynamic call. But worth checking.
1776 lvalue = _visit(expr);
1777 } else {
1778 lvalue = _assignableNotNull(expr);
1752 } 1779 }
1780 if (lvalue != null) return new JS.Postfix(op.lexeme, lvalue);
1753 } 1781 }
1754 1782
1755 assert(op.lexeme == '++' || op.lexeme == '--'); 1783 assert(op.lexeme == '++' || op.lexeme == '--');
1756 return _emitPostfixIncrement(expr, op); 1784 return _emitPostfixIncrement(expr, op);
1757 } 1785 }
1758 1786
1759 @override 1787 @override
1760 JS.Expression visitPrefixExpression(PrefixExpression node) { 1788 JS.Expression visitPrefixExpression(PrefixExpression node) {
1761 return _emitPrefixExpression(node.operator, node.operand); 1789 return _emitPrefixExpression(node.operator, node.operand);
1762 } 1790 }
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
2517 if (parent is MethodInvocation && 2545 if (parent is MethodInvocation &&
2518 identical(parent.methodName, node)) return; 2546 identical(parent.methodName, node)) return;
2519 if (parent is ConstructorName) return; 2547 if (parent is ConstructorName) return;
2520 if (parent is Label) return; 2548 if (parent is Label) return;
2521 2549
2522 if (node.inSetterContext() && node.staticElement == _variable) { 2550 if (node.inSetterContext() && node.staticElement == _variable) {
2523 _potentiallyMutated = true; 2551 _potentiallyMutated = true;
2524 } 2552 }
2525 } 2553 }
2526 } 2554 }
OLDNEW
« lib/runtime/dart/_isolate_helper.js ('K') | « lib/runtime/dart_runtime.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698