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

Side by Side Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 1635063003: Stop precomputing ClassElement.isValidMixin. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 analyzer.src.generated.resolver; 5 library analyzer.src.generated.resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/visitor.dart'; 10 import 'package:analyzer/dart/ast/visitor.dart';
(...skipping 2653 matching lines...) Expand 10 before | Expand all | Expand 10 after
2664 * A flag indicating whether a variable declaration is in the context of a fie ld declaration. 2664 * A flag indicating whether a variable declaration is in the context of a fie ld declaration.
2665 */ 2665 */
2666 bool _inFieldContext = false; 2666 bool _inFieldContext = false;
2667 2667
2668 /** 2668 /**
2669 * A flag indicating whether a variable declaration is within the body of a me thod or function. 2669 * A flag indicating whether a variable declaration is within the body of a me thod or function.
2670 */ 2670 */
2671 bool _inFunction = false; 2671 bool _inFunction = false;
2672 2672
2673 /** 2673 /**
2674 * A flag indicating whether the class currently being visited can be used as a mixin.
2675 */
2676 bool _isValidMixin = false;
2677
2678 /**
2679 * A collection holding the elements defined in a class that need to have 2674 * A collection holding the elements defined in a class that need to have
2680 * their function type fixed to take into account type parameters of the 2675 * their function type fixed to take into account type parameters of the
2681 * enclosing class, or `null` if we are not currently processing nodes within 2676 * enclosing class, or `null` if we are not currently processing nodes within
2682 * a class. 2677 * a class.
2683 */ 2678 */
2684 List<ExecutableElementImpl> _functionTypesToFix = null; 2679 List<ExecutableElementImpl> _functionTypesToFix = null;
2685 2680
2686 /** 2681 /**
2687 * A table mapping field names to field elements for the fields defined in the current class, or 2682 * A table mapping field names to field elements for the fields defined in the current class, or
2688 * `null` if we are not in the scope of a class. 2683 * `null` if we are not in the scope of a class.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2730 _currentHolder.addLocalVariable(stackTrace); 2725 _currentHolder.addLocalVariable(stackTrace);
2731 stackTraceParameter.staticElement = stackTrace; 2726 stackTraceParameter.staticElement = stackTrace;
2732 } 2727 }
2733 } 2728 }
2734 return super.visitCatchClause(node); 2729 return super.visitCatchClause(node);
2735 } 2730 }
2736 2731
2737 @override 2732 @override
2738 Object visitClassDeclaration(ClassDeclaration node) { 2733 Object visitClassDeclaration(ClassDeclaration node) {
2739 ElementHolder holder = new ElementHolder(); 2734 ElementHolder holder = new ElementHolder();
2740 _isValidMixin = true;
2741 _functionTypesToFix = new List<ExecutableElementImpl>(); 2735 _functionTypesToFix = new List<ExecutableElementImpl>();
2742 // 2736 //
2743 // Process field declarations before constructors and methods so that field 2737 // Process field declarations before constructors and methods so that field
2744 // formal parameters can be correctly resolved to their fields. 2738 // formal parameters can be correctly resolved to their fields.
2745 // 2739 //
2746 ElementHolder previousHolder = _currentHolder; 2740 ElementHolder previousHolder = _currentHolder;
2747 _currentHolder = holder; 2741 _currentHolder = holder;
2748 try { 2742 try {
2749 List<ClassMember> nonFields = new List<ClassMember>(); 2743 List<ClassMember> nonFields = new List<ClassMember>();
2750 node.visitChildren( 2744 node.visitChildren(
(...skipping 17 matching lines...) Expand all
2768 _setDoc(element, node); 2762 _setDoc(element, node);
2769 element.abstract = node.isAbstract; 2763 element.abstract = node.isAbstract;
2770 element.accessors = holder.accessors; 2764 element.accessors = holder.accessors;
2771 List<ConstructorElement> constructors = holder.constructors; 2765 List<ConstructorElement> constructors = holder.constructors;
2772 if (constructors.isEmpty) { 2766 if (constructors.isEmpty) {
2773 constructors = _createDefaultConstructors(element); 2767 constructors = _createDefaultConstructors(element);
2774 } 2768 }
2775 element.constructors = constructors; 2769 element.constructors = constructors;
2776 element.fields = holder.fields; 2770 element.fields = holder.fields;
2777 element.methods = holder.methods; 2771 element.methods = holder.methods;
2778 element.validMixin = _isValidMixin;
2779 // Function types must be initialized after the enclosing element has been 2772 // Function types must be initialized after the enclosing element has been
2780 // set, for them to pick up the type parameters. 2773 // set, for them to pick up the type parameters.
2781 for (ExecutableElementImpl e in _functionTypesToFix) { 2774 for (ExecutableElementImpl e in _functionTypesToFix) {
2782 e.type = new FunctionTypeImpl(e); 2775 e.type = new FunctionTypeImpl(e);
2783 } 2776 }
2784 _functionTypesToFix = null; 2777 _functionTypesToFix = null;
2785 _currentHolder.addType(element); 2778 _currentHolder.addType(element);
2786 className.staticElement = element; 2779 className.staticElement = element;
2787 _fieldMap = null; 2780 _fieldMap = null;
2788 holder.validate(); 2781 holder.validate();
(...skipping 29 matching lines...) Expand all
2818 element.type = interfaceType; 2811 element.type = interfaceType;
2819 _setDoc(element, node); 2812 _setDoc(element, node);
2820 _currentHolder.addType(element); 2813 _currentHolder.addType(element);
2821 className.staticElement = element; 2814 className.staticElement = element;
2822 holder.validate(); 2815 holder.validate();
2823 return null; 2816 return null;
2824 } 2817 }
2825 2818
2826 @override 2819 @override
2827 Object visitConstructorDeclaration(ConstructorDeclaration node) { 2820 Object visitConstructorDeclaration(ConstructorDeclaration node) {
2828 _isValidMixin = false;
2829 ElementHolder holder = new ElementHolder(); 2821 ElementHolder holder = new ElementHolder();
2830 bool wasInFunction = _inFunction; 2822 bool wasInFunction = _inFunction;
2831 _inFunction = true; 2823 _inFunction = true;
2832 try { 2824 try {
2833 _visitChildren(holder, node); 2825 _visitChildren(holder, node);
2834 } finally { 2826 } finally {
2835 _inFunction = wasInFunction; 2827 _inFunction = wasInFunction;
2836 } 2828 }
2837 FunctionBody body = node.body; 2829 FunctionBody body = node.body;
2838 SimpleIdentifier constructorName = node.name; 2830 SimpleIdentifier constructorName = node.name;
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
3391 if (node.type == null) { 3383 if (node.type == null) {
3392 parameter.hasImplicitType = true; 3384 parameter.hasImplicitType = true;
3393 } 3385 }
3394 _currentHolder.addParameter(parameter); 3386 _currentHolder.addParameter(parameter);
3395 parameterName.staticElement = parameter; 3387 parameterName.staticElement = parameter;
3396 } 3388 }
3397 return super.visitSimpleFormalParameter(node); 3389 return super.visitSimpleFormalParameter(node);
3398 } 3390 }
3399 3391
3400 @override 3392 @override
3401 Object visitSuperExpression(SuperExpression node) {
3402 _isValidMixin = false;
3403 return super.visitSuperExpression(node);
3404 }
3405
3406 @override
3407 Object visitSwitchCase(SwitchCase node) { 3393 Object visitSwitchCase(SwitchCase node) {
3408 for (Label label in node.labels) { 3394 for (Label label in node.labels) {
3409 SimpleIdentifier labelName = label.label; 3395 SimpleIdentifier labelName = label.label;
3410 LabelElementImpl element = new LabelElementImpl(labelName, false, true); 3396 LabelElementImpl element = new LabelElementImpl(labelName, false, true);
3411 _currentHolder.addLabel(element); 3397 _currentHolder.addLabel(element);
3412 labelName.staticElement = element; 3398 labelName.staticElement = element;
3413 } 3399 }
3414 return super.visitSwitchCase(node); 3400 return super.visitSwitchCase(node);
3415 } 3401 }
3416 3402
(...skipping 8602 matching lines...) Expand 10 before | Expand all | Expand 10 after
12019 WithClause withClause = node.withClause; 12005 WithClause withClause = node.withClause;
12020 ImplementsClause implementsClause = node.implementsClause; 12006 ImplementsClause implementsClause = node.implementsClause;
12021 ClassElementImpl classElement = _getClassElement(node.name); 12007 ClassElementImpl classElement = _getClassElement(node.name);
12022 InterfaceType superclassType = null; 12008 InterfaceType superclassType = null;
12023 if (extendsClause != null) { 12009 if (extendsClause != null) {
12024 ErrorCode errorCode = (withClause == null 12010 ErrorCode errorCode = (withClause == null
12025 ? CompileTimeErrorCode.EXTENDS_NON_CLASS 12011 ? CompileTimeErrorCode.EXTENDS_NON_CLASS
12026 : CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS); 12012 : CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS);
12027 superclassType = _resolveType(extendsClause.superclass, errorCode, 12013 superclassType = _resolveType(extendsClause.superclass, errorCode,
12028 CompileTimeErrorCode.EXTENDS_ENUM, errorCode); 12014 CompileTimeErrorCode.EXTENDS_ENUM, errorCode);
12029 if (!identical(superclassType, typeProvider.objectType)) {
12030 classElement.validMixin = false;
12031 }
12032 } 12015 }
12033 if (classElement != null) { 12016 if (classElement != null) {
12034 if (superclassType == null) { 12017 if (superclassType == null) {
12035 InterfaceType objectType = typeProvider.objectType; 12018 InterfaceType objectType = typeProvider.objectType;
12036 if (!identical(classElement.type, objectType)) { 12019 if (!identical(classElement.type, objectType)) {
12037 superclassType = objectType; 12020 superclassType = objectType;
12038 } 12021 }
12039 } 12022 }
12040 classElement.supertype = superclassType; 12023 classElement.supertype = superclassType;
12041 } 12024 }
(...skipping 1560 matching lines...) Expand 10 before | Expand all | Expand 10 after
13602 nonFields.add(node); 13585 nonFields.add(node);
13603 return null; 13586 return null;
13604 } 13587 }
13605 13588
13606 @override 13589 @override
13607 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 13590 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
13608 13591
13609 @override 13592 @override
13610 Object visitWithClause(WithClause node) => null; 13593 Object visitWithClause(WithClause node) => null;
13611 } 13594 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698