absyntax_utils/search_il_operand_type.cc
changeset 692 c3287ffaee8c
parent 691 958454e9e40f
child 693 51a2fa6441b9
equal deleted inserted replaced
691:958454e9e40f 692:c3287ffaee8c
     1 /*
       
     2  *  matiec - a compiler for the programming languages defined in IEC 61131-3
       
     3  *
       
     4  *  Copyright (C) 2003-2011  Mario de Sousa (msousa@fe.up.pt)
       
     5  *  Copyright (C) 2007-2011  Laurent Bessard and Edouard Tisserant
       
     6  *
       
     7  *  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  *  the Free Software Foundation, either version 3 of the License, or
       
    10  *  (at your option) any later version.
       
    11  *
       
    12  *  This program is distributed in the hope that it will be useful,
       
    13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    15  *  GNU General Public License for more details.
       
    16  *
       
    17  *  You should have received a copy of the GNU General Public License
       
    18  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
       
    19  *
       
    20  *
       
    21  * This code is made available on the understanding that it will not be
       
    22  * used in safety-critical situations without a full and competent review.
       
    23  */
       
    24 
       
    25 /*
       
    26  * An IEC 61131-3 compiler.
       
    27  *
       
    28  * Based on the
       
    29  * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
       
    30  *
       
    31  */
       
    32 
       
    33 
       
    34 
       
    35 
       
    36 /* Returns the data type of an il_operand.
       
    37  *
       
    38  * Note that the il_operand may be a variable, in which case
       
    39  * we return the type of the variable instance.
       
    40  * The il_operand may also be a constant, in which case
       
    41  * we return the data type of that constant.
       
    42  *
       
    43  * The variable instance may be a member of a structured variable,
       
    44  * or an element in an array, or any combination of the two.
       
    45  *
       
    46  * The class constructor must be given the search scope
       
    47  * (function, function block or program within which
       
    48  * the possible il_operand variable instance was declared).
       
    49  */
       
    50 
       
    51 #include "absyntax_utils.hh"
       
    52 
       
    53 symbol_c *search_il_operand_type_c::get_type(symbol_c *il_operand) {
       
    54   symbol_c *res;
       
    55 
       
    56   /* We first assume that it is a constant... */
       
    57   res = search_constant_type.get_type(il_operand);
       
    58   if (res != NULL) return res;
       
    59 
       
    60   /* Nope, now we assume it is a variable, and determine its type... */
       
    61   res = search_varfb_instance_type.get_type(il_operand);
       
    62   if (NULL != res) return res;
       
    63 
       
    64   /* not found */
       
    65   return NULL;
       
    66 }