Skip to content

rustc/syntax cleanups #11553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ fn add_local_native_libraries(args: &mut ~[~str], sess: Session) {
fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
dylib: bool, tmpdir: &Path) {
// Converts a library file-stem into a cc -l argument
fn unlib(config: @session::config, stem: &str) -> ~str {
fn unlib(config: @session::Config, stem: &str) -> ~str {
if stem.starts_with("lib") &&
config.os != abi::OsWin32 {
stem.slice(3, stem.len()).to_owned()
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/back/rpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn get_rpath_flags(sess: session::Session, out_filename: &Path) -> ~[~str] {

debug!("preparing the RPATH!");

let sysroot = sess.filesearch.sysroot();
let sysroot = sess.filesearch.sysroot;
let output = out_filename;
let libs = sess.cstore.get_used_crates(cstore::RequireDynamic);
let libs = libs.move_iter().filter_map(|(_, l)| l.map(|p| p.clone())).collect();
Expand All @@ -55,7 +55,7 @@ pub fn get_rpath_flags(sess: session::Session, out_filename: &Path) -> ~[~str] {

fn get_sysroot_absolute_rt_lib(sess: session::Session) -> Path {
let r = filesearch::relative_target_lib_path(sess.opts.target_triple);
let mut p = sess.filesearch.sysroot().join(&r);
let mut p = sess.filesearch.sysroot.join(&r);
p.push(os::dll_filename("rustrt"));
p
}
Expand Down
54 changes: 27 additions & 27 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ pub enum PpMode {
*/
pub fn anon_src() -> @str { @"<anon>" }

pub fn source_name(input: &input) -> @str {
pub fn source_name(input: &Input) -> @str {
match *input {
// FIXME (#9639): This needs to handle non-utf8 paths
file_input(ref ifile) => ifile.as_str().unwrap().to_managed(),
str_input(_) => anon_src()
FileInput(ref ifile) => ifile.as_str().unwrap().to_managed(),
StrInput(_) => anon_src()
}
}

Expand Down Expand Up @@ -133,22 +133,22 @@ fn parse_cfgspecs(cfgspecs: ~[~str], demitter: @diagnostic::Emitter)
}).collect::<ast::CrateConfig>()
}

pub enum input {
pub enum Input {
/// Load source from file
file_input(Path),
FileInput(Path),
/// The string is the source
// FIXME (#2319): Don't really want to box the source string
str_input(@str)
StrInput(@str)
}

pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &input)
pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &Input)
-> ast::Crate {
time(sess.time_passes(), "parsing", (), |_| {
match *input {
file_input(ref file) => {
FileInput(ref file) => {
parse::parse_crate_from_file(&(*file), cfg.clone(), sess.parse_sess)
}
str_input(src) => {
StrInput(src) => {
parse::parse_crate_from_source_str(
anon_src(), src, cfg.clone(), sess.parse_sess)
}
Expand Down Expand Up @@ -444,7 +444,7 @@ pub fn stop_after_phase_5(sess: Session) -> bool {
return false;
}

fn write_out_deps(sess: Session, input: &input, outputs: &OutputFilenames, crate: &ast::Crate)
fn write_out_deps(sess: Session, input: &Input, outputs: &OutputFilenames, crate: &ast::Crate)
{
let lm = link::build_link_meta(sess, crate.attrs, &outputs.obj_filename,
&mut ::util::sha2::Sha256::new());
Expand All @@ -460,12 +460,12 @@ fn write_out_deps(sess: Session, input: &input, outputs: &OutputFilenames, crate
(true, Some(ref filename)) => filename.clone(),
// Use default filename: crate source filename with extension replaced by ".d"
(true, None) => match *input {
file_input(ref input_path) => {
FileInput(ref input_path) => {
let filestem = input_path.filestem().expect("input file must have stem");
let filename = out_filenames[0].dir_path().join(filestem).with_extension("d");
filename
},
str_input(..) => {
StrInput(..) => {
sess.warn("can not write --dep-info without a filename when compiling stdin.");
return;
},
Expand Down Expand Up @@ -495,7 +495,7 @@ fn write_out_deps(sess: Session, input: &input, outputs: &OutputFilenames, crate
}
}

pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &input,
pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
outdir: &Option<Path>, output: &Option<Path>) {
// We need nested scopes here, because the intermediate results can keep
// large chunks of memory alive and we want to free them as soon as
Expand Down Expand Up @@ -587,7 +587,7 @@ impl pprust::PpAnn for TypedAnnotation {

pub fn pretty_print_input(sess: Session,
cfg: ast::CrateConfig,
input: &input,
input: &Input,
ppm: PpMode) {
let crate = phase_1_parse_input(sess, cfg.clone(), input);

Expand Down Expand Up @@ -664,9 +664,9 @@ static architecture_abis : &'static [(&'static str, abi::Architecture)] = &'stat

("mips", abi::Mips)];

pub fn build_target_config(sopts: @session::options,
pub fn build_target_config(sopts: @session::Options,
demitter: @diagnostic::Emitter)
-> @session::config {
-> @session::Config {
let os = match get_os(sopts.target_triple) {
Some(os) => os,
None => early_error(demitter, "unknown operating system")
Expand All @@ -689,7 +689,7 @@ pub fn build_target_config(sopts: @session::options,
abi::Arm => arm::get_target_strs(target_triple, os),
abi::Mips => mips::get_target_strs(target_triple, os)
};
let target_cfg = @session::config {
let target_cfg = @session::Config {
os: os,
arch: arch,
target_strs: target_strs,
Expand All @@ -714,7 +714,7 @@ pub fn host_triple() -> ~str {
pub fn build_session_options(binary: ~str,
matches: &getopts::Matches,
demitter: @diagnostic::Emitter)
-> @session::options {
-> @session::Options {
let mut outputs = ~[];
if matches.opt_present("rlib") {
outputs.push(session::OutputRlib)
Expand Down Expand Up @@ -862,7 +862,7 @@ pub fn build_session_options(binary: ~str,
matches.opt_present("crate-name"),
matches.opt_present("crate-file-name"));

let sopts = @session::options {
let sopts = @session::Options {
outputs: outputs,
gc: gc,
optimize: opt_level,
Expand Down Expand Up @@ -895,7 +895,7 @@ pub fn build_session_options(binary: ~str,
return sopts;
}

pub fn build_session(sopts: @session::options, demitter: @diagnostic::Emitter)
pub fn build_session(sopts: @session::Options, demitter: @diagnostic::Emitter)
-> Session {
let codemap = @codemap::CodeMap::new();
let diagnostic_handler =
Expand All @@ -905,7 +905,7 @@ pub fn build_session(sopts: @session::options, demitter: @diagnostic::Emitter)
build_session_(sopts, codemap, demitter, span_diagnostic_handler)
}

pub fn build_session_(sopts: @session::options,
pub fn build_session_(sopts: @session::Options,
cm: @codemap::CodeMap,
demitter: @diagnostic::Emitter,
span_diagnostic_handler: @diagnostic::SpanHandler)
Expand All @@ -914,7 +914,7 @@ pub fn build_session_(sopts: @session::options,
let p_s = parse::new_parse_sess_special_handler(span_diagnostic_handler,
cm);
let cstore = @CStore::new(token::get_ident_interner());
let filesearch = filesearch::mk_filesearch(
let filesearch = @filesearch::FileSearch::new(
&sopts.maybe_sysroot,
sopts.target_triple,
sopts.addl_lib_search_paths);
Expand Down Expand Up @@ -1046,7 +1046,7 @@ pub struct OutputFilenames {
obj_filename: Path
}

pub fn build_output_filenames(input: &input,
pub fn build_output_filenames(input: &Input,
odir: &Option<Path>,
ofile: &Option<Path>,
attrs: &[ast::Attribute],
Expand Down Expand Up @@ -1074,15 +1074,15 @@ pub fn build_output_filenames(input: &input,
let dirpath = match *odir {
Some(ref d) => (*d).clone(),
None => match *input {
str_input(_) => os::getcwd(),
file_input(ref ifile) => (*ifile).dir_path()
StrInput(_) => os::getcwd(),
FileInput(ref ifile) => (*ifile).dir_path()
}
};

let mut stem = match *input {
// FIXME (#9639): This needs to handle non-utf8 paths
file_input(ref ifile) => (*ifile).filestem_str().unwrap().to_managed(),
str_input(_) => @"rust_out"
FileInput(ref ifile) => (*ifile).filestem_str().unwrap().to_managed(),
StrInput(_) => @"rust_out"
};

// If a crateid is present, we use it as the link name
Expand Down
19 changes: 7 additions & 12 deletions src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use syntax;
use std::cell::{Cell, RefCell};
use std::hashmap::{HashMap,HashSet};

pub struct config {
pub struct Config {
os: abi::Os,
arch: abi::Architecture,
target_strs: target_strs::t,
Expand Down Expand Up @@ -134,7 +134,7 @@ pub enum OptLevel {
}

#[deriving(Clone)]
pub struct options {
pub struct Options {
// The crate config requested for the session, which may be combined
// with additional crate configurations during the compile process
outputs: ~[OutputStyle],
Expand Down Expand Up @@ -176,11 +176,6 @@ pub struct options {
print_metas: (bool, bool, bool),
}

pub struct crate_metadata {
name: ~str,
data: ~[u8]
}

// The type of entry function, so
// users can have their own entry
// functions that don't start a
Expand All @@ -201,8 +196,8 @@ pub enum OutputStyle {
}

pub struct Session_ {
targ_cfg: @config,
opts: @options,
targ_cfg: @Config,
opts: @Options,
cstore: @metadata::cstore::CStore,
parse_sess: @ParseSess,
codemap: @codemap::CodeMap,
Expand Down Expand Up @@ -375,8 +370,8 @@ impl Session_ {
}

/// Some reasonable defaults
pub fn basic_options() -> @options {
@options {
pub fn basic_options() -> @Options {
@Options {
outputs: ~[],
gc: false,
optimize: No,
Expand Down Expand Up @@ -413,7 +408,7 @@ pub fn expect<T:Clone>(sess: Session, opt: Option<T>, msg: || -> ~str) -> T {
diagnostic::expect(sess.diagnostic(), opt, msg)
}

pub fn building_library(options: &options, crate: &ast::Crate) -> bool {
pub fn building_library(options: &Options, crate: &ast::Crate) -> bool {
if options.test { return false }
for output in options.outputs.iter() {
match *output {
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
let ifile = matches.free[0].as_slice();
if "-" == ifile {
let src = str::from_utf8_owned(io::stdin().read_to_end());
d::str_input(src.to_managed())
d::StrInput(src.to_managed())
} else {
d::file_input(Path::new(ifile))
d::FileInput(Path::new(ifile))
}
}
_ => d::early_error(demitter, "multiple input filenames provided")
Expand All @@ -281,12 +281,12 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
let ls = matches.opt_present("ls");
if ls {
match input {
d::file_input(ref ifile) => {
d::FileInput(ref ifile) => {
let mut stdout = io::stdout();
d::list_metadata(sess, &(*ifile),
&mut stdout as &mut io::Writer);
}
d::str_input(_) => {
d::StrInput(_) => {
d::early_error(demitter, "can not list metadata for stdin");
}
}
Expand Down Expand Up @@ -332,12 +332,12 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
}

fn parse_crate_attrs(sess: session::Session,
input: &d::input) -> ~[ast::Attribute] {
input: &d::Input) -> ~[ast::Attribute] {
match *input {
d::file_input(ref ifile) => {
d::FileInput(ref ifile) => {
parse::parse_crate_attrs_from_file(ifile, ~[], sess.parse_sess)
}
d::str_input(src) => {
d::StrInput(src) => {
parse::parse_crate_attrs_from_source_str(
d::anon_src(), src, ~[], sess.parse_sess)
}
Expand Down
Loading