]> git.lizzy.rs Git - rust.git/commitdiff
move def-id to rustc crate
authorNiko Matsakis <niko@alum.mit.edu>
Sun, 16 Aug 2015 10:31:58 +0000 (06:31 -0400)
committerNiko Matsakis <niko@alum.mit.edu>
Mon, 24 Aug 2015 09:34:58 +0000 (05:34 -0400)
src/librustc/lib.rs
src/librustc/middle/def_id.rs [new file with mode: 0644]
src/libsyntax/ast.rs
src/libsyntax/ast_util.rs

index 1047f51e95ffc261216f44f1038208825a4efcca..07ca6129505a6ceb9210016a213702726846205e 100644 (file)
@@ -118,6 +118,7 @@ pub mod middle {
     pub mod dataflow;
     pub mod dead;
     pub mod def;
+    pub mod def_id;
     pub mod dependency_format;
     pub mod effect;
     pub mod entry;
diff --git a/src/librustc/middle/def_id.rs b/src/librustc/middle/def_id.rs
new file mode 100644 (file)
index 0000000..b91ccc2
--- /dev/null
@@ -0,0 +1,55 @@
+// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use syntax::ast::{CrateNum, NodeId};
+use std::cell::Cell;
+use std::fmt;
+
+#[derive(Clone, Eq, Ord, PartialOrd, PartialEq, RustcEncodable,
+           RustcDecodable, Hash, Copy)]
+pub struct DefId {
+    pub krate: CrateNum,
+    pub node: NodeId,
+}
+
+fn default_def_id_debug(_: DefId, _: &mut fmt::Formatter) -> fmt::Result { Ok(()) }
+
+thread_local!(pub static DEF_ID_DEBUG: Cell<fn(DefId, &mut fmt::Formatter) -> fmt::Result> =
+                Cell::new(default_def_id_debug));
+
+impl fmt::Debug for DefId {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        try!(write!(f, "DefId {{ krate: {}, node: {} }}",
+                    self.krate, self.node));
+        DEF_ID_DEBUG.with(|def_id_debug| def_id_debug.get()(*self, f))
+    }
+}
+
+impl DefId {
+    pub fn local(id: NodeId) -> DefId {
+        DefId { krate: LOCAL_CRATE, node: id }
+    }
+
+    /// Read the node id, asserting that this def-id is krate-local.
+    pub fn local_id(&self) -> NodeId {
+        assert_eq!(self.krate, LOCAL_CRATE);
+        self.node
+    }
+
+    pub fn is_local(&self) -> bool {
+        self.krate == LOCAL_CRATE
+    }
+}
+
+
+/// Item definitions in the currently-compiled crate would have the CrateNum
+/// LOCAL_CRATE in their DefId.
+pub const LOCAL_CRATE: CrateNum = 0;
+
index cd0705f543b238101555d3af6bb4b5c7a7353b80..66faa1227e6d6914707513d6dc5168c101fd17b1 100644 (file)
@@ -65,7 +65,6 @@
 use print::pprust;
 use ptr::P;
 
-use std::cell::Cell;
 use std::fmt;
 use std::rc::Rc;
 use serialize::{Encodable, Decodable, Encoder, Decoder};
@@ -371,37 +370,7 @@ pub struct ParenthesizedParameterData {
 
 pub type NodeId = u32;
 
-#[derive(Clone, Eq, Ord, PartialOrd, PartialEq, RustcEncodable,
-           RustcDecodable, Hash, Copy)]
-pub struct DefId {
-    pub krate: CrateNum,
-    pub node: NodeId,
-}
-
-fn default_def_id_debug(_: DefId, _: &mut fmt::Formatter) -> fmt::Result { Ok(()) }
-
-thread_local!(pub static DEF_ID_DEBUG: Cell<fn(DefId, &mut fmt::Formatter) -> fmt::Result> =
-                Cell::new(default_def_id_debug));
-
-impl fmt::Debug for DefId {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        try!(write!(f, "DefId {{ krate: {}, node: {} }}",
-                    self.krate, self.node));
-        DEF_ID_DEBUG.with(|def_id_debug| def_id_debug.get()(*self, f))
-    }
-}
-
-impl DefId {
-    /// Read the node id, asserting that this def-id is krate-local.
-    pub fn local_id(&self) -> NodeId {
-        assert_eq!(self.krate, LOCAL_CRATE);
-        self.node
-    }
-}
-
-/// Item definitions in the currently-compiled crate would have the CrateNum
-/// LOCAL_CRATE in their DefId.
-pub const LOCAL_CRATE: CrateNum = 0;
+/// Node id used to represent the root of the crate.
 pub const CRATE_NODE_ID: NodeId = 0;
 
 /// When parsing and doing expansions, we initially give all AST nodes this AST
index 7aff92ecb709080b6f97d0933a5b6ee290e55b38..45a41edae6c3744fe31ff38912168b5e520657a3 100644 (file)
@@ -28,12 +28,6 @@ pub fn path_name_i(idents: &[Ident]) -> String {
     idents.iter().map(|i| i.to_string()).collect::<Vec<String>>().join("::")
 }
 
-pub fn local_def(id: NodeId) -> DefId {
-    ast::DefId { krate: LOCAL_CRATE, node: id }
-}
-
-pub fn is_local(did: ast::DefId) -> bool { did.krate == LOCAL_CRATE }
-
 pub fn stmt_id(s: &Stmt) -> NodeId {
     match s.node {
       StmtDecl(_, id) => id,