35415ec8f446401b80b10eb0a8d7dbed1b7d1bab
4 * BabelTrace - Array Type Converter
6 * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
19 #include <babeltrace/compiler.h>
20 #include <babeltrace/format.h>
23 struct declaration
*_array_declaration_new(struct type
*type
,
24 struct declaration_scope
*parent_scope
);
26 void _array_declaration_free(struct declaration
*declaration
);
28 void array_copy(struct stream_pos
*dest
, const struct format
*fdest
,
29 struct stream_pos
*src
, const struct format
*fsrc
,
30 struct declaration
*declaration
)
32 struct declaration_array
*array
=
33 container_of(declaration
, struct declaration_array
, p
);
34 struct type_array
*array_type
= array
->type
;
37 fsrc
->array_begin(src
, array_type
);
38 fdest
->array_begin(dest
, array_type
);
40 for (i
= 0; i
< array_type
->len
; i
++) {
41 struct declaration
*elem
= array
->current_element
.declaration
;
42 elem
->type
->copy(dest
, fdest
, src
, fsrc
, elem
);
44 fsrc
->array_end(src
, array_type
);
45 fdest
->array_end(dest
, array_type
);
49 void _array_type_free(struct type
*type
)
51 struct type_array
*array_type
=
52 container_of(type
, struct type_array
, p
);
54 free_type_scope(array_type
->scope
);
55 type_unref(array_type
->elem
);
60 array_type_new(const char *name
, size_t len
, struct type
*elem_type
,
61 struct type_scope
*parent_scope
)
63 struct type_array
*array_type
;
66 array_type
= g_new(struct type_array
, 1);
67 type
= &array_type
->p
;
68 array_type
->len
= len
;
70 array_type
->elem
= elem_type
;
71 array_type
->scope
= new_type_scope(parent_scope
);
72 type
->name
= g_quark_from_string(name
);
73 /* No need to align the array, the first element will align itself */
75 type
->copy
= array_copy
;
76 type
->type_free
= _array_type_free
;
77 type
->declaration_new
= _array_declaration_new
;
78 type
->declaration_free
= _array_declaration_free
;
85 _array_declaration_new(struct type
*type
,
86 struct declaration_scope
*parent_scope
)
88 struct type_array
*array_type
=
89 container_of(type
, struct type_array
, p
);
90 struct declaration_array
*array
;
92 array
= g_new(struct declaration_array
, 1);
93 type_ref(&array_type
->p
);
95 array
->type
= array_type
;
97 array
->scope
= new_declaration_scope(parent_scope
);
98 array
->current_element
.declaration
=
99 array_type
->elem
->declaration_new(array_type
->elem
,
105 void _array_declaration_free(struct declaration
*declaration
)
107 struct declaration_array
*array
=
108 container_of(declaration
, struct declaration_array
, p
);
109 struct declaration
*elem_declaration
=
110 array
->current_element
.declaration
;
112 elem_declaration
->type
->declaration_free(elem_declaration
);
113 free_declaration_scope(array
->scope
);
114 type_unref(array
->p
.type
);
This page took 0.032624 seconds and 4 git commands to generate.