Reformat for new mode syntax, step 1
Long lines were fixed in a very crude way, as I'll be following up with another reformat in a bit.
This commit is contained in:
parent
64a6376da5
commit
fc6b7c8b38
209 changed files with 3358 additions and 3353 deletions
|
|
@ -31,7 +31,7 @@ tag output_type {
|
|||
output_type_exe;
|
||||
}
|
||||
|
||||
fn llvm_err(sess: session::session, msg: &str) {
|
||||
fn llvm_err(sess: session::session, msg: str) {
|
||||
let buf = llvm::LLVMRustGetLastError();
|
||||
if buf == std::ptr::null() {
|
||||
sess.fatal(msg);
|
||||
|
|
@ -41,11 +41,9 @@ fn llvm_err(sess: session::session, msg: &str) {
|
|||
fn link_intrinsics(sess: session::session, llmod: ModuleRef) {
|
||||
let path = fs::connect(sess.get_opts().sysroot, "lib/intrinsics.bc");
|
||||
let membuf =
|
||||
str::as_buf(
|
||||
path,
|
||||
{|buf|
|
||||
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
|
||||
});
|
||||
str::as_buf(path, {|buf|
|
||||
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
|
||||
});
|
||||
if membuf as uint == 0u {
|
||||
llvm_err(sess, "installation problem: couldn't open " + path);
|
||||
fail;
|
||||
|
|
@ -75,7 +73,7 @@ mod write {
|
|||
|
||||
// Decides what to call an intermediate file, given the name of the output
|
||||
// and the extension to use.
|
||||
fn mk_intermediate_name(output_path: &str, extension: &str) -> str {
|
||||
fn mk_intermediate_name(output_path: str, extension: str) -> str {
|
||||
let dot_pos = str::index(output_path, '.' as u8);
|
||||
let stem;
|
||||
if dot_pos < 0 {
|
||||
|
|
@ -83,7 +81,7 @@ mod write {
|
|||
} else { stem = str::substr(output_path, 0u, dot_pos as uint); }
|
||||
ret stem + "." + extension;
|
||||
}
|
||||
fn run_passes(sess: session::session, llmod: ModuleRef, output: &str) {
|
||||
fn run_passes(sess: session::session, llmod: ModuleRef, output: str) {
|
||||
let opts = sess.get_opts();
|
||||
if opts.time_llvm_passes { llvm::LLVMRustEnableTimePasses(); }
|
||||
link_intrinsics(sess, llmod);
|
||||
|
|
@ -147,8 +145,8 @@ mod write {
|
|||
False);
|
||||
|
||||
if threshold != 0u {
|
||||
llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(
|
||||
MPMB, threshold);
|
||||
llvm::LLVMPassManagerBuilderUseInlinerWithThreshold
|
||||
(MPMB, threshold);
|
||||
}
|
||||
llvm::LLVMPassManagerBuilderPopulateModulePassManager(MPMB,
|
||||
pm.llpm);
|
||||
|
|
@ -196,15 +194,14 @@ mod write {
|
|||
let _: () =
|
||||
str::as_buf(x86::get_target_triple(), {|buf_t|
|
||||
str::as_buf(output, {|buf_o|
|
||||
llvm::LLVMRustWriteOutputFile(
|
||||
pm.llpm,
|
||||
llmod,
|
||||
buf_t,
|
||||
buf_o,
|
||||
LLVMAssemblyFile,
|
||||
CodeGenOptLevel)
|
||||
})
|
||||
});
|
||||
llvm::LLVMRustWriteOutputFile(pm.llpm,
|
||||
llmod,
|
||||
buf_t,
|
||||
buf_o,
|
||||
LLVMAssemblyFile,
|
||||
CodeGenOptLevel)
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -221,8 +218,8 @@ mod write {
|
|||
buf_o,
|
||||
LLVMObjectFile,
|
||||
CodeGenOptLevel)
|
||||
})
|
||||
});
|
||||
})
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// If we aren't saving temps then just output the file
|
||||
|
|
@ -237,8 +234,8 @@ mod write {
|
|||
buf_o,
|
||||
FileType,
|
||||
CodeGenOptLevel)
|
||||
})
|
||||
});
|
||||
})
|
||||
});
|
||||
}
|
||||
// Clean up and return
|
||||
|
||||
|
|
@ -311,7 +308,7 @@ mod write {
|
|||
|
||||
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::session, c: ast::crate, output: str,
|
||||
sha: sha1) -> link_meta {
|
||||
|
||||
type provided_metas =
|
||||
|
|
@ -319,7 +316,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::session, c: ast::crate) ->
|
||||
provided_metas {
|
||||
let name: option::t<str> = none;
|
||||
let vers: option::t<str> = none;
|
||||
|
|
@ -343,13 +340,13 @@ fn build_link_meta(sess: &session::session, c: &ast::crate, output: &str,
|
|||
}
|
||||
|
||||
// This calculates CMH as defined above
|
||||
fn crate_meta_extras_hash(sha: sha1, _crate: &ast::crate,
|
||||
metas: &provided_metas) -> str {
|
||||
fn len_and_str(s: &str) -> str {
|
||||
fn crate_meta_extras_hash(sha: sha1, _crate: ast::crate,
|
||||
metas: provided_metas) -> str {
|
||||
fn len_and_str(s: str) -> str {
|
||||
ret #fmt["%u_%s", str::byte_len(s), s];
|
||||
}
|
||||
|
||||
fn len_and_str_lit(l: &ast::lit) -> str {
|
||||
fn len_and_str_lit(l: ast::lit) -> str {
|
||||
ret len_and_str(pprust::lit_to_str(@l));
|
||||
}
|
||||
|
||||
|
|
@ -373,14 +370,14 @@ fn build_link_meta(sess: &session::session, c: &ast::crate, output: &str,
|
|||
ret truncated_sha1_result(sha);
|
||||
}
|
||||
|
||||
fn warn_missing(sess: &session::session, name: &str, default: &str) {
|
||||
fn warn_missing(sess: session::session, name: str, default: str) {
|
||||
if !sess.get_opts().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,
|
||||
output: &str, metas: &provided_metas) -> str {
|
||||
fn crate_meta_name(sess: session::session, _crate: ast::crate,
|
||||
output: str, metas: provided_metas) -> str {
|
||||
ret alt metas.name {
|
||||
some(v) { v }
|
||||
none. {
|
||||
|
|
@ -397,8 +394,8 @@ fn build_link_meta(sess: &session::session, c: &ast::crate, output: &str,
|
|||
};
|
||||
}
|
||||
|
||||
fn crate_meta_vers(sess: &session::session, _crate: &ast::crate,
|
||||
metas: &provided_metas) -> str {
|
||||
fn crate_meta_vers(sess: session::session, _crate: ast::crate,
|
||||
metas: provided_metas) -> str {
|
||||
ret alt metas.vers {
|
||||
some(v) { v }
|
||||
none. {
|
||||
|
|
@ -423,7 +420,7 @@ fn truncated_sha1_result(sha: sha1) -> str {
|
|||
|
||||
|
||||
// This calculates STH for a symbol, as defined above
|
||||
fn symbol_hash(tcx: ty::ctxt, sha: sha1, t: ty::t, link_meta: &link_meta) ->
|
||||
fn symbol_hash(tcx: ty::ctxt, sha: sha1, t: ty::t, link_meta: link_meta) ->
|
||||
str {
|
||||
// NB: do *not* use abbrevs here as we want the symbol names
|
||||
// to be independent of one another in the crate.
|
||||
|
|
@ -441,7 +438,7 @@ fn symbol_hash(tcx: ty::ctxt, sha: sha1, t: ty::t, link_meta: &link_meta) ->
|
|||
ret "_" + hash;
|
||||
}
|
||||
|
||||
fn get_symbol_hash(ccx: &@crate_ctxt, t: ty::t) -> str {
|
||||
fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> str {
|
||||
let hash = "";
|
||||
alt ccx.type_sha1s.find(t) {
|
||||
some(h) { hash = h; }
|
||||
|
|
@ -453,7 +450,7 @@ fn get_symbol_hash(ccx: &@crate_ctxt, t: ty::t) -> str {
|
|||
ret hash;
|
||||
}
|
||||
|
||||
fn mangle(ss: &[str]) -> str {
|
||||
fn mangle(ss: [str]) -> str {
|
||||
// Follow C++ namespace-mangling style
|
||||
|
||||
let n = "_ZN"; // Begin name-sequence.
|
||||
|
|
@ -464,35 +461,35 @@ fn mangle(ss: &[str]) -> str {
|
|||
ret n;
|
||||
}
|
||||
|
||||
fn exported_name(path: &[str], hash: &str, _vers: &str) -> str {
|
||||
fn exported_name(path: [str], hash: str, _vers: str) -> str {
|
||||
// FIXME: versioning isn't working yet
|
||||
|
||||
ret mangle(path + [hash]); // + "@" + vers;
|
||||
|
||||
}
|
||||
|
||||
fn mangle_exported_name(ccx: &@crate_ctxt, path: &[str], t: ty::t) -> str {
|
||||
fn mangle_exported_name(ccx: @crate_ctxt, path: [str], t: ty::t) -> str {
|
||||
let hash = get_symbol_hash(ccx, t);
|
||||
ret exported_name(path, hash, ccx.link_meta.vers);
|
||||
}
|
||||
|
||||
fn mangle_internal_name_by_type_only(ccx: &@crate_ctxt, t: ty::t, name: &str)
|
||||
-> str {
|
||||
fn mangle_internal_name_by_type_only(ccx: @crate_ctxt, t: ty::t, name: str) ->
|
||||
str {
|
||||
let s = util::ppaux::ty_to_short_str(ccx.tcx, t);
|
||||
let hash = get_symbol_hash(ccx, t);
|
||||
ret mangle([name, s, hash]);
|
||||
}
|
||||
|
||||
fn mangle_internal_name_by_path_and_seq(ccx: &@crate_ctxt, path: &[str],
|
||||
flav: &str) -> str {
|
||||
fn mangle_internal_name_by_path_and_seq(ccx: @crate_ctxt, path: [str],
|
||||
flav: str) -> str {
|
||||
ret mangle(path + [ccx.names.next(flav)]);
|
||||
}
|
||||
|
||||
fn mangle_internal_name_by_path(_ccx: &@crate_ctxt, path: &[str]) -> str {
|
||||
fn mangle_internal_name_by_path(_ccx: @crate_ctxt, path: [str]) -> str {
|
||||
ret mangle(path);
|
||||
}
|
||||
|
||||
fn mangle_internal_name_by_seq(ccx: &@crate_ctxt, flav: &str) -> str {
|
||||
fn mangle_internal_name_by_seq(ccx: @crate_ctxt, flav: str) -> str {
|
||||
ret ccx.names.next(flav);
|
||||
}
|
||||
//
|
||||
|
|
|
|||
|
|
@ -41,14 +41,14 @@ type upcalls =
|
|||
|
||||
fn declare_upcalls(_tn: type_names, tydesc_type: TypeRef,
|
||||
taskptr_type: TypeRef, llmod: ModuleRef) -> @upcalls {
|
||||
fn decl(llmod: ModuleRef, name: &str, tys: [TypeRef], rv: TypeRef) ->
|
||||
fn decl(llmod: ModuleRef, name: str, tys: [TypeRef], rv: TypeRef) ->
|
||||
ValueRef {
|
||||
let arg_tys: [TypeRef] = [];
|
||||
for t: TypeRef in tys { arg_tys += [t]; }
|
||||
let fn_ty = T_fn(arg_tys, rv);
|
||||
ret trans::decl_cdecl_fn(llmod, "upcall_" + name, fn_ty);
|
||||
}
|
||||
fn decl_with_taskptr(taskptr_type: TypeRef, llmod: ModuleRef, name: &str,
|
||||
fn decl_with_taskptr(taskptr_type: TypeRef, llmod: ModuleRef, name: str,
|
||||
tys: [TypeRef], rv: TypeRef) -> ValueRef {
|
||||
ret decl(llmod, name, [taskptr_type] + tys, rv);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ import back::link::output_type;
|
|||
|
||||
tag pp_mode { ppm_normal; ppm_expanded; ppm_typed; ppm_identified; }
|
||||
|
||||
fn default_configuration(sess: session::session, argv0: &str, input: &str) ->
|
||||
fn default_configuration(sess: session::session, argv0: str, input: str) ->
|
||||
ast::crate_cfg {
|
||||
let libc =
|
||||
alt sess.get_targ_cfg().os {
|
||||
|
|
@ -60,7 +60,7 @@ fn default_configuration(sess: session::session, argv0: &str, input: &str) ->
|
|||
mk("build_compiler", argv0), mk("build_input", input)];
|
||||
}
|
||||
|
||||
fn build_configuration(sess: session::session, argv0: &str, input: &str) ->
|
||||
fn build_configuration(sess: session::session, argv0: str, input: str) ->
|
||||
ast::crate_cfg {
|
||||
// Combine the configuration requested by the session (command line) with
|
||||
// some default and generated configuration items
|
||||
|
|
@ -78,7 +78,7 @@ fn build_configuration(sess: session::session, argv0: &str, input: &str) ->
|
|||
}
|
||||
|
||||
// Convert strings provided as --cfg [cfgspec] into a crate_cfg
|
||||
fn parse_cfgspecs(cfgspecs: &[str]) -> ast::crate_cfg {
|
||||
fn parse_cfgspecs(cfgspecs: [str]) -> ast::crate_cfg {
|
||||
// FIXME: It would be nice to use the parser to parse all varieties of
|
||||
// meta_item here. At the moment we just support the meta_word variant.
|
||||
let words = [];
|
||||
|
|
@ -86,16 +86,16 @@ fn parse_cfgspecs(cfgspecs: &[str]) -> ast::crate_cfg {
|
|||
ret words;
|
||||
}
|
||||
|
||||
fn input_is_stdin(filename: &str) -> bool { filename == "-" }
|
||||
fn input_is_stdin(filename: str) -> bool { filename == "-" }
|
||||
|
||||
fn parse_input(sess: session::session, cfg: &ast::crate_cfg, input: &str) ->
|
||||
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())
|
||||
} else { parse_input_src(sess, cfg, input).crate }
|
||||
}
|
||||
|
||||
fn parse_input_src(sess: session::session, cfg: &ast::crate_cfg, infile: &str)
|
||||
fn parse_input_src(sess: session::session, cfg: ast::crate_cfg, infile: str)
|
||||
-> {crate: @ast::crate, src: str} {
|
||||
let srcbytes =
|
||||
if infile != "-" {
|
||||
|
|
@ -108,7 +108,7 @@ fn parse_input_src(sess: session::session, cfg: &ast::crate_cfg, infile: &str)
|
|||
ret {crate: crate, src: src};
|
||||
}
|
||||
|
||||
fn time<@T>(do_it: bool, what: &str, thunk: fn() -> T) -> T {
|
||||
fn time<@T>(do_it: bool, what: str, thunk: fn() -> T) -> T {
|
||||
if !do_it { ret thunk(); }
|
||||
let start = std::time::precise_time_s();
|
||||
let rv = thunk();
|
||||
|
|
@ -118,8 +118,8 @@ fn time<@T>(do_it: bool, what: &str, thunk: fn() -> T) -> T {
|
|||
ret rv;
|
||||
}
|
||||
|
||||
fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: &str,
|
||||
output: &str) {
|
||||
fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
|
||||
output: str) {
|
||||
let time_passes = sess.get_opts().time_passes;
|
||||
let crate =
|
||||
time(time_passes, "parsing", bind parse_input(sess, cfg, input));
|
||||
|
|
@ -158,8 +158,9 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: &str,
|
|||
let mut_map =
|
||||
time(time_passes, "mutability checking",
|
||||
bind middle::mut::check_crate(ty_cx, crate));
|
||||
let copy_map = time(time_passes, "alias checking",
|
||||
bind middle::alias::check_crate(ty_cx, crate));
|
||||
let copy_map =
|
||||
time(time_passes, "alias checking",
|
||||
bind middle::alias::check_crate(ty_cx, crate));
|
||||
time(time_passes, "kind checking", bind kind::check_crate(ty_cx, crate));
|
||||
if sess.get_opts().no_trans { ret; }
|
||||
let llmod =
|
||||
|
|
@ -170,12 +171,12 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: &str,
|
|||
bind link::write::run_passes(sess, llmod, output));
|
||||
}
|
||||
|
||||
fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg,
|
||||
input: &str, ppm: pp_mode) {
|
||||
fn ann_paren_for_expr(node: &pprust::ann_node) {
|
||||
fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str,
|
||||
ppm: pp_mode) {
|
||||
fn ann_paren_for_expr(node: pprust::ann_node) {
|
||||
alt node { pprust::node_expr(s, expr) { pprust::popen(s); } _ { } }
|
||||
}
|
||||
fn ann_typed_post(tcx: &ty::ctxt, node: &pprust::ann_node) {
|
||||
fn ann_typed_post(tcx: ty::ctxt, node: pprust::ann_node) {
|
||||
alt node {
|
||||
pprust::node_expr(s, expr) {
|
||||
pp::space(s.s);
|
||||
|
|
@ -187,7 +188,7 @@ fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg,
|
|||
_ { }
|
||||
}
|
||||
}
|
||||
fn ann_identified_post(node: &pprust::ann_node) {
|
||||
fn ann_identified_post(node: pprust::ann_node) {
|
||||
alt node {
|
||||
pprust::node_item(s, item) {
|
||||
pp::space(s.s);
|
||||
|
|
@ -240,14 +241,14 @@ fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg,
|
|||
io::string_reader(src), io::stdout(), ann);
|
||||
}
|
||||
|
||||
fn version(argv0: &str) {
|
||||
fn version(argv0: str) {
|
||||
let vers = "unknown version";
|
||||
let env_vers = #env["CFG_VERSION"];
|
||||
if str::byte_len(env_vers) != 0u { vers = env_vers; }
|
||||
io::stdout().write_str(#fmt["%s %s\n", argv0, vers]);
|
||||
}
|
||||
|
||||
fn usage(argv0: &str) {
|
||||
fn usage(argv0: str) {
|
||||
io::stdout().write_str(#fmt["usage: %s [options] <input>\n", argv0] +
|
||||
"
|
||||
options:
|
||||
|
|
@ -285,7 +286,7 @@ options:
|
|||
");
|
||||
}
|
||||
|
||||
fn get_os(triple: &str) -> session::os {
|
||||
fn get_os(triple: str) -> session::os {
|
||||
ret if str::find(triple, "win32") >= 0 ||
|
||||
str::find(triple, "mingw32") >= 0 {
|
||||
session::os_win32
|
||||
|
|
@ -296,7 +297,7 @@ fn get_os(triple: &str) -> session::os {
|
|||
} else { log_err "Unknown operating system!"; fail };
|
||||
}
|
||||
|
||||
fn get_arch(triple: &str) -> session::arch {
|
||||
fn get_arch(triple: str) -> session::arch {
|
||||
ret if str::find(triple, "i386") >= 0 || str::find(triple, "i486") >= 0 ||
|
||||
str::find(triple, "i586") >= 0 ||
|
||||
str::find(triple, "i686") >= 0 ||
|
||||
|
|
@ -310,7 +311,7 @@ fn get_arch(triple: &str) -> session::arch {
|
|||
} else { log_err "Unknown architecture! " + triple; fail };
|
||||
}
|
||||
|
||||
fn get_default_sysroot(binary: &str) -> str {
|
||||
fn get_default_sysroot(binary: str) -> str {
|
||||
let dirname = fs::dirname(binary);
|
||||
if str::eq(dirname, binary) { ret "."; }
|
||||
ret dirname;
|
||||
|
|
@ -327,8 +328,8 @@ fn build_target_config() -> @session::config {
|
|||
ret target_cfg;
|
||||
}
|
||||
|
||||
fn build_session_options(binary: &str, match: &getopts::match,
|
||||
binary_dir: &str) -> @session::options {
|
||||
fn build_session_options(binary: str, match: getopts::match, binary_dir: str)
|
||||
-> @session::options {
|
||||
let library = opt_present(match, "lib");
|
||||
let static = opt_present(match, "static");
|
||||
|
||||
|
|
@ -415,7 +416,7 @@ fn build_session(sopts: @session::options) -> session::session {
|
|||
none, 0u);
|
||||
}
|
||||
|
||||
fn parse_pretty(sess: session::session, name: &str) -> pp_mode {
|
||||
fn parse_pretty(sess: session::session, name: str) -> pp_mode {
|
||||
if str::eq(name, "normal") {
|
||||
ret ppm_normal;
|
||||
} else if str::eq(name, "expanded") {
|
||||
|
|
@ -513,6 +514,7 @@ fn main(args: [str]) {
|
|||
link::output_type_assembly. { "s" }
|
||||
|
||||
|
||||
|
||||
// Object and exe output both use the '.o' extension here
|
||||
link::output_type_object. | link::output_type_exe. {
|
||||
"o"
|
||||
|
|
@ -554,9 +556,9 @@ fn main(args: [str]) {
|
|||
} else { lib_cmd = "-shared"; }
|
||||
|
||||
// Converts a library file name into a gcc -l argument
|
||||
fn unlib(config: @session::config, filename: &str) -> str {
|
||||
fn unlib(config: @session::config, filename: str) -> str {
|
||||
let rmlib =
|
||||
bind fn (config: @session::config, filename: &str) -> str {
|
||||
bind fn (config: @session::config, filename: str) -> str {
|
||||
if config.os == session::os_macos ||
|
||||
config.os == session::os_linux &&
|
||||
str::find(filename, "lib") == 0 {
|
||||
|
|
@ -564,7 +566,7 @@ fn main(args: [str]) {
|
|||
str::byte_len(filename));
|
||||
} else { ret filename; }
|
||||
}(config, _);
|
||||
fn rmext(filename: &str) -> str {
|
||||
fn rmext(filename: str) -> str {
|
||||
let parts = str::split(filename, '.' as u8);
|
||||
vec::pop(parts);
|
||||
ret str::connect(parts, ".");
|
||||
|
|
|
|||
|
|
@ -58,46 +58,46 @@ obj session(targ_cfg: @config,
|
|||
fn get_targ_cfg() -> @config { ret targ_cfg; }
|
||||
fn get_opts() -> @options { ret opts; }
|
||||
fn get_cstore() -> metadata::cstore::cstore { cstore }
|
||||
fn span_fatal(sp: span, msg: &str) -> ! {
|
||||
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);
|
||||
fail;
|
||||
}
|
||||
fn fatal(msg: &str) -> ! {
|
||||
fn fatal(msg: str) -> ! {
|
||||
codemap::emit_error(none, msg, parse_sess.cm);
|
||||
fail;
|
||||
}
|
||||
fn span_err(sp: span, msg: &str) {
|
||||
fn span_err(sp: span, msg: str) {
|
||||
codemap::emit_error(some(sp), msg, parse_sess.cm);
|
||||
err_count += 1u;
|
||||
}
|
||||
fn err(msg: &str) {
|
||||
fn err(msg: str) {
|
||||
codemap::emit_error(none, msg, parse_sess.cm);
|
||||
err_count += 1u;
|
||||
}
|
||||
fn abort_if_errors() {
|
||||
if err_count > 0u { self.fatal("aborting due to previous errors"); }
|
||||
}
|
||||
fn span_warn(sp: span, msg: &str) {
|
||||
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);
|
||||
}
|
||||
fn warn(msg: &str) { codemap::emit_warning(none, msg, parse_sess.cm); }
|
||||
fn span_note(sp: span, msg: &str) {
|
||||
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);
|
||||
}
|
||||
fn note(msg: &str) { codemap::emit_note(none, msg, parse_sess.cm); }
|
||||
fn span_bug(sp: span, msg: &str) -> ! {
|
||||
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]);
|
||||
}
|
||||
fn bug(msg: &str) -> ! {
|
||||
fn bug(msg: str) -> ! {
|
||||
self.fatal(#fmt["internal compiler error %s", msg]);
|
||||
}
|
||||
fn span_unimpl(sp: span, msg: &str) -> ! {
|
||||
fn span_unimpl(sp: span, msg: str) -> ! {
|
||||
self.span_bug(sp, "unimplemented " + msg);
|
||||
}
|
||||
fn unimpl(msg: &str) -> ! { self.bug("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);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ export mk_attr;
|
|||
|
||||
// From a list of crate attributes get only the meta_items that impact crate
|
||||
// linkage
|
||||
fn find_linkage_metas(attrs: &[ast::attribute]) -> [@ast::meta_item] {
|
||||
fn find_linkage_metas(attrs: [ast::attribute]) -> [@ast::meta_item] {
|
||||
let metas: [@ast::meta_item] = [];
|
||||
for attr: ast::attribute in find_attrs_by_name(attrs, "link") {
|
||||
alt attr.node.value.node {
|
||||
|
|
@ -42,10 +42,10 @@ fn find_linkage_metas(attrs: &[ast::attribute]) -> [@ast::meta_item] {
|
|||
}
|
||||
|
||||
// Search a list of attributes and return only those with a specific name
|
||||
fn find_attrs_by_name(attrs: &[ast::attribute], name: ast::ident) ->
|
||||
fn find_attrs_by_name(attrs: [ast::attribute], name: ast::ident) ->
|
||||
[ast::attribute] {
|
||||
let filter =
|
||||
bind fn (a: &ast::attribute, name: ast::ident) ->
|
||||
bind fn (a: ast::attribute, name: ast::ident) ->
|
||||
option::t<ast::attribute> {
|
||||
if get_attr_name(a) == name {
|
||||
option::some(a)
|
||||
|
|
@ -54,14 +54,14 @@ fn find_attrs_by_name(attrs: &[ast::attribute], name: ast::ident) ->
|
|||
ret vec::filter_map(filter, attrs);
|
||||
}
|
||||
|
||||
fn get_attr_name(attr: &ast::attribute) -> ast::ident {
|
||||
fn get_attr_name(attr: ast::attribute) -> ast::ident {
|
||||
get_meta_item_name(@attr.node.value)
|
||||
}
|
||||
|
||||
fn find_meta_items_by_name(metas: &[@ast::meta_item], name: ast::ident) ->
|
||||
fn find_meta_items_by_name(metas: [@ast::meta_item], name: ast::ident) ->
|
||||
[@ast::meta_item] {
|
||||
let filter =
|
||||
bind fn (m: &@ast::meta_item, name: ast::ident) ->
|
||||
bind fn (m: @ast::meta_item, name: ast::ident) ->
|
||||
option::t<@ast::meta_item> {
|
||||
if get_meta_item_name(m) == name {
|
||||
option::some(m)
|
||||
|
|
@ -70,7 +70,7 @@ fn find_meta_items_by_name(metas: &[@ast::meta_item], name: ast::ident) ->
|
|||
ret vec::filter_map(filter, metas);
|
||||
}
|
||||
|
||||
fn get_meta_item_name(meta: &@ast::meta_item) -> ast::ident {
|
||||
fn get_meta_item_name(meta: @ast::meta_item) -> ast::ident {
|
||||
alt meta.node {
|
||||
ast::meta_word(n) { n }
|
||||
ast::meta_name_value(n, _) { n }
|
||||
|
|
@ -80,7 +80,7 @@ fn get_meta_item_name(meta: &@ast::meta_item) -> ast::ident {
|
|||
|
||||
// Gets the string value if the meta_item is a meta_name_value variant
|
||||
// containing a string, otherwise none
|
||||
fn get_meta_item_value_str(meta: &@ast::meta_item) -> option::t<str> {
|
||||
fn get_meta_item_value_str(meta: @ast::meta_item) -> option::t<str> {
|
||||
alt meta.node {
|
||||
ast::meta_name_value(_, v) {
|
||||
alt v.node { ast::lit_str(s) { option::some(s) } _ { option::none } }
|
||||
|
|
@ -89,10 +89,10 @@ fn get_meta_item_value_str(meta: &@ast::meta_item) -> option::t<str> {
|
|||
}
|
||||
}
|
||||
|
||||
fn attr_meta(attr: &ast::attribute) -> @ast::meta_item { @attr.node.value }
|
||||
fn attr_meta(attr: ast::attribute) -> @ast::meta_item { @attr.node.value }
|
||||
|
||||
// Get the meta_items from inside a vector of attributes
|
||||
fn attr_metas(attrs: &[ast::attribute]) -> [@ast::meta_item] {
|
||||
fn attr_metas(attrs: [ast::attribute]) -> [@ast::meta_item] {
|
||||
let mitems = [];
|
||||
for a: ast::attribute in attrs { mitems += [attr_meta(a)]; }
|
||||
ret mitems;
|
||||
|
|
@ -119,7 +119,7 @@ fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn contains(haystack: &[@ast::meta_item], needle: @ast::meta_item) -> bool {
|
||||
fn contains(haystack: [@ast::meta_item], needle: @ast::meta_item) -> bool {
|
||||
log #fmt["looking for %s",
|
||||
syntax::print::pprust::meta_item_to_str(*needle)];
|
||||
for item: @ast::meta_item in haystack {
|
||||
|
|
@ -131,15 +131,15 @@ fn contains(haystack: &[@ast::meta_item], needle: @ast::meta_item) -> bool {
|
|||
ret false;
|
||||
}
|
||||
|
||||
fn contains_name(metas: &[@ast::meta_item], name: ast::ident) -> bool {
|
||||
fn contains_name(metas: [@ast::meta_item], name: ast::ident) -> bool {
|
||||
let matches = find_meta_items_by_name(metas, name);
|
||||
ret vec::len(matches) > 0u;
|
||||
}
|
||||
|
||||
// FIXME: This needs to sort by meta_item variant in addition to the item name
|
||||
fn sort_meta_items(items: &[@ast::meta_item]) -> [@ast::meta_item] {
|
||||
fn lteq(ma: &@ast::meta_item, mb: &@ast::meta_item) -> bool {
|
||||
fn key(m: &@ast::meta_item) -> ast::ident {
|
||||
fn sort_meta_items(items: [@ast::meta_item]) -> [@ast::meta_item] {
|
||||
fn lteq(ma: @ast::meta_item, mb: @ast::meta_item) -> bool {
|
||||
fn key(m: @ast::meta_item) -> ast::ident {
|
||||
alt m.node {
|
||||
ast::meta_word(name) { name }
|
||||
ast::meta_name_value(name, _) { name }
|
||||
|
|
@ -160,11 +160,11 @@ fn sort_meta_items(items: &[@ast::meta_item]) -> [@ast::meta_item] {
|
|||
ret v2;
|
||||
}
|
||||
|
||||
fn remove_meta_items_by_name(items: &[@ast::meta_item], name: &str) ->
|
||||
fn remove_meta_items_by_name(items: [@ast::meta_item], name: str) ->
|
||||
[@ast::meta_item] {
|
||||
|
||||
let filter =
|
||||
bind fn (item: &@ast::meta_item, name: &str) ->
|
||||
bind fn (item: @ast::meta_item, name: str) ->
|
||||
option::t<@ast::meta_item> {
|
||||
if get_meta_item_name(item) != name {
|
||||
option::some(item)
|
||||
|
|
@ -174,7 +174,7 @@ fn remove_meta_items_by_name(items: &[@ast::meta_item], name: &str) ->
|
|||
ret vec::filter_map(filter, items);
|
||||
}
|
||||
|
||||
fn require_unique_names(sess: &session::session, metas: &[@ast::meta_item]) {
|
||||
fn require_unique_names(sess: session::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);
|
||||
|
|
@ -186,11 +186,11 @@ fn require_unique_names(sess: &session::session, metas: &[@ast::meta_item]) {
|
|||
}
|
||||
}
|
||||
|
||||
fn span<@T>(item: &T) -> ast::spanned<T> {
|
||||
fn span<@T>(item: T) -> ast::spanned<T> {
|
||||
ret {node: item, span: ast_util::dummy_sp()};
|
||||
}
|
||||
|
||||
fn mk_name_value_item_str(name: ast::ident, value: &str) -> @ast::meta_item {
|
||||
fn mk_name_value_item_str(name: ast::ident, value: str) -> @ast::meta_item {
|
||||
let value_lit = span(ast::lit_str(value));
|
||||
ret mk_name_value_item(name, value_lit);
|
||||
}
|
||||
|
|
@ -199,7 +199,7 @@ fn mk_name_value_item(name: ast::ident, value: ast::lit) -> @ast::meta_item {
|
|||
ret @span(ast::meta_name_value(name, value));
|
||||
}
|
||||
|
||||
fn mk_list_item(name: ast::ident, items: &[@ast::meta_item]) ->
|
||||
fn mk_list_item(name: ast::ident, items: [@ast::meta_item]) ->
|
||||
@ast::meta_item {
|
||||
ret @span(ast::meta_list(name, items));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,12 @@ fn strip_unconfigured_items(crate: @ast::crate) -> @ast::crate {
|
|||
ret res;
|
||||
}
|
||||
|
||||
fn filter_item(cfg: &ast::crate_cfg, item: &@ast::item) ->
|
||||
fn filter_item(cfg: ast::crate_cfg, item: @ast::item) ->
|
||||
option::t<@ast::item> {
|
||||
if item_in_cfg(cfg, item) { option::some(item) } else { option::none }
|
||||
}
|
||||
|
||||
fn fold_mod(cfg: &ast::crate_cfg, m: &ast::_mod, fld: fold::ast_fold) ->
|
||||
fn fold_mod(cfg: ast::crate_cfg, m: ast::_mod, fld: fold::ast_fold) ->
|
||||
ast::_mod {
|
||||
let filter = bind filter_item(cfg, _);
|
||||
let filtered_items = vec::filter_map(filter, m.items);
|
||||
|
|
@ -37,14 +37,14 @@ fn fold_mod(cfg: &ast::crate_cfg, m: &ast::_mod, fld: fold::ast_fold) ->
|
|||
items: vec::map(fld.fold_item, filtered_items)};
|
||||
}
|
||||
|
||||
fn filter_native_item(cfg: &ast::crate_cfg, item: &@ast::native_item) ->
|
||||
fn filter_native_item(cfg: ast::crate_cfg, item: @ast::native_item) ->
|
||||
option::t<@ast::native_item> {
|
||||
if native_item_in_cfg(cfg, item) {
|
||||
option::some(item)
|
||||
} else { option::none }
|
||||
}
|
||||
|
||||
fn fold_native_mod(cfg: &ast::crate_cfg, nm: &ast::native_mod,
|
||||
fn fold_native_mod(cfg: ast::crate_cfg, nm: ast::native_mod,
|
||||
fld: fold::ast_fold) -> ast::native_mod {
|
||||
let filter = bind filter_native_item(cfg, _);
|
||||
let filtered_items = vec::filter_map(filter, nm.items);
|
||||
|
|
@ -54,7 +54,7 @@ fn fold_native_mod(cfg: &ast::crate_cfg, nm: &ast::native_mod,
|
|||
items: filtered_items};
|
||||
}
|
||||
|
||||
fn filter_stmt(cfg: &ast::crate_cfg, stmt: &@ast::stmt) ->
|
||||
fn filter_stmt(cfg: ast::crate_cfg, stmt: @ast::stmt) ->
|
||||
option::t<@ast::stmt> {
|
||||
alt stmt.node {
|
||||
ast::stmt_decl(decl, _) {
|
||||
|
|
@ -71,7 +71,7 @@ fn filter_stmt(cfg: &ast::crate_cfg, stmt: &@ast::stmt) ->
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_block(cfg: &ast::crate_cfg, b: &ast::blk_, fld: fold::ast_fold) ->
|
||||
fn fold_block(cfg: ast::crate_cfg, b: ast::blk_, fld: fold::ast_fold) ->
|
||||
ast::blk_ {
|
||||
let filter = bind filter_stmt(cfg, _);
|
||||
let filtered_stmts = vec::filter_map(filter, b.stmts);
|
||||
|
|
@ -81,18 +81,17 @@ fn fold_block(cfg: &ast::crate_cfg, b: &ast::blk_, fld: fold::ast_fold) ->
|
|||
rules: b.rules};
|
||||
}
|
||||
|
||||
fn item_in_cfg(cfg: &ast::crate_cfg, item: &@ast::item) -> bool {
|
||||
fn item_in_cfg(cfg: ast::crate_cfg, item: @ast::item) -> bool {
|
||||
ret in_cfg(cfg, item.attrs);
|
||||
}
|
||||
|
||||
fn native_item_in_cfg(cfg: &ast::crate_cfg, item: &@ast::native_item) ->
|
||||
bool {
|
||||
fn native_item_in_cfg(cfg: ast::crate_cfg, item: @ast::native_item) -> bool {
|
||||
ret in_cfg(cfg, item.attrs);
|
||||
}
|
||||
|
||||
// Determine if an item should be translated in the current crate
|
||||
// configuration based on the item's attributes
|
||||
fn in_cfg(cfg: &ast::crate_cfg, attrs: &[ast::attribute]) -> bool {
|
||||
fn in_cfg(cfg: ast::crate_cfg, attrs: [ast::attribute]) -> bool {
|
||||
|
||||
// The "cfg" attributes on the item
|
||||
let item_cfg_attrs = attr::find_attrs_by_name(attrs, "cfg");
|
||||
|
|
@ -104,9 +103,8 @@ fn in_cfg(cfg: &ast::crate_cfg, attrs: &[ast::attribute]) -> bool {
|
|||
// which the item is valid
|
||||
let item_cfg_metas =
|
||||
{
|
||||
fn extract_metas(inner_items: &[@ast::meta_item],
|
||||
cfg_item: &@ast::meta_item) ->
|
||||
[@ast::meta_item] {
|
||||
fn extract_metas(inner_items: [@ast::meta_item],
|
||||
cfg_item: @ast::meta_item) -> [@ast::meta_item] {
|
||||
alt cfg_item.node {
|
||||
ast::meta_list(name, items) {
|
||||
assert (name == "cfg");
|
||||
|
|
|
|||
|
|
@ -55,14 +55,13 @@ fn modify_for_testing(crate: @ast::crate) -> @ast::crate {
|
|||
ret res;
|
||||
}
|
||||
|
||||
fn fold_mod(_cx: &test_ctxt, m: &ast::_mod, fld: fold::ast_fold) ->
|
||||
ast::_mod {
|
||||
fn fold_mod(_cx: test_ctxt, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod {
|
||||
|
||||
// Remove any defined main function from the AST so it doesn't clash with
|
||||
// the one we're going to add. FIXME: This is sloppy. Instead we should
|
||||
// have some mechanism to indicate to the translation pass which function
|
||||
// we want to be main.
|
||||
fn nomain(item: &@ast::item) -> option::t<@ast::item> {
|
||||
fn nomain(item: @ast::item) -> option::t<@ast::item> {
|
||||
alt item.node {
|
||||
ast::item_fn(f, _) {
|
||||
if item.ident == "main" {
|
||||
|
|
@ -78,7 +77,7 @@ fn fold_mod(_cx: &test_ctxt, m: &ast::_mod, fld: fold::ast_fold) ->
|
|||
ret fold::noop_fold_mod(mod_nomain, fld);
|
||||
}
|
||||
|
||||
fn fold_crate(cx: &test_ctxt, c: &ast::crate_, fld: fold::ast_fold) ->
|
||||
fn fold_crate(cx: test_ctxt, c: ast::crate_, fld: fold::ast_fold) ->
|
||||
ast::crate_ {
|
||||
let folded = fold::noop_fold_crate(c, fld);
|
||||
|
||||
|
|
@ -88,7 +87,7 @@ fn fold_crate(cx: &test_ctxt, c: &ast::crate_, fld: fold::ast_fold) ->
|
|||
}
|
||||
|
||||
|
||||
fn fold_item(cx: &test_ctxt, i: &@ast::item, fld: fold::ast_fold) ->
|
||||
fn fold_item(cx: test_ctxt, i: @ast::item, fld: fold::ast_fold) ->
|
||||
@ast::item {
|
||||
|
||||
cx.path += [i.ident];
|
||||
|
|
@ -106,11 +105,11 @@ fn fold_item(cx: &test_ctxt, i: &@ast::item, fld: fold::ast_fold) ->
|
|||
ret res;
|
||||
}
|
||||
|
||||
fn is_test_fn(i: &@ast::item) -> bool {
|
||||
fn is_test_fn(i: @ast::item) -> bool {
|
||||
let has_test_attr =
|
||||
vec::len(attr::find_attrs_by_name(i.attrs, "test")) > 0u;
|
||||
|
||||
fn has_test_signature(i: &@ast::item) -> bool {
|
||||
fn has_test_signature(i: @ast::item) -> bool {
|
||||
alt i.node {
|
||||
ast::item_fn(f, tps) {
|
||||
let input_cnt = vec::len(f.decl.inputs);
|
||||
|
|
@ -125,11 +124,11 @@ fn is_test_fn(i: &@ast::item) -> bool {
|
|||
ret has_test_attr && has_test_signature(i);
|
||||
}
|
||||
|
||||
fn is_ignored(i: &@ast::item) -> bool {
|
||||
fn is_ignored(i: @ast::item) -> bool {
|
||||
attr::contains_name(attr::attr_metas(i.attrs), "ignore")
|
||||
}
|
||||
|
||||
fn add_test_module(cx: &test_ctxt, m: &ast::_mod) -> ast::_mod {
|
||||
fn add_test_module(cx: test_ctxt, m: ast::_mod) -> ast::_mod {
|
||||
let testmod = mk_test_module(cx);
|
||||
ret {items: m.items + [testmod] with m};
|
||||
}
|
||||
|
|
@ -151,7 +150,7 @@ mod __test {
|
|||
|
||||
*/
|
||||
|
||||
fn mk_test_module(cx: &test_ctxt) -> @ast::item {
|
||||
fn mk_test_module(cx: test_ctxt) -> @ast::item {
|
||||
// A function that generates a vector of test descriptors to feed to the
|
||||
// test runner
|
||||
let testsfn = mk_tests(cx);
|
||||
|
|
@ -172,9 +171,9 @@ fn mk_test_module(cx: &test_ctxt) -> @ast::item {
|
|||
ret @item;
|
||||
}
|
||||
|
||||
fn nospan<@T>(t: &T) -> ast::spanned<T> { ret {node: t, span: dummy_sp()}; }
|
||||
fn nospan<@T>(t: T) -> ast::spanned<T> { ret {node: t, span: dummy_sp()}; }
|
||||
|
||||
fn mk_tests(cx: &test_ctxt) -> @ast::item {
|
||||
fn mk_tests(cx: test_ctxt) -> @ast::item {
|
||||
let ret_ty = mk_test_desc_vec_ty(cx);
|
||||
|
||||
let decl: ast::fn_decl =
|
||||
|
|
@ -215,7 +214,7 @@ fn empty_fn_ty() -> ast::ty {
|
|||
}
|
||||
|
||||
// The ast::ty of [std::test::test_desc]
|
||||
fn mk_test_desc_vec_ty(cx: &test_ctxt) -> @ast::ty {
|
||||
fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::ty {
|
||||
let test_desc_ty_path: ast::path =
|
||||
nospan({global: false,
|
||||
idents: ["std", "test", "test_desc"],
|
||||
|
|
@ -229,7 +228,7 @@ fn mk_test_desc_vec_ty(cx: &test_ctxt) -> @ast::ty {
|
|||
ret @nospan(ast::ty_vec(vec_mt));
|
||||
}
|
||||
|
||||
fn mk_test_desc_vec(cx: &test_ctxt) -> @ast::expr {
|
||||
fn mk_test_desc_vec(cx: test_ctxt) -> @ast::expr {
|
||||
log #fmt["building test vector from %u tests", vec::len(cx.testfns)];
|
||||
let descs = [];
|
||||
for test: test in cx.testfns {
|
||||
|
|
@ -242,7 +241,7 @@ fn mk_test_desc_vec(cx: &test_ctxt) -> @ast::expr {
|
|||
span: dummy_sp()};
|
||||
}
|
||||
|
||||
fn mk_test_desc_rec(cx: &test_ctxt, test: test) -> @ast::expr {
|
||||
fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
|
||||
let path = test.path;
|
||||
|
||||
log #fmt["encoding %s", ast_util::path_name_i(path)];
|
||||
|
|
@ -284,13 +283,15 @@ fn mk_test_desc_rec(cx: &test_ctxt, test: test) -> @ast::expr {
|
|||
ret @desc_rec;
|
||||
}
|
||||
|
||||
fn mk_main(cx: &test_ctxt) -> @ast::item {
|
||||
fn mk_main(cx: test_ctxt) -> @ast::item {
|
||||
|
||||
let args_mt: ast::mt = {ty: @nospan(ast::ty_str), mut: ast::imm};
|
||||
let args_ty: ast::ty = nospan(ast::ty_vec(args_mt));
|
||||
|
||||
let args_arg: ast::arg =
|
||||
{mode: ast::by_ref, ty: @args_ty, ident: "args",
|
||||
{mode: ast::by_ref,
|
||||
ty: @args_ty,
|
||||
ident: "args",
|
||||
id: cx.next_node_id()};
|
||||
|
||||
let ret_ty = nospan(ast::ty_nil);
|
||||
|
|
@ -322,7 +323,7 @@ fn mk_main(cx: &test_ctxt) -> @ast::item {
|
|||
ret @item;
|
||||
}
|
||||
|
||||
fn mk_test_main_call(cx: &test_ctxt) -> @ast::expr {
|
||||
fn mk_test_main_call(cx: test_ctxt) -> @ast::expr {
|
||||
|
||||
// Get the args passed to main so we can pass the to test_main
|
||||
let args_path: ast::path =
|
||||
|
|
|
|||
|
|
@ -809,15 +809,19 @@ native "cdecl" mod llvm = "rustllvm" {
|
|||
Value: Bool);
|
||||
fn LLVMPassManagerBuilderSetDisableUnrollLoops(PMB: PassManagerBuilderRef,
|
||||
Value: Bool);
|
||||
fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
|
||||
PMB: PassManagerBuilderRef, Value: Bool);
|
||||
fn LLVMPassManagerBuilderUseInlinerWithThreshold(
|
||||
PMB: PassManagerBuilderRef, threshold: uint);
|
||||
fn LLVMPassManagerBuilderPopulateModulePassManager(
|
||||
PMB: PassManagerBuilderRef, PM: PassManagerRef);
|
||||
fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls
|
||||
(PMB: PassManagerBuilderRef,
|
||||
Value: Bool);
|
||||
fn LLVMPassManagerBuilderUseInlinerWithThreshold
|
||||
(PMB: PassManagerBuilderRef,
|
||||
threshold: uint);
|
||||
fn LLVMPassManagerBuilderPopulateModulePassManager(PMB:
|
||||
PassManagerBuilderRef,
|
||||
PM: PassManagerRef);
|
||||
|
||||
fn LLVMPassManagerBuilderPopulateFunctionPassManager(
|
||||
PMB: PassManagerBuilderRef, PM: PassManagerRef);
|
||||
fn LLVMPassManagerBuilderPopulateFunctionPassManager(PMB:
|
||||
PassManagerBuilderRef,
|
||||
PM: PassManagerRef);
|
||||
|
||||
/** Destroys a memory buffer. */
|
||||
fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
|
||||
|
|
@ -898,7 +902,7 @@ native "cdecl" mod llvm = "rustllvm" {
|
|||
obj type_names(type_names: std::map::hashmap<TypeRef, str>,
|
||||
named_types: std::map::hashmap<str, TypeRef>) {
|
||||
|
||||
fn associate(s: &str, t: TypeRef) {
|
||||
fn associate(s: str, t: TypeRef) {
|
||||
assert (!named_types.contains_key(s));
|
||||
assert (!type_names.contains_key(t));
|
||||
type_names.insert(t, s);
|
||||
|
|
@ -909,17 +913,17 @@ obj type_names(type_names: std::map::hashmap<TypeRef, str>,
|
|||
|
||||
fn get_name(t: TypeRef) -> str { ret type_names.get(t); }
|
||||
|
||||
fn name_has_type(s: &str) -> bool { ret named_types.contains_key(s); }
|
||||
fn name_has_type(s: str) -> bool { ret named_types.contains_key(s); }
|
||||
|
||||
fn get_type(s: &str) -> TypeRef { ret named_types.get(s); }
|
||||
fn get_type(s: str) -> TypeRef { ret named_types.get(s); }
|
||||
}
|
||||
|
||||
fn mk_type_names() -> type_names {
|
||||
let nt = std::map::new_str_hash::<TypeRef>();
|
||||
|
||||
fn hash(t: &TypeRef) -> uint { ret t as uint; }
|
||||
fn hash(t: TypeRef) -> uint { ret t as uint; }
|
||||
|
||||
fn eq(a: &TypeRef, b: &TypeRef) -> bool { ret a as uint == b as uint; }
|
||||
fn eq(a: TypeRef, b: TypeRef) -> bool { ret a as uint == b as uint; }
|
||||
|
||||
let hasher: std::map::hashfn<TypeRef> = hash;
|
||||
let eqer: std::map::eqfn<TypeRef> = eq;
|
||||
|
|
@ -932,7 +936,7 @@ fn type_to_str(names: type_names, ty: TypeRef) -> str {
|
|||
ret type_to_str_inner(names, [], ty);
|
||||
}
|
||||
|
||||
fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
|
||||
fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
|
||||
str {
|
||||
|
||||
if names.type_has_name(ty) { ret names.get_name(ty); }
|
||||
|
|
@ -941,7 +945,7 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
|
|||
|
||||
let kind: int = llvm::LLVMGetTypeKind(ty);
|
||||
|
||||
fn tys_str(names: type_names, outer: &[TypeRef], tys: &[TypeRef]) -> str {
|
||||
fn tys_str(names: type_names, outer: [TypeRef], tys: [TypeRef]) -> str {
|
||||
let s: str = "";
|
||||
let first: bool = true;
|
||||
for t: TypeRef in tys {
|
||||
|
|
@ -957,6 +961,7 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
|
|||
|
||||
|
||||
|
||||
|
||||
// FIXME: more enum-as-int constants determined from Core::h;
|
||||
// horrible, horrible. Complete as needed.
|
||||
|
||||
|
|
@ -973,6 +978,7 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
|
|||
|
||||
|
||||
|
||||
|
||||
7 {
|
||||
ret "i" + std::int::str(llvm::LLVMGetIntTypeWidth(ty) as int);
|
||||
}
|
||||
|
|
@ -980,6 +986,7 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
|
|||
|
||||
|
||||
|
||||
|
||||
8 {
|
||||
let s = "fn(";
|
||||
let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
|
||||
|
|
@ -995,6 +1002,7 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
|
|||
|
||||
|
||||
|
||||
|
||||
9 {
|
||||
let s: str = "{";
|
||||
let n_elts: uint = llvm::LLVMCountStructElementTypes(ty);
|
||||
|
|
@ -1008,6 +1016,7 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
|
|||
|
||||
|
||||
|
||||
|
||||
10 {
|
||||
let el_ty = llvm::LLVMGetElementType(ty);
|
||||
ret "[" + type_to_str_inner(names, outer, el_ty) + "]";
|
||||
|
|
@ -1016,6 +1025,7 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
|
|||
|
||||
|
||||
|
||||
|
||||
11 {
|
||||
let i: uint = 0u;
|
||||
for tout: TypeRef in outer0 {
|
||||
|
|
@ -1032,6 +1042,7 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
|
|||
|
||||
|
||||
|
||||
|
||||
12 {
|
||||
ret "Opaque";
|
||||
}
|
||||
|
|
@ -1066,7 +1077,7 @@ resource target_data_res(TD: TargetDataRef) {
|
|||
|
||||
type target_data = {lltd: TargetDataRef, dtor: @target_data_res};
|
||||
|
||||
fn mk_target_data(string_rep: &str) -> target_data {
|
||||
fn mk_target_data(string_rep: str) -> target_data {
|
||||
let lltd =
|
||||
str::as_buf(string_rep, {|buf| llvm::LLVMCreateTargetData(buf) });
|
||||
ret {lltd: lltd, dtor: @target_data_res(lltd)};
|
||||
|
|
|
|||
|
|
@ -65,9 +65,9 @@ const tag_crate_dep: uint = 0x26u;
|
|||
const tag_items_data_item_inlineness: uint = 0x27u;
|
||||
|
||||
// djb's cdb hashes.
|
||||
fn hash_node_id(node_id: &int) -> uint { ret 177573u ^ (node_id as uint); }
|
||||
fn hash_node_id(node_id: int) -> uint { ret 177573u ^ (node_id as uint); }
|
||||
|
||||
fn hash_path(s: &str) -> uint {
|
||||
fn hash_path(s: str) -> uint {
|
||||
let h = 5381u;
|
||||
for ch: u8 in str::bytes(s) { h = (h << 5u) + h ^ (ch as uint); }
|
||||
ret h;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ export list_file_metadata;
|
|||
|
||||
// Traverses an AST, reading all the information about use'd crates and native
|
||||
// libraries necessary for later resolving, typechecking, linking, etc.
|
||||
fn read_crates(sess: session::session, crate: &ast::crate) {
|
||||
fn read_crates(sess: session::session, crate: ast::crate) {
|
||||
let e =
|
||||
@{sess: sess,
|
||||
crate_cache: @std::map::new_str_hash::<int>(),
|
||||
|
|
@ -50,7 +50,7 @@ type env =
|
|||
library_search_paths: [str],
|
||||
mutable next_crate_num: ast::crate_num};
|
||||
|
||||
fn visit_view_item(e: env, i: &@ast::view_item) {
|
||||
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);
|
||||
|
|
@ -60,7 +60,7 @@ fn visit_view_item(e: env, i: &@ast::view_item) {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_item(e: env, i: &@ast::item) {
|
||||
fn visit_item(e: env, i: @ast::item) {
|
||||
alt i.node {
|
||||
ast::item_native_mod(m) {
|
||||
if m.abi != ast::native_abi_rust && m.abi != ast::native_abi_cdecl {
|
||||
|
|
@ -81,7 +81,7 @@ fn visit_item(e: env, i: &@ast::item) {
|
|||
}
|
||||
|
||||
// A diagnostic function for dumping crate metadata to an output stream
|
||||
fn list_file_metadata(path: &str, out: io::writer) {
|
||||
fn list_file_metadata(path: str, out: io::writer) {
|
||||
alt get_metadata_section(path) {
|
||||
option::some(bytes) { decoder::list_crate_metadata(bytes, out); }
|
||||
option::none. {
|
||||
|
|
@ -90,7 +90,7 @@ fn list_file_metadata(path: &str, out: io::writer) {
|
|||
}
|
||||
}
|
||||
|
||||
fn metadata_matches(crate_data: &@[u8], metas: &[@ast::meta_item]) -> bool {
|
||||
fn metadata_matches(crate_data: @[u8], metas: [@ast::meta_item]) -> bool {
|
||||
let attrs = decoder::get_crate_attributes(crate_data);
|
||||
let linkage_metas = attr::find_linkage_metas(attrs);
|
||||
|
||||
|
|
@ -116,8 +116,8 @@ fn default_native_lib_naming(sess: session::session, static: bool) ->
|
|||
}
|
||||
}
|
||||
|
||||
fn find_library_crate(sess: &session::session, ident: &ast::ident,
|
||||
metas: &[@ast::meta_item], library_search_paths: &[str])
|
||||
fn find_library_crate(sess: session::session, ident: ast::ident,
|
||||
metas: [@ast::meta_item], library_search_paths: [str])
|
||||
-> option::t<{ident: str, data: @[u8]}> {
|
||||
|
||||
attr::require_unique_names(sess, metas);
|
||||
|
|
@ -146,9 +146,9 @@ fn find_library_crate(sess: &session::session, ident: &ast::ident,
|
|||
ret find_library_crate_aux(nn2, crate_name, metas, library_search_paths);
|
||||
}
|
||||
|
||||
fn find_library_crate_aux(nn: &{prefix: str, suffix: str}, crate_name: &str,
|
||||
metas: &[@ast::meta_item],
|
||||
library_search_paths: &[str]) ->
|
||||
fn find_library_crate_aux(nn: {prefix: str, suffix: str}, crate_name: str,
|
||||
metas: [@ast::meta_item],
|
||||
library_search_paths: [str]) ->
|
||||
option::t<{ident: str, data: @[u8]}> {
|
||||
let prefix: str = nn.prefix + crate_name;
|
||||
let suffix: str = nn.suffix;
|
||||
|
|
@ -184,11 +184,11 @@ fn find_library_crate_aux(nn: &{prefix: str, suffix: str}, crate_name: &str,
|
|||
ret none;
|
||||
}
|
||||
|
||||
fn get_metadata_section(filename: &str) -> option::t<@[u8]> {
|
||||
fn get_metadata_section(filename: str) -> option::t<@[u8]> {
|
||||
let mb =
|
||||
str::as_buf(filename, {|buf|
|
||||
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
|
||||
});
|
||||
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
|
||||
});
|
||||
if mb as int == 0 { ret option::none::<@[u8]>; }
|
||||
let of = mk_object_file(mb);
|
||||
let si = mk_section_iter(of.llof);
|
||||
|
|
@ -206,8 +206,8 @@ fn get_metadata_section(filename: &str) -> option::t<@[u8]> {
|
|||
ret option::none::<@[u8]>;
|
||||
}
|
||||
|
||||
fn load_library_crate(sess: &session::session, span: span, ident: &ast::ident,
|
||||
metas: &[@ast::meta_item], library_search_paths: &[str])
|
||||
fn load_library_crate(sess: session::session, span: span, ident: ast::ident,
|
||||
metas: [@ast::meta_item], library_search_paths: [str])
|
||||
-> {ident: str, data: @[u8]} {
|
||||
|
||||
|
||||
|
|
@ -219,7 +219,7 @@ fn load_library_crate(sess: &session::session, span: span, ident: &ast::ident,
|
|||
}
|
||||
}
|
||||
|
||||
fn resolve_crate(e: env, ident: &ast::ident, metas: [@ast::meta_item],
|
||||
fn resolve_crate(e: env, ident: ast::ident, metas: [@ast::meta_item],
|
||||
span: span) -> ast::crate_num {
|
||||
if !e.crate_cache.contains_key(ident) {
|
||||
let cinfo =
|
||||
|
|
@ -247,7 +247,7 @@ fn resolve_crate(e: env, ident: &ast::ident, metas: [@ast::meta_item],
|
|||
}
|
||||
|
||||
// Go through the crate metadata and load any crates that it references
|
||||
fn resolve_crate_deps(e: env, cdata: &@[u8]) -> cstore::cnum_map {
|
||||
fn resolve_crate_deps(e: env, cdata: @[u8]) -> cstore::cnum_map {
|
||||
log "resolving deps of external crate";
|
||||
// The map from crate numbers in the crate we're resolving to local crate
|
||||
// numbers
|
||||
|
|
|
|||
|
|
@ -11,18 +11,18 @@ export lookup_defs;
|
|||
export get_tag_variants;
|
||||
export get_type;
|
||||
|
||||
fn get_symbol(cstore: &cstore::cstore, def: ast::def_id) -> str {
|
||||
fn get_symbol(cstore: cstore::cstore, def: ast::def_id) -> str {
|
||||
let cdata = cstore::get_crate_data(cstore, def.crate).data;
|
||||
ret decoder::get_symbol(cdata, def.node);
|
||||
}
|
||||
|
||||
fn get_type_param_count(cstore: &cstore::cstore, def: &ast::def_id) -> uint {
|
||||
fn get_type_param_count(cstore: cstore::cstore, def: ast::def_id) -> uint {
|
||||
let cdata = cstore::get_crate_data(cstore, def.crate).data;
|
||||
ret decoder::get_type_param_count(cdata, def.node);
|
||||
}
|
||||
|
||||
fn lookup_defs(cstore: &cstore::cstore, cnum: ast::crate_num,
|
||||
path: &[ast::ident]) -> [ast::def] {
|
||||
fn lookup_defs(cstore: cstore::cstore, cnum: ast::crate_num,
|
||||
path: [ast::ident]) -> [ast::def] {
|
||||
let cdata = cstore::get_crate_data(cstore, cnum).data;
|
||||
ret decoder::lookup_defs(cdata, cnum, path);
|
||||
}
|
||||
|
|
@ -48,8 +48,8 @@ fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_kinds_and_ty {
|
|||
// external crates - if those types further refer to types in other crates
|
||||
// then we must translate the crate number from that encoded in the external
|
||||
// crate to the correct local crate number.
|
||||
fn translate_def_id(sess: &session::session, searched_crate: ast::crate_num,
|
||||
def_id: &ast::def_id) -> ast::def_id {
|
||||
fn translate_def_id(sess: session::session, searched_crate: ast::crate_num,
|
||||
def_id: ast::def_id) -> ast::def_id {
|
||||
|
||||
let ext_cnum = def_id.crate;
|
||||
let node_id = def_id.node;
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ type cstore_private =
|
|||
type use_crate_map = map::hashmap<ast::node_id, ast::crate_num>;
|
||||
|
||||
// Internal method to retrieve the data from the cstore
|
||||
fn p(cstore: &cstore) -> cstore_private { alt cstore { private(p) { p } } }
|
||||
fn p(cstore: cstore) -> cstore_private { alt cstore { private(p) { p } } }
|
||||
|
||||
fn mk_cstore() -> cstore {
|
||||
let meta_cache = map::new_int_hash::<crate_metadata>();
|
||||
|
|
@ -61,20 +61,20 @@ fn mk_cstore() -> cstore {
|
|||
mutable used_link_args: []});
|
||||
}
|
||||
|
||||
fn get_crate_data(cstore: &cstore, cnum: ast::crate_num) -> crate_metadata {
|
||||
fn get_crate_data(cstore: cstore, cnum: ast::crate_num) -> crate_metadata {
|
||||
ret p(cstore).metas.get(cnum);
|
||||
}
|
||||
|
||||
fn set_crate_data(cstore: &cstore, cnum: ast::crate_num,
|
||||
data: &crate_metadata) {
|
||||
fn set_crate_data(cstore: cstore, cnum: ast::crate_num,
|
||||
data: crate_metadata) {
|
||||
p(cstore).metas.insert(cnum, data);
|
||||
}
|
||||
|
||||
fn have_crate_data(cstore: &cstore, cnum: ast::crate_num) -> bool {
|
||||
fn have_crate_data(cstore: cstore, cnum: ast::crate_num) -> bool {
|
||||
ret p(cstore).metas.contains_key(cnum);
|
||||
}
|
||||
|
||||
iter iter_crate_data(cstore: &cstore) ->
|
||||
iter iter_crate_data(cstore: cstore) ->
|
||||
@{key: ast::crate_num, val: crate_metadata} {
|
||||
for each kv: @{key: ast::crate_num, val: crate_metadata} in
|
||||
p(cstore).metas.items() {
|
||||
|
|
@ -82,17 +82,17 @@ iter iter_crate_data(cstore: &cstore) ->
|
|||
}
|
||||
}
|
||||
|
||||
fn add_used_crate_file(cstore: &cstore, lib: &str) {
|
||||
fn add_used_crate_file(cstore: cstore, lib: str) {
|
||||
if !vec::member(lib, p(cstore).used_crate_files) {
|
||||
p(cstore).used_crate_files += [lib];
|
||||
}
|
||||
}
|
||||
|
||||
fn get_used_crate_files(cstore: &cstore) -> [str] {
|
||||
fn get_used_crate_files(cstore: cstore) -> [str] {
|
||||
ret p(cstore).used_crate_files;
|
||||
}
|
||||
|
||||
fn add_used_library(cstore: &cstore, lib: &str) -> bool {
|
||||
fn add_used_library(cstore: cstore, lib: str) -> bool {
|
||||
if lib == "" { ret false; }
|
||||
|
||||
if vec::member(lib, p(cstore).used_libraries) { ret false; }
|
||||
|
|
@ -101,25 +101,24 @@ fn add_used_library(cstore: &cstore, lib: &str) -> bool {
|
|||
ret true;
|
||||
}
|
||||
|
||||
fn get_used_libraries(cstore: &cstore) -> [str] {
|
||||
fn get_used_libraries(cstore: cstore) -> [str] {
|
||||
ret p(cstore).used_libraries;
|
||||
}
|
||||
|
||||
fn add_used_link_args(cstore: &cstore, args: &str) {
|
||||
fn add_used_link_args(cstore: cstore, args: str) {
|
||||
p(cstore).used_link_args += str::split(args, ' ' as u8);
|
||||
}
|
||||
|
||||
fn get_used_link_args(cstore: &cstore) -> [str] {
|
||||
fn get_used_link_args(cstore: cstore) -> [str] {
|
||||
ret p(cstore).used_link_args;
|
||||
}
|
||||
|
||||
fn add_use_stmt_cnum(cstore: &cstore, use_id: ast::node_id,
|
||||
fn add_use_stmt_cnum(cstore: cstore, use_id: ast::node_id,
|
||||
cnum: ast::crate_num) {
|
||||
p(cstore).use_crate_map.insert(use_id, cnum);
|
||||
}
|
||||
|
||||
fn get_use_stmt_cnum(cstore: &cstore, use_id: ast::node_id) ->
|
||||
ast::crate_num {
|
||||
fn get_use_stmt_cnum(cstore: cstore, use_id: ast::node_id) -> ast::crate_num {
|
||||
ret p(cstore).use_crate_map.get(use_id);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@ export external_resolver;
|
|||
// def_id for an item defined in another crate, somebody needs to figure out
|
||||
// what crate that's in and give us a def_id that makes sense for the current
|
||||
// build.
|
||||
type external_resolver = fn(&ast::def_id) -> ast::def_id;
|
||||
type external_resolver = fn(ast::def_id) -> ast::def_id;
|
||||
|
||||
fn lookup_hash(d: &ebml::doc, eq_fn: fn(&[u8]) -> bool, hash: uint) ->
|
||||
fn lookup_hash(d: ebml::doc, eq_fn: fn([u8]) -> bool, hash: uint) ->
|
||||
[ebml::doc] {
|
||||
let index = ebml::get_doc(d, tag_index);
|
||||
let table = ebml::get_doc(index, tag_index_table);
|
||||
|
|
@ -56,8 +56,8 @@ fn lookup_hash(d: &ebml::doc, eq_fn: fn(&[u8]) -> bool, hash: uint) ->
|
|||
ret result;
|
||||
}
|
||||
|
||||
fn maybe_find_item(item_id: int, items: &ebml::doc) -> option::t<ebml::doc> {
|
||||
fn eq_item(bytes: &[u8], item_id: int) -> bool {
|
||||
fn maybe_find_item(item_id: int, items: ebml::doc) -> option::t<ebml::doc> {
|
||||
fn eq_item(bytes: [u8], item_id: int) -> bool {
|
||||
ret ebml::be_uint_from_bytes(@bytes, 0u, 4u) as int == item_id;
|
||||
}
|
||||
let eqer = bind eq_item(_, item_id);
|
||||
|
|
@ -67,36 +67,36 @@ fn maybe_find_item(item_id: int, items: &ebml::doc) -> option::t<ebml::doc> {
|
|||
} else { ret option::some::<ebml::doc>(found[0]); }
|
||||
}
|
||||
|
||||
fn find_item(item_id: int, items: &ebml::doc) -> ebml::doc {
|
||||
fn find_item(item_id: int, items: ebml::doc) -> ebml::doc {
|
||||
ret option::get(maybe_find_item(item_id, items));
|
||||
}
|
||||
|
||||
// Looks up an item in the given metadata and returns an ebml doc pointing
|
||||
// to the item data.
|
||||
fn lookup_item(item_id: int, data: &@[u8]) -> ebml::doc {
|
||||
fn lookup_item(item_id: int, data: @[u8]) -> ebml::doc {
|
||||
let items = ebml::get_doc(ebml::new_doc(data), tag_items);
|
||||
ret find_item(item_id, items);
|
||||
}
|
||||
|
||||
fn item_family(item: &ebml::doc) -> u8 {
|
||||
fn item_family(item: ebml::doc) -> u8 {
|
||||
let fam = ebml::get_doc(item, tag_items_data_item_family);
|
||||
ret ebml::doc_as_uint(fam) as u8;
|
||||
}
|
||||
|
||||
fn item_symbol(item: &ebml::doc) -> str {
|
||||
fn item_symbol(item: ebml::doc) -> str {
|
||||
let sym = ebml::get_doc(item, tag_items_data_item_symbol);
|
||||
ret str::unsafe_from_bytes(ebml::doc_data(sym));
|
||||
}
|
||||
|
||||
fn variant_tag_id(d: &ebml::doc) -> ast::def_id {
|
||||
fn variant_tag_id(d: ebml::doc) -> ast::def_id {
|
||||
let tagdoc = ebml::get_doc(d, tag_items_data_item_tag_id);
|
||||
ret parse_def_id(ebml::doc_data(tagdoc));
|
||||
}
|
||||
|
||||
fn item_type(item: &ebml::doc, this_cnum: ast::crate_num, tcx: ty::ctxt,
|
||||
extres: &external_resolver) -> ty::t {
|
||||
fn item_type(item: ebml::doc, this_cnum: ast::crate_num, tcx: ty::ctxt,
|
||||
extres: external_resolver) -> ty::t {
|
||||
fn parse_external_def_id(this_cnum: ast::crate_num,
|
||||
extres: &external_resolver, s: &str) ->
|
||||
extres: external_resolver, s: str) ->
|
||||
ast::def_id {
|
||||
let buf = str::bytes(s);
|
||||
let external_def_id = parse_def_id(buf);
|
||||
|
|
@ -114,7 +114,7 @@ fn item_type(item: &ebml::doc, this_cnum: ast::crate_num, tcx: ty::ctxt,
|
|||
def_parser, tcx);
|
||||
}
|
||||
|
||||
fn item_ty_param_kinds(item: &ebml::doc) -> [ast::kind] {
|
||||
fn item_ty_param_kinds(item: ebml::doc) -> [ast::kind] {
|
||||
let ks: [ast::kind] = [];
|
||||
let tp = tag_items_data_item_ty_param_kinds;
|
||||
for each p: ebml::doc in ebml::tagged_docs(item, tp) {
|
||||
|
|
@ -135,7 +135,7 @@ fn item_ty_param_kinds(item: &ebml::doc) -> [ast::kind] {
|
|||
ret ks;
|
||||
}
|
||||
|
||||
fn tag_variant_ids(item: &ebml::doc, this_cnum: ast::crate_num) ->
|
||||
fn tag_variant_ids(item: ebml::doc, this_cnum: ast::crate_num) ->
|
||||
[ast::def_id] {
|
||||
let ids: [ast::def_id] = [];
|
||||
let v = tag_items_data_item_variant;
|
||||
|
|
@ -148,8 +148,8 @@ fn tag_variant_ids(item: &ebml::doc, this_cnum: ast::crate_num) ->
|
|||
|
||||
// Given a path and serialized crate metadata, returns the ID of the
|
||||
// definition the path refers to.
|
||||
fn resolve_path(path: &[ast::ident], data: @[u8]) -> [ast::def_id] {
|
||||
fn eq_item(data: &[u8], s: &str) -> bool {
|
||||
fn resolve_path(path: [ast::ident], data: @[u8]) -> [ast::def_id] {
|
||||
fn eq_item(data: [u8], s: str) -> bool {
|
||||
ret str::eq(str::unsafe_from_bytes(data), s);
|
||||
}
|
||||
let s = str::connect(path, "::");
|
||||
|
|
@ -165,14 +165,14 @@ fn resolve_path(path: &[ast::ident], data: @[u8]) -> [ast::def_id] {
|
|||
}
|
||||
|
||||
// Crate metadata queries
|
||||
fn lookup_defs(data: &@[u8], cnum: ast::crate_num, path: &[ast::ident]) ->
|
||||
fn lookup_defs(data: @[u8], cnum: ast::crate_num, path: [ast::ident]) ->
|
||||
[ast::def] {
|
||||
ret vec::map(bind lookup_def(cnum, data, _), resolve_path(path, data));
|
||||
}
|
||||
|
||||
|
||||
// FIXME doesn't yet handle re-exported externals
|
||||
fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: &ast::def_id) ->
|
||||
fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: ast::def_id) ->
|
||||
ast::def {
|
||||
let item = lookup_item(did_.node, data);
|
||||
let fam_ch = item_family(item);
|
||||
|
|
@ -198,8 +198,8 @@ fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: &ast::def_id) ->
|
|||
ret def;
|
||||
}
|
||||
|
||||
fn get_type(data: @[u8], def: ast::def_id, tcx: &ty::ctxt,
|
||||
extres: &external_resolver) -> ty::ty_param_kinds_and_ty {
|
||||
fn get_type(data: @[u8], def: ast::def_id, tcx: ty::ctxt,
|
||||
extres: external_resolver) -> ty::ty_param_kinds_and_ty {
|
||||
let this_cnum = def.crate;
|
||||
let node_id = def.node;
|
||||
let item = lookup_item(node_id, data);
|
||||
|
|
@ -225,8 +225,8 @@ fn get_symbol(data: @[u8], id: ast::node_id) -> str {
|
|||
ret item_symbol(lookup_item(id, data));
|
||||
}
|
||||
|
||||
fn get_tag_variants(_data: &@[u8], def: ast::def_id, tcx: &ty::ctxt,
|
||||
extres: &external_resolver) -> [ty::variant_info] {
|
||||
fn get_tag_variants(_data: @[u8], def: ast::def_id, tcx: ty::ctxt,
|
||||
extres: external_resolver) -> [ty::variant_info] {
|
||||
let external_crate_id = def.crate;
|
||||
let data =
|
||||
cstore::get_crate_data(tcx.sess.get_cstore(), external_crate_id).data;
|
||||
|
|
@ -267,7 +267,7 @@ fn family_has_type_params(fam_ch: u8) -> bool {
|
|||
};
|
||||
}
|
||||
|
||||
fn read_path(d: &ebml::doc) -> {path: str, pos: uint} {
|
||||
fn read_path(d: ebml::doc) -> {path: str, pos: uint} {
|
||||
let desc = ebml::doc_data(d);
|
||||
let pos = ebml::be_uint_from_bytes(@desc, 0u, 4u);
|
||||
let pathbytes = vec::slice::<u8>(desc, 4u, vec::len::<u8>(desc));
|
||||
|
|
@ -275,7 +275,7 @@ fn read_path(d: &ebml::doc) -> {path: str, pos: uint} {
|
|||
ret {path: path, pos: pos};
|
||||
}
|
||||
|
||||
fn describe_def(items: &ebml::doc, id: ast::def_id) -> str {
|
||||
fn describe_def(items: ebml::doc, id: ast::def_id) -> str {
|
||||
if id.crate != ast::local_crate { ret "external"; }
|
||||
ret item_family_to_str(item_family(find_item(id.node, items)));
|
||||
}
|
||||
|
|
@ -295,7 +295,7 @@ fn item_family_to_str(fam: u8) -> str {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_meta_items(md: &ebml::doc) -> [@ast::meta_item] {
|
||||
fn get_meta_items(md: ebml::doc) -> [@ast::meta_item] {
|
||||
let items: [@ast::meta_item] = [];
|
||||
for each meta_item_doc: ebml::doc in
|
||||
ebml::tagged_docs(md, tag_meta_item_word) {
|
||||
|
|
@ -323,7 +323,7 @@ fn get_meta_items(md: &ebml::doc) -> [@ast::meta_item] {
|
|||
ret items;
|
||||
}
|
||||
|
||||
fn get_attributes(md: &ebml::doc) -> [ast::attribute] {
|
||||
fn get_attributes(md: ebml::doc) -> [ast::attribute] {
|
||||
let attrs: [ast::attribute] = [];
|
||||
alt ebml::maybe_get_doc(md, tag_attributes) {
|
||||
option::some(attrs_d) {
|
||||
|
|
@ -344,13 +344,13 @@ fn get_attributes(md: &ebml::doc) -> [ast::attribute] {
|
|||
ret attrs;
|
||||
}
|
||||
|
||||
fn list_meta_items(meta_items: &ebml::doc, out: io::writer) {
|
||||
fn list_meta_items(meta_items: ebml::doc, out: io::writer) {
|
||||
for mi: @ast::meta_item in get_meta_items(meta_items) {
|
||||
out.write_str(#fmt["%s\n", pprust::meta_item_to_str(*mi)]);
|
||||
}
|
||||
}
|
||||
|
||||
fn list_crate_attributes(md: &ebml::doc, out: io::writer) {
|
||||
fn list_crate_attributes(md: ebml::doc, out: io::writer) {
|
||||
out.write_str("=Crate Attributes=\n");
|
||||
|
||||
for attr: ast::attribute in get_attributes(md) {
|
||||
|
|
@ -389,7 +389,7 @@ fn list_crate_deps(data: @[u8], out: io::writer) {
|
|||
out.write_str("\n");
|
||||
}
|
||||
|
||||
fn list_crate_items(bytes: &@[u8], md: &ebml::doc, out: io::writer) {
|
||||
fn list_crate_items(bytes: @[u8], md: ebml::doc, out: io::writer) {
|
||||
out.write_str("=Items=\n");
|
||||
let paths = ebml::get_doc(md, tag_paths);
|
||||
let items = ebml::get_doc(md, tag_items);
|
||||
|
|
@ -410,7 +410,7 @@ fn list_crate_items(bytes: &@[u8], md: &ebml::doc, out: io::writer) {
|
|||
out.write_str("\n");
|
||||
}
|
||||
|
||||
fn list_crate_metadata(bytes: &@[u8], out: io::writer) {
|
||||
fn list_crate_metadata(bytes: @[u8], out: io::writer) {
|
||||
let md = ebml::new_doc(bytes);
|
||||
list_crate_attributes(md, out);
|
||||
list_crate_deps(bytes, out);
|
||||
|
|
|
|||
|
|
@ -26,13 +26,13 @@ type abbrev_map = map::hashmap<ty::t, tyencode::ty_abbrev>;
|
|||
type encode_ctxt = {ccx: @crate_ctxt, type_abbrevs: abbrev_map};
|
||||
|
||||
// Path table encoding
|
||||
fn encode_name(ebml_w: &ebml::writer, name: &str) {
|
||||
fn encode_name(ebml_w: ebml::writer, name: str) {
|
||||
ebml::start_tag(ebml_w, tag_paths_data_name);
|
||||
ebml_w.writer.write(str::bytes(name));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn encode_def_id(ebml_w: &ebml::writer, id: &def_id) {
|
||||
fn encode_def_id(ebml_w: ebml::writer, id: def_id) {
|
||||
ebml::start_tag(ebml_w, tag_def_id);
|
||||
ebml_w.writer.write(str::bytes(def_to_str(id)));
|
||||
ebml::end_tag(ebml_w);
|
||||
|
|
@ -40,8 +40,8 @@ fn encode_def_id(ebml_w: &ebml::writer, id: &def_id) {
|
|||
|
||||
type entry<T> = {val: T, pos: uint};
|
||||
|
||||
fn encode_tag_variant_paths(ebml_w: &ebml::writer, variants: &[variant],
|
||||
path: &[str], index: &mutable [entry<str>]) {
|
||||
fn encode_tag_variant_paths(ebml_w: ebml::writer, variants: [variant],
|
||||
path: [str], index: &mutable [entry<str>]) {
|
||||
for variant: variant in variants {
|
||||
add_to_index(ebml_w, path, index, variant.node.name);
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
|
|
@ -51,15 +51,15 @@ fn encode_tag_variant_paths(ebml_w: &ebml::writer, variants: &[variant],
|
|||
}
|
||||
}
|
||||
|
||||
fn add_to_index(ebml_w: &ebml::writer, path: &[str],
|
||||
index: &mutable [entry<str>], name: &str) {
|
||||
fn add_to_index(ebml_w: ebml::writer, path: [str],
|
||||
index: &mutable [entry<str>], name: str) {
|
||||
let full_path = path + [name];
|
||||
index +=
|
||||
[{val: str::connect(full_path, "::"), pos: ebml_w.writer.tell()}];
|
||||
}
|
||||
|
||||
fn encode_native_module_item_paths(ebml_w: &ebml::writer, nmod: &native_mod,
|
||||
path: &[str],
|
||||
fn encode_native_module_item_paths(ebml_w: ebml::writer, nmod: native_mod,
|
||||
path: [str],
|
||||
index: &mutable [entry<str>]) {
|
||||
for nitem: @native_item in nmod.items {
|
||||
add_to_index(ebml_w, path, index, nitem.ident);
|
||||
|
|
@ -70,8 +70,8 @@ fn encode_native_module_item_paths(ebml_w: &ebml::writer, nmod: &native_mod,
|
|||
}
|
||||
}
|
||||
|
||||
fn encode_module_item_paths(ebml_w: &ebml::writer, module: &_mod,
|
||||
path: &[str], index: &mutable [entry<str>]) {
|
||||
fn encode_module_item_paths(ebml_w: ebml::writer, module: _mod, path: [str],
|
||||
index: &mutable [entry<str>]) {
|
||||
for it: @item in module.items {
|
||||
if !ast_util::is_exported(it.ident, module) { cont; }
|
||||
alt it.node {
|
||||
|
|
@ -149,7 +149,7 @@ fn encode_module_item_paths(ebml_w: &ebml::writer, module: &_mod,
|
|||
}
|
||||
}
|
||||
|
||||
fn encode_item_paths(ebml_w: &ebml::writer, crate: &@crate) -> [entry<str>] {
|
||||
fn encode_item_paths(ebml_w: ebml::writer, crate: @crate) -> [entry<str>] {
|
||||
let index: [entry<str>] = [];
|
||||
let path: [str] = [];
|
||||
ebml::start_tag(ebml_w, tag_paths);
|
||||
|
|
@ -160,21 +160,21 @@ fn encode_item_paths(ebml_w: &ebml::writer, crate: &@crate) -> [entry<str>] {
|
|||
|
||||
|
||||
// Item info table encoding
|
||||
fn encode_family(ebml_w: &ebml::writer, c: u8) {
|
||||
fn encode_family(ebml_w: ebml::writer, c: u8) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item_family);
|
||||
ebml_w.writer.write([c]);
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn encode_inlineness(ebml_w: &ebml::writer, c: u8) {
|
||||
fn encode_inlineness(ebml_w: ebml::writer, c: u8) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item_inlineness);
|
||||
ebml_w.writer.write([c]);
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn def_to_str(did: &def_id) -> str { ret #fmt["%d:%d", did.crate, did.node]; }
|
||||
fn def_to_str(did: def_id) -> str { ret #fmt["%d:%d", did.crate, did.node]; }
|
||||
|
||||
fn encode_type_param_kinds(ebml_w: &ebml::writer, tps: &[ty_param]) {
|
||||
fn encode_type_param_kinds(ebml_w: ebml::writer, tps: [ty_param]) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item_ty_param_kinds);
|
||||
ebml::write_vint(ebml_w.writer, vec::len::<ty_param>(tps));
|
||||
for tp: ty_param in tps {
|
||||
|
|
@ -189,13 +189,13 @@ fn encode_type_param_kinds(ebml_w: &ebml::writer, tps: &[ty_param]) {
|
|||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn encode_variant_id(ebml_w: &ebml::writer, vid: &def_id) {
|
||||
fn encode_variant_id(ebml_w: ebml::writer, vid: def_id) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item_variant);
|
||||
ebml_w.writer.write(str::bytes(def_to_str(vid)));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn encode_type(ecx: &@encode_ctxt, ebml_w: &ebml::writer, typ: ty::t) {
|
||||
fn encode_type(ecx: @encode_ctxt, ebml_w: ebml::writer, typ: ty::t) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item_type);
|
||||
let f = def_to_str;
|
||||
let ty_str_ctxt =
|
||||
|
|
@ -206,29 +206,28 @@ fn encode_type(ecx: &@encode_ctxt, ebml_w: &ebml::writer, typ: ty::t) {
|
|||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn encode_symbol(ecx: &@encode_ctxt, ebml_w: &ebml::writer, id: node_id) {
|
||||
fn encode_symbol(ecx: @encode_ctxt, ebml_w: ebml::writer, id: node_id) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item_symbol);
|
||||
ebml_w.writer.write(str::bytes(ecx.ccx.item_symbols.get(id)));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn encode_discriminant(ecx: &@encode_ctxt, ebml_w: &ebml::writer,
|
||||
id: node_id) {
|
||||
fn encode_discriminant(ecx: @encode_ctxt, ebml_w: ebml::writer, id: node_id) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item_symbol);
|
||||
ebml_w.writer.write(str::bytes(ecx.ccx.discrim_symbols.get(id)));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn encode_tag_id(ebml_w: &ebml::writer, id: &def_id) {
|
||||
fn encode_tag_id(ebml_w: ebml::writer, id: def_id) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item_tag_id);
|
||||
ebml_w.writer.write(str::bytes(def_to_str(id)));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn encode_tag_variant_info(ecx: &@encode_ctxt, ebml_w: &ebml::writer,
|
||||
id: node_id, variants: &[variant],
|
||||
fn encode_tag_variant_info(ecx: @encode_ctxt, ebml_w: ebml::writer,
|
||||
id: node_id, variants: [variant],
|
||||
index: &mutable [entry<int>],
|
||||
ty_params: &[ty_param]) {
|
||||
ty_params: [ty_param]) {
|
||||
for variant: variant in variants {
|
||||
index += [{val: variant.node.id, pos: ebml_w.writer.tell()}];
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
|
|
@ -246,7 +245,7 @@ fn encode_tag_variant_info(ecx: &@encode_ctxt, ebml_w: &ebml::writer,
|
|||
}
|
||||
}
|
||||
|
||||
fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: &ebml::writer, item: @item,
|
||||
fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
||||
index: &mutable [entry<int>]) {
|
||||
alt item.node {
|
||||
item_const(_, _) {
|
||||
|
|
@ -349,8 +348,8 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: &ebml::writer, item: @item,
|
|||
}
|
||||
}
|
||||
|
||||
fn encode_info_for_native_item(ecx: &@encode_ctxt, ebml_w: &ebml::writer,
|
||||
nitem: &@native_item) {
|
||||
fn encode_info_for_native_item(ecx: @encode_ctxt, ebml_w: ebml::writer,
|
||||
nitem: @native_item) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
alt nitem.node {
|
||||
native_item_ty. {
|
||||
|
|
@ -370,7 +369,7 @@ fn encode_info_for_native_item(ecx: &@encode_ctxt, ebml_w: &ebml::writer,
|
|||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn encode_info_for_items(ecx: &@encode_ctxt, ebml_w: &ebml::writer) ->
|
||||
fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::writer) ->
|
||||
[entry<int>] {
|
||||
let index: [entry<int>] = [];
|
||||
ebml::start_tag(ebml_w, tag_items_data);
|
||||
|
|
@ -395,7 +394,7 @@ fn encode_info_for_items(ecx: &@encode_ctxt, ebml_w: &ebml::writer) ->
|
|||
|
||||
// Path and definition ID indexing
|
||||
|
||||
fn create_index<T>(index: &[entry<T>], hash_fn: fn(&T) -> uint) ->
|
||||
fn create_index<T>(index: [entry<T>], hash_fn: fn(T) -> uint) ->
|
||||
[@[entry<T>]] {
|
||||
let buckets: [@mutable [entry<T>]] = [];
|
||||
for each i: uint in uint::range(0u, 256u) { buckets += [@mutable []]; }
|
||||
|
|
@ -411,8 +410,8 @@ fn create_index<T>(index: &[entry<T>], hash_fn: fn(&T) -> uint) ->
|
|||
ret buckets_frozen;
|
||||
}
|
||||
|
||||
fn encode_index<T>(ebml_w: &ebml::writer, buckets: &[@[entry<T>]],
|
||||
write_fn: fn(&io::writer, &T)) {
|
||||
fn encode_index<T>(ebml_w: ebml::writer, buckets: [@[entry<T>]],
|
||||
write_fn: fn(io::writer, T)) {
|
||||
let writer = io::new_writer(ebml_w.writer);
|
||||
ebml::start_tag(ebml_w, tag_index);
|
||||
let bucket_locs: [uint] = [];
|
||||
|
|
@ -435,13 +434,13 @@ fn encode_index<T>(ebml_w: &ebml::writer, buckets: &[@[entry<T>]],
|
|||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn write_str(writer: &io::writer, s: &str) { writer.write_str(s); }
|
||||
fn write_str(writer: io::writer, s: str) { writer.write_str(s); }
|
||||
|
||||
fn write_int(writer: &io::writer, n: &int) {
|
||||
fn write_int(writer: io::writer, n: int) {
|
||||
writer.write_be_uint(n as uint, 4u);
|
||||
}
|
||||
|
||||
fn encode_meta_item(ebml_w: &ebml::writer, mi: &meta_item) {
|
||||
fn encode_meta_item(ebml_w: ebml::writer, mi: meta_item) {
|
||||
alt mi.node {
|
||||
meta_word(name) {
|
||||
ebml::start_tag(ebml_w, tag_meta_item_word);
|
||||
|
|
@ -478,7 +477,7 @@ fn encode_meta_item(ebml_w: &ebml::writer, mi: &meta_item) {
|
|||
}
|
||||
}
|
||||
|
||||
fn encode_attributes(ebml_w: &ebml::writer, attrs: &[attribute]) {
|
||||
fn encode_attributes(ebml_w: ebml::writer, attrs: [attribute]) {
|
||||
ebml::start_tag(ebml_w, tag_attributes);
|
||||
for attr: attribute in attrs {
|
||||
ebml::start_tag(ebml_w, tag_attribute);
|
||||
|
|
@ -492,9 +491,9 @@ fn encode_attributes(ebml_w: &ebml::writer, attrs: &[attribute]) {
|
|||
// metadata that Rust cares about for linking crates. This attribute requires
|
||||
// 'name' and 'vers' items, so if the user didn't provide them we will throw
|
||||
// them in anyway with default values.
|
||||
fn synthesize_crate_attrs(ecx: &@encode_ctxt, crate: &@crate) -> [attribute] {
|
||||
fn synthesize_crate_attrs(ecx: @encode_ctxt, crate: @crate) -> [attribute] {
|
||||
|
||||
fn synthesize_link_attr(ecx: &@encode_ctxt, items: &[@meta_item]) ->
|
||||
fn synthesize_link_attr(ecx: @encode_ctxt, items: [@meta_item]) ->
|
||||
attribute {
|
||||
|
||||
assert (ecx.ccx.link_meta.name != "");
|
||||
|
|
@ -526,7 +525,7 @@ fn synthesize_crate_attrs(ecx: &@encode_ctxt, crate: &@crate) -> [attribute] {
|
|||
} else {
|
||||
alt attr.node.value.node {
|
||||
meta_list(n, l) {
|
||||
found_link_attr = true;
|
||||
found_link_attr = true;;
|
||||
[synthesize_link_attr(ecx, l)]
|
||||
}
|
||||
_ { [attr] }
|
||||
|
|
@ -539,9 +538,9 @@ fn synthesize_crate_attrs(ecx: &@encode_ctxt, crate: &@crate) -> [attribute] {
|
|||
ret attrs;
|
||||
}
|
||||
|
||||
fn encode_crate_deps(ebml_w: &ebml::writer, cstore: &cstore::cstore) {
|
||||
fn encode_crate_deps(ebml_w: ebml::writer, cstore: cstore::cstore) {
|
||||
|
||||
fn get_ordered_names(cstore: &cstore::cstore) -> [str] {
|
||||
fn get_ordered_names(cstore: cstore::cstore) -> [str] {
|
||||
type hashkv = @{key: crate_num, val: cstore::crate_metadata};
|
||||
type numname = {crate: crate_num, ident: str};
|
||||
|
||||
|
|
@ -552,9 +551,7 @@ fn encode_crate_deps(ebml_w: &ebml::writer, cstore: &cstore::cstore) {
|
|||
}
|
||||
|
||||
// Sort by cnum
|
||||
fn lteq(kv1: &numname, kv2: &numname) -> bool {
|
||||
kv1.crate <= kv2.crate
|
||||
}
|
||||
fn lteq(kv1: numname, kv2: numname) -> bool { kv1.crate <= kv2.crate }
|
||||
std::sort::quick_sort(lteq, pairs);
|
||||
|
||||
// Sanity-check the crate numbers
|
||||
|
|
@ -565,7 +562,7 @@ fn encode_crate_deps(ebml_w: &ebml::writer, cstore: &cstore::cstore) {
|
|||
}
|
||||
|
||||
// Return just the names
|
||||
fn name(kv: &numname) -> str { kv.ident }
|
||||
fn name(kv: numname) -> str { kv.ident }
|
||||
// mutable -> immutable hack for vec::map
|
||||
let immpairs = vec::slice(pairs, 0u, vec::len(pairs));
|
||||
ret vec::map(name, immpairs);
|
||||
|
|
@ -584,7 +581,7 @@ fn encode_crate_deps(ebml_w: &ebml::writer, cstore: &cstore::cstore) {
|
|||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn encode_metadata(cx: &@crate_ctxt, crate: &@crate) -> str {
|
||||
fn encode_metadata(cx: @crate_ctxt, crate: @crate) -> str {
|
||||
|
||||
let abbrevs = map::mk_hashmap(ty::hash_ty, ty::eq_ty);
|
||||
let ecx = @{ccx: cx, type_abbrevs: abbrevs};
|
||||
|
|
@ -620,7 +617,7 @@ fn encode_metadata(cx: &@crate_ctxt, crate: &@crate) -> str {
|
|||
}
|
||||
|
||||
// Get the encoded string for a type
|
||||
fn encoded_ty(tcx: &ty::ctxt, t: ty::t) -> str {
|
||||
fn encoded_ty(tcx: ty::ctxt, t: ty::t) -> str {
|
||||
let cx = @{ds: def_to_str, tcx: tcx, abbrevs: tyencode::ac_no_abbrevs};
|
||||
let sw = io::string_writer();
|
||||
tyencode::enc_ty(sw.get_writer(), cx, t);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export parse_ty_data;
|
|||
// data buffer. Whatever format you choose should not contain pipe characters.
|
||||
|
||||
// Callback to translate defs to strs or back:
|
||||
type str_def = fn(&str) -> ast::def_id;
|
||||
type str_def = fn(str) -> ast::def_id;
|
||||
|
||||
type pstate =
|
||||
{data: @[u8], crate: int, mutable pos: uint, len: uint, tcx: ty::ctxt};
|
||||
|
|
@ -401,7 +401,7 @@ fn parse_ty_fn(st: @pstate, sd: str_def) ->
|
|||
|
||||
|
||||
// Rust metadata parsing
|
||||
fn parse_def_id(buf: &[u8]) -> ast::def_id {
|
||||
fn parse_def_id(buf: [u8]) -> ast::def_id {
|
||||
let colon_idx = 0u;
|
||||
let len = vec::len::<u8>(buf);
|
||||
while colon_idx < len && buf[colon_idx] != ':' as u8 { colon_idx += 1u; }
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ export enc_ty;
|
|||
type ctxt =
|
||||
// Def -> str Callback:
|
||||
// The type context.
|
||||
{ds: fn(&def_id) -> str, tcx: ty::ctxt, abbrevs: abbrev_ctxt};
|
||||
{ds: fn(def_id) -> str, tcx: ty::ctxt, abbrevs: abbrev_ctxt};
|
||||
|
||||
// Compact string representation for ty.t values. API ty_str & parse_from_str.
|
||||
// Extra parameters are for converting to/from def_ids in the string rep.
|
||||
|
|
@ -30,14 +30,14 @@ type ty_abbrev = {pos: uint, len: uint, s: @str};
|
|||
|
||||
tag abbrev_ctxt { ac_no_abbrevs; ac_use_abbrevs(hashmap<ty::t, ty_abbrev>); }
|
||||
|
||||
fn cx_uses_abbrevs(cx: &@ctxt) -> bool {
|
||||
fn cx_uses_abbrevs(cx: @ctxt) -> bool {
|
||||
alt cx.abbrevs {
|
||||
ac_no_abbrevs. { ret false; }
|
||||
ac_use_abbrevs(_) { ret true; }
|
||||
}
|
||||
}
|
||||
|
||||
fn enc_ty(w: &io::writer, cx: &@ctxt, t: ty::t) {
|
||||
fn enc_ty(w: io::writer, cx: @ctxt, t: ty::t) {
|
||||
alt cx.abbrevs {
|
||||
ac_no_abbrevs. {
|
||||
let result_str: @str;
|
||||
|
|
@ -82,7 +82,7 @@ fn enc_ty(w: &io::writer, cx: &@ctxt, t: ty::t) {
|
|||
}
|
||||
}
|
||||
}
|
||||
fn enc_mt(w: &io::writer, cx: &@ctxt, mt: &ty::mt) {
|
||||
fn enc_mt(w: io::writer, cx: @ctxt, mt: ty::mt) {
|
||||
alt mt.mut {
|
||||
imm. { }
|
||||
mut. { w.write_char('m'); }
|
||||
|
|
@ -90,7 +90,7 @@ fn enc_mt(w: &io::writer, cx: &@ctxt, mt: &ty::mt) {
|
|||
}
|
||||
enc_ty(w, cx, mt.ty);
|
||||
}
|
||||
fn enc_sty(w: &io::writer, cx: &@ctxt, st: &ty::sty) {
|
||||
fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
|
||||
alt st {
|
||||
ty::ty_nil. { w.write_char('n'); }
|
||||
ty::ty_bot. { w.write_char('z'); }
|
||||
|
|
@ -194,7 +194,7 @@ fn enc_sty(w: &io::writer, cx: &@ctxt, st: &ty::sty) {
|
|||
}
|
||||
}
|
||||
}
|
||||
fn enc_proto(w: &io::writer, proto: proto) {
|
||||
fn enc_proto(w: io::writer, proto: proto) {
|
||||
alt proto {
|
||||
proto_iter. { w.write_char('W'); }
|
||||
proto_fn. { w.write_char('F'); }
|
||||
|
|
@ -202,8 +202,8 @@ fn enc_proto(w: &io::writer, proto: proto) {
|
|||
}
|
||||
}
|
||||
|
||||
fn enc_ty_fn(w: &io::writer, cx: &@ctxt, args: &[ty::arg], out: ty::t,
|
||||
cf: &controlflow, constrs: &[@ty::constr]) {
|
||||
fn enc_ty_fn(w: io::writer, cx: @ctxt, args: [ty::arg], out: ty::t,
|
||||
cf: controlflow, constrs: [@ty::constr]) {
|
||||
w.write_char('[');
|
||||
for arg: ty::arg in args {
|
||||
alt arg.mode {
|
||||
|
|
@ -227,7 +227,7 @@ fn enc_ty_fn(w: &io::writer, cx: &@ctxt, args: &[ty::arg], out: ty::t,
|
|||
}
|
||||
|
||||
// FIXME less copy-and-paste
|
||||
fn enc_constr(w: &io::writer, cx: &@ctxt, c: &@ty::constr) {
|
||||
fn enc_constr(w: io::writer, cx: @ctxt, c: @ty::constr) {
|
||||
w.write_str(path_to_str(c.node.path));
|
||||
w.write_char('(');
|
||||
w.write_str(cx.ds(c.node.id));
|
||||
|
|
@ -244,7 +244,7 @@ fn enc_constr(w: &io::writer, cx: &@ctxt, c: &@ty::constr) {
|
|||
w.write_char(')');
|
||||
}
|
||||
|
||||
fn enc_ty_constr(w: &io::writer, cx: &@ctxt, c: &@ty::type_constr) {
|
||||
fn enc_ty_constr(w: io::writer, cx: @ctxt, c: @ty::type_constr) {
|
||||
w.write_str(path_to_str(c.node.path));
|
||||
w.write_char('(');
|
||||
w.write_str(cx.ds(c.node.id));
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ type ctx =
|
|||
mutable next_local: uint,
|
||||
copy_map: copy_map};
|
||||
|
||||
fn check_crate(tcx: ty::ctxt, crate: &@ast::crate) -> copy_map {
|
||||
fn check_crate(tcx: ty::ctxt, crate: @ast::crate) -> copy_map {
|
||||
// Stores information about object fields and function
|
||||
// arguments that's otherwise not easily available.
|
||||
let cx =
|
||||
|
|
@ -63,17 +63,19 @@ fn check_crate(tcx: ty::ctxt, crate: &@ast::crate) -> copy_map {
|
|||
ret cx.copy_map;
|
||||
}
|
||||
|
||||
fn visit_fn(f: &ast::_fn, _tp: &[ast::ty_param], _sp: &span, _name: &fn_ident,
|
||||
_id: ast::node_id, sc: &scope, v: &vt<scope>) {
|
||||
fn visit_fn(f: ast::_fn, _tp: [ast::ty_param], _sp: span, _name: fn_ident,
|
||||
_id: ast::node_id, sc: scope, v: vt<scope>) {
|
||||
visit::visit_fn_decl(f.decl, sc, v);
|
||||
let scope =
|
||||
alt f.proto {
|
||||
|
||||
|
||||
// Blocks need to obey any restrictions from the enclosing scope.
|
||||
ast::proto_block. | ast::proto_closure. {
|
||||
sc
|
||||
}
|
||||
|
||||
|
||||
// Non capturing functions start out fresh.
|
||||
_ {
|
||||
@[]
|
||||
|
|
@ -82,7 +84,7 @@ fn visit_fn(f: &ast::_fn, _tp: &[ast::ty_param], _sp: &span, _name: &fn_ident,
|
|||
v.visit_block(f.body, scope, v);
|
||||
}
|
||||
|
||||
fn visit_expr(cx: &@ctx, ex: &@ast::expr, sc: &scope, v: &vt<scope>) {
|
||||
fn visit_expr(cx: @ctx, ex: @ast::expr, sc: scope, v: vt<scope>) {
|
||||
let handled = true;
|
||||
alt ex.node {
|
||||
ast::expr_call(f, args) {
|
||||
|
|
@ -129,14 +131,14 @@ fn visit_expr(cx: &@ctx, ex: &@ast::expr, sc: &scope, v: &vt<scope>) {
|
|||
if !handled { visit::visit_expr(ex, sc, v); }
|
||||
}
|
||||
|
||||
fn register_locals(cx: &ctx, pat: &@ast::pat) {
|
||||
fn register_locals(cx: ctx, pat: @ast::pat) {
|
||||
for each pat in ast_util::pat_bindings(pat) {
|
||||
cx.local_map.insert(pat.id, local(cx.next_local));
|
||||
cx.next_local += 1u;
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_decl(cx: &@ctx, d: &@ast::decl, sc: &scope, v: &vt<scope>) {
|
||||
fn visit_decl(cx: @ctx, d: @ast::decl, sc: scope, v: vt<scope>) {
|
||||
visit::visit_decl(d, sc, v);
|
||||
alt d.node {
|
||||
ast::decl_local(locs) {
|
||||
|
|
@ -156,22 +158,21 @@ fn visit_decl(cx: &@ctx, d: &@ast::decl, sc: &scope, v: &vt<scope>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn cant_copy(cx: &ctx, r: &restrict) -> bool {
|
||||
fn cant_copy(cx: ctx, r: restrict) -> bool {
|
||||
if r.given_up { ret false; }
|
||||
// FIXME alt contexts copying not supported yet
|
||||
if r.node_id == 0 { ret true; }
|
||||
|
||||
// FIXME warn when copy is expensive
|
||||
if ty::type_allows_implicit_copy(cx.tcx, r.ty) {
|
||||
r.given_up = true;
|
||||
cx.copy_map.insert(r.node_id, ());
|
||||
ret false;
|
||||
} else {
|
||||
ret true;
|
||||
}
|
||||
} else { ret true; }
|
||||
}
|
||||
|
||||
fn check_call(cx: &ctx, f: &@ast::expr, args: &[@ast::expr], sc: &scope)
|
||||
-> [restrict] {
|
||||
fn check_call(cx: ctx, f: @ast::expr, args: [@ast::expr], sc: scope) ->
|
||||
[restrict] {
|
||||
let fty = ty::type_autoderef(cx.tcx, ty::expr_ty(cx.tcx, f));
|
||||
let arg_ts = ty::ty_fn_args(cx.tcx, fty);
|
||||
let mut_roots: [{arg: uint, node: node_id}] = [];
|
||||
|
|
@ -193,7 +194,9 @@ fn check_call(cx: &ctx, f: &@ast::expr, args: &[@ast::expr], sc: &scope)
|
|||
let unsafe_t =
|
||||
alt inner_mut(root.ds) { some(t) { some(t) } _ { none } };
|
||||
restricts +=
|
||||
[@{root_var: root_var,
|
||||
[
|
||||
// FIXME kludge
|
||||
@{root_var: root_var,
|
||||
node_id: arg_t.mode == ast::by_mut_ref ? 0 : arg.id,
|
||||
ty: arg_t.ty,
|
||||
local_id: cx.next_local,
|
||||
|
|
@ -201,7 +204,6 @@ fn check_call(cx: &ctx, f: &@ast::expr, args: &[@ast::expr], sc: &scope)
|
|||
unsafe_ty: unsafe_t,
|
||||
depends_on: deps(sc, root_var),
|
||||
mutable ok: valid,
|
||||
// FIXME kludge
|
||||
mutable given_up: arg_t.mode == ast::by_move}];
|
||||
i += 1u;
|
||||
}
|
||||
|
|
@ -230,12 +232,12 @@ fn check_call(cx: &ctx, f: &@ast::expr, args: &[@ast::expr], sc: &scope)
|
|||
for arg_t: ty::arg in arg_ts {
|
||||
let mut_alias = arg_t.mode == ast::by_mut_ref;
|
||||
if i != j &&
|
||||
ty_can_unsafely_include(cx, ty, arg_t.ty, mut_alias) &&
|
||||
cant_copy(cx, r) {
|
||||
cx.tcx.sess.span_err(
|
||||
args[i].span,
|
||||
#fmt["argument %u may alias with argument %u, \
|
||||
which is not immutably rooted", i, j]);
|
||||
ty_can_unsafely_include(cx, ty, arg_t.ty, mut_alias) &&
|
||||
cant_copy(cx, r) {
|
||||
cx.tcx.sess.span_err(args[i].span,
|
||||
#fmt["argument %u may alias with argument %u, \
|
||||
which is not immutably rooted",
|
||||
i, j]);
|
||||
}
|
||||
i += 1u;
|
||||
}
|
||||
|
|
@ -253,8 +255,8 @@ fn check_call(cx: &ctx, f: &@ast::expr, args: &[@ast::expr], sc: &scope)
|
|||
alt r.root_var {
|
||||
some(root) {
|
||||
if node == root && cant_copy(cx, r) {
|
||||
cx.tcx.sess.span_err(
|
||||
args[arg].span, "passing a mutable alias to a \
|
||||
cx.tcx.sess.span_err(args[arg].span,
|
||||
"passing a mutable alias to a \
|
||||
variable that roots another alias");
|
||||
break;
|
||||
}
|
||||
|
|
@ -268,8 +270,8 @@ fn check_call(cx: &ctx, f: &@ast::expr, args: &[@ast::expr], sc: &scope)
|
|||
ret restricts;
|
||||
}
|
||||
|
||||
fn check_alt(cx: &ctx, input: &@ast::expr, arms: &[ast::arm], sc: &scope,
|
||||
v: &vt<scope>) {
|
||||
fn check_alt(cx: ctx, input: @ast::expr, arms: [ast::arm], sc: scope,
|
||||
v: vt<scope>) {
|
||||
v.visit_expr(input, sc, v);
|
||||
let root = expr_root(cx.tcx, input, true);
|
||||
for a: ast::arm in arms {
|
||||
|
|
@ -279,8 +281,9 @@ fn check_alt(cx: &ctx, input: &@ast::expr, arms: &[ast::arm], sc: &scope,
|
|||
let root_var = path_def_id(cx, root.ex);
|
||||
new_sc =
|
||||
@(*sc +
|
||||
[@{root_var: root_var,
|
||||
// FIXME need to use separate restrict for each binding
|
||||
[
|
||||
// FIXME need to use separate restrict for each binding
|
||||
@{root_var: root_var,
|
||||
node_id: 0,
|
||||
ty: ty::mk_int(cx.tcx),
|
||||
local_id: cx.next_local,
|
||||
|
|
@ -295,8 +298,8 @@ fn check_alt(cx: &ctx, input: &@ast::expr, arms: &[ast::arm], sc: &scope,
|
|||
}
|
||||
}
|
||||
|
||||
fn check_for_each(cx: &ctx, local: &@ast::local, call: &@ast::expr,
|
||||
blk: &ast::blk, sc: &scope, v: &vt<scope>) {
|
||||
fn check_for_each(cx: ctx, local: @ast::local, call: @ast::expr,
|
||||
blk: ast::blk, sc: scope, v: vt<scope>) {
|
||||
v.visit_expr(call, sc, v);
|
||||
alt call.node {
|
||||
ast::expr_call(f, args) {
|
||||
|
|
@ -307,8 +310,8 @@ fn check_for_each(cx: &ctx, local: &@ast::local, call: &@ast::expr,
|
|||
}
|
||||
}
|
||||
|
||||
fn check_for(cx: &ctx, local: &@ast::local, seq: &@ast::expr, blk: &ast::blk,
|
||||
sc: &scope, v: &vt<scope>) {
|
||||
fn check_for(cx: ctx, local: @ast::local, seq: @ast::expr, blk: ast::blk,
|
||||
sc: scope, v: vt<scope>) {
|
||||
v.visit_expr(seq, sc, v);
|
||||
let root = expr_root(cx.tcx, seq, false);
|
||||
let unsafe = inner_mut(root.ds);
|
||||
|
|
@ -321,13 +324,12 @@ fn check_for(cx: &ctx, local: &@ast::local, seq: &@ast::expr, blk: &ast::blk,
|
|||
if mt.mut != ast::imm { unsafe = some(seq_t); }
|
||||
elt_t = mt.ty;
|
||||
}
|
||||
ty::ty_str. {
|
||||
elt_t = ty::mk_mach(cx.tcx, ast::ty_u8);
|
||||
}
|
||||
ty::ty_str. { elt_t = ty::mk_mach(cx.tcx, ast::ty_u8); }
|
||||
}
|
||||
let root_var = path_def_id(cx, root.ex);
|
||||
let new_sc =
|
||||
@{root_var: root_var,
|
||||
|
||||
// FIXME reenable when trans knows how to copy for vars
|
||||
node_id: 0, // blk.node.id,
|
||||
ty: elt_t,
|
||||
|
|
@ -341,8 +343,8 @@ fn check_for(cx: &ctx, local: &@ast::local, seq: &@ast::expr, blk: &ast::blk,
|
|||
visit::visit_block(blk, @(*sc + [new_sc]), v);
|
||||
}
|
||||
|
||||
fn check_var(cx: &ctx, ex: &@ast::expr, p: &ast::path, id: ast::node_id,
|
||||
assign: bool, sc: &scope) {
|
||||
fn check_var(cx: ctx, ex: @ast::expr, p: ast::path, id: ast::node_id,
|
||||
assign: bool, sc: scope) {
|
||||
let def = cx.tcx.def_map.get(id);
|
||||
if !def_is_local(def, true) { ret; }
|
||||
let my_defnum = ast_util::def_id_of_def(def).node;
|
||||
|
|
@ -350,6 +352,7 @@ fn check_var(cx: &ctx, ex: &@ast::expr, p: &ast::path, id: ast::node_id,
|
|||
alt cx.local_map.find(my_defnum) { some(local(id)) { id } _ { 0u } };
|
||||
let var_t = ty::expr_ty(cx.tcx, ex);
|
||||
for r: restrict in *sc {
|
||||
|
||||
// excludes variables introduced since the alias was made
|
||||
if my_local_id < r.local_id {
|
||||
alt r.unsafe_ty {
|
||||
|
|
@ -366,7 +369,7 @@ fn check_var(cx: &ctx, ex: &@ast::expr, p: &ast::path, id: ast::node_id,
|
|||
}
|
||||
}
|
||||
|
||||
fn check_lval(cx: &@ctx, dest: &@ast::expr, sc: &scope, v: &vt<scope>) {
|
||||
fn check_lval(cx: @ctx, dest: @ast::expr, sc: scope, v: vt<scope>) {
|
||||
alt dest.node {
|
||||
ast::expr_path(p) {
|
||||
let def = cx.tcx.def_map.get(dest.id);
|
||||
|
|
@ -379,27 +382,29 @@ fn check_lval(cx: &@ctx, dest: &@ast::expr, sc: &scope, v: &vt<scope>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_assign(cx: &@ctx, dest: &@ast::expr, src: &@ast::expr, sc: &scope,
|
||||
v: &vt<scope>) {
|
||||
fn check_assign(cx: @ctx, dest: @ast::expr, src: @ast::expr, sc: scope,
|
||||
v: vt<scope>) {
|
||||
visit_expr(cx, src, sc, v);
|
||||
check_lval(cx, dest, sc, v);
|
||||
}
|
||||
|
||||
fn test_scope(cx: &ctx, sc: &scope, r: &restrict, p: &ast::path) {
|
||||
fn test_scope(cx: ctx, sc: scope, r: restrict, p: ast::path) {
|
||||
let prob = r.ok;
|
||||
for dep: uint in r.depends_on {
|
||||
if prob != valid { break; }
|
||||
prob = sc[dep].ok;
|
||||
}
|
||||
if prob != valid && cant_copy(cx, r) {
|
||||
let msg = alt prob {
|
||||
overwritten(sp, wpt) {
|
||||
{span: sp, msg: "overwriting " + ast_util::path_name(wpt)}
|
||||
}
|
||||
val_taken(sp, vpt) {
|
||||
{span: sp, msg: "taking the value of " + ast_util::path_name(vpt)}
|
||||
}
|
||||
};
|
||||
let msg =
|
||||
alt prob {
|
||||
overwritten(sp, wpt) {
|
||||
{span: sp, msg: "overwriting " + ast_util::path_name(wpt)}
|
||||
}
|
||||
val_taken(sp, vpt) {
|
||||
{span: sp,
|
||||
msg: "taking the value of " + ast_util::path_name(vpt)}
|
||||
}
|
||||
};
|
||||
cx.tcx.sess.span_err(msg.span,
|
||||
msg.msg + " will invalidate alias " +
|
||||
ast_util::path_name(p) +
|
||||
|
|
@ -407,7 +412,7 @@ fn test_scope(cx: &ctx, sc: &scope, r: &restrict, p: &ast::path) {
|
|||
}
|
||||
}
|
||||
|
||||
fn deps(sc: &scope, root: &option::t<node_id>) -> [uint] {
|
||||
fn deps(sc: scope, root: option::t<node_id>) -> [uint] {
|
||||
let result = [];
|
||||
alt root {
|
||||
some(dn) {
|
||||
|
|
@ -422,14 +427,14 @@ fn deps(sc: &scope, root: &option::t<node_id>) -> [uint] {
|
|||
ret result;
|
||||
}
|
||||
|
||||
fn path_def(cx: &ctx, ex: &@ast::expr) -> option::t<ast::def> {
|
||||
fn path_def(cx: ctx, ex: @ast::expr) -> option::t<ast::def> {
|
||||
ret alt ex.node {
|
||||
ast::expr_path(_) { some(cx.tcx.def_map.get(ex.id)) }
|
||||
_ { none }
|
||||
}
|
||||
}
|
||||
|
||||
fn path_def_id(cx: &ctx, ex: &@ast::expr) -> option::t<ast::node_id> {
|
||||
fn path_def_id(cx: ctx, ex: @ast::expr) -> option::t<ast::node_id> {
|
||||
alt ex.node {
|
||||
ast::expr_path(_) {
|
||||
ret some(ast_util::def_id_of_def(cx.tcx.def_map.get(ex.id)).node);
|
||||
|
|
@ -438,12 +443,12 @@ fn path_def_id(cx: &ctx, ex: &@ast::expr) -> option::t<ast::node_id> {
|
|||
}
|
||||
}
|
||||
|
||||
fn ty_can_unsafely_include(cx: &ctx, needle: ty::t, haystack: ty::t,
|
||||
mut: bool) -> bool {
|
||||
fn get_mut(cur: bool, mt: &ty::mt) -> bool {
|
||||
fn ty_can_unsafely_include(cx: ctx, needle: ty::t, haystack: ty::t, mut: bool)
|
||||
-> bool {
|
||||
fn get_mut(cur: bool, mt: ty::mt) -> bool {
|
||||
ret cur || mt.mut != ast::imm;
|
||||
}
|
||||
fn helper(tcx: &ty::ctxt, needle: ty::t, haystack: ty::t, mut: bool) ->
|
||||
fn helper(tcx: ty::ctxt, needle: ty::t, haystack: ty::t, mut: bool) ->
|
||||
bool {
|
||||
if needle == haystack { ret true; }
|
||||
alt ty::struct(tcx, haystack) {
|
||||
|
|
@ -472,6 +477,7 @@ fn ty_can_unsafely_include(cx: &ctx, needle: ty::t, haystack: ty::t,
|
|||
|
||||
|
||||
|
||||
|
||||
// These may contain anything.
|
||||
ty::ty_fn(_, _, _, _, _) {
|
||||
ret true;
|
||||
|
|
@ -480,6 +486,7 @@ fn ty_can_unsafely_include(cx: &ctx, needle: ty::t, haystack: ty::t,
|
|||
|
||||
|
||||
|
||||
|
||||
// A type param may include everything, but can only be
|
||||
// treated as opaque downstream, and is thus safe unless we
|
||||
// saw mutable fields, in which case the whole thing can be
|
||||
|
|
@ -493,7 +500,7 @@ fn ty_can_unsafely_include(cx: &ctx, needle: ty::t, haystack: ty::t,
|
|||
ret helper(cx.tcx, needle, haystack, mut);
|
||||
}
|
||||
|
||||
fn def_is_local(d: &ast::def, objfields_count: bool) -> bool {
|
||||
fn def_is_local(d: ast::def, objfields_count: bool) -> bool {
|
||||
ret alt d {
|
||||
ast::def_local(_) | ast::def_arg(_, _) | ast::def_binding(_) |
|
||||
ast::def_upvar(_, _, _) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ tag ast_node {
|
|||
|
||||
type map = std::map::hashmap<node_id, ast_node>;
|
||||
|
||||
fn map_crate(c: &crate) -> map {
|
||||
fn map_crate(c: crate) -> map {
|
||||
// FIXME: This is using an adapter to convert the smallintmap
|
||||
// interface to the hashmap interface. It would be better to just
|
||||
// convert everything to use the smallintmap.
|
||||
|
|
@ -29,7 +29,7 @@ fn map_crate(c: &crate) -> map {
|
|||
ret map;
|
||||
}
|
||||
|
||||
fn map_item(map: &map, i: &@item, e: &(), v: &vt<()>) {
|
||||
fn map_item(map: map, i: @item, e: (), v: vt<()>) {
|
||||
map.insert(i.id, node_item(i));
|
||||
alt i.node {
|
||||
item_obj(_, _, ctor_id) { map.insert(ctor_id, node_obj_ctor(i)); }
|
||||
|
|
@ -38,19 +38,19 @@ fn map_item(map: &map, i: &@item, e: &(), v: &vt<()>) {
|
|||
visit::visit_item(i, e, v);
|
||||
}
|
||||
|
||||
fn map_native_item(map: &map, i: &@native_item, e: &(), v: &vt<()>) {
|
||||
fn map_native_item(map: map, i: @native_item, e: (), v: vt<()>) {
|
||||
map.insert(i.id, node_native_item(i));
|
||||
visit::visit_native_item(i, e, v);
|
||||
}
|
||||
|
||||
fn map_expr(map: &map, ex: &@expr, e: &(), v: &vt<()>) {
|
||||
fn map_expr(map: map, ex: @expr, e: (), v: vt<()>) {
|
||||
map.insert(ex.id, node_expr(ex));
|
||||
visit::visit_expr(ex, e, v);
|
||||
}
|
||||
|
||||
fn new_smallintmap_int_adapter<@V>() -> std::map::hashmap<int, V> {
|
||||
let key_idx = fn (key: &int) -> uint { key as uint };
|
||||
let idx_key = fn (idx: &uint) -> int { idx as int };
|
||||
let key_idx = fn (key: int) -> uint { key as uint };
|
||||
let idx_key = fn (idx: uint) -> int { idx as int };
|
||||
ret new_smallintmap_adapter(key_idx, idx_key);
|
||||
}
|
||||
|
||||
|
|
@ -60,34 +60,33 @@ fn new_smallintmap_int_adapter<@V>() -> std::map::hashmap<int, V> {
|
|||
// interface.
|
||||
// FIXME: hashmap and smallintmap should support the same interface.
|
||||
fn new_smallintmap_adapter<@K,
|
||||
@V>(key_idx: fn(&K) -> uint,
|
||||
idx_key: fn(&uint) -> K) ->
|
||||
std::map::hashmap<K, V> {
|
||||
@V>(key_idx: fn(K) -> uint, idx_key: fn(uint) -> K)
|
||||
-> std::map::hashmap<K, V> {
|
||||
|
||||
obj adapter<@K,
|
||||
@V>(map: smallintmap::smallintmap<V>,
|
||||
key_idx: fn(&K) -> uint,
|
||||
idx_key: fn(&uint) -> K) {
|
||||
key_idx: fn(K) -> uint,
|
||||
idx_key: fn(uint) -> K) {
|
||||
|
||||
fn size() -> uint { fail }
|
||||
|
||||
fn insert(key: &K, value: &V) -> bool {
|
||||
fn insert(key: K, value: V) -> bool {
|
||||
let exists = smallintmap::contains_key(map, key_idx(key));
|
||||
smallintmap::insert(map, key_idx(key), value);
|
||||
ret !exists;
|
||||
}
|
||||
|
||||
fn contains_key(key: &K) -> bool {
|
||||
fn contains_key(key: K) -> bool {
|
||||
ret smallintmap::contains_key(map, key_idx(key));
|
||||
}
|
||||
|
||||
fn get(key: &K) -> V { ret smallintmap::get(map, key_idx(key)); }
|
||||
fn get(key: K) -> V { ret smallintmap::get(map, key_idx(key)); }
|
||||
|
||||
fn find(key: &K) -> option::t<V> {
|
||||
fn find(key: K) -> option::t<V> {
|
||||
ret smallintmap::find(map, key_idx(key));
|
||||
}
|
||||
|
||||
fn remove(_key: &K) -> option::t<V> { fail }
|
||||
fn remove(_key: K) -> option::t<V> { fail }
|
||||
|
||||
fn rehash() { fail }
|
||||
|
||||
|
|
@ -114,7 +113,7 @@ fn new_smallintmap_adapter<@K,
|
|||
ret adapter(map, key_idx, idx_key);
|
||||
}
|
||||
|
||||
fn node_span(node: &ast_node) -> codemap::span {
|
||||
fn node_span(node: ast_node) -> codemap::span {
|
||||
alt node {
|
||||
node_item(item) { item.span }
|
||||
node_obj_ctor(item) { item.span }
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import syntax::ast_util::variant_def_ids;
|
|||
import syntax::ast_util::dummy_sp;
|
||||
import syntax::visit;
|
||||
|
||||
fn check_crate(tcx: &ty::ctxt, crate: &@crate) {
|
||||
fn check_crate(tcx: ty::ctxt, crate: @crate) {
|
||||
let v =
|
||||
@{visit_expr: bind check_expr(tcx, _, _, _),
|
||||
visit_local: bind check_local(tcx, _, _, _)
|
||||
|
|
@ -12,12 +12,12 @@ fn check_crate(tcx: &ty::ctxt, crate: &@crate) {
|
|||
tcx.sess.abort_if_errors();
|
||||
}
|
||||
|
||||
fn check_expr(tcx: &ty::ctxt, ex: &@expr, s: &(), v: &visit::vt<()>) {
|
||||
fn check_expr(tcx: ty::ctxt, ex: @expr, s: (), v: visit::vt<()>) {
|
||||
visit::visit_expr(ex, s, v);
|
||||
alt ex.node { expr_alt(_, arms) { check_arms(tcx, arms); } _ { } }
|
||||
}
|
||||
|
||||
fn check_arms(tcx: &ty::ctxt, arms: &[arm]) {
|
||||
fn check_arms(tcx: ty::ctxt, arms: [arm]) {
|
||||
let i = 0;
|
||||
for arm: arm in arms {
|
||||
for arm_pat: @pat in arm.pats {
|
||||
|
|
@ -41,8 +41,8 @@ fn check_arms(tcx: &ty::ctxt, arms: &[arm]) {
|
|||
}
|
||||
}
|
||||
|
||||
fn pattern_supersedes(tcx: &ty::ctxt, a: &@pat, b: &@pat) -> bool {
|
||||
fn patterns_supersede(tcx: &ty::ctxt, as: &[@pat], bs: &[@pat]) -> bool {
|
||||
fn pattern_supersedes(tcx: ty::ctxt, a: @pat, b: @pat) -> bool {
|
||||
fn patterns_supersede(tcx: ty::ctxt, as: [@pat], bs: [@pat]) -> bool {
|
||||
let i = 0;
|
||||
for a: @pat in as {
|
||||
if !pattern_supersedes(tcx, a, bs[i]) { ret false; }
|
||||
|
|
@ -50,8 +50,8 @@ fn pattern_supersedes(tcx: &ty::ctxt, a: &@pat, b: &@pat) -> bool {
|
|||
}
|
||||
ret true;
|
||||
}
|
||||
fn field_patterns_supersede(tcx: &ty::ctxt, fas: &[field_pat],
|
||||
fbs: &[field_pat]) -> bool {
|
||||
fn field_patterns_supersede(tcx: ty::ctxt, fas: [field_pat],
|
||||
fbs: [field_pat]) -> bool {
|
||||
let wild = @{id: 0, node: pat_wild, span: dummy_sp()};
|
||||
for fa: field_pat in fas {
|
||||
let pb = wild;
|
||||
|
|
@ -102,7 +102,7 @@ fn pattern_supersedes(tcx: &ty::ctxt, a: &@pat, b: &@pat) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_local(tcx: &ty::ctxt, loc: &@local, s: &(), v: &visit::vt<()>) {
|
||||
fn check_local(tcx: ty::ctxt, loc: @local, s: (), v: visit::vt<()>) {
|
||||
visit::visit_local(loc, s, v);
|
||||
if is_refutable(tcx, loc.node.pat) {
|
||||
tcx.sess.span_err(loc.node.pat.span,
|
||||
|
|
@ -110,7 +110,7 @@ fn check_local(tcx: &ty::ctxt, loc: &@local, s: &(), v: &visit::vt<()>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_refutable(tcx: &ty::ctxt, pat: &@pat) -> bool {
|
||||
fn is_refutable(tcx: ty::ctxt, pat: @pat) -> bool {
|
||||
alt pat.node {
|
||||
pat_wild. | pat_bind(_) { ret false; }
|
||||
pat_lit(_) { ret true; }
|
||||
|
|
|
|||
|
|
@ -29,15 +29,15 @@ type freevar_map = hashmap<ast::node_id, freevar_info>;
|
|||
// Since we want to be able to collect upvars in some arbitrary piece
|
||||
// of the AST, we take a walker function that we invoke with a visitor
|
||||
// in order to start the search.
|
||||
fn collect_freevars(def_map: &resolve::def_map, walker: &fn(&visit::vt<int>))
|
||||
-> freevar_info {
|
||||
fn collect_freevars(def_map: resolve::def_map, walker: fn(visit::vt<int>)) ->
|
||||
freevar_info {
|
||||
let seen = new_int_hash();
|
||||
let refs = @mutable [];
|
||||
|
||||
fn ignore_item(_i: &@ast::item, _depth: &int, _v: &visit::vt<int>) { }
|
||||
fn ignore_item(_i: @ast::item, _depth: int, _v: visit::vt<int>) { }
|
||||
|
||||
let walk_expr =
|
||||
lambda (expr: &@ast::expr, depth: &int, v: &visit::vt<int>) {
|
||||
lambda (expr: @ast::expr, depth: int, v: visit::vt<int>) {
|
||||
alt expr.node {
|
||||
ast::expr_fn(f) {
|
||||
if f.proto == ast::proto_block ||
|
||||
|
|
@ -81,28 +81,26 @@ fn collect_freevars(def_map: &resolve::def_map, walker: &fn(&visit::vt<int>))
|
|||
// efficient as it fully recomputes the free variables at every
|
||||
// node of interest rather than building up the free variables in
|
||||
// one pass. This could be improved upon if it turns out to matter.
|
||||
fn annotate_freevars(def_map: &resolve::def_map, crate: &@ast::crate) ->
|
||||
fn annotate_freevars(def_map: resolve::def_map, crate: @ast::crate) ->
|
||||
freevar_map {
|
||||
let freevars = new_int_hash();
|
||||
|
||||
let walk_fn =
|
||||
lambda (f: &ast::_fn, tps: &[ast::ty_param], sp: &span,
|
||||
i: &ast::fn_ident, nid: ast::node_id) {
|
||||
lambda (f: ast::_fn, tps: [ast::ty_param], sp: span, i: ast::fn_ident,
|
||||
nid: ast::node_id) {
|
||||
let start_walk =
|
||||
lambda (v: &visit::vt<int>) {
|
||||
lambda (v: visit::vt<int>) {
|
||||
v.visit_fn(f, tps, sp, i, nid, 1, v);
|
||||
};
|
||||
let vars = collect_freevars(def_map, start_walk);
|
||||
freevars.insert(nid, vars);
|
||||
};
|
||||
let walk_expr =
|
||||
lambda (expr: &@ast::expr) {
|
||||
lambda (expr: @ast::expr) {
|
||||
alt expr.node {
|
||||
ast::expr_for_each(local, _, body) {
|
||||
let start_walk =
|
||||
lambda (v: &visit::vt<int>) {
|
||||
v.visit_block(body, 1, v);
|
||||
};
|
||||
lambda (v: visit::vt<int>) { v.visit_block(body, 1, v); };
|
||||
let vars = collect_freevars(def_map, start_walk);
|
||||
freevars.insert(body.node.id, vars);
|
||||
}
|
||||
|
|
@ -118,13 +116,13 @@ fn annotate_freevars(def_map: &resolve::def_map, crate: &@ast::crate) ->
|
|||
ret freevars;
|
||||
}
|
||||
|
||||
fn get_freevars(tcx: &ty::ctxt, fid: ast::node_id) -> freevar_info {
|
||||
fn get_freevars(tcx: ty::ctxt, fid: ast::node_id) -> freevar_info {
|
||||
alt tcx.freevars.find(fid) {
|
||||
none. { fail "get_freevars: " + int::str(fid) + " has no freevars"; }
|
||||
some(d) { ret d; }
|
||||
}
|
||||
}
|
||||
fn has_freevars(tcx: &ty::ctxt, fid: ast::node_id) -> bool {
|
||||
fn has_freevars(tcx: ty::ctxt, fid: ast::node_id) -> bool {
|
||||
ret std::vec::len(*get_freevars(tcx, fid)) != 0u;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ type ctxt = @{mutable next_tydesc_num: uint};
|
|||
|
||||
fn mk_ctxt() -> ctxt { ret @{mutable next_tydesc_num: 0u}; }
|
||||
|
||||
fn add_global(ccx: &@crate_ctxt, llval: ValueRef, name: &str) -> ValueRef {
|
||||
fn add_global(ccx: @crate_ctxt, llval: ValueRef, name: str) -> ValueRef {
|
||||
let llglobal =
|
||||
str::as_buf(name,
|
||||
{|buf|
|
||||
|
|
@ -32,7 +32,7 @@ fn add_global(ccx: &@crate_ctxt, llval: ValueRef, name: &str) -> ValueRef {
|
|||
ret llglobal;
|
||||
}
|
||||
|
||||
fn add_gc_root(cx: &@block_ctxt, llval: ValueRef, ty: ty::t) -> @block_ctxt {
|
||||
fn add_gc_root(cx: @block_ctxt, llval: ValueRef, ty: ty::t) -> @block_ctxt {
|
||||
let bcx = cx;
|
||||
if !type_is_gc_relevant(bcx_tcx(cx), ty) ||
|
||||
ty::type_has_dynamic_size(bcx_tcx(cx), ty) {
|
||||
|
|
@ -102,7 +102,7 @@ fn add_gc_root(cx: &@block_ctxt, llval: ValueRef, ty: ty::t) -> @block_ctxt {
|
|||
ret bcx;
|
||||
}
|
||||
|
||||
fn type_is_gc_relevant(cx: &ty::ctxt, ty: ty::t) -> bool {
|
||||
fn type_is_gc_relevant(cx: ty::ctxt, ty: ty::t) -> bool {
|
||||
alt ty::struct(cx, ty) {
|
||||
ty::ty_nil. | ty::ty_bot. | ty::ty_bool. | ty::ty_int. | ty::ty_float. |
|
||||
ty::ty_uint. | ty::ty_machine(_) | ty::ty_char. | ty::ty_str. |
|
||||
|
|
@ -113,6 +113,7 @@ fn type_is_gc_relevant(cx: &ty::ctxt, ty: ty::t) -> bool {
|
|||
|
||||
|
||||
|
||||
|
||||
ty::ty_rec(fields) {
|
||||
for f in fields { if type_is_gc_relevant(cx, f.mt.ty) { ret true; } }
|
||||
ret false;
|
||||
|
|
@ -124,6 +125,7 @@ fn type_is_gc_relevant(cx: &ty::ctxt, ty: ty::t) -> bool {
|
|||
|
||||
|
||||
|
||||
|
||||
ty::ty_tag(did, tps) {
|
||||
let variants = ty::tag_variants(cx, did);
|
||||
for variant in variants {
|
||||
|
|
@ -137,6 +139,7 @@ fn type_is_gc_relevant(cx: &ty::ctxt, ty: ty::t) -> bool {
|
|||
|
||||
|
||||
|
||||
|
||||
ty::ty_vec(tm) {
|
||||
ret type_is_gc_relevant(cx, tm.ty);
|
||||
}
|
||||
|
|
@ -144,6 +147,7 @@ fn type_is_gc_relevant(cx: &ty::ctxt, ty: ty::t) -> bool {
|
|||
|
||||
|
||||
|
||||
|
||||
ty::ty_box(_) | ty::ty_uniq(_) | ty::ty_fn(_, _, _, _, _) |
|
||||
ty::ty_native_fn(_, _, _) | ty::ty_obj(_) | ty::ty_param(_, _) |
|
||||
ty::ty_res(_, _, _) {
|
||||
|
|
@ -152,6 +156,7 @@ fn type_is_gc_relevant(cx: &ty::ctxt, ty: ty::t) -> bool {
|
|||
|
||||
|
||||
|
||||
|
||||
ty::ty_var(_) {
|
||||
fail "ty_var in type_is_gc_relevant";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,15 +104,15 @@ fn kind_to_str(k: kind) -> str {
|
|||
}
|
||||
}
|
||||
|
||||
fn type_and_kind(tcx: &ty::ctxt, e: &@ast::expr) ->
|
||||
fn type_and_kind(tcx: ty::ctxt, e: @ast::expr) ->
|
||||
{ty: ty::t, kind: ast::kind} {
|
||||
let t = ty::expr_ty(tcx, e);
|
||||
let k = ty::type_kind(tcx, t);
|
||||
{ty: t, kind: k}
|
||||
}
|
||||
|
||||
fn need_expr_kind(tcx: &ty::ctxt, e: &@ast::expr, k_need: ast::kind,
|
||||
descr: &str) {
|
||||
fn need_expr_kind(tcx: ty::ctxt, e: @ast::expr, k_need: ast::kind,
|
||||
descr: str) {
|
||||
let tk = type_and_kind(tcx, e);
|
||||
log #fmt["for %s: want %s type, got %s type %s", descr,
|
||||
kind_to_str(k_need), kind_to_str(tk.kind),
|
||||
|
|
@ -127,13 +127,12 @@ fn need_expr_kind(tcx: &ty::ctxt, e: &@ast::expr, k_need: ast::kind,
|
|||
}
|
||||
}
|
||||
|
||||
fn need_shared_lhs_rhs(tcx: &ty::ctxt, a: &@ast::expr, b: &@ast::expr,
|
||||
op: &str) {
|
||||
fn need_shared_lhs_rhs(tcx: ty::ctxt, a: @ast::expr, b: @ast::expr, op: str) {
|
||||
need_expr_kind(tcx, a, ast::kind_shared, op + " lhs");
|
||||
need_expr_kind(tcx, b, ast::kind_shared, op + " rhs");
|
||||
}
|
||||
|
||||
fn check_expr(tcx: &ty::ctxt, e: &@ast::expr) {
|
||||
fn check_expr(tcx: ty::ctxt, e: @ast::expr) {
|
||||
alt e.node {
|
||||
ast::expr_move(a, b) { need_shared_lhs_rhs(tcx, a, b, "<-"); }
|
||||
ast::expr_assign(a, b) { need_shared_lhs_rhs(tcx, a, b, "="); }
|
||||
|
|
@ -182,7 +181,7 @@ fn check_expr(tcx: &ty::ctxt, e: &@ast::expr) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_crate(tcx: &ty::ctxt, crate: &@ast::crate) {
|
||||
fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
|
||||
let visit =
|
||||
visit::mk_simple_visitor(@{visit_expr: bind check_expr(tcx, _)
|
||||
with *visit::default_simple_visitor()});
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ type deref = @{mut: bool, kind: deref_t, outer_t: ty::t};
|
|||
// vec of dereferences that were used on this root. Note that, in this vec,
|
||||
// the inner derefs come in front, so foo.bar[1] becomes rec(ex=foo,
|
||||
// ds=[index,field])
|
||||
fn expr_root(tcx: &ty::ctxt, ex: @expr, autoderef: bool) ->
|
||||
fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
|
||||
{ex: @expr, ds: @[deref]} {
|
||||
fn maybe_auto_unbox(tcx: &ty::ctxt, t: ty::t) -> {t: ty::t, ds: [deref]} {
|
||||
fn maybe_auto_unbox(tcx: ty::ctxt, t: ty::t) -> {t: ty::t, ds: [deref]} {
|
||||
let ds = [];
|
||||
while true {
|
||||
alt ty::struct(tcx, t) {
|
||||
|
|
@ -68,14 +68,13 @@ fn expr_root(tcx: &ty::ctxt, ex: @expr, autoderef: bool) ->
|
|||
let auto_unbox = maybe_auto_unbox(tcx, ty::expr_ty(tcx, base));
|
||||
alt ty::struct(tcx, auto_unbox.t) {
|
||||
ty::ty_vec(mt) {
|
||||
ds += [@{mut: mt.mut != imm,
|
||||
kind: index,
|
||||
outer_t: auto_unbox.t}];
|
||||
ds +=
|
||||
[@{mut: mt.mut != imm,
|
||||
kind: index,
|
||||
outer_t: auto_unbox.t}];
|
||||
}
|
||||
ty::ty_str. {
|
||||
ds += [@{mut: false,
|
||||
kind: index,
|
||||
outer_t: auto_unbox.t}];
|
||||
ds += [@{mut: false, kind: index, outer_t: auto_unbox.t}];
|
||||
}
|
||||
}
|
||||
ds += auto_unbox.ds;
|
||||
|
|
@ -106,12 +105,12 @@ fn expr_root(tcx: &ty::ctxt, ex: @expr, autoderef: bool) ->
|
|||
ret {ex: ex, ds: @ds};
|
||||
}
|
||||
|
||||
fn mut_field(ds: &@[deref]) -> bool {
|
||||
fn mut_field(ds: @[deref]) -> bool {
|
||||
for d: deref in *ds { if d.mut { ret true; } }
|
||||
ret false;
|
||||
}
|
||||
|
||||
fn inner_mut(ds: &@[deref]) -> option::t<ty::t> {
|
||||
fn inner_mut(ds: @[deref]) -> option::t<ty::t> {
|
||||
for d: deref in *ds { if d.mut { ret some(d.outer_t); } }
|
||||
ret none;
|
||||
}
|
||||
|
|
@ -121,7 +120,7 @@ fn inner_mut(ds: &@[deref]) -> option::t<ty::t> {
|
|||
type mut_map = std::map::hashmap<node_id, ()>;
|
||||
type ctx = {tcx: ty::ctxt, mut_map: mut_map};
|
||||
|
||||
fn check_crate(tcx: ty::ctxt, crate: &@crate) -> mut_map {
|
||||
fn check_crate(tcx: ty::ctxt, crate: @crate) -> mut_map {
|
||||
let cx = @{tcx: tcx, mut_map: std::map::new_int_hash()};
|
||||
let v =
|
||||
@{visit_expr: bind visit_expr(cx, _, _, _),
|
||||
|
|
@ -133,7 +132,7 @@ fn check_crate(tcx: ty::ctxt, crate: &@crate) -> mut_map {
|
|||
|
||||
tag msg { msg_assign; msg_move_out; msg_mut_alias; }
|
||||
|
||||
fn mk_err(cx: &@ctx, span: &syntax::codemap::span, msg: msg, name: &str) {
|
||||
fn mk_err(cx: @ctx, span: syntax::codemap::span, msg: msg, name: str) {
|
||||
cx.tcx.sess.span_err(span,
|
||||
alt msg {
|
||||
msg_assign. { "assigning to " + name }
|
||||
|
|
@ -144,7 +143,7 @@ fn mk_err(cx: &@ctx, span: &syntax::codemap::span, msg: msg, name: &str) {
|
|||
});
|
||||
}
|
||||
|
||||
fn visit_decl(cx: &@ctx, d: &@decl, e: &(), v: &visit::vt<()>) {
|
||||
fn visit_decl(cx: @ctx, d: @decl, e: (), v: visit::vt<()>) {
|
||||
visit::visit_decl(d, e, v);
|
||||
alt d.node {
|
||||
decl_local(locs) {
|
||||
|
|
@ -161,7 +160,7 @@ fn visit_decl(cx: &@ctx, d: &@decl, e: &(), v: &visit::vt<()>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_expr(cx: &@ctx, ex: &@expr, e: &(), v: &visit::vt<()>) {
|
||||
fn visit_expr(cx: @ctx, ex: @expr, e: (), v: visit::vt<()>) {
|
||||
alt ex.node {
|
||||
expr_call(f, args) { check_call(cx, f, args); }
|
||||
expr_swap(lhs, rhs) {
|
||||
|
|
@ -180,7 +179,7 @@ fn visit_expr(cx: &@ctx, ex: &@expr, e: &(), v: &visit::vt<()>) {
|
|||
visit::visit_expr(ex, e, v);
|
||||
}
|
||||
|
||||
fn check_lval(cx: &@ctx, dest: &@expr, msg: msg) {
|
||||
fn check_lval(cx: @ctx, dest: @expr, msg: msg) {
|
||||
alt dest.node {
|
||||
expr_path(p) {
|
||||
let def = cx.tcx.def_map.get(dest.id);
|
||||
|
|
@ -193,9 +192,7 @@ fn check_lval(cx: &@ctx, dest: &@expr, msg: msg) {
|
|||
_ {
|
||||
let root = expr_root(cx.tcx, dest, false);
|
||||
if vec::len(*root.ds) == 0u {
|
||||
if msg == msg_assign {
|
||||
mk_err(cx, dest.span, msg, "non-lvalue");
|
||||
}
|
||||
if msg == msg_assign { mk_err(cx, dest.span, msg, "non-lvalue"); }
|
||||
} else if !root.ds[0].mut {
|
||||
let name =
|
||||
alt root.ds[0].kind {
|
||||
|
|
@ -209,7 +206,7 @@ fn check_lval(cx: &@ctx, dest: &@expr, msg: msg) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_move_rhs(cx: &@ctx, src: &@expr) {
|
||||
fn check_move_rhs(cx: @ctx, src: @expr) {
|
||||
alt src.node {
|
||||
expr_path(p) {
|
||||
alt cx.tcx.def_map.get(src.id) {
|
||||
|
|
@ -231,20 +228,18 @@ fn check_move_rhs(cx: &@ctx, src: &@expr) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_call(cx: &@ctx, f: &@expr, args: &[@expr]) {
|
||||
fn check_call(cx: @ctx, f: @expr, args: [@expr]) {
|
||||
let arg_ts =
|
||||
ty::ty_fn_args(cx.tcx,
|
||||
ty::type_autoderef(cx.tcx, ty::expr_ty(cx.tcx, f)));
|
||||
let i = 0u;
|
||||
for arg_t: ty::arg in arg_ts {
|
||||
if arg_t.mode != by_ref {
|
||||
check_lval(cx, args[i], msg_mut_alias);
|
||||
}
|
||||
if arg_t.mode != by_ref { check_lval(cx, args[i], msg_mut_alias); }
|
||||
i += 1u;
|
||||
}
|
||||
}
|
||||
|
||||
fn is_immutable_def(def: &def) -> option::t<str> {
|
||||
fn is_immutable_def(def: def) -> option::t<str> {
|
||||
alt def {
|
||||
def_fn(_, _) | def_mod(_) | def_native_mod(_) | def_const(_) |
|
||||
def_use(_) {
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ type ext_hash = hashmap<{did: def_id, ident: str, ns: namespace}, def>;
|
|||
|
||||
fn new_ext_hash() -> ext_hash {
|
||||
type key = {did: def_id, ident: str, ns: namespace};
|
||||
fn hash(v: &key) -> uint {
|
||||
fn hash(v: key) -> uint {
|
||||
ret str::hash(v.ident) + util::common::hash_def(v.did) +
|
||||
alt v.ns {
|
||||
ns_value. { 1u }
|
||||
|
|
@ -86,7 +86,7 @@ fn new_ext_hash() -> ext_hash {
|
|||
ns_module. { 3u }
|
||||
};
|
||||
}
|
||||
fn eq(v1: &key, v2: &key) -> bool {
|
||||
fn eq(v1: key, v2: key) -> bool {
|
||||
ret util::common::def_eq(v1.did, v2.did) &&
|
||||
str::eq(v1.ident, v2.ident) && v1.ns == v2.ns;
|
||||
}
|
||||
|
|
@ -137,7 +137,7 @@ tag dir { inside; outside; }
|
|||
|
||||
tag namespace { ns_value; ns_type; ns_module; }
|
||||
|
||||
fn resolve_crate(sess: session, amap: &ast_map::map, crate: @ast::crate) ->
|
||||
fn resolve_crate(sess: session, amap: ast_map::map, crate: @ast::crate) ->
|
||||
{def_map: def_map, ext_map: ext_map} {
|
||||
let e =
|
||||
@{cstore: sess.get_cstore(),
|
||||
|
|
@ -160,7 +160,7 @@ fn resolve_crate(sess: session, amap: &ast_map::map, crate: @ast::crate) ->
|
|||
|
||||
// Locate all modules and imports and index them, so that the next passes can
|
||||
// resolve through them.
|
||||
fn map_crate(e: &@env, c: &@ast::crate) {
|
||||
fn map_crate(e: @env, c: @ast::crate) {
|
||||
// First, find all the modules, and index the names that they contain
|
||||
|
||||
let v_map_mod =
|
||||
|
|
@ -175,7 +175,7 @@ fn map_crate(e: &@env, c: &@ast::crate) {
|
|||
index: index_mod(c.node.module),
|
||||
mutable glob_imports: [],
|
||||
glob_imported_names: new_str_hash::<import_state>()});
|
||||
fn index_vi(e: @env, i: &@ast::view_item, sc: &scopes, _v: &vt<scopes>) {
|
||||
fn index_vi(e: @env, i: @ast::view_item, sc: scopes, _v: vt<scopes>) {
|
||||
alt i.node {
|
||||
ast::view_item_import(name, ids, id) {
|
||||
e.imports.insert(id, todo(id, name, ids, i.span, sc));
|
||||
|
|
@ -191,7 +191,7 @@ fn map_crate(e: &@env, c: &@ast::crate) {
|
|||
_ { }
|
||||
}
|
||||
}
|
||||
fn index_i(e: @env, i: &@ast::item, sc: &scopes, v: &vt<scopes>) {
|
||||
fn index_i(e: @env, i: @ast::item, sc: scopes, v: vt<scopes>) {
|
||||
visit_item_with_scope(i, sc, v);
|
||||
alt i.node {
|
||||
ast::item_mod(md) {
|
||||
|
|
@ -221,8 +221,7 @@ fn map_crate(e: &@env, c: &@ast::crate) {
|
|||
with *visit::default_visitor::<scopes>()};
|
||||
visit::visit_crate(*c, cons(scope_crate, @nil),
|
||||
visit::mk_vt(v_link_glob));
|
||||
fn link_glob(e: @env, vi: &@ast::view_item, sc: &scopes,
|
||||
_v: &vt<scopes>) {
|
||||
fn link_glob(e: @env, vi: @ast::view_item, sc: scopes, _v: vt<scopes>) {
|
||||
fn find_mod(e: @env, sc: scopes) -> @indexed_mod {
|
||||
alt sc {
|
||||
cons(scope_item(i), tl) {
|
||||
|
|
@ -243,6 +242,7 @@ fn map_crate(e: &@env, c: &@ast::crate) {
|
|||
|
||||
|
||||
|
||||
|
||||
//if it really is a glob import, that is
|
||||
ast::view_item_import_glob(path, _) {
|
||||
let imp = follow_import(*e, sc, path, vi.span);
|
||||
|
|
@ -256,7 +256,7 @@ fn map_crate(e: &@env, c: &@ast::crate) {
|
|||
}
|
||||
}
|
||||
|
||||
fn resolve_imports(e: &env) {
|
||||
fn resolve_imports(e: env) {
|
||||
for each it: @{key: ast::node_id, val: import_state} in e.imports.items()
|
||||
{
|
||||
alt it.val {
|
||||
|
|
@ -269,7 +269,7 @@ fn resolve_imports(e: &env) {
|
|||
e.sess.abort_if_errors();
|
||||
}
|
||||
|
||||
fn resolve_names(e: &@env, c: &@ast::crate) {
|
||||
fn resolve_names(e: @env, c: @ast::crate) {
|
||||
let v =
|
||||
@{visit_native_item: visit_native_item_with_scope,
|
||||
visit_item: visit_item_with_scope,
|
||||
|
|
@ -285,7 +285,7 @@ fn resolve_names(e: &@env, c: &@ast::crate) {
|
|||
visit::visit_crate(*c, cons(scope_crate, @nil), visit::mk_vt(v));
|
||||
e.sess.abort_if_errors();
|
||||
|
||||
fn walk_expr(e: @env, exp: &@ast::expr, sc: &scopes, v: &vt<scopes>) {
|
||||
fn walk_expr(e: @env, exp: @ast::expr, sc: scopes, v: vt<scopes>) {
|
||||
visit_expr_with_scope(exp, sc, v);
|
||||
alt exp.node {
|
||||
ast::expr_path(p) {
|
||||
|
|
@ -296,7 +296,7 @@ fn resolve_names(e: &@env, c: &@ast::crate) {
|
|||
_ { }
|
||||
}
|
||||
}
|
||||
fn walk_ty(e: @env, t: &@ast::ty, sc: &scopes, v: &vt<scopes>) {
|
||||
fn walk_ty(e: @env, t: @ast::ty, sc: scopes, v: vt<scopes>) {
|
||||
visit::visit_ty(t, sc, v);
|
||||
alt t.node {
|
||||
ast::ty_path(p, id) {
|
||||
|
|
@ -306,11 +306,11 @@ fn resolve_names(e: &@env, c: &@ast::crate) {
|
|||
_ { }
|
||||
}
|
||||
}
|
||||
fn walk_constr(e: @env, p: &ast::path, sp: &span, id: node_id,
|
||||
sc: &scopes, _v: &vt<scopes>) {
|
||||
fn walk_constr(e: @env, p: ast::path, sp: span, id: node_id, sc: scopes,
|
||||
_v: vt<scopes>) {
|
||||
maybe_insert(e, id, lookup_path_strict(*e, sc, sp, p.node, ns_value));
|
||||
}
|
||||
fn walk_pat(e: &@env, pat: &@ast::pat, sc: &scopes, v: &vt<scopes>) {
|
||||
fn walk_pat(e: @env, pat: @ast::pat, sc: scopes, v: vt<scopes>) {
|
||||
visit::visit_pat(pat, sc, v);
|
||||
alt pat.node {
|
||||
ast::pat_tag(p, _) {
|
||||
|
|
@ -337,18 +337,18 @@ fn resolve_names(e: &@env, c: &@ast::crate) {
|
|||
|
||||
|
||||
// Visit helper functions
|
||||
fn visit_item_with_scope(i: &@ast::item, sc: &scopes, v: &vt<scopes>) {
|
||||
fn visit_item_with_scope(i: @ast::item, sc: scopes, v: vt<scopes>) {
|
||||
visit::visit_item(i, cons(scope_item(i), @sc), v);
|
||||
}
|
||||
|
||||
fn visit_native_item_with_scope(ni: &@ast::native_item, sc: &scopes,
|
||||
v: &vt<scopes>) {
|
||||
fn visit_native_item_with_scope(ni: @ast::native_item, sc: scopes,
|
||||
v: vt<scopes>) {
|
||||
visit::visit_native_item(ni, cons(scope_native_item(ni), @sc), v);
|
||||
}
|
||||
|
||||
fn visit_fn_with_scope(e: &@env, f: &ast::_fn, tp: &[ast::ty_param],
|
||||
sp: &span, name: &fn_ident, id: node_id, sc: &scopes,
|
||||
v: &vt<scopes>) {
|
||||
fn visit_fn_with_scope(e: @env, f: ast::_fn, tp: [ast::ty_param], sp: span,
|
||||
name: fn_ident, id: node_id, sc: scopes,
|
||||
v: vt<scopes>) {
|
||||
// is this a main fn declaration?
|
||||
alt name {
|
||||
some(nm) {
|
||||
|
|
@ -369,7 +369,7 @@ fn visit_fn_with_scope(e: &@env, f: &ast::_fn, tp: &[ast::ty_param],
|
|||
cons(scope_fn(f.decl, f.proto, tp), @sc), v);
|
||||
}
|
||||
|
||||
fn visit_block_with_scope(b: &ast::blk, sc: &scopes, v: &vt<scopes>) {
|
||||
fn visit_block_with_scope(b: ast::blk, sc: scopes, v: vt<scopes>) {
|
||||
let pos = @mutable 0u, loc = @mutable 0u;
|
||||
let block_sc = cons(scope_block(b, pos, loc), @sc);
|
||||
for stmt in b.node.stmts {
|
||||
|
|
@ -380,7 +380,7 @@ fn visit_block_with_scope(b: &ast::blk, sc: &scopes, v: &vt<scopes>) {
|
|||
visit::visit_expr_opt(b.node.expr, block_sc, v);
|
||||
}
|
||||
|
||||
fn visit_decl_with_scope(d: &@decl, sc: &scopes, v: &vt<scopes>) {
|
||||
fn visit_decl_with_scope(d: @decl, sc: scopes, v: vt<scopes>) {
|
||||
let loc_pos =
|
||||
alt list::car(sc) {
|
||||
scope_block(_, _, pos) { pos }
|
||||
|
|
@ -394,14 +394,14 @@ fn visit_decl_with_scope(d: &@decl, sc: &scopes, v: &vt<scopes>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_arm_with_scope(a: &ast::arm, sc: &scopes, v: &vt<scopes>) {
|
||||
fn visit_arm_with_scope(a: ast::arm, sc: scopes, v: vt<scopes>) {
|
||||
for p: @pat in a.pats { v.visit_pat(p, sc, v); }
|
||||
let sc_inner = cons(scope_arm(a), @sc);
|
||||
visit::visit_expr_opt(a.guard, sc_inner, v);
|
||||
v.visit_block(a.body, sc_inner, v);
|
||||
}
|
||||
|
||||
fn visit_expr_with_scope(x: &@ast::expr, sc: &scopes, v: &vt<scopes>) {
|
||||
fn visit_expr_with_scope(x: @ast::expr, sc: scopes, v: vt<scopes>) {
|
||||
alt x.node {
|
||||
ast::expr_for(decl, coll, blk) | ast::expr_for_each(decl, coll, blk) {
|
||||
let f_e = alt x.node { expr_for_each(_, _, _) { true } _ { false } };
|
||||
|
|
@ -414,7 +414,7 @@ fn visit_expr_with_scope(x: &@ast::expr, sc: &scopes, v: &vt<scopes>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn follow_import(e: &env, sc: &scopes, path: &[ident], sp: &span) ->
|
||||
fn follow_import(e: env, sc: scopes, path: [ident], sp: span) ->
|
||||
option::t<def> {
|
||||
let path_len = vec::len(path);
|
||||
let dcur = lookup_in_scope_strict(e, sc, sp, path[0], ns_module);
|
||||
|
|
@ -439,7 +439,7 @@ fn follow_import(e: &env, sc: &scopes, path: &[ident], sp: &span) ->
|
|||
} else { ret none; }
|
||||
}
|
||||
|
||||
fn resolve_constr(e: @env, c: &@ast::constr, sc: &scopes, _v: &vt<scopes>) {
|
||||
fn resolve_constr(e: @env, c: @ast::constr, sc: scopes, _v: vt<scopes>) {
|
||||
let new_def =
|
||||
lookup_path_strict(*e, sc, c.span, c.node.path.node, ns_value);
|
||||
if option::is_some(new_def) {
|
||||
|
|
@ -457,8 +457,8 @@ fn resolve_constr(e: @env, c: &@ast::constr, sc: &scopes, _v: &vt<scopes>) {
|
|||
}
|
||||
|
||||
// Import resolution
|
||||
fn resolve_import(e: &env, defid: ast::def_id, name: &ast::ident,
|
||||
ids: &[ast::ident], sp: &codemap::span, sc_in: &scopes) {
|
||||
fn resolve_import(e: env, defid: ast::def_id, name: ast::ident,
|
||||
ids: [ast::ident], sp: codemap::span, sc_in: scopes) {
|
||||
e.imports.insert(defid.node, resolving(sp));
|
||||
let n_idents = vec::len(ids);
|
||||
let end_id = ids[n_idents - 1u];
|
||||
|
|
@ -507,9 +507,9 @@ fn resolve_import(e: &env, defid: ast::def_id, name: &ast::ident,
|
|||
}
|
||||
}
|
||||
}
|
||||
fn register(e: &env, defid: def_id, sp: &span, name: &ident, sc: &scopes,
|
||||
val: &option::t<def>, typ: &option::t<def>,
|
||||
md: &option::t<def>) {
|
||||
fn register(e: env, defid: def_id, sp: span, name: ident, sc: scopes,
|
||||
val: option::t<def>, typ: option::t<def>,
|
||||
md: option::t<def>) {
|
||||
if is_none(val) && is_none(typ) && is_none(md) {
|
||||
unresolved_err(e, sc, sp, name, "import");
|
||||
} else { e.imports.insert(defid.node, resolved(val, typ, md)); }
|
||||
|
|
@ -539,7 +539,7 @@ fn ns_name(ns: namespace) -> str {
|
|||
}
|
||||
}
|
||||
|
||||
fn unresolved_err(e: &env, sc: &scopes, sp: &span, name: &ident, kind: &str) {
|
||||
fn unresolved_err(e: env, sc: scopes, sp: span, name: ident, kind: str) {
|
||||
fn find_fn_or_mod_scope(sc: scopes) -> scope {
|
||||
while true {
|
||||
alt sc {
|
||||
|
|
@ -564,16 +564,16 @@ fn unresolved_err(e: &env, sc: &scopes, sp: &span, name: &ident, kind: &str) {
|
|||
e.sess.span_err(sp, mk_unresolved_msg(name, kind));
|
||||
}
|
||||
|
||||
fn unresolved_fatal(e: &env, sp: &span, id: &ident, kind: &str) -> ! {
|
||||
fn unresolved_fatal(e: env, sp: span, id: ident, kind: str) -> ! {
|
||||
e.sess.span_fatal(sp, mk_unresolved_msg(id, kind));
|
||||
}
|
||||
|
||||
fn mk_unresolved_msg(id: &ident, kind: &str) -> str {
|
||||
fn mk_unresolved_msg(id: ident, kind: str) -> str {
|
||||
ret #fmt["unresolved %s: %s", kind, id];
|
||||
}
|
||||
|
||||
// Lookup helpers
|
||||
fn lookup_path_strict(e: &env, sc: &scopes, sp: &span, pth: &ast::path_,
|
||||
fn lookup_path_strict(e: env, sc: scopes, sp: span, pth: ast::path_,
|
||||
ns: namespace) -> option::t<def> {
|
||||
let n_idents = vec::len(pth.idents);
|
||||
let headns = if n_idents == 1u { ns } else { ns_module };
|
||||
|
|
@ -597,7 +597,7 @@ fn lookup_path_strict(e: &env, sc: &scopes, sp: &span, pth: &ast::path_,
|
|||
ret dcur;
|
||||
}
|
||||
|
||||
fn lookup_in_scope_strict(e: &env, sc: scopes, sp: &span, name: &ident,
|
||||
fn lookup_in_scope_strict(e: env, sc: scopes, sp: span, name: ident,
|
||||
ns: namespace) -> option::t<def> {
|
||||
alt lookup_in_scope(e, sc, sp, name, ns) {
|
||||
none. { unresolved_err(e, sc, sp, name, ns_name(ns)); ret none; }
|
||||
|
|
@ -605,7 +605,7 @@ fn lookup_in_scope_strict(e: &env, sc: scopes, sp: &span, name: &ident,
|
|||
}
|
||||
}
|
||||
|
||||
fn scope_is_fn(sc: &scope) -> bool {
|
||||
fn scope_is_fn(sc: scope) -> bool {
|
||||
ret alt sc {
|
||||
scope_fn(_, ast::proto_iter., _) | scope_fn(_, ast::proto_fn., _) |
|
||||
scope_native_item(_) {
|
||||
|
|
@ -615,7 +615,7 @@ fn scope_is_fn(sc: &scope) -> bool {
|
|||
};
|
||||
}
|
||||
|
||||
fn scope_closes(sc: &scope) -> option::t<bool> {
|
||||
fn scope_closes(sc: scope) -> option::t<bool> {
|
||||
alt sc {
|
||||
scope_fn(_, ast::proto_block., _) | scope_loop(_, true) { some(true) }
|
||||
scope_fn(_, ast::proto_closure., _) { some(false) }
|
||||
|
|
@ -623,7 +623,7 @@ fn scope_closes(sc: &scope) -> option::t<bool> {
|
|||
}
|
||||
}
|
||||
|
||||
fn def_is_local(d: &def) -> bool {
|
||||
fn def_is_local(d: def) -> bool {
|
||||
ret alt d {
|
||||
ast::def_arg(_, _) | ast::def_local(_) | ast::def_binding(_) |
|
||||
ast::def_upvar(_, _, _) {
|
||||
|
|
@ -633,17 +633,17 @@ fn def_is_local(d: &def) -> bool {
|
|||
};
|
||||
}
|
||||
|
||||
fn def_is_obj_field(d: &def) -> bool {
|
||||
fn def_is_obj_field(d: def) -> bool {
|
||||
ret alt d { ast::def_obj_field(_, _) { true } _ { false } };
|
||||
}
|
||||
|
||||
fn def_is_ty_arg(d: &def) -> bool {
|
||||
fn def_is_ty_arg(d: def) -> bool {
|
||||
ret alt d { ast::def_ty_arg(_, _) { true } _ { false } };
|
||||
}
|
||||
|
||||
fn lookup_in_scope(e: &env, sc: scopes, sp: &span, name: &ident,
|
||||
ns: namespace) -> option::t<def> {
|
||||
fn in_scope(e: &env, sp: &span, name: &ident, s: &scope, ns: namespace) ->
|
||||
fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
|
||||
-> option::t<def> {
|
||||
fn in_scope(e: env, sp: span, name: ident, s: scope, ns: namespace) ->
|
||||
option::t<def> {
|
||||
alt s {
|
||||
scope_crate. {
|
||||
|
|
@ -749,7 +749,7 @@ fn lookup_in_scope(e: &env, sc: scopes, sp: &span, name: &ident,
|
|||
|
||||
}
|
||||
|
||||
fn lookup_in_ty_params(name: &ident, ty_params: &[ast::ty_param]) ->
|
||||
fn lookup_in_ty_params(name: ident, ty_params: [ast::ty_param]) ->
|
||||
option::t<def> {
|
||||
let i = 0u;
|
||||
for tp: ast::ty_param in ty_params {
|
||||
|
|
@ -759,7 +759,7 @@ fn lookup_in_ty_params(name: &ident, ty_params: &[ast::ty_param]) ->
|
|||
ret none::<def>;
|
||||
}
|
||||
|
||||
fn lookup_in_pat(name: &ident, pat: &@ast::pat) -> option::t<def_id> {
|
||||
fn lookup_in_pat(name: ident, pat: @ast::pat) -> option::t<def_id> {
|
||||
let found = none;
|
||||
for each bound in ast_util::pat_bindings(pat) {
|
||||
let p_name = alt bound.node { ast::pat_bind(n) { n } };
|
||||
|
|
@ -768,9 +768,8 @@ fn lookup_in_pat(name: &ident, pat: &@ast::pat) -> option::t<def_id> {
|
|||
ret found;
|
||||
}
|
||||
|
||||
fn lookup_in_fn(name: &ident, decl: &ast::fn_decl,
|
||||
ty_params: &[ast::ty_param], ns: namespace) ->
|
||||
option::t<def> {
|
||||
fn lookup_in_fn(name: ident, decl: ast::fn_decl, ty_params: [ast::ty_param],
|
||||
ns: namespace) -> option::t<def> {
|
||||
alt ns {
|
||||
ns_value. {
|
||||
for a: ast::arg in decl.inputs {
|
||||
|
|
@ -785,7 +784,7 @@ fn lookup_in_fn(name: &ident, decl: &ast::fn_decl,
|
|||
}
|
||||
}
|
||||
|
||||
fn lookup_in_obj(name: &ident, ob: &ast::_obj, ty_params: &[ast::ty_param],
|
||||
fn lookup_in_obj(name: ident, ob: ast::_obj, ty_params: [ast::ty_param],
|
||||
ns: namespace) -> option::t<def> {
|
||||
alt ns {
|
||||
ns_value. {
|
||||
|
|
@ -801,7 +800,7 @@ fn lookup_in_obj(name: &ident, ob: &ast::_obj, ty_params: &[ast::ty_param],
|
|||
}
|
||||
}
|
||||
|
||||
fn lookup_in_block(name: &ident, b: &ast::blk_, pos: uint, loc_pos: uint,
|
||||
fn lookup_in_block(name: ident, b: ast::blk_, pos: uint, loc_pos: uint,
|
||||
ns: namespace) -> option::t<def> {
|
||||
let i = vec::len(b.stmts);
|
||||
while i > 0u {
|
||||
|
|
@ -858,7 +857,7 @@ fn lookup_in_block(name: &ident, b: &ast::blk_, pos: uint, loc_pos: uint,
|
|||
ret none::<def>;
|
||||
}
|
||||
|
||||
fn found_def_item(i: &@ast::item, ns: namespace) -> option::t<def> {
|
||||
fn found_def_item(i: @ast::item, ns: namespace) -> option::t<def> {
|
||||
alt i.node {
|
||||
ast::item_const(_, _) {
|
||||
if ns == ns_value { ret some(ast::def_const(local_def(i.id))); }
|
||||
|
|
@ -903,7 +902,7 @@ fn found_def_item(i: &@ast::item, ns: namespace) -> option::t<def> {
|
|||
ret none::<def>;
|
||||
}
|
||||
|
||||
fn lookup_in_mod_strict(e: &env, sc: &scopes, m: def, sp: &span, name: &ident,
|
||||
fn lookup_in_mod_strict(e: env, sc: scopes, m: def, sp: span, name: ident,
|
||||
ns: namespace, dr: dir) -> option::t<def> {
|
||||
alt lookup_in_mod(e, m, sp, name, ns, dr) {
|
||||
none. { unresolved_err(e, sc, sp, name, ns_name(ns)); ret none; }
|
||||
|
|
@ -911,7 +910,7 @@ fn lookup_in_mod_strict(e: &env, sc: &scopes, m: def, sp: &span, name: &ident,
|
|||
}
|
||||
}
|
||||
|
||||
fn lookup_in_mod(e: &env, m: &def, sp: &span, name: &ident, ns: namespace,
|
||||
fn lookup_in_mod(e: env, m: def, sp: span, name: ident, ns: namespace,
|
||||
dr: dir) -> option::t<def> {
|
||||
let defid = ast_util::def_id_of_def(m);
|
||||
if defid.crate != ast::local_crate {
|
||||
|
|
@ -938,7 +937,7 @@ fn lookup_in_mod(e: &env, m: &def, sp: &span, name: &ident, ns: namespace,
|
|||
}
|
||||
}
|
||||
|
||||
fn found_view_item(e: &env, vi: @ast::view_item) -> option::t<def> {
|
||||
fn found_view_item(e: env, vi: @ast::view_item) -> option::t<def> {
|
||||
alt vi.node {
|
||||
ast::view_item_use(_, _, id) {
|
||||
let cnum = cstore::get_use_stmt_cnum(e.cstore, id);
|
||||
|
|
@ -947,7 +946,7 @@ fn found_view_item(e: &env, vi: @ast::view_item) -> option::t<def> {
|
|||
}
|
||||
}
|
||||
|
||||
fn lookup_import(e: &env, defid: def_id, ns: namespace) -> option::t<def> {
|
||||
fn lookup_import(e: env, defid: def_id, ns: namespace) -> option::t<def> {
|
||||
alt e.imports.get(defid.node) {
|
||||
todo(node_id, name, path, span, scopes) {
|
||||
resolve_import(e, local_def(node_id), name, path, span, scopes);
|
||||
|
|
@ -960,12 +959,12 @@ fn lookup_import(e: &env, defid: def_id, ns: namespace) -> option::t<def> {
|
|||
}
|
||||
}
|
||||
|
||||
fn lookup_in_local_native_mod(e: &env, node_id: node_id, sp: &span,
|
||||
id: &ident, ns: namespace) -> option::t<def> {
|
||||
fn lookup_in_local_native_mod(e: env, node_id: node_id, sp: span, id: ident,
|
||||
ns: namespace) -> option::t<def> {
|
||||
ret lookup_in_local_mod(e, node_id, sp, id, ns, inside);
|
||||
}
|
||||
|
||||
fn lookup_in_local_mod(e: &env, node_id: node_id, sp: &span, id: &ident,
|
||||
fn lookup_in_local_mod(e: env, node_id: node_id, sp: span, id: ident,
|
||||
ns: namespace, dr: dir) -> option::t<def> {
|
||||
let info = e.mod_map.get(node_id);
|
||||
if dr == outside && !ast_util::is_exported(id, option::get(info.m)) {
|
||||
|
|
@ -993,14 +992,13 @@ fn lookup_in_local_mod(e: &env, node_id: node_id, sp: &span, id: &ident,
|
|||
ret lookup_glob_in_mod(e, info, sp, id, ns, outside);
|
||||
}
|
||||
|
||||
fn lookup_glob_in_mod(e: &env, info: @indexed_mod, sp: &span, id: &ident,
|
||||
fn lookup_glob_in_mod(e: env, info: @indexed_mod, sp: span, id: ident,
|
||||
wanted_ns: namespace, dr: dir) -> option::t<def> {
|
||||
fn per_ns(e: &env, info: @indexed_mod, sp: &span, id: &ident,
|
||||
ns: namespace, dr: dir) -> option::t<def> {
|
||||
fn per_ns(e: env, info: @indexed_mod, sp: span, id: ident, ns: namespace,
|
||||
dr: dir) -> option::t<def> {
|
||||
|
||||
fn lookup_in_mod_(e: &env, def: &glob_imp_def, sp: &span,
|
||||
name: &ident, ns: namespace, dr: dir) ->
|
||||
option::t<glob_imp_def> {
|
||||
fn lookup_in_mod_(e: env, def: glob_imp_def, sp: span, name: ident,
|
||||
ns: namespace, dr: dir) -> option::t<glob_imp_def> {
|
||||
alt lookup_in_mod(e, def.def, sp, name, ns, dr) {
|
||||
option::some(d) { option::some({def: d, item: def.item}) }
|
||||
option::none. { option::none }
|
||||
|
|
@ -1050,7 +1048,7 @@ fn lookup_glob_in_mod(e: &env, info: @indexed_mod, sp: &span, id: &ident,
|
|||
}
|
||||
}
|
||||
|
||||
fn lookup_in_mie(e: &env, mie: &mod_index_entry, ns: namespace) ->
|
||||
fn lookup_in_mie(e: env, mie: mod_index_entry, ns: namespace) ->
|
||||
option::t<def> {
|
||||
alt mie {
|
||||
mie_view_item(view_item) {
|
||||
|
|
@ -1089,15 +1087,15 @@ fn lookup_in_mie(e: &env, mie: &mod_index_entry, ns: namespace) ->
|
|||
|
||||
|
||||
// Module indexing
|
||||
fn add_to_index(index: &hashmap<ident, list<mod_index_entry>>, id: &ident,
|
||||
ent: &mod_index_entry) {
|
||||
fn add_to_index(index: hashmap<ident, list<mod_index_entry>>, id: ident,
|
||||
ent: mod_index_entry) {
|
||||
alt index.find(id) {
|
||||
none. { index.insert(id, cons(ent, @nil::<mod_index_entry>)); }
|
||||
some(prev) { index.insert(id, cons(ent, @prev)); }
|
||||
}
|
||||
}
|
||||
|
||||
fn index_mod(md: &ast::_mod) -> mod_index {
|
||||
fn index_mod(md: ast::_mod) -> mod_index {
|
||||
let index = new_str_hash::<list<mod_index_entry>>();
|
||||
for it: @ast::view_item in md.view_items {
|
||||
alt it.node {
|
||||
|
|
@ -1107,12 +1105,14 @@ fn index_mod(md: &ast::_mod) -> mod_index {
|
|||
|
||||
|
||||
|
||||
|
||||
ast::view_item_import(ident, _, id) {
|
||||
add_to_index(index, ident, mie_import_ident(id, it.span));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ast::view_item_import_from(_, idents, _) {
|
||||
for ident in idents {
|
||||
add_to_index(index, ident.node.name,
|
||||
|
|
@ -1122,6 +1122,7 @@ fn index_mod(md: &ast::_mod) -> mod_index {
|
|||
|
||||
|
||||
|
||||
|
||||
//globbed imports have to be resolved lazily.
|
||||
ast::view_item_import_glob(_, _) | ast::view_item_export(_, _) {
|
||||
}
|
||||
|
|
@ -1148,7 +1149,7 @@ fn index_mod(md: &ast::_mod) -> mod_index {
|
|||
ret index;
|
||||
}
|
||||
|
||||
fn index_nmod(md: &ast::native_mod) -> mod_index {
|
||||
fn index_nmod(md: ast::native_mod) -> mod_index {
|
||||
let index = new_str_hash::<list<mod_index_entry>>();
|
||||
for it: @ast::view_item in md.view_items {
|
||||
alt it.node {
|
||||
|
|
@ -1194,7 +1195,7 @@ fn ns_for_def(d: def) -> namespace {
|
|||
};
|
||||
}
|
||||
|
||||
fn lookup_external(e: &env, cnum: int, ids: &[ident], ns: namespace) ->
|
||||
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) {
|
||||
e.ext_map.insert(ast_util::def_id_of_def(d), ids);
|
||||
|
|
@ -1205,7 +1206,7 @@ fn lookup_external(e: &env, cnum: int, ids: &[ident], ns: namespace) ->
|
|||
|
||||
|
||||
// Collision detection
|
||||
fn check_for_collisions(e: &@env, c: &ast::crate) {
|
||||
fn check_for_collisions(e: @env, c: ast::crate) {
|
||||
// Module indices make checking those relatively simple -- just check each
|
||||
// name for multiple entities in the same namespace.
|
||||
for each m: @{key: ast::node_id, val: @indexed_mod} in e.mod_map.items() {
|
||||
|
|
@ -1224,11 +1225,11 @@ fn check_for_collisions(e: &@env, c: &ast::crate) {
|
|||
visit::visit_crate(c, (), visit::mk_vt(v));
|
||||
}
|
||||
|
||||
fn check_mod_name(e: &env, name: &ident, entries: list<mod_index_entry>) {
|
||||
fn check_mod_name(e: env, name: ident, entries: list<mod_index_entry>) {
|
||||
let saw_mod = false;
|
||||
let saw_type = false;
|
||||
let saw_value = false;
|
||||
fn dup(e: &env, sp: &span, word: &str, name: &ident) {
|
||||
fn dup(e: env, sp: span, word: str, name: ident) {
|
||||
e.sess.span_fatal(sp, "duplicate definition of " + word + name);
|
||||
}
|
||||
while true {
|
||||
|
|
@ -1256,7 +1257,7 @@ fn check_mod_name(e: &env, name: &ident, entries: list<mod_index_entry>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn mie_span(mie: &mod_index_entry) -> span {
|
||||
fn mie_span(mie: mod_index_entry) -> span {
|
||||
ret alt mie {
|
||||
mie_view_item(item) { item.span }
|
||||
mie_import_ident(_, span) { span }
|
||||
|
|
@ -1266,8 +1267,8 @@ fn mie_span(mie: &mod_index_entry) -> span {
|
|||
};
|
||||
}
|
||||
|
||||
fn check_item(e: &@env, i: &@ast::item, x: &(), v: &vt<()>) {
|
||||
fn typaram_names(tps: &[ast::ty_param]) -> [ident] {
|
||||
fn check_item(e: @env, i: @ast::item, x: (), v: vt<()>) {
|
||||
fn typaram_names(tps: [ast::ty_param]) -> [ident] {
|
||||
let x: [ast::ident] = [];
|
||||
for tp: ast::ty_param in tps { x += [tp.ident] }
|
||||
ret x;
|
||||
|
|
@ -1280,7 +1281,7 @@ fn check_item(e: &@env, i: &@ast::item, x: &(), v: &vt<()>) {
|
|||
"type parameter");
|
||||
}
|
||||
ast::item_obj(ob, ty_params, _) {
|
||||
fn field_name(field: &ast::obj_field) -> ident { ret field.ident; }
|
||||
fn field_name(field: ast::obj_field) -> ident { ret field.ident; }
|
||||
ensure_unique(*e, i.span, ob.fields, field_name, "object field");
|
||||
for m: @ast::method in ob.methods {
|
||||
check_fn(*e, m.span, m.node.meth);
|
||||
|
|
@ -1296,14 +1297,14 @@ fn check_item(e: &@env, i: &@ast::item, x: &(), v: &vt<()>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_pat(ch: checker, p: &@ast::pat) {
|
||||
fn check_pat(ch: checker, p: @ast::pat) {
|
||||
for each p in ast_util::pat_bindings(p) {
|
||||
let ident = alt p.node { pat_bind(n) { n } };
|
||||
add_name(ch, p.span, ident);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_arm(e: &@env, a: &ast::arm, x: &(), v: &vt<()>) {
|
||||
fn check_arm(e: @env, a: ast::arm, x: (), v: vt<()>) {
|
||||
visit::visit_arm(a, x, v);
|
||||
let ch0 = checker(*e, "binding");
|
||||
check_pat(ch0, a.pats[0]);
|
||||
|
|
@ -1333,7 +1334,7 @@ fn check_arm(e: &@env, a: &ast::arm, x: &(), v: &vt<()>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_block(e: &@env, b: &ast::blk, x: &(), v: &vt<()>) {
|
||||
fn check_block(e: @env, b: ast::blk, x: (), v: vt<()>) {
|
||||
visit::visit_block(b, x, v);
|
||||
let values = checker(*e, "value");
|
||||
let types = checker(*e, "type");
|
||||
|
|
@ -1381,15 +1382,15 @@ fn check_block(e: &@env, b: &ast::blk, x: &(), v: &vt<()>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_fn(e: &env, sp: &span, f: &ast::_fn) {
|
||||
fn arg_name(a: &ast::arg) -> ident { ret a.ident; }
|
||||
fn check_fn(e: env, sp: span, f: ast::_fn) {
|
||||
fn arg_name(a: ast::arg) -> ident { ret a.ident; }
|
||||
ensure_unique(e, sp, f.decl.inputs, arg_name, "argument");
|
||||
}
|
||||
|
||||
fn check_expr(e: &@env, ex: &@ast::expr, x: &(), v: &vt<()>) {
|
||||
fn check_expr(e: @env, ex: @ast::expr, x: (), v: vt<()>) {
|
||||
alt ex.node {
|
||||
ast::expr_rec(fields, _) {
|
||||
fn field_name(f: &ast::field) -> ident { ret f.node.ident; }
|
||||
fn field_name(f: ast::field) -> ident { ret f.node.ident; }
|
||||
ensure_unique(*e, ex.span, fields, field_name, "field");
|
||||
}
|
||||
_ { }
|
||||
|
|
@ -1397,10 +1398,10 @@ fn check_expr(e: &@env, ex: &@ast::expr, x: &(), v: &vt<()>) {
|
|||
visit::visit_expr(ex, x, v);
|
||||
}
|
||||
|
||||
fn check_ty(e: &@env, ty: &@ast::ty, x: &(), v: &vt<()>) {
|
||||
fn check_ty(e: @env, ty: @ast::ty, x: (), v: vt<()>) {
|
||||
alt ty.node {
|
||||
ast::ty_rec(fields) {
|
||||
fn field_name(f: &ast::ty_field) -> ident { ret f.node.ident; }
|
||||
fn field_name(f: ast::ty_field) -> ident { ret f.node.ident; }
|
||||
ensure_unique(*e, ty.span, fields, field_name, "field");
|
||||
}
|
||||
_ { }
|
||||
|
|
@ -1410,34 +1411,34 @@ fn check_ty(e: &@env, ty: &@ast::ty, x: &(), v: &vt<()>) {
|
|||
|
||||
type checker = @{mutable seen: [ident], kind: str, sess: session};
|
||||
|
||||
fn checker(e: &env, kind: &str) -> checker {
|
||||
fn checker(e: env, kind: str) -> checker {
|
||||
let seen: [ident] = [];
|
||||
ret @{mutable seen: seen, kind: kind, sess: e.sess};
|
||||
}
|
||||
|
||||
fn check_name(ch: &checker, sp: &span, name: &ident) {
|
||||
fn check_name(ch: checker, sp: span, name: ident) {
|
||||
for s: ident in ch.seen {
|
||||
if str::eq(s, name) {
|
||||
ch.sess.span_fatal(sp, "duplicate " + ch.kind + " name: " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
fn add_name(ch: &checker, sp: &span, name: &ident) {
|
||||
fn add_name(ch: checker, sp: span, name: ident) {
|
||||
check_name(ch, sp, name);
|
||||
ch.seen += [name];
|
||||
}
|
||||
|
||||
fn ident_id(i: &ident) -> ident { ret i; }
|
||||
fn ident_id(i: ident) -> ident { ret i; }
|
||||
|
||||
fn ensure_unique<T>(e: &env, sp: &span, elts: &[T], id: fn(&T) -> ident,
|
||||
kind: &str) {
|
||||
fn ensure_unique<T>(e: env, sp: span, elts: [T], id: fn(T) -> ident,
|
||||
kind: str) {
|
||||
let ch = checker(e, kind);
|
||||
for elt: T in elts { add_name(ch, sp, id(elt)); }
|
||||
}
|
||||
|
||||
fn check_bad_exports(e: &@env) {
|
||||
fn lookup_glob_any(e: &env, info: &@indexed_mod, sp: &span, ident: &ident)
|
||||
-> bool {
|
||||
fn check_bad_exports(e: @env) {
|
||||
fn lookup_glob_any(e: env, info: @indexed_mod, sp: span, ident: ident) ->
|
||||
bool {
|
||||
ret !option::is_none(lookup_glob_in_mod(e, info, sp, ident, ns_module,
|
||||
inside)) ||
|
||||
!option::is_none(lookup_glob_in_mod(e, info, sp, ident,
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ const shape_uniq: u8 = 22u8;
|
|||
// FIXME: This is a bad API in trans_common.
|
||||
fn C_u8(n: u8) -> ValueRef { ret trans_common::C_u8(n as uint); }
|
||||
|
||||
fn hash_res_info(ri: &res_info) -> uint {
|
||||
fn hash_res_info(ri: res_info) -> uint {
|
||||
let h = 5381u;
|
||||
h *= 33u;
|
||||
h += ri.did.crate as uint;
|
||||
|
|
@ -80,12 +80,12 @@ fn hash_res_info(ri: &res_info) -> uint {
|
|||
ret h;
|
||||
}
|
||||
|
||||
fn eq_res_info(a: &res_info, b: &res_info) -> bool {
|
||||
fn eq_res_info(a: res_info, b: res_info) -> bool {
|
||||
ret a.did.crate == b.did.crate && a.did.node == b.did.node && a.t == b.t;
|
||||
}
|
||||
|
||||
fn mk_global(ccx: &@crate_ctxt, name: &str, llval: ValueRef, internal: bool)
|
||||
-> ValueRef {
|
||||
fn mk_global(ccx: @crate_ctxt, name: str, llval: ValueRef, internal: bool) ->
|
||||
ValueRef {
|
||||
let llglobal =
|
||||
str::as_buf(name,
|
||||
{|buf|
|
||||
|
|
@ -111,7 +111,7 @@ fn mk_global(ccx: &@crate_ctxt, name: &str, llval: ValueRef, internal: bool)
|
|||
//
|
||||
// TODO: Use this in dynamic_size_of() as well.
|
||||
|
||||
fn largest_variants(ccx: &@crate_ctxt, tag_id: &ast::def_id) -> [uint] {
|
||||
fn largest_variants(ccx: @crate_ctxt, tag_id: ast::def_id) -> [uint] {
|
||||
// Compute the minimum and maximum size and alignment for each variant.
|
||||
//
|
||||
// TODO: We could do better here; e.g. we know that any variant that
|
||||
|
|
@ -133,7 +133,7 @@ fn largest_variants(ccx: &@crate_ctxt, tag_id: &ast::def_id) -> [uint] {
|
|||
// follow from how elem_t doesn't contain params.
|
||||
// (Could add a postcondition to type_contains_params,
|
||||
// once we implement Issue #586.)
|
||||
check trans_common::type_has_static_size(ccx, elem_t);
|
||||
check (trans_common::type_has_static_size(ccx, elem_t));
|
||||
let llty = trans::type_of(ccx, dummy_sp(), elem_t);
|
||||
min_size += trans::llsize_of_real(ccx, llty);
|
||||
min_align += trans::llalign_of_real(ccx, llty);
|
||||
|
|
@ -200,8 +200,8 @@ fn round_up(size: u16, align: u8) -> u16 {
|
|||
|
||||
type size_align = {size: u16, align: u8};
|
||||
|
||||
fn compute_static_tag_size(ccx: &@crate_ctxt, largest_variants: &[uint],
|
||||
did: &ast::def_id) -> size_align {
|
||||
fn compute_static_tag_size(ccx: @crate_ctxt, largest_variants: [uint],
|
||||
did: ast::def_id) -> size_align {
|
||||
let max_size = 0u16;
|
||||
let max_align = 1u8;
|
||||
let variants = ty::tag_variants(ccx.tcx, did);
|
||||
|
|
@ -212,7 +212,7 @@ fn compute_static_tag_size(ccx: &@crate_ctxt, largest_variants: &[uint],
|
|||
// FIXME: there should really be a postcondition
|
||||
// on tag_variants that would obviate the need for
|
||||
// this check. (Issue #586)
|
||||
check trans_common::type_has_static_size(ccx, typ);
|
||||
check (trans_common::type_has_static_size(ccx, typ));
|
||||
lltys += [trans::type_of(ccx, dummy_sp(), typ)];
|
||||
}
|
||||
|
||||
|
|
@ -234,7 +234,7 @@ fn compute_static_tag_size(ccx: &@crate_ctxt, largest_variants: &[uint],
|
|||
|
||||
tag tag_kind { tk_unit; tk_enum; tk_complex; }
|
||||
|
||||
fn tag_kind(ccx: &@crate_ctxt, did: &ast::def_id) -> tag_kind {
|
||||
fn tag_kind(ccx: @crate_ctxt, did: ast::def_id) -> tag_kind {
|
||||
let variants = ty::tag_variants(ccx.tcx, did);
|
||||
if vec::len(variants) == 0u { ret tk_complex; }
|
||||
for v: ty::variant_info in variants {
|
||||
|
|
@ -246,15 +246,15 @@ 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 {
|
||||
fn s_int(_tcx: ty_ctxt) -> u8 {
|
||||
ret shape_i32; // TODO: x86-64
|
||||
}
|
||||
|
||||
fn s_uint(_tcx: &ty_ctxt) -> u8 {
|
||||
fn s_uint(_tcx: ty_ctxt) -> u8 {
|
||||
ret shape_u32; // TODO: x86-64
|
||||
}
|
||||
|
||||
fn s_float(_tcx: &ty_ctxt) -> u8 {
|
||||
fn s_float(_tcx: ty_ctxt) -> u8 {
|
||||
ret shape_f64; // TODO: x86-64
|
||||
}
|
||||
|
||||
|
|
@ -284,12 +284,12 @@ fn add_u16(dest: &mutable [u8], val: u16) {
|
|||
dest += [val & 0xffu16 as u8, val >> 8u16 as u8];
|
||||
}
|
||||
|
||||
fn add_substr(dest: &mutable [u8], src: &[u8]) {
|
||||
fn add_substr(dest: &mutable [u8], src: [u8]) {
|
||||
add_u16(dest, vec::len(src) as u16);
|
||||
dest += src;
|
||||
}
|
||||
|
||||
fn shape_of(ccx: &@crate_ctxt, t: ty::t, ty_param_map: &[uint]) -> [u8] {
|
||||
fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint]) -> [u8] {
|
||||
let s = [];
|
||||
|
||||
alt ty::struct(ccx.tcx, t) {
|
||||
|
|
@ -299,6 +299,7 @@ fn shape_of(ccx: &@crate_ctxt, t: ty::t, ty_param_map: &[uint]) -> [u8] {
|
|||
|
||||
|
||||
|
||||
|
||||
ty::ty_int. {
|
||||
s += [s_int(ccx.tcx)];
|
||||
}
|
||||
|
|
@ -306,12 +307,14 @@ fn shape_of(ccx: &@crate_ctxt, t: ty::t, ty_param_map: &[uint]) -> [u8] {
|
|||
|
||||
|
||||
|
||||
|
||||
ty::ty_uint. | ty::ty_ptr(_) | ty::ty_type. | ty::ty_native(_) {
|
||||
s += [s_uint(ccx.tcx)];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ty::ty_machine(ast::ty_i8.) {
|
||||
s += [shape_i8];
|
||||
}
|
||||
|
|
@ -324,6 +327,7 @@ fn shape_of(ccx: &@crate_ctxt, t: ty::t, ty_param_map: &[uint]) -> [u8] {
|
|||
|
||||
|
||||
|
||||
|
||||
ty::ty_str. {
|
||||
s += [shape_vec];
|
||||
add_bool(s, true); // type is POD
|
||||
|
|
@ -332,6 +336,7 @@ fn shape_of(ccx: &@crate_ctxt, t: ty::t, ty_param_map: &[uint]) -> [u8] {
|
|||
}
|
||||
|
||||
|
||||
|
||||
ty::ty_tag(did, tps) {
|
||||
alt tag_kind(ccx, did) {
|
||||
tk_unit. {
|
||||
|
|
@ -370,6 +375,7 @@ fn shape_of(ccx: &@crate_ctxt, t: ty::t, ty_param_map: &[uint]) -> [u8] {
|
|||
|
||||
|
||||
|
||||
|
||||
ty::ty_box(mt) {
|
||||
s += [shape_box];
|
||||
add_substr(s, shape_of(ccx, mt.ty, ty_param_map));
|
||||
|
|
@ -400,6 +406,7 @@ fn shape_of(ccx: &@crate_ctxt, t: ty::t, ty_param_map: &[uint]) -> [u8] {
|
|||
|
||||
|
||||
|
||||
|
||||
ty::ty_fn(_, _, _, _, _) {
|
||||
s += [shape_fn];
|
||||
}
|
||||
|
|
@ -408,6 +415,7 @@ fn shape_of(ccx: &@crate_ctxt, t: ty::t, ty_param_map: &[uint]) -> [u8] {
|
|||
|
||||
|
||||
|
||||
|
||||
ty::ty_res(did, raw_subt, tps) {
|
||||
let subt = ty::substitute_type_params(ccx.tcx, tps, raw_subt);
|
||||
let ri = {did: did, t: subt};
|
||||
|
|
@ -424,11 +432,13 @@ fn shape_of(ccx: &@crate_ctxt, t: ty::t, ty_param_map: &[uint]) -> [u8] {
|
|||
}
|
||||
|
||||
|
||||
|
||||
ty::ty_var(n) {
|
||||
fail "shape_of ty_var";
|
||||
}
|
||||
|
||||
|
||||
|
||||
ty::ty_param(n, _) {
|
||||
// Find the type parameter in the parameter list.
|
||||
let found = false;
|
||||
|
|
@ -449,7 +459,7 @@ fn shape_of(ccx: &@crate_ctxt, t: ty::t, ty_param_map: &[uint]) -> [u8] {
|
|||
}
|
||||
|
||||
// FIXME: We might discover other variants as we traverse these. Handle this.
|
||||
fn shape_of_variant(ccx: &@crate_ctxt, v: &ty::variant_info,
|
||||
fn shape_of_variant(ccx: @crate_ctxt, v: ty::variant_info,
|
||||
ty_param_count: uint) -> [u8] {
|
||||
let ty_param_map = [];
|
||||
let i = 0u;
|
||||
|
|
@ -460,7 +470,7 @@ fn shape_of_variant(ccx: &@crate_ctxt, v: &ty::variant_info,
|
|||
ret s;
|
||||
}
|
||||
|
||||
fn gen_tag_shapes(ccx: &@crate_ctxt) -> ValueRef {
|
||||
fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef {
|
||||
// Loop over all the tag variants and write their shapes into a data
|
||||
// buffer. As we do this, it's possible for us to discover new tags, so we
|
||||
// must do this first.
|
||||
|
|
@ -555,7 +565,7 @@ fn gen_tag_shapes(ccx: &@crate_ctxt) -> ValueRef {
|
|||
ret mk_global(ccx, "tag_shapes", C_bytes(header), true);
|
||||
}
|
||||
|
||||
fn gen_resource_shapes(ccx: &@crate_ctxt) -> ValueRef {
|
||||
fn gen_resource_shapes(ccx: @crate_ctxt) -> ValueRef {
|
||||
let dtors = [];
|
||||
let i = 0u;
|
||||
let len = interner::len(ccx.shape_cx.resources);
|
||||
|
|
@ -568,7 +578,7 @@ fn gen_resource_shapes(ccx: &@crate_ctxt) -> ValueRef {
|
|||
ret mk_global(ccx, "resource_shapes", C_struct(dtors), true);
|
||||
}
|
||||
|
||||
fn gen_shape_tables(ccx: &@crate_ctxt) {
|
||||
fn gen_shape_tables(ccx: @crate_ctxt) {
|
||||
let lltagstable = gen_tag_shapes(ccx);
|
||||
let llresourcestable = gen_resource_shapes(ccx);
|
||||
trans_common::set_struct_body(ccx.shape_cx.llshapetablesty,
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -28,7 +28,7 @@ tag opt {
|
|||
lit(@ast::lit);
|
||||
var(/* variant id */uint, /* variant dids */{tg: def_id, var: def_id});
|
||||
}
|
||||
fn opt_eq(a: &opt, b: &opt) -> bool {
|
||||
fn opt_eq(a: opt, b: opt) -> bool {
|
||||
alt a {
|
||||
lit(la) {
|
||||
ret alt b { lit(lb) { lit_eq(la, lb) } var(_, _) { false } };
|
||||
|
|
@ -38,14 +38,14 @@ fn opt_eq(a: &opt, b: &opt) -> bool {
|
|||
}
|
||||
}
|
||||
}
|
||||
fn trans_opt(bcx: &@block_ctxt, o: &opt) -> result {
|
||||
fn trans_opt(bcx: @block_ctxt, o: opt) -> result {
|
||||
alt o {
|
||||
lit(l) { ret trans::trans_lit(bcx, *l); }
|
||||
var(id, _) { ret rslt(bcx, C_int(id as int)); }
|
||||
}
|
||||
}
|
||||
|
||||
fn variant_opt(ccx: &@crate_ctxt, pat_id: ast::node_id) -> opt {
|
||||
fn variant_opt(ccx: @crate_ctxt, pat_id: ast::node_id) -> opt {
|
||||
let vdef = ast_util::variant_def_ids(ccx.tcx.def_map.get(pat_id));
|
||||
let variants = ty::tag_variants(ccx.tcx, vdef.tg);
|
||||
let i = 0u;
|
||||
|
|
@ -57,7 +57,7 @@ fn variant_opt(ccx: &@crate_ctxt, pat_id: ast::node_id) -> opt {
|
|||
}
|
||||
|
||||
type bind_map = [{ident: ast::ident, val: ValueRef}];
|
||||
fn assoc(key: &str, list: &bind_map) -> option::t<ValueRef> {
|
||||
fn assoc(key: str, list: bind_map) -> option::t<ValueRef> {
|
||||
for elt: {ident: ast::ident, val: ValueRef} in list {
|
||||
if str::eq(elt.ident, key) { ret some(elt.val); }
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ type match_branch =
|
|||
id_map: ast_util::pat_id_map}};
|
||||
type match = [match_branch];
|
||||
|
||||
fn matches_always(p: &@ast::pat) -> bool {
|
||||
fn matches_always(p: @ast::pat) -> bool {
|
||||
ret alt p.node {
|
||||
ast::pat_wild. { true }
|
||||
ast::pat_bind(_) { true }
|
||||
|
|
@ -83,9 +83,9 @@ fn matches_always(p: &@ast::pat) -> bool {
|
|||
};
|
||||
}
|
||||
|
||||
type enter_pat = fn(&@ast::pat) -> option::t<[@ast::pat]>;
|
||||
type enter_pat = fn(@ast::pat) -> option::t<[@ast::pat]>;
|
||||
|
||||
fn enter_match(m: &match, col: uint, val: ValueRef, e: &enter_pat) -> match {
|
||||
fn enter_match(m: match, col: uint, val: ValueRef, e: enter_pat) -> match {
|
||||
let result = [];
|
||||
for br: match_branch in m {
|
||||
alt e(br.pats[col]) {
|
||||
|
|
@ -110,18 +110,18 @@ fn enter_match(m: &match, col: uint, val: ValueRef, e: &enter_pat) -> match {
|
|||
ret result;
|
||||
}
|
||||
|
||||
fn enter_default(m: &match, col: uint, val: ValueRef) -> match {
|
||||
fn e(p: &@ast::pat) -> option::t<[@ast::pat]> {
|
||||
fn enter_default(m: match, col: uint, val: ValueRef) -> match {
|
||||
fn e(p: @ast::pat) -> option::t<[@ast::pat]> {
|
||||
ret if matches_always(p) { some([]) } else { none };
|
||||
}
|
||||
ret enter_match(m, col, val, e);
|
||||
}
|
||||
|
||||
fn enter_opt(ccx: &@crate_ctxt, m: &match, opt: &opt, col: uint,
|
||||
tag_size: uint, val: ValueRef) -> match {
|
||||
fn enter_opt(ccx: @crate_ctxt, m: match, opt: opt, col: uint, tag_size: uint,
|
||||
val: ValueRef) -> match {
|
||||
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
|
||||
fn e(ccx: &@crate_ctxt, dummy: &@ast::pat, opt: &opt, size: uint,
|
||||
p: &@ast::pat) -> option::t<[@ast::pat]> {
|
||||
fn e(ccx: @crate_ctxt, dummy: @ast::pat, opt: opt, size: uint,
|
||||
p: @ast::pat) -> option::t<[@ast::pat]> {
|
||||
alt p.node {
|
||||
ast::pat_tag(ctor, subpats) {
|
||||
ret if opt_eq(variant_opt(ccx, p.id), opt) {
|
||||
|
|
@ -137,10 +137,10 @@ fn enter_opt(ccx: &@crate_ctxt, m: &match, opt: &opt, col: uint,
|
|||
ret enter_match(m, col, val, bind e(ccx, dummy, opt, tag_size, _));
|
||||
}
|
||||
|
||||
fn enter_rec(m: &match, col: uint, fields: &[ast::ident], val: ValueRef) ->
|
||||
fn enter_rec(m: match, col: uint, fields: [ast::ident], val: ValueRef) ->
|
||||
match {
|
||||
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
|
||||
fn e(dummy: &@ast::pat, fields: &[ast::ident], p: &@ast::pat) ->
|
||||
fn e(dummy: @ast::pat, fields: [ast::ident], p: @ast::pat) ->
|
||||
option::t<[@ast::pat]> {
|
||||
alt p.node {
|
||||
ast::pat_rec(fpats, _) {
|
||||
|
|
@ -160,9 +160,9 @@ fn enter_rec(m: &match, col: uint, fields: &[ast::ident], val: ValueRef) ->
|
|||
ret enter_match(m, col, val, bind e(dummy, fields, _));
|
||||
}
|
||||
|
||||
fn enter_tup(m: &match, col: uint, val: ValueRef, n_elts: uint) -> match {
|
||||
fn enter_tup(m: match, col: uint, val: ValueRef, n_elts: uint) -> match {
|
||||
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
|
||||
fn e(dummy: &@ast::pat, n_elts: uint, p: &@ast::pat) ->
|
||||
fn e(dummy: @ast::pat, n_elts: uint, p: @ast::pat) ->
|
||||
option::t<[@ast::pat]> {
|
||||
alt p.node {
|
||||
ast::pat_tup(elts) { ret some(elts); }
|
||||
|
|
@ -172,9 +172,9 @@ fn enter_tup(m: &match, col: uint, val: ValueRef, n_elts: uint) -> match {
|
|||
ret enter_match(m, col, val, bind e(dummy, n_elts, _));
|
||||
}
|
||||
|
||||
fn enter_box(m: &match, col: uint, val: ValueRef) -> match {
|
||||
fn enter_box(m: match, col: uint, val: ValueRef) -> match {
|
||||
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
|
||||
fn e(dummy: &@ast::pat, p: &@ast::pat) -> option::t<[@ast::pat]> {
|
||||
fn e(dummy: @ast::pat, p: @ast::pat) -> option::t<[@ast::pat]> {
|
||||
alt p.node {
|
||||
ast::pat_box(sub) { ret some([sub]); }
|
||||
_ { ret some([dummy]); }
|
||||
|
|
@ -183,8 +183,8 @@ fn enter_box(m: &match, col: uint, val: ValueRef) -> match {
|
|||
ret enter_match(m, col, val, bind e(dummy, _));
|
||||
}
|
||||
|
||||
fn get_options(ccx: &@crate_ctxt, m: &match, col: uint) -> [opt] {
|
||||
fn add_to_set(set: &mutable [opt], val: &opt) {
|
||||
fn get_options(ccx: @crate_ctxt, m: match, col: uint) -> [opt] {
|
||||
fn add_to_set(set: &mutable [opt], val: opt) {
|
||||
for l: opt in set { if opt_eq(l, val) { ret; } }
|
||||
set += [val];
|
||||
}
|
||||
|
|
@ -203,7 +203,7 @@ fn get_options(ccx: &@crate_ctxt, m: &match, col: uint) -> [opt] {
|
|||
}
|
||||
|
||||
fn extract_variant_args(bcx: @block_ctxt, pat_id: ast::node_id,
|
||||
vdefs: &{tg: def_id, var: def_id}, val: ValueRef) ->
|
||||
vdefs: {tg: def_id, var: def_id}, val: ValueRef) ->
|
||||
{vals: [ValueRef], bcx: @block_ctxt} {
|
||||
let ccx = bcx.fcx.lcx.ccx;
|
||||
let ty_param_substs = ty::node_id_to_type_params(ccx.tcx, pat_id);
|
||||
|
|
@ -232,7 +232,7 @@ fn extract_variant_args(bcx: @block_ctxt, pat_id: ast::node_id,
|
|||
ret {vals: args, bcx: bcx};
|
||||
}
|
||||
|
||||
fn collect_record_fields(m: &match, col: uint) -> [ast::ident] {
|
||||
fn collect_record_fields(m: match, col: uint) -> [ast::ident] {
|
||||
let fields = [];
|
||||
for br: match_branch in m {
|
||||
alt br.pats[col].node {
|
||||
|
|
@ -249,14 +249,14 @@ fn collect_record_fields(m: &match, col: uint) -> [ast::ident] {
|
|||
ret fields;
|
||||
}
|
||||
|
||||
fn any_box_pat(m: &match, col: uint) -> bool {
|
||||
fn any_box_pat(m: match, col: uint) -> bool {
|
||||
for br: match_branch in m {
|
||||
alt br.pats[col].node { ast::pat_box(_) { ret true; } _ { } }
|
||||
}
|
||||
ret false;
|
||||
}
|
||||
|
||||
fn any_tup_pat(m: &match, col: uint) -> bool {
|
||||
fn any_tup_pat(m: match, col: uint) -> bool {
|
||||
for br: match_branch in m {
|
||||
alt br.pats[col].node { ast::pat_tup(_) { ret true; } _ { } }
|
||||
}
|
||||
|
|
@ -266,7 +266,7 @@ fn any_tup_pat(m: &match, col: uint) -> bool {
|
|||
type exit_node = {bound: bind_map, from: BasicBlockRef, to: BasicBlockRef};
|
||||
type mk_fail = fn() -> BasicBlockRef;
|
||||
|
||||
fn pick_col(m: &match) -> uint {
|
||||
fn pick_col(m: match) -> uint {
|
||||
let scores = vec::init_elt_mut(0u, vec::len(m[0].pats));
|
||||
for br: match_branch in m {
|
||||
let i = 0u;
|
||||
|
|
@ -293,8 +293,8 @@ fn pick_col(m: &match) -> uint {
|
|||
ret best_col;
|
||||
}
|
||||
|
||||
fn compile_submatch(bcx: @block_ctxt, m: &match, vals: [ValueRef],
|
||||
f: &mk_fail, exits: &mutable [exit_node]) {
|
||||
fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
|
||||
exits: &mutable [exit_node]) {
|
||||
if vec::len(m) == 0u { Br(bcx, f()); ret; }
|
||||
if vec::len(m[0].pats) == 0u {
|
||||
let data = m[0].data;
|
||||
|
|
@ -407,10 +407,11 @@ fn compile_submatch(bcx: @block_ctxt, m: &match, vals: [ValueRef],
|
|||
}
|
||||
}
|
||||
lit(l) {
|
||||
kind = alt l.node {
|
||||
ast::lit_str(_) { compare }
|
||||
_ { test_val = Load(bcx, val); switch }
|
||||
};
|
||||
kind =
|
||||
alt l.node {
|
||||
ast::lit_str(_) { compare }
|
||||
_ { test_val = Load(bcx, val); switch }
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -473,8 +474,8 @@ fn compile_submatch(bcx: @block_ctxt, m: &match, vals: [ValueRef],
|
|||
}
|
||||
|
||||
// Returns false for unreachable blocks
|
||||
fn make_phi_bindings(bcx: &@block_ctxt, map: &[exit_node],
|
||||
ids: &ast_util::pat_id_map) -> bool {
|
||||
fn make_phi_bindings(bcx: @block_ctxt, map: [exit_node],
|
||||
ids: ast_util::pat_id_map) -> bool {
|
||||
let our_block = bcx.llbb as uint;
|
||||
let success = true;
|
||||
for each item: @{key: ast::ident, val: ast::node_id} in ids.items() {
|
||||
|
|
@ -496,8 +497,8 @@ fn make_phi_bindings(bcx: &@block_ctxt, map: &[exit_node],
|
|||
ret success;
|
||||
}
|
||||
|
||||
fn trans_alt(cx: &@block_ctxt, expr: &@ast::expr, arms: &[ast::arm],
|
||||
output: &trans::out_method) -> result {
|
||||
fn trans_alt(cx: @block_ctxt, expr: @ast::expr, arms: [ast::arm],
|
||||
output: trans::out_method) -> result {
|
||||
let bodies = [];
|
||||
let match: match = [];
|
||||
let er = trans::trans_expr(cx, expr);
|
||||
|
|
@ -524,7 +525,7 @@ fn trans_alt(cx: &@block_ctxt, expr: &@ast::expr, arms: &[ast::arm],
|
|||
|
||||
// Cached fail-on-fallthrough block
|
||||
let fail_cx = @mutable none;
|
||||
fn mk_fail(cx: &@block_ctxt, sp: &span,
|
||||
fn mk_fail(cx: @block_ctxt, sp: span,
|
||||
done: @mutable option::t<BasicBlockRef>) -> BasicBlockRef {
|
||||
alt *done { some(bb) { ret bb; } _ { } }
|
||||
let fail_cx = new_sub_block_ctxt(cx, "case_fallthrough");
|
||||
|
|
@ -556,7 +557,7 @@ fn trans_alt(cx: &@block_ctxt, expr: &@ast::expr, arms: &[ast::arm],
|
|||
}
|
||||
|
||||
// Not alt-related, but similar to the pattern-munging code above
|
||||
fn bind_irrefutable_pat(bcx: @block_ctxt, pat: &@ast::pat, val: ValueRef,
|
||||
fn bind_irrefutable_pat(bcx: @block_ctxt, pat: @ast::pat, val: ValueRef,
|
||||
table: hashmap<ast::node_id, ValueRef>,
|
||||
make_copy: bool) -> @block_ctxt {
|
||||
let ccx = bcx.fcx.lcx.ccx;
|
||||
|
|
@ -566,7 +567,7 @@ fn bind_irrefutable_pat(bcx: @block_ctxt, pat: &@ast::pat, val: ValueRef,
|
|||
let ty = ty::node_id_to_monotype(ccx.tcx, pat.id);
|
||||
// FIXME: Could constrain pat_bind to make this
|
||||
// check unnecessary.
|
||||
check type_has_static_size(ccx, ty);
|
||||
check (type_has_static_size(ccx, ty));
|
||||
let llty = trans::type_of(ccx, pat.span, ty);
|
||||
let alloc = trans::alloca(bcx, llty);
|
||||
bcx =
|
||||
|
|
|
|||
|
|
@ -5,58 +5,58 @@ import llvm::{ValueRef, TypeRef, BasicBlockRef, BuilderRef, Opcode,
|
|||
ModuleRef};
|
||||
import trans_common::block_ctxt;
|
||||
|
||||
fn B(cx: &@block_ctxt) -> BuilderRef {
|
||||
fn B(cx: @block_ctxt) -> BuilderRef {
|
||||
let b = *cx.fcx.lcx.ccx.builder;
|
||||
llvm::LLVMPositionBuilderAtEnd(b, cx.llbb);
|
||||
ret b;
|
||||
}
|
||||
|
||||
fn RetVoid(cx: &@block_ctxt) -> ValueRef {
|
||||
fn RetVoid(cx: @block_ctxt) -> ValueRef {
|
||||
assert (!cx.terminated);
|
||||
cx.terminated = true;
|
||||
ret llvm::LLVMBuildRetVoid(B(cx));
|
||||
}
|
||||
|
||||
fn Ret(cx: &@block_ctxt, V: ValueRef) -> ValueRef {
|
||||
fn Ret(cx: @block_ctxt, V: ValueRef) -> ValueRef {
|
||||
assert (!cx.terminated);
|
||||
cx.terminated = true;
|
||||
ret llvm::LLVMBuildRet(B(cx), V);
|
||||
}
|
||||
|
||||
fn AggregateRet(cx: &@block_ctxt, RetVals: &[ValueRef]) -> ValueRef {
|
||||
fn AggregateRet(cx: @block_ctxt, RetVals: [ValueRef]) -> ValueRef {
|
||||
assert (!cx.terminated);
|
||||
cx.terminated = true;
|
||||
ret llvm::LLVMBuildAggregateRet(B(cx), vec::to_ptr(RetVals),
|
||||
vec::len(RetVals));
|
||||
}
|
||||
|
||||
fn Br(cx: &@block_ctxt, Dest: BasicBlockRef) -> ValueRef {
|
||||
fn Br(cx: @block_ctxt, Dest: BasicBlockRef) -> ValueRef {
|
||||
assert (!cx.terminated);
|
||||
cx.terminated = true;
|
||||
ret llvm::LLVMBuildBr(B(cx), Dest);
|
||||
}
|
||||
|
||||
fn CondBr(cx: &@block_ctxt, If: ValueRef, Then: BasicBlockRef,
|
||||
fn CondBr(cx: @block_ctxt, If: ValueRef, Then: BasicBlockRef,
|
||||
Else: BasicBlockRef) -> ValueRef {
|
||||
assert (!cx.terminated);
|
||||
cx.terminated = true;
|
||||
ret llvm::LLVMBuildCondBr(B(cx), If, Then, Else);
|
||||
}
|
||||
|
||||
fn Switch(cx: &@block_ctxt, V: ValueRef, Else: BasicBlockRef, NumCases: uint)
|
||||
fn Switch(cx: @block_ctxt, V: ValueRef, Else: BasicBlockRef, NumCases: uint)
|
||||
-> ValueRef {
|
||||
assert (!cx.terminated);
|
||||
cx.terminated = true;
|
||||
ret llvm::LLVMBuildSwitch(B(cx), V, Else, NumCases);
|
||||
}
|
||||
|
||||
fn IndirectBr(cx: &@block_ctxt, Addr: ValueRef, NumDests: uint) -> ValueRef {
|
||||
fn IndirectBr(cx: @block_ctxt, Addr: ValueRef, NumDests: uint) -> ValueRef {
|
||||
assert (!cx.terminated);
|
||||
cx.terminated = true;
|
||||
ret llvm::LLVMBuildIndirectBr(B(cx), Addr, NumDests);
|
||||
}
|
||||
|
||||
fn Invoke(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef],
|
||||
fn Invoke(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef],
|
||||
Then: BasicBlockRef, Catch: BasicBlockRef) -> ValueRef {
|
||||
assert (!cx.terminated);
|
||||
cx.terminated = true;
|
||||
|
|
@ -68,172 +68,171 @@ fn Invoke(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef],
|
|||
});
|
||||
}
|
||||
|
||||
fn Unreachable(cx: &@block_ctxt) -> ValueRef {
|
||||
fn Unreachable(cx: @block_ctxt) -> ValueRef {
|
||||
assert (!cx.terminated);
|
||||
cx.terminated = true;
|
||||
ret llvm::LLVMBuildUnreachable(B(cx));
|
||||
}
|
||||
|
||||
/* Arithmetic */
|
||||
fn Add(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn Add(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildAdd(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn NSWAdd(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn NSWAdd(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildNSWAdd(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn NUWAdd(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn NUWAdd(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildNUWAdd(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn FAdd(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn FAdd(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildFAdd(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn Sub(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn Sub(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildSub(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn NSWSub(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn NSWSub(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildNSWSub(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn NUWSub(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn NUWSub(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildNUWSub(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn FSub(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn FSub(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildFSub(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn Mul(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn Mul(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildMul(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn NSWMul(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn NSWMul(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildNSWMul(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn NUWMul(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn NUWMul(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildNUWMul(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn FMul(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn FMul(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildFMul(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn UDiv(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn UDiv(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildUDiv(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn SDiv(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn SDiv(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildSDiv(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn ExactSDiv(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn ExactSDiv(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf| llvm::LLVMBuildExactSDiv(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn FDiv(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn FDiv(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildFDiv(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn URem(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn URem(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildURem(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn SRem(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn SRem(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildSRem(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn FRem(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn FRem(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildFRem(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn Shl(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn Shl(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildShl(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn LShr(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn LShr(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildLShr(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn AShr(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn AShr(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildAShr(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn And(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn And(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildAnd(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn Or(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn Or(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildOr(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn Xor(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn Xor(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildXor(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn BinOp(cx: &@block_ctxt, Op: Opcode, LHS: ValueRef, RHS: ValueRef) ->
|
||||
fn BinOp(cx: @block_ctxt, Op: Opcode, LHS: ValueRef, RHS: ValueRef) ->
|
||||
ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf| llvm::LLVMBuildBinOp(B(cx), Op, LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn Neg(cx: &@block_ctxt, V: ValueRef) -> ValueRef {
|
||||
fn Neg(cx: @block_ctxt, V: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildNeg(B(cx), V, buf) });
|
||||
}
|
||||
|
||||
fn NSWNeg(cx: &@block_ctxt, V: ValueRef) -> ValueRef {
|
||||
fn NSWNeg(cx: @block_ctxt, V: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildNSWNeg(B(cx), V, buf) });
|
||||
}
|
||||
|
||||
fn NUWNeg(cx: &@block_ctxt, V: ValueRef) -> ValueRef {
|
||||
fn NUWNeg(cx: @block_ctxt, V: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildNUWNeg(B(cx), V, buf) });
|
||||
}
|
||||
fn FNeg(cx: &@block_ctxt, V: ValueRef) -> ValueRef {
|
||||
fn FNeg(cx: @block_ctxt, V: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildFNeg(B(cx), V, buf) });
|
||||
}
|
||||
|
||||
fn Not(cx: &@block_ctxt, V: ValueRef) -> ValueRef {
|
||||
fn Not(cx: @block_ctxt, V: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildNot(B(cx), V, buf) });
|
||||
}
|
||||
|
||||
/* Memory */
|
||||
fn Malloc(cx: &@block_ctxt, Ty: TypeRef) -> ValueRef {
|
||||
fn Malloc(cx: @block_ctxt, Ty: TypeRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildMalloc(B(cx), Ty, buf) });
|
||||
}
|
||||
|
||||
fn ArrayMalloc(cx: &@block_ctxt, Ty: TypeRef, Val: ValueRef) -> ValueRef {
|
||||
fn ArrayMalloc(cx: @block_ctxt, Ty: TypeRef, Val: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf| llvm::LLVMBuildArrayMalloc(B(cx), Ty, Val, buf) });
|
||||
}
|
||||
|
||||
fn Alloca(cx: &@block_ctxt, Ty: TypeRef) -> ValueRef {
|
||||
fn Alloca(cx: @block_ctxt, Ty: TypeRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildAlloca(B(cx), Ty, buf) });
|
||||
}
|
||||
|
||||
fn ArrayAlloca(cx: &@block_ctxt, Ty: TypeRef, Val: ValueRef) -> ValueRef {
|
||||
fn ArrayAlloca(cx: @block_ctxt, Ty: TypeRef, Val: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf| llvm::LLVMBuildArrayAlloca(B(cx), Ty, Val, buf) });
|
||||
}
|
||||
|
||||
fn Free(cx: &@block_ctxt, PointerVal: ValueRef) -> ValueRef {
|
||||
fn Free(cx: @block_ctxt, PointerVal: ValueRef) -> ValueRef {
|
||||
ret llvm::LLVMBuildFree(B(cx), PointerVal);
|
||||
}
|
||||
|
||||
fn Load(cx: &@block_ctxt, PointerVal: ValueRef) -> ValueRef {
|
||||
fn Load(cx: @block_ctxt, PointerVal: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildLoad(B(cx), PointerVal, buf) });
|
||||
}
|
||||
|
||||
fn Store(cx: &@block_ctxt, Val: ValueRef, Ptr: ValueRef) -> ValueRef {
|
||||
fn Store(cx: @block_ctxt, Val: ValueRef, Ptr: ValueRef) -> ValueRef {
|
||||
ret llvm::LLVMBuildStore(B(cx), Val, Ptr);
|
||||
}
|
||||
|
||||
fn GEP(cx: &@block_ctxt, Pointer: ValueRef, Indices: &[ValueRef]) ->
|
||||
ValueRef {
|
||||
fn GEP(cx: @block_ctxt, Pointer: ValueRef, Indices: [ValueRef]) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf|
|
||||
llvm::LLVMBuildGEP(B(cx), Pointer,
|
||||
|
|
@ -242,7 +241,7 @@ fn GEP(cx: &@block_ctxt, Pointer: ValueRef, Indices: &[ValueRef]) ->
|
|||
});
|
||||
}
|
||||
|
||||
fn InBoundsGEP(cx: &@block_ctxt, Pointer: ValueRef, Indices: &[ValueRef]) ->
|
||||
fn InBoundsGEP(cx: @block_ctxt, Pointer: ValueRef, Indices: [ValueRef]) ->
|
||||
ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf|
|
||||
|
|
@ -252,19 +251,19 @@ fn InBoundsGEP(cx: &@block_ctxt, Pointer: ValueRef, Indices: &[ValueRef]) ->
|
|||
});
|
||||
}
|
||||
|
||||
fn StructGEP(cx: &@block_ctxt, Pointer: ValueRef, Idx: uint) -> ValueRef {
|
||||
fn StructGEP(cx: @block_ctxt, Pointer: ValueRef, Idx: uint) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf|
|
||||
llvm::LLVMBuildStructGEP(B(cx), Pointer, Idx, buf)
|
||||
});
|
||||
}
|
||||
|
||||
fn GlobalString(cx: &@block_ctxt, _Str: sbuf) -> ValueRef {
|
||||
fn GlobalString(cx: @block_ctxt, _Str: sbuf) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf| llvm::LLVMBuildGlobalString(B(cx), _Str, buf) });
|
||||
}
|
||||
|
||||
fn GlobalStringPtr(cx: &@block_ctxt, _Str: sbuf) -> ValueRef {
|
||||
fn GlobalStringPtr(cx: @block_ctxt, _Str: sbuf) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf|
|
||||
llvm::LLVMBuildGlobalStringPtr(B(cx), _Str, buf)
|
||||
|
|
@ -272,71 +271,71 @@ fn GlobalStringPtr(cx: &@block_ctxt, _Str: sbuf) -> ValueRef {
|
|||
}
|
||||
|
||||
/* Casts */
|
||||
fn Trunc(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
fn Trunc(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf| llvm::LLVMBuildTrunc(B(cx), Val, DestTy, buf) });
|
||||
}
|
||||
|
||||
fn ZExt(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
fn ZExt(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf| llvm::LLVMBuildZExt(B(cx), Val, DestTy, buf) });
|
||||
}
|
||||
|
||||
fn SExt(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
fn SExt(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf| llvm::LLVMBuildSExt(B(cx), Val, DestTy, buf) });
|
||||
}
|
||||
|
||||
fn FPToUI(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
fn FPToUI(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf| llvm::LLVMBuildFPToUI(B(cx), Val, DestTy, buf) });
|
||||
}
|
||||
|
||||
fn FPToSI(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
fn FPToSI(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf| llvm::LLVMBuildFPToSI(B(cx), Val, DestTy, buf) });
|
||||
}
|
||||
|
||||
fn UIToFP(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
fn UIToFP(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf| llvm::LLVMBuildUIToFP(B(cx), Val, DestTy, buf) });
|
||||
}
|
||||
|
||||
fn SIToFP(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
fn SIToFP(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf| llvm::LLVMBuildSIToFP(B(cx), Val, DestTy, buf) });
|
||||
}
|
||||
|
||||
fn FPTrunc(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
fn FPTrunc(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf| llvm::LLVMBuildFPTrunc(B(cx), Val, DestTy, buf) });
|
||||
}
|
||||
|
||||
fn FPExt(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
fn FPExt(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf| llvm::LLVMBuildFPExt(B(cx), Val, DestTy, buf) });
|
||||
}
|
||||
|
||||
fn PtrToInt(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
fn PtrToInt(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf|
|
||||
llvm::LLVMBuildPtrToInt(B(cx), Val, DestTy, buf)
|
||||
});
|
||||
}
|
||||
|
||||
fn IntToPtr(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
fn IntToPtr(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf|
|
||||
llvm::LLVMBuildIntToPtr(B(cx), Val, DestTy, buf)
|
||||
});
|
||||
}
|
||||
|
||||
fn BitCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
fn BitCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf| llvm::LLVMBuildBitCast(B(cx), Val, DestTy, buf) });
|
||||
}
|
||||
|
||||
fn ZExtOrBitCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) ->
|
||||
fn ZExtOrBitCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) ->
|
||||
ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf|
|
||||
|
|
@ -344,7 +343,7 @@ fn ZExtOrBitCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) ->
|
|||
});
|
||||
}
|
||||
|
||||
fn SExtOrBitCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) ->
|
||||
fn SExtOrBitCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) ->
|
||||
ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf|
|
||||
|
|
@ -352,7 +351,7 @@ fn SExtOrBitCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) ->
|
|||
});
|
||||
}
|
||||
|
||||
fn TruncOrBitCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) ->
|
||||
fn TruncOrBitCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) ->
|
||||
ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf|
|
||||
|
|
@ -360,7 +359,7 @@ fn TruncOrBitCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) ->
|
|||
});
|
||||
}
|
||||
|
||||
fn Cast(cx: &@block_ctxt, Op: Opcode, Val: ValueRef, DestTy: TypeRef,
|
||||
fn Cast(cx: @block_ctxt, Op: Opcode, Val: ValueRef, DestTy: TypeRef,
|
||||
_Name: sbuf) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf|
|
||||
|
|
@ -368,41 +367,39 @@ fn Cast(cx: &@block_ctxt, Op: Opcode, Val: ValueRef, DestTy: TypeRef,
|
|||
});
|
||||
}
|
||||
|
||||
fn PointerCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
fn PointerCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf|
|
||||
llvm::LLVMBuildPointerCast(B(cx), Val, DestTy, buf)
|
||||
});
|
||||
}
|
||||
|
||||
fn IntCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
fn IntCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf| llvm::LLVMBuildIntCast(B(cx), Val, DestTy, buf) });
|
||||
}
|
||||
|
||||
fn FPCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
fn FPCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf| llvm::LLVMBuildFPCast(B(cx), Val, DestTy, buf) });
|
||||
}
|
||||
|
||||
|
||||
/* Comparisons */
|
||||
fn ICmp(cx: &@block_ctxt, Op: uint, LHS: ValueRef, RHS: ValueRef) ->
|
||||
ValueRef {
|
||||
fn ICmp(cx: @block_ctxt, Op: uint, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf| llvm::LLVMBuildICmp(B(cx), Op, LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn FCmp(cx: &@block_ctxt, Op: uint, LHS: ValueRef, RHS: ValueRef) ->
|
||||
ValueRef {
|
||||
fn FCmp(cx: @block_ctxt, Op: uint, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf| llvm::LLVMBuildFCmp(B(cx), Op, LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
|
||||
/* Miscellaneous instructions */
|
||||
fn Phi(cx: &@block_ctxt, Ty: TypeRef, vals: &[ValueRef],
|
||||
bbs: &[BasicBlockRef]) -> ValueRef {
|
||||
fn Phi(cx: @block_ctxt, Ty: TypeRef, vals: [ValueRef], bbs: [BasicBlockRef])
|
||||
-> ValueRef {
|
||||
let phi = str::as_buf("", {|buf| llvm::LLVMBuildPhi(B(cx), Ty, buf) });
|
||||
assert (vec::len::<ValueRef>(vals) == vec::len::<BasicBlockRef>(bbs));
|
||||
llvm::LLVMAddIncoming(phi, vec::to_ptr(vals), vec::to_ptr(bbs),
|
||||
|
|
@ -410,13 +407,13 @@ fn Phi(cx: &@block_ctxt, Ty: TypeRef, vals: &[ValueRef],
|
|||
ret phi;
|
||||
}
|
||||
|
||||
fn AddIncomingToPhi(phi: ValueRef, vals: &[ValueRef], bbs: &[BasicBlockRef]) {
|
||||
fn AddIncomingToPhi(phi: ValueRef, vals: [ValueRef], bbs: [BasicBlockRef]) {
|
||||
assert (vec::len::<ValueRef>(vals) == vec::len::<BasicBlockRef>(bbs));
|
||||
llvm::LLVMAddIncoming(phi, vec::to_ptr(vals), vec::to_ptr(bbs),
|
||||
vec::len(vals));
|
||||
}
|
||||
|
||||
fn Call(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef {
|
||||
fn Call(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef]) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf|
|
||||
llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
|
||||
|
|
@ -424,7 +421,7 @@ fn Call(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef {
|
|||
});
|
||||
}
|
||||
|
||||
fn FastCall(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef {
|
||||
fn FastCall(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef]) -> ValueRef {
|
||||
let v =
|
||||
str::as_buf("",
|
||||
{|buf|
|
||||
|
|
@ -435,7 +432,7 @@ fn FastCall(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef {
|
|||
ret v;
|
||||
}
|
||||
|
||||
fn CallWithConv(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef], Conv: uint)
|
||||
fn CallWithConv(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef], Conv: uint)
|
||||
-> ValueRef {
|
||||
let v =
|
||||
str::as_buf("",
|
||||
|
|
@ -447,7 +444,7 @@ fn CallWithConv(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef], Conv: uint)
|
|||
ret v;
|
||||
}
|
||||
|
||||
fn Select(cx: &@block_ctxt, If: ValueRef, Then: ValueRef, Else: ValueRef) ->
|
||||
fn Select(cx: @block_ctxt, If: ValueRef, Then: ValueRef, Else: ValueRef) ->
|
||||
ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf|
|
||||
|
|
@ -455,11 +452,11 @@ fn Select(cx: &@block_ctxt, If: ValueRef, Then: ValueRef, Else: ValueRef) ->
|
|||
});
|
||||
}
|
||||
|
||||
fn VAArg(cx: &@block_ctxt, list: ValueRef, Ty: TypeRef) -> ValueRef {
|
||||
fn VAArg(cx: @block_ctxt, list: ValueRef, Ty: TypeRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildVAArg(B(cx), list, Ty, buf) });
|
||||
}
|
||||
|
||||
fn ExtractElement(cx: &@block_ctxt, VecVal: ValueRef, Index: ValueRef) ->
|
||||
fn ExtractElement(cx: @block_ctxt, VecVal: ValueRef, Index: ValueRef) ->
|
||||
ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf|
|
||||
|
|
@ -468,7 +465,7 @@ fn ExtractElement(cx: &@block_ctxt, VecVal: ValueRef, Index: ValueRef) ->
|
|||
});
|
||||
}
|
||||
|
||||
fn InsertElement(cx: &@block_ctxt, VecVal: ValueRef, EltVal: ValueRef,
|
||||
fn InsertElement(cx: @block_ctxt, VecVal: ValueRef, EltVal: ValueRef,
|
||||
Index: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf|
|
||||
|
|
@ -477,7 +474,7 @@ fn InsertElement(cx: &@block_ctxt, VecVal: ValueRef, EltVal: ValueRef,
|
|||
});
|
||||
}
|
||||
|
||||
fn ShuffleVector(cx: &@block_ctxt, V1: ValueRef, V2: ValueRef, Mask: ValueRef)
|
||||
fn ShuffleVector(cx: @block_ctxt, V1: ValueRef, V2: ValueRef, Mask: ValueRef)
|
||||
-> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf|
|
||||
|
|
@ -485,14 +482,14 @@ fn ShuffleVector(cx: &@block_ctxt, V1: ValueRef, V2: ValueRef, Mask: ValueRef)
|
|||
});
|
||||
}
|
||||
|
||||
fn ExtractValue(cx: &@block_ctxt, AggVal: ValueRef, Index: uint) -> ValueRef {
|
||||
fn ExtractValue(cx: @block_ctxt, AggVal: ValueRef, Index: uint) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf|
|
||||
llvm::LLVMBuildExtractValue(B(cx), AggVal, Index, buf)
|
||||
});
|
||||
}
|
||||
|
||||
fn InsertValue(cx: &@block_ctxt, AggVal: ValueRef, EltVal: ValueRef,
|
||||
fn InsertValue(cx: @block_ctxt, AggVal: ValueRef, EltVal: ValueRef,
|
||||
Index: uint) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf|
|
||||
|
|
@ -501,20 +498,20 @@ fn InsertValue(cx: &@block_ctxt, AggVal: ValueRef, EltVal: ValueRef,
|
|||
});
|
||||
}
|
||||
|
||||
fn IsNull(cx: &@block_ctxt, Val: ValueRef) -> ValueRef {
|
||||
fn IsNull(cx: @block_ctxt, Val: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildIsNull(B(cx), Val, buf) });
|
||||
}
|
||||
|
||||
fn IsNotNull(cx: &@block_ctxt, Val: ValueRef) -> ValueRef {
|
||||
fn IsNotNull(cx: @block_ctxt, Val: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("", {|buf| llvm::LLVMBuildIsNotNull(B(cx), Val, buf) });
|
||||
}
|
||||
|
||||
fn PtrDiff(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
fn PtrDiff(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
||||
ret str::as_buf("",
|
||||
{|buf| llvm::LLVMBuildPtrDiff(B(cx), LHS, RHS, buf) });
|
||||
}
|
||||
|
||||
fn Trap(cx: &@block_ctxt) -> ValueRef {
|
||||
fn Trap(cx: @block_ctxt) -> ValueRef {
|
||||
let b = B(cx);
|
||||
let BB: BasicBlockRef = llvm::LLVMGetInsertBlock(b);
|
||||
let FN: ValueRef = llvm::LLVMGetBasicBlockParent(BB);
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ import trans::type_of_fn_full;
|
|||
import trans::drop_ty;
|
||||
|
||||
obj namegen(mutable i: int) {
|
||||
fn next(prefix: &str) -> str { i += 1; ret prefix + int::str(i); }
|
||||
fn next(prefix: str) -> str { i += 1; ret prefix + int::str(i); }
|
||||
}
|
||||
|
||||
type derived_tydesc_info = {lltydesc: ValueRef, escapes: bool};
|
||||
|
|
@ -291,15 +291,15 @@ type fn_ctxt =
|
|||
lcx: @local_ctxt};
|
||||
|
||||
tag cleanup {
|
||||
clean(fn(&@block_ctxt) -> @block_ctxt);
|
||||
clean_temp(ValueRef, fn(&@block_ctxt) -> @block_ctxt);
|
||||
clean(fn(@block_ctxt) -> @block_ctxt);
|
||||
clean_temp(ValueRef, fn(@block_ctxt) -> @block_ctxt);
|
||||
}
|
||||
|
||||
fn add_clean(cx: &@block_ctxt, val: ValueRef, ty: ty::t) {
|
||||
fn add_clean(cx: @block_ctxt, val: ValueRef, ty: ty::t) {
|
||||
find_scope_cx(cx).cleanups += [clean(bind drop_ty(_, val, ty))];
|
||||
}
|
||||
fn add_clean_temp(cx: &@block_ctxt, val: ValueRef, ty: ty::t) {
|
||||
fn spill_and_drop(cx: &@block_ctxt, val: ValueRef, ty: ty::t) ->
|
||||
fn add_clean_temp(cx: @block_ctxt, val: ValueRef, ty: ty::t) {
|
||||
fn spill_and_drop(cx: @block_ctxt, val: ValueRef, ty: ty::t) ->
|
||||
@block_ctxt {
|
||||
let bcx = cx;
|
||||
let r = trans::spill_if_immediate(bcx, val, ty);
|
||||
|
|
@ -315,7 +315,7 @@ fn add_clean_temp(cx: &@block_ctxt, val: ValueRef, ty: ty::t) {
|
|||
// to a system where we can also cancel the cleanup on local variables, but
|
||||
// this will be more involved. For now, we simply zero out the local, and the
|
||||
// drop glue checks whether it is zero.
|
||||
fn revoke_clean(cx: &@block_ctxt, val: ValueRef, t: ty::t) -> @block_ctxt {
|
||||
fn revoke_clean(cx: @block_ctxt, val: ValueRef, t: ty::t) -> @block_ctxt {
|
||||
if ty::type_is_unique(bcx_tcx(cx), t) {
|
||||
// Just zero out the allocation. This ensures that the GC won't try to
|
||||
// traverse dangling pointers.
|
||||
|
|
@ -346,8 +346,8 @@ fn revoke_clean(cx: &@block_ctxt, val: ValueRef, t: ty::t) -> @block_ctxt {
|
|||
ret cx;
|
||||
}
|
||||
|
||||
fn get_res_dtor(ccx: &@crate_ctxt, sp: &span, did: &ast::def_id,
|
||||
inner_t: ty::t) -> ValueRef {
|
||||
fn get_res_dtor(ccx: @crate_ctxt, sp: span, did: ast::def_id, inner_t: ty::t)
|
||||
-> ValueRef {
|
||||
if did.crate == ast::local_crate {
|
||||
alt ccx.fn_pairs.find(did.node) {
|
||||
some(x) { ret x; }
|
||||
|
|
@ -418,7 +418,7 @@ type block_ctxt =
|
|||
sp: span,
|
||||
fcx: @fn_ctxt};
|
||||
|
||||
fn is_terminated(cx: &@block_ctxt) -> bool { ret cx.terminated; }
|
||||
fn is_terminated(cx: @block_ctxt) -> bool { ret cx.terminated; }
|
||||
|
||||
// FIXME: we should be able to use option::t<@block_parent> here but
|
||||
// the infinite-tag check in rustboot gets upset.
|
||||
|
|
@ -427,7 +427,7 @@ tag block_parent { parent_none; parent_some(@block_ctxt); }
|
|||
type result = {bcx: @block_ctxt, val: ValueRef};
|
||||
type result_t = {bcx: @block_ctxt, val: ValueRef, ty: ty::t};
|
||||
|
||||
fn extend_path(cx: @local_ctxt, name: &str) -> @local_ctxt {
|
||||
fn extend_path(cx: @local_ctxt, name: str) -> @local_ctxt {
|
||||
ret @{path: cx.path + [name] with *cx};
|
||||
}
|
||||
|
||||
|
|
@ -452,7 +452,7 @@ fn struct_elt(llstructty: TypeRef, n: uint) -> TypeRef {
|
|||
ret llvm::LLVMGetElementType(elt_tys[n]);
|
||||
}
|
||||
|
||||
fn find_scope_cx(cx: &@block_ctxt) -> @block_ctxt {
|
||||
fn find_scope_cx(cx: @block_ctxt) -> @block_ctxt {
|
||||
if cx.kind != NON_SCOPE_BLOCK { ret cx; }
|
||||
alt cx.parent {
|
||||
parent_some(b) { ret find_scope_cx(b); }
|
||||
|
|
@ -466,14 +466,14 @@ fn find_scope_cx(cx: &@block_ctxt) -> @block_ctxt {
|
|||
// Accessors
|
||||
// TODO: When we have overloading, simplify these names!
|
||||
|
||||
fn bcx_tcx(bcx: &@block_ctxt) -> ty::ctxt { ret bcx.fcx.lcx.ccx.tcx; }
|
||||
fn bcx_ccx(bcx: &@block_ctxt) -> @crate_ctxt { ret bcx.fcx.lcx.ccx; }
|
||||
fn bcx_lcx(bcx: &@block_ctxt) -> @local_ctxt { ret bcx.fcx.lcx; }
|
||||
fn bcx_fcx(bcx: &@block_ctxt) -> @fn_ctxt { ret bcx.fcx; }
|
||||
fn fcx_ccx(fcx: &@fn_ctxt) -> @crate_ctxt { ret fcx.lcx.ccx; }
|
||||
fn fcx_tcx(fcx: &@fn_ctxt) -> ty::ctxt { ret fcx.lcx.ccx.tcx; }
|
||||
fn lcx_ccx(lcx: &@local_ctxt) -> @crate_ctxt { ret lcx.ccx; }
|
||||
fn ccx_tcx(ccx: &@crate_ctxt) -> ty::ctxt { ret ccx.tcx; }
|
||||
fn bcx_tcx(bcx: @block_ctxt) -> ty::ctxt { ret bcx.fcx.lcx.ccx.tcx; }
|
||||
fn bcx_ccx(bcx: @block_ctxt) -> @crate_ctxt { ret bcx.fcx.lcx.ccx; }
|
||||
fn bcx_lcx(bcx: @block_ctxt) -> @local_ctxt { ret bcx.fcx.lcx; }
|
||||
fn bcx_fcx(bcx: @block_ctxt) -> @fn_ctxt { ret bcx.fcx; }
|
||||
fn fcx_ccx(fcx: @fn_ctxt) -> @crate_ctxt { ret fcx.lcx.ccx; }
|
||||
fn fcx_tcx(fcx: @fn_ctxt) -> ty::ctxt { ret fcx.lcx.ccx.tcx; }
|
||||
fn lcx_ccx(lcx: @local_ctxt) -> @crate_ctxt { ret lcx.ccx; }
|
||||
fn ccx_tcx(ccx: @crate_ctxt) -> ty::ctxt { ret ccx.tcx; }
|
||||
|
||||
// LLVM type constructors.
|
||||
fn T_void() -> TypeRef {
|
||||
|
|
@ -532,27 +532,27 @@ fn T_size_t() -> TypeRef {
|
|||
ret T_i32();
|
||||
}
|
||||
|
||||
fn T_fn(inputs: &[TypeRef], output: TypeRef) -> TypeRef {
|
||||
fn T_fn(inputs: [TypeRef], output: TypeRef) -> TypeRef {
|
||||
ret llvm::LLVMFunctionType(output, to_ptr(inputs),
|
||||
std::vec::len::<TypeRef>(inputs), False);
|
||||
}
|
||||
|
||||
fn T_fn_pair(cx: &crate_ctxt, tfn: TypeRef) -> TypeRef {
|
||||
fn T_fn_pair(cx: crate_ctxt, tfn: TypeRef) -> TypeRef {
|
||||
ret T_struct([T_ptr(tfn), T_opaque_closure_ptr(cx)]);
|
||||
}
|
||||
|
||||
fn T_ptr(t: TypeRef) -> TypeRef { ret llvm::LLVMPointerType(t, 0u); }
|
||||
|
||||
fn T_struct(elts: &[TypeRef]) -> TypeRef {
|
||||
fn T_struct(elts: [TypeRef]) -> TypeRef {
|
||||
ret llvm::LLVMStructType(to_ptr(elts), std::vec::len(elts), False);
|
||||
}
|
||||
|
||||
fn T_named_struct(name: &str) -> TypeRef {
|
||||
fn T_named_struct(name: str) -> TypeRef {
|
||||
let c = llvm::LLVMGetGlobalContext();
|
||||
ret str::as_buf(name, {|buf| llvm::LLVMStructCreateNamed(c, buf) });
|
||||
}
|
||||
|
||||
fn set_struct_body(t: TypeRef, elts: &[TypeRef]) {
|
||||
fn set_struct_body(t: TypeRef, elts: [TypeRef]) {
|
||||
llvm::LLVMStructSetBody(t, to_ptr(elts), std::vec::len(elts), False);
|
||||
}
|
||||
|
||||
|
|
@ -590,7 +590,7 @@ fn T_task() -> TypeRef {
|
|||
ret t;
|
||||
}
|
||||
|
||||
fn T_tydesc_field(cx: &crate_ctxt, field: int) -> TypeRef {
|
||||
fn T_tydesc_field(cx: crate_ctxt, field: int) -> TypeRef {
|
||||
// Bit of a kludge: pick the fn typeref out of the tydesc..
|
||||
|
||||
let tydesc_elts: [TypeRef] =
|
||||
|
|
@ -601,7 +601,7 @@ fn T_tydesc_field(cx: &crate_ctxt, field: int) -> TypeRef {
|
|||
ret t;
|
||||
}
|
||||
|
||||
fn T_glue_fn(cx: &crate_ctxt) -> TypeRef {
|
||||
fn T_glue_fn(cx: crate_ctxt) -> TypeRef {
|
||||
let s = "glue_fn";
|
||||
if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
|
||||
let t = T_tydesc_field(cx, abi::tydesc_field_drop_glue);
|
||||
|
|
@ -609,7 +609,7 @@ fn T_glue_fn(cx: &crate_ctxt) -> TypeRef {
|
|||
ret t;
|
||||
}
|
||||
|
||||
fn T_cmp_glue_fn(cx: &crate_ctxt) -> TypeRef {
|
||||
fn T_cmp_glue_fn(cx: crate_ctxt) -> TypeRef {
|
||||
let s = "cmp_glue_fn";
|
||||
if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
|
||||
let t = T_tydesc_field(cx, abi::tydesc_field_cmp_glue);
|
||||
|
|
@ -663,11 +663,11 @@ fn T_chan(_t: TypeRef) -> TypeRef {
|
|||
|
||||
}
|
||||
|
||||
fn T_taskptr(cx: &crate_ctxt) -> TypeRef { ret T_ptr(cx.task_type); }
|
||||
fn T_taskptr(cx: crate_ctxt) -> TypeRef { ret T_ptr(cx.task_type); }
|
||||
|
||||
|
||||
// This type must never be used directly; it must always be cast away.
|
||||
fn T_typaram(tn: &type_names) -> TypeRef {
|
||||
fn T_typaram(tn: type_names) -> TypeRef {
|
||||
let s = "typaram";
|
||||
if tn.name_has_type(s) { ret tn.get_type(s); }
|
||||
let t = T_i8();
|
||||
|
|
@ -675,10 +675,10 @@ fn T_typaram(tn: &type_names) -> TypeRef {
|
|||
ret t;
|
||||
}
|
||||
|
||||
fn T_typaram_ptr(tn: &type_names) -> TypeRef { ret T_ptr(T_typaram(tn)); }
|
||||
fn T_typaram_ptr(tn: type_names) -> TypeRef { ret T_ptr(T_typaram(tn)); }
|
||||
|
||||
fn T_closure_ptr(cx: &crate_ctxt, llbindings_ty: TypeRef, n_ty_params: uint)
|
||||
-> TypeRef {
|
||||
fn T_closure_ptr(cx: crate_ctxt, llbindings_ty: TypeRef, n_ty_params: uint) ->
|
||||
TypeRef {
|
||||
// NB: keep this in sync with code in trans_bind; we're making
|
||||
// an LLVM typeref structure that has the same "shape" as the ty::t
|
||||
// it constructs.
|
||||
|
|
@ -686,7 +686,7 @@ fn T_closure_ptr(cx: &crate_ctxt, llbindings_ty: TypeRef, n_ty_params: uint)
|
|||
T_captured_tydescs(cx, n_ty_params)])));
|
||||
}
|
||||
|
||||
fn T_opaque_closure_ptr(cx: &crate_ctxt) -> TypeRef {
|
||||
fn T_opaque_closure_ptr(cx: crate_ctxt) -> TypeRef {
|
||||
let s = "*closure";
|
||||
if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
|
||||
let t = T_closure_ptr(cx, T_nil(), 0u);
|
||||
|
|
@ -694,19 +694,18 @@ fn T_opaque_closure_ptr(cx: &crate_ctxt) -> TypeRef {
|
|||
ret t;
|
||||
}
|
||||
|
||||
fn T_tag(tn: &type_names, size: uint) -> TypeRef {
|
||||
fn T_tag(tn: type_names, size: uint) -> TypeRef {
|
||||
let s = "tag_" + uint::to_str(size, 10u);
|
||||
if tn.name_has_type(s) { ret tn.get_type(s); }
|
||||
let t = if size == 0u {
|
||||
T_struct([T_int()])
|
||||
} else {
|
||||
T_struct([T_int(), T_array(T_i8(), size)])
|
||||
};
|
||||
let t =
|
||||
if size == 0u {
|
||||
T_struct([T_int()])
|
||||
} else { T_struct([T_int(), T_array(T_i8(), size)]) };
|
||||
tn.associate(s, t);
|
||||
ret t;
|
||||
}
|
||||
|
||||
fn T_opaque_tag(tn: &type_names) -> TypeRef {
|
||||
fn T_opaque_tag(tn: type_names) -> TypeRef {
|
||||
let s = "opaque_tag";
|
||||
if tn.name_has_type(s) { ret tn.get_type(s); }
|
||||
let t = T_struct([T_int(), T_i8()]);
|
||||
|
|
@ -714,26 +713,26 @@ fn T_opaque_tag(tn: &type_names) -> TypeRef {
|
|||
ret t;
|
||||
}
|
||||
|
||||
fn T_opaque_tag_ptr(tn: &type_names) -> TypeRef {
|
||||
fn T_opaque_tag_ptr(tn: type_names) -> TypeRef {
|
||||
ret T_ptr(T_opaque_tag(tn));
|
||||
}
|
||||
|
||||
fn T_captured_tydescs(cx: &crate_ctxt, n: uint) -> TypeRef {
|
||||
fn T_captured_tydescs(cx: crate_ctxt, n: uint) -> TypeRef {
|
||||
ret T_struct(std::vec::init_elt::<TypeRef>(T_ptr(cx.tydesc_type), n));
|
||||
}
|
||||
|
||||
fn T_obj_ptr(cx: &crate_ctxt, n_captured_tydescs: uint) -> TypeRef {
|
||||
fn T_obj_ptr(cx: crate_ctxt, n_captured_tydescs: uint) -> TypeRef {
|
||||
// This function is not publicly exposed because it returns an incomplete
|
||||
// type. The dynamically-sized fields follow the captured tydescs.
|
||||
|
||||
fn T_obj(cx: &crate_ctxt, n_captured_tydescs: uint) -> TypeRef {
|
||||
fn T_obj(cx: crate_ctxt, n_captured_tydescs: uint) -> TypeRef {
|
||||
ret T_struct([T_ptr(cx.tydesc_type),
|
||||
T_captured_tydescs(cx, n_captured_tydescs)]);
|
||||
}
|
||||
ret T_ptr(T_box(T_obj(cx, n_captured_tydescs)));
|
||||
}
|
||||
|
||||
fn T_opaque_obj_ptr(cx: &crate_ctxt) -> TypeRef { ret T_obj_ptr(cx, 0u); }
|
||||
fn T_opaque_obj_ptr(cx: crate_ctxt) -> TypeRef { ret T_obj_ptr(cx, 0u); }
|
||||
|
||||
fn T_opaque_port_ptr() -> TypeRef { ret T_ptr(T_i8()); }
|
||||
|
||||
|
|
@ -753,11 +752,11 @@ fn C_integral(t: TypeRef, u: uint, sign_extend: Bool) -> ValueRef {
|
|||
ret llvm::LLVMRustConstSmallInt(t, u, sign_extend);
|
||||
}
|
||||
|
||||
fn C_float(s: &str) -> ValueRef {
|
||||
fn C_float(s: str) -> ValueRef {
|
||||
ret str::as_buf(s, {|buf| llvm::LLVMConstRealOfString(T_float(), buf) });
|
||||
}
|
||||
|
||||
fn C_floating(s: &str, t: TypeRef) -> ValueRef {
|
||||
fn C_floating(s: str, t: TypeRef) -> ValueRef {
|
||||
ret str::as_buf(s, {|buf| llvm::LLVMConstRealOfString(t, buf) });
|
||||
}
|
||||
|
||||
|
|
@ -782,7 +781,7 @@ fn C_u8(i: uint) -> ValueRef { ret C_integral(T_i8(), i, False); }
|
|||
|
||||
// This is a 'c-like' raw string, which differs from
|
||||
// our boxed-and-length-annotated strings.
|
||||
fn C_cstr(cx: &@crate_ctxt, s: &str) -> ValueRef {
|
||||
fn C_cstr(cx: @crate_ctxt, s: str) -> ValueRef {
|
||||
let sc =
|
||||
str::as_buf(s,
|
||||
{|buf|
|
||||
|
|
@ -798,7 +797,7 @@ fn C_cstr(cx: &@crate_ctxt, s: &str) -> ValueRef {
|
|||
}
|
||||
|
||||
// Returns a Plain Old LLVM String:
|
||||
fn C_postr(s: &str) -> ValueRef {
|
||||
fn C_postr(s: str) -> ValueRef {
|
||||
ret str::as_buf(s,
|
||||
{|buf|
|
||||
llvm::LLVMConstString(buf, str::byte_len(s), False)
|
||||
|
|
@ -813,26 +812,26 @@ fn C_zero_byte_arr(size: uint) -> ValueRef {
|
|||
std::vec::len(elts));
|
||||
}
|
||||
|
||||
fn C_struct(elts: &[ValueRef]) -> ValueRef {
|
||||
fn C_struct(elts: [ValueRef]) -> ValueRef {
|
||||
ret llvm::LLVMConstStruct(std::vec::to_ptr(elts), std::vec::len(elts),
|
||||
False);
|
||||
}
|
||||
|
||||
fn C_named_struct(T: TypeRef, elts: &[ValueRef]) -> ValueRef {
|
||||
fn C_named_struct(T: TypeRef, elts: [ValueRef]) -> ValueRef {
|
||||
ret llvm::LLVMConstNamedStruct(T, std::vec::to_ptr(elts),
|
||||
std::vec::len(elts));
|
||||
}
|
||||
|
||||
fn C_array(ty: TypeRef, elts: &[ValueRef]) -> ValueRef {
|
||||
fn C_array(ty: TypeRef, elts: [ValueRef]) -> ValueRef {
|
||||
ret llvm::LLVMConstArray(ty, std::vec::to_ptr(elts), std::vec::len(elts));
|
||||
}
|
||||
|
||||
fn C_bytes(bytes: &[u8]) -> ValueRef {
|
||||
fn C_bytes(bytes: [u8]) -> ValueRef {
|
||||
ret llvm::LLVMConstString(unsafe::reinterpret_cast(vec::to_ptr(bytes)),
|
||||
vec::len(bytes), False);
|
||||
}
|
||||
|
||||
fn C_shape(ccx: &@crate_ctxt, bytes: &[u8]) -> ValueRef {
|
||||
fn C_shape(ccx: @crate_ctxt, bytes: [u8]) -> ValueRef {
|
||||
let llshape = C_bytes(bytes);
|
||||
let llglobal =
|
||||
str::as_buf(ccx.names.next("shape"),
|
||||
|
|
@ -847,8 +846,8 @@ fn C_shape(ccx: &@crate_ctxt, bytes: &[u8]) -> ValueRef {
|
|||
}
|
||||
|
||||
|
||||
pure fn valid_variant_index(ix: uint, cx: @block_ctxt, tag_id: &ast::def_id,
|
||||
variant_id: &ast::def_id) -> bool {
|
||||
pure fn valid_variant_index(ix: uint, cx: @block_ctxt, tag_id: ast::def_id,
|
||||
variant_id: ast::def_id) -> bool {
|
||||
|
||||
// Handwaving: it's ok to pretend this code is referentially
|
||||
// transparent, because the relevant parts of the type context don't
|
||||
|
|
@ -860,7 +859,7 @@ pure fn valid_variant_index(ix: uint, cx: @block_ctxt, tag_id: &ast::def_id,
|
|||
}
|
||||
}
|
||||
|
||||
pure fn type_has_static_size(cx: &@crate_ctxt, t: ty::t) -> bool {
|
||||
pure fn type_has_static_size(cx: @crate_ctxt, t: ty::t) -> bool {
|
||||
!ty::type_has_dynamic_size(cx.tcx, t)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ export trans_obj;
|
|||
|
||||
// trans_obj: create an LLVM function that is the object constructor for the
|
||||
// object being translated.
|
||||
fn trans_obj(cx: @local_ctxt, sp: &span, ob: &ast::_obj,
|
||||
ctor_id: ast::node_id, ty_params: &[ast::ty_param]) {
|
||||
fn trans_obj(cx: @local_ctxt, sp: span, ob: ast::_obj, ctor_id: ast::node_id,
|
||||
ty_params: [ast::ty_param]) {
|
||||
|
||||
// To make a function, we have to create a function context and, inside
|
||||
// that, a number of block contexts for which code is generated.
|
||||
|
|
@ -48,8 +48,7 @@ fn trans_obj(cx: @local_ctxt, sp: &span, ob: &ast::_obj,
|
|||
// we're creating.
|
||||
let fn_args: [ast::arg] = [];
|
||||
for f: ast::obj_field in ob.fields {
|
||||
fn_args +=
|
||||
[{mode: ast::by_ref, ty: f.ty, ident: f.ident, id: f.id}];
|
||||
fn_args += [{mode: ast::by_ref, ty: f.ty, ident: f.ident, id: f.id}];
|
||||
}
|
||||
let fcx = new_fn_ctxt(cx, sp, llctor_decl);
|
||||
|
||||
|
|
@ -205,7 +204,7 @@ fn trans_obj(cx: @local_ctxt, sp: &span, ob: &ast::_obj,
|
|||
// function and putting it in the generated code as an object item, we are
|
||||
// instead "inlining" the construction of the object and returning the object
|
||||
// itself.
|
||||
fn trans_anon_obj(bcx: @block_ctxt, sp: &span, anon_obj: &ast::anon_obj,
|
||||
fn trans_anon_obj(bcx: @block_ctxt, sp: span, anon_obj: ast::anon_obj,
|
||||
id: ast::node_id) -> result {
|
||||
|
||||
let ccx = bcx_ccx(bcx);
|
||||
|
|
@ -394,12 +393,12 @@ tag vtbl_mthd {
|
|||
}
|
||||
|
||||
// Alphabetize ast::methods by ident. A helper for create_vtbl.
|
||||
fn ast_mthd_lteq(a: &@ast::method, b: &@ast::method) -> bool {
|
||||
fn ast_mthd_lteq(a: @ast::method, b: @ast::method) -> bool {
|
||||
ret str::lteq(a.node.ident, b.node.ident);
|
||||
}
|
||||
|
||||
// Alphabetize vtbl_mthds by ident. A helper for create_vtbl.
|
||||
fn vtbl_mthd_lteq(a: &vtbl_mthd, b: &vtbl_mthd) -> bool {
|
||||
fn vtbl_mthd_lteq(a: vtbl_mthd, b: vtbl_mthd) -> bool {
|
||||
alt a {
|
||||
normal_mthd(ma) {
|
||||
alt b {
|
||||
|
|
@ -418,8 +417,8 @@ fn vtbl_mthd_lteq(a: &vtbl_mthd, b: &vtbl_mthd) -> bool {
|
|||
|
||||
// filtering_fn: Used by create_vtbl to filter a list of methods to remove the
|
||||
// ones that we don't need forwarding slots for.
|
||||
fn filtering_fn(cx: @local_ctxt, m: &vtbl_mthd, addtl_meths: [@ast::method])
|
||||
-> option::t<vtbl_mthd> {
|
||||
fn filtering_fn(cx: @local_ctxt, m: vtbl_mthd, addtl_meths: [@ast::method]) ->
|
||||
option::t<vtbl_mthd> {
|
||||
|
||||
// Since m is a fwding_mthd, and we're checking to see if it's in
|
||||
// addtl_meths (which only contains normal_mthds), we can't just check if
|
||||
|
|
@ -442,10 +441,9 @@ fn filtering_fn(cx: @local_ctxt, m: &vtbl_mthd, addtl_meths: [@ast::method])
|
|||
|
||||
// create_vtbl: Create a vtable for a regular object or for an outer anonymous
|
||||
// object, and return a pointer to it.
|
||||
fn create_vtbl(cx: @local_ctxt, sp: &span, outer_obj_ty: ty::t,
|
||||
ob: &ast::_obj, ty_params: &[ast::ty_param],
|
||||
inner_obj_ty: option::t<ty::t>, additional_field_tys: &[ty::t])
|
||||
-> ValueRef {
|
||||
fn create_vtbl(cx: @local_ctxt, sp: span, outer_obj_ty: ty::t, ob: ast::_obj,
|
||||
ty_params: [ast::ty_param], inner_obj_ty: option::t<ty::t>,
|
||||
additional_field_tys: [ty::t]) -> ValueRef {
|
||||
|
||||
let llmethods: [ValueRef] = [];
|
||||
|
||||
|
|
@ -531,7 +529,7 @@ fn create_vtbl(cx: @local_ctxt, sp: &span, outer_obj_ty: ty::t,
|
|||
// create_backwarding_vtbl: Create a vtable for the inner object of an
|
||||
// anonymous object, so that any self-calls made from the inner object's
|
||||
// methods get redirected appropriately.
|
||||
fn create_backwarding_vtbl(cx: @local_ctxt, sp: &span, inner_obj_ty: ty::t,
|
||||
fn create_backwarding_vtbl(cx: @local_ctxt, sp: span, inner_obj_ty: ty::t,
|
||||
outer_obj_ty: ty::t) -> ValueRef {
|
||||
|
||||
// This vtbl needs to have slots for all of the methods on an inner
|
||||
|
|
@ -564,7 +562,7 @@ fn create_backwarding_vtbl(cx: @local_ctxt, sp: &span, inner_obj_ty: ty::t,
|
|||
|
||||
// finish_vtbl: Given a vector of vtable entries, create the table in
|
||||
// read-only memory and return a pointer to it.
|
||||
fn finish_vtbl(cx: @local_ctxt, llmethods: [ValueRef], name: &str) ->
|
||||
fn finish_vtbl(cx: @local_ctxt, llmethods: [ValueRef], name: str) ->
|
||||
ValueRef {
|
||||
let vtbl = C_struct(llmethods);
|
||||
let vtbl_name = mangle_internal_name_by_path(cx.ccx, cx.path + [name]);
|
||||
|
|
@ -594,9 +592,9 @@ fn finish_vtbl(cx: @local_ctxt, llmethods: [ValueRef], name: &str) ->
|
|||
// one for each method on inner, each of which takes all the same arguments as
|
||||
// the corresponding method on inner does, calls that method on outer, and
|
||||
// returns the value returned from that call.
|
||||
fn process_bkwding_mthd(cx: @local_ctxt, sp: &span, m: @ty::method,
|
||||
ty_params: &[ast::ty_param], outer_obj_ty: ty::t,
|
||||
_additional_field_tys: &[ty::t]) -> ValueRef {
|
||||
fn process_bkwding_mthd(cx: @local_ctxt, sp: span, m: @ty::method,
|
||||
ty_params: [ast::ty_param], outer_obj_ty: ty::t,
|
||||
_additional_field_tys: [ty::t]) -> ValueRef {
|
||||
|
||||
// Create a local context that's aware of the name of the method we're
|
||||
// creating.
|
||||
|
|
@ -717,10 +715,10 @@ fn process_bkwding_mthd(cx: @local_ctxt, sp: &span, m: @ty::method,
|
|||
// calls inner.foo() with those arguments, and then returns the value returned
|
||||
// from that call. (The inner object won't exist until run-time, but we know
|
||||
// its type statically.)
|
||||
fn process_fwding_mthd(cx: @local_ctxt, sp: &span, m: @ty::method,
|
||||
ty_params: &[ast::ty_param], inner_obj_ty: ty::t,
|
||||
fn process_fwding_mthd(cx: @local_ctxt, sp: span, m: @ty::method,
|
||||
ty_params: [ast::ty_param], inner_obj_ty: ty::t,
|
||||
backwarding_vtbl: ValueRef,
|
||||
additional_field_tys: &[ty::t]) -> ValueRef {
|
||||
additional_field_tys: [ty::t]) -> ValueRef {
|
||||
|
||||
// Create a local context that's aware of the name of the method we're
|
||||
// creating.
|
||||
|
|
@ -783,11 +781,11 @@ fn process_fwding_mthd(cx: @local_ctxt, sp: &span, m: @ty::method,
|
|||
// create_object_body_type maybe should have a postcondition...
|
||||
|
||||
let cx_ccx = cx.ccx;
|
||||
check type_has_static_size(cx_ccx, body_ty);
|
||||
check (type_has_static_size(cx_ccx, body_ty));
|
||||
|
||||
llself_obj_body =
|
||||
PointerCast(bcx, llself_obj_body,
|
||||
T_ptr(type_of(cx_ccx, sp, body_ty)));
|
||||
T_ptr(type_of(cx_ccx, sp, body_ty)));
|
||||
|
||||
// Now, reach into the body and grab the inner_obj.
|
||||
let llinner_obj =
|
||||
|
|
@ -873,8 +871,8 @@ fn process_fwding_mthd(cx: @local_ctxt, sp: &span, m: @ty::method,
|
|||
|
||||
// create_object_body_type: Synthesize a big structural tuple type for an
|
||||
// object body: [tydesc, [typaram, ...], [field, ...], inner_obj].
|
||||
fn create_object_body_type(tcx: &ty::ctxt, fields_ty: &[ty::t],
|
||||
typarams_ty: &[ty::t],
|
||||
fn create_object_body_type(tcx: ty::ctxt, fields_ty: [ty::t],
|
||||
typarams_ty: [ty::t],
|
||||
maybe_inner_obj_ty: option::t<ty::t>) -> ty::t {
|
||||
|
||||
let tydesc_ty: ty::t = ty::mk_type(tcx);
|
||||
|
|
@ -901,7 +899,7 @@ fn create_object_body_type(tcx: &ty::ctxt, fields_ty: &[ty::t],
|
|||
// process_normal_mthd: Create the contents of a normal vtable slot. A helper
|
||||
// function for create_vtbl.
|
||||
fn process_normal_mthd(cx: @local_ctxt, m: @ast::method, self_ty: ty::t,
|
||||
ty_params: &[ast::ty_param]) -> ValueRef {
|
||||
ty_params: [ast::ty_param]) -> ValueRef {
|
||||
|
||||
let llfnty = T_nil();
|
||||
alt ty::struct(cx.ccx.tcx, node_id_type(cx.ccx, m.node.id)) {
|
||||
|
|
|
|||
|
|
@ -12,26 +12,25 @@ import trans::{call_memmove, trans_shared_malloc, llsize_of, type_of_or_i8,
|
|||
import trans_build::*;
|
||||
import trans_common::*;
|
||||
|
||||
fn get_fill(bcx: &@block_ctxt, vptrptr: ValueRef) -> ValueRef {
|
||||
fn get_fill(bcx: @block_ctxt, vptrptr: ValueRef) -> ValueRef {
|
||||
Load(bcx, GEPi(bcx, Load(bcx, vptrptr), [0, abi::vec_elt_fill as int]))
|
||||
}
|
||||
fn get_alloc(bcx: &@block_ctxt, vptrptr: ValueRef) -> ValueRef {
|
||||
fn get_alloc(bcx: @block_ctxt, vptrptr: ValueRef) -> ValueRef {
|
||||
Load(bcx, GEPi(bcx, Load(bcx, vptrptr), [0, abi::vec_elt_alloc as int]))
|
||||
}
|
||||
fn get_dataptr(bcx: &@block_ctxt, vptrptr: ValueRef, unit_ty: TypeRef) ->
|
||||
fn get_dataptr(bcx: @block_ctxt, vptrptr: ValueRef, unit_ty: TypeRef) ->
|
||||
ValueRef {
|
||||
let ptr = GEPi(bcx, Load(bcx, vptrptr), [0, abi::vec_elt_elems as int]);
|
||||
PointerCast(bcx, ptr, T_ptr(unit_ty))
|
||||
}
|
||||
|
||||
fn pointer_add(bcx: &@block_ctxt, ptr: ValueRef, bytes: ValueRef) ->
|
||||
ValueRef {
|
||||
fn pointer_add(bcx: @block_ctxt, ptr: ValueRef, bytes: ValueRef) -> ValueRef {
|
||||
let old_ty = val_ty(ptr);
|
||||
let bptr = PointerCast(bcx, ptr, T_ptr(T_i8()));
|
||||
ret PointerCast(bcx, InBoundsGEP(bcx, bptr, [bytes]), old_ty);
|
||||
}
|
||||
|
||||
fn alloc_raw(bcx: &@block_ctxt, fill: ValueRef, alloc: ValueRef) -> result {
|
||||
fn alloc_raw(bcx: @block_ctxt, fill: ValueRef, alloc: ValueRef) -> result {
|
||||
let llvecty = T_opaque_vec();
|
||||
let vecsize = Add(bcx, alloc, llsize_of(llvecty));
|
||||
let {bcx: bcx, val: vecptr} =
|
||||
|
|
@ -50,7 +49,7 @@ type alloc_result =
|
|||
llunitsz: ValueRef,
|
||||
llunitty: TypeRef};
|
||||
|
||||
fn alloc(bcx: &@block_ctxt, vec_ty: &ty::t, elts: uint) -> alloc_result {
|
||||
fn alloc(bcx: @block_ctxt, vec_ty: ty::t, elts: uint) -> alloc_result {
|
||||
let unit_ty = ty::sequence_element_type(bcx_tcx(bcx), vec_ty);
|
||||
let llunitty = type_of_or_i8(bcx, unit_ty);
|
||||
let llvecty = T_vec(llunitty);
|
||||
|
|
@ -62,7 +61,8 @@ fn alloc(bcx: &@block_ctxt, vec_ty: &ty::t, elts: uint) -> alloc_result {
|
|||
let vptr = PointerCast(bcx, vptr, T_ptr(llvecty));
|
||||
|
||||
let r = alloc_ty(bcx, vec_ty);
|
||||
let vptrptr = r.val; bcx = r.bcx;
|
||||
let vptrptr = r.val;
|
||||
bcx = r.bcx;
|
||||
|
||||
Store(bcx, vptr, vptrptr);
|
||||
add_clean_temp(bcx, vptrptr, vec_ty);
|
||||
|
|
@ -73,7 +73,7 @@ fn alloc(bcx: &@block_ctxt, vec_ty: &ty::t, elts: uint) -> alloc_result {
|
|||
llunitty: llunitty};
|
||||
}
|
||||
|
||||
fn duplicate(bcx: &@block_ctxt, vptrptr: ValueRef) -> @block_ctxt {
|
||||
fn duplicate(bcx: @block_ctxt, vptrptr: ValueRef) -> @block_ctxt {
|
||||
let fill = get_fill(bcx, vptrptr);
|
||||
let vptr = Load(bcx, vptrptr);
|
||||
let size = Add(bcx, fill, llsize_of(T_opaque_vec()));
|
||||
|
|
@ -85,7 +85,7 @@ fn duplicate(bcx: &@block_ctxt, vptrptr: ValueRef) -> @block_ctxt {
|
|||
Store(bcx, newptr, vptrptr);
|
||||
ret bcx;
|
||||
}
|
||||
fn make_drop_glue(bcx: &@block_ctxt, vptrptr: ValueRef, vec_ty: ty::t) ->
|
||||
fn make_drop_glue(bcx: @block_ctxt, vptrptr: ValueRef, vec_ty: ty::t) ->
|
||||
@block_ctxt {
|
||||
let unit_ty = ty::sequence_element_type(bcx_tcx(bcx), vec_ty);
|
||||
let vptr = Load(bcx, vptrptr);
|
||||
|
|
@ -102,7 +102,7 @@ fn make_drop_glue(bcx: &@block_ctxt, vptrptr: ValueRef, vec_ty: ty::t) ->
|
|||
ret next_cx;
|
||||
}
|
||||
|
||||
fn trans_vec(bcx: &@block_ctxt, args: &[@ast::expr], id: ast::node_id) ->
|
||||
fn trans_vec(bcx: @block_ctxt, args: [@ast::expr], id: ast::node_id) ->
|
||||
result {
|
||||
let vec_ty = node_id_type(bcx_ccx(bcx), id);
|
||||
let {bcx: bcx,
|
||||
|
|
@ -127,7 +127,7 @@ fn trans_vec(bcx: &@block_ctxt, args: &[@ast::expr], id: ast::node_id) ->
|
|||
}
|
||||
ret rslt(bcx, vptr);
|
||||
}
|
||||
fn trans_str(bcx: &@block_ctxt, s: str) -> result {
|
||||
fn trans_str(bcx: @block_ctxt, s: str) -> result {
|
||||
let veclen = std::str::byte_len(s) + 1u; // +1 for \0
|
||||
let {bcx: bcx, val: sptr, _} =
|
||||
alloc(bcx, ty::mk_str(bcx_tcx(bcx)), veclen);
|
||||
|
|
@ -140,7 +140,7 @@ fn trans_str(bcx: &@block_ctxt, s: str) -> result {
|
|||
ret rslt(bcx, sptr);
|
||||
}
|
||||
|
||||
fn trans_append(cx: &@block_ctxt, vec_ty: ty::t, lhsptr: ValueRef,
|
||||
fn trans_append(cx: @block_ctxt, vec_ty: ty::t, lhsptr: ValueRef,
|
||||
rhsptr: ValueRef) -> result {
|
||||
// Cast to opaque interior vector types if necessary.
|
||||
let unit_ty = ty::sequence_element_type(bcx_tcx(cx), vec_ty);
|
||||
|
|
@ -179,7 +179,7 @@ fn trans_append(cx: &@block_ctxt, vec_ty: ty::t, lhsptr: ValueRef,
|
|||
let bcx =
|
||||
iter_vec_raw(bcx, rhsptr, vec_ty, rfill,
|
||||
// We have to increment by the dynamically-computed size.
|
||||
{|&bcx, addr, _ty|
|
||||
{|bcx, addr, _ty|
|
||||
let write_ptr = Load(bcx, write_ptr_ptr);
|
||||
let bcx =
|
||||
copy_val(bcx, INIT, write_ptr,
|
||||
|
|
@ -193,8 +193,8 @@ fn trans_append(cx: &@block_ctxt, vec_ty: ty::t, lhsptr: ValueRef,
|
|||
ret rslt(bcx, C_nil());
|
||||
}
|
||||
|
||||
fn trans_append_literal(bcx: &@block_ctxt, vptrptr: ValueRef, vec_ty: ty::t,
|
||||
vals: &[@ast::expr]) -> @block_ctxt {
|
||||
fn trans_append_literal(bcx: @block_ctxt, vptrptr: ValueRef, vec_ty: ty::t,
|
||||
vals: [@ast::expr]) -> @block_ctxt {
|
||||
let elt_ty = ty::sequence_element_type(bcx_tcx(bcx), vec_ty);
|
||||
let ti = none;
|
||||
let {bcx: bcx, val: td} =
|
||||
|
|
@ -214,9 +214,8 @@ fn trans_append_literal(bcx: &@block_ctxt, vptrptr: ValueRef, vec_ty: ty::t,
|
|||
ret bcx;
|
||||
}
|
||||
|
||||
fn trans_add(bcx: &@block_ctxt, vec_ty: ty::t, lhsptr: ValueRef,
|
||||
rhsptr: ValueRef)
|
||||
-> result {
|
||||
fn trans_add(bcx: @block_ctxt, vec_ty: ty::t, lhsptr: ValueRef,
|
||||
rhsptr: ValueRef) -> result {
|
||||
let strings =
|
||||
alt ty::struct(bcx_tcx(bcx), vec_ty) {
|
||||
ty::ty_str. { true }
|
||||
|
|
@ -239,15 +238,16 @@ fn trans_add(bcx: &@block_ctxt, vec_ty: ty::t, lhsptr: ValueRef,
|
|||
let write_ptr_ptr =
|
||||
do_spill_noroot(bcx, get_dataptr(bcx, new_vec_ptr_ptr, llunitty));
|
||||
let copy_fn =
|
||||
bind fn (bcx: &@block_ctxt, addr: ValueRef, _ty: ty::t,
|
||||
bind fn (bcx: @block_ctxt, addr: ValueRef, _ty: ty::t,
|
||||
write_ptr_ptr: ValueRef, unit_ty: ty::t, llunitsz: ValueRef)
|
||||
-> @block_ctxt {
|
||||
let write_ptr = Load(bcx, write_ptr_ptr);
|
||||
let bcx =
|
||||
copy_val(bcx, INIT, write_ptr,
|
||||
load_if_immediate(bcx, addr, unit_ty), unit_ty);
|
||||
let incr = ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty) ?
|
||||
llunitsz : C_int(1);
|
||||
let incr =
|
||||
ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty) ?
|
||||
llunitsz : C_int(1);
|
||||
Store(bcx, InBoundsGEP(bcx, write_ptr, [incr]),
|
||||
write_ptr_ptr);
|
||||
ret bcx;
|
||||
|
|
@ -258,12 +258,12 @@ fn trans_add(bcx: &@block_ctxt, vec_ty: ty::t, lhsptr: ValueRef,
|
|||
ret rslt(bcx, new_vec_ptr_ptr);
|
||||
}
|
||||
|
||||
type val_and_ty_fn = fn(&@block_ctxt, ValueRef, ty::t) -> result;
|
||||
type val_and_ty_fn = fn(@block_ctxt, ValueRef, ty::t) -> result;
|
||||
|
||||
type iter_vec_block = block(&@block_ctxt, ValueRef, ty::t) -> @block_ctxt;
|
||||
type iter_vec_block = block(@block_ctxt, ValueRef, ty::t) -> @block_ctxt;
|
||||
|
||||
fn iter_vec_raw(bcx: &@block_ctxt, vptrptr: ValueRef, vec_ty: ty::t,
|
||||
fill: ValueRef, f: &iter_vec_block) -> @block_ctxt {
|
||||
fn iter_vec_raw(bcx: @block_ctxt, vptrptr: ValueRef, vec_ty: ty::t,
|
||||
fill: ValueRef, f: iter_vec_block) -> @block_ctxt {
|
||||
let unit_ty = ty::sequence_element_type(bcx_tcx(bcx), vec_ty);
|
||||
let llunitty = type_of_or_i8(bcx, unit_ty);
|
||||
let {bcx: bcx, val: unit_sz} = size_of(bcx, unit_ty);
|
||||
|
|
@ -289,14 +289,14 @@ fn iter_vec_raw(bcx: &@block_ctxt, vptrptr: ValueRef, vec_ty: ty::t,
|
|||
if ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty) {
|
||||
unit_sz
|
||||
} else { C_int(1) };
|
||||
AddIncomingToPhi(data_ptr, [InBoundsGEP(body_cx, data_ptr,
|
||||
[increment])], [body_cx.llbb]);
|
||||
AddIncomingToPhi(data_ptr, [InBoundsGEP(body_cx, data_ptr, [increment])],
|
||||
[body_cx.llbb]);
|
||||
Br(body_cx, header_cx.llbb);
|
||||
ret next_cx;
|
||||
}
|
||||
|
||||
fn iter_vec(bcx: &@block_ctxt, vptrptr: ValueRef, vec_ty: ty::t,
|
||||
f: &iter_vec_block) -> @block_ctxt {
|
||||
fn iter_vec(bcx: @block_ctxt, vptrptr: ValueRef, vec_ty: ty::t,
|
||||
f: iter_vec_block) -> @block_ctxt {
|
||||
vptrptr = PointerCast(bcx, vptrptr, T_ptr(T_ptr(T_opaque_vec())));
|
||||
ret iter_vec_raw(bcx, vptrptr, vec_ty, get_fill(bcx, vptrptr), f);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,84 +70,84 @@ fn empty_ann(num_vars: uint) -> ts_ann {
|
|||
states: empty_states(num_vars)};
|
||||
}
|
||||
|
||||
fn get_pre(p: &pre_and_post) -> precond { ret p.precondition; }
|
||||
fn get_pre(p: pre_and_post) -> precond { ret p.precondition; }
|
||||
|
||||
fn get_post(p: &pre_and_post) -> postcond { ret p.postcondition; }
|
||||
fn get_post(p: pre_and_post) -> postcond { ret p.postcondition; }
|
||||
|
||||
fn difference(p1: &precond, p2: &precond) -> bool {
|
||||
fn difference(p1: precond, p2: precond) -> bool {
|
||||
ret tritv_difference(p1, p2);
|
||||
}
|
||||
|
||||
fn union(p1: &precond, p2: &precond) -> bool { ret tritv_union(p1, p2); }
|
||||
fn union(p1: precond, p2: precond) -> bool { ret tritv_union(p1, p2); }
|
||||
|
||||
fn intersect(p1: &precond, p2: &precond) -> bool {
|
||||
fn intersect(p1: precond, p2: precond) -> bool {
|
||||
ret tritv_intersect(p1, p2);
|
||||
}
|
||||
|
||||
fn pps_len(p: &pre_and_post) -> uint {
|
||||
fn pps_len(p: pre_and_post) -> uint {
|
||||
// gratuitous check
|
||||
|
||||
assert (p.precondition.nbits == p.postcondition.nbits);
|
||||
ret p.precondition.nbits;
|
||||
}
|
||||
|
||||
fn require(i: uint, p: &pre_and_post) {
|
||||
fn require(i: uint, p: pre_and_post) {
|
||||
// sets the ith bit in p's pre
|
||||
tritv_set(i, p.precondition, ttrue);
|
||||
}
|
||||
|
||||
fn require_and_preserve(i: uint, p: &pre_and_post) {
|
||||
fn require_and_preserve(i: uint, p: pre_and_post) {
|
||||
// sets the ith bit in p's pre and post
|
||||
tritv_set(i, p.precondition, ttrue);
|
||||
tritv_set(i, p.postcondition, ttrue);
|
||||
}
|
||||
|
||||
fn set_in_postcond(i: uint, p: &pre_and_post) -> bool {
|
||||
fn set_in_postcond(i: uint, p: pre_and_post) -> bool {
|
||||
// sets the ith bit in p's post
|
||||
ret set_in_postcond_(i, p.postcondition);
|
||||
}
|
||||
|
||||
fn set_in_postcond_(i: uint, p: &postcond) -> bool {
|
||||
fn set_in_postcond_(i: uint, p: postcond) -> bool {
|
||||
let was_set = tritv_get(p, i);
|
||||
tritv_set(i, p, ttrue);
|
||||
ret was_set != ttrue;
|
||||
}
|
||||
|
||||
fn set_in_poststate(i: uint, s: &pre_and_post_state) -> bool {
|
||||
fn set_in_poststate(i: uint, s: pre_and_post_state) -> bool {
|
||||
// sets the ith bit in p's post
|
||||
ret set_in_poststate_(i, s.poststate);
|
||||
}
|
||||
|
||||
fn set_in_poststate_(i: uint, p: &poststate) -> bool {
|
||||
fn set_in_poststate_(i: uint, p: poststate) -> bool {
|
||||
let was_set = tritv_get(p, i);
|
||||
tritv_set(i, p, ttrue);
|
||||
ret was_set != ttrue;
|
||||
|
||||
}
|
||||
|
||||
fn clear_in_poststate(i: uint, s: &pre_and_post_state) -> bool {
|
||||
fn clear_in_poststate(i: uint, s: pre_and_post_state) -> bool {
|
||||
// sets the ith bit in p's post
|
||||
ret clear_in_poststate_(i, s.poststate);
|
||||
}
|
||||
|
||||
fn clear_in_poststate_(i: uint, s: &poststate) -> bool {
|
||||
fn clear_in_poststate_(i: uint, s: poststate) -> bool {
|
||||
let was_set = tritv_get(s, i);
|
||||
tritv_set(i, s, tfalse);
|
||||
ret was_set != tfalse;
|
||||
}
|
||||
|
||||
fn clear_in_prestate(i: uint, s: &pre_and_post_state) -> bool {
|
||||
fn clear_in_prestate(i: uint, s: pre_and_post_state) -> bool {
|
||||
// sets the ith bit in p's pre
|
||||
ret clear_in_prestate_(i, s.prestate);
|
||||
}
|
||||
|
||||
fn clear_in_prestate_(i: uint, s: &prestate) -> bool {
|
||||
fn clear_in_prestate_(i: uint, s: prestate) -> bool {
|
||||
let was_set = tritv_get(s, i);
|
||||
tritv_set(i, s, tfalse);
|
||||
ret was_set != tfalse;
|
||||
}
|
||||
|
||||
fn clear_in_postcond(i: uint, s: &pre_and_post) -> bool {
|
||||
fn clear_in_postcond(i: uint, s: pre_and_post) -> bool {
|
||||
// sets the ith bit in p's post
|
||||
let was_set = tritv_get(s.postcondition, i);
|
||||
tritv_set(i, s.postcondition, tfalse);
|
||||
|
|
@ -156,72 +156,72 @@ fn clear_in_postcond(i: uint, s: &pre_and_post) -> bool {
|
|||
|
||||
// Sets all the bits in a's precondition to equal the
|
||||
// corresponding bit in p's precondition.
|
||||
fn set_precondition(a: ts_ann, p: &precond) {
|
||||
fn set_precondition(a: ts_ann, p: precond) {
|
||||
tritv_copy(a.conditions.precondition, p);
|
||||
}
|
||||
|
||||
|
||||
// Sets all the bits in a's postcondition to equal the
|
||||
// corresponding bit in p's postcondition.
|
||||
fn set_postcondition(a: ts_ann, p: &postcond) {
|
||||
fn set_postcondition(a: ts_ann, p: postcond) {
|
||||
tritv_copy(a.conditions.postcondition, p);
|
||||
}
|
||||
|
||||
|
||||
// Sets all the bits in a's prestate to equal the
|
||||
// corresponding bit in p's prestate.
|
||||
fn set_prestate(a: ts_ann, p: &prestate) -> bool {
|
||||
fn set_prestate(a: ts_ann, p: prestate) -> bool {
|
||||
ret tritv_copy(a.states.prestate, p);
|
||||
}
|
||||
|
||||
|
||||
// Sets all the bits in a's postcondition to equal the
|
||||
// corresponding bit in p's postcondition.
|
||||
fn set_poststate(a: ts_ann, p: &poststate) -> bool {
|
||||
fn set_poststate(a: ts_ann, p: poststate) -> bool {
|
||||
ret tritv_copy(a.states.poststate, p);
|
||||
}
|
||||
|
||||
|
||||
// Set all the bits in p that are set in new
|
||||
fn extend_prestate(p: &prestate, new: &poststate) -> bool {
|
||||
fn extend_prestate(p: prestate, new: poststate) -> bool {
|
||||
ret tritv_union(p, new);
|
||||
}
|
||||
|
||||
|
||||
// Set all the bits in p that are set in new
|
||||
fn extend_poststate(p: &poststate, new: &poststate) -> bool {
|
||||
fn extend_poststate(p: poststate, new: poststate) -> bool {
|
||||
ret tritv_union(p, new);
|
||||
}
|
||||
|
||||
// Sets the given bit in p to "don't care"
|
||||
// FIXME: is this correct?
|
||||
fn relax_prestate(i: uint, p: &prestate) -> bool {
|
||||
fn relax_prestate(i: uint, p: prestate) -> bool {
|
||||
let was_set = tritv_get(p, i);
|
||||
tritv_set(i, p, dont_care);
|
||||
ret was_set != dont_care;
|
||||
}
|
||||
|
||||
// Clears the given bit in p
|
||||
fn relax_poststate(i: uint, p: &poststate) -> bool {
|
||||
fn relax_poststate(i: uint, p: poststate) -> bool {
|
||||
ret relax_prestate(i, p);
|
||||
}
|
||||
|
||||
// Clears the given bit in p
|
||||
fn relax_precond(i: uint, p: &precond) { relax_prestate(i, p); }
|
||||
fn relax_precond(i: uint, p: precond) { relax_prestate(i, p); }
|
||||
|
||||
// Sets all the bits in p to "don't care"
|
||||
fn clear(p: &precond) { tritv_clear(p); }
|
||||
fn clear(p: precond) { tritv_clear(p); }
|
||||
|
||||
// Sets all the bits in p to true
|
||||
fn set(p: &precond) { tritv_set_all(p); }
|
||||
fn set(p: precond) { tritv_set_all(p); }
|
||||
|
||||
fn ann_precond(a: &ts_ann) -> precond { ret a.conditions.precondition; }
|
||||
fn ann_precond(a: ts_ann) -> precond { ret a.conditions.precondition; }
|
||||
|
||||
fn ann_prestate(a: &ts_ann) -> prestate { ret a.states.prestate; }
|
||||
fn ann_prestate(a: ts_ann) -> prestate { ret a.states.prestate; }
|
||||
|
||||
fn ann_poststate(a: &ts_ann) -> poststate { ret a.states.poststate; }
|
||||
fn ann_poststate(a: ts_ann) -> poststate { ret a.states.poststate; }
|
||||
|
||||
fn pp_clone(p: &pre_and_post) -> pre_and_post {
|
||||
fn pp_clone(p: pre_and_post) -> pre_and_post {
|
||||
ret @{precondition: clone(p.precondition),
|
||||
postcondition: clone(p.postcondition)};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ import aux::crate_ctxt;
|
|||
import aux::add_node;
|
||||
import middle::tstate::ann::empty_ann;
|
||||
|
||||
fn collect_ids_expr(e: &@expr, rs: @mutable [node_id]) { *rs += [e.id]; }
|
||||
fn collect_ids_expr(e: @expr, rs: @mutable [node_id]) { *rs += [e.id]; }
|
||||
|
||||
fn collect_ids_block(b: &blk, rs: @mutable [node_id]) { *rs += [b.node.id]; }
|
||||
fn collect_ids_block(b: blk, rs: @mutable [node_id]) { *rs += [b.node.id]; }
|
||||
|
||||
fn collect_ids_stmt(s: &@stmt, rs: @mutable [node_id]) {
|
||||
fn collect_ids_stmt(s: @stmt, rs: @mutable [node_id]) {
|
||||
alt s.node {
|
||||
stmt_decl(_, id) {
|
||||
log "node_id " + int::str(id);
|
||||
|
|
@ -45,12 +45,12 @@ fn collect_ids_stmt(s: &@stmt, rs: @mutable [node_id]) {
|
|||
}
|
||||
}
|
||||
|
||||
fn collect_ids_local(l: &@local, rs: @mutable [node_id]) {
|
||||
fn collect_ids_local(l: @local, rs: @mutable [node_id]) {
|
||||
*rs += pat_binding_ids(l.node.pat);
|
||||
}
|
||||
|
||||
fn node_ids_in_fn(f: &_fn, tps: &[ty_param], sp: &span, i: &fn_ident,
|
||||
id: node_id, rs: @mutable [node_id]) {
|
||||
fn node_ids_in_fn(f: _fn, tps: [ty_param], sp: span, i: fn_ident, id: node_id,
|
||||
rs: @mutable [node_id]) {
|
||||
let collect_ids =
|
||||
visit::mk_simple_visitor(@{visit_expr: bind collect_ids_expr(_, rs),
|
||||
visit_block: bind collect_ids_block(_, rs),
|
||||
|
|
@ -60,28 +60,28 @@ fn node_ids_in_fn(f: &_fn, tps: &[ty_param], sp: &span, i: &fn_ident,
|
|||
visit::visit_fn(f, tps, sp, i, id, (), collect_ids);
|
||||
}
|
||||
|
||||
fn init_vecs(ccx: &crate_ctxt, node_ids: &[node_id], len: uint) {
|
||||
fn init_vecs(ccx: crate_ctxt, node_ids: [node_id], len: uint) {
|
||||
for i: node_id in node_ids {
|
||||
log int::str(i) + " |-> " + uint::str(len);
|
||||
add_node(ccx, i, empty_ann(len));
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_fn(ccx: &crate_ctxt, num_constraints: uint, f: &_fn,
|
||||
tps: &[ty_param], sp: &span, i: &fn_ident, id: node_id) {
|
||||
fn visit_fn(ccx: crate_ctxt, num_constraints: uint, f: _fn, tps: [ty_param],
|
||||
sp: span, i: fn_ident, id: node_id) {
|
||||
let node_ids: @mutable [node_id] = @mutable [];
|
||||
node_ids_in_fn(f, tps, sp, i, id, node_ids);
|
||||
let node_id_vec = *node_ids;
|
||||
init_vecs(ccx, node_id_vec, num_constraints);
|
||||
}
|
||||
|
||||
fn annotate_in_fn(ccx: &crate_ctxt, f: &_fn, tps: &[ty_param], sp: &span,
|
||||
i: &fn_ident, id: node_id) {
|
||||
fn annotate_in_fn(ccx: crate_ctxt, f: _fn, tps: [ty_param], sp: span,
|
||||
i: fn_ident, id: node_id) {
|
||||
let f_info = get_fn_info(ccx, id);
|
||||
visit_fn(ccx, num_constraints(f_info), f, tps, sp, i, id);
|
||||
}
|
||||
|
||||
fn annotate_crate(ccx: &crate_ctxt, crate: &crate) {
|
||||
fn annotate_crate(ccx: crate_ctxt, crate: crate) {
|
||||
let do_ann =
|
||||
visit::mk_simple_visitor(@{visit_fn:
|
||||
bind annotate_in_fn(ccx, _, _, _, _, _)
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ fn def_id_to_str(d: def_id) -> str {
|
|||
ret int::str(d.crate) + "," + int::str(d.node);
|
||||
}
|
||||
|
||||
fn comma_str(args: &[@constr_arg_use]) -> str {
|
||||
fn comma_str(args: [@constr_arg_use]) -> str {
|
||||
let rslt = "";
|
||||
let comma = false;
|
||||
for a: @constr_arg_use in args {
|
||||
|
|
@ -73,7 +73,7 @@ fn comma_str(args: &[@constr_arg_use]) -> str {
|
|||
ret rslt;
|
||||
}
|
||||
|
||||
fn constraint_to_str(tcx: &ty::ctxt, c: &sp_constr) -> str {
|
||||
fn constraint_to_str(tcx: ty::ctxt, c: sp_constr) -> str {
|
||||
alt c.node {
|
||||
ninit(_, i) {
|
||||
ret "init(" + i + " [" + tcx.sess.span_str(c.span) + "])";
|
||||
|
|
@ -85,7 +85,7 @@ fn constraint_to_str(tcx: &ty::ctxt, c: &sp_constr) -> str {
|
|||
}
|
||||
}
|
||||
|
||||
fn tritv_to_str(fcx: fn_ctxt, v: &tritv::t) -> str {
|
||||
fn tritv_to_str(fcx: fn_ctxt, v: tritv::t) -> str {
|
||||
let s = "";
|
||||
let comma = false;
|
||||
for p: norm_constraint in constraints(fcx) {
|
||||
|
|
@ -102,10 +102,10 @@ fn tritv_to_str(fcx: fn_ctxt, v: &tritv::t) -> str {
|
|||
ret s;
|
||||
}
|
||||
|
||||
fn log_tritv(fcx: &fn_ctxt, v: &tritv::t) { log tritv_to_str(fcx, v); }
|
||||
fn log_tritv(fcx: fn_ctxt, v: tritv::t) { log tritv_to_str(fcx, v); }
|
||||
|
||||
fn first_difference_string(fcx: &fn_ctxt, expected: &tritv::t,
|
||||
actual: &tritv::t) -> str {
|
||||
fn first_difference_string(fcx: fn_ctxt, expected: tritv::t, actual: tritv::t)
|
||||
-> str {
|
||||
let s: str = "";
|
||||
for c: norm_constraint in constraints(fcx) {
|
||||
if tritv_get(expected, c.bit_num) == ttrue &&
|
||||
|
|
@ -118,7 +118,7 @@ fn first_difference_string(fcx: &fn_ctxt, expected: &tritv::t,
|
|||
|
||||
fn log_tritv_err(fcx: fn_ctxt, v: tritv::t) { log_err tritv_to_str(fcx, v); }
|
||||
|
||||
fn tos(v: &[uint]) -> str {
|
||||
fn tos(v: [uint]) -> str {
|
||||
let rslt = "";
|
||||
for i: uint in v {
|
||||
if i == 0u {
|
||||
|
|
@ -128,11 +128,11 @@ fn tos(v: &[uint]) -> str {
|
|||
ret rslt;
|
||||
}
|
||||
|
||||
fn log_cond(v: &[uint]) { log tos(v); }
|
||||
fn log_cond(v: [uint]) { log tos(v); }
|
||||
|
||||
fn log_cond_err(v: &[uint]) { log_err tos(v); }
|
||||
fn log_cond_err(v: [uint]) { log_err tos(v); }
|
||||
|
||||
fn log_pp(pp: &pre_and_post) {
|
||||
fn log_pp(pp: pre_and_post) {
|
||||
let p1 = tritv::to_vec(pp.precondition);
|
||||
let p2 = tritv::to_vec(pp.postcondition);
|
||||
log "pre:";
|
||||
|
|
@ -141,7 +141,7 @@ fn log_pp(pp: &pre_and_post) {
|
|||
log_cond(p2);
|
||||
}
|
||||
|
||||
fn log_pp_err(pp: &pre_and_post) {
|
||||
fn log_pp_err(pp: pre_and_post) {
|
||||
let p1 = tritv::to_vec(pp.precondition);
|
||||
let p2 = tritv::to_vec(pp.postcondition);
|
||||
log_err "pre:";
|
||||
|
|
@ -150,7 +150,7 @@ fn log_pp_err(pp: &pre_and_post) {
|
|||
log_cond_err(p2);
|
||||
}
|
||||
|
||||
fn log_states(pp: &pre_and_post_state) {
|
||||
fn log_states(pp: pre_and_post_state) {
|
||||
let p1 = tritv::to_vec(pp.prestate);
|
||||
let p2 = tritv::to_vec(pp.poststate);
|
||||
log "prestate:";
|
||||
|
|
@ -159,7 +159,7 @@ fn log_states(pp: &pre_and_post_state) {
|
|||
log_cond(p2);
|
||||
}
|
||||
|
||||
fn log_states_err(pp: &pre_and_post_state) {
|
||||
fn log_states_err(pp: pre_and_post_state) {
|
||||
let p1 = tritv::to_vec(pp.prestate);
|
||||
let p2 = tritv::to_vec(pp.poststate);
|
||||
log_err "prestate:";
|
||||
|
|
@ -168,7 +168,7 @@ fn log_states_err(pp: &pre_and_post_state) {
|
|||
log_cond_err(p2);
|
||||
}
|
||||
|
||||
fn print_ident(i: &ident) { log " " + i + " "; }
|
||||
fn print_ident(i: ident) { log " " + i + " "; }
|
||||
|
||||
fn print_idents(idents: &mutable [ident]) {
|
||||
if vec::len::<ident>(idents) == 0u { ret; }
|
||||
|
|
@ -281,11 +281,11 @@ type fn_info =
|
|||
i_diverge: tsconstr,
|
||||
used_vars: @mutable [node_id]};
|
||||
|
||||
fn tsconstr_to_def_id(t: &tsconstr) -> def_id {
|
||||
fn tsconstr_to_def_id(t: tsconstr) -> def_id {
|
||||
alt t { ninit(id, _) { local_def(id) } npred(_, id, _) { id } }
|
||||
}
|
||||
|
||||
fn tsconstr_to_node_id(t: &tsconstr) -> node_id {
|
||||
fn tsconstr_to_node_id(t: tsconstr) -> node_id {
|
||||
alt t {
|
||||
ninit(id, _) { id }
|
||||
npred(_, id, _) { fail "tsconstr_to_node_id called on pred constraint" }
|
||||
|
|
@ -304,12 +304,12 @@ type fn_ctxt =
|
|||
|
||||
type crate_ctxt = {tcx: ty::ctxt, node_anns: node_ann_table, fm: fn_info_map};
|
||||
|
||||
fn get_fn_info(ccx: &crate_ctxt, id: node_id) -> fn_info {
|
||||
fn get_fn_info(ccx: crate_ctxt, id: node_id) -> fn_info {
|
||||
assert (ccx.fm.contains_key(id));
|
||||
ret ccx.fm.get(id);
|
||||
}
|
||||
|
||||
fn add_node(ccx: &crate_ctxt, i: node_id, a: &ts_ann) {
|
||||
fn add_node(ccx: crate_ctxt, i: node_id, a: ts_ann) {
|
||||
let sz = vec::len(*ccx.node_anns);
|
||||
if sz <= i as uint {
|
||||
vec::grow_mut(*ccx.node_anns, (i as uint) - sz + 1u, empty_ann(0u));
|
||||
|
|
@ -317,7 +317,7 @@ fn add_node(ccx: &crate_ctxt, i: node_id, a: &ts_ann) {
|
|||
ccx.node_anns[i] = a;
|
||||
}
|
||||
|
||||
fn get_ts_ann(ccx: &crate_ctxt, i: node_id) -> option::t<ts_ann> {
|
||||
fn get_ts_ann(ccx: crate_ctxt, i: node_id) -> option::t<ts_ann> {
|
||||
if i as uint < vec::len(*ccx.node_anns) {
|
||||
ret some::<ts_ann>(ccx.node_anns[i]);
|
||||
} else { ret none::<ts_ann>; }
|
||||
|
|
@ -325,7 +325,7 @@ fn get_ts_ann(ccx: &crate_ctxt, i: node_id) -> option::t<ts_ann> {
|
|||
|
||||
|
||||
/********* utils ********/
|
||||
fn node_id_to_ts_ann(ccx: &crate_ctxt, id: node_id) -> ts_ann {
|
||||
fn node_id_to_ts_ann(ccx: crate_ctxt, id: node_id) -> ts_ann {
|
||||
alt get_ts_ann(ccx, id) {
|
||||
none. {
|
||||
log_err "node_id_to_ts_ann: no ts_ann for node_id " + int::str(id);
|
||||
|
|
@ -335,12 +335,12 @@ fn node_id_to_ts_ann(ccx: &crate_ctxt, id: node_id) -> ts_ann {
|
|||
}
|
||||
}
|
||||
|
||||
fn node_id_to_poststate(ccx: &crate_ctxt, id: node_id) -> poststate {
|
||||
fn node_id_to_poststate(ccx: crate_ctxt, id: node_id) -> poststate {
|
||||
log "node_id_to_poststate";
|
||||
ret node_id_to_ts_ann(ccx, id).states.poststate;
|
||||
}
|
||||
|
||||
fn stmt_to_ann(ccx: &crate_ctxt, s: &stmt) -> ts_ann {
|
||||
fn stmt_to_ann(ccx: crate_ctxt, s: stmt) -> ts_ann {
|
||||
log "stmt_to_ann";
|
||||
alt s.node {
|
||||
stmt_decl(_, id) { ret node_id_to_ts_ann(ccx, id); }
|
||||
|
|
@ -354,25 +354,25 @@ fn stmt_to_ann(ccx: &crate_ctxt, s: &stmt) -> ts_ann {
|
|||
|
||||
|
||||
/* fails if e has no annotation */
|
||||
fn expr_states(ccx: &crate_ctxt, e: @expr) -> pre_and_post_state {
|
||||
fn expr_states(ccx: crate_ctxt, e: @expr) -> pre_and_post_state {
|
||||
log "expr_states";
|
||||
ret node_id_to_ts_ann(ccx, e.id).states;
|
||||
}
|
||||
|
||||
|
||||
/* fails if e has no annotation */
|
||||
fn expr_pp(ccx: &crate_ctxt, e: @expr) -> pre_and_post {
|
||||
fn expr_pp(ccx: crate_ctxt, e: @expr) -> pre_and_post {
|
||||
log "expr_pp";
|
||||
ret node_id_to_ts_ann(ccx, e.id).conditions;
|
||||
}
|
||||
|
||||
fn stmt_pp(ccx: &crate_ctxt, s: &stmt) -> pre_and_post {
|
||||
fn stmt_pp(ccx: crate_ctxt, s: stmt) -> pre_and_post {
|
||||
ret stmt_to_ann(ccx, s).conditions;
|
||||
}
|
||||
|
||||
|
||||
/* fails if b has no annotation */
|
||||
fn block_pp(ccx: &crate_ctxt, b: &blk) -> pre_and_post {
|
||||
fn block_pp(ccx: crate_ctxt, b: blk) -> pre_and_post {
|
||||
log "block_pp";
|
||||
ret node_id_to_ts_ann(ccx, b.node.id).conditions;
|
||||
}
|
||||
|
|
@ -382,111 +382,109 @@ fn clear_pp(pp: pre_and_post) {
|
|||
ann::clear(pp.postcondition);
|
||||
}
|
||||
|
||||
fn clear_precond(ccx: &crate_ctxt, id: node_id) {
|
||||
fn clear_precond(ccx: crate_ctxt, id: node_id) {
|
||||
let pp = node_id_to_ts_ann(ccx, id);
|
||||
ann::clear(pp.conditions.precondition);
|
||||
}
|
||||
|
||||
fn block_states(ccx: &crate_ctxt, b: &blk) -> pre_and_post_state {
|
||||
fn block_states(ccx: crate_ctxt, b: blk) -> pre_and_post_state {
|
||||
log "block_states";
|
||||
ret node_id_to_ts_ann(ccx, b.node.id).states;
|
||||
}
|
||||
|
||||
fn stmt_states(ccx: &crate_ctxt, s: &stmt) -> pre_and_post_state {
|
||||
fn stmt_states(ccx: crate_ctxt, s: stmt) -> pre_and_post_state {
|
||||
ret stmt_to_ann(ccx, s).states;
|
||||
}
|
||||
|
||||
fn expr_precond(ccx: &crate_ctxt, e: @expr) -> precond {
|
||||
fn expr_precond(ccx: crate_ctxt, e: @expr) -> precond {
|
||||
ret expr_pp(ccx, e).precondition;
|
||||
}
|
||||
|
||||
fn expr_postcond(ccx: &crate_ctxt, e: @expr) -> postcond {
|
||||
fn expr_postcond(ccx: crate_ctxt, e: @expr) -> postcond {
|
||||
ret expr_pp(ccx, e).postcondition;
|
||||
}
|
||||
|
||||
fn expr_prestate(ccx: &crate_ctxt, e: @expr) -> prestate {
|
||||
fn expr_prestate(ccx: crate_ctxt, e: @expr) -> prestate {
|
||||
ret expr_states(ccx, e).prestate;
|
||||
}
|
||||
|
||||
fn expr_poststate(ccx: &crate_ctxt, e: @expr) -> poststate {
|
||||
fn expr_poststate(ccx: crate_ctxt, e: @expr) -> poststate {
|
||||
ret expr_states(ccx, e).poststate;
|
||||
}
|
||||
|
||||
fn stmt_precond(ccx: &crate_ctxt, s: &stmt) -> precond {
|
||||
fn stmt_precond(ccx: crate_ctxt, s: stmt) -> precond {
|
||||
ret stmt_pp(ccx, s).precondition;
|
||||
}
|
||||
|
||||
fn stmt_postcond(ccx: &crate_ctxt, s: &stmt) -> postcond {
|
||||
fn stmt_postcond(ccx: crate_ctxt, s: stmt) -> postcond {
|
||||
ret stmt_pp(ccx, s).postcondition;
|
||||
}
|
||||
|
||||
fn states_to_poststate(ss: &pre_and_post_state) -> poststate {
|
||||
fn states_to_poststate(ss: pre_and_post_state) -> poststate {
|
||||
ret ss.poststate;
|
||||
}
|
||||
|
||||
fn stmt_prestate(ccx: &crate_ctxt, s: &stmt) -> prestate {
|
||||
fn stmt_prestate(ccx: crate_ctxt, s: stmt) -> prestate {
|
||||
ret stmt_states(ccx, s).prestate;
|
||||
}
|
||||
|
||||
fn stmt_poststate(ccx: &crate_ctxt, s: &stmt) -> poststate {
|
||||
fn stmt_poststate(ccx: crate_ctxt, s: stmt) -> poststate {
|
||||
ret stmt_states(ccx, s).poststate;
|
||||
}
|
||||
|
||||
fn block_precond(ccx: &crate_ctxt, b: &blk) -> precond {
|
||||
fn block_precond(ccx: crate_ctxt, b: blk) -> precond {
|
||||
ret block_pp(ccx, b).precondition;
|
||||
}
|
||||
|
||||
fn block_postcond(ccx: &crate_ctxt, b: &blk) -> postcond {
|
||||
fn block_postcond(ccx: crate_ctxt, b: blk) -> postcond {
|
||||
ret block_pp(ccx, b).postcondition;
|
||||
}
|
||||
|
||||
fn block_prestate(ccx: &crate_ctxt, b: &blk) -> prestate {
|
||||
fn block_prestate(ccx: crate_ctxt, b: blk) -> prestate {
|
||||
ret block_states(ccx, b).prestate;
|
||||
}
|
||||
|
||||
fn block_poststate(ccx: &crate_ctxt, b: &blk) -> poststate {
|
||||
fn block_poststate(ccx: crate_ctxt, b: blk) -> poststate {
|
||||
ret block_states(ccx, b).poststate;
|
||||
}
|
||||
|
||||
fn set_prestate_ann(ccx: &crate_ctxt, id: node_id, pre: &prestate) -> bool {
|
||||
fn set_prestate_ann(ccx: crate_ctxt, id: node_id, pre: prestate) -> bool {
|
||||
log "set_prestate_ann";
|
||||
ret set_prestate(node_id_to_ts_ann(ccx, id), pre);
|
||||
}
|
||||
|
||||
fn extend_prestate_ann(ccx: &crate_ctxt, id: node_id, pre: &prestate) ->
|
||||
bool {
|
||||
fn extend_prestate_ann(ccx: crate_ctxt, id: node_id, pre: prestate) -> bool {
|
||||
log "extend_prestate_ann";
|
||||
ret extend_prestate(node_id_to_ts_ann(ccx, id).states.prestate, pre);
|
||||
}
|
||||
|
||||
fn set_poststate_ann(ccx: &crate_ctxt, id: node_id, post: &poststate) ->
|
||||
bool {
|
||||
fn set_poststate_ann(ccx: crate_ctxt, id: node_id, post: poststate) -> bool {
|
||||
log "set_poststate_ann";
|
||||
ret set_poststate(node_id_to_ts_ann(ccx, id), post);
|
||||
}
|
||||
|
||||
fn extend_poststate_ann(ccx: &crate_ctxt, id: node_id, post: &poststate) ->
|
||||
fn extend_poststate_ann(ccx: crate_ctxt, id: node_id, post: poststate) ->
|
||||
bool {
|
||||
log "extend_poststate_ann";
|
||||
ret extend_poststate(node_id_to_ts_ann(ccx, id).states.poststate, post);
|
||||
}
|
||||
|
||||
fn set_pre_and_post(ccx: &crate_ctxt, id: node_id, pre: &precond,
|
||||
post: &postcond) {
|
||||
fn set_pre_and_post(ccx: crate_ctxt, id: node_id, pre: precond,
|
||||
post: postcond) {
|
||||
log "set_pre_and_post";
|
||||
let t = node_id_to_ts_ann(ccx, id);
|
||||
set_precondition(t, pre);
|
||||
set_postcondition(t, post);
|
||||
}
|
||||
|
||||
fn copy_pre_post(ccx: &crate_ctxt, id: node_id, sub: &@expr) {
|
||||
fn copy_pre_post(ccx: crate_ctxt, id: node_id, sub: @expr) {
|
||||
log "set_pre_and_post";
|
||||
let p = expr_pp(ccx, sub);
|
||||
copy_pre_post_(ccx, id, p.precondition, p.postcondition);
|
||||
}
|
||||
|
||||
fn copy_pre_post_(ccx: &crate_ctxt, id: node_id, pre: &prestate,
|
||||
post: &poststate) {
|
||||
fn copy_pre_post_(ccx: crate_ctxt, id: node_id, pre: prestate,
|
||||
post: poststate) {
|
||||
log "set_pre_and_post";
|
||||
let t = node_id_to_ts_ann(ccx, id);
|
||||
set_precondition(t, pre);
|
||||
|
|
@ -494,12 +492,12 @@ fn copy_pre_post_(ccx: &crate_ctxt, id: node_id, pre: &prestate,
|
|||
}
|
||||
|
||||
/* sets all bits to *1* */
|
||||
fn set_postcond_false(ccx: &crate_ctxt, id: node_id) {
|
||||
fn set_postcond_false(ccx: crate_ctxt, id: node_id) {
|
||||
let p = node_id_to_ts_ann(ccx, id);
|
||||
ann::set(p.conditions.postcondition);
|
||||
}
|
||||
|
||||
fn pure_exp(ccx: &crate_ctxt, id: node_id, p: &prestate) -> bool {
|
||||
fn pure_exp(ccx: crate_ctxt, id: node_id, p: prestate) -> bool {
|
||||
ret set_prestate_ann(ccx, id, p) | set_poststate_ann(ccx, id, p);
|
||||
}
|
||||
|
||||
|
|
@ -513,21 +511,21 @@ fn new_crate_ctxt(cx: ty::ctxt) -> crate_ctxt {
|
|||
/* Use e's type to determine whether it returns.
|
||||
If it has a function type with a ! annotation,
|
||||
the answer is noreturn. */
|
||||
fn controlflow_expr(ccx: &crate_ctxt, e: @expr) -> controlflow {
|
||||
fn controlflow_expr(ccx: crate_ctxt, e: @expr) -> controlflow {
|
||||
alt ty::struct(ccx.tcx, ty::node_id_to_type(ccx.tcx, e.id)) {
|
||||
ty::ty_fn(_, _, _, cf, _) { ret cf; }
|
||||
_ { ret return; }
|
||||
}
|
||||
}
|
||||
|
||||
fn constraints_expr(cx: &ty::ctxt, e: @expr) -> [@ty::constr] {
|
||||
fn constraints_expr(cx: ty::ctxt, e: @expr) -> [@ty::constr] {
|
||||
alt ty::struct(cx, ty::node_id_to_type(cx, e.id)) {
|
||||
ty::ty_fn(_, _, _, _, cs) { ret cs; }
|
||||
_ { ret []; }
|
||||
}
|
||||
}
|
||||
|
||||
fn node_id_to_def_strict(cx: &ty::ctxt, id: node_id) -> def {
|
||||
fn node_id_to_def_strict(cx: ty::ctxt, id: node_id) -> def {
|
||||
alt cx.def_map.find(id) {
|
||||
none. {
|
||||
log_err "node_id_to_def: node_id " + int::str(id) + " has no def";
|
||||
|
|
@ -537,11 +535,11 @@ fn node_id_to_def_strict(cx: &ty::ctxt, id: node_id) -> def {
|
|||
}
|
||||
}
|
||||
|
||||
fn node_id_to_def(ccx: &crate_ctxt, id: node_id) -> option::t<def> {
|
||||
fn node_id_to_def(ccx: crate_ctxt, id: node_id) -> option::t<def> {
|
||||
ret ccx.tcx.def_map.find(id);
|
||||
}
|
||||
|
||||
fn norm_a_constraint(id: def_id, c: &constraint) -> [norm_constraint] {
|
||||
fn norm_a_constraint(id: def_id, c: constraint) -> [norm_constraint] {
|
||||
alt c {
|
||||
cinit(n, sp, i) {
|
||||
ret [{bit_num: n, c: respan(sp, ninit(id.node, i))}];
|
||||
|
|
@ -561,7 +559,7 @@ fn norm_a_constraint(id: def_id, c: &constraint) -> [norm_constraint] {
|
|||
|
||||
// Tried to write this as an iterator, but I got a
|
||||
// non-exhaustive match in trans.
|
||||
fn constraints(fcx: &fn_ctxt) -> [norm_constraint] {
|
||||
fn constraints(fcx: fn_ctxt) -> [norm_constraint] {
|
||||
let rslt: [norm_constraint] = [];
|
||||
for each p: @{key: def_id, val: constraint} in
|
||||
fcx.enclosing.constrs.items() {
|
||||
|
|
@ -573,13 +571,13 @@ fn constraints(fcx: &fn_ctxt) -> [norm_constraint] {
|
|||
// FIXME
|
||||
// Would rather take an immutable vec as an argument,
|
||||
// should freeze it at some earlier point.
|
||||
fn match_args(fcx: &fn_ctxt, occs: &@mutable [pred_args],
|
||||
occ: &[@constr_arg_use]) -> uint {
|
||||
fn match_args(fcx: fn_ctxt, occs: @mutable [pred_args],
|
||||
occ: [@constr_arg_use]) -> uint {
|
||||
log "match_args: looking at " +
|
||||
constr_args_to_str(fn (i: &inst) -> str { ret i.ident; }, occ);
|
||||
constr_args_to_str(fn (i: inst) -> str { ret i.ident; }, occ);
|
||||
for pd: pred_args in *occs {
|
||||
log "match_args: candidate " + pred_args_to_str(pd);
|
||||
fn eq(p: &inst, q: &inst) -> bool { ret p.node == q.node; }
|
||||
fn eq(p: inst, q: inst) -> bool { ret p.node == q.node; }
|
||||
if ty::args_eq(eq, pd.node.args, occ) { ret pd.node.bit_num; }
|
||||
}
|
||||
fcx.ccx.tcx.sess.bug("match_args: no match for occurring args");
|
||||
|
|
@ -595,7 +593,7 @@ fn def_id_for_constr(tcx: ty::ctxt, t: node_id) -> def_id {
|
|||
}
|
||||
}
|
||||
|
||||
fn expr_to_constr_arg(tcx: ty::ctxt, e: &@expr) -> @constr_arg_use {
|
||||
fn expr_to_constr_arg(tcx: ty::ctxt, e: @expr) -> @constr_arg_use {
|
||||
alt e.node {
|
||||
expr_path(p) {
|
||||
alt tcx.def_map.find(e.id) {
|
||||
|
|
@ -623,14 +621,14 @@ fn expr_to_constr_arg(tcx: ty::ctxt, e: &@expr) -> @constr_arg_use {
|
|||
}
|
||||
}
|
||||
|
||||
fn exprs_to_constr_args(tcx: ty::ctxt, args: &[@expr]) -> [@constr_arg_use] {
|
||||
fn exprs_to_constr_args(tcx: ty::ctxt, args: [@expr]) -> [@constr_arg_use] {
|
||||
let f = bind expr_to_constr_arg(tcx, _);
|
||||
let rslt: [@constr_arg_use] = [];
|
||||
for e: @expr in args { rslt += [f(e)]; }
|
||||
rslt
|
||||
}
|
||||
|
||||
fn expr_to_constr(tcx: ty::ctxt, e: &@expr) -> sp_constr {
|
||||
fn expr_to_constr(tcx: ty::ctxt, e: @expr) -> sp_constr {
|
||||
alt e.node {
|
||||
expr_call(operator, args) {
|
||||
alt operator.node {
|
||||
|
|
@ -654,14 +652,14 @@ fn expr_to_constr(tcx: ty::ctxt, e: &@expr) -> sp_constr {
|
|||
}
|
||||
}
|
||||
|
||||
fn pred_args_to_str(p: &pred_args) -> str {
|
||||
fn pred_args_to_str(p: pred_args) -> str {
|
||||
"<" + uint::str(p.node.bit_num) + ", " +
|
||||
constr_args_to_str(fn (i: &inst) -> str { ret i.ident; }, p.node.args)
|
||||
constr_args_to_str(fn (i: inst) -> str { ret i.ident; }, p.node.args)
|
||||
+ ">"
|
||||
}
|
||||
|
||||
fn substitute_constr_args(cx: &ty::ctxt, actuals: &[@expr], c: &@ty::constr)
|
||||
-> tsconstr {
|
||||
fn substitute_constr_args(cx: ty::ctxt, actuals: [@expr], c: @ty::constr) ->
|
||||
tsconstr {
|
||||
let rslt: [@constr_arg_use] = [];
|
||||
for a: @constr_arg in c.node.args {
|
||||
rslt += [substitute_arg(cx, actuals, a)];
|
||||
|
|
@ -669,7 +667,7 @@ fn substitute_constr_args(cx: &ty::ctxt, actuals: &[@expr], c: &@ty::constr)
|
|||
ret npred(c.node.path, c.node.id, rslt);
|
||||
}
|
||||
|
||||
fn substitute_arg(cx: &ty::ctxt, actuals: &[@expr], a: @constr_arg) ->
|
||||
fn substitute_arg(cx: ty::ctxt, actuals: [@expr], a: @constr_arg) ->
|
||||
@constr_arg_use {
|
||||
let num_actuals = vec::len(actuals);
|
||||
alt a.node {
|
||||
|
|
@ -685,8 +683,8 @@ fn substitute_arg(cx: &ty::ctxt, actuals: &[@expr], a: @constr_arg) ->
|
|||
}
|
||||
}
|
||||
|
||||
fn pred_args_matches(pattern: &[constr_arg_general_<inst>], desc: &pred_args)
|
||||
-> bool {
|
||||
fn pred_args_matches(pattern: [constr_arg_general_<inst>], desc: pred_args) ->
|
||||
bool {
|
||||
let i = 0u;
|
||||
for c: @constr_arg_use in desc.node.args {
|
||||
let n = pattern[i];
|
||||
|
|
@ -710,8 +708,8 @@ fn pred_args_matches(pattern: &[constr_arg_general_<inst>], desc: &pred_args)
|
|||
ret true;
|
||||
}
|
||||
|
||||
fn find_instance_(pattern: &[constr_arg_general_<inst>], descs: &[pred_args])
|
||||
-> option::t<uint> {
|
||||
fn find_instance_(pattern: [constr_arg_general_<inst>], descs: [pred_args]) ->
|
||||
option::t<uint> {
|
||||
for d: pred_args in descs {
|
||||
if pred_args_matches(pattern, d) { ret some(d.node.bit_num); }
|
||||
}
|
||||
|
|
@ -721,7 +719,7 @@ fn find_instance_(pattern: &[constr_arg_general_<inst>], descs: &[pred_args])
|
|||
type inst = {ident: ident, node: node_id};
|
||||
type subst = [{from: inst, to: inst}];
|
||||
|
||||
fn find_instances(_fcx: &fn_ctxt, subst: &subst, c: &constraint) ->
|
||||
fn find_instances(_fcx: fn_ctxt, subst: subst, c: constraint) ->
|
||||
[{from: uint, to: uint}] {
|
||||
|
||||
let rslt = [];
|
||||
|
|
@ -745,18 +743,18 @@ fn find_instances(_fcx: &fn_ctxt, subst: &subst, c: &constraint) ->
|
|||
rslt
|
||||
}
|
||||
|
||||
fn find_in_subst(id: node_id, s: &subst) -> option::t<inst> {
|
||||
fn find_in_subst(id: node_id, s: subst) -> option::t<inst> {
|
||||
for p: {from: inst, to: inst} in s {
|
||||
if id == p.from.node { ret some(p.to); }
|
||||
}
|
||||
ret none;
|
||||
}
|
||||
|
||||
fn find_in_subst_bool(s: &subst, id: node_id) -> bool {
|
||||
fn find_in_subst_bool(s: subst, id: node_id) -> bool {
|
||||
is_some(find_in_subst(id, s))
|
||||
}
|
||||
|
||||
fn insts_to_str(stuff: &[constr_arg_general_<inst>]) -> str {
|
||||
fn insts_to_str(stuff: [constr_arg_general_<inst>]) -> str {
|
||||
let rslt = "<";
|
||||
for i: constr_arg_general_<inst> in stuff {
|
||||
rslt +=
|
||||
|
|
@ -802,7 +800,7 @@ fn replace(subst: subst, d: pred_args) -> [constr_arg_general_<inst>] {
|
|||
ret rslt;
|
||||
}
|
||||
|
||||
fn path_to_ident(cx: &ty::ctxt, p: &path) -> ident {
|
||||
fn path_to_ident(cx: ty::ctxt, p: path) -> ident {
|
||||
alt vec::last(p.node.idents) {
|
||||
none. { cx.sess.span_fatal(p.span, "Malformed path"); }
|
||||
some(i) { ret i; }
|
||||
|
|
@ -811,7 +809,7 @@ fn path_to_ident(cx: &ty::ctxt, p: &path) -> ident {
|
|||
|
||||
tag if_ty { if_check; plain_if; }
|
||||
|
||||
fn local_node_id_to_def_id_strict(fcx: &fn_ctxt, sp: &span, i: &node_id) ->
|
||||
fn local_node_id_to_def_id_strict(fcx: fn_ctxt, sp: span, i: node_id) ->
|
||||
def_id {
|
||||
alt local_node_id_to_def(fcx, i) {
|
||||
some(def_local(id)) | some(def_arg(id, _)) | some(def_upvar(id, _, _)) {
|
||||
|
|
@ -831,11 +829,11 @@ fn local_node_id_to_def_id_strict(fcx: &fn_ctxt, sp: &span, i: &node_id) ->
|
|||
}
|
||||
}
|
||||
|
||||
fn local_node_id_to_def(fcx: &fn_ctxt, i: &node_id) -> option::t<def> {
|
||||
fn local_node_id_to_def(fcx: fn_ctxt, i: node_id) -> option::t<def> {
|
||||
fcx.ccx.tcx.def_map.find(i)
|
||||
}
|
||||
|
||||
fn local_node_id_to_def_id(fcx: &fn_ctxt, i: &node_id) -> option::t<def_id> {
|
||||
fn local_node_id_to_def_id(fcx: fn_ctxt, i: node_id) -> option::t<def_id> {
|
||||
alt local_node_id_to_def(fcx, i) {
|
||||
some(def_local(id)) | some(def_arg(id, _)) | some(def_binding(id)) |
|
||||
some(def_upvar(id, _, _)) {
|
||||
|
|
@ -845,7 +843,7 @@ fn local_node_id_to_def_id(fcx: &fn_ctxt, i: &node_id) -> option::t<def_id> {
|
|||
}
|
||||
}
|
||||
|
||||
fn local_node_id_to_local_def_id(fcx: &fn_ctxt, i: &node_id) ->
|
||||
fn local_node_id_to_local_def_id(fcx: fn_ctxt, i: node_id) ->
|
||||
option::t<node_id> {
|
||||
alt local_node_id_to_def_id(fcx, i) {
|
||||
some(did) { some(did.node) }
|
||||
|
|
@ -853,7 +851,7 @@ fn local_node_id_to_local_def_id(fcx: &fn_ctxt, i: &node_id) ->
|
|||
}
|
||||
}
|
||||
|
||||
fn copy_in_postcond(fcx: &fn_ctxt, parent_exp: node_id, dest: inst, src: inst,
|
||||
fn copy_in_postcond(fcx: fn_ctxt, parent_exp: node_id, dest: inst, src: inst,
|
||||
ty: oper_type) {
|
||||
let post =
|
||||
node_id_to_ts_ann(fcx.ccx, parent_exp).conditions.postcondition;
|
||||
|
|
@ -861,7 +859,7 @@ fn copy_in_postcond(fcx: &fn_ctxt, parent_exp: node_id, dest: inst, src: inst,
|
|||
}
|
||||
|
||||
// FIXME refactor
|
||||
fn copy_in_poststate(fcx: &fn_ctxt, post: &poststate, dest: inst, src: inst,
|
||||
fn copy_in_poststate(fcx: fn_ctxt, post: poststate, dest: inst, src: inst,
|
||||
ty: oper_type) {
|
||||
copy_in_poststate_two(fcx, post, post, dest, src, ty);
|
||||
}
|
||||
|
|
@ -871,8 +869,8 @@ fn copy_in_poststate(fcx: &fn_ctxt, post: &poststate, dest: inst, src: inst,
|
|||
// dest substituted for src.
|
||||
// (This doesn't create any new constraints. If a new, substituted
|
||||
// constraint isn't already in the bit vector, it's ignored.)
|
||||
fn copy_in_poststate_two(fcx: &fn_ctxt, src_post: &poststate,
|
||||
target_post: &poststate, dest: inst, src: inst,
|
||||
fn copy_in_poststate_two(fcx: fn_ctxt, src_post: poststate,
|
||||
target_post: poststate, dest: inst, src: inst,
|
||||
ty: oper_type) {
|
||||
let subst;
|
||||
alt ty {
|
||||
|
|
@ -899,7 +897,7 @@ fn copy_in_poststate_two(fcx: &fn_ctxt, src_post: &poststate,
|
|||
|
||||
|
||||
/* FIXME should refactor this better */
|
||||
fn forget_in_postcond(fcx: &fn_ctxt, parent_exp: node_id, dead_v: node_id) {
|
||||
fn forget_in_postcond(fcx: fn_ctxt, parent_exp: node_id, dead_v: node_id) {
|
||||
// In the postcondition given by parent_exp, clear the bits
|
||||
// for any constraints mentioning dead_v
|
||||
let d = local_node_id_to_local_def_id(fcx, dead_v);
|
||||
|
|
@ -917,7 +915,7 @@ fn forget_in_postcond(fcx: &fn_ctxt, parent_exp: node_id, dead_v: node_id) {
|
|||
}
|
||||
}
|
||||
|
||||
fn forget_in_postcond_still_init(fcx: &fn_ctxt, parent_exp: node_id,
|
||||
fn forget_in_postcond_still_init(fcx: fn_ctxt, parent_exp: node_id,
|
||||
dead_v: node_id) {
|
||||
// In the postcondition given by parent_exp, clear the bits
|
||||
// for any constraints mentioning dead_v
|
||||
|
|
@ -936,8 +934,7 @@ fn forget_in_postcond_still_init(fcx: &fn_ctxt, parent_exp: node_id,
|
|||
}
|
||||
}
|
||||
|
||||
fn forget_in_poststate(fcx: &fn_ctxt, p: &poststate, dead_v: node_id) ->
|
||||
bool {
|
||||
fn forget_in_poststate(fcx: fn_ctxt, p: poststate, dead_v: node_id) -> bool {
|
||||
// In the poststate given by parent_exp, clear the bits
|
||||
// for any constraints mentioning dead_v
|
||||
let d = local_node_id_to_local_def_id(fcx, dead_v);
|
||||
|
|
@ -955,8 +952,8 @@ fn forget_in_poststate(fcx: &fn_ctxt, p: &poststate, dead_v: node_id) ->
|
|||
ret changed;
|
||||
}
|
||||
|
||||
fn forget_in_poststate_still_init(fcx: &fn_ctxt, p: &poststate,
|
||||
dead_v: node_id) -> bool {
|
||||
fn forget_in_poststate_still_init(fcx: fn_ctxt, p: poststate, dead_v: node_id)
|
||||
-> bool {
|
||||
// In the poststate given by parent_exp, clear the bits
|
||||
// for any constraints mentioning dead_v
|
||||
let d = local_node_id_to_local_def_id(fcx, dead_v);
|
||||
|
|
@ -974,12 +971,12 @@ fn forget_in_poststate_still_init(fcx: &fn_ctxt, p: &poststate,
|
|||
ret changed;
|
||||
}
|
||||
|
||||
fn any_eq(v: &[node_id], d: node_id) -> bool {
|
||||
fn any_eq(v: [node_id], d: node_id) -> bool {
|
||||
for i: node_id in v { if i == d { ret true; } }
|
||||
false
|
||||
}
|
||||
|
||||
fn constraint_mentions(_fcx: &fn_ctxt, c: &norm_constraint, v: node_id) ->
|
||||
fn constraint_mentions(_fcx: fn_ctxt, c: norm_constraint, v: node_id) ->
|
||||
bool {
|
||||
ret alt c.c.node {
|
||||
ninit(id, _) { v == id }
|
||||
|
|
@ -987,16 +984,16 @@ fn constraint_mentions(_fcx: &fn_ctxt, c: &norm_constraint, v: node_id) ->
|
|||
};
|
||||
}
|
||||
|
||||
fn non_init_constraint_mentions(_fcx: &fn_ctxt, c: &norm_constraint,
|
||||
v: &node_id) -> bool {
|
||||
fn non_init_constraint_mentions(_fcx: fn_ctxt, c: norm_constraint, v: node_id)
|
||||
-> bool {
|
||||
ret alt c.c.node {
|
||||
ninit(_, _) { false }
|
||||
npred(_, _, args) { args_mention(args, any_eq, [v]) }
|
||||
};
|
||||
}
|
||||
|
||||
fn args_mention<T>(args: &[@constr_arg_use], q: fn(&[T], node_id) -> bool,
|
||||
s: &[T]) -> bool {
|
||||
fn args_mention<T>(args: [@constr_arg_use], q: fn([T], node_id) -> bool,
|
||||
s: [T]) -> bool {
|
||||
/*
|
||||
FIXME
|
||||
The following version causes an assertion in trans to fail
|
||||
|
|
@ -1021,10 +1018,10 @@ fn args_mention<T>(args: &[@constr_arg_use], q: fn(&[T], node_id) -> bool,
|
|||
ret false;
|
||||
}
|
||||
|
||||
fn use_var(fcx: &fn_ctxt, v: &node_id) { *fcx.enclosing.used_vars += [v]; }
|
||||
fn use_var(fcx: fn_ctxt, v: node_id) { *fcx.enclosing.used_vars += [v]; }
|
||||
|
||||
// FIXME: This should be a function in std::vec::.
|
||||
fn vec_contains(v: &@mutable [node_id], i: &node_id) -> bool {
|
||||
fn vec_contains(v: @mutable [node_id], i: node_id) -> bool {
|
||||
for d: node_id in *v { if d == i { ret true; } }
|
||||
ret false;
|
||||
}
|
||||
|
|
@ -1034,14 +1031,13 @@ fn op_to_oper_ty(io: init_op) -> oper_type {
|
|||
}
|
||||
|
||||
// default function visitor
|
||||
fn do_nothing<T>(_f: &_fn, _tp: &[ty_param], _sp: &span, _i: &fn_ident,
|
||||
_iid: node_id, _cx: &T, _v: &visit::vt<T>) {
|
||||
fn do_nothing<T>(_f: _fn, _tp: [ty_param], _sp: span, _i: fn_ident,
|
||||
_iid: node_id, _cx: T, _v: visit::vt<T>) {
|
||||
}
|
||||
|
||||
|
||||
fn args_to_constr_args(tcx: &ty::ctxt, args: &[arg],
|
||||
indices: &[@sp_constr_arg<uint>]) ->
|
||||
[@constr_arg_use] {
|
||||
fn args_to_constr_args(tcx: ty::ctxt, args: [arg],
|
||||
indices: [@sp_constr_arg<uint>]) -> [@constr_arg_use] {
|
||||
let actuals: [@constr_arg_use] = [];
|
||||
let num_args = vec::len(args);
|
||||
for a: @sp_constr_arg<uint> in indices {
|
||||
|
|
@ -1065,14 +1061,14 @@ fn args_to_constr_args(tcx: &ty::ctxt, args: &[arg],
|
|||
ret actuals;
|
||||
}
|
||||
|
||||
fn ast_constr_to_ts_constr(tcx: &ty::ctxt, args: &[arg], c: &@constr) ->
|
||||
fn ast_constr_to_ts_constr(tcx: ty::ctxt, args: [arg], c: @constr) ->
|
||||
tsconstr {
|
||||
let tconstr = ty::ast_constr_to_constr(tcx, c);
|
||||
ret npred(tconstr.node.path, tconstr.node.id,
|
||||
args_to_constr_args(tcx, args, tconstr.node.args));
|
||||
}
|
||||
|
||||
fn ast_constr_to_sp_constr(tcx: &ty::ctxt, args: &[arg], c: &@constr) ->
|
||||
fn ast_constr_to_sp_constr(tcx: ty::ctxt, args: [arg], c: @constr) ->
|
||||
sp_constr {
|
||||
let tconstr = ast_constr_to_ts_constr(tcx, args, c);
|
||||
ret respan(c.span, tconstr);
|
||||
|
|
@ -1080,7 +1076,7 @@ fn ast_constr_to_sp_constr(tcx: &ty::ctxt, args: &[arg], c: &@constr) ->
|
|||
|
||||
type binding = {lhs: [inst], rhs: option::t<initializer>};
|
||||
|
||||
fn local_to_bindings(loc: &@local) -> binding {
|
||||
fn local_to_bindings(loc: @local) -> binding {
|
||||
let lhs = [];
|
||||
for each p: @pat in pat_bindings(loc.node.pat) {
|
||||
let ident = alt p.node { pat_bind(name) { name } };
|
||||
|
|
@ -1089,11 +1085,11 @@ fn local_to_bindings(loc: &@local) -> binding {
|
|||
{lhs: lhs, rhs: loc.node.init}
|
||||
}
|
||||
|
||||
fn locals_to_bindings(locals: &[@local]) -> [binding] {
|
||||
fn locals_to_bindings(locals: [@local]) -> [binding] {
|
||||
vec::map(local_to_bindings, locals)
|
||||
}
|
||||
|
||||
fn callee_modes(fcx: &fn_ctxt, callee: node_id) -> [ty::mode] {
|
||||
fn callee_modes(fcx: fn_ctxt, callee: node_id) -> [ty::mode] {
|
||||
let ty =
|
||||
ty::type_autoderef(fcx.ccx.tcx,
|
||||
ty::node_id_to_type(fcx.ccx.tcx, callee));
|
||||
|
|
@ -1111,14 +1107,14 @@ fn callee_modes(fcx: &fn_ctxt, callee: node_id) -> [ty::mode] {
|
|||
}
|
||||
}
|
||||
|
||||
fn callee_arg_init_ops(fcx: &fn_ctxt, callee: node_id) -> [init_op] {
|
||||
fn mode_to_op(m: &ty::mode) -> init_op {
|
||||
fn callee_arg_init_ops(fcx: fn_ctxt, callee: node_id) -> [init_op] {
|
||||
fn mode_to_op(m: ty::mode) -> init_op {
|
||||
alt m { by_move. { init_move } _ { init_assign } }
|
||||
}
|
||||
vec::map(mode_to_op, callee_modes(fcx, callee))
|
||||
}
|
||||
|
||||
fn anon_bindings(ops: &[init_op], es: &[@expr]) -> [binding] {
|
||||
fn anon_bindings(ops: [init_op], es: [@expr]) -> [binding] {
|
||||
let bindings: [binding] = [];
|
||||
let i = 0;
|
||||
for op: init_op in ops {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import tstate::ann::clear_in_poststate_;
|
|||
import tritv::*;
|
||||
import util::common::*;
|
||||
|
||||
fn bit_num(fcx: &fn_ctxt, c: &tsconstr) -> uint {
|
||||
fn bit_num(fcx: fn_ctxt, c: tsconstr) -> uint {
|
||||
let d = tsconstr_to_def_id(c);
|
||||
assert (fcx.enclosing.constrs.contains_key(d));
|
||||
let rslt = fcx.enclosing.constrs.get(d);
|
||||
|
|
@ -53,11 +53,11 @@ fn bit_num(fcx: &fn_ctxt, c: &tsconstr) -> uint {
|
|||
}
|
||||
}
|
||||
|
||||
fn promises(fcx: &fn_ctxt, p: &poststate, c: &tsconstr) -> bool {
|
||||
fn promises(fcx: fn_ctxt, p: poststate, c: tsconstr) -> bool {
|
||||
ret promises_(bit_num(fcx, c), p);
|
||||
}
|
||||
|
||||
fn promises_(n: uint, p: &poststate) -> bool { ret tritv_get(p, n) == ttrue; }
|
||||
fn promises_(n: uint, p: poststate) -> bool { ret tritv_get(p, n) == ttrue; }
|
||||
|
||||
// v "happens after" u
|
||||
fn seq_trit(u: trit, v: trit) -> trit {
|
||||
|
|
@ -67,7 +67,7 @@ fn seq_trit(u: trit, v: trit) -> trit {
|
|||
// idea: q "happens after" p -- so if something is
|
||||
// 1 in q and 0 in p, it's 1 in the result; however,
|
||||
// if it's 0 in q and 1 in p, it's 0 in the result
|
||||
fn seq_tritv(p: &postcond, q: &postcond) {
|
||||
fn seq_tritv(p: postcond, q: postcond) {
|
||||
let i = 0u;
|
||||
assert (p.nbits == q.nbits);
|
||||
while i < p.nbits {
|
||||
|
|
@ -76,7 +76,7 @@ fn seq_tritv(p: &postcond, q: &postcond) {
|
|||
}
|
||||
}
|
||||
|
||||
fn seq_postconds(fcx: &fn_ctxt, ps: &[postcond]) -> postcond {
|
||||
fn seq_postconds(fcx: fn_ctxt, ps: [postcond]) -> postcond {
|
||||
let sz = vec::len(ps);
|
||||
if sz >= 1u {
|
||||
let prev = tritv_clone(ps[0]);
|
||||
|
|
@ -89,12 +89,12 @@ fn seq_postconds(fcx: &fn_ctxt, ps: &[postcond]) -> postcond {
|
|||
// return the precondition for evaluating each expr in order.
|
||||
// So, if e0's post is {x} and e1's pre is {x, y, z}, the entire
|
||||
// precondition shouldn't include x.
|
||||
fn seq_preconds(fcx: &fn_ctxt, pps: &[pre_and_post]) -> precond {
|
||||
fn seq_preconds(fcx: fn_ctxt, pps: [pre_and_post]) -> precond {
|
||||
let sz: uint = vec::len(pps);
|
||||
let num_vars: uint = num_constraints(fcx.enclosing);
|
||||
|
||||
fn seq_preconds_go(fcx: &fn_ctxt, pps: &[pre_and_post],
|
||||
first: &pre_and_post) -> precond {
|
||||
fn seq_preconds_go(fcx: fn_ctxt, pps: [pre_and_post], first: pre_and_post)
|
||||
-> precond {
|
||||
let sz: uint = vec::len(pps);
|
||||
if sz >= 1u {
|
||||
let second = pps[0];
|
||||
|
|
@ -119,18 +119,18 @@ fn seq_preconds(fcx: &fn_ctxt, pps: &[pre_and_post]) -> precond {
|
|||
} else { ret true_precond(num_vars); }
|
||||
}
|
||||
|
||||
fn intersect_states(p: &prestate, q: &prestate) -> prestate {
|
||||
fn intersect_states(p: prestate, q: prestate) -> prestate {
|
||||
let rslt = tritv_clone(p);
|
||||
tritv_intersect(rslt, q);
|
||||
ret rslt;
|
||||
}
|
||||
|
||||
fn gen(fcx: &fn_ctxt, id: node_id, c: &tsconstr) -> bool {
|
||||
fn gen(fcx: fn_ctxt, id: node_id, c: tsconstr) -> bool {
|
||||
ret set_in_postcond(bit_num(fcx, c),
|
||||
node_id_to_ts_ann(fcx.ccx, id).conditions);
|
||||
}
|
||||
|
||||
fn declare_var(fcx: &fn_ctxt, c: &tsconstr, pre: prestate) -> prestate {
|
||||
fn declare_var(fcx: fn_ctxt, c: tsconstr, pre: prestate) -> prestate {
|
||||
let rslt = clone(pre);
|
||||
relax_prestate(bit_num(fcx, c), rslt);
|
||||
// idea is this is scoped
|
||||
|
|
@ -138,27 +138,25 @@ fn declare_var(fcx: &fn_ctxt, c: &tsconstr, pre: prestate) -> prestate {
|
|||
ret rslt;
|
||||
}
|
||||
|
||||
fn relax_precond_expr(e: &@expr, cx: &relax_ctxt,
|
||||
vt: &visit::vt<relax_ctxt>) {
|
||||
fn relax_precond_expr(e: @expr, cx: relax_ctxt, vt: visit::vt<relax_ctxt>) {
|
||||
relax_precond(cx.i as uint, expr_precond(cx.fcx.ccx, e));
|
||||
visit::visit_expr(e, cx, vt);
|
||||
}
|
||||
|
||||
fn relax_precond_stmt(s: &@stmt, cx: &relax_ctxt,
|
||||
vt: &visit::vt<relax_ctxt>) {
|
||||
fn relax_precond_stmt(s: @stmt, cx: relax_ctxt, vt: visit::vt<relax_ctxt>) {
|
||||
relax_precond(cx.i as uint, stmt_precond(cx.fcx.ccx, *s));
|
||||
visit::visit_stmt(s, cx, vt);
|
||||
}
|
||||
|
||||
type relax_ctxt = {fcx: fn_ctxt, i: node_id};
|
||||
|
||||
fn relax_precond_block_inner(b: &blk, cx: &relax_ctxt,
|
||||
vt: &visit::vt<relax_ctxt>) {
|
||||
fn relax_precond_block_inner(b: blk, cx: relax_ctxt,
|
||||
vt: visit::vt<relax_ctxt>) {
|
||||
relax_precond(cx.i as uint, block_precond(cx.fcx.ccx, b));
|
||||
visit::visit_block(b, cx, vt);
|
||||
}
|
||||
|
||||
fn relax_precond_block(fcx: &fn_ctxt, i: node_id, b: &blk) {
|
||||
fn relax_precond_block(fcx: fn_ctxt, i: node_id, b: blk) {
|
||||
let cx = {fcx: fcx, i: i};
|
||||
let visitor = visit::default_visitor::<relax_ctxt>();
|
||||
visitor =
|
||||
|
|
@ -166,35 +164,35 @@ fn relax_precond_block(fcx: &fn_ctxt, i: node_id, b: &blk) {
|
|||
visit_expr: relax_precond_expr,
|
||||
visit_stmt: relax_precond_stmt,
|
||||
visit_item:
|
||||
fn (_i: &@item, _cx: &relax_ctxt, _vt: &visit::vt<relax_ctxt>) {
|
||||
} with *visitor};
|
||||
fn (_i: @item, _cx: relax_ctxt, _vt: visit::vt<relax_ctxt>) { }
|
||||
with *visitor};
|
||||
let v1 = visit::mk_vt(visitor);
|
||||
v1.visit_block(b, cx, v1);
|
||||
}
|
||||
|
||||
fn gen_poststate(fcx: &fn_ctxt, id: node_id, c: &tsconstr) -> bool {
|
||||
fn gen_poststate(fcx: fn_ctxt, id: node_id, c: tsconstr) -> bool {
|
||||
log "gen_poststate";
|
||||
ret set_in_poststate(bit_num(fcx, c),
|
||||
node_id_to_ts_ann(fcx.ccx, id).states);
|
||||
}
|
||||
|
||||
fn kill_prestate(fcx: &fn_ctxt, id: node_id, c: &tsconstr) -> bool {
|
||||
fn kill_prestate(fcx: fn_ctxt, id: node_id, c: tsconstr) -> bool {
|
||||
ret clear_in_prestate(bit_num(fcx, c),
|
||||
node_id_to_ts_ann(fcx.ccx, id).states);
|
||||
}
|
||||
|
||||
fn kill_all_prestate(fcx: &fn_ctxt, id: node_id) {
|
||||
fn kill_all_prestate(fcx: fn_ctxt, id: node_id) {
|
||||
tritv::tritv_kill(node_id_to_ts_ann(fcx.ccx, id).states.prestate);
|
||||
}
|
||||
|
||||
|
||||
fn kill_poststate(fcx: &fn_ctxt, id: node_id, c: &tsconstr) -> bool {
|
||||
fn kill_poststate(fcx: fn_ctxt, id: node_id, c: tsconstr) -> bool {
|
||||
log "kill_poststate";
|
||||
ret clear_in_poststate(bit_num(fcx, c),
|
||||
node_id_to_ts_ann(fcx.ccx, id).states);
|
||||
}
|
||||
|
||||
fn clear_in_poststate_expr(fcx: &fn_ctxt, e: &@expr, t: &poststate) {
|
||||
fn clear_in_poststate_expr(fcx: fn_ctxt, e: @expr, t: poststate) {
|
||||
alt e.node {
|
||||
expr_path(p) {
|
||||
alt vec::last(p.node.idents) {
|
||||
|
|
@ -217,32 +215,32 @@ fn clear_in_poststate_expr(fcx: &fn_ctxt, e: &@expr, t: &poststate) {
|
|||
}
|
||||
}
|
||||
|
||||
fn kill_poststate_(fcx: &fn_ctxt, c: &tsconstr, post: &poststate) -> bool {
|
||||
fn kill_poststate_(fcx: fn_ctxt, c: tsconstr, post: poststate) -> bool {
|
||||
log "kill_poststate_";
|
||||
ret clear_in_poststate_(bit_num(fcx, c), post);
|
||||
}
|
||||
|
||||
fn set_in_poststate_ident(fcx: &fn_ctxt, id: &node_id, ident: &ident,
|
||||
t: &poststate) -> bool {
|
||||
fn set_in_poststate_ident(fcx: fn_ctxt, id: node_id, ident: ident,
|
||||
t: poststate) -> bool {
|
||||
ret set_in_poststate_(bit_num(fcx, ninit(id, ident)), t);
|
||||
}
|
||||
|
||||
fn set_in_prestate_constr(fcx: &fn_ctxt, c: &tsconstr, t: &prestate) -> bool {
|
||||
fn set_in_prestate_constr(fcx: fn_ctxt, c: tsconstr, t: prestate) -> bool {
|
||||
ret set_in_poststate_(bit_num(fcx, c), t);
|
||||
}
|
||||
|
||||
fn clear_in_poststate_ident(fcx: &fn_ctxt, id: &node_id, ident: &ident,
|
||||
parent: &node_id) -> bool {
|
||||
fn clear_in_poststate_ident(fcx: fn_ctxt, id: node_id, ident: ident,
|
||||
parent: node_id) -> bool {
|
||||
ret kill_poststate(fcx, parent, ninit(id, ident));
|
||||
}
|
||||
|
||||
fn clear_in_prestate_ident(fcx: &fn_ctxt, id: &node_id, ident: &ident,
|
||||
parent: &node_id) -> bool {
|
||||
fn clear_in_prestate_ident(fcx: fn_ctxt, id: node_id, ident: ident,
|
||||
parent: node_id) -> bool {
|
||||
ret kill_prestate(fcx, parent, ninit(id, ident));
|
||||
}
|
||||
|
||||
fn clear_in_poststate_ident_(fcx: &fn_ctxt, id: &node_id, ident: &ident,
|
||||
post: &poststate) -> bool {
|
||||
fn clear_in_poststate_ident_(fcx: fn_ctxt, id: node_id, ident: ident,
|
||||
post: poststate) -> bool {
|
||||
ret kill_poststate_(fcx, ninit(id, ident), post);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ import collect_locals::mk_f_to_fn_info;
|
|||
import pre_post_conditions::fn_pre_post;
|
||||
import states::find_pre_post_state_fn;
|
||||
|
||||
fn check_unused_vars(fcx: &fn_ctxt) {
|
||||
fn check_unused_vars(fcx: fn_ctxt) {
|
||||
|
||||
// FIXME: could be more efficient
|
||||
for c: norm_constraint in constraints(fcx) {
|
||||
|
|
@ -63,7 +63,7 @@ fn check_unused_vars(fcx: &fn_ctxt) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_states_expr(e: &@expr, fcx: &fn_ctxt, v: &visit::vt<fn_ctxt>) {
|
||||
fn check_states_expr(e: @expr, fcx: fn_ctxt, v: visit::vt<fn_ctxt>) {
|
||||
visit::visit_expr(e, fcx, v);
|
||||
|
||||
let prec: precond = expr_precond(fcx.ccx, e);
|
||||
|
|
@ -94,7 +94,7 @@ fn check_states_expr(e: &@expr, fcx: &fn_ctxt, v: &visit::vt<fn_ctxt>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_states_stmt(s: &@stmt, fcx: &fn_ctxt, v: &visit::vt<fn_ctxt>) {
|
||||
fn check_states_stmt(s: @stmt, fcx: fn_ctxt, v: visit::vt<fn_ctxt>) {
|
||||
visit::visit_stmt(s, fcx, v);
|
||||
|
||||
let a = stmt_to_ann(fcx.ccx, *s);
|
||||
|
|
@ -126,9 +126,8 @@ fn check_states_stmt(s: &@stmt, fcx: &fn_ctxt, v: &visit::vt<fn_ctxt>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_states_against_conditions(fcx: &fn_ctxt, f: &_fn,
|
||||
tps: &[ast::ty_param], id: node_id,
|
||||
sp: &span, i: &fn_ident) {
|
||||
fn check_states_against_conditions(fcx: fn_ctxt, f: _fn, tps: [ast::ty_param],
|
||||
id: node_id, sp: span, i: fn_ident) {
|
||||
/* Postorder traversal instead of pre is important
|
||||
because we want the smallest possible erroneous statement
|
||||
or expression. */
|
||||
|
|
@ -173,8 +172,8 @@ fn check_states_against_conditions(fcx: &fn_ctxt, f: &_fn,
|
|||
check_unused_vars(fcx);
|
||||
}
|
||||
|
||||
fn check_fn_states(fcx: &fn_ctxt, f: &_fn, tps: &[ast::ty_param], id: node_id,
|
||||
sp: &span, i: &fn_ident) {
|
||||
fn check_fn_states(fcx: fn_ctxt, f: _fn, tps: [ast::ty_param], id: node_id,
|
||||
sp: span, i: fn_ident) {
|
||||
/* Compute the pre- and post-states for this function */
|
||||
|
||||
// Fixpoint iteration
|
||||
|
|
@ -186,8 +185,8 @@ fn check_fn_states(fcx: &fn_ctxt, f: &_fn, tps: &[ast::ty_param], id: node_id,
|
|||
check_states_against_conditions(fcx, f, tps, id, sp, i);
|
||||
}
|
||||
|
||||
fn fn_states(f: &_fn, tps: &[ast::ty_param], sp: &span, i: &fn_ident,
|
||||
id: node_id, ccx: &crate_ctxt, v: &visit::vt<crate_ctxt>) {
|
||||
fn fn_states(f: _fn, tps: [ast::ty_param], sp: span, i: fn_ident, id: node_id,
|
||||
ccx: crate_ctxt, v: visit::vt<crate_ctxt>) {
|
||||
visit::visit_fn(f, tps, sp, i, id, ccx, v);
|
||||
/* Look up the var-to-bit-num map for this function */
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import syntax::ast_util::respan;
|
|||
|
||||
type ctxt = {cs: @mutable [sp_constr], tcx: ty::ctxt};
|
||||
|
||||
fn collect_local(loc: &@local, cx: &ctxt, v: &visit::vt<ctxt>) {
|
||||
fn collect_local(loc: @local, cx: ctxt, v: visit::vt<ctxt>) {
|
||||
for each p: @pat in pat_bindings(loc.node.pat) {
|
||||
let ident = alt p.node { pat_bind(id) { id } };
|
||||
log "collect_local: pushing " + ident;;
|
||||
|
|
@ -24,13 +24,14 @@ fn collect_local(loc: &@local, cx: &ctxt, v: &visit::vt<ctxt>) {
|
|||
visit::visit_local(loc, cx, v);
|
||||
}
|
||||
|
||||
fn collect_pred(e: &@expr, cx: &ctxt, v: &visit::vt<ctxt>) {
|
||||
fn collect_pred(e: @expr, cx: ctxt, v: visit::vt<ctxt>) {
|
||||
alt e.node {
|
||||
expr_check(_, ch) { *cx.cs += [expr_to_constr(cx.tcx, ch)]; }
|
||||
expr_if_check(ex, _, _) { *cx.cs += [expr_to_constr(cx.tcx, ex)]; }
|
||||
|
||||
|
||||
|
||||
|
||||
// If it's a call, generate appropriate instances of the
|
||||
// call's constraints.
|
||||
expr_call(operator, operands) {
|
||||
|
|
@ -47,8 +48,8 @@ fn collect_pred(e: &@expr, cx: &ctxt, v: &visit::vt<ctxt>) {
|
|||
visit::visit_expr(e, cx, v);
|
||||
}
|
||||
|
||||
fn find_locals(tcx: &ty::ctxt, f: &_fn, tps: &[ty_param], sp: &span,
|
||||
i: &fn_ident, id: node_id) -> ctxt {
|
||||
fn find_locals(tcx: ty::ctxt, f: _fn, tps: [ty_param], sp: span, i: fn_ident,
|
||||
id: node_id) -> ctxt {
|
||||
let cx: ctxt = {cs: @mutable [], tcx: tcx};
|
||||
let visitor = visit::default_visitor::<ctxt>();
|
||||
|
||||
|
|
@ -60,8 +61,8 @@ fn find_locals(tcx: &ty::ctxt, f: &_fn, tps: &[ty_param], sp: &span,
|
|||
ret cx;
|
||||
}
|
||||
|
||||
fn add_constraint(tcx: &ty::ctxt, c: sp_constr, next: uint, tbl: constr_map)
|
||||
-> uint {
|
||||
fn add_constraint(tcx: ty::ctxt, c: sp_constr, next: uint, tbl: constr_map) ->
|
||||
uint {
|
||||
log constraint_to_str(tcx, c) + " |-> " + std::uint::str(next);
|
||||
alt c.node {
|
||||
ninit(id, i) { tbl.insert(local_def(id), cinit(next, c.span, i)); }
|
||||
|
|
@ -92,8 +93,8 @@ fn add_constraint(tcx: &ty::ctxt, c: sp_constr, next: uint, tbl: constr_map)
|
|||
|
||||
/* builds a table mapping each local var defined in f
|
||||
to a bit number in the precondition/postcondition vectors */
|
||||
fn mk_fn_info(ccx: &crate_ctxt, f: &_fn, tp: &[ty_param], f_sp: &span,
|
||||
f_name: &fn_ident, id: node_id) {
|
||||
fn mk_fn_info(ccx: crate_ctxt, f: _fn, tp: [ty_param], f_sp: span,
|
||||
f_name: fn_ident, id: node_id) {
|
||||
let name = fn_ident_to_string(id, f_name);
|
||||
let res_map = @new_def_hash::<constraint>();
|
||||
let next: uint = 0u;
|
||||
|
|
@ -155,7 +156,7 @@ fn mk_fn_info(ccx: &crate_ctxt, f: &_fn, tp: &[ty_param], f_sp: &span,
|
|||
/* initializes the global fn_info_map (mapping each function ID, including
|
||||
nested locally defined functions, onto a mapping from local variable name
|
||||
to bit number) */
|
||||
fn mk_f_to_fn_info(ccx: &crate_ctxt, c: @crate) {
|
||||
fn mk_f_to_fn_info(ccx: crate_ctxt, c: @crate) {
|
||||
let visitor =
|
||||
visit::mk_simple_visitor(@{visit_fn:
|
||||
bind mk_fn_info(ccx, _, _, _, _, _)
|
||||
|
|
|
|||
|
|
@ -34,18 +34,18 @@ import util::common::log_block;
|
|||
import syntax::codemap::span;
|
||||
import util::ppaux::fn_ident_to_string;
|
||||
|
||||
fn find_pre_post_mod(_m: &_mod) -> _mod {
|
||||
fn find_pre_post_mod(_m: _mod) -> _mod {
|
||||
log "implement find_pre_post_mod!";
|
||||
fail;
|
||||
}
|
||||
|
||||
fn find_pre_post_native_mod(_m: &native_mod) -> native_mod {
|
||||
fn find_pre_post_native_mod(_m: native_mod) -> native_mod {
|
||||
log "implement find_pre_post_native_mod";
|
||||
fail;
|
||||
}
|
||||
|
||||
fn find_pre_post_obj(ccx: &crate_ctxt, o: _obj) {
|
||||
fn do_a_method(ccx: crate_ctxt, m: &@method) {
|
||||
fn find_pre_post_obj(ccx: crate_ctxt, o: _obj) {
|
||||
fn do_a_method(ccx: crate_ctxt, m: @method) {
|
||||
assert (ccx.fm.contains_key(m.node.id));
|
||||
let fcx: fn_ctxt =
|
||||
{enclosing: ccx.fm.get(m.node.id),
|
||||
|
|
@ -57,7 +57,7 @@ fn find_pre_post_obj(ccx: &crate_ctxt, o: _obj) {
|
|||
for m: @method in o.methods { do_a_method(ccx, m); }
|
||||
}
|
||||
|
||||
fn find_pre_post_item(ccx: &crate_ctxt, i: &item) {
|
||||
fn find_pre_post_item(ccx: crate_ctxt, i: item) {
|
||||
alt i.node {
|
||||
item_const(_, e) {
|
||||
// make a fake fcx
|
||||
|
|
@ -104,15 +104,15 @@ fn find_pre_post_item(ccx: &crate_ctxt, i: &item) {
|
|||
sets the precondition in a to be the result of combining
|
||||
the preconditions for <args>, and the postcondition in a to
|
||||
be the union of all postconditions for <args> */
|
||||
fn find_pre_post_exprs(fcx: &fn_ctxt, args: &[@expr], id: node_id) {
|
||||
fn find_pre_post_exprs(fcx: fn_ctxt, args: [@expr], id: node_id) {
|
||||
if vec::len::<@expr>(args) > 0u {
|
||||
log "find_pre_post_exprs: oper =";
|
||||
log_expr(*args[0]);
|
||||
}
|
||||
fn do_one(fcx: fn_ctxt, e: &@expr) { find_pre_post_expr(fcx, e); }
|
||||
fn do_one(fcx: fn_ctxt, e: @expr) { find_pre_post_expr(fcx, e); }
|
||||
for e: @expr in args { do_one(fcx, e); }
|
||||
|
||||
fn get_pp(ccx: crate_ctxt, e: &@expr) -> pre_and_post {
|
||||
fn get_pp(ccx: crate_ctxt, e: @expr) -> pre_and_post {
|
||||
ret expr_pp(ccx, e);
|
||||
}
|
||||
let pps = vec::map::<@expr, pre_and_post>(bind get_pp(fcx.ccx, _), args);
|
||||
|
|
@ -121,7 +121,7 @@ fn find_pre_post_exprs(fcx: &fn_ctxt, args: &[@expr], id: node_id) {
|
|||
seq_postconds(fcx, vec::map(get_post, pps)));
|
||||
}
|
||||
|
||||
fn find_pre_post_loop(fcx: &fn_ctxt, l: &@local, index: &@expr, body: &blk,
|
||||
fn find_pre_post_loop(fcx: fn_ctxt, l: @local, index: @expr, body: blk,
|
||||
id: node_id) {
|
||||
find_pre_post_expr(fcx, index);
|
||||
find_pre_post_block(fcx, body);
|
||||
|
|
@ -145,8 +145,8 @@ fn find_pre_post_loop(fcx: &fn_ctxt, l: &@local, index: &@expr, body: &blk,
|
|||
// Generates a pre/post assuming that a is the
|
||||
// annotation for an if-expression with consequent conseq
|
||||
// and alternative maybe_alt
|
||||
fn join_then_else(fcx: &fn_ctxt, antec: &@expr, conseq: &blk,
|
||||
maybe_alt: &option::t<@expr>, id: node_id, chck: &if_ty) {
|
||||
fn join_then_else(fcx: fn_ctxt, antec: @expr, conseq: blk,
|
||||
maybe_alt: option::t<@expr>, id: node_id, chck: if_ty) {
|
||||
find_pre_post_expr(fcx, antec);
|
||||
find_pre_post_block(fcx, conseq);
|
||||
alt maybe_alt {
|
||||
|
|
@ -208,8 +208,8 @@ fn join_then_else(fcx: &fn_ctxt, antec: &@expr, conseq: &blk,
|
|||
}
|
||||
}
|
||||
|
||||
fn gen_if_local(fcx: &fn_ctxt, lhs: @expr, rhs: @expr, larger_id: node_id,
|
||||
new_var: node_id, pth: &path) {
|
||||
fn gen_if_local(fcx: fn_ctxt, lhs: @expr, rhs: @expr, larger_id: node_id,
|
||||
new_var: node_id, pth: path) {
|
||||
alt node_id_to_def(fcx.ccx, new_var) {
|
||||
some(d) {
|
||||
alt d {
|
||||
|
|
@ -228,7 +228,7 @@ fn gen_if_local(fcx: &fn_ctxt, lhs: @expr, rhs: @expr, larger_id: node_id,
|
|||
}
|
||||
}
|
||||
|
||||
fn handle_update(fcx: &fn_ctxt, parent: &@expr, lhs: &@expr, rhs: &@expr,
|
||||
fn handle_update(fcx: fn_ctxt, parent: @expr, lhs: @expr, rhs: @expr,
|
||||
ty: oper_type) {
|
||||
find_pre_post_expr(fcx, rhs);
|
||||
alt lhs.node {
|
||||
|
|
@ -291,12 +291,11 @@ fn handle_update(fcx: &fn_ctxt, parent: &@expr, lhs: &@expr, rhs: &@expr,
|
|||
}
|
||||
}
|
||||
|
||||
fn handle_var(fcx: &fn_ctxt, rslt: &pre_and_post, id: node_id, name: ident) {
|
||||
fn handle_var(fcx: fn_ctxt, rslt: pre_and_post, id: node_id, name: ident) {
|
||||
handle_var_def(fcx, rslt, node_id_to_def_strict(fcx.ccx.tcx, id), name);
|
||||
}
|
||||
|
||||
fn handle_var_def(fcx: &fn_ctxt, rslt: &pre_and_post, def: &def,
|
||||
name: ident) {
|
||||
fn handle_var_def(fcx: fn_ctxt, rslt: pre_and_post, def: def, name: ident) {
|
||||
alt def {
|
||||
def_local(d_id) | def_arg(d_id, _) {
|
||||
use_var(fcx, d_id.node);
|
||||
|
|
@ -307,8 +306,8 @@ fn handle_var_def(fcx: &fn_ctxt, rslt: &pre_and_post, def: &def,
|
|||
}
|
||||
}
|
||||
|
||||
fn forget_args_moved_in(fcx: &fn_ctxt, parent: &@expr, modes: &[ty::mode],
|
||||
operands: &[@expr]) {
|
||||
fn forget_args_moved_in(fcx: fn_ctxt, parent: @expr, modes: [ty::mode],
|
||||
operands: [@expr]) {
|
||||
let i = 0u;
|
||||
for mode: ty::mode in modes {
|
||||
if mode == by_move {
|
||||
|
|
@ -319,10 +318,10 @@ fn forget_args_moved_in(fcx: &fn_ctxt, parent: &@expr, modes: &[ty::mode],
|
|||
}
|
||||
|
||||
/* Fills in annotations as a side effect. Does not rebuild the expr */
|
||||
fn find_pre_post_expr(fcx: &fn_ctxt, e: @expr) {
|
||||
fn find_pre_post_expr(fcx: fn_ctxt, e: @expr) {
|
||||
let enclosing = fcx.enclosing;
|
||||
let num_local_vars = num_constraints(enclosing);
|
||||
fn do_rand_(fcx: fn_ctxt, e: &@expr) { find_pre_post_expr(fcx, e); }
|
||||
fn do_rand_(fcx: fn_ctxt, e: @expr) { find_pre_post_expr(fcx, e); }
|
||||
|
||||
|
||||
alt e.node {
|
||||
|
|
@ -487,14 +486,14 @@ fn find_pre_post_expr(fcx: &fn_ctxt, e: @expr) {
|
|||
expr_index(val, sub) { find_pre_post_exprs(fcx, [val, sub], e.id); }
|
||||
expr_alt(ex, alts) {
|
||||
find_pre_post_expr(fcx, ex);
|
||||
fn do_an_alt(fcx: &fn_ctxt, an_alt: &arm) -> pre_and_post {
|
||||
fn do_an_alt(fcx: fn_ctxt, an_alt: arm) -> pre_and_post {
|
||||
find_pre_post_block(fcx, an_alt.body);
|
||||
ret block_pp(fcx.ccx, an_alt.body);
|
||||
}
|
||||
let alt_pps = [];
|
||||
for a: arm in alts { alt_pps += [do_an_alt(fcx, a)]; }
|
||||
fn combine_pp(antec: pre_and_post, fcx: fn_ctxt, pp: &pre_and_post,
|
||||
next: &pre_and_post) -> pre_and_post {
|
||||
fn combine_pp(antec: pre_and_post, fcx: fn_ctxt, pp: pre_and_post,
|
||||
next: pre_and_post) -> pre_and_post {
|
||||
union(pp.precondition, seq_preconds(fcx, [antec, next]));
|
||||
intersect(pp.postcondition, next.postcondition);
|
||||
ret pp;
|
||||
|
|
@ -546,6 +545,7 @@ fn find_pre_post_expr(fcx: &fn_ctxt, e: @expr) {
|
|||
|
||||
|
||||
|
||||
|
||||
expr_bind(operator, maybe_args) {
|
||||
let args = [];
|
||||
let cmodes = callee_modes(fcx, operator.id);
|
||||
|
|
@ -578,7 +578,7 @@ fn find_pre_post_expr(fcx: &fn_ctxt, e: @expr) {
|
|||
}
|
||||
}
|
||||
|
||||
fn find_pre_post_stmt(fcx: &fn_ctxt, s: &stmt) {
|
||||
fn find_pre_post_stmt(fcx: fn_ctxt, s: stmt) {
|
||||
log "stmt =";
|
||||
log_stmt(s);
|
||||
alt s.node {
|
||||
|
|
@ -681,7 +681,7 @@ fn find_pre_post_stmt(fcx: &fn_ctxt, s: &stmt) {
|
|||
}
|
||||
}
|
||||
|
||||
fn find_pre_post_block(fcx: &fn_ctxt, b: blk) {
|
||||
fn find_pre_post_block(fcx: fn_ctxt, b: blk) {
|
||||
/* Want to say that if there is a break or cont in this
|
||||
block, then that invalidates the poststate upheld by
|
||||
any of the stmts after it.
|
||||
|
|
@ -700,7 +700,7 @@ fn find_pre_post_block(fcx: &fn_ctxt, b: blk) {
|
|||
*/
|
||||
|
||||
let nv = num_constraints(fcx.enclosing);
|
||||
fn do_one_(fcx: fn_ctxt, s: &@stmt) {
|
||||
fn do_one_(fcx: fn_ctxt, s: @stmt) {
|
||||
find_pre_post_stmt(fcx, *s);
|
||||
/*
|
||||
log_err "pre_post for stmt:";
|
||||
|
|
@ -710,7 +710,7 @@ fn find_pre_post_block(fcx: &fn_ctxt, b: blk) {
|
|||
*/
|
||||
}
|
||||
for s: @stmt in b.node.stmts { do_one_(fcx, s); }
|
||||
fn do_inner_(fcx: fn_ctxt, e: &@expr) { find_pre_post_expr(fcx, e); }
|
||||
fn do_inner_(fcx: fn_ctxt, e: @expr) { find_pre_post_expr(fcx, e); }
|
||||
let do_inner = bind do_inner_(fcx, _);
|
||||
option::map::<@expr, ()>(do_inner, b.node.expr);
|
||||
|
||||
|
|
@ -739,7 +739,7 @@ fn find_pre_post_block(fcx: &fn_ctxt, b: blk) {
|
|||
set_pre_and_post(fcx.ccx, b.node.id, block_precond, block_postcond);
|
||||
}
|
||||
|
||||
fn find_pre_post_fn(fcx: &fn_ctxt, f: &_fn) {
|
||||
fn find_pre_post_fn(fcx: fn_ctxt, f: _fn) {
|
||||
// hack
|
||||
use_var(fcx, tsconstr_to_node_id(fcx.enclosing.i_return));
|
||||
use_var(fcx, tsconstr_to_node_id(fcx.enclosing.i_diverge));
|
||||
|
|
@ -754,8 +754,8 @@ fn find_pre_post_fn(fcx: &fn_ctxt, f: &_fn) {
|
|||
}
|
||||
}
|
||||
|
||||
fn fn_pre_post(f: &_fn, tps: &[ty_param], sp: &span, i: &fn_ident,
|
||||
id: node_id, ccx: &crate_ctxt, v: &visit::vt<crate_ctxt>) {
|
||||
fn fn_pre_post(f: _fn, tps: [ty_param], sp: span, i: fn_ident, id: node_id,
|
||||
ccx: crate_ctxt, v: visit::vt<crate_ctxt>) {
|
||||
visit::visit_fn(f, tps, sp, i, id, ccx, v);
|
||||
assert (ccx.fm.contains_key(id));
|
||||
let fcx =
|
||||
|
|
|
|||
|
|
@ -32,24 +32,24 @@ import util::common::log_stmt;
|
|||
import util::common::log_stmt_err;
|
||||
import util::common::log_expr_err;
|
||||
|
||||
fn forbid_upvar(fcx: &fn_ctxt, rhs_id: &node_id, sp: &span,
|
||||
t: oper_type) {
|
||||
fn forbid_upvar(fcx: fn_ctxt, rhs_id: node_id, sp: span, t: oper_type) {
|
||||
alt t {
|
||||
oper_move. {
|
||||
alt local_node_id_to_def(fcx, rhs_id) {
|
||||
some(def_upvar(_,_,_)) {
|
||||
fcx.ccx.tcx.sess.span_err(sp, "Tried to deinitialize a variable \
|
||||
some(def_upvar(_, _, _)) {
|
||||
fcx.ccx.tcx.sess.span_err(sp,
|
||||
"Tried to deinitialize a variable \
|
||||
declared in a different scope");
|
||||
}
|
||||
_ {}
|
||||
}
|
||||
_ { }
|
||||
}
|
||||
}
|
||||
_ { /* do nothing */ }
|
||||
_ {/* do nothing */ }
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_move_or_copy(fcx: &fn_ctxt, post: &poststate, rhs_path: &path,
|
||||
rhs_id: &node_id, instlhs: &inst, init_op: &init_op) {
|
||||
fn handle_move_or_copy(fcx: fn_ctxt, post: poststate, rhs_path: path,
|
||||
rhs_id: node_id, instlhs: inst, init_op: init_op) {
|
||||
forbid_upvar(fcx, rhs_id, rhs_path.span, op_to_oper_ty(init_op));
|
||||
|
||||
let rhs_d_id = local_node_id_to_def_id(fcx, rhs_id);
|
||||
|
|
@ -67,7 +67,7 @@ fn handle_move_or_copy(fcx: &fn_ctxt, post: &poststate, rhs_path: &path,
|
|||
}
|
||||
}
|
||||
|
||||
fn seq_states(fcx: &fn_ctxt, pres: &prestate, bindings: &[binding]) ->
|
||||
fn seq_states(fcx: fn_ctxt, pres: prestate, bindings: [binding]) ->
|
||||
{changed: bool, post: poststate} {
|
||||
let changed = false;
|
||||
let post = tritv_clone(pres);
|
||||
|
|
@ -105,7 +105,7 @@ fn seq_states(fcx: &fn_ctxt, pres: &prestate, bindings: &[binding]) ->
|
|||
ret {changed: changed, post: post};
|
||||
}
|
||||
|
||||
fn find_pre_post_state_sub(fcx: &fn_ctxt, pres: &prestate, e: &@expr,
|
||||
fn find_pre_post_state_sub(fcx: fn_ctxt, pres: prestate, e: @expr,
|
||||
parent: node_id, c: option::t<tsconstr>) -> bool {
|
||||
let changed = find_pre_post_state_expr(fcx, pres, e);
|
||||
|
||||
|
|
@ -121,8 +121,8 @@ fn find_pre_post_state_sub(fcx: &fn_ctxt, pres: &prestate, e: &@expr,
|
|||
ret changed;
|
||||
}
|
||||
|
||||
fn find_pre_post_state_two(fcx: &fn_ctxt, pres: &prestate, lhs: &@expr,
|
||||
rhs: &@expr, parent: node_id, ty: oper_type) ->
|
||||
fn find_pre_post_state_two(fcx: fn_ctxt, pres: prestate, lhs: @expr,
|
||||
rhs: @expr, parent: node_id, ty: oper_type) ->
|
||||
bool {
|
||||
let changed = set_prestate_ann(fcx.ccx, parent, pres);
|
||||
changed = find_pre_post_state_expr(fcx, pres, lhs) || changed;
|
||||
|
|
@ -184,8 +184,8 @@ fn find_pre_post_state_two(fcx: &fn_ctxt, pres: &prestate, lhs: &@expr,
|
|||
ret changed;
|
||||
}
|
||||
|
||||
fn find_pre_post_state_call(fcx: &fn_ctxt, pres: &prestate, a: &@expr,
|
||||
id: node_id, ops: &[init_op], bs: &[@expr],
|
||||
fn find_pre_post_state_call(fcx: fn_ctxt, pres: prestate, a: @expr,
|
||||
id: node_id, ops: [init_op], bs: [@expr],
|
||||
cf: controlflow) -> bool {
|
||||
let changed = find_pre_post_state_expr(fcx, pres, a);
|
||||
// FIXME: This could be a typestate constraint
|
||||
|
|
@ -199,9 +199,9 @@ fn find_pre_post_state_call(fcx: &fn_ctxt, pres: &prestate, a: &@expr,
|
|||
bs, cf) || changed;
|
||||
}
|
||||
|
||||
fn find_pre_post_state_exprs(fcx: &fn_ctxt, pres: &prestate, id: node_id,
|
||||
ops: &[init_op], es: &[@expr], cf: controlflow)
|
||||
-> bool {
|
||||
fn find_pre_post_state_exprs(fcx: fn_ctxt, pres: prestate, id: node_id,
|
||||
ops: [init_op], es: [@expr], cf: controlflow) ->
|
||||
bool {
|
||||
let rs = seq_states(fcx, pres, anon_bindings(ops, es));
|
||||
let changed = rs.changed | set_prestate_ann(fcx.ccx, id, pres);
|
||||
/* if this is a failing call, it sets everything as initialized */
|
||||
|
|
@ -215,8 +215,8 @@ fn find_pre_post_state_exprs(fcx: &fn_ctxt, pres: &prestate, id: node_id,
|
|||
ret changed;
|
||||
}
|
||||
|
||||
fn find_pre_post_state_loop(fcx: &fn_ctxt, pres: prestate, l: &@local,
|
||||
index: &@expr, body: &blk, id: node_id) -> bool {
|
||||
fn find_pre_post_state_loop(fcx: fn_ctxt, pres: prestate, l: @local,
|
||||
index: @expr, body: blk, id: node_id) -> bool {
|
||||
let loop_pres = intersect_states(pres, block_poststate(fcx.ccx, body));
|
||||
|
||||
let changed =
|
||||
|
|
@ -245,7 +245,7 @@ fn find_pre_post_state_loop(fcx: &fn_ctxt, pres: prestate, l: &@local,
|
|||
}
|
||||
}
|
||||
|
||||
fn gen_if_local(fcx: &fn_ctxt, p: &poststate, e: &@expr) -> bool {
|
||||
fn gen_if_local(fcx: fn_ctxt, p: poststate, e: @expr) -> bool {
|
||||
alt e.node {
|
||||
expr_path(pth) {
|
||||
alt fcx.ccx.tcx.def_map.find(e.id) {
|
||||
|
|
@ -260,9 +260,9 @@ fn gen_if_local(fcx: &fn_ctxt, p: &poststate, e: &@expr) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn join_then_else(fcx: &fn_ctxt, antec: &@expr, conseq: &blk,
|
||||
maybe_alt: &option::t<@expr>, id: node_id, chk: &if_ty,
|
||||
pres: &prestate) -> bool {
|
||||
fn join_then_else(fcx: fn_ctxt, antec: @expr, conseq: blk,
|
||||
maybe_alt: option::t<@expr>, id: node_id, chk: if_ty,
|
||||
pres: prestate) -> bool {
|
||||
let changed =
|
||||
set_prestate_ann(fcx.ccx, id, pres) |
|
||||
find_pre_post_state_expr(fcx, pres, antec);
|
||||
|
|
@ -291,18 +291,18 @@ fn join_then_else(fcx: &fn_ctxt, antec: &@expr, conseq: &blk,
|
|||
tritv_set(bit_num(fcx, c.node), conseq_prestate, ttrue);
|
||||
changed |=
|
||||
find_pre_post_state_block(fcx, conseq_prestate, conseq) |
|
||||
set_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, antec));
|
||||
set_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, antec));
|
||||
}
|
||||
_ {
|
||||
changed |=
|
||||
find_pre_post_state_block(fcx, expr_poststate(fcx.ccx, antec),
|
||||
conseq) |
|
||||
set_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, antec));
|
||||
set_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, antec));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
some(altern) {
|
||||
changed |=
|
||||
find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, antec),
|
||||
|
|
@ -341,8 +341,7 @@ fn join_then_else(fcx: &fn_ctxt, antec: &@expr, conseq: &blk,
|
|||
ret changed;
|
||||
}
|
||||
|
||||
fn find_pre_post_state_expr(fcx: &fn_ctxt, pres: &prestate, e: @expr) ->
|
||||
bool {
|
||||
fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
|
||||
let num_constrs = num_constraints(fcx.enclosing);
|
||||
|
||||
|
||||
|
|
@ -630,8 +629,7 @@ fn find_pre_post_state_expr(fcx: &fn_ctxt, pres: &prestate, e: @expr) ->
|
|||
}
|
||||
}
|
||||
|
||||
fn find_pre_post_state_stmt(fcx: &fn_ctxt, pres: &prestate, s: @stmt) ->
|
||||
bool {
|
||||
fn find_pre_post_state_stmt(fcx: fn_ctxt, pres: prestate, s: @stmt) -> bool {
|
||||
let stmt_ann = stmt_to_ann(fcx.ccx, *s);
|
||||
|
||||
/*
|
||||
|
|
@ -705,8 +703,7 @@ fn find_pre_post_state_stmt(fcx: &fn_ctxt, pres: &prestate, s: @stmt) ->
|
|||
|
||||
/* Updates the pre- and post-states of statements in the block,
|
||||
returns a boolean flag saying whether any pre- or poststates changed */
|
||||
fn find_pre_post_state_block(fcx: &fn_ctxt, pres0: &prestate, b: &blk) ->
|
||||
bool {
|
||||
fn find_pre_post_state_block(fcx: fn_ctxt, pres0: prestate, b: blk) -> bool {
|
||||
/* First, set the pre-states and post-states for every expression */
|
||||
|
||||
let pres = pres0;
|
||||
|
|
@ -748,7 +745,7 @@ fn find_pre_post_state_block(fcx: &fn_ctxt, pres0: &prestate, b: &blk) ->
|
|||
ret changed;
|
||||
}
|
||||
|
||||
fn find_pre_post_state_fn(fcx: &fn_ctxt, f: &_fn) -> bool {
|
||||
fn find_pre_post_state_fn(fcx: fn_ctxt, f: _fn) -> bool {
|
||||
let num_constrs = num_constraints(fcx.enclosing);
|
||||
// All constraints are considered false until proven otherwise.
|
||||
// This ensures that intersect works correctly.
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ fn trit_minus(a: trit, b: trit) -> trit {
|
|||
tfalse. { ttrue }
|
||||
|
||||
|
||||
|
||||
/* internally contradictory, but
|
||||
I guess it'll get flagged? */
|
||||
dont_care. {
|
||||
|
|
@ -68,6 +69,7 @@ fn trit_minus(a: trit, b: trit) -> trit {
|
|||
ttrue. { tfalse }
|
||||
|
||||
|
||||
|
||||
/* see above comment */
|
||||
_ {
|
||||
tfalse
|
||||
|
|
@ -86,6 +88,7 @@ fn trit_or(a: trit, b: trit) -> trit {
|
|||
ttrue. { dont_care }
|
||||
|
||||
|
||||
|
||||
/* FIXME: ?????? */
|
||||
_ {
|
||||
tfalse
|
||||
|
|
@ -105,12 +108,14 @@ fn trit_and(a: trit, b: trit) -> trit {
|
|||
dont_care. { b }
|
||||
|
||||
|
||||
|
||||
// also seems wrong for case b = ttrue
|
||||
ttrue. {
|
||||
alt b {
|
||||
dont_care. { ttrue }
|
||||
|
||||
|
||||
|
||||
// ??? Seems wrong
|
||||
ttrue. {
|
||||
ttrue
|
||||
|
|
@ -118,6 +123,7 @@ fn trit_and(a: trit, b: trit) -> trit {
|
|||
|
||||
|
||||
|
||||
|
||||
// false wins, since if something is uninit
|
||||
// on one path, we care
|
||||
// (Rationale: it's always safe to assume that
|
||||
|
|
@ -131,6 +137,7 @@ fn trit_and(a: trit, b: trit) -> trit {
|
|||
|
||||
|
||||
|
||||
|
||||
// Rationale: if it's uninit on one path,
|
||||
// we can consider it as uninit on all paths
|
||||
tfalse. {
|
||||
|
|
@ -145,7 +152,7 @@ fn change(changed: bool, old: trit, new: trit) -> bool {
|
|||
changed || new != old
|
||||
}
|
||||
|
||||
fn tritv_difference(p1: &t, p2: &t) -> bool {
|
||||
fn tritv_difference(p1: t, p2: t) -> bool {
|
||||
let i: uint = 0u;
|
||||
assert (p1.nbits == p2.nbits);
|
||||
let sz: uint = p1.nbits;
|
||||
|
|
@ -160,7 +167,7 @@ fn tritv_difference(p1: &t, p2: &t) -> bool {
|
|||
ret changed;
|
||||
}
|
||||
|
||||
fn tritv_union(p1: &t, p2: &t) -> bool {
|
||||
fn tritv_union(p1: t, p2: t) -> bool {
|
||||
let i: uint = 0u;
|
||||
assert (p1.nbits == p2.nbits);
|
||||
let sz: uint = p1.nbits;
|
||||
|
|
@ -175,7 +182,7 @@ fn tritv_union(p1: &t, p2: &t) -> bool {
|
|||
ret changed;
|
||||
}
|
||||
|
||||
fn tritv_intersect(p1: &t, p2: &t) -> bool {
|
||||
fn tritv_intersect(p1: t, p2: t) -> bool {
|
||||
let i: uint = 0u;
|
||||
assert (p1.nbits == p2.nbits);
|
||||
let sz: uint = p1.nbits;
|
||||
|
|
@ -190,14 +197,14 @@ fn tritv_intersect(p1: &t, p2: &t) -> bool {
|
|||
ret changed;
|
||||
}
|
||||
|
||||
fn tritv_get(v: &t, i: uint) -> trit {
|
||||
fn tritv_get(v: t, i: uint) -> trit {
|
||||
let b1 = bitv::get(v.uncertain, i);
|
||||
let b2 = bitv::get(v.val, i);
|
||||
assert (!(b1 && b2));
|
||||
if b1 { dont_care } else if b2 { ttrue } else { tfalse }
|
||||
}
|
||||
|
||||
fn tritv_set(i: uint, v: &t, t: trit) -> bool {
|
||||
fn tritv_set(i: uint, v: t, t: trit) -> bool {
|
||||
let old = tritv_get(v, i);
|
||||
alt t {
|
||||
dont_care. {
|
||||
|
|
@ -213,7 +220,7 @@ fn tritv_set(i: uint, v: &t, t: trit) -> bool {
|
|||
ret change(false, old, t);
|
||||
}
|
||||
|
||||
fn tritv_copy(target: &t, source: &t) -> bool {
|
||||
fn tritv_copy(target: t, source: t) -> bool {
|
||||
assert (target.nbits == source.nbits);
|
||||
let changed =
|
||||
!bitv::equal(target.uncertain, source.uncertain) ||
|
||||
|
|
@ -223,28 +230,28 @@ fn tritv_copy(target: &t, source: &t) -> bool {
|
|||
ret changed;
|
||||
}
|
||||
|
||||
fn tritv_set_all(v: &t) {
|
||||
fn tritv_set_all(v: t) {
|
||||
let i: uint = 0u;
|
||||
while i < v.nbits { tritv_set(i, v, ttrue); i += 1u; }
|
||||
}
|
||||
|
||||
fn tritv_clear(v: &t) {
|
||||
fn tritv_clear(v: t) {
|
||||
let i: uint = 0u;
|
||||
while i < v.nbits { tritv_set(i, v, dont_care); i += 1u; }
|
||||
}
|
||||
|
||||
fn tritv_kill(v: &t) {
|
||||
fn tritv_kill(v: t) {
|
||||
let i: uint = 0u;
|
||||
while i < v.nbits { tritv_set(i, v, tfalse); i += 1u; }
|
||||
}
|
||||
|
||||
fn tritv_clone(v: &t) -> t {
|
||||
fn tritv_clone(v: t) -> t {
|
||||
ret {uncertain: bitv::clone(v.uncertain),
|
||||
val: bitv::clone(v.val),
|
||||
nbits: v.nbits};
|
||||
}
|
||||
|
||||
fn tritv_doesntcare(v: &t) -> bool {
|
||||
fn tritv_doesntcare(v: t) -> bool {
|
||||
let i: uint = 0u;
|
||||
while i < v.nbits {
|
||||
if tritv_get(v, i) != dont_care { ret false; }
|
||||
|
|
@ -253,7 +260,7 @@ fn tritv_doesntcare(v: &t) -> bool {
|
|||
ret true;
|
||||
}
|
||||
|
||||
fn to_vec(v: &t) -> [uint] {
|
||||
fn to_vec(v: t) -> [uint] {
|
||||
let i: uint = 0u;
|
||||
let rslt: [uint] = [];
|
||||
while i < v.nbits {
|
||||
|
|
@ -268,7 +275,7 @@ fn to_vec(v: &t) -> [uint] {
|
|||
ret rslt;
|
||||
}
|
||||
|
||||
fn to_str(v: &t) -> str {
|
||||
fn to_str(v: t) -> str {
|
||||
let i: uint = 0u;
|
||||
let rs: str = "";
|
||||
while i < v.nbits {
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -293,10 +293,11 @@ tag ty_ {
|
|||
for this type. */
|
||||
|
||||
|
||||
|
||||
/* bot represents the value of functions that don't return a value
|
||||
locally to their context. in contrast, things like log that do
|
||||
return, but don't return a meaningful value, have result type nil. */
|
||||
ty_bool;
|
||||
ty_bool;
|
||||
ty_int;
|
||||
ty_uint;
|
||||
ty_float;
|
||||
|
|
@ -381,6 +382,7 @@ tag controlflow {
|
|||
// raise an error or exit (i.e. never return to the caller)
|
||||
|
||||
|
||||
|
||||
return; // everything else
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import std::option;
|
|||
import codemap::span;
|
||||
import ast::*;
|
||||
|
||||
fn respan<@T>(sp: &span, t: &T) -> spanned<T> { ret {node: t, span: sp}; }
|
||||
fn respan<@T>(sp: span, t: T) -> spanned<T> { ret {node: t, span: sp}; }
|
||||
|
||||
/* assuming that we're not in macro expansion */
|
||||
fn mk_sp(lo: uint, hi: uint) -> span {
|
||||
|
|
@ -13,13 +13,13 @@ fn mk_sp(lo: uint, hi: uint) -> span {
|
|||
// make this a const, once the compiler supports it
|
||||
fn dummy_sp() -> span { ret mk_sp(0u, 0u); }
|
||||
|
||||
fn path_name(p: &path) -> str { path_name_i(p.node.idents) }
|
||||
fn path_name(p: path) -> str { path_name_i(p.node.idents) }
|
||||
|
||||
fn path_name_i(idents: &[ident]) -> str { str::connect(idents, "::") }
|
||||
fn path_name_i(idents: [ident]) -> str { str::connect(idents, "::") }
|
||||
|
||||
fn local_def(id: node_id) -> def_id { ret {crate: local_crate, node: id}; }
|
||||
|
||||
fn variant_def_ids(d: &def) -> {tg: def_id, var: def_id} {
|
||||
fn variant_def_ids(d: def) -> {tg: def_id, var: def_id} {
|
||||
alt d { def_variant(tag_id, var_id) { ret {tg: tag_id, var: var_id}; } }
|
||||
}
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ type pat_id_map = std::map::hashmap<str, node_id>;
|
|||
|
||||
// This is used because same-named variables in alternative patterns need to
|
||||
// use the node_id of their namesake in the first pattern.
|
||||
fn pat_id_map(pat: &@pat) -> pat_id_map {
|
||||
fn pat_id_map(pat: @pat) -> pat_id_map {
|
||||
let map = std::map::new_str_hash::<node_id>();
|
||||
for each bound in pat_bindings(pat) {
|
||||
let name = alt bound.node { pat_bind(n) { n } };
|
||||
|
|
@ -57,7 +57,7 @@ fn pat_id_map(pat: &@pat) -> pat_id_map {
|
|||
}
|
||||
|
||||
// FIXME: could return a constrained type
|
||||
iter pat_bindings(pat: &@pat) -> @pat {
|
||||
iter pat_bindings(pat: @pat) -> @pat {
|
||||
alt pat.node {
|
||||
pat_bind(_) { put pat; }
|
||||
pat_tag(_, sub) {
|
||||
|
|
@ -74,7 +74,7 @@ iter pat_bindings(pat: &@pat) -> @pat {
|
|||
}
|
||||
}
|
||||
|
||||
fn pat_binding_ids(pat: &@pat) -> [node_id] {
|
||||
fn pat_binding_ids(pat: @pat) -> [node_id] {
|
||||
let found = [];
|
||||
for each b in pat_bindings(pat) { found += [b.id]; }
|
||||
ret found;
|
||||
|
|
@ -117,7 +117,7 @@ fn unop_to_str(op: unop) -> str {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_path(e: &@expr) -> bool {
|
||||
fn is_path(e: @expr) -> bool {
|
||||
ret alt e.node { expr_path(_) { true } _ { false } };
|
||||
}
|
||||
|
||||
|
|
@ -179,9 +179,9 @@ fn is_constraint_arg(e: @expr) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn eq_ty(a: &@ty, b: &@ty) -> bool { ret std::box::ptr_eq(a, b); }
|
||||
fn eq_ty(a: @ty, b: @ty) -> bool { ret std::box::ptr_eq(a, b); }
|
||||
|
||||
fn hash_ty(t: &@ty) -> uint { ret t.span.lo << 16u + t.span.hi; }
|
||||
fn hash_ty(t: @ty) -> uint { ret t.span.lo << 16u + t.span.hi; }
|
||||
|
||||
fn block_from_expr(e: @expr) -> blk {
|
||||
let blk_ = checked_blk([], option::some::<@expr>(e), e.id);
|
||||
|
|
@ -193,13 +193,13 @@ fn checked_blk(stmts1: [@stmt], expr1: option::t<@expr>, id1: node_id) ->
|
|||
ret {stmts: stmts1, expr: expr1, id: id1, rules: checked};
|
||||
}
|
||||
|
||||
fn obj_field_from_anon_obj_field(f: &anon_obj_field) -> obj_field {
|
||||
fn obj_field_from_anon_obj_field(f: anon_obj_field) -> obj_field {
|
||||
ret {mut: f.mut, ty: f.ty, ident: f.ident, id: f.id};
|
||||
}
|
||||
|
||||
// This is a convenience function to transfor ternary expressions to if
|
||||
// expressions so that they can be treated the same
|
||||
fn ternary_to_if(e: &@expr) -> @expr {
|
||||
fn ternary_to_if(e: @expr) -> @expr {
|
||||
alt e.node {
|
||||
expr_ternary(cond, then, els) {
|
||||
let then_blk = block_from_expr(then);
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ tag opt_span {
|
|||
}
|
||||
type span = {lo: uint, hi: uint, expanded_from: opt_span};
|
||||
|
||||
fn span_to_str(sp: &span, cm: &codemap) -> str {
|
||||
fn span_to_str(sp: span, cm: codemap) -> str {
|
||||
let cur = sp;
|
||||
let res = "";
|
||||
let prev_file = none;
|
||||
|
|
@ -98,8 +98,8 @@ fn span_to_str(sp: &span, cm: &codemap) -> str {
|
|||
ret res;
|
||||
}
|
||||
|
||||
fn emit_diagnostic(sp: &option::t<span>, msg: &str, kind: &str, color: u8,
|
||||
cm: &codemap) {
|
||||
fn emit_diagnostic(sp: option::t<span>, msg: str, kind: str, color: u8,
|
||||
cm: codemap) {
|
||||
let ss = "";
|
||||
let maybe_lines: option::t<@file_lines> = none;
|
||||
alt sp {
|
||||
|
|
@ -120,7 +120,7 @@ fn emit_diagnostic(sp: &option::t<span>, msg: &str, kind: &str, color: u8,
|
|||
maybe_highlight_lines(sp, cm, maybe_lines);
|
||||
}
|
||||
|
||||
fn maybe_highlight_lines(sp: &option::t<span>, cm: &codemap,
|
||||
fn maybe_highlight_lines(sp: option::t<span>, cm: codemap,
|
||||
maybe_lines: option::t<@file_lines>) {
|
||||
|
||||
alt maybe_lines {
|
||||
|
|
@ -188,13 +188,13 @@ fn maybe_highlight_lines(sp: &option::t<span>, cm: &codemap,
|
|||
}
|
||||
}
|
||||
|
||||
fn emit_warning(sp: &option::t<span>, msg: &str, cm: &codemap) {
|
||||
fn emit_warning(sp: option::t<span>, msg: str, cm: codemap) {
|
||||
emit_diagnostic(sp, msg, "warning", 11u8, cm);
|
||||
}
|
||||
fn emit_error(sp: &option::t<span>, msg: &str, cm: &codemap) {
|
||||
fn emit_error(sp: option::t<span>, msg: str, cm: codemap) {
|
||||
emit_diagnostic(sp, msg, "error", 9u8, cm);
|
||||
}
|
||||
fn emit_note(sp: &option::t<span>, msg: &str, cm: &codemap) {
|
||||
fn emit_note(sp: option::t<span>, msg: str, cm: codemap) {
|
||||
emit_diagnostic(sp, msg, "note", 10u8, cm);
|
||||
}
|
||||
|
||||
|
|
@ -210,7 +210,7 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {
|
|||
ret @{name: lo.filename, lines: lines};
|
||||
}
|
||||
|
||||
fn get_line(fm: filemap, line: int, file: &str) -> str {
|
||||
fn get_line(fm: filemap, line: int, file: str) -> str {
|
||||
let begin: uint = fm.lines[line].byte - fm.start_pos.byte;
|
||||
let end: uint;
|
||||
if line as uint < vec::len(fm.lines) - 1u {
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ import std::map::new_str_hash;
|
|||
import codemap;
|
||||
|
||||
type syntax_expander =
|
||||
fn(&ext_ctxt, span, @ast::expr, &option::t<str>) -> @ast::expr;
|
||||
fn(ext_ctxt, span, @ast::expr, option::t<str>) -> @ast::expr;
|
||||
type macro_def = {ident: str, ext: syntax_extension};
|
||||
type macro_definer =
|
||||
fn(&ext_ctxt, span, @ast::expr, &option::t<str>) -> macro_def;
|
||||
fn(ext_ctxt, span, @ast::expr, option::t<str>) -> macro_def;
|
||||
|
||||
tag syntax_extension {
|
||||
normal(syntax_expander);
|
||||
|
|
@ -83,7 +83,7 @@ obj ext_ctxt(sess: @session,
|
|||
|
||||
}
|
||||
|
||||
fn mk_ctxt(sess: &session) -> ext_ctxt {
|
||||
fn mk_ctxt(sess: session) -> ext_ctxt {
|
||||
// FIXME: Some extensions work by building ASTs with paths to functions
|
||||
// they need to call at runtime. As those functions live in the std crate,
|
||||
// the paths are prefixed with "std::". Unfortunately, these paths can't
|
||||
|
|
@ -96,7 +96,7 @@ fn mk_ctxt(sess: &session) -> ext_ctxt {
|
|||
ret ext_ctxt(@sess, crate_file_name_hack, codemap::os_none);
|
||||
}
|
||||
|
||||
fn expr_to_str(cx: &ext_ctxt, expr: @ast::expr, error: &str) -> str {
|
||||
fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, error: str) -> str {
|
||||
alt expr.node {
|
||||
ast::expr_lit(l) {
|
||||
alt l.node {
|
||||
|
|
@ -108,7 +108,7 @@ fn expr_to_str(cx: &ext_ctxt, expr: @ast::expr, error: &str) -> str {
|
|||
}
|
||||
}
|
||||
|
||||
fn expr_to_ident(cx: &ext_ctxt, expr: @ast::expr, error: &str) -> ast::ident {
|
||||
fn expr_to_ident(cx: ext_ctxt, expr: @ast::expr, error: str) -> ast::ident {
|
||||
alt expr.node {
|
||||
ast::expr_path(p) {
|
||||
if vec::len(p.node.types) > 0u || vec::len(p.node.idents) != 1u {
|
||||
|
|
@ -119,7 +119,7 @@ fn expr_to_ident(cx: &ext_ctxt, expr: @ast::expr, error: &str) -> ast::ident {
|
|||
}
|
||||
}
|
||||
|
||||
fn make_new_lit(cx: &ext_ctxt, sp: codemap::span, lit: ast::lit_) ->
|
||||
fn make_new_lit(cx: ext_ctxt, sp: codemap::span, lit: ast::lit_) ->
|
||||
@ast::expr {
|
||||
let sp_lit = @{node: lit, span: sp};
|
||||
ret @{id: cx.next_id(), node: ast::expr_lit(sp_lit), span: sp};
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import std::option;
|
|||
import base::*;
|
||||
import syntax::ast;
|
||||
|
||||
fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr,
|
||||
_body: &option::t<str>) -> @ast::expr {
|
||||
fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr,
|
||||
_body: option::t<str>) -> @ast::expr {
|
||||
let args: [@ast::expr] =
|
||||
alt arg.node {
|
||||
ast::expr_vec(elts, _) { elts }
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ import std::generic_os;
|
|||
import base::*;
|
||||
export expand_syntax_ext;
|
||||
|
||||
fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr,
|
||||
_body: &option::t<str>) -> @ast::expr {
|
||||
fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr,
|
||||
_body: option::t<str>) -> @ast::expr {
|
||||
let args: [@ast::expr] =
|
||||
alt arg.node {
|
||||
ast::expr_vec(elts, _) { elts }
|
||||
|
|
@ -33,7 +33,7 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr,
|
|||
}
|
||||
}
|
||||
|
||||
fn make_new_str(cx: &ext_ctxt, sp: codemap::span, s: &str) -> @ast::expr {
|
||||
fn make_new_str(cx: ext_ctxt, sp: codemap::span, s: str) -> @ast::expr {
|
||||
ret make_new_lit(cx, sp, ast::lit_str(s));
|
||||
}
|
||||
//
|
||||
|
|
|
|||
|
|
@ -15,9 +15,8 @@ import syntax::fold::*;
|
|||
import syntax::ext::base::*;
|
||||
|
||||
|
||||
fn expand_expr(exts: &hashmap<str, syntax_extension>, cx: &ext_ctxt,
|
||||
e: &expr_, fld: ast_fold, orig: &fn(&expr_, ast_fold) -> expr_)
|
||||
-> expr_ {
|
||||
fn expand_expr(exts: hashmap<str, syntax_extension>, cx: ext_ctxt, e: expr_,
|
||||
fld: ast_fold, orig: fn(expr_, ast_fold) -> expr_) -> expr_ {
|
||||
ret alt e {
|
||||
expr_mac(mac) {
|
||||
alt mac.node {
|
||||
|
|
@ -53,7 +52,7 @@ fn expand_expr(exts: &hashmap<str, syntax_extension>, cx: &ext_ctxt,
|
|||
};
|
||||
}
|
||||
|
||||
fn expand_crate(sess: &session::session, c: &@crate) -> @crate {
|
||||
fn expand_crate(sess: session::session, c: @crate) -> @crate {
|
||||
let exts = syntax_expander_table();
|
||||
let afp = default_ast_fold();
|
||||
let cx: ext_ctxt = mk_ctxt(sess);
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ import base::*;
|
|||
import codemap::span;
|
||||
export expand_syntax_ext;
|
||||
|
||||
fn expand_syntax_ext(cx: &ext_ctxt, sp: span, arg: @ast::expr,
|
||||
_body: &option::t<str>) -> @ast::expr {
|
||||
fn expand_syntax_ext(cx: ext_ctxt, sp: span, arg: @ast::expr,
|
||||
_body: option::t<str>) -> @ast::expr {
|
||||
let args: [@ast::expr] =
|
||||
alt arg.node {
|
||||
ast::expr_vec(elts, _) { elts }
|
||||
|
|
@ -33,7 +33,7 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: span, arg: @ast::expr,
|
|||
let fmtspan = args[0].span;
|
||||
log "Format string:";
|
||||
log fmt;
|
||||
fn parse_fmt_err_(cx: &ext_ctxt, sp: span, msg: &str) -> ! {
|
||||
fn parse_fmt_err_(cx: ext_ctxt, sp: span, msg: str) -> ! {
|
||||
cx.span_fatal(sp, msg);
|
||||
}
|
||||
let parse_fmt_err = bind parse_fmt_err_(cx, fmtspan, _);
|
||||
|
|
@ -44,49 +44,49 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: span, arg: @ast::expr,
|
|||
// FIXME: A lot of these functions for producing expressions can probably
|
||||
// be factored out in common with other code that builds expressions.
|
||||
// FIXME: Cleanup the naming of these functions
|
||||
fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
|
||||
args: &[@ast::expr]) -> @ast::expr {
|
||||
fn make_new_lit(cx: &ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr {
|
||||
fn pieces_to_expr(cx: ext_ctxt, sp: span, pieces: [piece], args: [@ast::expr])
|
||||
-> @ast::expr {
|
||||
fn make_new_lit(cx: ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr {
|
||||
let sp_lit = @{node: lit, span: sp};
|
||||
ret @{id: cx.next_id(), node: ast::expr_lit(sp_lit), span: sp};
|
||||
}
|
||||
fn make_new_str(cx: &ext_ctxt, sp: span, s: &str) -> @ast::expr {
|
||||
fn make_new_str(cx: ext_ctxt, sp: span, s: str) -> @ast::expr {
|
||||
let lit = ast::lit_str(s);
|
||||
ret make_new_lit(cx, sp, lit);
|
||||
}
|
||||
fn make_new_int(cx: &ext_ctxt, sp: span, i: int) -> @ast::expr {
|
||||
fn make_new_int(cx: ext_ctxt, sp: span, i: int) -> @ast::expr {
|
||||
let lit = ast::lit_int(i);
|
||||
ret make_new_lit(cx, sp, lit);
|
||||
}
|
||||
fn make_new_uint(cx: &ext_ctxt, sp: span, u: uint) -> @ast::expr {
|
||||
fn make_new_uint(cx: ext_ctxt, sp: span, u: uint) -> @ast::expr {
|
||||
let lit = ast::lit_uint(u);
|
||||
ret make_new_lit(cx, sp, lit);
|
||||
}
|
||||
fn make_add_expr(cx: &ext_ctxt, sp: span, lhs: @ast::expr,
|
||||
rhs: @ast::expr) -> @ast::expr {
|
||||
fn make_add_expr(cx: ext_ctxt, sp: span, lhs: @ast::expr, rhs: @ast::expr)
|
||||
-> @ast::expr {
|
||||
let binexpr = ast::expr_binary(ast::add, lhs, rhs);
|
||||
ret @{id: cx.next_id(), node: binexpr, span: sp};
|
||||
}
|
||||
fn make_path_expr(cx: &ext_ctxt, sp: span, idents: &[ast::ident]) ->
|
||||
fn make_path_expr(cx: ext_ctxt, sp: span, idents: [ast::ident]) ->
|
||||
@ast::expr {
|
||||
let path = {global: false, idents: idents, types: []};
|
||||
let sp_path = {node: path, span: sp};
|
||||
let pathexpr = ast::expr_path(sp_path);
|
||||
ret @{id: cx.next_id(), node: pathexpr, span: sp};
|
||||
}
|
||||
fn make_vec_expr(cx: &ext_ctxt, sp: span, exprs: &[@ast::expr]) ->
|
||||
fn make_vec_expr(cx: ext_ctxt, sp: span, exprs: [@ast::expr]) ->
|
||||
@ast::expr {
|
||||
let vecexpr = ast::expr_vec(exprs, ast::imm);
|
||||
ret @{id: cx.next_id(), node: vecexpr, span: sp};
|
||||
}
|
||||
fn make_call(cx: &ext_ctxt, sp: span, fn_path: &[ast::ident],
|
||||
args: &[@ast::expr]) -> @ast::expr {
|
||||
fn make_call(cx: ext_ctxt, sp: span, fn_path: [ast::ident],
|
||||
args: [@ast::expr]) -> @ast::expr {
|
||||
let pathexpr = make_path_expr(cx, sp, fn_path);
|
||||
let callexpr = ast::expr_call(pathexpr, args);
|
||||
ret @{id: cx.next_id(), node: callexpr, span: sp};
|
||||
}
|
||||
fn make_rec_expr(cx: &ext_ctxt, sp: span,
|
||||
fields: &[{ident: ast::ident, ex: @ast::expr}]) ->
|
||||
fn make_rec_expr(cx: ext_ctxt, sp: span,
|
||||
fields: [{ident: ast::ident, ex: @ast::expr}]) ->
|
||||
@ast::expr {
|
||||
let astfields: [ast::field] = [];
|
||||
for field: {ident: ast::ident, ex: @ast::expr} in fields {
|
||||
|
|
@ -99,23 +99,23 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
|
|||
let recexpr = ast::expr_rec(astfields, option::none::<@ast::expr>);
|
||||
ret @{id: cx.next_id(), node: recexpr, span: sp};
|
||||
}
|
||||
fn make_path_vec(cx: &ext_ctxt, ident: &ast::ident) -> [ast::ident] {
|
||||
fn compiling_std(cx: &ext_ctxt) -> bool {
|
||||
fn make_path_vec(cx: ext_ctxt, ident: ast::ident) -> [ast::ident] {
|
||||
fn compiling_std(cx: ext_ctxt) -> bool {
|
||||
ret str::find(cx.crate_file_name(), "std.rc") >= 0;
|
||||
}
|
||||
if compiling_std(cx) {
|
||||
ret ["extfmt", "rt", ident];
|
||||
} else { ret ["std", "extfmt", "rt", ident]; }
|
||||
}
|
||||
fn make_rt_path_expr(cx: &ext_ctxt, sp: span, ident: &str) -> @ast::expr {
|
||||
fn make_rt_path_expr(cx: ext_ctxt, sp: span, ident: str) -> @ast::expr {
|
||||
let path = make_path_vec(cx, ident);
|
||||
ret make_path_expr(cx, sp, path);
|
||||
}
|
||||
// Produces an AST expression that represents a RT::conv record,
|
||||
// which tells the RT::conv* functions how to perform the conversion
|
||||
|
||||
fn make_rt_conv_expr(cx: &ext_ctxt, sp: span, cnv: &conv) -> @ast::expr {
|
||||
fn make_flags(cx: &ext_ctxt, sp: span, flags: &[flag]) -> @ast::expr {
|
||||
fn make_rt_conv_expr(cx: ext_ctxt, sp: span, cnv: conv) -> @ast::expr {
|
||||
fn make_flags(cx: ext_ctxt, sp: span, flags: [flag]) -> @ast::expr {
|
||||
let flagexprs: [@ast::expr] = [];
|
||||
for f: flag in flags {
|
||||
let fstr;
|
||||
|
|
@ -137,7 +137,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
|
|||
}
|
||||
ret make_vec_expr(cx, sp, flagexprs);
|
||||
}
|
||||
fn make_count(cx: &ext_ctxt, sp: span, cnt: &count) -> @ast::expr {
|
||||
fn make_count(cx: ext_ctxt, sp: span, cnt: count) -> @ast::expr {
|
||||
alt cnt {
|
||||
count_implied. {
|
||||
ret make_rt_path_expr(cx, sp, "count_implied");
|
||||
|
|
@ -151,7 +151,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
|
|||
_ { cx.span_unimpl(sp, "unimplemented #fmt conversion"); }
|
||||
}
|
||||
}
|
||||
fn make_ty(cx: &ext_ctxt, sp: span, t: &ty) -> @ast::expr {
|
||||
fn make_ty(cx: ext_ctxt, sp: span, t: ty) -> @ast::expr {
|
||||
let rt_type;
|
||||
alt t {
|
||||
ty_hex(c) {
|
||||
|
|
@ -166,7 +166,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
|
|||
}
|
||||
ret make_rt_path_expr(cx, sp, rt_type);
|
||||
}
|
||||
fn make_conv_rec(cx: &ext_ctxt, sp: span, flags_expr: @ast::expr,
|
||||
fn make_conv_rec(cx: ext_ctxt, sp: span, flags_expr: @ast::expr,
|
||||
width_expr: @ast::expr, precision_expr: @ast::expr,
|
||||
ty_expr: @ast::expr) -> @ast::expr {
|
||||
ret make_rec_expr(cx, sp,
|
||||
|
|
@ -182,7 +182,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
|
|||
ret make_conv_rec(cx, sp, rt_conv_flags, rt_conv_width,
|
||||
rt_conv_precision, rt_conv_ty);
|
||||
}
|
||||
fn make_conv_call(cx: &ext_ctxt, sp: span, conv_type: &str, cnv: &conv,
|
||||
fn make_conv_call(cx: ext_ctxt, sp: span, conv_type: str, cnv: conv,
|
||||
arg: @ast::expr) -> @ast::expr {
|
||||
let fname = "conv_" + conv_type;
|
||||
let path = make_path_vec(cx, fname);
|
||||
|
|
@ -190,7 +190,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
|
|||
let args = [cnv_expr, arg];
|
||||
ret make_call(cx, arg.span, path, args);
|
||||
}
|
||||
fn make_new_conv(cx: &ext_ctxt, sp: span, cnv: conv, arg: @ast::expr) ->
|
||||
fn make_new_conv(cx: ext_ctxt, sp: span, cnv: conv, arg: @ast::expr) ->
|
||||
@ast::expr {
|
||||
// FIXME: Extract all this validation into extfmt::ct
|
||||
|
||||
|
|
@ -334,10 +334,9 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
|
|||
let expected_nargs = n + 1u; // n conversions + the fmt string
|
||||
|
||||
if expected_nargs < nargs {
|
||||
cx.span_fatal(
|
||||
sp,
|
||||
#fmt["too many arguments to #fmt. found %u, expected %u",
|
||||
nargs, expected_nargs]);
|
||||
cx.span_fatal(sp,
|
||||
#fmt["too many arguments to #fmt. found %u, expected %u",
|
||||
nargs, expected_nargs]);
|
||||
}
|
||||
ret tmp_expr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import std::option;
|
|||
import base::*;
|
||||
import syntax::ast;
|
||||
|
||||
fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr,
|
||||
_body: &option::t<str>) -> @ast::expr {
|
||||
fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr,
|
||||
_body: option::t<str>) -> @ast::expr {
|
||||
let args: [@ast::expr] =
|
||||
alt arg.node {
|
||||
ast::expr_vec(elts, _) { elts }
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ import base::*;
|
|||
import syntax::ast;
|
||||
import std::str;
|
||||
|
||||
fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr,
|
||||
_body: &option::t<str>) -> @ast::expr {
|
||||
fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr,
|
||||
_body: option::t<str>) -> @ast::expr {
|
||||
|
||||
cx.print_backtrace();
|
||||
std::io::stdout().write_line(print::pprust::expr_to_str(arg));
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import ast::mac_invoc;
|
|||
|
||||
export add_new_extension;
|
||||
|
||||
fn path_to_ident(pth: &path) -> option::t<ident> {
|
||||
fn path_to_ident(pth: path) -> option::t<ident> {
|
||||
if vec::len(pth.node.idents) == 1u && vec::len(pth.node.types) == 0u {
|
||||
ret some(pth.node.idents[0u]);
|
||||
}
|
||||
|
|
@ -57,7 +57,7 @@ tag matchable {
|
|||
}
|
||||
|
||||
/* for when given an incompatible bit of AST */
|
||||
fn match_error(cx: &ext_ctxt, m: &matchable, expected: &str) -> ! {
|
||||
fn match_error(cx: ext_ctxt, m: matchable, expected: str) -> ! {
|
||||
alt m {
|
||||
match_expr(x) {
|
||||
cx.span_fatal(x.span,
|
||||
|
|
@ -90,9 +90,9 @@ fn match_error(cx: &ext_ctxt, m: &matchable, expected: &str) -> ! {
|
|||
// we'll want to return something indicating amount of progress and location
|
||||
// of failure instead of `none`.
|
||||
type match_result = option::t<arb_depth<matchable>>;
|
||||
type selector = fn(&matchable) -> match_result;
|
||||
type selector = fn(matchable) -> match_result;
|
||||
|
||||
fn elts_to_ell(cx: &ext_ctxt, elts: &[@expr]) ->
|
||||
fn elts_to_ell(cx: ext_ctxt, elts: [@expr]) ->
|
||||
{pre: [@expr], rep: option::t<@expr>, post: [@expr]} {
|
||||
let idx: uint = 0u;
|
||||
let res = none;
|
||||
|
|
@ -122,7 +122,7 @@ fn elts_to_ell(cx: &ext_ctxt, elts: &[@expr]) ->
|
|||
}
|
||||
}
|
||||
|
||||
fn option_flatten_map<T, U>(f: &fn(&T) -> option::t<U>, v: &[T]) ->
|
||||
fn option_flatten_map<T, U>(f: fn(T) -> option::t<U>, v: [T]) ->
|
||||
option::t<[U]> {
|
||||
let res = [];
|
||||
for elem: T in v {
|
||||
|
|
@ -131,7 +131,7 @@ fn option_flatten_map<T, U>(f: &fn(&T) -> option::t<U>, v: &[T]) ->
|
|||
ret some(res);
|
||||
}
|
||||
|
||||
fn a_d_map(ad: &arb_depth<matchable>, f: &selector) -> match_result {
|
||||
fn a_d_map(ad: arb_depth<matchable>, f: selector) -> match_result {
|
||||
alt ad {
|
||||
leaf(x) { ret f(x); }
|
||||
seq(ads, span) {
|
||||
|
|
@ -144,7 +144,7 @@ fn a_d_map(ad: &arb_depth<matchable>, f: &selector) -> match_result {
|
|||
}
|
||||
|
||||
fn compose_sels(s1: selector, s2: selector) -> selector {
|
||||
fn scomp(s1: selector, s2: selector, m: &matchable) -> match_result {
|
||||
fn scomp(s1: selector, s2: selector, m: matchable) -> match_result {
|
||||
ret alt s1(m) {
|
||||
none. { none }
|
||||
some(matches) { a_d_map(matches, s2) }
|
||||
|
|
@ -160,19 +160,19 @@ type binders =
|
|||
mutable literal_ast_matchers: [selector]};
|
||||
type bindings = hashmap<ident, arb_depth<matchable>>;
|
||||
|
||||
fn acumm_bindings(_cx: &ext_ctxt, _b_dest: &bindings, _b_src: &bindings) { }
|
||||
fn acumm_bindings(_cx: ext_ctxt, _b_dest: bindings, _b_src: bindings) { }
|
||||
|
||||
/* these three functions are the big moving parts */
|
||||
|
||||
/* create the selectors needed to bind and verify the pattern */
|
||||
|
||||
fn pattern_to_selectors(cx: &ext_ctxt, e: @expr) -> binders {
|
||||
fn pattern_to_selectors(cx: ext_ctxt, e: @expr) -> binders {
|
||||
let res: binders =
|
||||
{real_binders: new_str_hash::<selector>(),
|
||||
mutable literal_ast_matchers: []};
|
||||
//this oughta return binders instead, but macro args are a sequence of
|
||||
//expressions, rather than a single expression
|
||||
fn trivial_selector(m: &matchable) -> match_result { ret some(leaf(m)); }
|
||||
fn trivial_selector(m: matchable) -> match_result { ret some(leaf(m)); }
|
||||
p_t_s_rec(cx, match_expr(e), trivial_selector, res);
|
||||
ret res;
|
||||
}
|
||||
|
|
@ -183,7 +183,7 @@ fn pattern_to_selectors(cx: &ext_ctxt, e: @expr) -> binders {
|
|||
bindings. Most of the work is done in p_t_s, which generates the
|
||||
selectors. */
|
||||
|
||||
fn use_selectors_to_bind(b: &binders, e: @expr) -> option::t<bindings> {
|
||||
fn use_selectors_to_bind(b: binders, e: @expr) -> option::t<bindings> {
|
||||
let res = new_str_hash::<arb_depth<matchable>>();
|
||||
//need to do this first, to check vec lengths.
|
||||
for sel: selector in b.literal_ast_matchers {
|
||||
|
|
@ -203,10 +203,10 @@ fn use_selectors_to_bind(b: &binders, e: @expr) -> option::t<bindings> {
|
|||
|
||||
/* use the bindings on the body to generate the expanded code */
|
||||
|
||||
fn transcribe(cx: &ext_ctxt, b: &bindings, body: @expr) -> @expr {
|
||||
fn transcribe(cx: ext_ctxt, b: bindings, body: @expr) -> @expr {
|
||||
let idx_path: @mutable [uint] = @mutable [];
|
||||
fn new_id(_old: node_id, cx: &ext_ctxt) -> node_id { ret cx.next_id(); }
|
||||
fn new_span(cx: &ext_ctxt, sp: &span) -> span {
|
||||
fn new_id(_old: node_id, cx: ext_ctxt) -> node_id { ret cx.next_id(); }
|
||||
fn new_span(cx: ext_ctxt, sp: span) -> span {
|
||||
/* this discards information in the case of macro-defining macros */
|
||||
ret {lo: sp.lo, hi: sp.hi, expanded_from: cx.backtrace()};
|
||||
}
|
||||
|
|
@ -231,7 +231,7 @@ fn transcribe(cx: &ext_ctxt, b: &bindings, body: @expr) -> @expr {
|
|||
|
||||
|
||||
/* helper: descend into a matcher */
|
||||
fn follow(m: &arb_depth<matchable>, idx_path: @mutable [uint]) ->
|
||||
fn follow(m: arb_depth<matchable>, idx_path: @mutable [uint]) ->
|
||||
arb_depth<matchable> {
|
||||
let res: arb_depth<matchable> = m;
|
||||
for idx: uint in *idx_path {
|
||||
|
|
@ -243,7 +243,7 @@ fn follow(m: &arb_depth<matchable>, idx_path: @mutable [uint]) ->
|
|||
ret res;
|
||||
}
|
||||
|
||||
fn follow_for_trans(cx: &ext_ctxt, mmaybe: &option::t<arb_depth<matchable>>,
|
||||
fn follow_for_trans(cx: ext_ctxt, mmaybe: option::t<arb_depth<matchable>>,
|
||||
idx_path: @mutable [uint]) -> option::t<matchable> {
|
||||
alt mmaybe {
|
||||
none. { ret none }
|
||||
|
|
@ -262,10 +262,10 @@ fn follow_for_trans(cx: &ext_ctxt, mmaybe: &option::t<arb_depth<matchable>>,
|
|||
}
|
||||
|
||||
/* helper for transcribe_exprs: what vars from `b` occur in `e`? */
|
||||
iter free_vars(b: &bindings, e: @expr) -> ident {
|
||||
iter free_vars(b: bindings, e: @expr) -> ident {
|
||||
let idents: hashmap<ident, ()> = new_str_hash::<()>();
|
||||
fn mark_ident(i: &ident, _fld: ast_fold, b: &bindings,
|
||||
idents: &hashmap<ident, ()>) -> ident {
|
||||
fn mark_ident(i: ident, _fld: ast_fold, b: bindings,
|
||||
idents: hashmap<ident, ()>) -> ident {
|
||||
if b.contains_key(i) { idents.insert(i, ()); }
|
||||
ret i;
|
||||
}
|
||||
|
|
@ -282,8 +282,8 @@ iter free_vars(b: &bindings, e: @expr) -> ident {
|
|||
|
||||
|
||||
/* handle sequences (anywhere in the AST) of exprs, either real or ...ed */
|
||||
fn transcribe_exprs(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
|
||||
recur: fn(&@expr) -> @expr, exprs: [@expr]) -> [@expr] {
|
||||
fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint],
|
||||
recur: fn(@expr) -> @expr, exprs: [@expr]) -> [@expr] {
|
||||
alt elts_to_ell(cx, exprs) {
|
||||
{pre: pre, rep: repeat_me_maybe, post: post} {
|
||||
let res = vec::map(recur, pre);
|
||||
|
|
@ -344,8 +344,8 @@ fn transcribe_exprs(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
|
|||
|
||||
|
||||
// substitute, in a position that's required to be an ident
|
||||
fn transcribe_ident(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
|
||||
i: &ident, _fld: ast_fold) -> ident {
|
||||
fn transcribe_ident(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint],
|
||||
i: ident, _fld: ast_fold) -> ident {
|
||||
ret alt follow_for_trans(cx, b.find(i), idx_path) {
|
||||
some(match_ident(a_id)) { a_id.node }
|
||||
some(m) { match_error(cx, m, "an identifier") }
|
||||
|
|
@ -354,8 +354,8 @@ fn transcribe_ident(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
|
|||
}
|
||||
|
||||
|
||||
fn transcribe_path(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
|
||||
p: &path_, _fld: ast_fold) -> path_ {
|
||||
fn transcribe_path(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint],
|
||||
p: path_, _fld: ast_fold) -> path_ {
|
||||
// Don't substitute into qualified names.
|
||||
if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { ret p; }
|
||||
ret alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) {
|
||||
|
|
@ -369,9 +369,9 @@ fn transcribe_path(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
|
|||
}
|
||||
|
||||
|
||||
fn transcribe_expr(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
|
||||
e: &ast::expr_, fld: ast_fold,
|
||||
orig: fn(&ast::expr_, ast_fold) -> ast::expr_) ->
|
||||
fn transcribe_expr(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint],
|
||||
e: ast::expr_, fld: ast_fold,
|
||||
orig: fn(ast::expr_, ast_fold) -> ast::expr_) ->
|
||||
ast::expr_ {
|
||||
ret alt e {
|
||||
expr_path(p) {
|
||||
|
|
@ -396,9 +396,9 @@ fn transcribe_expr(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
|
|||
}
|
||||
}
|
||||
|
||||
fn transcribe_type(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
|
||||
t: &ast::ty_, fld: ast_fold,
|
||||
orig: fn(&ast::ty_, ast_fold) -> ast::ty_) -> ast::ty_ {
|
||||
fn transcribe_type(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint],
|
||||
t: ast::ty_, fld: ast_fold,
|
||||
orig: fn(ast::ty_, ast_fold) -> ast::ty_) -> ast::ty_ {
|
||||
ret alt t {
|
||||
ast::ty_path(pth, _) {
|
||||
alt path_to_ident(pth) {
|
||||
|
|
@ -420,9 +420,9 @@ fn transcribe_type(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
|
|||
/* for parsing reasons, syntax variables bound to blocks must be used like
|
||||
`{v}` */
|
||||
|
||||
fn transcribe_block(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
|
||||
blk: &blk_, fld: ast_fold,
|
||||
orig: fn(&blk_, ast_fold) -> blk_) -> blk_ {
|
||||
fn transcribe_block(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint],
|
||||
blk: blk_, fld: ast_fold,
|
||||
orig: fn(blk_, ast_fold) -> blk_) -> blk_ {
|
||||
ret alt block_to_ident(blk) {
|
||||
some(id) {
|
||||
alt follow_for_trans(cx, b.find(id), idx_path) {
|
||||
|
|
@ -430,6 +430,7 @@ fn transcribe_block(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
|
|||
|
||||
|
||||
|
||||
|
||||
// possibly allow promotion of ident/path/expr to blocks?
|
||||
some(m) {
|
||||
match_error(cx, m, "a block")
|
||||
|
|
@ -444,7 +445,7 @@ fn transcribe_block(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
|
|||
|
||||
/* traverse the pattern, building instructions on how to bind the actual
|
||||
argument. ps accumulates instructions on navigating the tree.*/
|
||||
fn p_t_s_rec(cx: &ext_ctxt, m: &matchable, s: &selector, b: &binders) {
|
||||
fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) {
|
||||
|
||||
//it might be possible to traverse only exprs, not matchables
|
||||
alt m {
|
||||
|
|
@ -478,12 +479,13 @@ fn p_t_s_rec(cx: &ext_ctxt, m: &matchable, s: &selector, b: &binders) {
|
|||
|
||||
|
||||
|
||||
|
||||
/* TODO: handle embedded types and blocks, at least */
|
||||
expr_mac(mac) {
|
||||
p_t_s_r_mac(cx, mac, s, b);
|
||||
}
|
||||
_ {
|
||||
fn select(cx: &ext_ctxt, m: &matchable, pat: @expr) ->
|
||||
fn select(cx: ext_ctxt, m: matchable, pat: @expr) ->
|
||||
match_result {
|
||||
ret alt m {
|
||||
match_expr(e) {
|
||||
|
|
@ -501,7 +503,7 @@ fn p_t_s_rec(cx: &ext_ctxt, m: &matchable, s: &selector, b: &binders) {
|
|||
|
||||
|
||||
/* make a match more precise */
|
||||
fn specialize_match(m: &matchable) -> matchable {
|
||||
fn specialize_match(m: matchable) -> matchable {
|
||||
ret alt m {
|
||||
match_expr(e) {
|
||||
alt e.node {
|
||||
|
|
@ -519,10 +521,10 @@ fn specialize_match(m: &matchable) -> matchable {
|
|||
}
|
||||
|
||||
/* pattern_to_selectors helper functions */
|
||||
fn p_t_s_r_path(cx: &ext_ctxt, p: &path, s: &selector, b: &binders) {
|
||||
fn p_t_s_r_path(cx: ext_ctxt, p: path, s: selector, b: binders) {
|
||||
alt path_to_ident(p) {
|
||||
some(p_id) {
|
||||
fn select(cx: &ext_ctxt, m: &matchable) -> match_result {
|
||||
fn select(cx: ext_ctxt, m: matchable) -> match_result {
|
||||
ret alt m {
|
||||
match_expr(e) { some(leaf(specialize_match(m))) }
|
||||
_ { cx.bug("broken traversal in p_t_s_r") }
|
||||
|
|
@ -537,7 +539,7 @@ fn p_t_s_r_path(cx: &ext_ctxt, p: &path, s: &selector, b: &binders) {
|
|||
}
|
||||
}
|
||||
|
||||
fn block_to_ident(blk: &blk_) -> option::t<ident> {
|
||||
fn block_to_ident(blk: blk_) -> option::t<ident> {
|
||||
if vec::len(blk.stmts) != 0u { ret none; }
|
||||
ret alt blk.expr {
|
||||
some(expr) {
|
||||
|
|
@ -547,9 +549,9 @@ fn block_to_ident(blk: &blk_) -> option::t<ident> {
|
|||
}
|
||||
}
|
||||
|
||||
fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) {
|
||||
fn select_pt_1(cx: &ext_ctxt, m: &matchable,
|
||||
fn_m: fn(&ast::mac) -> match_result) -> match_result {
|
||||
fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, s: selector, b: binders) {
|
||||
fn select_pt_1(cx: ext_ctxt, m: matchable,
|
||||
fn_m: fn(ast::mac) -> match_result) -> match_result {
|
||||
ret alt m {
|
||||
match_expr(e) {
|
||||
alt e.node { expr_mac(mac) { fn_m(mac) } _ { none } }
|
||||
|
|
@ -557,7 +559,7 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) {
|
|||
_ { cx.bug("broken traversal in p_t_s_r") }
|
||||
}
|
||||
}
|
||||
fn no_des(cx: &ext_ctxt, sp: &span, syn: &str) -> ! {
|
||||
fn no_des(cx: ext_ctxt, sp: span, syn: str) -> ! {
|
||||
cx.span_fatal(sp, "destructuring " + syn + " is not yet supported");
|
||||
}
|
||||
alt mac.node {
|
||||
|
|
@ -569,7 +571,7 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) {
|
|||
alt path_to_ident(pth) {
|
||||
some(id) {
|
||||
/* look for an embedded type */
|
||||
fn select_pt_2(m: &ast::mac) -> match_result {
|
||||
fn select_pt_2(m: ast::mac) -> match_result {
|
||||
ret alt m.node {
|
||||
ast::mac_embed_type(t) { some(leaf(match_ty(t))) }
|
||||
_ { none }
|
||||
|
|
@ -587,7 +589,7 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) {
|
|||
ast::mac_embed_block(blk) {
|
||||
alt block_to_ident(blk.node) {
|
||||
some(id) {
|
||||
fn select_pt_2(m: &ast::mac) -> match_result {
|
||||
fn select_pt_2(m: ast::mac) -> match_result {
|
||||
ret alt m.node {
|
||||
ast::mac_embed_block(blk) {
|
||||
some(leaf(match_block(blk)))
|
||||
|
|
@ -604,9 +606,9 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) {
|
|||
}
|
||||
}
|
||||
|
||||
fn p_t_s_r_ellipses(cx: &ext_ctxt, repeat_me: @expr, offset: uint,
|
||||
s: &selector, b: &binders) {
|
||||
fn select(cx: &ext_ctxt, repeat_me: @expr, offset: uint, m: &matchable) ->
|
||||
fn p_t_s_r_ellipses(cx: ext_ctxt, repeat_me: @expr, offset: uint, s: selector,
|
||||
b: binders) {
|
||||
fn select(cx: ext_ctxt, repeat_me: @expr, offset: uint, m: matchable) ->
|
||||
match_result {
|
||||
ret alt m {
|
||||
match_expr(e) {
|
||||
|
|
@ -634,9 +636,9 @@ fn p_t_s_r_ellipses(cx: &ext_ctxt, repeat_me: @expr, offset: uint,
|
|||
}
|
||||
|
||||
|
||||
fn p_t_s_r_length(cx: &ext_ctxt, len: uint, at_least: bool, s: selector,
|
||||
b: &binders) {
|
||||
fn len_select(_cx: &ext_ctxt, m: &matchable, at_least: bool, len: uint) ->
|
||||
fn p_t_s_r_length(cx: ext_ctxt, len: uint, at_least: bool, s: selector,
|
||||
b: binders) {
|
||||
fn len_select(_cx: ext_ctxt, m: matchable, at_least: bool, len: uint) ->
|
||||
match_result {
|
||||
ret alt m {
|
||||
match_expr(e) {
|
||||
|
|
@ -657,11 +659,11 @@ fn p_t_s_r_length(cx: &ext_ctxt, len: uint, at_least: bool, s: selector,
|
|||
[compose_sels(s, bind len_select(cx, _, at_least, len))];
|
||||
}
|
||||
|
||||
fn p_t_s_r_actual_vector(cx: &ext_ctxt, elts: [@expr], _repeat_after: bool,
|
||||
s: &selector, b: &binders) {
|
||||
fn p_t_s_r_actual_vector(cx: ext_ctxt, elts: [@expr], _repeat_after: bool,
|
||||
s: selector, b: binders) {
|
||||
let idx: uint = 0u;
|
||||
while idx < vec::len(elts) {
|
||||
fn select(cx: &ext_ctxt, m: &matchable, idx: uint) -> match_result {
|
||||
fn select(cx: ext_ctxt, m: matchable, idx: uint) -> match_result {
|
||||
ret alt m {
|
||||
match_expr(e) {
|
||||
alt e.node {
|
||||
|
|
@ -680,8 +682,8 @@ fn p_t_s_r_actual_vector(cx: &ext_ctxt, elts: [@expr], _repeat_after: bool,
|
|||
}
|
||||
}
|
||||
|
||||
fn add_new_extension(cx: &ext_ctxt, sp: span, arg: @expr,
|
||||
_body: &option::t<str>) -> base::macro_def {
|
||||
fn add_new_extension(cx: ext_ctxt, sp: span, arg: @expr,
|
||||
_body: option::t<str>) -> base::macro_def {
|
||||
let args: [@ast::expr] =
|
||||
alt arg.node {
|
||||
ast::expr_vec(elts, _) { elts }
|
||||
|
|
@ -760,9 +762,8 @@ fn add_new_extension(cx: &ext_ctxt, sp: span, arg: @expr,
|
|||
},
|
||||
ext: normal(ext)};
|
||||
|
||||
fn generic_extension(cx: &ext_ctxt, sp: span, arg: @expr,
|
||||
_body: &option::t<str>, clauses: [@clause]) ->
|
||||
@expr {
|
||||
fn generic_extension(cx: ext_ctxt, sp: span, arg: @expr,
|
||||
_body: option::t<str>, clauses: [@clause]) -> @expr {
|
||||
for c: @clause in clauses {
|
||||
alt use_selectors_to_bind(c.params, arg) {
|
||||
some(bindings) { ret transcribe(cx, bindings, c.body) }
|
||||
|
|
|
|||
|
|
@ -21,92 +21,91 @@ type ast_fold = @mutable a_f;
|
|||
|
||||
type ast_fold_precursor =
|
||||
//unlike the others, item_ is non-trivial
|
||||
{fold_crate: fn(&crate_, ast_fold) -> crate_,
|
||||
fold_crate_directive:
|
||||
fn(&crate_directive_, ast_fold) -> crate_directive_,
|
||||
fold_view_item: fn(&view_item_, ast_fold) -> view_item_,
|
||||
fold_native_item: fn(&@native_item, ast_fold) -> @native_item,
|
||||
fold_item: fn(&@item, ast_fold) -> @item,
|
||||
fold_item_underscore: fn(&item_, ast_fold) -> item_,
|
||||
fold_method: fn(&method_, ast_fold) -> method_,
|
||||
fold_block: fn(&blk_, ast_fold) -> blk_,
|
||||
fold_stmt: fn(&stmt_, ast_fold) -> stmt_,
|
||||
fold_arm: fn(&arm, ast_fold) -> arm,
|
||||
fold_pat: fn(&pat_, ast_fold) -> pat_,
|
||||
fold_decl: fn(&decl_, ast_fold) -> decl_,
|
||||
fold_expr: fn(&expr_, ast_fold) -> expr_,
|
||||
fold_ty: fn(&ty_, ast_fold) -> ty_,
|
||||
fold_constr: fn(&ast::constr_, ast_fold) -> constr_,
|
||||
fold_fn: fn(&_fn, ast_fold) -> _fn,
|
||||
fold_mod: fn(&_mod, ast_fold) -> _mod,
|
||||
fold_native_mod: fn(&native_mod, ast_fold) -> native_mod,
|
||||
fold_variant: fn(&variant_, ast_fold) -> variant_,
|
||||
fold_ident: fn(&ident, ast_fold) -> ident,
|
||||
fold_path: fn(&path_, ast_fold) -> path_,
|
||||
fold_local: fn(&local_, ast_fold) -> local_,
|
||||
map_exprs: fn(fn(&@expr) -> @expr, [@expr]) -> [@expr],
|
||||
{fold_crate: fn(crate_, ast_fold) -> crate_,
|
||||
fold_crate_directive: fn(crate_directive_, ast_fold) -> crate_directive_,
|
||||
fold_view_item: fn(view_item_, ast_fold) -> view_item_,
|
||||
fold_native_item: fn(@native_item, ast_fold) -> @native_item,
|
||||
fold_item: fn(@item, ast_fold) -> @item,
|
||||
fold_item_underscore: fn(item_, ast_fold) -> item_,
|
||||
fold_method: fn(method_, ast_fold) -> method_,
|
||||
fold_block: fn(blk_, ast_fold) -> blk_,
|
||||
fold_stmt: fn(stmt_, ast_fold) -> stmt_,
|
||||
fold_arm: fn(arm, ast_fold) -> arm,
|
||||
fold_pat: fn(pat_, ast_fold) -> pat_,
|
||||
fold_decl: fn(decl_, ast_fold) -> decl_,
|
||||
fold_expr: fn(expr_, ast_fold) -> expr_,
|
||||
fold_ty: fn(ty_, ast_fold) -> ty_,
|
||||
fold_constr: fn(ast::constr_, ast_fold) -> constr_,
|
||||
fold_fn: fn(_fn, ast_fold) -> _fn,
|
||||
fold_mod: fn(_mod, ast_fold) -> _mod,
|
||||
fold_native_mod: fn(native_mod, ast_fold) -> native_mod,
|
||||
fold_variant: fn(variant_, ast_fold) -> variant_,
|
||||
fold_ident: fn(ident, ast_fold) -> ident,
|
||||
fold_path: fn(path_, ast_fold) -> path_,
|
||||
fold_local: fn(local_, ast_fold) -> local_,
|
||||
map_exprs: fn(fn(@expr) -> @expr, [@expr]) -> [@expr],
|
||||
new_id: fn(node_id) -> node_id,
|
||||
new_span: fn(&span) -> span};
|
||||
new_span: fn(span) -> span};
|
||||
|
||||
type a_f =
|
||||
{fold_crate: fn(&crate) -> crate,
|
||||
fold_crate_directive: fn(&@crate_directive) -> @crate_directive,
|
||||
fold_view_item: fn(&@view_item) -> @view_item,
|
||||
fold_native_item: fn(&@native_item) -> @native_item,
|
||||
fold_item: fn(&@item) -> @item,
|
||||
fold_item_underscore: fn(&item_) -> item_,
|
||||
fold_method: fn(&@method) -> @method,
|
||||
fold_block: fn(&blk) -> blk,
|
||||
fold_stmt: fn(&@stmt) -> @stmt,
|
||||
fold_arm: fn(&arm) -> arm,
|
||||
fold_pat: fn(&@pat) -> @pat,
|
||||
fold_decl: fn(&@decl) -> @decl,
|
||||
fold_expr: fn(&@expr) -> @expr,
|
||||
fold_ty: fn(&@ty) -> @ty,
|
||||
fold_constr: fn(&@constr) -> @constr,
|
||||
fold_fn: fn(&_fn) -> _fn,
|
||||
fold_mod: fn(&_mod) -> _mod,
|
||||
fold_native_mod: fn(&native_mod) -> native_mod,
|
||||
fold_variant: fn(&variant) -> variant,
|
||||
fold_ident: fn(&ident) -> ident,
|
||||
fold_path: fn(&path) -> path,
|
||||
fold_local: fn(&@local) -> @local,
|
||||
map_exprs: fn(fn(&@expr) -> @expr, [@expr]) -> [@expr],
|
||||
{fold_crate: fn(crate) -> crate,
|
||||
fold_crate_directive: fn(@crate_directive) -> @crate_directive,
|
||||
fold_view_item: fn(@view_item) -> @view_item,
|
||||
fold_native_item: fn(@native_item) -> @native_item,
|
||||
fold_item: fn(@item) -> @item,
|
||||
fold_item_underscore: fn(item_) -> item_,
|
||||
fold_method: fn(@method) -> @method,
|
||||
fold_block: fn(blk) -> blk,
|
||||
fold_stmt: fn(@stmt) -> @stmt,
|
||||
fold_arm: fn(arm) -> arm,
|
||||
fold_pat: fn(@pat) -> @pat,
|
||||
fold_decl: fn(@decl) -> @decl,
|
||||
fold_expr: fn(@expr) -> @expr,
|
||||
fold_ty: fn(@ty) -> @ty,
|
||||
fold_constr: fn(@constr) -> @constr,
|
||||
fold_fn: fn(_fn) -> _fn,
|
||||
fold_mod: fn(_mod) -> _mod,
|
||||
fold_native_mod: fn(native_mod) -> native_mod,
|
||||
fold_variant: fn(variant) -> variant,
|
||||
fold_ident: fn(ident) -> ident,
|
||||
fold_path: fn(path) -> path,
|
||||
fold_local: fn(@local) -> @local,
|
||||
map_exprs: fn(fn(@expr) -> @expr, [@expr]) -> [@expr],
|
||||
new_id: fn(node_id) -> node_id,
|
||||
new_span: fn(&span) -> span};
|
||||
new_span: fn(span) -> span};
|
||||
|
||||
|
||||
//fn nf_dummy<T>(&T node) -> T { fail; }
|
||||
fn nf_crate_dummy(_c: &crate) -> crate { fail; }
|
||||
fn nf_crate_directive_dummy(_c: &@crate_directive) -> @crate_directive {
|
||||
fn nf_crate_dummy(_c: crate) -> crate { fail; }
|
||||
fn nf_crate_directive_dummy(_c: @crate_directive) -> @crate_directive {
|
||||
fail;
|
||||
}
|
||||
fn nf_view_item_dummy(_v: &@view_item) -> @view_item { fail; }
|
||||
fn nf_native_item_dummy(_n: &@native_item) -> @native_item { fail; }
|
||||
fn nf_item_dummy(_i: &@item) -> @item { fail; }
|
||||
fn nf_item_underscore_dummy(_i: &item_) -> item_ { fail; }
|
||||
fn nf_method_dummy(_m: &@method) -> @method { fail; }
|
||||
fn nf_blk_dummy(_b: &blk) -> blk { fail; }
|
||||
fn nf_stmt_dummy(_s: &@stmt) -> @stmt { fail; }
|
||||
fn nf_arm_dummy(_a: &arm) -> arm { fail; }
|
||||
fn nf_pat_dummy(_p: &@pat) -> @pat { fail; }
|
||||
fn nf_decl_dummy(_d: &@decl) -> @decl { fail; }
|
||||
fn nf_expr_dummy(_e: &@expr) -> @expr { fail; }
|
||||
fn nf_ty_dummy(_t: &@ty) -> @ty { fail; }
|
||||
fn nf_constr_dummy(_c: &@constr) -> @constr { fail; }
|
||||
fn nf_fn_dummy(_f: &_fn) -> _fn { fail; }
|
||||
fn nf_mod_dummy(_m: &_mod) -> _mod { fail; }
|
||||
fn nf_native_mod_dummy(_n: &native_mod) -> native_mod { fail; }
|
||||
fn nf_variant_dummy(_v: &variant) -> variant { fail; }
|
||||
fn nf_ident_dummy(_i: &ident) -> ident { fail; }
|
||||
fn nf_path_dummy(_p: &path) -> path { fail; }
|
||||
fn nf_obj_field_dummy(_o: &obj_field) -> obj_field { fail; }
|
||||
fn nf_local_dummy(_o: &@local) -> @local { fail; }
|
||||
fn nf_view_item_dummy(_v: @view_item) -> @view_item { fail; }
|
||||
fn nf_native_item_dummy(_n: @native_item) -> @native_item { fail; }
|
||||
fn nf_item_dummy(_i: @item) -> @item { fail; }
|
||||
fn nf_item_underscore_dummy(_i: item_) -> item_ { fail; }
|
||||
fn nf_method_dummy(_m: @method) -> @method { fail; }
|
||||
fn nf_blk_dummy(_b: blk) -> blk { fail; }
|
||||
fn nf_stmt_dummy(_s: @stmt) -> @stmt { fail; }
|
||||
fn nf_arm_dummy(_a: arm) -> arm { fail; }
|
||||
fn nf_pat_dummy(_p: @pat) -> @pat { fail; }
|
||||
fn nf_decl_dummy(_d: @decl) -> @decl { fail; }
|
||||
fn nf_expr_dummy(_e: @expr) -> @expr { fail; }
|
||||
fn nf_ty_dummy(_t: @ty) -> @ty { fail; }
|
||||
fn nf_constr_dummy(_c: @constr) -> @constr { fail; }
|
||||
fn nf_fn_dummy(_f: _fn) -> _fn { fail; }
|
||||
fn nf_mod_dummy(_m: _mod) -> _mod { fail; }
|
||||
fn nf_native_mod_dummy(_n: native_mod) -> native_mod { fail; }
|
||||
fn nf_variant_dummy(_v: variant) -> variant { fail; }
|
||||
fn nf_ident_dummy(_i: ident) -> ident { fail; }
|
||||
fn nf_path_dummy(_p: path) -> path { fail; }
|
||||
fn nf_obj_field_dummy(_o: obj_field) -> obj_field { fail; }
|
||||
fn nf_local_dummy(_o: @local) -> @local { fail; }
|
||||
|
||||
/* some little folds that probably aren't useful to have in ast_fold itself*/
|
||||
|
||||
//used in noop_fold_item and noop_fold_crate and noop_fold_crate_directive
|
||||
fn fold_meta_item_(mi: &@meta_item, fld: ast_fold) -> @meta_item {
|
||||
fn fold_meta_item_(mi: @meta_item, fld: ast_fold) -> @meta_item {
|
||||
ret @{node:
|
||||
alt mi.node {
|
||||
meta_word(id) { meta_word(fld.fold_ident(id)) }
|
||||
|
|
@ -121,20 +120,20 @@ fn fold_meta_item_(mi: &@meta_item, fld: ast_fold) -> @meta_item {
|
|||
span: mi.span};
|
||||
}
|
||||
//used in noop_fold_item and noop_fold_crate
|
||||
fn fold_attribute_(at: &attribute, fmi: fn(&@meta_item) -> @meta_item) ->
|
||||
fn fold_attribute_(at: attribute, fmi: fn(@meta_item) -> @meta_item) ->
|
||||
attribute {
|
||||
ret {node: {style: at.node.style, value: *fmi(@at.node.value)},
|
||||
span: at.span};
|
||||
}
|
||||
//used in noop_fold_native_item and noop_fold_fn
|
||||
fn fold_arg_(a: &arg, fld: ast_fold) -> arg {
|
||||
fn fold_arg_(a: arg, fld: ast_fold) -> arg {
|
||||
ret {mode: a.mode,
|
||||
ty: fld.fold_ty(a.ty),
|
||||
ident: fld.fold_ident(a.ident),
|
||||
id: a.id};
|
||||
}
|
||||
//used in noop_fold_expr, and possibly elsewhere in the future
|
||||
fn fold_mac_(m: &mac, fld: ast_fold) -> mac {
|
||||
fn fold_mac_(m: mac, fld: ast_fold) -> mac {
|
||||
ret {node:
|
||||
alt m.node {
|
||||
mac_invoc(pth, arg, body) {
|
||||
|
|
@ -151,7 +150,7 @@ fn fold_mac_(m: &mac, fld: ast_fold) -> mac {
|
|||
|
||||
|
||||
|
||||
fn noop_fold_crate(c: &crate_, fld: ast_fold) -> crate_ {
|
||||
fn noop_fold_crate(c: crate_, fld: ast_fold) -> crate_ {
|
||||
let fold_meta_item = bind fold_meta_item_(_, fld);
|
||||
let fold_attribute = bind fold_attribute_(_, fold_meta_item);
|
||||
|
||||
|
|
@ -161,7 +160,7 @@ fn noop_fold_crate(c: &crate_, fld: ast_fold) -> crate_ {
|
|||
config: vec::map(fold_meta_item, c.config)};
|
||||
}
|
||||
|
||||
fn noop_fold_crate_directive(cd: &crate_directive_, fld: ast_fold) ->
|
||||
fn noop_fold_crate_directive(cd: crate_directive_, fld: ast_fold) ->
|
||||
crate_directive_ {
|
||||
ret alt cd {
|
||||
cdir_src_mod(id, fname, attrs) {
|
||||
|
|
@ -177,12 +176,12 @@ fn noop_fold_crate_directive(cd: &crate_directive_, fld: ast_fold) ->
|
|||
}
|
||||
}
|
||||
|
||||
fn noop_fold_view_item(vi: &view_item_, _fld: ast_fold) -> view_item_ {
|
||||
fn noop_fold_view_item(vi: view_item_, _fld: ast_fold) -> view_item_ {
|
||||
ret vi;
|
||||
}
|
||||
|
||||
|
||||
fn noop_fold_native_item(ni: &@native_item, fld: ast_fold) -> @native_item {
|
||||
fn noop_fold_native_item(ni: @native_item, fld: ast_fold) -> @native_item {
|
||||
let fold_arg = bind fold_arg_(_, fld);
|
||||
let fold_meta_item = bind fold_meta_item_(_, fld);
|
||||
let fold_attribute = bind fold_attribute_(_, fold_meta_item);
|
||||
|
|
@ -208,7 +207,7 @@ fn noop_fold_native_item(ni: &@native_item, fld: ast_fold) -> @native_item {
|
|||
span: ni.span};
|
||||
}
|
||||
|
||||
fn noop_fold_item(i: &@item, fld: ast_fold) -> @item {
|
||||
fn noop_fold_item(i: @item, fld: ast_fold) -> @item {
|
||||
let fold_meta_item = bind fold_meta_item_(_, fld);
|
||||
let fold_attribute = bind fold_attribute_(_, fold_meta_item);
|
||||
|
||||
|
|
@ -219,8 +218,8 @@ fn noop_fold_item(i: &@item, fld: ast_fold) -> @item {
|
|||
span: i.span};
|
||||
}
|
||||
|
||||
fn noop_fold_item_underscore(i: &item_, fld: ast_fold) -> item_ {
|
||||
fn fold_obj_field_(of: &obj_field, fld: ast_fold) -> obj_field {
|
||||
fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
|
||||
fn fold_obj_field_(of: obj_field, fld: ast_fold) -> obj_field {
|
||||
ret {mut: of.mut,
|
||||
ty: fld.fold_ty(of.ty),
|
||||
ident: fld.fold_ident(of.ident),
|
||||
|
|
@ -248,19 +247,19 @@ fn noop_fold_item_underscore(i: &item_, fld: ast_fold) -> item_ {
|
|||
};
|
||||
}
|
||||
|
||||
fn noop_fold_method(m: &method_, fld: ast_fold) -> method_ {
|
||||
fn noop_fold_method(m: method_, fld: ast_fold) -> method_ {
|
||||
ret {ident: fld.fold_ident(m.ident), meth: fld.fold_fn(m.meth), id: m.id};
|
||||
}
|
||||
|
||||
|
||||
fn noop_fold_block(b: &blk_, fld: ast_fold) -> blk_ {
|
||||
fn noop_fold_block(b: blk_, fld: ast_fold) -> blk_ {
|
||||
ret {stmts: vec::map(fld.fold_stmt, b.stmts),
|
||||
expr: option::map(fld.fold_expr, b.expr),
|
||||
id: b.id,
|
||||
rules: b.rules};
|
||||
}
|
||||
|
||||
fn noop_fold_stmt(s: &stmt_, fld: ast_fold) -> stmt_ {
|
||||
fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ {
|
||||
ret alt s {
|
||||
stmt_decl(d, nid) { stmt_decl(fld.fold_decl(d), nid) }
|
||||
stmt_expr(e, nid) { stmt_expr(fld.fold_expr(e), nid) }
|
||||
|
|
@ -270,13 +269,13 @@ fn noop_fold_stmt(s: &stmt_, fld: ast_fold) -> stmt_ {
|
|||
};
|
||||
}
|
||||
|
||||
fn noop_fold_arm(a: &arm, fld: ast_fold) -> arm {
|
||||
fn noop_fold_arm(a: arm, fld: ast_fold) -> arm {
|
||||
ret {pats: vec::map(fld.fold_pat, a.pats),
|
||||
guard: option::map(fld.fold_expr, a.guard),
|
||||
body: fld.fold_block(a.body)};
|
||||
}
|
||||
|
||||
fn noop_fold_pat(p: &pat_, fld: ast_fold) -> pat_ {
|
||||
fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
|
||||
ret alt p {
|
||||
pat_wild. { p }
|
||||
pat_bind(ident) { pat_bind(fld.fold_ident(ident)) }
|
||||
|
|
@ -296,15 +295,15 @@ fn noop_fold_pat(p: &pat_, fld: ast_fold) -> pat_ {
|
|||
};
|
||||
}
|
||||
|
||||
fn noop_fold_decl(d: &decl_, fld: ast_fold) -> decl_ {
|
||||
fn noop_fold_decl(d: decl_, fld: ast_fold) -> decl_ {
|
||||
ret alt d {
|
||||
decl_local(ls) { decl_local(vec::map(fld.fold_local, ls)) }
|
||||
decl_item(it) { decl_item(fld.fold_item(it)) }
|
||||
}
|
||||
}
|
||||
|
||||
fn noop_fold_expr(e: &expr_, fld: ast_fold) -> expr_ {
|
||||
fn fold_field_(field: &field, fld: ast_fold) -> field {
|
||||
fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
|
||||
fn fold_field_(field: field, fld: ast_fold) -> field {
|
||||
ret {node:
|
||||
{mut: field.node.mut,
|
||||
ident: fld.fold_ident(field.node.ident),
|
||||
|
|
@ -312,8 +311,8 @@ fn noop_fold_expr(e: &expr_, fld: ast_fold) -> expr_ {
|
|||
span: field.span};
|
||||
}
|
||||
let fold_field = bind fold_field_(_, fld);
|
||||
fn fold_anon_obj_(ao: &anon_obj, fld: ast_fold) -> anon_obj {
|
||||
fn fold_anon_obj_field_(aof: &anon_obj_field, fld: ast_fold) ->
|
||||
fn fold_anon_obj_(ao: anon_obj, fld: ast_fold) -> anon_obj {
|
||||
fn fold_anon_obj_field_(aof: anon_obj_field, fld: ast_fold) ->
|
||||
anon_obj_field {
|
||||
ret {mut: aof.mut,
|
||||
ty: fld.fold_ty(aof.ty),
|
||||
|
|
@ -427,17 +426,17 @@ fn noop_fold_expr(e: &expr_, fld: ast_fold) -> expr_ {
|
|||
}
|
||||
}
|
||||
|
||||
fn noop_fold_ty(t: &ty_, _fld: ast_fold) -> ty_ {
|
||||
fn noop_fold_ty(t: ty_, _fld: ast_fold) -> ty_ {
|
||||
//drop in ty::fold_ty here if necessary
|
||||
ret t;
|
||||
}
|
||||
|
||||
fn noop_fold_constr(c: &constr_, fld: ast_fold) -> constr_ {
|
||||
fn noop_fold_constr(c: constr_, fld: ast_fold) -> constr_ {
|
||||
{path: fld.fold_path(c.path), args: c.args, id: c.id}
|
||||
}
|
||||
|
||||
// functions just don't get spans, for some reason
|
||||
fn noop_fold_fn(f: &_fn, fld: ast_fold) -> _fn {
|
||||
fn noop_fold_fn(f: _fn, fld: ast_fold) -> _fn {
|
||||
let fold_arg = bind fold_arg_(_, fld);
|
||||
|
||||
ret {decl:
|
||||
|
|
@ -452,35 +451,35 @@ fn noop_fold_fn(f: &_fn, fld: ast_fold) -> _fn {
|
|||
}
|
||||
|
||||
// ...nor do modules
|
||||
fn noop_fold_mod(m: &_mod, fld: ast_fold) -> _mod {
|
||||
fn noop_fold_mod(m: _mod, fld: ast_fold) -> _mod {
|
||||
ret {view_items: vec::map(fld.fold_view_item, m.view_items),
|
||||
items: vec::map(fld.fold_item, m.items)};
|
||||
}
|
||||
|
||||
fn noop_fold_native_mod(nm: &native_mod, fld: ast_fold) -> native_mod {
|
||||
fn noop_fold_native_mod(nm: native_mod, fld: ast_fold) -> native_mod {
|
||||
ret {native_name: nm.native_name,
|
||||
abi: nm.abi,
|
||||
view_items: vec::map(fld.fold_view_item, nm.view_items),
|
||||
items: vec::map(fld.fold_native_item, nm.items)}
|
||||
}
|
||||
|
||||
fn noop_fold_variant(v: &variant_, fld: ast_fold) -> variant_ {
|
||||
fn fold_variant_arg_(va: &variant_arg, fld: ast_fold) -> variant_arg {
|
||||
fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
|
||||
fn fold_variant_arg_(va: variant_arg, fld: ast_fold) -> variant_arg {
|
||||
ret {ty: fld.fold_ty(va.ty), id: va.id};
|
||||
}
|
||||
let fold_variant_arg = bind fold_variant_arg_(_, fld);
|
||||
ret {name: v.name, args: vec::map(fold_variant_arg, v.args), id: v.id};
|
||||
}
|
||||
|
||||
fn noop_fold_ident(i: &ident, _fld: ast_fold) -> ident { ret i; }
|
||||
fn noop_fold_ident(i: ident, _fld: ast_fold) -> ident { ret i; }
|
||||
|
||||
fn noop_fold_path(p: &path_, fld: ast_fold) -> path_ {
|
||||
fn noop_fold_path(p: path_, fld: ast_fold) -> path_ {
|
||||
ret {global: p.global,
|
||||
idents: vec::map(fld.fold_ident, p.idents),
|
||||
types: vec::map(fld.fold_ty, p.types)};
|
||||
}
|
||||
|
||||
fn noop_fold_local(l: &local_, fld: ast_fold) -> local_ {
|
||||
fn noop_fold_local(l: local_, fld: ast_fold) -> local_ {
|
||||
ret {ty: fld.fold_ty(l.ty),
|
||||
pat: fld.fold_pat(l.pat),
|
||||
init:
|
||||
|
|
@ -496,13 +495,13 @@ fn noop_fold_local(l: &local_, fld: ast_fold) -> local_ {
|
|||
|
||||
/* temporarily eta-expand because of a compiler bug with using `fn<T>` as a
|
||||
value */
|
||||
fn noop_map_exprs(f: fn(&@expr) -> @expr, es: [@expr]) -> [@expr] {
|
||||
fn noop_map_exprs(f: fn(@expr) -> @expr, es: [@expr]) -> [@expr] {
|
||||
ret vec::map(f, es);
|
||||
}
|
||||
|
||||
fn noop_id(i: node_id) -> node_id { ret i; }
|
||||
|
||||
fn noop_span(sp: &span) -> span { ret sp; }
|
||||
fn noop_span(sp: span) -> span { ret sp; }
|
||||
|
||||
|
||||
fn default_ast_fold() -> @ast_fold_precursor {
|
||||
|
|
@ -563,7 +562,7 @@ fn dummy_out(a: ast_fold) {
|
|||
}
|
||||
|
||||
|
||||
fn make_fold(afp: &ast_fold_precursor) -> ast_fold {
|
||||
fn make_fold(afp: ast_fold_precursor) -> ast_fold {
|
||||
let result: ast_fold =
|
||||
@mutable {fold_crate: nf_crate_dummy,
|
||||
fold_crate_directive: nf_crate_directive_dummy,
|
||||
|
|
@ -592,84 +591,83 @@ fn make_fold(afp: &ast_fold_precursor) -> ast_fold {
|
|||
new_span: noop_span};
|
||||
|
||||
/* naturally, a macro to write these would be nice */
|
||||
fn f_crate(afp: &ast_fold_precursor, f: ast_fold, c: &crate) -> crate {
|
||||
fn f_crate(afp: ast_fold_precursor, f: ast_fold, c: crate) -> crate {
|
||||
ret {node: afp.fold_crate(c.node, f), span: afp.new_span(c.span)};
|
||||
}
|
||||
fn f_crate_directive(afp: &ast_fold_precursor, f: ast_fold,
|
||||
c: &@crate_directive) -> @crate_directive {
|
||||
fn f_crate_directive(afp: ast_fold_precursor, f: ast_fold,
|
||||
c: @crate_directive) -> @crate_directive {
|
||||
ret @{node: afp.fold_crate_directive(c.node, f),
|
||||
span: afp.new_span(c.span)};
|
||||
}
|
||||
fn f_view_item(afp: &ast_fold_precursor, f: ast_fold, x: &@view_item) ->
|
||||
fn f_view_item(afp: ast_fold_precursor, f: ast_fold, x: @view_item) ->
|
||||
@view_item {
|
||||
ret @{node: afp.fold_view_item(x.node, f),
|
||||
span: afp.new_span(x.span)};
|
||||
}
|
||||
fn f_native_item(afp: &ast_fold_precursor, f: ast_fold, x: &@native_item)
|
||||
-> @native_item {
|
||||
fn f_native_item(afp: ast_fold_precursor, f: ast_fold, x: @native_item) ->
|
||||
@native_item {
|
||||
ret afp.fold_native_item(x, f);
|
||||
}
|
||||
fn f_item(afp: &ast_fold_precursor, f: ast_fold, i: &@item) -> @item {
|
||||
fn f_item(afp: ast_fold_precursor, f: ast_fold, i: @item) -> @item {
|
||||
ret afp.fold_item(i, f);
|
||||
}
|
||||
fn f_item_underscore(afp: &ast_fold_precursor, f: ast_fold, i: &item_) ->
|
||||
fn f_item_underscore(afp: ast_fold_precursor, f: ast_fold, i: item_) ->
|
||||
item_ {
|
||||
ret afp.fold_item_underscore(i, f);
|
||||
}
|
||||
fn f_method(afp: &ast_fold_precursor, f: ast_fold, x: &@method) ->
|
||||
@method {
|
||||
fn f_method(afp: ast_fold_precursor, f: ast_fold, x: @method) -> @method {
|
||||
ret @{node: afp.fold_method(x.node, f), span: afp.new_span(x.span)};
|
||||
}
|
||||
fn f_block(afp: &ast_fold_precursor, f: ast_fold, x: &blk) -> blk {
|
||||
fn f_block(afp: ast_fold_precursor, f: ast_fold, x: blk) -> blk {
|
||||
ret {node: afp.fold_block(x.node, f), span: afp.new_span(x.span)};
|
||||
}
|
||||
fn f_stmt(afp: &ast_fold_precursor, f: ast_fold, x: &@stmt) -> @stmt {
|
||||
fn f_stmt(afp: ast_fold_precursor, f: ast_fold, x: @stmt) -> @stmt {
|
||||
ret @{node: afp.fold_stmt(x.node, f), span: afp.new_span(x.span)};
|
||||
}
|
||||
fn f_arm(afp: &ast_fold_precursor, f: ast_fold, x: &arm) -> arm {
|
||||
fn f_arm(afp: ast_fold_precursor, f: ast_fold, x: arm) -> arm {
|
||||
ret afp.fold_arm(x, f);
|
||||
}
|
||||
fn f_pat(afp: &ast_fold_precursor, f: ast_fold, x: &@pat) -> @pat {
|
||||
fn f_pat(afp: ast_fold_precursor, f: ast_fold, x: @pat) -> @pat {
|
||||
ret @{id: afp.new_id(x.id),
|
||||
node: afp.fold_pat(x.node, f),
|
||||
span: afp.new_span(x.span)};
|
||||
}
|
||||
fn f_decl(afp: &ast_fold_precursor, f: ast_fold, x: &@decl) -> @decl {
|
||||
fn f_decl(afp: ast_fold_precursor, f: ast_fold, x: @decl) -> @decl {
|
||||
ret @{node: afp.fold_decl(x.node, f), span: afp.new_span(x.span)};
|
||||
}
|
||||
fn f_expr(afp: &ast_fold_precursor, f: ast_fold, x: &@expr) -> @expr {
|
||||
fn f_expr(afp: ast_fold_precursor, f: ast_fold, x: @expr) -> @expr {
|
||||
ret @{id: afp.new_id(x.id),
|
||||
node: afp.fold_expr(x.node, f),
|
||||
span: afp.new_span(x.span)};
|
||||
}
|
||||
fn f_ty(afp: &ast_fold_precursor, f: ast_fold, x: &@ty) -> @ty {
|
||||
fn f_ty(afp: ast_fold_precursor, f: ast_fold, x: @ty) -> @ty {
|
||||
ret @{node: afp.fold_ty(x.node, f), span: afp.new_span(x.span)};
|
||||
}
|
||||
fn f_constr(afp: &ast_fold_precursor, f: ast_fold, x: &@ast::constr) ->
|
||||
fn f_constr(afp: ast_fold_precursor, f: ast_fold, x: @ast::constr) ->
|
||||
@ast::constr {
|
||||
ret @{node: afp.fold_constr(x.node, f), span: afp.new_span(x.span)};
|
||||
}
|
||||
fn f_fn(afp: &ast_fold_precursor, f: ast_fold, x: &_fn) -> _fn {
|
||||
fn f_fn(afp: ast_fold_precursor, f: ast_fold, x: _fn) -> _fn {
|
||||
ret afp.fold_fn(x, f);
|
||||
}
|
||||
fn f_mod(afp: &ast_fold_precursor, f: ast_fold, x: &_mod) -> _mod {
|
||||
fn f_mod(afp: ast_fold_precursor, f: ast_fold, x: _mod) -> _mod {
|
||||
ret afp.fold_mod(x, f);
|
||||
}
|
||||
fn f_native_mod(afp: &ast_fold_precursor, f: ast_fold, x: &native_mod) ->
|
||||
fn f_native_mod(afp: ast_fold_precursor, f: ast_fold, x: native_mod) ->
|
||||
native_mod {
|
||||
ret afp.fold_native_mod(x, f);
|
||||
}
|
||||
fn f_variant(afp: &ast_fold_precursor, f: ast_fold, x: &variant) ->
|
||||
fn f_variant(afp: ast_fold_precursor, f: ast_fold, x: variant) ->
|
||||
variant {
|
||||
ret {node: afp.fold_variant(x.node, f), span: afp.new_span(x.span)};
|
||||
}
|
||||
fn f_ident(afp: &ast_fold_precursor, f: ast_fold, x: &ident) -> ident {
|
||||
fn f_ident(afp: ast_fold_precursor, f: ast_fold, x: ident) -> ident {
|
||||
ret afp.fold_ident(x, f);
|
||||
}
|
||||
fn f_path(afp: &ast_fold_precursor, f: ast_fold, x: &path) -> path {
|
||||
fn f_path(afp: ast_fold_precursor, f: ast_fold, x: path) -> path {
|
||||
ret {node: afp.fold_path(x.node, f), span: afp.new_span(x.span)};
|
||||
}
|
||||
fn f_local(afp: &ast_fold_precursor, f: ast_fold, x: &@local) -> @local {
|
||||
fn f_local(afp: ast_fold_precursor, f: ast_fold, x: @local) -> @local {
|
||||
ret @{node: afp.fold_local(x.node, f), span: afp.new_span(x.span)};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,23 +25,23 @@ type ctx =
|
|||
mutable byte_pos: uint,
|
||||
cfg: ast::crate_cfg};
|
||||
|
||||
fn eval_crate_directives(cx: ctx, cdirs: &[@ast::crate_directive],
|
||||
prefix: &str, view_items: &mutable [@ast::view_item],
|
||||
fn eval_crate_directives(cx: ctx, cdirs: [@ast::crate_directive], prefix: str,
|
||||
view_items: &mutable [@ast::view_item],
|
||||
items: &mutable [@ast::item]) {
|
||||
for sub_cdir: @ast::crate_directive in cdirs {
|
||||
eval_crate_directive(cx, sub_cdir, prefix, view_items, items);
|
||||
}
|
||||
}
|
||||
|
||||
fn eval_crate_directives_to_mod(cx: ctx, cdirs: &[@ast::crate_directive],
|
||||
prefix: &str) -> ast::_mod {
|
||||
fn eval_crate_directives_to_mod(cx: ctx, cdirs: [@ast::crate_directive],
|
||||
prefix: str) -> ast::_mod {
|
||||
let view_items: [@ast::view_item] = [];
|
||||
let items: [@ast::item] = [];
|
||||
eval_crate_directives(cx, cdirs, prefix, view_items, items);
|
||||
ret {view_items: view_items, items: items};
|
||||
}
|
||||
|
||||
fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: &str,
|
||||
fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: str,
|
||||
view_items: &mutable [@ast::view_item],
|
||||
items: &mutable [@ast::item]) {
|
||||
alt cdir.node {
|
||||
|
|
|
|||
|
|
@ -25,10 +25,10 @@ type reader =
|
|||
fn get_byte_pos() -> uint;
|
||||
fn get_col() -> uint;
|
||||
fn get_filemap() -> codemap::filemap;
|
||||
fn err(&str);
|
||||
fn err(str);
|
||||
};
|
||||
|
||||
fn new_reader(cm: &codemap::codemap, src: &str, filemap: codemap::filemap,
|
||||
fn new_reader(cm: codemap::codemap, src: str, filemap: codemap::filemap,
|
||||
itr: @interner::interner<str>) -> reader {
|
||||
obj reader(cm: codemap::codemap,
|
||||
src: str,
|
||||
|
|
@ -77,7 +77,7 @@ fn new_reader(cm: &codemap::codemap, src: &str, filemap: codemap::filemap,
|
|||
fn get_interner() -> @interner::interner<str> { ret itr; }
|
||||
fn get_col() -> uint { ret col; }
|
||||
fn get_filemap() -> codemap::filemap { ret fm; }
|
||||
fn err(m: &str) {
|
||||
fn err(m: str) {
|
||||
codemap::emit_error(some(ast_util::mk_sp(chpos, chpos)), m, cm);
|
||||
}
|
||||
}
|
||||
|
|
@ -123,12 +123,12 @@ fn is_hex_digit(c: char) -> bool {
|
|||
|
||||
fn is_bin_digit(c: char) -> bool { ret c == '0' || c == '1'; }
|
||||
|
||||
fn consume_whitespace_and_comments(rdr: &reader) {
|
||||
fn consume_whitespace_and_comments(rdr: reader) {
|
||||
while is_whitespace(rdr.curr()) { rdr.bump(); }
|
||||
be consume_any_line_comment(rdr);
|
||||
}
|
||||
|
||||
fn consume_any_line_comment(rdr: &reader) {
|
||||
fn consume_any_line_comment(rdr: reader) {
|
||||
if rdr.curr() == '/' {
|
||||
alt rdr.next() {
|
||||
'/' {
|
||||
|
|
@ -143,7 +143,7 @@ fn consume_any_line_comment(rdr: &reader) {
|
|||
}
|
||||
}
|
||||
|
||||
fn consume_block_comment(rdr: &reader) {
|
||||
fn consume_block_comment(rdr: reader) {
|
||||
let level: int = 1;
|
||||
while level > 0 {
|
||||
if rdr.is_eof() { rdr.err("unterminated block comment"); fail; }
|
||||
|
|
@ -164,13 +164,13 @@ fn consume_block_comment(rdr: &reader) {
|
|||
be consume_whitespace_and_comments(rdr);
|
||||
}
|
||||
|
||||
fn digits_to_string(s: &str) -> int {
|
||||
fn digits_to_string(s: str) -> int {
|
||||
let accum_int: int = 0;
|
||||
for c: u8 in s { accum_int *= 10; accum_int += dec_digit_val(c as char); }
|
||||
ret accum_int;
|
||||
}
|
||||
|
||||
fn scan_exponent(rdr: &reader) -> option::t<str> {
|
||||
fn scan_exponent(rdr: reader) -> option::t<str> {
|
||||
let c = rdr.curr();
|
||||
let rslt = "";
|
||||
if c == 'e' || c == 'E' {
|
||||
|
|
@ -188,7 +188,7 @@ fn scan_exponent(rdr: &reader) -> option::t<str> {
|
|||
} else { ret none::<str>; }
|
||||
}
|
||||
|
||||
fn scan_dec_digits(rdr: &reader) -> str {
|
||||
fn scan_dec_digits(rdr: reader) -> str {
|
||||
let c = rdr.curr();
|
||||
let rslt: str = "";
|
||||
while is_dec_digit(c) || c == '_' {
|
||||
|
|
@ -199,7 +199,7 @@ fn scan_dec_digits(rdr: &reader) -> str {
|
|||
ret rslt;
|
||||
}
|
||||
|
||||
fn scan_number(c: char, rdr: &reader) -> token::token {
|
||||
fn scan_number(c: char, rdr: reader) -> token::token {
|
||||
let accum_int = 0;
|
||||
let dec_str: str = "";
|
||||
let is_dec_integer: bool = false;
|
||||
|
|
@ -312,7 +312,7 @@ fn scan_number(c: char, rdr: &reader) -> token::token {
|
|||
}
|
||||
}
|
||||
|
||||
fn scan_numeric_escape(rdr: &reader, n_hex_digits: uint) -> char {
|
||||
fn scan_numeric_escape(rdr: reader, n_hex_digits: uint) -> char {
|
||||
let accum_int = 0;
|
||||
while n_hex_digits != 0u {
|
||||
let n = rdr.curr();
|
||||
|
|
@ -328,7 +328,7 @@ fn scan_numeric_escape(rdr: &reader, n_hex_digits: uint) -> char {
|
|||
ret accum_int as char;
|
||||
}
|
||||
|
||||
fn next_token(rdr: &reader) -> {tok: token::token, chpos: uint, bpos: uint} {
|
||||
fn next_token(rdr: reader) -> {tok: token::token, chpos: uint, bpos: uint} {
|
||||
consume_whitespace_and_comments(rdr);
|
||||
let start_chpos = rdr.get_chpos();
|
||||
let start_bpos = rdr.get_byte_pos();
|
||||
|
|
@ -336,7 +336,7 @@ fn next_token(rdr: &reader) -> {tok: token::token, chpos: uint, bpos: uint} {
|
|||
ret {tok: tok, chpos: start_chpos, bpos: start_bpos};
|
||||
}
|
||||
|
||||
fn next_token_inner(rdr: &reader) -> token::token {
|
||||
fn next_token_inner(rdr: reader) -> token::token {
|
||||
let accum_str = "";
|
||||
let c = rdr.curr();
|
||||
if is_alpha(c) || c == '_' {
|
||||
|
|
@ -351,7 +351,7 @@ fn next_token_inner(rdr: &reader) -> token::token {
|
|||
accum_str), is_mod_name);
|
||||
}
|
||||
if is_dec_digit(c) { ret scan_number(c, rdr); }
|
||||
fn binop(rdr: &reader, op: token::binop) -> token::token {
|
||||
fn binop(rdr: reader, op: token::binop) -> token::token {
|
||||
rdr.bump();
|
||||
if rdr.curr() == '=' {
|
||||
rdr.bump();
|
||||
|
|
@ -362,6 +362,7 @@ fn next_token_inner(rdr: &reader) -> token::token {
|
|||
|
||||
|
||||
|
||||
|
||||
// One-byte tokens.
|
||||
'?' {
|
||||
rdr.bump();
|
||||
|
|
@ -402,6 +403,7 @@ fn next_token_inner(rdr: &reader) -> token::token {
|
|||
|
||||
|
||||
|
||||
|
||||
// Multi-byte tokens.
|
||||
'=' {
|
||||
rdr.bump();
|
||||
|
|
@ -551,7 +553,7 @@ tag cmnt_style {
|
|||
|
||||
type cmnt = {style: cmnt_style, lines: [str], pos: uint};
|
||||
|
||||
fn read_to_eol(rdr: &reader) -> str {
|
||||
fn read_to_eol(rdr: reader) -> str {
|
||||
let val = "";
|
||||
while rdr.curr() != '\n' && !rdr.is_eof() {
|
||||
str::push_char(val, rdr.curr());
|
||||
|
|
@ -561,29 +563,29 @@ fn read_to_eol(rdr: &reader) -> str {
|
|||
ret val;
|
||||
}
|
||||
|
||||
fn read_one_line_comment(rdr: &reader) -> str {
|
||||
fn read_one_line_comment(rdr: reader) -> str {
|
||||
let val = read_to_eol(rdr);
|
||||
assert (val[0] == '/' as u8 && val[1] == '/' as u8);
|
||||
ret val;
|
||||
}
|
||||
|
||||
fn consume_whitespace(rdr: &reader) {
|
||||
fn consume_whitespace(rdr: reader) {
|
||||
while is_whitespace(rdr.curr()) && !rdr.is_eof() { rdr.bump(); }
|
||||
}
|
||||
|
||||
fn consume_non_eol_whitespace(rdr: &reader) {
|
||||
fn consume_non_eol_whitespace(rdr: reader) {
|
||||
while is_whitespace(rdr.curr()) && rdr.curr() != '\n' && !rdr.is_eof() {
|
||||
rdr.bump();
|
||||
}
|
||||
}
|
||||
|
||||
fn push_blank_line_comment(rdr: &reader, comments: &mutable [cmnt]) {
|
||||
fn push_blank_line_comment(rdr: reader, comments: &mutable [cmnt]) {
|
||||
log ">>> blank-line comment";
|
||||
let v: [str] = [];
|
||||
comments += [{style: blank_line, lines: v, pos: rdr.get_chpos()}];
|
||||
}
|
||||
|
||||
fn consume_whitespace_counting_blank_lines(rdr: &reader,
|
||||
fn consume_whitespace_counting_blank_lines(rdr: reader,
|
||||
comments: &mutable [cmnt]) {
|
||||
while is_whitespace(rdr.curr()) && !rdr.is_eof() {
|
||||
if rdr.get_col() == 0u && rdr.curr() == '\n' {
|
||||
|
|
@ -593,7 +595,7 @@ fn consume_whitespace_counting_blank_lines(rdr: &reader,
|
|||
}
|
||||
}
|
||||
|
||||
fn read_line_comments(rdr: &reader, code_to_the_left: bool) -> cmnt {
|
||||
fn read_line_comments(rdr: reader, code_to_the_left: bool) -> cmnt {
|
||||
log ">>> line comments";
|
||||
let p = rdr.get_chpos();
|
||||
let lines: [str] = [];
|
||||
|
|
@ -609,13 +611,13 @@ fn read_line_comments(rdr: &reader, code_to_the_left: bool) -> cmnt {
|
|||
pos: p};
|
||||
}
|
||||
|
||||
fn all_whitespace(s: &str, begin: uint, end: uint) -> bool {
|
||||
fn all_whitespace(s: str, begin: uint, end: uint) -> bool {
|
||||
let i: uint = begin;
|
||||
while i != end { if !is_whitespace(s[i] as char) { ret false; } i += 1u; }
|
||||
ret true;
|
||||
}
|
||||
|
||||
fn trim_whitespace_prefix_and_push_line(lines: &mutable [str], s: &str,
|
||||
fn trim_whitespace_prefix_and_push_line(lines: &mutable [str], s: str,
|
||||
col: uint) {
|
||||
let s1;
|
||||
if all_whitespace(s, 0u, col) {
|
||||
|
|
@ -627,7 +629,7 @@ fn trim_whitespace_prefix_and_push_line(lines: &mutable [str], s: &str,
|
|||
lines += [s1];
|
||||
}
|
||||
|
||||
fn read_block_comment(rdr: &reader, code_to_the_left: bool) -> cmnt {
|
||||
fn read_block_comment(rdr: reader, code_to_the_left: bool) -> cmnt {
|
||||
log ">>> block comment";
|
||||
let p = rdr.get_chpos();
|
||||
let lines: [str] = [];
|
||||
|
|
@ -672,12 +674,12 @@ fn read_block_comment(rdr: &reader, code_to_the_left: bool) -> cmnt {
|
|||
ret {style: style, lines: lines, pos: p};
|
||||
}
|
||||
|
||||
fn peeking_at_comment(rdr: &reader) -> bool {
|
||||
fn peeking_at_comment(rdr: reader) -> bool {
|
||||
ret rdr.curr() == '/' && rdr.next() == '/' ||
|
||||
rdr.curr() == '/' && rdr.next() == '*';
|
||||
}
|
||||
|
||||
fn consume_comment(rdr: &reader, code_to_the_left: bool,
|
||||
fn consume_comment(rdr: reader, code_to_the_left: bool,
|
||||
comments: &mutable [cmnt]) {
|
||||
log ">>> consume comment";
|
||||
if rdr.curr() == '/' && rdr.next() == '/' {
|
||||
|
|
@ -688,7 +690,7 @@ fn consume_comment(rdr: &reader, code_to_the_left: bool,
|
|||
log "<<< consume comment";
|
||||
}
|
||||
|
||||
fn is_lit(t: &token::token) -> bool {
|
||||
fn is_lit(t: token::token) -> bool {
|
||||
ret alt t {
|
||||
token::LIT_INT(_) { true }
|
||||
token::LIT_UINT(_) { true }
|
||||
|
|
@ -704,7 +706,7 @@ fn is_lit(t: &token::token) -> bool {
|
|||
|
||||
type lit = {lit: str, pos: uint};
|
||||
|
||||
fn gather_comments_and_literals(cm: &codemap::codemap, path: &str,
|
||||
fn gather_comments_and_literals(cm: codemap::codemap, path: str,
|
||||
srdr: io::reader) ->
|
||||
{cmnts: [cmnt], lits: [lit]} {
|
||||
let src = str::unsafe_from_bytes(srdr.read_whole_stream());
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -118,6 +118,7 @@ fn to_str(r: lexer::reader, t: token) -> str {
|
|||
|
||||
|
||||
|
||||
|
||||
/* Structural symbols */
|
||||
AT. {
|
||||
ret "@";
|
||||
|
|
@ -144,6 +145,7 @@ fn to_str(r: lexer::reader, t: token) -> str {
|
|||
|
||||
|
||||
|
||||
|
||||
/* Literals */
|
||||
LIT_INT(i) {
|
||||
ret int::to_str(i, 10u);
|
||||
|
|
@ -171,6 +173,7 @@ fn to_str(r: lexer::reader, t: token) -> str {
|
|||
|
||||
|
||||
|
||||
|
||||
/* Name components */
|
||||
IDENT(s, _) {
|
||||
ret interner::get::<str>(*r.get_interner(), s);
|
||||
|
|
|
|||
|
|
@ -73,8 +73,8 @@ fn tok_str(t: token) -> str {
|
|||
}
|
||||
}
|
||||
|
||||
fn buf_str(toks: &[mutable token], szs: &[mutable int], left: uint,
|
||||
right: uint, lim: uint) -> str {
|
||||
fn buf_str(toks: [mutable token], szs: [mutable int], left: uint, right: uint,
|
||||
lim: uint) -> str {
|
||||
let n = vec::len(toks);
|
||||
assert (n == vec::len(szs));
|
||||
let i = left;
|
||||
|
|
@ -404,7 +404,7 @@ obj printer(out: io::writer,
|
|||
if n != 0u { top = print_stack[n - 1u]; }
|
||||
ret top;
|
||||
}
|
||||
fn write_str(s: &str) {
|
||||
fn write_str(s: str) {
|
||||
while pending_indentation > 0 {
|
||||
out.write_str(" ");
|
||||
pending_indentation -= 1;
|
||||
|
|
@ -492,15 +492,15 @@ fn end(p: printer) { p.pretty_print(END); }
|
|||
|
||||
fn eof(p: printer) { p.pretty_print(EOF); }
|
||||
|
||||
fn word(p: printer, wrd: &str) {
|
||||
fn word(p: printer, wrd: str) {
|
||||
p.pretty_print(STRING(wrd, str::char_len(wrd) as int));
|
||||
}
|
||||
|
||||
fn huge_word(p: printer, wrd: &str) {
|
||||
fn huge_word(p: printer, wrd: str) {
|
||||
p.pretty_print(STRING(wrd, size_infinity));
|
||||
}
|
||||
|
||||
fn zero_word(p: printer, wrd: &str) { p.pretty_print(STRING(wrd, 0)); }
|
||||
fn zero_word(p: printer, wrd: str) { p.pretty_print(STRING(wrd, 0)); }
|
||||
|
||||
fn spaces(p: printer, n: uint) { break_offset(p, n, 0); }
|
||||
|
||||
|
|
|
|||
|
|
@ -33,10 +33,10 @@ tag ann_node {
|
|||
node_expr(ps, @ast::expr);
|
||||
node_pat(ps, @ast::pat);
|
||||
}
|
||||
type pp_ann = {pre: fn(&ann_node), post: fn(&ann_node)};
|
||||
type pp_ann = {pre: fn(ann_node), post: fn(ann_node)};
|
||||
|
||||
fn no_ann() -> pp_ann {
|
||||
fn ignore(_node: &ann_node) { }
|
||||
fn ignore(_node: ann_node) { }
|
||||
ret {pre: ignore, post: ignore};
|
||||
}
|
||||
|
||||
|
|
@ -50,9 +50,9 @@ type ps =
|
|||
mutable boxes: [pp::breaks],
|
||||
ann: pp_ann};
|
||||
|
||||
fn ibox(s: &ps, u: uint) { s.boxes += [pp::inconsistent]; pp::ibox(s.s, u); }
|
||||
fn ibox(s: ps, u: uint) { s.boxes += [pp::inconsistent]; pp::ibox(s.s, u); }
|
||||
|
||||
fn end(s: &ps) { vec::pop(s.boxes); pp::end(s.s); }
|
||||
fn end(s: ps) { vec::pop(s.boxes); pp::end(s.s); }
|
||||
|
||||
fn rust_printer(writer: io::writer) -> ps {
|
||||
let boxes: [pp::breaks] = [];
|
||||
|
|
@ -74,8 +74,8 @@ const default_columns: uint = 78u;
|
|||
// Requires you to pass an input filename and reader so that
|
||||
// it can scan the input text for comments and literals to
|
||||
// copy forward.
|
||||
fn print_crate(cm: &codemap, crate: @ast::crate, filename: &str,
|
||||
in: io::reader, out: io::writer, ann: &pp_ann) {
|
||||
fn print_crate(cm: codemap, crate: @ast::crate, filename: str, in: io::reader,
|
||||
out: io::writer, ann: pp_ann) {
|
||||
let boxes: [pp::breaks] = [];
|
||||
let r = lexer::gather_comments_and_literals(cm, filename, in);
|
||||
let s =
|
||||
|
|
@ -92,22 +92,21 @@ fn print_crate(cm: &codemap, crate: @ast::crate, filename: &str,
|
|||
eof(s.s);
|
||||
}
|
||||
|
||||
fn ty_to_str(ty: &@ast::ty) -> str { be to_str(ty, print_type); }
|
||||
fn ty_to_str(ty: @ast::ty) -> str { be to_str(ty, print_type); }
|
||||
|
||||
fn pat_to_str(pat: &@ast::pat) -> str { be to_str(pat, print_pat); }
|
||||
fn pat_to_str(pat: @ast::pat) -> str { be to_str(pat, print_pat); }
|
||||
|
||||
fn expr_to_str(e: &@ast::expr) -> str { be to_str(e, print_expr); }
|
||||
fn expr_to_str(e: @ast::expr) -> str { be to_str(e, print_expr); }
|
||||
|
||||
fn stmt_to_str(s: &ast::stmt) -> str { be to_str(s, print_stmt); }
|
||||
fn stmt_to_str(s: ast::stmt) -> str { be to_str(s, print_stmt); }
|
||||
|
||||
fn item_to_str(i: &@ast::item) -> str { be to_str(i, print_item); }
|
||||
fn item_to_str(i: @ast::item) -> str { be to_str(i, print_item); }
|
||||
|
||||
fn path_to_str(p: &ast::path) -> str {
|
||||
fn path_to_str(p: ast::path) -> str {
|
||||
be to_str(p, bind print_path(_, _, false));
|
||||
}
|
||||
|
||||
fn fun_to_str(f: &ast::_fn, name: &ast::ident, params: &[ast::ty_param]) ->
|
||||
str {
|
||||
fn fun_to_str(f: ast::_fn, name: ast::ident, params: [ast::ty_param]) -> str {
|
||||
let writer = io::string_writer();
|
||||
let s = rust_printer(writer.get_writer());
|
||||
print_fn(s, f.decl, f.proto, name, params, f.decl.constraints);
|
||||
|
|
@ -115,7 +114,7 @@ fn fun_to_str(f: &ast::_fn, name: &ast::ident, params: &[ast::ty_param]) ->
|
|||
ret writer.get_str();
|
||||
}
|
||||
|
||||
fn block_to_str(blk: &ast::blk) -> str {
|
||||
fn block_to_str(blk: ast::blk) -> str {
|
||||
let writer = io::string_writer();
|
||||
let s = rust_printer(writer.get_writer());
|
||||
// containing cbox, will be closed by print-block at }
|
||||
|
|
@ -129,29 +128,29 @@ fn block_to_str(blk: &ast::blk) -> str {
|
|||
ret writer.get_str();
|
||||
}
|
||||
|
||||
fn meta_item_to_str(mi: &ast::meta_item) -> str {
|
||||
fn meta_item_to_str(mi: ast::meta_item) -> str {
|
||||
ret to_str(@mi, print_meta_item);
|
||||
}
|
||||
|
||||
fn attribute_to_str(attr: &ast::attribute) -> str {
|
||||
fn attribute_to_str(attr: ast::attribute) -> str {
|
||||
be to_str(attr, print_attribute);
|
||||
}
|
||||
|
||||
fn cbox(s: &ps, u: uint) { s.boxes += [pp::consistent]; pp::cbox(s.s, u); }
|
||||
fn cbox(s: ps, u: uint) { s.boxes += [pp::consistent]; pp::cbox(s.s, u); }
|
||||
|
||||
fn box(s: &ps, u: uint, b: pp::breaks) { s.boxes += [b]; pp::box(s.s, u, b); }
|
||||
fn box(s: ps, u: uint, b: pp::breaks) { s.boxes += [b]; pp::box(s.s, u, b); }
|
||||
|
||||
fn nbsp(s: &ps) { word(s.s, " "); }
|
||||
fn nbsp(s: ps) { word(s.s, " "); }
|
||||
|
||||
fn word_nbsp(s: &ps, w: &str) { word(s.s, w); nbsp(s); }
|
||||
fn word_nbsp(s: ps, w: str) { word(s.s, w); nbsp(s); }
|
||||
|
||||
fn word_space(s: &ps, w: &str) { word(s.s, w); space(s.s); }
|
||||
fn word_space(s: ps, w: str) { word(s.s, w); space(s.s); }
|
||||
|
||||
fn popen(s: &ps) { word(s.s, "("); }
|
||||
fn popen(s: ps) { word(s.s, "("); }
|
||||
|
||||
fn pclose(s: &ps) { word(s.s, ")"); }
|
||||
fn pclose(s: ps) { word(s.s, ")"); }
|
||||
|
||||
fn head(s: &ps, w: &str) {
|
||||
fn head(s: ps, w: str) {
|
||||
// outer-box is consistent
|
||||
cbox(s, indent_unit);
|
||||
// head-box is inconsistent
|
||||
|
|
@ -160,35 +159,35 @@ fn head(s: &ps, w: &str) {
|
|||
word_nbsp(s, w);
|
||||
}
|
||||
|
||||
fn bopen(s: &ps) {
|
||||
fn bopen(s: ps) {
|
||||
word(s.s, "{");
|
||||
end(s); // close the head-box
|
||||
}
|
||||
|
||||
fn bclose_(s: &ps, span: codemap::span, indented: uint) {
|
||||
fn bclose_(s: ps, span: codemap::span, indented: uint) {
|
||||
maybe_print_comment(s, span.hi);
|
||||
break_offset_if_not_bol(s, 1u, -(indented as int));
|
||||
word(s.s, "}");
|
||||
end(s); // close the outer-box
|
||||
}
|
||||
fn bclose(s: &ps, span: codemap::span) { bclose_(s, span, indent_unit); }
|
||||
fn bclose(s: ps, span: codemap::span) { bclose_(s, span, indent_unit); }
|
||||
|
||||
fn is_begin(s: &ps) -> bool {
|
||||
fn is_begin(s: ps) -> bool {
|
||||
alt s.s.last_token() { pp::BEGIN(_) { true } _ { false } }
|
||||
}
|
||||
|
||||
fn is_end(s: &ps) -> bool {
|
||||
fn is_end(s: ps) -> bool {
|
||||
alt s.s.last_token() { pp::END. { true } _ { false } }
|
||||
}
|
||||
|
||||
fn is_bol(s: &ps) -> bool {
|
||||
fn is_bol(s: ps) -> bool {
|
||||
ret s.s.last_token() == pp::EOF ||
|
||||
s.s.last_token() == pp::hardbreak_tok();
|
||||
}
|
||||
|
||||
fn hardbreak_if_not_bol(s: &ps) { if !is_bol(s) { hardbreak(s.s); } }
|
||||
fn space_if_not_bol(s: &ps) { if !is_bol(s) { space(s.s); } }
|
||||
fn break_offset_if_not_bol(s: &ps, n: uint, off: int) {
|
||||
fn hardbreak_if_not_bol(s: ps) { if !is_bol(s) { hardbreak(s.s); } }
|
||||
fn space_if_not_bol(s: ps) { if !is_bol(s) { space(s.s); } }
|
||||
fn break_offset_if_not_bol(s: ps, n: uint, off: int) {
|
||||
if !is_bol(s) {
|
||||
break_offset(s.s, n, off);
|
||||
} else {
|
||||
|
|
@ -203,7 +202,7 @@ fn break_offset_if_not_bol(s: &ps, n: uint, off: int) {
|
|||
|
||||
// Synthesizes a comment that was not textually present in the original source
|
||||
// file.
|
||||
fn synth_comment(s: &ps, text: &str) {
|
||||
fn synth_comment(s: ps, text: str) {
|
||||
word(s.s, "/*");
|
||||
space(s.s);
|
||||
word(s.s, text);
|
||||
|
|
@ -211,7 +210,7 @@ fn synth_comment(s: &ps, text: &str) {
|
|||
word(s.s, "*/");
|
||||
}
|
||||
|
||||
fn commasep<IN>(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN)) {
|
||||
fn commasep<IN>(s: ps, b: breaks, elts: [IN], op: fn(ps, IN)) {
|
||||
box(s, 0u, b);
|
||||
let first = true;
|
||||
for elt: IN in elts {
|
||||
|
|
@ -222,8 +221,8 @@ fn commasep<IN>(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN)) {
|
|||
}
|
||||
|
||||
|
||||
fn commasep_cmnt<IN>(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN),
|
||||
get_span: fn(&IN) -> codemap::span) {
|
||||
fn commasep_cmnt<IN>(s: ps, b: breaks, elts: [IN], op: fn(ps, IN),
|
||||
get_span: fn(IN) -> codemap::span) {
|
||||
box(s, 0u, b);
|
||||
let len = vec::len::<IN>(elts);
|
||||
let i = 0u;
|
||||
|
|
@ -241,12 +240,12 @@ fn commasep_cmnt<IN>(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN),
|
|||
end(s);
|
||||
}
|
||||
|
||||
fn commasep_exprs(s: &ps, b: breaks, exprs: &[@ast::expr]) {
|
||||
fn expr_span(expr: &@ast::expr) -> codemap::span { ret expr.span; }
|
||||
fn commasep_exprs(s: ps, b: breaks, exprs: [@ast::expr]) {
|
||||
fn expr_span(expr: @ast::expr) -> codemap::span { ret expr.span; }
|
||||
commasep_cmnt(s, b, exprs, print_expr, expr_span);
|
||||
}
|
||||
|
||||
fn print_mod(s: &ps, _mod: &ast::_mod, attrs: &[ast::attribute]) {
|
||||
fn print_mod(s: ps, _mod: ast::_mod, attrs: [ast::attribute]) {
|
||||
print_inner_attributes(s, attrs);
|
||||
for vitem: @ast::view_item in _mod.view_items {
|
||||
print_view_item(s, vitem);
|
||||
|
|
@ -254,8 +253,7 @@ fn print_mod(s: &ps, _mod: &ast::_mod, attrs: &[ast::attribute]) {
|
|||
for item: @ast::item in _mod.items { print_item(s, item); }
|
||||
}
|
||||
|
||||
fn print_native_mod(s: &ps, nmod: &ast::native_mod,
|
||||
attrs: &[ast::attribute]) {
|
||||
fn print_native_mod(s: ps, nmod: ast::native_mod, attrs: [ast::attribute]) {
|
||||
print_inner_attributes(s, attrs);
|
||||
for vitem: @ast::view_item in nmod.view_items {
|
||||
print_view_item(s, vitem);
|
||||
|
|
@ -263,7 +261,7 @@ fn print_native_mod(s: &ps, nmod: &ast::native_mod,
|
|||
for item: @ast::native_item in nmod.items { print_native_item(s, item); }
|
||||
}
|
||||
|
||||
fn print_type(s: &ps, ty: &@ast::ty) {
|
||||
fn print_type(s: ps, ty: @ast::ty) {
|
||||
maybe_print_comment(s, ty.span.lo);
|
||||
ibox(s, 0u);
|
||||
alt ty.node {
|
||||
|
|
@ -301,7 +299,7 @@ fn print_type(s: &ps, ty: &@ast::ty) {
|
|||
}
|
||||
ast::ty_rec(fields) {
|
||||
word(s.s, "{");
|
||||
fn print_field(s: &ps, f: &ast::ty_field) {
|
||||
fn print_field(s: ps, f: ast::ty_field) {
|
||||
cbox(s, indent_unit);
|
||||
print_mutability(s, f.node.mt.mut);
|
||||
word(s.s, f.node.ident);
|
||||
|
|
@ -309,7 +307,7 @@ fn print_type(s: &ps, ty: &@ast::ty) {
|
|||
print_type(s, f.node.mt.ty);
|
||||
end(s);
|
||||
}
|
||||
fn get_span(f: &ast::ty_field) -> codemap::span { ret f.span; }
|
||||
fn get_span(f: ast::ty_field) -> codemap::span { ret f.span; }
|
||||
commasep_cmnt(s, consistent, fields, print_field, get_span);
|
||||
word(s.s, "}");
|
||||
}
|
||||
|
|
@ -346,7 +344,7 @@ fn print_type(s: &ps, ty: &@ast::ty) {
|
|||
end(s);
|
||||
}
|
||||
|
||||
fn print_native_item(s: &ps, item: &@ast::native_item) {
|
||||
fn print_native_item(s: ps, item: @ast::native_item) {
|
||||
hardbreak_if_not_bol(s);
|
||||
maybe_print_comment(s, item.span.lo);
|
||||
print_outer_attributes(s, item.attrs);
|
||||
|
|
@ -365,6 +363,7 @@ fn print_native_item(s: &ps, item: &@ast::native_item) {
|
|||
|
||||
|
||||
|
||||
|
||||
ast::native_item_fn(lname, decl, typarams) {
|
||||
print_fn(s, decl, ast::proto_fn, item.ident, typarams,
|
||||
decl.constraints);
|
||||
|
|
@ -379,7 +378,7 @@ fn print_native_item(s: &ps, item: &@ast::native_item) {
|
|||
}
|
||||
}
|
||||
|
||||
fn print_item(s: &ps, item: &@ast::item) {
|
||||
fn print_item(s: ps, item: @ast::item) {
|
||||
hardbreak_if_not_bol(s);
|
||||
maybe_print_comment(s, item.span.lo);
|
||||
print_outer_attributes(s, item.attrs);
|
||||
|
|
@ -473,7 +472,7 @@ fn print_item(s: &ps, item: &@ast::item) {
|
|||
word(s.s, v.node.name);
|
||||
if vec::len(v.node.args) > 0u {
|
||||
popen(s);
|
||||
fn print_variant_arg(s: &ps, arg: &ast::variant_arg) {
|
||||
fn print_variant_arg(s: ps, arg: ast::variant_arg) {
|
||||
print_type(s, arg.ty);
|
||||
}
|
||||
commasep(s, consistent, v.node.args, print_variant_arg);
|
||||
|
|
@ -490,14 +489,14 @@ fn print_item(s: &ps, item: &@ast::item) {
|
|||
word(s.s, item.ident);
|
||||
print_type_params(s, params);
|
||||
popen(s);
|
||||
fn print_field(s: &ps, field: &ast::obj_field) {
|
||||
fn print_field(s: ps, field: ast::obj_field) {
|
||||
ibox(s, indent_unit);
|
||||
print_mutability(s, field.mut);
|
||||
word_space(s, field.ident + ":");
|
||||
print_type(s, field.ty);
|
||||
end(s);
|
||||
}
|
||||
fn get_span(f: &ast::obj_field) -> codemap::span { ret f.ty.span; }
|
||||
fn get_span(f: ast::obj_field) -> codemap::span { ret f.ty.span; }
|
||||
commasep_cmnt(s, consistent, _obj.fields, print_field, get_span);
|
||||
pclose(s);
|
||||
space(s.s);
|
||||
|
|
@ -528,7 +527,7 @@ fn print_item(s: &ps, item: &@ast::item) {
|
|||
s.ann.post(ann_node);
|
||||
}
|
||||
|
||||
fn print_outer_attributes(s: &ps, attrs: &[ast::attribute]) {
|
||||
fn print_outer_attributes(s: ps, attrs: [ast::attribute]) {
|
||||
let count = 0;
|
||||
for attr: ast::attribute in attrs {
|
||||
alt attr.node.style {
|
||||
|
|
@ -539,7 +538,7 @@ fn print_outer_attributes(s: &ps, attrs: &[ast::attribute]) {
|
|||
if count > 0 { hardbreak_if_not_bol(s); }
|
||||
}
|
||||
|
||||
fn print_inner_attributes(s: &ps, attrs: &[ast::attribute]) {
|
||||
fn print_inner_attributes(s: ps, attrs: [ast::attribute]) {
|
||||
let count = 0;
|
||||
for attr: ast::attribute in attrs {
|
||||
alt attr.node.style {
|
||||
|
|
@ -554,7 +553,7 @@ fn print_inner_attributes(s: &ps, attrs: &[ast::attribute]) {
|
|||
if count > 0 { hardbreak_if_not_bol(s); }
|
||||
}
|
||||
|
||||
fn print_attribute(s: &ps, attr: &ast::attribute) {
|
||||
fn print_attribute(s: ps, attr: ast::attribute) {
|
||||
hardbreak_if_not_bol(s);
|
||||
maybe_print_comment(s, attr.span.lo);
|
||||
word(s.s, "#[");
|
||||
|
|
@ -562,7 +561,7 @@ fn print_attribute(s: &ps, attr: &ast::attribute) {
|
|||
word(s.s, "]");
|
||||
}
|
||||
|
||||
fn print_stmt(s: &ps, st: &ast::stmt) {
|
||||
fn print_stmt(s: ps, st: ast::stmt) {
|
||||
maybe_print_comment(s, st.span.lo);
|
||||
alt st.node {
|
||||
ast::stmt_decl(decl, _) { print_decl(s, decl); }
|
||||
|
|
@ -572,13 +571,13 @@ fn print_stmt(s: &ps, st: &ast::stmt) {
|
|||
maybe_print_trailing_comment(s, st.span, none::<uint>);
|
||||
}
|
||||
|
||||
fn print_block(s: &ps, blk: &ast::blk) {
|
||||
fn print_block(s: ps, blk: ast::blk) {
|
||||
print_possibly_embedded_block(s, blk, block_normal, indent_unit);
|
||||
}
|
||||
|
||||
tag embed_type { block_macro; block_block_fn; block_normal; }
|
||||
|
||||
fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type,
|
||||
fn print_possibly_embedded_block(s: ps, blk: ast::blk, embedded: embed_type,
|
||||
indented: uint) {
|
||||
alt blk.node.rules { ast::unchecked. { word(s.s, "unchecked"); } _ { } }
|
||||
|
||||
|
|
@ -615,8 +614,8 @@ fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type,
|
|||
// followed by a unary op, square bracket, or paren. In those cases we
|
||||
// have to add an extra semi to make sure the output retains the same
|
||||
// meaning.
|
||||
fn maybe_protect_block(s: &ps, last: &option::t<@ast::stmt>,
|
||||
next: &expr_or_stmt) {
|
||||
fn maybe_protect_block(s: ps, last: option::t<@ast::stmt>,
|
||||
next: expr_or_stmt) {
|
||||
let last_expr_is_block =
|
||||
alt last {
|
||||
option::some(@{node: ast::stmt_expr(e, _), _}) {
|
||||
|
|
@ -655,7 +654,7 @@ fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type,
|
|||
visit_expr(ex, env, visitor);
|
||||
ret *env;
|
||||
|
||||
fn visit_expr(ex: &@ast::expr, e: &env, v: &visit::vt<env>) {
|
||||
fn visit_expr(ex: @ast::expr, e: env, v: visit::vt<env>) {
|
||||
assert (*e == false);
|
||||
|
||||
if expr_is_ambig(ex) { *e = true; ret; }
|
||||
|
|
@ -695,7 +694,7 @@ fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type,
|
|||
|
||||
// ret and fail, without arguments cannot appear is the discriminant of if,
|
||||
// alt, do, & while unambiguously without being parenthesized
|
||||
fn print_maybe_parens_discrim(s: &ps, e: &@ast::expr) {
|
||||
fn print_maybe_parens_discrim(s: ps, e: @ast::expr) {
|
||||
let disambig =
|
||||
alt e.node { ast::expr_ret(option::none.) { true } _ { false } };
|
||||
if disambig { popen(s) }
|
||||
|
|
@ -703,20 +702,21 @@ fn print_maybe_parens_discrim(s: &ps, e: &@ast::expr) {
|
|||
if disambig { pclose(s) }
|
||||
}
|
||||
|
||||
fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk,
|
||||
elseopt: &option::t<@ast::expr>, chk: bool) {
|
||||
fn print_if(s: ps, test: @ast::expr, blk: ast::blk,
|
||||
elseopt: option::t<@ast::expr>, chk: bool) {
|
||||
head(s, "if");
|
||||
if chk { word_nbsp(s, "check"); }
|
||||
print_maybe_parens_discrim(s, test);
|
||||
space(s.s);
|
||||
print_block(s, blk);
|
||||
fn do_else(s: &ps, els: option::t<@ast::expr>) {
|
||||
fn do_else(s: ps, els: option::t<@ast::expr>) {
|
||||
alt els {
|
||||
some(_else) {
|
||||
alt _else.node {
|
||||
|
||||
|
||||
|
||||
|
||||
// "another else-if"
|
||||
ast::expr_if(i, t, e) {
|
||||
cbox(s, indent_unit - 1u);
|
||||
|
|
@ -730,6 +730,7 @@ fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk,
|
|||
|
||||
|
||||
|
||||
|
||||
// "final else"
|
||||
ast::expr_block(b) {
|
||||
cbox(s, indent_unit - 1u);
|
||||
|
|
@ -745,7 +746,7 @@ fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk,
|
|||
do_else(s, elseopt);
|
||||
}
|
||||
|
||||
fn print_mac(s: &ps, m: &ast::mac) {
|
||||
fn print_mac(s: ps, m: ast::mac) {
|
||||
alt m.node {
|
||||
ast::mac_invoc(path, arg, body) {
|
||||
word(s.s, "#");
|
||||
|
|
@ -766,7 +767,7 @@ fn print_mac(s: &ps, m: &ast::mac) {
|
|||
}
|
||||
}
|
||||
|
||||
fn print_expr(s: &ps, expr: &@ast::expr) {
|
||||
fn print_expr(s: ps, expr: @ast::expr) {
|
||||
maybe_print_comment(s, expr.span.lo);
|
||||
ibox(s, indent_unit);
|
||||
let ann_node = node_expr(s, expr);
|
||||
|
|
@ -784,7 +785,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) {
|
|||
end(s);
|
||||
}
|
||||
ast::expr_rec(fields, wth) {
|
||||
fn print_field(s: &ps, field: &ast::field) {
|
||||
fn print_field(s: ps, field: ast::field) {
|
||||
ibox(s, indent_unit);
|
||||
if field.node.mut == ast::mut { word_nbsp(s, "mutable"); }
|
||||
word(s.s, field.node.ident);
|
||||
|
|
@ -792,7 +793,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) {
|
|||
print_expr(s, field.node.expr);
|
||||
end(s);
|
||||
}
|
||||
fn get_span(field: &ast::field) -> codemap::span { ret field.span; }
|
||||
fn get_span(field: ast::field) -> codemap::span { ret field.span; }
|
||||
word(s.s, "{");
|
||||
commasep_cmnt(s, consistent, fields, print_field, get_span);
|
||||
alt wth {
|
||||
|
|
@ -823,7 +824,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) {
|
|||
print_ident(s, ident);
|
||||
}
|
||||
ast::expr_bind(func, args) {
|
||||
fn print_opt(s: &ps, expr: &option::t<@ast::expr>) {
|
||||
fn print_opt(s: ps, expr: option::t<@ast::expr>) {
|
||||
alt expr {
|
||||
some(expr) { print_expr(s, expr); }
|
||||
_ { word(s.s, "_"); }
|
||||
|
|
@ -1036,7 +1037,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) {
|
|||
|
||||
// Fields
|
||||
popen(s);
|
||||
fn print_field(s: &ps, field: &ast::anon_obj_field) {
|
||||
fn print_field(s: ps, field: ast::anon_obj_field) {
|
||||
ibox(s, indent_unit);
|
||||
print_mutability(s, field.mut);
|
||||
word_space(s, field.ident + ":");
|
||||
|
|
@ -1046,7 +1047,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) {
|
|||
print_expr(s, field.expr);
|
||||
end(s);
|
||||
}
|
||||
fn get_span(f: &ast::anon_obj_field) -> codemap::span {
|
||||
fn get_span(f: ast::anon_obj_field) -> codemap::span {
|
||||
ret f.ty.span;
|
||||
}
|
||||
alt anon_obj.fields {
|
||||
|
|
@ -1083,14 +1084,14 @@ fn print_expr(s: &ps, expr: &@ast::expr) {
|
|||
end(s);
|
||||
}
|
||||
|
||||
fn print_expr_parens_if_unary(s: &ps, ex: &@ast::expr) {
|
||||
fn print_expr_parens_if_unary(s: ps, ex: @ast::expr) {
|
||||
let parens = alt ex.node { ast::expr_unary(_, _) { true } _ { false } };
|
||||
if parens { popen(s); }
|
||||
print_expr(s, ex);
|
||||
if parens { pclose(s); }
|
||||
}
|
||||
|
||||
fn print_local_decl(s: &ps, loc: &@ast::local) {
|
||||
fn print_local_decl(s: ps, loc: @ast::local) {
|
||||
print_pat(s, loc.node.pat);
|
||||
alt loc.node.ty.node {
|
||||
ast::ty_infer. { }
|
||||
|
|
@ -1098,14 +1099,14 @@ fn print_local_decl(s: &ps, loc: &@ast::local) {
|
|||
}
|
||||
}
|
||||
|
||||
fn print_decl(s: &ps, decl: &@ast::decl) {
|
||||
fn print_decl(s: ps, decl: @ast::decl) {
|
||||
maybe_print_comment(s, decl.span.lo);
|
||||
alt decl.node {
|
||||
ast::decl_local(locs) {
|
||||
space_if_not_bol(s);
|
||||
ibox(s, indent_unit);
|
||||
word_nbsp(s, "let");
|
||||
fn print_local(s: &ps, loc: &@ast::local) {
|
||||
fn print_local(s: ps, loc: @ast::local) {
|
||||
ibox(s, indent_unit);
|
||||
print_local_decl(s, loc);
|
||||
end(s);
|
||||
|
|
@ -1128,16 +1129,16 @@ fn print_decl(s: &ps, decl: &@ast::decl) {
|
|||
}
|
||||
}
|
||||
|
||||
fn print_ident(s: &ps, ident: &ast::ident) { word(s.s, ident); }
|
||||
fn print_ident(s: ps, ident: ast::ident) { word(s.s, ident); }
|
||||
|
||||
fn print_for_decl(s: &ps, loc: &@ast::local, coll: &@ast::expr) {
|
||||
fn print_for_decl(s: ps, loc: @ast::local, coll: @ast::expr) {
|
||||
print_local_decl(s, loc);
|
||||
space(s.s);
|
||||
word_space(s, "in");
|
||||
print_expr(s, coll);
|
||||
}
|
||||
|
||||
fn print_path(s: &ps, path: &ast::path, colons_before_params: bool) {
|
||||
fn print_path(s: ps, path: ast::path, colons_before_params: bool) {
|
||||
maybe_print_comment(s, path.span.lo);
|
||||
if path.node.global { word(s.s, "::"); }
|
||||
let first = true;
|
||||
|
|
@ -1153,7 +1154,7 @@ fn print_path(s: &ps, path: &ast::path, colons_before_params: bool) {
|
|||
}
|
||||
}
|
||||
|
||||
fn print_pat(s: &ps, pat: &@ast::pat) {
|
||||
fn print_pat(s: ps, pat: @ast::pat) {
|
||||
maybe_print_comment(s, pat.span.lo);
|
||||
let ann_node = node_pat(s, pat);
|
||||
s.ann.pre(ann_node);
|
||||
|
|
@ -1171,14 +1172,14 @@ fn print_pat(s: &ps, pat: &@ast::pat) {
|
|||
}
|
||||
ast::pat_rec(fields, etc) {
|
||||
word(s.s, "{");
|
||||
fn print_field(s: &ps, f: &ast::field_pat) {
|
||||
fn print_field(s: ps, f: ast::field_pat) {
|
||||
cbox(s, indent_unit);
|
||||
word(s.s, f.ident);
|
||||
word_space(s, ":");
|
||||
print_pat(s, f.pat);
|
||||
end(s);
|
||||
}
|
||||
fn get_span(f: &ast::field_pat) -> codemap::span { ret f.pat.span; }
|
||||
fn get_span(f: ast::field_pat) -> codemap::span { ret f.pat.span; }
|
||||
commasep_cmnt(s, consistent, fields, print_field, get_span);
|
||||
if etc {
|
||||
if vec::len(fields) != 0u { word_space(s, ","); }
|
||||
|
|
@ -1196,8 +1197,8 @@ fn print_pat(s: &ps, pat: &@ast::pat) {
|
|||
s.ann.post(ann_node);
|
||||
}
|
||||
|
||||
fn print_fn(s: &ps, decl: ast::fn_decl, proto: ast::proto, name: &ast::ident,
|
||||
typarams: &[ast::ty_param], constrs: [@ast::constr]) {
|
||||
fn print_fn(s: ps, decl: ast::fn_decl, proto: ast::proto, name: ast::ident,
|
||||
typarams: [ast::ty_param], constrs: [@ast::constr]) {
|
||||
alt decl.purity {
|
||||
ast::impure_fn. { head(s, proto_to_str(proto)); }
|
||||
_ { head(s, "pure fn"); }
|
||||
|
|
@ -1207,10 +1208,9 @@ fn print_fn(s: &ps, decl: ast::fn_decl, proto: ast::proto, name: &ast::ident,
|
|||
print_fn_args_and_ret(s, decl, constrs);
|
||||
}
|
||||
|
||||
fn print_fn_args_and_ret(s: &ps, decl: &ast::fn_decl,
|
||||
constrs: [@ast::constr]) {
|
||||
fn print_fn_args_and_ret(s: ps, decl: ast::fn_decl, constrs: [@ast::constr]) {
|
||||
popen(s);
|
||||
fn print_arg(s: &ps, x: &ast::arg) {
|
||||
fn print_arg(s: ps, x: ast::arg) {
|
||||
ibox(s, indent_unit);
|
||||
word_space(s, x.ident + ":");
|
||||
print_alias(s, x.mode);
|
||||
|
|
@ -1228,9 +1228,9 @@ fn print_fn_args_and_ret(s: &ps, decl: &ast::fn_decl,
|
|||
}
|
||||
}
|
||||
|
||||
fn print_fn_block_args(s: &ps, decl: &ast::fn_decl) {
|
||||
fn print_fn_block_args(s: ps, decl: ast::fn_decl) {
|
||||
word(s.s, "|");
|
||||
fn print_arg(s: &ps, x: &ast::arg) {
|
||||
fn print_arg(s: ps, x: ast::arg) {
|
||||
ibox(s, indent_unit);
|
||||
print_alias(s, x.mode);
|
||||
word(s.s, x.ident);
|
||||
|
|
@ -1241,7 +1241,7 @@ fn print_fn_block_args(s: &ps, decl: &ast::fn_decl) {
|
|||
maybe_print_comment(s, decl.output.span.lo);
|
||||
}
|
||||
|
||||
fn print_alias(s: &ps, m: ast::mode) {
|
||||
fn print_alias(s: ps, m: ast::mode) {
|
||||
alt m {
|
||||
ast::by_mut_ref. { word_space(s, "&mutable"); }
|
||||
ast::by_move. { word(s.s, "-"); }
|
||||
|
|
@ -1249,7 +1249,7 @@ fn print_alias(s: &ps, m: ast::mode) {
|
|||
}
|
||||
}
|
||||
|
||||
fn print_kind(s: &ps, kind: ast::kind) {
|
||||
fn print_kind(s: ps, kind: ast::kind) {
|
||||
alt kind {
|
||||
ast::kind_unique. { word(s.s, "~"); }
|
||||
ast::kind_shared. { word(s.s, "@"); }
|
||||
|
|
@ -1257,10 +1257,10 @@ fn print_kind(s: &ps, kind: ast::kind) {
|
|||
}
|
||||
}
|
||||
|
||||
fn print_type_params(s: &ps, params: &[ast::ty_param]) {
|
||||
fn print_type_params(s: ps, params: [ast::ty_param]) {
|
||||
if vec::len(params) > 0u {
|
||||
word(s.s, "<");
|
||||
fn printParam(s: &ps, param: &ast::ty_param) {
|
||||
fn printParam(s: ps, param: ast::ty_param) {
|
||||
print_kind(s, param.kind);
|
||||
word(s.s, param.ident);
|
||||
}
|
||||
|
|
@ -1269,7 +1269,7 @@ fn print_type_params(s: &ps, params: &[ast::ty_param]) {
|
|||
}
|
||||
}
|
||||
|
||||
fn print_meta_item(s: &ps, item: &@ast::meta_item) {
|
||||
fn print_meta_item(s: ps, item: @ast::meta_item) {
|
||||
ibox(s, indent_unit);
|
||||
alt item.node {
|
||||
ast::meta_word(name) { word(s.s, name); }
|
||||
|
|
@ -1288,7 +1288,7 @@ fn print_meta_item(s: &ps, item: &@ast::meta_item) {
|
|||
end(s);
|
||||
}
|
||||
|
||||
fn print_view_item(s: &ps, item: &@ast::view_item) {
|
||||
fn print_view_item(s: ps, item: @ast::view_item) {
|
||||
hardbreak_if_not_bol(s);
|
||||
maybe_print_comment(s, item.span.lo);
|
||||
alt item.node {
|
||||
|
|
@ -1318,9 +1318,7 @@ fn print_view_item(s: &ps, item: &@ast::view_item) {
|
|||
for elt: ast::ident in mod_path { word(s.s, elt); word(s.s, "::"); }
|
||||
word(s.s, "{");
|
||||
commasep(s, inconsistent, idents,
|
||||
fn (s: &ps, w: &ast::import_ident) {
|
||||
word(s.s, w.node.name)
|
||||
});
|
||||
fn (s: ps, w: ast::import_ident) { word(s.s, w.node.name) });
|
||||
word(s.s, "}");
|
||||
}
|
||||
ast::view_item_import_glob(ids, _) {
|
||||
|
|
@ -1335,7 +1333,7 @@ fn print_view_item(s: &ps, item: &@ast::view_item) {
|
|||
ast::view_item_export(ids, _) {
|
||||
head(s, "export");
|
||||
commasep(s, inconsistent, ids,
|
||||
fn (s: &ps, w: &ast::ident) { word(s.s, w) });
|
||||
fn (s: ps, w: ast::ident) { word(s.s, w) });
|
||||
}
|
||||
}
|
||||
word(s.s, ";");
|
||||
|
|
@ -1355,7 +1353,7 @@ fn operator_prec(op: ast::binop) -> int {
|
|||
fail;
|
||||
}
|
||||
|
||||
fn need_parens(expr: &@ast::expr, outer_prec: int) -> bool {
|
||||
fn need_parens(expr: @ast::expr, outer_prec: int) -> bool {
|
||||
alt expr.node {
|
||||
ast::expr_binary(op, _, _) { operator_prec(op) < outer_prec }
|
||||
ast::expr_cast(_, _) { parse::parser::as_prec < outer_prec }
|
||||
|
|
@ -1363,6 +1361,7 @@ fn need_parens(expr: &@ast::expr, outer_prec: int) -> bool {
|
|||
|
||||
|
||||
|
||||
|
||||
// This may be too conservative in some cases
|
||||
ast::expr_assign(_, _) {
|
||||
true
|
||||
|
|
@ -1380,14 +1379,14 @@ fn need_parens(expr: &@ast::expr, outer_prec: int) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn print_maybe_parens(s: &ps, expr: &@ast::expr, outer_prec: int) {
|
||||
fn print_maybe_parens(s: ps, expr: @ast::expr, outer_prec: int) {
|
||||
let add_them = need_parens(expr, outer_prec);
|
||||
if add_them { popen(s); }
|
||||
print_expr(s, expr);
|
||||
if add_them { pclose(s); }
|
||||
}
|
||||
|
||||
fn print_mutability(s: &ps, mut: &ast::mutability) {
|
||||
fn print_mutability(s: ps, mut: ast::mutability) {
|
||||
alt mut {
|
||||
ast::mut. { word_nbsp(s, "mutable"); }
|
||||
ast::maybe_mut. { word_nbsp(s, "mutable?"); }
|
||||
|
|
@ -1395,20 +1394,20 @@ fn print_mutability(s: &ps, mut: &ast::mutability) {
|
|||
}
|
||||
}
|
||||
|
||||
fn print_mt(s: &ps, mt: &ast::mt) {
|
||||
fn print_mt(s: ps, mt: ast::mt) {
|
||||
print_mutability(s, mt.mut);
|
||||
print_type(s, mt.ty);
|
||||
}
|
||||
|
||||
fn print_ty_fn(s: &ps, proto: &ast::proto, id: &option::t<ast::ident>,
|
||||
inputs: &[ast::ty_arg], output: &@ast::ty,
|
||||
cf: &ast::controlflow, constrs: &[@ast::constr]) {
|
||||
fn print_ty_fn(s: ps, proto: ast::proto, id: option::t<ast::ident>,
|
||||
inputs: [ast::ty_arg], output: @ast::ty, cf: ast::controlflow,
|
||||
constrs: [@ast::constr]) {
|
||||
ibox(s, indent_unit);
|
||||
word(s.s, proto_to_str(proto));
|
||||
alt id { some(id) { word(s.s, " "); word(s.s, id); } _ { } }
|
||||
zerobreak(s.s);
|
||||
popen(s);
|
||||
fn print_arg(s: &ps, input: &ast::ty_arg) {
|
||||
fn print_arg(s: ps, input: ast::ty_arg) {
|
||||
print_alias(s, input.node.mode);
|
||||
print_type(s, input.node.ty);
|
||||
}
|
||||
|
|
@ -1429,7 +1428,7 @@ fn print_ty_fn(s: &ps, proto: &ast::proto, id: &option::t<ast::ident>,
|
|||
end(s);
|
||||
}
|
||||
|
||||
fn maybe_print_trailing_comment(s: &ps, span: codemap::span,
|
||||
fn maybe_print_trailing_comment(s: ps, span: codemap::span,
|
||||
next_pos: option::t<uint>) {
|
||||
let cm;
|
||||
alt s.cm { some(ccm) { cm = ccm; } _ { ret; } }
|
||||
|
|
@ -1450,7 +1449,7 @@ fn maybe_print_trailing_comment(s: &ps, span: codemap::span,
|
|||
}
|
||||
}
|
||||
|
||||
fn print_remaining_comments(s: &ps) {
|
||||
fn print_remaining_comments(s: ps) {
|
||||
// If there aren't any remaining comments, then we need to manually
|
||||
// make sure there is a line break at the end.
|
||||
if option::is_none(next_comment(s)) { hardbreak(s.s); }
|
||||
|
|
@ -1462,13 +1461,13 @@ fn print_remaining_comments(s: &ps) {
|
|||
}
|
||||
}
|
||||
|
||||
fn in_cbox(s: &ps) -> bool {
|
||||
fn in_cbox(s: ps) -> bool {
|
||||
let len = vec::len(s.boxes);
|
||||
if len == 0u { ret false; }
|
||||
ret s.boxes[len - 1u] == pp::consistent;
|
||||
}
|
||||
|
||||
fn print_literal(s: &ps, lit: &@ast::lit) {
|
||||
fn print_literal(s: ps, lit: @ast::lit) {
|
||||
maybe_print_comment(s, lit.span.lo);
|
||||
alt next_lit(s) {
|
||||
some(lt) {
|
||||
|
|
@ -1502,9 +1501,9 @@ fn print_literal(s: &ps, lit: &@ast::lit) {
|
|||
}
|
||||
}
|
||||
|
||||
fn lit_to_str(l: &@ast::lit) -> str { be to_str(l, print_literal); }
|
||||
fn lit_to_str(l: @ast::lit) -> str { be to_str(l, print_literal); }
|
||||
|
||||
fn next_lit(s: &ps) -> option::t<lexer::lit> {
|
||||
fn next_lit(s: ps) -> option::t<lexer::lit> {
|
||||
alt s.literals {
|
||||
some(lits) {
|
||||
if s.cur_lit < vec::len(lits) {
|
||||
|
|
@ -1515,7 +1514,7 @@ fn next_lit(s: &ps) -> option::t<lexer::lit> {
|
|||
}
|
||||
}
|
||||
|
||||
fn maybe_print_comment(s: &ps, pos: uint) {
|
||||
fn maybe_print_comment(s: ps, pos: uint) {
|
||||
while true {
|
||||
alt next_comment(s) {
|
||||
some(cmnt) {
|
||||
|
|
@ -1529,7 +1528,7 @@ fn maybe_print_comment(s: &ps, pos: uint) {
|
|||
}
|
||||
}
|
||||
|
||||
fn print_comment(s: &ps, cmnt: lexer::cmnt) {
|
||||
fn print_comment(s: ps, cmnt: lexer::cmnt) {
|
||||
alt cmnt.style {
|
||||
lexer::mixed. {
|
||||
assert (vec::len(cmnt.lines) == 1u);
|
||||
|
|
@ -1573,13 +1572,13 @@ fn print_comment(s: &ps, cmnt: lexer::cmnt) {
|
|||
}
|
||||
}
|
||||
|
||||
fn print_string(s: &ps, st: &str) {
|
||||
fn print_string(s: ps, st: str) {
|
||||
word(s.s, "\"");
|
||||
word(s.s, escape_str(st, '"'));
|
||||
word(s.s, "\"");
|
||||
}
|
||||
|
||||
fn escape_str(st: &str, to_escape: char) -> str {
|
||||
fn escape_str(st: str, to_escape: char) -> str {
|
||||
let out: str = "";
|
||||
let len = str::byte_len(st);
|
||||
let i = 0u;
|
||||
|
|
@ -1601,7 +1600,7 @@ fn escape_str(st: &str, to_escape: char) -> str {
|
|||
ret out;
|
||||
}
|
||||
|
||||
fn to_str<T>(t: &T, f: fn(&ps, &T)) -> str {
|
||||
fn to_str<T>(t: T, f: fn(ps, T)) -> str {
|
||||
let writer = io::string_writer();
|
||||
let s = rust_printer(writer.get_writer());
|
||||
f(s, t);
|
||||
|
|
@ -1609,7 +1608,7 @@ fn to_str<T>(t: &T, f: fn(&ps, &T)) -> str {
|
|||
ret writer.get_str();
|
||||
}
|
||||
|
||||
fn next_comment(s: &ps) -> option::t<lexer::cmnt> {
|
||||
fn next_comment(s: ps) -> option::t<lexer::cmnt> {
|
||||
alt s.comments {
|
||||
some(cmnts) {
|
||||
if s.cur_cmnt < vec::len(cmnts) {
|
||||
|
|
@ -1622,8 +1621,8 @@ fn next_comment(s: &ps) -> option::t<lexer::cmnt> {
|
|||
|
||||
// Removing the aliases from the type of f in the next two functions
|
||||
// triggers memory corruption, but I haven't isolated the bug yet. FIXME
|
||||
fn constr_args_to_str<T>(f: &fn(&T) -> str, args: &[@ast::sp_constr_arg<T>])
|
||||
-> str {
|
||||
fn constr_args_to_str<T>(f: fn(T) -> str, args: [@ast::sp_constr_arg<T>]) ->
|
||||
str {
|
||||
let comma = false;
|
||||
let s = "(";
|
||||
for a: @ast::sp_constr_arg<T> in args {
|
||||
|
|
@ -1634,7 +1633,7 @@ fn constr_args_to_str<T>(f: &fn(&T) -> str, args: &[@ast::sp_constr_arg<T>])
|
|||
ret s;
|
||||
}
|
||||
|
||||
fn constr_arg_to_str<T>(f: &fn(&T) -> str, c: &ast::constr_arg_general_<T>) ->
|
||||
fn constr_arg_to_str<T>(f: fn(T) -> str, c: ast::constr_arg_general_<T>) ->
|
||||
str {
|
||||
alt c {
|
||||
ast::carg_base. { ret "*"; }
|
||||
|
|
@ -1646,15 +1645,15 @@ fn constr_arg_to_str<T>(f: &fn(&T) -> str, c: &ast::constr_arg_general_<T>) ->
|
|||
// needed b/c constr_args_to_str needs
|
||||
// something that takes an alias
|
||||
// (argh)
|
||||
fn uint_to_str(i: &uint) -> str { ret uint::str(i); }
|
||||
fn uint_to_str(i: uint) -> str { ret uint::str(i); }
|
||||
|
||||
fn ast_ty_fn_constr_to_str(c: &@ast::constr) -> str {
|
||||
fn ast_ty_fn_constr_to_str(c: @ast::constr) -> str {
|
||||
ret path_to_str(c.node.path) +
|
||||
constr_args_to_str(uint_to_str, c.node.args);
|
||||
}
|
||||
|
||||
// FIXME: fix repeated code
|
||||
fn ast_ty_fn_constrs_str(constrs: &[@ast::constr]) -> str {
|
||||
fn ast_ty_fn_constrs_str(constrs: [@ast::constr]) -> str {
|
||||
let s = "";
|
||||
let colon = true;
|
||||
for c: @ast::constr in constrs {
|
||||
|
|
@ -1664,18 +1663,18 @@ fn ast_ty_fn_constrs_str(constrs: &[@ast::constr]) -> str {
|
|||
ret s;
|
||||
}
|
||||
|
||||
fn fn_arg_idx_to_str(decl: &ast::fn_decl, idx: &uint) -> str {
|
||||
fn fn_arg_idx_to_str(decl: ast::fn_decl, idx: uint) -> str {
|
||||
decl.inputs[idx].ident
|
||||
}
|
||||
|
||||
fn ast_fn_constr_to_str(decl: &ast::fn_decl, c: &@ast::constr) -> str {
|
||||
fn ast_fn_constr_to_str(decl: ast::fn_decl, c: @ast::constr) -> str {
|
||||
let arg_to_str = bind fn_arg_idx_to_str(decl, _);
|
||||
ret path_to_str(c.node.path) +
|
||||
constr_args_to_str(arg_to_str, c.node.args);
|
||||
}
|
||||
|
||||
// FIXME: fix repeated code
|
||||
fn ast_fn_constrs_str(decl: &ast::fn_decl, constrs: &[@ast::constr]) -> str {
|
||||
fn ast_fn_constrs_str(decl: ast::fn_decl, constrs: [@ast::constr]) -> str {
|
||||
let s = "";
|
||||
let colon = true;
|
||||
for c: @ast::constr in constrs {
|
||||
|
|
@ -1685,7 +1684,7 @@ fn ast_fn_constrs_str(decl: &ast::fn_decl, constrs: &[@ast::constr]) -> str {
|
|||
ret s;
|
||||
}
|
||||
|
||||
fn proto_to_str(p: &ast::proto) -> str {
|
||||
fn proto_to_str(p: ast::proto) -> str {
|
||||
ret alt p {
|
||||
ast::proto_fn. { "fn" }
|
||||
ast::proto_iter. { "iter" }
|
||||
|
|
@ -1694,8 +1693,8 @@ fn proto_to_str(p: &ast::proto) -> str {
|
|||
};
|
||||
}
|
||||
|
||||
fn ty_constr_to_str(c: &@ast::ty_constr) -> str {
|
||||
fn ty_constr_path_to_str(p: &ast::path) -> str { "*." + path_to_str(p) }
|
||||
fn ty_constr_to_str(c: @ast::ty_constr) -> str {
|
||||
fn ty_constr_path_to_str(p: ast::path) -> str { "*." + path_to_str(p) }
|
||||
|
||||
ret path_to_str(c.node.path) +
|
||||
constr_args_to_str::<ast::path>(ty_constr_path_to_str,
|
||||
|
|
@ -1703,7 +1702,7 @@ fn ty_constr_to_str(c: &@ast::ty_constr) -> str {
|
|||
}
|
||||
|
||||
|
||||
fn ast_ty_constrs_str(constrs: &[@ast::ty_constr]) -> str {
|
||||
fn ast_ty_constrs_str(constrs: [@ast::ty_constr]) -> str {
|
||||
let s = "";
|
||||
let colon = true;
|
||||
for c: @ast::ty_constr in constrs {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ fn mk<@T>(hasher: hashfn<T>, eqer: eqfn<T>) -> interner<T> {
|
|||
ret {map: m, mutable vect: [], hasher: hasher, eqer: eqer};
|
||||
}
|
||||
|
||||
fn intern<@T>(itr: &interner<T>, val: &T) -> uint {
|
||||
fn intern<@T>(itr: interner<T>, val: T) -> uint {
|
||||
alt itr.map.find(val) {
|
||||
some(idx) { ret idx; }
|
||||
none. {
|
||||
|
|
@ -33,7 +33,7 @@ fn intern<@T>(itr: &interner<T>, val: &T) -> uint {
|
|||
}
|
||||
}
|
||||
|
||||
fn get<@T>(itr: &interner<T>, idx: uint) -> T { ret itr.vect[idx]; }
|
||||
fn get<@T>(itr: interner<T>, idx: uint) -> T { ret itr.vect[idx]; }
|
||||
|
||||
fn len<T>(itr: &interner<T>) -> uint { ret vec::len(itr.vect); }
|
||||
fn len<T>(itr: interner<T>) -> uint { ret vec::len(itr.vect); }
|
||||
|
||||
|
|
|
|||
|
|
@ -19,20 +19,20 @@ tag vt<E> { mk_vt(visitor<E>); }
|
|||
type visitor<E> =
|
||||
// takes the components so that one function can be
|
||||
// generic over constr and ty_constr
|
||||
@{visit_mod: fn(&_mod, &span, &E, &vt<E>),
|
||||
visit_view_item: fn(&@view_item, &E, &vt<E>),
|
||||
visit_native_item: fn(&@native_item, &E, &vt<E>),
|
||||
visit_item: fn(&@item, &E, &vt<E>),
|
||||
visit_local: fn(&@local, &E, &vt<E>),
|
||||
visit_block: fn(&ast::blk, &E, &vt<E>),
|
||||
visit_stmt: fn(&@stmt, &E, &vt<E>),
|
||||
visit_arm: fn(&arm, &E, &vt<E>),
|
||||
visit_pat: fn(&@pat, &E, &vt<E>),
|
||||
visit_decl: fn(&@decl, &E, &vt<E>),
|
||||
visit_expr: fn(&@expr, &E, &vt<E>),
|
||||
visit_ty: fn(&@ty, &E, &vt<E>),
|
||||
visit_constr: fn(&path, &span, node_id, &E, &vt<E>),
|
||||
visit_fn: fn(&_fn, &[ty_param], &span, &fn_ident, node_id, &E, &vt<E>)};
|
||||
@{visit_mod: fn(_mod, span, E, vt<E>),
|
||||
visit_view_item: fn(@view_item, E, vt<E>),
|
||||
visit_native_item: fn(@native_item, E, vt<E>),
|
||||
visit_item: fn(@item, E, vt<E>),
|
||||
visit_local: fn(@local, E, vt<E>),
|
||||
visit_block: fn(ast::blk, E, vt<E>),
|
||||
visit_stmt: fn(@stmt, E, vt<E>),
|
||||
visit_arm: fn(arm, E, vt<E>),
|
||||
visit_pat: fn(@pat, E, vt<E>),
|
||||
visit_decl: fn(@decl, E, vt<E>),
|
||||
visit_expr: fn(@expr, E, vt<E>),
|
||||
visit_ty: fn(@ty, E, vt<E>),
|
||||
visit_constr: fn(path, span, node_id, E, vt<E>),
|
||||
visit_fn: fn(_fn, [ty_param], span, fn_ident, node_id, E, vt<E>)};
|
||||
|
||||
fn default_visitor<E>() -> visitor<E> {
|
||||
ret @{visit_mod: bind visit_mod::<E>(_, _, _, _),
|
||||
|
|
@ -51,11 +51,11 @@ fn default_visitor<E>() -> visitor<E> {
|
|||
visit_fn: bind visit_fn::<E>(_, _, _, _, _, _, _)};
|
||||
}
|
||||
|
||||
fn visit_crate<E>(c: &crate, e: &E, v: &vt<E>) {
|
||||
fn visit_crate<E>(c: crate, e: E, v: vt<E>) {
|
||||
v.visit_mod(c.node.module, c.span, e, v);
|
||||
}
|
||||
|
||||
fn visit_crate_directive<E>(cd: &@crate_directive, e: &E, v: &vt<E>) {
|
||||
fn visit_crate_directive<E>(cd: @crate_directive, e: E, v: vt<E>) {
|
||||
alt cd.node {
|
||||
cdir_src_mod(_, _, _) { }
|
||||
cdir_dir_mod(_, _, cdirs, _) {
|
||||
|
|
@ -69,20 +69,20 @@ fn visit_crate_directive<E>(cd: &@crate_directive, e: &E, v: &vt<E>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_mod<E>(m: &_mod, _sp: &span, e: &E, v: &vt<E>) {
|
||||
fn visit_mod<E>(m: _mod, _sp: span, e: E, v: vt<E>) {
|
||||
for vi: @view_item in m.view_items { v.visit_view_item(vi, e, v); }
|
||||
for i: @item in m.items { v.visit_item(i, e, v); }
|
||||
}
|
||||
|
||||
fn visit_view_item<E>(_vi: &@view_item, _e: &E, _v: &vt<E>) { }
|
||||
fn visit_view_item<E>(_vi: @view_item, _e: E, _v: vt<E>) { }
|
||||
|
||||
fn visit_local<E>(loc: &@local, e: &E, v: &vt<E>) {
|
||||
fn visit_local<E>(loc: @local, e: E, v: vt<E>) {
|
||||
v.visit_pat(loc.node.pat, e, v);
|
||||
v.visit_ty(loc.node.ty, e, v);
|
||||
alt loc.node.init { none. { } some(i) { v.visit_expr(i.expr, e, v); } }
|
||||
}
|
||||
|
||||
fn visit_item<E>(i: &@item, e: &E, v: &vt<E>) {
|
||||
fn visit_item<E>(i: @item, e: E, v: vt<E>) {
|
||||
alt i.node {
|
||||
item_const(t, ex) { v.visit_ty(t, e, v); v.visit_expr(ex, e, v); }
|
||||
item_fn(f, tp) { v.visit_fn(f, tp, i.span, some(i.ident), i.id, e, v); }
|
||||
|
|
@ -110,7 +110,7 @@ fn visit_item<E>(i: &@item, e: &E, v: &vt<E>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_ty<E>(t: &@ty, e: &E, v: &vt<E>) {
|
||||
fn visit_ty<E>(t: @ty, e: E, v: vt<E>) {
|
||||
alt t.node {
|
||||
ty_nil. {/* no-op */ }
|
||||
ty_bot. {/* no-op */ }
|
||||
|
|
@ -156,12 +156,12 @@ fn visit_ty<E>(t: &@ty, e: &E, v: &vt<E>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_constr<E>(_operator: &path, _sp: &span, _id: node_id, _e: &E,
|
||||
_v: &vt<E>) {
|
||||
fn visit_constr<E>(_operator: path, _sp: span, _id: node_id, _e: E,
|
||||
_v: vt<E>) {
|
||||
// default
|
||||
}
|
||||
|
||||
fn visit_pat<E>(p: &@pat, e: &E, v: &vt<E>) {
|
||||
fn visit_pat<E>(p: @pat, e: E, v: vt<E>) {
|
||||
alt p.node {
|
||||
pat_tag(path, children) {
|
||||
for tp: @ty in path.node.types { v.visit_ty(tp, e, v); }
|
||||
|
|
@ -176,14 +176,14 @@ fn visit_pat<E>(p: &@pat, e: &E, v: &vt<E>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_native_item<E>(ni: &@native_item, e: &E, v: &vt<E>) {
|
||||
fn visit_native_item<E>(ni: @native_item, e: E, v: vt<E>) {
|
||||
alt ni.node {
|
||||
native_item_fn(_, fd, _) { visit_fn_decl(fd, e, v); }
|
||||
native_item_ty. { }
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_fn_decl<E>(fd: &fn_decl, e: &E, v: &vt<E>) {
|
||||
fn visit_fn_decl<E>(fd: fn_decl, e: E, v: vt<E>) {
|
||||
for a: arg in fd.inputs { v.visit_ty(a.ty, e, v); }
|
||||
for c: @constr in fd.constraints {
|
||||
v.visit_constr(c.node.path, c.span, c.node.id, e, v);
|
||||
|
|
@ -191,18 +191,18 @@ fn visit_fn_decl<E>(fd: &fn_decl, e: &E, v: &vt<E>) {
|
|||
v.visit_ty(fd.output, e, v);
|
||||
}
|
||||
|
||||
fn visit_fn<E>(f: &_fn, _tp: &[ty_param], _sp: &span, _i: &fn_ident,
|
||||
_id: node_id, e: &E, v: &vt<E>) {
|
||||
fn visit_fn<E>(f: _fn, _tp: [ty_param], _sp: span, _i: fn_ident, _id: node_id,
|
||||
e: E, v: vt<E>) {
|
||||
visit_fn_decl(f.decl, e, v);
|
||||
v.visit_block(f.body, e, v);
|
||||
}
|
||||
|
||||
fn visit_block<E>(b: &ast::blk, e: &E, v: &vt<E>) {
|
||||
fn visit_block<E>(b: ast::blk, e: E, v: vt<E>) {
|
||||
for s: @stmt in b.node.stmts { v.visit_stmt(s, e, v); }
|
||||
visit_expr_opt(b.node.expr, e, v);
|
||||
}
|
||||
|
||||
fn visit_stmt<E>(s: &@stmt, e: &E, v: &vt<E>) {
|
||||
fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) {
|
||||
alt s.node {
|
||||
stmt_decl(d, _) { v.visit_decl(d, e, v); }
|
||||
stmt_expr(ex, _) { v.visit_expr(ex, e, v); }
|
||||
|
|
@ -210,7 +210,7 @@ fn visit_stmt<E>(s: &@stmt, e: &E, v: &vt<E>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_decl<E>(d: &@decl, e: &E, v: &vt<E>) {
|
||||
fn visit_decl<E>(d: @decl, e: E, v: vt<E>) {
|
||||
alt d.node {
|
||||
decl_local(locs) {
|
||||
for loc: @ast::local in locs { v.visit_local(loc, e, v); }
|
||||
|
|
@ -219,15 +219,15 @@ fn visit_decl<E>(d: &@decl, e: &E, v: &vt<E>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_expr_opt<E>(eo: option::t<@expr>, e: &E, v: &vt<E>) {
|
||||
fn visit_expr_opt<E>(eo: option::t<@expr>, e: E, v: vt<E>) {
|
||||
alt eo { none. { } some(ex) { v.visit_expr(ex, e, v); } }
|
||||
}
|
||||
|
||||
fn visit_exprs<E>(exprs: &[@expr], e: &E, v: &vt<E>) {
|
||||
fn visit_exprs<E>(exprs: [@expr], e: E, v: vt<E>) {
|
||||
for ex: @expr in exprs { v.visit_expr(ex, e, v); }
|
||||
}
|
||||
|
||||
fn visit_mac<E>(m: mac, e: &E, v: &vt<E>) {
|
||||
fn visit_mac<E>(m: mac, e: E, v: vt<E>) {
|
||||
alt m.node {
|
||||
ast::mac_invoc(pth, arg, body) { visit_expr(arg, e, v); }
|
||||
ast::mac_embed_type(ty) { v.visit_ty(ty, e, v); }
|
||||
|
|
@ -236,7 +236,7 @@ fn visit_mac<E>(m: mac, e: &E, v: &vt<E>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_expr<E>(ex: &@expr, e: &E, v: &vt<E>) {
|
||||
fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
|
||||
alt ex.node {
|
||||
expr_vec(es, _) { visit_exprs(es, e, v); }
|
||||
expr_rec(flds, base) {
|
||||
|
|
@ -329,7 +329,7 @@ fn visit_expr<E>(ex: &@expr, e: &E, v: &vt<E>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_arm<E>(a: &arm, e: &E, v: &vt<E>) {
|
||||
fn visit_arm<E>(a: arm, e: E, v: vt<E>) {
|
||||
for p: @pat in a.pats { v.visit_pat(p, e, v); }
|
||||
visit_expr_opt(a.guard, e, v);
|
||||
v.visit_block(a.body, e, v);
|
||||
|
|
@ -341,99 +341,99 @@ fn visit_arm<E>(a: &arm, e: &E, v: &vt<E>) {
|
|||
type simple_visitor =
|
||||
// takes the components so that one function can be
|
||||
// generic over constr and ty_constr
|
||||
@{visit_mod: fn(&_mod, &span),
|
||||
visit_view_item: fn(&@view_item),
|
||||
visit_native_item: fn(&@native_item),
|
||||
visit_item: fn(&@item),
|
||||
visit_local: fn(&@local),
|
||||
visit_block: fn(&ast::blk),
|
||||
visit_stmt: fn(&@stmt),
|
||||
visit_arm: fn(&arm),
|
||||
visit_pat: fn(&@pat),
|
||||
visit_decl: fn(&@decl),
|
||||
visit_expr: fn(&@expr),
|
||||
visit_ty: fn(&@ty),
|
||||
visit_constr: fn(&path, &span, node_id),
|
||||
visit_fn: fn(&_fn, &[ty_param], &span, &fn_ident, node_id)};
|
||||
@{visit_mod: fn(_mod, span),
|
||||
visit_view_item: fn(@view_item),
|
||||
visit_native_item: fn(@native_item),
|
||||
visit_item: fn(@item),
|
||||
visit_local: fn(@local),
|
||||
visit_block: fn(ast::blk),
|
||||
visit_stmt: fn(@stmt),
|
||||
visit_arm: fn(arm),
|
||||
visit_pat: fn(@pat),
|
||||
visit_decl: fn(@decl),
|
||||
visit_expr: fn(@expr),
|
||||
visit_ty: fn(@ty),
|
||||
visit_constr: fn(path, span, node_id),
|
||||
visit_fn: fn(_fn, [ty_param], span, fn_ident, node_id)};
|
||||
|
||||
fn default_simple_visitor() -> simple_visitor {
|
||||
ret @{visit_mod: fn (_m: &_mod, _sp: &span) { },
|
||||
visit_view_item: fn (_vi: &@view_item) { },
|
||||
visit_native_item: fn (_ni: &@native_item) { },
|
||||
visit_item: fn (_i: &@item) { },
|
||||
visit_local: fn (_l: &@local) { },
|
||||
visit_block: fn (_b: &ast::blk) { },
|
||||
visit_stmt: fn (_s: &@stmt) { },
|
||||
visit_arm: fn (_a: &arm) { },
|
||||
visit_pat: fn (_p: &@pat) { },
|
||||
visit_decl: fn (_d: &@decl) { },
|
||||
visit_expr: fn (_e: &@expr) { },
|
||||
visit_ty: fn (_t: &@ty) { },
|
||||
visit_constr: fn (_p: &path, _sp: &span, _id: node_id) { },
|
||||
ret @{visit_mod: fn (_m: _mod, _sp: span) { },
|
||||
visit_view_item: fn (_vi: @view_item) { },
|
||||
visit_native_item: fn (_ni: @native_item) { },
|
||||
visit_item: fn (_i: @item) { },
|
||||
visit_local: fn (_l: @local) { },
|
||||
visit_block: fn (_b: ast::blk) { },
|
||||
visit_stmt: fn (_s: @stmt) { },
|
||||
visit_arm: fn (_a: arm) { },
|
||||
visit_pat: fn (_p: @pat) { },
|
||||
visit_decl: fn (_d: @decl) { },
|
||||
visit_expr: fn (_e: @expr) { },
|
||||
visit_ty: fn (_t: @ty) { },
|
||||
visit_constr: fn (_p: path, _sp: span, _id: node_id) { },
|
||||
visit_fn:
|
||||
fn (_f: &_fn, _tps: &[ty_param], _sp: &span, _ident: &fn_ident,
|
||||
fn (_f: _fn, _tps: [ty_param], _sp: span, _ident: fn_ident,
|
||||
_id: node_id) {
|
||||
}};
|
||||
}
|
||||
|
||||
fn mk_simple_visitor(v: &simple_visitor) -> vt<()> {
|
||||
fn v_mod(f: fn(&_mod, &span), m: &_mod, sp: &span, e: &(), v: &vt<()>) {
|
||||
fn mk_simple_visitor(v: simple_visitor) -> vt<()> {
|
||||
fn v_mod(f: fn(_mod, span), m: _mod, sp: span, e: (), v: vt<()>) {
|
||||
f(m, sp);
|
||||
visit_mod(m, sp, e, v);
|
||||
}
|
||||
fn v_view_item(f: fn(&@view_item), vi: &@view_item, e: &(), v: &vt<()>) {
|
||||
fn v_view_item(f: fn(@view_item), vi: @view_item, e: (), v: vt<()>) {
|
||||
f(vi);
|
||||
visit_view_item(vi, e, v);
|
||||
}
|
||||
fn v_native_item(f: fn(&@native_item), ni: &@native_item, e: &(),
|
||||
v: &vt<()>) {
|
||||
fn v_native_item(f: fn(@native_item), ni: @native_item, e: (),
|
||||
v: vt<()>) {
|
||||
f(ni);
|
||||
visit_native_item(ni, e, v);
|
||||
}
|
||||
fn v_item(f: fn(&@item), i: &@item, e: &(), v: &vt<()>) {
|
||||
fn v_item(f: fn(@item), i: @item, e: (), v: vt<()>) {
|
||||
f(i);
|
||||
visit_item(i, e, v);
|
||||
}
|
||||
fn v_local(f: fn(&@local), l: &@local, e: &(), v: &vt<()>) {
|
||||
fn v_local(f: fn(@local), l: @local, e: (), v: vt<()>) {
|
||||
f(l);
|
||||
visit_local(l, e, v);
|
||||
}
|
||||
fn v_block(f: fn(&ast::blk), bl: &ast::blk, e: &(), v: &vt<()>) {
|
||||
fn v_block(f: fn(ast::blk), bl: ast::blk, e: (), v: vt<()>) {
|
||||
f(bl);
|
||||
visit_block(bl, e, v);
|
||||
}
|
||||
fn v_stmt(f: fn(&@stmt), st: &@stmt, e: &(), v: &vt<()>) {
|
||||
fn v_stmt(f: fn(@stmt), st: @stmt, e: (), v: vt<()>) {
|
||||
f(st);
|
||||
visit_stmt(st, e, v);
|
||||
}
|
||||
fn v_arm(f: fn(&arm), a: &arm, e: &(), v: &vt<()>) {
|
||||
fn v_arm(f: fn(arm), a: arm, e: (), v: vt<()>) {
|
||||
f(a);
|
||||
visit_arm(a, e, v);
|
||||
}
|
||||
fn v_pat(f: fn(&@pat), p: &@pat, e: &(), v: &vt<()>) {
|
||||
fn v_pat(f: fn(@pat), p: @pat, e: (), v: vt<()>) {
|
||||
f(p);
|
||||
visit_pat(p, e, v);
|
||||
}
|
||||
fn v_decl(f: fn(&@decl), d: &@decl, e: &(), v: &vt<()>) {
|
||||
fn v_decl(f: fn(@decl), d: @decl, e: (), v: vt<()>) {
|
||||
f(d);
|
||||
visit_decl(d, e, v);
|
||||
}
|
||||
fn v_expr(f: fn(&@expr), ex: &@expr, e: &(), v: &vt<()>) {
|
||||
fn v_expr(f: fn(@expr), ex: @expr, e: (), v: vt<()>) {
|
||||
f(ex);
|
||||
visit_expr(ex, e, v);
|
||||
}
|
||||
fn v_ty(f: fn(&@ty), ty: &@ty, e: &(), v: &vt<()>) {
|
||||
fn v_ty(f: fn(@ty), ty: @ty, e: (), v: vt<()>) {
|
||||
f(ty);
|
||||
visit_ty(ty, e, v);
|
||||
}
|
||||
fn v_constr(f: fn(&path, &span, node_id), pt: &path, sp: &span,
|
||||
id: node_id, e: &(), v: &vt<()>) {
|
||||
fn v_constr(f: fn(path, span, node_id), pt: path, sp: span, id: node_id,
|
||||
e: (), v: vt<()>) {
|
||||
f(pt, sp, id);
|
||||
visit_constr(pt, sp, id, e, v);
|
||||
}
|
||||
fn v_fn(f: fn(&_fn, &[ty_param], &span, &fn_ident, node_id), ff: &_fn,
|
||||
tps: &[ty_param], sp: &span, ident: &fn_ident, id: node_id,
|
||||
e: &(), v: &vt<()>) {
|
||||
fn v_fn(f: fn(_fn, [ty_param], span, fn_ident, node_id), ff: _fn,
|
||||
tps: [ty_param], sp: span, ident: fn_ident, id: node_id, e: (),
|
||||
v: vt<()>) {
|
||||
f(ff, tps, sp, ident, id);
|
||||
visit_fn(ff, tps, sp, ident, id, e, v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,11 +30,11 @@ import print::pp::mk_printer;
|
|||
|
||||
type flag = hashmap<str, ()>;
|
||||
|
||||
fn def_eq(a: &ast::def_id, b: &ast::def_id) -> bool {
|
||||
fn def_eq(a: ast::def_id, b: ast::def_id) -> bool {
|
||||
ret a.crate == b.crate && a.node == b.node;
|
||||
}
|
||||
|
||||
fn hash_def(d: &ast::def_id) -> uint {
|
||||
fn hash_def(d: ast::def_id) -> uint {
|
||||
let h = 5381u;
|
||||
h = (h << 5u) + h ^ (d.crate as uint);
|
||||
h = (h << 5u) + h ^ (d.node as uint);
|
||||
|
|
@ -47,43 +47,43 @@ fn new_def_hash<@V>() -> std::map::hashmap<ast::def_id, V> {
|
|||
ret std::map::mk_hashmap::<ast::def_id, V>(hasher, eqer);
|
||||
}
|
||||
|
||||
fn field_expr(f: &ast::field) -> @ast::expr { ret f.node.expr; }
|
||||
fn field_expr(f: ast::field) -> @ast::expr { ret f.node.expr; }
|
||||
|
||||
fn field_exprs(fields: &[ast::field]) -> [@ast::expr] {
|
||||
fn field_exprs(fields: [ast::field]) -> [@ast::expr] {
|
||||
let es = [];
|
||||
for f: ast::field in fields { es += [f.node.expr]; }
|
||||
ret es;
|
||||
}
|
||||
|
||||
fn log_expr(e: &ast::expr) { log print::pprust::expr_to_str(@e); }
|
||||
fn log_expr(e: ast::expr) { log print::pprust::expr_to_str(@e); }
|
||||
|
||||
fn log_expr_err(e: &ast::expr) { log_err print::pprust::expr_to_str(@e); }
|
||||
fn log_expr_err(e: ast::expr) { log_err print::pprust::expr_to_str(@e); }
|
||||
|
||||
fn log_ty_err(t: &@ty) { log_err print::pprust::ty_to_str(t); }
|
||||
fn log_ty_err(t: @ty) { log_err print::pprust::ty_to_str(t); }
|
||||
|
||||
fn log_pat_err(p: &@pat) { log_err print::pprust::pat_to_str(p); }
|
||||
fn log_pat_err(p: @pat) { log_err print::pprust::pat_to_str(p); }
|
||||
|
||||
fn log_block(b: &ast::blk) { log print::pprust::block_to_str(b); }
|
||||
fn log_block(b: ast::blk) { log print::pprust::block_to_str(b); }
|
||||
|
||||
fn log_block_err(b: &ast::blk) { log_err print::pprust::block_to_str(b); }
|
||||
fn log_block_err(b: ast::blk) { log_err print::pprust::block_to_str(b); }
|
||||
|
||||
fn log_item_err(i: &@ast::item) { log_err print::pprust::item_to_str(i); }
|
||||
fn log_item_err(i: @ast::item) { log_err print::pprust::item_to_str(i); }
|
||||
|
||||
fn log_fn(f: &ast::_fn, name: &ast::ident, params: &[ast::ty_param]) {
|
||||
fn log_fn(f: ast::_fn, name: ast::ident, params: [ast::ty_param]) {
|
||||
log print::pprust::fun_to_str(f, name, params);
|
||||
}
|
||||
|
||||
fn log_fn_err(f: &ast::_fn, name: &ast::ident, params: &[ast::ty_param]) {
|
||||
fn log_fn_err(f: ast::_fn, name: ast::ident, params: [ast::ty_param]) {
|
||||
log_err print::pprust::fun_to_str(f, name, params);
|
||||
}
|
||||
|
||||
fn log_stmt(st: &ast::stmt) { log print::pprust::stmt_to_str(st); }
|
||||
fn log_stmt(st: ast::stmt) { log print::pprust::stmt_to_str(st); }
|
||||
|
||||
fn log_stmt_err(st: &ast::stmt) { log_err print::pprust::stmt_to_str(st); }
|
||||
fn log_stmt_err(st: ast::stmt) { log_err print::pprust::stmt_to_str(st); }
|
||||
|
||||
fn has_nonlocal_exits(b: &ast::blk) -> bool {
|
||||
fn has_nonlocal_exits(b: ast::blk) -> bool {
|
||||
let has_exits = @mutable false;
|
||||
fn visit_expr(flag: @mutable bool, e: &@ast::expr) {
|
||||
fn visit_expr(flag: @mutable bool, e: @ast::expr) {
|
||||
alt e.node {
|
||||
ast::expr_break. { *flag = true; }
|
||||
ast::expr_cont. { *flag = true; }
|
||||
|
|
@ -97,11 +97,11 @@ fn has_nonlocal_exits(b: &ast::blk) -> bool {
|
|||
ret *has_exits;
|
||||
}
|
||||
|
||||
fn local_rhs_span(l: &@ast::local, def: &span) -> span {
|
||||
fn local_rhs_span(l: @ast::local, def: span) -> span {
|
||||
alt l.node.init { some(i) { ret i.expr.span; } _ { ret def; } }
|
||||
}
|
||||
|
||||
fn lit_eq(l: &@ast::lit, m: &@ast::lit) -> bool {
|
||||
fn lit_eq(l: @ast::lit, m: @ast::lit) -> bool {
|
||||
alt l.node {
|
||||
ast::lit_str(s) {
|
||||
alt m.node { ast::lit_str(t) { ret s == t } _ { ret false; } }
|
||||
|
|
@ -150,7 +150,7 @@ fn call_kind_str(c: call_kind) -> str {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_main_name(path: &[ast::ident]) -> bool {
|
||||
fn is_main_name(path: [ast::ident]) -> bool {
|
||||
str::eq(option::get(std::vec::last(path)), "main")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import syntax::ast;
|
|||
import middle::ast_map;
|
||||
import metadata::csearch;
|
||||
|
||||
fn mode_str(m: &ty::mode) -> str {
|
||||
fn mode_str(m: ty::mode) -> str {
|
||||
alt m {
|
||||
ast::by_ref. { "" }
|
||||
ast::by_mut_ref. { "&" }
|
||||
|
|
@ -29,15 +29,15 @@ fn mode_str(m: &ty::mode) -> str {
|
|||
}
|
||||
}
|
||||
|
||||
fn mode_str_1(m: &ty::mode) -> str {
|
||||
fn mode_str_1(m: ty::mode) -> str {
|
||||
alt m { ast::by_ref. { "ref" } _ { mode_str(m) } }
|
||||
}
|
||||
|
||||
fn fn_ident_to_string(id: ast::node_id, i: &ast::fn_ident) -> str {
|
||||
fn fn_ident_to_string(id: ast::node_id, i: ast::fn_ident) -> str {
|
||||
ret alt i { none. { "anon" + int::str(id) } some(s) { s } };
|
||||
}
|
||||
|
||||
fn get_id_ident(cx: &ctxt, id: ast::def_id) -> str {
|
||||
fn get_id_ident(cx: ctxt, id: ast::def_id) -> str {
|
||||
if id.crate != ast::local_crate {
|
||||
alt cx.ext_map.find(id) {
|
||||
some(j) { str::connect(j, "::") }
|
||||
|
|
@ -54,15 +54,15 @@ fn get_id_ident(cx: &ctxt, id: ast::def_id) -> str {
|
|||
}
|
||||
}
|
||||
|
||||
fn ty_to_str(cx: &ctxt, typ: &t) -> str {
|
||||
fn fn_input_to_str(cx: &ctxt, input: &{mode: middle::ty::mode, ty: t}) ->
|
||||
fn ty_to_str(cx: ctxt, typ: t) -> str {
|
||||
fn fn_input_to_str(cx: ctxt, input: {mode: middle::ty::mode, ty: t}) ->
|
||||
str {
|
||||
let s = mode_str(input.mode);
|
||||
ret s + ty_to_str(cx, input.ty);
|
||||
}
|
||||
fn fn_to_str(cx: &ctxt, proto: ast::proto, ident: option::t<ast::ident>,
|
||||
inputs: &[arg], output: t, cf: ast::controlflow,
|
||||
constrs: &[@constr]) -> str {
|
||||
fn fn_to_str(cx: ctxt, proto: ast::proto, ident: option::t<ast::ident>,
|
||||
inputs: [arg], output: t, cf: ast::controlflow,
|
||||
constrs: [@constr]) -> str {
|
||||
let s = proto_to_str(proto);
|
||||
alt ident { some(i) { s += " "; s += i; } _ { } }
|
||||
s += "(";
|
||||
|
|
@ -79,14 +79,14 @@ fn ty_to_str(cx: &ctxt, typ: &t) -> str {
|
|||
s += constrs_str(constrs);
|
||||
ret s;
|
||||
}
|
||||
fn method_to_str(cx: &ctxt, m: &method) -> str {
|
||||
fn method_to_str(cx: ctxt, m: method) -> str {
|
||||
ret fn_to_str(cx, m.proto, some::<ast::ident>(m.ident), m.inputs,
|
||||
m.output, m.cf, m.constrs) + ";";
|
||||
}
|
||||
fn field_to_str(cx: &ctxt, f: &field) -> str {
|
||||
fn field_to_str(cx: ctxt, f: field) -> str {
|
||||
ret f.ident + ": " + mt_to_str(cx, f.mt);
|
||||
}
|
||||
fn mt_to_str(cx: &ctxt, m: &mt) -> str {
|
||||
fn mt_to_str(cx: ctxt, m: mt) -> str {
|
||||
let mstr;
|
||||
alt m.mut {
|
||||
ast::mut. { mstr = "mutable "; }
|
||||
|
|
@ -151,18 +151,18 @@ fn ty_to_str(cx: &ctxt, typ: &t) -> str {
|
|||
}
|
||||
}
|
||||
|
||||
fn ty_to_short_str(cx: &ctxt, typ: t) -> str {
|
||||
fn ty_to_short_str(cx: ctxt, typ: t) -> str {
|
||||
let s = encoder::encoded_ty(cx, typ);
|
||||
if str::byte_len(s) >= 32u { s = str::substr(s, 0u, 32u); }
|
||||
ret s;
|
||||
}
|
||||
|
||||
fn constr_to_str(c: &@constr) -> str {
|
||||
fn constr_to_str(c: @constr) -> str {
|
||||
ret path_to_str(c.node.path) +
|
||||
pprust::constr_args_to_str(pprust::uint_to_str, c.node.args);
|
||||
}
|
||||
|
||||
fn constrs_str(constrs: &[@constr]) -> str {
|
||||
fn constrs_str(constrs: [@constr]) -> str {
|
||||
let s = "";
|
||||
let colon = true;
|
||||
for c: @constr in constrs {
|
||||
|
|
@ -172,7 +172,7 @@ fn constrs_str(constrs: &[@constr]) -> str {
|
|||
ret s;
|
||||
}
|
||||
|
||||
fn ty_constr_to_str<Q>(c: &@ast::spanned<ast::constr_general_<ast::path, Q>>)
|
||||
fn ty_constr_to_str<Q>(c: @ast::spanned<ast::constr_general_<ast::path, Q>>)
|
||||
-> str {
|
||||
ret path_to_str(c.node.path) +
|
||||
constr_args_to_str::<ast::path>(path_to_str, c.node.args);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue