1
Fork 0

Move tracking of the next NodeId from syntax's ParseSess to rustc's Session.

This commit is contained in:
Eduard Burtescu 2015-05-13 16:45:50 +03:00
parent 222cd73b8a
commit 6a045b9d1c
2 changed files with 15 additions and 24 deletions

View file

@ -64,7 +64,9 @@ pub struct Session {
/// operations such as auto-dereference and monomorphization. /// operations such as auto-dereference and monomorphization.
pub recursion_limit: Cell<usize>, pub recursion_limit: Cell<usize>,
pub can_print_warnings: bool pub can_print_warnings: bool,
next_node_id: Cell<ast::NodeId>
} }
impl Session { impl Session {
@ -213,10 +215,17 @@ impl Session {
lints.insert(id, vec!((lint_id, sp, msg))); lints.insert(id, vec!((lint_id, sp, msg)));
} }
pub fn next_node_id(&self) -> ast::NodeId { pub fn next_node_id(&self) -> ast::NodeId {
self.parse_sess.next_node_id() self.reserve_node_ids(1)
} }
pub fn reserve_node_ids(&self, count: ast::NodeId) -> ast::NodeId { pub fn reserve_node_ids(&self, count: ast::NodeId) -> ast::NodeId {
self.parse_sess.reserve_node_ids(count) let id = self.next_node_id.get();
match id.checked_add(count) {
Some(next) => self.next_node_id.set(next),
None => self.bug("Input too large, ran out of node ids!")
}
id
} }
pub fn diagnostic<'a>(&'a self) -> &'a diagnostic::SpanHandler { pub fn diagnostic<'a>(&'a self) -> &'a diagnostic::SpanHandler {
&self.parse_sess.span_diagnostic &self.parse_sess.span_diagnostic
@ -421,7 +430,8 @@ pub fn build_session_(sopts: config::Options,
delayed_span_bug: RefCell::new(None), delayed_span_bug: RefCell::new(None),
features: RefCell::new(feature_gate::Features::new()), features: RefCell::new(feature_gate::Features::new()),
recursion_limit: Cell::new(64), recursion_limit: Cell::new(64),
can_print_warnings: can_print_warnings can_print_warnings: can_print_warnings,
next_node_id: Cell::new(1)
}; };
sess sess

View file

@ -18,7 +18,7 @@ use parse::parser::Parser;
use ptr::P; use ptr::P;
use str::char_at; use str::char_at;
use std::cell::{Cell, RefCell}; use std::cell::RefCell;
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
use std::iter; use std::iter;
@ -44,14 +44,12 @@ pub struct ParseSess {
pub span_diagnostic: SpanHandler, // better be the same as the one in the reader! pub span_diagnostic: SpanHandler, // better be the same as the one in the reader!
/// Used to determine and report recursive mod inclusions /// Used to determine and report recursive mod inclusions
included_mod_stack: RefCell<Vec<PathBuf>>, included_mod_stack: RefCell<Vec<PathBuf>>,
pub node_id: Cell<ast::NodeId>,
} }
pub fn new_parse_sess() -> ParseSess { pub fn new_parse_sess() -> ParseSess {
ParseSess { ParseSess {
span_diagnostic: mk_span_handler(default_handler(Auto, None, true), CodeMap::new()), span_diagnostic: mk_span_handler(default_handler(Auto, None, true), CodeMap::new()),
included_mod_stack: RefCell::new(Vec::new()), included_mod_stack: RefCell::new(Vec::new()),
node_id: Cell::new(1),
} }
} }
@ -59,23 +57,6 @@ pub fn new_parse_sess_special_handler(sh: SpanHandler) -> ParseSess {
ParseSess { ParseSess {
span_diagnostic: sh, span_diagnostic: sh,
included_mod_stack: RefCell::new(Vec::new()), included_mod_stack: RefCell::new(Vec::new()),
node_id: Cell::new(1),
}
}
impl ParseSess {
pub fn next_node_id(&self) -> ast::NodeId {
self.reserve_node_ids(1)
}
pub fn reserve_node_ids(&self, count: ast::NodeId) -> ast::NodeId {
let v = self.node_id.get();
match v.checked_add(count) {
Some(next) => { self.node_id.set(next); }
None => panic!("Input too large, ran out of node ids!")
}
v
} }
} }