2012-12-03 16:48:01 -08:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-01-08 19:37:25 -08:00
|
|
|
use core::prelude::*;
|
|
|
|
|
2012-12-23 17:41:37 -05:00
|
|
|
use ast::{crate, expr_, expr_mac, mac_invoc_tt};
|
|
|
|
use ast::{tt_delim, tt_tok, item_mac, stmt_, stmt_mac, stmt_expr, stmt_semi};
|
|
|
|
use ast;
|
|
|
|
use codemap::{span, ExpandedFrom};
|
2012-09-04 11:37:29 -07:00
|
|
|
use ext::base::*;
|
2012-12-23 17:41:37 -05:00
|
|
|
use fold::*;
|
2012-11-20 16:07:57 -08:00
|
|
|
use parse::{parser, parse_expr_from_source_str, new_parser_from_tts};
|
2011-08-05 13:06:11 -07:00
|
|
|
|
2012-12-23 17:41:37 -05:00
|
|
|
use core::option;
|
|
|
|
use core::vec;
|
|
|
|
use std::map::HashMap;
|
2012-11-17 07:41:36 -05:00
|
|
|
|
2013-01-22 16:45:27 -08:00
|
|
|
fn expand_expr(exts: HashMap<~str, SyntaxExtension>, cx: ext_ctxt,
|
2012-01-22 17:30:07 -07:00
|
|
|
e: expr_, s: span, fld: ast_fold,
|
|
|
|
orig: fn@(expr_, span, ast_fold) -> (expr_, span))
|
|
|
|
-> (expr_, span)
|
|
|
|
{
|
2012-08-06 12:34:08 -07:00
|
|
|
return match e {
|
2012-07-27 17:42:32 -07:00
|
|
|
// expr_mac should really be expr_ext or something; it's the
|
|
|
|
// entry-point for all syntax extensions.
|
2012-12-04 10:50:00 -08:00
|
|
|
expr_mac(ref mac) => {
|
2012-07-27 17:42:32 -07:00
|
|
|
|
2012-12-04 10:50:00 -08:00
|
|
|
match (*mac).node {
|
2012-07-27 17:42:32 -07:00
|
|
|
|
|
|
|
// Token-tree macros, these will be the only case when we're
|
|
|
|
// finished transitioning.
|
2012-12-04 10:50:00 -08:00
|
|
|
mac_invoc_tt(pth, ref tts) => {
|
2012-07-06 18:04:28 -07:00
|
|
|
assert (vec::len(pth.idents) == 1u);
|
2012-07-18 16:18:02 -07:00
|
|
|
/* using idents and token::special_idents would make the
|
|
|
|
the macro names be hygienic */
|
|
|
|
let extname = cx.parse_sess().interner.get(pth.idents[0]);
|
2012-08-06 12:34:08 -07:00
|
|
|
match exts.find(*extname) {
|
2012-08-20 12:23:37 -07:00
|
|
|
None => {
|
2012-06-25 15:04:50 -07:00
|
|
|
cx.span_fatal(pth.span,
|
2012-08-22 17:24:52 -07:00
|
|
|
fmt!("macro undefined: '%s'", *extname))
|
2012-06-25 15:04:50 -07:00
|
|
|
}
|
2013-01-23 11:45:48 -08:00
|
|
|
Some(NormalTT(SyntaxExpanderTT{expander: exp,
|
|
|
|
span: exp_sp})) => {
|
2012-12-06 11:01:58 -08:00
|
|
|
cx.bt_push(ExpandedFrom({call_site: s,
|
|
|
|
callie: {name: *extname, span: exp_sp}}));
|
|
|
|
|
2012-12-04 10:50:00 -08:00
|
|
|
let expanded = match exp(cx, (*mac).span, (*tts)) {
|
2013-01-22 16:45:27 -08:00
|
|
|
MRExpr(e) => e,
|
|
|
|
MRAny(expr_maker,_,_) => expr_maker(),
|
2012-08-03 19:59:04 -07:00
|
|
|
_ => cx.span_fatal(
|
2012-08-22 17:24:52 -07:00
|
|
|
pth.span, fmt!("non-expr macro in expr pos: %s",
|
|
|
|
*extname))
|
2012-07-06 18:04:28 -07:00
|
|
|
};
|
2012-06-25 15:04:50 -07:00
|
|
|
|
|
|
|
//keep going, outside-in
|
|
|
|
let fully_expanded = fld.fold_expr(expanded).node;
|
|
|
|
cx.bt_pop();
|
|
|
|
|
|
|
|
(fully_expanded, s)
|
2012-07-12 17:59:59 -07:00
|
|
|
}
|
2012-08-03 19:59:04 -07:00
|
|
|
_ => {
|
2012-06-25 15:04:50 -07:00
|
|
|
cx.span_fatal(pth.span,
|
2012-08-22 17:24:52 -07:00
|
|
|
fmt!("'%s' is not a tt-style macro",
|
|
|
|
*extname))
|
2012-06-25 15:04:50 -07:00
|
|
|
}
|
|
|
|
|
2011-07-06 15:22:23 -07:00
|
|
|
}
|
2011-07-27 14:19:39 +02:00
|
|
|
}
|
2011-07-06 15:22:23 -07:00
|
|
|
}
|
2011-07-27 14:19:39 +02:00
|
|
|
}
|
2012-08-03 19:59:04 -07:00
|
|
|
_ => orig(e, s, fld)
|
2011-07-27 14:19:39 +02:00
|
|
|
};
|
2011-07-06 15:22:23 -07:00
|
|
|
}
|
|
|
|
|
2012-07-27 17:42:32 -07:00
|
|
|
// This is a secondary mechanism for invoking syntax extensions on items:
|
2012-12-17 19:31:04 -08:00
|
|
|
// "decorator" attributes, such as #[auto_encode]. These are invoked by an
|
2012-07-27 17:42:32 -07:00
|
|
|
// 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
|
2013-01-22 16:45:27 -08:00
|
|
|
// these do _not_ work for macro extensions, just ItemDecorator ones.
|
2012-07-27 17:42:32 -07:00
|
|
|
//
|
|
|
|
// NB: there is some redundancy between this and expand_item, below, and
|
|
|
|
// they might benefit from some amount of semantic and language-UI merger.
|
2013-01-22 16:45:27 -08:00
|
|
|
fn expand_mod_items(exts: HashMap<~str, SyntaxExtension>, cx: ext_ctxt,
|
2012-07-31 16:38:41 -07:00
|
|
|
module_: ast::_mod, fld: ast_fold,
|
2012-03-02 14:36:22 -08:00
|
|
|
orig: fn@(ast::_mod, ast_fold) -> ast::_mod)
|
|
|
|
-> ast::_mod
|
|
|
|
{
|
|
|
|
// Fold the contents first:
|
2012-07-31 16:38:41 -07:00
|
|
|
let module_ = orig(module_, fld);
|
2012-03-02 14:36:22 -08:00
|
|
|
|
|
|
|
// For each item, look through the attributes. If any of them are
|
|
|
|
// decorated with "item decorators", then use that function to transform
|
|
|
|
// the item into a new set of items.
|
2012-07-31 16:38:41 -07:00
|
|
|
let new_items = do vec::flat_map(module_.items) |item| {
|
2012-09-27 22:20:47 -07:00
|
|
|
do vec::foldr(item.attrs, ~[*item]) |attr, items| {
|
2012-08-06 12:34:08 -07:00
|
|
|
let mname = match attr.node.value.node {
|
2012-12-04 10:50:00 -08:00
|
|
|
ast::meta_word(ref n) => (*n),
|
|
|
|
ast::meta_name_value(ref n, _) => (*n),
|
|
|
|
ast::meta_list(ref n, _) => (*n)
|
2012-03-02 14:36:22 -08:00
|
|
|
};
|
2012-07-18 16:18:02 -07:00
|
|
|
match exts.find(mname) {
|
2013-01-22 16:45:27 -08:00
|
|
|
None | Some(NormalTT(_)) | Some(ItemTT(*)) => items,
|
|
|
|
Some(ItemDecorator(dec_fn)) => {
|
2012-12-12 10:44:01 -08:00
|
|
|
cx.bt_push(ExpandedFrom({call_site: attr.span,
|
|
|
|
callie: {name: copy mname,
|
|
|
|
span: None}}));
|
|
|
|
let r = dec_fn(cx, attr.span, attr.node.value, items);
|
|
|
|
cx.bt_pop();
|
|
|
|
r
|
2012-03-02 14:36:22 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-15 16:05:20 -08:00
|
|
|
ast::_mod { items: new_items, ..module_ }
|
2012-03-02 14:36:22 -08:00
|
|
|
}
|
|
|
|
|
2012-07-27 11:19:21 -07:00
|
|
|
|
|
|
|
// When we enter a module, record it, for the sake of `module!`
|
2013-01-22 16:45:27 -08:00
|
|
|
fn expand_item(exts: HashMap<~str, SyntaxExtension>,
|
2012-07-05 12:10:33 -07:00
|
|
|
cx: ext_ctxt, &&it: @ast::item, fld: ast_fold,
|
2012-09-23 04:39:27 -07:00
|
|
|
orig: fn@(&&v: @ast::item, ast_fold) -> Option<@ast::item>)
|
2012-08-20 12:23:37 -07:00
|
|
|
-> Option<@ast::item>
|
2012-05-18 10:00:49 -07:00
|
|
|
{
|
2012-08-06 12:34:08 -07:00
|
|
|
let is_mod = match it.node {
|
2012-08-03 19:59:04 -07:00
|
|
|
ast::item_mod(_) | ast::item_foreign_mod(_) => true,
|
|
|
|
_ => false
|
2012-05-18 10:00:49 -07:00
|
|
|
};
|
2012-08-06 12:34:08 -07:00
|
|
|
let maybe_it = match it.node {
|
2012-08-03 19:59:04 -07:00
|
|
|
ast::item_mac(*) => expand_item_mac(exts, cx, it, fld),
|
2012-08-20 12:23:37 -07:00
|
|
|
_ => Some(it)
|
2012-07-05 12:10:33 -07:00
|
|
|
};
|
2012-07-06 12:17:34 -07:00
|
|
|
|
2012-08-06 12:34:08 -07:00
|
|
|
match maybe_it {
|
2012-08-20 12:23:37 -07:00
|
|
|
Some(it) => {
|
2012-07-06 12:17:34 -07:00
|
|
|
if is_mod { cx.mod_push(it.ident); }
|
|
|
|
let ret_val = orig(it, fld);
|
|
|
|
if is_mod { cx.mod_pop(); }
|
2012-08-01 17:30:05 -07:00
|
|
|
return ret_val;
|
2012-07-06 12:17:34 -07:00
|
|
|
}
|
2012-08-20 12:23:37 -07:00
|
|
|
None => return None
|
2012-07-06 12:17:34 -07:00
|
|
|
}
|
2012-05-18 10:00:49 -07:00
|
|
|
}
|
|
|
|
|
2012-07-27 11:19:21 -07:00
|
|
|
// Support for item-position macro invocations, exactly the same
|
|
|
|
// logic as for expression-position macro invocations.
|
2013-01-22 16:45:27 -08:00
|
|
|
fn expand_item_mac(exts: HashMap<~str, SyntaxExtension>,
|
2012-07-05 16:46:32 -07:00
|
|
|
cx: ext_ctxt, &&it: @ast::item,
|
2012-08-20 12:23:37 -07:00
|
|
|
fld: ast_fold) -> Option<@ast::item> {
|
2012-12-12 12:25:40 -08:00
|
|
|
|
|
|
|
let (pth, tts) = match it.node {
|
2012-12-27 14:36:00 -05:00
|
|
|
item_mac(ast::spanned { node: mac_invoc_tt(pth, ref tts), _}) => {
|
|
|
|
(pth, (*tts))
|
|
|
|
}
|
2012-12-12 12:25:40 -08:00
|
|
|
_ => cx.span_bug(it.span, ~"invalid item macro invocation")
|
|
|
|
};
|
2012-11-17 07:41:36 -05:00
|
|
|
|
|
|
|
let extname = cx.parse_sess().interner.get(pth.idents[0]);
|
2012-12-06 16:19:05 -08:00
|
|
|
let expanded = match exts.find(*extname) {
|
2012-11-17 07:41:36 -05:00
|
|
|
None => cx.span_fatal(pth.span,
|
|
|
|
fmt!("macro undefined: '%s!'", *extname)),
|
|
|
|
|
2013-01-22 16:45:27 -08:00
|
|
|
Some(NormalTT(ref expand)) => {
|
2012-11-08 23:12:45 -05:00
|
|
|
if it.ident != parse::token::special_idents::invalid {
|
|
|
|
cx.span_fatal(pth.span,
|
|
|
|
fmt!("macro %s! expects no ident argument, \
|
|
|
|
given '%s'", *extname,
|
|
|
|
*cx.parse_sess().interner.get(it.ident)));
|
|
|
|
}
|
2012-12-06 16:19:05 -08:00
|
|
|
cx.bt_push(ExpandedFrom({call_site: it.span,
|
|
|
|
callie: {name: *extname,
|
|
|
|
span: (*expand).span}}));
|
|
|
|
((*expand).expander)(cx, it.span, tts)
|
2012-11-17 07:41:36 -05:00
|
|
|
}
|
2013-01-22 16:45:27 -08:00
|
|
|
Some(ItemTT(ref expand)) => {
|
2012-11-08 23:12:45 -05:00
|
|
|
if it.ident == parse::token::special_idents::invalid {
|
|
|
|
cx.span_fatal(pth.span,
|
|
|
|
fmt!("macro %s! expects an ident argument",
|
|
|
|
*extname));
|
|
|
|
}
|
2012-12-06 16:19:05 -08:00
|
|
|
cx.bt_push(ExpandedFrom({call_site: it.span,
|
|
|
|
callie: {name: *extname,
|
|
|
|
span: (*expand).span}}));
|
|
|
|
((*expand).expander)(cx, it.span, it.ident, tts)
|
2012-11-17 07:41:36 -05:00
|
|
|
}
|
|
|
|
_ => cx.span_fatal(
|
|
|
|
it.span, fmt!("%s! is not legal in item position", *extname))
|
|
|
|
};
|
2012-11-08 23:12:45 -05:00
|
|
|
|
2012-11-17 07:41:36 -05:00
|
|
|
let maybe_it = match expanded {
|
2013-01-22 16:45:27 -08:00
|
|
|
MRItem(it) => fld.fold_item(it),
|
|
|
|
MRExpr(_) => cx.span_fatal(pth.span,
|
2012-11-17 07:41:36 -05:00
|
|
|
~"expr macro in item position: "
|
|
|
|
+ *extname),
|
2013-01-22 16:45:27 -08:00
|
|
|
MRAny(_, item_maker, _) =>
|
2012-11-17 07:41:36 -05:00
|
|
|
option::chain(item_maker(), |i| {fld.fold_item(i)}),
|
2013-01-22 16:45:27 -08:00
|
|
|
MRDef(ref mdef) => {
|
2012-12-04 10:50:00 -08:00
|
|
|
exts.insert((*mdef).name, (*mdef).ext);
|
2012-11-17 07:41:36 -05:00
|
|
|
None
|
|
|
|
}
|
|
|
|
};
|
|
|
|
cx.bt_pop();
|
|
|
|
return maybe_it;
|
2012-07-05 12:10:33 -07:00
|
|
|
}
|
|
|
|
|
2013-01-22 16:45:27 -08:00
|
|
|
fn expand_stmt(exts: HashMap<~str, SyntaxExtension>, cx: ext_ctxt,
|
2012-11-19 20:31:22 -05:00
|
|
|
&& s: stmt_, sp: span, fld: ast_fold,
|
|
|
|
orig: fn@(&&s: stmt_, span, ast_fold) -> (stmt_, span))
|
|
|
|
-> (stmt_, span)
|
|
|
|
{
|
2012-12-12 12:25:40 -08:00
|
|
|
|
|
|
|
let (mac, pth, tts, semi) = match s {
|
|
|
|
stmt_mac(ref mac, semi) => {
|
|
|
|
match (*mac).node {
|
|
|
|
mac_invoc_tt(pth, ref tts) => ((*mac), pth, (*tts), semi)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => return orig(s, sp, fld)
|
|
|
|
};
|
2012-11-17 07:41:36 -05:00
|
|
|
|
|
|
|
assert(vec::len(pth.idents) == 1u);
|
|
|
|
let extname = cx.parse_sess().interner.get(pth.idents[0]);
|
2012-11-21 18:49:42 -05:00
|
|
|
let (fully_expanded, sp) = match exts.find(*extname) {
|
2012-11-17 07:41:36 -05:00
|
|
|
None =>
|
|
|
|
cx.span_fatal(pth.span, fmt!("macro undefined: '%s'", *extname)),
|
|
|
|
|
2013-01-22 16:45:27 -08:00
|
|
|
Some(NormalTT(
|
|
|
|
SyntaxExpanderTT{expander: exp, span: exp_sp})) => {
|
2012-12-06 11:01:58 -08:00
|
|
|
cx.bt_push(ExpandedFrom(
|
|
|
|
{call_site: sp, callie: {name: *extname, span: exp_sp}}));
|
2012-11-17 07:41:36 -05:00
|
|
|
let expanded = match exp(cx, mac.span, tts) {
|
2013-01-22 16:45:27 -08:00
|
|
|
MRExpr(e) =>
|
2012-12-27 14:36:00 -05:00
|
|
|
@ast::spanned { node: stmt_expr(e, cx.next_id()),
|
|
|
|
span: e.span},
|
2013-01-22 16:45:27 -08:00
|
|
|
MRAny(_,_,stmt_mkr) => stmt_mkr(),
|
2012-11-17 07:41:36 -05:00
|
|
|
_ => cx.span_fatal(
|
|
|
|
pth.span,
|
|
|
|
fmt!("non-stmt macro in stmt pos: %s", *extname))
|
|
|
|
};
|
|
|
|
|
|
|
|
//keep going, outside-in
|
|
|
|
let fully_expanded = fld.fold_stmt(expanded).node;
|
|
|
|
cx.bt_pop();
|
|
|
|
|
2012-11-21 18:49:42 -05:00
|
|
|
(fully_expanded, sp)
|
2012-11-19 20:31:22 -05:00
|
|
|
}
|
2012-11-19 00:30:48 -05:00
|
|
|
|
2012-11-17 07:41:36 -05:00
|
|
|
_ => {
|
|
|
|
cx.span_fatal(pth.span,
|
2012-11-21 18:49:42 -05:00
|
|
|
fmt!("'%s' is not a tt-style macro", *extname))
|
2012-11-17 07:41:36 -05:00
|
|
|
}
|
2012-11-21 18:49:42 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
return (match fully_expanded {
|
|
|
|
stmt_expr(e, stmt_id) if semi => stmt_semi(e, stmt_id),
|
|
|
|
_ => { fully_expanded } /* might already have a semi */
|
|
|
|
}, sp)
|
2012-11-17 07:41:36 -05:00
|
|
|
|
2012-11-19 20:31:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-04 18:37:24 -07:00
|
|
|
fn new_span(cx: ext_ctxt, sp: span) -> span {
|
|
|
|
/* this discards information in the case of macro-defining macros */
|
2012-11-12 15:12:20 -08:00
|
|
|
return span {lo: sp.lo, hi: sp.hi, expn_info: cx.backtrace()};
|
2012-02-04 18:37:24 -07:00
|
|
|
}
|
|
|
|
|
2012-06-21 16:44:10 -07:00
|
|
|
// FIXME (#2247): this is a terrible kludge to inject some macros into
|
|
|
|
// the default compilation environment. When the macro-definition system
|
|
|
|
// is substantially more mature, these should move from here, into a
|
|
|
|
// compiled part of libcore at very least.
|
2011-12-20 13:38:10 -08:00
|
|
|
|
2012-07-13 22:57:48 -07:00
|
|
|
fn core_macros() -> ~str {
|
2012-08-01 17:30:05 -07:00
|
|
|
return
|
2012-07-13 22:57:48 -07:00
|
|
|
~"{
|
2012-09-07 16:58:27 -07:00
|
|
|
macro_rules! ignore (($($x:tt)*) => (()))
|
2012-11-26 22:34:01 -05:00
|
|
|
|
|
|
|
macro_rules! error ( ($( $arg:expr ),+) => (
|
2012-12-23 17:41:37 -05:00
|
|
|
log(::core::error, fmt!( $($arg),+ )) ))
|
2012-11-26 22:34:01 -05:00
|
|
|
macro_rules! warn ( ($( $arg:expr ),+) => (
|
2012-12-23 17:41:37 -05:00
|
|
|
log(::core::warn, fmt!( $($arg),+ )) ))
|
2012-11-26 22:34:01 -05:00
|
|
|
macro_rules! info ( ($( $arg:expr ),+) => (
|
2012-12-23 17:41:37 -05:00
|
|
|
log(::core::info, fmt!( $($arg),+ )) ))
|
2012-11-26 22:34:01 -05:00
|
|
|
macro_rules! debug ( ($( $arg:expr ),+) => (
|
2012-12-23 17:41:37 -05:00
|
|
|
log(::core::debug, fmt!( $($arg),+ )) ))
|
2012-11-27 18:05:20 -08:00
|
|
|
|
|
|
|
macro_rules! die(
|
|
|
|
($msg: expr) => (
|
2012-12-23 17:41:37 -05:00
|
|
|
::core::sys::begin_unwind($msg, file!().to_owned(), line!())
|
2012-11-27 18:05:20 -08:00
|
|
|
);
|
|
|
|
() => (
|
2012-12-10 17:22:10 -08:00
|
|
|
die!(~\"explicit failure\")
|
2012-11-27 18:05:20 -08:00
|
|
|
)
|
|
|
|
)
|
2012-12-14 11:52:11 -08:00
|
|
|
|
|
|
|
macro_rules! condition (
|
|
|
|
|
|
|
|
{ $c:ident: $in:ty -> $out:ty; } => {
|
|
|
|
|
|
|
|
mod $c {
|
2012-12-27 17:53:04 -08:00
|
|
|
fn key(_x: @::core::condition::Handler<$in,$out>) { }
|
2012-12-14 11:52:11 -08:00
|
|
|
|
2012-12-27 17:53:04 -08:00
|
|
|
pub const cond : ::core::condition::Condition<$in,$out> =
|
|
|
|
::core::condition::Condition {
|
2013-01-11 21:32:10 -05:00
|
|
|
name: stringify!($c),
|
2012-12-14 11:52:11 -08:00
|
|
|
key: key
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2011-12-20 13:38:10 -08:00
|
|
|
}";
|
|
|
|
}
|
|
|
|
|
2012-04-17 23:34:48 -07:00
|
|
|
fn expand_crate(parse_sess: parse::parse_sess,
|
2012-03-27 14:03:57 -07:00
|
|
|
cfg: ast::crate_cfg, c: @crate) -> @crate {
|
2011-08-05 13:06:11 -07:00
|
|
|
let exts = syntax_expander_table();
|
2011-07-27 14:19:39 +02:00
|
|
|
let afp = default_ast_fold();
|
2012-03-27 14:03:57 -07:00
|
|
|
let cx: ext_ctxt = mk_ctxt(parse_sess, cfg);
|
2013-01-08 14:00:45 -08:00
|
|
|
let f_pre = @AstFoldFns {
|
|
|
|
fold_expr: |a,b,c| expand_expr(exts, cx, a, b, c, afp.fold_expr),
|
|
|
|
fold_mod: |a,b| expand_mod_items(exts, cx, a, b, afp.fold_mod),
|
|
|
|
fold_item: |a,b| expand_item(exts, cx, a, b, afp.fold_item),
|
|
|
|
fold_stmt: |a,b,c| expand_stmt(exts, cx, a, b, c, afp.fold_stmt),
|
|
|
|
new_span: |a| new_span(cx, a),
|
|
|
|
.. *afp};
|
2011-07-27 14:19:39 +02:00
|
|
|
let f = make_fold(f_pre);
|
2012-07-13 22:57:48 -07:00
|
|
|
let cm = parse_expr_from_source_str(~"<core-macros>",
|
2012-04-30 11:52:07 -07:00
|
|
|
@core_macros(),
|
2012-03-27 14:03:57 -07:00
|
|
|
cfg,
|
|
|
|
parse_sess);
|
2011-12-20 13:38:10 -08:00
|
|
|
|
|
|
|
// This is run for its side-effects on the expander env,
|
|
|
|
// as it registers all the core macros as expanders.
|
|
|
|
f.fold_expr(cm);
|
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
let res = @f.fold_crate(*c);
|
2012-08-01 17:30:05 -07:00
|
|
|
return res;
|
2011-07-06 15:22:23 -07:00
|
|
|
}
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|