Skip to content

Commit ce5de54

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate ResolverVisitor.enclosingFunction
Change-Id: If1efd0e29716569737a0da7a795ccf61745b5c24 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/409842 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 23cde7f commit ce5de54

File tree

6 files changed

+41
-49
lines changed

6 files changed

+41
-49
lines changed

pkg/analyzer/lib/src/dart/resolver/simple_identifier_resolver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class SimpleIdentifierResolver with ScopeHelpers {
208208
}
209209
} else if (element == null) {
210210
// TODO(brianwilkerson): Recover from this error.
211-
if (node.name == "await" && _resolver.enclosingFunction2 != null) {
211+
if (node.name == "await" && _resolver.enclosingFunction != null) {
212212
errorReporter.atNode(
213213
node,
214214
CompileTimeErrorCode.UNDEFINED_IDENTIFIER_AWAIT,

pkg/analyzer/lib/src/generated/element_resolver.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ class ElementResolver {
9696
/// Return `true` iff the current enclosing function is a constant constructor
9797
/// declaration.
9898
bool get isInConstConstructor {
99-
var function = _resolver.enclosingFunction2;
100-
if (function is ConstructorElement2) {
99+
var function = _resolver.enclosingFunction;
100+
if (function is ConstructorElementImpl2) {
101101
return function.isConst;
102102
}
103103
return false;

pkg/analyzer/lib/src/generated/resolver.dart

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
180180

181181
/// The element representing the function containing the current node, or
182182
/// `null` if the current node is not contained in a function.
183-
ExecutableElement? _enclosingFunction;
183+
ExecutableElementImpl2? enclosingFunction;
184184

185185
/// The element that can be referenced by the `augmented` expression.
186186
AugmentableElement? enclosingAugmentation;
@@ -430,18 +430,6 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
430430
/// current node is inside a function body.
431431
BodyInferenceContext? get bodyContext => _bodyContext;
432432

433-
/// Return the element representing the function containing the current node,
434-
/// or `null` if the current node is not contained in a function.
435-
///
436-
/// @return the element representing the function containing the current node
437-
ExecutableElement? get enclosingFunction => _enclosingFunction;
438-
439-
/// Return the element representing the function containing the current node,
440-
/// or `null` if the current node is not contained in a function.
441-
///
442-
/// @return the element representing the function containing the current node
443-
ExecutableElement2? get enclosingFunction2 => _enclosingFunction.asElement2;
444-
445433
@override
446434
FlowAnalysis<AstNodeImpl, StatementImpl, ExpressionImpl,
447435
PromotableElementImpl2, SharedTypeView> get flow => flowAnalysis.flow!;
@@ -1314,12 +1302,12 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
13141302
/// Set information about enclosing declarations.
13151303
void prepareEnclosingDeclarations({
13161304
InterfaceElementImpl2? enclosingClassElement,
1317-
ExecutableElement? enclosingExecutableElement,
1305+
ExecutableElementImpl2? enclosingExecutableElement,
13181306
AugmentableElement? enclosingAugmentation,
13191307
}) {
13201308
enclosingClass = enclosingClassElement;
13211309
_setupThisType();
1322-
_enclosingFunction = enclosingExecutableElement;
1310+
enclosingFunction = enclosingExecutableElement;
13231311
this.enclosingAugmentation = enclosingAugmentation;
13241312
}
13251313

@@ -2334,14 +2322,15 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
23342322

23352323
@override
23362324
void visitConstructorDeclaration(covariant ConstructorDeclarationImpl node) {
2337-
var element = node.declaredElement!;
2325+
var fragment = node.declaredFragment!;
2326+
var element = fragment.element;
23382327
var returnType = element.type.returnType;
2339-
var outerFunction = _enclosingFunction;
2328+
var outerFunction = enclosingFunction;
23402329
var outerAugmentation = enclosingAugmentation;
23412330

23422331
try {
2343-
_enclosingFunction = element;
2344-
enclosingAugmentation = element;
2332+
enclosingFunction = element;
2333+
enclosingAugmentation = fragment;
23452334
assert(_thisType == null);
23462335
_setupThisType();
23472336
checkUnreachableNode(node);
@@ -2369,7 +2358,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
23692358
flowAnalysis.bodyOrInitializer_exit();
23702359
nullSafetyDeadCodeVerifier.flowEnd(node);
23712360
} finally {
2372-
_enclosingFunction = outerFunction;
2361+
enclosingFunction = outerFunction;
23732362
enclosingAugmentation = outerAugmentation;
23742363
_thisType = null;
23752364
}
@@ -2392,7 +2381,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
23922381
expression = popRewrite()!;
23932382
var whyNotPromoted = flowAnalysis.flow?.whyNotPromoted(expression);
23942383
if (fieldElement != null) {
2395-
var enclosingConstructor = enclosingFunction as ConstructorElement;
2384+
var enclosingConstructor = enclosingFunction as ConstructorElementImpl2;
23962385
checkForFieldInitializerNotAssignable(node, fieldElement.asElement2,
23972386
isConstConstructor: enclosingConstructor.isConst,
23982387
whyNotPromoted: whyNotPromoted);
@@ -2792,15 +2781,16 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
27922781
@override
27932782
void visitFunctionDeclaration(covariant FunctionDeclarationImpl node) {
27942783
bool isLocal = node.parent is FunctionDeclarationStatement;
2795-
var element = node.declaredElement!;
2784+
var fragment = node.declaredFragment!;
2785+
var element = fragment.element;
27962786
var functionType = node.declaredElement!.type;
2797-
var outerFunction = _enclosingFunction;
2787+
var outerFunction = enclosingFunction;
27982788
var outerAugmentation = enclosingAugmentation;
27992789

28002790
try {
2801-
_enclosingFunction = element;
2791+
enclosingFunction = element;
28022792
if (!isLocal) {
2803-
if (element case AugmentableElement augmentation) {
2793+
if (fragment case AugmentableElement augmentation) {
28042794
enclosingAugmentation = augmentation;
28052795
}
28062796
}
@@ -2843,7 +2833,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
28432833
}
28442834
nullSafetyDeadCodeVerifier.flowEnd(node);
28452835
} finally {
2846-
_enclosingFunction = outerFunction;
2836+
enclosingFunction = outerFunction;
28472837
enclosingAugmentation = outerAugmentation;
28482838
}
28492839
}
@@ -2860,13 +2850,13 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
28602850
void visitFunctionExpression(covariant FunctionExpressionImpl node,
28612851
{TypeImpl contextType = UnknownInferredType.instance}) {
28622852
inferenceLogWriter?.enterExpression(node, contextType);
2863-
var outerFunction = _enclosingFunction;
2864-
_enclosingFunction = node.declaredElement;
2853+
var outerFunction = enclosingFunction;
2854+
enclosingFunction = node.declaredFragment!.element;
28652855

28662856
_functionExpressionResolver.resolve(node, contextType: contextType);
28672857
insertGenericFunctionInstantiation(node, contextType: contextType);
28682858

2869-
_enclosingFunction = outerFunction;
2859+
enclosingFunction = outerFunction;
28702860
inferenceLogWriter?.exitExpression(node);
28712861
}
28722862

@@ -3197,14 +3187,15 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
31973187

31983188
@override
31993189
void visitMethodDeclaration(covariant MethodDeclarationImpl node) {
3200-
var element = node.declaredElement!;
3190+
var fragment = node.declaredFragment!;
3191+
var element = fragment.element;
32013192
var returnType = element.returnType;
3202-
var outerFunction = _enclosingFunction;
3193+
var outerFunction = enclosingFunction;
32033194
var outerAugmentation = enclosingAugmentation;
32043195

32053196
try {
3206-
_enclosingFunction = element;
3207-
if (element case AugmentableElement augmentation) {
3197+
enclosingFunction = element;
3198+
if (fragment case AugmentableElement augmentation) {
32083199
enclosingAugmentation = augmentation;
32093200
}
32103201
assert(_thisType == null);
@@ -3233,7 +3224,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
32333224
flowAnalysis.bodyOrInitializer_exit();
32343225
nullSafetyDeadCodeVerifier.flowEnd(node);
32353226
} finally {
3236-
_enclosingFunction = outerFunction;
3227+
enclosingFunction = outerFunction;
32373228
enclosingAugmentation = outerAugmentation;
32383229
_thisType = null;
32393230
}

pkg/analyzer/lib/src/summary2/ast_resolver.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore_for_file: analyzer_use_new_elements
6-
75
import 'package:_fe_analyzer_shared/src/types/shared_type.dart';
86
import 'package:analyzer/dart/analysis/analysis_options.dart';
97
import 'package:analyzer/dart/analysis/features.dart';
10-
import 'package:analyzer/dart/element/element.dart';
118
import 'package:analyzer/dart/element/scope.dart';
129
import 'package:analyzer/dart/element/type.dart';
1310
import 'package:analyzer/error/listener.dart';
@@ -30,7 +27,7 @@ class AstResolver {
3027
AnalysisErrorListener.NULL_LISTENER;
3128
final AnalysisOptions analysisOptions;
3229
final InterfaceElementImpl2? enclosingClassElement;
33-
final ExecutableElement? enclosingExecutableElement;
30+
final ExecutableElementImpl2? enclosingExecutableElement;
3431
final AugmentableElement? enclosingAugmentation;
3532
late final _resolutionVisitor = ResolutionVisitor(
3633
unitElement: _unitElement,

pkg/analyzer/lib/src/summary2/constructor_initializer_resolver.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,13 @@ class ConstructorInitializerResolver {
5757

5858
var analysisOptions = _libraryBuilder.kind.file.analysisOptions;
5959
var astResolver = AstResolver(
60-
_linker, unitElement, initializerScope, analysisOptions,
61-
enclosingClassElement: classElement.asElement2,
62-
enclosingExecutableElement: element);
60+
_linker,
61+
unitElement,
62+
initializerScope,
63+
analysisOptions,
64+
enclosingClassElement: classElement.asElement2,
65+
enclosingExecutableElement: element.asElement2,
66+
);
6367

6468
var body = node.body;
6569
body.localVariableInfo = LocalVariableInfo();

pkg/analyzer/lib/src/summary2/default_value_resolver.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class DefaultValueResolver {
3535
}
3636
}
3737

38-
void _constructor(_ClassContext context, ConstructorElement element) {
38+
void _constructor(_ClassContext context, ConstructorElementImpl element) {
3939
if (element.isSynthetic) return;
4040
_executable(context, element);
4141
}
@@ -49,15 +49,15 @@ class DefaultValueResolver {
4949
}
5050
}
5151

52-
void _executable(_Context context, ExecutableElement element) {
52+
void _executable(_Context context, ExecutableElementImpl element) {
5353
_ExecutableContext(
5454
enclosingContext: context,
5555
executableElement: element,
5656
scope: _scopeFromElement(element),
5757
).forEach(element.parameters, _parameter);
5858
}
5959

60-
void _extension(_UnitContext context, ExtensionElement element) {
60+
void _extension(_UnitContext context, ExtensionElementImpl element) {
6161
context.forEach(element.methods, _executable);
6262
}
6363

@@ -83,7 +83,7 @@ class DefaultValueResolver {
8383
context.scope,
8484
analysisOptions,
8585
enclosingClassElement: context.classElement?.asElement2,
86-
enclosingExecutableElement: context.executableElement,
86+
enclosingExecutableElement: context.executableElement.asElement2,
8787
);
8888
astResolver.resolveExpression(() => node.defaultValue!,
8989
contextType: contextType);
@@ -117,7 +117,7 @@ abstract class _Context {
117117

118118
class _ExecutableContext extends _Context {
119119
final _Context enclosingContext;
120-
final ExecutableElement executableElement;
120+
final ExecutableElementImpl executableElement;
121121
final Scope scope;
122122

123123
_ExecutableContext({

0 commit comments

Comments
 (0)