Two extra annotations: donotinclude and typedefto #42
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds two extra annotations:
donotinclude
Currently the code generator assumes that every schema
import
statement requires a#include
directive in the corresponding generated code. However this is not always the case eg. a schema that contains only annotation declarations doesn't generate any code. The best example of this isc.capnp.h
itself (see #22) but also other language bindings eg. Rust'srust.capnp
contains only annotations too.Ideally the generator could detect this and suppress
#include
directives for any such schema file, however I couldn't figure out how to do this without multiple passes over input files and massive refactoring. The next best solution I could come up with was to have an annotation at the file level that declares that a particular ID should not result in a#include
statement. For example, in the user's schema, they would have:Note that
0xc0183dd65ffef0f3
is the file ID forc.capnp
. It does not matter whether thedonotinclude
annotation comes before or after the import statement. Multiple annotations are fine:typedefto
This is purely cosmetic. This annotation lets you declare that a struct or enum must have a typedef generated for it with a given name. For example:
...will result in the following typedef:
I did this so that code can look a little more consistent with local style guides at the calling sites. Eventually it might be nice to implement a full camelCase/snake_case conversion, but that is a great deal more work.
It does not support doing this for the "which" enums created for unions.