sessiond: add a CTF 2-generating trace class visitor
[lttng-tools.git] / src / bin / lttng-sessiond / field.cpp
index 604092a3b86c9c5352a3ab3cd649f6ad77cc2312..4a7915e203b0fcf74a743b40b3503066dd61eaf8 100644 (file)
@@ -30,6 +30,18 @@ bool fields_are_equal(const FieldTypeSet& a, const FieldTypeSet& b)
 }
 } /* namespace */
 
+lst::field_location::field_location(lst::field_location::root in_lookup_root,
+               lst::field_location::elements in_elements) :
+       root_{in_lookup_root}, elements_{std::move(in_elements)}
+{
+}
+
+bool lst::field_location::operator==(const lst::field_location& other) const noexcept
+{
+       return root_ == other.root_ &&
+                       elements_ == other.elements_;
+}
+
 lst::type::type(unsigned int in_alignment) : alignment{in_alignment}
 {
 }
@@ -54,6 +66,9 @@ bool lst::type::operator!=(const lst::type& other) const noexcept
 lst::field::field(std::string in_name, lst::type::cuptr in_type) :
        name{std::move(in_name)}, _type{std::move(in_type)}
 {
+       if (!_type) {
+               LTTNG_THROW_ERROR(fmt::format("Invalid type used to create field: field name = `{}`", name));
+       }
 }
 
 void lst::field::accept(lst::field_visitor& visitor) const
@@ -66,16 +81,32 @@ bool lst::field::operator==(const lst::field& other) const noexcept
        return name == other.name && *_type == *other._type;
 }
 
+lst::type::cuptr lst::field::move_type() noexcept
+{
+       return std::move(_type);
+}
+
+const lst::type &lst::field::get_type() const
+{
+       if (_type) {
+               return *_type;
+       } else {
+               LTTNG_THROW_ERROR(fmt::format("Invalid attempt to access field type after transfer: field name = `{}`", name));
+       }
+}
+
 lst::integer_type::integer_type(unsigned int in_alignment,
                enum lst::byte_order in_byte_order,
                unsigned int in_size,
                enum lst::integer_type::signedness in_signedness,
-               enum lst::integer_type::base in_base) :
+               enum lst::integer_type::base in_base,
+               roles in_roles) :
        type(in_alignment),
        byte_order{in_byte_order},
        size{in_size},
        signedness_{in_signedness},
-       base_{in_base}
+       base_{in_base},
+       roles_{std::move(in_roles)}
 {
 }
 
@@ -86,7 +117,8 @@ bool lst::integer_type::_is_equal(const type &base_other) const noexcept
        return this->byte_order == other.byte_order &&
                this->size == other.size &&
                this->signedness_ == other.signedness_ &&
-               this->base_ == other.base_;
+               this->base_ == other.base_ &&
+               this->roles_ == other.roles_;
 }
 
 void lst::integer_type::accept(type_visitor& visitor) const
@@ -148,8 +180,14 @@ lst::enumeration_type::enumeration_type(unsigned int in_alignment,
                enum lst::byte_order in_byte_order,
                unsigned int in_size,
                enum signedness in_signedness,
-               enum base in_base) :
-       integer_type(in_alignment, in_byte_order, in_size, in_signedness, in_base)
+               enum base in_base,
+               lst::integer_type::roles in_roles) :
+       integer_type(in_alignment,
+                       in_byte_order,
+                       in_size,
+                       in_signedness,
+                       in_base,
+                       std::move(in_roles))
 {
 }
 
@@ -171,6 +209,20 @@ void lst::unsigned_enumeration_type::accept(type_visitor& visitor) const
 } /* namespace sessiond */
 } /* namespace lttng */
 
+template <>
+void lst::variant_type<lst::signed_enumeration_type::mapping::range_t::range_integer_t>::accept(
+               lst::type_visitor& visitor) const
+{
+       visitor.visit(*this);
+}
+
+template <>
+void lst::variant_type<lst::unsigned_enumeration_type::mapping::range_t::range_integer_t>::accept(
+               lst::type_visitor& visitor) const
+{
+       visitor.visit(*this);
+}
+
 lst::array_type::array_type(unsigned int in_alignment, type::cuptr in_element_type) :
        type(in_alignment), element_type{std::move(in_element_type)}
 {
@@ -205,9 +257,9 @@ void lst::static_length_array_type::accept(type_visitor& visitor) const
 
 lst::dynamic_length_array_type::dynamic_length_array_type(unsigned int in_alignment,
                type::cuptr in_element_type,
-               std::string in_length_field_name) :
+               lst::field_location in_length_field_location) :
        array_type(in_alignment, std::move(in_element_type)),
-       length_field_name{std::move(in_length_field_name)}
+       length_field_location{std::move(in_length_field_location)}
 {
 }
 
@@ -216,7 +268,7 @@ bool lst::dynamic_length_array_type::_is_equal(const type& base_other) const noe
        const auto& other = static_cast<decltype(*this)&>(base_other);
 
        return array_type::_is_equal(base_other) &&
-                       this->length_field_name == other.length_field_name;
+                       this->length_field_location == other.length_field_location;
 }
 
 void lst::dynamic_length_array_type::accept(type_visitor& visitor) const
@@ -224,6 +276,42 @@ void lst::dynamic_length_array_type::accept(type_visitor& visitor) const
        visitor.visit(*this);
 }
 
+lst::static_length_blob_type::static_length_blob_type(
+               unsigned int in_alignment, uint64_t in_length_bytes, roles in_roles) :
+       type(in_alignment), length_bytes{in_length_bytes}, roles_{std::move(in_roles)}
+{
+}
+
+bool lst::static_length_blob_type::_is_equal(const type& base_other) const noexcept
+{
+       const auto& other = static_cast<decltype(*this)&>(base_other);
+
+       return length_bytes == other.length_bytes && roles_ == other.roles_;
+}
+
+void lst::static_length_blob_type::accept(type_visitor& visitor) const
+{
+       visitor.visit(*this);
+}
+
+lst::dynamic_length_blob_type::dynamic_length_blob_type(
+               unsigned int in_alignment, lst::field_location in_length_field_location) :
+       type(in_alignment), length_field_location{std::move(in_length_field_location)}
+{
+}
+
+bool lst::dynamic_length_blob_type::_is_equal(const type& base_other) const noexcept
+{
+       const auto& other = dynamic_cast<decltype(*this)&>(base_other);
+
+       return length_field_location == other.length_field_location;
+}
+
+void lst::dynamic_length_blob_type::accept(type_visitor& visitor) const
+{
+       visitor.visit(*this);
+}
+
 lst::string_type::string_type(unsigned int in_alignment, enum encoding in_encoding) :
        type(in_alignment), encoding_{in_encoding}
 {
@@ -256,8 +344,9 @@ void lst::static_length_string_type::accept(type_visitor& visitor) const
 
 lst::dynamic_length_string_type::dynamic_length_string_type(unsigned int in_alignment,
                enum encoding in_encoding,
-               std::string in_length_field_name) :
-       string_type(in_alignment, in_encoding), length_field_name{std::move(in_length_field_name)}
+               field_location in_length_field_location) :
+       string_type(in_alignment, in_encoding),
+       length_field_location{std::move(in_length_field_location)}
 {
 }
 
@@ -266,7 +355,7 @@ bool lst::dynamic_length_string_type::_is_equal(const type& base_other) const no
        const auto& other = static_cast<decltype(*this)&>(base_other);
 
        return string_type::_is_equal(base_other) &&
-                       this->length_field_name == other.length_field_name;
+                       this->length_field_location == other.length_field_location;
 }
 
 void lst::dynamic_length_string_type::accept(type_visitor& visitor) const
@@ -286,7 +375,7 @@ void lst::null_terminated_string_type::accept(type_visitor& visitor) const
 }
 
 lst::structure_type::structure_type(unsigned int in_alignment, fields in_fields) :
-       type(in_alignment), _fields{std::move(in_fields)}
+       type(in_alignment), fields_{std::move(in_fields)}
 {
 }
 
@@ -294,32 +383,10 @@ bool lst::structure_type::_is_equal(const type& base_other) const noexcept
 {
        const auto &other = static_cast<decltype(*this)&>(base_other);
 
-       return fields_are_equal(this->_fields, other._fields);
+       return fields_are_equal(this->fields_, other.fields_);
 }
 
 void lst::structure_type::accept(type_visitor& visitor) const
 {
        visitor.visit(*this);
-}
-
-lst::variant_type::variant_type(unsigned int in_alignment,
-               std::string in_tag_name,
-               choices in_choices) :
-       type(in_alignment),
-       tag_name{std::move(in_tag_name)},
-       _choices{std::move(in_choices)}
-{
-}
-
-bool lst::variant_type::_is_equal(const type& base_other) const noexcept
-{
-       const auto &other = static_cast<decltype(*this)&>(base_other);
-
-       return this->tag_name == other.tag_name &&
-                       fields_are_equal(this->_choices, other._choices);
-}
-
-void lst::variant_type::accept(type_visitor& visitor) const
-{
-       visitor.visit(*this);
-}
+}
\ No newline at end of file
This page took 0.026672 seconds and 4 git commands to generate.