auto merge of #9804 : alexcrichton/rust/always-anon-extern, r=brson
There's currently a fair amount of code which is being ignored on unnamed blocks (which are the default now), and I opted to leave it commented out for now. I intend on very soon revisiting on how we perform linking with extern crates in an effort to support static linking.
This commit is contained in:
commit
e5fc0ca6dc
@ -102,7 +102,6 @@ fn fold_foreign_mod(cx: &Context, nm: &ast::foreign_mod) -> ast::foreign_mod {
|
|||||||
}
|
}
|
||||||
}.collect();
|
}.collect();
|
||||||
ast::foreign_mod {
|
ast::foreign_mod {
|
||||||
sort: nm.sort,
|
|
||||||
abis: nm.abis,
|
abis: nm.abis,
|
||||||
view_items: filtered_view_items,
|
view_items: filtered_view_items,
|
||||||
items: filtered_items
|
items: filtered_items
|
||||||
|
@ -175,40 +175,43 @@ fn visit_item(e: &Env, i: @ast::item) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let cstore = e.cstore;
|
let cstore = e.cstore;
|
||||||
let mut already_added = false;
|
|
||||||
let link_args = i.attrs.iter()
|
let link_args = i.attrs.iter()
|
||||||
.filter_map(|at| if "link_args" == at.name() {Some(at)} else {None})
|
.filter_map(|at| if "link_args" == at.name() {Some(at)} else {None})
|
||||||
.collect::<~[&ast::Attribute]>();
|
.collect::<~[&ast::Attribute]>();
|
||||||
|
|
||||||
match fm.sort {
|
// XXX: two whom it may concern, this was the old logic applied to the
|
||||||
ast::named => {
|
// ast's extern mod blocks which had names (we used to allow
|
||||||
let link_name = i.attrs.iter()
|
// "extern mod foo"). This code was never run for anonymous blocks,
|
||||||
.find(|at| "link_name" == at.name())
|
// and we now only have anonymous blocks. We're still in the midst
|
||||||
.and_then(|at| at.value_str());
|
// of figuring out what the exact operations we'd like to support
|
||||||
|
// when linking external modules, but I wanted to leave this logic
|
||||||
|
// here for the time beging to refer back to it
|
||||||
|
|
||||||
let foreign_name = match link_name {
|
//let mut already_added = false;
|
||||||
Some(nn) => {
|
//let link_name = i.attrs.iter()
|
||||||
if nn.is_empty() {
|
// .find(|at| "link_name" == at.name())
|
||||||
e.diag.span_fatal(
|
// .and_then(|at| at.value_str());
|
||||||
i.span,
|
|
||||||
"empty #[link_name] not allowed; use \
|
//let foreign_name = match link_name {
|
||||||
#[nolink].");
|
// Some(nn) => {
|
||||||
}
|
// if nn.is_empty() {
|
||||||
nn
|
// e.diag.span_fatal(
|
||||||
}
|
// i.span,
|
||||||
None => token::ident_to_str(&i.ident)
|
// "empty #[link_name] not allowed; use \
|
||||||
};
|
// #[nolink].");
|
||||||
if !attr::contains_name(i.attrs, "nolink") {
|
// }
|
||||||
already_added =
|
// nn
|
||||||
!cstore::add_used_library(cstore, foreign_name);
|
// }
|
||||||
}
|
// None => token::ident_to_str(&i.ident)
|
||||||
if !link_args.is_empty() && already_added {
|
// };
|
||||||
e.diag.span_fatal(i.span, ~"library '" + foreign_name +
|
//if !attr::contains_name(i.attrs, "nolink") {
|
||||||
"' already added: can't specify link_args.");
|
// already_added =
|
||||||
}
|
// !cstore::add_used_library(cstore, foreign_name);
|
||||||
}
|
//}
|
||||||
ast::anonymous => { /* do nothing */ }
|
//if !link_args.is_empty() && already_added {
|
||||||
}
|
// e.diag.span_fatal(i.span, ~"library '" + foreign_name +
|
||||||
|
// "' already added: can't specify link_args.");
|
||||||
|
//}
|
||||||
|
|
||||||
for m in link_args.iter() {
|
for m in link_args.iter() {
|
||||||
match m.value_str() {
|
match m.value_str() {
|
||||||
|
@ -1183,31 +1183,7 @@ impl Resolver {
|
|||||||
ModuleReducedGraphParent(name_bindings.get_module())
|
ModuleReducedGraphParent(name_bindings.get_module())
|
||||||
}
|
}
|
||||||
|
|
||||||
item_foreign_mod(ref fm) => {
|
item_foreign_mod(*) => parent,
|
||||||
match fm.sort {
|
|
||||||
named => {
|
|
||||||
let (name_bindings, new_parent) =
|
|
||||||
self.add_child(ident, parent,
|
|
||||||
ForbidDuplicateModules, sp);
|
|
||||||
|
|
||||||
let parent_link = self.get_parent_link(new_parent,
|
|
||||||
ident);
|
|
||||||
let def_id = DefId { crate: 0, node: item.id };
|
|
||||||
name_bindings.define_module(parent_link,
|
|
||||||
Some(def_id),
|
|
||||||
ExternModuleKind,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
sp);
|
|
||||||
|
|
||||||
ModuleReducedGraphParent(name_bindings.get_module())
|
|
||||||
}
|
|
||||||
|
|
||||||
// For anon foreign mods, the contents just go in the
|
|
||||||
// current scope
|
|
||||||
anonymous => parent
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// These items live in the value namespace.
|
// These items live in the value namespace.
|
||||||
item_static(_, m, _) => {
|
item_static(_, m, _) => {
|
||||||
|
@ -949,16 +949,8 @@ pub struct _mod {
|
|||||||
items: ~[@item],
|
items: ~[@item],
|
||||||
}
|
}
|
||||||
|
|
||||||
// Foreign mods can be named or anonymous
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)]
|
|
||||||
pub enum foreign_mod_sort {
|
|
||||||
named,
|
|
||||||
anonymous,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)]
|
#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)]
|
||||||
pub struct foreign_mod {
|
pub struct foreign_mod {
|
||||||
sort: foreign_mod_sort,
|
|
||||||
abis: AbiSet,
|
abis: AbiSet,
|
||||||
view_items: ~[view_item],
|
view_items: ~[view_item],
|
||||||
items: ~[@foreign_item],
|
items: ~[@foreign_item],
|
||||||
|
@ -294,17 +294,11 @@ impl Visitor<()> for Ctx {
|
|||||||
nm.abis,
|
nm.abis,
|
||||||
visibility,
|
visibility,
|
||||||
// FIXME (#2543)
|
// FIXME (#2543)
|
||||||
if nm.sort ==
|
|
||||||
ast::named {
|
|
||||||
let e = path_name(
|
|
||||||
i.ident);
|
|
||||||
self.extend(e)
|
|
||||||
} else {
|
|
||||||
// Anonymous extern
|
// Anonymous extern
|
||||||
// mods go in the
|
// mods go in the
|
||||||
// parent scope.
|
// parent scope.
|
||||||
@self.path.clone()
|
@self.path.clone()
|
||||||
}));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
item_struct(struct_def, _) => {
|
item_struct(struct_def, _) => {
|
||||||
|
@ -289,7 +289,6 @@ pub trait ast_fold {
|
|||||||
|
|
||||||
fn fold_foreign_mod(&self, nm: &foreign_mod) -> foreign_mod {
|
fn fold_foreign_mod(&self, nm: &foreign_mod) -> foreign_mod {
|
||||||
ast::foreign_mod {
|
ast::foreign_mod {
|
||||||
sort: nm.sort,
|
|
||||||
abis: nm.abis,
|
abis: nm.abis,
|
||||||
view_items: nm.view_items
|
view_items: nm.view_items
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -4128,7 +4128,6 @@ impl Parser {
|
|||||||
// at this point, this is essentially a wrapper for
|
// at this point, this is essentially a wrapper for
|
||||||
// parse_foreign_items.
|
// parse_foreign_items.
|
||||||
fn parse_foreign_mod_items(&self,
|
fn parse_foreign_mod_items(&self,
|
||||||
sort: ast::foreign_mod_sort,
|
|
||||||
abis: AbiSet,
|
abis: AbiSet,
|
||||||
first_item_attrs: ~[Attribute])
|
first_item_attrs: ~[Attribute])
|
||||||
-> foreign_mod {
|
-> foreign_mod {
|
||||||
@ -4144,7 +4143,6 @@ impl Parser {
|
|||||||
}
|
}
|
||||||
assert!(*self.token == token::RBRACE);
|
assert!(*self.token == token::RBRACE);
|
||||||
ast::foreign_mod {
|
ast::foreign_mod {
|
||||||
sort: sort,
|
|
||||||
abis: abis,
|
abis: abis,
|
||||||
view_items: view_items,
|
view_items: view_items,
|
||||||
items: foreign_items
|
items: foreign_items
|
||||||
@ -4169,7 +4167,7 @@ impl Parser {
|
|||||||
self.this_token_to_str()));
|
self.this_token_to_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let (sort, maybe_path, ident) = match *self.token {
|
let (named, maybe_path, ident) = match *self.token {
|
||||||
token::IDENT(*) => {
|
token::IDENT(*) => {
|
||||||
let the_ident = self.parse_ident();
|
let the_ident = self.parse_ident();
|
||||||
let path = if *self.token == token::EQ {
|
let path = if *self.token == token::EQ {
|
||||||
@ -4177,7 +4175,7 @@ impl Parser {
|
|||||||
Some(self.parse_str())
|
Some(self.parse_str())
|
||||||
}
|
}
|
||||||
else { None };
|
else { None };
|
||||||
(ast::named, path, the_ident)
|
(true, path, the_ident)
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if must_be_named_mod {
|
if must_be_named_mod {
|
||||||
@ -4187,7 +4185,7 @@ impl Parser {
|
|||||||
self.this_token_to_str()));
|
self.this_token_to_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
(ast::anonymous, None,
|
(false, None,
|
||||||
special_idents::clownshoes_foreign_mod)
|
special_idents::clownshoes_foreign_mod)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -4195,14 +4193,14 @@ impl Parser {
|
|||||||
// extern mod foo { ... } or extern { ... }
|
// extern mod foo { ... } or extern { ... }
|
||||||
if items_allowed && self.eat(&token::LBRACE) {
|
if items_allowed && self.eat(&token::LBRACE) {
|
||||||
// `extern mod foo { ... }` is obsolete.
|
// `extern mod foo { ... }` is obsolete.
|
||||||
if sort == ast::named {
|
if named {
|
||||||
self.obsolete(*self.last_span, ObsoleteNamedExternModule);
|
self.obsolete(*self.last_span, ObsoleteNamedExternModule);
|
||||||
}
|
}
|
||||||
|
|
||||||
let abis = opt_abis.unwrap_or(AbiSet::C());
|
let abis = opt_abis.unwrap_or(AbiSet::C());
|
||||||
|
|
||||||
let (inner, next) = self.parse_inner_attrs_and_next();
|
let (inner, next) = self.parse_inner_attrs_and_next();
|
||||||
let m = self.parse_foreign_mod_items(sort, abis, next);
|
let m = self.parse_foreign_mod_items(abis, next);
|
||||||
self.expect(&token::RBRACE);
|
self.expect(&token::RBRACE);
|
||||||
|
|
||||||
return iovi_item(self.mk_item(lo,
|
return iovi_item(self.mk_item(lo,
|
||||||
|
@ -539,14 +539,6 @@ pub fn print_item(s: @ps, item: &ast::item) {
|
|||||||
ast::item_foreign_mod(ref nmod) => {
|
ast::item_foreign_mod(ref nmod) => {
|
||||||
head(s, "extern");
|
head(s, "extern");
|
||||||
word_nbsp(s, nmod.abis.to_str());
|
word_nbsp(s, nmod.abis.to_str());
|
||||||
match nmod.sort {
|
|
||||||
ast::named => {
|
|
||||||
word_nbsp(s, "mod");
|
|
||||||
print_ident(s, item.ident);
|
|
||||||
nbsp(s);
|
|
||||||
}
|
|
||||||
ast::anonymous => {}
|
|
||||||
}
|
|
||||||
bopen(s);
|
bopen(s);
|
||||||
print_foreign_mod(s, nmod, item.attrs);
|
print_foreign_mod(s, nmod, item.attrs);
|
||||||
bclose(s, item.span);
|
bclose(s, item.span);
|
||||||
|
Loading…
Reference in New Issue
Block a user