Skip to content

simplify translate-c implementation by introducing a new pseudo-ast data structures #6710

@andrewrk

Description

@andrewrk

Right now working on translate-c code is awkward because we have to simultaneously create AST nodes, which is a tree structure, while outputting a list of tokens and source in a linear order. If we had a more specialized AST data structure for translate-c, we could generate the token list and source from it instead of having to duplicate the logic.

It ends up causing bugs like this: #6707

And this hack:

zig/lib/std/zig/ast.zig

Lines 26 to 28 in 245d98d

/// translate-c uses this to avoid having to emit correct newlines
/// TODO get rid of this hack
generated: bool = false,

To explain another way, the current process is:

  • clang analysis => zig AST + source + token list => std.zig.render

Proposed process is:

  • clang analysis => TranslateCNode Tree => zig AST + source + token list => std.zig.render

The translate-c node tree data structure does not need to map to zig AST, it just has to be whatever is convenient for the translate-c implementation.

This probably would have a small performance penalty; the main objective with this proposal is to increase maintainability.

cc @Vexu

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThis proposal is planned.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.translate-cC to Zig source translation feature (@cImport)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions