]> git.lizzy.rs Git - rust.git/commitdiff
Keep ExpnId abstract by providing conversions
authorKeegan McAllister <kmcallister@mozilla.com>
Sun, 28 Sep 2014 16:25:48 +0000 (09:25 -0700)
committerKeegan McAllister <kmcallister@mozilla.com>
Sun, 28 Sep 2014 16:25:48 +0000 (09:25 -0700)
mk/crates.mk
src/librustc/back/write.rs
src/librustc/middle/trans/asm.rs
src/libsyntax/ast.rs
src/libsyntax/codemap.rs
src/libsyntax/ext/asm.rs
src/libsyntax/lib.rs

index ed3fce775f31e7aa8d4a652d2299df608a2e37c0..9f01ff23c7fc93c7956285d174463cce288f7484 100644 (file)
@@ -71,7 +71,7 @@ DEPS_graphviz := std
 DEPS_green := std native:context_switch
 DEPS_rustuv := std native:uv native:uv_support
 DEPS_native := std
-DEPS_syntax := std term serialize log fmt_macros debug arena
+DEPS_syntax := std term serialize log fmt_macros debug arena libc
 DEPS_rustc := syntax flate arena serialize getopts rbml \
               time log graphviz debug rustc_llvm rustc_back
 DEPS_rustc_llvm := native:rustllvm libc std
index 8e703d954f3009467ad51b829ec7a327e09a3f12..7b4d1780ccd690fb072fcd600e29fb6103df936f 100644 (file)
@@ -345,7 +345,7 @@ struct HandlerFreeVars<'a> {
 
     match cgcx.lto_ctxt {
         Some((sess, _)) => {
-            sess.codemap().with_expn_info(ExpnId(cookie as u32), |info| match info {
+            sess.codemap().with_expn_info(ExpnId::from_llvm_cookie(cookie), |info| match info {
                 Some(ei) => sess.span_err(ei.call_site, msg.as_slice()),
                 None     => sess.err(msg.as_slice()),
             });
index b4c10c78db874ea21defad9e3ddc35fa82a7eae4..c51e242026241c72ee355dc4c7781e29368d8114 100644 (file)
@@ -149,7 +149,7 @@ pub fn trans_inline_asm<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ia: &ast::InlineAsm)
         let kind = llvm::LLVMGetMDKindIDInContext(bcx.ccx().llcx(),
             key.as_ptr() as *const c_char, key.len() as c_uint);
 
-        let val: llvm::ValueRef = C_i32(bcx.ccx(), ia.expn_id as i32);
+        let val: llvm::ValueRef = C_i32(bcx.ccx(), ia.expn_id.to_llvm_cookie());
 
         llvm::LLVMSetMetadata(r, kind,
             llvm::LLVMMDNodeInContext(bcx.ccx().llcx(), &val, 1));
index 43d6b9b9e905af75376d259686842bd28a548394..0fee3ff32185049f222e304b143f72d0cbda1961 100644 (file)
@@ -10,7 +10,7 @@
 
 // The Rust abstract syntax tree.
 
-use codemap::{Span, Spanned, DUMMY_SP};
+use codemap::{Span, Spanned, DUMMY_SP, ExpnId};
 use abi::Abi;
 use ast_util;
 use owned_slice::OwnedSlice;
@@ -984,7 +984,7 @@ pub struct InlineAsm {
     pub volatile: bool,
     pub alignstack: bool,
     pub dialect: AsmDialect,
-    pub expn_id: u32,
+    pub expn_id: ExpnId,
 }
 
 /// represents an argument in a function header
index d44de7862a33a564591a03ef9ac9012fd7bc539f..e9b2556c53e25dd5a86c78e3cc2d90962b6f997f 100644 (file)
@@ -26,6 +26,7 @@
 use serialize::{Encodable, Decodable, Encoder, Decoder};
 use std::cell::RefCell;
 use std::rc::Rc;
+use libc::c_uint;
 
 pub trait Pos {
     fn from_uint(n: uint) -> Self;
@@ -223,11 +224,22 @@ pub struct ExpnInfo {
     pub callee: NameAndSpan
 }
 
-#[deriving(PartialEq, Eq, Clone, Show, Hash)]
-pub struct ExpnId(pub u32);
+#[deriving(PartialEq, Eq, Clone, Show, Hash, Encodable, Decodable)]
+pub struct ExpnId(u32);
 
 pub static NO_EXPANSION: ExpnId = ExpnId(-1);
 
+impl ExpnId {
+    pub fn from_llvm_cookie(cookie: c_uint) -> ExpnId {
+        ExpnId(cookie as u32)
+    }
+
+    pub fn to_llvm_cookie(self) -> i32 {
+        let ExpnId(cookie) = self;
+        cookie as i32
+    }
+}
+
 pub type FileName = String;
 
 pub struct FileLines {
index f82fe4b13a212d106af2335c1bc98bc01ddf4e3b..702be0c0eeede090cb501a24a57de7d2983c99d4 100644 (file)
@@ -199,7 +199,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
         }
     }
 
-    let codemap::ExpnId(expn_id) = cx.codemap().record_expansion(codemap::ExpnInfo {
+    let expn_id = cx.codemap().record_expansion(codemap::ExpnInfo {
         call_site: sp,
         callee: codemap::NameAndSpan {
             name: "asm".to_string(),
index 7a504d22c1e9e192a4dce9ec7add4d76b071fbda..a42715441465470b6516b5392e10f0e8bd31bd0a 100644 (file)
@@ -33,6 +33,7 @@
 #[phase(plugin, link)] extern crate log;
 extern crate serialize;
 extern crate term;
+extern crate libc;
 
 pub mod util {
     pub mod interner;