asn1: Add compiler --enum-prefix=PREFIX option
C enum labels have to be globally unique. ASN.1 module ENUMERATED and
INTEGER types with named values are not globally unique. This means
that ASN.1 integer type value names and enumerations can cause conflicts
when compiled to C.
This new option allows the user to specify a prefix to apply to such
names. Then this:
Foo ::= ENUMERATED { v1 (0) }
can generate:
typedef enum Foo {
prefix_v1 = 0,
} Foo;
instead of
typedef enum Foo {
v1 = 0,
} Foo;
which is very likely to conflict.
TBD: Add option to use the type name as the prefix?
This commit is contained in:
@@ -61,6 +61,8 @@ seq_type(const char *p)
|
||||
}
|
||||
|
||||
const char *fuzzer_string = "";
|
||||
const char *enum_prefix;
|
||||
int prefix_enum;
|
||||
int fuzzer_flag;
|
||||
int support_ber;
|
||||
int template_flag;
|
||||
@@ -74,6 +76,12 @@ int help_flag;
|
||||
struct getargs args[] = {
|
||||
{ "fuzzer", 0, arg_flag, &fuzzer_flag, NULL, NULL },
|
||||
{ "template", 0, arg_flag, &template_flag, NULL, NULL },
|
||||
{ "prefix-enum", 0, arg_flag, &prefix_enum,
|
||||
"prefix C enum labels for ENUMERATED types and INTEGER types with the "
|
||||
"type's name", NULL },
|
||||
{ "enum-prefix", 0, arg_string, &enum_prefix,
|
||||
"prefix for C enum labels for ENUMERATED types and INTEGER types with "
|
||||
"enumerated values", "PREFIX" },
|
||||
{ "encode-rfc1510-bit-string", 0, arg_flag, &rfc1510_bitstring, NULL, NULL },
|
||||
{ "decode-dce-ber", 0, arg_flag, &support_ber, NULL, NULL },
|
||||
{ "support-ber", 0, arg_flag, &support_ber, NULL, NULL },
|
||||
|
||||
Reference in New Issue
Block a user