save-analysis: add a kind tag to JSON dumps

This commit is contained in:
Nick Cameron 2016-09-07 11:28:13 +12:00
parent 68d29cba95
commit 31100403fd
3 changed files with 14 additions and 1 deletions

View File

@ -16,6 +16,8 @@ use rustc_serialize::json::as_json;
use external_data::*; use external_data::*;
use data::{VariableKind, Visibility}; use data::{VariableKind, Visibility};
use dump::Dump; use dump::Dump;
use super::Format;
// A dumper to dump a restricted set of JSON information, designed for use with // 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 // 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)] #[derive(Debug, RustcEncodable)]
struct Analysis { struct Analysis {
kind: Format,
prelude: Option<CratePreludeData>, prelude: Option<CratePreludeData>,
imports: Vec<Import>, imports: Vec<Import>,
defs: Vec<Def>, defs: Vec<Def>,
// 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 { impl Analysis {
fn new() -> Analysis { fn new() -> Analysis {
Analysis { Analysis {
kind: Format::JsonApi,
prelude: None, prelude: None,
imports: vec![], imports: vec![],
defs: vec![], defs: vec![],
refs: vec![],
macro_refs: vec![],
} }
} }
} }

View File

@ -16,6 +16,7 @@ use rustc_serialize::json::as_json;
use external_data::*; use external_data::*;
use data::VariableKind; use data::VariableKind;
use dump::Dump; use dump::Dump;
use super::Format;
pub struct JsonDumper<'b, W: Write + 'b> { pub struct JsonDumper<'b, W: Write + 'b> {
output: &'b mut W, output: &'b mut W,
@ -87,6 +88,7 @@ impl<'b, W: Write + 'b> Dump for JsonDumper<'b, W> {
#[derive(Debug, RustcEncodable)] #[derive(Debug, RustcEncodable)]
struct Analysis { struct Analysis {
kind: Format,
prelude: Option<CratePreludeData>, prelude: Option<CratePreludeData>,
imports: Vec<Import>, imports: Vec<Import>,
defs: Vec<Def>, defs: Vec<Def>,
@ -97,6 +99,7 @@ struct Analysis {
impl Analysis { impl Analysis {
fn new() -> Analysis { fn new() -> Analysis {
Analysis { Analysis {
kind: Format::Json,
prelude: None, prelude: None,
imports: vec![], imports: vec![],
defs: vec![], defs: vec![],

View File

@ -766,7 +766,7 @@ fn docs_for_attrs(attrs: &[Attribute]) -> String {
result result
} }
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug, RustcEncodable)]
pub enum Format { pub enum Format {
Csv, Csv,
Json, Json,