From dbcfc9538ad024173ab2c37dedb29d400f267c14 Mon Sep 17 00:00:00 2001 From: lyken Date: Tue, 27 Aug 2024 16:33:31 +0800 Subject: [PATCH] ArrayLen::{get_length -> length} --- nac3core/src/codegen/model/array.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/nac3core/src/codegen/model/array.rs b/nac3core/src/codegen/model/array.rs index 19ebd5ce..81c7a401 100644 --- a/nac3core/src/codegen/model/array.rs +++ b/nac3core/src/codegen/model/array.rs @@ -12,7 +12,7 @@ use super::*; /// Trait for Rust structs identifying length values for [`Array`]. pub trait ArrayLen: fmt::Debug + Clone + Copy { - fn get_length(&self) -> u32; + fn length(&self) -> u32; } /// A statically known length. @@ -24,13 +24,13 @@ pub struct Len; pub struct AnyLen(pub u32); impl ArrayLen for Len { - fn get_length(&self) -> u32 { + fn length(&self) -> u32 { N } } impl ArrayLen for AnyLen { - fn get_length(&self) -> u32 { + fn length(&self) -> u32 { self.0 } } @@ -51,7 +51,7 @@ impl<'ctx, Len: ArrayLen, Item: Model<'ctx>> Model<'ctx> for Array { type Type = ArrayType<'ctx>; fn get_type(&self, generator: &G, ctx: &'ctx Context) -> Self::Type { - self.item.get_type(generator, ctx).array_type(self.len.get_length()) + self.item.get_type(generator, ctx).array_type(self.len.length()) } fn check_type, G: CodeGenerator + ?Sized>( @@ -65,11 +65,11 @@ impl<'ctx, Len: ArrayLen, Item: Model<'ctx>> Model<'ctx> for Array { return Err(ModelError(format!("Expecting ArrayType, but got {ty:?}"))); }; - if ty.len() != self.len.get_length() { + if ty.len() != self.len.length() { return Err(ModelError(format!( "Expecting ArrayType with size {}, but got an ArrayType with size {}", ty.len(), - self.len.get_length() + self.len.length() ))); } @@ -97,9 +97,9 @@ impl<'ctx, Len: ArrayLen, Item: Model<'ctx>> Instance<'ctx, Ptr /// Like `gep` but `i` is a constant. pub fn gep_const(&self, ctx: &CodeGenContext<'ctx, '_>, i: u64) -> Instance<'ctx, Ptr> { assert!( - i < u64::from(self.model.0.len.get_length()), + i < u64::from(self.model.0.len.length()), "Index {i} is out of bounds. Array length = {}", - self.model.0.len.get_length() + self.model.0.len.length() ); let i = ctx.ctx.i32_type().const_int(i, false);