feat(cc): multi-declarator per-decl pointers + preprocessor stringify#494
Merged
Conversation
Extend parse_variable_declaration so additional declarators after the first may grow their own pointer depth on top of the shared base type (``const unsigned char *p = a, *q = b;``). The file-scope path already supported this shape; the local path now mirrors it by consuming optional ``*`` tokens between COMMA and IDENT, capped at parse_type's combined two-star limit. Unblocks ``user/libbboeos/string.c`` (memcmp opens with that exact declaration); parsing now advances past line 138.
Implement the C99 §6.10.3.2 stringify operator inside function-like macro replacement-lists. A ``#`` preceding a parameter name in the body now expands at the call site to a C string literal whose content is the unexpanded argument tokens joined with single spaces, with every ``"`` and ``\`` escaped. Two surface-area changes in cc/preprocessor.py: - ``_parse_function_define`` scans the body text for ``#<param>`` sequences before lexing; each becomes a ``STRINGIFY`` sentinel token, and a ``#`` not followed by a parameter raises CompileError at define time (rather than the previous ``unexpected character`` lexer error). - ``_expand_function_macro`` materialises ``STRINGIFY`` tokens into STRING literals via the new ``_stringify_argument`` helper, and fully macro-expands argument tokens before non-stringify substitution so the standard ``STR(x) STR2(x)`` / ``STR2(x) #x`` double-indirection trick exposes the expanded value. Unblocks ``user/libbboeos/signal.c`` (transitively pulls ``_SYSNUM_STR2(x) #x`` via ``<signal.h>``); parsing now advances past line 1.
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.
Summary
Two small cc.py features, each unblocking a Phase 6 libbboeos file.
parse_variable_declarationnow consumes optional*tokens between each,and IDENT (capped at parse_type's two-star combined limit), soconst unsigned char *p = a, *q = b;and similar shapes parse at function scope. The file-scope path already supported this; the local path now mirrors it. Unblocksuser/libbboeos/string.c(memcmp's exact declaration shape) — parsing now advances past line 138.#x). Function-like macro bodies may now contain#<parameter>;_parse_function_definelifts each match into aSTRINGIFYsentinel token (raising at define time when#does not precede a parameter), and_expand_function_macromaterialises those into STRING literals per C99 §6.10.3.2. Non-stringify parameter substitution now also fully macro-expands the argument tokens first, so the standardSTR(x) STR2(x)/STR2(x) #xdouble-indirection trick exposes the expanded value (e.g.SYSNUM_STR(SYS_RTC_ALARM)becomes"0x40"). Unblocksuser/libbboeos/signal.c— parsing now advances past line 1.Both probes still fail at later, expected, unrelated points (
*++pin string.c line 166;volatilein signal.c line 5).Test plan
python3 -m pytest tests/unit/ tests/test_ccobj.py tests/test_ccld.py tests/test_ccar.py -x -q— 567 passedpython3 tests/test_cc_local_structs.py— 9 / 9python3 tests/test_cc_bits.py— 112 / 112timeout 240 python3 tests/test_asm.py— 42 / 42 byte-equivalent./make_os.sh— clean build*++p)volatile)