Commit 02b137df authored by Lev Walkin's avatar Lev Walkin

refine

parent d1e5494c
...@@ -70,6 +70,7 @@ asn1c_emit_constraint_checking_code(arg_t *arg) { ...@@ -70,6 +70,7 @@ asn1c_emit_constraint_checking_code(arg_t *arg) {
if(!(arg->flags & A1C_USE_NATIVE_INTEGERS)) if(!(arg->flags & A1C_USE_NATIVE_INTEGERS))
produce_st = 1; produce_st = 1;
break; break;
case ASN_BASIC_BIT_STRING:
case ASN_BASIC_OCTET_STRING: case ASN_BASIC_OCTET_STRING:
produce_st = 1; produce_st = 1;
break; break;
...@@ -79,7 +80,8 @@ asn1c_emit_constraint_checking_code(arg_t *arg) { ...@@ -79,7 +80,8 @@ asn1c_emit_constraint_checking_code(arg_t *arg) {
break; break;
} }
if(produce_st) if(produce_st)
OUT("const %s_t *st = sptr;\n", MKID(arg->expr->Identifier)); OUT("const %s_t *st = sptr;\n",
asn1c_type_name(arg, arg->expr, TNF_SAFE));
if(r_size || r_value) { if(r_size || r_value) {
if(r_size) { if(r_size) {
...@@ -350,12 +352,13 @@ emit_alphabet_check_loop(arg_t *arg, asn1cnst_range_t *range) { ...@@ -350,12 +352,13 @@ emit_alphabet_check_loop(arg_t *arg, asn1cnst_range_t *range) {
OUT("/* The underlying type is %s */\n", OUT("/* The underlying type is %s */\n",
ASN_EXPR_TYPE2STR(etype)); ASN_EXPR_TYPE2STR(etype));
OUT("const %s_t *st = sptr;\n", MKID(arg->expr->Identifier)); OUT("const %s_t *st = sptr;\n",
asn1c_type_name(arg, arg->expr, TNF_SAFE));
switch(etype) { switch(etype) {
case ASN_STRING_UTF8String: case ASN_STRING_UTF8String:
OUT("uint8_t *ch = st->buf;\n"); OUT("const uint8_t *ch = st->buf;\n");
OUT("uint8_t *end = ch + st->size;\n"); OUT("const uint8_t *end = ch + st->size;\n");
OUT("\n"); OUT("\n");
OUT("for(; ch < end; ch++) {\n"); OUT("for(; ch < end; ch++) {\n");
INDENT(+1); INDENT(+1);
...@@ -364,35 +367,35 @@ emit_alphabet_check_loop(arg_t *arg, asn1cnst_range_t *range) { ...@@ -364,35 +367,35 @@ emit_alphabet_check_loop(arg_t *arg, asn1cnst_range_t *range) {
natural_stop = 0xffffffffUL; natural_stop = 0xffffffffUL;
break; break;
case ASN_STRING_UniversalString: case ASN_STRING_UniversalString:
OUT("uint32_t *ch = st->buf;\n"); OUT("const uint32_t *ch = st->buf;\n");
OUT("uint32_t *end = ch + st->size;\n"); OUT("const uint32_t *end = ch + st->size;\n");
OUT("\n"); OUT("\n");
OUT("if(st->size % 4) return 0; /* (size%4)! */\n"); OUT("if(st->size % 4) return 0; /* (size%4)! */\n");
OUT("for(; ch < end; ch++) {\n"); OUT("for(; ch < end; ch++) {\n");
INDENT(+1); INDENT(+1);
OUT("uint32_t cv = (((uint8_t *)ch)[0] << 24)\n"); OUT("uint32_t cv = (((const uint8_t *)ch)[0] << 24)\n");
OUT("\t\t| (((uint8_t *)ch)[1] << 16)\n"); OUT("\t\t| (((const uint8_t *)ch)[1] << 16)\n");
OUT("\t\t| (((uint8_t *)ch)[2] << 8)\n"); OUT("\t\t| (((const uint8_t *)ch)[2] << 8)\n");
OUT("\t\t| ((uint8_t *)ch)[3]\n"); OUT("\t\t| ((const uint8_t *)ch)[3];\n");
if(!range) OUT("if(cv > 255) return 0;\n"); if(!range) OUT("if(cv > 255) return 0;\n");
natural_stop = 0xffffffffUL; natural_stop = 0xffffffffUL;
break; break;
case ASN_STRING_BMPString: case ASN_STRING_BMPString:
OUT("uint16_t *ch = st->buf;\n"); OUT("const uint16_t *ch = st->buf;\n");
OUT("uint16_t *end = ch + st->size;\n"); OUT("const uint16_t *end = ch + st->size;\n");
OUT("\n"); OUT("\n");
OUT("if(st->size % 2) return 0; /* (size%2)! */\n"); OUT("if(st->size % 2) return 0; /* (size%2)! */\n");
OUT("for(; ch < end; ch++) {\n"); OUT("for(; ch < end; ch++) {\n");
INDENT(+1); INDENT(+1);
OUT("uint16_t cv = (((uint8_t *)ch)[0] << 8)\n"); OUT("uint16_t cv = (((const uint8_t *)ch)[0] << 8)\n");
OUT("\t\t| ((uint8_t *)ch)[1];\n"); OUT("\t\t| ((const uint8_t *)ch)[1];\n");
if(!range) OUT("if(cv > 255) return 0;\n"); if(!range) OUT("if(cv > 255) return 0;\n");
natural_stop = 0xffff; natural_stop = 0xffff;
break; break;
case ASN_BASIC_OCTET_STRING: case ASN_BASIC_OCTET_STRING:
default: default:
OUT("uint8_t *ch = st->buf;\n"); OUT("const uint8_t *ch = st->buf;\n");
OUT("uint8_t *end = ch + st->size;\n"); OUT("const uint8_t *end = ch + st->size;\n");
OUT("\n"); OUT("\n");
OUT("for(; ch < end; ch++) {\n"); OUT("for(; ch < end; ch++) {\n");
INDENT(+1); INDENT(+1);
...@@ -531,7 +534,7 @@ emit_value_determination_code(arg_t *arg, asn1p_expr_type_e etype) { ...@@ -531,7 +534,7 @@ emit_value_determination_code(arg_t *arg, asn1p_expr_type_e etype) {
case ASN_BASIC_INTEGER: case ASN_BASIC_INTEGER:
case ASN_BASIC_ENUMERATED: case ASN_BASIC_ENUMERATED:
if(arg->flags & A1C_USE_NATIVE_INTEGERS) { if(arg->flags & A1C_USE_NATIVE_INTEGERS) {
OUT("value = *(int *)sptr;\n"); OUT("value = *(const int *)sptr;\n");
} else { } else {
OUT("if(asn1_INTEGER2long(st, &value)) {\n"); OUT("if(asn1_INTEGER2long(st, &value)) {\n");
INDENT(+1); INDENT(+1);
...@@ -543,14 +546,21 @@ emit_value_determination_code(arg_t *arg, asn1p_expr_type_e etype) { ...@@ -543,14 +546,21 @@ emit_value_determination_code(arg_t *arg, asn1p_expr_type_e etype) {
} }
break; break;
case ASN_BASIC_BOOLEAN: case ASN_BASIC_BOOLEAN:
OUT("value = (*(int *)sptr) ? 1 : 0;\n"); OUT("value = (*(const int *)sptr) ? 1 : 0;\n");
break; break;
default: default:
WARNING("Value cannot be determined " WARNING("%s:%d: Value cannot be determined "
"for constraint check for %s at line %d\n", "for constraint check for %s",
arg->expr->Identifier, arg->expr->_lineno); arg->mod->source_file_name,
OUT("#error Value cannot be determined for %s at %d\n", arg->expr->_lineno,
arg->expr->Identifier, arg->expr->_lineno); arg->expr->Identifier
);
OUT_NOINDENT(
"#error %s:%d: Value of %s cannot be determined\n",
arg->mod->source_file_name,
arg->expr->_lineno,
arg->expr->Identifier
);
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment