提交 efb9df1e 编写于 作者: M Marijn Haverbeke

Make driver::session::session no longer an object

Rather, it is now a struct where properties like opts are accessed
directly, and the error-reporting methods are part of a static impl
(with the same name as the type).
上级 56fe4c26
import driver::session;
import session::session;
import lib::llvm::llvm;
import front::attr;
import middle::ty;
......@@ -30,16 +31,16 @@
output_type_exe;
}
fn llvm_err(sess: session::session, msg: str) unsafe {
fn llvm_err(sess: session, msg: str) unsafe {
let buf = llvm::LLVMRustGetLastError();
if buf == ptr::null() {
sess.fatal(msg);
} else { sess.fatal(msg + ": " + str::from_cstr(buf)); }
}
fn load_intrinsics_bc(sess: session::session) -> option::t<ModuleRef> {
fn load_intrinsics_bc(sess: session) -> option::t<ModuleRef> {
let path = alt filesearch::search(
sess.filesearch(),
sess.filesearch,
bind filesearch::pick_file("intrinsics.bc", _)) {
option::some(path) { path }
option::none. {
......@@ -64,9 +65,9 @@ fn load_intrinsics_bc(sess: session::session) -> option::t<ModuleRef> {
ret option::some(llintrinsicsmod);
}
fn load_intrinsics_ll(sess: session::session) -> ModuleRef {
fn load_intrinsics_ll(sess: session) -> ModuleRef {
let path = alt filesearch::search(
sess.filesearch(),
sess.filesearch,
bind filesearch::pick_file("intrinsics.ll", _)) {
option::some(path) { path }
option::none. { sess.fatal("couldn't find intrinsics.ll") }
......@@ -81,7 +82,7 @@ fn load_intrinsics_ll(sess: session::session) -> ModuleRef {
ret llintrinsicsmod;
}
fn link_intrinsics(sess: session::session, llmod: ModuleRef) {
fn link_intrinsics(sess: session, llmod: ModuleRef) {
let llintrinsicsmod = {
alt load_intrinsics_bc(sess) {
option::some(m) { m }
......@@ -122,13 +123,13 @@ fn mk_intermediate_name(output_path: str, extension: str) -> str {
} else { stem = str::substr(output_path, 0u, dot_pos as uint); }
ret stem + "." + extension;
}
fn run_passes(sess: session::session, llmod: ModuleRef, output: str) {
let opts = sess.get_opts();
fn run_passes(sess: session, llmod: ModuleRef, output: str) {
let opts = sess.opts;
if opts.time_llvm_passes { llvm::LLVMRustEnableTimePasses(); }
link_intrinsics(sess, llmod);
let pm = mk_pass_manager();
let td = mk_target_data(
sess.get_targ_cfg().target_strs.data_layout);
sess.targ_cfg.target_strs.data_layout);
llvm::LLVMAddTargetData(td.lltd, pm.llpm);
// TODO: run the linter here also, once there are llvm-c bindings for
// it.
......@@ -234,7 +235,7 @@ fn run_passes(sess: session::session, llmod: ModuleRef, output: str) {
if opts.output_type == output_type_assembly {
let _: () = str::as_buf(
sess.get_targ_cfg().target_strs.target_triple,
sess.targ_cfg.target_strs.target_triple,
{|buf_t|
str::as_buf(output, {|buf_o|
llvm::LLVMRustWriteOutputFile(
......@@ -254,7 +255,7 @@ fn run_passes(sess: session::session, llmod: ModuleRef, output: str) {
opts.output_type == output_type_exe {
let _: () =
str::as_buf(
sess.get_targ_cfg().target_strs.target_triple,
sess.targ_cfg.target_strs.target_triple,
{|buf_t|
str::as_buf(output, {|buf_o|
llvm::LLVMRustWriteOutputFile(
......@@ -272,7 +273,7 @@ fn run_passes(sess: session::session, llmod: ModuleRef, output: str) {
let _: () =
str::as_buf(
sess.get_targ_cfg().target_strs.target_triple,
sess.targ_cfg.target_strs.target_triple,
{|buf_t|
str::as_buf(output, {|buf_o|
llvm::LLVMRustWriteOutputFile(
......@@ -362,7 +363,7 @@ fn run_passes(sess: session::session, llmod: ModuleRef, output: str) {
type link_meta = {name: str, vers: str, extras_hash: str};
fn build_link_meta(sess: session::session, c: ast::crate, output: str,
fn build_link_meta(sess: session, c: ast::crate, output: str,
sha: sha1) -> link_meta {
type provided_metas =
......@@ -370,7 +371,7 @@ fn build_link_meta(sess: session::session, c: ast::crate, output: str,
vers: option::t<str>,
cmh_items: [@ast::meta_item]};
fn provided_link_metas(sess: session::session, c: ast::crate) ->
fn provided_link_metas(sess: session, c: ast::crate) ->
provided_metas {
let name: option::t<str> = none;
let vers: option::t<str> = none;
......@@ -430,13 +431,13 @@ fn len_and_str_lit(l: ast::lit) -> str {
ret truncated_sha1_result(sha);
}
fn warn_missing(sess: session::session, name: str, default: str) {
if !sess.building_library() { ret; }
fn warn_missing(sess: session, name: str, default: str) {
if !sess.building_library { ret; }
sess.warn(#fmt["missing crate link meta '%s', using '%s' as default",
name, default]);
}
fn crate_meta_name(sess: session::session, _crate: ast::crate,
fn crate_meta_name(sess: session, _crate: ast::crate,
output: str, metas: provided_metas) -> str {
ret alt metas.name {
some(v) { v }
......@@ -454,7 +455,7 @@ fn crate_meta_name(sess: session::session, _crate: ast::crate,
};
}
fn crate_meta_vers(sess: session::session, _crate: ast::crate,
fn crate_meta_vers(sess: session, _crate: ast::crate,
metas: provided_metas) -> str {
ret alt metas.vers {
some(v) { v }
......@@ -469,7 +470,7 @@ fn crate_meta_vers(sess: session::session, _crate: ast::crate,
let provided_metas = provided_link_metas(sess, c);
let name = crate_meta_name(sess, c, output, provided_metas);
let vers = crate_meta_vers(sess, c, provided_metas);
let dep_hashes = cstore::get_dep_hashes(sess.get_cstore());
let dep_hashes = cstore::get_dep_hashes(sess.cstore);
let extras_hash =
crate_meta_extras_hash(sha, c, provided_metas, dep_hashes);
......@@ -557,7 +558,7 @@ fn mangle_internal_name_by_seq(ccx: @crate_ctxt, flav: str) -> str {
// If the user wants an exe generated we need to invoke
// gcc to link the object file with some libs
fn link_binary(sess: session::session,
fn link_binary(sess: session,
obj_filename: str,
out_filename: str,
lm: link_meta) {
......@@ -586,7 +587,7 @@ fn rmext(filename: str) -> str {
};
}
let output = if sess.building_library() {
let output = if sess.building_library {
let long_libname =
std::os::dylib_filename(#fmt("%s-%s-%s",
lm.name, lm.extras_hash, lm.vers));
......@@ -602,22 +603,22 @@ fn rmext(filename: str) -> str {
// The default library location, we need this to find the runtime.
// The location of crates will be determined as needed.
let stage: str = "-L" + sess.filesearch().get_target_lib_path();
let stage: str = "-L" + sess.filesearch.get_target_lib_path();
let prog: str = "gcc";
// The invocations of gcc share some flags across platforms
let gcc_args =
[stage] + sess.get_targ_cfg().target_strs.gcc_args +
[stage] + sess.targ_cfg.target_strs.gcc_args +
["-o", output, obj_filename];
let lib_cmd;
let os = sess.get_targ_cfg().os;
let os = sess.targ_cfg.os;
if os == session::os_macos {
lib_cmd = "-dynamiclib";
} else { lib_cmd = "-shared"; }
let cstore = sess.get_cstore();
let cstore = sess.cstore;
for cratepath: str in cstore::get_used_crate_files(cstore) {
if str::ends_with(cratepath, ".rlib") {
gcc_args += [cratepath];
......@@ -626,7 +627,7 @@ fn rmext(filename: str) -> str {
let cratepath = cratepath;
let dir = fs::dirname(cratepath);
if dir != "" { gcc_args += ["-L" + dir]; }
let libarg = unlib(sess.get_targ_cfg(), fs::basename(cratepath));
let libarg = unlib(sess.targ_cfg, fs::basename(cratepath));
gcc_args += ["-l" + libarg];
}
......@@ -636,12 +637,12 @@ fn rmext(filename: str) -> str {
let used_libs = cstore::get_used_libraries(cstore);
for l: str in used_libs { gcc_args += ["-l" + l]; }
if sess.building_library() {
if sess.building_library {
gcc_args += [lib_cmd];
// On mac we need to tell the linker to let this library
// be rpathed
if sess.get_targ_cfg().os == session::os_macos {
if sess.targ_cfg.os == session::os_macos {
gcc_args += ["-Wl,-install_name,@rpath/"
+ fs::basename(output)];
}
......@@ -655,11 +656,11 @@ fn rmext(filename: str) -> str {
// On linux librt and libdl are an indirect dependencies via rustrt,
// and binutils 2.22+ won't add them automatically
if sess.get_targ_cfg().os == session::os_linux {
if sess.targ_cfg.os == session::os_linux {
gcc_args += ["-lrt", "-ldl"];
}
if sess.get_targ_cfg().os == session::os_freebsd {
if sess.targ_cfg.os == session::os_freebsd {
gcc_args += ["-lrt", "-L/usr/local/lib", "-lexecinfo",
"-L/usr/local/lib/gcc46",
"-L/usr/local/lib/gcc44", "-lstdc++",
......@@ -672,7 +673,7 @@ fn rmext(filename: str) -> str {
// linker from the dwarf unwind info. Unfortunately, it does not seem to
// understand how to unwind our __morestack frame, so we have to turn it
// off. This has impacted some other projects like GHC.
if sess.get_targ_cfg().os == session::os_macos {
if sess.targ_cfg.os == session::os_macos {
gcc_args += ["-Wl,-no_compact_unwind"];
}
......@@ -692,12 +693,12 @@ fn rmext(filename: str) -> str {
}
// Clean up on Darwin
if sess.get_targ_cfg().os == session::os_macos {
if sess.targ_cfg.os == session::os_macos {
run::run_program("dsymutil", [output]);
}
// Remove the temporary object file if we aren't saving temps
if !sess.get_opts().save_temps {
if !sess.opts.save_temps {
run::run_program("rm", [obj_filename]);
}
}
......
......@@ -12,7 +12,7 @@
export get_rpath_flags;
fn get_rpath_flags(sess: session::session, out_filename: str) -> [str] {
let os = sess.get_targ_cfg().os;
let os = sess.targ_cfg.os;
// No rpath on windows
if os == session::os_win32 {
......@@ -22,22 +22,22 @@ fn get_rpath_flags(sess: session::session, out_filename: str) -> [str] {
#debug("preparing the RPATH!");
let cwd = os::getcwd();
let sysroot = sess.filesearch().sysroot();
let sysroot = sess.filesearch.sysroot();
let output = out_filename;
let libs = cstore::get_used_crate_files(sess.get_cstore());
let libs = cstore::get_used_crate_files(sess.cstore);
// We don't currently rpath native libraries, but we know
// where rustrt is and we know every rust program needs it
let libs = libs + [get_sysroot_absolute_rt_lib(sess)];
let target_triple = sess.get_opts().target_triple;
let target_triple = sess.opts.target_triple;
let rpaths = get_rpaths(os, cwd, sysroot, output, libs, target_triple);
rpaths_to_flags(rpaths)
}
fn get_sysroot_absolute_rt_lib(sess: session::session) -> fs::path {
let path = [sess.filesearch().sysroot()]
let path = [sess.filesearch.sysroot()]
+ filesearch::relative_target_lib_path(
sess.get_opts().target_triple)
sess.opts.target_triple)
+ [os::dylib_filename("rustrt")];
check vec::is_not_empty(path);
fs::connect_many(path)
......
// -*- rust -*-
import metadata::{creader, cstore};
import session::session;
import syntax::parse::{parser};
import syntax::{ast, codemap};
import front::attr;
......@@ -22,7 +23,7 @@
fn default_configuration(sess: session::session, argv0: str, input: str) ->
ast::crate_cfg {
let libc =
alt sess.get_targ_cfg().os {
alt sess.targ_cfg.os {
session::os_win32. { "msvcrt.dll" }
session::os_macos. { "libc.dylib" }
session::os_linux. { "libc.so.6" }
......@@ -32,7 +33,7 @@ fn default_configuration(sess: session::session, argv0: str, input: str) ->
let mk = attr::mk_name_value_item_str;
let arch = alt sess.get_targ_cfg().arch {
let arch = alt sess.targ_cfg.arch {
session::arch_x86. { "x86" }
session::arch_x86_64. { "x86_64" }
session::arch_arm. { "arm" }
......@@ -52,11 +53,11 @@ fn build_configuration(sess: session::session, argv0: str, input: str) ->
// Combine the configuration requested by the session (command line) with
// some default and generated configuration items
let default_cfg = default_configuration(sess, argv0, input);
let user_cfg = sess.get_opts().cfg;
let user_cfg = sess.opts.cfg;
// If the user wants a test runner, then add the test cfg
let gen_cfg =
{
if sess.get_opts().test && !attr::contains_name(user_cfg, "test")
if sess.opts.test && !attr::contains_name(user_cfg, "test")
{
[attr::mk_word_item("test")]
} else { [] }
......@@ -78,7 +79,7 @@ fn input_is_stdin(filename: str) -> bool { filename == "-" }
fn parse_input(sess: session::session, cfg: ast::crate_cfg, input: str) ->
@ast::crate {
if !input_is_stdin(input) {
parser::parse_crate_from_file(input, cfg, sess.get_parse_sess())
parser::parse_crate_from_file(input, cfg, sess.parse_sess)
} else { parse_input_src(sess, cfg, input).crate }
}
......@@ -98,7 +99,7 @@ fn parse_input_src(sess: session::session, cfg: ast::crate_cfg, infile: str)
let src = str::unsafe_from_bytes(srcbytes);
let crate =
parser::parse_crate_from_source_str(infile, src, cfg,
sess.get_parse_sess());
sess.parse_sess);
ret {crate: crate, src: src};
}
......@@ -137,12 +138,13 @@ fn spanned<T: copy>(x: T) -> @ast::spanned<T> {
fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
outdir: option::t<str>, output: option::t<str>) {
let time_passes = sess.get_opts().time_passes;
let time_passes = sess.opts.time_passes;
let crate =
time(time_passes, "parsing", bind parse_input(sess, cfg, input));
if sess.get_opts().parse_only { ret; }
if sess.opts.parse_only { ret; }
sess.set_building_library(crate);
sess.building_library =
session::building_library(sess.opts.crate_type, crate);
crate =
time(time_passes, "configuration",
......@@ -154,7 +156,7 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
time(time_passes, "expansion",
bind syntax::ext::expand::expand_crate(sess, crate));
if sess.get_opts().libcore {
if sess.opts.libcore {
crate = inject_libcore_reference(sess, crate);
}
......@@ -193,7 +195,7 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
bind last_use::find_last_uses(crate, def_map, ref_map, ty_cx));
time(time_passes, "kind checking",
bind kind::check_crate(ty_cx, method_map, last_uses, crate));
if sess.get_opts().no_trans { ret; }
if sess.opts.no_trans { ret; }
let outputs = build_output_filenames(input, outdir, output, sess);
......@@ -207,8 +209,8 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
bind link::write::run_passes(sess, llmod, outputs.obj_filename));
let stop_after_codegen =
sess.get_opts().output_type != link::output_type_exe ||
sess.get_opts().static && sess.building_library();
sess.opts.output_type != link::output_type_exe ||
sess.opts.static && sess.building_library;
if stop_after_codegen { ret; }
......@@ -283,7 +285,7 @@ fn ann_identified_post(node: pprust::ann_node) {
}
ppm_normal. { ann = pprust::no_ann(); }
}
pprust::print_crate(sess.get_codemap(), crate, input,
pprust::print_crate(sess.codemap, crate, input,
io::string_reader(src), io::stdout(), ann);
}
......@@ -449,9 +451,18 @@ fn build_session(sopts: @session::options, input: str) -> session::session {
sopts.maybe_sysroot,
sopts.target_triple,
sopts.addl_lib_search_paths);
ret session::session(target_cfg, sopts, cstore,
@{cm: codemap::new_codemap(), mutable next_id: 1},
none, 0u, filesearch, false, fs::dirname(input));
let codemap = codemap::new_codemap();
@{targ_cfg: target_cfg,
opts: sopts,
cstore: cstore,
parse_sess: @{cm: codemap, mutable next_id: 1},
codemap: codemap,
// For a library crate, this is always none
mutable main_fn: none,
mutable err_count: 0u,
filesearch: filesearch,
mutable building_library: false,
working_dir: fs::dirname(input)}
}
fn parse_pretty(sess: session::session, &&name: str) -> pp_mode {
......@@ -490,10 +501,10 @@ fn build_output_filenames(ifile: str,
-> @{out_filename: str, obj_filename:str} {
let obj_path = "";
let out_path: str = "";
let sopts = sess.get_opts();
let sopts = sess.opts;
let stop_after_codegen =
sopts.output_type != link::output_type_exe ||
sopts.static && sess.building_library();
sopts.static && sess.building_library;
let obj_suffix =
......@@ -531,7 +542,7 @@ fn build_output_filenames(ifile: str,
};
if sess.building_library() {
if sess.building_library {
let basename = fs::basename(base_path);
let dylibname = std::os::dylib_filename(basename);
out_path = fs::connect(dirname, dylibname);
......@@ -552,7 +563,7 @@ fn build_output_filenames(ifile: str,
modified
};
if sess.building_library() {
if sess.building_library {
// FIXME: We might want to warn here; we're actually not going to
// respect the user's choice of library name when it comes time to
// link, we'll be linking to lib<basename>-<hash>-<version>.so no
......
......@@ -51,51 +51,53 @@
type crate_metadata = {name: str, data: [u8]};
obj session(targ_cfg: @config,
opts: @options,
cstore: metadata::cstore::cstore,
parse_sess: parse_sess,
// For a library crate, this is always none
mutable main_fn: option::t<node_id>,
mutable err_count: uint,
filesearch: filesearch::filesearch,
mutable building_library: bool,
working_dir: str) {
fn get_targ_cfg() -> @config { ret targ_cfg; }
fn get_opts() -> @options { ret opts; }
fn get_cstore() -> metadata::cstore::cstore { cstore }
type session = @{targ_cfg: @config,
opts: @options,
cstore: metadata::cstore::cstore,
parse_sess: parse_sess,
codemap: codemap::codemap,
// For a library crate, this is always none
mutable main_fn: option::t<node_id>,
mutable err_count: uint,
filesearch: filesearch::filesearch,
mutable building_library: bool,
working_dir: str};
impl session for session {
fn span_fatal(sp: span, msg: str) -> ! {
// FIXME: Use constants, but rustboot doesn't know how to export them.
codemap::emit_error(some(sp), msg, parse_sess.cm);
codemap::emit_error(some(sp), msg, self.parse_sess.cm);
fail;
}
fn fatal(msg: str) -> ! {
codemap::emit_error(none, msg, parse_sess.cm);
codemap::emit_error(none, msg, self.parse_sess.cm);
fail;
}
fn span_err(sp: span, msg: str) {
codemap::emit_error(some(sp), msg, parse_sess.cm);
err_count += 1u;
codemap::emit_error(some(sp), msg, self.parse_sess.cm);
self.err_count += 1u;
}
fn err(msg: str) {
codemap::emit_error(none, msg, parse_sess.cm);
err_count += 1u;
codemap::emit_error(none, msg, self.parse_sess.cm);
self.err_count += 1u;
}
fn has_errors() -> bool { err_count > 0u }
fn has_errors() -> bool { self.err_count > 0u }
fn abort_if_errors() {
if err_count > 0u { self.fatal("aborting due to previous errors"); }
if self.err_count > 0u {
self.fatal("aborting due to previous errors");
}
}
fn span_warn(sp: span, msg: str) {
// FIXME: Use constants, but rustboot doesn't know how to export them.
codemap::emit_warning(some(sp), msg, parse_sess.cm);
codemap::emit_warning(some(sp), msg, self.parse_sess.cm);
}
fn warn(msg: str) {
codemap::emit_warning(none, msg, self.parse_sess.cm);
}
fn warn(msg: str) { codemap::emit_warning(none, msg, parse_sess.cm); }
fn span_note(sp: span, msg: str) {
// FIXME: Use constants, but rustboot doesn't know how to export them.
codemap::emit_note(some(sp), msg, parse_sess.cm);
codemap::emit_note(some(sp), msg, self.parse_sess.cm);
}
fn note(msg: str) {
codemap::emit_note(none, msg, self.parse_sess.cm);
}
fn note(msg: str) { codemap::emit_note(none, msg, parse_sess.cm); }
fn span_bug(sp: span, msg: str) -> ! {
self.span_fatal(sp, #fmt["internal compiler error %s", msg]);
}
......@@ -106,26 +108,8 @@ fn span_unimpl(sp: span, msg: str) -> ! {
self.span_bug(sp, "unimplemented " + msg);
}
fn unimpl(msg: str) -> ! { self.bug("unimplemented " + msg); }
fn get_codemap() -> codemap::codemap { ret parse_sess.cm; }
fn lookup_pos(pos: uint) -> codemap::loc {
ret codemap::lookup_char_pos(parse_sess.cm, pos);
}
fn get_parse_sess() -> parse_sess { ret parse_sess; }
fn next_node_id() -> ast::node_id {
ret syntax::parse::parser::next_node_id(parse_sess);
}
fn span_str(sp: span) -> str {
ret codemap::span_to_str(sp, self.get_codemap());
}
fn set_main_id(d: node_id) { main_fn = some(d); }
fn get_main_id() -> option::t<node_id> { main_fn }
fn filesearch() -> filesearch::filesearch { filesearch }
fn building_library() -> bool { building_library }
fn set_building_library(crate: @ast::crate) {
building_library = session::building_library(opts.crate_type, crate);
}
fn get_working_dir() -> str {
ret working_dir;
ret syntax::parse::parser::next_node_id(self.parse_sess);
}
}
......
......@@ -3,7 +3,7 @@
import core::{either, vec, option};
import std::map;
import syntax::{ast, ast_util};
import driver::session;
import driver::session::session;
export attr_meta;
export attr_metas;
......@@ -189,7 +189,7 @@ fn remove_meta_items_by_name(items: [@ast::meta_item], name: str) ->
ret vec::filter_map(items, filter);
}
fn require_unique_names(sess: session::session, metas: [@ast::meta_item]) {
fn require_unique_names(sess: session, metas: [@ast::meta_item]) {
let map = map::new_str_hash();
for meta: @ast::meta_item in metas {
let name = get_meta_item_name(meta);
......
......@@ -8,6 +8,7 @@
import syntax::print::pprust;
import syntax::codemap::span;
import driver::session;
import session::session;
import front::attr;
export modify_for_testing;
......@@ -27,7 +28,7 @@
fn modify_for_testing(sess: session::session,
crate: @ast::crate) -> @ast::crate {
if sess.get_opts().test {
if sess.opts.test {
generate_test_harness(sess, crate)
} else {
strip_test_functions(crate)
......
// Extracting metadata from crate files
import driver::session;
import session::session;
import syntax::{ast, ast_util};
import lib::llvm::{False, llvm, mk_object_file, mk_section_iter};
import front::attr;
......@@ -39,7 +40,7 @@ fn visit_view_item(e: env, i: @ast::view_item) {
alt i.node {
ast::view_item_use(ident, meta_items, id) {
let cnum = resolve_crate(e, ident, meta_items, i.span);
cstore::add_use_stmt_cnum(e.sess.get_cstore(), id, cnum);
cstore::add_use_stmt_cnum(e.sess.cstore, id, cnum);
}
_ { }
}
......@@ -56,7 +57,7 @@ fn visit_item(e: env, i: @ast::item) {
either::left(msg) { e.sess.span_fatal(i.span, msg); }
}
let cstore = e.sess.get_cstore();
let cstore = e.sess.cstore;
let native_name =
alt attr::get_meta_item_value_str_by_name(i.attrs, "link_name") {
some(nn) {
......@@ -126,7 +127,7 @@ fn metadata_matches(crate_data: @[u8], metas: [@ast::meta_item]) -> bool {
fn default_native_lib_naming(sess: session::session, static: bool) ->
{prefix: str, suffix: str} {
if static { ret {prefix: "lib", suffix: ".rlib"}; }
alt sess.get_targ_cfg().os {
alt sess.targ_cfg.os {
session::os_win32. { ret {prefix: "", suffix: ".dll"}; }
session::os_macos. { ret {prefix: "lib", suffix: ".dylib"}; }
session::os_linux. { ret {prefix: "lib", suffix: ".so"}; }
......@@ -157,14 +158,14 @@ fn find_library_crate(sess: session::session, ident: ast::ident,
}
};
let nn = default_native_lib_naming(sess, sess.get_opts().static);
let nn = default_native_lib_naming(sess, sess.opts.static);
let x =
find_library_crate_aux(sess, nn, crate_name,
metas, sess.filesearch());
if x != none || sess.get_opts().static { ret x; }
metas, sess.filesearch);
if x != none || sess.opts.static { ret x; }
let nn2 = default_native_lib_naming(sess, true);
ret find_library_crate_aux(sess, nn2, crate_name, metas,
sess.filesearch());
sess.filesearch);
}
fn find_library_crate_aux(sess: session::session,
......@@ -218,7 +219,7 @@ fn get_metadata_section(sess: session::session,
while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False {
let name_buf = llvm::LLVMGetSectionName(si.llsi);
let name = unsafe { str::from_cstr(name_buf) };
if str::eq(name, sess.get_targ_cfg().target_strs.meta_sect_name) {
if str::eq(name, sess.targ_cfg.target_strs.meta_sect_name) {
let cbuf = llvm::LLVMGetSectionContents(si.llsi);
let csz = llvm::LLVMGetSectionSize(si.llsi);
unsafe {
......@@ -264,7 +265,7 @@ fn resolve_crate(e: env, ident: ast::ident, metas: [@ast::meta_item],
let cmeta = @{name: ident, data: cdata,
cnum_map: cnum_map, cnum: cnum};
let cstore = e.sess.get_cstore();
let cstore = e.sess.cstore;
cstore::set_crate_data(cstore, cnum, cmeta);
cstore::add_used_crate_file(cstore, cfilename);
ret cnum;
......
......@@ -57,7 +57,7 @@ fn resolve_path(cstore: cstore::cstore, cnum: ast::crate_num,
}
fn get_tag_variants(tcx: ty::ctxt, def: ast::def_id) -> [ty::variant_info] {
let cstore = tcx.sess.get_cstore();
let cstore = tcx.sess.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate);
ret decoder::get_tag_variants(cdata, def.node, tcx)
}
......@@ -70,13 +70,13 @@ fn get_impls_for_mod(cstore: cstore::cstore, def: ast::def_id,
}
fn get_iface_methods(tcx: ty::ctxt, def: ast::def_id) -> @[ty::method] {
let cstore = tcx.sess.get_cstore();
let cstore = tcx.sess.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_iface_methods(cdata, def.node, tcx)
}
fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_bounds_and_ty {
let cstore = tcx.sess.get_cstore();
let cstore = tcx.sess.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_type(cdata, def.node, tcx)
}
......@@ -88,7 +88,7 @@ fn get_item_name(cstore: cstore::cstore, cnum: int, id: int) -> ast::ident {
fn get_impl_iface(tcx: ty::ctxt, def: ast::def_id)
-> option::t<ty::t> {
let cstore = tcx.sess.get_cstore();
let cstore = tcx.sess.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_impl_iface(cdata, def.node, tcx)
}
......
......@@ -704,7 +704,7 @@ fn encode_metadata(cx: @crate_ctxt, crate: @crate) -> str {
let crate_attrs = synthesize_crate_attrs(ecx, crate);
encode_attributes(ebml_w, crate_attrs);
encode_crate_deps(ebml_w, cx.sess.get_cstore());
encode_crate_deps(ebml_w, cx.sess.cstore);
// Encode and index the paths.
ebml::start_tag(ebml_w, tag_paths);
......
......@@ -8,6 +8,7 @@
import std::list;
import option::{some, none, is_none};
import list::list;
import driver::session::session;
// This is not an alias-analyser (though it would merit from becoming one, or
// getting input from one, to be more precise). It is a pass that checks
......
import syntax::visit;
import syntax::ast::*;
import driver::session::session;
type ctx = {tcx: ty::ctxt, mutable allow_block: bool};
......
import syntax::{ast, ast_util};
import driver::session::session;
import std::map;
export capture_mode;
......
......@@ -3,6 +3,7 @@
lit_expr_eq};
import syntax::visit;
import option::{some, none};
import driver::session::session;
fn check_crate(tcx: ty::ctxt, crate: @crate) {
let v =
......
......@@ -59,14 +59,14 @@ fn check_expr(sess: session, e: @expr, &&is_const: bool, v: visit::vt<bool>) {
expr_lit(@{node: lit_int(v, t), _}) {
if t != ty_char {
if (v as u64) > ast_util::int_ty_max(
t == ty_i ? sess.get_targ_cfg().int_type : t) {
t == ty_i ? sess.targ_cfg.int_type : t) {
sess.span_err(e.span, "literal out of range for its type");
}
}
}
expr_lit(@{node: lit_uint(v, t), _}) {
if v > ast_util::uint_ty_max(
t == ty_u ? sess.get_targ_cfg().uint_type : t) {
t == ty_u ? sess.targ_cfg.uint_type : t) {
sess.span_err(e.span, "literal out of range for its type");
}
}
......
......@@ -162,7 +162,7 @@ fn create_compile_unit(cx: @crate_ctxt, full_path: str)
option::none. {}
}
let work_dir = cx.sess.get_working_dir();
let work_dir = cx.sess.working_dir;
let file_path = if str::starts_with(full_path, work_dir) {
str::slice(full_path, str::byte_len(work_dir),
str::byte_len(full_path))
......@@ -176,7 +176,7 @@ fn create_compile_unit(cx: @crate_ctxt, full_path: str)
llstr(work_dir),
llstr(#env["CFG_VERSION"]),
lli1(false), // main compile unit
lli1(cx.sess.get_opts().optimize != 0u),
lli1(cx.sess.opts.optimize != 0u),
llstr(""), // flags (???)
lli32(0) // runtime version (???)
// list of enum types
......@@ -223,10 +223,10 @@ fn line_from_span(cm: codemap::codemap, sp: codemap::span) -> uint {
fn create_block(cx: @block_ctxt) -> @metadata<block_md> {
let cache = get_cache(bcx_ccx(cx));
let start = codemap::lookup_char_pos(bcx_ccx(cx).sess.get_codemap(),
let start = codemap::lookup_char_pos(bcx_ccx(cx).sess.codemap,
cx.sp.lo);
let fname = start.filename;
let end = codemap::lookup_char_pos(bcx_ccx(cx).sess.get_codemap(),
let end = codemap::lookup_char_pos(bcx_ccx(cx).sess.codemap,
cx.sp.hi);
let tg = LexicalBlockTag;
alt cached_metadata::<@metadata<block_md>>(
......@@ -395,14 +395,14 @@ fn create_record(cx: @crate_ctxt, t: ty::t, fields: [ast::ty_field],
let file_node = create_file(cx, fname);
let scx = create_structure(file_node,
option::get(cx.dbg_cx).names.next("rec"),
line_from_span(cx.sess.get_codemap(),
line_from_span(cx.sess.codemap,
span) as int);
for field in fields {
let field_t = ty::get_field(ccx_tcx(cx), t, field.node.ident).mt.ty;
let ty_md = create_ty(cx, field_t, field.node.mt.ty);
let (size, align) = member_size_and_align(field.node.mt.ty);
add_member(scx, field.node.ident,
line_from_span(cx.sess.get_codemap(), field.span) as int,
line_from_span(cx.sess.codemap, field.span) as int,
size as int, align as int, ty_md.node);
}
let mdval = @{node: finish_structure(scx), data:{hash: t}};
......@@ -602,7 +602,7 @@ fn t_to_ty(cx: @crate_ctxt, t: ty::t, span: codemap::span) -> @ast::ty {
}
fn filename_from_span(cx: @crate_ctxt, sp: codemap::span) -> str {
codemap::lookup_char_pos(cx.sess.get_codemap(), sp.lo).filename
codemap::lookup_char_pos(cx.sess.codemap, sp.lo).filename
}
fn create_var(type_tag: int, context: ValueRef, name: str, file: ValueRef,
......@@ -632,7 +632,7 @@ fn create_local_var(bcx: @block_ctxt, local: @ast::local)
let name = alt local.node.pat.node {
ast::pat_bind(ident, _) { ident /*XXX deal w/ optional node binding*/ }
};
let loc = codemap::lookup_char_pos(cx.sess.get_codemap(),
let loc = codemap::lookup_char_pos(cx.sess.codemap,
local.span.lo);
let ty = trans::node_id_type(cx, local.node.id);
let tymd = create_ty(cx, ty, local.node.ty);
......@@ -675,7 +675,7 @@ fn create_arg(bcx: @block_ctxt, arg: ast::arg)
/*let arg_n = alt cx.ast_map.get(arg.id) {
ast_map::node_arg(_, n) { n - 2u }
};*/
let loc = codemap::lookup_char_pos(cx.sess.get_codemap(),
let loc = codemap::lookup_char_pos(cx.sess.codemap,
fcx.sp.lo);
let ty = trans::node_id_type(cx, arg.id);
let tymd = create_ty(cx, ty, arg.ty);
......@@ -696,10 +696,10 @@ fn create_arg(bcx: @block_ctxt, arg: ast::arg)
}
fn update_source_pos(cx: @block_ctxt, s: codemap::span) {
if !bcx_ccx(cx).sess.get_opts().debuginfo {
if !bcx_ccx(cx).sess.opts.debuginfo {
ret;
}
let cm = bcx_ccx(cx).sess.get_codemap();
let cm = bcx_ccx(cx).sess.codemap;
let blockmd = create_block(cx);
let loc = codemap::lookup_char_pos(cm, s.lo);
let scopedata = [lli32(loc.line as int),
......@@ -716,7 +716,8 @@ fn create_function(fcx: @fn_ctxt) -> @metadata<subprogram_md> {
#debug("~~");
log(debug, fcx.id);
log(debug, cx.sess.span_str(fcx.sp));
log(debug, codemap::span_to_str(fcx.sp, cx.sess.codemap));
let (ident, ret_ty, id) = alt cx.ast_map.get(fcx.id) {
ast_map::node_item(item) {
......@@ -759,12 +760,12 @@ fn create_function(fcx: @fn_ctxt) -> @metadata<subprogram_md> {
option::none. {}
}
let loc = codemap::lookup_char_pos(cx.sess.get_codemap(),
let loc = codemap::lookup_char_pos(cx.sess.codemap,
fcx.sp.lo);
let file_node = create_file(cx, loc.filename).node;
let key = cx.item_symbols.contains_key(fcx.id) ? fcx.id : id;
let mangled = cx.item_symbols.get(key);
let ty_node = if cx.sess.get_opts().extra_debuginfo {
let ty_node = if cx.sess.opts.extra_debuginfo {
alt ret_ty.node {
ast::ty_nil. { llnull() }
_ { create_ty(cx, ty::node_id_to_type(ccx_tcx(cx), id),
......@@ -792,7 +793,7 @@ fn create_function(fcx: @fn_ctxt) -> @metadata<subprogram_md> {
lli32(0i), //index into virt func
llnull(), // base type with vtbl
lli1(false), // artificial
lli1(cx.sess.get_opts().optimize != 0u),
lli1(cx.sess.opts.optimize != 0u),
fcx.llfn
//list of template params
//func decl descriptor
......
......@@ -2,6 +2,7 @@
import syntax::visit;
import option::some;
import syntax::print::pprust::expr_to_str;
import driver::session::session;
export check_crate_fn_usage;
......
......@@ -8,6 +8,7 @@
import middle::ty;
import option::none;
import str;
import driver::session::session;
import lll = lib::llvm::llvm;
import bld = trans_build;
......
......@@ -3,6 +3,7 @@
import syntax::ast::*;
import syntax::codemap::span;
import ty::{kind, kind_copyable, kind_sendable, kind_noncopyable};
import driver::session::session;
// Kind analysis pass. There are three kinds:
//
......
......@@ -3,6 +3,7 @@
import syntax::ast::*;
import syntax::visit;
import syntax::ast_util;
import driver::session::session;
tag deref_t { unbox; field; index; }
......
......@@ -162,7 +162,7 @@ fn eq(v1: key, v2: key) -> bool {
fn resolve_crate(sess: session, amap: ast_map::map, crate: @ast::crate) ->
{def_map: def_map, exp_map: exp_map, impl_map: impl_map} {
let e =
@{cstore: sess.get_cstore(),
@{cstore: sess.cstore,
def_map: new_int_hash(),
ast_map: amap,
imports: new_int_hash(),
......@@ -185,7 +185,7 @@ fn resolve_crate(sess: session, amap: ast_map::map, crate: @ast::crate) ->
check_exports(e);
resolve_names(e, crate);
resolve_impls(e, crate);
if sess.get_opts().warn_unused_imports {
if sess.opts.warn_unused_imports {
check_unused_imports(e);
}
ret {def_map: e.def_map, exp_map: e.exp_map, impl_map: e.impl_map};
......@@ -472,10 +472,10 @@ fn visit_fn_with_scope(e: @env, fk: visit::fn_kind, decl: ast::fn_decl,
// is this a main fn declaration?
alt fk {
visit::fk_item_fn(nm, _) {
if is_main_name([nm]) && !e.sess.building_library() {
if is_main_name([nm]) && !e.sess.building_library {
// This is a main function -- set it in the session
// as the main ID
e.sess.set_main_id(id);
e.sess.main_fn = some(id);
}
}
_ { /* fallthrough */ }
......@@ -1496,7 +1496,7 @@ fn ns_ok(wanted:namespace, actual:namespace) -> bool {
fn lookup_external(e: env, cnum: int, ids: [ident], ns: namespace) ->
option::t<def> {
for d: def in csearch::lookup_defs(e.sess.get_cstore(), cnum, ids) {
for d: def in csearch::lookup_defs(e.sess.cstore, cnum, ids) {
let did = def_id_of_def(d);
alt d {
def_mod(_) | def_native_mod(_) {
......@@ -1919,7 +1919,7 @@ fn find_impls_in_mod(e: env, m: def, &impls: [@_impl],
}
@tmp
} else {
csearch::get_impls_for_mod(e.sess.get_cstore(), defid, none)
csearch::get_impls_for_mod(e.sess.cstore, defid, none)
};
e.impl_cache.insert(defid, cached);
}
......
......@@ -240,7 +240,7 @@ fn tag_kind(ccx: @crate_ctxt, did: ast::def_id) -> tag_kind {
// Returns the code corresponding to the pointer size on this architecture.
fn s_int(tcx: ty_ctxt) -> u8 {
ret alt tcx.sess.get_targ_cfg().arch {
ret alt tcx.sess.targ_cfg.arch {
session::arch_x86. { shape_i32 }
session::arch_x86_64. { shape_i64 }
session::arch_arm. { shape_i32 }
......@@ -248,7 +248,7 @@ fn s_int(tcx: ty_ctxt) -> u8 {
}
fn s_uint(tcx: ty_ctxt) -> u8 {
ret alt tcx.sess.get_targ_cfg().arch {
ret alt tcx.sess.targ_cfg.arch {
session::arch_x86. { shape_u32 }
session::arch_x86_64. { shape_u64 }
session::arch_arm. { shape_u32 }
......@@ -256,7 +256,7 @@ fn s_uint(tcx: ty_ctxt) -> u8 {
}
fn s_float(tcx: ty_ctxt) -> u8 {
ret alt tcx.sess.get_targ_cfg().arch {
ret alt tcx.sess.targ_cfg.arch {
session::arch_x86. { shape_f64 }
session::arch_x86_64. { shape_f64 }
session::arch_arm. { shape_f64 }
......
......@@ -18,6 +18,7 @@
import std::map::{new_int_hash, new_str_hash};
import option::{some, none};
import driver::session;
import session::session;
import front::attr;
import middle::{ty, gc, resolve, debuginfo};
import middle::freevars::*;
......@@ -364,7 +365,7 @@ fn trans_native_call(cx: @block_ctxt, externs: hashmap<str, ValueRef>,
fn trans_free_if_not_gc(cx: @block_ctxt, v: ValueRef) -> @block_ctxt {
let ccx = bcx_ccx(cx);
if !ccx.sess.get_opts().do_gc {
if !ccx.sess.opts.do_gc {
Call(cx, ccx.upcalls.free,
[PointerCast(cx, v, T_ptr(T_i8())),
C_int(bcx_ccx(cx), 0)]);
......@@ -1153,7 +1154,7 @@ fn declare_tydesc(cx: @local_ctxt, sp: span, t: ty::t, ty_params: [uint],
llalign = C_int(ccx, 0);
}
let name;
if cx.ccx.sess.get_opts().debuginfo {
if cx.ccx.sess.opts.debuginfo {
name = mangle_internal_name_by_type_only(cx.ccx, t, "tydesc");
name = sanitize(name);
} else { name = mangle_internal_name_by_seq(cx.ccx, "tydesc"); }
......@@ -1183,7 +1184,7 @@ fn declare_generic_glue(cx: @local_ctxt, t: ty::t, llfnty: TypeRef, name: str)
-> ValueRef {
let name = name;
let fn_nm;
if cx.ccx.sess.get_opts().debuginfo {
if cx.ccx.sess.opts.debuginfo {
fn_nm = mangle_internal_name_by_type_only(cx.ccx, t, "glue_" + name);
fn_nm = sanitize(fn_nm);
} else { fn_nm = mangle_internal_name_by_seq(cx.ccx, "glue_" + name); }
......@@ -1237,7 +1238,7 @@ fn make_generic_glue_inner(cx: @local_ctxt, sp: span, t: ty::t,
fn make_generic_glue(cx: @local_ctxt, sp: span, t: ty::t, llfn: ValueRef,
helper: glue_helper, ty_params: [uint], name: str) ->
ValueRef {
if !cx.ccx.sess.get_opts().stats {
if !cx.ccx.sess.opts.stats {
ret make_generic_glue_inner(cx, sp, t, llfn, helper, ty_params);
}
......@@ -1527,7 +1528,7 @@ fn decr_refcnt_maybe_free(cx: @block_ctxt, box_ptr: ValueRef, t: ty::t)
// Structural comparison: a rather involved form of glue.
fn maybe_name_value(cx: @crate_ctxt, v: ValueRef, s: str) {
if cx.sess.get_opts().save_temps {
if cx.sess.opts.save_temps {
let _: () = str::as_buf(s, {|buf| llvm::LLVMSetValueName(v, buf) });
}
}
......@@ -1971,7 +1972,7 @@ fn call_memmove(cx: @block_ctxt, dst: ValueRef, src: ValueRef,
// LLVM complains -- not even a constant element of a tydesc works).
let ccx = bcx_ccx(cx);
let key = alt ccx.sess.get_targ_cfg().arch {
let key = alt ccx.sess.targ_cfg.arch {
session::arch_x86. | session::arch_arm. { "llvm.memmove.p0i8.p0i8.i32" }
session::arch_x86_64. { "llvm.memmove.p0i8.p0i8.i64" }
};
......@@ -2623,7 +2624,7 @@ fn lval_no_env(bcx: @block_ctxt, val: ValueRef, kind: lval_kind)
fn trans_external_path(cx: @block_ctxt, did: ast::def_id,
tpt: ty::ty_param_bounds_and_ty) -> ValueRef {
let lcx = cx.fcx.lcx;
let name = csearch::get_symbol(lcx.ccx.sess.get_cstore(), did);
let name = csearch::get_symbol(lcx.ccx.sess.cstore, did);
ret get_extern_const(lcx.ccx.externs, lcx.ccx.llmod, name,
type_of_ty_param_bounds_and_ty(lcx, cx.sp, tpt));
}
......@@ -2667,7 +2668,7 @@ fn lookup_discriminant(lcx: @local_ctxt, vid: ast::def_id) -> ValueRef {
none. {
// It's an external discriminant that we haven't seen yet.
assert (vid.crate != ast::local_crate);
let sym = csearch::get_symbol(lcx.ccx.sess.get_cstore(), vid);
let sym = csearch::get_symbol(lcx.ccx.sess.cstore, vid);
let gvar =
str::as_buf(sym,
{|buf|
......@@ -3923,7 +3924,8 @@ fn trans_fail_value(bcx: @block_ctxt, sp_opt: option::t<span>,
let V_line;
alt sp_opt {
some(sp) {
let loc = bcx_ccx(bcx).sess.lookup_pos(sp.lo);
let sess = bcx_ccx(bcx).sess;
let loc = codemap::lookup_char_pos(sess.parse_sess.cm, sp.lo);
V_filename = C_cstr(bcx_ccx(bcx), loc.filename);
V_line = loc.line as int;
}
......@@ -4077,7 +4079,7 @@ fn zero_alloca(cx: @block_ctxt, llptr: ValueRef, t: ty::t)
fn trans_stmt(cx: @block_ctxt, s: ast::stmt) -> @block_ctxt {
// FIXME Fill in cx.sp
if (!bcx_ccx(cx).sess.get_opts().no_asm_comments) {
if (!bcx_ccx(cx).sess.opts.no_asm_comments) {
add_span_comment(cx, s.span, stmt_to_str(s));
}
......@@ -4097,7 +4099,7 @@ fn trans_stmt(cx: @block_ctxt, s: ast::stmt) -> @block_ctxt {
} else {
bcx = init_ref_local(bcx, local);
}
if bcx_ccx(cx).sess.get_opts().extra_debuginfo {
if bcx_ccx(cx).sess.opts.extra_debuginfo {
debuginfo::create_local_var(bcx, local);
}
}
......@@ -4116,8 +4118,8 @@ fn trans_stmt(cx: @block_ctxt, s: ast::stmt) -> @block_ctxt {
fn new_block_ctxt(cx: @fn_ctxt, parent: block_parent, kind: block_kind,
name: str) -> @block_ctxt {
let s = "";
if cx.lcx.ccx.sess.get_opts().save_temps ||
cx.lcx.ccx.sess.get_opts().debuginfo {
if cx.lcx.ccx.sess.opts.save_temps ||
cx.lcx.ccx.sess.opts.debuginfo {
s = cx.lcx.ccx.names.next(name);
}
let llbb: BasicBlockRef =
......@@ -4284,7 +4286,7 @@ fn alloc_ty(cx: @block_ctxt, t: ty::t) -> result {
// past caller conventions and may well make sense again,
// so we leave it as-is.
if bcx_tcx(cx).sess.get_opts().do_gc {
if bcx_tcx(cx).sess.opts.do_gc {
bcx = gc::add_gc_root(bcx, val, t);
}
......@@ -4309,7 +4311,7 @@ fn alloc_local(cx: @block_ctxt, local: @ast::local) -> @block_ctxt {
let r = alloc_ty(cx, t);
alt local.node.pat.node {
ast::pat_bind(ident, none.) {
if bcx_ccx(cx).sess.get_opts().debuginfo {
if bcx_ccx(cx).sess.opts.debuginfo {
let _: () = str::as_buf(ident, {|buf|
llvm::LLVMSetValueName(r.val, buf)
});
......@@ -4502,7 +4504,7 @@ fn copy_args_to_allocas(fcx: @fn_ctxt, bcx: @block_ctxt, args: [ast::arg],
}
ast::by_ref. {}
}
if fcx_ccx(fcx).sess.get_opts().extra_debuginfo {
if fcx_ccx(fcx).sess.opts.extra_debuginfo {
debuginfo::create_arg(bcx, args[arg_n]);
}
arg_n += 1u;
......@@ -4637,12 +4639,12 @@ fn trans_closure(cx: @local_ctxt, sp: span, decl: ast::fn_decl,
fn trans_fn(cx: @local_ctxt, sp: span, decl: ast::fn_decl, body: ast::blk,
llfndecl: ValueRef, ty_self: self_arg, ty_params: [ast::ty_param],
id: ast::node_id) {
let do_time = cx.ccx.sess.get_opts().stats;
let do_time = cx.ccx.sess.opts.stats;
let start = do_time ? time::get_time() : {sec: 0u32, usec: 0u32};
let fcx = option::none;
trans_closure(cx, sp, decl, body, llfndecl, ty_self, ty_params, id,
{|new_fcx| fcx = option::some(new_fcx);});
if cx.ccx.sess.get_opts().extra_debuginfo {
if cx.ccx.sess.opts.extra_debuginfo {
debuginfo::create_function(option::get(fcx));
}
if do_time {
......@@ -5149,7 +5151,7 @@ fn register_fn_full(ccx: @crate_ctxt, sp: span, path: [str], _flav: str,
ccx.item_ids.insert(node_id, llfn);
ccx.item_symbols.insert(node_id, ps);
let is_main: bool = is_main_name(path) && !ccx.sess.building_library();
let is_main: bool = is_main_name(path) && !ccx.sess.building_library;
if is_main { create_main_wrapper(ccx, sp, llfn, node_type); }
}
......@@ -5551,12 +5553,12 @@ fn create_module_map(ccx: @crate_ctxt) -> ValueRef {
fn decl_crate_map(sess: session::session, mapname: str,
llmod: ModuleRef) -> ValueRef {
let targ_cfg = sess.get_targ_cfg();
let targ_cfg = sess.targ_cfg;
let int_type = T_int(targ_cfg);
let n_subcrates = 1;
let cstore = sess.get_cstore();
let cstore = sess.cstore;
while cstore::have_crate_data(cstore, n_subcrates) { n_subcrates += 1; }
let mapname = sess.building_library() ? mapname : "toplevel";
let mapname = sess.building_library ? mapname : "toplevel";
let sym_name = "_rust_crate_map_" + mapname;
let arrtype = T_array(int_type, n_subcrates as uint);
let maptype = T_struct([int_type, arrtype]);
......@@ -5572,7 +5574,7 @@ fn decl_crate_map(sess: session::session, mapname: str,
fn fill_crate_map(ccx: @crate_ctxt, map: ValueRef) {
let subcrates: [ValueRef] = [];
let i = 1;
let cstore = ccx.sess.get_cstore();
let cstore = ccx.sess.cstore;
while cstore::have_crate_data(cstore, i) {
let nm = "_rust_crate_map_" + cstore::get_crate_data(cstore, i).name;
let cr = str::as_buf(nm, {|buf|
......@@ -5588,7 +5590,7 @@ fn fill_crate_map(ccx: @crate_ctxt, map: ValueRef) {
}
fn write_metadata(cx: @crate_ctxt, crate: @ast::crate) {
if !cx.sess.building_library() { ret; }
if !cx.sess.building_library { ret; }
let llmeta = C_postr(metadata::encoder::encode_metadata(cx, crate));
let llconst = trans_common::C_struct([llmeta]);
let llglobal =
......@@ -5598,7 +5600,7 @@ fn write_metadata(cx: @crate_ctxt, crate: @ast::crate) {
});
llvm::LLVMSetInitializer(llglobal, llconst);
let _: () =
str::as_buf(cx.sess.get_targ_cfg().target_strs.meta_sect_name,
str::as_buf(cx.sess.targ_cfg.target_strs.meta_sect_name,
{|buf| llvm::LLVMSetSection(llglobal, buf) });
llvm::LLVMSetLinkage(llglobal,
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
......@@ -5645,19 +5647,19 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
llvm::LLVMModuleCreateWithNameInContext
(buf, llvm::LLVMGetGlobalContext())
});
let data_layout = sess.get_targ_cfg().target_strs.data_layout;
let targ_triple = sess.get_targ_cfg().target_strs.target_triple;
let data_layout = sess.targ_cfg.target_strs.data_layout;
let targ_triple = sess.targ_cfg.target_strs.target_triple;
let _: () =
str::as_buf(data_layout,
{|buf| llvm::LLVMSetDataLayout(llmod, buf) });
let _: () =
str::as_buf(targ_triple,
{|buf| llvm::LLVMSetTarget(llmod, buf) });
let targ_cfg = sess.get_targ_cfg();
let td = mk_target_data(sess.get_targ_cfg().target_strs.data_layout);
let targ_cfg = sess.targ_cfg;
let td = mk_target_data(sess.targ_cfg.target_strs.data_layout);
let tn = mk_type_names();
let intrinsics = declare_intrinsics(llmod);
if sess.get_opts().extra_debuginfo {
if sess.opts.extra_debuginfo {
declare_dbg_intrinsics(llmod, intrinsics);
}
let int_type = T_int(targ_cfg);
......@@ -5668,7 +5670,7 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
let tydesc_type = T_tydesc(targ_cfg);
tn.associate("tydesc", tydesc_type);
let crate_map = decl_crate_map(sess, link_meta.name, llmod);
let dbg_cx = if sess.get_opts().debuginfo {
let dbg_cx = if sess.opts.debuginfo {
option::some(@{llmetadata: map::new_int_hash(),
names: namegen(0)})
} else {
......@@ -5737,7 +5739,7 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
// Translate the metadata.
write_metadata(cx.ccx, crate);
if ccx.sess.get_opts().stats {
if ccx.sess.opts.stats {
#error("--- trans stats ---");
#error("n_static_tydescs: %u", ccx.stats.n_static_tydescs);
#error("n_derived_tydescs: %u", ccx.stats.n_derived_tydescs);
......
import core::{vec, str};
import str::sbuf;
import lib::llvm::llvm;
import syntax::codemap::span;
import syntax::codemap;
import codemap::span;
import llvm::{ValueRef, TypeRef, BasicBlockRef, BuilderRef, Opcode,
ModuleRef};
import trans_common::{block_ctxt, T_ptr, T_nil, T_i8, T_i1, T_void,
......@@ -509,8 +510,9 @@ fn _UndefReturn(cx: @block_ctxt, Fn: ValueRef) -> ValueRef {
fn add_span_comment(bcx: @block_ctxt, sp: span, text: str) {
let ccx = bcx_ccx(bcx);
if (!ccx.sess.get_opts().no_asm_comments) {
let s = text + " (" + ccx.sess.span_str(sp) + ")";
if (!ccx.sess.opts.no_asm_comments) {
let s = text + " (" + codemap::span_to_str(sp, ccx.sess.codemap)
+ ")";
log(debug, s);
add_comment(bcx, s);
}
......@@ -518,7 +520,7 @@ fn add_span_comment(bcx: @block_ctxt, sp: span, text: str) {
fn add_comment(bcx: @block_ctxt, text: str) {
let ccx = bcx_ccx(bcx);
if (!ccx.sess.get_opts().no_asm_comments) {
if (!ccx.sess.opts.no_asm_comments) {
check str::is_not_empty("$");
let sanitized = str::replace(text, "$", "");
let comment_text = "; " + sanitized;
......
......@@ -364,7 +364,7 @@ fn maybe_clone_tydesc(bcx: @block_ctxt,
let {bcx: bcx, val:bindings_slot} =
GEP_tup_like_1(bcx, cboxptr_ty, llbox, [0, abi::cbox_elt_bindings]);
vec::iteri(bound_values) { |i, bv|
if (!ccx.sess.get_opts().no_asm_comments) {
if (!ccx.sess.opts.no_asm_comments) {
add_comment(bcx, #fmt("Copy %s into closure",
ev_to_str(ccx, bv)));
}
......
......@@ -9,6 +9,7 @@
import option::some;
import syntax::ast;
import driver::session;
import session::session;
import middle::{resolve, ty};
import back::{link, abi, upcall};
import util::common::*;
......@@ -331,7 +332,7 @@ fn get_res_dtor(ccx: @crate_ctxt, sp: span, did: ast::def_id, inner_t: ty::t)
[{mode: ast::by_ref, ty: inner_t}],
nil_res, *param_bounds);
ret trans::get_extern_const(ccx.externs, ccx.llmod,
csearch::get_symbol(ccx.sess.get_cstore(),
csearch::get_symbol(ccx.sess.cstore,
did), f_t);
}
......@@ -662,7 +663,7 @@ fn T_vec2(targ_cfg: @session::config, t: TypeRef) -> TypeRef {
}
fn T_vec(ccx: @crate_ctxt, t: TypeRef) -> TypeRef {
ret T_vec2(ccx.sess.get_targ_cfg(), t);
ret T_vec2(ccx.sess.targ_cfg, t);
}
// Note that the size of this one is in bytes.
......
......@@ -360,7 +360,7 @@ fn get_vtable(ccx: @crate_ctxt, did: ast::def_id) -> ValueRef {
if did.crate == ast::local_crate {
ccx.item_ids.get(did.node)
} else {
let name = csearch::get_symbol(ccx.sess.get_cstore(), did);
let name = csearch::get_symbol(ccx.sess.cstore, did);
get_extern_const(ccx.externs, ccx.llmod, name, T_ptr(T_i8()))
}
}
......
......@@ -16,6 +16,8 @@
import trans::*;
import trans_build::*;
import driver::session::session;
export trans_anon_obj;
export trans_obj;
......
......@@ -2,8 +2,8 @@
import option::*;
import syntax::ast::*;
import syntax::ast_util::*;
import syntax::codemap::span;
import syntax::visit;
import syntax::{visit, codemap};
import codemap::span;
import std::map::{new_int_hash};
import syntax::print::pprust::path_to_str;
import tstate::ann::{pre_and_post, pre_and_post_state, empty_ann, prestate,
......@@ -15,6 +15,7 @@
clear_in_poststate_};
import tritv::*;
import bitvectors::promises_;
import driver::session::session;
import syntax::print::pprust::{constr_args_to_str, lit_to_str};
......@@ -51,13 +52,13 @@ fn constraint_to_str(tcx: ty::ctxt, c: sp_constr) -> str {
alt c.node {
ninit(id, i) {
ret #fmt("init(%s id=%d - arising from %s)",
i, id, tcx.sess.span_str(c.span));
i, id, codemap::span_to_str(c.span, tcx.sess.codemap));
}
npred(p, _, args) {
ret #fmt("%s(%s) - arising from %s",
path_to_str(p),
comma_str(args),
tcx.sess.span_str(c.span));
codemap::span_to_str(c.span, tcx.sess.codemap));
}
}
}
......
......@@ -12,6 +12,7 @@
clear_in_poststate_};
import tritv::*;
import util::common::*;
import driver::session::session;
fn bit_num(fcx: fn_ctxt, c: tsconstr) -> uint {
let d = tsconstr_to_def_id(c);
......
......@@ -15,6 +15,7 @@
import collect_locals::mk_f_to_fn_info;
import pre_post_conditions::fn_pre_post;
import states::find_pre_post_state_fn;
import driver::session::session;
fn check_unused_vars(fcx: fn_ctxt) {
......
......@@ -6,6 +6,7 @@
import util::common::new_def_hash;
import syntax::codemap::span;
import syntax::ast_util::respan;
import driver::session::session;
type ctxt = {cs: @mutable [sp_constr], tcx: ty::ctxt};
......
......@@ -14,6 +14,7 @@
import util::common::{new_def_hash, log_expr, field_exprs,
has_nonlocal_exits, log_stmt};
import syntax::codemap::span;
import driver::session::session;
fn find_pre_post_mod(_m: _mod) -> _mod {
#debug("implement find_pre_post_mod!");
......
......@@ -10,6 +10,7 @@
import syntax::codemap::span;
import middle::ty::{expr_ty, type_is_bot};
import util::common::{field_exprs, has_nonlocal_exits};
import driver::session::session;
fn forbid_upvar(fcx: fn_ctxt, rhs_id: node_id, sp: span, t: oper_type) {
alt t {
......
......@@ -9,6 +9,7 @@
import option::some;
import std::smallintmap;
import driver::session;
import session::session;
import syntax::ast;
import syntax::ast::*;
import syntax::ast_util;
......@@ -1864,7 +1865,7 @@ fn record_var_binding(
// Simple structural type comparison.
fn struct_cmp(cx: @ctxt, expected: t, actual: t) -> result {
let tcx = cx.tcx;
let cfg = tcx.sess.get_targ_cfg();
let cfg = tcx.sess.targ_cfg;
if mach_struct(tcx, cfg, expected) == mach_struct(tcx, cfg, actual) {
ret ures_ok(expected);
}
......
......@@ -3,7 +3,7 @@
import syntax::ast_util::{local_def, respan};
import syntax::visit;
import metadata::csearch;
import driver::session;
import driver::session::session;
import util::common::*;
import syntax::codemap::span;
import middle::ty;
......@@ -1468,7 +1468,7 @@ fn matches(name: str, f: ty::field) -> bool {
}
}
fn require_unsafe(sess: session::session, f_purity: ast::purity, sp: span) {
fn require_unsafe(sess: session, f_purity: ast::purity, sp: span) {
alt f_purity {
ast::unsafe_fn. { ret; }
_ {
......@@ -1479,7 +1479,7 @@ fn require_unsafe(sess: session::session, f_purity: ast::purity, sp: span) {
}
}
fn require_impure(sess: session::session, f_purity: ast::purity, sp: span) {
fn require_impure(sess: session, f_purity: ast::purity, sp: span) {
alt f_purity {
ast::unsafe_fn. { ret; }
ast::impure_fn. { ret; }
......@@ -2879,8 +2879,8 @@ fn check_main_fn_ty(tcx: ty::ctxt, main_id: ast::node_id) {
}
fn check_for_main_fn(tcx: ty::ctxt, crate: @ast::crate) {
if !tcx.sess.building_library() {
alt tcx.sess.get_main_id() {
if !tcx.sess.building_library {
alt tcx.sess.main_fn {
some(id) { check_main_fn_ty(tcx, id); }
none. { tcx.sess.span_err(crate.span, "main function not found"); }
}
......
......@@ -33,10 +33,10 @@ fn syntax_expander_table() -> hashmap<str, syntax_extension> {
ret syntax_expanders;
}
obj ext_ctxt(sess: @session,
obj ext_ctxt(sess: session,
mutable backtrace: codemap::opt_span) {
fn session() -> @session { ret sess; }
fn session() -> session { ret sess; }
fn print_backtrace() { }
......@@ -80,7 +80,7 @@ fn span_bug(sp: span, msg: str) -> ! {
}
fn mk_ctxt(sess: session) -> ext_ctxt {
ret ext_ctxt(@sess, codemap::os_none);
ret ext_ctxt(sess, codemap::os_none);
}
fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, error: str) -> str {
......
......@@ -71,8 +71,8 @@ fn expand_crate(sess: session::session, c: @crate) -> @crate {
with *afp};
let f = make_fold(f_pre);
let cm = parse_expr_from_source_str("-", core_macros(),
sess.get_opts().cfg,
sess.get_parse_sess());
sess.opts.cfg,
sess.parse_sess);
// This is run for its side-effects on the expander env,
// as it registers all the core macros as expanders.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册