Skip to content

Commit

Permalink
Parse mixin augmentations, build element model.
Browse files Browse the repository at this point in the history
Change-Id: Ie1bdb6d47b31c527546f62abf65d19a4a4e50ee7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312924
Reviewed-by: Brian Wilkerson <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
  • Loading branch information
scheglov authored and Commit Queue committed Jul 10, 2023
1 parent f0310b5 commit 3bb4d7d
Show file tree
Hide file tree
Showing 23 changed files with 1,273 additions and 206 deletions.
30 changes: 30 additions & 0 deletions pkg/analyzer/lib/dart/ast/visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ class GeneralizingAstVisitor<R> implements AstVisitor<R> {
R? visitMethodInvocation(MethodInvocation node) =>
visitInvocationExpression(node);

@override
R? visitMixinAugmentationDeclaration(MixinAugmentationDeclaration node) =>
visitNamedCompilationUnitMember(node);

@override
R? visitMixinDeclaration(MixinDeclaration node) =>
visitNamedCompilationUnitMember(node);
Expand Down Expand Up @@ -1385,6 +1389,12 @@ class RecursiveAstVisitor<R> implements AstVisitor<R> {
return null;
}

@override
R? visitMixinAugmentationDeclaration(MixinAugmentationDeclaration node) {
node.visitChildren(this);
return null;
}

@override
R? visitMixinDeclaration(MixinDeclaration node) {
node.visitChildren(this);
Expand Down Expand Up @@ -2114,6 +2124,10 @@ class SimpleAstVisitor<R> implements AstVisitor<R> {
@override
R? visitMethodInvocation(MethodInvocation node) => null;

@override
R? visitMixinAugmentationDeclaration(MixinAugmentationDeclaration node) =>
null;

@override
R? visitMixinDeclaration(MixinDeclaration node) => null;

Expand Down Expand Up @@ -2652,6 +2666,10 @@ class ThrowingAstVisitor<R> implements AstVisitor<R> {
@override
R? visitMethodInvocation(MethodInvocation node) => _throw(node);

@override
R? visitMixinAugmentationDeclaration(MixinAugmentationDeclaration node) =>
_throw(node);

@override
R? visitMixinDeclaration(MixinDeclaration node) => _throw(node);

Expand Down Expand Up @@ -3693,6 +3711,14 @@ class TimedAstVisitor<T> implements AstVisitor<T> {
return result;
}

@override
T? visitMixinAugmentationDeclaration(MixinAugmentationDeclaration node) {
stopwatch.start();
T? result = _baseVisitor.visitMixinAugmentationDeclaration(node);
stopwatch.stop();
return result;
}

@override
T? visitMixinDeclaration(MixinDeclaration node) {
stopwatch.start();
Expand Down Expand Up @@ -4578,6 +4604,10 @@ class UnifyingAstVisitor<R> implements AstVisitor<R> {
@override
R? visitMethodInvocation(MethodInvocation node) => visitNode(node);

@override
R? visitMixinAugmentationDeclaration(MixinAugmentationDeclaration node) =>
visitNode(node);

@override
R? visitMixinDeclaration(MixinDeclaration node) => visitNode(node);

Expand Down
44 changes: 25 additions & 19 deletions pkg/analyzer/lib/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ abstract class CompilationUnitElement implements UriReferencedElement {
List<PropertyAccessorElement> get accessors;

/// The class augmentations declared in this compilation unit.
@experimental
List<ClassAugmentationElement> get classAugmentations;

/// The classes declared in this compilation unit.
Expand All @@ -384,6 +385,10 @@ abstract class CompilationUnitElement implements UriReferencedElement {
/// The [LineInfo] for the [source].
LineInfo get lineInfo;

/// The mixin augmentations declared in this compilation unit.
@experimental
List<MixinAugmentationElement> get mixinAugmentations;

/// The mixins declared in this compilation unit.
List<MixinElement> get mixins;

Expand Down Expand Up @@ -1169,6 +1174,8 @@ abstract class ElementVisitor<R> {

R? visitMethodElement(MethodElement element);

R? visitMixinAugmentationElement(MixinAugmentationElement element);

R? visitMixinElement(MixinElement element);

R? visitMultiplyDefinedElement(MultiplyDefinedElement element);
Expand Down Expand Up @@ -2177,25 +2184,6 @@ abstract class MixinElement
@override
AugmentedMixinElement get augmented;

/// Whether the mixin is a base mixin.
///
/// A mixin is a base mixin if it has an explicit `base` modifier, or the
/// mixin has a `base` induced modifier and [isSealed] is `true` as well.
/// The base modifier allows a mixin to be mixed in but not implemented.
bool get isBase;

/// The superclass constraints defined for this mixin.
///
/// If the declaration does not have an `on` clause, then the list will
/// contain the type for the class `Object`.
///
/// <b>Note:</b> Because the element model represents the state of the code,
/// it is possible for it to be semantically invalid. In particular, it is not
/// safe to assume that the inheritance structure of a class does not contain
/// a cycle. Clients that traverse the inheritance structure must explicitly
/// guard against infinite loops.
List<InterfaceType> get superclassConstraints;

/// Whether the element, assuming that it is within scope, is
/// implementable to classes, mixins, and enums in the given [library].
bool isImplementableIn(LibraryElement library);
Expand All @@ -2216,6 +2204,24 @@ abstract class MixinOrAugmentationElement

@override
MixinElement? get augmentedDeclaration;

/// Whether the mixin is a base mixin.
///
/// A mixin is a base mixin if it has an explicit `base` modifier.
/// The base modifier allows a mixin to be mixed in, but not implemented.
bool get isBase;

/// The superclass constraints defined for this mixin.
///
/// If the declaration does not have an `on` clause, then the list will
/// contain the type for the class `Object`.
///
/// <b>Note:</b> Because the element model represents the state of the code,
/// it is possible for it to be semantically invalid. In particular, it is not
/// safe to assume that the inheritance structure of a class does not contain
/// a cycle. Clients that traverse the inheritance structure must explicitly
/// guard against infinite loops.
List<InterfaceType> get superclassConstraints;
}

/// A pseudo-element that represents multiple elements defined within a single
Expand Down
17 changes: 17 additions & 0 deletions pkg/analyzer/lib/dart/element/visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ class GeneralizingElementVisitor<R> implements ElementVisitor<R> {
R? visitMethodElement(MethodElement element) =>
visitExecutableElement(element);

@override
R? visitMixinAugmentationElement(MixinAugmentationElement element) =>
visitElement(element);

@override
R? visitMixinElement(MixinElement element) => visitElement(element);

Expand Down Expand Up @@ -334,6 +338,12 @@ class RecursiveElementVisitor<R> implements ElementVisitor<R> {
return null;
}

@override
R? visitMixinAugmentationElement(MixinAugmentationElement element) {
element.visitChildren(this);
return null;
}

@override
R? visitMixinElement(MixinElement element) {
element.visitChildren(this);
Expand Down Expand Up @@ -462,6 +472,9 @@ class SimpleElementVisitor<R> implements ElementVisitor<R> {
@override
R? visitMethodElement(MethodElement element) => null;

@override
R? visitMixinAugmentationElement(MixinAugmentationElement element) => null;

@override
R? visitMixinElement(MixinElement element) => null;

Expand Down Expand Up @@ -565,6 +578,10 @@ class ThrowingElementVisitor<R> implements ElementVisitor<R> {
@override
R? visitMethodElement(MethodElement element) => _throw(element);

@override
R? visitMixinAugmentationElement(MixinAugmentationElement element) =>
_throw(element);

@override
R? visitMixinElement(MixinElement element) => _throw(element);

Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/analysis/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import 'package:analyzer/src/utilities/uri_cache.dart';
/// TODO(scheglov) Clean up the list of implicitly analyzed files.
class AnalysisDriver implements AnalysisDriverGeneric {
/// The version of data format, should be incremented on every format change.
static const int DATA_VERSION = 282;
static const int DATA_VERSION = 283;

/// The number of exception contexts allowed to write. Once this field is
/// zero, we stop writing any new exception contexts in this process.
Expand Down
Loading

0 comments on commit 3bb4d7d

Please sign in to comment.