mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
[dart2js] Disentangle instance field setter and static field initializer
A FieldEntity is used as the entity for generating the setter of an instance field (when a check is required), and as the entity for the initializer expression for a static or top-level field. I think it is a bit clearer to have a separate method for each case rather than one method with conditional paths. Change-Id: I32e63c3f3566a63e3d38315cab17d613f006405e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/253562 Commit-Queue: Stephen Adams <sra@google.com> Reviewed-by: Mayank Patke <fishythefish@google.com>
This commit is contained in:
parent
e7df4c9b19
commit
5e267854e1
|
@ -478,7 +478,11 @@ class KernelSsaGraphBuilder extends ir.Visitor<void> with ir.VisitorVoidMixin {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
_buildField(target);
|
||||
if (targetElement.isInstanceMember) {
|
||||
_buildInstanceFieldSetter(target);
|
||||
} else {
|
||||
_buildStaticFieldInitializer(target);
|
||||
}
|
||||
} else if (target is ir.LocalFunction) {
|
||||
_buildFunctionNode(targetElement,
|
||||
_ensureDefaultArgumentValues(null, target.function));
|
||||
|
@ -579,12 +583,10 @@ class KernelSsaGraphBuilder extends ir.Visitor<void> with ir.VisitorVoidMixin {
|
|||
return function;
|
||||
}
|
||||
|
||||
void _buildField(ir.Field node) {
|
||||
graph.isLazyInitializer = node.isStatic;
|
||||
void _buildInstanceFieldSetter(ir.Field node) {
|
||||
assert(!node.isStatic);
|
||||
FieldEntity field = _elementMap.getMember(node);
|
||||
_openFunction(field, checks: TargetChecks.none);
|
||||
if (node.isInstanceMember &&
|
||||
closedWorld.annotationsData.getParameterCheckPolicy(field).isEmitted) {
|
||||
HInstruction thisInstruction = localsHandler.readThis(
|
||||
sourceInformation: _sourceInformationBuilder.buildGet(node));
|
||||
// Use dynamic type because the type computed by the inferrer is
|
||||
|
@ -607,7 +609,14 @@ class KernelSsaGraphBuilder extends ir.Visitor<void> with ir.VisitorVoidMixin {
|
|||
if (!_fieldAnalysis.getFieldData(field).isElided) {
|
||||
add(HFieldSet(_abstractValueDomain, field, thisInstruction, value));
|
||||
}
|
||||
} else {
|
||||
_closeFunction();
|
||||
}
|
||||
|
||||
void _buildStaticFieldInitializer(ir.Field node) {
|
||||
assert(node.isStatic);
|
||||
graph.isLazyInitializer = true;
|
||||
FieldEntity field = _elementMap.getMember(node);
|
||||
_openFunction(field, checks: TargetChecks.none);
|
||||
if (node.initializer != null) {
|
||||
node.initializer.accept(this);
|
||||
HInstruction fieldValue = pop();
|
||||
|
@ -621,7 +630,6 @@ class KernelSsaGraphBuilder extends ir.Visitor<void> with ir.VisitorVoidMixin {
|
|||
HInstruction value = pop();
|
||||
_closeAndGotoExit(HReturn(_abstractValueDomain, value,
|
||||
_sourceInformationBuilder.buildReturn(node)));
|
||||
}
|
||||
_closeFunction();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue