absyntax_utils/search_constant_type.cc
changeset 270 f1674941c3ad
parent 265 4d222f46f8cc
child 279 c0453b7f99df
equal deleted inserted replaced
256:101c7f148b9a 270:f1674941c3ad
     1 /*
     1 /*
     2  * (c) 2003 Mario de Sousa
     2  *  matiec - a compiler for the programming languages defined in IEC 61131-3
     3  *
     3  *
     4  * Offered to the public under the terms of the GNU General Public License
     4  *  Copyright (C) 2003-2011  Mario de Sousa (msousa@fe.up.pt)
     5  * as published by the Free Software Foundation; either version 2 of the
       
     6  * License, or (at your option) any later version.
       
     7  *
     5  *
     8  * This program is distributed in the hope that it will be useful, but
     6  *  This program is free software: you can redistribute it and/or modify
     9  * WITHOUT ANY WARRANTY; without even the implied warranty of
     7  *  it under the terms of the GNU General Public License as published by
    10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
     8  *  the Free Software Foundation, either version 3 of the License, or
    11  * Public License for more details.
     9  *  (at your option) any later version.
       
    10  *
       
    11  *  This program is distributed in the hope that it will be useful,
       
    12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    14  *  GNU General Public License for more details.
       
    15  *
       
    16  *  You should have received a copy of the GNU General Public License
       
    17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
       
    18  *
    12  *
    19  *
    13  * This code is made available on the understanding that it will not be
    20  * This code is made available on the understanding that it will not be
    14  * used in safety-critical situations without a full and competent review.
    21  * used in safety-critical situations without a full and competent review.
    15  */
    22  */
    16 
    23 
    17 /*
    24 /*
    18  * An IEC 61131-3 IL and ST compiler.
    25  * An IEC 61131-3 compiler.
    19  *
    26  *
    20  * Based on the
    27  * Based on the
    21  * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
    28  * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
    22  *
    29  *
    23  */
    30  */
    57   * numeric literal '30' must then be considered a LINT so the ADD function may be called
    64   * numeric literal '30' must then be considered a LINT so the ADD function may be called
    58   * with all inputs of the same data type.
    65   * with all inputs of the same data type.
    59   * If 'x' were a SINT, then the '30' would have to be a SINT too!
    66   * If 'x' were a SINT, then the '30' would have to be a SINT too!
    60   */
    67   */
    61 void *search_constant_type_c::visit(real_c *symbol)           {return (void *)symbol;}
    68 void *search_constant_type_c::visit(real_c *symbol)           {return (void *)symbol;}
       
    69 void *search_constant_type_c::visit(neg_real_c *symbol)       {return (void *)symbol;}
    62 void *search_constant_type_c::visit(integer_c *symbol)        {return (void *)symbol;}
    70 void *search_constant_type_c::visit(integer_c *symbol)        {return (void *)symbol;}
       
    71 void *search_constant_type_c::visit(neg_integer_c *symbol)    {return (void *)symbol;}
    63 void *search_constant_type_c::visit(binary_integer_c *symbol) {return (void *)symbol;}
    72 void *search_constant_type_c::visit(binary_integer_c *symbol) {return (void *)symbol;}
    64 void *search_constant_type_c::visit(octal_integer_c *symbol)  {return (void *)symbol;}
    73 void *search_constant_type_c::visit(octal_integer_c *symbol)  {return (void *)symbol;}
    65 void *search_constant_type_c::visit(hex_integer_c *symbol)    {return (void *)symbol;}
    74 void *search_constant_type_c::visit(hex_integer_c *symbol)    {return (void *)symbol;}
    66 
    75 
    67 void *search_constant_type_c::visit(integer_literal_c *symbol)
    76 void *search_constant_type_c::visit(integer_literal_c *symbol)
    88 /***************************/
    97 /***************************/
    89 /************************/
    98 /************************/
    90 /* B 1.2.3.1 - Duration */
    99 /* B 1.2.3.1 - Duration */
    91 /************************/
   100 /************************/
    92 void *search_constant_type_c::visit(neg_time_c *symbol) {ERROR; return NULL;}  /* this member function should never be called. */
   101 void *search_constant_type_c::visit(neg_time_c *symbol) {ERROR; return NULL;}  /* this member function should never be called. */
    93 void *search_constant_type_c::visit(duration_c *symbol) {return (void *)&time_type_name;}
   102 void *search_constant_type_c::visit(duration_c *symbol) {return (void *)(symbol->type_name);}
    94 void *search_constant_type_c::visit(fixed_point_c *symbol) {ERROR; return NULL;}  /* this member function should never be called. */
   103 void *search_constant_type_c::visit(fixed_point_c *symbol) {ERROR; return NULL;}  /* this member function should never be called. */
    95 void *search_constant_type_c::visit(days_c *symbol) {ERROR; return NULL;}  /* this member function should never be called. */
   104 void *search_constant_type_c::visit(days_c *symbol) {ERROR; return NULL;}  /* this member function should never be called. */
    96 void *search_constant_type_c::visit(hours_c *symbol) {ERROR; return NULL;}  /* this member function should never be called. */
   105 void *search_constant_type_c::visit(hours_c *symbol) {ERROR; return NULL;}  /* this member function should never be called. */
    97 void *search_constant_type_c::visit(minutes_c *symbol) {ERROR; return NULL;}  /* this member function should never be called. */
   106 void *search_constant_type_c::visit(minutes_c *symbol) {ERROR; return NULL;}  /* this member function should never be called. */
    98 void *search_constant_type_c::visit(seconds_c *symbol) {ERROR; return NULL;}  /* this member function should never be called. */
   107 void *search_constant_type_c::visit(seconds_c *symbol) {ERROR; return NULL;}  /* this member function should never be called. */
    99 void *search_constant_type_c::visit(milliseconds_c *symbol) {ERROR; return NULL;}  /* this member function should never be called. */
   108 void *search_constant_type_c::visit(milliseconds_c *symbol) {ERROR; return NULL;}  /* this member function should never be called. */
   100 
   109 
   101 /************************************/
   110 /************************************/
   102 /* B 1.2.3.2 - Time of day and Date */
   111 /* B 1.2.3.2 - Time of day and Date */
   103 /************************************/
   112 /************************************/
   104 void *search_constant_type_c::visit(time_of_day_c *symbol) {return (void *)&tod_type_name;}
   113 void *search_constant_type_c::visit(time_of_day_c *symbol) {return (void *)(symbol->type_name);}
   105 void *search_constant_type_c::visit(daytime_c *symbol) {ERROR; return NULL;}  /* this member function should never be called. */
   114 void *search_constant_type_c::visit(daytime_c *symbol) {ERROR; return NULL;}  /* this member function should never be called. */
   106 void *search_constant_type_c::visit(date_c *symbol) {return (void *)&date_type_name;}
   115 void *search_constant_type_c::visit(date_c *symbol) {return (void *)(symbol->type_name);}
   107 void *search_constant_type_c::visit(date_literal_c *symbol) {ERROR; return NULL;}  /* this member function should never be called. */
   116 void *search_constant_type_c::visit(date_literal_c *symbol) {ERROR; return NULL;}  /* this member function should never be called. */
   108 void *search_constant_type_c::visit(date_and_time_c *symbol) {return (void *)&dt_type_name;}
   117 void *search_constant_type_c::visit(date_and_time_c *symbol) {return (void *)(symbol->type_name);}
       
   118 
   109 
   119 
   110 real_type_name_c     search_constant_type_c::real_type_name;
   120 real_type_name_c     search_constant_type_c::real_type_name;
   111 sint_type_name_c     search_constant_type_c::sint_type_name;
   121 sint_type_name_c     search_constant_type_c::sint_type_name;
   112 lint_type_name_c     search_constant_type_c::lint_type_name;
   122 lint_type_name_c     search_constant_type_c::lint_type_name;
   113 dint_type_name_c     search_constant_type_c::dint_type_name;
   123 dint_type_name_c     search_constant_type_c::dint_type_name;
   127 ulint_type_name_c    search_constant_type_c::ulint_type_name;
   137 ulint_type_name_c    search_constant_type_c::ulint_type_name;
   128 bool_type_name_c     search_constant_type_c::bool_type_name;
   138 bool_type_name_c     search_constant_type_c::bool_type_name;
   129 time_type_name_c     search_constant_type_c::time_type_name;
   139 time_type_name_c     search_constant_type_c::time_type_name;
   130 int_type_name_c      search_constant_type_c::int_type_name;
   140 int_type_name_c      search_constant_type_c::int_type_name;
   131 
   141 
   132 /*
   142 // safebool_type_name_c    search_constant_type_c::safebool_type_name;
   133 constant_real_type_name_c     search_constant_type_c::constant_real_type_name;
   143   /* The following is required because the expression (TOD_var - TOD_var) will result in a data type
   134 constant_int_type_name_c      search_constant_type_c::constant_int_type_name;
   144    *  (in this case, TIME) that is neither of the expression elements...
   135 */
   145    */
       
   146 safetime_type_name_c     search_constant_type_c::safetime_type_name;
       
   147 safetod_type_name_c      search_constant_type_c::safetod_type_name;
       
   148 safedt_type_name_c       search_constant_type_c::safedt_type_name;
       
   149 
       
   150 
       
   151 
   136 /* temporarily here until we remove the st_code_gen.c and il_code_gen.c files... */
   152 /* temporarily here until we remove the st_code_gen.c and il_code_gen.c files... */
   137 /* It should then move to search_expression_type_c                               */
   153 /* It should then move to search_expression_type_c                               */
   138 integer_c search_constant_type_c::integer("1");
   154 integer_c search_constant_type_c::integer("1");