Skip to content

Commit e9ecd88

Browse files
committed
further lowering of signature data
1 parent eb27b51 commit e9ecd88

File tree

2 files changed

+89
-8
lines changed

2 files changed

+89
-8
lines changed

src/librustc_save_analysis/json_api_dumper.rs

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc::hir::def_id::DefId;
1414
use rustc_serialize::json::as_json;
1515

1616
use external_data::*;
17-
use data::{VariableKind, Visibility};
17+
use data::{VariableKind, Visibility, SigElement};
1818
use dump::Dump;
1919
use super::Format;
2020

@@ -179,7 +179,7 @@ struct Def {
179179
children: Vec<Id>,
180180
decl_id: Option<Id>,
181181
docs: String,
182-
sig: Option<Signature>,
182+
sig: Option<JsonSignature>,
183183
}
184184

185185
#[derive(Debug, RustcEncodable)]
@@ -277,7 +277,7 @@ impl From<StructData> for Option<Def> {
277277
children: data.fields.into_iter().map(|id| From::from(id)).collect(),
278278
decl_id: None,
279279
docs: data.docs,
280-
sig: Some(data.sig),
280+
sig: Some(From::from(data.sig)),
281281
}),
282282
_ => None,
283283
}
@@ -400,6 +400,7 @@ impl From<TypeDefData> for Option<Def> {
400400
}
401401
}
402402
}
403+
403404
impl From<VariableData> for Option<Def> {
404405
fn from(data: VariableData) -> Option<Def> {
405406
match data.visibility {
@@ -419,9 +420,49 @@ impl From<VariableData> for Option<Def> {
419420
parent: data.parent.map(|id| From::from(id)),
420421
decl_id: None,
421422
docs: data.docs,
422-
sig: data.sig,
423+
sig: data.sig.map(|s| From::from(s)),
423424
}),
424425
_ => None,
425426
}
426427
}
427428
}
429+
430+
#[derive(Debug, RustcEncodable)]
431+
pub struct JsonSignature {
432+
span: SpanData,
433+
text: String,
434+
ident_start: usize,
435+
ident_end: usize,
436+
defs: Vec<JsonSigElement>,
437+
refs: Vec<JsonSigElement>,
438+
}
439+
440+
impl From<Signature> for JsonSignature {
441+
fn from(data: Signature) -> JsonSignature {
442+
JsonSignature {
443+
span: data.span,
444+
text: data.text,
445+
ident_start: data.ident_start,
446+
ident_end: data.ident_end,
447+
defs: data.defs.into_iter().map(|s| From::from(s)).collect(),
448+
refs: data.refs.into_iter().map(|s| From::from(s)).collect(),
449+
}
450+
}
451+
}
452+
453+
#[derive(Debug, RustcEncodable)]
454+
pub struct JsonSigElement {
455+
id: Id,
456+
start: usize,
457+
end: usize,
458+
}
459+
460+
impl From<SigElement> for JsonSigElement {
461+
fn from(data: SigElement) -> JsonSigElement {
462+
JsonSigElement {
463+
id: From::from(data.id),
464+
start: data.start,
465+
end: data.end,
466+
}
467+
}
468+
}

src/librustc_save_analysis/json_dumper.rs

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc::hir::def_id::DefId;
1414
use rustc_serialize::json::as_json;
1515

1616
use external_data::*;
17-
use data::VariableKind;
17+
use data::{VariableKind, SigElement};
1818
use dump::Dump;
1919
use super::Format;
2020

@@ -224,7 +224,7 @@ struct Def {
224224
children: Vec<Id>,
225225
decl_id: Option<Id>,
226226
docs: String,
227-
sig: Option<Signature>,
227+
sig: Option<JsonSignature>,
228228
}
229229

230230
#[derive(Debug, RustcEncodable)]
@@ -315,7 +315,7 @@ impl From<StructData> for Def {
315315
children: data.fields.into_iter().map(|id| From::from(id)).collect(),
316316
decl_id: None,
317317
docs: data.docs,
318-
sig: Some(data.sig),
318+
sig: Some(From::from(data.sig)),
319319
}
320320
}
321321
}
@@ -379,7 +379,7 @@ impl From<MacroData> for Def {
379379
children: vec![],
380380
decl_id: None,
381381
docs: data.docs,
382-
sig: data.sig,
382+
sig: data.sig.map(|s| From::from(s)),
383383
}
384384
}
385385
}
@@ -507,3 +507,43 @@ impl From<MacroUseData> for MacroRef {
507507
}
508508
}
509509
}
510+
511+
#[derive(Debug, RustcEncodable)]
512+
pub struct JsonSignature {
513+
span: SpanData,
514+
text: String,
515+
ident_start: usize,
516+
ident_end: usize,
517+
defs: Vec<JsonSigElement>,
518+
refs: Vec<JsonSigElement>,
519+
}
520+
521+
impl From<Signature> for JsonSignature {
522+
fn from(data: Signature) -> JsonSignature {
523+
JsonSignature {
524+
span: data.span,
525+
text: data.text,
526+
ident_start: data.ident_start,
527+
ident_end: data.ident_end,
528+
defs: data.defs.into_iter().map(|s| From::from(s)).collect(),
529+
refs: data.refs.into_iter().map(|s| From::from(s)).collect(),
530+
}
531+
}
532+
}
533+
534+
#[derive(Debug, RustcEncodable)]
535+
pub struct JsonSigElement {
536+
id: Id,
537+
start: usize,
538+
end: usize,
539+
}
540+
541+
impl From<SigElement> for JsonSigElement {
542+
fn from(data: SigElement) -> JsonSigElement {
543+
JsonSigElement {
544+
id: From::from(data.id),
545+
start: data.start,
546+
end: data.end,
547+
}
548+
}
549+
}

0 commit comments

Comments
 (0)