-
Notifications
You must be signed in to change notification settings - Fork 65
feat: add typed enums and allow type-specifier to be suffixed #1544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mhasel
wants to merge
6
commits into
master
Choose a base branch
from
mihr/typed-enums
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8d97223
feat: add typed enums
mhasel 2460c83
fmt
mhasel 9f534b2
Merge branch 'master' into mihr/typed-enums
mhasel b676e54
move evaluation to its own pass after constant resolution
mhasel c27527a
add issue reference to ignored tests
mhasel d34959b
remove some nesting
mhasel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
compiler/plc_diagnostics/src/diagnostics/error_codes/E122.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # E122: Invalid enum base type | ||
|
|
||
| This error occurs when an enum is declared with a base type that is not a valid integer type. Enums in IEC 61131-3 can only use integer types as their underlying representation. | ||
|
|
||
| ## Example | ||
|
|
||
| ```st | ||
| TYPE Color : STRING (red := 1, green := 2, blue := 3); | ||
| END_TYPE | ||
| ``` | ||
|
|
||
| In this example, `STRING` is not a valid base type for an enum. Only integer types are allowed. | ||
|
|
||
| ## Another example | ||
|
|
||
| ```st | ||
| TYPE Status : REAL (active := 1, inactive := 0); | ||
| END_TYPE | ||
|
|
||
| TYPE Timestamp : TIME (start := 0, stop := 1); | ||
| END_TYPE | ||
| ``` | ||
|
|
||
| These examples show other invalid base types: | ||
| - `REAL` is a floating-point type, not an integer type | ||
| - `TIME` is a time/date type, which although internally represented as an integer, should not be used as an enum base type | ||
|
|
||
| ## Valid integer types | ||
|
|
||
| The following integer types are valid for enum base types: | ||
| - `INT`, `UINT` - 16-bit integers | ||
| - `SINT`, `USINT` - 8-bit integers | ||
| - `DINT`, `UDINT` - 32-bit integers | ||
| - `LINT`, `ULINT` - 64-bit integers | ||
| - `BYTE` - 8-bit unsigned | ||
| - `WORD` - 16-bit unsigned | ||
| - `DWORD` - 32-bit unsigned | ||
| - `LWORD` - 64-bit unsigned | ||
|
|
||
| ## How to fix | ||
|
|
||
| **Use a valid integer type** | ||
|
|
||
| Change the base type to one of the supported integer types: | ||
|
|
||
| ```st | ||
| TYPE Color : INT (red := 1, green := 2, blue := 3); | ||
| END_TYPE | ||
|
|
||
| TYPE Status : BYTE (active := 1, inactive := 0); | ||
| END_TYPE | ||
| ``` | ||
|
|
||
| **Or omit the type specification** | ||
|
|
||
| If no specific size is required, you can omit the type specification (will default to `DINT`): | ||
|
|
||
| ```st | ||
| TYPE Color (red := 1, green := 2, blue := 3); | ||
| END_TYPE | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Design Question: Should
finalize_enum_defaults()be integrated intoevaluate_constants()?Currently,
finalize_enum_defaults()is called separately afterevaluate_constants()in three places:Arguments for keeping them separate (current approach):
Arguments for integrating into
evaluate_constants():finalize_enum_defaults()fundamentally requires resolved constants and cannot work without themShould we consider renaming to something like
resolve_constants_and_initializers()or updating theevaluate_constants()doc comment to clarify it also handles dependent initialization steps and add this pass toevaluate_constants()?