uint32_t nr_mappings;
};
+struct side_type_struct {
+ uint32_t nr_fields;
+ uint32_t nr_attr;
+ const struct side_event_field *fields;
+ const struct side_attr *attr;
+};
+
struct side_type_description {
uint32_t type; /* enum side_type */
uint32_t nr_attr;
const struct side_attr *attr;
union {
- struct {
- uint32_t nr_fields;
- const struct side_event_field *fields;
- } side_struct;
+ const struct side_type_struct *side_struct;
struct {
uint32_t length;
const struct side_type_description *elem_type;
#define side_field_enum_bitmap64(_name, _mappings, _attr) \
_side_field_enum_bitmap(_name, SIDE_TYPE_ENUM_BITMAP64, SIDE_PARAM(_mappings), SIDE_PARAM(_attr))
-#define side_type_struct(_fields, _attr) \
+#define side_type_struct(_struct) \
{ \
.type = SIDE_TYPE_STRUCT, \
- .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
- .attr = _attr, \
+ .nr_attr = 0, \
+ .attr = NULL, \
.u = { \
- .side_struct = { \
- .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
- .fields = _fields, \
- }, \
+ .side_struct = _struct, \
}, \
}
-#define side_field_struct(_name, _fields, _attr) \
- _side_field(_name, side_type_struct(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
+#define side_field_struct(_name, _struct) \
+ _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
+
+#define _side_type_struct_define(_fields, _attr) \
+ { \
+ .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
+ .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
+ .fields = _fields, \
+ .attr = _attr, \
+ }
+
+#define side_define_struct(_identifier, _fields, _attr) \
+ const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))
+
+#define side_struct_literal(_fields, _attr) \
+ SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
+ _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
#define side_type_array(_elem_type, _length, _attr) \
{ \
side_arg_dynamic(side_arg_dynamic_string("zzz", side_attr_list()))));
}
-static side_define_event(my_provider_event2, "myprovider", "myevent2", SIDE_LOGLEVEL_DEBUG,
+static side_define_event(my_provider_event_struct_literal, "myprovider", "myeventstructliteral", SIDE_LOGLEVEL_DEBUG,
side_field_list(
- side_field_struct("structfield",
- side_field_list(
- side_field_u32("x", side_attr_list()),
- side_field_s64("y", side_attr_list()),
- ),
- side_attr_list()
+ side_field_struct("structliteral",
+ side_struct_literal(
+ side_field_list(
+ side_field_u32("x", side_attr_list()),
+ side_field_s64("y", side_attr_list()),
+ ),
+ side_attr_list()
+ )
),
side_field_u8("z", side_attr_list()),
),
side_attr_list()
);
+static
+void test_struct_literal(void)
+{
+ my_provider_event_struct_literal_enabled = 1;
+ side_event_cond(my_provider_event_struct_literal) {
+ side_arg_define_vec(mystruct, side_arg_list(side_arg_u32(21), side_arg_s64(22)));
+ side_event_call(my_provider_event_struct_literal, side_arg_list(side_arg_struct(&mystruct), side_arg_u8(55)));
+ }
+}
+
+static side_define_struct(mystructdef,
+ side_field_list(
+ side_field_u32("x", side_attr_list()),
+ side_field_s64("y", side_attr_list()),
+ ),
+ side_attr_list()
+);
+
+static side_define_event(my_provider_event_struct, "myprovider", "myeventstruct", SIDE_LOGLEVEL_DEBUG,
+ side_field_list(
+ side_field_struct("struct", &mystructdef),
+ side_field_u8("z", side_attr_list()),
+ ),
+ side_attr_list()
+);
+
static
void test_struct(void)
{
- my_provider_event2_enabled = 1;
- side_event_cond(my_provider_event2) {
+ my_provider_event_struct_enabled = 1;
+ side_event_cond(my_provider_event_struct) {
side_arg_define_vec(mystruct, side_arg_list(side_arg_u32(21), side_arg_s64(22)));
- side_event_call(my_provider_event2, side_arg_list(side_arg_struct(&mystruct), side_arg_u8(55)));
+ side_event_call(my_provider_event_struct, side_arg_list(side_arg_struct(&mystruct), side_arg_u8(55)));
}
}
int main()
{
test_fields();
+ test_struct_literal();
test_struct();
test_array();
test_vla();
uint32_t side_sav_len = sav_desc->len;
int i;
- if (type_desc->u.side_struct.nr_fields != side_sav_len) {
+ if (type_desc->u.side_struct->nr_fields != side_sav_len) {
printf("ERROR: number of fields mismatch between description and arguments of structure\n");
abort();
}
printf("{ ");
for (i = 0; i < side_sav_len; i++) {
printf("%s", i ? ", " : "");
- tracer_print_field(&type_desc->u.side_struct.fields[i], &sav[i]);
+ tracer_print_field(&type_desc->u.side_struct->fields[i], &sav[i]);
}
printf(" }");
}