Rename: type_class, type -> type, declaration
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 27 Feb 2011 15:29:21 +0000 (10:29 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 27 Feb 2011 15:29:21 +0000 (10:29 -0500)
Fits better with the parser semantic.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
20 files changed:
formats/ctf/types/array.c
formats/ctf/types/enum.c
formats/ctf/types/float.c
formats/ctf/types/integer.c
formats/ctf/types/sequence.c
formats/ctf/types/string.c
formats/ctf/types/struct.c
formats/ctf/types/variant.c
include/babeltrace/ctf/types.h
include/babeltrace/format.h
include/babeltrace/types.h
types/array.c
types/enum.c
types/float.c
types/integer.c
types/sequence.c
types/string.c
types/struct.c
types/types.c
types/variant.c

index e6a2aa6c127eedcca00c3df6a4cfb888a1e7edf0..64d889e01d3867da6ed2820c61f8c79f060990b7 100644 (file)
 #include <babeltrace/ctf/types.h>
 
 void ctf_array_begin(struct stream_pos *pos,
-                    const struct type_class_array *array_class)
+                    const struct type_array *array_type)
 {
        /* No need to align, because the first field will align itself. */
 }
 
 void ctf_array_end(struct stream_pos *pos,
-                  const struct type_class_array *array_class)
+                  const struct type_array *array_type)
 {
 }
index 6243345140d1b5b196278daf80f3a3d447857d87..d0b284e67598c1474e09529689f19fb88677cc6f 100644 (file)
  * The caller should unref the GArray.
  */
 GArray *ctf_enum_read(struct stream_pos *pos,
-                     const struct type_class_enum *src)
+                     const struct type_enum *src)
 {
-       const struct type_class_integer *int_class = &src->p;
+       const struct type_integer *integer_type = src->integer_type;
 
-       if (!int_class->signedness) {
+       if (!integer_type->signedness) {
                uint64_t v;
 
-               v = ctf_uint_read(pos, int_class);
+               v = ctf_uint_read(pos, integer_type);
                return enum_uint_to_quark_set(src, v);
        } else {
                int64_t v;
 
-               v = ctf_int_read(pos, int_class);
+               v = ctf_int_read(pos, integer_type);
                return enum_int_to_quark_set(src, v);
        }
 }
@@ -45,20 +45,20 @@ GArray *ctf_enum_read(struct stream_pos *pos,
  * Arbitrarily choose the start of the first matching range.
  */
 void ctf_enum_write(struct stream_pos *pos,
-                   const struct type_class_enum *dest,
+                   const struct type_enum *dest,
                    GQuark q)
 {
-       const struct type_class_integer *int_class = &dest->p;
+       const struct type_integer *integer_type = dest->integer_type;
        GArray *array;
 
        array = enum_quark_to_range_set(dest, q);
        assert(array);
 
-       if (!int_class->signedness) {
+       if (!integer_type->signedness) {
                uint64_t v = g_array_index(array, struct enum_range, 0).start._unsigned;
-               ctf_uint_write(pos, int_class, v);
+               ctf_uint_write(pos, integer_type, v);
        } else {
                int64_t v = g_array_index(array, struct enum_range, 0).start._unsigned;
-               ctf_int_write(pos, int_class, v);
+               ctf_int_write(pos, integer_type, v);
        }
 }
index 000bc18361f2a081abcb2f7aa7825f3b1daafef2..f15c2856001f608cde70c093af8f77e7e9779786 100644 (file)
@@ -69,68 +69,68 @@ struct pos_len {
 };
 
 void _ctf_float_copy(struct stream_pos *destp,
-                    const struct type_class_float *dest_class,
+                    const struct type_float *dest_type,
                     struct stream_pos *srcp,
-                    const struct type_class_float *src_class)
+                    const struct type_float *src_type)
 {
        uint8_t sign;
        int64_t exp;
        uint64_t mantissa;
 
        /* Read */
-       if (src_class->byte_order == LITTLE_ENDIAN) {
-               mantissa = ctf_uint_read(srcp, src_class->mantissa);
-               exp = ctf_int_read(srcp, src_class->exp);
-               sign = ctf_uint_read(srcp, src_class->sign);
+       if (src_type->byte_order == LITTLE_ENDIAN) {
+               mantissa = ctf_uint_read(srcp, src_type->mantissa);
+               exp = ctf_int_read(srcp, src_type->exp);
+               sign = ctf_uint_read(srcp, src_type->sign);
        } else {
-               sign = ctf_uint_read(srcp, src_class->sign);
-               exp = ctf_int_read(srcp, src_class->exp);
-               mantissa = ctf_uint_read(srcp, src_class->mantissa);
+               sign = ctf_uint_read(srcp, src_type->sign);
+               exp = ctf_int_read(srcp, src_type->exp);
+               mantissa = ctf_uint_read(srcp, src_type->mantissa);
        }
        /* Write */
-       if (dest_class->byte_order == LITTLE_ENDIAN) {
-               ctf_uint_write(destp, dest_class->mantissa, mantissa);
-               ctf_int_write(destp, dest_class->exp, exp);
-               ctf_uint_write(destp, dest_class->sign, sign);
+       if (dest_type->byte_order == LITTLE_ENDIAN) {
+               ctf_uint_write(destp, dest_type->mantissa, mantissa);
+               ctf_int_write(destp, dest_type->exp, exp);
+               ctf_uint_write(destp, dest_type->sign, sign);
        } else {
-               ctf_uint_write(destp, dest_class->sign, sign);
-               ctf_int_write(destp, dest_class->exp, exp);
-               ctf_uint_write(destp, dest_class->mantissa, mantissa);
+               ctf_uint_write(destp, dest_type->sign, sign);
+               ctf_int_write(destp, dest_type->exp, exp);
+               ctf_uint_write(destp, dest_type->mantissa, mantissa);
        }
 }
 
 void ctf_float_copy(struct stream_pos *dest, struct stream_pos *src,
-                   const struct type_class_float *float_class)
+                   const struct type_float *float_type)
 {
-       align_pos(src, float_class->p.alignment);
-       align_pos(dest, float_class->p.alignment);
-       _ctf_float_copy(dest, float_class, src, float_class);
+       align_pos(src, float_type->p.alignment);
+       align_pos(dest, float_type->p.alignment);
+       _ctf_float_copy(dest, float_type, src, float_type);
 }
 
 double ctf_double_read(struct stream_pos *srcp,
-                      const struct type_class_float *float_class)
+                      const struct type_float *float_type)
 {
        union doubleIEEE754 u;
-       struct type_class_float *dest_class = float_type_class_new(NULL,
+       struct type_float *dest_type = float_type_new(NULL,
                                DBL_MANT_DIG,
                                sizeof(double) * CHAR_BIT - DBL_MANT_DIG,
                                BYTE_ORDER,
                                __alignof__(double));
        struct stream_pos destp;
 
-       align_pos(srcp, float_class->p.alignment);
+       align_pos(srcp, float_type->p.alignment);
        init_pos(&destp, (char *) u.bits);
-       _ctf_float_copy(&destp, dest_class, srcp, float_class);
-       type_class_unref(&dest_class->p);
+       _ctf_float_copy(&destp, dest_type, srcp, float_type);
+       type_unref(&dest_type->p);
        return u.v;
 }
 
 void ctf_double_write(struct stream_pos *destp,
-                     const struct type_class_float *float_class,
+                     const struct type_float *float_type,
                      double v)
 {
        union doubleIEEE754 u;
-       struct type_class_float *src_class = float_type_class_new(NULL,
+       struct type_float *src_type = float_type_new(NULL,
                                DBL_MANT_DIG,
                                sizeof(double) * CHAR_BIT - DBL_MANT_DIG,
                                BYTE_ORDER,
@@ -138,36 +138,36 @@ void ctf_double_write(struct stream_pos *destp,
        struct stream_pos srcp;
 
        u.v = v;
-       align_pos(destp, float_class->p.alignment);
+       align_pos(destp, float_type->p.alignment);
        init_pos(&srcp, (char *) u.bits);
-       _ctf_float_copy(destp, float_class, &srcp, src_class);
-       type_class_unref(&src_class->p);
+       _ctf_float_copy(destp, float_type, &srcp, src_type);
+       type_unref(&src_type->p);
 }
 
 long double ctf_ldouble_read(struct stream_pos *srcp,
-                            const struct type_class_float *float_class)
+                            const struct type_float *float_type)
 {
        union ldoubleIEEE754 u;
-       struct type_class_float *dest_class = float_type_class_new(NULL,
+       struct type_float *dest_type = float_type_new(NULL,
                                LDBL_MANT_DIG,
                                sizeof(long double) * CHAR_BIT - LDBL_MANT_DIG,
                                BYTE_ORDER,
                                __alignof__(long double));
        struct stream_pos destp;
 
-       align_pos(srcp, float_class->p.alignment);
+       align_pos(srcp, float_type->p.alignment);
        init_pos(&destp, (char *) u.bits);
-       _ctf_float_copy(&destp, dest_class, srcp, float_class);
-       type_class_unref(&dest_class->p);
+       _ctf_float_copy(&destp, dest_type, srcp, float_type);
+       type_unref(&dest_type->p);
        return u.v;
 }
 
 void ctf_ldouble_write(struct stream_pos *destp,
-                      const struct type_class_float *float_class,
+                      const struct type_float *float_type,
                       long double v)
 {
        union ldoubleIEEE754 u;
-       struct type_class_float *src_class = float_type_class_new(NULL,
+       struct type_float *src_type = float_type_new(NULL,
                                LDBL_MANT_DIG,
                                sizeof(long double) * CHAR_BIT - LDBL_MANT_DIG,
                                BYTE_ORDER,
@@ -175,8 +175,8 @@ void ctf_ldouble_write(struct stream_pos *destp,
        struct stream_pos srcp;
 
        u.v = v;
-       align_pos(destp, float_class->p.alignment);
+       align_pos(destp, float_type->p.alignment);
        init_pos(&srcp, (char *) u.bits);
-       _ctf_float_copy(destp, float_class, &srcp, src_class);
-       type_class_unref(&src_class->p);
+       _ctf_float_copy(destp, float_type, &srcp, src_type);
+       type_unref(&src_type->p);
 }
index 127b8062bf6901240ad3c38d9f6082cae2cbdb71..66e2a321eaf4bf6b12cbc37f3d5a1d091b3d8f27 100644 (file)
 
 static
 uint64_t _aligned_uint_read(struct stream_pos *pos,
-                      const struct type_class_integer *int_class)
+                      const struct type_integer *integer_type)
 {
-       int rbo = (int_class->byte_order != BYTE_ORDER);        /* reverse byte order */
+       int rbo = (integer_type->byte_order != BYTE_ORDER);     /* reverse byte order */
 
-       align_pos(pos, int_class->p.alignment);
+       align_pos(pos, integer_type->p.alignment);
        assert(!(pos->offset % CHAR_BIT));
-       switch (int_class->len) {
+       switch (integer_type->len) {
        case 8:
        {
                uint8_t v;
 
                v = *(const uint8_t *)pos->base;
-               move_pos(pos, int_class->len);
+               move_pos(pos, integer_type->len);
                return v;
        }
        case 16:
@@ -44,7 +44,7 @@ uint64_t _aligned_uint_read(struct stream_pos *pos,
                uint16_t v;
 
                v = *(const uint16_t *)pos->base;
-               move_pos(pos, int_class->len);
+               move_pos(pos, integer_type->len);
                return rbo ? GUINT16_SWAP_LE_BE(v) : v;
        }
        case 32:
@@ -52,7 +52,7 @@ uint64_t _aligned_uint_read(struct stream_pos *pos,
                uint32_t v;
 
                v = *(const uint32_t *)pos->base;
-               move_pos(pos, int_class->len);
+               move_pos(pos, integer_type->len);
                return rbo ? GUINT32_SWAP_LE_BE(v) : v;
        }
        case 64:
@@ -60,7 +60,7 @@ uint64_t _aligned_uint_read(struct stream_pos *pos,
                uint64_t v;
 
                v = *(const uint64_t *)pos->base;
-               move_pos(pos, int_class->len);
+               move_pos(pos, integer_type->len);
                return rbo ? GUINT64_SWAP_LE_BE(v) : v;
        }
        default:
@@ -70,19 +70,19 @@ uint64_t _aligned_uint_read(struct stream_pos *pos,
 
 static
 int64_t _aligned_int_read(struct stream_pos *pos,
-                    const struct type_class_integer *int_class)
+                    const struct type_integer *integer_type)
 {
-       int rbo = (int_class->byte_order != BYTE_ORDER);        /* reverse byte order */
+       int rbo = (integer_type->byte_order != BYTE_ORDER);     /* reverse byte order */
 
-       align_pos(pos, int_class->p.alignment);
+       align_pos(pos, integer_type->p.alignment);
        assert(!(pos->offset % CHAR_BIT));
-       switch (int_class->len) {
+       switch (integer_type->len) {
        case 8:
        {
                int8_t v;
 
                v = *(const int8_t *)pos->base;
-               move_pos(pos, int_class->len);
+               move_pos(pos, integer_type->len);
                return v;
        }
        case 16:
@@ -90,7 +90,7 @@ int64_t _aligned_int_read(struct stream_pos *pos,
                int16_t v;
 
                v = *(const int16_t *)pos->base;
-               move_pos(pos, int_class->len);
+               move_pos(pos, integer_type->len);
                return rbo ? GUINT16_SWAP_LE_BE(v) : v;
        }
        case 32:
@@ -98,7 +98,7 @@ int64_t _aligned_int_read(struct stream_pos *pos,
                int32_t v;
 
                v = *(const int32_t *)pos->base;
-               move_pos(pos, int_class->len);
+               move_pos(pos, integer_type->len);
                return rbo ? GUINT32_SWAP_LE_BE(v) : v;
        }
        case 64:
@@ -106,7 +106,7 @@ int64_t _aligned_int_read(struct stream_pos *pos,
                int64_t v;
 
                v = *(const int64_t *)pos->base;
-               move_pos(pos, int_class->len);
+               move_pos(pos, integer_type->len);
                return rbo ? GUINT64_SWAP_LE_BE(v) : v;
        }
        default:
@@ -116,17 +116,17 @@ int64_t _aligned_int_read(struct stream_pos *pos,
 
 static
 void _aligned_uint_write(struct stream_pos *pos,
-                   const struct type_class_integer *int_class,
+                   const struct type_integer *integer_type,
                    uint64_t v)
 {
-       int rbo = (int_class->byte_order != BYTE_ORDER);        /* reverse byte order */
+       int rbo = (integer_type->byte_order != BYTE_ORDER);     /* reverse byte order */
 
-       align_pos(pos, int_class->p.alignment);
+       align_pos(pos, integer_type->p.alignment);
        assert(!(pos->offset % CHAR_BIT));
        if (pos->dummy)
                goto end;
 
-       switch (int_class->len) {
+       switch (integer_type->len) {
        case 8: *(uint8_t *) get_pos_addr(pos) = (uint8_t) v;
                break;
        case 16:
@@ -147,22 +147,22 @@ void _aligned_uint_write(struct stream_pos *pos,
                assert(0);
        }
 end:
-       move_pos(pos, int_class->len);
+       move_pos(pos, integer_type->len);
 }
 
 static
 void _aligned_int_write(struct stream_pos *pos,
-                  const struct type_class_integer *int_class,
+                  const struct type_integer *integer_type,
                   int64_t v)
 {
-       int rbo = (int_class->byte_order != BYTE_ORDER);        /* reverse byte order */
+       int rbo = (integer_type->byte_order != BYTE_ORDER);     /* reverse byte order */
 
-       align_pos(pos, int_class->p.alignment);
+       align_pos(pos, integer_type->p.alignment);
        assert(!(pos->offset % CHAR_BIT));
        if (pos->dummy)
                goto end;
 
-       switch (int_class->len) {
+       switch (integer_type->len) {
        case 8: *(int8_t *) get_pos_addr(pos) = (int8_t) v;
                break;
        case 16:
@@ -183,72 +183,72 @@ void _aligned_int_write(struct stream_pos *pos,
                assert(0);
        }
 end:
-       move_pos(pos, int_class->len);
+       move_pos(pos, integer_type->len);
        return;
 }
 
 uint64_t ctf_uint_read(struct stream_pos *pos,
-                       const struct type_class_integer *int_class)
+                       const struct type_integer *integer_type)
 {
        uint64_t v = 0;
 
-       align_pos(pos, int_class->p.alignment);
-       if (int_class->byte_order == LITTLE_ENDIAN)
+       align_pos(pos, integer_type->p.alignment);
+       if (integer_type->byte_order == LITTLE_ENDIAN)
                bt_bitfield_read_le(pos->base, unsigned long, pos->offset,
-                                   int_class->len, &v);
+                                   integer_type->len, &v);
        else
                bt_bitfield_read_be(pos->base, unsigned long, pos->offset,
-                                   int_class->len, &v);
-       move_pos(pos, int_class->len);
+                                   integer_type->len, &v);
+       move_pos(pos, integer_type->len);
        return v;
 }
 
 int64_t ctf_int_read(struct stream_pos *pos,
-                       const struct type_class_integer *int_class)
+                       const struct type_integer *integer_type)
 {
        int64_t v = 0;
 
-       align_pos(pos, int_class->p.alignment);
-       if (int_class->byte_order == LITTLE_ENDIAN)
+       align_pos(pos, integer_type->p.alignment);
+       if (integer_type->byte_order == LITTLE_ENDIAN)
                bt_bitfield_read_le(pos->base, unsigned long, pos->offset,
-                                   int_class->len, &v);
+                                   integer_type->len, &v);
        else
                bt_bitfield_read_be(pos->base, unsigned long, pos->offset,
-                                   int_class->len, &v);
-       move_pos(pos, int_class->len);
+                                   integer_type->len, &v);
+       move_pos(pos, integer_type->len);
        return v;
 }
 
 void ctf_uint_write(struct stream_pos *pos,
-                       const struct type_class_integer *int_class,
+                       const struct type_integer *integer_type,
                        uint64_t v)
 {
-       align_pos(pos, int_class->p.alignment);
+       align_pos(pos, integer_type->p.alignment);
        if (pos->dummy)
                goto end;
-       if (int_class->byte_order == LITTLE_ENDIAN)
+       if (integer_type->byte_order == LITTLE_ENDIAN)
                bt_bitfield_write_le(pos->base, unsigned long, pos->offset,
-                                    int_class->len, v);
+                                    integer_type->len, v);
        else
                bt_bitfield_write_be(pos->base, unsigned long, pos->offset,
-                                    int_class->len, v);
+                                    integer_type->len, v);
 end:
-       move_pos(pos, int_class->len);
+       move_pos(pos, integer_type->len);
 }
 
 void ctf_int_write(struct stream_pos *pos,
-                       const struct type_class_integer *int_class,
+                       const struct type_integer *integer_type,
                        int64_t v)
 {
-       align_pos(pos, int_class->p.alignment);
+       align_pos(pos, integer_type->p.alignment);
        if (pos->dummy)
                goto end;
-       if (int_class->byte_order == LITTLE_ENDIAN)
+       if (integer_type->byte_order == LITTLE_ENDIAN)
                bt_bitfield_write_le(pos->base, unsigned long, pos->offset,
-                                    int_class->len, v);
+                                    integer_type->len, v);
        else
                bt_bitfield_write_be(pos->base, unsigned long, pos->offset,
-                                    int_class->len, v);
+                                    integer_type->len, v);
 end:
-       move_pos(pos, int_class->len);
+       move_pos(pos, integer_type->len);
 }
index f3c209fdffde67f00689027c615272753db21d18..127c6588ef33fedff14362138a29a3b29c69ad88 100644 (file)
 #include <babeltrace/ctf/types.h>
 
 void ctf_sequence_begin(struct stream_pos *pos,
-                       const struct type_class_sequence *sequence_class)
+                       const struct type_sequence *sequence_type)
 {
-       align_pos(pos, sequence_class->p.alignment);
+       align_pos(pos, sequence_type->p.alignment);
 }
 
 void ctf_sequence_end(struct stream_pos *pos,
-                     const struct type_class_sequence *sequence_class)
+                     const struct type_sequence *sequence_type)
 {
 }
index 95a81a30e76cd46929c7e16fb899625e0050f0ee..125e7b3b484814b3b3620044d006357b8df02c3f 100644 (file)
 #include <string.h>
 
 void ctf_string_copy(struct stream_pos *dest, struct stream_pos *src,
-                    const struct type_class_string *string_class)
+                    const struct type_string *string_type)
 {
        size_t len;
        char *destaddr, *srcaddr;
 
-       align_pos(src, string_class->p.alignment);
+       align_pos(src, string_type->p.alignment);
        srcaddr = get_pos_addr(src);
        len = strlen(srcaddr) + 1;
        if (dest->dummy)
                goto end;
-       align_pos(dest, string_class->p.alignment);
+       align_pos(dest, string_type->p.alignment);
        destaddr = get_pos_addr(dest);
        strcpy(destaddr, srcaddr);
 end:
@@ -40,12 +40,12 @@ end:
 }
 
 void ctf_string_read(char **dest, struct stream_pos *src,
-                    const struct type_class_string *string_class)
+                    const struct type_string *string_type)
 {
        size_t len;
        char *srcaddr;
 
-       align_pos(src, string_class->p.alignment);
+       align_pos(src, string_type->p.alignment);
        srcaddr = get_pos_addr(src);
        len = strlen(srcaddr) + 1;
        *dest = g_realloc(*dest, len);
@@ -54,12 +54,12 @@ void ctf_string_read(char **dest, struct stream_pos *src,
 }
 
 void ctf_string_write(struct stream_pos *dest, const char *src,
-                     const struct type_class_string *string_class)
+                     const struct type_string *string_type)
 {
        size_t len;
        char *destaddr;
 
-       align_pos(dest, string_class->p.alignment);
+       align_pos(dest, string_type->p.alignment);
        len = strlen(src) + 1;
        if (dest->dummy)
                goto end;
index 70c08219953200be6baa3931659ca3f505fbb51b..4eda7d6994d15b097f7a5d0d7f37b5d27cbf6f5b 100644 (file)
 #include <babeltrace/ctf/types.h>
 
 void ctf_struct_begin(struct stream_pos *pos,
-                     const struct type_class_struct *struct_class)
+                     const struct type_struct *struct_type)
 {
-       align_pos(pos, struct_class->p.alignment);
+       align_pos(pos, struct_type->p.alignment);
 }
 
 void ctf_struct_end(struct stream_pos *pos,
-                   const struct type_class_struct *struct_class)
+                   const struct type_struct *struct_type)
 {
 }
index 78adca3da54d7506970231ec53802aa2486f73bf..4422f1088a4171a24bafc016c883861ef031f42f 100644 (file)
 #include <babeltrace/ctf/types.h>
 
 void ctf_variant_begin(struct stream_pos *pos,
-                      const struct type_class_variant *variant_class)
+                      const struct type_variant *variant_type)
 {
 }
 
 void ctf_variant_end(struct stream_pos *pos,
-                    const struct type_class_variant *variant_class)
+                    const struct type_variant *variant_type)
 {
 }
index 6db8d27081848845a5674203ffc4f2a3fd0964a7..d0073e4c8d51d64459222df739286327a23a4142 100644 (file)
  */
 
 uint64_t ctf_uint_read(struct stream_pos *pos,
-               const struct type_class_integer *int_class);
+               const struct type_integer *integer_type);
 int64_t ctf_int_read(struct stream_pos *pos,
-               const struct type_class_integer *int_class);
+               const struct type_integer *integer_type);
 void ctf_uint_write(struct stream_pos *pos,
-               const struct type_class_integer *int_class,
+               const struct type_integer *integer_type,
                uint64_t v);
 void ctf_int_write(struct stream_pos *pos,
-               const struct type_class_integer *int_class,
+               const struct type_integer *integer_type,
                int64_t v);
 
 double ctf_double_read(struct stream_pos *pos,
-                       const struct type_class_float *src);
+                       const struct type_float *src);
 void ctf_double_write(struct stream_pos *pos,
-               const struct type_class_float *dest,
+               const struct type_float *dest,
                double v);
 long double ctf_ldouble_read(struct stream_pos *pos,
-                            const struct type_class_float *src);
+                            const struct type_float *src);
 void ctf_ldouble_write(struct stream_pos *pos,
-               const struct type_class_float *dest,
+               const struct type_float *dest,
                long double v);
 void ctf_float_copy(struct stream_pos *destp,
                struct stream_pos *srcp,
-               const struct type_class_float *float_class);
+               const struct type_float *float_type);
 
 void ctf_string_copy(struct stream_pos *dest, struct stream_pos *src,
-                    const struct type_class_string *string_class);
+                    const struct type_string *string_type);
 void ctf_string_read(char **dest, struct stream_pos *src,
-                    const struct type_class_string *string_class);
+                    const struct type_string *string_type);
 void ctf_string_write(struct stream_pos *dest, const char *src,
-                     const struct type_class_string *string_class);
+                     const struct type_string *string_type);
 void ctf_string_free_temp(char *string);
 
 GArray *ctf_enum_read(struct stream_pos *pos,
-                     const struct type_class_enum *src);
+                     const struct type_enum *src);
 void ctf_enum_write(struct stream_pos *pos,
-               const struct type_class_enum *dest,
+               const struct type_enum *dest,
                GQuark q);
 void ctf_struct_begin(struct stream_pos *pos,
-                     const struct type_class_struct *struct_class);
+                     const struct type_struct *struct_type);
 void ctf_struct_end(struct stream_pos *pos,
-                   const struct type_class_struct *struct_class);
+                   const struct type_struct *struct_type);
 void ctf_variant_begin(struct stream_pos *pos,
-                      const struct type_class_variant *variant_class);
+                      const struct type_variant *variant_type);
 void ctf_variant_end(struct stream_pos *pos,
-                    const struct type_class_variant *variant_class);
+                    const struct type_variant *variant_type);
 void ctf_array_begin(struct stream_pos *pos,
-                    const struct type_class_array *array_class);
+                    const struct type_array *array_type);
 void ctf_array_end(struct stream_pos *pos,
-                  const struct type_class_array *array_class);
+                  const struct type_array *array_type);
 void ctf_sequence_begin(struct stream_pos *pos,
-                       const struct type_class_sequence *sequence_class);
+                       const struct type_sequence *sequence_type);
 void ctf_sequence_end(struct stream_pos *pos,
-                     const struct type_class_sequence *sequence_class);
+                     const struct type_sequence *sequence_type);
 
 #endif /* _BABELTRACE_CTF_TYPES_H */
index 24276fa46915275f7b059edde605ad59cef65a70..6cae14efc3744ab7de264c7b672321a0857cd3de 100644 (file)
@@ -27,31 +27,31 @@ struct format {
        GQuark name;
 
        uint64_t (*uint_read)(struct stream_pos *pos,
-                       const struct type_class_integer *int_class);
+                       const struct type_integer *integer_type);
        int64_t (*int_read)(struct stream_pos *pos,
-                       const struct type_class_integer *int_class);
+                       const struct type_integer *integer_type);
        void (*uint_write)(struct stream_pos *pos,
-                          const struct type_class_integer *int_class,
+                          const struct type_integer *integer_type,
                           uint64_t v);
        void (*int_write)(struct stream_pos *pos,
-                         const struct type_class_integer *int_class,
+                         const struct type_integer *integer_type,
                          int64_t v);
 
        void (*float_copy)(struct stream_pos *destp,
                           struct stream_pos *srcp,
-                          const struct type_class_float *float_class);
+                          const struct type_float *float_type);
        double (*double_read)(struct stream_pos *pos,
-                             const struct type_class_float *float_class);
+                             const struct type_float *float_type);
        void (*double_write)(struct stream_pos *pos,
-                            const struct type_class_float *float_class,
+                            const struct type_float *float_type,
                             double v);
 
        void (*string_copy)(struct stream_pos *dest, struct stream_pos *src,
-                           const struct type_class_string *string_class);
+                           const struct type_string *string_type);
        void (*string_read)(char **dest, struct stream_pos *src,
-                           const struct type_class_string *string_class);
+                           const struct type_string *string_type);
        void (*string_write)(struct stream_pos *dest, const char *src,
-                            const struct type_class_string *string_class);
+                            const struct type_string *string_type);
        void (*string_free_temp)(char *string);
 
        /*
@@ -59,26 +59,26 @@ struct format {
         * g_array_unref().
         */
        GArray *(*enum_read)(struct stream_pos *pos,
-                           const struct type_class_enum *src);
+                           const struct type_enum *src);
        void (*enum_write)(struct stream_pos *pos,
-                          const struct type_class_enum *dest,
+                          const struct type_enum *dest,
                           GQuark q);
        void (*struct_begin)(struct stream_pos *pos,
-                            const struct type_class_struct *struct_class);
+                            const struct type_struct *struct_type);
        void (*struct_end)(struct stream_pos *pos,
-                          const struct type_class_struct *struct_class);
+                          const struct type_struct *struct_type);
        void (*variant_begin)(struct stream_pos *pos,
-                             const struct type_class_variant *variant_class);
+                             const struct type_variant *variant_type);
        void (*variant_end)(struct stream_pos *pos,
-                           const struct type_class_variant *variant_class);
+                           const struct type_variant *variant_type);
        void (*array_begin)(struct stream_pos *pos,
-                            const struct type_class_array *array_class);
+                            const struct type_array *array_type);
        void (*array_end)(struct stream_pos *pos,
-                          const struct type_class_array *array_class);
+                          const struct type_array *array_type);
        void (*sequence_begin)(struct stream_pos *pos,
-                            const struct type_class_sequence *sequence_class);
+                            const struct type_sequence *sequence_type);
        void (*sequence_end)(struct stream_pos *pos,
-                          const struct type_class_sequence *sequence_class);
+                          const struct type_sequence *sequence_type);
 };
 
 struct format *bt_lookup_format(GQuark qname);
index da2387d311853192dbc6885898a10a40505c407f..fe7ab62950f10604a1f4971b03f901bb6ab71f3c 100644 (file)
@@ -85,41 +85,42 @@ char *get_pos_addr(struct stream_pos *pos)
 }
 
 struct format;
-struct type;
+struct declaration;
 
 /* Type declaration scope */
 struct declaration_scope {
-       /* Hash table mapping type name GQuark to struct type_class */
-       GHashTable *type_classes;
+       /* Hash table mapping type name GQuark to struct type */
+       GHashTable *types;
        struct declaration_scope *parent_scope;
 };
 
-struct type_class {
+struct type {
        GQuark name;            /* type name */
        size_t alignment;       /* type alignment, in bits */
-       int ref;                /* number of references to the type class */
-       /*
-        * class_free called with type class ref is decremented to 0.
-        */
-       void (*class_free)(struct type_class *type_class);
-       struct type *(*type_new)(struct type_class *_class,
-                                struct declaration_scope *parent_scope);
+       int ref;                /* number of references to the type */
        /*
         * type_free called with type ref is decremented to 0.
         */
        void (*type_free)(struct type *type);
+       struct declaration *
+               (*declaration_new)(struct type *type,
+                                  struct declaration_scope *parent_scope);
        /*
-        * Type copy function. Knows how to find the child type from the parent
-        * type.
+        * declaration_free called with declaration ref is decremented to 0.
+        */
+       void (*declaration_free)(struct declaration *declaration);
+       /*
+        * Declaration copy function. Knows how to find the child declaration
+        * from the parent declaration.
         */
        void (*copy)(struct stream_pos *dest, const struct format *fdest, 
                     struct stream_pos *src, const struct format *fsrc,
-                    struct type *type);
+                    struct declaration *declaration);
 };
 
-struct type {
-       struct type_class *_class;
-       int ref;                /* number of references to the type instance */
+struct declaration {
+       struct type *type;
+       int ref;                /* number of references to the declaration */
 };
 
 /*
@@ -127,16 +128,16 @@ struct type {
  * integers, except that their read/write functions must be able to deal with
  * read/write non aligned on CHAR_BIT.
  */
-struct type_class_integer {
-       struct type_class p;
+struct type_integer {
+       struct type p;
        size_t len;             /* length, in bits. */
        int byte_order;         /* byte order */
        int signedness;
 };
 
-struct type_integer {
-       struct type p;
-       struct type_class_integer *_class;
+struct declaration_integer {
+       struct declaration p;
+       struct type_integer *type;
        /* Last values read */
        union {
                uint64_t _unsigned;
@@ -144,18 +145,18 @@ struct type_integer {
        } value;
 };
 
-struct type_class_float {
-       struct type_class p;
-       struct type_class_integer *sign;
-       struct type_class_integer *mantissa;
-       struct type_class_integer *exp;
+struct type_float {
+       struct type p;
+       struct type_integer *sign;
+       struct type_integer *mantissa;
+       struct type_integer *exp;
        int byte_order;
        /* TODO: we might want to express more info about NaN, +inf and -inf */
 };
 
-struct type_float {
-       struct type p;
-       struct type_class_float *_class;
+struct declaration_float {
+       struct declaration p;
+       struct type_float *type;
        /* Last values read */
        long double value;
 };
@@ -198,122 +199,121 @@ struct enum_table {
        GHashTable *quark_to_range_set;         /* (GQuark, range GArray) */
 };
 
-struct type_class_enum {
-       struct type_class_integer p;    /* inherit from integer */
+struct type_enum {
+       struct type p;
+       struct type_integer *integer_type;
        struct enum_table table;
 };
 
-struct type_enum {
-       struct type p;
-       struct type_class_enum *_class;
+struct declaration_enum {
+       struct declaration p;
+       struct declaration_integer *integer;
+       struct type_enum *type;
        /* Last GQuark values read. Keeping a reference on the GQuark array. */
        GArray *value;
 };
 
-struct type_class_string {
-       struct type_class p;
-};
-
 struct type_string {
        struct type p;
-       struct type_class_string *_class;
-       char *value;    /* freed at type_string teardown */
 };
 
-struct type_class_field {
-       GQuark name;
-       struct type_class *type_class;
+struct declaration_string {
+       struct declaration p;
+       struct type_string *type;
+       char *value;    /* freed at declaration_string teardown */
 };
 
-struct field {
+struct type_field {
+       GQuark name;
        struct type *type;
 };
 
-struct type_class_struct {
-       struct type_class p;
-       GHashTable *fields_by_name;     /* Tuples (field name, field index) */
-       GArray *fields;                 /* Array of type_class_field */
+struct field {
+       struct declaration *type;
 };
 
 struct type_struct {
        struct type p;
-       struct type_class_struct *_class;
+       GHashTable *fields_by_name;     /* Tuples (field name, field index) */
+       GArray *fields;                 /* Array of type_field */
+};
+
+struct declaration_struct {
+       struct declaration p;
+       struct type_struct *type;
        struct declaration_scope *scope;
        GArray *fields;                 /* Array of struct field */
 };
 
-struct type_class_variant {
-       struct type_class p;
+struct type_variant {
+       struct type p;
        GHashTable *fields_by_tag;      /* Tuples (field tag, field index) */
-       GArray *fields;                 /* Array of type_class_field */
+       GArray *fields;                 /* Array of type_field */
 };
 
-struct type_variant {
-       struct type p;
-       struct type_class_variant *_class;
+struct declaration_variant {
+       struct declaration p;
+       struct type_variant *type;
        struct declaration_scope *scope;
-       struct type *tag;
+       struct declaration *tag;
        GArray *fields;                 /* Array of struct field */
        struct field *current_field;    /* Last field read */
 };
 
-struct type_class_array {
-       struct type_class p;
+struct type_array {
+       struct type p;
        size_t len;
-       struct type_class *elem;
+       struct type *elem;
 };
 
-struct type_array {
-       struct type p;
-       struct type_class_array *_class;
+struct declaration_array {
+       struct declaration p;
+       struct type_array *type;
        struct declaration_scope *scope;
        struct field current_element;           /* struct field */
 };
 
-struct type_class_sequence {
-       struct type_class p;
-       struct type_class_integer *len_class;
-       struct type_class *elem;
-};
-
 struct type_sequence {
        struct type p;
-       struct type_class_sequence *_class;
+       struct type_integer *len_type;
+       struct type *elem;
+};
+
+struct declaration_sequence {
+       struct declaration p;
+       struct type_sequence *type;
        struct declaration_scope *scope;
-       struct type_integer *len;
+       struct declaration_integer *len;
        struct field current_element;           /* struct field */
 };
 
-struct type_class *lookup_type_class(GQuark qname,
-                                    struct declaration_scope *scope);
-int register_type_class(struct type_class *type_class,
-                       struct declaration_scope *scope);
+struct type *lookup_type(GQuark qname, struct declaration_scope *scope);
+int register_type(struct type *type, struct declaration_scope *scope);
 
-void type_class_ref(struct type_class *type_class);
-void type_class_unref(struct type_class *type_class);
+void type_ref(struct type *type);
+void type_unref(struct type *type);
 
 struct declaration_scope *
-new_declaration_scope(struct declaration_scope *parent_scope);
+       new_declaration_scope(struct declaration_scope *parent_scope);
 void free_declaration_scope(struct declaration_scope *scope);
 
-void type_ref(struct type *type);
-void type_unref(struct type *type);
+void declaration_ref(struct declaration *declaration);
+void declaration_unref(struct declaration *declaration);
 
 /* Nameless types can be created by passing a NULL name */
 
-struct type_class_integer *integer_type_class_new(const char *name,
-                                           size_t len, int byte_order,
-                                           int signedness,
-                                           size_t alignment);
+struct type_integer *integer_type_new(const char *name,
+                                     size_t len, int byte_order,
+                                     int signedness, size_t alignment);
 
 /*
  * mantissa_len is the length of the number of bytes represented by the mantissa
  * (e.g. result of DBL_MANT_DIG). It includes the leading 1.
  */
-struct type_class_float *float_type_class_new(const char *name,
-                                       size_t mantissa_len,
-                                       size_t exp_len, int byte_order,
-                                       size_t alignment);
+struct type_float *float_type_new(const char *name,
+                                 size_t mantissa_len,
+                                 size_t exp_len, int byte_order,
+                                 size_t alignment);
 
 /*
  * A GQuark can be translated to/from strings with g_quark_from_string() and
@@ -324,93 +324,83 @@ struct type_class_float *float_type_class_new(const char *name,
  * Returns a GArray of GQuark or NULL.
  * Caller must release the GArray with g_array_unref().
  */
-GArray *enum_uint_to_quark_set(const struct type_class_enum *enum_class,
-                              uint64_t v);
+GArray *enum_uint_to_quark_set(const struct type_enum *enum_type, uint64_t v);
 
 /*
  * Returns a GArray of GQuark or NULL.
  * Caller must release the GArray with g_array_unref().
  */
-GArray *enum_int_to_quark_set(const struct type_class_enum *enum_class,
-                             uint64_t v);
+GArray *enum_int_to_quark_set(const struct type_enum *enum_type, uint64_t v);
 
 /*
  * Returns a GArray of struct enum_range or NULL.
  * Callers do _not_ own the returned GArray (and therefore _don't_ need to
  * release it).
  */
-GArray *enum_quark_to_range_set(const struct type_class_enum *enum_class,
-                               GQuark q);
-void enum_signed_insert(struct type_class_enum *enum_class,
+GArray *enum_quark_to_range_set(const struct type_enum *enum_type, GQuark q);
+void enum_signed_insert(struct type_enum *enum_type,
                         int64_t start, int64_t end, GQuark q);
-void enum_unsigned_insert(struct type_class_enum *enum_class,
+void enum_unsigned_insert(struct type_enum *enum_type,
                          uint64_t start, uint64_t end, GQuark q);
-size_t enum_get_nr_enumerators(struct type_class_enum *enum_class);
+size_t enum_get_nr_enumerators(struct type_enum *enum_type);
 
-struct type_class_enum *enum_type_class_new(const char *name,
-                                     size_t len, int byte_order,
-                                     int signedness,
-                                     size_t alignment);
+struct type_enum *enum_type_new(const char *name,
+                               struct type_integer *integer_type);
 
-struct type_class_struct *struct_type_class_new(const char *name);
-void struct_type_class_add_field(struct type_class_struct *struct_class,
-                                const char *field_name,
-                                struct type_class *type_class);
+struct type_struct *struct_type_new(const char *name);
+void struct_type_add_field(struct type_struct *struct_type,
+                          const char *field_name, struct type *field_type);
 /*
  * Returns the index of a field within a structure.
  */
-unsigned long
-struct_type_class_lookup_field_index(struct type_class_struct *struct_class,
-                                    GQuark field_name);
+unsigned long struct_type_lookup_field_index(struct type_struct *struct_type,
+                                            GQuark field_name);
 /*
  * field returned only valid as long as the field structure is not appended to.
  */
-struct type_class_field *
-struct_type_class_get_field_from_index(struct type_class_struct *struct_class,
-                                      unsigned long index);
-struct field *
-struct_type_get_field_from_index(struct type_struct *_struct,
+struct type_field *
+struct_type_get_field_from_index(struct type_struct *struct_type,
                                 unsigned long index);
+struct field *
+struct_get_field_from_index(struct declaration_struct *struct_declaration,
+                           unsigned long index);
 
 /*
  * The tag enumeration is validated to ensure that it contains only mappings
  * from numeric values to a single tag. Overlapping tag value ranges are
  * therefore forbidden.
  */
-struct type_class_variant *variant_type_class_new(const char *name);
-void variant_type_class_add_field(struct type_class_variant *variant_class,
-                                 const char *tag_name,
-                                 struct type_class *type_class);
-struct type_class_field *
-variant_type_class_get_field_from_tag(struct type_class_variant *variant_class,
-                                     GQuark tag);
+struct type_variant *variant_type_new(const char *name);
+void variant_type_add_field(struct type_variant *variant_type,
+                           const char *tag_name, struct type *tag_type);
+struct type_field *
+variant_type_get_field_from_tag(struct type_variant *variant_type, GQuark tag);
 /*
  * Returns 0 on success, -EPERM on error.
  */
-int variant_type_set_tag(struct type_variant *variant,
-                        struct type *enum_tag_instance);
+int variant_declaration_set_tag(struct declaration_variant *variant,
+                               struct declaration *enum_tag);
 /*
  * Returns the field selected by the current tag value.
  * field returned only valid as long as the variant structure is not appended
  * to.
  */
 struct field *
-variant_type_get_current_field(struct type_variant *variant);
+variant_get_current_field(struct declaration_variant *variant);
 
 /*
- * elem_class passed as parameter now belongs to the array. No need to free it
+ * elem_type passed as parameter now belongs to the array. No need to free it
  * explicitly. "len" is the number of elements in the array.
  */
-struct type_class_array *array_type_class_new(const char *name,
-                                       size_t len,
-                                       struct type_class *elem_class);
+struct type_array *array_type_new(const char *name,
+                                 size_t len, struct type *elem_type);
 
 /*
- * int_class and elem_class passed as parameter now belongs to the sequence. No
+ * int_type and elem_type passed as parameter now belong to the sequence. No
  * need to free them explicitly.
  */
-struct type_class_sequence *sequence_type_class_new(const char *name,
-                                       struct type_class_integer *len_class
-                                       struct type_class *elem_class);
+struct type_sequence *sequence_type_new(const char *name,
+                                       struct type_integer *len_type
+                                       struct type *elem_type);
 
 #endif /* _BABELTRACE_TYPES_H */
index 6ac4a1a1cbfab26b06ef5648380b48ceb1264d95..6dd3b9ca8a6c869e419ef17c54ff9141ebf8c31f 100644 (file)
 #include <babeltrace/format.h>
 
 static
-struct type *_array_type_new(struct type_class *type_class,
-                            struct declaration_scope *parent_scope);
+struct declaration *_array_declaration_new(struct type *type,
+                       struct declaration_scope *parent_scope);
 static
-void _array_type_free(struct type *type);
+void _array_declaration_free(struct declaration *declaration);
 
 void array_copy(struct stream_pos *dest, const struct format *fdest, 
                struct stream_pos *src, const struct format *fsrc,
-               struct type *type)
+               struct declaration *declaration)
 {
-       struct type_sequence *array = container_of(type, struct type_array, p);
-       struct type_class_array *array_class = array->_class;
+       struct declaration_array *array =
+               container_of(declaration, struct declaration_array, p);
+       struct type_array *array_type = array->type;
        uint64_t i;
 
-       fsrc->array_begin(src, array_class);
-       fdest->array_begin(dest, array_class);
+       fsrc->array_begin(src, array_type);
+       fdest->array_begin(dest, array_type);
 
-       for (i = 0; i < array_class->len; i++) {
-               struct type_class *elem_class = array->current_element.type;
-               elem_type->p._class->copy(dest, fdest, src, fsrc, elem_type);
+       for (i = 0; i < array_type->len; i++) {
+               struct type *elem_type = array->current_element.type;
+               elem_type->p.type->copy(dest, fdest, src, fsrc, elem_type);
        }
-       fsrc->array_end(src, array_class);
-       fdest->array_end(dest, array_class);
+       fsrc->array_end(src, array_type);
+       fdest->array_end(dest, array_type);
 }
 
 static
-void _array_type_class_free(struct type_class *type_class)
+void _array_type_free(struct type *type)
 {
-       struct type_class_array *array_class =
-               container_of(type_class, struct type_class_array, p);
+       struct type_array *array_type =
+               container_of(type, struct type_array, p);
 
-       type_class_unref(array_class->elem);
-       g_free(array_class);
+       type_unref(array_type->elem);
+       g_free(array_type);
 }
 
-struct type_class_array *
-array_type_class_new(const char *name, size_t len, struct type_class *elem)
+struct type_array *
+       array_type_new(const char *name, size_t len, struct type *elem_type)
 {
-       struct type_class_array *array_class;
-       struct type_class *type_class;
+       struct type_array *array_type;
+       struct type *type;
        int ret;
 
-       array_class = g_new(struct type_class_array, 1);
-       type_class = &array_class->p;
-       array_class->len = len;
-       type_ref(elem);
-       array_class->elem = elem;
-       type_class->name = g_quark_from_string(name);
+       array_type = g_new(struct type_array, 1);
+       type = &array_type->p;
+       array_type->len = len;
+       type_ref(elem_type);
+       array_type->elem = elem_type;
+       type->name = g_quark_from_string(name);
        /* No need to align the array, the first element will align itself */
-       type_class->alignment = 1;
-       type_class->copy = array_copy;
-       type_class->class_free = _array_type_class_free;
-       type_class->type_new = _array_type_new;
-       type_class->type_free = _array_type_free;
-       type_class->ref = 1;
+       type->alignment = 1;
+       type->copy = array_copy;
+       type->type_free = _array_type_free;
+       type->declaration_new = _array_declaration_new;
+       type->declaration_free = _array_declaration_free;
+       type->ref = 1;
 
-       if (type_class->name) {
-               ret = register_type(type_class);
+       if (type->name) {
+               ret = register_type(type);
                if (ret)
                        goto error_register;
        }
-       return array_class;
+       return array_type;
 
 error_register:
-       type_class_unref(array_class->elem);
-       g_free(array_class);
+       type_unref(array_type->elem);
+       g_free(array_type);
        return NULL;
 }
 
 static
-struct type_array *_array_type_new(struct type_class *type_class,
-                                  struct declaration_scope *parent_scope)
+struct declaration *
+       _array_declaration_new(struct type *type,
+                              struct declaration_scope *parent_scope)
 {
-       struct type_class_array *array_class =
-               container_of(type_class, struct type_class_array, p);
-       struct type_array *array;
+       struct type_array *array_type =
+               container_of(type, struct type_array, p);
+       struct declaration_array *array;
 
-       array = g_new(struct type_array, 1);
-       type_class_ref(&array_class->p);
-       array->p._class = array_class;
+       array = g_new(struct declaration_array, 1);
+       type_ref(&array_type->p);
+       array->p.type = array_type;
        array->p.ref = 1;
        array->scope = new_declaration_scope(parent_scope);
-       array->current_element.type =
-               array_class->elem.p->type_new(&array_class->elem.p,
-                                                parent_scope);
+       array->current_element.declaration =
+               array_type->elem.p->declaration_new(&array_type->elem.p,
+                                                   parent_scope);
        return &array->p;
 }
 
 static
-void _array_type_free(struct type *type)
+void _array_declaration_free(struct declaration *declaration)
 {
        struct type_array *array =
-               container_of(type, struct type_array, p);
-       struct type *elem_type = array->current_element.type;
+               container_of(declaration, struct type_array, p);
+       struct declaration *elem_declaration =
+               array->current_element.declaration;
 
-       elem_type->p._class->type_free(elem_type);
+       elem_type->p.type->declaration_free(elem_type);
        free_declaration_scope(array->scope);
-       type_class_unref(array->p._class);
+       type_unref(array->p.type);
        g_free(array);
 }
index 109fd2815a2d1a3780a8a01378fdd10e6ba6f93b..a6d56ac9dae131ef07be01b6fc185e0a643f19ef 100644 (file)
 #include <glib.h>
 
 static
-struct type_enum *_enum_type_new(struct type_class *type_class,
+struct declaration *_enum_declaration_new(struct type *type,
                                 struct declaration_scope *parent_scope);
 static
-void _enum_type_free(struct type *type);
+void _enum_declaration_free(struct declaration *declaration);
 
 static
 void enum_range_set_free(void *ptr)
@@ -37,17 +37,17 @@ void enum_range_set_free(void *ptr)
  * Returns a GArray or NULL.
  * Caller must release the GArray with g_array_unref().
  */
-GArray *enum_uint_to_quark_set(const struct type_class_enum *enum_class,
+GArray *enum_uint_to_quark_set(const struct type_enum *enum_type,
                               uint64_t v)
 {
        struct enum_range_to_quark *iter;
        GArray *qs, *ranges = NULL;
 
        /* Single values lookup */
-       qs = g_hash_table_lookup(enum_class->table.value_to_quark_set, &v);
+       qs = g_hash_table_lookup(enum_type->table.value_to_quark_set, &v);
 
        /* Range lookup */
-       cds_list_for_each_entry(iter, &enum_class->table.range_to_quark, node) {
+       cds_list_for_each_entry(iter, &enum_type->table.range_to_quark, node) {
                if (iter->range.start._unsigned > v || iter->range.end._unsigned < v)
                        continue;
                if (!ranges) {
@@ -79,16 +79,16 @@ GArray *enum_uint_to_quark_set(const struct type_class_enum *enum_class,
  * Returns a GArray or NULL.
  * Caller must release the GArray with g_array_unref().
  */
-GArray *enum_int_to_quark_set(const struct type_class_enum *enum_class, uint64_t v)
+GArray *enum_int_to_quark_set(const struct type_enum *enum_type, uint64_t v)
 {
        struct enum_range_to_quark *iter;
        GArray *qs, *ranges = NULL;
 
        /* Single values lookup */
-       qs = g_hash_table_lookup(enum_class->table.value_to_quark_set, &v);
+       qs = g_hash_table_lookup(enum_type->table.value_to_quark_set, &v);
 
        /* Range lookup */
-       cds_list_for_each_entry(iter, &enum_class->table.range_to_quark, node) {
+       cds_list_for_each_entry(iter, &enum_type->table.range_to_quark, node) {
                if (iter->range.start._signed > v || iter->range.end._signed < v)
                        continue;
                if (!ranges) {
@@ -141,20 +141,20 @@ void enum_val_free(void *ptr)
 }
 
 static
-void enum_signed_insert_value_to_quark_set(struct type_class_enum *enum_class,
+void enum_signed_insert_value_to_quark_set(struct type_enum *enum_type,
                        int64_t v, GQuark q)
 {
        int64_t *valuep;
        GArray *array;
 
-       array = g_hash_table_lookup(enum_class->table.value_to_quark_set, &v);
+       array = g_hash_table_lookup(enum_type->table.value_to_quark_set, &v);
        if (!array) {
                array = g_array_sized_new(FALSE, TRUE, sizeof(GQuark), 1);
                g_array_set_size(array, 1);
                g_array_index(array, GQuark, array->len - 1) = q;
                valuep = g_new(int64_t, 1);
                *valuep = v;
-               g_hash_table_insert(enum_class->table.value_to_quark_set, valuep, array);
+               g_hash_table_insert(enum_type->table.value_to_quark_set, valuep, array);
        } else {
                g_array_set_size(array, array->len + 1);
                g_array_index(array, GQuark, array->len - 1) = q;
@@ -162,20 +162,20 @@ void enum_signed_insert_value_to_quark_set(struct type_class_enum *enum_class,
 }
 
 static
-void enum_unsigned_insert_value_to_quark_set(struct type_class_enum *enum_class,
+void enum_unsigned_insert_value_to_quark_set(struct type_enum *enum_type,
                         uint64_t v, GQuark q)
 {
        uint64_t *valuep;
        GArray *array;
 
-       array = g_hash_table_lookup(enum_class->table.value_to_quark_set, &v);
+       array = g_hash_table_lookup(enum_type->table.value_to_quark_set, &v);
        if (!array) {
                array = g_array_sized_new(FALSE, TRUE, sizeof(GQuark), 1);
                g_array_set_size(array, 1);
                g_array_index(array, GQuark, array->len - 1) = q;
                valuep = g_new(uint64_t, 1);
                *valuep = v;
-               g_hash_table_insert(enum_class->table.value_to_quark_set, valuep, array);
+               g_hash_table_insert(enum_type->table.value_to_quark_set, valuep, array);
        } else {
                g_array_set_size(array, array->len + 1);
                g_array_index(array, GQuark, array->len - 1) = q;
@@ -200,18 +200,18 @@ void enum_val_free(void *ptr)
 }
 
 static
-void enum_signed_insert_value_to_quark_set(struct type_class_enum *enum_class,
+void enum_signed_insert_value_to_quark_set(struct type_enum *enum_type,
                        int64_t v, GQuark q)
 {
        GArray *array;
 
-       array = g_hash_table_lookup(enum_class->table.value_to_quark_set,
+       array = g_hash_table_lookup(enum_type->table.value_to_quark_set,
                                    (gconstpointer) v);
        if (!array) {
                array = g_array_sized_new(FALSE, TRUE, sizeof(GQuark), 1);
                g_array_set_size(array, 1);
                g_array_index(array, GQuark, array->len - 1) = q;
-               g_hash_table_insert(enum_class->table.value_to_quark_set,
+               g_hash_table_insert(enum_type->table.value_to_quark_set,
                                    (gpointer) v, array);
        } else {
                g_array_set_size(array, array->len + 1);
@@ -220,18 +220,18 @@ void enum_signed_insert_value_to_quark_set(struct type_class_enum *enum_class,
 }
 
 static
-void enum_unsigned_insert_value_to_quark_set(struct type_class_enum *enum_class,
+void enum_unsigned_insert_value_to_quark_set(struct type_enum *enum_type,
                         uint64_t v, GQuark q)
 {
        GArray *array;
 
-       array = g_hash_table_lookup(enum_class->table.value_to_quark_set,
+       array = g_hash_table_lookup(enum_type->table.value_to_quark_set,
                                    (gconstpointer) v);
        if (!array) {
                array = g_array_sized_new(FALSE, TRUE, sizeof(GQuark), 1);
                g_array_set_size(array, 1);
                g_array_index(array, GQuark, array->len - 1) = q;
-               g_hash_table_insert(enum_class->table.value_to_quark_set,
+               g_hash_table_insert(enum_type->table.value_to_quark_set,
                                    (gpointer) v, array);
        } else {
                g_array_set_size(array, array->len + 1);
@@ -240,47 +240,47 @@ void enum_unsigned_insert_value_to_quark_set(struct type_class_enum *enum_class,
 }
 #endif /* __WORDSIZE != 32 */
 
-GArray *enum_quark_to_range_set(const struct type_class_enum *enum_class,
+GArray *enum_quark_to_range_set(const struct type_enum *enum_type,
                                GQuark q)
 {
-       return g_hash_table_lookup(enum_class->table.quark_to_range_set,
+       return g_hash_table_lookup(enum_type->table.quark_to_range_set,
                                   (gconstpointer) (unsigned long) q);
 }
 
 static
-void enum_signed_insert_range_to_quark(struct type_class_enum *enum_class,
+void enum_signed_insert_range_to_quark(struct type_enum *enum_type,
                         int64_t start, int64_t end, GQuark q)
 {
        struct enum_range_to_quark *rtoq;
 
        rtoq = g_new(struct enum_range_to_quark, 1);
-       cds_list_add(&rtoq->node, &enum_class->table.range_to_quark);
+       cds_list_add(&rtoq->node, &enum_type->table.range_to_quark);
        rtoq->range.start._signed = start;
        rtoq->range.end._signed = end;
        rtoq->quark = q;
 }
 
 static
-void enum_unsigned_insert_range_to_quark(struct type_class_enum *enum_class,
+void enum_unsigned_insert_range_to_quark(struct type_enum *enum_type,
                         uint64_t start, uint64_t end, GQuark q)
 {
        struct enum_range_to_quark *rtoq;
 
        rtoq = g_new(struct enum_range_to_quark, 1);
-       cds_list_add(&rtoq->node, &enum_class->table.range_to_quark);
+       cds_list_add(&rtoq->node, &enum_type->table.range_to_quark);
        rtoq->range.start._unsigned = start;
        rtoq->range.end._unsigned = end;
        rtoq->quark = q;
 }
 
-void enum_signed_insert(struct type_class_enum *enum_class,
+void enum_signed_insert(struct type_enum *enum_type,
                         int64_t start, int64_t end, GQuark q)
 {
        GArray *array;
        struct enum_range *range;
 
        if (start == end) {
-               enum_signed_insert_value_to_quark_set(enum_class, start, q);
+               enum_signed_insert_value_to_quark_set(enum_type, start, q);
        } else {
                if (start > end) {
                        uint64_t tmp;
@@ -289,15 +289,15 @@ void enum_signed_insert(struct type_class_enum *enum_class,
                        start = end;
                        end = tmp;
                }
-               enum_signed_insert_range_to_quark(enum_class, start, end, q);
+               enum_signed_insert_range_to_quark(enum_type, start, end, q);
        }
 
-       array = g_hash_table_lookup(enum_class->table.quark_to_range_set,
+       array = g_hash_table_lookup(enum_type->table.quark_to_range_set,
                                    (gconstpointer) (unsigned long) q);
        if (!array) {
                array = g_array_sized_new(FALSE, TRUE,
                                          sizeof(struct enum_range), 1);
-               g_hash_table_insert(enum_class->table.quark_to_range_set,
+               g_hash_table_insert(enum_type->table.quark_to_range_set,
                                    (gpointer) (unsigned long) q,
                                    array);
        }
@@ -307,7 +307,7 @@ void enum_signed_insert(struct type_class_enum *enum_class,
        range->end._signed = end;
 }
 
-void enum_unsigned_insert(struct type_class_enum *enum_class,
+void enum_unsigned_insert(struct type_enum *enum_type,
                          uint64_t start, uint64_t end, GQuark q)
 {
        GArray *array;
@@ -315,7 +315,7 @@ void enum_unsigned_insert(struct type_class_enum *enum_class,
 
 
        if (start == end) {
-               enum_unsigned_insert_value_to_quark_set(enum_class, start, q);
+               enum_unsigned_insert_value_to_quark_set(enum_type, start, q);
        } else {
                if (start > end) {
                        uint64_t tmp;
@@ -324,15 +324,15 @@ void enum_unsigned_insert(struct type_class_enum *enum_class,
                        start = end;
                        end = tmp;
                }
-               enum_unsigned_insert_range_to_quark(enum_class, start, end, q);
+               enum_unsigned_insert_range_to_quark(enum_type, start, end, q);
        }
 
-       array = g_hash_table_lookup(enum_class->table.quark_to_range_set,
+       array = g_hash_table_lookup(enum_type->table.quark_to_range_set,
                                    (gconstpointer) (unsigned long) q);
        if (!array) {
                array = g_array_sized_new(FALSE, TRUE,
                                          sizeof(struct enum_range), 1);
-               g_hash_table_insert(enum_class->table.quark_to_range_set,
+               g_hash_table_insert(enum_type->table.quark_to_range_set,
                                    (gpointer) (unsigned long) q,
                                    array);
        }
@@ -342,21 +342,22 @@ void enum_unsigned_insert(struct type_class_enum *enum_class,
        range->end._unsigned = end;
 }
 
-size_t enum_get_nr_enumerators(struct type_class_enum *enum_class)
+size_t enum_get_nr_enumerators(struct type_enum *enum_type)
 {
-       return g_hash_table_size(enum_class->table.quark_to_range_set);
+       return g_hash_table_size(enum_type->table.quark_to_range_set);
 }
 
 void enum_copy(struct stream_pos *dest, const struct format *fdest, 
               struct stream_pos *src, const struct format *fsrc,
-              struct type *type)
+              struct declaration *declaration)
 {
-       struct type_enum *_enum = container_of(type, struct type_enum, p);
-       struct type_class_enum *enum_class = _enum->_class;
+       struct declaration_enum *_enum =
+               container_of(declaration, struct declaration_enum, p);
+       struct type_enum *enum_type= _enum->type;
        GArray *array;
        GQuark v;
 
-       array = fsrc->enum_read(src, enum_class);
+       array = fsrc->enum_read(src, enum_type);
        assert(array);
        /* unref previous array */
        if (_enum->value)
@@ -368,97 +369,97 @@ void enum_copy(struct stream_pos *dest, const struct format *fdest,
         * now to test enum read and write code.
         */
        v = g_array_index(array, GQuark, 0);
-       return fdest->enum_write(dest, enum_class, v);
+       return fdest->enum_write(dest, enum_type, v);
 }
 
 static
-void _enum_type_class_free(struct type_class *type_class)
+void _enum_type_free(struct type *type)
 {
-       struct type_class_enum *enum_class =
-               container_of(type_class, struct enum_type_class, p);
+       struct type_enum *enum_type =
+               container_of(type, struct enum_type, p);
        struct enum_range_to_quark *iter, *tmp;
 
-       g_hash_table_destroy(enum_class->table.value_to_quark_set);
-       cds_list_for_each_entry_safe(iter, tmp, &enum_class->table.range_to_quark, node) {
+       g_hash_table_destroy(enum_type->table.value_to_quark_set);
+       cds_list_for_each_entry_safe(iter, tmp, &enum_type->table.range_to_quark, node) {
                cds_list_del(&iter->node);
                g_free(iter);
        }
-       g_hash_table_destroy(enum_class->table.quark_to_range_set);
-       g_free(enum_class);
+       g_hash_table_destroy(enum_type->table.quark_to_range_set);
+       type_unref(enum_type->integer_type);
+       g_free(enum_type);
 }
 
-struct type_class_enum *
-_enum_type_class_new(const char *name, size_t len, int byte_order,
-                    int signedness, size_t alignment)
+struct type_enum *
+       _enum_type_new(const char *name, struct type_integer *integer_type)
 {
-       struct type_class_enum *enum_class;
-       struct type_class_integer *int_class;
+       struct type_enum *enum_type;
        int ret;
 
-       enum_class = g_new(struct type_class_enum, 1);
-       enum_class->table.value_to_quark_set = g_hash_table_new_full(enum_val_hash,
+       enum_type = g_new(struct type_enum, 1);
+
+       enum_type->table.value_to_quark_set = g_hash_table_new_full(enum_val_hash,
                                                            enum_val_equal,
                                                            enum_val_free,
                                                            enum_range_set_free);
-       CDS_INIT_LIST_HEAD(&enum_class->table.range_to_quark);
-       enum_class->table.quark_to_range_set = g_hash_table_new_full(g_int_hash,
+       CDS_INIT_LIST_HEAD(&enum_type->table.range_to_quark);
+       enum_type->table.quark_to_range_set = g_hash_table_new_full(g_int_hash,
                                                        g_int_equal,
                                                        NULL, enum_range_set_free);
-       int_class = &enum_class->p;
-       int_class->p.name = g_quark_from_string(name);
-       int_class->p.alignment = alignment;
-       int_class->p.copy = enum_copy;
-       int_class->p.class_free = _enum_type_class_free;
-       int_class->p.type_new = _enum_type_new;
-       int_class->p.type_free = _enum_type_free;
-       int_class->p.ref = 1;
-       int_class->len = len;
-       int_class->byte_order = byte_order;
-       int_class->signedness = signedness;
-       if (int_class->p.name) {
-               ret = register_type(&int_class->p);
+       type_ref(integer_type);
+       enum_type->integer_type = integer_type;
+       enum_type->p.name = g_quark_from_string(name);
+       enum_type->p.alignment = 1;
+       enum_type->p.copy = enum_copy;
+       enum_type->p.type_free = _enum_type_free;
+       enum_type->p.declaration_new = _enum_declaration_new;
+       enum_type->p.declaration_free = _enum_declaration_free;
+       enum_type->p.ref = 1;
+       if (enum_type->p.name) {
+               ret = register_type(&enum_type->p);
                if (ret)
                        goto register_error;
        }
-       return enum_class;
+       return enum_type;
 
 register_error:
-       {
-               struct enum_range_to_quark *iter, *tmp;
-
-               cds_list_for_each_entry_safe(iter, tmp, &enum_class->table.range_to_quark, node) {
-                       cds_list_del(&iter->node);
-                       g_free(iter);
-               }
-       }
-       g_hash_table_destroy(enum_class->table.value_to_quark_set);
-       g_hash_table_destroy(enum_class->table.quark_to_range_set);
-       g_free(enum_class);
+       g_hash_table_destroy(enum_type->table.value_to_quark_set);
+       g_hash_table_destroy(enum_type->table.quark_to_range_set);
+       type_unref(enum_type->integer_type);
+       g_free(enum_type);
        return NULL;
 }
 
 static
-struct type_enum *_enum_type_new(struct type_class *type_class,
-                                struct declaration_scope *parent_scope)
+struct declaration *
+       _enum_declaration_new(struct type *type,
+                             struct declaration_scope *parent_scope)
 {
-       struct type_class_enum *enum_class =
-               container_of(type_class, struct type_class_enum, p);
-       struct type_enum *_enum;
-
-       _enum = g_new(struct type_enum, 1);
-       type_class_ref(&enum_class->p);
-       _enum->p._class = enum_class;
+       struct type_enum *enum_type =
+               container_of(type, struct type_enum, p);
+       struct declaration_enum *_enum;
+       struct declaration_integer_parent *declaration_integer_parent;
+
+       _enum = g_new(struct declaration_enum, 1);
+       type_ref(&enum_type->p);
+       _enum->p.type = enum_type;
        _enum->p.ref = 1;
        _enum->value = NULL;
+       declaration_integer_parent =
+               enum_type->integer_type->p.declaration_new(&enum_type->integer_type->p,
+                                                          parent_scope);
+       _enum->integer = container_of(declaration_integer_parent,
+                                     struct declaration_integer, p);
        return &_enum->p;
 }
 
 static
-void _enum_type_free(struct type *type)
+void _enum_declaration_free(struct declaration *declaration)
 {
-       struct type_enum *_enum = container_of(type, struct type_enum, p);
+       struct declaration_enum *_enum =
+               container_of(declaration, struct declaration_enum, p);
 
-       type_class_unref(_enum->p._class);
+       declaration_unref(_enum->integer);
+       type_unref(_enum->p.type);
        if (_enum->value)
                g_array_unref(_enum->value, TRUE);
        g_free(_enum);
index c78cf584feb4f07f9100ed5f8902a046f1027e01..a945fd290e73308f2f093819ab44c9b485b7a4d9 100644 (file)
 #include <babeltrace/format.h>
 
 static
-struct type_float *_float_type_new(struct type_class *type_class,
+struct declaration *_float_declaration_new(struct type *type,
                                   struct declaration_scope *parent_scope);
 static
-void _float_type_free(struct type *type);
+void _float_declaration_free(struct declaration *declaration);
 
 void float_copy(struct stream_pos *destp,
                const struct format *fdest,
                struct stream_pos *srcp,
                const struct format *fsrc,
-               struct type *type)
+               struct declaration *declaration)
 {
-       struct type_float *_float = container_of(type, struct type_float, p);
-       struct type_class_float *float_class = _float->_class;
+       struct declaration_float *_float =
+               container_of(declaration, struct declaration_float, p);
+       struct type_float *float_type = _float->type;
 
        if (fsrc->float_copy == fdest->float_copy) {
-               fsrc->float_copy(destp, srcp, float_class);
+               fsrc->float_copy(destp, srcp, float_type);
        } else {
                double v;
 
-               v = fsrc->double_read(srcp, float_class);
-               fdest->double_write(destp, float_class, v);
+               v = fsrc->double_read(srcp, float_type);
+               fdest->double_write(destp, float_type, v);
        }
 }
 
 static
-void _float_type_class_free(struct type_class *type_class)
+void _float_type_free(struct type *type)
 {
-       struct type_class_float *float_class =
-               container_of(type_class, struct type_class_float, p);
+       struct type_float *float_type =
+               container_of(type, struct type_float, p);
 
-       type_class_unref(&float_class->exp->p);
-       type_class_unref(&float_class->mantissa->p);
-       type_class_unref(&float_class->sign->p);
-       g_free(float_class);
+       type_unref(&float_type->exp->p);
+       type_unref(&float_type->mantissa->p);
+       type_unref(&float_type->sign->p);
+       g_free(float_type);
 }
 
-struct type_class_float *
-float_type_class_new(const char *name, size_t mantissa_len,
-                    size_t exp_len, int byte_order, size_t alignment)
+struct type_float *
+       float_type_new(const char *name, size_t mantissa_len,
+                      size_t exp_len, int byte_order, size_t alignment)
 {
-       struct type_class_float *float_class;
-       struct type_class *type_class;
+       struct type_float *float_type;
+       struct type *type;
        int ret;
 
-       float_class = g_new(struct type_class_float, 1);
-       type_class = &float_class->p;
-       type_class->name = g_quark_from_string(name);
-       type_class->alignment = alignment;
-       type_class->copy = float_copy;
-       type_class->class_free = _float_type_class_free;
-       type_class->type_new = _float_type_new;
-       type_class->type_free = _float_type_free;
-       type_class->ref = 1;
-       float_class->byte_order = byte_order;
-
-       float_class->sign = integer_type_new(NULL, 1,
-                                            byte_order, false, 1);
-       if (!float_class->mantissa)
+       float_type = g_new(struct type_float, 1);
+       type = &float_type->p;
+       type->name = g_quark_from_string(name);
+       type->alignment = alignment;
+       type->copy = float_copy;
+       type->type_free = _float_type_free;
+       type->declaration_new = _float_declaration_new;
+       type->declaration_free = _float_declaration_free;
+       type->ref = 1;
+       float_type->byte_order = byte_order;
+
+       float_type->sign = integer_type_new(NULL, 1,
+                                           byte_order, false, 1);
+       if (!float_type->mantissa)
                goto error_sign;
-       float_class->mantissa = integer_type_new(NULL, mantissa_len - 1,
-                                                byte_order, false, 1);
-       if (!float_class->mantissa)
+       float_type->mantissa = integer_type_new(NULL, mantissa_len - 1,
+                                               byte_order, false, 1);
+       if (!float_type->mantissa)
                goto error_mantissa;
-       float_class->exp = integer_type_new(NULL, exp_len,
-                                           byte_order, true, 1);
-       if (!float_class->exp)
+       float_type->exp = integer_type_new(NULL, exp_len,
+                                          byte_order, true, 1);
+       if (!float_type->exp)
                goto error_exp;
 
-       if (float_class->p.name) {
-               ret = register_type(&float_class->p);
+       if (float_type->p.name) {
+               ret = register_type(&float_type->p);
                if (ret)
                        goto error_register;
        }
-       return float_class;
+       return float_type;
 
 error_register:
-       type_class_unref(&float_class->exp->p);
+       type_unref(&float_type->exp->p);
 error_exp:
-       type_class_unref(&float_class->mantissa->p);
+       type_unref(&float_type->mantissa->p);
 error_mantissa:
-       type_class_unref(&float_class->sign->p);
+       type_unref(&float_type->sign->p);
 error_sign:
-       g_free(float_class);
+       g_free(float_type);
        return NULL;
 }
 
 static
-struct type_float *_float_type_new(struct type_class *type_class,
-                                  struct declaration_scope *parent_scope)
+struct declaration *
+       _float_declaration_new(struct type *type,
+                              struct declaration_scope *parent_scope)
 {
-       struct type_class_float *float_class =
-               container_of(type_class, struct type_class_float, p);
-       struct type_float *_float;
+       struct type_float *float_type =
+               container_of(type, struct type_float, p);
+       struct declaration_float *_float;
 
-       _float = g_new(struct type_float, 1);
-       type_class_ref(&_float_class->p);
-       _float->p._class = _float_class;
+       _float = g_new(struct declaration_float, 1);
+       type_ref(&_float_type->p);
+       _float->p.type= _float_type;
        _float->p.ref = 1;
        _float->value = 0.0;
        return &_float->p;
 }
 
 static
-void _float_type_free(struct type *type)
+void _float_declaration_free(struct declaration *declaration)
 {
-       struct type_float *_float = container_of(type, struct type_float, p);
+       struct declaration_float *_float =
+               container_of(declaration, struct declaration_float, p);
 
-       type_class_unref(_float->p._class);
+       type_unref(_float->p.type);
        g_free(_float);
 }
index ea292900ce80886141bf21a171ec3b76d2573db8..40deeb2b6f969a2d45ef353359488b1f0c718c93 100644 (file)
 #include <stdint.h>
 
 static
-struct type *_integer_type_new(struct type_class *type_class,
+struct declaration *_integer_declaration_new(struct type *type,
                               struct declaration_scope *parent_scope);
 static
-void _integer_type_free(struct type *type);
+void _integer_declaration_free(struct declaration *declaration);
 
 void integer_copy(struct stream_pos *dest, const struct format *fdest, 
                  struct stream_pos *src, const struct format *fsrc,
-                 struct type *type)
+                 struct declaration *declaration)
 {
-       struct type_integer *integer = container_of(type, struct type_integer,
-                                                   p);
-       struct type_class_integer *int_class = integer->_class;
+       struct declaration_integer *integer =
+               container_of(type, struct declaration_integer, p);
+       struct type_integer *integer_type = integer->type;
 
-       if (!int_class->signedness) {
+       if (!integer_type->signedness) {
                uint64_t v;
 
-               v = fsrc->uint_read(src, int_class);
-               fdest->uint_write(dest, int_class, v);
+               v = fsrc->uint_read(src, integer_type);
+               fdest->uint_write(dest, integer_type, v);
        } else {
                int64_t v;
 
-               v = fsrc->int_read(src, int_class);
-               fdest->int_write(dest, int_class, v);
+               v = fsrc->int_read(src, integer_type);
+               fdest->int_write(dest, integer_type, v);
        }
 }
 
 static
-void _integer_type_class_free(struct type_class *type_class)
+void _integer_type_free(struct type *type)
 {
-       struct type_class_integer *integer_class =
-               container_of(type_class, struct type_class_integer, p);
-       g_free(integer_class);
+       struct type_integer *integer_type =
+               container_of(type, struct type_integer, p);
+       g_free(integer_type);
 }
 
-struct type_class_integer *
-integer_type_class_new(const char *name, size_t len, int byte_order,
-                      int signedness, size_t alignment)
+struct type_integer *
+       integer_type_new(const char *name, size_t len, int byte_order,
+                        int signedness, size_t alignment)
 {
-       struct type_class_integer *int_class;
+       struct type_integer *integer_type;
        int ret;
 
-       int_class = g_new(struct type_class_integer, 1);
-       int_class->p.name = g_quark_from_string(name);
-       int_class->p.alignment = alignment;
-       int_class->p.copy = integer_copy;
-       int_class->p.class_free = _integer_type_class_free;
-       int_class->p.type_free = _integer_type_free;
-       int_class->p.type_new = _integer_type_new;
-       int_class->p.ref = 1;
-       int_class->len = len;
-       int_class->byte_order = byte_order;
-       int_class->signedness = signedness;
-       if (int_class->p.name) {
-               ret = register_type(&int_class->p);
+       integer_type = g_new(struct type_integer, 1);
+       integer_type->p.name = g_quark_from_string(name);
+       integer_type->p.alignment = alignment;
+       integer_type->p.copy = integer_copy;
+       integer_type->p.type_free = _integer_type_free;
+       integer_type->p.declaration_free = _integer_declaration_free;
+       integer_type->p.declaration_new = _integer_declaration_new;
+       integer_type->p.ref = 1;
+       integer_type->len = len;
+       integer_type->byte_order = byte_order;
+       integer_type->signedness = signedness;
+       if (integer_type->p.name) {
+               ret = register_type(&integer_type->p);
                if (ret) {
-                       g_free(int_class);
+                       g_free(integer_type);
                        return NULL;
                }
        }
-       return int_class;
+       return integer_type;
 }
 
 static
-struct type_integer *_integer_type_new(struct type_class *type_class,
-                                      struct declaration_scope *parent_scope)
+struct declaration *
+       _integer_declaration_new(struct type *type,
+                                struct declaration_scope *parent_scope)
 {
-       struct type_class_integer *integer_class =
-               container_of(type_class, struct type_class_integer, p);
-       struct type_integer *integer;
+       struct type_integer *integer_type =
+               container_of(type, struct type_integer, p);
+       struct declaration_integer *integer;
 
-       integer = g_new(struct type_integer, 1);
-       type_class_ref(&integer_class->p);
-       integer->p._class = integer_class;
+       integer = g_new(struct declaration_integer, 1);
+       type_ref(&integer_type->p);
+       integer->p.type = integer_type;
        integer->p.ref = 1;
        integer->value._unsigned = 0;
        return &integer->p;
 }
 
 static
-void _integer_type_free(struct type *type)
+void _integer_declaration_free(struct declaration *declaration)
 {
-       struct type_integer *integer =
-               container_of(type, struct type_integer, p);
+       struct declaration_integer *integer =
+               container_of(declaration, struct declaration_integer, p);
 
-       type_class_unref(integer->p._class);
+       type_unref(integer->p.type);
        g_free(integer);
 }
index 8f3fed9aff924105dee3220b67475f6a832dcc08..40a6998376b2e02b386edd2c1df40ebc9ea9e7d0 100644 (file)
 #endif
 
 static
-struct type *_sequence_type_new(struct type_class *type_class,
-                               struct declaration_scope *parent_scope);
+struct declaration *_sequence_declaration_new(struct type *type,
+                                       struct declaration_scope *parent_scope);
 static
-void _sequence_type_free(struct type *type);
+void _sequence_declaration_free(struct declaration *declaration);
 
 void sequence_copy(struct stream_pos *dest, const struct format *fdest, 
                   struct stream_pos *src, const struct format *fsrc,
-                  struct type *type)
+                  struct declaration *declaration)
 {
-       struct type_sequence *sequence =
-               container_of(type, struct type_sequence, p);
-       struct type_class_sequence *sequence_class = sequence->_class;
+       struct declaration_sequence *sequence =
+               container_of(declaration, struct declaration_sequence, p);
+       struct type_sequence *sequence_type = sequence->type;
        uint64_t i;
 
-       fsrc->sequence_begin(src, sequence);
-       fdest->sequence_begin(dest, sequence);
+       fsrc->sequence_begin(src, sequence_type);
+       fdest->sequence_begin(dest, sequence_type);
 
-       sequence->len->p._class->copy(dest, fdest, src, fsrc,
-                                     &sequence->len->p);
+       sequence->len->p.type->copy(dest, fdest, src, fsrc,
+                                   &sequence->len->p);
 
        for (i = 0; i < sequence->len->value._unsigned; i++) {
-               struct type *elem_type = sequence->current_element.type;
-               elem_type->p._class->copy(dest, fdest, src, fsrc, elem_type);
+               struct declaration *elem_type =
+                       sequence->current_element.declaration;
+               elem_type->p.type->copy(dest, fdest, src, fsrc, elem_type);
        }
-       fsrc->sequence_end(src, sequence);
-       fdest->sequence_end(dest, sequence);
+       fsrc->sequence_end(src, sequence_type);
+       fdest->sequence_end(dest, sequence_type);
 }
 
 static
-void _sequence_type_class_free(struct type_class *type_class)
+void _sequence_type_free(struct type *type)
 {
-       struct type_class_sequence *sequence_class =
-               container_of(type_class, struct type_class_sequence, p);
+       struct type_sequence *sequence_type =
+               container_of(type, struct type_sequence, p);
 
-       type_class_unref(&sequence_class->len_class->p);
-       type_class_unref(sequence_class->elem);
-       g_free(sequence_class);
+       type_unref(&sequence_type->len_type->p);
+       type_unref(sequence_type->elem);
+       g_free(sequence_type);
 }
 
-struct type_class_sequence *
-sequence_type_class_new(const char *name, struct type_class_integer *len_class,
-                       struct type_class *elem)
+struct type_sequence *
+       sequence_type_new(const char *name, struct type_integer *len_type,
+                         struct type *elem_type)
 {
-       struct type_class_sequence *sequence_class;
-       struct type_class *type_class;
+       struct type_sequence *sequence_type;
+       struct type *type;
        int ret;
 
-       sequence_class = g_new(struct type_class_sequence, 1);
-       type_class = &sequence_class->p;
-       assert(!len_class->signedness);
-       type_ref(&len_class->p);
-       sequence_class->len_class = len_class;
-       type_ref(elem);
-       sequence_class->elem = elem;
-       type_class->name = g_quark_from_string(name);
-       type_class->alignment = max(len_class->p.alignment,
-                                   elem->alignment);
-       type_class->copy = sequence_copy;
-       type_class->class_free = _sequence_type_class_free;
-       type_class->type_new = _sequence_type_new;
-       type_class->type_free = _sequence_type_free;
-       type_class->ref = 1;
-
-       if (type_class->name) {
-               ret = register_type(type_class);
+       sequence_type = g_new(struct type_sequence, 1);
+       type = &sequence_type->p;
+       assert(!len_type->signedness);
+       type_ref(&len_type->p);
+       sequence_type->len_type = len_type;
+       type_ref(elem_type);
+       sequence_type->elem = elem_type;
+       type->name = g_quark_from_string(name);
+       type->alignment = max(len_type->p.alignment, elem_type->alignment);
+       type->copy = sequence_copy;
+       type->type_free = _sequence_type_free;
+       type->declaration_new = _sequence_declaration_new;
+       type->declaration_free = _sequence_declaration_free;
+       type->ref = 1;
+
+       if (type->name) {
+               ret = register_type(type);
                if (ret)
                        goto error_register;
        }
-       return sequence_class;
+       return sequence_type;
 
 error_register:
-       type_class_unref(&len_class->p);
-       type_class_unref(elem);
-       g_free(sequence_class);
+       type_unref(&len_type->p);
+       type_unref(elem_type);
+       g_free(sequence_type);
        return NULL;
 }
 
 static
-struct type *_sequence_type_new(struct type_class *type_class,
+struct declaration *_sequence_declaration_new(struct type *type,
                                struct declaration_scope *parent_scope)
 {
-       struct type_class_sequence *sequence_class =
-               container_of(type_class, struct type_class_sequence, p);
-       struct type_sequence *sequence;
+       struct type_sequence *sequence_type =
+               container_of(type, struct type_sequence, p);
+       struct declaration_sequence *sequence;
+       struct declaration *len_parent;
 
-       sequence = g_new(struct type_sequence, 1);
-       type_class_ref(&sequence_class->p);
-       sequence->p._class = sequence_class;
+       sequence = g_new(struct declaration_sequence, 1);
+       type_ref(&sequence_type->p);
+       sequence->p.type = sequence_type;
        sequence->p.ref = 1;
        sequence->scope = new_declaration_scope(parent_scope);
-       sequence->len.type =
-               sequence_class->len_class.p->type_new(&sequence_class->len_class.p,
-                                                     parent_scope);
-       sequence->current_element.type =
-               sequence_class->elem.p->type_new(&sequence_class->elem.p,
-                                                parent_scope);
+       len_parent = 
+               sequence_type->len_type.p->type_new(&sequence_type->len_type.p,
+                                                   parent_scope);
+       sequence->len =
+               container_of(len_parent, struct declaration_integer, p);
+       sequence->current_element.declaration =
+               sequence_type->elem.p->type_new(&sequence_type->elem.p,
+                                               parent_scope);
        return &sequence->p;
 }
 
 static
-void _sequence_type_free(struct type *type)
+void _sequence_declaration_free(struct declaration *declaration)
 {
        struct type_sequence *sequence =
-               container_of(type, struct type_sequence, p);
-       struct type *len_type = sequence->len.type;
-       struct type *elem_type = sequence->current_element.type;
+               container_of(declaration, struct type_sequence, p);
+       struct declaration *len_declaration = sequence->len;
+       struct declaration *elem_declaration =
+               sequence->current_element.declaration;
 
-       len_type->p._class->type_free(len_type);
-       elem_type->p._class->type_free(elem_type);
+       len_declaration->p.type->declaration_free(len_declaration);
+       elem_declaration->p.type->declaration_free(elem_declaration);
        free_declaration_scope(sequence->scope);
-       type_class_unref(sequence->p._class);
+       type_unref(sequence->p.type);
        g_free(sequence);
 }
index e76ac77ae7620def6537f415642ef8375bd9210d..3b3cb07416cce808e4f5c299d92b5c4220b1fcb3 100644 (file)
 #include <babeltrace/format.h>
 
 static
-struct type_string *_string_type_new(struct type_class *type_class,
-                                    struct declaration_scope *parent_scope);
+struct declaration *_string_declaration_new(struct type *type,
+                               struct declaration_scope *parent_scope);
 static
-void _string_type_free(struct type *type);
+void _string_declaration_free(struct declaration *declaration);
 
 void string_copy(struct stream_pos *dest, const struct format *fdest, 
                 struct stream_pos *src, const struct format *fsrc,
-                struct type *type)
+                struct declaration *declaration)
 {
-       struct type_string *string = container_of(type, struct type_string, p);
-       struct type_class_string *string_class = string->_class;
+       struct declaration_string *string =
+               container_of(declaration, struct declaration_string, p);
+       struct type_string *string_type = string->type;
 
        if (fsrc->string_copy == fdest->string_copy) {
-               fsrc->string_copy(dest, src, string_class);
+               fsrc->string_copy(dest, src, string_type);
        } else {
                char *tmp = NULL;
 
-               fsrc->string_read(&tmp, src, string_class);
-               fdest->string_write(dest, tmp, string_class);
+               fsrc->string_read(&tmp, src, string_type);
+               fdest->string_write(dest, tmp, string_type);
                fsrc->string_free_temp(tmp);
        }
 }
 
 static
-void _string_type_class_free(struct type_class_string *string_class)
+void _string_type_free(struct type *type)
 {
-       struct type_class_string *string_class =
-               container_of(type_class, struct type_class_string, p);
-       g_free(string_class);
+       struct type_string *string_type =
+               container_of(type, struct type_string, p);
+       g_free(string_type);
 }
 
-struct type_class_string *
-string_type_class_new(const char *name)
+struct type_string *string_type_new(const char *name)
 {
-       struct type_class_string *string_class;
+       struct type_string *string_type;
        int ret;
 
-       string_class = g_new(struct type_class_string, 1);
-       string_class->p.name = g_quark_from_string(name);
-       string_class->p.alignment = CHAR_BIT;
-       string_class->p.copy = string_copy;
-       string_class->p.class_free = _string_type_class_free;
-       string_class->p.type_new = _string_type_new;
-       string_class->p.type_free = _string_type_free;
-       string_class->p.ref = 1;
-       if (string_class->p.name) {
-               ret = register_type(&string_class->p);
+       string_type = g_new(struct type_string, 1);
+       string_type->p.name = g_quark_from_string(name);
+       string_type->p.alignment = CHAR_BIT;
+       string_type->p.copy = string_copy;
+       string_type->p.type_free = _string_type_free;
+       string_type->p.declaration_new = _string_declaration_new;
+       string_type->p.declaration_free = _strin_declaration_free;
+       string_type->p.ref = 1;
+       if (string_type->p.name) {
+               ret = register_type(&string_type->p);
                if (ret) {
-                       g_free(string_class);
+                       g_free(string_type);
                        return NULL;
                }
        }
-       return string_class;
+       return string_type;
 }
 
 static
-struct type_string *_string_type_new(struct type_class *type_class,
-                                    struct declaration_scope *parent_scope)
+struct declaration *
+       _string_declaration_new(struct type *type,
+                               struct declaration_scope *parent_scope)
 {
-       struct type_class_string *string_class =
-               container_of(type_class, struct type_class_string, p);
-       struct type_string *string;
+       struct type_string *string_type =
+               container_of(type, struct type_string, p);
+       struct declaration_string *string;
 
-       string = g_new(struct type_string, 1);
-       type_class_ref(&string_class->p);
-       string->p._class = string_class;
+       string = g_new(struct declaration_string, 1);
+       type_ref(&string_type->p);
+       string->p.type = string_type;
        string->p.ref = 1;
        string->value = NULL;
        return &string->p;
 }
 
 static
-void _string_type_free(struct type *type)
+void _string_declaration_free(struct declaration *declaration)
 {
-       struct type_string *string =
-               container_of(type, struct type_string, p);
+       struct declaration_string *string =
+               container_of(declaration, struct declaration_string, p);
 
-       type_class_unref(string->p._class);
+       type_unref(string->p.type);
        g_free(string->value);
        g_free(string);
 }
index 1e1b458a91f531445fad1409c4c6a089d75972ab..ba3295f9a67eeedfe286dd2f812f76bebac03bfe 100644 (file)
 #endif
 
 static
-struct type *_struct_type_new(struct type_class *type_class,
-                            struct declaration_scope *parent_scope);
+struct declaration *_struct_declaration_new(struct type *type,
+                               struct declaration_scope *parent_scope);
 static
-void _struct_type_free(struct type *type);
+void _struct_declaration_free(struct declaration *declaration);
 
 void struct_copy(struct stream_pos *dest, const struct format *fdest, 
                 struct stream_pos *src, const struct format *fsrc,
-                struct type *type)
+                struct declaration *declaration)
 {
-       struct type_struct *_struct = container_of(type, struct type_struct, p);
-       struct type_class_struct *struct_class = _struct->_class;
+       struct declaration_struct *_struct =
+               container_of(declaration, struct declaration_struct, p);
+       struct type_struct *struct_type = _struct->type;
        unsigned long i;
 
-       fsrc->struct_begin(src, struct_class);
-       fdest->struct_begin(dest, struct_class);
+       fsrc->struct_begin(src, struct_type);
+       fdest->struct_begin(dest, struct_type);
 
        for (i = 0; i < _struct->fields->len; i++) {
                struct field *field = &g_array_index(_struct->fields,
                                                     struct field, i);
-               struct type_class *field_class = field->type->p._class;
+               struct type *field_type = field->type->p.type;
 
-               field_class->copy(dest, fdest, src, fsrc, &field->type->p);
+               field_type->copy(dest, fdest, src, fsrc, &field->type->p);
 
        }
-       fsrc->struct_end(src, struct_class);
-       fdest->struct_end(dest, struct_class);
+       fsrc->struct_end(src, struct_type);
+       fdest->struct_end(dest, struct_type);
 }
 
 static
-void _struct_type_class_free(struct type_class *type_class)
+void _struct_type_free(struct type *type)
 {
-       struct type_class_struct *struct_class =
-               container_of(type_class, struct type_class_struct, p);
+       struct type_struct *struct_type =
+               container_of(type, struct type_struct, p);
        unsigned long i;
 
-       g_hash_table_destroy(struct_class->fields_by_name);
+       g_hash_table_destroy(struct_type->fields_by_name);
 
-       for (i = 0; i < struct_class->fields->len; i++) {
-               struct field *type_class_field =
-                       &g_array_index(struct_class->fields,
-                                      struct type_class_field, i);
-               type_class_unref(field->type_class);
+       for (i = 0; i < struct_type->fields->len; i++) {
+               struct field *type_field =
+                       &g_array_index(struct_type->fields,
+                                      struct type_field, i);
+               type_unref(field->type);
        }
-       g_array_free(struct_class->fields, true);
-       g_free(struct_class);
+       g_array_free(struct_type->fields, true);
+       g_free(struct_type);
 }
 
-struct type_class_struct *
-struct_type_class_new(const char *name)
+struct type_struct *struct_type_new(const char *name)
 {
-       struct type_class_struct *struct_class;
-       struct type_class *type_class;
+       struct type_struct *struct_type;
+       struct type *type;
        int ret;
 
-       struct_class = g_new(struct type_class_struct, 1);
-       type_class = &struct_class->p;
-       struct_class->fields_by_name = g_hash_table_new(g_direct_hash,
-                                                       g_direct_equal);
-       struct_class->fields = g_array_sized_new(FALSE, TRUE,
-                                                sizeof(struct type_class_field),
-                                                DEFAULT_NR_STRUCT_FIELDS);
-       type_class->name = g_quark_from_string(name);
-       type_class->alignment = 1;
-       type_class->copy = struct_copy;
-       type_class->class_free = _struct_type_class_free;
-       type_class->type_new = _struct_type_new;
-       type_class->type_free = _struct_type_free;
-       type_class->ref = 1;
-
-       if (type_class->name) {
-               ret = register_type(type_class);
+       struct_type = g_new(struct type_struct, 1);
+       type = &struct_type->p;
+       struct_type->fields_by_name = g_hash_table_new(g_direct_hash,
+                                                      g_direct_equal);
+       struct_type->fields = g_array_sized_new(FALSE, TRUE,
+                                               sizeof(struct type_field),
+                                               DEFAULT_NR_STRUCT_FIELDS);
+       type->name = g_quark_from_string(name);
+       type->alignment = 1;
+       type->copy = struct_copy;
+       type->type_free = _struct_type_free;
+       type->declaration_new = _struct_declaration_new;
+       type->declaration_free = _struct_declaration_free;
+       type->ref = 1;
+
+       if (type->name) {
+               ret = register_type(type);
                if (ret)
                        goto error_register;
        }
-       return struct_class;
+       return struct_type;
 
 error_register:
-       g_hash_table_destroy(struct_class->fields_by_name);
-       g_array_free(struct_class->fields, true);
-       g_free(struct_class);
+       g_hash_table_destroy(struct_type->fields_by_name);
+       g_array_free(struct_type->fields, true);
+       g_free(struct_type);
        return NULL;
 }
 
 static
-struct type_struct *_struct_type_new(struct type_class *type_class,
-                                    struct declaration_scope *parent_scope)
+struct declaration *
+       _struct_declaration_new(struct type *type,
+                               struct declaration_scope *parent_scope)
 {
-       struct type_class_struct *_struct_class =
-               container_of(type_class, struct type_class_struct, p);
-       struct type_struct *_struct;
+       struct type_struct *struct_type =
+               container_of(type, struct type_struct, p);
+       struct declaration_struct *_struct;
 
-       _struct = g_new(struct type_struct, 1);
-       type_class_ref(&_struct_class->p);
-       _struct->p._class = _struct_class;
+       _struct = g_new(struct declaration_struct, 1);
+       type_ref(&struct_type->p);
+       _struct->p.type = struct_type;
        _struct->p.ref = 1;
        _struct->scope = new_declaration_scope(parent_scope);
        _struct->fields = g_array_sized_new(FALSE, TRUE,
@@ -127,53 +128,54 @@ struct type_struct *_struct_type_new(struct type_class *type_class,
 }
 
 static
-void _struct_type_free(struct type *type)
+void _struct_declaration_free(struct declaration *declaration)
 {
-       struct type_struct *_struct = container_of(type, struct type_struct, p);
+       struct declaration_struct *_struct =
+               container_of(declaration, struct declaration_struct, p);
        unsigned long i;
 
        for (i = 0; i < _struct->fields->len; i++) {
                struct field *field = &g_array_index(_struct->fields,
                                                     struct field, i);
-               type_unref(field->type);
+               declaration_unref(field->declaration);
        }
        free_declaration_scope(_struct->scope);
-       type_class_unref(_struct->p._class);
+       type_unref(_struct->p.type);
        g_free(_struct);
 }
 
-void struct_type_class_add_field(struct type_class_struct *struct_class,
-                                const char *field_name,
-                                struct type_class *type_class)
+void struct_type_add_field(struct type_struct *struct_type,
+                          const char *field_name,
+                          struct type *field_type)
 {
-       struct type_class_field *field;
+       struct type_field *field;
        unsigned long index;
 
-       g_array_set_size(struct_class->fields, struct_class->fields->len + 1);
-       index = struct_class->fields->len - 1;  /* last field (new) */
-       field = &g_array_index(struct_class->fields, struct type_class_field, index);
+       g_array_set_size(struct_type->fields, struct_type->fields->len + 1);
+       index = struct_type->fields->len - 1;   /* last field (new) */
+       field = &g_array_index(struct_type->fields, struct type_field, index);
        field->name = g_quark_from_string(field_name);
-       type_ref(type_class);
-       field->type_class = type_class;
+       type_ref(field_type);
+       field->type = field_type;
        /* Keep index in hash rather than pointer, because array can relocate */
-       g_hash_table_insert(struct_class->fields_by_name,
+       g_hash_table_insert(struct_type->fields_by_name,
                            (gpointer) (unsigned long) field->name,
                            (gpointer) index);
        /*
         * Alignment of structure is the max alignment of types contained
         * therein.
         */
-       struct_class->p.alignment = max(struct_class->p.alignment,
-                                       type_class->alignment);
+       struct_type->p.alignment = max(struct_type->p.alignment,
+                                      field_type->alignment);
 }
 
 unsigned long
-struct_type_class_lookup_field_index(struct type_class_struct *struct_class,
-                                    GQuark field_name)
+       struct_type_lookup_field_index(struct type_struct *struct_type,
+                                      GQuark field_name)
 {
        unsigned long index;
 
-       index = (unsigned long) g_hash_table_lookup(struct_class->fields_by_name,
+       index = (unsigned long) g_hash_table_lookup(struct_type->fields_by_name,
                                                    (gconstpointer) (unsigned long) field_name);
        return index;
 }
@@ -181,19 +183,19 @@ struct_type_class_lookup_field_index(struct type_class_struct *struct_class,
 /*
  * field returned only valid as long as the field structure is not appended to.
  */
-struct type_class_field *
-struct_type_class_get_field_from_index(struct type_class_struct *struct_class,
-                                      unsigned long index)
+struct type_field *
+       struct_type_get_field_from_index(struct type_struct *struct_type,
+                                        unsigned long index)
 {
-       return &g_array_index(struct_class->fields, struct type_class_field, index);
+       return &g_array_index(struct_type->fields, struct type_field, index);
 }
 
 /*
  * field returned only valid as long as the field structure is not appended to.
  */
 struct field *
-struct_type_get_field_from_index(struct type_struct *struct_type,
-                                unsigned long index)
+struct_declaration_get_field_from_index(struct declaration_struct *_struct,
+                                       unsigned long index)
 {
-       return &g_array_index(struct_type->fields, struct field, index);
+       return &g_array_index(_struct->fields, struct field, index);
 }
index 961337800a1e45472a2abd175de21448726884d5..b766f8d8d4cb415e23011c82eaf217ded71b110a 100644 (file)
 #include <errno.h>
 
 static
-struct type_class *lookup_type_class_scope(GQuark qname,
-                                          struct declaration_scope *scope)
+struct type *lookup_type_scope(GQuark qname, struct declaration_scope *scope)
 {
-       return g_hash_table_lookup(scope->type_classes,
+       return g_hash_table_lookup(scope->types,
                                   (gconstpointer) (unsigned long) qname);
 }
 
-struct type_class *lookup_type_class(GQuark qname,
-                                    struct declaration_scope *scope)
+struct type *lookup_type(GQuark qname, struct declaration_scope *scope)
 {
-       struct type_class *tc;
+       struct type *type;
 
        while (scope) {
-               tc = lookup_type_class_scope(qname, scope);
-               if (tc)
-                       return tc;
+               type = lookup_type_scope(qname, scope);
+               if (type)
+                       return type;
                scope = scope->parent_scope;
        }
        return NULL;
 }
 
-static void free_type_class(struct type_class *type_class)
+static void free_type(struct type *type)
 {
-       type_class->class_free(type_class);
+       type->type_free(type);
 }
 
-static void free_type(struct type *type)
+static void free_declaration(struct declaration *declaration)
 {
-       type->p.type_free(type);
+       declaration->p.declaration_free(declaration);
 }
 
-int register_type_class(struct type_class *type_class,
-                       struct declaration_scope *scope)
+int register_type(struct type *type, struct declaration_scope *scope)
 {
        /* Only lookup in local scope */
-       if (lookup_type_class_scope(type_class->name, scope))
+       if (lookup_type_scope(type->name, scope))
                return -EEXIST;
 
-       g_hash_table_insert(scope->type_classes,
-                           (gpointer) (unsigned long) type_class->name,
-                           type_class);
+       g_hash_table_insert(scope->types,
+                           (gpointer) (unsigned long) type->name,
+                           type);
        return 0;
 }
 
-void type_class_ref(struct type_class *type_class)
+void type_ref(struct type *type)
 {
-       type_class->ref++;
+       type->ref++;
 }
 
-void type_class_unref(struct type_class *type_class)
+void type_unref(struct type *type)
 {
-       if (!--type_class->ref)
-               free_type_class(type_class);
+       if (!--type->ref)
+               free_type(type);
 }
 
-void type_ref(struct type *type)
+void declaration_ref(struct declaration *declaration)
 {
-       type->ref++;
+       declaration->ref++;
 }
 
-void type_unref(struct type *type)
+void declaration_unref(struct declaration *declaration)
 {
-       if (!--type->ref)
-               free_type(type);
+       if (!--declaration->ref)
+               free_declaration(declaration);
 }
 
 struct declaration_scope *
-new_declaration_scope(struct declaration_scope *parent_scope)
+       new_declaration_scope(struct declaration_scope *parent_scope)
 {
        struct declaration_scope *scope = g_new(struct declaration_scope, 1);
 
-       scope->type_classes = g_hash_table_new_full(g_direct_hash,
+       scope->types = g_hash_table_new_full(g_direct_hash,
                                        g_direct_equal, NULL,
-                                       (GDestroyNotify) type_class_unref);
+                                       (GDestroyNotify) type_unref);
        scope->parent_scope = parent_scope;
        return scope;
 }
 
 void free_declaration_scope(struct declaration_scope *scope)
 {
-       g_hash_table_destroy(scope->type_classes);
+       g_hash_table_destroy(scope->types);
        g_free(scope);
 }
index 76573085d72510d547348ba2e533e968c0c03385..87cf9632a8a4b868602f92bb6c4e3e4d3375bf02 100644 (file)
 
 
 static
-struct type *variant_type_new(struct type_class *type_class,
-                             struct declaration_scope *parent_scope);
+struct declaration *_variant_declaration_new(struct type *type,
+                               struct declaration_scope *parent_scope);
 static
-void variant_type_free(struct type *type);
+void _variant_declaration_free(struct declaration *declaration);
 
 void variant_copy(struct stream_pos *dest, const struct format *fdest, 
                  struct stream_pos *src, const struct format *fsrc,
-                 struct type *type)
+                 struct declaration *declaration)
 {
-       struct type_variant *variant = container_of(type, struct type_variant,
-                                                   p);
-       struct type_class_variant *variant_class = variant->_class;
+       struct declaration_variant *variant =
+               container_of(declaration, struct declaration_variant, p);
+       struct type_variant *variant_type = variant->type;
        struct field *field;
-       struct type_class *field_class;
+       struct type *field_type;
        unsigned long i;
 
-       fsrc->variant_begin(src, variant_class);
-       fdest->variant_begin(dest, variant_class);
+       fsrc->variant_begin(src, variant_type);
+       fdest->variant_begin(dest, variant_type);
 
-       field = variant_type_get_current_field(variant);
-       field_class = field->type->p._class;
-       field_class->copy(dest, fdest, src, fsrc, &field->type->p);
+       field = variant_get_current_field(variant);
+       field_type = field->type->p.type;
+       field_type->copy(dest, fdest, src, fsrc, &field->type->p);
 
-       fsrc->variant_end(src, variant_class);
-       fdest->variant_end(dest, variant_class);
+       fsrc->variant_end(src, variant_type);
+       fdest->variant_end(dest, variant_type);
 }
 
 static
-void variant_type_class_free(struct type_class *type_class)
+void _variant_type_free(struct type *type)
 {
-       struct type_class_variant *variant_class =
-               container_of(type_class, struct type_class_variant, p);
+       struct type_variant *variant_type =
+               container_of(type, struct type_variant, p);
        unsigned long i;
 
-       g_hash_table_destroy(struct_class->fields_by_tag);
+       g_hash_table_destroy(variant_type->fields_by_tag);
 
-       for (i = 0; i < variant_class->fields->len; i++) {
-               struct field *type_class_field =
-                       &g_array_index(variant_class->fields,
-                                      struct type_class_field, i);
-               type_class_unref(field->type_class);
+       for (i = 0; i < variant_type->fields->len; i++) {
+               struct field *type_field =
+                       &g_array_index(variant_type->fields,
+                                      struct type_field, i);
+               type_unref(field->type);
        }
-       g_array_free(variant_class->fields, true);
-       g_free(variant_class);
+       g_array_free(variant_type->fields, true);
+       g_free(variant_type);
 }
 
-struct type_class_variant *
-variant_type_class_new(const char *name)
+struct type_variant *variant_type_new(const char *name)
 {
-       struct type_class_variant *variant_class;
-       struct type_class *type_class;
+       struct type_variant *variant_type;
+       struct type *type;
        int ret;
 
-       variant_class = g_new(struct type_class_variant, 1);
-       type_class = &variant_class->p;
-       variant_class->fields_by_tag = g_hash_table_new(g_direct_hash,
-                                                       g_direct_equal);
-       variant_class->fields = g_array_sized_new(FALSE, TRUE,
-                                                 sizeof(struct type_class_field),
-                                                 DEFAULT_NR_STRUCT_FIELDS);
-       type_class->name = g_quark_from_string(name);
-       type_class->alignment = 1;
-       type_class->copy = variant_copy;
-       type_class->class_free = _variant_type_class_free;
-       type_class->type_new = _variant_type_new;
-       type_class->type_free = _variant_type_free;
-       type_class->ref = 1;
-
-       if (type_class->name) {
-               ret = register_type(type_class);
+       variant_type = g_new(struct type_variant, 1);
+       type = &variant_type->p;
+       variant_type->fields_by_tag = g_hash_table_new(g_direct_hash,
+                                                      g_direct_equal);
+       variant_type->fields = g_array_sized_new(FALSE, TRUE,
+                                                sizeof(struct type_field),
+                                                DEFAULT_NR_STRUCT_FIELDS);
+       type->name = g_quark_from_string(name);
+       type->alignment = 1;
+       type->copy = variant_copy;
+       type->type_free = _variant_type_free;
+       type->declaration_new = _variant_declaration_new;
+       type->declaration_free = _variant_declaration_free;
+       type->ref = 1;
+
+       if (type->name) {
+               ret = register_type(type);
                if (ret)
                        goto error_register;
        }
-       return struct_class;
+       return variant_type;
 
 error_register:
-       g_hash_table_destroy(variant_class->fields_by_tag);
-       g_array_free(variant_class->fields, true);
-       g_free(variant_class);
+       g_hash_table_destroy(variant_type->fields_by_tag);
+       g_array_free(variant_type->fields, true);
+       g_free(variant_type);
        return NULL;
 }
 
 static
-struct type_variant *_variant_type_new(struct type_class *type_class,
-                                      struct declaration_scope *parent_scope)
+struct declaration *
+       _variant_declaration_new(struct type *type,
+                                struct declaration_scope *parent_scope)
 {
-       struct type_class_variant *variant_class =
-               container_of(type_class, struct type_class_variant, p);
-       struct type_struct *variant;
+       struct type_variant *variant_type =
+               container_of(type, struct type_variant, p);
+       struct declaration_variant *variant;
 
-       variant = g_new(struct type_variant, 1);
-       type_class_ref(&variant_class->p);
-       variant->p._class = variant_class;
+       variant = g_new(struct declaration_variant, 1);
+       type_ref(&variant_type->p);
+       variant->p.type = variant_type;
        variant->p.ref = 1;
        variant->scope = new_declaration_scope(parent_scope);
        variant->fields = g_array_sized_new(FALSE, TRUE,
@@ -124,37 +124,37 @@ struct type_variant *_variant_type_new(struct type_class *type_class,
 }
 
 static
-void variant_type_free(struct type *type)
+void variant_declaration_free(struct declaration *declaration)
 {
-       struct type_variant *variant = container_of(type, struct type_variant,
-                                                   p);
+       struct declaration_variant *variant =
+               container_of(declaration, struct declaration_variant, p);
        unsigned long i;
 
        for (i = 0; i < variant->fields->len; i++) {
                struct field *field = &g_array_index(variant->fields,
                                                     struct field, i);
-               type_unref(field->type);
+               declaration_unref(field->declaration);
        }
        free_declaration_scope(variant->scope);
-       type_class_unref(variant->p._class);
+       type_unref(variant->p.type);
        g_free(variant);
 }
 
-void variant_type_class_add_field(struct type_class_variant *variant_class,
-                                 const char *tag_name,
-                                 struct type_class *type_class)
+void variant_type_add_field(struct type_variant *variant_type,
+                           const char *tag_name,
+                           struct type *tag_type)
 {
-       struct type_class_field *field;
+       struct type_field *field;
        unsigned long index;
 
-       g_array_set_size(variant_class->fields, variant_class->fields->len + 1);
-       index = variant_class->fields->len - 1; /* last field (new) */
-       field = &g_array_index(variant_class->fields, struct type_class_field, index);
+       g_array_set_size(variant_type->fields, variant_type->fields->len + 1);
+       index = variant_type->fields->len - 1;  /* last field (new) */
+       field = &g_array_index(variant_type->fields, struct type_field, index);
        field->name = g_quark_from_string(tag_name);
-       type_ref(type_class);
-       field->type_class = type_class;
+       type_ref(tag_type);
+       field->type = tag_type;
        /* Keep index in hash rather than pointer, because array can relocate */
-       g_hash_table_insert(variant_class->fields_by_name,
+       g_hash_table_insert(variant_type->fields_by_name,
                            (gpointer) (unsigned long) field->name,
                            (gpointer) index);
        /*
@@ -164,26 +164,25 @@ void variant_type_class_add_field(struct type_class_variant *variant_class,
         */
 }
 
-struct type_class_field *
-struct_type_class_get_field_from_tag(struct type_class_variant *variant_class,
-                                    GQuark tag)
+struct type_field *
+struct_type_get_field_from_tag(struct type_variant *variant_type, GQuark tag)
 {
        unsigned long index;
 
-       index = (unsigned long) g_hash_table_lookup(variant_class->fields_by_tag,
+       index = (unsigned long) g_hash_table_lookup(variant_type->fields_by_tag,
                                                    (gconstpointer) (unsigned long) tag);
-       return &g_array_index(variant_class->fields, struct type_class_field, index);
+       return &g_array_index(variant_type->fields, struct type_field, index);
 }
 
 /*
  * tag_instance is assumed to be an enumeration.
  */
-int variant_type_set_tag(struct type_variant *variant,
-                        struct type *enum_tag_instance)
+int variant_declaration_set_tag(struct declaration_variant *variant,
+                               struct declaration *enum_tag)
 {
-       struct type_enum *_enum =
-               container_of(struct type_enum, variant->enum_tag, p);
-       struct type_class_enum *enum_class = _enum->_class;
+       struct declaration_enum *_enum =
+               container_of(variant->enum_tag, struct declaration_enum, p);
+       struct type_enum *enum_type = _enum->type;
        int missing_field = 0;
        unsigned long i;
 
@@ -193,14 +192,14 @@ int variant_type_set_tag(struct type_variant *variant,
         * variant choice map to an enumerator too. We then validate that the
         * number of enumerators equals the number of variant choices.
         */
-       if (variant->_class->fields->len != enum_get_nr_enumerators(enum_class))
+       if (variant->type->fields->len != enum_get_nr_enumerators(enum_type))
                return -EPERM;
 
-       for (i = 0; i < variant->_class->fields->len; i++) {
-               struct type_class_field *field_class =
-                       &g_array_index(variant->_class->fields,
-                                      struct type_class_field, i);
-               if (!enum_quark_to_range_set(enum_class, field_class->name)) {
+       for (i = 0; i < variant->type->fields->len; i++) {
+               struct type_field *field_type =
+                       &g_array_index(variant->type->fields,
+                                      struct type_field, i);
+               if (!enum_quark_to_range_set(enum_type, field_type->name)) {
                        missing_field = 1;
                        break;
                }
@@ -217,19 +216,18 @@ int variant_type_set_tag(struct type_variant *variant,
         */
 
        /* Set the enum tag field */
-       variant->enum_tag = enum_tag_instance;
+       variant->enum_tag = enum_tag;
        return 0;
 }
 
 /*
  * field returned only valid as long as the field structure is not appended to.
  */
-struct field *
-variant_type_get_current_field(struct type_variant *variant)
+struct field *variant_get_current_field(struct declaration_variant *variant)
 {
-       struct type_enum *_enum =
-               container_of(struct type_enum, variant->enum_tag, p);
-       struct variat_type_class *variant_class = variant->_class;
+       struct declaration_enum *_enum =
+               container_of(variant->enum_tag, struct declaration_enum, p);
+       struct variant_type *variant_type = variant->type;
        unsigned long index;
        GArray *tag_array;
        GQuark tag;
@@ -241,8 +239,8 @@ variant_type_get_current_field(struct type_variant *variant)
         */
        assert(tag_array->len == 1);
        tag = g_array_index(tag_array, GQuark, 0);
-       index = (unsigned long) g_hash_table_lookup(variant_class->fields_by_tag,
+       index = (unsigned long) g_hash_table_lookup(variant_type->fields_by_tag,
                                                    (gconstpointer) (unsigned long) tag);
-       variant->current_field = &g_array_index(variant_class->fields, struct field, index);
+       variant->current_field = &g_array_index(variant->fields, struct field, index);
        return variant->current_field;
 }
This page took 0.15344 seconds and 4 git commands to generate.