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

Side by Side Diff: pkg/analyzer/lib/src/task/strong_mode.dart

Issue 1320923003: Implement a task to compute the dependencies between static variables (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comments Created 5 years, 3 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
« no previous file with comments | « pkg/analyzer/lib/src/task/dart.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.task.strong_mode; 5 library analyzer.src.task.strong_mode;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
11 import 'package:analyzer/src/generated/engine.dart';
12 import 'package:analyzer/src/generated/java_engine.dart';
11 import 'package:analyzer/src/generated/resolver.dart'; 13 import 'package:analyzer/src/generated/resolver.dart';
12 import 'package:analyzer/src/generated/utilities_dart.dart'; 14 import 'package:analyzer/src/generated/utilities_dart.dart';
13 15
14 /** 16 /**
17 * A function that returns `true` if the given [variable] passes the filter.
18 */
19 typedef bool VariableFilter(VariableElement element);
20
21 /**
15 * An object used to find static variables whose types should be inferred and 22 * An object used to find static variables whose types should be inferred and
16 * classes whose members should have types inferred. Clients are expected to 23 * classes whose members should have types inferred. Clients are expected to
17 * visit a [CompilationUnit]. 24 * visit a [CompilationUnit].
18 */ 25 */
19 class InferrenceFinder extends SimpleAstVisitor { 26 class InferrenceFinder extends SimpleAstVisitor {
20 /** 27 /**
21 * The static variables that should have types inferred for them. 28 * The static variables that should have types inferred for them.
22 */ 29 */
23 final List<VariableElement> staticVariables = <VariableElement>[]; 30 final List<VariableElement> staticVariables = <VariableElement>[];
24 31
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 /** 79 /**
73 * Add all of the [variables] with initializers to the list of variables whose 80 * Add all of the [variables] with initializers to the list of variables whose
74 * type can be inferred. Technically, we only infer the types of variables 81 * type can be inferred. Technically, we only infer the types of variables
75 * that do not have a static type, but all variables with initializers 82 * that do not have a static type, but all variables with initializers
76 * potentially need to be re-resolved after inference because they might 83 * potentially need to be re-resolved after inference because they might
77 * refer to fields whose type was inferred. 84 * refer to fields whose type was inferred.
78 */ 85 */
79 void _addVariables(NodeList<VariableDeclaration> variables) { 86 void _addVariables(NodeList<VariableDeclaration> variables) {
80 for (VariableDeclaration variable in variables) { 87 for (VariableDeclaration variable in variables) {
81 if (variable.initializer != null) { 88 if (variable.initializer != null) {
82 staticVariables.add(variable.element); 89 VariableElement element = variable.element;
90 if (element.hasImplicitType) {
91 staticVariables.add(element);
92 }
83 } 93 }
84 } 94 }
85 } 95 }
86 } 96 }
87 97
88 /** 98 /**
89 * An object used to infer the type of instance fields and the return types of 99 * An object used to infer the type of instance fields and the return types of
90 * instance methods within a single compilation unit. 100 * instance methods within a single compilation unit.
91 */ 101 */
92 class InstanceMemberInferrer { 102 class InstanceMemberInferrer {
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 FunctionType functionType = element.type; 532 FunctionType functionType = element.type;
523 if (functionType is FunctionTypeImpl) { 533 if (functionType is FunctionTypeImpl) {
524 element.type = 534 element.type =
525 new FunctionTypeImpl(element, functionType.prunedTypedefs); 535 new FunctionTypeImpl(element, functionType.prunedTypedefs);
526 } 536 }
527 } 537 }
528 } 538 }
529 } 539 }
530 540
531 /** 541 /**
542 * A visitor that will gather all of the variables referenced within a given
543 * AST structure. The collection can be restricted to contain only those
544 * variables that pass a specified filter.
545 */
546 class VariableGatherer extends RecursiveAstVisitor {
547 /**
548 * The filter used to limit which variables are gathered, or `null` if no
549 * filtering is to be performed.
550 */
551 final VariableFilter filter;
552
553 /**
554 * The variables that were found.
555 */
556 final Set<VariableElement> results = new HashSet<VariableElement>();
557
558 /**
559 * Initialize a newly created gatherer to gather all of the variables that
560 * pass the given [filter] (or all variables if no filter is provided).
561 */
562 VariableGatherer([this.filter = null]);
563
564 @override
565 void visitSimpleIdentifier(SimpleIdentifier node) {
566 if (!node.inDeclarationContext()) {
567 Element element = node.staticElement;
568 if (element is PropertyAccessorElement && element.isSynthetic) {
569 element = (element as PropertyAccessorElement).variable;
570 }
571 if (element is VariableElement && (filter == null || filter(element))) {
572 results.add(element);
573 }
574 }
575 }
576 }
577
578 /**
532 * A class of exception that is not used anywhere else. 579 * A class of exception that is not used anywhere else.
533 */ 580 */
534 class _CycleException implements Exception {} 581 class _CycleException implements Exception {}
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/dart.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698