Skip to content

Commit

Permalink
field signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Dec 22, 2016
1 parent c53fa9a commit eb27b51
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/librustc_save_analysis/data.rs
Expand Up @@ -387,6 +387,7 @@ pub struct VariableData {
pub type_value: String,
pub visibility: Visibility,
pub docs: String,
pub sig: Option<Signature>,
}

#[derive(Debug, RustcEncodable)]
Expand Down
4 changes: 4 additions & 0 deletions src/librustc_save_analysis/dump_visitor.rs
Expand Up @@ -372,6 +372,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
parent: None,
visibility: Visibility::Inherited,
docs: String::new(),
sig: None,
}.lower(self.tcx));
}
}
Expand Down Expand Up @@ -587,6 +588,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
parent: Some(parent_id),
visibility: vis,
docs: docs_for_attrs(attrs),
sig: None,
}.lower(self.tcx));
}

Expand Down Expand Up @@ -1072,6 +1074,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
parent: None,
visibility: Visibility::Inherited,
docs: String::new(),
sig: None,
}.lower(self.tcx));
}
}
Expand Down Expand Up @@ -1521,6 +1524,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll,
parent: None,
visibility: Visibility::Inherited,
docs: String::new(),
sig: None,
}.lower(self.tcx));
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_save_analysis/external_data.rs
Expand Up @@ -658,6 +658,7 @@ pub struct VariableData {
pub parent: Option<DefId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Option<Signature>,
}

impl Lower for data::VariableData {
Expand All @@ -676,6 +677,7 @@ impl Lower for data::VariableData {
parent: self.parent,
visibility: self.visibility,
docs: self.docs,
sig: self.sig.map(|s| s.lower(tcx)),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/json_api_dumper.rs
Expand Up @@ -419,7 +419,7 @@ impl From<VariableData> for Option<Def> {
parent: data.parent.map(|id| From::from(id)),
decl_id: None,
docs: data.docs,
sig: None,
sig: data.sig,
}),
_ => None,
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/json_dumper.rs
Expand Up @@ -379,7 +379,7 @@ impl From<MacroData> for Def {
children: vec![],
decl_id: None,
docs: data.docs,
sig: None,
sig: data.sig,
}
}
}
Expand Down
34 changes: 29 additions & 5 deletions src/librustc_save_analysis/lib.rs
Expand Up @@ -179,6 +179,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
type_value: ty_to_string(&typ),
visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
sig: None,
}))
}
ast::ItemKind::Const(ref typ, ref expr) => {
Expand All @@ -197,6 +198,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
type_value: ty_to_string(&typ),
visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
sig: None,
}))
}
ast::ItemKind::Mod(ref m) => {
Expand Down Expand Up @@ -287,18 +289,39 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
}
}

pub fn get_field_data(&self, field: &ast::StructField,
scope: NodeId) -> Option<VariableData> {
pub fn get_field_data(&self,
field: &ast::StructField,
scope: NodeId)
-> Option<VariableData> {
if let Some(ident) = field.ident {
let name = ident.to_string();
let qualname = format!("::{}::{}", self.tcx.node_path_str(scope), ident);
let def_id = self.tcx.map.local_def_id(field.id);
let typ = self.tcx.item_type(def_id).to_string();
let sub_span = self.span_utils.sub_span_before_token(field.span, token::Colon);
filter!(self.span_utils, sub_span, field.span, None);
let def_id = self.tcx.map.local_def_id(field.id);
let typ = self.tcx.item_type(def_id).to_string();

let span = field.span;
let text = self.span_utils.snippet(field.span);
let ident_start = text.find(&name).unwrap();
let ident_end = ident_start + name.len();
// TODO refs
let sig = Signature {
span: span,
text: text,
ident_start: ident_start,
ident_end: ident_end,
defs: vec![SigElement {
id: def_id,
start: ident_start,
end: ident_end,
}],
refs: vec![],
};
Some(VariableData {
id: field.id,
kind: VariableKind::Field,
name: ident.to_string(),
name: name,
qualname: qualname,
span: sub_span.unwrap(),
scope: scope,
Expand All @@ -307,6 +330,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
type_value: typ,
visibility: From::from(&field.vis),
docs: docs_for_attrs(&field.attrs),
sig: Some(sig),
})
} else {
None
Expand Down

0 comments on commit eb27b51

Please sign in to comment.