2004-06-03 03:38:44 +00:00
|
|
|
/*
|
|
|
|
* Don't look into this file. First, because it's a mess, and second, because
|
|
|
|
* it's a brain of the compiler, and you don't wanna mess with brains do you? ;)
|
|
|
|
*/
|
|
|
|
#include "asn1c_internal.h"
|
|
|
|
#include "asn1c_C.h"
|
2004-08-19 13:29:46 +00:00
|
|
|
#include "asn1c_constraint.h"
|
2004-08-20 13:37:01 +00:00
|
|
|
#include "asn1c_out.h"
|
|
|
|
#include "asn1c_misc.h"
|
2005-11-26 11:25:14 +00:00
|
|
|
#include <asn1fix_crange.h> /* constraint groker from libasn1fix */
|
|
|
|
#include <asn1fix_export.h> /* other exportables from libasn1fix */
|
2017-08-04 08:38:41 +00:00
|
|
|
#include <asn1parser.h>
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2004-06-06 07:20:17 +00:00
|
|
|
typedef struct tag2el_s {
|
|
|
|
struct asn1p_type_tag_s el_tag;
|
|
|
|
int el_no;
|
2004-06-14 13:09:45 +00:00
|
|
|
int toff_first;
|
|
|
|
int toff_last;
|
2004-06-06 07:20:17 +00:00
|
|
|
asn1p_expr_t *from_expr;
|
|
|
|
} tag2el_t;
|
|
|
|
|
2004-10-03 09:13:30 +00:00
|
|
|
typedef enum fte {
|
|
|
|
FTE_ALLTAGS,
|
|
|
|
FTE_CANONICAL_XER,
|
|
|
|
} fte_e;
|
|
|
|
static int _fill_tag2el_map(arg_t *arg, tag2el_t **tag2el, int *count, int el_no, fte_e flags);
|
|
|
|
static int _add_tag2el_member(arg_t *arg, tag2el_t **tag2el, int *count, int el_no, fte_e flags);
|
2004-06-06 07:20:17 +00:00
|
|
|
|
2005-08-14 15:03:31 +00:00
|
|
|
enum onc_flags {
|
|
|
|
ONC_noflags = 0x00,
|
|
|
|
ONC_avoid_keywords = 0x01,
|
|
|
|
ONC_force_compound_name = 0x02,
|
|
|
|
};
|
|
|
|
static int out_name_chain(arg_t *arg, enum onc_flags);
|
2004-06-03 03:38:44 +00:00
|
|
|
static int asn1c_lang_C_type_SEQUENCE_def(arg_t *arg);
|
|
|
|
static int asn1c_lang_C_type_SET_def(arg_t *arg);
|
|
|
|
static int asn1c_lang_C_type_CHOICE_def(arg_t *arg);
|
|
|
|
static int asn1c_lang_C_type_SEx_OF_def(arg_t *arg, int seq_of);
|
2004-09-10 06:07:18 +00:00
|
|
|
static int _print_tag(arg_t *arg, struct asn1p_type_tag_s *tag_p);
|
2005-11-26 11:25:14 +00:00
|
|
|
static int compute_extensions_start(asn1p_expr_t *expr);
|
2005-08-16 17:00:21 +00:00
|
|
|
static int expr_break_recursion(arg_t *arg, asn1p_expr_t *expr);
|
2004-09-22 16:06:28 +00:00
|
|
|
static int expr_as_xmlvaluelist(arg_t *arg, asn1p_expr_t *expr);
|
2004-08-25 02:03:12 +00:00
|
|
|
static int expr_elements_count(arg_t *arg, asn1p_expr_t *expr);
|
2017-08-02 19:53:44 +00:00
|
|
|
static int emit_single_member_OER_constraint_value(arg_t *arg, asn1cnst_range_t *range);
|
|
|
|
static int emit_single_member_OER_constraint_size(arg_t *arg, asn1cnst_range_t *range);
|
|
|
|
static int emit_single_member_PER_constraint(arg_t *arg, asn1cnst_range_t *range, int juscountvalues, const char *type);
|
2017-07-19 04:51:11 +00:00
|
|
|
static int emit_member_OER_constraints(arg_t *arg, asn1p_expr_t *expr, const char *pfx);
|
2006-10-09 12:27:44 +00:00
|
|
|
static int emit_member_PER_constraints(arg_t *arg, asn1p_expr_t *expr, const char *pfx);
|
2004-08-25 02:03:12 +00:00
|
|
|
static int emit_member_table(arg_t *arg, asn1p_expr_t *expr);
|
2004-10-03 09:13:30 +00:00
|
|
|
static int emit_tag2member_map(arg_t *arg, tag2el_t *tag2el, int tag2el_count, const char *opt_modifier);
|
2005-03-04 22:18:20 +00:00
|
|
|
static int emit_include_dependencies(arg_t *arg);
|
2005-08-18 13:38:19 +00:00
|
|
|
static asn1p_expr_t *terminal_structable(arg_t *arg, asn1p_expr_t *expr);
|
|
|
|
static int expr_defined_recursively(arg_t *arg, asn1p_expr_t *expr);
|
|
|
|
static int asn1c_recurse(arg_t *arg, asn1p_expr_t *expr, int (*callback)(arg_t *arg, void *key), void *key);
|
2005-11-26 11:25:14 +00:00
|
|
|
static asn1p_expr_type_e expr_get_type(arg_t *arg, asn1p_expr_t *expr);
|
|
|
|
static int try_inline_default(arg_t *arg, asn1p_expr_t *expr, int out);
|
|
|
|
static int *compute_canonical_members_order(arg_t *arg, int el_count);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2004-09-13 08:31:01 +00:00
|
|
|
enum tvm_compat {
|
|
|
|
_TVM_SAME = 0, /* tags and all_tags are same */
|
|
|
|
_TVM_SUBSET = 1, /* tags are subset of all_tags */
|
|
|
|
_TVM_DIFFERENT = 2, /* tags and all_tags are different */
|
|
|
|
};
|
|
|
|
static enum tvm_compat emit_tags_vectors(arg_t *arg, asn1p_expr_t *expr, int *tc, int *atc);
|
|
|
|
|
2004-08-25 02:03:12 +00:00
|
|
|
enum etd_spec {
|
|
|
|
ETD_NO_SPECIFICS,
|
|
|
|
ETD_HAS_SPECIFICS
|
|
|
|
};
|
2004-09-26 13:11:31 +00:00
|
|
|
static int emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, enum tvm_compat tv_mode, int tags_count, int all_tags_count, int elements_count, enum etd_spec);
|
2004-08-25 02:03:12 +00:00
|
|
|
|
2004-08-20 13:37:01 +00:00
|
|
|
#define C99_MODE (!(arg->flags & A1C_NO_C99))
|
2004-06-03 03:38:44 +00:00
|
|
|
#define UNNAMED_UNIONS (arg->flags & A1C_UNNAMED_UNIONS)
|
2004-09-06 08:07:29 +00:00
|
|
|
#define HIDE_INNER_DEFS (arg->embed && !(arg->flags & A1C_ALL_DEFS_GLOBAL))
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
#define PCTX_DEF INDENTED( \
|
|
|
|
OUT("\n"); \
|
|
|
|
OUT("/* Context for parsing across buffer boundaries */\n"); \
|
2004-09-29 13:16:40 +00:00
|
|
|
OUT("asn_struct_ctx_t _asn_ctx;\n"));
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2005-03-04 22:18:20 +00:00
|
|
|
|
2004-08-11 05:21:32 +00:00
|
|
|
#define DEPENDENCIES do { \
|
2005-03-04 22:18:20 +00:00
|
|
|
emit_include_dependencies(arg); \
|
2004-08-11 05:21:32 +00:00
|
|
|
if(expr->expr_type == ASN_CONSTR_SET_OF) \
|
2006-09-13 02:51:20 +00:00
|
|
|
GEN_INCLUDE_STD("asn_SET_OF"); \
|
2004-08-11 05:21:32 +00:00
|
|
|
if(expr->expr_type == ASN_CONSTR_SEQUENCE_OF) \
|
2006-09-13 02:51:20 +00:00
|
|
|
GEN_INCLUDE_STD("asn_SEQUENCE_OF"); \
|
2004-08-11 05:21:32 +00:00
|
|
|
} while(0)
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2005-03-04 23:48:19 +00:00
|
|
|
/* MKID_safe() without checking for reserved keywords */
|
2006-03-21 03:40:38 +00:00
|
|
|
#define MKID(expr) (asn1c_make_identifier(0, expr, 0))
|
|
|
|
#define MKID_safe(expr) (asn1c_make_identifier(AMI_CHECK_RESERVED, expr, 0))
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
int
|
2004-09-14 12:47:45 +00:00
|
|
|
asn1c_lang_C_type_REAL(arg_t *arg) {
|
2004-06-03 03:38:44 +00:00
|
|
|
return asn1c_lang_C_type_SIMPLE_TYPE(arg);
|
|
|
|
}
|
|
|
|
|
2005-02-25 12:10:27 +00:00
|
|
|
struct value2enum {
|
|
|
|
asn1c_integer_t value;
|
|
|
|
const char *name;
|
|
|
|
int idx;
|
|
|
|
};
|
|
|
|
static int compar_enumMap_byName(const void *ap, const void *bp) {
|
|
|
|
const struct value2enum *a = (const struct value2enum *)ap;
|
|
|
|
const struct value2enum *b = (const struct value2enum *)bp;
|
|
|
|
return strcmp(a->name, b->name);
|
|
|
|
}
|
|
|
|
static int compar_enumMap_byValue(const void *ap, const void *bp) {
|
|
|
|
const struct value2enum *a = (const struct value2enum *)ap;
|
|
|
|
const struct value2enum *b = (const struct value2enum *)bp;
|
|
|
|
if(a->value < b->value)
|
|
|
|
return -1;
|
|
|
|
else if(a->value == b->value)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
int
|
2004-09-14 12:47:45 +00:00
|
|
|
asn1c_lang_C_type_common_INTEGER(arg_t *arg) {
|
2004-06-03 03:38:44 +00:00
|
|
|
asn1p_expr_t *expr = arg->expr;
|
|
|
|
asn1p_expr_t *v;
|
2005-02-25 12:10:27 +00:00
|
|
|
int el_count = expr_elements_count(arg, expr);
|
|
|
|
struct value2enum *v2e;
|
2005-11-26 11:25:14 +00:00
|
|
|
int map_extensions = (expr->expr_type == ASN_BASIC_INTEGER);
|
2005-08-13 23:30:24 +00:00
|
|
|
int eidx;
|
2016-06-05 16:23:16 +00:00
|
|
|
int saved_target = arg->target->target;
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2005-02-25 12:10:27 +00:00
|
|
|
v2e = alloca((el_count + 1) * sizeof(*v2e));
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2005-02-25 12:10:27 +00:00
|
|
|
/*
|
2005-08-13 23:30:24 +00:00
|
|
|
* For all ENUMERATED types and for those INTEGER types which
|
|
|
|
* have identifiers, print out an enumeration table.
|
2005-02-25 12:10:27 +00:00
|
|
|
*/
|
2005-08-13 23:30:24 +00:00
|
|
|
if(expr->expr_type == ASN_BASIC_ENUMERATED || el_count) {
|
|
|
|
eidx = 0;
|
2005-02-25 12:10:27 +00:00
|
|
|
REDIR(OT_DEPS);
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("typedef enum ");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT(" {\n");
|
2004-06-03 03:38:44 +00:00
|
|
|
TQ_FOR(v, &(expr->members), next) {
|
|
|
|
switch(v->expr_type) {
|
|
|
|
case A1TC_UNIVERVAL:
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("\t");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_noflags);
|
2006-03-21 03:40:38 +00:00
|
|
|
OUT("_%s", MKID(v));
|
2017-08-04 08:38:41 +00:00
|
|
|
OUT("\t= %s%s\n",
|
|
|
|
asn1p_itoa(v->value->value.v_integer),
|
2005-03-04 08:48:53 +00:00
|
|
|
(eidx+1 < el_count) ? "," : "");
|
2005-02-25 12:10:27 +00:00
|
|
|
v2e[eidx].name = v->Identifier;
|
|
|
|
v2e[eidx].value = v->value->value.v_integer;
|
|
|
|
eidx++;
|
2004-06-03 03:38:44 +00:00
|
|
|
break;
|
2004-09-14 12:47:45 +00:00
|
|
|
case A1TC_EXTENSIBLE:
|
|
|
|
OUT("\t/*\n");
|
|
|
|
OUT("\t * Enumeration is extensible\n");
|
|
|
|
OUT("\t */\n");
|
2005-11-26 11:25:14 +00:00
|
|
|
if(!map_extensions)
|
|
|
|
map_extensions = eidx + 1;
|
2004-09-14 12:47:45 +00:00
|
|
|
break;
|
2004-06-03 03:38:44 +00:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2006-03-21 07:25:18 +00:00
|
|
|
OUT("} e_");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_noflags);
|
2006-03-21 07:25:18 +00:00
|
|
|
OUT(";\n");
|
2005-02-25 12:10:27 +00:00
|
|
|
assert(eidx == el_count);
|
2005-08-13 23:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For all ENUMERATED types print out a mapping table
|
|
|
|
* between identifiers and associated values.
|
|
|
|
* This is prohibited for INTEGER types by by X.693:8.3.4.
|
|
|
|
*/
|
|
|
|
if(expr->expr_type == ASN_BASIC_ENUMERATED) {
|
2005-02-25 12:10:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Generate a enumerationName<->value map for XER codec.
|
|
|
|
*/
|
|
|
|
REDIR(OT_STAT_DEFS);
|
|
|
|
|
2014-07-28 19:16:01 +00:00
|
|
|
OUT("static const asn_INTEGER_enum_map_t asn_MAP_%s_value2enum_%d[] = {\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr), expr->_type_unique_index);
|
2005-02-25 12:10:27 +00:00
|
|
|
qsort(v2e, el_count, sizeof(v2e[0]), compar_enumMap_byValue);
|
|
|
|
for(eidx = 0; eidx < el_count; eidx++) {
|
|
|
|
v2e[eidx].idx = eidx;
|
2017-08-04 08:38:41 +00:00
|
|
|
OUT("\t{ %s,\t%ld,\t\"%s\" }%s\n",
|
|
|
|
asn1p_itoa(v2e[eidx].value),
|
2005-02-25 12:10:27 +00:00
|
|
|
(long)strlen(v2e[eidx].name), v2e[eidx].name,
|
|
|
|
(eidx + 1 < el_count) ? "," : "");
|
|
|
|
}
|
2005-11-26 11:25:14 +00:00
|
|
|
if(map_extensions)
|
2005-02-25 12:10:27 +00:00
|
|
|
OUT("\t/* This list is extensible */\n");
|
|
|
|
OUT("};\n");
|
|
|
|
|
2014-07-28 19:16:01 +00:00
|
|
|
OUT("static const unsigned int asn_MAP_%s_enum2value_%d[] = {\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr), expr->_type_unique_index);
|
2005-02-25 12:10:27 +00:00
|
|
|
qsort(v2e, el_count, sizeof(v2e[0]), compar_enumMap_byName);
|
|
|
|
for(eidx = 0; eidx < el_count; eidx++) {
|
2017-08-04 08:38:41 +00:00
|
|
|
OUT("\t%d%s\t/* %s(%s) */\n",
|
2005-02-25 12:10:27 +00:00
|
|
|
v2e[eidx].idx,
|
|
|
|
(eidx + 1 < el_count) ? "," : "",
|
2017-08-04 08:38:41 +00:00
|
|
|
v2e[eidx].name, asn1p_itoa(v2e[eidx].value));
|
2005-02-25 12:10:27 +00:00
|
|
|
}
|
2005-11-26 11:25:14 +00:00
|
|
|
if(map_extensions)
|
2005-02-25 12:10:27 +00:00
|
|
|
OUT("\t/* This list is extensible */\n");
|
|
|
|
OUT("};\n");
|
|
|
|
|
2016-05-16 05:50:09 +00:00
|
|
|
if(!(expr->_type_referenced)) OUT("static ");
|
|
|
|
OUT("const asn_INTEGER_specifics_t asn_SPC_%s_specs_%d = {\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr), expr->_type_unique_index);
|
2005-02-25 12:10:27 +00:00
|
|
|
INDENT(+1);
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("asn_MAP_%s_value2enum_%d,\t"
|
2005-02-25 12:10:27 +00:00
|
|
|
"/* \"tag\" => N; sorted by tag */\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr),
|
2005-03-04 08:48:53 +00:00
|
|
|
expr->_type_unique_index);
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("asn_MAP_%s_enum2value_%d,\t"
|
2005-02-25 12:10:27 +00:00
|
|
|
"/* N => \"tag\"; sorted by N */\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr),
|
2005-03-04 08:48:53 +00:00
|
|
|
expr->_type_unique_index);
|
2005-02-25 12:10:27 +00:00
|
|
|
OUT("%d,\t/* Number of elements in the maps */\n",
|
|
|
|
el_count);
|
2005-11-26 11:25:14 +00:00
|
|
|
if(map_extensions) {
|
|
|
|
OUT("%d,\t/* Extensions before this member */\n",
|
|
|
|
map_extensions);
|
|
|
|
} else {
|
|
|
|
OUT("0,\t/* Enumeration is not extensible */\n");
|
|
|
|
}
|
2005-02-25 12:10:27 +00:00
|
|
|
if(expr->expr_type == ASN_BASIC_ENUMERATED)
|
2007-12-03 13:41:36 +00:00
|
|
|
OUT("1,\t/* Strict enumeration */\n");
|
2005-02-25 12:10:27 +00:00
|
|
|
else
|
2007-12-03 13:41:36 +00:00
|
|
|
OUT("0,\n");
|
|
|
|
OUT("0,\t/* Native long size */\n");
|
|
|
|
OUT("0\n");
|
|
|
|
INDENT(-1);
|
|
|
|
OUT("};\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(expr->expr_type == ASN_BASIC_INTEGER
|
|
|
|
&& asn1c_type_fits_long(arg, expr) == FL_FITS_UNSIGN) {
|
|
|
|
REDIR(OT_STAT_DEFS);
|
2016-05-16 05:50:09 +00:00
|
|
|
if(!(expr->_type_referenced)) OUT("static ");
|
|
|
|
OUT("const asn_INTEGER_specifics_t asn_SPC_%s_specs_%d = {\n",
|
2007-12-03 13:41:36 +00:00
|
|
|
MKID(expr), expr->_type_unique_index);
|
|
|
|
INDENT(+1);
|
|
|
|
OUT("0,\t");
|
|
|
|
OUT("0,\t");
|
|
|
|
OUT("0,\t");
|
|
|
|
OUT("0,\t");
|
|
|
|
OUT("0,\n");
|
|
|
|
OUT("0,\t/* Native long size */\n");
|
|
|
|
OUT("1\t/* Unsigned representation */\n");
|
2005-02-25 12:10:27 +00:00
|
|
|
INDENT(-1);
|
|
|
|
OUT("};\n");
|
2004-06-03 03:38:44 +00:00
|
|
|
}
|
|
|
|
|
2016-06-05 16:23:16 +00:00
|
|
|
REDIR(saved_target);
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
return asn1c_lang_C_type_SIMPLE_TYPE(arg);
|
|
|
|
}
|
|
|
|
|
2005-08-13 23:51:47 +00:00
|
|
|
int
|
|
|
|
asn1c_lang_C_type_BIT_STRING(arg_t *arg) {
|
|
|
|
asn1p_expr_t *expr = arg->expr;
|
|
|
|
asn1p_expr_t *v;
|
|
|
|
int el_count = expr_elements_count(arg, expr);
|
2016-06-05 16:23:16 +00:00
|
|
|
int saved_target = arg->target->target;
|
2005-08-13 23:51:47 +00:00
|
|
|
|
|
|
|
if(el_count) {
|
2005-08-14 02:18:27 +00:00
|
|
|
int eidx = 0;
|
2005-08-13 23:51:47 +00:00
|
|
|
REDIR(OT_DEPS);
|
|
|
|
OUT("typedef enum ");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
2005-08-13 23:51:47 +00:00
|
|
|
OUT(" {\n");
|
|
|
|
TQ_FOR(v, &(expr->members), next) {
|
2005-08-14 02:18:27 +00:00
|
|
|
if(v->expr_type != A1TC_UNIVERVAL) {
|
2005-08-13 23:51:47 +00:00
|
|
|
OUT("/* Unexpected BIT STRING element: %s */\n",
|
|
|
|
v->Identifier);
|
2005-08-14 02:18:27 +00:00
|
|
|
continue;
|
2005-08-13 23:51:47 +00:00
|
|
|
}
|
2006-08-26 03:29:15 +00:00
|
|
|
eidx++;
|
2005-08-14 02:18:27 +00:00
|
|
|
OUT("\t");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_noflags);
|
2006-03-21 03:40:38 +00:00
|
|
|
OUT("_%s", MKID(v));
|
2017-08-04 08:38:41 +00:00
|
|
|
OUT("\t= %s%s\n",
|
|
|
|
asn1p_itoa(v->value->value.v_integer),
|
2005-08-14 02:18:27 +00:00
|
|
|
(eidx < el_count) ? "," : "");
|
2005-08-13 23:51:47 +00:00
|
|
|
}
|
2006-03-21 07:25:18 +00:00
|
|
|
OUT("} e_");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_noflags);
|
2006-03-21 07:25:18 +00:00
|
|
|
OUT(";\n");
|
2005-08-13 23:51:47 +00:00
|
|
|
assert(eidx == el_count);
|
|
|
|
}
|
|
|
|
|
2016-06-05 16:23:16 +00:00
|
|
|
REDIR(saved_target);
|
|
|
|
|
2005-08-13 23:51:47 +00:00
|
|
|
return asn1c_lang_C_type_SIMPLE_TYPE(arg);
|
|
|
|
}
|
|
|
|
|
2017-08-07 06:23:04 +00:00
|
|
|
/*
|
|
|
|
* Given the table constraint or component relation constraint
|
|
|
|
* ({ObjectSetName}{...}) returns "ObjectSetName" as a reference.
|
|
|
|
*/
|
|
|
|
static const asn1p_ref_t *
|
|
|
|
asn1c_get_information_object_set_reference_from_constraint(
|
|
|
|
const asn1p_constraint_t *ct) {
|
|
|
|
|
|
|
|
if(!ct) return NULL;
|
|
|
|
assert(ct->type == ACT_CA_CRC);
|
|
|
|
assert(ct->el_count >= 1);
|
|
|
|
|
|
|
|
assert(ct->elements[0]->type == ACT_EL_VALUE);
|
|
|
|
|
|
|
|
asn1p_value_t *val = ct->elements[0]->value;
|
|
|
|
assert(val->type == ATV_REFERENCED);
|
|
|
|
|
|
|
|
return val->value.reference;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct asn1c_ioc_table_s {
|
|
|
|
} asn1c_ioc_table_t;
|
|
|
|
|
|
|
|
static asn1c_ioc_table_t *
|
|
|
|
asn1c_construct_ioc_table_from_objset(arg_t *arg, const asn1p_ref_t *objset_ref, asn1p_expr_t *objset) {
|
2017-08-07 06:41:11 +00:00
|
|
|
(void)arg;
|
|
|
|
(void)objset_ref;
|
|
|
|
(void)objset;
|
|
|
|
|
2017-08-07 06:23:04 +00:00
|
|
|
asn1c_ioc_table_t *itable = NULL;
|
|
|
|
itable = calloc(1, sizeof(*itable));
|
|
|
|
assert(itable);
|
|
|
|
|
|
|
|
return itable;
|
|
|
|
};
|
|
|
|
|
|
|
|
static asn1c_ioc_table_t *
|
|
|
|
asn1c_construct_ioc_table(arg_t *arg) {
|
|
|
|
asn1p_expr_t *expr = arg->expr;
|
|
|
|
asn1p_expr_t *memb;
|
|
|
|
asn1p_expr_t *objset = 0;
|
|
|
|
const asn1p_ref_t *objset_ref = NULL;
|
|
|
|
|
|
|
|
TQ_FOR(memb, &(expr->members), next) {
|
|
|
|
const asn1p_ref_t *tmpref =
|
|
|
|
asn1c_get_information_object_set_reference_from_constraint(
|
|
|
|
asn1p_get_component_relation_constraint(memb->constraints));
|
|
|
|
if(tmpref) {
|
|
|
|
if(objset_ref && asn1p_ref_compare(objset_ref, tmpref) != 0) {
|
|
|
|
FATAL(
|
|
|
|
"Object set reference on line %d differs from object set "
|
|
|
|
"reference on line %d",
|
|
|
|
objset_ref->_lineno, tmpref->_lineno);
|
|
|
|
errno = EINVAL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
objset_ref = tmpref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!objset_ref) {
|
|
|
|
errno = 0; /* "Safe" error. */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
objset = asn1f_lookup_symbol_ex(arg->asn, arg->expr, objset_ref);
|
|
|
|
if(!objset) {
|
|
|
|
FATAL("Cannot found %s", asn1p_ref_string(objset_ref));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return asn1c_construct_ioc_table_from_objset(arg, objset_ref, objset);
|
|
|
|
}
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
int
|
|
|
|
asn1c_lang_C_type_SEQUENCE(arg_t *arg) {
|
|
|
|
asn1p_expr_t *expr = arg->expr;
|
|
|
|
asn1p_expr_t *v;
|
|
|
|
int comp_mode = 0; /* {root,ext=1,root,root,...} */
|
2016-06-05 16:23:16 +00:00
|
|
|
int saved_target = arg->target->target;
|
2017-08-07 06:23:04 +00:00
|
|
|
asn1c_ioc_table_t *itable = NULL;
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
DEPENDENCIES;
|
|
|
|
|
2017-08-07 06:23:04 +00:00
|
|
|
itable = asn1c_construct_ioc_table(arg);
|
|
|
|
if(!itable && errno != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
if(arg->embed) {
|
2016-06-05 16:23:16 +00:00
|
|
|
|
|
|
|
/* Use _anonymous_type field to indicate it's called from
|
|
|
|
* asn1c_lang_C_type_SEx_OF() */
|
|
|
|
if (expr->_anonymous_type) {
|
|
|
|
REDIR(OT_FWD_DEFS);
|
|
|
|
OUT("typedef ");
|
|
|
|
}
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("struct ");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT(" {\n");
|
2004-06-03 03:38:44 +00:00
|
|
|
} else {
|
2016-06-05 16:23:16 +00:00
|
|
|
REDIR(OT_TYPE_DECLS);
|
2004-06-03 03:38:44 +00:00
|
|
|
OUT("typedef struct %s {\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID_safe(expr));
|
2004-06-03 03:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TQ_FOR(v, &(expr->members), next) {
|
2005-08-16 17:00:21 +00:00
|
|
|
if(v->expr_type == A1TC_EXTENSIBLE)
|
2004-06-03 03:38:44 +00:00
|
|
|
if(comp_mode < 3) comp_mode++;
|
2005-08-16 17:00:21 +00:00
|
|
|
if(comp_mode == 1)
|
2005-11-26 11:25:14 +00:00
|
|
|
v->marker.flags |= EM_OMITABLE | EM_INDIRECT;
|
|
|
|
try_inline_default(arg, v, 1);
|
2004-06-03 03:38:44 +00:00
|
|
|
EMBED(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
PCTX_DEF;
|
2016-06-05 16:23:16 +00:00
|
|
|
|
|
|
|
if (arg->embed && expr->_anonymous_type) {
|
|
|
|
OUT("} %s", (expr->marker.flags & EM_INDIRECT)?"*":"");
|
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
|
|
|
OUT("%s;\n", arg->embed ? "" : "_t");
|
|
|
|
|
|
|
|
REDIR(saved_target);
|
|
|
|
|
|
|
|
OUT("%s", (expr->marker.flags & EM_INDIRECT)?"*":"");
|
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
|
|
|
} else {
|
|
|
|
OUT("} %s%s%s", (expr->marker.flags & EM_INDIRECT)?"*":"",
|
2005-03-04 23:48:19 +00:00
|
|
|
expr->_anonymous_type ? "" :
|
|
|
|
arg->embed
|
2006-03-21 03:40:38 +00:00
|
|
|
? MKID_safe(expr)
|
|
|
|
: MKID(expr),
|
2004-08-22 03:25:24 +00:00
|
|
|
arg->embed ? "" : "_t");
|
2016-06-05 16:23:16 +00:00
|
|
|
}
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
return asn1c_lang_C_type_SEQUENCE_def(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
asn1c_lang_C_type_SEQUENCE_def(arg_t *arg) {
|
|
|
|
asn1p_expr_t *expr = arg->expr;
|
|
|
|
asn1p_expr_t *v;
|
|
|
|
int elements; /* Number of elements */
|
2007-06-23 20:05:49 +00:00
|
|
|
int ext_start = -2;
|
|
|
|
int ext_stop = -2;
|
2004-06-06 07:20:17 +00:00
|
|
|
tag2el_t *tag2el = NULL;
|
|
|
|
int tag2el_count = 0;
|
2004-08-11 07:17:22 +00:00
|
|
|
int tags_count;
|
2004-09-13 08:31:01 +00:00
|
|
|
int all_tags_count;
|
|
|
|
enum tvm_compat tv_mode;
|
2005-11-26 11:25:14 +00:00
|
|
|
int roms_count; /* Root optional members */
|
|
|
|
int aoms_count; /* Additions optional members */
|
2016-06-05 16:23:16 +00:00
|
|
|
int saved_target = arg->target->target;
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2004-06-06 07:20:17 +00:00
|
|
|
/*
|
|
|
|
* Fetch every inner tag from the tag to elements map.
|
|
|
|
*/
|
2004-10-03 09:13:30 +00:00
|
|
|
if(_fill_tag2el_map(arg, &tag2el, &tag2el_count, -1, FTE_ALLTAGS)) {
|
2004-06-06 07:20:17 +00:00
|
|
|
if(tag2el) free(tag2el);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-09-13 02:51:20 +00:00
|
|
|
GEN_INCLUDE_STD("constr_SEQUENCE");
|
2004-08-11 05:21:32 +00:00
|
|
|
if(!arg->embed)
|
2016-05-16 05:50:09 +00:00
|
|
|
GEN_DECLARE("SEQUENCE", expr); /* asn_DEF_xxx */
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2004-08-11 05:21:32 +00:00
|
|
|
REDIR(OT_STAT_DEFS);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
/*
|
2005-11-26 11:25:14 +00:00
|
|
|
* Print out the table according to which parsing is performed.
|
2004-06-03 03:38:44 +00:00
|
|
|
*/
|
2004-09-22 16:06:28 +00:00
|
|
|
if(expr_elements_count(arg, expr)) {
|
|
|
|
int comp_mode = 0; /* {root,ext=1,root,root,...} */
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2016-05-16 05:50:09 +00:00
|
|
|
if(!(expr->_type_referenced)) OUT("static ");
|
|
|
|
OUT("asn_TYPE_member_t asn_MBR_%s_%d[] = {\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr), expr->_type_unique_index);
|
2004-09-22 16:06:28 +00:00
|
|
|
|
|
|
|
elements = 0;
|
2005-11-26 11:25:14 +00:00
|
|
|
roms_count = 0;
|
|
|
|
aoms_count = 0;
|
2004-09-22 16:06:28 +00:00
|
|
|
INDENTED(TQ_FOR(v, &(expr->members), next) {
|
|
|
|
if(v->expr_type == A1TC_EXTENSIBLE) {
|
|
|
|
if((++comp_mode) == 1)
|
|
|
|
ext_start = elements - 1;
|
|
|
|
else
|
|
|
|
ext_stop = elements - 1;
|
|
|
|
continue;
|
|
|
|
}
|
2005-11-26 11:25:14 +00:00
|
|
|
if(v->marker.flags & EM_OMITABLE)
|
|
|
|
comp_mode == 1 ? ++aoms_count : ++roms_count;
|
2004-09-22 16:06:28 +00:00
|
|
|
emit_member_table(arg, v);
|
2005-08-16 17:00:21 +00:00
|
|
|
elements++;
|
2004-09-22 16:06:28 +00:00
|
|
|
});
|
|
|
|
OUT("};\n");
|
2005-11-26 11:25:14 +00:00
|
|
|
|
2017-07-23 21:49:24 +00:00
|
|
|
if((roms_count + aoms_count) && (arg->flags & (A1C_GEN_OER|A1C_GEN_PER))) {
|
2005-11-26 11:25:14 +00:00
|
|
|
int elm = 0;
|
|
|
|
int comma = 0;
|
|
|
|
comp_mode = 0;
|
2014-07-28 19:16:01 +00:00
|
|
|
OUT("static const int asn_MAP_%s_oms_%d[] = {",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr),
|
2005-11-26 11:25:14 +00:00
|
|
|
expr->_type_unique_index);
|
|
|
|
TQ_FOR(v, &(expr->members), next) {
|
|
|
|
if(v->expr_type == A1TC_EXTENSIBLE) {
|
|
|
|
++comp_mode;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if((v->marker.flags & EM_OMITABLE)
|
|
|
|
&& comp_mode != 1) {
|
|
|
|
if(!comma) comma++;
|
|
|
|
else OUT(",");
|
|
|
|
OUT(" %d", elm);
|
|
|
|
}
|
|
|
|
++elm;
|
|
|
|
}
|
|
|
|
elm = 0;
|
|
|
|
comp_mode = 0;
|
|
|
|
TQ_FOR(v, &(expr->members), next) {
|
|
|
|
if(v->expr_type == A1TC_EXTENSIBLE) {
|
|
|
|
++comp_mode;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if((v->marker.flags & EM_OMITABLE)
|
|
|
|
&& comp_mode == 1) {
|
|
|
|
if(!comma) comma++;
|
|
|
|
else OUT(",");
|
|
|
|
OUT(" %d", elm);
|
|
|
|
}
|
|
|
|
++elm;
|
|
|
|
}
|
|
|
|
OUT(" };\n");
|
2017-08-07 06:23:04 +00:00
|
|
|
if(roms_count > 65536) {
|
2005-11-26 11:25:14 +00:00
|
|
|
FATAL("Too many optional elements in %s "
|
|
|
|
"at line %d!",
|
|
|
|
arg->expr->Identifier,
|
|
|
|
arg->expr->_lineno);
|
2017-08-07 06:23:04 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2005-11-26 11:25:14 +00:00
|
|
|
} else {
|
|
|
|
roms_count = 0;
|
|
|
|
aoms_count = 0;
|
|
|
|
}
|
2004-09-22 16:06:28 +00:00
|
|
|
} else {
|
|
|
|
elements = 0;
|
2005-11-26 11:25:14 +00:00
|
|
|
roms_count = 0;
|
|
|
|
aoms_count = 0;
|
2004-09-22 16:06:28 +00:00
|
|
|
}
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2004-06-28 21:13:46 +00:00
|
|
|
/*
|
2004-09-29 13:16:40 +00:00
|
|
|
* Print out asn_DEF_<type>_[all_]tags[] vectors.
|
2004-06-28 21:13:46 +00:00
|
|
|
*/
|
2004-09-13 08:31:01 +00:00
|
|
|
tv_mode = emit_tags_vectors(arg, expr, &tags_count, &all_tags_count);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2004-06-06 07:20:17 +00:00
|
|
|
/*
|
|
|
|
* Tags to elements map.
|
|
|
|
*/
|
2004-10-03 09:13:30 +00:00
|
|
|
emit_tag2member_map(arg, tag2el, tag2el_count, 0);
|
2004-06-06 07:20:17 +00:00
|
|
|
|
2016-05-16 05:50:09 +00:00
|
|
|
if(!(expr->_type_referenced)) OUT("static ");
|
|
|
|
OUT("asn_SEQUENCE_specifics_t asn_SPC_%s_specs_%d = {\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr), expr->_type_unique_index);
|
2005-11-26 11:25:14 +00:00
|
|
|
INDENT(+1);
|
|
|
|
OUT("sizeof(struct ");
|
|
|
|
out_name_chain(arg, ONC_avoid_keywords); OUT("),\n");
|
|
|
|
OUT("offsetof(struct ");
|
|
|
|
out_name_chain(arg, ONC_avoid_keywords); OUT(", _asn_ctx),\n");
|
2005-03-04 08:48:53 +00:00
|
|
|
|
2005-11-26 11:25:14 +00:00
|
|
|
if(tag2el_count) {
|
|
|
|
OUT("asn_MAP_%s_tag2el_%d,\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr),
|
2005-11-26 11:25:14 +00:00
|
|
|
expr->_type_unique_index);
|
|
|
|
OUT("%d,\t/* Count of tags in the map */\n", tag2el_count);
|
|
|
|
} else {
|
|
|
|
OUT("0,\t/* No top level tags */\n");
|
|
|
|
OUT("0,\t/* No tags in the map */\n");
|
|
|
|
}
|
|
|
|
if(roms_count + aoms_count) {
|
|
|
|
OUT("asn_MAP_%s_oms_%d,\t/* Optional members */\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr), expr->_type_unique_index);
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("%d, %d,\t/* Root/Additions */\n", roms_count, aoms_count);
|
|
|
|
} else {
|
|
|
|
OUT("0, 0, 0,\t/* Optional elements (not needed) */\n");
|
|
|
|
}
|
|
|
|
OUT("%d,\t/* Start extensions */\n",
|
2007-06-23 20:05:49 +00:00
|
|
|
ext_start<0 ? -1 : ext_start);
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("%d\t/* Stop extensions */\n",
|
2007-06-23 20:05:49 +00:00
|
|
|
(ext_stop<ext_start)?elements+1:(ext_stop<0?-1:ext_stop));
|
2005-11-26 11:25:14 +00:00
|
|
|
INDENT(-1);
|
2004-06-03 03:38:44 +00:00
|
|
|
OUT("};\n");
|
2004-08-25 02:03:12 +00:00
|
|
|
|
|
|
|
/*
|
2004-09-29 13:16:40 +00:00
|
|
|
* Emit asn_DEF_xxx table.
|
2004-08-25 02:03:12 +00:00
|
|
|
*/
|
2004-09-13 08:31:01 +00:00
|
|
|
emit_type_DEF(arg, expr, tv_mode, tags_count, all_tags_count, elements,
|
2004-09-26 13:11:31 +00:00
|
|
|
ETD_HAS_SPECIFICS);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2016-06-05 16:23:16 +00:00
|
|
|
REDIR(saved_target);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2016-11-04 03:59:45 +00:00
|
|
|
if(tag2el) free(tag2el);
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
return 0;
|
2005-01-17 11:57:48 +00:00
|
|
|
} /* _SEQUENCE_def() */
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
asn1c_lang_C_type_SET(arg_t *arg) {
|
|
|
|
asn1p_expr_t *expr = arg->expr;
|
|
|
|
asn1p_expr_t *v;
|
|
|
|
long mcount;
|
|
|
|
char *id;
|
|
|
|
int comp_mode = 0; /* {root,ext=1,root,root,...} */
|
2016-06-05 16:23:16 +00:00
|
|
|
int saved_target = arg->target->target;
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
DEPENDENCIES;
|
|
|
|
|
|
|
|
REDIR(OT_DEPS);
|
|
|
|
|
|
|
|
OUT("\n");
|
|
|
|
OUT("/*\n");
|
|
|
|
OUT(" * Method of determining the components presence\n");
|
|
|
|
OUT(" */\n");
|
|
|
|
mcount = 0;
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("typedef enum ");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_noflags);
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("_PR {\n");
|
2004-06-03 03:38:44 +00:00
|
|
|
TQ_FOR(v, &(expr->members), next) {
|
|
|
|
if(v->expr_type == A1TC_EXTENSIBLE) continue;
|
|
|
|
INDENTED(
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_noflags);
|
2005-01-28 12:18:50 +00:00
|
|
|
OUT("_PR_");
|
2006-03-21 03:40:38 +00:00
|
|
|
id = MKID(v);
|
2004-06-03 03:38:44 +00:00
|
|
|
OUT("%s,\t/* Member %s is present */\n",
|
|
|
|
id, id)
|
|
|
|
);
|
|
|
|
mcount++;
|
|
|
|
}
|
2005-08-14 15:03:31 +00:00
|
|
|
OUT("} "); out_name_chain(arg, ONC_noflags); OUT("_PR;\n");
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2016-06-05 16:23:16 +00:00
|
|
|
REDIR(saved_target);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
if(arg->embed) {
|
2016-06-05 16:23:16 +00:00
|
|
|
if (expr->_anonymous_type) {
|
|
|
|
REDIR(OT_FWD_DEFS);
|
|
|
|
OUT("typedef ");
|
|
|
|
}
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("struct ");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT(" {\n");
|
2004-06-03 03:38:44 +00:00
|
|
|
} else {
|
2016-06-05 16:23:16 +00:00
|
|
|
REDIR(OT_TYPE_DECLS);
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("typedef struct %s {\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID_safe(expr));
|
2004-06-03 03:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TQ_FOR(v, &(expr->members), next) {
|
2005-11-26 11:25:14 +00:00
|
|
|
if(v->expr_type == A1TC_EXTENSIBLE)
|
2004-06-03 03:38:44 +00:00
|
|
|
if(comp_mode < 3) comp_mode++;
|
2005-08-16 17:00:21 +00:00
|
|
|
if(comp_mode == 1)
|
2005-11-26 11:25:14 +00:00
|
|
|
v->marker.flags |= EM_OMITABLE | EM_INDIRECT;
|
|
|
|
try_inline_default(arg, v, 1);
|
2004-06-03 03:38:44 +00:00
|
|
|
EMBED(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
INDENTED(
|
2006-03-21 03:40:38 +00:00
|
|
|
id = MKID(expr);
|
2004-06-03 03:38:44 +00:00
|
|
|
OUT("\n");
|
|
|
|
OUT("/* Presence bitmask: ASN_SET_ISPRESENT(p%s, %s_PR_x) */\n",
|
|
|
|
id, id);
|
|
|
|
OUT("unsigned int _presence_map\n");
|
|
|
|
OUT("\t[((%ld+(8*sizeof(unsigned int))-1)/(8*sizeof(unsigned int)))];\n", mcount);
|
|
|
|
);
|
|
|
|
|
|
|
|
PCTX_DEF;
|
2016-06-05 16:23:16 +00:00
|
|
|
|
|
|
|
if (arg->embed && expr->_anonymous_type) {
|
|
|
|
OUT("} %s", (expr->marker.flags & EM_INDIRECT)?"*":"");
|
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
|
|
|
OUT("%s;\n", arg->embed ? "" : "_t");
|
|
|
|
|
|
|
|
REDIR(saved_target);
|
|
|
|
|
|
|
|
OUT("%s", (expr->marker.flags & EM_INDIRECT)?"*":"");
|
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
|
|
|
} else {
|
|
|
|
OUT("} %s%s%s", (expr->marker.flags & EM_INDIRECT)?"*":"",
|
|
|
|
expr->_anonymous_type ? "" : MKID_safe(expr),
|
|
|
|
arg->embed ? "" : "_t");
|
|
|
|
}
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
return asn1c_lang_C_type_SET_def(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
asn1c_lang_C_type_SET_def(arg_t *arg) {
|
|
|
|
asn1p_expr_t *expr = arg->expr;
|
|
|
|
asn1p_expr_t *v;
|
|
|
|
int elements;
|
|
|
|
tag2el_t *tag2el = NULL;
|
|
|
|
int tag2el_count = 0;
|
2004-10-03 09:13:30 +00:00
|
|
|
tag2el_t *tag2el_cxer = NULL;
|
|
|
|
int tag2el_cxer_count = 0;
|
2004-08-11 07:17:22 +00:00
|
|
|
int tags_count;
|
2004-09-13 08:31:01 +00:00
|
|
|
int all_tags_count;
|
|
|
|
enum tvm_compat tv_mode;
|
2004-06-03 03:38:44 +00:00
|
|
|
char *p;
|
2016-06-05 16:23:16 +00:00
|
|
|
int saved_target = arg->target->target;
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fetch every inner tag from the tag to elements map.
|
|
|
|
*/
|
2004-10-03 09:13:30 +00:00
|
|
|
if(_fill_tag2el_map(arg, &tag2el, &tag2el_count, -1, FTE_ALLTAGS)) {
|
2004-06-03 03:38:44 +00:00
|
|
|
if(tag2el) free(tag2el);
|
|
|
|
return -1;
|
|
|
|
}
|
2004-10-03 09:13:30 +00:00
|
|
|
if(_fill_tag2el_map(arg, &tag2el_cxer, &tag2el_cxer_count, -1, FTE_CANONICAL_XER)) {
|
|
|
|
if(tag2el) free(tag2el);
|
|
|
|
if(tag2el_cxer) free(tag2el_cxer);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if(tag2el_cxer_count == tag2el_count
|
|
|
|
&& memcmp(tag2el, tag2el_cxer, tag2el_count) == 0) {
|
|
|
|
free(tag2el_cxer);
|
|
|
|
tag2el_cxer = 0;
|
|
|
|
}
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2006-09-13 02:51:20 +00:00
|
|
|
GEN_INCLUDE_STD("constr_SET");
|
2004-08-11 05:21:32 +00:00
|
|
|
if(!arg->embed)
|
2016-05-16 05:50:09 +00:00
|
|
|
GEN_DECLARE("SET", expr); /* asn_DEF_xxx */
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
REDIR(OT_STAT_DEFS);
|
|
|
|
|
|
|
|
/*
|
2005-11-26 11:25:14 +00:00
|
|
|
* Print out the table according to which parsing is performed.
|
2004-06-03 03:38:44 +00:00
|
|
|
*/
|
2004-09-22 16:06:28 +00:00
|
|
|
if(expr_elements_count(arg, expr)) {
|
|
|
|
int comp_mode = 0; /* {root,ext=1,root,root,...} */
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2016-05-16 05:50:09 +00:00
|
|
|
if(!(expr->_type_referenced)) OUT("static ");
|
|
|
|
OUT("asn_TYPE_member_t asn_MBR_%s_%d[] = {\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr), expr->_type_unique_index);
|
2016-06-05 16:23:16 +00:00
|
|
|
|
2004-09-22 16:06:28 +00:00
|
|
|
elements = 0;
|
|
|
|
INDENTED(TQ_FOR(v, &(expr->members), next) {
|
|
|
|
if(v->expr_type == A1TC_EXTENSIBLE) {
|
|
|
|
if(comp_mode < 3) comp_mode++;
|
|
|
|
} else {
|
|
|
|
emit_member_table(arg, v);
|
2005-08-16 17:00:21 +00:00
|
|
|
elements++;
|
2004-09-22 16:06:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
OUT("};\n");
|
|
|
|
} else {
|
|
|
|
elements = 0;
|
|
|
|
}
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2004-06-28 21:13:46 +00:00
|
|
|
/*
|
2004-09-29 13:16:40 +00:00
|
|
|
* Print out asn_DEF_<type>_[all_]tags[] vectors.
|
2004-06-28 21:13:46 +00:00
|
|
|
*/
|
2004-09-13 08:31:01 +00:00
|
|
|
tv_mode = emit_tags_vectors(arg, expr, &tags_count, &all_tags_count);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Tags to elements map.
|
|
|
|
*/
|
2004-10-03 09:13:30 +00:00
|
|
|
emit_tag2member_map(arg, tag2el, tag2el_count, 0);
|
|
|
|
if(tag2el_cxer)
|
|
|
|
emit_tag2member_map(arg, tag2el_cxer, tag2el_cxer_count, "_cxer");
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Emit a map of mandatory elements.
|
|
|
|
*/
|
2014-07-28 19:16:01 +00:00
|
|
|
OUT("static const uint8_t asn_MAP_%s_mmap_%d",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr), expr->_type_unique_index);
|
|
|
|
p = MKID_safe(expr);
|
2004-06-03 03:38:44 +00:00
|
|
|
OUT("[(%d + (8 * sizeof(unsigned int)) - 1) / 8]", elements);
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT(" = {\n");
|
2004-06-03 03:38:44 +00:00
|
|
|
INDENTED(
|
|
|
|
if(elements) {
|
|
|
|
int el = 0;
|
|
|
|
TQ_FOR(v, &(expr->members), next) {
|
|
|
|
if(v->expr_type == A1TC_EXTENSIBLE) continue;
|
2005-10-05 08:59:03 +00:00
|
|
|
if(el) {
|
|
|
|
if((el % 8) == 0)
|
|
|
|
OUT(",\n");
|
|
|
|
else
|
|
|
|
OUT(" | ");
|
2004-06-03 03:38:44 +00:00
|
|
|
}
|
2004-09-10 09:18:20 +00:00
|
|
|
OUT("(%d << %d)",
|
2005-08-18 13:38:19 +00:00
|
|
|
(v->marker.flags & EM_OMITABLE) != EM_OMITABLE,
|
2004-09-10 09:18:20 +00:00
|
|
|
7 - (el % 8));
|
2004-06-03 03:38:44 +00:00
|
|
|
el++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
OUT("0");
|
|
|
|
}
|
|
|
|
);
|
|
|
|
OUT("\n");
|
|
|
|
OUT("};\n");
|
|
|
|
|
2016-05-16 05:50:09 +00:00
|
|
|
if(!(expr->_type_referenced)) OUT("static \n");
|
|
|
|
OUT("asn_SET_specifics_t asn_SPC_%s_specs_%d = {\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr), expr->_type_unique_index);
|
2004-06-03 03:38:44 +00:00
|
|
|
INDENTED(
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("sizeof(struct ");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("),\n");
|
|
|
|
OUT("offsetof(struct ");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT(", _asn_ctx),\n");
|
|
|
|
OUT("offsetof(struct ");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT(", _presence_map),\n");
|
2006-03-21 03:40:38 +00:00
|
|
|
p = MKID(expr);
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("asn_MAP_%s_tag2el_%d,\n", p, expr->_type_unique_index);
|
2004-06-03 03:38:44 +00:00
|
|
|
OUT("%d,\t/* Count of tags in the map */\n", tag2el_count);
|
2004-10-03 09:13:30 +00:00
|
|
|
if(tag2el_cxer)
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("asn_MAP_%s_tag2el_cxer_%d,\n",
|
2005-03-04 08:48:53 +00:00
|
|
|
p, expr->_type_unique_index);
|
2004-10-03 09:13:30 +00:00
|
|
|
else
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("asn_MAP_%s_tag2el_%d,\t/* Same as above */\n",
|
2005-03-04 08:48:53 +00:00
|
|
|
p, expr->_type_unique_index);
|
|
|
|
OUT("%d,\t/* Count of tags in the CXER map */\n",
|
|
|
|
tag2el_cxer_count);
|
2004-07-01 00:52:50 +00:00
|
|
|
OUT("%d,\t/* Whether extensible */\n",
|
2005-11-26 11:25:14 +00:00
|
|
|
compute_extensions_start(expr) == -1 ? 0 : 1);
|
2017-07-06 15:47:53 +00:00
|
|
|
OUT("(const unsigned int *)asn_MAP_%s_mmap_%d\t/* Mandatory elements map */\n",
|
2005-03-04 08:48:53 +00:00
|
|
|
p, expr->_type_unique_index);
|
2004-06-03 03:38:44 +00:00
|
|
|
);
|
|
|
|
OUT("};\n");
|
2004-08-25 02:03:12 +00:00
|
|
|
|
|
|
|
/*
|
2004-09-29 13:16:40 +00:00
|
|
|
* Emit asn_DEF_xxx table.
|
2004-08-25 02:03:12 +00:00
|
|
|
*/
|
2004-09-13 08:31:01 +00:00
|
|
|
emit_type_DEF(arg, expr, tv_mode, tags_count, all_tags_count, elements,
|
2004-09-26 13:11:31 +00:00
|
|
|
ETD_HAS_SPECIFICS);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2016-06-05 16:23:16 +00:00
|
|
|
REDIR(saved_target);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2016-11-04 03:59:45 +00:00
|
|
|
if (tag2el) free(tag2el);
|
|
|
|
if (tag2el_cxer) free(tag2el_cxer);
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
return 0;
|
2005-01-17 11:57:48 +00:00
|
|
|
} /* _SET_def() */
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
int
|
2004-08-22 03:25:24 +00:00
|
|
|
asn1c_lang_C_type_SEx_OF(arg_t *arg) {
|
2004-06-03 03:38:44 +00:00
|
|
|
asn1p_expr_t *expr = arg->expr;
|
2005-03-04 22:18:20 +00:00
|
|
|
asn1p_expr_t *memb = TQ_FIRST(&expr->members);
|
2016-06-05 16:23:16 +00:00
|
|
|
int saved_target = arg->target->target;
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
DEPENDENCIES;
|
|
|
|
|
|
|
|
if(arg->embed) {
|
2016-06-05 16:23:16 +00:00
|
|
|
if (expr->_anonymous_type) {
|
|
|
|
REDIR(OT_FWD_DEFS);
|
|
|
|
OUT("typedef ");
|
|
|
|
}
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("struct ");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT(" {\n");
|
2004-06-03 03:38:44 +00:00
|
|
|
} else {
|
2006-03-21 03:40:38 +00:00
|
|
|
OUT("typedef struct %s {\n", MKID_safe(expr));
|
2004-06-03 03:38:44 +00:00
|
|
|
}
|
|
|
|
|
2004-08-22 03:25:24 +00:00
|
|
|
INDENT(+1);
|
|
|
|
OUT("A_%s_OF(",
|
|
|
|
(arg->expr->expr_type == ASN_CONSTR_SET_OF)
|
|
|
|
? "SET" : "SEQUENCE");
|
2005-08-16 17:00:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* README README
|
|
|
|
* The implementation of the A_SET_OF() macro is already indirect.
|
|
|
|
*/
|
|
|
|
memb->marker.flags |= EM_INDIRECT;
|
|
|
|
|
2005-02-25 12:10:27 +00:00
|
|
|
if(memb->expr_type & ASN_CONSTR_MASK
|
|
|
|
|| ((memb->expr_type == ASN_BASIC_ENUMERATED
|
2005-03-03 21:28:12 +00:00
|
|
|
|| (0 /* -- prohibited by X.693:8.3.4 */
|
|
|
|
&& memb->expr_type == ASN_BASIC_INTEGER))
|
|
|
|
&& expr_elements_count(arg, memb))) {
|
2004-08-22 03:25:24 +00:00
|
|
|
arg_t tmp;
|
|
|
|
asn1p_expr_t tmp_memb;
|
|
|
|
arg->embed++;
|
|
|
|
tmp = *arg;
|
|
|
|
tmp.expr = &tmp_memb;
|
|
|
|
tmp_memb = *memb;
|
2005-08-16 17:00:21 +00:00
|
|
|
tmp_memb.marker.flags &= ~EM_INDIRECT;
|
2004-08-22 03:25:24 +00:00
|
|
|
tmp_memb._anonymous_type = 1;
|
2004-09-22 16:06:28 +00:00
|
|
|
if(tmp_memb.Identifier == 0) {
|
2005-03-04 08:48:53 +00:00
|
|
|
tmp_memb.Identifier = "Member";
|
|
|
|
if(0)
|
2004-09-22 16:06:28 +00:00
|
|
|
tmp_memb.Identifier = strdup(
|
|
|
|
asn1c_make_identifier(0,
|
2006-03-21 03:40:38 +00:00
|
|
|
expr, "Member", 0));
|
2004-09-22 16:06:28 +00:00
|
|
|
assert(tmp_memb.Identifier);
|
|
|
|
}
|
2004-08-22 03:25:24 +00:00
|
|
|
tmp.default_cb(&tmp);
|
2004-09-22 16:06:28 +00:00
|
|
|
if(tmp_memb.Identifier != memb->Identifier)
|
2005-03-04 08:48:53 +00:00
|
|
|
if(0) free(tmp_memb.Identifier);
|
2004-08-22 03:25:24 +00:00
|
|
|
arg->embed--;
|
2016-06-05 16:23:16 +00:00
|
|
|
assert(arg->target->target == OT_TYPE_DECLS ||
|
|
|
|
arg->target->target == OT_FWD_DEFS);
|
2004-08-22 03:25:24 +00:00
|
|
|
} else {
|
2005-03-04 22:38:22 +00:00
|
|
|
OUT("%s", asn1c_type_name(arg, memb,
|
|
|
|
(memb->marker.flags & EM_UNRECURSE)
|
|
|
|
? TNF_RSAFE : TNF_CTYPE));
|
2004-06-03 03:38:44 +00:00
|
|
|
}
|
2005-08-16 17:00:21 +00:00
|
|
|
/* README README (above) */
|
|
|
|
if(0 && (memb->marker.flags & EM_INDIRECT))
|
|
|
|
OUT(" *");
|
2004-08-22 03:25:24 +00:00
|
|
|
OUT(") list;\n");
|
|
|
|
INDENT(-1);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
PCTX_DEF;
|
2016-06-05 16:23:16 +00:00
|
|
|
|
|
|
|
if (arg->embed && expr->_anonymous_type) {
|
|
|
|
OUT("} %s", (expr->marker.flags & EM_INDIRECT)?"*":"");
|
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
|
|
|
OUT("%s;\n", arg->embed ? "" : "_t");
|
|
|
|
|
|
|
|
REDIR(saved_target);
|
|
|
|
|
|
|
|
OUT("%s", (expr->marker.flags & EM_INDIRECT)?"*":"");
|
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
|
|
|
} else {
|
|
|
|
OUT("} %s%s%s", (expr->marker.flags & EM_INDIRECT)?"*":"",
|
|
|
|
expr->_anonymous_type ? "" : MKID_safe(expr),
|
|
|
|
arg->embed ? "" : "_t");
|
|
|
|
}
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
/*
|
2004-08-22 03:25:24 +00:00
|
|
|
* SET OF/SEQUENCE OF definition
|
2004-06-03 03:38:44 +00:00
|
|
|
*/
|
2004-08-22 03:25:24 +00:00
|
|
|
return asn1c_lang_C_type_SEx_OF_def(arg,
|
|
|
|
(arg->expr->expr_type == ASN_CONSTR_SEQUENCE_OF));
|
2004-06-03 03:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
asn1c_lang_C_type_SEx_OF_def(arg_t *arg, int seq_of) {
|
|
|
|
asn1p_expr_t *expr = arg->expr;
|
|
|
|
asn1p_expr_t *v;
|
2004-08-11 07:17:22 +00:00
|
|
|
int tags_count;
|
2004-09-13 08:31:01 +00:00
|
|
|
int all_tags_count;
|
|
|
|
enum tvm_compat tv_mode;
|
2016-06-05 16:23:16 +00:00
|
|
|
int saved_target = arg->target->target;
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2004-08-11 05:21:32 +00:00
|
|
|
/*
|
2005-11-26 11:25:14 +00:00
|
|
|
* Print out the table according to which parsing is performed.
|
2004-08-11 05:21:32 +00:00
|
|
|
*/
|
2004-06-03 03:38:44 +00:00
|
|
|
if(seq_of) {
|
2006-09-13 02:51:20 +00:00
|
|
|
GEN_INCLUDE_STD("constr_SEQUENCE_OF");
|
2004-06-03 03:38:44 +00:00
|
|
|
} else {
|
2006-09-13 02:51:20 +00:00
|
|
|
GEN_INCLUDE_STD("constr_SET_OF");
|
2004-06-03 03:38:44 +00:00
|
|
|
}
|
2004-08-11 05:21:32 +00:00
|
|
|
if(!arg->embed)
|
2016-05-16 05:50:09 +00:00
|
|
|
GEN_DECLARE("SET_OF", expr); /* asn_DEF_xxx */
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
REDIR(OT_STAT_DEFS);
|
|
|
|
|
|
|
|
/*
|
2005-11-26 11:25:14 +00:00
|
|
|
* Print out the table according to which parsing is performed.
|
2004-06-03 03:38:44 +00:00
|
|
|
*/
|
2016-05-16 05:50:09 +00:00
|
|
|
if(!(expr->_type_referenced)) OUT("static ");
|
|
|
|
OUT("asn_TYPE_member_t asn_MBR_%s_%d[] = {\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr), expr->_type_unique_index);
|
2004-09-22 16:06:28 +00:00
|
|
|
INDENT(+1);
|
2004-06-03 03:38:44 +00:00
|
|
|
v = TQ_FIRST(&(expr->members));
|
2004-09-22 16:06:28 +00:00
|
|
|
if(!v->Identifier) {
|
2005-02-14 20:41:29 +00:00
|
|
|
v->Identifier = strdup("Member");
|
2004-09-22 16:06:28 +00:00
|
|
|
assert(v->Identifier);
|
|
|
|
}
|
|
|
|
v->_anonymous_type = 1;
|
|
|
|
arg->embed++;
|
2004-08-25 02:03:12 +00:00
|
|
|
emit_member_table(arg, v);
|
2004-09-22 16:06:28 +00:00
|
|
|
arg->embed--;
|
2016-11-07 14:19:10 +00:00
|
|
|
free(v->Identifier);
|
|
|
|
v->Identifier = (char *)NULL;
|
2004-09-22 16:06:28 +00:00
|
|
|
INDENT(-1);
|
2004-06-03 03:38:44 +00:00
|
|
|
OUT("};\n");
|
|
|
|
|
2004-06-28 21:13:46 +00:00
|
|
|
/*
|
2004-09-29 13:16:40 +00:00
|
|
|
* Print out asn_DEF_<type>_[all_]tags[] vectors.
|
2004-06-28 21:13:46 +00:00
|
|
|
*/
|
2004-09-13 08:31:01 +00:00
|
|
|
tv_mode = emit_tags_vectors(arg, expr, &tags_count, &all_tags_count);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2016-05-16 05:50:09 +00:00
|
|
|
if(!(expr->_type_referenced)) OUT("static ");
|
|
|
|
OUT("asn_SET_OF_specifics_t asn_SPC_%s_specs_%d = {\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr), expr->_type_unique_index);
|
2004-06-03 03:38:44 +00:00
|
|
|
INDENTED(
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("sizeof(struct ");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("),\n");
|
|
|
|
OUT("offsetof(struct ");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT(", _asn_ctx),\n");
|
2005-11-08 03:06:16 +00:00
|
|
|
{
|
|
|
|
int as_xvl = expr_as_xmlvaluelist(arg, v);
|
|
|
|
OUT("%d,\t/* XER encoding is %s */\n",
|
|
|
|
as_xvl,
|
|
|
|
as_xvl ? "XMLValueList" : "XMLDelimitedItemList");
|
|
|
|
}
|
2004-06-03 03:38:44 +00:00
|
|
|
);
|
|
|
|
OUT("};\n");
|
2004-08-25 02:03:12 +00:00
|
|
|
|
|
|
|
/*
|
2004-09-29 13:16:40 +00:00
|
|
|
* Emit asn_DEF_xxx table.
|
2004-08-25 02:03:12 +00:00
|
|
|
*/
|
2004-09-13 08:31:01 +00:00
|
|
|
emit_type_DEF(arg, expr, tv_mode, tags_count, all_tags_count, 1,
|
2004-09-26 13:11:31 +00:00
|
|
|
ETD_HAS_SPECIFICS);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2016-06-05 16:23:16 +00:00
|
|
|
REDIR(saved_target);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
return 0;
|
2005-01-17 11:57:48 +00:00
|
|
|
} /* _SEx_OF_def() */
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
asn1c_lang_C_type_CHOICE(arg_t *arg) {
|
|
|
|
asn1p_expr_t *expr = arg->expr;
|
|
|
|
asn1p_expr_t *v;
|
2004-08-22 03:25:24 +00:00
|
|
|
char *id;
|
2016-06-05 16:23:16 +00:00
|
|
|
int saved_target = arg->target->target;
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
DEPENDENCIES;
|
|
|
|
|
2004-08-11 05:21:32 +00:00
|
|
|
REDIR(OT_DEPS);
|
|
|
|
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("typedef enum ");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_noflags);
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("_PR {\n");
|
2004-08-11 05:21:32 +00:00
|
|
|
INDENTED(
|
2006-08-18 01:38:40 +00:00
|
|
|
int skipComma = 1;
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_noflags);
|
2005-01-28 12:18:50 +00:00
|
|
|
OUT("_PR_NOTHING,\t/* No components present */\n");
|
2004-08-11 05:21:32 +00:00
|
|
|
TQ_FOR(v, &(expr->members), next) {
|
2006-08-18 01:38:40 +00:00
|
|
|
if(skipComma) skipComma = 0;
|
2017-04-11 08:42:21 +00:00
|
|
|
else if (v->expr_type == A1TC_EXTENSIBLE && !TQ_NEXT(v, next)) OUT("\n");
|
2006-08-18 01:32:26 +00:00
|
|
|
else OUT(",\n");
|
2004-08-11 05:21:32 +00:00
|
|
|
if(v->expr_type == A1TC_EXTENSIBLE) {
|
|
|
|
OUT("/* Extensions may appear below */\n");
|
2006-08-18 01:38:40 +00:00
|
|
|
skipComma = 1;
|
2004-08-11 05:21:32 +00:00
|
|
|
continue;
|
|
|
|
}
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_noflags);
|
2006-03-21 03:40:38 +00:00
|
|
|
id = MKID(v);
|
2006-08-18 01:32:26 +00:00
|
|
|
OUT("_PR_%s", id);
|
2004-08-11 05:21:32 +00:00
|
|
|
}
|
2006-08-18 01:32:26 +00:00
|
|
|
OUT("\n");
|
2004-08-11 05:21:32 +00:00
|
|
|
);
|
2005-08-14 15:03:31 +00:00
|
|
|
OUT("} "); out_name_chain(arg, ONC_noflags); OUT("_PR;\n");
|
2004-08-11 05:21:32 +00:00
|
|
|
|
2016-06-05 16:23:16 +00:00
|
|
|
REDIR(saved_target);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
if(arg->embed) {
|
2016-06-05 16:23:16 +00:00
|
|
|
if (expr->_anonymous_type) {
|
|
|
|
REDIR(OT_FWD_DEFS);
|
|
|
|
OUT("typedef ");
|
|
|
|
}
|
2005-08-14 15:03:31 +00:00
|
|
|
OUT("struct "); out_name_chain(arg, ONC_avoid_keywords); OUT(" {\n");
|
2004-06-03 03:38:44 +00:00
|
|
|
} else {
|
2016-06-05 16:23:16 +00:00
|
|
|
REDIR(OT_TYPE_DECLS);
|
2006-03-21 03:40:38 +00:00
|
|
|
OUT("typedef struct %s {\n", MKID_safe(expr));
|
2004-06-03 03:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
INDENTED(
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_noflags);
|
2005-01-28 12:18:50 +00:00
|
|
|
OUT("_PR present;\n");
|
2005-08-14 15:03:31 +00:00
|
|
|
OUT("union ");
|
|
|
|
if(UNNAMED_UNIONS == 0) {
|
|
|
|
out_name_chain(arg, ONC_force_compound_name);
|
|
|
|
OUT("_u ");
|
|
|
|
}
|
|
|
|
OUT("{\n");
|
2004-06-03 03:38:44 +00:00
|
|
|
TQ_FOR(v, &(expr->members), next) {
|
|
|
|
EMBED(v);
|
|
|
|
}
|
|
|
|
if(UNNAMED_UNIONS) OUT("};\n");
|
|
|
|
else OUT("} choice;\n");
|
|
|
|
);
|
|
|
|
|
|
|
|
PCTX_DEF;
|
2016-06-05 16:23:16 +00:00
|
|
|
|
|
|
|
if (arg->embed && expr->_anonymous_type) {
|
|
|
|
OUT("} %s", (expr->marker.flags & EM_INDIRECT)?"*":"");
|
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
|
|
|
OUT("%s;\n", arg->embed ? "" : "_t");
|
|
|
|
|
|
|
|
REDIR(saved_target);
|
|
|
|
|
|
|
|
OUT("%s", (expr->marker.flags & EM_INDIRECT)?"*":"");
|
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
|
|
|
} else {
|
|
|
|
OUT("} %s%s%s", (expr->marker.flags & EM_INDIRECT)?"*":"",
|
|
|
|
expr->_anonymous_type ? "" :
|
|
|
|
arg->embed
|
|
|
|
? MKID_safe(expr)
|
|
|
|
: MKID(expr),
|
|
|
|
arg->embed ? "" : "_t");
|
|
|
|
}
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
return asn1c_lang_C_type_CHOICE_def(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
asn1c_lang_C_type_CHOICE_def(arg_t *arg) {
|
|
|
|
asn1p_expr_t *expr = arg->expr;
|
|
|
|
asn1p_expr_t *v;
|
|
|
|
int elements; /* Number of elements */
|
|
|
|
tag2el_t *tag2el = NULL;
|
|
|
|
int tag2el_count = 0;
|
2004-08-11 07:17:22 +00:00
|
|
|
int tags_count;
|
2004-09-13 08:31:01 +00:00
|
|
|
int all_tags_count;
|
|
|
|
enum tvm_compat tv_mode;
|
2005-11-26 11:25:14 +00:00
|
|
|
int *cmap = 0;
|
2016-06-05 16:23:16 +00:00
|
|
|
int saved_target = arg->target->target;
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fetch every inner tag from the tag to elements map.
|
|
|
|
*/
|
2004-10-03 09:13:30 +00:00
|
|
|
if(_fill_tag2el_map(arg, &tag2el, &tag2el_count, -1, FTE_ALLTAGS)) {
|
2004-06-03 03:38:44 +00:00
|
|
|
if(tag2el) free(tag2el);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-09-13 02:51:20 +00:00
|
|
|
GEN_INCLUDE_STD("constr_CHOICE");
|
2004-08-11 05:21:32 +00:00
|
|
|
if(!arg->embed)
|
2016-05-16 05:50:09 +00:00
|
|
|
GEN_DECLARE("CHOICE", expr); /* asn_DEF_xxx */
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2004-08-11 05:21:32 +00:00
|
|
|
REDIR(OT_STAT_DEFS);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
/*
|
2005-11-26 11:25:14 +00:00
|
|
|
* Print out the table according to which parsing is performed.
|
2004-06-03 03:38:44 +00:00
|
|
|
*/
|
2004-09-22 16:06:28 +00:00
|
|
|
if(expr_elements_count(arg, expr)) {
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2016-05-16 05:50:09 +00:00
|
|
|
if(!(expr->_type_referenced)) OUT("static ");
|
|
|
|
OUT("asn_TYPE_member_t asn_MBR_%s_%d[] = {\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr), expr->_type_unique_index);
|
2004-09-22 16:06:28 +00:00
|
|
|
|
|
|
|
elements = 0;
|
|
|
|
INDENTED(TQ_FOR(v, &(expr->members), next) {
|
2005-01-17 11:40:49 +00:00
|
|
|
if(v->expr_type == A1TC_EXTENSIBLE)
|
|
|
|
continue;
|
|
|
|
emit_member_table(arg, v);
|
2005-08-16 17:00:21 +00:00
|
|
|
elements++;
|
2004-09-22 16:06:28 +00:00
|
|
|
});
|
|
|
|
OUT("};\n");
|
|
|
|
} else {
|
|
|
|
elements = 0;
|
|
|
|
}
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2005-11-26 11:25:14 +00:00
|
|
|
/* Create a canonical elements map */
|
|
|
|
if(elements && (arg->flags & A1C_GEN_PER)) {
|
|
|
|
int i;
|
|
|
|
cmap = compute_canonical_members_order(arg, elements);
|
|
|
|
if(cmap) {
|
2014-07-28 19:16:01 +00:00
|
|
|
OUT("static const int asn_MAP_%s_cmap_%d[] = {",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr),
|
2005-11-26 11:25:14 +00:00
|
|
|
expr->_type_unique_index);
|
|
|
|
for(i = 0; i < elements; i++) {
|
|
|
|
if(i) OUT(",");
|
|
|
|
OUT(" %d", cmap[i]);
|
|
|
|
}
|
|
|
|
OUT(" };\n");
|
|
|
|
free(cmap);
|
|
|
|
}
|
|
|
|
}
|
2004-08-11 07:17:22 +00:00
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
if(arg->embed) {
|
|
|
|
/*
|
|
|
|
* Our parent structure has already taken this into account.
|
|
|
|
*/
|
2004-09-13 08:31:01 +00:00
|
|
|
tv_mode = _TVM_SAME;
|
|
|
|
tags_count = all_tags_count = 0;
|
2004-06-03 03:38:44 +00:00
|
|
|
} else {
|
2004-09-13 08:31:01 +00:00
|
|
|
tv_mode = emit_tags_vectors(arg, expr,
|
|
|
|
&tags_count, &all_tags_count);
|
2004-06-03 03:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tags to elements map.
|
|
|
|
*/
|
2004-10-03 09:13:30 +00:00
|
|
|
emit_tag2member_map(arg, tag2el, tag2el_count, 0);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2016-05-16 05:50:09 +00:00
|
|
|
if(!(expr->_type_referenced)) OUT("static ");
|
|
|
|
OUT("asn_CHOICE_specifics_t asn_SPC_%s_specs_%d = {\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr), expr->_type_unique_index);
|
2004-06-03 03:38:44 +00:00
|
|
|
INDENTED(
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("sizeof(struct ");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("),\n");
|
|
|
|
OUT("offsetof(struct ");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT(", _asn_ctx),\n");
|
|
|
|
OUT("offsetof(struct ");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT(", present),\n");
|
|
|
|
OUT("sizeof(((struct ");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT(" *)0)->present),\n");
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("asn_MAP_%s_tag2el_%d,\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr), expr->_type_unique_index);
|
2004-06-03 03:38:44 +00:00
|
|
|
OUT("%d,\t/* Count of tags in the map */\n", tag2el_count);
|
2005-11-26 11:25:14 +00:00
|
|
|
if(C99_MODE) OUT(".canonical_order = ");
|
|
|
|
if(cmap) OUT("asn_MAP_%s_cmap_%d,\t/* Canonically sorted */\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr), expr->_type_unique_index);
|
2005-11-26 11:25:14 +00:00
|
|
|
else OUT("0,\n");
|
|
|
|
if(C99_MODE) OUT(".ext_start = ");
|
|
|
|
OUT("%d\t/* Extensions start */\n",
|
|
|
|
compute_extensions_start(expr));
|
2004-06-03 03:38:44 +00:00
|
|
|
);
|
|
|
|
OUT("};\n");
|
2004-08-25 02:03:12 +00:00
|
|
|
|
|
|
|
/*
|
2004-09-29 13:16:40 +00:00
|
|
|
* Emit asn_DEF_xxx table.
|
2004-08-25 02:03:12 +00:00
|
|
|
*/
|
2004-09-13 08:31:01 +00:00
|
|
|
emit_type_DEF(arg, expr, tv_mode, tags_count, all_tags_count, elements,
|
2004-09-26 13:11:31 +00:00
|
|
|
ETD_HAS_SPECIFICS);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2016-06-05 16:23:16 +00:00
|
|
|
REDIR(saved_target);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2016-11-04 03:59:45 +00:00
|
|
|
if (tag2el) free(tag2el);
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
return 0;
|
2005-01-17 11:57:48 +00:00
|
|
|
} /* _CHOICE_def() */
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
asn1c_lang_C_type_REFERENCE(arg_t *arg) {
|
|
|
|
asn1p_ref_t *ref;
|
|
|
|
|
|
|
|
ref = arg->expr->reference;
|
|
|
|
if(ref->components[ref->comp_count-1].name[0] == '&') {
|
|
|
|
asn1p_expr_t *extract;
|
|
|
|
arg_t tmp;
|
|
|
|
int ret;
|
|
|
|
|
2004-09-22 16:06:28 +00:00
|
|
|
extract = asn1f_class_access_ex(arg->asn, arg->expr->module,
|
2006-03-21 03:40:38 +00:00
|
|
|
arg->expr, arg->expr->rhs_pspecs, ref);
|
2004-06-03 03:38:44 +00:00
|
|
|
if(extract == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2004-08-22 03:25:24 +00:00
|
|
|
extract = asn1p_expr_clone(extract, 0);
|
2004-06-03 03:38:44 +00:00
|
|
|
if(extract) {
|
2016-03-14 09:00:27 +00:00
|
|
|
free(extract->Identifier);
|
2004-06-03 03:38:44 +00:00
|
|
|
extract->Identifier = strdup(arg->expr->Identifier);
|
|
|
|
if(extract->Identifier == NULL) {
|
|
|
|
asn1p_expr_free(extract);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = *arg;
|
|
|
|
tmp.asn = arg->asn;
|
|
|
|
tmp.expr = extract;
|
|
|
|
|
|
|
|
ret = arg->default_cb(&tmp);
|
|
|
|
|
|
|
|
asn1p_expr_free(extract);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return asn1c_lang_C_type_SIMPLE_TYPE(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
asn1c_lang_C_type_SIMPLE_TYPE(arg_t *arg) {
|
|
|
|
asn1p_expr_t *expr = arg->expr;
|
2004-08-11 07:17:22 +00:00
|
|
|
int tags_count;
|
2004-09-13 08:31:01 +00:00
|
|
|
int all_tags_count;
|
|
|
|
enum tvm_compat tv_mode;
|
2005-02-25 12:10:27 +00:00
|
|
|
enum etd_spec etd_spec;
|
2004-06-03 03:38:44 +00:00
|
|
|
char *p;
|
2016-06-05 16:23:16 +00:00
|
|
|
int saved_target = arg->target->target;
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
if(arg->embed) {
|
2004-09-29 13:16:40 +00:00
|
|
|
enum tnfmt tnfmt = TNF_CTYPE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is an optional compound type,
|
|
|
|
* refer it using "struct X" convention,
|
|
|
|
* as it may recursively include the current structure.
|
|
|
|
*/
|
2005-03-04 22:18:20 +00:00
|
|
|
if(expr->marker.flags & (EM_INDIRECT | EM_UNRECURSE)) {
|
2005-08-18 13:38:19 +00:00
|
|
|
if(terminal_structable(arg, expr)) {
|
2005-03-04 22:18:20 +00:00
|
|
|
tnfmt = TNF_RSAFE;
|
2016-06-05 16:23:16 +00:00
|
|
|
if(saved_target != OT_FWD_DECLS) {
|
|
|
|
REDIR(OT_FWD_DECLS);
|
|
|
|
OUT("%s;\n",
|
|
|
|
asn1c_type_name(arg, arg->expr, tnfmt));
|
|
|
|
}
|
|
|
|
REDIR(saved_target);
|
2004-09-29 13:16:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2005-03-04 22:18:20 +00:00
|
|
|
OUT("%s", asn1c_type_name(arg, arg->expr, tnfmt));
|
2005-02-25 12:10:27 +00:00
|
|
|
if(!expr->_anonymous_type) {
|
2005-03-04 22:18:20 +00:00
|
|
|
OUT("%s", (expr->marker.flags&EM_INDIRECT)?"\t*":"\t ");
|
2006-03-21 03:40:38 +00:00
|
|
|
OUT("%s", MKID_safe(expr));
|
2005-11-26 11:25:14 +00:00
|
|
|
if((expr->marker.flags & (EM_DEFAULT & ~EM_INDIRECT))
|
|
|
|
== (EM_DEFAULT & ~EM_INDIRECT))
|
2005-02-25 12:10:27 +00:00
|
|
|
OUT("\t/* DEFAULT %s */",
|
|
|
|
asn1f_printable_value(
|
|
|
|
expr->marker.default_value));
|
2005-11-26 11:25:14 +00:00
|
|
|
else if((expr->marker.flags & EM_OPTIONAL)
|
|
|
|
== EM_OPTIONAL)
|
2005-02-25 12:10:27 +00:00
|
|
|
OUT("\t/* OPTIONAL */");
|
|
|
|
}
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2005-02-25 12:10:27 +00:00
|
|
|
} else {
|
|
|
|
GEN_INCLUDE(asn1c_type_name(arg, expr, TNF_INCLUDE));
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2005-02-25 12:10:27 +00:00
|
|
|
REDIR(OT_TYPE_DECLS);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2005-02-25 12:10:27 +00:00
|
|
|
OUT("typedef %s\t",
|
2005-03-04 22:18:20 +00:00
|
|
|
asn1c_type_name(arg, arg->expr, TNF_CTYPE));
|
2005-02-25 12:10:27 +00:00
|
|
|
OUT("%s%s_t",
|
2005-03-04 22:18:20 +00:00
|
|
|
(expr->marker.flags & EM_INDIRECT)?"*":" ",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr));
|
2005-02-25 12:10:27 +00:00
|
|
|
}
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2005-02-25 12:10:27 +00:00
|
|
|
if((expr->expr_type == ASN_BASIC_ENUMERATED)
|
2005-03-03 21:28:12 +00:00
|
|
|
|| (0 /* -- prohibited by X.693:8.3.4 */
|
|
|
|
&& expr->expr_type == ASN_BASIC_INTEGER
|
2007-12-03 13:41:36 +00:00
|
|
|
&& expr_elements_count(arg, expr))
|
|
|
|
|| (expr->expr_type == ASN_BASIC_INTEGER
|
|
|
|
&& asn1c_type_fits_long(arg, expr) == FL_FITS_UNSIGN)
|
|
|
|
)
|
2005-02-25 12:10:27 +00:00
|
|
|
etd_spec = ETD_HAS_SPECIFICS;
|
|
|
|
else
|
|
|
|
etd_spec = ETD_NO_SPECIFICS;
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2004-09-26 13:11:31 +00:00
|
|
|
/*
|
|
|
|
* If this type just blindly refers the other type, alias it.
|
|
|
|
* Type1 ::= Type2
|
|
|
|
*/
|
2005-02-25 12:10:27 +00:00
|
|
|
if(arg->embed && etd_spec == ETD_NO_SPECIFICS) {
|
2016-06-05 16:23:16 +00:00
|
|
|
REDIR(saved_target);
|
2005-02-25 12:10:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-09-26 13:11:31 +00:00
|
|
|
if((!expr->constraints || (arg->flags & A1C_NO_CONSTRAINTS))
|
2005-02-25 12:10:27 +00:00
|
|
|
&& (arg->embed || expr->tag.tag_class == TC_NOCLASS)
|
2005-03-04 23:23:50 +00:00
|
|
|
&& etd_spec == ETD_NO_SPECIFICS
|
|
|
|
&& 0 /* This shortcut is incompatible with XER */
|
|
|
|
) {
|
2004-09-26 13:11:31 +00:00
|
|
|
char *type_name;
|
|
|
|
REDIR(OT_FUNC_DECLS);
|
|
|
|
type_name = asn1c_type_name(arg, expr, TNF_SAFE);
|
|
|
|
OUT("/* This type is equivalent to %s */\n", type_name);
|
|
|
|
if(HIDE_INNER_DEFS) OUT("/* ");
|
2006-03-21 03:40:38 +00:00
|
|
|
OUT("#define\tasn_DEF_%s\t", MKID(expr));
|
2004-09-26 13:11:31 +00:00
|
|
|
type_name = asn1c_type_name(arg, expr, TNF_SAFE);
|
2005-02-25 12:10:27 +00:00
|
|
|
OUT("asn_DEF_%s", type_name);
|
2004-09-26 13:11:31 +00:00
|
|
|
if(HIDE_INNER_DEFS)
|
2005-02-25 12:10:27 +00:00
|
|
|
OUT("\t// (Use -fall-defs-global to expose) */");
|
|
|
|
OUT("\n");
|
2004-09-26 13:11:31 +00:00
|
|
|
REDIR(OT_CODE);
|
|
|
|
OUT("/* This type is equivalent to %s */\n", type_name);
|
|
|
|
OUT("\n");
|
2016-06-05 16:23:16 +00:00
|
|
|
REDIR(saved_target);
|
2004-09-26 13:11:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-08-20 13:37:01 +00:00
|
|
|
REDIR(OT_CODE);
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
/*
|
|
|
|
* Constraint checking.
|
|
|
|
*/
|
2016-05-16 05:50:09 +00:00
|
|
|
if(!(arg->flags & A1C_NO_CONSTRAINTS) && expr->combined_constraints) {
|
2006-03-21 03:40:38 +00:00
|
|
|
p = MKID(expr);
|
2005-02-25 12:10:27 +00:00
|
|
|
if(HIDE_INNER_DEFS) OUT("static ");
|
2004-09-26 13:11:31 +00:00
|
|
|
OUT("int\n");
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("%s", p);
|
|
|
|
if(HIDE_INNER_DEFS) OUT("_%d", expr->_type_unique_index);
|
|
|
|
OUT("_constraint(asn_TYPE_descriptor_t *td, const void *sptr,\n");
|
2004-09-26 13:11:31 +00:00
|
|
|
INDENT(+1);
|
2006-07-13 11:19:01 +00:00
|
|
|
OUT("\t\tasn_app_constraint_failed_f *ctfailcb, void *app_key) {");
|
2004-09-26 13:11:31 +00:00
|
|
|
OUT("\n");
|
2006-10-09 12:07:58 +00:00
|
|
|
DEBUG("expr constraint checking code for %s", p);
|
2004-09-26 13:11:31 +00:00
|
|
|
if(asn1c_emit_constraint_checking_code(arg) == 1) {
|
|
|
|
OUT("/* Replace with underlying type checker */\n");
|
|
|
|
OUT("td->check_constraints "
|
2004-09-29 13:16:40 +00:00
|
|
|
"= asn_DEF_%s.check_constraints;\n",
|
2004-09-26 13:11:31 +00:00
|
|
|
asn1c_type_name(arg, expr, TNF_SAFE));
|
|
|
|
OUT("return td->check_constraints"
|
2006-07-13 11:19:01 +00:00
|
|
|
"(td, sptr, ctfailcb, app_key);\n");
|
2004-08-19 13:29:46 +00:00
|
|
|
}
|
2004-09-26 13:11:31 +00:00
|
|
|
INDENT(-1);
|
|
|
|
OUT("}\n");
|
|
|
|
OUT("\n");
|
2004-06-03 03:38:44 +00:00
|
|
|
}
|
|
|
|
|
2006-10-09 12:07:58 +00:00
|
|
|
REDIR(OT_STAT_DEFS);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out asn_DEF_<type>_[all_]tags[] vectors.
|
|
|
|
*/
|
|
|
|
tv_mode = emit_tags_vectors(arg, expr, &tags_count, &all_tags_count);
|
|
|
|
DEBUG("emit tag vectors for %s %d, %d, %d", expr->Identifier,
|
|
|
|
tv_mode, tags_count, all_tags_count);
|
|
|
|
|
|
|
|
emit_type_DEF(arg, expr, tv_mode, tags_count, all_tags_count,
|
|
|
|
0, etd_spec);
|
|
|
|
|
|
|
|
REDIR(OT_CODE);
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
/*
|
|
|
|
* Emit suicidal functions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function replaces certain fields from the definition
|
|
|
|
* of a type with the corresponding fields from the basic type
|
|
|
|
* (from which the current type is inherited).
|
|
|
|
*/
|
|
|
|
OUT("/*\n");
|
2004-08-20 13:37:01 +00:00
|
|
|
OUT(" * This type is implemented using %s,\n",
|
|
|
|
asn1c_type_name(arg, expr, TNF_SAFE));
|
2004-09-23 22:20:47 +00:00
|
|
|
OUT(" * so here we adjust the DEF accordingly.\n");
|
2004-06-03 03:38:44 +00:00
|
|
|
OUT(" */\n");
|
2016-05-16 05:50:09 +00:00
|
|
|
|
|
|
|
#if 0 /* remove unnecessary functions */
|
2004-06-03 03:38:44 +00:00
|
|
|
OUT("static void\n");
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("%s_%d_inherit_TYPE_descriptor(asn_TYPE_descriptor_t *td) {\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr), expr->_type_unique_index);
|
2004-06-03 03:38:44 +00:00
|
|
|
INDENT(+1);
|
2005-02-25 12:10:27 +00:00
|
|
|
{
|
2004-09-22 16:06:28 +00:00
|
|
|
asn1p_expr_t *terminal = asn1f_find_terminal_type_ex(arg->asn, expr);
|
2004-08-20 13:37:01 +00:00
|
|
|
char *type_name = asn1c_type_name(arg, expr, TNF_SAFE);
|
2004-09-29 13:16:40 +00:00
|
|
|
OUT("td->free_struct = asn_DEF_%s.free_struct;\n", type_name);
|
|
|
|
OUT("td->print_struct = asn_DEF_%s.print_struct;\n", type_name);
|
2013-12-07 19:02:44 +00:00
|
|
|
OUT("td->check_constraints = asn_DEF_%s.check_constraints;\n", type_name);
|
2004-09-29 13:16:40 +00:00
|
|
|
OUT("td->ber_decoder = asn_DEF_%s.ber_decoder;\n", type_name);
|
|
|
|
OUT("td->der_encoder = asn_DEF_%s.der_encoder;\n", type_name);
|
|
|
|
OUT("td->xer_decoder = asn_DEF_%s.xer_decoder;\n", type_name);
|
|
|
|
OUT("td->xer_encoder = asn_DEF_%s.xer_encoder;\n", type_name);
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("td->uper_decoder = asn_DEF_%s.uper_decoder;\n", type_name);
|
2006-08-18 01:32:26 +00:00
|
|
|
OUT("td->uper_encoder = asn_DEF_%s.uper_encoder;\n", type_name);
|
2017-07-06 14:52:39 +00:00
|
|
|
OUT("td->oer_decoder = asn_DEF_%s.oer_decoder;\n", type_name);
|
|
|
|
OUT("td->oer_encoder = asn_DEF_%s.oer_encoder;\n", type_name);
|
2004-09-10 15:49:15 +00:00
|
|
|
if(!terminal && !tags_count) {
|
2004-09-13 08:31:01 +00:00
|
|
|
OUT("/* The next four lines are here because of -fknown-extern-type */\n");
|
2004-09-29 13:16:40 +00:00
|
|
|
OUT("td->tags = asn_DEF_%s.tags;\n", type_name);
|
|
|
|
OUT("td->tags_count = asn_DEF_%s.tags_count;\n", type_name);
|
|
|
|
OUT("td->all_tags = asn_DEF_%s.all_tags;\n", type_name);
|
|
|
|
OUT("td->all_tags_count = asn_DEF_%s.all_tags_count;\n",type_name);
|
2004-09-10 15:49:15 +00:00
|
|
|
OUT("/* End of these lines */\n");
|
|
|
|
}
|
2017-07-14 10:59:52 +00:00
|
|
|
OUT("if(!td->oer_constraints)\n");
|
|
|
|
OUT("\ttd->oer_constraints = asn_DEF_%s.oer_constraints;\n",
|
|
|
|
type_name);
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("if(!td->per_constraints)\n");
|
|
|
|
OUT("\ttd->per_constraints = asn_DEF_%s.per_constraints;\n",
|
|
|
|
type_name);
|
2004-09-29 13:16:40 +00:00
|
|
|
OUT("td->elements = asn_DEF_%s.elements;\n", type_name);
|
|
|
|
OUT("td->elements_count = asn_DEF_%s.elements_count;\n", type_name);
|
2005-02-25 12:10:27 +00:00
|
|
|
if(etd_spec != ETD_NO_SPECIFICS) {
|
|
|
|
INDENT(-1);
|
2005-03-29 19:04:24 +00:00
|
|
|
OUT(" /* ");
|
2004-08-20 13:37:01 +00:00
|
|
|
}
|
2005-02-25 12:10:27 +00:00
|
|
|
OUT("td->specifics = asn_DEF_%s.specifics;", type_name);
|
|
|
|
if(etd_spec == ETD_NO_SPECIFICS) {
|
|
|
|
INDENT(-1);
|
|
|
|
OUT("\n");
|
|
|
|
} else {
|
|
|
|
OUT("\t// Defined explicitly */\n");
|
|
|
|
}
|
|
|
|
}
|
2004-06-03 03:38:44 +00:00
|
|
|
OUT("}\n");
|
|
|
|
OUT("\n");
|
|
|
|
|
2006-03-21 03:40:38 +00:00
|
|
|
p = MKID(expr);
|
2005-02-25 12:10:27 +00:00
|
|
|
if(HIDE_INNER_DEFS) OUT("static ");
|
2004-09-22 16:06:28 +00:00
|
|
|
OUT("void\n");
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("%s", p);
|
|
|
|
if(HIDE_INNER_DEFS) OUT("_%d", expr->_type_unique_index);
|
|
|
|
OUT("_free(asn_TYPE_descriptor_t *td,\n");
|
2004-09-22 16:06:28 +00:00
|
|
|
INDENTED(
|
|
|
|
OUT("\tvoid *struct_ptr, int contents_only) {\n");
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("%s_%d_inherit_TYPE_descriptor(td);\n",
|
|
|
|
p, expr->_type_unique_index);
|
2004-09-22 16:06:28 +00:00
|
|
|
OUT("td->free_struct(td, struct_ptr, contents_only);\n");
|
|
|
|
);
|
|
|
|
OUT("}\n");
|
|
|
|
OUT("\n");
|
|
|
|
|
2006-03-21 03:40:38 +00:00
|
|
|
p = MKID(expr);
|
2005-02-25 12:10:27 +00:00
|
|
|
if(HIDE_INNER_DEFS) OUT("static ");
|
2004-09-22 16:06:28 +00:00
|
|
|
OUT("int\n");
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("%s", p);
|
|
|
|
if(HIDE_INNER_DEFS) OUT("_%d", expr->_type_unique_index);
|
|
|
|
OUT("_print(asn_TYPE_descriptor_t *td, const void *struct_ptr,\n");
|
2004-09-22 16:06:28 +00:00
|
|
|
INDENTED(
|
|
|
|
OUT("\tint ilevel, asn_app_consume_bytes_f *cb, void *app_key) {\n");
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("%s_%d_inherit_TYPE_descriptor(td);\n",
|
|
|
|
p, expr->_type_unique_index);
|
2004-09-22 16:06:28 +00:00
|
|
|
OUT("return td->print_struct(td, struct_ptr, ilevel, cb, app_key);\n");
|
|
|
|
);
|
|
|
|
OUT("}\n");
|
|
|
|
OUT("\n");
|
|
|
|
|
2006-03-21 03:40:38 +00:00
|
|
|
p = MKID(expr);
|
2005-02-25 12:10:27 +00:00
|
|
|
if(HIDE_INNER_DEFS) OUT("static ");
|
2004-10-20 15:50:55 +00:00
|
|
|
OUT("asn_dec_rval_t\n");
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("%s", p);
|
|
|
|
if(HIDE_INNER_DEFS) OUT("_%d", expr->_type_unique_index);
|
|
|
|
OUT("_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,\n");
|
2004-06-03 03:38:44 +00:00
|
|
|
INDENTED(
|
2005-03-17 21:56:00 +00:00
|
|
|
OUT("\tvoid **structure, const void *bufptr, size_t size, int tag_mode) {\n");
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("%s_%d_inherit_TYPE_descriptor(td);\n",
|
|
|
|
p, expr->_type_unique_index);
|
2004-09-29 13:16:40 +00:00
|
|
|
OUT("return td->ber_decoder(opt_codec_ctx, td, structure, bufptr, size, tag_mode);\n");
|
2004-06-03 03:38:44 +00:00
|
|
|
);
|
|
|
|
OUT("}\n");
|
|
|
|
OUT("\n");
|
|
|
|
|
2006-03-21 03:40:38 +00:00
|
|
|
p = MKID(expr);
|
2005-02-25 12:10:27 +00:00
|
|
|
if(HIDE_INNER_DEFS) OUT("static ");
|
2004-09-22 16:06:28 +00:00
|
|
|
OUT("asn_enc_rval_t\n");
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("%s", p);
|
|
|
|
if(HIDE_INNER_DEFS) OUT("_%d", expr->_type_unique_index);
|
|
|
|
OUT("_encode_der(asn_TYPE_descriptor_t *td,\n");
|
2004-06-03 03:38:44 +00:00
|
|
|
INDENTED(
|
|
|
|
OUT("\tvoid *structure, int tag_mode, ber_tlv_tag_t tag,\n");
|
|
|
|
OUT("\tasn_app_consume_bytes_f *cb, void *app_key) {\n");
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("%s_%d_inherit_TYPE_descriptor(td);\n",
|
|
|
|
p, expr->_type_unique_index);
|
2004-06-03 03:38:44 +00:00
|
|
|
OUT("return td->der_encoder(td, structure, tag_mode, tag, cb, app_key);\n");
|
|
|
|
);
|
|
|
|
OUT("}\n");
|
|
|
|
OUT("\n");
|
|
|
|
|
2006-03-21 03:40:38 +00:00
|
|
|
p = MKID(expr);
|
2005-02-25 12:10:27 +00:00
|
|
|
if(HIDE_INNER_DEFS) OUT("static ");
|
2004-10-23 13:34:00 +00:00
|
|
|
OUT("asn_dec_rval_t\n");
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("%s", p);
|
|
|
|
if(HIDE_INNER_DEFS) OUT("_%d", expr->_type_unique_index);
|
|
|
|
OUT("_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,\n");
|
2004-10-23 13:34:00 +00:00
|
|
|
INDENTED(
|
2005-03-17 21:56:00 +00:00
|
|
|
OUT("\tvoid **structure, const char *opt_mname, const void *bufptr, size_t size) {\n");
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("%s_%d_inherit_TYPE_descriptor(td);\n",
|
|
|
|
p, expr->_type_unique_index);
|
2004-10-23 13:34:00 +00:00
|
|
|
OUT("return td->xer_decoder(opt_codec_ctx, td, structure, opt_mname, bufptr, size);\n");
|
|
|
|
);
|
|
|
|
OUT("}\n");
|
|
|
|
OUT("\n");
|
|
|
|
|
2006-03-21 03:40:38 +00:00
|
|
|
p = MKID(expr);
|
2005-02-25 12:10:27 +00:00
|
|
|
if(HIDE_INNER_DEFS) OUT("static ");
|
2004-09-22 16:06:28 +00:00
|
|
|
OUT("asn_enc_rval_t\n");
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("%s", p);
|
|
|
|
if(HIDE_INNER_DEFS) OUT("_%d", expr->_type_unique_index);
|
|
|
|
OUT("_encode_xer(asn_TYPE_descriptor_t *td, void *structure,\n");
|
2004-06-03 03:38:44 +00:00
|
|
|
INDENTED(
|
2004-09-22 16:06:28 +00:00
|
|
|
OUT("\tint ilevel, enum xer_encoder_flags_e flags,\n");
|
|
|
|
OUT("\tasn_app_consume_bytes_f *cb, void *app_key) {\n");
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("%s_%d_inherit_TYPE_descriptor(td);\n",
|
|
|
|
p, expr->_type_unique_index);
|
2004-09-22 16:06:28 +00:00
|
|
|
OUT("return td->xer_encoder(td, structure, ilevel, flags, cb, app_key);\n");
|
2004-06-03 03:38:44 +00:00
|
|
|
);
|
|
|
|
OUT("}\n");
|
|
|
|
OUT("\n");
|
|
|
|
|
2017-07-14 10:59:52 +00:00
|
|
|
if(arg->flags & A1C_GEN_OER) {
|
|
|
|
p = MKID(expr);
|
|
|
|
|
|
|
|
if(HIDE_INNER_DEFS) OUT("static ");
|
|
|
|
OUT("asn_dec_rval_t\n");
|
|
|
|
OUT("%s", p);
|
|
|
|
if(HIDE_INNER_DEFS) OUT("_%d", expr->_type_unique_index);
|
|
|
|
OUT("_decode_oer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,\n");
|
|
|
|
INDENTED(
|
|
|
|
OUT("\tasn_oer_constraints_t *constraints, void **structure, const void *buffer, size_t size) {\n");
|
|
|
|
OUT("%s_%d_inherit_TYPE_descriptor(td);\n",
|
|
|
|
p, expr->_type_unique_index);
|
|
|
|
OUT("return td->oer_decoder(opt_codec_ctx, td, constraints, structure, buffer, size);\n");
|
|
|
|
);
|
|
|
|
OUT("}\n");
|
|
|
|
OUT("\n");
|
|
|
|
|
|
|
|
p = MKID(expr);
|
|
|
|
if(HIDE_INNER_DEFS) OUT("static ");
|
|
|
|
OUT("asn_enc_rval_t\n");
|
|
|
|
OUT("%s", p);
|
|
|
|
if(HIDE_INNER_DEFS) OUT("_%d", expr->_type_unique_index);
|
|
|
|
OUT("_encode_oer(asn_TYPE_descriptor_t *td,\n");
|
|
|
|
INDENTED(
|
|
|
|
OUT("\tasn_oer_constraints_t *constraints,\n");
|
|
|
|
OUT("\tvoid *structure, asn_app_consume_bytes_f *cb, void *app_key) {\n");
|
|
|
|
OUT("%s_%d_inherit_TYPE_descriptor(td);\n",
|
|
|
|
p, expr->_type_unique_index);
|
|
|
|
OUT("return td->uper_encoder(td, constraints, structure, cb, app_key);\n");
|
|
|
|
);
|
|
|
|
OUT("}\n");
|
|
|
|
OUT("\n");
|
|
|
|
}
|
|
|
|
|
2005-11-26 11:25:14 +00:00
|
|
|
if(arg->flags & A1C_GEN_PER) {
|
2006-03-21 03:40:38 +00:00
|
|
|
p = MKID(expr);
|
2006-08-18 01:32:26 +00:00
|
|
|
|
2005-11-26 11:25:14 +00:00
|
|
|
if(HIDE_INNER_DEFS) OUT("static ");
|
|
|
|
OUT("asn_dec_rval_t\n");
|
|
|
|
OUT("%s", p);
|
|
|
|
if(HIDE_INNER_DEFS) OUT("_%d", expr->_type_unique_index);
|
|
|
|
OUT("_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,\n");
|
|
|
|
INDENTED(
|
|
|
|
OUT("\tasn_per_constraints_t *constraints, void **structure, asn_per_data_t *per_data) {\n");
|
|
|
|
OUT("%s_%d_inherit_TYPE_descriptor(td);\n",
|
|
|
|
p, expr->_type_unique_index);
|
|
|
|
OUT("return td->uper_decoder(opt_codec_ctx, td, constraints, structure, per_data);\n");
|
|
|
|
);
|
|
|
|
OUT("}\n");
|
|
|
|
OUT("\n");
|
2006-08-18 01:32:26 +00:00
|
|
|
|
|
|
|
p = MKID(expr);
|
|
|
|
if(HIDE_INNER_DEFS) OUT("static ");
|
|
|
|
OUT("asn_enc_rval_t\n");
|
|
|
|
OUT("%s", p);
|
|
|
|
if(HIDE_INNER_DEFS) OUT("_%d", expr->_type_unique_index);
|
|
|
|
OUT("_encode_uper(asn_TYPE_descriptor_t *td,\n");
|
|
|
|
INDENTED(
|
|
|
|
OUT("\tasn_per_constraints_t *constraints,\n");
|
|
|
|
OUT("\tvoid *structure, asn_per_outp_t *per_out) {\n");
|
|
|
|
OUT("%s_%d_inherit_TYPE_descriptor(td);\n",
|
|
|
|
p, expr->_type_unique_index);
|
|
|
|
OUT("return td->uper_encoder(td, constraints, structure, per_out);\n");
|
|
|
|
);
|
|
|
|
OUT("}\n");
|
|
|
|
OUT("\n");
|
2005-11-26 11:25:14 +00:00
|
|
|
}
|
2016-05-16 05:50:09 +00:00
|
|
|
#endif
|
2004-06-03 03:38:44 +00:00
|
|
|
REDIR(OT_FUNC_DECLS);
|
|
|
|
|
2006-03-21 03:40:38 +00:00
|
|
|
p = MKID(expr);
|
2005-02-25 12:10:27 +00:00
|
|
|
if(HIDE_INNER_DEFS) {
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("/* extern asn_TYPE_descriptor_t asn_DEF_%s_%d;"
|
|
|
|
"\t// (Use -fall-defs-global to expose) */\n",
|
|
|
|
p, expr->_type_unique_index);
|
2005-02-25 12:10:27 +00:00
|
|
|
} else {
|
|
|
|
OUT("extern asn_TYPE_descriptor_t asn_DEF_%s;\n", p);
|
2016-05-16 05:50:09 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2005-02-25 12:10:27 +00:00
|
|
|
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);
|
|
|
|
OUT("ber_type_decoder_f %s_decode_ber;\n", p);
|
|
|
|
OUT("der_type_encoder_f %s_encode_der;\n", p);
|
|
|
|
OUT("xer_type_decoder_f %s_decode_xer;\n", p);
|
|
|
|
OUT("xer_type_encoder_f %s_encode_xer;\n", p);
|
2017-07-14 10:59:52 +00:00
|
|
|
if(arg->flags & A1C_GEN_OER) {
|
|
|
|
OUT("oer_type_decoder_f %s_decode_oer;\n", p);
|
|
|
|
OUT("oer_type_encoder_f %s_encode_oer;\n", p);
|
|
|
|
}
|
2006-08-18 01:32:26 +00:00
|
|
|
if(arg->flags & A1C_GEN_PER) {
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("per_type_decoder_f %s_decode_uper;\n", p);
|
2006-08-18 01:32:26 +00:00
|
|
|
OUT("per_type_encoder_f %s_encode_uper;\n", p);
|
|
|
|
}
|
2005-02-25 12:10:27 +00:00
|
|
|
}
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2016-06-05 16:23:16 +00:00
|
|
|
REDIR(saved_target);
|
2004-08-11 05:21:32 +00:00
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
asn1c_lang_C_type_EXTENSIBLE(arg_t *arg) {
|
|
|
|
|
|
|
|
OUT("/*\n");
|
|
|
|
OUT(" * This type is extensible,\n");
|
|
|
|
OUT(" * possible extensions are below.\n");
|
|
|
|
OUT(" */\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-26 11:25:14 +00:00
|
|
|
static int
|
|
|
|
compute_extensions_start(asn1p_expr_t *expr) {
|
2004-07-01 00:52:50 +00:00
|
|
|
asn1p_expr_t *v;
|
2005-11-26 11:25:14 +00:00
|
|
|
int eidx = 0;
|
2004-07-01 00:52:50 +00:00
|
|
|
TQ_FOR(v, &(expr->members), next) {
|
2005-11-26 11:25:14 +00:00
|
|
|
if(v->expr_type == A1TC_EXTENSIBLE)
|
|
|
|
return eidx;
|
|
|
|
eidx++;
|
2004-07-01 00:52:50 +00:00
|
|
|
}
|
2005-11-26 11:25:14 +00:00
|
|
|
return -1;
|
2004-07-01 00:52:50 +00:00
|
|
|
}
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
static int
|
2004-09-10 06:07:18 +00:00
|
|
|
_print_tag(arg_t *arg, struct asn1p_type_tag_s *tag) {
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
OUT("(");
|
2004-09-10 06:07:18 +00:00
|
|
|
switch(tag->tag_class) {
|
2004-06-03 03:38:44 +00:00
|
|
|
case TC_UNIVERSAL: OUT("ASN_TAG_CLASS_UNIVERSAL"); break;
|
|
|
|
case TC_APPLICATION: OUT("ASN_TAG_CLASS_APPLICATION"); break;
|
|
|
|
case TC_CONTEXT_SPECIFIC: OUT("ASN_TAG_CLASS_CONTEXT"); break;
|
|
|
|
case TC_PRIVATE: OUT("ASN_TAG_CLASS_PRIVATE"); break;
|
|
|
|
case TC_NOCLASS:
|
|
|
|
break;
|
|
|
|
}
|
2017-08-04 08:38:41 +00:00
|
|
|
OUT(" | (%s << 2))", asn1p_itoa(tag->tag_value));
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-06-06 07:20:17 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
_tag2el_cmp(const void *ap, const void *bp) {
|
|
|
|
const tag2el_t *a = ap;
|
|
|
|
const tag2el_t *b = bp;
|
|
|
|
const struct asn1p_type_tag_s *ta = &a->el_tag;
|
|
|
|
const struct asn1p_type_tag_s *tb = &b->el_tag;
|
|
|
|
|
|
|
|
if(ta->tag_class == tb->tag_class) {
|
|
|
|
if(ta->tag_value == tb->tag_value) {
|
|
|
|
/*
|
|
|
|
* Sort by their respective positions.
|
|
|
|
*/
|
|
|
|
if(a->el_no < b->el_no)
|
|
|
|
return -1;
|
|
|
|
else if(a->el_no > b->el_no)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
} else if(ta->tag_value < tb->tag_value)
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
} else if(ta->tag_class < tb->tag_class) {
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
/*
|
|
|
|
* For constructed types, number of external tags may be greater than
|
|
|
|
* number of elements in the type because of CHOICE type.
|
|
|
|
* T ::= SET { -- Three possible tags:
|
|
|
|
* a INTEGER, -- One tag is here...
|
|
|
|
* b Choice1 -- ... and two more tags are there.
|
|
|
|
* }
|
|
|
|
* Choice1 ::= CHOICE {
|
|
|
|
* s1 IA5String,
|
|
|
|
* s2 ObjectDescriptor
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
static int
|
2004-10-03 09:13:30 +00:00
|
|
|
_fill_tag2el_map(arg_t *arg, tag2el_t **tag2el, int *count, int el_no, fte_e flags) {
|
2004-06-03 03:38:44 +00:00
|
|
|
asn1p_expr_t *expr = arg->expr;
|
|
|
|
arg_t tmparg = *arg;
|
|
|
|
asn1p_expr_t *v;
|
|
|
|
int element = 0;
|
2004-10-03 09:13:30 +00:00
|
|
|
int original_count = *count;
|
|
|
|
int sort_until = -1;
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
TQ_FOR(v, &(expr->members), next) {
|
2004-10-03 09:13:30 +00:00
|
|
|
if(v->expr_type == A1TC_EXTENSIBLE) {
|
|
|
|
/*
|
2005-02-25 12:10:27 +00:00
|
|
|
* CXER mandates sorting
|
2004-10-03 09:13:30 +00:00
|
|
|
* only for the root part.
|
|
|
|
*/
|
|
|
|
if(flags == FTE_CANONICAL_XER
|
|
|
|
&& sort_until == -1)
|
|
|
|
sort_until = *count;
|
2004-06-03 03:38:44 +00:00
|
|
|
continue;
|
2004-10-03 09:13:30 +00:00
|
|
|
}
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
tmparg.expr = v;
|
|
|
|
|
|
|
|
if(_add_tag2el_member(&tmparg, tag2el, count,
|
2004-10-03 09:13:30 +00:00
|
|
|
(el_no==-1)?element:el_no, flags)) {
|
2004-06-03 03:38:44 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
element++;
|
|
|
|
}
|
|
|
|
|
2004-10-03 09:13:30 +00:00
|
|
|
|
|
|
|
if(flags == FTE_CANONICAL_XER) {
|
|
|
|
if(sort_until == -1) sort_until = *count;
|
|
|
|
qsort((*tag2el) + original_count,
|
|
|
|
sort_until - original_count,
|
|
|
|
sizeof(**tag2el), _tag2el_cmp);
|
|
|
|
if(arg->expr->expr_type == ASN_CONSTR_CHOICE
|
|
|
|
&& (sort_until - original_count) >= 1) {
|
|
|
|
/* Only take in account the root component */
|
|
|
|
*count = original_count + 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Sort the map according to canonical order of their
|
|
|
|
* tags and element numbers.
|
|
|
|
*/
|
|
|
|
qsort(*tag2el, *count, sizeof(**tag2el), _tag2el_cmp);
|
|
|
|
}
|
2004-06-06 07:20:17 +00:00
|
|
|
|
2004-06-14 13:09:45 +00:00
|
|
|
/*
|
|
|
|
* Initialize .toff_{first|last} members.
|
|
|
|
*/
|
|
|
|
if(*count) {
|
|
|
|
struct asn1p_type_tag_s *cur_tag = 0;
|
|
|
|
tag2el_t *cur = *tag2el;
|
|
|
|
tag2el_t *end = cur + *count;
|
|
|
|
int occur, i;
|
|
|
|
for(occur = 0; cur < end; cur++) {
|
|
|
|
if(cur_tag == 0
|
|
|
|
|| cur_tag->tag_value != cur->el_tag.tag_value
|
|
|
|
|| cur_tag->tag_class != cur->el_tag.tag_class) {
|
|
|
|
cur_tag = &cur->el_tag;
|
|
|
|
occur = 0;
|
|
|
|
} else {
|
|
|
|
occur++;
|
|
|
|
}
|
|
|
|
cur->toff_first = -occur;
|
|
|
|
for(i = 0; i >= -occur; i--)
|
|
|
|
cur[i].toff_last = -i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-10-03 09:13:30 +00:00
|
|
|
_add_tag2el_member(arg_t *arg, tag2el_t **tag2el, int *count, int el_no, fte_e flags) {
|
2004-06-03 03:38:44 +00:00
|
|
|
struct asn1p_type_tag_s tag;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
assert(el_no >= 0);
|
|
|
|
|
2004-09-22 16:06:28 +00:00
|
|
|
ret = asn1f_fetch_outmost_tag(arg->asn, arg->expr->module,
|
2005-11-26 11:25:14 +00:00
|
|
|
arg->expr, &tag, AFT_IMAGINARY_ANY);
|
2004-06-03 03:38:44 +00:00
|
|
|
if(ret == 0) {
|
2004-09-04 04:42:29 +00:00
|
|
|
tag2el_t *te;
|
|
|
|
int new_count = (*count) + 1;
|
2004-06-03 03:38:44 +00:00
|
|
|
void *p;
|
2004-09-04 04:42:29 +00:00
|
|
|
|
2004-09-05 10:42:33 +00:00
|
|
|
if(tag.tag_value == -1) {
|
|
|
|
/*
|
|
|
|
* This is an untagged ANY type,
|
|
|
|
* proceed without adding a tag
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-09-04 04:42:29 +00:00
|
|
|
p = realloc(*tag2el, new_count * sizeof(tag2el_t));
|
2004-06-03 03:38:44 +00:00
|
|
|
if(p) *tag2el = p;
|
|
|
|
else return -1;
|
|
|
|
|
2006-10-09 12:07:58 +00:00
|
|
|
if(0) DEBUG("Found tag for %s: %ld",
|
2004-06-03 03:38:44 +00:00
|
|
|
arg->expr->Identifier,
|
|
|
|
(long)tag.tag_value);
|
|
|
|
|
2004-09-04 04:42:29 +00:00
|
|
|
te = &((*tag2el)[*count]);
|
|
|
|
te->el_tag = tag;
|
|
|
|
te->el_no = el_no;
|
|
|
|
te->from_expr = arg->expr;
|
|
|
|
*count = new_count;
|
2004-06-03 03:38:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG("Searching tag in complex expression %s:%x at line %d",
|
|
|
|
arg->expr->Identifier,
|
|
|
|
arg->expr->expr_type,
|
|
|
|
arg->expr->_lineno);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over members of CHOICE type.
|
|
|
|
*/
|
|
|
|
if(arg->expr->expr_type == ASN_CONSTR_CHOICE) {
|
2004-10-03 09:13:30 +00:00
|
|
|
return _fill_tag2el_map(arg, tag2el, count, el_no, flags);
|
2004-06-03 03:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(arg->expr->expr_type == A1TC_REFERENCE) {
|
|
|
|
arg_t tmp = *arg;
|
|
|
|
asn1p_expr_t *expr;
|
2005-08-18 13:38:19 +00:00
|
|
|
expr = asn1f_lookup_symbol_ex(tmp.asn, tmp.expr,
|
2004-06-03 03:38:44 +00:00
|
|
|
arg->expr->reference);
|
|
|
|
if(expr) {
|
|
|
|
tmp.expr = expr;
|
2004-10-03 09:13:30 +00:00
|
|
|
return _add_tag2el_member(&tmp, tag2el, count, el_no, flags);
|
2004-06-03 03:38:44 +00:00
|
|
|
} else {
|
|
|
|
FATAL("Cannot dereference %s at line %d",
|
|
|
|
arg->expr->Identifier,
|
|
|
|
arg->expr->_lineno);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG("No tag for %s at line %d",
|
|
|
|
arg->expr->Identifier,
|
|
|
|
arg->expr->_lineno);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-06-06 07:20:17 +00:00
|
|
|
static int
|
2004-10-03 09:13:30 +00:00
|
|
|
emit_tag2member_map(arg_t *arg, tag2el_t *tag2el, int tag2el_count, const char *opt_modifier) {
|
2004-06-06 07:20:17 +00:00
|
|
|
asn1p_expr_t *expr = arg->expr;
|
2005-06-02 05:21:37 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if(!tag2el_count) return 0; /* No top level tags */
|
2004-06-06 07:20:17 +00:00
|
|
|
|
2014-07-28 19:16:01 +00:00
|
|
|
OUT("static const asn_TYPE_tag2member_t asn_MAP_%s_tag2el%s_%d[] = {\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr), opt_modifier?opt_modifier:"",
|
2005-11-26 11:25:14 +00:00
|
|
|
expr->_type_unique_index);
|
2005-06-02 05:21:37 +00:00
|
|
|
for(i = 0; i < tag2el_count; i++) {
|
|
|
|
OUT(" { ");
|
|
|
|
_print_tag(arg, &tag2el[i].el_tag);
|
|
|
|
OUT(", ");
|
|
|
|
OUT("%d, ", tag2el[i].el_no);
|
|
|
|
OUT("%d, ", tag2el[i].toff_first);
|
|
|
|
OUT("%d ", tag2el[i].toff_last);
|
2013-10-11 21:29:38 +00:00
|
|
|
OUT("}%s /* %s",
|
2005-06-02 05:21:37 +00:00
|
|
|
(i + 1 < tag2el_count) ? "," : "",
|
2013-10-11 21:29:38 +00:00
|
|
|
tag2el[i].from_expr->Identifier);
|
|
|
|
if(arg->flags & A1C_LINE_REFS)
|
|
|
|
OUT("at %d", tag2el[i].from_expr->_lineno);
|
|
|
|
OUT(" */\n");
|
2004-06-06 07:20:17 +00:00
|
|
|
}
|
|
|
|
OUT("};\n");
|
|
|
|
|
2005-06-02 05:21:37 +00:00
|
|
|
return 0;
|
2004-06-06 07:20:17 +00:00
|
|
|
}
|
|
|
|
|
2004-09-13 08:31:01 +00:00
|
|
|
static enum tvm_compat
|
|
|
|
emit_tags_vectors(arg_t *arg, asn1p_expr_t *expr, int *tags_count_r, int *all_tags_count_r) {
|
|
|
|
struct asn1p_type_tag_s *tags = 0; /* Effective tags */
|
|
|
|
struct asn1p_type_tag_s *all_tags = 0; /* The full array */
|
2004-08-11 07:17:22 +00:00
|
|
|
int tags_count = 0;
|
2004-09-13 08:31:01 +00:00
|
|
|
int all_tags_count = 0;
|
|
|
|
enum tvm_compat tv_mode = _TVM_SAME;
|
2004-09-10 15:49:15 +00:00
|
|
|
int i;
|
2004-06-28 21:13:46 +00:00
|
|
|
|
2004-09-14 14:10:10 +00:00
|
|
|
/* Cleanup before proceeding. */
|
|
|
|
*tags_count_r = 0;
|
|
|
|
*all_tags_count_r = 0;
|
|
|
|
|
2004-09-10 15:49:15 +00:00
|
|
|
/* Fetch a chain of tags */
|
2004-09-22 16:06:28 +00:00
|
|
|
tags_count = asn1f_fetch_tags(arg->asn, expr->module, expr, &tags, 0);
|
2006-10-09 12:07:58 +00:00
|
|
|
if(tags_count < 0) {
|
|
|
|
DEBUG("fail to fetch tags for %s", expr->Identifier);
|
2004-09-14 14:10:10 +00:00
|
|
|
return -1;
|
2006-10-09 12:07:58 +00:00
|
|
|
}
|
2004-08-11 07:17:22 +00:00
|
|
|
|
2004-09-13 08:31:01 +00:00
|
|
|
/* Fetch a chain of tags */
|
2004-09-22 16:06:28 +00:00
|
|
|
all_tags_count = asn1f_fetch_tags(arg->asn, expr->module, expr,
|
2004-09-13 08:31:01 +00:00
|
|
|
&all_tags, AFT_FULL_COLLECT);
|
|
|
|
if(all_tags_count < 0) {
|
2016-03-14 09:00:27 +00:00
|
|
|
free(tags);
|
2006-10-09 12:07:58 +00:00
|
|
|
DEBUG("fail to fetch tags chain for %s", expr->Identifier);
|
2004-09-13 08:31:01 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(tags_count <= all_tags_count);
|
|
|
|
assert((tags_count?0:1) == (all_tags_count?0:1));
|
2004-09-10 15:49:15 +00:00
|
|
|
|
2004-09-13 08:31:01 +00:00
|
|
|
if(tags_count <= all_tags_count) {
|
|
|
|
for(i = 0; i < tags_count; i++) {
|
|
|
|
if(tags[i].tag_value != all_tags[i].tag_value
|
|
|
|
|| tags[i].tag_class != all_tags[i].tag_class) {
|
|
|
|
tv_mode = _TVM_DIFFERENT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(i == tags_count && tags_count < all_tags_count)
|
|
|
|
tv_mode = _TVM_SUBSET;
|
|
|
|
} else {
|
|
|
|
tv_mode = _TVM_DIFFERENT;
|
2004-09-08 00:28:57 +00:00
|
|
|
}
|
2004-09-10 15:49:15 +00:00
|
|
|
|
2004-09-13 08:31:01 +00:00
|
|
|
#define EMIT_TAGS_TABLE(name, tags, tags_count) do { \
|
2014-07-28 19:16:01 +00:00
|
|
|
OUT("static const ber_tlv_tag_t asn_DEF_%s%s_tags_%d[] = {\n",\
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr), name, \
|
2005-11-26 11:25:14 +00:00
|
|
|
expr->_type_unique_index); \
|
2004-09-13 08:31:01 +00:00
|
|
|
INDENT(+1); \
|
|
|
|
/* Print the array of collected tags */ \
|
|
|
|
for(i = 0; i < tags_count; i++) { \
|
|
|
|
if(i) OUT(",\n"); \
|
|
|
|
_print_tag(arg, &tags[i]); \
|
|
|
|
} \
|
|
|
|
OUT("\n"); \
|
|
|
|
INDENT(-1); \
|
|
|
|
OUT("};\n"); \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
if(tags_count) {
|
|
|
|
if(tv_mode == _TVM_SUBSET)
|
|
|
|
EMIT_TAGS_TABLE("", all_tags, all_tags_count);
|
|
|
|
else
|
|
|
|
EMIT_TAGS_TABLE("", tags, tags_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(all_tags_count) {
|
|
|
|
if(tv_mode == _TVM_DIFFERENT)
|
|
|
|
EMIT_TAGS_TABLE("_all", all_tags, all_tags_count);
|
|
|
|
}
|
|
|
|
|
2016-03-14 09:00:27 +00:00
|
|
|
free(tags);
|
|
|
|
free(all_tags);
|
2004-09-13 08:31:01 +00:00
|
|
|
|
|
|
|
*tags_count_r = tags_count;
|
|
|
|
*all_tags_count_r = all_tags_count;
|
2004-06-28 21:13:46 +00:00
|
|
|
|
2004-09-13 08:31:01 +00:00
|
|
|
return tv_mode;
|
2004-06-28 21:13:46 +00:00
|
|
|
}
|
2004-08-20 13:37:01 +00:00
|
|
|
|
|
|
|
static int
|
2004-08-25 02:03:12 +00:00
|
|
|
expr_elements_count(arg_t *arg, asn1p_expr_t *expr) {
|
2004-08-20 13:37:01 +00:00
|
|
|
asn1p_expr_t *topmost_parent;
|
|
|
|
asn1p_expr_t *v;
|
|
|
|
int elements = 0;
|
|
|
|
|
2004-09-22 16:06:28 +00:00
|
|
|
topmost_parent = asn1f_find_terminal_type_ex(arg->asn, expr);
|
2004-08-20 13:37:01 +00:00
|
|
|
if(!topmost_parent) return 0;
|
|
|
|
|
2005-02-25 12:10:27 +00:00
|
|
|
if(!(topmost_parent->expr_type & ASN_CONSTR_MASK)
|
2016-01-10 21:15:02 +00:00
|
|
|
&& !(topmost_parent->expr_type == ASN_BASIC_INTEGER)
|
2016-01-10 21:33:08 +00:00
|
|
|
&& !(topmost_parent->expr_type == ASN_BASIC_ENUMERATED)
|
|
|
|
&& !(topmost_parent->expr_type == ASN_BASIC_BIT_STRING))
|
2004-08-20 13:37:01 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
TQ_FOR(v, &(topmost_parent->members), next) {
|
|
|
|
if(v->expr_type != A1TC_EXTENSIBLE)
|
|
|
|
elements++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return elements;
|
|
|
|
}
|
|
|
|
|
2005-11-26 11:25:14 +00:00
|
|
|
static asn1p_expr_type_e
|
|
|
|
expr_get_type(arg_t *arg, asn1p_expr_t *expr) {
|
|
|
|
asn1p_expr_t *terminal;
|
|
|
|
terminal = asn1f_find_terminal_type_ex(arg->asn, expr);
|
|
|
|
if(terminal) return terminal->expr_type;
|
|
|
|
return A1TC_INVALID;
|
|
|
|
}
|
|
|
|
|
2006-10-09 12:07:58 +00:00
|
|
|
static asn1c_integer_t
|
|
|
|
PER_FROM_alphabet_characters(asn1cnst_range_t *range) {
|
|
|
|
asn1c_integer_t numchars = 0;
|
|
|
|
if(range->el_count) {
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < range->el_count; i++)
|
|
|
|
numchars
|
|
|
|
+= PER_FROM_alphabet_characters(range->elements[i]);
|
|
|
|
} else {
|
|
|
|
assert(range->left.type == ARE_VALUE);
|
|
|
|
assert(range->right.type == ARE_VALUE);
|
|
|
|
numchars = 1 + (range->right.value - range->left.value);
|
|
|
|
}
|
|
|
|
return numchars;
|
|
|
|
}
|
|
|
|
|
2017-08-02 17:37:31 +00:00
|
|
|
static void
|
|
|
|
emit_single_member_OER_constraint_comment(arg_t *arg, asn1cnst_range_t *range, char *type) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print some courtesy debug information.
|
|
|
|
*/
|
|
|
|
if(range
|
|
|
|
&& (range->left.type == ARE_VALUE || range->right.type == ARE_VALUE)) {
|
|
|
|
OUT("\t/* ");
|
|
|
|
if(type) OUT("(%s", type);
|
|
|
|
OUT("(");
|
|
|
|
if(range->left.type == ARE_VALUE)
|
2017-08-04 08:38:41 +00:00
|
|
|
OUT("%s", asn1p_itoa(range->left.value));
|
2017-08-02 17:37:31 +00:00
|
|
|
else
|
|
|
|
OUT("MIN");
|
|
|
|
OUT("..");
|
|
|
|
if(range->right.type == ARE_VALUE)
|
2017-08-04 08:38:41 +00:00
|
|
|
OUT("%s", asn1p_itoa(range->right.value));
|
2017-08-02 17:37:31 +00:00
|
|
|
else
|
|
|
|
OUT("MAX");
|
|
|
|
if(range->extensible) OUT(",...");
|
|
|
|
if(type) OUT(")");
|
|
|
|
OUT(") */");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-19 04:51:11 +00:00
|
|
|
static int
|
2017-08-02 19:53:44 +00:00
|
|
|
emit_single_member_OER_constraint_value(arg_t *arg, asn1cnst_range_t *range) {
|
2017-07-19 04:51:11 +00:00
|
|
|
if(!range) {
|
|
|
|
/* oer_support.h: asn_oer_constraint_s */
|
2017-08-02 17:37:31 +00:00
|
|
|
OUT("{ 0, 0 }");
|
|
|
|
return 0;
|
2017-07-19 04:51:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(range->incompatible || range->not_OER_visible) {
|
2017-08-02 17:37:31 +00:00
|
|
|
OUT("{ 0, 0 }");
|
|
|
|
} else if(range->left.type == ARE_VALUE &&
|
|
|
|
range->right.type == ARE_VALUE) {
|
|
|
|
asn1c_integer_t lb = range->left.value;
|
|
|
|
asn1c_integer_t ub = range->right.value;
|
|
|
|
unsigned width = 0;
|
|
|
|
unsigned positive = 0;
|
|
|
|
|
2017-08-02 19:53:44 +00:00
|
|
|
|
2017-08-02 17:37:31 +00:00
|
|
|
if(lb >= 0) {
|
|
|
|
/* X.969 08/2015 10.2(a) */
|
|
|
|
if(ub <= 255) {
|
|
|
|
width = 1;
|
|
|
|
} else if(ub <= 65535) {
|
|
|
|
width = 2;
|
2017-08-02 19:53:44 +00:00
|
|
|
} else if((unsigned long long)ub <= 4294967295UL) {
|
2017-08-02 17:37:31 +00:00
|
|
|
width = 4;
|
2017-08-02 19:53:44 +00:00
|
|
|
} else if((unsigned long long)ub <= 18446744073709551615ULL) {
|
2017-08-02 17:37:31 +00:00
|
|
|
width = 8;
|
|
|
|
}
|
|
|
|
positive = 1;
|
|
|
|
} else {
|
|
|
|
positive = 0;
|
|
|
|
/* X.969 08/2015 10.2(b) - no lower bound or negative lower bound */
|
|
|
|
if(lb >= -128 && ub <= 127) {
|
|
|
|
width = 1;
|
|
|
|
} else if(lb >= -32768 && ub <= 32767) {
|
|
|
|
width = 2;
|
|
|
|
} else if(lb >= -2147483648L && ub <= 2147483647L) {
|
|
|
|
width = 4;
|
2017-08-02 19:53:44 +00:00
|
|
|
} else if(lb >= (-9223372036854775807LL-1)
|
2017-08-02 17:37:31 +00:00
|
|
|
&& ub <= 9223372036854775807LL) {
|
|
|
|
width = 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OUT("{ %u, %u }", width, positive);
|
|
|
|
} else {
|
|
|
|
OUT("{ 0, 0 }");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-08-02 19:53:44 +00:00
|
|
|
emit_single_member_OER_constraint_size(arg_t *arg, asn1cnst_range_t *range) {
|
2017-08-02 17:37:31 +00:00
|
|
|
if(!range) {
|
|
|
|
/* oer_support.h: asn_oer_constraint_s */
|
|
|
|
OUT("-1");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(range->incompatible || range->not_OER_visible) {
|
|
|
|
OUT("-1");
|
|
|
|
} else {
|
|
|
|
if(range->left.type == ARE_VALUE && range->right.type == ARE_VALUE
|
|
|
|
&& range->left.value == range->right.value
|
|
|
|
&& range->left.value >= 0) {
|
2017-08-04 08:38:41 +00:00
|
|
|
OUT("%s", asn1p_itoa(range->left.value));
|
2017-08-02 17:37:31 +00:00
|
|
|
} else {
|
|
|
|
OUT("-1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-26 11:25:14 +00:00
|
|
|
static int
|
2017-08-02 19:53:44 +00:00
|
|
|
emit_single_member_PER_constraint(arg_t *arg, asn1cnst_range_t *range, int alphabetsize, const char *type) {
|
2017-08-02 17:37:31 +00:00
|
|
|
if(!range || range->incompatible || range->not_PER_visible) {
|
|
|
|
OUT("{ APC_UNCONSTRAINED,\t-1, -1, 0, 0 }");
|
2005-11-26 11:25:14 +00:00
|
|
|
return 0;
|
2017-08-02 17:37:31 +00:00
|
|
|
}
|
2005-11-26 11:25:14 +00:00
|
|
|
|
2017-08-02 17:37:31 +00:00
|
|
|
if(range->left.type == ARE_VALUE) {
|
2005-11-26 11:25:14 +00:00
|
|
|
if(range->right.type == ARE_VALUE) {
|
|
|
|
asn1c_integer_t cover = 1;
|
|
|
|
asn1c_integer_t r = 1 + range->right.value
|
|
|
|
- range->left.value;
|
2006-08-18 02:27:55 +00:00
|
|
|
size_t rbits; /* Value range bits */
|
|
|
|
ssize_t ebits; /* Value effective range bits */
|
2005-11-26 11:25:14 +00:00
|
|
|
|
|
|
|
if(range->empty_constraint)
|
|
|
|
r = 0;
|
|
|
|
|
2006-10-09 12:07:58 +00:00
|
|
|
if(alphabetsize) {
|
|
|
|
/* X.691: 27.5.2 */
|
|
|
|
r = PER_FROM_alphabet_characters(range);
|
|
|
|
}
|
|
|
|
|
2005-11-26 11:25:14 +00:00
|
|
|
/* Compute real constraint */
|
|
|
|
for(rbits = 0; rbits < (8 * sizeof(r)); rbits++) {
|
|
|
|
if(r <= cover)
|
|
|
|
break;
|
|
|
|
cover *= 2; /* Can't do shifting */
|
|
|
|
if(cover < 0) {
|
|
|
|
FATAL("Constraint at line %d too wide "
|
|
|
|
"for %d-bits integer type",
|
|
|
|
arg->expr->_lineno,
|
|
|
|
sizeof(r) * 8);
|
|
|
|
rbits = sizeof(r);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-24 11:20:27 +00:00
|
|
|
if(alphabetsize) {
|
|
|
|
ebits = rbits;
|
|
|
|
} else {
|
2005-11-26 11:25:14 +00:00
|
|
|
/* X.691, #10.9.4.1 */
|
|
|
|
for(ebits = 0; ebits <= 16; ebits++)
|
|
|
|
if(r <= 1 << ebits) break;
|
|
|
|
if(ebits == 17
|
|
|
|
|| range->right.value >= 65536)
|
|
|
|
ebits = -1;
|
2006-11-24 11:20:27 +00:00
|
|
|
if(0) {
|
2005-11-26 11:25:14 +00:00
|
|
|
/* X.691, #10.5.7.1 */
|
|
|
|
for(ebits = 0; ebits <= 8; ebits++)
|
|
|
|
if(r <= 1 << ebits) break;
|
|
|
|
if(ebits == 9) {
|
|
|
|
if(r <= 65536)
|
|
|
|
ebits = 16;
|
|
|
|
else
|
|
|
|
ebits = -1;
|
|
|
|
}
|
|
|
|
}
|
2006-11-24 11:20:27 +00:00
|
|
|
}
|
2006-10-09 12:07:58 +00:00
|
|
|
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("{ APC_CONSTRAINED%s,%s% d, % d, ",
|
|
|
|
range->extensible
|
|
|
|
? " | APC_EXTENSIBLE" : "",
|
|
|
|
range->extensible ? " " : "\t", rbits, ebits);
|
2006-11-24 11:20:27 +00:00
|
|
|
|
|
|
|
if(alphabetsize) {
|
|
|
|
asn1c_integer_t lv = range->left.value;
|
|
|
|
asn1c_integer_t rv = range->right.value;
|
|
|
|
int gcmt = 0;
|
|
|
|
if(lv > 0x7fffffff) { lv = 0x7fffffff; gcmt++; }
|
|
|
|
if(rv > 0x7fffffff) { rv = 0x7fffffff; gcmt++; }
|
|
|
|
if(gcmt) {
|
2007-11-06 01:48:46 +00:00
|
|
|
OINTS(lv); OUT(", "); OINTS(rv); OUT(" }");
|
2006-11-24 11:20:27 +00:00
|
|
|
goto pcmt;
|
|
|
|
}
|
|
|
|
}
|
2005-11-26 11:25:14 +00:00
|
|
|
} else {
|
|
|
|
if(range->extensible) {
|
|
|
|
OUT("{ APC_SEMI_CONSTRAINED | APC_EXTENSIBLE, "
|
|
|
|
"-1, ");
|
|
|
|
} else {
|
|
|
|
OUT("{ APC_SEMI_CONSTRAINED,\t-1, -1, ");
|
|
|
|
}
|
|
|
|
}
|
2007-11-06 01:48:46 +00:00
|
|
|
OINTS(range->left.value); OUT(", ");
|
|
|
|
OINTS(range->right.value); OUT(" }");
|
2005-11-26 11:25:14 +00:00
|
|
|
} else {
|
|
|
|
OUT("{ APC_UNCONSTRAINED,\t-1, -1, 0, 0 }");
|
|
|
|
}
|
|
|
|
|
2006-11-24 11:20:27 +00:00
|
|
|
pcmt:
|
|
|
|
|
2005-11-26 11:25:14 +00:00
|
|
|
/*
|
|
|
|
* Print some courtesy debug information.
|
|
|
|
*/
|
|
|
|
if(range->left.type == ARE_VALUE
|
|
|
|
|| range->right.type == ARE_VALUE) {
|
|
|
|
OUT("\t/* ");
|
|
|
|
if(type) OUT("(%s", type);
|
|
|
|
OUT("(");
|
|
|
|
if(range->left.type == ARE_VALUE)
|
2017-08-04 08:38:41 +00:00
|
|
|
OUT("%s", asn1p_itoa(range->left.value));
|
2005-11-26 11:25:14 +00:00
|
|
|
else
|
|
|
|
OUT("MIN");
|
|
|
|
OUT("..");
|
|
|
|
if(range->right.type == ARE_VALUE)
|
2017-08-04 08:38:41 +00:00
|
|
|
OUT("%s", asn1p_itoa(range->right.value));
|
2005-11-26 11:25:14 +00:00
|
|
|
else
|
|
|
|
OUT("MAX");
|
|
|
|
if(range->extensible) OUT(",...");
|
|
|
|
if(type) OUT(")");
|
|
|
|
OUT(") */");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-19 04:51:11 +00:00
|
|
|
static int
|
|
|
|
emit_member_OER_constraints(arg_t *arg, asn1p_expr_t *expr, const char *pfx) {
|
|
|
|
int save_target = arg->target->target;
|
|
|
|
asn1cnst_range_t *range;
|
|
|
|
asn1p_expr_type_e etype;
|
|
|
|
|
|
|
|
etype = expr_get_type(arg, expr);
|
|
|
|
|
|
|
|
if((arg->flags & A1C_GEN_OER)
|
|
|
|
&& (expr->constraints || etype == ASN_BASIC_ENUMERATED
|
|
|
|
|| etype == ASN_CONSTR_CHOICE)) {
|
|
|
|
/* Fall through */
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
REDIR(OT_CTDEFS);
|
|
|
|
|
|
|
|
OUT("static asn_oer_constraints_t "
|
|
|
|
"asn_OER_%s_%s_constr_%d GCC_NOTUSED = {\n",
|
|
|
|
pfx, MKID(expr), expr->_type_unique_index);
|
|
|
|
|
|
|
|
INDENT(+1);
|
|
|
|
|
2017-08-02 17:37:31 +00:00
|
|
|
/* .value{.width,.positive} */
|
2017-08-01 03:20:17 +00:00
|
|
|
range = asn1constraint_compute_OER_range(expr->Identifier, etype,
|
|
|
|
expr->combined_constraints,
|
2017-07-19 04:51:11 +00:00
|
|
|
ACT_EL_RANGE, 0, 0, 0);
|
2017-08-02 19:53:44 +00:00
|
|
|
if(emit_single_member_OER_constraint_value(arg, range)) {
|
2017-07-19 04:51:11 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2017-08-02 17:37:31 +00:00
|
|
|
emit_single_member_OER_constraint_comment(arg, range, 0);
|
2017-07-19 04:51:11 +00:00
|
|
|
asn1constraint_range_free(range);
|
|
|
|
|
|
|
|
OUT(",\n");
|
|
|
|
|
2017-08-02 17:37:31 +00:00
|
|
|
/* .size */
|
2017-08-01 03:20:17 +00:00
|
|
|
range = asn1constraint_compute_OER_range(expr->Identifier, etype,
|
|
|
|
expr->combined_constraints,
|
2017-07-19 04:51:11 +00:00
|
|
|
ACT_CT_SIZE, 0, 0, 0);
|
2017-08-02 19:53:44 +00:00
|
|
|
if(emit_single_member_OER_constraint_size(arg, range)) {
|
2017-07-19 04:51:11 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2017-08-02 17:37:31 +00:00
|
|
|
emit_single_member_OER_constraint_comment(arg, range, "SIZE");
|
2017-07-19 04:51:11 +00:00
|
|
|
asn1constraint_range_free(range);
|
|
|
|
|
|
|
|
INDENT(-1);
|
|
|
|
|
|
|
|
OUT("};\n");
|
|
|
|
|
|
|
|
REDIR(save_target);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-26 11:25:14 +00:00
|
|
|
static int
|
2006-10-09 12:27:44 +00:00
|
|
|
emit_member_PER_constraints(arg_t *arg, asn1p_expr_t *expr, const char *pfx) {
|
2006-10-09 12:07:58 +00:00
|
|
|
int save_target = arg->target->target;
|
2005-11-26 11:25:14 +00:00
|
|
|
asn1cnst_range_t *range;
|
|
|
|
asn1p_expr_type_e etype;
|
|
|
|
|
2006-10-09 12:52:15 +00:00
|
|
|
etype = expr_get_type(arg, expr);
|
|
|
|
|
2006-10-09 12:07:58 +00:00
|
|
|
if((arg->flags & A1C_GEN_PER)
|
|
|
|
&& (expr->constraints
|
2006-10-09 12:52:15 +00:00
|
|
|
|| etype == ASN_BASIC_ENUMERATED
|
|
|
|
|| etype == ASN_CONSTR_CHOICE)
|
2006-10-09 12:07:58 +00:00
|
|
|
) {
|
|
|
|
/* Fall through */
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-16 05:50:09 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2006-10-09 12:07:58 +00:00
|
|
|
REDIR(OT_CTDEFS);
|
|
|
|
|
2016-05-16 05:50:09 +00:00
|
|
|
if(!(expr->_type_referenced)) OUT("static ");
|
|
|
|
OUT("asn_per_constraints_t "
|
2013-03-28 11:02:13 +00:00
|
|
|
"asn_PER_%s_%s_constr_%d GCC_NOTUSED = {\n",
|
2006-10-09 12:27:44 +00:00
|
|
|
pfx, MKID(expr), expr->_type_unique_index);
|
2006-10-09 12:07:58 +00:00
|
|
|
|
2005-11-26 11:25:14 +00:00
|
|
|
INDENT(+1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ENUMERATED and CHOICE are special.
|
|
|
|
*/
|
|
|
|
if(etype == ASN_BASIC_ENUMERATED
|
|
|
|
|| etype == ASN_CONSTR_CHOICE) {
|
|
|
|
asn1cnst_range_t tmprng;
|
|
|
|
asn1p_expr_t *v;
|
|
|
|
int extensible = 0;
|
|
|
|
int eidx = -1;
|
|
|
|
|
|
|
|
expr = asn1f_find_terminal_type_ex(arg->asn, expr);
|
|
|
|
assert(expr);
|
|
|
|
|
|
|
|
TQ_FOR(v, &(expr->members), next) {
|
|
|
|
if(v->expr_type == A1TC_EXTENSIBLE) {
|
|
|
|
extensible++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
eidx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&tmprng, 0, sizeof (tmprng));
|
|
|
|
tmprng.extensible = extensible;
|
|
|
|
if(eidx < 0) tmprng.empty_constraint = 1;
|
|
|
|
tmprng.left.type = ARE_VALUE;
|
|
|
|
tmprng.left.value = 0;
|
|
|
|
tmprng.right.type = ARE_VALUE;
|
|
|
|
tmprng.right.value = eidx < 0 ? 0 : eidx;
|
2006-10-09 12:07:58 +00:00
|
|
|
if(emit_single_member_PER_constraint(arg, &tmprng, 0, 0))
|
2005-11-26 11:25:14 +00:00
|
|
|
return -1;
|
2006-09-21 01:50:13 +00:00
|
|
|
} else if(etype & ASN_STRING_KM_MASK) {
|
2017-08-01 03:20:17 +00:00
|
|
|
range = asn1constraint_compute_PER_range(expr->Identifier, etype,
|
2006-09-21 01:50:13 +00:00
|
|
|
expr->combined_constraints, ACT_CT_FROM,
|
|
|
|
0, 0, 0);
|
2006-10-09 12:07:58 +00:00
|
|
|
DEBUG("Emitting FROM constraint for %s", expr->Identifier);
|
2006-11-24 11:20:27 +00:00
|
|
|
|
|
|
|
if((range->left.type == ARE_MIN && range->right.type == ARE_MAX)
|
|
|
|
|| range->not_PER_visible) {
|
|
|
|
switch(etype) {
|
|
|
|
case ASN_STRING_BMPString:
|
|
|
|
range->left.type = ARE_VALUE;
|
|
|
|
range->left.value = 0;
|
|
|
|
range->right.type = ARE_VALUE;
|
|
|
|
range->right.value = 65535;
|
|
|
|
range->not_PER_visible = 0;
|
|
|
|
range->extensible = 0;
|
|
|
|
break;
|
|
|
|
case ASN_STRING_UniversalString:
|
|
|
|
OUT("{ APC_CONSTRAINED,\t32, 32,"
|
|
|
|
" 0, 2147483647 }"
|
|
|
|
" /* special case 1 */\n");
|
|
|
|
goto avoid;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-10-09 12:07:58 +00:00
|
|
|
if(emit_single_member_PER_constraint(arg, range, 1, 0))
|
2006-09-21 01:50:13 +00:00
|
|
|
return -1;
|
2006-11-24 11:20:27 +00:00
|
|
|
avoid:
|
2006-09-21 01:50:13 +00:00
|
|
|
asn1constraint_range_free(range);
|
2005-11-26 11:25:14 +00:00
|
|
|
} else {
|
2017-08-01 03:20:17 +00:00
|
|
|
range = asn1constraint_compute_PER_range(expr->Identifier, etype,
|
2005-11-26 11:25:14 +00:00
|
|
|
expr->combined_constraints, ACT_EL_RANGE,
|
|
|
|
0, 0, 0);
|
2006-10-09 12:07:58 +00:00
|
|
|
if(emit_single_member_PER_constraint(arg, range, 0, 0))
|
2005-11-26 11:25:14 +00:00
|
|
|
return -1;
|
|
|
|
asn1constraint_range_free(range);
|
|
|
|
}
|
|
|
|
OUT(",\n");
|
|
|
|
|
2017-08-01 03:20:17 +00:00
|
|
|
range = asn1constraint_compute_PER_range(expr->Identifier, etype,
|
2005-11-26 11:25:14 +00:00
|
|
|
expr->combined_constraints, ACT_CT_SIZE, 0, 0, 0);
|
2006-10-09 12:07:58 +00:00
|
|
|
if(emit_single_member_PER_constraint(arg, range, 0, "SIZE"))
|
2005-11-26 11:25:14 +00:00
|
|
|
return -1;
|
|
|
|
asn1constraint_range_free(range);
|
2006-10-09 12:07:58 +00:00
|
|
|
OUT(",\n");
|
2005-11-26 11:25:14 +00:00
|
|
|
|
2006-10-09 12:07:58 +00:00
|
|
|
if((etype & ASN_STRING_KM_MASK) && (expr->_mark & TM_PERFROMCT)) {
|
|
|
|
int old_target = arg->target->target;
|
|
|
|
REDIR(OT_CODE);
|
2005-11-26 11:25:14 +00:00
|
|
|
|
2006-10-09 12:07:58 +00:00
|
|
|
OUT("static int asn_PER_MAP_%s_%d_v2c(unsigned int value) {\n",
|
|
|
|
MKID(expr), expr->_type_unique_index);
|
|
|
|
OUT("\tif(value >= sizeof(permitted_alphabet_table_%d)/"
|
|
|
|
"sizeof(permitted_alphabet_table_%d[0]))\n",
|
|
|
|
expr->_type_unique_index,
|
|
|
|
expr->_type_unique_index);
|
|
|
|
OUT("\t\treturn -1;\n");
|
|
|
|
OUT("\treturn permitted_alphabet_table_%d[value] - 1;\n",
|
|
|
|
expr->_type_unique_index);
|
|
|
|
OUT("}\n");
|
2005-11-26 11:25:14 +00:00
|
|
|
|
2006-10-09 12:07:58 +00:00
|
|
|
OUT("static int asn_PER_MAP_%s_%d_c2v(unsigned int code) {\n",
|
|
|
|
MKID(expr), expr->_type_unique_index);
|
|
|
|
OUT("\tif(code >= sizeof(permitted_alphabet_code2value_%d)/"
|
|
|
|
"sizeof(permitted_alphabet_code2value_%d[0]))\n",
|
|
|
|
expr->_type_unique_index,
|
|
|
|
expr->_type_unique_index);
|
|
|
|
OUT("\t\treturn -1;\n");
|
|
|
|
OUT("\treturn permitted_alphabet_code2value_%d[code];\n",
|
|
|
|
expr->_type_unique_index);
|
|
|
|
OUT("}\n");
|
2005-11-26 11:25:14 +00:00
|
|
|
|
2006-10-09 12:07:58 +00:00
|
|
|
REDIR(old_target);
|
2005-11-26 11:25:14 +00:00
|
|
|
|
2006-10-09 12:07:58 +00:00
|
|
|
OUT("asn_PER_MAP_%s_%d_v2c,\t/* Value to PER code map */\n",
|
|
|
|
MKID(expr), expr->_type_unique_index);
|
|
|
|
OUT("asn_PER_MAP_%s_%d_c2v\t/* PER code to value map */\n",
|
|
|
|
MKID(expr), expr->_type_unique_index);
|
|
|
|
} else if(etype & ASN_STRING_KM_MASK) {
|
|
|
|
DEBUG("No PER value map necessary for %s", MKID(expr));
|
|
|
|
OUT("0, 0\t/* No PER character map necessary */\n");
|
|
|
|
} else {
|
|
|
|
OUT("0, 0\t/* No PER value map */\n");
|
2005-11-26 11:25:14 +00:00
|
|
|
}
|
|
|
|
|
2006-10-09 12:07:58 +00:00
|
|
|
INDENT(-1);
|
|
|
|
|
|
|
|
OUT("};\n");
|
|
|
|
|
|
|
|
REDIR(save_target);
|
|
|
|
|
2005-11-26 11:25:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-06-27 01:54:57 +00:00
|
|
|
static int
|
|
|
|
safe_string(const uint8_t *buf, int size) {
|
|
|
|
const uint8_t *end = buf + size;
|
|
|
|
for(; buf < end; buf++) {
|
|
|
|
int ch = *buf;
|
|
|
|
if((ch < 0x20 || ch > 0x7e) || ch == '"')
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
emit_default_value(arg_t *arg, asn1p_value_t *v) {
|
|
|
|
|
|
|
|
OUT("static uint8_t defv[] = ");
|
|
|
|
assert(v->type == ATV_STRING);
|
|
|
|
|
|
|
|
if(safe_string(v->value.string.buf, v->value.string.size)) {
|
|
|
|
OUT("\"%s\";\n", v->value.string.buf);
|
|
|
|
} else {
|
|
|
|
uint8_t *b = v->value.string.buf;
|
|
|
|
uint8_t *e = v->value.string.size + b;
|
|
|
|
OUT("{ ");
|
|
|
|
for(;b < e; b++)
|
|
|
|
OUT("0x%02x, ", *b);
|
|
|
|
OUT("0 };\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-26 11:25:14 +00:00
|
|
|
static int
|
|
|
|
try_inline_default(arg_t *arg, asn1p_expr_t *expr, int out) {
|
|
|
|
int save_target = arg->target->target;
|
|
|
|
asn1p_expr_type_e etype = expr_get_type(arg, expr);
|
|
|
|
int fits_long = 0;
|
|
|
|
|
|
|
|
switch(etype) {
|
|
|
|
case ASN_BASIC_BOOLEAN:
|
|
|
|
fits_long = 1;
|
|
|
|
case ASN_BASIC_INTEGER:
|
|
|
|
case ASN_BASIC_ENUMERATED:
|
|
|
|
if(expr->marker.default_value == NULL
|
|
|
|
|| expr->marker.default_value->type != ATV_INTEGER)
|
|
|
|
break;
|
|
|
|
if(!fits_long)
|
|
|
|
fits_long = asn1c_type_fits_long(arg, expr)!=FL_NOTFIT;
|
|
|
|
if(fits_long && !expr->marker.default_value->value.v_integer)
|
|
|
|
expr->marker.flags &= ~EM_INDIRECT;
|
2007-06-27 01:54:57 +00:00
|
|
|
if(!out) {
|
2017-08-04 08:38:41 +00:00
|
|
|
OUT("asn_DFL_%d_set_%s,",
|
2007-06-27 01:54:57 +00:00
|
|
|
expr->_type_unique_index,
|
2017-08-04 08:38:41 +00:00
|
|
|
asn1p_itoa(expr->marker.default_value->value.v_integer));
|
|
|
|
OUT("\t/* DEFAULT %s */\n",
|
|
|
|
asn1p_itoa(expr->marker.default_value->value.v_integer));
|
2007-06-27 01:54:57 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2005-11-26 11:25:14 +00:00
|
|
|
REDIR(OT_STAT_DEFS);
|
2017-08-04 08:38:41 +00:00
|
|
|
OUT("static int asn_DFL_%d_set_%s(int set_value, void **sptr) {\n",
|
2005-11-26 11:25:14 +00:00
|
|
|
expr->_type_unique_index,
|
2017-08-04 08:38:41 +00:00
|
|
|
asn1p_itoa(expr->marker.default_value->value.v_integer));
|
2005-11-26 11:25:14 +00:00
|
|
|
INDENT(+1);
|
|
|
|
OUT("%s *st = *sptr;\n", asn1c_type_name(arg, expr, TNF_CTYPE));
|
|
|
|
OUT("\n");
|
|
|
|
OUT("if(!st) {\n");
|
2006-08-18 01:32:26 +00:00
|
|
|
OUT("\tif(!set_value) return -1;\t/* Not a default value */\n");
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("\tst = (*sptr = CALLOC(1, sizeof(*st)));\n");
|
|
|
|
OUT("\tif(!st) return -1;\n");
|
|
|
|
OUT("}\n");
|
|
|
|
OUT("\n");
|
2006-08-18 01:32:26 +00:00
|
|
|
OUT("if(set_value) {\n");
|
|
|
|
INDENT(+1);
|
2017-08-04 08:38:41 +00:00
|
|
|
OUT("/* Install default value %s */\n",
|
|
|
|
asn1p_itoa(expr->marker.default_value->value.v_integer));
|
2005-11-26 11:25:14 +00:00
|
|
|
if(fits_long) {
|
2007-11-06 01:48:46 +00:00
|
|
|
OUT("*st = ");
|
|
|
|
OINT(expr->marker.default_value->value.v_integer);
|
|
|
|
OUT(";\n");
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("return 0;\n");
|
|
|
|
} else {
|
2007-11-06 01:48:46 +00:00
|
|
|
OUT("return asn_long2INTEGER(st, ");
|
|
|
|
OINT(expr->marker.default_value->value.v_integer);
|
|
|
|
OUT(");\n");
|
2005-11-26 11:25:14 +00:00
|
|
|
}
|
|
|
|
INDENT(-1);
|
2006-08-18 01:32:26 +00:00
|
|
|
OUT("} else {\n");
|
|
|
|
INDENT(+1);
|
2017-08-04 08:38:41 +00:00
|
|
|
OUT("/* Test default value %s */\n",
|
|
|
|
asn1p_itoa(expr->marker.default_value->value.v_integer));
|
2006-08-18 01:32:26 +00:00
|
|
|
if(fits_long) {
|
2017-08-04 08:38:41 +00:00
|
|
|
OUT("return (*st == %s);\n",
|
|
|
|
asn1p_itoa(expr->marker.default_value->value.v_integer));
|
2006-08-18 01:32:26 +00:00
|
|
|
} else {
|
|
|
|
OUT("long value;\n");
|
|
|
|
OUT("if(asn_INTEGER2long(st, &value))\n");
|
|
|
|
OUT("\treturn -1;\n");
|
2017-08-04 08:38:41 +00:00
|
|
|
OUT("return (value == %s);\n",
|
|
|
|
asn1p_itoa(expr->marker.default_value->value.v_integer));
|
2006-08-18 01:32:26 +00:00
|
|
|
}
|
|
|
|
INDENT(-1);
|
|
|
|
OUT("}\n");
|
|
|
|
INDENT(-1);
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("}\n");
|
|
|
|
REDIR(save_target);
|
|
|
|
return 1;
|
|
|
|
case ASN_BASIC_NULL:
|
|
|
|
//expr->marker.flags &= ~EM_INDIRECT;
|
|
|
|
return 0;
|
|
|
|
default:
|
2007-06-27 01:54:57 +00:00
|
|
|
if(etype & ASN_STRING_KM_MASK) {
|
|
|
|
if(expr->marker.default_value == NULL
|
|
|
|
|| expr->marker.default_value->type != ATV_STRING)
|
|
|
|
break;
|
|
|
|
if(!out) {
|
|
|
|
OUT("asn_DFL_%d_set,\t/* DEFAULT \"%s\" */\n",
|
|
|
|
expr->_type_unique_index,
|
|
|
|
expr->marker.default_value->value.string.buf);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
REDIR(OT_STAT_DEFS);
|
|
|
|
OUT("static int asn_DFL_%d_set(int set_value, void **sptr) {\n", expr->_type_unique_index);
|
|
|
|
INDENT(+1);
|
|
|
|
emit_default_value(arg, expr->marker.default_value);
|
|
|
|
OUT("%s *st = *sptr;\n", asn1c_type_name(arg, expr, TNF_CTYPE));
|
|
|
|
OUT("\n");
|
|
|
|
OUT("if(!st) {\n");
|
|
|
|
OUT("\tif(!set_value) return -1;\t/* Not a default value */\n");
|
|
|
|
OUT("\tst = (*sptr = CALLOC(1, sizeof(*st)));\n");
|
|
|
|
OUT("\tif(!st) return -1;\n");
|
|
|
|
OUT("}\n");
|
|
|
|
OUT("\n");
|
|
|
|
OUT("if(set_value) {\n");
|
|
|
|
INDENT(+1);
|
|
|
|
OUT("uint8_t *ptr = MALLOC(sizeof(defv));\n");
|
|
|
|
OUT("if(!ptr) return -1;\n");
|
|
|
|
OUT("memcpy(ptr, &defv, sizeof(defv));\n");
|
|
|
|
OUT("FREEMEM(st->buf);\n");
|
|
|
|
OUT("st->buf = ptr;\n");
|
|
|
|
OUT("st->size = sizeof(defv) - 1;\n");
|
|
|
|
OUT("return 0;\n");
|
|
|
|
INDENT(-1);
|
|
|
|
OUT("} else {\n");
|
|
|
|
INDENT(+1);
|
|
|
|
OUT("if(st->size != (sizeof(defv) - 1)\n");
|
|
|
|
OUT("|| memcmp(st->buf, &defv, sizeof(defv) - 1))\n");
|
|
|
|
OUT("\treturn 0;\n");
|
|
|
|
OUT("return 1;\n");
|
|
|
|
INDENT(-1);
|
|
|
|
OUT("}\n"); OUT("\n");
|
|
|
|
INDENT(-1);
|
|
|
|
OUT("}\n");
|
|
|
|
REDIR(save_target);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
2005-11-26 11:25:14 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-08-20 13:37:01 +00:00
|
|
|
static int
|
2004-08-25 02:03:12 +00:00
|
|
|
emit_member_table(arg_t *arg, asn1p_expr_t *expr) {
|
2004-08-20 13:37:01 +00:00
|
|
|
int save_target;
|
|
|
|
arg_t tmp_arg;
|
2004-09-10 09:37:12 +00:00
|
|
|
struct asn1p_type_tag_s outmost_tag_s;
|
|
|
|
struct asn1p_type_tag_s *outmost_tag;
|
2005-02-25 12:10:27 +00:00
|
|
|
int complex_contents;
|
2004-08-20 13:37:01 +00:00
|
|
|
char *p;
|
|
|
|
|
2004-09-10 09:37:12 +00:00
|
|
|
if(asn1f_fetch_outmost_tag(arg->asn,
|
2005-11-26 11:25:14 +00:00
|
|
|
expr->module, expr, &outmost_tag_s,
|
|
|
|
AFT_IMAGINARY_ANY)) {
|
2004-09-10 09:37:12 +00:00
|
|
|
outmost_tag = 0;
|
|
|
|
} else {
|
|
|
|
outmost_tag = &outmost_tag_s;
|
|
|
|
}
|
|
|
|
|
2004-08-20 13:37:01 +00:00
|
|
|
OUT("{ ");
|
2004-09-10 09:37:12 +00:00
|
|
|
|
|
|
|
if(outmost_tag && outmost_tag->tag_value == -1)
|
|
|
|
OUT("ATF_OPEN_TYPE | ");
|
2005-03-04 22:18:20 +00:00
|
|
|
OUT("%s, ",
|
|
|
|
(expr->marker.flags & EM_INDIRECT)?"ATF_POINTER":"ATF_NOFLAGS");
|
2005-08-18 13:38:19 +00:00
|
|
|
if((expr->marker.flags & EM_OMITABLE) == EM_OMITABLE) {
|
2004-08-20 13:37:01 +00:00
|
|
|
asn1p_expr_t *tv;
|
|
|
|
int opts = 0;
|
2005-08-18 13:38:19 +00:00
|
|
|
for(tv = expr;
|
|
|
|
tv && (tv->marker.flags & EM_OMITABLE) == EM_OMITABLE;
|
2004-08-20 13:37:01 +00:00
|
|
|
tv = TQ_NEXT(tv, next), opts++) {
|
|
|
|
if(tv->expr_type == A1TC_EXTENSIBLE)
|
|
|
|
opts--;
|
|
|
|
}
|
|
|
|
OUT("%d, ", opts);
|
|
|
|
} else {
|
|
|
|
OUT("0, ");
|
|
|
|
}
|
2004-09-22 16:06:28 +00:00
|
|
|
if(expr->_anonymous_type) {
|
|
|
|
assert(arg->expr->expr_type == ASN_CONSTR_SET_OF
|
|
|
|
|| arg->expr->expr_type == ASN_CONSTR_SEQUENCE_OF);
|
|
|
|
OUT("0,\n");
|
|
|
|
} else {
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("offsetof(struct ");
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg, ONC_avoid_keywords);
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT(", ");
|
2004-08-20 13:37:01 +00:00
|
|
|
if(arg->expr->expr_type == ASN_CONSTR_CHOICE
|
|
|
|
&& (!UNNAMED_UNIONS)) OUT("choice.");
|
2006-03-21 03:40:38 +00:00
|
|
|
OUT("%s),\n", MKID_safe(expr));
|
2004-08-20 13:37:01 +00:00
|
|
|
}
|
|
|
|
INDENT(+1);
|
|
|
|
if(C99_MODE) OUT(".tag = ");
|
2004-09-10 09:37:12 +00:00
|
|
|
if(outmost_tag) {
|
|
|
|
if(outmost_tag->tag_value == -1)
|
|
|
|
OUT("-1 /* Ambiguous tag (ANY?) */");
|
|
|
|
else
|
|
|
|
_print_tag(arg, outmost_tag);
|
2004-09-10 06:07:18 +00:00
|
|
|
} else {
|
2004-09-10 09:37:12 +00:00
|
|
|
OUT("-1 /* Ambiguous tag (CHOICE?) */");
|
2004-09-10 06:07:18 +00:00
|
|
|
}
|
2004-09-10 09:37:12 +00:00
|
|
|
|
2004-08-20 13:37:01 +00:00
|
|
|
OUT(",\n");
|
|
|
|
if(C99_MODE) OUT(".tag_mode = ");
|
2006-10-19 02:46:01 +00:00
|
|
|
if((!(expr->expr_type & ASN_CONSTR_MASK)
|
|
|
|
|| expr->expr_type == ASN_CONSTR_CHOICE)
|
|
|
|
&& expr->tag.tag_class) {
|
2004-08-20 13:37:01 +00:00
|
|
|
if(expr->tag.tag_mode == TM_IMPLICIT)
|
|
|
|
OUT("-1,\t/* IMPLICIT tag at current level */\n");
|
|
|
|
else
|
|
|
|
OUT("+1,\t/* EXPLICIT tag at current level */\n");
|
|
|
|
} else {
|
|
|
|
OUT("0,\n");
|
|
|
|
}
|
2005-02-25 12:10:27 +00:00
|
|
|
|
|
|
|
complex_contents =
|
|
|
|
(expr->expr_type & ASN_CONSTR_MASK)
|
|
|
|
|| expr->expr_type == ASN_BASIC_ENUMERATED
|
2005-03-03 21:28:12 +00:00
|
|
|
|| (0 /* -- prohibited by X.693:8.3.4 */
|
|
|
|
&& expr->expr_type == ASN_BASIC_INTEGER
|
2007-12-03 13:41:36 +00:00
|
|
|
&& expr_elements_count(arg, expr))
|
|
|
|
|| (expr->expr_type == ASN_BASIC_INTEGER
|
|
|
|
&& asn1c_type_fits_long(arg, expr) == FL_FITS_UNSIGN);
|
2004-08-20 13:37:01 +00:00
|
|
|
if(C99_MODE) OUT(".type = ");
|
2005-08-29 10:31:14 +00:00
|
|
|
OUT("&asn_DEF_");
|
2005-03-04 08:48:53 +00:00
|
|
|
if(complex_contents) {
|
2006-03-21 03:40:38 +00:00
|
|
|
OUT("%s", MKID(expr));
|
2005-03-04 08:48:53 +00:00
|
|
|
if(!(arg->flags & A1C_ALL_DEFS_GLOBAL))
|
|
|
|
OUT("_%d", expr->_type_unique_index);
|
2004-08-22 03:25:24 +00:00
|
|
|
} else {
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT("%s", asn1c_type_name(arg, expr, TNF_SAFE));
|
2004-08-22 03:25:24 +00:00
|
|
|
}
|
2005-03-04 08:48:53 +00:00
|
|
|
OUT(",\n");
|
2004-08-20 13:37:01 +00:00
|
|
|
if(C99_MODE) OUT(".memb_constraints = ");
|
|
|
|
if(expr->constraints) {
|
2004-09-26 13:11:31 +00:00
|
|
|
if(arg->flags & A1C_NO_CONSTRAINTS) {
|
|
|
|
OUT("0,\t/* No check because of -fno-constraints */\n");
|
|
|
|
} else {
|
2006-03-21 03:40:38 +00:00
|
|
|
char *id = MKID(expr);
|
2004-09-26 13:11:31 +00:00
|
|
|
if(expr->_anonymous_type
|
2005-02-14 20:41:29 +00:00
|
|
|
&& !strcmp(expr->Identifier, "Member"))
|
2004-09-26 13:11:31 +00:00
|
|
|
id = asn1c_type_name(arg, expr, TNF_SAFE);
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("memb_%s_constraint_%d,\n", id,
|
2005-03-04 08:48:53 +00:00
|
|
|
arg->expr->_type_unique_index);
|
2004-09-26 13:11:31 +00:00
|
|
|
}
|
2004-08-20 13:37:01 +00:00
|
|
|
} else {
|
2005-01-17 12:16:58 +00:00
|
|
|
OUT("0,\t/* Defer constraints checking to the member type */\n");
|
2004-08-20 13:37:01 +00:00
|
|
|
}
|
2017-07-14 10:59:52 +00:00
|
|
|
if(C99_MODE) OUT(".oer_constraints = ");
|
|
|
|
if(arg->flags & A1C_GEN_OER) {
|
|
|
|
if(expr->constraints) {
|
|
|
|
OUT("&asn_OER_memb_%s_constr_%d,\n",
|
|
|
|
MKID(expr),
|
|
|
|
expr->_type_unique_index);
|
|
|
|
} else {
|
|
|
|
OUT("0,\t/* No OER visible constraints */\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
OUT("0,\t/* OER is not compiled, use -gen-OER */\n");
|
|
|
|
}
|
2005-11-26 11:25:14 +00:00
|
|
|
if(C99_MODE) OUT(".per_constraints = ");
|
|
|
|
if(arg->flags & A1C_GEN_PER) {
|
2006-10-09 12:52:15 +00:00
|
|
|
if(expr->constraints) {
|
2006-10-09 12:27:44 +00:00
|
|
|
OUT("&asn_PER_memb_%s_constr_%d,\n",
|
2006-03-21 03:40:38 +00:00
|
|
|
MKID(expr),
|
2005-11-26 11:25:14 +00:00
|
|
|
expr->_type_unique_index);
|
|
|
|
} else {
|
|
|
|
OUT("0,\t/* No PER visible constraints */\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
OUT("0,\t/* PER is not compiled, use -gen-PER */\n");
|
|
|
|
}
|
|
|
|
if(C99_MODE) OUT(".default_value = ");
|
|
|
|
if(try_inline_default(arg, expr, 0)) {
|
|
|
|
} else {
|
|
|
|
OUT("0,\n");
|
|
|
|
}
|
2004-08-20 13:37:01 +00:00
|
|
|
if(C99_MODE) OUT(".name = ");
|
2005-11-26 11:25:14 +00:00
|
|
|
if(expr->_anonymous_type && !strcmp(expr->Identifier, "Member")) {
|
|
|
|
OUT("\"\"\n");
|
2005-02-14 20:41:29 +00:00
|
|
|
} else {
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("\"%s\"\n", expr->Identifier);
|
2005-02-14 20:41:29 +00:00
|
|
|
}
|
2004-08-20 13:37:01 +00:00
|
|
|
OUT("},\n");
|
|
|
|
INDENT(-1);
|
|
|
|
|
2004-09-26 13:11:31 +00:00
|
|
|
if(!expr->constraints || (arg->flags & A1C_NO_CONSTRAINTS))
|
2004-08-20 13:37:01 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
save_target = arg->target->target;
|
|
|
|
REDIR(OT_CODE);
|
|
|
|
|
2005-02-14 20:41:29 +00:00
|
|
|
if(expr->_anonymous_type && !strcmp(expr->Identifier, "Member"))
|
2004-08-20 13:37:01 +00:00
|
|
|
p = asn1c_type_name(arg, expr, TNF_SAFE);
|
2004-09-22 16:06:28 +00:00
|
|
|
else
|
2006-03-21 03:40:38 +00:00
|
|
|
p = MKID(expr);
|
2004-08-20 13:37:01 +00:00
|
|
|
OUT("static int\n");
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("memb_%s_constraint_%d(asn_TYPE_descriptor_t *td, const void *sptr,\n", p, arg->expr->_type_unique_index);
|
2004-08-20 13:37:01 +00:00
|
|
|
INDENT(+1);
|
2006-07-13 11:19:01 +00:00
|
|
|
OUT("\t\tasn_app_constraint_failed_f *ctfailcb, void *app_key) {\n");
|
2004-08-20 13:37:01 +00:00
|
|
|
tmp_arg = *arg;
|
|
|
|
tmp_arg.expr = expr;
|
2006-10-09 12:07:58 +00:00
|
|
|
DEBUG("member constraint checking code for %s", p);
|
2004-08-20 13:37:01 +00:00
|
|
|
if(asn1c_emit_constraint_checking_code(&tmp_arg) == 1) {
|
2004-09-26 13:11:31 +00:00
|
|
|
OUT("return td->check_constraints"
|
2006-07-13 11:19:01 +00:00
|
|
|
"(td, sptr, ctfailcb, app_key);\n");
|
2004-08-20 13:37:01 +00:00
|
|
|
}
|
|
|
|
INDENT(-1);
|
|
|
|
OUT("}\n");
|
|
|
|
OUT("\n");
|
|
|
|
|
2017-07-19 04:51:11 +00:00
|
|
|
if(emit_member_OER_constraints(arg, expr, "memb"))
|
|
|
|
return -1;
|
|
|
|
|
2006-10-09 12:27:44 +00:00
|
|
|
if(emit_member_PER_constraints(arg, expr, "memb"))
|
2006-10-09 12:07:58 +00:00
|
|
|
return -1;
|
|
|
|
|
2004-08-20 13:37:01 +00:00
|
|
|
REDIR(save_target);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2004-08-25 02:03:12 +00:00
|
|
|
|
2004-10-20 15:50:55 +00:00
|
|
|
/*
|
|
|
|
* Generate "asn_DEF_XXX" type definition.
|
|
|
|
*/
|
2004-08-25 02:03:12 +00:00
|
|
|
static int
|
2004-09-26 13:11:31 +00:00
|
|
|
emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, enum tvm_compat tv_mode, int tags_count, int all_tags_count, int elements_count, enum etd_spec spec) {
|
2006-09-17 06:31:08 +00:00
|
|
|
asn1p_expr_t *terminal;
|
2005-03-04 08:48:53 +00:00
|
|
|
int using_type_name = 0;
|
2006-03-21 03:40:38 +00:00
|
|
|
char *p = MKID(expr);
|
2016-05-16 05:50:09 +00:00
|
|
|
char *p2 = (char *)0;
|
2005-11-26 11:25:14 +00:00
|
|
|
|
2006-09-17 06:31:08 +00:00
|
|
|
terminal = asn1f_find_terminal_type_ex(arg->asn, expr);
|
|
|
|
|
2017-07-27 01:47:08 +00:00
|
|
|
if(emit_member_OER_constraints(arg, expr, "type"))
|
|
|
|
return -1;
|
|
|
|
|
2006-10-09 12:27:44 +00:00
|
|
|
if(emit_member_PER_constraints(arg, expr, "type"))
|
2006-10-09 12:07:58 +00:00
|
|
|
return -1;
|
2004-08-25 02:03:12 +00:00
|
|
|
|
2004-09-06 08:07:29 +00:00
|
|
|
if(HIDE_INNER_DEFS)
|
|
|
|
OUT("static /* Use -fall-defs-global to expose */\n");
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("asn_TYPE_descriptor_t asn_DEF_%s", p);
|
2005-03-04 08:48:53 +00:00
|
|
|
if(HIDE_INNER_DEFS) OUT("_%d", expr->_type_unique_index);
|
|
|
|
OUT(" = {\n");
|
2004-09-13 08:31:01 +00:00
|
|
|
INDENT(+1);
|
2005-11-26 11:25:14 +00:00
|
|
|
|
|
|
|
if(expr->_anonymous_type) {
|
|
|
|
p = ASN_EXPR_TYPE2STR(expr->expr_type);
|
|
|
|
OUT("\"%s\",\n", p?p:"");
|
2006-03-21 03:40:38 +00:00
|
|
|
OUT("\"%s\",\n",
|
|
|
|
p ? asn1c_make_identifier(AMI_CHECK_RESERVED,
|
|
|
|
0, p, 0) : "");
|
2005-11-26 11:25:14 +00:00
|
|
|
} else {
|
|
|
|
OUT("\"%s\",\n", expr->Identifier);
|
|
|
|
OUT("\"%s\",\n", expr->Identifier);
|
|
|
|
}
|
2004-08-25 02:03:12 +00:00
|
|
|
|
|
|
|
if(expr->expr_type & ASN_CONSTR_MASK) {
|
2005-03-04 08:48:53 +00:00
|
|
|
using_type_name = 1;
|
2004-08-25 02:03:12 +00:00
|
|
|
p = asn1c_type_name(arg, arg->expr, TNF_SAFE);
|
2005-11-26 11:25:14 +00:00
|
|
|
} else {
|
2016-05-16 05:50:09 +00:00
|
|
|
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));
|
|
|
|
}
|
2006-03-21 03:40:38 +00:00
|
|
|
p = MKID(expr);
|
2004-08-25 02:03:12 +00:00
|
|
|
}
|
2016-05-16 05:50:09 +00:00
|
|
|
if (!p2)
|
|
|
|
p2 = strdup(p);
|
2004-08-25 02:03:12 +00:00
|
|
|
|
2005-03-04 08:48:53 +00:00
|
|
|
#define FUNCREF(foo) do { \
|
|
|
|
OUT("%s", p); \
|
|
|
|
if(HIDE_INNER_DEFS && !using_type_name) \
|
|
|
|
OUT("_%d", expr->_type_unique_index); \
|
|
|
|
OUT("_" #foo ",\n"); \
|
|
|
|
} while(0)
|
|
|
|
|
2016-05-16 05:50:09 +00:00
|
|
|
#define FUNCREF2(foo) \
|
|
|
|
do { \
|
|
|
|
OUT("%s", p2); \
|
|
|
|
OUT("_" #foo ",\n"); \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
FUNCREF2(free);
|
|
|
|
FUNCREF2(print);
|
2017-08-04 10:44:04 +00:00
|
|
|
if (arg->flags & A1C_NO_CONSTRAINTS)
|
|
|
|
OUT("0,\t/* No check because of -fno-constraints */\n");
|
2016-05-16 05:50:09 +00:00
|
|
|
else
|
2017-08-04 10:44:04 +00:00
|
|
|
{
|
|
|
|
if (!expr->combined_constraints)
|
|
|
|
FUNCREF2(constraint);
|
|
|
|
else
|
|
|
|
FUNCREF(constraint);
|
|
|
|
}
|
2016-05-16 05:50:09 +00:00
|
|
|
FUNCREF2(decode_ber);
|
|
|
|
FUNCREF2(encode_der);
|
|
|
|
FUNCREF2(decode_xer);
|
|
|
|
FUNCREF2(encode_xer);
|
2017-07-14 10:59:52 +00:00
|
|
|
|
|
|
|
if(arg->flags & A1C_GEN_OER) {
|
2016-05-16 05:50:09 +00:00
|
|
|
FUNCREF2(decode_oer);
|
|
|
|
FUNCREF2(encode_oer);
|
2017-07-14 10:59:52 +00:00
|
|
|
} else {
|
|
|
|
OUT("0, 0,\t/* No OER support, "
|
|
|
|
"use \"-gen-OER\" to enable */\n");
|
|
|
|
}
|
2006-08-18 01:32:26 +00:00
|
|
|
if(arg->flags & A1C_GEN_PER) {
|
2016-05-16 05:50:09 +00:00
|
|
|
FUNCREF2(decode_uper);
|
|
|
|
FUNCREF2(encode_uper);
|
2006-08-18 01:32:26 +00:00
|
|
|
} else {
|
|
|
|
OUT("0, 0,\t/* No PER support, "
|
|
|
|
"use \"-gen-PER\" to enable */\n");
|
|
|
|
}
|
2016-05-16 05:50:09 +00:00
|
|
|
if (p2) free(p2);
|
2004-08-25 02:03:12 +00:00
|
|
|
|
2006-09-17 06:31:08 +00:00
|
|
|
if(!terminal || terminal->expr_type == ASN_CONSTR_CHOICE) {
|
|
|
|
//if(expr->expr_type == ASN_CONSTR_CHOICE) {
|
2004-08-25 02:03:12 +00:00
|
|
|
OUT("CHOICE_outmost_tag,\n");
|
|
|
|
} else {
|
|
|
|
OUT("0,\t/* Use generic outmost tag fetcher */\n");
|
|
|
|
}
|
|
|
|
|
2006-03-21 03:40:38 +00:00
|
|
|
p = MKID(expr);
|
2004-08-25 02:03:12 +00:00
|
|
|
if(tags_count) {
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("asn_DEF_%s_tags_%d,\n",
|
2005-03-04 08:48:53 +00:00
|
|
|
p, expr->_type_unique_index);
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("sizeof(asn_DEF_%s_tags_%d)\n",
|
2005-03-04 08:48:53 +00:00
|
|
|
p, expr->_type_unique_index);
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("\t/sizeof(asn_DEF_%s_tags_%d[0])",
|
2005-03-04 08:48:53 +00:00
|
|
|
p, expr->_type_unique_index);
|
2004-09-13 08:31:01 +00:00
|
|
|
if(tv_mode == _TVM_SUBSET
|
|
|
|
&& tags_count != all_tags_count)
|
|
|
|
OUT(" - %d", all_tags_count - tags_count);
|
|
|
|
OUT(", /* %d */\n", tags_count);
|
|
|
|
} else {
|
|
|
|
OUT("0,\t/* No effective tags (pointer) */\n");
|
|
|
|
OUT("0,\t/* No effective tags (count) */\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(all_tags_count && tv_mode == _TVM_DIFFERENT) {
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("asn_DEF_%s_all_tags_%d,\n",
|
2005-03-04 08:48:53 +00:00
|
|
|
p, expr->_type_unique_index);
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("sizeof(asn_DEF_%s_all_tags_%d)\n",
|
2005-03-04 08:48:53 +00:00
|
|
|
p, expr->_type_unique_index);
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("\t/sizeof(asn_DEF_%s_all_tags_%d[0]), /* %d */\n",
|
2005-03-04 08:48:53 +00:00
|
|
|
p, expr->_type_unique_index, all_tags_count);
|
2004-09-13 08:31:01 +00:00
|
|
|
} else if(all_tags_count) {
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("asn_DEF_%s_tags_%d,\t/* Same as above */\n",
|
2005-03-04 08:48:53 +00:00
|
|
|
p, expr->_type_unique_index);
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("sizeof(asn_DEF_%s_tags_%d)\n",
|
2005-03-04 08:48:53 +00:00
|
|
|
p, expr->_type_unique_index);
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("\t/sizeof(asn_DEF_%s_tags_%d[0]), /* %d */\n",
|
2005-03-04 08:48:53 +00:00
|
|
|
p, expr->_type_unique_index, all_tags_count);
|
2004-08-25 02:03:12 +00:00
|
|
|
} else {
|
2004-09-13 08:31:01 +00:00
|
|
|
OUT("0,\t/* No tags (pointer) */\n");
|
|
|
|
OUT("0,\t/* No tags (count) */\n");
|
2004-08-25 02:03:12 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 10:59:52 +00:00
|
|
|
if(arg->flags & A1C_GEN_OER) {
|
|
|
|
if(expr->constraints
|
|
|
|
|| expr->expr_type == ASN_BASIC_ENUMERATED
|
|
|
|
|| expr->expr_type == ASN_CONSTR_CHOICE) {
|
|
|
|
OUT("&asn_OER_type_%s_constr_%d,\n",
|
|
|
|
p, expr->_type_unique_index);
|
|
|
|
} else {
|
|
|
|
OUT("0,\t/* No OER visible constraints */\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
OUT("0,\t/* No OER visible constraints */\n");
|
|
|
|
}
|
|
|
|
|
2005-11-26 11:25:14 +00:00
|
|
|
if(arg->flags & A1C_GEN_PER) {
|
|
|
|
if(expr->constraints
|
|
|
|
|| expr->expr_type == ASN_BASIC_ENUMERATED
|
|
|
|
|| expr->expr_type == ASN_CONSTR_CHOICE) {
|
2006-10-09 12:27:44 +00:00
|
|
|
OUT("&asn_PER_type_%s_constr_%d,\n",
|
2005-11-26 11:25:14 +00:00
|
|
|
p, expr->_type_unique_index);
|
|
|
|
} else {
|
|
|
|
OUT("0,\t/* No PER visible constraints */\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
OUT("0,\t/* No PER visible constraints */\n");
|
|
|
|
}
|
|
|
|
|
2016-05-16 05:50:09 +00:00
|
|
|
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));
|
|
|
|
}
|
2004-08-25 02:03:12 +00:00
|
|
|
} else {
|
2016-05-16 05:50:09 +00:00
|
|
|
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);
|
|
|
|
}
|
2004-08-25 02:03:12 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(expr_elements_count(arg, expr))
|
|
|
|
OUT("0, 0,\t/* Defined elsewhere */\n");
|
|
|
|
else
|
|
|
|
OUT("0, 0,\t/* No members */\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(spec) {
|
|
|
|
case ETD_NO_SPECIFICS:
|
2016-05-16 05:50:09 +00:00
|
|
|
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");
|
|
|
|
}
|
2004-08-25 02:03:12 +00:00
|
|
|
break;
|
|
|
|
case ETD_HAS_SPECIFICS:
|
2005-11-26 11:25:14 +00:00
|
|
|
OUT("&asn_SPC_%s_specs_%d\t/* Additional specs */\n",
|
2005-03-04 08:48:53 +00:00
|
|
|
p, expr->_type_unique_index);
|
2004-08-25 02:03:12 +00:00
|
|
|
}
|
2004-09-13 08:31:01 +00:00
|
|
|
INDENT(-1);
|
2004-08-25 02:03:12 +00:00
|
|
|
OUT("};\n");
|
|
|
|
OUT("\n");
|
2004-08-26 06:20:34 +00:00
|
|
|
|
|
|
|
return 0;
|
2004-08-25 02:03:12 +00:00
|
|
|
}
|
2004-09-10 09:18:20 +00:00
|
|
|
|
2004-09-22 16:06:28 +00:00
|
|
|
static int
|
|
|
|
expr_as_xmlvaluelist(arg_t *arg, asn1p_expr_t *expr) {
|
2005-11-08 03:06:16 +00:00
|
|
|
/*
|
|
|
|
* X.680, 25.5, Table 5
|
|
|
|
*/
|
2005-11-26 11:25:14 +00:00
|
|
|
switch(expr_get_type(arg, expr)) {
|
2004-09-22 16:06:28 +00:00
|
|
|
case ASN_BASIC_BOOLEAN:
|
|
|
|
case ASN_BASIC_ENUMERATED:
|
|
|
|
case ASN_BASIC_NULL:
|
|
|
|
return 1;
|
2005-11-08 03:06:16 +00:00
|
|
|
case ASN_CONSTR_CHOICE:
|
|
|
|
return 2;
|
2004-09-22 16:06:28 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2005-01-28 12:18:50 +00:00
|
|
|
|
|
|
|
static int
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(arg_t *arg, enum onc_flags onc_flags) {
|
2005-01-28 12:18:50 +00:00
|
|
|
asn1p_expr_t *expr = arg->expr;
|
|
|
|
char *id;
|
|
|
|
|
2005-08-14 15:03:31 +00:00
|
|
|
if((arg->flags & A1C_COMPOUND_NAMES
|
|
|
|
|| onc_flags & ONC_force_compound_name)
|
2005-03-04 08:48:53 +00:00
|
|
|
&& ((expr->expr_type & ASN_CONSTR_MASK)
|
|
|
|
|| expr->expr_type == ASN_BASIC_ENUMERATED
|
2005-08-13 23:51:47 +00:00
|
|
|
|| ((expr->expr_type == ASN_BASIC_INTEGER
|
|
|
|
|| expr->expr_type == ASN_BASIC_BIT_STRING)
|
2005-03-04 08:48:53 +00:00
|
|
|
&& expr_elements_count(arg, expr))
|
|
|
|
)
|
2017-06-28 17:34:23 +00:00
|
|
|
&& expr->parent_expr) {
|
|
|
|
|
2005-01-28 12:18:50 +00:00
|
|
|
arg_t tmparg = *arg;
|
|
|
|
|
|
|
|
tmparg.expr = expr->parent_expr;
|
2005-03-04 08:48:53 +00:00
|
|
|
if(0) tmparg.flags &= ~A1C_COMPOUND_NAMES;
|
|
|
|
|
2005-08-14 15:03:31 +00:00
|
|
|
out_name_chain(&tmparg, onc_flags);
|
2005-01-28 12:18:50 +00:00
|
|
|
|
2017-06-28 17:34:23 +00:00
|
|
|
if(expr->parent_expr->Identifier) OUT("__"); /* a separator between id components */
|
2005-03-04 08:48:53 +00:00
|
|
|
|
2005-01-28 12:18:50 +00:00
|
|
|
/* Fall through */
|
|
|
|
}
|
|
|
|
|
2005-08-14 15:03:31 +00:00
|
|
|
if(onc_flags & ONC_avoid_keywords)
|
2006-03-21 03:40:38 +00:00
|
|
|
id = MKID_safe(expr);
|
2005-01-28 12:18:50 +00:00
|
|
|
else
|
2006-03-21 03:40:38 +00:00
|
|
|
id = MKID(expr);
|
2005-01-28 12:18:50 +00:00
|
|
|
OUT("%s", id);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2005-08-18 13:38:19 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
emit_include_dependencies(arg_t *arg) {
|
|
|
|
asn1p_expr_t *expr = arg->expr;
|
|
|
|
asn1p_expr_t *memb;
|
|
|
|
|
|
|
|
/* Avoid recursive definitions. */
|
|
|
|
TQ_FOR(memb, &(expr->members), next) {
|
|
|
|
expr_break_recursion(arg, memb);
|
|
|
|
}
|
|
|
|
|
|
|
|
TQ_FOR(memb, &(expr->members), next) {
|
|
|
|
|
|
|
|
if(memb->marker.flags & (EM_INDIRECT | EM_UNRECURSE)) {
|
|
|
|
if(terminal_structable(arg, memb)) {
|
|
|
|
int saved_target = arg->target->target;
|
2016-06-05 16:23:16 +00:00
|
|
|
if(saved_target != OT_FWD_DECLS) {
|
|
|
|
REDIR(OT_FWD_DECLS);
|
|
|
|
OUT("%s;\n",
|
|
|
|
asn1c_type_name(arg, memb, TNF_RSAFE));
|
|
|
|
}
|
2005-08-18 13:38:19 +00:00
|
|
|
REDIR(saved_target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if((!(memb->expr_type & ASN_CONSTR_MASK)
|
|
|
|
&& memb->expr_type > ASN_CONSTR_MASK)
|
|
|
|
|| memb->meta_type == AMT_TYPEREF) {
|
|
|
|
if(memb->marker.flags & EM_UNRECURSE) {
|
|
|
|
GEN_POSTINCLUDE(asn1c_type_name(arg,
|
|
|
|
memb, TNF_INCLUDE));
|
|
|
|
} else {
|
|
|
|
GEN_INCLUDE(asn1c_type_name(arg,
|
|
|
|
memb, TNF_INCLUDE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if it is better to make this type indirectly accessed via
|
|
|
|
* a pointer.
|
|
|
|
* This may be the case for the following recursive definition:
|
|
|
|
* Type ::= CHOICE { member Type };
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
expr_break_recursion(arg_t *arg, asn1p_expr_t *expr) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if(expr->marker.flags & EM_UNRECURSE)
|
|
|
|
return 1; /* Already broken */
|
|
|
|
|
|
|
|
/* -findirect-choice compiles members of CHOICE as indirect pointers */
|
|
|
|
if((arg->flags & A1C_INDIRECT_CHOICE)
|
|
|
|
&& arg->expr->expr_type == ASN_CONSTR_CHOICE
|
2005-11-26 11:25:14 +00:00
|
|
|
&& (expr_get_type(arg, expr) & ASN_CONSTR_MASK)
|
2005-08-18 13:38:19 +00:00
|
|
|
) {
|
|
|
|
/* Break cross-reference */
|
|
|
|
expr->marker.flags |= EM_INDIRECT | EM_UNRECURSE;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((expr->marker.flags & EM_INDIRECT)
|
|
|
|
|| arg->expr->expr_type == ASN_CONSTR_SET_OF
|
|
|
|
|| arg->expr->expr_type == ASN_CONSTR_SEQUENCE_OF) {
|
|
|
|
if(terminal_structable(arg, expr)) {
|
|
|
|
expr->marker.flags |= EM_UNRECURSE;
|
|
|
|
|
|
|
|
if(arg->expr->expr_type == ASN_CONSTR_SET_OF
|
|
|
|
|| arg->expr->expr_type == ASN_CONSTR_SEQUENCE_OF) {
|
|
|
|
/* Don't put EM_INDIRECT even if recursion */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fall through */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look for recursive back-references */
|
|
|
|
ret = expr_defined_recursively(arg, expr);
|
|
|
|
switch(ret) {
|
|
|
|
case 2: /* Explicitly break the recursion */
|
|
|
|
case 1: /* Use safer typing */
|
|
|
|
expr->marker.flags |= EM_INDIRECT;
|
|
|
|
expr->marker.flags |= EM_UNRECURSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the type can be represented using simple `struct TYPE`.
|
|
|
|
*/
|
|
|
|
static asn1p_expr_t *
|
|
|
|
terminal_structable(arg_t *arg, asn1p_expr_t *expr) {
|
|
|
|
asn1p_expr_t *terminal = asn1f_find_terminal_type_ex(arg->asn, expr);
|
|
|
|
if(terminal
|
|
|
|
&& !terminal->parent_expr
|
|
|
|
&& (terminal->expr_type & ASN_CONSTR_MASK)) {
|
|
|
|
return terminal;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
asn1c_recurse(arg_t *arg, asn1p_expr_t *expr, int (*callback)(arg_t *arg, void *key), void *key) {
|
|
|
|
arg_t tmp = *arg;
|
|
|
|
int maxret = 0;
|
|
|
|
int ret;
|
|
|
|
|
2017-05-07 13:00:51 +00:00
|
|
|
if(expr->_mark & TM_RECURSION) return 0;
|
2005-08-18 13:38:19 +00:00
|
|
|
expr->_mark |= TM_RECURSION;
|
|
|
|
|
|
|
|
/* Invoke callback for every type going into recursion */
|
|
|
|
tmp.expr = expr;
|
|
|
|
maxret = callback(&tmp, key);
|
|
|
|
if(maxret <= 1) {
|
|
|
|
/*
|
|
|
|
* Recursively invoke myself and the callbacks.
|
|
|
|
*/
|
|
|
|
TQ_FOR(tmp.expr, &(expr->members), next) {
|
|
|
|
ret = asn1c_recurse(&tmp, tmp.expr, callback, key);
|
|
|
|
if(ret > maxret)
|
|
|
|
maxret = ret;
|
|
|
|
if(maxret > 1) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
expr->_mark &= ~TM_RECURSION;
|
|
|
|
return maxret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
check_is_refer_to(arg_t *arg, void *key) {
|
|
|
|
asn1p_expr_t *terminal = terminal_structable(arg, arg->expr);
|
|
|
|
if(terminal == key) {
|
|
|
|
if(arg->expr->marker.flags & EM_INDIRECT)
|
|
|
|
return 1; /* This is almost safe indirection */
|
|
|
|
return 2;
|
|
|
|
} else if(terminal) {
|
|
|
|
/* This might be N-step circular loop. Dive into it. */
|
|
|
|
return asn1c_recurse(arg, terminal, check_is_refer_to, key);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the possibly inner expression defined recursively.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
expr_defined_recursively(arg_t *arg, asn1p_expr_t *expr) {
|
|
|
|
asn1p_expr_t *terminal;
|
|
|
|
asn1p_expr_t *topmost;
|
|
|
|
|
|
|
|
/* If expression is top-level, there's no way it can be recursive. */
|
|
|
|
if(expr->parent_expr == 0) return 0;
|
|
|
|
if(expr->expr_type != A1TC_REFERENCE)
|
|
|
|
return 0; /* Basic types are never recursive */
|
|
|
|
|
|
|
|
terminal = terminal_structable(arg, expr);
|
|
|
|
if(!terminal) return 0; /* Terminal cannot be indirected */
|
|
|
|
|
|
|
|
/* Search for the parent container for the given expression */
|
|
|
|
topmost = expr;
|
|
|
|
while(topmost->parent_expr)
|
|
|
|
topmost = topmost->parent_expr;
|
|
|
|
|
|
|
|
/* Look inside the terminal type if it mentions the parent expression */
|
|
|
|
return asn1c_recurse(arg, terminal, check_is_refer_to, topmost);
|
|
|
|
}
|
2005-11-26 11:25:14 +00:00
|
|
|
|
|
|
|
struct canonical_map_element {
|
|
|
|
int eidx;
|
|
|
|
asn1p_expr_t *expr;
|
|
|
|
};
|
|
|
|
static int compar_cameo(const void *ap, const void *bp);
|
|
|
|
static arg_t *cameo_arg;
|
|
|
|
static int *
|
|
|
|
compute_canonical_members_order(arg_t *arg, int el_count) {
|
|
|
|
struct canonical_map_element *cmap;
|
|
|
|
int *rmap;
|
|
|
|
asn1p_expr_t *v;
|
|
|
|
int eidx = 0;
|
|
|
|
int ext_start = -1;
|
|
|
|
int nextmax = -1;
|
|
|
|
int already_sorted = 1;
|
|
|
|
|
|
|
|
cmap = calloc(el_count, sizeof *cmap);
|
|
|
|
assert(cmap);
|
|
|
|
|
|
|
|
TQ_FOR(v, &(arg->expr->members), next) {
|
|
|
|
if(v->expr_type != A1TC_EXTENSIBLE) {
|
|
|
|
cmap[eidx].eidx = eidx;
|
|
|
|
cmap[eidx].expr = v;
|
|
|
|
eidx++;
|
|
|
|
} else if(ext_start == -1)
|
|
|
|
ext_start = eidx;
|
|
|
|
}
|
|
|
|
|
|
|
|
cameo_arg = arg;
|
|
|
|
if(ext_start == -1) {
|
|
|
|
/* Sort the whole thing */
|
|
|
|
qsort(cmap, el_count, sizeof(*cmap), compar_cameo);
|
|
|
|
} else {
|
|
|
|
/* Sort root and extensions independently */
|
|
|
|
qsort(cmap, ext_start, sizeof(*cmap), compar_cameo);
|
|
|
|
qsort(cmap + ext_start, el_count - ext_start,
|
|
|
|
sizeof(*cmap), compar_cameo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* move data back to a simpler map */
|
|
|
|
rmap = calloc(el_count, sizeof *rmap);
|
|
|
|
assert(rmap);
|
|
|
|
for(eidx = 0; eidx < el_count; eidx++) {
|
|
|
|
rmap[eidx] = cmap[eidx].eidx;
|
|
|
|
if(rmap[eidx] <= nextmax)
|
|
|
|
already_sorted = 0;
|
|
|
|
else
|
|
|
|
nextmax = rmap[eidx];
|
|
|
|
}
|
|
|
|
free(cmap);
|
|
|
|
|
|
|
|
if(already_sorted) { free(rmap); rmap = 0; }
|
|
|
|
return rmap;
|
|
|
|
}
|
|
|
|
static int compar_cameo(const void *ap, const void *bp) {
|
|
|
|
const struct canonical_map_element *a = (const void *)ap;
|
|
|
|
const struct canonical_map_element *b = (const void *)bp;
|
|
|
|
struct asn1p_type_tag_s atag, btag;
|
|
|
|
arg_t *arg = cameo_arg;
|
|
|
|
|
|
|
|
if(asn1f_fetch_outmost_tag(arg->asn, a->expr->module, a->expr,
|
|
|
|
&atag, AFT_IMAGINARY_ANY | AFT_CANON_CHOICE))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if(asn1f_fetch_outmost_tag(arg->asn, b->expr->module, b->expr,
|
|
|
|
&btag, AFT_IMAGINARY_ANY | AFT_CANON_CHOICE))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if(atag.tag_class < btag.tag_class)
|
|
|
|
return -1;
|
|
|
|
if(atag.tag_class > btag.tag_class)
|
|
|
|
return 1;
|
|
|
|
if(atag.tag_value < btag.tag_value)
|
|
|
|
return -1;
|
|
|
|
if(atag.tag_value > btag.tag_value)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|