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') 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 From 3a01d0f1e3ab88a8b891a5cfeb552a78cbf69670 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Wed, 17 Sep 2014 11:58:11 +1200 Subject: rebasing fixes --- src/libsyntax/ast_map/mod.rs | 2 -- src/libsyntax/parse/mod.rs | 2 +- src/libsyntax/show_span.rs | 6 +++--- 3 files changed, 4 insertions(+), 6 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs index 9576cf26f58..ed0b8700bf3 100644 --- a/src/libsyntax/ast_map/mod.rs +++ b/src/libsyntax/ast_map/mod.rs @@ -15,7 +15,6 @@ use ast_util::PostExpansionMethod; use codemap::{DUMMY_SP, Span, Spanned}; use fold::Folder; use parse::token; -use parse::ParseSess; use print::pprust; use visit::{mod, Visitor}; @@ -251,7 +250,6 @@ pub struct Map<'ast> { } impl<'ast> Map<'ast> { -impl Map { fn entry_count(&self) -> uint { self.map.borrow().len() } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 506b607d02c..d73cb211694 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -17,7 +17,7 @@ use parse::attr::ParserAttr; use parse::parser::Parser; use ptr::P; -use std::cell::RefCell; +use std::cell::{Cell, RefCell}; use std::io::File; use std::rc::Rc; use std::str; diff --git a/src/libsyntax/show_span.rs b/src/libsyntax/show_span.rs index 4036ab04aa9..354ba854b10 100644 --- a/src/libsyntax/show_span.rs +++ b/src/libsyntax/show_span.rs @@ -22,10 +22,10 @@ struct ShowSpanVisitor<'a> { span_diagnostic: &'a diagnostic::SpanHandler, } -impl<'a> Visitor<()> for ShowSpanVisitor<'a> { - fn visit_expr(&mut self, e: &ast::Expr, _: ()) { +impl<'a, 'v> Visitor<'v> for ShowSpanVisitor<'a> { + fn visit_expr(&mut self, e: &ast::Expr) { self.span_diagnostic.span_note(e.span, "expression"); - visit::walk_expr(self, e, ()); + visit::walk_expr(self, e); } fn visit_mac(&mut self, macro: &ast::Mac) { -- cgit 1.4.1-3-g733a5