forked from libre-chip/fayalite
fix private fields in #[hdl] pub struct
This commit is contained in:
parent
26a7090178
commit
fbc8ffa5ae
4 changed files with 42 additions and 26 deletions
|
|
@ -271,7 +271,6 @@ impl Type for Bundle {
|
|||
|
||||
pub trait BundleType: Type<BaseType = Bundle> {
|
||||
type Builder: Default;
|
||||
type FilledBuilder: ToExpr<Type = Self>;
|
||||
fn fields(&self) -> Interned<[BundleField]>;
|
||||
}
|
||||
|
||||
|
|
@ -374,17 +373,8 @@ impl<'a> BundleSimValueToOpaque<'a> {
|
|||
#[derive(Default)]
|
||||
pub struct NoBuilder;
|
||||
|
||||
pub struct Unfilled<T: Type>(PhantomData<T>);
|
||||
|
||||
impl<T: Type> Default for Unfilled<T> {
|
||||
fn default() -> Self {
|
||||
Self(PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
impl BundleType for Bundle {
|
||||
type Builder = NoBuilder;
|
||||
type FilledBuilder = Expr<Bundle>;
|
||||
fn fields(&self) -> Interned<[BundleField]> {
|
||||
self.0.fields
|
||||
}
|
||||
|
|
@ -420,15 +410,14 @@ macro_rules! impl_tuple_builder_fields {
|
|||
) => {
|
||||
impl<
|
||||
$($head_type_var,)*
|
||||
$cur_type_var: Type,
|
||||
$($tail_type_var,)*
|
||||
> TupleBuilder<(
|
||||
$($head_type_var,)*
|
||||
Unfilled<$cur_type_var>,
|
||||
(),
|
||||
$($tail_type_var,)*
|
||||
)>
|
||||
{
|
||||
pub fn $cur_field(self, $cur_var: impl ToExpr<Type = $cur_type_var>) -> TupleBuilder<(
|
||||
pub fn $cur_field<$cur_type_var: Type>(self, $cur_var: impl ToExpr<Type = $cur_type_var>) -> TupleBuilder<(
|
||||
$($head_type_var,)*
|
||||
Expr<$cur_type_var>,
|
||||
$($tail_type_var,)*
|
||||
|
|
@ -452,6 +441,12 @@ macro_rules! impl_tuple_builder_fields {
|
|||
($global:tt []) => {};
|
||||
}
|
||||
|
||||
macro_rules! get_unit_ty {
|
||||
($($tt:tt)*) => {
|
||||
()
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! impl_tuples {
|
||||
(
|
||||
[$({
|
||||
|
|
@ -545,8 +540,7 @@ macro_rules! impl_tuples {
|
|||
}
|
||||
}
|
||||
impl<$($T: Type,)*> BundleType for ($($T,)*) {
|
||||
type Builder = TupleBuilder<($(Unfilled<$T>,)*)>;
|
||||
type FilledBuilder = TupleBuilder<($(Expr<$T>,)*)>;
|
||||
type Builder = TupleBuilder<($(get_unit_ty!($T),)*)>;
|
||||
fn fields(&self) -> Interned<[BundleField]> {
|
||||
let ($($var,)*) = self;
|
||||
[$(BundleField { name: stringify!($num).intern(), flipped: false, ty: $var.canonical() }),*].intern_slice()
|
||||
|
|
@ -791,7 +785,6 @@ impl<T: ?Sized + Send + Sync + 'static> ToExpr for PhantomDataBuilder<T> {
|
|||
|
||||
impl<T: ?Sized + Send + Sync + 'static> BundleType for PhantomData<T> {
|
||||
type Builder = PhantomDataBuilder<T>;
|
||||
type FilledBuilder = PhantomDataBuilder<T>;
|
||||
fn fields(&self) -> Interned<[BundleField]> {
|
||||
Interned::default()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,7 +96,6 @@ impl Type for UIntInRangeMaskType {
|
|||
|
||||
impl BundleType for UIntInRangeMaskType {
|
||||
type Builder = NoBuilder;
|
||||
type FilledBuilder = Expr<UIntInRangeMaskType>;
|
||||
|
||||
fn fields(&self) -> Interned<[BundleField]> {
|
||||
let [value_name, range_name] = UINT_IN_RANGE_TYPE_FIELD_NAMES;
|
||||
|
|
@ -400,7 +399,6 @@ macro_rules! define_uint_in_range_type {
|
|||
|
||||
impl<Start: Size, End: Size> BundleType for $UIntInRangeType<Start, End> {
|
||||
type Builder = NoBuilder;
|
||||
type FilledBuilder = Expr<Self>;
|
||||
|
||||
fn fields(&self) -> Interned<[BundleField]> {
|
||||
let [value_name, range_name] = UINT_IN_RANGE_TYPE_FIELD_NAMES;
|
||||
|
|
|
|||
|
|
@ -214,3 +214,33 @@ pub struct MyTypeWithPhantomConstParameter<P: PhantomConstGet<MyPhantomConstInne
|
|||
pub a: ArrayType<Bool, GetA<P>>,
|
||||
pub b: HdlOption<GetB<P>>,
|
||||
}
|
||||
|
||||
#[hdl(outline_generated)]
|
||||
struct MyPrivateType {}
|
||||
|
||||
#[hdl(outline_generated)]
|
||||
pub(crate) struct MyPubCrateType {}
|
||||
|
||||
#[hdl(outline_generated)]
|
||||
pub struct MyTypeWithPrivateMembers {
|
||||
a: MyPrivateType,
|
||||
pub(crate) b: MyPubCrateType,
|
||||
pub c: Bool,
|
||||
}
|
||||
|
||||
#[hdl(outline_generated)]
|
||||
struct MyPrivateTypeWithArg<T> {
|
||||
v: T,
|
||||
}
|
||||
|
||||
#[hdl(outline_generated)]
|
||||
pub(crate) struct MyPubCrateTypeWithArg<T> {
|
||||
v: T,
|
||||
}
|
||||
|
||||
#[hdl(outline_generated)]
|
||||
pub struct MyTypeWithPrivateMembersWithArg<T> {
|
||||
a: MyPrivateTypeWithArg<T>,
|
||||
pub(crate) b: MyPubCrateTypeWithArg<T>,
|
||||
pub c: T,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue