esa / asn1scc

ASN1SCC: An open source ASN.1 compiler for embedded systems
https://www.thanassis.space/asn1.html
Other
272 stars 58 forks source link

C global constant variable name collision #286

Open dsabala opened 11 months ago

dsabala commented 11 months ago

Hi

I am using asn1scc with following arguments:

asn1-docker.sh \
--acn-enc \
--auto-test-cases \
--icduper pus/docs/autogenerated/index.html \
--field-prefix AUTO \
--type-prefix pp_ \
--c-lang \
-o $directory_output \
$directory/*.asn1 \
$directory/*.acn

Types as well as function names are prefixed with pp_ which solves names conflicts I have due to similarity between two devices asn1 codes. However I still get one name collision between global variables:

Related *.asn1

some_constant INTEGER ::= 1

Generated header file

extern const asn1SccSint some_constant;

Two issues:

Best regards

usr3-1415 commented 10 months ago

Hi,

Thank you for your detailed feedback and suggestions regarding the asn1scc arguments and the naming conflicts you've encountered.

I agree that extending the --type-prefix argument to include global, constant variables seems like a viable solution. However, this change could potentially break existing code that relies on the current naming conventions.

@maxime-esa, could you please share your thoughts on this matter? If we proceed with this update, we'll need to consider its impact on existing users. Do you think we should implement this change?

maxime-esa commented 10 months ago

@usr3-1415 that would indeed break existing code (in C), so I do not think it is a good thing to add this option without any mean to disable it.

Alternatively, a new --prefix-with-module-name option that would be mutually exclusive with --type-prefix could be introduced (or --type-prefix MODULE).

All types and constants would be prefixed the module name (Module-Name DEFINITIONS ::= ...) avoiding all risks of collisions. In essence the idea (as with type prefixes) is to create a level of namespace in C (not needed in Ada as types are grouped in packages named with the namespace already).

However this would probably complicate the String templates quite a bit.