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

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

Issue 737353002: cps-ir: Implement boolean conversion in and use it to implement '&&', '||', and '?:'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase to new test infrastructure. Created 6 years, 1 month 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 | Annotate | Revision Log
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 '../../tree_ir/tree_ir_nodes.dart' as tree_ir; 9 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir;
10 import '../../js/js.dart' as js; 10 import '../../js/js.dart' as js;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 72 }
73 73
74 if (jsVariables.length > 0) { 74 if (jsVariables.length > 0) {
75 // Would be nice to avoid inserting at the beginning of list. 75 // Would be nice to avoid inserting at the beginning of list.
76 accumulator.insert(0, new js.ExpressionStatement( 76 accumulator.insert(0, new js.ExpressionStatement(
77 new js.VariableDeclarationList(jsVariables))); 77 new js.VariableDeclarationList(jsVariables)));
78 } 78 }
79 body = new js.Block(accumulator); 79 body = new js.Block(accumulator);
80 } 80 }
81 81
82 js.Expression visit(tree_ir.Expression node) {
83 js.Expression result = node.accept(this);
84 if (result == null) {
85 glue.reportInternalError('$node did not produce code.');
86 }
87 return result;
88 }
89
82 /// Generates a name for the given variable. First trying with the name of 90 /// Generates a name for the given variable. First trying with the name of
83 /// the [Variable.element] if it is non-null. 91 /// the [Variable.element] if it is non-null.
84 String getVariableName(tree_ir.Variable variable) { 92 String getVariableName(tree_ir.Variable variable) {
85 // TODO(sigurdm): Handle case where the variable belongs to an enclosing 93 // TODO(sigurdm): Handle case where the variable belongs to an enclosing
86 // function. 94 // function.
87 if (variable.host.element != currentFunction) giveup(variable); 95 if (variable.host.element != currentFunction) giveup(variable);
88 96
89 // Get the name if we already have one. 97 // Get the name if we already have one.
90 String name = variableNames[variable]; 98 String name = variableNames[variable];
91 if (name != null) { 99 if (name != null) {
(...skipping 29 matching lines...) Expand all
121 } 129 }
122 130
123 @override 131 @override
124 js.Expression visitConcatenateStrings(tree_ir.ConcatenateStrings node) { 132 js.Expression visitConcatenateStrings(tree_ir.ConcatenateStrings node) {
125 return giveup(node); 133 return giveup(node);
126 // TODO: implement visitConcatenateStrings 134 // TODO: implement visitConcatenateStrings
127 } 135 }
128 136
129 @override 137 @override
130 js.Expression visitConditional(tree_ir.Conditional node) { 138 js.Expression visitConditional(tree_ir.Conditional node) {
131 return giveup(node); 139 return new js.Conditional(
132 // TODO: implement visitConditional 140 visit(node.condition),
141 visit(node.thenExpression),
142 visit(node.elseExpression));
133 } 143 }
134 144
135 @override 145 @override
136 js.Expression visitConstant(tree_ir.Constant node) { 146 js.Expression visitConstant(tree_ir.Constant node) {
137 ConstantValue constant = node.expression.value; 147 ConstantValue constant = node.expression.value;
138 registry.registerCompileTimeConstant(constant); 148 registry.registerCompileTimeConstant(constant);
139 return glue.constantReference(constant); 149 return glue.constantReference(constant);
140 } 150 }
141 151
142 @override 152 @override
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 } 193 }
184 194
185 @override 195 @override
186 js.Expression visitLiteralMap(tree_ir.LiteralMap node) { 196 js.Expression visitLiteralMap(tree_ir.LiteralMap node) {
187 return giveup(node); 197 return giveup(node);
188 // TODO: implement visitLiteralMap 198 // TODO: implement visitLiteralMap
189 } 199 }
190 200
191 @override 201 @override
192 js.Expression visitLogicalOperator(tree_ir.LogicalOperator node) { 202 js.Expression visitLogicalOperator(tree_ir.LogicalOperator node) {
193 return giveup(node); 203 return new js.Binary(node.operator, visit(node.left), visit(node.right));
194 // TODO: implement visitLogicalOperator
195 } 204 }
196 205
197 @override 206 @override
198 js.Expression visitNot(tree_ir.Not node) { 207 js.Expression visitNot(tree_ir.Not node) {
199 return giveup(node); 208 return giveup(node);
200 // TODO: implement visitNot 209 // TODO: implement visitNot
201 } 210 }
202 211
203 @override 212 @override
204 js.Expression visitReifyTypeVar(tree_ir.ReifyTypeVar node) { 213 js.Expression visitReifyTypeVar(tree_ir.ReifyTypeVar node) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 } 293 }
285 294
286 @override 295 @override
287 void visitReturn(tree_ir.Return node) { 296 void visitReturn(tree_ir.Return node) {
288 accumulator.add(new js.Return(visitExpression(node.value))); 297 accumulator.add(new js.Return(visitExpression(node.value)));
289 } 298 }
290 299
291 bool isNullLiteral(js.Expression exp) => exp is js.LiteralNull; 300 bool isNullLiteral(js.Expression exp) => exp is js.LiteralNull;
292 301
293 } 302 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart ('k') | pkg/compiler/lib/src/js_backend/codegen/glue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698