X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=types%2Finteger.c;h=16cd903dc8aa8b7740859b0e7e30aae9bd4109a4;hp=1e926f7b4041e4c4f19c0e745a010d0e62eb6e41;hb=0f980a3595f61930659e392b1248c59490dd5a22;hpb=be85c1c7633af07e35db7b415d6ee8447c30e80a diff --git a/types/integer.c b/types/integer.c index 1e926f7b..16cd903d 100644 --- a/types/integer.c +++ b/types/integer.c @@ -3,7 +3,7 @@ * * BabelTrace - Integer Type Converter * - * Copyright 2010 - Mathieu Desnoyers + * Copyright 2010, 2011 - Mathieu Desnoyers * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -21,61 +21,90 @@ #include #include +static +struct definition *_integer_definition_new(struct declaration *declaration, + struct definition_scope *parent_scope, + GQuark field_name, int index); +static +void _integer_definition_free(struct definition *definition); + void integer_copy(struct stream_pos *dest, const struct format *fdest, struct stream_pos *src, const struct format *fsrc, - const struct type_class *type_class) + struct definition *definition) { - struct type_class_integer *int_class = - container_of(type_class, struct type_class_integer, p); + struct definition_integer *integer = + container_of(definition, struct definition_integer, p); + struct declaration_integer *integer_declaration = integer->declaration; - if (!int_class->signedness) { + if (!integer_declaration->signedness) { uint64_t v; - v = fsrc->uint_read(src, int_class); - fdest->uint_write(dest, int_class, v); + v = fsrc->uint_read(src, integer_declaration); + if (fdest) + fdest->uint_write(dest, integer_declaration, v); } else { int64_t v; - v = fsrc->int_read(src, int_class); - fdest->int_write(dest, int_class, v); + v = fsrc->int_read(src, integer_declaration); + if (fdest) + fdest->int_write(dest, integer_declaration, v); } } -void integer_type_free(struct type_class_integer *int_class) +static +void _integer_declaration_free(struct declaration *declaration) { - g_free(int_class); + struct declaration_integer *integer_declaration = + container_of(declaration, struct declaration_integer, p); + g_free(integer_declaration); } -static void _integer_type_free(struct type_class *type_class) +struct declaration_integer * + integer_declaration_new(size_t len, int byte_order, + int signedness, size_t alignment) { - struct type_class_integer *int_class = - container_of(type_class, struct type_class_integer, p); - integer_type_free(int_class); + struct declaration_integer *integer_declaration; + + integer_declaration = g_new(struct declaration_integer, 1); + integer_declaration->p.id = CTF_TYPE_INTEGER; + integer_declaration->p.alignment = alignment; + integer_declaration->p.copy = integer_copy; + integer_declaration->p.declaration_free = _integer_declaration_free; + integer_declaration->p.definition_free = _integer_definition_free; + integer_declaration->p.definition_new = _integer_definition_new; + integer_declaration->p.ref = 1; + integer_declaration->len = len; + integer_declaration->byte_order = byte_order; + integer_declaration->signedness = signedness; + return integer_declaration; } -struct type_class_integer *integer_type_new(const char *name, - size_t len, int byte_order, - int signedness, - size_t alignment) +static +struct definition * + _integer_definition_new(struct declaration *declaration, + struct definition_scope *parent_scope, + GQuark field_name, int index) { - struct type_class_integer *int_class; - int ret; + struct declaration_integer *integer_declaration = + container_of(declaration, struct declaration_integer, p); + struct definition_integer *integer; - int_class = g_new(struct type_class_integer, 1); - int_class->p.name = g_quark_from_string(name); - int_class->p.alignment = alignment; - int_class->p.copy = integer_copy; - int_class->p.free = _integer_type_free; - int_class->p.ref = 1; - int_class->len = len; - int_class->byte_order = byte_order; - int_class->signedness = signedness; - if (int_class->p.name) { - ret = register_type(&int_class->p); - if (ret) { - g_free(int_class); - return NULL; - } - } - return int_class; + integer = g_new(struct definition_integer, 1); + declaration_ref(&integer_declaration->p); + integer->p.declaration = declaration; + integer->declaration = integer_declaration; + integer->p.ref = 1; + integer->p.index = index; + integer->value._unsigned = 0; + return &integer->p; +} + +static +void _integer_definition_free(struct definition *definition) +{ + struct definition_integer *integer = + container_of(definition, struct definition_integer, p); + + declaration_unref(integer->p.declaration); + g_free(integer); }