filter_view_item(cx, a).map(|x| cx.fold_view_item(x))
}).collect();
ast::Mod {
+ inner: m.inner,
view_items: filtered_view_items,
items: flattened_items
}
}
let mod_nomain = ast::Mod {
+ inner: m.inner,
view_items: m.view_items.clone(),
items: m.items.iter().map(|i| nomain(&self.cx, *i)).collect(),
};
)).unwrap();
let testmod = ast::Mod {
+ inner: DUMMY_SP,
view_items: view_items,
items: vec!(mainfn, tests),
};
#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)]
pub struct Mod {
- pub view_items: Vec<ViewItem> ,
- pub items: Vec<@Item> ,
+ /// A span from the first token past `{` to the last token until `}`.
+ /// For `mod foo;`, the inner span ranges from the first token
+ /// to the last token in the external file.
+ pub inner: Span,
+ pub view_items: Vec<ViewItem>,
+ pub items: Vec<@Item>,
}
#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)]
fn check_asts_encodable() {
use std::io;
let e = Crate {
- module: Mod {view_items: Vec::new(), items: Vec::new()},
+ module: Mod {
+ inner: Span {
+ lo: BytePos(11),
+ hi: BytePos(19),
+ expn_info: None,
+ },
+ view_items: Vec::new(),
+ items: Vec::new(),
+ },
attrs: Vec::new(),
config: Vec::new(),
span: Span {
generics: Generics) -> @ast::Item;
fn item_struct(&self, span: Span, name: Ident, struct_def: ast::StructDef) -> @ast::Item;
- fn item_mod(&self, span: Span,
+ fn item_mod(&self, span: Span, inner_span: Span,
name: Ident, attrs: Vec<ast::Attribute> ,
vi: Vec<ast::ViewItem> , items: Vec<@ast::Item> ) -> @ast::Item;
self.item(span, name, Vec::new(), ast::ItemStruct(@struct_def, generics))
}
- fn item_mod(&self, span: Span, name: Ident,
+ fn item_mod(&self, span: Span, inner_span: Span, name: Ident,
attrs: Vec<ast::Attribute> ,
vi: Vec<ast::ViewItem> ,
items: Vec<@ast::Item> ) -> @ast::Item {
name,
attrs,
ast::ItemMod(ast::Mod {
+ inner: inner_span,
view_items: vi,
items: items,
})
pub fn noop_fold_mod<T: Folder>(m: &Mod, folder: &mut T) -> Mod {
ast::Mod {
+ inner: folder.new_span(m.inner),
view_items: m.view_items
.iter()
.map(|x| folder.fold_view_item(x)).collect(),
// attributes (of length 0 or 1), parse all of the items in a module
fn parse_mod_items(&mut self,
term: token::Token,
- first_item_attrs: Vec<Attribute> )
+ first_item_attrs: Vec<Attribute>,
+ inner_lo: BytePos)
-> Mod {
// parse all of the items up to closing or an attribute.
// view items are legal here.
self.span_err(self.last_span, "expected item after attributes");
}
- ast::Mod { view_items: view_items, items: items }
+ ast::Mod {
+ inner: mk_sp(inner_lo, self.span.lo),
+ view_items: view_items,
+ items: items
+ }
}
fn parse_item_const(&mut self) -> ItemInfo {
} else {
self.push_mod_path(id, outer_attrs);
self.expect(&token::LBRACE);
+ let mod_inner_lo = self.span.lo;
let (inner, next) = self.parse_inner_attrs_and_next();
- let m = self.parse_mod_items(token::RBRACE, next);
+ let m = self.parse_mod_items(token::RBRACE, next, mod_inner_lo);
self.expect(&token::RBRACE);
self.pop_mod_path();
(id, ItemMod(m), Some(inner))
self.cfg.clone(),
&path,
id_sp);
+ let mod_inner_lo = p0.span.lo;
let (inner, next) = p0.parse_inner_attrs_and_next();
let mod_attrs = outer_attrs.append(inner.as_slice());
let first_item_outer_attrs = next;
- let m0 = p0.parse_mod_items(token::EOF, first_item_outer_attrs);
+ let m0 = p0.parse_mod_items(token::EOF, first_item_outer_attrs, mod_inner_lo);
self.sess.included_mod_stack.borrow_mut().pop();
return (ast::ItemMod(m0), mod_attrs);
}
let (inner, next) = self.parse_inner_attrs_and_next();
let first_item_outer_attrs = next;
// parse the items inside the crate:
- let m = self.parse_mod_items(token::EOF, first_item_outer_attrs);
+ let m = self.parse_mod_items(token::EOF, first_item_outer_attrs, lo);
ast::Crate {
module: m,