absyntax_utils/search_expression_type.cc
author Mario de Sousa <msousa@fe.up.pt>
Thu, 16 Feb 2012 12:59:02 +0000
changeset 444 92d40d2a7adc
parent 350 2c3c4dc34979
permissions -rwxr-xr-x
Update comments on general architecture.
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
     1
/*
265
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 258
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 258
diff changeset
     3
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 258
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
265
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 258
diff changeset
     6
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 258
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: 258
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: 258
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: 258
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: 258
diff changeset
    11
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 258
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: 258
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: 258
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: 258
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: 258
diff changeset
    16
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 258
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: 258
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: 258
diff changeset
    19
 *
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    20
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    21
 * This code is made available on the understanding that it will not be
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    22
 * used in safety-critical situations without a full and competent review.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    23
 */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    24
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    25
/*
265
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 258
diff changeset
    26
 * An IEC 61131-3 compiler.
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    27
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    28
 * Based on the
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    29
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    30
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    31
 */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    32
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    33
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    34
/* Determine the data type of an ST expression.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    35
 * A reference to the relevant type definition is returned.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    36
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    37
 * For example:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    38
 *       2 + 3       -> returns reference to a int_type_name_c object.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    39
 *       22.2 - 5    -> returns reference to a real_type_name_c object.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    40
 *       etc...
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    41
 */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    42
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    43
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    44
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    45
#include "absyntax_utils.hh"
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    46
#include <typeinfo>
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    47
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    48
search_expression_type_c::search_expression_type_c(symbol_c *search_scope) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    49
  search_varfb_instance_type = new search_varfb_instance_type_c(search_scope);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    50
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    51
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    52
search_expression_type_c::~search_expression_type_c(void) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    53
  delete search_varfb_instance_type;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    54
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    55
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    56
/* A helper function... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    57
bool search_expression_type_c::is_bool_type(symbol_c *type_symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    58
  bool_type_name_c tt;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    59
  if (type_symbol == NULL) {return true;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    60
  if (typeid(*type_symbol) == typeid(safebool_type_name_c)) {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    61
  if (typeid(*type_symbol) == typeid(bool_type_name_c))     {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    62
  if (typeid(*type_symbol) == typeid(boolean_true_c))       {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    63
  if (typeid(*type_symbol) == typeid(boolean_false_c))      {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    64
  return false;
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    65
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    66
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    67
/* A helper function... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    68
bool search_expression_type_c::is_time_type(symbol_c *type_symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    69
  if (type_symbol == NULL) {return true;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    70
  if (typeid(*type_symbol) == typeid(time_type_name_c))     {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    71
  if (typeid(*type_symbol) == typeid(date_type_name_c))     {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    72
  if (typeid(*type_symbol) == typeid(tod_type_name_c))      {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    73
  if (typeid(*type_symbol) == typeid(dt_type_name_c))       {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    74
  if (typeid(*type_symbol) == typeid(safetime_type_name_c)) {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    75
  if (typeid(*type_symbol) == typeid(safedate_type_name_c)) {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    76
  if (typeid(*type_symbol) == typeid(safetod_type_name_c))  {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    77
  if (typeid(*type_symbol) == typeid(safedt_type_name_c))   {return true;}
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    78
  return false;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    79
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    80
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    81
/* A helper function... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    82
bool search_expression_type_c::is_string_type(symbol_c *type_symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    83
  if (type_symbol == NULL) {return true;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    84
  if (typeid(*type_symbol) == typeid(string_type_name_c))      {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    85
  if (typeid(*type_symbol) == typeid(wstring_type_name_c))     {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    86
  if (typeid(*type_symbol) == typeid(safestring_type_name_c))  {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    87
  if (typeid(*type_symbol) == typeid(safewstring_type_name_c)) {return true;}
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    88
  return false;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    89
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    90
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    91
/* A helper function... */
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
    92
bool search_expression_type_c::is_literal_integer_type(symbol_c *type_symbol) {
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
    93
  if (type_symbol == NULL) {return true;}
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
    94
  if (typeid(*type_symbol) == typeid(integer_c))        {return true;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    95
  if (typeid(*type_symbol) == typeid(neg_integer_c))    {return true;}
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
    96
  if (typeid(*type_symbol) == typeid(binary_integer_c)) {return true;}
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
    97
  if (typeid(*type_symbol) == typeid(octal_integer_c))  {return true;}
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
    98
  if (typeid(*type_symbol) == typeid(hex_integer_c))    {return true;}
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
    99
  return false;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   100
}
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   101
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   102
/* A helper function... */
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   103
bool search_expression_type_c::is_integer_type(symbol_c *type_symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   104
  if (type_symbol == NULL) {return true;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   105
  if (typeid(*type_symbol) == typeid(sint_type_name_c))      {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   106
  if (typeid(*type_symbol) == typeid(int_type_name_c))       {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   107
  if (typeid(*type_symbol) == typeid(dint_type_name_c))      {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   108
  if (typeid(*type_symbol) == typeid(lint_type_name_c))      {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   109
  if (typeid(*type_symbol) == typeid(usint_type_name_c))     {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   110
  if (typeid(*type_symbol) == typeid(uint_type_name_c))      {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   111
  if (typeid(*type_symbol) == typeid(udint_type_name_c))     {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   112
  if (typeid(*type_symbol) == typeid(ulint_type_name_c))     {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   113
  if (typeid(*type_symbol) == typeid(safesint_type_name_c))  {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   114
  if (typeid(*type_symbol) == typeid(safeint_type_name_c))   {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   115
  if (typeid(*type_symbol) == typeid(safedint_type_name_c))  {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   116
  if (typeid(*type_symbol) == typeid(safelint_type_name_c))  {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   117
  if (typeid(*type_symbol) == typeid(safeusint_type_name_c)) {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   118
  if (typeid(*type_symbol) == typeid(safeuint_type_name_c))  {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   119
  if (typeid(*type_symbol) == typeid(safeudint_type_name_c)) {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   120
  if (typeid(*type_symbol) == typeid(safeulint_type_name_c)) {return true;}
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   121
  return is_literal_integer_type(type_symbol);
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   122
}
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   123
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   124
/* A helper function... */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   125
bool search_expression_type_c::is_literal_real_type(symbol_c *type_symbol) {
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   126
  if (type_symbol == NULL) {return true;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   127
  if (typeid(*type_symbol) == typeid(real_c))     {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   128
  if (typeid(*type_symbol) == typeid(neg_real_c)) {return true;}
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   129
  return false;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   130
}
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   131
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   132
/* A helper function... */
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   133
bool search_expression_type_c::is_real_type(symbol_c *type_symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   134
  if (type_symbol == NULL) {return true;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   135
  if (typeid(*type_symbol) == typeid(real_type_name_c))      {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   136
  if (typeid(*type_symbol) == typeid(lreal_type_name_c))     {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   137
  if (typeid(*type_symbol) == typeid(safereal_type_name_c))  {return true;} 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   138
  if (typeid(*type_symbol) == typeid(safelreal_type_name_c)) {return true;}  
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   139
  return is_literal_real_type(type_symbol);
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   140
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   141
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   142
bool search_expression_type_c::is_num_type(symbol_c *type_symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   143
  if (type_symbol == NULL) {return true;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   144
  return is_real_type(type_symbol) || is_integer_type(type_symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   145
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   146
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   147
bool search_expression_type_c::is_nbinary_type(symbol_c *type_symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   148
  if (type_symbol == NULL) {return true;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   149
  if (typeid(*type_symbol) == typeid(byte_type_name_c))      {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   150
  if (typeid(*type_symbol) == typeid(word_type_name_c))      {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   151
  if (typeid(*type_symbol) == typeid(dword_type_name_c))     {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   152
  if (typeid(*type_symbol) == typeid(lword_type_name_c))     {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   153
  if (typeid(*type_symbol) == typeid(safebyte_type_name_c))  {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   154
  if (typeid(*type_symbol) == typeid(safeword_type_name_c))  {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   155
  if (typeid(*type_symbol) == typeid(safedword_type_name_c)) {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   156
  if (typeid(*type_symbol) == typeid(safelword_type_name_c)) {return true;}
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   157
  return is_literal_integer_type(type_symbol);
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   158
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   159
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   160
bool search_expression_type_c::is_binary_type(symbol_c *type_symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   161
  if (type_symbol == NULL) {return true;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   162
//   if (typeid(*type_symbol) == typeid(bool_type_name_c))     {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   163
//   if (typeid(*type_symbol) == typeid(safebool_type_name_c)) {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   164
  return (is_nbinary_type(type_symbol) || is_bool_type(type_symbol));
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   165
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   166
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   167
bool search_expression_type_c::is_same_type(symbol_c *first_type, symbol_c *second_type) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   168
  if (first_type == NULL || second_type == NULL) {return true;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   169
  if (typeid(*first_type) == typeid(*second_type)) {return true;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   170
  if (is_bool_type(first_type)            && is_bool_type(second_type))            {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   171
  if (is_integer_type(first_type)         && is_literal_integer_type(second_type)) {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   172
  if (is_literal_integer_type(first_type) && is_integer_type(second_type))         {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   173
  if (is_binary_type(first_type)          && is_literal_integer_type(second_type)) {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   174
  if (is_literal_integer_type(first_type) && is_binary_type(second_type))          {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   175
  if (is_real_type(first_type)            && is_literal_real_type(second_type))    {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   176
  if (is_literal_real_type(first_type)    && is_real_type(second_type))            {return true;}
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   177
  return false;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   178
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   179
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   180
symbol_c* search_expression_type_c::common_type(symbol_c *first_type, symbol_c *second_type) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   181
  if (first_type == NULL && second_type == NULL) {return NULL;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   182
  if (first_type == NULL) {return second_type;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   183
  if (second_type == NULL) {return first_type;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   184
  if (typeid(*first_type) == typeid(*second_type)) {return first_type;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   185
  if (is_integer_type(first_type)         && is_literal_integer_type(second_type)) {return first_type;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   186
  if (is_literal_integer_type(first_type) && is_integer_type(second_type))         {return second_type;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   187
  if (is_binary_type(first_type)          && is_literal_integer_type(second_type)) {return first_type;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   188
  if (is_literal_integer_type(first_type) && is_binary_type(second_type))          {return second_type;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   189
  if (is_real_type(first_type)            && is_literal_real_type(second_type))    {return first_type;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   190
  if (is_literal_real_type(first_type)    && is_real_type(second_type))            {return second_type;}
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   191
  return NULL;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   192
}
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   193
336
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 321
diff changeset
   194
symbol_c *search_expression_type_c::default_literal_type(symbol_c* symbol) {
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 321
diff changeset
   195
  if (is_literal_integer_type(symbol)) {
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 321
diff changeset
   196
    return (symbol_c *)&search_constant_type_c::lint_type_name;
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 321
diff changeset
   197
  }
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 321
diff changeset
   198
  else if (is_literal_real_type(symbol)) {
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 321
diff changeset
   199
    return (symbol_c *)&search_constant_type_c::lreal_type_name;
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 321
diff changeset
   200
  }
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 321
diff changeset
   201
  return symbol;
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 321
diff changeset
   202
}
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 321
diff changeset
   203
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   204
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   205
/* A helper function... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   206
void *search_expression_type_c::compute_boolean_expression(symbol_c *left_type, symbol_c *right_type) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   207
  if (!is_same_type(left_type, right_type))
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   208
    ERROR;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   209
  if (!is_bool_type(left_type) && !is_binary_type(left_type))
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   210
    ERROR;
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   211
  if (is_literal_integer_type(left_type)) {return (void *)right_type;}
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   212
  else {return (void *)left_type;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   213
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   214
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   215
/* A helper function... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   216
void *search_expression_type_c::compute_numeric_expression(symbol_c *left_type, symbol_c *right_type) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   217
  if (!is_same_type(left_type, right_type))
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   218
    ERROR;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   219
  if (!is_integer_type(left_type) && !is_real_type(left_type))
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   220
    ERROR;
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 196
diff changeset
   221
  if (is_literal_integer_type(left_type) || is_literal_real_type(left_type)) {return (void *)right_type;}
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   222
  else {return (void *)left_type;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   223
  return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   224
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   225
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   226
/* a helper function... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   227
symbol_c *search_expression_type_c::base_type(symbol_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   228
  return (symbol_c *)symbol->accept(search_base_type);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   229
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   230
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   231
/*********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   232
/* B 1.4 - Variables */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   233
/*********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   234
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   235
void *search_expression_type_c::visit(symbolic_variable_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   236
  symbol_c *res;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   237
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   238
  /* Nope, now we assume it is a variable, and determine its type... */
321
a96399ab57c2 Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   239
  res = search_varfb_instance_type->get_basetype_decl(symbol);
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   240
  if (NULL != res) return res;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   241
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   242
  return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   243
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   244
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   245
/********************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   246
/* B 1.4.1 - Directly Represented Variables */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   247
/********************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   248
void *search_expression_type_c::visit(direct_variable_c *symbol) {
196
1c0c7a664fc2 Fix problems with direct variables in expression while compiling resulting expression type
lbessard
parents: 194
diff changeset
   249
  symbol_c *res;
1c0c7a664fc2 Fix problems with direct variables in expression while compiling resulting expression type
lbessard
parents: 194
diff changeset
   250
  
1c0c7a664fc2 Fix problems with direct variables in expression while compiling resulting expression type
lbessard
parents: 194
diff changeset
   251
  /* Nope, now we assume it is a variable, and determine its type... */
321
a96399ab57c2 Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   252
  res = search_varfb_instance_type->get_basetype_decl(symbol);
196
1c0c7a664fc2 Fix problems with direct variables in expression while compiling resulting expression type
lbessard
parents: 194
diff changeset
   253
  if (NULL != res) return res;
1c0c7a664fc2 Fix problems with direct variables in expression while compiling resulting expression type
lbessard
parents: 194
diff changeset
   254
  
1c0c7a664fc2 Fix problems with direct variables in expression while compiling resulting expression type
lbessard
parents: 194
diff changeset
   255
  return NULL;
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   256
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   257
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   258
/*************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   259
/* B 1.4.2 - Multi-element variables */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   260
/*************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   261
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   262
void *search_expression_type_c::visit(array_variable_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   263
  symbol_c *res;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   264
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   265
  /* Nope, now we assume it is a variable, and determine its type... */
321
a96399ab57c2 Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   266
  res = search_varfb_instance_type->get_basetype_decl(symbol);
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   267
  if (NULL != res) return res;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   268
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   269
  return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   270
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   271
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   272
void *search_expression_type_c::visit(structured_variable_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   273
  symbol_c *res;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   274
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   275
  /* Nope, now we assume it is a variable, and determine its type... */
321
a96399ab57c2 Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   276
  res = search_varfb_instance_type->get_basetype_decl(symbol);
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   277
  if (NULL != res) return res;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   278
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   279
  return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   280
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   281
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   282
/***************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   283
/* B.3 - Language ST (Structured Text) */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   284
/***************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   285
/***********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   286
/* B 3.1 - Expressions */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   287
/***********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   288
void *search_expression_type_c::visit(or_expression_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   289
  symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   290
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   291
  return compute_boolean_expression(left_type, right_type);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   292
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   293
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   294
void *search_expression_type_c::visit(xor_expression_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   295
  symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   296
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   297
  return compute_boolean_expression(left_type, right_type);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   298
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   299
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   300
void *search_expression_type_c::visit(and_expression_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   301
  symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   302
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   303
  return compute_boolean_expression(left_type, right_type); 
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   304
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   305
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   306
void *search_expression_type_c::visit(equ_expression_c *symbol) {return (void *)&bool_type_name;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   307
void *search_expression_type_c::visit(notequ_expression_c *symbol) {return (void *)&bool_type_name;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   308
void *search_expression_type_c::visit(lt_expression_c *symbol) {return (void *)&bool_type_name;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   309
void *search_expression_type_c::visit(gt_expression_c *symbol) {return (void *)&bool_type_name;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   310
void *search_expression_type_c::visit(le_expression_c *symbol) {return (void *)&bool_type_name;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   311
void *search_expression_type_c::visit(ge_expression_c *symbol) {return (void *)&bool_type_name;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   312
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   313
void *search_expression_type_c::visit(add_expression_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   314
  symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   315
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   316
  if (typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&time_type_name;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   317
  if (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&tod_type_name;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   318
  if (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&dt_type_name;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   319
  return compute_numeric_expression(left_type, right_type);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   320
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   321
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   322
void *search_expression_type_c::visit(sub_expression_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   323
  symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   324
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   325
  if (typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&time_type_name;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   326
  if (typeid(*left_type) == typeid(date_type_name_c) && typeid(*right_type) == typeid(date_type_name_c)) {return (void *)&time_type_name;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   327
  if (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&tod_type_name;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   328
  if (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(tod_type_name_c)) {return (void *)&time_type_name;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   329
  if (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&dt_type_name;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   330
  if (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(dt_type_name_c)) {return (void *)&time_type_name;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   331
  return compute_numeric_expression(left_type, right_type);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   332
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   333
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   334
void *search_expression_type_c::visit(mul_expression_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   335
  symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   336
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   337
  if (typeid(*left_type) == typeid(time_type_name_c) && is_num_type(right_type)) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   338
      return (void *)&time_type_name;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   339
  }
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   340
  return compute_numeric_expression(left_type, right_type);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   341
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   342
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   343
void *search_expression_type_c::visit(div_expression_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   344
  symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   345
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   346
  if (typeid(*left_type) == typeid(time_type_name_c) && is_num_type(right_type)){
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   347
      return (void *)&time_type_name;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   348
  }
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   349
  return compute_numeric_expression(left_type, right_type);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   350
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   351
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   352
void *search_expression_type_c::visit(mod_expression_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   353
  symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   354
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   355
  return compute_numeric_expression(left_type, right_type);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   356
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   357
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   358
void *search_expression_type_c::visit(power_expression_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   359
  symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   360
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   361
  if (is_real_type(left_type) && is_num_type(right_type)) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   362
      return (void *)left_type;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   363
  }
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   364
  ERROR;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   365
  return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   366
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   367
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   368
void *search_expression_type_c::visit(neg_expression_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   369
  symbol_c *exp_type = base_type((symbol_c *)symbol->exp->accept(*this));
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   370
  if (is_num_type(exp_type) || typeid(*exp_type) == typeid(time_type_name_c)){
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   371
      return (void *)exp_type;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   372
  }
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   373
  ERROR;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   374
  return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   375
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   376
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   377
void *search_expression_type_c::visit(not_expression_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   378
  symbol_c *exp_type = base_type((symbol_c *)symbol->exp->accept(*this));
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   379
  return compute_boolean_expression(exp_type, exp_type);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   380
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   381
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   382
void *search_expression_type_c::visit(function_invocation_c *symbol) {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   383
  function_declaration_c *f_decl = (function_declaration_c *)symbol->called_function_declaration;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   384
  if (f_decl == NULL) ERROR;
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   385
  return base_type(f_decl->type_name);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   386
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   387
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   388
/*bool_type_name_c     search_expression_type_c::bool_type_name;*/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   389