Add base integer attribute, and use it in ctf-text
[babeltrace.git] / types / integer.c
1 /*
2 * integer.c
3 *
4 * BabelTrace - Integer Type Converter
5 *
6 * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
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:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 */
18
19 #include <babeltrace/compiler.h>
20 #include <babeltrace/align.h>
21 #include <babeltrace/format.h>
22 #include <stdint.h>
23
24 static
25 struct definition *_integer_definition_new(struct declaration *declaration,
26 struct definition_scope *parent_scope,
27 GQuark field_name, int index);
28 static
29 void _integer_definition_free(struct definition *definition);
30
31 static
32 void _integer_declaration_free(struct declaration *declaration)
33 {
34 struct declaration_integer *integer_declaration =
35 container_of(declaration, struct declaration_integer, p);
36 g_free(integer_declaration);
37 }
38
39 struct declaration_integer *
40 integer_declaration_new(size_t len, int byte_order,
41 int signedness, size_t alignment, int base)
42 {
43 struct declaration_integer *integer_declaration;
44
45 integer_declaration = g_new(struct declaration_integer, 1);
46 integer_declaration->p.id = CTF_TYPE_INTEGER;
47 integer_declaration->p.alignment = alignment;
48 integer_declaration->p.declaration_free = _integer_declaration_free;
49 integer_declaration->p.definition_free = _integer_definition_free;
50 integer_declaration->p.definition_new = _integer_definition_new;
51 integer_declaration->p.ref = 1;
52 integer_declaration->len = len;
53 integer_declaration->byte_order = byte_order;
54 integer_declaration->signedness = signedness;
55 integer_declaration->base = base;
56 return integer_declaration;
57 }
58
59 static
60 struct definition *
61 _integer_definition_new(struct declaration *declaration,
62 struct definition_scope *parent_scope,
63 GQuark field_name, int index)
64 {
65 struct declaration_integer *integer_declaration =
66 container_of(declaration, struct declaration_integer, p);
67 struct definition_integer *integer;
68
69 integer = g_new(struct definition_integer, 1);
70 declaration_ref(&integer_declaration->p);
71 integer->p.declaration = declaration;
72 integer->declaration = integer_declaration;
73 integer->p.ref = 1;
74 integer->p.index = index;
75 integer->p.name = field_name;
76 integer->p.path = new_definition_path(parent_scope, field_name);
77 integer->value._unsigned = 0;
78 return &integer->p;
79 }
80
81 static
82 void _integer_definition_free(struct definition *definition)
83 {
84 struct definition_integer *integer =
85 container_of(definition, struct definition_integer, p);
86
87 declaration_unref(integer->p.declaration);
88 g_free(integer);
89 }
This page took 0.031324 seconds and 5 git commands to generate.