Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: pkg/compiler/lib/src/resolution/members.dart

Issue 1416253002: Remove requiredTypes (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 8 import '../common/names.dart' show
9 Selectors; 9 Selectors;
10 import '../compiler.dart' show 10 import '../compiler.dart' show
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 // Run the body in a fresh statement scope. 632 // Run the body in a fresh statement scope.
633 StatementScope oldStatementScope = statementScope; 633 StatementScope oldStatementScope = statementScope;
634 statementScope = new StatementScope(); 634 statementScope = new StatementScope();
635 visit(node.body); 635 visit(node.body);
636 statementScope = oldStatementScope; 636 statementScope = oldStatementScope;
637 637
638 scope = oldScope; 638 scope = oldScope;
639 enclosingElement = previousEnclosingElement; 639 enclosingElement = previousEnclosingElement;
640 640
641 registry.registerClosure(function); 641 registry.registerClosure(function);
642 registry.registerInstantiatedClass(compiler.functionClass);
643 return const NoneResult(); 642 return const NoneResult();
644 } 643 }
645 644
646 ResolutionResult visitIf(If node) { 645 ResolutionResult visitIf(If node) {
647 doInPromotionScope(node.condition.expression, () => visit(node.condition)); 646 doInPromotionScope(node.condition.expression, () => visit(node.condition));
648 doInPromotionScope(node.thenPart, 647 doInPromotionScope(node.thenPart,
649 () => visitIn(node.thenPart, new BlockScope(scope))); 648 () => visitIn(node.thenPart, new BlockScope(scope)));
650 visitIn(node.elsePart, new BlockScope(scope)); 649 visitIn(node.elsePart, new BlockScope(scope));
651 return const NoneResult(); 650 return const NoneResult();
652 } 651 }
(...skipping 2872 matching lines...) Expand 10 before | Expand all | Expand 10 after
3525 } 3524 }
3526 3525
3527 ConstantResult visitLiteralNull(LiteralNull node) { 3526 ConstantResult visitLiteralNull(LiteralNull node) {
3528 registry.registerInstantiatedType(coreTypes.nullType); 3527 registry.registerInstantiatedType(coreTypes.nullType);
3529 ConstantExpression constant = new NullConstantExpression(); 3528 ConstantExpression constant = new NullConstantExpression();
3530 registry.setConstant(node, constant); 3529 registry.setConstant(node, constant);
3531 return new ConstantResult(node, constant); 3530 return new ConstantResult(node, constant);
3532 } 3531 }
3533 3532
3534 ConstantResult visitLiteralSymbol(LiteralSymbol node) { 3533 ConstantResult visitLiteralSymbol(LiteralSymbol node) {
3535 registry.registerInstantiatedClass(compiler.symbolClass);
3536 registry.registerStaticUse(compiler.symbolConstructor.declaration);
3537 String name = node.slowNameString; 3534 String name = node.slowNameString;
3538 registry.registerConstSymbol(name); 3535 registry.registerConstSymbol(name);
3539 if (!validateSymbol(node, name, reportError: false)) { 3536 if (!validateSymbol(node, name, reportError: false)) {
3540 reporter.reportErrorMessage( 3537 reporter.reportErrorMessage(
3541 node, 3538 node,
3542 MessageKind.UNSUPPORTED_LITERAL_SYMBOL, 3539 MessageKind.UNSUPPORTED_LITERAL_SYMBOL,
3543 {'value': name}); 3540 {'value': name});
3544 } 3541 }
3545 analyzeConstantDeferred(node); 3542 analyzeConstantDeferred(node);
3546 ConstantExpression constant = new SymbolConstantExpression(name); 3543 ConstantExpression constant = new SymbolConstantExpression(name);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
3643 // TODO(johnniwinther): Create constant constructor for this case and 3640 // TODO(johnniwinther): Create constant constructor for this case and
3644 // let evaluation detect the cyclicity. 3641 // let evaluation detect the cyclicity.
3645 isValidAsConstant = false; 3642 isValidAsConstant = false;
3646 } 3643 }
3647 } 3644 }
3648 3645
3649 // Check that the target constructor is type compatible with the 3646 // Check that the target constructor is type compatible with the
3650 // redirecting constructor. 3647 // redirecting constructor.
3651 ClassElement targetClass = redirectionTarget.enclosingClass; 3648 ClassElement targetClass = redirectionTarget.enclosingClass;
3652 InterfaceType type = registry.getType(node); 3649 InterfaceType type = registry.getType(node);
3653 FunctionType targetType = redirectionTarget.computeType(resolution) 3650 FunctionType targetConstructorType =
3654 .subst(type.typeArguments, targetClass.typeVariables); 3651 redirectionTarget.computeType(resolution)
3652 .subst(type.typeArguments, targetClass.typeVariables);
3655 FunctionType constructorType = constructor.computeType(resolution); 3653 FunctionType constructorType = constructor.computeType(resolution);
3656 bool isSubtype = compiler.types.isSubtype(targetType, constructorType); 3654 bool isSubtype = compiler.types.isSubtype(
3655 targetConstructorType, constructorType);
3657 if (!isSubtype) { 3656 if (!isSubtype) {
3658 reporter.reportWarningMessage( 3657 reporter.reportWarningMessage(
3659 node, 3658 node,
3660 MessageKind.NOT_ASSIGNABLE, 3659 MessageKind.NOT_ASSIGNABLE,
3661 {'fromType': targetType, 'toType': constructorType}); 3660 {'fromType': targetConstructorType, 'toType': constructorType});
3662 // TODO(johnniwinther): Handle this (potentially) erroneous case. 3661 // TODO(johnniwinther): Handle this (potentially) erroneous case.
3663 isValidAsConstant = false; 3662 isValidAsConstant = false;
3664 } 3663 }
3665 3664
3666 redirectionTarget.computeType(resolution); 3665 redirectionTarget.computeType(resolution);
3667 FunctionSignature targetSignature = redirectionTarget.functionSignature; 3666 FunctionSignature targetSignature = redirectionTarget.functionSignature;
3668 constructor.computeType(resolution); 3667 constructor.computeType(resolution);
3669 FunctionSignature constructorSignature = constructor.functionSignature; 3668 FunctionSignature constructorSignature = constructor.functionSignature;
3670 if (!targetSignature.isCompatibleWith(constructorSignature)) { 3669 if (!targetSignature.isCompatibleWith(constructorSignature)) {
3671 assert(!isSubtype); 3670 assert(!isSubtype);
3672 registry.registerThrowNoSuchMethod(); 3671 registry.registerThrowNoSuchMethod();
3673 isValidAsConstant = false; 3672 isValidAsConstant = false;
3674 } 3673 }
3675 3674
3676 // Register a post process to check for cycles in the redirection chain and 3675 // Register a post process to check for cycles in the redirection chain and
3677 // set the actual generative constructor at the end of the chain. 3676 // set the actual generative constructor at the end of the chain.
3678 addDeferredAction(constructor, () { 3677 addDeferredAction(constructor, () {
3679 compiler.resolver.resolveRedirectionChain(constructor, node); 3678 compiler.resolver.resolveRedirectionChain(constructor, node);
3680 }); 3679 });
3681 3680
3682 registry.registerStaticUse(redirectionTarget); 3681 registry.registerStaticUse(redirectionTarget);
3683 // TODO(johnniwinther): Register the effective target type instead. 3682 // TODO(johnniwinther): Register the effective target type instead.
3684 registry.registerInstantiatedClass( 3683 registry.registerInstantiatedType(
3685 redirectionTarget.enclosingClass.declaration); 3684 redirectionTarget.enclosingClass.thisType
3685 .subst(type.typeArguments, targetClass.typeVariables));
3686 if (isSymbolConstructor) { 3686 if (isSymbolConstructor) {
3687 registry.registerSymbolConstructor(); 3687 registry.registerSymbolConstructor();
3688 } 3688 }
3689 if (isValidAsConstant) { 3689 if (isValidAsConstant) {
3690 List<String> names = <String>[]; 3690 List<String> names = <String>[];
3691 List<ConstantExpression> arguments = <ConstantExpression>[]; 3691 List<ConstantExpression> arguments = <ConstantExpression>[];
3692 int index = 0; 3692 int index = 0;
3693 constructorSignature.forEachParameter((ParameterElement parameter) { 3693 constructorSignature.forEachParameter((ParameterElement parameter) {
3694 if (parameter.isNamed) { 3694 if (parameter.isNamed) {
3695 String name = parameter.name; 3695 String name = parameter.name;
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
3988 } 3988 }
3989 3989
3990 DartType resolveTypeAnnotation(TypeAnnotation node, 3990 DartType resolveTypeAnnotation(TypeAnnotation node,
3991 {bool malformedIsError: false, 3991 {bool malformedIsError: false,
3992 bool deferredIsMalformed: true}) { 3992 bool deferredIsMalformed: true}) {
3993 DartType type = typeResolver.resolveTypeAnnotation( 3993 DartType type = typeResolver.resolveTypeAnnotation(
3994 this, node, malformedIsError: malformedIsError, 3994 this, node, malformedIsError: malformedIsError,
3995 deferredIsMalformed: deferredIsMalformed); 3995 deferredIsMalformed: deferredIsMalformed);
3996 if (inCheckContext) { 3996 if (inCheckContext) {
3997 registry.registerCheckedModeCheck(type); 3997 registry.registerCheckedModeCheck(type);
3998 registry.registerRequiredType(type, enclosingElement);
3999 } 3998 }
4000 return type; 3999 return type;
4001 } 4000 }
4002 4001
4003 ResolutionResult visitLiteralList(LiteralList node) { 4002 ResolutionResult visitLiteralList(LiteralList node) {
4004 bool isValidAsConstant = true; 4003 bool isValidAsConstant = true;
4005 sendIsMemberAccess = false; 4004 sendIsMemberAccess = false;
4006 4005
4007 NodeList arguments = node.typeArguments; 4006 NodeList arguments = node.typeArguments;
4008 DartType typeArgument; 4007 DartType typeArgument;
(...skipping 23 matching lines...) Expand all
4032 } 4031 }
4033 listType = coreTypes.listType(typeArgument); 4032 listType = coreTypes.listType(typeArgument);
4034 } else { 4033 } else {
4035 listType = coreTypes.listType(); 4034 listType = coreTypes.listType();
4036 } 4035 }
4037 registry.registerLiteralList( 4036 registry.registerLiteralList(
4038 node, 4037 node,
4039 listType, 4038 listType,
4040 isConstant: node.isConst, 4039 isConstant: node.isConst,
4041 isEmpty: node.elements.isEmpty); 4040 isEmpty: node.elements.isEmpty);
4042 registry.registerRequiredType(listType, enclosingElement);
4043 if (node.isConst) { 4041 if (node.isConst) {
4044 List<ConstantExpression> constantExpressions = <ConstantExpression>[]; 4042 List<ConstantExpression> constantExpressions = <ConstantExpression>[];
4045 inConstantContext(() { 4043 inConstantContext(() {
4046 for (Node element in node.elements) { 4044 for (Node element in node.elements) {
4047 ResolutionResult elementResult = visit(element); 4045 ResolutionResult elementResult = visit(element);
4048 if (isValidAsConstant && elementResult.isConstant) { 4046 if (isValidAsConstant && elementResult.isConstant) {
4049 constantExpressions.add(elementResult.constant); 4047 constantExpressions.add(elementResult.constant);
4050 } else { 4048 } else {
4051 isValidAsConstant = false; 4049 isValidAsConstant = false;
4052 } 4050 }
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
4356 reporter.reportErrorMessage( 4354 reporter.reportErrorMessage(
4357 arguments, 4355 arguments,
4358 MessageKind.TYPE_VARIABLE_IN_CONSTANT); 4356 MessageKind.TYPE_VARIABLE_IN_CONSTANT);
4359 isValidAsConstant = false; 4357 isValidAsConstant = false;
4360 } 4358 }
4361 registry.registerMapLiteral( 4359 registry.registerMapLiteral(
4362 node, 4360 node,
4363 mapType, 4361 mapType,
4364 isConstant: node.isConst, 4362 isConstant: node.isConst,
4365 isEmpty: node.entries.isEmpty); 4363 isEmpty: node.entries.isEmpty);
4366 registry.registerRequiredType(mapType, enclosingElement); 4364
4367 if (node.isConst) { 4365 if (node.isConst) {
4368
4369 List<ConstantExpression> keyExpressions = <ConstantExpression>[]; 4366 List<ConstantExpression> keyExpressions = <ConstantExpression>[];
4370 List<ConstantExpression> valueExpressions = <ConstantExpression>[]; 4367 List<ConstantExpression> valueExpressions = <ConstantExpression>[];
4371 inConstantContext(() { 4368 inConstantContext(() {
4372 for (LiteralMapEntry entry in node.entries) { 4369 for (LiteralMapEntry entry in node.entries) {
4373 ResolutionResult keyResult = visit(entry.key); 4370 ResolutionResult keyResult = visit(entry.key);
4374 ResolutionResult valueResult = visit(entry.value); 4371 ResolutionResult valueResult = visit(entry.value);
4375 if (isValidAsConstant && 4372 if (isValidAsConstant &&
4376 keyResult.isConstant && 4373 keyResult.isConstant &&
4377 valueResult.isConstant) { 4374 valueResult.isConstant) {
4378 keyExpressions.add(keyResult.constant); 4375 keyExpressions.add(keyResult.constant);
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
4652 TypeAnnotation type = declaration.type; 4649 TypeAnnotation type = declaration.type;
4653 if (type != null) { 4650 if (type != null) {
4654 reporter.reportErrorMessage( 4651 reporter.reportErrorMessage(
4655 type, MessageKind.PARAMETER_WITH_TYPE_IN_CATCH); 4652 type, MessageKind.PARAMETER_WITH_TYPE_IN_CATCH);
4656 } 4653 }
4657 } 4654 }
4658 } 4655 }
4659 } 4656 }
4660 4657
4661 Scope blockScope = new BlockScope(scope); 4658 Scope blockScope = new BlockScope(scope);
4662 doInCheckContext(() => visitIn(node.type, blockScope)); 4659 TypeResult exceptionTypeResult = visitIn(node.type, blockScope);
sigurdm 2015/10/22 09:18:03 doInCheckContext seems to be unused now.
Johnni Winther 2015/10/22 10:31:55 Good catch! Removed.
4663 visitIn(node.formals, blockScope); 4660 visitIn(node.formals, blockScope);
4664 var oldInCatchBlock = inCatchBlock; 4661 var oldInCatchBlock = inCatchBlock;
4665 inCatchBlock = true; 4662 inCatchBlock = true;
4666 visitIn(node.block, blockScope); 4663 visitIn(node.block, blockScope);
4667 inCatchBlock = oldInCatchBlock; 4664 inCatchBlock = oldInCatchBlock;
4668 4665
4669 if (node.type != null && exceptionDefinition != null) { 4666 if (exceptionTypeResult != null) {
4670 DartType exceptionType = registry.getType(node.type); 4667 DartType exceptionType = exceptionTypeResult.type;
4671 Node exceptionVariable = exceptionDefinition.definitions.nodes.head; 4668 if (exceptionDefinition != null) {
4672 VariableElementX exceptionElement = 4669 Node exceptionVariable = exceptionDefinition.definitions.nodes.head;
4673 registry.getDefinition(exceptionVariable); 4670 VariableElementX exceptionElement =
4674 exceptionElement.variables.type = exceptionType; 4671 registry.getDefinition(exceptionVariable);
4672 exceptionElement.variables.type = exceptionType;
4673 }
4674 registry.registerOnCatchType(exceptionType);
4675 } 4675 }
4676 if (stackTraceDefinition != null) { 4676 if (stackTraceDefinition != null) {
4677 Node stackTraceVariable = stackTraceDefinition.definitions.nodes.head; 4677 Node stackTraceVariable = stackTraceDefinition.definitions.nodes.head;
4678 VariableElementX stackTraceElement = 4678 VariableElementX stackTraceElement =
4679 registry.getDefinition(stackTraceVariable); 4679 registry.getDefinition(stackTraceVariable);
4680 registry.registerInstantiatedClass(compiler.stackTraceClass); 4680 InterfaceType stackTraceType = coreTypes.stackTraceType;
4681 stackTraceElement.variables.type = compiler.stackTraceClass.rawType; 4681 stackTraceElement.variables.type = stackTraceType;
4682 } 4682 }
4683 return const NoneResult(); 4683 return const NoneResult();
4684 } 4684 }
4685 } 4685 }
4686 4686
4687 /// Looks up [name] in [scope] and unwraps the result. 4687 /// Looks up [name] in [scope] and unwraps the result.
4688 Element lookupInScope(DiagnosticReporter reporter, Node node, 4688 Element lookupInScope(DiagnosticReporter reporter, Node node,
4689 Scope scope, String name) { 4689 Scope scope, String name) {
4690 return Elements.unwrap(scope.lookup(name), reporter, node); 4690 return Elements.unwrap(scope.lookup(name), reporter, node);
4691 } 4691 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698