darklua_core/nodes/statements/
generic_for.rs

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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use crate::nodes::{Block, Expression, Token, TypedIdentifier};

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct GenericForTokens {
    pub r#for: Token,
    pub r#in: Token,
    pub r#do: Token,
    pub end: Token,
    pub identifier_commas: Vec<Token>,
    pub value_commas: Vec<Token>,
}

impl GenericForTokens {
    super::impl_token_fns!(
        target = [r#for, r#in, r#do, end]
        iter = [identifier_commas, value_commas]
    );
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct GenericForStatement {
    identifiers: Vec<TypedIdentifier>,
    expressions: Vec<Expression>,
    block: Block,
    tokens: Option<GenericForTokens>,
}

impl GenericForStatement {
    pub fn new<B: Into<Block>>(
        identifiers: Vec<TypedIdentifier>,
        expressions: Vec<Expression>,
        block: B,
    ) -> Self {
        Self {
            identifiers,
            expressions,
            block: block.into(),
            tokens: None,
        }
    }

    pub fn with_tokens(mut self, tokens: GenericForTokens) -> Self {
        self.tokens = Some(tokens);
        self
    }

    #[inline]
    pub fn set_tokens(&mut self, tokens: GenericForTokens) {
        self.tokens = Some(tokens);
    }

    #[inline]
    pub fn get_tokens(&self) -> Option<&GenericForTokens> {
        self.tokens.as_ref()
    }

    #[inline]
    pub fn mutate_tokens(&mut self) -> Option<&mut GenericForTokens> {
        self.tokens.as_mut()
    }

    #[inline]
    pub fn get_block(&self) -> &Block {
        &self.block
    }

    #[inline]
    pub fn get_identifiers(&self) -> &Vec<TypedIdentifier> {
        &self.identifiers
    }

    #[inline]
    pub fn iter_identifiers(&self) -> impl Iterator<Item = &TypedIdentifier> {
        self.identifiers.iter()
    }

    #[inline]
    pub fn get_expressions(&self) -> &Vec<Expression> {
        &self.expressions
    }

    #[inline]
    pub fn iter_expressions(&self) -> impl Iterator<Item = &Expression> {
        self.expressions.iter()
    }

    #[inline]
    pub fn iter_mut_identifiers(&mut self) -> impl Iterator<Item = &mut TypedIdentifier> {
        self.identifiers.iter_mut()
    }

    #[inline]
    pub fn iter_mut_expressions(&mut self) -> impl Iterator<Item = &mut Expression> {
        self.expressions.iter_mut()
    }

    #[inline]
    pub fn mutate_expressions(&mut self) -> &mut Vec<Expression> {
        &mut self.expressions
    }

    #[inline]
    pub fn mutate_block(&mut self) -> &mut Block {
        &mut self.block
    }

    #[inline]
    pub fn identifiers_len(&self) -> usize {
        self.identifiers.len()
    }

    #[inline]
    pub fn expressions_len(&self) -> usize {
        self.expressions.len()
    }

    pub fn clear_types(&mut self) {
        for identifier in &mut self.identifiers {
            identifier.remove_type();
        }
    }

    super::impl_token_fns!(iter = [tokens, identifiers]);
}