]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[script] Add a expressions and operators to the debug hashtables
authorCharlie Brej <cbrej@cs.man.ac.uk>
Sun, 30 Aug 2009 23:24:08 +0000 (00:24 +0100)
committerCharlie Brej <cbrej@cs.man.ac.uk>
Sun, 30 Aug 2009 23:24:08 +0000 (00:24 +0100)
src/plugins/splash/script/script-debug.c
src/plugins/splash/script/script-debug.h
src/plugins/splash/script/script-parse.c

index 9e9ef57a6031b8b5ecb8a039c34e6d389ce4dcf1..65bc95a995ac7ebc0995a73b5d5648ef713185d0 100644 (file)
  *
  * Written by: Charlie Brej <cbrej@cs.man.ac.uk>
  */
+#include "ply-hashtable.h"
+#include <stdlib.h>
+#include <string.h>
+
 #include "script-debug.h"
+
+static ply_hashtable_t *script_debug_location_hash = NULL;
+static ply_hashtable_t *script_debug_name_hash = NULL;
+
+static void script_debug_setup (void)
+{
+  if (script_debug_location_hash) return;
+  script_debug_location_hash = ply_hashtable_new(NULL, NULL);
+  script_debug_name_hash = ply_hashtable_new(ply_hashtable_string_hash,
+                                             ply_hashtable_string_compare);
+}
+
+void script_debug_add_element (void                    *element,
+                               script_debug_location_t *location)
+{
+  script_debug_setup();
+  script_debug_location_t *new_location = malloc (sizeof(script_debug_location_t));
+  new_location->line_index = location->line_index;
+  new_location->column_index = location->column_index;
+  new_location->name = ply_hashtable_lookup (script_debug_name_hash, location->name);
+  if (!new_location->name)
+    {
+      new_location->name = strdup(location->name);
+      ply_hashtable_insert (script_debug_name_hash, new_location->name, new_location->name);
+    }
+  ply_hashtable_insert (script_debug_location_hash, element, new_location);
+}
+
+void script_debug_remove_element (void *element)
+{
+  script_debug_setup();
+  script_debug_location_t *old_location = ply_hashtable_remove (script_debug_location_hash,
+                                                                element);
+  free(old_location);
+}
+
+script_debug_location_t *script_debug_lookup_element (void *element)
+{
+  script_debug_setup();
+  script_debug_location_t *location = ply_hashtable_remove (script_debug_location_hash,
+                                                            element);
+  return NULL;
+}
index d7000d09bad4e231a8d382dddc1df320d9eba5d4..a9ddf0c73c9763545c6882f7e942d53cbdba09f0 100644 (file)
@@ -31,4 +31,9 @@ typedef struct
 } script_debug_location_t;
 
 
+void script_debug_add_element (void                    *element,
+                               script_debug_location_t *location);
+void script_debug_remove_element (void *element);
+script_debug_location_t *script_debug_lookup_element (void *element);
+
 #endif /* SCRIPT_DEBUG_H */
index 60226eb52630cf89c7248ec682a0aa949b874818..ef9a79d584851e196cc6884f394b92724d7b332e 100644 (file)
@@ -56,6 +56,7 @@ static script_exp_t *script_parse_new_exp (script_exp_type_t        type,
 {
   script_exp_t *exp = malloc (sizeof (script_exp_t));
   exp->type = type;
+  script_debug_add_element (exp, location);
   return exp;
 }
 
@@ -126,6 +127,7 @@ static script_op_t *script_parse_new_op (script_op_type_t         type,
 {
   script_op_t *op = malloc (sizeof (script_op_t));
   op->type = type;
+  script_debug_add_element (op, location);
   return op;
 }
 
@@ -849,6 +851,7 @@ static void script_parse_exp_free (script_exp_t *exp)
         free (exp->data.string);
         break;
     }
+  script_debug_remove_element (exp);
   free (exp);
 }
 
@@ -909,6 +912,7 @@ void script_parse_op_free (script_op_t *op)
           break;
         }
     }
+  script_debug_remove_element (op);
   free (op);
 }