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

Side by Side Diff: pkg/compiler/lib/src/js_backend/codegen/codegen.dart

Issue 1507313006: dart2js cps: Add instruction for null checks. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix true/false misdocumentation about condition and do not emit call Created 5 years 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 code_generator; 5 library code_generator;
6 6
7 import 'glue.dart'; 7 import 'glue.dart';
8 8
9 import '../../closure.dart' show 9 import '../../closure.dart' show
10 ClosureClassElement; 10 ClosureClassElement;
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 } 938 }
939 939
940 @override 940 @override
941 void visitYield(tree_ir.Yield node) { 941 void visitYield(tree_ir.Yield node) {
942 js.Expression value = visitExpression(node.input); 942 js.Expression value = visitExpression(node.input);
943 accumulator.add(new js.DartYield(value, node.hasStar)); 943 accumulator.add(new js.DartYield(value, node.hasStar));
944 visitStatement(node.next); 944 visitStatement(node.next);
945 } 945 }
946 946
947 @override 947 @override
948 void visitNullCheck(tree_ir.NullCheck node) {
949 js.Expression value = visitExpression(node.value);
950 js.Expression access = node.selector != null
951 ? js.js('#.#', [value, glue.invocationName(node.selector)])
952 : js.js('#.toString', [value]);
953 if (node.condition != null) {
954 js.Expression condition = visitExpression(node.condition);
955 js.Statement body = isNullReturn(node.next)
956 ? new js.ExpressionStatement(access)
957 : new js.Return(access);
958 accumulator.add(new js.If.noElse(condition, body));
959 } else {
960 accumulator.add(new js.ExpressionStatement(access));
961 }
962 visitStatement(node.next);
963 }
964
965 @override
948 js.Expression visitApplyBuiltinOperator(tree_ir.ApplyBuiltinOperator node) { 966 js.Expression visitApplyBuiltinOperator(tree_ir.ApplyBuiltinOperator node) {
949 List<js.Expression> args = visitExpressionList(node.arguments); 967 List<js.Expression> args = visitExpressionList(node.arguments);
950 switch (node.operator) { 968 switch (node.operator) {
951 case BuiltinOperator.NumAdd: 969 case BuiltinOperator.NumAdd:
952 return new js.Binary('+', args[0], args[1]); 970 return new js.Binary('+', args[0], args[1]);
953 case BuiltinOperator.NumSubtract: 971 case BuiltinOperator.NumSubtract:
954 return new js.Binary('-', args[0], args[1]); 972 return new js.Binary('-', args[0], args[1]);
955 case BuiltinOperator.NumMultiply: 973 case BuiltinOperator.NumMultiply:
956 return new js.Binary('*', args[0], args[1]); 974 return new js.Binary('*', args[0], args[1]);
957 case BuiltinOperator.NumDivide: 975 case BuiltinOperator.NumDivide:
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 void registerDefaultParameterValues(ExecutableElement element) { 1140 void registerDefaultParameterValues(ExecutableElement element) {
1123 if (element is! FunctionElement) return; 1141 if (element is! FunctionElement) return;
1124 FunctionElement function = element; 1142 FunctionElement function = element;
1125 if (function.isStatic) return; // Defaults are inlined at call sites. 1143 if (function.isStatic) return; // Defaults are inlined at call sites.
1126 function.functionSignature.forEachOptionalParameter((param) { 1144 function.functionSignature.forEachOptionalParameter((param) {
1127 ConstantValue constant = glue.getDefaultParameterValue(param); 1145 ConstantValue constant = glue.getDefaultParameterValue(param);
1128 registry.registerCompileTimeConstant(constant); 1146 registry.registerCompileTimeConstant(constant);
1129 }); 1147 });
1130 } 1148 }
1131 } 1149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698