2019-12-31 11:15:40 -06:00
|
|
|
use rustc_span::ExpnId;
|
2019-12-22 16:42:04 -06:00
|
|
|
use std::fmt;
|
2019-11-29 14:41:22 -06:00
|
|
|
|
|
|
|
rustc_index::newtype_index! {
|
|
|
|
pub struct NodeId {
|
|
|
|
DEBUG_FORMAT = "NodeId({})"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-24 15:42:56 -06:00
|
|
|
rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeId);
|
|
|
|
|
2020-01-11 08:03:15 -06:00
|
|
|
/// `NodeId` used to represent the root of the crate.
|
2020-03-10 15:44:53 -05:00
|
|
|
pub const CRATE_NODE_ID: NodeId = NodeId::from_u32(0);
|
2020-01-11 08:03:15 -06:00
|
|
|
|
|
|
|
/// When parsing and doing expansions, we initially give all AST nodes this AST
|
The renumber pass is long gone
Originally, there has been a dedicated pass for renumbering
AST NodeIds to have actual values. This pass had been added by
commit a5ad4c379466519a0bf977864a5cdc50a7ade385.
Then, later, this step was moved to where it resides now,
macro expansion. See commit c86c8d41a26b2037e80c9fd028a59313a78b3a66
or PR #36438.
The comment snippet, added by the original commit, has
survived the times without any change, becoming outdated
at removal of the dedicated pass.
Nowadays, grepping for the next_node_id function will show up
multiple places in the compiler that call it, but the main
rewriting that the comment talks about is still done in the
expansion step, inside an innocious looking visit_id function
that's called during macro invocation collection.
2020-11-05 20:03:22 -06:00
|
|
|
/// node value. Then later, during expansion, we renumber them to have small,
|
|
|
|
/// positive ids.
|
2020-01-11 08:03:15 -06:00
|
|
|
pub const DUMMY_NODE_ID: NodeId = NodeId::MAX;
|
|
|
|
|
2019-11-29 14:41:22 -06:00
|
|
|
impl NodeId {
|
|
|
|
pub fn placeholder_from_expn_id(expn_id: ExpnId) -> Self {
|
|
|
|
NodeId::from_u32(expn_id.as_u32())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn placeholder_to_expn_id(self) -> ExpnId {
|
|
|
|
ExpnId::from_u32(self.as_u32())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for NodeId {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
fmt::Display::fmt(&self.as_u32(), f)
|
|
|
|
}
|
|
|
|
}
|