absyntax_utils/search_il_operand_type.cc
author Mario de Sousa <msousa@fe.up.pt>
Wed, 30 Mar 2011 19:53:32 +0100
changeset 257 90782e241346
parent 202 da1a8186f86f
child 265 4d222f46f8cc
permissions -rwxr-xr-x
Huge change.
201
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
     1
/*
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
     2
 * (c) 2003 Mario de Sousa
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
     3
 *
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
     4
 * Offered to the public under the terms of the GNU General Public License
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
     5
 * as published by the Free Software Foundation; either version 2 of the
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
     6
 * License, or (at your option) any later version.
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
     7
 *
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
     8
 * This program is distributed in the hope that it will be useful, but
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
     9
 * WITHOUT ANY WARRANTY; without even the implied warranty of
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    11
 * Public License for more details.
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    12
 *
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    13
 * This code is made available on the understanding that it will not be
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    14
 * used in safety-critical situations without a full and competent review.
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    15
 */
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    16
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    17
/*
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    18
 * An IEC 61131-3 IL and ST compiler.
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    19
 *
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    20
 * Based on the
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    21
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    22
 *
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    23
 */
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    24
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    25
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    26
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    27
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    28
/* Returns the data type of an il_operand.
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    29
 *
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    30
 * Note that the il_operand may be a variable, in which case
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    31
 * we return the type of the variable instance.
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    32
 * The il_operand may also be a constant, in which case
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    33
 * we return the data type of that constant.
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    34
 *
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    35
 * The variable instance may be a member of a structured variable,
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    36
 * or an element in an array, or any combination of the two.
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    37
 *
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    38
 * The class constructor must be given the search scope
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    39
 * (function, function block or program within which
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    40
 * the possible il_operand variable instance was declared).
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    41
 */
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    42
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
    43
#include "absyntax_utils.hh"
201
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    44
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    45
symbol_c *search_il_operand_type_c::get_type(symbol_c *il_operand) {
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    46
  symbol_c *res;
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    47
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    48
  /* We first assume that it is a constant... */
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    49
  res = search_constant_type.get_type(il_operand);
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    50
  if (res != NULL) return res;
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    51
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    52
  /* Nope, now we assume it is a variable, and determine its type... */
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    53
  res = search_varfb_instance_type.get_type(il_operand);
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    54
  if (NULL != res) return res;
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    55
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    56
  /* not found */
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    57
  return NULL;
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    58
}