Add 64-bit integer support to ASN.1 compiler

ASN.1 INTEGERs will now compile to C int64_t or uint64_t, depending
    on whether the constraint ranges include numbers that cannot be
    represented in 32-bit ints and whether they include negative
    numbers.

    Template backend support included.  check-template is now built with
    --template, so we know we're testing it.

    Tests included.
This commit is contained in:
Nicolas Williams
2011-06-22 17:11:40 -05:00
committed by Nicolas Williams
parent 0e7437ba2e
commit 19d378f44d
20 changed files with 426 additions and 48 deletions

View File

@@ -306,7 +306,7 @@ gen_assign_defval(const char *var, struct value *val)
fprintf(codefile, "if((%s = strdup(\"%s\")) == NULL)\nreturn ENOMEM;\n", var, val->u.stringvalue);
break;
case integervalue:
fprintf(codefile, "%s = %d;\n", var, val->u.integervalue);
fprintf(codefile, "%s = %lld;\n", var, val->u.integervalue);
break;
case booleanvalue:
if(val->u.booleanvalue)
@@ -327,7 +327,7 @@ gen_compare_defval(const char *var, struct value *val)
fprintf(codefile, "if(strcmp(%s, \"%s\") != 0)\n", var, val->u.stringvalue);
break;
case integervalue:
fprintf(codefile, "if(%s != %d)\n", var, val->u.integervalue);
fprintf(codefile, "if(%s != %lld)\n", var, val->u.integervalue);
break;
case booleanvalue:
if(val->u.booleanvalue)
@@ -400,7 +400,7 @@ generate_constant (const Symbol *s)
case booleanvalue:
break;
case integervalue:
fprintf (headerfile, "enum { %s = %d };\n\n",
fprintf (headerfile, "enum { %s = %lld };\n\n",
s->gen_name, s->value->u.integervalue);
break;
case nullvalue:
@@ -543,7 +543,7 @@ define_asn1 (int level, Type *t)
if(t->members == NULL) {
fprintf (headerfile, "INTEGER");
if (t->range)
fprintf (headerfile, " (%d..%d)",
fprintf (headerfile, " (%lld..%lld)",
t->range->min, t->range->max);
} else {
Member *m;
@@ -726,14 +726,16 @@ define_type (int level, const char *name, const char *basename, Type *t, int typ
fprintf (headerfile, "} %s;\n", name);
} else if (t->range == NULL) {
fprintf (headerfile, "heim_integer %s;\n", name);
} else if (t->range->min == INT_MIN && t->range->max == INT_MAX) {
} else if (t->range->min < INT_MIN && t->range->max <= INT64_MAX) {
fprintf (headerfile, "int64_t %s;\n", name);
} else if (t->range->min >= 0 && t->range->max > UINT_MAX) {
fprintf (headerfile, "uint64_t %s;\n", name);
} else if (t->range->min >= INT_MIN && t->range->max <= INT_MAX) {
fprintf (headerfile, "int %s;\n", name);
} else if (t->range->min == 0 && t->range->max == UINT_MAX) {
fprintf (headerfile, "unsigned int %s;\n", name);
} else if (t->range->min == 0 && t->range->max == INT_MAX) {
} else if (t->range->min >= 0 && t->range->max <= UINT_MAX) {
fprintf (headerfile, "unsigned int %s;\n", name);
} else
errx(1, "%s: unsupported range %d -> %d",
errx(1, "%s: unsupported range %lld -> %lld",
name, t->range->min, t->range->max);
break;
case TBoolean: