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.registerCheckedModeCheck(type); | 417 registry.registerIsCheck(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.registerCheckedModeCheck(element.type); | 503 registry.registerIsCheck(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.registerAsCast(type); | 1193 registry.registerAsCheck(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); |
1955 | 1956 |
1956 registry.useElement(node, element); | 1957 registry.useElement(node, element); |
1957 registry.registerTypeLiteral(node, element.type); | 1958 registry.registerTypeLiteral(node, element.type); |
1958 | 1959 |
1959 if (node.isCall) { | 1960 if (node.isCall) { |
1960 CallStructure callStructure = | 1961 CallStructure callStructure = |
1961 resolveArguments(node.argumentsNode).callStructure; | 1962 resolveArguments(node.argumentsNode).callStructure; |
1962 Selector selector = callStructure.callSelector; | 1963 Selector selector = callStructure.callSelector; |
1963 // TODO(23998): Remove this when all information goes through | 1964 // TODO(23998): Remove this when all information goes through |
1964 // the [SendStructure]. | 1965 // the [SendStructure]. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1997 MessageKind.IF_NULL_ASSIGNING_TYPE, const {}); | 1998 MessageKind.IF_NULL_ASSIGNING_TYPE, const {}); |
1998 // TODO(23998): Remove these when all information goes through | 1999 // TODO(23998): Remove these when all information goes through |
1999 // the [SendStructure]. | 2000 // the [SendStructure]. |
2000 registry.useElement(node.selector, element); | 2001 registry.useElement(node.selector, element); |
2001 } else { | 2002 } else { |
2002 error = reportAndCreateErroneousElement( | 2003 error = reportAndCreateErroneousElement( |
2003 node.selector, name.text, | 2004 node.selector, name.text, |
2004 MessageKind.ASSIGNING_TYPE, const {}); | 2005 MessageKind.ASSIGNING_TYPE, const {}); |
2005 } | 2006 } |
2006 | 2007 |
| 2008 if (node.isComplex) { |
| 2009 // We read the type variable before trying write to it. |
| 2010 registry.registerTypeVariableExpression(element); |
| 2011 } |
| 2012 |
2007 // TODO(23998): Remove this when all information goes through | 2013 // TODO(23998): Remove this when all information goes through |
2008 // the [SendStructure]. | 2014 // the [SendStructure]. |
2009 registry.useElement(node, error); | 2015 registry.useElement(node, error); |
2010 // TODO(johnniwinther): Register only on read? | |
2011 registry.registerTypeLiteral(node, element.type); | 2016 registry.registerTypeLiteral(node, element.type); |
2012 registry.registerThrowNoSuchMethod(); | 2017 registry.registerThrowNoSuchMethod(); |
2013 semantics = new StaticAccess.typeParameterTypeLiteral(element); | 2018 semantics = new StaticAccess.typeParameterTypeLiteral(element); |
2014 } | 2019 } |
2015 return handleUpdate(node, name, semantics); | 2020 return handleUpdate(node, name, semantics); |
2016 } | 2021 } |
2017 | 2022 |
2018 /// Handle access to a constant type literal of [type]. | 2023 /// Handle access to a constant type literal of [type]. |
2019 // TODO(johnniwinther): Remove [name] when [Selector] is not required for the | 2024 // TODO(johnniwinther): Remove [name] when [Selector] is not required for the |
2020 // the [GetStructure]. | 2025 // the [GetStructure]. |
(...skipping 1975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3996 compiler, this, inConstContext: inConstContext)); | 4001 compiler, this, inConstContext: inConstContext)); |
3997 } | 4002 } |
3998 | 4003 |
3999 DartType resolveTypeAnnotation(TypeAnnotation node, | 4004 DartType resolveTypeAnnotation(TypeAnnotation node, |
4000 {bool malformedIsError: false, | 4005 {bool malformedIsError: false, |
4001 bool deferredIsMalformed: true}) { | 4006 bool deferredIsMalformed: true}) { |
4002 DartType type = typeResolver.resolveTypeAnnotation( | 4007 DartType type = typeResolver.resolveTypeAnnotation( |
4003 this, node, malformedIsError: malformedIsError, | 4008 this, node, malformedIsError: malformedIsError, |
4004 deferredIsMalformed: deferredIsMalformed); | 4009 deferredIsMalformed: deferredIsMalformed); |
4005 if (inCheckContext) { | 4010 if (inCheckContext) { |
4006 registry.registerCheckedModeCheck(type); | 4011 registry.registerIsCheck(type); |
4007 registry.registerRequiredType(type, enclosingElement); | 4012 registry.registerRequiredType(type, enclosingElement); |
4008 } | 4013 } |
4009 return type; | 4014 return type; |
4010 } | 4015 } |
4011 | 4016 |
4012 ResolutionResult visitLiteralList(LiteralList node) { | 4017 ResolutionResult visitLiteralList(LiteralList node) { |
4013 bool isValidAsConstant = true; | 4018 bool isValidAsConstant = true; |
4014 sendIsMemberAccess = false; | 4019 sendIsMemberAccess = false; |
4015 | 4020 |
4016 NodeList arguments = node.typeArguments; | 4021 NodeList arguments = node.typeArguments; |
(...skipping 19 matching lines...) Expand all Loading... |
4036 if (node.isConst && typeArgument.containsTypeVariables) { | 4041 if (node.isConst && typeArgument.containsTypeVariables) { |
4037 reporter.reportErrorMessage( | 4042 reporter.reportErrorMessage( |
4038 arguments.nodes.head, | 4043 arguments.nodes.head, |
4039 MessageKind.TYPE_VARIABLE_IN_CONSTANT); | 4044 MessageKind.TYPE_VARIABLE_IN_CONSTANT); |
4040 isValidAsConstant = false; | 4045 isValidAsConstant = false; |
4041 } | 4046 } |
4042 listType = coreTypes.listType(typeArgument); | 4047 listType = coreTypes.listType(typeArgument); |
4043 } else { | 4048 } else { |
4044 listType = coreTypes.listType(); | 4049 listType = coreTypes.listType(); |
4045 } | 4050 } |
4046 registry.registerLiteralList( | 4051 registry.setType(node, listType); |
4047 node, | 4052 registry.registerInstantiatedType(listType); |
4048 listType, | |
4049 isConstant: node.isConst, | |
4050 isEmpty: node.elements.isEmpty); | |
4051 registry.registerRequiredType(listType, enclosingElement); | 4053 registry.registerRequiredType(listType, enclosingElement); |
4052 if (node.isConst) { | 4054 if (node.isConst) { |
4053 List<ConstantExpression> constantExpressions = <ConstantExpression>[]; | 4055 List<ConstantExpression> constantExpressions = <ConstantExpression>[]; |
4054 inConstantContext(() { | 4056 inConstantContext(() { |
4055 for (Node element in node.elements) { | 4057 for (Node element in node.elements) { |
4056 ResolutionResult elementResult = visit(element); | 4058 ResolutionResult elementResult = visit(element); |
4057 if (isValidAsConstant && elementResult.isConstant) { | 4059 if (isValidAsConstant && elementResult.isConstant) { |
4058 constantExpressions.add(elementResult.constant); | 4060 constantExpressions.add(elementResult.constant); |
4059 } else { | 4061 } else { |
4060 isValidAsConstant = false; | 4062 isValidAsConstant = false; |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4360 mapType = coreTypes.mapType(keyTypeArgument, valueTypeArgument); | 4362 mapType = coreTypes.mapType(keyTypeArgument, valueTypeArgument); |
4361 } else { | 4363 } else { |
4362 mapType = coreTypes.mapType(); | 4364 mapType = coreTypes.mapType(); |
4363 } | 4365 } |
4364 if (node.isConst && mapType.containsTypeVariables) { | 4366 if (node.isConst && mapType.containsTypeVariables) { |
4365 reporter.reportErrorMessage( | 4367 reporter.reportErrorMessage( |
4366 arguments, | 4368 arguments, |
4367 MessageKind.TYPE_VARIABLE_IN_CONSTANT); | 4369 MessageKind.TYPE_VARIABLE_IN_CONSTANT); |
4368 isValidAsConstant = false; | 4370 isValidAsConstant = false; |
4369 } | 4371 } |
4370 registry.registerMapLiteral( | 4372 registry.registerMapLiteral(node, mapType, node.isConst); |
4371 node, | |
4372 mapType, | |
4373 isConstant: node.isConst, | |
4374 isEmpty: node.entries.isEmpty); | |
4375 registry.registerRequiredType(mapType, enclosingElement); | 4373 registry.registerRequiredType(mapType, enclosingElement); |
4376 if (node.isConst) { | 4374 if (node.isConst) { |
4377 | 4375 |
4378 List<ConstantExpression> keyExpressions = <ConstantExpression>[]; | 4376 List<ConstantExpression> keyExpressions = <ConstantExpression>[]; |
4379 List<ConstantExpression> valueExpressions = <ConstantExpression>[]; | 4377 List<ConstantExpression> valueExpressions = <ConstantExpression>[]; |
4380 inConstantContext(() { | 4378 inConstantContext(() { |
4381 for (LiteralMapEntry entry in node.entries) { | 4379 for (LiteralMapEntry entry in node.entries) { |
4382 ResolutionResult keyResult = visit(entry.key); | 4380 ResolutionResult keyResult = visit(entry.key); |
4383 ResolutionResult valueResult = visit(entry.value); | 4381 ResolutionResult valueResult = visit(entry.value); |
4384 if (isValidAsConstant && | 4382 if (isValidAsConstant && |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4691 } | 4689 } |
4692 return const NoneResult(); | 4690 return const NoneResult(); |
4693 } | 4691 } |
4694 } | 4692 } |
4695 | 4693 |
4696 /// Looks up [name] in [scope] and unwraps the result. | 4694 /// Looks up [name] in [scope] and unwraps the result. |
4697 Element lookupInScope(DiagnosticReporter reporter, Node node, | 4695 Element lookupInScope(DiagnosticReporter reporter, Node node, |
4698 Scope scope, String name) { | 4696 Scope scope, String name) { |
4699 return Elements.unwrap(scope.lookup(name), reporter, node); | 4697 return Elements.unwrap(scope.lookup(name), reporter, node); |
4700 } | 4698 } |
OLD | NEW |