[c] Codegen improvements.

This commit is contained in:
Mario Zechner 2025-07-08 23:34:17 +02:00
parent 759434e461
commit 4fd23d3abe
5 changed files with 61 additions and 85 deletions

1
.gitignore vendored
View File

@ -242,3 +242,4 @@ spine-cpp/extraction.log
extraction.log
spine-c-new/codegen/dist
spine-c-new/codegen/all-spine-types.json
spine-c-new/codegen/spine-cpp-types.json

View File

@ -1,6 +1,3 @@
- We must review any and all code in the spine-c-new codegen
- Read README.md in spine-c-new/codegen
- find the main entry point, then
- Generate language bindings from spine-cpp-lite
- Create a TypeScript-based generator that takes spine-cpp-lite.h and generates:
- Swift bindings (matching current spine-ios output from spine-cpp-lite-codegen.py)

View File

@ -1,39 +0,0 @@
# spine-c-new codegen should not special case spine_bool but use stdbool instead
**Status:** Refining
**Created:** 2025-07-08T22:03:22
**Agent PID:** 23353
## Original Todo
- spine-c-new codegen should not special case spine_bool but use stdbool instead.
## Description
The spine-c-new codegen currently defines `spine_bool` as `int32_t` for C compatibility. This task involves updating the codegen to use the standard C99 `bool` type from `<stdbool.h>` instead of the custom `spine_bool` typedef. This will make the C API more modern and standard-compliant.
Currently:
- `spine_bool` is typedef'd as `int32_t` in base.h
- The codegen maps C++ `bool` to `spine_bool` throughout
- All generated code uses `spine_bool` instead of standard `bool`
The change will:
- Use standard C99 `bool` from `<stdbool.h>`
- Remove the special-casing in the codegen
- Make the API more standards-compliant
## Implementation Plan
- [ ] Update typedef in base.h to use stdbool.h instead of int32_t (spine-c-new/src/base.h:65)
- [ ] Update type mapping in types.ts from 'spine_bool' to 'bool' (spine-c-new/codegen/src/types.ts:70)
- [ ] Update pointer type handling for bool* in types.ts (spine-c-new/codegen/src/types.ts:148-149)
- [ ] Update reference type handling for bool& in types.ts (spine-c-new/codegen/src/types.ts:176)
- [ ] Update array element mapping in array-scanner.ts (spine-c-new/codegen/src/array-scanner.ts:103)
- [ ] Update return type check in array-generator.ts (spine-c-new/codegen/src/generators/array-generator.ts:148)
- [ ] Update default values for bool in array-generator.ts (spine-c-new/codegen/src/generators/array-generator.ts:209,216)
- [ ] Update default return value check in method-generator.ts (spine-c-new/codegen/src/generators/method-generator.ts:346)
- [ ] Run codegen to regenerate all C wrapper code
- [ ] Update test file to ensure bool types work correctly (spine-c-new/test/test.c)
- [ ] Automated test: Run codegen and verify it completes without errors
- [ ] Automated test: Verify generated code compiles with C compiler
- [ ] User test: Build spine-c-new with cmake and verify compilation succeeds
- [ ] User test: Run test.c to verify bool values work correctly (true/false instead of 1/0)
## Notes

16
spine-c-new/build.sh Executable file
View File

@ -0,0 +1,16 @@
#!/bin/bash
set -e
cd "$(dirname "$0")"
for arg in "${@:-clean build}"; do
case $arg in
clean) rm -rf build ;;
build)
mkdir -p build && cd build
[ -f CMakeCache.txt ] || cmake .. -DCMAKE_BUILD_TYPE=Debug
make -j$(sysctl -n hw.ncpu 2>/dev/null || nproc 2>/dev/null || echo 4)
cd ..
;;
esac
done

View File

@ -131,14 +131,15 @@ async function main() {
console.log(`Found ${classes.length} classes/structs and ${enums.length} enums to generate`);
// Check for const/non-const conflicts
checkConstNonConstConflicts(classes, exclusions);
// Initialize generators
const constructorGen = new ConstructorGenerator();
const methodGen = new MethodGenerator(exclusions);
const enumGen = new EnumGenerator();
const fileWriter = new FileWriter(path.join(__dirname, '../../src/generated'));
// Check for const/non-const conflicts
checkConstNonConstConflicts(classes, exclusions);
// Generate code for each type
for (const type of classes) {