Skip to main content

dada_ir_ast/ast/
class_item.rs

1use dada_util::SalsaSerialize;
2use serde::Serialize;
3
4use crate::{
5    ast::{AstFieldDecl, AstVisibility, DeferredParse},
6    span::{Span, Spanned},
7};
8
9use super::{AstGenericDecl, AstWhereClauses, Identifier, SpanVec};
10
11/// Some kind of aggregate, like a class, struct, etc.
12///
13/// `class $name[$generics] { ... }` or `class $name[$generics](...) { ... }`
14#[derive(SalsaSerialize)]
15#[salsa::tracked(debug)]
16pub struct AstAggregate<'db> {
17    pub span: Span<'db>,
18
19    /// Visibility of the class
20    pub visibility: Option<AstVisibility<'db>>,
21
22    pub kind: AstAggregateKind,
23
24    pub name: Identifier<'db>,
25
26    pub name_span: Span<'db>,
27
28    #[return_ref]
29    pub generics: Option<SpanVec<'db, AstGenericDecl<'db>>>,
30
31    /// If a `()` section is present...
32    #[return_ref]
33    pub inputs: Option<SpanVec<'db, AstFieldDecl<'db>>>,
34
35    #[return_ref]
36    pub where_clauses: Option<AstWhereClauses<'db>>,
37
38    /// The unparsed contents of the class.
39    /// This can be parsed via the `members`
40    /// method defined in `dada_parser::prelude`.
41    #[return_ref]
42    pub contents: Option<DeferredParse<'db>>,
43}
44
45impl<'db> Spanned<'db> for AstAggregate<'db> {
46    fn span(&self, db: &'db dyn crate::Db) -> Span<'db> {
47        AstAggregate::span(*self, db)
48    }
49}
50
51#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Serialize)]
52pub enum AstAggregateKind {
53    Class,
54    Struct,
55}