| 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.resolution.members; | 5 library dart2js.resolution.members; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/names.dart' show Selectors; | 8 import '../common/names.dart' show Selectors; |
| 9 import '../common/resolution.dart' show Resolution; | 9 import '../common/resolution.dart' show Resolution; |
| 10 import '../compile_time_constants.dart'; | 10 import '../compile_time_constants.dart'; |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 } | 331 } |
| 332 return const NoneResult(); | 332 return const NoneResult(); |
| 333 } else { | 333 } else { |
| 334 String name = node.source; | 334 String name = node.source; |
| 335 Element element = lookupInScope(reporter, node, scope, name); | 335 Element element = lookupInScope(reporter, node, scope, name); |
| 336 if (Elements.isUnresolved(element) && name == 'dynamic') { | 336 if (Elements.isUnresolved(element) && name == 'dynamic') { |
| 337 // TODO(johnniwinther): Remove this hack when we can return more complex | 337 // TODO(johnniwinther): Remove this hack when we can return more complex |
| 338 // objects than [Element] from this method. | 338 // objects than [Element] from this method. |
| 339 element = commonElements.typeClass; | 339 element = commonElements.typeClass; |
| 340 // Set the type to be `dynamic` to mark that this is a type literal. | 340 // Set the type to be `dynamic` to mark that this is a type literal. |
| 341 registry.setType(node, const DynamicType()); | 341 registry.setType(node, const ResolutionDynamicType()); |
| 342 } | 342 } |
| 343 element = reportLookupErrorIfAny(element, node, name); | 343 element = reportLookupErrorIfAny(element, node, name); |
| 344 if (element == null) { | 344 if (element == null) { |
| 345 if (!inInstanceContext) { | 345 if (!inInstanceContext) { |
| 346 element = reportCannotResolve(node, name); | 346 element = reportCannotResolve(node, name); |
| 347 } | 347 } |
| 348 } else if (element.isMalformed) { | 348 } else if (element.isMalformed) { |
| 349 // Use the malformed element. | 349 // Use the malformed element. |
| 350 } else { | 350 } else { |
| 351 if ((element.kind.category & allowedCategory) == 0) { | 351 if ((element.kind.category & allowedCategory) == 0) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 void setupFunction(FunctionExpression node, FunctionElement function) { | 406 void setupFunction(FunctionExpression node, FunctionElement function) { |
| 407 Element enclosingElement = function.enclosingElement; | 407 Element enclosingElement = function.enclosingElement; |
| 408 if (node.modifiers.isStatic && enclosingElement.kind != ElementKind.CLASS) { | 408 if (node.modifiers.isStatic && enclosingElement.kind != ElementKind.CLASS) { |
| 409 reporter.reportErrorMessage(node, MessageKind.ILLEGAL_STATIC); | 409 reporter.reportErrorMessage(node, MessageKind.ILLEGAL_STATIC); |
| 410 } | 410 } |
| 411 FunctionSignature functionSignature = function.functionSignature; | 411 FunctionSignature functionSignature = function.functionSignature; |
| 412 | 412 |
| 413 // Create the scope where the type variables are introduced, if any. | 413 // Create the scope where the type variables are introduced, if any. |
| 414 scope = new MethodScope(scope, function); | 414 scope = new MethodScope(scope, function); |
| 415 functionSignature.typeVariables | 415 functionSignature.typeVariables |
| 416 .forEach((DartType type) => addToScope(type.element)); | 416 .forEach((ResolutionDartType type) => addToScope(type.element)); |
| 417 | 417 |
| 418 // Create the scope for the function body, and put the parameters in scope. | 418 // Create the scope for the function body, and put the parameters in scope. |
| 419 scope = new BlockScope(scope); | 419 scope = new BlockScope(scope); |
| 420 Link<Node> parameterNodes = | 420 Link<Node> parameterNodes = |
| 421 (node.parameters == null) ? const Link<Node>() : node.parameters.nodes; | 421 (node.parameters == null) ? const Link<Node>() : node.parameters.nodes; |
| 422 functionSignature.forEachParameter((ParameterElementX element) { | 422 functionSignature.forEachParameter((ParameterElementX element) { |
| 423 // TODO(karlklose): should be a list of [FormalElement]s, but the actual | 423 // TODO(karlklose): should be a list of [FormalElement]s, but the actual |
| 424 // implementation uses [Element]. | 424 // implementation uses [Element]. |
| 425 List<Element> optionals = functionSignature.optionalParameters; | 425 List<Element> optionals = functionSignature.optionalParameters; |
| 426 if (!optionals.isEmpty && element == optionals.first) { | 426 if (!optionals.isEmpty && element == optionals.first) { |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 | 1094 |
| 1095 /// Handle a type test expression, like `a is T` and `a is! T`. | 1095 /// Handle a type test expression, like `a is T` and `a is! T`. |
| 1096 ResolutionResult handleIs(Send node) { | 1096 ResolutionResult handleIs(Send node) { |
| 1097 Node expression = node.receiver; | 1097 Node expression = node.receiver; |
| 1098 visitExpression(expression); | 1098 visitExpression(expression); |
| 1099 | 1099 |
| 1100 // TODO(johnniwinther): Use seen type tests to avoid registration of | 1100 // TODO(johnniwinther): Use seen type tests to avoid registration of |
| 1101 // mutation/access to unpromoted variables. | 1101 // mutation/access to unpromoted variables. |
| 1102 | 1102 |
| 1103 Send notTypeNode = node.arguments.head.asSend(); | 1103 Send notTypeNode = node.arguments.head.asSend(); |
| 1104 DartType type; | 1104 ResolutionDartType type; |
| 1105 SendStructure sendStructure; | 1105 SendStructure sendStructure; |
| 1106 if (notTypeNode != null) { | 1106 if (notTypeNode != null) { |
| 1107 // `e is! T`. | 1107 // `e is! T`. |
| 1108 Node typeNode = notTypeNode.receiver; | 1108 Node typeNode = notTypeNode.receiver; |
| 1109 type = resolveTypeAnnotation(typeNode, registerCheckedModeCheck: false); | 1109 type = resolveTypeAnnotation(typeNode, registerCheckedModeCheck: false); |
| 1110 sendStructure = new IsNotStructure(type); | 1110 sendStructure = new IsNotStructure(type); |
| 1111 } else { | 1111 } else { |
| 1112 // `e is T`. | 1112 // `e is T`. |
| 1113 Node typeNode = node.arguments.head; | 1113 Node typeNode = node.arguments.head; |
| 1114 type = resolveTypeAnnotation(typeNode, registerCheckedModeCheck: false); | 1114 type = resolveTypeAnnotation(typeNode, registerCheckedModeCheck: false); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1126 registry.registerSendStructure(node, sendStructure); | 1126 registry.registerSendStructure(node, sendStructure); |
| 1127 return const NoneResult(); | 1127 return const NoneResult(); |
| 1128 } | 1128 } |
| 1129 | 1129 |
| 1130 /// Handle a type cast expression, like `a as T`. | 1130 /// Handle a type cast expression, like `a as T`. |
| 1131 ResolutionResult handleAs(Send node) { | 1131 ResolutionResult handleAs(Send node) { |
| 1132 Node expression = node.receiver; | 1132 Node expression = node.receiver; |
| 1133 visitExpression(expression); | 1133 visitExpression(expression); |
| 1134 | 1134 |
| 1135 Node typeNode = node.arguments.head; | 1135 Node typeNode = node.arguments.head; |
| 1136 DartType type = | 1136 ResolutionDartType type = |
| 1137 resolveTypeAnnotation(typeNode, registerCheckedModeCheck: false); | 1137 resolveTypeAnnotation(typeNode, registerCheckedModeCheck: false); |
| 1138 | 1138 |
| 1139 // GENERIC_METHODS: Method type variables are not reified, so we must inform | 1139 // GENERIC_METHODS: Method type variables are not reified, so we must inform |
| 1140 // the developer about the potentially bug-inducing semantics. | 1140 // the developer about the potentially bug-inducing semantics. |
| 1141 if (type is MethodTypeVariableType) { | 1141 if (type is MethodTypeVariableType) { |
| 1142 reporter.reportHintMessage( | 1142 reporter.reportHintMessage( |
| 1143 node, MessageKind.TYPE_VARIABLE_FROM_METHOD_CONSIDERED_DYNAMIC); | 1143 node, MessageKind.TYPE_VARIABLE_FROM_METHOD_CONSIDERED_DYNAMIC); |
| 1144 } | 1144 } |
| 1145 | 1145 |
| 1146 registry.registerTypeUse(new TypeUse.asCast(type)); | 1146 registry.registerTypeUse(new TypeUse.asCast(type)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 registry.useElement(node, semantics.element); | 1188 registry.useElement(node, semantics.element); |
| 1189 } | 1189 } |
| 1190 } else { | 1190 } else { |
| 1191 ResolutionResult expressionResult = visitExpression(expression); | 1191 ResolutionResult expressionResult = visitExpression(expression); |
| 1192 semantics = const DynamicAccess.expression(); | 1192 semantics = const DynamicAccess.expression(); |
| 1193 registry.registerDynamicUse(new DynamicUse(selector, null)); | 1193 registry.registerDynamicUse(new DynamicUse(selector, null)); |
| 1194 | 1194 |
| 1195 if (expressionResult.isConstant) { | 1195 if (expressionResult.isConstant) { |
| 1196 bool isValidConstant; | 1196 bool isValidConstant; |
| 1197 ConstantExpression expressionConstant = expressionResult.constant; | 1197 ConstantExpression expressionConstant = expressionResult.constant; |
| 1198 DartType knownExpressionType = | 1198 ResolutionDartType knownExpressionType = |
| 1199 expressionConstant.getKnownType(commonElements); | 1199 expressionConstant.getKnownType(commonElements); |
| 1200 switch (operator.kind) { | 1200 switch (operator.kind) { |
| 1201 case UnaryOperatorKind.COMPLEMENT: | 1201 case UnaryOperatorKind.COMPLEMENT: |
| 1202 isValidConstant = knownExpressionType == commonElements.intType; | 1202 isValidConstant = knownExpressionType == commonElements.intType; |
| 1203 break; | 1203 break; |
| 1204 case UnaryOperatorKind.NEGATE: | 1204 case UnaryOperatorKind.NEGATE: |
| 1205 isValidConstant = knownExpressionType == commonElements.intType || | 1205 isValidConstant = knownExpressionType == commonElements.intType || |
| 1206 knownExpressionType == commonElements.doubleType; | 1206 knownExpressionType == commonElements.doubleType; |
| 1207 break; | 1207 break; |
| 1208 case UnaryOperatorKind.NOT: | 1208 case UnaryOperatorKind.NOT: |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1365 } else { | 1365 } else { |
| 1366 ResolutionResult leftResult = visitExpression(left); | 1366 ResolutionResult leftResult = visitExpression(left); |
| 1367 ResolutionResult rightResult = visitExpression(right); | 1367 ResolutionResult rightResult = visitExpression(right); |
| 1368 registry.registerDynamicUse(new DynamicUse(selector, null)); | 1368 registry.registerDynamicUse(new DynamicUse(selector, null)); |
| 1369 semantics = const DynamicAccess.expression(); | 1369 semantics = const DynamicAccess.expression(); |
| 1370 | 1370 |
| 1371 if (leftResult.isConstant && rightResult.isConstant) { | 1371 if (leftResult.isConstant && rightResult.isConstant) { |
| 1372 bool isValidConstant; | 1372 bool isValidConstant; |
| 1373 ConstantExpression leftConstant = leftResult.constant; | 1373 ConstantExpression leftConstant = leftResult.constant; |
| 1374 ConstantExpression rightConstant = rightResult.constant; | 1374 ConstantExpression rightConstant = rightResult.constant; |
| 1375 DartType knownLeftType = leftConstant.getKnownType(commonElements); | 1375 ResolutionDartType knownLeftType = |
| 1376 DartType knownRightType = rightConstant.getKnownType(commonElements); | 1376 leftConstant.getKnownType(commonElements); |
| 1377 ResolutionDartType knownRightType = |
| 1378 rightConstant.getKnownType(commonElements); |
| 1377 switch (operator.kind) { | 1379 switch (operator.kind) { |
| 1378 case BinaryOperatorKind.EQ: | 1380 case BinaryOperatorKind.EQ: |
| 1379 case BinaryOperatorKind.NOT_EQ: | 1381 case BinaryOperatorKind.NOT_EQ: |
| 1380 isValidConstant = (knownLeftType == commonElements.intType || | 1382 isValidConstant = (knownLeftType == commonElements.intType || |
| 1381 knownLeftType == commonElements.doubleType || | 1383 knownLeftType == commonElements.doubleType || |
| 1382 knownLeftType == commonElements.stringType || | 1384 knownLeftType == commonElements.stringType || |
| 1383 knownLeftType == commonElements.boolType || | 1385 knownLeftType == commonElements.boolType || |
| 1384 knownLeftType == commonElements.nullType) && | 1386 knownLeftType == commonElements.nullType) && |
| 1385 (knownRightType == commonElements.intType || | 1387 (knownRightType == commonElements.intType || |
| 1386 knownRightType == commonElements.doubleType || | 1388 knownRightType == commonElements.doubleType || |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1971 semantics = new StaticAccess.typeParameterTypeLiteral(element); | 1973 semantics = new StaticAccess.typeParameterTypeLiteral(element); |
| 1972 } | 1974 } |
| 1973 return handleUpdate(node, name, semantics); | 1975 return handleUpdate(node, name, semantics); |
| 1974 } | 1976 } |
| 1975 | 1977 |
| 1976 /// Handle access to a constant type literal of [type]. | 1978 /// Handle access to a constant type literal of [type]. |
| 1977 // TODO(johnniwinther): Remove [name] when [Selector] is not required for the | 1979 // TODO(johnniwinther): Remove [name] when [Selector] is not required for the |
| 1978 // the [GetStructure]. | 1980 // the [GetStructure]. |
| 1979 // TODO(johnniwinther): Remove [element] when it is no longer needed for | 1981 // TODO(johnniwinther): Remove [element] when it is no longer needed for |
| 1980 // evaluating constants. | 1982 // evaluating constants. |
| 1981 ResolutionResult handleConstantTypeLiteralAccess(Send node, Name name, | 1983 ResolutionResult handleConstantTypeLiteralAccess( |
| 1982 TypeDeclarationElement element, DartType type, ConstantAccess semantics) { | 1984 Send node, |
| 1985 Name name, |
| 1986 TypeDeclarationElement element, |
| 1987 ResolutionDartType type, |
| 1988 ConstantAccess semantics) { |
| 1983 registry.useElement(node, element); | 1989 registry.useElement(node, element); |
| 1984 registry.registerTypeLiteral(node, type); | 1990 registry.registerTypeLiteral(node, type); |
| 1985 | 1991 |
| 1986 if (node.isCall) { | 1992 if (node.isCall) { |
| 1987 CallStructure callStructure = | 1993 CallStructure callStructure = |
| 1988 resolveArguments(node.argumentsNode).callStructure; | 1994 resolveArguments(node.argumentsNode).callStructure; |
| 1989 Selector selector = callStructure.callSelector; | 1995 Selector selector = callStructure.callSelector; |
| 1990 // TODO(23998): Remove this when all information goes through | 1996 // TODO(23998): Remove this when all information goes through |
| 1991 // the [SendStructure]. | 1997 // the [SendStructure]. |
| 1992 registry.setSelector(node, selector); | 1998 registry.setSelector(node, selector); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2006 registry.registerSendStructure(node, new GetStructure(semantics)); | 2012 registry.registerSendStructure(node, new GetStructure(semantics)); |
| 2007 return new ConstantResult(node, semantics.constant); | 2013 return new ConstantResult(node, semantics.constant); |
| 2008 } | 2014 } |
| 2009 } | 2015 } |
| 2010 | 2016 |
| 2011 /// Handle access to a constant type literal of [type]. | 2017 /// Handle access to a constant type literal of [type]. |
| 2012 // TODO(johnniwinther): Remove [name] when [Selector] is not required for the | 2018 // TODO(johnniwinther): Remove [name] when [Selector] is not required for the |
| 2013 // the [GetStructure]. | 2019 // the [GetStructure]. |
| 2014 // TODO(johnniwinther): Remove [element] when it is no longer needed for | 2020 // TODO(johnniwinther): Remove [element] when it is no longer needed for |
| 2015 // evaluating constants. | 2021 // evaluating constants. |
| 2016 ResolutionResult handleConstantTypeLiteralUpdate(SendSet node, Name name, | 2022 ResolutionResult handleConstantTypeLiteralUpdate( |
| 2017 TypeDeclarationElement element, DartType type, ConstantAccess semantics) { | 2023 SendSet node, |
| 2024 Name name, |
| 2025 TypeDeclarationElement element, |
| 2026 ResolutionDartType type, |
| 2027 ConstantAccess semantics) { |
| 2018 // TODO(johnniwinther): Remove this when all constants are evaluated. | 2028 // TODO(johnniwinther): Remove this when all constants are evaluated. |
| 2019 resolver.constantCompiler.evaluate(semantics.constant); | 2029 resolver.constantCompiler.evaluate(semantics.constant); |
| 2020 | 2030 |
| 2021 ErroneousElement error; | 2031 ErroneousElement error; |
| 2022 if (node.isIfNullAssignment) { | 2032 if (node.isIfNullAssignment) { |
| 2023 error = reportAndCreateErroneousElement(node.selector, name.text, | 2033 error = reportAndCreateErroneousElement(node.selector, name.text, |
| 2024 MessageKind.IF_NULL_ASSIGNING_TYPE, const {}); | 2034 MessageKind.IF_NULL_ASSIGNING_TYPE, const {}); |
| 2025 // TODO(23998): Remove these when all information goes through | 2035 // TODO(23998): Remove these when all information goes through |
| 2026 // the [SendStructure]. | 2036 // the [SendStructure]. |
| 2027 registry.setConstant(node.selector, semantics.constant); | 2037 registry.setConstant(node.selector, semantics.constant); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2038 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); | 2048 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); |
| 2039 | 2049 |
| 2040 return handleUpdate(node, name, semantics); | 2050 return handleUpdate(node, name, semantics); |
| 2041 } | 2051 } |
| 2042 | 2052 |
| 2043 /// Handle access to a type literal of a typedef. Like `F` or | 2053 /// Handle access to a type literal of a typedef. Like `F` or |
| 2044 /// `F()` where 'F' is typedef. | 2054 /// `F()` where 'F' is typedef. |
| 2045 ResolutionResult handleTypedefTypeLiteralAccess( | 2055 ResolutionResult handleTypedefTypeLiteralAccess( |
| 2046 Send node, Name name, TypedefElement typdef) { | 2056 Send node, Name name, TypedefElement typdef) { |
| 2047 typdef.ensureResolved(resolution); | 2057 typdef.ensureResolved(resolution); |
| 2048 DartType type = typdef.rawType; | 2058 ResolutionDartType type = typdef.rawType; |
| 2049 ConstantExpression constant = new TypeConstantExpression(type); | 2059 ConstantExpression constant = new TypeConstantExpression(type); |
| 2050 AccessSemantics semantics = new ConstantAccess.typedefTypeLiteral(constant); | 2060 AccessSemantics semantics = new ConstantAccess.typedefTypeLiteral(constant); |
| 2051 return handleConstantTypeLiteralAccess(node, name, typdef, type, semantics); | 2061 return handleConstantTypeLiteralAccess(node, name, typdef, type, semantics); |
| 2052 } | 2062 } |
| 2053 | 2063 |
| 2054 /// Handle access to a type literal of a typedef. Like `F = b`, `F++` or | 2064 /// Handle access to a type literal of a typedef. Like `F = b`, `F++` or |
| 2055 /// `F += b` where 'F' is typedef. | 2065 /// `F += b` where 'F' is typedef. |
| 2056 ResolutionResult handleTypedefTypeLiteralUpdate( | 2066 ResolutionResult handleTypedefTypeLiteralUpdate( |
| 2057 SendSet node, Name name, TypedefElement typdef) { | 2067 SendSet node, Name name, TypedefElement typdef) { |
| 2058 typdef.ensureResolved(resolution); | 2068 typdef.ensureResolved(resolution); |
| 2059 DartType type = typdef.rawType; | 2069 ResolutionDartType type = typdef.rawType; |
| 2060 ConstantExpression constant = new TypeConstantExpression(type); | 2070 ConstantExpression constant = new TypeConstantExpression(type); |
| 2061 AccessSemantics semantics = new ConstantAccess.typedefTypeLiteral(constant); | 2071 AccessSemantics semantics = new ConstantAccess.typedefTypeLiteral(constant); |
| 2062 return handleConstantTypeLiteralUpdate(node, name, typdef, type, semantics); | 2072 return handleConstantTypeLiteralUpdate(node, name, typdef, type, semantics); |
| 2063 } | 2073 } |
| 2064 | 2074 |
| 2065 /// Handle access to a type literal of the type 'dynamic'. Like `dynamic` or | 2075 /// Handle access to a type literal of the type 'dynamic'. Like `dynamic` or |
| 2066 /// `dynamic()`. | 2076 /// `dynamic()`. |
| 2067 ResolutionResult handleDynamicTypeLiteralAccess(Send node) { | 2077 ResolutionResult handleDynamicTypeLiteralAccess(Send node) { |
| 2068 DartType type = const DynamicType(); | 2078 ResolutionDartType type = const ResolutionDynamicType(); |
| 2069 ConstantExpression constant = new TypeConstantExpression( | 2079 ConstantExpression constant = new TypeConstantExpression( |
| 2070 // TODO(johnniwinther): Use [type] when evaluation of constants is done | 2080 // TODO(johnniwinther): Use [type] when evaluation of constants is done |
| 2071 // directly on the constant expressions. | 2081 // directly on the constant expressions. |
| 2072 node.isCall ? commonElements.typeType : type); | 2082 node.isCall ? commonElements.typeType : type); |
| 2073 AccessSemantics semantics = new ConstantAccess.dynamicTypeLiteral(constant); | 2083 AccessSemantics semantics = new ConstantAccess.dynamicTypeLiteral(constant); |
| 2074 return handleConstantTypeLiteralAccess(node, const PublicName('dynamic'), | 2084 return handleConstantTypeLiteralAccess(node, const PublicName('dynamic'), |
| 2075 commonElements.typeClass, type, semantics); | 2085 commonElements.typeClass, type, semantics); |
| 2076 } | 2086 } |
| 2077 | 2087 |
| 2078 /// Handle update to a type literal of the type 'dynamic'. Like `dynamic++` or | 2088 /// Handle update to a type literal of the type 'dynamic'. Like `dynamic++` or |
| 2079 /// `dynamic = 0`. | 2089 /// `dynamic = 0`. |
| 2080 ResolutionResult handleDynamicTypeLiteralUpdate(SendSet node) { | 2090 ResolutionResult handleDynamicTypeLiteralUpdate(SendSet node) { |
| 2081 DartType type = const DynamicType(); | 2091 ResolutionDartType type = const ResolutionDynamicType(); |
| 2082 ConstantExpression constant = | 2092 ConstantExpression constant = |
| 2083 new TypeConstantExpression(const DynamicType()); | 2093 new TypeConstantExpression(const ResolutionDynamicType()); |
| 2084 AccessSemantics semantics = new ConstantAccess.dynamicTypeLiteral(constant); | 2094 AccessSemantics semantics = new ConstantAccess.dynamicTypeLiteral(constant); |
| 2085 return handleConstantTypeLiteralUpdate(node, const PublicName('dynamic'), | 2095 return handleConstantTypeLiteralUpdate(node, const PublicName('dynamic'), |
| 2086 commonElements.typeClass, type, semantics); | 2096 commonElements.typeClass, type, semantics); |
| 2087 } | 2097 } |
| 2088 | 2098 |
| 2089 /// Handle access to a type literal of a class. Like `C` or | 2099 /// Handle access to a type literal of a class. Like `C` or |
| 2090 /// `C()` where 'C' is class. | 2100 /// `C()` where 'C' is class. |
| 2091 ResolutionResult handleClassTypeLiteralAccess( | 2101 ResolutionResult handleClassTypeLiteralAccess( |
| 2092 Send node, Name name, ClassElement cls) { | 2102 Send node, Name name, ClassElement cls) { |
| 2093 cls.ensureResolved(resolution); | 2103 cls.ensureResolved(resolution); |
| 2094 DartType type = cls.rawType; | 2104 ResolutionDartType type = cls.rawType; |
| 2095 ConstantExpression constant = new TypeConstantExpression(type); | 2105 ConstantExpression constant = new TypeConstantExpression(type); |
| 2096 AccessSemantics semantics = new ConstantAccess.classTypeLiteral(constant); | 2106 AccessSemantics semantics = new ConstantAccess.classTypeLiteral(constant); |
| 2097 return handleConstantTypeLiteralAccess(node, name, cls, type, semantics); | 2107 return handleConstantTypeLiteralAccess(node, name, cls, type, semantics); |
| 2098 } | 2108 } |
| 2099 | 2109 |
| 2100 /// Handle access to a type literal of a class. Like `C = b`, `C++` or | 2110 /// Handle access to a type literal of a class. Like `C = b`, `C++` or |
| 2101 /// `C += b` where 'C' is class. | 2111 /// `C += b` where 'C' is class. |
| 2102 ResolutionResult handleClassTypeLiteralUpdate( | 2112 ResolutionResult handleClassTypeLiteralUpdate( |
| 2103 SendSet node, Name name, ClassElement cls) { | 2113 SendSet node, Name name, ClassElement cls) { |
| 2104 cls.ensureResolved(resolution); | 2114 cls.ensureResolved(resolution); |
| 2105 DartType type = cls.rawType; | 2115 ResolutionDartType type = cls.rawType; |
| 2106 ConstantExpression constant = new TypeConstantExpression(type); | 2116 ConstantExpression constant = new TypeConstantExpression(type); |
| 2107 AccessSemantics semantics = new ConstantAccess.classTypeLiteral(constant); | 2117 AccessSemantics semantics = new ConstantAccess.classTypeLiteral(constant); |
| 2108 return handleConstantTypeLiteralUpdate(node, name, cls, type, semantics); | 2118 return handleConstantTypeLiteralUpdate(node, name, cls, type, semantics); |
| 2109 } | 2119 } |
| 2110 | 2120 |
| 2111 /// Handle a [Send] that resolves to a [prefix]. Like `prefix` in | 2121 /// Handle a [Send] that resolves to a [prefix]. Like `prefix` in |
| 2112 /// `prefix.Class` or `prefix` in `prefix()`, the latter being a compile time | 2122 /// `prefix.Class` or `prefix` in `prefix()`, the latter being a compile time |
| 2113 /// error. | 2123 /// error. |
| 2114 ResolutionResult handleClassSend(Send node, Name name, ClassElement cls) { | 2124 ResolutionResult handleClassSend(Send node, Name name, ClassElement cls) { |
| 2115 cls.ensureResolved(resolution); | 2125 cls.ensureResolved(resolution); |
| (...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3035 | 3045 |
| 3036 // TODO(johnniwinther): Move this to the backend resolution callbacks. | 3046 // TODO(johnniwinther): Move this to the backend resolution callbacks. |
| 3037 void handleForeignCall( | 3047 void handleForeignCall( |
| 3038 Send node, Element target, CallStructure callStructure) { | 3048 Send node, Element target, CallStructure callStructure) { |
| 3039 if (target != null && resolution.target.isForeign(target)) { | 3049 if (target != null && resolution.target.isForeign(target)) { |
| 3040 registry.registerForeignCall(node, target, callStructure, this); | 3050 registry.registerForeignCall(node, target, callStructure, this); |
| 3041 } | 3051 } |
| 3042 } | 3052 } |
| 3043 | 3053 |
| 3044 /// Callback for native enqueuer to parse a type. Returns [:null:] on error. | 3054 /// Callback for native enqueuer to parse a type. Returns [:null:] on error. |
| 3045 DartType resolveTypeFromString(Node node, String typeName) { | 3055 ResolutionDartType resolveTypeFromString(Node node, String typeName) { |
| 3046 Element element = lookupInScope(reporter, node, scope, typeName); | 3056 Element element = lookupInScope(reporter, node, scope, typeName); |
| 3047 if (element == null) return null; | 3057 if (element == null) return null; |
| 3048 if (element is! ClassElement) return null; | 3058 if (element is! ClassElement) return null; |
| 3049 ClassElement cls = element; | 3059 ClassElement cls = element; |
| 3050 cls.ensureResolved(resolution); | 3060 cls.ensureResolved(resolution); |
| 3051 cls.computeType(resolution); | 3061 cls.computeType(resolution); |
| 3052 return cls.rawType; | 3062 return cls.rawType; |
| 3053 } | 3063 } |
| 3054 | 3064 |
| 3055 /// Handle index operations like `a[b] = c`, `a[b] += c`, and `a[b]++`. | 3065 /// Handle index operations like `a[b] = c`, `a[b] += c`, and `a[b]++`. |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3652 node, MessageKind.CYCLIC_REDIRECTING_FACTORY); | 3662 node, MessageKind.CYCLIC_REDIRECTING_FACTORY); |
| 3653 // TODO(johnniwinther): Create constant constructor for this case and | 3663 // TODO(johnniwinther): Create constant constructor for this case and |
| 3654 // let evaluation detect the cyclicity. | 3664 // let evaluation detect the cyclicity. |
| 3655 isValidAsConstant = false; | 3665 isValidAsConstant = false; |
| 3656 } | 3666 } |
| 3657 } | 3667 } |
| 3658 | 3668 |
| 3659 // Check that the target constructor is type compatible with the | 3669 // Check that the target constructor is type compatible with the |
| 3660 // redirecting constructor. | 3670 // redirecting constructor. |
| 3661 ClassElement targetClass = redirectionTarget.enclosingClass; | 3671 ClassElement targetClass = redirectionTarget.enclosingClass; |
| 3662 InterfaceType type = registry.getType(node); | 3672 ResolutionInterfaceType type = registry.getType(node); |
| 3663 FunctionType targetConstructorType = redirectionTarget | 3673 ResolutionFunctionType targetConstructorType = redirectionTarget |
| 3664 .computeType(resolution) | 3674 .computeType(resolution) |
| 3665 .subst(type.typeArguments, targetClass.typeVariables); | 3675 .subst(type.typeArguments, targetClass.typeVariables); |
| 3666 FunctionType constructorType = constructor.computeType(resolution); | 3676 ResolutionFunctionType constructorType = |
| 3677 constructor.computeType(resolution); |
| 3667 bool isSubtype = | 3678 bool isSubtype = |
| 3668 resolution.types.isSubtype(targetConstructorType, constructorType); | 3679 resolution.types.isSubtype(targetConstructorType, constructorType); |
| 3669 if (!isSubtype) { | 3680 if (!isSubtype) { |
| 3670 reporter.reportWarningMessage(node, MessageKind.NOT_ASSIGNABLE, | 3681 reporter.reportWarningMessage(node, MessageKind.NOT_ASSIGNABLE, |
| 3671 {'fromType': targetConstructorType, 'toType': constructorType}); | 3682 {'fromType': targetConstructorType, 'toType': constructorType}); |
| 3672 // TODO(johnniwinther): Handle this (potentially) erroneous case. | 3683 // TODO(johnniwinther): Handle this (potentially) erroneous case. |
| 3673 isValidAsConstant = false; | 3684 isValidAsConstant = false; |
| 3674 } | 3685 } |
| 3675 if (type.typeArguments.any((DartType type) => !type.isDynamic)) { | 3686 if (type.typeArguments.any((ResolutionDartType type) => !type.isDynamic)) { |
| 3676 registry.registerFeature(Feature.TYPE_VARIABLE_BOUNDS_CHECK); | 3687 registry.registerFeature(Feature.TYPE_VARIABLE_BOUNDS_CHECK); |
| 3677 } | 3688 } |
| 3678 | 3689 |
| 3679 redirectionTarget.computeType(resolution); | 3690 redirectionTarget.computeType(resolution); |
| 3680 FunctionSignature targetSignature = redirectionTarget.functionSignature; | 3691 FunctionSignature targetSignature = redirectionTarget.functionSignature; |
| 3681 constructor.computeType(resolution); | 3692 constructor.computeType(resolution); |
| 3682 FunctionSignature constructorSignature = constructor.functionSignature; | 3693 FunctionSignature constructorSignature = constructor.functionSignature; |
| 3683 if (!targetSignature.isCompatibleWith(constructorSignature)) { | 3694 if (!targetSignature.isCompatibleWith(constructorSignature)) { |
| 3684 assert(!isSubtype); | 3695 assert(!isSubtype); |
| 3685 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); | 3696 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3731 if (!currentAsyncMarker.isAsync) { | 3742 if (!currentAsyncMarker.isAsync) { |
| 3732 reporter.reportErrorMessage(node, MessageKind.INVALID_AWAIT); | 3743 reporter.reportErrorMessage(node, MessageKind.INVALID_AWAIT); |
| 3733 } | 3744 } |
| 3734 commonElements.futureClass.ensureResolved(resolution); | 3745 commonElements.futureClass.ensureResolved(resolution); |
| 3735 } | 3746 } |
| 3736 visit(node.expression); | 3747 visit(node.expression); |
| 3737 return const NoneResult(); | 3748 return const NoneResult(); |
| 3738 } | 3749 } |
| 3739 | 3750 |
| 3740 ResolutionResult visitVariableDefinitions(VariableDefinitions node) { | 3751 ResolutionResult visitVariableDefinitions(VariableDefinitions node) { |
| 3741 DartType type; | 3752 ResolutionDartType type; |
| 3742 if (node.type != null) { | 3753 if (node.type != null) { |
| 3743 type = resolveTypeAnnotation(node.type); | 3754 type = resolveTypeAnnotation(node.type); |
| 3744 } else { | 3755 } else { |
| 3745 type = const DynamicType(); | 3756 type = const ResolutionDynamicType(); |
| 3746 } | 3757 } |
| 3747 VariableList variables = new VariableList.node(node, type); | 3758 VariableList variables = new VariableList.node(node, type); |
| 3748 VariableDefinitionsVisitor visitor = | 3759 VariableDefinitionsVisitor visitor = |
| 3749 new VariableDefinitionsVisitor(resolution, node, this, variables); | 3760 new VariableDefinitionsVisitor(resolution, node, this, variables); |
| 3750 | 3761 |
| 3751 Modifiers modifiers = node.modifiers; | 3762 Modifiers modifiers = node.modifiers; |
| 3752 void reportExtraModifier(String modifier) { | 3763 void reportExtraModifier(String modifier) { |
| 3753 Node modifierNode; | 3764 Node modifierNode; |
| 3754 for (Link<Node> nodes = modifiers.nodes.nodes; | 3765 for (Link<Node> nodes = modifiers.nodes.nodes; |
| 3755 !nodes.isEmpty; | 3766 !nodes.isEmpty; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3816 argumentsResult = | 3827 argumentsResult = |
| 3817 inConstantContext(() => resolveArguments(node.send.argumentsNode)); | 3828 inConstantContext(() => resolveArguments(node.send.argumentsNode)); |
| 3818 } else { | 3829 } else { |
| 3819 argumentsResult = resolveArguments(node.send.argumentsNode); | 3830 argumentsResult = resolveArguments(node.send.argumentsNode); |
| 3820 } | 3831 } |
| 3821 // TODO(johnniwinther): Avoid the need for a [Selector]. | 3832 // TODO(johnniwinther): Avoid the need for a [Selector]. |
| 3822 Selector selector = resolveSelector(node.send, constructor); | 3833 Selector selector = resolveSelector(node.send, constructor); |
| 3823 CallStructure callStructure = selector.callStructure; | 3834 CallStructure callStructure = selector.callStructure; |
| 3824 registry.useElement(node.send, constructor); | 3835 registry.useElement(node.send, constructor); |
| 3825 | 3836 |
| 3826 DartType type = result.type; | 3837 ResolutionDartType type = result.type; |
| 3827 ConstructorAccessKind kind; | 3838 ConstructorAccessKind kind; |
| 3828 bool isInvalid = false; | 3839 bool isInvalid = false; |
| 3829 switch (result.kind) { | 3840 switch (result.kind) { |
| 3830 case ConstructorResultKind.GENERATIVE: | 3841 case ConstructorResultKind.GENERATIVE: |
| 3831 // Ensure that the signature of [constructor] has been computed. | 3842 // Ensure that the signature of [constructor] has been computed. |
| 3832 constructor.computeType(resolution); | 3843 constructor.computeType(resolution); |
| 3833 if (!callStructure.signatureApplies(constructor.functionSignature)) { | 3844 if (!callStructure.signatureApplies(constructor.functionSignature)) { |
| 3834 isInvalid = true; | 3845 isInvalid = true; |
| 3835 kind = ConstructorAccessKind.INCOMPATIBLE; | 3846 kind = ConstructorAccessKind.INCOMPATIBLE; |
| 3836 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); | 3847 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3889 if (!isInvalid) { | 3900 if (!isInvalid) { |
| 3890 // [constructor] might be the implementation element | 3901 // [constructor] might be the implementation element |
| 3891 // and only declaration elements may be registered. | 3902 // and only declaration elements may be registered. |
| 3892 // TODO(johniwinther): Avoid registration of `type` in face of redirecting | 3903 // TODO(johniwinther): Avoid registration of `type` in face of redirecting |
| 3893 // factory constructors. | 3904 // factory constructors. |
| 3894 registry.registerStaticUse(node.isConst | 3905 registry.registerStaticUse(node.isConst |
| 3895 ? new StaticUse.constConstructorInvoke( | 3906 ? new StaticUse.constConstructorInvoke( |
| 3896 constructor.declaration, callStructure, type) | 3907 constructor.declaration, callStructure, type) |
| 3897 : new StaticUse.typedConstructorInvoke( | 3908 : new StaticUse.typedConstructorInvoke( |
| 3898 constructor.declaration, callStructure, type)); | 3909 constructor.declaration, callStructure, type)); |
| 3899 InterfaceType interfaceType = type; | 3910 ResolutionInterfaceType interfaceType = type; |
| 3900 if (interfaceType.typeArguments.any((DartType type) => !type.isDynamic)) { | 3911 if (interfaceType.typeArguments |
| 3912 .any((ResolutionDartType type) => !type.isDynamic)) { |
| 3901 registry.registerFeature(Feature.TYPE_VARIABLE_BOUNDS_CHECK); | 3913 registry.registerFeature(Feature.TYPE_VARIABLE_BOUNDS_CHECK); |
| 3902 } | 3914 } |
| 3903 } | 3915 } |
| 3904 | 3916 |
| 3905 ResolutionResult resolutionResult = const NoneResult(); | 3917 ResolutionResult resolutionResult = const NoneResult(); |
| 3906 if (node.isConst) { | 3918 if (node.isConst) { |
| 3907 bool isValidAsConstant = !isInvalid && constructor.isConst; | 3919 bool isValidAsConstant = !isInvalid && constructor.isConst; |
| 3908 | 3920 |
| 3909 CommonElements commonElements = resolution.commonElements; | 3921 CommonElements commonElements = resolution.commonElements; |
| 3910 if (commonElements.isSymbolConstructor(constructor)) { | 3922 if (commonElements.isSymbolConstructor(constructor)) { |
| 3911 Node argumentNode = node.send.arguments.head; | 3923 Node argumentNode = node.send.arguments.head; |
| 3912 ConstantExpression constant = resolver.constantCompiler | 3924 ConstantExpression constant = resolver.constantCompiler |
| 3913 .compileNode(argumentNode, registry.mapping); | 3925 .compileNode(argumentNode, registry.mapping); |
| 3914 ConstantValue name = resolution.constants.getConstantValue(constant); | 3926 ConstantValue name = resolution.constants.getConstantValue(constant); |
| 3915 if (!name.isString) { | 3927 if (!name.isString) { |
| 3916 DartType type = name.getType(commonElements); | 3928 ResolutionDartType type = name.getType(commonElements); |
| 3917 reporter.reportErrorMessage( | 3929 reporter.reportErrorMessage( |
| 3918 argumentNode, MessageKind.STRING_EXPECTED, {'type': type}); | 3930 argumentNode, MessageKind.STRING_EXPECTED, {'type': type}); |
| 3919 } else { | 3931 } else { |
| 3920 StringConstantValue stringConstant = name; | 3932 StringConstantValue stringConstant = name; |
| 3921 String nameString = stringConstant.toDartString().slowToString(); | 3933 String nameString = stringConstant.toDartString().slowToString(); |
| 3922 if (validateSymbol(argumentNode, nameString)) { | 3934 if (validateSymbol(argumentNode, nameString)) { |
| 3923 registry.registerConstSymbol(nameString); | 3935 registry.registerConstSymbol(nameString); |
| 3924 } | 3936 } |
| 3925 } | 3937 } |
| 3926 } else if (commonElements.isMirrorsUsedConstructor(constructor)) { | 3938 } else if (commonElements.isMirrorsUsedConstructor(constructor)) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3997 } | 4009 } |
| 3998 | 4010 |
| 3999 return resolutionResult; | 4011 return resolutionResult; |
| 4000 } | 4012 } |
| 4001 | 4013 |
| 4002 void checkConstMapKeysDontOverrideEquals( | 4014 void checkConstMapKeysDontOverrideEquals( |
| 4003 Spannable spannable, MapConstantValue map) { | 4015 Spannable spannable, MapConstantValue map) { |
| 4004 for (ConstantValue key in map.keys) { | 4016 for (ConstantValue key in map.keys) { |
| 4005 if (!key.isObject) continue; | 4017 if (!key.isObject) continue; |
| 4006 ObjectConstantValue objectConstant = key; | 4018 ObjectConstantValue objectConstant = key; |
| 4007 DartType keyType = objectConstant.type; | 4019 ResolutionDartType keyType = objectConstant.type; |
| 4008 ClassElement cls = keyType.element; | 4020 ClassElement cls = keyType.element; |
| 4009 if (cls == commonElements.stringClass) continue; | 4021 if (cls == commonElements.stringClass) continue; |
| 4010 Element equals = cls.lookupMember('=='); | 4022 Element equals = cls.lookupMember('=='); |
| 4011 if (equals.enclosingClass != commonElements.objectClass) { | 4023 if (equals.enclosingClass != commonElements.objectClass) { |
| 4012 reporter.reportErrorMessage(spannable, | 4024 reporter.reportErrorMessage(spannable, |
| 4013 MessageKind.CONST_MAP_KEY_OVERRIDES_EQUALS, {'type': keyType}); | 4025 MessageKind.CONST_MAP_KEY_OVERRIDES_EQUALS, {'type': keyType}); |
| 4014 } | 4026 } |
| 4015 } | 4027 } |
| 4016 } | 4028 } |
| 4017 | 4029 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4068 return node.accept(new ConstructorResolver(resolution, this, | 4080 return node.accept(new ConstructorResolver(resolution, this, |
| 4069 inConstContext: node.isConst)); | 4081 inConstContext: node.isConst)); |
| 4070 } | 4082 } |
| 4071 | 4083 |
| 4072 ConstructorResult resolveRedirectingFactory(RedirectingFactoryBody node, | 4084 ConstructorResult resolveRedirectingFactory(RedirectingFactoryBody node, |
| 4073 {bool inConstContext: false}) { | 4085 {bool inConstContext: false}) { |
| 4074 return node.accept(new ConstructorResolver(resolution, this, | 4086 return node.accept(new ConstructorResolver(resolution, this, |
| 4075 inConstContext: inConstContext)); | 4087 inConstContext: inConstContext)); |
| 4076 } | 4088 } |
| 4077 | 4089 |
| 4078 DartType resolveTypeAnnotation(TypeAnnotation node, | 4090 ResolutionDartType resolveTypeAnnotation(TypeAnnotation node, |
| 4079 {bool malformedIsError: false, | 4091 {bool malformedIsError: false, |
| 4080 bool deferredIsMalformed: true, | 4092 bool deferredIsMalformed: true, |
| 4081 bool registerCheckedModeCheck: true}) { | 4093 bool registerCheckedModeCheck: true}) { |
| 4082 DartType type = typeResolver.resolveTypeAnnotation(this, node, | 4094 ResolutionDartType type = typeResolver.resolveTypeAnnotation(this, node, |
| 4083 malformedIsError: malformedIsError, | 4095 malformedIsError: malformedIsError, |
| 4084 deferredIsMalformed: deferredIsMalformed); | 4096 deferredIsMalformed: deferredIsMalformed); |
| 4085 if (registerCheckedModeCheck) { | 4097 if (registerCheckedModeCheck) { |
| 4086 registry.registerCheckedModeCheck(type); | 4098 registry.registerCheckedModeCheck(type); |
| 4087 } | 4099 } |
| 4088 return type; | 4100 return type; |
| 4089 } | 4101 } |
| 4090 | 4102 |
| 4091 ResolutionResult visitLiteralList(LiteralList node) { | 4103 ResolutionResult visitLiteralList(LiteralList node) { |
| 4092 bool isValidAsConstant = true; | 4104 bool isValidAsConstant = true; |
| 4093 sendIsMemberAccess = false; | 4105 sendIsMemberAccess = false; |
| 4094 | 4106 |
| 4095 NodeList arguments = node.typeArguments; | 4107 NodeList arguments = node.typeArguments; |
| 4096 DartType typeArgument; | 4108 ResolutionDartType typeArgument; |
| 4097 if (arguments != null) { | 4109 if (arguments != null) { |
| 4098 Link<Node> nodes = arguments.nodes; | 4110 Link<Node> nodes = arguments.nodes; |
| 4099 if (nodes.isEmpty) { | 4111 if (nodes.isEmpty) { |
| 4100 // The syntax [: <>[] :] is not allowed. | 4112 // The syntax [: <>[] :] is not allowed. |
| 4101 reporter.reportErrorMessage( | 4113 reporter.reportErrorMessage( |
| 4102 arguments, MessageKind.MISSING_TYPE_ARGUMENT); | 4114 arguments, MessageKind.MISSING_TYPE_ARGUMENT); |
| 4103 isValidAsConstant = false; | 4115 isValidAsConstant = false; |
| 4104 } else { | 4116 } else { |
| 4105 typeArgument = resolveTypeAnnotation(nodes.head); | 4117 typeArgument = resolveTypeAnnotation(nodes.head); |
| 4106 for (nodes = nodes.tail; !nodes.isEmpty; nodes = nodes.tail) { | 4118 for (nodes = nodes.tail; !nodes.isEmpty; nodes = nodes.tail) { |
| 4107 reporter.reportWarningMessage( | 4119 reporter.reportWarningMessage( |
| 4108 nodes.head, MessageKind.ADDITIONAL_TYPE_ARGUMENT); | 4120 nodes.head, MessageKind.ADDITIONAL_TYPE_ARGUMENT); |
| 4109 resolveTypeAnnotation(nodes.head); | 4121 resolveTypeAnnotation(nodes.head); |
| 4110 } | 4122 } |
| 4111 } | 4123 } |
| 4112 } | 4124 } |
| 4113 DartType listType; | 4125 ResolutionDartType listType; |
| 4114 if (typeArgument != null) { | 4126 if (typeArgument != null) { |
| 4115 if (node.isConst && typeArgument.containsTypeVariables) { | 4127 if (node.isConst && typeArgument.containsTypeVariables) { |
| 4116 reporter.reportErrorMessage( | 4128 reporter.reportErrorMessage( |
| 4117 arguments.nodes.head, MessageKind.TYPE_VARIABLE_IN_CONSTANT); | 4129 arguments.nodes.head, MessageKind.TYPE_VARIABLE_IN_CONSTANT); |
| 4118 isValidAsConstant = false; | 4130 isValidAsConstant = false; |
| 4119 } | 4131 } |
| 4120 listType = commonElements.listType(typeArgument); | 4132 listType = commonElements.listType(typeArgument); |
| 4121 } else { | 4133 } else { |
| 4122 listType = commonElements.listType(); | 4134 listType = commonElements.listType(); |
| 4123 } | 4135 } |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4381 registry.undefineTarget(body); | 4393 registry.undefineTarget(body); |
| 4382 } | 4394 } |
| 4383 return const NoneResult(); | 4395 return const NoneResult(); |
| 4384 } | 4396 } |
| 4385 | 4397 |
| 4386 ResolutionResult visitLiteralMap(LiteralMap node) { | 4398 ResolutionResult visitLiteralMap(LiteralMap node) { |
| 4387 bool isValidAsConstant = true; | 4399 bool isValidAsConstant = true; |
| 4388 sendIsMemberAccess = false; | 4400 sendIsMemberAccess = false; |
| 4389 | 4401 |
| 4390 NodeList arguments = node.typeArguments; | 4402 NodeList arguments = node.typeArguments; |
| 4391 DartType keyTypeArgument; | 4403 ResolutionDartType keyTypeArgument; |
| 4392 DartType valueTypeArgument; | 4404 ResolutionDartType valueTypeArgument; |
| 4393 if (arguments != null) { | 4405 if (arguments != null) { |
| 4394 Link<Node> nodes = arguments.nodes; | 4406 Link<Node> nodes = arguments.nodes; |
| 4395 if (nodes.isEmpty) { | 4407 if (nodes.isEmpty) { |
| 4396 // The syntax [: <>{} :] is not allowed. | 4408 // The syntax [: <>{} :] is not allowed. |
| 4397 reporter.reportErrorMessage( | 4409 reporter.reportErrorMessage( |
| 4398 arguments, MessageKind.MISSING_TYPE_ARGUMENT); | 4410 arguments, MessageKind.MISSING_TYPE_ARGUMENT); |
| 4399 isValidAsConstant = false; | 4411 isValidAsConstant = false; |
| 4400 } else { | 4412 } else { |
| 4401 keyTypeArgument = resolveTypeAnnotation(nodes.head); | 4413 keyTypeArgument = resolveTypeAnnotation(nodes.head); |
| 4402 nodes = nodes.tail; | 4414 nodes = nodes.tail; |
| 4403 if (nodes.isEmpty) { | 4415 if (nodes.isEmpty) { |
| 4404 reporter.reportWarningMessage( | 4416 reporter.reportWarningMessage( |
| 4405 arguments, MessageKind.MISSING_TYPE_ARGUMENT); | 4417 arguments, MessageKind.MISSING_TYPE_ARGUMENT); |
| 4406 } else { | 4418 } else { |
| 4407 valueTypeArgument = resolveTypeAnnotation(nodes.head); | 4419 valueTypeArgument = resolveTypeAnnotation(nodes.head); |
| 4408 for (nodes = nodes.tail; !nodes.isEmpty; nodes = nodes.tail) { | 4420 for (nodes = nodes.tail; !nodes.isEmpty; nodes = nodes.tail) { |
| 4409 reporter.reportWarningMessage( | 4421 reporter.reportWarningMessage( |
| 4410 nodes.head, MessageKind.ADDITIONAL_TYPE_ARGUMENT); | 4422 nodes.head, MessageKind.ADDITIONAL_TYPE_ARGUMENT); |
| 4411 resolveTypeAnnotation(nodes.head); | 4423 resolveTypeAnnotation(nodes.head); |
| 4412 } | 4424 } |
| 4413 } | 4425 } |
| 4414 } | 4426 } |
| 4415 } | 4427 } |
| 4416 DartType mapType; | 4428 ResolutionDartType mapType; |
| 4417 if (valueTypeArgument != null) { | 4429 if (valueTypeArgument != null) { |
| 4418 mapType = commonElements.mapType(keyTypeArgument, valueTypeArgument); | 4430 mapType = commonElements.mapType(keyTypeArgument, valueTypeArgument); |
| 4419 } else { | 4431 } else { |
| 4420 mapType = commonElements.mapType(); | 4432 mapType = commonElements.mapType(); |
| 4421 } | 4433 } |
| 4422 if (node.isConst && mapType.containsTypeVariables) { | 4434 if (node.isConst && mapType.containsTypeVariables) { |
| 4423 reporter.reportErrorMessage( | 4435 reporter.reportErrorMessage( |
| 4424 arguments, MessageKind.TYPE_VARIABLE_IN_CONSTANT); | 4436 arguments, MessageKind.TYPE_VARIABLE_IN_CONSTANT); |
| 4425 isValidAsConstant = false; | 4437 isValidAsConstant = false; |
| 4426 } | 4438 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4461 | 4473 |
| 4462 ResolutionResult visitLiteralMapEntry(LiteralMapEntry node) { | 4474 ResolutionResult visitLiteralMapEntry(LiteralMapEntry node) { |
| 4463 node.visitChildren(this); | 4475 node.visitChildren(this); |
| 4464 return const NoneResult(); | 4476 return const NoneResult(); |
| 4465 } | 4477 } |
| 4466 | 4478 |
| 4467 ResolutionResult visitNamedArgument(NamedArgument node) { | 4479 ResolutionResult visitNamedArgument(NamedArgument node) { |
| 4468 return visit(node.expression); | 4480 return visit(node.expression); |
| 4469 } | 4481 } |
| 4470 | 4482 |
| 4471 DartType typeOfConstant(ConstantValue constant) { | 4483 ResolutionDartType typeOfConstant(ConstantValue constant) { |
| 4472 if (constant.isInt) return commonElements.intType; | 4484 if (constant.isInt) return commonElements.intType; |
| 4473 if (constant.isBool) return commonElements.boolType; | 4485 if (constant.isBool) return commonElements.boolType; |
| 4474 if (constant.isDouble) return commonElements.doubleType; | 4486 if (constant.isDouble) return commonElements.doubleType; |
| 4475 if (constant.isString) return commonElements.stringType; | 4487 if (constant.isString) return commonElements.stringType; |
| 4476 if (constant.isNull) return commonElements.nullType; | 4488 if (constant.isNull) return commonElements.nullType; |
| 4477 if (constant.isFunction) return commonElements.functionType; | 4489 if (constant.isFunction) return commonElements.functionType; |
| 4478 assert(constant.isObject); | 4490 assert(constant.isObject); |
| 4479 ObjectConstantValue objectConstant = constant; | 4491 ObjectConstantValue objectConstant = constant; |
| 4480 return objectConstant.type; | 4492 return objectConstant.type; |
| 4481 } | 4493 } |
| 4482 | 4494 |
| 4483 bool overridesEquals(DartType type) { | 4495 bool overridesEquals(ResolutionDartType type) { |
| 4484 ClassElement cls = type.element; | 4496 ClassElement cls = type.element; |
| 4485 Element equals = cls.lookupMember('=='); | 4497 Element equals = cls.lookupMember('=='); |
| 4486 return equals.enclosingClass != commonElements.objectClass; | 4498 return equals.enclosingClass != commonElements.objectClass; |
| 4487 } | 4499 } |
| 4488 | 4500 |
| 4489 void checkCaseExpressions(SwitchStatement node) { | 4501 void checkCaseExpressions(SwitchStatement node) { |
| 4490 CaseMatch firstCase = null; | 4502 CaseMatch firstCase = null; |
| 4491 DartType firstCaseType = null; | 4503 ResolutionDartType firstCaseType = null; |
| 4492 DiagnosticMessage error; | 4504 DiagnosticMessage error; |
| 4493 List<DiagnosticMessage> infos = <DiagnosticMessage>[]; | 4505 List<DiagnosticMessage> infos = <DiagnosticMessage>[]; |
| 4494 | 4506 |
| 4495 for (Link<Node> cases = node.cases.nodes; | 4507 for (Link<Node> cases = node.cases.nodes; |
| 4496 !cases.isEmpty; | 4508 !cases.isEmpty; |
| 4497 cases = cases.tail) { | 4509 cases = cases.tail) { |
| 4498 SwitchCase switchCase = cases.head; | 4510 SwitchCase switchCase = cases.head; |
| 4499 | 4511 |
| 4500 for (Node labelOrCase in switchCase.labelsAndCases) { | 4512 for (Node labelOrCase in switchCase.labelsAndCases) { |
| 4501 CaseMatch caseMatch = labelOrCase.asCaseMatch(); | 4513 CaseMatch caseMatch = labelOrCase.asCaseMatch(); |
| 4502 if (caseMatch == null) continue; | 4514 if (caseMatch == null) continue; |
| 4503 | 4515 |
| 4504 // Analyze the constant. | 4516 // Analyze the constant. |
| 4505 ConstantExpression constant = | 4517 ConstantExpression constant = |
| 4506 registry.getConstant(caseMatch.expression); | 4518 registry.getConstant(caseMatch.expression); |
| 4507 assert(invariant(node, constant != null, | 4519 assert(invariant(node, constant != null, |
| 4508 message: 'No constant computed for $node')); | 4520 message: 'No constant computed for $node')); |
| 4509 | 4521 |
| 4510 ConstantValue value = resolution.constants.getConstantValue(constant); | 4522 ConstantValue value = resolution.constants.getConstantValue(constant); |
| 4511 DartType caseType = | 4523 ResolutionDartType caseType = |
| 4512 value.getType(commonElements); //typeOfConstant(value); | 4524 value.getType(commonElements); //typeOfConstant(value); |
| 4513 | 4525 |
| 4514 if (firstCaseType == null) { | 4526 if (firstCaseType == null) { |
| 4515 firstCase = caseMatch; | 4527 firstCase = caseMatch; |
| 4516 firstCaseType = caseType; | 4528 firstCaseType = caseType; |
| 4517 | 4529 |
| 4518 // We only report the bad type on the first class element. All others | 4530 // We only report the bad type on the first class element. All others |
| 4519 // get a "type differs" error. | 4531 // get a "type differs" error. |
| 4520 if (caseType == commonElements.doubleType) { | 4532 if (caseType == commonElements.doubleType) { |
| 4521 reporter.reportErrorMessage( | 4533 reporter.reportErrorMessage( |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4724 Scope blockScope = new BlockScope(scope); | 4736 Scope blockScope = new BlockScope(scope); |
| 4725 inCatchParameters = true; | 4737 inCatchParameters = true; |
| 4726 visitIn(node.formals, blockScope); | 4738 visitIn(node.formals, blockScope); |
| 4727 inCatchParameters = false; | 4739 inCatchParameters = false; |
| 4728 var oldInCatchBlock = inCatchBlock; | 4740 var oldInCatchBlock = inCatchBlock; |
| 4729 inCatchBlock = true; | 4741 inCatchBlock = true; |
| 4730 visitIn(node.block, blockScope); | 4742 visitIn(node.block, blockScope); |
| 4731 inCatchBlock = oldInCatchBlock; | 4743 inCatchBlock = oldInCatchBlock; |
| 4732 | 4744 |
| 4733 if (node.type != null) { | 4745 if (node.type != null) { |
| 4734 DartType exceptionType = | 4746 ResolutionDartType exceptionType = |
| 4735 resolveTypeAnnotation(node.type, registerCheckedModeCheck: false); | 4747 resolveTypeAnnotation(node.type, registerCheckedModeCheck: false); |
| 4736 if (exceptionDefinition != null) { | 4748 if (exceptionDefinition != null) { |
| 4737 Node exceptionVariable = exceptionDefinition.definitions.nodes.head; | 4749 Node exceptionVariable = exceptionDefinition.definitions.nodes.head; |
| 4738 VariableElementX exceptionElement = | 4750 VariableElementX exceptionElement = |
| 4739 registry.getDefinition(exceptionVariable); | 4751 registry.getDefinition(exceptionVariable); |
| 4740 exceptionElement.variables.type = exceptionType; | 4752 exceptionElement.variables.type = exceptionType; |
| 4741 } | 4753 } |
| 4742 registry.registerTypeUse(new TypeUse.catchType(exceptionType)); | 4754 registry.registerTypeUse(new TypeUse.catchType(exceptionType)); |
| 4743 } | 4755 } |
| 4744 if (stackTraceDefinition != null) { | 4756 if (stackTraceDefinition != null) { |
| 4745 Node stackTraceVariable = stackTraceDefinition.definitions.nodes.head; | 4757 Node stackTraceVariable = stackTraceDefinition.definitions.nodes.head; |
| 4746 VariableElementX stackTraceElement = | 4758 VariableElementX stackTraceElement = |
| 4747 registry.getDefinition(stackTraceVariable); | 4759 registry.getDefinition(stackTraceVariable); |
| 4748 InterfaceType stackTraceType = commonElements.stackTraceType; | 4760 ResolutionInterfaceType stackTraceType = commonElements.stackTraceType; |
| 4749 stackTraceElement.variables.type = stackTraceType; | 4761 stackTraceElement.variables.type = stackTraceType; |
| 4750 } | 4762 } |
| 4751 return const NoneResult(); | 4763 return const NoneResult(); |
| 4752 } | 4764 } |
| 4753 } | 4765 } |
| 4754 | 4766 |
| 4755 /// Looks up [name] in [scope] and unwraps the result. | 4767 /// Looks up [name] in [scope] and unwraps the result. |
| 4756 Element lookupInScope( | 4768 Element lookupInScope( |
| 4757 DiagnosticReporter reporter, Node node, Scope scope, String name) { | 4769 DiagnosticReporter reporter, Node node, Scope scope, String name) { |
| 4758 return Elements.unwrap(scope.lookup(name), reporter, node); | 4770 return Elements.unwrap(scope.lookup(name), reporter, node); |
| 4759 } | 4771 } |
| OLD | NEW |