Skip to content

Commit 6ae5ede

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate lib/src/wolf/
Change-Id: Id9f9ef36800368c29983c6bcbb65e00ac44e270a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396424 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent 1833bab commit 6ae5ede

File tree

5 files changed

+92
-75
lines changed

5 files changed

+92
-75
lines changed

pkg/analyzer/analyzer_use_new_elements.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ lib/src/utilities/extensions/ast.dart
166166
lib/src/utilities/extensions/element.dart
167167
lib/src/utilities/extensions/flutter.dart
168168
lib/src/utilities/extensions/library_element.dart
169-
lib/src/wolf/ir/ast_to_ir.dart
170-
lib/src/wolf/ir/call_descriptor.dart
171-
lib/src/wolf/ir/coded_ir.dart
172169
test/dart/sdk/build_sdk_summary_test.dart
173170
test/error/error_reporter_test.dart
174171
test/generated/element_resolver_test.dart

pkg/analyzer/lib/src/wolf/ir/ast_to_ir.dart

Lines changed: 61 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
import 'package:analyzer/dart/ast/ast.dart';
66
import 'package:analyzer/dart/ast/token.dart';
77
import 'package:analyzer/dart/ast/visitor.dart';
8-
import 'package:analyzer/dart/element/element.dart';
8+
import 'package:analyzer/dart/element/element2.dart';
99
import 'package:analyzer/dart/element/type.dart';
1010
import 'package:analyzer/dart/element/type_provider.dart';
1111
import 'package:analyzer/dart/element/type_system.dart';
12+
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
1213
import 'package:analyzer/src/wolf/ir/call_descriptor.dart';
1314
import 'package:analyzer/src/wolf/ir/coded_ir.dart';
1415
import 'package:analyzer/src/wolf/ir/ir.dart';
@@ -22,15 +23,20 @@ import 'package:analyzer/src/wolf/ir/ir.dart';
2223
/// (if provided). This should provide enough information to allow the caller to
2324
/// map individual instructions to the AST nodes that spawned them.
2425
CodedIRContainer astToIR(
25-
ExecutableElement executableElement, FunctionBody functionBody,
26-
{required TypeProvider typeProvider,
27-
required TypeSystem typeSystem,
28-
AstToIREventListener? eventListener}) {
26+
ExecutableElement2 executableElement,
27+
FunctionBody functionBody, {
28+
required TypeProvider typeProvider,
29+
required TypeSystem typeSystem,
30+
required InheritanceManager3 inheritanceManager,
31+
AstToIREventListener? eventListener,
32+
}) {
2933
eventListener ??= AstToIREventListener();
3034
var visitor = _AstToIRVisitor(
31-
typeSystem: typeSystem,
32-
typeProvider: typeProvider,
33-
eventListener: eventListener);
35+
typeSystem: typeSystem,
36+
typeProvider: typeProvider,
37+
inheritanceManager: inheritanceManager,
38+
eventListener: eventListener,
39+
);
3440
eventListener._visitor = visitor;
3541
visitor.visitFunctionBody(executableElement, functionBody,
3642
isInstanceMember: !executableElement.isStatic);
@@ -68,9 +74,10 @@ base class AstToIREventListener {
6874
///
6975
/// The remaining visit methods simply return `null`.
7076
class _AstToIRVisitor extends ThrowingAstVisitor<_LValueTemplates> {
71-
final TypeSystem typeSystem;
7277
final TypeProvider typeProvider;
73-
final LibraryElement coreLibrary;
78+
final TypeSystem typeSystem;
79+
final InheritanceManager3 inheritanceManager;
80+
final LibraryElement2 coreLibrary;
7481
final AstToIREventListener eventListener;
7582

7683
/// For each enclosing flow control construct that may be the target of a
@@ -94,18 +101,19 @@ class _AstToIRVisitor extends ThrowingAstVisitor<_LValueTemplates> {
94101
final functionNestingStack = <int>[];
95102

96103
final ir = CodedIRWriter();
97-
final Map<VariableElement, int> locals = {};
104+
final Map<VariableElement2, int> locals = {};
98105
late final oneArgument = ir.encodeArgumentNames([null]);
99106
late final twoArguments = ir.encodeArgumentNames([null, null]);
100107
late final null_ = ir.encodeLiteral(null);
101108
late final one = ir.encodeLiteral(1);
102109
late final stackIndices101 = ir.encodeStackIndices(const [1, 0, 1]);
103110

104-
_AstToIRVisitor(
105-
{required this.typeSystem,
106-
required this.typeProvider,
107-
required this.eventListener})
108-
: coreLibrary = typeProvider.objectElement.library;
111+
_AstToIRVisitor({
112+
required this.typeProvider,
113+
required this.typeSystem,
114+
required this.inheritanceManager,
115+
required this.eventListener,
116+
}) : coreLibrary = typeProvider.objectElement2.library2;
109117

110118
/// If [node] is used as the target of a [CompoundAssignmentExpression],
111119
/// returns the [CompoundAssignmentExpression].
@@ -164,7 +172,7 @@ class _AstToIRVisitor extends ThrowingAstVisitor<_LValueTemplates> {
164172
return result;
165173
}
166174

167-
void instanceCall(MethodElement? staticElement, String name,
175+
void instanceCall(MethodElement2? staticElement, String name,
168176
List<DartType> typeArguments, ArgumentNamesRef argumentNames) {
169177
if (staticElement == null) throw UnimplementedError('TODO(paulberry)');
170178
ir.call(
@@ -173,27 +181,29 @@ class _AstToIRVisitor extends ThrowingAstVisitor<_LValueTemplates> {
173181
argumentNames);
174182
}
175183

176-
void instanceGet(PropertyAccessorElement? staticElement, String name) {
184+
void instanceGet(PropertyAccessorElement2? staticElement, String name) {
177185
if (staticElement == null) {
178186
throw UnimplementedError('TODO(paulberry): dynamic instance get');
179187
}
180188
ir.call(ir.encodeCallDescriptor(ElementCallDescriptor(staticElement)),
181189
oneArgument);
182190
}
183191

184-
void instanceSet(PropertyAccessorElement? staticElement, String name) {
192+
void instanceSet(PropertyAccessorElement2? staticElement, String name) {
185193
if (staticElement == null) {
186194
throw UnimplementedError('TODO(paulberry): dynamic instance set');
187195
}
188196
ir.call(ir.encodeCallDescriptor(ElementCallDescriptor(staticElement)),
189197
twoArguments);
190198
}
191199

192-
MethodElement lookupToString(DartType? type) {
200+
MethodElement2 lookupToString(DartType? type) {
193201
var class_ =
194-
type is InterfaceType ? type.element : typeProvider.objectElement;
195-
return class_.augmented
196-
.lookUpMethod(name: 'toString', library: coreLibrary)!;
202+
type is InterfaceType ? type.element3 : typeProvider.objectElement2;
203+
return inheritanceManager.getMember4(
204+
class_,
205+
Name.forLibrary(coreLibrary, 'toString'),
206+
) as MethodElement2;
197207
}
198208

199209
/// Performs a null check that is part of a null shorting expression.
@@ -307,7 +317,7 @@ class _AstToIRVisitor extends ThrowingAstVisitor<_LValueTemplates> {
307317
// Stack: lValue oldValue rhs
308318
var lexeme = node.operator.lexeme;
309319
assert(lexeme.endsWith('='));
310-
instanceCall(node.staticElement, lexeme.substring(0, lexeme.length - 1),
320+
instanceCall(node.element, lexeme.substring(0, lexeme.length - 1),
311321
const [], twoArguments);
312322
// Stack: lValue newValue
313323
eventListener.onEnterNode(node.leftHandSide);
@@ -425,7 +435,7 @@ class _AstToIRVisitor extends ThrowingAstVisitor<_LValueTemplates> {
425435
// Stack: lhs
426436
dispatchNode(node.rightOperand);
427437
// Stack: lhs rhs
428-
instanceCall(node.staticElement, tokenType.lexeme, [], twoArguments);
438+
instanceCall(node.element, tokenType.lexeme, [], twoArguments);
429439
// Stack: result
430440
default:
431441
throw UnimplementedError('TODO(paulberry): $node');
@@ -590,13 +600,13 @@ class _AstToIRVisitor extends ThrowingAstVisitor<_LValueTemplates> {
590600
}
591601
}
592602

593-
void visitFunctionBody(ExecutableElement element, FunctionBody body,
603+
void visitFunctionBody(ExecutableElement2 element, FunctionBody body,
594604
{required bool isInstanceMember}) {
595605
int count = 0;
596606
if (isInstanceMember) {
597607
count++;
598608
}
599-
for (var element in element.parameters) {
609+
for (var element in element.formalParameters) {
600610
assert(!locals.containsKey(element));
601611
var localIndex = ir.localVariableCount + count;
602612
locals[element] = localIndex;
@@ -704,18 +714,18 @@ class _AstToIRVisitor extends ThrowingAstVisitor<_LValueTemplates> {
704714
var previousNestingLevel = ir.nestingLevel;
705715
var argumentNames = <String?>[];
706716
var target = node.target;
707-
var methodElement = node.methodName.staticElement;
717+
var methodElement = node.methodName.element;
708718
switch (methodElement) {
709-
case FunctionElement(enclosingElement3: CompilationUnitElement()):
719+
case TopLevelFunctionElement():
710720
assert(!node.isNullAware);
711721
_handleInvocationArgs(
712722
argumentList: node.argumentList,
713723
argumentNames: argumentNames,
714724
isNullAware: false,
715725
previousNestingLevel: previousNestingLevel);
716726
// Stack: arguments
717-
if (methodElement.library.isDartCore &&
718-
methodElement.name == 'identical') {
727+
if (methodElement.library2!.isDartCore &&
728+
methodElement.name3 == 'identical') {
719729
ir.identical();
720730
} else {
721731
ir.call(
@@ -724,7 +734,7 @@ class _AstToIRVisitor extends ThrowingAstVisitor<_LValueTemplates> {
724734
ir.encodeArgumentNames(argumentNames));
725735
}
726736
// Stack: result
727-
case MethodElement(isStatic: false):
737+
case MethodElement2(isStatic: false):
728738
if (target == null) {
729739
assert(!node.isNullAware);
730740
this_();
@@ -743,7 +753,7 @@ class _AstToIRVisitor extends ThrowingAstVisitor<_LValueTemplates> {
743753
instanceCall(methodElement, node.methodName.name,
744754
node.typeArgumentTypes!, ir.encodeArgumentNames(argumentNames));
745755
// Stack: BLOCK(1)? result
746-
case MethodElement(isStatic: true):
756+
case MethodElement2(isStatic: true):
747757
assert(!node.isNullAware);
748758
_handleInvocationArgs(
749759
argumentList: node.argumentList,
@@ -788,8 +798,7 @@ class _AstToIRVisitor extends ThrowingAstVisitor<_LValueTemplates> {
788798
eventListener.onExitNode();
789799
ir.literal(one);
790800
// Stack: oldValue lValue oldValue 1
791-
instanceCall(
792-
node.staticElement, node.operator.lexeme[0], [], twoArguments);
801+
instanceCall(node.element, node.operator.lexeme[0], [], twoArguments);
793802
// Stack: oldValue lValue newValue
794803
lValueTemplates.write(this);
795804
// Stack: oldValue newValue
@@ -803,10 +812,10 @@ class _AstToIRVisitor extends ThrowingAstVisitor<_LValueTemplates> {
803812
@override
804813
_LValueTemplates? visitPrefixedIdentifier(PrefixedIdentifier node) {
805814
var prefix = node.prefix;
806-
var prefixElement = prefix.staticElement;
815+
var prefixElement = prefix.element;
807816
switch (prefixElement) {
808-
case ParameterElement():
809-
case LocalVariableElement():
817+
case FormalParameterElement():
818+
case LocalVariableElement2():
810819
dispatchNode(prefix);
811820
// Stack: prefix
812821
return _PropertyAccessTemplates(node.identifier);
@@ -832,8 +841,7 @@ class _AstToIRVisitor extends ThrowingAstVisitor<_LValueTemplates> {
832841
// Stack: lValue oldValue
833842
ir.literal(one);
834843
// Stack: lValue oldValue 1
835-
instanceCall(
836-
node.staticElement, node.operator.lexeme[0], [], twoArguments);
844+
instanceCall(node.element, node.operator.lexeme[0], [], twoArguments);
837845
// Stack: lValue newValue
838846
eventListener.onEnterNode(node.operand);
839847
lValueTemplates.write(this);
@@ -872,17 +880,17 @@ class _AstToIRVisitor extends ThrowingAstVisitor<_LValueTemplates> {
872880

873881
@override
874882
_LValueTemplates visitSimpleIdentifier(SimpleIdentifier node) {
875-
var staticElement = node.staticElement;
883+
var staticElement = node.element;
876884
if (staticElement == null) {
877885
if (assignmentTargeting(node) case var assignment?) {
878-
staticElement = assignment.readElement ?? assignment.writeElement;
886+
staticElement = assignment.readElement2 ?? assignment.writeElement2;
879887
}
880888
}
881889
switch (staticElement) {
882-
case ParameterElement():
883-
case LocalVariableElement():
890+
case FormalParameterElement():
891+
case LocalVariableElement2():
884892
return _LocalTemplates(locals[staticElement]!);
885-
case PropertyAccessorElement(isStatic: false):
893+
case PropertyAccessorElement2(isStatic: false):
886894
this_();
887895
// Stack: this
888896
return _PropertyAccessTemplates(node);
@@ -914,8 +922,9 @@ class _AstToIRVisitor extends ThrowingAstVisitor<_LValueTemplates> {
914922

915923
@override
916924
Null visitVariableDeclarationList(VariableDeclarationList variables) {
917-
for (var VariableDeclaration(:initializer, :declaredElement!)
918-
in variables.variables) {
925+
for (var variable in variables.variables) {
926+
var initializer = variable.initializer;
927+
var declaredElement = variable.declaredFragment!.element;
919928
assert(!locals.containsKey(declaredElement));
920929
var localIndex = ir.localVariableCount;
921930
locals[declaredElement] = localIndex;
@@ -1104,9 +1113,9 @@ class _PropertyAccessTemplates extends _LValueTemplates {
11041113
void read(_AstToIRVisitor visitor) {
11051114
// Stack: target
11061115
visitor.instanceGet(
1107-
(property.staticElement ??
1108-
visitor.assignmentTargeting(property)?.readElement)
1109-
as PropertyAccessorElement?,
1116+
(property.element ??
1117+
visitor.assignmentTargeting(property)?.readElement2)
1118+
as PropertyAccessorElement2?,
11101119
property.name);
11111120
// Stack: value
11121121
}
@@ -1144,8 +1153,8 @@ class _PropertyAccessTemplates extends _LValueTemplates {
11441153
visitor.ir.shuffle(2, visitor.stackIndices101);
11451154
// Stack: value target value
11461155
visitor.instanceSet(
1147-
visitor.assignmentTargeting(property)!.writeElement
1148-
as PropertyAccessorElement?,
1156+
visitor.assignmentTargeting(property)!.writeElement2
1157+
as PropertyAccessorElement2?,
11491158
property.name);
11501159
// Stack: value returnValue
11511160
visitor.ir.drop();

pkg/analyzer/lib/src/wolf/ir/call_descriptor.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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-
import 'package:analyzer/dart/element/element.dart';
5+
import 'package:analyzer/dart/element/element2.dart';
66
import 'package:analyzer/dart/element/type.dart';
77

88
/// The target of a `call` instruction in the IR.
@@ -14,20 +14,20 @@ sealed class CallDescriptor {
1414
/// Call descriptor for a call that resolves to a specific element (i.e., a
1515
/// non-dynamic call).
1616
class ElementCallDescriptor extends CallDescriptor {
17-
final ExecutableElement element;
17+
final ExecutableElement2 element;
1818

1919
@override
2020
final List<DartType> typeArguments;
2121

2222
ElementCallDescriptor(this.element, {this.typeArguments = const []});
2323

2424
@override
25-
String get name => element.name;
25+
String get name => element.lookupName!;
2626

2727
@override
28-
String toString() => switch (element.enclosingElement3) {
29-
InstanceElement(name: var typeName) =>
30-
'${typeName ?? '<unnamed>'}.${element.name}',
31-
_ => element.name
28+
String toString() => switch (element.enclosingElement2) {
29+
InstanceElement2(name3: var typeName) =>
30+
'${typeName ?? '<unnamed>'}.${element.name3!}',
31+
_ => element.name3!
3232
};
3333
}

pkg/analyzer/lib/src/wolf/ir/coded_ir.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CodedIRContainer extends BaseIRContainer {
3030

3131
@override
3232
int countParameters(TypeRef type) =>
33-
(decodeType(type) as FunctionType).parameters.length;
33+
(decodeType(type) as FunctionType).formalParameters.length;
3434

3535
CallDescriptor decodeCallDescriptor(CallDescriptorRef callDescriptorRef) =>
3636
_callDescriptorTable[callDescriptorRef.index];

0 commit comments

Comments
 (0)