Debian Codegraph @

src/graph/meta.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().;
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#;
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::{Indexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#, IndexMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#};
4
5 use craterust-analyzer cargo logos-codegen 0.15.1 crate/::graphrust-analyzer cargo logos-codegen 0.15.1 graph/::{Graphrust-analyzer cargo logos-codegen 0.15.1 graph/Graph#, Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#, NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId#};
6
7 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
8 pub struct Metarust-analyzer cargo logos-codegen 0.15.1 graph/meta/Meta# {
9 maprust-analyzer cargo logos-codegen 0.15.1 graph/meta/Meta#map.: BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId#, MetaItemrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#>,
10 }
11
12 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
13 pub struct MetaItemrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem# {
14 /// Number of references to this node
15 pub refcountrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#refcount.: usize,
16 /// Minimum number of bytes that ought to be read for this
17 /// node to find a match
18 pub min_readrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#min_read.: usize,
19 /// Marks whether or not this node leads to a loop entry node.
20 pub is_loop_initrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#is_loop_init.: bool,
21 /// Ids of other nodes that point to this node while this
22 /// node is on a stack (creating a loop)
23 pub loop_entry_fromrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#loop_entry_from.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId#>,
24 }
25
26 impl Indexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#<NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId#> for Metarust-analyzer cargo logos-codegen 0.15.1 graph/meta/Meta# {
27 type Outputrust-analyzer cargo logos-codegen 0.15.1 graph/meta/impl#[Meta][`Index<NodeId>`]Output# = MetaItemrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#;
28
29 fn indexrust-analyzer cargo logos-codegen 0.15.1 graph/meta/impl#[Meta][`Index<NodeId>`]index().(&self, id: NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId#) -> &MetaItemrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem# {
30 &self.maprust-analyzer cargo logos-codegen 0.15.1 graph/meta/Meta#map.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`][`Index<&Q>`]index().&id]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`][`Index<&Q>`]index().
31 }
32 }
33
34 impl IndexMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#<NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId#> for Metarust-analyzer cargo logos-codegen 0.15.1 graph/meta/Meta# {
35 fn index_mutrust-analyzer cargo logos-codegen 0.15.1 graph/meta/impl#[Meta][`IndexMut<NodeId>`]index_mut().(&mut self, id: NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId#) -> &mut MetaItemrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem# {
36 self.maprust-analyzer cargo logos-codegen 0.15.1 graph/meta/Meta#map..entryrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]entry().(id).or_defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/entry/impl#[`Entry<'a, K, V, A>`]or_default().()
37 }
38 }
39
40 impl MetaItemrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem# {
41 fn loop_entryrust-analyzer cargo logos-codegen 0.15.1 graph/meta/impl#[MetaItem]loop_entry().(&mut self, id: NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId#) {
42 if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(idx) = self.loop_entry_fromrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#loop_entry_from..binary_searchrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]binary_search().(&id) {
43 self.loop_entry_fromrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#loop_entry_from..insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]insert().(idx, id);
44 }
45 }
46 }
47
48 impl Metarust-analyzer cargo logos-codegen 0.15.1 graph/meta/Meta# {
49 pub fn analyzerust-analyzer cargo logos-codegen 0.15.1 graph/meta/impl#[Meta]analyze().<T>(root: NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId#, graph: &Graphrust-analyzer cargo logos-codegen 0.15.1 graph/Graph#<T>) -> Selfrust-analyzer cargo logos-codegen 0.15.1 graph/meta/impl#[Meta] {
50 let mut meta = Metarust-analyzer cargo logos-codegen 0.15.1 graph/meta/Meta# {
51 maprust-analyzer cargo logos-codegen 0.15.1 graph/meta/Meta#map.: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`][Default]default().(),
52 };
53
54 meta.first_passrust-analyzer cargo logos-codegen 0.15.1 graph/meta/impl#[Meta]first_pass().(root, root, graph, &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().());
55
56 meta
57 }
58
59 pub fn first_passrust-analyzer cargo logos-codegen 0.15.1 graph/meta/impl#[Meta]first_pass().<T>(
60 &mut self,
61 this: NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId#,
62 parent: NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId#,
63 graph: &Graphrust-analyzer cargo logos-codegen 0.15.1 graph/Graph#<T>,
64 stack: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId#>,
65 ) -> &MetaItemrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem# {
66 let meta = &mut self[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().this]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().;
67 let is_done = meta.refcountrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#refcount. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0;
68
69 meta.refcountrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#refcount. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
70
71 if stack.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&this) {
72 meta.loop_entryrust-analyzer cargo logos-codegen 0.15.1 graph/meta/impl#[MetaItem]loop_entry().(parent);
73 self[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().parent]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()..is_loop_initrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#is_loop_init. = true;
74 }
75 if is_done {
76 return &self[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().this]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
77 }
78
79 stack.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(this);
80
81 let mut min_read;
82
83 match &graph[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().this]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). {
84 Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#::Forkrust-analyzer cargo logos-codegen 0.15.1 graph/Node#Fork#(fork) => {
85 min_read = usize::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]MAX.;
86 for (_, id) in fork.branchesrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]branches().() {
87 let meta = self.first_passrust-analyzer cargo logos-codegen 0.15.1 graph/meta/impl#[Meta]first_pass().(id, this, graph, stack);
88
89 if meta.is_loop_initrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#is_loop_init. {
90 min_read = 1;
91 } else {
92 min_read = minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(min_read, meta.min_readrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#min_read. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1);
93 }
94 }
95 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(id) = fork.missrust-analyzer cargo logos-codegen 0.15.1 graph/fork/Fork#miss. {
96 let meta = self.first_passrust-analyzer cargo logos-codegen 0.15.1 graph/meta/impl#[Meta]first_pass().(id, this, graph, stack);
97
98 if meta.is_loop_initrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#is_loop_init. {
99 min_read = 0;
100 } else {
101 min_read = minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(min_read, meta.min_readrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#min_read.);
102 }
103 }
104 if min_read rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().usize::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]MAX. {
105 min_read = 0;
106 }
107 }
108 Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#::Roperust-analyzer cargo logos-codegen 0.15.1 graph/Node#Rope#(rope) => {
109 min_read = rope.patternrust-analyzer cargo logos-codegen 0.15.1 graph/rope/Rope#pattern..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
110 let meta = self.first_passrust-analyzer cargo logos-codegen 0.15.1 graph/meta/impl#[Meta]first_pass().(rope.thenrust-analyzer cargo logos-codegen 0.15.1 graph/rope/Rope#then., this, graph, stack);
111
112 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().meta.is_loop_initrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#is_loop_init. {
113 min_read rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().meta.min_readrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#min_read.;
114 }
115
116 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(id) = rope.missrust-analyzer cargo logos-codegen 0.15.1 graph/rope/Rope#miss..firstrust-analyzer cargo logos-codegen 0.15.1 graph/rope/impl#[Miss]first().() {
117 let meta = self.first_passrust-analyzer cargo logos-codegen 0.15.1 graph/meta/impl#[Meta]first_pass().(id, this, graph, stack);
118
119 if meta.is_loop_initrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#is_loop_init. {
120 min_read = 0;
121 } else {
122 min_read = minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(min_read, meta.min_readrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#min_read.);
123 }
124 }
125 }
126 Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#::Leafrust-analyzer cargo logos-codegen 0.15.1 graph/Node#Leaf#(_) => min_read = 0,
127 }
128
129 stack.poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().();
130
131 let meta = &mut self[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().this]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().;
132 meta.min_readrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#min_read. = min_read;
133 let second_pass = meta.loop_entry_fromrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#loop_entry_from..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().();
134
135 for id in second_pass {
136 self.meta_second_passrust-analyzer cargo logos-codegen 0.15.1 graph/meta/impl#[Meta]meta_second_pass().(id, graph);
137 }
138
139 &self[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().this]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().
140 }
141
142 fn meta_second_passrust-analyzer cargo logos-codegen 0.15.1 graph/meta/impl#[Meta]meta_second_pass().<T>(&mut self, id: NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId#, graph: &Graphrust-analyzer cargo logos-codegen 0.15.1 graph/Graph#<T>) {
143 let mut min_read;
144
145 match &graph[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().id]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). {
146 Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#::Forkrust-analyzer cargo logos-codegen 0.15.1 graph/Node#Fork#(fork) => {
147 min_read = usize::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]MAX.;
148 for (_, id) in fork.branchesrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]branches().() {
149 let meta = &self[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().id]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
150
151 if meta.is_loop_initrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#is_loop_init. {
152 min_read = 1;
153 } else {
154 min_read = minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(min_read, meta.min_readrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#min_read. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1);
155 }
156 }
157 if min_read rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().usize::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]MAX. {
158 min_read = 0;
159 }
160 }
161 Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#::Roperust-analyzer cargo logos-codegen 0.15.1 graph/Node#Rope#(rope) => {
162 min_read = rope.patternrust-analyzer cargo logos-codegen 0.15.1 graph/rope/Rope#pattern..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
163 let meta = &self[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().rope.thenrust-analyzer cargo logos-codegen 0.15.1 graph/rope/Rope#then.]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
164
165 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().meta.is_loop_initrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#is_loop_init. {
166 min_read rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().meta.min_readrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#min_read.;
167 }
168 }
169 Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#::Leafrust-analyzer cargo logos-codegen 0.15.1 graph/Node#Leaf#(_) => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!(),
170 }
171
172 self[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().id]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()..min_readrust-analyzer cargo logos-codegen 0.15.1 graph/meta/MetaItem#min_read. = min_read;
173 }
174 }