Repository navigation
Escape keyword-named identifiers in the C generator [patch] - #446
Merged
Merged
Conversation
A struct field, parameter, local or free function named after a C keyword came out verbatim, so the header failed to compile: a field called auto or register, or a function called for, was enough. C now appends an underscore at each declaration, and references, designated initialisers and calls to a free function go through the same hook so they agree. The set is the C11 keywords plus the ones C23 adds; true, false and nullptr are left as written when a reference means them. Member functions are already spelled after their type (Holder_default) and need nothing. Part of #106. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3mc54mR7dMPMARSVv
So it does not sit at the same insertion point as the Go generator's keyword tests, which would make whichever of the two pull requests merges second conflict. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3mc54mR7dMPMARSVv
This was referenced Nov 4, 2026
Keeps both the C reserved words and main's SharesNameWithGetter override. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5jpiuVuBRXSgitSY1
|
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.



Part of #106 (C target). This stands alone on
mainand is independent of the Go PR #445. After both merge, only JavaScript is left.What was wrong
The C generator had no reserved-word set. Struct fields are not prefixed with the type name; only member functions are (
Holder_x). So a field, parameter, local or free function named after a C keyword came out as written, and the header did not compile:Change
CGenerator.ReservedWordslists the C11 keywords plus the ones C23 adds (bool,true,nullptr,typeof, …). It uses the baseEscapeIdentifier, which appends_.CFamilyGenerator.SpellDeclarator/SpellConstantDeclarator, which callEscapeIdentifier. Designated initialisers (.auto_ = 3) and references go through the shared hooks. Adding the set is enough for all of them.SpellFunctionNameescapes the name of a free function. A member function is alreadyType_name, so it can never be a keyword.GenerateCallExpressionspells a call with no receiver throughSpellCallee, sofor(5, 6)becomesfor_(5, 6). A call with a receiver keeps the name the caller wrote, which is the already-lowered member function name.IsReceiverWordkeepstrue,falseandnullptras written when a reference means the literal.Not covered here: the function-pointer member an interface's vtable struct declares,
(*name), is still written as it is.Tests
C_KeywordNamesCompileAndResolvebuilds a struct withautoandregisterfields and a designated-initialiser constructor, plus a free functionfor(do, case)with a localgotoand arelaythat calls it. It compiles them withcc -std=c11 -pedantic-errorsand runs a driver that reads each escaped name back. It failed before this change with the errors above.dotnet test --project Coder.Test/Coder.Test.csproj).Generated by Claude Code