rust/src/libsyntax/lib.rs

118 lines
2.8 KiB
Rust
Raw Normal View History

2014-06-09 20:12:30 +00:00
//! The Rust parser and macro expander.
//!
//! # Note
//!
//! This API is completely unstable and subject to change.
2013-03-29 19:51:10 +00:00
2019-12-22 22:42:04 +00:00
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/", test(attr(deny(warnings))))]
2019-10-08 00:14:42 +00:00
#![feature(bool_to_option)]
#![feature(box_syntax)]
#![feature(const_fn)]
#![feature(const_transmute)]
#![feature(crate_visibility_modifier)]
#![feature(label_break_value)]
2019-02-10 07:13:30 +00:00
#![feature(nll)]
2018-08-20 00:51:02 +00:00
#![feature(try_trait)]
2019-10-08 08:59:05 +00:00
#![feature(slice_patterns)]
#![feature(unicode_internals)]
2019-12-22 22:42:04 +00:00
#![recursion_limit = "256"]
2019-12-22 22:42:04 +00:00
use ast::AttrId;
pub use errors;
use rustc_data_structures::sync::Lock;
use rustc_index::bit_set::GrowableBitSet;
use syntax_pos::edition::Edition;
#[macro_export]
macro_rules! unwrap_or {
($opt:expr, $default:expr) => {
match $opt {
Some(x) => x,
None => $default,
}
2019-12-22 22:42:04 +00:00
};
}
2018-04-25 22:49:52 +00:00
pub struct Globals {
Merge indexed_set.rs into bitvec.rs, and rename it bit_set.rs. Currently we have two files implementing bitsets (and 2D bit matrices). This commit combines them into one, taking the best features from each. This involves renaming a lot of things. The high level changes are as follows. - bitvec.rs --> bit_set.rs - indexed_set.rs --> (removed) - BitArray + IdxSet --> BitSet (merged, see below) - BitVector --> GrowableBitSet - {,Sparse,Hybrid}IdxSet --> {,Sparse,Hybrid}BitSet - BitMatrix --> BitMatrix - SparseBitMatrix --> SparseBitMatrix The changes within the bitset types themselves are as follows. ``` OLD OLD NEW BitArray<C> IdxSet<T> BitSet<T> -------- ------ ------ grow - grow new - (remove) new_empty new_empty new_empty new_filled new_filled new_filled - to_hybrid to_hybrid clear clear clear set_up_to set_up_to set_up_to clear_above - clear_above count - count contains(T) contains(&T) contains(T) contains_all - superset is_empty - is_empty insert(T) add(&T) insert(T) insert_all - insert_all() remove(T) remove(&T) remove(T) words words words words_mut words_mut words_mut - overwrite overwrite merge union union - subtract subtract - intersect intersect iter iter iter ``` In general, when choosing names I went with: - names that are more obvious (e.g. `BitSet` over `IdxSet`). - names that are more like the Rust libraries (e.g. `T` over `C`, `insert` over `add`); - names that are more set-like (e.g. `union` over `merge`, `superset` over `contains_all`, `domain_size` over `num_bits`). Also, using `T` for index arguments seems more sensible than `&T` -- even though the latter is standard in Rust collection types -- because indices are always copyable. It also results in fewer `&` and `*` sigils in practice.
2018-09-14 05:07:25 +00:00
used_attrs: Lock<GrowableBitSet<AttrId>>,
known_attrs: Lock<GrowableBitSet<AttrId>>,
syntax_pos_globals: syntax_pos::Globals,
}
impl Globals {
fn new(edition: Edition) -> Globals {
Globals {
2019-10-20 15:03:33 +00:00
// We have no idea how many attributes there will be, so just
// initiate the vectors with 0 bits. We'll grow them as necessary.
Merge indexed_set.rs into bitvec.rs, and rename it bit_set.rs. Currently we have two files implementing bitsets (and 2D bit matrices). This commit combines them into one, taking the best features from each. This involves renaming a lot of things. The high level changes are as follows. - bitvec.rs --> bit_set.rs - indexed_set.rs --> (removed) - BitArray + IdxSet --> BitSet (merged, see below) - BitVector --> GrowableBitSet - {,Sparse,Hybrid}IdxSet --> {,Sparse,Hybrid}BitSet - BitMatrix --> BitMatrix - SparseBitMatrix --> SparseBitMatrix The changes within the bitset types themselves are as follows. ``` OLD OLD NEW BitArray<C> IdxSet<T> BitSet<T> -------- ------ ------ grow - grow new - (remove) new_empty new_empty new_empty new_filled new_filled new_filled - to_hybrid to_hybrid clear clear clear set_up_to set_up_to set_up_to clear_above - clear_above count - count contains(T) contains(&T) contains(T) contains_all - superset is_empty - is_empty insert(T) add(&T) insert(T) insert_all - insert_all() remove(T) remove(&T) remove(T) words words words words_mut words_mut words_mut - overwrite overwrite merge union union - subtract subtract - intersect intersect iter iter iter ``` In general, when choosing names I went with: - names that are more obvious (e.g. `BitSet` over `IdxSet`). - names that are more like the Rust libraries (e.g. `T` over `C`, `insert` over `add`); - names that are more set-like (e.g. `union` over `merge`, `superset` over `contains_all`, `domain_size` over `num_bits`). Also, using `T` for index arguments seems more sensible than `&T` -- even though the latter is standard in Rust collection types -- because indices are always copyable. It also results in fewer `&` and `*` sigils in practice.
2018-09-14 05:07:25 +00:00
used_attrs: Lock::new(GrowableBitSet::new_empty()),
known_attrs: Lock::new(GrowableBitSet::new_empty()),
syntax_pos_globals: syntax_pos::Globals::new(edition),
}
}
}
pub fn with_globals<F, R>(edition: Edition, f: F) -> R
2019-12-22 22:42:04 +00:00
where
F: FnOnce() -> R,
{
let globals = Globals::new(edition);
2019-12-22 22:42:04 +00:00
GLOBALS.set(&globals, || syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f))
}
pub fn with_default_globals<F, R>(f: F) -> R
2019-12-22 22:42:04 +00:00
where
F: FnOnce() -> R,
{
with_globals(edition::DEFAULT_EDITION, f)
}
2019-02-06 17:33:01 +00:00
scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
2016-06-28 17:40:40 +00:00
#[macro_use]
pub mod diagnostics {
#[macro_use]
pub mod macros;
}
2013-04-03 16:41:40 +00:00
pub mod util {
pub mod classify;
pub mod comments;
pub mod lev_distance;
pub mod literal;
2019-12-22 22:42:04 +00:00
pub mod map_in_place;
pub mod node_count;
pub mod parser;
2013-04-03 16:41:40 +00:00
}
pub mod ast;
pub mod attr;
pub mod expand;
pub use syntax_pos::source_map;
pub mod entry;
pub mod feature_gate {
mod check;
2019-12-22 22:42:04 +00:00
pub use check::{check_attribute, check_crate, feature_err, feature_err_issue, get_features};
}
2019-02-05 22:10:05 +00:00
pub mod mut_visit;
pub mod ptr;
2014-07-25 02:44:24 +00:00
pub mod show_span;
2019-12-22 22:42:04 +00:00
pub use rustc_session::parse as sess;
pub use syntax_pos::edition;
2017-03-17 04:04:41 +00:00
pub use syntax_pos::symbol;
2019-10-11 10:46:32 +00:00
pub mod token;
pub mod tokenstream;
pub mod visit;
pub mod print {
2019-12-22 22:42:04 +00:00
mod helpers;
pub mod pp;
pub mod pprust;
2012-03-29 20:48:05 +00:00
}
pub mod early_buffered_lints;
/// Requirements for a `StableHashingContext` to be used in this crate.
/// This is a hack to allow using the `HashStable_Generic` derive macro
/// instead of implementing everything in librustc.
2019-11-23 13:47:31 +00:00
pub trait HashStableContext: syntax_pos::HashStableContext {}