From 19122e29050315740302b3a2b7146e1aa3968ce0 Mon Sep 17 00:00:00 2001 From: David Mak Date: Fri, 13 Dec 2024 16:35:34 +0800 Subject: [PATCH] [core] codegen: Rename classes/functions for consistency - ContiguousNDArrayFields -> ContiguousNDArrayStructFields - ndarray/nditer: Add _field suffix to field accessors --- nac3core/src/codegen/types/ndarray/contiguous.rs | 14 +++++++------- nac3core/src/codegen/values/ndarray/nditer.rs | 11 +++++++---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/nac3core/src/codegen/types/ndarray/contiguous.rs b/nac3core/src/codegen/types/ndarray/contiguous.rs index 4401cb62..317539c0 100644 --- a/nac3core/src/codegen/types/ndarray/contiguous.rs +++ b/nac3core/src/codegen/types/ndarray/contiguous.rs @@ -31,7 +31,7 @@ pub struct ContiguousNDArrayType<'ctx> { } #[derive(PartialEq, Eq, Clone, Copy, StructFields)] -pub struct ContiguousNDArrayFields<'ctx> { +pub struct ContiguousNDArrayStructFields<'ctx> { #[value_type(usize)] pub ndims: StructField<'ctx, IntValue<'ctx>>, #[value_type(usize.ptr_type(AddressSpace::default()))] @@ -40,12 +40,12 @@ pub struct ContiguousNDArrayFields<'ctx> { pub data: StructField<'ctx, PointerValue<'ctx>>, } -impl<'ctx> ContiguousNDArrayFields<'ctx> { +impl<'ctx> ContiguousNDArrayStructFields<'ctx> { #[must_use] pub fn new_typed(item: BasicTypeEnum<'ctx>, llvm_usize: IntType<'ctx>) -> Self { let mut counter = FieldIndexCounter::default(); - ContiguousNDArrayFields { + ContiguousNDArrayStructFields { ndims: StructField::create(&mut counter, "ndims", llvm_usize), shape: StructField::create( &mut counter, @@ -72,7 +72,7 @@ impl<'ctx> ContiguousNDArrayType<'ctx> { )); }; - let fields = ContiguousNDArrayFields::new(ctx, llvm_usize); + let fields = ContiguousNDArrayStructFields::new(ctx, llvm_usize); check_struct_type_matches_fields( fields, @@ -93,14 +93,14 @@ impl<'ctx> ContiguousNDArrayType<'ctx> { fn fields( item: BasicTypeEnum<'ctx>, llvm_usize: IntType<'ctx>, - ) -> ContiguousNDArrayFields<'ctx> { - ContiguousNDArrayFields::new_typed(item, llvm_usize) + ) -> ContiguousNDArrayStructFields<'ctx> { + ContiguousNDArrayStructFields::new_typed(item, llvm_usize) } /// See [`NDArrayType::fields`]. // TODO: Move this into e.g. StructProxyType #[must_use] - pub fn get_fields(&self) -> ContiguousNDArrayFields<'ctx> { + pub fn get_fields(&self) -> ContiguousNDArrayStructFields<'ctx> { Self::fields(self.item, self.llvm_usize) } diff --git a/nac3core/src/codegen/values/ndarray/nditer.rs b/nac3core/src/codegen/values/ndarray/nditer.rs index 218afc19..4b31f274 100644 --- a/nac3core/src/codegen/values/ndarray/nditer.rs +++ b/nac3core/src/codegen/values/ndarray/nditer.rs @@ -69,7 +69,10 @@ impl<'ctx> NDIterValue<'ctx> { irrt::ndarray::call_nac3_nditer_next(generator, ctx, *self); } - fn element(&self, ctx: &CodeGenContext<'ctx, '_>) -> StructField<'ctx, PointerValue<'ctx>> { + fn element_field( + &self, + ctx: &CodeGenContext<'ctx, '_>, + ) -> StructField<'ctx, PointerValue<'ctx>> { self.get_type().get_fields(ctx.ctx).element } @@ -78,7 +81,7 @@ impl<'ctx> NDIterValue<'ctx> { pub fn get_pointer(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> { let elem_ty = self.parent.dtype; - let p = self.element(ctx).get(ctx, self.as_base_value(), self.name); + let p = self.element_field(ctx).get(ctx, self.as_base_value(), self.name); ctx.builder .build_pointer_cast(p, elem_ty.ptr_type(AddressSpace::default()), "element") .unwrap() @@ -91,14 +94,14 @@ impl<'ctx> NDIterValue<'ctx> { ctx.builder.build_load(p, "value").unwrap() } - fn nth(&self, ctx: &CodeGenContext<'ctx, '_>) -> StructField<'ctx, IntValue<'ctx>> { + fn nth_field(&self, ctx: &CodeGenContext<'ctx, '_>) -> StructField<'ctx, IntValue<'ctx>> { self.get_type().get_fields(ctx.ctx).nth } /// Get the index of the current element if this ndarray were a flat ndarray. #[must_use] pub fn get_index(&self, ctx: &CodeGenContext<'ctx, '_>) -> IntValue<'ctx> { - self.nth(ctx).get(ctx, self.as_base_value(), self.name) + self.nth_field(ctx).get(ctx, self.as_base_value(), self.name) } /// Get the indices of the current element.