115 lines
3.6 KiB
Rust
Raw Normal View History

//! Syntax extensions in the Rust compiler.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
2015-12-15 16:23:18 +09:00
2019-02-04 21:49:54 +09:00
#![deny(rust_2018_idioms)]
2019-06-11 12:21:12 +03:00
#![deny(unused_lifetimes)]
2019-02-04 21:49:54 +09:00
#![feature(crate_visibility_modifier)]
#![feature(decl_macro)]
#![feature(nll)]
#![feature(proc_macro_diagnostic)]
#![feature(proc_macro_internals)]
#![feature(proc_macro_span)]
2018-05-10 12:02:19 -06:00
#![feature(rustc_diagnostic_macros)]
#![feature(unicode_internals)]
2018-02-12 23:21:20 +01:00
extern crate proc_macro;
2019-02-04 21:49:54 +09:00
use crate::deriving::*;
use syntax::ast::Ident;
use syntax::edition::Edition;
use syntax::ext::base::{SyntaxExtension, SyntaxExtensionKind, MacroExpanderFn};
use syntax::ext::source_util;
use syntax::symbol::sym;
2019-04-17 07:35:54 +09:00
mod error_codes;
2018-02-12 23:21:20 +01:00
mod asm;
2018-05-17 21:17:53 +02:00
mod assert;
mod cfg;
2017-05-06 23:26:45 -04:00
mod compile_error;
mod concat;
mod concat_idents;
mod env;
mod format;
mod format_foreign;
mod global_allocator;
2017-03-15 21:27:40 -05:00
mod global_asm;
mod log_syntax;
mod proc_macro_server;
2018-07-20 18:04:02 -07:00
mod test;
mod test_case;
mod trace_macros;
pub mod deriving;
pub mod plugin_macro_defs;
pub mod proc_macro_decls;
pub mod proc_macro_impl;
pub fn register_builtin_macros(resolver: &mut dyn syntax::ext::base::Resolver, edition: Edition) {
let mut register = |name, kind| resolver.register_builtin_macro(
Ident::with_empty_ctxt(name), SyntaxExtension {
is_builtin: true, ..SyntaxExtension::default(kind, edition)
},
);
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! {
__rust_unstable_column: source_util::expand_column,
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_syntax_ext,
concat: concat::expand_syntax_ext,
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,
log_syntax: log_syntax::expand_syntax_ext,
module_path: source_util::expand_mod,
option_env: env::expand_option_env,
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,
global_allocator: global_allocator::expand,
test: test::expand_test,
test_case: test_case::expand,
}
register_derive! {
Clone: clone::expand_deriving_clone,
Copy: bounds::expand_deriving_copy,
Debug: debug::expand_deriving_debug,
Decodable: decodable::expand_deriving_decodable,
Default: default::expand_deriving_default,
Encodable: encodable::expand_deriving_encodable,
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,
}
}