Skip to content

Commit

Permalink
Elements. Inline _buildClass()/_buildMixin() and reuse _EnclosingCont…
Browse files Browse the repository at this point in the history
…ext.

Change-Id: I974849fb401630c54d9962b2c9dd7f633992d624
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391542
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and Commit Queue committed Oct 23, 2024
1 parent bff7817 commit 82592f2
Showing 1 changed file with 21 additions and 57 deletions.
78 changes: 21 additions & 57 deletions pkg/analyzer/lib/src/summary2/element_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,21 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
_libraryBuilder.declare(name, reference);
}

var holder = _EnclosingContext(reference, element);
var holder = _EnclosingContext(reference, element,
constFieldsForFinalInstance: true);
_withEnclosing(holder, () {
var typeParameters = node.typeParameters;
if (typeParameters != null) {
typeParameters.accept(this);
element.typeParameters = holder.typeParameters;
}
node.typeParameters?.accept(this);
_visitPropertyFirst<FieldDeclaration>(node.members);
});
element.typeParameters = holder.typeParameters;
element.accessors = holder.propertyAccessors;
element.constructors = holder.constructors;
element.fields = holder.fields;
element.methods = holder.methods;

node.extendsClause?.accept(this);
node.withClause?.accept(this);
node.implementsClause?.accept(this);
_buildClass(node);

_libraryBuilder.updateAugmentationTarget(name, element);

Expand Down Expand Up @@ -512,23 +514,13 @@ class ElementBuilder extends ThrowingAstVisitor<void> {

var holder = _EnclosingContext(reference, element);
_withEnclosing(holder, () {
var typeParameters = node.typeParameters;
if (typeParameters != null) {
typeParameters.accept(this);
element.typeParameters = holder.typeParameters;
}
node.typeParameters?.accept(this);
_visitPropertyFirst<FieldDeclaration>(node.members);
});

// TODO(scheglov): don't create a duplicate
{
var holder = _EnclosingContext(reference, element);
_withEnclosing(holder, () {
_visitPropertyFirst<FieldDeclaration>(node.members);
});
element.accessors = holder.propertyAccessors;
element.fields = holder.fields;
element.methods = holder.methods;
}
element.typeParameters = holder.typeParameters;
element.accessors = holder.propertyAccessors;
element.fields = holder.fields;
element.methods = holder.methods;

node.onClause?.accept(this);

Expand Down Expand Up @@ -1111,16 +1103,16 @@ class ElementBuilder extends ThrowingAstVisitor<void> {

var holder = _EnclosingContext(reference, element);
_withEnclosing(holder, () {
var typeParameters = node.typeParameters;
if (typeParameters != null) {
typeParameters.accept(this);
element.typeParameters = holder.typeParameters;
}
node.typeParameters?.accept(this);
_visitPropertyFirst<FieldDeclaration>(node.members);
});
element.typeParameters = holder.typeParameters;
element.accessors = holder.propertyAccessors;
element.fields = holder.fields;
element.methods = holder.methods;

node.onClause?.accept(this);
node.implementsClause?.accept(this);
_buildMixin(node);

_libraryBuilder.updateAugmentationTarget(name, element);

Expand Down Expand Up @@ -1387,21 +1379,6 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
return _buildAnnotationsWithUnit(_unitElement, nodeList);
}

void _buildClass(ClassDeclaration node) {
var element = node.declaredElement as ClassElementImpl;
// TODO(scheglov): don't create a duplicate
var holder = _EnclosingContext(element.reference!, element,
constFieldsForFinalInstance: true);
_withEnclosing(holder, () {
_visitPropertyFirst<FieldDeclaration>(node.members);
});

element.accessors = holder.propertyAccessors;
element.constructors = holder.constructors;
element.fields = holder.fields;
element.methods = holder.methods;
}

void _buildExecutableElementChildren({
required Reference reference,
required ExecutableElementImpl element,
Expand Down Expand Up @@ -1436,19 +1413,6 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
);
}

void _buildMixin(MixinDeclaration node) {
var element = node.declaredElement as MixinElementImpl;
// TODO(scheglov): don't create a duplicate
var holder = _EnclosingContext(element.reference!, element);
_withEnclosing(holder, () {
_visitPropertyFirst<FieldDeclaration>(node.members);
});

element.accessors = holder.propertyAccessors;
element.fields = holder.fields;
element.methods = holder.methods;
}

void _buildSyntheticVariable({
required String name,
required PropertyAccessorElementImpl accessorElement,
Expand Down

0 comments on commit 82592f2

Please sign in to comment.