From 31100403fd7a3734b9281cc530795716f94240a0 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Wed, 7 Sep 2016 11:28:13 +1200 Subject: [PATCH] save-analysis: add a `kind` tag to JSON dumps --- src/librustc_save_analysis/json_api_dumper.rs | 10 ++++++++++ src/librustc_save_analysis/json_dumper.rs | 3 +++ src/librustc_save_analysis/lib.rs | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/librustc_save_analysis/json_api_dumper.rs b/src/librustc_save_analysis/json_api_dumper.rs index 751c2d06ee7..78eaa65872a 100644 --- a/src/librustc_save_analysis/json_api_dumper.rs +++ b/src/librustc_save_analysis/json_api_dumper.rs @@ -16,6 +16,8 @@ use rustc_serialize::json::as_json; use external_data::*; use data::{VariableKind, Visibility}; use dump::Dump; +use super::Format; + // A dumper to dump a restricted set of JSON information, designed for use with // 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> { #[derive(Debug, RustcEncodable)] struct Analysis { + kind: Format, prelude: Option, imports: Vec, defs: Vec, + // These two fields are dummies so that clients can parse the two kinds of + // JSON data in the same way. + refs: Vec<()>, + macro_refs: Vec<()>, } impl Analysis { fn new() -> Analysis { Analysis { + kind: Format::JsonApi, prelude: None, imports: vec![], defs: vec![], + refs: vec![], + macro_refs: vec![], } } } diff --git a/src/librustc_save_analysis/json_dumper.rs b/src/librustc_save_analysis/json_dumper.rs index 3000376e724..2de883a55d3 100644 --- a/src/librustc_save_analysis/json_dumper.rs +++ b/src/librustc_save_analysis/json_dumper.rs @@ -16,6 +16,7 @@ use rustc_serialize::json::as_json; use external_data::*; use data::VariableKind; use dump::Dump; +use super::Format; pub struct JsonDumper<'b, W: Write + 'b> { output: &'b mut W, @@ -87,6 +88,7 @@ impl<'b, W: Write + 'b> Dump for JsonDumper<'b, W> { #[derive(Debug, RustcEncodable)] struct Analysis { + kind: Format, prelude: Option, imports: Vec, defs: Vec, @@ -97,6 +99,7 @@ struct Analysis { impl Analysis { fn new() -> Analysis { Analysis { + kind: Format::Json, prelude: None, imports: vec![], defs: vec![], diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index eeb8d02429c..99ab0d2684f 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -766,7 +766,7 @@ fn docs_for_attrs(attrs: &[Attribute]) -> String { result } -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, RustcEncodable)] pub enum Format { Csv, Json,