| OLD | NEW |
| 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 backend_ast_nodes; | 5 library backend_ast_nodes; |
| 6 | 6 |
| 7 import '../constants/values.dart' as values; | 7 import '../constants/values.dart' as values; |
| 8 import '../dart_types.dart' as types; | 8 import '../dart_types.dart' as types; |
| 9 import '../elements/elements.dart' as elements; | 9 import '../elements/elements.dart' as elements; |
| 10 import '../tree/tree.dart' as tree; | 10 import '../tree/tree.dart' as tree; |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 final String name; | 337 final String name; |
| 338 | 338 |
| 339 elements.Element element; | 339 elements.Element element; |
| 340 | 340 |
| 341 Identifier(this.name); | 341 Identifier(this.name); |
| 342 | 342 |
| 343 bool get assignable => true; | 343 bool get assignable => true; |
| 344 } | 344 } |
| 345 | 345 |
| 346 class Literal extends Expression { | 346 class Literal extends Expression { |
| 347 final values.PrimitiveConstant value; | 347 final values.PrimitiveConstantValue value; |
| 348 | 348 |
| 349 Literal(this.value); | 349 Literal(this.value); |
| 350 } | 350 } |
| 351 | 351 |
| 352 class LiteralList extends Expression { | 352 class LiteralList extends Expression { |
| 353 final bool isConst; | 353 final bool isConst; |
| 354 final TypeAnnotation typeArgument; | 354 final TypeAnnotation typeArgument; |
| 355 final List<Expression> values; | 355 final List<Expression> values; |
| 356 | 356 |
| 357 LiteralList(this.values, { this.typeArgument, this.isConst: false }); | 357 LiteralList(this.values, { this.typeArgument, this.isConst: false }); |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 write(' : '); | 804 write(' : '); |
| 805 writeExp(e.elseExpression, EXPRESSION); | 805 writeExp(e.elseExpression, EXPRESSION); |
| 806 }); | 806 }); |
| 807 } else if (e is Identifier) { | 807 } else if (e is Identifier) { |
| 808 write(e.name); | 808 write(e.name); |
| 809 } else if (e is Literal) { | 809 } else if (e is Literal) { |
| 810 if (e.value.isString) { | 810 if (e.value.isString) { |
| 811 writeStringLiteral(e); | 811 writeStringLiteral(e); |
| 812 } | 812 } |
| 813 else if (e.value.isDouble) { | 813 else if (e.value.isDouble) { |
| 814 double v = e.value.value; | 814 double v = e.value.primitiveValue; |
| 815 if (v == double.INFINITY) { | 815 if (v == double.INFINITY) { |
| 816 withPrecedence(MULTIPLICATIVE, () { | 816 withPrecedence(MULTIPLICATIVE, () { |
| 817 write('1/0.0'); | 817 write('1/0.0'); |
| 818 }); | 818 }); |
| 819 } else if (v == double.NEGATIVE_INFINITY) { | 819 } else if (v == double.NEGATIVE_INFINITY) { |
| 820 withPrecedence(MULTIPLICATIVE, () { | 820 withPrecedence(MULTIPLICATIVE, () { |
| 821 write('-1/0.0'); | 821 write('-1/0.0'); |
| 822 }); | 822 }); |
| 823 } else if (v.isNaN) { | 823 } else if (v.isNaN) { |
| 824 withPrecedence(MULTIPLICATIVE, () { | 824 withPrecedence(MULTIPLICATIVE, () { |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 ]; | 1285 ]; |
| 1286 | 1286 |
| 1287 static StringLiteralOutput analyzeStringLiteral(Expression node) { | 1287 static StringLiteralOutput analyzeStringLiteral(Expression node) { |
| 1288 // TODO(sigurdm,kmillikin): This might be a bit too expensive. Benchmark. | 1288 // TODO(sigurdm,kmillikin): This might be a bit too expensive. Benchmark. |
| 1289 // Flatten the StringConcat tree. | 1289 // Flatten the StringConcat tree. |
| 1290 List parts = []; // Expression or int (char node) | 1290 List parts = []; // Expression or int (char node) |
| 1291 void collectParts(Expression e) { | 1291 void collectParts(Expression e) { |
| 1292 if (e is StringConcat) { | 1292 if (e is StringConcat) { |
| 1293 e.expressions.forEach(collectParts); | 1293 e.expressions.forEach(collectParts); |
| 1294 } else if (e is Literal && e.value.isString) { | 1294 } else if (e is Literal && e.value.isString) { |
| 1295 for (int char in e.value.value) { | 1295 for (int char in e.value.primitiveValue) { |
| 1296 parts.add(char); | 1296 parts.add(char); |
| 1297 } | 1297 } |
| 1298 } else { | 1298 } else { |
| 1299 parts.add(e); | 1299 parts.add(e); |
| 1300 } | 1300 } |
| 1301 } | 1301 } |
| 1302 collectParts(node); | 1302 collectParts(node); |
| 1303 | 1303 |
| 1304 // We use a dynamic algorithm to compute the optimal way of printing | 1304 // We use a dynamic algorithm to compute the optimal way of printing |
| 1305 // the string literal. | 1305 // the string literal. |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1535 final StringChunk previous; | 1535 final StringChunk previous; |
| 1536 final tree.StringQuoting quoting; | 1536 final tree.StringQuoting quoting; |
| 1537 num cost; | 1537 num cost; |
| 1538 | 1538 |
| 1539 OpenStringChunk(this.previous, this.quoting, this.cost); | 1539 OpenStringChunk(this.previous, this.quoting, this.cost); |
| 1540 | 1540 |
| 1541 StringChunk end(int endIndex) { | 1541 StringChunk end(int endIndex) { |
| 1542 return new StringChunk(previous, quoting, endIndex); | 1542 return new StringChunk(previous, quoting, endIndex); |
| 1543 } | 1543 } |
| 1544 } | 1544 } |
| OLD | NEW |