| 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 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 class TypeCheckerTask extends CompilerTask { | 7 class TypeCheckerTask extends CompilerTask { |
| 8 TypeCheckerTask(Compiler compiler) : super(compiler); | 8 TypeCheckerTask(Compiler compiler) : super(compiler); |
| 9 String get name => "Type checker"; | 9 String get name => "Type checker"; |
| 10 | 10 |
| (...skipping 1789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1800 analyze(switchCase); | 1800 analyze(switchCase); |
| 1801 } | 1801 } |
| 1802 | 1802 |
| 1803 if (!hasDefaultCase && expressionType.isEnumType) { | 1803 if (!hasDefaultCase && expressionType.isEnumType) { |
| 1804 compiler.enqueuer.resolution.addDeferredAction(executableContext, () { | 1804 compiler.enqueuer.resolution.addDeferredAction(executableContext, () { |
| 1805 Map<ConstantValue, FieldElement> enumValues = | 1805 Map<ConstantValue, FieldElement> enumValues = |
| 1806 <ConstantValue, FieldElement>{}; | 1806 <ConstantValue, FieldElement>{}; |
| 1807 List<FieldElement> unreferencedFields = <FieldElement>[]; | 1807 List<FieldElement> unreferencedFields = <FieldElement>[]; |
| 1808 EnumClassElement enumClass = expressionType.element; | 1808 EnumClassElement enumClass = expressionType.element; |
| 1809 enumClass.enumValues.forEach((FieldElement field) { | 1809 enumClass.enumValues.forEach((FieldElement field) { |
| 1810 ConstantExpression constantExpression = | 1810 ConstantValue constantValue = |
| 1811 compiler.constants.getConstantForVariable(field); | 1811 compiler.constants.getConstantValueForVariable(field); |
| 1812 if (constantExpression == null) { | 1812 if (constantValue == null) { |
| 1813 // The field might not have been resolved. | 1813 // The field might not have been resolved. |
| 1814 unreferencedFields.add(field); | 1814 unreferencedFields.add(field); |
| 1815 } else { | 1815 } else { |
| 1816 enumValues[constantExpression.value] = field; | 1816 enumValues[constantValue] = field; |
| 1817 } | 1817 } |
| 1818 }); | 1818 }); |
| 1819 | 1819 |
| 1820 for (SwitchCase switchCase in node.cases) { | 1820 for (SwitchCase switchCase in node.cases) { |
| 1821 for (Node labelOrCase in switchCase.labelsAndCases) { | 1821 for (Node labelOrCase in switchCase.labelsAndCases) { |
| 1822 CaseMatch caseMatch = labelOrCase.asCaseMatch(); | 1822 CaseMatch caseMatch = labelOrCase.asCaseMatch(); |
| 1823 if (caseMatch != null) { | 1823 if (caseMatch != null) { |
| 1824 ConstantExpression caseConstant = | 1824 ConstantExpression caseConstant = |
| 1825 compiler.resolver.constantCompiler.compileNode( | 1825 compiler.resolver.constantCompiler.compileNode( |
| 1826 caseMatch.expression, elements); | 1826 caseMatch.expression, elements); |
| 1827 enumValues.remove(caseConstant.value); | 1827 enumValues.remove( |
| 1828 compiler.constants.getConstantValue(caseConstant)); |
| 1828 } | 1829 } |
| 1829 } | 1830 } |
| 1830 } | 1831 } |
| 1831 unreferencedFields.addAll(enumValues.values); | 1832 unreferencedFields.addAll(enumValues.values); |
| 1832 if (!unreferencedFields.isEmpty) { | 1833 if (!unreferencedFields.isEmpty) { |
| 1833 compiler.reportWarning(node, MessageKind.MISSING_ENUM_CASES, | 1834 compiler.reportWarning(node, MessageKind.MISSING_ENUM_CASES, |
| 1834 {'enumType': expressionType, | 1835 {'enumType': expressionType, |
| 1835 'enumValues': unreferencedFields.map((e) => e.name).join(', ')}); | 1836 'enumValues': unreferencedFields.map((e) => e.name).join(', ')}); |
| 1836 } | 1837 } |
| 1837 }); | 1838 }); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1862 | 1863 |
| 1863 visitTypedef(Typedef node) { | 1864 visitTypedef(Typedef node) { |
| 1864 // Do not typecheck [Typedef] nodes. | 1865 // Do not typecheck [Typedef] nodes. |
| 1865 } | 1866 } |
| 1866 | 1867 |
| 1867 visitNode(Node node) { | 1868 visitNode(Node node) { |
| 1868 compiler.internalError(node, | 1869 compiler.internalError(node, |
| 1869 'Unexpected node ${node.getObjectDescription()} in the type checker.'); | 1870 'Unexpected node ${node.getObjectDescription()} in the type checker.'); |
| 1870 } | 1871 } |
| 1871 } | 1872 } |
| OLD | NEW |