diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2013-01-27 00:43:59 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2013-01-27 00:43:59 (GMT) |
commit | 7f35f8d2f211fdf087252ede7665e9c81f35cdc7 (patch) | |
tree | d1c88366bc73e51db38ef982897e95950405bf52 /src/decomp/expr/array.c | |
parent | 2050b07c42c15738662dd9b3c5841694b64ab2a3 (diff) |
Implemented the first steps for visiting or replacing items in decompiled instructions.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@331 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/decomp/expr/array.c')
-rw-r--r-- | src/decomp/expr/array.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/decomp/expr/array.c b/src/decomp/expr/array.c index dc487ee..4053169 100644 --- a/src/decomp/expr/array.c +++ b/src/decomp/expr/array.c @@ -54,6 +54,12 @@ static void g_array_access_class_init(GArrayAccessClass *); /* Initialise une instance d'accès à une cellule de tableau. */ static void g_array_access_init(GArrayAccess *); +/* Visite un ensemble hiérarchique d'instructions décompilées. */ +static bool g_array_access_visit(GArrayAccess *, dec_instr_visitor_cb, DecInstrVisitFlags, void *); + +/* Remplace une instruction décompilée par une autre. */ +static bool g_array_access_replace(GArrayAccess *, GDecInstruction *, GDecInstruction *); + /* Imprime pour l'écran un version humaine d'une expression. */ static GBufferLine *g_array_access_print(const GArrayAccess *, GCodeBuffer *, GBufferLine *, GLangOutput *); @@ -99,6 +105,8 @@ static void g_array_access_init(GArrayAccess *expr) instr = G_DEC_INSTRUCTION(expr); + instr->visit = (dec_instr_visit_fc)g_array_access_visit; + instr->replace = (dec_instr_replace_fc)g_array_access_replace; instr->print = (dec_instr_print_fc)g_array_access_print; } @@ -133,6 +141,82 @@ GDecInstruction *g_array_access_new(GDecExpression *array, GDecExpression *index /****************************************************************************** * * +* Paramètres : expr = première instruction à venir visiter. * +* callback = procédure à appeler à chaque instruction visitée. * +* flags = moments des appels à réaliser en retour. * +* data = données quelconques associées au visiteur. * +* * +* Description : Visite un ensemble hiérarchique d'instructions décompilées. * +* * +* Retour : true si le parcours a été jusqu'à son terme, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_array_access_visit(GArrayAccess *expr, dec_instr_visitor_cb callback, DecInstrVisitFlags flags, void *data) +{ + bool result; /* Bilan à retourner */ + + result = g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->array), callback, flags, data); + + if (result) + result = g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->index), callback, flags, data); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : expr = première instruction à venir ausculter. * +* old = instruction décompilée à venir remplacer. * +* new = instruction décompilée à utiliser dorénavant. * +* * +* Description : Remplace une instruction décompilée par une autre. * +* * +* Retour : true si un remplacement a été effectué, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_array_access_replace(GArrayAccess *expr, GDecInstruction *old, GDecInstruction *new) +{ + bool result; /* Bilan à retourner */ + + if (expr->array == G_DEC_EXPRESSION(old)) + { + g_object_unref(G_OBJECT(expr->array)); + g_object_ref(G_OBJECT(new)); + expr->array = G_DEC_EXPRESSION(new); + + result = true; + + } + else + result = g_dec_instruction_replace(G_DEC_INSTRUCTION(expr->array), old, new); + + if (expr->index == G_DEC_EXPRESSION(old)) + { + g_object_unref(G_OBJECT(expr->index)); + g_object_ref(G_OBJECT(new)); + expr->index = G_DEC_EXPRESSION(new); + + result = true; + + } + else + result |= g_dec_instruction_replace(G_DEC_INSTRUCTION(expr->index), old, new); + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : expr = expression à transcrire en version humaine. * * buffer = tampon où doit se réaliser l'insertion. * * line = ligne d'impression prête à emploi ou NULL. * |