Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions libasn1compiler/asn1c_ioc.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,34 @@ emit_ioc_cell(arg_t *arg, struct asn1p_ioc_cell_s *cell) {
GEN_INCLUDE(asn1c_type_name(arg, cell->value, TNF_INCLUDE));
OUT("aioc__type, &asn_DEF_%s", MKID(cell->value));
} else if(cell->value->meta_type == AMT_TYPE) {
GEN_INCLUDE(asn1c_type_name(arg, cell->value, TNF_INCLUDE));
OUT("aioc__type, &asn_DEF_%s", asn1c_type_name(arg, cell->value, TNF_SAFE));
/*
* Handle anonymous SEQUENCE OF and SET OF types in IOC context.
* These need special handling because they don't have their own
* identifiers but need proper type descriptors.
*/
const char *type_name = asn1c_type_name(arg, cell->value, TNF_SAFE);
if(strcmp(type_name, "SEQUENCE_OF") == 0 || strcmp(type_name, "SET_OF") == 0) {
/*
* For anonymous SEQUENCE OF/SET OF types in IOC context,
* generate the proper type descriptor name based on the element type.
*/
const char *constructor = (cell->value->expr_type == ASN_CONSTR_SEQUENCE_OF)
? "SEQUENCE_OF" : "SET_OF";
asn1p_expr_t *element = TQ_FIRST(&(cell->value->members));
const char *element_name = "Member";

if(element && element->expr_type == A1TC_REFERENCE && element->reference) {
/* Get the referenced type name */
element_name = element->reference->components[
element->reference->comp_count - 1].name;
}

GEN_INCLUDE(asn1c_type_name(arg, cell->value, TNF_INCLUDE));
OUT("aioc__type, &asn_DEF_%s_%s_%d", constructor, element_name, cell->value->_type_unique_index);
} else {
GEN_INCLUDE(asn1c_type_name(arg, cell->value, TNF_INCLUDE));
OUT("aioc__type, &asn_DEF_%s", type_name);
}
} else {
return -1;
}
Expand Down Expand Up @@ -270,6 +296,32 @@ emit_ioc_table(arg_t *arg, asn1p_expr_t *context, asn1c_ioc_table_and_objset_t i
}
}

/* Generate forward declarations for anonymous SEQUENCE OF/SET OF types */
for(size_t rn = 0; rn < ioc_tao.ioct->rows; rn++) {
asn1p_ioc_row_t *row = ioc_tao.ioct->row[rn];
for(size_t cn = 0; cn < row->columns; cn++) {
struct asn1p_ioc_cell_s *cell = &row->column[cn];
if(cell->value && cell->value->meta_type == AMT_TYPE) {
const char *type_name = asn1c_type_name(arg, cell->value, TNF_SAFE);
if(strcmp(type_name, "SEQUENCE_OF") == 0 || strcmp(type_name, "SET_OF") == 0) {
const char *constructor = (cell->value->expr_type == ASN_CONSTR_SEQUENCE_OF)
? "SEQUENCE_OF" : "SET_OF";
Comment on lines +305 to +308
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

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

This code block duplicates the logic from lines 240-247. Consider extracting this into a helper function to avoid code duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

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

@copilot do the refactoring

asn1p_expr_t *element = TQ_FIRST(&(cell->value->members));
const char *element_name = "Member";

if(element && element->expr_type == A1TC_REFERENCE && element->reference) {
/* Get the referenced type name */
element_name = element->reference->components[
element->reference->comp_count - 1].name;
}

OUT("static asn_TYPE_descriptor_t asn_DEF_%s_%s_%d;\n",
constructor, element_name, cell->value->_type_unique_index);
}
}
}
}

if(ioc_tao.ioct->rows == 0)
return 0;

Expand Down
Loading