mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-11 23:33:00 +00:00
renaming to adhere to conventions
This commit is contained in:
parent
6dbfb5da0b
commit
0b958e74ac
@ -33,8 +33,6 @@ macro_rules! interner_key (
|
||||
(-3 as uint, 0u)))
|
||||
)
|
||||
|
||||
// FIXME(#3534): Replace with the struct-based newtype when it's been
|
||||
// implemented.
|
||||
struct ident { repr: uint }
|
||||
|
||||
impl<S: Encoder> ident: Encodable<S> {
|
||||
|
@ -25,65 +25,65 @@ use std::map::HashMap;
|
||||
|
||||
// new-style macro! tt code:
|
||||
//
|
||||
// syntax_expander_tt, syntax_expander_tt_item, mac_result,
|
||||
// normal_tt, item_tt
|
||||
// SyntaxExpanderTT, SyntaxExpanderTTItem, MacResult,
|
||||
// NormalTT, ItemTT
|
||||
//
|
||||
// also note that ast::mac used to have a bunch of extraneous cases and
|
||||
// is now probably a redundant AST node, can be merged with
|
||||
// ast::mac_invoc_tt.
|
||||
|
||||
struct macro_def {
|
||||
struct MacroDef {
|
||||
name: ~str,
|
||||
ext: syntax_extension,
|
||||
ext: SyntaxExtension
|
||||
}
|
||||
|
||||
type item_decorator =
|
||||
type ItemDecorator =
|
||||
fn@(ext_ctxt, span, ast::meta_item, ~[@ast::item]) -> ~[@ast::item];
|
||||
|
||||
struct syntax_expander_tt {
|
||||
expander: syntax_expander_tt_,
|
||||
span: Option<span>,
|
||||
struct SyntaxExpanderTT {
|
||||
expander: SyntaxExpanderTTFun,
|
||||
span: Option<span>
|
||||
}
|
||||
|
||||
type syntax_expander_tt_ = fn@(ext_ctxt, span, ~[ast::token_tree])
|
||||
-> mac_result;
|
||||
type SyntaxExpanderTTFun = fn@(ext_ctxt, span, ~[ast::token_tree])
|
||||
-> MacResult;
|
||||
|
||||
struct syntax_expander_tt_item {
|
||||
expander: syntax_expander_tt_item_,
|
||||
span: Option<span>,
|
||||
struct SyntaxExpanderTTItem {
|
||||
expander: SyntaxExpanderTTItemFun,
|
||||
span: Option<span>
|
||||
}
|
||||
|
||||
type syntax_expander_tt_item_
|
||||
= fn@(ext_ctxt, span, ast::ident, ~[ast::token_tree]) -> mac_result;
|
||||
type SyntaxExpanderTTItemFun
|
||||
= fn@(ext_ctxt, span, ast::ident, ~[ast::token_tree]) -> MacResult;
|
||||
|
||||
enum mac_result {
|
||||
mr_expr(@ast::expr),
|
||||
mr_item(@ast::item),
|
||||
mr_any(fn@()-> @ast::expr, fn@()-> Option<@ast::item>, fn@()->@ast::stmt),
|
||||
mr_def(macro_def)
|
||||
enum MacResult {
|
||||
MRExpr(@ast::expr),
|
||||
MRItem(@ast::item),
|
||||
MRAny(fn@()-> @ast::expr, fn@()-> Option<@ast::item>, fn@()->@ast::stmt),
|
||||
MRDef(MacroDef)
|
||||
}
|
||||
|
||||
enum syntax_extension {
|
||||
enum SyntaxExtension {
|
||||
|
||||
// #[auto_encode] and such
|
||||
item_decorator(item_decorator),
|
||||
ItemDecorator(ItemDecorator),
|
||||
|
||||
// Token-tree expanders
|
||||
normal_tt(syntax_expander_tt),
|
||||
NormalTT(SyntaxExpanderTT),
|
||||
|
||||
// perhaps macro_rules! will lose its odd special identifier argument,
|
||||
// and this can go away also
|
||||
item_tt(syntax_expander_tt_item),
|
||||
ItemTT(SyntaxExpanderTTItem),
|
||||
}
|
||||
|
||||
// A temporary hard-coded map of methods for expanding syntax extension
|
||||
// AST nodes into full ASTs
|
||||
fn syntax_expander_table() -> HashMap<~str, syntax_extension> {
|
||||
fn builtin_normal_tt(f: syntax_expander_tt_) -> syntax_extension {
|
||||
normal_tt(syntax_expander_tt {expander: f, span: None})
|
||||
fn syntax_expander_table() -> HashMap<~str, SyntaxExtension> {
|
||||
fn builtin_normal_tt(f: SyntaxExpanderTTFun) -> SyntaxExtension {
|
||||
NormalTT(SyntaxExpanderTT{expander: f, span: None})
|
||||
}
|
||||
fn builtin_item_tt(f: syntax_expander_tt_item_) -> syntax_extension {
|
||||
item_tt(syntax_expander_tt_item {expander: f, span: None})
|
||||
fn builtin_item_tt(f: SyntaxExpanderTTItemFun) -> SyntaxExtension {
|
||||
ItemTT(SyntaxExpanderTTItem{expander: f, span: None})
|
||||
}
|
||||
let syntax_expanders = HashMap();
|
||||
syntax_expanders.insert(~"macro_rules",
|
||||
@ -93,10 +93,10 @@ fn syntax_expander_table() -> HashMap<~str, syntax_extension> {
|
||||
builtin_normal_tt(ext::fmt::expand_syntax_ext));
|
||||
syntax_expanders.insert(
|
||||
~"auto_encode",
|
||||
item_decorator(ext::auto_encode::expand_auto_encode));
|
||||
ItemDecorator(ext::auto_encode::expand_auto_encode));
|
||||
syntax_expanders.insert(
|
||||
~"auto_decode",
|
||||
item_decorator(ext::auto_encode::expand_auto_decode));
|
||||
ItemDecorator(ext::auto_encode::expand_auto_decode));
|
||||
syntax_expanders.insert(~"env",
|
||||
builtin_normal_tt(ext::env::expand_syntax_ext));
|
||||
syntax_expanders.insert(~"concat_idents",
|
||||
@ -106,10 +106,10 @@ fn syntax_expander_table() -> HashMap<~str, syntax_extension> {
|
||||
builtin_normal_tt(
|
||||
ext::log_syntax::expand_syntax_ext));
|
||||
syntax_expanders.insert(~"deriving_eq",
|
||||
item_decorator(
|
||||
ItemDecorator(
|
||||
ext::deriving::expand_deriving_eq));
|
||||
syntax_expanders.insert(~"deriving_iter_bytes",
|
||||
item_decorator(
|
||||
ItemDecorator(
|
||||
ext::deriving::expand_deriving_iter_bytes));
|
||||
|
||||
// Quasi-quoting expanders
|
||||
|
@ -14,7 +14,7 @@ use ext::base::*;
|
||||
use ext::base;
|
||||
|
||||
fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
|
||||
-> base::mac_result {
|
||||
-> base::MacResult {
|
||||
let mut res_str = ~"";
|
||||
for tts.eachi |i, e| {
|
||||
if i & 1 == 1 {
|
||||
@ -48,5 +48,5 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
|
||||
),
|
||||
span: sp,
|
||||
};
|
||||
mr_expr(e)
|
||||
MRExpr(e)
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ use core::os;
|
||||
export expand_syntax_ext;
|
||||
|
||||
fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
|
||||
-> base::mac_result {
|
||||
-> base::MacResult {
|
||||
|
||||
let var = get_single_str_from_tts(cx, sp, tts, "env!");
|
||||
|
||||
@ -36,7 +36,7 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
|
||||
option::None => mk_uniq_str(cx, sp, ~""),
|
||||
option::Some(ref s) => mk_uniq_str(cx, sp, (*s))
|
||||
};
|
||||
mr_expr(e)
|
||||
MRExpr(e)
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -22,7 +22,7 @@ use core::option;
|
||||
use core::vec;
|
||||
use std::map::HashMap;
|
||||
|
||||
fn expand_expr(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
|
||||
fn expand_expr(exts: HashMap<~str, SyntaxExtension>, cx: ext_ctxt,
|
||||
e: expr_, s: span, fld: ast_fold,
|
||||
orig: fn@(expr_, span, ast_fold) -> (expr_, span))
|
||||
-> (expr_, span)
|
||||
@ -46,15 +46,13 @@ fn expand_expr(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
|
||||
cx.span_fatal(pth.span,
|
||||
fmt!("macro undefined: '%s'", *extname))
|
||||
}
|
||||
Some(normal_tt(
|
||||
syntax_expander_tt { expander: exp, span: exp_sp }
|
||||
)) => {
|
||||
Some(NormalTT(SyntaxExpanderTT{expander: exp, span: exp_sp})) => {
|
||||
cx.bt_push(ExpandedFrom({call_site: s,
|
||||
callie: {name: *extname, span: exp_sp}}));
|
||||
|
||||
let expanded = match exp(cx, (*mac).span, (*tts)) {
|
||||
mr_expr(e) => e,
|
||||
mr_any(expr_maker,_,_) => expr_maker(),
|
||||
MRExpr(e) => e,
|
||||
MRAny(expr_maker,_,_) => expr_maker(),
|
||||
_ => cx.span_fatal(
|
||||
pth.span, fmt!("non-expr macro in expr pos: %s",
|
||||
*extname))
|
||||
@ -85,11 +83,11 @@ fn expand_expr(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
|
||||
// attribute prefixing an item, and are interpreted by feeding the item
|
||||
// through the named attribute _as a syntax extension_ and splicing in the
|
||||
// resulting item vec into place in favour of the decorator. Note that
|
||||
// these do _not_ work for macro extensions, just item_decorator ones.
|
||||
// these do _not_ work for macro extensions, just ItemDecorator ones.
|
||||
//
|
||||
// NB: there is some redundancy between this and expand_item, below, and
|
||||
// they might benefit from some amount of semantic and language-UI merger.
|
||||
fn expand_mod_items(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
|
||||
fn expand_mod_items(exts: HashMap<~str, SyntaxExtension>, cx: ext_ctxt,
|
||||
module_: ast::_mod, fld: ast_fold,
|
||||
orig: fn@(ast::_mod, ast_fold) -> ast::_mod)
|
||||
-> ast::_mod
|
||||
@ -108,8 +106,8 @@ fn expand_mod_items(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
|
||||
ast::meta_list(ref n, _) => (*n)
|
||||
};
|
||||
match exts.find(mname) {
|
||||
None | Some(normal_tt(_)) | Some(item_tt(*)) => items,
|
||||
Some(item_decorator(dec_fn)) => {
|
||||
None | Some(NormalTT(_)) | Some(ItemTT(*)) => items,
|
||||
Some(ItemDecorator(dec_fn)) => {
|
||||
cx.bt_push(ExpandedFrom({call_site: attr.span,
|
||||
callie: {name: copy mname,
|
||||
span: None}}));
|
||||
@ -126,7 +124,7 @@ fn expand_mod_items(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
|
||||
|
||||
|
||||
// When we enter a module, record it, for the sake of `module!`
|
||||
fn expand_item(exts: HashMap<~str, syntax_extension>,
|
||||
fn expand_item(exts: HashMap<~str, SyntaxExtension>,
|
||||
cx: ext_ctxt, &&it: @ast::item, fld: ast_fold,
|
||||
orig: fn@(&&v: @ast::item, ast_fold) -> Option<@ast::item>)
|
||||
-> Option<@ast::item>
|
||||
@ -153,7 +151,7 @@ fn expand_item(exts: HashMap<~str, syntax_extension>,
|
||||
|
||||
// Support for item-position macro invocations, exactly the same
|
||||
// logic as for expression-position macro invocations.
|
||||
fn expand_item_mac(exts: HashMap<~str, syntax_extension>,
|
||||
fn expand_item_mac(exts: HashMap<~str, SyntaxExtension>,
|
||||
cx: ext_ctxt, &&it: @ast::item,
|
||||
fld: ast_fold) -> Option<@ast::item> {
|
||||
|
||||
@ -169,7 +167,7 @@ fn expand_item_mac(exts: HashMap<~str, syntax_extension>,
|
||||
None => cx.span_fatal(pth.span,
|
||||
fmt!("macro undefined: '%s!'", *extname)),
|
||||
|
||||
Some(normal_tt(ref expand)) => {
|
||||
Some(NormalTT(ref expand)) => {
|
||||
if it.ident != parse::token::special_idents::invalid {
|
||||
cx.span_fatal(pth.span,
|
||||
fmt!("macro %s! expects no ident argument, \
|
||||
@ -181,7 +179,7 @@ fn expand_item_mac(exts: HashMap<~str, syntax_extension>,
|
||||
span: (*expand).span}}));
|
||||
((*expand).expander)(cx, it.span, tts)
|
||||
}
|
||||
Some(item_tt(ref expand)) => {
|
||||
Some(ItemTT(ref expand)) => {
|
||||
if it.ident == parse::token::special_idents::invalid {
|
||||
cx.span_fatal(pth.span,
|
||||
fmt!("macro %s! expects an ident argument",
|
||||
@ -197,13 +195,13 @@ fn expand_item_mac(exts: HashMap<~str, syntax_extension>,
|
||||
};
|
||||
|
||||
let maybe_it = match expanded {
|
||||
mr_item(it) => fld.fold_item(it),
|
||||
mr_expr(_) => cx.span_fatal(pth.span,
|
||||
MRItem(it) => fld.fold_item(it),
|
||||
MRExpr(_) => cx.span_fatal(pth.span,
|
||||
~"expr macro in item position: "
|
||||
+ *extname),
|
||||
mr_any(_, item_maker, _) =>
|
||||
MRAny(_, item_maker, _) =>
|
||||
option::chain(item_maker(), |i| {fld.fold_item(i)}),
|
||||
mr_def(ref mdef) => {
|
||||
MRDef(ref mdef) => {
|
||||
exts.insert((*mdef).name, (*mdef).ext);
|
||||
None
|
||||
}
|
||||
@ -212,7 +210,7 @@ fn expand_item_mac(exts: HashMap<~str, syntax_extension>,
|
||||
return maybe_it;
|
||||
}
|
||||
|
||||
fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
|
||||
fn expand_stmt(exts: HashMap<~str, SyntaxExtension>, cx: ext_ctxt,
|
||||
&& s: stmt_, sp: span, fld: ast_fold,
|
||||
orig: fn@(&&s: stmt_, span, ast_fold) -> (stmt_, span))
|
||||
-> (stmt_, span)
|
||||
@ -233,16 +231,15 @@ fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
|
||||
None =>
|
||||
cx.span_fatal(pth.span, fmt!("macro undefined: '%s'", *extname)),
|
||||
|
||||
Some(normal_tt(
|
||||
syntax_expander_tt { expander: exp, span: exp_sp }
|
||||
)) => {
|
||||
Some(NormalTT(
|
||||
SyntaxExpanderTT{expander: exp, span: exp_sp})) => {
|
||||
cx.bt_push(ExpandedFrom(
|
||||
{call_site: sp, callie: {name: *extname, span: exp_sp}}));
|
||||
let expanded = match exp(cx, mac.span, tts) {
|
||||
mr_expr(e) =>
|
||||
MRExpr(e) =>
|
||||
@ast::spanned { node: stmt_expr(e, cx.next_id()),
|
||||
span: e.span},
|
||||
mr_any(_,_,stmt_mkr) => stmt_mkr(),
|
||||
MRAny(_,_,stmt_mkr) => stmt_mkr(),
|
||||
_ => cx.span_fatal(
|
||||
pth.span,
|
||||
fmt!("non-stmt macro in stmt pos: %s", *extname))
|
||||
|
@ -28,7 +28,7 @@ use extfmt::ct::*;
|
||||
export expand_syntax_ext;
|
||||
|
||||
fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
|
||||
-> base::mac_result {
|
||||
-> base::MacResult {
|
||||
let args = get_exprs_from_tts(cx, copy tts);
|
||||
if args.len() == 0 {
|
||||
cx.span_fatal(sp, "fmt! takes at least 1 argument.");
|
||||
@ -46,7 +46,7 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
|
||||
parse_fmt_err_(cx, fmtspan, s)
|
||||
};
|
||||
let pieces = parse_fmt_string(fmt, parse_fmt_err);
|
||||
mr_expr(pieces_to_expr(cx, sp, pieces, args))
|
||||
MRExpr(pieces_to_expr(cx, sp, pieces, args))
|
||||
}
|
||||
|
||||
// FIXME (#2249): A lot of these functions for producing expressions can
|
||||
|
@ -18,14 +18,14 @@ use core::io::WriterUtil;
|
||||
use core::option;
|
||||
|
||||
fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, tt: ~[ast::token_tree])
|
||||
-> base::mac_result {
|
||||
-> base::MacResult {
|
||||
|
||||
cx.print_backtrace();
|
||||
io::stdout().write_line(
|
||||
print::pprust::tt_to_str(ast::tt_delim(tt),cx.parse_sess().interner));
|
||||
|
||||
//trivial expression
|
||||
mr_expr(@ast::expr {
|
||||
MRExpr(@ast::expr {
|
||||
id: cx.next_id(),
|
||||
callee_id: cx.next_id(),
|
||||
node: ast::expr_rec(~[], option::None),
|
||||
|
@ -70,7 +70,7 @@ mod liveness;
|
||||
|
||||
|
||||
fn expand_proto(cx: ext_ctxt, _sp: span, id: ast::ident,
|
||||
tt: ~[ast::token_tree]) -> base::mac_result
|
||||
tt: ~[ast::token_tree]) -> base::MacResult
|
||||
{
|
||||
let sess = cx.parse_sess();
|
||||
let cfg = cx.cfg();
|
||||
@ -88,6 +88,6 @@ fn expand_proto(cx: ext_ctxt, _sp: span, id: ast::ident,
|
||||
liveness::analyze(proto, cx);
|
||||
|
||||
// compile
|
||||
base::mr_item(proto.compile(cx))
|
||||
base::MRItem(proto.compile(cx))
|
||||
}
|
||||
|
||||
|
@ -219,45 +219,45 @@ pub mod rt {
|
||||
|
||||
pub fn expand_quote_tokens(cx: ext_ctxt,
|
||||
sp: span,
|
||||
tts: ~[ast::token_tree]) -> base::mac_result {
|
||||
base::mr_expr(expand_tts(cx, sp, tts))
|
||||
tts: ~[ast::token_tree]) -> base::MacResult {
|
||||
base::MRExpr(expand_tts(cx, sp, tts))
|
||||
}
|
||||
|
||||
pub fn expand_quote_expr(cx: ext_ctxt,
|
||||
sp: span,
|
||||
tts: ~[ast::token_tree]) -> base::mac_result {
|
||||
base::mr_expr(expand_parse_call(cx, sp, ~"parse_expr", ~[], tts))
|
||||
tts: ~[ast::token_tree]) -> base::MacResult {
|
||||
base::MRExpr(expand_parse_call(cx, sp, ~"parse_expr", ~[], tts))
|
||||
}
|
||||
|
||||
pub fn expand_quote_item(cx: ext_ctxt,
|
||||
sp: span,
|
||||
tts: ~[ast::token_tree]) -> base::mac_result {
|
||||
tts: ~[ast::token_tree]) -> base::MacResult {
|
||||
let e_attrs = build::mk_uniq_vec_e(cx, sp, ~[]);
|
||||
base::mr_expr(expand_parse_call(cx, sp, ~"parse_item",
|
||||
base::MRExpr(expand_parse_call(cx, sp, ~"parse_item",
|
||||
~[e_attrs], tts))
|
||||
}
|
||||
|
||||
pub fn expand_quote_pat(cx: ext_ctxt,
|
||||
sp: span,
|
||||
tts: ~[ast::token_tree]) -> base::mac_result {
|
||||
tts: ~[ast::token_tree]) -> base::MacResult {
|
||||
let e_refutable = build::mk_lit(cx, sp, ast::lit_bool(true));
|
||||
base::mr_expr(expand_parse_call(cx, sp, ~"parse_pat",
|
||||
base::MRExpr(expand_parse_call(cx, sp, ~"parse_pat",
|
||||
~[e_refutable], tts))
|
||||
}
|
||||
|
||||
pub fn expand_quote_ty(cx: ext_ctxt,
|
||||
sp: span,
|
||||
tts: ~[ast::token_tree]) -> base::mac_result {
|
||||
tts: ~[ast::token_tree]) -> base::MacResult {
|
||||
let e_param_colons = build::mk_lit(cx, sp, ast::lit_bool(false));
|
||||
base::mr_expr(expand_parse_call(cx, sp, ~"parse_ty",
|
||||
base::MRExpr(expand_parse_call(cx, sp, ~"parse_ty",
|
||||
~[e_param_colons], tts))
|
||||
}
|
||||
|
||||
pub fn expand_quote_stmt(cx: ext_ctxt,
|
||||
sp: span,
|
||||
tts: ~[ast::token_tree]) -> base::mac_result {
|
||||
tts: ~[ast::token_tree]) -> base::MacResult {
|
||||
let e_attrs = build::mk_uniq_vec_e(cx, sp, ~[]);
|
||||
base::mr_expr(expand_parse_call(cx, sp, ~"parse_stmt",
|
||||
base::MRExpr(expand_parse_call(cx, sp, ~"parse_stmt",
|
||||
~[e_attrs], tts))
|
||||
}
|
||||
|
||||
|
@ -32,56 +32,56 @@ export expand_include_bin;
|
||||
|
||||
/* line!(): expands to the current line number */
|
||||
fn expand_line(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
|
||||
-> base::mac_result {
|
||||
-> base::MacResult {
|
||||
base::check_zero_tts(cx, sp, tts, "line!");
|
||||
let loc = cx.codemap().lookup_char_pos(sp.lo);
|
||||
base::mr_expr(mk_uint(cx, sp, loc.line))
|
||||
base::MRExpr(mk_uint(cx, sp, loc.line))
|
||||
}
|
||||
|
||||
/* col!(): expands to the current column number */
|
||||
fn expand_col(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
|
||||
-> base::mac_result {
|
||||
-> base::MacResult {
|
||||
base::check_zero_tts(cx, sp, tts, "col!");
|
||||
let loc = cx.codemap().lookup_char_pos(sp.lo);
|
||||
base::mr_expr(mk_uint(cx, sp, loc.col.to_uint()))
|
||||
base::MRExpr(mk_uint(cx, sp, loc.col.to_uint()))
|
||||
}
|
||||
|
||||
/* file!(): expands to the current filename */
|
||||
/* The filemap (`loc.file`) contains a bunch more information we could spit
|
||||
* out if we wanted. */
|
||||
fn expand_file(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
|
||||
-> base::mac_result {
|
||||
-> base::MacResult {
|
||||
base::check_zero_tts(cx, sp, tts, "file!");
|
||||
let Loc { file: @FileMap { name: filename, _ }, _ } =
|
||||
cx.codemap().lookup_char_pos(sp.lo);
|
||||
base::mr_expr(mk_base_str(cx, sp, filename))
|
||||
base::MRExpr(mk_base_str(cx, sp, filename))
|
||||
}
|
||||
|
||||
fn expand_stringify(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
|
||||
-> base::mac_result {
|
||||
-> base::MacResult {
|
||||
let s = pprust::tts_to_str(tts, cx.parse_sess().interner);
|
||||
base::mr_expr(mk_base_str(cx, sp, s))
|
||||
base::MRExpr(mk_base_str(cx, sp, s))
|
||||
}
|
||||
|
||||
fn expand_mod(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
|
||||
-> base::mac_result {
|
||||
-> base::MacResult {
|
||||
base::check_zero_tts(cx, sp, tts, "module_path!");
|
||||
base::mr_expr(mk_base_str(cx, sp,
|
||||
base::MRExpr(mk_base_str(cx, sp,
|
||||
str::connect(cx.mod_path().map(
|
||||
|x| cx.str_of(*x)), ~"::")))
|
||||
}
|
||||
|
||||
fn expand_include(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
|
||||
-> base::mac_result {
|
||||
-> base::MacResult {
|
||||
let file = get_single_str_from_tts(cx, sp, tts, "include!");
|
||||
let p = parse::new_sub_parser_from_file(
|
||||
cx.parse_sess(), cx.cfg(),
|
||||
&res_rel_file(cx, sp, &Path(file)), sp);
|
||||
base::mr_expr(p.parse_expr())
|
||||
base::MRExpr(p.parse_expr())
|
||||
}
|
||||
|
||||
fn expand_include_str(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
|
||||
-> base::mac_result {
|
||||
-> base::MacResult {
|
||||
let file = get_single_str_from_tts(cx, sp, tts, "include_str!");
|
||||
let res = io::read_whole_file_str(&res_rel_file(cx, sp, &Path(file)));
|
||||
match res {
|
||||
@ -91,18 +91,18 @@ fn expand_include_str(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
|
||||
}
|
||||
}
|
||||
|
||||
base::mr_expr(mk_base_str(cx, sp, result::unwrap(res)))
|
||||
base::MRExpr(mk_base_str(cx, sp, result::unwrap(res)))
|
||||
}
|
||||
|
||||
fn expand_include_bin(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
|
||||
-> base::mac_result {
|
||||
-> base::MacResult {
|
||||
let file = get_single_str_from_tts(cx, sp, tts, "include_bin!");
|
||||
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)
|
||||
});
|
||||
base::mr_expr(mk_base_vec_e(cx, sp, u8_exprs))
|
||||
base::MRExpr(mk_base_vec_e(cx, sp, u8_exprs))
|
||||
}
|
||||
result::Err(ref e) => {
|
||||
cx.parse_sess().span_diagnostic.handler().fatal((*e))
|
||||
|
@ -19,7 +19,7 @@ use parse::parser::Parser;
|
||||
use core::option::None;
|
||||
|
||||
fn expand_trace_macros(cx: ext_ctxt, sp: span,
|
||||
tt: ~[ast::token_tree]) -> base::mac_result {
|
||||
tt: ~[ast::token_tree]) -> base::MacResult {
|
||||
let sess = cx.parse_sess();
|
||||
let cfg = cx.cfg();
|
||||
let tt_rdr = new_tt_reader(cx.parse_sess().span_diagnostic,
|
||||
@ -39,5 +39,5 @@ fn expand_trace_macros(cx: ext_ctxt, sp: span,
|
||||
|
||||
let rust_parser = Parser(sess, cfg, rdr.dup());
|
||||
let result = rust_parser.parse_expr();
|
||||
base::mr_expr(result)
|
||||
base::MRExpr(result)
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ use ast::{tt_delim};
|
||||
use ast;
|
||||
use ast_util::dummy_sp;
|
||||
use codemap::span;
|
||||
use ext::base::{ext_ctxt, mac_result, mr_any, mr_def, normal_tt};
|
||||
use ext::base::{ext_ctxt, MacResult, MRAny, MRDef, MacroDef, NormalTT};
|
||||
use ext::base;
|
||||
use ext::tt::macro_parser::{error};
|
||||
use ext::tt::macro_parser::{named_match, matched_seq, matched_nonterminal};
|
||||
@ -30,7 +30,7 @@ use core::io;
|
||||
use std::map::HashMap;
|
||||
|
||||
fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
|
||||
arg: ~[ast::token_tree]) -> base::mac_result {
|
||||
arg: ~[ast::token_tree]) -> base::MacResult {
|
||||
// these spans won't matter, anyways
|
||||
fn ms(m: matcher_) -> matcher {
|
||||
ast::spanned { node: m, span: dummy_sp() }
|
||||
@ -73,7 +73,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
|
||||
fn generic_extension(cx: ext_ctxt, sp: span, name: ident,
|
||||
arg: ~[ast::token_tree],
|
||||
lhses: ~[@named_match], rhses: ~[@named_match])
|
||||
-> mac_result {
|
||||
-> MacResult {
|
||||
|
||||
if cx.trace_macros() {
|
||||
io::println(fmt!("%s! { %s }",
|
||||
@ -119,7 +119,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
|
||||
|
||||
// Let the context choose how to interpret the result.
|
||||
// Weird, but useful for X-macros.
|
||||
return mr_any(|| p.parse_expr(),
|
||||
return MRAny(|| p.parse_expr(),
|
||||
|| p.parse_item(~[/* no attrs*/]),
|
||||
|| p.parse_stmt(~[/* no attrs*/]));
|
||||
}
|
||||
@ -136,14 +136,11 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
|
||||
cx.span_fatal(best_fail_spot, best_fail_msg);
|
||||
}
|
||||
|
||||
let exp: @fn(ext_ctxt, span, ~[ast::token_tree]) -> mac_result =
|
||||
let exp: @fn(ext_ctxt, span, ~[ast::token_tree]) -> MacResult =
|
||||
|cx, sp, arg| generic_extension(cx, sp, name, arg, lhses, rhses);
|
||||
|
||||
mr_def(base::macro_def {
|
||||
return MRDef(MacroDef{
|
||||
name: *cx.parse_sess().interner.get(name),
|
||||
ext: normal_tt(base::syntax_expander_tt {
|
||||
expander: exp,
|
||||
span: Some(sp),
|
||||
})
|
||||
})
|
||||
ext: NormalTT(base::SyntaxExpanderTT{expander: exp, span: Some(sp)})
|
||||
});
|
||||
}
|
||||
|
0
src/test/run-pass/typeclasses-eq-example.rs
Executable file → Normal file
0
src/test/run-pass/typeclasses-eq-example.rs
Executable file → Normal file
Loading…
Reference in New Issue
Block a user