stage3/visit_expression_type.cc
changeset 257 90782e241346
parent 204 8ffa211b7f9a
child 258 d7d92b2f87e9
equal deleted inserted replaced
204:8ffa211b7f9a 257:90782e241346
    69   il_error = false;
    69   il_error = false;
    70   il_default_variable_type = NULL;
    70   il_default_variable_type = NULL;
    71   symbol->function_block_body->accept(*this);
    71   symbol->function_block_body->accept(*this);
    72   il_default_variable_type = NULL;
    72   il_default_variable_type = NULL;
    73   delete search_varfb_instance_type;
    73   delete search_varfb_instance_type;
       
    74   search_varfb_instance_type = NULL;
    74   return NULL;
    75   return NULL;
    75 }
    76 }
    76 
    77 
    77 void *visit_expression_type_c::visit(function_declaration_c *symbol) {
    78 void *visit_expression_type_c::visit(function_declaration_c *symbol) {
    78   search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
    79   search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
    82   il_error = false;
    83   il_error = false;
    83   il_default_variable_type = NULL;
    84   il_default_variable_type = NULL;
    84   symbol->function_body->accept(*this);
    85   symbol->function_body->accept(*this);
    85   il_default_variable_type = NULL;
    86   il_default_variable_type = NULL;
    86   delete search_varfb_instance_type;
    87   delete search_varfb_instance_type;
       
    88   search_varfb_instance_type = NULL;
    87   return NULL;
    89   return NULL;
    88 }
    90 }
    89 
    91 
    90 void *visit_expression_type_c::visit(function_block_declaration_c *symbol) {
    92 void *visit_expression_type_c::visit(function_block_declaration_c *symbol) {
    91   search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
    93   search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
    95   il_error = false;
    97   il_error = false;
    96   il_default_variable_type = NULL;
    98   il_default_variable_type = NULL;
    97   symbol->fblock_body->accept(*this);
    99   symbol->fblock_body->accept(*this);
    98   il_default_variable_type = NULL;
   100   il_default_variable_type = NULL;
    99   delete search_varfb_instance_type;
   101   delete search_varfb_instance_type;
       
   102   search_varfb_instance_type = NULL;
   100   return NULL;
   103   return NULL;
   101 }
   104 }
   102 
   105 
   103 
   106 
   104 
   107 
   113 
   116 
   114 visit_expression_type_c::~visit_expression_type_c(void) {
   117 visit_expression_type_c::~visit_expression_type_c(void) {
   115 }
   118 }
   116 
   119 
   117 
   120 
       
   121 
       
   122 
       
   123 /* NOTE on data type handling and literals...
       
   124  * ==========================================
       
   125  *
       
   126  * Literals that are explicitly type cast 
       
   127  *   e.g.:   BYTE#42
       
   128  *           INT#65
       
   129  *           TIME#45h23m
       
   130  *               etc...
       
   131  *  are NOT considered literals in the following code.
       
   132  *  Since they are type cast, and their data type is fixed and well known,
       
   133  *  they are treated as a variable of that data type (except when determining lvalues)
       
   134  *  In other words, when calling search_constant_type_c on these constants, it returns
       
   135  *  a xxxxx_type_name_c, and not one of the xxxx_literal_c ! 
       
   136  *
       
   137  *  When the following code handles a literal, it is really a literal of unknown data type.
       
   138  *    e.g.   42, may be considered an int, a byte, a word, etc... 
       
   139  */
       
   140 
   118 /* A helper function... */
   141 /* A helper function... */
   119 bool visit_expression_type_c::is_ANY_ELEMENTARY_type(symbol_c *type_symbol) {
   142 bool visit_expression_type_c::is_ANY_ELEMENTARY_type(symbol_c *type_symbol) {
   120   if (type_symbol == NULL) {ERROR;}
   143   if (type_symbol == NULL) {ERROR;}
   121   return is_ANY_MAGNITUDE_type(type_symbol)
   144   return is_ANY_MAGNITUDE_type(type_symbol)
   122       || is_ANY_BIT_type(type_symbol)
   145       || is_ANY_BIT_type      (type_symbol)
   123       || is_ANY_STRING_type(type_symbol)
   146       || is_ANY_STRING_type   (type_symbol)
   124       || is_ANY_DATE_type(type_symbol);
   147       || is_ANY_DATE_type     (type_symbol);
       
   148 }
       
   149 
       
   150 /* A helper function... */
       
   151 bool visit_expression_type_c::is_ANY_SAFEELEMENTARY_type(symbol_c *type_symbol) {
       
   152   if (type_symbol == NULL) {ERROR;}
       
   153   return is_ANY_SAFEMAGNITUDE_type(type_symbol)
       
   154       || is_ANY_SAFEBIT_type      (type_symbol)
       
   155       || is_ANY_SAFESTRING_type   (type_symbol)
       
   156       || is_ANY_SAFEDATE_type     (type_symbol);
       
   157 }
       
   158 
       
   159 /* A helper function... */
       
   160 bool visit_expression_type_c::is_ANY_ELEMENTARY_compatible(symbol_c *type_symbol) {
       
   161   if (type_symbol == NULL) {ERROR;}
       
   162   /* NOTE: doing 
       
   163    *          return is_ANY_SAFEELEMENTARY_type() || is_ANY_ELEMENTARY_type()
       
   164    *       is incorrect, as the literals would never be considered compatible...
       
   165    */
       
   166   return is_ANY_MAGNITUDE_compatible(type_symbol)
       
   167       || is_ANY_BIT_compatible      (type_symbol)
       
   168       || is_ANY_STRING_compatible   (type_symbol)
       
   169       || is_ANY_DATE_compatible     (type_symbol);
   125 }
   170 }
   126 
   171 
   127 
   172 
   128 /* A helper function... */
   173 /* A helper function... */
   129 bool visit_expression_type_c::is_ANY_MAGNITUDE_type(symbol_c *type_symbol) {
   174 bool visit_expression_type_c::is_ANY_MAGNITUDE_type(symbol_c *type_symbol) {
   130   if (type_symbol == NULL) {ERROR;}
   175   if (type_symbol == NULL) {ERROR;}
   131   if (typeid(*type_symbol) == typeid(time_type_name_c)) {return true;}
   176   if (typeid(*type_symbol) == typeid(time_type_name_c)) {return true;}
   132   return is_ANY_NUM_type(type_symbol);
   177   return is_ANY_NUM_type(type_symbol);
   133 }
   178 }
   134 
   179 
       
   180 /* A helper function... */
       
   181 bool visit_expression_type_c::is_ANY_SAFEMAGNITUDE_type(symbol_c *type_symbol) {
       
   182   if (type_symbol == NULL) {ERROR;}
       
   183   if (typeid(*type_symbol) == typeid(safetime_type_name_c)) {return true;}
       
   184   return is_ANY_SAFENUM_type(type_symbol);
       
   185 }
       
   186 
       
   187 /* A helper function... */
       
   188 bool visit_expression_type_c::is_ANY_MAGNITUDE_compatible(symbol_c *type_symbol) {
       
   189   if (type_symbol == NULL) {ERROR;}
       
   190   if (is_ANY_MAGNITUDE_type    (type_symbol))              {return true;}
       
   191   if (is_ANY_SAFEMAGNITUDE_type(type_symbol))              {return true;}
       
   192 
       
   193   return is_ANY_NUM_compatible(type_symbol);
       
   194 }
   135 
   195 
   136 /* A helper function... */
   196 /* A helper function... */
   137 bool visit_expression_type_c::is_ANY_NUM_type(symbol_c *type_symbol) {
   197 bool visit_expression_type_c::is_ANY_NUM_type(symbol_c *type_symbol) {
   138   if (type_symbol == NULL) {ERROR;}
   198   if (type_symbol == NULL) {ERROR;}
   139   return is_ANY_REAL_type(type_symbol) || is_ANY_INT_type(type_symbol);
   199   if (is_ANY_REAL_type(type_symbol))                       {return true;}
   140 }
   200   if (is_ANY_INT_type(type_symbol))                        {return true;}
   141 
   201   return false;
       
   202 }
       
   203 
       
   204 /* A helper function... */
       
   205 bool visit_expression_type_c::is_ANY_SAFENUM_type(symbol_c *type_symbol) {
       
   206   if (type_symbol == NULL) {ERROR;}
       
   207   return is_ANY_SAFEREAL_type(type_symbol) 
       
   208       || is_ANY_SAFEINT_type (type_symbol);
       
   209 }
       
   210 
       
   211 /* A helper function... */
       
   212 bool visit_expression_type_c::is_ANY_NUM_compatible(symbol_c *type_symbol) {
       
   213   if (type_symbol == NULL) {ERROR;}
       
   214   if (is_ANY_REAL_compatible(type_symbol))                       {return true;}
       
   215   if (is_ANY_INT_compatible(type_symbol))                        {return true;}
       
   216   return false;  
       
   217 }
   142 
   218 
   143 /* A helper function... */
   219 /* A helper function... */
   144 bool visit_expression_type_c::is_ANY_DATE_type(symbol_c *type_symbol) {
   220 bool visit_expression_type_c::is_ANY_DATE_type(symbol_c *type_symbol) {
   145   if (type_symbol == NULL) {ERROR;}
   221   if (type_symbol == NULL) {ERROR;}
   146   if (typeid(*type_symbol) == typeid(date_type_name_c)) {return true;}
   222   if (typeid(*type_symbol) == typeid(date_type_name_c)) {return true;}
   147   if (typeid(*type_symbol) == typeid(tod_type_name_c)) {return true;}
   223   if (typeid(*type_symbol) == typeid(tod_type_name_c))  {return true;}
   148   if (typeid(*type_symbol) == typeid(dt_type_name_c)) {return true;}
   224   if (typeid(*type_symbol) == typeid(dt_type_name_c))   {return true;}
   149   return false;
   225   return false;
   150 }
   226 }
   151 
   227 
       
   228 /* A helper function... */
       
   229 bool visit_expression_type_c::is_ANY_SAFEDATE_type(symbol_c *type_symbol) {
       
   230   if (type_symbol == NULL) {ERROR;}
       
   231   if (typeid(*type_symbol) == typeid(safedate_type_name_c)) {return true;}
       
   232   if (typeid(*type_symbol) == typeid(safetod_type_name_c))  {return true;}
       
   233   if (typeid(*type_symbol) == typeid(safedt_type_name_c))   {return true;}
       
   234   return false;
       
   235 }
       
   236 
       
   237 /* A helper function... */
       
   238 bool visit_expression_type_c::is_ANY_DATE_compatible(symbol_c *type_symbol) {
       
   239   if (type_symbol == NULL) {ERROR;}
       
   240   if (is_ANY_DATE_type    (type_symbol))              {return true;}
       
   241   if (is_ANY_SAFEDATE_type(type_symbol))              {return true;}
       
   242   return false;
       
   243 }
   152 
   244 
   153 /* A helper function... */
   245 /* A helper function... */
   154 bool visit_expression_type_c::is_ANY_STRING_type(symbol_c *type_symbol) {
   246 bool visit_expression_type_c::is_ANY_STRING_type(symbol_c *type_symbol) {
   155   if (type_symbol == NULL) {ERROR;}
   247   if (type_symbol == NULL) {ERROR;}
   156   if (typeid(*type_symbol) == typeid(string_type_name_c)) {return true;}
   248   if (typeid(*type_symbol) == typeid(string_type_name_c)) {return true;}
   157   if (typeid(*type_symbol) == typeid(wstring_type_name_c)) {return true;}
   249   if (typeid(*type_symbol) == typeid(wstring_type_name_c)) {return true;}
       
   250 // TODO literal_string ???
   158   return false;
   251   return false;
   159 }
   252 }
   160 
   253 
       
   254 /* A helper function... */
       
   255 bool visit_expression_type_c::is_ANY_SAFESTRING_type(symbol_c *type_symbol) {
       
   256   if (type_symbol == NULL) {ERROR;}
       
   257   if (typeid(*type_symbol) == typeid(safestring_type_name_c)) {return true;}
       
   258   if (typeid(*type_symbol) == typeid(safewstring_type_name_c)) {return true;}
       
   259   return false;
       
   260 }
       
   261 
       
   262 /* A helper function... */
       
   263 bool visit_expression_type_c::is_ANY_STRING_compatible(symbol_c *type_symbol) {
       
   264   if (type_symbol == NULL) {ERROR;}
       
   265   if (is_ANY_STRING_type    (type_symbol))              {return true;}
       
   266   if (is_ANY_SAFESTRING_type(type_symbol))              {return true;}
       
   267   return false;
       
   268 }
   161 
   269 
   162 /* A helper function... */
   270 /* A helper function... */
   163 bool visit_expression_type_c::is_ANY_INT_type(symbol_c *type_symbol) {
   271 bool visit_expression_type_c::is_ANY_INT_type(symbol_c *type_symbol) {
   164   if (type_symbol == NULL) {ERROR;}
   272   if (type_symbol == NULL) {ERROR;}
   165   if (typeid(*type_symbol) == typeid(sint_type_name_c))  {return true;}
   273   if (typeid(*type_symbol) == typeid(sint_type_name_c))  {return true;}
   168   if (typeid(*type_symbol) == typeid(lint_type_name_c))  {return true;}
   276   if (typeid(*type_symbol) == typeid(lint_type_name_c))  {return true;}
   169   if (typeid(*type_symbol) == typeid(usint_type_name_c)) {return true;}
   277   if (typeid(*type_symbol) == typeid(usint_type_name_c)) {return true;}
   170   if (typeid(*type_symbol) == typeid(uint_type_name_c))  {return true;}
   278   if (typeid(*type_symbol) == typeid(uint_type_name_c))  {return true;}
   171   if (typeid(*type_symbol) == typeid(udint_type_name_c)) {return true;}
   279   if (typeid(*type_symbol) == typeid(udint_type_name_c)) {return true;}
   172   if (typeid(*type_symbol) == typeid(ulint_type_name_c)) {return true;}
   280   if (typeid(*type_symbol) == typeid(ulint_type_name_c)) {return true;}
   173   if (is_literal_integer_type(type_symbol))              {return true;}
       
   174   return false;
   281   return false;
   175 }
   282 }
   176 
   283 
       
   284 /* A helper function... */
       
   285 bool visit_expression_type_c::is_ANY_SAFEINT_type(symbol_c *type_symbol) {
       
   286   if (type_symbol == NULL) {ERROR;}
       
   287   if (typeid(*type_symbol) == typeid(safesint_type_name_c))  {return true;}
       
   288   if (typeid(*type_symbol) == typeid(safeint_type_name_c))   {return true;}
       
   289   if (typeid(*type_symbol) == typeid(safedint_type_name_c))  {return true;}
       
   290   if (typeid(*type_symbol) == typeid(safelint_type_name_c))  {return true;}
       
   291   if (typeid(*type_symbol) == typeid(safeusint_type_name_c)) {return true;}
       
   292   if (typeid(*type_symbol) == typeid(safeuint_type_name_c))  {return true;}
       
   293   if (typeid(*type_symbol) == typeid(safeudint_type_name_c)) {return true;}
       
   294   if (typeid(*type_symbol) == typeid(safeulint_type_name_c)) {return true;}
       
   295   return false;
       
   296 }
       
   297 
       
   298 /* A helper function... */
       
   299 bool visit_expression_type_c::is_ANY_INT_compatible(symbol_c *type_symbol) {
       
   300   if (type_symbol == NULL) {ERROR;}
       
   301   if (is_ANY_INT_type    (type_symbol))              {return true;}
       
   302   if (is_ANY_SAFEINT_type(type_symbol))              {return true;}
       
   303   if (is_literal_integer_type(type_symbol))          {return true;}
       
   304   return false;
       
   305 }
   177 
   306 
   178 /* A helper function... */
   307 /* A helper function... */
   179 bool visit_expression_type_c::is_ANY_REAL_type(symbol_c *type_symbol) {
   308 bool visit_expression_type_c::is_ANY_REAL_type(symbol_c *type_symbol) {
   180   if (type_symbol == NULL) {ERROR;}
   309   if (type_symbol == NULL) {ERROR;}
   181   if (typeid(*type_symbol) == typeid(real_type_name_c))  {return true;}
   310   if (typeid(*type_symbol) == typeid(real_type_name_c))  {return true;}
   182   if (typeid(*type_symbol) == typeid(lreal_type_name_c)) {return true;}
   311   if (typeid(*type_symbol) == typeid(lreal_type_name_c)) {return true;}
   183   if (is_literal_real_type(type_symbol))                 {return true;}
       
   184   return false;
   312   return false;
   185 }
   313 }
   186 
   314 
       
   315 /* A helper function... */
       
   316 bool visit_expression_type_c::is_ANY_SAFEREAL_type(symbol_c *type_symbol) {
       
   317   if (type_symbol == NULL) {ERROR;}
       
   318   if (typeid(*type_symbol) == typeid(safereal_type_name_c))  {return true;}
       
   319   if (typeid(*type_symbol) == typeid(safelreal_type_name_c)) {return true;}
       
   320   return false;
       
   321 }
       
   322 
       
   323 /* A helper function... */
       
   324 bool visit_expression_type_c::is_ANY_REAL_compatible(symbol_c *type_symbol) {
       
   325   if (type_symbol == NULL) {ERROR;}
       
   326   if (is_ANY_REAL_type    (type_symbol))              {return true;}
       
   327   if (is_ANY_SAFEREAL_type(type_symbol))              {return true;}
       
   328   if (is_literal_real_type(type_symbol))              {return true;}
       
   329   return false;
       
   330 }
   187 
   331 
   188 /* A helper function... */
   332 /* A helper function... */
   189 bool visit_expression_type_c::is_ANY_BIT_type(symbol_c *type_symbol) {
   333 bool visit_expression_type_c::is_ANY_BIT_type(symbol_c *type_symbol) {
   190   if (type_symbol == NULL) {ERROR;}
   334   if (type_symbol == NULL) {ERROR;}
   191   if (typeid(*type_symbol) == typeid(bool_type_name_c))  {return true;}
   335   if (typeid(*type_symbol) == typeid(bool_type_name_c))     {return true;}
   192   if (typeid(*type_symbol) == typeid(byte_type_name_c))  {return true;}
   336   if (typeid(*type_symbol) == typeid(byte_type_name_c))     {return true;}
   193   if (typeid(*type_symbol) == typeid(word_type_name_c))  {return true;}
   337   if (typeid(*type_symbol) == typeid(word_type_name_c))     {return true;}
   194   if (typeid(*type_symbol) == typeid(dword_type_name_c)) {return true;}
   338   if (typeid(*type_symbol) == typeid(dword_type_name_c))    {return true;}
   195   if (typeid(*type_symbol) == typeid(lword_type_name_c)) {return true;}
   339   if (typeid(*type_symbol) == typeid(lword_type_name_c))    {return true;}
   196   if (is_literal_integer_type(type_symbol))              {return true;}
       
   197   return false;
   340   return false;
   198 }
   341 }
   199 
   342 
       
   343 /* A helper function... */
       
   344 bool visit_expression_type_c::is_ANY_SAFEBIT_type(symbol_c *type_symbol) {
       
   345   if (type_symbol == NULL) {ERROR;}
       
   346   if (typeid(*type_symbol) == typeid(safebool_type_name_c))     {return true;}
       
   347   if (typeid(*type_symbol) == typeid(safebyte_type_name_c))     {return true;}
       
   348   if (typeid(*type_symbol) == typeid(safeword_type_name_c))     {return true;}
       
   349   if (typeid(*type_symbol) == typeid(safedword_type_name_c))    {return true;}
       
   350   if (typeid(*type_symbol) == typeid(safelword_type_name_c))    {return true;}
       
   351   return false;
       
   352 }
       
   353 
       
   354 /* A helper function... */
       
   355 bool visit_expression_type_c::is_ANY_BIT_compatible(symbol_c *type_symbol) {
       
   356   if (type_symbol == NULL) {ERROR;}
       
   357   if (is_ANY_BIT_type    (type_symbol))              {return true;}
       
   358   if (is_ANY_SAFEBIT_type(type_symbol))              {return true;}
       
   359   if (is_nonneg_literal_integer_type(type_symbol))   {return true;}
       
   360   if (is_literal_bool_type(type_symbol))             {return true;}
       
   361   return false;
       
   362 }
   200 
   363 
   201 /* A helper function... */
   364 /* A helper function... */
   202 bool visit_expression_type_c::is_BOOL_type(symbol_c *type_symbol) {
   365 bool visit_expression_type_c::is_BOOL_type(symbol_c *type_symbol) {
   203   if (type_symbol == NULL) {ERROR;}
   366   if (type_symbol == NULL) {ERROR;}
   204   if (typeid(*type_symbol) == typeid(bool_type_name_c))  {return true;}
   367   if (typeid(*type_symbol) == typeid(bool_type_name_c))      {return true;}
   205   if (is_literal_bool_type(type_symbol))                 {return true;}
       
   206   return false;
   368   return false;
   207 }
   369 }
   208 
   370 
       
   371 /* A helper function... */
       
   372 bool visit_expression_type_c::is_SAFEBOOL_type(symbol_c *type_symbol){
       
   373   if (type_symbol == NULL) {ERROR;}
       
   374   if (typeid(*type_symbol) == typeid(safebool_type_name_c))  {return true;}
       
   375   return false;  
       
   376 }
       
   377 
       
   378 /* A helper function... */
       
   379 bool visit_expression_type_c::is_ANY_BOOL_compatible(symbol_c *type_symbol) {
       
   380   if (type_symbol == NULL) {ERROR;}
       
   381   if (is_BOOL_type    (type_symbol))              {return true;}
       
   382   if (is_SAFEBOOL_type(type_symbol))              {return true;}
       
   383   if (is_literal_bool_type(type_symbol))              {return true;}
       
   384   return false;
       
   385 }
       
   386 
       
   387 
       
   388 #define is_type(type_name_symbol, type_name_class)  (typeid(*type_name_symbol) == typeid(type_name_class))
       
   389 
   209 
   390 
   210 #define sizeoftype(symbol) get_sizeof_datatype_c::getsize(symbol)
   391 #define sizeoftype(symbol) get_sizeof_datatype_c::getsize(symbol)
   211 
   392 
   212 
   393 
   213 /* A helper function... */
   394 /* A helper function... */
   214 bool visit_expression_type_c::is_literal_integer_type(symbol_c *type_symbol) {
   395 bool visit_expression_type_c::is_literal_integer_type(symbol_c *type_symbol) {
   215   if (type_symbol == NULL) {return true;}
   396   if (type_symbol == NULL) {ERROR;}
       
   397   if (typeid(*type_symbol) == typeid(neg_integer_c))        {return true;}
       
   398   return is_nonneg_literal_integer_type(type_symbol);
       
   399 }
       
   400 
       
   401 
       
   402 /* A helper function... */
       
   403 bool visit_expression_type_c::is_nonneg_literal_integer_type(symbol_c *type_symbol) {
       
   404   if (type_symbol == NULL) {ERROR;}
   216   if (typeid(*type_symbol) == typeid(integer_c))        {return true;}
   405   if (typeid(*type_symbol) == typeid(integer_c))        {return true;}
   217   if (typeid(*type_symbol) == typeid(binary_integer_c)) {return true;}
   406   if (typeid(*type_symbol) == typeid(binary_integer_c)) {return true;}
   218   if (typeid(*type_symbol) == typeid(octal_integer_c))  {return true;}
   407   if (typeid(*type_symbol) == typeid(octal_integer_c))  {return true;}
   219   if (typeid(*type_symbol) == typeid(hex_integer_c))    {return true;}
   408   if (typeid(*type_symbol) == typeid(hex_integer_c))    {return true;}
   220   return false;
   409   return false;
   221 }
   410 }
   222 
   411 
   223 
   412 
   224 /* A helper function... */
   413 /* A helper function... */
   225 bool visit_expression_type_c::is_literal_real_type(symbol_c *type_symbol) {
   414 bool visit_expression_type_c::is_literal_real_type(symbol_c *type_symbol) {
   226   if (type_symbol == NULL) {return true;}
   415   if (type_symbol == NULL) {ERROR;}
   227   if (typeid(*type_symbol) == typeid(real_c)) {return true;}
   416   if (typeid(*type_symbol) == typeid(real_c))     {return true;}
       
   417   if (typeid(*type_symbol) == typeid(neg_real_c)) {return true;}
   228   return false;
   418   return false;
   229 }
   419 }
   230 
   420 
   231 
   421 
   232 /* A helper function... */
   422 /* A helper function... */
   233 bool visit_expression_type_c::is_literal_bool_type(symbol_c *type_symbol) {
   423 bool visit_expression_type_c::is_literal_bool_type(symbol_c *type_symbol) {
   234   bool_type_name_c bool_t;
   424   bool_type_name_c bool_t;
   235 
   425 
   236   if (type_symbol == NULL) {return true;}
   426   if (type_symbol == NULL) {ERROR;}
   237   if (typeid(*type_symbol) == typeid(boolean_true_c))    {return true;}
   427   if (typeid(*type_symbol) == typeid(boolean_true_c))    {return true;}
   238   if (typeid(*type_symbol) == typeid(boolean_false_c))   {return true;}
   428   if (typeid(*type_symbol) == typeid(boolean_false_c))   {return true;}
   239   if (is_literal_integer_type(type_symbol))
   429   if (is_nonneg_literal_integer_type(type_symbol))
   240     if (sizeoftype(&bool_t) >= sizeoftype(type_symbol))  {return true;}
   430     if (sizeoftype(&bool_t) >= sizeoftype(type_symbol))  {return true;}
   241   return false;
   431   return false;
   242 }
   432 }
   243 
       
   244 
   433 
   245 /* Determine the common data type between two data types.
   434 /* Determine the common data type between two data types.
   246  * If no common data type found, return NULL.
   435  * If no common data type found, return NULL.
   247  *
   436  *
   248  * If data types are identical, return the first (actually any would do...).
   437  * If data types are identical, return the first (actually any would do...).
   251  *   e.g. BYTE and 1024 returns NULL
   440  *   e.g. BYTE and 1024 returns NULL
   252  *        BYTE and 255  returns BYTE
   441  *        BYTE and 255  returns BYTE
   253  *
   442  *
   254  * If two literals, then return the literal that requires more bits...
   443  * If two literals, then return the literal that requires more bits...
   255  */
   444  */
       
   445 
   256 symbol_c *visit_expression_type_c::common_type__(symbol_c *first_type, symbol_c *second_type) {
   446 symbol_c *visit_expression_type_c::common_type__(symbol_c *first_type, symbol_c *second_type) {
   257   if (first_type == NULL && second_type == NULL) {ERROR;}
   447   if (first_type == NULL && second_type == NULL) {ERROR;}
   258   if (first_type == NULL)  {return second_type;}
   448   if (first_type == NULL)  {return second_type;}
   259   if (second_type == NULL) {return first_type;}
   449   if (second_type == NULL) {return first_type;}
   260 
   450 
   265     {return ((sizeoftype(first_type) > sizeoftype(second_type))? first_type:second_type);}
   455     {return ((sizeoftype(first_type) > sizeoftype(second_type))? first_type:second_type);}
   266 
   456 
   267   if (is_literal_bool_type(first_type) && is_literal_bool_type(second_type))
   457   if (is_literal_bool_type(first_type) && is_literal_bool_type(second_type))
   268     {return first_type;}
   458     {return first_type;}
   269 
   459 
   270   /* This check can only be made after the is_literal_XXXX checks */
   460   /* The following check can only be made after the is_literal_XXXX checks */
   271   /* When two literals of the same type, with identical typeid's are checked,
   461   /* When two literals of the same type, with identical typeid's are checked,
   272    * we must return the one that occupies more bits...
   462    * we must return the one that occupies more bits... This is done above.
   273    */
   463    */
   274   if (typeid(*first_type) == typeid(*second_type)) {return first_type;}
   464   if (typeid(*first_type) == typeid(*second_type)) {return first_type;}
   275 
   465 
   276   if (is_BOOL_type(first_type)      && is_literal_bool_type(second_type))     {return first_type;}
   466   /* NOTE Although a BOOL is also an ANY_BIT, we must check it explicitly since some
   277   if (is_BOOL_type(second_type)     && is_literal_bool_type(first_type))      {return second_type;}
   467    *       literal bool values are not literal integers...
   278 
   468    */ 
   279   if (is_ANY_BIT_type(first_type)     && is_literal_integer_type(second_type))
   469   if (is_BOOL_type(first_type)        && is_literal_bool_type(second_type))    {return first_type;}
       
   470   if (is_BOOL_type(second_type)       && is_literal_bool_type(first_type))     {return second_type;}
       
   471 
       
   472   if (is_SAFEBOOL_type(first_type)    && is_literal_bool_type(second_type))    {return first_type;}
       
   473   if (is_SAFEBOOL_type(second_type)   && is_literal_bool_type(first_type))     {return second_type;}
       
   474 
       
   475   if (is_SAFEBOOL_type(first_type)    && is_BOOL_type(second_type))            {return second_type;}
       
   476   if (is_SAFEBOOL_type(second_type)   && is_BOOL_type(first_type))             {return first_type;}
       
   477 
       
   478   if (is_ANY_BIT_type(first_type)     && is_nonneg_literal_integer_type(second_type))
   280     {return ((sizeoftype(first_type)  >= sizeoftype(second_type))? first_type :NULL);}
   479     {return ((sizeoftype(first_type)  >= sizeoftype(second_type))? first_type :NULL);}
   281   if (is_ANY_BIT_type(second_type)    && is_literal_integer_type(first_type))
   480   if (is_ANY_BIT_type(second_type)    && is_nonneg_literal_integer_type(first_type))
   282     {return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
   481     {return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
   283 
   482 
   284   if (is_ANY_INT_type(first_type)   && is_literal_integer_type(second_type))
   483   if (is_ANY_SAFEBIT_type(first_type)     && is_nonneg_literal_integer_type(second_type))
   285     {return ((sizeoftype(first_type)  >= sizeoftype(second_type))? first_type :NULL);}
   484     {return ((sizeoftype(first_type)  >= sizeoftype(second_type))? first_type :NULL);}
   286   if (is_ANY_INT_type(second_type)  && is_literal_integer_type(first_type))
   485   if (is_ANY_SAFEBIT_type(second_type)    && is_nonneg_literal_integer_type(first_type))
   287     {return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
   486     {return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
   288 
   487 
   289   if (is_ANY_REAL_type(first_type)  && is_literal_real_type(second_type))
   488   if  (is_ANY_SAFEBIT_type(first_type)    && is_ANY_BIT_type(second_type))
       
   489     {return ((sizeoftype(first_type) == sizeoftype(second_type))? second_type:NULL);}
       
   490   if  (is_ANY_SAFEBIT_type(second_type)   && is_ANY_BIT_type(first_type))
       
   491     {return ((sizeoftype(first_type) == sizeoftype(second_type))? first_type :NULL);}
       
   492 
       
   493   if (is_ANY_INT_type(first_type)     && is_literal_integer_type(second_type))
   290     {return ((sizeoftype(first_type)  >= sizeoftype(second_type))? first_type :NULL);}
   494     {return ((sizeoftype(first_type)  >= sizeoftype(second_type))? first_type :NULL);}
   291   if (is_ANY_REAL_type(second_type) && is_literal_real_type(first_type))
   495   if (is_ANY_INT_type(second_type)    && is_literal_integer_type(first_type))
   292     {return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
   496     {return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
       
   497 
       
   498   if (is_ANY_SAFEINT_type(first_type)     && is_literal_integer_type(second_type))
       
   499     {return ((sizeoftype(first_type)  >= sizeoftype(second_type))? first_type :NULL);}
       
   500   if (is_ANY_SAFEINT_type(second_type)    && is_literal_integer_type(first_type))
       
   501     {return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
       
   502 
       
   503   if  (is_ANY_SAFEINT_type(first_type)    && is_ANY_INT_type(second_type))
       
   504     {return ((sizeoftype(first_type) == sizeoftype(second_type))? second_type:NULL);}
       
   505   if  (is_ANY_SAFEINT_type(second_type)   && is_ANY_INT_type(first_type))
       
   506     {return ((sizeoftype(first_type) == sizeoftype(second_type))? first_type :NULL);}
       
   507 
       
   508   if (is_ANY_REAL_type(first_type)    && is_literal_real_type(second_type))
       
   509     {return ((sizeoftype(first_type)  >= sizeoftype(second_type))? first_type :NULL);}
       
   510   if (is_ANY_REAL_type(second_type)   && is_literal_real_type(first_type))
       
   511     {return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
       
   512 
       
   513   if (is_ANY_SAFEREAL_type(first_type)    && is_literal_real_type(second_type))
       
   514     {return ((sizeoftype(first_type)  >= sizeoftype(second_type))? first_type :NULL);}
       
   515   if (is_ANY_SAFEREAL_type(second_type)   && is_literal_real_type(first_type))
       
   516     {return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
       
   517 
       
   518   if  (is_ANY_SAFEREAL_type(first_type)    && is_ANY_REAL_type(second_type))
       
   519     {return ((sizeoftype(first_type) == sizeoftype(second_type))? second_type:NULL);}
       
   520   if  (is_ANY_SAFEREAL_type(second_type)   && is_ANY_REAL_type(first_type))
       
   521     {return ((sizeoftype(first_type) == sizeoftype(second_type))? first_type :NULL);}
       
   522 
       
   523   /* the Time and Date types... */
       
   524   if (is_type(first_type,  safetime_type_name_c) && is_type(second_type, time_type_name_c))  {return second_type;}
       
   525   if (is_type(second_type, safetime_type_name_c) && is_type( first_type, time_type_name_c))  {return  first_type;}
       
   526 
       
   527   if (is_type(first_type,  safedate_type_name_c) && is_type(second_type, date_type_name_c))  {return second_type;}
       
   528   if (is_type(second_type, safedate_type_name_c) && is_type( first_type, date_type_name_c))  {return  first_type;}
       
   529 
       
   530   if (is_type(first_type,  safedt_type_name_c)   && is_type(second_type, dt_type_name_c))    {return second_type;}
       
   531   if (is_type(second_type, safedt_type_name_c)   && is_type( first_type, dt_type_name_c))    {return  first_type;}
       
   532 
       
   533   if (is_type(first_type,  safetod_type_name_c)  && is_type(second_type, tod_type_name_c))   {return second_type;}
       
   534   if (is_type(second_type, safetod_type_name_c)  && is_type( first_type, tod_type_name_c))   {return  first_type;}
   293 
   535 
   294   /* no common type */
   536   /* no common type */
   295   return NULL;
   537   return NULL;
   296 }
   538 }
   297 
   539 
   304   if (NULL == res) ERROR;
   546   if (NULL == res) ERROR;
   305   return res;
   547   return res;
   306 }
   548 }
   307 
   549 
   308 
   550 
       
   551 /* Return TRUE if the second (value) data type may be assigned to a variable of the first (variable) data type
       
   552  * such as: 
       
   553  *     var_type     value_type
       
   554  *    BOOL           BYTE#7     -> returns false
       
   555  *    INT            INT#7      -> returns true
       
   556  *    INT            7          -> returns true
       
   557  *    REAL           7.89       -> returns true
       
   558  *    REAL           7          -> returns true
       
   559  *    INT            7.89       -> returns false
       
   560  *    SAFEBOOL       BOOL#1     -> returns false   !!!
       
   561  *   etc...
       
   562  *
       
   563  * NOTE: It is assumed that the var_type is the data type of an lvalue
       
   564  */
       
   565 bool visit_expression_type_c::is_valid_assignment(symbol_c *var_type, symbol_c *value_type) {
       
   566   if (var_type == NULL)   {/* STAGE3_ERROR(value_type, value_type, "Var_type   == NULL"); */ ERROR;}
       
   567   if (value_type == NULL) {/* STAGE3_ERROR(var_type,   var_type,   "Value_type == NULL"); */ ERROR;}
       
   568   if (var_type == NULL || value_type == NULL) {ERROR;}
       
   569 
       
   570   symbol_c *common_type = common_type__(var_type, value_type);
       
   571   if (NULL == common_type)
       
   572     return false;
       
   573   return (typeid(*var_type) == typeid(*common_type));
       
   574 }
       
   575 
       
   576 
   309 /* Return TRUE if there is a common data type, otherwise return FALSE
   577 /* Return TRUE if there is a common data type, otherwise return FALSE
       
   578  * i.e., return TRUE if both data types may be used simultaneously in an expression
       
   579  * such as:
       
   580  *    BOOL#0     AND BYTE#7  -> returns false
       
   581  *    0          AND BYTE#7  -> returns true
       
   582  *    INT#10     AND INT#7   -> returns true
       
   583  *    INT#10     AND 7       -> returns true
       
   584  *    REAL#34.3  AND 7.89    -> returns true
       
   585  *    REAL#34.3  AND 7       -> returns true
       
   586  *    INT#10     AND 7.89    -> returns false
       
   587  *    SAFEBOOL#0 AND BOOL#1  -> returns true   !!!
       
   588  *   etc...
   310  */
   589  */
   311 bool visit_expression_type_c::is_compatible_type(symbol_c *first_type, symbol_c *second_type) {
   590 bool visit_expression_type_c::is_compatible_type(symbol_c *first_type, symbol_c *second_type) {
   312   if (first_type == NULL || second_type == NULL) {ERROR;}
   591   if (first_type == NULL || second_type == NULL) {ERROR;}
   313   return (NULL != common_type__(first_type, second_type));
   592   return (NULL != common_type__(first_type, second_type));
   314 }
   593 }
   315 
   594 
   316 
   595 
   317 
   596 
   318 #define is_num_type      is_ANY_NUM_type
   597 #define is_num_type      is_ANY_NUM_compatible
   319 #define is_integer_type  is_ANY_INT_type
   598 #define is_integer_type  is_ANY_INT_compatible
   320 #define is_real_type     is_ANY_REAL_type
   599 #define is_real_type     is_ANY_REAL_compatible
   321 #define is_binary_type   is_ANY_BIT_type
   600 #define is_binary_type   is_ANY_BIT_compatible
   322  /* actually the ROR, ROL, SHL, and SHR function also accept boolean type! */
   601  /* actually the ROR, ROL, SHL, and SHR function also accept boolean type! */
   323 #define is_nbinary_type  is_ANY_BIT_type  
   602 #define is_nbinary_type  is_ANY_BIT_compatible
   324 #define compute_standard_function_default visit_expression_type_c::compute_standard_function_default
   603 #define compute_standard_function_default visit_expression_type_c::compute_standard_function_default
   325 #define compute_standard_function_il visit_expression_type_c::compute_standard_function_il
   604 #define compute_standard_function_il visit_expression_type_c::compute_standard_function_il
   326 #define search_expression_type_c visit_expression_type_c
   605 #define search_expression_type_c visit_expression_type_c
   327 #define search(x) search_f(x)
   606 #define search(x) search_f(x)
   328 #define next() next_nf()
   607 #define next() next_nf()
   348 
   627 
   349 
   628 
   350 
   629 
   351 
   630 
   352 /* A helper function... */
   631 /* A helper function... */
       
   632 /*
   353 symbol_c *visit_expression_type_c::compute_boolean_expression(symbol_c *left_type, symbol_c *right_type,
   633 symbol_c *visit_expression_type_c::compute_boolean_expression(symbol_c *left_type, symbol_c *right_type,
   354                                                               is_data_type_t is_data_type) {
   634                                                               is_data_type_t is_data_type) {
       
   635 */
       
   636 symbol_c *visit_expression_type_c::compute_expression(symbol_c *left_type, symbol_c *right_type,
       
   637                                                       is_data_type_t is_data_type) {
   355   bool error = false;
   638   bool error = false;
   356 
   639 
   357   if (!(this->*is_data_type)(left_type)) {
   640   if (!(this->*is_data_type)(left_type)) {
   358     STAGE3_ERROR(left_type, left_type, "invalid data type of first operand.");
   641     STAGE3_ERROR(left_type, left_type, "Invalid data type of left operand.");
   359     error = true;
   642     error = true;
   360   }
   643   }
   361   if (!(this->*is_data_type)(right_type)) {
   644   if (!(this->*is_data_type)(right_type)) {
   362     STAGE3_ERROR(right_type, right_type, "invalid data type of second operand.");
   645     STAGE3_ERROR(right_type, right_type, "Invalid data type of right operand.");
   363     error = true;
   646     error = true;
   364   }
   647   }
   365   if (!is_compatible_type(left_type, right_type)) {
   648   if (!is_compatible_type(left_type, right_type)) {
   366     STAGE3_ERROR(left_type, right_type, "type mismatch between operands.");
   649     STAGE3_ERROR(left_type, right_type, "Type mismatch between operands.");
   367     error = true;
   650     error = true;
   368   }
   651   }
   369 
   652 
   370   if (error)
   653   if (error)
   371     return NULL;
   654     return NULL;
   372   else
   655   else
   373     return common_type(left_type, right_type);
   656     return common_type(left_type, right_type);
   374 }
   657 }
   375 
   658 
   376 
   659 
       
   660 # if 0
   377 /* A helper function... */
   661 /* A helper function... */
   378 symbol_c *visit_expression_type_c::compute_numeric_expression(symbol_c *left_type, symbol_c *right_type,
   662 symbol_c *visit_expression_type_c::compute_numeric_expression(symbol_c *left_type, symbol_c *right_type,
   379                                                               is_data_type_t is_data_type) {
   663                                                               is_data_type_t is_data_type) {
   380   if (!(this->*is_data_type)(left_type))
   664   bool error = false;
   381     STAGE3_ERROR(left_type, right_type, "Both parts of the equation must be the same type.");
   665 
   382   if (!(this->*is_data_type)(right_type))
   666   if (!(this->*is_data_type)(left_type)) {
   383     STAGE3_ERROR(left_type, right_type, "Both parts of the equation must be the same type.");
   667     STAGE3_ERROR(left_type, right_type, "Invalid data type of left operand.");
   384   if (!is_compatible_type(left_type, right_type))
   668     error = true;
   385     STAGE3_ERROR(left_type, right_type, "Both parts of the equation must be the same type.");
   669   }
   386 
   670   if (!(this->*is_data_type)(right_type)) {
       
   671     STAGE3_ERROR(left_type, right_type, "Invalid data type of right operand.");
       
   672     error = true;
       
   673   }
       
   674   if (!is_compatible_type(left_type, right_type)) {
       
   675     STAGE3_ERROR(left_type, right_type, "Type mismatch between operands.");
       
   676     error = true;
       
   677   }
       
   678 
       
   679 /*
   387   if (is_literal_integer_type(left_type) || is_literal_real_type(left_type)) {
   680   if (is_literal_integer_type(left_type) || is_literal_real_type(left_type)) {
   388     return right_type;
   681     return right_type;
   389   } else {
   682   } else {
   390     return left_type;
   683     return left_type;
   391   }
   684   }
       
   685 */
       
   686 
       
   687   if (error)
       
   688     return NULL;
       
   689   else
       
   690     return common_type(left_type, right_type);
   392 
   691 
   393   /* humour the compiler... */
   692   /* humour the compiler... */
   394   return NULL;
   693 /*
   395 }
   694   return NULL;
   396 
   695 */
       
   696 }
       
   697 #endif
   397 
   698 
   398 
   699 
   399 
   700 
   400 
   701 
   401 
   702 
   423     /* If the function does not have any parameters (param_name == NULL)
   724     /* If the function does not have any parameters (param_name == NULL)
   424      * then we cannot compare its type with the il_default_variable_type.
   725      * then we cannot compare its type with the il_default_variable_type.
   425      */
   726      */
   426     if(param_name != NULL) {
   727     if(param_name != NULL) {
   427       param_type = fp_iterator.param_type();
   728       param_type = fp_iterator.param_type();
   428       if(!is_compatible_type(il_default_variable_type,param_type)) 
   729       if(!is_valid_assignment(param_type, il_default_variable_type)) 
   429         STAGE3_ERROR(f_call, f_call, "In function/FB call, first parameter has invalid data type.");
   730         STAGE3_ERROR(f_call, f_call, "In function/FB call, first parameter has invalid data type.");
   430     }
   731     }
   431   } // if (use_il_defvar)
   732   } // if (use_il_defvar)
   432 
   733 
   433   /* Iterating through the non-formal parameters of the function call */
   734   /* Iterating through the non-formal parameters of the function call */
   447 
   748 
   448     if(param_name != NULL) {
   749     if(param_name != NULL) {
   449       /* Get the parameter type */
   750       /* Get the parameter type */
   450       param_type = fp_iterator.param_type();
   751       param_type = fp_iterator.param_type();
   451       /* If the declared parameter and the parameter from the function call do no have the same type */
   752       /* If the declared parameter and the parameter from the function call do no have the same type */
   452       if(!is_compatible_type(call_param_type,param_type)) STAGE3_ERROR(call_param_value, call_param_value, "Type mismatch in function/FB call parameter.");
   753       if(!is_valid_assignment(param_type, call_param_type)) STAGE3_ERROR(call_param_value, call_param_value, "Type mismatch in function/FB call parameter.");
   453     }
   754     }
   454   }
   755   }
   455 }
   756 }
   456 
   757 
   457 void visit_expression_type_c::compute_input_operatores(symbol_c *symbol, const char *input_operator){
   758 void visit_expression_type_c::compute_input_operatores(symbol_c *symbol, const char *input_operator){
   497     STAGE3_ERROR(call_param_name, call_param_name, "Invalid parameter in function/FB call.");
   798     STAGE3_ERROR(call_param_name, call_param_name, "Invalid parameter in function/FB call.");
   498   } else {
   799   } else {
   499     /* Get the parameter type */
   800     /* Get the parameter type */
   500     param_type = fp_iterator.param_type();
   801     param_type = fp_iterator.param_type();
   501     /* If the declared parameter and the parameter from the function call have the same type */
   802     /* If the declared parameter and the parameter from the function call have the same type */
   502 //     if(!is_compatible_type(call_param_type, param_type)) STAGE3_ERROR(call_param_name, call_param_value, "Type mismatch function/FB call parameter.");
   803     if(!is_valid_assignment(param_type, call_param_type)) STAGE3_ERROR(call_param_name, call_param_name, "Type mismatch function/FB call parameter.");
   503     if(!is_compatible_type(call_param_type, param_type)) STAGE3_ERROR(call_param_name, call_param_name, "Type mismatch function/FB call parameter.");
       
   504   }
   804   }
   505 }
   805 }
   506 
   806 
   507 
   807 
   508 /* A helper function... */
   808 /* A helper function... */
   547       STAGE3_ERROR(call_param_name, call_param_name, "Invalid parameter in function/FB call.");
   847       STAGE3_ERROR(call_param_name, call_param_name, "Invalid parameter in function/FB call.");
   548     } else {
   848     } else {
   549       /* Get the parameter type */
   849       /* Get the parameter type */
   550       param_type = fp_iterator.param_type();
   850       param_type = fp_iterator.param_type();
   551       /* If the declared parameter and the parameter from the function call have the same type */
   851       /* If the declared parameter and the parameter from the function call have the same type */
   552       if(!is_compatible_type(call_param_type, param_type)) STAGE3_ERROR(call_param_name, call_param_value, "Type mismatch function/FB call parameter.");
   852       if(!is_valid_assignment(param_type, call_param_type)) STAGE3_ERROR(call_param_name, call_param_value, "Type mismatch function/FB call parameter.");
   553     }
   853     }
   554   }
   854   }
   555 }
   855 }
   556 
   856 
   557 
   857 
   927 
  1227 
   928 // SYM_REF0(LDN_operator_c)
  1228 // SYM_REF0(LDN_operator_c)
   929 void *visit_expression_type_c::visit(LDN_operator_c *symbol) {
  1229 void *visit_expression_type_c::visit(LDN_operator_c *symbol) {
   930   if(il_operand_type == NULL)
  1230   if(il_operand_type == NULL)
   931       STAGE3_ERROR(symbol, symbol, "LDN operator requires an operand.");
  1231       STAGE3_ERROR(symbol, symbol, "LDN operator requires an operand.");
   932   if(!is_ANY_BIT_type(il_operand_type))
  1232   if(!is_ANY_BIT_compatible(il_operand_type))
   933       STAGE3_ERROR(symbol, symbol, "invalid data type of LDN operand, should be of type ANY_BIT.");
  1233       STAGE3_ERROR(symbol, symbol, "invalid data type of LDN operand, should be of type ANY_BIT.");
   934   il_default_variable_type = il_operand_type;
  1234   il_default_variable_type = il_operand_type;
   935   return NULL;
  1235   return NULL;
   936 }
  1236 }
   937 
  1237 
   938 // SYM_REF0(ST_operator_c)
  1238 // SYM_REF0(ST_operator_c)
   939 void *visit_expression_type_c::visit(ST_operator_c *symbol) {
  1239 void *visit_expression_type_c::visit(ST_operator_c *symbol) {
   940   verify_null(symbol);
  1240   verify_null(symbol);
   941   if(!is_compatible_type(il_default_variable_type, il_operand_type))
  1241 
       
  1242   if(!is_valid_assignment(il_operand_type, il_default_variable_type))
   942     STAGE3_ERROR(symbol, symbol, "Type mismatch in ST operation.");
  1243     STAGE3_ERROR(symbol, symbol, "Type mismatch in ST operation.");
   943   /* TODO: check whether il_operand_type is an LVALUE !! */
  1244   /* TODO: check whether il_operand_type is an LVALUE !! */
   944   /* data type of il_default_variable_type is unchanged... */
  1245   /* data type of il_default_variable_type is unchanged... */
   945   // il_default_variable_type = il_default_variable_type;
  1246   // il_default_variable_type = il_default_variable_type;
   946   return NULL;
  1247   return NULL;
   947 }
  1248 }
   948 
  1249 
   949 // SYM_REF0(STN_operator_c)
  1250 // SYM_REF0(STN_operator_c)
   950  void *visit_expression_type_c::visit(STN_operator_c *symbol) {
  1251  void *visit_expression_type_c::visit(STN_operator_c *symbol) {
   951   verify_null(symbol);
  1252   verify_null(symbol);
   952   if(!is_compatible_type(il_default_variable_type, il_operand_type))
  1253   if(!is_valid_assignment(il_operand_type, il_default_variable_type))
   953     STAGE3_ERROR(symbol, symbol, "Type mismatch in ST operation.");
  1254     STAGE3_ERROR(symbol, symbol, "Type mismatch in ST operation.");
   954   /* TODO: check whether il_operand_type is an LVALUE !! */
  1255   /* TODO: check whether il_operand_type is an LVALUE !! */
   955   if(!is_ANY_BIT_type(il_default_variable_type))
  1256   if(!is_ANY_BIT_compatible(il_default_variable_type))
   956       STAGE3_ERROR(symbol, symbol, "invalid data type of il_default_variable for STN operand, should be of type ANY_BIT.");
  1257       STAGE3_ERROR(symbol, symbol, "invalid data type of il_default_variable for STN operand, should be of type ANY_BIT.");
   957   if(!is_ANY_BIT_type(il_operand_type))
  1258   if(!is_ANY_BIT_compatible(il_operand_type))
   958       STAGE3_ERROR(symbol, symbol, "invalid data type of STN operand, should be of type ANY_BIT.");
  1259       STAGE3_ERROR(symbol, symbol, "invalid data type of STN operand, should be of type ANY_BIT.");
   959   /* data type of il_default_variable_type is unchanged... */
  1260   /* data type of il_default_variable_type is unchanged... */
   960   // il_default_variable_type = il_default_variable_type;
  1261   // il_default_variable_type = il_default_variable_type;
   961   return NULL;
  1262   return NULL;
   962 }
  1263 }
   969   }
  1270   }
   970   if(il_default_variable_type == NULL) {
  1271   if(il_default_variable_type == NULL) {
   971     STAGE3_ERROR(symbol, symbol, "Il default variable should not be NULL.");
  1272     STAGE3_ERROR(symbol, symbol, "Il default variable should not be NULL.");
   972     return NULL;
  1273     return NULL;
   973   }
  1274   }
   974   if(!is_ANY_BIT_type(il_default_variable_type)) {
  1275   if(!is_ANY_BIT_compatible(il_default_variable_type)) {
   975     STAGE3_ERROR(symbol, symbol, "Il default variable should be of type ANY_BIT.");
  1276     STAGE3_ERROR(symbol, symbol, "Il default variable should be of type ANY_BIT.");
   976     return NULL;
  1277     return NULL;
   977   }
  1278   }
   978   /* data type of il_default_variable_type is unchanged... */
  1279   /* data type of il_default_variable_type is unchanged... */
   979   // il_default_variable_type = il_default_variable_type;
  1280   // il_default_variable_type = il_default_variable_type;
  1052 }
  1353 }
  1053 
  1354 
  1054 //SYM_REF0(AND_operator_c)
  1355 //SYM_REF0(AND_operator_c)
  1055 void *visit_expression_type_c::visit(AND_operator_c *symbol) {
  1356 void *visit_expression_type_c::visit(AND_operator_c *symbol) {
  1056   verify_null(symbol);
  1357   verify_null(symbol);
  1057   il_default_variable_type = compute_boolean_expression(il_default_variable_type,  il_operand_type, &visit_expression_type_c::is_ANY_BIT_type);
  1358   il_default_variable_type = compute_expression(il_default_variable_type,  il_operand_type, &visit_expression_type_c::is_ANY_BIT_compatible);
  1058   return NULL;
  1359   return NULL;
  1059 }
  1360 }
  1060 
  1361 
  1061 //SYM_REF0(OR_operator_c)
  1362 //SYM_REF0(OR_operator_c)
  1062 void *visit_expression_type_c::visit(OR_operator_c *symbol) {
  1363 void *visit_expression_type_c::visit(OR_operator_c *symbol) {
  1063   verify_null(symbol);
  1364   verify_null(symbol);
  1064   il_default_variable_type = compute_boolean_expression(il_default_variable_type,  il_operand_type, &visit_expression_type_c::is_ANY_BIT_type);
  1365   il_default_variable_type = compute_expression(il_default_variable_type,  il_operand_type, &visit_expression_type_c::is_ANY_BIT_compatible);
  1065   return NULL;
  1366   return NULL;
  1066 }
  1367 }
  1067 
  1368 
  1068 //SYM_REF0(XOR_operator_c)
  1369 //SYM_REF0(XOR_operator_c)
  1069 void *visit_expression_type_c::visit(XOR_operator_c *symbol) {
  1370 void *visit_expression_type_c::visit(XOR_operator_c *symbol) {
  1070   verify_null(symbol);
  1371   verify_null(symbol);
  1071   il_default_variable_type = compute_boolean_expression(il_default_variable_type,  il_operand_type, &visit_expression_type_c::is_ANY_BIT_type);
  1372   il_default_variable_type = compute_expression(il_default_variable_type,  il_operand_type, &visit_expression_type_c::is_ANY_BIT_compatible);
  1072   return NULL;
  1373   return NULL;
  1073 }
  1374 }
  1074 
  1375 
  1075 // SYM_REF0(ANDN_operator_c)
  1376 // SYM_REF0(ANDN_operator_c)
  1076 void *visit_expression_type_c::visit(ANDN_operator_c *symbol) {
  1377 void *visit_expression_type_c::visit(ANDN_operator_c *symbol) {
  1077   verify_null(symbol);
  1378   verify_null(symbol);
  1078   il_default_variable_type = compute_boolean_expression(il_default_variable_type,  il_operand_type, &visit_expression_type_c::is_ANY_BIT_type);
  1379   il_default_variable_type = compute_expression(il_default_variable_type,  il_operand_type, &visit_expression_type_c::is_ANY_BIT_compatible);
  1079   return NULL;
  1380   return NULL;
  1080 }
  1381 }
  1081 
  1382 
  1082 // SYM_REF0(ORN_operator_c)
  1383 // SYM_REF0(ORN_operator_c)
  1083 void *visit_expression_type_c::visit(ORN_operator_c *symbol) {
  1384 void *visit_expression_type_c::visit(ORN_operator_c *symbol) {
  1084   verify_null(symbol);
  1385   verify_null(symbol);
  1085   il_default_variable_type = compute_boolean_expression(il_default_variable_type,  il_operand_type, &visit_expression_type_c::is_ANY_BIT_type);
  1386   il_default_variable_type = compute_expression(il_default_variable_type,  il_operand_type, &visit_expression_type_c::is_ANY_BIT_compatible);
  1086   return NULL;
  1387   return NULL;
  1087 }
  1388 }
  1088 
  1389 
  1089 // SYM_REF0(XORN_operator_c)
  1390 // SYM_REF0(XORN_operator_c)
  1090 void *visit_expression_type_c::visit(XORN_operator_c *symbol) {
  1391 void *visit_expression_type_c::visit(XORN_operator_c *symbol) {
  1091   verify_null(symbol);
  1392   verify_null(symbol);
  1092   il_default_variable_type = compute_boolean_expression(il_default_variable_type,  il_operand_type, &visit_expression_type_c::is_ANY_BIT_type);
  1393   il_default_variable_type = compute_expression(il_default_variable_type,  il_operand_type, &visit_expression_type_c::is_ANY_BIT_compatible);
  1093   return NULL;
  1394   return NULL;
  1094 }
  1395 }
  1095 
  1396 
  1096 // SYM_REF0(ADD_operator_c)
  1397 // SYM_REF0(ADD_operator_c)
  1097 void *visit_expression_type_c::visit(ADD_operator_c *symbol) {
  1398 void *visit_expression_type_c::visit(ADD_operator_c *symbol) {
  1098   verify_null(symbol);
  1399   verify_null(symbol);
  1099   symbol_c *left_type  = il_default_variable_type;
  1400   symbol_c *left_type  = il_default_variable_type;
  1100   symbol_c *right_type = il_operand_type;
  1401   symbol_c *right_type = il_operand_type;
  1101   if      (typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) 
  1402 
       
  1403 /* The following is not required, it is already handled by compute_expression() ... */
       
  1404 /*
       
  1405   if      (is_type(left_type, time_type_name_c) && is_type(right_type, time_type_name_c))
  1102     il_default_variable_type = &time_type_name;
  1406     il_default_variable_type = &time_type_name;
  1103   else if (typeid(*left_type) == typeid(tod_type_name_c)  && typeid(*right_type) == typeid(time_type_name_c)) 
  1407 */
       
  1408 
       
  1409   if      (is_type(left_type, tod_type_name_c)      && is_type(right_type, time_type_name_c))
  1104     il_default_variable_type = &tod_type_name;
  1410     il_default_variable_type = &tod_type_name;
  1105   else if (typeid(*left_type) == typeid(dt_type_name_c)   && typeid(*right_type) == typeid(time_type_name_c)) 
  1411   else if (is_type(left_type, safetod_type_name_c)  && is_type(right_type, time_type_name_c))
       
  1412     il_default_variable_type = &tod_type_name;
       
  1413   else if (is_type(left_type, tod_type_name_c)      && is_type(right_type, safetime_type_name_c))
       
  1414     il_default_variable_type = &tod_type_name;
       
  1415   else if (is_type(left_type, safetod_type_name_c)  && is_type(right_type, safetime_type_name_c))
       
  1416     il_default_variable_type = &safetod_type_name;
       
  1417 
       
  1418   else if (is_type(left_type, dt_type_name_c)       && is_type(right_type, time_type_name_c))
  1106     il_default_variable_type = &dt_type_name;
  1419     il_default_variable_type = &dt_type_name;
  1107   else il_default_variable_type = compute_numeric_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_MAGNITUDE_type);
  1420   else if (is_type(left_type, safedt_type_name_c)   && is_type(right_type, time_type_name_c))
       
  1421     il_default_variable_type = &dt_type_name;
       
  1422   else if (is_type(left_type, dt_type_name_c)       && is_type(right_type, safetime_type_name_c))
       
  1423     il_default_variable_type = &dt_type_name;
       
  1424   else if (is_type(left_type, safedt_type_name_c)   && is_type(right_type, safetime_type_name_c))
       
  1425     il_default_variable_type = &safedt_type_name;
       
  1426 
       
  1427   else il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_MAGNITUDE_compatible);
  1108   return NULL;
  1428   return NULL;
  1109 }
  1429 }
  1110 
  1430 
  1111 // SYM_REF0(SUB_operator_c)
  1431 // SYM_REF0(SUB_operator_c)
  1112 void *visit_expression_type_c::visit(SUB_operator_c *symbol) {
  1432 void *visit_expression_type_c::visit(SUB_operator_c *symbol) {
  1113   verify_null(symbol);
  1433   verify_null(symbol);
  1114   symbol_c *left_type = il_default_variable_type;
  1434   symbol_c *left_type = il_default_variable_type;
  1115   symbol_c *right_type = il_operand_type;;
  1435   symbol_c *right_type = il_operand_type;;
       
  1436 
       
  1437 /* The following is not required, it is already handled by compute_expression() ... */
       
  1438 /*
  1116   if      (typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c))
  1439   if      (typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c))
  1117     il_default_variable_type = &time_type_name;
  1440     il_default_variable_type = &time_type_name;
  1118   else if (typeid(*left_type) == typeid(date_type_name_c) && typeid(*right_type) == typeid(date_type_name_c))
  1441 */
       
  1442 
       
  1443   if      (is_type(left_type, tod_type_name_c)       && is_type(right_type, time_type_name_c))
       
  1444     il_default_variable_type = &tod_type_name;
       
  1445   else if (is_type(left_type, safetod_type_name_c)   && is_type(right_type, time_type_name_c))
       
  1446     il_default_variable_type = &tod_type_name;
       
  1447   else if (is_type(left_type, tod_type_name_c)       && is_type(right_type, safetime_type_name_c))
       
  1448     il_default_variable_type = &tod_type_name;
       
  1449   else if (is_type(left_type, safetod_type_name_c)   && is_type(right_type, safetime_type_name_c))
       
  1450     il_default_variable_type = &safetod_type_name;
       
  1451 
       
  1452   else if (is_type(left_type, dt_type_name_c)       && is_type(right_type, time_type_name_c))
       
  1453     il_default_variable_type = &dt_type_name;
       
  1454   else if (is_type(left_type, safedt_type_name_c)   && is_type(right_type, time_type_name_c))
       
  1455     il_default_variable_type = &dt_type_name;
       
  1456   else if (is_type(left_type, dt_type_name_c)       && is_type(right_type, safetime_type_name_c))
       
  1457     il_default_variable_type = &dt_type_name;
       
  1458   else if (is_type(left_type, safedt_type_name_c)   && is_type(right_type, safetime_type_name_c))
       
  1459     il_default_variable_type = &safedt_type_name;
       
  1460 
       
  1461   else if (is_type(left_type, date_type_name_c)     && is_type(right_type, date_type_name_c))
  1119     il_default_variable_type = &time_type_name;
  1462     il_default_variable_type = &time_type_name;
  1120   else if (typeid(*left_type) == typeid(tod_type_name_c)  && typeid(*right_type) == typeid(time_type_name_c))
  1463   else if (is_type(left_type, safedate_type_name_c) && is_type(right_type, date_type_name_c))
  1121     il_default_variable_type = &tod_type_name;
       
  1122   else if (typeid(*left_type) == typeid(tod_type_name_c)  && typeid(*right_type) == typeid(tod_type_name_c))
       
  1123     il_default_variable_type = &time_type_name;
  1464     il_default_variable_type = &time_type_name;
  1124   else if (typeid(*left_type) == typeid(dt_type_name_c)   && typeid(*right_type) == typeid(time_type_name_c))
  1465   else if (is_type(left_type, date_type_name_c)     && is_type(right_type, safedate_type_name_c))
  1125     il_default_variable_type = &dt_type_name;
       
  1126   else if (typeid(*left_type) == typeid(dt_type_name_c)   && typeid(*right_type) == typeid(dt_type_name_c))
       
  1127     il_default_variable_type = &time_type_name;
  1466     il_default_variable_type = &time_type_name;
  1128   else il_default_variable_type = compute_numeric_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_MAGNITUDE_type);
  1467   else if (is_type(left_type, safedate_type_name_c) && is_type(right_type, safedate_type_name_c))
       
  1468     il_default_variable_type = &safetime_type_name;
       
  1469 
       
  1470   else if (is_type(left_type, tod_type_name_c)      && is_type(right_type, tod_type_name_c))
       
  1471     il_default_variable_type = &time_type_name;
       
  1472   else if (is_type(left_type, safetod_type_name_c)  && is_type(right_type, tod_type_name_c))
       
  1473     il_default_variable_type = &time_type_name;
       
  1474   else if (is_type(left_type, tod_type_name_c)      && is_type(right_type, safetod_type_name_c))
       
  1475     il_default_variable_type = &time_type_name;
       
  1476   else if (is_type(left_type, safetod_type_name_c)  && is_type(right_type, safetod_type_name_c))
       
  1477     il_default_variable_type = &safetime_type_name;
       
  1478 
       
  1479   else if (is_type(left_type, dt_type_name_c)       && is_type(right_type, dt_type_name_c))
       
  1480     il_default_variable_type = &time_type_name;
       
  1481   else if (is_type(left_type, safedt_type_name_c)   && is_type(right_type, dt_type_name_c))
       
  1482     il_default_variable_type = &time_type_name;
       
  1483   else if (is_type(left_type, dt_type_name_c)       && is_type(right_type, safedt_type_name_c))
       
  1484     il_default_variable_type = &time_type_name;
       
  1485   else if (is_type(left_type, safedt_type_name_c)   && is_type(right_type, safedt_type_name_c))
       
  1486     il_default_variable_type = &safetime_type_name;
       
  1487 
       
  1488   else il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_MAGNITUDE_compatible);
  1129   return NULL;
  1489   return NULL;
  1130 }
  1490 }
  1131 
  1491 
  1132 // SYM_REF0(MUL_operator_c)
  1492 // SYM_REF0(MUL_operator_c)
  1133 void *visit_expression_type_c::visit(MUL_operator_c *symbol) {
  1493 void *visit_expression_type_c::visit(MUL_operator_c *symbol) {
  1134   verify_null(symbol);
  1494   verify_null(symbol);
  1135   symbol_c *left_type = il_default_variable_type;
  1495   symbol_c *left_type = il_default_variable_type;
  1136   symbol_c *right_type = il_operand_type;
  1496   symbol_c *right_type = il_operand_type;
  1137   if (typeid(*left_type) == typeid(time_type_name_c) && is_ANY_NUM_type(right_type))
  1497 
       
  1498   if      (is_type(left_type, time_type_name_c)     && is_ANY_NUM_compatible(right_type))
  1138     il_default_variable_type = &time_type_name;
  1499     il_default_variable_type = &time_type_name;
  1139   else il_default_variable_type = compute_numeric_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_NUM_type);
  1500   else if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_type(right_type))
       
  1501     il_default_variable_type = &time_type_name;
       
  1502   else if (is_type(left_type, safetime_type_name_c) && is_ANY_SAFENUM_type(right_type))
       
  1503     il_default_variable_type = &safetime_type_name;
       
  1504   /* Since we have already checked for ANY_NUM_type and ANY_SAFENUM_type in the previous lines,
       
  1505    * this next line is really only to check for integers/reals of undefined type on 'right_type'... 
       
  1506    */
       
  1507   else if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_compatible(right_type))
       
  1508     il_default_variable_type = &safetime_type_name;
       
  1509 
       
  1510   else il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_NUM_compatible);
  1140   return NULL;
  1511   return NULL;
  1141 }
  1512 }
  1142 
  1513 
  1143 // SYM_REF0(DIV_operator_c)
  1514 // SYM_REF0(DIV_operator_c)
  1144 void *visit_expression_type_c::visit(DIV_operator_c *symbol) {
  1515 void *visit_expression_type_c::visit(DIV_operator_c *symbol) {
  1145   verify_null(symbol);
  1516   verify_null(symbol);
  1146   symbol_c *left_type = il_default_variable_type;
  1517   symbol_c *left_type = il_default_variable_type;
  1147   symbol_c *right_type = il_operand_type;
  1518   symbol_c *right_type = il_operand_type;
  1148   if (typeid(*left_type) == typeid(time_type_name_c) && is_ANY_NUM_type(right_type))
  1519 
       
  1520   if      (is_type(left_type, time_type_name_c)     && is_ANY_NUM_compatible(right_type))
  1149     il_default_variable_type = &time_type_name;
  1521     il_default_variable_type = &time_type_name;
  1150   else il_default_variable_type = compute_numeric_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_NUM_type);
  1522   else if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_type(right_type))
       
  1523     il_default_variable_type = &time_type_name;
       
  1524   else if (is_type(left_type, safetime_type_name_c) && is_ANY_SAFENUM_type(right_type))
       
  1525     il_default_variable_type = &safetime_type_name;
       
  1526   /* Since we have already checked for ANY_NUM_type and ANY_SAFENUM_type in the previous lines,
       
  1527    * this next line is really only to check for integers/reals of undefined type on 'right_type'... 
       
  1528    */
       
  1529   else if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_compatible(right_type))
       
  1530     il_default_variable_type = &safetime_type_name;
       
  1531 
       
  1532   else il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_NUM_compatible);
  1151   return NULL;
  1533   return NULL;
  1152 }
  1534 }
  1153 
  1535 
  1154 // SYM_REF0(MOD_operator_c)
  1536 // SYM_REF0(MOD_operator_c)
  1155 void *visit_expression_type_c::visit(MOD_operator_c *symbol) {
  1537 void *visit_expression_type_c::visit(MOD_operator_c *symbol) {
  1156   verify_null(symbol);
  1538   verify_null(symbol);
  1157   il_default_variable_type = compute_numeric_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_INT_type); 
  1539   il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_INT_compatible); 
  1158   return NULL;
  1540   return NULL;
  1159 }
  1541 }
  1160 
  1542 
  1161 // SYM_REF0(GT_operator_c)
  1543 // SYM_REF0(GT_operator_c)
  1162 void *visit_expression_type_c::visit(GT_operator_c *symbol) {
  1544 void *visit_expression_type_c::visit(GT_operator_c *symbol) {
  1163   verify_null(symbol);
  1545   verify_null(symbol);
  1164   compute_boolean_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
  1546   compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
  1165   il_default_variable_type = &search_expression_type_c::bool_type_name;
  1547   il_default_variable_type = &search_expression_type_c::bool_type_name;
  1166   return NULL;
  1548   return NULL;
  1167 }
  1549 }
  1168 
  1550 
  1169 //SYM_REF0(GE_operator_c)
  1551 //SYM_REF0(GE_operator_c)
  1170 void *visit_expression_type_c::visit(GE_operator_c *symbol) {
  1552 void *visit_expression_type_c::visit(GE_operator_c *symbol) {
  1171   verify_null(symbol);
  1553   verify_null(symbol);
  1172   compute_boolean_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
  1554   compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
  1173   il_default_variable_type = &search_expression_type_c::bool_type_name;
  1555   il_default_variable_type = &search_expression_type_c::bool_type_name;
  1174   return NULL;
  1556   return NULL;
  1175 }
  1557 }
  1176 
  1558 
  1177 //SYM_REF0(EQ_operator_c)
  1559 //SYM_REF0(EQ_operator_c)
  1178 void *visit_expression_type_c::visit(EQ_operator_c *symbol) {
  1560 void *visit_expression_type_c::visit(EQ_operator_c *symbol) {
  1179   verify_null(symbol);
  1561   verify_null(symbol);
  1180   compute_boolean_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
  1562   compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
  1181   il_default_variable_type = &search_expression_type_c::bool_type_name;
  1563   il_default_variable_type = &search_expression_type_c::bool_type_name;
  1182   return NULL;
  1564   return NULL;
  1183 }
  1565 }
  1184 
  1566 
  1185 //SYM_REF0(LT_operator_c)
  1567 //SYM_REF0(LT_operator_c)
  1186 void *visit_expression_type_c::visit(LT_operator_c *symbol) {
  1568 void *visit_expression_type_c::visit(LT_operator_c *symbol) {
  1187   verify_null(symbol);
  1569   verify_null(symbol);
  1188   compute_boolean_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
  1570   compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
  1189   il_default_variable_type = &search_expression_type_c::bool_type_name;
  1571   il_default_variable_type = &search_expression_type_c::bool_type_name;
  1190   return NULL;
  1572   return NULL;
  1191 }
  1573 }
  1192 
  1574 
  1193 //SYM_REF0(LE_operator_c)
  1575 //SYM_REF0(LE_operator_c)
  1194 void *visit_expression_type_c::visit(LE_operator_c *symbol) {
  1576 void *visit_expression_type_c::visit(LE_operator_c *symbol) {
  1195   verify_null(symbol);
  1577   verify_null(symbol);
  1196   compute_boolean_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
  1578   compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
  1197   il_default_variable_type = &search_expression_type_c::bool_type_name;
  1579   il_default_variable_type = &search_expression_type_c::bool_type_name;
  1198   return NULL;
  1580   return NULL;
  1199 }
  1581 }
  1200 
  1582 
  1201 //SYM_REF0(NE_operator_c)
  1583 //SYM_REF0(NE_operator_c)
  1202 void *visit_expression_type_c::visit(NE_operator_c *symbol) {
  1584 void *visit_expression_type_c::visit(NE_operator_c *symbol) {
  1203   verify_null(symbol);
  1585   verify_null(symbol);
  1204   compute_boolean_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
  1586   compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
  1205   il_default_variable_type = &search_expression_type_c::bool_type_name;
  1587   il_default_variable_type = &search_expression_type_c::bool_type_name;
  1206   return NULL;
  1588   return NULL;
  1207 }
  1589 }
  1208 
  1590 
  1209 // SYM_REF0(CAL_operator_c)
  1591 // SYM_REF0(CAL_operator_c)
  1297 /***********************/
  1679 /***********************/
  1298 
  1680 
  1299 void *visit_expression_type_c::visit(or_expression_c *symbol) {
  1681 void *visit_expression_type_c::visit(or_expression_c *symbol) {
  1300   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1682   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1301   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1683   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1302   return compute_boolean_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_type);
  1684   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_compatible);
  1303 }
  1685 }
  1304 
  1686 
  1305 
  1687 
  1306 void *visit_expression_type_c::visit(xor_expression_c *symbol) {
  1688 void *visit_expression_type_c::visit(xor_expression_c *symbol) {
  1307   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1689   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1308   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1690   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1309   return compute_boolean_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_type);
  1691   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_compatible);
  1310 }
  1692 }
  1311 
  1693 
  1312 
  1694 
  1313 void *visit_expression_type_c::visit(and_expression_c *symbol) {
  1695 void *visit_expression_type_c::visit(and_expression_c *symbol) {
  1314   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1696   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1315   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1697   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1316   return compute_boolean_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_type);
  1698   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_compatible);
  1317 }
  1699 }
  1318 
  1700 
  1319 
  1701 
  1320 void *visit_expression_type_c::visit(equ_expression_c *symbol) {
  1702 void *visit_expression_type_c::visit(equ_expression_c *symbol) {
  1321   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1703   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1322   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1704   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1323   compute_boolean_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
  1705   compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
  1324   return &search_expression_type_c::bool_type_name;
  1706   return &search_expression_type_c::bool_type_name;
  1325 }
  1707 }
  1326 
  1708 
  1327 
  1709 
  1328 void *visit_expression_type_c::visit(notequ_expression_c *symbol)  {
  1710 void *visit_expression_type_c::visit(notequ_expression_c *symbol)  {
  1329   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1711   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1330   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1712   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1331   compute_boolean_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
  1713   compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
  1332   return &search_expression_type_c::bool_type_name;
  1714   return &search_expression_type_c::bool_type_name;
  1333 }
  1715 }
  1334 
  1716 
  1335 
  1717 
  1336 void *visit_expression_type_c::visit(lt_expression_c *symbol) {
  1718 void *visit_expression_type_c::visit(lt_expression_c *symbol) {
  1337   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1719   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1338   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1720   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1339   compute_boolean_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
  1721   compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
  1340   return &search_expression_type_c::bool_type_name;
  1722   return &search_expression_type_c::bool_type_name;
  1341 }
  1723 }
  1342 
  1724 
  1343 
  1725 
  1344 void *visit_expression_type_c::visit(gt_expression_c *symbol) {
  1726 void *visit_expression_type_c::visit(gt_expression_c *symbol) {
  1345   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1727   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1346   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1728   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1347   compute_boolean_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
  1729   compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
  1348   return &search_expression_type_c::bool_type_name;
  1730   return &search_expression_type_c::bool_type_name;
  1349 }
  1731 }
  1350 
  1732 
  1351 
  1733 
  1352 void *visit_expression_type_c::visit(le_expression_c *symbol) {
  1734 void *visit_expression_type_c::visit(le_expression_c *symbol) {
  1353   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1735   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1354   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1736   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1355   compute_boolean_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
  1737   compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
  1356   return &search_expression_type_c::bool_type_name;
  1738   return &search_expression_type_c::bool_type_name;
  1357 }
  1739 }
  1358 
  1740 
  1359 
  1741 
  1360 void *visit_expression_type_c::visit(ge_expression_c *symbol) {
  1742 void *visit_expression_type_c::visit(ge_expression_c *symbol) {
  1361   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1743   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1362   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1744   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1363   compute_boolean_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
  1745   compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
  1364   return &search_expression_type_c::bool_type_name;
  1746   return &search_expression_type_c::bool_type_name;
  1365 }
  1747 }
  1366 
  1748 
  1367 
  1749 
  1368 void *visit_expression_type_c::visit(add_expression_c *symbol) {
  1750 void *visit_expression_type_c::visit(add_expression_c *symbol) {
  1369   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1751   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1370   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1752   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1371   if (typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&time_type_name;}
  1753 
  1372   if (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&tod_type_name;}
  1754 /* The following is already checked in compute_expression */
  1373   if (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&dt_type_name;}
  1755 /*
  1374   return compute_numeric_expression(left_type, right_type, &visit_expression_type_c::is_ANY_MAGNITUDE_type);
  1756   if (is_type(left_type, time_type_name_c) && is_type(right_type, time_type_name_c)) 
       
  1757     return (void *)&time_type_name;
       
  1758 */
       
  1759 
       
  1760   if (is_type(left_type, tod_type_name_c)      && is_type(right_type, time_type_name_c)) 
       
  1761     return (void *)&tod_type_name;
       
  1762   if (is_type(left_type, safetod_type_name_c)  && is_type(right_type, time_type_name_c)) 
       
  1763     return (void *)&tod_type_name;
       
  1764   if (is_type(left_type, tod_type_name_c)      && is_type(right_type, safetime_type_name_c)) 
       
  1765     return (void *)&tod_type_name;
       
  1766   if (is_type(left_type, safetod_type_name_c)  && is_type(right_type, safetime_type_name_c)) 
       
  1767     return (void *)&safetod_type_name;
       
  1768 
       
  1769   if (is_type(left_type, dt_type_name_c)       && is_type(right_type, time_type_name_c)) 
       
  1770     return (void *)&dt_type_name;
       
  1771   if (is_type(left_type, safedt_type_name_c)   && is_type(right_type, time_type_name_c)) 
       
  1772     return (void *)&dt_type_name;
       
  1773   if (is_type(left_type, dt_type_name_c)       && is_type(right_type, safetime_type_name_c)) 
       
  1774     return (void *)&dt_type_name;
       
  1775   if (is_type(left_type, safedt_type_name_c)   && is_type(right_type, safetime_type_name_c)) 
       
  1776     return (void *)&safedt_type_name;
       
  1777 
       
  1778   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_MAGNITUDE_compatible);
  1375 }
  1779 }
  1376 
  1780 
  1377 
  1781 
  1378 void *visit_expression_type_c::visit(sub_expression_c *symbol) {
  1782 void *visit_expression_type_c::visit(sub_expression_c *symbol) {
  1379   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1783   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1380   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1784   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1381   if (typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&time_type_name;}
  1785 
  1382   if (typeid(*left_type) == typeid(date_type_name_c) && typeid(*right_type) == typeid(date_type_name_c)) {return (void *)&time_type_name;}
  1786 /* The following is already checked in compute_expression */
  1383   if (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&tod_type_name;}
  1787 /*
  1384   if (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(tod_type_name_c)) {return (void *)&time_type_name;}
  1788   if (is_type(left_type, time_type_name_c) && is_type(right_type, time_type_name_c))
  1385   if (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&dt_type_name;}
  1789     return (void *)&time_type_name;
  1386   if (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(dt_type_name_c)) {return (void *)&time_type_name;}
  1790 */
  1387   return compute_numeric_expression(left_type, right_type, &visit_expression_type_c::is_ANY_MAGNITUDE_type);
  1791 
       
  1792   if (is_type(left_type, tod_type_name_c)     && is_type(right_type, time_type_name_c))
       
  1793     return (void *)&tod_type_name;
       
  1794   if (is_type(left_type, safetod_type_name_c) && is_type(right_type, time_type_name_c))
       
  1795     return (void *)&tod_type_name;
       
  1796   if (is_type(left_type, tod_type_name_c)     && is_type(right_type, safetime_type_name_c))
       
  1797     return (void *)&tod_type_name;
       
  1798   if (is_type(left_type, safetod_type_name_c) && is_type(right_type, safetime_type_name_c))
       
  1799     return (void *)&safetod_type_name;
       
  1800 
       
  1801   if (is_type(left_type, dt_type_name_c)     && is_type(right_type, time_type_name_c))
       
  1802     return (void *)&dt_type_name;
       
  1803   if (is_type(left_type, safedt_type_name_c) && is_type(right_type, time_type_name_c))
       
  1804     return (void *)&dt_type_name;
       
  1805   if (is_type(left_type, dt_type_name_c)     && is_type(right_type, safetime_type_name_c))
       
  1806     return (void *)&dt_type_name;
       
  1807   if (is_type(left_type, safedt_type_name_c) && is_type(right_type, safetime_type_name_c))
       
  1808     return (void *)&safedt_type_name;
       
  1809 
       
  1810   if (is_type(left_type, tod_type_name_c)     && is_type(right_type, tod_type_name_c))
       
  1811     return (void *)&time_type_name;
       
  1812   if (is_type(left_type, safetod_type_name_c) && is_type(right_type, tod_type_name_c))
       
  1813     return (void *)&time_type_name;
       
  1814   if (is_type(left_type, tod_type_name_c)     && is_type(right_type, safetod_type_name_c))
       
  1815     return (void *)&time_type_name;
       
  1816   if (is_type(left_type, safetod_type_name_c) && is_type(right_type, safetod_type_name_c))
       
  1817     return (void *)&safetime_type_name;
       
  1818 
       
  1819   if (is_type(left_type, date_type_name_c)     && is_type(right_type, date_type_name_c))
       
  1820     return (void *)&time_type_name;
       
  1821   if (is_type(left_type, safedate_type_name_c) && is_type(right_type, date_type_name_c))
       
  1822     return (void *)&time_type_name;
       
  1823   if (is_type(left_type, date_type_name_c)     && is_type(right_type, safedate_type_name_c))
       
  1824     return (void *)&time_type_name;
       
  1825   if (is_type(left_type, safedate_type_name_c) && is_type(right_type, safedate_type_name_c))
       
  1826     return (void *)&safetime_type_name;
       
  1827 
       
  1828   if (is_type(left_type, dt_type_name_c)     && is_type(right_type, dt_type_name_c))
       
  1829     return (void *)&time_type_name;
       
  1830   if (is_type(left_type, safedt_type_name_c) && is_type(right_type, dt_type_name_c))
       
  1831     return (void *)&time_type_name;
       
  1832   if (is_type(left_type, dt_type_name_c)     && is_type(right_type, safedt_type_name_c))
       
  1833     return (void *)&time_type_name;
       
  1834   if (is_type(left_type, safedt_type_name_c) && is_type(right_type, safedt_type_name_c))
       
  1835     return (void *)&safetime_type_name;
       
  1836 
       
  1837   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_MAGNITUDE_compatible);
  1388 }
  1838 }
  1389 
  1839 
  1390 
  1840 
  1391 void *visit_expression_type_c::visit(mul_expression_c *symbol) {
  1841 void *visit_expression_type_c::visit(mul_expression_c *symbol) {
  1392   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1842   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1393   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1843   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1394   if (typeid(*left_type) == typeid(time_type_name_c) && is_ANY_NUM_type(right_type)) {return (void *)&time_type_name;}
  1844 
  1395   return compute_numeric_expression(left_type, right_type, &visit_expression_type_c::is_ANY_NUM_type);
  1845   if (is_type(left_type, time_type_name_c)     && is_ANY_NUM_compatible(right_type)) 
       
  1846     return (void *)&time_type_name;
       
  1847   if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_type(right_type)) 
       
  1848     return (void *)&time_type_name;
       
  1849   if (is_type(left_type, safetime_type_name_c) && is_ANY_SAFENUM_type(right_type)) 
       
  1850     return (void *)&safetime_type_name;
       
  1851   /* Since we have already checked for ANY_NUM_type and ANY_SAFENUM_type in the previous lines,
       
  1852    * this next line is really only to check for integers/reals of undefined type on 'right_type'... 
       
  1853    */
       
  1854   if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_compatible(right_type)) 
       
  1855     return (void *)&safetime_type_name;
       
  1856 
       
  1857   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_NUM_compatible);
  1396 }
  1858 }
  1397 
  1859 
  1398 
  1860 
  1399 void *visit_expression_type_c::visit(div_expression_c *symbol) {
  1861 void *visit_expression_type_c::visit(div_expression_c *symbol) {
  1400   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1862   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1401   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1863   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1402   if (typeid(*left_type) == typeid(time_type_name_c) && is_ANY_NUM_type(right_type)){return (void *)&time_type_name;}
  1864 
  1403   return compute_numeric_expression(left_type, right_type, &visit_expression_type_c::is_ANY_NUM_type);
  1865   if (is_type(left_type, time_type_name_c)     && is_ANY_NUM_compatible(right_type)) 
       
  1866     return (void *)&time_type_name;
       
  1867   if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_type(right_type)) 
       
  1868     return (void *)&time_type_name;
       
  1869   if (is_type(left_type, safetime_type_name_c) && is_ANY_SAFENUM_type(right_type)) 
       
  1870     return (void *)&safetime_type_name;
       
  1871   /* Since we have already checked for ANY_NUM_type and ANY_SAFENUM_type in the previous lines,
       
  1872    * this next line is really only to check for integers/reals of undefined type on 'right_type'... 
       
  1873    */
       
  1874   if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_compatible(right_type)) 
       
  1875     return (void *)&safetime_type_name;
       
  1876 
       
  1877   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_NUM_compatible);
  1404 }
  1878 }
  1405 
  1879 
  1406 
  1880 
  1407 void *visit_expression_type_c::visit(mod_expression_c *symbol) {
  1881 void *visit_expression_type_c::visit(mod_expression_c *symbol) {
  1408   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1882   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1409   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1883   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1410   return compute_numeric_expression(left_type, right_type, &visit_expression_type_c::is_ANY_INT_type);
  1884   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_INT_compatible);
  1411 }
  1885 }
  1412 
  1886 
  1413 
  1887 
  1414 void *visit_expression_type_c::visit(power_expression_c *symbol) {
  1888 void *visit_expression_type_c::visit(power_expression_c *symbol) {
  1415   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1889   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1416   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1890   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1417   if (!is_ANY_REAL_type(left_type))
  1891   if (!is_ANY_REAL_compatible(left_type))
  1418     STAGE3_ERROR(symbol->l_exp, symbol->l_exp, "first operand of ** operator has invalid data type, should be of type ANY_REAL.");
  1892     STAGE3_ERROR(symbol->l_exp, symbol->l_exp, "first operand of ** operator has invalid data type, should be of type ANY_REAL.");
  1419   if (!is_ANY_NUM_type(right_type))
  1893   if (!is_ANY_NUM_compatible(right_type))
  1420     STAGE3_ERROR(symbol->r_exp, symbol->r_exp, "second operand of ** operator has invalid data type, should be of type ANY_NUM.");
  1894     STAGE3_ERROR(symbol->r_exp, symbol->r_exp, "second operand of ** operator has invalid data type, should be of type ANY_NUM.");
  1421 
  1895 
  1422   return (void *)left_type;
  1896   return (void *)left_type;
  1423 }
  1897 }
  1424 
  1898 
  1425 
  1899 
  1426 void *visit_expression_type_c::visit(neg_expression_c *symbol) {
  1900 void *visit_expression_type_c::visit(neg_expression_c *symbol) {
  1427   symbol_c *exp_type = base_type((symbol_c *)symbol->exp->accept(*this));
  1901   symbol_c *exp_type = base_type((symbol_c *)symbol->exp->accept(*this));
  1428   if (!is_ANY_MAGNITUDE_type(exp_type))
  1902   if (!is_ANY_MAGNITUDE_compatible(exp_type))
  1429     STAGE3_ERROR(symbol, symbol, "operand of negate expression '-' has invalid data type, should be of type ANY_MAGNITUDE.");
  1903     STAGE3_ERROR(symbol, symbol, "operand of negate expression '-' has invalid data type, should be of type ANY_MAGNITUDE.");
  1430 
  1904 
  1431   return exp_type;
  1905   return exp_type;
  1432 }
  1906 }
  1433 
  1907 
  1434 
  1908 
  1435 void *visit_expression_type_c::visit(not_expression_c *symbol) {
  1909 void *visit_expression_type_c::visit(not_expression_c *symbol) {
  1436   symbol_c *type = base_type((symbol_c *)symbol->exp->accept(*this));
  1910   symbol_c *type = base_type((symbol_c *)symbol->exp->accept(*this));
  1437   return compute_boolean_expression(type, type, &visit_expression_type_c::is_ANY_BIT_type);
  1911   return compute_expression(type, type, &visit_expression_type_c::is_ANY_BIT_compatible);
  1438 }
  1912 }
  1439 
  1913 
  1440 
  1914 
  1441 void *visit_expression_type_c::visit(function_invocation_c *symbol) {
  1915 void *visit_expression_type_c::visit(function_invocation_c *symbol) {
  1442   function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name);
  1916   function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name);
  1473 
  1947 
  1474 void *visit_expression_type_c::visit(assignment_statement_c *symbol) {
  1948 void *visit_expression_type_c::visit(assignment_statement_c *symbol) {
  1475   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1949   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1476   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1950   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1477 
  1951 
  1478   if (!is_compatible_type(left_type, right_type))  {
  1952   if (!is_valid_assignment(left_type, right_type))  {
  1479      STAGE3_ERROR(symbol, symbol, "data type mismatch in assignment statement!\n");
  1953      STAGE3_ERROR(symbol, symbol, "data type mismatch in assignment statement!\n");
  1480   }
  1954   }
  1481   return NULL;
  1955   return NULL;
  1482 }
  1956 }
  1483 
  1957 
  1593     if (NULL == element_type) {
  2067     if (NULL == element_type) {
  1594       STAGE3_ERROR(symbol->elements[i], symbol->elements[i], "Case list element has undefined data type.");
  2068       STAGE3_ERROR(symbol->elements[i], symbol->elements[i], "Case list element has undefined data type.");
  1595     } else {
  2069     } else {
  1596       element_type = base_type(element_type);
  2070       element_type = base_type(element_type);
  1597       if (NULL != element_type){
  2071       if (NULL != element_type){
       
  2072         /* The CASE value is only used for comparison (and not assingment), so we only check for compatibility! */ 
  1598         if (!is_compatible_type(case_expression_type, element_type))
  2073         if (!is_compatible_type(case_expression_type, element_type))
  1599           STAGE3_ERROR(symbol->elements[i], symbol->elements[i], "Invalid data type of case list element.");
  2074           STAGE3_ERROR(symbol->elements[i], symbol->elements[i], "Invalid data type of case list element.");
  1600       }
  2075       }
  1601     }
  2076     }
  1602   }
  2077   }
  1614   if (NULL == var_type) ERROR;
  2089   if (NULL == var_type) ERROR;
  1615   var_type = base_type(var_type);
  2090   var_type = base_type(var_type);
  1616   if (NULL == var_type) ERROR;
  2091   if (NULL == var_type) ERROR;
  1617   // ASSIGN
  2092   // ASSIGN
  1618   symbol_c *beg_expr_type = base_type((symbol_c*)symbol->beg_expression->accept(*this));
  2093   symbol_c *beg_expr_type = base_type((symbol_c*)symbol->beg_expression->accept(*this));
  1619   if (NULL != beg_expr_type) { 
  2094   if (NULL != beg_expr_type) {
  1620     if(!is_compatible_type(var_type,beg_expr_type)) 
  2095     /* The BEG value is assigned to the variable, so we check for assignment validity! */ 
       
  2096     if(!is_valid_assignment(var_type, beg_expr_type)) 
  1621       STAGE3_ERROR(symbol, symbol, "Data type mismatch between control variable and initial value.");
  2097       STAGE3_ERROR(symbol, symbol, "Data type mismatch between control variable and initial value.");
  1622   }
  2098   }
  1623   // TO
  2099   // TO
  1624   symbol_c *end_expr_type = base_type((symbol_c*)symbol->end_expression->accept(*this));
  2100   symbol_c *end_expr_type = base_type((symbol_c*)symbol->end_expression->accept(*this));
  1625   if (NULL != end_expr_type) { 
  2101   if (NULL != end_expr_type) { 
  1626     if(!is_compatible_type(var_type,end_expr_type)) 
  2102     /* The TO value is only used for comparison, so we only check for compatibility! */ 
       
  2103     if(!is_compatible_type(var_type, end_expr_type)) 
  1627       STAGE3_ERROR(symbol, symbol, "Data type mismatch between control variable and final value.");
  2104       STAGE3_ERROR(symbol, symbol, "Data type mismatch between control variable and final value.");
  1628   }
  2105   }
  1629   // BY
  2106   // BY
  1630   if(symbol->by_expression != NULL) {
  2107   if(symbol->by_expression != NULL) {
  1631     symbol_c *by_expr_type = base_type((symbol_c*)symbol->by_expression->accept(*this));
  2108     symbol_c *by_expr_type = base_type((symbol_c*)symbol->by_expression->accept(*this));
  1632     if (NULL != end_expr_type) {   
  2109     if (NULL != end_expr_type) {   
  1633       if(!is_compatible_type(var_type,by_expr_type)) 
  2110       /* The BY value is used in an expression (add, sub, ...), so we only check for compatibility! */ 
       
  2111       if(!is_compatible_type(var_type, by_expr_type)) 
  1634         STAGE3_ERROR(symbol, symbol, "Data type mismatch between control variable and BY value.");
  2112         STAGE3_ERROR(symbol, symbol, "Data type mismatch between control variable and BY value.");
  1635     }
  2113     }
  1636   }
  2114   }
  1637   // DO
  2115   // DO
  1638   if (NULL != symbol->statement_list)
  2116   if (NULL != symbol->statement_list)