syn_sem/semantic/tree/
mod.rs1mod format;
2mod inner;
3mod item;
4mod node;
5mod private;
6mod public;
7mod ty;
8
9pub use format::Brief;
12pub use item::{
13 Block, Const, Enum, Field, Fn, Local, Mod, PubItem, Struct, Trait, TypeAlias, Use, Variant,
14};
15pub use node::NodeIndex;
16pub use public::{pub_filter, PubPathTree};
17pub use ty::{
18 ArrayLen, Param, Type, TypeArray, TypeId, TypeMut, TypePath, TypeRef, TypeScalar, TypeTuple,
19 UniqueTypes,
20};
21
22#[cfg(test)]
23pub use ty::{OwnedParam, OwnedType};
24
25pub(crate) use inner::{
26 filter, PathTree, SearchTypeNotFound, SearchTypeNotReady, SearchTypeOk, SearchTypeResult,
27};
28pub(crate) use item::{
29 EffectiveItemKind, ItemTrait, PathVis, PrivItem, RawConst, RawEnum, RawField, RawFn, RawLocal,
30 RawMod, RawStruct, RawTrait, RawTypeAlias, RawUse, RawVariant,
31};
32pub(crate) use private::PrivPathTree;
33pub(crate) use public::AsPrivPathTree;
34
35use crate::{syntax::common::SynId, Map};
36use std::fmt;
37
38#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
41pub struct PathId {
42 pub(crate) ni: node::NodeIndex,
43 pub(crate) ii: item::ItemIndex,
44}
45
46impl PathId {
47 pub const fn node_index(&self) -> node::NodeIndex {
48 self.ni
49 }
50}
51
52impl fmt::Display for PathId {
53 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
54 write!(f, "({},{})", self.ni, self.ii)
55 }
56}
57
58impl fmt::Debug for PathId {
59 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60 write!(f, "({},{})", self.ni, self.ii)
61 }
62}
63
64#[derive(Debug, Default)]
67pub struct SynToPath(Map<SynId, PathId>);
68
69impl SynToPath {
70 pub(super) fn new() -> Self {
71 Self(Map::default())
72 }
73
74 pub(super) fn add_syn_to_path(&mut self, sid: SynId, pid: PathId) {
75 if let Some(old_pid) = self.0.insert(sid, pid) {
76 if old_pid != pid {
77 panic!(
78 "syn-path id conflicts: syn: `{}`, old_pid: {old_pid}, pid: {pid}",
79 sid.content(),
80 );
81 }
82 }
83 }
84
85 pub(super) fn get_path_id(&self, sid: SynId) -> Option<PathId> {
86 self.0.get(&sid).cloned()
87 }
88}