Skip to main content

no_mistakes_postgres_sql/statement_facts/bounds/
lines.rs

1use super::{SqlBoundFact, SqlBoundItemKind, SqlBoundQuery, SqlPinSource};
2
3impl SqlBoundFact {
4    /// Map every position through `map(line, column)`, for SQL embedded in a host file: the
5    /// column decides which physical operand of a recovered string owns the line.
6    pub fn map_lines(&mut self, map: &impl Fn(usize, usize) -> usize) {
7        self.line = map(self.line, self.column);
8        if let Some((line, column)) = &mut self.statement_start {
9            *line = map(*line, *column);
10        }
11        self.query.map_lines(map);
12    }
13}
14
15impl SqlBoundQuery {
16    // Borrow one callback through the recursive tree instead of specializing each traversal.
17    pub(super) fn map_lines(&mut self, map: &dyn Fn(usize, usize) -> usize) {
18        for item in &mut self.items {
19            item.line = map(item.line, item.column);
20            if let SqlBoundItemKind::Query(query) = &mut item.kind {
21                query.map_lines(map);
22            }
23            for pin in &mut item.pins {
24                if let SqlPinSource::Query(query)
25                | SqlPinSource::ReadQuery(query)
26                | SqlPinSource::ArrayQuery(query) = &mut pin.source
27                {
28                    query.map_lines(map);
29                }
30            }
31        }
32    }
33}