stage4/generate_cc/generate_cc_st.cc
changeset 22 08bcc40be1fa
parent 16 e8b99f896416
child 24 7e830409f72a
equal deleted inserted replaced
21:ae19aa4ff2d9 22:08bcc40be1fa
   129 /* B 3.1 - Expressions */
   129 /* B 3.1 - Expressions */
   130 /***********************/
   130 /***********************/
   131 void *visit(or_expression_c *symbol) {
   131 void *visit(or_expression_c *symbol) {
   132   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   132   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   133   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   133   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   134   if (typeid(*left_type) == typeid(bool_type_name_c) && typeid(*right_type) == typeid(bool_type_name_c)) {
   134   if (search_expression_type->is_bool_type(left_type) && search_expression_type->is_bool_type(right_type)) {
   135     return print_binary_expression(symbol->l_exp, symbol->r_exp, " || ");
   135     return print_binary_expression(symbol->l_exp, symbol->r_exp, " || ");
   136   }
   136   }
   137   if (search_expression_type->is_numeric_compatible(left_type) && search_expression_type->is_numeric_compatible(right_type)) {
   137   if (search_expression_type->is_numeric_compatible(left_type) && search_expression_type->is_numeric_compatible(right_type)) {
   138     return print_binary_expression(symbol->l_exp, symbol->r_exp, " | ");
   138     return print_binary_expression(symbol->l_exp, symbol->r_exp, " | ");
   139   }
   139   }
   142 }
   142 }
   143 
   143 
   144 void *visit(xor_expression_c *symbol) {
   144 void *visit(xor_expression_c *symbol) {
   145   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   145   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   146   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   146   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   147   if (typeid(*left_type) == typeid(bool_type_name_c) && typeid(*right_type) == typeid(bool_type_name_c)) {
   147   if (search_expression_type->is_bool_type(left_type) && search_expression_type->is_bool_type(right_type)) {
   148     s4o.print("(");
   148     s4o.print("(");
   149     symbol->l_exp->accept(*this);
   149     symbol->l_exp->accept(*this);
   150     s4o.print(" && !");
   150     s4o.print(" && !");
   151     symbol->r_exp->accept(*this);
   151     symbol->r_exp->accept(*this);
   152     s4o.print(") || (!");
   152     s4o.print(") || (!");
   163 }
   163 }
   164 
   164 
   165 void *visit(and_expression_c *symbol) {
   165 void *visit(and_expression_c *symbol) {
   166   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   166   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   167   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   167   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   168   if (typeid(*left_type) == typeid(bool_type_name_c) && typeid(*right_type) == typeid(bool_type_name_c)) {
   168   if (search_expression_type->is_bool_type(left_type) && search_expression_type->is_bool_type(right_type)) {
   169     return print_binary_expression(symbol->l_exp, symbol->r_exp, " && ");
   169     return print_binary_expression(symbol->l_exp, symbol->r_exp, " && ");
   170   }
   170   }
   171   if (search_expression_type->is_numeric_compatible(left_type) && search_expression_type->is_numeric_compatible(right_type)) {
   171   if (search_expression_type->is_numeric_compatible(left_type) && search_expression_type->is_numeric_compatible(right_type)) {
   172     return print_binary_expression(symbol->l_exp, symbol->r_exp, " & ");
   172     return print_binary_expression(symbol->l_exp, symbol->r_exp, " & ");
   173   }
   173   }