}
pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &input)
- -> @ast::Crate {
- time(sess.time_passes(), ~"parsing", || {
+ -> ast::Crate {
+ time(sess.time_passes(), ~"parsing", (), |_| {
match *input {
file_input(ref file) => {
parse::parse_crate_from_file(&(*file), cfg.clone(), sess.parse_sess)
/// standard library and prelude.
pub fn phase_2_configure_and_expand(sess: Session,
cfg: ast::CrateConfig,
- mut crate: @ast::Crate) -> @ast::Crate {
+ mut crate: ast::Crate) -> ast::Crate {
let time_passes = sess.time_passes();
*sess.building_library = session::building_library(sess.opts.crate_type,
- crate, sess.opts.test);
+ &crate, sess.opts.test);
// strip before expansion to allow macros to depend on
// mod bar { macro_rules! baz!(() => {{}}) }
//
// baz! should not use this definition unless foo is enabled.
- crate = time(time_passes, ~"std macros injection", ||
+ crate = time(time_passes, ~"std macros injection", crate, |crate|
syntax::ext::expand::inject_std_macros(sess.parse_sess,
cfg.clone(),
crate));
- crate = time(time_passes, ~"configuration 1", ||
+ crate = time(time_passes, ~"configuration 1", crate, |crate|
front::config::strip_unconfigured_items(crate));
- crate = time(time_passes, ~"expansion", ||
+ crate = time(time_passes, ~"expansion", crate, |crate|
syntax::ext::expand::expand_crate(sess.parse_sess, cfg.clone(),
crate));
// strip again, in case expansion added anything with a #[cfg].
- crate = time(time_passes, ~"configuration 2", ||
+ crate = time(time_passes, ~"configuration 2", crate, |crate|
front::config::strip_unconfigured_items(crate));
- crate = time(time_passes, ~"maybe building test harness", ||
+ crate = time(time_passes, ~"maybe building test harness", crate, |crate|
front::test::modify_for_testing(sess, crate));
- crate = time(time_passes, ~"std injection", ||
+ crate = time(time_passes, ~"std injection", crate, |crate|
front::std_inject::maybe_inject_libstd_ref(sess, crate));
- crate = time(time_passes, ~"assigning node ids", ||
+ crate = time(time_passes, ~"assigning node ids", crate, |crate|
front::assign_node_ids::assign_node_ids(sess, crate));
return crate;
/// miscellaneous analysis passes on the crate. Return various
/// structures carrying the results of the analysis.
pub fn phase_3_run_analysis_passes(sess: Session,
- crate: @ast::Crate) -> CrateAnalysis {
+ crate: &ast::Crate) -> CrateAnalysis {
let time_passes = sess.time_passes();
- let ast_map = time(time_passes, ~"ast indexing", ||
+ let ast_map = time(time_passes, ~"ast indexing", (), |_|
syntax::ast_map::map_crate(sess.diagnostic(), crate));
- time(time_passes, ~"external crate/lib resolution", ||
+ time(time_passes, ~"external crate/lib resolution", (), |_|
creader::read_crates(sess.diagnostic(), crate, sess.cstore,
sess.filesearch,
session::sess_os_to_meta_os(sess.targ_cfg.os),
sess.opts.is_static,
token::get_ident_interner()));
- let lang_items = time(time_passes, ~"language item collection", ||
+ let lang_items = time(time_passes, ~"language item collection", (), |_|
middle::lang_items::collect_language_items(crate, sess));
let middle::resolve::CrateMap {
exp_map2: exp_map2,
trait_map: trait_map
} =
- time(time_passes, ~"resolution", ||
+ time(time_passes, ~"resolution", (), |_|
middle::resolve::resolve_crate(sess, lang_items, crate));
- time(time_passes, ~"looking for entry point",
- || middle::entry::find_entry_point(sess, crate, ast_map));
+ time(time_passes, ~"looking for entry point", (),
+ |_| middle::entry::find_entry_point(sess, crate, ast_map));
- let freevars = time(time_passes, ~"freevar finding", ||
+ let freevars = time(time_passes, ~"freevar finding", (), |_|
freevars::annotate_freevars(def_map, crate));
- let region_map = time(time_passes, ~"region resolution", ||
+ let region_map = time(time_passes, ~"region resolution", (), |_|
middle::region::resolve_crate(sess, def_map, crate));
- let rp_set = time(time_passes, ~"region parameterization inference", ||
+ let rp_set = time(time_passes, ~"region parameterization inference", (), |_|
middle::region::determine_rp_in_crate(sess, ast_map, def_map, crate));
let ty_cx = ty::mk_ctxt(sess, def_map, ast_map, freevars,
ty_cx, trait_map, crate);
// These next two const passes can probably be merged
- time(time_passes, ~"const marking", ||
+ time(time_passes, ~"const marking", (), |_|
middle::const_eval::process_crate(crate, ty_cx));
- time(time_passes, ~"const checking", ||
+ time(time_passes, ~"const checking", (), |_|
middle::check_const::check_crate(sess, crate, ast_map, def_map,
method_map, ty_cx));
let exported_items =
- time(time_passes, ~"privacy checking", ||
+ time(time_passes, ~"privacy checking", (), |_|
middle::privacy::check_crate(ty_cx, &method_map, &exp_map2, crate));
- time(time_passes, ~"effect checking", ||
+ time(time_passes, ~"effect checking", (), |_|
middle::effect::check_crate(ty_cx, method_map, crate));
- time(time_passes, ~"loop checking", ||
+ time(time_passes, ~"loop checking", (), |_|
middle::check_loop::check_crate(ty_cx, crate));
- time(time_passes, ~"stack checking", ||
+ time(time_passes, ~"stack checking", (), |_|
middle::stack_check::stack_check_crate(ty_cx, crate));
let middle::moves::MoveMaps {moves_map, moved_variables_set,
capture_map} =
- time(time_passes, ~"compute moves", ||
+ time(time_passes, ~"compute moves", (), |_|
middle::moves::compute_moves(ty_cx, method_map, crate));
- time(time_passes, ~"match checking", ||
+ time(time_passes, ~"match checking", (), |_|
middle::check_match::check_crate(ty_cx, method_map,
moves_map, crate));
- time(time_passes, ~"liveness checking", ||
+ time(time_passes, ~"liveness checking", (), |_|
middle::liveness::check_crate(ty_cx, method_map,
capture_map, crate));
let (root_map, write_guard_map) =
- time(time_passes, ~"borrow checking", ||
+ time(time_passes, ~"borrow checking", (), |_|
middle::borrowck::check_crate(ty_cx, method_map,
moves_map, moved_variables_set,
capture_map, crate));
- time(time_passes, ~"kind checking", ||
+ time(time_passes, ~"kind checking", (), |_|
kind::check_crate(ty_cx, method_map, crate));
let reachable_map =
- time(time_passes, ~"reachability checking", ||
+ time(time_passes, ~"reachability checking", (), |_|
reachable::find_reachable(ty_cx, method_map, crate));
- time(time_passes, ~"lint checking", ||
+ time(time_passes, ~"lint checking", (), |_|
lint::check_crate(ty_cx, crate));
CrateAnalysis {
/// Run the translation phase to LLVM, after which the AST and analysis can
/// be discarded.
pub fn phase_4_translate_to_llvm(sess: Session,
- crate: @ast::Crate,
+ crate: ast::Crate,
analysis: &CrateAnalysis,
outputs: &OutputFilenames) -> CrateTranslation {
- time(sess.time_passes(), ~"translation", ||
+ time(sess.time_passes(), ~"translation", crate, |crate|
trans::base::trans_crate(sess, crate, analysis,
&outputs.obj_filename))
}
let output_type = link::output_type_assembly;
let asm_filename = outputs.obj_filename.with_filetype("s");
- time(sess.time_passes(), ~"LLVM passes", ||
+ time(sess.time_passes(), ~"LLVM passes", (), |_|
link::write::run_passes(sess,
trans.context,
trans.module,
os::remove_file(&asm_filename);
}
} else {
- time(sess.time_passes(), ~"LLVM passes", ||
+ time(sess.time_passes(), ~"LLVM passes", (), |_|
link::write::run_passes(sess,
trans.context,
trans.module,
pub fn phase_6_link_output(sess: Session,
trans: &CrateTranslation,
outputs: &OutputFilenames) {
- time(sess.time_passes(), ~"linking", ||
+ time(sess.time_passes(), ~"linking", (), |_|
link::link_binary(sess,
&outputs.obj_filename,
&outputs.out_filename,
if stop_after_phase_1(sess) { return; }
phase_2_configure_and_expand(sess, cfg, crate)
};
- let analysis = phase_3_run_analysis_passes(sess, expanded_crate);
+ let analysis = phase_3_run_analysis_passes(sess, &expanded_crate);
if stop_after_phase_3(sess) { return; }
let outputs = build_output_filenames(input, outdir, output, [], sess);
let trans = phase_4_translate_to_llvm(sess, expanded_crate,
} as @pprust::pp_ann
}
PpmTyped => {
- let analysis = phase_3_run_analysis_passes(sess, crate);
+ let analysis = phase_3_run_analysis_passes(sess, &crate);
@TypedAnnotation {
analysis: analysis
} as @pprust::pp_ann
pprust::print_crate(sess.codemap,
token::get_ident_interner(),
sess.span_diagnostic,
- crate,
+ &crate,
source_name(input),
rdr,
io::stdout(),
}
}
-pub fn assign_node_ids(sess: Session, crate: @ast::Crate) -> @ast::Crate {
+pub fn assign_node_ids(sess: Session, crate: ast::Crate) -> ast::Crate {
let fold = NodeIdAssigner {
sess: sess,
};
- @fold.fold_crate(crate)
+ fold.fold_crate(crate)
}
// Support conditional compilation by transforming the AST, stripping out
// any items that do not belong in the current configuration
-pub fn strip_unconfigured_items(crate: @ast::Crate) -> @ast::Crate {
+pub fn strip_unconfigured_items(crate: ast::Crate) -> ast::Crate {
+ let config = crate.config.clone();
do strip_items(crate) |attrs| {
- in_cfg(crate.config, attrs)
+ in_cfg(config, attrs)
}
}
}
}
-pub fn strip_items(crate: &ast::Crate,
+pub fn strip_items(crate: ast::Crate,
in_cfg: &fn(attrs: &[ast::Attribute]) -> bool)
- -> @ast::Crate {
+ -> ast::Crate {
let ctxt = Context {
in_cfg: in_cfg,
};
- @ctxt.fold_crate(crate)
+ ctxt.fold_crate(crate)
}
fn filter_item(cx: &Context, item: @ast::item) -> Option<@ast::item> {
static STD_VERSION: &'static str = "0.9-pre";
-pub fn maybe_inject_libstd_ref(sess: Session, crate: @ast::Crate)
- -> @ast::Crate {
- if use_std(crate) {
+pub fn maybe_inject_libstd_ref(sess: Session, crate: ast::Crate)
+ -> ast::Crate {
+ if use_std(&crate) {
inject_libstd_ref(sess, crate)
} else {
crate
}
impl fold::ast_fold for StandardLibraryInjector {
- fn fold_crate(&self, crate: &ast::Crate) -> ast::Crate {
+ fn fold_crate(&self, crate: ast::Crate) -> ast::Crate {
let version = STD_VERSION.to_managed();
let vi1 = ast::view_item {
node: ast::view_item_extern_mod(self.sess.ident_of("std"),
new_module = self.fold_mod(&new_module);
}
- // FIXME #2543: Bad copy.
ast::Crate {
module: new_module,
- ..(*crate).clone()
+ ..crate
}
}
}
}
-fn inject_libstd_ref(sess: Session, crate: &ast::Crate) -> @ast::Crate {
+fn inject_libstd_ref(sess: Session, crate: ast::Crate) -> ast::Crate {
let fold = StandardLibraryInjector {
sess: sess,
};
- @fold.fold_crate(crate)
+ fold.fold_crate(crate)
}
struct TestCtxt {
sess: session::Session,
- crate: @ast::Crate,
path: ~[ast::Ident],
ext_cx: @ExtCtxt,
- testfns: ~[Test]
+ testfns: ~[Test],
+ is_extra: bool,
+ config: ast::CrateConfig,
}
// Traverse the crate, collecting all the test functions, eliding any
// existing main functions, and synthesizing a main test harness
pub fn modify_for_testing(sess: session::Session,
- crate: @ast::Crate)
- -> @ast::Crate {
+ crate: ast::Crate) -> ast::Crate {
// We generate the test harness when building in the 'test'
// configuration, either with the '--test' or '--cfg test'
// command line options.
}
impl fold::ast_fold for TestHarnessGenerator {
- fn fold_crate(&self, c: &ast::Crate) -> ast::Crate {
+ fn fold_crate(&self, c: ast::Crate) -> ast::Crate {
let folded = fold::noop_fold_crate(c, self);
// Add a special __test module to the crate that will contain code
}
}
-fn generate_test_harness(sess: session::Session, crate: @ast::Crate)
- -> @ast::Crate {
+fn generate_test_harness(sess: session::Session, crate: ast::Crate)
+ -> ast::Crate {
let cx: @mut TestCtxt = @mut TestCtxt {
sess: sess,
- crate: crate,
ext_cx: ExtCtxt::new(sess.parse_sess, sess.opts.cfg.clone()),
path: ~[],
- testfns: ~[]
+ testfns: ~[],
+ is_extra: is_extra(&crate),
+ config: crate.config.clone(),
};
let ext_cx = cx.ext_cx;
let fold = TestHarnessGenerator {
cx: cx
};
- let res = @fold.fold_crate(&*crate);
+ let res = fold.fold_crate(crate);
ext_cx.bt_pop();
return res;
}
-fn strip_test_functions(crate: &ast::Crate) -> @ast::Crate {
+fn strip_test_functions(crate: ast::Crate) -> ast::Crate {
// When not compiling with --test we should not compile the
// #[test] functions
do config::strip_items(crate) |attrs| {
do i.attrs.iter().any |attr| {
// check ignore(cfg(foo, bar))
"ignore" == attr.name() && match attr.meta_item_list() {
- Some(ref cfgs) => attr::test_cfg(cx.crate.config, cfgs.iter().map(|x| *x)),
+ Some(ref cfgs) => attr::test_cfg(cx.config, cfgs.iter().map(|x| *x)),
None => true
}
}
fn mk_std(cx: &TestCtxt) -> ast::view_item {
let id_extra = cx.sess.ident_of("extra");
- let vi = if is_extra(cx) {
+ let vi = if cx.is_extra {
ast::view_item_use(
~[@nospan(ast::view_path_simple(id_extra,
path_node(~[id_extra]),
)).unwrap()
}
-fn is_extra(cx: &TestCtxt) -> bool {
- let items = attr::find_linkage_metas(cx.crate.attrs);
+fn is_extra(crate: &ast::Crate) -> bool {
+ let items = attr::find_linkage_metas(crate.attrs);
match attr::last_meta_item_value_str_by_name(items, "name") {
Some(s) if "extra" == s => true,
_ => false
use syntax::visit;
use syntax::visit::Visitor;
-use std::str;
use std::uint;
use std::hashmap::{HashMap, HashSet};
use std::util;
pub fn Resolver(session: Session,
lang_items: LanguageItems,
- crate: @Crate)
- -> Resolver {
+ crate_span: Span) -> Resolver {
let graph_root = @mut NameBindings();
graph_root.define_module(Public,
Some(DefId { crate: 0, node: 0 }),
NormalModuleKind,
false,
- crate.span);
+ crate_span);
let current_module = graph_root.get_module();
let this = Resolver {
session: @session,
lang_items: lang_items,
- crate: crate,
// The outermost module has def ID 0; this is not reflected in the
// AST.
pub struct Resolver {
session: @Session,
lang_items: LanguageItems,
- crate: @Crate,
intr: @ident_interner,
impl Resolver {
/// The main name resolution procedure.
- pub fn resolve(&mut self) {
- self.build_reduced_graph();
+ pub fn resolve(&mut self, crate: &ast::Crate) {
+ self.build_reduced_graph(crate);
self.session.abort_if_errors();
self.resolve_imports();
self.record_exports();
self.session.abort_if_errors();
- self.resolve_crate();
+ self.resolve_crate(crate);
self.session.abort_if_errors();
- self.check_for_unused_imports();
+ self.check_for_unused_imports(crate);
}
//
//
/// Constructs the reduced graph for the entire crate.
- pub fn build_reduced_graph(&mut self) {
+ pub fn build_reduced_graph(&mut self, crate: &ast::Crate) {
let initial_parent =
ModuleReducedGraphParent(self.graph_root.get_module());
let mut visitor = BuildReducedGraphVisitor { resolver: self, };
- visit::walk_crate(&mut visitor, self.crate, initial_parent);
+ visit::walk_crate(&mut visitor, crate, initial_parent);
}
/// Returns the current module tracked by the reduced graph parent.
return None;
}
- pub fn resolve_crate(&mut self) {
+ pub fn resolve_crate(&mut self, crate: &ast::Crate) {
debug!("(resolving crate) starting");
- visit::walk_crate(self, self.crate, ());
+ visit::walk_crate(self, crate, ());
}
pub fn resolve_item(&mut self, item: @item) {
}
}
- pub fn name_exists_in_scope_struct(&mut self, name: &str) -> bool {
- let this = &mut *self;
-
- let mut i = this.type_ribs.len();
- while i != 0 {
- i -= 1;
- match this.type_ribs[i].kind {
- MethodRibKind(node_id, _) =>
- for item in this.crate.module.items.iter() {
- if item.id == node_id {
- match item.node {
- item_struct(class_def, _) => {
- for field in class_def.fields.iter() {
- match field.node.kind {
- unnamed_field => {},
- named_field(ident, _) => {
- if str::eq_slice(this.session.str_of(ident),
- name) {
- return true
- }
- }
- }
- }
- }
- _ => {}
- }
- }
- },
- _ => {}
- }
- }
- return false;
- }
-
pub fn resolve_expr(&mut self, expr: @Expr) {
// First, record candidate traits for this expression if it could
// result in the invocation of a method call.
}
None => {
let wrong_name = self.path_idents_to_str(path);
- if self.name_exists_in_scope_struct(wrong_name) {
- self.resolve_error(expr.span,
- fmt!("unresolved name `%s`. \
- Did you mean `self.%s`?",
- wrong_name,
- wrong_name));
- }
- else {
- // Be helpful if the name refers to a struct
- // (The pattern matching def_tys where the id is in self.structs
- // matches on regular structs while excluding tuple- and enum-like
- // structs, which wouldn't result in this error.)
- match self.with_no_errors(|this|
- this.resolve_path(expr.id, path, TypeNS, false)) {
- Some(DefTy(struct_id))
- if self.structs.contains(&struct_id) => {
- self.resolve_error(expr.span,
- fmt!("`%s` is a structure name, but this expression \
- uses it like a function name", wrong_name));
-
- self.session.span_note(expr.span, fmt!("Did you mean to write: \
- `%s { /* fields */ }`?", wrong_name));
+ // Be helpful if the name refers to a struct
+ // (The pattern matching def_tys where the id is in self.structs
+ // matches on regular structs while excluding tuple- and enum-like
+ // structs, which wouldn't result in this error.)
+ match self.with_no_errors(|this|
+ this.resolve_path(expr.id, path, TypeNS, false)) {
+ Some(DefTy(struct_id))
+ if self.structs.contains(&struct_id) => {
+ self.resolve_error(expr.span,
+ fmt!("`%s` is a structure name, but this expression \
+ uses it like a function name", wrong_name));
+
+ self.session.span_note(expr.span, fmt!("Did you mean to write: \
+ `%s { /* fields */ }`?", wrong_name));
- }
- _ =>
- // limit search to 5 to reduce the number
- // of stupid suggestions
- match self.find_best_match_for_name(wrong_name, 5) {
- Some(m) => {
- self.resolve_error(expr.span,
- fmt!("unresolved name `%s`. \
- Did you mean `%s`?",
- wrong_name, m));
- }
- None => {
- self.resolve_error(expr.span,
- fmt!("unresolved name `%s`.",
- wrong_name));
- }
- }
}
+ _ =>
+ // limit search to 5 to reduce the number
+ // of stupid suggestions
+ match self.find_best_match_for_name(wrong_name, 5) {
+ Some(m) => {
+ self.resolve_error(expr.span,
+ fmt!("unresolved name `%s`. \
+ Did you mean `%s`?",
+ wrong_name, m));
+ }
+ None => {
+ self.resolve_error(expr.span,
+ fmt!("unresolved name `%s`.",
+ wrong_name));
+ }
+ }
}
}
}
// resolve data structures.
//
- pub fn check_for_unused_imports(&self) {
+ pub fn check_for_unused_imports(&self, crate: &ast::Crate) {
let mut visitor = UnusedImportCheckVisitor{ resolver: self };
- visit::walk_crate(&mut visitor, self.crate, ());
+ visit::walk_crate(&mut visitor, crate, ());
}
pub fn check_for_item_unused_imports(&self, vi: &view_item) {
/// Entry point to crate resolution.
pub fn resolve_crate(session: Session,
lang_items: LanguageItems,
- crate: @Crate)
+ crate: &Crate)
-> CrateMap {
- let mut resolver = Resolver(session, lang_items, crate);
- resolver.resolve();
+ let mut resolver = Resolver(session, lang_items, crate.span);
+ resolver.resolve(crate);
CrateMap {
def_map: resolver.def_map,
exp_map2: resolver.export_map2,
}
pub fn trans_crate(sess: session::Session,
- crate: &ast::Crate,
+ crate: ast::Crate,
analysis: &CrateAnalysis,
output: &Path) -> CrateTranslation {
// Before we touch LLVM, make sure that multithreading is enabled.
if unsafe { !llvm::LLVMRustStartMultithreading() } {
- //sess.bug("couldn't enable multi-threaded LLVM");
+ sess.bug("couldn't enable multi-threaded LLVM");
}
let mut symbol_hasher = hash::default_state();
- let link_meta = link::build_link_meta(sess, crate, output, &mut symbol_hasher);
+ let link_meta = link::build_link_meta(sess, &crate, output,
+ &mut symbol_hasher);
// Append ".rc" to crate name as LLVM module identifier.
//
analysis.reachable);
if ccx.sess.opts.debuginfo {
- debuginfo::initialize(ccx, crate);
+ debuginfo::initialize(ccx, &crate);
}
{
}
// Translate the metadata.
- write_metadata(ccx, crate);
+ write_metadata(ccx, &crate);
if ccx.sess.trans_stats() {
io::println("--- trans stats ---");
println!("n_static_tydescs: {}", ccx.stats.n_static_tydescs);
tcx: tcx
};
- time(time_passes, ~"type collecting", ||
+ time(time_passes, ~"type collecting", (), |_|
collect::collect_item_types(ccx, crate));
// this ensures that later parts of type checking can assume that items
// have valid types and not error
tcx.sess.abort_if_errors();
- time(time_passes, ~"coherence checking", ||
+ time(time_passes, ~"coherence checking", (), |_|
coherence::check_coherence(ccx, crate));
- time(time_passes, ~"type checking", ||
+ time(time_passes, ~"type checking", (), |_|
check::check_item_types(ccx, crate));
check_for_entry_fn(ccx);
use std::hashmap::HashSet;
use extra;
-pub fn time<T>(do_it: bool, what: ~str, thunk: &fn() -> T) -> T {
- if !do_it { return thunk(); }
+pub fn time<T, U>(do_it: bool, what: ~str, u: U, f: &fn(U) -> T) -> T {
+ if !do_it { return f(u); }
let start = extra::time::precise_time_s();
- let rv = thunk();
+ let rv = f(u);
let end = extra::time::precise_time_s();
println!("time: {:3.3f} s\t{}", end - start, what);
rv
use clean::Clean;
pub struct DocContext {
- crate: @ast::Crate,
+ crate: ast::Crate,
tycx: middle::ty::ctxt,
sess: driver::session::Session
}
let mut crate = phase_1_parse_input(sess, cfg.clone(), &input);
crate = phase_2_configure_and_expand(sess, cfg, crate);
- let analysis = phase_3_run_analysis_passes(sess, crate);
+ let analysis = phase_3_run_analysis_passes(sess, &crate);
debug!("crate: %?", crate);
DocContext { crate: crate, tycx: analysis.ty_cx, sess: sess }
local_data::set(super::ctxtkey, ctxt);
let v = @mut RustdocVisitor::new();
- v.visit(ctxt.crate);
+ v.visit(&ctxt.crate);
v.clean()
}
let mut to_run = ~[]; // statements to run (emitted back into code)
let new_locals = @mut ~[]; // new locals being defined
let mut result = None; // resultant expression (to print via pp)
- do find_main(crate, sess) |blk| {
+ do find_main(&crate, sess) |blk| {
// Fish out all the view items, be sure to record 'extern mod' items
// differently beause they must appear before all 'use' statements
for vi in blk.view_items.iter() {
let crate = driver::phase_1_parse_input(sess, cfg.clone(), &dinput);
let expanded_crate = driver::phase_2_configure_and_expand(sess, cfg, crate);
- let analysis = driver::phase_3_run_analysis_passes(sess, expanded_crate);
+ let analysis = driver::phase_3_run_analysis_passes(sess, &expanded_crate);
// Once we're typechecked, record the types of all local variables defined
// in this input
- do find_main(crate, sess) |blk| {
+ do find_main(&expanded_crate, sess) |blk| {
program.register_new_vars(blk, analysis.ty_cx);
}
let crate = driver::phase_1_parse_input(sess, cfg.clone(), &input);
let expanded_crate = driver::phase_2_configure_and_expand(sess, cfg, crate);
- let analysis = driver::phase_3_run_analysis_passes(sess, expanded_crate);
+ let analysis = driver::phase_3_run_analysis_passes(sess, &expanded_crate);
let trans = driver::phase_4_translate_to_llvm(sess, expanded_crate, &analysis, outputs);
driver::phase_5_run_llvm_passes(sess, &trans, outputs);
//
return (program, jit::consume_engine());
- fn parse_input(sess: session::Session, input: &str) -> @ast::Crate {
+ fn parse_input(sess: session::Session, input: &str) -> ast::Crate {
let code = fmt!("fn main() {\n %s \n}", input);
let input = driver::str_input(code.to_managed());
let cfg = driver::build_configuration(sess);
driver::phase_1_parse_input(sess, cfg.clone(), &input)
}
- fn find_main(crate: @ast::Crate, sess: session::Session,
+ fn find_main(crate: &ast::Crate, sess: session::Session,
f: &fn(&ast::Block)) {
for item in crate.module.items.iter() {
match item.node {
println(fmt!("compiling %s...", src_filename));
let crate = driver::phase_1_parse_input(sess, cfg.clone(), &input);
let expanded_crate = driver::phase_2_configure_and_expand(sess, cfg, crate);
- let analysis = driver::phase_3_run_analysis_passes(sess, expanded_crate);
+ let analysis = driver::phase_3_run_analysis_passes(sess, &expanded_crate);
let trans = driver::phase_4_translate_to_llvm(sess, expanded_crate, &analysis, outputs);
driver::phase_5_run_llvm_passes(sess, &trans, outputs);
true
/// The config for compiling the custom build script
cfg: ast::CrateConfig,
/// The crate for the custom build script
- crate: @ast::Crate,
+ crate: Option<ast::Crate>,
/// Directory in which to store build output
build_dir: Path
}
input: script,
sess: sess,
cfg: cfg,
- crate: crate,
+ crate: Some(crate),
build_dir: work_dir
}
}
/// is the command to pass to it (e.g., "build", "clean", "install")
/// Returns a pair of an exit code and list of configs (obtained by
/// calling the package script's configs() function if it exists
- fn run_custom(&self, exec: &mut workcache::Exec, sysroot: &Path) -> (~[~str], ExitCode) {
+ fn run_custom(&mut self, exec: &mut workcache::Exec,
+ sysroot: &Path) -> (~[~str], ExitCode) {
let sess = self.sess;
debug!("Working directory = %s", self.build_dir.to_str());
// Collect together any user-defined commands in the package script
- let crate = util::ready_crate(sess, self.crate);
+ let crate = util::ready_crate(sess, self.crate.take_unwrap());
debug!("Building output filenames with script name %s",
driver::source_name(&driver::file_input(self.input.clone())));
let exe = self.build_dir.push(~"pkg" + util::exe_suffix());
let sub_id = pkgid.clone();
declare_package_script_dependency(prep, &*pkg_src);
do prep.exec |exec| {
- let pscript = PkgScript::parse(@sub_sysroot.clone(),
- package_script_path_clone.clone(),
- &sub_ws,
- &sub_id);
+ let mut pscript = PkgScript::parse(@sub_sysroot.clone(),
+ package_script_path_clone.clone(),
+ &sub_ws,
+ &sub_id);
pscript.run_custom(exec, &sub_sysroot)
}
struct ReadyCtx {
sess: session::Session,
- crate: @ast::Crate,
ext_cx: @ExtCtxt,
path: ~[ast::Ident],
fns: ~[ListenerFn]
/// Generate/filter main function, add the list of commands, etc.
pub fn ready_crate(sess: session::Session,
- crate: @ast::Crate) -> @ast::Crate {
+ crate: ast::Crate) -> ast::Crate {
let ctx = @mut ReadyCtx {
sess: sess,
- crate: crate,
ext_cx: ExtCtxt::new(sess.parse_sess, sess.opts.cfg.clone()),
path: ~[],
fns: ~[]
let fold = CrateSetup {
ctx: ctx,
};
- @fold.fold_crate(crate)
+ fold.fold_crate(crate)
}
pub fn compile_input(context: &BuildContext,
let mut crate = driver::phase_1_parse_input(sess, cfg.clone(), &input);
crate = driver::phase_2_configure_and_expand(sess, cfg.clone(), crate);
- find_and_install_dependencies(context, pkg_id, sess, exec, crate,
+ find_and_install_dependencies(context, pkg_id, sess, exec, &crate,
|p| {
debug!("a dependency: %s", p.to_str());
// Pass the directory containing a dependency
pkg_id.path.to_str().to_managed())];
debug!("link options: %?", link_options);
- crate = @ast::Crate {
- attrs: ~[attr::mk_attr(attr::mk_list_item(@"link", link_options))],
- .. (*crate).clone()
- }
+ crate.attrs = ~[attr::mk_attr(attr::mk_list_item(@"link", link_options))];
}
debug!("calling compile_crate_from_input, workspace = %s,
sess: session::Session,
// Returns None if one of the flags that suppresses compilation output was
// given
- crate: @ast::Crate) -> Option<Path> {
+ crate: ast::Crate) -> Option<Path> {
debug!("Calling build_output_filenames with %s, building library? %?",
out_dir.to_str(), sess.building_library);
for lib in sess.opts.addl_lib_search_paths.iter() {
debug!("an additional library: %s", lib.to_str());
}
- let analysis = driver::phase_3_run_analysis_passes(sess, crate);
+ let analysis = driver::phase_3_run_analysis_passes(sess, &crate);
if driver::stop_after_phase_3(sess) { return None; }
let translation = driver::phase_4_translate_to_llvm(sess, crate,
&analysis,
// program (ick). This should run before cfg stripping.
pub fn inject_std_macros(parse_sess: @mut parse::ParseSess,
cfg: ast::CrateConfig,
- c: @Crate)
- -> @Crate {
+ c: Crate)
+ -> Crate {
let sm = match parse_item_from_source_str(@"<std-macros>",
std_macros(),
cfg.clone(),
let injector = @Injector {
sm: sm,
} as @ast_fold;
- @injector.fold_crate(c)
+ injector.fold_crate(c)
}
struct NoOpFolder {
pub fn expand_crate(parse_sess: @mut parse::ParseSess,
cfg: ast::CrateConfig,
- c: &Crate) -> @Crate {
+ c: Crate) -> Crate {
// adding *another* layer of indirection here so that the block
// visitor can swap out one exts table for another for the duration
// of the block. The cleaner alternative would be to thread the
cx: cx,
} as @ast_fold;
- let ret = @expander.fold_crate(c);
+ let ret = expander.fold_crate(c);
parse_sess.span_diagnostic.handler().abort_if_errors();
return ret;
}
let a2_name = gensym("a2");
let renamer = new_rename_folder(ast::Ident{name:a_name,ctxt:EMPTY_CTXT},
a2_name);
- let renamed_ast = renamer.fold_crate(item_ast);
+ let renamed_ast = renamer.fold_crate(item_ast.clone());
let varrefs = @mut ~[];
visit::walk_crate(&mut new_path_finder(varrefs), &renamed_ast, ());
match varrefs {
}
}
- fn fake_print_crate(crate: @ast::Crate) {
+ fn fake_print_crate(crate: &ast::Crate) {
let s = pprust::rust_printer(std::io::stderr(),get_ident_interner());
pprust::print_crate_(s, crate);
}
- fn expand_crate_str(crate_str: @str) -> @ast::Crate {
+ fn expand_crate_str(crate_str: @str) -> ast::Crate {
let (crate_ast,ps) = string_to_crate_and_sess(crate_str);
// the cfg argument actually does matter, here...
expand_crate(ps,~[],crate_ast)
let cr = expand_crate_str(teststr.to_managed());
// find the bindings:
let bindings = @mut ~[];
- visit::walk_crate(&mut new_name_finder(bindings),cr,());
+ visit::walk_crate(&mut new_name_finder(bindings),&cr,());
// find the varrefs:
let varrefs = @mut ~[];
- visit::walk_crate(&mut new_path_finder(varrefs),cr,());
+ visit::walk_crate(&mut new_path_finder(varrefs),&cr,());
// must be one check clause for each binding:
assert_eq!(bindings.len(),bound_connections.len());
for (binding_idx,shouldmatch) in bound_connections.iter().enumerate() {
let cr = expand_crate_str(crate_str);
// find the xx binding
let bindings = @mut ~[];
- visit::walk_crate(&mut new_name_finder(bindings), cr, ());
+ visit::walk_crate(&mut new_name_finder(bindings), &cr, ());
let cxbinds : ~[&ast::Ident] =
bindings.iter().filter(|b|{@"xx" == (ident_to_str(*b))}).collect();
let cxbind = match cxbinds {
let resolved_binding = mtwt_resolve(*cxbind);
// find all the xx varrefs:
let varrefs = @mut ~[];
- visit::walk_crate(&mut new_path_finder(varrefs), cr, ());
+ visit::walk_crate(&mut new_path_finder(varrefs), &cr, ());
// the xx binding should bind all of the xx varrefs:
for (idx,v) in varrefs.iter().filter(|p|{ p.segments.len() == 1
&& (@"xx" == (ident_to_str(&p.segments[0].identifier)))
// We may eventually want to be able to fold over type parameters, too.
pub trait ast_fold {
- fn fold_crate(&self, c: &Crate) -> Crate {
+ fn fold_crate(&self, c: Crate) -> Crate {
noop_fold_crate(c, self)
}
}
}
-pub fn noop_fold_crate<T:ast_fold>(c: &Crate, folder: &T) -> Crate {
+pub fn noop_fold_crate<T:ast_fold>(c: Crate, folder: &T) -> Crate {
let fold_meta_item = |x| fold_meta_item_(x, folder);
let fold_attribute = |x| fold_attribute_(x, folder);
input: &Path,
cfg: ast::CrateConfig,
sess: @mut ParseSess
-) -> @ast::Crate {
+) -> ast::Crate {
new_parser_from_file(sess, /*bad*/ cfg.clone(), input).parse_crate_mod()
// why is there no p.abort_if_errors here?
}
source: @str,
cfg: ast::CrateConfig,
sess: @mut ParseSess
-) -> @ast::Crate {
+) -> ast::Crate {
let p = new_parser_from_source_str(sess,
/*bad*/ cfg.clone(),
name,
// Parses a source module as a crate. This is the main
// entry point for the parser.
- pub fn parse_crate_mod(&self) -> @Crate {
+ pub fn parse_crate_mod(&self) -> Crate {
let lo = self.span.lo;
// parse the crate's inner attrs, maybe (oops) one
// of the attrs of an item:
// parse the items inside the crate:
let m = self.parse_mod_items(token::EOF, first_item_outer_attrs);
- @ast::Crate {
+ ast::Crate {
module: m,
attrs: inner,
config: self.cfg.clone(),
}
// parse a string, return a crate.
-pub fn string_to_crate (source_str : @str) -> @ast::Crate {
+pub fn string_to_crate (source_str : @str) -> ast::Crate {
do with_error_checking_parse(source_str) |p| {
p.parse_crate_mod()
}
}
// parse a string, return a crate and the ParseSess
-pub fn string_to_crate_and_sess (source_str : @str) -> (@ast::Crate,@mut ParseSess) {
+pub fn string_to_crate_and_sess (source_str : @str) -> (ast::Crate,@mut ParseSess) {
let (p,ps) = string_to_parser_and_sess(source_str);
(p.parse_crate_mod(),ps)
}