Repository navigation
Split a type from the variables declared with it in Partials - #1410
Merged
Merged
Conversation
Generated include guards and the type names Partials are about to invent both build identifiers from names C does not allow. CIdentifier.fold replaces each such character with an underscore, one for one, so a test author can predict a folded name. The include guard builds on it with its own squeezing and trimming. FFF keeps Unity's rule, which its runner names must match. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A declaration such as `static struct { int count; } s_ctx;` defines a type
and declares a variable at once. Extraction read it as a variable whose
type held the whole body, so a Partial wrote the body into both the extern
and the definition. Two copies of a tagged body are a redefinition, and two
anonymous bodies are two different types.
The extractor now records the type as an aggregate statement ahead of its
variables, and each variable names it through defined_type. Reading the
variables without the body also keeps a member's array size and the first
variable of a compound declaration, which the body used to lose.
A Partial names each such type after its first variable and writes it once,
as a typedef in the types header. A typedef leaves an anonymous type
anonymous, so a header's extern still matches the real definition in
another module.
Statements also record their kind, and type statements their tag and the
name a typedef gives them. A struct or union forward declaration now reads
as a type statement instead of as a variable.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each generated header kept its own blank-line state and recovered each statement's category by searching the module's lists. A PartialHeaderWriter now writes all three headers, as PartialSourceWriter writes the source, and the generator dispatches on a statement's kind. A CModule gives each statement the kind of the list that holds it, so the two always agree. The real header's include guard is removed from the extracted macros once, along with the generated guards, instead of being filtered at each place a header writes macros. Whether a module has types is one CModule#types? that the generator and PartialsManager share. A variable's definition text and its defining-declaration index each have one builder. Generated output is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Promotion found each static's statement again in the function by its text,
tolerating comments through a regex, and swapped placeholders in and out
around the rename. It now records where each statement sits in the
function's code block as it reads it, splices the no-ops in at those
places, and renames only the text around them. The comment holding a
statement keeps its line breaks, so a function keeps its line count.
A static that defines its type, as `static struct { int n; } st;` does,
promotes its type too. The type is named for the function and the
variable, and a tagged one takes that name as its tag, since a tag local
to the function can collide at module scope. The function's other uses of
the tag follow. Promoted items now join the module just ahead of their
function.
A struct member sharing a promoted static's name is renamed alike in its
uses. The member's own declaration sat in a statement the rename never
reached, so `s.count` and the member it named disagreed.
The no-op and text-replacement utilities promotion no longer needs are
gone, and the rename specs moved beside Partials::Rename.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PARTIAL_TYPE(module, variable) and PARTIAL_LOCAL_TYPE(module, function, variable) give the name a Partial writes for the type of a variable declared together with it. A test can then declare another object of that type, such as a copy of a module's state. Each argument pastes before anything expands, as PARTIAL_LOCAL_VAR's do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PARTIAL_LOCAL_VAR(), PARTIAL_TYPE() and PARTIAL_LOCAL_TYPE() paste their arguments into one name as a test compiles. An argument that doesn't match the module builds a name nothing declares, and the compiler reports only that name. PartialNameSpecialist recognizes such a name in a test file's compilation failure, in a build with Partials, across the common compilers' wordings. Its hedged guidance explains how the macro builds the name, what each argument must match, and the names this test's Partials actually provide. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A system build tests a module holding an anonymous struct and enum at file scope and a tagged struct inside a function, through the variables, their members and values, and ceedling.h's names for their types. An unchanged rebuild regenerates nothing. A coverage case confirms that a promoted three-line type keeps the lines after it aligned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Promotion read a function's body from the code block's first brace, so an
attribute string in the signature holding one, as in
`__attribute__((section("t{x}")))`, sent it reading from inside the string
and nothing was promoted. The body now opens at the first brace outside a
literal or comment.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Partials guide describes how a Partial splits a type from its variables, the names it gives such types, and ceedling.h's PARTIAL_TYPE() and PARTIAL_LOCAL_TYPE(). The macros reference lists both. The Partials and doctor design notes describe the extraction model, promotion, the header writer and PartialNameSpecialist. The Changelog records the fixes and the macros. Known Issues drops the items this resolves, describes the trailing-macro case as builds now meet it, and adds the local anonymous enum. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Partials generator no longer exceeds the ABC, cyclomatic, perceived complexity or method length limits, and the Partializer helper no longer exceeds the complexity limits. Nothing was added. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CI summary · 8d2844a · ✅ 25/25 jobs passed · nearest baseline bf3683b (master)
Diff coverage: 100.00% (345/345 changed lines).
All legs (examples / failures / pending)
Jobs
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A promoted statement's comment blanked the comments inside it to spaces, keeping only their line feeds, so a CRLF inside a multi-line comment lost its carriage return. Each comment now keeps both. The function line-count check moves from the real-compiler spec to the helper's own, with LF and CRLF endings. On Windows, the function text a real preprocessor hands promotion already doubles each line break, so the compiled check measured the toolchain rather than promotion. Co-Authored-By: Claude Opus 5.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.
Fixes #1401.
Problem
A Partial couldn't be generated for a module that defines a type and declares a variable in one statement, a common way to keep private state:
The extractor read such a statement as a variable whose type held the whole body. The Partial wrote that body into both the variable's extern in
_impl.hand its definition in_impl.c, and the source includes the header. Two copies of a tagged body are a redefinition, and two anonymous bodies are two different types. A function-scopestaticof this form failed the same way once promoted.Probes found three more defects with the same root:
struct { int buf[8]; }read asstruct { int buf; }.struct pair { int a[2]; } g_p1, g_p2;read as one record namedg_p2.s.countwasn't.A tag-only forward declaration,
struct node;, was also read as a variable, givingextern struct node;.Fix
CExtractorDefinedType). The type becomes an aggregate statement ahead of its variables, and each variable names it throughdefined_type. The member-array and compound bugs go with the body.struct node;reads as a type statement.ceedling_partial_<module>_<variable>_t. A typedef leaves an anonymous type anonymous, so a header'sextern struct { … } g;still matches its real definition in another module.ceedling_partial_<module>_<function>_<variable>_t. A local tag takes that name, so it can't collide at module scope. The shared-name check now covers the moved type's body, which fixes the member rename.ceedling.hgainsPARTIAL_TYPE(module, variable)andPARTIAL_LOCAL_TYPE(module, function, variable), so a test can declare another object of such a type.PartialNameSpecialistrecognizes a test file's compilation failure on a namePARTIAL_LOCAL_VAR(),PARTIAL_TYPE()orPARTIAL_LOCAL_TYPE()built and nothing declares. It explains the macro's arguments and lists the names the test's Partials provide. It speaks only with Partials enabled.PartialHeaderWriter, dispatching on kind.sanitize.CModule#types?replaces two copies of the types-header test.CIdentifier.foldis shared with include guards.Not handled here, by decision:
struct pk { … } PACKED;now reads as a type plus a variable namedPACKED, so the types header loses the attribute and the build compiles unpacked with warnings. This is to be fixed with #1395's macro-expansion work before the next release, and Known Issues describes it.Tests
}, qualifiers, initializers, asm labels, forward declarations, and statement kinds and names.wondrous_forestsystem specs pass.rake lintis clean. The regenerated RuboCop to-do only shrank: the generator and helper drop six entries.Docs
variables.md): the known-limit section becomes how the split works, the naming rule and the macros.configuration.md: the two new macros.lib/ceedling/partials/README.mdanddiagnostics/DOCTOR.md.🤖 Generated with Claude Code