From e84fc98325447f7094913772dda6e26c4bd861aa Mon Sep 17 00:00:00 2001 From: Charlie Brej Date: Mon, 31 Aug 2009 00:24:08 +0100 Subject: [PATCH] [script] Add a expressions and operators to the debug hashtables --- src/plugins/splash/script/script-debug.c | 47 ++++++++++++++++++++++++ src/plugins/splash/script/script-debug.h | 5 +++ src/plugins/splash/script/script-parse.c | 4 ++ 3 files changed, 56 insertions(+) diff --git a/src/plugins/splash/script/script-debug.c b/src/plugins/splash/script/script-debug.c index 9e9ef57a..65bc95a9 100644 --- a/src/plugins/splash/script/script-debug.c +++ b/src/plugins/splash/script/script-debug.c @@ -19,4 +19,51 @@ * * Written by: Charlie Brej */ +#include "ply-hashtable.h" +#include +#include + #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; +} diff --git a/src/plugins/splash/script/script-debug.h b/src/plugins/splash/script/script-debug.h index d7000d09..a9ddf0c7 100644 --- a/src/plugins/splash/script/script-debug.h +++ b/src/plugins/splash/script/script-debug.h @@ -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 */ diff --git a/src/plugins/splash/script/script-parse.c b/src/plugins/splash/script/script-parse.c index 60226eb5..ef9a79d5 100644 --- a/src/plugins/splash/script/script-parse.c +++ b/src/plugins/splash/script/script-parse.c @@ -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); } -- 2.47.3