Skip to content

Fix a number of errors in loops#308

Open
Mingun wants to merge 17 commits intokaitai-io:masterfrom
Mingun:loops
Open

Fix a number of errors in loops#308
Mingun wants to merge 17 commits intokaitai-io:masterfrom
Mingun:loops

Conversation

@Mingun
Copy link
Copy Markdown
Contributor

@Mingun Mingun commented Sep 15, 2024

This PR the result of revision of how generation of repeated attributes is implemented due to which a number of bugs was found and fixed:

This PR supersedes #234

Also, some refactoring was done: removed unused parameters and documented methods that generates loops.

Besides, _currentIteratorType was renamed to _typeOfUnderscore (this is the variable that holds type of the _ variable in expression language) because it is used also in valid: expr key to refer to the element that just was parsed.

@transverberate
Copy link
Copy Markdown

Thank you for fixing this and closing the PR. I apologize for not following up on my PR last year. I'm happy we have this consistent behavior across languages.

Mingun and others added 10 commits December 24, 2025 20:00
… `SwitchIfOps.switchCases`

PerlCompiler implements SwitchIfOps so this call already was performed
…on place

<each changed compiler> extends EveryReadIsExpression extends CommonReads
GoCompiler extends GoReads extends CommonReads
…d here

If that not the case, then a bug in compiler is present.
Exception is better rather than generating incorrect code
…e it only can be used

We do not want that type validation calculate type of actually undefined variable
The `_` variable used not only as getter to the last parsed value in repeat-until expression,
but also as getter of the value to check in the `valid` expression. So it is better to name
this field as just "type of the `_`"
Previous behavior (everything with 1 in last column was fixed):

|Language|Initial|Incremented|`_index` of first iteration
|--------|-------|-----------|---------------------------
|C++     |0      |before     |1
|C#      |0      |before     |1
|Go      |1      |after      |1
|Java    |0      |before     |1
|JS      |0      |before     |1
|Lua     |0      |after      |0
|Nim     |0?     |after      |0 (variable declared without initializer)
|Perl    |-      |-          |- (variable was not declared)
|PHP     |0      |before     |1
|Python  |0      |after      |0
|Ruby    |0      |before     |1
|Rust    |0      |before     |1

Fixes kaitai-io/kaitai_struct#958
…ndRepeatExprHeader` and `condRepeatExprFooter`
…dRepeatEosHeader` and `condRepeatEosFooter`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent compiler generated code when 'repition index' is used in 'repeat-until' expression

2 participants