hydroper_razen/semantics/
unused.rs1use crate::ns::*;
2
3pub struct Unused<'a>(pub &'a SemanticHost);
4
5impl<'a> Unused<'a> {
6 pub fn all(&self) -> std::cell::Ref<Vec<Thingy>> {
7 self.0.unused_things()
8 }
9
10 pub fn is_unused(&self, thingy: &Thingy) -> bool {
11 self.0.is_unused(thingy)
12 }
13
14 pub(crate) fn add(&self, thing: &Thingy) {
15 self.0.add_unused_thing(thing);
16 }
17
18 pub(crate) fn add_named_entity(&self, thing: &Thingy) {
19 let name = thing.name();
20 if name.in_public_or_protected_ns() || name.local_name().starts_with('_') {
21 return;
22 }
23 self.add(thing);
24 }
25
26 pub fn mark_used(&self, property: &Thingy) {
27 if property.is::<InvalidationThingy>() {
28 return;
29 }
30 let qn = property.name();
31 if !qn.in_public_or_protected_ns() {
32 if property.is_entity_after_substitution() {
33 self.mark_used(&property.origin());
34 } else {
35 self.0.remove_unused_thing(property);
36 }
37 }
38 }
39}