codeql/swift/codegen
Paolo Tranquilli a8e6dc7a54 Swift: avoid wrongly using `doc` instead of `desc` for properties 2022-11-10 09:29:02 +01:00
..
generators Swift: add possibility to specify null class 2022-11-08 11:27:14 +01:00
lib Swift: avoid wrongly using `doc` instead of `desc` for properties 2022-11-10 09:29:02 +01:00
templates Swift: add label iteration 2022-11-08 11:47:12 +01:00
test Swift: avoid wrongly using `doc` instead of `desc` for properties 2022-11-10 09:29:02 +01:00
.pep8 Swift: implement python schema 2022-09-21 15:53:09 +02:00
BUILD.bazel Swift: implement python schema 2022-09-21 15:53:09 +02:00
README.md Swift: document and partially simplify codegen 2022-06-02 15:28:57 +02:00
codegen.py Swift: implement python schema 2022-09-21 15:53:09 +02:00
requirements.txt Swift: add `trapgen` unit tests 2022-05-04 18:20:06 +02:00

README.md

Code generation suite

This directory contains the code generation suite used by the Swift extractor and the QL library. This suite will use the abstract class specification of schema.yml to generate:

Usage

By default bazel run //swift/codegen will update all checked-in generated files (dbscheme and QL sources). You can append -- followed by other options to tweak the behaviour, which is mainly intended for debugging. See bazel run //swift/codegen -- --help for a list of all options. In particular --generate can be used with a comma separated list to select what to generate (choosing among dbscheme, ql, trap and cpp).

C++ code is generated during build (see swift/extractor/trap/BUILD.bazel). After a build you can browse the generated code in bazel-bin/swift/extractor/trap/generated.

Implementation notes

The suite uses mustache templating for generation. Templates are in the templates directory, prefixed with the generation target they are used for.

Rather than passing dictionaries to the templating engine, python dataclasses are used as defined in the lib directory. For each of the four generation targets the entry point for the implementation is specified as the generate function in the modules within the generators directory.

Finally, codegen.py is the driver script gluing everything together and specifying the command line options.

Unit tests are in the test directory and can be run via bazel test //swift/codegen/test.

For more details about each specific generation target, please refer to the module docstrings in the generators directory.