| 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 resolution; | 5 part of resolution; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Core implementation of resolution. | 8 * Core implementation of resolution. |
| 9 * | 9 * |
| 10 * Do not subclass or instantiate this class outside this library | 10 * Do not subclass or instantiate this class outside this library |
| (...skipping 1951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1962 warning(node, MessageKind.ABSTRACT_CLASS_INSTANTIATION); | 1962 warning(node, MessageKind.ABSTRACT_CLASS_INSTANTIATION); |
| 1963 registry.registerAbstractClassInstantiation(); | 1963 registry.registerAbstractClassInstantiation(); |
| 1964 } | 1964 } |
| 1965 | 1965 |
| 1966 if (isSymbolConstructor) { | 1966 if (isSymbolConstructor) { |
| 1967 if (node.isConst) { | 1967 if (node.isConst) { |
| 1968 Node argumentNode = node.send.arguments.head; | 1968 Node argumentNode = node.send.arguments.head; |
| 1969 ConstantExpression constant = | 1969 ConstantExpression constant = |
| 1970 compiler.resolver.constantCompiler.compileNode( | 1970 compiler.resolver.constantCompiler.compileNode( |
| 1971 argumentNode, registry.mapping); | 1971 argumentNode, registry.mapping); |
| 1972 ConstantValue name = constant.value; | 1972 ConstantValue name = compiler.constants.getConstantValue(constant); |
| 1973 if (!name.isString) { | 1973 if (!name.isString) { |
| 1974 DartType type = name.getType(compiler.coreTypes); | 1974 DartType type = name.getType(compiler.coreTypes); |
| 1975 compiler.reportError(argumentNode, MessageKind.STRING_EXPECTED, | 1975 compiler.reportError(argumentNode, MessageKind.STRING_EXPECTED, |
| 1976 {'type': type}); | 1976 {'type': type}); |
| 1977 } else { | 1977 } else { |
| 1978 StringConstantValue stringConstant = name; | 1978 StringConstantValue stringConstant = name; |
| 1979 String nameString = stringConstant.toDartString().slowToString(); | 1979 String nameString = stringConstant.toDartString().slowToString(); |
| 1980 if (validateSymbol(argumentNode, nameString)) { | 1980 if (validateSymbol(argumentNode, nameString)) { |
| 1981 registry.registerConstSymbol(nameString); | 1981 registry.registerConstSymbol(nameString); |
| 1982 } | 1982 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2020 void analyzeConstant(Node node, {enforceConst: true}) { | 2020 void analyzeConstant(Node node, {enforceConst: true}) { |
| 2021 ConstantExpression constant = | 2021 ConstantExpression constant = |
| 2022 compiler.resolver.constantCompiler.compileNode( | 2022 compiler.resolver.constantCompiler.compileNode( |
| 2023 node, registry.mapping, enforceConst: enforceConst); | 2023 node, registry.mapping, enforceConst: enforceConst); |
| 2024 | 2024 |
| 2025 if (constant == null) { | 2025 if (constant == null) { |
| 2026 assert(invariant(node, compiler.compilationFailed)); | 2026 assert(invariant(node, compiler.compilationFailed)); |
| 2027 return; | 2027 return; |
| 2028 } | 2028 } |
| 2029 | 2029 |
| 2030 ConstantValue value = constant.value; | 2030 ConstantValue value = compiler.constants.getConstantValue(constant); |
| 2031 if (value.isMap) { | 2031 if (value.isMap) { |
| 2032 checkConstMapKeysDontOverrideEquals(node, value); | 2032 checkConstMapKeysDontOverrideEquals(node, value); |
| 2033 } | 2033 } |
| 2034 | 2034 |
| 2035 // The type constant that is an argument to JS_INTERCEPTOR_CONSTANT names | 2035 // The type constant that is an argument to JS_INTERCEPTOR_CONSTANT names |
| 2036 // a class that will be instantiated outside the program by attaching a | 2036 // a class that will be instantiated outside the program by attaching a |
| 2037 // native class dispatch record referencing the interceptor. | 2037 // native class dispatch record referencing the interceptor. |
| 2038 if (argumentsToJsInterceptorConstant != null && | 2038 if (argumentsToJsInterceptorConstant != null && |
| 2039 argumentsToJsInterceptorConstant.contains(node)) { | 2039 argumentsToJsInterceptorConstant.contains(node)) { |
| 2040 if (value.isType) { | 2040 if (value.isType) { |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2425 for (Node labelOrCase in switchCase.labelsAndCases) { | 2425 for (Node labelOrCase in switchCase.labelsAndCases) { |
| 2426 CaseMatch caseMatch = labelOrCase.asCaseMatch(); | 2426 CaseMatch caseMatch = labelOrCase.asCaseMatch(); |
| 2427 if (caseMatch == null) continue; | 2427 if (caseMatch == null) continue; |
| 2428 | 2428 |
| 2429 // Analyze the constant. | 2429 // Analyze the constant. |
| 2430 ConstantExpression constant = | 2430 ConstantExpression constant = |
| 2431 registry.getConstant(caseMatch.expression); | 2431 registry.getConstant(caseMatch.expression); |
| 2432 assert(invariant(node, constant != null, | 2432 assert(invariant(node, constant != null, |
| 2433 message: 'No constant computed for $node')); | 2433 message: 'No constant computed for $node')); |
| 2434 | 2434 |
| 2435 DartType caseType = typeOfConstant(constant.value); | 2435 ConstantValue value = compiler.constants.getConstantValue(constant); |
| 2436 DartType caseType = typeOfConstant(value); |
| 2436 | 2437 |
| 2437 if (firstCaseType == null) { | 2438 if (firstCaseType == null) { |
| 2438 firstCase = caseMatch; | 2439 firstCase = caseMatch; |
| 2439 firstCaseType = caseType; | 2440 firstCaseType = caseType; |
| 2440 | 2441 |
| 2441 // We only report the bad type on the first class element. All others | 2442 // We only report the bad type on the first class element. All others |
| 2442 // get a "type differs" error. | 2443 // get a "type differs" error. |
| 2443 if (caseType.element == compiler.doubleClass) { | 2444 if (caseType.element == compiler.doubleClass) { |
| 2444 compiler.reportError(node, | 2445 compiler.reportError(node, |
| 2445 MessageKind.SWITCH_CASE_VALUE_OVERRIDES_EQUALS, | 2446 MessageKind.SWITCH_CASE_VALUE_OVERRIDES_EQUALS, |
| 2446 {'type': "double"}); | 2447 {'type': "double"}); |
| 2447 } else if (caseType.element == compiler.functionClass) { | 2448 } else if (caseType.element == compiler.functionClass) { |
| 2448 compiler.reportError(node, MessageKind.SWITCH_CASE_FORBIDDEN, | 2449 compiler.reportError(node, MessageKind.SWITCH_CASE_FORBIDDEN, |
| 2449 {'type': "Function"}); | 2450 {'type': "Function"}); |
| 2450 } else if (constant.value.isObject && overridesEquals(caseType)) { | 2451 } else if (value.isObject && overridesEquals(caseType)) { |
| 2451 compiler.reportError(firstCase.expression, | 2452 compiler.reportError(firstCase.expression, |
| 2452 MessageKind.SWITCH_CASE_VALUE_OVERRIDES_EQUALS, | 2453 MessageKind.SWITCH_CASE_VALUE_OVERRIDES_EQUALS, |
| 2453 {'type': caseType}); | 2454 {'type': caseType}); |
| 2454 } | 2455 } |
| 2455 } else { | 2456 } else { |
| 2456 if (caseType != firstCaseType) { | 2457 if (caseType != firstCaseType) { |
| 2457 if (!hasReportedProblem) { | 2458 if (!hasReportedProblem) { |
| 2458 compiler.reportError( | 2459 compiler.reportError( |
| 2459 node, | 2460 node, |
| 2460 MessageKind.SWITCH_CASE_TYPES_NOT_EQUAL, | 2461 MessageKind.SWITCH_CASE_TYPES_NOT_EQUAL, |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2641 visitTypedef(Typedef node) { | 2642 visitTypedef(Typedef node) { |
| 2642 internalError(node, 'typedef'); | 2643 internalError(node, 'typedef'); |
| 2643 } | 2644 } |
| 2644 } | 2645 } |
| 2645 | 2646 |
| 2646 /// Looks up [name] in [scope] and unwraps the result. | 2647 /// Looks up [name] in [scope] and unwraps the result. |
| 2647 Element lookupInScope(Compiler compiler, Node node, | 2648 Element lookupInScope(Compiler compiler, Node node, |
| 2648 Scope scope, String name) { | 2649 Scope scope, String name) { |
| 2649 return Elements.unwrap(scope.lookup(name), compiler, node); | 2650 return Elements.unwrap(scope.lookup(name), compiler, node); |
| 2650 } | 2651 } |
| OLD | NEW |