summaryrefslogtreecommitdiff
path: root/src/analysis/types/literal.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/types/literal.c')
-rw-r--r--src/analysis/types/literal.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/analysis/types/literal.c b/src/analysis/types/literal.c
index 3a9e5cf..addab5a 100644
--- a/src/analysis/types/literal.c
+++ b/src/analysis/types/literal.c
@@ -64,6 +64,9 @@ static void g_literal_type_dispose(GLiteralType *);
/* Procède à la libération totale de la mémoire. */
static void g_literal_type_finalize(GLiteralType *);
+/* Calcule une empreinte pour un type de données. */
+static guint g_literal_type_hash(const GLiteralType *);
+
/* Crée un copie d'un type existant. */
static GDataType *g_literal_type_dup(const GLiteralType *);
@@ -100,6 +103,7 @@ static void g_literal_type_class_init(GLiteralTypeClass *klass)
type = G_DATA_TYPE_CLASS(klass);
+ type->hash = (type_hash_fc)g_literal_type_hash;
type->dup = (type_dup_fc)g_literal_type_dup;
type->to_string = (type_to_string_fc)g_literal_type_to_string;
@@ -202,6 +206,34 @@ GDataType *g_literal_type_new(GDataType *orig, const literal_value *value)
/******************************************************************************
* *
+* Paramètres : type = type à consulter. *
+* *
+* Description : Calcule une empreinte pour un type de données. *
+* *
+* Retour : Valeur arbitraire sur 32 bits, idéalement unique par type. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static guint g_literal_type_hash(const GLiteralType *type)
+{
+ guint result; /* Empreinte à renvoyer */
+
+ result = g_data_type_hash(type->orig);
+
+ if (g_basic_type_get_base(G_BASIC_TYPE(type->orig)) == BTP_FLOAT)
+ result ^= g_double_hash((gdouble []){ type->value.float_val });
+ else
+ result ^= g_int_hash((gint []){ type->value.int_val });
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : type = type à dupliquer. *
* *
* Description : Crée un copie d'un type existant. *