1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "https://doc.rust-lang.org/nightly/")]
#![feature(proc_macro_internals)]
#![feature(decl_macro)]
#![cfg_attr(not(stage0), feature(nll))]
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
#![feature(str_escape)]
#![feature(quote)]
#![feature(rustc_diagnostic_macros)]
extern crate fmt_macros;
#[macro_use]
extern crate syntax;
extern crate syntax_pos;
extern crate proc_macro;
extern crate rustc_data_structures;
extern crate rustc_errors as errors;
extern crate rustc_target;
#[macro_use]
extern crate smallvec;
#[macro_use]
extern crate log;
mod diagnostics;
#[macro_use]
pub mod deriving;
mod asm;
mod assert;
mod cfg;
mod compile_error;
mod concat;
mod concat_idents;
mod env;
mod format;
mod format_foreign;
mod global_asm;
mod log_syntax;
mod trace_macros;
mod test;
mod test_case;
pub mod proc_macro_registrar;
pub mod proc_macro_impl;
use rustc_data_structures::sync::Lrc;
use syntax::ast;
use syntax::ext::base::{MacroExpanderFn, NormalTT, NamedSyntaxExtension, MultiModifier};
use syntax::ext::hygiene;
use syntax::symbol::Symbol;
pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver,
user_exts: Vec<NamedSyntaxExtension>,
enable_quotes: bool) {
deriving::register_builtin_derives(resolver);
let mut register = |name, ext| {
resolver.add_builtin(ast::Ident::with_empty_ctxt(name), Lrc::new(ext));
};
macro_rules! register {
($( $name:ident: $f:expr, )*) => { $(
register(Symbol::intern(stringify!($name)),
NormalTT {
expander: Box::new($f as MacroExpanderFn),
def_info: None,
allow_internal_unstable: false,
allow_internal_unsafe: false,
local_inner_macros: false,
unstable_feature: None,
edition: hygiene::default_edition(),
});
)* }
}
if enable_quotes {
use syntax::ext::quote::*;
register! {
quote_tokens: expand_quote_tokens,
quote_expr: expand_quote_expr,
quote_ty: expand_quote_ty,
quote_item: expand_quote_item,
quote_pat: expand_quote_pat,
quote_arm: expand_quote_arm,
quote_stmt: expand_quote_stmt,
quote_attr: expand_quote_attr,
quote_arg: expand_quote_arg,
quote_block: expand_quote_block,
quote_meta_item: expand_quote_meta_item,
quote_path: expand_quote_path,
}
}
use syntax::ext::source_util::*;
register! {
line: expand_line,
__rust_unstable_column: expand_column_gated,
column: expand_column,
file: expand_file,
stringify: expand_stringify,
include: expand_include,
include_str: expand_include_str,
include_bytes: expand_include_bytes,
module_path: expand_mod,
asm: asm::expand_asm,
global_asm: global_asm::expand_global_asm,
cfg: cfg::expand_cfg,
concat: concat::expand_syntax_ext,
concat_idents: concat_idents::expand_syntax_ext,
env: env::expand_env,
option_env: env::expand_option_env,
log_syntax: log_syntax::expand_syntax_ext,
trace_macros: trace_macros::expand_trace_macros,
compile_error: compile_error::expand_compile_error,
assert: assert::expand_assert,
}
register(Symbol::intern("test_case"), MultiModifier(Box::new(test_case::expand)));
register(Symbol::intern("test"), MultiModifier(Box::new(test::expand_test)));
register(Symbol::intern("bench"), MultiModifier(Box::new(test::expand_bench)));
register(Symbol::intern("format_args"),
NormalTT {
expander: Box::new(format::expand_format_args),
def_info: None,
allow_internal_unstable: true,
allow_internal_unsafe: false,
local_inner_macros: false,
unstable_feature: None,
edition: hygiene::default_edition(),
});
register(Symbol::intern("format_args_nl"),
NormalTT {
expander: Box::new(format::expand_format_args_nl),
def_info: None,
allow_internal_unstable: true,
allow_internal_unsafe: false,
local_inner_macros: false,
unstable_feature: None,
edition: hygiene::default_edition(),
});
for (name, ext) in user_exts {
register(name, ext);
}
}