Skip to content

Commit bc2aaad

Browse files
committed
Add post-formatters and enhance type mapping
Introduce post-generation formatters and significantly enrich type/method mapping metadata. - README: document mapping.options.formatters with examples and supported placeholders. - generator: implement formatter normalization, token expansion and subprocess execution to run configured formatters after code generation; respect continue_on_error and surface warnings/errors. - context: extend Mapped* dataclasses and TypeMapper with API types, call symbols/args, return-bridge logic, string-free symbol lookup, singleton handling, symbol overrides, bridge/param rules, and improved name handling; update map_function/map_method/map_class to populate new metadata and derive property/getter info. - normalizer: more robust type parsing (catch ValueError from clang types), map common C/C++ type spellings to IRType kinds (including pointers/references/cstrings), and return "unknown" for unresolvable cursor paths. These changes enable richer codegen metadata for downstream templates and allow auto-formatting of generated sources.
1 parent ef88f36 commit bc2aaad

File tree

4 files changed

+403
-103
lines changed

4 files changed

+403
-103
lines changed

tools/bindgen/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,32 @@ PYTHONPATH=../.. python3 -m bindgen \
464464
- `--out` 输出目录
465465
- `--dump-ir` 输出 IR JSON 便于调试
466466

467+
### 生成后格式化(Post Formatters)
468+
469+
可在 `mapping.options.formatters` 配置生成完成后的格式化命令:
470+
471+
```yaml
472+
mapping:
473+
options:
474+
formatters:
475+
- name: swiftformat-generated
476+
cmd: ["swiftformat", "{out_dir}/src"]
477+
continue_on_error: true
478+
- name: dart-format-generated
479+
cmd: ["dart", "format", "{out_dir}/src"]
480+
continue_on_error: true
481+
```
482+
483+
说明:
484+
485+
- `cmd`:必填,命令与参数数组(不走 shell)。
486+
- `continue_on_error`:可选,默认 `true`。失败时仅 warning 并继续。
487+
- `enabled`:可选,默认 `true`,可按项关闭 formatter。
488+
- 占位符支持:
489+
- `{out_dir}`:`--out` 指定的输出目录(绝对路径)
490+
- `{config_dir}`:`config.yaml` 所在目录
491+
- `{project_dir}`:执行 bindgen 时的当前工作目录
492+
467493
## 开发计划(里程碑)
468494

469495
1. **MVP**

0 commit comments

Comments
 (0)