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
use crate::{language::parsed::Expression, transform, type_system::*};
use sway_types::{ident::Ident, span::Span, Spanned};

#[derive(Debug, Clone)]
/// A declaration of contract storage. Only valid within contract contexts.
/// All values in this struct are mutable and persistent among executions of the same contract deployment.
pub struct StorageDeclaration {
    pub attributes: transform::AttributesMap,
    pub fields: Vec<StorageField>,
    pub span: Span,
    pub storage_keyword: Ident,
}

impl Spanned for StorageDeclaration {
    fn span(&self) -> sway_types::Span {
        self.span.clone()
    }
}

/// An individual field in a storage declaration.
/// A type annotation _and_ initializer value must be provided. The initializer value must be a
/// constant expression. For now, that basically means just a literal, but as constant folding
/// improves, we can update that.
#[derive(Debug, Clone)]
pub struct StorageField {
    pub name: Ident,
    pub attributes: transform::AttributesMap,
    pub type_argument: TypeArgument,
    pub span: Span,
    pub initializer: Expression,
}