use rustc::hir::map::Node;
use rustc::session::Session;
use rustc::ty::{self, TyCtxt};
+use rustc_data_structures::fx::FxHashSet;
use std::path::Path;
// we only write one macro def per unique macro definition, and
// one macro use per unique callsite span.
// mac_defs: HashSet<Span>,
+ macro_calls: FxHashSet<Span>,
}
impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
span: span_utils.clone(),
cur_scope: CRATE_NODE_ID,
// mac_defs: HashSet::new(),
+ macro_calls: FxHashSet(),
}
}
let (value, fields) =
if let ast::ItemKind::Struct(ast::VariantData::Struct(ref fields, _), _) = item.node
{
- let fields_str = fields.iter()
- .enumerate()
- .map(|(i, f)| f.ident.map(|i| i.to_string())
- .unwrap_or(i.to_string()))
- .collect::<Vec<_>>()
- .join(", ");
- (format!("{} {{ {} }}", name, fields_str),
- fields.iter().map(|f| ::id_from_node_id(f.id, &self.save_ctxt)).collect())
+ let include_priv_fields = !self.save_ctxt.config.pub_only;
+ let fields_str = fields
+ .iter()
+ .enumerate()
+ .filter_map(|(i, f)| {
+ if include_priv_fields || f.vis == ast::Visibility::Public {
+ f.ident.map(|i| i.to_string()).or_else(|| Some(i.to_string()))
+ } else {
+ None
+ }
+ })
+ .collect::<Vec<_>>()
+ .join(", ");
+ let value = format!("{} {{ {} }}", name, fields_str);
+ (value, fields.iter().map(|f| ::id_from_node_id(f.id, &self.save_ctxt)).collect())
} else {
(String::new(), vec![])
};
/// callsite spans to record macro definition and use data, using the
/// mac_uses and mac_defs sets to prevent multiples.
fn process_macro_use(&mut self, span: Span) {
+ let source_span = span.source_callsite();
+ if self.macro_calls.contains(&source_span) {
+ return;
+ }
+ self.macro_calls.insert(source_span);
+
let data = match self.save_ctxt.get_macro_use_data(span) {
None => return,
Some(data) => data,
};
+ self.dumper.macro_use(data);
+
// FIXME write the macro def
// let mut hasher = DefaultHasher::new();
// data.callee_span.hash(&mut hasher);
// }.lower(self.tcx));
// }
// }
- self.dumper.macro_use(data);
}
fn process_trait_item(&mut self, trait_item: &'l ast::TraitItem, trait_id: DefId) {