Skip to content

Commit

Permalink
using cargo clippy for coding style as well as cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioBachmann committed Jul 14, 2022
1 parent 5bfd80b commit e9f6a16
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
16 changes: 12 additions & 4 deletions src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,18 @@ impl Diagnostic {
}
}

pub fn incompatible_type_size(nature: &str, size: u32, error: &str, location: SourceRange) -> Diagnostic {
Diagnostic::SyntaxError {
message: format!("The type {} {} is too small to {} Pointer",nature, size, error),
range: location,
pub fn incompatible_type_size(
nature: &str,
size: u32,
error: &str,
location: SourceRange,
) -> Diagnostic {
Diagnostic::SyntaxError {
message: format!(
"The type {} {} is too small to {} Pointer",
nature, size, error
),
range: location,
err_no: ErrNo::type__incompatible_size,
}
}
Expand Down
21 changes: 11 additions & 10 deletions src/validation/stmt_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use crate::{
resolver::{AnnotationMap, StatementAnnotation},
typesystem::{
DataType, DataTypeInformation, Dimension, BOOL_TYPE, DATE_AND_TIME_TYPE, DATE_TYPE,
DINT_TYPE, INT_TYPE, LINT_TYPE, LREAL_TYPE, SINT_TYPE, STRING_TYPE, TIME_OF_DAY_TYPE,
TIME_TYPE, UDINT_TYPE, UINT_TYPE, ULINT_TYPE, USINT_TYPE, VOID_TYPE, WSTRING_TYPE, POINTER_SIZE,
DINT_TYPE, INT_TYPE, LINT_TYPE, LREAL_TYPE, POINTER_SIZE, SINT_TYPE, STRING_TYPE,
TIME_OF_DAY_TYPE, TIME_TYPE, UDINT_TYPE, UINT_TYPE, ULINT_TYPE, USINT_TYPE, VOID_TYPE,
WSTRING_TYPE,
},
Diagnostic,
};
Expand Down Expand Up @@ -138,21 +139,21 @@ impl StatementValidator {
.get_type_information();

//check if Datatype can hold a Pointer (u64)
if r_effective_type.is_pointer() &&
!l_effective_type.is_pointer() &&
l_effective_type.get_size() < POINTER_SIZE
{
if r_effective_type.is_pointer()
&& !l_effective_type.is_pointer()
&& l_effective_type.get_size() < POINTER_SIZE
{
self.diagnostics.push(Diagnostic::incompatible_type_size(
l_effective_type.get_name(),
l_effective_type.get_size(),
"hold a",
statement.get_location(),
));
}
}
//check if size allocated to Pointer is standart pointer size (u64)
else if l_effective_type.is_pointer() &&
!r_effective_type.is_pointer() &&
r_effective_type.get_size() < POINTER_SIZE
else if l_effective_type.is_pointer()
&& !r_effective_type.is_pointer()
&& r_effective_type.get_size() < POINTER_SIZE
{
self.diagnostics.push(Diagnostic::incompatible_type_size(
r_effective_type.get_name(),
Expand Down
23 changes: 13 additions & 10 deletions src/validation/tests/statement_validation_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ fn assign_pointer_to_too_small_type_result_in_an_error() {
//THEN assignment with different type sizes are reported
assert_eq!(
diagnostics,
vec![
Diagnostic::incompatible_type_size("DWORD",32,"hold a",(204..218).into()),
]
vec![Diagnostic::incompatible_type_size(
"DWORD",
32,
"hold a",
(204..218).into()
),]
);
}

Expand All @@ -49,9 +52,12 @@ fn assign_too_small_type_to_pointer_result_in_an_error() {
//THEN assignment with different type sizes are reported
assert_eq!(
diagnostics,
vec![
Diagnostic::incompatible_type_size("DWORD",32,"to be stored in a",(204..218).into()),
]
vec![Diagnostic::incompatible_type_size(
"DWORD",
32,
"to be stored in a",
(204..218).into()
),]
);
}

Expand All @@ -74,10 +80,7 @@ fn assign_pointer_to_lword() {
);

//THEN every assignment is valid
assert_eq!(
diagnostics,
vec![]
);
assert_eq!(diagnostics, vec![]);
}

#[test]
Expand Down

0 comments on commit e9f6a16

Please sign in to comment.