Skip to content

Commit 97176be

Browse files
jakemac53Commit Bot
authored and
Commit Bot
committed
add the local identifier type for parameters, add isStatic field to class members
Change-Id: I15d85fdc4a6b894e6ecda6716f9931e03a8278ae Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232961 Auto-Submit: Jake Macdonald <[email protected]> Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent 8d1eedc commit 97176be

File tree

8 files changed

+71
-10
lines changed

8 files changed

+71
-10
lines changed

pkg/_fe_analyzer_shared/lib/src/macros/api/introspection.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ abstract class Declaration {
8282
abstract class ClassMemberDeclaration implements Declaration {
8383
/// The class that defines this method.
8484
Identifier get definingClass;
85+
86+
/// Whether or not this is a static member.
87+
bool get isStatic;
8588
}
8689

8790
/// A declaration that defines a new type in the program.

pkg/_fe_analyzer_shared/lib/src/macros/executor.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ class ResolvedIdentifier extends Identifier {
261261
/// The types of identifiers.
262262
enum IdentifierKind {
263263
instanceMember,
264+
local, // Parameters, local variables, etc.
264265
staticInstanceMember,
265266
topLevelMember,
266267
}

pkg/_fe_analyzer_shared/lib/src/macros/executor_shared/builder_impls.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,18 +269,21 @@ List<DeclarationCode> _buildVariableAugmentations(
269269
if (getter != null) {
270270
augmentations.add(new DeclarationCode.fromParts([
271271
'augment ',
272+
if (declaration is FieldDeclaration && declaration.isStatic) 'static ',
272273
getter,
273274
]));
274275
}
275276
if (setter != null) {
276277
augmentations.add(new DeclarationCode.fromParts([
277278
'augment ',
279+
if (declaration is FieldDeclaration && declaration.isStatic) 'static ',
278280
setter,
279281
]));
280282
}
281283
if (initializer != null) {
282284
augmentations.add(new DeclarationCode.fromParts([
283285
'augment ',
286+
if (declaration is FieldDeclaration && declaration.isStatic) 'static ',
284287
if (declaration.isFinal) 'final ',
285288
declaration.type.code,
286289
' ',
@@ -310,6 +313,7 @@ DeclarationCode _buildFunctionAugmentation(
310313
declaration.definingClass.name,
311314
if (declaration.identifier.name.isNotEmpty) '.',
312315
] else ...[
316+
if (declaration is MethodDeclaration && declaration.isStatic) 'static ',
313317
declaration.returnType.code,
314318
' ',
315319
if (declaration.isOperator) 'operator ',

pkg/_fe_analyzer_shared/lib/src/macros/executor_shared/introspection_impls.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ class MethodDeclarationImpl extends FunctionDeclarationImpl
330330
@override
331331
RemoteInstanceKind get kind => RemoteInstanceKind.methodDeclaration;
332332

333+
@override
334+
final bool isStatic;
335+
333336
MethodDeclarationImpl({
334337
// Declaration fields
335338
required int id,
@@ -346,6 +349,7 @@ class MethodDeclarationImpl extends FunctionDeclarationImpl
346349
required List<TypeParameterDeclarationImpl> typeParameters,
347350
// Method fields
348351
required this.definingClass,
352+
required this.isStatic,
349353
}) : super(
350354
id: id,
351355
identifier: identifier,
@@ -367,6 +371,7 @@ class MethodDeclarationImpl extends FunctionDeclarationImpl
367371
if (serializationMode.isClient) return;
368372

369373
definingClass.serialize(serializer);
374+
serializer.addBool(isStatic);
370375
}
371376
}
372377

@@ -409,6 +414,7 @@ class ConstructorDeclarationImpl extends MethodDeclarationImpl
409414
returnType: returnType,
410415
typeParameters: typeParameters,
411416
definingClass: definingClass,
417+
isStatic: true,
412418
);
413419

414420
@override
@@ -466,6 +472,9 @@ class FieldDeclarationImpl extends VariableDeclarationImpl
466472
@override
467473
final IdentifierImpl definingClass;
468474

475+
@override
476+
final bool isStatic;
477+
469478
FieldDeclarationImpl({
470479
// Declaration fields
471480
required int id,
@@ -477,6 +486,7 @@ class FieldDeclarationImpl extends VariableDeclarationImpl
477486
required TypeAnnotationImpl type,
478487
// Field fields
479488
required this.definingClass,
489+
required this.isStatic,
480490
}) : super(
481491
id: id,
482492
identifier: identifier,
@@ -494,6 +504,7 @@ class FieldDeclarationImpl extends VariableDeclarationImpl
494504
if (serializationMode.isClient) return;
495505

496506
definingClass.serialize(serializer);
507+
serializer.addBool(isStatic);
497508
}
498509
}
499510

pkg/_fe_analyzer_shared/lib/src/macros/executor_shared/serialization_extensions.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ extension DeserializerExtensions on Deserializer {
139139
returnType: RemoteInstance.deserialize(this),
140140
typeParameters: (this..moveNext())._expectRemoteInstanceList(),
141141
definingClass: RemoteInstance.deserialize(this),
142+
isStatic: (this..moveNext()).expectBool(),
142143
);
143144

144145
ConstructorDeclaration _expectConstructorDeclaration(int id) =>
@@ -155,7 +156,13 @@ extension DeserializerExtensions on Deserializer {
155156
returnType: RemoteInstance.deserialize(this),
156157
typeParameters: (this..moveNext())._expectRemoteInstanceList(),
157158
definingClass: RemoteInstance.deserialize(this),
158-
isFactory: (this..moveNext()).expectBool(),
159+
// There is an extra boolean here representing the `isStatic` field
160+
// which we just skip past.
161+
isFactory: (this
162+
..moveNext()
163+
..expectBool()
164+
..moveNext())
165+
.expectBool(),
159166
);
160167

161168
VariableDeclaration _expectVariableDeclaration(int id) =>
@@ -176,6 +183,7 @@ extension DeserializerExtensions on Deserializer {
176183
isLate: (this..moveNext()).expectBool(),
177184
type: RemoteInstance.deserialize(this),
178185
definingClass: RemoteInstance.deserialize(this),
186+
isStatic: (this..moveNext()).expectBool(),
179187
);
180188

181189
ClassDeclaration _expectClassDeclaration(int id) => new ClassDeclarationImpl(

pkg/_fe_analyzer_shared/test/macros/executor_shared/serialization_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ void main() {
226226
positionalParameters: [barPositionalParam],
227227
returnType: fooType,
228228
typeParameters: [zapTypeParam],
229-
definingClass: fooType.identifier);
229+
definingClass: fooType.identifier,
230+
isStatic: false);
230231
expectSerializationEquality(method, mode);
231232
});
232233

@@ -273,6 +274,7 @@ void main() {
273274
isLate: false,
274275
type: barType,
275276
definingClass: fooType.identifier,
277+
isStatic: false,
276278
);
277279
expectSerializationEquality(bar, mode);
278280
});

pkg/_fe_analyzer_shared/test/macros/util.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ class Fixtures {
359359
isFinal: false,
360360
isLate: false,
361361
type: stringType,
362-
definingClass: myClassType.identifier);
362+
definingClass: myClassType.identifier,
363+
isStatic: false);
363364
static final myInterface = ClassDeclarationImpl(
364365
id: RemoteInstance.uniqueId,
365366
identifier: myInterfaceType.identifier,
@@ -381,7 +382,8 @@ class Fixtures {
381382
positionalParameters: [],
382383
returnType: stringType,
383384
typeParameters: [],
384-
definingClass: myClassType.identifier);
385+
definingClass: myClassType.identifier,
386+
isStatic: false);
385387
static final myMixin = ClassDeclarationImpl(
386388
id: RemoteInstance.uniqueId,
387389
identifier: myMixinType.identifier,

pkg/front_end/lib/src/fasta/kernel/macro.dart

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ class MacroApplications {
205205
macro.ResolvedIdentifier _resolveIdentifier(macro.Identifier identifier) {
206206
if (identifier is _IdentifierImpl) {
207207
MemberBuilder? memberBuilder = identifier.memberBuilder;
208+
TypeBuilder? typeBuilder = identifier.typeBuilder;
209+
FormalParameterBuilder? parameterBuilder = identifier.parameterBuilder;
208210
if (memberBuilder != null) {
209211
Uri? uri;
210212
String? staticScope;
@@ -225,9 +227,9 @@ class MacroApplications {
225227
name: identifier.name,
226228
staticScope: staticScope,
227229
uri: uri);
228-
} else {
230+
} else if (typeBuilder != null) {
229231
TypeDeclarationBuilder typeDeclarationBuilder =
230-
identifier.typeBuilder!.declaration!;
232+
typeBuilder.declaration!;
231233
Uri? uri;
232234
if (typeDeclarationBuilder is ClassBuilder) {
233235
uri = typeDeclarationBuilder.library.importUri;
@@ -239,6 +241,14 @@ class MacroApplications {
239241
name: identifier.name,
240242
staticScope: null,
241243
uri: uri);
244+
} else if (parameterBuilder != null) {
245+
return new macro.ResolvedIdentifier(
246+
kind: macro.IdentifierKind.local,
247+
name: identifier.name,
248+
staticScope: null,
249+
uri: null);
250+
} else {
251+
throw new StateError('Unable to resolve identifier $identifier');
242252
}
243253
} else {
244254
// TODO(johnniwinther): Use [_IdentifierImpl] for all identifiers.
@@ -433,20 +443,24 @@ class MacroApplications {
433443
for (FormalParameterBuilder formal in formals) {
434444
macro.TypeAnnotationImpl type =
435445
computeTypeAnnotation(builder.library, formal.type);
446+
macro.IdentifierImpl identifier =
447+
new _IdentifierImpl.forParameterBuilder(
448+
id: macro.RemoteInstance.uniqueId,
449+
name: formal.name,
450+
parameterBuilder: formal,
451+
libraryBuilder: builder.library);
436452
if (formal.isNamed) {
437453
namedParameters.add(new macro.ParameterDeclarationImpl(
438454
id: macro.RemoteInstance.uniqueId,
439-
identifier: new macro.IdentifierImpl(
440-
id: macro.RemoteInstance.uniqueId, name: formal.name),
455+
identifier: identifier,
441456
isRequired: formal.isNamedRequired,
442457
isNamed: true,
443458
type: type,
444459
));
445460
} else {
446461
positionalParameters.add(new macro.ParameterDeclarationImpl(
447462
id: macro.RemoteInstance.uniqueId,
448-
identifier: new macro.IdentifierImpl(
449-
id: macro.RemoteInstance.uniqueId, name: formal.name),
463+
identifier: identifier,
450464
isRequired: formal.isRequired,
451465
isNamed: false,
452466
type: type,
@@ -544,6 +558,7 @@ class MacroApplications {
544558
isGetter: builder.isGetter,
545559
isOperator: builder.isOperator,
546560
isSetter: builder.isSetter,
561+
isStatic: builder.isStatic,
547562
positionalParameters: parameters[0],
548563
namedParameters: parameters[1],
549564
returnType:
@@ -589,6 +604,7 @@ class MacroApplications {
589604
isExternal: builder.isExternal,
590605
isFinal: builder.isFinal,
591606
isLate: builder.isLate,
607+
isStatic: builder.isStatic,
592608
type: computeTypeAnnotation(builder.library, builder.type));
593609
} else {
594610
return new macro.VariableDeclarationImpl(
@@ -728,6 +744,7 @@ class _IdentifierImpl extends macro.IdentifierImpl {
728744
final MemberBuilder? memberBuilder;
729745
final TypeBuilder? typeBuilder;
730746
final LibraryBuilder libraryBuilder;
747+
final FormalParameterBuilder? parameterBuilder;
731748

732749
_IdentifierImpl.forTypeBuilder({
733750
required TypeBuilder this.typeBuilder,
@@ -736,6 +753,7 @@ class _IdentifierImpl extends macro.IdentifierImpl {
736753
required String name,
737754
}) : typeDeclarationBuilder = null,
738755
memberBuilder = null,
756+
parameterBuilder = null,
739757
super(id: id, name: name);
740758

741759
_IdentifierImpl.forTypeDeclarationBuilder({
@@ -745,6 +763,7 @@ class _IdentifierImpl extends macro.IdentifierImpl {
745763
required String name,
746764
}) : typeBuilder = null,
747765
memberBuilder = null,
766+
parameterBuilder = null,
748767
super(id: id, name: name);
749768

750769
_IdentifierImpl.forMemberBuilder(
@@ -753,8 +772,19 @@ class _IdentifierImpl extends macro.IdentifierImpl {
753772
required String name})
754773
: typeBuilder = null,
755774
typeDeclarationBuilder = null,
775+
parameterBuilder = null,
756776
libraryBuilder = memberBuilder.library,
757777
super(id: id, name: name);
778+
779+
_IdentifierImpl.forParameterBuilder({
780+
required FormalParameterBuilder this.parameterBuilder,
781+
required this.libraryBuilder,
782+
required int id,
783+
required String name,
784+
}) : typeBuilder = null,
785+
typeDeclarationBuilder = null,
786+
memberBuilder = null,
787+
super(id: id, name: name);
758788
}
759789

760790
class _StaticTypeImpl extends macro.StaticType {

0 commit comments

Comments
 (0)