lib: commonize some precondition assertion macros
[babeltrace.git] / src / lib / trace-ir / field.h
index d6fe2bce53f77fc19abadec27d3ebe6448b75328..df303b662e379993eec73b6c923c49d4fa5a5acc 100644 (file)
@@ -1,30 +1,14 @@
-#ifndef BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H
-#define BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H
-
 /*
+ * SPDX-License-Identifier: MIT
+ *
  * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
  * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
  */
 
-#include "lib/assert-pre.h"
+#ifndef BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H
+#define BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H
+
+#include "lib/assert-cond.h"
 #include "common/common.h"
 #include "lib/object.h"
 #include "common/macros.h"
 #include "field-class.h"
 #include "utils.h"
 
-#define BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(_field, _cls_type, _name) \
-       BT_ASSERT_PRE_DEV(((const struct bt_field *) (_field))->class->type == (_cls_type), \
-               _name " has the wrong class type: expected-class-type=%s, " \
-               "%![field-]+f",                                         \
-               bt_common_field_class_type_string(_cls_type), (_field))
-
-#define BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(_field, _name)         \
-       BT_ASSERT_PRE_DEV(                                              \
-               ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \
-               ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, \
-               _name " is not an unsigned integer field: %![field-]+f", \
-               (_field))
-
-#define BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(_field, _name)           \
-       BT_ASSERT_PRE_DEV(                                              \
-               ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || \
-               ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, \
-               _name " is not a signed integer field: %![field-]+f",   \
-               (_field))
-
-#define BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(_field, _name)                        \
-       BT_ASSERT_PRE_DEV(                                              \
-               ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || \
-               ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY, \
-               _name " is not an array field: %![field-]+f", (_field))
-
-#define BT_ASSERT_PRE_DEV_FIELD_IS_OPTION(_field, _name)               \
-       BT_ASSERT_PRE_DEV(                                              \
-               ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR || \
-               ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR || \
-               ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR || \
-               ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR, \
-               _name " is not an option field: %![field-]+f", (_field))
-
-#define BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(_field, _name)              \
-       BT_ASSERT_PRE_DEV(                                              \
-               ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR || \
-               ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR || \
-               ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR, \
-               _name " is not a variant field: %![field-]+f", (_field))
-
-#define BT_ASSERT_PRE_DEV_FIELD_IS_SET(_field, _name)                  \
-       BT_ASSERT_PRE_DEV(bt_field_is_set(_field),                      \
-               _name " is not set: %!+f", (_field))
-
-#define BT_ASSERT_PRE_DEV_FIELD_HOT(_field, _name)                     \
-       BT_ASSERT_PRE_DEV_HOT((const struct bt_field *) (_field), (_name), \
-               ": %!+f", (_field))
-
 struct bt_field;
 
 typedef struct bt_field *(* bt_field_create_func)(struct bt_field_class *);
@@ -201,15 +136,15 @@ void _bt_field_set_is_frozen(const struct bt_field *field, bool is_frozen);
 static inline
 void _bt_field_reset(const struct bt_field *field)
 {
-       BT_ASSERT(field);
-       BT_ASSERT(field->methods->reset);
+       BT_ASSERT_DBG(field);
+       BT_ASSERT_DBG(field->methods->reset);
        field->methods->reset((void *) field);
 }
 
 static inline
 void _bt_field_set_single(struct bt_field *field, bool value)
 {
-       BT_ASSERT(field);
+       BT_ASSERT_DBG(field);
        field->is_set = value;
 }
 
@@ -222,7 +157,7 @@ bt_bool _bt_field_is_set(const struct bt_field *field)
                goto end;
        }
 
-       BT_ASSERT(field->methods->is_set);
+       BT_ASSERT_DBG(field->methods->is_set);
        is_set = field->methods->is_set(field);
 
 end:
This page took 0.024938 seconds and 4 git commands to generate.