]> git.proxmox.com Git - rustc.git/blame - src/test/auxiliary/plugin_args.rs
Imported Upstream version 1.3.0+dfsg1
[rustc.git] / src / test / auxiliary / plugin_args.rs
CommitLineData
1a4d82fc
JJ
1// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11// force-host
12
13#![feature(plugin_registrar)]
c34b1796 14#![feature(box_syntax, rustc_private)]
1a4d82fc
JJ
15
16extern crate syntax;
17extern crate rustc;
18
19use std::borrow::ToOwned;
20use syntax::ast;
21use syntax::codemap::Span;
22use syntax::ext::build::AstBuilder;
c34b1796 23use syntax::ext::base::{TTMacroExpander, ExtCtxt, MacResult, MacEager, NormalTT};
1a4d82fc
JJ
24use syntax::parse::token;
25use syntax::print::pprust;
26use syntax::ptr::P;
27use rustc::plugin::Registry;
28
29struct Expander {
85aaf69f 30 args: Vec<P<ast::MetaItem>>,
1a4d82fc
JJ
31}
32
33impl TTMacroExpander for Expander {
34 fn expand<'cx>(&self,
35 ecx: &'cx mut ExtCtxt,
36 sp: Span,
37 _: &[ast::TokenTree]) -> Box<MacResult+'cx> {
85aaf69f 38 let args = self.args.iter().map(|i| pprust::meta_item_to_string(&*i))
c1a9b12d 39 .collect::<Vec<_>>().join(", ");
85aaf69f 40 let interned = token::intern_and_get_ident(&args[..]);
c34b1796 41 MacEager::expr(ecx.expr_str(sp, interned))
1a4d82fc
JJ
42 }
43}
44
45#[plugin_registrar]
46pub fn plugin_registrar(reg: &mut Registry) {
47 let args = reg.args().clone();
48 reg.register_syntax_extension(token::intern("plugin_args"),
c34b1796
AL
49 // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
50 NormalTT(Box::new(Expander { args: args, }), None, false));
1a4d82fc 51}