stage3/forced_narrow_candidate_datatypes.cc
changeset 681 e837adad2437
parent 679 2f5618c0039a
child 684 0e417d42cf6a
equal deleted inserted replaced
680:df783da3ebe2 681:e837adad2437
    53  * (2) --> Data type after executing 2nd pass of forced_narrow_candidate_datatypes_c
    53  * (2) --> Data type after executing 2nd pass of forced_narrow_candidate_datatypes_c
    54  * 
    54  * 
    55  * --- --> NULL (undefined datatype)
    55  * --- --> NULL (undefined datatype)
    56  * *** --> invalid_type_name_c (invalid datatype)
    56  * *** --> invalid_type_name_c (invalid datatype)
    57  *
    57  *
    58  * (0)       (1)   (2)
    58  * (0)   PASS1   (1)    PASS2   (2)
    59  *      
    59  *      
    60  * ---       ***   ***       CAL tonv (                          
    60  * ---     (e)   ***            ***       CAL tonv (                          
    61  *                                  PT := T#1s                   
    61  *                                               PT := T#1s                   
    62  *                               )                               
    62  *                                            )                               
    63  * ---       ***   ***       JMP l4                              
    63  * ---     (e)   ***            ***       JMP l4                              
    64  *
    64  *
    65  * ---       sint  sint  l0: LD  1                               
    65  * ---     (e)   sint           sint  l0: LD  1                               
    66  * ---       sint  sint      ADD 2                               
    66  * ---     (e)   sint           sint      ADD 2                               
    67  * --- (c)   sint  sint      CAL tonv (                          
    67  * ---  (c)      sint           sint      CAL tonv (                          
    68  *                               PT := T#1s                      
    68  *                                            PT := T#1s                      
    69  *                               )                               
    69  *                                            )                               
    70  *                                                               
    70  *                                                                            
    71  * ---       sint  sint      LD  45                              
    71  * ---     (e)   sint           sint      LD  45                              
    72  * --- (c)   sint  sint      ADD 45                              
    72  * ---  (c)      sint           sint      ADD 45                              
    73  *
    73  *
    74  *
    74  *
    75  * ---       sint  sint      LD  3                               
    75  * ---     (e)   sint           sint      LD  3                               
    76  * ---       sint  sint  l1:                                     
    76  * ---     (e)   sint           sint  l1:                                     
    77  * --- (c)   sint  sint  l2: ADD 4                               
    77  * ---  (c)      sint           sint  l2: ADD 4                               
    78  * int       int   int       LD  5                               
    78  * int           int            int       LD  5                               
    79  * int       int   int       ST  n                               
    79  * int           int            int       ST  n                               
    80  * int       int   int       JMP l3                              
    80  * int           int            int       JMP l3                              
    81  *                                                               
    81  *                                                                            
    82  * --- (d)   ---   sint      LD  5                               
    82  * ---  (d)      ---      (e)   sint      LD  5                               
    83  * --- (d)   ---   sint      SUB 6                               
    83  * ---  (d)      ---      (e)   sint      SUB 6                               
    84  * --- (d)   sint  sint      JMP l1                              
    84  * ---  (d)(e)   sint           sint      JMP l1                              
    85  *
    85  *
    86  * ---       bool  bool      LD  FALSE                           
    86  * ---     (e)   bool           bool      LD  FALSE                           
    87  * ---       bool  bool      NOT                                 
    87  * ---     (e)   bool           bool      NOT                                 
    88  * --- (b)   bool  bool      RET                                 
    88  * ---  (b)      bool           bool      RET                                 
    89  *
    89  *
    90  * int       int   int   l3:                                     
    90  * int           int            int   l3:                                     
    91  * int       int   int       ST  n                               
    91  * int           int            int       ST  n                               
    92  * --- (b)   int   int       RET                                 
    92  * ---  (b)      int            int       RET                                 
    93  *
    93  *
    94  * ---       ***   ***   l4:                                     
    94  * ---     (e)   ***            ***   l4:                                     
    95  * ---       ***   ***       CAL tonv (                          
    95  * ---     (e)   ***            ***       CAL tonv (                          
    96  *                                  PT := T#1s                   
    96  *                                               PT := T#1s                   
    97  *                               )                               
    97  *                                            )                               
    98  * --- (a)   ***   ***       JMP l0                              
    98  * ---  (a)      ***            ***       JMP l0                              
    99  * --- (b)   byte  byte      LD  88                              
    99  * ---  (b)      byte           byte      LD  88                              
   100  *
   100  *
   101  *
   101  *
   102  *   
   102  *   
   103  */
   103  */
   104 
   104 
   115  :narrow_candidate_datatypes_c(ignore) {
   115  :narrow_candidate_datatypes_c(ignore) {
   116 }
   116 }
   117 
   117 
   118 forced_narrow_candidate_datatypes_c::~forced_narrow_candidate_datatypes_c(void) {
   118 forced_narrow_candidate_datatypes_c::~forced_narrow_candidate_datatypes_c(void) {
   119 }
   119 }
       
   120 
   120 
   121 
   121 
   122 
   122 
   123 
   123 
   124 
   124 
   125 
   166         /* find the datatype of the following IL instructions (they should all be identical by now, but we don't have an assertion checking for this. */
   167         /* find the datatype of the following IL instructions (they should all be identical by now, but we don't have an assertion checking for this. */
   167         for (unsigned int i=0; i < symbol->next_il_instruction.size(); i++)
   168         for (unsigned int i=0; i < symbol->next_il_instruction.size(); i++)
   168           if (NULL != symbol->next_il_instruction[i]->datatype)
   169           if (NULL != symbol->next_il_instruction[i]->datatype)
   169             next_datatype = symbol->next_il_instruction[i]->datatype;
   170             next_datatype = symbol->next_il_instruction[i]->datatype;
   170         if (get_datatype_info_c::is_type_valid(next_datatype)) {
   171         if (get_datatype_info_c::is_type_valid(next_datatype)) {
   171           /* This will occur in the following situations from the above example	   
   172           //  This will occur in the situations (c) in the above example
   172            *    (d)   during the second pass of this algorithm (remember, we execute this algorithm twice, because of backward JMPs!)
       
   173            */
       
   174           symbol->datatype = symbol->candidate_datatypes[0]; 
   173           symbol->datatype = symbol->candidate_datatypes[0]; 
   175         } else {
   174         } else {
   176           /* This will occur in the following situations from the above example	   
   175           //  This will occur in the situations (d) in the above example
   177            *    (d)   during the first pass of this algorithm (remember, we execute this algorithm twice, because of backward JMPs!)
       
   178            */
       
   179           // it is not possible to determine the exact situation in the current pass, so we can't do anything just yet. Leave it for the next time around!
   176           // it is not possible to determine the exact situation in the current pass, so we can't do anything just yet. Leave it for the next time around!
   180         }
   177         }
   181       }
   178       }
   182     }
   179     }
   183   }
   180   }
   184   
   181   
   185   /* return control to the visit() method of the base class! */
   182   /* return control to the visit() method of the base class! */
   186   narrow_candidate_datatypes_c::visit(symbol);
   183   narrow_candidate_datatypes_c::visit(symbol);  //  This handle the situations (e) in the above example
   187   
   184   
   188   return NULL;
   185   return NULL;
   189 }
   186 }
   190 
   187 
   191 
   188 
   234     void *visit(il_param_list_c *symbol);
   231     void *visit(il_param_list_c *symbol);
   235     void *visit(il_param_assignment_c *symbol);
   232     void *visit(il_param_assignment_c *symbol);
   236     void *visit(il_param_out_assignment_c *symbol);
   233     void *visit(il_param_out_assignment_c *symbol);
   237  */
   234  */
   238 
   235 
       
   236 
       
   237 
       
   238 /***************************************/
       
   239 /* B.3 - Language ST (Structured Text) */
       
   240 /***************************************/
       
   241 // SYM_LIST(statement_list_c)
       
   242 /* The normal narrow_candidate_datatypes_c algorithm does not leave any symbol, in an ST code, with an undefined datatype.
       
   243  * There is therefore no need to re-run the narrow algorithm here, so we overide the narrow_candidate_datatypes_c visitor,
       
   244  * and simply bug out!
       
   245  */
       
   246 void *forced_narrow_candidate_datatypes_c::visit(statement_list_c *symbol) {return NULL;}
       
   247