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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// This file is auto-generated by codegen/rust/nodes/node_file/native.rs

use crate::nodes::InnerNode;
use crate::nodes::InspectVec;
use crate::Loc;
use crate::Node;

/// Represents conditional method call using `&.` operator
#[derive(Debug, Clone, PartialEq)]
#[repr(C)]
pub struct CSend {
    /// Receiver of the method call, `Int("1")` for `1&.foo`
    pub recv: Box<Node>,

    /// Name of the method, `String("foo")` for `1&.foo`
    pub method_name: String,

    /// List of arguments
    ///
    /// ```text
    /// foo&.bar(42)
    /// # and also setters like
    /// foo&.bar = 42
    /// ```
    pub args: Vec<Node>,

    /// Location of the `&.` operator
    ///
    /// ```text
    /// foo&.bar
    ///    ~~
    /// ```
    pub dot_l: Loc,

    /// Location of the method name
    ///
    /// ```text
    /// foo&.bar(42)
    ///      ~~~
    /// ```
    ///
    /// `None` in a very special case when method call is implicit (i.e. `foo&.()`)
    pub selector_l: Option<Loc>,

    /// Location of the open parenthesis
    ///
    /// ```text
    /// foo&.bar(42)
    ///         ~
    /// ```
    ///
    /// `None` if there are no parentheses
    pub begin_l: Option<Loc>,

    /// Location of the closing parenthesis
    ///
    /// ```text
    /// foo&.bar(42)
    ///            ~
    /// ```
    ///
    /// `None` if there are no parentheses
    pub end_l: Option<Loc>,

    /// Location of the operator if `CSend` is a part of assignment like
    ///
    /// ```text
    /// foo&.bar = 1
    ///          ~
    /// ```
    ///
    /// `None` for a regular call.
    pub operator_l: Option<Loc>,

    /// Location of the full expression
    ///
    /// ```text
    /// foo&.bar(42)
    /// ~~~~~~~~~~~~
    /// ```
    pub expression_l: Loc,

}

impl CSend {
    // getters

    /// Returns `recv` field
    pub fn get_recv(&self) -> &Box<Node> {
        &self.recv
    }

    /// Returns `method_name` field
    pub fn get_method_name(&self) -> &String {
        &self.method_name
    }

    /// Returns `args` field
    pub fn get_args(&self) -> &Vec<Node> {
        &self.args
    }

    /// Returns `dot_l` field
    pub fn get_dot_l(&self) -> &Loc {
        &self.dot_l
    }

    /// Returns `selector_l` field
    pub fn get_selector_l(&self) -> &Option<Loc> {
        &self.selector_l
    }

    /// Returns `begin_l` field
    pub fn get_begin_l(&self) -> &Option<Loc> {
        &self.begin_l
    }

    /// Returns `end_l` field
    pub fn get_end_l(&self) -> &Option<Loc> {
        &self.end_l
    }

    /// Returns `operator_l` field
    pub fn get_operator_l(&self) -> &Option<Loc> {
        &self.operator_l
    }

    /// Returns `expression_l` field
    pub fn get_expression_l(&self) -> &Loc {
        &self.expression_l
    }


    // setters

    /// Sets `recv` field
    pub fn set_recv(&mut self, recv: Box<Node>) {
        self.recv = recv;
    }

    /// Sets `method_name` field
    pub fn set_method_name(&mut self, method_name: String) {
        self.method_name = method_name;
    }

    /// Sets `args` field
    pub fn set_args(&mut self, args: Vec<Node>) {
        self.args = args;
    }

    /// Sets `dot_l` field
    pub fn set_dot_l(&mut self, dot_l: Loc) {
        self.dot_l = dot_l;
    }

    /// Sets `selector_l` field
    pub fn set_selector_l(&mut self, selector_l: Option<Loc>) {
        self.selector_l = selector_l;
    }

    /// Sets `begin_l` field
    pub fn set_begin_l(&mut self, begin_l: Option<Loc>) {
        self.begin_l = begin_l;
    }

    /// Sets `end_l` field
    pub fn set_end_l(&mut self, end_l: Option<Loc>) {
        self.end_l = end_l;
    }

    /// Sets `operator_l` field
    pub fn set_operator_l(&mut self, operator_l: Option<Loc>) {
        self.operator_l = operator_l;
    }

    /// Sets `expression_l` field
    pub fn set_expression_l(&mut self, expression_l: Loc) {
        self.expression_l = expression_l;
    }


    #[allow(dead_code)]
    pub(crate) fn into_internal(self) -> super::InternalCSend {
        let Self { recv, method_name, args, dot_l, selector_l, begin_l, end_l, operator_l, expression_l,  } = self;
        super::InternalCSend { recv, method_name, args, dot_l, selector_l, begin_l, end_l, operator_l, expression_l,  }
    }
}

impl InnerNode for CSend {
    fn expression(&self) -> &Loc {
        &self.expression_l
    }

    fn inspected_children(&self, indent: usize) -> Vec<String> {
        let mut result = InspectVec::new(indent);
        result.push_node(self.get_recv());
        result.push_str(self.get_method_name());
        result.push_nodes(self.get_args());






        result.strings()
    }

    fn str_type(&self) -> &'static str {
        "csend"
    }

    fn print_with_locs(&self) {
        println!("{}", self.inspect(0));
        self.get_recv().inner_ref().print_with_locs();

        for node in self.get_args().iter() { node.inner_ref().print_with_locs(); }
        self.get_dot_l().print("dot");
        if let Some(loc) = self.get_selector_l().as_ref() { loc.print("selector") }
        if let Some(loc) = self.get_begin_l().as_ref() { loc.print("begin") }
        if let Some(loc) = self.get_end_l().as_ref() { loc.print("end") }
        if let Some(loc) = self.get_operator_l().as_ref() { loc.print("operator") }
        self.get_expression_l().print("expression");
    }
}