about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNick Cameron <ncameron@mozilla.com>2014-07-25 14:44:24 +1200
committerNick Cameron <ncameron@mozilla.com>2014-09-17 16:53:20 +1200
commit520671f1500885ffc2c5096e9150a665b63c2e0d (patch)
tree5ed7ce68faaa724c8c6655f4edc325aa533239d6
parentb75b0f79235c919b3ab959fb79247d2997bd63e0 (diff)
downloadrust-520671f1500885ffc2c5096e9150a665b63c2e0d.tar.gz
rust-520671f1500885ffc2c5096e9150a665b63c2e0d.zip
move most of front to libsyntax
-rw-r--r--src/librustc/driver/driver.rs11
-rw-r--r--src/librustc/driver/session.rs13
-rw-r--r--src/librustc/lib.rs3
-rw-r--r--src/libsyntax/ast_map/mod.rs2
-rw-r--r--src/libsyntax/config.rs (renamed from src/librustc/front/config.rs)8
-rw-r--r--src/libsyntax/lib.rs3
-rw-r--r--src/libsyntax/parse/mod.rs19
-rw-r--r--src/libsyntax/show_span.rs (renamed from src/librustc/front/show_span.rs)23
-rw-r--r--src/libsyntax/test.rs (renamed from src/librustc/front/test.rs)77
9 files changed, 89 insertions, 70 deletions
diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs
index 2f252fc042a..4d73408cc6e 100644
--- a/src/librustc/driver/driver.rs
+++ b/src/librustc/driver/driver.rs
@@ -166,7 +166,7 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
     }
 
     if sess.show_span() {
-        front::show_span::run(sess, &krate);
+        syntax::show_span::run(sess.diagnostic(), &krate);
     }
 
     krate
@@ -209,7 +209,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
     // baz! should not use this definition unless foo is enabled.
 
     krate = time(time_passes, "configuration 1", krate, |krate|
-                 front::config::strip_unconfigured_items(krate));
+                 syntax::config::strip_unconfigured_items(krate));
 
     let mut addl_plugins = Some(addl_plugins);
     let Plugins { macros, registrars }
@@ -290,10 +290,13 @@ pub fn phase_2_configure_and_expand(sess: &Session,
 
     // strip again, in case expansion added anything with a #[cfg].
     krate = time(time_passes, "configuration 2", krate, |krate|
-                 front::config::strip_unconfigured_items(krate));
+                 syntax::config::strip_unconfigured_items(krate));
 
     krate = time(time_passes, "maybe building test harness", krate, |krate|
-                 front::test::modify_for_testing(sess, krate));
+                 syntax::test::modify_for_testing(&sess.parse_sess,
+                                                  &sess.opts.cfg,
+                                                  krate,
+                                                  sess.diagnostic()));
 
     krate = time(time_passes, "prelude injection", krate, |krate|
                  front::std_inject::maybe_inject_prelude(sess, krate));
diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs
index 6f020184b33..2d28a9294e4 100644
--- a/src/librustc/driver/session.rs
+++ b/src/librustc/driver/session.rs
@@ -47,7 +47,6 @@ pub struct Session {
     pub working_dir: Path,
     pub lint_store: RefCell<lint::LintStore>,
     pub lints: RefCell<NodeMap<Vec<(lint::LintId, codemap::Span, String)>>>,
-    pub node_id: Cell<ast::NodeId>,
     pub crate_types: RefCell<Vec<config::CrateType>>,
     pub crate_metadata: RefCell<Vec<String>>,
     pub features: front::feature_gate::Features,
@@ -129,17 +128,10 @@ impl Session {
         lints.insert(id, vec!((lint_id, sp, msg)));
     }
     pub fn next_node_id(&self) -> ast::NodeId {
-        self.reserve_node_ids(1)
+        self.parse_sess.next_node_id()
     }
     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 => self.bug("Input too large, ran out of node ids!")
-        }
-
-        v
+        self.parse_sess.reserve_node_ids(count)
     }
     pub fn diagnostic<'a>(&'a self) -> &'a diagnostic::SpanHandler {
         &self.parse_sess.span_diagnostic
@@ -251,7 +243,6 @@ pub fn build_session_(sopts: config::Options,
         working_dir: os::getcwd(),
         lint_store: RefCell::new(lint::LintStore::new()),
         lints: RefCell::new(NodeMap::new()),
-        node_id: Cell::new(1),
         crate_types: RefCell::new(Vec::new()),
         crate_metadata: RefCell::new(Vec::new()),
         features: front::feature_gate::Features::new(),
diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs
index af3d19c4d2d..dade485f701 100644
--- a/src/librustc/lib.rs
+++ b/src/librustc/lib.rs
@@ -117,11 +117,8 @@ pub mod middle {
 }
 
 pub mod front {
-    pub mod config;
-    pub mod test;
     pub mod std_inject;
     pub mod feature_gate;
-    pub mod show_span;
 }
 
 pub mod metadata;
diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs
index ed0b8700bf3..9576cf26f58 100644
--- a/src/libsyntax/ast_map/mod.rs
+++ b/src/libsyntax/ast_map/mod.rs
@@ -15,6 +15,7 @@ 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};
 
@@ -250,6 +251,7 @@ pub struct Map<'ast> {
 }
 
 impl<'ast> Map<'ast> {
+impl Map {
     fn entry_count(&self) -> uint {
         self.map.borrow().len()
     }
diff --git a/src/librustc/front/config.rs b/src/libsyntax/config.rs
index 2e05cb054e8..cb96cd911b5 100644
--- a/src/librustc/front/config.rs
+++ b/src/libsyntax/config.rs
@@ -8,10 +8,10 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use syntax::fold::Folder;
-use syntax::{ast, fold, attr};
-use syntax::codemap::Spanned;
-use syntax::ptr::P;
+use fold::Folder;
+use {ast, fold, attr};
+use codemap::Spanned;
+use ptr::P;
 
 /// A folder that strips out items that do not belong in the current
 /// configuration.
diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs
index 146b5a5b348..ff481dd7299 100644
--- a/src/libsyntax/lib.rs
+++ b/src/libsyntax/lib.rs
@@ -59,12 +59,15 @@ pub mod ast_map;
 pub mod ast_util;
 pub mod attr;
 pub mod codemap;
+pub mod config;
 pub mod crateid;
 pub mod diagnostic;
 pub mod fold;
 pub mod owned_slice;
 pub mod parse;
 pub mod ptr;
+pub mod show_span;
+pub mod test;
 pub mod visit;
 
 pub mod print {
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<Vec<Path>>,
+    pub node_id: Cell<ast::NodeId>,
 }
 
 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
     }
 }
 
diff --git a/src/librustc/front/show_span.rs b/src/libsyntax/show_span.rs
index df0b02261b1..4036ab04aa9 100644
--- a/src/librustc/front/show_span.rs
+++ b/src/libsyntax/show_span.rs
@@ -13,20 +13,19 @@
 //! This module shows spans for all expressions in the crate
 //! to help with compiler debugging.
 
-use syntax::ast;
-use syntax::visit;
-use syntax::visit::Visitor;
-
-use driver::session::Session;
+use ast;
+use diagnostic;
+use visit;
+use visit::Visitor;
 
 struct ShowSpanVisitor<'a> {
-    sess: &'a Session
+    span_diagnostic: &'a diagnostic::SpanHandler,
 }
 
-impl<'a, 'v> Visitor<'v> for ShowSpanVisitor<'a> {
-    fn visit_expr(&mut self, e: &ast::Expr) {
-        self.sess.span_note(e.span, "expression");
-        visit::walk_expr(self, e);
+impl<'a> Visitor<()> for ShowSpanVisitor<'a> {
+    fn visit_expr(&mut self, e: &ast::Expr, _: ()) {
+        self.span_diagnostic.span_note(e.span, "expression");
+        visit::walk_expr(self, e, ());
     }
 
     fn visit_mac(&mut self, macro: &ast::Mac) {
@@ -34,7 +33,7 @@ impl<'a, 'v> Visitor<'v> for ShowSpanVisitor<'a> {
     }
 }
 
-pub fn run(sess: &Session, krate: &ast::Crate) {
-    let mut v = ShowSpanVisitor { sess: sess };
+pub fn run(span_diagnostic: &diagnostic::SpanHandler, krate: &ast::Crate) {
+    let mut v = ShowSpanVisitor { span_diagnostic: span_diagnostic };
     visit::walk_crate(&mut v, krate);
 }
diff --git a/src/librustc/front/test.rs b/src/libsyntax/test.rs
index 737fe748340..f0e69712714 100644
--- a/src/librustc/front/test.rs
+++ b/src/libsyntax/test.rs
@@ -13,29 +13,29 @@
 #![allow(dead_code)]
 #![allow(unused_imports)]
 
-use driver::session::Session;
-use front::config;
-
+use std::gc::{Gc, GC};
 use std::slice;
 use std::mem;
 use std::vec;
-use syntax::{ast, ast_util};
-use syntax::ast_util::*;
-use syntax::attr::AttrMetaMethods;
-use syntax::attr;
-use syntax::codemap::{DUMMY_SP, Span, ExpnInfo, NameAndSpan, MacroAttribute};
-use syntax::codemap;
-use syntax::ext::base::ExtCtxt;
-use syntax::ext::build::AstBuilder;
-use syntax::ext::expand::ExpansionConfig;
-use syntax::fold::{Folder, MoveMap};
-use syntax::fold;
-use syntax::owned_slice::OwnedSlice;
-use syntax::parse::token::InternedString;
-use syntax::parse::token;
-use syntax::print::pprust;
-use syntax::ptr::P;
-use syntax::util::small_vector::SmallVector;
+use ast_util::*;
+use attr::AttrMetaMethods;
+use attr;
+use codemap::{DUMMY_SP, Span, ExpnInfo, NameAndSpan, MacroAttribute};
+use codemap;
+use diagnostic;
+use config;
+use ext::base::ExtCtxt;
+use ext::build::AstBuilder;
+use ext::expand::ExpansionConfig;
+use fold::{Folder, MoveMap};
+use fold;
+use owned_slice::OwnedSlice;
+use parse::token::InternedString;
+use parse::{token, ParseSess};
+use print::pprust;
+use {ast, ast_util};
+use ptr::P;
+use util::small_vector::SmallVector;
 
 struct Test {
     span: Span,
@@ -46,7 +46,8 @@ struct Test {
 }
 
 struct TestCtxt<'a> {
-    sess: &'a Session,
+    sess: &'a ParseSess,
+    span_diagnostic: &'a diagnostic::SpanHandler,
     path: Vec<ast::Ident>,
     ext_cx: ExtCtxt<'a>,
     testfns: Vec<Test>,
@@ -60,8 +61,10 @@ struct TestCtxt<'a> {
 
 // Traverse the crate, collecting all the test functions, eliding any
 // existing main functions, and synthesizing a main test harness
-pub fn modify_for_testing(sess: &Session,
-                          krate: ast::Crate) -> ast::Crate {
+pub fn modify_for_testing(sess: &ParseSess,
+                          cfg: &ast::CrateConfig,
+                          krate: ast::Crate,
+                          span_diagnostic: &diagnostic::SpanHandler) -> ast::Crate {
     // We generate the test harness when building in the 'test'
     // configuration, either with the '--test' or '--cfg test'
     // command line options.
@@ -76,7 +79,7 @@ pub fn modify_for_testing(sess: &Session,
                                            "reexport_test_harness_main");
 
     if should_test {
-        generate_test_harness(sess, reexport_test_harness_main, krate)
+        generate_test_harness(sess, reexport_test_harness_main, krate, cfg, span_diagnostic)
     } else {
         strip_test_functions(krate)
     }
@@ -113,8 +116,8 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
         if is_test_fn(&self.cx, &*i) || is_bench_fn(&self.cx, &*i) {
             match i.node {
                 ast::ItemFn(_, ast::UnsafeFn, _, _, _) => {
-                    let sess = self.cx.sess;
-                    sess.span_fatal(i.span,
+                    let diag = self.cx.span_diagnostic;
+                    diag.span_fatal(i.span,
                                     "unsafe functions cannot be used for \
                                      tests");
                 }
@@ -223,12 +226,15 @@ fn mk_reexport_mod(cx: &mut TestCtxt, tests: Vec<ast::Ident>,
     (it, sym)
 }
 
-fn generate_test_harness(sess: &Session,
+fn generate_test_harness(sess: &ParseSess,
                          reexport_test_harness_main: Option<InternedString>,
-                         krate: ast::Crate) -> ast::Crate {
+                         krate: ast::Crate,
+                         cfg: &ast::CrateConfig,
+                         sd: &diagnostic::SpanHandler) -> ast::Crate {
     let mut cx: TestCtxt = TestCtxt {
         sess: sess,
-        ext_cx: ExtCtxt::new(&sess.parse_sess, sess.opts.cfg.clone(),
+        span_diagnostic: sd,
+        ext_cx: ExtCtxt::new(sess, cfg.clone(),
                              ExpansionConfig {
                                  deriving_hash_type_parameter: false,
                                  crate_name: "test".to_string(),
@@ -288,8 +294,8 @@ fn is_test_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
     }
 
     if has_test_attr && !has_test_signature(i) {
-        let sess = cx.sess;
-        sess.span_err(
+        let diag = cx.span_diagnostic;
+        diag.span_err(
             i.span,
             "functions used as tests must have signature fn() -> ()."
         );
@@ -320,8 +326,8 @@ fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
     }
 
     if has_bench_attr && !has_test_signature(i) {
-        let sess = cx.sess;
-        sess.span_err(i.span, "functions used as benches must have signature \
+        let diag = cx.span_diagnostic;
+        diag.span_err(i.span, "functions used as benches must have signature \
                       `fn(&mut Bencher) -> ()`");
     }
 
@@ -547,9 +553,8 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P<ast::Expr> {
     let mut visible_path = match cx.toplevel_reexport {
         Some(id) => vec![id],
         None => {
-            cx.sess.bug(
-                "expected to find top-level re-export name, but found None"
-            );
+            let diag = cx.span_diagnostic;
+            diag.handler.bug("expected to find top-level re-export name, but found None");
         }
     };
     visible_path.extend(path.into_iter());