]> git.proxmox.com Git - rustc.git/blame - src/libsyntax_ext/lib.rs
New upstream version 1.30.0+dfsg1
[rustc.git] / src / libsyntax_ext / lib.rs
CommitLineData
9cc50fc6
SL
1// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11//! Syntax extensions in the Rust compiler.
12
9cc50fc6
SL
13#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
14 html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
15 html_root_url = "https://doc.rust-lang.org/nightly/")]
9cc50fc6 16
c30ab7b3 17#![feature(proc_macro_internals)]
ff7c6d11 18#![feature(decl_macro)]
b7449926 19#![cfg_attr(not(stage0), feature(nll))]
4462d4a0 20#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
0531ce1d 21#![feature(str_escape)]
b7449926 22#![feature(quote)]
94b46f34 23#![feature(rustc_diagnostic_macros)]
83c7162d 24
9cc50fc6
SL
25extern crate fmt_macros;
26#[macro_use]
27extern crate syntax;
3157f602 28extern crate syntax_pos;
c30ab7b3 29extern crate proc_macro;
0531ce1d 30extern crate rustc_data_structures;
3157f602 31extern crate rustc_errors as errors;
83c7162d 32extern crate rustc_target;
b7449926
XL
33#[macro_use]
34extern crate smallvec;
35#[macro_use]
36extern crate log;
83c7162d 37
83c7162d 38mod diagnostics;
9cc50fc6 39
94b46f34
XL
40#[macro_use]
41// for custom_derive
42pub mod deriving;
43
9cc50fc6 44mod asm;
94b46f34 45mod assert;
9cc50fc6 46mod cfg;
041b39d2 47mod compile_error;
9cc50fc6
SL
48mod concat;
49mod concat_idents;
50mod env;
51mod format;
476ff2be 52mod format_foreign;
cc61c64b 53mod global_asm;
9cc50fc6
SL
54mod log_syntax;
55mod trace_macros;
b7449926
XL
56mod test;
57mod test_case;
9cc50fc6 58
c30ab7b3 59pub mod proc_macro_registrar;
9e0c209e 60
9cc50fc6 61
32a655c1
SL
62pub mod proc_macro_impl;
63
0531ce1d 64use rustc_data_structures::sync::Lrc;
9e0c209e 65use syntax::ast;
b7449926 66use syntax::ext::base::{MacroExpanderFn, NormalTT, NamedSyntaxExtension, MultiModifier};
94b46f34 67use syntax::ext::hygiene;
476ff2be 68use syntax::symbol::Symbol;
9e0c209e 69
8faf50e0 70pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver,
c30ab7b3
SL
71 user_exts: Vec<NamedSyntaxExtension>,
72 enable_quotes: bool) {
8bb4bdeb
XL
73 deriving::register_builtin_derives(resolver);
74
9e0c209e 75 let mut register = |name, ext| {
0531ce1d 76 resolver.add_builtin(ast::Ident::with_empty_ctxt(name), Lrc::new(ext));
9e0c209e
SL
77 };
78
9e0c209e
SL
79 macro_rules! register {
80 ($( $name:ident: $f:expr, )*) => { $(
476ff2be 81 register(Symbol::intern(stringify!($name)),
3b2f2976
XL
82 NormalTT {
83 expander: Box::new($f as MacroExpanderFn),
84 def_info: None,
85 allow_internal_unstable: false,
86 allow_internal_unsafe: false,
8faf50e0 87 local_inner_macros: false,
0531ce1d 88 unstable_feature: None,
94b46f34 89 edition: hygiene::default_edition(),
3b2f2976 90 });
9e0c209e
SL
91 )* }
92 }
93
94 if enable_quotes {
95 use syntax::ext::quote::*;
96 register! {
97 quote_tokens: expand_quote_tokens,
98 quote_expr: expand_quote_expr,
99 quote_ty: expand_quote_ty,
100 quote_item: expand_quote_item,
101 quote_pat: expand_quote_pat,
102 quote_arm: expand_quote_arm,
103 quote_stmt: expand_quote_stmt,
9e0c209e
SL
104 quote_attr: expand_quote_attr,
105 quote_arg: expand_quote_arg,
106 quote_block: expand_quote_block,
107 quote_meta_item: expand_quote_meta_item,
108 quote_path: expand_quote_path,
109 }
9cc50fc6
SL
110 }
111
9e0c209e
SL
112 use syntax::ext::source_util::*;
113 register! {
114 line: expand_line,
041b39d2 115 __rust_unstable_column: expand_column_gated,
9e0c209e
SL
116 column: expand_column,
117 file: expand_file,
118 stringify: expand_stringify,
119 include: expand_include,
120 include_str: expand_include_str,
121 include_bytes: expand_include_bytes,
122 module_path: expand_mod,
123
124 asm: asm::expand_asm,
cc61c64b 125 global_asm: global_asm::expand_global_asm,
9e0c209e
SL
126 cfg: cfg::expand_cfg,
127 concat: concat::expand_syntax_ext,
128 concat_idents: concat_idents::expand_syntax_ext,
129 env: env::expand_env,
130 option_env: env::expand_option_env,
131 log_syntax: log_syntax::expand_syntax_ext,
132 trace_macros: trace_macros::expand_trace_macros,
041b39d2 133 compile_error: compile_error::expand_compile_error,
0531ce1d 134 assert: assert::expand_assert,
9e0c209e
SL
135 }
136
b7449926
XL
137 register(Symbol::intern("test_case"), MultiModifier(Box::new(test_case::expand)));
138 register(Symbol::intern("test"), MultiModifier(Box::new(test::expand_test)));
139 register(Symbol::intern("bench"), MultiModifier(Box::new(test::expand_bench)));
140
9e0c209e 141 // format_args uses `unstable` things internally.
476ff2be 142 register(Symbol::intern("format_args"),
3b2f2976
XL
143 NormalTT {
144 expander: Box::new(format::expand_format_args),
145 def_info: None,
146 allow_internal_unstable: true,
147 allow_internal_unsafe: false,
8faf50e0 148 local_inner_macros: false,
94b46f34
XL
149 unstable_feature: None,
150 edition: hygiene::default_edition(),
3b2f2976 151 });
8faf50e0
XL
152 register(Symbol::intern("format_args_nl"),
153 NormalTT {
154 expander: Box::new(format::expand_format_args_nl),
155 def_info: None,
156 allow_internal_unstable: true,
157 allow_internal_unsafe: false,
158 local_inner_macros: false,
159 unstable_feature: None,
160 edition: hygiene::default_edition(),
161 });
9e0c209e 162
c30ab7b3
SL
163 for (name, ext) in user_exts {
164 register(name, ext);
165 }
9cc50fc6 166}