miqt/cmd/genbindings
2024-09-20 19:13:00 +12:00
..
cachedir
clang2il_test.go
clang2il.go genbindings/clang2il: add some minor function comments 2024-09-20 19:13:00 +12:00
clangexec.go
emitcabi.go genbindings/qflags: emit qflags as inner type 2024-09-20 18:41:22 +12:00
emitgo.go genbindings/qflags: emit qflags as inner type 2024-09-20 18:41:22 +12:00
exceptions.go genbindings/typedefs: centralize exceptions 2024-09-20 18:41:21 +12:00
intermediate.go genbindings/qflags: emit qflags as inner type 2024-09-20 18:41:22 +12:00
main.go genbindings/typedefs: centralize exceptions 2024-09-20 18:41:21 +12:00
README.md
transformblocklist.go
transformchildclasses_test.go
transformchildclasses.go
transformoptional.go genbindings/cabi: move method renaming to helper function 2024-09-11 18:06:17 +12:00
transformoverload.go genbindings/cabi: move method renaming to helper function 2024-09-11 18:06:17 +12:00
transformredundant.go genbindings: merge enums with redundant definitions 2024-09-16 19:03:45 +12:00
transformtypedefs_test.go genbindings/typedefs: centralize exceptions 2024-09-20 18:41:21 +12:00
transformtypedefs.go genbindings: preserve const/ptr attributes through typedefs 2024-09-18 13:08:18 +12:00
util.go

genbindings

The genbindings program regenerates the Qt bindings.

Architecture design

Bindings are generated in two passes:

Pass 1

  1. Scan input directory for header files.
  2. For each header file:
  3. Run clang --ast-dump=json to get a JSON ast.
    • This is somewhat slow, the results will be cached in ./cachedir after the first run.
    • Strip all Clang AST nodes that were included from other files, to only consider the header's own definitions.
  4. Convert Clang AST to our own intermediate representation.
  5. Run some transformations on the intermediate representation.
  6. Cache and collect the global state of all known class names, enum names, and typedefs.

Pass 2

  1. For each intermediate-representation AST:
  2. Emit "CABI" cpp/h pair.
    • The CABI is a projection of Qt into plain C. The translation unit itself is C++, but the header can be used as extern c.
  3. Emit Go binding file.
    • The Go binding uses CGO to call into the CABI binding.

Configuration

It's tested to work on with Debian 12 / Qt 5.15 / Clang 14 / GCC 12.

You should check the following configuration:

  • main.go: Input directories containing Qt headers
  • exceptions.go: Check everything