From 520671f1500885ffc2c5096e9150a665b63c2e0d Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Fri, 25 Jul 2014 14:44:24 +1200 Subject: move most of front to libsyntax --- src/libsyntax/parse/mod.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/libsyntax/parse/mod.rs') diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index e5b6359000b..506b607d02c 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -37,12 +37,14 @@ pub struct ParseSess { pub span_diagnostic: SpanHandler, // better be the same as the one in the reader! /// Used to determine and report recursive mod inclusions included_mod_stack: RefCell>, + pub node_id: Cell, } pub fn new_parse_sess() -> ParseSess { ParseSess { span_diagnostic: mk_span_handler(default_handler(Auto, None), CodeMap::new()), included_mod_stack: RefCell::new(Vec::new()), + node_id: Cell::new(1), } } @@ -50,6 +52,23 @@ pub fn new_parse_sess_special_handler(sh: SpanHandler) -> ParseSess { ParseSess { span_diagnostic: sh, 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 => fail!("Input too large, ran out of node ids!") + } + + v } } -- cgit 1.4.1-3-g733a5