(&mut self, other: WorkingStruct, recursion: usize)
| 124 | } |
| 125 | |
| 126 | pub fn insert(&mut self, other: WorkingStruct, recursion: usize) -> Result<()> { |
| 127 | log(|| { |
| 128 | format!("{}self: {:#?}", " ".repeat(recursion), self) |
| 129 | .replace("\n", &("\n".to_owned() + &" ".repeat(recursion))) |
| 130 | }); |
| 131 | log(|| { |
| 132 | format!("{}other: {:#?}", " ".repeat(recursion), other) |
| 133 | .replace("\n", &("\n".to_owned() + &" ".repeat(recursion))) |
| 134 | }); |
| 135 | |
| 136 | self.extend_to(other.end()); |
| 137 | |
| 138 | // There are 2 cases we have to deal with here: |
| 139 | // a. `other` starts after the end of the last group => insert `other` into the last group |
| 140 | // b. `other` starts before the end of the last group => collect all the children inserted after it starts and put them into a struct |
| 141 | // start a new struct with `other` |
| 142 | |
| 143 | if self.children.is_empty() { |
| 144 | self.children.push(other); |
| 145 | return Ok(()); |
| 146 | } |
| 147 | |
| 148 | // This is really gross. |
| 149 | // But also I need to ship this before I leave for France |
| 150 | // TODO: Clean this up |
| 151 | |
| 152 | if other.start() |
| 153 | >= self |
| 154 | .children |
| 155 | .last() |
| 156 | .ok_or_else(|| anyhow!("Expected we have children #A"))? |
| 157 | .end() |
| 158 | { |
| 159 | self.children.push(other); |
| 160 | } else { |
| 161 | // Create a structure with fields from self.children |
| 162 | if self |
| 163 | .children |
| 164 | .last() |
| 165 | .ok_or_else(|| anyhow!("Expected we have children #B"))? |
| 166 | .index |
| 167 | .is_none() |
| 168 | && self |
| 169 | .children |
| 170 | .last() |
| 171 | .ok_or_else(|| anyhow!("Expected we have children #C"))? |
| 172 | .start() |
| 173 | < other.start() |
| 174 | { |
| 175 | self.children |
| 176 | .last_mut() |
| 177 | .ok_or_else(|| anyhow!("Expected we have children #D"))? |
| 178 | .insert(other, recursion + 1)?; |
| 179 | return Ok(()); |
| 180 | } |
| 181 | |
| 182 | // If we're a union, we don't have to bother pushing a struct+union combo |
| 183 | if self.is_union { |
no test coverage detected