Fix C++ POU local state variables#934
Conversation
WalkthroughC++ POU processing and generation now preserve local variables, emit them as per-instance state, and exclude the runtime-only ChangesCPP POU state handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant preprocessPous
participant cppPouVariables
participant CppGenerators
participant Tests
preprocessPous->>cppPouVariables: augment and classify POU variables
cppPouVariables->>CppGenerators: provide CPP POU state variables
CppGenerators->>Tests: emit and validate local struct state and assignments
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
e87be2b to
0553dc9
Compare
|
Updated in commit 0553dc9. The desktop compiler now keeps the generated ST bridge, c_blocks.h, and c_blocks_code.cpp aligned. This fixes the PREVSEQ/PREV_SEND missing-member errors during Arduino pre-compilation. |
0553dc9 to
f97cd28
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/backend/editor/compiler/compiler-module.ts (1)
2805-2806: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winAdapt
PLCProjectDatabefore callingfromSchemaShape.
PLCProjectDatadefinesconfigurations, butfromSchemaShapereadsdata.configuration?.resource. The cast suppresses the mismatch, causing debug-generated ST to omit tasks, instances, and global variables.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/backend/editor/compiler/compiler-module.ts` around lines 2805 - 2806, Update the compiler flow around fromSchemaShape and runJsonTranspiler to adapt PLCProjectData’s configurations field into the configuration shape expected by fromSchemaShape, rather than suppressing the mismatch with a cast. Ensure the adapted data preserves configuration resources so generated ST includes tasks, instances, and global variables.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/backend/editor/compiler/compiler-module.ts`:
- Around line 89-94: Update the processed POU lookup in the compiler module to
match `projectData.pous` entries by their top-level `name` field instead of
`pou.data.name`, and read variables from `interface.variables` rather than
`data.variables`. Preserve the fallback to `cppPou.variables` when no matching
variables are available.
---
Outside diff comments:
In `@src/backend/editor/compiler/compiler-module.ts`:
- Around line 2805-2806: Update the compiler flow around fromSchemaShape and
runJsonTranspiler to adapt PLCProjectData’s configurations field into the
configuration shape expected by fromSchemaShape, rather than suppressing the
mismatch with a cast. Ensure the adapted data preserves configuration resources
so generated ST includes tasks, instances, and global variables.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 1902709b-3b82-49c5-9857-ae6e3d52f15b
📒 Files selected for processing (10)
src/backend/editor/compiler/compiler-module.tssrc/backend/shared/utils/PLC/__tests__/preprocess-pous.test.tssrc/backend/shared/utils/PLC/preprocess-pous.tssrc/backend/shared/utils/cpp/__tests__/generateCBlocksCode.test.tssrc/backend/shared/utils/cpp/__tests__/generateCBlocksHeader.test.tssrc/backend/shared/utils/cpp/generateCBlocksCode.tssrc/backend/shared/utils/cpp/generateCBlocksHeader.tssrc/frontend/utils/cpp/__tests__/generateSTCode.test.tssrc/frontend/utils/cpp/cppPouVariables.tssrc/frontend/utils/cpp/generateSTCode.ts
🚧 Files skipped from review as they are similar to previous changes (8)
- src/backend/shared/utils/cpp/tests/generateCBlocksHeader.test.ts
- src/backend/shared/utils/cpp/generateCBlocksHeader.ts
- src/frontend/utils/cpp/generateSTCode.ts
- src/frontend/utils/cpp/cppPouVariables.ts
- src/backend/shared/utils/PLC/preprocess-pous.ts
- src/frontend/utils/cpp/tests/generateSTCode.test.ts
- src/backend/shared/utils/cpp/generateCBlocksCode.ts
- src/backend/shared/utils/cpp/tests/generateCBlocksCode.test.ts
|
Follow-up on the outside-diff CodeRabbit finding about |
Summary
Fix C/C++ POU local variables so they are generated as per-instance state instead of being omitted from the generated C++ bridge.
Previously, only input and output variables were included in the generated
*_VARSstructs, ST pointer assignments, and C++ macros. Local variables declared on a C/C++ Function Block POU, such asPrevSeq, were referenced by user code but never declared in the generated C++ scope.Changes
localvariables, along withinput,output, andinOut, in generated C++ POU structs and macros.hasBeenInitializedsetup guard internal to the ST stub so it is not exposed as a user C++ macro or struct field.PrevSeq.Closes #933
Validation
npx jest src/frontend/utils/cpp/__tests__/generateSTCode.test.ts src/backend/shared/utils/cpp/__tests__/generateCBlocksCode.test.ts src/backend/shared/utils/cpp/__tests__/generateCBlocksHeader.test.ts src/backend/shared/utils/PLC/__tests__/preprocess-pous.test.ts --runInBandnpx eslint src/frontend/utils/cpp/cppPouVariables.ts src/frontend/utils/cpp/generateSTCode.ts src/backend/shared/utils/cpp/generateCBlocksCode.ts src/backend/shared/utils/cpp/generateCBlocksHeader.tsSummary by CodeRabbit
hasBeenInitializedsymbol) are no longer emitted as struct fields or user-visible macro tokens.