Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify finding decoder logic #93

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions asn1c/log2diff.pl
@@ -0,0 +1,32 @@
#!/usr/bin/env perl
#
# Convert check-parsing.sh log to diff format
#

if(-t STDIN && $#ARGV == -1) {
print STDERR "Usage : log2diff.pl < check-parsing.sh.log > diff.patch\n";
exit(1);
}

$state = 0;
while(<>) {
if ($state == 0) {
if (/^Checking\s*(.+?)\s*against\s*(.+?)$/) {
$source = $1;
$target = $2;
} elsif (/^\-\-\-\s(.+?)\s.*/) {
print "--- a/dev/null " . "\n";
} elsif (/^\+\+\+\s(.+?)\s.*/) {
print "+++ b" . $target . "\n";
$state = 1;
}
} else {
if (/^Checking\s*(.+?)\s*against\s*(.+?)$/) {
$source = $1;
$target = $2;
$state = 0;
} else {
print $_;
}
}
}
2 changes: 1 addition & 1 deletion examples/sample.source.RRC/Makefile
Expand Up @@ -4825,7 +4825,7 @@ check-per:
done; done; fi
@if test -f sample-DL-DCCH-Message-1.per ; then \
for f in sample-*-[1-9].per; do \
pdu=`echo $$f | sed -E -e "s/sample-([A-Za-z-]+)-[0-9].*/\1/"`; \
pdu=`echo $$f | sed -E -e "s/sample-([A-Za-z-]+)-[0-9].*//"`; \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentional?

for b in 1 17 33 980 8192; do \
echo "Recoding $$f into DER into XER and back ($$b)..."; \
./${TARGET} -b $$b -p $$pdu -iper -oder $$f > ./.tmp.1.$$$$ || exit 3; \
Expand Down
167 changes: 130 additions & 37 deletions libasn1compiler/asn1c_C.c
Expand Up @@ -203,7 +203,8 @@ asn1c_lang_C_type_common_INTEGER(arg_t *arg) {
OUT("\t/* This list is extensible */\n");
OUT("};\n");

OUT("static const asn_INTEGER_specifics_t asn_SPC_%s_specs_%d = {\n",
if(!(expr->_type_referenced)) OUT("static ");
OUT("const asn_INTEGER_specifics_t asn_SPC_%s_specs_%d = {\n",
MKID(expr), expr->_type_unique_index);
INDENT(+1);
OUT("asn_MAP_%s_value2enum_%d,\t"
Expand Down Expand Up @@ -235,7 +236,8 @@ asn1c_lang_C_type_common_INTEGER(arg_t *arg) {
if(expr->expr_type == ASN_BASIC_INTEGER
&& asn1c_type_fits_long(arg, expr) == FL_FITS_UNSIGN) {
REDIR(OT_STAT_DEFS);
OUT("static const asn_INTEGER_specifics_t asn_SPC_%s_specs_%d = {\n",
if(!(expr->_type_referenced)) OUT("static ");
OUT("const asn_INTEGER_specifics_t asn_SPC_%s_specs_%d = {\n",
MKID(expr), expr->_type_unique_index);
INDENT(+1);
OUT("0,\t");
Expand Down Expand Up @@ -376,7 +378,7 @@ asn1c_lang_C_type_SEQUENCE_def(arg_t *arg) {

GEN_INCLUDE_STD("constr_SEQUENCE");
if(!arg->embed)
GEN_DECLARE(expr); /* asn_DEF_xxx */
GEN_DECLARE("SEQUENCE", expr); /* asn_DEF_xxx */

REDIR(OT_STAT_DEFS);

Expand All @@ -386,7 +388,8 @@ asn1c_lang_C_type_SEQUENCE_def(arg_t *arg) {
if(expr_elements_count(arg, expr)) {
int comp_mode = 0; /* {root,ext=1,root,root,...} */

OUT("static asn_TYPE_member_t asn_MBR_%s_%d[] = {\n",
if(!(expr->_type_referenced)) OUT("static ");
OUT("asn_TYPE_member_t asn_MBR_%s_%d[] = {\n",
MKID(expr), expr->_type_unique_index);

elements = 0;
Expand Down Expand Up @@ -468,7 +471,8 @@ asn1c_lang_C_type_SEQUENCE_def(arg_t *arg) {
*/
emit_tag2member_map(arg, tag2el, tag2el_count, 0);

OUT("static asn_SEQUENCE_specifics_t asn_SPC_%s_specs_%d = {\n",
if(!(expr->_type_referenced)) OUT("static ");
OUT("asn_SEQUENCE_specifics_t asn_SPC_%s_specs_%d = {\n",
MKID(expr), expr->_type_unique_index);
INDENT(+1);
OUT("sizeof(struct ");
Expand Down Expand Up @@ -635,7 +639,7 @@ asn1c_lang_C_type_SET_def(arg_t *arg) {

GEN_INCLUDE_STD("constr_SET");
if(!arg->embed)
GEN_DECLARE(expr); /* asn_DEF_xxx */
GEN_DECLARE("SET", expr); /* asn_DEF_xxx */

REDIR(OT_STAT_DEFS);

Expand All @@ -645,7 +649,8 @@ asn1c_lang_C_type_SET_def(arg_t *arg) {
if(expr_elements_count(arg, expr)) {
int comp_mode = 0; /* {root,ext=1,root,root,...} */

OUT("static asn_TYPE_member_t asn_MBR_%s_%d[] = {\n",
if(!(expr->_type_referenced)) OUT("static ");
OUT("asn_TYPE_member_t asn_MBR_%s_%d[] = {\n",
MKID(expr), expr->_type_unique_index);

elements = 0;
Expand Down Expand Up @@ -705,7 +710,8 @@ asn1c_lang_C_type_SET_def(arg_t *arg) {
OUT("\n");
OUT("};\n");

OUT("static asn_SET_specifics_t asn_SPC_%s_specs_%d = {\n",
if(!(expr->_type_referenced)) OUT("static \n");
OUT("asn_SET_specifics_t asn_SPC_%s_specs_%d = {\n",
MKID(expr), expr->_type_unique_index);
INDENTED(
OUT("sizeof(struct ");
Expand Down Expand Up @@ -860,14 +866,15 @@ asn1c_lang_C_type_SEx_OF_def(arg_t *arg, int seq_of) {
GEN_INCLUDE_STD("constr_SET_OF");
}
if(!arg->embed)
GEN_DECLARE(expr); /* asn_DEF_xxx */
GEN_DECLARE("SET_OF", expr); /* asn_DEF_xxx */

REDIR(OT_STAT_DEFS);

/*
* Print out the table according to which parsing is performed.
*/
OUT("static asn_TYPE_member_t asn_MBR_%s_%d[] = {\n",
if(!(expr->_type_referenced)) OUT("static ");
OUT("asn_TYPE_member_t asn_MBR_%s_%d[] = {\n",
MKID(expr), expr->_type_unique_index);
INDENT(+1);
v = TQ_FIRST(&(expr->members));
Expand All @@ -889,7 +896,8 @@ asn1c_lang_C_type_SEx_OF_def(arg_t *arg, int seq_of) {
*/
tv_mode = emit_tags_vectors(arg, expr, &tags_count, &all_tags_count);

OUT("static asn_SET_OF_specifics_t asn_SPC_%s_specs_%d = {\n",
if(!(expr->_type_referenced)) OUT("static ");
OUT("asn_SET_OF_specifics_t asn_SPC_%s_specs_%d = {\n",
MKID(expr), expr->_type_unique_index);
INDENTED(
OUT("sizeof(struct ");
Expand Down Expand Up @@ -1028,7 +1036,7 @@ asn1c_lang_C_type_CHOICE_def(arg_t *arg) {

GEN_INCLUDE_STD("constr_CHOICE");
if(!arg->embed)
GEN_DECLARE(expr); /* asn_DEF_xxx */
GEN_DECLARE("CHOICE", expr); /* asn_DEF_xxx */

REDIR(OT_STAT_DEFS);

Expand All @@ -1037,7 +1045,8 @@ asn1c_lang_C_type_CHOICE_def(arg_t *arg) {
*/
if(expr_elements_count(arg, expr)) {

OUT("static asn_TYPE_member_t asn_MBR_%s_%d[] = {\n",
if(!(expr->_type_referenced)) OUT("static ");
OUT("asn_TYPE_member_t asn_MBR_%s_%d[] = {\n",
MKID(expr), expr->_type_unique_index);

elements = 0;
Expand Down Expand Up @@ -1085,7 +1094,8 @@ asn1c_lang_C_type_CHOICE_def(arg_t *arg) {
*/
emit_tag2member_map(arg, tag2el, tag2el_count, 0);

OUT("static asn_CHOICE_specifics_t asn_SPC_%s_specs_%d = {\n",
if(!(expr->_type_referenced)) OUT("static ");
OUT("asn_CHOICE_specifics_t asn_SPC_%s_specs_%d = {\n",
MKID(expr), expr->_type_unique_index);
INDENTED(
OUT("sizeof(struct ");
Expand Down Expand Up @@ -1272,7 +1282,7 @@ asn1c_lang_C_type_SIMPLE_TYPE(arg_t *arg) {
/*
* Constraint checking.
*/
if(!(arg->flags & A1C_NO_CONSTRAINTS)) {
if(!(arg->flags & A1C_NO_CONSTRAINTS) && expr->combined_constraints) {
p = MKID(expr);
if(HIDE_INNER_DEFS) OUT("static ");
OUT("int\n");
Expand Down Expand Up @@ -1324,6 +1334,8 @@ asn1c_lang_C_type_SIMPLE_TYPE(arg_t *arg) {
asn1c_type_name(arg, expr, TNF_SAFE));
OUT(" * so here we adjust the DEF accordingly.\n");
OUT(" */\n");

#if 0 /* remove unnecessary functions */
OUT("static void\n");
OUT("%s_%d_inherit_TYPE_descriptor(asn_TYPE_descriptor_t *td) {\n",
MKID(expr), expr->_type_unique_index);
Expand Down Expand Up @@ -1493,7 +1505,7 @@ asn1c_lang_C_type_SIMPLE_TYPE(arg_t *arg) {
OUT("}\n");
OUT("\n");
}

#endif
REDIR(OT_FUNC_DECLS);

p = MKID(expr);
Expand All @@ -1503,6 +1515,20 @@ asn1c_lang_C_type_SIMPLE_TYPE(arg_t *arg) {
p, expr->_type_unique_index);
} else {
OUT("extern asn_TYPE_descriptor_t asn_DEF_%s;\n", p);
if (etd_spec == ETD_HAS_SPECIFICS) {
if((expr->expr_type == ASN_BASIC_ENUMERATED) ||
(expr->expr_type == ASN_BASIC_INTEGER)) {
if(expr->_type_referenced) {
OUT("extern asn_INTEGER_specifics_t "
"asn_SPC_%s_specs_%d;\n", p, expr->_type_unique_index);
}
} else {
asn1p_expr_t *terminal = asn1f_find_terminal_type_ex(arg->asn, expr);

OUT("extern asn_%s_specifics_t ", asn1c_type_name(arg, terminal, TNF_SAFE));
OUT("asn_SPC_%s_specs_%d;\n", MKID(expr), expr->_type_unique_index);
}
}
OUT("asn_struct_free_f %s_free;\n", p);
OUT("asn_struct_print_f %s_print;\n", p);
OUT("asn_constr_check_f %s_constraint;\n", p);
Expand Down Expand Up @@ -2044,9 +2070,18 @@ emit_member_PER_constraints(arg_t *arg, asn1p_expr_t *expr, const char *pfx) {
return 0;
}

if(expr->_type_referenced) {
REDIR(OT_FUNC_DECLS);

OUT("extern asn_per_constraints_t "
"asn_PER_%s_%s_constr_%d;\n",
pfx, MKID(expr), expr->_type_unique_index);
}

REDIR(OT_CTDEFS);

OUT("static asn_per_constraints_t "
if(!(expr->_type_referenced)) OUT("static ");
OUT("asn_per_constraints_t "
"asn_PER_%s_%s_constr_%d GCC_NOTUSED = {\n",
pfx, MKID(expr), expr->_type_unique_index);

Expand Down Expand Up @@ -2506,6 +2541,7 @@ emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, enum tvm_compat tv_mode, int tags_
asn1p_expr_t *terminal;
int using_type_name = 0;
char *p = MKID(expr);
char *p2 = (char *)0;

terminal = asn1f_find_terminal_type_ex(arg->asn, expr);

Expand Down Expand Up @@ -2534,8 +2570,15 @@ emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, enum tvm_compat tv_mode, int tags_
using_type_name = 1;
p = asn1c_type_name(arg, arg->expr, TNF_SAFE);
} else {
if (expr->expr_type == A1TC_REFERENCE) {
p2 = strdup(asn1c_type_name(arg, terminal, TNF_SAFE));
} else {
p2 = strdup(asn1c_type_name(arg, expr, TNF_SAFE));
}
p = MKID(expr);
}
if (!p2)
p2 = strdup(p);

#define FUNCREF(foo) do { \
OUT("%s", p); \
Expand All @@ -2544,20 +2587,30 @@ emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, enum tvm_compat tv_mode, int tags_
OUT("_" #foo ",\n"); \
} while(0)

FUNCREF(free);
FUNCREF(print);
FUNCREF(constraint);
FUNCREF(decode_ber);
FUNCREF(encode_der);
FUNCREF(decode_xer);
FUNCREF(encode_xer);
#define FUNCREF2(foo) \
do { \
OUT("%s", p2); \
OUT("_" #foo ",\n"); \
} while(0)

FUNCREF2(free);
FUNCREF2(print);
if (!expr->combined_constraints)
FUNCREF2(constraint);
else
FUNCREF(constraint);
FUNCREF2(decode_ber);
FUNCREF2(encode_der);
FUNCREF2(decode_xer);
FUNCREF2(encode_xer);
if(arg->flags & A1C_GEN_PER) {
FUNCREF(decode_uper);
FUNCREF(encode_uper);
FUNCREF2(decode_uper);
FUNCREF2(encode_uper);
} else {
OUT("0, 0,\t/* No PER support, "
"use \"-gen-PER\" to enable */\n");
}
if (p2) free(p2);

if(!terminal || terminal->expr_type == ASN_CONSTR_CHOICE) {
//if(expr->expr_type == ASN_CONSTR_CHOICE) {
Expand Down Expand Up @@ -2615,16 +2668,35 @@ emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, enum tvm_compat tv_mode, int tags_
OUT("0,\t/* No PER visible constraints */\n");
}

if(elements_count) {
OUT("asn_MBR_%s_%d,\n", p, expr->_type_unique_index);
if(expr->expr_type == ASN_CONSTR_SEQUENCE_OF
|| expr->expr_type == ASN_CONSTR_SET_OF) {
OUT("%d,\t/* Single element */\n",
elements_count);
assert(elements_count == 1);
if(elements_count ||
((expr->expr_type == A1TC_REFERENCE) &&
(terminal->expr_type & ASN_CONSTR_MASK) &&
expr_elements_count(arg, terminal))) {

if (expr->expr_type == A1TC_REFERENCE) {
OUT("asn_MBR_%s_%d,\n", MKID(terminal), terminal->_type_unique_index);

if(terminal->expr_type == ASN_CONSTR_SEQUENCE_OF
|| terminal->expr_type == ASN_CONSTR_SET_OF) {
OUT("%d,\t/* Single element */\n",
expr_elements_count(arg, terminal));
assert(expr_elements_count(arg, terminal) == 1);
} else {
OUT("%d,\t/* Elements count */\n",
expr_elements_count(arg, terminal));
}
} else {
OUT("%d,\t/* Elements count */\n",
elements_count);
OUT("asn_MBR_%s_%d,\n", p, expr->_type_unique_index);

if(expr->expr_type == ASN_CONSTR_SEQUENCE_OF
|| expr->expr_type == ASN_CONSTR_SET_OF) {
OUT("%d,\t/* Single element */\n",
elements_count);
assert(elements_count == 1);
} else {
OUT("%d,\t/* Elements count */\n",
elements_count);
}
}
} else {
if(expr_elements_count(arg, expr))
Expand All @@ -2635,7 +2707,28 @@ emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, enum tvm_compat tv_mode, int tags_

switch(spec) {
case ETD_NO_SPECIFICS:
OUT("0\t/* No specifics */\n");
if ((expr->expr_type == A1TC_REFERENCE) &&
((terminal->expr_type & ASN_CONSTR_MASK) ||
(terminal->expr_type == ASN_BASIC_ENUMERATED) ||
((terminal->expr_type == ASN_BASIC_INTEGER) &&
(asn1c_type_fits_long(arg, terminal) == FL_FITS_UNSIGN)))) {
OUT("&asn_SPC_%s_specs_%d\t/* Additional specs */\n", MKID(terminal), terminal->_type_unique_index);
} else if ((expr->expr_type == ASN_TYPE_ANY) ||
(expr->expr_type == ASN_BASIC_BIT_STRING) ||
(expr->expr_type == ASN_STRING_BMPString) ||
(expr->expr_type == ASN_BASIC_OCTET_STRING) ||
(expr->expr_type == ASN_STRING_UniversalString)) {
OUT("&asn_SPC_%s_specs\t/* Additional specs */\n", asn1c_type_name(arg, expr, TNF_SAFE));
} else if ((expr->expr_type == A1TC_REFERENCE) &&
((terminal->expr_type == ASN_TYPE_ANY) ||
(terminal->expr_type == ASN_BASIC_BIT_STRING) ||
(terminal->expr_type == ASN_STRING_BMPString) ||
(terminal->expr_type == ASN_BASIC_OCTET_STRING) ||
(terminal->expr_type == ASN_STRING_UniversalString))) {
OUT("&asn_SPC_%s_specs\t/* Additional specs */\n", asn1c_type_name(arg, terminal, TNF_SAFE));
} else {
OUT("0\t/* No specifics */\n");
}
break;
case ETD_HAS_SPECIFICS:
OUT("&asn_SPC_%s_specs_%d\t/* Additional specs */\n",
Expand Down Expand Up @@ -2815,7 +2908,7 @@ asn1c_recurse(arg_t *arg, asn1p_expr_t *expr, int (*callback)(arg_t *arg, void *
int maxret = 0;
int ret;

if(expr->_mark) return 0;
if(expr->_mark & TM_RECURSION) return 0;
expr->_mark |= TM_RECURSION;

/* Invoke callback for every type going into recursion */
Expand Down