Skip to content

feat: replace regex ino prototype generation with clang AST parsing #648

Description

@zackees

Context

fbuild currently generates function prototypes for .ino preprocessing with regex-based extraction.

That is brittle for real C++ syntax, including templates, attributes, namespaces, multiline signatures, default arguments, comments, macros, references, qualifiers, and other common sketch patterns.

Relevant area:

  • crates/fbuild-build/src/source_scanner.rs

Proposal

Replace regex-based .ino function prototype generation with a clang AST-based implementation, or an equivalent parser-backed approach that is robust against normal C++ syntax.

The implementation should preserve Arduino/PlatformIO compatibility while avoiding accidental prototypes from control-flow statements, macros, lambdas, class methods, or invalid parse fragments.

Acceptance criteria

  • Prototype generation no longer depends on brittle regex matching.
  • Tests cover common Arduino sketch functions and complex C++ signatures.
  • Tests cover cases that should not produce prototypes, including lambdas, class methods, macros, control-flow blocks, and namespaced definitions.
  • Generated prototypes are stable across repeated runs.
  • Any clang dependency/runtime requirement is documented.

Open questions

  • Should this use clang directly, libclang bindings, clang tooling JSON output, or a smaller parser-backed compatibility layer?
  • How should parsing work before generated prototypes exist, given Arduino-style sketches may not be valid C++ yet?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions