118 lines
3.9 KiB
Rust
Raw Normal View History

//! This crate contains implementations of built-in macros and other code generating facilities
//! injecting code into the crate before it is lowered to HIR.
2020-09-23 21:51:56 +02:00
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
2021-01-29 08:31:08 +01:00
#![feature(box_patterns)]
#![feature(box_syntax)]
2019-10-08 01:14:42 +01:00
#![feature(bool_to_option)]
#![feature(crate_visibility_modifier)]
#![feature(decl_macro)]
#![feature(nll)]
2020-11-21 15:12:05 -06:00
#![cfg_attr(bootstrap, feature(or_patterns))]
#![feature(proc_macro_internals)]
#![feature(proc_macro_quote)]
#![recursion_limit = "256"]
2019-02-04 21:49:54 +09:00
extern crate proc_macro;
use crate::deriving::*;
2021-01-10 14:36:30 +03:00
use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtensionKind};
use rustc_expand::proc_macro::BangProcMacro;
2021-01-10 14:36:30 +03:00
use rustc_span::symbol::sym;
mod asm;
2018-05-17 21:17:53 +02:00
mod assert;
mod cfg;
mod cfg_accessible;
mod cfg_eval;
2017-05-06 23:26:45 -04:00
mod compile_error;
mod concat;
mod concat_idents;
mod derive;
2019-07-18 21:02:34 +03:00
mod deriving;
mod env;
mod format;
mod format_foreign;
mod global_allocator;
2017-03-15 21:27:40 -05:00
mod global_asm;
mod llvm_asm;
mod log_syntax;
mod panic;
mod source_util;
2018-07-20 18:04:02 -07:00
mod test;
mod trace_macros;
2019-10-08 14:15:26 +02:00
mod util;
pub mod cmdline_attrs;
pub mod proc_macro_harness;
pub mod standard_library_imports;
pub mod test_harness;
2021-01-10 14:36:30 +03:00
pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
let mut register = |name, kind| resolver.register_builtin_macro(name, kind);
macro register_bang($($name:ident: $f:expr,)*) {
$(register(sym::$name, SyntaxExtensionKind::LegacyBang(Box::new($f as MacroExpanderFn)));)*
}
macro register_attr($($name:ident: $f:expr,)*) {
$(register(sym::$name, SyntaxExtensionKind::LegacyAttr(Box::new($f)));)*
}
macro register_derive($($name:ident: $f:expr,)*) {
$(register(sym::$name, SyntaxExtensionKind::LegacyDerive(Box::new(BuiltinDerive($f))));)*
}
register_bang! {
asm: asm::expand_asm,
assert: assert::expand_assert,
cfg: cfg::expand_cfg,
column: source_util::expand_column,
compile_error: compile_error::expand_compile_error,
concat_idents: concat_idents::expand_concat_idents,
concat: concat::expand_concat,
env: env::expand_env,
file: source_util::expand_file,
format_args_nl: format::expand_format_args_nl,
format_args: format::expand_format_args,
global_asm: global_asm::expand_global_asm,
include_bytes: source_util::expand_include_bytes,
include_str: source_util::expand_include_str,
include: source_util::expand_include,
line: source_util::expand_line,
llvm_asm: llvm_asm::expand_llvm_asm,
log_syntax: log_syntax::expand_log_syntax,
module_path: source_util::expand_mod,
option_env: env::expand_option_env,
core_panic: panic::expand_panic,
std_panic: panic::expand_panic,
stringify: source_util::expand_stringify,
trace_macros: trace_macros::expand_trace_macros,
}
2018-07-20 18:04:02 -07:00
register_attr! {
bench: test::expand_bench,
cfg_accessible: cfg_accessible::Expander,
cfg_eval: cfg_eval::expand,
derive: derive::Expander,
global_allocator: global_allocator::expand,
test: test::expand_test,
test_case: test::expand_test_case,
}
register_derive! {
Clone: clone::expand_deriving_clone,
Copy: bounds::expand_deriving_copy,
Debug: debug::expand_deriving_debug,
Default: default::expand_deriving_default,
Eq: eq::expand_deriving_eq,
Hash: hash::expand_deriving_hash,
Ord: ord::expand_deriving_ord,
PartialEq: partial_eq::expand_deriving_partial_eq,
PartialOrd: partial_ord::expand_deriving_partial_ord,
RustcDecodable: decodable::expand_deriving_rustc_decodable,
RustcEncodable: encodable::expand_deriving_rustc_encodable,
}
let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
register(sym::quote, SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client })));
}