Commit 6938d044 authored by Lev Walkin's avatar Lev Walkin

refactoring

parent fe7f6ecd
#undef NDEBUG
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <assert.h>
#include <Int5.h>
#include <Str4.h>
#include <Utf8-4.h>
#include <VisibleIdentifier.h>
int
main(int ac, char **av) {
(void)ac; /* Unused argument */
(void)av; /* Unused argument */
/*
* No plans to fill it up: just checking whether it compiles or not.
*/
return 0;
}
...@@ -967,7 +967,9 @@ asn1c_lang_C_type_SIMPLE_TYPE(arg_t *arg) { ...@@ -967,7 +967,9 @@ asn1c_lang_C_type_SIMPLE_TYPE(arg_t *arg) {
} }
if((!expr->constraints || (arg->flags & A1C_NO_CONSTRAINTS)) if((!expr->constraints || (arg->flags & A1C_NO_CONSTRAINTS))
&& (arg->embed || expr->tag.tag_class == TC_NOCLASS) && (arg->embed || expr->tag.tag_class == TC_NOCLASS)
&& etd_spec == ETD_NO_SPECIFICS) { && etd_spec == ETD_NO_SPECIFICS
&& 0 /* This shortcut is incompatible with XER */
) {
char *type_name; char *type_name;
REDIR(OT_FUNC_DECLS); REDIR(OT_FUNC_DECLS);
type_name = asn1c_type_name(arg, expr, TNF_SAFE); type_name = asn1c_type_name(arg, expr, TNF_SAFE);
......
...@@ -13,8 +13,6 @@ static int emit_size_determination_code(arg_t *arg, asn1p_expr_type_e etype); ...@@ -13,8 +13,6 @@ static int emit_size_determination_code(arg_t *arg, asn1p_expr_type_e etype);
static asn1p_expr_type_e _find_terminal_type(arg_t *arg); static asn1p_expr_type_e _find_terminal_type(arg_t *arg);
static int emit_range_comparison_code(arg_t *arg, asn1cnst_range_t *range, const char *varname, asn1c_integer_t natural_start, asn1c_integer_t natural_stop); static int emit_range_comparison_code(arg_t *arg, asn1cnst_range_t *range, const char *varname, asn1c_integer_t natural_start, asn1c_integer_t natural_stop);
static int global_compile_mark;
int int
asn1c_emit_constraint_checking_code(arg_t *arg) { asn1c_emit_constraint_checking_code(arg_t *arg) {
asn1cnst_range_t *r_size; asn1cnst_range_t *r_size;
...@@ -23,6 +21,7 @@ asn1c_emit_constraint_checking_code(arg_t *arg) { ...@@ -23,6 +21,7 @@ asn1c_emit_constraint_checking_code(arg_t *arg) {
asn1p_expr_type_e etype; asn1p_expr_type_e etype;
asn1p_constraint_t *ct; asn1p_constraint_t *ct;
int got_something = 0; int got_something = 0;
int alphabet_table_compiled;
int produce_st = 0; int produce_st = 0;
ct = expr->combined_constraints; ct = expr->combined_constraints;
...@@ -125,7 +124,8 @@ asn1c_emit_constraint_checking_code(arg_t *arg) { ...@@ -125,7 +124,8 @@ asn1c_emit_constraint_checking_code(arg_t *arg) {
INDENT(-1); INDENT(-1);
REDIR(OT_CTABLES); REDIR(OT_CTABLES);
/* Emit FROM() tables */ /* Emit FROM() tables */
asn1c_emit_constraint_tables(arg, r_size?1:0); alphabet_table_compiled =
(asn1c_emit_constraint_tables(arg, r_size?1:0) == 1);
REDIR(OT_CODE); REDIR(OT_CODE);
INDENT(+1); INDENT(+1);
...@@ -152,10 +152,11 @@ asn1c_emit_constraint_checking_code(arg_t *arg) { ...@@ -152,10 +152,11 @@ asn1c_emit_constraint_checking_code(arg_t *arg) {
"value", -1, -1); "value", -1, -1);
OUT(")"); OUT(")");
} }
if(ct->_compile_mark) { if(alphabet_table_compiled) {
if(got_something++) { OUT("\n"); OUT(" && "); } if(got_something++) { OUT("\n"); OUT(" && "); }
OUT("!check_permitted_alphabet_%d(sptr)", OUT("!check_permitted_alphabet_%d(%s)",
ct->_compile_mark); arg->expr->_type_unique_index,
produce_st ? "st" : "sptr");
} }
if(!got_something) { if(!got_something) {
OUT("1 /* No applicable constraints whatsoever */"); OUT("1 /* No applicable constraints whatsoever */");
...@@ -252,9 +253,6 @@ asn1c_emit_constraint_tables(arg_t *arg, int got_size) { ...@@ -252,9 +253,6 @@ asn1c_emit_constraint_tables(arg_t *arg, int got_size) {
max_table_size = 128; max_table_size = 128;
} }
if(!ct->_compile_mark)
ct->_compile_mark = ++global_compile_mark;
if(use_table) { if(use_table) {
int i, n = 0; int i, n = 0;
int untl; int untl;
...@@ -278,7 +276,7 @@ asn1c_emit_constraint_tables(arg_t *arg, int got_size) { ...@@ -278,7 +276,7 @@ asn1c_emit_constraint_tables(arg_t *arg, int got_size) {
untl = (range_stop - range_start) + 1; untl = (range_stop - range_start) + 1;
untl += (untl % 16)?16 - (untl % 16):0; untl += (untl % 16)?16 - (untl % 16):0;
OUT("static int permitted_alphabet_table_%d[%d] = {\n", OUT("static int permitted_alphabet_table_%d[%d] = {\n",
ct->_compile_mark, max_table_size); arg->expr->_type_unique_index, max_table_size);
for(n = 0; n < untl; n++) { for(n = 0; n < untl; n++) {
OUT("%d,", table[n]?1:0); OUT("%d,", table[n]?1:0);
if(!((n+1) % 16)) { if(!((n+1) % 16)) {
...@@ -316,7 +314,6 @@ asn1c_emit_constraint_tables(arg_t *arg, int got_size) { ...@@ -316,7 +314,6 @@ asn1c_emit_constraint_tables(arg_t *arg, int got_size) {
* for the syntax validity, so we don't have * for the syntax validity, so we don't have
* to repeat this process twice. * to repeat this process twice.
*/ */
ct->_compile_mark = 0; /* Don't generate code */
asn1constraint_range_free(range); asn1constraint_range_free(range);
return 0; return 0;
} else { } else {
...@@ -332,7 +329,7 @@ asn1c_emit_constraint_tables(arg_t *arg, int got_size) { ...@@ -332,7 +329,7 @@ asn1c_emit_constraint_tables(arg_t *arg, int got_size) {
} }
OUT("static int check_permitted_alphabet_%d(const void *sptr) {\n", OUT("static int check_permitted_alphabet_%d(const void *sptr) {\n",
ct->_compile_mark); arg->expr->_type_unique_index);
INDENT(+1); INDENT(+1);
if(utf8_full_alphabet_check) { if(utf8_full_alphabet_check) {
OUT("if(UTF8String_length((const UTF8String_t *)sptr) < 0)\n"); OUT("if(UTF8String_length((const UTF8String_t *)sptr) < 0)\n");
...@@ -341,7 +338,7 @@ asn1c_emit_constraint_tables(arg_t *arg, int got_size) { ...@@ -341,7 +338,7 @@ asn1c_emit_constraint_tables(arg_t *arg, int got_size) {
} else { } else {
if(use_table) { if(use_table) {
OUT("int *table = permitted_alphabet_table_%d;\n", OUT("int *table = permitted_alphabet_table_%d;\n",
ct->_compile_mark); arg->expr->_type_unique_index);
emit_alphabet_check_loop(arg, 0); emit_alphabet_check_loop(arg, 0);
} else { } else {
emit_alphabet_check_loop(arg, range); emit_alphabet_check_loop(arg, range);
...@@ -354,7 +351,7 @@ asn1c_emit_constraint_tables(arg_t *arg, int got_size) { ...@@ -354,7 +351,7 @@ asn1c_emit_constraint_tables(arg_t *arg, int got_size) {
asn1constraint_range_free(range); asn1constraint_range_free(range);
return 0; return 1;
} }
static int static int
......
...@@ -57,7 +57,6 @@ typedef struct asn1p_constraint_s { ...@@ -57,7 +57,6 @@ typedef struct asn1p_constraint_s {
unsigned int el_size; /* Size of the allocated (elements) */ unsigned int el_size; /* Size of the allocated (elements) */
int _lineno; /* Position in a source file */ int _lineno; /* Position in a source file */
int _compile_mark; /* Marker used by the compiler */
} asn1p_constraint_t; } asn1p_constraint_t;
/* Human-readable constraint type description */ /* Human-readable constraint type description */
......
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