asn1: Circular types and Topo. sort declarations
Many external ASN.1 modules that we have imported over time define types like this: Foo ::= SEQUENCE { bar Bar } Bar ::= SEQUENCE { aMember INTEGER } and before this change one had to re-order the definitions so that the one for `Bar` came first. No more. We can now have out of order definitions in ASN.1 modules and the compiler will topologically sort output C type declarations so that one no longer has to manually sort types in ASN.1 modules when importing them. Besides that, it is now possible to create circular data types using OPTIONAL since we generate such fields as pointers (which can then be pointers to incomplete struct declarations): Circular ::= SEQUENCE { name UTF8String, next Circular OPTIONAL } Circular types aren't necessarily useful, but they have been used in the past. E.g., the rpc.mountd protocol uses a circular type as a linked list -- it should just have used an array, of course, as that's semantically equivalent but more space efficient in its encoding, but the point is that such types exist out there.
This commit is contained in:
@@ -879,6 +879,12 @@ gen_template_import(const Symbol *s)
|
||||
gen_extern_stubs(f, s->gen_name);
|
||||
}
|
||||
|
||||
void
|
||||
generate_template_type_forward(const char *name)
|
||||
{
|
||||
fprintf(get_code_file(), "extern const struct asn1_template asn1_%s[];\n", name);
|
||||
}
|
||||
|
||||
static void
|
||||
generate_template_type(const char *varname,
|
||||
const char **dupname,
|
||||
@@ -900,8 +906,6 @@ generate_template_type(const char *varname,
|
||||
if (type->type == TTag)
|
||||
implicit = (type->tag.tagenv == TE_IMPLICIT);
|
||||
|
||||
fprintf(get_code_file(), "extern const struct asn1_template asn1_%s[];\n", tl->name);
|
||||
|
||||
template_members(&tl->template, basetype, name, type, optional, implicit, isstruct, need_offset);
|
||||
|
||||
/* if its a sequence or set type, check if there is a ellipsis */
|
||||
|
Reference in New Issue
Block a user