2009 |
2009 |
2010 /* IF expression THEN statement_list elseif_statement_list ELSE statement_list END_IF */ |
2010 /* IF expression THEN statement_list elseif_statement_list ELSE statement_list END_IF */ |
2011 // SYM_REF4(if_statement_c, expression, statement_list, elseif_statement_list, else_statement_list) |
2011 // SYM_REF4(if_statement_c, expression, statement_list, elseif_statement_list, else_statement_list) |
2012 void *visit_expression_type_c::visit(if_statement_c *symbol) { |
2012 void *visit_expression_type_c::visit(if_statement_c *symbol) { |
2013 symbol_c *expr_type = base_type((symbol_c*)symbol->expression->accept(*this)); |
2013 symbol_c *expr_type = base_type((symbol_c*)symbol->expression->accept(*this)); |
2014 if (!is_BOOL_type(expr_type)) STAGE3_ERROR(symbol,symbol,"IF conditional expression is not of boolean type."); |
2014 if (!is_BOOL_type(expr_type)) STAGE3_ERROR(symbol->expression,symbol->expression,"IF conditional expression is not of boolean type."); |
2015 if (NULL != symbol->statement_list) |
2015 if (NULL != symbol->statement_list) |
2016 symbol->statement_list->accept(*this); |
2016 symbol->statement_list->accept(*this); |
2017 if (NULL != symbol->elseif_statement_list) |
2017 if (NULL != symbol->elseif_statement_list) |
2018 symbol->elseif_statement_list->accept(*this); |
2018 symbol->elseif_statement_list->accept(*this); |
2019 if (NULL != symbol->else_statement_list) |
2019 if (NULL != symbol->else_statement_list) |
2028 /* helper symbol for elseif_statement_list */ |
2028 /* helper symbol for elseif_statement_list */ |
2029 /* ELSIF expression THEN statement_list */ |
2029 /* ELSIF expression THEN statement_list */ |
2030 // SYM_REF2(elseif_statement_c, expression, statement_list) |
2030 // SYM_REF2(elseif_statement_c, expression, statement_list) |
2031 void *visit_expression_type_c::visit(elseif_statement_c *symbol) { |
2031 void *visit_expression_type_c::visit(elseif_statement_c *symbol) { |
2032 symbol_c *elseif_expr_type = base_type((symbol_c*)symbol->expression->accept(*this)); |
2032 symbol_c *elseif_expr_type = base_type((symbol_c*)symbol->expression->accept(*this)); |
2033 if(!is_BOOL_type(elseif_expr_type)) STAGE3_ERROR(symbol,symbol,"ELSIF conditional expression is not of boolean type."); |
2033 if(!is_BOOL_type(elseif_expr_type)) STAGE3_ERROR(symbol->expression,symbol->expression,"ELSIF conditional expression is not of boolean type."); |
2034 if (NULL != symbol->statement_list) |
2034 if (NULL != symbol->statement_list) |
2035 symbol->statement_list->accept(*this); |
2035 symbol->statement_list->accept(*this); |
2036 return NULL; |
2036 return NULL; |
2037 } |
2037 } |
2038 |
2038 |
2093 // ASSIGN |
2093 // ASSIGN |
2094 symbol_c *beg_expr_type = base_type((symbol_c*)symbol->beg_expression->accept(*this)); |
2094 symbol_c *beg_expr_type = base_type((symbol_c*)symbol->beg_expression->accept(*this)); |
2095 if (NULL != beg_expr_type) { |
2095 if (NULL != beg_expr_type) { |
2096 /* The BEG value is assigned to the variable, so we check for assignment validity! */ |
2096 /* The BEG value is assigned to the variable, so we check for assignment validity! */ |
2097 if(!is_valid_assignment(var_type, beg_expr_type)) |
2097 if(!is_valid_assignment(var_type, beg_expr_type)) |
2098 STAGE3_ERROR(symbol, symbol, "Data type mismatch between control variable and initial value."); |
2098 STAGE3_ERROR(symbol->beg_expression, symbol->beg_expression, "Data type mismatch between control variable and initial value."); |
2099 } |
2099 } |
2100 // TO |
2100 // TO |
2101 symbol_c *end_expr_type = base_type((symbol_c*)symbol->end_expression->accept(*this)); |
2101 symbol_c *end_expr_type = base_type((symbol_c*)symbol->end_expression->accept(*this)); |
2102 if (NULL != end_expr_type) { |
2102 if (NULL != end_expr_type) { |
2103 /* The TO value is only used for comparison, so we only check for compatibility! */ |
2103 /* The TO value is only used for comparison, so we only check for compatibility! */ |
2104 if(!is_compatible_type(var_type, end_expr_type)) |
2104 if(!is_compatible_type(var_type, end_expr_type)) |
2105 STAGE3_ERROR(symbol, symbol, "Data type mismatch between control variable and final value."); |
2105 STAGE3_ERROR(symbol->end_expression, symbol->end_expression, "Data type mismatch between control variable and final value."); |
2106 } |
2106 } |
2107 // BY |
2107 // BY |
2108 if(symbol->by_expression != NULL) { |
2108 if(symbol->by_expression != NULL) { |
2109 symbol_c *by_expr_type = base_type((symbol_c*)symbol->by_expression->accept(*this)); |
2109 symbol_c *by_expr_type = base_type((symbol_c*)symbol->by_expression->accept(*this)); |
2110 if (NULL != end_expr_type) { |
2110 if (NULL != end_expr_type) { |
2111 /* The BY value is used in an expression (add, sub, ...), so we only check for compatibility! */ |
2111 /* The BY value is used in an expression (add, sub, ...), so we only check for compatibility! */ |
2112 if(!is_compatible_type(var_type, by_expr_type)) |
2112 if(!is_compatible_type(var_type, by_expr_type)) |
2113 STAGE3_ERROR(symbol, symbol, "Data type mismatch between control variable and BY value."); |
2113 STAGE3_ERROR(symbol->by_expression, symbol->by_expression, "Data type mismatch between control variable and BY value."); |
2114 } |
2114 } |
2115 } |
2115 } |
2116 // DO |
2116 // DO |
2117 if (NULL != symbol->statement_list) |
2117 if (NULL != symbol->statement_list) |
2118 symbol->statement_list->accept(*this); |
2118 symbol->statement_list->accept(*this); |
2124 // SYM_REF2(while_statement_c, expression, statement_list) |
2124 // SYM_REF2(while_statement_c, expression, statement_list) |
2125 void *visit_expression_type_c::visit(while_statement_c *symbol) { |
2125 void *visit_expression_type_c::visit(while_statement_c *symbol) { |
2126 symbol_c *expr_type = base_type((symbol_c*)symbol->expression->accept(*this)); |
2126 symbol_c *expr_type = base_type((symbol_c*)symbol->expression->accept(*this)); |
2127 if (NULL != expr_type) { |
2127 if (NULL != expr_type) { |
2128 if(!is_BOOL_type(expr_type)) |
2128 if(!is_BOOL_type(expr_type)) |
2129 STAGE3_ERROR(symbol,symbol,"WHILE conditional expression is not of boolean type."); |
2129 STAGE3_ERROR(symbol->expression,symbol->expression,"WHILE conditional expression is not of boolean type."); |
2130 } |
2130 } |
2131 |
2131 |
2132 if (NULL != symbol->statement_list) |
2132 if (NULL != symbol->statement_list) |
2133 symbol->statement_list->accept(*this); |
2133 symbol->statement_list->accept(*this); |
2134 return NULL; |
2134 return NULL; |
2141 symbol->statement_list->accept(*this); |
2141 symbol->statement_list->accept(*this); |
2142 |
2142 |
2143 symbol_c *expr_type = base_type((symbol_c*)symbol->expression->accept(*this)); |
2143 symbol_c *expr_type = base_type((symbol_c*)symbol->expression->accept(*this)); |
2144 if (NULL != expr_type) { |
2144 if (NULL != expr_type) { |
2145 if(!is_BOOL_type(expr_type)) |
2145 if(!is_BOOL_type(expr_type)) |
2146 STAGE3_ERROR(symbol,symbol,"REPEAT conditional expression is not of boolean type."); |
2146 STAGE3_ERROR(symbol->expression,symbol->expression,"REPEAT conditional expression is not of boolean type."); |
2147 } |
2147 } |
2148 return NULL; |
2148 return NULL; |
2149 } |
2149 } |
2150 |
2150 |
2151 /* EXIT */ |
2151 /* EXIT */ |