Chromium Code Reviews| 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 library ddc.src.codegen.js_codegen; | 5 library ddc.src.codegen.js_codegen; |
| 6 | 6 |
| 7 import 'dart:collection' show HashSet; | 7 import 'dart:collection' show HashSet; |
| 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 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1040 rules.isNumType(t)); | 1040 rules.isNumType(t)); |
| 1041 | 1041 |
| 1042 bool typeIsNonNullablePrimitiveInJS(DartType t) => | 1042 bool typeIsNonNullablePrimitiveInJS(DartType t) => |
| 1043 typeIsPrimitiveInJS(t) && rules.isNonNullableType(t); | 1043 typeIsPrimitiveInJS(t) && rules.isNonNullableType(t); |
| 1044 | 1044 |
| 1045 bool binaryOperationIsPrimitive(DartType leftT, DartType rightT) => | 1045 bool binaryOperationIsPrimitive(DartType leftT, DartType rightT) => |
| 1046 typeIsPrimitiveInJS(leftT) && typeIsPrimitiveInJS(rightT); | 1046 typeIsPrimitiveInJS(leftT) && typeIsPrimitiveInJS(rightT); |
| 1047 | 1047 |
| 1048 bool unaryOperationIsPrimitive(DartType t) => typeIsPrimitiveInJS(t); | 1048 bool unaryOperationIsPrimitive(DartType t) => typeIsPrimitiveInJS(t); |
| 1049 | 1049 |
| 1050 bool _isNonNullableExpression(Expression expr) { | |
|
Jennifer Messerly
2015/03/03 19:14:30
add a TODO that this will go away when we have not
vsm
2015/03/03 19:29:41
Done.
| |
| 1051 if (expr is Literal && expr is! NullLiteral) { | |
| 1052 return true; | |
| 1053 } | |
| 1054 if (expr is ParenthesizedExpression) { | |
| 1055 return _isNonNullableExpression(expr.expression); | |
| 1056 } | |
| 1057 DartType type = null; | |
| 1058 if (expr is BinaryExpression) { | |
| 1059 type = rules.getStaticType(expr.leftOperand); | |
| 1060 } else if (expr is PrefixExpression) { | |
| 1061 type = rules.getStaticType(expr.operand); | |
| 1062 } else if (expr is PostfixExpression) { | |
| 1063 type = rules.getStaticType(expr.operand); | |
| 1064 } | |
| 1065 if (type != null && typeIsPrimitiveInJS(type)) { | |
| 1066 return true; | |
| 1067 } | |
| 1068 return false; | |
| 1069 } | |
| 1070 | |
| 1050 JS.Expression notNull(Expression expr) { | 1071 JS.Expression notNull(Expression expr) { |
| 1051 var type = rules.getStaticType(expr); | 1072 var type = rules.getStaticType(expr); |
| 1052 if (rules.isNonNullableType(type)) { | 1073 if (rules.isNonNullableType(type) || _isNonNullableExpression(expr)) { |
| 1053 return _visit(expr); | 1074 return _visit(expr); |
| 1054 } else { | 1075 } else { |
| 1055 return js.call('dart.notNull(#)', _visit(expr)); | 1076 return js.call('dart.notNull(#)', _visit(expr)); |
| 1056 } | 1077 } |
| 1057 } | 1078 } |
| 1058 | 1079 |
| 1059 @override | 1080 @override |
| 1060 JS.Expression visitBinaryExpression(BinaryExpression node) { | 1081 JS.Expression visitBinaryExpression(BinaryExpression node) { |
| 1061 var op = node.operator; | 1082 var op = node.operator; |
| 1062 var left = node.leftOperand; | 1083 var left = node.leftOperand; |
| (...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1916 | 1937 |
| 1917 // TODO(jmesserly): in many cases marking the end will be unncessary. | 1938 // TODO(jmesserly): in many cases marking the end will be unncessary. |
| 1918 printer.mark(_location(node.end)); | 1939 printer.mark(_location(node.end)); |
| 1919 } | 1940 } |
| 1920 | 1941 |
| 1921 String _getIdentifier(AstNode node) { | 1942 String _getIdentifier(AstNode node) { |
| 1922 if (node is SimpleIdentifier) return node.name; | 1943 if (node is SimpleIdentifier) return node.name; |
| 1923 return null; | 1944 return null; |
| 1924 } | 1945 } |
| 1925 } | 1946 } |
| OLD | NEW |