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
//! Faithful port of `Luau::detail::ArcCollector::add`
//! (`Analysis/src/TopoSortStatements.cpp:220-233`).
//!
//! ```cpp
//! // Adds a dependency from the current node to the named node.
//! void add(const Identifier& name)
//! {
//! Node** it = map.find(name);
//! if (it == nullptr)
//! return;
//!
//! Node* n = *it;
//!
//! if (n == currentArc)
//! return;
//!
//! n->provides.insert(currentArc);
//! currentArc->depends.insert(n);
//! }
//! ```
use crate::records::arc_collector::ArcCollector;
use crate::records::identifier::Identifier;
use crate::records::node::Node;
impl ArcCollector {
pub fn add(&mut self, name: &Identifier) {
// Node** it = map.find(name);
// if (it == nullptr) return;
let n: *mut Node = match self.map.find(name) {
Some(&n) => n,
None => return,
};
// if (n == currentArc) return;
if n == self.current_arc {
return;
}
// n->provides.insert(currentArc);
// currentArc->depends.insert(n);
unsafe {
(*n).provides.insert(self.current_arc);
(*self.current_arc).depends.insert(n);
}
}
}