mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
move most of front to libsyntax
This commit is contained in:
parent
b75b0f7923
commit
520671f150
@ -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));
|
||||
|
@ -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(),
|
||||
|
@ -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;
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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.
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
@ -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());
|
Loading…
Reference in New Issue
Block a user