absyntax_utils/search_constant_type.hh
changeset 181 38d6eb056260
child 194 e18690830555
equal deleted inserted replaced
180:64334c5a00b1 181:38d6eb056260
       
     1 /*
       
     2  * (c) 2003 Mario de Sousa
       
     3  *
       
     4  * Offered to the public under the terms of the GNU General Public License
       
     5  * as published by the Free Software Foundation; either version 2 of the
       
     6  * License, or (at your option) any later version.
       
     7  *
       
     8  * This program is distributed in the hope that it will be useful, but
       
     9  * WITHOUT ANY WARRANTY; without even the implied warranty of
       
    10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
       
    11  * Public License for more details.
       
    12  *
       
    13  * 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.
       
    15  */
       
    16 
       
    17 /*
       
    18  * An IEC 61131-3 IL and ST compiler.
       
    19  *
       
    20  * Based on the
       
    21  * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
       
    22  *
       
    23  */
       
    24 
       
    25 /* Determine the data type of a specific constant or variable.
       
    26  * A reference to the relevant type definition is returned.
       
    27  *
       
    28  * For example:
       
    29  *       22          -> returns reference to a int_type_name_c object.
       
    30  *       22.2        -> returns reference to a real_type_name_c object.
       
    31  *       LREAL#22.2  -> returns reference to a lreal_type_name_c object.
       
    32  *       etc...
       
    33  */
       
    34 
       
    35 
       
    36 #include "../absyntax/visitor.hh"
       
    37 
       
    38 
       
    39 class search_constant_type_c: public search_visitor_c {
       
    40 
       
    41   public:
       
    42   /**********************/
       
    43   /* B.1.3 - Data types */
       
    44   /**********************/
       
    45   /***********************************/
       
    46   /* B 1.3.1 - Elementary Data Types */
       
    47   /***********************************/
       
    48   static real_type_name_c     real_type_name;
       
    49   static sint_type_name_c     sint_type_name;
       
    50   static lint_type_name_c     lint_type_name;
       
    51   static dint_type_name_c     dint_type_name;
       
    52   static date_type_name_c     date_type_name;
       
    53   static dword_type_name_c    dword_type_name;
       
    54   static dt_type_name_c       dt_type_name;
       
    55   static tod_type_name_c      tod_type_name;
       
    56   static udint_type_name_c    udint_type_name;
       
    57   static word_type_name_c     word_type_name;
       
    58   static wstring_type_name_c  wstring_type_name;
       
    59   static string_type_name_c   string_type_name;
       
    60   static lword_type_name_c    lword_type_name;
       
    61   static uint_type_name_c     uint_type_name;
       
    62   static lreal_type_name_c    lreal_type_name;
       
    63   static byte_type_name_c     byte_type_name;
       
    64   static usint_type_name_c    usint_type_name;
       
    65   static ulint_type_name_c    ulint_type_name;
       
    66   static bool_type_name_c     bool_type_name;
       
    67   static time_type_name_c     time_type_name;
       
    68   static int_type_name_c      int_type_name;
       
    69 
       
    70   static constant_real_type_name_c     constant_real_type_name;
       
    71   static constant_int_type_name_c      constant_int_type_name;
       
    72   static direct_variable_type_name_c   direct_variable_type_name;
       
    73 
       
    74   /******************************************************/
       
    75   /* Extensions to the base standard as defined in      */
       
    76   /* "Safety Software Technical Specification,          */
       
    77   /*  Part 1: Concepts and Function Blocks,             */
       
    78   /*  Version 1.0 – Official Release"                   */
       
    79   /* by PLCopen - Technical Committee 5 - 2006-01-31    */
       
    80   /******************************************************/
       
    81   static safebool_type_name_c          safebool_type_name;
       
    82 
       
    83 
       
    84   public:
       
    85     symbol_c *get_type(symbol_c *constant);
       
    86 
       
    87 
       
    88   private:
       
    89     /*********************/
       
    90     /* B 1.2 - Constants */
       
    91     /*********************/
       
    92 
       
    93     /******************************/
       
    94     /* B 1.2.1 - Numeric Literals */
       
    95     /******************************/
       
    96     void *visit(real_c *symbol);
       
    97     void *visit(integer_c *symbol);
       
    98     void *visit(binary_integer_c *symbol);
       
    99     void *visit(octal_integer_c *symbol);
       
   100     void *visit(hex_integer_c *symbol);
       
   101 
       
   102     void *visit(numeric_literal_c *symbol);
       
   103     void *visit(integer_literal_c *symbol);
       
   104     void *visit(real_literal_c *symbol);
       
   105     void *visit(bit_string_literal_c *symbol);
       
   106     void *visit(boolean_literal_c *symbol);
       
   107 
       
   108     /*******************************/
       
   109     /* B.1.2.2   Character Strings */
       
   110     /*******************************/
       
   111     void *visit(double_byte_character_string_c *symbol);
       
   112     void *visit(single_byte_character_string_c *symbol);
       
   113 
       
   114     /***************************/
       
   115     /* B 1.2.3 - Time Literals */
       
   116     /***************************/
       
   117     /************************/
       
   118     /* B 1.2.3.1 - Duration */
       
   119     /************************/
       
   120     void *visit(neg_time_c *symbol);
       
   121     void *visit(duration_c *symbol);
       
   122     void *visit(fixed_point_c *symbol);
       
   123     void *visit(days_c *symbol);
       
   124     void *visit(hours_c *symbol);
       
   125     void *visit(minutes_c *symbol);
       
   126     void *visit(seconds_c *symbol);
       
   127     void *visit(milliseconds_c *symbol);
       
   128 
       
   129     /************************************/
       
   130     /* B 1.2.3.2 - Time of day and Date */
       
   131     /************************************/
       
   132     void *visit(time_of_day_c *symbol);
       
   133     void *visit(daytime_c *symbol);
       
   134     void *visit(date_c *symbol);
       
   135     void *visit(date_literal_c *symbol);
       
   136     void *visit(date_and_time_c *symbol);
       
   137 };  // search_constant_type_c
       
   138 
       
   139 
       
   140