| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 dart2js.compile_time_constant_evaluator; | 5 library dart2js.compile_time_constant_evaluator; |
| 6 | 6 |
| 7 import 'constant_system_dart.dart'; | 7 import 'constant_system_dart.dart'; |
| 8 import 'constants/constant_system.dart'; | 8 import 'constants/constant_system.dart'; |
| 9 import 'constants/expressions.dart'; | 9 import 'constants/expressions.dart'; |
| 10 import 'constants/values.dart'; | 10 import 'constants/values.dart'; |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 AstConstant argument = evaluateConstant(link.head); | 332 AstConstant argument = evaluateConstant(link.head); |
| 333 if (argument == null) { | 333 if (argument == null) { |
| 334 return null; | 334 return null; |
| 335 } | 335 } |
| 336 argumentExpressions.add(argument.expression); | 336 argumentExpressions.add(argument.expression); |
| 337 argumentValues.add(argument.value); | 337 argumentValues.add(argument.value); |
| 338 } | 338 } |
| 339 DartType type = elements.getType(node); | 339 DartType type = elements.getType(node); |
| 340 return new AstConstant( | 340 return new AstConstant( |
| 341 context, node, new ListConstantExpression( | 341 context, node, new ListConstantExpression( |
| 342 new ListConstantValue(type, argumentValues), | 342 constantSystem.createList(type, argumentValues), |
| 343 type, | 343 type, |
| 344 argumentExpressions)); | 344 argumentExpressions)); |
| 345 } | 345 } |
| 346 | 346 |
| 347 AstConstant visitLiteralMap(LiteralMap node) { | 347 AstConstant visitLiteralMap(LiteralMap node) { |
| 348 if (!node.isConst) { | 348 if (!node.isConst) { |
| 349 return signalNotCompileTimeConstant(node); | 349 return signalNotCompileTimeConstant(node); |
| 350 } | 350 } |
| 351 List<ConstantExpression> keyExpressions = <ConstantExpression>[]; | 351 List<ConstantExpression> keyExpressions = <ConstantExpression>[]; |
| 352 List<ConstantValue> keyValues = <ConstantValue>[]; | 352 List<ConstantValue> keyValues = <ConstantValue>[]; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 constantSystem.createString(new LiteralDartString(text))))]; | 463 constantSystem.createString(new LiteralDartString(text))))]; |
| 464 AstConstant constant = makeConstructedConstant( | 464 AstConstant constant = makeConstructedConstant( |
| 465 compiler, handler, context, node, type, compiler.symbolConstructor, | 465 compiler, handler, context, node, type, compiler.symbolConstructor, |
| 466 CallStructure.ONE_ARG, | 466 CallStructure.ONE_ARG, |
| 467 arguments, arguments); | 467 arguments, arguments); |
| 468 return new AstConstant( | 468 return new AstConstant( |
| 469 context, node, new SymbolConstantExpression(constant.value, text)); | 469 context, node, new SymbolConstantExpression(constant.value, text)); |
| 470 } | 470 } |
| 471 | 471 |
| 472 AstConstant makeTypeConstant(Node node, DartType elementType) { | 472 AstConstant makeTypeConstant(Node node, DartType elementType) { |
| 473 DartType constantType = | |
| 474 compiler.backend.typeImplementation.computeType(compiler); | |
| 475 return new AstConstant( | 473 return new AstConstant( |
| 476 context, node, new TypeConstantExpression( | 474 context, node, new TypeConstantExpression( |
| 477 new TypeConstantValue(elementType, constantType), | 475 constantSystem.createType(compiler, elementType), |
| 478 elementType)); | 476 elementType)); |
| 479 } | 477 } |
| 480 | 478 |
| 481 /// Returns true if the prefix of the send resolves to a deferred import | 479 /// Returns true if the prefix of the send resolves to a deferred import |
| 482 /// prefix. | 480 /// prefix. |
| 483 bool isDeferredUse(Send send) { | 481 bool isDeferredUse(Send send) { |
| 484 if (send == null) return false; | 482 if (send == null) return false; |
| 485 return compiler.deferredLoadTask | 483 return compiler.deferredLoadTask |
| 486 .deferredPrefixElement(send, elements) != null; | 484 .deferredPrefixElement(send, elements) != null; |
| 487 } | 485 } |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1155 ConstantValue get value => expression.value; | 1153 ConstantValue get value => expression.value; |
| 1156 | 1154 |
| 1157 String toString() => expression.toString(); | 1155 String toString() => expression.toString(); |
| 1158 } | 1156 } |
| 1159 | 1157 |
| 1160 /// A synthetic constant used to recover from errors. | 1158 /// A synthetic constant used to recover from errors. |
| 1161 class ErroneousAstConstant extends AstConstant { | 1159 class ErroneousAstConstant extends AstConstant { |
| 1162 ErroneousAstConstant(Element element, Node node) | 1160 ErroneousAstConstant(Element element, Node node) |
| 1163 : super(element, node, new ErroneousConstantExpression()); | 1161 : super(element, node, new ErroneousConstantExpression()); |
| 1164 } | 1162 } |
| OLD | NEW |