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

Side by Side Diff: pkg/analyzer2dart/lib/src/cps_generator.dart

Issue 661923003: Support binary expressions in analyzer2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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 | 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 analyzer2dart.cps_generator; 5 library analyzer2dart.cps_generator;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 8
9 import 'package:compiler/implementation/elements/elements.dart' as dart2js; 9 import 'package:compiler/implementation/elements/elements.dart' as dart2js;
10 import 'package:analyzer/src/generated/source.dart'; 10 import 'package:analyzer/src/generated/source.dart';
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 ir.Node visitStaticFieldAccess(AstNode node, AccessSemantics semantics) { 180 ir.Node visitStaticFieldAccess(AstNode node, AccessSemantics semantics) {
181 analyzer.Element element = semantics.element; 181 analyzer.Element element = semantics.element;
182 dart2js.Element target = converter.convertElement(element); 182 dart2js.Element target = converter.convertElement(element);
183 // TODO(johnniwinther): Selector information should be computed in the 183 // TODO(johnniwinther): Selector information should be computed in the
184 // [TreeShaker] and shared with the [CpsGeneratingVisitor]. 184 // [TreeShaker] and shared with the [CpsGeneratingVisitor].
185 assert(invariant(node, target.isTopLevel || target.isStatic, 185 assert(invariant(node, target.isTopLevel || target.isStatic,
186 '$target expected to be top-level or static.')); 186 '$target expected to be top-level or static.'));
187 return irBuilder.buildStaticGet(target, 187 return irBuilder.buildStaticGet(target,
188 new Selector.getter(target.name, target.library)); 188 new Selector.getter(target.name, target.library));
189 } 189 }
190
191 ir.Primitive handleBinaryExpression(BinaryExpression node,
192 String op) {
193 ir.Primitive left = node.leftOperand.accept(this);
194 ir.Primitive right = node.rightOperand.accept(this);
195 Selector selector = new Selector.binaryOperator(op);
196 return irBuilder.buildDynamicInvocation(
197 left, selector, <ir.Definition>[right]);
198 }
199
200 ir.Node handleLazyOperator(BinaryExpression node, {bool isLazyOr: false}) {
201 ir.Primitive left = node.leftOperand.accept(this);
202 ir.Primitive buildRightValue(IrBuilder builder) {
203 return withBuilder(builder, () => node.rightOperand.accept(this));
204 }
205 return irBuilder.buildLogicalOperator(
206 left, buildRightValue, isLazyOr: isLazyOr);
207 }
208
209 @override
210 ir.Node visitBinaryExpression(BinaryExpression node) {
211 // TODO(johnniwinther,paulberry,brianwilkerson): The operator should be
212 // available through an enum.
213 String op = node.operator.lexeme;
214 switch (op) {
215 case '||':
216 case '&&':
217 return handleLazyOperator(node, isLazyOr: op == '||');
218 case '!=':
219 return irBuilder.buildNegation(handleBinaryExpression(node, '=='));
220 default:
221 return handleBinaryExpression(node, op);
222 }
223 }
190 } 224 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698