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

Unified Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 1917893003: Optimize the task to re-resolve instance fields (issue 26306) (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add comment Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/task/dart.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/resolver.dart
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 510acdd29e1125ef219be82413ba26e780709856..621b85c1265e50a7366ad69d73a691755eb4ed44 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -4903,6 +4903,101 @@ class INIT_STATE extends Enum<INIT_STATE> {
}
/**
+ * An AST visitor that is used to re-resolve the initializers of instance
+ * fields. Although this class is an AST visitor, clients are expected to use
+ * the method [resolveCompilationUnit] to run it over a compilation unit.
+ */
+class InstanceFieldResolverVisitor extends ResolverVisitor {
+ /**
+ * Initialize a newly created visitor to resolve the nodes in an AST node.
+ *
+ * The [definingLibrary] is the element for the library containing the node
+ * being visited. The [source] is the source representing the compilation unit
+ * containing the node being visited. The [typeProvider] is the object used to
+ * access the types from the core library. The [errorListener] is the error
+ * listener that will be informed of any errors that are found during
+ * resolution. The [nameScope] is the scope used to resolve identifiers in the
+ * node that will first be visited. If `null` or unspecified, a new
+ * [LibraryScope] will be created based on [definingLibrary] and
+ * [typeProvider]. The [inheritanceManager] is used to perform inheritance
scheglov 2016/04/25 20:45:55 1. AFAIK LibraryScope does not need TypeProvider.
Brian Wilkerson 2016/04/25 21:08:58 Done. The comment was copied from elsewhere and I
+ * lookups. If `null` or unspecified, a new [InheritanceManager] will be
+ * created based on [definingLibrary]. The [typeAnalyzerFactory] is used to
+ * create the type analyzer. If `null` or unspecified, a type analyzer of
+ * type [StaticTypeAnalyzer] will be created.
+ */
+ InstanceFieldResolverVisitor(LibraryElement definingLibrary, Source source,
+ TypeProvider typeProvider, AnalysisErrorListener errorListener,
+ {Scope nameScope})
+ : super(definingLibrary, source, typeProvider, errorListener,
+ nameScope: nameScope);
+
+ /**
+ * Resolve the instance fields in the given compilation unit [node].
+ */
+ void resolveCompilationUnit(CompilationUnit node) {
+ _overrideManager.enterScope();
+ try {
+ NodeList<CompilationUnitMember> declarations = node.declarations;
+ int declarationCount = declarations.length;
+ for (int i = 0; i < declarationCount; i++) {
+ CompilationUnitMember declaration = declarations[i];
+ if (declaration is ClassDeclaration) {
+ _resolveClassDeclaration(declaration);
+ }
+ }
+ } finally {
+ _overrideManager.exitScope();
+ }
+ }
+
+ /**
+ * Resolve the instance fields in the given class declaration [node].
+ */
+ void _resolveClassDeclaration(ClassDeclaration node) {
+ _enclosingClassDeclaration = node;
+ ClassElement outerType = enclosingClass;
+ Scope outerScope = nameScope;
+ try {
+ enclosingClass = node.element;
+ typeAnalyzer.thisType = enclosingClass?.type;
+ if (enclosingClass == null) {
+ AnalysisEngine.instance.logger.logInformation(
+ "Missing element for class declaration ${node.name.name} in ${definingLibrary.source.fullName}",
+ new CaughtException(new AnalysisException(), null));
+ // Don't try to re-resolve the initializers if we cannot set up the
+ // right name scope for resolution.
+ } else {
+ nameScope = new ClassScope(nameScope, enclosingClass);
+ NodeList<ClassMember> members = node.members;
+ for (int i = 0; i < members.length; i++) {
scheglov 2016/04/25 20:45:55 Do we want to extract members.length as we do for
Brian Wilkerson 2016/04/25 21:08:58 Done
+ ClassMember member = members[i];
+ if (member is FieldDeclaration) {
+ _resolveFieldDeclaration(member);
+ }
+ }
+ }
+ } finally {
+ nameScope = outerScope;
+ typeAnalyzer.thisType = outerType?.type;
+ enclosingClass = outerType;
+ _enclosingClassDeclaration = null;
+ }
+ }
+
+ /**
+ * Resolve the instance fields in the given field declaration [node].
+ */
+ void _resolveFieldDeclaration(FieldDeclaration node) {
+ for (VariableDeclaration field in node.fields.variables) {
scheglov 2016/04/25 20:45:55 Do we need to check that it is an instance (not st
Brian Wilkerson 2016/04/25 21:08:58 Done
+ Expression initializer = field.initializer;
+ if (initializer != null) {
+ initializer.accept(this);
scheglov 2016/04/25 20:45:55 field.initializer?.accept(this) maybe?
Brian Wilkerson 2016/04/25 21:08:58 Done
+ }
+ }
+ }
+}
+
+/**
* Instances of the class `OverrideVerifier` visit all of the declarations in a compilation
* unit to verify that if they have an override annotation it is being used correctly.
*/
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/task/dart.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698