Skip to content

Comments

Fix: type to format mapping only accepts exact match#70

Merged
hit9 merged 1 commit intohit9:masterfrom
D-Walther:test-fuzzy-type-match
Aug 27, 2025
Merged

Fix: type to format mapping only accepts exact match#70
hit9 merged 1 commit intohit9:masterfrom
D-Walther:test-fuzzy-type-match

Conversation

@D-Walther
Copy link
Contributor

Partly addresses #68.


Issue:

  • Fetching a derived type (e.g. IntegerConstant) resulted in no match, even if the dictionary has a value for Constant.
  • This made it so that combining option c.name_prefix = "lowercase" with const MY_CONST = 42; would result in #define lowercaseMY_CONST 42, as it would leave the capitalization untouched.

Fix:

  • Traverse the key's __mro__, perform a lookup of each base type and return the first (and therefore best) match.
  • Note: exact type matches are still prioritized.

Suggestion:

  • Currently the c-formatter maps Constant: "upper", however Constant: ("snake", "upper") seems like the more fitting option to me. Thoughts?

- Fetching a derived type (e.g. `IntegerConstant`) resulted in no match, even if the dictionary has a value set for `Constsant`.
- This made it so combining`option c.name_prefix = "lowercase_"` with `const MY_CONST = 4;` would result in `#define lowercase_MY_CONST 4`, as it would leave the capitalization untouched.
hit9 added a commit that referenced this pull request Aug 27, 2025
@hit9 hit9 mentioned this pull request Aug 27, 2025
@hit9
Copy link
Owner

hit9 commented Aug 27, 2025

Thanks.

Bug confirmed.

Reproducible codes:

proto example
option c.name_prefix = "lowercase"
const MY_CONST = 42;

Generated c files:

// Code generated by bitproto. DO NOT EDIT.

#ifndef __BITPROTO__EXAMPLE_H__
#define __BITPROTO__EXAMPLE_H__ 1

#include <inttypes.h>
#include <stddef.h>
#include <stdint.h>
#ifndef __cplusplus
#include <stdbool.h>
#endif

#include "bitproto.h"

#if defined(__cplusplus)
extern "C" {
#endif

#define lowercaseMY_CONST 42      // <======= here.

#if defined(__cplusplus)
}
#endif

#endif

Likewise, integer constant's capitalization is also not working for Go and Python output.

Merged into #72

hit9 added a commit that referenced this pull request Aug 27, 2025
@hit9 hit9 merged commit 01d4212 into hit9:master Aug 27, 2025
10 checks passed
@hit9 hit9 mentioned this pull request Sep 20, 2025
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.

2 participants