[cfe] Add synthesized this to view instance methods

+ generate getters.

Change-Id: Id873e8e6c3f8d64a845b211f18616d807302f180
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273180
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
Johnni Winther 2022-12-01 11:53:17 +00:00 committed by Commit Queue
parent 55b4542dab
commit 05c0f5ca9a
10 changed files with 119 additions and 12 deletions

View file

@ -1947,8 +1947,10 @@ class OutlineBuilder extends StackListenerImpl {
bool isStatic = (modifiers & staticMask) != 0;
if (constructorName == null &&
!isStatic &&
libraryBuilder.currentTypeParameterScopeBuilder.kind ==
TypeParameterScopeKind.extensionDeclaration) {
(libraryBuilder.currentTypeParameterScopeBuilder.kind ==
TypeParameterScopeKind.extensionDeclaration ||
libraryBuilder.currentTypeParameterScopeBuilder.kind ==
TypeParameterScopeKind.viewDeclaration)) {
TypeParameterScopeBuilder extension =
libraryBuilder.currentTypeParameterScopeBuilder;
Map<TypeVariableBuilder, TypeBuilder>? substitution;
@ -1975,7 +1977,27 @@ class OutlineBuilder extends StackListenerImpl {
}
}
List<FormalParameterBuilder> synthesizedFormals = [];
TypeBuilder thisType = extension.extensionThisType;
TypeBuilder thisType;
if (extension.kind == TypeParameterScopeKind.extensionDeclaration) {
thisType = extension.extensionThisType;
} else {
thisType = libraryBuilder.addNamedType(
extension.name,
const NullabilityBuilder.omitted(),
typeVariables != null
? new List<TypeBuilder>.generate(
typeVariables.length,
(int index) =>
new NamedTypeBuilder.fromTypeDeclarationBuilder(
typeVariables![index],
const NullabilityBuilder.omitted(),
instanceTypeVariableAccess:
InstanceTypeVariableAccessState.Allowed))
: null,
charOffset,
instanceTypeVariableAccess:
InstanceTypeVariableAccessState.Allowed);
}
if (substitution != null) {
List<NamedTypeBuilder> unboundTypes = [];
List<TypeVariableBuilder> unboundTypeVariables = [];

View file

@ -114,9 +114,7 @@ class SourceProcedureBuilder extends SourceFunctionBuilderImpl
..isNonNullableByDefault = libraryBuilder.isNonNullableByDefault;
nameScheme.getProcedureMemberName(kind, name).attachMember(_procedure);
this.asyncModifier = asyncModifier;
if ((isExtensionInstanceMember
// TODO(johnniwinther): Support view tear offs.
/* || isViewInstanceMember*/) &&
if ((isExtensionInstanceMember || isViewInstanceMember) &&
kind == ProcedureKind.Method) {
_extensionTearOff = new Procedure(
dummyName, ProcedureKind.Method, new FunctionNode(null),

View file

@ -5,6 +5,13 @@
view class Class {
final int it;
void instanceMethod() {}
static void staticMethod() {}
}
view class GenericClass<T> {
final T it;
void instanceMethod() {}
static void staticMethod() {}
}

View file

@ -4,7 +4,19 @@ import "dart:core" as core;
view Class /* representationType = core::int */ {
method instanceMethod = self::Class|instanceMethod;
tearoff instanceMethod = self::Class|get#instanceMethod;
static method staticMethod = self::Class|staticMethod;
}
static method Class|instanceMethod() → void {}
view GenericClass<T extends core::Object? = dynamic> /* representationType = T% */ {
method instanceMethod = self::GenericClass|instanceMethod;
tearoff instanceMethod = self::GenericClass|get#instanceMethod;
static method staticMethod = self::GenericClass|staticMethod;
}
static method Class|instanceMethod(lowered final self::Class #this) → void {}
static method Class|get#instanceMethod(lowered final self::Class #this) → () → void
return () → void => self::Class|instanceMethod(#this);
static method Class|staticMethod() → void {}
static method GenericClass|instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod::T%> #this) → void {}
static method GenericClass|get#instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|get#instanceMethod::T%> #this) → () → void
return () → void => self::GenericClass|instanceMethod<self::GenericClass|get#instanceMethod::T%>(#this);
static method GenericClass|staticMethod() → void {}

View file

@ -4,7 +4,19 @@ import "dart:core" as core;
view Class /* representationType = core::int */ {
method instanceMethod = self::Class|instanceMethod;
tearoff instanceMethod = self::Class|get#instanceMethod;
static method staticMethod = self::Class|staticMethod;
}
static method Class|instanceMethod() → void {}
view GenericClass<T extends core::Object? = dynamic> /* representationType = T% */ {
method instanceMethod = self::GenericClass|instanceMethod;
tearoff instanceMethod = self::GenericClass|get#instanceMethod;
static method staticMethod = self::GenericClass|staticMethod;
}
static method Class|instanceMethod(lowered final self::Class #this) → void {}
static method Class|get#instanceMethod(lowered final self::Class #this) → () → void
return () → void => self::Class|instanceMethod(#this);
static method Class|staticMethod() → void {}
static method GenericClass|instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod::T%> #this) → void {}
static method GenericClass|get#instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|get#instanceMethod::T%> #this) → () → void
return () → void => self::GenericClass|instanceMethod<self::GenericClass|get#instanceMethod::T%>(#this);
static method GenericClass|staticMethod() → void {}

View file

@ -4,3 +4,9 @@ class Class {
void instanceMethod() {}
static void staticMethod() {}
}
view
class GenericClass<T> {
final T it;
void instanceMethod() {}
static void staticMethod() {}
}

View file

@ -4,7 +4,19 @@ import "dart:core" as core;
view Class /* representationType = core::int */ {
method instanceMethod = self::Class|instanceMethod;
tearoff instanceMethod = self::Class|get#instanceMethod;
static method staticMethod = self::Class|staticMethod;
}
static method Class|instanceMethod() → void {}
view GenericClass<T extends core::Object? = dynamic> /* representationType = T% */ {
method instanceMethod = self::GenericClass|instanceMethod;
tearoff instanceMethod = self::GenericClass|get#instanceMethod;
static method staticMethod = self::GenericClass|staticMethod;
}
static method Class|instanceMethod(lowered final self::Class #this) → void {}
static method Class|get#instanceMethod(lowered final self::Class #this) → () → void
return () → void => self::Class|instanceMethod(#this);
static method Class|staticMethod() → void {}
static method GenericClass|instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod::T%> #this) → void {}
static method GenericClass|get#instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|get#instanceMethod::T%> #this) → () → void
return () → void => self::GenericClass|instanceMethod<self::GenericClass|get#instanceMethod::T%>(#this);
static method GenericClass|staticMethod() → void {}

View file

@ -4,7 +4,19 @@ import "dart:core" as core;
view Class /* representationType = core::int */ {
method instanceMethod = self::Class|instanceMethod;
tearoff instanceMethod = self::Class|get#instanceMethod;
static method staticMethod = self::Class|staticMethod;
}
static method Class|instanceMethod() → void {}
view GenericClass<T extends core::Object? = dynamic> /* representationType = T% */ {
method instanceMethod = self::GenericClass|instanceMethod;
tearoff instanceMethod = self::GenericClass|get#instanceMethod;
static method staticMethod = self::GenericClass|staticMethod;
}
static method Class|instanceMethod(lowered final self::Class #this) → void {}
static method Class|get#instanceMethod(lowered final self::Class #this) → () → void
return () → void => self::Class|instanceMethod(#this);
static method Class|staticMethod() → void {}
static method GenericClass|instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod::T%> #this) → void {}
static method GenericClass|get#instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|get#instanceMethod::T%> #this) → () → void
return () → void => self::GenericClass|instanceMethod<self::GenericClass|get#instanceMethod::T%>(#this);
static method GenericClass|staticMethod() → void {}

View file

@ -4,9 +4,23 @@ import "dart:core" as core;
view Class /* representationType = core::int */ {
method instanceMethod = self::Class|instanceMethod;
tearoff instanceMethod = self::Class|get#instanceMethod;
static method staticMethod = self::Class|staticMethod;
}
static method Class|instanceMethod() → void
view GenericClass<T extends core::Object? = dynamic> /* representationType = T% */ {
method instanceMethod = self::GenericClass|instanceMethod;
tearoff instanceMethod = self::GenericClass|get#instanceMethod;
static method staticMethod = self::GenericClass|staticMethod;
}
static method Class|instanceMethod(lowered final self::Class #this) → void
;
static method Class|get#instanceMethod(lowered final self::Class #this) → () → void
return () → void => self::Class|instanceMethod(#this);
static method Class|staticMethod() → void
;
static method GenericClass|instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod::T%> #this) → void
;
static method GenericClass|get#instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|get#instanceMethod::T%> #this) → () → void
return () → void => self::GenericClass|instanceMethod<self::GenericClass|get#instanceMethod::T%>(#this);
static method GenericClass|staticMethod() → void
;

View file

@ -4,7 +4,19 @@ import "dart:core" as core;
view Class /* representationType = core::int */ {
method instanceMethod = self::Class|instanceMethod;
tearoff instanceMethod = self::Class|get#instanceMethod;
static method staticMethod = self::Class|staticMethod;
}
static method Class|instanceMethod() → void {}
view GenericClass<T extends core::Object? = dynamic> /* representationType = T% */ {
method instanceMethod = self::GenericClass|instanceMethod;
tearoff instanceMethod = self::GenericClass|get#instanceMethod;
static method staticMethod = self::GenericClass|staticMethod;
}
static method Class|instanceMethod(lowered final self::Class #this) → void {}
static method Class|get#instanceMethod(lowered final self::Class #this) → () → void
return () → void => self::Class|instanceMethod(#this);
static method Class|staticMethod() → void {}
static method GenericClass|instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod::T%> #this) → void {}
static method GenericClass|get#instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|get#instanceMethod::T%> #this) → () → void
return () → void => self::GenericClass|instanceMethod<self::GenericClass|get#instanceMethod::T%>(#this);
static method GenericClass|staticMethod() → void {}