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: sdk/lib/_internal/compiler/implementation/dart_backend/dart_tree_printer.dart

Issue 295933006: dart2dart: Introduce compound assignment and prefix increment in dart_codegen. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: SVN rebase Created 6 years, 7 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 dart_tree_printer; 5 library dart_tree_printer;
6 6
7 import 'dart_printer.dart'; 7 import 'dart_printer.dart';
8 import '../tree/tree.dart' as tree; 8 import '../tree/tree.dart' as tree;
9 import '../scanner/scannerlib.dart'; 9 import '../scanner/scannerlib.dart';
10 import '../util/util.dart'; 10 import '../util/util.dart';
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 selector = makeIdentifier(left.fieldName); 261 selector = makeIdentifier(left.fieldName);
262 arguments = singleton(makeExpression(exp.right)); 262 arguments = singleton(makeExpression(exp.right));
263 } else if (left is IndexExpression) { 263 } else if (left is IndexExpression) {
264 receiver = makeExp(left.object, PRIMARY, beginStmt: beginStmt); 264 receiver = makeExp(left.object, PRIMARY, beginStmt: beginStmt);
265 selector = new tree.Operator(indexToken); 265 selector = new tree.Operator(indexToken);
266 arguments = bracketList(',', 266 arguments = bracketList(',',
267 [makeExpression(left.index), makeExpression(exp.right)]); 267 [makeExpression(left.index), makeExpression(exp.right)]);
268 } else { 268 } else {
269 throw "Unexpected left-hand side of assignment: ${left}"; 269 throw "Unexpected left-hand side of assignment: ${left}";
270 } 270 }
271 tree.Operator op = new tree.Operator(assignmentToken(exp.operatorName)); 271 tree.Operator op = new tree.Operator(assignmentToken(exp.operator));
272 result = new tree.SendSet(receiver, selector, op, arguments); 272 result = new tree.SendSet(receiver, selector, op, arguments);
273 if (left is Identifier) { 273 if (left is Identifier) {
274 setElement(result, element, exp); 274 setElement(result, element, exp);
275 } 275 }
276 precedence = EXPRESSION; 276 precedence = EXPRESSION;
277 } else if (exp is BinaryOperator) { 277 } else if (exp is BinaryOperator) {
278 precedence = BINARY_PRECEDENCE[exp.operatorName]; 278 precedence = BINARY_PRECEDENCE[exp.operator];
279 int deltaLeft = isAssociativeBinaryOperator(precedence) ? 0 : 1; 279 int deltaLeft = isAssociativeBinaryOperator(precedence) ? 0 : 1;
280 result = new tree.Send( 280 result = new tree.Send(
281 makeExp(exp.left, precedence + deltaLeft, beginStmt: beginStmt), 281 makeExp(exp.left, precedence + deltaLeft, beginStmt: beginStmt),
282 new tree.Operator(binopToken(exp.operatorName)), 282 new tree.Operator(binopToken(exp.operator)),
283 singleton(makeExp(exp.right, precedence + 1))); 283 singleton(makeExp(exp.right, precedence + 1)));
284 } else if (exp is CallFunction) { 284 } else if (exp is CallFunction) {
285 precedence = CALLEE; 285 precedence = CALLEE;
286 tree.Node selector; 286 tree.Node selector;
287 Expression callee = exp.callee; 287 Expression callee = exp.callee;
288 elements.Element element; 288 elements.Element element;
289 if (callee is Identifier) { 289 if (callee is Identifier) {
290 selector = makeIdentifier(callee.name); 290 selector = makeIdentifier(callee.name);
291 element = callee.element; 291 element = callee.element;
292 } else { 292 } else {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 } else if (lvalue is FieldExpression) { 377 } else if (lvalue is FieldExpression) {
378 receiver = makeExp(lvalue.object, PRIMARY, beginStmt: innerBeginStmt); 378 receiver = makeExp(lvalue.object, PRIMARY, beginStmt: innerBeginStmt);
379 selector = makeIdentifier(lvalue.fieldName); 379 selector = makeIdentifier(lvalue.fieldName);
380 } else if (lvalue is IndexExpression) { 380 } else if (lvalue is IndexExpression) {
381 receiver = makeExp(lvalue.object, PRIMARY, beginStmt: innerBeginStmt); 381 receiver = makeExp(lvalue.object, PRIMARY, beginStmt: innerBeginStmt);
382 selector = new tree.Operator(indexToken); 382 selector = new tree.Operator(indexToken);
383 argument = makeExpression(lvalue.index); 383 argument = makeExpression(lvalue.index);
384 } else { 384 } else {
385 throw "Unrecognized left-hand side: ${lvalue}"; 385 throw "Unrecognized left-hand side: ${lvalue}";
386 } 386 }
387 tree.Operator op = new tree.Operator(incrementToken(exp.operatorName)); 387 tree.Operator op = new tree.Operator(incrementToken(exp.operator));
388 if (exp.isPrefix) { 388 if (exp.isPrefix) {
389 precedence = UNARY; 389 precedence = UNARY;
390 result = new tree.SendSet.prefix(receiver, selector, op, argument); 390 result = new tree.SendSet.prefix(receiver, selector, op, argument);
391 } else { 391 } else {
392 precedence = POSTFIX_INCREMENT; 392 precedence = POSTFIX_INCREMENT;
393 result = new tree.SendSet.postfix(receiver, selector, op, argument); 393 result = new tree.SendSet.postfix(receiver, selector, op, argument);
394 } 394 }
395 if (lvalue is Identifier) {
396 setElement(result, lvalue.element, exp);
397 }
395 } else if (exp is IndexExpression) { 398 } else if (exp is IndexExpression) {
396 precedence = CALLEE; 399 precedence = CALLEE;
397 result = new tree.Send( 400 result = new tree.Send(
398 makeExp(exp.object, PRIMARY, beginStmt: beginStmt), 401 makeExp(exp.object, PRIMARY, beginStmt: beginStmt),
399 new tree.Operator(indexToken), 402 new tree.Operator(indexToken),
400 bracketList(',', [makeExpression(exp.index)])); 403 bracketList(',', [makeExpression(exp.index)]));
401 } else if (exp is Literal) { 404 } else if (exp is Literal) {
402 precedence = CALLEE; 405 precedence = CALLEE;
403 dart2js.PrimitiveConstant value = exp.value; 406 dart2js.PrimitiveConstant value = exp.value;
404 Token tok = new StringToken.fromString(STRING_INFO, '${value.value}', -1); 407 Token tok = new StringToken.fromString(STRING_INFO, '${value.value}', -1);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 } else if (exp is Throw) { 466 } else if (exp is Throw) {
464 precedence = EXPRESSION; // ??? 467 precedence = EXPRESSION; // ???
465 result = new tree.Throw( 468 result = new tree.Throw(
466 makeExpression(exp.expression), 469 makeExpression(exp.expression),
467 throwToken, 470 throwToken,
468 throwToken); // endToken not used by unparser 471 throwToken); // endToken not used by unparser
469 } else if (exp is TypeOperator) { 472 } else if (exp is TypeOperator) {
470 precedence = RELATIONAL; 473 precedence = RELATIONAL;
471 tree.Operator operator; 474 tree.Operator operator;
472 tree.Node rightOperand = makeType(exp.type); 475 tree.Node rightOperand = makeType(exp.type);
473 if (exp.operatorName == 'is!') { 476 if (exp.operator == 'is!') {
474 operator = new tree.Operator(typeOpToken('is')); 477 operator = new tree.Operator(typeOpToken('is'));
475 rightOperand = new tree.Send( 478 rightOperand = new tree.Send(
476 rightOperand, 479 rightOperand,
477 new tree.Operator(bang), 480 new tree.Operator(bang),
478 blankList()); 481 blankList());
479 } else { 482 } else {
480 operator = new tree.Operator(typeOpToken(exp.operatorName)); 483 operator = new tree.Operator(typeOpToken(exp.operator));
481 } 484 }
482 result = new tree.Send( 485 result = new tree.Send(
483 makeExp(exp.expression, BITWISE_OR, beginStmt: beginStmt), 486 makeExp(exp.expression, BITWISE_OR, beginStmt: beginStmt),
484 operator, 487 operator,
485 singleton(rightOperand)); 488 singleton(rightOperand));
486 } else if (exp is UnaryOperator) { 489 } else if (exp is UnaryOperator) {
487 precedence = UNARY; 490 precedence = UNARY;
488 result = new tree.Send.prefix( 491 result = new tree.Send.prefix(
489 makeExp(exp.operand, UNARY), 492 makeExp(exp.operand, UNARY),
490 new tree.Operator(unopToken(exp.operatorName))); 493 new tree.Operator(unopToken(exp.operatorName)));
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 printStringChunk(chunk.previous), 914 printStringChunk(chunk.previous),
912 node); 915 node);
913 } else { 916 } else {
914 return node; 917 return node;
915 } 918 }
916 } 919 }
917 return printStringChunk(output.chunk); 920 return printStringChunk(output.chunk);
918 } 921 }
919 922
920 } 923 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698