Fix flow control analysis of IL simple instructions (i.e. IL instructions inside parenthises!)
authorMario de Sousa <msousa@fe.up.pt>
Thu, 25 Oct 2012 12:05:31 +0100
changeset 685 5b19e376cc94
parent 684 0e417d42cf6a
child 686 9b87606d4c07
Fix flow control analysis of IL simple instructions (i.e. IL instructions inside parenthises!)
absyntax/absyntax.def
stage3/flow_control_analysis.cc
--- a/absyntax/absyntax.def	Thu Oct 25 11:28:06 2012 +0100
+++ b/absyntax/absyntax.def	Thu Oct 25 12:05:31 2012 +0100
@@ -911,6 +911,7 @@
 /* NOTE: The parameters 'prev_il_instruction'/'next_il_instruction' are used to point to all previous/next il instructions that may be executed imedaitely before/after this instruction.
  *       In case of an il instruction preceded by a label, the previous_il_instruction will include all IL instructions that jump to this label!
  *       It is filled in by the flow_control_analysis_c during stage 3.
+ *       This will essentially be a doubly linked list of il_instruction_c and il_simple_instruction_c objects!!
  */
 SYM_REF2(il_instruction_c, label, il_instruction, std::vector <symbol_c *> prev_il_instruction, next_il_instruction;)
 
@@ -960,8 +961,12 @@
  * | il_expression eol_list
  * | il_formal_funct_call eol_list
  */
-/* NOTE: The parameter 'prev_il_instruction' is used to point to all previous il instructions that may be executed imedaitely before this instruction. */
-SYM_REF1(il_simple_instruction_c, il_simple_instruction, std::vector <symbol_c *> prev_il_instruction;)
+/* NOTE: The parameters 'prev_il_instruction'/'next_il_instruction' are used to point to all previous/next il instructions that may be executed imedaitely before/after this instruction.
+ *       In case of an il instruction preceded by a label, the previous_il_instruction will include all IL instructions that jump to this label!
+ *       It is filled in by the flow_control_analysis_c during stage 3.
+ *       This will essentially be a doubly linked list of il_instruction_c and il_simple_instruction_c objects!!
+ */
+SYM_REF1(il_simple_instruction_c, il_simple_instruction, std::vector <symbol_c *> prev_il_instruction, next_il_instruction;)
 
 /* | il_initial_param_list il_param_instruction */
 SYM_LIST(il_param_list_c)
--- a/stage3/flow_control_analysis.cc	Thu Oct 25 11:28:06 2012 +0100
+++ b/stage3/flow_control_analysis.cc	Thu Oct 25 12:05:31 2012 +0100
@@ -132,12 +132,18 @@
 
 
 void flow_control_analysis_c::link_insert(symbol_c *prev_instruction, symbol_c *next_instruction) {
-	il_instruction_c *next = dynamic_cast<il_instruction_c *>(next_instruction);
-	il_instruction_c *prev = dynamic_cast<il_instruction_c *>(prev_instruction);
-	if ((NULL == next) || (NULL == prev)) ERROR;
-
-	next->prev_il_instruction.insert(next->prev_il_instruction.begin(), prev);
-	prev->next_il_instruction.insert(prev->next_il_instruction.begin(), next);
+	il_instruction_c        *next_a = dynamic_cast<il_instruction_c        *>(next_instruction);
+	il_instruction_c        *prev_a = dynamic_cast<il_instruction_c        *>(prev_instruction);
+	il_simple_instruction_c *next_b = dynamic_cast<il_simple_instruction_c *>(next_instruction);
+	il_simple_instruction_c *prev_b = dynamic_cast<il_simple_instruction_c *>(prev_instruction);
+	
+	if       (NULL != next_a)  next_a->prev_il_instruction.insert(next_a->prev_il_instruction.begin(), prev_instruction);
+	else if  (NULL != next_b)  next_b->prev_il_instruction.insert(next_b->prev_il_instruction.begin(), prev_instruction);
+	else ERROR;
+	
+	if       (NULL != prev_a)  prev_a->next_il_instruction.insert(prev_a->next_il_instruction.begin(), next_instruction);
+	else if  (NULL != prev_b)  prev_b->next_il_instruction.insert(prev_b->next_il_instruction.begin(), next_instruction);
+	else ERROR;
 }