Fix rustdoc and tests.
This commit is contained in:
parent
e02aa722aa
commit
e2ebc8f811
13 changed files with 71 additions and 103 deletions
|
|
@ -684,7 +684,7 @@ impl Clean<Type> for ast::Ty {
|
|||
fn clean(&self) -> Type {
|
||||
use syntax::ast::*;
|
||||
debug!("cleaning type `{:?}`", self);
|
||||
let codemap = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess().codemap;
|
||||
let codemap = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess().codemap();
|
||||
debug!("span corresponds to `{}`", codemap.span_to_str(self.span));
|
||||
match self.node {
|
||||
TyNil => Unit,
|
||||
|
|
@ -866,7 +866,7 @@ pub struct Span {
|
|||
|
||||
impl Clean<Span> for syntax::codemap::Span {
|
||||
fn clean(&self) -> Span {
|
||||
let cm = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess().codemap;
|
||||
let cm = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess().codemap();
|
||||
let filename = cm.span_to_filename(*self);
|
||||
let lo = cm.lookup_char_pos(self.lo);
|
||||
let hi = cm.lookup_char_pos(self.hi);
|
||||
|
|
@ -1180,7 +1180,7 @@ trait ToSource {
|
|||
impl ToSource for syntax::codemap::Span {
|
||||
fn to_src(&self) -> ~str {
|
||||
debug!("converting span {:?} to snippet", self.clean());
|
||||
let cm = local_data::get(super::ctxtkey, |x| x.unwrap().clone()).sess().codemap.clone();
|
||||
let cm = local_data::get(super::ctxtkey, |x| x.unwrap().clone()).sess().codemap().clone();
|
||||
let sn = match cm.span_to_snippet(*self) {
|
||||
Some(x) => x,
|
||||
None => ~""
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ use rustc::middle::privacy;
|
|||
|
||||
use syntax::ast;
|
||||
use syntax::parse::token;
|
||||
use syntax::parse;
|
||||
use syntax;
|
||||
|
||||
use std::cell::RefCell;
|
||||
|
|
@ -60,24 +59,23 @@ fn get_ast_and_resolve(cpath: &Path,
|
|||
phase_2_configure_and_expand,
|
||||
phase_3_run_analysis_passes};
|
||||
|
||||
let parsesess = parse::new_parse_sess();
|
||||
let input = FileInput(cpath.clone());
|
||||
|
||||
let sessopts = @driver::session::Options {
|
||||
let sessopts = driver::session::Options {
|
||||
maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
|
||||
addl_lib_search_paths: RefCell::new(libs),
|
||||
crate_types: vec!(driver::session::CrateTypeDylib),
|
||||
.. (*rustc::driver::session::basic_options()).clone()
|
||||
..rustc::driver::session::basic_options().clone()
|
||||
};
|
||||
|
||||
|
||||
let codemap = syntax::codemap::CodeMap::new();
|
||||
let diagnostic_handler = syntax::diagnostic::default_handler();
|
||||
let span_diagnostic_handler =
|
||||
syntax::diagnostic::mk_span_handler(diagnostic_handler, parsesess.cm);
|
||||
syntax::diagnostic::mk_span_handler(diagnostic_handler, codemap);
|
||||
|
||||
let sess = driver::driver::build_session_(sessopts,
|
||||
Some(cpath.clone()),
|
||||
parsesess.cm,
|
||||
span_diagnostic_handler);
|
||||
|
||||
let mut cfg = build_configuration(&sess);
|
||||
|
|
@ -87,7 +85,7 @@ fn get_ast_and_resolve(cpath: &Path,
|
|||
}
|
||||
|
||||
let krate = phase_1_parse_input(&sess, cfg, &input);
|
||||
let (krate, ast_map) = phase_2_configure_and_expand(&sess, &mut Loader::new(sess),
|
||||
let (krate, ast_map) = phase_2_configure_and_expand(&sess, &mut Loader::new(&sess),
|
||||
krate, &from_str("rustdoc").unwrap());
|
||||
let driver::driver::CrateAnalysis {
|
||||
exported_items, public_items, ty_cx, ..
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ use std::io;
|
|||
|
||||
use syntax::parse;
|
||||
use syntax::parse::lexer;
|
||||
use syntax::diagnostic;
|
||||
use syntax::codemap::{BytePos, Span};
|
||||
|
||||
use html::escape::Escape;
|
||||
|
|
@ -28,13 +27,11 @@ use t = syntax::parse::token;
|
|||
/// Highlights some source code, returning the HTML output.
|
||||
pub fn highlight(src: &str, class: Option<&str>) -> ~str {
|
||||
let sess = parse::new_parse_sess();
|
||||
let handler = diagnostic::default_handler();
|
||||
let span_handler = diagnostic::mk_span_handler(handler, sess.cm);
|
||||
let fm = parse::string_to_filemap(&sess, src.to_owned(), ~"<stdin>");
|
||||
|
||||
let mut out = io::MemWriter::new();
|
||||
doit(&sess,
|
||||
lexer::new_string_reader(span_handler, fm),
|
||||
lexer::new_string_reader(&sess.span_diagnostic, fm),
|
||||
class,
|
||||
&mut out).unwrap();
|
||||
str::from_utf8_lossy(out.unwrap()).into_owned()
|
||||
|
|
@ -68,7 +65,7 @@ fn doit(sess: &parse::ParseSess, lexer: lexer::StringReader, class: Option<&str>
|
|||
// comment. This will classify some whitespace as a comment, but that
|
||||
// doesn't matter too much for syntax highlighting purposes.
|
||||
if test > last {
|
||||
let snip = sess.cm.span_to_snippet(Span {
|
||||
let snip = sess.span_diagnostic.cm.span_to_snippet(Span {
|
||||
lo: last,
|
||||
hi: test,
|
||||
expn_info: None,
|
||||
|
|
@ -172,7 +169,7 @@ fn doit(sess: &parse::ParseSess, lexer: lexer::StringReader, class: Option<&str>
|
|||
|
||||
// as mentioned above, use the original source code instead of
|
||||
// stringifying this token
|
||||
let snip = sess.cm.span_to_snippet(next.sp).unwrap();
|
||||
let snip = sess.span_diagnostic.cm.span_to_snippet(next.sp).unwrap();
|
||||
if klass == "" {
|
||||
try!(write!(out, "{}", Escape(snip)));
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ extern crate time;
|
|||
#[phase(syntax, link)]
|
||||
extern crate log;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::local_data;
|
||||
use std::io;
|
||||
use std::io::{File, MemWriter};
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::{str, io};
|
||||
use std::cell::RefCell;
|
||||
use std::vec_ng::Vec;
|
||||
|
||||
use collections::HashSet;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ use rustc::driver::driver;
|
|||
use rustc::driver::session;
|
||||
use rustc::metadata::creader::Loader;
|
||||
use syntax::diagnostic;
|
||||
use syntax::parse;
|
||||
use syntax::codemap::CodeMap;
|
||||
|
||||
use core;
|
||||
|
|
@ -38,29 +37,26 @@ pub fn run(input: &str, libs: HashSet<Path>, mut test_args: ~[~str]) -> int {
|
|||
let input_path = Path::new(input);
|
||||
let input = driver::FileInput(input_path.clone());
|
||||
|
||||
let sessopts = @session::Options {
|
||||
let sessopts = session::Options {
|
||||
maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
|
||||
addl_lib_search_paths: RefCell::new(libs.clone()),
|
||||
crate_types: vec!(session::CrateTypeDylib),
|
||||
.. (*session::basic_options()).clone()
|
||||
..session::basic_options().clone()
|
||||
};
|
||||
|
||||
|
||||
let cm = @CodeMap::new();
|
||||
let codemap = CodeMap::new();
|
||||
let diagnostic_handler = diagnostic::default_handler();
|
||||
let span_diagnostic_handler =
|
||||
diagnostic::mk_span_handler(diagnostic_handler, cm);
|
||||
let parsesess = parse::new_parse_sess_special_handler(span_diagnostic_handler,
|
||||
cm);
|
||||
diagnostic::mk_span_handler(diagnostic_handler, codemap);
|
||||
|
||||
let sess = driver::build_session_(sessopts,
|
||||
Some(input_path),
|
||||
parsesess.cm,
|
||||
span_diagnostic_handler);
|
||||
|
||||
let cfg = driver::build_configuration(&sess);
|
||||
let krate = driver::phase_1_parse_input(&sess, cfg, &input);
|
||||
let (krate, _) = driver::phase_2_configure_and_expand(sess, &mut Loader::new(sess), krate,
|
||||
let (krate, _) = driver::phase_2_configure_and_expand(&sess, &mut Loader::new(&sess), krate,
|
||||
&from_str("rustdoc-test").unwrap());
|
||||
|
||||
let ctx = @core::DocContext {
|
||||
|
|
@ -88,10 +84,9 @@ pub fn run(input: &str, libs: HashSet<Path>, mut test_args: ~[~str]) -> int {
|
|||
fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
|
||||
no_run: bool, loose_feature_gating: bool) {
|
||||
let test = maketest(test, cratename, loose_feature_gating);
|
||||
let parsesess = parse::new_parse_sess();
|
||||
let input = driver::StrInput(test);
|
||||
|
||||
let sessopts = @session::Options {
|
||||
let sessopts = session::Options {
|
||||
maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
|
||||
addl_lib_search_paths: RefCell::new(libs),
|
||||
crate_types: vec!(session::CrateTypeExecutable),
|
||||
|
|
@ -100,7 +95,7 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
|
|||
prefer_dynamic: true,
|
||||
.. session::basic_codegen_options()
|
||||
},
|
||||
.. (*session::basic_options()).clone()
|
||||
..session::basic_options().clone()
|
||||
};
|
||||
|
||||
// Shuffle around a few input and output handles here. We're going to pass
|
||||
|
|
@ -126,13 +121,13 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
|
|||
let emitter = diagnostic::EmitterWriter::new(~w2);
|
||||
|
||||
// Compile the code
|
||||
let codemap = CodeMap::new();
|
||||
let diagnostic_handler = diagnostic::mk_handler(~emitter);
|
||||
let span_diagnostic_handler =
|
||||
diagnostic::mk_span_handler(diagnostic_handler, parsesess.cm);
|
||||
diagnostic::mk_span_handler(diagnostic_handler, codemap);
|
||||
|
||||
let sess = driver::build_session_(sessopts,
|
||||
None,
|
||||
parsesess.cm,
|
||||
span_diagnostic_handler);
|
||||
|
||||
let outdir = TempDir::new("rustdoctest").expect("rustdoc needs a tempdir");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue