use cbuilder for most braced initializers #24259
Merged
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.
StructInitializer
is now used for most braced initializers in the C generation, mostly ingenBracedInit
,getNullValueAux
,getDefaultValue
. The exceptions are:StructInitializer
yet (siNamedStruct
)ccgliterals
are untouched so all of ccgliterals can be done separately and in 1 goThere is one case where
genBracedInit
does not use cbuilder, which is the global literal variable for openarrays. The reason for this is simply that variables with C array type are not implemented, which I thought would be best to leave out of this PR.For the simplicity of the implementation, code in
getNullValueAuxT
that reset the initializer back to its initial state if theSup
field did not have any fields itself, is now disabled. This was so the compiler does not generate{}
for the Sup field, i.e.{{}}
, but every call togetNullValueAuxT
still generates{}
if the struct doesn't have any fields, so I don't know if it really breaks anything. The case where the Sup field doesn't have any fields but the struct does also would have generated{{}, field}
.Worst case, we can implement either the "resetting" or just disable the generation of the
Sup
field if there are no fields total. But a better fix might be to always generate{0}
if the struct has no fields, in line with thechar dummy
field that gets added for all objects with no fields. This doesn't seem necessary for now but might be for the NIFC output, in which case we can probably keep the logic contained inside cbuilder (if no fields generated forsiOrderedStruct
/siNamedStruct
, we add a0
for thedummy
field). This would stipulate that all uses of struct initializers are exhaustive for every field in structs.