absyntax_utils/get_datatype_info.cc
changeset 676 ca4f17211251
parent 668 90b6eb7f1775
child 693 51a2fa6441b9
equal deleted inserted replaced
675:59fc28d4b06c 676:ca4f17211251
     1 /*
     1 /*
     2  *  matiec - a compiler for the programming languages defined in IEC 61131-3
     2  *  matiec - a compiler for the programming languages defined in IEC 61131-3
     3  *
     3  *
     4  *  Copyright (C) 2003-2012  Mario de Sousa (msousa@fe.up.pt)
     4  *  Copyright (C) 2003-2012  Mario de Sousa (msousa@fe.up.pt)
     5  *  Copyright (C) 2007-2011  Laurent Bessard and Edouard Tisserant
     5  *  Copyright (C) 2007-2011  Laurent Bessard and Edouard Tisserant
       
     6  *  Copyright (C) 2012       Manuele Conti  (conti.ma@alice.it)
     6  *
     7  *
     7  *  This program is free software: you can redistribute it and/or modify
     8  *  This program is free software: you can redistribute it and/or modify
     8  *  it under the terms of the GNU General Public License as published by
     9  *  it under the terms of the GNU General Public License as published by
     9  *  the Free Software Foundation, either version 3 of the License, or
    10  *  the Free Software Foundation, either version 3 of the License, or
    10  *  (at your option) any later version.
    11  *  (at your option) any later version.
    52 
    53 
    53 
    54 
    54 
    55 
    55 
    56 
    56 static search_base_type_c search_base_type;
    57 static search_base_type_c search_base_type;
       
    58 
       
    59 
       
    60 
       
    61 
       
    62 
       
    63 bool get_datatype_info_c::is_type_equal(symbol_c *first_type, symbol_c *second_type) {
       
    64   if ((NULL == first_type) || (NULL == second_type))
       
    65       return false;
       
    66   if (typeid(* first_type) == typeid(invalid_type_name_c))
       
    67       return false;
       
    68   if (typeid(*second_type) == typeid(invalid_type_name_c))
       
    69       return false;
       
    70     
       
    71   if (get_datatype_info_c::is_ANY_ELEMENTARY(first_type)) {
       
    72       if (typeid(*first_type) == typeid(*second_type))
       
    73           return true;
       
    74   } else   /* ANY_DERIVED */
       
    75       return (first_type == second_type);
       
    76 
       
    77   return false;
       
    78 }
       
    79 
       
    80 
       
    81 
       
    82 bool get_datatype_info_c::is_type_valid(symbol_c *type) {
       
    83   if (NULL == type)
       
    84       return false;
       
    85   if (typeid(*type) == typeid(invalid_type_name_c))
       
    86       return false;
       
    87 
       
    88   return true;
       
    89 }
       
    90 
       
    91 
    57 
    92 
    58 
    93 
    59 
    94 
    60 
    95 
    61 bool get_datatype_info_c::is_sfc_initstep(symbol_c *type_symbol) {
    96 bool get_datatype_info_c::is_sfc_initstep(symbol_c *type_symbol) {
   257 
   292 
   258 bool get_datatype_info_c::is_ANY_SAFENUM(symbol_c *type_symbol) {
   293 bool get_datatype_info_c::is_ANY_SAFENUM(symbol_c *type_symbol) {
   259   if (type_symbol == NULL)                                     {return false;}
   294   if (type_symbol == NULL)                                     {return false;}
   260   if (is_ANY_SAFEREAL(type_symbol))                            {return true;}
   295   if (is_ANY_SAFEREAL(type_symbol))                            {return true;}
   261   if (is_ANY_SAFEINT (type_symbol))                            {return true;}
   296   if (is_ANY_SAFEINT (type_symbol))                            {return true;}
       
   297   return false;
   262 }
   298 }
   263 
   299 
   264 
   300 
   265 bool get_datatype_info_c::is_ANY_NUM_compatible(symbol_c *type_symbol) {
   301 bool get_datatype_info_c::is_ANY_NUM_compatible(symbol_c *type_symbol) {
   266   if (type_symbol == NULL)                                     {return false;}
   302   if (type_symbol == NULL)                                     {return false;}
   285 
   321 
   286 bool get_datatype_info_c::is_ANY_signed_SAFENUM(symbol_c *type_symbol) {
   322 bool get_datatype_info_c::is_ANY_signed_SAFENUM(symbol_c *type_symbol) {
   287   if (type_symbol == NULL)                                     {return false;}
   323   if (type_symbol == NULL)                                     {return false;}
   288   if (is_ANY_SAFEREAL      (type_symbol))                      {return true;}
   324   if (is_ANY_SAFEREAL      (type_symbol))                      {return true;}
   289   if (is_ANY_signed_SAFEINT(type_symbol))                      {return true;}
   325   if (is_ANY_signed_SAFEINT(type_symbol))                      {return true;}
       
   326   return false;
   290 }
   327 }
   291 
   328 
   292 
   329 
   293 bool get_datatype_info_c::is_ANY_signed_NUM_compatible(symbol_c *type_symbol) {
   330 bool get_datatype_info_c::is_ANY_signed_NUM_compatible(symbol_c *type_symbol) {
   294   if (type_symbol == NULL)                                     {return false;}
   331   if (type_symbol == NULL)                                     {return false;}