absyntax_utils/search_il_operand_type.cc
author Edouard Tisserant
Tue, 05 Apr 2011 15:14:19 +0200
changeset 279 c0453b7f99df
parent 265 4d222f46f8cc
permissions -rwxr-xr-x
Re-generated std lib related code, with updated headers, updated all forgotten headers
201
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
     1
/*
265
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
201
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
     3
 *
265
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
     4
 *  Copyright (C) 2003-2011  Mario de Sousa (msousa@fe.up.pt)
279
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 265
diff changeset
     5
 *  Copyright (C) 2007-2011  Laurent Bessard and Edouard Tisserant
201
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
     6
 *
265
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
     7
 *  This program is free software: you can redistribute it and/or modify
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
     8
 *  it under the terms of the GNU General Public License as published by
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
     9
 *  the Free Software Foundation, either version 3 of the License, or
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    10
 *  (at your option) any later version.
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    11
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    12
 *  This program is distributed in the hope that it will be useful,
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    15
 *  GNU General Public License for more details.
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    16
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    17
 *  You should have received a copy of the GNU General Public License
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    19
 *
201
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    20
 *
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    21
 * 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
    22
 * 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
    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
/*
265
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    26
 * An IEC 61131-3 compiler.
201
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
 * 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
    29
 * 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
    30
 *
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    31
 */
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    32
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    33
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
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    36
/* 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
    37
 *
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    38
 * 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
    39
 * 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
    40
 * 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
    41
 * 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
    42
 *
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    43
 * 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
    44
 * 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
    45
 *
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    46
 * 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
    47
 * (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
    48
 * 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
    49
 */
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    50
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
    51
#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
    52
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    53
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
    54
  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
    55
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    56
  /* 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
    57
  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
    58
  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
    59
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    60
  /* 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
    61
  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
    62
  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
    63
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    64
  /* not found */
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    65
  return NULL;
e657008f43d0 Introducing the search_il_operand_type files in the absyntax_utils folder.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    66
}