Refactor type generation, remove code duplication (#352)

* codegen: fix compact unnamed fields

* Fmt

* codegen: move derives and struct_def to types

* codegen: rename struct_def to composite_def.r

* WIP: deduplicate struct def code

* Fmt

* WIP refactoring composite type codegen duplication

* Fmt

* Fix TokenStream import

* Fix field_tokens ty_path parse error

* Fix call struct generation

* Refactor ty_path()

* Optional derives and move CompactAs derive to composite_def

* Fmt

* Introduce CompositeDefFieldType

* Restore default codec derives

* Extract TypeDefParameters and TypeDefGen construction

* Fmt

* Reset codegen to master

* Introduce CompositeDefFields

* Introduce CompositeDefFields

* Fix up errors

* Fix Box field types

* Fmt

* Fix compact attribute

* Handle no fields case

* Handle no fields with trailing semi

* Fix compact field detection

* Fix generic phantom marker

* Fmt

* Fix generic type parm fields

* Clippy

* Fix up boxed call fields

* Fmt

* Add comments to composite_def.rs

* Fix license headers

* Restore Debug derive in tests

* Fix empty struct codegen test

* Use BTreeSet for type params for ordering

* code review: fix comment

* code review: refactor CompositeDefFields as enum

* Fix empty named fields

* Fix generation of call variant enum structs

* Expand field_tokens into separate methods for struct and enum variants

* Add TypeDefParameters docs

* Fix doc link

* Clippy redundant return
This commit is contained in:
Andrew Jones
2022-01-26 09:18:13 +00:00
committed by GitHub
parent 934aebcc2c
commit b0004ea79f
11 changed files with 620 additions and 454 deletions
+1 -3
View File
@@ -17,9 +17,7 @@
//! Library to generate an API for a Substrate runtime from its metadata.
mod api;
mod derives;
mod ir;
mod struct_def;
mod types;
pub use self::{
@@ -27,5 +25,5 @@ pub use self::{
generate_runtime_api,
RuntimeGenerator,
},
derives::GeneratedTypeDerives,
types::GeneratedTypeDerives,
};