Keep ExpnId abstract by providing conversions

This commit is contained in:
Keegan McAllister 2014-09-28 09:25:48 -07:00
parent 9d60de93e2
commit 8826fdfe37
7 changed files with 21 additions and 8 deletions

View 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

View File

@ -345,7 +345,7 @@ unsafe extern "C" fn inline_asm_handler(diag: SMDiagnosticRef,
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()),
});

View 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));

View 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

View File

@ -26,6 +26,7 @@ source code snippets, etc.
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 {

View 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(),

View File

@ -33,6 +33,7 @@ extern crate debug;
#[phase(plugin, link)] extern crate log;
extern crate serialize;
extern crate term;
extern crate libc;
pub mod util {
pub mod interner;