7ef361bda0
This change introduces experimental AST support for the "declaring constructors" (DeCo) feature and wires the parser to build explicit nodes for primary constructors. The new behavior is gated by a static switch: analyzer/dart/ast/ast.dart: useDeclaringConstructorsAst (experimental) When the flag is **true** (must be set once before parsing and not changed thereafter): * Declarations expose structured bodies: - `ClassDeclaration.body` / `MixinDeclaration.body` - `EnumDeclaration.body` - `ExtensionDeclaration.body` - `ExtensionTypeDeclaration.body` Legacy bracket/members tokens (`leftBracket`, `members`, `rightBracket`) throw `UnsupportedError`. * The declaration "name" area is modeled as `namePart: ClassNamePart`, which is either: - `NameWithTypeParameters` (e.g., `A<T>`), or - `PrimaryConstructorDeclaration` (e.g., `A<T>.named(...)`). Legacy fields (`name`, `typeParameters`) throw `UnsupportedError`. For extension types, `representation` also throws under the flag and is represented via `PrimaryConstructorDeclaration`. * Child iteration (`childEntities`), visiting (`visitChildren`), and token boundaries (`endToken`) adapt to the new shape. Parser changes: * Build `PrimaryConstructorDeclaration` / `PrimaryConstructorName` via a new `_PrimaryConstructorBuilder`. For extension types, the existing representation syntax is mapped to a primary constructor when the flag is enabled. * Add `NullValue.PrimaryConstructor` to the stack listener to carry the parsed primary constructor through the builder pipeline. Implementation details: * Introduce small internal *Stub classes (e.g., `ClassBodyImplStub`, `EnumBodyImplStub`, `RepresentationDeclarationImplStub`) to satisfy constructor requirements for fields that are not surfaced under the current mode, avoiding API churn while the feature is gated. * Update API surface to make `body` and `namePart` available on the affected declarations and document which legacy getters throw when the flag is enabled. Rationale: This lays the AST groundwork for DeCo while preserving backwards compatibility by default. Consumers can opt in to validate workflows and migrate incrementally. Bug: https://github.com/dart-lang/sdk/issues/61701 Change-Id: Ie5300b2958383bf3b2e9d6faf138bb7f74c9d7ed Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/455820 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Paul Berry <paulberry@google.com>
FE/analyzer shared code
This package contains logic that is shared between the front_end and analyzer packages. It is intended solely to facilitate development of the Dart SDK, and is not intended for use by end users. In particular, this package has no public API, so no guarantee is made of compatibility between one version of the package and the next.
End users should consider using the analyzer package to analyze Dart source code.