Skip to content

Commit f657ad3

Browse files
committed
chore: Clippy
1 parent 3a34a1c commit f657ad3

File tree

5 files changed

+21
-44
lines changed

5 files changed

+21
-44
lines changed

src/builtins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ lazy_static! {
107107
// Check if this is a qualified method reference like fb.fbSpecificMethod
108108
if let Some(resolver::StatementAnnotation::Function { qualified_name, .. }) = generator.annotations.get(reference) {
109109
// This is a qualified method reference - return the function pointer directly
110-
if let Some(fn_value) = generator.llvm_index.find_associated_implementation(&qualified_name) {
110+
if let Some(fn_value) = generator.llvm_index.find_associated_implementation(qualified_name) {
111111
return Ok(ExpressionValue::RValue(fn_value.as_global_value().as_pointer_value().as_basic_value_enum()));
112112
}
113113
}

src/codegen/generators/data_type_generator.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,10 @@ impl<'ink> DataTypeGenerator<'ink, '_> {
188188
let mut parameter_types = vec![];
189189

190190
// For methods, we need to add the 'this' parameter as the first parameter
191-
if let Some(pou_entry) = self.index.find_pou(name) {
192-
if let PouIndexEntry::Method { parent_name, .. } = pou_entry {
193-
// Get the owner class type and add it as the first parameter (this pointer)
194-
if let Ok(owner_type) = self.types_index.get_associated_type(parent_name) {
195-
parameter_types
196-
.push(owner_type.ptr_type(AddressSpace::from(ADDRESS_SPACE_GENERIC)).into());
197-
}
191+
if let Some(PouIndexEntry::Method { parent_name, .. }) = self.index.find_pou(name) {
192+
// Get the owner class type and add it as the first parameter (this pointer)
193+
if let Ok(owner_type) = self.types_index.get_associated_type(parent_name) {
194+
parameter_types.push(owner_type.ptr_type(AddressSpace::from(ADDRESS_SPACE_GENERIC)).into());
198195
}
199196
}
200197

src/codegen/generators/expression_generator.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -537,17 +537,18 @@ impl<'ink, 'b> ExpressionCodeGenerator<'ink, 'b> {
537537
let parameters_list = parameters.map(flatten_expression_list).unwrap_or_default();
538538

539539
// For method function pointers, we need to handle the instance parameter specially
540-
let (method_instance, actual_parameters) = if matches!(function_pou, PouIndexEntry::Method { .. }) && !parameters_list.is_empty() {
541-
// For methods, the first parameter is the instance, the rest are method parameters
542-
// But if there's only one parameter, it's just the instance and there are no method parameters
543-
if parameters_list.len() == 1 {
544-
(Some(&parameters_list[0]), [].as_slice())
540+
let (method_instance, actual_parameters) =
541+
if matches!(function_pou, PouIndexEntry::Method { .. }) && !parameters_list.is_empty() {
542+
// For methods, the first parameter is the instance, the rest are method parameters
543+
// But if there's only one parameter, it's just the instance and there are no method parameters
544+
if parameters_list.len() == 1 {
545+
(Some(&parameters_list[0]), [].as_slice())
546+
} else {
547+
(Some(&parameters_list[0]), &parameters_list[1..])
548+
}
545549
} else {
546-
(Some(&parameters_list[0]), &parameters_list[1..])
547-
}
548-
} else {
549-
(None, parameters_list.as_slice())
550-
};
550+
(None, parameters_list.as_slice())
551+
};
551552

552553
// For function blocks, we need special handling for parameters
553554
if matches!(function_pou, PouIndexEntry::FunctionBlock { .. }) {
@@ -1682,7 +1683,7 @@ impl<'ink, 'b> ExpressionCodeGenerator<'ink, 'b> {
16821683
}
16831684

16841685
// For regular functions or when not in a method context, return the function pointer
1685-
if let Some(fn_value) = self.llvm_index.find_associated_implementation(&qualified_name) {
1686+
if let Some(fn_value) = self.llvm_index.find_associated_implementation(qualified_name) {
16861687
return Ok(fn_value.as_global_value().as_pointer_value());
16871688
}
16881689

src/codegen/llvm_index.rs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// TODO(vosa): Remove this
2+
#![allow(clippy::wrong_self_convention)]
3+
14
// Copyright (c) 2020 Ghaith Hachem and Mathias Rieder
25
use inkwell::types::{AnyTypeEnum, BasicType, BasicTypeEnum, FunctionType, PointerType};
36
use inkwell::values::{BasicValueEnum, FunctionValue, GlobalValue, PointerValue};
@@ -25,20 +28,12 @@ pub struct LlvmTypedIndex<'ink> {
2528
}
2629

2730
pub trait TypeHelper<'ink> {
28-
fn is_basic_type(&self) -> bool;
2931
fn as_basic_type(self) -> Option<BasicTypeEnum<'ink>>;
30-
fn is_function(&self) -> bool;
3132
fn as_function(self) -> Option<FunctionType<'ink>>;
32-
fn is_void(&self) -> bool;
33-
// fn as_void(self) -> Option<VoidType<'ink>>;
3433
fn create_ptr_type(&self, address_space: AddressSpace) -> PointerType<'ink>;
3534
}
3635

3736
impl<'ink> TypeHelper<'ink> for AnyTypeEnum<'ink> {
38-
fn is_function(&self) -> bool {
39-
matches!(self, AnyTypeEnum::FunctionType(_))
40-
}
41-
4237
fn as_function(self) -> Option<FunctionType<'ink>> {
4338
if let AnyTypeEnum::FunctionType(function_type) = self {
4439
Some(function_type)
@@ -47,22 +42,6 @@ impl<'ink> TypeHelper<'ink> for AnyTypeEnum<'ink> {
4742
}
4843
}
4944

50-
fn is_void(&self) -> bool {
51-
matches!(self, AnyTypeEnum::VoidType(_))
52-
}
53-
54-
fn is_basic_type(&self) -> bool {
55-
matches!(
56-
self,
57-
AnyTypeEnum::ArrayType(_)
58-
| AnyTypeEnum::FloatType(_)
59-
| AnyTypeEnum::IntType(_)
60-
| AnyTypeEnum::PointerType(_)
61-
| AnyTypeEnum::StructType(_)
62-
| AnyTypeEnum::VectorType(_)
63-
)
64-
}
65-
6645
fn as_basic_type(self) -> Option<BasicTypeEnum<'ink>> {
6746
match self {
6847
AnyTypeEnum::ArrayType(array_type) => Some(array_type.as_basic_type_enum()),

src/resolver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ pub trait AnnotationMap {
850850
StatementAnnotation::Program { qualified_name }
851851
| StatementAnnotation::Super { name: qualified_name, .. } => Some(qualified_name.as_str()),
852852
StatementAnnotation::Type { type_name } => Some(type_name),
853-
StatementAnnotation::Function { qualified_name, .. } => Some(&qualified_name),
853+
StatementAnnotation::Function { qualified_name, .. } => Some(qualified_name),
854854
StatementAnnotation::Label { .. }
855855
| StatementAnnotation::Override { .. }
856856
| StatementAnnotation::MethodDeclarations { .. }

0 commit comments

Comments
 (0)