Skip to content

fix(compiler): sanitize node IDs for valid C macro generation#35

Merged
MadhurKumar004 merged 2 commits intopointblank-club:mainfrom
me-jain-anurag:fix/sanitize-c-identifiers
Feb 7, 2026
Merged

fix(compiler): sanitize node IDs for valid C macro generation#35
MadhurKumar004 merged 2 commits intopointblank-club:mainfrom
me-jain-anurag:fix/sanitize-c-identifiers

Conversation

@me-jain-anurag
Copy link
Contributor

Description: Fixes compilation errors in the C backend caused by node identifiers containing invalid characters like hyphens, dots, or spaces.

The issue: Node IDs often include characters that are illegal in C macros (e.g., "conv-layer.1"). The generator previously used these IDs directly, resulting in invalid C code like "#define EF_NODE_CONV-LAYER.1".

The fix:

  • Added _sanitize_identifier() helper to EdgeBackendCCode to replace non-alphanumeric characters with underscores.
  • Handled identifiers starting with digits by adding a leading underscore.
  • Updated the generation loop to pass all node IDs through this sanitizer.

Testing: Added unit tests in tests/test_parser_extended.py to verify:

  • "layer-1.input" becomes "LAYER_1_INPUT"
  • "2nd_layer" becomes "_2ND_LAYER"
  • "node@link" becomes "NODE_LINK"

Resolves: #15

Introduces _sanitize_identifier to ensure node IDs are valid C tokens.

Replaces non-alphanumeric characters and handles

leading digits with underscores to prevent compilation errors in generated headers.

Updates EdgeBackendCCode.generate to use sanitized IDs for

EF_NODE_ macros.
Adds test_c_identifier_sanitization to TestModuleAttributes class
in tests/test_parser_extended.py. Covers hyphen/dot replacement,
leading digits, and special characters to ensure robust macro generation.
@MadhurKumar004
Copy link
Collaborator

Good work, thanks for the pr

@MadhurKumar004 MadhurKumar004 merged commit 869aabc into pointblank-club:main Feb 7, 2026
1 check passed
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

Successfully merging this pull request may close these issues.

[Bug] Sanitize Node IDs in C++ Backend Generation

2 participants