diff --git a/tasks/ast_codegen/src/defs.rs b/tasks/ast_codegen/src/defs.rs index ad7b5cb69706e..4ab475fb1b28f 100644 --- a/tasks/ast_codegen/src/defs.rs +++ b/tasks/ast_codegen/src/defs.rs @@ -11,38 +11,38 @@ pub enum TypeDef { #[derive(Debug, Serialize)] pub struct StructDef { - name: TypeName, - fields: Vec, - has_lifetime: bool, + pub name: TypeName, + pub fields: Vec, + pub has_lifetime: bool, } #[derive(Debug, Serialize)] pub struct EnumDef { - name: TypeName, - variants: Vec, + pub name: TypeName, + pub variants: Vec, /// For `@inherits` inherited enum variants - inherits: Vec, - has_lifetime: bool, + pub inherits: Vec, + pub has_lifetime: bool, } #[derive(Debug, Serialize)] pub struct EnumVariantDef { - name: TypeName, - fields: Vec, - discriminant: Option, + pub name: TypeName, + pub fields: Vec, + pub discriminant: Option, } #[derive(Debug, Serialize)] pub struct EnumInheritDef { - super_name: String, - variants: Vec, + pub super_name: String, + pub variants: Vec, } #[derive(Debug, Serialize)] pub struct FieldDef { /// `None` if unnamed - name: Option, - r#type: TypeName, + pub name: Option, + pub r#type: TypeName, } impl From<&RType> for Option { diff --git a/tasks/ast_codegen/src/main.rs b/tasks/ast_codegen/src/main.rs index aa70644d5f817..871c117931352 100644 --- a/tasks/ast_codegen/src/main.rs +++ b/tasks/ast_codegen/src/main.rs @@ -100,12 +100,11 @@ impl GeneratorOutput { struct CodegenCtx { ty_table: TypeTable, ident_table: IdentTable, - schema: Vec, + schema: Schema, } struct CodegenResult { - /// One schema per definition file - schema: Vec, + schema: Schema, outputs: Vec<(/* generator name */ &'static str, /* output */ GeneratorOutput)>, } @@ -126,9 +125,10 @@ impl CodegenCtx { } } - let mut me = Self { ty_table, ident_table, schema: Vec::default() }.link(linker)?; - let schema = mods.into_iter().map(Module::build).collect::>>()?; - _ = std::mem::replace(&mut me.schema, schema); + let mut me = Self { ty_table, ident_table, schema: Schema::default() }.link(linker)?; + for m in mods { + m.build_in(&mut me.schema)?; + } Ok(me) } diff --git a/tasks/ast_codegen/src/schema.rs b/tasks/ast_codegen/src/schema.rs index a5b0ca189de63..abf9764f14e45 100644 --- a/tasks/ast_codegen/src/schema.rs +++ b/tasks/ast_codegen/src/schema.rs @@ -13,15 +13,9 @@ use crate::{util::NormalizeError, TypeName}; use super::{parse_file, Itertools, PathBuf, Rc, Read, RefCell, Result, TypeDef, TypeRef}; -#[derive(Debug, serde::Serialize)] +#[derive(Debug, Default, serde::Serialize)] pub struct Schema { - source: PathBuf, - definitions: Definitions, -} - -#[derive(Debug, serde::Serialize)] -pub struct Definitions { - types: Vec, + definitions: Vec, } #[derive(Debug, Clone)] @@ -265,16 +259,13 @@ impl Module { Ok(self) } - pub fn build(self) -> Result { + pub fn build_in(self, schema: &mut Schema) -> Result<()> { if !self.loaded { return Err(String::from(LOAD_ERROR)); } - let definitions = Definitions { - // We filter map to get rid of stuff we don't need in our schema. - types: self.items.into_iter().filter_map(|it| (&*it.borrow()).into()).collect(), - }; - Ok(Schema { source: self.path, definitions }) + schema.definitions.extend(self.items.into_iter().filter_map(|it| (&*it.borrow()).into())); + Ok(()) } }