Skip to content

Commit

Permalink
further lowering of signature data
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Dec 22, 2016
1 parent eb27b51 commit e9ecd88
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 8 deletions.
49 changes: 45 additions & 4 deletions src/librustc_save_analysis/json_api_dumper.rs
Expand Up @@ -14,7 +14,7 @@ use rustc::hir::def_id::DefId;
use rustc_serialize::json::as_json;

use external_data::*;
use data::{VariableKind, Visibility};
use data::{VariableKind, Visibility, SigElement};
use dump::Dump;
use super::Format;

Expand Down Expand Up @@ -179,7 +179,7 @@ struct Def {
children: Vec<Id>,
decl_id: Option<Id>,
docs: String,
sig: Option<Signature>,
sig: Option<JsonSignature>,
}

#[derive(Debug, RustcEncodable)]
Expand Down Expand Up @@ -277,7 +277,7 @@ impl From<StructData> for Option<Def> {
children: data.fields.into_iter().map(|id| From::from(id)).collect(),
decl_id: None,
docs: data.docs,
sig: Some(data.sig),
sig: Some(From::from(data.sig)),
}),
_ => None,
}
Expand Down Expand Up @@ -400,6 +400,7 @@ impl From<TypeDefData> for Option<Def> {
}
}
}

impl From<VariableData> for Option<Def> {
fn from(data: VariableData) -> Option<Def> {
match data.visibility {
Expand All @@ -419,9 +420,49 @@ impl From<VariableData> for Option<Def> {
parent: data.parent.map(|id| From::from(id)),
decl_id: None,
docs: data.docs,
sig: data.sig,
sig: data.sig.map(|s| From::from(s)),
}),
_ => None,
}
}
}

#[derive(Debug, RustcEncodable)]
pub struct JsonSignature {
span: SpanData,
text: String,
ident_start: usize,
ident_end: usize,
defs: Vec<JsonSigElement>,
refs: Vec<JsonSigElement>,
}

impl From<Signature> for JsonSignature {
fn from(data: Signature) -> JsonSignature {
JsonSignature {
span: data.span,
text: data.text,
ident_start: data.ident_start,
ident_end: data.ident_end,
defs: data.defs.into_iter().map(|s| From::from(s)).collect(),
refs: data.refs.into_iter().map(|s| From::from(s)).collect(),
}
}
}

#[derive(Debug, RustcEncodable)]
pub struct JsonSigElement {
id: Id,
start: usize,
end: usize,
}

impl From<SigElement> for JsonSigElement {
fn from(data: SigElement) -> JsonSigElement {
JsonSigElement {
id: From::from(data.id),
start: data.start,
end: data.end,
}
}
}
48 changes: 44 additions & 4 deletions src/librustc_save_analysis/json_dumper.rs
Expand Up @@ -14,7 +14,7 @@ use rustc::hir::def_id::DefId;
use rustc_serialize::json::as_json;

use external_data::*;
use data::VariableKind;
use data::{VariableKind, SigElement};
use dump::Dump;
use super::Format;

Expand Down Expand Up @@ -224,7 +224,7 @@ struct Def {
children: Vec<Id>,
decl_id: Option<Id>,
docs: String,
sig: Option<Signature>,
sig: Option<JsonSignature>,
}

#[derive(Debug, RustcEncodable)]
Expand Down Expand Up @@ -315,7 +315,7 @@ impl From<StructData> for Def {
children: data.fields.into_iter().map(|id| From::from(id)).collect(),
decl_id: None,
docs: data.docs,
sig: Some(data.sig),
sig: Some(From::from(data.sig)),
}
}
}
Expand Down Expand Up @@ -379,7 +379,7 @@ impl From<MacroData> for Def {
children: vec![],
decl_id: None,
docs: data.docs,
sig: data.sig,
sig: data.sig.map(|s| From::from(s)),
}
}
}
Expand Down Expand Up @@ -507,3 +507,43 @@ impl From<MacroUseData> for MacroRef {
}
}
}

#[derive(Debug, RustcEncodable)]
pub struct JsonSignature {
span: SpanData,
text: String,
ident_start: usize,
ident_end: usize,
defs: Vec<JsonSigElement>,
refs: Vec<JsonSigElement>,
}

impl From<Signature> for JsonSignature {
fn from(data: Signature) -> JsonSignature {
JsonSignature {
span: data.span,
text: data.text,
ident_start: data.ident_start,
ident_end: data.ident_end,
defs: data.defs.into_iter().map(|s| From::from(s)).collect(),
refs: data.refs.into_iter().map(|s| From::from(s)).collect(),
}
}
}

#[derive(Debug, RustcEncodable)]
pub struct JsonSigElement {
id: Id,
start: usize,
end: usize,
}

impl From<SigElement> for JsonSigElement {
fn from(data: SigElement) -> JsonSigElement {
JsonSigElement {
id: From::from(data.id),
start: data.start,
end: data.end,
}
}
}

0 comments on commit e9ecd88

Please sign in to comment.