Skip to content

Commit

Permalink
update book for multiple file includes, re-enable pointer assignment …
Browse files Browse the repository at this point in the history
…validation (PLC-lang#952)

* update book for multiple file includes
  • Loading branch information
mhasel authored Sep 1, 2023
1 parent ca193d5 commit 7d17dc6
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 19 deletions.
2 changes: 2 additions & 0 deletions book/src/libraries/external_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ The interface of the function has to:
- either be included with the `-i` flag
- or be declared in `ST` using the `{external}` keyword

When including multiple header files/function interfaces, the `-i` flag must precede each individual file, e.g. `-i file1.st -i file2.st -i file3.st`. Alternatively, when including an entire folder with `-i '/liblocation/*.st'`, the path must be put in quotes, otherwise the command-line might parse the arguments in a way that is incompatible (i.e. does not precede each file with `-i`).

### Example

Given a `min` function defined in `C` as follows:
Expand Down
38 changes: 19 additions & 19 deletions src/validation/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ fn is_valid_assignment(
return true;
} else if is_invalid_char_assignment(left_type.get_type_information(), right_type.get_type_information())
// FIXME: See https://github.com/PLC-lang/rusty/issues/857
// else if is_invalid_pointer_assignment(left_type.get_type_information(), right_type.get_type_information(), index, location, validator) |
| is_invalid_pointer_assignment(left_type.get_type_information(), right_type.get_type_information(), index, location, validator)
| is_aggregate_to_none_aggregate_assignment(left_type, right_type)
| is_aggregate_type_missmatch(left_type, right_type, index)
{
Expand Down Expand Up @@ -802,7 +802,7 @@ fn is_valid_string_to_char_assignment(
false
}

fn _is_invalid_pointer_assignment(
fn is_invalid_pointer_assignment(
left_type: &DataTypeInformation,
right_type: &DataTypeInformation,
index: &Index,
Expand Down Expand Up @@ -1035,23 +1035,23 @@ fn validate_type_nature<T: AnnotationMap>(
}
}

// fn validate_assignment_type_sizes<T: AnnotationMap>(
// validator: &mut Validator,
// left: &DataType,
// right: &DataType,
// location: &SourceRange,
// context: &ValidationContext<T>,
// ) {
// if left.get_type_information().get_size(context.index)
// < right.get_type_information().get_size(context.index)
// {
// validator.push_diagnostic(Diagnostic::implicit_downcast(
// left.get_name(),
// right.get_name(),
// location.clone(),
// ))
// }
// }
fn _validate_assignment_type_sizes<T: AnnotationMap>(
validator: &mut Validator,
left: &DataType,
right: &DataType,
location: &SourceRange,
context: &ValidationContext<T>,
) {
if left.get_type_information().get_size(context.index)
< right.get_type_information().get_size(context.index)
{
validator.push_diagnostic(Diagnostic::implicit_downcast(
left.get_name(),
right.get_name(),
location.clone(),
))
}
}

mod helper {
use std::ops::Range;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
source: src/validation/tests/assignment_validation_tests.rs
expression: res
---
SyntaxError { message: "The type DINT 32 is too small to hold a Pointer", range: [SourceRange { range: 448..467 }], err_no: type__incompatible_size }
SyntaxError { message: "Invalid assignment: cannot assign '__main_v_ptr_int' to 'DINT'", range: [SourceRange { range: 448..467 }], err_no: var__invalid_assignment }
SyntaxError { message: "The type WORD 16 is too small to hold a Pointer", range: [SourceRange { range: 484..503 }], err_no: type__incompatible_size }
SyntaxError { message: "Invalid assignment: cannot assign '__main_v_ptr_int' to 'WORD'", range: [SourceRange { range: 484..503 }], err_no: var__invalid_assignment }
SyntaxError { message: "Invalid assignment: cannot assign '__POINTER_TO_REAL' to '__main_v_ptr_int'", range: [SourceRange { range: 555..575 }], err_no: var__invalid_assignment }
SyntaxError { message: "Invalid assignment: cannot assign '__POINTER_TO_STRING' to '__main_v_ptr_int'", range: [SourceRange { range: 934..956 }], err_no: var__invalid_assignment }
SyntaxError { message: "Invalid assignment: cannot assign 'STRING' to 'INT'", range: [SourceRange { range: 973..995 }], err_no: var__invalid_assignment }
SyntaxError { message: "Invalid assignment: cannot assign 'CHAR' to 'INT'", range: [SourceRange { range: 1077..1097 }], err_no: var__invalid_assignment }
SyntaxError { message: "Invalid assignment: cannot assign 'STRING' to 'INT'", range: [SourceRange { range: 1227..1258 }], err_no: var__invalid_assignment }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ SyntaxError { message: "Invalid assignment: cannot assign 'REAL' to 'STRUCT1'",
SyntaxError { message: "Invalid assignment: cannot assign 'STRUCT2' to 'STRUCT1'", range: [SourceRange { range: 870..892 }], err_no: var__invalid_assignment }
SyntaxError { message: "Invalid assignment: cannot assign 'STRUCT2' to 'STRUCT1'", range: [SourceRange { range: 978..1002 }], err_no: var__invalid_assignment }
SyntaxError { message: "Invalid assignment: cannot assign 'STRUCT2' to 'STRUCT1'", range: [SourceRange { range: 1077..1107 }], err_no: var__invalid_assignment }
SyntaxError { message: "Invalid assignment: cannot assign '__POINTER_TO_REAL' to '__main_v_ref_to_struct1'", range: [SourceRange { range: 1422..1453 }], err_no: var__invalid_assignment }
SyntaxError { message: "Invalid assignment: cannot assign '__POINTER_TO_STRING' to '__main_v_ref_to_struct1'", range: [SourceRange { range: 1470..1503 }], err_no: var__invalid_assignment }
SyntaxError { message: "Invalid assignment: cannot assign '__POINTER_TO_CHAR' to '__main_v_ref_to_struct1'", range: [SourceRange { range: 1520..1551 }], err_no: var__invalid_assignment }
SyntaxError { message: "Invalid assignment: cannot assign '__POINTER_TO_REAL' to '__main_v_ref_to_struct1'", range: [SourceRange { range: 1573..1601 }], err_no: var__invalid_assignment }
SyntaxError { message: "Invalid assignment: cannot assign '__POINTER_TO_STRING' to '__main_v_ref_to_struct1'", range: [SourceRange { range: 1619..1649 }], err_no: var__invalid_assignment }
SyntaxError { message: "Invalid assignment: cannot assign '__POINTER_TO_CHAR' to '__main_v_ref_to_struct1'", range: [SourceRange { range: 1667..1695 }], err_no: var__invalid_assignment }

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
source: src/validation/tests/statement_validation_tests.rs
expression: res
---
SyntaxError { message: "The type DWORD 32 is too small to hold a Pointer", range: [SourceRange { range: 204..218 }], err_no: type__incompatible_size }
SyntaxError { message: "Invalid assignment: cannot assign '__FOO_ptr' to 'DWORD'", range: [SourceRange { range: 204..218 }], err_no: var__invalid_assignment }

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
source: src/validation/tests/statement_validation_tests.rs
expression: res
---
SyntaxError { message: "The type DWORD 32 is too small to to be stored in a Pointer", range: [SourceRange { range: 204..218 }], err_no: type__incompatible_size }
SyntaxError { message: "Invalid assignment: cannot assign 'DWORD' to '__FOO_ptr'", range: [SourceRange { range: 204..218 }], err_no: var__invalid_assignment }

Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ expression: res
SyntaxError { message: "Cannot mix implicit and explicit call parameters!", range: [SourceRange { range: 360..364 }], err_no: call__invalid_parameter_type }
SyntaxError { message: "Cannot mix implicit and explicit call parameters!", range: [SourceRange { range: 366..370 }], err_no: call__invalid_parameter_type }
SyntaxError { message: "Invalid assignment: cannot assign 'STRING' to 'DINT'", range: [SourceRange { range: 425..439 }], err_no: var__invalid_assignment }
SyntaxError { message: "The type DINT 32 is too small to hold a Pointer", range: [SourceRange { range: 441..455 }], err_no: type__incompatible_size }
SyntaxError { message: "Invalid assignment: cannot assign '__main_var3' to 'DINT'", range: [SourceRange { range: 441..455 }], err_no: var__invalid_assignment }
SyntaxError { message: "Invalid assignment: cannot assign 'STRING' to 'DINT'", range: [SourceRange { range: 605..609 }], err_no: var__invalid_assignment }
SyntaxError { message: "The type DINT 32 is too small to hold a Pointer", range: [SourceRange { range: 611..615 }], err_no: type__incompatible_size }
SyntaxError { message: "Invalid assignment: cannot assign '__main_var3' to 'DINT'", range: [SourceRange { range: 611..615 }], err_no: var__invalid_assignment }

Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ expression: res
SyntaxError { message: "Cannot mix implicit and explicit call parameters!", range: [SourceRange { range: 354..358 }], err_no: call__invalid_parameter_type }
SyntaxError { message: "Cannot mix implicit and explicit call parameters!", range: [SourceRange { range: 360..364 }], err_no: call__invalid_parameter_type }
SyntaxError { message: "Invalid assignment: cannot assign 'STRING' to 'DINT'", range: [SourceRange { range: 420..434 }], err_no: var__invalid_assignment }
SyntaxError { message: "The type DINT 32 is too small to hold a Pointer", range: [SourceRange { range: 436..450 }], err_no: type__incompatible_size }
SyntaxError { message: "Invalid assignment: cannot assign '__main_var3' to 'DINT'", range: [SourceRange { range: 436..450 }], err_no: var__invalid_assignment }
SyntaxError { message: "Invalid assignment: cannot assign 'STRING' to 'DINT'", range: [SourceRange { range: 602..606 }], err_no: var__invalid_assignment }
SyntaxError { message: "The type DINT 32 is too small to hold a Pointer", range: [SourceRange { range: 608..612 }], err_no: type__incompatible_size }
SyntaxError { message: "Invalid assignment: cannot assign '__main_var3' to 'DINT'", range: [SourceRange { range: 608..612 }], err_no: var__invalid_assignment }

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: src/validation/tests/statement_validation_tests.rs
expression: res
---
SyntaxError { message: "Invalid assignment: cannot assign '__POINTER_TO_INT' to '__prog_input1'", range: [SourceRange { range: 1286..1308 }], err_no: var__invalid_assignment }
SyntaxError { message: "Invalid assignment: cannot assign '__POINTER_TO_REAL' to '__prog_input2'", range: [SourceRange { range: 1322..1344 }], err_no: var__invalid_assignment }
SyntaxError { message: "Invalid assignment: cannot assign '__POINTER_TO_STRING' to '__prog_input3'", range: [SourceRange { range: 1358..1380 }], err_no: var__invalid_assignment }
SyntaxError { message: "Invalid assignment: cannot assign '__POINTER_TO_INT' to '__prog_input1'", range: [SourceRange { range: 1596..1615 }], err_no: var__invalid_assignment }
SyntaxError { message: "Invalid assignment: cannot assign '__POINTER_TO_REAL' to '__prog_input2'", range: [SourceRange { range: 1630..1649 }], err_no: var__invalid_assignment }
SyntaxError { message: "Invalid assignment: cannot assign '__POINTER_TO___global_global6' to '__prog_input3'", range: [SourceRange { range: 1664..1683 }], err_no: var__invalid_assignment }

0 comments on commit 7d17dc6

Please sign in to comment.