]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass-fulldeps/auxiliary/plugin_args.rs
New upstream version 1.13.0+dfsg1
[rustc.git] / src / test / run-pass-fulldeps / 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;
3157f602 17extern crate syntax_pos;
1a4d82fc 18extern crate rustc;
92a42be0 19extern crate rustc_plugin;
1a4d82fc
JJ
20
21use std::borrow::ToOwned;
22use syntax::ast;
1a4d82fc 23use syntax::ext::build::AstBuilder;
c34b1796 24use syntax::ext::base::{TTMacroExpander, ExtCtxt, MacResult, MacEager, NormalTT};
1a4d82fc
JJ
25use syntax::parse::token;
26use syntax::print::pprust;
27use syntax::ptr::P;
3157f602
XL
28use syntax_pos::Span;
29use syntax::tokenstream;
92a42be0 30use rustc_plugin::Registry;
1a4d82fc
JJ
31
32struct Expander {
9e0c209e 33 args: Vec<ast::NestedMetaItem>,
1a4d82fc
JJ
34}
35
36impl TTMacroExpander for Expander {
37 fn expand<'cx>(&self,
38 ecx: &'cx mut ExtCtxt,
39 sp: Span,
3157f602 40 _: &[tokenstream::TokenTree]) -> Box<MacResult+'cx> {
9e0c209e 41 let args = self.args.iter().map(|i| pprust::meta_list_item_to_string(i))
c1a9b12d 42 .collect::<Vec<_>>().join(", ");
85aaf69f 43 let interned = token::intern_and_get_ident(&args[..]);
c34b1796 44 MacEager::expr(ecx.expr_str(sp, interned))
1a4d82fc
JJ
45 }
46}
47
48#[plugin_registrar]
49pub fn plugin_registrar(reg: &mut Registry) {
a7813a04 50 let args = reg.args().to_owned();
1a4d82fc 51 reg.register_syntax_extension(token::intern("plugin_args"),
c34b1796
AL
52 // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
53 NormalTT(Box::new(Expander { args: args, }), None, false));
1a4d82fc 54}