absyntax_utils/search_il_operand_type.cc
changeset 201 e657008f43d0
child 202 da1a8186f86f
equal deleted inserted replaced
196:1c0c7a664fc2 201:e657008f43d0
       
     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 
       
    26 
       
    27 
       
    28 /* Returns the data type of an il_operand.
       
    29  *
       
    30  * Note that the il_operand may be a variable, in which case
       
    31  * we return the type of the variable instance.
       
    32  * The il_operand may also be a constant, in which case
       
    33  * we return the data type of that constant.
       
    34  *
       
    35  * The variable instance may be a member of a structured variable,
       
    36  * or an element in an array, or any combination of the two.
       
    37  *
       
    38  * The class constructor must be given the search scope
       
    39  * (function, function block or program within which
       
    40  * the possible il_operand variable instance was declared).
       
    41  */
       
    42 
       
    43 
       
    44 
       
    45 symbol_c *search_il_operand_type_c::get_type(symbol_c *il_operand) {
       
    46   symbol_c *res;
       
    47 
       
    48   /* We first assume that it is a constant... */
       
    49   res = search_constant_type.get_type(il_operand);
       
    50   if (res != NULL) return res;
       
    51 
       
    52   /* Nope, now we assume it is a variable, and determine its type... */
       
    53   res = search_varfb_instance_type.get_type(il_operand);
       
    54   if (NULL != res) return res;
       
    55 
       
    56   /* not found */
       
    57   return NULL;
       
    58 }