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

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: 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 190 }
181 191
182 @override 192 @override
183 js.Expression visitLiteralMap(tree_ir.LiteralMap node) { 193 js.Expression visitLiteralMap(tree_ir.LiteralMap node) {
184 return giveup(node); 194 return giveup(node);
185 // TODO: implement visitLiteralMap 195 // TODO: implement visitLiteralMap
186 } 196 }
187 197
188 @override 198 @override
189 js.Expression visitLogicalOperator(tree_ir.LogicalOperator node) { 199 js.Expression visitLogicalOperator(tree_ir.LogicalOperator node) {
190 return giveup(node); 200 return new js.Binary(node.operator, visit(node.left), visit(node.right));
191 // TODO: implement visitLogicalOperator
192 } 201 }
193 202
194 @override 203 @override
195 js.Expression visitNot(tree_ir.Not node) { 204 js.Expression visitNot(tree_ir.Not node) {
196 return giveup(node); 205 return giveup(node);
197 // TODO: implement visitNot 206 // TODO: implement visitNot
198 } 207 }
199 208
200 @override 209 @override
201 js.Expression visitReifyTypeVar(tree_ir.ReifyTypeVar node) { 210 js.Expression visitReifyTypeVar(tree_ir.ReifyTypeVar node) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 295 }
287 296
288 @override 297 @override
289 void visitReturn(tree_ir.Return node) { 298 void visitReturn(tree_ir.Return node) {
290 accumulator.add(new js.Return(visitExpression(node.value))); 299 accumulator.add(new js.Return(visitExpression(node.value)));
291 } 300 }
292 301
293 bool isNullLiteral(js.Expression exp) => exp is js.LiteralNull; 302 bool isNullLiteral(js.Expression exp) => exp is js.LiteralNull;
294 303
295 } 304 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698