]> git.lizzy.rs Git - rust.git/blob - src/libsyntax_ext/lib.rs
rustc: Remove #![unstable] annotation
[rust.git] / src / libsyntax_ext / lib.rs
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
13 #![crate_name = "syntax_ext"]
14 #![crate_type = "dylib"]
15 #![crate_type = "rlib"]
16 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
17        html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
18        html_root_url = "https://doc.rust-lang.org/nightly/")]
19 #![deny(warnings)]
20
21 #![feature(proc_macro_internals)]
22
23 #![cfg_attr(stage0, unstable(feature = "rustc_private", issue = "27812"))]
24 #![cfg_attr(stage0, feature(rustc_private))]
25 #![cfg_attr(stage0, feature(staged_api))]
26
27 extern crate fmt_macros;
28 extern crate log;
29 #[macro_use]
30 extern crate syntax;
31 extern crate syntax_pos;
32 extern crate proc_macro;
33 extern crate rustc_errors as errors;
34
35 mod asm;
36 mod cfg;
37 mod concat;
38 mod concat_idents;
39 mod env;
40 mod format;
41 mod format_foreign;
42 mod global_asm;
43 mod log_syntax;
44 mod trace_macros;
45
46 pub mod proc_macro_registrar;
47
48 // for custom_derive
49 pub mod deriving;
50
51 pub mod proc_macro_impl;
52
53 use std::rc::Rc;
54 use syntax::ast;
55 use syntax::ext::base::{MacroExpanderFn, NormalTT, NamedSyntaxExtension};
56 use syntax::symbol::Symbol;
57
58 pub fn register_builtins(resolver: &mut syntax::ext::base::Resolver,
59                          user_exts: Vec<NamedSyntaxExtension>,
60                          enable_quotes: bool) {
61     deriving::register_builtin_derives(resolver);
62
63     let mut register = |name, ext| {
64         resolver.add_builtin(ast::Ident::with_empty_ctxt(name), Rc::new(ext));
65     };
66
67     macro_rules! register {
68         ($( $name:ident: $f:expr, )*) => { $(
69             register(Symbol::intern(stringify!($name)),
70                      NormalTT(Box::new($f as MacroExpanderFn), None, false));
71         )* }
72     }
73
74     if enable_quotes {
75         use syntax::ext::quote::*;
76         register! {
77             quote_tokens: expand_quote_tokens,
78             quote_expr: expand_quote_expr,
79             quote_ty: expand_quote_ty,
80             quote_item: expand_quote_item,
81             quote_pat: expand_quote_pat,
82             quote_arm: expand_quote_arm,
83             quote_stmt: expand_quote_stmt,
84             quote_attr: expand_quote_attr,
85             quote_arg: expand_quote_arg,
86             quote_block: expand_quote_block,
87             quote_meta_item: expand_quote_meta_item,
88             quote_path: expand_quote_path,
89         }
90     }
91
92     use syntax::ext::source_util::*;
93     register! {
94         line: expand_line,
95         column: expand_column,
96         file: expand_file,
97         stringify: expand_stringify,
98         include: expand_include,
99         include_str: expand_include_str,
100         include_bytes: expand_include_bytes,
101         module_path: expand_mod,
102
103         asm: asm::expand_asm,
104         global_asm: global_asm::expand_global_asm,
105         cfg: cfg::expand_cfg,
106         concat: concat::expand_syntax_ext,
107         concat_idents: concat_idents::expand_syntax_ext,
108         env: env::expand_env,
109         option_env: env::expand_option_env,
110         log_syntax: log_syntax::expand_syntax_ext,
111         trace_macros: trace_macros::expand_trace_macros,
112     }
113
114     // format_args uses `unstable` things internally.
115     register(Symbol::intern("format_args"),
116              NormalTT(Box::new(format::expand_format_args), None, true));
117
118     for (name, ext) in user_exts {
119         register(name, ext);
120     }
121 }