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