time(time_passes, "looking for entry point", (),
|_| middle::entry::find_entry_point(&sess, krate, &ast_map));
- *sess.macro_registrar_fn.borrow_mut() =
+ sess.macro_registrar_fn.set(
time(time_passes, "looking for macro registrar", (), |_|
syntax::ext::registrar::find_macro_registrar(
- sess.diagnostic(), krate));
+ sess.diagnostic(), krate)));
let freevars = time(time_passes, "freevar finding", (), |_|
freevars::annotate_freevars(def_map, krate));
// For a library crate, this is always none
entry_fn: RefCell::new(None),
entry_type: Cell::new(None),
- macro_registrar_fn: RefCell::new(None),
+ macro_registrar_fn: Cell::new(None),
default_sysroot: default_sysroot,
building_library: Cell::new(false),
local_crate_source_file: local_crate_source_file,
// For a library crate, this is always none
pub entry_fn: RefCell<Option<(NodeId, codemap::Span)>>,
pub entry_type: Cell<Option<EntryFnType>>,
- pub macro_registrar_fn: RefCell<Option<ast::DefId>>,
+ pub macro_registrar_fn: Cell<Option<ast::NodeId>>,
pub default_sysroot: Option<Path>,
pub building_library: Cell<bool>,
// The name of the root source file of the crate, in the local file system. The path is always
use back::svh::Svh;
use driver::{driver, session};
use driver::session::Session;
-use metadata::csearch;
use metadata::cstore;
use metadata::cstore::CStore;
use metadata::decoder;
impl<'a> CrateLoader for Loader<'a> {
fn load_crate(&mut self, krate: &ast::ViewItem) -> MacroCrate {
let info = extract_crate_info(&self.env, krate).unwrap();
- let (cnum, data, library) = resolve_crate(&mut self.env, &None,
- info.ident, &info.crate_id,
- None, true, krate.span);
+ let (_, data, library) = resolve_crate(&mut self.env, &None,
+ info.ident, &info.crate_id,
+ None, info.should_link,
+ krate.span);
let macros = decoder::get_exported_macros(data);
- let cstore = &self.env.sess.cstore;
- let registrar = csearch::get_macro_registrar_fn(cstore, cnum)
- .map(|did| csearch::get_symbol(cstore, did));
+ let registrar = decoder::get_macro_registrar_fn(data).map(|id| {
+ decoder::get_symbol(data.data.as_slice(), id)
+ });
MacroCrate {
lib: library.dylib,
macros: macros.move_iter().collect(),
pub fn get_macro_registrar_fn(cstore: &cstore::CStore,
crate_num: ast::CrateNum)
- -> Option<ast::DefId> {
+ -> Option<ast::NodeId> {
let cdata = cstore.get_crate_data(crate_num);
decoder::get_macro_registrar_fn(cdata)
}
return result;
}
-pub fn get_macro_registrar_fn(cdata: Cmd) -> Option<ast::DefId> {
+pub fn get_macro_registrar_fn(cdata: Cmd) -> Option<ast::NodeId> {
reader::maybe_get_doc(reader::Doc(cdata.data()), tag_macro_registrar_fn)
- .map(|doc| item_def_id(doc, cdata))
+ .map(|doc| FromPrimitive::from_u32(reader::doc_as_u32(doc)).unwrap())
}
pub fn get_exported_macros(cdata: Cmd) -> Vec<~str> {
}
fn encode_macro_registrar_fn(ecx: &EncodeContext, ebml_w: &mut Encoder) {
- match *ecx.tcx.sess.macro_registrar_fn.borrow() {
- Some(did) => {
- ebml_w.start_tag(tag_macro_registrar_fn);
- encode_def_id(ebml_w, did);
- ebml_w.end_tag();
- }
+ match ecx.tcx.sess.macro_registrar_fn.get() {
+ Some(id) => { ebml_w.wr_tagged_u32(tag_macro_registrar_fn, id); }
None => {}
}
}
}
pub fn find_macro_registrar(diagnostic: &diagnostic::SpanHandler,
- krate: &ast::Crate) -> Option<ast::DefId> {
+ krate: &ast::Crate) -> Option<ast::NodeId> {
let mut ctx = MacroRegistrarContext { registrars: Vec::new() };
visit::walk_crate(&mut ctx, krate, ());
0 => None,
1 => {
let (node_id, _) = ctx.registrars.pop().unwrap();
- Some(ast::DefId {
- krate: ast::LOCAL_CRATE,
- node: node_id
- })
+ Some(node_id)
},
_ => {
diagnostic.handler().err("multiple macro registration functions found");
--- /dev/null
+-include ../tools.mk
+
+all:
+ $(RUSTC) lib.rs
+ $(RUSTC) main.rs -Z lto
+ $(call RUN,main)
--- /dev/null
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#[crate_type = "rlib"];
--- /dev/null
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(phase)]
+
+extern crate lib;
+#[phase(syntax)] extern crate fourcc;
+
+fn main() {
+ fourcc!("1234");
+}