From 48e663f21a6429787fec2c426f46024dad9cde08 Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Sun, 3 Feb 2013 00:47:09 +0000
Subject: Added more options to render braces (or not) around decompiled
 blocks.

git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@337 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
---
 ChangeLog                        | 12 ++++++++
 src/analysis/decomp/decompiler.c |  3 ++
 src/analysis/decomp/il.c         |  1 +
 src/decomp/expr/block.c          | 61 ++++++++++++++++++++++++++++++++++++++--
 src/decomp/expr/block.h          | 16 +++++++++++
 5 files changed, 91 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 48a5414..90a1cb1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+13-02-03  Cyrille Bagard <nocbos@gmail.com>
+
+	* src/analysis/decomp/decompiler.c:
+	Force braces for routines bodies.
+
+	* src/analysis/decomp/il.c:
+	Avoid braces for switch cases content.
+
+	* src/decomp/expr/block.c:
+	* src/decomp/expr/block.h:
+	Add more options to render braces (or not) around decompiled blocks.
+
 13-02-02  Cyrille Bagard <nocbos@gmail.com>
 
 	* plugins/androhelpers/switch.c:
diff --git a/src/analysis/decomp/decompiler.c b/src/analysis/decomp/decompiler.c
index 67583bb..c36811d 100644
--- a/src/analysis/decomp/decompiler.c
+++ b/src/analysis/decomp/decompiler.c
@@ -186,6 +186,9 @@ static void prepare_all_routines_for_decomp(const GLoadedBinary *binary, const c
 
         reduce_used_variables(dinstrs);
 
+        
+        g_expr_block_set_border_behavior(G_EXPR_BLOCK(dinstrs), BBB_FORCE_ON);
+
         g_binary_routine_set_decomp_instructions(routines[i], dinstrs);
 
 
diff --git a/src/analysis/decomp/il.c b/src/analysis/decomp/il.c
index 9e235a6..595cad1 100644
--- a/src/analysis/decomp/il.c
+++ b/src/analysis/decomp/il.c
@@ -736,6 +736,7 @@ static void build_switch_branches(GSwitchInstruction *decomp, GFlowBlock *block,
             g_object_unref(G_OBJECT(sub_ctx));
 
             close_case_decomp_instructions(case_dinstr, next_block, dests, i, dcount);
+            g_expr_block_set_border_behavior(G_EXPR_BLOCK(case_dinstr), BBB_FORCE_OFF);
 
             if (info[i].imm != NULL)
             {
diff --git a/src/decomp/expr/block.c b/src/decomp/expr/block.c
index b58972d..7c2387a 100644
--- a/src/decomp/expr/block.c
+++ b/src/decomp/expr/block.c
@@ -37,6 +37,8 @@ struct _GExprBlock
 {
     GDecExpression parent;                  /* A laisser en premier        */
 
+    BlockBordeBehavior behavior;            /* Type de Rendu des bordures  */
+
     GDecInstruction **list;                 /* Instructions contenues      */
     size_t count;                           /* Taille de cette liste       */
 
@@ -113,6 +115,8 @@ static void g_expr_block_init(GExprBlock *block)
     instr->replace = (dec_instr_replace_fc)g_expr_block_replace;
     instr->print = (dec_instr_print_fc)g_expr_block_print;
 
+    block->behavior = BBB_AUTO;
+
 }
 
 
@@ -143,6 +147,45 @@ GDecInstruction *g_expr_block_new(GDecInstruction *item)
 
 /******************************************************************************
 *                                                                             *
+*  Paramètres  : block = première instruction à venir visiter.                *
+*                                                                             *
+*  Description : Fournit le comportement du bloc pour le rendu de ses bords.  *
+*                                                                             *
+*  Retour      : Comportement pour le rendu des bordures.                     *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+BlockBordeBehavior g_expr_block_get_border_behavior(const GExprBlock *block)
+{
+    return block->behavior;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : block    = première instruction à venir visiter.             *
+*                behavior = comportement pour le rendu des bordures.          *
+*                                                                             *
+*  Description : Définit le comportement du bloc pour le rendu de ses bords.  *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+void g_expr_block_set_border_behavior(GExprBlock *block, BlockBordeBehavior behavior)
+{
+    block->behavior = behavior;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
 *  Paramètres  : block    = première instruction à venir visiter.             *
 *                callback = procédure à appeler à chaque instruction visitée. *
 *                flags    = moments des appels à réaliser en retour.          *
@@ -232,9 +275,23 @@ static bool g_expr_block_replace(GExprBlock *block, GDecInstruction *old, GDecIn
 static GBufferLine *g_expr_block_print(const GExprBlock *block, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output)
 {
     GBufferLine *result;                    /* Ligne à retourner           */
+    size_t expr_count;                      /* Taille officielle           */
     size_t i;                               /* Boucle de parcours          */
 
-    result = g_lang_output_start_code_block(output, buffer, line, block->count);
+    switch (block->behavior)
+    {
+        case BBB_AUTO:
+            expr_count = block->count;
+            break;
+        case BBB_FORCE_OFF:
+            expr_count = 1;
+            break;
+        case BBB_FORCE_ON:
+            expr_count = 2;
+            break;
+    }
+
+    result = g_lang_output_start_code_block(output, buffer, line, expr_count);
 
     for (i = 0; i < block->count; i++)
     {
@@ -245,7 +302,7 @@ static GBufferLine *g_expr_block_print(const GExprBlock *block, GCodeBuffer *buf
 
     }
 
-    result = g_lang_output_end_code_block(output, buffer, result, block->count);
+    result = g_lang_output_end_code_block(output, buffer, result, expr_count);
 
     return result;
 
diff --git a/src/decomp/expr/block.h b/src/decomp/expr/block.h
index b0c2baa..b0788dd 100644
--- a/src/decomp/expr/block.h
+++ b/src/decomp/expr/block.h
@@ -48,12 +48,28 @@ typedef struct _GExprBlock GExprBlock;
 typedef struct _GExprBlockClass GExprBlockClass;
 
 
+/* Rendu des bordures */
+typedef enum _BlockBordeBehavior
+{
+    BBB_AUTO,
+    BBB_FORCE_OFF,
+    BBB_FORCE_ON
+
+} BlockBordeBehavior;
+
+
 /* Indique le type défini pour un ensemble d'instructions décompilées. */
 GType g_expr_block_get_type(void);
 
 /* Constuit un conteneur pour diverses instructions décompilées. */
 GDecInstruction *g_expr_block_new(GDecInstruction *);
 
+/* Fournit le comportement du bloc pour le rendu de ses bords. */
+BlockBordeBehavior g_expr_block_get_border_behavior(const GExprBlock *);
+
+/* Définit le comportement du bloc pour le rendu de ses bords. */
+void g_expr_block_set_border_behavior(GExprBlock *, BlockBordeBehavior);
+
 /* Ajoute une instruction décompilée au conteneur existant. */
 void g_expr_block_add_item(GExprBlock *, GDecInstruction *);
 
-- 
cgit v0.11.2-87-g4458