syntax/ext: migrate build.rs functions to AstBuilder methods.
This commit is contained in:
parent
8c15a0ec4c
commit
6e50515530
19 changed files with 1126 additions and 925 deletions
|
@ -14,7 +14,7 @@ use codemap::{FileMap, Loc, Pos, ExpandedFrom, span};
|
|||
use codemap::{CallInfo, NameAndSpan};
|
||||
use ext::base::*;
|
||||
use ext::base;
|
||||
use ext::build::{mk_base_vec_e, mk_uint, mk_u8, mk_base_str};
|
||||
use ext::build::AstBuilder;
|
||||
use parse;
|
||||
use print::pprust;
|
||||
|
||||
|
@ -30,7 +30,7 @@ pub fn expand_line(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
|
|||
let topmost = topmost_expn_info(cx.backtrace().get());
|
||||
let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo);
|
||||
|
||||
base::MRExpr(mk_uint(cx, topmost.call_site, loc.line))
|
||||
base::MRExpr(cx.mk_uint(topmost.call_site, loc.line))
|
||||
}
|
||||
|
||||
/* col!(): expands to the current column number */
|
||||
|
@ -40,7 +40,7 @@ pub fn expand_col(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
|
|||
|
||||
let topmost = topmost_expn_info(cx.backtrace().get());
|
||||
let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo);
|
||||
base::MRExpr(mk_uint(cx, topmost.call_site, loc.col.to_uint()))
|
||||
base::MRExpr(cx.mk_uint(topmost.call_site, loc.col.to_uint()))
|
||||
}
|
||||
|
||||
/* file!(): expands to the current filename */
|
||||
|
@ -53,19 +53,19 @@ pub fn expand_file(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
|
|||
let topmost = topmost_expn_info(cx.backtrace().get());
|
||||
let Loc { file: @FileMap { name: filename, _ }, _ } =
|
||||
cx.codemap().lookup_char_pos(topmost.call_site.lo);
|
||||
base::MRExpr(mk_base_str(cx, topmost.call_site, filename))
|
||||
base::MRExpr(cx.mk_base_str(topmost.call_site, filename))
|
||||
}
|
||||
|
||||
pub fn expand_stringify(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
|
||||
-> base::MacResult {
|
||||
let s = pprust::tts_to_str(tts, cx.parse_sess().interner);
|
||||
base::MRExpr(mk_base_str(cx, sp, s))
|
||||
base::MRExpr(cx.mk_base_str(sp, s))
|
||||
}
|
||||
|
||||
pub fn expand_mod(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
|
||||
-> base::MacResult {
|
||||
base::check_zero_tts(cx, sp, tts, "module_path!");
|
||||
base::MRExpr(mk_base_str(cx, sp,
|
||||
base::MRExpr(cx.mk_base_str(sp,
|
||||
str::connect(cx.mod_path().map(
|
||||
|x| cx.str_of(*x)), "::")))
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ pub fn expand_include_str(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
|
|||
}
|
||||
}
|
||||
|
||||
base::MRExpr(mk_base_str(cx, sp, result::unwrap(res)))
|
||||
base::MRExpr(cx.mk_base_str(sp, result::unwrap(res)))
|
||||
}
|
||||
|
||||
pub fn expand_include_bin(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
|
||||
|
@ -103,9 +103,9 @@ pub fn expand_include_bin(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
|
|||
match io::read_whole_file(&res_rel_file(cx, sp, &Path(file))) {
|
||||
result::Ok(src) => {
|
||||
let u8_exprs = vec::map(src, |char| {
|
||||
mk_u8(cx, sp, *char)
|
||||
cx.mk_u8(sp, *char)
|
||||
});
|
||||
base::MRExpr(mk_base_vec_e(cx, sp, u8_exprs))
|
||||
base::MRExpr(cx.mk_base_vec_e(sp, u8_exprs))
|
||||
}
|
||||
result::Err(ref e) => {
|
||||
cx.parse_sess().span_diagnostic.handler().fatal((*e))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue