Skip to content

Commit

Permalink
signature info for other items (mods, fns, methods, etc.)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Dec 22, 2016
1 parent e9ecd88 commit d849236
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 50 deletions.
12 changes: 10 additions & 2 deletions src/librustc_save_analysis/data.rs
Expand Up @@ -135,6 +135,7 @@ pub struct EnumData {
pub variants: Vec<NodeId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Signature,
}

/// Data for extern crates.
Expand Down Expand Up @@ -169,6 +170,7 @@ pub struct FunctionData {
pub visibility: Visibility,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Signature,
}

/// Data about a function call.
Expand Down Expand Up @@ -253,6 +255,7 @@ pub struct MethodData {
pub parent: Option<DefId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Signature,
}

/// Data for modules.
Expand All @@ -267,6 +270,7 @@ pub struct ModData {
pub items: Vec<NodeId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Signature,
}

/// Data for a reference to a module.
Expand Down Expand Up @@ -304,6 +308,7 @@ pub struct StructVariantData {
pub scope: NodeId,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Signature,
}

#[derive(Debug, RustcEncodable)]
Expand All @@ -317,6 +322,7 @@ pub struct TraitData {
pub items: Vec<NodeId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Signature,
}

#[derive(Debug, RustcEncodable)]
Expand All @@ -330,6 +336,7 @@ pub struct TupleVariantData {
pub scope: NodeId,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Signature,
}

/// Data for a typedef.
Expand All @@ -343,6 +350,7 @@ pub struct TypeDefData {
pub visibility: Visibility,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Option<Signature>,
}

/// Data for a reference to a type or trait.
Expand Down Expand Up @@ -412,7 +420,7 @@ pub struct VariableRefData {
/// Encodes information about the signature of a definition. This should have
/// enough information to create a nice display about a definition without
/// access to the source code.
#[derive(Debug, RustcEncodable)]
#[derive(Clone, Debug, RustcEncodable)]
pub struct Signature {
pub span: Span,
pub text: String,
Expand All @@ -426,7 +434,7 @@ pub struct Signature {

/// An element of a signature. `start` and `end` are byte offsets into the `text`
/// of the parent `Signature`.
#[derive(Debug, RustcEncodable)]
#[derive(Clone, Debug, RustcEncodable)]
pub struct SigElement {
pub id: DefId,
pub start: usize,
Expand Down
43 changes: 23 additions & 20 deletions src/librustc_save_analysis/dump_visitor.rs
Expand Up @@ -445,6 +445,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
parent: trait_id,
visibility: vis,
docs: docs_for_attrs(attrs),
sig: method_data.sig,
}.lower(self.tcx));
}

Expand Down Expand Up @@ -516,6 +517,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
visibility: Visibility::Inherited,
parent: None,
docs: String::new(),
sig: None,
}.lower(self.tcx));
}
}
Expand Down Expand Up @@ -621,9 +623,6 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
};

if !self.span.filter_generated(sub_span, item.span) {
let mut sig = self.sig_base(item);
sig.ident_start = sig.text.find(&name).expect("Name not in struct signature?");
sig.ident_end = sig.ident_start + name.len();
self.dumper.struct_data(StructData {
span: sub_span.expect("No span found for struct"),
id: item.id,
Expand All @@ -635,7 +634,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
fields: fields,
visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
sig: sig,
sig: self.save_ctxt.sig_base(item),
}.lower(self.tcx));
}

Expand All @@ -647,18 +646,6 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
self.process_generic_params(ty_params, item.span, &qualname, item.id);
}

fn sig_base(&self, item: &ast::Item) -> Signature {
let text = self.span.signature_string_for_span(item.span).expect("Couldn't make signature");
Signature {
span: mk_sp(item.span.lo, item.span.lo + BytePos(text.len() as u32)),
text: text,
ident_start: 0,
ident_end: 0,
defs: vec![],
refs: vec![],
}
}

fn process_enum(&mut self,
item: &'l ast::Item,
enum_definition: &'l ast::EnumDef,
Expand All @@ -679,6 +666,18 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
qualname.push_str("::");
qualname.push_str(&name);

let text = self.span.signature_string_for_span(variant.span);
let ident_start = text.find(&name).unwrap();
let ident_end = ident_start + name.len();
let sig = Signature {
span: variant.span,
text: text,
ident_start: ident_start,
ident_end: ident_end,
defs: vec![],
refs: vec![],
};

match variant.node.data {
ast::VariantData::Struct(ref fields, _) => {
let sub_span = self.span.span_for_first_ident(variant.span);
Expand All @@ -700,6 +699,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
scope: enum_data.scope,
parent: Some(make_def_id(item.id, &self.tcx.map)),
docs: docs_for_attrs(&variant.node.attrs),
sig: sig,
}.lower(self.tcx));
}
}
Expand All @@ -725,6 +725,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
scope: enum_data.scope,
parent: Some(make_def_id(item.id, &self.tcx.map)),
docs: docs_for_attrs(&variant.node.attrs),
sig: sig,
}.lower(self.tcx));
}
}
Expand Down Expand Up @@ -809,6 +810,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
items: methods.iter().map(|i| i.id).collect(),
visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
sig: self.save_ctxt.sig_base(item),
}.lower(self.tcx));
}

Expand Down Expand Up @@ -1289,10 +1291,10 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll,
Struct(ref def, ref ty_params) => self.process_struct(item, def, ty_params),
Enum(ref def, ref ty_params) => self.process_enum(item, def, ty_params),
Impl(..,
ref ty_params,
ref trait_ref,
ref typ,
ref impl_items) => {
ref ty_params,
ref trait_ref,
ref typ,
ref impl_items) => {
self.process_impl(item, ty_params, trait_ref, &typ, impl_items)
}
Trait(_, ref generics, ref trait_refs, ref methods) =>
Expand All @@ -1315,6 +1317,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll,
visibility: From::from(&item.vis),
parent: None,
docs: docs_for_attrs(&item.attrs),
sig: Some(self.save_ctxt.sig_base(item)),
}.lower(self.tcx));
}

Expand Down
18 changes: 17 additions & 1 deletion src/librustc_save_analysis/external_data.rs
Expand Up @@ -97,6 +97,7 @@ pub struct EnumData {
pub variants: Vec<DefId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Signature,
}

impl Lower for data::EnumData {
Expand All @@ -113,6 +114,7 @@ impl Lower for data::EnumData {
variants: self.variants.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(),
visibility: self.visibility,
docs: self.docs,
sig: self.sig.lower(tcx),
}
}
}
Expand Down Expand Up @@ -176,6 +178,7 @@ pub struct FunctionData {
pub visibility: Visibility,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Signature,
}

impl Lower for data::FunctionData {
Expand All @@ -193,6 +196,7 @@ impl Lower for data::FunctionData {
visibility: self.visibility,
parent: self.parent,
docs: self.docs,
sig: self.sig.lower(tcx),
}
}
}
Expand Down Expand Up @@ -341,6 +345,7 @@ pub struct MethodData {
pub visibility: Visibility,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Signature,
}

impl Lower for data::MethodData {
Expand All @@ -358,6 +363,7 @@ impl Lower for data::MethodData {
visibility: self.visibility,
parent: self.parent,
docs: self.docs,
sig: self.sig.lower(tcx),
}
}
}
Expand All @@ -374,6 +380,7 @@ pub struct ModData {
pub items: Vec<DefId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Signature,
}

impl Lower for data::ModData {
Expand All @@ -390,6 +397,7 @@ impl Lower for data::ModData {
items: self.items.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(),
visibility: self.visibility,
docs: self.docs,
sig: self.sig.lower(tcx),
}
}
}
Expand Down Expand Up @@ -462,6 +470,7 @@ pub struct StructVariantData {
pub scope: DefId,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Signature,
}

impl Lower for data::StructVariantData {
Expand All @@ -478,6 +487,7 @@ impl Lower for data::StructVariantData {
scope: make_def_id(self.scope, &tcx.map),
parent: self.parent,
docs: self.docs,
sig: self.sig.lower(tcx),
}
}
}
Expand All @@ -493,6 +503,7 @@ pub struct TraitData {
pub items: Vec<DefId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Signature,
}

impl Lower for data::TraitData {
Expand All @@ -509,6 +520,7 @@ impl Lower for data::TraitData {
items: self.items.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(),
visibility: self.visibility,
docs: self.docs,
sig: self.sig.lower(tcx),
}
}
}
Expand All @@ -524,6 +536,7 @@ pub struct TupleVariantData {
pub scope: DefId,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Signature,
}

impl Lower for data::TupleVariantData {
Expand All @@ -540,6 +553,7 @@ impl Lower for data::TupleVariantData {
scope: make_def_id(self.scope, &tcx.map),
parent: self.parent,
docs: self.docs,
sig: self.sig.lower(tcx),
}
}
}
Expand All @@ -555,6 +569,7 @@ pub struct TypeDefData {
pub visibility: Visibility,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Option<Signature>,
}

impl Lower for data::TypeDefData {
Expand All @@ -570,6 +585,7 @@ impl Lower for data::TypeDefData {
visibility: self.visibility,
parent: self.parent,
docs: self.docs,
sig: self.sig.map(|s| s.lower(tcx)),
}
}
}
Expand Down Expand Up @@ -705,7 +721,7 @@ impl Lower for data::VariableRefData {
}
}

#[derive(Debug, RustcEncodable)]
#[derive(Clone, Debug, RustcEncodable)]
pub struct Signature {
pub span: SpanData,
pub text: String,
Expand Down

0 comments on commit d849236

Please sign in to comment.