]> git.lizzy.rs Git - rust.git/blob - src/libsyntax_ext/lib.rs
Rollup merge of #64016 - nnethercote:Compiler-fiddling, r=oli-obk
[rust.git] / src / libsyntax_ext / lib.rs
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.
3
4 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
5
6 #![feature(crate_visibility_modifier)]
7 #![feature(decl_macro)]
8 #![feature(mem_take)]
9 #![feature(nll)]
10 #![feature(proc_macro_internals)]
11 #![feature(proc_macro_quote)]
12
13 extern crate proc_macro;
14
15 use crate::deriving::*;
16
17 use syntax::ast::Ident;
18 use syntax::edition::Edition;
19 use syntax::ext::base::{SyntaxExtension, SyntaxExtensionKind, MacroExpanderFn};
20 use syntax::ext::proc_macro::BangProcMacro;
21 use syntax::symbol::sym;
22
23 mod error_codes;
24
25 mod asm;
26 mod assert;
27 mod cfg;
28 mod compile_error;
29 mod concat;
30 mod concat_idents;
31 mod deriving;
32 mod env;
33 mod format;
34 mod format_foreign;
35 mod global_allocator;
36 mod global_asm;
37 mod log_syntax;
38 mod source_util;
39 mod test;
40 mod trace_macros;
41
42 pub mod cmdline_attrs;
43 pub mod plugin_macro_defs;
44 pub mod proc_macro_harness;
45 pub mod standard_library_imports;
46 pub mod test_harness;
47
48 pub fn register_builtin_macros(resolver: &mut dyn syntax::ext::base::Resolver, edition: Edition) {
49     let mut register = |name, kind| resolver.register_builtin_macro(
50         Ident::with_dummy_span(name), SyntaxExtension {
51             is_builtin: true, ..SyntaxExtension::default(kind, edition)
52         },
53     );
54     macro register_bang($($name:ident: $f:expr,)*) {
55         $(register(sym::$name, SyntaxExtensionKind::LegacyBang(Box::new($f as MacroExpanderFn)));)*
56     }
57     macro register_attr($($name:ident: $f:expr,)*) {
58         $(register(sym::$name, SyntaxExtensionKind::LegacyAttr(Box::new($f)));)*
59     }
60     macro register_derive($($name:ident: $f:expr,)*) {
61         $(register(sym::$name, SyntaxExtensionKind::LegacyDerive(Box::new(BuiltinDerive($f))));)*
62     }
63
64     register_bang! {
65         asm: asm::expand_asm,
66         assert: assert::expand_assert,
67         cfg: cfg::expand_cfg,
68         column: source_util::expand_column,
69         compile_error: compile_error::expand_compile_error,
70         concat_idents: concat_idents::expand_concat_idents,
71         concat: concat::expand_concat,
72         env: env::expand_env,
73         file: source_util::expand_file,
74         format_args_nl: format::expand_format_args_nl,
75         format_args: format::expand_format_args,
76         global_asm: global_asm::expand_global_asm,
77         include_bytes: source_util::expand_include_bytes,
78         include_str: source_util::expand_include_str,
79         include: source_util::expand_include,
80         line: source_util::expand_line,
81         log_syntax: log_syntax::expand_log_syntax,
82         module_path: source_util::expand_mod,
83         option_env: env::expand_option_env,
84         stringify: source_util::expand_stringify,
85         trace_macros: trace_macros::expand_trace_macros,
86     }
87
88     register_attr! {
89         bench: test::expand_bench,
90         global_allocator: global_allocator::expand,
91         test: test::expand_test,
92         test_case: test::expand_test_case,
93     }
94
95     register_derive! {
96         Clone: clone::expand_deriving_clone,
97         Copy: bounds::expand_deriving_copy,
98         Debug: debug::expand_deriving_debug,
99         Default: default::expand_deriving_default,
100         Eq: eq::expand_deriving_eq,
101         Hash: hash::expand_deriving_hash,
102         Ord: ord::expand_deriving_ord,
103         PartialEq: partial_eq::expand_deriving_partial_eq,
104         PartialOrd: partial_ord::expand_deriving_partial_ord,
105         RustcDecodable: decodable::expand_deriving_rustc_decodable,
106         RustcEncodable: encodable::expand_deriving_rustc_encodable,
107     }
108
109     let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
110     register(sym::quote, SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client })));
111 }