asn1: Fix IMPLICIT tagging (codegen)

This commit is contained in:
Nicolas Williams
2021-03-10 19:14:27 -06:00
parent 7f4e9db9f9
commit 05a952dbb9
5 changed files with 39 additions and 3 deletions

View File

@@ -551,6 +551,41 @@ generate_constant (const Symbol *s)
}
}
int
is_tagged_type(const Type *t)
{
/*
* Start by chasing aliasings like this:
*
* Type0 ::= ...
* Type1 ::= Type0
* ..
* TypeN ::= TypeN-1
*
* to <Type0>, then check if <Type0> is tagged.
*/
while (t->type == TType) {
if (t->subtype)
t = t->subtype;
else if (t->symbol && t->symbol->type)
t = t->symbol->type;
else
abort();
}
if (t->type == TTag && t->tag.tagenv == TE_EXPLICIT)
return 1;
if (t->type == TTag) {
if (t->subtype)
return is_tagged_type(t->subtype);
if (t->symbol && t->symbol->type)
return is_tagged_type(t->symbol->type);
/* This is the tag */
return 1;
}
return 0;
}
int
is_primitive_type(const Type *t)
{

View File

@@ -533,7 +533,7 @@ decode_type(const char *name, const Type *t, int optional, struct value *defval,
else if (t->subtype->symbol && strcmp(t->subtype->symbol->name, "HEIM_ANY"))
replace_tag = 1;
} else if (t->tag.tagenv == TE_IMPLICIT && prim && t->subtype->symbol)
replace_tag = 1;
replace_tag = is_tagged_type(t->subtype->symbol->type);
if (asprintf(&typestring, "%s_type", tmpstr) < 0 || typestring == NULL)
errx(1, "malloc");

View File

@@ -457,7 +457,7 @@ encode_type (const char *name, const Type *t, const char *tmpstr)
* functions, and those will be adding their UNIVERSAL or whatever
* tags unlike our raw primtive codec library.
*/
replace_tag = 1;
replace_tag = is_tagged_type(t->subtype->symbol->type);
if (replace_tag)
fprintf(codefile,

View File

@@ -266,7 +266,7 @@ length_type (const char *name, const Type *t,
else if (t->subtype->symbol && strcmp(t->subtype->symbol->name, "heim_any"))
replace_tag = 1;
} else if (t->tag.tagenv == TE_IMPLICIT && prim && t->subtype->symbol)
replace_tag = 1;
replace_tag = is_tagged_type(t->subtype->symbol->type);
if (replace_tag)
/*
* We're replacing the tag of the underlying type. If that type is

View File

@@ -138,6 +138,7 @@ void add_export(const char *);
int is_export(const char *);
int yyparse(void);
int is_primitive_type(const Type *);
int is_tagged_type(const Type *);
int preserve_type(const char *);
int seq_type(const char *);