1use derive_more::From;
2use galvan_ast_macro::AstNode;
3
4use crate::{AstNode, PrintAst, Span};
5
6use super::{DeclModifier, Ident, TypeElement, TypeIdent, Visibility};
7
8#[derive(Debug, PartialEq, Eq, From)]
9pub enum TypeDecl {
10 Tuple(TupleTypeDecl),
11 Struct(StructTypeDecl),
12 Alias(AliasTypeDecl),
13 Enum(EnumTypeDecl),
14 Empty(EmptyTypeDecl),
15}
16
17impl TypeDecl {
18 pub fn ident(&self) -> &TypeIdent {
19 match self {
20 TypeDecl::Tuple(t) => &t.ident,
21 TypeDecl::Struct(s) => &s.ident,
22 TypeDecl::Alias(a) => &a.ident,
23 TypeDecl::Empty(e) => &e.ident,
24 TypeDecl::Enum(e) => &e.ident,
25 }
26 }
27}
28
29#[derive(Debug, PartialEq, Eq, AstNode)]
30pub struct TupleTypeDecl {
31 pub visibility: Visibility,
32 pub ident: TypeIdent,
33 pub members: Vec<TupleTypeMember>,
34 pub span: Span,
35}
36
37#[derive(Debug, PartialEq, Eq, AstNode)]
38pub struct TupleTypeMember {
39 pub r#type: TypeElement,
41 pub span: Span,
42}
43
44#[derive(Debug, PartialEq, Eq, AstNode)]
45pub struct StructTypeDecl {
46 pub visibility: Visibility,
47 pub ident: TypeIdent,
48 pub members: Vec<StructTypeMember>,
49 pub span: Span,
50}
51
52#[derive(Debug, PartialEq, Eq, AstNode)]
53pub struct StructTypeMember {
54 pub decl_modifier: Option<DeclModifier>,
56 pub ident: Ident,
57 pub r#type: TypeElement,
58 pub span: Span,
59}
60
61#[derive(Debug, PartialEq, Eq, AstNode)]
62pub struct AliasTypeDecl {
63 pub visibility: Visibility,
64 pub ident: TypeIdent,
65 pub r#type: TypeElement,
66 pub span: Span,
67}
68
69#[derive(Debug, PartialEq, Eq, AstNode)]
70pub struct EnumTypeDecl {
71 pub visibility: Visibility,
72 pub ident: TypeIdent,
73 pub members: Vec<EnumTypeMember>,
74 pub span: Span,
75}
76
77#[derive(Debug, PartialEq, Eq, AstNode)]
78pub struct EnumTypeMember {
79 pub ident: TypeIdent,
81 pub span: Span,
82}
83
84#[derive(Debug, PartialEq, Eq, AstNode)]
85pub struct EmptyTypeDecl {
87 pub visibility: Visibility,
88 pub ident: TypeIdent,
89 pub span: Span,
90}