OLD | NEW |
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 engine.resolver; | 5 library engine.resolver; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/src/generated/scanner.dart'; | 9 import 'package:analyzer/src/generated/scanner.dart'; |
10 | 10 |
(...skipping 10884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10895 // | 10895 // |
10896 // Continue the class resolution. | 10896 // Continue the class resolution. |
10897 // | 10897 // |
10898 enclosingClass = node.element; | 10898 enclosingClass = node.element; |
10899 typeAnalyzer.thisType = enclosingClass == null ? null : enclosingClass.type; | 10899 typeAnalyzer.thisType = enclosingClass == null ? null : enclosingClass.type; |
10900 node.accept(elementResolver); | 10900 node.accept(elementResolver); |
10901 node.accept(typeAnalyzer); | 10901 node.accept(typeAnalyzer); |
10902 } | 10902 } |
10903 | 10903 |
10904 @override | 10904 @override |
10905 void visitClassMembersInScope(ClassDeclaration node) { | |
10906 safelyVisit(node.documentationComment); | |
10907 node.metadata.accept(this); | |
10908 // | |
10909 // Visit the fields before other members so that instance fields will have | |
10910 // propagated types associated with them before we see their use sites. | |
10911 // | |
10912 List<ClassMember> nonFields = <ClassMember>[]; | |
10913 for (ClassMember member in node.members) { | |
10914 if (member is FieldDeclaration) { | |
10915 member.accept(this); | |
10916 } else { | |
10917 nonFields.add(member); | |
10918 } | |
10919 } | |
10920 for (ClassMember member in nonFields) { | |
10921 member.accept(this); | |
10922 } | |
10923 } | |
10924 | |
10925 @override | |
10926 Object visitComment(Comment node) { | 10905 Object visitComment(Comment node) { |
10927 if (node.parent is FunctionDeclaration || | 10906 if (node.parent is FunctionDeclaration || |
10928 node.parent is ConstructorDeclaration || | 10907 node.parent is ConstructorDeclaration || |
10929 node.parent is MethodDeclaration) { | 10908 node.parent is MethodDeclaration) { |
10930 if (!identical(node, _commentBeforeFunction)) { | 10909 if (!identical(node, _commentBeforeFunction)) { |
10931 _commentBeforeFunction = node; | 10910 _commentBeforeFunction = node; |
10932 return null; | 10911 return null; |
10933 } | 10912 } |
10934 } | 10913 } |
10935 super.visitComment(node); | 10914 super.visitComment(node); |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11527 return null; | 11506 return null; |
11528 } | 11507 } |
11529 | 11508 |
11530 @override | 11509 @override |
11531 Object visitTypeName(TypeName node) => null; | 11510 Object visitTypeName(TypeName node) => null; |
11532 | 11511 |
11533 @override | 11512 @override |
11534 Object visitVariableDeclaration(VariableDeclaration node) { | 11513 Object visitVariableDeclaration(VariableDeclaration node) { |
11535 super.visitVariableDeclaration(node); | 11514 super.visitVariableDeclaration(node); |
11536 VariableElement element = node.element; | 11515 VariableElement element = node.element; |
11537 FunctionElement initializerElement = element.initializer; | 11516 if (element.initializer != null && node.initializer != null) { |
11538 Expression initializer = node.initializer; | 11517 (element.initializer as FunctionElementImpl).returnType = |
11539 if (initializerElement is FunctionElementImpl && initializer != null) { | 11518 node.initializer.staticType; |
11540 initializerElement.returnType = initializer.staticType; | |
11541 } | |
11542 // | |
11543 // Propagate types for instance fields. Top-level variables and static | |
11544 // fields are handled elsewhere. | |
11545 // | |
11546 // TODO(brianwilkerson) Instance field propagation should probably be moved | |
11547 // into the class InstanceMemberInferrer because we're already doing | |
11548 // something there for strong mode. | |
11549 // | |
11550 if (initializer != null && | |
11551 element is FieldElementImpl && | |
11552 !element.isStatic && | |
11553 element.isFinal) { | |
11554 DartType staticType = element.type; | |
11555 DartType bestType = initializer.bestType; | |
11556 if (bestType != null && | |
11557 bestType != staticType && | |
11558 bestType.isMoreSpecificThan(staticType)) { | |
11559 element.propagatedType = bestType; | |
11560 } | |
11561 } | 11519 } |
11562 // Note: in addition to cloning the initializers for const variables, we | 11520 // Note: in addition to cloning the initializers for const variables, we |
11563 // have to clone the initializers for non-static final fields (because if | 11521 // have to clone the initializers for non-static final fields (because if |
11564 // they occur in a class with a const constructor, they will be needed to | 11522 // they occur in a class with a const constructor, they will be needed to |
11565 // evaluate the const constructor). | 11523 // evaluate the const constructor). |
11566 if ((element.isConst || | 11524 if ((element.isConst || |
11567 (element is FieldElement && | 11525 (element is FieldElement && |
11568 element.isFinal && | 11526 element.isFinal && |
11569 !element.isStatic)) && | 11527 !element.isStatic)) && |
11570 initializer != null) { | 11528 node.initializer != null) { |
11571 (element as ConstVariableElement).constantInitializer = | 11529 (element as ConstVariableElement).constantInitializer = |
11572 new ConstantAstCloner().cloneNode(initializer); | 11530 new ConstantAstCloner().cloneNode(node.initializer); |
11573 } | 11531 } |
11574 return null; | 11532 return null; |
11575 } | 11533 } |
11576 | 11534 |
11577 @override | 11535 @override |
11578 Object visitWhileStatement(WhileStatement node) { | 11536 Object visitWhileStatement(WhileStatement node) { |
11579 // Note: since we don't call the base class, we have to maintain | 11537 // Note: since we don't call the base class, we have to maintain |
11580 // _implicitLabelScope ourselves. | 11538 // _implicitLabelScope ourselves. |
11581 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; | 11539 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; |
11582 try { | 11540 try { |
(...skipping 4524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16107 nonFields.add(node); | 16065 nonFields.add(node); |
16108 return null; | 16066 return null; |
16109 } | 16067 } |
16110 | 16068 |
16111 @override | 16069 @override |
16112 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 16070 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
16113 | 16071 |
16114 @override | 16072 @override |
16115 Object visitWithClause(WithClause node) => null; | 16073 Object visitWithClause(WithClause node) => null; |
16116 } | 16074 } |
OLD | NEW |