[FEATURE]: cJSON - generate source/header pairs#2618
Merged
Conversation
Contributor
Author
|
It seems the CI didn't trigger. Is there something I must do to have it run, or is there an issue with it? |
Fixes for the header/source split feature (header-only=false): - startSourceFile now takes the header filename at every call site and derives the source filename itself. Previously the multi-source call sites passed the source filename, so every generated .c file began with an unguarded self-include (#include <ClassName.c>) that made compilation recurse infinitely. - The redundant unconditional emitIncludeLine(headerFilename, true) after startSourceFile is gone. In header-only mode it made every generated header include itself (an unintended change to the pre-existing multi-source output); in split mode it duplicated the include emitted by startSourceFile. - The source file's include of its own header is now a quoted include, matching the existing convention: quoted includes for generated files, angle brackets only for system and vendored headers. - getSourceNameFromHeaderName anchors the extension swap (/\.h$/), so a header named my.house.h maps to my.house.c, not my.couse.h. - The header-only option is a BooleanOption instead of a string EnumOption, giving the usual --[no-]header-only CLI flags. - The five duplicated finishHeaderFile/finishSourceFile blocks are factored into finishCurrentFile, and a comment typo is fixed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- The vendored dependencies (cJSON, hashtable, list) are downloaded into a deps/ subdirectory and included with -isystem instead of -I.. Angle-bracket includes now resolve only in deps/, while quoted includes resolve relative to the including file, so a generated #include <TopLevel.h> fails to compile and the include-style convention is enforced by the build. - second.c is a second translation unit including TopLevel.h. It is compiled and linked in the split-mode compile commands, verifying that split output supports multi-TU builds (issue glideapps#2617). - Three minimal mode fixtures run one complex input (nbl-stats.json, which produces enums, unions and 22 type pairs) through the remaining option combinations: - cjson-default: single-source, header-only (the pre-existing default output mode) - cjson-multi-header: multi-source, header-only (single TU; header-only output cannot link from multiple TUs) - cjson-multi-split: multi-source with header/source pairs, compiled with *.c so every generated source file is linked - The cjson comment-injection target's output is TopLevel.h; with header-only=false a proposed filename of TopLevel.c would have named both generated files TopLevel.c. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Renders a small input through the quicktype API and asserts, for the multi-source modes, that every header gets a source file, that no generated file includes itself, that generated files are referenced with quoted includes (never angle brackets), that each source file includes its own header first, and that header-only mode emits no source files. Also pins the output filenames for a proposed filename with an inner ".h" (my.house.h -> my.house.c). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Motivation and Context
closes #2617
Previous Behaviour / Output
Currently Quicktype generates one or more header files containing both definitions and implementations.
New Behaviour / Output
Quicktype should generate header files containing only definitions, and source files containing only implementations.
How Has This Been Tested?
I have added the command line option to the test configuration and run the tests with and without this new feature enabled by manually toggling it in the configuration file. To make the tests compile the
compileCommandhave to be manually edited as well where the generated .c file must appear here depending on the value of the new command line option.After running the tests I inspected the generated test files to verify that definitions indeed ended up in the header file, and that the implementations ended up in the corresponding source file.
Unfortunately I am unfamiliar with this test suite, and I don't know how to test all the different permutations of command line options.