def = lookup_definition(scope, field_underscore);
g_free(field_underscore);
}
- if (bt_ctf_field_type(bt_ctf_get_field_decl(def)) == CTF_TYPE_VARIANT) {
+ if (bt_ctf_field_type(bt_ctf_get_decl_from_def(def)) == CTF_TYPE_VARIANT) {
const struct definition_variant *variant_definition;
variant_definition = container_of(def,
const struct definition_variant, p);
if (!ctf_event || !field)
return NULL;
- if (bt_ctf_field_type(bt_ctf_get_field_decl(field)) == CTF_TYPE_ARRAY) {
+ if (bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_ARRAY) {
struct definition_array *array_definition;
array_definition = container_of(field,
struct definition_array, p);
ret = array_index(array_definition, index);
- } else if (bt_ctf_field_type(bt_ctf_get_field_decl(field)) == CTF_TYPE_SEQUENCE) {
+ } else if (bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_SEQUENCE) {
struct definition_sequence *sequence_definition;
sequence_definition = container_of(field,
struct definition_sequence, p);
if (!ctf_event || !scope || !list || !count)
return -EINVAL;
- switch (bt_ctf_field_type(bt_ctf_get_field_decl(scope))) {
+ switch (bt_ctf_field_type(bt_ctf_get_decl_from_def(scope))) {
case CTF_TYPE_INTEGER:
case CTF_TYPE_FLOAT:
case CTF_TYPE_STRING:
return container_of(decl, const struct declaration_array, p);
}
+static const struct declaration_sequence *
+get_declaration_sequence(const struct declaration *decl)
+{
+ if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_SEQUENCE)
+ return NULL;
+ return container_of(decl, const struct declaration_sequence, p);
+}
+
int bt_ctf_get_int_signedness(const struct declaration *decl)
{
const struct declaration_integer *integer;
{
const struct definition_enum *def_enum;
- if (!field || bt_ctf_field_type(bt_ctf_get_field_decl(field)) != CTF_TYPE_ENUM) {
+ if (!field || bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) != CTF_TYPE_ENUM) {
bt_ctf_field_set_error(-EINVAL);
return NULL;
}
GArray *array;
const char *ret;
- if (!field || bt_ctf_field_type(bt_ctf_get_field_decl(field)) != CTF_TYPE_ENUM) {
+ if (!field || bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) != CTF_TYPE_ENUM) {
bt_ctf_field_set_error(-EINVAL);
return NULL;
}
enum ctf_string_encoding bt_ctf_get_encoding(const struct declaration *decl)
{
enum ctf_string_encoding ret = 0;
+ enum ctf_type_id type;
const struct declaration_integer *integer;
const struct declaration_string *string;
+ const struct declaration_array *array;
+ const struct declaration_sequence *sequence;
if (!decl)
goto error;
- if (bt_ctf_field_type(decl) == CTF_TYPE_INTEGER) {
- integer = get_declaration_integer(decl);
- if (integer) {
- ret = integer->encoding;
- } else {
+ type = bt_ctf_field_type(decl);
+
+ switch (type) {
+ case CTF_TYPE_ARRAY:
+ array = get_declaration_array(decl);
+ if (!array)
goto error;
- }
- } else if (bt_ctf_field_type(decl) == CTF_TYPE_STRING) {
+ integer = get_declaration_integer(array->elem);
+ if (!integer)
+ goto error;
+ ret = integer->encoding;
+ break;
+ case CTF_TYPE_SEQUENCE:
+ sequence = get_declaration_sequence(decl);
+ if (!sequence)
+ goto error;
+ integer = get_declaration_integer(sequence->elem);
+ if (!integer)
+ goto error;
+ ret = integer->encoding;
+ break;
+ case CTF_TYPE_STRING:
string = get_declaration_string(decl);
- if (string) {
- ret = string->encoding;
- } else {
+ if (!string)
goto error;
- }
- } else {
+ ret = string->encoding;
+ break;
+ case CTF_TYPE_INTEGER:
+ integer = get_declaration_integer(decl);
+ if (!integer)
+ goto error;
+ ret = integer->encoding;
+ break;
+ default:
goto error;
}
return ret;
{
uint64_t ret = 0;
- if (field && bt_ctf_field_type(bt_ctf_get_field_decl(field)) == CTF_TYPE_INTEGER)
+ if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_INTEGER)
ret = get_unsigned_int(field);
else
bt_ctf_field_set_error(-EINVAL);
{
int64_t ret = 0;
- if (field && bt_ctf_field_type(bt_ctf_get_field_decl(field)) == CTF_TYPE_INTEGER)
+ if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_INTEGER)
ret = get_signed_int(field);
else
bt_ctf_field_set_error(-EINVAL);
char *ret = NULL;
GString *char_array;
- if (field && bt_ctf_field_type(bt_ctf_get_field_decl(field)) == CTF_TYPE_ARRAY) {
+ if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_ARRAY) {
char_array = get_char_array(field);
if (char_array) {
ret = char_array->str;
{
char *ret = NULL;
- if (field && bt_ctf_field_type(bt_ctf_get_field_decl(field)) == CTF_TYPE_STRING)
+ if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_STRING)
ret = get_string(field);
else
bt_ctf_field_set_error(-EINVAL);
return rem_(g_quark_to_string(((struct declaration_field *) field)->name));
}
-const struct declaration *bt_ctf_get_field_decl(const struct definition *def)
+const struct declaration *bt_ctf_get_decl_from_def(const struct definition *def)
{
if (def)
return def->declaration;
return NULL;
}
+
+const struct declaration *bt_ctf_get_decl_from_field_decl(
+ const struct bt_ctf_field_decl *field)
+{
+ if (field)
+ return ((struct declaration_field *) field)->declaration;
+
+ return NULL;
+}