74 |
74 |
75 public: |
75 public: |
76 visit_expression_type_c(symbol_c *search_scope); |
76 visit_expression_type_c(symbol_c *search_scope); |
77 virtual ~visit_expression_type_c(void); |
77 virtual ~visit_expression_type_c(void); |
78 |
78 |
|
79 |
|
80 typedef struct { |
|
81 symbol_c *value; |
|
82 symbol_c *type; |
|
83 } value_and_type_t; |
|
84 |
79 /* A helper function... */ |
85 /* A helper function... */ |
80 bool is_ANY_ELEMENTARY_type(symbol_c *type_symbol); |
86 bool is_ANY_ELEMENTARY_type (symbol_c *type_symbol); |
81 bool is_ANY_MAGNITUDE_type(symbol_c *type_symbol); |
87 bool is_ANY_SAFEELEMENTARY_type (symbol_c *type_symbol); |
82 bool is_ANY_DATE_type(symbol_c *type_symbol); |
88 bool is_ANY_ELEMENTARY_compatible (symbol_c *type_symbol); |
83 bool is_ANY_STRING_type(symbol_c *type_symbol); |
89 |
84 bool is_ANY_INT_type(symbol_c *type_symbol); |
90 bool is_ANY_MAGNITUDE_type (symbol_c *type_symbol); |
85 bool is_ANY_REAL_type(symbol_c *type_symbol); |
91 bool is_ANY_SAFEMAGNITUDE_type (symbol_c *type_symbol); |
86 bool is_ANY_NUM_type(symbol_c *type_symbol); |
92 bool is_ANY_MAGNITUDE_compatible (symbol_c *type_symbol); |
87 bool is_ANY_BIT_type(symbol_c *type_symbol); |
93 |
88 bool is_BOOL_type(symbol_c *type_symbol); |
94 bool is_ANY_DATE_type (symbol_c *type_symbol); |
89 |
95 bool is_ANY_SAFEDATE_type (symbol_c *type_symbol); |
90 bool is_literal_integer_type(symbol_c *type_symbol); |
96 bool is_ANY_DATE_compatible (symbol_c *type_symbol); |
91 bool is_literal_real_type(symbol_c *type_symbol); |
97 |
92 bool is_literal_bool_type(symbol_c *type_symbol); |
98 bool is_ANY_STRING_type (symbol_c *type_symbol); |
|
99 bool is_ANY_SAFESTRING_type (symbol_c *type_symbol); |
|
100 bool is_ANY_STRING_compatible (symbol_c *type_symbol); |
|
101 |
|
102 bool is_ANY_INT_type (symbol_c *type_symbol); |
|
103 bool is_ANY_SAFEINT_type (symbol_c *type_symbol); |
|
104 bool is_ANY_INT_compatible (symbol_c *type_symbol); |
|
105 |
|
106 bool is_ANY_REAL_type (symbol_c *type_symbol); |
|
107 bool is_ANY_SAFEREAL_type (symbol_c *type_symbol); |
|
108 bool is_ANY_REAL_compatible (symbol_c *type_symbol); |
|
109 |
|
110 bool is_ANY_NUM_type (symbol_c *type_symbol); |
|
111 bool is_ANY_SAFENUM_type (symbol_c *type_symbol); |
|
112 bool is_ANY_NUM_compatible (symbol_c *type_symbol); |
|
113 |
|
114 bool is_ANY_BIT_type (symbol_c *type_symbol); |
|
115 bool is_ANY_SAFEBIT_type (symbol_c *type_symbol); |
|
116 bool is_ANY_BIT_compatible (symbol_c *type_symbol); |
|
117 |
|
118 bool is_BOOL_type (symbol_c *type_symbol); |
|
119 bool is_SAFEBOOL_type (symbol_c *type_symbol); |
|
120 bool is_ANY_BOOL_compatible (symbol_c *type_symbol); |
|
121 |
|
122 bool is_nonneg_literal_integer_type (symbol_c *type_symbol); |
|
123 bool is_literal_integer_type (symbol_c *type_symbol); |
|
124 bool is_literal_real_type (symbol_c *type_symbol); |
|
125 bool is_literal_bool_type (symbol_c *type_symbol); |
93 |
126 |
94 /* Determine the common data type between two data types. |
127 /* Determine the common data type between two data types. |
95 * If no common data type found, return NULL. |
128 * If no common data type found, return NULL. |
96 * |
129 * |
97 * If data types are identical, return the first (any would do...). |
130 * If data types are identical, return the first (any would do...). |
106 /* Determine the common data type between two data types. |
139 /* Determine the common data type between two data types. |
107 * Unlike the common_type__() function, we stop the compiler with an ERROR |
140 * Unlike the common_type__() function, we stop the compiler with an ERROR |
108 * if no common data type is found. |
141 * if no common data type is found. |
109 */ |
142 */ |
110 symbol_c *common_type(symbol_c *first_type, symbol_c *second_type); |
143 symbol_c *common_type(symbol_c *first_type, symbol_c *second_type); |
111 /* Return TRUE if there is a common data type, otherwise return FALSE */ |
144 /* Return TRUE if the second (value) data type may be assigned to a variable of the first (variable) data type |
|
145 * such as: |
|
146 * var_type value_type |
|
147 * BOOL BYTE#7 -> returns false |
|
148 * INT INT#7 -> returns true |
|
149 * INT 7 -> returns true |
|
150 * REAL 7.89 -> returns true |
|
151 * REAL 7 -> returns true |
|
152 * INT 7.89 -> returns false |
|
153 * SAFEBOOL BOOL#1 -> returns false !!! |
|
154 * etc... |
|
155 * |
|
156 * NOTE: It is assumed that the var_type is the data type of an lvalue |
|
157 */ |
|
158 bool is_valid_assignment(symbol_c *var_type, symbol_c *value_type); |
|
159 |
|
160 /* Return TRUE if there is a common data type, otherwise return FALSE |
|
161 * i.e., return TRUE if both data types may be used simultaneously in an expression |
|
162 * such as: |
|
163 * BOOL#0 AND BYTE#7 -> returns false |
|
164 * 0 AND BYTE#7 -> returns true |
|
165 * INT#10 AND INT#7 -> returns true |
|
166 * INT#10 AND 7 -> returns true |
|
167 * REAL#34.3 AND 7.89 -> returns true |
|
168 * REAL#34.3 AND 7 -> returns true |
|
169 * INT#10 AND 7.89 -> returns false |
|
170 * SAFEBOOL#0 AND BOOL#1 -> returns true !!! |
|
171 * etc... |
|
172 */ |
112 bool is_compatible_type(symbol_c *first_type, symbol_c *second_type); |
173 bool is_compatible_type(symbol_c *first_type, symbol_c *second_type); |
113 |
174 |
114 void compute_input_operatores(symbol_c *symbol, const char *input_operator); |
175 void compute_input_operatores(symbol_c *symbol, const char *input_operator); |
115 void check_formal_parameter(symbol_c *call_param_name, symbol_c *call_param_type, symbol_c *f_decl); |
176 void check_formal_parameter(symbol_c *call_param_name, symbol_c *call_param_type, symbol_c *f_decl); |
116 |
177 |
126 void *compute_standard_function_il(il_function_call_c *symbol, symbol_c *param_data_type); |
187 void *compute_standard_function_il(il_function_call_c *symbol, symbol_c *param_data_type); |
127 |
188 |
128 |
189 |
129 /* A helper function... */ |
190 /* A helper function... */ |
130 typedef bool (visit_expression_type_c::*is_data_type_t)(symbol_c *type_symbol); /* a pointer to a function! */ |
191 typedef bool (visit_expression_type_c::*is_data_type_t)(symbol_c *type_symbol); /* a pointer to a function! */ |
131 symbol_c *compute_boolean_expression(symbol_c *left_exp, symbol_c *right_exp, is_data_type_t is_data_type); |
192 // symbol_c *compute_boolean_expression(symbol_c *left_exp, symbol_c *right_exp, is_data_type_t is_data_type); |
132 symbol_c *compute_numeric_expression(symbol_c *left_exp, symbol_c *right_exp, is_data_type_t is_data_type); |
193 // symbol_c *compute_numeric_expression(symbol_c *left_exp, symbol_c *right_exp, is_data_type_t is_data_type); |
|
194 symbol_c *compute_expression(symbol_c *left_exp, symbol_c *right_exp, is_data_type_t is_data_type); |
133 |
195 |
134 /* a helper function... */ |
196 /* a helper function... */ |
135 symbol_c *base_type(symbol_c *symbol); |
197 symbol_c *base_type(symbol_c *symbol); |
136 |
198 |
137 /* a helper function... */ |
199 /* a helper function... */ |