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