Skip to content

Commit 3110040

Browse files
committed
save-analysis: add a kind tag to JSON dumps
1 parent 68d29cb commit 3110040

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/librustc_save_analysis/json_api_dumper.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use rustc_serialize::json::as_json;
1616
use external_data::*;
1717
use data::{VariableKind, Visibility};
1818
use dump::Dump;
19+
use super::Format;
20+
1921

2022
// A dumper to dump a restricted set of JSON information, designed for use with
2123
// libraries distributed without their source. Clients are likely to use type
@@ -81,17 +83,25 @@ impl<'b, W: Write + 'b> Dump for JsonApiDumper<'b, W> {
8183

8284
#[derive(Debug, RustcEncodable)]
8385
struct Analysis {
86+
kind: Format,
8487
prelude: Option<CratePreludeData>,
8588
imports: Vec<Import>,
8689
defs: Vec<Def>,
90+
// These two fields are dummies so that clients can parse the two kinds of
91+
// JSON data in the same way.
92+
refs: Vec<()>,
93+
macro_refs: Vec<()>,
8794
}
8895

8996
impl Analysis {
9097
fn new() -> Analysis {
9198
Analysis {
99+
kind: Format::JsonApi,
92100
prelude: None,
93101
imports: vec![],
94102
defs: vec![],
103+
refs: vec![],
104+
macro_refs: vec![],
95105
}
96106
}
97107
}

src/librustc_save_analysis/json_dumper.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_serialize::json::as_json;
1616
use external_data::*;
1717
use data::VariableKind;
1818
use dump::Dump;
19+
use super::Format;
1920

2021
pub struct JsonDumper<'b, W: Write + 'b> {
2122
output: &'b mut W,
@@ -87,6 +88,7 @@ impl<'b, W: Write + 'b> Dump for JsonDumper<'b, W> {
8788

8889
#[derive(Debug, RustcEncodable)]
8990
struct Analysis {
91+
kind: Format,
9092
prelude: Option<CratePreludeData>,
9193
imports: Vec<Import>,
9294
defs: Vec<Def>,
@@ -97,6 +99,7 @@ struct Analysis {
9799
impl Analysis {
98100
fn new() -> Analysis {
99101
Analysis {
102+
kind: Format::Json,
100103
prelude: None,
101104
imports: vec![],
102105
defs: vec![],

src/librustc_save_analysis/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ fn docs_for_attrs(attrs: &[Attribute]) -> String {
766766
result
767767
}
768768

769-
#[derive(Clone, Copy, Debug)]
769+
#[derive(Clone, Copy, Debug, RustcEncodable)]
770770
pub enum Format {
771771
Csv,
772772
Json,

0 commit comments

Comments
 (0)