1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use fuel_tx::StorageSlot;
use sway_types::Ident;

use crate::{
    language::{parsed, ty::*},
    TypeId,
};

#[derive(Debug)]
pub struct TyProgram {
    pub kind: TyProgramKind,
    pub root: TyModule,
    pub storage_slots: Vec<StorageSlot>,
    pub logged_types: Vec<TypeId>,
}

#[derive(Clone, Debug)]
pub enum TyProgramKind {
    Contract {
        abi_entries: Vec<TyFunctionDeclaration>,
        declarations: Vec<TyDeclaration>,
    },
    Library {
        name: Ident,
    },
    Predicate {
        main_function: TyFunctionDeclaration,
        declarations: Vec<TyDeclaration>,
    },
    Script {
        main_function: TyFunctionDeclaration,
        declarations: Vec<TyDeclaration>,
    },
}

impl TyProgramKind {
    /// The parse tree type associated with this program kind.
    pub fn tree_type(&self) -> parsed::TreeType {
        match self {
            TyProgramKind::Contract { .. } => parsed::TreeType::Contract,
            TyProgramKind::Library { name } => parsed::TreeType::Library { name: name.clone() },
            TyProgramKind::Predicate { .. } => parsed::TreeType::Predicate,
            TyProgramKind::Script { .. } => parsed::TreeType::Script,
        }
    }
}