]>
Commit | Line | Data |
---|---|---|
416331ca XL |
1 | //! This crate contains implementations of built-in macros and other code generating facilities |
2 | //! injecting code into the crate before it is lowered to HIR. | |
9cc50fc6 | 3 | |
9fa01778 XL |
4 | #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] |
5 | ||
60c5eb7d | 6 | #![feature(bool_to_option)] |
416331ca | 7 | #![feature(crate_visibility_modifier)] |
ff7c6d11 | 8 | #![feature(decl_macro)] |
0bf4aa26 | 9 | #![feature(nll)] |
e1599b0c XL |
10 | #![feature(proc_macro_internals)] |
11 | #![feature(proc_macro_quote)] | |
12 | ||
13 | extern crate proc_macro; | |
83c7162d | 14 | |
416331ca | 15 | use crate::deriving::*; |
0731742a | 16 | |
416331ca XL |
17 | use syntax::ast::Ident; |
18 | use syntax::edition::Edition; | |
416331ca | 19 | use syntax::symbol::sym; |
e74abb32 XL |
20 | use syntax_expand::base::{Resolver, SyntaxExtension, SyntaxExtensionKind, MacroExpanderFn}; |
21 | use syntax_expand::proc_macro::BangProcMacro; | |
83c7162d | 22 | |
9cc50fc6 | 23 | mod asm; |
94b46f34 | 24 | mod assert; |
9cc50fc6 | 25 | mod cfg; |
041b39d2 | 26 | mod compile_error; |
9cc50fc6 SL |
27 | mod concat; |
28 | mod concat_idents; | |
416331ca | 29 | mod deriving; |
9cc50fc6 SL |
30 | mod env; |
31 | mod format; | |
476ff2be | 32 | mod format_foreign; |
416331ca | 33 | mod global_allocator; |
cc61c64b | 34 | mod global_asm; |
9cc50fc6 | 35 | mod log_syntax; |
416331ca | 36 | mod source_util; |
b7449926 | 37 | mod test; |
0731742a | 38 | mod trace_macros; |
e74abb32 | 39 | mod util; |
9cc50fc6 | 40 | |
e1599b0c | 41 | pub mod cmdline_attrs; |
416331ca XL |
42 | pub mod proc_macro_harness; |
43 | pub mod standard_library_imports; | |
44 | pub mod test_harness; | |
45 | ||
e74abb32 | 46 | pub fn register_builtin_macros(resolver: &mut dyn Resolver, edition: Edition) { |
416331ca | 47 | let mut register = |name, kind| resolver.register_builtin_macro( |
e1599b0c | 48 | Ident::with_dummy_span(name), SyntaxExtension { |
416331ca XL |
49 | is_builtin: true, ..SyntaxExtension::default(kind, edition) |
50 | }, | |
51 | ); | |
52 | macro register_bang($($name:ident: $f:expr,)*) { | |
53 | $(register(sym::$name, SyntaxExtensionKind::LegacyBang(Box::new($f as MacroExpanderFn)));)* | |
dc9dc135 | 54 | } |
416331ca XL |
55 | macro register_attr($($name:ident: $f:expr,)*) { |
56 | $(register(sym::$name, SyntaxExtensionKind::LegacyAttr(Box::new($f)));)* | |
57 | } | |
58 | macro register_derive($($name:ident: $f:expr,)*) { | |
59 | $(register(sym::$name, SyntaxExtensionKind::LegacyDerive(Box::new(BuiltinDerive($f))));)* | |
9e0c209e SL |
60 | } |
61 | ||
416331ca | 62 | register_bang! { |
9e0c209e | 63 | asm: asm::expand_asm, |
416331ca | 64 | assert: assert::expand_assert, |
9e0c209e | 65 | cfg: cfg::expand_cfg, |
416331ca XL |
66 | column: source_util::expand_column, |
67 | compile_error: compile_error::expand_compile_error, | |
e1599b0c XL |
68 | concat_idents: concat_idents::expand_concat_idents, |
69 | concat: concat::expand_concat, | |
9e0c209e | 70 | env: env::expand_env, |
416331ca XL |
71 | file: source_util::expand_file, |
72 | format_args_nl: format::expand_format_args_nl, | |
73 | format_args: format::expand_format_args, | |
74 | global_asm: global_asm::expand_global_asm, | |
75 | include_bytes: source_util::expand_include_bytes, | |
76 | include_str: source_util::expand_include_str, | |
77 | include: source_util::expand_include, | |
78 | line: source_util::expand_line, | |
e1599b0c | 79 | log_syntax: log_syntax::expand_log_syntax, |
416331ca XL |
80 | module_path: source_util::expand_mod, |
81 | option_env: env::expand_option_env, | |
82 | stringify: source_util::expand_stringify, | |
9e0c209e SL |
83 | trace_macros: trace_macros::expand_trace_macros, |
84 | } | |
85 | ||
dc9dc135 | 86 | register_attr! { |
dc9dc135 | 87 | bench: test::expand_bench, |
416331ca XL |
88 | global_allocator: global_allocator::expand, |
89 | test: test::expand_test, | |
90 | test_case: test::expand_test_case, | |
dc9dc135 | 91 | } |
b7449926 | 92 | |
416331ca XL |
93 | register_derive! { |
94 | Clone: clone::expand_deriving_clone, | |
95 | Copy: bounds::expand_deriving_copy, | |
96 | Debug: debug::expand_deriving_debug, | |
97 | Default: default::expand_deriving_default, | |
98 | Eq: eq::expand_deriving_eq, | |
99 | Hash: hash::expand_deriving_hash, | |
100 | Ord: ord::expand_deriving_ord, | |
101 | PartialEq: partial_eq::expand_deriving_partial_eq, | |
102 | PartialOrd: partial_ord::expand_deriving_partial_ord, | |
103 | RustcDecodable: decodable::expand_deriving_rustc_decodable, | |
104 | RustcEncodable: encodable::expand_deriving_rustc_encodable, | |
c30ab7b3 | 105 | } |
e1599b0c XL |
106 | |
107 | let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote); | |
108 | register(sym::quote, SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client }))); | |
9cc50fc6 | 109 | } |