UTF8 fix
[lttv.git] / ltt / branches / poly / ltt / type.c
CommitLineData
449cb9d7 1/* This file is part of the Linux Trace Toolkit viewer
57df94dd 2 * Copyright (C) 2003-2004 Xiangxiu Yang, Mathieu Desnoyers
449cb9d7 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
6cd62ccf 19#include <stdio.h>
57df94dd 20#include <glib.h>
6cd62ccf 21
6cd62ccf 22#include "parser.h"
a5dcde2f 23#include <ltt/ltt.h>
24#include "ltt-private.h"
6cd62ccf 25#include <ltt/type.h>
26
27static unsigned intSizes[] = {
28 sizeof(int8_t), sizeof(int16_t), sizeof(int32_t), sizeof(int64_t),
29 sizeof(short) };
30
57df94dd 31typedef enum _intSizesNames { SIZE_INT8, SIZE_INT16, SIZE_INT32,
32 SIZE_INT64, SIZE_SHORT, INT_SIZES_NUMBER }
33 intSizesNames;
34
35
6cd62ccf 36static unsigned floatSizes[] = {
37 0, 0, sizeof(float), sizeof(double), 0, sizeof(float), sizeof(double) };
38
57df94dd 39#define FLOAT_SIZES_NUMBER 7
40
6cd62ccf 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
45e14832 51gchar *ltt_eventtype_name(LttEventType *et)
6cd62ccf 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
45e14832 65gchar *ltt_eventtype_description(LttEventType *et)
6cd62ccf 66{
67 return et->description;
68}
69
963b5f2d 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
79LttFacility *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
33690006 90 * unsigned : the relative id
963b5f2d 91 ****************************************************************************/
92
33690006 93unsigned ltt_eventtype_relative_id(LttEventType *et)
963b5f2d 94{
33690006 95 return et->index;
963b5f2d 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
33690006 104 * unsigned : the id
963b5f2d 105 ****************************************************************************/
106
33690006 107unsigned ltt_eventtype_id(LttEventType *et)
963b5f2d 108{
33690006 109 return et->facility->base_id + et->index;
963b5f2d 110}
111
6cd62ccf 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
963b5f2d 118 * LttType * : the type of the event type
6cd62ccf 119 ****************************************************************************/
120
963b5f2d 121LttType *ltt_eventtype_type(LttEventType *et)
6cd62ccf 122{
57df94dd 123 if(unlikely(!et->root_field)) return NULL;
124 else return et->root_field->field_type;
6cd62ccf 125}
126
963b5f2d 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
136LttField *ltt_eventtype_field(LttEventType *et)
137{
138 return et->root_field;
139}
140
6cd62ccf 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
45e14832 150gchar *ltt_type_name(LttType *t)
6cd62ccf 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
963b5f2d 161 * LttTypeEnum : the type class of the type
6cd62ccf 162 ****************************************************************************/
163
963b5f2d 164LttTypeEnum ltt_type_class(LttType *t)
6cd62ccf 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
8d1e6362 179 * returns 0 if erroneous, and show a critical warning message.
6cd62ccf 180 ****************************************************************************/
181
963b5f2d 182unsigned ltt_type_size(LttTrace * trace, LttType *t)
6cd62ccf 183{
57df94dd 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];
62c72abf 208 }
6cd62ccf 209 }
210 }
57df94dd 211
212 return size;
6cd62ccf 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
963b5f2d 222 * LttType : the type of nested element of array or sequence
6cd62ccf 223 ****************************************************************************/
224
963b5f2d 225LttType *ltt_type_element_type(LttType *t)
6cd62ccf 226{
57df94dd 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;
6cd62ccf 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
963b5f2d 246unsigned ltt_type_element_number(LttType *t)
6cd62ccf 247{
57df94dd 248 unsigned ret = 0;
249
250 if(likely(t->type_class == LTT_ARRAY))
251 ret = t->element_number;
252
253 return ret;
6cd62ccf 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
963b5f2d 265unsigned ltt_type_member_number(LttType *t)
6cd62ccf 266{
57df94dd 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;
6cd62ccf 273}
274
275/*****************************************************************************
276 *Function name
59d7bdf3 277 * ltt_type_member_type : obtain the type of a data member in a structure
278 * or union.
6cd62ccf 279 *Input params
280 * t : a type
281 * i : index of the member
282 *Return value
963b5f2d 283 * LttType * : the type of structure member
6cd62ccf 284 ****************************************************************************/
285
45e14832 286LttType *ltt_type_member_type(LttType *t, unsigned i, gchar ** name)
6cd62ccf 287{
57df94dd 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;
6cd62ccf 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
963b5f2d 316char *ltt_enum_string_get(LttType *t, unsigned i)
57df94dd 317{
45e14832 318 gchar *string = NULL;
57df94dd 319
320 if(likely(t->type_class == LTT_ENUM && i < t->element_number))
321 string = t->enum_strings[i];
322
323 return string;
6cd62ccf 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
963b5f2d 333 * LttField * : the field of the nested element
6cd62ccf 334 ****************************************************************************/
335
963b5f2d 336LttField *ltt_field_element(LttField *f)
6cd62ccf 337{
57df94dd 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];
6cd62ccf 343
57df94dd 344 return nest;
6cd62ccf 345}
346
347/*****************************************************************************
348 *Function name
59d7bdf3 349 * ltt_field_member : obtain the field of data members for structure
6cd62ccf 350 *Input params
351 * f : a field
352 * i : index of member field
353 *Return value
963b5f2d 354 * LttField * : the field of the nested element
6cd62ccf 355 ****************************************************************************/
356
963b5f2d 357LttField *ltt_field_member(LttField *f, unsigned i)
6cd62ccf 358{
57df94dd 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;
6cd62ccf 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
963b5f2d 380LttType *ltt_field_type(LttField *f)
6cd62ccf 381{
57df94dd 382 if(unlikely(!f))return NULL;
6cd62ccf 383 return f->field_type;
384}
385
a5dcde2f 386int ltt_field_size(LttField * f)
387{
57df94dd 388 if(unlikely(!f))return 0;
a5dcde2f 389 return f->field_size;
390}
This page took 0.046598 seconds and 4 git commands to generate.