| 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 'common/backend_api.dart' show BackendClasses; |
| 7 import 'common/resolution.dart' show Resolution; | 8 import 'common/resolution.dart' show Resolution; |
| 8 import 'common/tasks.dart' show CompilerTask, Measurer; | 9 import 'common/tasks.dart' show CompilerTask, Measurer; |
| 9 import 'common.dart'; | 10 import 'common.dart'; |
| 10 import 'compiler.dart' show Compiler; | 11 import 'compiler.dart' show Compiler; |
| 11 import 'constant_system_dart.dart'; | 12 import 'constant_system_dart.dart'; |
| 12 import 'constants/constant_system.dart'; | 13 import 'constants/constant_system.dart'; |
| 13 import 'constants/constructors.dart'; | 14 import 'constants/constructors.dart'; |
| 14 import 'constants/evaluation.dart'; | 15 import 'constants/evaluation.dart'; |
| 15 import 'constants/expressions.dart'; | 16 import 'constants/expressions.dart'; |
| 16 import 'constants/values.dart'; | 17 import 'constants/values.dart'; |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 keyExpressions.add(key.expression); | 500 keyExpressions.add(key.expression); |
| 500 valueExpressions.add(value.expression); | 501 valueExpressions.add(value.expression); |
| 501 map[key.value] = value.value; | 502 map[key.value] = value.value; |
| 502 } | 503 } |
| 503 ResolutionInterfaceType type = elements.getType(node); | 504 ResolutionInterfaceType type = elements.getType(node); |
| 504 return new AstConstant( | 505 return new AstConstant( |
| 505 context, | 506 context, |
| 506 node, | 507 node, |
| 507 new MapConstantExpression(type, keyExpressions, valueExpressions), | 508 new MapConstantExpression(type, keyExpressions, valueExpressions), |
| 508 constantSystem.createMap( | 509 constantSystem.createMap( |
| 509 compiler, type, keyValues, map.values.toList())); | 510 compiler.commonElements, |
| 511 compiler.backend.backendClasses, |
| 512 type, |
| 513 keyValues, |
| 514 map.values.toList())); |
| 510 } | 515 } |
| 511 | 516 |
| 512 AstConstant visitLiteralNull(LiteralNull node) { | 517 AstConstant visitLiteralNull(LiteralNull node) { |
| 513 return new AstConstant(context, node, new NullConstantExpression(), | 518 return new AstConstant(context, node, new NullConstantExpression(), |
| 514 constantSystem.createNull()); | 519 constantSystem.createNull()); |
| 515 } | 520 } |
| 516 | 521 |
| 517 AstConstant visitLiteralString(LiteralString node) { | 522 AstConstant visitLiteralString(LiteralString node) { |
| 518 return new AstConstant( | 523 return new AstConstant( |
| 519 context, | 524 context, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 ]; | 599 ]; |
| 595 ConstructorElement constructor = compiler.commonElements.symbolConstructor; | 600 ConstructorElement constructor = compiler.commonElements.symbolConstructor; |
| 596 AstConstant constant = createConstructorInvocation( | 601 AstConstant constant = createConstructorInvocation( |
| 597 node, type, constructor, CallStructure.ONE_ARG, | 602 node, type, constructor, CallStructure.ONE_ARG, |
| 598 normalizedArguments: arguments); | 603 normalizedArguments: arguments); |
| 599 return new AstConstant( | 604 return new AstConstant( |
| 600 context, node, new SymbolConstantExpression(text), constant.value); | 605 context, node, new SymbolConstantExpression(text), constant.value); |
| 601 } | 606 } |
| 602 | 607 |
| 603 ConstantValue makeTypeConstant(ResolutionDartType elementType) { | 608 ConstantValue makeTypeConstant(ResolutionDartType elementType) { |
| 604 return constantSystem.createType(compiler, elementType); | 609 return constantSystem.createType( |
| 610 compiler.commonElements, compiler.backend.backendClasses, elementType); |
| 605 } | 611 } |
| 606 | 612 |
| 607 /// Returns true if the prefix of the send resolves to a deferred import | 613 /// Returns true if the prefix of the send resolves to a deferred import |
| 608 /// prefix. | 614 /// prefix. |
| 609 bool isDeferredUse(Send send) { | 615 bool isDeferredUse(Send send) { |
| 610 if (send == null) return false; | 616 if (send == null) return false; |
| 611 return compiler.deferredLoadTask.deferredPrefixElement(send, elements) != | 617 return compiler.deferredLoadTask.deferredPrefixElement(send, elements) != |
| 612 null; | 618 null; |
| 613 } | 619 } |
| 614 | 620 |
| (...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1435 ErroneousAstConstant(Element element, Node node) | 1441 ErroneousAstConstant(Element element, Node node) |
| 1436 : super( | 1442 : super( |
| 1437 element, | 1443 element, |
| 1438 node, | 1444 node, |
| 1439 // TODO(johnniwinther): Return a [NonConstantValue] instead. | 1445 // TODO(johnniwinther): Return a [NonConstantValue] instead. |
| 1440 new ErroneousConstantExpression(), | 1446 new ErroneousConstantExpression(), |
| 1441 new NullConstantValue()); | 1447 new NullConstantValue()); |
| 1442 } | 1448 } |
| 1443 | 1449 |
| 1444 class _CompilerEnvironment implements Environment { | 1450 class _CompilerEnvironment implements Environment { |
| 1445 final Compiler compiler; | 1451 final Compiler _compiler; |
| 1446 | 1452 |
| 1447 _CompilerEnvironment(this.compiler); | 1453 _CompilerEnvironment(this._compiler); |
| 1454 |
| 1455 @override |
| 1456 BackendClasses get backendClasses => _compiler.backend.backendClasses; |
| 1457 |
| 1458 @override |
| 1459 CommonElements get commonElements => _compiler.commonElements; |
| 1448 | 1460 |
| 1449 @override | 1461 @override |
| 1450 String readFromEnvironment(String name) { | 1462 String readFromEnvironment(String name) { |
| 1451 return compiler.fromEnvironment(name); | 1463 return _compiler.fromEnvironment(name); |
| 1452 } | 1464 } |
| 1453 | 1465 |
| 1454 @override | 1466 @override |
| 1455 ResolutionInterfaceType substByContext( | 1467 ResolutionInterfaceType substByContext( |
| 1456 ResolutionInterfaceType base, ResolutionInterfaceType target) { | 1468 ResolutionInterfaceType base, ResolutionInterfaceType target) { |
| 1457 return base.substByContext(target); | 1469 return base.substByContext(target); |
| 1458 } | 1470 } |
| 1459 | 1471 |
| 1460 @override | 1472 @override |
| 1461 ConstantConstructor getConstructorConstant(ConstructorElement constructor) { | 1473 ConstantConstructor getConstructorConstant(ConstructorElement constructor) { |
| 1462 return constructor.constantConstructor; | 1474 return constructor.constantConstructor; |
| 1463 } | 1475 } |
| 1464 | 1476 |
| 1465 @override | 1477 @override |
| 1466 ConstantExpression getFieldConstant(FieldElement field) { | 1478 ConstantExpression getFieldConstant(FieldElement field) { |
| 1467 return field.constant; | 1479 return field.constant; |
| 1468 } | 1480 } |
| 1469 | 1481 |
| 1470 @override | 1482 @override |
| 1471 ConstantExpression getLocalConstant(LocalVariableElement local) { | 1483 ConstantExpression getLocalConstant(LocalVariableElement local) { |
| 1472 return local.constant; | 1484 return local.constant; |
| 1473 } | 1485 } |
| 1474 } | 1486 } |
| OLD | NEW |