Skip to content

Faust passes invalid --class-name and --super-class-name identifiers to generated code #1120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Pri-yan-shu opened this issue Feb 13, 2025 · 1 comment

Comments

@Pri-yan-shu
Copy link
Contributor

Pri-yan-shu commented Feb 13, 2025

Faust doesn't correctly modify --class-name and --super-class-name to valid c++ identifiers and generates uncompilable c++ code. Its bigger issue with faust2.. scripts using filename as classname, for instance faust2lv2, so filenames that are valid (for instance starting with a digit or containing hyphen) result in error during the compilation of the generated c++ code.

@Pri-yan-shu Pri-yan-shu changed the title Faust doesn't check --class-name and --super-class-name values for validity Faust passes invalid --class-name and --super-class-name identifiers to generated code Feb 13, 2025
@Oshangsurtani
Copy link

I have already developed a prototype of this solution. Could you please review this approach, @sletz ?

Approach

The solution is to sanitize the provided identifier strings to ensure they conform to C++ identifier rules. The key steps are:

  1. Validation and Sanitization Function
    Create a helper function (e.g., sanitizeIdentifier) that:

    • Checks the first character: If it is a digit, prepend an underscore.
    • Filters through the rest of the string: Convert any illegal character (anything other than alphanumerics or underscore) into an underscore.
    • Optionally: Warn the user if the provided identifier is changed, so they are aware of the transformation.
  2. Integrate the Sanitization Function
    Modify the part of the Faust code where --class-name and --super-class-name are processed. Instead of using the raw input, pass the input through the sanitization function before using it in code generation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants