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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use std::borrow::Cow;
use sway_types::{state::StateIndex, Ident, Span, Spanned};
use crate::{language::ty::*, type_system::*};
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TyReassignment {
pub lhs_base_name: Ident,
pub lhs_type: TypeId,
pub lhs_indices: Vec<ProjectionKind>,
pub rhs: TyExpression,
}
impl CopyTypes for TyReassignment {
fn copy_types_inner(&mut self, type_mapping: &TypeMapping) {
self.rhs.copy_types(type_mapping);
self.lhs_type.copy_types(type_mapping);
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ProjectionKind {
StructField { name: Ident },
TupleField { index: usize, index_span: Span },
}
impl Spanned for ProjectionKind {
fn span(&self) -> Span {
match self {
ProjectionKind::StructField { name } => name.span(),
ProjectionKind::TupleField { index_span, .. } => index_span.clone(),
}
}
}
impl ProjectionKind {
pub(crate) fn pretty_print(&self) -> Cow<str> {
match self {
ProjectionKind::StructField { name } => Cow::Borrowed(name.as_str()),
ProjectionKind::TupleField { index, .. } => Cow::Owned(index.to_string()),
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TyStorageReassignment {
pub fields: Vec<TyStorageReassignDescriptor>,
pub(crate) ix: StateIndex,
pub rhs: TyExpression,
}
impl Spanned for TyStorageReassignment {
fn span(&self) -> Span {
self.fields
.iter()
.fold(self.fields[0].span.clone(), |acc, field| {
Span::join(acc, field.span.clone())
})
}
}
impl TyStorageReassignment {
pub fn names(&self) -> Vec<Ident> {
self.fields
.iter()
.map(|f| f.name.clone())
.collect::<Vec<_>>()
}
}
#[derive(Clone, Debug, Eq)]
pub struct TyStorageReassignDescriptor {
pub name: Ident,
pub type_id: TypeId,
pub(crate) span: Span,
}
impl PartialEq for TyStorageReassignDescriptor {
fn eq(&self, other: &Self) -> bool {
self.name == other.name && look_up_type_id(self.type_id) == look_up_type_id(other.type_id)
}
}