diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-01-11 15:03:15 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-01 18:58:08 +0100 |
| commit | 097d5e1c5edea1c0bf350b709087ddf5d60d2d9f (patch) | |
| tree | 5c1555c8d346774cab0028a3f3d73a78a8d7b9f5 /src/libsyntax | |
| parent | 93a8283614e995a0cf7a866356609b7522cfda24 (diff) | |
| download | rust-097d5e1c5edea1c0bf350b709087ddf5d60d2d9f.tar.gz rust-097d5e1c5edea1c0bf350b709087ddf5d60d2d9f.zip | |
1. move node_id to syntax
2. invert rustc_session & syntax deps 3. drop rustc_session dep in rustc_hir
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/Cargo.toml | 2 | ||||
| -rw-r--r-- | src/libsyntax/ast.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/lib.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/node_id.rs | 48 |
4 files changed, 50 insertions, 14 deletions
diff --git a/src/libsyntax/Cargo.toml b/src/libsyntax/Cargo.toml index 2e647d2a1e0..b3e16f740fd 100644 --- a/src/libsyntax/Cargo.toml +++ b/src/libsyntax/Cargo.toml @@ -16,9 +16,7 @@ scoped-tls = "1.0" rustc_errors = { path = "../librustc_errors" } rustc_span = { path = "../librustc_span" } rustc_data_structures = { path = "../librustc_data_structures" } -rustc_feature = { path = "../librustc_feature" } rustc_index = { path = "../librustc_index" } rustc_lexer = { path = "../librustc_lexer" } rustc_macros = { path = "../librustc_macros" } smallvec = { version = "1.0", features = ["union", "may_dangle"] } -rustc_session = { path = "../librustc_session" } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index db4fd53fe16..49f559de1b1 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -256,15 +256,7 @@ impl ParenthesizedArgs { } } -pub use rustc_session::node_id::NodeId; - -/// `NodeId` used to represent the root of the crate. -pub const CRATE_NODE_ID: NodeId = NodeId::from_u32_const(0); - -/// When parsing and doing expansions, we initially give all AST nodes this AST -/// node value. Then later, in the renumber pass, we renumber them to have -/// small, positive ids. -pub const DUMMY_NODE_ID: NodeId = NodeId::MAX; +pub use crate::node_id::{NodeId, CRATE_NODE_ID, DUMMY_NODE_ID}; /// A modifier on a bound, e.g., `?Sized` or `?const Trait`. /// @@ -432,8 +424,6 @@ pub struct WhereEqPredicate { pub rhs_ty: P<Ty>, } -pub use rustc_session::parse::CrateConfig; - #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct Crate { pub module: Mod, diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 9fcc7a1dfa8..a0b2d50cef3 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -41,8 +41,8 @@ pub mod attr; pub mod entry; pub mod expand; pub mod mut_visit; +pub mod node_id; pub mod ptr; -pub use rustc_session::parse as sess; pub mod token; pub mod tokenstream; pub mod visit; diff --git a/src/libsyntax/node_id.rs b/src/libsyntax/node_id.rs new file mode 100644 index 00000000000..58d2334a7b1 --- /dev/null +++ b/src/libsyntax/node_id.rs @@ -0,0 +1,48 @@ +use rustc_serialize::{Decoder, Encoder}; +use rustc_span::ExpnId; +use std::fmt; + +rustc_index::newtype_index! { + pub struct NodeId { + ENCODABLE = custom + DEBUG_FORMAT = "NodeId({})" + } +} + +rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeId); + +/// `NodeId` used to represent the root of the crate. +pub const CRATE_NODE_ID: NodeId = NodeId::from_u32_const(0); + +/// When parsing and doing expansions, we initially give all AST nodes this AST +/// node value. Then later, in the renumber pass, we renumber them to have +/// small, positive ids. +pub const DUMMY_NODE_ID: NodeId = NodeId::MAX; + +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) + } +} + +impl rustc_serialize::UseSpecializedEncodable for NodeId { + fn default_encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { + s.emit_u32(self.as_u32()) + } +} + +impl rustc_serialize::UseSpecializedDecodable for NodeId { + fn default_decode<D: Decoder>(d: &mut D) -> Result<NodeId, D::Error> { + d.read_u32().map(NodeId::from_u32) + } +} |
