summaryrefslogtreecommitdiff
path: root/src/decomp/expr/block.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/decomp/expr/block.c')
-rw-r--r--src/decomp/expr/block.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/decomp/expr/block.c b/src/decomp/expr/block.c
index 5124204..3c56ef6 100644
--- a/src/decomp/expr/block.c
+++ b/src/decomp/expr/block.c
@@ -57,6 +57,12 @@ static void g_expr_block_class_init(GExprBlockClass *);
/* Initialise une instance d'ensemble d'instructions. */
static void g_expr_block_init(GExprBlock *);
+/* Visite un ensemble hiérarchique d'instructions décompilées. */
+static bool g_expr_block_visit(GExprBlock *, dec_instr_visitor_cb, DecInstrVisitFlags, void *);
+
+/* Remplace une instruction décompilée par une autre. */
+static bool g_expr_block_replace(GExprBlock *, GDecInstruction *, GDecInstruction *);
+
/* Imprime pour l'écran un version humaine d'une expression. */
static GBufferLine *g_expr_block_print(const GExprBlock *, GCodeBuffer *, GBufferLine *, GLangOutput *);
@@ -102,6 +108,8 @@ static void g_expr_block_init(GExprBlock *block)
instr = G_DEC_INSTRUCTION(block);
+ instr->visit = (dec_instr_visit_fc)g_expr_block_visit;
+ instr->replace = (dec_instr_replace_fc)g_expr_block_replace;
instr->print = (dec_instr_print_fc)g_expr_block_print;
}
@@ -134,6 +142,78 @@ GDecInstruction *g_expr_block_new(GDecInstruction *item)
/******************************************************************************
* *
+* Paramètres : block = 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_expr_block_visit(GExprBlock *block, dec_instr_visitor_cb callback, DecInstrVisitFlags flags, void *data)
+{
+ bool result; /* Bilan à retourner */
+ size_t i; /* Boucle de parcours */
+
+ result = true;
+
+ for (i = 0; i < block->count && result; i++)
+ result = g_dec_instruction_visit(block->list[i], callback, flags, data);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : block = 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_expr_block_replace(GExprBlock *block, GDecInstruction *old, GDecInstruction *new)
+{
+ bool result; /* Bilan à retourner */
+ size_t i; /* Boucle de parcours */
+
+ result = false;
+
+ for (i = 0; i < block->count; i++)
+ {
+ if (block->list[i] == old)
+ {
+ g_object_unref(G_OBJECT(block->list[i]));
+ g_object_ref(G_OBJECT(new));
+ block->list[i] = new;
+
+ result = true;
+
+ }
+ else
+ result |= g_dec_instruction_replace(block->list[i], old, new);
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : block = expression à transcrire en version humaine. *
* buffer = tampon où doit se réaliser l'insertion. *
* line = ligne d'impression prête à emploi ou NULL. *