UTF8 fix
[lttv.git] / ltt / branches / poly / ltt / type.c
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Xiangxiu Yang, Mathieu Desnoyers
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
19 #include <stdio.h>
20 #include <glib.h>
21
22 #include "parser.h"
23 #include <ltt/ltt.h>
24 #include "ltt-private.h"
25 #include <ltt/type.h>
26
27 static unsigned intSizes[] = {
28 sizeof(int8_t), sizeof(int16_t), sizeof(int32_t), sizeof(int64_t),
29 sizeof(short) };
30
31 typedef enum _intSizesNames { SIZE_INT8, SIZE_INT16, SIZE_INT32,
32 SIZE_INT64, SIZE_SHORT, INT_SIZES_NUMBER }
33 intSizesNames;
34
35
36 static unsigned floatSizes[] = {
37 0, 0, sizeof(float), sizeof(double), 0, sizeof(float), sizeof(double) };
38
39 #define FLOAT_SIZES_NUMBER 7
40
41
42 /*****************************************************************************
43 *Function name
44 * ltt_eventtype_name : get the name of the event type
45 *Input params
46 * et : an event type
47 *Return value
48 * char * : the name of the event type
49 ****************************************************************************/
50
51 gchar *ltt_eventtype_name(LttEventType *et)
52 {
53 return et->name;
54 }
55
56 /*****************************************************************************
57 *Function name
58 * ltt_eventtype_description : get the description of the event type
59 *Input params
60 * et : an event type
61 *Return value
62 * char * : the description of the event type
63 ****************************************************************************/
64
65 gchar *ltt_eventtype_description(LttEventType *et)
66 {
67 return et->description;
68 }
69
70 /*****************************************************************************
71 *Function name
72 * ltt_eventtype_facility : get the facility which contains the event type
73 *Input params
74 * et : an event type
75 *Return value
76 * LttFacility * : the facility
77 ****************************************************************************/
78
79 LttFacility *ltt_eventtype_facility(LttEventType *et)
80 {
81 return et->facility;
82 }
83
84 /*****************************************************************************
85 *Function name
86 * ltt_eventtype_relative_id : get the relative id of the event type
87 *Input params
88 * et : an event type
89 *Return value
90 * unsigned : the relative id
91 ****************************************************************************/
92
93 unsigned ltt_eventtype_relative_id(LttEventType *et)
94 {
95 return et->index;
96 }
97
98 /*****************************************************************************
99 *Function name
100 * ltt_eventtype_id : get the id of the event type
101 *Input params
102 * et : an event type
103 *Return value
104 * unsigned : the id
105 ****************************************************************************/
106
107 unsigned ltt_eventtype_id(LttEventType *et)
108 {
109 return et->facility->base_id + et->index;
110 }
111
112 /*****************************************************************************
113 *Function name
114 * ltt_eventtype_type : get the type of the event type
115 *Input params
116 * et : an event type
117 *Return value
118 * LttType * : the type of the event type
119 ****************************************************************************/
120
121 LttType *ltt_eventtype_type(LttEventType *et)
122 {
123 if(unlikely(!et->root_field)) return NULL;
124 else return et->root_field->field_type;
125 }
126
127 /*****************************************************************************
128 *Function name
129 * ltt_eventtype_field : get the root filed of the event type
130 *Input params
131 * et : an event type
132 *Return value
133 * LttField * : the root filed of the event type
134 ****************************************************************************/
135
136 LttField *ltt_eventtype_field(LttEventType *et)
137 {
138 return et->root_field;
139 }
140
141 /*****************************************************************************
142 *Function name
143 * ltt_type_name : get the name of the type
144 *Input params
145 * t : a type
146 *Return value
147 * char * : the name of the type
148 ****************************************************************************/
149
150 gchar *ltt_type_name(LttType *t)
151 {
152 return t->element_name;
153 }
154
155 /*****************************************************************************
156 *Function name
157 * ltt_type_class : get the type class of the type
158 *Input params
159 * t : a type
160 *Return value
161 * LttTypeEnum : the type class of the type
162 ****************************************************************************/
163
164 LttTypeEnum ltt_type_class(LttType *t)
165 {
166 return t->type_class;
167 }
168
169 /*****************************************************************************
170 *Function name
171 * ltt_type_size : obtain the type size. The size is the number of bytes
172 * for primitive types (INT, UINT, FLOAT, ENUM), or the
173 * size for the unsigned integer length count for sequences
174 *Input params
175 * tf : trace file
176 * t : a type
177 *Return value
178 * unsigned : the type size
179 * returns 0 if erroneous, and show a critical warning message.
180 ****************************************************************************/
181
182 unsigned ltt_type_size(LttTrace * trace, LttType *t)
183 {
184 unsigned size;
185 if(unlikely(t->type_class==LTT_STRUCT || t->type_class==LTT_ARRAY ||
186 t->type_class==LTT_STRING || t->type_class==LTT_UNION)) {
187 size = 0;
188 } else {
189 if(t->type_class == LTT_FLOAT){
190 size = floatSizes[t->size];
191 }else{
192 if(likely(t->size < INT_SIZES_NUMBER))
193 size = intSizes[t->size];
194 else{
195 LttArchSize archsize = trace->system_description->size;
196 if(archsize == LTT_LP32){
197 if(t->size == 5) size = intSizes[SIZE_INT16];
198 else size = intSizes[SIZE_INT32];
199 }
200 else if(archsize == LTT_ILP32 || archsize == LTT_LP64){
201 if(t->size == 5) size = intSizes[SIZE_INT32];
202 else{
203 if(archsize == LTT_ILP32) size = intSizes[SIZE_INT32];
204 else size = intSizes[SIZE_INT64];
205 }
206 }
207 else if(archsize == LTT_ILP64) size = intSizes[SIZE_INT64];
208 }
209 }
210 }
211
212 return size;
213 }
214
215 /*****************************************************************************
216 *Function name
217 * ltt_type_element_type : obtain the type of nested elements for arrays
218 * and sequences
219 *Input params
220 * t : a type
221 *Return value
222 * LttType : the type of nested element of array or sequence
223 ****************************************************************************/
224
225 LttType *ltt_type_element_type(LttType *t)
226 {
227 LttType *element_type;
228
229 if(unlikely(t->type_class != LTT_ARRAY && t->type_class != LTT_SEQUENCE))
230 element_type = NULL;
231 else
232 element_type = t->element_type[0];
233
234 return element_type;
235 }
236
237 /*****************************************************************************
238 *Function name
239 * ltt_type_element_number : obtain the number of elements for arrays
240 *Input params
241 * t : a type
242 *Return value
243 * unsigned : the number of elements for arrays
244 ****************************************************************************/
245
246 unsigned ltt_type_element_number(LttType *t)
247 {
248 unsigned ret = 0;
249
250 if(likely(t->type_class == LTT_ARRAY))
251 ret = t->element_number;
252
253 return ret;
254 }
255
256 /*****************************************************************************
257 *Function name
258 * ltt_type_member_number : obtain the number of data members for structure
259 *Input params
260 * t : a type
261 *Return value
262 * unsigned : the number of members for structure
263 ****************************************************************************/
264
265 unsigned ltt_type_member_number(LttType *t)
266 {
267 unsigned ret = 0;
268
269 if(likely(t->type_class == LTT_STRUCT || t->type_class == LTT_UNION))
270 ret =t->element_number;
271
272 return ret;
273 }
274
275 /*****************************************************************************
276 *Function name
277 * ltt_type_member_type : obtain the type of a data member in a structure
278 * or union.
279 *Input params
280 * t : a type
281 * i : index of the member
282 *Return value
283 * LttType * : the type of structure member
284 ****************************************************************************/
285
286 LttType *ltt_type_member_type(LttType *t, unsigned i, gchar ** name)
287 {
288 LttType *member_type = NULL;
289
290 if(unlikely( (t->type_class != LTT_STRUCT
291 && t->type_class != LTT_UNION)
292 ||
293 (i >= t->element_number)
294 )) {
295 *name = NULL;
296 } else {
297 *name = t->element_type[i]->element_name;
298 member_type = t->element_type[i];
299 }
300
301 return member_type;
302 }
303
304 /*****************************************************************************
305 *Function name
306 * ltt_enum_string_get : for enumerations, obtain the symbolic string
307 * associated with a value (0 to n - 1 for an
308 * enumeration of n elements)
309 *Input params
310 * t : a type
311 * i : index of the member
312 *Return value
313 * char * : symbolic string associated with a value
314 ****************************************************************************/
315
316 char *ltt_enum_string_get(LttType *t, unsigned i)
317 {
318 gchar *string = NULL;
319
320 if(likely(t->type_class == LTT_ENUM && i < t->element_number))
321 string = t->enum_strings[i];
322
323 return string;
324 }
325
326 /*****************************************************************************
327 *Function name
328 * ltt_field_element : obtain the field of nested elements for arrays and
329 * sequence
330 *Input params
331 * f : a field
332 *Return value
333 * LttField * : the field of the nested element
334 ****************************************************************************/
335
336 LttField *ltt_field_element(LttField *f)
337 {
338 LttField *nest = NULL;
339
340 if(likely(f->field_type->type_class == LTT_ARRAY ||
341 f->field_type->type_class == LTT_SEQUENCE))
342 nest = f->child[0];
343
344 return nest;
345 }
346
347 /*****************************************************************************
348 *Function name
349 * ltt_field_member : obtain the field of data members for structure
350 *Input params
351 * f : a field
352 * i : index of member field
353 *Return value
354 * LttField * : the field of the nested element
355 ****************************************************************************/
356
357 LttField *ltt_field_member(LttField *f, unsigned i)
358 {
359 LttField *field_member;
360
361 if(unlikely( f->field_type->type_class != LTT_STRUCT
362 && f->field_type->type_class != LTT_UNION)
363 || i >= f->field_type->element_number )
364 field_member = NULL;
365 else
366 field_member = f->child[i];
367
368 return field_member;
369 }
370
371 /*****************************************************************************
372 *Function name
373 * ltt_field_type : obtain the type of the field
374 *Input params
375 * f : a field
376 *Return value
377 * ltt_tyoe * : the type of field
378 ****************************************************************************/
379
380 LttType *ltt_field_type(LttField *f)
381 {
382 if(unlikely(!f))return NULL;
383 return f->field_type;
384 }
385
386 int ltt_field_size(LttField * f)
387 {
388 if(unlikely(!f))return 0;
389 return f->field_size;
390 }
This page took 0.038526 seconds and 4 git commands to generate.