mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 02:27:39 +00:00
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 <jakemac@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
parent
8d1eedca64
commit
97176be3d4
|
@ -82,6 +82,9 @@ abstract class Declaration {
|
|||
abstract class ClassMemberDeclaration implements Declaration {
|
||||
/// The class that defines this method.
|
||||
Identifier get definingClass;
|
||||
|
||||
/// Whether or not this is a static member.
|
||||
bool get isStatic;
|
||||
}
|
||||
|
||||
/// A declaration that defines a new type in the program.
|
||||
|
|
|
@ -261,6 +261,7 @@ class ResolvedIdentifier extends Identifier {
|
|||
/// The types of identifiers.
|
||||
enum IdentifierKind {
|
||||
instanceMember,
|
||||
local, // Parameters, local variables, etc.
|
||||
staticInstanceMember,
|
||||
topLevelMember,
|
||||
}
|
||||
|
|
|
@ -269,18 +269,21 @@ List<DeclarationCode> _buildVariableAugmentations(
|
|||
if (getter != null) {
|
||||
augmentations.add(new DeclarationCode.fromParts([
|
||||
'augment ',
|
||||
if (declaration is FieldDeclaration && declaration.isStatic) 'static ',
|
||||
getter,
|
||||
]));
|
||||
}
|
||||
if (setter != null) {
|
||||
augmentations.add(new DeclarationCode.fromParts([
|
||||
'augment ',
|
||||
if (declaration is FieldDeclaration && declaration.isStatic) 'static ',
|
||||
setter,
|
||||
]));
|
||||
}
|
||||
if (initializer != null) {
|
||||
augmentations.add(new DeclarationCode.fromParts([
|
||||
'augment ',
|
||||
if (declaration is FieldDeclaration && declaration.isStatic) 'static ',
|
||||
if (declaration.isFinal) 'final ',
|
||||
declaration.type.code,
|
||||
' ',
|
||||
|
@ -310,6 +313,7 @@ DeclarationCode _buildFunctionAugmentation(
|
|||
declaration.definingClass.name,
|
||||
if (declaration.identifier.name.isNotEmpty) '.',
|
||||
] else ...[
|
||||
if (declaration is MethodDeclaration && declaration.isStatic) 'static ',
|
||||
declaration.returnType.code,
|
||||
' ',
|
||||
if (declaration.isOperator) 'operator ',
|
||||
|
|
|
@ -330,6 +330,9 @@ class MethodDeclarationImpl extends FunctionDeclarationImpl
|
|||
@override
|
||||
RemoteInstanceKind get kind => RemoteInstanceKind.methodDeclaration;
|
||||
|
||||
@override
|
||||
final bool isStatic;
|
||||
|
||||
MethodDeclarationImpl({
|
||||
// Declaration fields
|
||||
required int id,
|
||||
|
@ -346,6 +349,7 @@ class MethodDeclarationImpl extends FunctionDeclarationImpl
|
|||
required List<TypeParameterDeclarationImpl> typeParameters,
|
||||
// Method fields
|
||||
required this.definingClass,
|
||||
required this.isStatic,
|
||||
}) : super(
|
||||
id: id,
|
||||
identifier: identifier,
|
||||
|
@ -367,6 +371,7 @@ class MethodDeclarationImpl extends FunctionDeclarationImpl
|
|||
if (serializationMode.isClient) return;
|
||||
|
||||
definingClass.serialize(serializer);
|
||||
serializer.addBool(isStatic);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -409,6 +414,7 @@ class ConstructorDeclarationImpl extends MethodDeclarationImpl
|
|||
returnType: returnType,
|
||||
typeParameters: typeParameters,
|
||||
definingClass: definingClass,
|
||||
isStatic: true,
|
||||
);
|
||||
|
||||
@override
|
||||
|
@ -466,6 +472,9 @@ class FieldDeclarationImpl extends VariableDeclarationImpl
|
|||
@override
|
||||
final IdentifierImpl definingClass;
|
||||
|
||||
@override
|
||||
final bool isStatic;
|
||||
|
||||
FieldDeclarationImpl({
|
||||
// Declaration fields
|
||||
required int id,
|
||||
|
@ -477,6 +486,7 @@ class FieldDeclarationImpl extends VariableDeclarationImpl
|
|||
required TypeAnnotationImpl type,
|
||||
// Field fields
|
||||
required this.definingClass,
|
||||
required this.isStatic,
|
||||
}) : super(
|
||||
id: id,
|
||||
identifier: identifier,
|
||||
|
@ -494,6 +504,7 @@ class FieldDeclarationImpl extends VariableDeclarationImpl
|
|||
if (serializationMode.isClient) return;
|
||||
|
||||
definingClass.serialize(serializer);
|
||||
serializer.addBool(isStatic);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -139,6 +139,7 @@ extension DeserializerExtensions on Deserializer {
|
|||
returnType: RemoteInstance.deserialize(this),
|
||||
typeParameters: (this..moveNext())._expectRemoteInstanceList(),
|
||||
definingClass: RemoteInstance.deserialize(this),
|
||||
isStatic: (this..moveNext()).expectBool(),
|
||||
);
|
||||
|
||||
ConstructorDeclaration _expectConstructorDeclaration(int id) =>
|
||||
|
@ -155,7 +156,13 @@ extension DeserializerExtensions on Deserializer {
|
|||
returnType: RemoteInstance.deserialize(this),
|
||||
typeParameters: (this..moveNext())._expectRemoteInstanceList(),
|
||||
definingClass: RemoteInstance.deserialize(this),
|
||||
isFactory: (this..moveNext()).expectBool(),
|
||||
// There is an extra boolean here representing the `isStatic` field
|
||||
// which we just skip past.
|
||||
isFactory: (this
|
||||
..moveNext()
|
||||
..expectBool()
|
||||
..moveNext())
|
||||
.expectBool(),
|
||||
);
|
||||
|
||||
VariableDeclaration _expectVariableDeclaration(int id) =>
|
||||
|
@ -176,6 +183,7 @@ extension DeserializerExtensions on Deserializer {
|
|||
isLate: (this..moveNext()).expectBool(),
|
||||
type: RemoteInstance.deserialize(this),
|
||||
definingClass: RemoteInstance.deserialize(this),
|
||||
isStatic: (this..moveNext()).expectBool(),
|
||||
);
|
||||
|
||||
ClassDeclaration _expectClassDeclaration(int id) => new ClassDeclarationImpl(
|
||||
|
|
|
@ -226,7 +226,8 @@ void main() {
|
|||
positionalParameters: [barPositionalParam],
|
||||
returnType: fooType,
|
||||
typeParameters: [zapTypeParam],
|
||||
definingClass: fooType.identifier);
|
||||
definingClass: fooType.identifier,
|
||||
isStatic: false);
|
||||
expectSerializationEquality(method, mode);
|
||||
});
|
||||
|
||||
|
@ -273,6 +274,7 @@ void main() {
|
|||
isLate: false,
|
||||
type: barType,
|
||||
definingClass: fooType.identifier,
|
||||
isStatic: false,
|
||||
);
|
||||
expectSerializationEquality(bar, mode);
|
||||
});
|
||||
|
|
|
@ -359,7 +359,8 @@ class Fixtures {
|
|||
isFinal: false,
|
||||
isLate: false,
|
||||
type: stringType,
|
||||
definingClass: myClassType.identifier);
|
||||
definingClass: myClassType.identifier,
|
||||
isStatic: false);
|
||||
static final myInterface = ClassDeclarationImpl(
|
||||
id: RemoteInstance.uniqueId,
|
||||
identifier: myInterfaceType.identifier,
|
||||
|
@ -381,7 +382,8 @@ class Fixtures {
|
|||
positionalParameters: [],
|
||||
returnType: stringType,
|
||||
typeParameters: [],
|
||||
definingClass: myClassType.identifier);
|
||||
definingClass: myClassType.identifier,
|
||||
isStatic: false);
|
||||
static final myMixin = ClassDeclarationImpl(
|
||||
id: RemoteInstance.uniqueId,
|
||||
identifier: myMixinType.identifier,
|
||||
|
|
|
@ -205,6 +205,8 @@ class MacroApplications {
|
|||
macro.ResolvedIdentifier _resolveIdentifier(macro.Identifier identifier) {
|
||||
if (identifier is _IdentifierImpl) {
|
||||
MemberBuilder? memberBuilder = identifier.memberBuilder;
|
||||
TypeBuilder? typeBuilder = identifier.typeBuilder;
|
||||
FormalParameterBuilder? parameterBuilder = identifier.parameterBuilder;
|
||||
if (memberBuilder != null) {
|
||||
Uri? uri;
|
||||
String? staticScope;
|
||||
|
@ -225,9 +227,9 @@ class MacroApplications {
|
|||
name: identifier.name,
|
||||
staticScope: staticScope,
|
||||
uri: uri);
|
||||
} else {
|
||||
} else if (typeBuilder != null) {
|
||||
TypeDeclarationBuilder typeDeclarationBuilder =
|
||||
identifier.typeBuilder!.declaration!;
|
||||
typeBuilder.declaration!;
|
||||
Uri? uri;
|
||||
if (typeDeclarationBuilder is ClassBuilder) {
|
||||
uri = typeDeclarationBuilder.library.importUri;
|
||||
|
@ -239,6 +241,14 @@ class MacroApplications {
|
|||
name: identifier.name,
|
||||
staticScope: null,
|
||||
uri: uri);
|
||||
} else if (parameterBuilder != null) {
|
||||
return new macro.ResolvedIdentifier(
|
||||
kind: macro.IdentifierKind.local,
|
||||
name: identifier.name,
|
||||
staticScope: null,
|
||||
uri: null);
|
||||
} else {
|
||||
throw new StateError('Unable to resolve identifier $identifier');
|
||||
}
|
||||
} else {
|
||||
// TODO(johnniwinther): Use [_IdentifierImpl] for all identifiers.
|
||||
|
@ -433,11 +443,16 @@ class MacroApplications {
|
|||
for (FormalParameterBuilder formal in formals) {
|
||||
macro.TypeAnnotationImpl type =
|
||||
computeTypeAnnotation(builder.library, formal.type);
|
||||
macro.IdentifierImpl identifier =
|
||||
new _IdentifierImpl.forParameterBuilder(
|
||||
id: macro.RemoteInstance.uniqueId,
|
||||
name: formal.name,
|
||||
parameterBuilder: formal,
|
||||
libraryBuilder: builder.library);
|
||||
if (formal.isNamed) {
|
||||
namedParameters.add(new macro.ParameterDeclarationImpl(
|
||||
id: macro.RemoteInstance.uniqueId,
|
||||
identifier: new macro.IdentifierImpl(
|
||||
id: macro.RemoteInstance.uniqueId, name: formal.name),
|
||||
identifier: identifier,
|
||||
isRequired: formal.isNamedRequired,
|
||||
isNamed: true,
|
||||
type: type,
|
||||
|
@ -445,8 +460,7 @@ class MacroApplications {
|
|||
} else {
|
||||
positionalParameters.add(new macro.ParameterDeclarationImpl(
|
||||
id: macro.RemoteInstance.uniqueId,
|
||||
identifier: new macro.IdentifierImpl(
|
||||
id: macro.RemoteInstance.uniqueId, name: formal.name),
|
||||
identifier: identifier,
|
||||
isRequired: formal.isRequired,
|
||||
isNamed: false,
|
||||
type: type,
|
||||
|
@ -544,6 +558,7 @@ class MacroApplications {
|
|||
isGetter: builder.isGetter,
|
||||
isOperator: builder.isOperator,
|
||||
isSetter: builder.isSetter,
|
||||
isStatic: builder.isStatic,
|
||||
positionalParameters: parameters[0],
|
||||
namedParameters: parameters[1],
|
||||
returnType:
|
||||
|
@ -589,6 +604,7 @@ class MacroApplications {
|
|||
isExternal: builder.isExternal,
|
||||
isFinal: builder.isFinal,
|
||||
isLate: builder.isLate,
|
||||
isStatic: builder.isStatic,
|
||||
type: computeTypeAnnotation(builder.library, builder.type));
|
||||
} else {
|
||||
return new macro.VariableDeclarationImpl(
|
||||
|
@ -728,6 +744,7 @@ class _IdentifierImpl extends macro.IdentifierImpl {
|
|||
final MemberBuilder? memberBuilder;
|
||||
final TypeBuilder? typeBuilder;
|
||||
final LibraryBuilder libraryBuilder;
|
||||
final FormalParameterBuilder? parameterBuilder;
|
||||
|
||||
_IdentifierImpl.forTypeBuilder({
|
||||
required TypeBuilder this.typeBuilder,
|
||||
|
@ -736,6 +753,7 @@ class _IdentifierImpl extends macro.IdentifierImpl {
|
|||
required String name,
|
||||
}) : typeDeclarationBuilder = null,
|
||||
memberBuilder = null,
|
||||
parameterBuilder = null,
|
||||
super(id: id, name: name);
|
||||
|
||||
_IdentifierImpl.forTypeDeclarationBuilder({
|
||||
|
@ -745,6 +763,7 @@ class _IdentifierImpl extends macro.IdentifierImpl {
|
|||
required String name,
|
||||
}) : typeBuilder = null,
|
||||
memberBuilder = null,
|
||||
parameterBuilder = null,
|
||||
super(id: id, name: name);
|
||||
|
||||
_IdentifierImpl.forMemberBuilder(
|
||||
|
@ -753,8 +772,19 @@ class _IdentifierImpl extends macro.IdentifierImpl {
|
|||
required String name})
|
||||
: typeBuilder = null,
|
||||
typeDeclarationBuilder = null,
|
||||
parameterBuilder = null,
|
||||
libraryBuilder = memberBuilder.library,
|
||||
super(id: id, name: name);
|
||||
|
||||
_IdentifierImpl.forParameterBuilder({
|
||||
required FormalParameterBuilder this.parameterBuilder,
|
||||
required this.libraryBuilder,
|
||||
required int id,
|
||||
required String name,
|
||||
}) : typeBuilder = null,
|
||||
typeDeclarationBuilder = null,
|
||||
memberBuilder = null,
|
||||
super(id: id, name: name);
|
||||
}
|
||||
|
||||
class _StaticTypeImpl extends macro.StaticType {
|
||||
|
|
Loading…
Reference in a new issue