]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/lib.rs
Simplify Cache wrapper to single type, impl Deref on it, fix all compilation errors...
[rust.git] / src / libsyntax / lib.rs
1 //! The Rust parser and macro expander.
2 //!
3 //! # Note
4 //!
5 //! This API is completely unstable and subject to change.
6
7 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/",
8        test(attr(deny(warnings))))]
9
10 #![feature(box_syntax)]
11 #![feature(const_fn)]
12 #![feature(const_transmute)]
13 #![feature(crate_visibility_modifier)]
14 #![feature(label_break_value)]
15 #![feature(nll)]
16 #![feature(try_trait)]
17 #![feature(slice_patterns)]
18 #![feature(unicode_internals)]
19
20 #![recursion_limit="256"]
21
22 pub use errors;
23 use rustc_data_structures::sync::Lock;
24 use rustc_index::bit_set::GrowableBitSet;
25 pub use rustc_data_structures::thin_vec::ThinVec;
26 use ast::AttrId;
27 use syntax_pos::edition::Edition;
28
29 #[macro_export]
30 macro_rules! unwrap_or {
31     ($opt:expr, $default:expr) => {
32         match $opt {
33             Some(x) => x,
34             None => $default,
35         }
36     }
37 }
38
39 pub struct Globals {
40     used_attrs: Lock<GrowableBitSet<AttrId>>,
41     known_attrs: Lock<GrowableBitSet<AttrId>>,
42     syntax_pos_globals: syntax_pos::Globals,
43 }
44
45 impl Globals {
46     fn new(edition: Edition) -> Globals {
47         Globals {
48             // We have no idea how many attributes there will be, so just
49             // initiate the vectors with 0 bits. We'll grow them as necessary.
50             used_attrs: Lock::new(GrowableBitSet::new_empty()),
51             known_attrs: Lock::new(GrowableBitSet::new_empty()),
52             syntax_pos_globals: syntax_pos::Globals::new(edition),
53         }
54     }
55 }
56
57 pub fn with_globals<F, R>(edition: Edition, f: F) -> R
58     where F: FnOnce() -> R
59 {
60     let globals = Globals::new(edition);
61     GLOBALS.set(&globals, || {
62         syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
63     })
64 }
65
66 pub fn with_default_globals<F, R>(f: F) -> R
67     where F: FnOnce() -> R
68 {
69     with_globals(edition::DEFAULT_EDITION, f)
70 }
71
72 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
73
74 #[macro_use]
75 pub mod diagnostics {
76     #[macro_use]
77     pub mod macros;
78 }
79
80 pub mod util {
81     pub mod classify;
82     pub mod comments;
83     pub mod lev_distance;
84     pub mod literal;
85     pub mod node_count;
86     pub mod parser;
87     pub mod map_in_place;
88 }
89
90 pub mod ast;
91 pub mod attr;
92 pub mod expand;
93 pub use syntax_pos::source_map;
94 pub mod entry;
95 pub mod feature_gate {
96     mod check;
97     pub use check::{check_crate, check_attribute, get_features, feature_err, feature_err_issue};
98 }
99 pub mod mut_visit;
100 pub mod ptr;
101 pub mod show_span;
102 pub use syntax_pos::edition;
103 pub use syntax_pos::symbol;
104 pub mod sess;
105 pub mod token;
106 pub mod tokenstream;
107 pub mod visit;
108
109 pub mod print {
110     pub mod pp;
111     pub mod pprust;
112     mod helpers;
113 }
114
115 pub mod early_buffered_lints;
116
117 /// Requirements for a `StableHashingContext` to be used in this crate.
118 /// This is a hack to allow using the `HashStable_Generic` derive macro
119 /// instead of implementing everything in librustc.
120 pub trait HashStableContext: syntax_pos::HashStableContext {}