diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-07-02 22:39:25 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-07-02 22:40:18 (GMT) |
commit | de2cb8e2fad4a3031d7b7c2cb189a6dbdaf8d5a9 (patch) | |
tree | eb9b01fc893ace47e0311ebca7511162769c36be /src/analysis/types/literal.c | |
parent | 4630eb7a2b0b61a4e9ea3a99e7a8cdaba05392cd (diff) |
Extented the types definitions.
Diffstat (limited to 'src/analysis/types/literal.c')
-rw-r--r-- | src/analysis/types/literal.c | 155 |
1 files changed, 89 insertions, 66 deletions
diff --git a/src/analysis/types/literal.c b/src/analysis/types/literal.c index 7a0c4f7..f284310 100644 --- a/src/analysis/types/literal.c +++ b/src/analysis/types/literal.c @@ -58,14 +58,17 @@ static void g_literal_type_class_init(GLiteralTypeClass *); /* Initialise l'instance d'un type instancié avec une valeur. */ static void g_literal_type_init(GLiteralType *); +/* Supprime toutes les références externes. */ +static void g_literal_type_dispose(GLiteralType *); + +/* Procède à la libération totale de la mémoire. */ +static void g_literal_type_finalize(GLiteralType *); + /* Crée un copie d'un type existant. */ static GDataType *g_literal_type_dup(const GLiteralType *); /* Décrit le type fourni sous forme de caractères. */ -static char *g_literal_type_to_string(const GLiteralType *); - -/* Procède à l'impression de la description d'un type. */ -//static void g_literal_type_output(const GLiteralType *, GLangOutput *, GBufferLine *, bool, bool); +static char *g_literal_type_to_string(const GLiteralType *, bool); @@ -87,6 +90,18 @@ G_DEFINE_TYPE(GLiteralType, g_literal_type, G_TYPE_DATA_TYPE); static void g_literal_type_class_init(GLiteralTypeClass *klass) { + GObjectClass *object; /* Autre version de la classe */ + GDataTypeClass *type; /* Version parente et basique */ + + object = G_OBJECT_CLASS(klass); + + object->dispose = (GObjectFinalizeFunc/* ! */)g_literal_type_dispose; + object->finalize = (GObjectFinalizeFunc)g_literal_type_finalize; + + type = G_DATA_TYPE_CLASS(klass); + + type->dup = (type_dup_fc)g_literal_type_dup; + type->to_string = (type_to_string_fc)g_literal_type_to_string; } @@ -105,13 +120,48 @@ static void g_literal_type_class_init(GLiteralTypeClass *klass) static void g_literal_type_init(GLiteralType *type) { - GDataType *data_type; /* Version basique */ + type->orig = NULL; - data_type = G_DATA_TYPE(type); +} - data_type->dup = (type_dup_fc)g_literal_type_dup; - data_type->to_string = (type_to_string_fc)g_literal_type_to_string; - //data_type->output = (output_type_fc)g_literal_type_output; + +/****************************************************************************** +* * +* Paramètres : type = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_literal_type_dispose(GLiteralType *type) +{ + if (type->orig != NULL) + g_object_unref(G_OBJECT(type->orig)); + + G_OBJECT_CLASS(g_literal_type_parent_class)->dispose(G_OBJECT(type)); + +} + + +/****************************************************************************** +* * +* Paramètres : type = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_literal_type_finalize(GLiteralType *type) +{ + G_OBJECT_CLASS(g_literal_type_parent_class)->finalize(G_OBJECT(type)); } @@ -129,18 +179,23 @@ static void g_literal_type_init(GLiteralType *type) * * ******************************************************************************/ -GDataType *g_literal_type_new(GDataType *orig, literal_value value) +GDataType *g_literal_type_new(GDataType *orig, const literal_value *value) { GLiteralType *result; /* Structure à retourner */ - result = g_object_new(G_TYPE_LITERAL_TYPE, NULL); + if (!G_IS_BASIC_TYPE(orig)) + result = NULL; - result->orig = orig; - result->value = value; + else + { + result = g_object_new(G_TYPE_LITERAL_TYPE, NULL); - g_object_ref(orig); + result->orig = orig; + result->value = *value; - return G_DATA_TYPE(result); + } + + return (result != NULL ? G_DATA_TYPE(result) : NULL); } @@ -159,18 +214,22 @@ GDataType *g_literal_type_new(GDataType *orig, literal_value value) static GDataType *g_literal_type_dup(const GLiteralType *type) { + GDataType *result; /* Copie à retourner */ GDataType *orig; /* Copie du type interne */ orig = g_data_type_dup(type->orig); - return g_literal_type_new(orig, type->value); + result = g_literal_type_new(orig, &type->value); + + return result; } /****************************************************************************** * * -* Paramètres : type = type à convertir. * +* Paramètres : type = type à convertir. * +* include = doit-on inclure les espaces de noms ? * * * * Description : Décrit le type fourni sous forme de caractères. * * * @@ -180,63 +239,27 @@ static GDataType *g_literal_type_dup(const GLiteralType *type) * * ******************************************************************************/ -static char *g_literal_type_to_string(const GLiteralType *type) +static char *g_literal_type_to_string(const GLiteralType *type, bool include) { char *result; /* Valeur à renvoyer */ - size_t max; /* Longueur totale du texte */ - if (G_IS_BASIC_TYPE(type->orig)) - switch (g_basic_type_get_btype(G_BASIC_TYPE(type->orig))) - { - case BTP_BOOL: - result = strdup(type->value.int_val ? "true" : "false"); - break; + switch (g_basic_type_get_base_type(G_BASIC_TYPE(type->orig))) + { + case BTP_BOOL: + result = strdup(type->value.int_val ? "true" : "false"); + break; - case BTP_INT: - max = strlen("2147483647" /* INT_MAX */) + 1; - result = (char *)calloc(max, sizeof(char)); - snprintf(result, max, "%d", type->value.int_val); - break; + case BTP_INT: + default: + asprintf(&result, "%d", type->value.int_val); + break; - default: - result = strdup("TODO"); - break; + case BTP_FLOAT: + asprintf(&result, "%f", type->value.float_val); + break; } - else result = strdup("???"); return result; } - - -/****************************************************************************** -* * -* Paramètres : type = type à afficher. * -* lang = langage à utiliser pour la sortie humaine. * -* buffer = tampon mis à disposition pour la sortie. * -* info = nature du cadre de destination. * -* full = besoin de descriptions étendues ? * -* * -* Description : Procède à l'impression de la description d'un type. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ -#if 0 -static void g_literal_type_output(const GLiteralType *type, GLangOutput *lang, GBufferLine *line, bool info, bool full) -{ - char *text; /* Version humaine à imprimer */ - size_t len; /* Taille de cette version */ - - text = g_literal_type_to_string(type); - len = strlen(text); - - g_buffer_line_append_text(line, BLC_LAST_USED, text, len, info ? RTT_COMMENT : RTT_RAW, NULL); - - free(text); - -} -#endif |