Open bantl23 opened 9 years ago
Being able to create something like namespaces for generated symbol names in the target language with such a prefix option would be very useful. Especially being able to define the prefix independently of the ASN.1 schemas.
Have a look at osmocom/asn1c@5e2364f614b114a5373bf0a445e31b682c5ff3bb in aper-prefix-onto-upstream branch
Code that triggers this issue: File test.ASN:
B DEFINITIONS AUTOMATIC TAGS::= BEGIN
OurInt ::= INTEGER (0..16)
END
A DEFINITIONS AUTOMATIC TAGS::= BEGIN
OurInt ::= INTEGER (0..8)
END
> asn1c test.ASN -fcompound-names
FATAL: ASN.1 expression "OurInt" at line 9 of module A
clashes with expression "OurInt" at line 3 of module B.
Rename or remove either instance to resolve the conflict in test.ASN
I have tested on https://github.com/vlm/asn1c at HEAD, at #115 which is pulling in the prefix fix from osmocom and on https://github.com/osmocom/asn1c/tree/aper-prefix-onto-upstream at HEAD.
There is still a need to add custom prefixes to all the classnames if needed. This is useful if other classes have the same name, that is comming from a thirdparty.
hi @pitzor , you can use this branch of my repository : https://github.com/brchiu/asn1c/tree/s1ap or @velichkov 's branch of his repository which adds some more his own fixes : https://github.com/velichkov/asn1c/tree/s1ap
With these two versions, you can specify environment variable ASN1C_PREFIX
for generating code and append this prefix in generated data structures.
export ASN1C_PREFIX=S1AP_
asn1c -pdu=all -fcompound-names -findirect-choice -fno-include-deps -gen-PER s1ap-14.4.0.asn1
For example, Criticality
type will generate S1AP_Ciricality.h
file which contains S1AP_Criticality_t
type.
This is an re-implementation
of aforementioned prefix feature from osmocom (or OAI ?). I have used it in my newly created branch to OAI.
https://gitlab.eurecom.fr/oai/openairinterface5g/tree/feature-s1ap-r14-based-on-new-asn1c , As for the exemplified ASN.1 stated by @AlexTelon, using these two branches, module name A and module name B will be appended to code generated for two Outer types.
However, I admit there still be some more unsolved name resolution problems existed, for example item 2 of #254.
Ok thanks, I will look it up!
I tested your branch and it does the trick! I realize that this fix is not in the master/master_mouse07410 branch and it would be really appreciated if this will make it there but maybe as a flag instead of an env variable. Another thing I would like to see is the possibility to append pdus to the pdu_collection as they are generated.
@pitzor , have you specify -pdu=all
or -pdu=auto
in your command line when invoking asn1c
? You can refer to Makefile
s under various examples directories.
yes I have, but the problem is that I need to call asn1c for each asn file (as I need the prefix) and the pdu_collection will get overwritten each time
@pitzor , if the prefix are the same for this set of asn files, e.g. 3GPP's S1AP has S1AP-PDU-Descriptions.asn
, S1AP-IEs.asn
, S1AP-Containers.asn
..... in its specification and people would like to add the same S1AP_
to every types created.
Then the command line :
ASN1C_PREFIX=S1AP_ asn1c -pdu=all -fcompound-names -findirect-choice -fno-include-deps -gen-PER S1AP-PDU-Descriptions.asn S1AP-IEs.asn S1AP-Containers.asn ....
can handle them in batch.
However, due to some limitation of asn1c
, I prefer to concatenate separate ASN.1 files into a single ASN.1 file, e.g. s1ap-14.4.0.asn1
in my previous example then process it will be a better way.
I have an ASN.1 ISO specification where structures are duplicated within different modules. This causes clashes when I run asn1c even with the -fcompound-names option. I'm requesting an additional option where modules names can be prepended to the structure names as discussed on the sourceforge website:
http://sourceforge.net/p/asn1c/discussion/357921/thread/034be54d/#07ad