26 #define _HELPER_FUNCTIONS_HH_ |
26 #define _HELPER_FUNCTIONS_HH_ |
27 |
27 |
28 #include "../absyntax/visitor.hh" |
28 #include "../absyntax/visitor.hh" |
29 #include <typeinfo> |
29 #include <typeinfo> |
30 |
30 |
|
31 |
|
32 |
|
33 #define is_type(type_name_symbol, type_name_class) ((type_name_symbol == NULL) ? false : (typeid(*type_name_symbol) == typeid(type_name_class))) |
|
34 #define sizeoftype(symbol) get_sizeof_datatype_c::getsize(symbol) |
31 |
35 |
32 |
36 |
33 |
37 |
34 /* A small helper class, to transform elementary data type to string. |
38 /* A small helper class, to transform elementary data type to string. |
35 * this allows us to generate more relevant error messages... |
39 * this allows us to generate more relevant error messages... |
93 void *visit(safelword_type_name_c *symbol) {return (void *)"SAFELWORD"; }; |
97 void *visit(safelword_type_name_c *symbol) {return (void *)"SAFELWORD"; }; |
94 void *visit(safedword_type_name_c *symbol) {return (void *)"SAFEDWORD"; }; |
98 void *visit(safedword_type_name_c *symbol) {return (void *)"SAFEDWORD"; }; |
95 void *visit(safestring_type_name_c *symbol) {return (void *)"SAFESTRING"; }; |
99 void *visit(safestring_type_name_c *symbol) {return (void *)"SAFESTRING"; }; |
96 void *visit(safewstring_type_name_c *symbol) {return (void *)"SAFEWSTRING"; }; |
100 void *visit(safewstring_type_name_c *symbol) {return (void *)"SAFEWSTRING"; }; |
97 }; |
101 }; |
98 extern elementary_type_c *elementary_type; |
|
99 |
102 |
100 |
103 |
101 |
104 |
102 |
105 |
103 |
106 |
104 #define is_type(type_name_symbol, type_name_class) ((type_name_symbol == NULL) ? false : (typeid(*type_name_symbol) == typeid(type_name_class))) |
|
105 #define sizeoftype(symbol) get_sizeof_datatype_c::getsize(symbol) |
|
106 |
107 |
107 /* Widening Primitive Conversion */ |
108 /* Widening Primitive Conversion */ |
108 struct widen_entry { |
109 struct widen_entry { |
109 symbol_c *left; |
110 symbol_c *left; |
110 symbol_c *right; |
111 symbol_c *right; |
171 |
172 |
172 bool is_BOOL_type (symbol_c *type_symbol); |
173 bool is_BOOL_type (symbol_c *type_symbol); |
173 bool is_SAFEBOOL_type (symbol_c *type_symbol); |
174 bool is_SAFEBOOL_type (symbol_c *type_symbol); |
174 bool is_ANY_BOOL_compatible (symbol_c *type_symbol); |
175 bool is_ANY_BOOL_compatible (symbol_c *type_symbol); |
175 |
176 |
176 #if 0 |
|
177 bool is_nonneg_literal_integer_type (symbol_c *type_symbol); |
|
178 bool is_literal_integer_type (symbol_c *type_symbol); |
|
179 bool is_literal_real_type (symbol_c *type_symbol); |
|
180 bool is_literal_bool_type (symbol_c *type_symbol); |
|
181 |
|
182 /* Determine the common data type between two data types. |
|
183 * If no common data type found, return NULL. |
|
184 * |
|
185 * If data types are identical, return the first (any would do...). |
|
186 * If any of the data types is a literal, we confirm that |
|
187 * the literal uses less bits than the fixed size data type. |
|
188 * e.g. BYTE and 1024 returns NULL |
|
189 * BYTE and 255 returns BYTE |
|
190 * |
|
191 * If two literals, then return the literal that requires more bits... |
|
192 */ |
|
193 symbol_c *common_type(symbol_c *first_type, symbol_c *second_type); |
|
194 bool is_valid_assignment(symbol_c *var_type, symbol_c *value_type); |
|
195 bool is_compatible_type(symbol_c *first_type, symbol_c *second_type); |
|
196 #endif |
|
197 |
177 |
198 bool is_type_equal(symbol_c *first_type, symbol_c *second_type); |
178 bool is_type_equal(symbol_c *first_type, symbol_c *second_type); |
199 |
179 |
200 // typedef bool (*helper_function_t) (symbol_c *type_symbol); /* a pointer to a function! */ |
180 // typedef bool (*helper_function_t) (symbol_c *type_symbol); /* a pointer to a function! */ |
201 |
181 |
202 |
182 |
203 |
|
204 #endif /* _HELPER_FUNCTIONS_HH_ */ |
183 #endif /* _HELPER_FUNCTIONS_HH_ */ |