| 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/names.dart' show | 7 import '../common/names.dart' show |
| 8 Selectors; | 8 Selectors; |
| 9 import '../compiler.dart' show | 9 import '../compiler.dart' show |
| 10 Compiler; | 10 Compiler; |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 } | 407 } |
| 408 return new ElementResult(element); | 408 return new ElementResult(element); |
| 409 } | 409 } |
| 410 return const NoneResult(); | 410 return const NoneResult(); |
| 411 } | 411 } |
| 412 } | 412 } |
| 413 | 413 |
| 414 TypeResult visitTypeAnnotation(TypeAnnotation node) { | 414 TypeResult visitTypeAnnotation(TypeAnnotation node) { |
| 415 DartType type = resolveTypeAnnotation(node); | 415 DartType type = resolveTypeAnnotation(node); |
| 416 if (inCheckContext) { | 416 if (inCheckContext) { |
| 417 registry.registerIsCheck(type); | 417 registry.registerCheckedModeCheck(type); |
| 418 } | 418 } |
| 419 return new TypeResult(type); | 419 return new TypeResult(type); |
| 420 } | 420 } |
| 421 | 421 |
| 422 bool isNamedConstructor(Send node) => node.receiver != null; | 422 bool isNamedConstructor(Send node) => node.receiver != null; |
| 423 | 423 |
| 424 Selector getRedirectingThisOrSuperConstructorSelector(Send node) { | 424 Selector getRedirectingThisOrSuperConstructorSelector(Send node) { |
| 425 if (isNamedConstructor(node)) { | 425 if (isNamedConstructor(node)) { |
| 426 String constructorName = node.selector.asIdentifier().source; | 426 String constructorName = node.selector.asIdentifier().source; |
| 427 return new Selector.callConstructor( | 427 return new Selector.callConstructor( |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 }); | 493 }); |
| 494 addDeferredAction(enclosingElement, () { | 494 addDeferredAction(enclosingElement, () { |
| 495 functionParameters.forEachOptionalParameter( | 495 functionParameters.forEachOptionalParameter( |
| 496 (ParameterElementX parameter) { | 496 (ParameterElementX parameter) { |
| 497 parameter.constant = | 497 parameter.constant = |
| 498 compiler.resolver.constantCompiler.compileConstant(parameter); | 498 compiler.resolver.constantCompiler.compileConstant(parameter); |
| 499 }); | 499 }); |
| 500 }); | 500 }); |
| 501 if (inCheckContext) { | 501 if (inCheckContext) { |
| 502 functionParameters.forEachParameter((ParameterElement element) { | 502 functionParameters.forEachParameter((ParameterElement element) { |
| 503 registry.registerIsCheck(element.type); | 503 registry.registerCheckedModeCheck(element.type); |
| 504 }); | 504 }); |
| 505 } | 505 } |
| 506 } | 506 } |
| 507 | 507 |
| 508 ResolutionResult visitAssert(Assert node) { | 508 ResolutionResult visitAssert(Assert node) { |
| 509 if (!compiler.enableAssertMessage) { | 509 if (!compiler.enableAssertMessage) { |
| 510 if (node.hasMessage) { | 510 if (node.hasMessage) { |
| 511 reporter.reportErrorMessage( | 511 reporter.reportErrorMessage( |
| 512 node, MessageKind.EXPERIMENTAL_ASSERT_MESSAGE); | 512 node, MessageKind.EXPERIMENTAL_ASSERT_MESSAGE); |
| 513 } | 513 } |
| (...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 return const NoneResult(); | 1183 return const NoneResult(); |
| 1184 } | 1184 } |
| 1185 | 1185 |
| 1186 /// Handle a type cast expression, like `a as T`. | 1186 /// Handle a type cast expression, like `a as T`. |
| 1187 ResolutionResult handleAs(Send node) { | 1187 ResolutionResult handleAs(Send node) { |
| 1188 Node expression = node.receiver; | 1188 Node expression = node.receiver; |
| 1189 visitExpression(expression); | 1189 visitExpression(expression); |
| 1190 | 1190 |
| 1191 Node typeNode = node.arguments.head; | 1191 Node typeNode = node.arguments.head; |
| 1192 DartType type = resolveTypeAnnotation(typeNode); | 1192 DartType type = resolveTypeAnnotation(typeNode); |
| 1193 registry.registerAsCheck(type); | 1193 registry.registerAsCast(type); |
| 1194 registry.registerSendStructure(node, new AsStructure(type)); | 1194 registry.registerSendStructure(node, new AsStructure(type)); |
| 1195 return const NoneResult(); | 1195 return const NoneResult(); |
| 1196 } | 1196 } |
| 1197 | 1197 |
| 1198 /// Handle the unary expression of an unresolved unary operator [text], like | 1198 /// Handle the unary expression of an unresolved unary operator [text], like |
| 1199 /// the no longer supported `+a`. | 1199 /// the no longer supported `+a`. |
| 1200 ResolutionResult handleUnresolvedUnary(Send node, String text) { | 1200 ResolutionResult handleUnresolvedUnary(Send node, String text) { |
| 1201 Node expression = node.receiver; | 1201 Node expression = node.receiver; |
| 1202 if (node.isSuperCall) { | 1202 if (node.isSuperCall) { |
| 1203 checkSuperAccess(node); | 1203 checkSuperAccess(node); |
| (...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1945 MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER, | 1945 MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER, |
| 1946 {'typeVariableName': name}, | 1946 {'typeVariableName': name}, |
| 1947 isError: true); | 1947 isError: true); |
| 1948 registry.registerCompileTimeError(error); | 1948 registry.registerCompileTimeError(error); |
| 1949 semantics = new StaticAccess.invalid(error); | 1949 semantics = new StaticAccess.invalid(error); |
| 1950 // TODO(johnniwinther): Clean up registration of elements and selectors | 1950 // TODO(johnniwinther): Clean up registration of elements and selectors |
| 1951 // for this case. | 1951 // for this case. |
| 1952 } else { | 1952 } else { |
| 1953 semantics = new StaticAccess.typeParameterTypeLiteral(element); | 1953 semantics = new StaticAccess.typeParameterTypeLiteral(element); |
| 1954 } | 1954 } |
| 1955 registry.registerTypeVariableExpression(element); | |
| 1956 | 1955 |
| 1957 registry.useElement(node, element); | 1956 registry.useElement(node, element); |
| 1958 registry.registerTypeLiteral(node, element.type); | 1957 registry.registerTypeLiteral(node, element.type); |
| 1959 | 1958 |
| 1960 if (node.isCall) { | 1959 if (node.isCall) { |
| 1961 CallStructure callStructure = | 1960 CallStructure callStructure = |
| 1962 resolveArguments(node.argumentsNode).callStructure; | 1961 resolveArguments(node.argumentsNode).callStructure; |
| 1963 Selector selector = callStructure.callSelector; | 1962 Selector selector = callStructure.callSelector; |
| 1964 // TODO(23998): Remove this when all information goes through | 1963 // TODO(23998): Remove this when all information goes through |
| 1965 // the [SendStructure]. | 1964 // the [SendStructure]. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1998 MessageKind.IF_NULL_ASSIGNING_TYPE, const {}); | 1997 MessageKind.IF_NULL_ASSIGNING_TYPE, const {}); |
| 1999 // TODO(23998): Remove these when all information goes through | 1998 // TODO(23998): Remove these when all information goes through |
| 2000 // the [SendStructure]. | 1999 // the [SendStructure]. |
| 2001 registry.useElement(node.selector, element); | 2000 registry.useElement(node.selector, element); |
| 2002 } else { | 2001 } else { |
| 2003 error = reportAndCreateErroneousElement( | 2002 error = reportAndCreateErroneousElement( |
| 2004 node.selector, name.text, | 2003 node.selector, name.text, |
| 2005 MessageKind.ASSIGNING_TYPE, const {}); | 2004 MessageKind.ASSIGNING_TYPE, const {}); |
| 2006 } | 2005 } |
| 2007 | 2006 |
| 2008 if (node.isComplex) { | |
| 2009 // We read the type variable before trying write to it. | |
| 2010 registry.registerTypeVariableExpression(element); | |
| 2011 } | |
| 2012 | |
| 2013 // TODO(23998): Remove this when all information goes through | 2007 // TODO(23998): Remove this when all information goes through |
| 2014 // the [SendStructure]. | 2008 // the [SendStructure]. |
| 2015 registry.useElement(node, error); | 2009 registry.useElement(node, error); |
| 2010 // TODO(johnniwinther): Register only on read? |
| 2016 registry.registerTypeLiteral(node, element.type); | 2011 registry.registerTypeLiteral(node, element.type); |
| 2017 registry.registerThrowNoSuchMethod(); | 2012 registry.registerThrowNoSuchMethod(); |
| 2018 semantics = new StaticAccess.typeParameterTypeLiteral(element); | 2013 semantics = new StaticAccess.typeParameterTypeLiteral(element); |
| 2019 } | 2014 } |
| 2020 return handleUpdate(node, name, semantics); | 2015 return handleUpdate(node, name, semantics); |
| 2021 } | 2016 } |
| 2022 | 2017 |
| 2023 /// Handle access to a constant type literal of [type]. | 2018 /// Handle access to a constant type literal of [type]. |
| 2024 // TODO(johnniwinther): Remove [name] when [Selector] is not required for the | 2019 // TODO(johnniwinther): Remove [name] when [Selector] is not required for the |
| 2025 // the [GetStructure]. | 2020 // the [GetStructure]. |
| (...skipping 1975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4001 compiler, this, inConstContext: inConstContext)); | 3996 compiler, this, inConstContext: inConstContext)); |
| 4002 } | 3997 } |
| 4003 | 3998 |
| 4004 DartType resolveTypeAnnotation(TypeAnnotation node, | 3999 DartType resolveTypeAnnotation(TypeAnnotation node, |
| 4005 {bool malformedIsError: false, | 4000 {bool malformedIsError: false, |
| 4006 bool deferredIsMalformed: true}) { | 4001 bool deferredIsMalformed: true}) { |
| 4007 DartType type = typeResolver.resolveTypeAnnotation( | 4002 DartType type = typeResolver.resolveTypeAnnotation( |
| 4008 this, node, malformedIsError: malformedIsError, | 4003 this, node, malformedIsError: malformedIsError, |
| 4009 deferredIsMalformed: deferredIsMalformed); | 4004 deferredIsMalformed: deferredIsMalformed); |
| 4010 if (inCheckContext) { | 4005 if (inCheckContext) { |
| 4011 registry.registerIsCheck(type); | 4006 registry.registerCheckedModeCheck(type); |
| 4012 registry.registerRequiredType(type, enclosingElement); | 4007 registry.registerRequiredType(type, enclosingElement); |
| 4013 } | 4008 } |
| 4014 return type; | 4009 return type; |
| 4015 } | 4010 } |
| 4016 | 4011 |
| 4017 ResolutionResult visitLiteralList(LiteralList node) { | 4012 ResolutionResult visitLiteralList(LiteralList node) { |
| 4018 bool isValidAsConstant = true; | 4013 bool isValidAsConstant = true; |
| 4019 sendIsMemberAccess = false; | 4014 sendIsMemberAccess = false; |
| 4020 | 4015 |
| 4021 NodeList arguments = node.typeArguments; | 4016 NodeList arguments = node.typeArguments; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 4041 if (node.isConst && typeArgument.containsTypeVariables) { | 4036 if (node.isConst && typeArgument.containsTypeVariables) { |
| 4042 reporter.reportErrorMessage( | 4037 reporter.reportErrorMessage( |
| 4043 arguments.nodes.head, | 4038 arguments.nodes.head, |
| 4044 MessageKind.TYPE_VARIABLE_IN_CONSTANT); | 4039 MessageKind.TYPE_VARIABLE_IN_CONSTANT); |
| 4045 isValidAsConstant = false; | 4040 isValidAsConstant = false; |
| 4046 } | 4041 } |
| 4047 listType = coreTypes.listType(typeArgument); | 4042 listType = coreTypes.listType(typeArgument); |
| 4048 } else { | 4043 } else { |
| 4049 listType = coreTypes.listType(); | 4044 listType = coreTypes.listType(); |
| 4050 } | 4045 } |
| 4051 registry.setType(node, listType); | 4046 registry.registerLiteralList( |
| 4052 registry.registerInstantiatedType(listType); | 4047 node, |
| 4048 listType, |
| 4049 isConstant: node.isConst, |
| 4050 isEmpty: node.elements.isEmpty); |
| 4053 registry.registerRequiredType(listType, enclosingElement); | 4051 registry.registerRequiredType(listType, enclosingElement); |
| 4054 if (node.isConst) { | 4052 if (node.isConst) { |
| 4055 List<ConstantExpression> constantExpressions = <ConstantExpression>[]; | 4053 List<ConstantExpression> constantExpressions = <ConstantExpression>[]; |
| 4056 inConstantContext(() { | 4054 inConstantContext(() { |
| 4057 for (Node element in node.elements) { | 4055 for (Node element in node.elements) { |
| 4058 ResolutionResult elementResult = visit(element); | 4056 ResolutionResult elementResult = visit(element); |
| 4059 if (isValidAsConstant && elementResult.isConstant) { | 4057 if (isValidAsConstant && elementResult.isConstant) { |
| 4060 constantExpressions.add(elementResult.constant); | 4058 constantExpressions.add(elementResult.constant); |
| 4061 } else { | 4059 } else { |
| 4062 isValidAsConstant = false; | 4060 isValidAsConstant = false; |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4362 mapType = coreTypes.mapType(keyTypeArgument, valueTypeArgument); | 4360 mapType = coreTypes.mapType(keyTypeArgument, valueTypeArgument); |
| 4363 } else { | 4361 } else { |
| 4364 mapType = coreTypes.mapType(); | 4362 mapType = coreTypes.mapType(); |
| 4365 } | 4363 } |
| 4366 if (node.isConst && mapType.containsTypeVariables) { | 4364 if (node.isConst && mapType.containsTypeVariables) { |
| 4367 reporter.reportErrorMessage( | 4365 reporter.reportErrorMessage( |
| 4368 arguments, | 4366 arguments, |
| 4369 MessageKind.TYPE_VARIABLE_IN_CONSTANT); | 4367 MessageKind.TYPE_VARIABLE_IN_CONSTANT); |
| 4370 isValidAsConstant = false; | 4368 isValidAsConstant = false; |
| 4371 } | 4369 } |
| 4372 registry.registerMapLiteral(node, mapType, node.isConst); | 4370 registry.registerMapLiteral( |
| 4371 node, |
| 4372 mapType, |
| 4373 isConstant: node.isConst, |
| 4374 isEmpty: node.entries.isEmpty); |
| 4373 registry.registerRequiredType(mapType, enclosingElement); | 4375 registry.registerRequiredType(mapType, enclosingElement); |
| 4374 if (node.isConst) { | 4376 if (node.isConst) { |
| 4375 | 4377 |
| 4376 List<ConstantExpression> keyExpressions = <ConstantExpression>[]; | 4378 List<ConstantExpression> keyExpressions = <ConstantExpression>[]; |
| 4377 List<ConstantExpression> valueExpressions = <ConstantExpression>[]; | 4379 List<ConstantExpression> valueExpressions = <ConstantExpression>[]; |
| 4378 inConstantContext(() { | 4380 inConstantContext(() { |
| 4379 for (LiteralMapEntry entry in node.entries) { | 4381 for (LiteralMapEntry entry in node.entries) { |
| 4380 ResolutionResult keyResult = visit(entry.key); | 4382 ResolutionResult keyResult = visit(entry.key); |
| 4381 ResolutionResult valueResult = visit(entry.value); | 4383 ResolutionResult valueResult = visit(entry.value); |
| 4382 if (isValidAsConstant && | 4384 if (isValidAsConstant && |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4689 } | 4691 } |
| 4690 return const NoneResult(); | 4692 return const NoneResult(); |
| 4691 } | 4693 } |
| 4692 } | 4694 } |
| 4693 | 4695 |
| 4694 /// Looks up [name] in [scope] and unwraps the result. | 4696 /// Looks up [name] in [scope] and unwraps the result. |
| 4695 Element lookupInScope(DiagnosticReporter reporter, Node node, | 4697 Element lookupInScope(DiagnosticReporter reporter, Node node, |
| 4696 Scope scope, String name) { | 4698 Scope scope, String name) { |
| 4697 return Elements.unwrap(scope.lookup(name), reporter, node); | 4699 return Elements.unwrap(scope.lookup(name), reporter, node); |
| 4698 } | 4700 } |
| OLD | NEW |