# HG changeset patch # User Mario de Sousa # Date 1351186043 -3600 # Node ID 958454e9e40fde5f313532c20f9cf4ab14a2d0c4 # Parent 6156ee2b4e329e0473e24eb58676660d7b989be4 Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis. diff -r 6156ee2b4e32 -r 958454e9e40f stage3/forced_narrow_candidate_datatypes.cc --- a/stage3/forced_narrow_candidate_datatypes.cc Thu Oct 25 18:20:28 2012 +0100 +++ b/stage3/forced_narrow_candidate_datatypes.cc Thu Oct 25 18:27:23 2012 +0100 @@ -120,6 +120,32 @@ +void forced_narrow_candidate_datatypes_c::forced_narrow_il_instruction(symbol_c *symbol, std::vector &next_il_instruction) { + if (NULL == symbol->datatype) { + if (symbol->candidate_datatypes.empty()) { + symbol->datatype = &(search_constant_type_c::invalid_type_name); // This will occur in the situations (a) in the above example + // return NULL; // No need to return control to the visit() method of the base class... But we do so, just to be safe (called at the end of this function)! + } else { + if (next_il_instruction.empty()) { + symbol->datatype = symbol->candidate_datatypes[0]; // This will occur in the situations (b) in the above example + } else { + symbol_c *next_datatype = NULL; + + /* 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. */ + for (unsigned int i=0; i < next_il_instruction.size(); i++) + if (NULL != next_il_instruction[i]->datatype) + next_datatype = next_il_instruction[i]->datatype; + if (get_datatype_info_c::is_type_valid(next_datatype)) { + // This will occur in the situations (c) in the above example + symbol->datatype = symbol->candidate_datatypes[0]; + } else { + // This will occur in the situations (d) in the above example + // 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! + } + } + } + } +} @@ -159,35 +185,10 @@ // SYM_REF2(il_instruction_c, label, il_instruction) // void *visit(instruction_list_c *symbol); void *forced_narrow_candidate_datatypes_c::visit(il_instruction_c *symbol) { - if (NULL == symbol->datatype) { - if (symbol->candidate_datatypes.empty()) { - symbol->datatype = &(search_constant_type_c::invalid_type_name); // This will occur in the situations (a) in the above example - // return NULL; // No need to return control to the visit() method of the base class... But we do so, just to be safe (called at the end of this function)! - } else { - if (symbol->next_il_instruction.empty()) { - symbol->datatype = symbol->candidate_datatypes[0]; // This will occur in the situations (b) in the above example - } else { - symbol_c *next_datatype = NULL; - - /* 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. */ - for (unsigned int i=0; i < symbol->next_il_instruction.size(); i++) - if (NULL != symbol->next_il_instruction[i]->datatype) - next_datatype = symbol->next_il_instruction[i]->datatype; - if (get_datatype_info_c::is_type_valid(next_datatype)) { - // This will occur in the situations (c) in the above example - symbol->datatype = symbol->candidate_datatypes[0]; - } else { - // This will occur in the situations (d) in the above example - // 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! - } - } - } - } + forced_narrow_il_instruction(symbol, symbol->next_il_instruction); /* return control to the visit() method of the base class! */ - narrow_candidate_datatypes_c::visit(symbol); // This handle the situations (e) in the above example - - return NULL; + return narrow_candidate_datatypes_c::visit(symbol); // This handles the situations (e) in the above example } @@ -230,7 +231,13 @@ // void *forced_narrow_candidate_datatypes_c::visit(simple_instr_list_c *symbol) // SYM_REF1(il_simple_instruction_c, il_simple_instruction, symbol_c *prev_il_instruction;) -// void *forced_narrow_candidate_datatypes_c::visit(il_simple_instruction_c*symbol) +void *forced_narrow_candidate_datatypes_c::visit(il_simple_instruction_c*symbol) { + forced_narrow_il_instruction(symbol, symbol->next_il_instruction); + + /* return control to the visit() method of the base class! */ + return narrow_candidate_datatypes_c::visit(symbol); // This handle the situations (e) in the above example +} + /* void *visit(il_param_list_c *symbol); diff -r 6156ee2b4e32 -r 958454e9e40f stage3/forced_narrow_candidate_datatypes.hh --- a/stage3/forced_narrow_candidate_datatypes.hh Thu Oct 25 18:20:28 2012 +0100 +++ b/stage3/forced_narrow_candidate_datatypes.hh Thu Oct 25 18:27:23 2012 +0100 @@ -46,13 +46,12 @@ class forced_narrow_candidate_datatypes_c: public narrow_candidate_datatypes_c { private: - - private: - + void forced_narrow_il_instruction(symbol_c *symbol, std::vector &next_il_instruction); + public: forced_narrow_candidate_datatypes_c(symbol_c *ignore); virtual ~forced_narrow_candidate_datatypes_c(void); - + /****************************************/ /* B.2 - Language IL (Instruction List) */ /****************************************/ @@ -69,7 +68,7 @@ // void *visit(il_formal_funct_call_c *symbol); // void *visit(il_operand_list_c *symbol); // void *visit(simple_instr_list_c *symbol); -// void *visit(il_simple_instruction_c*symbol); + void *visit(il_simple_instruction_c*symbol); // void *visit(il_param_list_c *symbol); // void *visit(il_param_assignment_c *symbol); // void *visit(il_param_out_assignment_c *symbol);