53 #define FIRST_(symbol1, symbol2) (((symbol1)->first_order < (symbol2)->first_order) ? (symbol1) : (symbol2)) |
53 #define FIRST_(symbol1, symbol2) (((symbol1)->first_order < (symbol2)->first_order) ? (symbol1) : (symbol2)) |
54 #define LAST_(symbol1, symbol2) (((symbol1)->last_order > (symbol2)->last_order) ? (symbol1) : (symbol2)) |
54 #define LAST_(symbol1, symbol2) (((symbol1)->last_order > (symbol2)->last_order) ? (symbol1) : (symbol2)) |
55 |
55 |
56 #define STAGE3_ERROR(error_level, symbol1, symbol2, ...) { \ |
56 #define STAGE3_ERROR(error_level, symbol1, symbol2, ...) { \ |
57 if (current_display_error_level >= error_level) { \ |
57 if (current_display_error_level >= error_level) { \ |
58 fprintf(stderr, "%s:%d-%d..%d-%d: error : ", \ |
58 fprintf(stderr, "%s:%d-%d..%d-%d: error: ", \ |
59 FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,\ |
59 FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,\ |
60 LAST_(symbol1,symbol2) ->last_line, LAST_(symbol1,symbol2) ->last_column);\ |
60 LAST_(symbol1,symbol2) ->last_line, LAST_(symbol1,symbol2) ->last_column);\ |
61 fprintf(stderr, __VA_ARGS__); \ |
61 fprintf(stderr, __VA_ARGS__); \ |
62 fprintf(stderr, "\n"); \ |
62 fprintf(stderr, "\n"); \ |
63 il_error = true; \ |
63 il_error = true; \ |
64 error_found = true; \ |
64 error_found = true; \ |
65 } \ |
65 } \ |
66 } |
66 } |
67 |
67 |
68 |
68 |
|
69 #define STAGE3_WARNING(symbol1, symbol2, ...) { \ |
|
70 fprintf(stderr, "%s:%d-%d..%d-%d: warning: ", \ |
|
71 FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,\ |
|
72 LAST_(symbol1,symbol2) ->last_line, LAST_(symbol1,symbol2) ->last_column);\ |
|
73 fprintf(stderr, __VA_ARGS__); \ |
|
74 fprintf(stderr, "\n"); \ |
|
75 warning_found = true; \ |
|
76 } |
|
77 |
|
78 |
69 /* set to 1 to see debug info during execution */ |
79 /* set to 1 to see debug info during execution */ |
70 static int debug = 0; |
80 static int debug = 0; |
71 |
81 |
72 print_datatypes_error_c::print_datatypes_error_c(symbol_c *ignore) { |
82 print_datatypes_error_c::print_datatypes_error_c(symbol_c *ignore) { |
73 error_found = false; |
83 error_found = false; |
|
84 warning_found = false; |
74 current_display_error_level = error_level_default; |
85 current_display_error_level = error_level_default; |
75 } |
86 } |
76 |
87 |
77 print_datatypes_error_c::~print_datatypes_error_c(void) { |
88 print_datatypes_error_c::~print_datatypes_error_c(void) { |
78 } |
89 } |
89 if (symbol == NULL) return NULL; |
100 if (symbol == NULL) return NULL; |
90 return (symbol_c *)symbol->accept(search_base_type); |
101 return (symbol_c *)symbol->accept(search_base_type); |
91 } |
102 } |
92 |
103 |
93 |
104 |
|
105 |
|
106 |
|
107 void print_datatypes_error_c::check_used_operation_status(symbol_c *symbol, symbol_c *left, symbol_c *right, const struct widen_entry widen_table[]) { |
|
108 /* find a compatible entry in the widening table */ |
|
109 for (int k = 0; NULL != widen_table[k].left; k++) |
|
110 if (is_type_equal(left, widen_table[k].left) && is_type_equal(right, widen_table[k].right)) |
|
111 if (widen_entry::deprecated == widen_table[k].status) |
|
112 STAGE3_WARNING(symbol, symbol, "Deprecated operation."); |
|
113 } |
94 |
114 |
95 |
115 |
96 /* |
116 /* |
97 typedef struct { |
117 typedef struct { |
98 symbol_c *function_name, |
118 symbol_c *function_name, |
892 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'ORN' operator."); |
912 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'ORN' operator."); |
893 return NULL; |
913 return NULL; |
894 } |
914 } |
895 |
915 |
896 void *print_datatypes_error_c::visit(ADD_operator_c *symbol) { |
916 void *print_datatypes_error_c::visit(ADD_operator_c *symbol) { |
|
917 /* TODO: print warning messages for deprecated operations! */ |
897 if ((symbol->candidate_datatypes.size() == 0) && |
918 if ((symbol->candidate_datatypes.size() == 0) && |
898 (il_operand->candidate_datatypes.size() > 0)) |
919 (il_operand->candidate_datatypes.size() > 0)) |
899 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'ADD' operator."); |
920 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'ADD' operator."); |
900 return NULL; |
921 return NULL; |
901 } |
922 } |
902 |
923 |
903 void *print_datatypes_error_c::visit(SUB_operator_c *symbol) { |
924 void *print_datatypes_error_c::visit(SUB_operator_c *symbol) { |
|
925 /* TODO: print warning messages for deprecated operations! */ |
904 if ((symbol->candidate_datatypes.size() == 0) && |
926 if ((symbol->candidate_datatypes.size() == 0) && |
905 (il_operand->candidate_datatypes.size() > 0)) |
927 (il_operand->candidate_datatypes.size() > 0)) |
906 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'SUB' operator."); |
928 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'SUB' operator."); |
907 return NULL; |
929 return NULL; |
908 } |
930 } |
909 |
931 |
910 void *print_datatypes_error_c::visit(MUL_operator_c *symbol) { |
932 void *print_datatypes_error_c::visit(MUL_operator_c *symbol) { |
|
933 /* TODO: print warning messages for deprecated operations! */ |
911 if ((symbol->candidate_datatypes.size() == 0) && |
934 if ((symbol->candidate_datatypes.size() == 0) && |
912 (il_operand->candidate_datatypes.size() > 0)) |
935 (il_operand->candidate_datatypes.size() > 0)) |
913 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'MUL' operator."); |
936 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'MUL' operator."); |
914 return NULL; |
937 return NULL; |
915 } |
938 } |
916 |
939 |
917 void *print_datatypes_error_c::visit(DIV_operator_c *symbol) { |
940 void *print_datatypes_error_c::visit(DIV_operator_c *symbol) { |
|
941 /* TODO: print warning messages for deprecated operations! */ |
918 if ((symbol->candidate_datatypes.size() == 0) && |
942 if ((symbol->candidate_datatypes.size() == 0) && |
919 (il_operand->candidate_datatypes.size() > 0)) |
943 (il_operand->candidate_datatypes.size() > 0)) |
920 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'DIV' operator."); |
944 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'DIV' operator."); |
921 return NULL; |
945 return NULL; |
922 } |
946 } |
1111 symbol->r_exp->accept(*this); |
1135 symbol->r_exp->accept(*this); |
1112 if ((symbol->candidate_datatypes.size() == 0) && |
1136 if ((symbol->candidate_datatypes.size() == 0) && |
1113 (symbol->l_exp->candidate_datatypes.size() > 0) && |
1137 (symbol->l_exp->candidate_datatypes.size() > 0) && |
1114 (symbol->r_exp->candidate_datatypes.size() > 0)) |
1138 (symbol->r_exp->candidate_datatypes.size() > 0)) |
1115 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '+' expression."); |
1139 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '+' expression."); |
1116 |
1140 |
|
1141 check_used_operation_status(symbol, symbol->l_exp->datatype,symbol->r_exp->datatype, widen_ADD_table); |
1117 return NULL; |
1142 return NULL; |
1118 } |
1143 } |
1119 |
1144 |
1120 |
1145 |
1121 |
1146 |
1124 symbol->r_exp->accept(*this); |
1149 symbol->r_exp->accept(*this); |
1125 if ((symbol->candidate_datatypes.size() == 0) && |
1150 if ((symbol->candidate_datatypes.size() == 0) && |
1126 (symbol->l_exp->candidate_datatypes.size() > 0) && |
1151 (symbol->l_exp->candidate_datatypes.size() > 0) && |
1127 (symbol->r_exp->candidate_datatypes.size() > 0)) |
1152 (symbol->r_exp->candidate_datatypes.size() > 0)) |
1128 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '-' expression."); |
1153 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '-' expression."); |
|
1154 check_used_operation_status(symbol, symbol->l_exp->datatype,symbol->r_exp->datatype, widen_SUB_table); |
1129 return NULL; |
1155 return NULL; |
1130 } |
1156 } |
1131 |
1157 |
1132 void *print_datatypes_error_c::visit(mul_expression_c *symbol) { |
1158 void *print_datatypes_error_c::visit(mul_expression_c *symbol) { |
1133 symbol->l_exp->accept(*this); |
1159 symbol->l_exp->accept(*this); |
1134 symbol->r_exp->accept(*this); |
1160 symbol->r_exp->accept(*this); |
1135 if ((symbol->candidate_datatypes.size() == 0) && |
1161 if ((symbol->candidate_datatypes.size() == 0) && |
1136 (symbol->l_exp->candidate_datatypes.size() > 0) && |
1162 (symbol->l_exp->candidate_datatypes.size() > 0) && |
1137 (symbol->r_exp->candidate_datatypes.size() > 0)) |
1163 (symbol->r_exp->candidate_datatypes.size() > 0)) |
1138 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '*' expression."); |
1164 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '*' expression."); |
|
1165 check_used_operation_status(symbol, symbol->l_exp->datatype,symbol->r_exp->datatype, widen_MUL_table); |
1139 return NULL; |
1166 return NULL; |
1140 } |
1167 } |
1141 |
1168 |
1142 void *print_datatypes_error_c::visit(div_expression_c *symbol) { |
1169 void *print_datatypes_error_c::visit(div_expression_c *symbol) { |
1143 symbol->l_exp->accept(*this); |
1170 symbol->l_exp->accept(*this); |
1144 symbol->r_exp->accept(*this); |
1171 symbol->r_exp->accept(*this); |
1145 if ((symbol->candidate_datatypes.size() == 0) && |
1172 if ((symbol->candidate_datatypes.size() == 0) && |
1146 (symbol->l_exp->candidate_datatypes.size() > 0) && |
1173 (symbol->l_exp->candidate_datatypes.size() > 0) && |
1147 (symbol->r_exp->candidate_datatypes.size() > 0)) |
1174 (symbol->r_exp->candidate_datatypes.size() > 0)) |
1148 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '/' expression."); |
1175 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '/' expression."); |
|
1176 check_used_operation_status(symbol, symbol->l_exp->datatype,symbol->r_exp->datatype, widen_DIV_table); |
1149 return NULL; |
1177 return NULL; |
1150 } |
1178 } |
1151 |
1179 |
1152 |
1180 |
1153 void *print_datatypes_error_c::visit(mod_expression_c *symbol) { |
1181 void *print_datatypes_error_c::visit(mod_expression_c *symbol) { |