librustc::metadata : Allow passing a string to read_plugin_metadata

This commit is contained in:
Manish Goregaokar 2014-12-09 21:33:05 +05:30
parent 7e87ea9fc5
commit efaf613497
2 changed files with 26 additions and 9 deletions

View File

@ -26,7 +26,7 @@
use syntax::abi;
use syntax::attr;
use syntax::attr::AttrMetaMethods;
use syntax::codemap::{Span, mk_sp};
use syntax::codemap::{DUMMY_SP, Span, mk_sp};
use syntax::parse;
use syntax::parse::token::InternedString;
use syntax::parse::token;
@ -445,8 +445,20 @@ fn resolve_crate_deps(&mut self,
}
pub fn read_plugin_metadata<'b>(&'b mut self,
vi: &'b ast::ViewItem) -> PluginMetadata<'b> {
let info = self.extract_crate_info(vi).unwrap();
krate: CrateOrString<'b>) -> PluginMetadata<'b> {
let (info, span) = match krate {
CrateOrString::Krate(c) => {
(self.extract_crate_info(c).unwrap(), c.span)
}
CrateOrString::Str(s) => {
(CrateInfo {
name: s.to_string(),
ident: s.to_string(),
id: ast::DUMMY_NODE_ID,
should_link: true,
}, DUMMY_SP)
}
};
let target_triple = &self.sess.opts.target_triple[];
let is_cross = target_triple != config::host_triple();
let mut should_link = info.should_link && !is_cross;
@ -455,7 +467,7 @@ pub fn read_plugin_metadata<'b>(&'b mut self,
let name = info.name.clone();
let mut load_ctxt = loader::Context {
sess: self.sess,
span: vi.span,
span: span,
ident: &ident[],
crate_name: &name[],
hash: None,
@ -485,8 +497,8 @@ pub fn read_plugin_metadata<'b>(&'b mut self,
let register = should_link && self.existing_match(info.name.as_slice(), None).is_none();
let metadata = if register {
// Register crate now to avoid double-reading metadata
let (_, cmd, _) = self.register_crate(&None, &info.ident[],
&info.name[], vi.span, library);
let (_, cmd, _) = self.register_crate(&None, info.ident[],
info.name[], span, library);
PMDSource::Registered(cmd)
} else {
// Not registering the crate; just hold on to the metadata
@ -498,12 +510,17 @@ pub fn read_plugin_metadata<'b>(&'b mut self,
metadata: metadata,
dylib: dylib,
info: info,
vi_span: vi.span,
vi_span: span,
target_only: target_only,
}
}
}
pub enum CrateOrString<'a> {
Krate(&'a ast::ViewItem),
Str(&'a str)
}
impl<'a> PluginMetadata<'a> {
/// Read exported macros
pub fn exported_macros(&self) -> Vec<ast::MacroDef> {

View File

@ -11,7 +11,7 @@
//! Used by `rustc` when loading a plugin, or a crate with exported macros.
use session::Session;
use metadata::creader::CrateReader;
use metadata::creader::{CrateOrString, CrateReader};
use plugin::registry::Registry;
use std::mem;
@ -175,7 +175,7 @@ fn visit_view_item(&mut self, vi: &ast::ViewItem) {
}
if load_macros || load_registrar {
let pmd = self.reader.read_plugin_metadata(vi);
let pmd = self.reader.read_plugin_metadata(CrateOrString::Krate(vi));
if load_macros {
macros = pmd.exported_macros();
}