diff options
Diffstat (limited to 'src/decomp/expr/arithm.c')
-rw-r--r-- | src/decomp/expr/arithm.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/decomp/expr/arithm.c b/src/decomp/expr/arithm.c index d91e080..3811cf4 100644 --- a/src/decomp/expr/arithm.c +++ b/src/decomp/expr/arithm.c @@ -56,6 +56,12 @@ static void g_arithm_expression_class_init(GArithmExpressionClass *); /* Initialise une instance d'opération arithmétique définie. */ static void g_arithm_expression_init(GArithmExpression *); +/* Visite un ensemble hiérarchique d'instructions décompilées. */ +static bool g_arithm_expression_visit(GArithmExpression *, dec_instr_visitor_cb, DecInstrVisitFlags, void *); + +/* Remplace une instruction décompilée par une autre. */ +static bool g_arithm_expression_replace(GArithmExpression *, GDecInstruction *, GDecInstruction *); + /* Imprime pour l'écran un version humaine d'une expression. */ static GBufferLine *g_arithm_expression_print(const GArithmExpression *, GCodeBuffer *, GBufferLine *, GLangOutput *); @@ -101,6 +107,8 @@ static void g_arithm_expression_init(GArithmExpression *expr) instr = G_DEC_INSTRUCTION(expr); + instr->visit = (dec_instr_visit_fc)g_arithm_expression_visit; + instr->replace = (dec_instr_replace_fc)g_arithm_expression_replace; instr->print = (dec_instr_print_fc)g_arithm_expression_print; } @@ -138,6 +146,82 @@ GDecInstruction *g_arithm_expression_new(GDecExpression *op1, ArithmOperationTyp /****************************************************************************** * * +* 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_arithm_expression_visit(GArithmExpression *expr, dec_instr_visitor_cb callback, DecInstrVisitFlags flags, void *data) +{ + bool result; /* Bilan à retourner */ + + result = g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->op1), callback, flags, data); + + if (result) + result = g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->op2), 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_arithm_expression_replace(GArithmExpression *expr, GDecInstruction *old, GDecInstruction *new) +{ + bool result; /* Bilan à retourner */ + + if (expr->op1 == G_DEC_EXPRESSION(old)) + { + g_object_unref(G_OBJECT(expr->op1)); + g_object_ref(G_OBJECT(new)); + expr->op1 = G_DEC_EXPRESSION(new); + + result = true; + + } + else + result = g_dec_instruction_replace(G_DEC_INSTRUCTION(expr->op1), old, new); + + if (expr->op2 == G_DEC_EXPRESSION(old)) + { + g_object_unref(G_OBJECT(expr->op2)); + g_object_ref(G_OBJECT(new)); + expr->op2 = G_DEC_EXPRESSION(new); + + result = true; + + } + else + result |= g_dec_instruction_replace(G_DEC_INSTRUCTION(expr->op2), 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. * |