]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/lib.rs
Auto merge of #53384 - gootorov:use-servo-smallvec, r=michaelwoerister
[rust.git] / src / libsyntax / lib.rs
1 // Copyright 2012-2013 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 //! The Rust parser and macro expander.
12 //!
13 //! # Note
14 //!
15 //! This API is completely unstable and subject to change.
16
17 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
18        html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
19        html_root_url = "https://doc.rust-lang.org/nightly/",
20        test(attr(deny(warnings))))]
21
22 #![feature(crate_visibility_modifier)]
23 #![feature(macro_at_most_once_rep)]
24 #![cfg_attr(not(stage0), feature(nll))]
25 #![feature(rustc_attrs)]
26 #![feature(rustc_diagnostic_macros)]
27 #![feature(slice_sort_by_cached_key)]
28 #![feature(str_escape)]
29 #![feature(try_trait)]
30 #![feature(unicode_internals)]
31
32 #![recursion_limit="256"]
33
34 #[macro_use] extern crate bitflags;
35 extern crate core;
36 extern crate serialize;
37 #[macro_use] extern crate log;
38 pub extern crate rustc_errors as errors;
39 extern crate syntax_pos;
40 extern crate rustc_data_structures;
41 extern crate rustc_target;
42 #[macro_use] extern crate scoped_tls;
43 #[macro_use]
44 extern crate smallvec;
45
46 extern crate serialize as rustc_serialize; // used by deriving
47
48 use rustc_data_structures::sync::Lock;
49 use rustc_data_structures::bitvec::BitVector;
50 pub use rustc_data_structures::small_vec::OneVector;
51 pub use rustc_data_structures::thin_vec::ThinVec;
52 use ast::AttrId;
53
54 // A variant of 'try!' that panics on an Err. This is used as a crutch on the
55 // way towards a non-panic!-prone parser. It should be used for fatal parsing
56 // errors; eventually we plan to convert all code using panictry to just use
57 // normal try.
58 // Exported for syntax_ext, not meant for general use.
59 #[macro_export]
60 macro_rules! panictry {
61     ($e:expr) => ({
62         use std::result::Result::{Ok, Err};
63         use errors::FatalError;
64         match $e {
65             Ok(e) => e,
66             Err(mut e) => {
67                 e.emit();
68                 FatalError.raise()
69             }
70         }
71     })
72 }
73
74 #[macro_export]
75 macro_rules! unwrap_or {
76     ($opt:expr, $default:expr) => {
77         match $opt {
78             Some(x) => x,
79             None => $default,
80         }
81     }
82 }
83
84 pub struct Globals {
85     used_attrs: Lock<BitVector<AttrId>>,
86     known_attrs: Lock<BitVector<AttrId>>,
87     syntax_pos_globals: syntax_pos::Globals,
88 }
89
90 impl Globals {
91     fn new() -> Globals {
92         Globals {
93             // We have no idea how many attributes their will be, so just
94             // initiate the vectors with 0 bits. We'll grow them as necessary.
95             used_attrs: Lock::new(BitVector::new()),
96             known_attrs: Lock::new(BitVector::new()),
97             syntax_pos_globals: syntax_pos::Globals::new(),
98         }
99     }
100 }
101
102 pub fn with_globals<F, R>(f: F) -> R
103     where F: FnOnce() -> R
104 {
105     let globals = Globals::new();
106     GLOBALS.set(&globals, || {
107         syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
108     })
109 }
110
111 scoped_thread_local!(pub static GLOBALS: Globals);
112
113 #[macro_use]
114 pub mod diagnostics {
115     #[macro_use]
116     pub mod macros;
117     pub mod plugin;
118     pub mod metadata;
119 }
120
121 // NB: This module needs to be declared first so diagnostics are
122 // registered before they are used.
123 pub mod diagnostic_list;
124
125 pub mod util {
126     pub mod lev_distance;
127     pub mod node_count;
128     pub mod parser;
129     #[cfg(test)]
130     pub mod parser_testing;
131     pub mod move_map;
132
133     mod rc_slice;
134     pub use self::rc_slice::RcSlice;
135
136     mod rc_vec;
137     pub use self::rc_vec::RcVec;
138 }
139
140 pub mod json;
141
142 pub mod syntax {
143     pub use ext;
144     pub use parse;
145     pub use ast;
146 }
147
148 pub mod ast;
149 pub mod attr;
150 pub mod source_map;
151 #[macro_use]
152 pub mod config;
153 pub mod entry;
154 pub mod feature_gate;
155 pub mod fold;
156 pub mod parse;
157 pub mod ptr;
158 pub mod show_span;
159 pub mod std_inject;
160 pub mod str;
161 pub use syntax_pos::edition;
162 pub use syntax_pos::symbol;
163 pub mod test;
164 pub mod tokenstream;
165 pub mod visit;
166
167 pub mod print {
168     pub mod pp;
169     pub mod pprust;
170 }
171
172 pub mod ext {
173     pub use syntax_pos::hygiene;
174     pub mod base;
175     pub mod build;
176     pub mod derive;
177     pub mod expand;
178     pub mod placeholders;
179     pub mod quote;
180     pub mod source_util;
181
182     pub mod tt {
183         pub mod transcribe;
184         pub mod macro_parser;
185         pub mod macro_rules;
186         pub mod quoted;
187     }
188 }
189
190 pub mod early_buffered_lints;
191
192 #[cfg(test)]
193 mod test_snippet;
194
195 __build_diagnostic_array! { libsyntax, DIAGNOSTICS }