Skip to content

Commit 8826fdf

Browse files
author
Keegan McAllister
committed
Keep ExpnId abstract by providing conversions
1 parent 9d60de9 commit 8826fdf

File tree

7 files changed

+21
-8
lines changed

7 files changed

+21
-8
lines changed

mk/crates.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ DEPS_graphviz := std
7171
DEPS_green := std native:context_switch
7272
DEPS_rustuv := std native:uv native:uv_support
7373
DEPS_native := std
74-
DEPS_syntax := std term serialize log fmt_macros debug arena
74+
DEPS_syntax := std term serialize log fmt_macros debug arena libc
7575
DEPS_rustc := syntax flate arena serialize getopts rbml \
7676
time log graphviz debug rustc_llvm rustc_back
7777
DEPS_rustc_llvm := native:rustllvm libc std

src/librustc/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ unsafe extern "C" fn inline_asm_handler(diag: SMDiagnosticRef,
345345

346346
match cgcx.lto_ctxt {
347347
Some((sess, _)) => {
348-
sess.codemap().with_expn_info(ExpnId(cookie as u32), |info| match info {
348+
sess.codemap().with_expn_info(ExpnId::from_llvm_cookie(cookie), |info| match info {
349349
Some(ei) => sess.span_err(ei.call_site, msg.as_slice()),
350350
None => sess.err(msg.as_slice()),
351351
});

src/librustc/middle/trans/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pub fn trans_inline_asm<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ia: &ast::InlineAsm)
149149
let kind = llvm::LLVMGetMDKindIDInContext(bcx.ccx().llcx(),
150150
key.as_ptr() as *const c_char, key.len() as c_uint);
151151

152-
let val: llvm::ValueRef = C_i32(bcx.ccx(), ia.expn_id as i32);
152+
let val: llvm::ValueRef = C_i32(bcx.ccx(), ia.expn_id.to_llvm_cookie());
153153

154154
llvm::LLVMSetMetadata(r, kind,
155155
llvm::LLVMMDNodeInContext(bcx.ccx().llcx(), &val, 1));

src/libsyntax/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// The Rust abstract syntax tree.
1212

13-
use codemap::{Span, Spanned, DUMMY_SP};
13+
use codemap::{Span, Spanned, DUMMY_SP, ExpnId};
1414
use abi::Abi;
1515
use ast_util;
1616
use owned_slice::OwnedSlice;
@@ -984,7 +984,7 @@ pub struct InlineAsm {
984984
pub volatile: bool,
985985
pub alignstack: bool,
986986
pub dialect: AsmDialect,
987-
pub expn_id: u32,
987+
pub expn_id: ExpnId,
988988
}
989989

990990
/// represents an argument in a function header

src/libsyntax/codemap.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ source code snippets, etc.
2626
use serialize::{Encodable, Decodable, Encoder, Decoder};
2727
use std::cell::RefCell;
2828
use std::rc::Rc;
29+
use libc::c_uint;
2930

3031
pub trait Pos {
3132
fn from_uint(n: uint) -> Self;
@@ -223,11 +224,22 @@ pub struct ExpnInfo {
223224
pub callee: NameAndSpan
224225
}
225226

226-
#[deriving(PartialEq, Eq, Clone, Show, Hash)]
227-
pub struct ExpnId(pub u32);
227+
#[deriving(PartialEq, Eq, Clone, Show, Hash, Encodable, Decodable)]
228+
pub struct ExpnId(u32);
228229

229230
pub static NO_EXPANSION: ExpnId = ExpnId(-1);
230231

232+
impl ExpnId {
233+
pub fn from_llvm_cookie(cookie: c_uint) -> ExpnId {
234+
ExpnId(cookie as u32)
235+
}
236+
237+
pub fn to_llvm_cookie(self) -> i32 {
238+
let ExpnId(cookie) = self;
239+
cookie as i32
240+
}
241+
}
242+
231243
pub type FileName = String;
232244

233245
pub struct FileLines {

src/libsyntax/ext/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
199199
}
200200
}
201201

202-
let codemap::ExpnId(expn_id) = cx.codemap().record_expansion(codemap::ExpnInfo {
202+
let expn_id = cx.codemap().record_expansion(codemap::ExpnInfo {
203203
call_site: sp,
204204
callee: codemap::NameAndSpan {
205205
name: "asm".to_string(),

src/libsyntax/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extern crate debug;
3333
#[phase(plugin, link)] extern crate log;
3434
extern crate serialize;
3535
extern crate term;
36+
extern crate libc;
3637

3738
pub mod util {
3839
pub mod interner;

0 commit comments

Comments
 (0)