Add static type attributes
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 18 Oct 2022 14:07:12 +0000 (10:07 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 18 Oct 2022 14:07:12 +0000 (10:07 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/side/trace.h
src/test.c

index baac5f4f24a88513b1ac0ea4844d96964cf02090..1d2eebc67465d1da5845643f7750c2f64a5c0065 100644 (file)
@@ -121,7 +121,8 @@ struct side_attr {
 
 struct side_type_description {
        uint32_t type;  /* enum side_type */
-       //TODO: we should add something like a list of user attributes (namespaced strings)
+       uint32_t nr_attr;
+       const struct side_attr *attr;
        union {
                struct {
                        uint32_t nr_fields;
@@ -276,17 +277,24 @@ struct side_tracer_dynamic_vla_visitor_ctx {
 #define side_attr_list(...) \
        SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
 
-#define side_type_decl(_type)          { .type = _type }
+#define side_type_decl(_type, _attr) \
+       { \
+               .type = _type, \
+               .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
+               .attr = _attr, \
+       }
 
-#define side_field(_name, _type) \
+#define side_field(_name, _type, _attr) \
        { \
                .field_name = _name, \
-               .side_type = side_type_decl(_type), \
+               .side_type = side_type_decl(_type, SIDE_PARAM(_attr)), \
        }
 
-#define side_type_struct_decl(_fields) \
+#define side_type_struct_decl(_fields, _attr) \
        { \
                .type = SIDE_TYPE_STRUCT, \
+               .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
+               .attr = _attr, \
                .u = { \
                        .side_struct = { \
                                .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
@@ -294,15 +302,17 @@ struct side_tracer_dynamic_vla_visitor_ctx {
                        }, \
                }, \
        }
-#define side_field_struct(_name, _fields) \
+#define side_field_struct(_name, _fields, _attr) \
        { \
                .field_name = _name, \
-               .side_type = side_type_struct_decl(SIDE_PARAM(_fields)), \
+               .side_type = side_type_struct_decl(SIDE_PARAM(_fields), SIDE_PARAM(_attr)), \
        }
 
-#define side_type_array_decl(_elem_type, _length) \
+#define side_type_array_decl(_elem_type, _length, _attr) \
        { \
                .type = SIDE_TYPE_ARRAY, \
+               .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
+               .attr = _attr, \
                .u = { \
                        .side_array = { \
                                .length = _length, \
@@ -310,30 +320,34 @@ struct side_tracer_dynamic_vla_visitor_ctx {
                        }, \
                }, \
        }
-#define side_field_array(_name, _elem_type, _length) \
+#define side_field_array(_name, _elem_type, _length, _attr) \
        { \
                .field_name = _name, \
-               .side_type = side_type_array_decl(_elem_type, _length), \
+               .side_type = side_type_array_decl(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)), \
        }
 
-#define side_type_vla_decl(_elem_type) \
+#define side_type_vla_decl(_elem_type, _attr) \
        { \
                .type = SIDE_TYPE_VLA, \
+               .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
+               .attr = _attr, \
                .u = { \
                        .side_vla = { \
                                .elem_type = _elem_type, \
                        }, \
                }, \
        }
-#define side_field_vla(_name, _elem_type) \
+#define side_field_vla(_name, _elem_type, _attr) \
        { \
                .field_name = _name, \
-               .side_type = side_type_vla_decl(_elem_type), \
+               .side_type = side_type_vla_decl(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)), \
        }
 
-#define side_type_vla_visitor_decl(_elem_type, _visitor) \
+#define side_type_vla_visitor_decl(_elem_type, _visitor, _attr) \
        { \
                .type = SIDE_TYPE_VLA_VISITOR, \
+               .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
+               .attr = _attr, \
                .u = { \
                        .side_vla_visitor = { \
                                .elem_type = SIDE_PARAM(_elem_type), \
@@ -341,17 +355,17 @@ struct side_tracer_dynamic_vla_visitor_ctx {
                        }, \
                }, \
        }
-#define side_field_vla_visitor(_name, _elem_type, _visitor) \
+#define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
        { \
                .field_name = _name, \
-               .side_type = side_type_vla_visitor_decl(SIDE_PARAM(_elem_type), _visitor), \
+               .side_type = side_type_vla_visitor_decl(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)), \
        }
 
 #define side_elem(...) \
        SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
 
-#define side_elem_type(...) \
-       side_elem(side_type_decl(__VA_ARGS__))
+#define side_elem_type(_type, _attr) \
+       side_elem(side_type_decl(_type, SIDE_PARAM(_attr)))
 
 #define side_field_list(...) \
        SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
index 46847bb39a2068dd7278c97a5a8fed325d826258..0437d43d2eed4c4478016dd6383b8ed7f749ad46 100644 (file)
@@ -17,9 +17,9 @@
 static side_define_event(my_provider_event, "myprovider", "myevent", SIDE_LOGLEVEL_DEBUG,
        side_attr_list(),
        side_field_list(
-               side_field("abc", SIDE_TYPE_U32),
-               side_field("def", SIDE_TYPE_S64),
-               side_field("dynamic", SIDE_TYPE_DYNAMIC),
+               side_field("abc", SIDE_TYPE_U32, side_attr_list()),
+               side_field("def", SIDE_TYPE_S64, side_attr_list()),
+               side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
        )
 );
 
@@ -39,11 +39,12 @@ static side_define_event(my_provider_event2, "myprovider", "myevent2", SIDE_LOGL
        side_field_list(
                side_field_struct("structfield",
                        side_field_list(
-                               side_field("x", SIDE_TYPE_U32),
-                               side_field("y", SIDE_TYPE_S64),
-                       )
+                               side_field("x", SIDE_TYPE_U32, side_attr_list()),
+                               side_field("y", SIDE_TYPE_S64, side_attr_list()),
+                       ),
+                       side_attr_list()
                ),
-               side_field("z", SIDE_TYPE_U8),
+               side_field("z", SIDE_TYPE_U8, side_attr_list()),
        )
 );
 
@@ -60,8 +61,8 @@ void test_struct(void)
 static side_define_event(my_provider_event_array, "myprovider", "myarray", SIDE_LOGLEVEL_DEBUG,
        side_attr_list(),
        side_field_list(
-               side_field_array("arr", side_elem_type(SIDE_TYPE_U32), 3),
-               side_field("v", SIDE_TYPE_S64),
+               side_field_array("arr", side_elem_type(SIDE_TYPE_U32, side_attr_list()), 3, side_attr_list()),
+               side_field("v", SIDE_TYPE_S64, side_attr_list()),
        )
 );
 
@@ -78,8 +79,8 @@ void test_array(void)
 static side_define_event(my_provider_event_vla, "myprovider", "myvla", SIDE_LOGLEVEL_DEBUG,
        side_attr_list(),
        side_field_list(
-               side_field_vla("vla", side_elem_type(SIDE_TYPE_U32)),
-               side_field("v", SIDE_TYPE_S64),
+               side_field_vla("vla", side_elem_type(SIDE_TYPE_U32, side_attr_list()), side_attr_list()),
+               side_field("v", SIDE_TYPE_S64, side_attr_list()),
        )
 );
 
@@ -124,8 +125,8 @@ static uint32_t testarray[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
 static side_define_event(my_provider_event_vla_visitor, "myprovider", "myvlavisit", SIDE_LOGLEVEL_DEBUG,
        side_attr_list(),
        side_field_list(
-               side_field_vla_visitor("vlavisit", side_elem_type(SIDE_TYPE_U32), test_visitor),
-               side_field("v", SIDE_TYPE_S64),
+               side_field_vla_visitor("vlavisit", side_elem_type(SIDE_TYPE_U32, side_attr_list()), test_visitor, side_attr_list()),
+               side_field("v", SIDE_TYPE_S64, side_attr_list()),
        )
 );
 
@@ -201,8 +202,13 @@ static side_define_event(my_provider_event_vla_visitor2d, "myprovider", "myvlavi
        side_attr_list(),
        side_field_list(
                side_field_vla_visitor("vlavisit2d",
-                       side_elem(side_type_vla_visitor_decl(side_elem_type(SIDE_TYPE_U32), test_inner_visitor)), test_outer_visitor),
-               side_field("v", SIDE_TYPE_S64),
+                       side_elem(
+                               side_type_vla_visitor_decl(
+                                       side_elem_type(SIDE_TYPE_U32, side_attr_list()),
+                                       test_inner_visitor,
+                                       side_attr_list())
+                       ), test_outer_visitor, side_attr_list()),
+               side_field("v", SIDE_TYPE_S64, side_attr_list()),
        )
 );
 
@@ -224,8 +230,8 @@ static int64_t array_fixint[] = { -444, 555, 123, 2897432587 };
 static side_define_event(my_provider_event_array_fixint, "myprovider", "myarrayfixint", SIDE_LOGLEVEL_DEBUG,
        side_attr_list(),
        side_field_list(
-               side_field_array("arrfixint", side_elem_type(SIDE_TYPE_S64), SIDE_ARRAY_SIZE(array_fixint)),
-               side_field("v", SIDE_TYPE_S64),
+               side_field_array("arrfixint", side_elem_type(SIDE_TYPE_S64, side_attr_list()), SIDE_ARRAY_SIZE(array_fixint), side_attr_list()),
+               side_field("v", SIDE_TYPE_S64, side_attr_list()),
        )
 );
 
@@ -242,8 +248,8 @@ static int64_t vla_fixint[] = { -444, 555, 123, 2897432587 };
 static side_define_event(my_provider_event_vla_fixint, "myprovider", "myvlafixint", SIDE_LOGLEVEL_DEBUG,
        side_attr_list(),
        side_field_list(
-               side_field_vla("vlafixint", side_elem_type(SIDE_TYPE_S64)),
-               side_field("v", SIDE_TYPE_S64),
+               side_field_vla("vlafixint", side_elem_type(SIDE_TYPE_S64, side_attr_list()), side_attr_list()),
+               side_field("v", SIDE_TYPE_S64, side_attr_list()),
        )
 );
 
@@ -259,7 +265,7 @@ static side_define_event(my_provider_event_dynamic_basic,
        "myprovider", "mydynamicbasic", SIDE_LOGLEVEL_DEBUG,
        side_attr_list(),
        side_field_list(
-               side_field("dynamic", SIDE_TYPE_DYNAMIC),
+               side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
        )
 );
 
@@ -275,7 +281,7 @@ static side_define_event(my_provider_event_dynamic_vla,
        "myprovider", "mydynamicvla", SIDE_LOGLEVEL_DEBUG,
        side_attr_list(),
        side_field_list(
-               side_field("dynamic", SIDE_TYPE_DYNAMIC),
+               side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
        )
 );
 
@@ -296,7 +302,7 @@ static side_define_event(my_provider_event_dynamic_null,
        "myprovider", "mydynamicnull", SIDE_LOGLEVEL_DEBUG,
        side_attr_list(),
        side_field_list(
-               side_field("dynamic", SIDE_TYPE_DYNAMIC),
+               side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
        )
 );
 
@@ -312,7 +318,7 @@ static side_define_event(my_provider_event_dynamic_struct,
        "myprovider", "mydynamicstruct", SIDE_LOGLEVEL_DEBUG,
        side_attr_list(),
        side_field_list(
-               side_field("dynamic", SIDE_TYPE_DYNAMIC),
+               side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
        )
 );
 
@@ -336,7 +342,7 @@ static side_define_event(my_provider_event_dynamic_nested_struct,
        "myprovider", "mydynamicnestedstruct", SIDE_LOGLEVEL_DEBUG,
        side_attr_list(),
        side_field_list(
-               side_field("dynamic", SIDE_TYPE_DYNAMIC),
+               side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
        )
 );
 
@@ -370,7 +376,7 @@ static side_define_event(my_provider_event_dynamic_vla_struct,
        "myprovider", "mydynamicvlastruct", SIDE_LOGLEVEL_DEBUG,
        side_attr_list(),
        side_field_list(
-               side_field("dynamic", SIDE_TYPE_DYNAMIC),
+               side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
        )
 );
 
@@ -400,7 +406,7 @@ static side_define_event(my_provider_event_dynamic_struct_vla,
        "myprovider", "mydynamicstructvla", SIDE_LOGLEVEL_DEBUG,
        side_attr_list(),
        side_field_list(
-               side_field("dynamic", SIDE_TYPE_DYNAMIC),
+               side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
        )
 );
 
@@ -432,7 +438,7 @@ static side_define_event(my_provider_event_dynamic_nested_vla,
        "myprovider", "mydynamicnestedvla", SIDE_LOGLEVEL_DEBUG,
        side_attr_list(),
        side_field_list(
-               side_field("dynamic", SIDE_TYPE_DYNAMIC),
+               side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
        )
 );
 
@@ -483,8 +489,8 @@ static side_define_event_variadic(my_provider_event_static_variadic,
        "myprovider", "mystaticvariadicevent", SIDE_LOGLEVEL_DEBUG,
        side_attr_list(),
        side_field_list(
-               side_field("abc", SIDE_TYPE_U32),
-               side_field("def", SIDE_TYPE_U16),
+               side_field("abc", SIDE_TYPE_U32, side_attr_list()),
+               side_field("def", SIDE_TYPE_U16, side_attr_list()),
        )
 );
 
@@ -507,13 +513,13 @@ void test_static_variadic(void)
 static side_define_event(my_provider_event_bool, "myprovider", "myeventbool", SIDE_LOGLEVEL_DEBUG,
        side_attr_list(),
        side_field_list(
-               side_field("a_false", SIDE_TYPE_BOOL),
-               side_field("b_true", SIDE_TYPE_BOOL),
-               side_field("c_true", SIDE_TYPE_BOOL),
-               side_field("d_true", SIDE_TYPE_BOOL),
-               side_field("e_true", SIDE_TYPE_BOOL),
-               side_field("f_false", SIDE_TYPE_BOOL),
-               side_field("g_true", SIDE_TYPE_BOOL),
+               side_field("a_false", SIDE_TYPE_BOOL, side_attr_list()),
+               side_field("b_true", SIDE_TYPE_BOOL, side_attr_list()),
+               side_field("c_true", SIDE_TYPE_BOOL, side_attr_list()),
+               side_field("d_true", SIDE_TYPE_BOOL, side_attr_list()),
+               side_field("e_true", SIDE_TYPE_BOOL, side_attr_list()),
+               side_field("f_false", SIDE_TYPE_BOOL, side_attr_list()),
+               side_field("g_true", SIDE_TYPE_BOOL, side_attr_list()),
        )
 );
 
@@ -567,7 +573,7 @@ static side_define_event(my_provider_event_dynamic_vla_visitor,
        "myprovider", "mydynamicvlavisitor", SIDE_LOGLEVEL_DEBUG,
        side_attr_list(),
        side_field_list(
-               side_field("dynamic", SIDE_TYPE_DYNAMIC),
+               side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
        )
 );
 
@@ -620,7 +626,7 @@ static side_define_event(my_provider_event_dynamic_struct_visitor,
        "myprovider", "mydynamicstructvisitor", SIDE_LOGLEVEL_DEBUG,
        side_attr_list(),
        side_field_list(
-               side_field("dynamic", SIDE_TYPE_DYNAMIC),
+               side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
        )
 );
 
@@ -688,8 +694,8 @@ static side_define_event(my_provider_event_user_attribute, "myprovider", "myeven
                side_attr("user_attribute_b", "val2"),
        ),
        side_field_list(
-               side_field("abc", SIDE_TYPE_U32),
-               side_field("def", SIDE_TYPE_S64),
+               side_field("abc", SIDE_TYPE_U32, side_attr_list()),
+               side_field("def", SIDE_TYPE_S64, side_attr_list()),
        )
 );
 
@@ -700,7 +706,6 @@ void test_event_user_attribute(void)
        side_event(&my_provider_event_user_attribute, side_arg_list(side_arg_u32(1), side_arg_s64(2)));
 }
 
-
 int main()
 {
        test_fields();
This page took 0.030609 seconds and 4 git commands to generate.