Chromium Code Reviews| 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 analyzer.src.generated.incremental_resolver; | 5 library analyzer.src.generated.incremental_resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:math' as math; | 8 import 'dart:math' as math; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 node is MethodDeclaration) { | 324 node is MethodDeclaration) { |
| 325 return node; | 325 return node; |
| 326 } | 326 } |
| 327 node = node.parent; | 327 node = node.parent; |
| 328 } | 328 } |
| 329 throw new AnalysisException("Cannot resolve node: no resolvable node"); | 329 throw new AnalysisException("Cannot resolve node: no resolvable node"); |
| 330 } | 330 } |
| 331 | 331 |
| 332 void _prepareResolutionContext(AstNode node) { | 332 void _prepareResolutionContext(AstNode node) { |
| 333 if (_resolutionContext == null) { | 333 if (_resolutionContext == null) { |
| 334 _resolutionContext = | 334 _resolutionContext = ResolutionContextBuilder.contextFor(node); |
| 335 ResolutionContextBuilder.contextFor(node, errorListener); | |
| 336 } | 335 } |
| 337 } | 336 } |
| 338 | 337 |
| 339 _resolveReferences(AstNode node) { | 338 _resolveReferences(AstNode node) { |
| 340 LoggingTimer timer = logger.startTimer(); | 339 LoggingTimer timer = logger.startTimer(); |
| 341 try { | 340 try { |
| 342 _prepareResolutionContext(node); | 341 _prepareResolutionContext(node); |
| 343 Scope scope = _resolutionContext.scope; | 342 Scope scope = _resolutionContext.scope; |
| 344 // resolve types | 343 // resolve types |
| 345 { | 344 { |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1047 Scope scope; | 1046 Scope scope; |
| 1048 } | 1047 } |
| 1049 | 1048 |
| 1050 /** | 1049 /** |
| 1051 * Instances of the class [ResolutionContextBuilder] build the context for a | 1050 * Instances of the class [ResolutionContextBuilder] build the context for a |
| 1052 * given node in an AST structure. At the moment, this class only handles | 1051 * given node in an AST structure. At the moment, this class only handles |
| 1053 * top-level and class-level declarations. | 1052 * top-level and class-level declarations. |
| 1054 */ | 1053 */ |
| 1055 class ResolutionContextBuilder { | 1054 class ResolutionContextBuilder { |
| 1056 /** | 1055 /** |
| 1057 * The listener to which analysis errors will be reported. | |
| 1058 */ | |
| 1059 final AnalysisErrorListener _errorListener; | |
| 1060 | |
| 1061 /** | |
| 1062 * The class containing the enclosing [CompilationUnitElement]. | 1056 * The class containing the enclosing [CompilationUnitElement]. |
| 1063 */ | 1057 */ |
| 1064 CompilationUnitElement _enclosingUnit; | 1058 CompilationUnitElement _enclosingUnit; |
| 1065 | 1059 |
| 1066 /** | 1060 /** |
| 1067 * The class containing the enclosing [ClassDeclaration], or `null` if we are | 1061 * The class containing the enclosing [ClassDeclaration], or `null` if we are |
| 1068 * not in the scope of a class. | 1062 * not in the scope of a class. |
| 1069 */ | 1063 */ |
| 1070 ClassDeclaration _enclosingClassDeclaration; | 1064 ClassDeclaration _enclosingClassDeclaration; |
| 1071 | 1065 |
| 1072 /** | 1066 /** |
| 1073 * The class containing the enclosing [ClassElement], or `null` if we are not | 1067 * The class containing the enclosing [ClassElement], or `null` if we are not |
| 1074 * in the scope of a class. | 1068 * in the scope of a class. |
| 1075 */ | 1069 */ |
| 1076 ClassElement _enclosingClass; | 1070 ClassElement _enclosingClass; |
| 1077 | 1071 |
| 1078 /** | 1072 /** |
| 1079 * Initialize a newly created scope builder to generate a scope that will | 1073 * Initialize a newly created scope builder to generate a scope that will |
| 1080 * report errors to the given listener. | 1074 * report errors to the given listener. |
| 1081 */ | 1075 */ |
| 1082 ResolutionContextBuilder(this._errorListener); | 1076 ResolutionContextBuilder(); |
|
scheglov
2016/09/09 16:06:53
The documentation is not accurate anymore.
And pro
Brian Wilkerson
2016/09/09 16:16:56
Done
| |
| 1083 | 1077 |
| 1084 Scope _scopeFor(AstNode node) { | 1078 Scope _scopeFor(AstNode node) { |
| 1085 if (node is CompilationUnit) { | 1079 if (node is CompilationUnit) { |
| 1086 return _scopeForAstNode(node); | 1080 return _scopeForAstNode(node); |
| 1087 } | 1081 } |
| 1088 AstNode parent = node.parent; | 1082 AstNode parent = node.parent; |
| 1089 if (parent == null) { | 1083 if (parent == null) { |
| 1090 throw new AnalysisException( | 1084 throw new AnalysisException( |
| 1091 "Cannot create scope: node is not part of a CompilationUnit"); | 1085 "Cannot create scope: node is not part of a CompilationUnit"); |
| 1092 } | 1086 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1174 throw new AnalysisException( | 1168 throw new AnalysisException( |
| 1175 "Cannot create scope: compilation unit is not part of a library"); | 1169 "Cannot create scope: compilation unit is not part of a library"); |
| 1176 } | 1170 } |
| 1177 return new LibraryScope(libraryElement); | 1171 return new LibraryScope(libraryElement); |
| 1178 } | 1172 } |
| 1179 | 1173 |
| 1180 /** | 1174 /** |
| 1181 * Return the context in which the given AST structure should be resolved. | 1175 * Return the context in which the given AST structure should be resolved. |
| 1182 * | 1176 * |
| 1183 * [node] - the root of the AST structure to be resolved. | 1177 * [node] - the root of the AST structure to be resolved. |
| 1184 * [errorListener] - the listener to which analysis errors will be reported. | 1178 * [errorListener] - the listener to which analysis errors will be reported. |
|
scheglov
2016/09/09 16:06:53
This line can be removed.
Brian Wilkerson
2016/09/09 16:16:56
Done
| |
| 1185 * | 1179 * |
| 1186 * Throws [AnalysisException] if the AST structure has not been resolved or | 1180 * Throws [AnalysisException] if the AST structure has not been resolved or |
| 1187 * is not part of a [CompilationUnit] | 1181 * is not part of a [CompilationUnit] |
| 1188 */ | 1182 */ |
| 1189 static ResolutionContext contextFor( | 1183 static ResolutionContext contextFor(AstNode node) { |
| 1190 AstNode node, AnalysisErrorListener errorListener) { | |
| 1191 if (node == null) { | 1184 if (node == null) { |
| 1192 throw new AnalysisException("Cannot create context: node is null"); | 1185 throw new AnalysisException("Cannot create context: node is null"); |
| 1193 } | 1186 } |
| 1194 // build scope | 1187 // build scope |
| 1195 ResolutionContextBuilder builder = | 1188 ResolutionContextBuilder builder = new ResolutionContextBuilder(); |
| 1196 new ResolutionContextBuilder(errorListener); | |
| 1197 Scope scope = builder._scopeFor(node); | 1189 Scope scope = builder._scopeFor(node); |
| 1198 // prepare context | 1190 // prepare context |
| 1199 ResolutionContext context = new ResolutionContext(); | 1191 ResolutionContext context = new ResolutionContext(); |
| 1200 context.scope = scope; | 1192 context.scope = scope; |
| 1201 context.enclosingUnit = builder._enclosingUnit; | 1193 context.enclosingUnit = builder._enclosingUnit; |
| 1202 context.enclosingClassDeclaration = builder._enclosingClassDeclaration; | 1194 context.enclosingClassDeclaration = builder._enclosingClassDeclaration; |
| 1203 context.enclosingClass = builder._enclosingClass; | 1195 context.enclosingClass = builder._enclosingClass; |
| 1204 return context; | 1196 return context; |
| 1205 } | 1197 } |
| 1206 } | 1198 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1319 @override | 1311 @override |
| 1320 String toString() => name; | 1312 String toString() => name; |
| 1321 } | 1313 } |
| 1322 | 1314 |
| 1323 class _TokenPair { | 1315 class _TokenPair { |
| 1324 final _TokenDifferenceKind kind; | 1316 final _TokenDifferenceKind kind; |
| 1325 final Token oldToken; | 1317 final Token oldToken; |
| 1326 final Token newToken; | 1318 final Token newToken; |
| 1327 _TokenPair(this.kind, this.oldToken, this.newToken); | 1319 _TokenPair(this.kind, this.oldToken, this.newToken); |
| 1328 } | 1320 } |
| OLD | NEW |