Change name of oldret for each instance its used to avoid shadow
warning. From: Stefan Metzmacher <metze@samba.org>. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@15962 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -198,7 +198,7 @@ find_tag (const Type *t,
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
decode_type (const char *name, const Type *t, int optional,
|
decode_type (const char *name, const Type *t, int optional,
|
||||||
const char *forwstr)
|
const char *forwstr, const char *tmpstr)
|
||||||
{
|
{
|
||||||
switch (t->type) {
|
switch (t->type) {
|
||||||
case TType: {
|
case TType: {
|
||||||
@@ -304,7 +304,7 @@ decode_type (const char *name, const Type *t, int optional,
|
|||||||
name, m->gen_name);
|
name, m->gen_name);
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
errx(1, "malloc");
|
errx(1, "malloc");
|
||||||
decode_type (s, m->type, m->optional, forwstr);
|
decode_type (s, m->type, m->optional, forwstr, m->gen_name);
|
||||||
free (s);
|
free (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,7 +346,7 @@ decode_type (const char *name, const Type *t, int optional,
|
|||||||
"%s = calloc(1, sizeof(*%s));\n"
|
"%s = calloc(1, sizeof(*%s));\n"
|
||||||
"if (%s == NULL) { e = ENOMEM; %s; }\n",
|
"if (%s == NULL) { e = ENOMEM; %s; }\n",
|
||||||
s, s, s, forwstr);
|
s, s, s, forwstr);
|
||||||
decode_type (s, m->type, 0, forwstr);
|
decode_type (s, m->type, 0, forwstr, m->gen_name);
|
||||||
free (s);
|
free (s);
|
||||||
|
|
||||||
fprintf(codefile, "members |= (1 << %d);\n", memno);
|
fprintf(codefile, "members |= (1 << %d);\n", memno);
|
||||||
@@ -382,33 +382,45 @@ decode_type (const char *name, const Type *t, int optional,
|
|||||||
case TSetOf:
|
case TSetOf:
|
||||||
case TSequenceOf: {
|
case TSequenceOf: {
|
||||||
char *n;
|
char *n;
|
||||||
|
char *sname;
|
||||||
|
|
||||||
fprintf (codefile,
|
fprintf (codefile,
|
||||||
"{\n"
|
"{\n"
|
||||||
"size_t origlen = len;\n"
|
"size_t %s_origlen = len;\n"
|
||||||
"size_t oldret = ret;\n"
|
"size_t %s_oldret = ret;\n"
|
||||||
"void *tmp;\n"
|
"void *%s_tmp;\n"
|
||||||
"ret = 0;\n"
|
"ret = 0;\n"
|
||||||
"(%s)->len = 0;\n"
|
"(%s)->len = 0;\n"
|
||||||
"(%s)->val = NULL;\n"
|
"(%s)->val = NULL;\n"
|
||||||
"while(ret < origlen) {\n"
|
"while(ret < %s_origlen) {\n"
|
||||||
"tmp = realloc((%s)->val, "
|
"%s_tmp = realloc((%s)->val, "
|
||||||
" sizeof(*((%s)->val)) * ((%s)->len + 1));\n"
|
" sizeof(*((%s)->val)) * ((%s)->len + 1));\n"
|
||||||
"if (tmp == NULL) { %s; }\n"
|
"if (%s_tmp == NULL) { %s; }\n"
|
||||||
"(%s)->len++;\n"
|
"(%s)->len++;\n"
|
||||||
"(%s)->val = tmp;\n",
|
"(%s)->val = %s_tmp;\n",
|
||||||
name, name, name, name, name, forwstr, name, name);
|
tmpstr, tmpstr, tmpstr,
|
||||||
|
name, name,
|
||||||
|
tmpstr, tmpstr,
|
||||||
|
name, name, name,
|
||||||
|
tmpstr,
|
||||||
|
forwstr, name, name,
|
||||||
|
tmpstr);
|
||||||
|
|
||||||
asprintf (&n, "&(%s)->val[(%s)->len-1]", name, name);
|
asprintf (&n, "&(%s)->val[(%s)->len-1]", name, name);
|
||||||
if (n == NULL)
|
if (n == NULL)
|
||||||
errx(1, "malloc");
|
errx(1, "malloc");
|
||||||
decode_type (n, t->subtype, 0, forwstr);
|
asprintf (&sname, "%s_s_of", tmpstr);
|
||||||
|
if (sname == NULL)
|
||||||
|
errx(1, "malloc");
|
||||||
|
decode_type (n, t->subtype, 0, forwstr, sname);
|
||||||
fprintf (codefile,
|
fprintf (codefile,
|
||||||
"len = origlen - ret;\n"
|
"len = %s_origlen - ret;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"ret += oldret;\n"
|
"ret += %s_oldret;\n"
|
||||||
"}\n");
|
"}\n",
|
||||||
|
tmpstr, tmpstr);
|
||||||
free (n);
|
free (n);
|
||||||
|
free (sname);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TGeneralizedTime:
|
case TGeneralizedTime:
|
||||||
@@ -418,17 +430,21 @@ decode_type (const char *name, const Type *t, int optional,
|
|||||||
decode_primitive ("general_string", name, forwstr);
|
decode_primitive ("general_string", name, forwstr);
|
||||||
break;
|
break;
|
||||||
case TTag:{
|
case TTag:{
|
||||||
|
char *tname;
|
||||||
|
|
||||||
fprintf(codefile,
|
fprintf(codefile,
|
||||||
"{\n"
|
"{\n"
|
||||||
"size_t tagdatalen, oldlen;\n");
|
"size_t %s_datalen, %s_oldlen;\n",
|
||||||
|
tmpstr, tmpstr);
|
||||||
if(dce_fix)
|
if(dce_fix)
|
||||||
fprintf(codefile,
|
fprintf(codefile,
|
||||||
"int dce_fix;\n");
|
"int dce_fix;\n");
|
||||||
fprintf(codefile, "e = der_match_tag_and_length(p, len, %s, %s, %s, "
|
fprintf(codefile, "e = der_match_tag_and_length(p, len, %s, %s, %s, "
|
||||||
"&tagdatalen, &l);\n",
|
"&%s_datalen, &l);\n",
|
||||||
classname(t->tag.tagclass),
|
classname(t->tag.tagclass),
|
||||||
is_primitive_type(t->subtype->type) ? "PRIM" : "CONS",
|
is_primitive_type(t->subtype->type) ? "PRIM" : "CONS",
|
||||||
valuename(t->tag.tagclass, t->tag.tagvalue));
|
valuename(t->tag.tagclass, t->tag.tagvalue),
|
||||||
|
tmpstr);
|
||||||
if(optional) {
|
if(optional) {
|
||||||
fprintf(codefile,
|
fprintf(codefile,
|
||||||
"if(e) {\n"
|
"if(e) {\n"
|
||||||
@@ -442,32 +458,38 @@ decode_type (const char *name, const Type *t, int optional,
|
|||||||
}
|
}
|
||||||
fprintf (codefile,
|
fprintf (codefile,
|
||||||
"p += l; len -= l; ret += l;\n"
|
"p += l; len -= l; ret += l;\n"
|
||||||
"oldlen = len;\n");
|
"%s_oldlen = len;\n",
|
||||||
|
tmpstr);
|
||||||
if(dce_fix)
|
if(dce_fix)
|
||||||
fprintf (codefile,
|
fprintf (codefile,
|
||||||
"if((dce_fix = _heim_fix_dce(tagdatalen, &len)) < 0)\n"
|
"if((dce_fix = _heim_fix_dce(%s_datalen, &len)) < 0)\n"
|
||||||
"{ e = ASN1_BAD_FORMAT; %s; }\n",
|
"{ e = ASN1_BAD_FORMAT; %s; }\n",
|
||||||
forwstr);
|
tmpstr, forwstr);
|
||||||
else
|
else
|
||||||
fprintf(codefile,
|
fprintf(codefile,
|
||||||
"if (tagdatalen > len) { e = ASN1_OVERRUN; %s; }\n"
|
"if (%s_datalen > len) { e = ASN1_OVERRUN; %s; }\n"
|
||||||
"len = tagdatalen;\n", forwstr);
|
"len = %s_datalen;\n", tmpstr, forwstr, tmpstr);
|
||||||
decode_type (name, t->subtype, 0, forwstr);
|
asprintf (&tname, "%s_Tag", tmpstr);
|
||||||
|
if (tname == NULL)
|
||||||
|
errx(1, "malloc");
|
||||||
|
decode_type (name, t->subtype, 0, forwstr, tname);
|
||||||
if(dce_fix)
|
if(dce_fix)
|
||||||
fprintf(codefile,
|
fprintf(codefile,
|
||||||
"if(dce_fix){\n"
|
"if(dce_fix){\n"
|
||||||
"e = der_match_tag_and_length (p, len, "
|
"e = der_match_tag_and_length (p, len, "
|
||||||
"(Der_class)0,(Der_type)0, UT_EndOfContent, "
|
"(Der_class)0,(Der_type)0, UT_EndOfContent, "
|
||||||
"&tagdatalen, &l);\n"
|
"&%s_datalen, &l);\n"
|
||||||
"if(e) %s;\np += l; len -= l; ret += l;\n"
|
"if(e) %s;\np += l; len -= l; ret += l;\n"
|
||||||
"} else \n", forwstr);
|
"} else \n", tmpstr, forwstr);
|
||||||
fprintf(codefile,
|
fprintf(codefile,
|
||||||
"len = oldlen - tagdatalen;\n");
|
"len = %s_oldlen - %s_datalen;\n",
|
||||||
|
tmpstr, tmpstr);
|
||||||
if(optional)
|
if(optional)
|
||||||
fprintf(codefile,
|
fprintf(codefile,
|
||||||
"}\n");
|
"}\n");
|
||||||
fprintf(codefile,
|
fprintf(codefile,
|
||||||
"}\n");
|
"}\n");
|
||||||
|
free(tname);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TChoice: {
|
case TChoice: {
|
||||||
@@ -501,7 +523,7 @@ decode_type (const char *name, const Type *t, int optional,
|
|||||||
name, m->gen_name);
|
name, m->gen_name);
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
errx(1, "malloc");
|
errx(1, "malloc");
|
||||||
decode_type (s, m->type, m->optional, forwstr);
|
decode_type (s, m->type, m->optional, forwstr, m->gen_name);
|
||||||
fprintf(codefile,
|
fprintf(codefile,
|
||||||
"(%s)->element = %s;\n",
|
"(%s)->element = %s;\n",
|
||||||
name, m->label);
|
name, m->label);
|
||||||
@@ -573,71 +595,73 @@ decode_type (const char *name, const Type *t, int optional,
|
|||||||
void
|
void
|
||||||
generate_type_decode (const Symbol *s)
|
generate_type_decode (const Symbol *s)
|
||||||
{
|
{
|
||||||
int preserve = preserve_type(s->name) ? TRUE : FALSE;
|
int preserve = preserve_type(s->name) ? TRUE : FALSE;
|
||||||
|
|
||||||
fprintf (headerfile,
|
fprintf (headerfile,
|
||||||
"int "
|
"int "
|
||||||
"decode_%s(const unsigned char *, size_t, %s *, size_t *);\n",
|
"decode_%s(const unsigned char *, size_t, %s *, size_t *);\n",
|
||||||
s->gen_name, s->gen_name);
|
s->gen_name, s->gen_name);
|
||||||
|
|
||||||
fprintf (codefile, "int\n"
|
fprintf (codefile, "int\n"
|
||||||
"decode_%s(const unsigned char *p,"
|
"decode_%s(const unsigned char *p,"
|
||||||
" size_t len, %s *data, size_t *size)\n"
|
" size_t len, %s *data, size_t *size)\n"
|
||||||
"{\n",
|
"{\n",
|
||||||
s->gen_name, s->gen_name);
|
s->gen_name, s->gen_name);
|
||||||
|
|
||||||
switch (s->type->type) {
|
switch (s->type->type) {
|
||||||
case TInteger:
|
case TInteger:
|
||||||
case TBoolean:
|
case TBoolean:
|
||||||
case TOctetString:
|
case TOctetString:
|
||||||
case TOID:
|
case TOID:
|
||||||
case TGeneralizedTime:
|
case TGeneralizedTime:
|
||||||
case TGeneralString:
|
case TGeneralString:
|
||||||
case TUTF8String:
|
case TUTF8String:
|
||||||
case TPrintableString:
|
case TPrintableString:
|
||||||
case TIA5String:
|
case TIA5String:
|
||||||
case TBMPString:
|
case TBMPString:
|
||||||
case TUniversalString:
|
case TUniversalString:
|
||||||
case TUTCTime:
|
case TUTCTime:
|
||||||
case TNull:
|
case TNull:
|
||||||
case TEnumerated:
|
case TEnumerated:
|
||||||
case TBitString:
|
case TBitString:
|
||||||
case TSequence:
|
case TSequence:
|
||||||
case TSequenceOf:
|
case TSequenceOf:
|
||||||
case TSet:
|
case TSet:
|
||||||
case TSetOf:
|
case TSetOf:
|
||||||
case TTag:
|
case TTag:
|
||||||
case TType:
|
case TType:
|
||||||
case TChoice:
|
case TChoice:
|
||||||
fprintf (codefile,
|
|
||||||
"size_t ret = 0, reallen;\n"
|
|
||||||
"size_t l;\n"
|
|
||||||
"int e;\n");
|
|
||||||
if (preserve)
|
|
||||||
fprintf (codefile, "const unsigned char *begin = p;\n");
|
|
||||||
|
|
||||||
fprintf (codefile, "\n");
|
|
||||||
fprintf (codefile, "memset(data, 0, sizeof(*data));\n");
|
|
||||||
fprintf (codefile, "reallen = 0;\n"); /* hack to avoid `unused variable' */
|
|
||||||
|
|
||||||
decode_type ("data", s->type, 0, "goto fail");
|
|
||||||
if (preserve)
|
|
||||||
fprintf (codefile,
|
fprintf (codefile,
|
||||||
"data->_save.data = calloc(1, ret);\n"
|
"size_t ret = 0, reallen;\n"
|
||||||
"if (data->_save.data == NULL) { e = ENOMEM; goto fail; }\n"
|
"size_t l;\n"
|
||||||
"data->_save.length = ret;\n"
|
"int e;\n");
|
||||||
"memcpy(data->_save.data, begin, ret);\n");
|
if (preserve)
|
||||||
fprintf (codefile,
|
fprintf (codefile, "const unsigned char *begin = p;\n");
|
||||||
"if(size) *size = ret;\n"
|
|
||||||
"return 0;\n");
|
fprintf (codefile, "\n");
|
||||||
fprintf (codefile,
|
fprintf (codefile, "memset(data, 0, sizeof(*data));\n"); /* hack to avoid `unused variable' */
|
||||||
"fail:\n"
|
fprintf (codefile, "reallen = 0;\n");
|
||||||
"free_%s(data);\n"
|
|
||||||
"return e;\n",
|
decode_type ("data", s->type, 0, "goto fail", "Top");
|
||||||
s->gen_name);
|
if (preserve)
|
||||||
break;
|
fprintf (codefile,
|
||||||
default:
|
"data->_save.data = calloc(1, ret);\n"
|
||||||
abort ();
|
"if (data->_save.data == NULL) { \n"
|
||||||
}
|
"e = ENOMEM; goto fail; \n"
|
||||||
fprintf (codefile, "}\n\n");
|
"}\n"
|
||||||
|
"data->_save.length = ret;\n"
|
||||||
|
"memcpy(data->_save.data, begin, ret);\n");
|
||||||
|
fprintf (codefile,
|
||||||
|
"if(size) *size = ret;\n"
|
||||||
|
"return 0;\n");
|
||||||
|
fprintf (codefile,
|
||||||
|
"fail:\n"
|
||||||
|
"free_%s(data);\n"
|
||||||
|
"return e;\n",
|
||||||
|
s->gen_name);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
abort ();
|
||||||
|
}
|
||||||
|
fprintf (codefile, "}\n\n");
|
||||||
}
|
}
|
||||||
|
@@ -62,7 +62,7 @@ valuename(Der_class class, int value)
|
|||||||
static char s[32];
|
static char s[32];
|
||||||
struct {
|
struct {
|
||||||
int value;
|
int value;
|
||||||
char *s;
|
const char *s;
|
||||||
} *p, values[] = {
|
} *p, values[] = {
|
||||||
#define X(Y) { Y, #Y }
|
#define X(Y) { Y, #Y }
|
||||||
X(UT_BMPString),
|
X(UT_BMPString),
|
||||||
@@ -105,7 +105,7 @@ valuename(Der_class class, int value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
encode_type (const char *name, const Type *t)
|
encode_type (const char *name, const Type *t, const char *tmpstr)
|
||||||
{
|
{
|
||||||
int constructed = 1;
|
int constructed = 1;
|
||||||
|
|
||||||
@@ -260,10 +260,10 @@ encode_type (const char *name, const Type *t)
|
|||||||
else if(m->defval)
|
else if(m->defval)
|
||||||
gen_compare_defval(s + 1, m->defval);
|
gen_compare_defval(s + 1, m->defval);
|
||||||
fprintf (codefile, "{\n");
|
fprintf (codefile, "{\n");
|
||||||
fprintf (codefile, "size_t oldret = ret;\n");
|
fprintf (codefile, "size_t %s_oldret = ret;\n", tmpstr);
|
||||||
fprintf (codefile, "ret = 0;\n");
|
fprintf (codefile, "ret = 0;\n");
|
||||||
encode_type (s, m->type);
|
encode_type (s, m->type, m->gen_name);
|
||||||
fprintf (codefile, "ret += oldret;\n");
|
fprintf (codefile, "ret += %s_oldret;\n", tmpstr);
|
||||||
fprintf (codefile, "}\n");
|
fprintf (codefile, "}\n");
|
||||||
free (s);
|
free (s);
|
||||||
}
|
}
|
||||||
@@ -333,20 +333,26 @@ encode_type (const char *name, const Type *t)
|
|||||||
}
|
}
|
||||||
case TSequenceOf: {
|
case TSequenceOf: {
|
||||||
char *n;
|
char *n;
|
||||||
|
char *sname;
|
||||||
|
|
||||||
fprintf (codefile,
|
fprintf (codefile,
|
||||||
"for(i = (%s)->len - 1; i >= 0; --i) {\n"
|
"for(i = (%s)->len - 1; i >= 0; --i) {\n"
|
||||||
"size_t oldret = ret;\n"
|
"size_t %s_for_oldret = ret;\n"
|
||||||
"ret = 0;\n",
|
"ret = 0;\n",
|
||||||
name);
|
name, tmpstr);
|
||||||
asprintf (&n, "&(%s)->val[i]", name);
|
asprintf (&n, "&(%s)->val[i]", name);
|
||||||
if (n == NULL)
|
if (n == NULL)
|
||||||
errx(1, "malloc");
|
errx(1, "malloc");
|
||||||
encode_type (n, t->subtype);
|
asprintf (&sname, "%s_S_Of", tmpstr);
|
||||||
|
if (sname == NULL)
|
||||||
|
errx(1, "malloc");
|
||||||
|
encode_type (n, t->subtype, sname);
|
||||||
fprintf (codefile,
|
fprintf (codefile,
|
||||||
"ret += oldret;\n"
|
"ret += %s_for_oldret;\n"
|
||||||
"}\n");
|
"}\n",
|
||||||
|
tmpstr);
|
||||||
free (n);
|
free (n);
|
||||||
|
free (sname);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TGeneralizedTime:
|
case TGeneralizedTime:
|
||||||
@@ -358,13 +364,19 @@ encode_type (const char *name, const Type *t)
|
|||||||
constructed = 0;
|
constructed = 0;
|
||||||
break;
|
break;
|
||||||
case TTag: {
|
case TTag: {
|
||||||
int c = encode_type (name, t->subtype);
|
char *tname;
|
||||||
|
int c;
|
||||||
|
asprintf (&tname, "%s_tag", tmpstr);
|
||||||
|
if (tname == NULL)
|
||||||
|
errx(1, "malloc");
|
||||||
|
c = encode_type (name, t->subtype, tname);
|
||||||
fprintf (codefile,
|
fprintf (codefile,
|
||||||
"e = der_put_length_and_tag (p, len, ret, %s, %s, %s, &l);\n"
|
"e = der_put_length_and_tag (p, len, ret, %s, %s, %s, &l);\n"
|
||||||
"if (e) return e;\np -= l; len -= l; ret += l;\n\n",
|
"if (e) return e;\np -= l; len -= l; ret += l;\n\n",
|
||||||
classname(t->tag.tagclass),
|
classname(t->tag.tagclass),
|
||||||
c ? "CONS" : "PRIM",
|
c ? "CONS" : "PRIM",
|
||||||
valuename(t->tag.tagclass, t->tag.tagvalue));
|
valuename(t->tag.tagclass, t->tag.tagvalue));
|
||||||
|
free (tname);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TChoice:{
|
case TChoice:{
|
||||||
@@ -396,11 +408,10 @@ encode_type (const char *name, const Type *t)
|
|||||||
errx(1, "malloc");
|
errx(1, "malloc");
|
||||||
if (m->optional)
|
if (m->optional)
|
||||||
fprintf (codefile, "if(%s) {\n", s2);
|
fprintf (codefile, "if(%s) {\n", s2);
|
||||||
fprintf (codefile, "size_t oldret;\n");
|
fprintf (codefile, "size_t %s_oldret = ret;\n", tmpstr);
|
||||||
fprintf (codefile, "oldret = ret;\n");
|
|
||||||
fprintf (codefile, "ret = 0;\n");
|
fprintf (codefile, "ret = 0;\n");
|
||||||
constructed = encode_type (s2, m->type);
|
constructed = encode_type (s2, m->type, m->gen_name);
|
||||||
fprintf (codefile, "ret += oldret;\n");
|
fprintf (codefile, "ret += %s_oldret;\n", tmpstr);
|
||||||
if(m->optional)
|
if(m->optional)
|
||||||
fprintf (codefile, "}\n");
|
fprintf (codefile, "}\n");
|
||||||
fprintf(codefile, "break;\n");
|
fprintf(codefile, "break;\n");
|
||||||
@@ -469,53 +480,53 @@ encode_type (const char *name, const Type *t)
|
|||||||
void
|
void
|
||||||
generate_type_encode (const Symbol *s)
|
generate_type_encode (const Symbol *s)
|
||||||
{
|
{
|
||||||
fprintf (headerfile,
|
fprintf (headerfile,
|
||||||
"int "
|
"int "
|
||||||
"encode_%s(unsigned char *, size_t, const %s *, size_t *);\n",
|
"encode_%s(unsigned char *, size_t, const %s *, size_t *);\n",
|
||||||
s->gen_name, s->gen_name);
|
s->gen_name, s->gen_name);
|
||||||
|
|
||||||
fprintf (codefile, "int\n"
|
fprintf (codefile, "int\n"
|
||||||
"encode_%s(unsigned char *p, size_t len,"
|
"encode_%s(unsigned char *p, size_t len,"
|
||||||
" const %s *data, size_t *size)\n"
|
" const %s *data, size_t *size)\n"
|
||||||
"{\n",
|
"{\n",
|
||||||
s->gen_name, s->gen_name);
|
s->gen_name, s->gen_name);
|
||||||
|
|
||||||
switch (s->type->type) {
|
switch (s->type->type) {
|
||||||
case TInteger:
|
case TInteger:
|
||||||
case TBoolean:
|
case TBoolean:
|
||||||
case TOctetString:
|
case TOctetString:
|
||||||
case TGeneralizedTime:
|
case TGeneralizedTime:
|
||||||
case TGeneralString:
|
case TGeneralString:
|
||||||
case TUTCTime:
|
case TUTCTime:
|
||||||
case TUTF8String:
|
case TUTF8String:
|
||||||
case TPrintableString:
|
case TPrintableString:
|
||||||
case TIA5String:
|
case TIA5String:
|
||||||
case TBMPString:
|
case TBMPString:
|
||||||
case TUniversalString:
|
case TUniversalString:
|
||||||
case TNull:
|
case TNull:
|
||||||
case TBitString:
|
case TBitString:
|
||||||
case TEnumerated:
|
case TEnumerated:
|
||||||
case TOID:
|
case TOID:
|
||||||
case TSequence:
|
case TSequence:
|
||||||
case TSequenceOf:
|
case TSequenceOf:
|
||||||
case TSet:
|
case TSet:
|
||||||
case TSetOf:
|
case TSetOf:
|
||||||
case TTag:
|
case TTag:
|
||||||
case TType:
|
case TType:
|
||||||
case TChoice:
|
case TChoice:
|
||||||
fprintf (codefile,
|
fprintf (codefile,
|
||||||
"size_t ret = 0;\n"
|
"size_t ret = 0;\n"
|
||||||
"size_t l;\n"
|
"size_t l;\n"
|
||||||
"int i, e;\n\n");
|
"int i, e;\n\n");
|
||||||
fprintf(codefile, "i = 0;\n"); /* hack to avoid `unused variable' */
|
fprintf(codefile, "i = 0;\n"); /* hack to avoid `unused variable' */
|
||||||
|
|
||||||
encode_type("data", s->type);
|
encode_type("data", s->type, "Top");
|
||||||
|
|
||||||
fprintf (codefile, "*size = ret;\n"
|
fprintf (codefile, "*size = ret;\n"
|
||||||
"return 0;\n");
|
"return 0;\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
abort ();
|
abort ();
|
||||||
}
|
}
|
||||||
fprintf (codefile, "}\n\n");
|
fprintf (codefile, "}\n\n");
|
||||||
}
|
}
|
||||||
|
@@ -59,7 +59,8 @@ length_tag(unsigned int tag)
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
length_type (const char *name, const Type *t, const char *variable)
|
length_type (const char *name, const Type *t,
|
||||||
|
const char *variable, const char *tmpstr)
|
||||||
{
|
{
|
||||||
switch (t->type) {
|
switch (t->type) {
|
||||||
case TType:
|
case TType:
|
||||||
@@ -158,10 +159,10 @@ length_type (const char *name, const Type *t, const char *variable)
|
|||||||
else if(m->defval)
|
else if(m->defval)
|
||||||
gen_compare_defval(s + 1, m->defval);
|
gen_compare_defval(s + 1, m->defval);
|
||||||
fprintf (codefile, "{\n"
|
fprintf (codefile, "{\n"
|
||||||
"size_t oldret = %s;\n"
|
"size_t %s_oldret = %s;\n"
|
||||||
"%s = 0;\n", variable, variable);
|
"%s = 0;\n", tmpstr, variable, variable);
|
||||||
length_type (s, m->type, "ret");
|
length_type (s, m->type, "ret", m->gen_name);
|
||||||
fprintf (codefile, "ret += oldret;\n");
|
fprintf (codefile, "ret += %s_oldret;\n", tmpstr);
|
||||||
fprintf (codefile, "}\n");
|
fprintf (codefile, "}\n");
|
||||||
free (s);
|
free (s);
|
||||||
if(t->type == TChoice)
|
if(t->type == TChoice)
|
||||||
@@ -183,29 +184,34 @@ length_type (const char *name, const Type *t, const char *variable)
|
|||||||
case TSetOf:
|
case TSetOf:
|
||||||
case TSequenceOf: {
|
case TSequenceOf: {
|
||||||
char *n;
|
char *n;
|
||||||
|
char *sname;
|
||||||
|
|
||||||
fprintf (codefile,
|
fprintf (codefile,
|
||||||
"{\n"
|
"{\n"
|
||||||
"int oldret = %s;\n"
|
"int %s_oldret = %s;\n"
|
||||||
"int i;\n"
|
"int i;\n"
|
||||||
"%s = 0;\n",
|
"%s = 0;\n",
|
||||||
variable, variable);
|
tmpstr, variable, variable);
|
||||||
|
|
||||||
fprintf (codefile, "for(i = (%s)->len - 1; i >= 0; --i){\n", name);
|
fprintf (codefile, "for(i = (%s)->len - 1; i >= 0; --i){\n", name);
|
||||||
fprintf (codefile, "int oldret = %s;\n"
|
fprintf (codefile, "int %s_for_oldret = %s;\n"
|
||||||
"%s = 0;\n", variable, variable);
|
"%s = 0;\n", tmpstr, variable, variable);
|
||||||
asprintf (&n, "&(%s)->val[i]", name);
|
asprintf (&n, "&(%s)->val[i]", name);
|
||||||
if (n == NULL)
|
if (n == NULL)
|
||||||
errx(1, "malloc");
|
errx(1, "malloc");
|
||||||
length_type(n, t->subtype, variable);
|
asprintf (&sname, "%s_S_Of", tmpstr);
|
||||||
fprintf (codefile, "%s += oldret;\n",
|
if (sname == NULL)
|
||||||
variable);
|
errx(1, "malloc");
|
||||||
|
length_type(n, t->subtype, variable, sname);
|
||||||
|
fprintf (codefile, "%s += %s_for_oldret;\n",
|
||||||
|
variable, tmpstr);
|
||||||
fprintf (codefile, "}\n");
|
fprintf (codefile, "}\n");
|
||||||
|
|
||||||
fprintf (codefile,
|
fprintf (codefile,
|
||||||
"%s += oldret;\n"
|
"%s += %s_oldret;\n"
|
||||||
"}\n", variable);
|
"}\n", variable, tmpstr);
|
||||||
free(n);
|
free(n);
|
||||||
|
free(sname);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TGeneralizedTime:
|
case TGeneralizedTime:
|
||||||
@@ -235,11 +241,17 @@ length_type (const char *name, const Type *t, const char *variable)
|
|||||||
case TNull:
|
case TNull:
|
||||||
fprintf (codefile, "/* NULL */\n");
|
fprintf (codefile, "/* NULL */\n");
|
||||||
break;
|
break;
|
||||||
case TTag:
|
case TTag:{
|
||||||
length_type (name, t->subtype, variable);
|
char *tname;
|
||||||
|
asprintf(&tname, "%s_tag", tmpstr);
|
||||||
|
if (tname == NULL)
|
||||||
|
errx(1, "malloc");
|
||||||
|
length_type (name, t->subtype, variable, tname);
|
||||||
fprintf (codefile, "ret += %lu + length_len (ret);\n",
|
fprintf (codefile, "ret += %lu + length_len (ret);\n",
|
||||||
(unsigned long)length_tag(t->tag.tagvalue));
|
(unsigned long)length_tag(t->tag.tagvalue));
|
||||||
|
free(tname);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case TOID:
|
case TOID:
|
||||||
length_primitive ("oid", name, variable);
|
length_primitive ("oid", name, variable);
|
||||||
break;
|
break;
|
||||||
@@ -252,18 +264,18 @@ length_type (const char *name, const Type *t, const char *variable)
|
|||||||
void
|
void
|
||||||
generate_type_length (const Symbol *s)
|
generate_type_length (const Symbol *s)
|
||||||
{
|
{
|
||||||
fprintf (headerfile,
|
fprintf (headerfile,
|
||||||
"size_t length_%s(const %s *);\n",
|
"size_t length_%s(const %s *);\n",
|
||||||
s->gen_name, s->gen_name);
|
s->gen_name, s->gen_name);
|
||||||
|
|
||||||
fprintf (codefile,
|
fprintf (codefile,
|
||||||
"size_t\n"
|
"size_t\n"
|
||||||
"length_%s(const %s *data)\n"
|
"length_%s(const %s *data)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
"size_t ret = 0;\n",
|
"size_t ret = 0;\n",
|
||||||
s->gen_name, s->gen_name);
|
s->gen_name, s->gen_name);
|
||||||
|
|
||||||
length_type ("data", s->type, "ret");
|
length_type ("data", s->type, "ret", "Top");
|
||||||
fprintf (codefile, "return ret;\n}\n\n");
|
fprintf (codefile, "return ret;\n}\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user