Expand description
Structural-mode C frontend and the shared C-family CST walking machinery.
The file is parsed with the tree-sitter C grammar and the resulting
error-tolerant concrete syntax tree is mapped onto the language-neutral
SyntaxIrFile: a comment-free token stream plus a tree of IrNodes
built from structurally meaningful grammar nodes only. Interior expression
detail (member accesses, casts, non-assignment binary operators,
parentheses) stays token-only under the nearest ancestor node. Statement
wrappers add no node of their own when their inner expression already maps
to a shape: f(); is one Shape::Call node, not an ExprStmt(Call)
pair.
The walking machinery is language-parameterized through IrMapping and
shared with the C++ structural frontend, which layers its own mapping
table on top of the C one (cpp → c → core is the fixed dependency
direction, so the shared code lives here).
§Granularity decisions specific to C
declarationmaps toShape::VarDecluniformly — locals, file-scope variables and function prototypes alike. C declarations have no lexical marker separating those roles, and prototype-vs-variable disambiguation is a semantic judgement Structural mode does not make.- Macro invocations are structurally indistinguishable from
call_expression(the grammar has no separate node for them), so they surface asShape::Call;Shape::MacroCallis never produced. - Preprocessor conditionals (
preproc_if,preproc_ifdef, …) becomeShape::Nativenodes and both branches stay in the IR unexpanded.#includeand other non-defining directives produce tokens only. - Macro replacement text is a single opaque
preproc_argleaf in the grammar; it becomes oneTokenKind::Unknowntoken.
§Degradation
Malformed regions and CST-depth truncation become Shape::Error nodes
plus byte ranges in SyntaxIrFile::error_ranges. If the parser itself
cannot be set up (grammar version mismatch) or returns no tree, the file
degrades to an empty token stream and node tree with one error range
spanning the whole file.
Structs§
- CMapping
- The C node-mapping table as an
IrMapping. - CStructural
Frontend - The C Structural-mode frontend.
Enums§
- Mapping
- How one CST node maps onto the IR.
Constants§
- STRUCTURAL_
FRONTEND_ VERSION - Version tag of this structural frontend, used as a fingerprint input. Bump it whenever a change alters the token stream or the IR tree for unchanged input.
Traits§
- IrMapping
- The per-language part of a C-family structural frontend.
Functions§
- c_
family_ node_ name - Recover a declared name where the C-family grammars provide one: the
namefield of record specifiers and macro definitions, or the identifier buried in a function definition’s declarator chain. - classify_
c - The C node-mapping table, also the fallthrough table of the C++ frontend.
- classify_
token - The shared C-family token classification.
- parse_
to_ ir - Parse
sourcewithgrammarand map the tree onto the IR undermapping. This is the shared entry point of the C-family structural frontends. - record_
mapping Shape::Recordwhen a record specifier carries a body; transparent in type-reference position (struct foo x;names a type, it defines nothing).