Skip to content

Commit

Permalink
Refactor WhereClauseOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGVSV committed Aug 2, 2023
1 parent 2df1abd commit 675d7fb
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 146 deletions.
14 changes: 6 additions & 8 deletions crates/bevy_reflect/bevy_reflect_derive/src/from_reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::derive_data::ReflectEnum;
use crate::enum_utility::{get_variant_constructors, EnumVariantConstructors};
use crate::field_attributes::DefaultBehavior;
use crate::fq_std::{FQAny, FQClone, FQDefault, FQOption};
use crate::utility::{extend_where_clause, ident_or_index, WhereClauseOptions};
use crate::utility::{ident_or_index, WhereClauseOptions};
use crate::{ReflectMeta, ReflectStruct};
use proc_macro2::Span;
use quote::{quote, ToTokens};
Expand All @@ -23,8 +23,8 @@ pub(crate) fn impl_value(meta: &ReflectMeta) -> proc_macro2::TokenStream {
let type_path = meta.type_path();
let bevy_reflect_path = meta.bevy_reflect_path();
let (impl_generics, ty_generics, where_clause) = type_path.generics().split_for_impl();
let where_from_reflect_clause =
extend_where_clause(where_clause, &WhereClauseOptions::new(meta));
let where_from_reflect_clause = WhereClauseOptions::new(meta).extend_where_clause(where_clause);

quote! {
impl #impl_generics #bevy_reflect_path::FromReflect for #type_path #ty_generics #where_from_reflect_clause {
fn from_reflect(reflect: &dyn #bevy_reflect_path::Reflect) -> #FQOption<Self> {
Expand All @@ -51,7 +51,7 @@ pub(crate) fn impl_enum(reflect_enum: &ReflectEnum) -> proc_macro2::TokenStream

// Add FromReflect bound for each active field
let where_from_reflect_clause =
extend_where_clause(where_clause, &WhereClauseOptions::new(reflect_enum.meta()));
WhereClauseOptions::new(reflect_enum.meta()).extend_where_clause(where_clause);

quote! {
impl #impl_generics #bevy_reflect_path::FromReflect for #enum_path #ty_generics #where_from_reflect_clause {
Expand Down Expand Up @@ -130,10 +130,8 @@ fn impl_struct_internal(
.split_for_impl();

// Add FromReflect bound for each active field
let where_from_reflect_clause = extend_where_clause(
where_clause,
&WhereClauseOptions::new(reflect_struct.meta()),
);
let where_from_reflect_clause =
WhereClauseOptions::new(reflect_struct.meta()).extend_where_clause(where_clause);

quote! {
impl #impl_generics #bevy_reflect_path::FromReflect for #struct_path #ty_generics #where_from_reflect_clause {
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_reflect/bevy_reflect_derive/src/impls/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::derive_data::{EnumVariant, EnumVariantFields, ReflectEnum, StructFiel
use crate::enum_utility::{get_variant_constructors, EnumVariantConstructors};
use crate::fq_std::{FQAny, FQBox, FQOption, FQResult};
use crate::impls::{impl_type_path, impl_typed};
use crate::utility::extend_where_clause;
use proc_macro2::{Ident, Span};
use quote::quote;
use syn::Fields;
Expand Down Expand Up @@ -94,7 +93,7 @@ pub(crate) fn impl_enum(reflect_enum: &ReflectEnum) -> proc_macro2::TokenStream
let (impl_generics, ty_generics, where_clause) =
reflect_enum.meta().type_path().generics().split_for_impl();

let where_reflect_clause = extend_where_clause(where_clause, &where_clause_options);
let where_reflect_clause = where_clause_options.extend_where_clause(where_clause);

quote! {
#get_type_registration_impl
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_reflect/bevy_reflect_derive/src/impls/structs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::fq_std::{FQAny, FQBox, FQDefault, FQOption, FQResult};
use crate::impls::{impl_type_path, impl_typed};
use crate::utility::{extend_where_clause, ident_or_index};
use crate::utility::ident_or_index;
use crate::ReflectStruct;
use quote::{quote, ToTokens};

Expand Down Expand Up @@ -101,7 +101,7 @@ pub(crate) fn impl_struct(reflect_struct: &ReflectStruct) -> proc_macro2::TokenS
.generics()
.split_for_impl();

let where_reflect_clause = extend_where_clause(where_clause, &where_clause_options);
let where_reflect_clause = where_clause_options.extend_where_clause(where_clause);

quote! {
#get_type_registration_impl
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::fq_std::{FQAny, FQBox, FQDefault, FQOption, FQResult};
use crate::impls::{impl_type_path, impl_typed};
use crate::utility::extend_where_clause;
use crate::ReflectStruct;
use quote::{quote, ToTokens};
use syn::{Index, Member};
Expand Down Expand Up @@ -92,7 +91,7 @@ pub(crate) fn impl_tuple_struct(reflect_struct: &ReflectStruct) -> proc_macro2::
.generics()
.split_for_impl();

let where_reflect_clause = extend_where_clause(where_clause, &where_clause_options);
let where_reflect_clause = where_clause_options.extend_where_clause(where_clause);

quote! {
#get_type_registration_impl
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_reflect/bevy_reflect_derive/src/impls/typed.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utility::{extend_where_clause, StringExpr, WhereClauseOptions};
use crate::utility::{StringExpr, WhereClauseOptions};
use quote::{quote, ToTokens};

use crate::{
Expand Down Expand Up @@ -97,7 +97,7 @@ pub(crate) fn impl_type_path(
let (impl_generics, ty_generics, where_clause) = type_path.generics().split_for_impl();

// Add Typed bound for each active field
let where_reflect_clause = extend_where_clause(where_clause, where_clause_options);
let where_reflect_clause = where_clause_options.extend_where_clause(where_clause);

quote! {
#primitive_assert
Expand Down Expand Up @@ -138,7 +138,7 @@ pub(crate) fn impl_typed(

let (impl_generics, ty_generics, where_clause) = type_path.generics().split_for_impl();

let where_reflect_clause = extend_where_clause(where_clause, where_clause_options);
let where_reflect_clause = where_clause_options.extend_where_clause(where_clause);

quote! {
impl #impl_generics #bevy_reflect_path::Typed for #type_path #ty_generics #where_reflect_clause {
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_reflect/bevy_reflect_derive/src/impls/values.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::fq_std::{FQAny, FQBox, FQClone, FQOption, FQResult};
use crate::impls::{impl_type_path, impl_typed};
use crate::utility::{extend_where_clause, WhereClauseOptions};
use crate::utility::WhereClauseOptions;
use crate::ReflectMeta;
use quote::quote;

Expand Down Expand Up @@ -34,7 +34,7 @@ pub(crate) fn impl_value(meta: &ReflectMeta) -> proc_macro2::TokenStream {
let type_path_impl = impl_type_path(meta, &where_clause_options);

let (impl_generics, ty_generics, where_clause) = type_path.generics().split_for_impl();
let where_reflect_clause = extend_where_clause(where_clause, &where_clause_options);
let where_reflect_clause = where_clause_options.extend_where_clause(where_clause);
let get_type_registration_impl = meta.get_type_registration(&where_clause_options);

quote! {
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_reflect/bevy_reflect_derive/src/registration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Contains code related specifically to Bevy's type registration.

use crate::derive_data::ReflectMeta;
use crate::utility::{extend_where_clause, WhereClauseOptions};
use crate::utility::WhereClauseOptions;
use bit_set::BitSet;
use quote::quote;

Expand All @@ -16,7 +16,7 @@ pub(crate) fn impl_get_type_registration(
let bevy_reflect_path = meta.bevy_reflect_path();
let registration_data = meta.traits().idents();
let (impl_generics, ty_generics, where_clause) = type_path.generics().split_for_impl();
let where_reflect_clause = extend_where_clause(where_clause, where_clause_options);
let where_reflect_clause = where_clause_options.extend_where_clause(where_clause);

let from_reflect_data = if meta.from_reflect().should_auto_derive() {
Some(quote! {
Expand Down
Loading

0 comments on commit 675d7fb

Please sign in to comment.