Rename some things and turn macro to macro def into a query

This commit is contained in:
Lukas Wirth 2023-12-21 09:18:06 +01:00
parent 071fe4e4e9
commit 51a9e7831a
21 changed files with 165 additions and 163 deletions

View file

@ -199,6 +199,19 @@ impl AstIdMap {
FileAstId { raw, covariant: PhantomData }
}
pub fn ast_id_for_ptr<N: AstIdNode>(&self, ptr: AstPtr<N>) -> FileAstId<N> {
let ptr = ptr.syntax_node_ptr();
let hash = hash_ptr(&ptr);
match self.map.raw_entry().from_hash(hash, |&idx| self.arena[idx] == ptr) {
Some((&raw, &())) => FileAstId { raw, covariant: PhantomData },
None => panic!(
"Can't find {:?} in AstIdMap:\n{:?}",
ptr,
self.arena.iter().map(|(_id, i)| i).collect::<Vec<_>>(),
),
}
}
pub fn get<N: AstIdNode>(&self, id: FileAstId<N>) -> AstPtr<N> {
AstPtr::try_from_raw(self.arena[id.raw].clone()).unwrap()
}